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"
50 #include "basic-block.h"
51 #include "tree-ssa-alias.h"
52 #include "internal-fn.h"
53 #include "gimple-expr.h"
56 #include "gimple-ssa.h"
58 #include "tree-ssanames.h"
60 #include "common/common-target.h"
63 #include "diagnostic.h"
64 #include "tree-ssa-live.h"
65 #include "tree-outof-ssa.h"
66 #include "target-globals.h"
68 #include "tree-ssa-address.h"
69 #include "cfgexpand.h"
71 /* Decide whether a function's arguments should be processed
72 from first to last or from last to first.
74 They should if the stack and args grow in opposite directions, but
75 only if we have push insns. */
79 #ifndef PUSH_ARGS_REVERSED
80 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
81 #define PUSH_ARGS_REVERSED /* If it's last to first. */
87 #ifndef STACK_PUSH_CODE
88 #ifdef STACK_GROWS_DOWNWARD
89 #define STACK_PUSH_CODE PRE_DEC
91 #define STACK_PUSH_CODE PRE_INC
96 /* If this is nonzero, we do not bother generating VOLATILE
97 around volatile memory references, and we are willing to
98 output indirect addresses. If cse is to follow, we reject
99 indirect addresses so a useful potential cse is generated;
100 if it is used only once, instruction combination will produce
101 the same indirect address eventually. */
102 int cse_not_expected
;
104 /* This structure is used by move_by_pieces to describe the move to
106 struct move_by_pieces_d
115 int explicit_inc_from
;
116 unsigned HOST_WIDE_INT len
;
117 HOST_WIDE_INT offset
;
121 /* This structure is used by store_by_pieces to describe the clear to
124 struct store_by_pieces_d
130 unsigned HOST_WIDE_INT len
;
131 HOST_WIDE_INT offset
;
132 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
);
137 static void move_by_pieces_1 (insn_gen_fn
, machine_mode
,
138 struct move_by_pieces_d
*);
139 static bool block_move_libcall_safe_for_call_parm (void);
140 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned, unsigned, HOST_WIDE_INT
,
141 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
142 unsigned HOST_WIDE_INT
);
143 static tree
emit_block_move_libcall_fn (int);
144 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
145 static rtx
clear_by_pieces_1 (void *, HOST_WIDE_INT
, enum machine_mode
);
146 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
147 static void store_by_pieces_1 (struct store_by_pieces_d
*, unsigned int);
148 static void store_by_pieces_2 (insn_gen_fn
, machine_mode
,
149 struct store_by_pieces_d
*);
150 static tree
clear_storage_libcall_fn (int);
151 static rtx
compress_float_constant (rtx
, rtx
);
152 static rtx
get_subtarget (rtx
);
153 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
154 HOST_WIDE_INT
, enum machine_mode
,
155 tree
, int, alias_set_type
);
156 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
);
157 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
,
158 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
159 enum machine_mode
, tree
, alias_set_type
, bool);
161 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
163 static int is_aligning_offset (const_tree
, const_tree
);
164 static void expand_operands (tree
, tree
, rtx
, rtx
*, rtx
*,
165 enum expand_modifier
);
166 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
167 static rtx
do_store_flag (sepops
, rtx
, enum machine_mode
);
169 static void emit_single_push_insn (enum machine_mode
, rtx
, tree
);
171 static void do_tablejump (rtx
, enum machine_mode
, rtx
, rtx
, rtx
, int);
172 static rtx
const_vector_from_tree (tree
);
173 static void write_complex_part (rtx
, rtx
, bool);
175 /* This macro is used to determine whether move_by_pieces should be called
176 to perform a structure copy. */
177 #ifndef MOVE_BY_PIECES_P
178 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
179 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
180 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
183 /* This macro is used to determine whether clear_by_pieces should be
184 called to clear storage. */
185 #ifndef CLEAR_BY_PIECES_P
186 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
187 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
188 < (unsigned int) CLEAR_RATIO (optimize_insn_for_speed_p ()))
191 /* This macro is used to determine whether store_by_pieces should be
192 called to "memset" storage with byte values other than zero. */
193 #ifndef SET_BY_PIECES_P
194 #define SET_BY_PIECES_P(SIZE, ALIGN) \
195 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
196 < (unsigned int) SET_RATIO (optimize_insn_for_speed_p ()))
199 /* This macro is used to determine whether store_by_pieces should be
200 called to "memcpy" storage when the source is a constant string. */
201 #ifndef STORE_BY_PIECES_P
202 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
203 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
204 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
207 /* This is run to set up which modes can be used
208 directly in memory and to initialize the block move optab. It is run
209 at the beginning of compilation and when the target is reinitialized. */
212 init_expr_target (void)
215 enum machine_mode mode
;
220 /* Try indexing by frame ptr and try by stack ptr.
221 It is known that on the Convex the stack ptr isn't a valid index.
222 With luck, one or the other is valid on any machine. */
223 mem
= gen_rtx_MEM (VOIDmode
, stack_pointer_rtx
);
224 mem1
= gen_rtx_MEM (VOIDmode
, frame_pointer_rtx
);
226 /* A scratch register we can modify in-place below to avoid
227 useless RTL allocations. */
228 reg
= gen_rtx_REG (VOIDmode
, -1);
230 insn
= rtx_alloc (INSN
);
231 pat
= gen_rtx_SET (VOIDmode
, NULL_RTX
, NULL_RTX
);
232 PATTERN (insn
) = pat
;
234 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
235 mode
= (enum machine_mode
) ((int) mode
+ 1))
239 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
240 PUT_MODE (mem
, mode
);
241 PUT_MODE (mem1
, mode
);
242 PUT_MODE (reg
, mode
);
244 /* See if there is some register that can be used in this mode and
245 directly loaded or stored from memory. */
247 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
248 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
249 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
252 if (! HARD_REGNO_MODE_OK (regno
, mode
))
255 SET_REGNO (reg
, regno
);
258 SET_DEST (pat
) = reg
;
259 if (recog (pat
, insn
, &num_clobbers
) >= 0)
260 direct_load
[(int) mode
] = 1;
262 SET_SRC (pat
) = mem1
;
263 SET_DEST (pat
) = reg
;
264 if (recog (pat
, insn
, &num_clobbers
) >= 0)
265 direct_load
[(int) mode
] = 1;
268 SET_DEST (pat
) = mem
;
269 if (recog (pat
, insn
, &num_clobbers
) >= 0)
270 direct_store
[(int) mode
] = 1;
273 SET_DEST (pat
) = mem1
;
274 if (recog (pat
, insn
, &num_clobbers
) >= 0)
275 direct_store
[(int) mode
] = 1;
279 mem
= gen_rtx_MEM (VOIDmode
, gen_rtx_raw_REG (Pmode
, 10000));
281 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
282 mode
= GET_MODE_WIDER_MODE (mode
))
284 enum machine_mode srcmode
;
285 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
286 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
290 ic
= can_extend_p (mode
, srcmode
, 0);
291 if (ic
== CODE_FOR_nothing
)
294 PUT_MODE (mem
, srcmode
);
296 if (insn_operand_matches (ic
, 1, mem
))
297 float_extend_from_mem
[mode
][srcmode
] = true;
302 /* This is run at the start of compiling a function. */
307 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
310 /* Copy data from FROM to TO, where the machine modes are not the same.
311 Both modes may be integer, or both may be floating, or both may be
313 UNSIGNEDP should be nonzero if FROM is an unsigned type.
314 This causes zero-extension instead of sign-extension. */
317 convert_move (rtx to
, rtx from
, int unsignedp
)
319 enum machine_mode to_mode
= GET_MODE (to
);
320 enum machine_mode from_mode
= GET_MODE (from
);
321 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
322 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
326 /* rtx code for making an equivalent value. */
327 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
328 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
331 gcc_assert (to_real
== from_real
);
332 gcc_assert (to_mode
!= BLKmode
);
333 gcc_assert (from_mode
!= BLKmode
);
335 /* If the source and destination are already the same, then there's
340 /* If FROM is a SUBREG that indicates that we have already done at least
341 the required extension, strip it. We don't handle such SUBREGs as
344 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
345 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
346 >= GET_MODE_PRECISION (to_mode
))
347 && SUBREG_PROMOTED_UNSIGNED_P (from
) == unsignedp
)
348 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
350 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
352 if (to_mode
== from_mode
353 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
355 emit_move_insn (to
, from
);
359 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
361 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
363 if (VECTOR_MODE_P (to_mode
))
364 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
366 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
368 emit_move_insn (to
, from
);
372 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
374 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
375 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
384 gcc_assert ((GET_MODE_PRECISION (from_mode
)
385 != GET_MODE_PRECISION (to_mode
))
386 || (DECIMAL_FLOAT_MODE_P (from_mode
)
387 != DECIMAL_FLOAT_MODE_P (to_mode
)));
389 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
390 /* Conversion between decimal float and binary float, same size. */
391 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
392 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
397 /* Try converting directly if the insn is supported. */
399 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
400 if (code
!= CODE_FOR_nothing
)
402 emit_unop_insn (code
, to
, from
,
403 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
407 /* Otherwise use a libcall. */
408 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
410 /* Is this conversion implemented yet? */
411 gcc_assert (libcall
);
414 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
416 insns
= get_insns ();
418 emit_libcall_block (insns
, to
, value
,
419 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
421 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
425 /* Handle pointer conversion. */ /* SPEE 900220. */
426 /* Targets are expected to provide conversion insns between PxImode and
427 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
428 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
430 enum machine_mode full_mode
431 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
433 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
434 != CODE_FOR_nothing
);
436 if (full_mode
!= from_mode
)
437 from
= convert_to_mode (full_mode
, from
, unsignedp
);
438 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
442 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
445 enum machine_mode full_mode
446 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
447 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
448 enum insn_code icode
;
450 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
451 gcc_assert (icode
!= CODE_FOR_nothing
);
453 if (to_mode
== full_mode
)
455 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
459 new_from
= gen_reg_rtx (full_mode
);
460 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
462 /* else proceed to integer conversions below. */
463 from_mode
= full_mode
;
467 /* Make sure both are fixed-point modes or both are not. */
468 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
469 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
470 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
472 /* If we widen from_mode to to_mode and they are in the same class,
473 we won't saturate the result.
474 Otherwise, always saturate the result to play safe. */
475 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
476 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
477 expand_fixed_convert (to
, from
, 0, 0);
479 expand_fixed_convert (to
, from
, 0, 1);
483 /* Now both modes are integers. */
485 /* Handle expanding beyond a word. */
486 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
487 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
494 enum machine_mode lowpart_mode
;
495 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
497 /* Try converting directly if the insn is supported. */
498 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
501 /* If FROM is a SUBREG, put it into a register. Do this
502 so that we always generate the same set of insns for
503 better cse'ing; if an intermediate assignment occurred,
504 we won't be doing the operation directly on the SUBREG. */
505 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
506 from
= force_reg (from_mode
, from
);
507 emit_unop_insn (code
, to
, from
, equiv_code
);
510 /* Next, try converting via full word. */
511 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
512 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
513 != CODE_FOR_nothing
))
515 rtx word_to
= gen_reg_rtx (word_mode
);
518 if (reg_overlap_mentioned_p (to
, from
))
519 from
= force_reg (from_mode
, from
);
522 convert_move (word_to
, from
, unsignedp
);
523 emit_unop_insn (code
, to
, word_to
, equiv_code
);
527 /* No special multiword conversion insn; do it by hand. */
530 /* Since we will turn this into a no conflict block, we must ensure the
531 the source does not overlap the target so force it into an isolated
532 register when maybe so. Likewise for any MEM input, since the
533 conversion sequence might require several references to it and we
534 must ensure we're getting the same value every time. */
536 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
537 from
= force_reg (from_mode
, from
);
539 /* Get a copy of FROM widened to a word, if necessary. */
540 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
541 lowpart_mode
= word_mode
;
543 lowpart_mode
= from_mode
;
545 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
547 lowpart
= gen_lowpart (lowpart_mode
, to
);
548 emit_move_insn (lowpart
, lowfrom
);
550 /* Compute the value to put in each remaining word. */
552 fill_value
= const0_rtx
;
554 fill_value
= emit_store_flag (gen_reg_rtx (word_mode
),
555 LT
, lowfrom
, const0_rtx
,
558 /* Fill the remaining words. */
559 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
561 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
562 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
564 gcc_assert (subword
);
566 if (fill_value
!= subword
)
567 emit_move_insn (subword
, fill_value
);
570 insns
= get_insns ();
577 /* Truncating multi-word to a word or less. */
578 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
579 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
582 && ! MEM_VOLATILE_P (from
)
583 && direct_load
[(int) to_mode
]
584 && ! mode_dependent_address_p (XEXP (from
, 0),
585 MEM_ADDR_SPACE (from
)))
587 || GET_CODE (from
) == SUBREG
))
588 from
= force_reg (from_mode
, from
);
589 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
593 /* Now follow all the conversions between integers
594 no more than a word long. */
596 /* For truncation, usually we can just refer to FROM in a narrower mode. */
597 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
598 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
601 && ! MEM_VOLATILE_P (from
)
602 && direct_load
[(int) to_mode
]
603 && ! mode_dependent_address_p (XEXP (from
, 0),
604 MEM_ADDR_SPACE (from
)))
606 || GET_CODE (from
) == SUBREG
))
607 from
= force_reg (from_mode
, from
);
608 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
609 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
610 from
= copy_to_reg (from
);
611 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
615 /* Handle extension. */
616 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
618 /* Convert directly if that works. */
619 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
622 emit_unop_insn (code
, to
, from
, equiv_code
);
627 enum machine_mode intermediate
;
631 /* Search for a mode to convert via. */
632 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
633 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
634 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
636 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
637 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
638 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
639 != CODE_FOR_nothing
))
641 convert_move (to
, convert_to_mode (intermediate
, from
,
642 unsignedp
), unsignedp
);
646 /* No suitable intermediate mode.
647 Generate what we need with shifts. */
648 shift_amount
= (GET_MODE_PRECISION (to_mode
)
649 - GET_MODE_PRECISION (from_mode
));
650 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
651 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
653 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
656 emit_move_insn (to
, tmp
);
661 /* Support special truncate insns for certain modes. */
662 if (convert_optab_handler (trunc_optab
, to_mode
,
663 from_mode
) != CODE_FOR_nothing
)
665 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
670 /* Handle truncation of volatile memrefs, and so on;
671 the things that couldn't be truncated directly,
672 and for which there was no special instruction.
674 ??? Code above formerly short-circuited this, for most integer
675 mode pairs, with a force_reg in from_mode followed by a recursive
676 call to this routine. Appears always to have been wrong. */
677 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
679 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
680 emit_move_insn (to
, temp
);
684 /* Mode combination is not recognized. */
688 /* Return an rtx for a value that would result
689 from converting X to mode MODE.
690 Both X and MODE may be floating, or both integer.
691 UNSIGNEDP is nonzero if X is an unsigned value.
692 This can be done by referring to a part of X in place
693 or by copying to a new temporary with conversion. */
696 convert_to_mode (enum machine_mode mode
, rtx x
, int unsignedp
)
698 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
701 /* Return an rtx for a value that would result
702 from converting X from mode OLDMODE to mode MODE.
703 Both modes may be floating, or both integer.
704 UNSIGNEDP is nonzero if X is an unsigned value.
706 This can be done by referring to a part of X in place
707 or by copying to a new temporary with conversion.
709 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
712 convert_modes (enum machine_mode mode
, enum machine_mode oldmode
, rtx x
, int unsignedp
)
716 /* If FROM is a SUBREG that indicates that we have already done at least
717 the required extension, strip it. */
719 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
720 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
721 && SUBREG_PROMOTED_UNSIGNED_P (x
) == unsignedp
)
722 x
= gen_lowpart (mode
, x
);
724 if (GET_MODE (x
) != VOIDmode
)
725 oldmode
= GET_MODE (x
);
730 /* There is one case that we must handle specially: If we are converting
731 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
732 we are to interpret the constant as unsigned, gen_lowpart will do
733 the wrong if the constant appears negative. What we want to do is
734 make the high-order word of the constant zero, not all ones. */
736 if (unsignedp
&& GET_MODE_CLASS (mode
) == MODE_INT
737 && GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
738 && CONST_INT_P (x
) && INTVAL (x
) < 0)
740 double_int val
= double_int::from_uhwi (INTVAL (x
));
742 /* We need to zero extend VAL. */
743 if (oldmode
!= VOIDmode
)
744 val
= val
.zext (GET_MODE_BITSIZE (oldmode
));
746 return immed_double_int_const (val
, mode
);
749 /* We can do this with a gen_lowpart if both desired and current modes
750 are integer, and this is either a constant integer, a register, or a
751 non-volatile MEM. Except for the constant case where MODE is no
752 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
755 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
)
756 || (GET_MODE_CLASS (mode
) == MODE_INT
757 && GET_MODE_CLASS (oldmode
) == MODE_INT
758 && (CONST_DOUBLE_AS_INT_P (x
)
759 || (GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
760 && ((MEM_P (x
) && ! MEM_VOLATILE_P (x
)
761 && direct_load
[(int) mode
])
763 && (! HARD_REGISTER_P (x
)
764 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
765 && TRULY_NOOP_TRUNCATION_MODES_P (mode
,
768 /* ?? If we don't know OLDMODE, we have to assume here that
769 X does not need sign- or zero-extension. This may not be
770 the case, but it's the best we can do. */
771 if (CONST_INT_P (x
) && oldmode
!= VOIDmode
772 && GET_MODE_PRECISION (mode
) > GET_MODE_PRECISION (oldmode
))
774 HOST_WIDE_INT val
= INTVAL (x
);
776 /* We must sign or zero-extend in this case. Start by
777 zero-extending, then sign extend if we need to. */
778 val
&= GET_MODE_MASK (oldmode
);
780 && val_signbit_known_set_p (oldmode
, val
))
781 val
|= ~GET_MODE_MASK (oldmode
);
783 return gen_int_mode (val
, mode
);
786 return gen_lowpart (mode
, x
);
789 /* Converting from integer constant into mode is always equivalent to an
791 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
793 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
794 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
797 temp
= gen_reg_rtx (mode
);
798 convert_move (temp
, x
, unsignedp
);
802 /* Return the largest alignment we can use for doing a move (or store)
803 of MAX_PIECES. ALIGN is the largest alignment we could use. */
806 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
808 enum machine_mode tmode
;
810 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
811 if (align
>= GET_MODE_ALIGNMENT (tmode
))
812 align
= GET_MODE_ALIGNMENT (tmode
);
815 enum machine_mode tmode
, xmode
;
817 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
819 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
820 if (GET_MODE_SIZE (tmode
) > max_pieces
821 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
824 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
830 /* Return the widest integer mode no wider than SIZE. If no such mode
831 can be found, return VOIDmode. */
833 static enum machine_mode
834 widest_int_mode_for_size (unsigned int size
)
836 enum machine_mode tmode
, mode
= VOIDmode
;
838 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
839 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
840 if (GET_MODE_SIZE (tmode
) < size
)
846 /* STORE_MAX_PIECES is the number of bytes at a time that we can
847 store efficiently. Due to internal GCC limitations, this is
848 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
849 for an immediate constant. */
851 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
853 /* Determine whether the LEN bytes can be moved by using several move
854 instructions. Return nonzero if a call to move_by_pieces should
858 can_move_by_pieces (unsigned HOST_WIDE_INT len ATTRIBUTE_UNUSED
,
859 unsigned int align ATTRIBUTE_UNUSED
)
861 return MOVE_BY_PIECES_P (len
, align
);
864 /* Generate several move instructions to copy LEN bytes from block FROM to
865 block TO. (These are MEM rtx's with BLKmode).
867 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
868 used to push FROM to the stack.
870 ALIGN is maximum stack alignment we can assume.
872 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
873 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
877 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
878 unsigned int align
, int endp
)
880 struct move_by_pieces_d data
;
881 enum machine_mode to_addr_mode
;
882 enum machine_mode from_addr_mode
= get_address_mode (from
);
883 rtx to_addr
, from_addr
= XEXP (from
, 0);
884 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
885 enum insn_code icode
;
887 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
890 data
.from_addr
= from_addr
;
893 to_addr_mode
= get_address_mode (to
);
894 to_addr
= XEXP (to
, 0);
897 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
898 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
900 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
904 to_addr_mode
= VOIDmode
;
908 #ifdef STACK_GROWS_DOWNWARD
914 data
.to_addr
= to_addr
;
917 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
918 || GET_CODE (from_addr
) == POST_INC
919 || GET_CODE (from_addr
) == POST_DEC
);
921 data
.explicit_inc_from
= 0;
922 data
.explicit_inc_to
= 0;
923 if (data
.reverse
) data
.offset
= len
;
926 /* If copying requires more than two move insns,
927 copy addresses to registers (to make displacements shorter)
928 and use post-increment if available. */
929 if (!(data
.autinc_from
&& data
.autinc_to
)
930 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
932 /* Find the mode of the largest move...
933 MODE might not be used depending on the definitions of the
934 USE_* macros below. */
935 enum machine_mode mode ATTRIBUTE_UNUSED
936 = widest_int_mode_for_size (max_size
);
938 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
940 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
941 plus_constant (from_addr_mode
,
943 data
.autinc_from
= 1;
944 data
.explicit_inc_from
= -1;
946 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
948 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
949 data
.autinc_from
= 1;
950 data
.explicit_inc_from
= 1;
952 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
953 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
954 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
956 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
957 plus_constant (to_addr_mode
,
960 data
.explicit_inc_to
= -1;
962 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
964 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
966 data
.explicit_inc_to
= 1;
968 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
969 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
972 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
974 /* First move what we can in the largest integer mode, then go to
975 successively smaller modes. */
977 while (max_size
> 1 && data
.len
> 0)
979 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
981 if (mode
== VOIDmode
)
984 icode
= optab_handler (mov_optab
, mode
);
985 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
986 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
988 max_size
= GET_MODE_SIZE (mode
);
991 /* The code above should have handled everything. */
992 gcc_assert (!data
.len
);
998 gcc_assert (!data
.reverse
);
1003 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
1004 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
1006 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
1007 plus_constant (to_addr_mode
,
1011 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
1018 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
1026 /* Return number of insns required to move L bytes by pieces.
1027 ALIGN (in bits) is maximum alignment we can assume. */
1029 unsigned HOST_WIDE_INT
1030 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
1031 unsigned int max_size
)
1033 unsigned HOST_WIDE_INT n_insns
= 0;
1035 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
1037 while (max_size
> 1 && l
> 0)
1039 enum machine_mode mode
;
1040 enum insn_code icode
;
1042 mode
= widest_int_mode_for_size (max_size
);
1044 if (mode
== VOIDmode
)
1047 icode
= optab_handler (mov_optab
, mode
);
1048 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
1049 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
1051 max_size
= GET_MODE_SIZE (mode
);
1058 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1059 with move instructions for mode MODE. GENFUN is the gen_... function
1060 to make a move insn for that mode. DATA has all the other info. */
1063 move_by_pieces_1 (insn_gen_fn genfun
, machine_mode mode
,
1064 struct move_by_pieces_d
*data
)
1066 unsigned int size
= GET_MODE_SIZE (mode
);
1067 rtx to1
= NULL_RTX
, from1
;
1069 while (data
->len
>= size
)
1072 data
->offset
-= size
;
1076 if (data
->autinc_to
)
1077 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1080 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1083 if (data
->autinc_from
)
1084 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1087 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1089 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1090 emit_insn (gen_add2_insn (data
->to_addr
,
1091 gen_int_mode (-(HOST_WIDE_INT
) size
,
1092 GET_MODE (data
->to_addr
))));
1093 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1094 emit_insn (gen_add2_insn (data
->from_addr
,
1095 gen_int_mode (-(HOST_WIDE_INT
) size
,
1096 GET_MODE (data
->from_addr
))));
1099 emit_insn ((*genfun
) (to1
, from1
));
1102 #ifdef PUSH_ROUNDING
1103 emit_single_push_insn (mode
, from1
, NULL
);
1109 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1110 emit_insn (gen_add2_insn (data
->to_addr
,
1112 GET_MODE (data
->to_addr
))));
1113 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1114 emit_insn (gen_add2_insn (data
->from_addr
,
1116 GET_MODE (data
->from_addr
))));
1118 if (! data
->reverse
)
1119 data
->offset
+= size
;
1125 /* Emit code to move a block Y to a block X. This may be done with
1126 string-move instructions, with multiple scalar move instructions,
1127 or with a library call.
1129 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1130 SIZE is an rtx that says how long they are.
1131 ALIGN is the maximum alignment we can assume they have.
1132 METHOD describes what kind of copy this is, and what mechanisms may be used.
1133 MIN_SIZE is the minimal size of block to move
1134 MAX_SIZE is the maximal size of block to move, if it can not be represented
1135 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1137 Return the address of the new block, if memcpy is called and returns it,
1141 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1142 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1143 unsigned HOST_WIDE_INT min_size
,
1144 unsigned HOST_WIDE_INT max_size
,
1145 unsigned HOST_WIDE_INT probable_max_size
)
1152 if (CONST_INT_P (size
)
1153 && INTVAL (size
) == 0)
1158 case BLOCK_OP_NORMAL
:
1159 case BLOCK_OP_TAILCALL
:
1160 may_use_call
= true;
1163 case BLOCK_OP_CALL_PARM
:
1164 may_use_call
= block_move_libcall_safe_for_call_parm ();
1166 /* Make inhibit_defer_pop nonzero around the library call
1167 to force it to pop the arguments right away. */
1171 case BLOCK_OP_NO_LIBCALL
:
1172 may_use_call
= false;
1179 gcc_assert (MEM_P (x
) && MEM_P (y
));
1180 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1181 gcc_assert (align
>= BITS_PER_UNIT
);
1183 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1184 block copy is more efficient for other large modes, e.g. DCmode. */
1185 x
= adjust_address (x
, BLKmode
, 0);
1186 y
= adjust_address (y
, BLKmode
, 0);
1188 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1189 can be incorrect is coming from __builtin_memcpy. */
1190 if (CONST_INT_P (size
))
1192 x
= shallow_copy_rtx (x
);
1193 y
= shallow_copy_rtx (y
);
1194 set_mem_size (x
, INTVAL (size
));
1195 set_mem_size (y
, INTVAL (size
));
1198 if (CONST_INT_P (size
) && MOVE_BY_PIECES_P (INTVAL (size
), align
))
1199 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1200 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1201 expected_align
, expected_size
,
1202 min_size
, max_size
, probable_max_size
))
1204 else if (may_use_call
1205 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1206 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1208 /* Since x and y are passed to a libcall, mark the corresponding
1209 tree EXPR as addressable. */
1210 tree y_expr
= MEM_EXPR (y
);
1211 tree x_expr
= MEM_EXPR (x
);
1213 mark_addressable (y_expr
);
1215 mark_addressable (x_expr
);
1216 retval
= emit_block_move_via_libcall (x
, y
, size
,
1217 method
== BLOCK_OP_TAILCALL
);
1221 emit_block_move_via_loop (x
, y
, size
, align
);
1223 if (method
== BLOCK_OP_CALL_PARM
)
1230 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1232 unsigned HOST_WIDE_INT max
, min
= 0;
1233 if (GET_CODE (size
) == CONST_INT
)
1234 min
= max
= UINTVAL (size
);
1236 max
= GET_MODE_MASK (GET_MODE (size
));
1237 return emit_block_move_hints (x
, y
, size
, method
, 0, -1,
1241 /* A subroutine of emit_block_move. Returns true if calling the
1242 block move libcall will not clobber any parameters which may have
1243 already been placed on the stack. */
1246 block_move_libcall_safe_for_call_parm (void)
1248 #if defined (REG_PARM_STACK_SPACE)
1252 /* If arguments are pushed on the stack, then they're safe. */
1256 /* If registers go on the stack anyway, any argument is sure to clobber
1257 an outgoing argument. */
1258 #if defined (REG_PARM_STACK_SPACE)
1259 fn
= emit_block_move_libcall_fn (false);
1260 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1261 depend on its argument. */
1263 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1264 && REG_PARM_STACK_SPACE (fn
) != 0)
1268 /* If any argument goes in memory, then it might clobber an outgoing
1271 CUMULATIVE_ARGS args_so_far_v
;
1272 cumulative_args_t args_so_far
;
1275 fn
= emit_block_move_libcall_fn (false);
1276 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1277 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1279 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1280 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1282 enum machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1283 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1285 if (!tmp
|| !REG_P (tmp
))
1287 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1289 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1296 /* A subroutine of emit_block_move. Expand a movmem pattern;
1297 return true if successful. */
1300 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1301 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1302 unsigned HOST_WIDE_INT min_size
,
1303 unsigned HOST_WIDE_INT max_size
,
1304 unsigned HOST_WIDE_INT probable_max_size
)
1306 int save_volatile_ok
= volatile_ok
;
1307 enum machine_mode mode
;
1309 if (expected_align
< align
)
1310 expected_align
= align
;
1311 if (expected_size
!= -1)
1313 if ((unsigned HOST_WIDE_INT
)expected_size
> probable_max_size
)
1314 expected_size
= probable_max_size
;
1315 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
1316 expected_size
= min_size
;
1319 /* Since this is a move insn, we don't care about volatility. */
1322 /* Try the most limited insn first, because there's no point
1323 including more than one in the machine description unless
1324 the more limited one has some advantage. */
1326 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1327 mode
= GET_MODE_WIDER_MODE (mode
))
1329 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1331 if (code
!= CODE_FOR_nothing
1332 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1333 here because if SIZE is less than the mode mask, as it is
1334 returned by the macro, it will definitely be less than the
1335 actual mode mask. Since SIZE is within the Pmode address
1336 space, we limit MODE to Pmode. */
1337 && ((CONST_INT_P (size
)
1338 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1339 <= (GET_MODE_MASK (mode
) >> 1)))
1340 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
1341 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
1343 struct expand_operand ops
[9];
1346 /* ??? When called via emit_block_move_for_call, it'd be
1347 nice if there were some way to inform the backend, so
1348 that it doesn't fail the expansion because it thinks
1349 emitting the libcall would be more efficient. */
1350 nops
= insn_data
[(int) code
].n_generator_args
;
1351 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
1353 create_fixed_operand (&ops
[0], x
);
1354 create_fixed_operand (&ops
[1], y
);
1355 /* The check above guarantees that this size conversion is valid. */
1356 create_convert_operand_to (&ops
[2], size
, mode
, true);
1357 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1360 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1361 create_integer_operand (&ops
[5], expected_size
);
1365 create_integer_operand (&ops
[6], min_size
);
1366 /* If we can not represent the maximal size,
1367 make parameter NULL. */
1368 if ((HOST_WIDE_INT
) max_size
!= -1)
1369 create_integer_operand (&ops
[7], max_size
);
1371 create_fixed_operand (&ops
[7], NULL
);
1375 /* If we can not represent the maximal size,
1376 make parameter NULL. */
1377 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
1378 create_integer_operand (&ops
[8], probable_max_size
);
1380 create_fixed_operand (&ops
[8], NULL
);
1382 if (maybe_expand_insn (code
, nops
, ops
))
1384 volatile_ok
= save_volatile_ok
;
1390 volatile_ok
= save_volatile_ok
;
1394 /* A subroutine of emit_block_move. Expand a call to memcpy.
1395 Return the return value from memcpy, 0 otherwise. */
1398 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1400 rtx dst_addr
, src_addr
;
1401 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1402 enum machine_mode size_mode
;
1405 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1406 pseudos. We can then place those new pseudos into a VAR_DECL and
1409 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1410 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1412 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1413 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1415 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1416 src_tree
= make_tree (ptr_type_node
, src_addr
);
1418 size_mode
= TYPE_MODE (sizetype
);
1420 size
= convert_to_mode (size_mode
, size
, 1);
1421 size
= copy_to_mode_reg (size_mode
, size
);
1423 /* It is incorrect to use the libcall calling conventions to call
1424 memcpy in this context. This could be a user call to memcpy and
1425 the user may wish to examine the return value from memcpy. For
1426 targets where libcalls and normal calls have different conventions
1427 for returning pointers, we could end up generating incorrect code. */
1429 size_tree
= make_tree (sizetype
, size
);
1431 fn
= emit_block_move_libcall_fn (true);
1432 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1433 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1435 retval
= expand_normal (call_expr
);
1440 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1441 for the function we use for block copies. */
1443 static GTY(()) tree block_move_fn
;
1446 init_block_move_fn (const char *asmspec
)
1450 tree args
, fn
, attrs
, attr_args
;
1452 fn
= get_identifier ("memcpy");
1453 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1454 const_ptr_type_node
, sizetype
,
1457 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1458 DECL_EXTERNAL (fn
) = 1;
1459 TREE_PUBLIC (fn
) = 1;
1460 DECL_ARTIFICIAL (fn
) = 1;
1461 TREE_NOTHROW (fn
) = 1;
1462 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1463 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1465 attr_args
= build_tree_list (NULL_TREE
, build_string (1, "1"));
1466 attrs
= tree_cons (get_identifier ("fn spec"), attr_args
, NULL
);
1468 decl_attributes (&fn
, attrs
, ATTR_FLAG_BUILT_IN
);
1474 set_user_assembler_name (block_move_fn
, asmspec
);
1478 emit_block_move_libcall_fn (int for_call
)
1480 static bool emitted_extern
;
1483 init_block_move_fn (NULL
);
1485 if (for_call
&& !emitted_extern
)
1487 emitted_extern
= true;
1488 make_decl_rtl (block_move_fn
);
1491 return block_move_fn
;
1494 /* A subroutine of emit_block_move. Copy the data via an explicit
1495 loop. This is used only when libcalls are forbidden. */
1496 /* ??? It'd be nice to copy in hunks larger than QImode. */
1499 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1500 unsigned int align ATTRIBUTE_UNUSED
)
1502 rtx cmp_label
, top_label
, iter
, x_addr
, y_addr
, tmp
;
1503 enum machine_mode x_addr_mode
= get_address_mode (x
);
1504 enum machine_mode y_addr_mode
= get_address_mode (y
);
1505 enum machine_mode iter_mode
;
1507 iter_mode
= GET_MODE (size
);
1508 if (iter_mode
== VOIDmode
)
1509 iter_mode
= word_mode
;
1511 top_label
= gen_label_rtx ();
1512 cmp_label
= gen_label_rtx ();
1513 iter
= gen_reg_rtx (iter_mode
);
1515 emit_move_insn (iter
, const0_rtx
);
1517 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1518 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1519 do_pending_stack_adjust ();
1521 emit_jump (cmp_label
);
1522 emit_label (top_label
);
1524 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1525 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1527 if (x_addr_mode
!= y_addr_mode
)
1528 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1529 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1531 x
= change_address (x
, QImode
, x_addr
);
1532 y
= change_address (y
, QImode
, y_addr
);
1534 emit_move_insn (x
, y
);
1536 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1537 true, OPTAB_LIB_WIDEN
);
1539 emit_move_insn (iter
, tmp
);
1541 emit_label (cmp_label
);
1543 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1544 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1547 /* Copy all or part of a value X into registers starting at REGNO.
1548 The number of registers to be filled is NREGS. */
1551 move_block_to_reg (int regno
, rtx x
, int nregs
, enum machine_mode mode
)
1554 #ifdef HAVE_load_multiple
1562 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1563 x
= validize_mem (force_const_mem (mode
, x
));
1565 /* See if the machine can do this with a load multiple insn. */
1566 #ifdef HAVE_load_multiple
1567 if (HAVE_load_multiple
)
1569 last
= get_last_insn ();
1570 pat
= gen_load_multiple (gen_rtx_REG (word_mode
, regno
), x
,
1578 delete_insns_since (last
);
1582 for (i
= 0; i
< nregs
; i
++)
1583 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1584 operand_subword_force (x
, i
, mode
));
1587 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1588 The number of registers to be filled is NREGS. */
1591 move_block_from_reg (int regno
, rtx x
, int nregs
)
1598 /* See if the machine can do this with a store multiple insn. */
1599 #ifdef HAVE_store_multiple
1600 if (HAVE_store_multiple
)
1602 rtx last
= get_last_insn ();
1603 rtx pat
= gen_store_multiple (x
, gen_rtx_REG (word_mode
, regno
),
1611 delete_insns_since (last
);
1615 for (i
= 0; i
< nregs
; i
++)
1617 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1621 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1625 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1626 ORIG, where ORIG is a non-consecutive group of registers represented by
1627 a PARALLEL. The clone is identical to the original except in that the
1628 original set of registers is replaced by a new set of pseudo registers.
1629 The new set has the same modes as the original set. */
1632 gen_group_rtx (rtx orig
)
1637 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1639 length
= XVECLEN (orig
, 0);
1640 tmps
= XALLOCAVEC (rtx
, length
);
1642 /* Skip a NULL entry in first slot. */
1643 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1648 for (; i
< length
; i
++)
1650 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1651 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1653 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1656 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1659 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1660 except that values are placed in TMPS[i], and must later be moved
1661 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1664 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1668 enum machine_mode m
= GET_MODE (orig_src
);
1670 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1673 && !SCALAR_INT_MODE_P (m
)
1674 && !MEM_P (orig_src
)
1675 && GET_CODE (orig_src
) != CONCAT
)
1677 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1678 if (imode
== BLKmode
)
1679 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
1681 src
= gen_reg_rtx (imode
);
1682 if (imode
!= BLKmode
)
1683 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1684 emit_move_insn (src
, orig_src
);
1685 /* ...and back again. */
1686 if (imode
!= BLKmode
)
1687 src
= gen_lowpart (imode
, src
);
1688 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1692 /* Check for a NULL entry, used to indicate that the parameter goes
1693 both on the stack and in registers. */
1694 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1699 /* Process the pieces. */
1700 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1702 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1703 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1704 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1707 /* Handle trailing fragments that run over the size of the struct. */
1708 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1710 /* Arrange to shift the fragment to where it belongs.
1711 extract_bit_field loads to the lsb of the reg. */
1713 #ifdef BLOCK_REG_PADDING
1714 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1715 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1720 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1721 bytelen
= ssize
- bytepos
;
1722 gcc_assert (bytelen
> 0);
1725 /* If we won't be loading directly from memory, protect the real source
1726 from strange tricks we might play; but make sure that the source can
1727 be loaded directly into the destination. */
1729 if (!MEM_P (orig_src
)
1730 && (!CONSTANT_P (orig_src
)
1731 || (GET_MODE (orig_src
) != mode
1732 && GET_MODE (orig_src
) != VOIDmode
)))
1734 if (GET_MODE (orig_src
) == VOIDmode
)
1735 src
= gen_reg_rtx (mode
);
1737 src
= gen_reg_rtx (GET_MODE (orig_src
));
1739 emit_move_insn (src
, orig_src
);
1742 /* Optimize the access just a bit. */
1744 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1745 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1746 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1747 && bytelen
== GET_MODE_SIZE (mode
))
1749 tmps
[i
] = gen_reg_rtx (mode
);
1750 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1752 else if (COMPLEX_MODE_P (mode
)
1753 && GET_MODE (src
) == mode
1754 && bytelen
== GET_MODE_SIZE (mode
))
1755 /* Let emit_move_complex do the bulk of the work. */
1757 else if (GET_CODE (src
) == CONCAT
)
1759 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1760 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1762 if ((bytepos
== 0 && bytelen
== slen0
)
1763 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1765 /* The following assumes that the concatenated objects all
1766 have the same size. In this case, a simple calculation
1767 can be used to determine the object and the bit field
1769 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1770 if (! CONSTANT_P (tmps
[i
])
1771 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1772 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1773 (bytepos
% slen0
) * BITS_PER_UNIT
,
1774 1, NULL_RTX
, mode
, mode
);
1780 gcc_assert (!bytepos
);
1781 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1782 emit_move_insn (mem
, src
);
1783 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1784 0, 1, NULL_RTX
, mode
, mode
);
1787 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1788 SIMD register, which is currently broken. While we get GCC
1789 to emit proper RTL for these cases, let's dump to memory. */
1790 else if (VECTOR_MODE_P (GET_MODE (dst
))
1793 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1796 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1797 emit_move_insn (mem
, src
);
1798 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1800 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1801 && XVECLEN (dst
, 0) > 1)
1802 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE (dst
), bytepos
);
1803 else if (CONSTANT_P (src
))
1805 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1813 gcc_assert (2 * len
== ssize
);
1814 split_double (src
, &first
, &second
);
1821 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1824 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1825 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
1829 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1834 /* Emit code to move a block SRC of type TYPE to a block DST,
1835 where DST is non-consecutive registers represented by a PARALLEL.
1836 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1840 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1845 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1846 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1848 /* Copy the extracted pieces into the proper (probable) hard regs. */
1849 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1851 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1854 emit_move_insn (d
, tmps
[i
]);
1858 /* Similar, but load SRC into new pseudos in a format that looks like
1859 PARALLEL. This can later be fed to emit_group_move to get things
1860 in the right place. */
1863 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1868 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1869 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1871 /* Convert the vector to look just like the original PARALLEL, except
1872 with the computed values. */
1873 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1875 rtx e
= XVECEXP (parallel
, 0, i
);
1876 rtx d
= XEXP (e
, 0);
1880 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1881 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1883 RTVEC_ELT (vec
, i
) = e
;
1886 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1889 /* Emit code to move a block SRC to block DST, where SRC and DST are
1890 non-consecutive groups of registers, each represented by a PARALLEL. */
1893 emit_group_move (rtx dst
, rtx src
)
1897 gcc_assert (GET_CODE (src
) == PARALLEL
1898 && GET_CODE (dst
) == PARALLEL
1899 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1901 /* Skip first entry if NULL. */
1902 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1903 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1904 XEXP (XVECEXP (src
, 0, i
), 0));
1907 /* Move a group of registers represented by a PARALLEL into pseudos. */
1910 emit_group_move_into_temps (rtx src
)
1912 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1915 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1917 rtx e
= XVECEXP (src
, 0, i
);
1918 rtx d
= XEXP (e
, 0);
1921 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1922 RTVEC_ELT (vec
, i
) = e
;
1925 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1928 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1929 where SRC is non-consecutive registers represented by a PARALLEL.
1930 SSIZE represents the total size of block ORIG_DST, or -1 if not
1934 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1937 int start
, finish
, i
;
1938 enum machine_mode m
= GET_MODE (orig_dst
);
1940 gcc_assert (GET_CODE (src
) == PARALLEL
);
1942 if (!SCALAR_INT_MODE_P (m
)
1943 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1945 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1946 if (imode
== BLKmode
)
1947 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
1949 dst
= gen_reg_rtx (imode
);
1950 emit_group_store (dst
, src
, type
, ssize
);
1951 if (imode
!= BLKmode
)
1952 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1953 emit_move_insn (orig_dst
, dst
);
1957 /* Check for a NULL entry, used to indicate that the parameter goes
1958 both on the stack and in registers. */
1959 if (XEXP (XVECEXP (src
, 0, 0), 0))
1963 finish
= XVECLEN (src
, 0);
1965 tmps
= XALLOCAVEC (rtx
, finish
);
1967 /* Copy the (probable) hard regs into pseudos. */
1968 for (i
= start
; i
< finish
; i
++)
1970 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1971 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1973 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1974 emit_move_insn (tmps
[i
], reg
);
1980 /* If we won't be storing directly into memory, protect the real destination
1981 from strange tricks we might play. */
1983 if (GET_CODE (dst
) == PARALLEL
)
1987 /* We can get a PARALLEL dst if there is a conditional expression in
1988 a return statement. In that case, the dst and src are the same,
1989 so no action is necessary. */
1990 if (rtx_equal_p (dst
, src
))
1993 /* It is unclear if we can ever reach here, but we may as well handle
1994 it. Allocate a temporary, and split this into a store/load to/from
1997 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
1998 emit_group_store (temp
, src
, type
, ssize
);
1999 emit_group_load (dst
, temp
, type
, ssize
);
2002 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
2004 enum machine_mode outer
= GET_MODE (dst
);
2005 enum machine_mode inner
;
2006 HOST_WIDE_INT bytepos
;
2010 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
2011 dst
= gen_reg_rtx (outer
);
2013 /* Make life a bit easier for combine. */
2014 /* If the first element of the vector is the low part
2015 of the destination mode, use a paradoxical subreg to
2016 initialize the destination. */
2019 inner
= GET_MODE (tmps
[start
]);
2020 bytepos
= subreg_lowpart_offset (inner
, outer
);
2021 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
2023 temp
= simplify_gen_subreg (outer
, tmps
[start
],
2027 emit_move_insn (dst
, temp
);
2034 /* If the first element wasn't the low part, try the last. */
2036 && start
< finish
- 1)
2038 inner
= GET_MODE (tmps
[finish
- 1]);
2039 bytepos
= subreg_lowpart_offset (inner
, outer
);
2040 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
2042 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
2046 emit_move_insn (dst
, temp
);
2053 /* Otherwise, simply initialize the result to zero. */
2055 emit_move_insn (dst
, CONST0_RTX (outer
));
2058 /* Process the pieces. */
2059 for (i
= start
; i
< finish
; i
++)
2061 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
2062 enum machine_mode mode
= GET_MODE (tmps
[i
]);
2063 unsigned int bytelen
= GET_MODE_SIZE (mode
);
2064 unsigned int adj_bytelen
;
2067 /* Handle trailing fragments that run over the size of the struct. */
2068 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2069 adj_bytelen
= ssize
- bytepos
;
2071 adj_bytelen
= bytelen
;
2073 if (GET_CODE (dst
) == CONCAT
)
2075 if (bytepos
+ adj_bytelen
2076 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2077 dest
= XEXP (dst
, 0);
2078 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2080 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2081 dest
= XEXP (dst
, 1);
2085 enum machine_mode dest_mode
= GET_MODE (dest
);
2086 enum machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2088 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2090 if (GET_MODE_ALIGNMENT (dest_mode
)
2091 >= GET_MODE_ALIGNMENT (tmp_mode
))
2093 dest
= assign_stack_temp (dest_mode
,
2094 GET_MODE_SIZE (dest_mode
));
2095 emit_move_insn (adjust_address (dest
,
2103 dest
= assign_stack_temp (tmp_mode
,
2104 GET_MODE_SIZE (tmp_mode
));
2105 emit_move_insn (dest
, tmps
[i
]);
2106 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2112 /* Handle trailing fragments that run over the size of the struct. */
2113 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2115 /* store_bit_field always takes its value from the lsb.
2116 Move the fragment to the lsb if it's not already there. */
2118 #ifdef BLOCK_REG_PADDING
2119 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2120 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2126 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2127 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2131 /* Make sure not to write past the end of the struct. */
2132 store_bit_field (dest
,
2133 adj_bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2134 bytepos
* BITS_PER_UNIT
, ssize
* BITS_PER_UNIT
,
2138 /* Optimize the access just a bit. */
2139 else if (MEM_P (dest
)
2140 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2141 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2142 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2143 && bytelen
== GET_MODE_SIZE (mode
))
2144 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2147 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2148 0, 0, mode
, tmps
[i
]);
2151 /* Copy from the pseudo into the (probable) hard reg. */
2152 if (orig_dst
!= dst
)
2153 emit_move_insn (orig_dst
, dst
);
2156 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2157 of the value stored in X. */
2160 maybe_emit_group_store (rtx x
, tree type
)
2162 enum machine_mode mode
= TYPE_MODE (type
);
2163 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
2164 if (GET_CODE (x
) == PARALLEL
)
2166 rtx result
= gen_reg_rtx (mode
);
2167 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
2173 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2175 This is used on targets that return BLKmode values in registers. */
2178 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2180 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2181 rtx src
= NULL
, dst
= NULL
;
2182 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2183 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2184 enum machine_mode mode
= GET_MODE (srcreg
);
2185 enum machine_mode tmode
= GET_MODE (target
);
2186 enum machine_mode copy_mode
;
2188 /* BLKmode registers created in the back-end shouldn't have survived. */
2189 gcc_assert (mode
!= BLKmode
);
2191 /* If the structure doesn't take up a whole number of words, see whether
2192 SRCREG is padded on the left or on the right. If it's on the left,
2193 set PADDING_CORRECTION to the number of bits to skip.
2195 In most ABIs, the structure will be returned at the least end of
2196 the register, which translates to right padding on little-endian
2197 targets and left padding on big-endian targets. The opposite
2198 holds if the structure is returned at the most significant
2199 end of the register. */
2200 if (bytes
% UNITS_PER_WORD
!= 0
2201 && (targetm
.calls
.return_in_msb (type
)
2203 : BYTES_BIG_ENDIAN
))
2205 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2207 /* We can use a single move if we have an exact mode for the size. */
2208 else if (MEM_P (target
)
2209 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2210 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2211 && bytes
== GET_MODE_SIZE (mode
))
2213 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2217 /* And if we additionally have the same mode for a register. */
2218 else if (REG_P (target
)
2219 && GET_MODE (target
) == mode
2220 && bytes
== GET_MODE_SIZE (mode
))
2222 emit_move_insn (target
, srcreg
);
2226 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2227 into a new pseudo which is a full word. */
2228 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2230 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2234 /* Copy the structure BITSIZE bits at a time. If the target lives in
2235 memory, take care of not reading/writing past its end by selecting
2236 a copy mode suited to BITSIZE. This should always be possible given
2239 If the target lives in register, make sure not to select a copy mode
2240 larger than the mode of the register.
2242 We could probably emit more efficient code for machines which do not use
2243 strict alignment, but it doesn't seem worth the effort at the current
2246 copy_mode
= word_mode
;
2249 enum machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2250 if (mem_mode
!= BLKmode
)
2251 copy_mode
= mem_mode
;
2253 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2256 for (bitpos
= 0, xbitpos
= padding_correction
;
2257 bitpos
< bytes
* BITS_PER_UNIT
;
2258 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2260 /* We need a new source operand each time xbitpos is on a
2261 word boundary and when xbitpos == padding_correction
2262 (the first time through). */
2263 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2264 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2266 /* We need a new destination operand each time bitpos is on
2268 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2270 else if (bitpos
% BITS_PER_WORD
== 0)
2271 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2273 /* Use xbitpos for the source extraction (right justified) and
2274 bitpos for the destination store (left justified). */
2275 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2276 extract_bit_field (src
, bitsize
,
2277 xbitpos
% BITS_PER_WORD
, 1,
2278 NULL_RTX
, copy_mode
, copy_mode
));
2282 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2283 register if it contains any data, otherwise return null.
2285 This is used on targets that return BLKmode values in registers. */
2288 copy_blkmode_to_reg (enum machine_mode mode
, tree src
)
2291 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2292 unsigned int bitsize
;
2293 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2294 enum machine_mode dst_mode
;
2296 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2298 x
= expand_normal (src
);
2300 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2304 /* If the structure doesn't take up a whole number of words, see
2305 whether the register value should be padded on the left or on
2306 the right. Set PADDING_CORRECTION to the number of padding
2307 bits needed on the left side.
2309 In most ABIs, the structure will be returned at the least end of
2310 the register, which translates to right padding on little-endian
2311 targets and left padding on big-endian targets. The opposite
2312 holds if the structure is returned at the most significant
2313 end of the register. */
2314 if (bytes
% UNITS_PER_WORD
!= 0
2315 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2317 : BYTES_BIG_ENDIAN
))
2318 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2321 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2322 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2323 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2325 /* Copy the structure BITSIZE bits at a time. */
2326 for (bitpos
= 0, xbitpos
= padding_correction
;
2327 bitpos
< bytes
* BITS_PER_UNIT
;
2328 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2330 /* We need a new destination pseudo each time xbitpos is
2331 on a word boundary and when xbitpos == padding_correction
2332 (the first time through). */
2333 if (xbitpos
% BITS_PER_WORD
== 0
2334 || xbitpos
== padding_correction
)
2336 /* Generate an appropriate register. */
2337 dst_word
= gen_reg_rtx (word_mode
);
2338 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2340 /* Clear the destination before we move anything into it. */
2341 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2344 /* We need a new source operand each time bitpos is on a word
2346 if (bitpos
% BITS_PER_WORD
== 0)
2347 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2349 /* Use bitpos for the source extraction (left justified) and
2350 xbitpos for the destination store (right justified). */
2351 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2353 extract_bit_field (src_word
, bitsize
,
2354 bitpos
% BITS_PER_WORD
, 1,
2355 NULL_RTX
, word_mode
, word_mode
));
2358 if (mode
== BLKmode
)
2360 /* Find the smallest integer mode large enough to hold the
2361 entire structure. */
2362 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2364 mode
= GET_MODE_WIDER_MODE (mode
))
2365 /* Have we found a large enough mode? */
2366 if (GET_MODE_SIZE (mode
) >= bytes
)
2369 /* A suitable mode should have been found. */
2370 gcc_assert (mode
!= VOIDmode
);
2373 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2374 dst_mode
= word_mode
;
2377 dst
= gen_reg_rtx (dst_mode
);
2379 for (i
= 0; i
< n_regs
; i
++)
2380 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2382 if (mode
!= dst_mode
)
2383 dst
= gen_lowpart (mode
, dst
);
2388 /* Add a USE expression for REG to the (possibly empty) list pointed
2389 to by CALL_FUSAGE. REG must denote a hard register. */
2392 use_reg_mode (rtx
*call_fusage
, rtx reg
, enum machine_mode mode
)
2394 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2397 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2400 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2401 starting at REGNO. All of these registers must be hard registers. */
2404 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2408 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2410 for (i
= 0; i
< nregs
; i
++)
2411 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2414 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2415 PARALLEL REGS. This is for calls that pass values in multiple
2416 non-contiguous locations. The Irix 6 ABI has examples of this. */
2419 use_group_regs (rtx
*call_fusage
, rtx regs
)
2423 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2425 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2427 /* A NULL entry means the parameter goes both on the stack and in
2428 registers. This can also be a MEM for targets that pass values
2429 partially on the stack and partially in registers. */
2430 if (reg
!= 0 && REG_P (reg
))
2431 use_reg (call_fusage
, reg
);
2435 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2436 assigment and the code of the expresion on the RHS is CODE. Return
2440 get_def_for_expr (tree name
, enum tree_code code
)
2444 if (TREE_CODE (name
) != SSA_NAME
)
2447 def_stmt
= get_gimple_for_ssa_name (name
);
2449 || gimple_assign_rhs_code (def_stmt
) != code
)
2455 #ifdef HAVE_conditional_move
2456 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2457 assigment and the class of the expresion on the RHS is CLASS. Return
2461 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2465 if (TREE_CODE (name
) != SSA_NAME
)
2468 def_stmt
= get_gimple_for_ssa_name (name
);
2470 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2478 /* Determine whether the LEN bytes generated by CONSTFUN can be
2479 stored to memory using several move instructions. CONSTFUNDATA is
2480 a pointer which will be passed as argument in every CONSTFUN call.
2481 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2482 a memset operation and false if it's a copy of a constant string.
2483 Return nonzero if a call to store_by_pieces should succeed. */
2486 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2487 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2488 void *constfundata
, unsigned int align
, bool memsetp
)
2490 unsigned HOST_WIDE_INT l
;
2491 unsigned int max_size
;
2492 HOST_WIDE_INT offset
= 0;
2493 enum machine_mode mode
;
2494 enum insn_code icode
;
2496 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2497 rtx cst ATTRIBUTE_UNUSED
;
2503 ? SET_BY_PIECES_P (len
, align
)
2504 : STORE_BY_PIECES_P (len
, align
)))
2507 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2509 /* We would first store what we can in the largest integer mode, then go to
2510 successively smaller modes. */
2513 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2517 max_size
= STORE_MAX_PIECES
+ 1;
2518 while (max_size
> 1 && l
> 0)
2520 mode
= widest_int_mode_for_size (max_size
);
2522 if (mode
== VOIDmode
)
2525 icode
= optab_handler (mov_optab
, mode
);
2526 if (icode
!= CODE_FOR_nothing
2527 && align
>= GET_MODE_ALIGNMENT (mode
))
2529 unsigned int size
= GET_MODE_SIZE (mode
);
2536 cst
= (*constfun
) (constfundata
, offset
, mode
);
2537 if (!targetm
.legitimate_constant_p (mode
, cst
))
2547 max_size
= GET_MODE_SIZE (mode
);
2550 /* The code above should have handled everything. */
2557 /* Generate several move instructions to store LEN bytes generated by
2558 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2559 pointer which will be passed as argument in every CONSTFUN call.
2560 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2561 a memset operation and false if it's a copy of a constant string.
2562 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2563 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2567 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2568 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2569 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2571 enum machine_mode to_addr_mode
= get_address_mode (to
);
2572 struct store_by_pieces_d data
;
2576 gcc_assert (endp
!= 2);
2581 ? SET_BY_PIECES_P (len
, align
)
2582 : STORE_BY_PIECES_P (len
, align
));
2583 data
.constfun
= constfun
;
2584 data
.constfundata
= constfundata
;
2587 store_by_pieces_1 (&data
, align
);
2592 gcc_assert (!data
.reverse
);
2597 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2598 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2600 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2601 plus_constant (to_addr_mode
,
2605 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2612 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2620 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2621 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2624 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2626 struct store_by_pieces_d data
;
2631 data
.constfun
= clear_by_pieces_1
;
2632 data
.constfundata
= NULL
;
2635 store_by_pieces_1 (&data
, align
);
2638 /* Callback routine for clear_by_pieces.
2639 Return const0_rtx unconditionally. */
2642 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2643 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2644 enum machine_mode mode ATTRIBUTE_UNUSED
)
2649 /* Subroutine of clear_by_pieces and store_by_pieces.
2650 Generate several move instructions to store LEN bytes of block TO. (A MEM
2651 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2654 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2655 unsigned int align ATTRIBUTE_UNUSED
)
2657 enum machine_mode to_addr_mode
= get_address_mode (data
->to
);
2658 rtx to_addr
= XEXP (data
->to
, 0);
2659 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2660 enum insn_code icode
;
2663 data
->to_addr
= to_addr
;
2665 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2666 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2668 data
->explicit_inc_to
= 0;
2670 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2672 data
->offset
= data
->len
;
2674 /* If storing requires more than two move insns,
2675 copy addresses to registers (to make displacements shorter)
2676 and use post-increment if available. */
2677 if (!data
->autinc_to
2678 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2680 /* Determine the main mode we'll be using.
2681 MODE might not be used depending on the definitions of the
2682 USE_* macros below. */
2683 enum machine_mode mode ATTRIBUTE_UNUSED
2684 = widest_int_mode_for_size (max_size
);
2686 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2688 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2689 plus_constant (to_addr_mode
,
2692 data
->autinc_to
= 1;
2693 data
->explicit_inc_to
= -1;
2696 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2697 && ! data
->autinc_to
)
2699 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2700 data
->autinc_to
= 1;
2701 data
->explicit_inc_to
= 1;
2704 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2705 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2708 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2710 /* First store what we can in the largest integer mode, then go to
2711 successively smaller modes. */
2713 while (max_size
> 1 && data
->len
> 0)
2715 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
2717 if (mode
== VOIDmode
)
2720 icode
= optab_handler (mov_optab
, mode
);
2721 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2722 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2724 max_size
= GET_MODE_SIZE (mode
);
2727 /* The code above should have handled everything. */
2728 gcc_assert (!data
->len
);
2731 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2732 with move instructions for mode MODE. GENFUN is the gen_... function
2733 to make a move insn for that mode. DATA has all the other info. */
2736 store_by_pieces_2 (insn_gen_fn genfun
, machine_mode mode
,
2737 struct store_by_pieces_d
*data
)
2739 unsigned int size
= GET_MODE_SIZE (mode
);
2742 while (data
->len
>= size
)
2745 data
->offset
-= size
;
2747 if (data
->autinc_to
)
2748 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2751 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2753 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2754 emit_insn (gen_add2_insn (data
->to_addr
,
2755 gen_int_mode (-(HOST_WIDE_INT
) size
,
2756 GET_MODE (data
->to_addr
))));
2758 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2759 emit_insn ((*genfun
) (to1
, cst
));
2761 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2762 emit_insn (gen_add2_insn (data
->to_addr
,
2764 GET_MODE (data
->to_addr
))));
2766 if (! data
->reverse
)
2767 data
->offset
+= size
;
2773 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2774 its length in bytes. */
2777 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2778 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2779 unsigned HOST_WIDE_INT min_size
,
2780 unsigned HOST_WIDE_INT max_size
,
2781 unsigned HOST_WIDE_INT probable_max_size
)
2783 enum machine_mode mode
= GET_MODE (object
);
2786 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2788 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2789 just move a zero. Otherwise, do this a piece at a time. */
2791 && CONST_INT_P (size
)
2792 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2794 rtx zero
= CONST0_RTX (mode
);
2797 emit_move_insn (object
, zero
);
2801 if (COMPLEX_MODE_P (mode
))
2803 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2806 write_complex_part (object
, zero
, 0);
2807 write_complex_part (object
, zero
, 1);
2813 if (size
== const0_rtx
)
2816 align
= MEM_ALIGN (object
);
2818 if (CONST_INT_P (size
)
2819 && CLEAR_BY_PIECES_P (INTVAL (size
), align
))
2820 clear_by_pieces (object
, INTVAL (size
), align
);
2821 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2822 expected_align
, expected_size
,
2823 min_size
, max_size
, probable_max_size
))
2825 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2826 return set_storage_via_libcall (object
, size
, const0_rtx
,
2827 method
== BLOCK_OP_TAILCALL
);
2835 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2837 unsigned HOST_WIDE_INT max
, min
= 0;
2838 if (GET_CODE (size
) == CONST_INT
)
2839 min
= max
= UINTVAL (size
);
2841 max
= GET_MODE_MASK (GET_MODE (size
));
2842 return clear_storage_hints (object
, size
, method
, 0, -1, min
, max
, max
);
2846 /* A subroutine of clear_storage. Expand a call to memset.
2847 Return the return value of memset, 0 otherwise. */
2850 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2852 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2853 enum machine_mode size_mode
;
2856 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2857 place those into new pseudos into a VAR_DECL and use them later. */
2859 object
= copy_addr_to_reg (XEXP (object
, 0));
2861 size_mode
= TYPE_MODE (sizetype
);
2862 size
= convert_to_mode (size_mode
, size
, 1);
2863 size
= copy_to_mode_reg (size_mode
, size
);
2865 /* It is incorrect to use the libcall calling conventions to call
2866 memset in this context. This could be a user call to memset and
2867 the user may wish to examine the return value from memset. For
2868 targets where libcalls and normal calls have different conventions
2869 for returning pointers, we could end up generating incorrect code. */
2871 object_tree
= make_tree (ptr_type_node
, object
);
2872 if (!CONST_INT_P (val
))
2873 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2874 size_tree
= make_tree (sizetype
, size
);
2875 val_tree
= make_tree (integer_type_node
, val
);
2877 fn
= clear_storage_libcall_fn (true);
2878 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2879 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2881 retval
= expand_normal (call_expr
);
2886 /* A subroutine of set_storage_via_libcall. Create the tree node
2887 for the function we use for block clears. */
2889 tree block_clear_fn
;
2892 init_block_clear_fn (const char *asmspec
)
2894 if (!block_clear_fn
)
2898 fn
= get_identifier ("memset");
2899 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2900 integer_type_node
, sizetype
,
2903 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2904 DECL_EXTERNAL (fn
) = 1;
2905 TREE_PUBLIC (fn
) = 1;
2906 DECL_ARTIFICIAL (fn
) = 1;
2907 TREE_NOTHROW (fn
) = 1;
2908 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2909 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2911 block_clear_fn
= fn
;
2915 set_user_assembler_name (block_clear_fn
, asmspec
);
2919 clear_storage_libcall_fn (int for_call
)
2921 static bool emitted_extern
;
2923 if (!block_clear_fn
)
2924 init_block_clear_fn (NULL
);
2926 if (for_call
&& !emitted_extern
)
2928 emitted_extern
= true;
2929 make_decl_rtl (block_clear_fn
);
2932 return block_clear_fn
;
2935 /* Expand a setmem pattern; return true if successful. */
2938 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2939 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2940 unsigned HOST_WIDE_INT min_size
,
2941 unsigned HOST_WIDE_INT max_size
,
2942 unsigned HOST_WIDE_INT probable_max_size
)
2944 /* Try the most limited insn first, because there's no point
2945 including more than one in the machine description unless
2946 the more limited one has some advantage. */
2948 enum machine_mode mode
;
2950 if (expected_align
< align
)
2951 expected_align
= align
;
2952 if (expected_size
!= -1)
2954 if ((unsigned HOST_WIDE_INT
)expected_size
> max_size
)
2955 expected_size
= max_size
;
2956 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
2957 expected_size
= min_size
;
2960 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2961 mode
= GET_MODE_WIDER_MODE (mode
))
2963 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2965 if (code
!= CODE_FOR_nothing
2966 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2967 here because if SIZE is less than the mode mask, as it is
2968 returned by the macro, it will definitely be less than the
2969 actual mode mask. Since SIZE is within the Pmode address
2970 space, we limit MODE to Pmode. */
2971 && ((CONST_INT_P (size
)
2972 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2973 <= (GET_MODE_MASK (mode
) >> 1)))
2974 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
2975 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
2977 struct expand_operand ops
[9];
2980 nops
= insn_data
[(int) code
].n_generator_args
;
2981 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
2983 create_fixed_operand (&ops
[0], object
);
2984 /* The check above guarantees that this size conversion is valid. */
2985 create_convert_operand_to (&ops
[1], size
, mode
, true);
2986 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2987 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2990 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2991 create_integer_operand (&ops
[5], expected_size
);
2995 create_integer_operand (&ops
[6], min_size
);
2996 /* If we can not represent the maximal size,
2997 make parameter NULL. */
2998 if ((HOST_WIDE_INT
) max_size
!= -1)
2999 create_integer_operand (&ops
[7], max_size
);
3001 create_fixed_operand (&ops
[7], NULL
);
3005 /* If we can not represent the maximal size,
3006 make parameter NULL. */
3007 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
3008 create_integer_operand (&ops
[8], probable_max_size
);
3010 create_fixed_operand (&ops
[8], NULL
);
3012 if (maybe_expand_insn (code
, nops
, ops
))
3021 /* Write to one of the components of the complex value CPLX. Write VAL to
3022 the real part if IMAG_P is false, and the imaginary part if its true. */
3025 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
3027 enum machine_mode cmode
;
3028 enum machine_mode imode
;
3031 if (GET_CODE (cplx
) == CONCAT
)
3033 emit_move_insn (XEXP (cplx
, imag_p
), val
);
3037 cmode
= GET_MODE (cplx
);
3038 imode
= GET_MODE_INNER (cmode
);
3039 ibitsize
= GET_MODE_BITSIZE (imode
);
3041 /* For MEMs simplify_gen_subreg may generate an invalid new address
3042 because, e.g., the original address is considered mode-dependent
3043 by the target, which restricts simplify_subreg from invoking
3044 adjust_address_nv. Instead of preparing fallback support for an
3045 invalid address, we call adjust_address_nv directly. */
3048 emit_move_insn (adjust_address_nv (cplx
, imode
,
3049 imag_p
? GET_MODE_SIZE (imode
) : 0),
3054 /* If the sub-object is at least word sized, then we know that subregging
3055 will work. This special case is important, since store_bit_field
3056 wants to operate on integer modes, and there's rarely an OImode to
3057 correspond to TCmode. */
3058 if (ibitsize
>= BITS_PER_WORD
3059 /* For hard regs we have exact predicates. Assume we can split
3060 the original object if it spans an even number of hard regs.
3061 This special case is important for SCmode on 64-bit platforms
3062 where the natural size of floating-point regs is 32-bit. */
3064 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3065 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3067 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
3068 imag_p
? GET_MODE_SIZE (imode
) : 0);
3071 emit_move_insn (part
, val
);
3075 /* simplify_gen_subreg may fail for sub-word MEMs. */
3076 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3079 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
3082 /* Extract one of the components of the complex value CPLX. Extract the
3083 real part if IMAG_P is false, and the imaginary part if it's true. */
3086 read_complex_part (rtx cplx
, bool imag_p
)
3088 enum machine_mode cmode
, imode
;
3091 if (GET_CODE (cplx
) == CONCAT
)
3092 return XEXP (cplx
, imag_p
);
3094 cmode
= GET_MODE (cplx
);
3095 imode
= GET_MODE_INNER (cmode
);
3096 ibitsize
= GET_MODE_BITSIZE (imode
);
3098 /* Special case reads from complex constants that got spilled to memory. */
3099 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
3101 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
3102 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
3104 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
3105 if (CONSTANT_CLASS_P (part
))
3106 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
3110 /* For MEMs simplify_gen_subreg may generate an invalid new address
3111 because, e.g., the original address is considered mode-dependent
3112 by the target, which restricts simplify_subreg from invoking
3113 adjust_address_nv. Instead of preparing fallback support for an
3114 invalid address, we call adjust_address_nv directly. */
3116 return adjust_address_nv (cplx
, imode
,
3117 imag_p
? GET_MODE_SIZE (imode
) : 0);
3119 /* If the sub-object is at least word sized, then we know that subregging
3120 will work. This special case is important, since extract_bit_field
3121 wants to operate on integer modes, and there's rarely an OImode to
3122 correspond to TCmode. */
3123 if (ibitsize
>= BITS_PER_WORD
3124 /* For hard regs we have exact predicates. Assume we can split
3125 the original object if it spans an even number of hard regs.
3126 This special case is important for SCmode on 64-bit platforms
3127 where the natural size of floating-point regs is 32-bit. */
3129 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3130 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3132 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3133 imag_p
? GET_MODE_SIZE (imode
) : 0);
3137 /* simplify_gen_subreg may fail for sub-word MEMs. */
3138 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3141 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3142 true, NULL_RTX
, imode
, imode
);
3145 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3146 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3147 represented in NEW_MODE. If FORCE is true, this will never happen, as
3148 we'll force-create a SUBREG if needed. */
3151 emit_move_change_mode (enum machine_mode new_mode
,
3152 enum machine_mode old_mode
, rtx x
, bool force
)
3156 if (push_operand (x
, GET_MODE (x
)))
3158 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3159 MEM_COPY_ATTRIBUTES (ret
, x
);
3163 /* We don't have to worry about changing the address since the
3164 size in bytes is supposed to be the same. */
3165 if (reload_in_progress
)
3167 /* Copy the MEM to change the mode and move any
3168 substitutions from the old MEM to the new one. */
3169 ret
= adjust_address_nv (x
, new_mode
, 0);
3170 copy_replacements (x
, ret
);
3173 ret
= adjust_address (x
, new_mode
, 0);
3177 /* Note that we do want simplify_subreg's behavior of validating
3178 that the new mode is ok for a hard register. If we were to use
3179 simplify_gen_subreg, we would create the subreg, but would
3180 probably run into the target not being able to implement it. */
3181 /* Except, of course, when FORCE is true, when this is exactly what
3182 we want. Which is needed for CCmodes on some targets. */
3184 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3186 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3192 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3193 an integer mode of the same size as MODE. Returns the instruction
3194 emitted, or NULL if such a move could not be generated. */
3197 emit_move_via_integer (enum machine_mode mode
, rtx x
, rtx y
, bool force
)
3199 enum machine_mode imode
;
3200 enum insn_code code
;
3202 /* There must exist a mode of the exact size we require. */
3203 imode
= int_mode_for_mode (mode
);
3204 if (imode
== BLKmode
)
3207 /* The target must support moves in this mode. */
3208 code
= optab_handler (mov_optab
, imode
);
3209 if (code
== CODE_FOR_nothing
)
3212 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3215 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3218 return emit_insn (GEN_FCN (code
) (x
, y
));
3221 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3222 Return an equivalent MEM that does not use an auto-increment. */
3225 emit_move_resolve_push (enum machine_mode mode
, rtx x
)
3227 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3228 HOST_WIDE_INT adjust
;
3231 adjust
= GET_MODE_SIZE (mode
);
3232 #ifdef PUSH_ROUNDING
3233 adjust
= PUSH_ROUNDING (adjust
);
3235 if (code
== PRE_DEC
|| code
== POST_DEC
)
3237 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3239 rtx expr
= XEXP (XEXP (x
, 0), 1);
3242 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3243 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3244 val
= INTVAL (XEXP (expr
, 1));
3245 if (GET_CODE (expr
) == MINUS
)
3247 gcc_assert (adjust
== val
|| adjust
== -val
);
3251 /* Do not use anti_adjust_stack, since we don't want to update
3252 stack_pointer_delta. */
3253 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3254 gen_int_mode (adjust
, Pmode
), stack_pointer_rtx
,
3255 0, OPTAB_LIB_WIDEN
);
3256 if (temp
!= stack_pointer_rtx
)
3257 emit_move_insn (stack_pointer_rtx
, temp
);
3264 temp
= stack_pointer_rtx
;
3269 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3275 return replace_equiv_address (x
, temp
);
3278 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3279 X is known to satisfy push_operand, and MODE is known to be complex.
3280 Returns the last instruction emitted. */
3283 emit_move_complex_push (enum machine_mode mode
, rtx x
, rtx y
)
3285 enum machine_mode submode
= GET_MODE_INNER (mode
);
3288 #ifdef PUSH_ROUNDING
3289 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3291 /* In case we output to the stack, but the size is smaller than the
3292 machine can push exactly, we need to use move instructions. */
3293 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3295 x
= emit_move_resolve_push (mode
, x
);
3296 return emit_move_insn (x
, y
);
3300 /* Note that the real part always precedes the imag part in memory
3301 regardless of machine's endianness. */
3302 switch (GET_CODE (XEXP (x
, 0)))
3316 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3317 read_complex_part (y
, imag_first
));
3318 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3319 read_complex_part (y
, !imag_first
));
3322 /* A subroutine of emit_move_complex. Perform the move from Y to X
3323 via two moves of the parts. Returns the last instruction emitted. */
3326 emit_move_complex_parts (rtx x
, rtx y
)
3328 /* Show the output dies here. This is necessary for SUBREGs
3329 of pseudos since we cannot track their lifetimes correctly;
3330 hard regs shouldn't appear here except as return values. */
3331 if (!reload_completed
&& !reload_in_progress
3332 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3335 write_complex_part (x
, read_complex_part (y
, false), false);
3336 write_complex_part (x
, read_complex_part (y
, true), true);
3338 return get_last_insn ();
3341 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3342 MODE is known to be complex. Returns the last instruction emitted. */
3345 emit_move_complex (enum machine_mode mode
, rtx x
, rtx y
)
3349 /* Need to take special care for pushes, to maintain proper ordering
3350 of the data, and possibly extra padding. */
3351 if (push_operand (x
, mode
))
3352 return emit_move_complex_push (mode
, x
, y
);
3354 /* See if we can coerce the target into moving both values at once, except
3355 for floating point where we favor moving as parts if this is easy. */
3356 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3357 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
3359 && HARD_REGISTER_P (x
)
3360 && hard_regno_nregs
[REGNO (x
)][mode
] == 1)
3362 && HARD_REGISTER_P (y
)
3363 && hard_regno_nregs
[REGNO (y
)][mode
] == 1))
3365 /* Not possible if the values are inherently not adjacent. */
3366 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3368 /* Is possible if both are registers (or subregs of registers). */
3369 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3371 /* If one of the operands is a memory, and alignment constraints
3372 are friendly enough, we may be able to do combined memory operations.
3373 We do not attempt this if Y is a constant because that combination is
3374 usually better with the by-parts thing below. */
3375 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3376 && (!STRICT_ALIGNMENT
3377 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3386 /* For memory to memory moves, optimal behavior can be had with the
3387 existing block move logic. */
3388 if (MEM_P (x
) && MEM_P (y
))
3390 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3391 BLOCK_OP_NO_LIBCALL
);
3392 return get_last_insn ();
3395 ret
= emit_move_via_integer (mode
, x
, y
, true);
3400 return emit_move_complex_parts (x
, y
);
3403 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3404 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3407 emit_move_ccmode (enum machine_mode mode
, rtx x
, rtx y
)
3411 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3414 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3415 if (code
!= CODE_FOR_nothing
)
3417 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3418 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3419 return emit_insn (GEN_FCN (code
) (x
, y
));
3423 /* Otherwise, find the MODE_INT mode of the same width. */
3424 ret
= emit_move_via_integer (mode
, x
, y
, false);
3425 gcc_assert (ret
!= NULL
);
3429 /* Return true if word I of OP lies entirely in the
3430 undefined bits of a paradoxical subreg. */
3433 undefined_operand_subword_p (const_rtx op
, int i
)
3435 enum machine_mode innermode
, innermostmode
;
3437 if (GET_CODE (op
) != SUBREG
)
3439 innermode
= GET_MODE (op
);
3440 innermostmode
= GET_MODE (SUBREG_REG (op
));
3441 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3442 /* The SUBREG_BYTE represents offset, as if the value were stored in
3443 memory, except for a paradoxical subreg where we define
3444 SUBREG_BYTE to be 0; undo this exception as in
3446 if (SUBREG_BYTE (op
) == 0
3447 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3449 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3450 if (WORDS_BIG_ENDIAN
)
3451 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3452 if (BYTES_BIG_ENDIAN
)
3453 offset
+= difference
% UNITS_PER_WORD
;
3455 if (offset
>= GET_MODE_SIZE (innermostmode
)
3456 || offset
<= -GET_MODE_SIZE (word_mode
))
3461 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3462 MODE is any multi-word or full-word mode that lacks a move_insn
3463 pattern. Note that you will get better code if you define such
3464 patterns, even if they must turn into multiple assembler instructions. */
3467 emit_move_multi_word (enum machine_mode mode
, rtx x
, rtx y
)
3474 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3476 /* If X is a push on the stack, do the push now and replace
3477 X with a reference to the stack pointer. */
3478 if (push_operand (x
, mode
))
3479 x
= emit_move_resolve_push (mode
, x
);
3481 /* If we are in reload, see if either operand is a MEM whose address
3482 is scheduled for replacement. */
3483 if (reload_in_progress
&& MEM_P (x
)
3484 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3485 x
= replace_equiv_address_nv (x
, inner
);
3486 if (reload_in_progress
&& MEM_P (y
)
3487 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3488 y
= replace_equiv_address_nv (y
, inner
);
3492 need_clobber
= false;
3494 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3497 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3500 /* Do not generate code for a move if it would come entirely
3501 from the undefined bits of a paradoxical subreg. */
3502 if (undefined_operand_subword_p (y
, i
))
3505 ypart
= operand_subword (y
, i
, 1, mode
);
3507 /* If we can't get a part of Y, put Y into memory if it is a
3508 constant. Otherwise, force it into a register. Then we must
3509 be able to get a part of Y. */
3510 if (ypart
== 0 && CONSTANT_P (y
))
3512 y
= use_anchored_address (force_const_mem (mode
, y
));
3513 ypart
= operand_subword (y
, i
, 1, mode
);
3515 else if (ypart
== 0)
3516 ypart
= operand_subword_force (y
, i
, mode
);
3518 gcc_assert (xpart
&& ypart
);
3520 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3522 last_insn
= emit_move_insn (xpart
, ypart
);
3528 /* Show the output dies here. This is necessary for SUBREGs
3529 of pseudos since we cannot track their lifetimes correctly;
3530 hard regs shouldn't appear here except as return values.
3531 We never want to emit such a clobber after reload. */
3533 && ! (reload_in_progress
|| reload_completed
)
3534 && need_clobber
!= 0)
3542 /* Low level part of emit_move_insn.
3543 Called just like emit_move_insn, but assumes X and Y
3544 are basically valid. */
3547 emit_move_insn_1 (rtx x
, rtx y
)
3549 enum machine_mode mode
= GET_MODE (x
);
3550 enum insn_code code
;
3552 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3554 code
= optab_handler (mov_optab
, mode
);
3555 if (code
!= CODE_FOR_nothing
)
3556 return emit_insn (GEN_FCN (code
) (x
, y
));
3558 /* Expand complex moves by moving real part and imag part. */
3559 if (COMPLEX_MODE_P (mode
))
3560 return emit_move_complex (mode
, x
, y
);
3562 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3563 || ALL_FIXED_POINT_MODE_P (mode
))
3565 rtx result
= emit_move_via_integer (mode
, x
, y
, true);
3567 /* If we can't find an integer mode, use multi words. */
3571 return emit_move_multi_word (mode
, x
, y
);
3574 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3575 return emit_move_ccmode (mode
, x
, y
);
3577 /* Try using a move pattern for the corresponding integer mode. This is
3578 only safe when simplify_subreg can convert MODE constants into integer
3579 constants. At present, it can only do this reliably if the value
3580 fits within a HOST_WIDE_INT. */
3581 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3583 rtx ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3587 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3592 return emit_move_multi_word (mode
, x
, y
);
3595 /* Generate code to copy Y into X.
3596 Both Y and X must have the same mode, except that
3597 Y can be a constant with VOIDmode.
3598 This mode cannot be BLKmode; use emit_block_move for that.
3600 Return the last instruction emitted. */
3603 emit_move_insn (rtx x
, rtx y
)
3605 enum machine_mode mode
= GET_MODE (x
);
3606 rtx y_cst
= NULL_RTX
;
3609 gcc_assert (mode
!= BLKmode
3610 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3615 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3616 && (last_insn
= compress_float_constant (x
, y
)))
3621 if (!targetm
.legitimate_constant_p (mode
, y
))
3623 y
= force_const_mem (mode
, y
);
3625 /* If the target's cannot_force_const_mem prevented the spill,
3626 assume that the target's move expanders will also take care
3627 of the non-legitimate constant. */
3631 y
= use_anchored_address (y
);
3635 /* If X or Y are memory references, verify that their addresses are valid
3638 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3640 && ! push_operand (x
, GET_MODE (x
))))
3641 x
= validize_mem (x
);
3644 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3645 MEM_ADDR_SPACE (y
)))
3646 y
= validize_mem (y
);
3648 gcc_assert (mode
!= BLKmode
);
3650 last_insn
= emit_move_insn_1 (x
, y
);
3652 if (y_cst
&& REG_P (x
)
3653 && (set
= single_set (last_insn
)) != NULL_RTX
3654 && SET_DEST (set
) == x
3655 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3656 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3661 /* If Y is representable exactly in a narrower mode, and the target can
3662 perform the extension directly from constant or memory, then emit the
3663 move as an extension. */
3666 compress_float_constant (rtx x
, rtx y
)
3668 enum machine_mode dstmode
= GET_MODE (x
);
3669 enum machine_mode orig_srcmode
= GET_MODE (y
);
3670 enum machine_mode srcmode
;
3672 int oldcost
, newcost
;
3673 bool speed
= optimize_insn_for_speed_p ();
3675 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3677 if (targetm
.legitimate_constant_p (dstmode
, y
))
3678 oldcost
= set_src_cost (y
, speed
);
3680 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), speed
);
3682 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3683 srcmode
!= orig_srcmode
;
3684 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3687 rtx trunc_y
, last_insn
;
3689 /* Skip if the target can't extend this way. */
3690 ic
= can_extend_p (dstmode
, srcmode
, 0);
3691 if (ic
== CODE_FOR_nothing
)
3694 /* Skip if the narrowed value isn't exact. */
3695 if (! exact_real_truncate (srcmode
, &r
))
3698 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3700 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3702 /* Skip if the target needs extra instructions to perform
3704 if (!insn_operand_matches (ic
, 1, trunc_y
))
3706 /* This is valid, but may not be cheaper than the original. */
3707 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3709 if (oldcost
< newcost
)
3712 else if (float_extend_from_mem
[dstmode
][srcmode
])
3714 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3715 /* This is valid, but may not be cheaper than the original. */
3716 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3718 if (oldcost
< newcost
)
3720 trunc_y
= validize_mem (trunc_y
);
3725 /* For CSE's benefit, force the compressed constant pool entry
3726 into a new pseudo. This constant may be used in different modes,
3727 and if not, combine will put things back together for us. */
3728 trunc_y
= force_reg (srcmode
, trunc_y
);
3729 emit_unop_insn (ic
, x
, trunc_y
, UNKNOWN
);
3730 last_insn
= get_last_insn ();
3733 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3741 /* Pushing data onto the stack. */
3743 /* Push a block of length SIZE (perhaps variable)
3744 and return an rtx to address the beginning of the block.
3745 The value may be virtual_outgoing_args_rtx.
3747 EXTRA is the number of bytes of padding to push in addition to SIZE.
3748 BELOW nonzero means this padding comes at low addresses;
3749 otherwise, the padding comes at high addresses. */
3752 push_block (rtx size
, int extra
, int below
)
3756 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3757 if (CONSTANT_P (size
))
3758 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3759 else if (REG_P (size
) && extra
== 0)
3760 anti_adjust_stack (size
);
3763 temp
= copy_to_mode_reg (Pmode
, size
);
3765 temp
= expand_binop (Pmode
, add_optab
, temp
,
3766 gen_int_mode (extra
, Pmode
),
3767 temp
, 0, OPTAB_LIB_WIDEN
);
3768 anti_adjust_stack (temp
);
3771 #ifndef STACK_GROWS_DOWNWARD
3777 temp
= virtual_outgoing_args_rtx
;
3778 if (extra
!= 0 && below
)
3779 temp
= plus_constant (Pmode
, temp
, extra
);
3783 if (CONST_INT_P (size
))
3784 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3785 -INTVAL (size
) - (below
? 0 : extra
));
3786 else if (extra
!= 0 && !below
)
3787 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3788 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3791 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3792 negate_rtx (Pmode
, size
));
3795 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3798 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3801 mem_autoinc_base (rtx mem
)
3805 rtx addr
= XEXP (mem
, 0);
3806 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3807 return XEXP (addr
, 0);
3812 /* A utility routine used here, in reload, and in try_split. The insns
3813 after PREV up to and including LAST are known to adjust the stack,
3814 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3815 placing notes as appropriate. PREV may be NULL, indicating the
3816 entire insn sequence prior to LAST should be scanned.
3818 The set of allowed stack pointer modifications is small:
3819 (1) One or more auto-inc style memory references (aka pushes),
3820 (2) One or more addition/subtraction with the SP as destination,
3821 (3) A single move insn with the SP as destination,
3822 (4) A call_pop insn,
3823 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3825 Insns in the sequence that do not modify the SP are ignored,
3826 except for noreturn calls.
3828 The return value is the amount of adjustment that can be trivially
3829 verified, via immediate operand or auto-inc. If the adjustment
3830 cannot be trivially extracted, the return value is INT_MIN. */
3833 find_args_size_adjust (rtx insn
)
3838 pat
= PATTERN (insn
);
3841 /* Look for a call_pop pattern. */
3844 /* We have to allow non-call_pop patterns for the case
3845 of emit_single_push_insn of a TLS address. */
3846 if (GET_CODE (pat
) != PARALLEL
)
3849 /* All call_pop have a stack pointer adjust in the parallel.
3850 The call itself is always first, and the stack adjust is
3851 usually last, so search from the end. */
3852 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3854 set
= XVECEXP (pat
, 0, i
);
3855 if (GET_CODE (set
) != SET
)
3857 dest
= SET_DEST (set
);
3858 if (dest
== stack_pointer_rtx
)
3861 /* We'd better have found the stack pointer adjust. */
3864 /* Fall through to process the extracted SET and DEST
3865 as if it was a standalone insn. */
3867 else if (GET_CODE (pat
) == SET
)
3869 else if ((set
= single_set (insn
)) != NULL
)
3871 else if (GET_CODE (pat
) == PARALLEL
)
3873 /* ??? Some older ports use a parallel with a stack adjust
3874 and a store for a PUSH_ROUNDING pattern, rather than a
3875 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3876 /* ??? See h8300 and m68k, pushqi1. */
3877 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3879 set
= XVECEXP (pat
, 0, i
);
3880 if (GET_CODE (set
) != SET
)
3882 dest
= SET_DEST (set
);
3883 if (dest
== stack_pointer_rtx
)
3886 /* We do not expect an auto-inc of the sp in the parallel. */
3887 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3888 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3889 != stack_pointer_rtx
);
3897 dest
= SET_DEST (set
);
3899 /* Look for direct modifications of the stack pointer. */
3900 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3902 /* Look for a trivial adjustment, otherwise assume nothing. */
3903 /* Note that the SPU restore_stack_block pattern refers to
3904 the stack pointer in V4SImode. Consider that non-trivial. */
3905 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3906 && GET_CODE (SET_SRC (set
)) == PLUS
3907 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3908 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3909 return INTVAL (XEXP (SET_SRC (set
), 1));
3910 /* ??? Reload can generate no-op moves, which will be cleaned
3911 up later. Recognize it and continue searching. */
3912 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3915 return HOST_WIDE_INT_MIN
;
3921 /* Otherwise only think about autoinc patterns. */
3922 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3925 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3926 != stack_pointer_rtx
);
3928 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3929 mem
= SET_SRC (set
);
3933 addr
= XEXP (mem
, 0);
3934 switch (GET_CODE (addr
))
3938 return GET_MODE_SIZE (GET_MODE (mem
));
3941 return -GET_MODE_SIZE (GET_MODE (mem
));
3944 addr
= XEXP (addr
, 1);
3945 gcc_assert (GET_CODE (addr
) == PLUS
);
3946 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3947 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3948 return INTVAL (XEXP (addr
, 1));
3956 fixup_args_size_notes (rtx prev
, rtx last
, int end_args_size
)
3958 int args_size
= end_args_size
;
3959 bool saw_unknown
= false;
3962 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3964 HOST_WIDE_INT this_delta
;
3966 if (!NONDEBUG_INSN_P (insn
))
3969 this_delta
= find_args_size_adjust (insn
);
3970 if (this_delta
== 0)
3973 || ACCUMULATE_OUTGOING_ARGS
3974 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3978 gcc_assert (!saw_unknown
);
3979 if (this_delta
== HOST_WIDE_INT_MIN
)
3982 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3983 #ifdef STACK_GROWS_DOWNWARD
3984 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3986 args_size
-= this_delta
;
3989 return saw_unknown
? INT_MIN
: args_size
;
3992 #ifdef PUSH_ROUNDING
3993 /* Emit single push insn. */
3996 emit_single_push_insn_1 (enum machine_mode mode
, rtx x
, tree type
)
3999 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
4001 enum insn_code icode
;
4003 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
4004 /* If there is push pattern, use it. Otherwise try old way of throwing
4005 MEM representing push operation to move expander. */
4006 icode
= optab_handler (push_optab
, mode
);
4007 if (icode
!= CODE_FOR_nothing
)
4009 struct expand_operand ops
[1];
4011 create_input_operand (&ops
[0], x
, mode
);
4012 if (maybe_expand_insn (icode
, 1, ops
))
4015 if (GET_MODE_SIZE (mode
) == rounded_size
)
4016 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
4017 /* If we are to pad downward, adjust the stack pointer first and
4018 then store X into the stack location using an offset. This is
4019 because emit_move_insn does not know how to pad; it does not have
4021 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
4023 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
4024 HOST_WIDE_INT offset
;
4026 emit_move_insn (stack_pointer_rtx
,
4027 expand_binop (Pmode
,
4028 #ifdef STACK_GROWS_DOWNWARD
4034 gen_int_mode (rounded_size
, Pmode
),
4035 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
4037 offset
= (HOST_WIDE_INT
) padding_size
;
4038 #ifdef STACK_GROWS_DOWNWARD
4039 if (STACK_PUSH_CODE
== POST_DEC
)
4040 /* We have already decremented the stack pointer, so get the
4042 offset
+= (HOST_WIDE_INT
) rounded_size
;
4044 if (STACK_PUSH_CODE
== POST_INC
)
4045 /* We have already incremented the stack pointer, so get the
4047 offset
-= (HOST_WIDE_INT
) rounded_size
;
4049 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4050 gen_int_mode (offset
, Pmode
));
4054 #ifdef STACK_GROWS_DOWNWARD
4055 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4056 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4057 gen_int_mode (-(HOST_WIDE_INT
) rounded_size
,
4060 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4061 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4062 gen_int_mode (rounded_size
, Pmode
));
4064 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
4067 dest
= gen_rtx_MEM (mode
, dest_addr
);
4071 set_mem_attributes (dest
, type
, 1);
4073 if (flag_optimize_sibling_calls
)
4074 /* Function incoming arguments may overlap with sibling call
4075 outgoing arguments and we cannot allow reordering of reads
4076 from function arguments with stores to outgoing arguments
4077 of sibling calls. */
4078 set_mem_alias_set (dest
, 0);
4080 emit_move_insn (dest
, x
);
4083 /* Emit and annotate a single push insn. */
4086 emit_single_push_insn (enum machine_mode mode
, rtx x
, tree type
)
4088 int delta
, old_delta
= stack_pointer_delta
;
4089 rtx prev
= get_last_insn ();
4092 emit_single_push_insn_1 (mode
, x
, type
);
4094 last
= get_last_insn ();
4096 /* Notice the common case where we emitted exactly one insn. */
4097 if (PREV_INSN (last
) == prev
)
4099 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
4103 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
4104 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
4108 /* Generate code to push X onto the stack, assuming it has mode MODE and
4110 MODE is redundant except when X is a CONST_INT (since they don't
4112 SIZE is an rtx for the size of data to be copied (in bytes),
4113 needed only if X is BLKmode.
4115 ALIGN (in bits) is maximum alignment we can assume.
4117 If PARTIAL and REG are both nonzero, then copy that many of the first
4118 bytes of X into registers starting with REG, and push the rest of X.
4119 The amount of space pushed is decreased by PARTIAL bytes.
4120 REG must be a hard register in this case.
4121 If REG is zero but PARTIAL is not, take any all others actions for an
4122 argument partially in registers, but do not actually load any
4125 EXTRA is the amount in bytes of extra space to leave next to this arg.
4126 This is ignored if an argument block has already been allocated.
4128 On a machine that lacks real push insns, ARGS_ADDR is the address of
4129 the bottom of the argument block for this call. We use indexing off there
4130 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4131 argument block has not been preallocated.
4133 ARGS_SO_FAR is the size of args previously pushed for this call.
4135 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4136 for arguments passed in registers. If nonzero, it will be the number
4137 of bytes required. */
4140 emit_push_insn (rtx x
, enum machine_mode mode
, tree type
, rtx size
,
4141 unsigned int align
, int partial
, rtx reg
, int extra
,
4142 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4146 enum direction stack_direction
4147 #ifdef STACK_GROWS_DOWNWARD
4153 /* Decide where to pad the argument: `downward' for below,
4154 `upward' for above, or `none' for don't pad it.
4155 Default is below for small data on big-endian machines; else above. */
4156 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4158 /* Invert direction if stack is post-decrement.
4160 if (STACK_PUSH_CODE
== POST_DEC
)
4161 if (where_pad
!= none
)
4162 where_pad
= (where_pad
== downward
? upward
: downward
);
4167 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4169 /* Copy a block into the stack, entirely or partially. */
4176 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4177 used
= partial
- offset
;
4179 if (mode
!= BLKmode
)
4181 /* A value is to be stored in an insufficiently aligned
4182 stack slot; copy via a suitably aligned slot if
4184 size
= GEN_INT (GET_MODE_SIZE (mode
));
4185 if (!MEM_P (xinner
))
4187 temp
= assign_temp (type
, 1, 1);
4188 emit_move_insn (temp
, xinner
);
4195 /* USED is now the # of bytes we need not copy to the stack
4196 because registers will take care of them. */
4199 xinner
= adjust_address (xinner
, BLKmode
, used
);
4201 /* If the partial register-part of the arg counts in its stack size,
4202 skip the part of stack space corresponding to the registers.
4203 Otherwise, start copying to the beginning of the stack space,
4204 by setting SKIP to 0. */
4205 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4207 #ifdef PUSH_ROUNDING
4208 /* Do it with several push insns if that doesn't take lots of insns
4209 and if there is no difficulty with push insns that skip bytes
4210 on the stack for alignment purposes. */
4213 && CONST_INT_P (size
)
4215 && MEM_ALIGN (xinner
) >= align
4216 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size
) - used
, align
))
4217 /* Here we avoid the case of a structure whose weak alignment
4218 forces many pushes of a small amount of data,
4219 and such small pushes do rounding that causes trouble. */
4220 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4221 || align
>= BIGGEST_ALIGNMENT
4222 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4223 == (align
/ BITS_PER_UNIT
)))
4224 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4226 /* Push padding now if padding above and stack grows down,
4227 or if padding below and stack grows up.
4228 But if space already allocated, this has already been done. */
4229 if (extra
&& args_addr
== 0
4230 && where_pad
!= none
&& where_pad
!= stack_direction
)
4231 anti_adjust_stack (GEN_INT (extra
));
4233 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4236 #endif /* PUSH_ROUNDING */
4240 /* Otherwise make space on the stack and copy the data
4241 to the address of that space. */
4243 /* Deduct words put into registers from the size we must copy. */
4246 if (CONST_INT_P (size
))
4247 size
= GEN_INT (INTVAL (size
) - used
);
4249 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4250 gen_int_mode (used
, GET_MODE (size
)),
4251 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4254 /* Get the address of the stack space.
4255 In this case, we do not deal with EXTRA separately.
4256 A single stack adjust will do. */
4259 temp
= push_block (size
, extra
, where_pad
== downward
);
4262 else if (CONST_INT_P (args_so_far
))
4263 temp
= memory_address (BLKmode
,
4264 plus_constant (Pmode
, args_addr
,
4265 skip
+ INTVAL (args_so_far
)));
4267 temp
= memory_address (BLKmode
,
4268 plus_constant (Pmode
,
4269 gen_rtx_PLUS (Pmode
,
4274 if (!ACCUMULATE_OUTGOING_ARGS
)
4276 /* If the source is referenced relative to the stack pointer,
4277 copy it to another register to stabilize it. We do not need
4278 to do this if we know that we won't be changing sp. */
4280 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4281 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4282 temp
= copy_to_reg (temp
);
4285 target
= gen_rtx_MEM (BLKmode
, temp
);
4287 /* We do *not* set_mem_attributes here, because incoming arguments
4288 may overlap with sibling call outgoing arguments and we cannot
4289 allow reordering of reads from function arguments with stores
4290 to outgoing arguments of sibling calls. We do, however, want
4291 to record the alignment of the stack slot. */
4292 /* ALIGN may well be better aligned than TYPE, e.g. due to
4293 PARM_BOUNDARY. Assume the caller isn't lying. */
4294 set_mem_align (target
, align
);
4296 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4299 else if (partial
> 0)
4301 /* Scalar partly in registers. */
4303 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4306 /* # bytes of start of argument
4307 that we must make space for but need not store. */
4308 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4309 int args_offset
= INTVAL (args_so_far
);
4312 /* Push padding now if padding above and stack grows down,
4313 or if padding below and stack grows up.
4314 But if space already allocated, this has already been done. */
4315 if (extra
&& args_addr
== 0
4316 && where_pad
!= none
&& where_pad
!= stack_direction
)
4317 anti_adjust_stack (GEN_INT (extra
));
4319 /* If we make space by pushing it, we might as well push
4320 the real data. Otherwise, we can leave OFFSET nonzero
4321 and leave the space uninitialized. */
4325 /* Now NOT_STACK gets the number of words that we don't need to
4326 allocate on the stack. Convert OFFSET to words too. */
4327 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4328 offset
/= UNITS_PER_WORD
;
4330 /* If the partial register-part of the arg counts in its stack size,
4331 skip the part of stack space corresponding to the registers.
4332 Otherwise, start copying to the beginning of the stack space,
4333 by setting SKIP to 0. */
4334 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4336 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4337 x
= validize_mem (force_const_mem (mode
, x
));
4339 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4340 SUBREGs of such registers are not allowed. */
4341 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4342 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4343 x
= copy_to_reg (x
);
4345 /* Loop over all the words allocated on the stack for this arg. */
4346 /* We can do it by words, because any scalar bigger than a word
4347 has a size a multiple of a word. */
4348 #ifndef PUSH_ARGS_REVERSED
4349 for (i
= not_stack
; i
< size
; i
++)
4351 for (i
= size
- 1; i
>= not_stack
; i
--)
4353 if (i
>= not_stack
+ offset
)
4354 emit_push_insn (operand_subword_force (x
, i
, mode
),
4355 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4357 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4359 reg_parm_stack_space
, alignment_pad
);
4366 /* Push padding now if padding above and stack grows down,
4367 or if padding below and stack grows up.
4368 But if space already allocated, this has already been done. */
4369 if (extra
&& args_addr
== 0
4370 && where_pad
!= none
&& where_pad
!= stack_direction
)
4371 anti_adjust_stack (GEN_INT (extra
));
4373 #ifdef PUSH_ROUNDING
4374 if (args_addr
== 0 && PUSH_ARGS
)
4375 emit_single_push_insn (mode
, x
, type
);
4379 if (CONST_INT_P (args_so_far
))
4381 = memory_address (mode
,
4382 plus_constant (Pmode
, args_addr
,
4383 INTVAL (args_so_far
)));
4385 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4387 dest
= gen_rtx_MEM (mode
, addr
);
4389 /* We do *not* set_mem_attributes here, because incoming arguments
4390 may overlap with sibling call outgoing arguments and we cannot
4391 allow reordering of reads from function arguments with stores
4392 to outgoing arguments of sibling calls. We do, however, want
4393 to record the alignment of the stack slot. */
4394 /* ALIGN may well be better aligned than TYPE, e.g. due to
4395 PARM_BOUNDARY. Assume the caller isn't lying. */
4396 set_mem_align (dest
, align
);
4398 emit_move_insn (dest
, x
);
4402 /* If part should go in registers, copy that part
4403 into the appropriate registers. Do this now, at the end,
4404 since mem-to-mem copies above may do function calls. */
4405 if (partial
> 0 && reg
!= 0)
4407 /* Handle calls that pass values in multiple non-contiguous locations.
4408 The Irix 6 ABI has examples of this. */
4409 if (GET_CODE (reg
) == PARALLEL
)
4410 emit_group_load (reg
, x
, type
, -1);
4413 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4414 move_block_to_reg (REGNO (reg
), x
, partial
/ UNITS_PER_WORD
, mode
);
4418 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4419 anti_adjust_stack (GEN_INT (extra
));
4421 if (alignment_pad
&& args_addr
== 0)
4422 anti_adjust_stack (alignment_pad
);
4425 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4429 get_subtarget (rtx x
)
4433 /* Only registers can be subtargets. */
4435 /* Don't use hard regs to avoid extending their life. */
4436 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4440 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4441 FIELD is a bitfield. Returns true if the optimization was successful,
4442 and there's nothing else to do. */
4445 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4446 unsigned HOST_WIDE_INT bitpos
,
4447 unsigned HOST_WIDE_INT bitregion_start
,
4448 unsigned HOST_WIDE_INT bitregion_end
,
4449 enum machine_mode mode1
, rtx str_rtx
,
4452 enum machine_mode str_mode
= GET_MODE (str_rtx
);
4453 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4458 enum tree_code code
;
4460 if (mode1
!= VOIDmode
4461 || bitsize
>= BITS_PER_WORD
4462 || str_bitsize
> BITS_PER_WORD
4463 || TREE_SIDE_EFFECTS (to
)
4464 || TREE_THIS_VOLATILE (to
))
4468 if (TREE_CODE (src
) != SSA_NAME
)
4470 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4473 srcstmt
= get_gimple_for_ssa_name (src
);
4475 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4478 code
= gimple_assign_rhs_code (srcstmt
);
4480 op0
= gimple_assign_rhs1 (srcstmt
);
4482 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4483 to find its initialization. Hopefully the initialization will
4484 be from a bitfield load. */
4485 if (TREE_CODE (op0
) == SSA_NAME
)
4487 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4489 /* We want to eventually have OP0 be the same as TO, which
4490 should be a bitfield. */
4492 || !is_gimple_assign (op0stmt
)
4493 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4495 op0
= gimple_assign_rhs1 (op0stmt
);
4498 op1
= gimple_assign_rhs2 (srcstmt
);
4500 if (!operand_equal_p (to
, op0
, 0))
4503 if (MEM_P (str_rtx
))
4505 unsigned HOST_WIDE_INT offset1
;
4507 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4508 str_mode
= word_mode
;
4509 str_mode
= get_best_mode (bitsize
, bitpos
,
4510 bitregion_start
, bitregion_end
,
4511 MEM_ALIGN (str_rtx
), str_mode
, 0);
4512 if (str_mode
== VOIDmode
)
4514 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4517 bitpos
%= str_bitsize
;
4518 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4519 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4521 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4524 /* If the bit field covers the whole REG/MEM, store_field
4525 will likely generate better code. */
4526 if (bitsize
>= str_bitsize
)
4529 /* We can't handle fields split across multiple entities. */
4530 if (bitpos
+ bitsize
> str_bitsize
)
4533 if (BYTES_BIG_ENDIAN
)
4534 bitpos
= str_bitsize
- bitpos
- bitsize
;
4540 /* For now, just optimize the case of the topmost bitfield
4541 where we don't need to do any masking and also
4542 1 bit bitfields where xor can be used.
4543 We might win by one instruction for the other bitfields
4544 too if insv/extv instructions aren't used, so that
4545 can be added later. */
4546 if (bitpos
+ bitsize
!= str_bitsize
4547 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4550 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4551 value
= convert_modes (str_mode
,
4552 TYPE_MODE (TREE_TYPE (op1
)), value
,
4553 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4555 /* We may be accessing data outside the field, which means
4556 we can alias adjacent data. */
4557 if (MEM_P (str_rtx
))
4559 str_rtx
= shallow_copy_rtx (str_rtx
);
4560 set_mem_alias_set (str_rtx
, 0);
4561 set_mem_expr (str_rtx
, 0);
4564 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4565 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4567 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4570 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4571 result
= expand_binop (str_mode
, binop
, str_rtx
,
4572 value
, str_rtx
, 1, OPTAB_WIDEN
);
4573 if (result
!= str_rtx
)
4574 emit_move_insn (str_rtx
, result
);
4579 if (TREE_CODE (op1
) != INTEGER_CST
)
4581 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4582 value
= convert_modes (str_mode
,
4583 TYPE_MODE (TREE_TYPE (op1
)), value
,
4584 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4586 /* We may be accessing data outside the field, which means
4587 we can alias adjacent data. */
4588 if (MEM_P (str_rtx
))
4590 str_rtx
= shallow_copy_rtx (str_rtx
);
4591 set_mem_alias_set (str_rtx
, 0);
4592 set_mem_expr (str_rtx
, 0);
4595 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4596 if (bitpos
+ bitsize
!= str_bitsize
)
4598 rtx mask
= gen_int_mode (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1,
4600 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4602 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4603 result
= expand_binop (str_mode
, binop
, str_rtx
,
4604 value
, str_rtx
, 1, OPTAB_WIDEN
);
4605 if (result
!= str_rtx
)
4606 emit_move_insn (str_rtx
, result
);
4616 /* In the C++ memory model, consecutive bit fields in a structure are
4617 considered one memory location.
4619 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4620 returns the bit range of consecutive bits in which this COMPONENT_REF
4621 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4622 and *OFFSET may be adjusted in the process.
4624 If the access does not need to be restricted, 0 is returned in both
4625 *BITSTART and *BITEND. */
4628 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4629 unsigned HOST_WIDE_INT
*bitend
,
4631 HOST_WIDE_INT
*bitpos
,
4634 HOST_WIDE_INT bitoffset
;
4637 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4639 field
= TREE_OPERAND (exp
, 1);
4640 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4641 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4642 need to limit the range we can access. */
4645 *bitstart
= *bitend
= 0;
4649 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4650 part of a larger bit field, then the representative does not serve any
4651 useful purpose. This can occur in Ada. */
4652 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4654 enum machine_mode rmode
;
4655 HOST_WIDE_INT rbitsize
, rbitpos
;
4659 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4660 &roffset
, &rmode
, &unsignedp
, &volatilep
);
4661 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4663 *bitstart
= *bitend
= 0;
4668 /* Compute the adjustment to bitpos from the offset of the field
4669 relative to the representative. DECL_FIELD_OFFSET of field and
4670 repr are the same by construction if they are not constants,
4671 see finish_bitfield_layout. */
4672 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
4673 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
4674 bitoffset
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
4675 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
4678 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
4679 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
4681 /* If the adjustment is larger than bitpos, we would have a negative bit
4682 position for the lower bound and this may wreak havoc later. Adjust
4683 offset and bitpos to make the lower bound non-negative in that case. */
4684 if (bitoffset
> *bitpos
)
4686 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4687 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4690 if (*offset
== NULL_TREE
)
4691 *offset
= size_int (-adjust
/ BITS_PER_UNIT
);
4694 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4698 *bitstart
= *bitpos
- bitoffset
;
4700 *bitend
= *bitstart
+ tree_to_uhwi (DECL_SIZE (repr
)) - 1;
4703 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4704 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4705 DECL_RTL was not set yet, return NORTL. */
4708 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4710 if (TREE_CODE (addr
) != ADDR_EXPR
)
4713 tree base
= TREE_OPERAND (addr
, 0);
4716 || TREE_ADDRESSABLE (base
)
4717 || DECL_MODE (base
) == BLKmode
)
4720 if (!DECL_RTL_SET_P (base
))
4723 return (!MEM_P (DECL_RTL (base
)));
4726 /* Returns true if the MEM_REF REF refers to an object that does not
4727 reside in memory and has non-BLKmode. */
4730 mem_ref_refers_to_non_mem_p (tree ref
)
4732 tree base
= TREE_OPERAND (ref
, 0);
4733 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4736 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4737 is true, try generating a nontemporal store. */
4740 expand_assignment (tree to
, tree from
, bool nontemporal
)
4744 enum machine_mode mode
;
4746 enum insn_code icode
;
4748 /* Don't crash if the lhs of the assignment was erroneous. */
4749 if (TREE_CODE (to
) == ERROR_MARK
)
4751 expand_normal (from
);
4755 /* Optimize away no-op moves without side-effects. */
4756 if (operand_equal_p (to
, from
, 0))
4759 /* Handle misaligned stores. */
4760 mode
= TYPE_MODE (TREE_TYPE (to
));
4761 if ((TREE_CODE (to
) == MEM_REF
4762 || TREE_CODE (to
) == TARGET_MEM_REF
)
4764 && !mem_ref_refers_to_non_mem_p (to
)
4765 && ((align
= get_object_alignment (to
))
4766 < GET_MODE_ALIGNMENT (mode
))
4767 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4768 != CODE_FOR_nothing
)
4769 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4773 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4774 reg
= force_not_mem (reg
);
4775 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4777 if (icode
!= CODE_FOR_nothing
)
4779 struct expand_operand ops
[2];
4781 create_fixed_operand (&ops
[0], mem
);
4782 create_input_operand (&ops
[1], reg
, mode
);
4783 /* The movmisalign<mode> pattern cannot fail, else the assignment
4784 would silently be omitted. */
4785 expand_insn (icode
, 2, ops
);
4788 store_bit_field (mem
, GET_MODE_BITSIZE (mode
), 0, 0, 0, mode
, reg
);
4792 /* Assignment of a structure component needs special treatment
4793 if the structure component's rtx is not simply a MEM.
4794 Assignment of an array element at a constant index, and assignment of
4795 an array element in an unaligned packed structure field, has the same
4796 problem. Same for (partially) storing into a non-memory object. */
4797 if (handled_component_p (to
)
4798 || (TREE_CODE (to
) == MEM_REF
4799 && mem_ref_refers_to_non_mem_p (to
))
4800 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4802 enum machine_mode mode1
;
4803 HOST_WIDE_INT bitsize
, bitpos
;
4804 unsigned HOST_WIDE_INT bitregion_start
= 0;
4805 unsigned HOST_WIDE_INT bitregion_end
= 0;
4812 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4813 &unsignedp
, &volatilep
);
4815 /* Make sure bitpos is not negative, it can wreak havoc later. */
4818 gcc_assert (offset
== NULL_TREE
);
4819 offset
= size_int (bitpos
>> (BITS_PER_UNIT
== 8
4820 ? 3 : exact_log2 (BITS_PER_UNIT
)));
4821 bitpos
&= BITS_PER_UNIT
- 1;
4824 if (TREE_CODE (to
) == COMPONENT_REF
4825 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4826 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4828 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4830 /* If the bitfield is volatile, we want to access it in the
4831 field's mode, not the computed mode.
4832 If a MEM has VOIDmode (external with incomplete type),
4833 use BLKmode for it instead. */
4836 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
4837 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4838 else if (GET_MODE (to_rtx
) == VOIDmode
)
4839 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4844 enum machine_mode address_mode
;
4847 if (!MEM_P (to_rtx
))
4849 /* We can get constant negative offsets into arrays with broken
4850 user code. Translate this to a trap instead of ICEing. */
4851 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4852 expand_builtin_trap ();
4853 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4856 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4857 address_mode
= get_address_mode (to_rtx
);
4858 if (GET_MODE (offset_rtx
) != address_mode
)
4859 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4861 /* A constant address in TO_RTX can have VOIDmode, we must not try
4862 to call force_reg for that case. Avoid that case. */
4864 && GET_MODE (to_rtx
) == BLKmode
4865 && GET_MODE (XEXP (to_rtx
, 0)) != VOIDmode
4867 && (bitpos
% bitsize
) == 0
4868 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4869 && MEM_ALIGN (to_rtx
) == GET_MODE_ALIGNMENT (mode1
))
4871 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4875 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4876 highest_pow2_factor_for_target (to
,
4880 /* No action is needed if the target is not a memory and the field
4881 lies completely outside that target. This can occur if the source
4882 code contains an out-of-bounds access to a small array. */
4884 && GET_MODE (to_rtx
) != BLKmode
4885 && (unsigned HOST_WIDE_INT
) bitpos
4886 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4888 expand_normal (from
);
4891 /* Handle expand_expr of a complex value returning a CONCAT. */
4892 else if (GET_CODE (to_rtx
) == CONCAT
)
4894 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4895 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4897 && bitsize
== mode_bitsize
)
4898 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4899 else if (bitsize
== mode_bitsize
/ 2
4900 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4901 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4903 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4904 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4905 bitregion_start
, bitregion_end
,
4907 get_alias_set (to
), nontemporal
);
4908 else if (bitpos
>= mode_bitsize
/ 2)
4909 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4910 bitpos
- mode_bitsize
/ 2,
4911 bitregion_start
, bitregion_end
,
4913 get_alias_set (to
), nontemporal
);
4914 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4917 result
= expand_normal (from
);
4918 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4919 TYPE_MODE (TREE_TYPE (from
)), 0);
4920 emit_move_insn (XEXP (to_rtx
, 0),
4921 read_complex_part (from_rtx
, false));
4922 emit_move_insn (XEXP (to_rtx
, 1),
4923 read_complex_part (from_rtx
, true));
4927 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4928 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4929 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4930 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4931 result
= store_field (temp
, bitsize
, bitpos
,
4932 bitregion_start
, bitregion_end
,
4934 get_alias_set (to
), nontemporal
);
4935 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4936 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
4943 /* If the field is at offset zero, we could have been given the
4944 DECL_RTX of the parent struct. Don't munge it. */
4945 to_rtx
= shallow_copy_rtx (to_rtx
);
4946 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
4948 MEM_VOLATILE_P (to_rtx
) = 1;
4951 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
4952 bitregion_start
, bitregion_end
,
4957 result
= store_field (to_rtx
, bitsize
, bitpos
,
4958 bitregion_start
, bitregion_end
,
4960 get_alias_set (to
), nontemporal
);
4964 preserve_temp_slots (result
);
4969 /* If the rhs is a function call and its value is not an aggregate,
4970 call the function before we start to compute the lhs.
4971 This is needed for correct code for cases such as
4972 val = setjmp (buf) on machines where reference to val
4973 requires loading up part of an address in a separate insn.
4975 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4976 since it might be a promoted variable where the zero- or sign- extension
4977 needs to be done. Handling this in the normal way is safe because no
4978 computation is done before the call. The same is true for SSA names. */
4979 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
4980 && COMPLETE_TYPE_P (TREE_TYPE (from
))
4981 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
4982 && ! (((TREE_CODE (to
) == VAR_DECL
4983 || TREE_CODE (to
) == PARM_DECL
4984 || TREE_CODE (to
) == RESULT_DECL
)
4985 && REG_P (DECL_RTL (to
)))
4986 || TREE_CODE (to
) == SSA_NAME
))
4991 value
= expand_normal (from
);
4993 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4995 /* Handle calls that return values in multiple non-contiguous locations.
4996 The Irix 6 ABI has examples of this. */
4997 if (GET_CODE (to_rtx
) == PARALLEL
)
4999 if (GET_CODE (value
) == PARALLEL
)
5000 emit_group_move (to_rtx
, value
);
5002 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
5003 int_size_in_bytes (TREE_TYPE (from
)));
5005 else if (GET_CODE (value
) == PARALLEL
)
5006 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
5007 int_size_in_bytes (TREE_TYPE (from
)));
5008 else if (GET_MODE (to_rtx
) == BLKmode
)
5010 /* Handle calls that return BLKmode values in registers. */
5012 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
5014 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
5018 if (POINTER_TYPE_P (TREE_TYPE (to
)))
5019 value
= convert_memory_address_addr_space
5020 (GET_MODE (to_rtx
), value
,
5021 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
5023 emit_move_insn (to_rtx
, value
);
5025 preserve_temp_slots (to_rtx
);
5030 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5031 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5033 /* Don't move directly into a return register. */
5034 if (TREE_CODE (to
) == RESULT_DECL
5035 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
5041 /* If the source is itself a return value, it still is in a pseudo at
5042 this point so we can move it back to the return register directly. */
5044 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
5045 && TREE_CODE (from
) != CALL_EXPR
)
5046 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
5048 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
5050 /* Handle calls that return values in multiple non-contiguous locations.
5051 The Irix 6 ABI has examples of this. */
5052 if (GET_CODE (to_rtx
) == PARALLEL
)
5054 if (GET_CODE (temp
) == PARALLEL
)
5055 emit_group_move (to_rtx
, temp
);
5057 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
5058 int_size_in_bytes (TREE_TYPE (from
)));
5061 emit_move_insn (to_rtx
, temp
);
5063 preserve_temp_slots (to_rtx
);
5068 /* In case we are returning the contents of an object which overlaps
5069 the place the value is being stored, use a safe function when copying
5070 a value through a pointer into a structure value return block. */
5071 if (TREE_CODE (to
) == RESULT_DECL
5072 && TREE_CODE (from
) == INDIRECT_REF
5073 && ADDR_SPACE_GENERIC_P
5074 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5075 && refs_may_alias_p (to
, from
)
5076 && cfun
->returns_struct
5077 && !cfun
->returns_pcc_struct
)
5082 size
= expr_size (from
);
5083 from_rtx
= expand_normal (from
);
5085 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
5086 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
5087 XEXP (from_rtx
, 0), Pmode
,
5088 convert_to_mode (TYPE_MODE (sizetype
),
5089 size
, TYPE_UNSIGNED (sizetype
)),
5090 TYPE_MODE (sizetype
));
5092 preserve_temp_slots (to_rtx
);
5097 /* Compute FROM and store the value in the rtx we got. */
5100 result
= store_expr (from
, to_rtx
, 0, nontemporal
);
5101 preserve_temp_slots (result
);
5106 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5107 succeeded, false otherwise. */
5110 emit_storent_insn (rtx to
, rtx from
)
5112 struct expand_operand ops
[2];
5113 enum machine_mode mode
= GET_MODE (to
);
5114 enum insn_code code
= optab_handler (storent_optab
, mode
);
5116 if (code
== CODE_FOR_nothing
)
5119 create_fixed_operand (&ops
[0], to
);
5120 create_input_operand (&ops
[1], from
, mode
);
5121 return maybe_expand_insn (code
, 2, ops
);
5124 /* Generate code for computing expression EXP,
5125 and storing the value into TARGET.
5127 If the mode is BLKmode then we may return TARGET itself.
5128 It turns out that in BLKmode it doesn't cause a problem.
5129 because C has no operators that could combine two different
5130 assignments into the same BLKmode object with different values
5131 with no sequence point. Will other languages need this to
5134 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5135 stack, and block moves may need to be treated specially.
5137 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5140 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5143 rtx alt_rtl
= NULL_RTX
;
5144 location_t loc
= curr_insn_location ();
5146 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5148 /* C++ can generate ?: expressions with a throw expression in one
5149 branch and an rvalue in the other. Here, we resolve attempts to
5150 store the throw expression's nonexistent result. */
5151 gcc_assert (!call_param_p
);
5152 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5155 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5157 /* Perform first part of compound expression, then assign from second
5159 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5160 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5161 return store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5164 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5166 /* For conditional expression, get safe form of the target. Then
5167 test the condition, doing the appropriate assignment on either
5168 side. This avoids the creation of unnecessary temporaries.
5169 For non-BLKmode, it is more efficient not to do this. */
5171 rtx lab1
= gen_label_rtx (), lab2
= gen_label_rtx ();
5173 do_pending_stack_adjust ();
5175 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5176 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5178 emit_jump_insn (gen_jump (lab2
));
5181 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5188 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5189 /* If this is a scalar in a register that is stored in a wider mode
5190 than the declared mode, compute the result into its declared mode
5191 and then convert to the wider mode. Our value is the computed
5194 rtx inner_target
= 0;
5196 /* We can do the conversion inside EXP, which will often result
5197 in some optimizations. Do the conversion in two steps: first
5198 change the signedness, if needed, then the extend. But don't
5199 do this if the type of EXP is a subtype of something else
5200 since then the conversion might involve more than just
5201 converting modes. */
5202 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5203 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5204 && GET_MODE_PRECISION (GET_MODE (target
))
5205 == TYPE_PRECISION (TREE_TYPE (exp
)))
5207 if (TYPE_UNSIGNED (TREE_TYPE (exp
))
5208 != SUBREG_PROMOTED_UNSIGNED_P (target
))
5210 /* Some types, e.g. Fortran's logical*4, won't have a signed
5211 version, so use the mode instead. */
5213 = (signed_or_unsigned_type_for
5214 (SUBREG_PROMOTED_UNSIGNED_P (target
), TREE_TYPE (exp
)));
5216 ntype
= lang_hooks
.types
.type_for_mode
5217 (TYPE_MODE (TREE_TYPE (exp
)),
5218 SUBREG_PROMOTED_UNSIGNED_P (target
));
5220 exp
= fold_convert_loc (loc
, ntype
, exp
);
5223 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5224 (GET_MODE (SUBREG_REG (target
)),
5225 SUBREG_PROMOTED_UNSIGNED_P (target
)),
5228 inner_target
= SUBREG_REG (target
);
5231 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5232 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5234 /* If TEMP is a VOIDmode constant, use convert_modes to make
5235 sure that we properly convert it. */
5236 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5238 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5239 temp
, SUBREG_PROMOTED_UNSIGNED_P (target
));
5240 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5241 GET_MODE (target
), temp
,
5242 SUBREG_PROMOTED_UNSIGNED_P (target
));
5245 convert_move (SUBREG_REG (target
), temp
,
5246 SUBREG_PROMOTED_UNSIGNED_P (target
));
5250 else if ((TREE_CODE (exp
) == STRING_CST
5251 || (TREE_CODE (exp
) == MEM_REF
5252 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5253 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5255 && integer_zerop (TREE_OPERAND (exp
, 1))))
5256 && !nontemporal
&& !call_param_p
5259 /* Optimize initialization of an array with a STRING_CST. */
5260 HOST_WIDE_INT exp_len
, str_copy_len
;
5262 tree str
= TREE_CODE (exp
) == STRING_CST
5263 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5265 exp_len
= int_expr_size (exp
);
5269 if (TREE_STRING_LENGTH (str
) <= 0)
5272 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5273 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5276 str_copy_len
= TREE_STRING_LENGTH (str
);
5277 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5278 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5280 str_copy_len
+= STORE_MAX_PIECES
- 1;
5281 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5283 str_copy_len
= MIN (str_copy_len
, exp_len
);
5284 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5285 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5286 MEM_ALIGN (target
), false))
5291 dest_mem
= store_by_pieces (dest_mem
,
5292 str_copy_len
, builtin_strncpy_read_str
,
5294 TREE_STRING_POINTER (str
)),
5295 MEM_ALIGN (target
), false,
5296 exp_len
> str_copy_len
? 1 : 0);
5297 if (exp_len
> str_copy_len
)
5298 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5299 GEN_INT (exp_len
- str_copy_len
),
5308 /* If we want to use a nontemporal store, force the value to
5310 tmp_target
= nontemporal
? NULL_RTX
: target
;
5311 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5313 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5317 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5318 the same as that of TARGET, adjust the constant. This is needed, for
5319 example, in case it is a CONST_DOUBLE and we want only a word-sized
5321 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5322 && TREE_CODE (exp
) != ERROR_MARK
5323 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5324 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5325 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5327 /* If value was not generated in the target, store it there.
5328 Convert the value to TARGET's type first if necessary and emit the
5329 pending incrementations that have been queued when expanding EXP.
5330 Note that we cannot emit the whole queue blindly because this will
5331 effectively disable the POST_INC optimization later.
5333 If TEMP and TARGET compare equal according to rtx_equal_p, but
5334 one or both of them are volatile memory refs, we have to distinguish
5336 - expand_expr has used TARGET. In this case, we must not generate
5337 another copy. This can be detected by TARGET being equal according
5339 - expand_expr has not used TARGET - that means that the source just
5340 happens to have the same RTX form. Since temp will have been created
5341 by expand_expr, it will compare unequal according to == .
5342 We must generate a copy in this case, to reach the correct number
5343 of volatile memory references. */
5345 if ((! rtx_equal_p (temp
, target
)
5346 || (temp
!= target
&& (side_effects_p (temp
)
5347 || side_effects_p (target
))))
5348 && TREE_CODE (exp
) != ERROR_MARK
5349 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5350 but TARGET is not valid memory reference, TEMP will differ
5351 from TARGET although it is really the same location. */
5353 && rtx_equal_p (alt_rtl
, target
)
5354 && !side_effects_p (alt_rtl
)
5355 && !side_effects_p (target
))
5356 /* If there's nothing to copy, don't bother. Don't call
5357 expr_size unless necessary, because some front-ends (C++)
5358 expr_size-hook must not be given objects that are not
5359 supposed to be bit-copied or bit-initialized. */
5360 && expr_size (exp
) != const0_rtx
)
5362 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5364 if (GET_MODE (target
) == BLKmode
)
5366 /* Handle calls that return BLKmode values in registers. */
5367 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5368 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5370 store_bit_field (target
,
5371 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5372 0, 0, 0, GET_MODE (temp
), temp
);
5375 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5378 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5380 /* Handle copying a string constant into an array. The string
5381 constant may be shorter than the array. So copy just the string's
5382 actual length, and clear the rest. First get the size of the data
5383 type of the string, which is actually the size of the target. */
5384 rtx size
= expr_size (exp
);
5386 if (CONST_INT_P (size
)
5387 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5388 emit_block_move (target
, temp
, size
,
5390 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5393 enum machine_mode pointer_mode
5394 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5395 enum machine_mode address_mode
= get_address_mode (target
);
5397 /* Compute the size of the data to copy from the string. */
5399 = size_binop_loc (loc
, MIN_EXPR
,
5400 make_tree (sizetype
, size
),
5401 size_int (TREE_STRING_LENGTH (exp
)));
5403 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5405 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5408 /* Copy that much. */
5409 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5410 TYPE_UNSIGNED (sizetype
));
5411 emit_block_move (target
, temp
, copy_size_rtx
,
5413 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5415 /* Figure out how much is left in TARGET that we have to clear.
5416 Do all calculations in pointer_mode. */
5417 if (CONST_INT_P (copy_size_rtx
))
5419 size
= plus_constant (address_mode
, size
,
5420 -INTVAL (copy_size_rtx
));
5421 target
= adjust_address (target
, BLKmode
,
5422 INTVAL (copy_size_rtx
));
5426 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5427 copy_size_rtx
, NULL_RTX
, 0,
5430 if (GET_MODE (copy_size_rtx
) != address_mode
)
5431 copy_size_rtx
= convert_to_mode (address_mode
,
5433 TYPE_UNSIGNED (sizetype
));
5435 target
= offset_address (target
, copy_size_rtx
,
5436 highest_pow2_factor (copy_size
));
5437 label
= gen_label_rtx ();
5438 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5439 GET_MODE (size
), 0, label
);
5442 if (size
!= const0_rtx
)
5443 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5449 /* Handle calls that return values in multiple non-contiguous locations.
5450 The Irix 6 ABI has examples of this. */
5451 else if (GET_CODE (target
) == PARALLEL
)
5453 if (GET_CODE (temp
) == PARALLEL
)
5454 emit_group_move (target
, temp
);
5456 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5457 int_size_in_bytes (TREE_TYPE (exp
)));
5459 else if (GET_CODE (temp
) == PARALLEL
)
5460 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5461 int_size_in_bytes (TREE_TYPE (exp
)));
5462 else if (GET_MODE (temp
) == BLKmode
)
5463 emit_block_move (target
, temp
, expr_size (exp
),
5465 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5466 /* If we emit a nontemporal store, there is nothing else to do. */
5467 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5471 temp
= force_operand (temp
, target
);
5473 emit_move_insn (target
, temp
);
5480 /* Return true if field F of structure TYPE is a flexible array. */
5483 flexible_array_member_p (const_tree f
, const_tree type
)
5488 return (DECL_CHAIN (f
) == NULL
5489 && TREE_CODE (tf
) == ARRAY_TYPE
5491 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5492 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5493 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5494 && int_size_in_bytes (type
) >= 0);
5497 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5498 must have in order for it to completely initialize a value of type TYPE.
5499 Return -1 if the number isn't known.
5501 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5503 static HOST_WIDE_INT
5504 count_type_elements (const_tree type
, bool for_ctor_p
)
5506 switch (TREE_CODE (type
))
5512 nelts
= array_type_nelts (type
);
5513 if (nelts
&& tree_fits_uhwi_p (nelts
))
5515 unsigned HOST_WIDE_INT n
;
5517 n
= tree_to_uhwi (nelts
) + 1;
5518 if (n
== 0 || for_ctor_p
)
5521 return n
* count_type_elements (TREE_TYPE (type
), false);
5523 return for_ctor_p
? -1 : 1;
5528 unsigned HOST_WIDE_INT n
;
5532 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5533 if (TREE_CODE (f
) == FIELD_DECL
)
5536 n
+= count_type_elements (TREE_TYPE (f
), false);
5537 else if (!flexible_array_member_p (f
, type
))
5538 /* Don't count flexible arrays, which are not supposed
5539 to be initialized. */
5547 case QUAL_UNION_TYPE
:
5552 gcc_assert (!for_ctor_p
);
5553 /* Estimate the number of scalars in each field and pick the
5554 maximum. Other estimates would do instead; the idea is simply
5555 to make sure that the estimate is not sensitive to the ordering
5558 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5559 if (TREE_CODE (f
) == FIELD_DECL
)
5561 m
= count_type_elements (TREE_TYPE (f
), false);
5562 /* If the field doesn't span the whole union, add an extra
5563 scalar for the rest. */
5564 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5565 TYPE_SIZE (type
)) != 1)
5577 return TYPE_VECTOR_SUBPARTS (type
);
5581 case FIXED_POINT_TYPE
:
5586 case REFERENCE_TYPE
:
5602 /* Helper for categorize_ctor_elements. Identical interface. */
5605 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5606 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5608 unsigned HOST_WIDE_INT idx
;
5609 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5610 tree value
, purpose
, elt_type
;
5612 /* Whether CTOR is a valid constant initializer, in accordance with what
5613 initializer_constant_valid_p does. If inferred from the constructor
5614 elements, true until proven otherwise. */
5615 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5616 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5621 elt_type
= NULL_TREE
;
5623 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5625 HOST_WIDE_INT mult
= 1;
5627 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5629 tree lo_index
= TREE_OPERAND (purpose
, 0);
5630 tree hi_index
= TREE_OPERAND (purpose
, 1);
5632 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5633 mult
= (tree_to_uhwi (hi_index
)
5634 - tree_to_uhwi (lo_index
) + 1);
5637 elt_type
= TREE_TYPE (value
);
5639 switch (TREE_CODE (value
))
5643 HOST_WIDE_INT nz
= 0, ic
= 0;
5645 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5648 nz_elts
+= mult
* nz
;
5649 init_elts
+= mult
* ic
;
5651 if (const_from_elts_p
&& const_p
)
5652 const_p
= const_elt_p
;
5659 if (!initializer_zerop (value
))
5665 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5666 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5670 if (!initializer_zerop (TREE_REALPART (value
)))
5672 if (!initializer_zerop (TREE_IMAGPART (value
)))
5680 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5682 tree v
= VECTOR_CST_ELT (value
, i
);
5683 if (!initializer_zerop (v
))
5692 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5693 nz_elts
+= mult
* tc
;
5694 init_elts
+= mult
* tc
;
5696 if (const_from_elts_p
&& const_p
)
5697 const_p
= initializer_constant_valid_p (value
, elt_type
)
5704 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5705 num_fields
, elt_type
))
5706 *p_complete
= false;
5708 *p_nz_elts
+= nz_elts
;
5709 *p_init_elts
+= init_elts
;
5714 /* Examine CTOR to discover:
5715 * how many scalar fields are set to nonzero values,
5716 and place it in *P_NZ_ELTS;
5717 * how many scalar fields in total are in CTOR,
5718 and place it in *P_ELT_COUNT.
5719 * whether the constructor is complete -- in the sense that every
5720 meaningful byte is explicitly given a value --
5721 and place it in *P_COMPLETE.
5723 Return whether or not CTOR is a valid static constant initializer, the same
5724 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5727 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5728 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5734 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5737 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5738 of which had type LAST_TYPE. Each element was itself a complete
5739 initializer, in the sense that every meaningful byte was explicitly
5740 given a value. Return true if the same is true for the constructor
5744 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5745 const_tree last_type
)
5747 if (TREE_CODE (type
) == UNION_TYPE
5748 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5753 gcc_assert (num_elts
== 1 && last_type
);
5755 /* ??? We could look at each element of the union, and find the
5756 largest element. Which would avoid comparing the size of the
5757 initialized element against any tail padding in the union.
5758 Doesn't seem worth the effort... */
5759 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5762 return count_type_elements (type
, true) == num_elts
;
5765 /* Return 1 if EXP contains mostly (3/4) zeros. */
5768 mostly_zeros_p (const_tree exp
)
5770 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5772 HOST_WIDE_INT nz_elts
, init_elts
;
5775 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5776 return !complete_p
|| nz_elts
< init_elts
/ 4;
5779 return initializer_zerop (exp
);
5782 /* Return 1 if EXP contains all zeros. */
5785 all_zeros_p (const_tree exp
)
5787 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5789 HOST_WIDE_INT nz_elts
, init_elts
;
5792 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5793 return nz_elts
== 0;
5796 return initializer_zerop (exp
);
5799 /* Helper function for store_constructor.
5800 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5801 CLEARED is as for store_constructor.
5802 ALIAS_SET is the alias set to use for any stores.
5804 This provides a recursive shortcut back to store_constructor when it isn't
5805 necessary to go through store_field. This is so that we can pass through
5806 the cleared field to let store_constructor know that we may not have to
5807 clear a substructure if the outer structure has already been cleared. */
5810 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5811 HOST_WIDE_INT bitpos
, enum machine_mode mode
,
5812 tree exp
, int cleared
, alias_set_type alias_set
)
5814 if (TREE_CODE (exp
) == CONSTRUCTOR
5815 /* We can only call store_constructor recursively if the size and
5816 bit position are on a byte boundary. */
5817 && bitpos
% BITS_PER_UNIT
== 0
5818 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5819 /* If we have a nonzero bitpos for a register target, then we just
5820 let store_field do the bitfield handling. This is unlikely to
5821 generate unnecessary clear instructions anyways. */
5822 && (bitpos
== 0 || MEM_P (target
)))
5826 = adjust_address (target
,
5827 GET_MODE (target
) == BLKmode
5829 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5830 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5833 /* Update the alias set, if required. */
5834 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5835 && MEM_ALIAS_SET (target
) != 0)
5837 target
= copy_rtx (target
);
5838 set_mem_alias_set (target
, alias_set
);
5841 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5844 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5848 /* Returns the number of FIELD_DECLs in TYPE. */
5851 fields_length (const_tree type
)
5853 tree t
= TYPE_FIELDS (type
);
5856 for (; t
; t
= DECL_CHAIN (t
))
5857 if (TREE_CODE (t
) == FIELD_DECL
)
5864 /* Store the value of constructor EXP into the rtx TARGET.
5865 TARGET is either a REG or a MEM; we know it cannot conflict, since
5866 safe_from_p has been called.
5867 CLEARED is true if TARGET is known to have been zero'd.
5868 SIZE is the number of bytes of TARGET we are allowed to modify: this
5869 may not be the same as the size of EXP if we are assigning to a field
5870 which has been packed to exclude padding bits. */
5873 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5875 tree type
= TREE_TYPE (exp
);
5876 #ifdef WORD_REGISTER_OPERATIONS
5877 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5880 switch (TREE_CODE (type
))
5884 case QUAL_UNION_TYPE
:
5886 unsigned HOST_WIDE_INT idx
;
5889 /* If size is zero or the target is already cleared, do nothing. */
5890 if (size
== 0 || cleared
)
5892 /* We either clear the aggregate or indicate the value is dead. */
5893 else if ((TREE_CODE (type
) == UNION_TYPE
5894 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5895 && ! CONSTRUCTOR_ELTS (exp
))
5896 /* If the constructor is empty, clear the union. */
5898 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
5902 /* If we are building a static constructor into a register,
5903 set the initial value as zero so we can fold the value into
5904 a constant. But if more than one register is involved,
5905 this probably loses. */
5906 else if (REG_P (target
) && TREE_STATIC (exp
)
5907 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
5909 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5913 /* If the constructor has fewer fields than the structure or
5914 if we are initializing the structure to mostly zeros, clear
5915 the whole structure first. Don't do this if TARGET is a
5916 register whose mode size isn't equal to SIZE since
5917 clear_storage can't handle this case. */
5919 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
5920 != fields_length (type
))
5921 || mostly_zeros_p (exp
))
5923 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
5926 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5930 if (REG_P (target
) && !cleared
)
5931 emit_clobber (target
);
5933 /* Store each element of the constructor into the
5934 corresponding field of TARGET. */
5935 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
5937 enum machine_mode mode
;
5938 HOST_WIDE_INT bitsize
;
5939 HOST_WIDE_INT bitpos
= 0;
5941 rtx to_rtx
= target
;
5943 /* Just ignore missing fields. We cleared the whole
5944 structure, above, if any fields are missing. */
5948 if (cleared
&& initializer_zerop (value
))
5951 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
5952 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
5956 mode
= DECL_MODE (field
);
5957 if (DECL_BIT_FIELD (field
))
5960 offset
= DECL_FIELD_OFFSET (field
);
5961 if (tree_fits_shwi_p (offset
)
5962 && tree_fits_shwi_p (bit_position (field
)))
5964 bitpos
= int_bit_position (field
);
5968 bitpos
= tree_to_shwi (DECL_FIELD_BIT_OFFSET (field
));
5972 enum machine_mode address_mode
;
5976 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
5977 make_tree (TREE_TYPE (exp
),
5980 offset_rtx
= expand_normal (offset
);
5981 gcc_assert (MEM_P (to_rtx
));
5983 address_mode
= get_address_mode (to_rtx
);
5984 if (GET_MODE (offset_rtx
) != address_mode
)
5985 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
5987 to_rtx
= offset_address (to_rtx
, offset_rtx
,
5988 highest_pow2_factor (offset
));
5991 #ifdef WORD_REGISTER_OPERATIONS
5992 /* If this initializes a field that is smaller than a
5993 word, at the start of a word, try to widen it to a full
5994 word. This special case allows us to output C++ member
5995 function initializations in a form that the optimizers
5998 && bitsize
< BITS_PER_WORD
5999 && bitpos
% BITS_PER_WORD
== 0
6000 && GET_MODE_CLASS (mode
) == MODE_INT
6001 && TREE_CODE (value
) == INTEGER_CST
6003 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
6005 tree type
= TREE_TYPE (value
);
6007 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
6009 type
= lang_hooks
.types
.type_for_mode
6010 (word_mode
, TYPE_UNSIGNED (type
));
6011 value
= fold_convert (type
, value
);
6014 if (BYTES_BIG_ENDIAN
)
6016 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6017 build_int_cst (type
,
6018 BITS_PER_WORD
- bitsize
));
6019 bitsize
= BITS_PER_WORD
;
6024 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6025 && DECL_NONADDRESSABLE_P (field
))
6027 to_rtx
= copy_rtx (to_rtx
);
6028 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6031 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
6033 get_alias_set (TREE_TYPE (field
)));
6040 unsigned HOST_WIDE_INT i
;
6043 tree elttype
= TREE_TYPE (type
);
6045 HOST_WIDE_INT minelt
= 0;
6046 HOST_WIDE_INT maxelt
= 0;
6048 domain
= TYPE_DOMAIN (type
);
6049 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6050 && TYPE_MAX_VALUE (domain
)
6051 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6052 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6054 /* If we have constant bounds for the range of the type, get them. */
6057 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6058 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6061 /* If the constructor has fewer elements than the array, clear
6062 the whole array first. Similarly if this is static
6063 constructor of a non-BLKmode object. */
6066 else if (REG_P (target
) && TREE_STATIC (exp
))
6070 unsigned HOST_WIDE_INT idx
;
6072 HOST_WIDE_INT count
= 0, zero_count
= 0;
6073 need_to_clear
= ! const_bounds_p
;
6075 /* This loop is a more accurate version of the loop in
6076 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6077 is also needed to check for missing elements. */
6078 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6080 HOST_WIDE_INT this_node_count
;
6085 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6087 tree lo_index
= TREE_OPERAND (index
, 0);
6088 tree hi_index
= TREE_OPERAND (index
, 1);
6090 if (! tree_fits_uhwi_p (lo_index
)
6091 || ! tree_fits_uhwi_p (hi_index
))
6097 this_node_count
= (tree_to_uhwi (hi_index
)
6098 - tree_to_uhwi (lo_index
) + 1);
6101 this_node_count
= 1;
6103 count
+= this_node_count
;
6104 if (mostly_zeros_p (value
))
6105 zero_count
+= this_node_count
;
6108 /* Clear the entire array first if there are any missing
6109 elements, or if the incidence of zero elements is >=
6112 && (count
< maxelt
- minelt
+ 1
6113 || 4 * zero_count
>= 3 * count
))
6117 if (need_to_clear
&& size
> 0)
6120 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6122 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6126 if (!cleared
&& REG_P (target
))
6127 /* Inform later passes that the old value is dead. */
6128 emit_clobber (target
);
6130 /* Store each element of the constructor into the
6131 corresponding element of TARGET, determined by counting the
6133 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6135 enum machine_mode mode
;
6136 HOST_WIDE_INT bitsize
;
6137 HOST_WIDE_INT bitpos
;
6138 rtx xtarget
= target
;
6140 if (cleared
&& initializer_zerop (value
))
6143 mode
= TYPE_MODE (elttype
);
6144 if (mode
== BLKmode
)
6145 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6146 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6149 bitsize
= GET_MODE_BITSIZE (mode
);
6151 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6153 tree lo_index
= TREE_OPERAND (index
, 0);
6154 tree hi_index
= TREE_OPERAND (index
, 1);
6155 rtx index_r
, pos_rtx
;
6156 HOST_WIDE_INT lo
, hi
, count
;
6159 /* If the range is constant and "small", unroll the loop. */
6161 && tree_fits_shwi_p (lo_index
)
6162 && tree_fits_shwi_p (hi_index
)
6163 && (lo
= tree_to_shwi (lo_index
),
6164 hi
= tree_to_shwi (hi_index
),
6165 count
= hi
- lo
+ 1,
6168 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6169 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6172 lo
-= minelt
; hi
-= minelt
;
6173 for (; lo
<= hi
; lo
++)
6175 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6178 && !MEM_KEEP_ALIAS_SET_P (target
)
6179 && TREE_CODE (type
) == ARRAY_TYPE
6180 && TYPE_NONALIASED_COMPONENT (type
))
6182 target
= copy_rtx (target
);
6183 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6186 store_constructor_field
6187 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6188 get_alias_set (elttype
));
6193 rtx loop_start
= gen_label_rtx ();
6194 rtx loop_end
= gen_label_rtx ();
6197 expand_normal (hi_index
);
6199 index
= build_decl (EXPR_LOCATION (exp
),
6200 VAR_DECL
, NULL_TREE
, domain
);
6201 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6202 SET_DECL_RTL (index
, index_r
);
6203 store_expr (lo_index
, index_r
, 0, false);
6205 /* Build the head of the loop. */
6206 do_pending_stack_adjust ();
6207 emit_label (loop_start
);
6209 /* Assign value to element index. */
6211 fold_convert (ssizetype
,
6212 fold_build2 (MINUS_EXPR
,
6215 TYPE_MIN_VALUE (domain
)));
6218 size_binop (MULT_EXPR
, position
,
6219 fold_convert (ssizetype
,
6220 TYPE_SIZE_UNIT (elttype
)));
6222 pos_rtx
= expand_normal (position
);
6223 xtarget
= offset_address (target
, pos_rtx
,
6224 highest_pow2_factor (position
));
6225 xtarget
= adjust_address (xtarget
, mode
, 0);
6226 if (TREE_CODE (value
) == CONSTRUCTOR
)
6227 store_constructor (value
, xtarget
, cleared
,
6228 bitsize
/ BITS_PER_UNIT
);
6230 store_expr (value
, xtarget
, 0, false);
6232 /* Generate a conditional jump to exit the loop. */
6233 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6235 jumpif (exit_cond
, loop_end
, -1);
6237 /* Update the loop counter, and jump to the head of
6239 expand_assignment (index
,
6240 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6241 index
, integer_one_node
),
6244 emit_jump (loop_start
);
6246 /* Build the end of the loop. */
6247 emit_label (loop_end
);
6250 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6251 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6256 index
= ssize_int (1);
6259 index
= fold_convert (ssizetype
,
6260 fold_build2 (MINUS_EXPR
,
6263 TYPE_MIN_VALUE (domain
)));
6266 size_binop (MULT_EXPR
, index
,
6267 fold_convert (ssizetype
,
6268 TYPE_SIZE_UNIT (elttype
)));
6269 xtarget
= offset_address (target
,
6270 expand_normal (position
),
6271 highest_pow2_factor (position
));
6272 xtarget
= adjust_address (xtarget
, mode
, 0);
6273 store_expr (value
, xtarget
, 0, false);
6278 bitpos
= ((tree_to_shwi (index
) - minelt
)
6279 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6281 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6283 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6284 && TREE_CODE (type
) == ARRAY_TYPE
6285 && TYPE_NONALIASED_COMPONENT (type
))
6287 target
= copy_rtx (target
);
6288 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6290 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6291 cleared
, get_alias_set (elttype
));
6299 unsigned HOST_WIDE_INT idx
;
6300 constructor_elt
*ce
;
6303 int icode
= CODE_FOR_nothing
;
6304 tree elttype
= TREE_TYPE (type
);
6305 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6306 enum machine_mode eltmode
= TYPE_MODE (elttype
);
6307 HOST_WIDE_INT bitsize
;
6308 HOST_WIDE_INT bitpos
;
6309 rtvec vector
= NULL
;
6311 alias_set_type alias
;
6313 gcc_assert (eltmode
!= BLKmode
);
6315 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6316 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6318 enum machine_mode mode
= GET_MODE (target
);
6320 icode
= (int) optab_handler (vec_init_optab
, mode
);
6321 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6322 if (icode
!= CODE_FOR_nothing
)
6326 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6327 if (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
)
6329 icode
= CODE_FOR_nothing
;
6333 if (icode
!= CODE_FOR_nothing
)
6337 vector
= rtvec_alloc (n_elts
);
6338 for (i
= 0; i
< n_elts
; i
++)
6339 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6343 /* If the constructor has fewer elements than the vector,
6344 clear the whole array first. Similarly if this is static
6345 constructor of a non-BLKmode object. */
6348 else if (REG_P (target
) && TREE_STATIC (exp
))
6352 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6355 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6357 int n_elts_here
= tree_to_uhwi
6358 (int_const_binop (TRUNC_DIV_EXPR
,
6359 TYPE_SIZE (TREE_TYPE (value
)),
6360 TYPE_SIZE (elttype
)));
6362 count
+= n_elts_here
;
6363 if (mostly_zeros_p (value
))
6364 zero_count
+= n_elts_here
;
6367 /* Clear the entire vector first if there are any missing elements,
6368 or if the incidence of zero elements is >= 75%. */
6369 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6372 if (need_to_clear
&& size
> 0 && !vector
)
6375 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6377 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6381 /* Inform later passes that the old value is dead. */
6382 if (!cleared
&& !vector
&& REG_P (target
))
6383 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6386 alias
= MEM_ALIAS_SET (target
);
6388 alias
= get_alias_set (elttype
);
6390 /* Store each element of the constructor into the corresponding
6391 element of TARGET, determined by counting the elements. */
6392 for (idx
= 0, i
= 0;
6393 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6394 idx
++, i
+= bitsize
/ elt_size
)
6396 HOST_WIDE_INT eltpos
;
6397 tree value
= ce
->value
;
6399 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6400 if (cleared
&& initializer_zerop (value
))
6404 eltpos
= tree_to_uhwi (ce
->index
);
6410 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6412 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6413 RTVEC_ELT (vector
, eltpos
)
6414 = expand_normal (value
);
6418 enum machine_mode value_mode
=
6419 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6420 ? TYPE_MODE (TREE_TYPE (value
))
6422 bitpos
= eltpos
* elt_size
;
6423 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6424 value
, cleared
, alias
);
6429 emit_insn (GEN_FCN (icode
)
6431 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6440 /* Store the value of EXP (an expression tree)
6441 into a subfield of TARGET which has mode MODE and occupies
6442 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6443 If MODE is VOIDmode, it means that we are storing into a bit-field.
6445 BITREGION_START is bitpos of the first bitfield in this region.
6446 BITREGION_END is the bitpos of the ending bitfield in this region.
6447 These two fields are 0, if the C++ memory model does not apply,
6448 or we are not interested in keeping track of bitfield regions.
6450 Always return const0_rtx unless we have something particular to
6453 ALIAS_SET is the alias set for the destination. This value will
6454 (in general) be different from that for TARGET, since TARGET is a
6455 reference to the containing structure.
6457 If NONTEMPORAL is true, try generating a nontemporal store. */
6460 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6461 unsigned HOST_WIDE_INT bitregion_start
,
6462 unsigned HOST_WIDE_INT bitregion_end
,
6463 enum machine_mode mode
, tree exp
,
6464 alias_set_type alias_set
, bool nontemporal
)
6466 if (TREE_CODE (exp
) == ERROR_MARK
)
6469 /* If we have nothing to store, do nothing unless the expression has
6472 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6474 if (GET_CODE (target
) == CONCAT
)
6476 /* We're storing into a struct containing a single __complex. */
6478 gcc_assert (!bitpos
);
6479 return store_expr (exp
, target
, 0, nontemporal
);
6482 /* If the structure is in a register or if the component
6483 is a bit field, we cannot use addressing to access it.
6484 Use bit-field techniques or SUBREG to store in it. */
6486 if (mode
== VOIDmode
6487 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6488 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6489 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6491 || GET_CODE (target
) == SUBREG
6492 /* If the field isn't aligned enough to store as an ordinary memref,
6493 store it as a bit field. */
6495 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6496 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6497 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6498 || (bitpos
% BITS_PER_UNIT
!= 0)))
6499 || (bitsize
>= 0 && mode
!= BLKmode
6500 && GET_MODE_BITSIZE (mode
) > bitsize
)
6501 /* If the RHS and field are a constant size and the size of the
6502 RHS isn't the same size as the bitfield, we must use bitfield
6505 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6506 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6507 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6508 decl we must use bitfield operations. */
6510 && TREE_CODE (exp
) == MEM_REF
6511 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6512 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6513 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6514 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6519 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6520 implies a mask operation. If the precision is the same size as
6521 the field we're storing into, that mask is redundant. This is
6522 particularly common with bit field assignments generated by the
6524 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6527 tree type
= TREE_TYPE (exp
);
6528 if (INTEGRAL_TYPE_P (type
)
6529 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6530 && bitsize
== TYPE_PRECISION (type
))
6532 tree op
= gimple_assign_rhs1 (nop_def
);
6533 type
= TREE_TYPE (op
);
6534 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6539 temp
= expand_normal (exp
);
6541 /* If BITSIZE is narrower than the size of the type of EXP
6542 we will be narrowing TEMP. Normally, what's wanted are the
6543 low-order bits. However, if EXP's type is a record and this is
6544 big-endian machine, we want the upper BITSIZE bits. */
6545 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6546 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6547 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6548 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6549 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6552 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6553 if (mode
!= VOIDmode
&& mode
!= BLKmode
6554 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6555 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6557 /* If the modes of TEMP and TARGET are both BLKmode, both
6558 must be in memory and BITPOS must be aligned on a byte
6559 boundary. If so, we simply do a block copy. Likewise
6560 for a BLKmode-like TARGET. */
6561 if (GET_MODE (temp
) == BLKmode
6562 && (GET_MODE (target
) == BLKmode
6564 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6565 && (bitpos
% BITS_PER_UNIT
) == 0
6566 && (bitsize
% BITS_PER_UNIT
) == 0)))
6568 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6569 && (bitpos
% BITS_PER_UNIT
) == 0);
6571 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6572 emit_block_move (target
, temp
,
6573 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6580 /* Handle calls that return values in multiple non-contiguous locations.
6581 The Irix 6 ABI has examples of this. */
6582 if (GET_CODE (temp
) == PARALLEL
)
6584 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6586 if (mode
== BLKmode
)
6587 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6588 temp_target
= gen_reg_rtx (mode
);
6589 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6592 else if (mode
== BLKmode
)
6594 /* Handle calls that return BLKmode values in registers. */
6595 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6597 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6598 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6603 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6605 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6606 temp_target
= gen_reg_rtx (mode
);
6608 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6609 temp_target
, mode
, mode
);
6614 /* Store the value in the bitfield. */
6615 store_bit_field (target
, bitsize
, bitpos
,
6616 bitregion_start
, bitregion_end
,
6623 /* Now build a reference to just the desired component. */
6624 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6626 if (to_rtx
== target
)
6627 to_rtx
= copy_rtx (to_rtx
);
6629 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6630 set_mem_alias_set (to_rtx
, alias_set
);
6632 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6636 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6637 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6638 codes and find the ultimate containing object, which we return.
6640 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6641 bit position, and *PUNSIGNEDP to the signedness of the field.
6642 If the position of the field is variable, we store a tree
6643 giving the variable offset (in units) in *POFFSET.
6644 This offset is in addition to the bit position.
6645 If the position is not variable, we store 0 in *POFFSET.
6647 If any of the extraction expressions is volatile,
6648 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6650 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6651 Otherwise, it is a mode that can be used to access the field.
6653 If the field describes a variable-sized object, *PMODE is set to
6654 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6655 this case, but the address of the object can be found. */
6658 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6659 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6660 enum machine_mode
*pmode
, int *punsignedp
,
6664 enum machine_mode mode
= VOIDmode
;
6665 bool blkmode_bitfield
= false;
6666 tree offset
= size_zero_node
;
6667 double_int bit_offset
= double_int_zero
;
6669 /* First get the mode, signedness, and size. We do this from just the
6670 outermost expression. */
6672 if (TREE_CODE (exp
) == COMPONENT_REF
)
6674 tree field
= TREE_OPERAND (exp
, 1);
6675 size_tree
= DECL_SIZE (field
);
6676 if (flag_strict_volatile_bitfields
> 0
6677 && TREE_THIS_VOLATILE (exp
)
6678 && DECL_BIT_FIELD_TYPE (field
)
6679 && DECL_MODE (field
) != BLKmode
)
6680 /* Volatile bitfields should be accessed in the mode of the
6681 field's type, not the mode computed based on the bit
6683 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6684 else if (!DECL_BIT_FIELD (field
))
6685 mode
= DECL_MODE (field
);
6686 else if (DECL_MODE (field
) == BLKmode
)
6687 blkmode_bitfield
= true;
6689 *punsignedp
= DECL_UNSIGNED (field
);
6691 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6693 size_tree
= TREE_OPERAND (exp
, 1);
6694 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6695 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6697 /* For vector types, with the correct size of access, use the mode of
6699 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6700 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6701 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6702 mode
= TYPE_MODE (TREE_TYPE (exp
));
6706 mode
= TYPE_MODE (TREE_TYPE (exp
));
6707 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6709 if (mode
== BLKmode
)
6710 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6712 *pbitsize
= GET_MODE_BITSIZE (mode
);
6717 if (! tree_fits_uhwi_p (size_tree
))
6718 mode
= BLKmode
, *pbitsize
= -1;
6720 *pbitsize
= tree_to_uhwi (size_tree
);
6723 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6724 and find the ultimate containing object. */
6727 switch (TREE_CODE (exp
))
6730 bit_offset
+= tree_to_double_int (TREE_OPERAND (exp
, 2));
6735 tree field
= TREE_OPERAND (exp
, 1);
6736 tree this_offset
= component_ref_field_offset (exp
);
6738 /* If this field hasn't been filled in yet, don't go past it.
6739 This should only happen when folding expressions made during
6740 type construction. */
6741 if (this_offset
== 0)
6744 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6745 bit_offset
+= tree_to_double_int (DECL_FIELD_BIT_OFFSET (field
));
6747 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6752 case ARRAY_RANGE_REF
:
6754 tree index
= TREE_OPERAND (exp
, 1);
6755 tree low_bound
= array_ref_low_bound (exp
);
6756 tree unit_size
= array_ref_element_size (exp
);
6758 /* We assume all arrays have sizes that are a multiple of a byte.
6759 First subtract the lower bound, if any, in the type of the
6760 index, then convert to sizetype and multiply by the size of
6761 the array element. */
6762 if (! integer_zerop (low_bound
))
6763 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6766 offset
= size_binop (PLUS_EXPR
, offset
,
6767 size_binop (MULT_EXPR
,
6768 fold_convert (sizetype
, index
),
6777 bit_offset
+= double_int::from_uhwi (*pbitsize
);
6780 case VIEW_CONVERT_EXPR
:
6784 /* Hand back the decl for MEM[&decl, off]. */
6785 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6787 tree off
= TREE_OPERAND (exp
, 1);
6788 if (!integer_zerop (off
))
6790 double_int boff
, coff
= mem_ref_offset (exp
);
6791 boff
= coff
.lshift (BITS_PER_UNIT
== 8
6792 ? 3 : exact_log2 (BITS_PER_UNIT
));
6795 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6803 /* If any reference in the chain is volatile, the effect is volatile. */
6804 if (TREE_THIS_VOLATILE (exp
))
6807 exp
= TREE_OPERAND (exp
, 0);
6811 /* If OFFSET is constant, see if we can return the whole thing as a
6812 constant bit position. Make sure to handle overflow during
6814 if (TREE_CODE (offset
) == INTEGER_CST
)
6816 double_int tem
= tree_to_double_int (offset
);
6817 tem
= tem
.sext (TYPE_PRECISION (sizetype
));
6818 tem
= tem
.lshift (BITS_PER_UNIT
== 8 ? 3 : exact_log2 (BITS_PER_UNIT
));
6820 if (tem
.fits_shwi ())
6822 *pbitpos
= tem
.to_shwi ();
6823 *poffset
= offset
= NULL_TREE
;
6827 /* Otherwise, split it up. */
6830 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6831 if (bit_offset
.is_negative ())
6834 = double_int::mask (BITS_PER_UNIT
== 8
6835 ? 3 : exact_log2 (BITS_PER_UNIT
));
6836 double_int tem
= bit_offset
.and_not (mask
);
6837 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6838 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6840 tem
= tem
.arshift (BITS_PER_UNIT
== 8
6841 ? 3 : exact_log2 (BITS_PER_UNIT
),
6842 HOST_BITS_PER_DOUBLE_INT
);
6843 offset
= size_binop (PLUS_EXPR
, offset
,
6844 double_int_to_tree (sizetype
, tem
));
6847 *pbitpos
= bit_offset
.to_shwi ();
6851 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6852 if (mode
== VOIDmode
6854 && (*pbitpos
% BITS_PER_UNIT
) == 0
6855 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6863 /* Return a tree of sizetype representing the size, in bytes, of the element
6864 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6867 array_ref_element_size (tree exp
)
6869 tree aligned_size
= TREE_OPERAND (exp
, 3);
6870 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6871 location_t loc
= EXPR_LOCATION (exp
);
6873 /* If a size was specified in the ARRAY_REF, it's the size measured
6874 in alignment units of the element type. So multiply by that value. */
6877 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6878 sizetype from another type of the same width and signedness. */
6879 if (TREE_TYPE (aligned_size
) != sizetype
)
6880 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
6881 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
6882 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
6885 /* Otherwise, take the size from that of the element type. Substitute
6886 any PLACEHOLDER_EXPR that we have. */
6888 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
6891 /* Return a tree representing the lower bound of the array mentioned in
6892 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6895 array_ref_low_bound (tree exp
)
6897 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6899 /* If a lower bound is specified in EXP, use it. */
6900 if (TREE_OPERAND (exp
, 2))
6901 return TREE_OPERAND (exp
, 2);
6903 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6904 substituting for a PLACEHOLDER_EXPR as needed. */
6905 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
6906 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
6908 /* Otherwise, return a zero of the appropriate type. */
6909 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
6912 /* Returns true if REF is an array reference to an array at the end of
6913 a structure. If this is the case, the array may be allocated larger
6914 than its upper bound implies. */
6917 array_at_struct_end_p (tree ref
)
6919 if (TREE_CODE (ref
) != ARRAY_REF
6920 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
6923 while (handled_component_p (ref
))
6925 /* If the reference chain contains a component reference to a
6926 non-union type and there follows another field the reference
6927 is not at the end of a structure. */
6928 if (TREE_CODE (ref
) == COMPONENT_REF
6929 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
6931 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
6932 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
6933 nextf
= DECL_CHAIN (nextf
);
6938 ref
= TREE_OPERAND (ref
, 0);
6941 /* If the reference is based on a declared entity, the size of the array
6942 is constrained by its given domain. */
6949 /* Return a tree representing the upper bound of the array mentioned in
6950 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6953 array_ref_up_bound (tree exp
)
6955 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6957 /* If there is a domain type and it has an upper bound, use it, substituting
6958 for a PLACEHOLDER_EXPR as needed. */
6959 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
6960 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
6962 /* Otherwise fail. */
6966 /* Return a tree representing the offset, in bytes, of the field referenced
6967 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6970 component_ref_field_offset (tree exp
)
6972 tree aligned_offset
= TREE_OPERAND (exp
, 2);
6973 tree field
= TREE_OPERAND (exp
, 1);
6974 location_t loc
= EXPR_LOCATION (exp
);
6976 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6977 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6981 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6982 sizetype from another type of the same width and signedness. */
6983 if (TREE_TYPE (aligned_offset
) != sizetype
)
6984 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
6985 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
6986 size_int (DECL_OFFSET_ALIGN (field
)
6990 /* Otherwise, take the offset from that of the field. Substitute
6991 any PLACEHOLDER_EXPR that we have. */
6993 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
6996 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6998 static unsigned HOST_WIDE_INT
6999 target_align (const_tree target
)
7001 /* We might have a chain of nested references with intermediate misaligning
7002 bitfields components, so need to recurse to find out. */
7004 unsigned HOST_WIDE_INT this_align
, outer_align
;
7006 switch (TREE_CODE (target
))
7012 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7013 outer_align
= target_align (TREE_OPERAND (target
, 0));
7014 return MIN (this_align
, outer_align
);
7017 case ARRAY_RANGE_REF
:
7018 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7019 outer_align
= target_align (TREE_OPERAND (target
, 0));
7020 return MIN (this_align
, outer_align
);
7023 case NON_LVALUE_EXPR
:
7024 case VIEW_CONVERT_EXPR
:
7025 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7026 outer_align
= target_align (TREE_OPERAND (target
, 0));
7027 return MAX (this_align
, outer_align
);
7030 return TYPE_ALIGN (TREE_TYPE (target
));
7035 /* Given an rtx VALUE that may contain additions and multiplications, return
7036 an equivalent value that just refers to a register, memory, or constant.
7037 This is done by generating instructions to perform the arithmetic and
7038 returning a pseudo-register containing the value.
7040 The returned value may be a REG, SUBREG, MEM or constant. */
7043 force_operand (rtx value
, rtx target
)
7046 /* Use subtarget as the target for operand 0 of a binary operation. */
7047 rtx subtarget
= get_subtarget (target
);
7048 enum rtx_code code
= GET_CODE (value
);
7050 /* Check for subreg applied to an expression produced by loop optimizer. */
7052 && !REG_P (SUBREG_REG (value
))
7053 && !MEM_P (SUBREG_REG (value
)))
7056 = simplify_gen_subreg (GET_MODE (value
),
7057 force_reg (GET_MODE (SUBREG_REG (value
)),
7058 force_operand (SUBREG_REG (value
),
7060 GET_MODE (SUBREG_REG (value
)),
7061 SUBREG_BYTE (value
));
7062 code
= GET_CODE (value
);
7065 /* Check for a PIC address load. */
7066 if ((code
== PLUS
|| code
== MINUS
)
7067 && XEXP (value
, 0) == pic_offset_table_rtx
7068 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7069 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7070 || GET_CODE (XEXP (value
, 1)) == CONST
))
7073 subtarget
= gen_reg_rtx (GET_MODE (value
));
7074 emit_move_insn (subtarget
, value
);
7078 if (ARITHMETIC_P (value
))
7080 op2
= XEXP (value
, 1);
7081 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7083 if (code
== MINUS
&& CONST_INT_P (op2
))
7086 op2
= negate_rtx (GET_MODE (value
), op2
);
7089 /* Check for an addition with OP2 a constant integer and our first
7090 operand a PLUS of a virtual register and something else. In that
7091 case, we want to emit the sum of the virtual register and the
7092 constant first and then add the other value. This allows virtual
7093 register instantiation to simply modify the constant rather than
7094 creating another one around this addition. */
7095 if (code
== PLUS
&& CONST_INT_P (op2
)
7096 && GET_CODE (XEXP (value
, 0)) == PLUS
7097 && REG_P (XEXP (XEXP (value
, 0), 0))
7098 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7099 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7101 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7102 XEXP (XEXP (value
, 0), 0), op2
,
7103 subtarget
, 0, OPTAB_LIB_WIDEN
);
7104 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7105 force_operand (XEXP (XEXP (value
,
7107 target
, 0, OPTAB_LIB_WIDEN
);
7110 op1
= force_operand (XEXP (value
, 0), subtarget
);
7111 op2
= force_operand (op2
, NULL_RTX
);
7115 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7117 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7118 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7119 target
, 1, OPTAB_LIB_WIDEN
);
7121 return expand_divmod (0,
7122 FLOAT_MODE_P (GET_MODE (value
))
7123 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7124 GET_MODE (value
), op1
, op2
, target
, 0);
7126 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7129 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7132 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7135 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7136 target
, 0, OPTAB_LIB_WIDEN
);
7138 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7139 target
, 1, OPTAB_LIB_WIDEN
);
7142 if (UNARY_P (value
))
7145 target
= gen_reg_rtx (GET_MODE (value
));
7146 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7153 case FLOAT_TRUNCATE
:
7154 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7159 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7163 case UNSIGNED_FLOAT
:
7164 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7168 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7172 #ifdef INSN_SCHEDULING
7173 /* On machines that have insn scheduling, we want all memory reference to be
7174 explicit, so we need to deal with such paradoxical SUBREGs. */
7175 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7177 = simplify_gen_subreg (GET_MODE (value
),
7178 force_reg (GET_MODE (SUBREG_REG (value
)),
7179 force_operand (SUBREG_REG (value
),
7181 GET_MODE (SUBREG_REG (value
)),
7182 SUBREG_BYTE (value
));
7188 /* Subroutine of expand_expr: return nonzero iff there is no way that
7189 EXP can reference X, which is being modified. TOP_P is nonzero if this
7190 call is going to be used to determine whether we need a temporary
7191 for EXP, as opposed to a recursive call to this function.
7193 It is always safe for this routine to return zero since it merely
7194 searches for optimization opportunities. */
7197 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7203 /* If EXP has varying size, we MUST use a target since we currently
7204 have no way of allocating temporaries of variable size
7205 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7206 So we assume here that something at a higher level has prevented a
7207 clash. This is somewhat bogus, but the best we can do. Only
7208 do this when X is BLKmode and when we are at the top level. */
7209 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7210 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7211 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7212 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7213 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7215 && GET_MODE (x
) == BLKmode
)
7216 /* If X is in the outgoing argument area, it is always safe. */
7218 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7219 || (GET_CODE (XEXP (x
, 0)) == PLUS
7220 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7223 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7224 find the underlying pseudo. */
7225 if (GET_CODE (x
) == SUBREG
)
7228 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7232 /* Now look at our tree code and possibly recurse. */
7233 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7235 case tcc_declaration
:
7236 exp_rtl
= DECL_RTL_IF_SET (exp
);
7242 case tcc_exceptional
:
7243 if (TREE_CODE (exp
) == TREE_LIST
)
7247 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7249 exp
= TREE_CHAIN (exp
);
7252 if (TREE_CODE (exp
) != TREE_LIST
)
7253 return safe_from_p (x
, exp
, 0);
7256 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7258 constructor_elt
*ce
;
7259 unsigned HOST_WIDE_INT idx
;
7261 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7262 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7263 || !safe_from_p (x
, ce
->value
, 0))
7267 else if (TREE_CODE (exp
) == ERROR_MARK
)
7268 return 1; /* An already-visited SAVE_EXPR? */
7273 /* The only case we look at here is the DECL_INITIAL inside a
7275 return (TREE_CODE (exp
) != DECL_EXPR
7276 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7277 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7278 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7281 case tcc_comparison
:
7282 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7287 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7289 case tcc_expression
:
7292 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7293 the expression. If it is set, we conflict iff we are that rtx or
7294 both are in memory. Otherwise, we check all operands of the
7295 expression recursively. */
7297 switch (TREE_CODE (exp
))
7300 /* If the operand is static or we are static, we can't conflict.
7301 Likewise if we don't conflict with the operand at all. */
7302 if (staticp (TREE_OPERAND (exp
, 0))
7303 || TREE_STATIC (exp
)
7304 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7307 /* Otherwise, the only way this can conflict is if we are taking
7308 the address of a DECL a that address if part of X, which is
7310 exp
= TREE_OPERAND (exp
, 0);
7313 if (!DECL_RTL_SET_P (exp
)
7314 || !MEM_P (DECL_RTL (exp
)))
7317 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7323 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7324 get_alias_set (exp
)))
7329 /* Assume that the call will clobber all hard registers and
7331 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7336 case WITH_CLEANUP_EXPR
:
7337 case CLEANUP_POINT_EXPR
:
7338 /* Lowered by gimplify.c. */
7342 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7348 /* If we have an rtx, we do not need to scan our operands. */
7352 nops
= TREE_OPERAND_LENGTH (exp
);
7353 for (i
= 0; i
< nops
; i
++)
7354 if (TREE_OPERAND (exp
, i
) != 0
7355 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7361 /* Should never get a type here. */
7365 /* If we have an rtl, find any enclosed object. Then see if we conflict
7369 if (GET_CODE (exp_rtl
) == SUBREG
)
7371 exp_rtl
= SUBREG_REG (exp_rtl
);
7373 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7377 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7378 are memory and they conflict. */
7379 return ! (rtx_equal_p (x
, exp_rtl
)
7380 || (MEM_P (x
) && MEM_P (exp_rtl
)
7381 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7384 /* If we reach here, it is safe. */
7389 /* Return the highest power of two that EXP is known to be a multiple of.
7390 This is used in updating alignment of MEMs in array references. */
7392 unsigned HOST_WIDE_INT
7393 highest_pow2_factor (const_tree exp
)
7395 unsigned HOST_WIDE_INT ret
;
7396 int trailing_zeros
= tree_ctz (exp
);
7397 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7398 return BIGGEST_ALIGNMENT
;
7399 ret
= (unsigned HOST_WIDE_INT
) 1 << trailing_zeros
;
7400 if (ret
> BIGGEST_ALIGNMENT
)
7401 return BIGGEST_ALIGNMENT
;
7405 /* Similar, except that the alignment requirements of TARGET are
7406 taken into account. Assume it is at least as aligned as its
7407 type, unless it is a COMPONENT_REF in which case the layout of
7408 the structure gives the alignment. */
7410 static unsigned HOST_WIDE_INT
7411 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7413 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7414 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7416 return MAX (factor
, talign
);
7419 #ifdef HAVE_conditional_move
7420 /* Convert the tree comparison code TCODE to the rtl one where the
7421 signedness is UNSIGNEDP. */
7423 static enum rtx_code
7424 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7436 code
= unsignedp
? LTU
: LT
;
7439 code
= unsignedp
? LEU
: LE
;
7442 code
= unsignedp
? GTU
: GT
;
7445 code
= unsignedp
? GEU
: GE
;
7447 case UNORDERED_EXPR
:
7479 /* Subroutine of expand_expr. Expand the two operands of a binary
7480 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7481 The value may be stored in TARGET if TARGET is nonzero. The
7482 MODIFIER argument is as documented by expand_expr. */
7485 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7486 enum expand_modifier modifier
)
7488 if (! safe_from_p (target
, exp1
, 1))
7490 if (operand_equal_p (exp0
, exp1
, 0))
7492 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7493 *op1
= copy_rtx (*op0
);
7497 /* If we need to preserve evaluation order, copy exp0 into its own
7498 temporary variable so that it can't be clobbered by exp1. */
7499 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7500 exp0
= save_expr (exp0
);
7501 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7502 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7507 /* Return a MEM that contains constant EXP. DEFER is as for
7508 output_constant_def and MODIFIER is as for expand_expr. */
7511 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7515 mem
= output_constant_def (exp
, defer
);
7516 if (modifier
!= EXPAND_INITIALIZER
)
7517 mem
= use_anchored_address (mem
);
7521 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7522 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7525 expand_expr_addr_expr_1 (tree exp
, rtx target
, enum machine_mode tmode
,
7526 enum expand_modifier modifier
, addr_space_t as
)
7528 rtx result
, subtarget
;
7530 HOST_WIDE_INT bitsize
, bitpos
;
7531 int volatilep
, unsignedp
;
7532 enum machine_mode mode1
;
7534 /* If we are taking the address of a constant and are at the top level,
7535 we have to use output_constant_def since we can't call force_const_mem
7537 /* ??? This should be considered a front-end bug. We should not be
7538 generating ADDR_EXPR of something that isn't an LVALUE. The only
7539 exception here is STRING_CST. */
7540 if (CONSTANT_CLASS_P (exp
))
7542 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7543 if (modifier
< EXPAND_SUM
)
7544 result
= force_operand (result
, target
);
7548 /* Everything must be something allowed by is_gimple_addressable. */
7549 switch (TREE_CODE (exp
))
7552 /* This case will happen via recursion for &a->b. */
7553 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7557 tree tem
= TREE_OPERAND (exp
, 0);
7558 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7559 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7560 return expand_expr (tem
, target
, tmode
, modifier
);
7564 /* Expand the initializer like constants above. */
7565 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7567 if (modifier
< EXPAND_SUM
)
7568 result
= force_operand (result
, target
);
7572 /* The real part of the complex number is always first, therefore
7573 the address is the same as the address of the parent object. */
7576 inner
= TREE_OPERAND (exp
, 0);
7580 /* The imaginary part of the complex number is always second.
7581 The expression is therefore always offset by the size of the
7584 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7585 inner
= TREE_OPERAND (exp
, 0);
7588 case COMPOUND_LITERAL_EXPR
:
7589 /* Allow COMPOUND_LITERAL_EXPR in initializers, if e.g.
7590 rtl_for_decl_init is called on DECL_INITIAL with
7591 COMPOUNT_LITERAL_EXPRs in it, they aren't gimplified. */
7592 if (modifier
== EXPAND_INITIALIZER
7593 && COMPOUND_LITERAL_EXPR_DECL (exp
))
7594 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7595 target
, tmode
, modifier
, as
);
7598 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7599 expand_expr, as that can have various side effects; LABEL_DECLs for
7600 example, may not have their DECL_RTL set yet. Expand the rtl of
7601 CONSTRUCTORs too, which should yield a memory reference for the
7602 constructor's contents. Assume language specific tree nodes can
7603 be expanded in some interesting way. */
7604 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7606 || TREE_CODE (exp
) == CONSTRUCTOR
7607 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7609 result
= expand_expr (exp
, target
, tmode
,
7610 modifier
== EXPAND_INITIALIZER
7611 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7613 /* If the DECL isn't in memory, then the DECL wasn't properly
7614 marked TREE_ADDRESSABLE, which will be either a front-end
7615 or a tree optimizer bug. */
7617 if (TREE_ADDRESSABLE (exp
)
7619 && ! targetm
.calls
.allocate_stack_slots_for_args ())
7621 error ("local frame unavailable (naked function?)");
7625 gcc_assert (MEM_P (result
));
7626 result
= XEXP (result
, 0);
7628 /* ??? Is this needed anymore? */
7630 TREE_USED (exp
) = 1;
7632 if (modifier
!= EXPAND_INITIALIZER
7633 && modifier
!= EXPAND_CONST_ADDRESS
7634 && modifier
!= EXPAND_SUM
)
7635 result
= force_operand (result
, target
);
7639 /* Pass FALSE as the last argument to get_inner_reference although
7640 we are expanding to RTL. The rationale is that we know how to
7641 handle "aligning nodes" here: we can just bypass them because
7642 they won't change the final object whose address will be returned
7643 (they actually exist only for that purpose). */
7644 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7645 &mode1
, &unsignedp
, &volatilep
);
7649 /* We must have made progress. */
7650 gcc_assert (inner
!= exp
);
7652 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7653 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7654 inner alignment, force the inner to be sufficiently aligned. */
7655 if (CONSTANT_CLASS_P (inner
)
7656 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7658 inner
= copy_node (inner
);
7659 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7660 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7661 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7663 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7669 if (modifier
!= EXPAND_NORMAL
)
7670 result
= force_operand (result
, NULL
);
7671 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7672 modifier
== EXPAND_INITIALIZER
7673 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7675 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7676 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7678 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7679 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7682 subtarget
= bitpos
? NULL_RTX
: target
;
7683 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7684 1, OPTAB_LIB_WIDEN
);
7690 /* Someone beforehand should have rejected taking the address
7691 of such an object. */
7692 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7694 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7695 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7696 if (modifier
< EXPAND_SUM
)
7697 result
= force_operand (result
, target
);
7703 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7704 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7707 expand_expr_addr_expr (tree exp
, rtx target
, enum machine_mode tmode
,
7708 enum expand_modifier modifier
)
7710 addr_space_t as
= ADDR_SPACE_GENERIC
;
7711 enum machine_mode address_mode
= Pmode
;
7712 enum machine_mode pointer_mode
= ptr_mode
;
7713 enum machine_mode rmode
;
7716 /* Target mode of VOIDmode says "whatever's natural". */
7717 if (tmode
== VOIDmode
)
7718 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7720 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7722 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7723 address_mode
= targetm
.addr_space
.address_mode (as
);
7724 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7727 /* We can get called with some Weird Things if the user does silliness
7728 like "(short) &a". In that case, convert_memory_address won't do
7729 the right thing, so ignore the given target mode. */
7730 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7731 tmode
= address_mode
;
7733 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7734 tmode
, modifier
, as
);
7736 /* Despite expand_expr claims concerning ignoring TMODE when not
7737 strictly convenient, stuff breaks if we don't honor it. Note
7738 that combined with the above, we only do this for pointer modes. */
7739 rmode
= GET_MODE (result
);
7740 if (rmode
== VOIDmode
)
7743 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7748 /* Generate code for computing CONSTRUCTOR EXP.
7749 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7750 is TRUE, instead of creating a temporary variable in memory
7751 NULL is returned and the caller needs to handle it differently. */
7754 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7755 bool avoid_temp_mem
)
7757 tree type
= TREE_TYPE (exp
);
7758 enum machine_mode mode
= TYPE_MODE (type
);
7760 /* Try to avoid creating a temporary at all. This is possible
7761 if all of the initializer is zero.
7762 FIXME: try to handle all [0..255] initializers we can handle
7764 if (TREE_STATIC (exp
)
7765 && !TREE_ADDRESSABLE (exp
)
7766 && target
!= 0 && mode
== BLKmode
7767 && all_zeros_p (exp
))
7769 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7773 /* All elts simple constants => refer to a constant in memory. But
7774 if this is a non-BLKmode mode, let it store a field at a time
7775 since that should make a CONST_INT or CONST_DOUBLE when we
7776 fold. Likewise, if we have a target we can use, it is best to
7777 store directly into the target unless the type is large enough
7778 that memcpy will be used. If we are making an initializer and
7779 all operands are constant, put it in memory as well.
7781 FIXME: Avoid trying to fill vector constructors piece-meal.
7782 Output them with output_constant_def below unless we're sure
7783 they're zeros. This should go away when vector initializers
7784 are treated like VECTOR_CST instead of arrays. */
7785 if ((TREE_STATIC (exp
)
7786 && ((mode
== BLKmode
7787 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7788 || TREE_ADDRESSABLE (exp
)
7789 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7790 && (! MOVE_BY_PIECES_P
7791 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7793 && ! mostly_zeros_p (exp
))))
7794 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7795 && TREE_CONSTANT (exp
)))
7802 constructor
= expand_expr_constant (exp
, 1, modifier
);
7804 if (modifier
!= EXPAND_CONST_ADDRESS
7805 && modifier
!= EXPAND_INITIALIZER
7806 && modifier
!= EXPAND_SUM
)
7807 constructor
= validize_mem (constructor
);
7812 /* Handle calls that pass values in multiple non-contiguous
7813 locations. The Irix 6 ABI has examples of this. */
7814 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7815 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7821 = assign_temp (build_qualified_type (type
, (TYPE_QUALS (type
)
7822 | (TREE_READONLY (exp
)
7823 * TYPE_QUAL_CONST
))),
7824 TREE_ADDRESSABLE (exp
), 1);
7827 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7832 /* expand_expr: generate code for computing expression EXP.
7833 An rtx for the computed value is returned. The value is never null.
7834 In the case of a void EXP, const0_rtx is returned.
7836 The value may be stored in TARGET if TARGET is nonzero.
7837 TARGET is just a suggestion; callers must assume that
7838 the rtx returned may not be the same as TARGET.
7840 If TARGET is CONST0_RTX, it means that the value will be ignored.
7842 If TMODE is not VOIDmode, it suggests generating the
7843 result in mode TMODE. But this is done only when convenient.
7844 Otherwise, TMODE is ignored and the value generated in its natural mode.
7845 TMODE is just a suggestion; callers must assume that
7846 the rtx returned may not have mode TMODE.
7848 Note that TARGET may have neither TMODE nor MODE. In that case, it
7849 probably will not be used.
7851 If MODIFIER is EXPAND_SUM then when EXP is an addition
7852 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7853 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7854 products as above, or REG or MEM, or constant.
7855 Ordinarily in such cases we would output mul or add instructions
7856 and then return a pseudo reg containing the sum.
7858 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7859 it also marks a label as absolutely required (it can't be dead).
7860 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7861 This is used for outputting expressions used in initializers.
7863 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7864 with a constant address even if that address is not normally legitimate.
7865 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7867 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7868 a call parameter. Such targets require special care as we haven't yet
7869 marked TARGET so that it's safe from being trashed by libcalls. We
7870 don't want to use TARGET for anything but the final result;
7871 Intermediate values must go elsewhere. Additionally, calls to
7872 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7874 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7875 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7876 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7877 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7881 expand_expr_real (tree exp
, rtx target
, enum machine_mode tmode
,
7882 enum expand_modifier modifier
, rtx
*alt_rtl
)
7886 /* Handle ERROR_MARK before anybody tries to access its type. */
7887 if (TREE_CODE (exp
) == ERROR_MARK
7888 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7890 ret
= CONST0_RTX (tmode
);
7891 return ret
? ret
: const0_rtx
;
7894 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
7898 /* Try to expand the conditional expression which is represented by
7899 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7900 return the rtl reg which repsents the result. Otherwise return
7904 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7905 tree treeop1 ATTRIBUTE_UNUSED
,
7906 tree treeop2 ATTRIBUTE_UNUSED
)
7908 #ifdef HAVE_conditional_move
7910 rtx op00
, op01
, op1
, op2
;
7911 enum rtx_code comparison_code
;
7912 enum machine_mode comparison_mode
;
7915 tree type
= TREE_TYPE (treeop1
);
7916 int unsignedp
= TYPE_UNSIGNED (type
);
7917 enum machine_mode mode
= TYPE_MODE (type
);
7918 enum machine_mode orig_mode
= mode
;
7920 /* If we cannot do a conditional move on the mode, try doing it
7921 with the promoted mode. */
7922 if (!can_conditionally_move_p (mode
))
7924 mode
= promote_mode (type
, mode
, &unsignedp
);
7925 if (!can_conditionally_move_p (mode
))
7927 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7930 temp
= assign_temp (type
, 0, 1);
7933 expand_operands (treeop1
, treeop2
,
7934 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7936 if (TREE_CODE (treeop0
) == SSA_NAME
7937 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7939 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7940 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7941 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7942 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7943 comparison_mode
= TYPE_MODE (type
);
7944 unsignedp
= TYPE_UNSIGNED (type
);
7945 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7947 else if (TREE_CODE_CLASS (TREE_CODE (treeop0
)) == tcc_comparison
)
7949 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7950 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7951 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7952 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7953 unsignedp
= TYPE_UNSIGNED (type
);
7954 comparison_mode
= TYPE_MODE (type
);
7955 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7959 op00
= expand_normal (treeop0
);
7961 comparison_code
= NE
;
7962 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7965 if (GET_MODE (op1
) != mode
)
7966 op1
= gen_lowpart (mode
, op1
);
7968 if (GET_MODE (op2
) != mode
)
7969 op2
= gen_lowpart (mode
, op2
);
7971 /* Try to emit the conditional move. */
7972 insn
= emit_conditional_move (temp
, comparison_code
,
7973 op00
, op01
, comparison_mode
,
7977 /* If we could do the conditional move, emit the sequence,
7981 rtx seq
= get_insns ();
7984 return convert_modes (orig_mode
, mode
, temp
, 0);
7987 /* Otherwise discard the sequence and fall back to code with
7995 expand_expr_real_2 (sepops ops
, rtx target
, enum machine_mode tmode
,
7996 enum expand_modifier modifier
)
7998 rtx op0
, op1
, op2
, temp
;
8001 enum machine_mode mode
;
8002 enum tree_code code
= ops
->code
;
8004 rtx subtarget
, original_target
;
8006 bool reduce_bit_field
;
8007 location_t loc
= ops
->location
;
8008 tree treeop0
, treeop1
, treeop2
;
8009 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8010 ? reduce_to_bit_field_precision ((expr), \
8016 mode
= TYPE_MODE (type
);
8017 unsignedp
= TYPE_UNSIGNED (type
);
8023 /* We should be called only on simple (binary or unary) expressions,
8024 exactly those that are valid in gimple expressions that aren't
8025 GIMPLE_SINGLE_RHS (or invalid). */
8026 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8027 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8028 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8030 ignore
= (target
== const0_rtx
8031 || ((CONVERT_EXPR_CODE_P (code
)
8032 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8033 && TREE_CODE (type
) == VOID_TYPE
));
8035 /* We should be called only if we need the result. */
8036 gcc_assert (!ignore
);
8038 /* An operation in what may be a bit-field type needs the
8039 result to be reduced to the precision of the bit-field type,
8040 which is narrower than that of the type's mode. */
8041 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8042 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8044 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8047 /* Use subtarget as the target for operand 0 of a binary operation. */
8048 subtarget
= get_subtarget (target
);
8049 original_target
= target
;
8053 case NON_LVALUE_EXPR
:
8056 if (treeop0
== error_mark_node
)
8059 if (TREE_CODE (type
) == UNION_TYPE
)
8061 tree valtype
= TREE_TYPE (treeop0
);
8063 /* If both input and output are BLKmode, this conversion isn't doing
8064 anything except possibly changing memory attribute. */
8065 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8067 rtx result
= expand_expr (treeop0
, target
, tmode
,
8070 result
= copy_rtx (result
);
8071 set_mem_attributes (result
, type
, 0);
8077 if (TYPE_MODE (type
) != BLKmode
)
8078 target
= gen_reg_rtx (TYPE_MODE (type
));
8080 target
= assign_temp (type
, 1, 1);
8084 /* Store data into beginning of memory target. */
8085 store_expr (treeop0
,
8086 adjust_address (target
, TYPE_MODE (valtype
), 0),
8087 modifier
== EXPAND_STACK_PARM
,
8092 gcc_assert (REG_P (target
));
8094 /* Store this field into a union of the proper type. */
8095 store_field (target
,
8096 MIN ((int_size_in_bytes (TREE_TYPE
8099 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8100 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8103 /* Return the entire union. */
8107 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8109 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8112 /* If the signedness of the conversion differs and OP0 is
8113 a promoted SUBREG, clear that indication since we now
8114 have to do the proper extension. */
8115 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8116 && GET_CODE (op0
) == SUBREG
)
8117 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8119 return REDUCE_BIT_FIELD (op0
);
8122 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8123 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8124 if (GET_MODE (op0
) == mode
)
8127 /* If OP0 is a constant, just convert it into the proper mode. */
8128 else if (CONSTANT_P (op0
))
8130 tree inner_type
= TREE_TYPE (treeop0
);
8131 enum machine_mode inner_mode
= GET_MODE (op0
);
8133 if (inner_mode
== VOIDmode
)
8134 inner_mode
= TYPE_MODE (inner_type
);
8136 if (modifier
== EXPAND_INITIALIZER
)
8137 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
8138 subreg_lowpart_offset (mode
,
8141 op0
= convert_modes (mode
, inner_mode
, op0
,
8142 TYPE_UNSIGNED (inner_type
));
8145 else if (modifier
== EXPAND_INITIALIZER
)
8146 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8148 else if (target
== 0)
8149 op0
= convert_to_mode (mode
, op0
,
8150 TYPE_UNSIGNED (TREE_TYPE
8154 convert_move (target
, op0
,
8155 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8159 return REDUCE_BIT_FIELD (op0
);
8161 case ADDR_SPACE_CONVERT_EXPR
:
8163 tree treeop0_type
= TREE_TYPE (treeop0
);
8165 addr_space_t as_from
;
8167 gcc_assert (POINTER_TYPE_P (type
));
8168 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8170 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8171 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8173 /* Conversions between pointers to the same address space should
8174 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8175 gcc_assert (as_to
!= as_from
);
8177 /* Ask target code to handle conversion between pointers
8178 to overlapping address spaces. */
8179 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8180 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8182 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8183 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8188 /* For disjoint address spaces, converting anything but
8189 a null pointer invokes undefined behaviour. We simply
8190 always return a null pointer here. */
8191 return CONST0_RTX (mode
);
8194 case POINTER_PLUS_EXPR
:
8195 /* Even though the sizetype mode and the pointer's mode can be different
8196 expand is able to handle this correctly and get the correct result out
8197 of the PLUS_EXPR code. */
8198 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8199 if sizetype precision is smaller than pointer precision. */
8200 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8201 treeop1
= fold_convert_loc (loc
, type
,
8202 fold_convert_loc (loc
, ssizetype
,
8204 /* If sizetype precision is larger than pointer precision, truncate the
8205 offset to have matching modes. */
8206 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8207 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8210 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8211 something else, make sure we add the register to the constant and
8212 then to the other thing. This case can occur during strength
8213 reduction and doing it this way will produce better code if the
8214 frame pointer or argument pointer is eliminated.
8216 fold-const.c will ensure that the constant is always in the inner
8217 PLUS_EXPR, so the only case we need to do anything about is if
8218 sp, ap, or fp is our second argument, in which case we must swap
8219 the innermost first argument and our second argument. */
8221 if (TREE_CODE (treeop0
) == PLUS_EXPR
8222 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8223 && TREE_CODE (treeop1
) == VAR_DECL
8224 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8225 || DECL_RTL (treeop1
) == stack_pointer_rtx
8226 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8231 /* If the result is to be ptr_mode and we are adding an integer to
8232 something, we might be forming a constant. So try to use
8233 plus_constant. If it produces a sum and we can't accept it,
8234 use force_operand. This allows P = &ARR[const] to generate
8235 efficient code on machines where a SYMBOL_REF is not a valid
8238 If this is an EXPAND_SUM call, always return the sum. */
8239 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8240 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8242 if (modifier
== EXPAND_STACK_PARM
)
8244 if (TREE_CODE (treeop0
) == INTEGER_CST
8245 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8246 && TREE_CONSTANT (treeop1
))
8250 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8252 /* Use immed_double_const to ensure that the constant is
8253 truncated according to the mode of OP1, then sign extended
8254 to a HOST_WIDE_INT. Using the constant directly can result
8255 in non-canonical RTL in a 64x32 cross compile. */
8257 = immed_double_const (TREE_INT_CST_LOW (treeop0
),
8259 TYPE_MODE (TREE_TYPE (treeop1
)));
8260 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8261 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8262 op1
= force_operand (op1
, target
);
8263 return REDUCE_BIT_FIELD (op1
);
8266 else if (TREE_CODE (treeop1
) == INTEGER_CST
8267 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8268 && TREE_CONSTANT (treeop0
))
8272 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8273 (modifier
== EXPAND_INITIALIZER
8274 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8275 if (! CONSTANT_P (op0
))
8277 op1
= expand_expr (treeop1
, NULL_RTX
,
8278 VOIDmode
, modifier
);
8279 /* Return a PLUS if modifier says it's OK. */
8280 if (modifier
== EXPAND_SUM
8281 || modifier
== EXPAND_INITIALIZER
)
8282 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8285 /* Use immed_double_const to ensure that the constant is
8286 truncated according to the mode of OP1, then sign extended
8287 to a HOST_WIDE_INT. Using the constant directly can result
8288 in non-canonical RTL in a 64x32 cross compile. */
8290 = immed_double_const (TREE_INT_CST_LOW (treeop1
),
8292 TYPE_MODE (TREE_TYPE (treeop0
)));
8293 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8294 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8295 op0
= force_operand (op0
, target
);
8296 return REDUCE_BIT_FIELD (op0
);
8300 /* Use TER to expand pointer addition of a negated value
8301 as pointer subtraction. */
8302 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8303 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8304 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8305 && TREE_CODE (treeop1
) == SSA_NAME
8306 && TYPE_MODE (TREE_TYPE (treeop0
))
8307 == TYPE_MODE (TREE_TYPE (treeop1
)))
8309 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8312 treeop1
= gimple_assign_rhs1 (def
);
8318 /* No sense saving up arithmetic to be done
8319 if it's all in the wrong mode to form part of an address.
8320 And force_operand won't know whether to sign-extend or
8322 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8323 || mode
!= ptr_mode
)
8325 expand_operands (treeop0
, treeop1
,
8326 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8327 if (op0
== const0_rtx
)
8329 if (op1
== const0_rtx
)
8334 expand_operands (treeop0
, treeop1
,
8335 subtarget
, &op0
, &op1
, modifier
);
8336 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8340 /* For initializers, we are allowed to return a MINUS of two
8341 symbolic constants. Here we handle all cases when both operands
8343 /* Handle difference of two symbolic constants,
8344 for the sake of an initializer. */
8345 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8346 && really_constant_p (treeop0
)
8347 && really_constant_p (treeop1
))
8349 expand_operands (treeop0
, treeop1
,
8350 NULL_RTX
, &op0
, &op1
, modifier
);
8352 /* If the last operand is a CONST_INT, use plus_constant of
8353 the negated constant. Else make the MINUS. */
8354 if (CONST_INT_P (op1
))
8355 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8358 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8361 /* No sense saving up arithmetic to be done
8362 if it's all in the wrong mode to form part of an address.
8363 And force_operand won't know whether to sign-extend or
8365 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8366 || mode
!= ptr_mode
)
8369 expand_operands (treeop0
, treeop1
,
8370 subtarget
, &op0
, &op1
, modifier
);
8372 /* Convert A - const to A + (-const). */
8373 if (CONST_INT_P (op1
))
8375 op1
= negate_rtx (mode
, op1
);
8376 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8381 case WIDEN_MULT_PLUS_EXPR
:
8382 case WIDEN_MULT_MINUS_EXPR
:
8383 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8384 op2
= expand_normal (treeop2
);
8385 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8389 case WIDEN_MULT_EXPR
:
8390 /* If first operand is constant, swap them.
8391 Thus the following special case checks need only
8392 check the second operand. */
8393 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8400 /* First, check if we have a multiplication of one signed and one
8401 unsigned operand. */
8402 if (TREE_CODE (treeop1
) != INTEGER_CST
8403 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8404 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8406 enum machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8407 this_optab
= usmul_widen_optab
;
8408 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8409 != CODE_FOR_nothing
)
8411 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8412 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8415 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8417 /* op0 and op1 might still be constant, despite the above
8418 != INTEGER_CST check. Handle it. */
8419 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8421 op0
= convert_modes (innermode
, mode
, op0
, true);
8422 op1
= convert_modes (innermode
, mode
, op1
, false);
8423 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8424 target
, unsignedp
));
8429 /* Check for a multiplication with matching signedness. */
8430 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8431 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8432 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8433 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8435 tree op0type
= TREE_TYPE (treeop0
);
8436 enum machine_mode innermode
= TYPE_MODE (op0type
);
8437 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8438 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8439 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8441 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8443 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8444 != CODE_FOR_nothing
)
8446 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8448 /* op0 and op1 might still be constant, despite the above
8449 != INTEGER_CST check. Handle it. */
8450 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8453 op0
= convert_modes (innermode
, mode
, op0
, zextend_p
);
8455 = convert_modes (innermode
, mode
, op1
,
8456 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8457 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8461 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8462 unsignedp
, this_optab
);
8463 return REDUCE_BIT_FIELD (temp
);
8465 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8467 && innermode
== word_mode
)
8470 op0
= expand_normal (treeop0
);
8471 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8472 op1
= convert_modes (innermode
, mode
,
8473 expand_normal (treeop1
),
8474 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8476 op1
= expand_normal (treeop1
);
8477 /* op0 and op1 might still be constant, despite the above
8478 != INTEGER_CST check. Handle it. */
8479 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8480 goto widen_mult_const
;
8481 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8482 unsignedp
, OPTAB_LIB_WIDEN
);
8483 hipart
= gen_highpart (innermode
, temp
);
8484 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8488 emit_move_insn (hipart
, htem
);
8489 return REDUCE_BIT_FIELD (temp
);
8493 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8494 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8495 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8496 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8500 optab opt
= fma_optab
;
8503 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8505 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8507 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8510 gcc_assert (fn
!= NULL_TREE
);
8511 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8512 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8515 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8516 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8521 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8524 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8525 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8528 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8531 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8534 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8537 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8541 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8543 op2
= expand_normal (treeop2
);
8544 op1
= expand_normal (treeop1
);
8546 return expand_ternary_op (TYPE_MODE (type
), opt
,
8547 op0
, op1
, op2
, target
, 0);
8551 /* If this is a fixed-point operation, then we cannot use the code
8552 below because "expand_mult" doesn't support sat/no-sat fixed-point
8554 if (ALL_FIXED_POINT_MODE_P (mode
))
8557 /* If first operand is constant, swap them.
8558 Thus the following special case checks need only
8559 check the second operand. */
8560 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8567 /* Attempt to return something suitable for generating an
8568 indexed address, for machines that support that. */
8570 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8571 && tree_fits_shwi_p (treeop1
))
8573 tree exp1
= treeop1
;
8575 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8579 op0
= force_operand (op0
, NULL_RTX
);
8581 op0
= copy_to_mode_reg (mode
, op0
);
8583 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8584 gen_int_mode (tree_to_shwi (exp1
),
8585 TYPE_MODE (TREE_TYPE (exp1
)))));
8588 if (modifier
== EXPAND_STACK_PARM
)
8591 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8592 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8594 case TRUNC_DIV_EXPR
:
8595 case FLOOR_DIV_EXPR
:
8597 case ROUND_DIV_EXPR
:
8598 case EXACT_DIV_EXPR
:
8599 /* If this is a fixed-point operation, then we cannot use the code
8600 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8602 if (ALL_FIXED_POINT_MODE_P (mode
))
8605 if (modifier
== EXPAND_STACK_PARM
)
8607 /* Possible optimization: compute the dividend with EXPAND_SUM
8608 then if the divisor is constant can optimize the case
8609 where some terms of the dividend have coeffs divisible by it. */
8610 expand_operands (treeop0
, treeop1
,
8611 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8612 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8617 case MULT_HIGHPART_EXPR
:
8618 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8619 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8623 case TRUNC_MOD_EXPR
:
8624 case FLOOR_MOD_EXPR
:
8626 case ROUND_MOD_EXPR
:
8627 if (modifier
== EXPAND_STACK_PARM
)
8629 expand_operands (treeop0
, treeop1
,
8630 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8631 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8633 case FIXED_CONVERT_EXPR
:
8634 op0
= expand_normal (treeop0
);
8635 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8636 target
= gen_reg_rtx (mode
);
8638 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8639 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8640 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8641 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8643 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8646 case FIX_TRUNC_EXPR
:
8647 op0
= expand_normal (treeop0
);
8648 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8649 target
= gen_reg_rtx (mode
);
8650 expand_fix (target
, op0
, unsignedp
);
8654 op0
= expand_normal (treeop0
);
8655 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8656 target
= gen_reg_rtx (mode
);
8657 /* expand_float can't figure out what to do if FROM has VOIDmode.
8658 So give it the correct mode. With -O, cse will optimize this. */
8659 if (GET_MODE (op0
) == VOIDmode
)
8660 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8662 expand_float (target
, op0
,
8663 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8667 op0
= expand_expr (treeop0
, subtarget
,
8668 VOIDmode
, EXPAND_NORMAL
);
8669 if (modifier
== EXPAND_STACK_PARM
)
8671 temp
= expand_unop (mode
,
8672 optab_for_tree_code (NEGATE_EXPR
, type
,
8676 return REDUCE_BIT_FIELD (temp
);
8679 op0
= expand_expr (treeop0
, subtarget
,
8680 VOIDmode
, EXPAND_NORMAL
);
8681 if (modifier
== EXPAND_STACK_PARM
)
8684 /* ABS_EXPR is not valid for complex arguments. */
8685 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8686 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8688 /* Unsigned abs is simply the operand. Testing here means we don't
8689 risk generating incorrect code below. */
8690 if (TYPE_UNSIGNED (type
))
8693 return expand_abs (mode
, op0
, target
, unsignedp
,
8694 safe_from_p (target
, treeop0
, 1));
8698 target
= original_target
;
8700 || modifier
== EXPAND_STACK_PARM
8701 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8702 || GET_MODE (target
) != mode
8704 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8705 target
= gen_reg_rtx (mode
);
8706 expand_operands (treeop0
, treeop1
,
8707 target
, &op0
, &op1
, EXPAND_NORMAL
);
8709 /* First try to do it with a special MIN or MAX instruction.
8710 If that does not win, use a conditional jump to select the proper
8712 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8713 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8718 /* At this point, a MEM target is no longer useful; we will get better
8721 if (! REG_P (target
))
8722 target
= gen_reg_rtx (mode
);
8724 /* If op1 was placed in target, swap op0 and op1. */
8725 if (target
!= op0
&& target
== op1
)
8732 /* We generate better code and avoid problems with op1 mentioning
8733 target by forcing op1 into a pseudo if it isn't a constant. */
8734 if (! CONSTANT_P (op1
))
8735 op1
= force_reg (mode
, op1
);
8738 enum rtx_code comparison_code
;
8741 if (code
== MAX_EXPR
)
8742 comparison_code
= unsignedp
? GEU
: GE
;
8744 comparison_code
= unsignedp
? LEU
: LE
;
8746 /* Canonicalize to comparisons against 0. */
8747 if (op1
== const1_rtx
)
8749 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8750 or (a != 0 ? a : 1) for unsigned.
8751 For MIN we are safe converting (a <= 1 ? a : 1)
8752 into (a <= 0 ? a : 1) */
8753 cmpop1
= const0_rtx
;
8754 if (code
== MAX_EXPR
)
8755 comparison_code
= unsignedp
? NE
: GT
;
8757 if (op1
== constm1_rtx
&& !unsignedp
)
8759 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8760 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8761 cmpop1
= const0_rtx
;
8762 if (code
== MIN_EXPR
)
8763 comparison_code
= LT
;
8765 #ifdef HAVE_conditional_move
8766 /* Use a conditional move if possible. */
8767 if (can_conditionally_move_p (mode
))
8771 /* ??? Same problem as in expmed.c: emit_conditional_move
8772 forces a stack adjustment via compare_from_rtx, and we
8773 lose the stack adjustment if the sequence we are about
8774 to create is discarded. */
8775 do_pending_stack_adjust ();
8779 /* Try to emit the conditional move. */
8780 insn
= emit_conditional_move (target
, comparison_code
,
8785 /* If we could do the conditional move, emit the sequence,
8789 rtx seq
= get_insns ();
8795 /* Otherwise discard the sequence and fall back to code with
8801 emit_move_insn (target
, op0
);
8803 temp
= gen_label_rtx ();
8804 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8805 unsignedp
, mode
, NULL_RTX
, NULL_RTX
, temp
,
8808 emit_move_insn (target
, op1
);
8813 op0
= expand_expr (treeop0
, subtarget
,
8814 VOIDmode
, EXPAND_NORMAL
);
8815 if (modifier
== EXPAND_STACK_PARM
)
8817 /* In case we have to reduce the result to bitfield precision
8818 for unsigned bitfield expand this as XOR with a proper constant
8820 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8821 temp
= expand_binop (mode
, xor_optab
, op0
,
8822 immed_double_int_const
8823 (double_int::mask (TYPE_PRECISION (type
)), mode
),
8824 target
, 1, OPTAB_LIB_WIDEN
);
8826 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8830 /* ??? Can optimize bitwise operations with one arg constant.
8831 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8832 and (a bitwise1 b) bitwise2 b (etc)
8833 but that is probably not worth while. */
8842 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8843 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8844 == TYPE_PRECISION (type
)));
8849 /* If this is a fixed-point operation, then we cannot use the code
8850 below because "expand_shift" doesn't support sat/no-sat fixed-point
8852 if (ALL_FIXED_POINT_MODE_P (mode
))
8855 if (! safe_from_p (subtarget
, treeop1
, 1))
8857 if (modifier
== EXPAND_STACK_PARM
)
8859 op0
= expand_expr (treeop0
, subtarget
,
8860 VOIDmode
, EXPAND_NORMAL
);
8861 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8863 if (code
== LSHIFT_EXPR
)
8864 temp
= REDUCE_BIT_FIELD (temp
);
8867 /* Could determine the answer when only additive constants differ. Also,
8868 the addition of one can be handled by changing the condition. */
8875 case UNORDERED_EXPR
:
8883 temp
= do_store_flag (ops
,
8884 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8885 tmode
!= VOIDmode
? tmode
: mode
);
8889 /* Use a compare and a jump for BLKmode comparisons, or for function
8890 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8893 || modifier
== EXPAND_STACK_PARM
8894 || ! safe_from_p (target
, treeop0
, 1)
8895 || ! safe_from_p (target
, treeop1
, 1)
8896 /* Make sure we don't have a hard reg (such as function's return
8897 value) live across basic blocks, if not optimizing. */
8898 || (!optimize
&& REG_P (target
)
8899 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8900 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8902 emit_move_insn (target
, const0_rtx
);
8904 op1
= gen_label_rtx ();
8905 jumpifnot_1 (code
, treeop0
, treeop1
, op1
, -1);
8907 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8908 emit_move_insn (target
, constm1_rtx
);
8910 emit_move_insn (target
, const1_rtx
);
8916 /* Get the rtx code of the operands. */
8917 op0
= expand_normal (treeop0
);
8918 op1
= expand_normal (treeop1
);
8921 target
= gen_reg_rtx (TYPE_MODE (type
));
8923 /* If target overlaps with op1, then either we need to force
8924 op1 into a pseudo (if target also overlaps with op0),
8925 or write the complex parts in reverse order. */
8926 switch (GET_CODE (target
))
8929 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
8931 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
8933 complex_expr_force_op1
:
8934 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
8935 emit_move_insn (temp
, op1
);
8939 complex_expr_swap_order
:
8940 /* Move the imaginary (op1) and real (op0) parts to their
8942 write_complex_part (target
, op1
, true);
8943 write_complex_part (target
, op0
, false);
8949 temp
= adjust_address_nv (target
,
8950 GET_MODE_INNER (GET_MODE (target
)), 0);
8951 if (reg_overlap_mentioned_p (temp
, op1
))
8953 enum machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
8954 temp
= adjust_address_nv (target
, imode
,
8955 GET_MODE_SIZE (imode
));
8956 if (reg_overlap_mentioned_p (temp
, op0
))
8957 goto complex_expr_force_op1
;
8958 goto complex_expr_swap_order
;
8962 if (reg_overlap_mentioned_p (target
, op1
))
8964 if (reg_overlap_mentioned_p (target
, op0
))
8965 goto complex_expr_force_op1
;
8966 goto complex_expr_swap_order
;
8971 /* Move the real (op0) and imaginary (op1) parts to their location. */
8972 write_complex_part (target
, op0
, false);
8973 write_complex_part (target
, op1
, true);
8977 case WIDEN_SUM_EXPR
:
8979 tree oprnd0
= treeop0
;
8980 tree oprnd1
= treeop1
;
8982 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8983 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
8988 case REDUC_MAX_EXPR
:
8989 case REDUC_MIN_EXPR
:
8990 case REDUC_PLUS_EXPR
:
8992 op0
= expand_normal (treeop0
);
8993 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8994 temp
= expand_unop (mode
, this_optab
, op0
, target
, unsignedp
);
8999 case VEC_LSHIFT_EXPR
:
9000 case VEC_RSHIFT_EXPR
:
9002 target
= expand_vec_shift_expr (ops
, target
);
9006 case VEC_UNPACK_HI_EXPR
:
9007 case VEC_UNPACK_LO_EXPR
:
9009 op0
= expand_normal (treeop0
);
9010 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9016 case VEC_UNPACK_FLOAT_HI_EXPR
:
9017 case VEC_UNPACK_FLOAT_LO_EXPR
:
9019 op0
= expand_normal (treeop0
);
9020 /* The signedness is determined from input operand. */
9021 temp
= expand_widen_pattern_expr
9022 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9023 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9029 case VEC_WIDEN_MULT_HI_EXPR
:
9030 case VEC_WIDEN_MULT_LO_EXPR
:
9031 case VEC_WIDEN_MULT_EVEN_EXPR
:
9032 case VEC_WIDEN_MULT_ODD_EXPR
:
9033 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9034 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9035 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9036 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9038 gcc_assert (target
);
9041 case VEC_PACK_TRUNC_EXPR
:
9042 case VEC_PACK_SAT_EXPR
:
9043 case VEC_PACK_FIX_TRUNC_EXPR
:
9044 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9048 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9049 op2
= expand_normal (treeop2
);
9051 /* Careful here: if the target doesn't support integral vector modes,
9052 a constant selection vector could wind up smooshed into a normal
9053 integral constant. */
9054 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9056 tree sel_type
= TREE_TYPE (treeop2
);
9057 enum machine_mode vmode
9058 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9059 TYPE_VECTOR_SUBPARTS (sel_type
));
9060 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9061 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9062 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9065 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9067 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9073 tree oprnd0
= treeop0
;
9074 tree oprnd1
= treeop1
;
9075 tree oprnd2
= treeop2
;
9078 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9079 op2
= expand_normal (oprnd2
);
9080 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9085 case REALIGN_LOAD_EXPR
:
9087 tree oprnd0
= treeop0
;
9088 tree oprnd1
= treeop1
;
9089 tree oprnd2
= treeop2
;
9092 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9093 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9094 op2
= expand_normal (oprnd2
);
9095 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9102 /* A COND_EXPR with its type being VOID_TYPE represents a
9103 conditional jump and is handled in
9104 expand_gimple_cond_expr. */
9105 gcc_assert (!VOID_TYPE_P (type
));
9107 /* Note that COND_EXPRs whose type is a structure or union
9108 are required to be constructed to contain assignments of
9109 a temporary variable, so that we can evaluate them here
9110 for side effect only. If type is void, we must do likewise. */
9112 gcc_assert (!TREE_ADDRESSABLE (type
)
9114 && TREE_TYPE (treeop1
) != void_type_node
9115 && TREE_TYPE (treeop2
) != void_type_node
);
9117 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9121 /* If we are not to produce a result, we have no target. Otherwise,
9122 if a target was specified use it; it will not be used as an
9123 intermediate target unless it is safe. If no target, use a
9126 if (modifier
!= EXPAND_STACK_PARM
9128 && safe_from_p (original_target
, treeop0
, 1)
9129 && GET_MODE (original_target
) == mode
9130 && !MEM_P (original_target
))
9131 temp
= original_target
;
9133 temp
= assign_temp (type
, 0, 1);
9135 do_pending_stack_adjust ();
9137 op0
= gen_label_rtx ();
9138 op1
= gen_label_rtx ();
9139 jumpifnot (treeop0
, op0
, -1);
9140 store_expr (treeop1
, temp
,
9141 modifier
== EXPAND_STACK_PARM
,
9144 emit_jump_insn (gen_jump (op1
));
9147 store_expr (treeop2
, temp
,
9148 modifier
== EXPAND_STACK_PARM
,
9156 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9163 /* Here to do an ordinary binary operator. */
9165 expand_operands (treeop0
, treeop1
,
9166 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9168 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9170 if (modifier
== EXPAND_STACK_PARM
)
9172 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9173 unsignedp
, OPTAB_LIB_WIDEN
);
9175 /* Bitwise operations do not need bitfield reduction as we expect their
9176 operands being properly truncated. */
9177 if (code
== BIT_XOR_EXPR
9178 || code
== BIT_AND_EXPR
9179 || code
== BIT_IOR_EXPR
)
9181 return REDUCE_BIT_FIELD (temp
);
9183 #undef REDUCE_BIT_FIELD
9186 /* Return TRUE if expression STMT is suitable for replacement.
9187 Never consider memory loads as replaceable, because those don't ever lead
9188 into constant expressions. */
9191 stmt_is_replaceable_p (gimple stmt
)
9193 if (ssa_is_replaceable_p (stmt
))
9195 /* Don't move around loads. */
9196 if (!gimple_assign_single_p (stmt
)
9197 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9204 expand_expr_real_1 (tree exp
, rtx target
, enum machine_mode tmode
,
9205 enum expand_modifier modifier
, rtx
*alt_rtl
)
9207 rtx op0
, op1
, temp
, decl_rtl
;
9210 enum machine_mode mode
;
9211 enum tree_code code
= TREE_CODE (exp
);
9212 rtx subtarget
, original_target
;
9215 bool reduce_bit_field
;
9216 location_t loc
= EXPR_LOCATION (exp
);
9217 struct separate_ops ops
;
9218 tree treeop0
, treeop1
, treeop2
;
9219 tree ssa_name
= NULL_TREE
;
9222 type
= TREE_TYPE (exp
);
9223 mode
= TYPE_MODE (type
);
9224 unsignedp
= TYPE_UNSIGNED (type
);
9226 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9227 if (!VL_EXP_CLASS_P (exp
))
9228 switch (TREE_CODE_LENGTH (code
))
9231 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9232 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9233 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9243 ignore
= (target
== const0_rtx
9244 || ((CONVERT_EXPR_CODE_P (code
)
9245 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9246 && TREE_CODE (type
) == VOID_TYPE
));
9248 /* An operation in what may be a bit-field type needs the
9249 result to be reduced to the precision of the bit-field type,
9250 which is narrower than that of the type's mode. */
9251 reduce_bit_field
= (!ignore
9252 && INTEGRAL_TYPE_P (type
)
9253 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9255 /* If we are going to ignore this result, we need only do something
9256 if there is a side-effect somewhere in the expression. If there
9257 is, short-circuit the most common cases here. Note that we must
9258 not call expand_expr with anything but const0_rtx in case this
9259 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9263 if (! TREE_SIDE_EFFECTS (exp
))
9266 /* Ensure we reference a volatile object even if value is ignored, but
9267 don't do this if all we are doing is taking its address. */
9268 if (TREE_THIS_VOLATILE (exp
)
9269 && TREE_CODE (exp
) != FUNCTION_DECL
9270 && mode
!= VOIDmode
&& mode
!= BLKmode
9271 && modifier
!= EXPAND_CONST_ADDRESS
)
9273 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9279 if (TREE_CODE_CLASS (code
) == tcc_unary
9280 || code
== BIT_FIELD_REF
9281 || code
== COMPONENT_REF
9282 || code
== INDIRECT_REF
)
9283 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9286 else if (TREE_CODE_CLASS (code
) == tcc_binary
9287 || TREE_CODE_CLASS (code
) == tcc_comparison
9288 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9290 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9291 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9298 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9301 /* Use subtarget as the target for operand 0 of a binary operation. */
9302 subtarget
= get_subtarget (target
);
9303 original_target
= target
;
9309 tree function
= decl_function_context (exp
);
9311 temp
= label_rtx (exp
);
9312 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9314 if (function
!= current_function_decl
9316 LABEL_REF_NONLOCAL_P (temp
) = 1;
9318 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9323 /* ??? ivopts calls expander, without any preparation from
9324 out-of-ssa. So fake instructions as if this was an access to the
9325 base variable. This unnecessarily allocates a pseudo, see how we can
9326 reuse it, if partition base vars have it set already. */
9327 if (!currently_expanding_to_rtl
)
9329 tree var
= SSA_NAME_VAR (exp
);
9330 if (var
&& DECL_RTL_SET_P (var
))
9331 return DECL_RTL (var
);
9332 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9333 LAST_VIRTUAL_REGISTER
+ 1);
9336 g
= get_gimple_for_ssa_name (exp
);
9337 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9339 && modifier
== EXPAND_INITIALIZER
9340 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9341 && (optimize
|| DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9342 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9343 g
= SSA_NAME_DEF_STMT (exp
);
9347 location_t saved_loc
= curr_insn_location ();
9349 set_curr_insn_location (gimple_location (g
));
9350 r
= expand_expr_real (gimple_assign_rhs_to_tree (g
), target
,
9351 tmode
, modifier
, NULL
);
9352 set_curr_insn_location (saved_loc
);
9353 if (REG_P (r
) && !REG_EXPR (r
))
9354 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9359 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9360 exp
= SSA_NAME_VAR (ssa_name
);
9361 goto expand_decl_rtl
;
9365 /* If a static var's type was incomplete when the decl was written,
9366 but the type is complete now, lay out the decl now. */
9367 if (DECL_SIZE (exp
) == 0
9368 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9369 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9370 layout_decl (exp
, 0);
9372 /* ... fall through ... */
9376 decl_rtl
= DECL_RTL (exp
);
9378 gcc_assert (decl_rtl
);
9379 decl_rtl
= copy_rtx (decl_rtl
);
9380 /* Record writes to register variables. */
9381 if (modifier
== EXPAND_WRITE
9383 && HARD_REGISTER_P (decl_rtl
))
9384 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9385 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9387 /* Ensure variable marked as used even if it doesn't go through
9388 a parser. If it hasn't be used yet, write out an external
9390 TREE_USED (exp
) = 1;
9392 /* Show we haven't gotten RTL for this yet. */
9395 /* Variables inherited from containing functions should have
9396 been lowered by this point. */
9397 context
= decl_function_context (exp
);
9398 gcc_assert (SCOPE_FILE_SCOPE_P (context
)
9399 || context
== current_function_decl
9400 || TREE_STATIC (exp
)
9401 || DECL_EXTERNAL (exp
)
9402 /* ??? C++ creates functions that are not TREE_STATIC. */
9403 || TREE_CODE (exp
) == FUNCTION_DECL
);
9405 /* This is the case of an array whose size is to be determined
9406 from its initializer, while the initializer is still being parsed.
9407 ??? We aren't parsing while expanding anymore. */
9409 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9410 temp
= validize_mem (decl_rtl
);
9412 /* If DECL_RTL is memory, we are in the normal case and the
9413 address is not valid, get the address into a register. */
9415 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9418 *alt_rtl
= decl_rtl
;
9419 decl_rtl
= use_anchored_address (decl_rtl
);
9420 if (modifier
!= EXPAND_CONST_ADDRESS
9421 && modifier
!= EXPAND_SUM
9422 && !memory_address_addr_space_p (DECL_MODE (exp
),
9424 MEM_ADDR_SPACE (decl_rtl
)))
9425 temp
= replace_equiv_address (decl_rtl
,
9426 copy_rtx (XEXP (decl_rtl
, 0)));
9429 /* If we got something, return it. But first, set the alignment
9430 if the address is a register. */
9433 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9434 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9439 /* If the mode of DECL_RTL does not match that of the decl,
9440 there are two cases: we are dealing with a BLKmode value
9441 that is returned in a register, or we are dealing with
9442 a promoted value. In the latter case, return a SUBREG
9443 of the wanted mode, but mark it so that we know that it
9444 was already extended. */
9445 if (REG_P (decl_rtl
)
9446 && DECL_MODE (exp
) != BLKmode
9447 && GET_MODE (decl_rtl
) != DECL_MODE (exp
))
9449 enum machine_mode pmode
;
9451 /* Get the signedness to be used for this variable. Ensure we get
9452 the same mode we got when the variable was declared. */
9453 if (code
== SSA_NAME
9454 && (g
= SSA_NAME_DEF_STMT (ssa_name
))
9455 && gimple_code (g
) == GIMPLE_CALL
)
9457 gcc_assert (!gimple_call_internal_p (g
));
9458 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9459 gimple_call_fntype (g
),
9463 pmode
= promote_decl_mode (exp
, &unsignedp
);
9464 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9466 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9467 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9468 SUBREG_PROMOTED_UNSIGNED_SET (temp
, unsignedp
);
9475 temp
= immed_double_const (TREE_INT_CST_LOW (exp
),
9476 TREE_INT_CST_HIGH (exp
), mode
);
9482 tree tmp
= NULL_TREE
;
9483 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9484 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9485 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9486 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9487 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9488 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9489 return const_vector_from_tree (exp
);
9490 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9492 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9494 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9498 vec
<constructor_elt
, va_gc
> *v
;
9500 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9501 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9502 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9503 tmp
= build_constructor (type
, v
);
9505 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9510 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9513 /* If optimized, generate immediate CONST_DOUBLE
9514 which will be turned into memory by reload if necessary.
9516 We used to force a register so that loop.c could see it. But
9517 this does not allow gen_* patterns to perform optimizations with
9518 the constants. It also produces two insns in cases like "x = 1.0;".
9519 On most machines, floating-point constants are not permitted in
9520 many insns, so we'd end up copying it to a register in any case.
9522 Now, we do the copying in expand_binop, if appropriate. */
9523 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9524 TYPE_MODE (TREE_TYPE (exp
)));
9527 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9528 TYPE_MODE (TREE_TYPE (exp
)));
9531 /* Handle evaluating a complex constant in a CONCAT target. */
9532 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9534 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9537 rtarg
= XEXP (original_target
, 0);
9538 itarg
= XEXP (original_target
, 1);
9540 /* Move the real and imaginary parts separately. */
9541 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9542 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9545 emit_move_insn (rtarg
, op0
);
9547 emit_move_insn (itarg
, op1
);
9549 return original_target
;
9552 /* ... fall through ... */
9555 temp
= expand_expr_constant (exp
, 1, modifier
);
9557 /* temp contains a constant address.
9558 On RISC machines where a constant address isn't valid,
9559 make some insns to get that address into a register. */
9560 if (modifier
!= EXPAND_CONST_ADDRESS
9561 && modifier
!= EXPAND_INITIALIZER
9562 && modifier
!= EXPAND_SUM
9563 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9564 MEM_ADDR_SPACE (temp
)))
9565 return replace_equiv_address (temp
,
9566 copy_rtx (XEXP (temp
, 0)));
9572 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
);
9574 if (!SAVE_EXPR_RESOLVED_P (exp
))
9576 /* We can indeed still hit this case, typically via builtin
9577 expanders calling save_expr immediately before expanding
9578 something. Assume this means that we only have to deal
9579 with non-BLKmode values. */
9580 gcc_assert (GET_MODE (ret
) != BLKmode
);
9582 val
= build_decl (curr_insn_location (),
9583 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9584 DECL_ARTIFICIAL (val
) = 1;
9585 DECL_IGNORED_P (val
) = 1;
9587 TREE_OPERAND (exp
, 0) = treeop0
;
9588 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9590 if (!CONSTANT_P (ret
))
9591 ret
= copy_to_reg (ret
);
9592 SET_DECL_RTL (val
, ret
);
9600 /* If we don't need the result, just ensure we evaluate any
9604 unsigned HOST_WIDE_INT idx
;
9607 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9608 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9613 return expand_constructor (exp
, target
, modifier
, false);
9615 case TARGET_MEM_REF
:
9618 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9619 enum insn_code icode
;
9622 op0
= addr_for_mem_ref (exp
, as
, true);
9623 op0
= memory_address_addr_space (mode
, op0
, as
);
9624 temp
= gen_rtx_MEM (mode
, op0
);
9625 set_mem_attributes (temp
, exp
, 0);
9626 set_mem_addr_space (temp
, as
);
9627 align
= get_object_alignment (exp
);
9628 if (modifier
!= EXPAND_WRITE
9629 && modifier
!= EXPAND_MEMORY
9631 && align
< GET_MODE_ALIGNMENT (mode
)
9632 /* If the target does not have special handling for unaligned
9633 loads of mode then it can use regular moves for them. */
9634 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9635 != CODE_FOR_nothing
))
9637 struct expand_operand ops
[2];
9639 /* We've already validated the memory, and we're creating a
9640 new pseudo destination. The predicates really can't fail,
9641 nor can the generator. */
9642 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9643 create_fixed_operand (&ops
[1], temp
);
9644 expand_insn (icode
, 2, ops
);
9645 temp
= ops
[0].value
;
9653 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9654 enum machine_mode address_mode
;
9655 tree base
= TREE_OPERAND (exp
, 0);
9657 enum insn_code icode
;
9659 /* Handle expansion of non-aliased memory with non-BLKmode. That
9660 might end up in a register. */
9661 if (mem_ref_refers_to_non_mem_p (exp
))
9663 HOST_WIDE_INT offset
= mem_ref_offset (exp
).low
;
9664 base
= TREE_OPERAND (base
, 0);
9666 && tree_fits_uhwi_p (TYPE_SIZE (type
))
9667 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9668 == tree_to_uhwi (TYPE_SIZE (type
))))
9669 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
9670 target
, tmode
, modifier
);
9671 if (TYPE_MODE (type
) == BLKmode
)
9673 temp
= assign_stack_temp (DECL_MODE (base
),
9674 GET_MODE_SIZE (DECL_MODE (base
)));
9675 store_expr (base
, temp
, 0, false);
9676 temp
= adjust_address (temp
, BLKmode
, offset
);
9677 set_mem_size (temp
, int_size_in_bytes (type
));
9680 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
9681 bitsize_int (offset
* BITS_PER_UNIT
));
9682 return expand_expr (exp
, target
, tmode
, modifier
);
9684 address_mode
= targetm
.addr_space
.address_mode (as
);
9685 base
= TREE_OPERAND (exp
, 0);
9686 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9688 tree mask
= gimple_assign_rhs2 (def_stmt
);
9689 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9690 gimple_assign_rhs1 (def_stmt
), mask
);
9691 TREE_OPERAND (exp
, 0) = base
;
9693 align
= get_object_alignment (exp
);
9694 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9695 op0
= memory_address_addr_space (mode
, op0
, as
);
9696 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9699 = immed_double_int_const (mem_ref_offset (exp
), address_mode
);
9700 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9701 op0
= memory_address_addr_space (mode
, op0
, as
);
9703 temp
= gen_rtx_MEM (mode
, op0
);
9704 set_mem_attributes (temp
, exp
, 0);
9705 set_mem_addr_space (temp
, as
);
9706 if (TREE_THIS_VOLATILE (exp
))
9707 MEM_VOLATILE_P (temp
) = 1;
9708 if (modifier
!= EXPAND_WRITE
9709 && modifier
!= EXPAND_MEMORY
9711 && align
< GET_MODE_ALIGNMENT (mode
))
9713 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9714 != CODE_FOR_nothing
)
9716 struct expand_operand ops
[2];
9718 /* We've already validated the memory, and we're creating a
9719 new pseudo destination. The predicates really can't fail,
9720 nor can the generator. */
9721 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9722 create_fixed_operand (&ops
[1], temp
);
9723 expand_insn (icode
, 2, ops
);
9724 temp
= ops
[0].value
;
9726 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9727 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9728 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9729 (modifier
== EXPAND_STACK_PARM
9730 ? NULL_RTX
: target
),
9739 tree array
= treeop0
;
9740 tree index
= treeop1
;
9743 /* Fold an expression like: "foo"[2].
9744 This is not done in fold so it won't happen inside &.
9745 Don't fold if this is for wide characters since it's too
9746 difficult to do correctly and this is a very rare case. */
9748 if (modifier
!= EXPAND_CONST_ADDRESS
9749 && modifier
!= EXPAND_INITIALIZER
9750 && modifier
!= EXPAND_MEMORY
)
9752 tree t
= fold_read_from_constant_string (exp
);
9755 return expand_expr (t
, target
, tmode
, modifier
);
9758 /* If this is a constant index into a constant array,
9759 just get the value from the array. Handle both the cases when
9760 we have an explicit constructor and when our operand is a variable
9761 that was declared const. */
9763 if (modifier
!= EXPAND_CONST_ADDRESS
9764 && modifier
!= EXPAND_INITIALIZER
9765 && modifier
!= EXPAND_MEMORY
9766 && TREE_CODE (array
) == CONSTRUCTOR
9767 && ! TREE_SIDE_EFFECTS (array
)
9768 && TREE_CODE (index
) == INTEGER_CST
)
9770 unsigned HOST_WIDE_INT ix
;
9773 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9775 if (tree_int_cst_equal (field
, index
))
9777 if (!TREE_SIDE_EFFECTS (value
))
9778 return expand_expr (fold (value
), target
, tmode
, modifier
);
9783 else if (optimize
>= 1
9784 && modifier
!= EXPAND_CONST_ADDRESS
9785 && modifier
!= EXPAND_INITIALIZER
9786 && modifier
!= EXPAND_MEMORY
9787 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9788 && TREE_CODE (index
) == INTEGER_CST
9789 && (TREE_CODE (array
) == VAR_DECL
9790 || TREE_CODE (array
) == CONST_DECL
)
9791 && (init
= ctor_for_folding (array
)) != error_mark_node
)
9793 if (TREE_CODE (init
) == CONSTRUCTOR
)
9795 unsigned HOST_WIDE_INT ix
;
9798 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9800 if (tree_int_cst_equal (field
, index
))
9802 if (TREE_SIDE_EFFECTS (value
))
9805 if (TREE_CODE (value
) == CONSTRUCTOR
)
9807 /* If VALUE is a CONSTRUCTOR, this
9808 optimization is only useful if
9809 this doesn't store the CONSTRUCTOR
9810 into memory. If it does, it is more
9811 efficient to just load the data from
9812 the array directly. */
9813 rtx ret
= expand_constructor (value
, target
,
9815 if (ret
== NULL_RTX
)
9820 expand_expr (fold (value
), target
, tmode
, modifier
);
9823 else if (TREE_CODE (init
) == STRING_CST
)
9825 tree low_bound
= array_ref_low_bound (exp
);
9826 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
9828 /* Optimize the special case of a zero lower bound.
9830 We convert the lower bound to sizetype to avoid problems
9831 with constant folding. E.g. suppose the lower bound is
9832 1 and its mode is QI. Without the conversion
9833 (ARRAY + (INDEX - (unsigned char)1))
9835 (ARRAY + (-(unsigned char)1) + INDEX)
9837 (ARRAY + 255 + INDEX). Oops! */
9838 if (!integer_zerop (low_bound
))
9839 index1
= size_diffop_loc (loc
, index1
,
9840 fold_convert_loc (loc
, sizetype
,
9843 if (compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
9845 tree type
= TREE_TYPE (TREE_TYPE (init
));
9846 enum machine_mode mode
= TYPE_MODE (type
);
9848 if (GET_MODE_CLASS (mode
) == MODE_INT
9849 && GET_MODE_SIZE (mode
) == 1)
9850 return gen_int_mode (TREE_STRING_POINTER (init
)
9851 [TREE_INT_CST_LOW (index1
)],
9857 goto normal_inner_ref
;
9860 /* If the operand is a CONSTRUCTOR, we can just extract the
9861 appropriate field if it is present. */
9862 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
9864 unsigned HOST_WIDE_INT idx
;
9867 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
9869 if (field
== treeop1
9870 /* We can normally use the value of the field in the
9871 CONSTRUCTOR. However, if this is a bitfield in
9872 an integral mode that we can fit in a HOST_WIDE_INT,
9873 we must mask only the number of bits in the bitfield,
9874 since this is done implicitly by the constructor. If
9875 the bitfield does not meet either of those conditions,
9876 we can't do this optimization. */
9877 && (! DECL_BIT_FIELD (field
)
9878 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
9879 && (GET_MODE_PRECISION (DECL_MODE (field
))
9880 <= HOST_BITS_PER_WIDE_INT
))))
9882 if (DECL_BIT_FIELD (field
)
9883 && modifier
== EXPAND_STACK_PARM
)
9885 op0
= expand_expr (value
, target
, tmode
, modifier
);
9886 if (DECL_BIT_FIELD (field
))
9888 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
9889 enum machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
9891 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
9893 op1
= gen_int_mode (((HOST_WIDE_INT
) 1 << bitsize
) - 1,
9895 op0
= expand_and (imode
, op0
, op1
, target
);
9899 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
9901 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
9903 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
9911 goto normal_inner_ref
;
9914 case ARRAY_RANGE_REF
:
9917 enum machine_mode mode1
, mode2
;
9918 HOST_WIDE_INT bitsize
, bitpos
;
9920 int volatilep
= 0, must_force_mem
;
9921 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
9922 &mode1
, &unsignedp
, &volatilep
);
9923 rtx orig_op0
, memloc
;
9924 bool mem_attrs_from_type
= false;
9926 /* If we got back the original object, something is wrong. Perhaps
9927 we are evaluating an expression too early. In any event, don't
9928 infinitely recurse. */
9929 gcc_assert (tem
!= exp
);
9931 /* If TEM's type is a union of variable size, pass TARGET to the inner
9932 computation, since it will need a temporary and TARGET is known
9933 to have to do. This occurs in unchecked conversion in Ada. */
9936 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
9937 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
9938 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
9940 && modifier
!= EXPAND_STACK_PARM
9941 ? target
: NULL_RTX
),
9943 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
9945 /* If the bitfield is volatile, we want to access it in the
9946 field's mode, not the computed mode.
9947 If a MEM has VOIDmode (external with incomplete type),
9948 use BLKmode for it instead. */
9951 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
9952 op0
= adjust_address (op0
, mode1
, 0);
9953 else if (GET_MODE (op0
) == VOIDmode
)
9954 op0
= adjust_address (op0
, BLKmode
, 0);
9958 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
9960 /* If we have either an offset, a BLKmode result, or a reference
9961 outside the underlying object, we must force it to memory.
9962 Such a case can occur in Ada if we have unchecked conversion
9963 of an expression from a scalar type to an aggregate type or
9964 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9965 passed a partially uninitialized object or a view-conversion
9966 to a larger size. */
9967 must_force_mem
= (offset
9969 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
9971 /* Handle CONCAT first. */
9972 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
9975 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
9978 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9981 op0
= XEXP (op0
, 0);
9982 mode2
= GET_MODE (op0
);
9984 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9985 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
9989 op0
= XEXP (op0
, 1);
9991 mode2
= GET_MODE (op0
);
9994 /* Otherwise force into memory. */
9998 /* If this is a constant, put it in a register if it is a legitimate
9999 constant and we don't need a memory reference. */
10000 if (CONSTANT_P (op0
)
10001 && mode2
!= BLKmode
10002 && targetm
.legitimate_constant_p (mode2
, op0
)
10003 && !must_force_mem
)
10004 op0
= force_reg (mode2
, op0
);
10006 /* Otherwise, if this is a constant, try to force it to the constant
10007 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10008 is a legitimate constant. */
10009 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10010 op0
= validize_mem (memloc
);
10012 /* Otherwise, if this is a constant or the object is not in memory
10013 and need be, put it there. */
10014 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10016 tree nt
= build_qualified_type (TREE_TYPE (tem
),
10017 (TYPE_QUALS (TREE_TYPE (tem
))
10018 | TYPE_QUAL_CONST
));
10019 memloc
= assign_temp (nt
, 1, 1);
10020 emit_move_insn (memloc
, op0
);
10022 mem_attrs_from_type
= true;
10027 enum machine_mode address_mode
;
10028 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10031 gcc_assert (MEM_P (op0
));
10033 address_mode
= get_address_mode (op0
);
10034 if (GET_MODE (offset_rtx
) != address_mode
)
10035 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10037 if (GET_MODE (op0
) == BLKmode
10038 /* A constant address in OP0 can have VOIDmode, we must
10039 not try to call force_reg in that case. */
10040 && GET_MODE (XEXP (op0
, 0)) != VOIDmode
10042 && (bitpos
% bitsize
) == 0
10043 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10044 && MEM_ALIGN (op0
) == GET_MODE_ALIGNMENT (mode1
))
10046 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10050 op0
= offset_address (op0
, offset_rtx
,
10051 highest_pow2_factor (offset
));
10054 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10055 record its alignment as BIGGEST_ALIGNMENT. */
10056 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10057 && is_aligning_offset (offset
, tem
))
10058 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10060 /* Don't forget about volatility even if this is a bitfield. */
10061 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10063 if (op0
== orig_op0
)
10064 op0
= copy_rtx (op0
);
10066 MEM_VOLATILE_P (op0
) = 1;
10069 /* In cases where an aligned union has an unaligned object
10070 as a field, we might be extracting a BLKmode value from
10071 an integer-mode (e.g., SImode) object. Handle this case
10072 by doing the extract into an object as wide as the field
10073 (which we know to be the width of a basic mode), then
10074 storing into memory, and changing the mode to BLKmode. */
10075 if (mode1
== VOIDmode
10076 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10077 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10078 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10079 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10080 && modifier
!= EXPAND_CONST_ADDRESS
10081 && modifier
!= EXPAND_INITIALIZER
10082 && modifier
!= EXPAND_MEMORY
)
10083 /* If the field is volatile, we always want an aligned
10084 access. Do this in following two situations:
10085 1. the access is not already naturally
10086 aligned, otherwise "normal" (non-bitfield) volatile fields
10087 become non-addressable.
10088 2. the bitsize is narrower than the access size. Need
10089 to extract bitfields from the access. */
10090 || (volatilep
&& flag_strict_volatile_bitfields
> 0
10091 && (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0
10092 || (mode1
!= BLKmode
10093 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)))
10094 /* If the field isn't aligned enough to fetch as a memref,
10095 fetch it as a bit field. */
10096 || (mode1
!= BLKmode
10097 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10098 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10100 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10101 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10102 && modifier
!= EXPAND_MEMORY
10103 && ((modifier
== EXPAND_CONST_ADDRESS
10104 || modifier
== EXPAND_INITIALIZER
)
10106 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10107 || (bitpos
% BITS_PER_UNIT
!= 0)))
10108 /* If the type and the field are a constant size and the
10109 size of the type isn't the same size as the bitfield,
10110 we must use bitfield operations. */
10112 && TYPE_SIZE (TREE_TYPE (exp
))
10113 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10114 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10117 enum machine_mode ext_mode
= mode
;
10119 if (ext_mode
== BLKmode
10120 && ! (target
!= 0 && MEM_P (op0
)
10122 && bitpos
% BITS_PER_UNIT
== 0))
10123 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10125 if (ext_mode
== BLKmode
)
10128 target
= assign_temp (type
, 1, 1);
10133 /* In this case, BITPOS must start at a byte boundary and
10134 TARGET, if specified, must be a MEM. */
10135 gcc_assert (MEM_P (op0
)
10136 && (!target
|| MEM_P (target
))
10137 && !(bitpos
% BITS_PER_UNIT
));
10139 emit_block_move (target
,
10140 adjust_address (op0
, VOIDmode
,
10141 bitpos
/ BITS_PER_UNIT
),
10142 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10144 (modifier
== EXPAND_STACK_PARM
10145 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10150 op0
= validize_mem (op0
);
10152 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10153 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10155 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10156 (modifier
== EXPAND_STACK_PARM
10157 ? NULL_RTX
: target
),
10158 ext_mode
, ext_mode
);
10160 /* If the result is a record type and BITSIZE is narrower than
10161 the mode of OP0, an integral mode, and this is a big endian
10162 machine, we must put the field into the high-order bits. */
10163 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10164 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10165 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10166 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10167 GET_MODE_BITSIZE (GET_MODE (op0
))
10168 - bitsize
, op0
, 1);
10170 /* If the result type is BLKmode, store the data into a temporary
10171 of the appropriate type, but with the mode corresponding to the
10172 mode for the data we have (op0's mode). It's tempting to make
10173 this a constant type, since we know it's only being stored once,
10174 but that can cause problems if we are taking the address of this
10175 COMPONENT_REF because the MEM of any reference via that address
10176 will have flags corresponding to the type, which will not
10177 necessarily be constant. */
10178 if (mode
== BLKmode
)
10182 new_rtx
= assign_stack_temp_for_type (ext_mode
,
10183 GET_MODE_BITSIZE (ext_mode
),
10185 emit_move_insn (new_rtx
, op0
);
10186 op0
= copy_rtx (new_rtx
);
10187 PUT_MODE (op0
, BLKmode
);
10193 /* If the result is BLKmode, use that to access the object
10195 if (mode
== BLKmode
)
10198 /* Get a reference to just this component. */
10199 if (modifier
== EXPAND_CONST_ADDRESS
10200 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10201 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10203 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10205 if (op0
== orig_op0
)
10206 op0
= copy_rtx (op0
);
10208 /* If op0 is a temporary because of forcing to memory, pass only the
10209 type to set_mem_attributes so that the original expression is never
10210 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10211 if (mem_attrs_from_type
)
10212 set_mem_attributes (op0
, type
, 0);
10214 set_mem_attributes (op0
, exp
, 0);
10216 if (REG_P (XEXP (op0
, 0)))
10217 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10219 MEM_VOLATILE_P (op0
) |= volatilep
;
10220 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10221 || modifier
== EXPAND_CONST_ADDRESS
10222 || modifier
== EXPAND_INITIALIZER
)
10226 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10228 convert_move (target
, op0
, unsignedp
);
10233 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10236 /* All valid uses of __builtin_va_arg_pack () are removed during
10238 if (CALL_EXPR_VA_ARG_PACK (exp
))
10239 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10241 tree fndecl
= get_callee_fndecl (exp
), attr
;
10244 && (attr
= lookup_attribute ("error",
10245 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10246 error ("%Kcall to %qs declared with attribute error: %s",
10247 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10248 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10250 && (attr
= lookup_attribute ("warning",
10251 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10252 warning_at (tree_nonartificial_location (exp
),
10253 0, "%Kcall to %qs declared with attribute warning: %s",
10254 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10255 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10257 /* Check for a built-in function. */
10258 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10260 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10261 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10264 return expand_call (exp
, target
, ignore
);
10266 case VIEW_CONVERT_EXPR
:
10269 /* If we are converting to BLKmode, try to avoid an intermediate
10270 temporary by fetching an inner memory reference. */
10271 if (mode
== BLKmode
10272 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10273 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10274 && handled_component_p (treeop0
))
10276 enum machine_mode mode1
;
10277 HOST_WIDE_INT bitsize
, bitpos
;
10282 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10283 &offset
, &mode1
, &unsignedp
, &volatilep
);
10286 /* ??? We should work harder and deal with non-zero offsets. */
10288 && (bitpos
% BITS_PER_UNIT
) == 0
10290 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10292 /* See the normal_inner_ref case for the rationale. */
10294 = expand_expr (tem
,
10295 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10296 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10298 && modifier
!= EXPAND_STACK_PARM
10299 ? target
: NULL_RTX
),
10301 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
10303 if (MEM_P (orig_op0
))
10307 /* Get a reference to just this component. */
10308 if (modifier
== EXPAND_CONST_ADDRESS
10309 || modifier
== EXPAND_SUM
10310 || modifier
== EXPAND_INITIALIZER
)
10311 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10313 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10315 if (op0
== orig_op0
)
10316 op0
= copy_rtx (op0
);
10318 set_mem_attributes (op0
, treeop0
, 0);
10319 if (REG_P (XEXP (op0
, 0)))
10320 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10322 MEM_VOLATILE_P (op0
) |= volatilep
;
10328 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
10330 /* If the input and output modes are both the same, we are done. */
10331 if (mode
== GET_MODE (op0
))
10333 /* If neither mode is BLKmode, and both modes are the same size
10334 then we can use gen_lowpart. */
10335 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10336 && (GET_MODE_PRECISION (mode
)
10337 == GET_MODE_PRECISION (GET_MODE (op0
)))
10338 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10340 if (GET_CODE (op0
) == SUBREG
)
10341 op0
= force_reg (GET_MODE (op0
), op0
);
10342 temp
= gen_lowpart_common (mode
, op0
);
10347 if (!REG_P (op0
) && !MEM_P (op0
))
10348 op0
= force_reg (GET_MODE (op0
), op0
);
10349 op0
= gen_lowpart (mode
, op0
);
10352 /* If both types are integral, convert from one mode to the other. */
10353 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10354 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10355 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10356 /* As a last resort, spill op0 to memory, and reload it in a
10358 else if (!MEM_P (op0
))
10360 /* If the operand is not a MEM, force it into memory. Since we
10361 are going to be changing the mode of the MEM, don't call
10362 force_const_mem for constants because we don't allow pool
10363 constants to change mode. */
10364 tree inner_type
= TREE_TYPE (treeop0
);
10366 gcc_assert (!TREE_ADDRESSABLE (exp
));
10368 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10370 = assign_stack_temp_for_type
10371 (TYPE_MODE (inner_type
),
10372 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10374 emit_move_insn (target
, op0
);
10378 /* At this point, OP0 is in the correct mode. If the output type is
10379 such that the operand is known to be aligned, indicate that it is.
10380 Otherwise, we need only be concerned about alignment for non-BLKmode
10384 enum insn_code icode
;
10386 if (TYPE_ALIGN_OK (type
))
10388 /* ??? Copying the MEM without substantially changing it might
10389 run afoul of the code handling volatile memory references in
10390 store_expr, which assumes that TARGET is returned unmodified
10391 if it has been used. */
10392 op0
= copy_rtx (op0
);
10393 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10395 else if (mode
!= BLKmode
10396 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
)
10397 /* If the target does have special handling for unaligned
10398 loads of mode then use them. */
10399 && ((icode
= optab_handler (movmisalign_optab
, mode
))
10400 != CODE_FOR_nothing
))
10404 op0
= adjust_address (op0
, mode
, 0);
10405 /* We've already validated the memory, and we're creating a
10406 new pseudo destination. The predicates really can't
10408 reg
= gen_reg_rtx (mode
);
10410 /* Nor can the insn generator. */
10411 insn
= GEN_FCN (icode
) (reg
, op0
);
10415 else if (STRICT_ALIGNMENT
10417 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10419 tree inner_type
= TREE_TYPE (treeop0
);
10420 HOST_WIDE_INT temp_size
10421 = MAX (int_size_in_bytes (inner_type
),
10422 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10424 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10425 rtx new_with_op0_mode
10426 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10428 gcc_assert (!TREE_ADDRESSABLE (exp
));
10430 if (GET_MODE (op0
) == BLKmode
)
10431 emit_block_move (new_with_op0_mode
, op0
,
10432 GEN_INT (GET_MODE_SIZE (mode
)),
10433 (modifier
== EXPAND_STACK_PARM
10434 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10436 emit_move_insn (new_with_op0_mode
, op0
);
10441 op0
= adjust_address (op0
, mode
, 0);
10448 tree lhs
= treeop0
;
10449 tree rhs
= treeop1
;
10450 gcc_assert (ignore
);
10452 /* Check for |= or &= of a bitfield of size one into another bitfield
10453 of size 1. In this case, (unless we need the result of the
10454 assignment) we can do this more efficiently with a
10455 test followed by an assignment, if necessary.
10457 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10458 things change so we do, this code should be enhanced to
10460 if (TREE_CODE (lhs
) == COMPONENT_REF
10461 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10462 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10463 && TREE_OPERAND (rhs
, 0) == lhs
10464 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10465 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10466 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10468 rtx label
= gen_label_rtx ();
10469 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10470 do_jump (TREE_OPERAND (rhs
, 1),
10472 value
? 0 : label
, -1);
10473 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10475 do_pending_stack_adjust ();
10476 emit_label (label
);
10480 expand_assignment (lhs
, rhs
, false);
10485 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10487 case REALPART_EXPR
:
10488 op0
= expand_normal (treeop0
);
10489 return read_complex_part (op0
, false);
10491 case IMAGPART_EXPR
:
10492 op0
= expand_normal (treeop0
);
10493 return read_complex_part (op0
, true);
10500 /* Expanded in cfgexpand.c. */
10501 gcc_unreachable ();
10503 case TRY_CATCH_EXPR
:
10505 case EH_FILTER_EXPR
:
10506 case TRY_FINALLY_EXPR
:
10507 /* Lowered by tree-eh.c. */
10508 gcc_unreachable ();
10510 case WITH_CLEANUP_EXPR
:
10511 case CLEANUP_POINT_EXPR
:
10513 case CASE_LABEL_EXPR
:
10518 case COMPOUND_EXPR
:
10519 case PREINCREMENT_EXPR
:
10520 case PREDECREMENT_EXPR
:
10521 case POSTINCREMENT_EXPR
:
10522 case POSTDECREMENT_EXPR
:
10525 case COMPOUND_LITERAL_EXPR
:
10526 /* Lowered by gimplify.c. */
10527 gcc_unreachable ();
10530 /* Function descriptors are not valid except for as
10531 initialization constants, and should not be expanded. */
10532 gcc_unreachable ();
10534 case WITH_SIZE_EXPR
:
10535 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10536 have pulled out the size to use in whatever context it needed. */
10537 return expand_expr_real (treeop0
, original_target
, tmode
,
10538 modifier
, alt_rtl
);
10541 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10545 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10546 signedness of TYPE), possibly returning the result in TARGET. */
10548 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10550 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10551 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10553 /* For constant values, reduce using build_int_cst_type. */
10554 if (CONST_INT_P (exp
))
10556 HOST_WIDE_INT value
= INTVAL (exp
);
10557 tree t
= build_int_cst_type (type
, value
);
10558 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10560 else if (TYPE_UNSIGNED (type
))
10562 rtx mask
= immed_double_int_const (double_int::mask (prec
),
10564 return expand_and (GET_MODE (exp
), exp
, mask
, target
);
10568 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10569 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10570 exp
, count
, target
, 0);
10571 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10572 exp
, count
, target
, 0);
10576 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10577 when applied to the address of EXP produces an address known to be
10578 aligned more than BIGGEST_ALIGNMENT. */
10581 is_aligning_offset (const_tree offset
, const_tree exp
)
10583 /* Strip off any conversions. */
10584 while (CONVERT_EXPR_P (offset
))
10585 offset
= TREE_OPERAND (offset
, 0);
10587 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10588 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10589 if (TREE_CODE (offset
) != BIT_AND_EXPR
10590 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
10591 || compare_tree_int (TREE_OPERAND (offset
, 1),
10592 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10593 || !exact_log2 (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1) < 0)
10596 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10597 It must be NEGATE_EXPR. Then strip any more conversions. */
10598 offset
= TREE_OPERAND (offset
, 0);
10599 while (CONVERT_EXPR_P (offset
))
10600 offset
= TREE_OPERAND (offset
, 0);
10602 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10605 offset
= TREE_OPERAND (offset
, 0);
10606 while (CONVERT_EXPR_P (offset
))
10607 offset
= TREE_OPERAND (offset
, 0);
10609 /* This must now be the address of EXP. */
10610 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10613 /* Return the tree node if an ARG corresponds to a string constant or zero
10614 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10615 in bytes within the string that ARG is accessing. The type of the
10616 offset will be `sizetype'. */
10619 string_constant (tree arg
, tree
*ptr_offset
)
10621 tree array
, offset
, lower_bound
;
10624 if (TREE_CODE (arg
) == ADDR_EXPR
)
10626 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10628 *ptr_offset
= size_zero_node
;
10629 return TREE_OPERAND (arg
, 0);
10631 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10633 array
= TREE_OPERAND (arg
, 0);
10634 offset
= size_zero_node
;
10636 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10638 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10639 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10640 if (TREE_CODE (array
) != STRING_CST
10641 && TREE_CODE (array
) != VAR_DECL
)
10644 /* Check if the array has a nonzero lower bound. */
10645 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10646 if (!integer_zerop (lower_bound
))
10648 /* If the offset and base aren't both constants, return 0. */
10649 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10651 if (TREE_CODE (offset
) != INTEGER_CST
)
10653 /* Adjust offset by the lower bound. */
10654 offset
= size_diffop (fold_convert (sizetype
, offset
),
10655 fold_convert (sizetype
, lower_bound
));
10658 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10660 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10661 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10662 if (TREE_CODE (array
) != ADDR_EXPR
)
10664 array
= TREE_OPERAND (array
, 0);
10665 if (TREE_CODE (array
) != STRING_CST
10666 && TREE_CODE (array
) != VAR_DECL
)
10672 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10674 tree arg0
= TREE_OPERAND (arg
, 0);
10675 tree arg1
= TREE_OPERAND (arg
, 1);
10680 if (TREE_CODE (arg0
) == ADDR_EXPR
10681 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10682 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10684 array
= TREE_OPERAND (arg0
, 0);
10687 else if (TREE_CODE (arg1
) == ADDR_EXPR
10688 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10689 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10691 array
= TREE_OPERAND (arg1
, 0);
10700 if (TREE_CODE (array
) == STRING_CST
)
10702 *ptr_offset
= fold_convert (sizetype
, offset
);
10705 else if (TREE_CODE (array
) == VAR_DECL
10706 || TREE_CODE (array
) == CONST_DECL
)
10709 tree init
= ctor_for_folding (array
);
10711 /* Variables initialized to string literals can be handled too. */
10712 if (init
== error_mark_node
10714 || TREE_CODE (init
) != STRING_CST
)
10717 /* Avoid const char foo[4] = "abcde"; */
10718 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10719 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10720 || (length
= TREE_STRING_LENGTH (init
)) <= 0
10721 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10724 /* If variable is bigger than the string literal, OFFSET must be constant
10725 and inside of the bounds of the string literal. */
10726 offset
= fold_convert (sizetype
, offset
);
10727 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10728 && (! tree_fits_uhwi_p (offset
)
10729 || compare_tree_int (offset
, length
) >= 0))
10732 *ptr_offset
= offset
;
10739 /* Generate code to calculate OPS, and exploded expression
10740 using a store-flag instruction and return an rtx for the result.
10741 OPS reflects a comparison.
10743 If TARGET is nonzero, store the result there if convenient.
10745 Return zero if there is no suitable set-flag instruction
10746 available on this machine.
10748 Once expand_expr has been called on the arguments of the comparison,
10749 we are committed to doing the store flag, since it is not safe to
10750 re-evaluate the expression. We emit the store-flag insn by calling
10751 emit_store_flag, but only expand the arguments if we have a reason
10752 to believe that emit_store_flag will be successful. If we think that
10753 it will, but it isn't, we have to simulate the store-flag with a
10754 set/jump/set sequence. */
10757 do_store_flag (sepops ops
, rtx target
, enum machine_mode mode
)
10759 enum rtx_code code
;
10760 tree arg0
, arg1
, type
;
10762 enum machine_mode operand_mode
;
10765 rtx subtarget
= target
;
10766 location_t loc
= ops
->location
;
10771 /* Don't crash if the comparison was erroneous. */
10772 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10775 type
= TREE_TYPE (arg0
);
10776 operand_mode
= TYPE_MODE (type
);
10777 unsignedp
= TYPE_UNSIGNED (type
);
10779 /* We won't bother with BLKmode store-flag operations because it would mean
10780 passing a lot of information to emit_store_flag. */
10781 if (operand_mode
== BLKmode
)
10784 /* We won't bother with store-flag operations involving function pointers
10785 when function pointers must be canonicalized before comparisons. */
10786 #ifdef HAVE_canonicalize_funcptr_for_compare
10787 if (HAVE_canonicalize_funcptr_for_compare
10788 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10789 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10791 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10792 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10793 == FUNCTION_TYPE
))))
10800 /* For vector typed comparisons emit code to generate the desired
10801 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10802 expander for this. */
10803 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10805 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10806 tree if_true
= constant_boolean_node (true, ops
->type
);
10807 tree if_false
= constant_boolean_node (false, ops
->type
);
10808 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10811 /* Get the rtx comparison code to use. We know that EXP is a comparison
10812 operation of some type. Some comparisons against 1 and -1 can be
10813 converted to comparisons with zero. Do so here so that the tests
10814 below will be aware that we have a comparison with zero. These
10815 tests will not catch constants in the first operand, but constants
10816 are rarely passed as the first operand. */
10827 if (integer_onep (arg1
))
10828 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
10830 code
= unsignedp
? LTU
: LT
;
10833 if (! unsignedp
&& integer_all_onesp (arg1
))
10834 arg1
= integer_zero_node
, code
= LT
;
10836 code
= unsignedp
? LEU
: LE
;
10839 if (! unsignedp
&& integer_all_onesp (arg1
))
10840 arg1
= integer_zero_node
, code
= GE
;
10842 code
= unsignedp
? GTU
: GT
;
10845 if (integer_onep (arg1
))
10846 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
10848 code
= unsignedp
? GEU
: GE
;
10851 case UNORDERED_EXPR
:
10877 gcc_unreachable ();
10880 /* Put a constant second. */
10881 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
10882 || TREE_CODE (arg0
) == FIXED_CST
)
10884 tem
= arg0
; arg0
= arg1
; arg1
= tem
;
10885 code
= swap_condition (code
);
10888 /* If this is an equality or inequality test of a single bit, we can
10889 do this by shifting the bit being tested to the low-order bit and
10890 masking the result with the constant 1. If the condition was EQ,
10891 we xor it with 1. This does not require an scc insn and is faster
10892 than an scc insn even if we have it.
10894 The code to make this transformation was moved into fold_single_bit_test,
10895 so we just call into the folder and expand its result. */
10897 if ((code
== NE
|| code
== EQ
)
10898 && integer_zerop (arg1
)
10899 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
10901 gimple srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
10903 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
10905 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
10906 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10907 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
10908 gimple_assign_rhs1 (srcstmt
),
10909 gimple_assign_rhs2 (srcstmt
));
10910 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
10912 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
10916 if (! get_subtarget (target
)
10917 || GET_MODE (subtarget
) != operand_mode
)
10920 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10923 target
= gen_reg_rtx (mode
);
10925 /* Try a cstore if possible. */
10926 return emit_store_flag_force (target
, code
, op0
, op1
,
10927 operand_mode
, unsignedp
,
10928 (TYPE_PRECISION (ops
->type
) == 1
10929 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
10933 /* Stubs in case we haven't got a casesi insn. */
10934 #ifndef HAVE_casesi
10935 # define HAVE_casesi 0
10936 # define gen_casesi(a, b, c, d, e) (0)
10937 # define CODE_FOR_casesi CODE_FOR_nothing
10940 /* Attempt to generate a casesi instruction. Returns 1 if successful,
10941 0 otherwise (i.e. if there is no casesi instruction).
10943 DEFAULT_PROBABILITY is the probability of jumping to the default
10946 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
10947 rtx table_label
, rtx default_label
, rtx fallback_label
,
10948 int default_probability
)
10950 struct expand_operand ops
[5];
10951 enum machine_mode index_mode
= SImode
;
10952 rtx op1
, op2
, index
;
10957 /* Convert the index to SImode. */
10958 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
10960 enum machine_mode omode
= TYPE_MODE (index_type
);
10961 rtx rangertx
= expand_normal (range
);
10963 /* We must handle the endpoints in the original mode. */
10964 index_expr
= build2 (MINUS_EXPR
, index_type
,
10965 index_expr
, minval
);
10966 minval
= integer_zero_node
;
10967 index
= expand_normal (index_expr
);
10969 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
10970 omode
, 1, default_label
,
10971 default_probability
);
10972 /* Now we can safely truncate. */
10973 index
= convert_to_mode (index_mode
, index
, 0);
10977 if (TYPE_MODE (index_type
) != index_mode
)
10979 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
10980 index_expr
= fold_convert (index_type
, index_expr
);
10983 index
= expand_normal (index_expr
);
10986 do_pending_stack_adjust ();
10988 op1
= expand_normal (minval
);
10989 op2
= expand_normal (range
);
10991 create_input_operand (&ops
[0], index
, index_mode
);
10992 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
10993 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
10994 create_fixed_operand (&ops
[3], table_label
);
10995 create_fixed_operand (&ops
[4], (default_label
10997 : fallback_label
));
10998 expand_jump_insn (CODE_FOR_casesi
, 5, ops
);
11002 /* Attempt to generate a tablejump instruction; same concept. */
11003 #ifndef HAVE_tablejump
11004 #define HAVE_tablejump 0
11005 #define gen_tablejump(x, y) (0)
11008 /* Subroutine of the next function.
11010 INDEX is the value being switched on, with the lowest value
11011 in the table already subtracted.
11012 MODE is its expected mode (needed if INDEX is constant).
11013 RANGE is the length of the jump table.
11014 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11016 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11017 index value is out of range.
11018 DEFAULT_PROBABILITY is the probability of jumping to
11019 the default label. */
11022 do_tablejump (rtx index
, enum machine_mode mode
, rtx range
, rtx table_label
,
11023 rtx default_label
, int default_probability
)
11027 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11028 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11030 /* Do an unsigned comparison (in the proper mode) between the index
11031 expression and the value which represents the length of the range.
11032 Since we just finished subtracting the lower bound of the range
11033 from the index expression, this comparison allows us to simultaneously
11034 check that the original index expression value is both greater than
11035 or equal to the minimum value of the range and less than or equal to
11036 the maximum value of the range. */
11039 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11040 default_label
, default_probability
);
11043 /* If index is in range, it must fit in Pmode.
11044 Convert to Pmode so we can index with it. */
11046 index
= convert_to_mode (Pmode
, index
, 1);
11048 /* Don't let a MEM slip through, because then INDEX that comes
11049 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11050 and break_out_memory_refs will go to work on it and mess it up. */
11051 #ifdef PIC_CASE_VECTOR_ADDRESS
11052 if (flag_pic
&& !REG_P (index
))
11053 index
= copy_to_mode_reg (Pmode
, index
);
11056 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11057 GET_MODE_SIZE, because this indicates how large insns are. The other
11058 uses should all be Pmode, because they are addresses. This code
11059 could fail if addresses and insns are not the same size. */
11060 index
= gen_rtx_PLUS
11062 gen_rtx_MULT (Pmode
, index
,
11063 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
), Pmode
)),
11064 gen_rtx_LABEL_REF (Pmode
, table_label
));
11065 #ifdef PIC_CASE_VECTOR_ADDRESS
11067 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11070 index
= memory_address (CASE_VECTOR_MODE
, index
);
11071 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11072 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11073 convert_move (temp
, vector
, 0);
11075 emit_jump_insn (gen_tablejump (temp
, table_label
));
11077 /* If we are generating PIC code or if the table is PC-relative, the
11078 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11079 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11084 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11085 rtx table_label
, rtx default_label
, int default_probability
)
11089 if (! HAVE_tablejump
)
11092 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11093 fold_convert (index_type
, index_expr
),
11094 fold_convert (index_type
, minval
));
11095 index
= expand_normal (index_expr
);
11096 do_pending_stack_adjust ();
11098 do_tablejump (index
, TYPE_MODE (index_type
),
11099 convert_modes (TYPE_MODE (index_type
),
11100 TYPE_MODE (TREE_TYPE (range
)),
11101 expand_normal (range
),
11102 TYPE_UNSIGNED (TREE_TYPE (range
))),
11103 table_label
, default_label
, default_probability
);
11107 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11109 const_vector_from_tree (tree exp
)
11115 enum machine_mode inner
, mode
;
11117 mode
= TYPE_MODE (TREE_TYPE (exp
));
11119 if (initializer_zerop (exp
))
11120 return CONST0_RTX (mode
);
11122 units
= GET_MODE_NUNITS (mode
);
11123 inner
= GET_MODE_INNER (mode
);
11125 v
= rtvec_alloc (units
);
11127 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11129 elt
= VECTOR_CST_ELT (exp
, i
);
11131 if (TREE_CODE (elt
) == REAL_CST
)
11132 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11134 else if (TREE_CODE (elt
) == FIXED_CST
)
11135 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11138 RTVEC_ELT (v
, i
) = immed_double_int_const (tree_to_double_int (elt
),
11142 return gen_rtx_CONST_VECTOR (mode
, v
);
11145 /* Build a decl for a personality function given a language prefix. */
11148 build_personality_function (const char *lang
)
11150 const char *unwind_and_version
;
11154 switch (targetm_common
.except_unwind_info (&global_options
))
11159 unwind_and_version
= "_sj0";
11163 unwind_and_version
= "_v0";
11166 unwind_and_version
= "_seh0";
11169 gcc_unreachable ();
11172 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11174 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11175 long_long_unsigned_type_node
,
11176 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11177 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11178 get_identifier (name
), type
);
11179 DECL_ARTIFICIAL (decl
) = 1;
11180 DECL_EXTERNAL (decl
) = 1;
11181 TREE_PUBLIC (decl
) = 1;
11183 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11184 are the flags assigned by targetm.encode_section_info. */
11185 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11190 /* Extracts the personality function of DECL and returns the corresponding
11194 get_personality_function (tree decl
)
11196 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11197 enum eh_personality_kind pk
;
11199 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11200 if (pk
== eh_personality_none
)
11204 && pk
== eh_personality_any
)
11205 personality
= lang_hooks
.eh_personality ();
11207 if (pk
== eh_personality_lang
)
11208 gcc_assert (personality
!= NULL_TREE
);
11210 return XEXP (DECL_RTL (personality
), 0);
11213 #include "gt-expr.h"