1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 #include "stringpool.h"
28 #include "stor-layout.h"
33 #include "hard-reg-set.h"
36 #include "insn-config.h"
37 #include "insn-attr.h"
38 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
44 #include "typeclass.h"
46 #include "langhooks.h"
49 #include "tree-iterator.h"
51 #include "gimple-ssa.h"
53 #include "tree-ssanames.h"
55 #include "common/common-target.h"
58 #include "diagnostic.h"
59 #include "tree-ssa-live.h"
60 #include "tree-outof-ssa.h"
61 #include "target-globals.h"
63 #include "tree-ssa-address.h"
64 #include "cfgexpand.h"
66 /* Decide whether a function's arguments should be processed
67 from first to last or from last to first.
69 They should if the stack and args grow in opposite directions, but
70 only if we have push insns. */
74 #ifndef PUSH_ARGS_REVERSED
75 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
76 #define PUSH_ARGS_REVERSED /* If it's last to first. */
82 #ifndef STACK_PUSH_CODE
83 #ifdef STACK_GROWS_DOWNWARD
84 #define STACK_PUSH_CODE PRE_DEC
86 #define STACK_PUSH_CODE PRE_INC
91 /* If this is nonzero, we do not bother generating VOLATILE
92 around volatile memory references, and we are willing to
93 output indirect addresses. If cse is to follow, we reject
94 indirect addresses so a useful potential cse is generated;
95 if it is used only once, instruction combination will produce
96 the same indirect address eventually. */
99 /* This structure is used by move_by_pieces to describe the move to
101 struct move_by_pieces_d
110 int explicit_inc_from
;
111 unsigned HOST_WIDE_INT len
;
112 HOST_WIDE_INT offset
;
116 /* This structure is used by store_by_pieces to describe the clear to
119 struct store_by_pieces_d
125 unsigned HOST_WIDE_INT len
;
126 HOST_WIDE_INT offset
;
127 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
);
132 static void move_by_pieces_1 (insn_gen_fn
, machine_mode
,
133 struct move_by_pieces_d
*);
134 static bool block_move_libcall_safe_for_call_parm (void);
135 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned, unsigned, HOST_WIDE_INT
,
136 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
137 unsigned HOST_WIDE_INT
);
138 static tree
emit_block_move_libcall_fn (int);
139 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
140 static rtx
clear_by_pieces_1 (void *, HOST_WIDE_INT
, enum machine_mode
);
141 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
142 static void store_by_pieces_1 (struct store_by_pieces_d
*, unsigned int);
143 static void store_by_pieces_2 (insn_gen_fn
, machine_mode
,
144 struct store_by_pieces_d
*);
145 static tree
clear_storage_libcall_fn (int);
146 static rtx
compress_float_constant (rtx
, rtx
);
147 static rtx
get_subtarget (rtx
);
148 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
149 HOST_WIDE_INT
, enum machine_mode
,
150 tree
, int, alias_set_type
);
151 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
);
152 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
,
153 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
154 enum machine_mode
, tree
, alias_set_type
, bool);
156 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
158 static int is_aligning_offset (const_tree
, const_tree
);
159 static void expand_operands (tree
, tree
, rtx
, rtx
*, rtx
*,
160 enum expand_modifier
);
161 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
162 static rtx
do_store_flag (sepops
, rtx
, enum machine_mode
);
164 static void emit_single_push_insn (enum machine_mode
, rtx
, tree
);
166 static void do_tablejump (rtx
, enum machine_mode
, rtx
, rtx
, rtx
, int);
167 static rtx
const_vector_from_tree (tree
);
168 static void write_complex_part (rtx
, rtx
, bool);
170 /* This macro is used to determine whether move_by_pieces should be called
171 to perform a structure copy. */
172 #ifndef MOVE_BY_PIECES_P
173 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
174 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
175 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
178 /* This macro is used to determine whether clear_by_pieces should be
179 called to clear storage. */
180 #ifndef CLEAR_BY_PIECES_P
181 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
182 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
183 < (unsigned int) CLEAR_RATIO (optimize_insn_for_speed_p ()))
186 /* This macro is used to determine whether store_by_pieces should be
187 called to "memset" storage with byte values other than zero. */
188 #ifndef SET_BY_PIECES_P
189 #define SET_BY_PIECES_P(SIZE, ALIGN) \
190 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
191 < (unsigned int) SET_RATIO (optimize_insn_for_speed_p ()))
194 /* This macro is used to determine whether store_by_pieces should be
195 called to "memcpy" storage when the source is a constant string. */
196 #ifndef STORE_BY_PIECES_P
197 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
198 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
199 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
202 /* This is run to set up which modes can be used
203 directly in memory and to initialize the block move optab. It is run
204 at the beginning of compilation and when the target is reinitialized. */
207 init_expr_target (void)
210 enum machine_mode mode
;
215 /* Try indexing by frame ptr and try by stack ptr.
216 It is known that on the Convex the stack ptr isn't a valid index.
217 With luck, one or the other is valid on any machine. */
218 mem
= gen_rtx_MEM (VOIDmode
, stack_pointer_rtx
);
219 mem1
= gen_rtx_MEM (VOIDmode
, frame_pointer_rtx
);
221 /* A scratch register we can modify in-place below to avoid
222 useless RTL allocations. */
223 reg
= gen_rtx_REG (VOIDmode
, -1);
225 insn
= rtx_alloc (INSN
);
226 pat
= gen_rtx_SET (VOIDmode
, NULL_RTX
, NULL_RTX
);
227 PATTERN (insn
) = pat
;
229 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
230 mode
= (enum machine_mode
) ((int) mode
+ 1))
234 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
235 PUT_MODE (mem
, mode
);
236 PUT_MODE (mem1
, mode
);
237 PUT_MODE (reg
, mode
);
239 /* See if there is some register that can be used in this mode and
240 directly loaded or stored from memory. */
242 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
243 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
244 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
247 if (! HARD_REGNO_MODE_OK (regno
, mode
))
250 SET_REGNO (reg
, regno
);
253 SET_DEST (pat
) = reg
;
254 if (recog (pat
, insn
, &num_clobbers
) >= 0)
255 direct_load
[(int) mode
] = 1;
257 SET_SRC (pat
) = mem1
;
258 SET_DEST (pat
) = reg
;
259 if (recog (pat
, insn
, &num_clobbers
) >= 0)
260 direct_load
[(int) mode
] = 1;
263 SET_DEST (pat
) = mem
;
264 if (recog (pat
, insn
, &num_clobbers
) >= 0)
265 direct_store
[(int) mode
] = 1;
268 SET_DEST (pat
) = mem1
;
269 if (recog (pat
, insn
, &num_clobbers
) >= 0)
270 direct_store
[(int) mode
] = 1;
274 mem
= gen_rtx_MEM (VOIDmode
, gen_rtx_raw_REG (Pmode
, 10000));
276 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
277 mode
= GET_MODE_WIDER_MODE (mode
))
279 enum machine_mode srcmode
;
280 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
281 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
285 ic
= can_extend_p (mode
, srcmode
, 0);
286 if (ic
== CODE_FOR_nothing
)
289 PUT_MODE (mem
, srcmode
);
291 if (insn_operand_matches (ic
, 1, mem
))
292 float_extend_from_mem
[mode
][srcmode
] = true;
297 /* This is run at the start of compiling a function. */
302 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
305 /* Copy data from FROM to TO, where the machine modes are not the same.
306 Both modes may be integer, or both may be floating, or both may be
308 UNSIGNEDP should be nonzero if FROM is an unsigned type.
309 This causes zero-extension instead of sign-extension. */
312 convert_move (rtx to
, rtx from
, int unsignedp
)
314 enum machine_mode to_mode
= GET_MODE (to
);
315 enum machine_mode from_mode
= GET_MODE (from
);
316 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
317 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
321 /* rtx code for making an equivalent value. */
322 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
323 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
326 gcc_assert (to_real
== from_real
);
327 gcc_assert (to_mode
!= BLKmode
);
328 gcc_assert (from_mode
!= BLKmode
);
330 /* If the source and destination are already the same, then there's
335 /* If FROM is a SUBREG that indicates that we have already done at least
336 the required extension, strip it. We don't handle such SUBREGs as
339 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
340 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
341 >= GET_MODE_PRECISION (to_mode
))
342 && SUBREG_PROMOTED_UNSIGNED_P (from
) == unsignedp
)
343 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
345 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
347 if (to_mode
== from_mode
348 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
350 emit_move_insn (to
, from
);
354 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
356 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
358 if (VECTOR_MODE_P (to_mode
))
359 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
361 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
363 emit_move_insn (to
, from
);
367 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
369 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
370 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
379 gcc_assert ((GET_MODE_PRECISION (from_mode
)
380 != GET_MODE_PRECISION (to_mode
))
381 || (DECIMAL_FLOAT_MODE_P (from_mode
)
382 != DECIMAL_FLOAT_MODE_P (to_mode
)));
384 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
385 /* Conversion between decimal float and binary float, same size. */
386 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
387 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
392 /* Try converting directly if the insn is supported. */
394 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
395 if (code
!= CODE_FOR_nothing
)
397 emit_unop_insn (code
, to
, from
,
398 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
402 /* Otherwise use a libcall. */
403 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
405 /* Is this conversion implemented yet? */
406 gcc_assert (libcall
);
409 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
411 insns
= get_insns ();
413 emit_libcall_block (insns
, to
, value
,
414 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
416 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
420 /* Handle pointer conversion. */ /* SPEE 900220. */
421 /* Targets are expected to provide conversion insns between PxImode and
422 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
423 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
425 enum machine_mode full_mode
426 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
428 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
429 != CODE_FOR_nothing
);
431 if (full_mode
!= from_mode
)
432 from
= convert_to_mode (full_mode
, from
, unsignedp
);
433 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
437 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
440 enum machine_mode full_mode
441 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
442 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
443 enum insn_code icode
;
445 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
446 gcc_assert (icode
!= CODE_FOR_nothing
);
448 if (to_mode
== full_mode
)
450 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
454 new_from
= gen_reg_rtx (full_mode
);
455 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
457 /* else proceed to integer conversions below. */
458 from_mode
= full_mode
;
462 /* Make sure both are fixed-point modes or both are not. */
463 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
464 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
465 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
467 /* If we widen from_mode to to_mode and they are in the same class,
468 we won't saturate the result.
469 Otherwise, always saturate the result to play safe. */
470 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
471 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
472 expand_fixed_convert (to
, from
, 0, 0);
474 expand_fixed_convert (to
, from
, 0, 1);
478 /* Now both modes are integers. */
480 /* Handle expanding beyond a word. */
481 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
482 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
489 enum machine_mode lowpart_mode
;
490 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
492 /* Try converting directly if the insn is supported. */
493 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
496 /* If FROM is a SUBREG, put it into a register. Do this
497 so that we always generate the same set of insns for
498 better cse'ing; if an intermediate assignment occurred,
499 we won't be doing the operation directly on the SUBREG. */
500 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
501 from
= force_reg (from_mode
, from
);
502 emit_unop_insn (code
, to
, from
, equiv_code
);
505 /* Next, try converting via full word. */
506 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
507 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
508 != CODE_FOR_nothing
))
510 rtx word_to
= gen_reg_rtx (word_mode
);
513 if (reg_overlap_mentioned_p (to
, from
))
514 from
= force_reg (from_mode
, from
);
517 convert_move (word_to
, from
, unsignedp
);
518 emit_unop_insn (code
, to
, word_to
, equiv_code
);
522 /* No special multiword conversion insn; do it by hand. */
525 /* Since we will turn this into a no conflict block, we must ensure the
526 the source does not overlap the target so force it into an isolated
527 register when maybe so. Likewise for any MEM input, since the
528 conversion sequence might require several references to it and we
529 must ensure we're getting the same value every time. */
531 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
532 from
= force_reg (from_mode
, from
);
534 /* Get a copy of FROM widened to a word, if necessary. */
535 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
536 lowpart_mode
= word_mode
;
538 lowpart_mode
= from_mode
;
540 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
542 lowpart
= gen_lowpart (lowpart_mode
, to
);
543 emit_move_insn (lowpart
, lowfrom
);
545 /* Compute the value to put in each remaining word. */
547 fill_value
= const0_rtx
;
549 fill_value
= emit_store_flag (gen_reg_rtx (word_mode
),
550 LT
, lowfrom
, const0_rtx
,
553 /* Fill the remaining words. */
554 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
556 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
557 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
559 gcc_assert (subword
);
561 if (fill_value
!= subword
)
562 emit_move_insn (subword
, fill_value
);
565 insns
= get_insns ();
572 /* Truncating multi-word to a word or less. */
573 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
574 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
577 && ! MEM_VOLATILE_P (from
)
578 && direct_load
[(int) to_mode
]
579 && ! mode_dependent_address_p (XEXP (from
, 0),
580 MEM_ADDR_SPACE (from
)))
582 || GET_CODE (from
) == SUBREG
))
583 from
= force_reg (from_mode
, from
);
584 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
588 /* Now follow all the conversions between integers
589 no more than a word long. */
591 /* For truncation, usually we can just refer to FROM in a narrower mode. */
592 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
593 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
596 && ! MEM_VOLATILE_P (from
)
597 && direct_load
[(int) to_mode
]
598 && ! mode_dependent_address_p (XEXP (from
, 0),
599 MEM_ADDR_SPACE (from
)))
601 || GET_CODE (from
) == SUBREG
))
602 from
= force_reg (from_mode
, from
);
603 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
604 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
605 from
= copy_to_reg (from
);
606 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
610 /* Handle extension. */
611 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
613 /* Convert directly if that works. */
614 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
617 emit_unop_insn (code
, to
, from
, equiv_code
);
622 enum machine_mode intermediate
;
626 /* Search for a mode to convert via. */
627 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
628 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
629 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
631 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
632 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
633 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
634 != CODE_FOR_nothing
))
636 convert_move (to
, convert_to_mode (intermediate
, from
,
637 unsignedp
), unsignedp
);
641 /* No suitable intermediate mode.
642 Generate what we need with shifts. */
643 shift_amount
= (GET_MODE_PRECISION (to_mode
)
644 - GET_MODE_PRECISION (from_mode
));
645 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
646 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
648 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
651 emit_move_insn (to
, tmp
);
656 /* Support special truncate insns for certain modes. */
657 if (convert_optab_handler (trunc_optab
, to_mode
,
658 from_mode
) != CODE_FOR_nothing
)
660 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
665 /* Handle truncation of volatile memrefs, and so on;
666 the things that couldn't be truncated directly,
667 and for which there was no special instruction.
669 ??? Code above formerly short-circuited this, for most integer
670 mode pairs, with a force_reg in from_mode followed by a recursive
671 call to this routine. Appears always to have been wrong. */
672 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
674 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
675 emit_move_insn (to
, temp
);
679 /* Mode combination is not recognized. */
683 /* Return an rtx for a value that would result
684 from converting X to mode MODE.
685 Both X and MODE may be floating, or both integer.
686 UNSIGNEDP is nonzero if X is an unsigned value.
687 This can be done by referring to a part of X in place
688 or by copying to a new temporary with conversion. */
691 convert_to_mode (enum machine_mode mode
, rtx x
, int unsignedp
)
693 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
696 /* Return an rtx for a value that would result
697 from converting X from mode OLDMODE to mode MODE.
698 Both modes may be floating, or both integer.
699 UNSIGNEDP is nonzero if X is an unsigned value.
701 This can be done by referring to a part of X in place
702 or by copying to a new temporary with conversion.
704 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
707 convert_modes (enum machine_mode mode
, enum machine_mode oldmode
, rtx x
, int unsignedp
)
711 /* If FROM is a SUBREG that indicates that we have already done at least
712 the required extension, strip it. */
714 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
715 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
716 && SUBREG_PROMOTED_UNSIGNED_P (x
) == unsignedp
)
717 x
= gen_lowpart (mode
, x
);
719 if (GET_MODE (x
) != VOIDmode
)
720 oldmode
= GET_MODE (x
);
725 /* There is one case that we must handle specially: If we are converting
726 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
727 we are to interpret the constant as unsigned, gen_lowpart will do
728 the wrong if the constant appears negative. What we want to do is
729 make the high-order word of the constant zero, not all ones. */
731 if (unsignedp
&& GET_MODE_CLASS (mode
) == MODE_INT
732 && GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
733 && CONST_INT_P (x
) && INTVAL (x
) < 0)
735 double_int val
= double_int::from_uhwi (INTVAL (x
));
737 /* We need to zero extend VAL. */
738 if (oldmode
!= VOIDmode
)
739 val
= val
.zext (GET_MODE_BITSIZE (oldmode
));
741 return immed_double_int_const (val
, mode
);
744 /* We can do this with a gen_lowpart if both desired and current modes
745 are integer, and this is either a constant integer, a register, or a
746 non-volatile MEM. Except for the constant case where MODE is no
747 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
750 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
)
751 || (GET_MODE_CLASS (mode
) == MODE_INT
752 && GET_MODE_CLASS (oldmode
) == MODE_INT
753 && (CONST_DOUBLE_AS_INT_P (x
)
754 || (GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
755 && ((MEM_P (x
) && ! MEM_VOLATILE_P (x
)
756 && direct_load
[(int) mode
])
758 && (! HARD_REGISTER_P (x
)
759 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
760 && TRULY_NOOP_TRUNCATION_MODES_P (mode
,
763 /* ?? If we don't know OLDMODE, we have to assume here that
764 X does not need sign- or zero-extension. This may not be
765 the case, but it's the best we can do. */
766 if (CONST_INT_P (x
) && oldmode
!= VOIDmode
767 && GET_MODE_PRECISION (mode
) > GET_MODE_PRECISION (oldmode
))
769 HOST_WIDE_INT val
= INTVAL (x
);
771 /* We must sign or zero-extend in this case. Start by
772 zero-extending, then sign extend if we need to. */
773 val
&= GET_MODE_MASK (oldmode
);
775 && val_signbit_known_set_p (oldmode
, val
))
776 val
|= ~GET_MODE_MASK (oldmode
);
778 return gen_int_mode (val
, mode
);
781 return gen_lowpart (mode
, x
);
784 /* Converting from integer constant into mode is always equivalent to an
786 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
788 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
789 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
792 temp
= gen_reg_rtx (mode
);
793 convert_move (temp
, x
, unsignedp
);
797 /* Return the largest alignment we can use for doing a move (or store)
798 of MAX_PIECES. ALIGN is the largest alignment we could use. */
801 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
803 enum machine_mode tmode
;
805 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
806 if (align
>= GET_MODE_ALIGNMENT (tmode
))
807 align
= GET_MODE_ALIGNMENT (tmode
);
810 enum machine_mode tmode
, xmode
;
812 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
814 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
815 if (GET_MODE_SIZE (tmode
) > max_pieces
816 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
819 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
825 /* Return the widest integer mode no wider than SIZE. If no such mode
826 can be found, return VOIDmode. */
828 static enum machine_mode
829 widest_int_mode_for_size (unsigned int size
)
831 enum machine_mode tmode
, mode
= VOIDmode
;
833 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
834 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
835 if (GET_MODE_SIZE (tmode
) < size
)
841 /* STORE_MAX_PIECES is the number of bytes at a time that we can
842 store efficiently. Due to internal GCC limitations, this is
843 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
844 for an immediate constant. */
846 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
848 /* Determine whether the LEN bytes can be moved by using several move
849 instructions. Return nonzero if a call to move_by_pieces should
853 can_move_by_pieces (unsigned HOST_WIDE_INT len ATTRIBUTE_UNUSED
,
854 unsigned int align ATTRIBUTE_UNUSED
)
856 return MOVE_BY_PIECES_P (len
, align
);
859 /* Generate several move instructions to copy LEN bytes from block FROM to
860 block TO. (These are MEM rtx's with BLKmode).
862 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
863 used to push FROM to the stack.
865 ALIGN is maximum stack alignment we can assume.
867 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
868 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
872 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
873 unsigned int align
, int endp
)
875 struct move_by_pieces_d data
;
876 enum machine_mode to_addr_mode
;
877 enum machine_mode from_addr_mode
= get_address_mode (from
);
878 rtx to_addr
, from_addr
= XEXP (from
, 0);
879 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
880 enum insn_code icode
;
882 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
885 data
.from_addr
= from_addr
;
888 to_addr_mode
= get_address_mode (to
);
889 to_addr
= XEXP (to
, 0);
892 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
893 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
895 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
899 to_addr_mode
= VOIDmode
;
903 #ifdef STACK_GROWS_DOWNWARD
909 data
.to_addr
= to_addr
;
912 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
913 || GET_CODE (from_addr
) == POST_INC
914 || GET_CODE (from_addr
) == POST_DEC
);
916 data
.explicit_inc_from
= 0;
917 data
.explicit_inc_to
= 0;
918 if (data
.reverse
) data
.offset
= len
;
921 /* If copying requires more than two move insns,
922 copy addresses to registers (to make displacements shorter)
923 and use post-increment if available. */
924 if (!(data
.autinc_from
&& data
.autinc_to
)
925 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
927 /* Find the mode of the largest move...
928 MODE might not be used depending on the definitions of the
929 USE_* macros below. */
930 enum machine_mode mode ATTRIBUTE_UNUSED
931 = widest_int_mode_for_size (max_size
);
933 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
935 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
936 plus_constant (from_addr_mode
,
938 data
.autinc_from
= 1;
939 data
.explicit_inc_from
= -1;
941 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
943 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
944 data
.autinc_from
= 1;
945 data
.explicit_inc_from
= 1;
947 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
948 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
949 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
951 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
952 plus_constant (to_addr_mode
,
955 data
.explicit_inc_to
= -1;
957 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
959 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
961 data
.explicit_inc_to
= 1;
963 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
964 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
967 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
969 /* First move what we can in the largest integer mode, then go to
970 successively smaller modes. */
972 while (max_size
> 1 && data
.len
> 0)
974 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
976 if (mode
== VOIDmode
)
979 icode
= optab_handler (mov_optab
, mode
);
980 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
981 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
983 max_size
= GET_MODE_SIZE (mode
);
986 /* The code above should have handled everything. */
987 gcc_assert (!data
.len
);
993 gcc_assert (!data
.reverse
);
998 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
999 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
1001 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
1002 plus_constant (to_addr_mode
,
1006 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
1013 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
1021 /* Return number of insns required to move L bytes by pieces.
1022 ALIGN (in bits) is maximum alignment we can assume. */
1024 unsigned HOST_WIDE_INT
1025 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
1026 unsigned int max_size
)
1028 unsigned HOST_WIDE_INT n_insns
= 0;
1030 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
1032 while (max_size
> 1 && l
> 0)
1034 enum machine_mode mode
;
1035 enum insn_code icode
;
1037 mode
= widest_int_mode_for_size (max_size
);
1039 if (mode
== VOIDmode
)
1042 icode
= optab_handler (mov_optab
, mode
);
1043 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
1044 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
1046 max_size
= GET_MODE_SIZE (mode
);
1053 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1054 with move instructions for mode MODE. GENFUN is the gen_... function
1055 to make a move insn for that mode. DATA has all the other info. */
1058 move_by_pieces_1 (insn_gen_fn genfun
, machine_mode mode
,
1059 struct move_by_pieces_d
*data
)
1061 unsigned int size
= GET_MODE_SIZE (mode
);
1062 rtx to1
= NULL_RTX
, from1
;
1064 while (data
->len
>= size
)
1067 data
->offset
-= size
;
1071 if (data
->autinc_to
)
1072 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1075 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1078 if (data
->autinc_from
)
1079 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1082 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1084 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1085 emit_insn (gen_add2_insn (data
->to_addr
,
1086 gen_int_mode (-(HOST_WIDE_INT
) size
,
1087 GET_MODE (data
->to_addr
))));
1088 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1089 emit_insn (gen_add2_insn (data
->from_addr
,
1090 gen_int_mode (-(HOST_WIDE_INT
) size
,
1091 GET_MODE (data
->from_addr
))));
1094 emit_insn ((*genfun
) (to1
, from1
));
1097 #ifdef PUSH_ROUNDING
1098 emit_single_push_insn (mode
, from1
, NULL
);
1104 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1105 emit_insn (gen_add2_insn (data
->to_addr
,
1107 GET_MODE (data
->to_addr
))));
1108 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1109 emit_insn (gen_add2_insn (data
->from_addr
,
1111 GET_MODE (data
->from_addr
))));
1113 if (! data
->reverse
)
1114 data
->offset
+= size
;
1120 /* Emit code to move a block Y to a block X. This may be done with
1121 string-move instructions, with multiple scalar move instructions,
1122 or with a library call.
1124 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1125 SIZE is an rtx that says how long they are.
1126 ALIGN is the maximum alignment we can assume they have.
1127 METHOD describes what kind of copy this is, and what mechanisms may be used.
1128 MIN_SIZE is the minimal size of block to move
1129 MAX_SIZE is the maximal size of block to move, if it can not be represented
1130 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1132 Return the address of the new block, if memcpy is called and returns it,
1136 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1137 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1138 unsigned HOST_WIDE_INT min_size
,
1139 unsigned HOST_WIDE_INT max_size
,
1140 unsigned HOST_WIDE_INT probable_max_size
)
1147 if (CONST_INT_P (size
)
1148 && INTVAL (size
) == 0)
1153 case BLOCK_OP_NORMAL
:
1154 case BLOCK_OP_TAILCALL
:
1155 may_use_call
= true;
1158 case BLOCK_OP_CALL_PARM
:
1159 may_use_call
= block_move_libcall_safe_for_call_parm ();
1161 /* Make inhibit_defer_pop nonzero around the library call
1162 to force it to pop the arguments right away. */
1166 case BLOCK_OP_NO_LIBCALL
:
1167 may_use_call
= false;
1174 gcc_assert (MEM_P (x
) && MEM_P (y
));
1175 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1176 gcc_assert (align
>= BITS_PER_UNIT
);
1178 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1179 block copy is more efficient for other large modes, e.g. DCmode. */
1180 x
= adjust_address (x
, BLKmode
, 0);
1181 y
= adjust_address (y
, BLKmode
, 0);
1183 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1184 can be incorrect is coming from __builtin_memcpy. */
1185 if (CONST_INT_P (size
))
1187 x
= shallow_copy_rtx (x
);
1188 y
= shallow_copy_rtx (y
);
1189 set_mem_size (x
, INTVAL (size
));
1190 set_mem_size (y
, INTVAL (size
));
1193 if (CONST_INT_P (size
) && MOVE_BY_PIECES_P (INTVAL (size
), align
))
1194 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1195 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1196 expected_align
, expected_size
,
1197 min_size
, max_size
, probable_max_size
))
1199 else if (may_use_call
1200 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1201 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1203 /* Since x and y are passed to a libcall, mark the corresponding
1204 tree EXPR as addressable. */
1205 tree y_expr
= MEM_EXPR (y
);
1206 tree x_expr
= MEM_EXPR (x
);
1208 mark_addressable (y_expr
);
1210 mark_addressable (x_expr
);
1211 retval
= emit_block_move_via_libcall (x
, y
, size
,
1212 method
== BLOCK_OP_TAILCALL
);
1216 emit_block_move_via_loop (x
, y
, size
, align
);
1218 if (method
== BLOCK_OP_CALL_PARM
)
1225 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1227 unsigned HOST_WIDE_INT max
, min
= 0;
1228 if (GET_CODE (size
) == CONST_INT
)
1229 min
= max
= UINTVAL (size
);
1231 max
= GET_MODE_MASK (GET_MODE (size
));
1232 return emit_block_move_hints (x
, y
, size
, method
, 0, -1,
1236 /* A subroutine of emit_block_move. Returns true if calling the
1237 block move libcall will not clobber any parameters which may have
1238 already been placed on the stack. */
1241 block_move_libcall_safe_for_call_parm (void)
1243 #if defined (REG_PARM_STACK_SPACE)
1247 /* If arguments are pushed on the stack, then they're safe. */
1251 /* If registers go on the stack anyway, any argument is sure to clobber
1252 an outgoing argument. */
1253 #if defined (REG_PARM_STACK_SPACE)
1254 fn
= emit_block_move_libcall_fn (false);
1255 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1256 depend on its argument. */
1258 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1259 && REG_PARM_STACK_SPACE (fn
) != 0)
1263 /* If any argument goes in memory, then it might clobber an outgoing
1266 CUMULATIVE_ARGS args_so_far_v
;
1267 cumulative_args_t args_so_far
;
1270 fn
= emit_block_move_libcall_fn (false);
1271 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1272 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1274 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1275 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1277 enum machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1278 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1280 if (!tmp
|| !REG_P (tmp
))
1282 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1284 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1291 /* A subroutine of emit_block_move. Expand a movmem pattern;
1292 return true if successful. */
1295 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1296 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1297 unsigned HOST_WIDE_INT min_size
,
1298 unsigned HOST_WIDE_INT max_size
,
1299 unsigned HOST_WIDE_INT probable_max_size
)
1301 int save_volatile_ok
= volatile_ok
;
1302 enum machine_mode mode
;
1304 if (expected_align
< align
)
1305 expected_align
= align
;
1306 if (expected_size
!= -1)
1308 if ((unsigned HOST_WIDE_INT
)expected_size
> probable_max_size
)
1309 expected_size
= probable_max_size
;
1310 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
1311 expected_size
= min_size
;
1314 /* Since this is a move insn, we don't care about volatility. */
1317 /* Try the most limited insn first, because there's no point
1318 including more than one in the machine description unless
1319 the more limited one has some advantage. */
1321 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1322 mode
= GET_MODE_WIDER_MODE (mode
))
1324 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1326 if (code
!= CODE_FOR_nothing
1327 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1328 here because if SIZE is less than the mode mask, as it is
1329 returned by the macro, it will definitely be less than the
1330 actual mode mask. Since SIZE is within the Pmode address
1331 space, we limit MODE to Pmode. */
1332 && ((CONST_INT_P (size
)
1333 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1334 <= (GET_MODE_MASK (mode
) >> 1)))
1335 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
1336 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
1338 struct expand_operand ops
[9];
1341 /* ??? When called via emit_block_move_for_call, it'd be
1342 nice if there were some way to inform the backend, so
1343 that it doesn't fail the expansion because it thinks
1344 emitting the libcall would be more efficient. */
1345 nops
= insn_data
[(int) code
].n_generator_args
;
1346 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
1348 create_fixed_operand (&ops
[0], x
);
1349 create_fixed_operand (&ops
[1], y
);
1350 /* The check above guarantees that this size conversion is valid. */
1351 create_convert_operand_to (&ops
[2], size
, mode
, true);
1352 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1355 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1356 create_integer_operand (&ops
[5], expected_size
);
1360 create_integer_operand (&ops
[6], min_size
);
1361 /* If we can not represent the maximal size,
1362 make parameter NULL. */
1363 if ((HOST_WIDE_INT
) max_size
!= -1)
1364 create_integer_operand (&ops
[7], max_size
);
1366 create_fixed_operand (&ops
[7], NULL
);
1370 /* If we can not represent the maximal size,
1371 make parameter NULL. */
1372 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
1373 create_integer_operand (&ops
[8], probable_max_size
);
1375 create_fixed_operand (&ops
[8], NULL
);
1377 if (maybe_expand_insn (code
, nops
, ops
))
1379 volatile_ok
= save_volatile_ok
;
1385 volatile_ok
= save_volatile_ok
;
1389 /* A subroutine of emit_block_move. Expand a call to memcpy.
1390 Return the return value from memcpy, 0 otherwise. */
1393 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1395 rtx dst_addr
, src_addr
;
1396 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1397 enum machine_mode size_mode
;
1400 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1401 pseudos. We can then place those new pseudos into a VAR_DECL and
1404 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1405 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1407 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1408 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1410 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1411 src_tree
= make_tree (ptr_type_node
, src_addr
);
1413 size_mode
= TYPE_MODE (sizetype
);
1415 size
= convert_to_mode (size_mode
, size
, 1);
1416 size
= copy_to_mode_reg (size_mode
, size
);
1418 /* It is incorrect to use the libcall calling conventions to call
1419 memcpy in this context. This could be a user call to memcpy and
1420 the user may wish to examine the return value from memcpy. For
1421 targets where libcalls and normal calls have different conventions
1422 for returning pointers, we could end up generating incorrect code. */
1424 size_tree
= make_tree (sizetype
, size
);
1426 fn
= emit_block_move_libcall_fn (true);
1427 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1428 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1430 retval
= expand_normal (call_expr
);
1435 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1436 for the function we use for block copies. */
1438 static GTY(()) tree block_move_fn
;
1441 init_block_move_fn (const char *asmspec
)
1445 tree args
, fn
, attrs
, attr_args
;
1447 fn
= get_identifier ("memcpy");
1448 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1449 const_ptr_type_node
, sizetype
,
1452 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1453 DECL_EXTERNAL (fn
) = 1;
1454 TREE_PUBLIC (fn
) = 1;
1455 DECL_ARTIFICIAL (fn
) = 1;
1456 TREE_NOTHROW (fn
) = 1;
1457 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1458 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1460 attr_args
= build_tree_list (NULL_TREE
, build_string (1, "1"));
1461 attrs
= tree_cons (get_identifier ("fn spec"), attr_args
, NULL
);
1463 decl_attributes (&fn
, attrs
, ATTR_FLAG_BUILT_IN
);
1469 set_user_assembler_name (block_move_fn
, asmspec
);
1473 emit_block_move_libcall_fn (int for_call
)
1475 static bool emitted_extern
;
1478 init_block_move_fn (NULL
);
1480 if (for_call
&& !emitted_extern
)
1482 emitted_extern
= true;
1483 make_decl_rtl (block_move_fn
);
1486 return block_move_fn
;
1489 /* A subroutine of emit_block_move. Copy the data via an explicit
1490 loop. This is used only when libcalls are forbidden. */
1491 /* ??? It'd be nice to copy in hunks larger than QImode. */
1494 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1495 unsigned int align ATTRIBUTE_UNUSED
)
1497 rtx cmp_label
, top_label
, iter
, x_addr
, y_addr
, tmp
;
1498 enum machine_mode x_addr_mode
= get_address_mode (x
);
1499 enum machine_mode y_addr_mode
= get_address_mode (y
);
1500 enum machine_mode iter_mode
;
1502 iter_mode
= GET_MODE (size
);
1503 if (iter_mode
== VOIDmode
)
1504 iter_mode
= word_mode
;
1506 top_label
= gen_label_rtx ();
1507 cmp_label
= gen_label_rtx ();
1508 iter
= gen_reg_rtx (iter_mode
);
1510 emit_move_insn (iter
, const0_rtx
);
1512 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1513 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1514 do_pending_stack_adjust ();
1516 emit_jump (cmp_label
);
1517 emit_label (top_label
);
1519 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1520 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1522 if (x_addr_mode
!= y_addr_mode
)
1523 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1524 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1526 x
= change_address (x
, QImode
, x_addr
);
1527 y
= change_address (y
, QImode
, y_addr
);
1529 emit_move_insn (x
, y
);
1531 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1532 true, OPTAB_LIB_WIDEN
);
1534 emit_move_insn (iter
, tmp
);
1536 emit_label (cmp_label
);
1538 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1539 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1542 /* Copy all or part of a value X into registers starting at REGNO.
1543 The number of registers to be filled is NREGS. */
1546 move_block_to_reg (int regno
, rtx x
, int nregs
, enum machine_mode mode
)
1549 #ifdef HAVE_load_multiple
1557 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1558 x
= validize_mem (force_const_mem (mode
, x
));
1560 /* See if the machine can do this with a load multiple insn. */
1561 #ifdef HAVE_load_multiple
1562 if (HAVE_load_multiple
)
1564 last
= get_last_insn ();
1565 pat
= gen_load_multiple (gen_rtx_REG (word_mode
, regno
), x
,
1573 delete_insns_since (last
);
1577 for (i
= 0; i
< nregs
; i
++)
1578 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1579 operand_subword_force (x
, i
, mode
));
1582 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1583 The number of registers to be filled is NREGS. */
1586 move_block_from_reg (int regno
, rtx x
, int nregs
)
1593 /* See if the machine can do this with a store multiple insn. */
1594 #ifdef HAVE_store_multiple
1595 if (HAVE_store_multiple
)
1597 rtx last
= get_last_insn ();
1598 rtx pat
= gen_store_multiple (x
, gen_rtx_REG (word_mode
, regno
),
1606 delete_insns_since (last
);
1610 for (i
= 0; i
< nregs
; i
++)
1612 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1616 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1620 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1621 ORIG, where ORIG is a non-consecutive group of registers represented by
1622 a PARALLEL. The clone is identical to the original except in that the
1623 original set of registers is replaced by a new set of pseudo registers.
1624 The new set has the same modes as the original set. */
1627 gen_group_rtx (rtx orig
)
1632 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1634 length
= XVECLEN (orig
, 0);
1635 tmps
= XALLOCAVEC (rtx
, length
);
1637 /* Skip a NULL entry in first slot. */
1638 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1643 for (; i
< length
; i
++)
1645 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1646 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1648 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1651 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1654 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1655 except that values are placed in TMPS[i], and must later be moved
1656 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1659 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1663 enum machine_mode m
= GET_MODE (orig_src
);
1665 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1668 && !SCALAR_INT_MODE_P (m
)
1669 && !MEM_P (orig_src
)
1670 && GET_CODE (orig_src
) != CONCAT
)
1672 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1673 if (imode
== BLKmode
)
1674 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
1676 src
= gen_reg_rtx (imode
);
1677 if (imode
!= BLKmode
)
1678 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1679 emit_move_insn (src
, orig_src
);
1680 /* ...and back again. */
1681 if (imode
!= BLKmode
)
1682 src
= gen_lowpart (imode
, src
);
1683 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1687 /* Check for a NULL entry, used to indicate that the parameter goes
1688 both on the stack and in registers. */
1689 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1694 /* Process the pieces. */
1695 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1697 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1698 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1699 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1702 /* Handle trailing fragments that run over the size of the struct. */
1703 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1705 /* Arrange to shift the fragment to where it belongs.
1706 extract_bit_field loads to the lsb of the reg. */
1708 #ifdef BLOCK_REG_PADDING
1709 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1710 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1715 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1716 bytelen
= ssize
- bytepos
;
1717 gcc_assert (bytelen
> 0);
1720 /* If we won't be loading directly from memory, protect the real source
1721 from strange tricks we might play; but make sure that the source can
1722 be loaded directly into the destination. */
1724 if (!MEM_P (orig_src
)
1725 && (!CONSTANT_P (orig_src
)
1726 || (GET_MODE (orig_src
) != mode
1727 && GET_MODE (orig_src
) != VOIDmode
)))
1729 if (GET_MODE (orig_src
) == VOIDmode
)
1730 src
= gen_reg_rtx (mode
);
1732 src
= gen_reg_rtx (GET_MODE (orig_src
));
1734 emit_move_insn (src
, orig_src
);
1737 /* Optimize the access just a bit. */
1739 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1740 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1741 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1742 && bytelen
== GET_MODE_SIZE (mode
))
1744 tmps
[i
] = gen_reg_rtx (mode
);
1745 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1747 else if (COMPLEX_MODE_P (mode
)
1748 && GET_MODE (src
) == mode
1749 && bytelen
== GET_MODE_SIZE (mode
))
1750 /* Let emit_move_complex do the bulk of the work. */
1752 else if (GET_CODE (src
) == CONCAT
)
1754 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1755 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1757 if ((bytepos
== 0 && bytelen
== slen0
)
1758 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1760 /* The following assumes that the concatenated objects all
1761 have the same size. In this case, a simple calculation
1762 can be used to determine the object and the bit field
1764 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1765 if (! CONSTANT_P (tmps
[i
])
1766 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1767 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1768 (bytepos
% slen0
) * BITS_PER_UNIT
,
1769 1, NULL_RTX
, mode
, mode
);
1775 gcc_assert (!bytepos
);
1776 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1777 emit_move_insn (mem
, src
);
1778 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1779 0, 1, NULL_RTX
, mode
, mode
);
1782 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1783 SIMD register, which is currently broken. While we get GCC
1784 to emit proper RTL for these cases, let's dump to memory. */
1785 else if (VECTOR_MODE_P (GET_MODE (dst
))
1788 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1791 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1792 emit_move_insn (mem
, src
);
1793 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1795 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1796 && XVECLEN (dst
, 0) > 1)
1797 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE (dst
), bytepos
);
1798 else if (CONSTANT_P (src
))
1800 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1808 gcc_assert (2 * len
== ssize
);
1809 split_double (src
, &first
, &second
);
1816 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1819 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1820 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
1824 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1829 /* Emit code to move a block SRC of type TYPE to a block DST,
1830 where DST is non-consecutive registers represented by a PARALLEL.
1831 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1835 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1840 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1841 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1843 /* Copy the extracted pieces into the proper (probable) hard regs. */
1844 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1846 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1849 emit_move_insn (d
, tmps
[i
]);
1853 /* Similar, but load SRC into new pseudos in a format that looks like
1854 PARALLEL. This can later be fed to emit_group_move to get things
1855 in the right place. */
1858 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1863 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1864 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1866 /* Convert the vector to look just like the original PARALLEL, except
1867 with the computed values. */
1868 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1870 rtx e
= XVECEXP (parallel
, 0, i
);
1871 rtx d
= XEXP (e
, 0);
1875 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1876 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1878 RTVEC_ELT (vec
, i
) = e
;
1881 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1884 /* Emit code to move a block SRC to block DST, where SRC and DST are
1885 non-consecutive groups of registers, each represented by a PARALLEL. */
1888 emit_group_move (rtx dst
, rtx src
)
1892 gcc_assert (GET_CODE (src
) == PARALLEL
1893 && GET_CODE (dst
) == PARALLEL
1894 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1896 /* Skip first entry if NULL. */
1897 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1898 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1899 XEXP (XVECEXP (src
, 0, i
), 0));
1902 /* Move a group of registers represented by a PARALLEL into pseudos. */
1905 emit_group_move_into_temps (rtx src
)
1907 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1910 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1912 rtx e
= XVECEXP (src
, 0, i
);
1913 rtx d
= XEXP (e
, 0);
1916 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1917 RTVEC_ELT (vec
, i
) = e
;
1920 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1923 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1924 where SRC is non-consecutive registers represented by a PARALLEL.
1925 SSIZE represents the total size of block ORIG_DST, or -1 if not
1929 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1932 int start
, finish
, i
;
1933 enum machine_mode m
= GET_MODE (orig_dst
);
1935 gcc_assert (GET_CODE (src
) == PARALLEL
);
1937 if (!SCALAR_INT_MODE_P (m
)
1938 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1940 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1941 if (imode
== BLKmode
)
1942 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
1944 dst
= gen_reg_rtx (imode
);
1945 emit_group_store (dst
, src
, type
, ssize
);
1946 if (imode
!= BLKmode
)
1947 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1948 emit_move_insn (orig_dst
, dst
);
1952 /* Check for a NULL entry, used to indicate that the parameter goes
1953 both on the stack and in registers. */
1954 if (XEXP (XVECEXP (src
, 0, 0), 0))
1958 finish
= XVECLEN (src
, 0);
1960 tmps
= XALLOCAVEC (rtx
, finish
);
1962 /* Copy the (probable) hard regs into pseudos. */
1963 for (i
= start
; i
< finish
; i
++)
1965 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1966 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1968 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1969 emit_move_insn (tmps
[i
], reg
);
1975 /* If we won't be storing directly into memory, protect the real destination
1976 from strange tricks we might play. */
1978 if (GET_CODE (dst
) == PARALLEL
)
1982 /* We can get a PARALLEL dst if there is a conditional expression in
1983 a return statement. In that case, the dst and src are the same,
1984 so no action is necessary. */
1985 if (rtx_equal_p (dst
, src
))
1988 /* It is unclear if we can ever reach here, but we may as well handle
1989 it. Allocate a temporary, and split this into a store/load to/from
1992 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
1993 emit_group_store (temp
, src
, type
, ssize
);
1994 emit_group_load (dst
, temp
, type
, ssize
);
1997 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1999 enum machine_mode outer
= GET_MODE (dst
);
2000 enum machine_mode inner
;
2001 HOST_WIDE_INT bytepos
;
2005 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
2006 dst
= gen_reg_rtx (outer
);
2008 /* Make life a bit easier for combine. */
2009 /* If the first element of the vector is the low part
2010 of the destination mode, use a paradoxical subreg to
2011 initialize the destination. */
2014 inner
= GET_MODE (tmps
[start
]);
2015 bytepos
= subreg_lowpart_offset (inner
, outer
);
2016 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
2018 temp
= simplify_gen_subreg (outer
, tmps
[start
],
2022 emit_move_insn (dst
, temp
);
2029 /* If the first element wasn't the low part, try the last. */
2031 && start
< finish
- 1)
2033 inner
= GET_MODE (tmps
[finish
- 1]);
2034 bytepos
= subreg_lowpart_offset (inner
, outer
);
2035 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
2037 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
2041 emit_move_insn (dst
, temp
);
2048 /* Otherwise, simply initialize the result to zero. */
2050 emit_move_insn (dst
, CONST0_RTX (outer
));
2053 /* Process the pieces. */
2054 for (i
= start
; i
< finish
; i
++)
2056 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
2057 enum machine_mode mode
= GET_MODE (tmps
[i
]);
2058 unsigned int bytelen
= GET_MODE_SIZE (mode
);
2059 unsigned int adj_bytelen
= bytelen
;
2062 /* Handle trailing fragments that run over the size of the struct. */
2063 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2064 adj_bytelen
= ssize
- bytepos
;
2066 if (GET_CODE (dst
) == CONCAT
)
2068 if (bytepos
+ adj_bytelen
2069 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2070 dest
= XEXP (dst
, 0);
2071 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2073 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2074 dest
= XEXP (dst
, 1);
2078 enum machine_mode dest_mode
= GET_MODE (dest
);
2079 enum machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2081 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2083 if (GET_MODE_ALIGNMENT (dest_mode
)
2084 >= GET_MODE_ALIGNMENT (tmp_mode
))
2086 dest
= assign_stack_temp (dest_mode
,
2087 GET_MODE_SIZE (dest_mode
));
2088 emit_move_insn (adjust_address (dest
,
2096 dest
= assign_stack_temp (tmp_mode
,
2097 GET_MODE_SIZE (tmp_mode
));
2098 emit_move_insn (dest
, tmps
[i
]);
2099 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2105 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2107 /* store_bit_field always takes its value from the lsb.
2108 Move the fragment to the lsb if it's not already there. */
2110 #ifdef BLOCK_REG_PADDING
2111 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2112 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2118 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2119 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2122 bytelen
= adj_bytelen
;
2125 /* Optimize the access just a bit. */
2127 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2128 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2129 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2130 && bytelen
== GET_MODE_SIZE (mode
))
2131 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2133 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2134 0, 0, mode
, tmps
[i
]);
2137 /* Copy from the pseudo into the (probable) hard reg. */
2138 if (orig_dst
!= dst
)
2139 emit_move_insn (orig_dst
, dst
);
2142 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2143 of the value stored in X. */
2146 maybe_emit_group_store (rtx x
, tree type
)
2148 enum machine_mode mode
= TYPE_MODE (type
);
2149 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
2150 if (GET_CODE (x
) == PARALLEL
)
2152 rtx result
= gen_reg_rtx (mode
);
2153 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
2159 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2161 This is used on targets that return BLKmode values in registers. */
2164 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2166 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2167 rtx src
= NULL
, dst
= NULL
;
2168 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2169 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2170 enum machine_mode mode
= GET_MODE (srcreg
);
2171 enum machine_mode tmode
= GET_MODE (target
);
2172 enum machine_mode copy_mode
;
2174 /* BLKmode registers created in the back-end shouldn't have survived. */
2175 gcc_assert (mode
!= BLKmode
);
2177 /* If the structure doesn't take up a whole number of words, see whether
2178 SRCREG is padded on the left or on the right. If it's on the left,
2179 set PADDING_CORRECTION to the number of bits to skip.
2181 In most ABIs, the structure will be returned at the least end of
2182 the register, which translates to right padding on little-endian
2183 targets and left padding on big-endian targets. The opposite
2184 holds if the structure is returned at the most significant
2185 end of the register. */
2186 if (bytes
% UNITS_PER_WORD
!= 0
2187 && (targetm
.calls
.return_in_msb (type
)
2189 : BYTES_BIG_ENDIAN
))
2191 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2193 /* We can use a single move if we have an exact mode for the size. */
2194 else if (MEM_P (target
)
2195 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2196 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2197 && bytes
== GET_MODE_SIZE (mode
))
2199 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2203 /* And if we additionally have the same mode for a register. */
2204 else if (REG_P (target
)
2205 && GET_MODE (target
) == mode
2206 && bytes
== GET_MODE_SIZE (mode
))
2208 emit_move_insn (target
, srcreg
);
2212 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2213 into a new pseudo which is a full word. */
2214 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2216 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2220 /* Copy the structure BITSIZE bits at a time. If the target lives in
2221 memory, take care of not reading/writing past its end by selecting
2222 a copy mode suited to BITSIZE. This should always be possible given
2225 If the target lives in register, make sure not to select a copy mode
2226 larger than the mode of the register.
2228 We could probably emit more efficient code for machines which do not use
2229 strict alignment, but it doesn't seem worth the effort at the current
2232 copy_mode
= word_mode
;
2235 enum machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2236 if (mem_mode
!= BLKmode
)
2237 copy_mode
= mem_mode
;
2239 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2242 for (bitpos
= 0, xbitpos
= padding_correction
;
2243 bitpos
< bytes
* BITS_PER_UNIT
;
2244 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2246 /* We need a new source operand each time xbitpos is on a
2247 word boundary and when xbitpos == padding_correction
2248 (the first time through). */
2249 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2250 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2252 /* We need a new destination operand each time bitpos is on
2254 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2256 else if (bitpos
% BITS_PER_WORD
== 0)
2257 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2259 /* Use xbitpos for the source extraction (right justified) and
2260 bitpos for the destination store (left justified). */
2261 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2262 extract_bit_field (src
, bitsize
,
2263 xbitpos
% BITS_PER_WORD
, 1,
2264 NULL_RTX
, copy_mode
, copy_mode
));
2268 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2269 register if it contains any data, otherwise return null.
2271 This is used on targets that return BLKmode values in registers. */
2274 copy_blkmode_to_reg (enum machine_mode mode
, tree src
)
2277 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2278 unsigned int bitsize
;
2279 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2280 enum machine_mode dst_mode
;
2282 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2284 x
= expand_normal (src
);
2286 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2290 /* If the structure doesn't take up a whole number of words, see
2291 whether the register value should be padded on the left or on
2292 the right. Set PADDING_CORRECTION to the number of padding
2293 bits needed on the left side.
2295 In most ABIs, the structure will be returned at the least end of
2296 the register, which translates to right padding on little-endian
2297 targets and left padding on big-endian targets. The opposite
2298 holds if the structure is returned at the most significant
2299 end of the register. */
2300 if (bytes
% UNITS_PER_WORD
!= 0
2301 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2303 : BYTES_BIG_ENDIAN
))
2304 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2307 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2308 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2309 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2311 /* Copy the structure BITSIZE bits at a time. */
2312 for (bitpos
= 0, xbitpos
= padding_correction
;
2313 bitpos
< bytes
* BITS_PER_UNIT
;
2314 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2316 /* We need a new destination pseudo each time xbitpos is
2317 on a word boundary and when xbitpos == padding_correction
2318 (the first time through). */
2319 if (xbitpos
% BITS_PER_WORD
== 0
2320 || xbitpos
== padding_correction
)
2322 /* Generate an appropriate register. */
2323 dst_word
= gen_reg_rtx (word_mode
);
2324 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2326 /* Clear the destination before we move anything into it. */
2327 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2330 /* We need a new source operand each time bitpos is on a word
2332 if (bitpos
% BITS_PER_WORD
== 0)
2333 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2335 /* Use bitpos for the source extraction (left justified) and
2336 xbitpos for the destination store (right justified). */
2337 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2339 extract_bit_field (src_word
, bitsize
,
2340 bitpos
% BITS_PER_WORD
, 1,
2341 NULL_RTX
, word_mode
, word_mode
));
2344 if (mode
== BLKmode
)
2346 /* Find the smallest integer mode large enough to hold the
2347 entire structure. */
2348 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2350 mode
= GET_MODE_WIDER_MODE (mode
))
2351 /* Have we found a large enough mode? */
2352 if (GET_MODE_SIZE (mode
) >= bytes
)
2355 /* A suitable mode should have been found. */
2356 gcc_assert (mode
!= VOIDmode
);
2359 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2360 dst_mode
= word_mode
;
2363 dst
= gen_reg_rtx (dst_mode
);
2365 for (i
= 0; i
< n_regs
; i
++)
2366 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2368 if (mode
!= dst_mode
)
2369 dst
= gen_lowpart (mode
, dst
);
2374 /* Add a USE expression for REG to the (possibly empty) list pointed
2375 to by CALL_FUSAGE. REG must denote a hard register. */
2378 use_reg_mode (rtx
*call_fusage
, rtx reg
, enum machine_mode mode
)
2380 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2383 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2386 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2387 starting at REGNO. All of these registers must be hard registers. */
2390 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2394 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2396 for (i
= 0; i
< nregs
; i
++)
2397 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2400 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2401 PARALLEL REGS. This is for calls that pass values in multiple
2402 non-contiguous locations. The Irix 6 ABI has examples of this. */
2405 use_group_regs (rtx
*call_fusage
, rtx regs
)
2409 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2411 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2413 /* A NULL entry means the parameter goes both on the stack and in
2414 registers. This can also be a MEM for targets that pass values
2415 partially on the stack and partially in registers. */
2416 if (reg
!= 0 && REG_P (reg
))
2417 use_reg (call_fusage
, reg
);
2421 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2422 assigment and the code of the expresion on the RHS is CODE. Return
2426 get_def_for_expr (tree name
, enum tree_code code
)
2430 if (TREE_CODE (name
) != SSA_NAME
)
2433 def_stmt
= get_gimple_for_ssa_name (name
);
2435 || gimple_assign_rhs_code (def_stmt
) != code
)
2441 #ifdef HAVE_conditional_move
2442 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2443 assigment and the class of the expresion on the RHS is CLASS. Return
2447 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2451 if (TREE_CODE (name
) != SSA_NAME
)
2454 def_stmt
= get_gimple_for_ssa_name (name
);
2456 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2464 /* Determine whether the LEN bytes generated by CONSTFUN can be
2465 stored to memory using several move instructions. CONSTFUNDATA is
2466 a pointer which will be passed as argument in every CONSTFUN call.
2467 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2468 a memset operation and false if it's a copy of a constant string.
2469 Return nonzero if a call to store_by_pieces should succeed. */
2472 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2473 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2474 void *constfundata
, unsigned int align
, bool memsetp
)
2476 unsigned HOST_WIDE_INT l
;
2477 unsigned int max_size
;
2478 HOST_WIDE_INT offset
= 0;
2479 enum machine_mode mode
;
2480 enum insn_code icode
;
2482 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2483 rtx cst ATTRIBUTE_UNUSED
;
2489 ? SET_BY_PIECES_P (len
, align
)
2490 : STORE_BY_PIECES_P (len
, align
)))
2493 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2495 /* We would first store what we can in the largest integer mode, then go to
2496 successively smaller modes. */
2499 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2503 max_size
= STORE_MAX_PIECES
+ 1;
2504 while (max_size
> 1 && l
> 0)
2506 mode
= widest_int_mode_for_size (max_size
);
2508 if (mode
== VOIDmode
)
2511 icode
= optab_handler (mov_optab
, mode
);
2512 if (icode
!= CODE_FOR_nothing
2513 && align
>= GET_MODE_ALIGNMENT (mode
))
2515 unsigned int size
= GET_MODE_SIZE (mode
);
2522 cst
= (*constfun
) (constfundata
, offset
, mode
);
2523 if (!targetm
.legitimate_constant_p (mode
, cst
))
2533 max_size
= GET_MODE_SIZE (mode
);
2536 /* The code above should have handled everything. */
2543 /* Generate several move instructions to store LEN bytes generated by
2544 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2545 pointer which will be passed as argument in every CONSTFUN call.
2546 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2547 a memset operation and false if it's a copy of a constant string.
2548 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2549 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2553 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2554 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2555 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2557 enum machine_mode to_addr_mode
= get_address_mode (to
);
2558 struct store_by_pieces_d data
;
2562 gcc_assert (endp
!= 2);
2567 ? SET_BY_PIECES_P (len
, align
)
2568 : STORE_BY_PIECES_P (len
, align
));
2569 data
.constfun
= constfun
;
2570 data
.constfundata
= constfundata
;
2573 store_by_pieces_1 (&data
, align
);
2578 gcc_assert (!data
.reverse
);
2583 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2584 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2586 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2587 plus_constant (to_addr_mode
,
2591 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2598 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2606 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2607 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2610 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2612 struct store_by_pieces_d data
;
2617 data
.constfun
= clear_by_pieces_1
;
2618 data
.constfundata
= NULL
;
2621 store_by_pieces_1 (&data
, align
);
2624 /* Callback routine for clear_by_pieces.
2625 Return const0_rtx unconditionally. */
2628 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2629 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2630 enum machine_mode mode ATTRIBUTE_UNUSED
)
2635 /* Subroutine of clear_by_pieces and store_by_pieces.
2636 Generate several move instructions to store LEN bytes of block TO. (A MEM
2637 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2640 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2641 unsigned int align ATTRIBUTE_UNUSED
)
2643 enum machine_mode to_addr_mode
= get_address_mode (data
->to
);
2644 rtx to_addr
= XEXP (data
->to
, 0);
2645 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2646 enum insn_code icode
;
2649 data
->to_addr
= to_addr
;
2651 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2652 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2654 data
->explicit_inc_to
= 0;
2656 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2658 data
->offset
= data
->len
;
2660 /* If storing requires more than two move insns,
2661 copy addresses to registers (to make displacements shorter)
2662 and use post-increment if available. */
2663 if (!data
->autinc_to
2664 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2666 /* Determine the main mode we'll be using.
2667 MODE might not be used depending on the definitions of the
2668 USE_* macros below. */
2669 enum machine_mode mode ATTRIBUTE_UNUSED
2670 = widest_int_mode_for_size (max_size
);
2672 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2674 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2675 plus_constant (to_addr_mode
,
2678 data
->autinc_to
= 1;
2679 data
->explicit_inc_to
= -1;
2682 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2683 && ! data
->autinc_to
)
2685 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2686 data
->autinc_to
= 1;
2687 data
->explicit_inc_to
= 1;
2690 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2691 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2694 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2696 /* First store what we can in the largest integer mode, then go to
2697 successively smaller modes. */
2699 while (max_size
> 1 && data
->len
> 0)
2701 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
2703 if (mode
== VOIDmode
)
2706 icode
= optab_handler (mov_optab
, mode
);
2707 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2708 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2710 max_size
= GET_MODE_SIZE (mode
);
2713 /* The code above should have handled everything. */
2714 gcc_assert (!data
->len
);
2717 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2718 with move instructions for mode MODE. GENFUN is the gen_... function
2719 to make a move insn for that mode. DATA has all the other info. */
2722 store_by_pieces_2 (insn_gen_fn genfun
, machine_mode mode
,
2723 struct store_by_pieces_d
*data
)
2725 unsigned int size
= GET_MODE_SIZE (mode
);
2728 while (data
->len
>= size
)
2731 data
->offset
-= size
;
2733 if (data
->autinc_to
)
2734 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2737 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2739 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2740 emit_insn (gen_add2_insn (data
->to_addr
,
2741 gen_int_mode (-(HOST_WIDE_INT
) size
,
2742 GET_MODE (data
->to_addr
))));
2744 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2745 emit_insn ((*genfun
) (to1
, cst
));
2747 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2748 emit_insn (gen_add2_insn (data
->to_addr
,
2750 GET_MODE (data
->to_addr
))));
2752 if (! data
->reverse
)
2753 data
->offset
+= size
;
2759 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2760 its length in bytes. */
2763 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2764 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2765 unsigned HOST_WIDE_INT min_size
,
2766 unsigned HOST_WIDE_INT max_size
,
2767 unsigned HOST_WIDE_INT probable_max_size
)
2769 enum machine_mode mode
= GET_MODE (object
);
2772 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2774 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2775 just move a zero. Otherwise, do this a piece at a time. */
2777 && CONST_INT_P (size
)
2778 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2780 rtx zero
= CONST0_RTX (mode
);
2783 emit_move_insn (object
, zero
);
2787 if (COMPLEX_MODE_P (mode
))
2789 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2792 write_complex_part (object
, zero
, 0);
2793 write_complex_part (object
, zero
, 1);
2799 if (size
== const0_rtx
)
2802 align
= MEM_ALIGN (object
);
2804 if (CONST_INT_P (size
)
2805 && CLEAR_BY_PIECES_P (INTVAL (size
), align
))
2806 clear_by_pieces (object
, INTVAL (size
), align
);
2807 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2808 expected_align
, expected_size
,
2809 min_size
, max_size
, probable_max_size
))
2811 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2812 return set_storage_via_libcall (object
, size
, const0_rtx
,
2813 method
== BLOCK_OP_TAILCALL
);
2821 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2823 unsigned HOST_WIDE_INT max
, min
= 0;
2824 if (GET_CODE (size
) == CONST_INT
)
2825 min
= max
= UINTVAL (size
);
2827 max
= GET_MODE_MASK (GET_MODE (size
));
2828 return clear_storage_hints (object
, size
, method
, 0, -1, min
, max
, max
);
2832 /* A subroutine of clear_storage. Expand a call to memset.
2833 Return the return value of memset, 0 otherwise. */
2836 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2838 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2839 enum machine_mode size_mode
;
2842 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2843 place those into new pseudos into a VAR_DECL and use them later. */
2845 object
= copy_addr_to_reg (XEXP (object
, 0));
2847 size_mode
= TYPE_MODE (sizetype
);
2848 size
= convert_to_mode (size_mode
, size
, 1);
2849 size
= copy_to_mode_reg (size_mode
, size
);
2851 /* It is incorrect to use the libcall calling conventions to call
2852 memset in this context. This could be a user call to memset and
2853 the user may wish to examine the return value from memset. For
2854 targets where libcalls and normal calls have different conventions
2855 for returning pointers, we could end up generating incorrect code. */
2857 object_tree
= make_tree (ptr_type_node
, object
);
2858 if (!CONST_INT_P (val
))
2859 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2860 size_tree
= make_tree (sizetype
, size
);
2861 val_tree
= make_tree (integer_type_node
, val
);
2863 fn
= clear_storage_libcall_fn (true);
2864 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2865 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2867 retval
= expand_normal (call_expr
);
2872 /* A subroutine of set_storage_via_libcall. Create the tree node
2873 for the function we use for block clears. */
2875 tree block_clear_fn
;
2878 init_block_clear_fn (const char *asmspec
)
2880 if (!block_clear_fn
)
2884 fn
= get_identifier ("memset");
2885 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2886 integer_type_node
, sizetype
,
2889 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2890 DECL_EXTERNAL (fn
) = 1;
2891 TREE_PUBLIC (fn
) = 1;
2892 DECL_ARTIFICIAL (fn
) = 1;
2893 TREE_NOTHROW (fn
) = 1;
2894 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2895 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2897 block_clear_fn
= fn
;
2901 set_user_assembler_name (block_clear_fn
, asmspec
);
2905 clear_storage_libcall_fn (int for_call
)
2907 static bool emitted_extern
;
2909 if (!block_clear_fn
)
2910 init_block_clear_fn (NULL
);
2912 if (for_call
&& !emitted_extern
)
2914 emitted_extern
= true;
2915 make_decl_rtl (block_clear_fn
);
2918 return block_clear_fn
;
2921 /* Expand a setmem pattern; return true if successful. */
2924 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2925 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2926 unsigned HOST_WIDE_INT min_size
,
2927 unsigned HOST_WIDE_INT max_size
,
2928 unsigned HOST_WIDE_INT probable_max_size
)
2930 /* Try the most limited insn first, because there's no point
2931 including more than one in the machine description unless
2932 the more limited one has some advantage. */
2934 enum machine_mode mode
;
2936 if (expected_align
< align
)
2937 expected_align
= align
;
2938 if (expected_size
!= -1)
2940 if ((unsigned HOST_WIDE_INT
)expected_size
> max_size
)
2941 expected_size
= max_size
;
2942 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
2943 expected_size
= min_size
;
2946 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2947 mode
= GET_MODE_WIDER_MODE (mode
))
2949 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2951 if (code
!= CODE_FOR_nothing
2952 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2953 here because if SIZE is less than the mode mask, as it is
2954 returned by the macro, it will definitely be less than the
2955 actual mode mask. Since SIZE is within the Pmode address
2956 space, we limit MODE to Pmode. */
2957 && ((CONST_INT_P (size
)
2958 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2959 <= (GET_MODE_MASK (mode
) >> 1)))
2960 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
2961 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
2963 struct expand_operand ops
[9];
2966 nops
= insn_data
[(int) code
].n_generator_args
;
2967 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
2969 create_fixed_operand (&ops
[0], object
);
2970 /* The check above guarantees that this size conversion is valid. */
2971 create_convert_operand_to (&ops
[1], size
, mode
, true);
2972 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2973 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2976 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2977 create_integer_operand (&ops
[5], expected_size
);
2981 create_integer_operand (&ops
[6], min_size
);
2982 /* If we can not represent the maximal size,
2983 make parameter NULL. */
2984 if ((HOST_WIDE_INT
) max_size
!= -1)
2985 create_integer_operand (&ops
[7], max_size
);
2987 create_fixed_operand (&ops
[7], NULL
);
2991 /* If we can not represent the maximal size,
2992 make parameter NULL. */
2993 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
2994 create_integer_operand (&ops
[8], probable_max_size
);
2996 create_fixed_operand (&ops
[8], NULL
);
2998 if (maybe_expand_insn (code
, nops
, ops
))
3007 /* Write to one of the components of the complex value CPLX. Write VAL to
3008 the real part if IMAG_P is false, and the imaginary part if its true. */
3011 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
3013 enum machine_mode cmode
;
3014 enum machine_mode imode
;
3017 if (GET_CODE (cplx
) == CONCAT
)
3019 emit_move_insn (XEXP (cplx
, imag_p
), val
);
3023 cmode
= GET_MODE (cplx
);
3024 imode
= GET_MODE_INNER (cmode
);
3025 ibitsize
= GET_MODE_BITSIZE (imode
);
3027 /* For MEMs simplify_gen_subreg may generate an invalid new address
3028 because, e.g., the original address is considered mode-dependent
3029 by the target, which restricts simplify_subreg from invoking
3030 adjust_address_nv. Instead of preparing fallback support for an
3031 invalid address, we call adjust_address_nv directly. */
3034 emit_move_insn (adjust_address_nv (cplx
, imode
,
3035 imag_p
? GET_MODE_SIZE (imode
) : 0),
3040 /* If the sub-object is at least word sized, then we know that subregging
3041 will work. This special case is important, since store_bit_field
3042 wants to operate on integer modes, and there's rarely an OImode to
3043 correspond to TCmode. */
3044 if (ibitsize
>= BITS_PER_WORD
3045 /* For hard regs we have exact predicates. Assume we can split
3046 the original object if it spans an even number of hard regs.
3047 This special case is important for SCmode on 64-bit platforms
3048 where the natural size of floating-point regs is 32-bit. */
3050 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3051 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3053 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
3054 imag_p
? GET_MODE_SIZE (imode
) : 0);
3057 emit_move_insn (part
, val
);
3061 /* simplify_gen_subreg may fail for sub-word MEMs. */
3062 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3065 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
3068 /* Extract one of the components of the complex value CPLX. Extract the
3069 real part if IMAG_P is false, and the imaginary part if it's true. */
3072 read_complex_part (rtx cplx
, bool imag_p
)
3074 enum machine_mode cmode
, imode
;
3077 if (GET_CODE (cplx
) == CONCAT
)
3078 return XEXP (cplx
, imag_p
);
3080 cmode
= GET_MODE (cplx
);
3081 imode
= GET_MODE_INNER (cmode
);
3082 ibitsize
= GET_MODE_BITSIZE (imode
);
3084 /* Special case reads from complex constants that got spilled to memory. */
3085 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
3087 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
3088 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
3090 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
3091 if (CONSTANT_CLASS_P (part
))
3092 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
3096 /* For MEMs simplify_gen_subreg may generate an invalid new address
3097 because, e.g., the original address is considered mode-dependent
3098 by the target, which restricts simplify_subreg from invoking
3099 adjust_address_nv. Instead of preparing fallback support for an
3100 invalid address, we call adjust_address_nv directly. */
3102 return adjust_address_nv (cplx
, imode
,
3103 imag_p
? GET_MODE_SIZE (imode
) : 0);
3105 /* If the sub-object is at least word sized, then we know that subregging
3106 will work. This special case is important, since extract_bit_field
3107 wants to operate on integer modes, and there's rarely an OImode to
3108 correspond to TCmode. */
3109 if (ibitsize
>= BITS_PER_WORD
3110 /* For hard regs we have exact predicates. Assume we can split
3111 the original object if it spans an even number of hard regs.
3112 This special case is important for SCmode on 64-bit platforms
3113 where the natural size of floating-point regs is 32-bit. */
3115 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3116 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3118 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3119 imag_p
? GET_MODE_SIZE (imode
) : 0);
3123 /* simplify_gen_subreg may fail for sub-word MEMs. */
3124 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3127 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3128 true, NULL_RTX
, imode
, imode
);
3131 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3132 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3133 represented in NEW_MODE. If FORCE is true, this will never happen, as
3134 we'll force-create a SUBREG if needed. */
3137 emit_move_change_mode (enum machine_mode new_mode
,
3138 enum machine_mode old_mode
, rtx x
, bool force
)
3142 if (push_operand (x
, GET_MODE (x
)))
3144 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3145 MEM_COPY_ATTRIBUTES (ret
, x
);
3149 /* We don't have to worry about changing the address since the
3150 size in bytes is supposed to be the same. */
3151 if (reload_in_progress
)
3153 /* Copy the MEM to change the mode and move any
3154 substitutions from the old MEM to the new one. */
3155 ret
= adjust_address_nv (x
, new_mode
, 0);
3156 copy_replacements (x
, ret
);
3159 ret
= adjust_address (x
, new_mode
, 0);
3163 /* Note that we do want simplify_subreg's behavior of validating
3164 that the new mode is ok for a hard register. If we were to use
3165 simplify_gen_subreg, we would create the subreg, but would
3166 probably run into the target not being able to implement it. */
3167 /* Except, of course, when FORCE is true, when this is exactly what
3168 we want. Which is needed for CCmodes on some targets. */
3170 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3172 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3178 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3179 an integer mode of the same size as MODE. Returns the instruction
3180 emitted, or NULL if such a move could not be generated. */
3183 emit_move_via_integer (enum machine_mode mode
, rtx x
, rtx y
, bool force
)
3185 enum machine_mode imode
;
3186 enum insn_code code
;
3188 /* There must exist a mode of the exact size we require. */
3189 imode
= int_mode_for_mode (mode
);
3190 if (imode
== BLKmode
)
3193 /* The target must support moves in this mode. */
3194 code
= optab_handler (mov_optab
, imode
);
3195 if (code
== CODE_FOR_nothing
)
3198 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3201 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3204 return emit_insn (GEN_FCN (code
) (x
, y
));
3207 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3208 Return an equivalent MEM that does not use an auto-increment. */
3211 emit_move_resolve_push (enum machine_mode mode
, rtx x
)
3213 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3214 HOST_WIDE_INT adjust
;
3217 adjust
= GET_MODE_SIZE (mode
);
3218 #ifdef PUSH_ROUNDING
3219 adjust
= PUSH_ROUNDING (adjust
);
3221 if (code
== PRE_DEC
|| code
== POST_DEC
)
3223 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3225 rtx expr
= XEXP (XEXP (x
, 0), 1);
3228 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3229 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3230 val
= INTVAL (XEXP (expr
, 1));
3231 if (GET_CODE (expr
) == MINUS
)
3233 gcc_assert (adjust
== val
|| adjust
== -val
);
3237 /* Do not use anti_adjust_stack, since we don't want to update
3238 stack_pointer_delta. */
3239 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3240 gen_int_mode (adjust
, Pmode
), stack_pointer_rtx
,
3241 0, OPTAB_LIB_WIDEN
);
3242 if (temp
!= stack_pointer_rtx
)
3243 emit_move_insn (stack_pointer_rtx
, temp
);
3250 temp
= stack_pointer_rtx
;
3255 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3261 return replace_equiv_address (x
, temp
);
3264 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3265 X is known to satisfy push_operand, and MODE is known to be complex.
3266 Returns the last instruction emitted. */
3269 emit_move_complex_push (enum machine_mode mode
, rtx x
, rtx y
)
3271 enum machine_mode submode
= GET_MODE_INNER (mode
);
3274 #ifdef PUSH_ROUNDING
3275 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3277 /* In case we output to the stack, but the size is smaller than the
3278 machine can push exactly, we need to use move instructions. */
3279 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3281 x
= emit_move_resolve_push (mode
, x
);
3282 return emit_move_insn (x
, y
);
3286 /* Note that the real part always precedes the imag part in memory
3287 regardless of machine's endianness. */
3288 switch (GET_CODE (XEXP (x
, 0)))
3302 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3303 read_complex_part (y
, imag_first
));
3304 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3305 read_complex_part (y
, !imag_first
));
3308 /* A subroutine of emit_move_complex. Perform the move from Y to X
3309 via two moves of the parts. Returns the last instruction emitted. */
3312 emit_move_complex_parts (rtx x
, rtx y
)
3314 /* Show the output dies here. This is necessary for SUBREGs
3315 of pseudos since we cannot track their lifetimes correctly;
3316 hard regs shouldn't appear here except as return values. */
3317 if (!reload_completed
&& !reload_in_progress
3318 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3321 write_complex_part (x
, read_complex_part (y
, false), false);
3322 write_complex_part (x
, read_complex_part (y
, true), true);
3324 return get_last_insn ();
3327 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3328 MODE is known to be complex. Returns the last instruction emitted. */
3331 emit_move_complex (enum machine_mode mode
, rtx x
, rtx y
)
3335 /* Need to take special care for pushes, to maintain proper ordering
3336 of the data, and possibly extra padding. */
3337 if (push_operand (x
, mode
))
3338 return emit_move_complex_push (mode
, x
, y
);
3340 /* See if we can coerce the target into moving both values at once, except
3341 for floating point where we favor moving as parts if this is easy. */
3342 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3343 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
3345 && HARD_REGISTER_P (x
)
3346 && hard_regno_nregs
[REGNO (x
)][mode
] == 1)
3348 && HARD_REGISTER_P (y
)
3349 && hard_regno_nregs
[REGNO (y
)][mode
] == 1))
3351 /* Not possible if the values are inherently not adjacent. */
3352 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3354 /* Is possible if both are registers (or subregs of registers). */
3355 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3357 /* If one of the operands is a memory, and alignment constraints
3358 are friendly enough, we may be able to do combined memory operations.
3359 We do not attempt this if Y is a constant because that combination is
3360 usually better with the by-parts thing below. */
3361 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3362 && (!STRICT_ALIGNMENT
3363 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3372 /* For memory to memory moves, optimal behavior can be had with the
3373 existing block move logic. */
3374 if (MEM_P (x
) && MEM_P (y
))
3376 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3377 BLOCK_OP_NO_LIBCALL
);
3378 return get_last_insn ();
3381 ret
= emit_move_via_integer (mode
, x
, y
, true);
3386 return emit_move_complex_parts (x
, y
);
3389 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3390 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3393 emit_move_ccmode (enum machine_mode mode
, rtx x
, rtx y
)
3397 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3400 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3401 if (code
!= CODE_FOR_nothing
)
3403 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3404 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3405 return emit_insn (GEN_FCN (code
) (x
, y
));
3409 /* Otherwise, find the MODE_INT mode of the same width. */
3410 ret
= emit_move_via_integer (mode
, x
, y
, false);
3411 gcc_assert (ret
!= NULL
);
3415 /* Return true if word I of OP lies entirely in the
3416 undefined bits of a paradoxical subreg. */
3419 undefined_operand_subword_p (const_rtx op
, int i
)
3421 enum machine_mode innermode
, innermostmode
;
3423 if (GET_CODE (op
) != SUBREG
)
3425 innermode
= GET_MODE (op
);
3426 innermostmode
= GET_MODE (SUBREG_REG (op
));
3427 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3428 /* The SUBREG_BYTE represents offset, as if the value were stored in
3429 memory, except for a paradoxical subreg where we define
3430 SUBREG_BYTE to be 0; undo this exception as in
3432 if (SUBREG_BYTE (op
) == 0
3433 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3435 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3436 if (WORDS_BIG_ENDIAN
)
3437 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3438 if (BYTES_BIG_ENDIAN
)
3439 offset
+= difference
% UNITS_PER_WORD
;
3441 if (offset
>= GET_MODE_SIZE (innermostmode
)
3442 || offset
<= -GET_MODE_SIZE (word_mode
))
3447 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3448 MODE is any multi-word or full-word mode that lacks a move_insn
3449 pattern. Note that you will get better code if you define such
3450 patterns, even if they must turn into multiple assembler instructions. */
3453 emit_move_multi_word (enum machine_mode mode
, rtx x
, rtx y
)
3460 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3462 /* If X is a push on the stack, do the push now and replace
3463 X with a reference to the stack pointer. */
3464 if (push_operand (x
, mode
))
3465 x
= emit_move_resolve_push (mode
, x
);
3467 /* If we are in reload, see if either operand is a MEM whose address
3468 is scheduled for replacement. */
3469 if (reload_in_progress
&& MEM_P (x
)
3470 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3471 x
= replace_equiv_address_nv (x
, inner
);
3472 if (reload_in_progress
&& MEM_P (y
)
3473 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3474 y
= replace_equiv_address_nv (y
, inner
);
3478 need_clobber
= false;
3480 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3483 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3486 /* Do not generate code for a move if it would come entirely
3487 from the undefined bits of a paradoxical subreg. */
3488 if (undefined_operand_subword_p (y
, i
))
3491 ypart
= operand_subword (y
, i
, 1, mode
);
3493 /* If we can't get a part of Y, put Y into memory if it is a
3494 constant. Otherwise, force it into a register. Then we must
3495 be able to get a part of Y. */
3496 if (ypart
== 0 && CONSTANT_P (y
))
3498 y
= use_anchored_address (force_const_mem (mode
, y
));
3499 ypart
= operand_subword (y
, i
, 1, mode
);
3501 else if (ypart
== 0)
3502 ypart
= operand_subword_force (y
, i
, mode
);
3504 gcc_assert (xpart
&& ypart
);
3506 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3508 last_insn
= emit_move_insn (xpart
, ypart
);
3514 /* Show the output dies here. This is necessary for SUBREGs
3515 of pseudos since we cannot track their lifetimes correctly;
3516 hard regs shouldn't appear here except as return values.
3517 We never want to emit such a clobber after reload. */
3519 && ! (reload_in_progress
|| reload_completed
)
3520 && need_clobber
!= 0)
3528 /* Low level part of emit_move_insn.
3529 Called just like emit_move_insn, but assumes X and Y
3530 are basically valid. */
3533 emit_move_insn_1 (rtx x
, rtx y
)
3535 enum machine_mode mode
= GET_MODE (x
);
3536 enum insn_code code
;
3538 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3540 code
= optab_handler (mov_optab
, mode
);
3541 if (code
!= CODE_FOR_nothing
)
3542 return emit_insn (GEN_FCN (code
) (x
, y
));
3544 /* Expand complex moves by moving real part and imag part. */
3545 if (COMPLEX_MODE_P (mode
))
3546 return emit_move_complex (mode
, x
, y
);
3548 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3549 || ALL_FIXED_POINT_MODE_P (mode
))
3551 rtx result
= emit_move_via_integer (mode
, x
, y
, true);
3553 /* If we can't find an integer mode, use multi words. */
3557 return emit_move_multi_word (mode
, x
, y
);
3560 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3561 return emit_move_ccmode (mode
, x
, y
);
3563 /* Try using a move pattern for the corresponding integer mode. This is
3564 only safe when simplify_subreg can convert MODE constants into integer
3565 constants. At present, it can only do this reliably if the value
3566 fits within a HOST_WIDE_INT. */
3567 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3569 rtx ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3573 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3578 return emit_move_multi_word (mode
, x
, y
);
3581 /* Generate code to copy Y into X.
3582 Both Y and X must have the same mode, except that
3583 Y can be a constant with VOIDmode.
3584 This mode cannot be BLKmode; use emit_block_move for that.
3586 Return the last instruction emitted. */
3589 emit_move_insn (rtx x
, rtx y
)
3591 enum machine_mode mode
= GET_MODE (x
);
3592 rtx y_cst
= NULL_RTX
;
3595 gcc_assert (mode
!= BLKmode
3596 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3601 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3602 && (last_insn
= compress_float_constant (x
, y
)))
3607 if (!targetm
.legitimate_constant_p (mode
, y
))
3609 y
= force_const_mem (mode
, y
);
3611 /* If the target's cannot_force_const_mem prevented the spill,
3612 assume that the target's move expanders will also take care
3613 of the non-legitimate constant. */
3617 y
= use_anchored_address (y
);
3621 /* If X or Y are memory references, verify that their addresses are valid
3624 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3626 && ! push_operand (x
, GET_MODE (x
))))
3627 x
= validize_mem (x
);
3630 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3631 MEM_ADDR_SPACE (y
)))
3632 y
= validize_mem (y
);
3634 gcc_assert (mode
!= BLKmode
);
3636 last_insn
= emit_move_insn_1 (x
, y
);
3638 if (y_cst
&& REG_P (x
)
3639 && (set
= single_set (last_insn
)) != NULL_RTX
3640 && SET_DEST (set
) == x
3641 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3642 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3647 /* If Y is representable exactly in a narrower mode, and the target can
3648 perform the extension directly from constant or memory, then emit the
3649 move as an extension. */
3652 compress_float_constant (rtx x
, rtx y
)
3654 enum machine_mode dstmode
= GET_MODE (x
);
3655 enum machine_mode orig_srcmode
= GET_MODE (y
);
3656 enum machine_mode srcmode
;
3658 int oldcost
, newcost
;
3659 bool speed
= optimize_insn_for_speed_p ();
3661 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3663 if (targetm
.legitimate_constant_p (dstmode
, y
))
3664 oldcost
= set_src_cost (y
, speed
);
3666 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), speed
);
3668 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3669 srcmode
!= orig_srcmode
;
3670 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3673 rtx trunc_y
, last_insn
;
3675 /* Skip if the target can't extend this way. */
3676 ic
= can_extend_p (dstmode
, srcmode
, 0);
3677 if (ic
== CODE_FOR_nothing
)
3680 /* Skip if the narrowed value isn't exact. */
3681 if (! exact_real_truncate (srcmode
, &r
))
3684 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3686 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3688 /* Skip if the target needs extra instructions to perform
3690 if (!insn_operand_matches (ic
, 1, trunc_y
))
3692 /* This is valid, but may not be cheaper than the original. */
3693 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3695 if (oldcost
< newcost
)
3698 else if (float_extend_from_mem
[dstmode
][srcmode
])
3700 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3701 /* This is valid, but may not be cheaper than the original. */
3702 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3704 if (oldcost
< newcost
)
3706 trunc_y
= validize_mem (trunc_y
);
3711 /* For CSE's benefit, force the compressed constant pool entry
3712 into a new pseudo. This constant may be used in different modes,
3713 and if not, combine will put things back together for us. */
3714 trunc_y
= force_reg (srcmode
, trunc_y
);
3715 emit_unop_insn (ic
, x
, trunc_y
, UNKNOWN
);
3716 last_insn
= get_last_insn ();
3719 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3727 /* Pushing data onto the stack. */
3729 /* Push a block of length SIZE (perhaps variable)
3730 and return an rtx to address the beginning of the block.
3731 The value may be virtual_outgoing_args_rtx.
3733 EXTRA is the number of bytes of padding to push in addition to SIZE.
3734 BELOW nonzero means this padding comes at low addresses;
3735 otherwise, the padding comes at high addresses. */
3738 push_block (rtx size
, int extra
, int below
)
3742 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3743 if (CONSTANT_P (size
))
3744 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3745 else if (REG_P (size
) && extra
== 0)
3746 anti_adjust_stack (size
);
3749 temp
= copy_to_mode_reg (Pmode
, size
);
3751 temp
= expand_binop (Pmode
, add_optab
, temp
,
3752 gen_int_mode (extra
, Pmode
),
3753 temp
, 0, OPTAB_LIB_WIDEN
);
3754 anti_adjust_stack (temp
);
3757 #ifndef STACK_GROWS_DOWNWARD
3763 temp
= virtual_outgoing_args_rtx
;
3764 if (extra
!= 0 && below
)
3765 temp
= plus_constant (Pmode
, temp
, extra
);
3769 if (CONST_INT_P (size
))
3770 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3771 -INTVAL (size
) - (below
? 0 : extra
));
3772 else if (extra
!= 0 && !below
)
3773 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3774 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3777 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3778 negate_rtx (Pmode
, size
));
3781 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3784 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3787 mem_autoinc_base (rtx mem
)
3791 rtx addr
= XEXP (mem
, 0);
3792 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3793 return XEXP (addr
, 0);
3798 /* A utility routine used here, in reload, and in try_split. The insns
3799 after PREV up to and including LAST are known to adjust the stack,
3800 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3801 placing notes as appropriate. PREV may be NULL, indicating the
3802 entire insn sequence prior to LAST should be scanned.
3804 The set of allowed stack pointer modifications is small:
3805 (1) One or more auto-inc style memory references (aka pushes),
3806 (2) One or more addition/subtraction with the SP as destination,
3807 (3) A single move insn with the SP as destination,
3808 (4) A call_pop insn,
3809 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3811 Insns in the sequence that do not modify the SP are ignored,
3812 except for noreturn calls.
3814 The return value is the amount of adjustment that can be trivially
3815 verified, via immediate operand or auto-inc. If the adjustment
3816 cannot be trivially extracted, the return value is INT_MIN. */
3819 find_args_size_adjust (rtx insn
)
3824 pat
= PATTERN (insn
);
3827 /* Look for a call_pop pattern. */
3830 /* We have to allow non-call_pop patterns for the case
3831 of emit_single_push_insn of a TLS address. */
3832 if (GET_CODE (pat
) != PARALLEL
)
3835 /* All call_pop have a stack pointer adjust in the parallel.
3836 The call itself is always first, and the stack adjust is
3837 usually last, so search from the end. */
3838 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3840 set
= XVECEXP (pat
, 0, i
);
3841 if (GET_CODE (set
) != SET
)
3843 dest
= SET_DEST (set
);
3844 if (dest
== stack_pointer_rtx
)
3847 /* We'd better have found the stack pointer adjust. */
3850 /* Fall through to process the extracted SET and DEST
3851 as if it was a standalone insn. */
3853 else if (GET_CODE (pat
) == SET
)
3855 else if ((set
= single_set (insn
)) != NULL
)
3857 else if (GET_CODE (pat
) == PARALLEL
)
3859 /* ??? Some older ports use a parallel with a stack adjust
3860 and a store for a PUSH_ROUNDING pattern, rather than a
3861 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3862 /* ??? See h8300 and m68k, pushqi1. */
3863 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3865 set
= XVECEXP (pat
, 0, i
);
3866 if (GET_CODE (set
) != SET
)
3868 dest
= SET_DEST (set
);
3869 if (dest
== stack_pointer_rtx
)
3872 /* We do not expect an auto-inc of the sp in the parallel. */
3873 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3874 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3875 != stack_pointer_rtx
);
3883 dest
= SET_DEST (set
);
3885 /* Look for direct modifications of the stack pointer. */
3886 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3888 /* Look for a trivial adjustment, otherwise assume nothing. */
3889 /* Note that the SPU restore_stack_block pattern refers to
3890 the stack pointer in V4SImode. Consider that non-trivial. */
3891 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3892 && GET_CODE (SET_SRC (set
)) == PLUS
3893 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3894 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3895 return INTVAL (XEXP (SET_SRC (set
), 1));
3896 /* ??? Reload can generate no-op moves, which will be cleaned
3897 up later. Recognize it and continue searching. */
3898 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3901 return HOST_WIDE_INT_MIN
;
3907 /* Otherwise only think about autoinc patterns. */
3908 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3911 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3912 != stack_pointer_rtx
);
3914 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3915 mem
= SET_SRC (set
);
3919 addr
= XEXP (mem
, 0);
3920 switch (GET_CODE (addr
))
3924 return GET_MODE_SIZE (GET_MODE (mem
));
3927 return -GET_MODE_SIZE (GET_MODE (mem
));
3930 addr
= XEXP (addr
, 1);
3931 gcc_assert (GET_CODE (addr
) == PLUS
);
3932 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3933 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3934 return INTVAL (XEXP (addr
, 1));
3942 fixup_args_size_notes (rtx prev
, rtx last
, int end_args_size
)
3944 int args_size
= end_args_size
;
3945 bool saw_unknown
= false;
3948 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3950 HOST_WIDE_INT this_delta
;
3952 if (!NONDEBUG_INSN_P (insn
))
3955 this_delta
= find_args_size_adjust (insn
);
3956 if (this_delta
== 0)
3959 || ACCUMULATE_OUTGOING_ARGS
3960 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3964 gcc_assert (!saw_unknown
);
3965 if (this_delta
== HOST_WIDE_INT_MIN
)
3968 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3969 #ifdef STACK_GROWS_DOWNWARD
3970 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3972 args_size
-= this_delta
;
3975 return saw_unknown
? INT_MIN
: args_size
;
3978 #ifdef PUSH_ROUNDING
3979 /* Emit single push insn. */
3982 emit_single_push_insn_1 (enum machine_mode mode
, rtx x
, tree type
)
3985 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3987 enum insn_code icode
;
3989 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3990 /* If there is push pattern, use it. Otherwise try old way of throwing
3991 MEM representing push operation to move expander. */
3992 icode
= optab_handler (push_optab
, mode
);
3993 if (icode
!= CODE_FOR_nothing
)
3995 struct expand_operand ops
[1];
3997 create_input_operand (&ops
[0], x
, mode
);
3998 if (maybe_expand_insn (icode
, 1, ops
))
4001 if (GET_MODE_SIZE (mode
) == rounded_size
)
4002 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
4003 /* If we are to pad downward, adjust the stack pointer first and
4004 then store X into the stack location using an offset. This is
4005 because emit_move_insn does not know how to pad; it does not have
4007 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
4009 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
4010 HOST_WIDE_INT offset
;
4012 emit_move_insn (stack_pointer_rtx
,
4013 expand_binop (Pmode
,
4014 #ifdef STACK_GROWS_DOWNWARD
4020 gen_int_mode (rounded_size
, Pmode
),
4021 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
4023 offset
= (HOST_WIDE_INT
) padding_size
;
4024 #ifdef STACK_GROWS_DOWNWARD
4025 if (STACK_PUSH_CODE
== POST_DEC
)
4026 /* We have already decremented the stack pointer, so get the
4028 offset
+= (HOST_WIDE_INT
) rounded_size
;
4030 if (STACK_PUSH_CODE
== POST_INC
)
4031 /* We have already incremented the stack pointer, so get the
4033 offset
-= (HOST_WIDE_INT
) rounded_size
;
4035 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4036 gen_int_mode (offset
, Pmode
));
4040 #ifdef STACK_GROWS_DOWNWARD
4041 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4042 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4043 gen_int_mode (-(HOST_WIDE_INT
) rounded_size
,
4046 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4047 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4048 gen_int_mode (rounded_size
, Pmode
));
4050 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
4053 dest
= gen_rtx_MEM (mode
, dest_addr
);
4057 set_mem_attributes (dest
, type
, 1);
4059 if (flag_optimize_sibling_calls
)
4060 /* Function incoming arguments may overlap with sibling call
4061 outgoing arguments and we cannot allow reordering of reads
4062 from function arguments with stores to outgoing arguments
4063 of sibling calls. */
4064 set_mem_alias_set (dest
, 0);
4066 emit_move_insn (dest
, x
);
4069 /* Emit and annotate a single push insn. */
4072 emit_single_push_insn (enum machine_mode mode
, rtx x
, tree type
)
4074 int delta
, old_delta
= stack_pointer_delta
;
4075 rtx prev
= get_last_insn ();
4078 emit_single_push_insn_1 (mode
, x
, type
);
4080 last
= get_last_insn ();
4082 /* Notice the common case where we emitted exactly one insn. */
4083 if (PREV_INSN (last
) == prev
)
4085 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
4089 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
4090 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
4094 /* Generate code to push X onto the stack, assuming it has mode MODE and
4096 MODE is redundant except when X is a CONST_INT (since they don't
4098 SIZE is an rtx for the size of data to be copied (in bytes),
4099 needed only if X is BLKmode.
4101 ALIGN (in bits) is maximum alignment we can assume.
4103 If PARTIAL and REG are both nonzero, then copy that many of the first
4104 bytes of X into registers starting with REG, and push the rest of X.
4105 The amount of space pushed is decreased by PARTIAL bytes.
4106 REG must be a hard register in this case.
4107 If REG is zero but PARTIAL is not, take any all others actions for an
4108 argument partially in registers, but do not actually load any
4111 EXTRA is the amount in bytes of extra space to leave next to this arg.
4112 This is ignored if an argument block has already been allocated.
4114 On a machine that lacks real push insns, ARGS_ADDR is the address of
4115 the bottom of the argument block for this call. We use indexing off there
4116 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4117 argument block has not been preallocated.
4119 ARGS_SO_FAR is the size of args previously pushed for this call.
4121 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4122 for arguments passed in registers. If nonzero, it will be the number
4123 of bytes required. */
4126 emit_push_insn (rtx x
, enum machine_mode mode
, tree type
, rtx size
,
4127 unsigned int align
, int partial
, rtx reg
, int extra
,
4128 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4132 enum direction stack_direction
4133 #ifdef STACK_GROWS_DOWNWARD
4139 /* Decide where to pad the argument: `downward' for below,
4140 `upward' for above, or `none' for don't pad it.
4141 Default is below for small data on big-endian machines; else above. */
4142 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4144 /* Invert direction if stack is post-decrement.
4146 if (STACK_PUSH_CODE
== POST_DEC
)
4147 if (where_pad
!= none
)
4148 where_pad
= (where_pad
== downward
? upward
: downward
);
4153 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4155 /* Copy a block into the stack, entirely or partially. */
4162 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4163 used
= partial
- offset
;
4165 if (mode
!= BLKmode
)
4167 /* A value is to be stored in an insufficiently aligned
4168 stack slot; copy via a suitably aligned slot if
4170 size
= GEN_INT (GET_MODE_SIZE (mode
));
4171 if (!MEM_P (xinner
))
4173 temp
= assign_temp (type
, 1, 1);
4174 emit_move_insn (temp
, xinner
);
4181 /* USED is now the # of bytes we need not copy to the stack
4182 because registers will take care of them. */
4185 xinner
= adjust_address (xinner
, BLKmode
, used
);
4187 /* If the partial register-part of the arg counts in its stack size,
4188 skip the part of stack space corresponding to the registers.
4189 Otherwise, start copying to the beginning of the stack space,
4190 by setting SKIP to 0. */
4191 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4193 #ifdef PUSH_ROUNDING
4194 /* Do it with several push insns if that doesn't take lots of insns
4195 and if there is no difficulty with push insns that skip bytes
4196 on the stack for alignment purposes. */
4199 && CONST_INT_P (size
)
4201 && MEM_ALIGN (xinner
) >= align
4202 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size
) - used
, align
))
4203 /* Here we avoid the case of a structure whose weak alignment
4204 forces many pushes of a small amount of data,
4205 and such small pushes do rounding that causes trouble. */
4206 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4207 || align
>= BIGGEST_ALIGNMENT
4208 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4209 == (align
/ BITS_PER_UNIT
)))
4210 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4212 /* Push padding now if padding above and stack grows down,
4213 or if padding below and stack grows up.
4214 But if space already allocated, this has already been done. */
4215 if (extra
&& args_addr
== 0
4216 && where_pad
!= none
&& where_pad
!= stack_direction
)
4217 anti_adjust_stack (GEN_INT (extra
));
4219 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4222 #endif /* PUSH_ROUNDING */
4226 /* Otherwise make space on the stack and copy the data
4227 to the address of that space. */
4229 /* Deduct words put into registers from the size we must copy. */
4232 if (CONST_INT_P (size
))
4233 size
= GEN_INT (INTVAL (size
) - used
);
4235 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4236 gen_int_mode (used
, GET_MODE (size
)),
4237 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4240 /* Get the address of the stack space.
4241 In this case, we do not deal with EXTRA separately.
4242 A single stack adjust will do. */
4245 temp
= push_block (size
, extra
, where_pad
== downward
);
4248 else if (CONST_INT_P (args_so_far
))
4249 temp
= memory_address (BLKmode
,
4250 plus_constant (Pmode
, args_addr
,
4251 skip
+ INTVAL (args_so_far
)));
4253 temp
= memory_address (BLKmode
,
4254 plus_constant (Pmode
,
4255 gen_rtx_PLUS (Pmode
,
4260 if (!ACCUMULATE_OUTGOING_ARGS
)
4262 /* If the source is referenced relative to the stack pointer,
4263 copy it to another register to stabilize it. We do not need
4264 to do this if we know that we won't be changing sp. */
4266 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4267 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4268 temp
= copy_to_reg (temp
);
4271 target
= gen_rtx_MEM (BLKmode
, temp
);
4273 /* We do *not* set_mem_attributes here, because incoming arguments
4274 may overlap with sibling call outgoing arguments and we cannot
4275 allow reordering of reads from function arguments with stores
4276 to outgoing arguments of sibling calls. We do, however, want
4277 to record the alignment of the stack slot. */
4278 /* ALIGN may well be better aligned than TYPE, e.g. due to
4279 PARM_BOUNDARY. Assume the caller isn't lying. */
4280 set_mem_align (target
, align
);
4282 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4285 else if (partial
> 0)
4287 /* Scalar partly in registers. */
4289 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4292 /* # bytes of start of argument
4293 that we must make space for but need not store. */
4294 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4295 int args_offset
= INTVAL (args_so_far
);
4298 /* Push padding now if padding above and stack grows down,
4299 or if padding below and stack grows up.
4300 But if space already allocated, this has already been done. */
4301 if (extra
&& args_addr
== 0
4302 && where_pad
!= none
&& where_pad
!= stack_direction
)
4303 anti_adjust_stack (GEN_INT (extra
));
4305 /* If we make space by pushing it, we might as well push
4306 the real data. Otherwise, we can leave OFFSET nonzero
4307 and leave the space uninitialized. */
4311 /* Now NOT_STACK gets the number of words that we don't need to
4312 allocate on the stack. Convert OFFSET to words too. */
4313 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4314 offset
/= UNITS_PER_WORD
;
4316 /* If the partial register-part of the arg counts in its stack size,
4317 skip the part of stack space corresponding to the registers.
4318 Otherwise, start copying to the beginning of the stack space,
4319 by setting SKIP to 0. */
4320 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4322 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4323 x
= validize_mem (force_const_mem (mode
, x
));
4325 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4326 SUBREGs of such registers are not allowed. */
4327 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4328 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4329 x
= copy_to_reg (x
);
4331 /* Loop over all the words allocated on the stack for this arg. */
4332 /* We can do it by words, because any scalar bigger than a word
4333 has a size a multiple of a word. */
4334 #ifndef PUSH_ARGS_REVERSED
4335 for (i
= not_stack
; i
< size
; i
++)
4337 for (i
= size
- 1; i
>= not_stack
; i
--)
4339 if (i
>= not_stack
+ offset
)
4340 emit_push_insn (operand_subword_force (x
, i
, mode
),
4341 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4343 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4345 reg_parm_stack_space
, alignment_pad
);
4352 /* Push padding now if padding above and stack grows down,
4353 or if padding below and stack grows up.
4354 But if space already allocated, this has already been done. */
4355 if (extra
&& args_addr
== 0
4356 && where_pad
!= none
&& where_pad
!= stack_direction
)
4357 anti_adjust_stack (GEN_INT (extra
));
4359 #ifdef PUSH_ROUNDING
4360 if (args_addr
== 0 && PUSH_ARGS
)
4361 emit_single_push_insn (mode
, x
, type
);
4365 if (CONST_INT_P (args_so_far
))
4367 = memory_address (mode
,
4368 plus_constant (Pmode
, args_addr
,
4369 INTVAL (args_so_far
)));
4371 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4373 dest
= gen_rtx_MEM (mode
, addr
);
4375 /* We do *not* set_mem_attributes here, because incoming arguments
4376 may overlap with sibling call outgoing arguments and we cannot
4377 allow reordering of reads from function arguments with stores
4378 to outgoing arguments of sibling calls. We do, however, want
4379 to record the alignment of the stack slot. */
4380 /* ALIGN may well be better aligned than TYPE, e.g. due to
4381 PARM_BOUNDARY. Assume the caller isn't lying. */
4382 set_mem_align (dest
, align
);
4384 emit_move_insn (dest
, x
);
4388 /* If part should go in registers, copy that part
4389 into the appropriate registers. Do this now, at the end,
4390 since mem-to-mem copies above may do function calls. */
4391 if (partial
> 0 && reg
!= 0)
4393 /* Handle calls that pass values in multiple non-contiguous locations.
4394 The Irix 6 ABI has examples of this. */
4395 if (GET_CODE (reg
) == PARALLEL
)
4396 emit_group_load (reg
, x
, type
, -1);
4399 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4400 move_block_to_reg (REGNO (reg
), x
, partial
/ UNITS_PER_WORD
, mode
);
4404 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4405 anti_adjust_stack (GEN_INT (extra
));
4407 if (alignment_pad
&& args_addr
== 0)
4408 anti_adjust_stack (alignment_pad
);
4411 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4415 get_subtarget (rtx x
)
4419 /* Only registers can be subtargets. */
4421 /* Don't use hard regs to avoid extending their life. */
4422 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4426 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4427 FIELD is a bitfield. Returns true if the optimization was successful,
4428 and there's nothing else to do. */
4431 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4432 unsigned HOST_WIDE_INT bitpos
,
4433 unsigned HOST_WIDE_INT bitregion_start
,
4434 unsigned HOST_WIDE_INT bitregion_end
,
4435 enum machine_mode mode1
, rtx str_rtx
,
4438 enum machine_mode str_mode
= GET_MODE (str_rtx
);
4439 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4444 enum tree_code code
;
4446 if (mode1
!= VOIDmode
4447 || bitsize
>= BITS_PER_WORD
4448 || str_bitsize
> BITS_PER_WORD
4449 || TREE_SIDE_EFFECTS (to
)
4450 || TREE_THIS_VOLATILE (to
))
4454 if (TREE_CODE (src
) != SSA_NAME
)
4456 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4459 srcstmt
= get_gimple_for_ssa_name (src
);
4461 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4464 code
= gimple_assign_rhs_code (srcstmt
);
4466 op0
= gimple_assign_rhs1 (srcstmt
);
4468 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4469 to find its initialization. Hopefully the initialization will
4470 be from a bitfield load. */
4471 if (TREE_CODE (op0
) == SSA_NAME
)
4473 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4475 /* We want to eventually have OP0 be the same as TO, which
4476 should be a bitfield. */
4478 || !is_gimple_assign (op0stmt
)
4479 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4481 op0
= gimple_assign_rhs1 (op0stmt
);
4484 op1
= gimple_assign_rhs2 (srcstmt
);
4486 if (!operand_equal_p (to
, op0
, 0))
4489 if (MEM_P (str_rtx
))
4491 unsigned HOST_WIDE_INT offset1
;
4493 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4494 str_mode
= word_mode
;
4495 str_mode
= get_best_mode (bitsize
, bitpos
,
4496 bitregion_start
, bitregion_end
,
4497 MEM_ALIGN (str_rtx
), str_mode
, 0);
4498 if (str_mode
== VOIDmode
)
4500 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4503 bitpos
%= str_bitsize
;
4504 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4505 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4507 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4510 /* If the bit field covers the whole REG/MEM, store_field
4511 will likely generate better code. */
4512 if (bitsize
>= str_bitsize
)
4515 /* We can't handle fields split across multiple entities. */
4516 if (bitpos
+ bitsize
> str_bitsize
)
4519 if (BYTES_BIG_ENDIAN
)
4520 bitpos
= str_bitsize
- bitpos
- bitsize
;
4526 /* For now, just optimize the case of the topmost bitfield
4527 where we don't need to do any masking and also
4528 1 bit bitfields where xor can be used.
4529 We might win by one instruction for the other bitfields
4530 too if insv/extv instructions aren't used, so that
4531 can be added later. */
4532 if (bitpos
+ bitsize
!= str_bitsize
4533 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4536 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4537 value
= convert_modes (str_mode
,
4538 TYPE_MODE (TREE_TYPE (op1
)), value
,
4539 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4541 /* We may be accessing data outside the field, which means
4542 we can alias adjacent data. */
4543 if (MEM_P (str_rtx
))
4545 str_rtx
= shallow_copy_rtx (str_rtx
);
4546 set_mem_alias_set (str_rtx
, 0);
4547 set_mem_expr (str_rtx
, 0);
4550 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4551 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4553 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4556 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4557 result
= expand_binop (str_mode
, binop
, str_rtx
,
4558 value
, str_rtx
, 1, OPTAB_WIDEN
);
4559 if (result
!= str_rtx
)
4560 emit_move_insn (str_rtx
, result
);
4565 if (TREE_CODE (op1
) != INTEGER_CST
)
4567 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4568 value
= convert_modes (str_mode
,
4569 TYPE_MODE (TREE_TYPE (op1
)), value
,
4570 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4572 /* We may be accessing data outside the field, which means
4573 we can alias adjacent data. */
4574 if (MEM_P (str_rtx
))
4576 str_rtx
= shallow_copy_rtx (str_rtx
);
4577 set_mem_alias_set (str_rtx
, 0);
4578 set_mem_expr (str_rtx
, 0);
4581 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4582 if (bitpos
+ bitsize
!= str_bitsize
)
4584 rtx mask
= gen_int_mode (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1,
4586 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4588 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4589 result
= expand_binop (str_mode
, binop
, str_rtx
,
4590 value
, str_rtx
, 1, OPTAB_WIDEN
);
4591 if (result
!= str_rtx
)
4592 emit_move_insn (str_rtx
, result
);
4602 /* In the C++ memory model, consecutive bit fields in a structure are
4603 considered one memory location.
4605 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4606 returns the bit range of consecutive bits in which this COMPONENT_REF
4607 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4608 and *OFFSET may be adjusted in the process.
4610 If the access does not need to be restricted, 0 is returned in both
4611 *BITSTART and *BITEND. */
4614 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4615 unsigned HOST_WIDE_INT
*bitend
,
4617 HOST_WIDE_INT
*bitpos
,
4620 HOST_WIDE_INT bitoffset
;
4623 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4625 field
= TREE_OPERAND (exp
, 1);
4626 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4627 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4628 need to limit the range we can access. */
4631 *bitstart
= *bitend
= 0;
4635 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4636 part of a larger bit field, then the representative does not serve any
4637 useful purpose. This can occur in Ada. */
4638 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4640 enum machine_mode rmode
;
4641 HOST_WIDE_INT rbitsize
, rbitpos
;
4645 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4646 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4647 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4649 *bitstart
= *bitend
= 0;
4654 /* Compute the adjustment to bitpos from the offset of the field
4655 relative to the representative. DECL_FIELD_OFFSET of field and
4656 repr are the same by construction if they are not constants,
4657 see finish_bitfield_layout. */
4658 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
4659 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
4660 bitoffset
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
4661 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
4664 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
4665 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
4667 /* If the adjustment is larger than bitpos, we would have a negative bit
4668 position for the lower bound and this may wreak havoc later. Adjust
4669 offset and bitpos to make the lower bound non-negative in that case. */
4670 if (bitoffset
> *bitpos
)
4672 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4673 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4676 if (*offset
== NULL_TREE
)
4677 *offset
= size_int (-adjust
/ BITS_PER_UNIT
);
4680 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4684 *bitstart
= *bitpos
- bitoffset
;
4686 *bitend
= *bitstart
+ tree_to_uhwi (DECL_SIZE (repr
)) - 1;
4689 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4690 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4691 DECL_RTL was not set yet, return NORTL. */
4694 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4696 if (TREE_CODE (addr
) != ADDR_EXPR
)
4699 tree base
= TREE_OPERAND (addr
, 0);
4702 || TREE_ADDRESSABLE (base
)
4703 || DECL_MODE (base
) == BLKmode
)
4706 if (!DECL_RTL_SET_P (base
))
4709 return (!MEM_P (DECL_RTL (base
)));
4712 /* Returns true if the MEM_REF REF refers to an object that does not
4713 reside in memory and has non-BLKmode. */
4716 mem_ref_refers_to_non_mem_p (tree ref
)
4718 tree base
= TREE_OPERAND (ref
, 0);
4719 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4722 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4723 is true, try generating a nontemporal store. */
4726 expand_assignment (tree to
, tree from
, bool nontemporal
)
4730 enum machine_mode mode
;
4732 enum insn_code icode
;
4734 /* Don't crash if the lhs of the assignment was erroneous. */
4735 if (TREE_CODE (to
) == ERROR_MARK
)
4737 expand_normal (from
);
4741 /* Optimize away no-op moves without side-effects. */
4742 if (operand_equal_p (to
, from
, 0))
4745 /* Handle misaligned stores. */
4746 mode
= TYPE_MODE (TREE_TYPE (to
));
4747 if ((TREE_CODE (to
) == MEM_REF
4748 || TREE_CODE (to
) == TARGET_MEM_REF
)
4750 && !mem_ref_refers_to_non_mem_p (to
)
4751 && ((align
= get_object_alignment (to
))
4752 < GET_MODE_ALIGNMENT (mode
))
4753 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4754 != CODE_FOR_nothing
)
4755 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4759 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4760 reg
= force_not_mem (reg
);
4761 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4763 if (icode
!= CODE_FOR_nothing
)
4765 struct expand_operand ops
[2];
4767 create_fixed_operand (&ops
[0], mem
);
4768 create_input_operand (&ops
[1], reg
, mode
);
4769 /* The movmisalign<mode> pattern cannot fail, else the assignment
4770 would silently be omitted. */
4771 expand_insn (icode
, 2, ops
);
4774 store_bit_field (mem
, GET_MODE_BITSIZE (mode
),
4775 0, 0, 0, mode
, reg
);
4779 /* Assignment of a structure component needs special treatment
4780 if the structure component's rtx is not simply a MEM.
4781 Assignment of an array element at a constant index, and assignment of
4782 an array element in an unaligned packed structure field, has the same
4783 problem. Same for (partially) storing into a non-memory object. */
4784 if (handled_component_p (to
)
4785 || (TREE_CODE (to
) == MEM_REF
4786 && mem_ref_refers_to_non_mem_p (to
))
4787 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4789 enum machine_mode mode1
;
4790 HOST_WIDE_INT bitsize
, bitpos
;
4791 unsigned HOST_WIDE_INT bitregion_start
= 0;
4792 unsigned HOST_WIDE_INT bitregion_end
= 0;
4799 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4800 &unsignedp
, &volatilep
, true);
4802 /* Make sure bitpos is not negative, it can wreak havoc later. */
4805 gcc_assert (offset
== NULL_TREE
);
4806 offset
= size_int (bitpos
>> (BITS_PER_UNIT
== 8
4807 ? 3 : exact_log2 (BITS_PER_UNIT
)));
4808 bitpos
&= BITS_PER_UNIT
- 1;
4811 if (TREE_CODE (to
) == COMPONENT_REF
4812 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4813 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4815 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4817 /* If the bitfield is volatile, we want to access it in the
4818 field's mode, not the computed mode.
4819 If a MEM has VOIDmode (external with incomplete type),
4820 use BLKmode for it instead. */
4823 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
4824 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4825 else if (GET_MODE (to_rtx
) == VOIDmode
)
4826 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4831 enum machine_mode address_mode
;
4834 if (!MEM_P (to_rtx
))
4836 /* We can get constant negative offsets into arrays with broken
4837 user code. Translate this to a trap instead of ICEing. */
4838 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4839 expand_builtin_trap ();
4840 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4843 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4844 address_mode
= get_address_mode (to_rtx
);
4845 if (GET_MODE (offset_rtx
) != address_mode
)
4846 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4848 /* A constant address in TO_RTX can have VOIDmode, we must not try
4849 to call force_reg for that case. Avoid that case. */
4851 && GET_MODE (to_rtx
) == BLKmode
4852 && GET_MODE (XEXP (to_rtx
, 0)) != VOIDmode
4854 && (bitpos
% bitsize
) == 0
4855 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4856 && MEM_ALIGN (to_rtx
) == GET_MODE_ALIGNMENT (mode1
))
4858 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4862 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4863 highest_pow2_factor_for_target (to
,
4867 /* No action is needed if the target is not a memory and the field
4868 lies completely outside that target. This can occur if the source
4869 code contains an out-of-bounds access to a small array. */
4871 && GET_MODE (to_rtx
) != BLKmode
4872 && (unsigned HOST_WIDE_INT
) bitpos
4873 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4875 expand_normal (from
);
4878 /* Handle expand_expr of a complex value returning a CONCAT. */
4879 else if (GET_CODE (to_rtx
) == CONCAT
)
4881 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4882 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4884 && bitsize
== mode_bitsize
)
4885 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4886 else if (bitsize
== mode_bitsize
/ 2
4887 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4888 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4890 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4891 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4892 bitregion_start
, bitregion_end
,
4894 get_alias_set (to
), nontemporal
);
4895 else if (bitpos
>= mode_bitsize
/ 2)
4896 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4897 bitpos
- mode_bitsize
/ 2,
4898 bitregion_start
, bitregion_end
,
4900 get_alias_set (to
), nontemporal
);
4901 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4904 result
= expand_normal (from
);
4905 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4906 TYPE_MODE (TREE_TYPE (from
)), 0);
4907 emit_move_insn (XEXP (to_rtx
, 0),
4908 read_complex_part (from_rtx
, false));
4909 emit_move_insn (XEXP (to_rtx
, 1),
4910 read_complex_part (from_rtx
, true));
4914 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4915 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4916 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4917 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4918 result
= store_field (temp
, bitsize
, bitpos
,
4919 bitregion_start
, bitregion_end
,
4921 get_alias_set (to
), nontemporal
);
4922 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4923 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
4930 /* If the field is at offset zero, we could have been given the
4931 DECL_RTX of the parent struct. Don't munge it. */
4932 to_rtx
= shallow_copy_rtx (to_rtx
);
4933 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
4935 MEM_VOLATILE_P (to_rtx
) = 1;
4938 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
4939 bitregion_start
, bitregion_end
,
4944 result
= store_field (to_rtx
, bitsize
, bitpos
,
4945 bitregion_start
, bitregion_end
,
4947 get_alias_set (to
), nontemporal
);
4951 preserve_temp_slots (result
);
4956 /* If the rhs is a function call and its value is not an aggregate,
4957 call the function before we start to compute the lhs.
4958 This is needed for correct code for cases such as
4959 val = setjmp (buf) on machines where reference to val
4960 requires loading up part of an address in a separate insn.
4962 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4963 since it might be a promoted variable where the zero- or sign- extension
4964 needs to be done. Handling this in the normal way is safe because no
4965 computation is done before the call. The same is true for SSA names. */
4966 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
4967 && COMPLETE_TYPE_P (TREE_TYPE (from
))
4968 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
4969 && ! (((TREE_CODE (to
) == VAR_DECL
4970 || TREE_CODE (to
) == PARM_DECL
4971 || TREE_CODE (to
) == RESULT_DECL
)
4972 && REG_P (DECL_RTL (to
)))
4973 || TREE_CODE (to
) == SSA_NAME
))
4978 value
= expand_normal (from
);
4980 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4982 /* Handle calls that return values in multiple non-contiguous locations.
4983 The Irix 6 ABI has examples of this. */
4984 if (GET_CODE (to_rtx
) == PARALLEL
)
4986 if (GET_CODE (value
) == PARALLEL
)
4987 emit_group_move (to_rtx
, value
);
4989 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
4990 int_size_in_bytes (TREE_TYPE (from
)));
4992 else if (GET_CODE (value
) == PARALLEL
)
4993 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
4994 int_size_in_bytes (TREE_TYPE (from
)));
4995 else if (GET_MODE (to_rtx
) == BLKmode
)
4997 /* Handle calls that return BLKmode values in registers. */
4999 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
5001 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
5005 if (POINTER_TYPE_P (TREE_TYPE (to
)))
5006 value
= convert_memory_address_addr_space
5007 (GET_MODE (to_rtx
), value
,
5008 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
5010 emit_move_insn (to_rtx
, value
);
5012 preserve_temp_slots (to_rtx
);
5017 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5018 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5020 /* Don't move directly into a return register. */
5021 if (TREE_CODE (to
) == RESULT_DECL
5022 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
5028 /* If the source is itself a return value, it still is in a pseudo at
5029 this point so we can move it back to the return register directly. */
5031 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
5032 && TREE_CODE (from
) != CALL_EXPR
)
5033 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
5035 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
5037 /* Handle calls that return values in multiple non-contiguous locations.
5038 The Irix 6 ABI has examples of this. */
5039 if (GET_CODE (to_rtx
) == PARALLEL
)
5041 if (GET_CODE (temp
) == PARALLEL
)
5042 emit_group_move (to_rtx
, temp
);
5044 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
5045 int_size_in_bytes (TREE_TYPE (from
)));
5048 emit_move_insn (to_rtx
, temp
);
5050 preserve_temp_slots (to_rtx
);
5055 /* In case we are returning the contents of an object which overlaps
5056 the place the value is being stored, use a safe function when copying
5057 a value through a pointer into a structure value return block. */
5058 if (TREE_CODE (to
) == RESULT_DECL
5059 && TREE_CODE (from
) == INDIRECT_REF
5060 && ADDR_SPACE_GENERIC_P
5061 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5062 && refs_may_alias_p (to
, from
)
5063 && cfun
->returns_struct
5064 && !cfun
->returns_pcc_struct
)
5069 size
= expr_size (from
);
5070 from_rtx
= expand_normal (from
);
5072 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
5073 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
5074 XEXP (from_rtx
, 0), Pmode
,
5075 convert_to_mode (TYPE_MODE (sizetype
),
5076 size
, TYPE_UNSIGNED (sizetype
)),
5077 TYPE_MODE (sizetype
));
5079 preserve_temp_slots (to_rtx
);
5084 /* Compute FROM and store the value in the rtx we got. */
5087 result
= store_expr (from
, to_rtx
, 0, nontemporal
);
5088 preserve_temp_slots (result
);
5093 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5094 succeeded, false otherwise. */
5097 emit_storent_insn (rtx to
, rtx from
)
5099 struct expand_operand ops
[2];
5100 enum machine_mode mode
= GET_MODE (to
);
5101 enum insn_code code
= optab_handler (storent_optab
, mode
);
5103 if (code
== CODE_FOR_nothing
)
5106 create_fixed_operand (&ops
[0], to
);
5107 create_input_operand (&ops
[1], from
, mode
);
5108 return maybe_expand_insn (code
, 2, ops
);
5111 /* Generate code for computing expression EXP,
5112 and storing the value into TARGET.
5114 If the mode is BLKmode then we may return TARGET itself.
5115 It turns out that in BLKmode it doesn't cause a problem.
5116 because C has no operators that could combine two different
5117 assignments into the same BLKmode object with different values
5118 with no sequence point. Will other languages need this to
5121 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5122 stack, and block moves may need to be treated specially.
5124 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5127 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5130 rtx alt_rtl
= NULL_RTX
;
5131 location_t loc
= curr_insn_location ();
5133 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5135 /* C++ can generate ?: expressions with a throw expression in one
5136 branch and an rvalue in the other. Here, we resolve attempts to
5137 store the throw expression's nonexistent result. */
5138 gcc_assert (!call_param_p
);
5139 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5142 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5144 /* Perform first part of compound expression, then assign from second
5146 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5147 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5148 return store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5151 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5153 /* For conditional expression, get safe form of the target. Then
5154 test the condition, doing the appropriate assignment on either
5155 side. This avoids the creation of unnecessary temporaries.
5156 For non-BLKmode, it is more efficient not to do this. */
5158 rtx lab1
= gen_label_rtx (), lab2
= gen_label_rtx ();
5160 do_pending_stack_adjust ();
5162 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5163 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5165 emit_jump_insn (gen_jump (lab2
));
5168 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5175 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5176 /* If this is a scalar in a register that is stored in a wider mode
5177 than the declared mode, compute the result into its declared mode
5178 and then convert to the wider mode. Our value is the computed
5181 rtx inner_target
= 0;
5183 /* We can do the conversion inside EXP, which will often result
5184 in some optimizations. Do the conversion in two steps: first
5185 change the signedness, if needed, then the extend. But don't
5186 do this if the type of EXP is a subtype of something else
5187 since then the conversion might involve more than just
5188 converting modes. */
5189 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5190 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5191 && GET_MODE_PRECISION (GET_MODE (target
))
5192 == TYPE_PRECISION (TREE_TYPE (exp
)))
5194 if (TYPE_UNSIGNED (TREE_TYPE (exp
))
5195 != SUBREG_PROMOTED_UNSIGNED_P (target
))
5197 /* Some types, e.g. Fortran's logical*4, won't have a signed
5198 version, so use the mode instead. */
5200 = (signed_or_unsigned_type_for
5201 (SUBREG_PROMOTED_UNSIGNED_P (target
), TREE_TYPE (exp
)));
5203 ntype
= lang_hooks
.types
.type_for_mode
5204 (TYPE_MODE (TREE_TYPE (exp
)),
5205 SUBREG_PROMOTED_UNSIGNED_P (target
));
5207 exp
= fold_convert_loc (loc
, ntype
, exp
);
5210 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5211 (GET_MODE (SUBREG_REG (target
)),
5212 SUBREG_PROMOTED_UNSIGNED_P (target
)),
5215 inner_target
= SUBREG_REG (target
);
5218 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5219 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5221 /* If TEMP is a VOIDmode constant, use convert_modes to make
5222 sure that we properly convert it. */
5223 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5225 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5226 temp
, SUBREG_PROMOTED_UNSIGNED_P (target
));
5227 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5228 GET_MODE (target
), temp
,
5229 SUBREG_PROMOTED_UNSIGNED_P (target
));
5232 convert_move (SUBREG_REG (target
), temp
,
5233 SUBREG_PROMOTED_UNSIGNED_P (target
));
5237 else if ((TREE_CODE (exp
) == STRING_CST
5238 || (TREE_CODE (exp
) == MEM_REF
5239 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5240 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5242 && integer_zerop (TREE_OPERAND (exp
, 1))))
5243 && !nontemporal
&& !call_param_p
5246 /* Optimize initialization of an array with a STRING_CST. */
5247 HOST_WIDE_INT exp_len
, str_copy_len
;
5249 tree str
= TREE_CODE (exp
) == STRING_CST
5250 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5252 exp_len
= int_expr_size (exp
);
5256 if (TREE_STRING_LENGTH (str
) <= 0)
5259 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5260 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5263 str_copy_len
= TREE_STRING_LENGTH (str
);
5264 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5265 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5267 str_copy_len
+= STORE_MAX_PIECES
- 1;
5268 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5270 str_copy_len
= MIN (str_copy_len
, exp_len
);
5271 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5272 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5273 MEM_ALIGN (target
), false))
5278 dest_mem
= store_by_pieces (dest_mem
,
5279 str_copy_len
, builtin_strncpy_read_str
,
5281 TREE_STRING_POINTER (str
)),
5282 MEM_ALIGN (target
), false,
5283 exp_len
> str_copy_len
? 1 : 0);
5284 if (exp_len
> str_copy_len
)
5285 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5286 GEN_INT (exp_len
- str_copy_len
),
5295 /* If we want to use a nontemporal store, force the value to
5297 tmp_target
= nontemporal
? NULL_RTX
: target
;
5298 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5300 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5304 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5305 the same as that of TARGET, adjust the constant. This is needed, for
5306 example, in case it is a CONST_DOUBLE and we want only a word-sized
5308 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5309 && TREE_CODE (exp
) != ERROR_MARK
5310 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5311 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5312 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5314 /* If value was not generated in the target, store it there.
5315 Convert the value to TARGET's type first if necessary and emit the
5316 pending incrementations that have been queued when expanding EXP.
5317 Note that we cannot emit the whole queue blindly because this will
5318 effectively disable the POST_INC optimization later.
5320 If TEMP and TARGET compare equal according to rtx_equal_p, but
5321 one or both of them are volatile memory refs, we have to distinguish
5323 - expand_expr has used TARGET. In this case, we must not generate
5324 another copy. This can be detected by TARGET being equal according
5326 - expand_expr has not used TARGET - that means that the source just
5327 happens to have the same RTX form. Since temp will have been created
5328 by expand_expr, it will compare unequal according to == .
5329 We must generate a copy in this case, to reach the correct number
5330 of volatile memory references. */
5332 if ((! rtx_equal_p (temp
, target
)
5333 || (temp
!= target
&& (side_effects_p (temp
)
5334 || side_effects_p (target
))))
5335 && TREE_CODE (exp
) != ERROR_MARK
5336 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5337 but TARGET is not valid memory reference, TEMP will differ
5338 from TARGET although it is really the same location. */
5340 && rtx_equal_p (alt_rtl
, target
)
5341 && !side_effects_p (alt_rtl
)
5342 && !side_effects_p (target
))
5343 /* If there's nothing to copy, don't bother. Don't call
5344 expr_size unless necessary, because some front-ends (C++)
5345 expr_size-hook must not be given objects that are not
5346 supposed to be bit-copied or bit-initialized. */
5347 && expr_size (exp
) != const0_rtx
)
5349 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5351 if (GET_MODE (target
) == BLKmode
)
5353 /* Handle calls that return BLKmode values in registers. */
5354 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5355 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5357 store_bit_field (target
,
5358 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5359 0, 0, 0, GET_MODE (temp
), temp
);
5362 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5365 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5367 /* Handle copying a string constant into an array. The string
5368 constant may be shorter than the array. So copy just the string's
5369 actual length, and clear the rest. First get the size of the data
5370 type of the string, which is actually the size of the target. */
5371 rtx size
= expr_size (exp
);
5373 if (CONST_INT_P (size
)
5374 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5375 emit_block_move (target
, temp
, size
,
5377 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5380 enum machine_mode pointer_mode
5381 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5382 enum machine_mode address_mode
= get_address_mode (target
);
5384 /* Compute the size of the data to copy from the string. */
5386 = size_binop_loc (loc
, MIN_EXPR
,
5387 make_tree (sizetype
, size
),
5388 size_int (TREE_STRING_LENGTH (exp
)));
5390 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5392 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5395 /* Copy that much. */
5396 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5397 TYPE_UNSIGNED (sizetype
));
5398 emit_block_move (target
, temp
, copy_size_rtx
,
5400 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5402 /* Figure out how much is left in TARGET that we have to clear.
5403 Do all calculations in pointer_mode. */
5404 if (CONST_INT_P (copy_size_rtx
))
5406 size
= plus_constant (address_mode
, size
,
5407 -INTVAL (copy_size_rtx
));
5408 target
= adjust_address (target
, BLKmode
,
5409 INTVAL (copy_size_rtx
));
5413 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5414 copy_size_rtx
, NULL_RTX
, 0,
5417 if (GET_MODE (copy_size_rtx
) != address_mode
)
5418 copy_size_rtx
= convert_to_mode (address_mode
,
5420 TYPE_UNSIGNED (sizetype
));
5422 target
= offset_address (target
, copy_size_rtx
,
5423 highest_pow2_factor (copy_size
));
5424 label
= gen_label_rtx ();
5425 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5426 GET_MODE (size
), 0, label
);
5429 if (size
!= const0_rtx
)
5430 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5436 /* Handle calls that return values in multiple non-contiguous locations.
5437 The Irix 6 ABI has examples of this. */
5438 else if (GET_CODE (target
) == PARALLEL
)
5440 if (GET_CODE (temp
) == PARALLEL
)
5441 emit_group_move (target
, temp
);
5443 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5444 int_size_in_bytes (TREE_TYPE (exp
)));
5446 else if (GET_CODE (temp
) == PARALLEL
)
5447 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5448 int_size_in_bytes (TREE_TYPE (exp
)));
5449 else if (GET_MODE (temp
) == BLKmode
)
5450 emit_block_move (target
, temp
, expr_size (exp
),
5452 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5453 /* If we emit a nontemporal store, there is nothing else to do. */
5454 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5458 temp
= force_operand (temp
, target
);
5460 emit_move_insn (target
, temp
);
5467 /* Return true if field F of structure TYPE is a flexible array. */
5470 flexible_array_member_p (const_tree f
, const_tree type
)
5475 return (DECL_CHAIN (f
) == NULL
5476 && TREE_CODE (tf
) == ARRAY_TYPE
5478 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5479 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5480 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5481 && int_size_in_bytes (type
) >= 0);
5484 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5485 must have in order for it to completely initialize a value of type TYPE.
5486 Return -1 if the number isn't known.
5488 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5490 static HOST_WIDE_INT
5491 count_type_elements (const_tree type
, bool for_ctor_p
)
5493 switch (TREE_CODE (type
))
5499 nelts
= array_type_nelts (type
);
5500 if (nelts
&& tree_fits_uhwi_p (nelts
))
5502 unsigned HOST_WIDE_INT n
;
5504 n
= tree_to_uhwi (nelts
) + 1;
5505 if (n
== 0 || for_ctor_p
)
5508 return n
* count_type_elements (TREE_TYPE (type
), false);
5510 return for_ctor_p
? -1 : 1;
5515 unsigned HOST_WIDE_INT n
;
5519 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5520 if (TREE_CODE (f
) == FIELD_DECL
)
5523 n
+= count_type_elements (TREE_TYPE (f
), false);
5524 else if (!flexible_array_member_p (f
, type
))
5525 /* Don't count flexible arrays, which are not supposed
5526 to be initialized. */
5534 case QUAL_UNION_TYPE
:
5539 gcc_assert (!for_ctor_p
);
5540 /* Estimate the number of scalars in each field and pick the
5541 maximum. Other estimates would do instead; the idea is simply
5542 to make sure that the estimate is not sensitive to the ordering
5545 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5546 if (TREE_CODE (f
) == FIELD_DECL
)
5548 m
= count_type_elements (TREE_TYPE (f
), false);
5549 /* If the field doesn't span the whole union, add an extra
5550 scalar for the rest. */
5551 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5552 TYPE_SIZE (type
)) != 1)
5564 return TYPE_VECTOR_SUBPARTS (type
);
5568 case FIXED_POINT_TYPE
:
5573 case REFERENCE_TYPE
:
5589 /* Helper for categorize_ctor_elements. Identical interface. */
5592 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5593 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5595 unsigned HOST_WIDE_INT idx
;
5596 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5597 tree value
, purpose
, elt_type
;
5599 /* Whether CTOR is a valid constant initializer, in accordance with what
5600 initializer_constant_valid_p does. If inferred from the constructor
5601 elements, true until proven otherwise. */
5602 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5603 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5608 elt_type
= NULL_TREE
;
5610 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5612 HOST_WIDE_INT mult
= 1;
5614 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5616 tree lo_index
= TREE_OPERAND (purpose
, 0);
5617 tree hi_index
= TREE_OPERAND (purpose
, 1);
5619 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5620 mult
= (tree_to_uhwi (hi_index
)
5621 - tree_to_uhwi (lo_index
) + 1);
5624 elt_type
= TREE_TYPE (value
);
5626 switch (TREE_CODE (value
))
5630 HOST_WIDE_INT nz
= 0, ic
= 0;
5632 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5635 nz_elts
+= mult
* nz
;
5636 init_elts
+= mult
* ic
;
5638 if (const_from_elts_p
&& const_p
)
5639 const_p
= const_elt_p
;
5646 if (!initializer_zerop (value
))
5652 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5653 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5657 if (!initializer_zerop (TREE_REALPART (value
)))
5659 if (!initializer_zerop (TREE_IMAGPART (value
)))
5667 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5669 tree v
= VECTOR_CST_ELT (value
, i
);
5670 if (!initializer_zerop (v
))
5679 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5680 nz_elts
+= mult
* tc
;
5681 init_elts
+= mult
* tc
;
5683 if (const_from_elts_p
&& const_p
)
5684 const_p
= initializer_constant_valid_p (value
, elt_type
)
5691 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5692 num_fields
, elt_type
))
5693 *p_complete
= false;
5695 *p_nz_elts
+= nz_elts
;
5696 *p_init_elts
+= init_elts
;
5701 /* Examine CTOR to discover:
5702 * how many scalar fields are set to nonzero values,
5703 and place it in *P_NZ_ELTS;
5704 * how many scalar fields in total are in CTOR,
5705 and place it in *P_ELT_COUNT.
5706 * whether the constructor is complete -- in the sense that every
5707 meaningful byte is explicitly given a value --
5708 and place it in *P_COMPLETE.
5710 Return whether or not CTOR is a valid static constant initializer, the same
5711 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5714 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5715 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5721 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5724 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5725 of which had type LAST_TYPE. Each element was itself a complete
5726 initializer, in the sense that every meaningful byte was explicitly
5727 given a value. Return true if the same is true for the constructor
5731 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5732 const_tree last_type
)
5734 if (TREE_CODE (type
) == UNION_TYPE
5735 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5740 gcc_assert (num_elts
== 1 && last_type
);
5742 /* ??? We could look at each element of the union, and find the
5743 largest element. Which would avoid comparing the size of the
5744 initialized element against any tail padding in the union.
5745 Doesn't seem worth the effort... */
5746 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5749 return count_type_elements (type
, true) == num_elts
;
5752 /* Return 1 if EXP contains mostly (3/4) zeros. */
5755 mostly_zeros_p (const_tree exp
)
5757 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5759 HOST_WIDE_INT nz_elts
, init_elts
;
5762 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5763 return !complete_p
|| nz_elts
< init_elts
/ 4;
5766 return initializer_zerop (exp
);
5769 /* Return 1 if EXP contains all zeros. */
5772 all_zeros_p (const_tree exp
)
5774 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5776 HOST_WIDE_INT nz_elts
, init_elts
;
5779 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5780 return nz_elts
== 0;
5783 return initializer_zerop (exp
);
5786 /* Helper function for store_constructor.
5787 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5788 CLEARED is as for store_constructor.
5789 ALIAS_SET is the alias set to use for any stores.
5791 This provides a recursive shortcut back to store_constructor when it isn't
5792 necessary to go through store_field. This is so that we can pass through
5793 the cleared field to let store_constructor know that we may not have to
5794 clear a substructure if the outer structure has already been cleared. */
5797 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5798 HOST_WIDE_INT bitpos
, enum machine_mode mode
,
5799 tree exp
, int cleared
, alias_set_type alias_set
)
5801 if (TREE_CODE (exp
) == CONSTRUCTOR
5802 /* We can only call store_constructor recursively if the size and
5803 bit position are on a byte boundary. */
5804 && bitpos
% BITS_PER_UNIT
== 0
5805 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5806 /* If we have a nonzero bitpos for a register target, then we just
5807 let store_field do the bitfield handling. This is unlikely to
5808 generate unnecessary clear instructions anyways. */
5809 && (bitpos
== 0 || MEM_P (target
)))
5813 = adjust_address (target
,
5814 GET_MODE (target
) == BLKmode
5816 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5817 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5820 /* Update the alias set, if required. */
5821 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5822 && MEM_ALIAS_SET (target
) != 0)
5824 target
= copy_rtx (target
);
5825 set_mem_alias_set (target
, alias_set
);
5828 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5831 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5835 /* Returns the number of FIELD_DECLs in TYPE. */
5838 fields_length (const_tree type
)
5840 tree t
= TYPE_FIELDS (type
);
5843 for (; t
; t
= DECL_CHAIN (t
))
5844 if (TREE_CODE (t
) == FIELD_DECL
)
5851 /* Store the value of constructor EXP into the rtx TARGET.
5852 TARGET is either a REG or a MEM; we know it cannot conflict, since
5853 safe_from_p has been called.
5854 CLEARED is true if TARGET is known to have been zero'd.
5855 SIZE is the number of bytes of TARGET we are allowed to modify: this
5856 may not be the same as the size of EXP if we are assigning to a field
5857 which has been packed to exclude padding bits. */
5860 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5862 tree type
= TREE_TYPE (exp
);
5863 #ifdef WORD_REGISTER_OPERATIONS
5864 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5867 switch (TREE_CODE (type
))
5871 case QUAL_UNION_TYPE
:
5873 unsigned HOST_WIDE_INT idx
;
5876 /* If size is zero or the target is already cleared, do nothing. */
5877 if (size
== 0 || cleared
)
5879 /* We either clear the aggregate or indicate the value is dead. */
5880 else if ((TREE_CODE (type
) == UNION_TYPE
5881 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5882 && ! CONSTRUCTOR_ELTS (exp
))
5883 /* If the constructor is empty, clear the union. */
5885 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
5889 /* If we are building a static constructor into a register,
5890 set the initial value as zero so we can fold the value into
5891 a constant. But if more than one register is involved,
5892 this probably loses. */
5893 else if (REG_P (target
) && TREE_STATIC (exp
)
5894 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
5896 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5900 /* If the constructor has fewer fields than the structure or
5901 if we are initializing the structure to mostly zeros, clear
5902 the whole structure first. Don't do this if TARGET is a
5903 register whose mode size isn't equal to SIZE since
5904 clear_storage can't handle this case. */
5906 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
5907 != fields_length (type
))
5908 || mostly_zeros_p (exp
))
5910 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
5913 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5917 if (REG_P (target
) && !cleared
)
5918 emit_clobber (target
);
5920 /* Store each element of the constructor into the
5921 corresponding field of TARGET. */
5922 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
5924 enum machine_mode mode
;
5925 HOST_WIDE_INT bitsize
;
5926 HOST_WIDE_INT bitpos
= 0;
5928 rtx to_rtx
= target
;
5930 /* Just ignore missing fields. We cleared the whole
5931 structure, above, if any fields are missing. */
5935 if (cleared
&& initializer_zerop (value
))
5938 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
5939 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
5943 mode
= DECL_MODE (field
);
5944 if (DECL_BIT_FIELD (field
))
5947 offset
= DECL_FIELD_OFFSET (field
);
5948 if (tree_fits_shwi_p (offset
)
5949 && tree_fits_shwi_p (bit_position (field
)))
5951 bitpos
= int_bit_position (field
);
5955 bitpos
= tree_to_shwi (DECL_FIELD_BIT_OFFSET (field
));
5959 enum machine_mode address_mode
;
5963 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
5964 make_tree (TREE_TYPE (exp
),
5967 offset_rtx
= expand_normal (offset
);
5968 gcc_assert (MEM_P (to_rtx
));
5970 address_mode
= get_address_mode (to_rtx
);
5971 if (GET_MODE (offset_rtx
) != address_mode
)
5972 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
5974 to_rtx
= offset_address (to_rtx
, offset_rtx
,
5975 highest_pow2_factor (offset
));
5978 #ifdef WORD_REGISTER_OPERATIONS
5979 /* If this initializes a field that is smaller than a
5980 word, at the start of a word, try to widen it to a full
5981 word. This special case allows us to output C++ member
5982 function initializations in a form that the optimizers
5985 && bitsize
< BITS_PER_WORD
5986 && bitpos
% BITS_PER_WORD
== 0
5987 && GET_MODE_CLASS (mode
) == MODE_INT
5988 && TREE_CODE (value
) == INTEGER_CST
5990 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
5992 tree type
= TREE_TYPE (value
);
5994 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
5996 type
= lang_hooks
.types
.type_for_mode
5997 (word_mode
, TYPE_UNSIGNED (type
));
5998 value
= fold_convert (type
, value
);
6001 if (BYTES_BIG_ENDIAN
)
6003 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6004 build_int_cst (type
,
6005 BITS_PER_WORD
- bitsize
));
6006 bitsize
= BITS_PER_WORD
;
6011 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6012 && DECL_NONADDRESSABLE_P (field
))
6014 to_rtx
= copy_rtx (to_rtx
);
6015 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6018 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
6020 get_alias_set (TREE_TYPE (field
)));
6027 unsigned HOST_WIDE_INT i
;
6030 tree elttype
= TREE_TYPE (type
);
6032 HOST_WIDE_INT minelt
= 0;
6033 HOST_WIDE_INT maxelt
= 0;
6035 domain
= TYPE_DOMAIN (type
);
6036 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6037 && TYPE_MAX_VALUE (domain
)
6038 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6039 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6041 /* If we have constant bounds for the range of the type, get them. */
6044 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6045 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6048 /* If the constructor has fewer elements than the array, clear
6049 the whole array first. Similarly if this is static
6050 constructor of a non-BLKmode object. */
6053 else if (REG_P (target
) && TREE_STATIC (exp
))
6057 unsigned HOST_WIDE_INT idx
;
6059 HOST_WIDE_INT count
= 0, zero_count
= 0;
6060 need_to_clear
= ! const_bounds_p
;
6062 /* This loop is a more accurate version of the loop in
6063 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6064 is also needed to check for missing elements. */
6065 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6067 HOST_WIDE_INT this_node_count
;
6072 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6074 tree lo_index
= TREE_OPERAND (index
, 0);
6075 tree hi_index
= TREE_OPERAND (index
, 1);
6077 if (! tree_fits_uhwi_p (lo_index
)
6078 || ! tree_fits_uhwi_p (hi_index
))
6084 this_node_count
= (tree_to_uhwi (hi_index
)
6085 - tree_to_uhwi (lo_index
) + 1);
6088 this_node_count
= 1;
6090 count
+= this_node_count
;
6091 if (mostly_zeros_p (value
))
6092 zero_count
+= this_node_count
;
6095 /* Clear the entire array first if there are any missing
6096 elements, or if the incidence of zero elements is >=
6099 && (count
< maxelt
- minelt
+ 1
6100 || 4 * zero_count
>= 3 * count
))
6104 if (need_to_clear
&& size
> 0)
6107 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6109 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6113 if (!cleared
&& REG_P (target
))
6114 /* Inform later passes that the old value is dead. */
6115 emit_clobber (target
);
6117 /* Store each element of the constructor into the
6118 corresponding element of TARGET, determined by counting the
6120 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6122 enum machine_mode mode
;
6123 HOST_WIDE_INT bitsize
;
6124 HOST_WIDE_INT bitpos
;
6125 rtx xtarget
= target
;
6127 if (cleared
&& initializer_zerop (value
))
6130 mode
= TYPE_MODE (elttype
);
6131 if (mode
== BLKmode
)
6132 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6133 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6136 bitsize
= GET_MODE_BITSIZE (mode
);
6138 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6140 tree lo_index
= TREE_OPERAND (index
, 0);
6141 tree hi_index
= TREE_OPERAND (index
, 1);
6142 rtx index_r
, pos_rtx
;
6143 HOST_WIDE_INT lo
, hi
, count
;
6146 /* If the range is constant and "small", unroll the loop. */
6148 && tree_fits_shwi_p (lo_index
)
6149 && tree_fits_shwi_p (hi_index
)
6150 && (lo
= tree_to_shwi (lo_index
),
6151 hi
= tree_to_shwi (hi_index
),
6152 count
= hi
- lo
+ 1,
6155 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6156 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6159 lo
-= minelt
; hi
-= minelt
;
6160 for (; lo
<= hi
; lo
++)
6162 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6165 && !MEM_KEEP_ALIAS_SET_P (target
)
6166 && TREE_CODE (type
) == ARRAY_TYPE
6167 && TYPE_NONALIASED_COMPONENT (type
))
6169 target
= copy_rtx (target
);
6170 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6173 store_constructor_field
6174 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6175 get_alias_set (elttype
));
6180 rtx loop_start
= gen_label_rtx ();
6181 rtx loop_end
= gen_label_rtx ();
6184 expand_normal (hi_index
);
6186 index
= build_decl (EXPR_LOCATION (exp
),
6187 VAR_DECL
, NULL_TREE
, domain
);
6188 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6189 SET_DECL_RTL (index
, index_r
);
6190 store_expr (lo_index
, index_r
, 0, false);
6192 /* Build the head of the loop. */
6193 do_pending_stack_adjust ();
6194 emit_label (loop_start
);
6196 /* Assign value to element index. */
6198 fold_convert (ssizetype
,
6199 fold_build2 (MINUS_EXPR
,
6202 TYPE_MIN_VALUE (domain
)));
6205 size_binop (MULT_EXPR
, position
,
6206 fold_convert (ssizetype
,
6207 TYPE_SIZE_UNIT (elttype
)));
6209 pos_rtx
= expand_normal (position
);
6210 xtarget
= offset_address (target
, pos_rtx
,
6211 highest_pow2_factor (position
));
6212 xtarget
= adjust_address (xtarget
, mode
, 0);
6213 if (TREE_CODE (value
) == CONSTRUCTOR
)
6214 store_constructor (value
, xtarget
, cleared
,
6215 bitsize
/ BITS_PER_UNIT
);
6217 store_expr (value
, xtarget
, 0, false);
6219 /* Generate a conditional jump to exit the loop. */
6220 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6222 jumpif (exit_cond
, loop_end
, -1);
6224 /* Update the loop counter, and jump to the head of
6226 expand_assignment (index
,
6227 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6228 index
, integer_one_node
),
6231 emit_jump (loop_start
);
6233 /* Build the end of the loop. */
6234 emit_label (loop_end
);
6237 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6238 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6243 index
= ssize_int (1);
6246 index
= fold_convert (ssizetype
,
6247 fold_build2 (MINUS_EXPR
,
6250 TYPE_MIN_VALUE (domain
)));
6253 size_binop (MULT_EXPR
, index
,
6254 fold_convert (ssizetype
,
6255 TYPE_SIZE_UNIT (elttype
)));
6256 xtarget
= offset_address (target
,
6257 expand_normal (position
),
6258 highest_pow2_factor (position
));
6259 xtarget
= adjust_address (xtarget
, mode
, 0);
6260 store_expr (value
, xtarget
, 0, false);
6265 bitpos
= ((tree_to_shwi (index
) - minelt
)
6266 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6268 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6270 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6271 && TREE_CODE (type
) == ARRAY_TYPE
6272 && TYPE_NONALIASED_COMPONENT (type
))
6274 target
= copy_rtx (target
);
6275 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6277 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6278 cleared
, get_alias_set (elttype
));
6286 unsigned HOST_WIDE_INT idx
;
6287 constructor_elt
*ce
;
6290 int icode
= CODE_FOR_nothing
;
6291 tree elttype
= TREE_TYPE (type
);
6292 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6293 enum machine_mode eltmode
= TYPE_MODE (elttype
);
6294 HOST_WIDE_INT bitsize
;
6295 HOST_WIDE_INT bitpos
;
6296 rtvec vector
= NULL
;
6298 alias_set_type alias
;
6300 gcc_assert (eltmode
!= BLKmode
);
6302 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6303 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6305 enum machine_mode mode
= GET_MODE (target
);
6307 icode
= (int) optab_handler (vec_init_optab
, mode
);
6308 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6309 if (icode
!= CODE_FOR_nothing
)
6313 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6314 if (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
)
6316 icode
= CODE_FOR_nothing
;
6320 if (icode
!= CODE_FOR_nothing
)
6324 vector
= rtvec_alloc (n_elts
);
6325 for (i
= 0; i
< n_elts
; i
++)
6326 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6330 /* If the constructor has fewer elements than the vector,
6331 clear the whole array first. Similarly if this is static
6332 constructor of a non-BLKmode object. */
6335 else if (REG_P (target
) && TREE_STATIC (exp
))
6339 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6342 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6344 int n_elts_here
= tree_to_uhwi
6345 (int_const_binop (TRUNC_DIV_EXPR
,
6346 TYPE_SIZE (TREE_TYPE (value
)),
6347 TYPE_SIZE (elttype
)));
6349 count
+= n_elts_here
;
6350 if (mostly_zeros_p (value
))
6351 zero_count
+= n_elts_here
;
6354 /* Clear the entire vector first if there are any missing elements,
6355 or if the incidence of zero elements is >= 75%. */
6356 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6359 if (need_to_clear
&& size
> 0 && !vector
)
6362 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6364 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6368 /* Inform later passes that the old value is dead. */
6369 if (!cleared
&& !vector
&& REG_P (target
))
6370 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6373 alias
= MEM_ALIAS_SET (target
);
6375 alias
= get_alias_set (elttype
);
6377 /* Store each element of the constructor into the corresponding
6378 element of TARGET, determined by counting the elements. */
6379 for (idx
= 0, i
= 0;
6380 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6381 idx
++, i
+= bitsize
/ elt_size
)
6383 HOST_WIDE_INT eltpos
;
6384 tree value
= ce
->value
;
6386 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6387 if (cleared
&& initializer_zerop (value
))
6391 eltpos
= tree_to_uhwi (ce
->index
);
6397 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6399 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6400 RTVEC_ELT (vector
, eltpos
)
6401 = expand_normal (value
);
6405 enum machine_mode value_mode
=
6406 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6407 ? TYPE_MODE (TREE_TYPE (value
))
6409 bitpos
= eltpos
* elt_size
;
6410 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6411 value
, cleared
, alias
);
6416 emit_insn (GEN_FCN (icode
)
6418 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6427 /* Store the value of EXP (an expression tree)
6428 into a subfield of TARGET which has mode MODE and occupies
6429 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6430 If MODE is VOIDmode, it means that we are storing into a bit-field.
6432 BITREGION_START is bitpos of the first bitfield in this region.
6433 BITREGION_END is the bitpos of the ending bitfield in this region.
6434 These two fields are 0, if the C++ memory model does not apply,
6435 or we are not interested in keeping track of bitfield regions.
6437 Always return const0_rtx unless we have something particular to
6440 ALIAS_SET is the alias set for the destination. This value will
6441 (in general) be different from that for TARGET, since TARGET is a
6442 reference to the containing structure.
6444 If NONTEMPORAL is true, try generating a nontemporal store. */
6447 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6448 unsigned HOST_WIDE_INT bitregion_start
,
6449 unsigned HOST_WIDE_INT bitregion_end
,
6450 enum machine_mode mode
, tree exp
,
6451 alias_set_type alias_set
, bool nontemporal
)
6453 if (TREE_CODE (exp
) == ERROR_MARK
)
6456 /* If we have nothing to store, do nothing unless the expression has
6459 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6461 if (GET_CODE (target
) == CONCAT
)
6463 /* We're storing into a struct containing a single __complex. */
6465 gcc_assert (!bitpos
);
6466 return store_expr (exp
, target
, 0, nontemporal
);
6469 /* If the structure is in a register or if the component
6470 is a bit field, we cannot use addressing to access it.
6471 Use bit-field techniques or SUBREG to store in it. */
6473 if (mode
== VOIDmode
6474 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6475 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6476 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6478 || GET_CODE (target
) == SUBREG
6479 /* If the field isn't aligned enough to store as an ordinary memref,
6480 store it as a bit field. */
6482 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6483 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6484 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6485 || (bitpos
% BITS_PER_UNIT
!= 0)))
6486 || (bitsize
>= 0 && mode
!= BLKmode
6487 && GET_MODE_BITSIZE (mode
) > bitsize
)
6488 /* If the RHS and field are a constant size and the size of the
6489 RHS isn't the same size as the bitfield, we must use bitfield
6492 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6493 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6494 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6495 decl we must use bitfield operations. */
6497 && TREE_CODE (exp
) == MEM_REF
6498 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6499 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6500 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6501 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6506 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6507 implies a mask operation. If the precision is the same size as
6508 the field we're storing into, that mask is redundant. This is
6509 particularly common with bit field assignments generated by the
6511 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6514 tree type
= TREE_TYPE (exp
);
6515 if (INTEGRAL_TYPE_P (type
)
6516 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6517 && bitsize
== TYPE_PRECISION (type
))
6519 tree op
= gimple_assign_rhs1 (nop_def
);
6520 type
= TREE_TYPE (op
);
6521 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6526 temp
= expand_normal (exp
);
6528 /* If BITSIZE is narrower than the size of the type of EXP
6529 we will be narrowing TEMP. Normally, what's wanted are the
6530 low-order bits. However, if EXP's type is a record and this is
6531 big-endian machine, we want the upper BITSIZE bits. */
6532 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6533 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6534 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6535 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6536 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6539 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6540 if (mode
!= VOIDmode
&& mode
!= BLKmode
6541 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6542 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6544 /* If the modes of TEMP and TARGET are both BLKmode, both
6545 must be in memory and BITPOS must be aligned on a byte
6546 boundary. If so, we simply do a block copy. Likewise
6547 for a BLKmode-like TARGET. */
6548 if (GET_MODE (temp
) == BLKmode
6549 && (GET_MODE (target
) == BLKmode
6551 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6552 && (bitpos
% BITS_PER_UNIT
) == 0
6553 && (bitsize
% BITS_PER_UNIT
) == 0)))
6555 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6556 && (bitpos
% BITS_PER_UNIT
) == 0);
6558 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6559 emit_block_move (target
, temp
,
6560 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6567 /* Handle calls that return values in multiple non-contiguous locations.
6568 The Irix 6 ABI has examples of this. */
6569 if (GET_CODE (temp
) == PARALLEL
)
6571 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6573 if (mode
== BLKmode
)
6574 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6575 temp_target
= gen_reg_rtx (mode
);
6576 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6579 else if (mode
== BLKmode
)
6581 /* Handle calls that return BLKmode values in registers. */
6582 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6584 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6585 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6590 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6592 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6593 temp_target
= gen_reg_rtx (mode
);
6595 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6596 temp_target
, mode
, mode
);
6601 /* Store the value in the bitfield. */
6602 store_bit_field (target
, bitsize
, bitpos
,
6603 bitregion_start
, bitregion_end
,
6610 /* Now build a reference to just the desired component. */
6611 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6613 if (to_rtx
== target
)
6614 to_rtx
= copy_rtx (to_rtx
);
6616 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6617 set_mem_alias_set (to_rtx
, alias_set
);
6619 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6623 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6624 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6625 codes and find the ultimate containing object, which we return.
6627 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6628 bit position, and *PUNSIGNEDP to the signedness of the field.
6629 If the position of the field is variable, we store a tree
6630 giving the variable offset (in units) in *POFFSET.
6631 This offset is in addition to the bit position.
6632 If the position is not variable, we store 0 in *POFFSET.
6634 If any of the extraction expressions is volatile,
6635 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6637 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6638 Otherwise, it is a mode that can be used to access the field.
6640 If the field describes a variable-sized object, *PMODE is set to
6641 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6642 this case, but the address of the object can be found.
6644 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6645 look through nodes that serve as markers of a greater alignment than
6646 the one that can be deduced from the expression. These nodes make it
6647 possible for front-ends to prevent temporaries from being created by
6648 the middle-end on alignment considerations. For that purpose, the
6649 normal operating mode at high-level is to always pass FALSE so that
6650 the ultimate containing object is really returned; moreover, the
6651 associated predicate handled_component_p will always return TRUE
6652 on these nodes, thus indicating that they are essentially handled
6653 by get_inner_reference. TRUE should only be passed when the caller
6654 is scanning the expression in order to build another representation
6655 and specifically knows how to handle these nodes; as such, this is
6656 the normal operating mode in the RTL expanders. */
6659 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6660 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6661 enum machine_mode
*pmode
, int *punsignedp
,
6662 int *pvolatilep
, bool keep_aligning
)
6665 enum machine_mode mode
= VOIDmode
;
6666 bool blkmode_bitfield
= false;
6667 tree offset
= size_zero_node
;
6668 double_int bit_offset
= double_int_zero
;
6670 /* First get the mode, signedness, and size. We do this from just the
6671 outermost expression. */
6673 if (TREE_CODE (exp
) == COMPONENT_REF
)
6675 tree field
= TREE_OPERAND (exp
, 1);
6676 size_tree
= DECL_SIZE (field
);
6677 if (flag_strict_volatile_bitfields
> 0
6678 && TREE_THIS_VOLATILE (exp
)
6679 && DECL_BIT_FIELD_TYPE (field
)
6680 && DECL_MODE (field
) != BLKmode
)
6681 /* Volatile bitfields should be accessed in the mode of the
6682 field's type, not the mode computed based on the bit
6684 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6685 else if (!DECL_BIT_FIELD (field
))
6686 mode
= DECL_MODE (field
);
6687 else if (DECL_MODE (field
) == BLKmode
)
6688 blkmode_bitfield
= true;
6690 *punsignedp
= DECL_UNSIGNED (field
);
6692 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6694 size_tree
= TREE_OPERAND (exp
, 1);
6695 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6696 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6698 /* For vector types, with the correct size of access, use the mode of
6700 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6701 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6702 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6703 mode
= TYPE_MODE (TREE_TYPE (exp
));
6707 mode
= TYPE_MODE (TREE_TYPE (exp
));
6708 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6710 if (mode
== BLKmode
)
6711 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6713 *pbitsize
= GET_MODE_BITSIZE (mode
);
6718 if (! tree_fits_uhwi_p (size_tree
))
6719 mode
= BLKmode
, *pbitsize
= -1;
6721 *pbitsize
= tree_to_uhwi (size_tree
);
6724 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6725 and find the ultimate containing object. */
6728 switch (TREE_CODE (exp
))
6731 bit_offset
+= tree_to_double_int (TREE_OPERAND (exp
, 2));
6736 tree field
= TREE_OPERAND (exp
, 1);
6737 tree this_offset
= component_ref_field_offset (exp
);
6739 /* If this field hasn't been filled in yet, don't go past it.
6740 This should only happen when folding expressions made during
6741 type construction. */
6742 if (this_offset
== 0)
6745 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6746 bit_offset
+= tree_to_double_int (DECL_FIELD_BIT_OFFSET (field
));
6748 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6753 case ARRAY_RANGE_REF
:
6755 tree index
= TREE_OPERAND (exp
, 1);
6756 tree low_bound
= array_ref_low_bound (exp
);
6757 tree unit_size
= array_ref_element_size (exp
);
6759 /* We assume all arrays have sizes that are a multiple of a byte.
6760 First subtract the lower bound, if any, in the type of the
6761 index, then convert to sizetype and multiply by the size of
6762 the array element. */
6763 if (! integer_zerop (low_bound
))
6764 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6767 offset
= size_binop (PLUS_EXPR
, offset
,
6768 size_binop (MULT_EXPR
,
6769 fold_convert (sizetype
, index
),
6778 bit_offset
+= double_int::from_uhwi (*pbitsize
);
6781 case VIEW_CONVERT_EXPR
:
6782 if (keep_aligning
&& STRICT_ALIGNMENT
6783 && (TYPE_ALIGN (TREE_TYPE (exp
))
6784 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6785 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6786 < BIGGEST_ALIGNMENT
)
6787 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6788 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6793 /* Hand back the decl for MEM[&decl, off]. */
6794 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6796 tree off
= TREE_OPERAND (exp
, 1);
6797 if (!integer_zerop (off
))
6799 double_int boff
, coff
= mem_ref_offset (exp
);
6800 boff
= coff
.lshift (BITS_PER_UNIT
== 8
6801 ? 3 : exact_log2 (BITS_PER_UNIT
));
6804 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6812 /* If any reference in the chain is volatile, the effect is volatile. */
6813 if (TREE_THIS_VOLATILE (exp
))
6816 exp
= TREE_OPERAND (exp
, 0);
6820 /* If OFFSET is constant, see if we can return the whole thing as a
6821 constant bit position. Make sure to handle overflow during
6823 if (TREE_CODE (offset
) == INTEGER_CST
)
6825 double_int tem
= tree_to_double_int (offset
);
6826 tem
= tem
.sext (TYPE_PRECISION (sizetype
));
6827 tem
= tem
.lshift (BITS_PER_UNIT
== 8 ? 3 : exact_log2 (BITS_PER_UNIT
));
6829 if (tem
.fits_shwi ())
6831 *pbitpos
= tem
.to_shwi ();
6832 *poffset
= offset
= NULL_TREE
;
6836 /* Otherwise, split it up. */
6839 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6840 if (bit_offset
.is_negative ())
6843 = double_int::mask (BITS_PER_UNIT
== 8
6844 ? 3 : exact_log2 (BITS_PER_UNIT
));
6845 double_int tem
= bit_offset
.and_not (mask
);
6846 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6847 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6849 tem
= tem
.arshift (BITS_PER_UNIT
== 8
6850 ? 3 : exact_log2 (BITS_PER_UNIT
),
6851 HOST_BITS_PER_DOUBLE_INT
);
6852 offset
= size_binop (PLUS_EXPR
, offset
,
6853 double_int_to_tree (sizetype
, tem
));
6856 *pbitpos
= bit_offset
.to_shwi ();
6860 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6861 if (mode
== VOIDmode
6863 && (*pbitpos
% BITS_PER_UNIT
) == 0
6864 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6872 /* Return a tree of sizetype representing the size, in bytes, of the element
6873 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6876 array_ref_element_size (tree exp
)
6878 tree aligned_size
= TREE_OPERAND (exp
, 3);
6879 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6880 location_t loc
= EXPR_LOCATION (exp
);
6882 /* If a size was specified in the ARRAY_REF, it's the size measured
6883 in alignment units of the element type. So multiply by that value. */
6886 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6887 sizetype from another type of the same width and signedness. */
6888 if (TREE_TYPE (aligned_size
) != sizetype
)
6889 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
6890 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
6891 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
6894 /* Otherwise, take the size from that of the element type. Substitute
6895 any PLACEHOLDER_EXPR that we have. */
6897 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
6900 /* Return a tree representing the lower bound of the array mentioned in
6901 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6904 array_ref_low_bound (tree exp
)
6906 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6908 /* If a lower bound is specified in EXP, use it. */
6909 if (TREE_OPERAND (exp
, 2))
6910 return TREE_OPERAND (exp
, 2);
6912 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6913 substituting for a PLACEHOLDER_EXPR as needed. */
6914 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
6915 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
6917 /* Otherwise, return a zero of the appropriate type. */
6918 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
6921 /* Returns true if REF is an array reference to an array at the end of
6922 a structure. If this is the case, the array may be allocated larger
6923 than its upper bound implies. */
6926 array_at_struct_end_p (tree ref
)
6928 if (TREE_CODE (ref
) != ARRAY_REF
6929 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
6932 while (handled_component_p (ref
))
6934 /* If the reference chain contains a component reference to a
6935 non-union type and there follows another field the reference
6936 is not at the end of a structure. */
6937 if (TREE_CODE (ref
) == COMPONENT_REF
6938 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
6940 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
6941 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
6942 nextf
= DECL_CHAIN (nextf
);
6947 ref
= TREE_OPERAND (ref
, 0);
6950 /* If the reference is based on a declared entity, the size of the array
6951 is constrained by its given domain. */
6958 /* Return a tree representing the upper bound of the array mentioned in
6959 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6962 array_ref_up_bound (tree exp
)
6964 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6966 /* If there is a domain type and it has an upper bound, use it, substituting
6967 for a PLACEHOLDER_EXPR as needed. */
6968 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
6969 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
6971 /* Otherwise fail. */
6975 /* Return a tree representing the offset, in bytes, of the field referenced
6976 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6979 component_ref_field_offset (tree exp
)
6981 tree aligned_offset
= TREE_OPERAND (exp
, 2);
6982 tree field
= TREE_OPERAND (exp
, 1);
6983 location_t loc
= EXPR_LOCATION (exp
);
6985 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6986 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6990 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6991 sizetype from another type of the same width and signedness. */
6992 if (TREE_TYPE (aligned_offset
) != sizetype
)
6993 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
6994 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
6995 size_int (DECL_OFFSET_ALIGN (field
)
6999 /* Otherwise, take the offset from that of the field. Substitute
7000 any PLACEHOLDER_EXPR that we have. */
7002 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
7005 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
7007 static unsigned HOST_WIDE_INT
7008 target_align (const_tree target
)
7010 /* We might have a chain of nested references with intermediate misaligning
7011 bitfields components, so need to recurse to find out. */
7013 unsigned HOST_WIDE_INT this_align
, outer_align
;
7015 switch (TREE_CODE (target
))
7021 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7022 outer_align
= target_align (TREE_OPERAND (target
, 0));
7023 return MIN (this_align
, outer_align
);
7026 case ARRAY_RANGE_REF
:
7027 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7028 outer_align
= target_align (TREE_OPERAND (target
, 0));
7029 return MIN (this_align
, outer_align
);
7032 case NON_LVALUE_EXPR
:
7033 case VIEW_CONVERT_EXPR
:
7034 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7035 outer_align
= target_align (TREE_OPERAND (target
, 0));
7036 return MAX (this_align
, outer_align
);
7039 return TYPE_ALIGN (TREE_TYPE (target
));
7044 /* Given an rtx VALUE that may contain additions and multiplications, return
7045 an equivalent value that just refers to a register, memory, or constant.
7046 This is done by generating instructions to perform the arithmetic and
7047 returning a pseudo-register containing the value.
7049 The returned value may be a REG, SUBREG, MEM or constant. */
7052 force_operand (rtx value
, rtx target
)
7055 /* Use subtarget as the target for operand 0 of a binary operation. */
7056 rtx subtarget
= get_subtarget (target
);
7057 enum rtx_code code
= GET_CODE (value
);
7059 /* Check for subreg applied to an expression produced by loop optimizer. */
7061 && !REG_P (SUBREG_REG (value
))
7062 && !MEM_P (SUBREG_REG (value
)))
7065 = simplify_gen_subreg (GET_MODE (value
),
7066 force_reg (GET_MODE (SUBREG_REG (value
)),
7067 force_operand (SUBREG_REG (value
),
7069 GET_MODE (SUBREG_REG (value
)),
7070 SUBREG_BYTE (value
));
7071 code
= GET_CODE (value
);
7074 /* Check for a PIC address load. */
7075 if ((code
== PLUS
|| code
== MINUS
)
7076 && XEXP (value
, 0) == pic_offset_table_rtx
7077 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7078 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7079 || GET_CODE (XEXP (value
, 1)) == CONST
))
7082 subtarget
= gen_reg_rtx (GET_MODE (value
));
7083 emit_move_insn (subtarget
, value
);
7087 if (ARITHMETIC_P (value
))
7089 op2
= XEXP (value
, 1);
7090 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7092 if (code
== MINUS
&& CONST_INT_P (op2
))
7095 op2
= negate_rtx (GET_MODE (value
), op2
);
7098 /* Check for an addition with OP2 a constant integer and our first
7099 operand a PLUS of a virtual register and something else. In that
7100 case, we want to emit the sum of the virtual register and the
7101 constant first and then add the other value. This allows virtual
7102 register instantiation to simply modify the constant rather than
7103 creating another one around this addition. */
7104 if (code
== PLUS
&& CONST_INT_P (op2
)
7105 && GET_CODE (XEXP (value
, 0)) == PLUS
7106 && REG_P (XEXP (XEXP (value
, 0), 0))
7107 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7108 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7110 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7111 XEXP (XEXP (value
, 0), 0), op2
,
7112 subtarget
, 0, OPTAB_LIB_WIDEN
);
7113 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7114 force_operand (XEXP (XEXP (value
,
7116 target
, 0, OPTAB_LIB_WIDEN
);
7119 op1
= force_operand (XEXP (value
, 0), subtarget
);
7120 op2
= force_operand (op2
, NULL_RTX
);
7124 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7126 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7127 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7128 target
, 1, OPTAB_LIB_WIDEN
);
7130 return expand_divmod (0,
7131 FLOAT_MODE_P (GET_MODE (value
))
7132 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7133 GET_MODE (value
), op1
, op2
, target
, 0);
7135 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7138 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7141 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7144 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7145 target
, 0, OPTAB_LIB_WIDEN
);
7147 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7148 target
, 1, OPTAB_LIB_WIDEN
);
7151 if (UNARY_P (value
))
7154 target
= gen_reg_rtx (GET_MODE (value
));
7155 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7162 case FLOAT_TRUNCATE
:
7163 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7168 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7172 case UNSIGNED_FLOAT
:
7173 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7177 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7181 #ifdef INSN_SCHEDULING
7182 /* On machines that have insn scheduling, we want all memory reference to be
7183 explicit, so we need to deal with such paradoxical SUBREGs. */
7184 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7186 = simplify_gen_subreg (GET_MODE (value
),
7187 force_reg (GET_MODE (SUBREG_REG (value
)),
7188 force_operand (SUBREG_REG (value
),
7190 GET_MODE (SUBREG_REG (value
)),
7191 SUBREG_BYTE (value
));
7197 /* Subroutine of expand_expr: return nonzero iff there is no way that
7198 EXP can reference X, which is being modified. TOP_P is nonzero if this
7199 call is going to be used to determine whether we need a temporary
7200 for EXP, as opposed to a recursive call to this function.
7202 It is always safe for this routine to return zero since it merely
7203 searches for optimization opportunities. */
7206 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7212 /* If EXP has varying size, we MUST use a target since we currently
7213 have no way of allocating temporaries of variable size
7214 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7215 So we assume here that something at a higher level has prevented a
7216 clash. This is somewhat bogus, but the best we can do. Only
7217 do this when X is BLKmode and when we are at the top level. */
7218 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7219 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7220 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7221 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7222 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7224 && GET_MODE (x
) == BLKmode
)
7225 /* If X is in the outgoing argument area, it is always safe. */
7227 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7228 || (GET_CODE (XEXP (x
, 0)) == PLUS
7229 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7232 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7233 find the underlying pseudo. */
7234 if (GET_CODE (x
) == SUBREG
)
7237 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7241 /* Now look at our tree code and possibly recurse. */
7242 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7244 case tcc_declaration
:
7245 exp_rtl
= DECL_RTL_IF_SET (exp
);
7251 case tcc_exceptional
:
7252 if (TREE_CODE (exp
) == TREE_LIST
)
7256 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7258 exp
= TREE_CHAIN (exp
);
7261 if (TREE_CODE (exp
) != TREE_LIST
)
7262 return safe_from_p (x
, exp
, 0);
7265 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7267 constructor_elt
*ce
;
7268 unsigned HOST_WIDE_INT idx
;
7270 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7271 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7272 || !safe_from_p (x
, ce
->value
, 0))
7276 else if (TREE_CODE (exp
) == ERROR_MARK
)
7277 return 1; /* An already-visited SAVE_EXPR? */
7282 /* The only case we look at here is the DECL_INITIAL inside a
7284 return (TREE_CODE (exp
) != DECL_EXPR
7285 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7286 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7287 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7290 case tcc_comparison
:
7291 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7296 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7298 case tcc_expression
:
7301 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7302 the expression. If it is set, we conflict iff we are that rtx or
7303 both are in memory. Otherwise, we check all operands of the
7304 expression recursively. */
7306 switch (TREE_CODE (exp
))
7309 /* If the operand is static or we are static, we can't conflict.
7310 Likewise if we don't conflict with the operand at all. */
7311 if (staticp (TREE_OPERAND (exp
, 0))
7312 || TREE_STATIC (exp
)
7313 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7316 /* Otherwise, the only way this can conflict is if we are taking
7317 the address of a DECL a that address if part of X, which is
7319 exp
= TREE_OPERAND (exp
, 0);
7322 if (!DECL_RTL_SET_P (exp
)
7323 || !MEM_P (DECL_RTL (exp
)))
7326 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7332 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7333 get_alias_set (exp
)))
7338 /* Assume that the call will clobber all hard registers and
7340 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7345 case WITH_CLEANUP_EXPR
:
7346 case CLEANUP_POINT_EXPR
:
7347 /* Lowered by gimplify.c. */
7351 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7357 /* If we have an rtx, we do not need to scan our operands. */
7361 nops
= TREE_OPERAND_LENGTH (exp
);
7362 for (i
= 0; i
< nops
; i
++)
7363 if (TREE_OPERAND (exp
, i
) != 0
7364 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7370 /* Should never get a type here. */
7374 /* If we have an rtl, find any enclosed object. Then see if we conflict
7378 if (GET_CODE (exp_rtl
) == SUBREG
)
7380 exp_rtl
= SUBREG_REG (exp_rtl
);
7382 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7386 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7387 are memory and they conflict. */
7388 return ! (rtx_equal_p (x
, exp_rtl
)
7389 || (MEM_P (x
) && MEM_P (exp_rtl
)
7390 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7393 /* If we reach here, it is safe. */
7398 /* Return the highest power of two that EXP is known to be a multiple of.
7399 This is used in updating alignment of MEMs in array references. */
7401 unsigned HOST_WIDE_INT
7402 highest_pow2_factor (const_tree exp
)
7404 unsigned HOST_WIDE_INT ret
;
7405 int trailing_zeros
= tree_ctz (exp
);
7406 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7407 return BIGGEST_ALIGNMENT
;
7408 ret
= (unsigned HOST_WIDE_INT
) 1 << trailing_zeros
;
7409 if (ret
> BIGGEST_ALIGNMENT
)
7410 return BIGGEST_ALIGNMENT
;
7414 /* Similar, except that the alignment requirements of TARGET are
7415 taken into account. Assume it is at least as aligned as its
7416 type, unless it is a COMPONENT_REF in which case the layout of
7417 the structure gives the alignment. */
7419 static unsigned HOST_WIDE_INT
7420 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7422 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7423 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7425 return MAX (factor
, talign
);
7428 #ifdef HAVE_conditional_move
7429 /* Convert the tree comparison code TCODE to the rtl one where the
7430 signedness is UNSIGNEDP. */
7432 static enum rtx_code
7433 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7445 code
= unsignedp
? LTU
: LT
;
7448 code
= unsignedp
? LEU
: LE
;
7451 code
= unsignedp
? GTU
: GT
;
7454 code
= unsignedp
? GEU
: GE
;
7456 case UNORDERED_EXPR
:
7488 /* Subroutine of expand_expr. Expand the two operands of a binary
7489 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7490 The value may be stored in TARGET if TARGET is nonzero. The
7491 MODIFIER argument is as documented by expand_expr. */
7494 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7495 enum expand_modifier modifier
)
7497 if (! safe_from_p (target
, exp1
, 1))
7499 if (operand_equal_p (exp0
, exp1
, 0))
7501 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7502 *op1
= copy_rtx (*op0
);
7506 /* If we need to preserve evaluation order, copy exp0 into its own
7507 temporary variable so that it can't be clobbered by exp1. */
7508 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7509 exp0
= save_expr (exp0
);
7510 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7511 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7516 /* Return a MEM that contains constant EXP. DEFER is as for
7517 output_constant_def and MODIFIER is as for expand_expr. */
7520 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7524 mem
= output_constant_def (exp
, defer
);
7525 if (modifier
!= EXPAND_INITIALIZER
)
7526 mem
= use_anchored_address (mem
);
7530 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7531 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7534 expand_expr_addr_expr_1 (tree exp
, rtx target
, enum machine_mode tmode
,
7535 enum expand_modifier modifier
, addr_space_t as
)
7537 rtx result
, subtarget
;
7539 HOST_WIDE_INT bitsize
, bitpos
;
7540 int volatilep
, unsignedp
;
7541 enum machine_mode mode1
;
7543 /* If we are taking the address of a constant and are at the top level,
7544 we have to use output_constant_def since we can't call force_const_mem
7546 /* ??? This should be considered a front-end bug. We should not be
7547 generating ADDR_EXPR of something that isn't an LVALUE. The only
7548 exception here is STRING_CST. */
7549 if (CONSTANT_CLASS_P (exp
))
7551 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7552 if (modifier
< EXPAND_SUM
)
7553 result
= force_operand (result
, target
);
7557 /* Everything must be something allowed by is_gimple_addressable. */
7558 switch (TREE_CODE (exp
))
7561 /* This case will happen via recursion for &a->b. */
7562 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7566 tree tem
= TREE_OPERAND (exp
, 0);
7567 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7568 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7569 return expand_expr (tem
, target
, tmode
, modifier
);
7573 /* Expand the initializer like constants above. */
7574 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7576 if (modifier
< EXPAND_SUM
)
7577 result
= force_operand (result
, target
);
7581 /* The real part of the complex number is always first, therefore
7582 the address is the same as the address of the parent object. */
7585 inner
= TREE_OPERAND (exp
, 0);
7589 /* The imaginary part of the complex number is always second.
7590 The expression is therefore always offset by the size of the
7593 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7594 inner
= TREE_OPERAND (exp
, 0);
7597 case COMPOUND_LITERAL_EXPR
:
7598 /* Allow COMPOUND_LITERAL_EXPR in initializers, if e.g.
7599 rtl_for_decl_init is called on DECL_INITIAL with
7600 COMPOUNT_LITERAL_EXPRs in it, they aren't gimplified. */
7601 if (modifier
== EXPAND_INITIALIZER
7602 && COMPOUND_LITERAL_EXPR_DECL (exp
))
7603 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7604 target
, tmode
, modifier
, as
);
7607 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7608 expand_expr, as that can have various side effects; LABEL_DECLs for
7609 example, may not have their DECL_RTL set yet. Expand the rtl of
7610 CONSTRUCTORs too, which should yield a memory reference for the
7611 constructor's contents. Assume language specific tree nodes can
7612 be expanded in some interesting way. */
7613 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7615 || TREE_CODE (exp
) == CONSTRUCTOR
7616 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7618 result
= expand_expr (exp
, target
, tmode
,
7619 modifier
== EXPAND_INITIALIZER
7620 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7622 /* If the DECL isn't in memory, then the DECL wasn't properly
7623 marked TREE_ADDRESSABLE, which will be either a front-end
7624 or a tree optimizer bug. */
7626 if (TREE_ADDRESSABLE (exp
)
7628 && ! targetm
.calls
.allocate_stack_slots_for_args ())
7630 error ("local frame unavailable (naked function?)");
7634 gcc_assert (MEM_P (result
));
7635 result
= XEXP (result
, 0);
7637 /* ??? Is this needed anymore? */
7639 TREE_USED (exp
) = 1;
7641 if (modifier
!= EXPAND_INITIALIZER
7642 && modifier
!= EXPAND_CONST_ADDRESS
7643 && modifier
!= EXPAND_SUM
)
7644 result
= force_operand (result
, target
);
7648 /* Pass FALSE as the last argument to get_inner_reference although
7649 we are expanding to RTL. The rationale is that we know how to
7650 handle "aligning nodes" here: we can just bypass them because
7651 they won't change the final object whose address will be returned
7652 (they actually exist only for that purpose). */
7653 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7654 &mode1
, &unsignedp
, &volatilep
, false);
7658 /* We must have made progress. */
7659 gcc_assert (inner
!= exp
);
7661 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7662 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7663 inner alignment, force the inner to be sufficiently aligned. */
7664 if (CONSTANT_CLASS_P (inner
)
7665 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7667 inner
= copy_node (inner
);
7668 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7669 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7670 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7672 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7678 if (modifier
!= EXPAND_NORMAL
)
7679 result
= force_operand (result
, NULL
);
7680 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7681 modifier
== EXPAND_INITIALIZER
7682 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7684 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7685 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7687 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7688 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7691 subtarget
= bitpos
? NULL_RTX
: target
;
7692 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7693 1, OPTAB_LIB_WIDEN
);
7699 /* Someone beforehand should have rejected taking the address
7700 of such an object. */
7701 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7703 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7704 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7705 if (modifier
< EXPAND_SUM
)
7706 result
= force_operand (result
, target
);
7712 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7713 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7716 expand_expr_addr_expr (tree exp
, rtx target
, enum machine_mode tmode
,
7717 enum expand_modifier modifier
)
7719 addr_space_t as
= ADDR_SPACE_GENERIC
;
7720 enum machine_mode address_mode
= Pmode
;
7721 enum machine_mode pointer_mode
= ptr_mode
;
7722 enum machine_mode rmode
;
7725 /* Target mode of VOIDmode says "whatever's natural". */
7726 if (tmode
== VOIDmode
)
7727 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7729 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7731 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7732 address_mode
= targetm
.addr_space
.address_mode (as
);
7733 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7736 /* We can get called with some Weird Things if the user does silliness
7737 like "(short) &a". In that case, convert_memory_address won't do
7738 the right thing, so ignore the given target mode. */
7739 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7740 tmode
= address_mode
;
7742 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7743 tmode
, modifier
, as
);
7745 /* Despite expand_expr claims concerning ignoring TMODE when not
7746 strictly convenient, stuff breaks if we don't honor it. Note
7747 that combined with the above, we only do this for pointer modes. */
7748 rmode
= GET_MODE (result
);
7749 if (rmode
== VOIDmode
)
7752 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7757 /* Generate code for computing CONSTRUCTOR EXP.
7758 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7759 is TRUE, instead of creating a temporary variable in memory
7760 NULL is returned and the caller needs to handle it differently. */
7763 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7764 bool avoid_temp_mem
)
7766 tree type
= TREE_TYPE (exp
);
7767 enum machine_mode mode
= TYPE_MODE (type
);
7769 /* Try to avoid creating a temporary at all. This is possible
7770 if all of the initializer is zero.
7771 FIXME: try to handle all [0..255] initializers we can handle
7773 if (TREE_STATIC (exp
)
7774 && !TREE_ADDRESSABLE (exp
)
7775 && target
!= 0 && mode
== BLKmode
7776 && all_zeros_p (exp
))
7778 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7782 /* All elts simple constants => refer to a constant in memory. But
7783 if this is a non-BLKmode mode, let it store a field at a time
7784 since that should make a CONST_INT or CONST_DOUBLE when we
7785 fold. Likewise, if we have a target we can use, it is best to
7786 store directly into the target unless the type is large enough
7787 that memcpy will be used. If we are making an initializer and
7788 all operands are constant, put it in memory as well.
7790 FIXME: Avoid trying to fill vector constructors piece-meal.
7791 Output them with output_constant_def below unless we're sure
7792 they're zeros. This should go away when vector initializers
7793 are treated like VECTOR_CST instead of arrays. */
7794 if ((TREE_STATIC (exp
)
7795 && ((mode
== BLKmode
7796 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7797 || TREE_ADDRESSABLE (exp
)
7798 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7799 && (! MOVE_BY_PIECES_P
7800 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7802 && ! mostly_zeros_p (exp
))))
7803 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7804 && TREE_CONSTANT (exp
)))
7811 constructor
= expand_expr_constant (exp
, 1, modifier
);
7813 if (modifier
!= EXPAND_CONST_ADDRESS
7814 && modifier
!= EXPAND_INITIALIZER
7815 && modifier
!= EXPAND_SUM
)
7816 constructor
= validize_mem (constructor
);
7821 /* Handle calls that pass values in multiple non-contiguous
7822 locations. The Irix 6 ABI has examples of this. */
7823 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7824 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7830 = assign_temp (build_qualified_type (type
, (TYPE_QUALS (type
)
7831 | (TREE_READONLY (exp
)
7832 * TYPE_QUAL_CONST
))),
7833 TREE_ADDRESSABLE (exp
), 1);
7836 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7841 /* expand_expr: generate code for computing expression EXP.
7842 An rtx for the computed value is returned. The value is never null.
7843 In the case of a void EXP, const0_rtx is returned.
7845 The value may be stored in TARGET if TARGET is nonzero.
7846 TARGET is just a suggestion; callers must assume that
7847 the rtx returned may not be the same as TARGET.
7849 If TARGET is CONST0_RTX, it means that the value will be ignored.
7851 If TMODE is not VOIDmode, it suggests generating the
7852 result in mode TMODE. But this is done only when convenient.
7853 Otherwise, TMODE is ignored and the value generated in its natural mode.
7854 TMODE is just a suggestion; callers must assume that
7855 the rtx returned may not have mode TMODE.
7857 Note that TARGET may have neither TMODE nor MODE. In that case, it
7858 probably will not be used.
7860 If MODIFIER is EXPAND_SUM then when EXP is an addition
7861 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7862 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7863 products as above, or REG or MEM, or constant.
7864 Ordinarily in such cases we would output mul or add instructions
7865 and then return a pseudo reg containing the sum.
7867 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7868 it also marks a label as absolutely required (it can't be dead).
7869 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7870 This is used for outputting expressions used in initializers.
7872 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7873 with a constant address even if that address is not normally legitimate.
7874 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7876 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7877 a call parameter. Such targets require special care as we haven't yet
7878 marked TARGET so that it's safe from being trashed by libcalls. We
7879 don't want to use TARGET for anything but the final result;
7880 Intermediate values must go elsewhere. Additionally, calls to
7881 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7883 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7884 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7885 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7886 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7890 expand_expr_real (tree exp
, rtx target
, enum machine_mode tmode
,
7891 enum expand_modifier modifier
, rtx
*alt_rtl
)
7895 /* Handle ERROR_MARK before anybody tries to access its type. */
7896 if (TREE_CODE (exp
) == ERROR_MARK
7897 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7899 ret
= CONST0_RTX (tmode
);
7900 return ret
? ret
: const0_rtx
;
7903 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
7907 /* Try to expand the conditional expression which is represented by
7908 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7909 return the rtl reg which repsents the result. Otherwise return
7913 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7914 tree treeop1 ATTRIBUTE_UNUSED
,
7915 tree treeop2 ATTRIBUTE_UNUSED
)
7917 #ifdef HAVE_conditional_move
7919 rtx op00
, op01
, op1
, op2
;
7920 enum rtx_code comparison_code
;
7921 enum machine_mode comparison_mode
;
7924 tree type
= TREE_TYPE (treeop1
);
7925 int unsignedp
= TYPE_UNSIGNED (type
);
7926 enum machine_mode mode
= TYPE_MODE (type
);
7927 enum machine_mode orig_mode
= mode
;
7929 /* If we cannot do a conditional move on the mode, try doing it
7930 with the promoted mode. */
7931 if (!can_conditionally_move_p (mode
))
7933 mode
= promote_mode (type
, mode
, &unsignedp
);
7934 if (!can_conditionally_move_p (mode
))
7936 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7939 temp
= assign_temp (type
, 0, 1);
7942 expand_operands (treeop1
, treeop2
,
7943 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7945 if (TREE_CODE (treeop0
) == SSA_NAME
7946 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7948 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7949 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7950 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7951 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7952 comparison_mode
= TYPE_MODE (type
);
7953 unsignedp
= TYPE_UNSIGNED (type
);
7954 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7956 else if (TREE_CODE_CLASS (TREE_CODE (treeop0
)) == tcc_comparison
)
7958 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7959 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7960 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7961 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7962 unsignedp
= TYPE_UNSIGNED (type
);
7963 comparison_mode
= TYPE_MODE (type
);
7964 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7968 op00
= expand_normal (treeop0
);
7970 comparison_code
= NE
;
7971 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7974 if (GET_MODE (op1
) != mode
)
7975 op1
= gen_lowpart (mode
, op1
);
7977 if (GET_MODE (op2
) != mode
)
7978 op2
= gen_lowpart (mode
, op2
);
7980 /* Try to emit the conditional move. */
7981 insn
= emit_conditional_move (temp
, comparison_code
,
7982 op00
, op01
, comparison_mode
,
7986 /* If we could do the conditional move, emit the sequence,
7990 rtx seq
= get_insns ();
7993 return convert_modes (orig_mode
, mode
, temp
, 0);
7996 /* Otherwise discard the sequence and fall back to code with
8004 expand_expr_real_2 (sepops ops
, rtx target
, enum machine_mode tmode
,
8005 enum expand_modifier modifier
)
8007 rtx op0
, op1
, op2
, temp
;
8010 enum machine_mode mode
;
8011 enum tree_code code
= ops
->code
;
8013 rtx subtarget
, original_target
;
8015 bool reduce_bit_field
;
8016 location_t loc
= ops
->location
;
8017 tree treeop0
, treeop1
, treeop2
;
8018 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8019 ? reduce_to_bit_field_precision ((expr), \
8025 mode
= TYPE_MODE (type
);
8026 unsignedp
= TYPE_UNSIGNED (type
);
8032 /* We should be called only on simple (binary or unary) expressions,
8033 exactly those that are valid in gimple expressions that aren't
8034 GIMPLE_SINGLE_RHS (or invalid). */
8035 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8036 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8037 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8039 ignore
= (target
== const0_rtx
8040 || ((CONVERT_EXPR_CODE_P (code
)
8041 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8042 && TREE_CODE (type
) == VOID_TYPE
));
8044 /* We should be called only if we need the result. */
8045 gcc_assert (!ignore
);
8047 /* An operation in what may be a bit-field type needs the
8048 result to be reduced to the precision of the bit-field type,
8049 which is narrower than that of the type's mode. */
8050 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8051 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8053 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8056 /* Use subtarget as the target for operand 0 of a binary operation. */
8057 subtarget
= get_subtarget (target
);
8058 original_target
= target
;
8062 case NON_LVALUE_EXPR
:
8065 if (treeop0
== error_mark_node
)
8068 if (TREE_CODE (type
) == UNION_TYPE
)
8070 tree valtype
= TREE_TYPE (treeop0
);
8072 /* If both input and output are BLKmode, this conversion isn't doing
8073 anything except possibly changing memory attribute. */
8074 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8076 rtx result
= expand_expr (treeop0
, target
, tmode
,
8079 result
= copy_rtx (result
);
8080 set_mem_attributes (result
, type
, 0);
8086 if (TYPE_MODE (type
) != BLKmode
)
8087 target
= gen_reg_rtx (TYPE_MODE (type
));
8089 target
= assign_temp (type
, 1, 1);
8093 /* Store data into beginning of memory target. */
8094 store_expr (treeop0
,
8095 adjust_address (target
, TYPE_MODE (valtype
), 0),
8096 modifier
== EXPAND_STACK_PARM
,
8101 gcc_assert (REG_P (target
));
8103 /* Store this field into a union of the proper type. */
8104 store_field (target
,
8105 MIN ((int_size_in_bytes (TREE_TYPE
8108 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8109 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8112 /* Return the entire union. */
8116 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8118 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8121 /* If the signedness of the conversion differs and OP0 is
8122 a promoted SUBREG, clear that indication since we now
8123 have to do the proper extension. */
8124 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8125 && GET_CODE (op0
) == SUBREG
)
8126 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8128 return REDUCE_BIT_FIELD (op0
);
8131 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8132 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8133 if (GET_MODE (op0
) == mode
)
8136 /* If OP0 is a constant, just convert it into the proper mode. */
8137 else if (CONSTANT_P (op0
))
8139 tree inner_type
= TREE_TYPE (treeop0
);
8140 enum machine_mode inner_mode
= GET_MODE (op0
);
8142 if (inner_mode
== VOIDmode
)
8143 inner_mode
= TYPE_MODE (inner_type
);
8145 if (modifier
== EXPAND_INITIALIZER
)
8146 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
8147 subreg_lowpart_offset (mode
,
8150 op0
= convert_modes (mode
, inner_mode
, op0
,
8151 TYPE_UNSIGNED (inner_type
));
8154 else if (modifier
== EXPAND_INITIALIZER
)
8155 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8157 else if (target
== 0)
8158 op0
= convert_to_mode (mode
, op0
,
8159 TYPE_UNSIGNED (TREE_TYPE
8163 convert_move (target
, op0
,
8164 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8168 return REDUCE_BIT_FIELD (op0
);
8170 case ADDR_SPACE_CONVERT_EXPR
:
8172 tree treeop0_type
= TREE_TYPE (treeop0
);
8174 addr_space_t as_from
;
8176 gcc_assert (POINTER_TYPE_P (type
));
8177 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8179 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8180 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8182 /* Conversions between pointers to the same address space should
8183 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8184 gcc_assert (as_to
!= as_from
);
8186 /* Ask target code to handle conversion between pointers
8187 to overlapping address spaces. */
8188 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8189 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8191 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8192 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8197 /* For disjoint address spaces, converting anything but
8198 a null pointer invokes undefined behaviour. We simply
8199 always return a null pointer here. */
8200 return CONST0_RTX (mode
);
8203 case POINTER_PLUS_EXPR
:
8204 /* Even though the sizetype mode and the pointer's mode can be different
8205 expand is able to handle this correctly and get the correct result out
8206 of the PLUS_EXPR code. */
8207 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8208 if sizetype precision is smaller than pointer precision. */
8209 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8210 treeop1
= fold_convert_loc (loc
, type
,
8211 fold_convert_loc (loc
, ssizetype
,
8213 /* If sizetype precision is larger than pointer precision, truncate the
8214 offset to have matching modes. */
8215 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8216 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8219 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8220 something else, make sure we add the register to the constant and
8221 then to the other thing. This case can occur during strength
8222 reduction and doing it this way will produce better code if the
8223 frame pointer or argument pointer is eliminated.
8225 fold-const.c will ensure that the constant is always in the inner
8226 PLUS_EXPR, so the only case we need to do anything about is if
8227 sp, ap, or fp is our second argument, in which case we must swap
8228 the innermost first argument and our second argument. */
8230 if (TREE_CODE (treeop0
) == PLUS_EXPR
8231 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8232 && TREE_CODE (treeop1
) == VAR_DECL
8233 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8234 || DECL_RTL (treeop1
) == stack_pointer_rtx
8235 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8240 /* If the result is to be ptr_mode and we are adding an integer to
8241 something, we might be forming a constant. So try to use
8242 plus_constant. If it produces a sum and we can't accept it,
8243 use force_operand. This allows P = &ARR[const] to generate
8244 efficient code on machines where a SYMBOL_REF is not a valid
8247 If this is an EXPAND_SUM call, always return the sum. */
8248 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8249 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8251 if (modifier
== EXPAND_STACK_PARM
)
8253 if (TREE_CODE (treeop0
) == INTEGER_CST
8254 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8255 && TREE_CONSTANT (treeop1
))
8259 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8261 /* Use immed_double_const to ensure that the constant is
8262 truncated according to the mode of OP1, then sign extended
8263 to a HOST_WIDE_INT. Using the constant directly can result
8264 in non-canonical RTL in a 64x32 cross compile. */
8266 = immed_double_const (TREE_INT_CST_LOW (treeop0
),
8268 TYPE_MODE (TREE_TYPE (treeop1
)));
8269 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8270 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8271 op1
= force_operand (op1
, target
);
8272 return REDUCE_BIT_FIELD (op1
);
8275 else if (TREE_CODE (treeop1
) == INTEGER_CST
8276 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8277 && TREE_CONSTANT (treeop0
))
8281 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8282 (modifier
== EXPAND_INITIALIZER
8283 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8284 if (! CONSTANT_P (op0
))
8286 op1
= expand_expr (treeop1
, NULL_RTX
,
8287 VOIDmode
, modifier
);
8288 /* Return a PLUS if modifier says it's OK. */
8289 if (modifier
== EXPAND_SUM
8290 || modifier
== EXPAND_INITIALIZER
)
8291 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8294 /* Use immed_double_const to ensure that the constant is
8295 truncated according to the mode of OP1, then sign extended
8296 to a HOST_WIDE_INT. Using the constant directly can result
8297 in non-canonical RTL in a 64x32 cross compile. */
8299 = immed_double_const (TREE_INT_CST_LOW (treeop1
),
8301 TYPE_MODE (TREE_TYPE (treeop0
)));
8302 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8303 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8304 op0
= force_operand (op0
, target
);
8305 return REDUCE_BIT_FIELD (op0
);
8309 /* Use TER to expand pointer addition of a negated value
8310 as pointer subtraction. */
8311 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8312 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8313 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8314 && TREE_CODE (treeop1
) == SSA_NAME
8315 && TYPE_MODE (TREE_TYPE (treeop0
))
8316 == TYPE_MODE (TREE_TYPE (treeop1
)))
8318 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8321 treeop1
= gimple_assign_rhs1 (def
);
8327 /* No sense saving up arithmetic to be done
8328 if it's all in the wrong mode to form part of an address.
8329 And force_operand won't know whether to sign-extend or
8331 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8332 || mode
!= ptr_mode
)
8334 expand_operands (treeop0
, treeop1
,
8335 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8336 if (op0
== const0_rtx
)
8338 if (op1
== const0_rtx
)
8343 expand_operands (treeop0
, treeop1
,
8344 subtarget
, &op0
, &op1
, modifier
);
8345 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8349 /* For initializers, we are allowed to return a MINUS of two
8350 symbolic constants. Here we handle all cases when both operands
8352 /* Handle difference of two symbolic constants,
8353 for the sake of an initializer. */
8354 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8355 && really_constant_p (treeop0
)
8356 && really_constant_p (treeop1
))
8358 expand_operands (treeop0
, treeop1
,
8359 NULL_RTX
, &op0
, &op1
, modifier
);
8361 /* If the last operand is a CONST_INT, use plus_constant of
8362 the negated constant. Else make the MINUS. */
8363 if (CONST_INT_P (op1
))
8364 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8367 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8370 /* No sense saving up arithmetic to be done
8371 if it's all in the wrong mode to form part of an address.
8372 And force_operand won't know whether to sign-extend or
8374 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8375 || mode
!= ptr_mode
)
8378 expand_operands (treeop0
, treeop1
,
8379 subtarget
, &op0
, &op1
, modifier
);
8381 /* Convert A - const to A + (-const). */
8382 if (CONST_INT_P (op1
))
8384 op1
= negate_rtx (mode
, op1
);
8385 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8390 case WIDEN_MULT_PLUS_EXPR
:
8391 case WIDEN_MULT_MINUS_EXPR
:
8392 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8393 op2
= expand_normal (treeop2
);
8394 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8398 case WIDEN_MULT_EXPR
:
8399 /* If first operand is constant, swap them.
8400 Thus the following special case checks need only
8401 check the second operand. */
8402 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8409 /* First, check if we have a multiplication of one signed and one
8410 unsigned operand. */
8411 if (TREE_CODE (treeop1
) != INTEGER_CST
8412 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8413 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8415 enum machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8416 this_optab
= usmul_widen_optab
;
8417 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8418 != CODE_FOR_nothing
)
8420 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8421 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8424 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8426 /* op0 and op1 might still be constant, despite the above
8427 != INTEGER_CST check. Handle it. */
8428 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8430 op0
= convert_modes (innermode
, mode
, op0
, true);
8431 op1
= convert_modes (innermode
, mode
, op1
, false);
8432 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8433 target
, unsignedp
));
8438 /* Check for a multiplication with matching signedness. */
8439 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8440 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8441 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8442 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8444 tree op0type
= TREE_TYPE (treeop0
);
8445 enum machine_mode innermode
= TYPE_MODE (op0type
);
8446 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8447 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8448 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8450 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8452 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8453 != CODE_FOR_nothing
)
8455 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8457 /* op0 and op1 might still be constant, despite the above
8458 != INTEGER_CST check. Handle it. */
8459 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8462 op0
= convert_modes (innermode
, mode
, op0
, zextend_p
);
8464 = convert_modes (innermode
, mode
, op1
,
8465 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8466 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8470 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8471 unsignedp
, this_optab
);
8472 return REDUCE_BIT_FIELD (temp
);
8474 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8476 && innermode
== word_mode
)
8479 op0
= expand_normal (treeop0
);
8480 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8481 op1
= convert_modes (innermode
, mode
,
8482 expand_normal (treeop1
),
8483 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8485 op1
= expand_normal (treeop1
);
8486 /* op0 and op1 might still be constant, despite the above
8487 != INTEGER_CST check. Handle it. */
8488 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8489 goto widen_mult_const
;
8490 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8491 unsignedp
, OPTAB_LIB_WIDEN
);
8492 hipart
= gen_highpart (innermode
, temp
);
8493 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8497 emit_move_insn (hipart
, htem
);
8498 return REDUCE_BIT_FIELD (temp
);
8502 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8503 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8504 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8505 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8509 optab opt
= fma_optab
;
8512 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8514 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8516 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8519 gcc_assert (fn
!= NULL_TREE
);
8520 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8521 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8524 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8525 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8530 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8533 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8534 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8537 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8540 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8543 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8546 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8550 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8552 op2
= expand_normal (treeop2
);
8553 op1
= expand_normal (treeop1
);
8555 return expand_ternary_op (TYPE_MODE (type
), opt
,
8556 op0
, op1
, op2
, target
, 0);
8560 /* If this is a fixed-point operation, then we cannot use the code
8561 below because "expand_mult" doesn't support sat/no-sat fixed-point
8563 if (ALL_FIXED_POINT_MODE_P (mode
))
8566 /* If first operand is constant, swap them.
8567 Thus the following special case checks need only
8568 check the second operand. */
8569 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8576 /* Attempt to return something suitable for generating an
8577 indexed address, for machines that support that. */
8579 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8580 && tree_fits_shwi_p (treeop1
))
8582 tree exp1
= treeop1
;
8584 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8588 op0
= force_operand (op0
, NULL_RTX
);
8590 op0
= copy_to_mode_reg (mode
, op0
);
8592 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8593 gen_int_mode (tree_to_shwi (exp1
),
8594 TYPE_MODE (TREE_TYPE (exp1
)))));
8597 if (modifier
== EXPAND_STACK_PARM
)
8600 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8601 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8603 case TRUNC_DIV_EXPR
:
8604 case FLOOR_DIV_EXPR
:
8606 case ROUND_DIV_EXPR
:
8607 case EXACT_DIV_EXPR
:
8608 /* If this is a fixed-point operation, then we cannot use the code
8609 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8611 if (ALL_FIXED_POINT_MODE_P (mode
))
8614 if (modifier
== EXPAND_STACK_PARM
)
8616 /* Possible optimization: compute the dividend with EXPAND_SUM
8617 then if the divisor is constant can optimize the case
8618 where some terms of the dividend have coeffs divisible by it. */
8619 expand_operands (treeop0
, treeop1
,
8620 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8621 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8626 case MULT_HIGHPART_EXPR
:
8627 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8628 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8632 case TRUNC_MOD_EXPR
:
8633 case FLOOR_MOD_EXPR
:
8635 case ROUND_MOD_EXPR
:
8636 if (modifier
== EXPAND_STACK_PARM
)
8638 expand_operands (treeop0
, treeop1
,
8639 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8640 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8642 case FIXED_CONVERT_EXPR
:
8643 op0
= expand_normal (treeop0
);
8644 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8645 target
= gen_reg_rtx (mode
);
8647 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8648 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8649 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8650 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8652 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8655 case FIX_TRUNC_EXPR
:
8656 op0
= expand_normal (treeop0
);
8657 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8658 target
= gen_reg_rtx (mode
);
8659 expand_fix (target
, op0
, unsignedp
);
8663 op0
= expand_normal (treeop0
);
8664 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8665 target
= gen_reg_rtx (mode
);
8666 /* expand_float can't figure out what to do if FROM has VOIDmode.
8667 So give it the correct mode. With -O, cse will optimize this. */
8668 if (GET_MODE (op0
) == VOIDmode
)
8669 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8671 expand_float (target
, op0
,
8672 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8676 op0
= expand_expr (treeop0
, subtarget
,
8677 VOIDmode
, EXPAND_NORMAL
);
8678 if (modifier
== EXPAND_STACK_PARM
)
8680 temp
= expand_unop (mode
,
8681 optab_for_tree_code (NEGATE_EXPR
, type
,
8685 return REDUCE_BIT_FIELD (temp
);
8688 op0
= expand_expr (treeop0
, subtarget
,
8689 VOIDmode
, EXPAND_NORMAL
);
8690 if (modifier
== EXPAND_STACK_PARM
)
8693 /* ABS_EXPR is not valid for complex arguments. */
8694 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8695 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8697 /* Unsigned abs is simply the operand. Testing here means we don't
8698 risk generating incorrect code below. */
8699 if (TYPE_UNSIGNED (type
))
8702 return expand_abs (mode
, op0
, target
, unsignedp
,
8703 safe_from_p (target
, treeop0
, 1));
8707 target
= original_target
;
8709 || modifier
== EXPAND_STACK_PARM
8710 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8711 || GET_MODE (target
) != mode
8713 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8714 target
= gen_reg_rtx (mode
);
8715 expand_operands (treeop0
, treeop1
,
8716 target
, &op0
, &op1
, EXPAND_NORMAL
);
8718 /* First try to do it with a special MIN or MAX instruction.
8719 If that does not win, use a conditional jump to select the proper
8721 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8722 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8727 /* At this point, a MEM target is no longer useful; we will get better
8730 if (! REG_P (target
))
8731 target
= gen_reg_rtx (mode
);
8733 /* If op1 was placed in target, swap op0 and op1. */
8734 if (target
!= op0
&& target
== op1
)
8741 /* We generate better code and avoid problems with op1 mentioning
8742 target by forcing op1 into a pseudo if it isn't a constant. */
8743 if (! CONSTANT_P (op1
))
8744 op1
= force_reg (mode
, op1
);
8747 enum rtx_code comparison_code
;
8750 if (code
== MAX_EXPR
)
8751 comparison_code
= unsignedp
? GEU
: GE
;
8753 comparison_code
= unsignedp
? LEU
: LE
;
8755 /* Canonicalize to comparisons against 0. */
8756 if (op1
== const1_rtx
)
8758 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8759 or (a != 0 ? a : 1) for unsigned.
8760 For MIN we are safe converting (a <= 1 ? a : 1)
8761 into (a <= 0 ? a : 1) */
8762 cmpop1
= const0_rtx
;
8763 if (code
== MAX_EXPR
)
8764 comparison_code
= unsignedp
? NE
: GT
;
8766 if (op1
== constm1_rtx
&& !unsignedp
)
8768 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8769 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8770 cmpop1
= const0_rtx
;
8771 if (code
== MIN_EXPR
)
8772 comparison_code
= LT
;
8774 #ifdef HAVE_conditional_move
8775 /* Use a conditional move if possible. */
8776 if (can_conditionally_move_p (mode
))
8780 /* ??? Same problem as in expmed.c: emit_conditional_move
8781 forces a stack adjustment via compare_from_rtx, and we
8782 lose the stack adjustment if the sequence we are about
8783 to create is discarded. */
8784 do_pending_stack_adjust ();
8788 /* Try to emit the conditional move. */
8789 insn
= emit_conditional_move (target
, comparison_code
,
8794 /* If we could do the conditional move, emit the sequence,
8798 rtx seq
= get_insns ();
8804 /* Otherwise discard the sequence and fall back to code with
8810 emit_move_insn (target
, op0
);
8812 temp
= gen_label_rtx ();
8813 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8814 unsignedp
, mode
, NULL_RTX
, NULL_RTX
, temp
,
8817 emit_move_insn (target
, op1
);
8822 op0
= expand_expr (treeop0
, subtarget
,
8823 VOIDmode
, EXPAND_NORMAL
);
8824 if (modifier
== EXPAND_STACK_PARM
)
8826 /* In case we have to reduce the result to bitfield precision
8827 for unsigned bitfield expand this as XOR with a proper constant
8829 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8830 temp
= expand_binop (mode
, xor_optab
, op0
,
8831 immed_double_int_const
8832 (double_int::mask (TYPE_PRECISION (type
)), mode
),
8833 target
, 1, OPTAB_LIB_WIDEN
);
8835 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8839 /* ??? Can optimize bitwise operations with one arg constant.
8840 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8841 and (a bitwise1 b) bitwise2 b (etc)
8842 but that is probably not worth while. */
8851 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8852 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8853 == TYPE_PRECISION (type
)));
8858 /* If this is a fixed-point operation, then we cannot use the code
8859 below because "expand_shift" doesn't support sat/no-sat fixed-point
8861 if (ALL_FIXED_POINT_MODE_P (mode
))
8864 if (! safe_from_p (subtarget
, treeop1
, 1))
8866 if (modifier
== EXPAND_STACK_PARM
)
8868 op0
= expand_expr (treeop0
, subtarget
,
8869 VOIDmode
, EXPAND_NORMAL
);
8870 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8872 if (code
== LSHIFT_EXPR
)
8873 temp
= REDUCE_BIT_FIELD (temp
);
8876 /* Could determine the answer when only additive constants differ. Also,
8877 the addition of one can be handled by changing the condition. */
8884 case UNORDERED_EXPR
:
8892 temp
= do_store_flag (ops
,
8893 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8894 tmode
!= VOIDmode
? tmode
: mode
);
8898 /* Use a compare and a jump for BLKmode comparisons, or for function
8899 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8902 || modifier
== EXPAND_STACK_PARM
8903 || ! safe_from_p (target
, treeop0
, 1)
8904 || ! safe_from_p (target
, treeop1
, 1)
8905 /* Make sure we don't have a hard reg (such as function's return
8906 value) live across basic blocks, if not optimizing. */
8907 || (!optimize
&& REG_P (target
)
8908 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8909 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8911 emit_move_insn (target
, const0_rtx
);
8913 op1
= gen_label_rtx ();
8914 jumpifnot_1 (code
, treeop0
, treeop1
, op1
, -1);
8916 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8917 emit_move_insn (target
, constm1_rtx
);
8919 emit_move_insn (target
, const1_rtx
);
8925 /* Get the rtx code of the operands. */
8926 op0
= expand_normal (treeop0
);
8927 op1
= expand_normal (treeop1
);
8930 target
= gen_reg_rtx (TYPE_MODE (type
));
8932 /* If target overlaps with op1, then either we need to force
8933 op1 into a pseudo (if target also overlaps with op0),
8934 or write the complex parts in reverse order. */
8935 switch (GET_CODE (target
))
8938 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
8940 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
8942 complex_expr_force_op1
:
8943 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
8944 emit_move_insn (temp
, op1
);
8948 complex_expr_swap_order
:
8949 /* Move the imaginary (op1) and real (op0) parts to their
8951 write_complex_part (target
, op1
, true);
8952 write_complex_part (target
, op0
, false);
8958 temp
= adjust_address_nv (target
,
8959 GET_MODE_INNER (GET_MODE (target
)), 0);
8960 if (reg_overlap_mentioned_p (temp
, op1
))
8962 enum machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
8963 temp
= adjust_address_nv (target
, imode
,
8964 GET_MODE_SIZE (imode
));
8965 if (reg_overlap_mentioned_p (temp
, op0
))
8966 goto complex_expr_force_op1
;
8967 goto complex_expr_swap_order
;
8971 if (reg_overlap_mentioned_p (target
, op1
))
8973 if (reg_overlap_mentioned_p (target
, op0
))
8974 goto complex_expr_force_op1
;
8975 goto complex_expr_swap_order
;
8980 /* Move the real (op0) and imaginary (op1) parts to their location. */
8981 write_complex_part (target
, op0
, false);
8982 write_complex_part (target
, op1
, true);
8986 case WIDEN_SUM_EXPR
:
8988 tree oprnd0
= treeop0
;
8989 tree oprnd1
= treeop1
;
8991 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8992 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
8997 case REDUC_MAX_EXPR
:
8998 case REDUC_MIN_EXPR
:
8999 case REDUC_PLUS_EXPR
:
9001 op0
= expand_normal (treeop0
);
9002 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9003 temp
= expand_unop (mode
, this_optab
, op0
, target
, unsignedp
);
9008 case VEC_LSHIFT_EXPR
:
9009 case VEC_RSHIFT_EXPR
:
9011 target
= expand_vec_shift_expr (ops
, target
);
9015 case VEC_UNPACK_HI_EXPR
:
9016 case VEC_UNPACK_LO_EXPR
:
9018 op0
= expand_normal (treeop0
);
9019 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9025 case VEC_UNPACK_FLOAT_HI_EXPR
:
9026 case VEC_UNPACK_FLOAT_LO_EXPR
:
9028 op0
= expand_normal (treeop0
);
9029 /* The signedness is determined from input operand. */
9030 temp
= expand_widen_pattern_expr
9031 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9032 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9038 case VEC_WIDEN_MULT_HI_EXPR
:
9039 case VEC_WIDEN_MULT_LO_EXPR
:
9040 case VEC_WIDEN_MULT_EVEN_EXPR
:
9041 case VEC_WIDEN_MULT_ODD_EXPR
:
9042 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9043 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9044 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9045 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9047 gcc_assert (target
);
9050 case VEC_PACK_TRUNC_EXPR
:
9051 case VEC_PACK_SAT_EXPR
:
9052 case VEC_PACK_FIX_TRUNC_EXPR
:
9053 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9057 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9058 op2
= expand_normal (treeop2
);
9060 /* Careful here: if the target doesn't support integral vector modes,
9061 a constant selection vector could wind up smooshed into a normal
9062 integral constant. */
9063 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9065 tree sel_type
= TREE_TYPE (treeop2
);
9066 enum machine_mode vmode
9067 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9068 TYPE_VECTOR_SUBPARTS (sel_type
));
9069 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9070 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9071 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9074 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9076 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9082 tree oprnd0
= treeop0
;
9083 tree oprnd1
= treeop1
;
9084 tree oprnd2
= treeop2
;
9087 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9088 op2
= expand_normal (oprnd2
);
9089 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9094 case REALIGN_LOAD_EXPR
:
9096 tree oprnd0
= treeop0
;
9097 tree oprnd1
= treeop1
;
9098 tree oprnd2
= treeop2
;
9101 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9102 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9103 op2
= expand_normal (oprnd2
);
9104 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9111 /* A COND_EXPR with its type being VOID_TYPE represents a
9112 conditional jump and is handled in
9113 expand_gimple_cond_expr. */
9114 gcc_assert (!VOID_TYPE_P (type
));
9116 /* Note that COND_EXPRs whose type is a structure or union
9117 are required to be constructed to contain assignments of
9118 a temporary variable, so that we can evaluate them here
9119 for side effect only. If type is void, we must do likewise. */
9121 gcc_assert (!TREE_ADDRESSABLE (type
)
9123 && TREE_TYPE (treeop1
) != void_type_node
9124 && TREE_TYPE (treeop2
) != void_type_node
);
9126 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9130 /* If we are not to produce a result, we have no target. Otherwise,
9131 if a target was specified use it; it will not be used as an
9132 intermediate target unless it is safe. If no target, use a
9135 if (modifier
!= EXPAND_STACK_PARM
9137 && safe_from_p (original_target
, treeop0
, 1)
9138 && GET_MODE (original_target
) == mode
9139 && !MEM_P (original_target
))
9140 temp
= original_target
;
9142 temp
= assign_temp (type
, 0, 1);
9144 do_pending_stack_adjust ();
9146 op0
= gen_label_rtx ();
9147 op1
= gen_label_rtx ();
9148 jumpifnot (treeop0
, op0
, -1);
9149 store_expr (treeop1
, temp
,
9150 modifier
== EXPAND_STACK_PARM
,
9153 emit_jump_insn (gen_jump (op1
));
9156 store_expr (treeop2
, temp
,
9157 modifier
== EXPAND_STACK_PARM
,
9165 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9172 /* Here to do an ordinary binary operator. */
9174 expand_operands (treeop0
, treeop1
,
9175 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9177 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9179 if (modifier
== EXPAND_STACK_PARM
)
9181 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9182 unsignedp
, OPTAB_LIB_WIDEN
);
9184 /* Bitwise operations do not need bitfield reduction as we expect their
9185 operands being properly truncated. */
9186 if (code
== BIT_XOR_EXPR
9187 || code
== BIT_AND_EXPR
9188 || code
== BIT_IOR_EXPR
)
9190 return REDUCE_BIT_FIELD (temp
);
9192 #undef REDUCE_BIT_FIELD
9195 /* Return TRUE if expression STMT is suitable for replacement.
9196 Never consider memory loads as replaceable, because those don't ever lead
9197 into constant expressions. */
9200 stmt_is_replaceable_p (gimple stmt
)
9202 if (ssa_is_replaceable_p (stmt
))
9204 /* Don't move around loads. */
9205 if (!gimple_assign_single_p (stmt
)
9206 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9213 expand_expr_real_1 (tree exp
, rtx target
, enum machine_mode tmode
,
9214 enum expand_modifier modifier
, rtx
*alt_rtl
)
9216 rtx op0
, op1
, temp
, decl_rtl
;
9219 enum machine_mode mode
;
9220 enum tree_code code
= TREE_CODE (exp
);
9221 rtx subtarget
, original_target
;
9224 bool reduce_bit_field
;
9225 location_t loc
= EXPR_LOCATION (exp
);
9226 struct separate_ops ops
;
9227 tree treeop0
, treeop1
, treeop2
;
9228 tree ssa_name
= NULL_TREE
;
9231 type
= TREE_TYPE (exp
);
9232 mode
= TYPE_MODE (type
);
9233 unsignedp
= TYPE_UNSIGNED (type
);
9235 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9236 if (!VL_EXP_CLASS_P (exp
))
9237 switch (TREE_CODE_LENGTH (code
))
9240 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9241 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9242 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9252 ignore
= (target
== const0_rtx
9253 || ((CONVERT_EXPR_CODE_P (code
)
9254 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9255 && TREE_CODE (type
) == VOID_TYPE
));
9257 /* An operation in what may be a bit-field type needs the
9258 result to be reduced to the precision of the bit-field type,
9259 which is narrower than that of the type's mode. */
9260 reduce_bit_field
= (!ignore
9261 && INTEGRAL_TYPE_P (type
)
9262 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9264 /* If we are going to ignore this result, we need only do something
9265 if there is a side-effect somewhere in the expression. If there
9266 is, short-circuit the most common cases here. Note that we must
9267 not call expand_expr with anything but const0_rtx in case this
9268 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9272 if (! TREE_SIDE_EFFECTS (exp
))
9275 /* Ensure we reference a volatile object even if value is ignored, but
9276 don't do this if all we are doing is taking its address. */
9277 if (TREE_THIS_VOLATILE (exp
)
9278 && TREE_CODE (exp
) != FUNCTION_DECL
9279 && mode
!= VOIDmode
&& mode
!= BLKmode
9280 && modifier
!= EXPAND_CONST_ADDRESS
)
9282 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9288 if (TREE_CODE_CLASS (code
) == tcc_unary
9289 || code
== BIT_FIELD_REF
9290 || code
== COMPONENT_REF
9291 || code
== INDIRECT_REF
)
9292 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9295 else if (TREE_CODE_CLASS (code
) == tcc_binary
9296 || TREE_CODE_CLASS (code
) == tcc_comparison
9297 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9299 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9300 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9307 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9310 /* Use subtarget as the target for operand 0 of a binary operation. */
9311 subtarget
= get_subtarget (target
);
9312 original_target
= target
;
9318 tree function
= decl_function_context (exp
);
9320 temp
= label_rtx (exp
);
9321 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9323 if (function
!= current_function_decl
9325 LABEL_REF_NONLOCAL_P (temp
) = 1;
9327 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9332 /* ??? ivopts calls expander, without any preparation from
9333 out-of-ssa. So fake instructions as if this was an access to the
9334 base variable. This unnecessarily allocates a pseudo, see how we can
9335 reuse it, if partition base vars have it set already. */
9336 if (!currently_expanding_to_rtl
)
9338 tree var
= SSA_NAME_VAR (exp
);
9339 if (var
&& DECL_RTL_SET_P (var
))
9340 return DECL_RTL (var
);
9341 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9342 LAST_VIRTUAL_REGISTER
+ 1);
9345 g
= get_gimple_for_ssa_name (exp
);
9346 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9348 && modifier
== EXPAND_INITIALIZER
9349 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9350 && (optimize
|| DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9351 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9352 g
= SSA_NAME_DEF_STMT (exp
);
9356 location_t saved_loc
= curr_insn_location ();
9358 set_curr_insn_location (gimple_location (g
));
9359 r
= expand_expr_real (gimple_assign_rhs_to_tree (g
), target
,
9360 tmode
, modifier
, NULL
);
9361 set_curr_insn_location (saved_loc
);
9362 if (REG_P (r
) && !REG_EXPR (r
))
9363 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9368 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9369 exp
= SSA_NAME_VAR (ssa_name
);
9370 goto expand_decl_rtl
;
9374 /* If a static var's type was incomplete when the decl was written,
9375 but the type is complete now, lay out the decl now. */
9376 if (DECL_SIZE (exp
) == 0
9377 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9378 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9379 layout_decl (exp
, 0);
9381 /* ... fall through ... */
9385 decl_rtl
= DECL_RTL (exp
);
9387 gcc_assert (decl_rtl
);
9388 decl_rtl
= copy_rtx (decl_rtl
);
9389 /* Record writes to register variables. */
9390 if (modifier
== EXPAND_WRITE
9392 && HARD_REGISTER_P (decl_rtl
))
9393 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9394 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9396 /* Ensure variable marked as used even if it doesn't go through
9397 a parser. If it hasn't be used yet, write out an external
9399 TREE_USED (exp
) = 1;
9401 /* Show we haven't gotten RTL for this yet. */
9404 /* Variables inherited from containing functions should have
9405 been lowered by this point. */
9406 context
= decl_function_context (exp
);
9407 gcc_assert (SCOPE_FILE_SCOPE_P (context
)
9408 || context
== current_function_decl
9409 || TREE_STATIC (exp
)
9410 || DECL_EXTERNAL (exp
)
9411 /* ??? C++ creates functions that are not TREE_STATIC. */
9412 || TREE_CODE (exp
) == FUNCTION_DECL
);
9414 /* This is the case of an array whose size is to be determined
9415 from its initializer, while the initializer is still being parsed.
9416 ??? We aren't parsing while expanding anymore. */
9418 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9419 temp
= validize_mem (decl_rtl
);
9421 /* If DECL_RTL is memory, we are in the normal case and the
9422 address is not valid, get the address into a register. */
9424 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9427 *alt_rtl
= decl_rtl
;
9428 decl_rtl
= use_anchored_address (decl_rtl
);
9429 if (modifier
!= EXPAND_CONST_ADDRESS
9430 && modifier
!= EXPAND_SUM
9431 && !memory_address_addr_space_p (DECL_MODE (exp
),
9433 MEM_ADDR_SPACE (decl_rtl
)))
9434 temp
= replace_equiv_address (decl_rtl
,
9435 copy_rtx (XEXP (decl_rtl
, 0)));
9438 /* If we got something, return it. But first, set the alignment
9439 if the address is a register. */
9442 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9443 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9448 /* If the mode of DECL_RTL does not match that of the decl,
9449 there are two cases: we are dealing with a BLKmode value
9450 that is returned in a register, or we are dealing with
9451 a promoted value. In the latter case, return a SUBREG
9452 of the wanted mode, but mark it so that we know that it
9453 was already extended. */
9454 if (REG_P (decl_rtl
)
9455 && DECL_MODE (exp
) != BLKmode
9456 && GET_MODE (decl_rtl
) != DECL_MODE (exp
))
9458 enum machine_mode pmode
;
9460 /* Get the signedness to be used for this variable. Ensure we get
9461 the same mode we got when the variable was declared. */
9462 if (code
== SSA_NAME
9463 && (g
= SSA_NAME_DEF_STMT (ssa_name
))
9464 && gimple_code (g
) == GIMPLE_CALL
)
9466 gcc_assert (!gimple_call_internal_p (g
));
9467 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9468 gimple_call_fntype (g
),
9472 pmode
= promote_decl_mode (exp
, &unsignedp
);
9473 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9475 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9476 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9477 SUBREG_PROMOTED_UNSIGNED_SET (temp
, unsignedp
);
9484 temp
= immed_double_const (TREE_INT_CST_LOW (exp
),
9485 TREE_INT_CST_HIGH (exp
), mode
);
9491 tree tmp
= NULL_TREE
;
9492 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9493 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9494 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9495 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9496 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9497 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9498 return const_vector_from_tree (exp
);
9499 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9501 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9503 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9507 vec
<constructor_elt
, va_gc
> *v
;
9509 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9510 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9511 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9512 tmp
= build_constructor (type
, v
);
9514 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9519 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9522 /* If optimized, generate immediate CONST_DOUBLE
9523 which will be turned into memory by reload if necessary.
9525 We used to force a register so that loop.c could see it. But
9526 this does not allow gen_* patterns to perform optimizations with
9527 the constants. It also produces two insns in cases like "x = 1.0;".
9528 On most machines, floating-point constants are not permitted in
9529 many insns, so we'd end up copying it to a register in any case.
9531 Now, we do the copying in expand_binop, if appropriate. */
9532 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9533 TYPE_MODE (TREE_TYPE (exp
)));
9536 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9537 TYPE_MODE (TREE_TYPE (exp
)));
9540 /* Handle evaluating a complex constant in a CONCAT target. */
9541 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9543 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9546 rtarg
= XEXP (original_target
, 0);
9547 itarg
= XEXP (original_target
, 1);
9549 /* Move the real and imaginary parts separately. */
9550 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9551 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9554 emit_move_insn (rtarg
, op0
);
9556 emit_move_insn (itarg
, op1
);
9558 return original_target
;
9561 /* ... fall through ... */
9564 temp
= expand_expr_constant (exp
, 1, modifier
);
9566 /* temp contains a constant address.
9567 On RISC machines where a constant address isn't valid,
9568 make some insns to get that address into a register. */
9569 if (modifier
!= EXPAND_CONST_ADDRESS
9570 && modifier
!= EXPAND_INITIALIZER
9571 && modifier
!= EXPAND_SUM
9572 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9573 MEM_ADDR_SPACE (temp
)))
9574 return replace_equiv_address (temp
,
9575 copy_rtx (XEXP (temp
, 0)));
9581 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
);
9583 if (!SAVE_EXPR_RESOLVED_P (exp
))
9585 /* We can indeed still hit this case, typically via builtin
9586 expanders calling save_expr immediately before expanding
9587 something. Assume this means that we only have to deal
9588 with non-BLKmode values. */
9589 gcc_assert (GET_MODE (ret
) != BLKmode
);
9591 val
= build_decl (curr_insn_location (),
9592 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9593 DECL_ARTIFICIAL (val
) = 1;
9594 DECL_IGNORED_P (val
) = 1;
9596 TREE_OPERAND (exp
, 0) = treeop0
;
9597 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9599 if (!CONSTANT_P (ret
))
9600 ret
= copy_to_reg (ret
);
9601 SET_DECL_RTL (val
, ret
);
9609 /* If we don't need the result, just ensure we evaluate any
9613 unsigned HOST_WIDE_INT idx
;
9616 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9617 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9622 return expand_constructor (exp
, target
, modifier
, false);
9624 case TARGET_MEM_REF
:
9627 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9628 enum insn_code icode
;
9631 op0
= addr_for_mem_ref (exp
, as
, true);
9632 op0
= memory_address_addr_space (mode
, op0
, as
);
9633 temp
= gen_rtx_MEM (mode
, op0
);
9634 set_mem_attributes (temp
, exp
, 0);
9635 set_mem_addr_space (temp
, as
);
9636 align
= get_object_alignment (exp
);
9637 if (modifier
!= EXPAND_WRITE
9638 && modifier
!= EXPAND_MEMORY
9640 && align
< GET_MODE_ALIGNMENT (mode
)
9641 /* If the target does not have special handling for unaligned
9642 loads of mode then it can use regular moves for them. */
9643 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9644 != CODE_FOR_nothing
))
9646 struct expand_operand ops
[2];
9648 /* We've already validated the memory, and we're creating a
9649 new pseudo destination. The predicates really can't fail,
9650 nor can the generator. */
9651 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9652 create_fixed_operand (&ops
[1], temp
);
9653 expand_insn (icode
, 2, ops
);
9654 temp
= ops
[0].value
;
9662 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9663 enum machine_mode address_mode
;
9664 tree base
= TREE_OPERAND (exp
, 0);
9666 enum insn_code icode
;
9668 /* Handle expansion of non-aliased memory with non-BLKmode. That
9669 might end up in a register. */
9670 if (mem_ref_refers_to_non_mem_p (exp
))
9672 HOST_WIDE_INT offset
= mem_ref_offset (exp
).low
;
9673 base
= TREE_OPERAND (base
, 0);
9675 && tree_fits_uhwi_p (TYPE_SIZE (type
))
9676 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9677 == tree_to_uhwi (TYPE_SIZE (type
))))
9678 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
9679 target
, tmode
, modifier
);
9680 if (TYPE_MODE (type
) == BLKmode
)
9682 temp
= assign_stack_temp (DECL_MODE (base
),
9683 GET_MODE_SIZE (DECL_MODE (base
)));
9684 store_expr (base
, temp
, 0, false);
9685 temp
= adjust_address (temp
, BLKmode
, offset
);
9686 set_mem_size (temp
, int_size_in_bytes (type
));
9689 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
9690 bitsize_int (offset
* BITS_PER_UNIT
));
9691 return expand_expr (exp
, target
, tmode
, modifier
);
9693 address_mode
= targetm
.addr_space
.address_mode (as
);
9694 base
= TREE_OPERAND (exp
, 0);
9695 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9697 tree mask
= gimple_assign_rhs2 (def_stmt
);
9698 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9699 gimple_assign_rhs1 (def_stmt
), mask
);
9700 TREE_OPERAND (exp
, 0) = base
;
9702 align
= get_object_alignment (exp
);
9703 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9704 op0
= memory_address_addr_space (mode
, op0
, as
);
9705 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9708 = immed_double_int_const (mem_ref_offset (exp
), address_mode
);
9709 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9710 op0
= memory_address_addr_space (mode
, op0
, as
);
9712 temp
= gen_rtx_MEM (mode
, op0
);
9713 set_mem_attributes (temp
, exp
, 0);
9714 set_mem_addr_space (temp
, as
);
9715 if (TREE_THIS_VOLATILE (exp
))
9716 MEM_VOLATILE_P (temp
) = 1;
9717 if (modifier
!= EXPAND_WRITE
9718 && modifier
!= EXPAND_MEMORY
9720 && align
< GET_MODE_ALIGNMENT (mode
))
9722 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9723 != CODE_FOR_nothing
)
9725 struct expand_operand ops
[2];
9727 /* We've already validated the memory, and we're creating a
9728 new pseudo destination. The predicates really can't fail,
9729 nor can the generator. */
9730 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9731 create_fixed_operand (&ops
[1], temp
);
9732 expand_insn (icode
, 2, ops
);
9733 temp
= ops
[0].value
;
9735 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9736 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9737 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9738 (modifier
== EXPAND_STACK_PARM
9739 ? NULL_RTX
: target
),
9748 tree array
= treeop0
;
9749 tree index
= treeop1
;
9752 /* Fold an expression like: "foo"[2].
9753 This is not done in fold so it won't happen inside &.
9754 Don't fold if this is for wide characters since it's too
9755 difficult to do correctly and this is a very rare case. */
9757 if (modifier
!= EXPAND_CONST_ADDRESS
9758 && modifier
!= EXPAND_INITIALIZER
9759 && modifier
!= EXPAND_MEMORY
)
9761 tree t
= fold_read_from_constant_string (exp
);
9764 return expand_expr (t
, target
, tmode
, modifier
);
9767 /* If this is a constant index into a constant array,
9768 just get the value from the array. Handle both the cases when
9769 we have an explicit constructor and when our operand is a variable
9770 that was declared const. */
9772 if (modifier
!= EXPAND_CONST_ADDRESS
9773 && modifier
!= EXPAND_INITIALIZER
9774 && modifier
!= EXPAND_MEMORY
9775 && TREE_CODE (array
) == CONSTRUCTOR
9776 && ! TREE_SIDE_EFFECTS (array
)
9777 && TREE_CODE (index
) == INTEGER_CST
)
9779 unsigned HOST_WIDE_INT ix
;
9782 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9784 if (tree_int_cst_equal (field
, index
))
9786 if (!TREE_SIDE_EFFECTS (value
))
9787 return expand_expr (fold (value
), target
, tmode
, modifier
);
9792 else if (optimize
>= 1
9793 && modifier
!= EXPAND_CONST_ADDRESS
9794 && modifier
!= EXPAND_INITIALIZER
9795 && modifier
!= EXPAND_MEMORY
9796 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9797 && TREE_CODE (index
) == INTEGER_CST
9798 && (TREE_CODE (array
) == VAR_DECL
9799 || TREE_CODE (array
) == CONST_DECL
)
9800 && (init
= ctor_for_folding (array
)) != error_mark_node
)
9802 if (TREE_CODE (init
) == CONSTRUCTOR
)
9804 unsigned HOST_WIDE_INT ix
;
9807 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9809 if (tree_int_cst_equal (field
, index
))
9811 if (TREE_SIDE_EFFECTS (value
))
9814 if (TREE_CODE (value
) == CONSTRUCTOR
)
9816 /* If VALUE is a CONSTRUCTOR, this
9817 optimization is only useful if
9818 this doesn't store the CONSTRUCTOR
9819 into memory. If it does, it is more
9820 efficient to just load the data from
9821 the array directly. */
9822 rtx ret
= expand_constructor (value
, target
,
9824 if (ret
== NULL_RTX
)
9829 expand_expr (fold (value
), target
, tmode
, modifier
);
9832 else if (TREE_CODE (init
) == STRING_CST
)
9834 tree low_bound
= array_ref_low_bound (exp
);
9835 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
9837 /* Optimize the special case of a zero lower bound.
9839 We convert the lower bound to sizetype to avoid problems
9840 with constant folding. E.g. suppose the lower bound is
9841 1 and its mode is QI. Without the conversion
9842 (ARRAY + (INDEX - (unsigned char)1))
9844 (ARRAY + (-(unsigned char)1) + INDEX)
9846 (ARRAY + 255 + INDEX). Oops! */
9847 if (!integer_zerop (low_bound
))
9848 index1
= size_diffop_loc (loc
, index1
,
9849 fold_convert_loc (loc
, sizetype
,
9852 if (compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
9854 tree type
= TREE_TYPE (TREE_TYPE (init
));
9855 enum machine_mode mode
= TYPE_MODE (type
);
9857 if (GET_MODE_CLASS (mode
) == MODE_INT
9858 && GET_MODE_SIZE (mode
) == 1)
9859 return gen_int_mode (TREE_STRING_POINTER (init
)
9860 [TREE_INT_CST_LOW (index1
)],
9866 goto normal_inner_ref
;
9869 /* If the operand is a CONSTRUCTOR, we can just extract the
9870 appropriate field if it is present. */
9871 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
9873 unsigned HOST_WIDE_INT idx
;
9876 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
9878 if (field
== treeop1
9879 /* We can normally use the value of the field in the
9880 CONSTRUCTOR. However, if this is a bitfield in
9881 an integral mode that we can fit in a HOST_WIDE_INT,
9882 we must mask only the number of bits in the bitfield,
9883 since this is done implicitly by the constructor. If
9884 the bitfield does not meet either of those conditions,
9885 we can't do this optimization. */
9886 && (! DECL_BIT_FIELD (field
)
9887 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
9888 && (GET_MODE_PRECISION (DECL_MODE (field
))
9889 <= HOST_BITS_PER_WIDE_INT
))))
9891 if (DECL_BIT_FIELD (field
)
9892 && modifier
== EXPAND_STACK_PARM
)
9894 op0
= expand_expr (value
, target
, tmode
, modifier
);
9895 if (DECL_BIT_FIELD (field
))
9897 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
9898 enum machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
9900 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
9902 op1
= gen_int_mode (((HOST_WIDE_INT
) 1 << bitsize
) - 1,
9904 op0
= expand_and (imode
, op0
, op1
, target
);
9908 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
9910 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
9912 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
9920 goto normal_inner_ref
;
9923 case ARRAY_RANGE_REF
:
9926 enum machine_mode mode1
, mode2
;
9927 HOST_WIDE_INT bitsize
, bitpos
;
9929 int volatilep
= 0, must_force_mem
;
9930 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
9931 &mode1
, &unsignedp
, &volatilep
, true);
9932 rtx orig_op0
, memloc
;
9933 bool mem_attrs_from_type
= false;
9935 /* If we got back the original object, something is wrong. Perhaps
9936 we are evaluating an expression too early. In any event, don't
9937 infinitely recurse. */
9938 gcc_assert (tem
!= exp
);
9940 /* If TEM's type is a union of variable size, pass TARGET to the inner
9941 computation, since it will need a temporary and TARGET is known
9942 to have to do. This occurs in unchecked conversion in Ada. */
9945 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
9946 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
9947 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
9949 && modifier
!= EXPAND_STACK_PARM
9950 ? target
: NULL_RTX
),
9952 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
9954 /* If the bitfield is volatile, we want to access it in the
9955 field's mode, not the computed mode.
9956 If a MEM has VOIDmode (external with incomplete type),
9957 use BLKmode for it instead. */
9960 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
9961 op0
= adjust_address (op0
, mode1
, 0);
9962 else if (GET_MODE (op0
) == VOIDmode
)
9963 op0
= adjust_address (op0
, BLKmode
, 0);
9967 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
9969 /* If we have either an offset, a BLKmode result, or a reference
9970 outside the underlying object, we must force it to memory.
9971 Such a case can occur in Ada if we have unchecked conversion
9972 of an expression from a scalar type to an aggregate type or
9973 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9974 passed a partially uninitialized object or a view-conversion
9975 to a larger size. */
9976 must_force_mem
= (offset
9978 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
9980 /* Handle CONCAT first. */
9981 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
9984 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
9987 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9990 op0
= XEXP (op0
, 0);
9991 mode2
= GET_MODE (op0
);
9993 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9994 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
9998 op0
= XEXP (op0
, 1);
10000 mode2
= GET_MODE (op0
);
10003 /* Otherwise force into memory. */
10004 must_force_mem
= 1;
10007 /* If this is a constant, put it in a register if it is a legitimate
10008 constant and we don't need a memory reference. */
10009 if (CONSTANT_P (op0
)
10010 && mode2
!= BLKmode
10011 && targetm
.legitimate_constant_p (mode2
, op0
)
10012 && !must_force_mem
)
10013 op0
= force_reg (mode2
, op0
);
10015 /* Otherwise, if this is a constant, try to force it to the constant
10016 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10017 is a legitimate constant. */
10018 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10019 op0
= validize_mem (memloc
);
10021 /* Otherwise, if this is a constant or the object is not in memory
10022 and need be, put it there. */
10023 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10025 tree nt
= build_qualified_type (TREE_TYPE (tem
),
10026 (TYPE_QUALS (TREE_TYPE (tem
))
10027 | TYPE_QUAL_CONST
));
10028 memloc
= assign_temp (nt
, 1, 1);
10029 emit_move_insn (memloc
, op0
);
10031 mem_attrs_from_type
= true;
10036 enum machine_mode address_mode
;
10037 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10040 gcc_assert (MEM_P (op0
));
10042 address_mode
= get_address_mode (op0
);
10043 if (GET_MODE (offset_rtx
) != address_mode
)
10044 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10046 if (GET_MODE (op0
) == BLKmode
10047 /* A constant address in OP0 can have VOIDmode, we must
10048 not try to call force_reg in that case. */
10049 && GET_MODE (XEXP (op0
, 0)) != VOIDmode
10051 && (bitpos
% bitsize
) == 0
10052 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10053 && MEM_ALIGN (op0
) == GET_MODE_ALIGNMENT (mode1
))
10055 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10059 op0
= offset_address (op0
, offset_rtx
,
10060 highest_pow2_factor (offset
));
10063 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10064 record its alignment as BIGGEST_ALIGNMENT. */
10065 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10066 && is_aligning_offset (offset
, tem
))
10067 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10069 /* Don't forget about volatility even if this is a bitfield. */
10070 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10072 if (op0
== orig_op0
)
10073 op0
= copy_rtx (op0
);
10075 MEM_VOLATILE_P (op0
) = 1;
10078 /* In cases where an aligned union has an unaligned object
10079 as a field, we might be extracting a BLKmode value from
10080 an integer-mode (e.g., SImode) object. Handle this case
10081 by doing the extract into an object as wide as the field
10082 (which we know to be the width of a basic mode), then
10083 storing into memory, and changing the mode to BLKmode. */
10084 if (mode1
== VOIDmode
10085 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10086 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10087 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10088 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10089 && modifier
!= EXPAND_CONST_ADDRESS
10090 && modifier
!= EXPAND_INITIALIZER
10091 && modifier
!= EXPAND_MEMORY
)
10092 /* If the field is volatile, we always want an aligned
10093 access. Do this in following two situations:
10094 1. the access is not already naturally
10095 aligned, otherwise "normal" (non-bitfield) volatile fields
10096 become non-addressable.
10097 2. the bitsize is narrower than the access size. Need
10098 to extract bitfields from the access. */
10099 || (volatilep
&& flag_strict_volatile_bitfields
> 0
10100 && (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0
10101 || (mode1
!= BLKmode
10102 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)))
10103 /* If the field isn't aligned enough to fetch as a memref,
10104 fetch it as a bit field. */
10105 || (mode1
!= BLKmode
10106 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10107 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10109 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10110 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10111 && modifier
!= EXPAND_MEMORY
10112 && ((modifier
== EXPAND_CONST_ADDRESS
10113 || modifier
== EXPAND_INITIALIZER
)
10115 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10116 || (bitpos
% BITS_PER_UNIT
!= 0)))
10117 /* If the type and the field are a constant size and the
10118 size of the type isn't the same size as the bitfield,
10119 we must use bitfield operations. */
10121 && TYPE_SIZE (TREE_TYPE (exp
))
10122 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10123 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10126 enum machine_mode ext_mode
= mode
;
10128 if (ext_mode
== BLKmode
10129 && ! (target
!= 0 && MEM_P (op0
)
10131 && bitpos
% BITS_PER_UNIT
== 0))
10132 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10134 if (ext_mode
== BLKmode
)
10137 target
= assign_temp (type
, 1, 1);
10142 /* In this case, BITPOS must start at a byte boundary and
10143 TARGET, if specified, must be a MEM. */
10144 gcc_assert (MEM_P (op0
)
10145 && (!target
|| MEM_P (target
))
10146 && !(bitpos
% BITS_PER_UNIT
));
10148 emit_block_move (target
,
10149 adjust_address (op0
, VOIDmode
,
10150 bitpos
/ BITS_PER_UNIT
),
10151 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10153 (modifier
== EXPAND_STACK_PARM
10154 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10159 op0
= validize_mem (op0
);
10161 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10162 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10164 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10165 (modifier
== EXPAND_STACK_PARM
10166 ? NULL_RTX
: target
),
10167 ext_mode
, ext_mode
);
10169 /* If the result is a record type and BITSIZE is narrower than
10170 the mode of OP0, an integral mode, and this is a big endian
10171 machine, we must put the field into the high-order bits. */
10172 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10173 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10174 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10175 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10176 GET_MODE_BITSIZE (GET_MODE (op0
))
10177 - bitsize
, op0
, 1);
10179 /* If the result type is BLKmode, store the data into a temporary
10180 of the appropriate type, but with the mode corresponding to the
10181 mode for the data we have (op0's mode). It's tempting to make
10182 this a constant type, since we know it's only being stored once,
10183 but that can cause problems if we are taking the address of this
10184 COMPONENT_REF because the MEM of any reference via that address
10185 will have flags corresponding to the type, which will not
10186 necessarily be constant. */
10187 if (mode
== BLKmode
)
10191 new_rtx
= assign_stack_temp_for_type (ext_mode
,
10192 GET_MODE_BITSIZE (ext_mode
),
10194 emit_move_insn (new_rtx
, op0
);
10195 op0
= copy_rtx (new_rtx
);
10196 PUT_MODE (op0
, BLKmode
);
10202 /* If the result is BLKmode, use that to access the object
10204 if (mode
== BLKmode
)
10207 /* Get a reference to just this component. */
10208 if (modifier
== EXPAND_CONST_ADDRESS
10209 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10210 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10212 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10214 if (op0
== orig_op0
)
10215 op0
= copy_rtx (op0
);
10217 /* If op0 is a temporary because of forcing to memory, pass only the
10218 type to set_mem_attributes so that the original expression is never
10219 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10220 if (mem_attrs_from_type
)
10221 set_mem_attributes (op0
, type
, 0);
10223 set_mem_attributes (op0
, exp
, 0);
10225 if (REG_P (XEXP (op0
, 0)))
10226 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10228 MEM_VOLATILE_P (op0
) |= volatilep
;
10229 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10230 || modifier
== EXPAND_CONST_ADDRESS
10231 || modifier
== EXPAND_INITIALIZER
)
10235 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10237 convert_move (target
, op0
, unsignedp
);
10242 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10245 /* All valid uses of __builtin_va_arg_pack () are removed during
10247 if (CALL_EXPR_VA_ARG_PACK (exp
))
10248 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10250 tree fndecl
= get_callee_fndecl (exp
), attr
;
10253 && (attr
= lookup_attribute ("error",
10254 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10255 error ("%Kcall to %qs declared with attribute error: %s",
10256 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10257 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10259 && (attr
= lookup_attribute ("warning",
10260 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10261 warning_at (tree_nonartificial_location (exp
),
10262 0, "%Kcall to %qs declared with attribute warning: %s",
10263 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10264 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10266 /* Check for a built-in function. */
10267 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10269 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10270 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10273 return expand_call (exp
, target
, ignore
);
10275 case VIEW_CONVERT_EXPR
:
10278 /* If we are converting to BLKmode, try to avoid an intermediate
10279 temporary by fetching an inner memory reference. */
10280 if (mode
== BLKmode
10281 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10282 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10283 && handled_component_p (treeop0
))
10285 enum machine_mode mode1
;
10286 HOST_WIDE_INT bitsize
, bitpos
;
10291 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10292 &offset
, &mode1
, &unsignedp
, &volatilep
,
10296 /* ??? We should work harder and deal with non-zero offsets. */
10298 && (bitpos
% BITS_PER_UNIT
) == 0
10300 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10302 /* See the normal_inner_ref case for the rationale. */
10304 = expand_expr (tem
,
10305 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10306 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10308 && modifier
!= EXPAND_STACK_PARM
10309 ? target
: NULL_RTX
),
10311 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
10313 if (MEM_P (orig_op0
))
10317 /* Get a reference to just this component. */
10318 if (modifier
== EXPAND_CONST_ADDRESS
10319 || modifier
== EXPAND_SUM
10320 || modifier
== EXPAND_INITIALIZER
)
10321 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10323 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10325 if (op0
== orig_op0
)
10326 op0
= copy_rtx (op0
);
10328 set_mem_attributes (op0
, treeop0
, 0);
10329 if (REG_P (XEXP (op0
, 0)))
10330 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10332 MEM_VOLATILE_P (op0
) |= volatilep
;
10338 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
10340 /* If the input and output modes are both the same, we are done. */
10341 if (mode
== GET_MODE (op0
))
10343 /* If neither mode is BLKmode, and both modes are the same size
10344 then we can use gen_lowpart. */
10345 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10346 && (GET_MODE_PRECISION (mode
)
10347 == GET_MODE_PRECISION (GET_MODE (op0
)))
10348 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10350 if (GET_CODE (op0
) == SUBREG
)
10351 op0
= force_reg (GET_MODE (op0
), op0
);
10352 temp
= gen_lowpart_common (mode
, op0
);
10357 if (!REG_P (op0
) && !MEM_P (op0
))
10358 op0
= force_reg (GET_MODE (op0
), op0
);
10359 op0
= gen_lowpart (mode
, op0
);
10362 /* If both types are integral, convert from one mode to the other. */
10363 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10364 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10365 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10366 /* As a last resort, spill op0 to memory, and reload it in a
10368 else if (!MEM_P (op0
))
10370 /* If the operand is not a MEM, force it into memory. Since we
10371 are going to be changing the mode of the MEM, don't call
10372 force_const_mem for constants because we don't allow pool
10373 constants to change mode. */
10374 tree inner_type
= TREE_TYPE (treeop0
);
10376 gcc_assert (!TREE_ADDRESSABLE (exp
));
10378 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10380 = assign_stack_temp_for_type
10381 (TYPE_MODE (inner_type
),
10382 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10384 emit_move_insn (target
, op0
);
10388 /* At this point, OP0 is in the correct mode. If the output type is
10389 such that the operand is known to be aligned, indicate that it is.
10390 Otherwise, we need only be concerned about alignment for non-BLKmode
10394 enum insn_code icode
;
10396 if (TYPE_ALIGN_OK (type
))
10398 /* ??? Copying the MEM without substantially changing it might
10399 run afoul of the code handling volatile memory references in
10400 store_expr, which assumes that TARGET is returned unmodified
10401 if it has been used. */
10402 op0
= copy_rtx (op0
);
10403 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10405 else if (mode
!= BLKmode
10406 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
)
10407 /* If the target does have special handling for unaligned
10408 loads of mode then use them. */
10409 && ((icode
= optab_handler (movmisalign_optab
, mode
))
10410 != CODE_FOR_nothing
))
10414 op0
= adjust_address (op0
, mode
, 0);
10415 /* We've already validated the memory, and we're creating a
10416 new pseudo destination. The predicates really can't
10418 reg
= gen_reg_rtx (mode
);
10420 /* Nor can the insn generator. */
10421 insn
= GEN_FCN (icode
) (reg
, op0
);
10425 else if (STRICT_ALIGNMENT
10427 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10429 tree inner_type
= TREE_TYPE (treeop0
);
10430 HOST_WIDE_INT temp_size
10431 = MAX (int_size_in_bytes (inner_type
),
10432 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10434 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10435 rtx new_with_op0_mode
10436 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10438 gcc_assert (!TREE_ADDRESSABLE (exp
));
10440 if (GET_MODE (op0
) == BLKmode
)
10441 emit_block_move (new_with_op0_mode
, op0
,
10442 GEN_INT (GET_MODE_SIZE (mode
)),
10443 (modifier
== EXPAND_STACK_PARM
10444 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10446 emit_move_insn (new_with_op0_mode
, op0
);
10451 op0
= adjust_address (op0
, mode
, 0);
10458 tree lhs
= treeop0
;
10459 tree rhs
= treeop1
;
10460 gcc_assert (ignore
);
10462 /* Check for |= or &= of a bitfield of size one into another bitfield
10463 of size 1. In this case, (unless we need the result of the
10464 assignment) we can do this more efficiently with a
10465 test followed by an assignment, if necessary.
10467 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10468 things change so we do, this code should be enhanced to
10470 if (TREE_CODE (lhs
) == COMPONENT_REF
10471 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10472 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10473 && TREE_OPERAND (rhs
, 0) == lhs
10474 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10475 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10476 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10478 rtx label
= gen_label_rtx ();
10479 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10480 do_jump (TREE_OPERAND (rhs
, 1),
10482 value
? 0 : label
, -1);
10483 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10485 do_pending_stack_adjust ();
10486 emit_label (label
);
10490 expand_assignment (lhs
, rhs
, false);
10495 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10497 case REALPART_EXPR
:
10498 op0
= expand_normal (treeop0
);
10499 return read_complex_part (op0
, false);
10501 case IMAGPART_EXPR
:
10502 op0
= expand_normal (treeop0
);
10503 return read_complex_part (op0
, true);
10510 /* Expanded in cfgexpand.c. */
10511 gcc_unreachable ();
10513 case TRY_CATCH_EXPR
:
10515 case EH_FILTER_EXPR
:
10516 case TRY_FINALLY_EXPR
:
10517 /* Lowered by tree-eh.c. */
10518 gcc_unreachable ();
10520 case WITH_CLEANUP_EXPR
:
10521 case CLEANUP_POINT_EXPR
:
10523 case CASE_LABEL_EXPR
:
10528 case COMPOUND_EXPR
:
10529 case PREINCREMENT_EXPR
:
10530 case PREDECREMENT_EXPR
:
10531 case POSTINCREMENT_EXPR
:
10532 case POSTDECREMENT_EXPR
:
10535 case COMPOUND_LITERAL_EXPR
:
10536 /* Lowered by gimplify.c. */
10537 gcc_unreachable ();
10540 /* Function descriptors are not valid except for as
10541 initialization constants, and should not be expanded. */
10542 gcc_unreachable ();
10544 case WITH_SIZE_EXPR
:
10545 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10546 have pulled out the size to use in whatever context it needed. */
10547 return expand_expr_real (treeop0
, original_target
, tmode
,
10548 modifier
, alt_rtl
);
10551 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10555 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10556 signedness of TYPE), possibly returning the result in TARGET. */
10558 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10560 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10561 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10563 /* For constant values, reduce using build_int_cst_type. */
10564 if (CONST_INT_P (exp
))
10566 HOST_WIDE_INT value
= INTVAL (exp
);
10567 tree t
= build_int_cst_type (type
, value
);
10568 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10570 else if (TYPE_UNSIGNED (type
))
10572 rtx mask
= immed_double_int_const (double_int::mask (prec
),
10574 return expand_and (GET_MODE (exp
), exp
, mask
, target
);
10578 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10579 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10580 exp
, count
, target
, 0);
10581 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10582 exp
, count
, target
, 0);
10586 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10587 when applied to the address of EXP produces an address known to be
10588 aligned more than BIGGEST_ALIGNMENT. */
10591 is_aligning_offset (const_tree offset
, const_tree exp
)
10593 /* Strip off any conversions. */
10594 while (CONVERT_EXPR_P (offset
))
10595 offset
= TREE_OPERAND (offset
, 0);
10597 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10598 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10599 if (TREE_CODE (offset
) != BIT_AND_EXPR
10600 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
10601 || compare_tree_int (TREE_OPERAND (offset
, 1),
10602 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10603 || !exact_log2 (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1) < 0)
10606 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10607 It must be NEGATE_EXPR. Then strip any more conversions. */
10608 offset
= TREE_OPERAND (offset
, 0);
10609 while (CONVERT_EXPR_P (offset
))
10610 offset
= TREE_OPERAND (offset
, 0);
10612 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10615 offset
= TREE_OPERAND (offset
, 0);
10616 while (CONVERT_EXPR_P (offset
))
10617 offset
= TREE_OPERAND (offset
, 0);
10619 /* This must now be the address of EXP. */
10620 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10623 /* Return the tree node if an ARG corresponds to a string constant or zero
10624 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10625 in bytes within the string that ARG is accessing. The type of the
10626 offset will be `sizetype'. */
10629 string_constant (tree arg
, tree
*ptr_offset
)
10631 tree array
, offset
, lower_bound
;
10634 if (TREE_CODE (arg
) == ADDR_EXPR
)
10636 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10638 *ptr_offset
= size_zero_node
;
10639 return TREE_OPERAND (arg
, 0);
10641 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10643 array
= TREE_OPERAND (arg
, 0);
10644 offset
= size_zero_node
;
10646 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10648 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10649 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10650 if (TREE_CODE (array
) != STRING_CST
10651 && TREE_CODE (array
) != VAR_DECL
)
10654 /* Check if the array has a nonzero lower bound. */
10655 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10656 if (!integer_zerop (lower_bound
))
10658 /* If the offset and base aren't both constants, return 0. */
10659 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10661 if (TREE_CODE (offset
) != INTEGER_CST
)
10663 /* Adjust offset by the lower bound. */
10664 offset
= size_diffop (fold_convert (sizetype
, offset
),
10665 fold_convert (sizetype
, lower_bound
));
10668 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10670 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10671 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10672 if (TREE_CODE (array
) != ADDR_EXPR
)
10674 array
= TREE_OPERAND (array
, 0);
10675 if (TREE_CODE (array
) != STRING_CST
10676 && TREE_CODE (array
) != VAR_DECL
)
10682 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10684 tree arg0
= TREE_OPERAND (arg
, 0);
10685 tree arg1
= TREE_OPERAND (arg
, 1);
10690 if (TREE_CODE (arg0
) == ADDR_EXPR
10691 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10692 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10694 array
= TREE_OPERAND (arg0
, 0);
10697 else if (TREE_CODE (arg1
) == ADDR_EXPR
10698 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10699 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10701 array
= TREE_OPERAND (arg1
, 0);
10710 if (TREE_CODE (array
) == STRING_CST
)
10712 *ptr_offset
= fold_convert (sizetype
, offset
);
10715 else if (TREE_CODE (array
) == VAR_DECL
10716 || TREE_CODE (array
) == CONST_DECL
)
10719 tree init
= ctor_for_folding (array
);
10721 /* Variables initialized to string literals can be handled too. */
10722 if (init
== error_mark_node
10724 || TREE_CODE (init
) != STRING_CST
)
10727 /* Avoid const char foo[4] = "abcde"; */
10728 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10729 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10730 || (length
= TREE_STRING_LENGTH (init
)) <= 0
10731 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10734 /* If variable is bigger than the string literal, OFFSET must be constant
10735 and inside of the bounds of the string literal. */
10736 offset
= fold_convert (sizetype
, offset
);
10737 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10738 && (! tree_fits_uhwi_p (offset
)
10739 || compare_tree_int (offset
, length
) >= 0))
10742 *ptr_offset
= offset
;
10749 /* Generate code to calculate OPS, and exploded expression
10750 using a store-flag instruction and return an rtx for the result.
10751 OPS reflects a comparison.
10753 If TARGET is nonzero, store the result there if convenient.
10755 Return zero if there is no suitable set-flag instruction
10756 available on this machine.
10758 Once expand_expr has been called on the arguments of the comparison,
10759 we are committed to doing the store flag, since it is not safe to
10760 re-evaluate the expression. We emit the store-flag insn by calling
10761 emit_store_flag, but only expand the arguments if we have a reason
10762 to believe that emit_store_flag will be successful. If we think that
10763 it will, but it isn't, we have to simulate the store-flag with a
10764 set/jump/set sequence. */
10767 do_store_flag (sepops ops
, rtx target
, enum machine_mode mode
)
10769 enum rtx_code code
;
10770 tree arg0
, arg1
, type
;
10772 enum machine_mode operand_mode
;
10775 rtx subtarget
= target
;
10776 location_t loc
= ops
->location
;
10781 /* Don't crash if the comparison was erroneous. */
10782 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10785 type
= TREE_TYPE (arg0
);
10786 operand_mode
= TYPE_MODE (type
);
10787 unsignedp
= TYPE_UNSIGNED (type
);
10789 /* We won't bother with BLKmode store-flag operations because it would mean
10790 passing a lot of information to emit_store_flag. */
10791 if (operand_mode
== BLKmode
)
10794 /* We won't bother with store-flag operations involving function pointers
10795 when function pointers must be canonicalized before comparisons. */
10796 #ifdef HAVE_canonicalize_funcptr_for_compare
10797 if (HAVE_canonicalize_funcptr_for_compare
10798 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10799 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10801 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10802 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10803 == FUNCTION_TYPE
))))
10810 /* For vector typed comparisons emit code to generate the desired
10811 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10812 expander for this. */
10813 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10815 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10816 tree if_true
= constant_boolean_node (true, ops
->type
);
10817 tree if_false
= constant_boolean_node (false, ops
->type
);
10818 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10821 /* Get the rtx comparison code to use. We know that EXP is a comparison
10822 operation of some type. Some comparisons against 1 and -1 can be
10823 converted to comparisons with zero. Do so here so that the tests
10824 below will be aware that we have a comparison with zero. These
10825 tests will not catch constants in the first operand, but constants
10826 are rarely passed as the first operand. */
10837 if (integer_onep (arg1
))
10838 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
10840 code
= unsignedp
? LTU
: LT
;
10843 if (! unsignedp
&& integer_all_onesp (arg1
))
10844 arg1
= integer_zero_node
, code
= LT
;
10846 code
= unsignedp
? LEU
: LE
;
10849 if (! unsignedp
&& integer_all_onesp (arg1
))
10850 arg1
= integer_zero_node
, code
= GE
;
10852 code
= unsignedp
? GTU
: GT
;
10855 if (integer_onep (arg1
))
10856 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
10858 code
= unsignedp
? GEU
: GE
;
10861 case UNORDERED_EXPR
:
10887 gcc_unreachable ();
10890 /* Put a constant second. */
10891 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
10892 || TREE_CODE (arg0
) == FIXED_CST
)
10894 tem
= arg0
; arg0
= arg1
; arg1
= tem
;
10895 code
= swap_condition (code
);
10898 /* If this is an equality or inequality test of a single bit, we can
10899 do this by shifting the bit being tested to the low-order bit and
10900 masking the result with the constant 1. If the condition was EQ,
10901 we xor it with 1. This does not require an scc insn and is faster
10902 than an scc insn even if we have it.
10904 The code to make this transformation was moved into fold_single_bit_test,
10905 so we just call into the folder and expand its result. */
10907 if ((code
== NE
|| code
== EQ
)
10908 && integer_zerop (arg1
)
10909 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
10911 gimple srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
10913 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
10915 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
10916 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10917 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
10918 gimple_assign_rhs1 (srcstmt
),
10919 gimple_assign_rhs2 (srcstmt
));
10920 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
10922 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
10926 if (! get_subtarget (target
)
10927 || GET_MODE (subtarget
) != operand_mode
)
10930 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10933 target
= gen_reg_rtx (mode
);
10935 /* Try a cstore if possible. */
10936 return emit_store_flag_force (target
, code
, op0
, op1
,
10937 operand_mode
, unsignedp
,
10938 (TYPE_PRECISION (ops
->type
) == 1
10939 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
10943 /* Stubs in case we haven't got a casesi insn. */
10944 #ifndef HAVE_casesi
10945 # define HAVE_casesi 0
10946 # define gen_casesi(a, b, c, d, e) (0)
10947 # define CODE_FOR_casesi CODE_FOR_nothing
10950 /* Attempt to generate a casesi instruction. Returns 1 if successful,
10951 0 otherwise (i.e. if there is no casesi instruction).
10953 DEFAULT_PROBABILITY is the probability of jumping to the default
10956 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
10957 rtx table_label
, rtx default_label
, rtx fallback_label
,
10958 int default_probability
)
10960 struct expand_operand ops
[5];
10961 enum machine_mode index_mode
= SImode
;
10962 rtx op1
, op2
, index
;
10967 /* Convert the index to SImode. */
10968 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
10970 enum machine_mode omode
= TYPE_MODE (index_type
);
10971 rtx rangertx
= expand_normal (range
);
10973 /* We must handle the endpoints in the original mode. */
10974 index_expr
= build2 (MINUS_EXPR
, index_type
,
10975 index_expr
, minval
);
10976 minval
= integer_zero_node
;
10977 index
= expand_normal (index_expr
);
10979 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
10980 omode
, 1, default_label
,
10981 default_probability
);
10982 /* Now we can safely truncate. */
10983 index
= convert_to_mode (index_mode
, index
, 0);
10987 if (TYPE_MODE (index_type
) != index_mode
)
10989 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
10990 index_expr
= fold_convert (index_type
, index_expr
);
10993 index
= expand_normal (index_expr
);
10996 do_pending_stack_adjust ();
10998 op1
= expand_normal (minval
);
10999 op2
= expand_normal (range
);
11001 create_input_operand (&ops
[0], index
, index_mode
);
11002 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
11003 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
11004 create_fixed_operand (&ops
[3], table_label
);
11005 create_fixed_operand (&ops
[4], (default_label
11007 : fallback_label
));
11008 expand_jump_insn (CODE_FOR_casesi
, 5, ops
);
11012 /* Attempt to generate a tablejump instruction; same concept. */
11013 #ifndef HAVE_tablejump
11014 #define HAVE_tablejump 0
11015 #define gen_tablejump(x, y) (0)
11018 /* Subroutine of the next function.
11020 INDEX is the value being switched on, with the lowest value
11021 in the table already subtracted.
11022 MODE is its expected mode (needed if INDEX is constant).
11023 RANGE is the length of the jump table.
11024 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11026 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11027 index value is out of range.
11028 DEFAULT_PROBABILITY is the probability of jumping to
11029 the default label. */
11032 do_tablejump (rtx index
, enum machine_mode mode
, rtx range
, rtx table_label
,
11033 rtx default_label
, int default_probability
)
11037 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11038 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11040 /* Do an unsigned comparison (in the proper mode) between the index
11041 expression and the value which represents the length of the range.
11042 Since we just finished subtracting the lower bound of the range
11043 from the index expression, this comparison allows us to simultaneously
11044 check that the original index expression value is both greater than
11045 or equal to the minimum value of the range and less than or equal to
11046 the maximum value of the range. */
11049 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11050 default_label
, default_probability
);
11053 /* If index is in range, it must fit in Pmode.
11054 Convert to Pmode so we can index with it. */
11056 index
= convert_to_mode (Pmode
, index
, 1);
11058 /* Don't let a MEM slip through, because then INDEX that comes
11059 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11060 and break_out_memory_refs will go to work on it and mess it up. */
11061 #ifdef PIC_CASE_VECTOR_ADDRESS
11062 if (flag_pic
&& !REG_P (index
))
11063 index
= copy_to_mode_reg (Pmode
, index
);
11066 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11067 GET_MODE_SIZE, because this indicates how large insns are. The other
11068 uses should all be Pmode, because they are addresses. This code
11069 could fail if addresses and insns are not the same size. */
11070 index
= gen_rtx_PLUS
11072 gen_rtx_MULT (Pmode
, index
,
11073 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
), Pmode
)),
11074 gen_rtx_LABEL_REF (Pmode
, table_label
));
11075 #ifdef PIC_CASE_VECTOR_ADDRESS
11077 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11080 index
= memory_address (CASE_VECTOR_MODE
, index
);
11081 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11082 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11083 convert_move (temp
, vector
, 0);
11085 emit_jump_insn (gen_tablejump (temp
, table_label
));
11087 /* If we are generating PIC code or if the table is PC-relative, the
11088 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11089 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11094 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11095 rtx table_label
, rtx default_label
, int default_probability
)
11099 if (! HAVE_tablejump
)
11102 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11103 fold_convert (index_type
, index_expr
),
11104 fold_convert (index_type
, minval
));
11105 index
= expand_normal (index_expr
);
11106 do_pending_stack_adjust ();
11108 do_tablejump (index
, TYPE_MODE (index_type
),
11109 convert_modes (TYPE_MODE (index_type
),
11110 TYPE_MODE (TREE_TYPE (range
)),
11111 expand_normal (range
),
11112 TYPE_UNSIGNED (TREE_TYPE (range
))),
11113 table_label
, default_label
, default_probability
);
11117 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11119 const_vector_from_tree (tree exp
)
11125 enum machine_mode inner
, mode
;
11127 mode
= TYPE_MODE (TREE_TYPE (exp
));
11129 if (initializer_zerop (exp
))
11130 return CONST0_RTX (mode
);
11132 units
= GET_MODE_NUNITS (mode
);
11133 inner
= GET_MODE_INNER (mode
);
11135 v
= rtvec_alloc (units
);
11137 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11139 elt
= VECTOR_CST_ELT (exp
, i
);
11141 if (TREE_CODE (elt
) == REAL_CST
)
11142 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11144 else if (TREE_CODE (elt
) == FIXED_CST
)
11145 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11148 RTVEC_ELT (v
, i
) = immed_double_int_const (tree_to_double_int (elt
),
11152 return gen_rtx_CONST_VECTOR (mode
, v
);
11155 /* Build a decl for a personality function given a language prefix. */
11158 build_personality_function (const char *lang
)
11160 const char *unwind_and_version
;
11164 switch (targetm_common
.except_unwind_info (&global_options
))
11169 unwind_and_version
= "_sj0";
11173 unwind_and_version
= "_v0";
11176 unwind_and_version
= "_seh0";
11179 gcc_unreachable ();
11182 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11184 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11185 long_long_unsigned_type_node
,
11186 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11187 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11188 get_identifier (name
), type
);
11189 DECL_ARTIFICIAL (decl
) = 1;
11190 DECL_EXTERNAL (decl
) = 1;
11191 TREE_PUBLIC (decl
) = 1;
11193 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11194 are the flags assigned by targetm.encode_section_info. */
11195 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11200 /* Extracts the personality function of DECL and returns the corresponding
11204 get_personality_function (tree decl
)
11206 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11207 enum eh_personality_kind pk
;
11209 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11210 if (pk
== eh_personality_none
)
11214 && pk
== eh_personality_any
)
11215 personality
= lang_hooks
.eh_personality ();
11217 if (pk
== eh_personality_lang
)
11218 gcc_assert (personality
!= NULL_TREE
);
11220 return XEXP (DECL_RTL (personality
), 0);
11223 #include "gt-expr.h"