1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 #include "stringpool.h"
28 #include "stor-layout.h"
33 #include "hard-reg-set.h"
36 #include "insn-config.h"
37 #include "insn-attr.h"
38 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
44 #include "typeclass.h"
46 #include "langhooks.h"
49 #include "tree-iterator.h"
51 #include "gimple-ssa.h"
53 #include "tree-ssanames.h"
55 #include "common/common-target.h"
58 #include "diagnostic.h"
59 #include "tree-ssa-live.h"
60 #include "tree-outof-ssa.h"
61 #include "target-globals.h"
63 #include "tree-ssa-address.h"
64 #include "cfgexpand.h"
66 /* Decide whether a function's arguments should be processed
67 from first to last or from last to first.
69 They should if the stack and args grow in opposite directions, but
70 only if we have push insns. */
74 #ifndef PUSH_ARGS_REVERSED
75 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
76 #define PUSH_ARGS_REVERSED /* If it's last to first. */
82 #ifndef STACK_PUSH_CODE
83 #ifdef STACK_GROWS_DOWNWARD
84 #define STACK_PUSH_CODE PRE_DEC
86 #define STACK_PUSH_CODE PRE_INC
91 /* If this is nonzero, we do not bother generating VOLATILE
92 around volatile memory references, and we are willing to
93 output indirect addresses. If cse is to follow, we reject
94 indirect addresses so a useful potential cse is generated;
95 if it is used only once, instruction combination will produce
96 the same indirect address eventually. */
99 /* This structure is used by move_by_pieces to describe the move to
101 struct move_by_pieces_d
110 int explicit_inc_from
;
111 unsigned HOST_WIDE_INT len
;
112 HOST_WIDE_INT offset
;
116 /* This structure is used by store_by_pieces to describe the clear to
119 struct store_by_pieces_d
125 unsigned HOST_WIDE_INT len
;
126 HOST_WIDE_INT offset
;
127 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
);
132 static void move_by_pieces_1 (insn_gen_fn
, machine_mode
,
133 struct move_by_pieces_d
*);
134 static bool block_move_libcall_safe_for_call_parm (void);
135 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned, unsigned, HOST_WIDE_INT
,
136 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
137 unsigned HOST_WIDE_INT
);
138 static tree
emit_block_move_libcall_fn (int);
139 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
140 static rtx
clear_by_pieces_1 (void *, HOST_WIDE_INT
, enum machine_mode
);
141 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
142 static void store_by_pieces_1 (struct store_by_pieces_d
*, unsigned int);
143 static void store_by_pieces_2 (insn_gen_fn
, machine_mode
,
144 struct store_by_pieces_d
*);
145 static tree
clear_storage_libcall_fn (int);
146 static rtx
compress_float_constant (rtx
, rtx
);
147 static rtx
get_subtarget (rtx
);
148 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
149 HOST_WIDE_INT
, enum machine_mode
,
150 tree
, int, alias_set_type
);
151 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
);
152 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
,
153 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
154 enum machine_mode
, tree
, alias_set_type
, bool);
156 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
158 static int is_aligning_offset (const_tree
, const_tree
);
159 static void expand_operands (tree
, tree
, rtx
, rtx
*, rtx
*,
160 enum expand_modifier
);
161 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
162 static rtx
do_store_flag (sepops
, rtx
, enum machine_mode
);
164 static void emit_single_push_insn (enum machine_mode
, rtx
, tree
);
166 static void do_tablejump (rtx
, enum machine_mode
, rtx
, rtx
, rtx
, int);
167 static rtx
const_vector_from_tree (tree
);
168 static void write_complex_part (rtx
, rtx
, bool);
170 /* This macro is used to determine whether move_by_pieces should be called
171 to perform a structure copy. */
172 #ifndef MOVE_BY_PIECES_P
173 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
174 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
175 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
178 /* This macro is used to determine whether clear_by_pieces should be
179 called to clear storage. */
180 #ifndef CLEAR_BY_PIECES_P
181 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
182 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
183 < (unsigned int) CLEAR_RATIO (optimize_insn_for_speed_p ()))
186 /* This macro is used to determine whether store_by_pieces should be
187 called to "memset" storage with byte values other than zero. */
188 #ifndef SET_BY_PIECES_P
189 #define SET_BY_PIECES_P(SIZE, ALIGN) \
190 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
191 < (unsigned int) SET_RATIO (optimize_insn_for_speed_p ()))
194 /* This macro is used to determine whether store_by_pieces should be
195 called to "memcpy" storage when the source is a constant string. */
196 #ifndef STORE_BY_PIECES_P
197 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
198 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
199 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
202 /* This is run to set up which modes can be used
203 directly in memory and to initialize the block move optab. It is run
204 at the beginning of compilation and when the target is reinitialized. */
207 init_expr_target (void)
210 enum machine_mode mode
;
215 /* Try indexing by frame ptr and try by stack ptr.
216 It is known that on the Convex the stack ptr isn't a valid index.
217 With luck, one or the other is valid on any machine. */
218 mem
= gen_rtx_MEM (VOIDmode
, stack_pointer_rtx
);
219 mem1
= gen_rtx_MEM (VOIDmode
, frame_pointer_rtx
);
221 /* A scratch register we can modify in-place below to avoid
222 useless RTL allocations. */
223 reg
= gen_rtx_REG (VOIDmode
, -1);
225 insn
= rtx_alloc (INSN
);
226 pat
= gen_rtx_SET (VOIDmode
, NULL_RTX
, NULL_RTX
);
227 PATTERN (insn
) = pat
;
229 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
230 mode
= (enum machine_mode
) ((int) mode
+ 1))
234 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
235 PUT_MODE (mem
, mode
);
236 PUT_MODE (mem1
, mode
);
237 PUT_MODE (reg
, mode
);
239 /* See if there is some register that can be used in this mode and
240 directly loaded or stored from memory. */
242 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
243 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
244 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
247 if (! HARD_REGNO_MODE_OK (regno
, mode
))
250 SET_REGNO (reg
, regno
);
253 SET_DEST (pat
) = reg
;
254 if (recog (pat
, insn
, &num_clobbers
) >= 0)
255 direct_load
[(int) mode
] = 1;
257 SET_SRC (pat
) = mem1
;
258 SET_DEST (pat
) = reg
;
259 if (recog (pat
, insn
, &num_clobbers
) >= 0)
260 direct_load
[(int) mode
] = 1;
263 SET_DEST (pat
) = mem
;
264 if (recog (pat
, insn
, &num_clobbers
) >= 0)
265 direct_store
[(int) mode
] = 1;
268 SET_DEST (pat
) = mem1
;
269 if (recog (pat
, insn
, &num_clobbers
) >= 0)
270 direct_store
[(int) mode
] = 1;
274 mem
= gen_rtx_MEM (VOIDmode
, gen_rtx_raw_REG (Pmode
, 10000));
276 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
277 mode
= GET_MODE_WIDER_MODE (mode
))
279 enum machine_mode srcmode
;
280 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
281 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
285 ic
= can_extend_p (mode
, srcmode
, 0);
286 if (ic
== CODE_FOR_nothing
)
289 PUT_MODE (mem
, srcmode
);
291 if (insn_operand_matches (ic
, 1, mem
))
292 float_extend_from_mem
[mode
][srcmode
] = true;
297 /* This is run at the start of compiling a function. */
302 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
305 /* Copy data from FROM to TO, where the machine modes are not the same.
306 Both modes may be integer, or both may be floating, or both may be
308 UNSIGNEDP should be nonzero if FROM is an unsigned type.
309 This causes zero-extension instead of sign-extension. */
312 convert_move (rtx to
, rtx from
, int unsignedp
)
314 enum machine_mode to_mode
= GET_MODE (to
);
315 enum machine_mode from_mode
= GET_MODE (from
);
316 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
317 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
321 /* rtx code for making an equivalent value. */
322 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
323 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
326 gcc_assert (to_real
== from_real
);
327 gcc_assert (to_mode
!= BLKmode
);
328 gcc_assert (from_mode
!= BLKmode
);
330 /* If the source and destination are already the same, then there's
335 /* If FROM is a SUBREG that indicates that we have already done at least
336 the required extension, strip it. We don't handle such SUBREGs as
339 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
340 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
341 >= GET_MODE_PRECISION (to_mode
))
342 && SUBREG_PROMOTED_UNSIGNED_P (from
) == unsignedp
)
343 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
345 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
347 if (to_mode
== from_mode
348 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
350 emit_move_insn (to
, from
);
354 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
356 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
358 if (VECTOR_MODE_P (to_mode
))
359 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
361 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
363 emit_move_insn (to
, from
);
367 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
369 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
370 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
379 gcc_assert ((GET_MODE_PRECISION (from_mode
)
380 != GET_MODE_PRECISION (to_mode
))
381 || (DECIMAL_FLOAT_MODE_P (from_mode
)
382 != DECIMAL_FLOAT_MODE_P (to_mode
)));
384 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
385 /* Conversion between decimal float and binary float, same size. */
386 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
387 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
392 /* Try converting directly if the insn is supported. */
394 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
395 if (code
!= CODE_FOR_nothing
)
397 emit_unop_insn (code
, to
, from
,
398 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
402 /* Otherwise use a libcall. */
403 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
405 /* Is this conversion implemented yet? */
406 gcc_assert (libcall
);
409 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
411 insns
= get_insns ();
413 emit_libcall_block (insns
, to
, value
,
414 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
416 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
420 /* Handle pointer conversion. */ /* SPEE 900220. */
421 /* Targets are expected to provide conversion insns between PxImode and
422 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
423 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
425 enum machine_mode full_mode
426 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
428 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
429 != CODE_FOR_nothing
);
431 if (full_mode
!= from_mode
)
432 from
= convert_to_mode (full_mode
, from
, unsignedp
);
433 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
437 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
440 enum machine_mode full_mode
441 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
442 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
443 enum insn_code icode
;
445 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
446 gcc_assert (icode
!= CODE_FOR_nothing
);
448 if (to_mode
== full_mode
)
450 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
454 new_from
= gen_reg_rtx (full_mode
);
455 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
457 /* else proceed to integer conversions below. */
458 from_mode
= full_mode
;
462 /* Make sure both are fixed-point modes or both are not. */
463 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
464 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
465 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
467 /* If we widen from_mode to to_mode and they are in the same class,
468 we won't saturate the result.
469 Otherwise, always saturate the result to play safe. */
470 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
471 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
472 expand_fixed_convert (to
, from
, 0, 0);
474 expand_fixed_convert (to
, from
, 0, 1);
478 /* Now both modes are integers. */
480 /* Handle expanding beyond a word. */
481 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
482 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
489 enum machine_mode lowpart_mode
;
490 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
492 /* Try converting directly if the insn is supported. */
493 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
496 /* If FROM is a SUBREG, put it into a register. Do this
497 so that we always generate the same set of insns for
498 better cse'ing; if an intermediate assignment occurred,
499 we won't be doing the operation directly on the SUBREG. */
500 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
501 from
= force_reg (from_mode
, from
);
502 emit_unop_insn (code
, to
, from
, equiv_code
);
505 /* Next, try converting via full word. */
506 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
507 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
508 != CODE_FOR_nothing
))
510 rtx word_to
= gen_reg_rtx (word_mode
);
513 if (reg_overlap_mentioned_p (to
, from
))
514 from
= force_reg (from_mode
, from
);
517 convert_move (word_to
, from
, unsignedp
);
518 emit_unop_insn (code
, to
, word_to
, equiv_code
);
522 /* No special multiword conversion insn; do it by hand. */
525 /* Since we will turn this into a no conflict block, we must ensure the
526 the source does not overlap the target so force it into an isolated
527 register when maybe so. Likewise for any MEM input, since the
528 conversion sequence might require several references to it and we
529 must ensure we're getting the same value every time. */
531 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
532 from
= force_reg (from_mode
, from
);
534 /* Get a copy of FROM widened to a word, if necessary. */
535 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
536 lowpart_mode
= word_mode
;
538 lowpart_mode
= from_mode
;
540 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
542 lowpart
= gen_lowpart (lowpart_mode
, to
);
543 emit_move_insn (lowpart
, lowfrom
);
545 /* Compute the value to put in each remaining word. */
547 fill_value
= const0_rtx
;
549 fill_value
= emit_store_flag (gen_reg_rtx (word_mode
),
550 LT
, lowfrom
, const0_rtx
,
553 /* Fill the remaining words. */
554 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
556 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
557 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
559 gcc_assert (subword
);
561 if (fill_value
!= subword
)
562 emit_move_insn (subword
, fill_value
);
565 insns
= get_insns ();
572 /* Truncating multi-word to a word or less. */
573 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
574 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
577 && ! MEM_VOLATILE_P (from
)
578 && direct_load
[(int) to_mode
]
579 && ! mode_dependent_address_p (XEXP (from
, 0),
580 MEM_ADDR_SPACE (from
)))
582 || GET_CODE (from
) == SUBREG
))
583 from
= force_reg (from_mode
, from
);
584 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
588 /* Now follow all the conversions between integers
589 no more than a word long. */
591 /* For truncation, usually we can just refer to FROM in a narrower mode. */
592 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
593 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
596 && ! MEM_VOLATILE_P (from
)
597 && direct_load
[(int) to_mode
]
598 && ! mode_dependent_address_p (XEXP (from
, 0),
599 MEM_ADDR_SPACE (from
)))
601 || GET_CODE (from
) == SUBREG
))
602 from
= force_reg (from_mode
, from
);
603 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
604 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
605 from
= copy_to_reg (from
);
606 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
610 /* Handle extension. */
611 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
613 /* Convert directly if that works. */
614 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
617 emit_unop_insn (code
, to
, from
, equiv_code
);
622 enum machine_mode intermediate
;
626 /* Search for a mode to convert via. */
627 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
628 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
629 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
631 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
632 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
633 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
634 != CODE_FOR_nothing
))
636 convert_move (to
, convert_to_mode (intermediate
, from
,
637 unsignedp
), unsignedp
);
641 /* No suitable intermediate mode.
642 Generate what we need with shifts. */
643 shift_amount
= (GET_MODE_PRECISION (to_mode
)
644 - GET_MODE_PRECISION (from_mode
));
645 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
646 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
648 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
651 emit_move_insn (to
, tmp
);
656 /* Support special truncate insns for certain modes. */
657 if (convert_optab_handler (trunc_optab
, to_mode
,
658 from_mode
) != CODE_FOR_nothing
)
660 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
665 /* Handle truncation of volatile memrefs, and so on;
666 the things that couldn't be truncated directly,
667 and for which there was no special instruction.
669 ??? Code above formerly short-circuited this, for most integer
670 mode pairs, with a force_reg in from_mode followed by a recursive
671 call to this routine. Appears always to have been wrong. */
672 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
674 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
675 emit_move_insn (to
, temp
);
679 /* Mode combination is not recognized. */
683 /* Return an rtx for a value that would result
684 from converting X to mode MODE.
685 Both X and MODE may be floating, or both integer.
686 UNSIGNEDP is nonzero if X is an unsigned value.
687 This can be done by referring to a part of X in place
688 or by copying to a new temporary with conversion. */
691 convert_to_mode (enum machine_mode mode
, rtx x
, int unsignedp
)
693 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
696 /* Return an rtx for a value that would result
697 from converting X from mode OLDMODE to mode MODE.
698 Both modes may be floating, or both integer.
699 UNSIGNEDP is nonzero if X is an unsigned value.
701 This can be done by referring to a part of X in place
702 or by copying to a new temporary with conversion.
704 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
707 convert_modes (enum machine_mode mode
, enum machine_mode oldmode
, rtx x
, int unsignedp
)
711 /* If FROM is a SUBREG that indicates that we have already done at least
712 the required extension, strip it. */
714 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
715 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
716 && SUBREG_PROMOTED_UNSIGNED_P (x
) == unsignedp
)
717 x
= gen_lowpart (mode
, x
);
719 if (GET_MODE (x
) != VOIDmode
)
720 oldmode
= GET_MODE (x
);
725 /* There is one case that we must handle specially: If we are converting
726 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
727 we are to interpret the constant as unsigned, gen_lowpart will do
728 the wrong if the constant appears negative. What we want to do is
729 make the high-order word of the constant zero, not all ones. */
731 if (unsignedp
&& GET_MODE_CLASS (mode
) == MODE_INT
732 && GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
733 && CONST_INT_P (x
) && INTVAL (x
) < 0)
735 double_int val
= double_int::from_uhwi (INTVAL (x
));
737 /* We need to zero extend VAL. */
738 if (oldmode
!= VOIDmode
)
739 val
= val
.zext (GET_MODE_BITSIZE (oldmode
));
741 return immed_double_int_const (val
, mode
);
744 /* We can do this with a gen_lowpart if both desired and current modes
745 are integer, and this is either a constant integer, a register, or a
746 non-volatile MEM. Except for the constant case where MODE is no
747 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
750 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
)
751 || (GET_MODE_CLASS (mode
) == MODE_INT
752 && GET_MODE_CLASS (oldmode
) == MODE_INT
753 && (CONST_DOUBLE_AS_INT_P (x
)
754 || (GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
755 && ((MEM_P (x
) && ! MEM_VOLATILE_P (x
)
756 && direct_load
[(int) mode
])
758 && (! HARD_REGISTER_P (x
)
759 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
760 && TRULY_NOOP_TRUNCATION_MODES_P (mode
,
763 /* ?? If we don't know OLDMODE, we have to assume here that
764 X does not need sign- or zero-extension. This may not be
765 the case, but it's the best we can do. */
766 if (CONST_INT_P (x
) && oldmode
!= VOIDmode
767 && GET_MODE_PRECISION (mode
) > GET_MODE_PRECISION (oldmode
))
769 HOST_WIDE_INT val
= INTVAL (x
);
771 /* We must sign or zero-extend in this case. Start by
772 zero-extending, then sign extend if we need to. */
773 val
&= GET_MODE_MASK (oldmode
);
775 && val_signbit_known_set_p (oldmode
, val
))
776 val
|= ~GET_MODE_MASK (oldmode
);
778 return gen_int_mode (val
, mode
);
781 return gen_lowpart (mode
, x
);
784 /* Converting from integer constant into mode is always equivalent to an
786 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
788 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
789 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
792 temp
= gen_reg_rtx (mode
);
793 convert_move (temp
, x
, unsignedp
);
797 /* Return the largest alignment we can use for doing a move (or store)
798 of MAX_PIECES. ALIGN is the largest alignment we could use. */
801 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
803 enum machine_mode tmode
;
805 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
806 if (align
>= GET_MODE_ALIGNMENT (tmode
))
807 align
= GET_MODE_ALIGNMENT (tmode
);
810 enum machine_mode tmode
, xmode
;
812 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
814 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
815 if (GET_MODE_SIZE (tmode
) > max_pieces
816 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
819 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
825 /* Return the widest integer mode no wider than SIZE. If no such mode
826 can be found, return VOIDmode. */
828 static enum machine_mode
829 widest_int_mode_for_size (unsigned int size
)
831 enum machine_mode tmode
, mode
= VOIDmode
;
833 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
834 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
835 if (GET_MODE_SIZE (tmode
) < size
)
841 /* STORE_MAX_PIECES is the number of bytes at a time that we can
842 store efficiently. Due to internal GCC limitations, this is
843 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
844 for an immediate constant. */
846 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
848 /* Determine whether the LEN bytes can be moved by using several move
849 instructions. Return nonzero if a call to move_by_pieces should
853 can_move_by_pieces (unsigned HOST_WIDE_INT len ATTRIBUTE_UNUSED
,
854 unsigned int align ATTRIBUTE_UNUSED
)
856 return MOVE_BY_PIECES_P (len
, align
);
859 /* Generate several move instructions to copy LEN bytes from block FROM to
860 block TO. (These are MEM rtx's with BLKmode).
862 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
863 used to push FROM to the stack.
865 ALIGN is maximum stack alignment we can assume.
867 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
868 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
872 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
873 unsigned int align
, int endp
)
875 struct move_by_pieces_d data
;
876 enum machine_mode to_addr_mode
;
877 enum machine_mode from_addr_mode
= get_address_mode (from
);
878 rtx to_addr
, from_addr
= XEXP (from
, 0);
879 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
880 enum insn_code icode
;
882 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
885 data
.from_addr
= from_addr
;
888 to_addr_mode
= get_address_mode (to
);
889 to_addr
= XEXP (to
, 0);
892 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
893 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
895 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
899 to_addr_mode
= VOIDmode
;
903 #ifdef STACK_GROWS_DOWNWARD
909 data
.to_addr
= to_addr
;
912 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
913 || GET_CODE (from_addr
) == POST_INC
914 || GET_CODE (from_addr
) == POST_DEC
);
916 data
.explicit_inc_from
= 0;
917 data
.explicit_inc_to
= 0;
918 if (data
.reverse
) data
.offset
= len
;
921 /* If copying requires more than two move insns,
922 copy addresses to registers (to make displacements shorter)
923 and use post-increment if available. */
924 if (!(data
.autinc_from
&& data
.autinc_to
)
925 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
927 /* Find the mode of the largest move...
928 MODE might not be used depending on the definitions of the
929 USE_* macros below. */
930 enum machine_mode mode ATTRIBUTE_UNUSED
931 = widest_int_mode_for_size (max_size
);
933 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
935 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
936 plus_constant (from_addr_mode
,
938 data
.autinc_from
= 1;
939 data
.explicit_inc_from
= -1;
941 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
943 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
944 data
.autinc_from
= 1;
945 data
.explicit_inc_from
= 1;
947 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
948 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
949 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
951 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
952 plus_constant (to_addr_mode
,
955 data
.explicit_inc_to
= -1;
957 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
959 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
961 data
.explicit_inc_to
= 1;
963 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
964 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
967 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
969 /* First move what we can in the largest integer mode, then go to
970 successively smaller modes. */
972 while (max_size
> 1 && data
.len
> 0)
974 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
976 if (mode
== VOIDmode
)
979 icode
= optab_handler (mov_optab
, mode
);
980 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
981 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
983 max_size
= GET_MODE_SIZE (mode
);
986 /* The code above should have handled everything. */
987 gcc_assert (!data
.len
);
993 gcc_assert (!data
.reverse
);
998 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
999 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
1001 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
1002 plus_constant (to_addr_mode
,
1006 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
1013 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
1021 /* Return number of insns required to move L bytes by pieces.
1022 ALIGN (in bits) is maximum alignment we can assume. */
1024 unsigned HOST_WIDE_INT
1025 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
1026 unsigned int max_size
)
1028 unsigned HOST_WIDE_INT n_insns
= 0;
1030 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
1032 while (max_size
> 1 && l
> 0)
1034 enum machine_mode mode
;
1035 enum insn_code icode
;
1037 mode
= widest_int_mode_for_size (max_size
);
1039 if (mode
== VOIDmode
)
1042 icode
= optab_handler (mov_optab
, mode
);
1043 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
1044 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
1046 max_size
= GET_MODE_SIZE (mode
);
1053 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1054 with move instructions for mode MODE. GENFUN is the gen_... function
1055 to make a move insn for that mode. DATA has all the other info. */
1058 move_by_pieces_1 (insn_gen_fn genfun
, machine_mode mode
,
1059 struct move_by_pieces_d
*data
)
1061 unsigned int size
= GET_MODE_SIZE (mode
);
1062 rtx to1
= NULL_RTX
, from1
;
1064 while (data
->len
>= size
)
1067 data
->offset
-= size
;
1071 if (data
->autinc_to
)
1072 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1075 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1078 if (data
->autinc_from
)
1079 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1082 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1084 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1085 emit_insn (gen_add2_insn (data
->to_addr
,
1086 gen_int_mode (-(HOST_WIDE_INT
) size
,
1087 GET_MODE (data
->to_addr
))));
1088 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1089 emit_insn (gen_add2_insn (data
->from_addr
,
1090 gen_int_mode (-(HOST_WIDE_INT
) size
,
1091 GET_MODE (data
->from_addr
))));
1094 emit_insn ((*genfun
) (to1
, from1
));
1097 #ifdef PUSH_ROUNDING
1098 emit_single_push_insn (mode
, from1
, NULL
);
1104 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1105 emit_insn (gen_add2_insn (data
->to_addr
,
1107 GET_MODE (data
->to_addr
))));
1108 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1109 emit_insn (gen_add2_insn (data
->from_addr
,
1111 GET_MODE (data
->from_addr
))));
1113 if (! data
->reverse
)
1114 data
->offset
+= size
;
1120 /* Emit code to move a block Y to a block X. This may be done with
1121 string-move instructions, with multiple scalar move instructions,
1122 or with a library call.
1124 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1125 SIZE is an rtx that says how long they are.
1126 ALIGN is the maximum alignment we can assume they have.
1127 METHOD describes what kind of copy this is, and what mechanisms may be used.
1128 MIN_SIZE is the minimal size of block to move
1129 MAX_SIZE is the maximal size of block to move, if it can not be represented
1130 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1132 Return the address of the new block, if memcpy is called and returns it,
1136 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1137 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1138 unsigned HOST_WIDE_INT min_size
,
1139 unsigned HOST_WIDE_INT max_size
,
1140 unsigned HOST_WIDE_INT probable_max_size
)
1147 if (CONST_INT_P (size
)
1148 && INTVAL (size
) == 0)
1153 case BLOCK_OP_NORMAL
:
1154 case BLOCK_OP_TAILCALL
:
1155 may_use_call
= true;
1158 case BLOCK_OP_CALL_PARM
:
1159 may_use_call
= block_move_libcall_safe_for_call_parm ();
1161 /* Make inhibit_defer_pop nonzero around the library call
1162 to force it to pop the arguments right away. */
1166 case BLOCK_OP_NO_LIBCALL
:
1167 may_use_call
= false;
1174 gcc_assert (MEM_P (x
) && MEM_P (y
));
1175 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1176 gcc_assert (align
>= BITS_PER_UNIT
);
1178 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1179 block copy is more efficient for other large modes, e.g. DCmode. */
1180 x
= adjust_address (x
, BLKmode
, 0);
1181 y
= adjust_address (y
, BLKmode
, 0);
1183 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1184 can be incorrect is coming from __builtin_memcpy. */
1185 if (CONST_INT_P (size
))
1187 x
= shallow_copy_rtx (x
);
1188 y
= shallow_copy_rtx (y
);
1189 set_mem_size (x
, INTVAL (size
));
1190 set_mem_size (y
, INTVAL (size
));
1193 if (CONST_INT_P (size
) && MOVE_BY_PIECES_P (INTVAL (size
), align
))
1194 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1195 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1196 expected_align
, expected_size
,
1197 min_size
, max_size
, probable_max_size
))
1199 else if (may_use_call
1200 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1201 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1203 /* Since x and y are passed to a libcall, mark the corresponding
1204 tree EXPR as addressable. */
1205 tree y_expr
= MEM_EXPR (y
);
1206 tree x_expr
= MEM_EXPR (x
);
1208 mark_addressable (y_expr
);
1210 mark_addressable (x_expr
);
1211 retval
= emit_block_move_via_libcall (x
, y
, size
,
1212 method
== BLOCK_OP_TAILCALL
);
1216 emit_block_move_via_loop (x
, y
, size
, align
);
1218 if (method
== BLOCK_OP_CALL_PARM
)
1225 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1227 unsigned HOST_WIDE_INT max
, min
= 0;
1228 if (GET_CODE (size
) == CONST_INT
)
1229 min
= max
= UINTVAL (size
);
1231 max
= GET_MODE_MASK (GET_MODE (size
));
1232 return emit_block_move_hints (x
, y
, size
, method
, 0, -1,
1236 /* A subroutine of emit_block_move. Returns true if calling the
1237 block move libcall will not clobber any parameters which may have
1238 already been placed on the stack. */
1241 block_move_libcall_safe_for_call_parm (void)
1243 #if defined (REG_PARM_STACK_SPACE)
1247 /* If arguments are pushed on the stack, then they're safe. */
1251 /* If registers go on the stack anyway, any argument is sure to clobber
1252 an outgoing argument. */
1253 #if defined (REG_PARM_STACK_SPACE)
1254 fn
= emit_block_move_libcall_fn (false);
1255 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1256 depend on its argument. */
1258 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1259 && REG_PARM_STACK_SPACE (fn
) != 0)
1263 /* If any argument goes in memory, then it might clobber an outgoing
1266 CUMULATIVE_ARGS args_so_far_v
;
1267 cumulative_args_t args_so_far
;
1270 fn
= emit_block_move_libcall_fn (false);
1271 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1272 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1274 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1275 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1277 enum machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1278 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1280 if (!tmp
|| !REG_P (tmp
))
1282 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1284 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1291 /* A subroutine of emit_block_move. Expand a movmem pattern;
1292 return true if successful. */
1295 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1296 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1297 unsigned HOST_WIDE_INT min_size
,
1298 unsigned HOST_WIDE_INT max_size
,
1299 unsigned HOST_WIDE_INT probable_max_size
)
1301 int save_volatile_ok
= volatile_ok
;
1302 enum machine_mode mode
;
1304 if (expected_align
< align
)
1305 expected_align
= align
;
1306 if (expected_size
!= -1)
1308 if ((unsigned HOST_WIDE_INT
)expected_size
> probable_max_size
)
1309 expected_size
= probable_max_size
;
1310 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
1311 expected_size
= min_size
;
1314 /* Since this is a move insn, we don't care about volatility. */
1317 /* Try the most limited insn first, because there's no point
1318 including more than one in the machine description unless
1319 the more limited one has some advantage. */
1321 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1322 mode
= GET_MODE_WIDER_MODE (mode
))
1324 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1326 if (code
!= CODE_FOR_nothing
1327 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1328 here because if SIZE is less than the mode mask, as it is
1329 returned by the macro, it will definitely be less than the
1330 actual mode mask. Since SIZE is within the Pmode address
1331 space, we limit MODE to Pmode. */
1332 && ((CONST_INT_P (size
)
1333 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1334 <= (GET_MODE_MASK (mode
) >> 1)))
1335 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
1336 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
1338 struct expand_operand ops
[9];
1341 /* ??? When called via emit_block_move_for_call, it'd be
1342 nice if there were some way to inform the backend, so
1343 that it doesn't fail the expansion because it thinks
1344 emitting the libcall would be more efficient. */
1345 nops
= insn_data
[(int) code
].n_generator_args
;
1346 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
1348 create_fixed_operand (&ops
[0], x
);
1349 create_fixed_operand (&ops
[1], y
);
1350 /* The check above guarantees that this size conversion is valid. */
1351 create_convert_operand_to (&ops
[2], size
, mode
, true);
1352 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1355 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1356 create_integer_operand (&ops
[5], expected_size
);
1360 create_integer_operand (&ops
[6], min_size
);
1361 /* If we can not represent the maximal size,
1362 make parameter NULL. */
1363 if ((HOST_WIDE_INT
) max_size
!= -1)
1364 create_integer_operand (&ops
[7], max_size
);
1366 create_fixed_operand (&ops
[7], NULL
);
1370 /* If we can not represent the maximal size,
1371 make parameter NULL. */
1372 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
1373 create_integer_operand (&ops
[8], probable_max_size
);
1375 create_fixed_operand (&ops
[8], NULL
);
1377 if (maybe_expand_insn (code
, nops
, ops
))
1379 volatile_ok
= save_volatile_ok
;
1385 volatile_ok
= save_volatile_ok
;
1389 /* A subroutine of emit_block_move. Expand a call to memcpy.
1390 Return the return value from memcpy, 0 otherwise. */
1393 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1395 rtx dst_addr
, src_addr
;
1396 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1397 enum machine_mode size_mode
;
1400 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1401 pseudos. We can then place those new pseudos into a VAR_DECL and
1404 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1405 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1407 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1408 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1410 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1411 src_tree
= make_tree (ptr_type_node
, src_addr
);
1413 size_mode
= TYPE_MODE (sizetype
);
1415 size
= convert_to_mode (size_mode
, size
, 1);
1416 size
= copy_to_mode_reg (size_mode
, size
);
1418 /* It is incorrect to use the libcall calling conventions to call
1419 memcpy in this context. This could be a user call to memcpy and
1420 the user may wish to examine the return value from memcpy. For
1421 targets where libcalls and normal calls have different conventions
1422 for returning pointers, we could end up generating incorrect code. */
1424 size_tree
= make_tree (sizetype
, size
);
1426 fn
= emit_block_move_libcall_fn (true);
1427 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1428 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1430 retval
= expand_normal (call_expr
);
1435 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1436 for the function we use for block copies. */
1438 static GTY(()) tree block_move_fn
;
1441 init_block_move_fn (const char *asmspec
)
1445 tree args
, fn
, attrs
, attr_args
;
1447 fn
= get_identifier ("memcpy");
1448 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1449 const_ptr_type_node
, sizetype
,
1452 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1453 DECL_EXTERNAL (fn
) = 1;
1454 TREE_PUBLIC (fn
) = 1;
1455 DECL_ARTIFICIAL (fn
) = 1;
1456 TREE_NOTHROW (fn
) = 1;
1457 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1458 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1460 attr_args
= build_tree_list (NULL_TREE
, build_string (1, "1"));
1461 attrs
= tree_cons (get_identifier ("fn spec"), attr_args
, NULL
);
1463 decl_attributes (&fn
, attrs
, ATTR_FLAG_BUILT_IN
);
1469 set_user_assembler_name (block_move_fn
, asmspec
);
1473 emit_block_move_libcall_fn (int for_call
)
1475 static bool emitted_extern
;
1478 init_block_move_fn (NULL
);
1480 if (for_call
&& !emitted_extern
)
1482 emitted_extern
= true;
1483 make_decl_rtl (block_move_fn
);
1486 return block_move_fn
;
1489 /* A subroutine of emit_block_move. Copy the data via an explicit
1490 loop. This is used only when libcalls are forbidden. */
1491 /* ??? It'd be nice to copy in hunks larger than QImode. */
1494 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1495 unsigned int align ATTRIBUTE_UNUSED
)
1497 rtx cmp_label
, top_label
, iter
, x_addr
, y_addr
, tmp
;
1498 enum machine_mode x_addr_mode
= get_address_mode (x
);
1499 enum machine_mode y_addr_mode
= get_address_mode (y
);
1500 enum machine_mode iter_mode
;
1502 iter_mode
= GET_MODE (size
);
1503 if (iter_mode
== VOIDmode
)
1504 iter_mode
= word_mode
;
1506 top_label
= gen_label_rtx ();
1507 cmp_label
= gen_label_rtx ();
1508 iter
= gen_reg_rtx (iter_mode
);
1510 emit_move_insn (iter
, const0_rtx
);
1512 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1513 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1514 do_pending_stack_adjust ();
1516 emit_jump (cmp_label
);
1517 emit_label (top_label
);
1519 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1520 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1522 if (x_addr_mode
!= y_addr_mode
)
1523 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1524 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1526 x
= change_address (x
, QImode
, x_addr
);
1527 y
= change_address (y
, QImode
, y_addr
);
1529 emit_move_insn (x
, y
);
1531 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1532 true, OPTAB_LIB_WIDEN
);
1534 emit_move_insn (iter
, tmp
);
1536 emit_label (cmp_label
);
1538 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1539 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1542 /* Copy all or part of a value X into registers starting at REGNO.
1543 The number of registers to be filled is NREGS. */
1546 move_block_to_reg (int regno
, rtx x
, int nregs
, enum machine_mode mode
)
1549 #ifdef HAVE_load_multiple
1557 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1558 x
= validize_mem (force_const_mem (mode
, x
));
1560 /* See if the machine can do this with a load multiple insn. */
1561 #ifdef HAVE_load_multiple
1562 if (HAVE_load_multiple
)
1564 last
= get_last_insn ();
1565 pat
= gen_load_multiple (gen_rtx_REG (word_mode
, regno
), x
,
1573 delete_insns_since (last
);
1577 for (i
= 0; i
< nregs
; i
++)
1578 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1579 operand_subword_force (x
, i
, mode
));
1582 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1583 The number of registers to be filled is NREGS. */
1586 move_block_from_reg (int regno
, rtx x
, int nregs
)
1593 /* See if the machine can do this with a store multiple insn. */
1594 #ifdef HAVE_store_multiple
1595 if (HAVE_store_multiple
)
1597 rtx last
= get_last_insn ();
1598 rtx pat
= gen_store_multiple (x
, gen_rtx_REG (word_mode
, regno
),
1606 delete_insns_since (last
);
1610 for (i
= 0; i
< nregs
; i
++)
1612 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1616 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1620 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1621 ORIG, where ORIG is a non-consecutive group of registers represented by
1622 a PARALLEL. The clone is identical to the original except in that the
1623 original set of registers is replaced by a new set of pseudo registers.
1624 The new set has the same modes as the original set. */
1627 gen_group_rtx (rtx orig
)
1632 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1634 length
= XVECLEN (orig
, 0);
1635 tmps
= XALLOCAVEC (rtx
, length
);
1637 /* Skip a NULL entry in first slot. */
1638 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1643 for (; i
< length
; i
++)
1645 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1646 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1648 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1651 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1654 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1655 except that values are placed in TMPS[i], and must later be moved
1656 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1659 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1663 enum machine_mode m
= GET_MODE (orig_src
);
1665 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1668 && !SCALAR_INT_MODE_P (m
)
1669 && !MEM_P (orig_src
)
1670 && GET_CODE (orig_src
) != CONCAT
)
1672 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1673 if (imode
== BLKmode
)
1674 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
1676 src
= gen_reg_rtx (imode
);
1677 if (imode
!= BLKmode
)
1678 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1679 emit_move_insn (src
, orig_src
);
1680 /* ...and back again. */
1681 if (imode
!= BLKmode
)
1682 src
= gen_lowpart (imode
, src
);
1683 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1687 /* Check for a NULL entry, used to indicate that the parameter goes
1688 both on the stack and in registers. */
1689 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1694 /* Process the pieces. */
1695 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1697 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1698 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1699 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1702 /* Handle trailing fragments that run over the size of the struct. */
1703 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1705 /* Arrange to shift the fragment to where it belongs.
1706 extract_bit_field loads to the lsb of the reg. */
1708 #ifdef BLOCK_REG_PADDING
1709 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1710 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1715 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1716 bytelen
= ssize
- bytepos
;
1717 gcc_assert (bytelen
> 0);
1720 /* If we won't be loading directly from memory, protect the real source
1721 from strange tricks we might play; but make sure that the source can
1722 be loaded directly into the destination. */
1724 if (!MEM_P (orig_src
)
1725 && (!CONSTANT_P (orig_src
)
1726 || (GET_MODE (orig_src
) != mode
1727 && GET_MODE (orig_src
) != VOIDmode
)))
1729 if (GET_MODE (orig_src
) == VOIDmode
)
1730 src
= gen_reg_rtx (mode
);
1732 src
= gen_reg_rtx (GET_MODE (orig_src
));
1734 emit_move_insn (src
, orig_src
);
1737 /* Optimize the access just a bit. */
1739 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1740 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1741 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1742 && bytelen
== GET_MODE_SIZE (mode
))
1744 tmps
[i
] = gen_reg_rtx (mode
);
1745 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1747 else if (COMPLEX_MODE_P (mode
)
1748 && GET_MODE (src
) == mode
1749 && bytelen
== GET_MODE_SIZE (mode
))
1750 /* Let emit_move_complex do the bulk of the work. */
1752 else if (GET_CODE (src
) == CONCAT
)
1754 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1755 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1757 if ((bytepos
== 0 && bytelen
== slen0
)
1758 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1760 /* The following assumes that the concatenated objects all
1761 have the same size. In this case, a simple calculation
1762 can be used to determine the object and the bit field
1764 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1765 if (! CONSTANT_P (tmps
[i
])
1766 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1767 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1768 (bytepos
% slen0
) * BITS_PER_UNIT
,
1769 1, NULL_RTX
, mode
, mode
);
1775 gcc_assert (!bytepos
);
1776 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1777 emit_move_insn (mem
, src
);
1778 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1779 0, 1, NULL_RTX
, mode
, mode
);
1782 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1783 SIMD register, which is currently broken. While we get GCC
1784 to emit proper RTL for these cases, let's dump to memory. */
1785 else if (VECTOR_MODE_P (GET_MODE (dst
))
1788 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1791 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1792 emit_move_insn (mem
, src
);
1793 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1795 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1796 && XVECLEN (dst
, 0) > 1)
1797 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE (dst
), bytepos
);
1798 else if (CONSTANT_P (src
))
1800 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1808 gcc_assert (2 * len
== ssize
);
1809 split_double (src
, &first
, &second
);
1816 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1819 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1820 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
1824 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1829 /* Emit code to move a block SRC of type TYPE to a block DST,
1830 where DST is non-consecutive registers represented by a PARALLEL.
1831 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1835 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1840 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1841 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1843 /* Copy the extracted pieces into the proper (probable) hard regs. */
1844 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1846 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1849 emit_move_insn (d
, tmps
[i
]);
1853 /* Similar, but load SRC into new pseudos in a format that looks like
1854 PARALLEL. This can later be fed to emit_group_move to get things
1855 in the right place. */
1858 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1863 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1864 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1866 /* Convert the vector to look just like the original PARALLEL, except
1867 with the computed values. */
1868 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1870 rtx e
= XVECEXP (parallel
, 0, i
);
1871 rtx d
= XEXP (e
, 0);
1875 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1876 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1878 RTVEC_ELT (vec
, i
) = e
;
1881 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1884 /* Emit code to move a block SRC to block DST, where SRC and DST are
1885 non-consecutive groups of registers, each represented by a PARALLEL. */
1888 emit_group_move (rtx dst
, rtx src
)
1892 gcc_assert (GET_CODE (src
) == PARALLEL
1893 && GET_CODE (dst
) == PARALLEL
1894 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1896 /* Skip first entry if NULL. */
1897 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1898 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1899 XEXP (XVECEXP (src
, 0, i
), 0));
1902 /* Move a group of registers represented by a PARALLEL into pseudos. */
1905 emit_group_move_into_temps (rtx src
)
1907 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1910 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1912 rtx e
= XVECEXP (src
, 0, i
);
1913 rtx d
= XEXP (e
, 0);
1916 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1917 RTVEC_ELT (vec
, i
) = e
;
1920 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1923 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1924 where SRC is non-consecutive registers represented by a PARALLEL.
1925 SSIZE represents the total size of block ORIG_DST, or -1 if not
1929 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1932 int start
, finish
, i
;
1933 enum machine_mode m
= GET_MODE (orig_dst
);
1935 gcc_assert (GET_CODE (src
) == PARALLEL
);
1937 if (!SCALAR_INT_MODE_P (m
)
1938 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1940 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1941 if (imode
== BLKmode
)
1942 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
1944 dst
= gen_reg_rtx (imode
);
1945 emit_group_store (dst
, src
, type
, ssize
);
1946 if (imode
!= BLKmode
)
1947 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1948 emit_move_insn (orig_dst
, dst
);
1952 /* Check for a NULL entry, used to indicate that the parameter goes
1953 both on the stack and in registers. */
1954 if (XEXP (XVECEXP (src
, 0, 0), 0))
1958 finish
= XVECLEN (src
, 0);
1960 tmps
= XALLOCAVEC (rtx
, finish
);
1962 /* Copy the (probable) hard regs into pseudos. */
1963 for (i
= start
; i
< finish
; i
++)
1965 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1966 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1968 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1969 emit_move_insn (tmps
[i
], reg
);
1975 /* If we won't be storing directly into memory, protect the real destination
1976 from strange tricks we might play. */
1978 if (GET_CODE (dst
) == PARALLEL
)
1982 /* We can get a PARALLEL dst if there is a conditional expression in
1983 a return statement. In that case, the dst and src are the same,
1984 so no action is necessary. */
1985 if (rtx_equal_p (dst
, src
))
1988 /* It is unclear if we can ever reach here, but we may as well handle
1989 it. Allocate a temporary, and split this into a store/load to/from
1992 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
1993 emit_group_store (temp
, src
, type
, ssize
);
1994 emit_group_load (dst
, temp
, type
, ssize
);
1997 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1999 enum machine_mode outer
= GET_MODE (dst
);
2000 enum machine_mode inner
;
2001 HOST_WIDE_INT bytepos
;
2005 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
2006 dst
= gen_reg_rtx (outer
);
2008 /* Make life a bit easier for combine. */
2009 /* If the first element of the vector is the low part
2010 of the destination mode, use a paradoxical subreg to
2011 initialize the destination. */
2014 inner
= GET_MODE (tmps
[start
]);
2015 bytepos
= subreg_lowpart_offset (inner
, outer
);
2016 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
2018 temp
= simplify_gen_subreg (outer
, tmps
[start
],
2022 emit_move_insn (dst
, temp
);
2029 /* If the first element wasn't the low part, try the last. */
2031 && start
< finish
- 1)
2033 inner
= GET_MODE (tmps
[finish
- 1]);
2034 bytepos
= subreg_lowpart_offset (inner
, outer
);
2035 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
2037 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
2041 emit_move_insn (dst
, temp
);
2048 /* Otherwise, simply initialize the result to zero. */
2050 emit_move_insn (dst
, CONST0_RTX (outer
));
2053 /* Process the pieces. */
2054 for (i
= start
; i
< finish
; i
++)
2056 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
2057 enum machine_mode mode
= GET_MODE (tmps
[i
]);
2058 unsigned int bytelen
= GET_MODE_SIZE (mode
);
2059 unsigned int adj_bytelen
= bytelen
;
2062 /* Handle trailing fragments that run over the size of the struct. */
2063 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2064 adj_bytelen
= ssize
- bytepos
;
2066 if (GET_CODE (dst
) == CONCAT
)
2068 if (bytepos
+ adj_bytelen
2069 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2070 dest
= XEXP (dst
, 0);
2071 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2073 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2074 dest
= XEXP (dst
, 1);
2078 enum machine_mode dest_mode
= GET_MODE (dest
);
2079 enum machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2081 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2083 if (GET_MODE_ALIGNMENT (dest_mode
)
2084 >= GET_MODE_ALIGNMENT (tmp_mode
))
2086 dest
= assign_stack_temp (dest_mode
,
2087 GET_MODE_SIZE (dest_mode
));
2088 emit_move_insn (adjust_address (dest
,
2096 dest
= assign_stack_temp (tmp_mode
,
2097 GET_MODE_SIZE (tmp_mode
));
2098 emit_move_insn (dest
, tmps
[i
]);
2099 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2105 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2107 /* store_bit_field always takes its value from the lsb.
2108 Move the fragment to the lsb if it's not already there. */
2110 #ifdef BLOCK_REG_PADDING
2111 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2112 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2118 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2119 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2122 bytelen
= adj_bytelen
;
2125 /* Optimize the access just a bit. */
2127 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2128 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2129 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2130 && bytelen
== GET_MODE_SIZE (mode
))
2131 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2133 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2134 0, 0, mode
, tmps
[i
]);
2137 /* Copy from the pseudo into the (probable) hard reg. */
2138 if (orig_dst
!= dst
)
2139 emit_move_insn (orig_dst
, dst
);
2142 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2143 of the value stored in X. */
2146 maybe_emit_group_store (rtx x
, tree type
)
2148 enum machine_mode mode
= TYPE_MODE (type
);
2149 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
2150 if (GET_CODE (x
) == PARALLEL
)
2152 rtx result
= gen_reg_rtx (mode
);
2153 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
2159 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2161 This is used on targets that return BLKmode values in registers. */
2164 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2166 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2167 rtx src
= NULL
, dst
= NULL
;
2168 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2169 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2170 enum machine_mode mode
= GET_MODE (srcreg
);
2171 enum machine_mode tmode
= GET_MODE (target
);
2172 enum machine_mode copy_mode
;
2174 /* BLKmode registers created in the back-end shouldn't have survived. */
2175 gcc_assert (mode
!= BLKmode
);
2177 /* If the structure doesn't take up a whole number of words, see whether
2178 SRCREG is padded on the left or on the right. If it's on the left,
2179 set PADDING_CORRECTION to the number of bits to skip.
2181 In most ABIs, the structure will be returned at the least end of
2182 the register, which translates to right padding on little-endian
2183 targets and left padding on big-endian targets. The opposite
2184 holds if the structure is returned at the most significant
2185 end of the register. */
2186 if (bytes
% UNITS_PER_WORD
!= 0
2187 && (targetm
.calls
.return_in_msb (type
)
2189 : BYTES_BIG_ENDIAN
))
2191 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2193 /* We can use a single move if we have an exact mode for the size. */
2194 else if (MEM_P (target
)
2195 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2196 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2197 && bytes
== GET_MODE_SIZE (mode
))
2199 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2203 /* And if we additionally have the same mode for a register. */
2204 else if (REG_P (target
)
2205 && GET_MODE (target
) == mode
2206 && bytes
== GET_MODE_SIZE (mode
))
2208 emit_move_insn (target
, srcreg
);
2212 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2213 into a new pseudo which is a full word. */
2214 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2216 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2220 /* Copy the structure BITSIZE bits at a time. If the target lives in
2221 memory, take care of not reading/writing past its end by selecting
2222 a copy mode suited to BITSIZE. This should always be possible given
2225 If the target lives in register, make sure not to select a copy mode
2226 larger than the mode of the register.
2228 We could probably emit more efficient code for machines which do not use
2229 strict alignment, but it doesn't seem worth the effort at the current
2232 copy_mode
= word_mode
;
2235 enum machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2236 if (mem_mode
!= BLKmode
)
2237 copy_mode
= mem_mode
;
2239 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2242 for (bitpos
= 0, xbitpos
= padding_correction
;
2243 bitpos
< bytes
* BITS_PER_UNIT
;
2244 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2246 /* We need a new source operand each time xbitpos is on a
2247 word boundary and when xbitpos == padding_correction
2248 (the first time through). */
2249 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2250 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2252 /* We need a new destination operand each time bitpos is on
2254 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2256 else if (bitpos
% BITS_PER_WORD
== 0)
2257 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2259 /* Use xbitpos for the source extraction (right justified) and
2260 bitpos for the destination store (left justified). */
2261 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2262 extract_bit_field (src
, bitsize
,
2263 xbitpos
% BITS_PER_WORD
, 1,
2264 NULL_RTX
, copy_mode
, copy_mode
));
2268 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2269 register if it contains any data, otherwise return null.
2271 This is used on targets that return BLKmode values in registers. */
2274 copy_blkmode_to_reg (enum machine_mode mode
, tree src
)
2277 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2278 unsigned int bitsize
;
2279 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2280 enum machine_mode dst_mode
;
2282 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2284 x
= expand_normal (src
);
2286 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2290 /* If the structure doesn't take up a whole number of words, see
2291 whether the register value should be padded on the left or on
2292 the right. Set PADDING_CORRECTION to the number of padding
2293 bits needed on the left side.
2295 In most ABIs, the structure will be returned at the least end of
2296 the register, which translates to right padding on little-endian
2297 targets and left padding on big-endian targets. The opposite
2298 holds if the structure is returned at the most significant
2299 end of the register. */
2300 if (bytes
% UNITS_PER_WORD
!= 0
2301 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2303 : BYTES_BIG_ENDIAN
))
2304 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2307 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2308 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2309 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2311 /* Copy the structure BITSIZE bits at a time. */
2312 for (bitpos
= 0, xbitpos
= padding_correction
;
2313 bitpos
< bytes
* BITS_PER_UNIT
;
2314 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2316 /* We need a new destination pseudo each time xbitpos is
2317 on a word boundary and when xbitpos == padding_correction
2318 (the first time through). */
2319 if (xbitpos
% BITS_PER_WORD
== 0
2320 || xbitpos
== padding_correction
)
2322 /* Generate an appropriate register. */
2323 dst_word
= gen_reg_rtx (word_mode
);
2324 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2326 /* Clear the destination before we move anything into it. */
2327 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2330 /* We need a new source operand each time bitpos is on a word
2332 if (bitpos
% BITS_PER_WORD
== 0)
2333 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2335 /* Use bitpos for the source extraction (left justified) and
2336 xbitpos for the destination store (right justified). */
2337 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2339 extract_bit_field (src_word
, bitsize
,
2340 bitpos
% BITS_PER_WORD
, 1,
2341 NULL_RTX
, word_mode
, word_mode
));
2344 if (mode
== BLKmode
)
2346 /* Find the smallest integer mode large enough to hold the
2347 entire structure. */
2348 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2350 mode
= GET_MODE_WIDER_MODE (mode
))
2351 /* Have we found a large enough mode? */
2352 if (GET_MODE_SIZE (mode
) >= bytes
)
2355 /* A suitable mode should have been found. */
2356 gcc_assert (mode
!= VOIDmode
);
2359 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2360 dst_mode
= word_mode
;
2363 dst
= gen_reg_rtx (dst_mode
);
2365 for (i
= 0; i
< n_regs
; i
++)
2366 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2368 if (mode
!= dst_mode
)
2369 dst
= gen_lowpart (mode
, dst
);
2374 /* Add a USE expression for REG to the (possibly empty) list pointed
2375 to by CALL_FUSAGE. REG must denote a hard register. */
2378 use_reg_mode (rtx
*call_fusage
, rtx reg
, enum machine_mode mode
)
2380 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2383 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2386 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2387 starting at REGNO. All of these registers must be hard registers. */
2390 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2394 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2396 for (i
= 0; i
< nregs
; i
++)
2397 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2400 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2401 PARALLEL REGS. This is for calls that pass values in multiple
2402 non-contiguous locations. The Irix 6 ABI has examples of this. */
2405 use_group_regs (rtx
*call_fusage
, rtx regs
)
2409 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2411 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2413 /* A NULL entry means the parameter goes both on the stack and in
2414 registers. This can also be a MEM for targets that pass values
2415 partially on the stack and partially in registers. */
2416 if (reg
!= 0 && REG_P (reg
))
2417 use_reg (call_fusage
, reg
);
2421 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2422 assigment and the code of the expresion on the RHS is CODE. Return
2426 get_def_for_expr (tree name
, enum tree_code code
)
2430 if (TREE_CODE (name
) != SSA_NAME
)
2433 def_stmt
= get_gimple_for_ssa_name (name
);
2435 || gimple_assign_rhs_code (def_stmt
) != code
)
2441 #ifdef HAVE_conditional_move
2442 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2443 assigment and the class of the expresion on the RHS is CLASS. Return
2447 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2451 if (TREE_CODE (name
) != SSA_NAME
)
2454 def_stmt
= get_gimple_for_ssa_name (name
);
2456 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2464 /* Determine whether the LEN bytes generated by CONSTFUN can be
2465 stored to memory using several move instructions. CONSTFUNDATA is
2466 a pointer which will be passed as argument in every CONSTFUN call.
2467 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2468 a memset operation and false if it's a copy of a constant string.
2469 Return nonzero if a call to store_by_pieces should succeed. */
2472 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2473 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2474 void *constfundata
, unsigned int align
, bool memsetp
)
2476 unsigned HOST_WIDE_INT l
;
2477 unsigned int max_size
;
2478 HOST_WIDE_INT offset
= 0;
2479 enum machine_mode mode
;
2480 enum insn_code icode
;
2482 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2483 rtx cst ATTRIBUTE_UNUSED
;
2489 ? SET_BY_PIECES_P (len
, align
)
2490 : STORE_BY_PIECES_P (len
, align
)))
2493 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2495 /* We would first store what we can in the largest integer mode, then go to
2496 successively smaller modes. */
2499 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2503 max_size
= STORE_MAX_PIECES
+ 1;
2504 while (max_size
> 1 && l
> 0)
2506 mode
= widest_int_mode_for_size (max_size
);
2508 if (mode
== VOIDmode
)
2511 icode
= optab_handler (mov_optab
, mode
);
2512 if (icode
!= CODE_FOR_nothing
2513 && align
>= GET_MODE_ALIGNMENT (mode
))
2515 unsigned int size
= GET_MODE_SIZE (mode
);
2522 cst
= (*constfun
) (constfundata
, offset
, mode
);
2523 if (!targetm
.legitimate_constant_p (mode
, cst
))
2533 max_size
= GET_MODE_SIZE (mode
);
2536 /* The code above should have handled everything. */
2543 /* Generate several move instructions to store LEN bytes generated by
2544 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2545 pointer which will be passed as argument in every CONSTFUN call.
2546 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2547 a memset operation and false if it's a copy of a constant string.
2548 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2549 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2553 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2554 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2555 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2557 enum machine_mode to_addr_mode
= get_address_mode (to
);
2558 struct store_by_pieces_d data
;
2562 gcc_assert (endp
!= 2);
2567 ? SET_BY_PIECES_P (len
, align
)
2568 : STORE_BY_PIECES_P (len
, align
));
2569 data
.constfun
= constfun
;
2570 data
.constfundata
= constfundata
;
2573 store_by_pieces_1 (&data
, align
);
2578 gcc_assert (!data
.reverse
);
2583 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2584 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2586 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2587 plus_constant (to_addr_mode
,
2591 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2598 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2606 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2607 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2610 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2612 struct store_by_pieces_d data
;
2617 data
.constfun
= clear_by_pieces_1
;
2618 data
.constfundata
= NULL
;
2621 store_by_pieces_1 (&data
, align
);
2624 /* Callback routine for clear_by_pieces.
2625 Return const0_rtx unconditionally. */
2628 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2629 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2630 enum machine_mode mode ATTRIBUTE_UNUSED
)
2635 /* Subroutine of clear_by_pieces and store_by_pieces.
2636 Generate several move instructions to store LEN bytes of block TO. (A MEM
2637 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2640 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2641 unsigned int align ATTRIBUTE_UNUSED
)
2643 enum machine_mode to_addr_mode
= get_address_mode (data
->to
);
2644 rtx to_addr
= XEXP (data
->to
, 0);
2645 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2646 enum insn_code icode
;
2649 data
->to_addr
= to_addr
;
2651 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2652 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2654 data
->explicit_inc_to
= 0;
2656 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2658 data
->offset
= data
->len
;
2660 /* If storing requires more than two move insns,
2661 copy addresses to registers (to make displacements shorter)
2662 and use post-increment if available. */
2663 if (!data
->autinc_to
2664 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2666 /* Determine the main mode we'll be using.
2667 MODE might not be used depending on the definitions of the
2668 USE_* macros below. */
2669 enum machine_mode mode ATTRIBUTE_UNUSED
2670 = widest_int_mode_for_size (max_size
);
2672 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2674 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2675 plus_constant (to_addr_mode
,
2678 data
->autinc_to
= 1;
2679 data
->explicit_inc_to
= -1;
2682 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2683 && ! data
->autinc_to
)
2685 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2686 data
->autinc_to
= 1;
2687 data
->explicit_inc_to
= 1;
2690 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2691 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2694 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2696 /* First store what we can in the largest integer mode, then go to
2697 successively smaller modes. */
2699 while (max_size
> 1 && data
->len
> 0)
2701 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
2703 if (mode
== VOIDmode
)
2706 icode
= optab_handler (mov_optab
, mode
);
2707 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2708 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2710 max_size
= GET_MODE_SIZE (mode
);
2713 /* The code above should have handled everything. */
2714 gcc_assert (!data
->len
);
2717 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2718 with move instructions for mode MODE. GENFUN is the gen_... function
2719 to make a move insn for that mode. DATA has all the other info. */
2722 store_by_pieces_2 (insn_gen_fn genfun
, machine_mode mode
,
2723 struct store_by_pieces_d
*data
)
2725 unsigned int size
= GET_MODE_SIZE (mode
);
2728 while (data
->len
>= size
)
2731 data
->offset
-= size
;
2733 if (data
->autinc_to
)
2734 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2737 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2739 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2740 emit_insn (gen_add2_insn (data
->to_addr
,
2741 gen_int_mode (-(HOST_WIDE_INT
) size
,
2742 GET_MODE (data
->to_addr
))));
2744 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2745 emit_insn ((*genfun
) (to1
, cst
));
2747 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2748 emit_insn (gen_add2_insn (data
->to_addr
,
2750 GET_MODE (data
->to_addr
))));
2752 if (! data
->reverse
)
2753 data
->offset
+= size
;
2759 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2760 its length in bytes. */
2763 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2764 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2765 unsigned HOST_WIDE_INT min_size
,
2766 unsigned HOST_WIDE_INT max_size
,
2767 unsigned HOST_WIDE_INT probable_max_size
)
2769 enum machine_mode mode
= GET_MODE (object
);
2772 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2774 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2775 just move a zero. Otherwise, do this a piece at a time. */
2777 && CONST_INT_P (size
)
2778 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2780 rtx zero
= CONST0_RTX (mode
);
2783 emit_move_insn (object
, zero
);
2787 if (COMPLEX_MODE_P (mode
))
2789 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2792 write_complex_part (object
, zero
, 0);
2793 write_complex_part (object
, zero
, 1);
2799 if (size
== const0_rtx
)
2802 align
= MEM_ALIGN (object
);
2804 if (CONST_INT_P (size
)
2805 && CLEAR_BY_PIECES_P (INTVAL (size
), align
))
2806 clear_by_pieces (object
, INTVAL (size
), align
);
2807 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2808 expected_align
, expected_size
,
2809 min_size
, max_size
, probable_max_size
))
2811 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2812 return set_storage_via_libcall (object
, size
, const0_rtx
,
2813 method
== BLOCK_OP_TAILCALL
);
2821 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2823 unsigned HOST_WIDE_INT max
, min
= 0;
2824 if (GET_CODE (size
) == CONST_INT
)
2825 min
= max
= UINTVAL (size
);
2827 max
= GET_MODE_MASK (GET_MODE (size
));
2828 return clear_storage_hints (object
, size
, method
, 0, -1, min
, max
, max
);
2832 /* A subroutine of clear_storage. Expand a call to memset.
2833 Return the return value of memset, 0 otherwise. */
2836 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2838 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2839 enum machine_mode size_mode
;
2842 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2843 place those into new pseudos into a VAR_DECL and use them later. */
2845 object
= copy_addr_to_reg (XEXP (object
, 0));
2847 size_mode
= TYPE_MODE (sizetype
);
2848 size
= convert_to_mode (size_mode
, size
, 1);
2849 size
= copy_to_mode_reg (size_mode
, size
);
2851 /* It is incorrect to use the libcall calling conventions to call
2852 memset in this context. This could be a user call to memset and
2853 the user may wish to examine the return value from memset. For
2854 targets where libcalls and normal calls have different conventions
2855 for returning pointers, we could end up generating incorrect code. */
2857 object_tree
= make_tree (ptr_type_node
, object
);
2858 if (!CONST_INT_P (val
))
2859 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2860 size_tree
= make_tree (sizetype
, size
);
2861 val_tree
= make_tree (integer_type_node
, val
);
2863 fn
= clear_storage_libcall_fn (true);
2864 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2865 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2867 retval
= expand_normal (call_expr
);
2872 /* A subroutine of set_storage_via_libcall. Create the tree node
2873 for the function we use for block clears. */
2875 tree block_clear_fn
;
2878 init_block_clear_fn (const char *asmspec
)
2880 if (!block_clear_fn
)
2884 fn
= get_identifier ("memset");
2885 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2886 integer_type_node
, sizetype
,
2889 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2890 DECL_EXTERNAL (fn
) = 1;
2891 TREE_PUBLIC (fn
) = 1;
2892 DECL_ARTIFICIAL (fn
) = 1;
2893 TREE_NOTHROW (fn
) = 1;
2894 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2895 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2897 block_clear_fn
= fn
;
2901 set_user_assembler_name (block_clear_fn
, asmspec
);
2905 clear_storage_libcall_fn (int for_call
)
2907 static bool emitted_extern
;
2909 if (!block_clear_fn
)
2910 init_block_clear_fn (NULL
);
2912 if (for_call
&& !emitted_extern
)
2914 emitted_extern
= true;
2915 make_decl_rtl (block_clear_fn
);
2918 return block_clear_fn
;
2921 /* Expand a setmem pattern; return true if successful. */
2924 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2925 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2926 unsigned HOST_WIDE_INT min_size
,
2927 unsigned HOST_WIDE_INT max_size
,
2928 unsigned HOST_WIDE_INT probable_max_size
)
2930 /* Try the most limited insn first, because there's no point
2931 including more than one in the machine description unless
2932 the more limited one has some advantage. */
2934 enum machine_mode mode
;
2936 if (expected_align
< align
)
2937 expected_align
= align
;
2938 if (expected_size
!= -1)
2940 if ((unsigned HOST_WIDE_INT
)expected_size
> max_size
)
2941 expected_size
= max_size
;
2942 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
2943 expected_size
= min_size
;
2946 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2947 mode
= GET_MODE_WIDER_MODE (mode
))
2949 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2951 if (code
!= CODE_FOR_nothing
2952 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2953 here because if SIZE is less than the mode mask, as it is
2954 returned by the macro, it will definitely be less than the
2955 actual mode mask. Since SIZE is within the Pmode address
2956 space, we limit MODE to Pmode. */
2957 && ((CONST_INT_P (size
)
2958 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2959 <= (GET_MODE_MASK (mode
) >> 1)))
2960 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
2961 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
2963 struct expand_operand ops
[9];
2966 nops
= insn_data
[(int) code
].n_generator_args
;
2967 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
2969 create_fixed_operand (&ops
[0], object
);
2970 /* The check above guarantees that this size conversion is valid. */
2971 create_convert_operand_to (&ops
[1], size
, mode
, true);
2972 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2973 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2976 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2977 create_integer_operand (&ops
[5], expected_size
);
2981 create_integer_operand (&ops
[6], min_size
);
2982 /* If we can not represent the maximal size,
2983 make parameter NULL. */
2984 if ((HOST_WIDE_INT
) max_size
!= -1)
2985 create_integer_operand (&ops
[7], max_size
);
2987 create_fixed_operand (&ops
[7], NULL
);
2991 /* If we can not represent the maximal size,
2992 make parameter NULL. */
2993 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
2994 create_integer_operand (&ops
[8], probable_max_size
);
2996 create_fixed_operand (&ops
[8], NULL
);
2998 if (maybe_expand_insn (code
, nops
, ops
))
3007 /* Write to one of the components of the complex value CPLX. Write VAL to
3008 the real part if IMAG_P is false, and the imaginary part if its true. */
3011 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
3013 enum machine_mode cmode
;
3014 enum machine_mode imode
;
3017 if (GET_CODE (cplx
) == CONCAT
)
3019 emit_move_insn (XEXP (cplx
, imag_p
), val
);
3023 cmode
= GET_MODE (cplx
);
3024 imode
= GET_MODE_INNER (cmode
);
3025 ibitsize
= GET_MODE_BITSIZE (imode
);
3027 /* For MEMs simplify_gen_subreg may generate an invalid new address
3028 because, e.g., the original address is considered mode-dependent
3029 by the target, which restricts simplify_subreg from invoking
3030 adjust_address_nv. Instead of preparing fallback support for an
3031 invalid address, we call adjust_address_nv directly. */
3034 emit_move_insn (adjust_address_nv (cplx
, imode
,
3035 imag_p
? GET_MODE_SIZE (imode
) : 0),
3040 /* If the sub-object is at least word sized, then we know that subregging
3041 will work. This special case is important, since store_bit_field
3042 wants to operate on integer modes, and there's rarely an OImode to
3043 correspond to TCmode. */
3044 if (ibitsize
>= BITS_PER_WORD
3045 /* For hard regs we have exact predicates. Assume we can split
3046 the original object if it spans an even number of hard regs.
3047 This special case is important for SCmode on 64-bit platforms
3048 where the natural size of floating-point regs is 32-bit. */
3050 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3051 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3053 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
3054 imag_p
? GET_MODE_SIZE (imode
) : 0);
3057 emit_move_insn (part
, val
);
3061 /* simplify_gen_subreg may fail for sub-word MEMs. */
3062 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3065 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
3068 /* Extract one of the components of the complex value CPLX. Extract the
3069 real part if IMAG_P is false, and the imaginary part if it's true. */
3072 read_complex_part (rtx cplx
, bool imag_p
)
3074 enum machine_mode cmode
, imode
;
3077 if (GET_CODE (cplx
) == CONCAT
)
3078 return XEXP (cplx
, imag_p
);
3080 cmode
= GET_MODE (cplx
);
3081 imode
= GET_MODE_INNER (cmode
);
3082 ibitsize
= GET_MODE_BITSIZE (imode
);
3084 /* Special case reads from complex constants that got spilled to memory. */
3085 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
3087 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
3088 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
3090 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
3091 if (CONSTANT_CLASS_P (part
))
3092 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
3096 /* For MEMs simplify_gen_subreg may generate an invalid new address
3097 because, e.g., the original address is considered mode-dependent
3098 by the target, which restricts simplify_subreg from invoking
3099 adjust_address_nv. Instead of preparing fallback support for an
3100 invalid address, we call adjust_address_nv directly. */
3102 return adjust_address_nv (cplx
, imode
,
3103 imag_p
? GET_MODE_SIZE (imode
) : 0);
3105 /* If the sub-object is at least word sized, then we know that subregging
3106 will work. This special case is important, since extract_bit_field
3107 wants to operate on integer modes, and there's rarely an OImode to
3108 correspond to TCmode. */
3109 if (ibitsize
>= BITS_PER_WORD
3110 /* For hard regs we have exact predicates. Assume we can split
3111 the original object if it spans an even number of hard regs.
3112 This special case is important for SCmode on 64-bit platforms
3113 where the natural size of floating-point regs is 32-bit. */
3115 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3116 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3118 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3119 imag_p
? GET_MODE_SIZE (imode
) : 0);
3123 /* simplify_gen_subreg may fail for sub-word MEMs. */
3124 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3127 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3128 true, NULL_RTX
, imode
, imode
);
3131 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3132 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3133 represented in NEW_MODE. If FORCE is true, this will never happen, as
3134 we'll force-create a SUBREG if needed. */
3137 emit_move_change_mode (enum machine_mode new_mode
,
3138 enum machine_mode old_mode
, rtx x
, bool force
)
3142 if (push_operand (x
, GET_MODE (x
)))
3144 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3145 MEM_COPY_ATTRIBUTES (ret
, x
);
3149 /* We don't have to worry about changing the address since the
3150 size in bytes is supposed to be the same. */
3151 if (reload_in_progress
)
3153 /* Copy the MEM to change the mode and move any
3154 substitutions from the old MEM to the new one. */
3155 ret
= adjust_address_nv (x
, new_mode
, 0);
3156 copy_replacements (x
, ret
);
3159 ret
= adjust_address (x
, new_mode
, 0);
3163 /* Note that we do want simplify_subreg's behavior of validating
3164 that the new mode is ok for a hard register. If we were to use
3165 simplify_gen_subreg, we would create the subreg, but would
3166 probably run into the target not being able to implement it. */
3167 /* Except, of course, when FORCE is true, when this is exactly what
3168 we want. Which is needed for CCmodes on some targets. */
3170 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3172 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3178 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3179 an integer mode of the same size as MODE. Returns the instruction
3180 emitted, or NULL if such a move could not be generated. */
3183 emit_move_via_integer (enum machine_mode mode
, rtx x
, rtx y
, bool force
)
3185 enum machine_mode imode
;
3186 enum insn_code code
;
3188 /* There must exist a mode of the exact size we require. */
3189 imode
= int_mode_for_mode (mode
);
3190 if (imode
== BLKmode
)
3193 /* The target must support moves in this mode. */
3194 code
= optab_handler (mov_optab
, imode
);
3195 if (code
== CODE_FOR_nothing
)
3198 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3201 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3204 return emit_insn (GEN_FCN (code
) (x
, y
));
3207 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3208 Return an equivalent MEM that does not use an auto-increment. */
3211 emit_move_resolve_push (enum machine_mode mode
, rtx x
)
3213 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3214 HOST_WIDE_INT adjust
;
3217 adjust
= GET_MODE_SIZE (mode
);
3218 #ifdef PUSH_ROUNDING
3219 adjust
= PUSH_ROUNDING (adjust
);
3221 if (code
== PRE_DEC
|| code
== POST_DEC
)
3223 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3225 rtx expr
= XEXP (XEXP (x
, 0), 1);
3228 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3229 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3230 val
= INTVAL (XEXP (expr
, 1));
3231 if (GET_CODE (expr
) == MINUS
)
3233 gcc_assert (adjust
== val
|| adjust
== -val
);
3237 /* Do not use anti_adjust_stack, since we don't want to update
3238 stack_pointer_delta. */
3239 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3240 gen_int_mode (adjust
, Pmode
), stack_pointer_rtx
,
3241 0, OPTAB_LIB_WIDEN
);
3242 if (temp
!= stack_pointer_rtx
)
3243 emit_move_insn (stack_pointer_rtx
, temp
);
3250 temp
= stack_pointer_rtx
;
3255 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3261 return replace_equiv_address (x
, temp
);
3264 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3265 X is known to satisfy push_operand, and MODE is known to be complex.
3266 Returns the last instruction emitted. */
3269 emit_move_complex_push (enum machine_mode mode
, rtx x
, rtx y
)
3271 enum machine_mode submode
= GET_MODE_INNER (mode
);
3274 #ifdef PUSH_ROUNDING
3275 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3277 /* In case we output to the stack, but the size is smaller than the
3278 machine can push exactly, we need to use move instructions. */
3279 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3281 x
= emit_move_resolve_push (mode
, x
);
3282 return emit_move_insn (x
, y
);
3286 /* Note that the real part always precedes the imag part in memory
3287 regardless of machine's endianness. */
3288 switch (GET_CODE (XEXP (x
, 0)))
3302 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3303 read_complex_part (y
, imag_first
));
3304 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3305 read_complex_part (y
, !imag_first
));
3308 /* A subroutine of emit_move_complex. Perform the move from Y to X
3309 via two moves of the parts. Returns the last instruction emitted. */
3312 emit_move_complex_parts (rtx x
, rtx y
)
3314 /* Show the output dies here. This is necessary for SUBREGs
3315 of pseudos since we cannot track their lifetimes correctly;
3316 hard regs shouldn't appear here except as return values. */
3317 if (!reload_completed
&& !reload_in_progress
3318 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3321 write_complex_part (x
, read_complex_part (y
, false), false);
3322 write_complex_part (x
, read_complex_part (y
, true), true);
3324 return get_last_insn ();
3327 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3328 MODE is known to be complex. Returns the last instruction emitted. */
3331 emit_move_complex (enum machine_mode mode
, rtx x
, rtx y
)
3335 /* Need to take special care for pushes, to maintain proper ordering
3336 of the data, and possibly extra padding. */
3337 if (push_operand (x
, mode
))
3338 return emit_move_complex_push (mode
, x
, y
);
3340 /* See if we can coerce the target into moving both values at once, except
3341 for floating point where we favor moving as parts if this is easy. */
3342 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3343 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
3345 && HARD_REGISTER_P (x
)
3346 && hard_regno_nregs
[REGNO (x
)][mode
] == 1)
3348 && HARD_REGISTER_P (y
)
3349 && hard_regno_nregs
[REGNO (y
)][mode
] == 1))
3351 /* Not possible if the values are inherently not adjacent. */
3352 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3354 /* Is possible if both are registers (or subregs of registers). */
3355 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3357 /* If one of the operands is a memory, and alignment constraints
3358 are friendly enough, we may be able to do combined memory operations.
3359 We do not attempt this if Y is a constant because that combination is
3360 usually better with the by-parts thing below. */
3361 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3362 && (!STRICT_ALIGNMENT
3363 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3372 /* For memory to memory moves, optimal behavior can be had with the
3373 existing block move logic. */
3374 if (MEM_P (x
) && MEM_P (y
))
3376 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3377 BLOCK_OP_NO_LIBCALL
);
3378 return get_last_insn ();
3381 ret
= emit_move_via_integer (mode
, x
, y
, true);
3386 return emit_move_complex_parts (x
, y
);
3389 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3390 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3393 emit_move_ccmode (enum machine_mode mode
, rtx x
, rtx y
)
3397 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3400 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3401 if (code
!= CODE_FOR_nothing
)
3403 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3404 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3405 return emit_insn (GEN_FCN (code
) (x
, y
));
3409 /* Otherwise, find the MODE_INT mode of the same width. */
3410 ret
= emit_move_via_integer (mode
, x
, y
, false);
3411 gcc_assert (ret
!= NULL
);
3415 /* Return true if word I of OP lies entirely in the
3416 undefined bits of a paradoxical subreg. */
3419 undefined_operand_subword_p (const_rtx op
, int i
)
3421 enum machine_mode innermode
, innermostmode
;
3423 if (GET_CODE (op
) != SUBREG
)
3425 innermode
= GET_MODE (op
);
3426 innermostmode
= GET_MODE (SUBREG_REG (op
));
3427 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3428 /* The SUBREG_BYTE represents offset, as if the value were stored in
3429 memory, except for a paradoxical subreg where we define
3430 SUBREG_BYTE to be 0; undo this exception as in
3432 if (SUBREG_BYTE (op
) == 0
3433 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3435 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3436 if (WORDS_BIG_ENDIAN
)
3437 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3438 if (BYTES_BIG_ENDIAN
)
3439 offset
+= difference
% UNITS_PER_WORD
;
3441 if (offset
>= GET_MODE_SIZE (innermostmode
)
3442 || offset
<= -GET_MODE_SIZE (word_mode
))
3447 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3448 MODE is any multi-word or full-word mode that lacks a move_insn
3449 pattern. Note that you will get better code if you define such
3450 patterns, even if they must turn into multiple assembler instructions. */
3453 emit_move_multi_word (enum machine_mode mode
, rtx x
, rtx y
)
3460 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3462 /* If X is a push on the stack, do the push now and replace
3463 X with a reference to the stack pointer. */
3464 if (push_operand (x
, mode
))
3465 x
= emit_move_resolve_push (mode
, x
);
3467 /* If we are in reload, see if either operand is a MEM whose address
3468 is scheduled for replacement. */
3469 if (reload_in_progress
&& MEM_P (x
)
3470 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3471 x
= replace_equiv_address_nv (x
, inner
);
3472 if (reload_in_progress
&& MEM_P (y
)
3473 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3474 y
= replace_equiv_address_nv (y
, inner
);
3478 need_clobber
= false;
3480 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3483 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3486 /* Do not generate code for a move if it would come entirely
3487 from the undefined bits of a paradoxical subreg. */
3488 if (undefined_operand_subword_p (y
, i
))
3491 ypart
= operand_subword (y
, i
, 1, mode
);
3493 /* If we can't get a part of Y, put Y into memory if it is a
3494 constant. Otherwise, force it into a register. Then we must
3495 be able to get a part of Y. */
3496 if (ypart
== 0 && CONSTANT_P (y
))
3498 y
= use_anchored_address (force_const_mem (mode
, y
));
3499 ypart
= operand_subword (y
, i
, 1, mode
);
3501 else if (ypart
== 0)
3502 ypart
= operand_subword_force (y
, i
, mode
);
3504 gcc_assert (xpart
&& ypart
);
3506 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3508 last_insn
= emit_move_insn (xpart
, ypart
);
3514 /* Show the output dies here. This is necessary for SUBREGs
3515 of pseudos since we cannot track their lifetimes correctly;
3516 hard regs shouldn't appear here except as return values.
3517 We never want to emit such a clobber after reload. */
3519 && ! (reload_in_progress
|| reload_completed
)
3520 && need_clobber
!= 0)
3528 /* Low level part of emit_move_insn.
3529 Called just like emit_move_insn, but assumes X and Y
3530 are basically valid. */
3533 emit_move_insn_1 (rtx x
, rtx y
)
3535 enum machine_mode mode
= GET_MODE (x
);
3536 enum insn_code code
;
3538 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3540 code
= optab_handler (mov_optab
, mode
);
3541 if (code
!= CODE_FOR_nothing
)
3542 return emit_insn (GEN_FCN (code
) (x
, y
));
3544 /* Expand complex moves by moving real part and imag part. */
3545 if (COMPLEX_MODE_P (mode
))
3546 return emit_move_complex (mode
, x
, y
);
3548 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3549 || ALL_FIXED_POINT_MODE_P (mode
))
3551 rtx result
= emit_move_via_integer (mode
, x
, y
, true);
3553 /* If we can't find an integer mode, use multi words. */
3557 return emit_move_multi_word (mode
, x
, y
);
3560 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3561 return emit_move_ccmode (mode
, x
, y
);
3563 /* Try using a move pattern for the corresponding integer mode. This is
3564 only safe when simplify_subreg can convert MODE constants into integer
3565 constants. At present, it can only do this reliably if the value
3566 fits within a HOST_WIDE_INT. */
3567 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3569 rtx ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3573 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3578 return emit_move_multi_word (mode
, x
, y
);
3581 /* Generate code to copy Y into X.
3582 Both Y and X must have the same mode, except that
3583 Y can be a constant with VOIDmode.
3584 This mode cannot be BLKmode; use emit_block_move for that.
3586 Return the last instruction emitted. */
3589 emit_move_insn (rtx x
, rtx y
)
3591 enum machine_mode mode
= GET_MODE (x
);
3592 rtx y_cst
= NULL_RTX
;
3595 gcc_assert (mode
!= BLKmode
3596 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3601 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3602 && (last_insn
= compress_float_constant (x
, y
)))
3607 if (!targetm
.legitimate_constant_p (mode
, y
))
3609 y
= force_const_mem (mode
, y
);
3611 /* If the target's cannot_force_const_mem prevented the spill,
3612 assume that the target's move expanders will also take care
3613 of the non-legitimate constant. */
3617 y
= use_anchored_address (y
);
3621 /* If X or Y are memory references, verify that their addresses are valid
3624 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3626 && ! push_operand (x
, GET_MODE (x
))))
3627 x
= validize_mem (x
);
3630 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3631 MEM_ADDR_SPACE (y
)))
3632 y
= validize_mem (y
);
3634 gcc_assert (mode
!= BLKmode
);
3636 last_insn
= emit_move_insn_1 (x
, y
);
3638 if (y_cst
&& REG_P (x
)
3639 && (set
= single_set (last_insn
)) != NULL_RTX
3640 && SET_DEST (set
) == x
3641 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3642 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3647 /* If Y is representable exactly in a narrower mode, and the target can
3648 perform the extension directly from constant or memory, then emit the
3649 move as an extension. */
3652 compress_float_constant (rtx x
, rtx y
)
3654 enum machine_mode dstmode
= GET_MODE (x
);
3655 enum machine_mode orig_srcmode
= GET_MODE (y
);
3656 enum machine_mode srcmode
;
3658 int oldcost
, newcost
;
3659 bool speed
= optimize_insn_for_speed_p ();
3661 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3663 if (targetm
.legitimate_constant_p (dstmode
, y
))
3664 oldcost
= set_src_cost (y
, speed
);
3666 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), speed
);
3668 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3669 srcmode
!= orig_srcmode
;
3670 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3673 rtx trunc_y
, last_insn
;
3675 /* Skip if the target can't extend this way. */
3676 ic
= can_extend_p (dstmode
, srcmode
, 0);
3677 if (ic
== CODE_FOR_nothing
)
3680 /* Skip if the narrowed value isn't exact. */
3681 if (! exact_real_truncate (srcmode
, &r
))
3684 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3686 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3688 /* Skip if the target needs extra instructions to perform
3690 if (!insn_operand_matches (ic
, 1, trunc_y
))
3692 /* This is valid, but may not be cheaper than the original. */
3693 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3695 if (oldcost
< newcost
)
3698 else if (float_extend_from_mem
[dstmode
][srcmode
])
3700 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3701 /* This is valid, but may not be cheaper than the original. */
3702 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3704 if (oldcost
< newcost
)
3706 trunc_y
= validize_mem (trunc_y
);
3711 /* For CSE's benefit, force the compressed constant pool entry
3712 into a new pseudo. This constant may be used in different modes,
3713 and if not, combine will put things back together for us. */
3714 trunc_y
= force_reg (srcmode
, trunc_y
);
3715 emit_unop_insn (ic
, x
, trunc_y
, UNKNOWN
);
3716 last_insn
= get_last_insn ();
3719 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3727 /* Pushing data onto the stack. */
3729 /* Push a block of length SIZE (perhaps variable)
3730 and return an rtx to address the beginning of the block.
3731 The value may be virtual_outgoing_args_rtx.
3733 EXTRA is the number of bytes of padding to push in addition to SIZE.
3734 BELOW nonzero means this padding comes at low addresses;
3735 otherwise, the padding comes at high addresses. */
3738 push_block (rtx size
, int extra
, int below
)
3742 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3743 if (CONSTANT_P (size
))
3744 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3745 else if (REG_P (size
) && extra
== 0)
3746 anti_adjust_stack (size
);
3749 temp
= copy_to_mode_reg (Pmode
, size
);
3751 temp
= expand_binop (Pmode
, add_optab
, temp
,
3752 gen_int_mode (extra
, Pmode
),
3753 temp
, 0, OPTAB_LIB_WIDEN
);
3754 anti_adjust_stack (temp
);
3757 #ifndef STACK_GROWS_DOWNWARD
3763 temp
= virtual_outgoing_args_rtx
;
3764 if (extra
!= 0 && below
)
3765 temp
= plus_constant (Pmode
, temp
, extra
);
3769 if (CONST_INT_P (size
))
3770 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3771 -INTVAL (size
) - (below
? 0 : extra
));
3772 else if (extra
!= 0 && !below
)
3773 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3774 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3777 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3778 negate_rtx (Pmode
, size
));
3781 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3784 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3787 mem_autoinc_base (rtx mem
)
3791 rtx addr
= XEXP (mem
, 0);
3792 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3793 return XEXP (addr
, 0);
3798 /* A utility routine used here, in reload, and in try_split. The insns
3799 after PREV up to and including LAST are known to adjust the stack,
3800 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3801 placing notes as appropriate. PREV may be NULL, indicating the
3802 entire insn sequence prior to LAST should be scanned.
3804 The set of allowed stack pointer modifications is small:
3805 (1) One or more auto-inc style memory references (aka pushes),
3806 (2) One or more addition/subtraction with the SP as destination,
3807 (3) A single move insn with the SP as destination,
3808 (4) A call_pop insn,
3809 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3811 Insns in the sequence that do not modify the SP are ignored,
3812 except for noreturn calls.
3814 The return value is the amount of adjustment that can be trivially
3815 verified, via immediate operand or auto-inc. If the adjustment
3816 cannot be trivially extracted, the return value is INT_MIN. */
3819 find_args_size_adjust (rtx insn
)
3824 pat
= PATTERN (insn
);
3827 /* Look for a call_pop pattern. */
3830 /* We have to allow non-call_pop patterns for the case
3831 of emit_single_push_insn of a TLS address. */
3832 if (GET_CODE (pat
) != PARALLEL
)
3835 /* All call_pop have a stack pointer adjust in the parallel.
3836 The call itself is always first, and the stack adjust is
3837 usually last, so search from the end. */
3838 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3840 set
= XVECEXP (pat
, 0, i
);
3841 if (GET_CODE (set
) != SET
)
3843 dest
= SET_DEST (set
);
3844 if (dest
== stack_pointer_rtx
)
3847 /* We'd better have found the stack pointer adjust. */
3850 /* Fall through to process the extracted SET and DEST
3851 as if it was a standalone insn. */
3853 else if (GET_CODE (pat
) == SET
)
3855 else if ((set
= single_set (insn
)) != NULL
)
3857 else if (GET_CODE (pat
) == PARALLEL
)
3859 /* ??? Some older ports use a parallel with a stack adjust
3860 and a store for a PUSH_ROUNDING pattern, rather than a
3861 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3862 /* ??? See h8300 and m68k, pushqi1. */
3863 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3865 set
= XVECEXP (pat
, 0, i
);
3866 if (GET_CODE (set
) != SET
)
3868 dest
= SET_DEST (set
);
3869 if (dest
== stack_pointer_rtx
)
3872 /* We do not expect an auto-inc of the sp in the parallel. */
3873 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3874 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3875 != stack_pointer_rtx
);
3883 dest
= SET_DEST (set
);
3885 /* Look for direct modifications of the stack pointer. */
3886 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3888 /* Look for a trivial adjustment, otherwise assume nothing. */
3889 /* Note that the SPU restore_stack_block pattern refers to
3890 the stack pointer in V4SImode. Consider that non-trivial. */
3891 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3892 && GET_CODE (SET_SRC (set
)) == PLUS
3893 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3894 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3895 return INTVAL (XEXP (SET_SRC (set
), 1));
3896 /* ??? Reload can generate no-op moves, which will be cleaned
3897 up later. Recognize it and continue searching. */
3898 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3901 return HOST_WIDE_INT_MIN
;
3907 /* Otherwise only think about autoinc patterns. */
3908 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3911 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3912 != stack_pointer_rtx
);
3914 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3915 mem
= SET_SRC (set
);
3919 addr
= XEXP (mem
, 0);
3920 switch (GET_CODE (addr
))
3924 return GET_MODE_SIZE (GET_MODE (mem
));
3927 return -GET_MODE_SIZE (GET_MODE (mem
));
3930 addr
= XEXP (addr
, 1);
3931 gcc_assert (GET_CODE (addr
) == PLUS
);
3932 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3933 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3934 return INTVAL (XEXP (addr
, 1));
3942 fixup_args_size_notes (rtx prev
, rtx last
, int end_args_size
)
3944 int args_size
= end_args_size
;
3945 bool saw_unknown
= false;
3948 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3950 HOST_WIDE_INT this_delta
;
3952 if (!NONDEBUG_INSN_P (insn
))
3955 this_delta
= find_args_size_adjust (insn
);
3956 if (this_delta
== 0)
3959 || ACCUMULATE_OUTGOING_ARGS
3960 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3964 gcc_assert (!saw_unknown
);
3965 if (this_delta
== HOST_WIDE_INT_MIN
)
3968 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3969 #ifdef STACK_GROWS_DOWNWARD
3970 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3972 args_size
-= this_delta
;
3975 return saw_unknown
? INT_MIN
: args_size
;
3978 #ifdef PUSH_ROUNDING
3979 /* Emit single push insn. */
3982 emit_single_push_insn_1 (enum machine_mode mode
, rtx x
, tree type
)
3985 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3987 enum insn_code icode
;
3989 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3990 /* If there is push pattern, use it. Otherwise try old way of throwing
3991 MEM representing push operation to move expander. */
3992 icode
= optab_handler (push_optab
, mode
);
3993 if (icode
!= CODE_FOR_nothing
)
3995 struct expand_operand ops
[1];
3997 create_input_operand (&ops
[0], x
, mode
);
3998 if (maybe_expand_insn (icode
, 1, ops
))
4001 if (GET_MODE_SIZE (mode
) == rounded_size
)
4002 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
4003 /* If we are to pad downward, adjust the stack pointer first and
4004 then store X into the stack location using an offset. This is
4005 because emit_move_insn does not know how to pad; it does not have
4007 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
4009 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
4010 HOST_WIDE_INT offset
;
4012 emit_move_insn (stack_pointer_rtx
,
4013 expand_binop (Pmode
,
4014 #ifdef STACK_GROWS_DOWNWARD
4020 gen_int_mode (rounded_size
, Pmode
),
4021 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
4023 offset
= (HOST_WIDE_INT
) padding_size
;
4024 #ifdef STACK_GROWS_DOWNWARD
4025 if (STACK_PUSH_CODE
== POST_DEC
)
4026 /* We have already decremented the stack pointer, so get the
4028 offset
+= (HOST_WIDE_INT
) rounded_size
;
4030 if (STACK_PUSH_CODE
== POST_INC
)
4031 /* We have already incremented the stack pointer, so get the
4033 offset
-= (HOST_WIDE_INT
) rounded_size
;
4035 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4036 gen_int_mode (offset
, Pmode
));
4040 #ifdef STACK_GROWS_DOWNWARD
4041 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4042 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4043 gen_int_mode (-(HOST_WIDE_INT
) rounded_size
,
4046 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4047 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4048 gen_int_mode (rounded_size
, Pmode
));
4050 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
4053 dest
= gen_rtx_MEM (mode
, dest_addr
);
4057 set_mem_attributes (dest
, type
, 1);
4059 if (flag_optimize_sibling_calls
)
4060 /* Function incoming arguments may overlap with sibling call
4061 outgoing arguments and we cannot allow reordering of reads
4062 from function arguments with stores to outgoing arguments
4063 of sibling calls. */
4064 set_mem_alias_set (dest
, 0);
4066 emit_move_insn (dest
, x
);
4069 /* Emit and annotate a single push insn. */
4072 emit_single_push_insn (enum machine_mode mode
, rtx x
, tree type
)
4074 int delta
, old_delta
= stack_pointer_delta
;
4075 rtx prev
= get_last_insn ();
4078 emit_single_push_insn_1 (mode
, x
, type
);
4080 last
= get_last_insn ();
4082 /* Notice the common case where we emitted exactly one insn. */
4083 if (PREV_INSN (last
) == prev
)
4085 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
4089 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
4090 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
4094 /* Generate code to push X onto the stack, assuming it has mode MODE and
4096 MODE is redundant except when X is a CONST_INT (since they don't
4098 SIZE is an rtx for the size of data to be copied (in bytes),
4099 needed only if X is BLKmode.
4101 ALIGN (in bits) is maximum alignment we can assume.
4103 If PARTIAL and REG are both nonzero, then copy that many of the first
4104 bytes of X into registers starting with REG, and push the rest of X.
4105 The amount of space pushed is decreased by PARTIAL bytes.
4106 REG must be a hard register in this case.
4107 If REG is zero but PARTIAL is not, take any all others actions for an
4108 argument partially in registers, but do not actually load any
4111 EXTRA is the amount in bytes of extra space to leave next to this arg.
4112 This is ignored if an argument block has already been allocated.
4114 On a machine that lacks real push insns, ARGS_ADDR is the address of
4115 the bottom of the argument block for this call. We use indexing off there
4116 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4117 argument block has not been preallocated.
4119 ARGS_SO_FAR is the size of args previously pushed for this call.
4121 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4122 for arguments passed in registers. If nonzero, it will be the number
4123 of bytes required. */
4126 emit_push_insn (rtx x
, enum machine_mode mode
, tree type
, rtx size
,
4127 unsigned int align
, int partial
, rtx reg
, int extra
,
4128 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4132 enum direction stack_direction
4133 #ifdef STACK_GROWS_DOWNWARD
4139 /* Decide where to pad the argument: `downward' for below,
4140 `upward' for above, or `none' for don't pad it.
4141 Default is below for small data on big-endian machines; else above. */
4142 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4144 /* Invert direction if stack is post-decrement.
4146 if (STACK_PUSH_CODE
== POST_DEC
)
4147 if (where_pad
!= none
)
4148 where_pad
= (where_pad
== downward
? upward
: downward
);
4153 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4155 /* Copy a block into the stack, entirely or partially. */
4162 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4163 used
= partial
- offset
;
4165 if (mode
!= BLKmode
)
4167 /* A value is to be stored in an insufficiently aligned
4168 stack slot; copy via a suitably aligned slot if
4170 size
= GEN_INT (GET_MODE_SIZE (mode
));
4171 if (!MEM_P (xinner
))
4173 temp
= assign_temp (type
, 1, 1);
4174 emit_move_insn (temp
, xinner
);
4181 /* USED is now the # of bytes we need not copy to the stack
4182 because registers will take care of them. */
4185 xinner
= adjust_address (xinner
, BLKmode
, used
);
4187 /* If the partial register-part of the arg counts in its stack size,
4188 skip the part of stack space corresponding to the registers.
4189 Otherwise, start copying to the beginning of the stack space,
4190 by setting SKIP to 0. */
4191 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4193 #ifdef PUSH_ROUNDING
4194 /* Do it with several push insns if that doesn't take lots of insns
4195 and if there is no difficulty with push insns that skip bytes
4196 on the stack for alignment purposes. */
4199 && CONST_INT_P (size
)
4201 && MEM_ALIGN (xinner
) >= align
4202 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size
) - used
, align
))
4203 /* Here we avoid the case of a structure whose weak alignment
4204 forces many pushes of a small amount of data,
4205 and such small pushes do rounding that causes trouble. */
4206 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4207 || align
>= BIGGEST_ALIGNMENT
4208 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4209 == (align
/ BITS_PER_UNIT
)))
4210 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4212 /* Push padding now if padding above and stack grows down,
4213 or if padding below and stack grows up.
4214 But if space already allocated, this has already been done. */
4215 if (extra
&& args_addr
== 0
4216 && where_pad
!= none
&& where_pad
!= stack_direction
)
4217 anti_adjust_stack (GEN_INT (extra
));
4219 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4222 #endif /* PUSH_ROUNDING */
4226 /* Otherwise make space on the stack and copy the data
4227 to the address of that space. */
4229 /* Deduct words put into registers from the size we must copy. */
4232 if (CONST_INT_P (size
))
4233 size
= GEN_INT (INTVAL (size
) - used
);
4235 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4236 gen_int_mode (used
, GET_MODE (size
)),
4237 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4240 /* Get the address of the stack space.
4241 In this case, we do not deal with EXTRA separately.
4242 A single stack adjust will do. */
4245 temp
= push_block (size
, extra
, where_pad
== downward
);
4248 else if (CONST_INT_P (args_so_far
))
4249 temp
= memory_address (BLKmode
,
4250 plus_constant (Pmode
, args_addr
,
4251 skip
+ INTVAL (args_so_far
)));
4253 temp
= memory_address (BLKmode
,
4254 plus_constant (Pmode
,
4255 gen_rtx_PLUS (Pmode
,
4260 if (!ACCUMULATE_OUTGOING_ARGS
)
4262 /* If the source is referenced relative to the stack pointer,
4263 copy it to another register to stabilize it. We do not need
4264 to do this if we know that we won't be changing sp. */
4266 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4267 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4268 temp
= copy_to_reg (temp
);
4271 target
= gen_rtx_MEM (BLKmode
, temp
);
4273 /* We do *not* set_mem_attributes here, because incoming arguments
4274 may overlap with sibling call outgoing arguments and we cannot
4275 allow reordering of reads from function arguments with stores
4276 to outgoing arguments of sibling calls. We do, however, want
4277 to record the alignment of the stack slot. */
4278 /* ALIGN may well be better aligned than TYPE, e.g. due to
4279 PARM_BOUNDARY. Assume the caller isn't lying. */
4280 set_mem_align (target
, align
);
4282 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4285 else if (partial
> 0)
4287 /* Scalar partly in registers. */
4289 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4292 /* # bytes of start of argument
4293 that we must make space for but need not store. */
4294 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4295 int args_offset
= INTVAL (args_so_far
);
4298 /* Push padding now if padding above and stack grows down,
4299 or if padding below and stack grows up.
4300 But if space already allocated, this has already been done. */
4301 if (extra
&& args_addr
== 0
4302 && where_pad
!= none
&& where_pad
!= stack_direction
)
4303 anti_adjust_stack (GEN_INT (extra
));
4305 /* If we make space by pushing it, we might as well push
4306 the real data. Otherwise, we can leave OFFSET nonzero
4307 and leave the space uninitialized. */
4311 /* Now NOT_STACK gets the number of words that we don't need to
4312 allocate on the stack. Convert OFFSET to words too. */
4313 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4314 offset
/= UNITS_PER_WORD
;
4316 /* If the partial register-part of the arg counts in its stack size,
4317 skip the part of stack space corresponding to the registers.
4318 Otherwise, start copying to the beginning of the stack space,
4319 by setting SKIP to 0. */
4320 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4322 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4323 x
= validize_mem (force_const_mem (mode
, x
));
4325 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4326 SUBREGs of such registers are not allowed. */
4327 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4328 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4329 x
= copy_to_reg (x
);
4331 /* Loop over all the words allocated on the stack for this arg. */
4332 /* We can do it by words, because any scalar bigger than a word
4333 has a size a multiple of a word. */
4334 #ifndef PUSH_ARGS_REVERSED
4335 for (i
= not_stack
; i
< size
; i
++)
4337 for (i
= size
- 1; i
>= not_stack
; i
--)
4339 if (i
>= not_stack
+ offset
)
4340 emit_push_insn (operand_subword_force (x
, i
, mode
),
4341 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4343 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4345 reg_parm_stack_space
, alignment_pad
);
4352 /* Push padding now if padding above and stack grows down,
4353 or if padding below and stack grows up.
4354 But if space already allocated, this has already been done. */
4355 if (extra
&& args_addr
== 0
4356 && where_pad
!= none
&& where_pad
!= stack_direction
)
4357 anti_adjust_stack (GEN_INT (extra
));
4359 #ifdef PUSH_ROUNDING
4360 if (args_addr
== 0 && PUSH_ARGS
)
4361 emit_single_push_insn (mode
, x
, type
);
4365 if (CONST_INT_P (args_so_far
))
4367 = memory_address (mode
,
4368 plus_constant (Pmode
, args_addr
,
4369 INTVAL (args_so_far
)));
4371 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4373 dest
= gen_rtx_MEM (mode
, addr
);
4375 /* We do *not* set_mem_attributes here, because incoming arguments
4376 may overlap with sibling call outgoing arguments and we cannot
4377 allow reordering of reads from function arguments with stores
4378 to outgoing arguments of sibling calls. We do, however, want
4379 to record the alignment of the stack slot. */
4380 /* ALIGN may well be better aligned than TYPE, e.g. due to
4381 PARM_BOUNDARY. Assume the caller isn't lying. */
4382 set_mem_align (dest
, align
);
4384 emit_move_insn (dest
, x
);
4388 /* If part should go in registers, copy that part
4389 into the appropriate registers. Do this now, at the end,
4390 since mem-to-mem copies above may do function calls. */
4391 if (partial
> 0 && reg
!= 0)
4393 /* Handle calls that pass values in multiple non-contiguous locations.
4394 The Irix 6 ABI has examples of this. */
4395 if (GET_CODE (reg
) == PARALLEL
)
4396 emit_group_load (reg
, x
, type
, -1);
4399 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4400 move_block_to_reg (REGNO (reg
), x
, partial
/ UNITS_PER_WORD
, mode
);
4404 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4405 anti_adjust_stack (GEN_INT (extra
));
4407 if (alignment_pad
&& args_addr
== 0)
4408 anti_adjust_stack (alignment_pad
);
4411 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4415 get_subtarget (rtx x
)
4419 /* Only registers can be subtargets. */
4421 /* Don't use hard regs to avoid extending their life. */
4422 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4426 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4427 FIELD is a bitfield. Returns true if the optimization was successful,
4428 and there's nothing else to do. */
4431 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4432 unsigned HOST_WIDE_INT bitpos
,
4433 unsigned HOST_WIDE_INT bitregion_start
,
4434 unsigned HOST_WIDE_INT bitregion_end
,
4435 enum machine_mode mode1
, rtx str_rtx
,
4438 enum machine_mode str_mode
= GET_MODE (str_rtx
);
4439 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4444 enum tree_code code
;
4446 if (mode1
!= VOIDmode
4447 || bitsize
>= BITS_PER_WORD
4448 || str_bitsize
> BITS_PER_WORD
4449 || TREE_SIDE_EFFECTS (to
)
4450 || TREE_THIS_VOLATILE (to
))
4454 if (TREE_CODE (src
) != SSA_NAME
)
4456 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4459 srcstmt
= get_gimple_for_ssa_name (src
);
4461 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4464 code
= gimple_assign_rhs_code (srcstmt
);
4466 op0
= gimple_assign_rhs1 (srcstmt
);
4468 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4469 to find its initialization. Hopefully the initialization will
4470 be from a bitfield load. */
4471 if (TREE_CODE (op0
) == SSA_NAME
)
4473 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4475 /* We want to eventually have OP0 be the same as TO, which
4476 should be a bitfield. */
4478 || !is_gimple_assign (op0stmt
)
4479 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4481 op0
= gimple_assign_rhs1 (op0stmt
);
4484 op1
= gimple_assign_rhs2 (srcstmt
);
4486 if (!operand_equal_p (to
, op0
, 0))
4489 if (MEM_P (str_rtx
))
4491 unsigned HOST_WIDE_INT offset1
;
4493 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4494 str_mode
= word_mode
;
4495 str_mode
= get_best_mode (bitsize
, bitpos
,
4496 bitregion_start
, bitregion_end
,
4497 MEM_ALIGN (str_rtx
), str_mode
, 0);
4498 if (str_mode
== VOIDmode
)
4500 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4503 bitpos
%= str_bitsize
;
4504 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4505 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4507 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4510 /* If the bit field covers the whole REG/MEM, store_field
4511 will likely generate better code. */
4512 if (bitsize
>= str_bitsize
)
4515 /* We can't handle fields split across multiple entities. */
4516 if (bitpos
+ bitsize
> str_bitsize
)
4519 if (BYTES_BIG_ENDIAN
)
4520 bitpos
= str_bitsize
- bitpos
- bitsize
;
4526 /* For now, just optimize the case of the topmost bitfield
4527 where we don't need to do any masking and also
4528 1 bit bitfields where xor can be used.
4529 We might win by one instruction for the other bitfields
4530 too if insv/extv instructions aren't used, so that
4531 can be added later. */
4532 if (bitpos
+ bitsize
!= str_bitsize
4533 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4536 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4537 value
= convert_modes (str_mode
,
4538 TYPE_MODE (TREE_TYPE (op1
)), value
,
4539 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4541 /* We may be accessing data outside the field, which means
4542 we can alias adjacent data. */
4543 if (MEM_P (str_rtx
))
4545 str_rtx
= shallow_copy_rtx (str_rtx
);
4546 set_mem_alias_set (str_rtx
, 0);
4547 set_mem_expr (str_rtx
, 0);
4550 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4551 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4553 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4556 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4557 result
= expand_binop (str_mode
, binop
, str_rtx
,
4558 value
, str_rtx
, 1, OPTAB_WIDEN
);
4559 if (result
!= str_rtx
)
4560 emit_move_insn (str_rtx
, result
);
4565 if (TREE_CODE (op1
) != INTEGER_CST
)
4567 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4568 value
= convert_modes (str_mode
,
4569 TYPE_MODE (TREE_TYPE (op1
)), value
,
4570 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4572 /* We may be accessing data outside the field, which means
4573 we can alias adjacent data. */
4574 if (MEM_P (str_rtx
))
4576 str_rtx
= shallow_copy_rtx (str_rtx
);
4577 set_mem_alias_set (str_rtx
, 0);
4578 set_mem_expr (str_rtx
, 0);
4581 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4582 if (bitpos
+ bitsize
!= str_bitsize
)
4584 rtx mask
= gen_int_mode (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1,
4586 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4588 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4589 result
= expand_binop (str_mode
, binop
, str_rtx
,
4590 value
, str_rtx
, 1, OPTAB_WIDEN
);
4591 if (result
!= str_rtx
)
4592 emit_move_insn (str_rtx
, result
);
4602 /* In the C++ memory model, consecutive bit fields in a structure are
4603 considered one memory location.
4605 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4606 returns the bit range of consecutive bits in which this COMPONENT_REF
4607 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4608 and *OFFSET may be adjusted in the process.
4610 If the access does not need to be restricted, 0 is returned in both
4611 *BITSTART and *BITEND. */
4614 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4615 unsigned HOST_WIDE_INT
*bitend
,
4617 HOST_WIDE_INT
*bitpos
,
4620 HOST_WIDE_INT bitoffset
;
4623 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4625 field
= TREE_OPERAND (exp
, 1);
4626 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4627 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4628 need to limit the range we can access. */
4631 *bitstart
= *bitend
= 0;
4635 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4636 part of a larger bit field, then the representative does not serve any
4637 useful purpose. This can occur in Ada. */
4638 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4640 enum machine_mode rmode
;
4641 HOST_WIDE_INT rbitsize
, rbitpos
;
4645 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4646 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4647 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4649 *bitstart
= *bitend
= 0;
4654 /* Compute the adjustment to bitpos from the offset of the field
4655 relative to the representative. DECL_FIELD_OFFSET of field and
4656 repr are the same by construction if they are not constants,
4657 see finish_bitfield_layout. */
4658 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
4659 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
4660 bitoffset
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
4661 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
4664 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
4665 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
4667 /* If the adjustment is larger than bitpos, we would have a negative bit
4668 position for the lower bound and this may wreak havoc later. Adjust
4669 offset and bitpos to make the lower bound non-negative in that case. */
4670 if (bitoffset
> *bitpos
)
4672 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4673 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4676 if (*offset
== NULL_TREE
)
4677 *offset
= size_int (-adjust
/ BITS_PER_UNIT
);
4680 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4684 *bitstart
= *bitpos
- bitoffset
;
4686 *bitend
= *bitstart
+ tree_to_uhwi (DECL_SIZE (repr
)) - 1;
4689 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4690 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4691 DECL_RTL was not set yet, return NORTL. */
4694 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4696 if (TREE_CODE (addr
) != ADDR_EXPR
)
4699 tree base
= TREE_OPERAND (addr
, 0);
4702 || TREE_ADDRESSABLE (base
)
4703 || DECL_MODE (base
) == BLKmode
)
4706 if (!DECL_RTL_SET_P (base
))
4709 return (!MEM_P (DECL_RTL (base
)));
4712 /* Returns true if the MEM_REF REF refers to an object that does not
4713 reside in memory and has non-BLKmode. */
4716 mem_ref_refers_to_non_mem_p (tree ref
)
4718 tree base
= TREE_OPERAND (ref
, 0);
4719 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4722 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4723 is true, try generating a nontemporal store. */
4726 expand_assignment (tree to
, tree from
, bool nontemporal
)
4730 enum machine_mode mode
;
4732 enum insn_code icode
;
4734 /* Don't crash if the lhs of the assignment was erroneous. */
4735 if (TREE_CODE (to
) == ERROR_MARK
)
4737 expand_normal (from
);
4741 /* Optimize away no-op moves without side-effects. */
4742 if (operand_equal_p (to
, from
, 0))
4745 /* Handle misaligned stores. */
4746 mode
= TYPE_MODE (TREE_TYPE (to
));
4747 if ((TREE_CODE (to
) == MEM_REF
4748 || TREE_CODE (to
) == TARGET_MEM_REF
)
4750 && !mem_ref_refers_to_non_mem_p (to
)
4751 && ((align
= get_object_alignment (to
))
4752 < GET_MODE_ALIGNMENT (mode
))
4753 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4754 != CODE_FOR_nothing
)
4755 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4759 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4760 reg
= force_not_mem (reg
);
4761 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4763 if (icode
!= CODE_FOR_nothing
)
4765 struct expand_operand ops
[2];
4767 create_fixed_operand (&ops
[0], mem
);
4768 create_input_operand (&ops
[1], reg
, mode
);
4769 /* The movmisalign<mode> pattern cannot fail, else the assignment
4770 would silently be omitted. */
4771 expand_insn (icode
, 2, ops
);
4774 store_bit_field (mem
, GET_MODE_BITSIZE (mode
),
4775 0, 0, 0, mode
, reg
);
4779 /* Assignment of a structure component needs special treatment
4780 if the structure component's rtx is not simply a MEM.
4781 Assignment of an array element at a constant index, and assignment of
4782 an array element in an unaligned packed structure field, has the same
4783 problem. Same for (partially) storing into a non-memory object. */
4784 if (handled_component_p (to
)
4785 || (TREE_CODE (to
) == MEM_REF
4786 && mem_ref_refers_to_non_mem_p (to
))
4787 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4789 enum machine_mode mode1
;
4790 HOST_WIDE_INT bitsize
, bitpos
;
4791 unsigned HOST_WIDE_INT bitregion_start
= 0;
4792 unsigned HOST_WIDE_INT bitregion_end
= 0;
4799 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4800 &unsignedp
, &volatilep
, true);
4802 /* Make sure bitpos is not negative, it can wreak havoc later. */
4805 gcc_assert (offset
== NULL_TREE
);
4806 offset
= size_int (bitpos
>> (BITS_PER_UNIT
== 8
4807 ? 3 : exact_log2 (BITS_PER_UNIT
)));
4808 bitpos
&= BITS_PER_UNIT
- 1;
4811 if (TREE_CODE (to
) == COMPONENT_REF
4812 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4813 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4815 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4817 /* If the bitfield is volatile, we want to access it in the
4818 field's mode, not the computed mode.
4819 If a MEM has VOIDmode (external with incomplete type),
4820 use BLKmode for it instead. */
4823 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
4824 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4825 else if (GET_MODE (to_rtx
) == VOIDmode
)
4826 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4831 enum machine_mode address_mode
;
4834 if (!MEM_P (to_rtx
))
4836 /* We can get constant negative offsets into arrays with broken
4837 user code. Translate this to a trap instead of ICEing. */
4838 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4839 expand_builtin_trap ();
4840 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4843 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4844 address_mode
= get_address_mode (to_rtx
);
4845 if (GET_MODE (offset_rtx
) != address_mode
)
4846 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4848 /* A constant address in TO_RTX can have VOIDmode, we must not try
4849 to call force_reg for that case. Avoid that case. */
4851 && GET_MODE (to_rtx
) == BLKmode
4852 && GET_MODE (XEXP (to_rtx
, 0)) != VOIDmode
4854 && (bitpos
% bitsize
) == 0
4855 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4856 && MEM_ALIGN (to_rtx
) == GET_MODE_ALIGNMENT (mode1
))
4858 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4862 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4863 highest_pow2_factor_for_target (to
,
4867 /* No action is needed if the target is not a memory and the field
4868 lies completely outside that target. This can occur if the source
4869 code contains an out-of-bounds access to a small array. */
4871 && GET_MODE (to_rtx
) != BLKmode
4872 && (unsigned HOST_WIDE_INT
) bitpos
4873 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4875 expand_normal (from
);
4878 /* Handle expand_expr of a complex value returning a CONCAT. */
4879 else if (GET_CODE (to_rtx
) == CONCAT
)
4881 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4882 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4884 && bitsize
== mode_bitsize
)
4885 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4886 else if (bitsize
== mode_bitsize
/ 2
4887 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4888 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4890 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4891 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4892 bitregion_start
, bitregion_end
,
4894 get_alias_set (to
), nontemporal
);
4895 else if (bitpos
>= mode_bitsize
/ 2)
4896 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4897 bitpos
- mode_bitsize
/ 2,
4898 bitregion_start
, bitregion_end
,
4900 get_alias_set (to
), nontemporal
);
4901 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4904 result
= expand_normal (from
);
4905 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4906 TYPE_MODE (TREE_TYPE (from
)), 0);
4907 emit_move_insn (XEXP (to_rtx
, 0),
4908 read_complex_part (from_rtx
, false));
4909 emit_move_insn (XEXP (to_rtx
, 1),
4910 read_complex_part (from_rtx
, true));
4914 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4915 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4916 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4917 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4918 result
= store_field (temp
, bitsize
, bitpos
,
4919 bitregion_start
, bitregion_end
,
4921 get_alias_set (to
), nontemporal
);
4922 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4923 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
4930 /* If the field is at offset zero, we could have been given the
4931 DECL_RTX of the parent struct. Don't munge it. */
4932 to_rtx
= shallow_copy_rtx (to_rtx
);
4933 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
4935 MEM_VOLATILE_P (to_rtx
) = 1;
4938 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
4939 bitregion_start
, bitregion_end
,
4944 result
= store_field (to_rtx
, bitsize
, bitpos
,
4945 bitregion_start
, bitregion_end
,
4947 get_alias_set (to
), nontemporal
);
4951 preserve_temp_slots (result
);
4956 /* If the rhs is a function call and its value is not an aggregate,
4957 call the function before we start to compute the lhs.
4958 This is needed for correct code for cases such as
4959 val = setjmp (buf) on machines where reference to val
4960 requires loading up part of an address in a separate insn.
4962 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4963 since it might be a promoted variable where the zero- or sign- extension
4964 needs to be done. Handling this in the normal way is safe because no
4965 computation is done before the call. The same is true for SSA names. */
4966 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
4967 && COMPLETE_TYPE_P (TREE_TYPE (from
))
4968 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
4969 && ! (((TREE_CODE (to
) == VAR_DECL
4970 || TREE_CODE (to
) == PARM_DECL
4971 || TREE_CODE (to
) == RESULT_DECL
)
4972 && REG_P (DECL_RTL (to
)))
4973 || TREE_CODE (to
) == SSA_NAME
))
4978 value
= expand_normal (from
);
4980 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4982 /* Handle calls that return values in multiple non-contiguous locations.
4983 The Irix 6 ABI has examples of this. */
4984 if (GET_CODE (to_rtx
) == PARALLEL
)
4986 if (GET_CODE (value
) == PARALLEL
)
4987 emit_group_move (to_rtx
, value
);
4989 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
4990 int_size_in_bytes (TREE_TYPE (from
)));
4992 else if (GET_CODE (value
) == PARALLEL
)
4993 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
4994 int_size_in_bytes (TREE_TYPE (from
)));
4995 else if (GET_MODE (to_rtx
) == BLKmode
)
4997 /* Handle calls that return BLKmode values in registers. */
4999 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
5001 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
5005 if (POINTER_TYPE_P (TREE_TYPE (to
)))
5006 value
= convert_memory_address_addr_space
5007 (GET_MODE (to_rtx
), value
,
5008 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
5010 emit_move_insn (to_rtx
, value
);
5012 preserve_temp_slots (to_rtx
);
5017 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5018 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5020 /* Don't move directly into a return register. */
5021 if (TREE_CODE (to
) == RESULT_DECL
5022 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
5028 /* If the source is itself a return value, it still is in a pseudo at
5029 this point so we can move it back to the return register directly. */
5031 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
5032 && TREE_CODE (from
) != CALL_EXPR
)
5033 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
5035 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
5037 /* Handle calls that return values in multiple non-contiguous locations.
5038 The Irix 6 ABI has examples of this. */
5039 if (GET_CODE (to_rtx
) == PARALLEL
)
5041 if (GET_CODE (temp
) == PARALLEL
)
5042 emit_group_move (to_rtx
, temp
);
5044 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
5045 int_size_in_bytes (TREE_TYPE (from
)));
5048 emit_move_insn (to_rtx
, temp
);
5050 preserve_temp_slots (to_rtx
);
5055 /* In case we are returning the contents of an object which overlaps
5056 the place the value is being stored, use a safe function when copying
5057 a value through a pointer into a structure value return block. */
5058 if (TREE_CODE (to
) == RESULT_DECL
5059 && TREE_CODE (from
) == INDIRECT_REF
5060 && ADDR_SPACE_GENERIC_P
5061 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5062 && refs_may_alias_p (to
, from
)
5063 && cfun
->returns_struct
5064 && !cfun
->returns_pcc_struct
)
5069 size
= expr_size (from
);
5070 from_rtx
= expand_normal (from
);
5072 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
5073 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
5074 XEXP (from_rtx
, 0), Pmode
,
5075 convert_to_mode (TYPE_MODE (sizetype
),
5076 size
, TYPE_UNSIGNED (sizetype
)),
5077 TYPE_MODE (sizetype
));
5079 preserve_temp_slots (to_rtx
);
5084 /* Compute FROM and store the value in the rtx we got. */
5087 result
= store_expr (from
, to_rtx
, 0, nontemporal
);
5088 preserve_temp_slots (result
);
5093 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5094 succeeded, false otherwise. */
5097 emit_storent_insn (rtx to
, rtx from
)
5099 struct expand_operand ops
[2];
5100 enum machine_mode mode
= GET_MODE (to
);
5101 enum insn_code code
= optab_handler (storent_optab
, mode
);
5103 if (code
== CODE_FOR_nothing
)
5106 create_fixed_operand (&ops
[0], to
);
5107 create_input_operand (&ops
[1], from
, mode
);
5108 return maybe_expand_insn (code
, 2, ops
);
5111 /* Generate code for computing expression EXP,
5112 and storing the value into TARGET.
5114 If the mode is BLKmode then we may return TARGET itself.
5115 It turns out that in BLKmode it doesn't cause a problem.
5116 because C has no operators that could combine two different
5117 assignments into the same BLKmode object with different values
5118 with no sequence point. Will other languages need this to
5121 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5122 stack, and block moves may need to be treated specially.
5124 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5127 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5130 rtx alt_rtl
= NULL_RTX
;
5131 location_t loc
= curr_insn_location ();
5133 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5135 /* C++ can generate ?: expressions with a throw expression in one
5136 branch and an rvalue in the other. Here, we resolve attempts to
5137 store the throw expression's nonexistent result. */
5138 gcc_assert (!call_param_p
);
5139 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5142 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5144 /* Perform first part of compound expression, then assign from second
5146 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5147 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5148 return store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5151 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5153 /* For conditional expression, get safe form of the target. Then
5154 test the condition, doing the appropriate assignment on either
5155 side. This avoids the creation of unnecessary temporaries.
5156 For non-BLKmode, it is more efficient not to do this. */
5158 rtx lab1
= gen_label_rtx (), lab2
= gen_label_rtx ();
5160 do_pending_stack_adjust ();
5162 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5163 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5165 emit_jump_insn (gen_jump (lab2
));
5168 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5175 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5176 /* If this is a scalar in a register that is stored in a wider mode
5177 than the declared mode, compute the result into its declared mode
5178 and then convert to the wider mode. Our value is the computed
5181 rtx inner_target
= 0;
5183 /* We can do the conversion inside EXP, which will often result
5184 in some optimizations. Do the conversion in two steps: first
5185 change the signedness, if needed, then the extend. But don't
5186 do this if the type of EXP is a subtype of something else
5187 since then the conversion might involve more than just
5188 converting modes. */
5189 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5190 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5191 && GET_MODE_PRECISION (GET_MODE (target
))
5192 == TYPE_PRECISION (TREE_TYPE (exp
)))
5194 if (TYPE_UNSIGNED (TREE_TYPE (exp
))
5195 != SUBREG_PROMOTED_UNSIGNED_P (target
))
5197 /* Some types, e.g. Fortran's logical*4, won't have a signed
5198 version, so use the mode instead. */
5200 = (signed_or_unsigned_type_for
5201 (SUBREG_PROMOTED_UNSIGNED_P (target
), TREE_TYPE (exp
)));
5203 ntype
= lang_hooks
.types
.type_for_mode
5204 (TYPE_MODE (TREE_TYPE (exp
)),
5205 SUBREG_PROMOTED_UNSIGNED_P (target
));
5207 exp
= fold_convert_loc (loc
, ntype
, exp
);
5210 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5211 (GET_MODE (SUBREG_REG (target
)),
5212 SUBREG_PROMOTED_UNSIGNED_P (target
)),
5215 inner_target
= SUBREG_REG (target
);
5218 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5219 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5221 /* If TEMP is a VOIDmode constant, use convert_modes to make
5222 sure that we properly convert it. */
5223 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5225 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5226 temp
, SUBREG_PROMOTED_UNSIGNED_P (target
));
5227 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5228 GET_MODE (target
), temp
,
5229 SUBREG_PROMOTED_UNSIGNED_P (target
));
5232 convert_move (SUBREG_REG (target
), temp
,
5233 SUBREG_PROMOTED_UNSIGNED_P (target
));
5237 else if ((TREE_CODE (exp
) == STRING_CST
5238 || (TREE_CODE (exp
) == MEM_REF
5239 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5240 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5242 && integer_zerop (TREE_OPERAND (exp
, 1))))
5243 && !nontemporal
&& !call_param_p
5246 /* Optimize initialization of an array with a STRING_CST. */
5247 HOST_WIDE_INT exp_len
, str_copy_len
;
5249 tree str
= TREE_CODE (exp
) == STRING_CST
5250 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5252 exp_len
= int_expr_size (exp
);
5256 if (TREE_STRING_LENGTH (str
) <= 0)
5259 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5260 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5263 str_copy_len
= TREE_STRING_LENGTH (str
);
5264 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5265 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5267 str_copy_len
+= STORE_MAX_PIECES
- 1;
5268 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5270 str_copy_len
= MIN (str_copy_len
, exp_len
);
5271 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5272 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5273 MEM_ALIGN (target
), false))
5278 dest_mem
= store_by_pieces (dest_mem
,
5279 str_copy_len
, builtin_strncpy_read_str
,
5281 TREE_STRING_POINTER (str
)),
5282 MEM_ALIGN (target
), false,
5283 exp_len
> str_copy_len
? 1 : 0);
5284 if (exp_len
> str_copy_len
)
5285 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5286 GEN_INT (exp_len
- str_copy_len
),
5295 /* If we want to use a nontemporal store, force the value to
5297 tmp_target
= nontemporal
? NULL_RTX
: target
;
5298 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5300 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5304 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5305 the same as that of TARGET, adjust the constant. This is needed, for
5306 example, in case it is a CONST_DOUBLE and we want only a word-sized
5308 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5309 && TREE_CODE (exp
) != ERROR_MARK
5310 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5311 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5312 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5314 /* If value was not generated in the target, store it there.
5315 Convert the value to TARGET's type first if necessary and emit the
5316 pending incrementations that have been queued when expanding EXP.
5317 Note that we cannot emit the whole queue blindly because this will
5318 effectively disable the POST_INC optimization later.
5320 If TEMP and TARGET compare equal according to rtx_equal_p, but
5321 one or both of them are volatile memory refs, we have to distinguish
5323 - expand_expr has used TARGET. In this case, we must not generate
5324 another copy. This can be detected by TARGET being equal according
5326 - expand_expr has not used TARGET - that means that the source just
5327 happens to have the same RTX form. Since temp will have been created
5328 by expand_expr, it will compare unequal according to == .
5329 We must generate a copy in this case, to reach the correct number
5330 of volatile memory references. */
5332 if ((! rtx_equal_p (temp
, target
)
5333 || (temp
!= target
&& (side_effects_p (temp
)
5334 || side_effects_p (target
))))
5335 && TREE_CODE (exp
) != ERROR_MARK
5336 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5337 but TARGET is not valid memory reference, TEMP will differ
5338 from TARGET although it is really the same location. */
5340 && rtx_equal_p (alt_rtl
, target
)
5341 && !side_effects_p (alt_rtl
)
5342 && !side_effects_p (target
))
5343 /* If there's nothing to copy, don't bother. Don't call
5344 expr_size unless necessary, because some front-ends (C++)
5345 expr_size-hook must not be given objects that are not
5346 supposed to be bit-copied or bit-initialized. */
5347 && expr_size (exp
) != const0_rtx
)
5349 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5351 if (GET_MODE (target
) == BLKmode
)
5353 /* Handle calls that return BLKmode values in registers. */
5354 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5355 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5357 store_bit_field (target
,
5358 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5359 0, 0, 0, GET_MODE (temp
), temp
);
5362 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5365 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5367 /* Handle copying a string constant into an array. The string
5368 constant may be shorter than the array. So copy just the string's
5369 actual length, and clear the rest. First get the size of the data
5370 type of the string, which is actually the size of the target. */
5371 rtx size
= expr_size (exp
);
5373 if (CONST_INT_P (size
)
5374 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5375 emit_block_move (target
, temp
, size
,
5377 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5380 enum machine_mode pointer_mode
5381 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5382 enum machine_mode address_mode
= get_address_mode (target
);
5384 /* Compute the size of the data to copy from the string. */
5386 = size_binop_loc (loc
, MIN_EXPR
,
5387 make_tree (sizetype
, size
),
5388 size_int (TREE_STRING_LENGTH (exp
)));
5390 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5392 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5395 /* Copy that much. */
5396 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5397 TYPE_UNSIGNED (sizetype
));
5398 emit_block_move (target
, temp
, copy_size_rtx
,
5400 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5402 /* Figure out how much is left in TARGET that we have to clear.
5403 Do all calculations in pointer_mode. */
5404 if (CONST_INT_P (copy_size_rtx
))
5406 size
= plus_constant (address_mode
, size
,
5407 -INTVAL (copy_size_rtx
));
5408 target
= adjust_address (target
, BLKmode
,
5409 INTVAL (copy_size_rtx
));
5413 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5414 copy_size_rtx
, NULL_RTX
, 0,
5417 if (GET_MODE (copy_size_rtx
) != address_mode
)
5418 copy_size_rtx
= convert_to_mode (address_mode
,
5420 TYPE_UNSIGNED (sizetype
));
5422 target
= offset_address (target
, copy_size_rtx
,
5423 highest_pow2_factor (copy_size
));
5424 label
= gen_label_rtx ();
5425 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5426 GET_MODE (size
), 0, label
);
5429 if (size
!= const0_rtx
)
5430 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5436 /* Handle calls that return values in multiple non-contiguous locations.
5437 The Irix 6 ABI has examples of this. */
5438 else if (GET_CODE (target
) == PARALLEL
)
5440 if (GET_CODE (temp
) == PARALLEL
)
5441 emit_group_move (target
, temp
);
5443 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5444 int_size_in_bytes (TREE_TYPE (exp
)));
5446 else if (GET_CODE (temp
) == PARALLEL
)
5447 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5448 int_size_in_bytes (TREE_TYPE (exp
)));
5449 else if (GET_MODE (temp
) == BLKmode
)
5450 emit_block_move (target
, temp
, expr_size (exp
),
5452 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5453 /* If we emit a nontemporal store, there is nothing else to do. */
5454 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5458 temp
= force_operand (temp
, target
);
5460 emit_move_insn (target
, temp
);
5467 /* Return true if field F of structure TYPE is a flexible array. */
5470 flexible_array_member_p (const_tree f
, const_tree type
)
5475 return (DECL_CHAIN (f
) == NULL
5476 && TREE_CODE (tf
) == ARRAY_TYPE
5478 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5479 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5480 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5481 && int_size_in_bytes (type
) >= 0);
5484 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5485 must have in order for it to completely initialize a value of type TYPE.
5486 Return -1 if the number isn't known.
5488 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5490 static HOST_WIDE_INT
5491 count_type_elements (const_tree type
, bool for_ctor_p
)
5493 switch (TREE_CODE (type
))
5499 nelts
= array_type_nelts (type
);
5500 if (nelts
&& tree_fits_uhwi_p (nelts
))
5502 unsigned HOST_WIDE_INT n
;
5504 n
= tree_to_uhwi (nelts
) + 1;
5505 if (n
== 0 || for_ctor_p
)
5508 return n
* count_type_elements (TREE_TYPE (type
), false);
5510 return for_ctor_p
? -1 : 1;
5515 unsigned HOST_WIDE_INT n
;
5519 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5520 if (TREE_CODE (f
) == FIELD_DECL
)
5523 n
+= count_type_elements (TREE_TYPE (f
), false);
5524 else if (!flexible_array_member_p (f
, type
))
5525 /* Don't count flexible arrays, which are not supposed
5526 to be initialized. */
5534 case QUAL_UNION_TYPE
:
5539 gcc_assert (!for_ctor_p
);
5540 /* Estimate the number of scalars in each field and pick the
5541 maximum. Other estimates would do instead; the idea is simply
5542 to make sure that the estimate is not sensitive to the ordering
5545 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5546 if (TREE_CODE (f
) == FIELD_DECL
)
5548 m
= count_type_elements (TREE_TYPE (f
), false);
5549 /* If the field doesn't span the whole union, add an extra
5550 scalar for the rest. */
5551 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5552 TYPE_SIZE (type
)) != 1)
5564 return TYPE_VECTOR_SUBPARTS (type
);
5568 case FIXED_POINT_TYPE
:
5573 case REFERENCE_TYPE
:
5589 /* Helper for categorize_ctor_elements. Identical interface. */
5592 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5593 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5595 unsigned HOST_WIDE_INT idx
;
5596 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5597 tree value
, purpose
, elt_type
;
5599 /* Whether CTOR is a valid constant initializer, in accordance with what
5600 initializer_constant_valid_p does. If inferred from the constructor
5601 elements, true until proven otherwise. */
5602 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5603 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5608 elt_type
= NULL_TREE
;
5610 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5612 HOST_WIDE_INT mult
= 1;
5614 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5616 tree lo_index
= TREE_OPERAND (purpose
, 0);
5617 tree hi_index
= TREE_OPERAND (purpose
, 1);
5619 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5620 mult
= (tree_to_uhwi (hi_index
)
5621 - tree_to_uhwi (lo_index
) + 1);
5624 elt_type
= TREE_TYPE (value
);
5626 switch (TREE_CODE (value
))
5630 HOST_WIDE_INT nz
= 0, ic
= 0;
5632 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5635 nz_elts
+= mult
* nz
;
5636 init_elts
+= mult
* ic
;
5638 if (const_from_elts_p
&& const_p
)
5639 const_p
= const_elt_p
;
5646 if (!initializer_zerop (value
))
5652 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5653 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5657 if (!initializer_zerop (TREE_REALPART (value
)))
5659 if (!initializer_zerop (TREE_IMAGPART (value
)))
5667 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5669 tree v
= VECTOR_CST_ELT (value
, i
);
5670 if (!initializer_zerop (v
))
5679 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5680 nz_elts
+= mult
* tc
;
5681 init_elts
+= mult
* tc
;
5683 if (const_from_elts_p
&& const_p
)
5684 const_p
= initializer_constant_valid_p (value
, elt_type
)
5691 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5692 num_fields
, elt_type
))
5693 *p_complete
= false;
5695 *p_nz_elts
+= nz_elts
;
5696 *p_init_elts
+= init_elts
;
5701 /* Examine CTOR to discover:
5702 * how many scalar fields are set to nonzero values,
5703 and place it in *P_NZ_ELTS;
5704 * how many scalar fields in total are in CTOR,
5705 and place it in *P_ELT_COUNT.
5706 * whether the constructor is complete -- in the sense that every
5707 meaningful byte is explicitly given a value --
5708 and place it in *P_COMPLETE.
5710 Return whether or not CTOR is a valid static constant initializer, the same
5711 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5714 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5715 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5721 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5724 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5725 of which had type LAST_TYPE. Each element was itself a complete
5726 initializer, in the sense that every meaningful byte was explicitly
5727 given a value. Return true if the same is true for the constructor
5731 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5732 const_tree last_type
)
5734 if (TREE_CODE (type
) == UNION_TYPE
5735 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5740 gcc_assert (num_elts
== 1 && last_type
);
5742 /* ??? We could look at each element of the union, and find the
5743 largest element. Which would avoid comparing the size of the
5744 initialized element against any tail padding in the union.
5745 Doesn't seem worth the effort... */
5746 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5749 return count_type_elements (type
, true) == num_elts
;
5752 /* Return 1 if EXP contains mostly (3/4) zeros. */
5755 mostly_zeros_p (const_tree exp
)
5757 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5759 HOST_WIDE_INT nz_elts
, init_elts
;
5762 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5763 return !complete_p
|| nz_elts
< init_elts
/ 4;
5766 return initializer_zerop (exp
);
5769 /* Return 1 if EXP contains all zeros. */
5772 all_zeros_p (const_tree exp
)
5774 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5776 HOST_WIDE_INT nz_elts
, init_elts
;
5779 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5780 return nz_elts
== 0;
5783 return initializer_zerop (exp
);
5786 /* Helper function for store_constructor.
5787 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5788 CLEARED is as for store_constructor.
5789 ALIAS_SET is the alias set to use for any stores.
5791 This provides a recursive shortcut back to store_constructor when it isn't
5792 necessary to go through store_field. This is so that we can pass through
5793 the cleared field to let store_constructor know that we may not have to
5794 clear a substructure if the outer structure has already been cleared. */
5797 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5798 HOST_WIDE_INT bitpos
, enum machine_mode mode
,
5799 tree exp
, int cleared
, alias_set_type alias_set
)
5801 if (TREE_CODE (exp
) == CONSTRUCTOR
5802 /* We can only call store_constructor recursively if the size and
5803 bit position are on a byte boundary. */
5804 && bitpos
% BITS_PER_UNIT
== 0
5805 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5806 /* If we have a nonzero bitpos for a register target, then we just
5807 let store_field do the bitfield handling. This is unlikely to
5808 generate unnecessary clear instructions anyways. */
5809 && (bitpos
== 0 || MEM_P (target
)))
5813 = adjust_address (target
,
5814 GET_MODE (target
) == BLKmode
5816 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5817 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5820 /* Update the alias set, if required. */
5821 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5822 && MEM_ALIAS_SET (target
) != 0)
5824 target
= copy_rtx (target
);
5825 set_mem_alias_set (target
, alias_set
);
5828 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5831 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5835 /* Returns the number of FIELD_DECLs in TYPE. */
5838 fields_length (const_tree type
)
5840 tree t
= TYPE_FIELDS (type
);
5843 for (; t
; t
= DECL_CHAIN (t
))
5844 if (TREE_CODE (t
) == FIELD_DECL
)
5851 /* Store the value of constructor EXP into the rtx TARGET.
5852 TARGET is either a REG or a MEM; we know it cannot conflict, since
5853 safe_from_p has been called.
5854 CLEARED is true if TARGET is known to have been zero'd.
5855 SIZE is the number of bytes of TARGET we are allowed to modify: this
5856 may not be the same as the size of EXP if we are assigning to a field
5857 which has been packed to exclude padding bits. */
5860 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5862 tree type
= TREE_TYPE (exp
);
5863 #ifdef WORD_REGISTER_OPERATIONS
5864 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5867 switch (TREE_CODE (type
))
5871 case QUAL_UNION_TYPE
:
5873 unsigned HOST_WIDE_INT idx
;
5876 /* If size is zero or the target is already cleared, do nothing. */
5877 if (size
== 0 || cleared
)
5879 /* We either clear the aggregate or indicate the value is dead. */
5880 else if ((TREE_CODE (type
) == UNION_TYPE
5881 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5882 && ! CONSTRUCTOR_ELTS (exp
))
5883 /* If the constructor is empty, clear the union. */
5885 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
5889 /* If we are building a static constructor into a register,
5890 set the initial value as zero so we can fold the value into
5891 a constant. But if more than one register is involved,
5892 this probably loses. */
5893 else if (REG_P (target
) && TREE_STATIC (exp
)
5894 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
5896 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5900 /* If the constructor has fewer fields than the structure or
5901 if we are initializing the structure to mostly zeros, clear
5902 the whole structure first. Don't do this if TARGET is a
5903 register whose mode size isn't equal to SIZE since
5904 clear_storage can't handle this case. */
5906 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
5907 != fields_length (type
))
5908 || mostly_zeros_p (exp
))
5910 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
5913 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5917 if (REG_P (target
) && !cleared
)
5918 emit_clobber (target
);
5920 /* Store each element of the constructor into the
5921 corresponding field of TARGET. */
5922 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
5924 enum machine_mode mode
;
5925 HOST_WIDE_INT bitsize
;
5926 HOST_WIDE_INT bitpos
= 0;
5928 rtx to_rtx
= target
;
5930 /* Just ignore missing fields. We cleared the whole
5931 structure, above, if any fields are missing. */
5935 if (cleared
&& initializer_zerop (value
))
5938 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
5939 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
5943 mode
= DECL_MODE (field
);
5944 if (DECL_BIT_FIELD (field
))
5947 offset
= DECL_FIELD_OFFSET (field
);
5948 if (tree_fits_shwi_p (offset
)
5949 && tree_fits_shwi_p (bit_position (field
)))
5951 bitpos
= int_bit_position (field
);
5955 bitpos
= tree_to_shwi (DECL_FIELD_BIT_OFFSET (field
));
5959 enum machine_mode address_mode
;
5963 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
5964 make_tree (TREE_TYPE (exp
),
5967 offset_rtx
= expand_normal (offset
);
5968 gcc_assert (MEM_P (to_rtx
));
5970 address_mode
= get_address_mode (to_rtx
);
5971 if (GET_MODE (offset_rtx
) != address_mode
)
5972 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
5974 to_rtx
= offset_address (to_rtx
, offset_rtx
,
5975 highest_pow2_factor (offset
));
5978 #ifdef WORD_REGISTER_OPERATIONS
5979 /* If this initializes a field that is smaller than a
5980 word, at the start of a word, try to widen it to a full
5981 word. This special case allows us to output C++ member
5982 function initializations in a form that the optimizers
5985 && bitsize
< BITS_PER_WORD
5986 && bitpos
% BITS_PER_WORD
== 0
5987 && GET_MODE_CLASS (mode
) == MODE_INT
5988 && TREE_CODE (value
) == INTEGER_CST
5990 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
5992 tree type
= TREE_TYPE (value
);
5994 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
5996 type
= lang_hooks
.types
.type_for_mode
5997 (word_mode
, TYPE_UNSIGNED (type
));
5998 value
= fold_convert (type
, value
);
6001 if (BYTES_BIG_ENDIAN
)
6003 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6004 build_int_cst (type
,
6005 BITS_PER_WORD
- bitsize
));
6006 bitsize
= BITS_PER_WORD
;
6011 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6012 && DECL_NONADDRESSABLE_P (field
))
6014 to_rtx
= copy_rtx (to_rtx
);
6015 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6018 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
6020 get_alias_set (TREE_TYPE (field
)));
6027 unsigned HOST_WIDE_INT i
;
6030 tree elttype
= TREE_TYPE (type
);
6032 HOST_WIDE_INT minelt
= 0;
6033 HOST_WIDE_INT maxelt
= 0;
6035 domain
= TYPE_DOMAIN (type
);
6036 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6037 && TYPE_MAX_VALUE (domain
)
6038 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6039 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6041 /* If we have constant bounds for the range of the type, get them. */
6044 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6045 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6048 /* If the constructor has fewer elements than the array, clear
6049 the whole array first. Similarly if this is static
6050 constructor of a non-BLKmode object. */
6053 else if (REG_P (target
) && TREE_STATIC (exp
))
6057 unsigned HOST_WIDE_INT idx
;
6059 HOST_WIDE_INT count
= 0, zero_count
= 0;
6060 need_to_clear
= ! const_bounds_p
;
6062 /* This loop is a more accurate version of the loop in
6063 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6064 is also needed to check for missing elements. */
6065 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6067 HOST_WIDE_INT this_node_count
;
6072 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6074 tree lo_index
= TREE_OPERAND (index
, 0);
6075 tree hi_index
= TREE_OPERAND (index
, 1);
6077 if (! tree_fits_uhwi_p (lo_index
)
6078 || ! tree_fits_uhwi_p (hi_index
))
6084 this_node_count
= (tree_to_uhwi (hi_index
)
6085 - tree_to_uhwi (lo_index
) + 1);
6088 this_node_count
= 1;
6090 count
+= this_node_count
;
6091 if (mostly_zeros_p (value
))
6092 zero_count
+= this_node_count
;
6095 /* Clear the entire array first if there are any missing
6096 elements, or if the incidence of zero elements is >=
6099 && (count
< maxelt
- minelt
+ 1
6100 || 4 * zero_count
>= 3 * count
))
6104 if (need_to_clear
&& size
> 0)
6107 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6109 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6113 if (!cleared
&& REG_P (target
))
6114 /* Inform later passes that the old value is dead. */
6115 emit_clobber (target
);
6117 /* Store each element of the constructor into the
6118 corresponding element of TARGET, determined by counting the
6120 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6122 enum machine_mode mode
;
6123 HOST_WIDE_INT bitsize
;
6124 HOST_WIDE_INT bitpos
;
6125 rtx xtarget
= target
;
6127 if (cleared
&& initializer_zerop (value
))
6130 mode
= TYPE_MODE (elttype
);
6131 if (mode
== BLKmode
)
6132 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6133 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6136 bitsize
= GET_MODE_BITSIZE (mode
);
6138 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6140 tree lo_index
= TREE_OPERAND (index
, 0);
6141 tree hi_index
= TREE_OPERAND (index
, 1);
6142 rtx index_r
, pos_rtx
;
6143 HOST_WIDE_INT lo
, hi
, count
;
6146 /* If the range is constant and "small", unroll the loop. */
6148 && tree_fits_shwi_p (lo_index
)
6149 && tree_fits_shwi_p (hi_index
)
6150 && (lo
= tree_to_shwi (lo_index
),
6151 hi
= tree_to_shwi (hi_index
),
6152 count
= hi
- lo
+ 1,
6155 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6156 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6159 lo
-= minelt
; hi
-= minelt
;
6160 for (; lo
<= hi
; lo
++)
6162 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6165 && !MEM_KEEP_ALIAS_SET_P (target
)
6166 && TREE_CODE (type
) == ARRAY_TYPE
6167 && TYPE_NONALIASED_COMPONENT (type
))
6169 target
= copy_rtx (target
);
6170 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6173 store_constructor_field
6174 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6175 get_alias_set (elttype
));
6180 rtx loop_start
= gen_label_rtx ();
6181 rtx loop_end
= gen_label_rtx ();
6184 expand_normal (hi_index
);
6186 index
= build_decl (EXPR_LOCATION (exp
),
6187 VAR_DECL
, NULL_TREE
, domain
);
6188 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6189 SET_DECL_RTL (index
, index_r
);
6190 store_expr (lo_index
, index_r
, 0, false);
6192 /* Build the head of the loop. */
6193 do_pending_stack_adjust ();
6194 emit_label (loop_start
);
6196 /* Assign value to element index. */
6198 fold_convert (ssizetype
,
6199 fold_build2 (MINUS_EXPR
,
6202 TYPE_MIN_VALUE (domain
)));
6205 size_binop (MULT_EXPR
, position
,
6206 fold_convert (ssizetype
,
6207 TYPE_SIZE_UNIT (elttype
)));
6209 pos_rtx
= expand_normal (position
);
6210 xtarget
= offset_address (target
, pos_rtx
,
6211 highest_pow2_factor (position
));
6212 xtarget
= adjust_address (xtarget
, mode
, 0);
6213 if (TREE_CODE (value
) == CONSTRUCTOR
)
6214 store_constructor (value
, xtarget
, cleared
,
6215 bitsize
/ BITS_PER_UNIT
);
6217 store_expr (value
, xtarget
, 0, false);
6219 /* Generate a conditional jump to exit the loop. */
6220 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6222 jumpif (exit_cond
, loop_end
, -1);
6224 /* Update the loop counter, and jump to the head of
6226 expand_assignment (index
,
6227 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6228 index
, integer_one_node
),
6231 emit_jump (loop_start
);
6233 /* Build the end of the loop. */
6234 emit_label (loop_end
);
6237 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6238 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6243 index
= ssize_int (1);
6246 index
= fold_convert (ssizetype
,
6247 fold_build2 (MINUS_EXPR
,
6250 TYPE_MIN_VALUE (domain
)));
6253 size_binop (MULT_EXPR
, index
,
6254 fold_convert (ssizetype
,
6255 TYPE_SIZE_UNIT (elttype
)));
6256 xtarget
= offset_address (target
,
6257 expand_normal (position
),
6258 highest_pow2_factor (position
));
6259 xtarget
= adjust_address (xtarget
, mode
, 0);
6260 store_expr (value
, xtarget
, 0, false);
6265 bitpos
= ((tree_to_shwi (index
) - minelt
)
6266 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6268 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6270 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6271 && TREE_CODE (type
) == ARRAY_TYPE
6272 && TYPE_NONALIASED_COMPONENT (type
))
6274 target
= copy_rtx (target
);
6275 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6277 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6278 cleared
, get_alias_set (elttype
));
6286 unsigned HOST_WIDE_INT idx
;
6287 constructor_elt
*ce
;
6290 int icode
= CODE_FOR_nothing
;
6291 tree elttype
= TREE_TYPE (type
);
6292 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6293 enum machine_mode eltmode
= TYPE_MODE (elttype
);
6294 HOST_WIDE_INT bitsize
;
6295 HOST_WIDE_INT bitpos
;
6296 rtvec vector
= NULL
;
6298 alias_set_type alias
;
6300 gcc_assert (eltmode
!= BLKmode
);
6302 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6303 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6305 enum machine_mode mode
= GET_MODE (target
);
6307 icode
= (int) optab_handler (vec_init_optab
, mode
);
6308 if (icode
!= CODE_FOR_nothing
)
6312 vector
= rtvec_alloc (n_elts
);
6313 for (i
= 0; i
< n_elts
; i
++)
6314 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6318 /* If the constructor has fewer elements than the vector,
6319 clear the whole array first. Similarly if this is static
6320 constructor of a non-BLKmode object. */
6323 else if (REG_P (target
) && TREE_STATIC (exp
))
6327 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6330 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6332 int n_elts_here
= tree_to_uhwi
6333 (int_const_binop (TRUNC_DIV_EXPR
,
6334 TYPE_SIZE (TREE_TYPE (value
)),
6335 TYPE_SIZE (elttype
)));
6337 count
+= n_elts_here
;
6338 if (mostly_zeros_p (value
))
6339 zero_count
+= n_elts_here
;
6342 /* Clear the entire vector first if there are any missing elements,
6343 or if the incidence of zero elements is >= 75%. */
6344 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6347 if (need_to_clear
&& size
> 0 && !vector
)
6350 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6352 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6356 /* Inform later passes that the old value is dead. */
6357 if (!cleared
&& !vector
&& REG_P (target
))
6358 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6361 alias
= MEM_ALIAS_SET (target
);
6363 alias
= get_alias_set (elttype
);
6365 /* Store each element of the constructor into the corresponding
6366 element of TARGET, determined by counting the elements. */
6367 for (idx
= 0, i
= 0;
6368 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6369 idx
++, i
+= bitsize
/ elt_size
)
6371 HOST_WIDE_INT eltpos
;
6372 tree value
= ce
->value
;
6374 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6375 if (cleared
&& initializer_zerop (value
))
6379 eltpos
= tree_to_uhwi (ce
->index
);
6385 /* Vector CONSTRUCTORs should only be built from smaller
6386 vectors in the case of BLKmode vectors. */
6387 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6388 RTVEC_ELT (vector
, eltpos
)
6389 = expand_normal (value
);
6393 enum machine_mode value_mode
=
6394 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6395 ? TYPE_MODE (TREE_TYPE (value
))
6397 bitpos
= eltpos
* elt_size
;
6398 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6399 value
, cleared
, alias
);
6404 emit_insn (GEN_FCN (icode
)
6406 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6415 /* Store the value of EXP (an expression tree)
6416 into a subfield of TARGET which has mode MODE and occupies
6417 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6418 If MODE is VOIDmode, it means that we are storing into a bit-field.
6420 BITREGION_START is bitpos of the first bitfield in this region.
6421 BITREGION_END is the bitpos of the ending bitfield in this region.
6422 These two fields are 0, if the C++ memory model does not apply,
6423 or we are not interested in keeping track of bitfield regions.
6425 Always return const0_rtx unless we have something particular to
6428 ALIAS_SET is the alias set for the destination. This value will
6429 (in general) be different from that for TARGET, since TARGET is a
6430 reference to the containing structure.
6432 If NONTEMPORAL is true, try generating a nontemporal store. */
6435 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6436 unsigned HOST_WIDE_INT bitregion_start
,
6437 unsigned HOST_WIDE_INT bitregion_end
,
6438 enum machine_mode mode
, tree exp
,
6439 alias_set_type alias_set
, bool nontemporal
)
6441 if (TREE_CODE (exp
) == ERROR_MARK
)
6444 /* If we have nothing to store, do nothing unless the expression has
6447 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6449 if (GET_CODE (target
) == CONCAT
)
6451 /* We're storing into a struct containing a single __complex. */
6453 gcc_assert (!bitpos
);
6454 return store_expr (exp
, target
, 0, nontemporal
);
6457 /* If the structure is in a register or if the component
6458 is a bit field, we cannot use addressing to access it.
6459 Use bit-field techniques or SUBREG to store in it. */
6461 if (mode
== VOIDmode
6462 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6463 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6464 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6466 || GET_CODE (target
) == SUBREG
6467 /* If the field isn't aligned enough to store as an ordinary memref,
6468 store it as a bit field. */
6470 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6471 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6472 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6473 || (bitpos
% BITS_PER_UNIT
!= 0)))
6474 || (bitsize
>= 0 && mode
!= BLKmode
6475 && GET_MODE_BITSIZE (mode
) > bitsize
)
6476 /* If the RHS and field are a constant size and the size of the
6477 RHS isn't the same size as the bitfield, we must use bitfield
6480 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6481 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6482 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6483 decl we must use bitfield operations. */
6485 && TREE_CODE (exp
) == MEM_REF
6486 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6487 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6488 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6489 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6494 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6495 implies a mask operation. If the precision is the same size as
6496 the field we're storing into, that mask is redundant. This is
6497 particularly common with bit field assignments generated by the
6499 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6502 tree type
= TREE_TYPE (exp
);
6503 if (INTEGRAL_TYPE_P (type
)
6504 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6505 && bitsize
== TYPE_PRECISION (type
))
6507 tree op
= gimple_assign_rhs1 (nop_def
);
6508 type
= TREE_TYPE (op
);
6509 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6514 temp
= expand_normal (exp
);
6516 /* If BITSIZE is narrower than the size of the type of EXP
6517 we will be narrowing TEMP. Normally, what's wanted are the
6518 low-order bits. However, if EXP's type is a record and this is
6519 big-endian machine, we want the upper BITSIZE bits. */
6520 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6521 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6522 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6523 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6524 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6527 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6528 if (mode
!= VOIDmode
&& mode
!= BLKmode
6529 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6530 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6532 /* If the modes of TEMP and TARGET are both BLKmode, both
6533 must be in memory and BITPOS must be aligned on a byte
6534 boundary. If so, we simply do a block copy. Likewise
6535 for a BLKmode-like TARGET. */
6536 if (GET_MODE (temp
) == BLKmode
6537 && (GET_MODE (target
) == BLKmode
6539 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6540 && (bitpos
% BITS_PER_UNIT
) == 0
6541 && (bitsize
% BITS_PER_UNIT
) == 0)))
6543 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6544 && (bitpos
% BITS_PER_UNIT
) == 0);
6546 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6547 emit_block_move (target
, temp
,
6548 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6555 /* Handle calls that return values in multiple non-contiguous locations.
6556 The Irix 6 ABI has examples of this. */
6557 if (GET_CODE (temp
) == PARALLEL
)
6559 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6561 if (mode
== BLKmode
)
6562 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6563 temp_target
= gen_reg_rtx (mode
);
6564 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6567 else if (mode
== BLKmode
)
6569 /* Handle calls that return BLKmode values in registers. */
6570 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6572 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6573 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6578 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6580 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6581 temp_target
= gen_reg_rtx (mode
);
6583 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6584 temp_target
, mode
, mode
);
6589 /* Store the value in the bitfield. */
6590 store_bit_field (target
, bitsize
, bitpos
,
6591 bitregion_start
, bitregion_end
,
6598 /* Now build a reference to just the desired component. */
6599 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6601 if (to_rtx
== target
)
6602 to_rtx
= copy_rtx (to_rtx
);
6604 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6605 set_mem_alias_set (to_rtx
, alias_set
);
6607 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6611 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6612 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6613 codes and find the ultimate containing object, which we return.
6615 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6616 bit position, and *PUNSIGNEDP to the signedness of the field.
6617 If the position of the field is variable, we store a tree
6618 giving the variable offset (in units) in *POFFSET.
6619 This offset is in addition to the bit position.
6620 If the position is not variable, we store 0 in *POFFSET.
6622 If any of the extraction expressions is volatile,
6623 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6625 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6626 Otherwise, it is a mode that can be used to access the field.
6628 If the field describes a variable-sized object, *PMODE is set to
6629 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6630 this case, but the address of the object can be found.
6632 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6633 look through nodes that serve as markers of a greater alignment than
6634 the one that can be deduced from the expression. These nodes make it
6635 possible for front-ends to prevent temporaries from being created by
6636 the middle-end on alignment considerations. For that purpose, the
6637 normal operating mode at high-level is to always pass FALSE so that
6638 the ultimate containing object is really returned; moreover, the
6639 associated predicate handled_component_p will always return TRUE
6640 on these nodes, thus indicating that they are essentially handled
6641 by get_inner_reference. TRUE should only be passed when the caller
6642 is scanning the expression in order to build another representation
6643 and specifically knows how to handle these nodes; as such, this is
6644 the normal operating mode in the RTL expanders. */
6647 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6648 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6649 enum machine_mode
*pmode
, int *punsignedp
,
6650 int *pvolatilep
, bool keep_aligning
)
6653 enum machine_mode mode
= VOIDmode
;
6654 bool blkmode_bitfield
= false;
6655 tree offset
= size_zero_node
;
6656 double_int bit_offset
= double_int_zero
;
6658 /* First get the mode, signedness, and size. We do this from just the
6659 outermost expression. */
6661 if (TREE_CODE (exp
) == COMPONENT_REF
)
6663 tree field
= TREE_OPERAND (exp
, 1);
6664 size_tree
= DECL_SIZE (field
);
6665 if (flag_strict_volatile_bitfields
> 0
6666 && TREE_THIS_VOLATILE (exp
)
6667 && DECL_BIT_FIELD_TYPE (field
)
6668 && DECL_MODE (field
) != BLKmode
)
6669 /* Volatile bitfields should be accessed in the mode of the
6670 field's type, not the mode computed based on the bit
6672 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6673 else if (!DECL_BIT_FIELD (field
))
6674 mode
= DECL_MODE (field
);
6675 else if (DECL_MODE (field
) == BLKmode
)
6676 blkmode_bitfield
= true;
6678 *punsignedp
= DECL_UNSIGNED (field
);
6680 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6682 size_tree
= TREE_OPERAND (exp
, 1);
6683 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6684 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6686 /* For vector types, with the correct size of access, use the mode of
6688 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6689 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6690 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6691 mode
= TYPE_MODE (TREE_TYPE (exp
));
6695 mode
= TYPE_MODE (TREE_TYPE (exp
));
6696 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6698 if (mode
== BLKmode
)
6699 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6701 *pbitsize
= GET_MODE_BITSIZE (mode
);
6706 if (! tree_fits_uhwi_p (size_tree
))
6707 mode
= BLKmode
, *pbitsize
= -1;
6709 *pbitsize
= tree_to_uhwi (size_tree
);
6712 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6713 and find the ultimate containing object. */
6716 switch (TREE_CODE (exp
))
6719 bit_offset
+= tree_to_double_int (TREE_OPERAND (exp
, 2));
6724 tree field
= TREE_OPERAND (exp
, 1);
6725 tree this_offset
= component_ref_field_offset (exp
);
6727 /* If this field hasn't been filled in yet, don't go past it.
6728 This should only happen when folding expressions made during
6729 type construction. */
6730 if (this_offset
== 0)
6733 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6734 bit_offset
+= tree_to_double_int (DECL_FIELD_BIT_OFFSET (field
));
6736 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6741 case ARRAY_RANGE_REF
:
6743 tree index
= TREE_OPERAND (exp
, 1);
6744 tree low_bound
= array_ref_low_bound (exp
);
6745 tree unit_size
= array_ref_element_size (exp
);
6747 /* We assume all arrays have sizes that are a multiple of a byte.
6748 First subtract the lower bound, if any, in the type of the
6749 index, then convert to sizetype and multiply by the size of
6750 the array element. */
6751 if (! integer_zerop (low_bound
))
6752 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6755 offset
= size_binop (PLUS_EXPR
, offset
,
6756 size_binop (MULT_EXPR
,
6757 fold_convert (sizetype
, index
),
6766 bit_offset
+= double_int::from_uhwi (*pbitsize
);
6769 case VIEW_CONVERT_EXPR
:
6770 if (keep_aligning
&& STRICT_ALIGNMENT
6771 && (TYPE_ALIGN (TREE_TYPE (exp
))
6772 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6773 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6774 < BIGGEST_ALIGNMENT
)
6775 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6776 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6781 /* Hand back the decl for MEM[&decl, off]. */
6782 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6784 tree off
= TREE_OPERAND (exp
, 1);
6785 if (!integer_zerop (off
))
6787 double_int boff
, coff
= mem_ref_offset (exp
);
6788 boff
= coff
.lshift (BITS_PER_UNIT
== 8
6789 ? 3 : exact_log2 (BITS_PER_UNIT
));
6792 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6800 /* If any reference in the chain is volatile, the effect is volatile. */
6801 if (TREE_THIS_VOLATILE (exp
))
6804 exp
= TREE_OPERAND (exp
, 0);
6808 /* If OFFSET is constant, see if we can return the whole thing as a
6809 constant bit position. Make sure to handle overflow during
6811 if (TREE_CODE (offset
) == INTEGER_CST
)
6813 double_int tem
= tree_to_double_int (offset
);
6814 tem
= tem
.sext (TYPE_PRECISION (sizetype
));
6815 tem
= tem
.lshift (BITS_PER_UNIT
== 8 ? 3 : exact_log2 (BITS_PER_UNIT
));
6817 if (tem
.fits_shwi ())
6819 *pbitpos
= tem
.to_shwi ();
6820 *poffset
= offset
= NULL_TREE
;
6824 /* Otherwise, split it up. */
6827 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6828 if (bit_offset
.is_negative ())
6831 = double_int::mask (BITS_PER_UNIT
== 8
6832 ? 3 : exact_log2 (BITS_PER_UNIT
));
6833 double_int tem
= bit_offset
.and_not (mask
);
6834 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6835 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6837 tem
= tem
.arshift (BITS_PER_UNIT
== 8
6838 ? 3 : exact_log2 (BITS_PER_UNIT
),
6839 HOST_BITS_PER_DOUBLE_INT
);
6840 offset
= size_binop (PLUS_EXPR
, offset
,
6841 double_int_to_tree (sizetype
, tem
));
6844 *pbitpos
= bit_offset
.to_shwi ();
6848 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6849 if (mode
== VOIDmode
6851 && (*pbitpos
% BITS_PER_UNIT
) == 0
6852 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6860 /* Return a tree of sizetype representing the size, in bytes, of the element
6861 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6864 array_ref_element_size (tree exp
)
6866 tree aligned_size
= TREE_OPERAND (exp
, 3);
6867 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6868 location_t loc
= EXPR_LOCATION (exp
);
6870 /* If a size was specified in the ARRAY_REF, it's the size measured
6871 in alignment units of the element type. So multiply by that value. */
6874 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6875 sizetype from another type of the same width and signedness. */
6876 if (TREE_TYPE (aligned_size
) != sizetype
)
6877 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
6878 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
6879 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
6882 /* Otherwise, take the size from that of the element type. Substitute
6883 any PLACEHOLDER_EXPR that we have. */
6885 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
6888 /* Return a tree representing the lower bound of the array mentioned in
6889 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6892 array_ref_low_bound (tree exp
)
6894 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6896 /* If a lower bound is specified in EXP, use it. */
6897 if (TREE_OPERAND (exp
, 2))
6898 return TREE_OPERAND (exp
, 2);
6900 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6901 substituting for a PLACEHOLDER_EXPR as needed. */
6902 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
6903 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
6905 /* Otherwise, return a zero of the appropriate type. */
6906 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
6909 /* Returns true if REF is an array reference to an array at the end of
6910 a structure. If this is the case, the array may be allocated larger
6911 than its upper bound implies. */
6914 array_at_struct_end_p (tree ref
)
6916 if (TREE_CODE (ref
) != ARRAY_REF
6917 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
6920 while (handled_component_p (ref
))
6922 /* If the reference chain contains a component reference to a
6923 non-union type and there follows another field the reference
6924 is not at the end of a structure. */
6925 if (TREE_CODE (ref
) == COMPONENT_REF
6926 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
6928 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
6929 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
6930 nextf
= DECL_CHAIN (nextf
);
6935 ref
= TREE_OPERAND (ref
, 0);
6938 /* If the reference is based on a declared entity, the size of the array
6939 is constrained by its given domain. */
6946 /* Return a tree representing the upper bound of the array mentioned in
6947 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6950 array_ref_up_bound (tree exp
)
6952 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6954 /* If there is a domain type and it has an upper bound, use it, substituting
6955 for a PLACEHOLDER_EXPR as needed. */
6956 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
6957 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
6959 /* Otherwise fail. */
6963 /* Return a tree representing the offset, in bytes, of the field referenced
6964 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6967 component_ref_field_offset (tree exp
)
6969 tree aligned_offset
= TREE_OPERAND (exp
, 2);
6970 tree field
= TREE_OPERAND (exp
, 1);
6971 location_t loc
= EXPR_LOCATION (exp
);
6973 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6974 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6978 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6979 sizetype from another type of the same width and signedness. */
6980 if (TREE_TYPE (aligned_offset
) != sizetype
)
6981 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
6982 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
6983 size_int (DECL_OFFSET_ALIGN (field
)
6987 /* Otherwise, take the offset from that of the field. Substitute
6988 any PLACEHOLDER_EXPR that we have. */
6990 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
6993 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6995 static unsigned HOST_WIDE_INT
6996 target_align (const_tree target
)
6998 /* We might have a chain of nested references with intermediate misaligning
6999 bitfields components, so need to recurse to find out. */
7001 unsigned HOST_WIDE_INT this_align
, outer_align
;
7003 switch (TREE_CODE (target
))
7009 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7010 outer_align
= target_align (TREE_OPERAND (target
, 0));
7011 return MIN (this_align
, outer_align
);
7014 case ARRAY_RANGE_REF
:
7015 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7016 outer_align
= target_align (TREE_OPERAND (target
, 0));
7017 return MIN (this_align
, outer_align
);
7020 case NON_LVALUE_EXPR
:
7021 case VIEW_CONVERT_EXPR
:
7022 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7023 outer_align
= target_align (TREE_OPERAND (target
, 0));
7024 return MAX (this_align
, outer_align
);
7027 return TYPE_ALIGN (TREE_TYPE (target
));
7032 /* Given an rtx VALUE that may contain additions and multiplications, return
7033 an equivalent value that just refers to a register, memory, or constant.
7034 This is done by generating instructions to perform the arithmetic and
7035 returning a pseudo-register containing the value.
7037 The returned value may be a REG, SUBREG, MEM or constant. */
7040 force_operand (rtx value
, rtx target
)
7043 /* Use subtarget as the target for operand 0 of a binary operation. */
7044 rtx subtarget
= get_subtarget (target
);
7045 enum rtx_code code
= GET_CODE (value
);
7047 /* Check for subreg applied to an expression produced by loop optimizer. */
7049 && !REG_P (SUBREG_REG (value
))
7050 && !MEM_P (SUBREG_REG (value
)))
7053 = simplify_gen_subreg (GET_MODE (value
),
7054 force_reg (GET_MODE (SUBREG_REG (value
)),
7055 force_operand (SUBREG_REG (value
),
7057 GET_MODE (SUBREG_REG (value
)),
7058 SUBREG_BYTE (value
));
7059 code
= GET_CODE (value
);
7062 /* Check for a PIC address load. */
7063 if ((code
== PLUS
|| code
== MINUS
)
7064 && XEXP (value
, 0) == pic_offset_table_rtx
7065 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7066 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7067 || GET_CODE (XEXP (value
, 1)) == CONST
))
7070 subtarget
= gen_reg_rtx (GET_MODE (value
));
7071 emit_move_insn (subtarget
, value
);
7075 if (ARITHMETIC_P (value
))
7077 op2
= XEXP (value
, 1);
7078 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7080 if (code
== MINUS
&& CONST_INT_P (op2
))
7083 op2
= negate_rtx (GET_MODE (value
), op2
);
7086 /* Check for an addition with OP2 a constant integer and our first
7087 operand a PLUS of a virtual register and something else. In that
7088 case, we want to emit the sum of the virtual register and the
7089 constant first and then add the other value. This allows virtual
7090 register instantiation to simply modify the constant rather than
7091 creating another one around this addition. */
7092 if (code
== PLUS
&& CONST_INT_P (op2
)
7093 && GET_CODE (XEXP (value
, 0)) == PLUS
7094 && REG_P (XEXP (XEXP (value
, 0), 0))
7095 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7096 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7098 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7099 XEXP (XEXP (value
, 0), 0), op2
,
7100 subtarget
, 0, OPTAB_LIB_WIDEN
);
7101 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7102 force_operand (XEXP (XEXP (value
,
7104 target
, 0, OPTAB_LIB_WIDEN
);
7107 op1
= force_operand (XEXP (value
, 0), subtarget
);
7108 op2
= force_operand (op2
, NULL_RTX
);
7112 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7114 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7115 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7116 target
, 1, OPTAB_LIB_WIDEN
);
7118 return expand_divmod (0,
7119 FLOAT_MODE_P (GET_MODE (value
))
7120 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7121 GET_MODE (value
), op1
, op2
, target
, 0);
7123 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7126 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7129 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7132 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7133 target
, 0, OPTAB_LIB_WIDEN
);
7135 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7136 target
, 1, OPTAB_LIB_WIDEN
);
7139 if (UNARY_P (value
))
7142 target
= gen_reg_rtx (GET_MODE (value
));
7143 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7150 case FLOAT_TRUNCATE
:
7151 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7156 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7160 case UNSIGNED_FLOAT
:
7161 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7165 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7169 #ifdef INSN_SCHEDULING
7170 /* On machines that have insn scheduling, we want all memory reference to be
7171 explicit, so we need to deal with such paradoxical SUBREGs. */
7172 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7174 = simplify_gen_subreg (GET_MODE (value
),
7175 force_reg (GET_MODE (SUBREG_REG (value
)),
7176 force_operand (SUBREG_REG (value
),
7178 GET_MODE (SUBREG_REG (value
)),
7179 SUBREG_BYTE (value
));
7185 /* Subroutine of expand_expr: return nonzero iff there is no way that
7186 EXP can reference X, which is being modified. TOP_P is nonzero if this
7187 call is going to be used to determine whether we need a temporary
7188 for EXP, as opposed to a recursive call to this function.
7190 It is always safe for this routine to return zero since it merely
7191 searches for optimization opportunities. */
7194 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7200 /* If EXP has varying size, we MUST use a target since we currently
7201 have no way of allocating temporaries of variable size
7202 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7203 So we assume here that something at a higher level has prevented a
7204 clash. This is somewhat bogus, but the best we can do. Only
7205 do this when X is BLKmode and when we are at the top level. */
7206 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7207 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7208 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7209 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7210 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7212 && GET_MODE (x
) == BLKmode
)
7213 /* If X is in the outgoing argument area, it is always safe. */
7215 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7216 || (GET_CODE (XEXP (x
, 0)) == PLUS
7217 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7220 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7221 find the underlying pseudo. */
7222 if (GET_CODE (x
) == SUBREG
)
7225 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7229 /* Now look at our tree code and possibly recurse. */
7230 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7232 case tcc_declaration
:
7233 exp_rtl
= DECL_RTL_IF_SET (exp
);
7239 case tcc_exceptional
:
7240 if (TREE_CODE (exp
) == TREE_LIST
)
7244 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7246 exp
= TREE_CHAIN (exp
);
7249 if (TREE_CODE (exp
) != TREE_LIST
)
7250 return safe_from_p (x
, exp
, 0);
7253 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7255 constructor_elt
*ce
;
7256 unsigned HOST_WIDE_INT idx
;
7258 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7259 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7260 || !safe_from_p (x
, ce
->value
, 0))
7264 else if (TREE_CODE (exp
) == ERROR_MARK
)
7265 return 1; /* An already-visited SAVE_EXPR? */
7270 /* The only case we look at here is the DECL_INITIAL inside a
7272 return (TREE_CODE (exp
) != DECL_EXPR
7273 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7274 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7275 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7278 case tcc_comparison
:
7279 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7284 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7286 case tcc_expression
:
7289 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7290 the expression. If it is set, we conflict iff we are that rtx or
7291 both are in memory. Otherwise, we check all operands of the
7292 expression recursively. */
7294 switch (TREE_CODE (exp
))
7297 /* If the operand is static or we are static, we can't conflict.
7298 Likewise if we don't conflict with the operand at all. */
7299 if (staticp (TREE_OPERAND (exp
, 0))
7300 || TREE_STATIC (exp
)
7301 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7304 /* Otherwise, the only way this can conflict is if we are taking
7305 the address of a DECL a that address if part of X, which is
7307 exp
= TREE_OPERAND (exp
, 0);
7310 if (!DECL_RTL_SET_P (exp
)
7311 || !MEM_P (DECL_RTL (exp
)))
7314 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7320 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7321 get_alias_set (exp
)))
7326 /* Assume that the call will clobber all hard registers and
7328 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7333 case WITH_CLEANUP_EXPR
:
7334 case CLEANUP_POINT_EXPR
:
7335 /* Lowered by gimplify.c. */
7339 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7345 /* If we have an rtx, we do not need to scan our operands. */
7349 nops
= TREE_OPERAND_LENGTH (exp
);
7350 for (i
= 0; i
< nops
; i
++)
7351 if (TREE_OPERAND (exp
, i
) != 0
7352 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7358 /* Should never get a type here. */
7362 /* If we have an rtl, find any enclosed object. Then see if we conflict
7366 if (GET_CODE (exp_rtl
) == SUBREG
)
7368 exp_rtl
= SUBREG_REG (exp_rtl
);
7370 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7374 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7375 are memory and they conflict. */
7376 return ! (rtx_equal_p (x
, exp_rtl
)
7377 || (MEM_P (x
) && MEM_P (exp_rtl
)
7378 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7381 /* If we reach here, it is safe. */
7386 /* Return the highest power of two that EXP is known to be a multiple of.
7387 This is used in updating alignment of MEMs in array references. */
7389 unsigned HOST_WIDE_INT
7390 highest_pow2_factor (const_tree exp
)
7392 unsigned HOST_WIDE_INT ret
;
7393 int trailing_zeros
= tree_ctz (exp
);
7394 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7395 return BIGGEST_ALIGNMENT
;
7396 ret
= (unsigned HOST_WIDE_INT
) 1 << trailing_zeros
;
7397 if (ret
> BIGGEST_ALIGNMENT
)
7398 return BIGGEST_ALIGNMENT
;
7402 /* Similar, except that the alignment requirements of TARGET are
7403 taken into account. Assume it is at least as aligned as its
7404 type, unless it is a COMPONENT_REF in which case the layout of
7405 the structure gives the alignment. */
7407 static unsigned HOST_WIDE_INT
7408 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7410 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7411 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7413 return MAX (factor
, talign
);
7416 #ifdef HAVE_conditional_move
7417 /* Convert the tree comparison code TCODE to the rtl one where the
7418 signedness is UNSIGNEDP. */
7420 static enum rtx_code
7421 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7433 code
= unsignedp
? LTU
: LT
;
7436 code
= unsignedp
? LEU
: LE
;
7439 code
= unsignedp
? GTU
: GT
;
7442 code
= unsignedp
? GEU
: GE
;
7444 case UNORDERED_EXPR
:
7476 /* Subroutine of expand_expr. Expand the two operands of a binary
7477 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7478 The value may be stored in TARGET if TARGET is nonzero. The
7479 MODIFIER argument is as documented by expand_expr. */
7482 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7483 enum expand_modifier modifier
)
7485 if (! safe_from_p (target
, exp1
, 1))
7487 if (operand_equal_p (exp0
, exp1
, 0))
7489 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7490 *op1
= copy_rtx (*op0
);
7494 /* If we need to preserve evaluation order, copy exp0 into its own
7495 temporary variable so that it can't be clobbered by exp1. */
7496 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7497 exp0
= save_expr (exp0
);
7498 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7499 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7504 /* Return a MEM that contains constant EXP. DEFER is as for
7505 output_constant_def and MODIFIER is as for expand_expr. */
7508 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7512 mem
= output_constant_def (exp
, defer
);
7513 if (modifier
!= EXPAND_INITIALIZER
)
7514 mem
= use_anchored_address (mem
);
7518 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7519 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7522 expand_expr_addr_expr_1 (tree exp
, rtx target
, enum machine_mode tmode
,
7523 enum expand_modifier modifier
, addr_space_t as
)
7525 rtx result
, subtarget
;
7527 HOST_WIDE_INT bitsize
, bitpos
;
7528 int volatilep
, unsignedp
;
7529 enum machine_mode mode1
;
7531 /* If we are taking the address of a constant and are at the top level,
7532 we have to use output_constant_def since we can't call force_const_mem
7534 /* ??? This should be considered a front-end bug. We should not be
7535 generating ADDR_EXPR of something that isn't an LVALUE. The only
7536 exception here is STRING_CST. */
7537 if (CONSTANT_CLASS_P (exp
))
7539 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7540 if (modifier
< EXPAND_SUM
)
7541 result
= force_operand (result
, target
);
7545 /* Everything must be something allowed by is_gimple_addressable. */
7546 switch (TREE_CODE (exp
))
7549 /* This case will happen via recursion for &a->b. */
7550 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7554 tree tem
= TREE_OPERAND (exp
, 0);
7555 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7556 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7557 return expand_expr (tem
, target
, tmode
, modifier
);
7561 /* Expand the initializer like constants above. */
7562 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7564 if (modifier
< EXPAND_SUM
)
7565 result
= force_operand (result
, target
);
7569 /* The real part of the complex number is always first, therefore
7570 the address is the same as the address of the parent object. */
7573 inner
= TREE_OPERAND (exp
, 0);
7577 /* The imaginary part of the complex number is always second.
7578 The expression is therefore always offset by the size of the
7581 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7582 inner
= TREE_OPERAND (exp
, 0);
7585 case COMPOUND_LITERAL_EXPR
:
7586 /* Allow COMPOUND_LITERAL_EXPR in initializers, if e.g.
7587 rtl_for_decl_init is called on DECL_INITIAL with
7588 COMPOUNT_LITERAL_EXPRs in it, they aren't gimplified. */
7589 if (modifier
== EXPAND_INITIALIZER
7590 && COMPOUND_LITERAL_EXPR_DECL (exp
))
7591 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7592 target
, tmode
, modifier
, as
);
7595 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7596 expand_expr, as that can have various side effects; LABEL_DECLs for
7597 example, may not have their DECL_RTL set yet. Expand the rtl of
7598 CONSTRUCTORs too, which should yield a memory reference for the
7599 constructor's contents. Assume language specific tree nodes can
7600 be expanded in some interesting way. */
7601 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7603 || TREE_CODE (exp
) == CONSTRUCTOR
7604 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7606 result
= expand_expr (exp
, target
, tmode
,
7607 modifier
== EXPAND_INITIALIZER
7608 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7610 /* If the DECL isn't in memory, then the DECL wasn't properly
7611 marked TREE_ADDRESSABLE, which will be either a front-end
7612 or a tree optimizer bug. */
7614 if (TREE_ADDRESSABLE (exp
)
7616 && ! targetm
.calls
.allocate_stack_slots_for_args ())
7618 error ("local frame unavailable (naked function?)");
7622 gcc_assert (MEM_P (result
));
7623 result
= XEXP (result
, 0);
7625 /* ??? Is this needed anymore? */
7627 TREE_USED (exp
) = 1;
7629 if (modifier
!= EXPAND_INITIALIZER
7630 && modifier
!= EXPAND_CONST_ADDRESS
7631 && modifier
!= EXPAND_SUM
)
7632 result
= force_operand (result
, target
);
7636 /* Pass FALSE as the last argument to get_inner_reference although
7637 we are expanding to RTL. The rationale is that we know how to
7638 handle "aligning nodes" here: we can just bypass them because
7639 they won't change the final object whose address will be returned
7640 (they actually exist only for that purpose). */
7641 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7642 &mode1
, &unsignedp
, &volatilep
, false);
7646 /* We must have made progress. */
7647 gcc_assert (inner
!= exp
);
7649 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7650 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7651 inner alignment, force the inner to be sufficiently aligned. */
7652 if (CONSTANT_CLASS_P (inner
)
7653 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7655 inner
= copy_node (inner
);
7656 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7657 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7658 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7660 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7666 if (modifier
!= EXPAND_NORMAL
)
7667 result
= force_operand (result
, NULL
);
7668 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7669 modifier
== EXPAND_INITIALIZER
7670 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7672 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7673 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7675 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7676 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7679 subtarget
= bitpos
? NULL_RTX
: target
;
7680 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7681 1, OPTAB_LIB_WIDEN
);
7687 /* Someone beforehand should have rejected taking the address
7688 of such an object. */
7689 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7691 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7692 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7693 if (modifier
< EXPAND_SUM
)
7694 result
= force_operand (result
, target
);
7700 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7701 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7704 expand_expr_addr_expr (tree exp
, rtx target
, enum machine_mode tmode
,
7705 enum expand_modifier modifier
)
7707 addr_space_t as
= ADDR_SPACE_GENERIC
;
7708 enum machine_mode address_mode
= Pmode
;
7709 enum machine_mode pointer_mode
= ptr_mode
;
7710 enum machine_mode rmode
;
7713 /* Target mode of VOIDmode says "whatever's natural". */
7714 if (tmode
== VOIDmode
)
7715 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7717 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7719 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7720 address_mode
= targetm
.addr_space
.address_mode (as
);
7721 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7724 /* We can get called with some Weird Things if the user does silliness
7725 like "(short) &a". In that case, convert_memory_address won't do
7726 the right thing, so ignore the given target mode. */
7727 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7728 tmode
= address_mode
;
7730 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7731 tmode
, modifier
, as
);
7733 /* Despite expand_expr claims concerning ignoring TMODE when not
7734 strictly convenient, stuff breaks if we don't honor it. Note
7735 that combined with the above, we only do this for pointer modes. */
7736 rmode
= GET_MODE (result
);
7737 if (rmode
== VOIDmode
)
7740 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7745 /* Generate code for computing CONSTRUCTOR EXP.
7746 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7747 is TRUE, instead of creating a temporary variable in memory
7748 NULL is returned and the caller needs to handle it differently. */
7751 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7752 bool avoid_temp_mem
)
7754 tree type
= TREE_TYPE (exp
);
7755 enum machine_mode mode
= TYPE_MODE (type
);
7757 /* Try to avoid creating a temporary at all. This is possible
7758 if all of the initializer is zero.
7759 FIXME: try to handle all [0..255] initializers we can handle
7761 if (TREE_STATIC (exp
)
7762 && !TREE_ADDRESSABLE (exp
)
7763 && target
!= 0 && mode
== BLKmode
7764 && all_zeros_p (exp
))
7766 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7770 /* All elts simple constants => refer to a constant in memory. But
7771 if this is a non-BLKmode mode, let it store a field at a time
7772 since that should make a CONST_INT or CONST_DOUBLE when we
7773 fold. Likewise, if we have a target we can use, it is best to
7774 store directly into the target unless the type is large enough
7775 that memcpy will be used. If we are making an initializer and
7776 all operands are constant, put it in memory as well.
7778 FIXME: Avoid trying to fill vector constructors piece-meal.
7779 Output them with output_constant_def below unless we're sure
7780 they're zeros. This should go away when vector initializers
7781 are treated like VECTOR_CST instead of arrays. */
7782 if ((TREE_STATIC (exp
)
7783 && ((mode
== BLKmode
7784 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7785 || TREE_ADDRESSABLE (exp
)
7786 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7787 && (! MOVE_BY_PIECES_P
7788 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7790 && ! mostly_zeros_p (exp
))))
7791 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7792 && TREE_CONSTANT (exp
)))
7799 constructor
= expand_expr_constant (exp
, 1, modifier
);
7801 if (modifier
!= EXPAND_CONST_ADDRESS
7802 && modifier
!= EXPAND_INITIALIZER
7803 && modifier
!= EXPAND_SUM
)
7804 constructor
= validize_mem (constructor
);
7809 /* Handle calls that pass values in multiple non-contiguous
7810 locations. The Irix 6 ABI has examples of this. */
7811 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7812 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7818 = assign_temp (build_qualified_type (type
, (TYPE_QUALS (type
)
7819 | (TREE_READONLY (exp
)
7820 * TYPE_QUAL_CONST
))),
7821 TREE_ADDRESSABLE (exp
), 1);
7824 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7829 /* expand_expr: generate code for computing expression EXP.
7830 An rtx for the computed value is returned. The value is never null.
7831 In the case of a void EXP, const0_rtx is returned.
7833 The value may be stored in TARGET if TARGET is nonzero.
7834 TARGET is just a suggestion; callers must assume that
7835 the rtx returned may not be the same as TARGET.
7837 If TARGET is CONST0_RTX, it means that the value will be ignored.
7839 If TMODE is not VOIDmode, it suggests generating the
7840 result in mode TMODE. But this is done only when convenient.
7841 Otherwise, TMODE is ignored and the value generated in its natural mode.
7842 TMODE is just a suggestion; callers must assume that
7843 the rtx returned may not have mode TMODE.
7845 Note that TARGET may have neither TMODE nor MODE. In that case, it
7846 probably will not be used.
7848 If MODIFIER is EXPAND_SUM then when EXP is an addition
7849 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7850 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7851 products as above, or REG or MEM, or constant.
7852 Ordinarily in such cases we would output mul or add instructions
7853 and then return a pseudo reg containing the sum.
7855 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7856 it also marks a label as absolutely required (it can't be dead).
7857 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7858 This is used for outputting expressions used in initializers.
7860 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7861 with a constant address even if that address is not normally legitimate.
7862 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7864 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7865 a call parameter. Such targets require special care as we haven't yet
7866 marked TARGET so that it's safe from being trashed by libcalls. We
7867 don't want to use TARGET for anything but the final result;
7868 Intermediate values must go elsewhere. Additionally, calls to
7869 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7871 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7872 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7873 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7874 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7878 expand_expr_real (tree exp
, rtx target
, enum machine_mode tmode
,
7879 enum expand_modifier modifier
, rtx
*alt_rtl
)
7883 /* Handle ERROR_MARK before anybody tries to access its type. */
7884 if (TREE_CODE (exp
) == ERROR_MARK
7885 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7887 ret
= CONST0_RTX (tmode
);
7888 return ret
? ret
: const0_rtx
;
7891 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
7895 /* Try to expand the conditional expression which is represented by
7896 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7897 return the rtl reg which repsents the result. Otherwise return
7901 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7902 tree treeop1 ATTRIBUTE_UNUSED
,
7903 tree treeop2 ATTRIBUTE_UNUSED
)
7905 #ifdef HAVE_conditional_move
7907 rtx op00
, op01
, op1
, op2
;
7908 enum rtx_code comparison_code
;
7909 enum machine_mode comparison_mode
;
7912 tree type
= TREE_TYPE (treeop1
);
7913 int unsignedp
= TYPE_UNSIGNED (type
);
7914 enum machine_mode mode
= TYPE_MODE (type
);
7915 enum machine_mode orig_mode
= mode
;
7917 /* If we cannot do a conditional move on the mode, try doing it
7918 with the promoted mode. */
7919 if (!can_conditionally_move_p (mode
))
7921 mode
= promote_mode (type
, mode
, &unsignedp
);
7922 if (!can_conditionally_move_p (mode
))
7924 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7927 temp
= assign_temp (type
, 0, 1);
7930 expand_operands (treeop1
, treeop2
,
7931 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7933 if (TREE_CODE (treeop0
) == SSA_NAME
7934 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7936 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7937 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7938 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7939 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7940 comparison_mode
= TYPE_MODE (type
);
7941 unsignedp
= TYPE_UNSIGNED (type
);
7942 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7944 else if (TREE_CODE_CLASS (TREE_CODE (treeop0
)) == tcc_comparison
)
7946 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7947 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7948 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7949 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7950 unsignedp
= TYPE_UNSIGNED (type
);
7951 comparison_mode
= TYPE_MODE (type
);
7952 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7956 op00
= expand_normal (treeop0
);
7958 comparison_code
= NE
;
7959 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7962 if (GET_MODE (op1
) != mode
)
7963 op1
= gen_lowpart (mode
, op1
);
7965 if (GET_MODE (op2
) != mode
)
7966 op2
= gen_lowpart (mode
, op2
);
7968 /* Try to emit the conditional move. */
7969 insn
= emit_conditional_move (temp
, comparison_code
,
7970 op00
, op01
, comparison_mode
,
7974 /* If we could do the conditional move, emit the sequence,
7978 rtx seq
= get_insns ();
7981 return convert_modes (orig_mode
, mode
, temp
, 0);
7984 /* Otherwise discard the sequence and fall back to code with
7992 expand_expr_real_2 (sepops ops
, rtx target
, enum machine_mode tmode
,
7993 enum expand_modifier modifier
)
7995 rtx op0
, op1
, op2
, temp
;
7998 enum machine_mode mode
;
7999 enum tree_code code
= ops
->code
;
8001 rtx subtarget
, original_target
;
8003 bool reduce_bit_field
;
8004 location_t loc
= ops
->location
;
8005 tree treeop0
, treeop1
, treeop2
;
8006 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8007 ? reduce_to_bit_field_precision ((expr), \
8013 mode
= TYPE_MODE (type
);
8014 unsignedp
= TYPE_UNSIGNED (type
);
8020 /* We should be called only on simple (binary or unary) expressions,
8021 exactly those that are valid in gimple expressions that aren't
8022 GIMPLE_SINGLE_RHS (or invalid). */
8023 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8024 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8025 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8027 ignore
= (target
== const0_rtx
8028 || ((CONVERT_EXPR_CODE_P (code
)
8029 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8030 && TREE_CODE (type
) == VOID_TYPE
));
8032 /* We should be called only if we need the result. */
8033 gcc_assert (!ignore
);
8035 /* An operation in what may be a bit-field type needs the
8036 result to be reduced to the precision of the bit-field type,
8037 which is narrower than that of the type's mode. */
8038 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8039 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8041 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8044 /* Use subtarget as the target for operand 0 of a binary operation. */
8045 subtarget
= get_subtarget (target
);
8046 original_target
= target
;
8050 case NON_LVALUE_EXPR
:
8053 if (treeop0
== error_mark_node
)
8056 if (TREE_CODE (type
) == UNION_TYPE
)
8058 tree valtype
= TREE_TYPE (treeop0
);
8060 /* If both input and output are BLKmode, this conversion isn't doing
8061 anything except possibly changing memory attribute. */
8062 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8064 rtx result
= expand_expr (treeop0
, target
, tmode
,
8067 result
= copy_rtx (result
);
8068 set_mem_attributes (result
, type
, 0);
8074 if (TYPE_MODE (type
) != BLKmode
)
8075 target
= gen_reg_rtx (TYPE_MODE (type
));
8077 target
= assign_temp (type
, 1, 1);
8081 /* Store data into beginning of memory target. */
8082 store_expr (treeop0
,
8083 adjust_address (target
, TYPE_MODE (valtype
), 0),
8084 modifier
== EXPAND_STACK_PARM
,
8089 gcc_assert (REG_P (target
));
8091 /* Store this field into a union of the proper type. */
8092 store_field (target
,
8093 MIN ((int_size_in_bytes (TREE_TYPE
8096 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8097 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8100 /* Return the entire union. */
8104 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8106 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8109 /* If the signedness of the conversion differs and OP0 is
8110 a promoted SUBREG, clear that indication since we now
8111 have to do the proper extension. */
8112 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8113 && GET_CODE (op0
) == SUBREG
)
8114 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8116 return REDUCE_BIT_FIELD (op0
);
8119 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8120 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8121 if (GET_MODE (op0
) == mode
)
8124 /* If OP0 is a constant, just convert it into the proper mode. */
8125 else if (CONSTANT_P (op0
))
8127 tree inner_type
= TREE_TYPE (treeop0
);
8128 enum machine_mode inner_mode
= GET_MODE (op0
);
8130 if (inner_mode
== VOIDmode
)
8131 inner_mode
= TYPE_MODE (inner_type
);
8133 if (modifier
== EXPAND_INITIALIZER
)
8134 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
8135 subreg_lowpart_offset (mode
,
8138 op0
= convert_modes (mode
, inner_mode
, op0
,
8139 TYPE_UNSIGNED (inner_type
));
8142 else if (modifier
== EXPAND_INITIALIZER
)
8143 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8145 else if (target
== 0)
8146 op0
= convert_to_mode (mode
, op0
,
8147 TYPE_UNSIGNED (TREE_TYPE
8151 convert_move (target
, op0
,
8152 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8156 return REDUCE_BIT_FIELD (op0
);
8158 case ADDR_SPACE_CONVERT_EXPR
:
8160 tree treeop0_type
= TREE_TYPE (treeop0
);
8162 addr_space_t as_from
;
8164 gcc_assert (POINTER_TYPE_P (type
));
8165 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8167 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8168 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8170 /* Conversions between pointers to the same address space should
8171 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8172 gcc_assert (as_to
!= as_from
);
8174 /* Ask target code to handle conversion between pointers
8175 to overlapping address spaces. */
8176 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8177 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8179 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8180 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8185 /* For disjoint address spaces, converting anything but
8186 a null pointer invokes undefined behaviour. We simply
8187 always return a null pointer here. */
8188 return CONST0_RTX (mode
);
8191 case POINTER_PLUS_EXPR
:
8192 /* Even though the sizetype mode and the pointer's mode can be different
8193 expand is able to handle this correctly and get the correct result out
8194 of the PLUS_EXPR code. */
8195 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8196 if sizetype precision is smaller than pointer precision. */
8197 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8198 treeop1
= fold_convert_loc (loc
, type
,
8199 fold_convert_loc (loc
, ssizetype
,
8201 /* If sizetype precision is larger than pointer precision, truncate the
8202 offset to have matching modes. */
8203 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8204 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8207 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8208 something else, make sure we add the register to the constant and
8209 then to the other thing. This case can occur during strength
8210 reduction and doing it this way will produce better code if the
8211 frame pointer or argument pointer is eliminated.
8213 fold-const.c will ensure that the constant is always in the inner
8214 PLUS_EXPR, so the only case we need to do anything about is if
8215 sp, ap, or fp is our second argument, in which case we must swap
8216 the innermost first argument and our second argument. */
8218 if (TREE_CODE (treeop0
) == PLUS_EXPR
8219 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8220 && TREE_CODE (treeop1
) == VAR_DECL
8221 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8222 || DECL_RTL (treeop1
) == stack_pointer_rtx
8223 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8228 /* If the result is to be ptr_mode and we are adding an integer to
8229 something, we might be forming a constant. So try to use
8230 plus_constant. If it produces a sum and we can't accept it,
8231 use force_operand. This allows P = &ARR[const] to generate
8232 efficient code on machines where a SYMBOL_REF is not a valid
8235 If this is an EXPAND_SUM call, always return the sum. */
8236 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8237 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8239 if (modifier
== EXPAND_STACK_PARM
)
8241 if (TREE_CODE (treeop0
) == INTEGER_CST
8242 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8243 && TREE_CONSTANT (treeop1
))
8247 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8249 /* Use immed_double_const to ensure that the constant is
8250 truncated according to the mode of OP1, then sign extended
8251 to a HOST_WIDE_INT. Using the constant directly can result
8252 in non-canonical RTL in a 64x32 cross compile. */
8254 = immed_double_const (TREE_INT_CST_LOW (treeop0
),
8256 TYPE_MODE (TREE_TYPE (treeop1
)));
8257 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8258 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8259 op1
= force_operand (op1
, target
);
8260 return REDUCE_BIT_FIELD (op1
);
8263 else if (TREE_CODE (treeop1
) == INTEGER_CST
8264 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8265 && TREE_CONSTANT (treeop0
))
8269 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8270 (modifier
== EXPAND_INITIALIZER
8271 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8272 if (! CONSTANT_P (op0
))
8274 op1
= expand_expr (treeop1
, NULL_RTX
,
8275 VOIDmode
, modifier
);
8276 /* Return a PLUS if modifier says it's OK. */
8277 if (modifier
== EXPAND_SUM
8278 || modifier
== EXPAND_INITIALIZER
)
8279 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8282 /* Use immed_double_const to ensure that the constant is
8283 truncated according to the mode of OP1, then sign extended
8284 to a HOST_WIDE_INT. Using the constant directly can result
8285 in non-canonical RTL in a 64x32 cross compile. */
8287 = immed_double_const (TREE_INT_CST_LOW (treeop1
),
8289 TYPE_MODE (TREE_TYPE (treeop0
)));
8290 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8291 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8292 op0
= force_operand (op0
, target
);
8293 return REDUCE_BIT_FIELD (op0
);
8297 /* Use TER to expand pointer addition of a negated value
8298 as pointer subtraction. */
8299 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8300 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8301 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8302 && TREE_CODE (treeop1
) == SSA_NAME
8303 && TYPE_MODE (TREE_TYPE (treeop0
))
8304 == TYPE_MODE (TREE_TYPE (treeop1
)))
8306 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8309 treeop1
= gimple_assign_rhs1 (def
);
8315 /* No sense saving up arithmetic to be done
8316 if it's all in the wrong mode to form part of an address.
8317 And force_operand won't know whether to sign-extend or
8319 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8320 || mode
!= ptr_mode
)
8322 expand_operands (treeop0
, treeop1
,
8323 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8324 if (op0
== const0_rtx
)
8326 if (op1
== const0_rtx
)
8331 expand_operands (treeop0
, treeop1
,
8332 subtarget
, &op0
, &op1
, modifier
);
8333 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8337 /* For initializers, we are allowed to return a MINUS of two
8338 symbolic constants. Here we handle all cases when both operands
8340 /* Handle difference of two symbolic constants,
8341 for the sake of an initializer. */
8342 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8343 && really_constant_p (treeop0
)
8344 && really_constant_p (treeop1
))
8346 expand_operands (treeop0
, treeop1
,
8347 NULL_RTX
, &op0
, &op1
, modifier
);
8349 /* If the last operand is a CONST_INT, use plus_constant of
8350 the negated constant. Else make the MINUS. */
8351 if (CONST_INT_P (op1
))
8352 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8355 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8358 /* No sense saving up arithmetic to be done
8359 if it's all in the wrong mode to form part of an address.
8360 And force_operand won't know whether to sign-extend or
8362 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8363 || mode
!= ptr_mode
)
8366 expand_operands (treeop0
, treeop1
,
8367 subtarget
, &op0
, &op1
, modifier
);
8369 /* Convert A - const to A + (-const). */
8370 if (CONST_INT_P (op1
))
8372 op1
= negate_rtx (mode
, op1
);
8373 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8378 case WIDEN_MULT_PLUS_EXPR
:
8379 case WIDEN_MULT_MINUS_EXPR
:
8380 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8381 op2
= expand_normal (treeop2
);
8382 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8386 case WIDEN_MULT_EXPR
:
8387 /* If first operand is constant, swap them.
8388 Thus the following special case checks need only
8389 check the second operand. */
8390 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8397 /* First, check if we have a multiplication of one signed and one
8398 unsigned operand. */
8399 if (TREE_CODE (treeop1
) != INTEGER_CST
8400 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8401 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8403 enum machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8404 this_optab
= usmul_widen_optab
;
8405 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8406 != CODE_FOR_nothing
)
8408 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8409 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8412 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8414 /* op0 and op1 might still be constant, despite the above
8415 != INTEGER_CST check. Handle it. */
8416 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8418 op0
= convert_modes (innermode
, mode
, op0
, true);
8419 op1
= convert_modes (innermode
, mode
, op1
, false);
8420 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8421 target
, unsignedp
));
8426 /* Check for a multiplication with matching signedness. */
8427 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8428 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8429 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8430 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8432 tree op0type
= TREE_TYPE (treeop0
);
8433 enum machine_mode innermode
= TYPE_MODE (op0type
);
8434 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8435 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8436 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8438 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8440 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8441 != CODE_FOR_nothing
)
8443 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8445 /* op0 and op1 might still be constant, despite the above
8446 != INTEGER_CST check. Handle it. */
8447 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8450 op0
= convert_modes (innermode
, mode
, op0
, zextend_p
);
8452 = convert_modes (innermode
, mode
, op1
,
8453 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8454 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8458 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8459 unsignedp
, this_optab
);
8460 return REDUCE_BIT_FIELD (temp
);
8462 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8464 && innermode
== word_mode
)
8467 op0
= expand_normal (treeop0
);
8468 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8469 op1
= convert_modes (innermode
, mode
,
8470 expand_normal (treeop1
),
8471 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8473 op1
= expand_normal (treeop1
);
8474 /* op0 and op1 might still be constant, despite the above
8475 != INTEGER_CST check. Handle it. */
8476 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8477 goto widen_mult_const
;
8478 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8479 unsignedp
, OPTAB_LIB_WIDEN
);
8480 hipart
= gen_highpart (innermode
, temp
);
8481 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8485 emit_move_insn (hipart
, htem
);
8486 return REDUCE_BIT_FIELD (temp
);
8490 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8491 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8492 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8493 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8497 optab opt
= fma_optab
;
8500 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8502 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8504 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8507 gcc_assert (fn
!= NULL_TREE
);
8508 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8509 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8512 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8513 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8518 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8521 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8522 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8525 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8528 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8531 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8534 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8538 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8540 op2
= expand_normal (treeop2
);
8541 op1
= expand_normal (treeop1
);
8543 return expand_ternary_op (TYPE_MODE (type
), opt
,
8544 op0
, op1
, op2
, target
, 0);
8548 /* If this is a fixed-point operation, then we cannot use the code
8549 below because "expand_mult" doesn't support sat/no-sat fixed-point
8551 if (ALL_FIXED_POINT_MODE_P (mode
))
8554 /* If first operand is constant, swap them.
8555 Thus the following special case checks need only
8556 check the second operand. */
8557 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8564 /* Attempt to return something suitable for generating an
8565 indexed address, for machines that support that. */
8567 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8568 && tree_fits_shwi_p (treeop1
))
8570 tree exp1
= treeop1
;
8572 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8576 op0
= force_operand (op0
, NULL_RTX
);
8578 op0
= copy_to_mode_reg (mode
, op0
);
8580 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8581 gen_int_mode (tree_to_shwi (exp1
),
8582 TYPE_MODE (TREE_TYPE (exp1
)))));
8585 if (modifier
== EXPAND_STACK_PARM
)
8588 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8589 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8591 case TRUNC_DIV_EXPR
:
8592 case FLOOR_DIV_EXPR
:
8594 case ROUND_DIV_EXPR
:
8595 case EXACT_DIV_EXPR
:
8596 /* If this is a fixed-point operation, then we cannot use the code
8597 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8599 if (ALL_FIXED_POINT_MODE_P (mode
))
8602 if (modifier
== EXPAND_STACK_PARM
)
8604 /* Possible optimization: compute the dividend with EXPAND_SUM
8605 then if the divisor is constant can optimize the case
8606 where some terms of the dividend have coeffs divisible by it. */
8607 expand_operands (treeop0
, treeop1
,
8608 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8609 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8614 case MULT_HIGHPART_EXPR
:
8615 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8616 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8620 case TRUNC_MOD_EXPR
:
8621 case FLOOR_MOD_EXPR
:
8623 case ROUND_MOD_EXPR
:
8624 if (modifier
== EXPAND_STACK_PARM
)
8626 expand_operands (treeop0
, treeop1
,
8627 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8628 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8630 case FIXED_CONVERT_EXPR
:
8631 op0
= expand_normal (treeop0
);
8632 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8633 target
= gen_reg_rtx (mode
);
8635 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8636 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8637 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8638 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8640 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8643 case FIX_TRUNC_EXPR
:
8644 op0
= expand_normal (treeop0
);
8645 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8646 target
= gen_reg_rtx (mode
);
8647 expand_fix (target
, op0
, unsignedp
);
8651 op0
= expand_normal (treeop0
);
8652 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8653 target
= gen_reg_rtx (mode
);
8654 /* expand_float can't figure out what to do if FROM has VOIDmode.
8655 So give it the correct mode. With -O, cse will optimize this. */
8656 if (GET_MODE (op0
) == VOIDmode
)
8657 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8659 expand_float (target
, op0
,
8660 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8664 op0
= expand_expr (treeop0
, subtarget
,
8665 VOIDmode
, EXPAND_NORMAL
);
8666 if (modifier
== EXPAND_STACK_PARM
)
8668 temp
= expand_unop (mode
,
8669 optab_for_tree_code (NEGATE_EXPR
, type
,
8673 return REDUCE_BIT_FIELD (temp
);
8676 op0
= expand_expr (treeop0
, subtarget
,
8677 VOIDmode
, EXPAND_NORMAL
);
8678 if (modifier
== EXPAND_STACK_PARM
)
8681 /* ABS_EXPR is not valid for complex arguments. */
8682 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8683 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8685 /* Unsigned abs is simply the operand. Testing here means we don't
8686 risk generating incorrect code below. */
8687 if (TYPE_UNSIGNED (type
))
8690 return expand_abs (mode
, op0
, target
, unsignedp
,
8691 safe_from_p (target
, treeop0
, 1));
8695 target
= original_target
;
8697 || modifier
== EXPAND_STACK_PARM
8698 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8699 || GET_MODE (target
) != mode
8701 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8702 target
= gen_reg_rtx (mode
);
8703 expand_operands (treeop0
, treeop1
,
8704 target
, &op0
, &op1
, EXPAND_NORMAL
);
8706 /* First try to do it with a special MIN or MAX instruction.
8707 If that does not win, use a conditional jump to select the proper
8709 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8710 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8715 /* At this point, a MEM target is no longer useful; we will get better
8718 if (! REG_P (target
))
8719 target
= gen_reg_rtx (mode
);
8721 /* If op1 was placed in target, swap op0 and op1. */
8722 if (target
!= op0
&& target
== op1
)
8729 /* We generate better code and avoid problems with op1 mentioning
8730 target by forcing op1 into a pseudo if it isn't a constant. */
8731 if (! CONSTANT_P (op1
))
8732 op1
= force_reg (mode
, op1
);
8735 enum rtx_code comparison_code
;
8738 if (code
== MAX_EXPR
)
8739 comparison_code
= unsignedp
? GEU
: GE
;
8741 comparison_code
= unsignedp
? LEU
: LE
;
8743 /* Canonicalize to comparisons against 0. */
8744 if (op1
== const1_rtx
)
8746 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8747 or (a != 0 ? a : 1) for unsigned.
8748 For MIN we are safe converting (a <= 1 ? a : 1)
8749 into (a <= 0 ? a : 1) */
8750 cmpop1
= const0_rtx
;
8751 if (code
== MAX_EXPR
)
8752 comparison_code
= unsignedp
? NE
: GT
;
8754 if (op1
== constm1_rtx
&& !unsignedp
)
8756 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8757 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8758 cmpop1
= const0_rtx
;
8759 if (code
== MIN_EXPR
)
8760 comparison_code
= LT
;
8762 #ifdef HAVE_conditional_move
8763 /* Use a conditional move if possible. */
8764 if (can_conditionally_move_p (mode
))
8768 /* ??? Same problem as in expmed.c: emit_conditional_move
8769 forces a stack adjustment via compare_from_rtx, and we
8770 lose the stack adjustment if the sequence we are about
8771 to create is discarded. */
8772 do_pending_stack_adjust ();
8776 /* Try to emit the conditional move. */
8777 insn
= emit_conditional_move (target
, comparison_code
,
8782 /* If we could do the conditional move, emit the sequence,
8786 rtx seq
= get_insns ();
8792 /* Otherwise discard the sequence and fall back to code with
8798 emit_move_insn (target
, op0
);
8800 temp
= gen_label_rtx ();
8801 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8802 unsignedp
, mode
, NULL_RTX
, NULL_RTX
, temp
,
8805 emit_move_insn (target
, op1
);
8810 op0
= expand_expr (treeop0
, subtarget
,
8811 VOIDmode
, EXPAND_NORMAL
);
8812 if (modifier
== EXPAND_STACK_PARM
)
8814 /* In case we have to reduce the result to bitfield precision
8815 for unsigned bitfield expand this as XOR with a proper constant
8817 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8818 temp
= expand_binop (mode
, xor_optab
, op0
,
8819 immed_double_int_const
8820 (double_int::mask (TYPE_PRECISION (type
)), mode
),
8821 target
, 1, OPTAB_LIB_WIDEN
);
8823 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8827 /* ??? Can optimize bitwise operations with one arg constant.
8828 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8829 and (a bitwise1 b) bitwise2 b (etc)
8830 but that is probably not worth while. */
8839 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8840 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8841 == TYPE_PRECISION (type
)));
8846 /* If this is a fixed-point operation, then we cannot use the code
8847 below because "expand_shift" doesn't support sat/no-sat fixed-point
8849 if (ALL_FIXED_POINT_MODE_P (mode
))
8852 if (! safe_from_p (subtarget
, treeop1
, 1))
8854 if (modifier
== EXPAND_STACK_PARM
)
8856 op0
= expand_expr (treeop0
, subtarget
,
8857 VOIDmode
, EXPAND_NORMAL
);
8858 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8860 if (code
== LSHIFT_EXPR
)
8861 temp
= REDUCE_BIT_FIELD (temp
);
8864 /* Could determine the answer when only additive constants differ. Also,
8865 the addition of one can be handled by changing the condition. */
8872 case UNORDERED_EXPR
:
8880 temp
= do_store_flag (ops
,
8881 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8882 tmode
!= VOIDmode
? tmode
: mode
);
8886 /* Use a compare and a jump for BLKmode comparisons, or for function
8887 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8890 || modifier
== EXPAND_STACK_PARM
8891 || ! safe_from_p (target
, treeop0
, 1)
8892 || ! safe_from_p (target
, treeop1
, 1)
8893 /* Make sure we don't have a hard reg (such as function's return
8894 value) live across basic blocks, if not optimizing. */
8895 || (!optimize
&& REG_P (target
)
8896 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8897 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8899 emit_move_insn (target
, const0_rtx
);
8901 op1
= gen_label_rtx ();
8902 jumpifnot_1 (code
, treeop0
, treeop1
, op1
, -1);
8904 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8905 emit_move_insn (target
, constm1_rtx
);
8907 emit_move_insn (target
, const1_rtx
);
8913 /* Get the rtx code of the operands. */
8914 op0
= expand_normal (treeop0
);
8915 op1
= expand_normal (treeop1
);
8918 target
= gen_reg_rtx (TYPE_MODE (type
));
8920 /* If target overlaps with op1, then either we need to force
8921 op1 into a pseudo (if target also overlaps with op0),
8922 or write the complex parts in reverse order. */
8923 switch (GET_CODE (target
))
8926 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
8928 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
8930 complex_expr_force_op1
:
8931 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
8932 emit_move_insn (temp
, op1
);
8936 complex_expr_swap_order
:
8937 /* Move the imaginary (op1) and real (op0) parts to their
8939 write_complex_part (target
, op1
, true);
8940 write_complex_part (target
, op0
, false);
8946 temp
= adjust_address_nv (target
,
8947 GET_MODE_INNER (GET_MODE (target
)), 0);
8948 if (reg_overlap_mentioned_p (temp
, op1
))
8950 enum machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
8951 temp
= adjust_address_nv (target
, imode
,
8952 GET_MODE_SIZE (imode
));
8953 if (reg_overlap_mentioned_p (temp
, op0
))
8954 goto complex_expr_force_op1
;
8955 goto complex_expr_swap_order
;
8959 if (reg_overlap_mentioned_p (target
, op1
))
8961 if (reg_overlap_mentioned_p (target
, op0
))
8962 goto complex_expr_force_op1
;
8963 goto complex_expr_swap_order
;
8968 /* Move the real (op0) and imaginary (op1) parts to their location. */
8969 write_complex_part (target
, op0
, false);
8970 write_complex_part (target
, op1
, true);
8974 case WIDEN_SUM_EXPR
:
8976 tree oprnd0
= treeop0
;
8977 tree oprnd1
= treeop1
;
8979 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8980 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
8985 case REDUC_MAX_EXPR
:
8986 case REDUC_MIN_EXPR
:
8987 case REDUC_PLUS_EXPR
:
8989 op0
= expand_normal (treeop0
);
8990 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8991 temp
= expand_unop (mode
, this_optab
, op0
, target
, unsignedp
);
8996 case VEC_LSHIFT_EXPR
:
8997 case VEC_RSHIFT_EXPR
:
8999 target
= expand_vec_shift_expr (ops
, target
);
9003 case VEC_UNPACK_HI_EXPR
:
9004 case VEC_UNPACK_LO_EXPR
:
9006 op0
= expand_normal (treeop0
);
9007 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9013 case VEC_UNPACK_FLOAT_HI_EXPR
:
9014 case VEC_UNPACK_FLOAT_LO_EXPR
:
9016 op0
= expand_normal (treeop0
);
9017 /* The signedness is determined from input operand. */
9018 temp
= expand_widen_pattern_expr
9019 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9020 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9026 case VEC_WIDEN_MULT_HI_EXPR
:
9027 case VEC_WIDEN_MULT_LO_EXPR
:
9028 case VEC_WIDEN_MULT_EVEN_EXPR
:
9029 case VEC_WIDEN_MULT_ODD_EXPR
:
9030 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9031 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9032 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9033 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9035 gcc_assert (target
);
9038 case VEC_PACK_TRUNC_EXPR
:
9039 case VEC_PACK_SAT_EXPR
:
9040 case VEC_PACK_FIX_TRUNC_EXPR
:
9041 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9045 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9046 op2
= expand_normal (treeop2
);
9048 /* Careful here: if the target doesn't support integral vector modes,
9049 a constant selection vector could wind up smooshed into a normal
9050 integral constant. */
9051 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9053 tree sel_type
= TREE_TYPE (treeop2
);
9054 enum machine_mode vmode
9055 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9056 TYPE_VECTOR_SUBPARTS (sel_type
));
9057 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9058 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9059 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9062 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9064 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9070 tree oprnd0
= treeop0
;
9071 tree oprnd1
= treeop1
;
9072 tree oprnd2
= treeop2
;
9075 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9076 op2
= expand_normal (oprnd2
);
9077 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9082 case REALIGN_LOAD_EXPR
:
9084 tree oprnd0
= treeop0
;
9085 tree oprnd1
= treeop1
;
9086 tree oprnd2
= treeop2
;
9089 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9090 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9091 op2
= expand_normal (oprnd2
);
9092 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9099 /* A COND_EXPR with its type being VOID_TYPE represents a
9100 conditional jump and is handled in
9101 expand_gimple_cond_expr. */
9102 gcc_assert (!VOID_TYPE_P (type
));
9104 /* Note that COND_EXPRs whose type is a structure or union
9105 are required to be constructed to contain assignments of
9106 a temporary variable, so that we can evaluate them here
9107 for side effect only. If type is void, we must do likewise. */
9109 gcc_assert (!TREE_ADDRESSABLE (type
)
9111 && TREE_TYPE (treeop1
) != void_type_node
9112 && TREE_TYPE (treeop2
) != void_type_node
);
9114 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9118 /* If we are not to produce a result, we have no target. Otherwise,
9119 if a target was specified use it; it will not be used as an
9120 intermediate target unless it is safe. If no target, use a
9123 if (modifier
!= EXPAND_STACK_PARM
9125 && safe_from_p (original_target
, treeop0
, 1)
9126 && GET_MODE (original_target
) == mode
9127 && !MEM_P (original_target
))
9128 temp
= original_target
;
9130 temp
= assign_temp (type
, 0, 1);
9132 do_pending_stack_adjust ();
9134 op0
= gen_label_rtx ();
9135 op1
= gen_label_rtx ();
9136 jumpifnot (treeop0
, op0
, -1);
9137 store_expr (treeop1
, temp
,
9138 modifier
== EXPAND_STACK_PARM
,
9141 emit_jump_insn (gen_jump (op1
));
9144 store_expr (treeop2
, temp
,
9145 modifier
== EXPAND_STACK_PARM
,
9153 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9160 /* Here to do an ordinary binary operator. */
9162 expand_operands (treeop0
, treeop1
,
9163 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9165 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9167 if (modifier
== EXPAND_STACK_PARM
)
9169 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9170 unsignedp
, OPTAB_LIB_WIDEN
);
9172 /* Bitwise operations do not need bitfield reduction as we expect their
9173 operands being properly truncated. */
9174 if (code
== BIT_XOR_EXPR
9175 || code
== BIT_AND_EXPR
9176 || code
== BIT_IOR_EXPR
)
9178 return REDUCE_BIT_FIELD (temp
);
9180 #undef REDUCE_BIT_FIELD
9183 /* Return TRUE if expression STMT is suitable for replacement.
9184 Never consider memory loads as replaceable, because those don't ever lead
9185 into constant expressions. */
9188 stmt_is_replaceable_p (gimple stmt
)
9190 if (ssa_is_replaceable_p (stmt
))
9192 /* Don't move around loads. */
9193 if (!gimple_assign_single_p (stmt
)
9194 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9201 expand_expr_real_1 (tree exp
, rtx target
, enum machine_mode tmode
,
9202 enum expand_modifier modifier
, rtx
*alt_rtl
)
9204 rtx op0
, op1
, temp
, decl_rtl
;
9207 enum machine_mode mode
;
9208 enum tree_code code
= TREE_CODE (exp
);
9209 rtx subtarget
, original_target
;
9212 bool reduce_bit_field
;
9213 location_t loc
= EXPR_LOCATION (exp
);
9214 struct separate_ops ops
;
9215 tree treeop0
, treeop1
, treeop2
;
9216 tree ssa_name
= NULL_TREE
;
9219 type
= TREE_TYPE (exp
);
9220 mode
= TYPE_MODE (type
);
9221 unsignedp
= TYPE_UNSIGNED (type
);
9223 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9224 if (!VL_EXP_CLASS_P (exp
))
9225 switch (TREE_CODE_LENGTH (code
))
9228 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9229 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9230 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9240 ignore
= (target
== const0_rtx
9241 || ((CONVERT_EXPR_CODE_P (code
)
9242 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9243 && TREE_CODE (type
) == VOID_TYPE
));
9245 /* An operation in what may be a bit-field type needs the
9246 result to be reduced to the precision of the bit-field type,
9247 which is narrower than that of the type's mode. */
9248 reduce_bit_field
= (!ignore
9249 && INTEGRAL_TYPE_P (type
)
9250 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9252 /* If we are going to ignore this result, we need only do something
9253 if there is a side-effect somewhere in the expression. If there
9254 is, short-circuit the most common cases here. Note that we must
9255 not call expand_expr with anything but const0_rtx in case this
9256 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9260 if (! TREE_SIDE_EFFECTS (exp
))
9263 /* Ensure we reference a volatile object even if value is ignored, but
9264 don't do this if all we are doing is taking its address. */
9265 if (TREE_THIS_VOLATILE (exp
)
9266 && TREE_CODE (exp
) != FUNCTION_DECL
9267 && mode
!= VOIDmode
&& mode
!= BLKmode
9268 && modifier
!= EXPAND_CONST_ADDRESS
)
9270 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9276 if (TREE_CODE_CLASS (code
) == tcc_unary
9277 || code
== BIT_FIELD_REF
9278 || code
== COMPONENT_REF
9279 || code
== INDIRECT_REF
)
9280 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9283 else if (TREE_CODE_CLASS (code
) == tcc_binary
9284 || TREE_CODE_CLASS (code
) == tcc_comparison
9285 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9287 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9288 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9295 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9298 /* Use subtarget as the target for operand 0 of a binary operation. */
9299 subtarget
= get_subtarget (target
);
9300 original_target
= target
;
9306 tree function
= decl_function_context (exp
);
9308 temp
= label_rtx (exp
);
9309 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9311 if (function
!= current_function_decl
9313 LABEL_REF_NONLOCAL_P (temp
) = 1;
9315 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9320 /* ??? ivopts calls expander, without any preparation from
9321 out-of-ssa. So fake instructions as if this was an access to the
9322 base variable. This unnecessarily allocates a pseudo, see how we can
9323 reuse it, if partition base vars have it set already. */
9324 if (!currently_expanding_to_rtl
)
9326 tree var
= SSA_NAME_VAR (exp
);
9327 if (var
&& DECL_RTL_SET_P (var
))
9328 return DECL_RTL (var
);
9329 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9330 LAST_VIRTUAL_REGISTER
+ 1);
9333 g
= get_gimple_for_ssa_name (exp
);
9334 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9336 && modifier
== EXPAND_INITIALIZER
9337 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9338 && (optimize
|| DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9339 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9340 g
= SSA_NAME_DEF_STMT (exp
);
9344 location_t saved_loc
= curr_insn_location ();
9346 set_curr_insn_location (gimple_location (g
));
9347 r
= expand_expr_real (gimple_assign_rhs_to_tree (g
), target
,
9348 tmode
, modifier
, NULL
);
9349 set_curr_insn_location (saved_loc
);
9350 if (REG_P (r
) && !REG_EXPR (r
))
9351 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9356 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9357 exp
= SSA_NAME_VAR (ssa_name
);
9358 goto expand_decl_rtl
;
9362 /* If a static var's type was incomplete when the decl was written,
9363 but the type is complete now, lay out the decl now. */
9364 if (DECL_SIZE (exp
) == 0
9365 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9366 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9367 layout_decl (exp
, 0);
9369 /* ... fall through ... */
9373 decl_rtl
= DECL_RTL (exp
);
9375 gcc_assert (decl_rtl
);
9376 decl_rtl
= copy_rtx (decl_rtl
);
9377 /* Record writes to register variables. */
9378 if (modifier
== EXPAND_WRITE
9380 && HARD_REGISTER_P (decl_rtl
))
9381 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9382 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9384 /* Ensure variable marked as used even if it doesn't go through
9385 a parser. If it hasn't be used yet, write out an external
9387 TREE_USED (exp
) = 1;
9389 /* Show we haven't gotten RTL for this yet. */
9392 /* Variables inherited from containing functions should have
9393 been lowered by this point. */
9394 context
= decl_function_context (exp
);
9395 gcc_assert (SCOPE_FILE_SCOPE_P (context
)
9396 || context
== current_function_decl
9397 || TREE_STATIC (exp
)
9398 || DECL_EXTERNAL (exp
)
9399 /* ??? C++ creates functions that are not TREE_STATIC. */
9400 || TREE_CODE (exp
) == FUNCTION_DECL
);
9402 /* This is the case of an array whose size is to be determined
9403 from its initializer, while the initializer is still being parsed.
9404 ??? We aren't parsing while expanding anymore. */
9406 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9407 temp
= validize_mem (decl_rtl
);
9409 /* If DECL_RTL is memory, we are in the normal case and the
9410 address is not valid, get the address into a register. */
9412 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9415 *alt_rtl
= decl_rtl
;
9416 decl_rtl
= use_anchored_address (decl_rtl
);
9417 if (modifier
!= EXPAND_CONST_ADDRESS
9418 && modifier
!= EXPAND_SUM
9419 && !memory_address_addr_space_p (DECL_MODE (exp
),
9421 MEM_ADDR_SPACE (decl_rtl
)))
9422 temp
= replace_equiv_address (decl_rtl
,
9423 copy_rtx (XEXP (decl_rtl
, 0)));
9426 /* If we got something, return it. But first, set the alignment
9427 if the address is a register. */
9430 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9431 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9436 /* If the mode of DECL_RTL does not match that of the decl,
9437 there are two cases: we are dealing with a BLKmode value
9438 that is returned in a register, or we are dealing with
9439 a promoted value. In the latter case, return a SUBREG
9440 of the wanted mode, but mark it so that we know that it
9441 was already extended. */
9442 if (REG_P (decl_rtl
)
9443 && DECL_MODE (exp
) != BLKmode
9444 && GET_MODE (decl_rtl
) != DECL_MODE (exp
))
9446 enum machine_mode pmode
;
9448 /* Get the signedness to be used for this variable. Ensure we get
9449 the same mode we got when the variable was declared. */
9450 if (code
== SSA_NAME
9451 && (g
= SSA_NAME_DEF_STMT (ssa_name
))
9452 && gimple_code (g
) == GIMPLE_CALL
)
9454 gcc_assert (!gimple_call_internal_p (g
));
9455 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9456 gimple_call_fntype (g
),
9460 pmode
= promote_decl_mode (exp
, &unsignedp
);
9461 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9463 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9464 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9465 SUBREG_PROMOTED_UNSIGNED_SET (temp
, unsignedp
);
9472 temp
= immed_double_const (TREE_INT_CST_LOW (exp
),
9473 TREE_INT_CST_HIGH (exp
), mode
);
9479 tree tmp
= NULL_TREE
;
9480 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9481 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9482 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9483 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9484 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9485 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9486 return const_vector_from_tree (exp
);
9487 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9489 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9491 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9495 vec
<constructor_elt
, va_gc
> *v
;
9497 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9498 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9499 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9500 tmp
= build_constructor (type
, v
);
9502 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9507 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9510 /* If optimized, generate immediate CONST_DOUBLE
9511 which will be turned into memory by reload if necessary.
9513 We used to force a register so that loop.c could see it. But
9514 this does not allow gen_* patterns to perform optimizations with
9515 the constants. It also produces two insns in cases like "x = 1.0;".
9516 On most machines, floating-point constants are not permitted in
9517 many insns, so we'd end up copying it to a register in any case.
9519 Now, we do the copying in expand_binop, if appropriate. */
9520 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9521 TYPE_MODE (TREE_TYPE (exp
)));
9524 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9525 TYPE_MODE (TREE_TYPE (exp
)));
9528 /* Handle evaluating a complex constant in a CONCAT target. */
9529 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9531 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9534 rtarg
= XEXP (original_target
, 0);
9535 itarg
= XEXP (original_target
, 1);
9537 /* Move the real and imaginary parts separately. */
9538 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9539 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9542 emit_move_insn (rtarg
, op0
);
9544 emit_move_insn (itarg
, op1
);
9546 return original_target
;
9549 /* ... fall through ... */
9552 temp
= expand_expr_constant (exp
, 1, modifier
);
9554 /* temp contains a constant address.
9555 On RISC machines where a constant address isn't valid,
9556 make some insns to get that address into a register. */
9557 if (modifier
!= EXPAND_CONST_ADDRESS
9558 && modifier
!= EXPAND_INITIALIZER
9559 && modifier
!= EXPAND_SUM
9560 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9561 MEM_ADDR_SPACE (temp
)))
9562 return replace_equiv_address (temp
,
9563 copy_rtx (XEXP (temp
, 0)));
9569 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
);
9571 if (!SAVE_EXPR_RESOLVED_P (exp
))
9573 /* We can indeed still hit this case, typically via builtin
9574 expanders calling save_expr immediately before expanding
9575 something. Assume this means that we only have to deal
9576 with non-BLKmode values. */
9577 gcc_assert (GET_MODE (ret
) != BLKmode
);
9579 val
= build_decl (curr_insn_location (),
9580 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9581 DECL_ARTIFICIAL (val
) = 1;
9582 DECL_IGNORED_P (val
) = 1;
9584 TREE_OPERAND (exp
, 0) = treeop0
;
9585 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9587 if (!CONSTANT_P (ret
))
9588 ret
= copy_to_reg (ret
);
9589 SET_DECL_RTL (val
, ret
);
9597 /* If we don't need the result, just ensure we evaluate any
9601 unsigned HOST_WIDE_INT idx
;
9604 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9605 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9610 return expand_constructor (exp
, target
, modifier
, false);
9612 case TARGET_MEM_REF
:
9615 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9616 enum insn_code icode
;
9619 op0
= addr_for_mem_ref (exp
, as
, true);
9620 op0
= memory_address_addr_space (mode
, op0
, as
);
9621 temp
= gen_rtx_MEM (mode
, op0
);
9622 set_mem_attributes (temp
, exp
, 0);
9623 set_mem_addr_space (temp
, as
);
9624 align
= get_object_alignment (exp
);
9625 if (modifier
!= EXPAND_WRITE
9626 && modifier
!= EXPAND_MEMORY
9628 && align
< GET_MODE_ALIGNMENT (mode
)
9629 /* If the target does not have special handling for unaligned
9630 loads of mode then it can use regular moves for them. */
9631 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9632 != CODE_FOR_nothing
))
9634 struct expand_operand ops
[2];
9636 /* We've already validated the memory, and we're creating a
9637 new pseudo destination. The predicates really can't fail,
9638 nor can the generator. */
9639 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9640 create_fixed_operand (&ops
[1], temp
);
9641 expand_insn (icode
, 2, ops
);
9642 temp
= ops
[0].value
;
9650 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9651 enum machine_mode address_mode
;
9652 tree base
= TREE_OPERAND (exp
, 0);
9654 enum insn_code icode
;
9656 /* Handle expansion of non-aliased memory with non-BLKmode. That
9657 might end up in a register. */
9658 if (mem_ref_refers_to_non_mem_p (exp
))
9660 HOST_WIDE_INT offset
= mem_ref_offset (exp
).low
;
9661 base
= TREE_OPERAND (base
, 0);
9663 && tree_fits_uhwi_p (TYPE_SIZE (type
))
9664 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9665 == TREE_INT_CST_LOW (TYPE_SIZE (type
))))
9666 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
9667 target
, tmode
, modifier
);
9668 if (TYPE_MODE (type
) == BLKmode
)
9670 temp
= assign_stack_temp (DECL_MODE (base
),
9671 GET_MODE_SIZE (DECL_MODE (base
)));
9672 store_expr (base
, temp
, 0, false);
9673 temp
= adjust_address (temp
, BLKmode
, offset
);
9674 set_mem_size (temp
, int_size_in_bytes (type
));
9677 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
9678 bitsize_int (offset
* BITS_PER_UNIT
));
9679 return expand_expr (exp
, target
, tmode
, modifier
);
9681 address_mode
= targetm
.addr_space
.address_mode (as
);
9682 base
= TREE_OPERAND (exp
, 0);
9683 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9685 tree mask
= gimple_assign_rhs2 (def_stmt
);
9686 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9687 gimple_assign_rhs1 (def_stmt
), mask
);
9688 TREE_OPERAND (exp
, 0) = base
;
9690 align
= get_object_alignment (exp
);
9691 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9692 op0
= memory_address_addr_space (mode
, op0
, as
);
9693 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9696 = immed_double_int_const (mem_ref_offset (exp
), address_mode
);
9697 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9698 op0
= memory_address_addr_space (mode
, op0
, as
);
9700 temp
= gen_rtx_MEM (mode
, op0
);
9701 set_mem_attributes (temp
, exp
, 0);
9702 set_mem_addr_space (temp
, as
);
9703 if (TREE_THIS_VOLATILE (exp
))
9704 MEM_VOLATILE_P (temp
) = 1;
9705 if (modifier
!= EXPAND_WRITE
9706 && modifier
!= EXPAND_MEMORY
9708 && align
< GET_MODE_ALIGNMENT (mode
))
9710 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9711 != CODE_FOR_nothing
)
9713 struct expand_operand ops
[2];
9715 /* We've already validated the memory, and we're creating a
9716 new pseudo destination. The predicates really can't fail,
9717 nor can the generator. */
9718 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9719 create_fixed_operand (&ops
[1], temp
);
9720 expand_insn (icode
, 2, ops
);
9721 temp
= ops
[0].value
;
9723 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9724 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9725 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9726 (modifier
== EXPAND_STACK_PARM
9727 ? NULL_RTX
: target
),
9736 tree array
= treeop0
;
9737 tree index
= treeop1
;
9740 /* Fold an expression like: "foo"[2].
9741 This is not done in fold so it won't happen inside &.
9742 Don't fold if this is for wide characters since it's too
9743 difficult to do correctly and this is a very rare case. */
9745 if (modifier
!= EXPAND_CONST_ADDRESS
9746 && modifier
!= EXPAND_INITIALIZER
9747 && modifier
!= EXPAND_MEMORY
)
9749 tree t
= fold_read_from_constant_string (exp
);
9752 return expand_expr (t
, target
, tmode
, modifier
);
9755 /* If this is a constant index into a constant array,
9756 just get the value from the array. Handle both the cases when
9757 we have an explicit constructor and when our operand is a variable
9758 that was declared const. */
9760 if (modifier
!= EXPAND_CONST_ADDRESS
9761 && modifier
!= EXPAND_INITIALIZER
9762 && modifier
!= EXPAND_MEMORY
9763 && TREE_CODE (array
) == CONSTRUCTOR
9764 && ! TREE_SIDE_EFFECTS (array
)
9765 && TREE_CODE (index
) == INTEGER_CST
)
9767 unsigned HOST_WIDE_INT ix
;
9770 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9772 if (tree_int_cst_equal (field
, index
))
9774 if (!TREE_SIDE_EFFECTS (value
))
9775 return expand_expr (fold (value
), target
, tmode
, modifier
);
9780 else if (optimize
>= 1
9781 && modifier
!= EXPAND_CONST_ADDRESS
9782 && modifier
!= EXPAND_INITIALIZER
9783 && modifier
!= EXPAND_MEMORY
9784 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9785 && TREE_CODE (index
) == INTEGER_CST
9786 && (TREE_CODE (array
) == VAR_DECL
9787 || TREE_CODE (array
) == CONST_DECL
)
9788 && (init
= ctor_for_folding (array
)) != error_mark_node
)
9790 if (TREE_CODE (init
) == CONSTRUCTOR
)
9792 unsigned HOST_WIDE_INT ix
;
9795 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9797 if (tree_int_cst_equal (field
, index
))
9799 if (TREE_SIDE_EFFECTS (value
))
9802 if (TREE_CODE (value
) == CONSTRUCTOR
)
9804 /* If VALUE is a CONSTRUCTOR, this
9805 optimization is only useful if
9806 this doesn't store the CONSTRUCTOR
9807 into memory. If it does, it is more
9808 efficient to just load the data from
9809 the array directly. */
9810 rtx ret
= expand_constructor (value
, target
,
9812 if (ret
== NULL_RTX
)
9817 expand_expr (fold (value
), target
, tmode
, modifier
);
9820 else if (TREE_CODE (init
) == STRING_CST
)
9822 tree low_bound
= array_ref_low_bound (exp
);
9823 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
9825 /* Optimize the special case of a zero lower bound.
9827 We convert the lower bound to sizetype to avoid problems
9828 with constant folding. E.g. suppose the lower bound is
9829 1 and its mode is QI. Without the conversion
9830 (ARRAY + (INDEX - (unsigned char)1))
9832 (ARRAY + (-(unsigned char)1) + INDEX)
9834 (ARRAY + 255 + INDEX). Oops! */
9835 if (!integer_zerop (low_bound
))
9836 index1
= size_diffop_loc (loc
, index1
,
9837 fold_convert_loc (loc
, sizetype
,
9840 if (compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
9842 tree type
= TREE_TYPE (TREE_TYPE (init
));
9843 enum machine_mode mode
= TYPE_MODE (type
);
9845 if (GET_MODE_CLASS (mode
) == MODE_INT
9846 && GET_MODE_SIZE (mode
) == 1)
9847 return gen_int_mode (TREE_STRING_POINTER (init
)
9848 [TREE_INT_CST_LOW (index1
)],
9854 goto normal_inner_ref
;
9857 /* If the operand is a CONSTRUCTOR, we can just extract the
9858 appropriate field if it is present. */
9859 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
9861 unsigned HOST_WIDE_INT idx
;
9864 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
9866 if (field
== treeop1
9867 /* We can normally use the value of the field in the
9868 CONSTRUCTOR. However, if this is a bitfield in
9869 an integral mode that we can fit in a HOST_WIDE_INT,
9870 we must mask only the number of bits in the bitfield,
9871 since this is done implicitly by the constructor. If
9872 the bitfield does not meet either of those conditions,
9873 we can't do this optimization. */
9874 && (! DECL_BIT_FIELD (field
)
9875 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
9876 && (GET_MODE_PRECISION (DECL_MODE (field
))
9877 <= HOST_BITS_PER_WIDE_INT
))))
9879 if (DECL_BIT_FIELD (field
)
9880 && modifier
== EXPAND_STACK_PARM
)
9882 op0
= expand_expr (value
, target
, tmode
, modifier
);
9883 if (DECL_BIT_FIELD (field
))
9885 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
9886 enum machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
9888 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
9890 op1
= gen_int_mode (((HOST_WIDE_INT
) 1 << bitsize
) - 1,
9892 op0
= expand_and (imode
, op0
, op1
, target
);
9896 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
9898 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
9900 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
9908 goto normal_inner_ref
;
9911 case ARRAY_RANGE_REF
:
9914 enum machine_mode mode1
, mode2
;
9915 HOST_WIDE_INT bitsize
, bitpos
;
9917 int volatilep
= 0, must_force_mem
;
9918 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
9919 &mode1
, &unsignedp
, &volatilep
, true);
9920 rtx orig_op0
, memloc
;
9921 bool mem_attrs_from_type
= false;
9923 /* If we got back the original object, something is wrong. Perhaps
9924 we are evaluating an expression too early. In any event, don't
9925 infinitely recurse. */
9926 gcc_assert (tem
!= exp
);
9928 /* If TEM's type is a union of variable size, pass TARGET to the inner
9929 computation, since it will need a temporary and TARGET is known
9930 to have to do. This occurs in unchecked conversion in Ada. */
9933 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
9934 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
9935 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
9937 && modifier
!= EXPAND_STACK_PARM
9938 ? target
: NULL_RTX
),
9940 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
9942 /* If the bitfield is volatile, we want to access it in the
9943 field's mode, not the computed mode.
9944 If a MEM has VOIDmode (external with incomplete type),
9945 use BLKmode for it instead. */
9948 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
9949 op0
= adjust_address (op0
, mode1
, 0);
9950 else if (GET_MODE (op0
) == VOIDmode
)
9951 op0
= adjust_address (op0
, BLKmode
, 0);
9955 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
9957 /* If we have either an offset, a BLKmode result, or a reference
9958 outside the underlying object, we must force it to memory.
9959 Such a case can occur in Ada if we have unchecked conversion
9960 of an expression from a scalar type to an aggregate type or
9961 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9962 passed a partially uninitialized object or a view-conversion
9963 to a larger size. */
9964 must_force_mem
= (offset
9966 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
9968 /* Handle CONCAT first. */
9969 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
9972 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
9975 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9978 op0
= XEXP (op0
, 0);
9979 mode2
= GET_MODE (op0
);
9981 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9982 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
9986 op0
= XEXP (op0
, 1);
9988 mode2
= GET_MODE (op0
);
9991 /* Otherwise force into memory. */
9995 /* If this is a constant, put it in a register if it is a legitimate
9996 constant and we don't need a memory reference. */
9997 if (CONSTANT_P (op0
)
9999 && targetm
.legitimate_constant_p (mode2
, op0
)
10000 && !must_force_mem
)
10001 op0
= force_reg (mode2
, op0
);
10003 /* Otherwise, if this is a constant, try to force it to the constant
10004 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10005 is a legitimate constant. */
10006 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10007 op0
= validize_mem (memloc
);
10009 /* Otherwise, if this is a constant or the object is not in memory
10010 and need be, put it there. */
10011 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10013 tree nt
= build_qualified_type (TREE_TYPE (tem
),
10014 (TYPE_QUALS (TREE_TYPE (tem
))
10015 | TYPE_QUAL_CONST
));
10016 memloc
= assign_temp (nt
, 1, 1);
10017 emit_move_insn (memloc
, op0
);
10019 mem_attrs_from_type
= true;
10024 enum machine_mode address_mode
;
10025 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10028 gcc_assert (MEM_P (op0
));
10030 address_mode
= get_address_mode (op0
);
10031 if (GET_MODE (offset_rtx
) != address_mode
)
10032 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10034 if (GET_MODE (op0
) == BLKmode
10035 /* A constant address in OP0 can have VOIDmode, we must
10036 not try to call force_reg in that case. */
10037 && GET_MODE (XEXP (op0
, 0)) != VOIDmode
10039 && (bitpos
% bitsize
) == 0
10040 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10041 && MEM_ALIGN (op0
) == GET_MODE_ALIGNMENT (mode1
))
10043 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10047 op0
= offset_address (op0
, offset_rtx
,
10048 highest_pow2_factor (offset
));
10051 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10052 record its alignment as BIGGEST_ALIGNMENT. */
10053 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10054 && is_aligning_offset (offset
, tem
))
10055 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10057 /* Don't forget about volatility even if this is a bitfield. */
10058 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10060 if (op0
== orig_op0
)
10061 op0
= copy_rtx (op0
);
10063 MEM_VOLATILE_P (op0
) = 1;
10066 /* In cases where an aligned union has an unaligned object
10067 as a field, we might be extracting a BLKmode value from
10068 an integer-mode (e.g., SImode) object. Handle this case
10069 by doing the extract into an object as wide as the field
10070 (which we know to be the width of a basic mode), then
10071 storing into memory, and changing the mode to BLKmode. */
10072 if (mode1
== VOIDmode
10073 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10074 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10075 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10076 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10077 && modifier
!= EXPAND_CONST_ADDRESS
10078 && modifier
!= EXPAND_INITIALIZER
10079 && modifier
!= EXPAND_MEMORY
)
10080 /* If the field is volatile, we always want an aligned
10081 access. Do this in following two situations:
10082 1. the access is not already naturally
10083 aligned, otherwise "normal" (non-bitfield) volatile fields
10084 become non-addressable.
10085 2. the bitsize is narrower than the access size. Need
10086 to extract bitfields from the access. */
10087 || (volatilep
&& flag_strict_volatile_bitfields
> 0
10088 && (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0
10089 || (mode1
!= BLKmode
10090 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)))
10091 /* If the field isn't aligned enough to fetch as a memref,
10092 fetch it as a bit field. */
10093 || (mode1
!= BLKmode
10094 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10095 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10097 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10098 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10099 && modifier
!= EXPAND_MEMORY
10100 && ((modifier
== EXPAND_CONST_ADDRESS
10101 || modifier
== EXPAND_INITIALIZER
)
10103 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10104 || (bitpos
% BITS_PER_UNIT
!= 0)))
10105 /* If the type and the field are a constant size and the
10106 size of the type isn't the same size as the bitfield,
10107 we must use bitfield operations. */
10109 && TYPE_SIZE (TREE_TYPE (exp
))
10110 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10111 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10114 enum machine_mode ext_mode
= mode
;
10116 if (ext_mode
== BLKmode
10117 && ! (target
!= 0 && MEM_P (op0
)
10119 && bitpos
% BITS_PER_UNIT
== 0))
10120 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10122 if (ext_mode
== BLKmode
)
10125 target
= assign_temp (type
, 1, 1);
10130 /* In this case, BITPOS must start at a byte boundary and
10131 TARGET, if specified, must be a MEM. */
10132 gcc_assert (MEM_P (op0
)
10133 && (!target
|| MEM_P (target
))
10134 && !(bitpos
% BITS_PER_UNIT
));
10136 emit_block_move (target
,
10137 adjust_address (op0
, VOIDmode
,
10138 bitpos
/ BITS_PER_UNIT
),
10139 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10141 (modifier
== EXPAND_STACK_PARM
10142 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10147 op0
= validize_mem (op0
);
10149 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10150 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10152 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10153 (modifier
== EXPAND_STACK_PARM
10154 ? NULL_RTX
: target
),
10155 ext_mode
, ext_mode
);
10157 /* If the result is a record type and BITSIZE is narrower than
10158 the mode of OP0, an integral mode, and this is a big endian
10159 machine, we must put the field into the high-order bits. */
10160 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10161 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10162 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10163 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10164 GET_MODE_BITSIZE (GET_MODE (op0
))
10165 - bitsize
, op0
, 1);
10167 /* If the result type is BLKmode, store the data into a temporary
10168 of the appropriate type, but with the mode corresponding to the
10169 mode for the data we have (op0's mode). It's tempting to make
10170 this a constant type, since we know it's only being stored once,
10171 but that can cause problems if we are taking the address of this
10172 COMPONENT_REF because the MEM of any reference via that address
10173 will have flags corresponding to the type, which will not
10174 necessarily be constant. */
10175 if (mode
== BLKmode
)
10179 new_rtx
= assign_stack_temp_for_type (ext_mode
,
10180 GET_MODE_BITSIZE (ext_mode
),
10182 emit_move_insn (new_rtx
, op0
);
10183 op0
= copy_rtx (new_rtx
);
10184 PUT_MODE (op0
, BLKmode
);
10190 /* If the result is BLKmode, use that to access the object
10192 if (mode
== BLKmode
)
10195 /* Get a reference to just this component. */
10196 if (modifier
== EXPAND_CONST_ADDRESS
10197 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10198 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10200 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10202 if (op0
== orig_op0
)
10203 op0
= copy_rtx (op0
);
10205 /* If op0 is a temporary because of forcing to memory, pass only the
10206 type to set_mem_attributes so that the original expression is never
10207 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10208 if (mem_attrs_from_type
)
10209 set_mem_attributes (op0
, type
, 0);
10211 set_mem_attributes (op0
, exp
, 0);
10213 if (REG_P (XEXP (op0
, 0)))
10214 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10216 MEM_VOLATILE_P (op0
) |= volatilep
;
10217 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10218 || modifier
== EXPAND_CONST_ADDRESS
10219 || modifier
== EXPAND_INITIALIZER
)
10223 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10225 convert_move (target
, op0
, unsignedp
);
10230 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10233 /* All valid uses of __builtin_va_arg_pack () are removed during
10235 if (CALL_EXPR_VA_ARG_PACK (exp
))
10236 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10238 tree fndecl
= get_callee_fndecl (exp
), attr
;
10241 && (attr
= lookup_attribute ("error",
10242 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10243 error ("%Kcall to %qs declared with attribute error: %s",
10244 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10245 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10247 && (attr
= lookup_attribute ("warning",
10248 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10249 warning_at (tree_nonartificial_location (exp
),
10250 0, "%Kcall to %qs declared with attribute warning: %s",
10251 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10252 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10254 /* Check for a built-in function. */
10255 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10257 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10258 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10261 return expand_call (exp
, target
, ignore
);
10263 case VIEW_CONVERT_EXPR
:
10266 /* If we are converting to BLKmode, try to avoid an intermediate
10267 temporary by fetching an inner memory reference. */
10268 if (mode
== BLKmode
10269 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10270 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10271 && handled_component_p (treeop0
))
10273 enum machine_mode mode1
;
10274 HOST_WIDE_INT bitsize
, bitpos
;
10279 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10280 &offset
, &mode1
, &unsignedp
, &volatilep
,
10284 /* ??? We should work harder and deal with non-zero offsets. */
10286 && (bitpos
% BITS_PER_UNIT
) == 0
10288 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10290 /* See the normal_inner_ref case for the rationale. */
10292 = expand_expr (tem
,
10293 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10294 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10296 && modifier
!= EXPAND_STACK_PARM
10297 ? target
: NULL_RTX
),
10299 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
10301 if (MEM_P (orig_op0
))
10305 /* Get a reference to just this component. */
10306 if (modifier
== EXPAND_CONST_ADDRESS
10307 || modifier
== EXPAND_SUM
10308 || modifier
== EXPAND_INITIALIZER
)
10309 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10311 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10313 if (op0
== orig_op0
)
10314 op0
= copy_rtx (op0
);
10316 set_mem_attributes (op0
, treeop0
, 0);
10317 if (REG_P (XEXP (op0
, 0)))
10318 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10320 MEM_VOLATILE_P (op0
) |= volatilep
;
10326 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
10328 /* If the input and output modes are both the same, we are done. */
10329 if (mode
== GET_MODE (op0
))
10331 /* If neither mode is BLKmode, and both modes are the same size
10332 then we can use gen_lowpart. */
10333 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10334 && (GET_MODE_PRECISION (mode
)
10335 == GET_MODE_PRECISION (GET_MODE (op0
)))
10336 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10338 if (GET_CODE (op0
) == SUBREG
)
10339 op0
= force_reg (GET_MODE (op0
), op0
);
10340 temp
= gen_lowpart_common (mode
, op0
);
10345 if (!REG_P (op0
) && !MEM_P (op0
))
10346 op0
= force_reg (GET_MODE (op0
), op0
);
10347 op0
= gen_lowpart (mode
, op0
);
10350 /* If both types are integral, convert from one mode to the other. */
10351 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10352 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10353 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10354 /* As a last resort, spill op0 to memory, and reload it in a
10356 else if (!MEM_P (op0
))
10358 /* If the operand is not a MEM, force it into memory. Since we
10359 are going to be changing the mode of the MEM, don't call
10360 force_const_mem for constants because we don't allow pool
10361 constants to change mode. */
10362 tree inner_type
= TREE_TYPE (treeop0
);
10364 gcc_assert (!TREE_ADDRESSABLE (exp
));
10366 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10368 = assign_stack_temp_for_type
10369 (TYPE_MODE (inner_type
),
10370 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10372 emit_move_insn (target
, op0
);
10376 /* At this point, OP0 is in the correct mode. If the output type is
10377 such that the operand is known to be aligned, indicate that it is.
10378 Otherwise, we need only be concerned about alignment for non-BLKmode
10382 enum insn_code icode
;
10384 if (TYPE_ALIGN_OK (type
))
10386 /* ??? Copying the MEM without substantially changing it might
10387 run afoul of the code handling volatile memory references in
10388 store_expr, which assumes that TARGET is returned unmodified
10389 if it has been used. */
10390 op0
= copy_rtx (op0
);
10391 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10393 else if (mode
!= BLKmode
10394 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
)
10395 /* If the target does have special handling for unaligned
10396 loads of mode then use them. */
10397 && ((icode
= optab_handler (movmisalign_optab
, mode
))
10398 != CODE_FOR_nothing
))
10402 op0
= adjust_address (op0
, mode
, 0);
10403 /* We've already validated the memory, and we're creating a
10404 new pseudo destination. The predicates really can't
10406 reg
= gen_reg_rtx (mode
);
10408 /* Nor can the insn generator. */
10409 insn
= GEN_FCN (icode
) (reg
, op0
);
10413 else if (STRICT_ALIGNMENT
10415 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10417 tree inner_type
= TREE_TYPE (treeop0
);
10418 HOST_WIDE_INT temp_size
10419 = MAX (int_size_in_bytes (inner_type
),
10420 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10422 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10423 rtx new_with_op0_mode
10424 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10426 gcc_assert (!TREE_ADDRESSABLE (exp
));
10428 if (GET_MODE (op0
) == BLKmode
)
10429 emit_block_move (new_with_op0_mode
, op0
,
10430 GEN_INT (GET_MODE_SIZE (mode
)),
10431 (modifier
== EXPAND_STACK_PARM
10432 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10434 emit_move_insn (new_with_op0_mode
, op0
);
10439 op0
= adjust_address (op0
, mode
, 0);
10446 tree lhs
= treeop0
;
10447 tree rhs
= treeop1
;
10448 gcc_assert (ignore
);
10450 /* Check for |= or &= of a bitfield of size one into another bitfield
10451 of size 1. In this case, (unless we need the result of the
10452 assignment) we can do this more efficiently with a
10453 test followed by an assignment, if necessary.
10455 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10456 things change so we do, this code should be enhanced to
10458 if (TREE_CODE (lhs
) == COMPONENT_REF
10459 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10460 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10461 && TREE_OPERAND (rhs
, 0) == lhs
10462 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10463 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10464 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10466 rtx label
= gen_label_rtx ();
10467 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10468 do_jump (TREE_OPERAND (rhs
, 1),
10470 value
? 0 : label
, -1);
10471 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10473 do_pending_stack_adjust ();
10474 emit_label (label
);
10478 expand_assignment (lhs
, rhs
, false);
10483 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10485 case REALPART_EXPR
:
10486 op0
= expand_normal (treeop0
);
10487 return read_complex_part (op0
, false);
10489 case IMAGPART_EXPR
:
10490 op0
= expand_normal (treeop0
);
10491 return read_complex_part (op0
, true);
10498 /* Expanded in cfgexpand.c. */
10499 gcc_unreachable ();
10501 case TRY_CATCH_EXPR
:
10503 case EH_FILTER_EXPR
:
10504 case TRY_FINALLY_EXPR
:
10505 /* Lowered by tree-eh.c. */
10506 gcc_unreachable ();
10508 case WITH_CLEANUP_EXPR
:
10509 case CLEANUP_POINT_EXPR
:
10511 case CASE_LABEL_EXPR
:
10516 case COMPOUND_EXPR
:
10517 case PREINCREMENT_EXPR
:
10518 case PREDECREMENT_EXPR
:
10519 case POSTINCREMENT_EXPR
:
10520 case POSTDECREMENT_EXPR
:
10523 case COMPOUND_LITERAL_EXPR
:
10524 /* Lowered by gimplify.c. */
10525 gcc_unreachable ();
10528 /* Function descriptors are not valid except for as
10529 initialization constants, and should not be expanded. */
10530 gcc_unreachable ();
10532 case WITH_SIZE_EXPR
:
10533 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10534 have pulled out the size to use in whatever context it needed. */
10535 return expand_expr_real (treeop0
, original_target
, tmode
,
10536 modifier
, alt_rtl
);
10539 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10543 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10544 signedness of TYPE), possibly returning the result in TARGET. */
10546 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10548 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10549 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10551 /* For constant values, reduce using build_int_cst_type. */
10552 if (CONST_INT_P (exp
))
10554 HOST_WIDE_INT value
= INTVAL (exp
);
10555 tree t
= build_int_cst_type (type
, value
);
10556 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10558 else if (TYPE_UNSIGNED (type
))
10560 rtx mask
= immed_double_int_const (double_int::mask (prec
),
10562 return expand_and (GET_MODE (exp
), exp
, mask
, target
);
10566 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10567 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10568 exp
, count
, target
, 0);
10569 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10570 exp
, count
, target
, 0);
10574 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10575 when applied to the address of EXP produces an address known to be
10576 aligned more than BIGGEST_ALIGNMENT. */
10579 is_aligning_offset (const_tree offset
, const_tree exp
)
10581 /* Strip off any conversions. */
10582 while (CONVERT_EXPR_P (offset
))
10583 offset
= TREE_OPERAND (offset
, 0);
10585 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10586 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10587 if (TREE_CODE (offset
) != BIT_AND_EXPR
10588 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
10589 || compare_tree_int (TREE_OPERAND (offset
, 1),
10590 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10591 || !exact_log2 (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1) < 0)
10594 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10595 It must be NEGATE_EXPR. Then strip any more conversions. */
10596 offset
= TREE_OPERAND (offset
, 0);
10597 while (CONVERT_EXPR_P (offset
))
10598 offset
= TREE_OPERAND (offset
, 0);
10600 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10603 offset
= TREE_OPERAND (offset
, 0);
10604 while (CONVERT_EXPR_P (offset
))
10605 offset
= TREE_OPERAND (offset
, 0);
10607 /* This must now be the address of EXP. */
10608 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10611 /* Return the tree node if an ARG corresponds to a string constant or zero
10612 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10613 in bytes within the string that ARG is accessing. The type of the
10614 offset will be `sizetype'. */
10617 string_constant (tree arg
, tree
*ptr_offset
)
10619 tree array
, offset
, lower_bound
;
10622 if (TREE_CODE (arg
) == ADDR_EXPR
)
10624 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10626 *ptr_offset
= size_zero_node
;
10627 return TREE_OPERAND (arg
, 0);
10629 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10631 array
= TREE_OPERAND (arg
, 0);
10632 offset
= size_zero_node
;
10634 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10636 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10637 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10638 if (TREE_CODE (array
) != STRING_CST
10639 && TREE_CODE (array
) != VAR_DECL
)
10642 /* Check if the array has a nonzero lower bound. */
10643 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10644 if (!integer_zerop (lower_bound
))
10646 /* If the offset and base aren't both constants, return 0. */
10647 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10649 if (TREE_CODE (offset
) != INTEGER_CST
)
10651 /* Adjust offset by the lower bound. */
10652 offset
= size_diffop (fold_convert (sizetype
, offset
),
10653 fold_convert (sizetype
, lower_bound
));
10656 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10658 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10659 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10660 if (TREE_CODE (array
) != ADDR_EXPR
)
10662 array
= TREE_OPERAND (array
, 0);
10663 if (TREE_CODE (array
) != STRING_CST
10664 && TREE_CODE (array
) != VAR_DECL
)
10670 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10672 tree arg0
= TREE_OPERAND (arg
, 0);
10673 tree arg1
= TREE_OPERAND (arg
, 1);
10678 if (TREE_CODE (arg0
) == ADDR_EXPR
10679 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10680 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10682 array
= TREE_OPERAND (arg0
, 0);
10685 else if (TREE_CODE (arg1
) == ADDR_EXPR
10686 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10687 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10689 array
= TREE_OPERAND (arg1
, 0);
10698 if (TREE_CODE (array
) == STRING_CST
)
10700 *ptr_offset
= fold_convert (sizetype
, offset
);
10703 else if (TREE_CODE (array
) == VAR_DECL
10704 || TREE_CODE (array
) == CONST_DECL
)
10707 tree init
= ctor_for_folding (array
);
10709 /* Variables initialized to string literals can be handled too. */
10710 if (init
== error_mark_node
10712 || TREE_CODE (init
) != STRING_CST
)
10715 /* Avoid const char foo[4] = "abcde"; */
10716 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10717 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10718 || (length
= TREE_STRING_LENGTH (init
)) <= 0
10719 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10722 /* If variable is bigger than the string literal, OFFSET must be constant
10723 and inside of the bounds of the string literal. */
10724 offset
= fold_convert (sizetype
, offset
);
10725 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10726 && (! tree_fits_uhwi_p (offset
)
10727 || compare_tree_int (offset
, length
) >= 0))
10730 *ptr_offset
= offset
;
10737 /* Generate code to calculate OPS, and exploded expression
10738 using a store-flag instruction and return an rtx for the result.
10739 OPS reflects a comparison.
10741 If TARGET is nonzero, store the result there if convenient.
10743 Return zero if there is no suitable set-flag instruction
10744 available on this machine.
10746 Once expand_expr has been called on the arguments of the comparison,
10747 we are committed to doing the store flag, since it is not safe to
10748 re-evaluate the expression. We emit the store-flag insn by calling
10749 emit_store_flag, but only expand the arguments if we have a reason
10750 to believe that emit_store_flag will be successful. If we think that
10751 it will, but it isn't, we have to simulate the store-flag with a
10752 set/jump/set sequence. */
10755 do_store_flag (sepops ops
, rtx target
, enum machine_mode mode
)
10757 enum rtx_code code
;
10758 tree arg0
, arg1
, type
;
10760 enum machine_mode operand_mode
;
10763 rtx subtarget
= target
;
10764 location_t loc
= ops
->location
;
10769 /* Don't crash if the comparison was erroneous. */
10770 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10773 type
= TREE_TYPE (arg0
);
10774 operand_mode
= TYPE_MODE (type
);
10775 unsignedp
= TYPE_UNSIGNED (type
);
10777 /* We won't bother with BLKmode store-flag operations because it would mean
10778 passing a lot of information to emit_store_flag. */
10779 if (operand_mode
== BLKmode
)
10782 /* We won't bother with store-flag operations involving function pointers
10783 when function pointers must be canonicalized before comparisons. */
10784 #ifdef HAVE_canonicalize_funcptr_for_compare
10785 if (HAVE_canonicalize_funcptr_for_compare
10786 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10787 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10789 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10790 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10791 == FUNCTION_TYPE
))))
10798 /* For vector typed comparisons emit code to generate the desired
10799 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10800 expander for this. */
10801 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10803 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10804 tree if_true
= constant_boolean_node (true, ops
->type
);
10805 tree if_false
= constant_boolean_node (false, ops
->type
);
10806 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10809 /* Get the rtx comparison code to use. We know that EXP is a comparison
10810 operation of some type. Some comparisons against 1 and -1 can be
10811 converted to comparisons with zero. Do so here so that the tests
10812 below will be aware that we have a comparison with zero. These
10813 tests will not catch constants in the first operand, but constants
10814 are rarely passed as the first operand. */
10825 if (integer_onep (arg1
))
10826 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
10828 code
= unsignedp
? LTU
: LT
;
10831 if (! unsignedp
&& integer_all_onesp (arg1
))
10832 arg1
= integer_zero_node
, code
= LT
;
10834 code
= unsignedp
? LEU
: LE
;
10837 if (! unsignedp
&& integer_all_onesp (arg1
))
10838 arg1
= integer_zero_node
, code
= GE
;
10840 code
= unsignedp
? GTU
: GT
;
10843 if (integer_onep (arg1
))
10844 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
10846 code
= unsignedp
? GEU
: GE
;
10849 case UNORDERED_EXPR
:
10875 gcc_unreachable ();
10878 /* Put a constant second. */
10879 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
10880 || TREE_CODE (arg0
) == FIXED_CST
)
10882 tem
= arg0
; arg0
= arg1
; arg1
= tem
;
10883 code
= swap_condition (code
);
10886 /* If this is an equality or inequality test of a single bit, we can
10887 do this by shifting the bit being tested to the low-order bit and
10888 masking the result with the constant 1. If the condition was EQ,
10889 we xor it with 1. This does not require an scc insn and is faster
10890 than an scc insn even if we have it.
10892 The code to make this transformation was moved into fold_single_bit_test,
10893 so we just call into the folder and expand its result. */
10895 if ((code
== NE
|| code
== EQ
)
10896 && integer_zerop (arg1
)
10897 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
10899 gimple srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
10901 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
10903 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
10904 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10905 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
10906 gimple_assign_rhs1 (srcstmt
),
10907 gimple_assign_rhs2 (srcstmt
));
10908 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
10910 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
10914 if (! get_subtarget (target
)
10915 || GET_MODE (subtarget
) != operand_mode
)
10918 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10921 target
= gen_reg_rtx (mode
);
10923 /* Try a cstore if possible. */
10924 return emit_store_flag_force (target
, code
, op0
, op1
,
10925 operand_mode
, unsignedp
,
10926 (TYPE_PRECISION (ops
->type
) == 1
10927 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
10931 /* Stubs in case we haven't got a casesi insn. */
10932 #ifndef HAVE_casesi
10933 # define HAVE_casesi 0
10934 # define gen_casesi(a, b, c, d, e) (0)
10935 # define CODE_FOR_casesi CODE_FOR_nothing
10938 /* Attempt to generate a casesi instruction. Returns 1 if successful,
10939 0 otherwise (i.e. if there is no casesi instruction).
10941 DEFAULT_PROBABILITY is the probability of jumping to the default
10944 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
10945 rtx table_label
, rtx default_label
, rtx fallback_label
,
10946 int default_probability
)
10948 struct expand_operand ops
[5];
10949 enum machine_mode index_mode
= SImode
;
10950 rtx op1
, op2
, index
;
10955 /* Convert the index to SImode. */
10956 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
10958 enum machine_mode omode
= TYPE_MODE (index_type
);
10959 rtx rangertx
= expand_normal (range
);
10961 /* We must handle the endpoints in the original mode. */
10962 index_expr
= build2 (MINUS_EXPR
, index_type
,
10963 index_expr
, minval
);
10964 minval
= integer_zero_node
;
10965 index
= expand_normal (index_expr
);
10967 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
10968 omode
, 1, default_label
,
10969 default_probability
);
10970 /* Now we can safely truncate. */
10971 index
= convert_to_mode (index_mode
, index
, 0);
10975 if (TYPE_MODE (index_type
) != index_mode
)
10977 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
10978 index_expr
= fold_convert (index_type
, index_expr
);
10981 index
= expand_normal (index_expr
);
10984 do_pending_stack_adjust ();
10986 op1
= expand_normal (minval
);
10987 op2
= expand_normal (range
);
10989 create_input_operand (&ops
[0], index
, index_mode
);
10990 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
10991 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
10992 create_fixed_operand (&ops
[3], table_label
);
10993 create_fixed_operand (&ops
[4], (default_label
10995 : fallback_label
));
10996 expand_jump_insn (CODE_FOR_casesi
, 5, ops
);
11000 /* Attempt to generate a tablejump instruction; same concept. */
11001 #ifndef HAVE_tablejump
11002 #define HAVE_tablejump 0
11003 #define gen_tablejump(x, y) (0)
11006 /* Subroutine of the next function.
11008 INDEX is the value being switched on, with the lowest value
11009 in the table already subtracted.
11010 MODE is its expected mode (needed if INDEX is constant).
11011 RANGE is the length of the jump table.
11012 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11014 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11015 index value is out of range.
11016 DEFAULT_PROBABILITY is the probability of jumping to
11017 the default label. */
11020 do_tablejump (rtx index
, enum machine_mode mode
, rtx range
, rtx table_label
,
11021 rtx default_label
, int default_probability
)
11025 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11026 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11028 /* Do an unsigned comparison (in the proper mode) between the index
11029 expression and the value which represents the length of the range.
11030 Since we just finished subtracting the lower bound of the range
11031 from the index expression, this comparison allows us to simultaneously
11032 check that the original index expression value is both greater than
11033 or equal to the minimum value of the range and less than or equal to
11034 the maximum value of the range. */
11037 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11038 default_label
, default_probability
);
11041 /* If index is in range, it must fit in Pmode.
11042 Convert to Pmode so we can index with it. */
11044 index
= convert_to_mode (Pmode
, index
, 1);
11046 /* Don't let a MEM slip through, because then INDEX that comes
11047 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11048 and break_out_memory_refs will go to work on it and mess it up. */
11049 #ifdef PIC_CASE_VECTOR_ADDRESS
11050 if (flag_pic
&& !REG_P (index
))
11051 index
= copy_to_mode_reg (Pmode
, index
);
11054 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11055 GET_MODE_SIZE, because this indicates how large insns are. The other
11056 uses should all be Pmode, because they are addresses. This code
11057 could fail if addresses and insns are not the same size. */
11058 index
= gen_rtx_PLUS
11060 gen_rtx_MULT (Pmode
, index
,
11061 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
), Pmode
)),
11062 gen_rtx_LABEL_REF (Pmode
, table_label
));
11063 #ifdef PIC_CASE_VECTOR_ADDRESS
11065 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11068 index
= memory_address (CASE_VECTOR_MODE
, index
);
11069 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11070 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11071 convert_move (temp
, vector
, 0);
11073 emit_jump_insn (gen_tablejump (temp
, table_label
));
11075 /* If we are generating PIC code or if the table is PC-relative, the
11076 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11077 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11082 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11083 rtx table_label
, rtx default_label
, int default_probability
)
11087 if (! HAVE_tablejump
)
11090 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11091 fold_convert (index_type
, index_expr
),
11092 fold_convert (index_type
, minval
));
11093 index
= expand_normal (index_expr
);
11094 do_pending_stack_adjust ();
11096 do_tablejump (index
, TYPE_MODE (index_type
),
11097 convert_modes (TYPE_MODE (index_type
),
11098 TYPE_MODE (TREE_TYPE (range
)),
11099 expand_normal (range
),
11100 TYPE_UNSIGNED (TREE_TYPE (range
))),
11101 table_label
, default_label
, default_probability
);
11105 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11107 const_vector_from_tree (tree exp
)
11113 enum machine_mode inner
, mode
;
11115 mode
= TYPE_MODE (TREE_TYPE (exp
));
11117 if (initializer_zerop (exp
))
11118 return CONST0_RTX (mode
);
11120 units
= GET_MODE_NUNITS (mode
);
11121 inner
= GET_MODE_INNER (mode
);
11123 v
= rtvec_alloc (units
);
11125 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11127 elt
= VECTOR_CST_ELT (exp
, i
);
11129 if (TREE_CODE (elt
) == REAL_CST
)
11130 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11132 else if (TREE_CODE (elt
) == FIXED_CST
)
11133 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11136 RTVEC_ELT (v
, i
) = immed_double_int_const (tree_to_double_int (elt
),
11140 return gen_rtx_CONST_VECTOR (mode
, v
);
11143 /* Build a decl for a personality function given a language prefix. */
11146 build_personality_function (const char *lang
)
11148 const char *unwind_and_version
;
11152 switch (targetm_common
.except_unwind_info (&global_options
))
11157 unwind_and_version
= "_sj0";
11161 unwind_and_version
= "_v0";
11164 unwind_and_version
= "_seh0";
11167 gcc_unreachable ();
11170 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11172 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11173 long_long_unsigned_type_node
,
11174 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11175 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11176 get_identifier (name
), type
);
11177 DECL_ARTIFICIAL (decl
) = 1;
11178 DECL_EXTERNAL (decl
) = 1;
11179 TREE_PUBLIC (decl
) = 1;
11181 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11182 are the flags assigned by targetm.encode_section_info. */
11183 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11188 /* Extracts the personality function of DECL and returns the corresponding
11192 get_personality_function (tree decl
)
11194 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11195 enum eh_personality_kind pk
;
11197 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11198 if (pk
== eh_personality_none
)
11202 && pk
== eh_personality_any
)
11203 personality
= lang_hooks
.eh_personality ();
11205 if (pk
== eh_personality_lang
)
11206 gcc_assert (personality
!= NULL_TREE
);
11208 return XEXP (DECL_RTL (personality
), 0);
11211 #include "gt-expr.h"