1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988-2014 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"
40 #include "insn-config.h"
41 #include "insn-attr.h"
42 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
44 #include "insn-codes.h"
49 #include "typeclass.h"
51 #include "langhooks.h"
54 #include "tree-iterator.h"
56 #include "dominance.h"
58 #include "basic-block.h"
59 #include "tree-ssa-alias.h"
60 #include "internal-fn.h"
61 #include "gimple-expr.h"
64 #include "gimple-ssa.h"
66 #include "plugin-api.h"
69 #include "tree-ssanames.h"
71 #include "common/common-target.h"
74 #include "diagnostic.h"
75 #include "tree-ssa-live.h"
76 #include "tree-outof-ssa.h"
77 #include "target-globals.h"
79 #include "tree-ssa-address.h"
80 #include "cfgexpand.h"
83 #ifndef STACK_PUSH_CODE
84 #ifdef STACK_GROWS_DOWNWARD
85 #define STACK_PUSH_CODE PRE_DEC
87 #define STACK_PUSH_CODE PRE_INC
92 /* If this is nonzero, we do not bother generating VOLATILE
93 around volatile memory references, and we are willing to
94 output indirect addresses. If cse is to follow, we reject
95 indirect addresses so a useful potential cse is generated;
96 if it is used only once, instruction combination will produce
97 the same indirect address eventually. */
100 /* This structure is used by move_by_pieces to describe the move to
102 struct move_by_pieces_d
111 int explicit_inc_from
;
112 unsigned HOST_WIDE_INT len
;
113 HOST_WIDE_INT offset
;
117 /* This structure is used by store_by_pieces to describe the clear to
120 struct store_by_pieces_d
126 unsigned HOST_WIDE_INT len
;
127 HOST_WIDE_INT offset
;
128 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
);
133 static void move_by_pieces_1 (insn_gen_fn
, machine_mode
,
134 struct move_by_pieces_d
*);
135 static bool block_move_libcall_safe_for_call_parm (void);
136 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned, unsigned, HOST_WIDE_INT
,
137 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
138 unsigned HOST_WIDE_INT
);
139 static tree
emit_block_move_libcall_fn (int);
140 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
141 static rtx
clear_by_pieces_1 (void *, HOST_WIDE_INT
, machine_mode
);
142 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
143 static void store_by_pieces_1 (struct store_by_pieces_d
*, unsigned int);
144 static void store_by_pieces_2 (insn_gen_fn
, machine_mode
,
145 struct store_by_pieces_d
*);
146 static tree
clear_storage_libcall_fn (int);
147 static rtx_insn
*compress_float_constant (rtx
, rtx
);
148 static rtx
get_subtarget (rtx
);
149 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
150 HOST_WIDE_INT
, machine_mode
,
151 tree
, int, alias_set_type
);
152 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
);
153 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
,
154 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
155 machine_mode
, tree
, alias_set_type
, bool);
157 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
159 static int is_aligning_offset (const_tree
, const_tree
);
160 static void expand_operands (tree
, tree
, rtx
, rtx
*, rtx
*,
161 enum expand_modifier
);
162 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
163 static rtx
do_store_flag (sepops
, rtx
, machine_mode
);
165 static void emit_single_push_insn (machine_mode
, rtx
, tree
);
167 static void do_tablejump (rtx
, machine_mode
, rtx
, rtx
, rtx
, int);
168 static rtx
const_vector_from_tree (tree
);
169 static void write_complex_part (rtx
, rtx
, bool);
172 /* This is run to set up which modes can be used
173 directly in memory and to initialize the block move optab. It is run
174 at the beginning of compilation and when the target is reinitialized. */
177 init_expr_target (void)
185 /* Try indexing by frame ptr and try by stack ptr.
186 It is known that on the Convex the stack ptr isn't a valid index.
187 With luck, one or the other is valid on any machine. */
188 mem
= gen_rtx_MEM (VOIDmode
, stack_pointer_rtx
);
189 mem1
= gen_rtx_MEM (VOIDmode
, frame_pointer_rtx
);
191 /* A scratch register we can modify in-place below to avoid
192 useless RTL allocations. */
193 reg
= gen_rtx_REG (VOIDmode
, -1);
195 insn
= rtx_alloc (INSN
);
196 pat
= gen_rtx_SET (VOIDmode
, NULL_RTX
, NULL_RTX
);
197 PATTERN (insn
) = pat
;
199 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
200 mode
= (machine_mode
) ((int) mode
+ 1))
204 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
205 PUT_MODE (mem
, mode
);
206 PUT_MODE (mem1
, mode
);
207 PUT_MODE (reg
, mode
);
209 /* See if there is some register that can be used in this mode and
210 directly loaded or stored from memory. */
212 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
213 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
214 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
217 if (! HARD_REGNO_MODE_OK (regno
, mode
))
220 SET_REGNO (reg
, regno
);
223 SET_DEST (pat
) = reg
;
224 if (recog (pat
, insn
, &num_clobbers
) >= 0)
225 direct_load
[(int) mode
] = 1;
227 SET_SRC (pat
) = mem1
;
228 SET_DEST (pat
) = reg
;
229 if (recog (pat
, insn
, &num_clobbers
) >= 0)
230 direct_load
[(int) mode
] = 1;
233 SET_DEST (pat
) = mem
;
234 if (recog (pat
, insn
, &num_clobbers
) >= 0)
235 direct_store
[(int) mode
] = 1;
238 SET_DEST (pat
) = mem1
;
239 if (recog (pat
, insn
, &num_clobbers
) >= 0)
240 direct_store
[(int) mode
] = 1;
244 mem
= gen_rtx_MEM (VOIDmode
, gen_rtx_raw_REG (Pmode
, 10000));
246 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
247 mode
= GET_MODE_WIDER_MODE (mode
))
249 machine_mode srcmode
;
250 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
251 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
255 ic
= can_extend_p (mode
, srcmode
, 0);
256 if (ic
== CODE_FOR_nothing
)
259 PUT_MODE (mem
, srcmode
);
261 if (insn_operand_matches (ic
, 1, mem
))
262 float_extend_from_mem
[mode
][srcmode
] = true;
267 /* This is run at the start of compiling a function. */
272 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
275 /* Copy data from FROM to TO, where the machine modes are not the same.
276 Both modes may be integer, or both may be floating, or both may be
278 UNSIGNEDP should be nonzero if FROM is an unsigned type.
279 This causes zero-extension instead of sign-extension. */
282 convert_move (rtx to
, rtx from
, int unsignedp
)
284 machine_mode to_mode
= GET_MODE (to
);
285 machine_mode from_mode
= GET_MODE (from
);
286 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
287 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
291 /* rtx code for making an equivalent value. */
292 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
293 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
296 gcc_assert (to_real
== from_real
);
297 gcc_assert (to_mode
!= BLKmode
);
298 gcc_assert (from_mode
!= BLKmode
);
300 /* If the source and destination are already the same, then there's
305 /* If FROM is a SUBREG that indicates that we have already done at least
306 the required extension, strip it. We don't handle such SUBREGs as
309 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
310 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
311 >= GET_MODE_PRECISION (to_mode
))
312 && SUBREG_CHECK_PROMOTED_SIGN (from
, unsignedp
))
313 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
315 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
317 if (to_mode
== from_mode
318 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
320 emit_move_insn (to
, from
);
324 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
326 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
328 if (VECTOR_MODE_P (to_mode
))
329 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
331 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
333 emit_move_insn (to
, from
);
337 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
339 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
340 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
350 gcc_assert ((GET_MODE_PRECISION (from_mode
)
351 != GET_MODE_PRECISION (to_mode
))
352 || (DECIMAL_FLOAT_MODE_P (from_mode
)
353 != DECIMAL_FLOAT_MODE_P (to_mode
)));
355 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
356 /* Conversion between decimal float and binary float, same size. */
357 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
358 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
363 /* Try converting directly if the insn is supported. */
365 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
366 if (code
!= CODE_FOR_nothing
)
368 emit_unop_insn (code
, to
, from
,
369 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
373 /* Otherwise use a libcall. */
374 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
376 /* Is this conversion implemented yet? */
377 gcc_assert (libcall
);
380 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
382 insns
= get_insns ();
384 emit_libcall_block (insns
, to
, value
,
385 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
387 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
391 /* Handle pointer conversion. */ /* SPEE 900220. */
392 /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
396 if (GET_MODE_PRECISION (from_mode
) > GET_MODE_PRECISION (to_mode
))
403 if (convert_optab_handler (ctab
, to_mode
, from_mode
)
406 emit_unop_insn (convert_optab_handler (ctab
, to_mode
, from_mode
),
412 /* Targets are expected to provide conversion insns between PxImode and
413 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
414 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
416 machine_mode full_mode
417 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
419 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
420 != CODE_FOR_nothing
);
422 if (full_mode
!= from_mode
)
423 from
= convert_to_mode (full_mode
, from
, unsignedp
);
424 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
428 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
431 machine_mode full_mode
432 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
433 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
434 enum insn_code icode
;
436 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
437 gcc_assert (icode
!= CODE_FOR_nothing
);
439 if (to_mode
== full_mode
)
441 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
445 new_from
= gen_reg_rtx (full_mode
);
446 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
448 /* else proceed to integer conversions below. */
449 from_mode
= full_mode
;
453 /* Make sure both are fixed-point modes or both are not. */
454 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
455 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
456 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
458 /* If we widen from_mode to to_mode and they are in the same class,
459 we won't saturate the result.
460 Otherwise, always saturate the result to play safe. */
461 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
462 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
463 expand_fixed_convert (to
, from
, 0, 0);
465 expand_fixed_convert (to
, from
, 0, 1);
469 /* Now both modes are integers. */
471 /* Handle expanding beyond a word. */
472 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
473 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
480 machine_mode lowpart_mode
;
481 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
483 /* Try converting directly if the insn is supported. */
484 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
487 /* If FROM is a SUBREG, put it into a register. Do this
488 so that we always generate the same set of insns for
489 better cse'ing; if an intermediate assignment occurred,
490 we won't be doing the operation directly on the SUBREG. */
491 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
492 from
= force_reg (from_mode
, from
);
493 emit_unop_insn (code
, to
, from
, equiv_code
);
496 /* Next, try converting via full word. */
497 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
498 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
499 != CODE_FOR_nothing
))
501 rtx word_to
= gen_reg_rtx (word_mode
);
504 if (reg_overlap_mentioned_p (to
, from
))
505 from
= force_reg (from_mode
, from
);
508 convert_move (word_to
, from
, unsignedp
);
509 emit_unop_insn (code
, to
, word_to
, equiv_code
);
513 /* No special multiword conversion insn; do it by hand. */
516 /* Since we will turn this into a no conflict block, we must ensure the
517 the source does not overlap the target so force it into an isolated
518 register when maybe so. Likewise for any MEM input, since the
519 conversion sequence might require several references to it and we
520 must ensure we're getting the same value every time. */
522 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
523 from
= force_reg (from_mode
, from
);
525 /* Get a copy of FROM widened to a word, if necessary. */
526 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
527 lowpart_mode
= word_mode
;
529 lowpart_mode
= from_mode
;
531 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
533 lowpart
= gen_lowpart (lowpart_mode
, to
);
534 emit_move_insn (lowpart
, lowfrom
);
536 /* Compute the value to put in each remaining word. */
538 fill_value
= const0_rtx
;
540 fill_value
= emit_store_flag_force (gen_reg_rtx (word_mode
),
541 LT
, lowfrom
, const0_rtx
,
542 lowpart_mode
, 0, -1);
544 /* Fill the remaining words. */
545 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
547 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
548 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
550 gcc_assert (subword
);
552 if (fill_value
!= subword
)
553 emit_move_insn (subword
, fill_value
);
556 insns
= get_insns ();
563 /* Truncating multi-word to a word or less. */
564 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
565 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
568 && ! MEM_VOLATILE_P (from
)
569 && direct_load
[(int) to_mode
]
570 && ! mode_dependent_address_p (XEXP (from
, 0),
571 MEM_ADDR_SPACE (from
)))
573 || GET_CODE (from
) == SUBREG
))
574 from
= force_reg (from_mode
, from
);
575 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
579 /* Now follow all the conversions between integers
580 no more than a word long. */
582 /* For truncation, usually we can just refer to FROM in a narrower mode. */
583 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
584 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
587 && ! MEM_VOLATILE_P (from
)
588 && direct_load
[(int) to_mode
]
589 && ! mode_dependent_address_p (XEXP (from
, 0),
590 MEM_ADDR_SPACE (from
)))
592 || GET_CODE (from
) == SUBREG
))
593 from
= force_reg (from_mode
, from
);
594 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
595 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
596 from
= copy_to_reg (from
);
597 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
601 /* Handle extension. */
602 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
604 /* Convert directly if that works. */
605 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
608 emit_unop_insn (code
, to
, from
, equiv_code
);
613 machine_mode intermediate
;
617 /* Search for a mode to convert via. */
618 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
619 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
620 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
622 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
623 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
624 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
625 != CODE_FOR_nothing
))
627 convert_move (to
, convert_to_mode (intermediate
, from
,
628 unsignedp
), unsignedp
);
632 /* No suitable intermediate mode.
633 Generate what we need with shifts. */
634 shift_amount
= (GET_MODE_PRECISION (to_mode
)
635 - GET_MODE_PRECISION (from_mode
));
636 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
637 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
639 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
642 emit_move_insn (to
, tmp
);
647 /* Support special truncate insns for certain modes. */
648 if (convert_optab_handler (trunc_optab
, to_mode
,
649 from_mode
) != CODE_FOR_nothing
)
651 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
656 /* Handle truncation of volatile memrefs, and so on;
657 the things that couldn't be truncated directly,
658 and for which there was no special instruction.
660 ??? Code above formerly short-circuited this, for most integer
661 mode pairs, with a force_reg in from_mode followed by a recursive
662 call to this routine. Appears always to have been wrong. */
663 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
665 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
666 emit_move_insn (to
, temp
);
670 /* Mode combination is not recognized. */
674 /* Return an rtx for a value that would result
675 from converting X to mode MODE.
676 Both X and MODE may be floating, or both integer.
677 UNSIGNEDP is nonzero if X is an unsigned value.
678 This can be done by referring to a part of X in place
679 or by copying to a new temporary with conversion. */
682 convert_to_mode (machine_mode mode
, rtx x
, int unsignedp
)
684 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
687 /* Return an rtx for a value that would result
688 from converting X from mode OLDMODE to mode MODE.
689 Both modes may be floating, or both integer.
690 UNSIGNEDP is nonzero if X is an unsigned value.
692 This can be done by referring to a part of X in place
693 or by copying to a new temporary with conversion.
695 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
698 convert_modes (machine_mode mode
, machine_mode oldmode
, rtx x
, int unsignedp
)
702 /* If FROM is a SUBREG that indicates that we have already done at least
703 the required extension, strip it. */
705 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
706 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
707 && SUBREG_CHECK_PROMOTED_SIGN (x
, unsignedp
))
708 x
= gen_lowpart (mode
, SUBREG_REG (x
));
710 if (GET_MODE (x
) != VOIDmode
)
711 oldmode
= GET_MODE (x
);
716 if (CONST_SCALAR_INT_P (x
) && GET_MODE_CLASS (mode
) == MODE_INT
)
718 /* If the caller did not tell us the old mode, then there is not
719 much to do with respect to canonicalization. We have to
720 assume that all the bits are significant. */
721 if (GET_MODE_CLASS (oldmode
) != MODE_INT
)
722 oldmode
= MAX_MODE_INT
;
723 wide_int w
= wide_int::from (std::make_pair (x
, oldmode
),
724 GET_MODE_PRECISION (mode
),
725 unsignedp
? UNSIGNED
: SIGNED
);
726 return immed_wide_int_const (w
, mode
);
729 /* We can do this with a gen_lowpart if both desired and current modes
730 are integer, and this is either a constant integer, a register, or a
732 if (GET_MODE_CLASS (mode
) == MODE_INT
733 && GET_MODE_CLASS (oldmode
) == MODE_INT
734 && GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
735 && ((MEM_P (x
) && !MEM_VOLATILE_P (x
) && direct_load
[(int) mode
])
737 && (!HARD_REGISTER_P (x
)
738 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
739 && TRULY_NOOP_TRUNCATION_MODES_P (mode
, GET_MODE (x
)))))
741 return gen_lowpart (mode
, x
);
743 /* Converting from integer constant into mode is always equivalent to an
745 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
747 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
748 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
751 temp
= gen_reg_rtx (mode
);
752 convert_move (temp
, x
, unsignedp
);
756 /* Return the largest alignment we can use for doing a move (or store)
757 of MAX_PIECES. ALIGN is the largest alignment we could use. */
760 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
764 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
765 if (align
>= GET_MODE_ALIGNMENT (tmode
))
766 align
= GET_MODE_ALIGNMENT (tmode
);
769 machine_mode tmode
, xmode
;
771 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
773 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
774 if (GET_MODE_SIZE (tmode
) > max_pieces
775 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
778 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
784 /* Return the widest integer mode no wider than SIZE. If no such mode
785 can be found, return VOIDmode. */
788 widest_int_mode_for_size (unsigned int size
)
790 machine_mode tmode
, mode
= VOIDmode
;
792 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
793 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
794 if (GET_MODE_SIZE (tmode
) < size
)
800 /* Determine whether the LEN bytes can be moved by using several move
801 instructions. Return nonzero if a call to move_by_pieces should
805 can_move_by_pieces (unsigned HOST_WIDE_INT len
,
808 return targetm
.use_by_pieces_infrastructure_p (len
, align
, MOVE_BY_PIECES
,
809 optimize_insn_for_speed_p ());
812 /* Generate several move instructions to copy LEN bytes from block FROM to
813 block TO. (These are MEM rtx's with BLKmode).
815 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
816 used to push FROM to the stack.
818 ALIGN is maximum stack alignment we can assume.
820 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
821 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
825 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
826 unsigned int align
, int endp
)
828 struct move_by_pieces_d data
;
829 machine_mode to_addr_mode
;
830 machine_mode from_addr_mode
= get_address_mode (from
);
831 rtx to_addr
, from_addr
= XEXP (from
, 0);
832 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
833 enum insn_code icode
;
835 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
838 data
.from_addr
= from_addr
;
841 to_addr_mode
= get_address_mode (to
);
842 to_addr
= XEXP (to
, 0);
845 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
846 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
848 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
852 to_addr_mode
= VOIDmode
;
856 #ifdef STACK_GROWS_DOWNWARD
862 data
.to_addr
= to_addr
;
865 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
866 || GET_CODE (from_addr
) == POST_INC
867 || GET_CODE (from_addr
) == POST_DEC
);
869 data
.explicit_inc_from
= 0;
870 data
.explicit_inc_to
= 0;
871 if (data
.reverse
) data
.offset
= len
;
874 /* If copying requires more than two move insns,
875 copy addresses to registers (to make displacements shorter)
876 and use post-increment if available. */
877 if (!(data
.autinc_from
&& data
.autinc_to
)
878 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
880 /* Find the mode of the largest move...
881 MODE might not be used depending on the definitions of the
882 USE_* macros below. */
883 machine_mode mode ATTRIBUTE_UNUSED
884 = widest_int_mode_for_size (max_size
);
886 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
888 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
889 plus_constant (from_addr_mode
,
891 data
.autinc_from
= 1;
892 data
.explicit_inc_from
= -1;
894 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
896 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
897 data
.autinc_from
= 1;
898 data
.explicit_inc_from
= 1;
900 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
901 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
902 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
904 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
905 plus_constant (to_addr_mode
,
908 data
.explicit_inc_to
= -1;
910 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
912 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
914 data
.explicit_inc_to
= 1;
916 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
917 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
920 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
922 /* First move what we can in the largest integer mode, then go to
923 successively smaller modes. */
925 while (max_size
> 1 && data
.len
> 0)
927 machine_mode mode
= widest_int_mode_for_size (max_size
);
929 if (mode
== VOIDmode
)
932 icode
= optab_handler (mov_optab
, mode
);
933 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
934 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
936 max_size
= GET_MODE_SIZE (mode
);
939 /* The code above should have handled everything. */
940 gcc_assert (!data
.len
);
946 gcc_assert (!data
.reverse
);
951 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
952 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
954 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
955 plus_constant (to_addr_mode
,
959 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
966 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
974 /* Return number of insns required to move L bytes by pieces.
975 ALIGN (in bits) is maximum alignment we can assume. */
977 unsigned HOST_WIDE_INT
978 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
979 unsigned int max_size
)
981 unsigned HOST_WIDE_INT n_insns
= 0;
983 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
985 while (max_size
> 1 && l
> 0)
988 enum insn_code icode
;
990 mode
= widest_int_mode_for_size (max_size
);
992 if (mode
== VOIDmode
)
995 icode
= optab_handler (mov_optab
, mode
);
996 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
997 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
999 max_size
= GET_MODE_SIZE (mode
);
1006 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1007 with move instructions for mode MODE. GENFUN is the gen_... function
1008 to make a move insn for that mode. DATA has all the other info. */
1011 move_by_pieces_1 (insn_gen_fn genfun
, machine_mode mode
,
1012 struct move_by_pieces_d
*data
)
1014 unsigned int size
= GET_MODE_SIZE (mode
);
1015 rtx to1
= NULL_RTX
, from1
;
1017 while (data
->len
>= size
)
1020 data
->offset
-= size
;
1024 if (data
->autinc_to
)
1025 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1028 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1031 if (data
->autinc_from
)
1032 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1035 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1037 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1038 emit_insn (gen_add2_insn (data
->to_addr
,
1039 gen_int_mode (-(HOST_WIDE_INT
) size
,
1040 GET_MODE (data
->to_addr
))));
1041 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1042 emit_insn (gen_add2_insn (data
->from_addr
,
1043 gen_int_mode (-(HOST_WIDE_INT
) size
,
1044 GET_MODE (data
->from_addr
))));
1047 emit_insn ((*genfun
) (to1
, from1
));
1050 #ifdef PUSH_ROUNDING
1051 emit_single_push_insn (mode
, from1
, NULL
);
1057 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1058 emit_insn (gen_add2_insn (data
->to_addr
,
1060 GET_MODE (data
->to_addr
))));
1061 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1062 emit_insn (gen_add2_insn (data
->from_addr
,
1064 GET_MODE (data
->from_addr
))));
1066 if (! data
->reverse
)
1067 data
->offset
+= size
;
1073 /* Emit code to move a block Y to a block X. This may be done with
1074 string-move instructions, with multiple scalar move instructions,
1075 or with a library call.
1077 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1078 SIZE is an rtx that says how long they are.
1079 ALIGN is the maximum alignment we can assume they have.
1080 METHOD describes what kind of copy this is, and what mechanisms may be used.
1081 MIN_SIZE is the minimal size of block to move
1082 MAX_SIZE is the maximal size of block to move, if it can not be represented
1083 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1085 Return the address of the new block, if memcpy is called and returns it,
1089 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1090 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1091 unsigned HOST_WIDE_INT min_size
,
1092 unsigned HOST_WIDE_INT max_size
,
1093 unsigned HOST_WIDE_INT probable_max_size
)
1100 if (CONST_INT_P (size
)
1101 && INTVAL (size
) == 0)
1106 case BLOCK_OP_NORMAL
:
1107 case BLOCK_OP_TAILCALL
:
1108 may_use_call
= true;
1111 case BLOCK_OP_CALL_PARM
:
1112 may_use_call
= block_move_libcall_safe_for_call_parm ();
1114 /* Make inhibit_defer_pop nonzero around the library call
1115 to force it to pop the arguments right away. */
1119 case BLOCK_OP_NO_LIBCALL
:
1120 may_use_call
= false;
1127 gcc_assert (MEM_P (x
) && MEM_P (y
));
1128 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1129 gcc_assert (align
>= BITS_PER_UNIT
);
1131 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1132 block copy is more efficient for other large modes, e.g. DCmode. */
1133 x
= adjust_address (x
, BLKmode
, 0);
1134 y
= adjust_address (y
, BLKmode
, 0);
1136 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1137 can be incorrect is coming from __builtin_memcpy. */
1138 if (CONST_INT_P (size
))
1140 x
= shallow_copy_rtx (x
);
1141 y
= shallow_copy_rtx (y
);
1142 set_mem_size (x
, INTVAL (size
));
1143 set_mem_size (y
, INTVAL (size
));
1146 if (CONST_INT_P (size
) && can_move_by_pieces (INTVAL (size
), align
))
1147 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1148 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1149 expected_align
, expected_size
,
1150 min_size
, max_size
, probable_max_size
))
1152 else if (may_use_call
1153 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1154 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1156 /* Since x and y are passed to a libcall, mark the corresponding
1157 tree EXPR as addressable. */
1158 tree y_expr
= MEM_EXPR (y
);
1159 tree x_expr
= MEM_EXPR (x
);
1161 mark_addressable (y_expr
);
1163 mark_addressable (x_expr
);
1164 retval
= emit_block_move_via_libcall (x
, y
, size
,
1165 method
== BLOCK_OP_TAILCALL
);
1169 emit_block_move_via_loop (x
, y
, size
, align
);
1171 if (method
== BLOCK_OP_CALL_PARM
)
1178 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1180 unsigned HOST_WIDE_INT max
, min
= 0;
1181 if (GET_CODE (size
) == CONST_INT
)
1182 min
= max
= UINTVAL (size
);
1184 max
= GET_MODE_MASK (GET_MODE (size
));
1185 return emit_block_move_hints (x
, y
, size
, method
, 0, -1,
1189 /* A subroutine of emit_block_move. Returns true if calling the
1190 block move libcall will not clobber any parameters which may have
1191 already been placed on the stack. */
1194 block_move_libcall_safe_for_call_parm (void)
1196 #if defined (REG_PARM_STACK_SPACE)
1200 /* If arguments are pushed on the stack, then they're safe. */
1204 /* If registers go on the stack anyway, any argument is sure to clobber
1205 an outgoing argument. */
1206 #if defined (REG_PARM_STACK_SPACE)
1207 fn
= emit_block_move_libcall_fn (false);
1208 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1209 depend on its argument. */
1211 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1212 && REG_PARM_STACK_SPACE (fn
) != 0)
1216 /* If any argument goes in memory, then it might clobber an outgoing
1219 CUMULATIVE_ARGS args_so_far_v
;
1220 cumulative_args_t args_so_far
;
1223 fn
= emit_block_move_libcall_fn (false);
1224 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1225 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1227 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1228 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1230 machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1231 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1233 if (!tmp
|| !REG_P (tmp
))
1235 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1237 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1244 /* A subroutine of emit_block_move. Expand a movmem pattern;
1245 return true if successful. */
1248 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1249 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1250 unsigned HOST_WIDE_INT min_size
,
1251 unsigned HOST_WIDE_INT max_size
,
1252 unsigned HOST_WIDE_INT probable_max_size
)
1254 int save_volatile_ok
= volatile_ok
;
1257 if (expected_align
< align
)
1258 expected_align
= align
;
1259 if (expected_size
!= -1)
1261 if ((unsigned HOST_WIDE_INT
)expected_size
> probable_max_size
)
1262 expected_size
= probable_max_size
;
1263 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
1264 expected_size
= min_size
;
1267 /* Since this is a move insn, we don't care about volatility. */
1270 /* Try the most limited insn first, because there's no point
1271 including more than one in the machine description unless
1272 the more limited one has some advantage. */
1274 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1275 mode
= GET_MODE_WIDER_MODE (mode
))
1277 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1279 if (code
!= CODE_FOR_nothing
1280 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1281 here because if SIZE is less than the mode mask, as it is
1282 returned by the macro, it will definitely be less than the
1283 actual mode mask. Since SIZE is within the Pmode address
1284 space, we limit MODE to Pmode. */
1285 && ((CONST_INT_P (size
)
1286 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1287 <= (GET_MODE_MASK (mode
) >> 1)))
1288 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
1289 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
1291 struct expand_operand ops
[9];
1294 /* ??? When called via emit_block_move_for_call, it'd be
1295 nice if there were some way to inform the backend, so
1296 that it doesn't fail the expansion because it thinks
1297 emitting the libcall would be more efficient. */
1298 nops
= insn_data
[(int) code
].n_generator_args
;
1299 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
1301 create_fixed_operand (&ops
[0], x
);
1302 create_fixed_operand (&ops
[1], y
);
1303 /* The check above guarantees that this size conversion is valid. */
1304 create_convert_operand_to (&ops
[2], size
, mode
, true);
1305 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1308 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1309 create_integer_operand (&ops
[5], expected_size
);
1313 create_integer_operand (&ops
[6], min_size
);
1314 /* If we can not represent the maximal size,
1315 make parameter NULL. */
1316 if ((HOST_WIDE_INT
) max_size
!= -1)
1317 create_integer_operand (&ops
[7], max_size
);
1319 create_fixed_operand (&ops
[7], NULL
);
1323 /* If we can not represent the maximal size,
1324 make parameter NULL. */
1325 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
1326 create_integer_operand (&ops
[8], probable_max_size
);
1328 create_fixed_operand (&ops
[8], NULL
);
1330 if (maybe_expand_insn (code
, nops
, ops
))
1332 volatile_ok
= save_volatile_ok
;
1338 volatile_ok
= save_volatile_ok
;
1342 /* A subroutine of emit_block_move. Expand a call to memcpy.
1343 Return the return value from memcpy, 0 otherwise. */
1346 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1348 rtx dst_addr
, src_addr
;
1349 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1350 machine_mode size_mode
;
1353 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1354 pseudos. We can then place those new pseudos into a VAR_DECL and
1357 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1358 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1360 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1361 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1363 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1364 src_tree
= make_tree (ptr_type_node
, src_addr
);
1366 size_mode
= TYPE_MODE (sizetype
);
1368 size
= convert_to_mode (size_mode
, size
, 1);
1369 size
= copy_to_mode_reg (size_mode
, size
);
1371 /* It is incorrect to use the libcall calling conventions to call
1372 memcpy in this context. This could be a user call to memcpy and
1373 the user may wish to examine the return value from memcpy. For
1374 targets where libcalls and normal calls have different conventions
1375 for returning pointers, we could end up generating incorrect code. */
1377 size_tree
= make_tree (sizetype
, size
);
1379 fn
= emit_block_move_libcall_fn (true);
1380 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1381 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1383 retval
= expand_normal (call_expr
);
1388 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1389 for the function we use for block copies. */
1391 static GTY(()) tree block_move_fn
;
1394 init_block_move_fn (const char *asmspec
)
1398 tree args
, fn
, attrs
, attr_args
;
1400 fn
= get_identifier ("memcpy");
1401 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1402 const_ptr_type_node
, sizetype
,
1405 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1406 DECL_EXTERNAL (fn
) = 1;
1407 TREE_PUBLIC (fn
) = 1;
1408 DECL_ARTIFICIAL (fn
) = 1;
1409 TREE_NOTHROW (fn
) = 1;
1410 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1411 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1413 attr_args
= build_tree_list (NULL_TREE
, build_string (1, "1"));
1414 attrs
= tree_cons (get_identifier ("fn spec"), attr_args
, NULL
);
1416 decl_attributes (&fn
, attrs
, ATTR_FLAG_BUILT_IN
);
1422 set_user_assembler_name (block_move_fn
, asmspec
);
1426 emit_block_move_libcall_fn (int for_call
)
1428 static bool emitted_extern
;
1431 init_block_move_fn (NULL
);
1433 if (for_call
&& !emitted_extern
)
1435 emitted_extern
= true;
1436 make_decl_rtl (block_move_fn
);
1439 return block_move_fn
;
1442 /* A subroutine of emit_block_move. Copy the data via an explicit
1443 loop. This is used only when libcalls are forbidden. */
1444 /* ??? It'd be nice to copy in hunks larger than QImode. */
1447 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1448 unsigned int align ATTRIBUTE_UNUSED
)
1450 rtx_code_label
*cmp_label
, *top_label
;
1451 rtx iter
, x_addr
, y_addr
, tmp
;
1452 machine_mode x_addr_mode
= get_address_mode (x
);
1453 machine_mode y_addr_mode
= get_address_mode (y
);
1454 machine_mode iter_mode
;
1456 iter_mode
= GET_MODE (size
);
1457 if (iter_mode
== VOIDmode
)
1458 iter_mode
= word_mode
;
1460 top_label
= gen_label_rtx ();
1461 cmp_label
= gen_label_rtx ();
1462 iter
= gen_reg_rtx (iter_mode
);
1464 emit_move_insn (iter
, const0_rtx
);
1466 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1467 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1468 do_pending_stack_adjust ();
1470 emit_jump (cmp_label
);
1471 emit_label (top_label
);
1473 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1474 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1476 if (x_addr_mode
!= y_addr_mode
)
1477 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1478 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1480 x
= change_address (x
, QImode
, x_addr
);
1481 y
= change_address (y
, QImode
, y_addr
);
1483 emit_move_insn (x
, y
);
1485 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1486 true, OPTAB_LIB_WIDEN
);
1488 emit_move_insn (iter
, tmp
);
1490 emit_label (cmp_label
);
1492 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1493 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1496 /* Copy all or part of a value X into registers starting at REGNO.
1497 The number of registers to be filled is NREGS. */
1500 move_block_to_reg (int regno
, rtx x
, int nregs
, machine_mode mode
)
1503 #ifdef HAVE_load_multiple
1511 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1512 x
= validize_mem (force_const_mem (mode
, x
));
1514 /* See if the machine can do this with a load multiple insn. */
1515 #ifdef HAVE_load_multiple
1516 if (HAVE_load_multiple
)
1518 last
= get_last_insn ();
1519 pat
= gen_load_multiple (gen_rtx_REG (word_mode
, regno
), x
,
1527 delete_insns_since (last
);
1531 for (i
= 0; i
< nregs
; i
++)
1532 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1533 operand_subword_force (x
, i
, mode
));
1536 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1537 The number of registers to be filled is NREGS. */
1540 move_block_from_reg (int regno
, rtx x
, int nregs
)
1547 /* See if the machine can do this with a store multiple insn. */
1548 #ifdef HAVE_store_multiple
1549 if (HAVE_store_multiple
)
1551 rtx_insn
*last
= get_last_insn ();
1552 rtx pat
= gen_store_multiple (x
, gen_rtx_REG (word_mode
, regno
),
1560 delete_insns_since (last
);
1564 for (i
= 0; i
< nregs
; i
++)
1566 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1570 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1574 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1575 ORIG, where ORIG is a non-consecutive group of registers represented by
1576 a PARALLEL. The clone is identical to the original except in that the
1577 original set of registers is replaced by a new set of pseudo registers.
1578 The new set has the same modes as the original set. */
1581 gen_group_rtx (rtx orig
)
1586 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1588 length
= XVECLEN (orig
, 0);
1589 tmps
= XALLOCAVEC (rtx
, length
);
1591 /* Skip a NULL entry in first slot. */
1592 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1597 for (; i
< length
; i
++)
1599 machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1600 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1602 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1605 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1608 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1609 except that values are placed in TMPS[i], and must later be moved
1610 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1613 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1617 machine_mode m
= GET_MODE (orig_src
);
1619 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1622 && !SCALAR_INT_MODE_P (m
)
1623 && !MEM_P (orig_src
)
1624 && GET_CODE (orig_src
) != CONCAT
)
1626 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1627 if (imode
== BLKmode
)
1628 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
1630 src
= gen_reg_rtx (imode
);
1631 if (imode
!= BLKmode
)
1632 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1633 emit_move_insn (src
, orig_src
);
1634 /* ...and back again. */
1635 if (imode
!= BLKmode
)
1636 src
= gen_lowpart (imode
, src
);
1637 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1641 /* Check for a NULL entry, used to indicate that the parameter goes
1642 both on the stack and in registers. */
1643 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1648 /* Process the pieces. */
1649 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1651 machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1652 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1653 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1656 /* Handle trailing fragments that run over the size of the struct. */
1657 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1659 /* Arrange to shift the fragment to where it belongs.
1660 extract_bit_field loads to the lsb of the reg. */
1662 #ifdef BLOCK_REG_PADDING
1663 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1664 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1669 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1670 bytelen
= ssize
- bytepos
;
1671 gcc_assert (bytelen
> 0);
1674 /* If we won't be loading directly from memory, protect the real source
1675 from strange tricks we might play; but make sure that the source can
1676 be loaded directly into the destination. */
1678 if (!MEM_P (orig_src
)
1679 && (!CONSTANT_P (orig_src
)
1680 || (GET_MODE (orig_src
) != mode
1681 && GET_MODE (orig_src
) != VOIDmode
)))
1683 if (GET_MODE (orig_src
) == VOIDmode
)
1684 src
= gen_reg_rtx (mode
);
1686 src
= gen_reg_rtx (GET_MODE (orig_src
));
1688 emit_move_insn (src
, orig_src
);
1691 /* Optimize the access just a bit. */
1693 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1694 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1695 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1696 && bytelen
== GET_MODE_SIZE (mode
))
1698 tmps
[i
] = gen_reg_rtx (mode
);
1699 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1701 else if (COMPLEX_MODE_P (mode
)
1702 && GET_MODE (src
) == mode
1703 && bytelen
== GET_MODE_SIZE (mode
))
1704 /* Let emit_move_complex do the bulk of the work. */
1706 else if (GET_CODE (src
) == CONCAT
)
1708 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1709 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1711 if ((bytepos
== 0 && bytelen
== slen0
)
1712 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1714 /* The following assumes that the concatenated objects all
1715 have the same size. In this case, a simple calculation
1716 can be used to determine the object and the bit field
1718 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1719 if (! CONSTANT_P (tmps
[i
])
1720 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1721 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1722 (bytepos
% slen0
) * BITS_PER_UNIT
,
1723 1, NULL_RTX
, mode
, mode
);
1729 gcc_assert (!bytepos
);
1730 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1731 emit_move_insn (mem
, src
);
1732 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1733 0, 1, NULL_RTX
, mode
, mode
);
1736 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1737 SIMD register, which is currently broken. While we get GCC
1738 to emit proper RTL for these cases, let's dump to memory. */
1739 else if (VECTOR_MODE_P (GET_MODE (dst
))
1742 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1745 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1746 emit_move_insn (mem
, src
);
1747 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1749 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1750 && XVECLEN (dst
, 0) > 1)
1751 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE (dst
), bytepos
);
1752 else if (CONSTANT_P (src
))
1754 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1762 /* TODO: const_wide_int can have sizes other than this... */
1763 gcc_assert (2 * len
== ssize
);
1764 split_double (src
, &first
, &second
);
1771 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1774 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1775 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
1779 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1784 /* Emit code to move a block SRC of type TYPE to a block DST,
1785 where DST is non-consecutive registers represented by a PARALLEL.
1786 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1790 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1795 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1796 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1798 /* Copy the extracted pieces into the proper (probable) hard regs. */
1799 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1801 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1804 emit_move_insn (d
, tmps
[i
]);
1808 /* Similar, but load SRC into new pseudos in a format that looks like
1809 PARALLEL. This can later be fed to emit_group_move to get things
1810 in the right place. */
1813 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1818 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1819 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1821 /* Convert the vector to look just like the original PARALLEL, except
1822 with the computed values. */
1823 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1825 rtx e
= XVECEXP (parallel
, 0, i
);
1826 rtx d
= XEXP (e
, 0);
1830 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1831 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1833 RTVEC_ELT (vec
, i
) = e
;
1836 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1839 /* Emit code to move a block SRC to block DST, where SRC and DST are
1840 non-consecutive groups of registers, each represented by a PARALLEL. */
1843 emit_group_move (rtx dst
, rtx src
)
1847 gcc_assert (GET_CODE (src
) == PARALLEL
1848 && GET_CODE (dst
) == PARALLEL
1849 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1851 /* Skip first entry if NULL. */
1852 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1853 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1854 XEXP (XVECEXP (src
, 0, i
), 0));
1857 /* Move a group of registers represented by a PARALLEL into pseudos. */
1860 emit_group_move_into_temps (rtx src
)
1862 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1865 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1867 rtx e
= XVECEXP (src
, 0, i
);
1868 rtx d
= XEXP (e
, 0);
1871 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1872 RTVEC_ELT (vec
, i
) = e
;
1875 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1878 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1879 where SRC is non-consecutive registers represented by a PARALLEL.
1880 SSIZE represents the total size of block ORIG_DST, or -1 if not
1884 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1887 int start
, finish
, i
;
1888 machine_mode m
= GET_MODE (orig_dst
);
1890 gcc_assert (GET_CODE (src
) == PARALLEL
);
1892 if (!SCALAR_INT_MODE_P (m
)
1893 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1895 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1896 if (imode
== BLKmode
)
1897 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
1899 dst
= gen_reg_rtx (imode
);
1900 emit_group_store (dst
, src
, type
, ssize
);
1901 if (imode
!= BLKmode
)
1902 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1903 emit_move_insn (orig_dst
, dst
);
1907 /* Check for a NULL entry, used to indicate that the parameter goes
1908 both on the stack and in registers. */
1909 if (XEXP (XVECEXP (src
, 0, 0), 0))
1913 finish
= XVECLEN (src
, 0);
1915 tmps
= XALLOCAVEC (rtx
, finish
);
1917 /* Copy the (probable) hard regs into pseudos. */
1918 for (i
= start
; i
< finish
; i
++)
1920 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1921 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1923 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1924 emit_move_insn (tmps
[i
], reg
);
1930 /* If we won't be storing directly into memory, protect the real destination
1931 from strange tricks we might play. */
1933 if (GET_CODE (dst
) == PARALLEL
)
1937 /* We can get a PARALLEL dst if there is a conditional expression in
1938 a return statement. In that case, the dst and src are the same,
1939 so no action is necessary. */
1940 if (rtx_equal_p (dst
, src
))
1943 /* It is unclear if we can ever reach here, but we may as well handle
1944 it. Allocate a temporary, and split this into a store/load to/from
1946 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
1947 emit_group_store (temp
, src
, type
, ssize
);
1948 emit_group_load (dst
, temp
, type
, ssize
);
1951 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1953 machine_mode outer
= GET_MODE (dst
);
1955 HOST_WIDE_INT bytepos
;
1959 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
1960 dst
= gen_reg_rtx (outer
);
1962 /* Make life a bit easier for combine. */
1963 /* If the first element of the vector is the low part
1964 of the destination mode, use a paradoxical subreg to
1965 initialize the destination. */
1968 inner
= GET_MODE (tmps
[start
]);
1969 bytepos
= subreg_lowpart_offset (inner
, outer
);
1970 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
1972 temp
= simplify_gen_subreg (outer
, tmps
[start
],
1976 emit_move_insn (dst
, temp
);
1983 /* If the first element wasn't the low part, try the last. */
1985 && start
< finish
- 1)
1987 inner
= GET_MODE (tmps
[finish
- 1]);
1988 bytepos
= subreg_lowpart_offset (inner
, outer
);
1989 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
1991 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
1995 emit_move_insn (dst
, temp
);
2002 /* Otherwise, simply initialize the result to zero. */
2004 emit_move_insn (dst
, CONST0_RTX (outer
));
2007 /* Process the pieces. */
2008 for (i
= start
; i
< finish
; i
++)
2010 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
2011 machine_mode mode
= GET_MODE (tmps
[i
]);
2012 unsigned int bytelen
= GET_MODE_SIZE (mode
);
2013 unsigned int adj_bytelen
;
2016 /* Handle trailing fragments that run over the size of the struct. */
2017 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2018 adj_bytelen
= ssize
- bytepos
;
2020 adj_bytelen
= bytelen
;
2022 if (GET_CODE (dst
) == CONCAT
)
2024 if (bytepos
+ adj_bytelen
2025 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2026 dest
= XEXP (dst
, 0);
2027 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2029 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2030 dest
= XEXP (dst
, 1);
2034 machine_mode dest_mode
= GET_MODE (dest
);
2035 machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2037 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2039 if (GET_MODE_ALIGNMENT (dest_mode
)
2040 >= GET_MODE_ALIGNMENT (tmp_mode
))
2042 dest
= assign_stack_temp (dest_mode
,
2043 GET_MODE_SIZE (dest_mode
));
2044 emit_move_insn (adjust_address (dest
,
2052 dest
= assign_stack_temp (tmp_mode
,
2053 GET_MODE_SIZE (tmp_mode
));
2054 emit_move_insn (dest
, tmps
[i
]);
2055 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2061 /* Handle trailing fragments that run over the size of the struct. */
2062 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2064 /* store_bit_field always takes its value from the lsb.
2065 Move the fragment to the lsb if it's not already there. */
2067 #ifdef BLOCK_REG_PADDING
2068 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2069 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2075 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2076 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2080 /* Make sure not to write past the end of the struct. */
2081 store_bit_field (dest
,
2082 adj_bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2083 bytepos
* BITS_PER_UNIT
, ssize
* BITS_PER_UNIT
- 1,
2087 /* Optimize the access just a bit. */
2088 else if (MEM_P (dest
)
2089 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2090 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2091 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2092 && bytelen
== GET_MODE_SIZE (mode
))
2093 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2096 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2097 0, 0, mode
, tmps
[i
]);
2100 /* Copy from the pseudo into the (probable) hard reg. */
2101 if (orig_dst
!= dst
)
2102 emit_move_insn (orig_dst
, dst
);
2105 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2106 of the value stored in X. */
2109 maybe_emit_group_store (rtx x
, tree type
)
2111 machine_mode mode
= TYPE_MODE (type
);
2112 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
2113 if (GET_CODE (x
) == PARALLEL
)
2115 rtx result
= gen_reg_rtx (mode
);
2116 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
2122 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2124 This is used on targets that return BLKmode values in registers. */
2127 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2129 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2130 rtx src
= NULL
, dst
= NULL
;
2131 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2132 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2133 machine_mode mode
= GET_MODE (srcreg
);
2134 machine_mode tmode
= GET_MODE (target
);
2135 machine_mode copy_mode
;
2137 /* BLKmode registers created in the back-end shouldn't have survived. */
2138 gcc_assert (mode
!= BLKmode
);
2140 /* If the structure doesn't take up a whole number of words, see whether
2141 SRCREG is padded on the left or on the right. If it's on the left,
2142 set PADDING_CORRECTION to the number of bits to skip.
2144 In most ABIs, the structure will be returned at the least end of
2145 the register, which translates to right padding on little-endian
2146 targets and left padding on big-endian targets. The opposite
2147 holds if the structure is returned at the most significant
2148 end of the register. */
2149 if (bytes
% UNITS_PER_WORD
!= 0
2150 && (targetm
.calls
.return_in_msb (type
)
2152 : BYTES_BIG_ENDIAN
))
2154 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2156 /* We can use a single move if we have an exact mode for the size. */
2157 else if (MEM_P (target
)
2158 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2159 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2160 && bytes
== GET_MODE_SIZE (mode
))
2162 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2166 /* And if we additionally have the same mode for a register. */
2167 else if (REG_P (target
)
2168 && GET_MODE (target
) == mode
2169 && bytes
== GET_MODE_SIZE (mode
))
2171 emit_move_insn (target
, srcreg
);
2175 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2176 into a new pseudo which is a full word. */
2177 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2179 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2183 /* Copy the structure BITSIZE bits at a time. If the target lives in
2184 memory, take care of not reading/writing past its end by selecting
2185 a copy mode suited to BITSIZE. This should always be possible given
2188 If the target lives in register, make sure not to select a copy mode
2189 larger than the mode of the register.
2191 We could probably emit more efficient code for machines which do not use
2192 strict alignment, but it doesn't seem worth the effort at the current
2195 copy_mode
= word_mode
;
2198 machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2199 if (mem_mode
!= BLKmode
)
2200 copy_mode
= mem_mode
;
2202 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2205 for (bitpos
= 0, xbitpos
= padding_correction
;
2206 bitpos
< bytes
* BITS_PER_UNIT
;
2207 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2209 /* We need a new source operand each time xbitpos is on a
2210 word boundary and when xbitpos == padding_correction
2211 (the first time through). */
2212 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2213 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2215 /* We need a new destination operand each time bitpos is on
2217 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2219 else if (bitpos
% BITS_PER_WORD
== 0)
2220 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2222 /* Use xbitpos for the source extraction (right justified) and
2223 bitpos for the destination store (left justified). */
2224 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2225 extract_bit_field (src
, bitsize
,
2226 xbitpos
% BITS_PER_WORD
, 1,
2227 NULL_RTX
, copy_mode
, copy_mode
));
2231 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2232 register if it contains any data, otherwise return null.
2234 This is used on targets that return BLKmode values in registers. */
2237 copy_blkmode_to_reg (machine_mode mode
, tree src
)
2240 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2241 unsigned int bitsize
;
2242 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2243 machine_mode dst_mode
;
2245 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2247 x
= expand_normal (src
);
2249 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2253 /* If the structure doesn't take up a whole number of words, see
2254 whether the register value should be padded on the left or on
2255 the right. Set PADDING_CORRECTION to the number of padding
2256 bits needed on the left side.
2258 In most ABIs, the structure will be returned at the least end of
2259 the register, which translates to right padding on little-endian
2260 targets and left padding on big-endian targets. The opposite
2261 holds if the structure is returned at the most significant
2262 end of the register. */
2263 if (bytes
% UNITS_PER_WORD
!= 0
2264 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2266 : BYTES_BIG_ENDIAN
))
2267 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2270 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2271 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2272 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2274 /* Copy the structure BITSIZE bits at a time. */
2275 for (bitpos
= 0, xbitpos
= padding_correction
;
2276 bitpos
< bytes
* BITS_PER_UNIT
;
2277 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2279 /* We need a new destination pseudo each time xbitpos is
2280 on a word boundary and when xbitpos == padding_correction
2281 (the first time through). */
2282 if (xbitpos
% BITS_PER_WORD
== 0
2283 || xbitpos
== padding_correction
)
2285 /* Generate an appropriate register. */
2286 dst_word
= gen_reg_rtx (word_mode
);
2287 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2289 /* Clear the destination before we move anything into it. */
2290 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2293 /* We need a new source operand each time bitpos is on a word
2295 if (bitpos
% BITS_PER_WORD
== 0)
2296 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2298 /* Use bitpos for the source extraction (left justified) and
2299 xbitpos for the destination store (right justified). */
2300 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2302 extract_bit_field (src_word
, bitsize
,
2303 bitpos
% BITS_PER_WORD
, 1,
2304 NULL_RTX
, word_mode
, word_mode
));
2307 if (mode
== BLKmode
)
2309 /* Find the smallest integer mode large enough to hold the
2310 entire structure. */
2311 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2313 mode
= GET_MODE_WIDER_MODE (mode
))
2314 /* Have we found a large enough mode? */
2315 if (GET_MODE_SIZE (mode
) >= bytes
)
2318 /* A suitable mode should have been found. */
2319 gcc_assert (mode
!= VOIDmode
);
2322 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2323 dst_mode
= word_mode
;
2326 dst
= gen_reg_rtx (dst_mode
);
2328 for (i
= 0; i
< n_regs
; i
++)
2329 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2331 if (mode
!= dst_mode
)
2332 dst
= gen_lowpart (mode
, dst
);
2337 /* Add a USE expression for REG to the (possibly empty) list pointed
2338 to by CALL_FUSAGE. REG must denote a hard register. */
2341 use_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2343 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2346 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2349 /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
2350 to by CALL_FUSAGE. REG must denote a hard register. */
2353 clobber_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2355 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2358 = gen_rtx_EXPR_LIST (mode
, gen_rtx_CLOBBER (VOIDmode
, reg
), *call_fusage
);
2361 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2362 starting at REGNO. All of these registers must be hard registers. */
2365 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2369 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2371 for (i
= 0; i
< nregs
; i
++)
2372 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2375 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2376 PARALLEL REGS. This is for calls that pass values in multiple
2377 non-contiguous locations. The Irix 6 ABI has examples of this. */
2380 use_group_regs (rtx
*call_fusage
, rtx regs
)
2384 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2386 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2388 /* A NULL entry means the parameter goes both on the stack and in
2389 registers. This can also be a MEM for targets that pass values
2390 partially on the stack and partially in registers. */
2391 if (reg
!= 0 && REG_P (reg
))
2392 use_reg (call_fusage
, reg
);
2396 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2397 assigment and the code of the expresion on the RHS is CODE. Return
2401 get_def_for_expr (tree name
, enum tree_code code
)
2405 if (TREE_CODE (name
) != SSA_NAME
)
2408 def_stmt
= get_gimple_for_ssa_name (name
);
2410 || gimple_assign_rhs_code (def_stmt
) != code
)
2416 #ifdef HAVE_conditional_move
2417 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2418 assigment and the class of the expresion on the RHS is CLASS. Return
2422 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2426 if (TREE_CODE (name
) != SSA_NAME
)
2429 def_stmt
= get_gimple_for_ssa_name (name
);
2431 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2439 /* Determine whether the LEN bytes generated by CONSTFUN can be
2440 stored to memory using several move instructions. CONSTFUNDATA is
2441 a pointer which will be passed as argument in every CONSTFUN call.
2442 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2443 a memset operation and false if it's a copy of a constant string.
2444 Return nonzero if a call to store_by_pieces should succeed. */
2447 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2448 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
2449 void *constfundata
, unsigned int align
, bool memsetp
)
2451 unsigned HOST_WIDE_INT l
;
2452 unsigned int max_size
;
2453 HOST_WIDE_INT offset
= 0;
2455 enum insn_code icode
;
2457 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2458 rtx cst ATTRIBUTE_UNUSED
;
2463 if (!targetm
.use_by_pieces_infrastructure_p (len
, align
,
2467 optimize_insn_for_speed_p ()))
2470 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2472 /* We would first store what we can in the largest integer mode, then go to
2473 successively smaller modes. */
2476 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2480 max_size
= STORE_MAX_PIECES
+ 1;
2481 while (max_size
> 1 && l
> 0)
2483 mode
= widest_int_mode_for_size (max_size
);
2485 if (mode
== VOIDmode
)
2488 icode
= optab_handler (mov_optab
, mode
);
2489 if (icode
!= CODE_FOR_nothing
2490 && align
>= GET_MODE_ALIGNMENT (mode
))
2492 unsigned int size
= GET_MODE_SIZE (mode
);
2499 cst
= (*constfun
) (constfundata
, offset
, mode
);
2500 if (!targetm
.legitimate_constant_p (mode
, cst
))
2510 max_size
= GET_MODE_SIZE (mode
);
2513 /* The code above should have handled everything. */
2520 /* Generate several move instructions to store LEN bytes generated by
2521 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2522 pointer which will be passed as argument in every CONSTFUN call.
2523 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2524 a memset operation and false if it's a copy of a constant string.
2525 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2526 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2530 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2531 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
2532 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2534 machine_mode to_addr_mode
= get_address_mode (to
);
2535 struct store_by_pieces_d data
;
2539 gcc_assert (endp
!= 2);
2543 gcc_assert (targetm
.use_by_pieces_infrastructure_p
2548 optimize_insn_for_speed_p ()));
2550 data
.constfun
= constfun
;
2551 data
.constfundata
= constfundata
;
2554 store_by_pieces_1 (&data
, align
);
2559 gcc_assert (!data
.reverse
);
2564 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2565 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2567 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2568 plus_constant (to_addr_mode
,
2572 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2579 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2587 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2588 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2591 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2593 struct store_by_pieces_d data
;
2598 data
.constfun
= clear_by_pieces_1
;
2599 data
.constfundata
= NULL
;
2602 store_by_pieces_1 (&data
, align
);
2605 /* Callback routine for clear_by_pieces.
2606 Return const0_rtx unconditionally. */
2609 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2610 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2611 machine_mode mode ATTRIBUTE_UNUSED
)
2616 /* Subroutine of clear_by_pieces and store_by_pieces.
2617 Generate several move instructions to store LEN bytes of block TO. (A MEM
2618 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2621 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2622 unsigned int align ATTRIBUTE_UNUSED
)
2624 machine_mode to_addr_mode
= get_address_mode (data
->to
);
2625 rtx to_addr
= XEXP (data
->to
, 0);
2626 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2627 enum insn_code icode
;
2630 data
->to_addr
= to_addr
;
2632 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2633 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2635 data
->explicit_inc_to
= 0;
2637 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2639 data
->offset
= data
->len
;
2641 /* If storing requires more than two move insns,
2642 copy addresses to registers (to make displacements shorter)
2643 and use post-increment if available. */
2644 if (!data
->autinc_to
2645 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2647 /* Determine the main mode we'll be using.
2648 MODE might not be used depending on the definitions of the
2649 USE_* macros below. */
2650 machine_mode mode ATTRIBUTE_UNUSED
2651 = widest_int_mode_for_size (max_size
);
2653 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2655 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2656 plus_constant (to_addr_mode
,
2659 data
->autinc_to
= 1;
2660 data
->explicit_inc_to
= -1;
2663 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2664 && ! data
->autinc_to
)
2666 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2667 data
->autinc_to
= 1;
2668 data
->explicit_inc_to
= 1;
2671 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2672 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2675 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2677 /* First store what we can in the largest integer mode, then go to
2678 successively smaller modes. */
2680 while (max_size
> 1 && data
->len
> 0)
2682 machine_mode mode
= widest_int_mode_for_size (max_size
);
2684 if (mode
== VOIDmode
)
2687 icode
= optab_handler (mov_optab
, mode
);
2688 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2689 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2691 max_size
= GET_MODE_SIZE (mode
);
2694 /* The code above should have handled everything. */
2695 gcc_assert (!data
->len
);
2698 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2699 with move instructions for mode MODE. GENFUN is the gen_... function
2700 to make a move insn for that mode. DATA has all the other info. */
2703 store_by_pieces_2 (insn_gen_fn genfun
, machine_mode mode
,
2704 struct store_by_pieces_d
*data
)
2706 unsigned int size
= GET_MODE_SIZE (mode
);
2709 while (data
->len
>= size
)
2712 data
->offset
-= size
;
2714 if (data
->autinc_to
)
2715 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2718 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2720 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2721 emit_insn (gen_add2_insn (data
->to_addr
,
2722 gen_int_mode (-(HOST_WIDE_INT
) size
,
2723 GET_MODE (data
->to_addr
))));
2725 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2726 emit_insn ((*genfun
) (to1
, cst
));
2728 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2729 emit_insn (gen_add2_insn (data
->to_addr
,
2731 GET_MODE (data
->to_addr
))));
2733 if (! data
->reverse
)
2734 data
->offset
+= size
;
2740 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2741 its length in bytes. */
2744 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2745 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2746 unsigned HOST_WIDE_INT min_size
,
2747 unsigned HOST_WIDE_INT max_size
,
2748 unsigned HOST_WIDE_INT probable_max_size
)
2750 machine_mode mode
= GET_MODE (object
);
2753 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2755 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2756 just move a zero. Otherwise, do this a piece at a time. */
2758 && CONST_INT_P (size
)
2759 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2761 rtx zero
= CONST0_RTX (mode
);
2764 emit_move_insn (object
, zero
);
2768 if (COMPLEX_MODE_P (mode
))
2770 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2773 write_complex_part (object
, zero
, 0);
2774 write_complex_part (object
, zero
, 1);
2780 if (size
== const0_rtx
)
2783 align
= MEM_ALIGN (object
);
2785 if (CONST_INT_P (size
)
2786 && targetm
.use_by_pieces_infrastructure_p (INTVAL (size
), align
,
2788 optimize_insn_for_speed_p ()))
2789 clear_by_pieces (object
, INTVAL (size
), align
);
2790 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2791 expected_align
, expected_size
,
2792 min_size
, max_size
, probable_max_size
))
2794 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2795 return set_storage_via_libcall (object
, size
, const0_rtx
,
2796 method
== BLOCK_OP_TAILCALL
);
2804 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2806 unsigned HOST_WIDE_INT max
, min
= 0;
2807 if (GET_CODE (size
) == CONST_INT
)
2808 min
= max
= UINTVAL (size
);
2810 max
= GET_MODE_MASK (GET_MODE (size
));
2811 return clear_storage_hints (object
, size
, method
, 0, -1, min
, max
, max
);
2815 /* A subroutine of clear_storage. Expand a call to memset.
2816 Return the return value of memset, 0 otherwise. */
2819 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2821 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2822 machine_mode size_mode
;
2825 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2826 place those into new pseudos into a VAR_DECL and use them later. */
2828 object
= copy_addr_to_reg (XEXP (object
, 0));
2830 size_mode
= TYPE_MODE (sizetype
);
2831 size
= convert_to_mode (size_mode
, size
, 1);
2832 size
= copy_to_mode_reg (size_mode
, size
);
2834 /* It is incorrect to use the libcall calling conventions to call
2835 memset in this context. This could be a user call to memset and
2836 the user may wish to examine the return value from memset. For
2837 targets where libcalls and normal calls have different conventions
2838 for returning pointers, we could end up generating incorrect code. */
2840 object_tree
= make_tree (ptr_type_node
, object
);
2841 if (!CONST_INT_P (val
))
2842 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2843 size_tree
= make_tree (sizetype
, size
);
2844 val_tree
= make_tree (integer_type_node
, val
);
2846 fn
= clear_storage_libcall_fn (true);
2847 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2848 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2850 retval
= expand_normal (call_expr
);
2855 /* A subroutine of set_storage_via_libcall. Create the tree node
2856 for the function we use for block clears. */
2858 tree block_clear_fn
;
2861 init_block_clear_fn (const char *asmspec
)
2863 if (!block_clear_fn
)
2867 fn
= get_identifier ("memset");
2868 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2869 integer_type_node
, sizetype
,
2872 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2873 DECL_EXTERNAL (fn
) = 1;
2874 TREE_PUBLIC (fn
) = 1;
2875 DECL_ARTIFICIAL (fn
) = 1;
2876 TREE_NOTHROW (fn
) = 1;
2877 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2878 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2880 block_clear_fn
= fn
;
2884 set_user_assembler_name (block_clear_fn
, asmspec
);
2888 clear_storage_libcall_fn (int for_call
)
2890 static bool emitted_extern
;
2892 if (!block_clear_fn
)
2893 init_block_clear_fn (NULL
);
2895 if (for_call
&& !emitted_extern
)
2897 emitted_extern
= true;
2898 make_decl_rtl (block_clear_fn
);
2901 return block_clear_fn
;
2904 /* Expand a setmem pattern; return true if successful. */
2907 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2908 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2909 unsigned HOST_WIDE_INT min_size
,
2910 unsigned HOST_WIDE_INT max_size
,
2911 unsigned HOST_WIDE_INT probable_max_size
)
2913 /* Try the most limited insn first, because there's no point
2914 including more than one in the machine description unless
2915 the more limited one has some advantage. */
2919 if (expected_align
< align
)
2920 expected_align
= align
;
2921 if (expected_size
!= -1)
2923 if ((unsigned HOST_WIDE_INT
)expected_size
> max_size
)
2924 expected_size
= max_size
;
2925 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
2926 expected_size
= min_size
;
2929 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2930 mode
= GET_MODE_WIDER_MODE (mode
))
2932 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2934 if (code
!= CODE_FOR_nothing
2935 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2936 here because if SIZE is less than the mode mask, as it is
2937 returned by the macro, it will definitely be less than the
2938 actual mode mask. Since SIZE is within the Pmode address
2939 space, we limit MODE to Pmode. */
2940 && ((CONST_INT_P (size
)
2941 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2942 <= (GET_MODE_MASK (mode
) >> 1)))
2943 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
2944 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
2946 struct expand_operand ops
[9];
2949 nops
= insn_data
[(int) code
].n_generator_args
;
2950 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
2952 create_fixed_operand (&ops
[0], object
);
2953 /* The check above guarantees that this size conversion is valid. */
2954 create_convert_operand_to (&ops
[1], size
, mode
, true);
2955 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2956 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2959 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2960 create_integer_operand (&ops
[5], expected_size
);
2964 create_integer_operand (&ops
[6], min_size
);
2965 /* If we can not represent the maximal size,
2966 make parameter NULL. */
2967 if ((HOST_WIDE_INT
) max_size
!= -1)
2968 create_integer_operand (&ops
[7], max_size
);
2970 create_fixed_operand (&ops
[7], NULL
);
2974 /* If we can not represent the maximal size,
2975 make parameter NULL. */
2976 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
2977 create_integer_operand (&ops
[8], probable_max_size
);
2979 create_fixed_operand (&ops
[8], NULL
);
2981 if (maybe_expand_insn (code
, nops
, ops
))
2990 /* Write to one of the components of the complex value CPLX. Write VAL to
2991 the real part if IMAG_P is false, and the imaginary part if its true. */
2994 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
3000 if (GET_CODE (cplx
) == CONCAT
)
3002 emit_move_insn (XEXP (cplx
, imag_p
), val
);
3006 cmode
= GET_MODE (cplx
);
3007 imode
= GET_MODE_INNER (cmode
);
3008 ibitsize
= GET_MODE_BITSIZE (imode
);
3010 /* For MEMs simplify_gen_subreg may generate an invalid new address
3011 because, e.g., the original address is considered mode-dependent
3012 by the target, which restricts simplify_subreg from invoking
3013 adjust_address_nv. Instead of preparing fallback support for an
3014 invalid address, we call adjust_address_nv directly. */
3017 emit_move_insn (adjust_address_nv (cplx
, imode
,
3018 imag_p
? GET_MODE_SIZE (imode
) : 0),
3023 /* If the sub-object is at least word sized, then we know that subregging
3024 will work. This special case is important, since store_bit_field
3025 wants to operate on integer modes, and there's rarely an OImode to
3026 correspond to TCmode. */
3027 if (ibitsize
>= BITS_PER_WORD
3028 /* For hard regs we have exact predicates. Assume we can split
3029 the original object if it spans an even number of hard regs.
3030 This special case is important for SCmode on 64-bit platforms
3031 where the natural size of floating-point regs is 32-bit. */
3033 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3034 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3036 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
3037 imag_p
? GET_MODE_SIZE (imode
) : 0);
3040 emit_move_insn (part
, val
);
3044 /* simplify_gen_subreg may fail for sub-word MEMs. */
3045 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3048 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
3051 /* Extract one of the components of the complex value CPLX. Extract the
3052 real part if IMAG_P is false, and the imaginary part if it's true. */
3055 read_complex_part (rtx cplx
, bool imag_p
)
3057 machine_mode cmode
, imode
;
3060 if (GET_CODE (cplx
) == CONCAT
)
3061 return XEXP (cplx
, imag_p
);
3063 cmode
= GET_MODE (cplx
);
3064 imode
= GET_MODE_INNER (cmode
);
3065 ibitsize
= GET_MODE_BITSIZE (imode
);
3067 /* Special case reads from complex constants that got spilled to memory. */
3068 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
3070 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
3071 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
3073 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
3074 if (CONSTANT_CLASS_P (part
))
3075 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
3079 /* For MEMs simplify_gen_subreg may generate an invalid new address
3080 because, e.g., the original address is considered mode-dependent
3081 by the target, which restricts simplify_subreg from invoking
3082 adjust_address_nv. Instead of preparing fallback support for an
3083 invalid address, we call adjust_address_nv directly. */
3085 return adjust_address_nv (cplx
, imode
,
3086 imag_p
? GET_MODE_SIZE (imode
) : 0);
3088 /* If the sub-object is at least word sized, then we know that subregging
3089 will work. This special case is important, since extract_bit_field
3090 wants to operate on integer modes, and there's rarely an OImode to
3091 correspond to TCmode. */
3092 if (ibitsize
>= BITS_PER_WORD
3093 /* For hard regs we have exact predicates. Assume we can split
3094 the original object if it spans an even number of hard regs.
3095 This special case is important for SCmode on 64-bit platforms
3096 where the natural size of floating-point regs is 32-bit. */
3098 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3099 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3101 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3102 imag_p
? GET_MODE_SIZE (imode
) : 0);
3106 /* simplify_gen_subreg may fail for sub-word MEMs. */
3107 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3110 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3111 true, NULL_RTX
, imode
, imode
);
3114 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3115 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3116 represented in NEW_MODE. If FORCE is true, this will never happen, as
3117 we'll force-create a SUBREG if needed. */
3120 emit_move_change_mode (machine_mode new_mode
,
3121 machine_mode old_mode
, rtx x
, bool force
)
3125 if (push_operand (x
, GET_MODE (x
)))
3127 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3128 MEM_COPY_ATTRIBUTES (ret
, x
);
3132 /* We don't have to worry about changing the address since the
3133 size in bytes is supposed to be the same. */
3134 if (reload_in_progress
)
3136 /* Copy the MEM to change the mode and move any
3137 substitutions from the old MEM to the new one. */
3138 ret
= adjust_address_nv (x
, new_mode
, 0);
3139 copy_replacements (x
, ret
);
3142 ret
= adjust_address (x
, new_mode
, 0);
3146 /* Note that we do want simplify_subreg's behavior of validating
3147 that the new mode is ok for a hard register. If we were to use
3148 simplify_gen_subreg, we would create the subreg, but would
3149 probably run into the target not being able to implement it. */
3150 /* Except, of course, when FORCE is true, when this is exactly what
3151 we want. Which is needed for CCmodes on some targets. */
3153 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3155 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3161 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3162 an integer mode of the same size as MODE. Returns the instruction
3163 emitted, or NULL if such a move could not be generated. */
3166 emit_move_via_integer (machine_mode mode
, rtx x
, rtx y
, bool force
)
3169 enum insn_code code
;
3171 /* There must exist a mode of the exact size we require. */
3172 imode
= int_mode_for_mode (mode
);
3173 if (imode
== BLKmode
)
3176 /* The target must support moves in this mode. */
3177 code
= optab_handler (mov_optab
, imode
);
3178 if (code
== CODE_FOR_nothing
)
3181 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3184 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3187 return emit_insn (GEN_FCN (code
) (x
, y
));
3190 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3191 Return an equivalent MEM that does not use an auto-increment. */
3194 emit_move_resolve_push (machine_mode mode
, rtx x
)
3196 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3197 HOST_WIDE_INT adjust
;
3200 adjust
= GET_MODE_SIZE (mode
);
3201 #ifdef PUSH_ROUNDING
3202 adjust
= PUSH_ROUNDING (adjust
);
3204 if (code
== PRE_DEC
|| code
== POST_DEC
)
3206 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3208 rtx expr
= XEXP (XEXP (x
, 0), 1);
3211 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3212 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3213 val
= INTVAL (XEXP (expr
, 1));
3214 if (GET_CODE (expr
) == MINUS
)
3216 gcc_assert (adjust
== val
|| adjust
== -val
);
3220 /* Do not use anti_adjust_stack, since we don't want to update
3221 stack_pointer_delta. */
3222 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3223 gen_int_mode (adjust
, Pmode
), stack_pointer_rtx
,
3224 0, OPTAB_LIB_WIDEN
);
3225 if (temp
!= stack_pointer_rtx
)
3226 emit_move_insn (stack_pointer_rtx
, temp
);
3233 temp
= stack_pointer_rtx
;
3238 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3244 return replace_equiv_address (x
, temp
);
3247 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3248 X is known to satisfy push_operand, and MODE is known to be complex.
3249 Returns the last instruction emitted. */
3252 emit_move_complex_push (machine_mode mode
, rtx x
, rtx y
)
3254 machine_mode submode
= GET_MODE_INNER (mode
);
3257 #ifdef PUSH_ROUNDING
3258 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3260 /* In case we output to the stack, but the size is smaller than the
3261 machine can push exactly, we need to use move instructions. */
3262 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3264 x
= emit_move_resolve_push (mode
, x
);
3265 return emit_move_insn (x
, y
);
3269 /* Note that the real part always precedes the imag part in memory
3270 regardless of machine's endianness. */
3271 switch (GET_CODE (XEXP (x
, 0)))
3285 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3286 read_complex_part (y
, imag_first
));
3287 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3288 read_complex_part (y
, !imag_first
));
3291 /* A subroutine of emit_move_complex. Perform the move from Y to X
3292 via two moves of the parts. Returns the last instruction emitted. */
3295 emit_move_complex_parts (rtx x
, rtx y
)
3297 /* Show the output dies here. This is necessary for SUBREGs
3298 of pseudos since we cannot track their lifetimes correctly;
3299 hard regs shouldn't appear here except as return values. */
3300 if (!reload_completed
&& !reload_in_progress
3301 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3304 write_complex_part (x
, read_complex_part (y
, false), false);
3305 write_complex_part (x
, read_complex_part (y
, true), true);
3307 return get_last_insn ();
3310 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3311 MODE is known to be complex. Returns the last instruction emitted. */
3314 emit_move_complex (machine_mode mode
, rtx x
, rtx y
)
3318 /* Need to take special care for pushes, to maintain proper ordering
3319 of the data, and possibly extra padding. */
3320 if (push_operand (x
, mode
))
3321 return emit_move_complex_push (mode
, x
, y
);
3323 /* See if we can coerce the target into moving both values at once, except
3324 for floating point where we favor moving as parts if this is easy. */
3325 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3326 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
3328 && HARD_REGISTER_P (x
)
3329 && hard_regno_nregs
[REGNO (x
)][mode
] == 1)
3331 && HARD_REGISTER_P (y
)
3332 && hard_regno_nregs
[REGNO (y
)][mode
] == 1))
3334 /* Not possible if the values are inherently not adjacent. */
3335 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3337 /* Is possible if both are registers (or subregs of registers). */
3338 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3340 /* If one of the operands is a memory, and alignment constraints
3341 are friendly enough, we may be able to do combined memory operations.
3342 We do not attempt this if Y is a constant because that combination is
3343 usually better with the by-parts thing below. */
3344 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3345 && (!STRICT_ALIGNMENT
3346 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3355 /* For memory to memory moves, optimal behavior can be had with the
3356 existing block move logic. */
3357 if (MEM_P (x
) && MEM_P (y
))
3359 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3360 BLOCK_OP_NO_LIBCALL
);
3361 return get_last_insn ();
3364 ret
= emit_move_via_integer (mode
, x
, y
, true);
3369 return emit_move_complex_parts (x
, y
);
3372 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3373 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3376 emit_move_ccmode (machine_mode mode
, rtx x
, rtx y
)
3380 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3383 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3384 if (code
!= CODE_FOR_nothing
)
3386 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3387 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3388 return emit_insn (GEN_FCN (code
) (x
, y
));
3392 /* Otherwise, find the MODE_INT mode of the same width. */
3393 ret
= emit_move_via_integer (mode
, x
, y
, false);
3394 gcc_assert (ret
!= NULL
);
3398 /* Return true if word I of OP lies entirely in the
3399 undefined bits of a paradoxical subreg. */
3402 undefined_operand_subword_p (const_rtx op
, int i
)
3404 machine_mode innermode
, innermostmode
;
3406 if (GET_CODE (op
) != SUBREG
)
3408 innermode
= GET_MODE (op
);
3409 innermostmode
= GET_MODE (SUBREG_REG (op
));
3410 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3411 /* The SUBREG_BYTE represents offset, as if the value were stored in
3412 memory, except for a paradoxical subreg where we define
3413 SUBREG_BYTE to be 0; undo this exception as in
3415 if (SUBREG_BYTE (op
) == 0
3416 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3418 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3419 if (WORDS_BIG_ENDIAN
)
3420 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3421 if (BYTES_BIG_ENDIAN
)
3422 offset
+= difference
% UNITS_PER_WORD
;
3424 if (offset
>= GET_MODE_SIZE (innermostmode
)
3425 || offset
<= -GET_MODE_SIZE (word_mode
))
3430 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3431 MODE is any multi-word or full-word mode that lacks a move_insn
3432 pattern. Note that you will get better code if you define such
3433 patterns, even if they must turn into multiple assembler instructions. */
3436 emit_move_multi_word (machine_mode mode
, rtx x
, rtx y
)
3438 rtx_insn
*last_insn
= 0;
3444 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3446 /* If X is a push on the stack, do the push now and replace
3447 X with a reference to the stack pointer. */
3448 if (push_operand (x
, mode
))
3449 x
= emit_move_resolve_push (mode
, x
);
3451 /* If we are in reload, see if either operand is a MEM whose address
3452 is scheduled for replacement. */
3453 if (reload_in_progress
&& MEM_P (x
)
3454 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3455 x
= replace_equiv_address_nv (x
, inner
);
3456 if (reload_in_progress
&& MEM_P (y
)
3457 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3458 y
= replace_equiv_address_nv (y
, inner
);
3462 need_clobber
= false;
3464 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3467 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3470 /* Do not generate code for a move if it would come entirely
3471 from the undefined bits of a paradoxical subreg. */
3472 if (undefined_operand_subword_p (y
, i
))
3475 ypart
= operand_subword (y
, i
, 1, mode
);
3477 /* If we can't get a part of Y, put Y into memory if it is a
3478 constant. Otherwise, force it into a register. Then we must
3479 be able to get a part of Y. */
3480 if (ypart
== 0 && CONSTANT_P (y
))
3482 y
= use_anchored_address (force_const_mem (mode
, y
));
3483 ypart
= operand_subword (y
, i
, 1, mode
);
3485 else if (ypart
== 0)
3486 ypart
= operand_subword_force (y
, i
, mode
);
3488 gcc_assert (xpart
&& ypart
);
3490 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3492 last_insn
= emit_move_insn (xpart
, ypart
);
3498 /* Show the output dies here. This is necessary for SUBREGs
3499 of pseudos since we cannot track their lifetimes correctly;
3500 hard regs shouldn't appear here except as return values.
3501 We never want to emit such a clobber after reload. */
3503 && ! (reload_in_progress
|| reload_completed
)
3504 && need_clobber
!= 0)
3512 /* Low level part of emit_move_insn.
3513 Called just like emit_move_insn, but assumes X and Y
3514 are basically valid. */
3517 emit_move_insn_1 (rtx x
, rtx y
)
3519 machine_mode mode
= GET_MODE (x
);
3520 enum insn_code code
;
3522 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3524 code
= optab_handler (mov_optab
, mode
);
3525 if (code
!= CODE_FOR_nothing
)
3526 return emit_insn (GEN_FCN (code
) (x
, y
));
3528 /* Expand complex moves by moving real part and imag part. */
3529 if (COMPLEX_MODE_P (mode
))
3530 return emit_move_complex (mode
, x
, y
);
3532 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3533 || ALL_FIXED_POINT_MODE_P (mode
))
3535 rtx_insn
*result
= emit_move_via_integer (mode
, x
, y
, true);
3537 /* If we can't find an integer mode, use multi words. */
3541 return emit_move_multi_word (mode
, x
, y
);
3544 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3545 return emit_move_ccmode (mode
, x
, y
);
3547 /* Try using a move pattern for the corresponding integer mode. This is
3548 only safe when simplify_subreg can convert MODE constants into integer
3549 constants. At present, it can only do this reliably if the value
3550 fits within a HOST_WIDE_INT. */
3551 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3553 rtx_insn
*ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3557 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3562 return emit_move_multi_word (mode
, x
, y
);
3565 /* Generate code to copy Y into X.
3566 Both Y and X must have the same mode, except that
3567 Y can be a constant with VOIDmode.
3568 This mode cannot be BLKmode; use emit_block_move for that.
3570 Return the last instruction emitted. */
3573 emit_move_insn (rtx x
, rtx y
)
3575 machine_mode mode
= GET_MODE (x
);
3576 rtx y_cst
= NULL_RTX
;
3577 rtx_insn
*last_insn
;
3580 gcc_assert (mode
!= BLKmode
3581 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3586 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3587 && (last_insn
= compress_float_constant (x
, y
)))
3592 if (!targetm
.legitimate_constant_p (mode
, y
))
3594 y
= force_const_mem (mode
, y
);
3596 /* If the target's cannot_force_const_mem prevented the spill,
3597 assume that the target's move expanders will also take care
3598 of the non-legitimate constant. */
3602 y
= use_anchored_address (y
);
3606 /* If X or Y are memory references, verify that their addresses are valid
3609 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3611 && ! push_operand (x
, GET_MODE (x
))))
3612 x
= validize_mem (x
);
3615 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3616 MEM_ADDR_SPACE (y
)))
3617 y
= validize_mem (y
);
3619 gcc_assert (mode
!= BLKmode
);
3621 last_insn
= emit_move_insn_1 (x
, y
);
3623 if (y_cst
&& REG_P (x
)
3624 && (set
= single_set (last_insn
)) != NULL_RTX
3625 && SET_DEST (set
) == x
3626 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3627 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3632 /* Generate the body of an instruction to copy Y into X.
3633 It may be a list of insns, if one insn isn't enough. */
3636 gen_move_insn (rtx x
, rtx y
)
3641 emit_move_insn_1 (x
, y
);
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 machine_mode dstmode
= GET_MODE (x
);
3655 machine_mode orig_srcmode
= GET_MODE (y
);
3656 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
))
3674 rtx_insn
*last_insn
;
3676 /* Skip if the target can't extend this way. */
3677 ic
= can_extend_p (dstmode
, srcmode
, 0);
3678 if (ic
== CODE_FOR_nothing
)
3681 /* Skip if the narrowed value isn't exact. */
3682 if (! exact_real_truncate (srcmode
, &r
))
3685 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3687 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3689 /* Skip if the target needs extra instructions to perform
3691 if (!insn_operand_matches (ic
, 1, trunc_y
))
3693 /* This is valid, but may not be cheaper than the original. */
3694 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3696 if (oldcost
< newcost
)
3699 else if (float_extend_from_mem
[dstmode
][srcmode
])
3701 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3702 /* This is valid, but may not be cheaper than the original. */
3703 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3705 if (oldcost
< newcost
)
3707 trunc_y
= validize_mem (trunc_y
);
3712 /* For CSE's benefit, force the compressed constant pool entry
3713 into a new pseudo. This constant may be used in different modes,
3714 and if not, combine will put things back together for us. */
3715 trunc_y
= force_reg (srcmode
, trunc_y
);
3717 /* If x is a hard register, perform the extension into a pseudo,
3718 so that e.g. stack realignment code is aware of it. */
3720 if (REG_P (x
) && HARD_REGISTER_P (x
))
3721 target
= gen_reg_rtx (dstmode
);
3723 emit_unop_insn (ic
, target
, trunc_y
, UNKNOWN
);
3724 last_insn
= get_last_insn ();
3727 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3730 return emit_move_insn (x
, target
);
3737 /* Pushing data onto the stack. */
3739 /* Push a block of length SIZE (perhaps variable)
3740 and return an rtx to address the beginning of the block.
3741 The value may be virtual_outgoing_args_rtx.
3743 EXTRA is the number of bytes of padding to push in addition to SIZE.
3744 BELOW nonzero means this padding comes at low addresses;
3745 otherwise, the padding comes at high addresses. */
3748 push_block (rtx size
, int extra
, int below
)
3752 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3753 if (CONSTANT_P (size
))
3754 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3755 else if (REG_P (size
) && extra
== 0)
3756 anti_adjust_stack (size
);
3759 temp
= copy_to_mode_reg (Pmode
, size
);
3761 temp
= expand_binop (Pmode
, add_optab
, temp
,
3762 gen_int_mode (extra
, Pmode
),
3763 temp
, 0, OPTAB_LIB_WIDEN
);
3764 anti_adjust_stack (temp
);
3767 #ifndef STACK_GROWS_DOWNWARD
3773 temp
= virtual_outgoing_args_rtx
;
3774 if (extra
!= 0 && below
)
3775 temp
= plus_constant (Pmode
, temp
, extra
);
3779 if (CONST_INT_P (size
))
3780 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3781 -INTVAL (size
) - (below
? 0 : extra
));
3782 else if (extra
!= 0 && !below
)
3783 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3784 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3787 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3788 negate_rtx (Pmode
, size
));
3791 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3794 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3797 mem_autoinc_base (rtx mem
)
3801 rtx addr
= XEXP (mem
, 0);
3802 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3803 return XEXP (addr
, 0);
3808 /* A utility routine used here, in reload, and in try_split. The insns
3809 after PREV up to and including LAST are known to adjust the stack,
3810 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3811 placing notes as appropriate. PREV may be NULL, indicating the
3812 entire insn sequence prior to LAST should be scanned.
3814 The set of allowed stack pointer modifications is small:
3815 (1) One or more auto-inc style memory references (aka pushes),
3816 (2) One or more addition/subtraction with the SP as destination,
3817 (3) A single move insn with the SP as destination,
3818 (4) A call_pop insn,
3819 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3821 Insns in the sequence that do not modify the SP are ignored,
3822 except for noreturn calls.
3824 The return value is the amount of adjustment that can be trivially
3825 verified, via immediate operand or auto-inc. If the adjustment
3826 cannot be trivially extracted, the return value is INT_MIN. */
3829 find_args_size_adjust (rtx_insn
*insn
)
3834 pat
= PATTERN (insn
);
3837 /* Look for a call_pop pattern. */
3840 /* We have to allow non-call_pop patterns for the case
3841 of emit_single_push_insn of a TLS address. */
3842 if (GET_CODE (pat
) != PARALLEL
)
3845 /* All call_pop have a stack pointer adjust in the parallel.
3846 The call itself is always first, and the stack adjust is
3847 usually last, so search from the end. */
3848 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3850 set
= XVECEXP (pat
, 0, i
);
3851 if (GET_CODE (set
) != SET
)
3853 dest
= SET_DEST (set
);
3854 if (dest
== stack_pointer_rtx
)
3857 /* We'd better have found the stack pointer adjust. */
3860 /* Fall through to process the extracted SET and DEST
3861 as if it was a standalone insn. */
3863 else if (GET_CODE (pat
) == SET
)
3865 else if ((set
= single_set (insn
)) != NULL
)
3867 else if (GET_CODE (pat
) == PARALLEL
)
3869 /* ??? Some older ports use a parallel with a stack adjust
3870 and a store for a PUSH_ROUNDING pattern, rather than a
3871 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3872 /* ??? See h8300 and m68k, pushqi1. */
3873 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3875 set
= XVECEXP (pat
, 0, i
);
3876 if (GET_CODE (set
) != SET
)
3878 dest
= SET_DEST (set
);
3879 if (dest
== stack_pointer_rtx
)
3882 /* We do not expect an auto-inc of the sp in the parallel. */
3883 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3884 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3885 != stack_pointer_rtx
);
3893 dest
= SET_DEST (set
);
3895 /* Look for direct modifications of the stack pointer. */
3896 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3898 /* Look for a trivial adjustment, otherwise assume nothing. */
3899 /* Note that the SPU restore_stack_block pattern refers to
3900 the stack pointer in V4SImode. Consider that non-trivial. */
3901 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3902 && GET_CODE (SET_SRC (set
)) == PLUS
3903 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3904 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3905 return INTVAL (XEXP (SET_SRC (set
), 1));
3906 /* ??? Reload can generate no-op moves, which will be cleaned
3907 up later. Recognize it and continue searching. */
3908 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3911 return HOST_WIDE_INT_MIN
;
3917 /* Otherwise only think about autoinc patterns. */
3918 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3921 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3922 != stack_pointer_rtx
);
3924 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3925 mem
= SET_SRC (set
);
3929 addr
= XEXP (mem
, 0);
3930 switch (GET_CODE (addr
))
3934 return GET_MODE_SIZE (GET_MODE (mem
));
3937 return -GET_MODE_SIZE (GET_MODE (mem
));
3940 addr
= XEXP (addr
, 1);
3941 gcc_assert (GET_CODE (addr
) == PLUS
);
3942 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3943 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3944 return INTVAL (XEXP (addr
, 1));
3952 fixup_args_size_notes (rtx_insn
*prev
, rtx_insn
*last
, int end_args_size
)
3954 int args_size
= end_args_size
;
3955 bool saw_unknown
= false;
3958 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3960 HOST_WIDE_INT this_delta
;
3962 if (!NONDEBUG_INSN_P (insn
))
3965 this_delta
= find_args_size_adjust (insn
);
3966 if (this_delta
== 0)
3969 || ACCUMULATE_OUTGOING_ARGS
3970 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3974 gcc_assert (!saw_unknown
);
3975 if (this_delta
== HOST_WIDE_INT_MIN
)
3978 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3979 #ifdef STACK_GROWS_DOWNWARD
3980 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3982 args_size
-= this_delta
;
3985 return saw_unknown
? INT_MIN
: args_size
;
3988 #ifdef PUSH_ROUNDING
3989 /* Emit single push insn. */
3992 emit_single_push_insn_1 (machine_mode mode
, rtx x
, tree type
)
3995 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3997 enum insn_code icode
;
3999 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
4000 /* If there is push pattern, use it. Otherwise try old way of throwing
4001 MEM representing push operation to move expander. */
4002 icode
= optab_handler (push_optab
, mode
);
4003 if (icode
!= CODE_FOR_nothing
)
4005 struct expand_operand ops
[1];
4007 create_input_operand (&ops
[0], x
, mode
);
4008 if (maybe_expand_insn (icode
, 1, ops
))
4011 if (GET_MODE_SIZE (mode
) == rounded_size
)
4012 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
4013 /* If we are to pad downward, adjust the stack pointer first and
4014 then store X into the stack location using an offset. This is
4015 because emit_move_insn does not know how to pad; it does not have
4017 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
4019 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
4020 HOST_WIDE_INT offset
;
4022 emit_move_insn (stack_pointer_rtx
,
4023 expand_binop (Pmode
,
4024 #ifdef STACK_GROWS_DOWNWARD
4030 gen_int_mode (rounded_size
, Pmode
),
4031 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
4033 offset
= (HOST_WIDE_INT
) padding_size
;
4034 #ifdef STACK_GROWS_DOWNWARD
4035 if (STACK_PUSH_CODE
== POST_DEC
)
4036 /* We have already decremented the stack pointer, so get the
4038 offset
+= (HOST_WIDE_INT
) rounded_size
;
4040 if (STACK_PUSH_CODE
== POST_INC
)
4041 /* We have already incremented the stack pointer, so get the
4043 offset
-= (HOST_WIDE_INT
) rounded_size
;
4045 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4046 gen_int_mode (offset
, Pmode
));
4050 #ifdef STACK_GROWS_DOWNWARD
4051 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4052 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4053 gen_int_mode (-(HOST_WIDE_INT
) rounded_size
,
4056 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4057 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4058 gen_int_mode (rounded_size
, Pmode
));
4060 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
4063 dest
= gen_rtx_MEM (mode
, dest_addr
);
4067 set_mem_attributes (dest
, type
, 1);
4069 if (cfun
->tail_call_marked
)
4070 /* Function incoming arguments may overlap with sibling call
4071 outgoing arguments and we cannot allow reordering of reads
4072 from function arguments with stores to outgoing arguments
4073 of sibling calls. */
4074 set_mem_alias_set (dest
, 0);
4076 emit_move_insn (dest
, x
);
4079 /* Emit and annotate a single push insn. */
4082 emit_single_push_insn (machine_mode mode
, rtx x
, tree type
)
4084 int delta
, old_delta
= stack_pointer_delta
;
4085 rtx_insn
*prev
= get_last_insn ();
4088 emit_single_push_insn_1 (mode
, x
, type
);
4090 last
= get_last_insn ();
4092 /* Notice the common case where we emitted exactly one insn. */
4093 if (PREV_INSN (last
) == prev
)
4095 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
4099 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
4100 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
4104 /* Generate code to push X onto the stack, assuming it has mode MODE and
4106 MODE is redundant except when X is a CONST_INT (since they don't
4108 SIZE is an rtx for the size of data to be copied (in bytes),
4109 needed only if X is BLKmode.
4111 ALIGN (in bits) is maximum alignment we can assume.
4113 If PARTIAL and REG are both nonzero, then copy that many of the first
4114 bytes of X into registers starting with REG, and push the rest of X.
4115 The amount of space pushed is decreased by PARTIAL bytes.
4116 REG must be a hard register in this case.
4117 If REG is zero but PARTIAL is not, take any all others actions for an
4118 argument partially in registers, but do not actually load any
4121 EXTRA is the amount in bytes of extra space to leave next to this arg.
4122 This is ignored if an argument block has already been allocated.
4124 On a machine that lacks real push insns, ARGS_ADDR is the address of
4125 the bottom of the argument block for this call. We use indexing off there
4126 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4127 argument block has not been preallocated.
4129 ARGS_SO_FAR is the size of args previously pushed for this call.
4131 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4132 for arguments passed in registers. If nonzero, it will be the number
4133 of bytes required. */
4136 emit_push_insn (rtx x
, machine_mode mode
, tree type
, rtx size
,
4137 unsigned int align
, int partial
, rtx reg
, int extra
,
4138 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4142 enum direction stack_direction
4143 #ifdef STACK_GROWS_DOWNWARD
4149 /* Decide where to pad the argument: `downward' for below,
4150 `upward' for above, or `none' for don't pad it.
4151 Default is below for small data on big-endian machines; else above. */
4152 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4154 /* Invert direction if stack is post-decrement.
4156 if (STACK_PUSH_CODE
== POST_DEC
)
4157 if (where_pad
!= none
)
4158 where_pad
= (where_pad
== downward
? upward
: downward
);
4163 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4165 /* Copy a block into the stack, entirely or partially. */
4172 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4173 used
= partial
- offset
;
4175 if (mode
!= BLKmode
)
4177 /* A value is to be stored in an insufficiently aligned
4178 stack slot; copy via a suitably aligned slot if
4180 size
= GEN_INT (GET_MODE_SIZE (mode
));
4181 if (!MEM_P (xinner
))
4183 temp
= assign_temp (type
, 1, 1);
4184 emit_move_insn (temp
, xinner
);
4191 /* USED is now the # of bytes we need not copy to the stack
4192 because registers will take care of them. */
4195 xinner
= adjust_address (xinner
, BLKmode
, used
);
4197 /* If the partial register-part of the arg counts in its stack size,
4198 skip the part of stack space corresponding to the registers.
4199 Otherwise, start copying to the beginning of the stack space,
4200 by setting SKIP to 0. */
4201 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4203 #ifdef PUSH_ROUNDING
4204 /* Do it with several push insns if that doesn't take lots of insns
4205 and if there is no difficulty with push insns that skip bytes
4206 on the stack for alignment purposes. */
4209 && CONST_INT_P (size
)
4211 && MEM_ALIGN (xinner
) >= align
4212 && can_move_by_pieces ((unsigned) INTVAL (size
) - used
, align
)
4213 /* Here we avoid the case of a structure whose weak alignment
4214 forces many pushes of a small amount of data,
4215 and such small pushes do rounding that causes trouble. */
4216 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4217 || align
>= BIGGEST_ALIGNMENT
4218 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4219 == (align
/ BITS_PER_UNIT
)))
4220 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4222 /* Push padding now if padding above and stack grows down,
4223 or if padding below and stack grows up.
4224 But if space already allocated, this has already been done. */
4225 if (extra
&& args_addr
== 0
4226 && where_pad
!= none
&& where_pad
!= stack_direction
)
4227 anti_adjust_stack (GEN_INT (extra
));
4229 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4232 #endif /* PUSH_ROUNDING */
4236 /* Otherwise make space on the stack and copy the data
4237 to the address of that space. */
4239 /* Deduct words put into registers from the size we must copy. */
4242 if (CONST_INT_P (size
))
4243 size
= GEN_INT (INTVAL (size
) - used
);
4245 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4246 gen_int_mode (used
, GET_MODE (size
)),
4247 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4250 /* Get the address of the stack space.
4251 In this case, we do not deal with EXTRA separately.
4252 A single stack adjust will do. */
4255 temp
= push_block (size
, extra
, where_pad
== downward
);
4258 else if (CONST_INT_P (args_so_far
))
4259 temp
= memory_address (BLKmode
,
4260 plus_constant (Pmode
, args_addr
,
4261 skip
+ INTVAL (args_so_far
)));
4263 temp
= memory_address (BLKmode
,
4264 plus_constant (Pmode
,
4265 gen_rtx_PLUS (Pmode
,
4270 if (!ACCUMULATE_OUTGOING_ARGS
)
4272 /* If the source is referenced relative to the stack pointer,
4273 copy it to another register to stabilize it. We do not need
4274 to do this if we know that we won't be changing sp. */
4276 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4277 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4278 temp
= copy_to_reg (temp
);
4281 target
= gen_rtx_MEM (BLKmode
, temp
);
4283 /* We do *not* set_mem_attributes here, because incoming arguments
4284 may overlap with sibling call outgoing arguments and we cannot
4285 allow reordering of reads from function arguments with stores
4286 to outgoing arguments of sibling calls. We do, however, want
4287 to record the alignment of the stack slot. */
4288 /* ALIGN may well be better aligned than TYPE, e.g. due to
4289 PARM_BOUNDARY. Assume the caller isn't lying. */
4290 set_mem_align (target
, align
);
4292 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4295 else if (partial
> 0)
4297 /* Scalar partly in registers. */
4299 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4302 /* # bytes of start of argument
4303 that we must make space for but need not store. */
4304 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4305 int args_offset
= INTVAL (args_so_far
);
4308 /* Push padding now if padding above and stack grows down,
4309 or if padding below and stack grows up.
4310 But if space already allocated, this has already been done. */
4311 if (extra
&& args_addr
== 0
4312 && where_pad
!= none
&& where_pad
!= stack_direction
)
4313 anti_adjust_stack (GEN_INT (extra
));
4315 /* If we make space by pushing it, we might as well push
4316 the real data. Otherwise, we can leave OFFSET nonzero
4317 and leave the space uninitialized. */
4321 /* Now NOT_STACK gets the number of words that we don't need to
4322 allocate on the stack. Convert OFFSET to words too. */
4323 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4324 offset
/= UNITS_PER_WORD
;
4326 /* If the partial register-part of the arg counts in its stack size,
4327 skip the part of stack space corresponding to the registers.
4328 Otherwise, start copying to the beginning of the stack space,
4329 by setting SKIP to 0. */
4330 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4332 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4333 x
= validize_mem (force_const_mem (mode
, x
));
4335 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4336 SUBREGs of such registers are not allowed. */
4337 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4338 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4339 x
= copy_to_reg (x
);
4341 /* Loop over all the words allocated on the stack for this arg. */
4342 /* We can do it by words, because any scalar bigger than a word
4343 has a size a multiple of a word. */
4344 for (i
= size
- 1; i
>= not_stack
; i
--)
4345 if (i
>= not_stack
+ offset
)
4346 emit_push_insn (operand_subword_force (x
, i
, mode
),
4347 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4349 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4351 reg_parm_stack_space
, alignment_pad
);
4358 /* Push padding now if padding above and stack grows down,
4359 or if padding below and stack grows up.
4360 But if space already allocated, this has already been done. */
4361 if (extra
&& args_addr
== 0
4362 && where_pad
!= none
&& where_pad
!= stack_direction
)
4363 anti_adjust_stack (GEN_INT (extra
));
4365 #ifdef PUSH_ROUNDING
4366 if (args_addr
== 0 && PUSH_ARGS
)
4367 emit_single_push_insn (mode
, x
, type
);
4371 if (CONST_INT_P (args_so_far
))
4373 = memory_address (mode
,
4374 plus_constant (Pmode
, args_addr
,
4375 INTVAL (args_so_far
)));
4377 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4379 dest
= gen_rtx_MEM (mode
, addr
);
4381 /* We do *not* set_mem_attributes here, because incoming arguments
4382 may overlap with sibling call outgoing arguments and we cannot
4383 allow reordering of reads from function arguments with stores
4384 to outgoing arguments of sibling calls. We do, however, want
4385 to record the alignment of the stack slot. */
4386 /* ALIGN may well be better aligned than TYPE, e.g. due to
4387 PARM_BOUNDARY. Assume the caller isn't lying. */
4388 set_mem_align (dest
, align
);
4390 emit_move_insn (dest
, x
);
4394 /* If part should go in registers, copy that part
4395 into the appropriate registers. Do this now, at the end,
4396 since mem-to-mem copies above may do function calls. */
4397 if (partial
> 0 && reg
!= 0)
4399 /* Handle calls that pass values in multiple non-contiguous locations.
4400 The Irix 6 ABI has examples of this. */
4401 if (GET_CODE (reg
) == PARALLEL
)
4402 emit_group_load (reg
, x
, type
, -1);
4405 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4406 move_block_to_reg (REGNO (reg
), x
, partial
/ UNITS_PER_WORD
, mode
);
4410 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4411 anti_adjust_stack (GEN_INT (extra
));
4413 if (alignment_pad
&& args_addr
== 0)
4414 anti_adjust_stack (alignment_pad
);
4417 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4421 get_subtarget (rtx x
)
4425 /* Only registers can be subtargets. */
4427 /* Don't use hard regs to avoid extending their life. */
4428 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4432 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4433 FIELD is a bitfield. Returns true if the optimization was successful,
4434 and there's nothing else to do. */
4437 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4438 unsigned HOST_WIDE_INT bitpos
,
4439 unsigned HOST_WIDE_INT bitregion_start
,
4440 unsigned HOST_WIDE_INT bitregion_end
,
4441 machine_mode mode1
, rtx str_rtx
,
4444 machine_mode str_mode
= GET_MODE (str_rtx
);
4445 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4450 enum tree_code code
;
4452 if (mode1
!= VOIDmode
4453 || bitsize
>= BITS_PER_WORD
4454 || str_bitsize
> BITS_PER_WORD
4455 || TREE_SIDE_EFFECTS (to
)
4456 || TREE_THIS_VOLATILE (to
))
4460 if (TREE_CODE (src
) != SSA_NAME
)
4462 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4465 srcstmt
= get_gimple_for_ssa_name (src
);
4467 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4470 code
= gimple_assign_rhs_code (srcstmt
);
4472 op0
= gimple_assign_rhs1 (srcstmt
);
4474 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4475 to find its initialization. Hopefully the initialization will
4476 be from a bitfield load. */
4477 if (TREE_CODE (op0
) == SSA_NAME
)
4479 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4481 /* We want to eventually have OP0 be the same as TO, which
4482 should be a bitfield. */
4484 || !is_gimple_assign (op0stmt
)
4485 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4487 op0
= gimple_assign_rhs1 (op0stmt
);
4490 op1
= gimple_assign_rhs2 (srcstmt
);
4492 if (!operand_equal_p (to
, op0
, 0))
4495 if (MEM_P (str_rtx
))
4497 unsigned HOST_WIDE_INT offset1
;
4499 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4500 str_mode
= word_mode
;
4501 str_mode
= get_best_mode (bitsize
, bitpos
,
4502 bitregion_start
, bitregion_end
,
4503 MEM_ALIGN (str_rtx
), str_mode
, 0);
4504 if (str_mode
== VOIDmode
)
4506 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4509 bitpos
%= str_bitsize
;
4510 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4511 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4513 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4516 /* If the bit field covers the whole REG/MEM, store_field
4517 will likely generate better code. */
4518 if (bitsize
>= str_bitsize
)
4521 /* We can't handle fields split across multiple entities. */
4522 if (bitpos
+ bitsize
> str_bitsize
)
4525 if (BYTES_BIG_ENDIAN
)
4526 bitpos
= str_bitsize
- bitpos
- bitsize
;
4532 /* For now, just optimize the case of the topmost bitfield
4533 where we don't need to do any masking and also
4534 1 bit bitfields where xor can be used.
4535 We might win by one instruction for the other bitfields
4536 too if insv/extv instructions aren't used, so that
4537 can be added later. */
4538 if (bitpos
+ bitsize
!= str_bitsize
4539 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4542 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4543 value
= convert_modes (str_mode
,
4544 TYPE_MODE (TREE_TYPE (op1
)), value
,
4545 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4547 /* We may be accessing data outside the field, which means
4548 we can alias adjacent data. */
4549 if (MEM_P (str_rtx
))
4551 str_rtx
= shallow_copy_rtx (str_rtx
);
4552 set_mem_alias_set (str_rtx
, 0);
4553 set_mem_expr (str_rtx
, 0);
4556 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4557 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4559 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4562 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4563 result
= expand_binop (str_mode
, binop
, str_rtx
,
4564 value
, str_rtx
, 1, OPTAB_WIDEN
);
4565 if (result
!= str_rtx
)
4566 emit_move_insn (str_rtx
, result
);
4571 if (TREE_CODE (op1
) != INTEGER_CST
)
4573 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4574 value
= convert_modes (str_mode
,
4575 TYPE_MODE (TREE_TYPE (op1
)), value
,
4576 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4578 /* We may be accessing data outside the field, which means
4579 we can alias adjacent data. */
4580 if (MEM_P (str_rtx
))
4582 str_rtx
= shallow_copy_rtx (str_rtx
);
4583 set_mem_alias_set (str_rtx
, 0);
4584 set_mem_expr (str_rtx
, 0);
4587 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4588 if (bitpos
+ bitsize
!= str_bitsize
)
4590 rtx mask
= gen_int_mode (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1,
4592 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4594 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4595 result
= expand_binop (str_mode
, binop
, str_rtx
,
4596 value
, str_rtx
, 1, OPTAB_WIDEN
);
4597 if (result
!= str_rtx
)
4598 emit_move_insn (str_rtx
, result
);
4608 /* In the C++ memory model, consecutive bit fields in a structure are
4609 considered one memory location.
4611 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4612 returns the bit range of consecutive bits in which this COMPONENT_REF
4613 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4614 and *OFFSET may be adjusted in the process.
4616 If the access does not need to be restricted, 0 is returned in both
4617 *BITSTART and *BITEND. */
4620 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4621 unsigned HOST_WIDE_INT
*bitend
,
4623 HOST_WIDE_INT
*bitpos
,
4626 HOST_WIDE_INT bitoffset
;
4629 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4631 field
= TREE_OPERAND (exp
, 1);
4632 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4633 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4634 need to limit the range we can access. */
4637 *bitstart
= *bitend
= 0;
4641 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4642 part of a larger bit field, then the representative does not serve any
4643 useful purpose. This can occur in Ada. */
4644 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4647 HOST_WIDE_INT rbitsize
, rbitpos
;
4651 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4652 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4653 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4655 *bitstart
= *bitend
= 0;
4660 /* Compute the adjustment to bitpos from the offset of the field
4661 relative to the representative. DECL_FIELD_OFFSET of field and
4662 repr are the same by construction if they are not constants,
4663 see finish_bitfield_layout. */
4664 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
4665 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
4666 bitoffset
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
4667 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
4670 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
4671 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
4673 /* If the adjustment is larger than bitpos, we would have a negative bit
4674 position for the lower bound and this may wreak havoc later. Adjust
4675 offset and bitpos to make the lower bound non-negative in that case. */
4676 if (bitoffset
> *bitpos
)
4678 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4679 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4682 if (*offset
== NULL_TREE
)
4683 *offset
= size_int (-adjust
/ BITS_PER_UNIT
);
4686 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4690 *bitstart
= *bitpos
- bitoffset
;
4692 *bitend
= *bitstart
+ tree_to_uhwi (DECL_SIZE (repr
)) - 1;
4695 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4696 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4697 DECL_RTL was not set yet, return NORTL. */
4700 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4702 if (TREE_CODE (addr
) != ADDR_EXPR
)
4705 tree base
= TREE_OPERAND (addr
, 0);
4708 || TREE_ADDRESSABLE (base
)
4709 || DECL_MODE (base
) == BLKmode
)
4712 if (!DECL_RTL_SET_P (base
))
4715 return (!MEM_P (DECL_RTL (base
)));
4718 /* Returns true if the MEM_REF REF refers to an object that does not
4719 reside in memory and has non-BLKmode. */
4722 mem_ref_refers_to_non_mem_p (tree ref
)
4724 tree base
= TREE_OPERAND (ref
, 0);
4725 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4728 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4729 is true, try generating a nontemporal store. */
4732 expand_assignment (tree to
, tree from
, bool nontemporal
)
4738 enum insn_code icode
;
4740 /* Don't crash if the lhs of the assignment was erroneous. */
4741 if (TREE_CODE (to
) == ERROR_MARK
)
4743 expand_normal (from
);
4747 /* Optimize away no-op moves without side-effects. */
4748 if (operand_equal_p (to
, from
, 0))
4751 /* Handle misaligned stores. */
4752 mode
= TYPE_MODE (TREE_TYPE (to
));
4753 if ((TREE_CODE (to
) == MEM_REF
4754 || TREE_CODE (to
) == TARGET_MEM_REF
)
4756 && !mem_ref_refers_to_non_mem_p (to
)
4757 && ((align
= get_object_alignment (to
))
4758 < GET_MODE_ALIGNMENT (mode
))
4759 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4760 != CODE_FOR_nothing
)
4761 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4765 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4766 reg
= force_not_mem (reg
);
4767 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4769 if (icode
!= CODE_FOR_nothing
)
4771 struct expand_operand ops
[2];
4773 create_fixed_operand (&ops
[0], mem
);
4774 create_input_operand (&ops
[1], reg
, mode
);
4775 /* The movmisalign<mode> pattern cannot fail, else the assignment
4776 would silently be omitted. */
4777 expand_insn (icode
, 2, ops
);
4780 store_bit_field (mem
, GET_MODE_BITSIZE (mode
), 0, 0, 0, mode
, reg
);
4784 /* Assignment of a structure component needs special treatment
4785 if the structure component's rtx is not simply a MEM.
4786 Assignment of an array element at a constant index, and assignment of
4787 an array element in an unaligned packed structure field, has the same
4788 problem. Same for (partially) storing into a non-memory object. */
4789 if (handled_component_p (to
)
4790 || (TREE_CODE (to
) == MEM_REF
4791 && mem_ref_refers_to_non_mem_p (to
))
4792 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4795 HOST_WIDE_INT bitsize
, bitpos
;
4796 unsigned HOST_WIDE_INT bitregion_start
= 0;
4797 unsigned HOST_WIDE_INT bitregion_end
= 0;
4804 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4805 &unsignedp
, &volatilep
, true);
4807 /* Make sure bitpos is not negative, it can wreak havoc later. */
4810 gcc_assert (offset
== NULL_TREE
);
4811 offset
= size_int (bitpos
>> (BITS_PER_UNIT
== 8
4812 ? 3 : exact_log2 (BITS_PER_UNIT
)));
4813 bitpos
&= BITS_PER_UNIT
- 1;
4816 if (TREE_CODE (to
) == COMPONENT_REF
4817 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4818 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4819 /* The C++ memory model naturally applies to byte-aligned fields.
4820 However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
4821 BITSIZE are not byte-aligned, there is no need to limit the range
4822 we can access. This can occur with packed structures in Ada. */
4823 else if (bitsize
> 0
4824 && bitsize
% BITS_PER_UNIT
== 0
4825 && bitpos
% BITS_PER_UNIT
== 0)
4827 bitregion_start
= bitpos
;
4828 bitregion_end
= bitpos
+ bitsize
- 1;
4831 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4833 /* If the field has a mode, we want to access it in the
4834 field's mode, not the computed mode.
4835 If a MEM has VOIDmode (external with incomplete type),
4836 use BLKmode for it instead. */
4839 if (mode1
!= VOIDmode
)
4840 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4841 else if (GET_MODE (to_rtx
) == VOIDmode
)
4842 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4847 machine_mode address_mode
;
4850 if (!MEM_P (to_rtx
))
4852 /* We can get constant negative offsets into arrays with broken
4853 user code. Translate this to a trap instead of ICEing. */
4854 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4855 expand_builtin_trap ();
4856 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4859 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4860 address_mode
= get_address_mode (to_rtx
);
4861 if (GET_MODE (offset_rtx
) != address_mode
)
4862 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4864 /* If we have an expression in OFFSET_RTX and a non-zero
4865 byte offset in BITPOS, adding the byte offset before the
4866 OFFSET_RTX results in better intermediate code, which makes
4867 later rtl optimization passes perform better.
4869 We prefer intermediate code like this:
4871 r124:DI=r123:DI+0x18
4876 r124:DI=r123:DI+0x10
4877 [r124:DI+0x8]=r121:DI
4879 This is only done for aligned data values, as these can
4880 be expected to result in single move instructions. */
4881 if (mode1
!= VOIDmode
4884 && (bitpos
% bitsize
) == 0
4885 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4886 && MEM_ALIGN (to_rtx
) >= GET_MODE_ALIGNMENT (mode1
))
4888 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4889 bitregion_start
= 0;
4890 if (bitregion_end
>= (unsigned HOST_WIDE_INT
) bitpos
)
4891 bitregion_end
-= bitpos
;
4895 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4896 highest_pow2_factor_for_target (to
,
4900 /* No action is needed if the target is not a memory and the field
4901 lies completely outside that target. This can occur if the source
4902 code contains an out-of-bounds access to a small array. */
4904 && GET_MODE (to_rtx
) != BLKmode
4905 && (unsigned HOST_WIDE_INT
) bitpos
4906 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4908 expand_normal (from
);
4911 /* Handle expand_expr of a complex value returning a CONCAT. */
4912 else if (GET_CODE (to_rtx
) == CONCAT
)
4914 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4915 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4917 && bitsize
== mode_bitsize
)
4918 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4919 else if (bitsize
== mode_bitsize
/ 2
4920 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4921 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4923 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4924 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4925 bitregion_start
, bitregion_end
,
4927 get_alias_set (to
), nontemporal
);
4928 else if (bitpos
>= mode_bitsize
/ 2)
4929 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4930 bitpos
- mode_bitsize
/ 2,
4931 bitregion_start
, bitregion_end
,
4933 get_alias_set (to
), nontemporal
);
4934 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4937 result
= expand_normal (from
);
4938 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4939 TYPE_MODE (TREE_TYPE (from
)), 0);
4940 emit_move_insn (XEXP (to_rtx
, 0),
4941 read_complex_part (from_rtx
, false));
4942 emit_move_insn (XEXP (to_rtx
, 1),
4943 read_complex_part (from_rtx
, true));
4947 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4948 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4949 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4950 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4951 result
= store_field (temp
, bitsize
, bitpos
,
4952 bitregion_start
, bitregion_end
,
4954 get_alias_set (to
), nontemporal
);
4955 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4956 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
4963 /* If the field is at offset zero, we could have been given the
4964 DECL_RTX of the parent struct. Don't munge it. */
4965 to_rtx
= shallow_copy_rtx (to_rtx
);
4966 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
4968 MEM_VOLATILE_P (to_rtx
) = 1;
4971 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
4972 bitregion_start
, bitregion_end
,
4977 result
= store_field (to_rtx
, bitsize
, bitpos
,
4978 bitregion_start
, bitregion_end
,
4980 get_alias_set (to
), nontemporal
);
4984 preserve_temp_slots (result
);
4989 /* If the rhs is a function call and its value is not an aggregate,
4990 call the function before we start to compute the lhs.
4991 This is needed for correct code for cases such as
4992 val = setjmp (buf) on machines where reference to val
4993 requires loading up part of an address in a separate insn.
4995 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4996 since it might be a promoted variable where the zero- or sign- extension
4997 needs to be done. Handling this in the normal way is safe because no
4998 computation is done before the call. The same is true for SSA names. */
4999 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
5000 && COMPLETE_TYPE_P (TREE_TYPE (from
))
5001 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
5002 && ! (((TREE_CODE (to
) == VAR_DECL
5003 || TREE_CODE (to
) == PARM_DECL
5004 || TREE_CODE (to
) == RESULT_DECL
)
5005 && REG_P (DECL_RTL (to
)))
5006 || TREE_CODE (to
) == SSA_NAME
))
5011 value
= expand_normal (from
);
5013 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5015 /* Handle calls that return values in multiple non-contiguous locations.
5016 The Irix 6 ABI has examples of this. */
5017 if (GET_CODE (to_rtx
) == PARALLEL
)
5019 if (GET_CODE (value
) == PARALLEL
)
5020 emit_group_move (to_rtx
, value
);
5022 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
5023 int_size_in_bytes (TREE_TYPE (from
)));
5025 else if (GET_CODE (value
) == PARALLEL
)
5026 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
5027 int_size_in_bytes (TREE_TYPE (from
)));
5028 else if (GET_MODE (to_rtx
) == BLKmode
)
5030 /* Handle calls that return BLKmode values in registers. */
5032 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
5034 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
5038 if (POINTER_TYPE_P (TREE_TYPE (to
)))
5039 value
= convert_memory_address_addr_space
5040 (GET_MODE (to_rtx
), value
,
5041 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
5043 emit_move_insn (to_rtx
, value
);
5045 preserve_temp_slots (to_rtx
);
5050 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5051 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5053 /* Don't move directly into a return register. */
5054 if (TREE_CODE (to
) == RESULT_DECL
5055 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
5061 /* If the source is itself a return value, it still is in a pseudo at
5062 this point so we can move it back to the return register directly. */
5064 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
5065 && TREE_CODE (from
) != CALL_EXPR
)
5066 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
5068 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
5070 /* Handle calls that return values in multiple non-contiguous locations.
5071 The Irix 6 ABI has examples of this. */
5072 if (GET_CODE (to_rtx
) == PARALLEL
)
5074 if (GET_CODE (temp
) == PARALLEL
)
5075 emit_group_move (to_rtx
, temp
);
5077 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
5078 int_size_in_bytes (TREE_TYPE (from
)));
5081 emit_move_insn (to_rtx
, temp
);
5083 preserve_temp_slots (to_rtx
);
5088 /* In case we are returning the contents of an object which overlaps
5089 the place the value is being stored, use a safe function when copying
5090 a value through a pointer into a structure value return block. */
5091 if (TREE_CODE (to
) == RESULT_DECL
5092 && TREE_CODE (from
) == INDIRECT_REF
5093 && ADDR_SPACE_GENERIC_P
5094 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5095 && refs_may_alias_p (to
, from
)
5096 && cfun
->returns_struct
5097 && !cfun
->returns_pcc_struct
)
5102 size
= expr_size (from
);
5103 from_rtx
= expand_normal (from
);
5105 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
5106 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
5107 XEXP (from_rtx
, 0), Pmode
,
5108 convert_to_mode (TYPE_MODE (sizetype
),
5109 size
, TYPE_UNSIGNED (sizetype
)),
5110 TYPE_MODE (sizetype
));
5112 preserve_temp_slots (to_rtx
);
5117 /* Compute FROM and store the value in the rtx we got. */
5120 result
= store_expr (from
, to_rtx
, 0, nontemporal
);
5121 preserve_temp_slots (result
);
5126 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5127 succeeded, false otherwise. */
5130 emit_storent_insn (rtx to
, rtx from
)
5132 struct expand_operand ops
[2];
5133 machine_mode mode
= GET_MODE (to
);
5134 enum insn_code code
= optab_handler (storent_optab
, mode
);
5136 if (code
== CODE_FOR_nothing
)
5139 create_fixed_operand (&ops
[0], to
);
5140 create_input_operand (&ops
[1], from
, mode
);
5141 return maybe_expand_insn (code
, 2, ops
);
5144 /* Generate code for computing expression EXP,
5145 and storing the value into TARGET.
5147 If the mode is BLKmode then we may return TARGET itself.
5148 It turns out that in BLKmode it doesn't cause a problem.
5149 because C has no operators that could combine two different
5150 assignments into the same BLKmode object with different values
5151 with no sequence point. Will other languages need this to
5154 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5155 stack, and block moves may need to be treated specially.
5157 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5160 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5163 rtx alt_rtl
= NULL_RTX
;
5164 location_t loc
= curr_insn_location ();
5166 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5168 /* C++ can generate ?: expressions with a throw expression in one
5169 branch and an rvalue in the other. Here, we resolve attempts to
5170 store the throw expression's nonexistent result. */
5171 gcc_assert (!call_param_p
);
5172 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5175 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5177 /* Perform first part of compound expression, then assign from second
5179 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5180 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5181 return store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5184 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5186 /* For conditional expression, get safe form of the target. Then
5187 test the condition, doing the appropriate assignment on either
5188 side. This avoids the creation of unnecessary temporaries.
5189 For non-BLKmode, it is more efficient not to do this. */
5191 rtx_code_label
*lab1
= gen_label_rtx (), *lab2
= gen_label_rtx ();
5193 do_pending_stack_adjust ();
5195 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5196 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5198 emit_jump_insn (gen_jump (lab2
));
5201 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5208 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5209 /* If this is a scalar in a register that is stored in a wider mode
5210 than the declared mode, compute the result into its declared mode
5211 and then convert to the wider mode. Our value is the computed
5214 rtx inner_target
= 0;
5216 /* We can do the conversion inside EXP, which will often result
5217 in some optimizations. Do the conversion in two steps: first
5218 change the signedness, if needed, then the extend. But don't
5219 do this if the type of EXP is a subtype of something else
5220 since then the conversion might involve more than just
5221 converting modes. */
5222 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5223 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5224 && GET_MODE_PRECISION (GET_MODE (target
))
5225 == TYPE_PRECISION (TREE_TYPE (exp
)))
5227 if (!SUBREG_CHECK_PROMOTED_SIGN (target
,
5228 TYPE_UNSIGNED (TREE_TYPE (exp
))))
5230 /* Some types, e.g. Fortran's logical*4, won't have a signed
5231 version, so use the mode instead. */
5233 = (signed_or_unsigned_type_for
5234 (SUBREG_PROMOTED_SIGN (target
), TREE_TYPE (exp
)));
5236 ntype
= lang_hooks
.types
.type_for_mode
5237 (TYPE_MODE (TREE_TYPE (exp
)),
5238 SUBREG_PROMOTED_SIGN (target
));
5240 exp
= fold_convert_loc (loc
, ntype
, exp
);
5243 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5244 (GET_MODE (SUBREG_REG (target
)),
5245 SUBREG_PROMOTED_SIGN (target
)),
5248 inner_target
= SUBREG_REG (target
);
5251 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5252 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5254 /* If TEMP is a VOIDmode constant, use convert_modes to make
5255 sure that we properly convert it. */
5256 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5258 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5259 temp
, SUBREG_PROMOTED_SIGN (target
));
5260 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5261 GET_MODE (target
), temp
,
5262 SUBREG_PROMOTED_SIGN (target
));
5265 convert_move (SUBREG_REG (target
), temp
,
5266 SUBREG_PROMOTED_SIGN (target
));
5270 else if ((TREE_CODE (exp
) == STRING_CST
5271 || (TREE_CODE (exp
) == MEM_REF
5272 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5273 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5275 && integer_zerop (TREE_OPERAND (exp
, 1))))
5276 && !nontemporal
&& !call_param_p
5279 /* Optimize initialization of an array with a STRING_CST. */
5280 HOST_WIDE_INT exp_len
, str_copy_len
;
5282 tree str
= TREE_CODE (exp
) == STRING_CST
5283 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5285 exp_len
= int_expr_size (exp
);
5289 if (TREE_STRING_LENGTH (str
) <= 0)
5292 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5293 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5296 str_copy_len
= TREE_STRING_LENGTH (str
);
5297 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5298 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5300 str_copy_len
+= STORE_MAX_PIECES
- 1;
5301 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5303 str_copy_len
= MIN (str_copy_len
, exp_len
);
5304 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5305 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5306 MEM_ALIGN (target
), false))
5311 dest_mem
= store_by_pieces (dest_mem
,
5312 str_copy_len
, builtin_strncpy_read_str
,
5314 TREE_STRING_POINTER (str
)),
5315 MEM_ALIGN (target
), false,
5316 exp_len
> str_copy_len
? 1 : 0);
5317 if (exp_len
> str_copy_len
)
5318 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5319 GEN_INT (exp_len
- str_copy_len
),
5328 /* If we want to use a nontemporal store, force the value to
5330 tmp_target
= nontemporal
? NULL_RTX
: target
;
5331 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5333 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5337 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5338 the same as that of TARGET, adjust the constant. This is needed, for
5339 example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
5340 only a word-sized value. */
5341 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5342 && TREE_CODE (exp
) != ERROR_MARK
5343 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5344 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5345 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5347 /* If value was not generated in the target, store it there.
5348 Convert the value to TARGET's type first if necessary and emit the
5349 pending incrementations that have been queued when expanding EXP.
5350 Note that we cannot emit the whole queue blindly because this will
5351 effectively disable the POST_INC optimization later.
5353 If TEMP and TARGET compare equal according to rtx_equal_p, but
5354 one or both of them are volatile memory refs, we have to distinguish
5356 - expand_expr has used TARGET. In this case, we must not generate
5357 another copy. This can be detected by TARGET being equal according
5359 - expand_expr has not used TARGET - that means that the source just
5360 happens to have the same RTX form. Since temp will have been created
5361 by expand_expr, it will compare unequal according to == .
5362 We must generate a copy in this case, to reach the correct number
5363 of volatile memory references. */
5365 if ((! rtx_equal_p (temp
, target
)
5366 || (temp
!= target
&& (side_effects_p (temp
)
5367 || side_effects_p (target
))))
5368 && TREE_CODE (exp
) != ERROR_MARK
5369 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5370 but TARGET is not valid memory reference, TEMP will differ
5371 from TARGET although it is really the same location. */
5373 && rtx_equal_p (alt_rtl
, target
)
5374 && !side_effects_p (alt_rtl
)
5375 && !side_effects_p (target
))
5376 /* If there's nothing to copy, don't bother. Don't call
5377 expr_size unless necessary, because some front-ends (C++)
5378 expr_size-hook must not be given objects that are not
5379 supposed to be bit-copied or bit-initialized. */
5380 && expr_size (exp
) != const0_rtx
)
5382 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5384 if (GET_MODE (target
) == BLKmode
)
5386 /* Handle calls that return BLKmode values in registers. */
5387 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5388 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5390 store_bit_field (target
,
5391 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5392 0, 0, 0, GET_MODE (temp
), temp
);
5395 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5398 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5400 /* Handle copying a string constant into an array. The string
5401 constant may be shorter than the array. So copy just the string's
5402 actual length, and clear the rest. First get the size of the data
5403 type of the string, which is actually the size of the target. */
5404 rtx size
= expr_size (exp
);
5406 if (CONST_INT_P (size
)
5407 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5408 emit_block_move (target
, temp
, size
,
5410 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5413 machine_mode pointer_mode
5414 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5415 machine_mode address_mode
= get_address_mode (target
);
5417 /* Compute the size of the data to copy from the string. */
5419 = size_binop_loc (loc
, MIN_EXPR
,
5420 make_tree (sizetype
, size
),
5421 size_int (TREE_STRING_LENGTH (exp
)));
5423 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5425 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5426 rtx_code_label
*label
= 0;
5428 /* Copy that much. */
5429 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5430 TYPE_UNSIGNED (sizetype
));
5431 emit_block_move (target
, temp
, copy_size_rtx
,
5433 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5435 /* Figure out how much is left in TARGET that we have to clear.
5436 Do all calculations in pointer_mode. */
5437 if (CONST_INT_P (copy_size_rtx
))
5439 size
= plus_constant (address_mode
, size
,
5440 -INTVAL (copy_size_rtx
));
5441 target
= adjust_address (target
, BLKmode
,
5442 INTVAL (copy_size_rtx
));
5446 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5447 copy_size_rtx
, NULL_RTX
, 0,
5450 if (GET_MODE (copy_size_rtx
) != address_mode
)
5451 copy_size_rtx
= convert_to_mode (address_mode
,
5453 TYPE_UNSIGNED (sizetype
));
5455 target
= offset_address (target
, copy_size_rtx
,
5456 highest_pow2_factor (copy_size
));
5457 label
= gen_label_rtx ();
5458 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5459 GET_MODE (size
), 0, label
);
5462 if (size
!= const0_rtx
)
5463 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5469 /* Handle calls that return values in multiple non-contiguous locations.
5470 The Irix 6 ABI has examples of this. */
5471 else if (GET_CODE (target
) == PARALLEL
)
5473 if (GET_CODE (temp
) == PARALLEL
)
5474 emit_group_move (target
, temp
);
5476 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5477 int_size_in_bytes (TREE_TYPE (exp
)));
5479 else if (GET_CODE (temp
) == PARALLEL
)
5480 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5481 int_size_in_bytes (TREE_TYPE (exp
)));
5482 else if (GET_MODE (temp
) == BLKmode
)
5483 emit_block_move (target
, temp
, expr_size (exp
),
5485 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5486 /* If we emit a nontemporal store, there is nothing else to do. */
5487 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5491 temp
= force_operand (temp
, target
);
5493 emit_move_insn (target
, temp
);
5500 /* Return true if field F of structure TYPE is a flexible array. */
5503 flexible_array_member_p (const_tree f
, const_tree type
)
5508 return (DECL_CHAIN (f
) == NULL
5509 && TREE_CODE (tf
) == ARRAY_TYPE
5511 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5512 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5513 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5514 && int_size_in_bytes (type
) >= 0);
5517 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5518 must have in order for it to completely initialize a value of type TYPE.
5519 Return -1 if the number isn't known.
5521 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5523 static HOST_WIDE_INT
5524 count_type_elements (const_tree type
, bool for_ctor_p
)
5526 switch (TREE_CODE (type
))
5532 nelts
= array_type_nelts (type
);
5533 if (nelts
&& tree_fits_uhwi_p (nelts
))
5535 unsigned HOST_WIDE_INT n
;
5537 n
= tree_to_uhwi (nelts
) + 1;
5538 if (n
== 0 || for_ctor_p
)
5541 return n
* count_type_elements (TREE_TYPE (type
), false);
5543 return for_ctor_p
? -1 : 1;
5548 unsigned HOST_WIDE_INT n
;
5552 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5553 if (TREE_CODE (f
) == FIELD_DECL
)
5556 n
+= count_type_elements (TREE_TYPE (f
), false);
5557 else if (!flexible_array_member_p (f
, type
))
5558 /* Don't count flexible arrays, which are not supposed
5559 to be initialized. */
5567 case QUAL_UNION_TYPE
:
5572 gcc_assert (!for_ctor_p
);
5573 /* Estimate the number of scalars in each field and pick the
5574 maximum. Other estimates would do instead; the idea is simply
5575 to make sure that the estimate is not sensitive to the ordering
5578 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5579 if (TREE_CODE (f
) == FIELD_DECL
)
5581 m
= count_type_elements (TREE_TYPE (f
), false);
5582 /* If the field doesn't span the whole union, add an extra
5583 scalar for the rest. */
5584 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5585 TYPE_SIZE (type
)) != 1)
5597 return TYPE_VECTOR_SUBPARTS (type
);
5601 case FIXED_POINT_TYPE
:
5606 case REFERENCE_TYPE
:
5622 /* Helper for categorize_ctor_elements. Identical interface. */
5625 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5626 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5628 unsigned HOST_WIDE_INT idx
;
5629 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5630 tree value
, purpose
, elt_type
;
5632 /* Whether CTOR is a valid constant initializer, in accordance with what
5633 initializer_constant_valid_p does. If inferred from the constructor
5634 elements, true until proven otherwise. */
5635 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5636 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5641 elt_type
= NULL_TREE
;
5643 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5645 HOST_WIDE_INT mult
= 1;
5647 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5649 tree lo_index
= TREE_OPERAND (purpose
, 0);
5650 tree hi_index
= TREE_OPERAND (purpose
, 1);
5652 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5653 mult
= (tree_to_uhwi (hi_index
)
5654 - tree_to_uhwi (lo_index
) + 1);
5657 elt_type
= TREE_TYPE (value
);
5659 switch (TREE_CODE (value
))
5663 HOST_WIDE_INT nz
= 0, ic
= 0;
5665 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5668 nz_elts
+= mult
* nz
;
5669 init_elts
+= mult
* ic
;
5671 if (const_from_elts_p
&& const_p
)
5672 const_p
= const_elt_p
;
5679 if (!initializer_zerop (value
))
5685 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5686 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5690 if (!initializer_zerop (TREE_REALPART (value
)))
5692 if (!initializer_zerop (TREE_IMAGPART (value
)))
5700 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5702 tree v
= VECTOR_CST_ELT (value
, i
);
5703 if (!initializer_zerop (v
))
5712 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5713 nz_elts
+= mult
* tc
;
5714 init_elts
+= mult
* tc
;
5716 if (const_from_elts_p
&& const_p
)
5717 const_p
= initializer_constant_valid_p (value
, elt_type
)
5724 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5725 num_fields
, elt_type
))
5726 *p_complete
= false;
5728 *p_nz_elts
+= nz_elts
;
5729 *p_init_elts
+= init_elts
;
5734 /* Examine CTOR to discover:
5735 * how many scalar fields are set to nonzero values,
5736 and place it in *P_NZ_ELTS;
5737 * how many scalar fields in total are in CTOR,
5738 and place it in *P_ELT_COUNT.
5739 * whether the constructor is complete -- in the sense that every
5740 meaningful byte is explicitly given a value --
5741 and place it in *P_COMPLETE.
5743 Return whether or not CTOR is a valid static constant initializer, the same
5744 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5747 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5748 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5754 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5757 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5758 of which had type LAST_TYPE. Each element was itself a complete
5759 initializer, in the sense that every meaningful byte was explicitly
5760 given a value. Return true if the same is true for the constructor
5764 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5765 const_tree last_type
)
5767 if (TREE_CODE (type
) == UNION_TYPE
5768 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5773 gcc_assert (num_elts
== 1 && last_type
);
5775 /* ??? We could look at each element of the union, and find the
5776 largest element. Which would avoid comparing the size of the
5777 initialized element against any tail padding in the union.
5778 Doesn't seem worth the effort... */
5779 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5782 return count_type_elements (type
, true) == num_elts
;
5785 /* Return 1 if EXP contains mostly (3/4) zeros. */
5788 mostly_zeros_p (const_tree exp
)
5790 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5792 HOST_WIDE_INT nz_elts
, init_elts
;
5795 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5796 return !complete_p
|| nz_elts
< init_elts
/ 4;
5799 return initializer_zerop (exp
);
5802 /* Return 1 if EXP contains all zeros. */
5805 all_zeros_p (const_tree exp
)
5807 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5809 HOST_WIDE_INT nz_elts
, init_elts
;
5812 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5813 return nz_elts
== 0;
5816 return initializer_zerop (exp
);
5819 /* Helper function for store_constructor.
5820 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5821 CLEARED is as for store_constructor.
5822 ALIAS_SET is the alias set to use for any stores.
5824 This provides a recursive shortcut back to store_constructor when it isn't
5825 necessary to go through store_field. This is so that we can pass through
5826 the cleared field to let store_constructor know that we may not have to
5827 clear a substructure if the outer structure has already been cleared. */
5830 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5831 HOST_WIDE_INT bitpos
, machine_mode mode
,
5832 tree exp
, int cleared
, alias_set_type alias_set
)
5834 if (TREE_CODE (exp
) == CONSTRUCTOR
5835 /* We can only call store_constructor recursively if the size and
5836 bit position are on a byte boundary. */
5837 && bitpos
% BITS_PER_UNIT
== 0
5838 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5839 /* If we have a nonzero bitpos for a register target, then we just
5840 let store_field do the bitfield handling. This is unlikely to
5841 generate unnecessary clear instructions anyways. */
5842 && (bitpos
== 0 || MEM_P (target
)))
5846 = adjust_address (target
,
5847 GET_MODE (target
) == BLKmode
5849 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5850 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5853 /* Update the alias set, if required. */
5854 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5855 && MEM_ALIAS_SET (target
) != 0)
5857 target
= copy_rtx (target
);
5858 set_mem_alias_set (target
, alias_set
);
5861 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5864 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5868 /* Returns the number of FIELD_DECLs in TYPE. */
5871 fields_length (const_tree type
)
5873 tree t
= TYPE_FIELDS (type
);
5876 for (; t
; t
= DECL_CHAIN (t
))
5877 if (TREE_CODE (t
) == FIELD_DECL
)
5884 /* Store the value of constructor EXP into the rtx TARGET.
5885 TARGET is either a REG or a MEM; we know it cannot conflict, since
5886 safe_from_p has been called.
5887 CLEARED is true if TARGET is known to have been zero'd.
5888 SIZE is the number of bytes of TARGET we are allowed to modify: this
5889 may not be the same as the size of EXP if we are assigning to a field
5890 which has been packed to exclude padding bits. */
5893 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5895 tree type
= TREE_TYPE (exp
);
5896 #ifdef WORD_REGISTER_OPERATIONS
5897 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5900 switch (TREE_CODE (type
))
5904 case QUAL_UNION_TYPE
:
5906 unsigned HOST_WIDE_INT idx
;
5909 /* If size is zero or the target is already cleared, do nothing. */
5910 if (size
== 0 || cleared
)
5912 /* We either clear the aggregate or indicate the value is dead. */
5913 else if ((TREE_CODE (type
) == UNION_TYPE
5914 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5915 && ! CONSTRUCTOR_ELTS (exp
))
5916 /* If the constructor is empty, clear the union. */
5918 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
5922 /* If we are building a static constructor into a register,
5923 set the initial value as zero so we can fold the value into
5924 a constant. But if more than one register is involved,
5925 this probably loses. */
5926 else if (REG_P (target
) && TREE_STATIC (exp
)
5927 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
5929 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5933 /* If the constructor has fewer fields than the structure or
5934 if we are initializing the structure to mostly zeros, clear
5935 the whole structure first. Don't do this if TARGET is a
5936 register whose mode size isn't equal to SIZE since
5937 clear_storage can't handle this case. */
5939 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
5940 != fields_length (type
))
5941 || mostly_zeros_p (exp
))
5943 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
5946 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5950 if (REG_P (target
) && !cleared
)
5951 emit_clobber (target
);
5953 /* Store each element of the constructor into the
5954 corresponding field of TARGET. */
5955 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
5958 HOST_WIDE_INT bitsize
;
5959 HOST_WIDE_INT bitpos
= 0;
5961 rtx to_rtx
= target
;
5963 /* Just ignore missing fields. We cleared the whole
5964 structure, above, if any fields are missing. */
5968 if (cleared
&& initializer_zerop (value
))
5971 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
5972 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
5976 mode
= DECL_MODE (field
);
5977 if (DECL_BIT_FIELD (field
))
5980 offset
= DECL_FIELD_OFFSET (field
);
5981 if (tree_fits_shwi_p (offset
)
5982 && tree_fits_shwi_p (bit_position (field
)))
5984 bitpos
= int_bit_position (field
);
5988 bitpos
= tree_to_shwi (DECL_FIELD_BIT_OFFSET (field
));
5992 machine_mode address_mode
;
5996 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
5997 make_tree (TREE_TYPE (exp
),
6000 offset_rtx
= expand_normal (offset
);
6001 gcc_assert (MEM_P (to_rtx
));
6003 address_mode
= get_address_mode (to_rtx
);
6004 if (GET_MODE (offset_rtx
) != address_mode
)
6005 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
6007 to_rtx
= offset_address (to_rtx
, offset_rtx
,
6008 highest_pow2_factor (offset
));
6011 #ifdef WORD_REGISTER_OPERATIONS
6012 /* If this initializes a field that is smaller than a
6013 word, at the start of a word, try to widen it to a full
6014 word. This special case allows us to output C++ member
6015 function initializations in a form that the optimizers
6018 && bitsize
< BITS_PER_WORD
6019 && bitpos
% BITS_PER_WORD
== 0
6020 && GET_MODE_CLASS (mode
) == MODE_INT
6021 && TREE_CODE (value
) == INTEGER_CST
6023 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
6025 tree type
= TREE_TYPE (value
);
6027 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
6029 type
= lang_hooks
.types
.type_for_mode
6030 (word_mode
, TYPE_UNSIGNED (type
));
6031 value
= fold_convert (type
, value
);
6034 if (BYTES_BIG_ENDIAN
)
6036 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6037 build_int_cst (type
,
6038 BITS_PER_WORD
- bitsize
));
6039 bitsize
= BITS_PER_WORD
;
6044 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6045 && DECL_NONADDRESSABLE_P (field
))
6047 to_rtx
= copy_rtx (to_rtx
);
6048 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6051 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
6053 get_alias_set (TREE_TYPE (field
)));
6060 unsigned HOST_WIDE_INT i
;
6063 tree elttype
= TREE_TYPE (type
);
6065 HOST_WIDE_INT minelt
= 0;
6066 HOST_WIDE_INT maxelt
= 0;
6068 domain
= TYPE_DOMAIN (type
);
6069 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6070 && TYPE_MAX_VALUE (domain
)
6071 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6072 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6074 /* If we have constant bounds for the range of the type, get them. */
6077 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6078 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6081 /* If the constructor has fewer elements than the array, clear
6082 the whole array first. Similarly if this is static
6083 constructor of a non-BLKmode object. */
6086 else if (REG_P (target
) && TREE_STATIC (exp
))
6090 unsigned HOST_WIDE_INT idx
;
6092 HOST_WIDE_INT count
= 0, zero_count
= 0;
6093 need_to_clear
= ! const_bounds_p
;
6095 /* This loop is a more accurate version of the loop in
6096 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6097 is also needed to check for missing elements. */
6098 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6100 HOST_WIDE_INT this_node_count
;
6105 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6107 tree lo_index
= TREE_OPERAND (index
, 0);
6108 tree hi_index
= TREE_OPERAND (index
, 1);
6110 if (! tree_fits_uhwi_p (lo_index
)
6111 || ! tree_fits_uhwi_p (hi_index
))
6117 this_node_count
= (tree_to_uhwi (hi_index
)
6118 - tree_to_uhwi (lo_index
) + 1);
6121 this_node_count
= 1;
6123 count
+= this_node_count
;
6124 if (mostly_zeros_p (value
))
6125 zero_count
+= this_node_count
;
6128 /* Clear the entire array first if there are any missing
6129 elements, or if the incidence of zero elements is >=
6132 && (count
< maxelt
- minelt
+ 1
6133 || 4 * zero_count
>= 3 * count
))
6137 if (need_to_clear
&& size
> 0)
6140 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6142 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6146 if (!cleared
&& REG_P (target
))
6147 /* Inform later passes that the old value is dead. */
6148 emit_clobber (target
);
6150 /* Store each element of the constructor into the
6151 corresponding element of TARGET, determined by counting the
6153 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6156 HOST_WIDE_INT bitsize
;
6157 HOST_WIDE_INT bitpos
;
6158 rtx xtarget
= target
;
6160 if (cleared
&& initializer_zerop (value
))
6163 mode
= TYPE_MODE (elttype
);
6164 if (mode
== BLKmode
)
6165 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6166 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6169 bitsize
= GET_MODE_BITSIZE (mode
);
6171 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6173 tree lo_index
= TREE_OPERAND (index
, 0);
6174 tree hi_index
= TREE_OPERAND (index
, 1);
6175 rtx index_r
, pos_rtx
;
6176 HOST_WIDE_INT lo
, hi
, count
;
6179 /* If the range is constant and "small", unroll the loop. */
6181 && tree_fits_shwi_p (lo_index
)
6182 && tree_fits_shwi_p (hi_index
)
6183 && (lo
= tree_to_shwi (lo_index
),
6184 hi
= tree_to_shwi (hi_index
),
6185 count
= hi
- lo
+ 1,
6188 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6189 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6192 lo
-= minelt
; hi
-= minelt
;
6193 for (; lo
<= hi
; lo
++)
6195 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6198 && !MEM_KEEP_ALIAS_SET_P (target
)
6199 && TREE_CODE (type
) == ARRAY_TYPE
6200 && TYPE_NONALIASED_COMPONENT (type
))
6202 target
= copy_rtx (target
);
6203 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6206 store_constructor_field
6207 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6208 get_alias_set (elttype
));
6213 rtx_code_label
*loop_start
= gen_label_rtx ();
6214 rtx_code_label
*loop_end
= gen_label_rtx ();
6217 expand_normal (hi_index
);
6219 index
= build_decl (EXPR_LOCATION (exp
),
6220 VAR_DECL
, NULL_TREE
, domain
);
6221 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6222 SET_DECL_RTL (index
, index_r
);
6223 store_expr (lo_index
, index_r
, 0, false);
6225 /* Build the head of the loop. */
6226 do_pending_stack_adjust ();
6227 emit_label (loop_start
);
6229 /* Assign value to element index. */
6231 fold_convert (ssizetype
,
6232 fold_build2 (MINUS_EXPR
,
6235 TYPE_MIN_VALUE (domain
)));
6238 size_binop (MULT_EXPR
, position
,
6239 fold_convert (ssizetype
,
6240 TYPE_SIZE_UNIT (elttype
)));
6242 pos_rtx
= expand_normal (position
);
6243 xtarget
= offset_address (target
, pos_rtx
,
6244 highest_pow2_factor (position
));
6245 xtarget
= adjust_address (xtarget
, mode
, 0);
6246 if (TREE_CODE (value
) == CONSTRUCTOR
)
6247 store_constructor (value
, xtarget
, cleared
,
6248 bitsize
/ BITS_PER_UNIT
);
6250 store_expr (value
, xtarget
, 0, false);
6252 /* Generate a conditional jump to exit the loop. */
6253 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6255 jumpif (exit_cond
, loop_end
, -1);
6257 /* Update the loop counter, and jump to the head of
6259 expand_assignment (index
,
6260 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6261 index
, integer_one_node
),
6264 emit_jump (loop_start
);
6266 /* Build the end of the loop. */
6267 emit_label (loop_end
);
6270 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6271 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6276 index
= ssize_int (1);
6279 index
= fold_convert (ssizetype
,
6280 fold_build2 (MINUS_EXPR
,
6283 TYPE_MIN_VALUE (domain
)));
6286 size_binop (MULT_EXPR
, index
,
6287 fold_convert (ssizetype
,
6288 TYPE_SIZE_UNIT (elttype
)));
6289 xtarget
= offset_address (target
,
6290 expand_normal (position
),
6291 highest_pow2_factor (position
));
6292 xtarget
= adjust_address (xtarget
, mode
, 0);
6293 store_expr (value
, xtarget
, 0, false);
6298 bitpos
= ((tree_to_shwi (index
) - minelt
)
6299 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6301 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6303 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6304 && TREE_CODE (type
) == ARRAY_TYPE
6305 && TYPE_NONALIASED_COMPONENT (type
))
6307 target
= copy_rtx (target
);
6308 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6310 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6311 cleared
, get_alias_set (elttype
));
6319 unsigned HOST_WIDE_INT idx
;
6320 constructor_elt
*ce
;
6323 int icode
= CODE_FOR_nothing
;
6324 tree elttype
= TREE_TYPE (type
);
6325 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6326 machine_mode eltmode
= TYPE_MODE (elttype
);
6327 HOST_WIDE_INT bitsize
;
6328 HOST_WIDE_INT bitpos
;
6329 rtvec vector
= NULL
;
6331 alias_set_type alias
;
6333 gcc_assert (eltmode
!= BLKmode
);
6335 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6336 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6338 machine_mode mode
= GET_MODE (target
);
6340 icode
= (int) optab_handler (vec_init_optab
, mode
);
6341 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6342 if (icode
!= CODE_FOR_nothing
)
6346 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6347 if (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
)
6349 icode
= CODE_FOR_nothing
;
6353 if (icode
!= CODE_FOR_nothing
)
6357 vector
= rtvec_alloc (n_elts
);
6358 for (i
= 0; i
< n_elts
; i
++)
6359 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6363 /* If the constructor has fewer elements than the vector,
6364 clear the whole array first. Similarly if this is static
6365 constructor of a non-BLKmode object. */
6368 else if (REG_P (target
) && TREE_STATIC (exp
))
6372 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6375 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6377 int n_elts_here
= tree_to_uhwi
6378 (int_const_binop (TRUNC_DIV_EXPR
,
6379 TYPE_SIZE (TREE_TYPE (value
)),
6380 TYPE_SIZE (elttype
)));
6382 count
+= n_elts_here
;
6383 if (mostly_zeros_p (value
))
6384 zero_count
+= n_elts_here
;
6387 /* Clear the entire vector first if there are any missing elements,
6388 or if the incidence of zero elements is >= 75%. */
6389 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6392 if (need_to_clear
&& size
> 0 && !vector
)
6395 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6397 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6401 /* Inform later passes that the old value is dead. */
6402 if (!cleared
&& !vector
&& REG_P (target
))
6403 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6406 alias
= MEM_ALIAS_SET (target
);
6408 alias
= get_alias_set (elttype
);
6410 /* Store each element of the constructor into the corresponding
6411 element of TARGET, determined by counting the elements. */
6412 for (idx
= 0, i
= 0;
6413 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6414 idx
++, i
+= bitsize
/ elt_size
)
6416 HOST_WIDE_INT eltpos
;
6417 tree value
= ce
->value
;
6419 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6420 if (cleared
&& initializer_zerop (value
))
6424 eltpos
= tree_to_uhwi (ce
->index
);
6430 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6432 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6433 RTVEC_ELT (vector
, eltpos
)
6434 = expand_normal (value
);
6438 machine_mode value_mode
=
6439 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6440 ? TYPE_MODE (TREE_TYPE (value
))
6442 bitpos
= eltpos
* elt_size
;
6443 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6444 value
, cleared
, alias
);
6449 emit_insn (GEN_FCN (icode
)
6451 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6460 /* Store the value of EXP (an expression tree)
6461 into a subfield of TARGET which has mode MODE and occupies
6462 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6463 If MODE is VOIDmode, it means that we are storing into a bit-field.
6465 BITREGION_START is bitpos of the first bitfield in this region.
6466 BITREGION_END is the bitpos of the ending bitfield in this region.
6467 These two fields are 0, if the C++ memory model does not apply,
6468 or we are not interested in keeping track of bitfield regions.
6470 Always return const0_rtx unless we have something particular to
6473 ALIAS_SET is the alias set for the destination. This value will
6474 (in general) be different from that for TARGET, since TARGET is a
6475 reference to the containing structure.
6477 If NONTEMPORAL is true, try generating a nontemporal store. */
6480 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6481 unsigned HOST_WIDE_INT bitregion_start
,
6482 unsigned HOST_WIDE_INT bitregion_end
,
6483 machine_mode mode
, tree exp
,
6484 alias_set_type alias_set
, bool nontemporal
)
6486 if (TREE_CODE (exp
) == ERROR_MARK
)
6489 /* If we have nothing to store, do nothing unless the expression has
6492 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6494 if (GET_CODE (target
) == CONCAT
)
6496 /* We're storing into a struct containing a single __complex. */
6498 gcc_assert (!bitpos
);
6499 return store_expr (exp
, target
, 0, nontemporal
);
6502 /* If the structure is in a register or if the component
6503 is a bit field, we cannot use addressing to access it.
6504 Use bit-field techniques or SUBREG to store in it. */
6506 if (mode
== VOIDmode
6507 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6508 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6509 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6511 || GET_CODE (target
) == SUBREG
6512 /* If the field isn't aligned enough to store as an ordinary memref,
6513 store it as a bit field. */
6515 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6516 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6517 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6518 || (bitpos
% BITS_PER_UNIT
!= 0)))
6519 || (bitsize
>= 0 && mode
!= BLKmode
6520 && GET_MODE_BITSIZE (mode
) > bitsize
)
6521 /* If the RHS and field are a constant size and the size of the
6522 RHS isn't the same size as the bitfield, we must use bitfield
6525 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6526 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6527 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6528 decl we must use bitfield operations. */
6530 && TREE_CODE (exp
) == MEM_REF
6531 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6532 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6533 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6534 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6539 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6540 implies a mask operation. If the precision is the same size as
6541 the field we're storing into, that mask is redundant. This is
6542 particularly common with bit field assignments generated by the
6544 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6547 tree type
= TREE_TYPE (exp
);
6548 if (INTEGRAL_TYPE_P (type
)
6549 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6550 && bitsize
== TYPE_PRECISION (type
))
6552 tree op
= gimple_assign_rhs1 (nop_def
);
6553 type
= TREE_TYPE (op
);
6554 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6559 temp
= expand_normal (exp
);
6561 /* If BITSIZE is narrower than the size of the type of EXP
6562 we will be narrowing TEMP. Normally, what's wanted are the
6563 low-order bits. However, if EXP's type is a record and this is
6564 big-endian machine, we want the upper BITSIZE bits. */
6565 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6566 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6567 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6568 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6569 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6572 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6573 if (mode
!= VOIDmode
&& mode
!= BLKmode
6574 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6575 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6577 /* If the modes of TEMP and TARGET are both BLKmode, both
6578 must be in memory and BITPOS must be aligned on a byte
6579 boundary. If so, we simply do a block copy. Likewise
6580 for a BLKmode-like TARGET. */
6581 if (GET_MODE (temp
) == BLKmode
6582 && (GET_MODE (target
) == BLKmode
6584 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6585 && (bitpos
% BITS_PER_UNIT
) == 0
6586 && (bitsize
% BITS_PER_UNIT
) == 0)))
6588 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6589 && (bitpos
% BITS_PER_UNIT
) == 0);
6591 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6592 emit_block_move (target
, temp
,
6593 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6600 /* Handle calls that return values in multiple non-contiguous locations.
6601 The Irix 6 ABI has examples of this. */
6602 if (GET_CODE (temp
) == PARALLEL
)
6604 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6606 if (mode
== BLKmode
|| mode
== VOIDmode
)
6607 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6608 temp_target
= gen_reg_rtx (mode
);
6609 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6612 else if (mode
== BLKmode
)
6614 /* Handle calls that return BLKmode values in registers. */
6615 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6617 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6618 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6623 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6625 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6626 temp_target
= gen_reg_rtx (mode
);
6628 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6629 temp_target
, mode
, mode
);
6634 /* Store the value in the bitfield. */
6635 store_bit_field (target
, bitsize
, bitpos
,
6636 bitregion_start
, bitregion_end
,
6643 /* Now build a reference to just the desired component. */
6644 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6646 if (to_rtx
== target
)
6647 to_rtx
= copy_rtx (to_rtx
);
6649 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6650 set_mem_alias_set (to_rtx
, alias_set
);
6652 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6656 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6657 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6658 codes and find the ultimate containing object, which we return.
6660 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6661 bit position, and *PUNSIGNEDP to the signedness of the field.
6662 If the position of the field is variable, we store a tree
6663 giving the variable offset (in units) in *POFFSET.
6664 This offset is in addition to the bit position.
6665 If the position is not variable, we store 0 in *POFFSET.
6667 If any of the extraction expressions is volatile,
6668 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6670 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6671 Otherwise, it is a mode that can be used to access the field.
6673 If the field describes a variable-sized object, *PMODE is set to
6674 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6675 this case, but the address of the object can be found.
6677 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6678 look through nodes that serve as markers of a greater alignment than
6679 the one that can be deduced from the expression. These nodes make it
6680 possible for front-ends to prevent temporaries from being created by
6681 the middle-end on alignment considerations. For that purpose, the
6682 normal operating mode at high-level is to always pass FALSE so that
6683 the ultimate containing object is really returned; moreover, the
6684 associated predicate handled_component_p will always return TRUE
6685 on these nodes, thus indicating that they are essentially handled
6686 by get_inner_reference. TRUE should only be passed when the caller
6687 is scanning the expression in order to build another representation
6688 and specifically knows how to handle these nodes; as such, this is
6689 the normal operating mode in the RTL expanders. */
6692 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6693 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6694 machine_mode
*pmode
, int *punsignedp
,
6695 int *pvolatilep
, bool keep_aligning
)
6698 machine_mode mode
= VOIDmode
;
6699 bool blkmode_bitfield
= false;
6700 tree offset
= size_zero_node
;
6701 offset_int bit_offset
= 0;
6703 /* First get the mode, signedness, and size. We do this from just the
6704 outermost expression. */
6706 if (TREE_CODE (exp
) == COMPONENT_REF
)
6708 tree field
= TREE_OPERAND (exp
, 1);
6709 size_tree
= DECL_SIZE (field
);
6710 if (flag_strict_volatile_bitfields
> 0
6711 && TREE_THIS_VOLATILE (exp
)
6712 && DECL_BIT_FIELD_TYPE (field
)
6713 && DECL_MODE (field
) != BLKmode
)
6714 /* Volatile bitfields should be accessed in the mode of the
6715 field's type, not the mode computed based on the bit
6717 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6718 else if (!DECL_BIT_FIELD (field
))
6719 mode
= DECL_MODE (field
);
6720 else if (DECL_MODE (field
) == BLKmode
)
6721 blkmode_bitfield
= true;
6723 *punsignedp
= DECL_UNSIGNED (field
);
6725 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6727 size_tree
= TREE_OPERAND (exp
, 1);
6728 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6729 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6731 /* For vector types, with the correct size of access, use the mode of
6733 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6734 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6735 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6736 mode
= TYPE_MODE (TREE_TYPE (exp
));
6740 mode
= TYPE_MODE (TREE_TYPE (exp
));
6741 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6743 if (mode
== BLKmode
)
6744 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6746 *pbitsize
= GET_MODE_BITSIZE (mode
);
6751 if (! tree_fits_uhwi_p (size_tree
))
6752 mode
= BLKmode
, *pbitsize
= -1;
6754 *pbitsize
= tree_to_uhwi (size_tree
);
6757 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6758 and find the ultimate containing object. */
6761 switch (TREE_CODE (exp
))
6764 bit_offset
+= wi::to_offset (TREE_OPERAND (exp
, 2));
6769 tree field
= TREE_OPERAND (exp
, 1);
6770 tree this_offset
= component_ref_field_offset (exp
);
6772 /* If this field hasn't been filled in yet, don't go past it.
6773 This should only happen when folding expressions made during
6774 type construction. */
6775 if (this_offset
== 0)
6778 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6779 bit_offset
+= wi::to_offset (DECL_FIELD_BIT_OFFSET (field
));
6781 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6786 case ARRAY_RANGE_REF
:
6788 tree index
= TREE_OPERAND (exp
, 1);
6789 tree low_bound
= array_ref_low_bound (exp
);
6790 tree unit_size
= array_ref_element_size (exp
);
6792 /* We assume all arrays have sizes that are a multiple of a byte.
6793 First subtract the lower bound, if any, in the type of the
6794 index, then convert to sizetype and multiply by the size of
6795 the array element. */
6796 if (! integer_zerop (low_bound
))
6797 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6800 offset
= size_binop (PLUS_EXPR
, offset
,
6801 size_binop (MULT_EXPR
,
6802 fold_convert (sizetype
, index
),
6811 bit_offset
+= *pbitsize
;
6814 case VIEW_CONVERT_EXPR
:
6815 if (keep_aligning
&& STRICT_ALIGNMENT
6816 && (TYPE_ALIGN (TREE_TYPE (exp
))
6817 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6818 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6819 < BIGGEST_ALIGNMENT
)
6820 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6821 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6826 /* Hand back the decl for MEM[&decl, off]. */
6827 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6829 tree off
= TREE_OPERAND (exp
, 1);
6830 if (!integer_zerop (off
))
6832 offset_int boff
, coff
= mem_ref_offset (exp
);
6833 boff
= wi::lshift (coff
, LOG2_BITS_PER_UNIT
);
6836 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6844 /* If any reference in the chain is volatile, the effect is volatile. */
6845 if (TREE_THIS_VOLATILE (exp
))
6848 exp
= TREE_OPERAND (exp
, 0);
6852 /* If OFFSET is constant, see if we can return the whole thing as a
6853 constant bit position. Make sure to handle overflow during
6855 if (TREE_CODE (offset
) == INTEGER_CST
)
6857 offset_int tem
= wi::sext (wi::to_offset (offset
),
6858 TYPE_PRECISION (sizetype
));
6859 tem
= wi::lshift (tem
, LOG2_BITS_PER_UNIT
);
6861 if (wi::fits_shwi_p (tem
))
6863 *pbitpos
= tem
.to_shwi ();
6864 *poffset
= offset
= NULL_TREE
;
6868 /* Otherwise, split it up. */
6871 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6872 if (wi::neg_p (bit_offset
))
6874 offset_int mask
= wi::mask
<offset_int
> (LOG2_BITS_PER_UNIT
, false);
6875 offset_int tem
= bit_offset
.and_not (mask
);
6876 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6877 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6879 tem
= wi::arshift (tem
, LOG2_BITS_PER_UNIT
);
6880 offset
= size_binop (PLUS_EXPR
, offset
,
6881 wide_int_to_tree (sizetype
, tem
));
6884 *pbitpos
= bit_offset
.to_shwi ();
6888 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6889 if (mode
== VOIDmode
6891 && (*pbitpos
% BITS_PER_UNIT
) == 0
6892 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6900 /* Return a tree of sizetype representing the size, in bytes, of the element
6901 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6904 array_ref_element_size (tree exp
)
6906 tree aligned_size
= TREE_OPERAND (exp
, 3);
6907 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6908 location_t loc
= EXPR_LOCATION (exp
);
6910 /* If a size was specified in the ARRAY_REF, it's the size measured
6911 in alignment units of the element type. So multiply by that value. */
6914 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6915 sizetype from another type of the same width and signedness. */
6916 if (TREE_TYPE (aligned_size
) != sizetype
)
6917 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
6918 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
6919 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
6922 /* Otherwise, take the size from that of the element type. Substitute
6923 any PLACEHOLDER_EXPR that we have. */
6925 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
6928 /* Return a tree representing the lower bound of the array mentioned in
6929 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6932 array_ref_low_bound (tree exp
)
6934 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6936 /* If a lower bound is specified in EXP, use it. */
6937 if (TREE_OPERAND (exp
, 2))
6938 return TREE_OPERAND (exp
, 2);
6940 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6941 substituting for a PLACEHOLDER_EXPR as needed. */
6942 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
6943 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
6945 /* Otherwise, return a zero of the appropriate type. */
6946 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
6949 /* Returns true if REF is an array reference to an array at the end of
6950 a structure. If this is the case, the array may be allocated larger
6951 than its upper bound implies. */
6954 array_at_struct_end_p (tree ref
)
6956 if (TREE_CODE (ref
) != ARRAY_REF
6957 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
6960 while (handled_component_p (ref
))
6962 /* If the reference chain contains a component reference to a
6963 non-union type and there follows another field the reference
6964 is not at the end of a structure. */
6965 if (TREE_CODE (ref
) == COMPONENT_REF
6966 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
6968 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
6969 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
6970 nextf
= DECL_CHAIN (nextf
);
6975 ref
= TREE_OPERAND (ref
, 0);
6978 /* If the reference is based on a declared entity, the size of the array
6979 is constrained by its given domain. */
6986 /* Return a tree representing the upper bound of the array mentioned in
6987 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6990 array_ref_up_bound (tree exp
)
6992 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6994 /* If there is a domain type and it has an upper bound, use it, substituting
6995 for a PLACEHOLDER_EXPR as needed. */
6996 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
6997 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
6999 /* Otherwise fail. */
7003 /* Return a tree representing the offset, in bytes, of the field referenced
7004 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
7007 component_ref_field_offset (tree exp
)
7009 tree aligned_offset
= TREE_OPERAND (exp
, 2);
7010 tree field
= TREE_OPERAND (exp
, 1);
7011 location_t loc
= EXPR_LOCATION (exp
);
7013 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
7014 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
7018 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
7019 sizetype from another type of the same width and signedness. */
7020 if (TREE_TYPE (aligned_offset
) != sizetype
)
7021 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
7022 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
7023 size_int (DECL_OFFSET_ALIGN (field
)
7027 /* Otherwise, take the offset from that of the field. Substitute
7028 any PLACEHOLDER_EXPR that we have. */
7030 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
7033 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
7035 static unsigned HOST_WIDE_INT
7036 target_align (const_tree target
)
7038 /* We might have a chain of nested references with intermediate misaligning
7039 bitfields components, so need to recurse to find out. */
7041 unsigned HOST_WIDE_INT this_align
, outer_align
;
7043 switch (TREE_CODE (target
))
7049 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7050 outer_align
= target_align (TREE_OPERAND (target
, 0));
7051 return MIN (this_align
, outer_align
);
7054 case ARRAY_RANGE_REF
:
7055 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7056 outer_align
= target_align (TREE_OPERAND (target
, 0));
7057 return MIN (this_align
, outer_align
);
7060 case NON_LVALUE_EXPR
:
7061 case VIEW_CONVERT_EXPR
:
7062 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7063 outer_align
= target_align (TREE_OPERAND (target
, 0));
7064 return MAX (this_align
, outer_align
);
7067 return TYPE_ALIGN (TREE_TYPE (target
));
7072 /* Given an rtx VALUE that may contain additions and multiplications, return
7073 an equivalent value that just refers to a register, memory, or constant.
7074 This is done by generating instructions to perform the arithmetic and
7075 returning a pseudo-register containing the value.
7077 The returned value may be a REG, SUBREG, MEM or constant. */
7080 force_operand (rtx value
, rtx target
)
7083 /* Use subtarget as the target for operand 0 of a binary operation. */
7084 rtx subtarget
= get_subtarget (target
);
7085 enum rtx_code code
= GET_CODE (value
);
7087 /* Check for subreg applied to an expression produced by loop optimizer. */
7089 && !REG_P (SUBREG_REG (value
))
7090 && !MEM_P (SUBREG_REG (value
)))
7093 = simplify_gen_subreg (GET_MODE (value
),
7094 force_reg (GET_MODE (SUBREG_REG (value
)),
7095 force_operand (SUBREG_REG (value
),
7097 GET_MODE (SUBREG_REG (value
)),
7098 SUBREG_BYTE (value
));
7099 code
= GET_CODE (value
);
7102 /* Check for a PIC address load. */
7103 if ((code
== PLUS
|| code
== MINUS
)
7104 && XEXP (value
, 0) == pic_offset_table_rtx
7105 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7106 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7107 || GET_CODE (XEXP (value
, 1)) == CONST
))
7110 subtarget
= gen_reg_rtx (GET_MODE (value
));
7111 emit_move_insn (subtarget
, value
);
7115 if (ARITHMETIC_P (value
))
7117 op2
= XEXP (value
, 1);
7118 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7120 if (code
== MINUS
&& CONST_INT_P (op2
))
7123 op2
= negate_rtx (GET_MODE (value
), op2
);
7126 /* Check for an addition with OP2 a constant integer and our first
7127 operand a PLUS of a virtual register and something else. In that
7128 case, we want to emit the sum of the virtual register and the
7129 constant first and then add the other value. This allows virtual
7130 register instantiation to simply modify the constant rather than
7131 creating another one around this addition. */
7132 if (code
== PLUS
&& CONST_INT_P (op2
)
7133 && GET_CODE (XEXP (value
, 0)) == PLUS
7134 && REG_P (XEXP (XEXP (value
, 0), 0))
7135 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7136 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7138 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7139 XEXP (XEXP (value
, 0), 0), op2
,
7140 subtarget
, 0, OPTAB_LIB_WIDEN
);
7141 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7142 force_operand (XEXP (XEXP (value
,
7144 target
, 0, OPTAB_LIB_WIDEN
);
7147 op1
= force_operand (XEXP (value
, 0), subtarget
);
7148 op2
= force_operand (op2
, NULL_RTX
);
7152 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7154 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7155 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7156 target
, 1, OPTAB_LIB_WIDEN
);
7158 return expand_divmod (0,
7159 FLOAT_MODE_P (GET_MODE (value
))
7160 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7161 GET_MODE (value
), op1
, op2
, target
, 0);
7163 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7166 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7169 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7172 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7173 target
, 0, OPTAB_LIB_WIDEN
);
7175 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7176 target
, 1, OPTAB_LIB_WIDEN
);
7179 if (UNARY_P (value
))
7182 target
= gen_reg_rtx (GET_MODE (value
));
7183 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7190 case FLOAT_TRUNCATE
:
7191 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7196 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7200 case UNSIGNED_FLOAT
:
7201 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7205 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7209 #ifdef INSN_SCHEDULING
7210 /* On machines that have insn scheduling, we want all memory reference to be
7211 explicit, so we need to deal with such paradoxical SUBREGs. */
7212 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7214 = simplify_gen_subreg (GET_MODE (value
),
7215 force_reg (GET_MODE (SUBREG_REG (value
)),
7216 force_operand (SUBREG_REG (value
),
7218 GET_MODE (SUBREG_REG (value
)),
7219 SUBREG_BYTE (value
));
7225 /* Subroutine of expand_expr: return nonzero iff there is no way that
7226 EXP can reference X, which is being modified. TOP_P is nonzero if this
7227 call is going to be used to determine whether we need a temporary
7228 for EXP, as opposed to a recursive call to this function.
7230 It is always safe for this routine to return zero since it merely
7231 searches for optimization opportunities. */
7234 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7240 /* If EXP has varying size, we MUST use a target since we currently
7241 have no way of allocating temporaries of variable size
7242 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7243 So we assume here that something at a higher level has prevented a
7244 clash. This is somewhat bogus, but the best we can do. Only
7245 do this when X is BLKmode and when we are at the top level. */
7246 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7247 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7248 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7249 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7250 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7252 && GET_MODE (x
) == BLKmode
)
7253 /* If X is in the outgoing argument area, it is always safe. */
7255 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7256 || (GET_CODE (XEXP (x
, 0)) == PLUS
7257 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7260 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7261 find the underlying pseudo. */
7262 if (GET_CODE (x
) == SUBREG
)
7265 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7269 /* Now look at our tree code and possibly recurse. */
7270 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7272 case tcc_declaration
:
7273 exp_rtl
= DECL_RTL_IF_SET (exp
);
7279 case tcc_exceptional
:
7280 if (TREE_CODE (exp
) == TREE_LIST
)
7284 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7286 exp
= TREE_CHAIN (exp
);
7289 if (TREE_CODE (exp
) != TREE_LIST
)
7290 return safe_from_p (x
, exp
, 0);
7293 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7295 constructor_elt
*ce
;
7296 unsigned HOST_WIDE_INT idx
;
7298 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7299 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7300 || !safe_from_p (x
, ce
->value
, 0))
7304 else if (TREE_CODE (exp
) == ERROR_MARK
)
7305 return 1; /* An already-visited SAVE_EXPR? */
7310 /* The only case we look at here is the DECL_INITIAL inside a
7312 return (TREE_CODE (exp
) != DECL_EXPR
7313 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7314 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7315 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7318 case tcc_comparison
:
7319 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7324 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7326 case tcc_expression
:
7329 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7330 the expression. If it is set, we conflict iff we are that rtx or
7331 both are in memory. Otherwise, we check all operands of the
7332 expression recursively. */
7334 switch (TREE_CODE (exp
))
7337 /* If the operand is static or we are static, we can't conflict.
7338 Likewise if we don't conflict with the operand at all. */
7339 if (staticp (TREE_OPERAND (exp
, 0))
7340 || TREE_STATIC (exp
)
7341 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7344 /* Otherwise, the only way this can conflict is if we are taking
7345 the address of a DECL a that address if part of X, which is
7347 exp
= TREE_OPERAND (exp
, 0);
7350 if (!DECL_RTL_SET_P (exp
)
7351 || !MEM_P (DECL_RTL (exp
)))
7354 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7360 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7361 get_alias_set (exp
)))
7366 /* Assume that the call will clobber all hard registers and
7368 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7373 case WITH_CLEANUP_EXPR
:
7374 case CLEANUP_POINT_EXPR
:
7375 /* Lowered by gimplify.c. */
7379 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7385 /* If we have an rtx, we do not need to scan our operands. */
7389 nops
= TREE_OPERAND_LENGTH (exp
);
7390 for (i
= 0; i
< nops
; i
++)
7391 if (TREE_OPERAND (exp
, i
) != 0
7392 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7398 /* Should never get a type here. */
7402 /* If we have an rtl, find any enclosed object. Then see if we conflict
7406 if (GET_CODE (exp_rtl
) == SUBREG
)
7408 exp_rtl
= SUBREG_REG (exp_rtl
);
7410 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7414 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7415 are memory and they conflict. */
7416 return ! (rtx_equal_p (x
, exp_rtl
)
7417 || (MEM_P (x
) && MEM_P (exp_rtl
)
7418 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7421 /* If we reach here, it is safe. */
7426 /* Return the highest power of two that EXP is known to be a multiple of.
7427 This is used in updating alignment of MEMs in array references. */
7429 unsigned HOST_WIDE_INT
7430 highest_pow2_factor (const_tree exp
)
7432 unsigned HOST_WIDE_INT ret
;
7433 int trailing_zeros
= tree_ctz (exp
);
7434 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7435 return BIGGEST_ALIGNMENT
;
7436 ret
= (unsigned HOST_WIDE_INT
) 1 << trailing_zeros
;
7437 if (ret
> BIGGEST_ALIGNMENT
)
7438 return BIGGEST_ALIGNMENT
;
7442 /* Similar, except that the alignment requirements of TARGET are
7443 taken into account. Assume it is at least as aligned as its
7444 type, unless it is a COMPONENT_REF in which case the layout of
7445 the structure gives the alignment. */
7447 static unsigned HOST_WIDE_INT
7448 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7450 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7451 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7453 return MAX (factor
, talign
);
7456 #ifdef HAVE_conditional_move
7457 /* Convert the tree comparison code TCODE to the rtl one where the
7458 signedness is UNSIGNEDP. */
7460 static enum rtx_code
7461 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7473 code
= unsignedp
? LTU
: LT
;
7476 code
= unsignedp
? LEU
: LE
;
7479 code
= unsignedp
? GTU
: GT
;
7482 code
= unsignedp
? GEU
: GE
;
7484 case UNORDERED_EXPR
:
7516 /* Subroutine of expand_expr. Expand the two operands of a binary
7517 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7518 The value may be stored in TARGET if TARGET is nonzero. The
7519 MODIFIER argument is as documented by expand_expr. */
7522 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7523 enum expand_modifier modifier
)
7525 if (! safe_from_p (target
, exp1
, 1))
7527 if (operand_equal_p (exp0
, exp1
, 0))
7529 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7530 *op1
= copy_rtx (*op0
);
7534 /* If we need to preserve evaluation order, copy exp0 into its own
7535 temporary variable so that it can't be clobbered by exp1. */
7536 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7537 exp0
= save_expr (exp0
);
7538 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7539 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7544 /* Return a MEM that contains constant EXP. DEFER is as for
7545 output_constant_def and MODIFIER is as for expand_expr. */
7548 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7552 mem
= output_constant_def (exp
, defer
);
7553 if (modifier
!= EXPAND_INITIALIZER
)
7554 mem
= use_anchored_address (mem
);
7558 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7559 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7562 expand_expr_addr_expr_1 (tree exp
, rtx target
, machine_mode tmode
,
7563 enum expand_modifier modifier
, addr_space_t as
)
7565 rtx result
, subtarget
;
7567 HOST_WIDE_INT bitsize
, bitpos
;
7568 int volatilep
, unsignedp
;
7571 /* If we are taking the address of a constant and are at the top level,
7572 we have to use output_constant_def since we can't call force_const_mem
7574 /* ??? This should be considered a front-end bug. We should not be
7575 generating ADDR_EXPR of something that isn't an LVALUE. The only
7576 exception here is STRING_CST. */
7577 if (CONSTANT_CLASS_P (exp
))
7579 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7580 if (modifier
< EXPAND_SUM
)
7581 result
= force_operand (result
, target
);
7585 /* Everything must be something allowed by is_gimple_addressable. */
7586 switch (TREE_CODE (exp
))
7589 /* This case will happen via recursion for &a->b. */
7590 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7594 tree tem
= TREE_OPERAND (exp
, 0);
7595 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7596 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7597 return expand_expr (tem
, target
, tmode
, modifier
);
7601 /* Expand the initializer like constants above. */
7602 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7604 if (modifier
< EXPAND_SUM
)
7605 result
= force_operand (result
, target
);
7609 /* The real part of the complex number is always first, therefore
7610 the address is the same as the address of the parent object. */
7613 inner
= TREE_OPERAND (exp
, 0);
7617 /* The imaginary part of the complex number is always second.
7618 The expression is therefore always offset by the size of the
7621 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7622 inner
= TREE_OPERAND (exp
, 0);
7625 case COMPOUND_LITERAL_EXPR
:
7626 /* Allow COMPOUND_LITERAL_EXPR in initializers, if e.g.
7627 rtl_for_decl_init is called on DECL_INITIAL with
7628 COMPOUNT_LITERAL_EXPRs in it, they aren't gimplified. */
7629 if (modifier
== EXPAND_INITIALIZER
7630 && COMPOUND_LITERAL_EXPR_DECL (exp
))
7631 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7632 target
, tmode
, modifier
, as
);
7635 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7636 expand_expr, as that can have various side effects; LABEL_DECLs for
7637 example, may not have their DECL_RTL set yet. Expand the rtl of
7638 CONSTRUCTORs too, which should yield a memory reference for the
7639 constructor's contents. Assume language specific tree nodes can
7640 be expanded in some interesting way. */
7641 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7643 || TREE_CODE (exp
) == CONSTRUCTOR
7644 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7646 result
= expand_expr (exp
, target
, tmode
,
7647 modifier
== EXPAND_INITIALIZER
7648 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7650 /* If the DECL isn't in memory, then the DECL wasn't properly
7651 marked TREE_ADDRESSABLE, which will be either a front-end
7652 or a tree optimizer bug. */
7654 if (TREE_ADDRESSABLE (exp
)
7656 && ! targetm
.calls
.allocate_stack_slots_for_args ())
7658 error ("local frame unavailable (naked function?)");
7662 gcc_assert (MEM_P (result
));
7663 result
= XEXP (result
, 0);
7665 /* ??? Is this needed anymore? */
7667 TREE_USED (exp
) = 1;
7669 if (modifier
!= EXPAND_INITIALIZER
7670 && modifier
!= EXPAND_CONST_ADDRESS
7671 && modifier
!= EXPAND_SUM
)
7672 result
= force_operand (result
, target
);
7676 /* Pass FALSE as the last argument to get_inner_reference although
7677 we are expanding to RTL. The rationale is that we know how to
7678 handle "aligning nodes" here: we can just bypass them because
7679 they won't change the final object whose address will be returned
7680 (they actually exist only for that purpose). */
7681 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7682 &mode1
, &unsignedp
, &volatilep
, false);
7686 /* We must have made progress. */
7687 gcc_assert (inner
!= exp
);
7689 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7690 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7691 inner alignment, force the inner to be sufficiently aligned. */
7692 if (CONSTANT_CLASS_P (inner
)
7693 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7695 inner
= copy_node (inner
);
7696 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7697 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7698 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7700 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7706 if (modifier
!= EXPAND_NORMAL
)
7707 result
= force_operand (result
, NULL
);
7708 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7709 modifier
== EXPAND_INITIALIZER
7710 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7712 /* expand_expr is allowed to return an object in a mode other
7713 than TMODE. If it did, we need to convert. */
7714 if (GET_MODE (tmp
) != VOIDmode
&& tmode
!= GET_MODE (tmp
))
7715 tmp
= convert_modes (tmode
, GET_MODE (tmp
),
7716 tmp
, TYPE_UNSIGNED (TREE_TYPE (offset
)));
7717 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7718 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7720 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7721 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7724 subtarget
= bitpos
? NULL_RTX
: target
;
7725 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7726 1, OPTAB_LIB_WIDEN
);
7732 /* Someone beforehand should have rejected taking the address
7733 of such an object. */
7734 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7736 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7737 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7738 if (modifier
< EXPAND_SUM
)
7739 result
= force_operand (result
, target
);
7745 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7746 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7749 expand_expr_addr_expr (tree exp
, rtx target
, machine_mode tmode
,
7750 enum expand_modifier modifier
)
7752 addr_space_t as
= ADDR_SPACE_GENERIC
;
7753 machine_mode address_mode
= Pmode
;
7754 machine_mode pointer_mode
= ptr_mode
;
7758 /* Target mode of VOIDmode says "whatever's natural". */
7759 if (tmode
== VOIDmode
)
7760 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7762 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7764 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7765 address_mode
= targetm
.addr_space
.address_mode (as
);
7766 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7769 /* We can get called with some Weird Things if the user does silliness
7770 like "(short) &a". In that case, convert_memory_address won't do
7771 the right thing, so ignore the given target mode. */
7772 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7773 tmode
= address_mode
;
7775 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7776 tmode
, modifier
, as
);
7778 /* Despite expand_expr claims concerning ignoring TMODE when not
7779 strictly convenient, stuff breaks if we don't honor it. Note
7780 that combined with the above, we only do this for pointer modes. */
7781 rmode
= GET_MODE (result
);
7782 if (rmode
== VOIDmode
)
7785 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7790 /* Generate code for computing CONSTRUCTOR EXP.
7791 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7792 is TRUE, instead of creating a temporary variable in memory
7793 NULL is returned and the caller needs to handle it differently. */
7796 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7797 bool avoid_temp_mem
)
7799 tree type
= TREE_TYPE (exp
);
7800 machine_mode mode
= TYPE_MODE (type
);
7802 /* Try to avoid creating a temporary at all. This is possible
7803 if all of the initializer is zero.
7804 FIXME: try to handle all [0..255] initializers we can handle
7806 if (TREE_STATIC (exp
)
7807 && !TREE_ADDRESSABLE (exp
)
7808 && target
!= 0 && mode
== BLKmode
7809 && all_zeros_p (exp
))
7811 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7815 /* All elts simple constants => refer to a constant in memory. But
7816 if this is a non-BLKmode mode, let it store a field at a time
7817 since that should make a CONST_INT, CONST_WIDE_INT or
7818 CONST_DOUBLE when we fold. Likewise, if we have a target we can
7819 use, it is best to store directly into the target unless the type
7820 is large enough that memcpy will be used. If we are making an
7821 initializer and all operands are constant, put it in memory as
7824 FIXME: Avoid trying to fill vector constructors piece-meal.
7825 Output them with output_constant_def below unless we're sure
7826 they're zeros. This should go away when vector initializers
7827 are treated like VECTOR_CST instead of arrays. */
7828 if ((TREE_STATIC (exp
)
7829 && ((mode
== BLKmode
7830 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7831 || TREE_ADDRESSABLE (exp
)
7832 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7833 && (! can_move_by_pieces
7834 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7836 && ! mostly_zeros_p (exp
))))
7837 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7838 && TREE_CONSTANT (exp
)))
7845 constructor
= expand_expr_constant (exp
, 1, modifier
);
7847 if (modifier
!= EXPAND_CONST_ADDRESS
7848 && modifier
!= EXPAND_INITIALIZER
7849 && modifier
!= EXPAND_SUM
)
7850 constructor
= validize_mem (constructor
);
7855 /* Handle calls that pass values in multiple non-contiguous
7856 locations. The Irix 6 ABI has examples of this. */
7857 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7858 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7863 target
= assign_temp (type
, TREE_ADDRESSABLE (exp
), 1);
7866 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7871 /* expand_expr: generate code for computing expression EXP.
7872 An rtx for the computed value is returned. The value is never null.
7873 In the case of a void EXP, const0_rtx is returned.
7875 The value may be stored in TARGET if TARGET is nonzero.
7876 TARGET is just a suggestion; callers must assume that
7877 the rtx returned may not be the same as TARGET.
7879 If TARGET is CONST0_RTX, it means that the value will be ignored.
7881 If TMODE is not VOIDmode, it suggests generating the
7882 result in mode TMODE. But this is done only when convenient.
7883 Otherwise, TMODE is ignored and the value generated in its natural mode.
7884 TMODE is just a suggestion; callers must assume that
7885 the rtx returned may not have mode TMODE.
7887 Note that TARGET may have neither TMODE nor MODE. In that case, it
7888 probably will not be used.
7890 If MODIFIER is EXPAND_SUM then when EXP is an addition
7891 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7892 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7893 products as above, or REG or MEM, or constant.
7894 Ordinarily in such cases we would output mul or add instructions
7895 and then return a pseudo reg containing the sum.
7897 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7898 it also marks a label as absolutely required (it can't be dead).
7899 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7900 This is used for outputting expressions used in initializers.
7902 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7903 with a constant address even if that address is not normally legitimate.
7904 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7906 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7907 a call parameter. Such targets require special care as we haven't yet
7908 marked TARGET so that it's safe from being trashed by libcalls. We
7909 don't want to use TARGET for anything but the final result;
7910 Intermediate values must go elsewhere. Additionally, calls to
7911 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7913 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7914 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7915 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7916 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7919 If INNER_REFERENCE_P is true, we are expanding an inner reference.
7920 In this case, we don't adjust a returned MEM rtx that wouldn't be
7921 sufficiently aligned for its mode; instead, it's up to the caller
7922 to deal with it afterwards. This is used to make sure that unaligned
7923 base objects for which out-of-bounds accesses are supported, for
7924 example record types with trailing arrays, aren't realigned behind
7925 the back of the caller.
7926 The normal operating mode is to pass FALSE for this parameter. */
7929 expand_expr_real (tree exp
, rtx target
, machine_mode tmode
,
7930 enum expand_modifier modifier
, rtx
*alt_rtl
,
7931 bool inner_reference_p
)
7935 /* Handle ERROR_MARK before anybody tries to access its type. */
7936 if (TREE_CODE (exp
) == ERROR_MARK
7937 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7939 ret
= CONST0_RTX (tmode
);
7940 return ret
? ret
: const0_rtx
;
7943 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
,
7948 /* Try to expand the conditional expression which is represented by
7949 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7950 return the rtl reg which repsents the result. Otherwise return
7954 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7955 tree treeop1 ATTRIBUTE_UNUSED
,
7956 tree treeop2 ATTRIBUTE_UNUSED
)
7958 #ifdef HAVE_conditional_move
7960 rtx op00
, op01
, op1
, op2
;
7961 enum rtx_code comparison_code
;
7962 machine_mode comparison_mode
;
7965 tree type
= TREE_TYPE (treeop1
);
7966 int unsignedp
= TYPE_UNSIGNED (type
);
7967 machine_mode mode
= TYPE_MODE (type
);
7968 machine_mode orig_mode
= mode
;
7970 /* If we cannot do a conditional move on the mode, try doing it
7971 with the promoted mode. */
7972 if (!can_conditionally_move_p (mode
))
7974 mode
= promote_mode (type
, mode
, &unsignedp
);
7975 if (!can_conditionally_move_p (mode
))
7977 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7980 temp
= assign_temp (type
, 0, 1);
7983 expand_operands (treeop1
, treeop2
,
7984 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7986 if (TREE_CODE (treeop0
) == SSA_NAME
7987 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7989 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7990 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7991 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7992 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7993 comparison_mode
= TYPE_MODE (type
);
7994 unsignedp
= TYPE_UNSIGNED (type
);
7995 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7997 else if (TREE_CODE_CLASS (TREE_CODE (treeop0
)) == tcc_comparison
)
7999 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
8000 enum tree_code cmpcode
= TREE_CODE (treeop0
);
8001 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
8002 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
8003 unsignedp
= TYPE_UNSIGNED (type
);
8004 comparison_mode
= TYPE_MODE (type
);
8005 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
8009 op00
= expand_normal (treeop0
);
8011 comparison_code
= NE
;
8012 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
8015 if (GET_MODE (op1
) != mode
)
8016 op1
= gen_lowpart (mode
, op1
);
8018 if (GET_MODE (op2
) != mode
)
8019 op2
= gen_lowpart (mode
, op2
);
8021 /* Try to emit the conditional move. */
8022 insn
= emit_conditional_move (temp
, comparison_code
,
8023 op00
, op01
, comparison_mode
,
8027 /* If we could do the conditional move, emit the sequence,
8031 rtx_insn
*seq
= get_insns ();
8034 return convert_modes (orig_mode
, mode
, temp
, 0);
8037 /* Otherwise discard the sequence and fall back to code with
8045 expand_expr_real_2 (sepops ops
, rtx target
, machine_mode tmode
,
8046 enum expand_modifier modifier
)
8048 rtx op0
, op1
, op2
, temp
;
8052 enum tree_code code
= ops
->code
;
8054 rtx subtarget
, original_target
;
8056 bool reduce_bit_field
;
8057 location_t loc
= ops
->location
;
8058 tree treeop0
, treeop1
, treeop2
;
8059 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8060 ? reduce_to_bit_field_precision ((expr), \
8066 mode
= TYPE_MODE (type
);
8067 unsignedp
= TYPE_UNSIGNED (type
);
8073 /* We should be called only on simple (binary or unary) expressions,
8074 exactly those that are valid in gimple expressions that aren't
8075 GIMPLE_SINGLE_RHS (or invalid). */
8076 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8077 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8078 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8080 ignore
= (target
== const0_rtx
8081 || ((CONVERT_EXPR_CODE_P (code
)
8082 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8083 && TREE_CODE (type
) == VOID_TYPE
));
8085 /* We should be called only if we need the result. */
8086 gcc_assert (!ignore
);
8088 /* An operation in what may be a bit-field type needs the
8089 result to be reduced to the precision of the bit-field type,
8090 which is narrower than that of the type's mode. */
8091 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8092 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8094 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8097 /* Use subtarget as the target for operand 0 of a binary operation. */
8098 subtarget
= get_subtarget (target
);
8099 original_target
= target
;
8103 case NON_LVALUE_EXPR
:
8106 if (treeop0
== error_mark_node
)
8109 if (TREE_CODE (type
) == UNION_TYPE
)
8111 tree valtype
= TREE_TYPE (treeop0
);
8113 /* If both input and output are BLKmode, this conversion isn't doing
8114 anything except possibly changing memory attribute. */
8115 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8117 rtx result
= expand_expr (treeop0
, target
, tmode
,
8120 result
= copy_rtx (result
);
8121 set_mem_attributes (result
, type
, 0);
8127 if (TYPE_MODE (type
) != BLKmode
)
8128 target
= gen_reg_rtx (TYPE_MODE (type
));
8130 target
= assign_temp (type
, 1, 1);
8134 /* Store data into beginning of memory target. */
8135 store_expr (treeop0
,
8136 adjust_address (target
, TYPE_MODE (valtype
), 0),
8137 modifier
== EXPAND_STACK_PARM
,
8142 gcc_assert (REG_P (target
));
8144 /* Store this field into a union of the proper type. */
8145 store_field (target
,
8146 MIN ((int_size_in_bytes (TREE_TYPE
8149 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8150 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8153 /* Return the entire union. */
8157 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8159 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8162 /* If the signedness of the conversion differs and OP0 is
8163 a promoted SUBREG, clear that indication since we now
8164 have to do the proper extension. */
8165 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8166 && GET_CODE (op0
) == SUBREG
)
8167 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8169 return REDUCE_BIT_FIELD (op0
);
8172 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8173 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8174 if (GET_MODE (op0
) == mode
)
8177 /* If OP0 is a constant, just convert it into the proper mode. */
8178 else if (CONSTANT_P (op0
))
8180 tree inner_type
= TREE_TYPE (treeop0
);
8181 machine_mode inner_mode
= GET_MODE (op0
);
8183 if (inner_mode
== VOIDmode
)
8184 inner_mode
= TYPE_MODE (inner_type
);
8186 if (modifier
== EXPAND_INITIALIZER
)
8187 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
8188 subreg_lowpart_offset (mode
,
8191 op0
= convert_modes (mode
, inner_mode
, op0
,
8192 TYPE_UNSIGNED (inner_type
));
8195 else if (modifier
== EXPAND_INITIALIZER
)
8196 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8198 else if (target
== 0)
8199 op0
= convert_to_mode (mode
, op0
,
8200 TYPE_UNSIGNED (TREE_TYPE
8204 convert_move (target
, op0
,
8205 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8209 return REDUCE_BIT_FIELD (op0
);
8211 case ADDR_SPACE_CONVERT_EXPR
:
8213 tree treeop0_type
= TREE_TYPE (treeop0
);
8215 addr_space_t as_from
;
8217 gcc_assert (POINTER_TYPE_P (type
));
8218 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8220 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8221 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8223 /* Conversions between pointers to the same address space should
8224 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8225 gcc_assert (as_to
!= as_from
);
8227 /* Ask target code to handle conversion between pointers
8228 to overlapping address spaces. */
8229 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8230 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8232 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8233 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8238 /* For disjoint address spaces, converting anything but
8239 a null pointer invokes undefined behaviour. We simply
8240 always return a null pointer here. */
8241 return CONST0_RTX (mode
);
8244 case POINTER_PLUS_EXPR
:
8245 /* Even though the sizetype mode and the pointer's mode can be different
8246 expand is able to handle this correctly and get the correct result out
8247 of the PLUS_EXPR code. */
8248 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8249 if sizetype precision is smaller than pointer precision. */
8250 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8251 treeop1
= fold_convert_loc (loc
, type
,
8252 fold_convert_loc (loc
, ssizetype
,
8254 /* If sizetype precision is larger than pointer precision, truncate the
8255 offset to have matching modes. */
8256 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8257 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8260 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8261 something else, make sure we add the register to the constant and
8262 then to the other thing. This case can occur during strength
8263 reduction and doing it this way will produce better code if the
8264 frame pointer or argument pointer is eliminated.
8266 fold-const.c will ensure that the constant is always in the inner
8267 PLUS_EXPR, so the only case we need to do anything about is if
8268 sp, ap, or fp is our second argument, in which case we must swap
8269 the innermost first argument and our second argument. */
8271 if (TREE_CODE (treeop0
) == PLUS_EXPR
8272 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8273 && TREE_CODE (treeop1
) == VAR_DECL
8274 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8275 || DECL_RTL (treeop1
) == stack_pointer_rtx
8276 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8281 /* If the result is to be ptr_mode and we are adding an integer to
8282 something, we might be forming a constant. So try to use
8283 plus_constant. If it produces a sum and we can't accept it,
8284 use force_operand. This allows P = &ARR[const] to generate
8285 efficient code on machines where a SYMBOL_REF is not a valid
8288 If this is an EXPAND_SUM call, always return the sum. */
8289 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8290 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8292 if (modifier
== EXPAND_STACK_PARM
)
8294 if (TREE_CODE (treeop0
) == INTEGER_CST
8295 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8296 && TREE_CONSTANT (treeop1
))
8300 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop1
));
8302 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8304 /* Use wi::shwi to ensure that the constant is
8305 truncated according to the mode of OP1, then sign extended
8306 to a HOST_WIDE_INT. Using the constant directly can result
8307 in non-canonical RTL in a 64x32 cross compile. */
8308 wc
= TREE_INT_CST_LOW (treeop0
);
8310 immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8311 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8312 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8313 op1
= force_operand (op1
, target
);
8314 return REDUCE_BIT_FIELD (op1
);
8317 else if (TREE_CODE (treeop1
) == INTEGER_CST
8318 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8319 && TREE_CONSTANT (treeop0
))
8323 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop0
));
8325 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8326 (modifier
== EXPAND_INITIALIZER
8327 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8328 if (! CONSTANT_P (op0
))
8330 op1
= expand_expr (treeop1
, NULL_RTX
,
8331 VOIDmode
, modifier
);
8332 /* Return a PLUS if modifier says it's OK. */
8333 if (modifier
== EXPAND_SUM
8334 || modifier
== EXPAND_INITIALIZER
)
8335 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8338 /* Use wi::shwi to ensure that the constant is
8339 truncated according to the mode of OP1, then sign extended
8340 to a HOST_WIDE_INT. Using the constant directly can result
8341 in non-canonical RTL in a 64x32 cross compile. */
8342 wc
= TREE_INT_CST_LOW (treeop1
);
8344 = immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8345 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8346 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8347 op0
= force_operand (op0
, target
);
8348 return REDUCE_BIT_FIELD (op0
);
8352 /* Use TER to expand pointer addition of a negated value
8353 as pointer subtraction. */
8354 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8355 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8356 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8357 && TREE_CODE (treeop1
) == SSA_NAME
8358 && TYPE_MODE (TREE_TYPE (treeop0
))
8359 == TYPE_MODE (TREE_TYPE (treeop1
)))
8361 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8364 treeop1
= gimple_assign_rhs1 (def
);
8370 /* No sense saving up arithmetic to be done
8371 if it's all in the wrong mode to form part of an address.
8372 And force_operand won't know whether to sign-extend or
8374 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8375 || mode
!= ptr_mode
)
8377 expand_operands (treeop0
, treeop1
,
8378 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8379 if (op0
== const0_rtx
)
8381 if (op1
== const0_rtx
)
8386 expand_operands (treeop0
, treeop1
,
8387 subtarget
, &op0
, &op1
, modifier
);
8388 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8392 /* For initializers, we are allowed to return a MINUS of two
8393 symbolic constants. Here we handle all cases when both operands
8395 /* Handle difference of two symbolic constants,
8396 for the sake of an initializer. */
8397 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8398 && really_constant_p (treeop0
)
8399 && really_constant_p (treeop1
))
8401 expand_operands (treeop0
, treeop1
,
8402 NULL_RTX
, &op0
, &op1
, modifier
);
8404 /* If the last operand is a CONST_INT, use plus_constant of
8405 the negated constant. Else make the MINUS. */
8406 if (CONST_INT_P (op1
))
8407 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8410 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8413 /* No sense saving up arithmetic to be done
8414 if it's all in the wrong mode to form part of an address.
8415 And force_operand won't know whether to sign-extend or
8417 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8418 || mode
!= ptr_mode
)
8421 expand_operands (treeop0
, treeop1
,
8422 subtarget
, &op0
, &op1
, modifier
);
8424 /* Convert A - const to A + (-const). */
8425 if (CONST_INT_P (op1
))
8427 op1
= negate_rtx (mode
, op1
);
8428 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8433 case WIDEN_MULT_PLUS_EXPR
:
8434 case WIDEN_MULT_MINUS_EXPR
:
8435 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8436 op2
= expand_normal (treeop2
);
8437 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8441 case WIDEN_MULT_EXPR
:
8442 /* If first operand is constant, swap them.
8443 Thus the following special case checks need only
8444 check the second operand. */
8445 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8452 /* First, check if we have a multiplication of one signed and one
8453 unsigned operand. */
8454 if (TREE_CODE (treeop1
) != INTEGER_CST
8455 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8456 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8458 machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8459 this_optab
= usmul_widen_optab
;
8460 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8461 != CODE_FOR_nothing
)
8463 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8464 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8467 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8469 /* op0 and op1 might still be constant, despite the above
8470 != INTEGER_CST check. Handle it. */
8471 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8473 op0
= convert_modes (innermode
, mode
, op0
, true);
8474 op1
= convert_modes (innermode
, mode
, op1
, false);
8475 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8476 target
, unsignedp
));
8481 /* Check for a multiplication with matching signedness. */
8482 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8483 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8484 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8485 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8487 tree op0type
= TREE_TYPE (treeop0
);
8488 machine_mode innermode
= TYPE_MODE (op0type
);
8489 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8490 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8491 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8493 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8495 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8496 != CODE_FOR_nothing
)
8498 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8500 /* op0 and op1 might still be constant, despite the above
8501 != INTEGER_CST check. Handle it. */
8502 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8505 op0
= convert_modes (innermode
, mode
, op0
, zextend_p
);
8507 = convert_modes (innermode
, mode
, op1
,
8508 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8509 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8513 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8514 unsignedp
, this_optab
);
8515 return REDUCE_BIT_FIELD (temp
);
8517 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8519 && innermode
== word_mode
)
8522 op0
= expand_normal (treeop0
);
8523 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8524 op1
= convert_modes (innermode
, mode
,
8525 expand_normal (treeop1
),
8526 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8528 op1
= expand_normal (treeop1
);
8529 /* op0 and op1 might still be constant, despite the above
8530 != INTEGER_CST check. Handle it. */
8531 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8532 goto widen_mult_const
;
8533 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8534 unsignedp
, OPTAB_LIB_WIDEN
);
8535 hipart
= gen_highpart (innermode
, temp
);
8536 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8540 emit_move_insn (hipart
, htem
);
8541 return REDUCE_BIT_FIELD (temp
);
8545 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8546 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8547 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8548 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8552 optab opt
= fma_optab
;
8555 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8557 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8559 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8562 gcc_assert (fn
!= NULL_TREE
);
8563 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8564 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8567 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8568 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8573 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8576 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8577 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8580 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8583 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8586 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8589 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8593 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8595 op2
= expand_normal (treeop2
);
8596 op1
= expand_normal (treeop1
);
8598 return expand_ternary_op (TYPE_MODE (type
), opt
,
8599 op0
, op1
, op2
, target
, 0);
8603 /* If this is a fixed-point operation, then we cannot use the code
8604 below because "expand_mult" doesn't support sat/no-sat fixed-point
8606 if (ALL_FIXED_POINT_MODE_P (mode
))
8609 /* If first operand is constant, swap them.
8610 Thus the following special case checks need only
8611 check the second operand. */
8612 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8619 /* Attempt to return something suitable for generating an
8620 indexed address, for machines that support that. */
8622 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8623 && tree_fits_shwi_p (treeop1
))
8625 tree exp1
= treeop1
;
8627 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8631 op0
= force_operand (op0
, NULL_RTX
);
8633 op0
= copy_to_mode_reg (mode
, op0
);
8635 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8636 gen_int_mode (tree_to_shwi (exp1
),
8637 TYPE_MODE (TREE_TYPE (exp1
)))));
8640 if (modifier
== EXPAND_STACK_PARM
)
8643 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8644 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8646 case TRUNC_DIV_EXPR
:
8647 case FLOOR_DIV_EXPR
:
8649 case ROUND_DIV_EXPR
:
8650 case EXACT_DIV_EXPR
:
8651 /* If this is a fixed-point operation, then we cannot use the code
8652 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8654 if (ALL_FIXED_POINT_MODE_P (mode
))
8657 if (modifier
== EXPAND_STACK_PARM
)
8659 /* Possible optimization: compute the dividend with EXPAND_SUM
8660 then if the divisor is constant can optimize the case
8661 where some terms of the dividend have coeffs divisible by it. */
8662 expand_operands (treeop0
, treeop1
,
8663 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8664 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8669 case MULT_HIGHPART_EXPR
:
8670 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8671 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8675 case TRUNC_MOD_EXPR
:
8676 case FLOOR_MOD_EXPR
:
8678 case ROUND_MOD_EXPR
:
8679 if (modifier
== EXPAND_STACK_PARM
)
8681 expand_operands (treeop0
, treeop1
,
8682 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8683 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8685 case FIXED_CONVERT_EXPR
:
8686 op0
= expand_normal (treeop0
);
8687 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8688 target
= gen_reg_rtx (mode
);
8690 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8691 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8692 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8693 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8695 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8698 case FIX_TRUNC_EXPR
:
8699 op0
= expand_normal (treeop0
);
8700 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8701 target
= gen_reg_rtx (mode
);
8702 expand_fix (target
, op0
, unsignedp
);
8706 op0
= expand_normal (treeop0
);
8707 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8708 target
= gen_reg_rtx (mode
);
8709 /* expand_float can't figure out what to do if FROM has VOIDmode.
8710 So give it the correct mode. With -O, cse will optimize this. */
8711 if (GET_MODE (op0
) == VOIDmode
)
8712 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8714 expand_float (target
, op0
,
8715 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8719 op0
= expand_expr (treeop0
, subtarget
,
8720 VOIDmode
, EXPAND_NORMAL
);
8721 if (modifier
== EXPAND_STACK_PARM
)
8723 temp
= expand_unop (mode
,
8724 optab_for_tree_code (NEGATE_EXPR
, type
,
8728 return REDUCE_BIT_FIELD (temp
);
8731 op0
= expand_expr (treeop0
, subtarget
,
8732 VOIDmode
, EXPAND_NORMAL
);
8733 if (modifier
== EXPAND_STACK_PARM
)
8736 /* ABS_EXPR is not valid for complex arguments. */
8737 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8738 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8740 /* Unsigned abs is simply the operand. Testing here means we don't
8741 risk generating incorrect code below. */
8742 if (TYPE_UNSIGNED (type
))
8745 return expand_abs (mode
, op0
, target
, unsignedp
,
8746 safe_from_p (target
, treeop0
, 1));
8750 target
= original_target
;
8752 || modifier
== EXPAND_STACK_PARM
8753 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8754 || GET_MODE (target
) != mode
8756 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8757 target
= gen_reg_rtx (mode
);
8758 expand_operands (treeop0
, treeop1
,
8759 target
, &op0
, &op1
, EXPAND_NORMAL
);
8761 /* First try to do it with a special MIN or MAX instruction.
8762 If that does not win, use a conditional jump to select the proper
8764 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8765 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8770 /* At this point, a MEM target is no longer useful; we will get better
8773 if (! REG_P (target
))
8774 target
= gen_reg_rtx (mode
);
8776 /* If op1 was placed in target, swap op0 and op1. */
8777 if (target
!= op0
&& target
== op1
)
8784 /* We generate better code and avoid problems with op1 mentioning
8785 target by forcing op1 into a pseudo if it isn't a constant. */
8786 if (! CONSTANT_P (op1
))
8787 op1
= force_reg (mode
, op1
);
8790 enum rtx_code comparison_code
;
8793 if (code
== MAX_EXPR
)
8794 comparison_code
= unsignedp
? GEU
: GE
;
8796 comparison_code
= unsignedp
? LEU
: LE
;
8798 /* Canonicalize to comparisons against 0. */
8799 if (op1
== const1_rtx
)
8801 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8802 or (a != 0 ? a : 1) for unsigned.
8803 For MIN we are safe converting (a <= 1 ? a : 1)
8804 into (a <= 0 ? a : 1) */
8805 cmpop1
= const0_rtx
;
8806 if (code
== MAX_EXPR
)
8807 comparison_code
= unsignedp
? NE
: GT
;
8809 if (op1
== constm1_rtx
&& !unsignedp
)
8811 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8812 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8813 cmpop1
= const0_rtx
;
8814 if (code
== MIN_EXPR
)
8815 comparison_code
= LT
;
8817 #ifdef HAVE_conditional_move
8818 /* Use a conditional move if possible. */
8819 if (can_conditionally_move_p (mode
))
8825 /* Try to emit the conditional move. */
8826 insn
= emit_conditional_move (target
, comparison_code
,
8831 /* If we could do the conditional move, emit the sequence,
8835 rtx_insn
*seq
= get_insns ();
8841 /* Otherwise discard the sequence and fall back to code with
8847 emit_move_insn (target
, op0
);
8849 temp
= gen_label_rtx ();
8850 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8851 unsignedp
, mode
, NULL_RTX
, NULL_RTX
, temp
,
8854 emit_move_insn (target
, op1
);
8859 op0
= expand_expr (treeop0
, subtarget
,
8860 VOIDmode
, EXPAND_NORMAL
);
8861 if (modifier
== EXPAND_STACK_PARM
)
8863 /* In case we have to reduce the result to bitfield precision
8864 for unsigned bitfield expand this as XOR with a proper constant
8866 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8868 wide_int mask
= wi::mask (TYPE_PRECISION (type
),
8869 false, GET_MODE_PRECISION (mode
));
8871 temp
= expand_binop (mode
, xor_optab
, op0
,
8872 immed_wide_int_const (mask
, mode
),
8873 target
, 1, OPTAB_LIB_WIDEN
);
8876 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8880 /* ??? Can optimize bitwise operations with one arg constant.
8881 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8882 and (a bitwise1 b) bitwise2 b (etc)
8883 but that is probably not worth while. */
8892 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8893 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8894 == TYPE_PRECISION (type
)));
8899 /* If this is a fixed-point operation, then we cannot use the code
8900 below because "expand_shift" doesn't support sat/no-sat fixed-point
8902 if (ALL_FIXED_POINT_MODE_P (mode
))
8905 if (! safe_from_p (subtarget
, treeop1
, 1))
8907 if (modifier
== EXPAND_STACK_PARM
)
8909 op0
= expand_expr (treeop0
, subtarget
,
8910 VOIDmode
, EXPAND_NORMAL
);
8911 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8913 if (code
== LSHIFT_EXPR
)
8914 temp
= REDUCE_BIT_FIELD (temp
);
8917 /* Could determine the answer when only additive constants differ. Also,
8918 the addition of one can be handled by changing the condition. */
8925 case UNORDERED_EXPR
:
8933 temp
= do_store_flag (ops
,
8934 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8935 tmode
!= VOIDmode
? tmode
: mode
);
8939 /* Use a compare and a jump for BLKmode comparisons, or for function
8940 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8943 || modifier
== EXPAND_STACK_PARM
8944 || ! safe_from_p (target
, treeop0
, 1)
8945 || ! safe_from_p (target
, treeop1
, 1)
8946 /* Make sure we don't have a hard reg (such as function's return
8947 value) live across basic blocks, if not optimizing. */
8948 || (!optimize
&& REG_P (target
)
8949 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8950 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8952 emit_move_insn (target
, const0_rtx
);
8954 op1
= gen_label_rtx ();
8955 jumpifnot_1 (code
, treeop0
, treeop1
, op1
, -1);
8957 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8958 emit_move_insn (target
, constm1_rtx
);
8960 emit_move_insn (target
, const1_rtx
);
8966 /* Get the rtx code of the operands. */
8967 op0
= expand_normal (treeop0
);
8968 op1
= expand_normal (treeop1
);
8971 target
= gen_reg_rtx (TYPE_MODE (type
));
8973 /* If target overlaps with op1, then either we need to force
8974 op1 into a pseudo (if target also overlaps with op0),
8975 or write the complex parts in reverse order. */
8976 switch (GET_CODE (target
))
8979 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
8981 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
8983 complex_expr_force_op1
:
8984 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
8985 emit_move_insn (temp
, op1
);
8989 complex_expr_swap_order
:
8990 /* Move the imaginary (op1) and real (op0) parts to their
8992 write_complex_part (target
, op1
, true);
8993 write_complex_part (target
, op0
, false);
8999 temp
= adjust_address_nv (target
,
9000 GET_MODE_INNER (GET_MODE (target
)), 0);
9001 if (reg_overlap_mentioned_p (temp
, op1
))
9003 machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
9004 temp
= adjust_address_nv (target
, imode
,
9005 GET_MODE_SIZE (imode
));
9006 if (reg_overlap_mentioned_p (temp
, op0
))
9007 goto complex_expr_force_op1
;
9008 goto complex_expr_swap_order
;
9012 if (reg_overlap_mentioned_p (target
, op1
))
9014 if (reg_overlap_mentioned_p (target
, op0
))
9015 goto complex_expr_force_op1
;
9016 goto complex_expr_swap_order
;
9021 /* Move the real (op0) and imaginary (op1) parts to their location. */
9022 write_complex_part (target
, op0
, false);
9023 write_complex_part (target
, op1
, true);
9027 case WIDEN_SUM_EXPR
:
9029 tree oprnd0
= treeop0
;
9030 tree oprnd1
= treeop1
;
9032 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9033 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
9038 case REDUC_MAX_EXPR
:
9039 case REDUC_MIN_EXPR
:
9040 case REDUC_PLUS_EXPR
:
9042 op0
= expand_normal (treeop0
);
9043 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9044 machine_mode vec_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9046 if (optab_handler (this_optab
, vec_mode
) != CODE_FOR_nothing
)
9048 struct expand_operand ops
[2];
9049 enum insn_code icode
= optab_handler (this_optab
, vec_mode
);
9051 create_output_operand (&ops
[0], target
, mode
);
9052 create_input_operand (&ops
[1], op0
, vec_mode
);
9053 if (maybe_expand_insn (icode
, 2, ops
))
9055 target
= ops
[0].value
;
9056 if (GET_MODE (target
) != mode
)
9057 return gen_lowpart (tmode
, target
);
9061 /* Fall back to optab with vector result, and then extract scalar. */
9062 this_optab
= scalar_reduc_to_vector (this_optab
, type
);
9063 temp
= expand_unop (vec_mode
, this_optab
, op0
, NULL_RTX
, unsignedp
);
9065 /* The tree code produces a scalar result, but (somewhat by convention)
9066 the optab produces a vector with the result in element 0 if
9067 little-endian, or element N-1 if big-endian. So pull the scalar
9068 result out of that element. */
9069 int index
= BYTES_BIG_ENDIAN
? GET_MODE_NUNITS (vec_mode
) - 1 : 0;
9070 int bitsize
= GET_MODE_BITSIZE (GET_MODE_INNER (vec_mode
));
9071 temp
= extract_bit_field (temp
, bitsize
, bitsize
* index
, unsignedp
,
9072 target
, mode
, mode
);
9077 case VEC_RSHIFT_EXPR
:
9079 target
= expand_vec_shift_expr (ops
, target
);
9083 case VEC_UNPACK_HI_EXPR
:
9084 case VEC_UNPACK_LO_EXPR
:
9086 op0
= expand_normal (treeop0
);
9087 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9093 case VEC_UNPACK_FLOAT_HI_EXPR
:
9094 case VEC_UNPACK_FLOAT_LO_EXPR
:
9096 op0
= expand_normal (treeop0
);
9097 /* The signedness is determined from input operand. */
9098 temp
= expand_widen_pattern_expr
9099 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9100 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9106 case VEC_WIDEN_MULT_HI_EXPR
:
9107 case VEC_WIDEN_MULT_LO_EXPR
:
9108 case VEC_WIDEN_MULT_EVEN_EXPR
:
9109 case VEC_WIDEN_MULT_ODD_EXPR
:
9110 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9111 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9112 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9113 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9115 gcc_assert (target
);
9118 case VEC_PACK_TRUNC_EXPR
:
9119 case VEC_PACK_SAT_EXPR
:
9120 case VEC_PACK_FIX_TRUNC_EXPR
:
9121 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9125 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9126 op2
= expand_normal (treeop2
);
9128 /* Careful here: if the target doesn't support integral vector modes,
9129 a constant selection vector could wind up smooshed into a normal
9130 integral constant. */
9131 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9133 tree sel_type
= TREE_TYPE (treeop2
);
9135 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9136 TYPE_VECTOR_SUBPARTS (sel_type
));
9137 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9138 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9139 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9142 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9144 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9150 tree oprnd0
= treeop0
;
9151 tree oprnd1
= treeop1
;
9152 tree oprnd2
= treeop2
;
9155 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9156 op2
= expand_normal (oprnd2
);
9157 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9164 tree oprnd0
= treeop0
;
9165 tree oprnd1
= treeop1
;
9166 tree oprnd2
= treeop2
;
9169 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9170 op2
= expand_normal (oprnd2
);
9171 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9176 case REALIGN_LOAD_EXPR
:
9178 tree oprnd0
= treeop0
;
9179 tree oprnd1
= treeop1
;
9180 tree oprnd2
= treeop2
;
9183 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9184 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9185 op2
= expand_normal (oprnd2
);
9186 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9193 /* A COND_EXPR with its type being VOID_TYPE represents a
9194 conditional jump and is handled in
9195 expand_gimple_cond_expr. */
9196 gcc_assert (!VOID_TYPE_P (type
));
9198 /* Note that COND_EXPRs whose type is a structure or union
9199 are required to be constructed to contain assignments of
9200 a temporary variable, so that we can evaluate them here
9201 for side effect only. If type is void, we must do likewise. */
9203 gcc_assert (!TREE_ADDRESSABLE (type
)
9205 && TREE_TYPE (treeop1
) != void_type_node
9206 && TREE_TYPE (treeop2
) != void_type_node
);
9208 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9212 /* If we are not to produce a result, we have no target. Otherwise,
9213 if a target was specified use it; it will not be used as an
9214 intermediate target unless it is safe. If no target, use a
9217 if (modifier
!= EXPAND_STACK_PARM
9219 && safe_from_p (original_target
, treeop0
, 1)
9220 && GET_MODE (original_target
) == mode
9221 && !MEM_P (original_target
))
9222 temp
= original_target
;
9224 temp
= assign_temp (type
, 0, 1);
9226 do_pending_stack_adjust ();
9228 op0
= gen_label_rtx ();
9229 op1
= gen_label_rtx ();
9230 jumpifnot (treeop0
, op0
, -1);
9231 store_expr (treeop1
, temp
,
9232 modifier
== EXPAND_STACK_PARM
,
9235 emit_jump_insn (gen_jump (op1
));
9238 store_expr (treeop2
, temp
,
9239 modifier
== EXPAND_STACK_PARM
,
9247 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9254 /* Here to do an ordinary binary operator. */
9256 expand_operands (treeop0
, treeop1
,
9257 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9259 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9261 if (modifier
== EXPAND_STACK_PARM
)
9263 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9264 unsignedp
, OPTAB_LIB_WIDEN
);
9266 /* Bitwise operations do not need bitfield reduction as we expect their
9267 operands being properly truncated. */
9268 if (code
== BIT_XOR_EXPR
9269 || code
== BIT_AND_EXPR
9270 || code
== BIT_IOR_EXPR
)
9272 return REDUCE_BIT_FIELD (temp
);
9274 #undef REDUCE_BIT_FIELD
9277 /* Return TRUE if expression STMT is suitable for replacement.
9278 Never consider memory loads as replaceable, because those don't ever lead
9279 into constant expressions. */
9282 stmt_is_replaceable_p (gimple stmt
)
9284 if (ssa_is_replaceable_p (stmt
))
9286 /* Don't move around loads. */
9287 if (!gimple_assign_single_p (stmt
)
9288 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9295 expand_expr_real_1 (tree exp
, rtx target
, machine_mode tmode
,
9296 enum expand_modifier modifier
, rtx
*alt_rtl
,
9297 bool inner_reference_p
)
9299 rtx op0
, op1
, temp
, decl_rtl
;
9303 enum tree_code code
= TREE_CODE (exp
);
9304 rtx subtarget
, original_target
;
9307 bool reduce_bit_field
;
9308 location_t loc
= EXPR_LOCATION (exp
);
9309 struct separate_ops ops
;
9310 tree treeop0
, treeop1
, treeop2
;
9311 tree ssa_name
= NULL_TREE
;
9314 type
= TREE_TYPE (exp
);
9315 mode
= TYPE_MODE (type
);
9316 unsignedp
= TYPE_UNSIGNED (type
);
9318 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9319 if (!VL_EXP_CLASS_P (exp
))
9320 switch (TREE_CODE_LENGTH (code
))
9323 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9324 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9325 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9335 ignore
= (target
== const0_rtx
9336 || ((CONVERT_EXPR_CODE_P (code
)
9337 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9338 && TREE_CODE (type
) == VOID_TYPE
));
9340 /* An operation in what may be a bit-field type needs the
9341 result to be reduced to the precision of the bit-field type,
9342 which is narrower than that of the type's mode. */
9343 reduce_bit_field
= (!ignore
9344 && INTEGRAL_TYPE_P (type
)
9345 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9347 /* If we are going to ignore this result, we need only do something
9348 if there is a side-effect somewhere in the expression. If there
9349 is, short-circuit the most common cases here. Note that we must
9350 not call expand_expr with anything but const0_rtx in case this
9351 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9355 if (! TREE_SIDE_EFFECTS (exp
))
9358 /* Ensure we reference a volatile object even if value is ignored, but
9359 don't do this if all we are doing is taking its address. */
9360 if (TREE_THIS_VOLATILE (exp
)
9361 && TREE_CODE (exp
) != FUNCTION_DECL
9362 && mode
!= VOIDmode
&& mode
!= BLKmode
9363 && modifier
!= EXPAND_CONST_ADDRESS
)
9365 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9371 if (TREE_CODE_CLASS (code
) == tcc_unary
9372 || code
== BIT_FIELD_REF
9373 || code
== COMPONENT_REF
9374 || code
== INDIRECT_REF
)
9375 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9378 else if (TREE_CODE_CLASS (code
) == tcc_binary
9379 || TREE_CODE_CLASS (code
) == tcc_comparison
9380 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9382 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9383 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9390 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9393 /* Use subtarget as the target for operand 0 of a binary operation. */
9394 subtarget
= get_subtarget (target
);
9395 original_target
= target
;
9401 tree function
= decl_function_context (exp
);
9403 temp
= label_rtx (exp
);
9404 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9406 if (function
!= current_function_decl
9408 LABEL_REF_NONLOCAL_P (temp
) = 1;
9410 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9415 /* ??? ivopts calls expander, without any preparation from
9416 out-of-ssa. So fake instructions as if this was an access to the
9417 base variable. This unnecessarily allocates a pseudo, see how we can
9418 reuse it, if partition base vars have it set already. */
9419 if (!currently_expanding_to_rtl
)
9421 tree var
= SSA_NAME_VAR (exp
);
9422 if (var
&& DECL_RTL_SET_P (var
))
9423 return DECL_RTL (var
);
9424 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9425 LAST_VIRTUAL_REGISTER
+ 1);
9428 g
= get_gimple_for_ssa_name (exp
);
9429 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9431 && modifier
== EXPAND_INITIALIZER
9432 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9433 && (optimize
|| DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9434 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9435 g
= SSA_NAME_DEF_STMT (exp
);
9439 ops
.code
= gimple_assign_rhs_code (g
);
9440 switch (get_gimple_rhs_class (ops
.code
))
9442 case GIMPLE_TERNARY_RHS
:
9443 ops
.op2
= gimple_assign_rhs3 (g
);
9445 case GIMPLE_BINARY_RHS
:
9446 ops
.op1
= gimple_assign_rhs2 (g
);
9448 case GIMPLE_UNARY_RHS
:
9449 ops
.op0
= gimple_assign_rhs1 (g
);
9450 ops
.type
= TREE_TYPE (gimple_assign_lhs (g
));
9451 ops
.location
= gimple_location (g
);
9452 r
= expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
9454 case GIMPLE_SINGLE_RHS
:
9456 location_t saved_loc
= curr_insn_location ();
9457 set_curr_insn_location (gimple_location (g
));
9458 r
= expand_expr_real (gimple_assign_rhs1 (g
), target
,
9459 tmode
, modifier
, NULL
, inner_reference_p
);
9460 set_curr_insn_location (saved_loc
);
9466 if (REG_P (r
) && !REG_EXPR (r
))
9467 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9472 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9473 exp
= SSA_NAME_VAR (ssa_name
);
9474 goto expand_decl_rtl
;
9478 /* If a static var's type was incomplete when the decl was written,
9479 but the type is complete now, lay out the decl now. */
9480 if (DECL_SIZE (exp
) == 0
9481 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9482 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9483 layout_decl (exp
, 0);
9485 /* ... fall through ... */
9489 decl_rtl
= DECL_RTL (exp
);
9491 gcc_assert (decl_rtl
);
9492 decl_rtl
= copy_rtx (decl_rtl
);
9493 /* Record writes to register variables. */
9494 if (modifier
== EXPAND_WRITE
9496 && HARD_REGISTER_P (decl_rtl
))
9497 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9498 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9500 /* Ensure variable marked as used even if it doesn't go through
9501 a parser. If it hasn't be used yet, write out an external
9503 TREE_USED (exp
) = 1;
9505 /* Show we haven't gotten RTL for this yet. */
9508 /* Variables inherited from containing functions should have
9509 been lowered by this point. */
9510 context
= decl_function_context (exp
);
9511 gcc_assert (SCOPE_FILE_SCOPE_P (context
)
9512 || context
== current_function_decl
9513 || TREE_STATIC (exp
)
9514 || DECL_EXTERNAL (exp
)
9515 /* ??? C++ creates functions that are not TREE_STATIC. */
9516 || TREE_CODE (exp
) == FUNCTION_DECL
);
9518 /* This is the case of an array whose size is to be determined
9519 from its initializer, while the initializer is still being parsed.
9520 ??? We aren't parsing while expanding anymore. */
9522 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9523 temp
= validize_mem (decl_rtl
);
9525 /* If DECL_RTL is memory, we are in the normal case and the
9526 address is not valid, get the address into a register. */
9528 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9531 *alt_rtl
= decl_rtl
;
9532 decl_rtl
= use_anchored_address (decl_rtl
);
9533 if (modifier
!= EXPAND_CONST_ADDRESS
9534 && modifier
!= EXPAND_SUM
9535 && !memory_address_addr_space_p (DECL_MODE (exp
),
9537 MEM_ADDR_SPACE (decl_rtl
)))
9538 temp
= replace_equiv_address (decl_rtl
,
9539 copy_rtx (XEXP (decl_rtl
, 0)));
9542 /* If we got something, return it. But first, set the alignment
9543 if the address is a register. */
9546 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9547 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9552 /* If the mode of DECL_RTL does not match that of the decl,
9553 there are two cases: we are dealing with a BLKmode value
9554 that is returned in a register, or we are dealing with
9555 a promoted value. In the latter case, return a SUBREG
9556 of the wanted mode, but mark it so that we know that it
9557 was already extended. */
9558 if (REG_P (decl_rtl
)
9559 && DECL_MODE (exp
) != BLKmode
9560 && GET_MODE (decl_rtl
) != DECL_MODE (exp
))
9564 /* Get the signedness to be used for this variable. Ensure we get
9565 the same mode we got when the variable was declared. */
9566 if (code
== SSA_NAME
9567 && (g
= SSA_NAME_DEF_STMT (ssa_name
))
9568 && gimple_code (g
) == GIMPLE_CALL
9569 && !gimple_call_internal_p (g
))
9570 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9571 gimple_call_fntype (g
),
9574 pmode
= promote_decl_mode (exp
, &unsignedp
);
9575 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9577 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9578 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9579 SUBREG_PROMOTED_SET (temp
, unsignedp
);
9586 /* Given that TYPE_PRECISION (type) is not always equal to
9587 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
9588 the former to the latter according to the signedness of the
9590 temp
= immed_wide_int_const (wide_int::from
9592 GET_MODE_PRECISION (TYPE_MODE (type
)),
9599 tree tmp
= NULL_TREE
;
9600 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9601 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9602 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9603 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9604 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9605 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9606 return const_vector_from_tree (exp
);
9607 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9609 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9611 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9615 vec
<constructor_elt
, va_gc
> *v
;
9617 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9618 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9619 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9620 tmp
= build_constructor (type
, v
);
9622 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9627 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9630 /* If optimized, generate immediate CONST_DOUBLE
9631 which will be turned into memory by reload if necessary.
9633 We used to force a register so that loop.c could see it. But
9634 this does not allow gen_* patterns to perform optimizations with
9635 the constants. It also produces two insns in cases like "x = 1.0;".
9636 On most machines, floating-point constants are not permitted in
9637 many insns, so we'd end up copying it to a register in any case.
9639 Now, we do the copying in expand_binop, if appropriate. */
9640 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9641 TYPE_MODE (TREE_TYPE (exp
)));
9644 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9645 TYPE_MODE (TREE_TYPE (exp
)));
9648 /* Handle evaluating a complex constant in a CONCAT target. */
9649 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9651 machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9654 rtarg
= XEXP (original_target
, 0);
9655 itarg
= XEXP (original_target
, 1);
9657 /* Move the real and imaginary parts separately. */
9658 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9659 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9662 emit_move_insn (rtarg
, op0
);
9664 emit_move_insn (itarg
, op1
);
9666 return original_target
;
9669 /* ... fall through ... */
9672 temp
= expand_expr_constant (exp
, 1, modifier
);
9674 /* temp contains a constant address.
9675 On RISC machines where a constant address isn't valid,
9676 make some insns to get that address into a register. */
9677 if (modifier
!= EXPAND_CONST_ADDRESS
9678 && modifier
!= EXPAND_INITIALIZER
9679 && modifier
!= EXPAND_SUM
9680 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9681 MEM_ADDR_SPACE (temp
)))
9682 return replace_equiv_address (temp
,
9683 copy_rtx (XEXP (temp
, 0)));
9689 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
,
9692 if (!SAVE_EXPR_RESOLVED_P (exp
))
9694 /* We can indeed still hit this case, typically via builtin
9695 expanders calling save_expr immediately before expanding
9696 something. Assume this means that we only have to deal
9697 with non-BLKmode values. */
9698 gcc_assert (GET_MODE (ret
) != BLKmode
);
9700 val
= build_decl (curr_insn_location (),
9701 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9702 DECL_ARTIFICIAL (val
) = 1;
9703 DECL_IGNORED_P (val
) = 1;
9705 TREE_OPERAND (exp
, 0) = treeop0
;
9706 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9708 if (!CONSTANT_P (ret
))
9709 ret
= copy_to_reg (ret
);
9710 SET_DECL_RTL (val
, ret
);
9718 /* If we don't need the result, just ensure we evaluate any
9722 unsigned HOST_WIDE_INT idx
;
9725 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9726 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9731 return expand_constructor (exp
, target
, modifier
, false);
9733 case TARGET_MEM_REF
:
9736 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9737 enum insn_code icode
;
9740 op0
= addr_for_mem_ref (exp
, as
, true);
9741 op0
= memory_address_addr_space (mode
, op0
, as
);
9742 temp
= gen_rtx_MEM (mode
, op0
);
9743 set_mem_attributes (temp
, exp
, 0);
9744 set_mem_addr_space (temp
, as
);
9745 align
= get_object_alignment (exp
);
9746 if (modifier
!= EXPAND_WRITE
9747 && modifier
!= EXPAND_MEMORY
9749 && align
< GET_MODE_ALIGNMENT (mode
)
9750 /* If the target does not have special handling for unaligned
9751 loads of mode then it can use regular moves for them. */
9752 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9753 != CODE_FOR_nothing
))
9755 struct expand_operand ops
[2];
9757 /* We've already validated the memory, and we're creating a
9758 new pseudo destination. The predicates really can't fail,
9759 nor can the generator. */
9760 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9761 create_fixed_operand (&ops
[1], temp
);
9762 expand_insn (icode
, 2, ops
);
9763 temp
= ops
[0].value
;
9771 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9772 machine_mode address_mode
;
9773 tree base
= TREE_OPERAND (exp
, 0);
9775 enum insn_code icode
;
9777 /* Handle expansion of non-aliased memory with non-BLKmode. That
9778 might end up in a register. */
9779 if (mem_ref_refers_to_non_mem_p (exp
))
9781 HOST_WIDE_INT offset
= mem_ref_offset (exp
).to_short_addr ();
9782 base
= TREE_OPERAND (base
, 0);
9784 && tree_fits_uhwi_p (TYPE_SIZE (type
))
9785 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9786 == tree_to_uhwi (TYPE_SIZE (type
))))
9787 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
9788 target
, tmode
, modifier
);
9789 if (TYPE_MODE (type
) == BLKmode
)
9791 temp
= assign_stack_temp (DECL_MODE (base
),
9792 GET_MODE_SIZE (DECL_MODE (base
)));
9793 store_expr (base
, temp
, 0, false);
9794 temp
= adjust_address (temp
, BLKmode
, offset
);
9795 set_mem_size (temp
, int_size_in_bytes (type
));
9798 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
9799 bitsize_int (offset
* BITS_PER_UNIT
));
9800 return expand_expr (exp
, target
, tmode
, modifier
);
9802 address_mode
= targetm
.addr_space
.address_mode (as
);
9803 base
= TREE_OPERAND (exp
, 0);
9804 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9806 tree mask
= gimple_assign_rhs2 (def_stmt
);
9807 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9808 gimple_assign_rhs1 (def_stmt
), mask
);
9809 TREE_OPERAND (exp
, 0) = base
;
9811 align
= get_object_alignment (exp
);
9812 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9813 op0
= memory_address_addr_space (mode
, op0
, as
);
9814 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9816 rtx off
= immed_wide_int_const (mem_ref_offset (exp
), address_mode
);
9817 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9818 op0
= memory_address_addr_space (mode
, op0
, as
);
9820 temp
= gen_rtx_MEM (mode
, op0
);
9821 set_mem_attributes (temp
, exp
, 0);
9822 set_mem_addr_space (temp
, as
);
9823 if (TREE_THIS_VOLATILE (exp
))
9824 MEM_VOLATILE_P (temp
) = 1;
9825 if (modifier
!= EXPAND_WRITE
9826 && modifier
!= EXPAND_MEMORY
9827 && !inner_reference_p
9829 && align
< GET_MODE_ALIGNMENT (mode
))
9831 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9832 != CODE_FOR_nothing
)
9834 struct expand_operand ops
[2];
9836 /* We've already validated the memory, and we're creating a
9837 new pseudo destination. The predicates really can't fail,
9838 nor can the generator. */
9839 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9840 create_fixed_operand (&ops
[1], temp
);
9841 expand_insn (icode
, 2, ops
);
9842 temp
= ops
[0].value
;
9844 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9845 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9846 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9847 (modifier
== EXPAND_STACK_PARM
9848 ? NULL_RTX
: target
),
9857 tree array
= treeop0
;
9858 tree index
= treeop1
;
9861 /* Fold an expression like: "foo"[2].
9862 This is not done in fold so it won't happen inside &.
9863 Don't fold if this is for wide characters since it's too
9864 difficult to do correctly and this is a very rare case. */
9866 if (modifier
!= EXPAND_CONST_ADDRESS
9867 && modifier
!= EXPAND_INITIALIZER
9868 && modifier
!= EXPAND_MEMORY
)
9870 tree t
= fold_read_from_constant_string (exp
);
9873 return expand_expr (t
, target
, tmode
, modifier
);
9876 /* If this is a constant index into a constant array,
9877 just get the value from the array. Handle both the cases when
9878 we have an explicit constructor and when our operand is a variable
9879 that was declared const. */
9881 if (modifier
!= EXPAND_CONST_ADDRESS
9882 && modifier
!= EXPAND_INITIALIZER
9883 && modifier
!= EXPAND_MEMORY
9884 && TREE_CODE (array
) == CONSTRUCTOR
9885 && ! TREE_SIDE_EFFECTS (array
)
9886 && TREE_CODE (index
) == INTEGER_CST
)
9888 unsigned HOST_WIDE_INT ix
;
9891 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9893 if (tree_int_cst_equal (field
, index
))
9895 if (!TREE_SIDE_EFFECTS (value
))
9896 return expand_expr (fold (value
), target
, tmode
, modifier
);
9901 else if (optimize
>= 1
9902 && modifier
!= EXPAND_CONST_ADDRESS
9903 && modifier
!= EXPAND_INITIALIZER
9904 && modifier
!= EXPAND_MEMORY
9905 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9906 && TREE_CODE (index
) == INTEGER_CST
9907 && (TREE_CODE (array
) == VAR_DECL
9908 || TREE_CODE (array
) == CONST_DECL
)
9909 && (init
= ctor_for_folding (array
)) != error_mark_node
)
9911 if (init
== NULL_TREE
)
9913 tree value
= build_zero_cst (type
);
9914 if (TREE_CODE (value
) == CONSTRUCTOR
)
9916 /* If VALUE is a CONSTRUCTOR, this optimization is only
9917 useful if this doesn't store the CONSTRUCTOR into
9918 memory. If it does, it is more efficient to just
9919 load the data from the array directly. */
9920 rtx ret
= expand_constructor (value
, target
,
9922 if (ret
== NULL_RTX
)
9927 return expand_expr (value
, target
, tmode
, modifier
);
9929 else if (TREE_CODE (init
) == CONSTRUCTOR
)
9931 unsigned HOST_WIDE_INT ix
;
9934 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9936 if (tree_int_cst_equal (field
, index
))
9938 if (TREE_SIDE_EFFECTS (value
))
9941 if (TREE_CODE (value
) == CONSTRUCTOR
)
9943 /* If VALUE is a CONSTRUCTOR, this
9944 optimization is only useful if
9945 this doesn't store the CONSTRUCTOR
9946 into memory. If it does, it is more
9947 efficient to just load the data from
9948 the array directly. */
9949 rtx ret
= expand_constructor (value
, target
,
9951 if (ret
== NULL_RTX
)
9956 expand_expr (fold (value
), target
, tmode
, modifier
);
9959 else if (TREE_CODE (init
) == STRING_CST
)
9961 tree low_bound
= array_ref_low_bound (exp
);
9962 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
9964 /* Optimize the special case of a zero lower bound.
9966 We convert the lower bound to sizetype to avoid problems
9967 with constant folding. E.g. suppose the lower bound is
9968 1 and its mode is QI. Without the conversion
9969 (ARRAY + (INDEX - (unsigned char)1))
9971 (ARRAY + (-(unsigned char)1) + INDEX)
9973 (ARRAY + 255 + INDEX). Oops! */
9974 if (!integer_zerop (low_bound
))
9975 index1
= size_diffop_loc (loc
, index1
,
9976 fold_convert_loc (loc
, sizetype
,
9979 if (compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
9981 tree type
= TREE_TYPE (TREE_TYPE (init
));
9982 machine_mode mode
= TYPE_MODE (type
);
9984 if (GET_MODE_CLASS (mode
) == MODE_INT
9985 && GET_MODE_SIZE (mode
) == 1)
9986 return gen_int_mode (TREE_STRING_POINTER (init
)
9987 [TREE_INT_CST_LOW (index1
)],
9993 goto normal_inner_ref
;
9996 /* If the operand is a CONSTRUCTOR, we can just extract the
9997 appropriate field if it is present. */
9998 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
10000 unsigned HOST_WIDE_INT idx
;
10003 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
10005 if (field
== treeop1
10006 /* We can normally use the value of the field in the
10007 CONSTRUCTOR. However, if this is a bitfield in
10008 an integral mode that we can fit in a HOST_WIDE_INT,
10009 we must mask only the number of bits in the bitfield,
10010 since this is done implicitly by the constructor. If
10011 the bitfield does not meet either of those conditions,
10012 we can't do this optimization. */
10013 && (! DECL_BIT_FIELD (field
)
10014 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
10015 && (GET_MODE_PRECISION (DECL_MODE (field
))
10016 <= HOST_BITS_PER_WIDE_INT
))))
10018 if (DECL_BIT_FIELD (field
)
10019 && modifier
== EXPAND_STACK_PARM
)
10021 op0
= expand_expr (value
, target
, tmode
, modifier
);
10022 if (DECL_BIT_FIELD (field
))
10024 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
10025 machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
10027 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
10029 op1
= gen_int_mode (((HOST_WIDE_INT
) 1 << bitsize
) - 1,
10031 op0
= expand_and (imode
, op0
, op1
, target
);
10035 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
10037 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
10039 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
10047 goto normal_inner_ref
;
10049 case BIT_FIELD_REF
:
10050 case ARRAY_RANGE_REF
:
10053 machine_mode mode1
, mode2
;
10054 HOST_WIDE_INT bitsize
, bitpos
;
10056 int volatilep
= 0, must_force_mem
;
10057 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
10058 &mode1
, &unsignedp
, &volatilep
, true);
10059 rtx orig_op0
, memloc
;
10060 bool mem_attrs_from_type
= false;
10062 /* If we got back the original object, something is wrong. Perhaps
10063 we are evaluating an expression too early. In any event, don't
10064 infinitely recurse. */
10065 gcc_assert (tem
!= exp
);
10067 /* If TEM's type is a union of variable size, pass TARGET to the inner
10068 computation, since it will need a temporary and TARGET is known
10069 to have to do. This occurs in unchecked conversion in Ada. */
10071 = expand_expr_real (tem
,
10072 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10073 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
10074 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10076 && modifier
!= EXPAND_STACK_PARM
10077 ? target
: NULL_RTX
),
10079 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10082 /* If the field has a mode, we want to access it in the
10083 field's mode, not the computed mode.
10084 If a MEM has VOIDmode (external with incomplete type),
10085 use BLKmode for it instead. */
10088 if (mode1
!= VOIDmode
)
10089 op0
= adjust_address (op0
, mode1
, 0);
10090 else if (GET_MODE (op0
) == VOIDmode
)
10091 op0
= adjust_address (op0
, BLKmode
, 0);
10095 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
10097 /* If we have either an offset, a BLKmode result, or a reference
10098 outside the underlying object, we must force it to memory.
10099 Such a case can occur in Ada if we have unchecked conversion
10100 of an expression from a scalar type to an aggregate type or
10101 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
10102 passed a partially uninitialized object or a view-conversion
10103 to a larger size. */
10104 must_force_mem
= (offset
10105 || mode1
== BLKmode
10106 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
10108 /* Handle CONCAT first. */
10109 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
10112 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
10115 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10118 op0
= XEXP (op0
, 0);
10119 mode2
= GET_MODE (op0
);
10121 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10122 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
10126 op0
= XEXP (op0
, 1);
10128 mode2
= GET_MODE (op0
);
10131 /* Otherwise force into memory. */
10132 must_force_mem
= 1;
10135 /* If this is a constant, put it in a register if it is a legitimate
10136 constant and we don't need a memory reference. */
10137 if (CONSTANT_P (op0
)
10138 && mode2
!= BLKmode
10139 && targetm
.legitimate_constant_p (mode2
, op0
)
10140 && !must_force_mem
)
10141 op0
= force_reg (mode2
, op0
);
10143 /* Otherwise, if this is a constant, try to force it to the constant
10144 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10145 is a legitimate constant. */
10146 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10147 op0
= validize_mem (memloc
);
10149 /* Otherwise, if this is a constant or the object is not in memory
10150 and need be, put it there. */
10151 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10153 memloc
= assign_temp (TREE_TYPE (tem
), 1, 1);
10154 emit_move_insn (memloc
, op0
);
10156 mem_attrs_from_type
= true;
10161 machine_mode address_mode
;
10162 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10165 gcc_assert (MEM_P (op0
));
10167 address_mode
= get_address_mode (op0
);
10168 if (GET_MODE (offset_rtx
) != address_mode
)
10169 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10171 /* See the comment in expand_assignment for the rationale. */
10172 if (mode1
!= VOIDmode
10175 && (bitpos
% bitsize
) == 0
10176 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10177 && MEM_ALIGN (op0
) >= GET_MODE_ALIGNMENT (mode1
))
10179 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10183 op0
= offset_address (op0
, offset_rtx
,
10184 highest_pow2_factor (offset
));
10187 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10188 record its alignment as BIGGEST_ALIGNMENT. */
10189 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10190 && is_aligning_offset (offset
, tem
))
10191 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10193 /* Don't forget about volatility even if this is a bitfield. */
10194 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10196 if (op0
== orig_op0
)
10197 op0
= copy_rtx (op0
);
10199 MEM_VOLATILE_P (op0
) = 1;
10202 /* In cases where an aligned union has an unaligned object
10203 as a field, we might be extracting a BLKmode value from
10204 an integer-mode (e.g., SImode) object. Handle this case
10205 by doing the extract into an object as wide as the field
10206 (which we know to be the width of a basic mode), then
10207 storing into memory, and changing the mode to BLKmode. */
10208 if (mode1
== VOIDmode
10209 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10210 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10211 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10212 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10213 && modifier
!= EXPAND_CONST_ADDRESS
10214 && modifier
!= EXPAND_INITIALIZER
10215 && modifier
!= EXPAND_MEMORY
)
10216 /* If the bitfield is volatile and the bitsize
10217 is narrower than the access size of the bitfield,
10218 we need to extract bitfields from the access. */
10219 || (volatilep
&& TREE_CODE (exp
) == COMPONENT_REF
10220 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp
, 1))
10221 && mode1
!= BLKmode
10222 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)
10223 /* If the field isn't aligned enough to fetch as a memref,
10224 fetch it as a bit field. */
10225 || (mode1
!= BLKmode
10226 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10227 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10229 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10230 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10231 && modifier
!= EXPAND_MEMORY
10232 && ((modifier
== EXPAND_CONST_ADDRESS
10233 || modifier
== EXPAND_INITIALIZER
)
10235 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10236 || (bitpos
% BITS_PER_UNIT
!= 0)))
10237 /* If the type and the field are a constant size and the
10238 size of the type isn't the same size as the bitfield,
10239 we must use bitfield operations. */
10241 && TYPE_SIZE (TREE_TYPE (exp
))
10242 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10243 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10246 machine_mode ext_mode
= mode
;
10248 if (ext_mode
== BLKmode
10249 && ! (target
!= 0 && MEM_P (op0
)
10251 && bitpos
% BITS_PER_UNIT
== 0))
10252 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10254 if (ext_mode
== BLKmode
)
10257 target
= assign_temp (type
, 1, 1);
10259 /* ??? Unlike the similar test a few lines below, this one is
10260 very likely obsolete. */
10264 /* In this case, BITPOS must start at a byte boundary and
10265 TARGET, if specified, must be a MEM. */
10266 gcc_assert (MEM_P (op0
)
10267 && (!target
|| MEM_P (target
))
10268 && !(bitpos
% BITS_PER_UNIT
));
10270 emit_block_move (target
,
10271 adjust_address (op0
, VOIDmode
,
10272 bitpos
/ BITS_PER_UNIT
),
10273 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10275 (modifier
== EXPAND_STACK_PARM
10276 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10281 /* If we have nothing to extract, the result will be 0 for targets
10282 with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
10283 return 0 for the sake of consistency, as reading a zero-sized
10284 bitfield is valid in Ada and the value is fully specified. */
10288 op0
= validize_mem (op0
);
10290 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10291 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10293 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10294 (modifier
== EXPAND_STACK_PARM
10295 ? NULL_RTX
: target
),
10296 ext_mode
, ext_mode
);
10298 /* If the result is a record type and BITSIZE is narrower than
10299 the mode of OP0, an integral mode, and this is a big endian
10300 machine, we must put the field into the high-order bits. */
10301 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10302 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10303 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10304 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10305 GET_MODE_BITSIZE (GET_MODE (op0
))
10306 - bitsize
, op0
, 1);
10308 /* If the result type is BLKmode, store the data into a temporary
10309 of the appropriate type, but with the mode corresponding to the
10310 mode for the data we have (op0's mode). */
10311 if (mode
== BLKmode
)
10314 = assign_stack_temp_for_type (ext_mode
,
10315 GET_MODE_BITSIZE (ext_mode
),
10317 emit_move_insn (new_rtx
, op0
);
10318 op0
= copy_rtx (new_rtx
);
10319 PUT_MODE (op0
, BLKmode
);
10325 /* If the result is BLKmode, use that to access the object
10327 if (mode
== BLKmode
)
10330 /* Get a reference to just this component. */
10331 if (modifier
== EXPAND_CONST_ADDRESS
10332 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10333 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10335 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10337 if (op0
== orig_op0
)
10338 op0
= copy_rtx (op0
);
10340 /* If op0 is a temporary because of forcing to memory, pass only the
10341 type to set_mem_attributes so that the original expression is never
10342 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10343 if (mem_attrs_from_type
)
10344 set_mem_attributes (op0
, type
, 0);
10346 set_mem_attributes (op0
, exp
, 0);
10348 if (REG_P (XEXP (op0
, 0)))
10349 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10351 MEM_VOLATILE_P (op0
) |= volatilep
;
10352 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10353 || modifier
== EXPAND_CONST_ADDRESS
10354 || modifier
== EXPAND_INITIALIZER
)
10358 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10360 convert_move (target
, op0
, unsignedp
);
10365 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10368 /* All valid uses of __builtin_va_arg_pack () are removed during
10370 if (CALL_EXPR_VA_ARG_PACK (exp
))
10371 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10373 tree fndecl
= get_callee_fndecl (exp
), attr
;
10376 && (attr
= lookup_attribute ("error",
10377 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10378 error ("%Kcall to %qs declared with attribute error: %s",
10379 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10380 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10382 && (attr
= lookup_attribute ("warning",
10383 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10384 warning_at (tree_nonartificial_location (exp
),
10385 0, "%Kcall to %qs declared with attribute warning: %s",
10386 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10387 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10389 /* Check for a built-in function. */
10390 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10392 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10393 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10396 return expand_call (exp
, target
, ignore
);
10398 case VIEW_CONVERT_EXPR
:
10401 /* If we are converting to BLKmode, try to avoid an intermediate
10402 temporary by fetching an inner memory reference. */
10403 if (mode
== BLKmode
10404 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10405 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10406 && handled_component_p (treeop0
))
10408 machine_mode mode1
;
10409 HOST_WIDE_INT bitsize
, bitpos
;
10414 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10415 &offset
, &mode1
, &unsignedp
, &volatilep
,
10419 /* ??? We should work harder and deal with non-zero offsets. */
10421 && (bitpos
% BITS_PER_UNIT
) == 0
10423 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10425 /* See the normal_inner_ref case for the rationale. */
10427 = expand_expr_real (tem
,
10428 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10429 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10431 && modifier
!= EXPAND_STACK_PARM
10432 ? target
: NULL_RTX
),
10434 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10437 if (MEM_P (orig_op0
))
10441 /* Get a reference to just this component. */
10442 if (modifier
== EXPAND_CONST_ADDRESS
10443 || modifier
== EXPAND_SUM
10444 || modifier
== EXPAND_INITIALIZER
)
10445 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10447 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10449 if (op0
== orig_op0
)
10450 op0
= copy_rtx (op0
);
10452 set_mem_attributes (op0
, treeop0
, 0);
10453 if (REG_P (XEXP (op0
, 0)))
10454 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10456 MEM_VOLATILE_P (op0
) |= volatilep
;
10462 op0
= expand_expr_real (treeop0
, NULL_RTX
, VOIDmode
, modifier
,
10463 NULL
, inner_reference_p
);
10465 /* If the input and output modes are both the same, we are done. */
10466 if (mode
== GET_MODE (op0
))
10468 /* If neither mode is BLKmode, and both modes are the same size
10469 then we can use gen_lowpart. */
10470 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10471 && (GET_MODE_PRECISION (mode
)
10472 == GET_MODE_PRECISION (GET_MODE (op0
)))
10473 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10475 if (GET_CODE (op0
) == SUBREG
)
10476 op0
= force_reg (GET_MODE (op0
), op0
);
10477 temp
= gen_lowpart_common (mode
, op0
);
10482 if (!REG_P (op0
) && !MEM_P (op0
))
10483 op0
= force_reg (GET_MODE (op0
), op0
);
10484 op0
= gen_lowpart (mode
, op0
);
10487 /* If both types are integral, convert from one mode to the other. */
10488 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10489 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10490 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10491 /* If the output type is a bit-field type, do an extraction. */
10492 else if (reduce_bit_field
)
10493 return extract_bit_field (op0
, TYPE_PRECISION (type
), 0,
10494 TYPE_UNSIGNED (type
), NULL_RTX
,
10496 /* As a last resort, spill op0 to memory, and reload it in a
10498 else if (!MEM_P (op0
))
10500 /* If the operand is not a MEM, force it into memory. Since we
10501 are going to be changing the mode of the MEM, don't call
10502 force_const_mem for constants because we don't allow pool
10503 constants to change mode. */
10504 tree inner_type
= TREE_TYPE (treeop0
);
10506 gcc_assert (!TREE_ADDRESSABLE (exp
));
10508 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10510 = assign_stack_temp_for_type
10511 (TYPE_MODE (inner_type
),
10512 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10514 emit_move_insn (target
, op0
);
10518 /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
10519 output type is such that the operand is known to be aligned, indicate
10520 that it is. Otherwise, we need only be concerned about alignment for
10521 non-BLKmode results. */
10524 enum insn_code icode
;
10526 if (TYPE_ALIGN_OK (type
))
10528 /* ??? Copying the MEM without substantially changing it might
10529 run afoul of the code handling volatile memory references in
10530 store_expr, which assumes that TARGET is returned unmodified
10531 if it has been used. */
10532 op0
= copy_rtx (op0
);
10533 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10535 else if (modifier
!= EXPAND_WRITE
10536 && modifier
!= EXPAND_MEMORY
10537 && !inner_reference_p
10539 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10541 /* If the target does have special handling for unaligned
10542 loads of mode then use them. */
10543 if ((icode
= optab_handler (movmisalign_optab
, mode
))
10544 != CODE_FOR_nothing
)
10548 op0
= adjust_address (op0
, mode
, 0);
10549 /* We've already validated the memory, and we're creating a
10550 new pseudo destination. The predicates really can't
10552 reg
= gen_reg_rtx (mode
);
10554 /* Nor can the insn generator. */
10555 insn
= GEN_FCN (icode
) (reg
, op0
);
10559 else if (STRICT_ALIGNMENT
)
10561 tree inner_type
= TREE_TYPE (treeop0
);
10562 HOST_WIDE_INT temp_size
10563 = MAX (int_size_in_bytes (inner_type
),
10564 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10566 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10567 rtx new_with_op0_mode
10568 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10570 gcc_assert (!TREE_ADDRESSABLE (exp
));
10572 if (GET_MODE (op0
) == BLKmode
)
10573 emit_block_move (new_with_op0_mode
, op0
,
10574 GEN_INT (GET_MODE_SIZE (mode
)),
10575 (modifier
== EXPAND_STACK_PARM
10576 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10578 emit_move_insn (new_with_op0_mode
, op0
);
10584 op0
= adjust_address (op0
, mode
, 0);
10591 tree lhs
= treeop0
;
10592 tree rhs
= treeop1
;
10593 gcc_assert (ignore
);
10595 /* Check for |= or &= of a bitfield of size one into another bitfield
10596 of size 1. In this case, (unless we need the result of the
10597 assignment) we can do this more efficiently with a
10598 test followed by an assignment, if necessary.
10600 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10601 things change so we do, this code should be enhanced to
10603 if (TREE_CODE (lhs
) == COMPONENT_REF
10604 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10605 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10606 && TREE_OPERAND (rhs
, 0) == lhs
10607 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10608 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10609 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10611 rtx_code_label
*label
= gen_label_rtx ();
10612 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10613 do_jump (TREE_OPERAND (rhs
, 1),
10615 value
? 0 : label
, -1);
10616 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10618 do_pending_stack_adjust ();
10619 emit_label (label
);
10623 expand_assignment (lhs
, rhs
, false);
10628 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10630 case REALPART_EXPR
:
10631 op0
= expand_normal (treeop0
);
10632 return read_complex_part (op0
, false);
10634 case IMAGPART_EXPR
:
10635 op0
= expand_normal (treeop0
);
10636 return read_complex_part (op0
, true);
10643 /* Expanded in cfgexpand.c. */
10644 gcc_unreachable ();
10646 case TRY_CATCH_EXPR
:
10648 case EH_FILTER_EXPR
:
10649 case TRY_FINALLY_EXPR
:
10650 /* Lowered by tree-eh.c. */
10651 gcc_unreachable ();
10653 case WITH_CLEANUP_EXPR
:
10654 case CLEANUP_POINT_EXPR
:
10656 case CASE_LABEL_EXPR
:
10661 case COMPOUND_EXPR
:
10662 case PREINCREMENT_EXPR
:
10663 case PREDECREMENT_EXPR
:
10664 case POSTINCREMENT_EXPR
:
10665 case POSTDECREMENT_EXPR
:
10668 case COMPOUND_LITERAL_EXPR
:
10669 /* Lowered by gimplify.c. */
10670 gcc_unreachable ();
10673 /* Function descriptors are not valid except for as
10674 initialization constants, and should not be expanded. */
10675 gcc_unreachable ();
10677 case WITH_SIZE_EXPR
:
10678 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10679 have pulled out the size to use in whatever context it needed. */
10680 return expand_expr_real (treeop0
, original_target
, tmode
,
10681 modifier
, alt_rtl
, inner_reference_p
);
10684 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10688 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10689 signedness of TYPE), possibly returning the result in TARGET. */
10691 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10693 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10694 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10696 /* For constant values, reduce using build_int_cst_type. */
10697 if (CONST_INT_P (exp
))
10699 HOST_WIDE_INT value
= INTVAL (exp
);
10700 tree t
= build_int_cst_type (type
, value
);
10701 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10703 else if (TYPE_UNSIGNED (type
))
10705 machine_mode mode
= GET_MODE (exp
);
10706 rtx mask
= immed_wide_int_const
10707 (wi::mask (prec
, false, GET_MODE_PRECISION (mode
)), mode
);
10708 return expand_and (mode
, exp
, mask
, target
);
10712 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10713 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10714 exp
, count
, target
, 0);
10715 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10716 exp
, count
, target
, 0);
10720 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10721 when applied to the address of EXP produces an address known to be
10722 aligned more than BIGGEST_ALIGNMENT. */
10725 is_aligning_offset (const_tree offset
, const_tree exp
)
10727 /* Strip off any conversions. */
10728 while (CONVERT_EXPR_P (offset
))
10729 offset
= TREE_OPERAND (offset
, 0);
10731 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10732 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10733 if (TREE_CODE (offset
) != BIT_AND_EXPR
10734 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
10735 || compare_tree_int (TREE_OPERAND (offset
, 1),
10736 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10737 || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1) < 0)
10740 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10741 It must be NEGATE_EXPR. Then strip any more conversions. */
10742 offset
= TREE_OPERAND (offset
, 0);
10743 while (CONVERT_EXPR_P (offset
))
10744 offset
= TREE_OPERAND (offset
, 0);
10746 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10749 offset
= TREE_OPERAND (offset
, 0);
10750 while (CONVERT_EXPR_P (offset
))
10751 offset
= TREE_OPERAND (offset
, 0);
10753 /* This must now be the address of EXP. */
10754 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10757 /* Return the tree node if an ARG corresponds to a string constant or zero
10758 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10759 in bytes within the string that ARG is accessing. The type of the
10760 offset will be `sizetype'. */
10763 string_constant (tree arg
, tree
*ptr_offset
)
10765 tree array
, offset
, lower_bound
;
10768 if (TREE_CODE (arg
) == ADDR_EXPR
)
10770 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10772 *ptr_offset
= size_zero_node
;
10773 return TREE_OPERAND (arg
, 0);
10775 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10777 array
= TREE_OPERAND (arg
, 0);
10778 offset
= size_zero_node
;
10780 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10782 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10783 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10784 if (TREE_CODE (array
) != STRING_CST
10785 && TREE_CODE (array
) != VAR_DECL
)
10788 /* Check if the array has a nonzero lower bound. */
10789 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10790 if (!integer_zerop (lower_bound
))
10792 /* If the offset and base aren't both constants, return 0. */
10793 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10795 if (TREE_CODE (offset
) != INTEGER_CST
)
10797 /* Adjust offset by the lower bound. */
10798 offset
= size_diffop (fold_convert (sizetype
, offset
),
10799 fold_convert (sizetype
, lower_bound
));
10802 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10804 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10805 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10806 if (TREE_CODE (array
) != ADDR_EXPR
)
10808 array
= TREE_OPERAND (array
, 0);
10809 if (TREE_CODE (array
) != STRING_CST
10810 && TREE_CODE (array
) != VAR_DECL
)
10816 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10818 tree arg0
= TREE_OPERAND (arg
, 0);
10819 tree arg1
= TREE_OPERAND (arg
, 1);
10824 if (TREE_CODE (arg0
) == ADDR_EXPR
10825 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10826 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10828 array
= TREE_OPERAND (arg0
, 0);
10831 else if (TREE_CODE (arg1
) == ADDR_EXPR
10832 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10833 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10835 array
= TREE_OPERAND (arg1
, 0);
10844 if (TREE_CODE (array
) == STRING_CST
)
10846 *ptr_offset
= fold_convert (sizetype
, offset
);
10849 else if (TREE_CODE (array
) == VAR_DECL
10850 || TREE_CODE (array
) == CONST_DECL
)
10853 tree init
= ctor_for_folding (array
);
10855 /* Variables initialized to string literals can be handled too. */
10856 if (init
== error_mark_node
10858 || TREE_CODE (init
) != STRING_CST
)
10861 /* Avoid const char foo[4] = "abcde"; */
10862 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10863 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10864 || (length
= TREE_STRING_LENGTH (init
)) <= 0
10865 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10868 /* If variable is bigger than the string literal, OFFSET must be constant
10869 and inside of the bounds of the string literal. */
10870 offset
= fold_convert (sizetype
, offset
);
10871 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10872 && (! tree_fits_uhwi_p (offset
)
10873 || compare_tree_int (offset
, length
) >= 0))
10876 *ptr_offset
= offset
;
10883 /* Generate code to calculate OPS, and exploded expression
10884 using a store-flag instruction and return an rtx for the result.
10885 OPS reflects a comparison.
10887 If TARGET is nonzero, store the result there if convenient.
10889 Return zero if there is no suitable set-flag instruction
10890 available on this machine.
10892 Once expand_expr has been called on the arguments of the comparison,
10893 we are committed to doing the store flag, since it is not safe to
10894 re-evaluate the expression. We emit the store-flag insn by calling
10895 emit_store_flag, but only expand the arguments if we have a reason
10896 to believe that emit_store_flag will be successful. If we think that
10897 it will, but it isn't, we have to simulate the store-flag with a
10898 set/jump/set sequence. */
10901 do_store_flag (sepops ops
, rtx target
, machine_mode mode
)
10903 enum rtx_code code
;
10904 tree arg0
, arg1
, type
;
10906 machine_mode operand_mode
;
10909 rtx subtarget
= target
;
10910 location_t loc
= ops
->location
;
10915 /* Don't crash if the comparison was erroneous. */
10916 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10919 type
= TREE_TYPE (arg0
);
10920 operand_mode
= TYPE_MODE (type
);
10921 unsignedp
= TYPE_UNSIGNED (type
);
10923 /* We won't bother with BLKmode store-flag operations because it would mean
10924 passing a lot of information to emit_store_flag. */
10925 if (operand_mode
== BLKmode
)
10928 /* We won't bother with store-flag operations involving function pointers
10929 when function pointers must be canonicalized before comparisons. */
10930 #ifdef HAVE_canonicalize_funcptr_for_compare
10931 if (HAVE_canonicalize_funcptr_for_compare
10932 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10933 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10935 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10936 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10937 == FUNCTION_TYPE
))))
10944 /* For vector typed comparisons emit code to generate the desired
10945 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10946 expander for this. */
10947 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10949 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10950 tree if_true
= constant_boolean_node (true, ops
->type
);
10951 tree if_false
= constant_boolean_node (false, ops
->type
);
10952 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10955 /* Get the rtx comparison code to use. We know that EXP is a comparison
10956 operation of some type. Some comparisons against 1 and -1 can be
10957 converted to comparisons with zero. Do so here so that the tests
10958 below will be aware that we have a comparison with zero. These
10959 tests will not catch constants in the first operand, but constants
10960 are rarely passed as the first operand. */
10971 if (integer_onep (arg1
))
10972 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
10974 code
= unsignedp
? LTU
: LT
;
10977 if (! unsignedp
&& integer_all_onesp (arg1
))
10978 arg1
= integer_zero_node
, code
= LT
;
10980 code
= unsignedp
? LEU
: LE
;
10983 if (! unsignedp
&& integer_all_onesp (arg1
))
10984 arg1
= integer_zero_node
, code
= GE
;
10986 code
= unsignedp
? GTU
: GT
;
10989 if (integer_onep (arg1
))
10990 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
10992 code
= unsignedp
? GEU
: GE
;
10995 case UNORDERED_EXPR
:
11021 gcc_unreachable ();
11024 /* Put a constant second. */
11025 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
11026 || TREE_CODE (arg0
) == FIXED_CST
)
11028 tem
= arg0
; arg0
= arg1
; arg1
= tem
;
11029 code
= swap_condition (code
);
11032 /* If this is an equality or inequality test of a single bit, we can
11033 do this by shifting the bit being tested to the low-order bit and
11034 masking the result with the constant 1. If the condition was EQ,
11035 we xor it with 1. This does not require an scc insn and is faster
11036 than an scc insn even if we have it.
11038 The code to make this transformation was moved into fold_single_bit_test,
11039 so we just call into the folder and expand its result. */
11041 if ((code
== NE
|| code
== EQ
)
11042 && integer_zerop (arg1
)
11043 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
11045 gimple srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
11047 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
11049 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
11050 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11051 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
11052 gimple_assign_rhs1 (srcstmt
),
11053 gimple_assign_rhs2 (srcstmt
));
11054 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
11056 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
11060 if (! get_subtarget (target
)
11061 || GET_MODE (subtarget
) != operand_mode
)
11064 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
11067 target
= gen_reg_rtx (mode
);
11069 /* Try a cstore if possible. */
11070 return emit_store_flag_force (target
, code
, op0
, op1
,
11071 operand_mode
, unsignedp
,
11072 (TYPE_PRECISION (ops
->type
) == 1
11073 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
11077 /* Stubs in case we haven't got a casesi insn. */
11078 #ifndef HAVE_casesi
11079 # define HAVE_casesi 0
11080 # define gen_casesi(a, b, c, d, e) (0)
11081 # define CODE_FOR_casesi CODE_FOR_nothing
11084 /* Attempt to generate a casesi instruction. Returns 1 if successful,
11085 0 otherwise (i.e. if there is no casesi instruction).
11087 DEFAULT_PROBABILITY is the probability of jumping to the default
11090 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
11091 rtx table_label
, rtx default_label
, rtx fallback_label
,
11092 int default_probability
)
11094 struct expand_operand ops
[5];
11095 machine_mode index_mode
= SImode
;
11096 rtx op1
, op2
, index
;
11101 /* Convert the index to SImode. */
11102 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
11104 machine_mode omode
= TYPE_MODE (index_type
);
11105 rtx rangertx
= expand_normal (range
);
11107 /* We must handle the endpoints in the original mode. */
11108 index_expr
= build2 (MINUS_EXPR
, index_type
,
11109 index_expr
, minval
);
11110 minval
= integer_zero_node
;
11111 index
= expand_normal (index_expr
);
11113 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
11114 omode
, 1, default_label
,
11115 default_probability
);
11116 /* Now we can safely truncate. */
11117 index
= convert_to_mode (index_mode
, index
, 0);
11121 if (TYPE_MODE (index_type
) != index_mode
)
11123 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
11124 index_expr
= fold_convert (index_type
, index_expr
);
11127 index
= expand_normal (index_expr
);
11130 do_pending_stack_adjust ();
11132 op1
= expand_normal (minval
);
11133 op2
= expand_normal (range
);
11135 create_input_operand (&ops
[0], index
, index_mode
);
11136 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
11137 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
11138 create_fixed_operand (&ops
[3], table_label
);
11139 create_fixed_operand (&ops
[4], (default_label
11141 : fallback_label
));
11142 expand_jump_insn (CODE_FOR_casesi
, 5, ops
);
11146 /* Attempt to generate a tablejump instruction; same concept. */
11147 #ifndef HAVE_tablejump
11148 #define HAVE_tablejump 0
11149 #define gen_tablejump(x, y) (0)
11152 /* Subroutine of the next function.
11154 INDEX is the value being switched on, with the lowest value
11155 in the table already subtracted.
11156 MODE is its expected mode (needed if INDEX is constant).
11157 RANGE is the length of the jump table.
11158 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11160 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11161 index value is out of range.
11162 DEFAULT_PROBABILITY is the probability of jumping to
11163 the default label. */
11166 do_tablejump (rtx index
, machine_mode mode
, rtx range
, rtx table_label
,
11167 rtx default_label
, int default_probability
)
11171 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11172 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11174 /* Do an unsigned comparison (in the proper mode) between the index
11175 expression and the value which represents the length of the range.
11176 Since we just finished subtracting the lower bound of the range
11177 from the index expression, this comparison allows us to simultaneously
11178 check that the original index expression value is both greater than
11179 or equal to the minimum value of the range and less than or equal to
11180 the maximum value of the range. */
11183 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11184 default_label
, default_probability
);
11187 /* If index is in range, it must fit in Pmode.
11188 Convert to Pmode so we can index with it. */
11190 index
= convert_to_mode (Pmode
, index
, 1);
11192 /* Don't let a MEM slip through, because then INDEX that comes
11193 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11194 and break_out_memory_refs will go to work on it and mess it up. */
11195 #ifdef PIC_CASE_VECTOR_ADDRESS
11196 if (flag_pic
&& !REG_P (index
))
11197 index
= copy_to_mode_reg (Pmode
, index
);
11200 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11201 GET_MODE_SIZE, because this indicates how large insns are. The other
11202 uses should all be Pmode, because they are addresses. This code
11203 could fail if addresses and insns are not the same size. */
11204 index
= simplify_gen_binary (MULT
, Pmode
, index
,
11205 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
),
11207 index
= simplify_gen_binary (PLUS
, Pmode
, index
,
11208 gen_rtx_LABEL_REF (Pmode
, table_label
));
11210 #ifdef PIC_CASE_VECTOR_ADDRESS
11212 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11215 index
= memory_address (CASE_VECTOR_MODE
, index
);
11216 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11217 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11218 convert_move (temp
, vector
, 0);
11220 emit_jump_insn (gen_tablejump (temp
, table_label
));
11222 /* If we are generating PIC code or if the table is PC-relative, the
11223 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11224 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11229 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11230 rtx table_label
, rtx default_label
, int default_probability
)
11234 if (! HAVE_tablejump
)
11237 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11238 fold_convert (index_type
, index_expr
),
11239 fold_convert (index_type
, minval
));
11240 index
= expand_normal (index_expr
);
11241 do_pending_stack_adjust ();
11243 do_tablejump (index
, TYPE_MODE (index_type
),
11244 convert_modes (TYPE_MODE (index_type
),
11245 TYPE_MODE (TREE_TYPE (range
)),
11246 expand_normal (range
),
11247 TYPE_UNSIGNED (TREE_TYPE (range
))),
11248 table_label
, default_label
, default_probability
);
11252 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11254 const_vector_from_tree (tree exp
)
11260 machine_mode inner
, mode
;
11262 mode
= TYPE_MODE (TREE_TYPE (exp
));
11264 if (initializer_zerop (exp
))
11265 return CONST0_RTX (mode
);
11267 units
= GET_MODE_NUNITS (mode
);
11268 inner
= GET_MODE_INNER (mode
);
11270 v
= rtvec_alloc (units
);
11272 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11274 elt
= VECTOR_CST_ELT (exp
, i
);
11276 if (TREE_CODE (elt
) == REAL_CST
)
11277 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11279 else if (TREE_CODE (elt
) == FIXED_CST
)
11280 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11283 RTVEC_ELT (v
, i
) = immed_wide_int_const (elt
, inner
);
11286 return gen_rtx_CONST_VECTOR (mode
, v
);
11289 /* Build a decl for a personality function given a language prefix. */
11292 build_personality_function (const char *lang
)
11294 const char *unwind_and_version
;
11298 switch (targetm_common
.except_unwind_info (&global_options
))
11303 unwind_and_version
= "_sj0";
11307 unwind_and_version
= "_v0";
11310 unwind_and_version
= "_seh0";
11313 gcc_unreachable ();
11316 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11318 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11319 long_long_unsigned_type_node
,
11320 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11321 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11322 get_identifier (name
), type
);
11323 DECL_ARTIFICIAL (decl
) = 1;
11324 DECL_EXTERNAL (decl
) = 1;
11325 TREE_PUBLIC (decl
) = 1;
11327 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11328 are the flags assigned by targetm.encode_section_info. */
11329 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11334 /* Extracts the personality function of DECL and returns the corresponding
11338 get_personality_function (tree decl
)
11340 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11341 enum eh_personality_kind pk
;
11343 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11344 if (pk
== eh_personality_none
)
11348 && pk
== eh_personality_any
)
11349 personality
= lang_hooks
.eh_personality ();
11351 if (pk
== eh_personality_lang
)
11352 gcc_assert (personality
!= NULL_TREE
);
11354 return XEXP (DECL_RTL (personality
), 0);
11357 #include "gt-expr.h"