1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "coretypes.h"
32 #include "hard-reg-set.h"
35 #include "insn-config.h"
36 #include "insn-attr.h"
37 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
44 #include "typeclass.h"
47 #include "langhooks.h"
50 #include "tree-iterator.h"
51 #include "tree-pass.h"
52 #include "tree-flow.h"
56 /* Decide whether a function's arguments should be processed
57 from first to last or from last to first.
59 They should if the stack and args grow in opposite directions, but
60 only if we have push insns. */
64 #ifndef PUSH_ARGS_REVERSED
65 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
66 #define PUSH_ARGS_REVERSED /* If it's last to first. */
72 #ifndef STACK_PUSH_CODE
73 #ifdef STACK_GROWS_DOWNWARD
74 #define STACK_PUSH_CODE PRE_DEC
76 #define STACK_PUSH_CODE PRE_INC
81 /* If this is nonzero, we do not bother generating VOLATILE
82 around volatile memory references, and we are willing to
83 output indirect addresses. If cse is to follow, we reject
84 indirect addresses so a useful potential cse is generated;
85 if it is used only once, instruction combination will produce
86 the same indirect address eventually. */
89 /* This structure is used by move_by_pieces to describe the move to
100 int explicit_inc_from
;
101 unsigned HOST_WIDE_INT len
;
102 HOST_WIDE_INT offset
;
106 /* This structure is used by store_by_pieces to describe the clear to
109 struct store_by_pieces
115 unsigned HOST_WIDE_INT len
;
116 HOST_WIDE_INT offset
;
117 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
);
122 static unsigned HOST_WIDE_INT
move_by_pieces_ninsns (unsigned HOST_WIDE_INT
,
125 static void move_by_pieces_1 (rtx (*) (rtx
, ...), enum machine_mode
,
126 struct move_by_pieces
*);
127 static bool block_move_libcall_safe_for_call_parm (void);
128 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned);
129 static rtx
emit_block_move_via_libcall (rtx
, rtx
, rtx
, bool);
130 static tree
emit_block_move_libcall_fn (int);
131 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
132 static rtx
clear_by_pieces_1 (void *, HOST_WIDE_INT
, enum machine_mode
);
133 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
134 static void store_by_pieces_1 (struct store_by_pieces
*, unsigned int);
135 static void store_by_pieces_2 (rtx (*) (rtx
, ...), enum machine_mode
,
136 struct store_by_pieces
*);
137 static rtx
clear_storage_via_libcall (rtx
, rtx
, bool);
138 static tree
clear_storage_libcall_fn (int);
139 static rtx
compress_float_constant (rtx
, rtx
);
140 static rtx
get_subtarget (rtx
);
141 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
142 HOST_WIDE_INT
, enum machine_mode
,
143 tree
, tree
, int, int);
144 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
);
145 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
, enum machine_mode
,
148 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (tree
, tree
);
150 static int is_aligning_offset (tree
, tree
);
151 static void expand_operands (tree
, tree
, rtx
, rtx
*, rtx
*,
152 enum expand_modifier
);
153 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
154 static rtx
do_store_flag (tree
, rtx
, enum machine_mode
, int);
156 static void emit_single_push_insn (enum machine_mode
, rtx
, tree
);
158 static void do_tablejump (rtx
, enum machine_mode
, rtx
, rtx
, rtx
);
159 static rtx
const_vector_from_tree (tree
);
160 static void write_complex_part (rtx
, rtx
, bool);
162 /* Record for each mode whether we can move a register directly to or
163 from an object of that mode in memory. If we can't, we won't try
164 to use that mode directly when accessing a field of that mode. */
166 static char direct_load
[NUM_MACHINE_MODES
];
167 static char direct_store
[NUM_MACHINE_MODES
];
169 /* Record for each mode whether we can float-extend from memory. */
171 static bool float_extend_from_mem
[NUM_MACHINE_MODES
][NUM_MACHINE_MODES
];
173 /* This macro is used to determine whether move_by_pieces should be called
174 to perform a structure copy. */
175 #ifndef MOVE_BY_PIECES_P
176 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
177 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
178 < (unsigned int) MOVE_RATIO)
181 /* This macro is used to determine whether clear_by_pieces should be
182 called to clear storage. */
183 #ifndef CLEAR_BY_PIECES_P
184 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
185 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
186 < (unsigned int) CLEAR_RATIO)
189 /* This macro is used to determine whether store_by_pieces should be
190 called to "memset" storage with byte values other than zero, or
191 to "memcpy" storage when the source is a constant string. */
192 #ifndef STORE_BY_PIECES_P
193 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
194 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
195 < (unsigned int) MOVE_RATIO)
198 /* This array records the insn_code of insns to perform block moves. */
199 enum insn_code movmem_optab
[NUM_MACHINE_MODES
];
201 /* This array records the insn_code of insns to perform block sets. */
202 enum insn_code setmem_optab
[NUM_MACHINE_MODES
];
204 /* These arrays record the insn_code of three different kinds of insns
205 to perform block compares. */
206 enum insn_code cmpstr_optab
[NUM_MACHINE_MODES
];
207 enum insn_code cmpstrn_optab
[NUM_MACHINE_MODES
];
208 enum insn_code cmpmem_optab
[NUM_MACHINE_MODES
];
210 /* Synchronization primitives. */
211 enum insn_code sync_add_optab
[NUM_MACHINE_MODES
];
212 enum insn_code sync_sub_optab
[NUM_MACHINE_MODES
];
213 enum insn_code sync_ior_optab
[NUM_MACHINE_MODES
];
214 enum insn_code sync_and_optab
[NUM_MACHINE_MODES
];
215 enum insn_code sync_xor_optab
[NUM_MACHINE_MODES
];
216 enum insn_code sync_nand_optab
[NUM_MACHINE_MODES
];
217 enum insn_code sync_old_add_optab
[NUM_MACHINE_MODES
];
218 enum insn_code sync_old_sub_optab
[NUM_MACHINE_MODES
];
219 enum insn_code sync_old_ior_optab
[NUM_MACHINE_MODES
];
220 enum insn_code sync_old_and_optab
[NUM_MACHINE_MODES
];
221 enum insn_code sync_old_xor_optab
[NUM_MACHINE_MODES
];
222 enum insn_code sync_old_nand_optab
[NUM_MACHINE_MODES
];
223 enum insn_code sync_new_add_optab
[NUM_MACHINE_MODES
];
224 enum insn_code sync_new_sub_optab
[NUM_MACHINE_MODES
];
225 enum insn_code sync_new_ior_optab
[NUM_MACHINE_MODES
];
226 enum insn_code sync_new_and_optab
[NUM_MACHINE_MODES
];
227 enum insn_code sync_new_xor_optab
[NUM_MACHINE_MODES
];
228 enum insn_code sync_new_nand_optab
[NUM_MACHINE_MODES
];
229 enum insn_code sync_compare_and_swap
[NUM_MACHINE_MODES
];
230 enum insn_code sync_compare_and_swap_cc
[NUM_MACHINE_MODES
];
231 enum insn_code sync_lock_test_and_set
[NUM_MACHINE_MODES
];
232 enum insn_code sync_lock_release
[NUM_MACHINE_MODES
];
234 /* SLOW_UNALIGNED_ACCESS is nonzero if unaligned accesses are very slow. */
236 #ifndef SLOW_UNALIGNED_ACCESS
237 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
240 /* This is run once per compilation to set up which modes can be used
241 directly in memory and to initialize the block move optab. */
244 init_expr_once (void)
247 enum machine_mode mode
;
252 /* Try indexing by frame ptr and try by stack ptr.
253 It is known that on the Convex the stack ptr isn't a valid index.
254 With luck, one or the other is valid on any machine. */
255 mem
= gen_rtx_MEM (VOIDmode
, stack_pointer_rtx
);
256 mem1
= gen_rtx_MEM (VOIDmode
, frame_pointer_rtx
);
258 /* A scratch register we can modify in-place below to avoid
259 useless RTL allocations. */
260 reg
= gen_rtx_REG (VOIDmode
, -1);
262 insn
= rtx_alloc (INSN
);
263 pat
= gen_rtx_SET (0, NULL_RTX
, NULL_RTX
);
264 PATTERN (insn
) = pat
;
266 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
267 mode
= (enum machine_mode
) ((int) mode
+ 1))
271 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
272 PUT_MODE (mem
, mode
);
273 PUT_MODE (mem1
, mode
);
274 PUT_MODE (reg
, mode
);
276 /* See if there is some register that can be used in this mode and
277 directly loaded or stored from memory. */
279 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
280 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
281 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
284 if (! HARD_REGNO_MODE_OK (regno
, mode
))
290 SET_DEST (pat
) = reg
;
291 if (recog (pat
, insn
, &num_clobbers
) >= 0)
292 direct_load
[(int) mode
] = 1;
294 SET_SRC (pat
) = mem1
;
295 SET_DEST (pat
) = reg
;
296 if (recog (pat
, insn
, &num_clobbers
) >= 0)
297 direct_load
[(int) mode
] = 1;
300 SET_DEST (pat
) = mem
;
301 if (recog (pat
, insn
, &num_clobbers
) >= 0)
302 direct_store
[(int) mode
] = 1;
305 SET_DEST (pat
) = mem1
;
306 if (recog (pat
, insn
, &num_clobbers
) >= 0)
307 direct_store
[(int) mode
] = 1;
311 mem
= gen_rtx_MEM (VOIDmode
, gen_rtx_raw_REG (Pmode
, 10000));
313 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
314 mode
= GET_MODE_WIDER_MODE (mode
))
316 enum machine_mode srcmode
;
317 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
318 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
322 ic
= can_extend_p (mode
, srcmode
, 0);
323 if (ic
== CODE_FOR_nothing
)
326 PUT_MODE (mem
, srcmode
);
328 if ((*insn_data
[ic
].operand
[1].predicate
) (mem
, srcmode
))
329 float_extend_from_mem
[mode
][srcmode
] = true;
334 /* This is run at the start of compiling a function. */
339 cfun
->expr
= ggc_alloc_cleared (sizeof (struct expr_status
));
342 /* Copy data from FROM to TO, where the machine modes are not the same.
343 Both modes may be integer, or both may be floating.
344 UNSIGNEDP should be nonzero if FROM is an unsigned type.
345 This causes zero-extension instead of sign-extension. */
348 convert_move (rtx to
, rtx from
, int unsignedp
)
350 enum machine_mode to_mode
= GET_MODE (to
);
351 enum machine_mode from_mode
= GET_MODE (from
);
352 int to_real
= GET_MODE_CLASS (to_mode
) == MODE_FLOAT
;
353 int from_real
= GET_MODE_CLASS (from_mode
) == MODE_FLOAT
;
357 /* rtx code for making an equivalent value. */
358 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
359 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
362 gcc_assert (to_real
== from_real
);
364 /* If the source and destination are already the same, then there's
369 /* If FROM is a SUBREG that indicates that we have already done at least
370 the required extension, strip it. We don't handle such SUBREGs as
373 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
374 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (from
)))
375 >= GET_MODE_SIZE (to_mode
))
376 && SUBREG_PROMOTED_UNSIGNED_P (from
) == unsignedp
)
377 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
379 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
381 if (to_mode
== from_mode
382 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
384 emit_move_insn (to
, from
);
388 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
390 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
392 if (VECTOR_MODE_P (to_mode
))
393 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
395 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
397 emit_move_insn (to
, from
);
401 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
403 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
404 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
413 gcc_assert (GET_MODE_PRECISION (from_mode
)
414 != GET_MODE_PRECISION (to_mode
));
416 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
421 /* Try converting directly if the insn is supported. */
423 code
= tab
->handlers
[to_mode
][from_mode
].insn_code
;
424 if (code
!= CODE_FOR_nothing
)
426 emit_unop_insn (code
, to
, from
,
427 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
431 /* Otherwise use a libcall. */
432 libcall
= tab
->handlers
[to_mode
][from_mode
].libfunc
;
434 /* Is this conversion implemented yet? */
435 gcc_assert (libcall
);
438 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
440 insns
= get_insns ();
442 emit_libcall_block (insns
, to
, value
,
443 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
445 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
449 /* Handle pointer conversion. */ /* SPEE 900220. */
450 /* Targets are expected to provide conversion insns between PxImode and
451 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
452 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
454 enum machine_mode full_mode
455 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
457 gcc_assert (trunc_optab
->handlers
[to_mode
][full_mode
].insn_code
458 != CODE_FOR_nothing
);
460 if (full_mode
!= from_mode
)
461 from
= convert_to_mode (full_mode
, from
, unsignedp
);
462 emit_unop_insn (trunc_optab
->handlers
[to_mode
][full_mode
].insn_code
,
466 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
469 enum machine_mode full_mode
470 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
472 gcc_assert (sext_optab
->handlers
[full_mode
][from_mode
].insn_code
473 != CODE_FOR_nothing
);
475 if (to_mode
== full_mode
)
477 emit_unop_insn (sext_optab
->handlers
[full_mode
][from_mode
].insn_code
,
482 new_from
= gen_reg_rtx (full_mode
);
483 emit_unop_insn (sext_optab
->handlers
[full_mode
][from_mode
].insn_code
,
484 new_from
, from
, UNKNOWN
);
486 /* else proceed to integer conversions below. */
487 from_mode
= full_mode
;
491 /* Now both modes are integers. */
493 /* Handle expanding beyond a word. */
494 if (GET_MODE_BITSIZE (from_mode
) < GET_MODE_BITSIZE (to_mode
)
495 && GET_MODE_BITSIZE (to_mode
) > BITS_PER_WORD
)
502 enum machine_mode lowpart_mode
;
503 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
505 /* Try converting directly if the insn is supported. */
506 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
509 /* If FROM is a SUBREG, put it into a register. Do this
510 so that we always generate the same set of insns for
511 better cse'ing; if an intermediate assignment occurred,
512 we won't be doing the operation directly on the SUBREG. */
513 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
514 from
= force_reg (from_mode
, from
);
515 emit_unop_insn (code
, to
, from
, equiv_code
);
518 /* Next, try converting via full word. */
519 else if (GET_MODE_BITSIZE (from_mode
) < BITS_PER_WORD
520 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
521 != CODE_FOR_nothing
))
525 if (reg_overlap_mentioned_p (to
, from
))
526 from
= force_reg (from_mode
, from
);
527 emit_insn (gen_rtx_CLOBBER (VOIDmode
, to
));
529 convert_move (gen_lowpart (word_mode
, to
), from
, unsignedp
);
530 emit_unop_insn (code
, to
,
531 gen_lowpart (word_mode
, to
), equiv_code
);
535 /* No special multiword conversion insn; do it by hand. */
538 /* Since we will turn this into a no conflict block, we must ensure
539 that the source does not overlap the target. */
541 if (reg_overlap_mentioned_p (to
, from
))
542 from
= force_reg (from_mode
, from
);
544 /* Get a copy of FROM widened to a word, if necessary. */
545 if (GET_MODE_BITSIZE (from_mode
) < BITS_PER_WORD
)
546 lowpart_mode
= word_mode
;
548 lowpart_mode
= from_mode
;
550 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
552 lowpart
= gen_lowpart (lowpart_mode
, to
);
553 emit_move_insn (lowpart
, lowfrom
);
555 /* Compute the value to put in each remaining word. */
557 fill_value
= const0_rtx
;
562 && insn_data
[(int) CODE_FOR_slt
].operand
[0].mode
== word_mode
563 && STORE_FLAG_VALUE
== -1)
565 emit_cmp_insn (lowfrom
, const0_rtx
, NE
, NULL_RTX
,
567 fill_value
= gen_reg_rtx (word_mode
);
568 emit_insn (gen_slt (fill_value
));
574 = expand_shift (RSHIFT_EXPR
, lowpart_mode
, lowfrom
,
575 size_int (GET_MODE_BITSIZE (lowpart_mode
) - 1),
577 fill_value
= convert_to_mode (word_mode
, fill_value
, 1);
581 /* Fill the remaining words. */
582 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
584 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
585 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
587 gcc_assert (subword
);
589 if (fill_value
!= subword
)
590 emit_move_insn (subword
, fill_value
);
593 insns
= get_insns ();
596 emit_no_conflict_block (insns
, to
, from
, NULL_RTX
,
597 gen_rtx_fmt_e (equiv_code
, to_mode
, copy_rtx (from
)));
601 /* Truncating multi-word to a word or less. */
602 if (GET_MODE_BITSIZE (from_mode
) > BITS_PER_WORD
603 && GET_MODE_BITSIZE (to_mode
) <= BITS_PER_WORD
)
606 && ! MEM_VOLATILE_P (from
)
607 && direct_load
[(int) to_mode
]
608 && ! mode_dependent_address_p (XEXP (from
, 0)))
610 || GET_CODE (from
) == SUBREG
))
611 from
= force_reg (from_mode
, from
);
612 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
616 /* Now follow all the conversions between integers
617 no more than a word long. */
619 /* For truncation, usually we can just refer to FROM in a narrower mode. */
620 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
621 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode
),
622 GET_MODE_BITSIZE (from_mode
)))
625 && ! MEM_VOLATILE_P (from
)
626 && direct_load
[(int) to_mode
]
627 && ! mode_dependent_address_p (XEXP (from
, 0)))
629 || GET_CODE (from
) == SUBREG
))
630 from
= force_reg (from_mode
, from
);
631 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
632 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
633 from
= copy_to_reg (from
);
634 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
638 /* Handle extension. */
639 if (GET_MODE_BITSIZE (to_mode
) > GET_MODE_BITSIZE (from_mode
))
641 /* Convert directly if that works. */
642 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
645 emit_unop_insn (code
, to
, from
, equiv_code
);
650 enum machine_mode intermediate
;
654 /* Search for a mode to convert via. */
655 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
656 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
657 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
659 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
660 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode
),
661 GET_MODE_BITSIZE (intermediate
))))
662 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
663 != CODE_FOR_nothing
))
665 convert_move (to
, convert_to_mode (intermediate
, from
,
666 unsignedp
), unsignedp
);
670 /* No suitable intermediate mode.
671 Generate what we need with shifts. */
672 shift_amount
= build_int_cst (NULL_TREE
,
673 GET_MODE_BITSIZE (to_mode
)
674 - GET_MODE_BITSIZE (from_mode
));
675 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
676 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
678 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
681 emit_move_insn (to
, tmp
);
686 /* Support special truncate insns for certain modes. */
687 if (trunc_optab
->handlers
[to_mode
][from_mode
].insn_code
!= CODE_FOR_nothing
)
689 emit_unop_insn (trunc_optab
->handlers
[to_mode
][from_mode
].insn_code
,
694 /* Handle truncation of volatile memrefs, and so on;
695 the things that couldn't be truncated directly,
696 and for which there was no special instruction.
698 ??? Code above formerly short-circuited this, for most integer
699 mode pairs, with a force_reg in from_mode followed by a recursive
700 call to this routine. Appears always to have been wrong. */
701 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
))
703 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
704 emit_move_insn (to
, temp
);
708 /* Mode combination is not recognized. */
712 /* Return an rtx for a value that would result
713 from converting X to mode MODE.
714 Both X and MODE may be floating, or both integer.
715 UNSIGNEDP is nonzero if X is an unsigned value.
716 This can be done by referring to a part of X in place
717 or by copying to a new temporary with conversion. */
720 convert_to_mode (enum machine_mode mode
, rtx x
, int unsignedp
)
722 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
725 /* Return an rtx for a value that would result
726 from converting X from mode OLDMODE to mode MODE.
727 Both modes may be floating, or both integer.
728 UNSIGNEDP is nonzero if X is an unsigned value.
730 This can be done by referring to a part of X in place
731 or by copying to a new temporary with conversion.
733 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
736 convert_modes (enum machine_mode mode
, enum machine_mode oldmode
, rtx x
, int unsignedp
)
740 /* If FROM is a SUBREG that indicates that we have already done at least
741 the required extension, strip it. */
743 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
744 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
745 && SUBREG_PROMOTED_UNSIGNED_P (x
) == unsignedp
)
746 x
= gen_lowpart (mode
, x
);
748 if (GET_MODE (x
) != VOIDmode
)
749 oldmode
= GET_MODE (x
);
754 /* There is one case that we must handle specially: If we are converting
755 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
756 we are to interpret the constant as unsigned, gen_lowpart will do
757 the wrong if the constant appears negative. What we want to do is
758 make the high-order word of the constant zero, not all ones. */
760 if (unsignedp
&& GET_MODE_CLASS (mode
) == MODE_INT
761 && GET_MODE_BITSIZE (mode
) == 2 * HOST_BITS_PER_WIDE_INT
762 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < 0)
764 HOST_WIDE_INT val
= INTVAL (x
);
766 if (oldmode
!= VOIDmode
767 && HOST_BITS_PER_WIDE_INT
> GET_MODE_BITSIZE (oldmode
))
769 int width
= GET_MODE_BITSIZE (oldmode
);
771 /* We need to zero extend VAL. */
772 val
&= ((HOST_WIDE_INT
) 1 << width
) - 1;
775 return immed_double_const (val
, (HOST_WIDE_INT
) 0, mode
);
778 /* We can do this with a gen_lowpart if both desired and current modes
779 are integer, and this is either a constant integer, a register, or a
780 non-volatile MEM. Except for the constant case where MODE is no
781 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
783 if ((GET_CODE (x
) == CONST_INT
784 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
785 || (GET_MODE_CLASS (mode
) == MODE_INT
786 && GET_MODE_CLASS (oldmode
) == MODE_INT
787 && (GET_CODE (x
) == CONST_DOUBLE
788 || (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (oldmode
)
789 && ((MEM_P (x
) && ! MEM_VOLATILE_P (x
)
790 && direct_load
[(int) mode
])
792 && (! HARD_REGISTER_P (x
)
793 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
794 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode
),
795 GET_MODE_BITSIZE (GET_MODE (x
)))))))))
797 /* ?? If we don't know OLDMODE, we have to assume here that
798 X does not need sign- or zero-extension. This may not be
799 the case, but it's the best we can do. */
800 if (GET_CODE (x
) == CONST_INT
&& oldmode
!= VOIDmode
801 && GET_MODE_SIZE (mode
) > GET_MODE_SIZE (oldmode
))
803 HOST_WIDE_INT val
= INTVAL (x
);
804 int width
= GET_MODE_BITSIZE (oldmode
);
806 /* We must sign or zero-extend in this case. Start by
807 zero-extending, then sign extend if we need to. */
808 val
&= ((HOST_WIDE_INT
) 1 << width
) - 1;
810 && (val
& ((HOST_WIDE_INT
) 1 << (width
- 1))))
811 val
|= (HOST_WIDE_INT
) (-1) << width
;
813 return gen_int_mode (val
, mode
);
816 return gen_lowpart (mode
, x
);
819 /* Converting from integer constant into mode is always equivalent to an
821 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
823 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
824 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
827 temp
= gen_reg_rtx (mode
);
828 convert_move (temp
, x
, unsignedp
);
832 /* STORE_MAX_PIECES is the number of bytes at a time that we can
833 store efficiently. Due to internal GCC limitations, this is
834 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
835 for an immediate constant. */
837 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
839 /* Determine whether the LEN bytes can be moved by using several move
840 instructions. Return nonzero if a call to move_by_pieces should
844 can_move_by_pieces (unsigned HOST_WIDE_INT len
,
845 unsigned int align ATTRIBUTE_UNUSED
)
847 return MOVE_BY_PIECES_P (len
, align
);
850 /* Generate several move instructions to copy LEN bytes from block FROM to
851 block TO. (These are MEM rtx's with BLKmode).
853 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
854 used to push FROM to the stack.
856 ALIGN is maximum stack alignment we can assume.
858 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
859 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
863 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
864 unsigned int align
, int endp
)
866 struct move_by_pieces data
;
867 rtx to_addr
, from_addr
= XEXP (from
, 0);
868 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
869 enum machine_mode mode
= VOIDmode
, tmode
;
870 enum insn_code icode
;
872 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
875 data
.from_addr
= from_addr
;
878 to_addr
= XEXP (to
, 0);
881 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
882 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
884 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
891 #ifdef STACK_GROWS_DOWNWARD
897 data
.to_addr
= to_addr
;
900 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
901 || GET_CODE (from_addr
) == POST_INC
902 || GET_CODE (from_addr
) == POST_DEC
);
904 data
.explicit_inc_from
= 0;
905 data
.explicit_inc_to
= 0;
906 if (data
.reverse
) data
.offset
= len
;
909 /* If copying requires more than two move insns,
910 copy addresses to registers (to make displacements shorter)
911 and use post-increment if available. */
912 if (!(data
.autinc_from
&& data
.autinc_to
)
913 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
915 /* Find the mode of the largest move... */
916 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
917 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
918 if (GET_MODE_SIZE (tmode
) < max_size
)
921 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
923 data
.from_addr
= copy_addr_to_reg (plus_constant (from_addr
, len
));
924 data
.autinc_from
= 1;
925 data
.explicit_inc_from
= -1;
927 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
929 data
.from_addr
= copy_addr_to_reg (from_addr
);
930 data
.autinc_from
= 1;
931 data
.explicit_inc_from
= 1;
933 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
934 data
.from_addr
= copy_addr_to_reg (from_addr
);
935 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
937 data
.to_addr
= copy_addr_to_reg (plus_constant (to_addr
, len
));
939 data
.explicit_inc_to
= -1;
941 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
943 data
.to_addr
= copy_addr_to_reg (to_addr
);
945 data
.explicit_inc_to
= 1;
947 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
948 data
.to_addr
= copy_addr_to_reg (to_addr
);
951 tmode
= mode_for_size (MOVE_MAX_PIECES
* BITS_PER_UNIT
, MODE_INT
, 1);
952 if (align
>= GET_MODE_ALIGNMENT (tmode
))
953 align
= GET_MODE_ALIGNMENT (tmode
);
956 enum machine_mode xmode
;
958 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
960 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
961 if (GET_MODE_SIZE (tmode
) > MOVE_MAX_PIECES
962 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
965 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
968 /* First move what we can in the largest integer mode, then go to
969 successively smaller modes. */
973 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
974 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
975 if (GET_MODE_SIZE (tmode
) < max_size
)
978 if (mode
== VOIDmode
)
981 icode
= mov_optab
->handlers
[(int) mode
].insn_code
;
982 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
983 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
985 max_size
= GET_MODE_SIZE (mode
);
988 /* The code above should have handled everything. */
989 gcc_assert (!data
.len
);
995 gcc_assert (!data
.reverse
);
1000 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
1001 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
1003 data
.to_addr
= copy_addr_to_reg (plus_constant (data
.to_addr
,
1006 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
1013 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
1021 /* Return number of insns required to move L bytes by pieces.
1022 ALIGN (in bits) is maximum alignment we can assume. */
1024 static unsigned HOST_WIDE_INT
1025 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
1026 unsigned int max_size
)
1028 unsigned HOST_WIDE_INT n_insns
= 0;
1029 enum machine_mode tmode
;
1031 tmode
= mode_for_size (MOVE_MAX_PIECES
* BITS_PER_UNIT
, MODE_INT
, 1);
1032 if (align
>= GET_MODE_ALIGNMENT (tmode
))
1033 align
= GET_MODE_ALIGNMENT (tmode
);
1036 enum machine_mode tmode
, xmode
;
1038 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
1040 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
1041 if (GET_MODE_SIZE (tmode
) > MOVE_MAX_PIECES
1042 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
1045 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
1048 while (max_size
> 1)
1050 enum machine_mode mode
= VOIDmode
;
1051 enum insn_code icode
;
1053 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
1054 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
1055 if (GET_MODE_SIZE (tmode
) < max_size
)
1058 if (mode
== VOIDmode
)
1061 icode
= mov_optab
->handlers
[(int) mode
].insn_code
;
1062 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
1063 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
1065 max_size
= GET_MODE_SIZE (mode
);
1072 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1073 with move instructions for mode MODE. GENFUN is the gen_... function
1074 to make a move insn for that mode. DATA has all the other info. */
1077 move_by_pieces_1 (rtx (*genfun
) (rtx
, ...), enum machine_mode mode
,
1078 struct move_by_pieces
*data
)
1080 unsigned int size
= GET_MODE_SIZE (mode
);
1081 rtx to1
= NULL_RTX
, from1
;
1083 while (data
->len
>= size
)
1086 data
->offset
-= size
;
1090 if (data
->autinc_to
)
1091 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1094 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1097 if (data
->autinc_from
)
1098 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1101 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1103 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1104 emit_insn (gen_add2_insn (data
->to_addr
,
1105 GEN_INT (-(HOST_WIDE_INT
)size
)));
1106 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1107 emit_insn (gen_add2_insn (data
->from_addr
,
1108 GEN_INT (-(HOST_WIDE_INT
)size
)));
1111 emit_insn ((*genfun
) (to1
, from1
));
1114 #ifdef PUSH_ROUNDING
1115 emit_single_push_insn (mode
, from1
, NULL
);
1121 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1122 emit_insn (gen_add2_insn (data
->to_addr
, GEN_INT (size
)));
1123 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1124 emit_insn (gen_add2_insn (data
->from_addr
, GEN_INT (size
)));
1126 if (! data
->reverse
)
1127 data
->offset
+= size
;
1133 /* Emit code to move a block Y to a block X. This may be done with
1134 string-move instructions, with multiple scalar move instructions,
1135 or with a library call.
1137 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1138 SIZE is an rtx that says how long they are.
1139 ALIGN is the maximum alignment we can assume they have.
1140 METHOD describes what kind of copy this is, and what mechanisms may be used.
1142 Return the address of the new block, if memcpy is called and returns it,
1146 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1154 case BLOCK_OP_NORMAL
:
1155 case BLOCK_OP_TAILCALL
:
1156 may_use_call
= true;
1159 case BLOCK_OP_CALL_PARM
:
1160 may_use_call
= block_move_libcall_safe_for_call_parm ();
1162 /* Make inhibit_defer_pop nonzero around the library call
1163 to force it to pop the arguments right away. */
1167 case BLOCK_OP_NO_LIBCALL
:
1168 may_use_call
= false;
1175 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1177 gcc_assert (MEM_P (x
));
1178 gcc_assert (MEM_P (y
));
1181 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1182 block copy is more efficient for other large modes, e.g. DCmode. */
1183 x
= adjust_address (x
, BLKmode
, 0);
1184 y
= adjust_address (y
, BLKmode
, 0);
1186 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1187 can be incorrect is coming from __builtin_memcpy. */
1188 if (GET_CODE (size
) == CONST_INT
)
1190 if (INTVAL (size
) == 0)
1193 x
= shallow_copy_rtx (x
);
1194 y
= shallow_copy_rtx (y
);
1195 set_mem_size (x
, size
);
1196 set_mem_size (y
, size
);
1199 if (GET_CODE (size
) == CONST_INT
&& MOVE_BY_PIECES_P (INTVAL (size
), align
))
1200 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1201 else if (emit_block_move_via_movmem (x
, y
, size
, align
))
1203 else if (may_use_call
)
1204 retval
= emit_block_move_via_libcall (x
, y
, size
,
1205 method
== BLOCK_OP_TAILCALL
);
1207 emit_block_move_via_loop (x
, y
, size
, align
);
1209 if (method
== BLOCK_OP_CALL_PARM
)
1215 /* A subroutine of emit_block_move. Returns true if calling the
1216 block move libcall will not clobber any parameters which may have
1217 already been placed on the stack. */
1220 block_move_libcall_safe_for_call_parm (void)
1222 /* If arguments are pushed on the stack, then they're safe. */
1226 /* If registers go on the stack anyway, any argument is sure to clobber
1227 an outgoing argument. */
1228 #if defined (REG_PARM_STACK_SPACE) && defined (OUTGOING_REG_PARM_STACK_SPACE)
1230 tree fn
= emit_block_move_libcall_fn (false);
1232 if (REG_PARM_STACK_SPACE (fn
) != 0)
1237 /* If any argument goes in memory, then it might clobber an outgoing
1240 CUMULATIVE_ARGS args_so_far
;
1243 fn
= emit_block_move_libcall_fn (false);
1244 INIT_CUMULATIVE_ARGS (args_so_far
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1246 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1247 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1249 enum machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1250 rtx tmp
= FUNCTION_ARG (args_so_far
, mode
, NULL_TREE
, 1);
1251 if (!tmp
|| !REG_P (tmp
))
1253 if (targetm
.calls
.arg_partial_bytes (&args_so_far
, mode
, NULL
, 1))
1255 FUNCTION_ARG_ADVANCE (args_so_far
, mode
, NULL_TREE
, 1);
1261 /* A subroutine of emit_block_move. Expand a movmem pattern;
1262 return true if successful. */
1265 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
)
1267 rtx opalign
= GEN_INT (align
/ BITS_PER_UNIT
);
1268 int save_volatile_ok
= volatile_ok
;
1269 enum machine_mode mode
;
1271 /* Since this is a move insn, we don't care about volatility. */
1274 /* Try the most limited insn first, because there's no point
1275 including more than one in the machine description unless
1276 the more limited one has some advantage. */
1278 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1279 mode
= GET_MODE_WIDER_MODE (mode
))
1281 enum insn_code code
= movmem_optab
[(int) mode
];
1282 insn_operand_predicate_fn pred
;
1284 if (code
!= CODE_FOR_nothing
1285 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1286 here because if SIZE is less than the mode mask, as it is
1287 returned by the macro, it will definitely be less than the
1288 actual mode mask. */
1289 && ((GET_CODE (size
) == CONST_INT
1290 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1291 <= (GET_MODE_MASK (mode
) >> 1)))
1292 || GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
)
1293 && ((pred
= insn_data
[(int) code
].operand
[0].predicate
) == 0
1294 || (*pred
) (x
, BLKmode
))
1295 && ((pred
= insn_data
[(int) code
].operand
[1].predicate
) == 0
1296 || (*pred
) (y
, BLKmode
))
1297 && ((pred
= insn_data
[(int) code
].operand
[3].predicate
) == 0
1298 || (*pred
) (opalign
, VOIDmode
)))
1301 rtx last
= get_last_insn ();
1304 op2
= convert_to_mode (mode
, size
, 1);
1305 pred
= insn_data
[(int) code
].operand
[2].predicate
;
1306 if (pred
!= 0 && ! (*pred
) (op2
, mode
))
1307 op2
= copy_to_mode_reg (mode
, op2
);
1309 /* ??? When called via emit_block_move_for_call, it'd be
1310 nice if there were some way to inform the backend, so
1311 that it doesn't fail the expansion because it thinks
1312 emitting the libcall would be more efficient. */
1314 pat
= GEN_FCN ((int) code
) (x
, y
, op2
, opalign
);
1318 volatile_ok
= save_volatile_ok
;
1322 delete_insns_since (last
);
1326 volatile_ok
= save_volatile_ok
;
1330 /* A subroutine of emit_block_move. Expand a call to memcpy.
1331 Return the return value from memcpy, 0 otherwise. */
1334 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1336 rtx dst_addr
, src_addr
;
1337 tree call_expr
, arg_list
, fn
, src_tree
, dst_tree
, size_tree
;
1338 enum machine_mode size_mode
;
1341 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1342 pseudos. We can then place those new pseudos into a VAR_DECL and
1345 dst_addr
= copy_to_mode_reg (Pmode
, XEXP (dst
, 0));
1346 src_addr
= copy_to_mode_reg (Pmode
, XEXP (src
, 0));
1348 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1349 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1351 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1352 src_tree
= make_tree (ptr_type_node
, src_addr
);
1354 size_mode
= TYPE_MODE (sizetype
);
1356 size
= convert_to_mode (size_mode
, size
, 1);
1357 size
= copy_to_mode_reg (size_mode
, size
);
1359 /* It is incorrect to use the libcall calling conventions to call
1360 memcpy in this context. This could be a user call to memcpy and
1361 the user may wish to examine the return value from memcpy. For
1362 targets where libcalls and normal calls have different conventions
1363 for returning pointers, we could end up generating incorrect code. */
1365 size_tree
= make_tree (sizetype
, size
);
1367 fn
= emit_block_move_libcall_fn (true);
1368 arg_list
= tree_cons (NULL_TREE
, size_tree
, NULL_TREE
);
1369 arg_list
= tree_cons (NULL_TREE
, src_tree
, arg_list
);
1370 arg_list
= tree_cons (NULL_TREE
, dst_tree
, arg_list
);
1372 /* Now we have to build up the CALL_EXPR itself. */
1373 call_expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (fn
)), fn
);
1374 call_expr
= build3 (CALL_EXPR
, TREE_TYPE (TREE_TYPE (fn
)),
1375 call_expr
, arg_list
, NULL_TREE
);
1376 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1378 retval
= expand_expr (call_expr
, NULL_RTX
, VOIDmode
, 0);
1383 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1384 for the function we use for block copies. The first time FOR_CALL
1385 is true, we call assemble_external. */
1387 static GTY(()) tree block_move_fn
;
1390 init_block_move_fn (const char *asmspec
)
1396 fn
= get_identifier ("memcpy");
1397 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1398 const_ptr_type_node
, sizetype
,
1401 fn
= build_decl (FUNCTION_DECL
, fn
, args
);
1402 DECL_EXTERNAL (fn
) = 1;
1403 TREE_PUBLIC (fn
) = 1;
1404 DECL_ARTIFICIAL (fn
) = 1;
1405 TREE_NOTHROW (fn
) = 1;
1406 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1407 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1413 set_user_assembler_name (block_move_fn
, asmspec
);
1417 emit_block_move_libcall_fn (int for_call
)
1419 static bool emitted_extern
;
1422 init_block_move_fn (NULL
);
1424 if (for_call
&& !emitted_extern
)
1426 emitted_extern
= true;
1427 make_decl_rtl (block_move_fn
);
1428 assemble_external (block_move_fn
);
1431 return block_move_fn
;
1434 /* A subroutine of emit_block_move. Copy the data via an explicit
1435 loop. This is used only when libcalls are forbidden. */
1436 /* ??? It'd be nice to copy in hunks larger than QImode. */
1439 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1440 unsigned int align ATTRIBUTE_UNUSED
)
1442 rtx cmp_label
, top_label
, iter
, x_addr
, y_addr
, tmp
;
1443 enum machine_mode iter_mode
;
1445 iter_mode
= GET_MODE (size
);
1446 if (iter_mode
== VOIDmode
)
1447 iter_mode
= word_mode
;
1449 top_label
= gen_label_rtx ();
1450 cmp_label
= gen_label_rtx ();
1451 iter
= gen_reg_rtx (iter_mode
);
1453 emit_move_insn (iter
, const0_rtx
);
1455 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1456 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1457 do_pending_stack_adjust ();
1459 emit_jump (cmp_label
);
1460 emit_label (top_label
);
1462 tmp
= convert_modes (Pmode
, iter_mode
, iter
, true);
1463 x_addr
= gen_rtx_PLUS (Pmode
, x_addr
, tmp
);
1464 y_addr
= gen_rtx_PLUS (Pmode
, y_addr
, tmp
);
1465 x
= change_address (x
, QImode
, x_addr
);
1466 y
= change_address (y
, QImode
, y_addr
);
1468 emit_move_insn (x
, y
);
1470 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1471 true, OPTAB_LIB_WIDEN
);
1473 emit_move_insn (iter
, tmp
);
1475 emit_label (cmp_label
);
1477 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1481 /* Copy all or part of a value X into registers starting at REGNO.
1482 The number of registers to be filled is NREGS. */
1485 move_block_to_reg (int regno
, rtx x
, int nregs
, enum machine_mode mode
)
1488 #ifdef HAVE_load_multiple
1496 if (CONSTANT_P (x
) && ! LEGITIMATE_CONSTANT_P (x
))
1497 x
= validize_mem (force_const_mem (mode
, x
));
1499 /* See if the machine can do this with a load multiple insn. */
1500 #ifdef HAVE_load_multiple
1501 if (HAVE_load_multiple
)
1503 last
= get_last_insn ();
1504 pat
= gen_load_multiple (gen_rtx_REG (word_mode
, regno
), x
,
1512 delete_insns_since (last
);
1516 for (i
= 0; i
< nregs
; i
++)
1517 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1518 operand_subword_force (x
, i
, mode
));
1521 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1522 The number of registers to be filled is NREGS. */
1525 move_block_from_reg (int regno
, rtx x
, int nregs
)
1532 /* See if the machine can do this with a store multiple insn. */
1533 #ifdef HAVE_store_multiple
1534 if (HAVE_store_multiple
)
1536 rtx last
= get_last_insn ();
1537 rtx pat
= gen_store_multiple (x
, gen_rtx_REG (word_mode
, regno
),
1545 delete_insns_since (last
);
1549 for (i
= 0; i
< nregs
; i
++)
1551 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1555 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1559 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1560 ORIG, where ORIG is a non-consecutive group of registers represented by
1561 a PARALLEL. The clone is identical to the original except in that the
1562 original set of registers is replaced by a new set of pseudo registers.
1563 The new set has the same modes as the original set. */
1566 gen_group_rtx (rtx orig
)
1571 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1573 length
= XVECLEN (orig
, 0);
1574 tmps
= alloca (sizeof (rtx
) * length
);
1576 /* Skip a NULL entry in first slot. */
1577 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1582 for (; i
< length
; i
++)
1584 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1585 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1587 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1590 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1593 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1594 except that values are placed in TMPS[i], and must later be moved
1595 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1598 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1602 enum machine_mode m
= GET_MODE (orig_src
);
1604 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1607 && !SCALAR_INT_MODE_P (m
)
1608 && !MEM_P (orig_src
)
1609 && GET_CODE (orig_src
) != CONCAT
)
1611 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1612 if (imode
== BLKmode
)
1613 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
, 0);
1615 src
= gen_reg_rtx (imode
);
1616 if (imode
!= BLKmode
)
1617 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1618 emit_move_insn (src
, orig_src
);
1619 /* ...and back again. */
1620 if (imode
!= BLKmode
)
1621 src
= gen_lowpart (imode
, src
);
1622 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1626 /* Check for a NULL entry, used to indicate that the parameter goes
1627 both on the stack and in registers. */
1628 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1633 /* Process the pieces. */
1634 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1636 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1637 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1638 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1641 /* Handle trailing fragments that run over the size of the struct. */
1642 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1644 /* Arrange to shift the fragment to where it belongs.
1645 extract_bit_field loads to the lsb of the reg. */
1647 #ifdef BLOCK_REG_PADDING
1648 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1649 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1654 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1655 bytelen
= ssize
- bytepos
;
1656 gcc_assert (bytelen
> 0);
1659 /* If we won't be loading directly from memory, protect the real source
1660 from strange tricks we might play; but make sure that the source can
1661 be loaded directly into the destination. */
1663 if (!MEM_P (orig_src
)
1664 && (!CONSTANT_P (orig_src
)
1665 || (GET_MODE (orig_src
) != mode
1666 && GET_MODE (orig_src
) != VOIDmode
)))
1668 if (GET_MODE (orig_src
) == VOIDmode
)
1669 src
= gen_reg_rtx (mode
);
1671 src
= gen_reg_rtx (GET_MODE (orig_src
));
1673 emit_move_insn (src
, orig_src
);
1676 /* Optimize the access just a bit. */
1678 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1679 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1680 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1681 && bytelen
== GET_MODE_SIZE (mode
))
1683 tmps
[i
] = gen_reg_rtx (mode
);
1684 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1686 else if (COMPLEX_MODE_P (mode
)
1687 && GET_MODE (src
) == mode
1688 && bytelen
== GET_MODE_SIZE (mode
))
1689 /* Let emit_move_complex do the bulk of the work. */
1691 else if (GET_CODE (src
) == CONCAT
)
1693 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1694 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1696 if ((bytepos
== 0 && bytelen
== slen0
)
1697 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1699 /* The following assumes that the concatenated objects all
1700 have the same size. In this case, a simple calculation
1701 can be used to determine the object and the bit field
1703 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1704 if (! CONSTANT_P (tmps
[i
])
1705 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1706 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1707 (bytepos
% slen0
) * BITS_PER_UNIT
,
1708 1, NULL_RTX
, mode
, mode
);
1714 gcc_assert (!bytepos
);
1715 mem
= assign_stack_temp (GET_MODE (src
), slen
, 0);
1716 emit_move_insn (mem
, src
);
1717 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1718 0, 1, NULL_RTX
, mode
, mode
);
1721 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1722 SIMD register, which is currently broken. While we get GCC
1723 to emit proper RTL for these cases, let's dump to memory. */
1724 else if (VECTOR_MODE_P (GET_MODE (dst
))
1727 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1730 mem
= assign_stack_temp (GET_MODE (src
), slen
, 0);
1731 emit_move_insn (mem
, src
);
1732 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1734 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1735 && XVECLEN (dst
, 0) > 1)
1736 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE(dst
), bytepos
);
1737 else if (CONSTANT_P (src
)
1738 || (REG_P (src
) && GET_MODE (src
) == mode
))
1741 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1742 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
1746 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1747 build_int_cst (NULL_TREE
, shift
), tmps
[i
], 0);
1751 /* Emit code to move a block SRC of type TYPE to a block DST,
1752 where DST is non-consecutive registers represented by a PARALLEL.
1753 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1757 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1762 tmps
= alloca (sizeof (rtx
) * XVECLEN (dst
, 0));
1763 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1765 /* Copy the extracted pieces into the proper (probable) hard regs. */
1766 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1768 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1771 emit_move_insn (d
, tmps
[i
]);
1775 /* Similar, but load SRC into new pseudos in a format that looks like
1776 PARALLEL. This can later be fed to emit_group_move to get things
1777 in the right place. */
1780 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1785 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1786 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1788 /* Convert the vector to look just like the original PARALLEL, except
1789 with the computed values. */
1790 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1792 rtx e
= XVECEXP (parallel
, 0, i
);
1793 rtx d
= XEXP (e
, 0);
1797 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1798 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1800 RTVEC_ELT (vec
, i
) = e
;
1803 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1806 /* Emit code to move a block SRC to block DST, where SRC and DST are
1807 non-consecutive groups of registers, each represented by a PARALLEL. */
1810 emit_group_move (rtx dst
, rtx src
)
1814 gcc_assert (GET_CODE (src
) == PARALLEL
1815 && GET_CODE (dst
) == PARALLEL
1816 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1818 /* Skip first entry if NULL. */
1819 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1820 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1821 XEXP (XVECEXP (src
, 0, i
), 0));
1824 /* Move a group of registers represented by a PARALLEL into pseudos. */
1827 emit_group_move_into_temps (rtx src
)
1829 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1832 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1834 rtx e
= XVECEXP (src
, 0, i
);
1835 rtx d
= XEXP (e
, 0);
1838 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1839 RTVEC_ELT (vec
, i
) = e
;
1842 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1845 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1846 where SRC is non-consecutive registers represented by a PARALLEL.
1847 SSIZE represents the total size of block ORIG_DST, or -1 if not
1851 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1855 enum machine_mode m
= GET_MODE (orig_dst
);
1857 gcc_assert (GET_CODE (src
) == PARALLEL
);
1859 if (!SCALAR_INT_MODE_P (m
)
1860 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1862 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1863 if (imode
== BLKmode
)
1864 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
, 0);
1866 dst
= gen_reg_rtx (imode
);
1867 emit_group_store (dst
, src
, type
, ssize
);
1868 if (imode
!= BLKmode
)
1869 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1870 emit_move_insn (orig_dst
, dst
);
1874 /* Check for a NULL entry, used to indicate that the parameter goes
1875 both on the stack and in registers. */
1876 if (XEXP (XVECEXP (src
, 0, 0), 0))
1881 tmps
= alloca (sizeof (rtx
) * XVECLEN (src
, 0));
1883 /* Copy the (probable) hard regs into pseudos. */
1884 for (i
= start
; i
< XVECLEN (src
, 0); i
++)
1886 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1887 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1888 emit_move_insn (tmps
[i
], reg
);
1891 /* If we won't be storing directly into memory, protect the real destination
1892 from strange tricks we might play. */
1894 if (GET_CODE (dst
) == PARALLEL
)
1898 /* We can get a PARALLEL dst if there is a conditional expression in
1899 a return statement. In that case, the dst and src are the same,
1900 so no action is necessary. */
1901 if (rtx_equal_p (dst
, src
))
1904 /* It is unclear if we can ever reach here, but we may as well handle
1905 it. Allocate a temporary, and split this into a store/load to/from
1908 temp
= assign_stack_temp (GET_MODE (dst
), ssize
, 0);
1909 emit_group_store (temp
, src
, type
, ssize
);
1910 emit_group_load (dst
, temp
, type
, ssize
);
1913 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1915 dst
= gen_reg_rtx (GET_MODE (orig_dst
));
1916 /* Make life a bit easier for combine. */
1917 emit_move_insn (dst
, CONST0_RTX (GET_MODE (orig_dst
)));
1920 /* Process the pieces. */
1921 for (i
= start
; i
< XVECLEN (src
, 0); i
++)
1923 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
1924 enum machine_mode mode
= GET_MODE (tmps
[i
]);
1925 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1928 /* Handle trailing fragments that run over the size of the struct. */
1929 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1931 /* store_bit_field always takes its value from the lsb.
1932 Move the fragment to the lsb if it's not already there. */
1934 #ifdef BLOCK_REG_PADDING
1935 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
1936 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1942 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1943 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
1944 build_int_cst (NULL_TREE
, shift
),
1947 bytelen
= ssize
- bytepos
;
1950 if (GET_CODE (dst
) == CONCAT
)
1952 if (bytepos
+ bytelen
<= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
1953 dest
= XEXP (dst
, 0);
1954 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
1956 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
1957 dest
= XEXP (dst
, 1);
1961 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
1962 dest
= assign_stack_temp (GET_MODE (dest
),
1963 GET_MODE_SIZE (GET_MODE (dest
)), 0);
1964 emit_move_insn (adjust_address (dest
, GET_MODE (tmps
[i
]), bytepos
),
1971 /* Optimize the access just a bit. */
1973 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
1974 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
1975 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1976 && bytelen
== GET_MODE_SIZE (mode
))
1977 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
1979 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
1983 /* Copy from the pseudo into the (probable) hard reg. */
1984 if (orig_dst
!= dst
)
1985 emit_move_insn (orig_dst
, dst
);
1988 /* Generate code to copy a BLKmode object of TYPE out of a
1989 set of registers starting with SRCREG into TGTBLK. If TGTBLK
1990 is null, a stack temporary is created. TGTBLK is returned.
1992 The purpose of this routine is to handle functions that return
1993 BLKmode structures in registers. Some machines (the PA for example)
1994 want to return all small structures in registers regardless of the
1995 structure's alignment. */
1998 copy_blkmode_from_reg (rtx tgtblk
, rtx srcreg
, tree type
)
2000 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2001 rtx src
= NULL
, dst
= NULL
;
2002 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2003 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2007 tgtblk
= assign_temp (build_qualified_type (type
,
2009 | TYPE_QUAL_CONST
)),
2011 preserve_temp_slots (tgtblk
);
2014 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2015 into a new pseudo which is a full word. */
2017 if (GET_MODE (srcreg
) != BLKmode
2018 && GET_MODE_SIZE (GET_MODE (srcreg
)) < UNITS_PER_WORD
)
2019 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2021 /* If the structure doesn't take up a whole number of words, see whether
2022 SRCREG is padded on the left or on the right. If it's on the left,
2023 set PADDING_CORRECTION to the number of bits to skip.
2025 In most ABIs, the structure will be returned at the least end of
2026 the register, which translates to right padding on little-endian
2027 targets and left padding on big-endian targets. The opposite
2028 holds if the structure is returned at the most significant
2029 end of the register. */
2030 if (bytes
% UNITS_PER_WORD
!= 0
2031 && (targetm
.calls
.return_in_msb (type
)
2033 : BYTES_BIG_ENDIAN
))
2035 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2037 /* Copy the structure BITSIZE bites at a time.
2039 We could probably emit more efficient code for machines which do not use
2040 strict alignment, but it doesn't seem worth the effort at the current
2042 for (bitpos
= 0, xbitpos
= padding_correction
;
2043 bitpos
< bytes
* BITS_PER_UNIT
;
2044 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2046 /* We need a new source operand each time xbitpos is on a
2047 word boundary and when xbitpos == padding_correction
2048 (the first time through). */
2049 if (xbitpos
% BITS_PER_WORD
== 0
2050 || xbitpos
== padding_correction
)
2051 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
,
2054 /* We need a new destination operand each time bitpos is on
2056 if (bitpos
% BITS_PER_WORD
== 0)
2057 dst
= operand_subword (tgtblk
, bitpos
/ BITS_PER_WORD
, 1, BLKmode
);
2059 /* Use xbitpos for the source extraction (right justified) and
2060 xbitpos for the destination store (left justified). */
2061 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, word_mode
,
2062 extract_bit_field (src
, bitsize
,
2063 xbitpos
% BITS_PER_WORD
, 1,
2064 NULL_RTX
, word_mode
, word_mode
));
2070 /* Add a USE expression for REG to the (possibly empty) list pointed
2071 to by CALL_FUSAGE. REG must denote a hard register. */
2074 use_reg (rtx
*call_fusage
, rtx reg
)
2076 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2079 = gen_rtx_EXPR_LIST (VOIDmode
,
2080 gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2083 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2084 starting at REGNO. All of these registers must be hard registers. */
2087 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2091 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2093 for (i
= 0; i
< nregs
; i
++)
2094 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2097 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2098 PARALLEL REGS. This is for calls that pass values in multiple
2099 non-contiguous locations. The Irix 6 ABI has examples of this. */
2102 use_group_regs (rtx
*call_fusage
, rtx regs
)
2106 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2108 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2110 /* A NULL entry means the parameter goes both on the stack and in
2111 registers. This can also be a MEM for targets that pass values
2112 partially on the stack and partially in registers. */
2113 if (reg
!= 0 && REG_P (reg
))
2114 use_reg (call_fusage
, reg
);
2119 /* Determine whether the LEN bytes generated by CONSTFUN can be
2120 stored to memory using several move instructions. CONSTFUNDATA is
2121 a pointer which will be passed as argument in every CONSTFUN call.
2122 ALIGN is maximum alignment we can assume. Return nonzero if a
2123 call to store_by_pieces should succeed. */
2126 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2127 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2128 void *constfundata
, unsigned int align
)
2130 unsigned HOST_WIDE_INT l
;
2131 unsigned int max_size
;
2132 HOST_WIDE_INT offset
= 0;
2133 enum machine_mode mode
, tmode
;
2134 enum insn_code icode
;
2141 if (! STORE_BY_PIECES_P (len
, align
))
2144 tmode
= mode_for_size (STORE_MAX_PIECES
* BITS_PER_UNIT
, MODE_INT
, 1);
2145 if (align
>= GET_MODE_ALIGNMENT (tmode
))
2146 align
= GET_MODE_ALIGNMENT (tmode
);
2149 enum machine_mode xmode
;
2151 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
2153 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
2154 if (GET_MODE_SIZE (tmode
) > STORE_MAX_PIECES
2155 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
2158 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
2161 /* We would first store what we can in the largest integer mode, then go to
2162 successively smaller modes. */
2165 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2170 max_size
= STORE_MAX_PIECES
+ 1;
2171 while (max_size
> 1)
2173 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2174 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
2175 if (GET_MODE_SIZE (tmode
) < max_size
)
2178 if (mode
== VOIDmode
)
2181 icode
= mov_optab
->handlers
[(int) mode
].insn_code
;
2182 if (icode
!= CODE_FOR_nothing
2183 && align
>= GET_MODE_ALIGNMENT (mode
))
2185 unsigned int size
= GET_MODE_SIZE (mode
);
2192 cst
= (*constfun
) (constfundata
, offset
, mode
);
2193 if (!LEGITIMATE_CONSTANT_P (cst
))
2203 max_size
= GET_MODE_SIZE (mode
);
2206 /* The code above should have handled everything. */
2213 /* Generate several move instructions to store LEN bytes generated by
2214 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2215 pointer which will be passed as argument in every CONSTFUN call.
2216 ALIGN is maximum alignment we can assume.
2217 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2218 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2222 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2223 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2224 void *constfundata
, unsigned int align
, int endp
)
2226 struct store_by_pieces data
;
2230 gcc_assert (endp
!= 2);
2234 gcc_assert (STORE_BY_PIECES_P (len
, align
));
2235 data
.constfun
= constfun
;
2236 data
.constfundata
= constfundata
;
2239 store_by_pieces_1 (&data
, align
);
2244 gcc_assert (!data
.reverse
);
2249 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2250 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2252 data
.to_addr
= copy_addr_to_reg (plus_constant (data
.to_addr
,
2255 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2262 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2270 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2271 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2274 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2276 struct store_by_pieces data
;
2281 data
.constfun
= clear_by_pieces_1
;
2282 data
.constfundata
= NULL
;
2285 store_by_pieces_1 (&data
, align
);
2288 /* Callback routine for clear_by_pieces.
2289 Return const0_rtx unconditionally. */
2292 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2293 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2294 enum machine_mode mode ATTRIBUTE_UNUSED
)
2299 /* Subroutine of clear_by_pieces and store_by_pieces.
2300 Generate several move instructions to store LEN bytes of block TO. (A MEM
2301 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2304 store_by_pieces_1 (struct store_by_pieces
*data ATTRIBUTE_UNUSED
,
2305 unsigned int align ATTRIBUTE_UNUSED
)
2307 rtx to_addr
= XEXP (data
->to
, 0);
2308 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2309 enum machine_mode mode
= VOIDmode
, tmode
;
2310 enum insn_code icode
;
2313 data
->to_addr
= to_addr
;
2315 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2316 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2318 data
->explicit_inc_to
= 0;
2320 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2322 data
->offset
= data
->len
;
2324 /* If storing requires more than two move insns,
2325 copy addresses to registers (to make displacements shorter)
2326 and use post-increment if available. */
2327 if (!data
->autinc_to
2328 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2330 /* Determine the main mode we'll be using. */
2331 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2332 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
2333 if (GET_MODE_SIZE (tmode
) < max_size
)
2336 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2338 data
->to_addr
= copy_addr_to_reg (plus_constant (to_addr
, data
->len
));
2339 data
->autinc_to
= 1;
2340 data
->explicit_inc_to
= -1;
2343 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2344 && ! data
->autinc_to
)
2346 data
->to_addr
= copy_addr_to_reg (to_addr
);
2347 data
->autinc_to
= 1;
2348 data
->explicit_inc_to
= 1;
2351 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2352 data
->to_addr
= copy_addr_to_reg (to_addr
);
2355 tmode
= mode_for_size (STORE_MAX_PIECES
* BITS_PER_UNIT
, MODE_INT
, 1);
2356 if (align
>= GET_MODE_ALIGNMENT (tmode
))
2357 align
= GET_MODE_ALIGNMENT (tmode
);
2360 enum machine_mode xmode
;
2362 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
2364 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
2365 if (GET_MODE_SIZE (tmode
) > STORE_MAX_PIECES
2366 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
2369 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
2372 /* First store what we can in the largest integer mode, then go to
2373 successively smaller modes. */
2375 while (max_size
> 1)
2377 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2378 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
2379 if (GET_MODE_SIZE (tmode
) < max_size
)
2382 if (mode
== VOIDmode
)
2385 icode
= mov_optab
->handlers
[(int) mode
].insn_code
;
2386 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2387 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2389 max_size
= GET_MODE_SIZE (mode
);
2392 /* The code above should have handled everything. */
2393 gcc_assert (!data
->len
);
2396 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2397 with move instructions for mode MODE. GENFUN is the gen_... function
2398 to make a move insn for that mode. DATA has all the other info. */
2401 store_by_pieces_2 (rtx (*genfun
) (rtx
, ...), enum machine_mode mode
,
2402 struct store_by_pieces
*data
)
2404 unsigned int size
= GET_MODE_SIZE (mode
);
2407 while (data
->len
>= size
)
2410 data
->offset
-= size
;
2412 if (data
->autinc_to
)
2413 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2416 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2418 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2419 emit_insn (gen_add2_insn (data
->to_addr
,
2420 GEN_INT (-(HOST_WIDE_INT
) size
)));
2422 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2423 emit_insn ((*genfun
) (to1
, cst
));
2425 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2426 emit_insn (gen_add2_insn (data
->to_addr
, GEN_INT (size
)));
2428 if (! data
->reverse
)
2429 data
->offset
+= size
;
2435 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2436 its length in bytes. */
2439 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2441 enum machine_mode mode
= GET_MODE (object
);
2444 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2446 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2447 just move a zero. Otherwise, do this a piece at a time. */
2449 && GET_CODE (size
) == CONST_INT
2450 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2452 rtx zero
= CONST0_RTX (mode
);
2455 emit_move_insn (object
, zero
);
2459 if (COMPLEX_MODE_P (mode
))
2461 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2464 write_complex_part (object
, zero
, 0);
2465 write_complex_part (object
, zero
, 1);
2471 if (size
== const0_rtx
)
2474 align
= MEM_ALIGN (object
);
2476 if (GET_CODE (size
) == CONST_INT
2477 && CLEAR_BY_PIECES_P (INTVAL (size
), align
))
2478 clear_by_pieces (object
, INTVAL (size
), align
);
2479 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
))
2482 return clear_storage_via_libcall (object
, size
,
2483 method
== BLOCK_OP_TAILCALL
);
2488 /* A subroutine of clear_storage. Expand a call to memset.
2489 Return the return value of memset, 0 otherwise. */
2492 clear_storage_via_libcall (rtx object
, rtx size
, bool tailcall
)
2494 tree call_expr
, arg_list
, fn
, object_tree
, size_tree
;
2495 enum machine_mode size_mode
;
2498 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2499 place those into new pseudos into a VAR_DECL and use them later. */
2501 object
= copy_to_mode_reg (Pmode
, XEXP (object
, 0));
2503 size_mode
= TYPE_MODE (sizetype
);
2504 size
= convert_to_mode (size_mode
, size
, 1);
2505 size
= copy_to_mode_reg (size_mode
, size
);
2507 /* It is incorrect to use the libcall calling conventions to call
2508 memset in this context. This could be a user call to memset and
2509 the user may wish to examine the return value from memset. For
2510 targets where libcalls and normal calls have different conventions
2511 for returning pointers, we could end up generating incorrect code. */
2513 object_tree
= make_tree (ptr_type_node
, object
);
2514 size_tree
= make_tree (sizetype
, size
);
2516 fn
= clear_storage_libcall_fn (true);
2517 arg_list
= tree_cons (NULL_TREE
, size_tree
, NULL_TREE
);
2518 arg_list
= tree_cons (NULL_TREE
, integer_zero_node
, arg_list
);
2519 arg_list
= tree_cons (NULL_TREE
, object_tree
, arg_list
);
2521 /* Now we have to build up the CALL_EXPR itself. */
2522 call_expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (fn
)), fn
);
2523 call_expr
= build3 (CALL_EXPR
, TREE_TYPE (TREE_TYPE (fn
)),
2524 call_expr
, arg_list
, NULL_TREE
);
2525 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2527 retval
= expand_expr (call_expr
, NULL_RTX
, VOIDmode
, 0);
2532 /* A subroutine of clear_storage_via_libcall. Create the tree node
2533 for the function we use for block clears. The first time FOR_CALL
2534 is true, we call assemble_external. */
2536 static GTY(()) tree block_clear_fn
;
2539 init_block_clear_fn (const char *asmspec
)
2541 if (!block_clear_fn
)
2545 fn
= get_identifier ("memset");
2546 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2547 integer_type_node
, sizetype
,
2550 fn
= build_decl (FUNCTION_DECL
, fn
, args
);
2551 DECL_EXTERNAL (fn
) = 1;
2552 TREE_PUBLIC (fn
) = 1;
2553 DECL_ARTIFICIAL (fn
) = 1;
2554 TREE_NOTHROW (fn
) = 1;
2555 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2556 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2558 block_clear_fn
= fn
;
2562 set_user_assembler_name (block_clear_fn
, asmspec
);
2566 clear_storage_libcall_fn (int for_call
)
2568 static bool emitted_extern
;
2570 if (!block_clear_fn
)
2571 init_block_clear_fn (NULL
);
2573 if (for_call
&& !emitted_extern
)
2575 emitted_extern
= true;
2576 make_decl_rtl (block_clear_fn
);
2577 assemble_external (block_clear_fn
);
2580 return block_clear_fn
;
2583 /* Expand a setmem pattern; return true if successful. */
2586 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
)
2588 /* Try the most limited insn first, because there's no point
2589 including more than one in the machine description unless
2590 the more limited one has some advantage. */
2592 rtx opalign
= GEN_INT (align
/ BITS_PER_UNIT
);
2593 enum machine_mode mode
;
2595 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2596 mode
= GET_MODE_WIDER_MODE (mode
))
2598 enum insn_code code
= setmem_optab
[(int) mode
];
2599 insn_operand_predicate_fn pred
;
2601 if (code
!= CODE_FOR_nothing
2602 /* We don't need MODE to be narrower than
2603 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2604 the mode mask, as it is returned by the macro, it will
2605 definitely be less than the actual mode mask. */
2606 && ((GET_CODE (size
) == CONST_INT
2607 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2608 <= (GET_MODE_MASK (mode
) >> 1)))
2609 || GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
)
2610 && ((pred
= insn_data
[(int) code
].operand
[0].predicate
) == 0
2611 || (*pred
) (object
, BLKmode
))
2612 && ((pred
= insn_data
[(int) code
].operand
[3].predicate
) == 0
2613 || (*pred
) (opalign
, VOIDmode
)))
2616 enum machine_mode char_mode
;
2617 rtx last
= get_last_insn ();
2620 opsize
= convert_to_mode (mode
, size
, 1);
2621 pred
= insn_data
[(int) code
].operand
[1].predicate
;
2622 if (pred
!= 0 && ! (*pred
) (opsize
, mode
))
2623 opsize
= copy_to_mode_reg (mode
, opsize
);
2626 char_mode
= insn_data
[(int) code
].operand
[2].mode
;
2627 if (char_mode
!= VOIDmode
)
2629 opchar
= convert_to_mode (char_mode
, opchar
, 1);
2630 pred
= insn_data
[(int) code
].operand
[2].predicate
;
2631 if (pred
!= 0 && ! (*pred
) (opchar
, char_mode
))
2632 opchar
= copy_to_mode_reg (char_mode
, opchar
);
2635 pat
= GEN_FCN ((int) code
) (object
, opsize
, opchar
, opalign
);
2642 delete_insns_since (last
);
2650 /* Write to one of the components of the complex value CPLX. Write VAL to
2651 the real part if IMAG_P is false, and the imaginary part if its true. */
2654 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
2656 enum machine_mode cmode
;
2657 enum machine_mode imode
;
2660 if (GET_CODE (cplx
) == CONCAT
)
2662 emit_move_insn (XEXP (cplx
, imag_p
), val
);
2666 cmode
= GET_MODE (cplx
);
2667 imode
= GET_MODE_INNER (cmode
);
2668 ibitsize
= GET_MODE_BITSIZE (imode
);
2670 /* For MEMs simplify_gen_subreg may generate an invalid new address
2671 because, e.g., the original address is considered mode-dependent
2672 by the target, which restricts simplify_subreg from invoking
2673 adjust_address_nv. Instead of preparing fallback support for an
2674 invalid address, we call adjust_address_nv directly. */
2677 emit_move_insn (adjust_address_nv (cplx
, imode
,
2678 imag_p
? GET_MODE_SIZE (imode
) : 0),
2683 /* If the sub-object is at least word sized, then we know that subregging
2684 will work. This special case is important, since store_bit_field
2685 wants to operate on integer modes, and there's rarely an OImode to
2686 correspond to TCmode. */
2687 if (ibitsize
>= BITS_PER_WORD
2688 /* For hard regs we have exact predicates. Assume we can split
2689 the original object if it spans an even number of hard regs.
2690 This special case is important for SCmode on 64-bit platforms
2691 where the natural size of floating-point regs is 32-bit. */
2693 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
2694 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
2696 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
2697 imag_p
? GET_MODE_SIZE (imode
) : 0);
2700 emit_move_insn (part
, val
);
2704 /* simplify_gen_subreg may fail for sub-word MEMs. */
2705 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
2708 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, imode
, val
);
2711 /* Extract one of the components of the complex value CPLX. Extract the
2712 real part if IMAG_P is false, and the imaginary part if it's true. */
2715 read_complex_part (rtx cplx
, bool imag_p
)
2717 enum machine_mode cmode
, imode
;
2720 if (GET_CODE (cplx
) == CONCAT
)
2721 return XEXP (cplx
, imag_p
);
2723 cmode
= GET_MODE (cplx
);
2724 imode
= GET_MODE_INNER (cmode
);
2725 ibitsize
= GET_MODE_BITSIZE (imode
);
2727 /* Special case reads from complex constants that got spilled to memory. */
2728 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
2730 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
2731 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
2733 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
2734 if (CONSTANT_CLASS_P (part
))
2735 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
2739 /* For MEMs simplify_gen_subreg may generate an invalid new address
2740 because, e.g., the original address is considered mode-dependent
2741 by the target, which restricts simplify_subreg from invoking
2742 adjust_address_nv. Instead of preparing fallback support for an
2743 invalid address, we call adjust_address_nv directly. */
2745 return adjust_address_nv (cplx
, imode
,
2746 imag_p
? GET_MODE_SIZE (imode
) : 0);
2748 /* If the sub-object is at least word sized, then we know that subregging
2749 will work. This special case is important, since extract_bit_field
2750 wants to operate on integer modes, and there's rarely an OImode to
2751 correspond to TCmode. */
2752 if (ibitsize
>= BITS_PER_WORD
2753 /* For hard regs we have exact predicates. Assume we can split
2754 the original object if it spans an even number of hard regs.
2755 This special case is important for SCmode on 64-bit platforms
2756 where the natural size of floating-point regs is 32-bit. */
2758 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
2759 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
2761 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
2762 imag_p
? GET_MODE_SIZE (imode
) : 0);
2766 /* simplify_gen_subreg may fail for sub-word MEMs. */
2767 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
2770 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
2771 true, NULL_RTX
, imode
, imode
);
2774 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
2775 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
2776 represented in NEW_MODE. If FORCE is true, this will never happen, as
2777 we'll force-create a SUBREG if needed. */
2780 emit_move_change_mode (enum machine_mode new_mode
,
2781 enum machine_mode old_mode
, rtx x
, bool force
)
2785 if (reload_in_progress
&& MEM_P (x
))
2787 /* We can't use gen_lowpart here because it may call change_address
2788 which is not appropriate if we were called when a reload was in
2789 progress. We don't have to worry about changing the address since
2790 the size in bytes is supposed to be the same. Copy the MEM to
2791 change the mode and move any substitutions from the old MEM to
2794 ret
= adjust_address_nv (x
, new_mode
, 0);
2795 copy_replacements (x
, ret
);
2799 /* Note that we do want simplify_subreg's behavior of validating
2800 that the new mode is ok for a hard register. If we were to use
2801 simplify_gen_subreg, we would create the subreg, but would
2802 probably run into the target not being able to implement it. */
2803 /* Except, of course, when FORCE is true, when this is exactly what
2804 we want. Which is needed for CCmodes on some targets. */
2806 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
2808 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
2814 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
2815 an integer mode of the same size as MODE. Returns the instruction
2816 emitted, or NULL if such a move could not be generated. */
2819 emit_move_via_integer (enum machine_mode mode
, rtx x
, rtx y
, bool force
)
2821 enum machine_mode imode
;
2822 enum insn_code code
;
2824 /* There must exist a mode of the exact size we require. */
2825 imode
= int_mode_for_mode (mode
);
2826 if (imode
== BLKmode
)
2829 /* The target must support moves in this mode. */
2830 code
= mov_optab
->handlers
[imode
].insn_code
;
2831 if (code
== CODE_FOR_nothing
)
2834 x
= emit_move_change_mode (imode
, mode
, x
, force
);
2837 y
= emit_move_change_mode (imode
, mode
, y
, force
);
2840 return emit_insn (GEN_FCN (code
) (x
, y
));
2843 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
2844 Return an equivalent MEM that does not use an auto-increment. */
2847 emit_move_resolve_push (enum machine_mode mode
, rtx x
)
2849 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
2850 HOST_WIDE_INT adjust
;
2853 adjust
= GET_MODE_SIZE (mode
);
2854 #ifdef PUSH_ROUNDING
2855 adjust
= PUSH_ROUNDING (adjust
);
2857 if (code
== PRE_DEC
|| code
== POST_DEC
)
2859 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
2861 rtx expr
= XEXP (XEXP (x
, 0), 1);
2864 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
2865 gcc_assert (GET_CODE (XEXP (expr
, 1)) == CONST_INT
);
2866 val
= INTVAL (XEXP (expr
, 1));
2867 if (GET_CODE (expr
) == MINUS
)
2869 gcc_assert (adjust
== val
|| adjust
== -val
);
2873 /* Do not use anti_adjust_stack, since we don't want to update
2874 stack_pointer_delta. */
2875 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
2876 GEN_INT (adjust
), stack_pointer_rtx
,
2877 0, OPTAB_LIB_WIDEN
);
2878 if (temp
!= stack_pointer_rtx
)
2879 emit_move_insn (stack_pointer_rtx
, temp
);
2886 temp
= stack_pointer_rtx
;
2891 temp
= plus_constant (stack_pointer_rtx
, -adjust
);
2897 return replace_equiv_address (x
, temp
);
2900 /* A subroutine of emit_move_complex. Generate a move from Y into X.
2901 X is known to satisfy push_operand, and MODE is known to be complex.
2902 Returns the last instruction emitted. */
2905 emit_move_complex_push (enum machine_mode mode
, rtx x
, rtx y
)
2907 enum machine_mode submode
= GET_MODE_INNER (mode
);
2910 #ifdef PUSH_ROUNDING
2911 unsigned int submodesize
= GET_MODE_SIZE (submode
);
2913 /* In case we output to the stack, but the size is smaller than the
2914 machine can push exactly, we need to use move instructions. */
2915 if (PUSH_ROUNDING (submodesize
) != submodesize
)
2917 x
= emit_move_resolve_push (mode
, x
);
2918 return emit_move_insn (x
, y
);
2922 /* Note that the real part always precedes the imag part in memory
2923 regardless of machine's endianness. */
2924 switch (GET_CODE (XEXP (x
, 0)))
2938 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
2939 read_complex_part (y
, imag_first
));
2940 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
2941 read_complex_part (y
, !imag_first
));
2944 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
2945 MODE is known to be complex. Returns the last instruction emitted. */
2948 emit_move_complex (enum machine_mode mode
, rtx x
, rtx y
)
2952 /* Need to take special care for pushes, to maintain proper ordering
2953 of the data, and possibly extra padding. */
2954 if (push_operand (x
, mode
))
2955 return emit_move_complex_push (mode
, x
, y
);
2957 /* See if we can coerce the target into moving both values at once. */
2959 /* Move floating point as parts. */
2960 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
2961 && mov_optab
->handlers
[GET_MODE_INNER (mode
)].insn_code
!= CODE_FOR_nothing
)
2963 /* Not possible if the values are inherently not adjacent. */
2964 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
2966 /* Is possible if both are registers (or subregs of registers). */
2967 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
2969 /* If one of the operands is a memory, and alignment constraints
2970 are friendly enough, we may be able to do combined memory operations.
2971 We do not attempt this if Y is a constant because that combination is
2972 usually better with the by-parts thing below. */
2973 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
2974 && (!STRICT_ALIGNMENT
2975 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
2984 /* For memory to memory moves, optimal behavior can be had with the
2985 existing block move logic. */
2986 if (MEM_P (x
) && MEM_P (y
))
2988 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
2989 BLOCK_OP_NO_LIBCALL
);
2990 return get_last_insn ();
2993 ret
= emit_move_via_integer (mode
, x
, y
, true);
2998 /* Show the output dies here. This is necessary for SUBREGs
2999 of pseudos since we cannot track their lifetimes correctly;
3000 hard regs shouldn't appear here except as return values. */
3001 if (!reload_completed
&& !reload_in_progress
3002 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3003 emit_insn (gen_rtx_CLOBBER (VOIDmode
, x
));
3005 write_complex_part (x
, read_complex_part (y
, false), false);
3006 write_complex_part (x
, read_complex_part (y
, true), true);
3007 return get_last_insn ();
3010 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3011 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3014 emit_move_ccmode (enum machine_mode mode
, rtx x
, rtx y
)
3018 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3021 enum insn_code code
= mov_optab
->handlers
[CCmode
].insn_code
;
3022 if (code
!= CODE_FOR_nothing
)
3024 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3025 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3026 return emit_insn (GEN_FCN (code
) (x
, y
));
3030 /* Otherwise, find the MODE_INT mode of the same width. */
3031 ret
= emit_move_via_integer (mode
, x
, y
, false);
3032 gcc_assert (ret
!= NULL
);
3036 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3037 MODE is any multi-word or full-word mode that lacks a move_insn
3038 pattern. Note that you will get better code if you define such
3039 patterns, even if they must turn into multiple assembler instructions. */
3042 emit_move_multi_word (enum machine_mode mode
, rtx x
, rtx y
)
3049 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3051 /* If X is a push on the stack, do the push now and replace
3052 X with a reference to the stack pointer. */
3053 if (push_operand (x
, mode
))
3054 x
= emit_move_resolve_push (mode
, x
);
3056 /* If we are in reload, see if either operand is a MEM whose address
3057 is scheduled for replacement. */
3058 if (reload_in_progress
&& MEM_P (x
)
3059 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3060 x
= replace_equiv_address_nv (x
, inner
);
3061 if (reload_in_progress
&& MEM_P (y
)
3062 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3063 y
= replace_equiv_address_nv (y
, inner
);
3067 need_clobber
= false;
3069 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3072 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3073 rtx ypart
= operand_subword (y
, i
, 1, mode
);
3075 /* If we can't get a part of Y, put Y into memory if it is a
3076 constant. Otherwise, force it into a register. Then we must
3077 be able to get a part of Y. */
3078 if (ypart
== 0 && CONSTANT_P (y
))
3080 y
= force_const_mem (mode
, y
);
3081 ypart
= operand_subword (y
, i
, 1, mode
);
3083 else if (ypart
== 0)
3084 ypart
= operand_subword_force (y
, i
, mode
);
3086 gcc_assert (xpart
&& ypart
);
3088 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3090 last_insn
= emit_move_insn (xpart
, ypart
);
3096 /* Show the output dies here. This is necessary for SUBREGs
3097 of pseudos since we cannot track their lifetimes correctly;
3098 hard regs shouldn't appear here except as return values.
3099 We never want to emit such a clobber after reload. */
3101 && ! (reload_in_progress
|| reload_completed
)
3102 && need_clobber
!= 0)
3103 emit_insn (gen_rtx_CLOBBER (VOIDmode
, x
));
3110 /* Low level part of emit_move_insn.
3111 Called just like emit_move_insn, but assumes X and Y
3112 are basically valid. */
3115 emit_move_insn_1 (rtx x
, rtx y
)
3117 enum machine_mode mode
= GET_MODE (x
);
3118 enum insn_code code
;
3120 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3122 code
= mov_optab
->handlers
[mode
].insn_code
;
3123 if (code
!= CODE_FOR_nothing
)
3124 return emit_insn (GEN_FCN (code
) (x
, y
));
3126 /* Expand complex moves by moving real part and imag part. */
3127 if (COMPLEX_MODE_P (mode
))
3128 return emit_move_complex (mode
, x
, y
);
3130 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3131 return emit_move_ccmode (mode
, x
, y
);
3133 /* Try using a move pattern for the corresponding integer mode. This is
3134 only safe when simplify_subreg can convert MODE constants into integer
3135 constants. At present, it can only do this reliably if the value
3136 fits within a HOST_WIDE_INT. */
3137 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3139 rtx ret
= emit_move_via_integer (mode
, x
, y
, false);
3144 return emit_move_multi_word (mode
, x
, y
);
3147 /* Generate code to copy Y into X.
3148 Both Y and X must have the same mode, except that
3149 Y can be a constant with VOIDmode.
3150 This mode cannot be BLKmode; use emit_block_move for that.
3152 Return the last instruction emitted. */
3155 emit_move_insn (rtx x
, rtx y
)
3157 enum machine_mode mode
= GET_MODE (x
);
3158 rtx y_cst
= NULL_RTX
;
3161 gcc_assert (mode
!= BLKmode
3162 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3167 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3168 && (last_insn
= compress_float_constant (x
, y
)))
3173 if (!LEGITIMATE_CONSTANT_P (y
))
3175 y
= force_const_mem (mode
, y
);
3177 /* If the target's cannot_force_const_mem prevented the spill,
3178 assume that the target's move expanders will also take care
3179 of the non-legitimate constant. */
3185 /* If X or Y are memory references, verify that their addresses are valid
3188 && ((! memory_address_p (GET_MODE (x
), XEXP (x
, 0))
3189 && ! push_operand (x
, GET_MODE (x
)))
3191 && CONSTANT_ADDRESS_P (XEXP (x
, 0)))))
3192 x
= validize_mem (x
);
3195 && (! memory_address_p (GET_MODE (y
), XEXP (y
, 0))
3197 && CONSTANT_ADDRESS_P (XEXP (y
, 0)))))
3198 y
= validize_mem (y
);
3200 gcc_assert (mode
!= BLKmode
);
3202 last_insn
= emit_move_insn_1 (x
, y
);
3204 if (y_cst
&& REG_P (x
)
3205 && (set
= single_set (last_insn
)) != NULL_RTX
3206 && SET_DEST (set
) == x
3207 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3208 set_unique_reg_note (last_insn
, REG_EQUAL
, y_cst
);
3213 /* If Y is representable exactly in a narrower mode, and the target can
3214 perform the extension directly from constant or memory, then emit the
3215 move as an extension. */
3218 compress_float_constant (rtx x
, rtx y
)
3220 enum machine_mode dstmode
= GET_MODE (x
);
3221 enum machine_mode orig_srcmode
= GET_MODE (y
);
3222 enum machine_mode srcmode
;
3224 int oldcost
, newcost
;
3226 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3228 if (LEGITIMATE_CONSTANT_P (y
))
3229 oldcost
= rtx_cost (y
, SET
);
3231 oldcost
= rtx_cost (force_const_mem (dstmode
, y
), SET
);
3233 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3234 srcmode
!= orig_srcmode
;
3235 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3238 rtx trunc_y
, last_insn
;
3240 /* Skip if the target can't extend this way. */
3241 ic
= can_extend_p (dstmode
, srcmode
, 0);
3242 if (ic
== CODE_FOR_nothing
)
3245 /* Skip if the narrowed value isn't exact. */
3246 if (! exact_real_truncate (srcmode
, &r
))
3249 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3251 if (LEGITIMATE_CONSTANT_P (trunc_y
))
3253 /* Skip if the target needs extra instructions to perform
3255 if (! (*insn_data
[ic
].operand
[1].predicate
) (trunc_y
, srcmode
))
3257 /* This is valid, but may not be cheaper than the original. */
3258 newcost
= rtx_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
), SET
);
3259 if (oldcost
< newcost
)
3262 else if (float_extend_from_mem
[dstmode
][srcmode
])
3264 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3265 /* This is valid, but may not be cheaper than the original. */
3266 newcost
= rtx_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
), SET
);
3267 if (oldcost
< newcost
)
3269 trunc_y
= validize_mem (trunc_y
);
3274 emit_unop_insn (ic
, x
, trunc_y
, UNKNOWN
);
3275 last_insn
= get_last_insn ();
3278 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3286 /* Pushing data onto the stack. */
3288 /* Push a block of length SIZE (perhaps variable)
3289 and return an rtx to address the beginning of the block.
3290 The value may be virtual_outgoing_args_rtx.
3292 EXTRA is the number of bytes of padding to push in addition to SIZE.
3293 BELOW nonzero means this padding comes at low addresses;
3294 otherwise, the padding comes at high addresses. */
3297 push_block (rtx size
, int extra
, int below
)
3301 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3302 if (CONSTANT_P (size
))
3303 anti_adjust_stack (plus_constant (size
, extra
));
3304 else if (REG_P (size
) && extra
== 0)
3305 anti_adjust_stack (size
);
3308 temp
= copy_to_mode_reg (Pmode
, size
);
3310 temp
= expand_binop (Pmode
, add_optab
, temp
, GEN_INT (extra
),
3311 temp
, 0, OPTAB_LIB_WIDEN
);
3312 anti_adjust_stack (temp
);
3315 #ifndef STACK_GROWS_DOWNWARD
3321 temp
= virtual_outgoing_args_rtx
;
3322 if (extra
!= 0 && below
)
3323 temp
= plus_constant (temp
, extra
);
3327 if (GET_CODE (size
) == CONST_INT
)
3328 temp
= plus_constant (virtual_outgoing_args_rtx
,
3329 -INTVAL (size
) - (below
? 0 : extra
));
3330 else if (extra
!= 0 && !below
)
3331 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3332 negate_rtx (Pmode
, plus_constant (size
, extra
)));
3334 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3335 negate_rtx (Pmode
, size
));
3338 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3341 #ifdef PUSH_ROUNDING
3343 /* Emit single push insn. */
3346 emit_single_push_insn (enum machine_mode mode
, rtx x
, tree type
)
3349 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3351 enum insn_code icode
;
3352 insn_operand_predicate_fn pred
;
3354 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3355 /* If there is push pattern, use it. Otherwise try old way of throwing
3356 MEM representing push operation to move expander. */
3357 icode
= push_optab
->handlers
[(int) mode
].insn_code
;
3358 if (icode
!= CODE_FOR_nothing
)
3360 if (((pred
= insn_data
[(int) icode
].operand
[0].predicate
)
3361 && !((*pred
) (x
, mode
))))
3362 x
= force_reg (mode
, x
);
3363 emit_insn (GEN_FCN (icode
) (x
));
3366 if (GET_MODE_SIZE (mode
) == rounded_size
)
3367 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
3368 /* If we are to pad downward, adjust the stack pointer first and
3369 then store X into the stack location using an offset. This is
3370 because emit_move_insn does not know how to pad; it does not have
3372 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
3374 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
3375 HOST_WIDE_INT offset
;
3377 emit_move_insn (stack_pointer_rtx
,
3378 expand_binop (Pmode
,
3379 #ifdef STACK_GROWS_DOWNWARD
3385 GEN_INT (rounded_size
),
3386 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
3388 offset
= (HOST_WIDE_INT
) padding_size
;
3389 #ifdef STACK_GROWS_DOWNWARD
3390 if (STACK_PUSH_CODE
== POST_DEC
)
3391 /* We have already decremented the stack pointer, so get the
3393 offset
+= (HOST_WIDE_INT
) rounded_size
;
3395 if (STACK_PUSH_CODE
== POST_INC
)
3396 /* We have already incremented the stack pointer, so get the
3398 offset
-= (HOST_WIDE_INT
) rounded_size
;
3400 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, GEN_INT (offset
));
3404 #ifdef STACK_GROWS_DOWNWARD
3405 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3406 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3407 GEN_INT (-(HOST_WIDE_INT
) rounded_size
));
3409 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3410 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3411 GEN_INT (rounded_size
));
3413 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
3416 dest
= gen_rtx_MEM (mode
, dest_addr
);
3420 set_mem_attributes (dest
, type
, 1);
3422 if (flag_optimize_sibling_calls
)
3423 /* Function incoming arguments may overlap with sibling call
3424 outgoing arguments and we cannot allow reordering of reads
3425 from function arguments with stores to outgoing arguments
3426 of sibling calls. */
3427 set_mem_alias_set (dest
, 0);
3429 emit_move_insn (dest
, x
);
3433 /* Generate code to push X onto the stack, assuming it has mode MODE and
3435 MODE is redundant except when X is a CONST_INT (since they don't
3437 SIZE is an rtx for the size of data to be copied (in bytes),
3438 needed only if X is BLKmode.
3440 ALIGN (in bits) is maximum alignment we can assume.
3442 If PARTIAL and REG are both nonzero, then copy that many of the first
3443 bytes of X into registers starting with REG, and push the rest of X.
3444 The amount of space pushed is decreased by PARTIAL bytes.
3445 REG must be a hard register in this case.
3446 If REG is zero but PARTIAL is not, take any all others actions for an
3447 argument partially in registers, but do not actually load any
3450 EXTRA is the amount in bytes of extra space to leave next to this arg.
3451 This is ignored if an argument block has already been allocated.
3453 On a machine that lacks real push insns, ARGS_ADDR is the address of
3454 the bottom of the argument block for this call. We use indexing off there
3455 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3456 argument block has not been preallocated.
3458 ARGS_SO_FAR is the size of args previously pushed for this call.
3460 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3461 for arguments passed in registers. If nonzero, it will be the number
3462 of bytes required. */
3465 emit_push_insn (rtx x
, enum machine_mode mode
, tree type
, rtx size
,
3466 unsigned int align
, int partial
, rtx reg
, int extra
,
3467 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
3471 enum direction stack_direction
3472 #ifdef STACK_GROWS_DOWNWARD
3478 /* Decide where to pad the argument: `downward' for below,
3479 `upward' for above, or `none' for don't pad it.
3480 Default is below for small data on big-endian machines; else above. */
3481 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
3483 /* Invert direction if stack is post-decrement.
3485 if (STACK_PUSH_CODE
== POST_DEC
)
3486 if (where_pad
!= none
)
3487 where_pad
= (where_pad
== downward
? upward
: downward
);
3491 if (mode
== BLKmode
)
3493 /* Copy a block into the stack, entirely or partially. */
3500 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
3501 used
= partial
- offset
;
3505 /* USED is now the # of bytes we need not copy to the stack
3506 because registers will take care of them. */
3509 xinner
= adjust_address (xinner
, BLKmode
, used
);
3511 /* If the partial register-part of the arg counts in its stack size,
3512 skip the part of stack space corresponding to the registers.
3513 Otherwise, start copying to the beginning of the stack space,
3514 by setting SKIP to 0. */
3515 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
3517 #ifdef PUSH_ROUNDING
3518 /* Do it with several push insns if that doesn't take lots of insns
3519 and if there is no difficulty with push insns that skip bytes
3520 on the stack for alignment purposes. */
3523 && GET_CODE (size
) == CONST_INT
3525 && MEM_ALIGN (xinner
) >= align
3526 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size
) - used
, align
))
3527 /* Here we avoid the case of a structure whose weak alignment
3528 forces many pushes of a small amount of data,
3529 and such small pushes do rounding that causes trouble. */
3530 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
3531 || align
>= BIGGEST_ALIGNMENT
3532 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
3533 == (align
/ BITS_PER_UNIT
)))
3534 && PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
3536 /* Push padding now if padding above and stack grows down,
3537 or if padding below and stack grows up.
3538 But if space already allocated, this has already been done. */
3539 if (extra
&& args_addr
== 0
3540 && where_pad
!= none
&& where_pad
!= stack_direction
)
3541 anti_adjust_stack (GEN_INT (extra
));
3543 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
3546 #endif /* PUSH_ROUNDING */
3550 /* Otherwise make space on the stack and copy the data
3551 to the address of that space. */
3553 /* Deduct words put into registers from the size we must copy. */
3556 if (GET_CODE (size
) == CONST_INT
)
3557 size
= GEN_INT (INTVAL (size
) - used
);
3559 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
3560 GEN_INT (used
), NULL_RTX
, 0,
3564 /* Get the address of the stack space.
3565 In this case, we do not deal with EXTRA separately.
3566 A single stack adjust will do. */
3569 temp
= push_block (size
, extra
, where_pad
== downward
);
3572 else if (GET_CODE (args_so_far
) == CONST_INT
)
3573 temp
= memory_address (BLKmode
,
3574 plus_constant (args_addr
,
3575 skip
+ INTVAL (args_so_far
)));
3577 temp
= memory_address (BLKmode
,
3578 plus_constant (gen_rtx_PLUS (Pmode
,
3583 if (!ACCUMULATE_OUTGOING_ARGS
)
3585 /* If the source is referenced relative to the stack pointer,
3586 copy it to another register to stabilize it. We do not need
3587 to do this if we know that we won't be changing sp. */
3589 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
3590 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
3591 temp
= copy_to_reg (temp
);
3594 target
= gen_rtx_MEM (BLKmode
, temp
);
3596 /* We do *not* set_mem_attributes here, because incoming arguments
3597 may overlap with sibling call outgoing arguments and we cannot
3598 allow reordering of reads from function arguments with stores
3599 to outgoing arguments of sibling calls. We do, however, want
3600 to record the alignment of the stack slot. */
3601 /* ALIGN may well be better aligned than TYPE, e.g. due to
3602 PARM_BOUNDARY. Assume the caller isn't lying. */
3603 set_mem_align (target
, align
);
3605 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
3608 else if (partial
> 0)
3610 /* Scalar partly in registers. */
3612 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
3615 /* # bytes of start of argument
3616 that we must make space for but need not store. */
3617 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
3618 int args_offset
= INTVAL (args_so_far
);
3621 /* Push padding now if padding above and stack grows down,
3622 or if padding below and stack grows up.
3623 But if space already allocated, this has already been done. */
3624 if (extra
&& args_addr
== 0
3625 && where_pad
!= none
&& where_pad
!= stack_direction
)
3626 anti_adjust_stack (GEN_INT (extra
));
3628 /* If we make space by pushing it, we might as well push
3629 the real data. Otherwise, we can leave OFFSET nonzero
3630 and leave the space uninitialized. */
3634 /* Now NOT_STACK gets the number of words that we don't need to
3635 allocate on the stack. Convert OFFSET to words too. */
3636 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
3637 offset
/= UNITS_PER_WORD
;
3639 /* If the partial register-part of the arg counts in its stack size,
3640 skip the part of stack space corresponding to the registers.
3641 Otherwise, start copying to the beginning of the stack space,
3642 by setting SKIP to 0. */
3643 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
3645 if (CONSTANT_P (x
) && ! LEGITIMATE_CONSTANT_P (x
))
3646 x
= validize_mem (force_const_mem (mode
, x
));
3648 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
3649 SUBREGs of such registers are not allowed. */
3650 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
3651 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
3652 x
= copy_to_reg (x
);
3654 /* Loop over all the words allocated on the stack for this arg. */
3655 /* We can do it by words, because any scalar bigger than a word
3656 has a size a multiple of a word. */
3657 #ifndef PUSH_ARGS_REVERSED
3658 for (i
= not_stack
; i
< size
; i
++)
3660 for (i
= size
- 1; i
>= not_stack
; i
--)
3662 if (i
>= not_stack
+ offset
)
3663 emit_push_insn (operand_subword_force (x
, i
, mode
),
3664 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
3666 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
3668 reg_parm_stack_space
, alignment_pad
);
3675 /* Push padding now if padding above and stack grows down,
3676 or if padding below and stack grows up.
3677 But if space already allocated, this has already been done. */
3678 if (extra
&& args_addr
== 0
3679 && where_pad
!= none
&& where_pad
!= stack_direction
)
3680 anti_adjust_stack (GEN_INT (extra
));
3682 #ifdef PUSH_ROUNDING
3683 if (args_addr
== 0 && PUSH_ARGS
)
3684 emit_single_push_insn (mode
, x
, type
);
3688 if (GET_CODE (args_so_far
) == CONST_INT
)
3690 = memory_address (mode
,
3691 plus_constant (args_addr
,
3692 INTVAL (args_so_far
)));
3694 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
3696 dest
= gen_rtx_MEM (mode
, addr
);
3698 /* We do *not* set_mem_attributes here, because incoming arguments
3699 may overlap with sibling call outgoing arguments and we cannot
3700 allow reordering of reads from function arguments with stores
3701 to outgoing arguments of sibling calls. We do, however, want
3702 to record the alignment of the stack slot. */
3703 /* ALIGN may well be better aligned than TYPE, e.g. due to
3704 PARM_BOUNDARY. Assume the caller isn't lying. */
3705 set_mem_align (dest
, align
);
3707 emit_move_insn (dest
, x
);
3711 /* If part should go in registers, copy that part
3712 into the appropriate registers. Do this now, at the end,
3713 since mem-to-mem copies above may do function calls. */
3714 if (partial
> 0 && reg
!= 0)
3716 /* Handle calls that pass values in multiple non-contiguous locations.
3717 The Irix 6 ABI has examples of this. */
3718 if (GET_CODE (reg
) == PARALLEL
)
3719 emit_group_load (reg
, x
, type
, -1);
3722 gcc_assert (partial
% UNITS_PER_WORD
== 0);
3723 move_block_to_reg (REGNO (reg
), x
, partial
/ UNITS_PER_WORD
, mode
);
3727 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
3728 anti_adjust_stack (GEN_INT (extra
));
3730 if (alignment_pad
&& args_addr
== 0)
3731 anti_adjust_stack (alignment_pad
);
3734 /* Return X if X can be used as a subtarget in a sequence of arithmetic
3738 get_subtarget (rtx x
)
3742 /* Only registers can be subtargets. */
3744 /* Don't use hard regs to avoid extending their life. */
3745 || REGNO (x
) < FIRST_PSEUDO_REGISTER
3749 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
3750 FIELD is a bitfield. Returns true if the optimization was successful,
3751 and there's nothing else to do. */
3754 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
3755 unsigned HOST_WIDE_INT bitpos
,
3756 enum machine_mode mode1
, rtx str_rtx
,
3759 enum machine_mode str_mode
= GET_MODE (str_rtx
);
3760 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
3765 if (mode1
!= VOIDmode
3766 || bitsize
>= BITS_PER_WORD
3767 || str_bitsize
> BITS_PER_WORD
3768 || TREE_SIDE_EFFECTS (to
)
3769 || TREE_THIS_VOLATILE (to
))
3773 if (!BINARY_CLASS_P (src
)
3774 || TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
3777 op0
= TREE_OPERAND (src
, 0);
3778 op1
= TREE_OPERAND (src
, 1);
3781 if (!operand_equal_p (to
, op0
, 0))
3784 if (MEM_P (str_rtx
))
3786 unsigned HOST_WIDE_INT offset1
;
3788 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
3789 str_mode
= word_mode
;
3790 str_mode
= get_best_mode (bitsize
, bitpos
,
3791 MEM_ALIGN (str_rtx
), str_mode
, 0);
3792 if (str_mode
== VOIDmode
)
3794 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
3797 bitpos
%= str_bitsize
;
3798 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
3799 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
3801 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
3804 /* If the bit field covers the whole REG/MEM, store_field
3805 will likely generate better code. */
3806 if (bitsize
>= str_bitsize
)
3809 /* We can't handle fields split across multiple entities. */
3810 if (bitpos
+ bitsize
> str_bitsize
)
3813 if (BYTES_BIG_ENDIAN
)
3814 bitpos
= str_bitsize
- bitpos
- bitsize
;
3816 switch (TREE_CODE (src
))
3820 /* For now, just optimize the case of the topmost bitfield
3821 where we don't need to do any masking and also
3822 1 bit bitfields where xor can be used.
3823 We might win by one instruction for the other bitfields
3824 too if insv/extv instructions aren't used, so that
3825 can be added later. */
3826 if (bitpos
+ bitsize
!= str_bitsize
3827 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
3830 value
= expand_expr (op1
, NULL_RTX
, str_mode
, 0);
3831 value
= convert_modes (str_mode
,
3832 TYPE_MODE (TREE_TYPE (op1
)), value
,
3833 TYPE_UNSIGNED (TREE_TYPE (op1
)));
3835 /* We may be accessing data outside the field, which means
3836 we can alias adjacent data. */
3837 if (MEM_P (str_rtx
))
3839 str_rtx
= shallow_copy_rtx (str_rtx
);
3840 set_mem_alias_set (str_rtx
, 0);
3841 set_mem_expr (str_rtx
, 0);
3844 binop
= TREE_CODE (src
) == PLUS_EXPR
? add_optab
: sub_optab
;
3845 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
3847 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
3850 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
,
3851 build_int_cst (NULL_TREE
, bitpos
),
3853 result
= expand_binop (str_mode
, binop
, str_rtx
,
3854 value
, str_rtx
, 1, OPTAB_WIDEN
);
3855 if (result
!= str_rtx
)
3856 emit_move_insn (str_rtx
, result
);
3861 if (TREE_CODE (op1
) != INTEGER_CST
)
3863 value
= expand_expr (op1
, NULL_RTX
, GET_MODE (str_rtx
), 0);
3864 value
= convert_modes (GET_MODE (str_rtx
),
3865 TYPE_MODE (TREE_TYPE (op1
)), value
,
3866 TYPE_UNSIGNED (TREE_TYPE (op1
)));
3868 /* We may be accessing data outside the field, which means
3869 we can alias adjacent data. */
3870 if (MEM_P (str_rtx
))
3872 str_rtx
= shallow_copy_rtx (str_rtx
);
3873 set_mem_alias_set (str_rtx
, 0);
3874 set_mem_expr (str_rtx
, 0);
3877 binop
= TREE_CODE (src
) == BIT_IOR_EXPR
? ior_optab
: xor_optab
;
3878 if (bitpos
+ bitsize
!= GET_MODE_BITSIZE (GET_MODE (str_rtx
)))
3880 rtx mask
= GEN_INT (((unsigned HOST_WIDE_INT
) 1 << bitsize
)
3882 value
= expand_and (GET_MODE (str_rtx
), value
, mask
,
3885 value
= expand_shift (LSHIFT_EXPR
, GET_MODE (str_rtx
), value
,
3886 build_int_cst (NULL_TREE
, bitpos
),
3888 result
= expand_binop (GET_MODE (str_rtx
), binop
, str_rtx
,
3889 value
, str_rtx
, 1, OPTAB_WIDEN
);
3890 if (result
!= str_rtx
)
3891 emit_move_insn (str_rtx
, result
);
3902 /* Expand an assignment that stores the value of FROM into TO. */
3905 expand_assignment (tree to
, tree from
)
3910 /* Don't crash if the lhs of the assignment was erroneous. */
3912 if (TREE_CODE (to
) == ERROR_MARK
)
3914 result
= expand_expr (from
, NULL_RTX
, VOIDmode
, 0);
3918 /* Assignment of a structure component needs special treatment
3919 if the structure component's rtx is not simply a MEM.
3920 Assignment of an array element at a constant index, and assignment of
3921 an array element in an unaligned packed structure field, has the same
3923 if (handled_component_p (to
)
3924 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
3926 enum machine_mode mode1
;
3927 HOST_WIDE_INT bitsize
, bitpos
;
3934 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
3935 &unsignedp
, &volatilep
, true);
3937 /* If we are going to use store_bit_field and extract_bit_field,
3938 make sure to_rtx will be safe for multiple use. */
3940 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, 0);
3946 if (!MEM_P (to_rtx
))
3948 /* We can get constant negative offsets into arrays with broken
3949 user code. Translate this to a trap instead of ICEing. */
3950 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
3951 expand_builtin_trap ();
3952 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
3955 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
3956 #ifdef POINTERS_EXTEND_UNSIGNED
3957 if (GET_MODE (offset_rtx
) != Pmode
)
3958 offset_rtx
= convert_to_mode (Pmode
, offset_rtx
, 0);
3960 if (GET_MODE (offset_rtx
) != ptr_mode
)
3961 offset_rtx
= convert_to_mode (ptr_mode
, offset_rtx
, 0);
3964 /* A constant address in TO_RTX can have VOIDmode, we must not try
3965 to call force_reg for that case. Avoid that case. */
3967 && GET_MODE (to_rtx
) == BLKmode
3968 && GET_MODE (XEXP (to_rtx
, 0)) != VOIDmode
3970 && (bitpos
% bitsize
) == 0
3971 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
3972 && MEM_ALIGN (to_rtx
) == GET_MODE_ALIGNMENT (mode1
))
3974 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
3978 to_rtx
= offset_address (to_rtx
, offset_rtx
,
3979 highest_pow2_factor_for_target (to
,
3983 /* Handle expand_expr of a complex value returning a CONCAT. */
3984 if (GET_CODE (to_rtx
) == CONCAT
)
3986 if (TREE_CODE (TREE_TYPE (from
)) == COMPLEX_TYPE
)
3988 gcc_assert (bitpos
== 0);
3989 result
= store_expr (from
, to_rtx
, false);
3993 gcc_assert (bitpos
== 0 || bitpos
== GET_MODE_BITSIZE (mode1
));
3994 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false);
4001 /* If the field is at offset zero, we could have been given the
4002 DECL_RTX of the parent struct. Don't munge it. */
4003 to_rtx
= shallow_copy_rtx (to_rtx
);
4005 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
4007 /* Deal with volatile and readonly fields. The former is only
4008 done for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
4010 MEM_VOLATILE_P (to_rtx
) = 1;
4011 if (component_uses_parent_alias_set (to
))
4012 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
4015 if (optimize_bitfield_assignment_op (bitsize
, bitpos
, mode1
,
4019 result
= store_field (to_rtx
, bitsize
, bitpos
, mode1
, from
,
4020 TREE_TYPE (tem
), get_alias_set (to
));
4024 preserve_temp_slots (result
);
4030 /* If the rhs is a function call and its value is not an aggregate,
4031 call the function before we start to compute the lhs.
4032 This is needed for correct code for cases such as
4033 val = setjmp (buf) on machines where reference to val
4034 requires loading up part of an address in a separate insn.
4036 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4037 since it might be a promoted variable where the zero- or sign- extension
4038 needs to be done. Handling this in the normal way is safe because no
4039 computation is done before the call. */
4040 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
4041 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
4042 && ! ((TREE_CODE (to
) == VAR_DECL
|| TREE_CODE (to
) == PARM_DECL
)
4043 && REG_P (DECL_RTL (to
))))
4048 value
= expand_expr (from
, NULL_RTX
, VOIDmode
, 0);
4050 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4052 /* Handle calls that return values in multiple non-contiguous locations.
4053 The Irix 6 ABI has examples of this. */
4054 if (GET_CODE (to_rtx
) == PARALLEL
)
4055 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
4056 int_size_in_bytes (TREE_TYPE (from
)));
4057 else if (GET_MODE (to_rtx
) == BLKmode
)
4058 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
4061 if (POINTER_TYPE_P (TREE_TYPE (to
)))
4062 value
= convert_memory_address (GET_MODE (to_rtx
), value
);
4063 emit_move_insn (to_rtx
, value
);
4065 preserve_temp_slots (to_rtx
);
4071 /* Ordinary treatment. Expand TO to get a REG or MEM rtx.
4072 Don't re-expand if it was expanded already (in COMPONENT_REF case). */
4075 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4077 /* Don't move directly into a return register. */
4078 if (TREE_CODE (to
) == RESULT_DECL
4079 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
4084 temp
= expand_expr (from
, 0, GET_MODE (to_rtx
), 0);
4086 if (GET_CODE (to_rtx
) == PARALLEL
)
4087 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
4088 int_size_in_bytes (TREE_TYPE (from
)));
4090 emit_move_insn (to_rtx
, temp
);
4092 preserve_temp_slots (to_rtx
);
4098 /* In case we are returning the contents of an object which overlaps
4099 the place the value is being stored, use a safe function when copying
4100 a value through a pointer into a structure value return block. */
4101 if (TREE_CODE (to
) == RESULT_DECL
&& TREE_CODE (from
) == INDIRECT_REF
4102 && current_function_returns_struct
4103 && !current_function_returns_pcc_struct
)
4108 size
= expr_size (from
);
4109 from_rtx
= expand_expr (from
, NULL_RTX
, VOIDmode
, 0);
4111 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
4112 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
4113 XEXP (from_rtx
, 0), Pmode
,
4114 convert_to_mode (TYPE_MODE (sizetype
),
4115 size
, TYPE_UNSIGNED (sizetype
)),
4116 TYPE_MODE (sizetype
));
4118 preserve_temp_slots (to_rtx
);
4124 /* Compute FROM and store the value in the rtx we got. */
4127 result
= store_expr (from
, to_rtx
, 0);
4128 preserve_temp_slots (result
);
4134 /* Generate code for computing expression EXP,
4135 and storing the value into TARGET.
4137 If the mode is BLKmode then we may return TARGET itself.
4138 It turns out that in BLKmode it doesn't cause a problem.
4139 because C has no operators that could combine two different
4140 assignments into the same BLKmode object with different values
4141 with no sequence point. Will other languages need this to
4144 If CALL_PARAM_P is nonzero, this is a store into a call param on the
4145 stack, and block moves may need to be treated specially. */
4148 store_expr (tree exp
, rtx target
, int call_param_p
)
4151 rtx alt_rtl
= NULL_RTX
;
4152 int dont_return_target
= 0;
4154 if (VOID_TYPE_P (TREE_TYPE (exp
)))
4156 /* C++ can generate ?: expressions with a throw expression in one
4157 branch and an rvalue in the other. Here, we resolve attempts to
4158 store the throw expression's nonexistent result. */
4159 gcc_assert (!call_param_p
);
4160 expand_expr (exp
, const0_rtx
, VOIDmode
, 0);
4163 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
4165 /* Perform first part of compound expression, then assign from second
4167 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
4168 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
4169 return store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
);
4171 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
4173 /* For conditional expression, get safe form of the target. Then
4174 test the condition, doing the appropriate assignment on either
4175 side. This avoids the creation of unnecessary temporaries.
4176 For non-BLKmode, it is more efficient not to do this. */
4178 rtx lab1
= gen_label_rtx (), lab2
= gen_label_rtx ();
4180 do_pending_stack_adjust ();
4182 jumpifnot (TREE_OPERAND (exp
, 0), lab1
);
4183 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
);
4184 emit_jump_insn (gen_jump (lab2
));
4187 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
);
4193 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
4194 /* If this is a scalar in a register that is stored in a wider mode
4195 than the declared mode, compute the result into its declared mode
4196 and then convert to the wider mode. Our value is the computed
4199 rtx inner_target
= 0;
4201 /* We can do the conversion inside EXP, which will often result
4202 in some optimizations. Do the conversion in two steps: first
4203 change the signedness, if needed, then the extend. But don't
4204 do this if the type of EXP is a subtype of something else
4205 since then the conversion might involve more than just
4206 converting modes. */
4207 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
4208 && TREE_TYPE (TREE_TYPE (exp
)) == 0
4209 && (!lang_hooks
.reduce_bit_field_operations
4210 || (GET_MODE_PRECISION (GET_MODE (target
))
4211 == TYPE_PRECISION (TREE_TYPE (exp
)))))
4213 if (TYPE_UNSIGNED (TREE_TYPE (exp
))
4214 != SUBREG_PROMOTED_UNSIGNED_P (target
))
4216 (lang_hooks
.types
.signed_or_unsigned_type
4217 (SUBREG_PROMOTED_UNSIGNED_P (target
), TREE_TYPE (exp
)), exp
);
4219 exp
= convert (lang_hooks
.types
.type_for_mode
4220 (GET_MODE (SUBREG_REG (target
)),
4221 SUBREG_PROMOTED_UNSIGNED_P (target
)),
4224 inner_target
= SUBREG_REG (target
);
4227 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
4228 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
4230 /* If TEMP is a VOIDmode constant, use convert_modes to make
4231 sure that we properly convert it. */
4232 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
4234 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
4235 temp
, SUBREG_PROMOTED_UNSIGNED_P (target
));
4236 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
4237 GET_MODE (target
), temp
,
4238 SUBREG_PROMOTED_UNSIGNED_P (target
));
4241 convert_move (SUBREG_REG (target
), temp
,
4242 SUBREG_PROMOTED_UNSIGNED_P (target
));
4248 temp
= expand_expr_real (exp
, target
, GET_MODE (target
),
4250 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
4252 /* Return TARGET if it's a specified hardware register.
4253 If TARGET is a volatile mem ref, either return TARGET
4254 or return a reg copied *from* TARGET; ANSI requires this.
4256 Otherwise, if TEMP is not TARGET, return TEMP
4257 if it is constant (for efficiency),
4258 or if we really want the correct value. */
4259 if (!(target
&& REG_P (target
)
4260 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)
4261 && !(MEM_P (target
) && MEM_VOLATILE_P (target
))
4262 && ! rtx_equal_p (temp
, target
)
4263 && CONSTANT_P (temp
))
4264 dont_return_target
= 1;
4267 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
4268 the same as that of TARGET, adjust the constant. This is needed, for
4269 example, in case it is a CONST_DOUBLE and we want only a word-sized
4271 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
4272 && TREE_CODE (exp
) != ERROR_MARK
4273 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
4274 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
4275 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
4277 /* If value was not generated in the target, store it there.
4278 Convert the value to TARGET's type first if necessary and emit the
4279 pending incrementations that have been queued when expanding EXP.
4280 Note that we cannot emit the whole queue blindly because this will
4281 effectively disable the POST_INC optimization later.
4283 If TEMP and TARGET compare equal according to rtx_equal_p, but
4284 one or both of them are volatile memory refs, we have to distinguish
4286 - expand_expr has used TARGET. In this case, we must not generate
4287 another copy. This can be detected by TARGET being equal according
4289 - expand_expr has not used TARGET - that means that the source just
4290 happens to have the same RTX form. Since temp will have been created
4291 by expand_expr, it will compare unequal according to == .
4292 We must generate a copy in this case, to reach the correct number
4293 of volatile memory references. */
4295 if ((! rtx_equal_p (temp
, target
)
4296 || (temp
!= target
&& (side_effects_p (temp
)
4297 || side_effects_p (target
))))
4298 && TREE_CODE (exp
) != ERROR_MARK
4299 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
4300 but TARGET is not valid memory reference, TEMP will differ
4301 from TARGET although it is really the same location. */
4302 && !(alt_rtl
&& rtx_equal_p (alt_rtl
, target
))
4303 /* If there's nothing to copy, don't bother. Don't call
4304 expr_size unless necessary, because some front-ends (C++)
4305 expr_size-hook must not be given objects that are not
4306 supposed to be bit-copied or bit-initialized. */
4307 && expr_size (exp
) != const0_rtx
)
4309 if (GET_MODE (temp
) != GET_MODE (target
)
4310 && GET_MODE (temp
) != VOIDmode
)
4312 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
4313 if (dont_return_target
)
4315 /* In this case, we will return TEMP,
4316 so make sure it has the proper mode.
4317 But don't forget to store the value into TARGET. */
4318 temp
= convert_to_mode (GET_MODE (target
), temp
, unsignedp
);
4319 emit_move_insn (target
, temp
);
4322 convert_move (target
, temp
, unsignedp
);
4325 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
4327 /* Handle copying a string constant into an array. The string
4328 constant may be shorter than the array. So copy just the string's
4329 actual length, and clear the rest. First get the size of the data
4330 type of the string, which is actually the size of the target. */
4331 rtx size
= expr_size (exp
);
4333 if (GET_CODE (size
) == CONST_INT
4334 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
4335 emit_block_move (target
, temp
, size
,
4337 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
4340 /* Compute the size of the data to copy from the string. */
4342 = size_binop (MIN_EXPR
,
4343 make_tree (sizetype
, size
),
4344 size_int (TREE_STRING_LENGTH (exp
)));
4346 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
4348 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
4351 /* Copy that much. */
4352 copy_size_rtx
= convert_to_mode (ptr_mode
, copy_size_rtx
,
4353 TYPE_UNSIGNED (sizetype
));
4354 emit_block_move (target
, temp
, copy_size_rtx
,
4356 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
4358 /* Figure out how much is left in TARGET that we have to clear.
4359 Do all calculations in ptr_mode. */
4360 if (GET_CODE (copy_size_rtx
) == CONST_INT
)
4362 size
= plus_constant (size
, -INTVAL (copy_size_rtx
));
4363 target
= adjust_address (target
, BLKmode
,
4364 INTVAL (copy_size_rtx
));
4368 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
4369 copy_size_rtx
, NULL_RTX
, 0,
4372 #ifdef POINTERS_EXTEND_UNSIGNED
4373 if (GET_MODE (copy_size_rtx
) != Pmode
)
4374 copy_size_rtx
= convert_to_mode (Pmode
, copy_size_rtx
,
4375 TYPE_UNSIGNED (sizetype
));
4378 target
= offset_address (target
, copy_size_rtx
,
4379 highest_pow2_factor (copy_size
));
4380 label
= gen_label_rtx ();
4381 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
4382 GET_MODE (size
), 0, label
);
4385 if (size
!= const0_rtx
)
4386 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
4392 /* Handle calls that return values in multiple non-contiguous locations.
4393 The Irix 6 ABI has examples of this. */
4394 else if (GET_CODE (target
) == PARALLEL
)
4395 emit_group_load (target
, temp
, TREE_TYPE (exp
),
4396 int_size_in_bytes (TREE_TYPE (exp
)));
4397 else if (GET_MODE (temp
) == BLKmode
)
4398 emit_block_move (target
, temp
, expr_size (exp
),
4400 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
4403 temp
= force_operand (temp
, target
);
4405 emit_move_insn (target
, temp
);
4412 /* Examine CTOR to discover:
4413 * how many scalar fields are set to nonzero values,
4414 and place it in *P_NZ_ELTS;
4415 * how many scalar fields are set to non-constant values,
4416 and place it in *P_NC_ELTS; and
4417 * how many scalar fields in total are in CTOR,
4418 and place it in *P_ELT_COUNT.
4419 * if a type is a union, and the initializer from the constructor
4420 is not the largest element in the union, then set *p_must_clear. */
4423 categorize_ctor_elements_1 (tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
4424 HOST_WIDE_INT
*p_nc_elts
,
4425 HOST_WIDE_INT
*p_elt_count
,
4428 unsigned HOST_WIDE_INT idx
;
4429 HOST_WIDE_INT nz_elts
, nc_elts
, elt_count
;
4430 tree value
, purpose
;
4436 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
4441 if (TREE_CODE (purpose
) == RANGE_EXPR
)
4443 tree lo_index
= TREE_OPERAND (purpose
, 0);
4444 tree hi_index
= TREE_OPERAND (purpose
, 1);
4446 if (host_integerp (lo_index
, 1) && host_integerp (hi_index
, 1))
4447 mult
= (tree_low_cst (hi_index
, 1)
4448 - tree_low_cst (lo_index
, 1) + 1);
4451 switch (TREE_CODE (value
))
4455 HOST_WIDE_INT nz
= 0, nc
= 0, ic
= 0;
4456 categorize_ctor_elements_1 (value
, &nz
, &nc
, &ic
, p_must_clear
);
4457 nz_elts
+= mult
* nz
;
4458 nc_elts
+= mult
* nc
;
4459 elt_count
+= mult
* ic
;
4465 if (!initializer_zerop (value
))
4471 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
4472 elt_count
+= mult
* TREE_STRING_LENGTH (value
);
4476 if (!initializer_zerop (TREE_REALPART (value
)))
4478 if (!initializer_zerop (TREE_IMAGPART (value
)))
4486 for (v
= TREE_VECTOR_CST_ELTS (value
); v
; v
= TREE_CHAIN (v
))
4488 if (!initializer_zerop (TREE_VALUE (v
)))
4498 if (!initializer_constant_valid_p (value
, TREE_TYPE (value
)))
4505 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4506 || TREE_CODE (TREE_TYPE (ctor
)) == QUAL_UNION_TYPE
))
4509 bool clear_this
= true;
4511 if (!VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (ctor
)))
4513 /* We don't expect more than one element of the union to be
4514 initialized. Not sure what we should do otherwise... */
4515 gcc_assert (VEC_length (constructor_elt
, CONSTRUCTOR_ELTS (ctor
))
4518 init_sub_type
= TREE_TYPE (VEC_index (constructor_elt
,
4519 CONSTRUCTOR_ELTS (ctor
),
4522 /* ??? We could look at each element of the union, and find the
4523 largest element. Which would avoid comparing the size of the
4524 initialized element against any tail padding in the union.
4525 Doesn't seem worth the effort... */
4526 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (ctor
)),
4527 TYPE_SIZE (init_sub_type
)) == 1)
4529 /* And now we have to find out if the element itself is fully
4530 constructed. E.g. for union { struct { int a, b; } s; } u
4531 = { .s = { .a = 1 } }. */
4532 if (elt_count
== count_type_elements (init_sub_type
, false))
4537 *p_must_clear
= clear_this
;
4540 *p_nz_elts
+= nz_elts
;
4541 *p_nc_elts
+= nc_elts
;
4542 *p_elt_count
+= elt_count
;
4546 categorize_ctor_elements (tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
4547 HOST_WIDE_INT
*p_nc_elts
,
4548 HOST_WIDE_INT
*p_elt_count
,
4554 *p_must_clear
= false;
4555 categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_nc_elts
, p_elt_count
,
4559 /* Count the number of scalars in TYPE. Return -1 on overflow or
4560 variable-sized. If ALLOW_FLEXARR is true, don't count flexible
4561 array member at the end of the structure. */
4564 count_type_elements (tree type
, bool allow_flexarr
)
4566 const HOST_WIDE_INT max
= ~((HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
-1));
4567 switch (TREE_CODE (type
))
4571 tree telts
= array_type_nelts (type
);
4572 if (telts
&& host_integerp (telts
, 1))
4574 HOST_WIDE_INT n
= tree_low_cst (telts
, 1) + 1;
4575 HOST_WIDE_INT m
= count_type_elements (TREE_TYPE (type
), false);
4578 else if (max
/ n
> m
)
4586 HOST_WIDE_INT n
= 0, t
;
4589 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
4590 if (TREE_CODE (f
) == FIELD_DECL
)
4592 t
= count_type_elements (TREE_TYPE (f
), false);
4595 /* Check for structures with flexible array member. */
4596 tree tf
= TREE_TYPE (f
);
4598 && TREE_CHAIN (f
) == NULL
4599 && TREE_CODE (tf
) == ARRAY_TYPE
4601 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
4602 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
4603 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
4604 && int_size_in_bytes (type
) >= 0)
4616 case QUAL_UNION_TYPE
:
4618 /* Ho hum. How in the world do we guess here? Clearly it isn't
4619 right to count the fields. Guess based on the number of words. */
4620 HOST_WIDE_INT n
= int_size_in_bytes (type
);
4623 return n
/ UNITS_PER_WORD
;
4630 return TYPE_VECTOR_SUBPARTS (type
);
4639 case REFERENCE_TYPE
:
4651 /* Return 1 if EXP contains mostly (3/4) zeros. */
4654 mostly_zeros_p (tree exp
)
4656 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4659 HOST_WIDE_INT nz_elts
, nc_elts
, count
, elts
;
4662 categorize_ctor_elements (exp
, &nz_elts
, &nc_elts
, &count
, &must_clear
);
4666 elts
= count_type_elements (TREE_TYPE (exp
), false);
4668 return nz_elts
< elts
/ 4;
4671 return initializer_zerop (exp
);
4674 /* Return 1 if EXP contains all zeros. */
4677 all_zeros_p (tree exp
)
4679 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4682 HOST_WIDE_INT nz_elts
, nc_elts
, count
;
4685 categorize_ctor_elements (exp
, &nz_elts
, &nc_elts
, &count
, &must_clear
);
4686 return nz_elts
== 0;
4689 return initializer_zerop (exp
);
4692 /* Helper function for store_constructor.
4693 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
4694 TYPE is the type of the CONSTRUCTOR, not the element type.
4695 CLEARED is as for store_constructor.
4696 ALIAS_SET is the alias set to use for any stores.
4698 This provides a recursive shortcut back to store_constructor when it isn't
4699 necessary to go through store_field. This is so that we can pass through
4700 the cleared field to let store_constructor know that we may not have to
4701 clear a substructure if the outer structure has already been cleared. */
4704 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
4705 HOST_WIDE_INT bitpos
, enum machine_mode mode
,
4706 tree exp
, tree type
, int cleared
, int alias_set
)
4708 if (TREE_CODE (exp
) == CONSTRUCTOR
4709 /* We can only call store_constructor recursively if the size and
4710 bit position are on a byte boundary. */
4711 && bitpos
% BITS_PER_UNIT
== 0
4712 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
4713 /* If we have a nonzero bitpos for a register target, then we just
4714 let store_field do the bitfield handling. This is unlikely to
4715 generate unnecessary clear instructions anyways. */
4716 && (bitpos
== 0 || MEM_P (target
)))
4720 = adjust_address (target
,
4721 GET_MODE (target
) == BLKmode
4723 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
4724 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
4727 /* Update the alias set, if required. */
4728 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
4729 && MEM_ALIAS_SET (target
) != 0)
4731 target
= copy_rtx (target
);
4732 set_mem_alias_set (target
, alias_set
);
4735 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
4738 store_field (target
, bitsize
, bitpos
, mode
, exp
, type
, alias_set
);
4741 /* Store the value of constructor EXP into the rtx TARGET.
4742 TARGET is either a REG or a MEM; we know it cannot conflict, since
4743 safe_from_p has been called.
4744 CLEARED is true if TARGET is known to have been zero'd.
4745 SIZE is the number of bytes of TARGET we are allowed to modify: this
4746 may not be the same as the size of EXP if we are assigning to a field
4747 which has been packed to exclude padding bits. */
4750 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
4752 tree type
= TREE_TYPE (exp
);
4753 #ifdef WORD_REGISTER_OPERATIONS
4754 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
4757 switch (TREE_CODE (type
))
4761 case QUAL_UNION_TYPE
:
4763 unsigned HOST_WIDE_INT idx
;
4766 /* If size is zero or the target is already cleared, do nothing. */
4767 if (size
== 0 || cleared
)
4769 /* We either clear the aggregate or indicate the value is dead. */
4770 else if ((TREE_CODE (type
) == UNION_TYPE
4771 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
4772 && ! CONSTRUCTOR_ELTS (exp
))
4773 /* If the constructor is empty, clear the union. */
4775 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
4779 /* If we are building a static constructor into a register,
4780 set the initial value as zero so we can fold the value into
4781 a constant. But if more than one register is involved,
4782 this probably loses. */
4783 else if (REG_P (target
) && TREE_STATIC (exp
)
4784 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
4786 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
4790 /* If the constructor has fewer fields than the structure or
4791 if we are initializing the structure to mostly zeros, clear
4792 the whole structure first. Don't do this if TARGET is a
4793 register whose mode size isn't equal to SIZE since
4794 clear_storage can't handle this case. */
4796 && (((int)VEC_length (constructor_elt
, CONSTRUCTOR_ELTS (exp
))
4797 != fields_length (type
))
4798 || mostly_zeros_p (exp
))
4800 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
4803 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
4808 emit_insn (gen_rtx_CLOBBER (VOIDmode
, target
));
4810 /* Store each element of the constructor into the
4811 corresponding field of TARGET. */
4812 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
4814 enum machine_mode mode
;
4815 HOST_WIDE_INT bitsize
;
4816 HOST_WIDE_INT bitpos
= 0;
4818 rtx to_rtx
= target
;
4820 /* Just ignore missing fields. We cleared the whole
4821 structure, above, if any fields are missing. */
4825 if (cleared
&& initializer_zerop (value
))
4828 if (host_integerp (DECL_SIZE (field
), 1))
4829 bitsize
= tree_low_cst (DECL_SIZE (field
), 1);
4833 mode
= DECL_MODE (field
);
4834 if (DECL_BIT_FIELD (field
))
4837 offset
= DECL_FIELD_OFFSET (field
);
4838 if (host_integerp (offset
, 0)
4839 && host_integerp (bit_position (field
), 0))
4841 bitpos
= int_bit_position (field
);
4845 bitpos
= tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 0);
4852 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
4853 make_tree (TREE_TYPE (exp
),
4856 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, 0);
4857 gcc_assert (MEM_P (to_rtx
));
4859 #ifdef POINTERS_EXTEND_UNSIGNED
4860 if (GET_MODE (offset_rtx
) != Pmode
)
4861 offset_rtx
= convert_to_mode (Pmode
, offset_rtx
, 0);
4863 if (GET_MODE (offset_rtx
) != ptr_mode
)
4864 offset_rtx
= convert_to_mode (ptr_mode
, offset_rtx
, 0);
4867 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4868 highest_pow2_factor (offset
));
4871 #ifdef WORD_REGISTER_OPERATIONS
4872 /* If this initializes a field that is smaller than a
4873 word, at the start of a word, try to widen it to a full
4874 word. This special case allows us to output C++ member
4875 function initializations in a form that the optimizers
4878 && bitsize
< BITS_PER_WORD
4879 && bitpos
% BITS_PER_WORD
== 0
4880 && GET_MODE_CLASS (mode
) == MODE_INT
4881 && TREE_CODE (value
) == INTEGER_CST
4883 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
4885 tree type
= TREE_TYPE (value
);
4887 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
4889 type
= lang_hooks
.types
.type_for_size
4890 (BITS_PER_WORD
, TYPE_UNSIGNED (type
));
4891 value
= convert (type
, value
);
4894 if (BYTES_BIG_ENDIAN
)
4896 = fold_build2 (LSHIFT_EXPR
, type
, value
,
4897 build_int_cst (NULL_TREE
,
4898 BITS_PER_WORD
- bitsize
));
4899 bitsize
= BITS_PER_WORD
;
4904 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
4905 && DECL_NONADDRESSABLE_P (field
))
4907 to_rtx
= copy_rtx (to_rtx
);
4908 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
4911 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
4912 value
, type
, cleared
,
4913 get_alias_set (TREE_TYPE (field
)));
4920 unsigned HOST_WIDE_INT i
;
4923 tree elttype
= TREE_TYPE (type
);
4925 HOST_WIDE_INT minelt
= 0;
4926 HOST_WIDE_INT maxelt
= 0;
4928 domain
= TYPE_DOMAIN (type
);
4929 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
4930 && TYPE_MAX_VALUE (domain
)
4931 && host_integerp (TYPE_MIN_VALUE (domain
), 0)
4932 && host_integerp (TYPE_MAX_VALUE (domain
), 0));
4934 /* If we have constant bounds for the range of the type, get them. */
4937 minelt
= tree_low_cst (TYPE_MIN_VALUE (domain
), 0);
4938 maxelt
= tree_low_cst (TYPE_MAX_VALUE (domain
), 0);
4941 /* If the constructor has fewer elements than the array, clear
4942 the whole array first. Similarly if this is static
4943 constructor of a non-BLKmode object. */
4946 else if (REG_P (target
) && TREE_STATIC (exp
))
4950 unsigned HOST_WIDE_INT idx
;
4952 HOST_WIDE_INT count
= 0, zero_count
= 0;
4953 need_to_clear
= ! const_bounds_p
;
4955 /* This loop is a more accurate version of the loop in
4956 mostly_zeros_p (it handles RANGE_EXPR in an index). It
4957 is also needed to check for missing elements. */
4958 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
4960 HOST_WIDE_INT this_node_count
;
4965 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
4967 tree lo_index
= TREE_OPERAND (index
, 0);
4968 tree hi_index
= TREE_OPERAND (index
, 1);
4970 if (! host_integerp (lo_index
, 1)
4971 || ! host_integerp (hi_index
, 1))
4977 this_node_count
= (tree_low_cst (hi_index
, 1)
4978 - tree_low_cst (lo_index
, 1) + 1);
4981 this_node_count
= 1;
4983 count
+= this_node_count
;
4984 if (mostly_zeros_p (value
))
4985 zero_count
+= this_node_count
;
4988 /* Clear the entire array first if there are any missing
4989 elements, or if the incidence of zero elements is >=
4992 && (count
< maxelt
- minelt
+ 1
4993 || 4 * zero_count
>= 3 * count
))
4997 if (need_to_clear
&& size
> 0)
5000 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5002 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5006 if (!cleared
&& REG_P (target
))
5007 /* Inform later passes that the old value is dead. */
5008 emit_insn (gen_rtx_CLOBBER (VOIDmode
, target
));
5010 /* Store each element of the constructor into the
5011 corresponding element of TARGET, determined by counting the
5013 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
5015 enum machine_mode mode
;
5016 HOST_WIDE_INT bitsize
;
5017 HOST_WIDE_INT bitpos
;
5019 rtx xtarget
= target
;
5021 if (cleared
&& initializer_zerop (value
))
5024 unsignedp
= TYPE_UNSIGNED (elttype
);
5025 mode
= TYPE_MODE (elttype
);
5026 if (mode
== BLKmode
)
5027 bitsize
= (host_integerp (TYPE_SIZE (elttype
), 1)
5028 ? tree_low_cst (TYPE_SIZE (elttype
), 1)
5031 bitsize
= GET_MODE_BITSIZE (mode
);
5033 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
5035 tree lo_index
= TREE_OPERAND (index
, 0);
5036 tree hi_index
= TREE_OPERAND (index
, 1);
5037 rtx index_r
, pos_rtx
;
5038 HOST_WIDE_INT lo
, hi
, count
;
5041 /* If the range is constant and "small", unroll the loop. */
5043 && host_integerp (lo_index
, 0)
5044 && host_integerp (hi_index
, 0)
5045 && (lo
= tree_low_cst (lo_index
, 0),
5046 hi
= tree_low_cst (hi_index
, 0),
5047 count
= hi
- lo
+ 1,
5050 || (host_integerp (TYPE_SIZE (elttype
), 1)
5051 && (tree_low_cst (TYPE_SIZE (elttype
), 1) * count
5054 lo
-= minelt
; hi
-= minelt
;
5055 for (; lo
<= hi
; lo
++)
5057 bitpos
= lo
* tree_low_cst (TYPE_SIZE (elttype
), 0);
5060 && !MEM_KEEP_ALIAS_SET_P (target
)
5061 && TREE_CODE (type
) == ARRAY_TYPE
5062 && TYPE_NONALIASED_COMPONENT (type
))
5064 target
= copy_rtx (target
);
5065 MEM_KEEP_ALIAS_SET_P (target
) = 1;
5068 store_constructor_field
5069 (target
, bitsize
, bitpos
, mode
, value
, type
, cleared
,
5070 get_alias_set (elttype
));
5075 rtx loop_start
= gen_label_rtx ();
5076 rtx loop_end
= gen_label_rtx ();
5079 expand_expr (hi_index
, NULL_RTX
, VOIDmode
, 0);
5080 unsignedp
= TYPE_UNSIGNED (domain
);
5082 index
= build_decl (VAR_DECL
, NULL_TREE
, domain
);
5085 = gen_reg_rtx (promote_mode (domain
, DECL_MODE (index
),
5087 SET_DECL_RTL (index
, index_r
);
5088 store_expr (lo_index
, index_r
, 0);
5090 /* Build the head of the loop. */
5091 do_pending_stack_adjust ();
5092 emit_label (loop_start
);
5094 /* Assign value to element index. */
5096 = convert (ssizetype
,
5097 fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
5098 index
, TYPE_MIN_VALUE (domain
)));
5099 position
= size_binop (MULT_EXPR
, position
,
5101 TYPE_SIZE_UNIT (elttype
)));
5103 pos_rtx
= expand_expr (position
, 0, VOIDmode
, 0);
5104 xtarget
= offset_address (target
, pos_rtx
,
5105 highest_pow2_factor (position
));
5106 xtarget
= adjust_address (xtarget
, mode
, 0);
5107 if (TREE_CODE (value
) == CONSTRUCTOR
)
5108 store_constructor (value
, xtarget
, cleared
,
5109 bitsize
/ BITS_PER_UNIT
);
5111 store_expr (value
, xtarget
, 0);
5113 /* Generate a conditional jump to exit the loop. */
5114 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
5116 jumpif (exit_cond
, loop_end
);
5118 /* Update the loop counter, and jump to the head of
5120 expand_assignment (index
,
5121 build2 (PLUS_EXPR
, TREE_TYPE (index
),
5122 index
, integer_one_node
));
5124 emit_jump (loop_start
);
5126 /* Build the end of the loop. */
5127 emit_label (loop_end
);
5130 else if ((index
!= 0 && ! host_integerp (index
, 0))
5131 || ! host_integerp (TYPE_SIZE (elttype
), 1))
5136 index
= ssize_int (1);
5139 index
= fold_convert (ssizetype
,
5140 fold_build2 (MINUS_EXPR
,
5143 TYPE_MIN_VALUE (domain
)));
5145 position
= size_binop (MULT_EXPR
, index
,
5147 TYPE_SIZE_UNIT (elttype
)));
5148 xtarget
= offset_address (target
,
5149 expand_expr (position
, 0, VOIDmode
, 0),
5150 highest_pow2_factor (position
));
5151 xtarget
= adjust_address (xtarget
, mode
, 0);
5152 store_expr (value
, xtarget
, 0);
5157 bitpos
= ((tree_low_cst (index
, 0) - minelt
)
5158 * tree_low_cst (TYPE_SIZE (elttype
), 1));
5160 bitpos
= (i
* tree_low_cst (TYPE_SIZE (elttype
), 1));
5162 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
5163 && TREE_CODE (type
) == ARRAY_TYPE
5164 && TYPE_NONALIASED_COMPONENT (type
))
5166 target
= copy_rtx (target
);
5167 MEM_KEEP_ALIAS_SET_P (target
) = 1;
5169 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
5170 type
, cleared
, get_alias_set (elttype
));
5178 unsigned HOST_WIDE_INT idx
;
5179 constructor_elt
*ce
;
5183 tree elttype
= TREE_TYPE (type
);
5184 int elt_size
= tree_low_cst (TYPE_SIZE (elttype
), 1);
5185 enum machine_mode eltmode
= TYPE_MODE (elttype
);
5186 HOST_WIDE_INT bitsize
;
5187 HOST_WIDE_INT bitpos
;
5188 rtvec vector
= NULL
;
5191 gcc_assert (eltmode
!= BLKmode
);
5193 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
5194 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
5196 enum machine_mode mode
= GET_MODE (target
);
5198 icode
= (int) vec_init_optab
->handlers
[mode
].insn_code
;
5199 if (icode
!= CODE_FOR_nothing
)
5203 vector
= rtvec_alloc (n_elts
);
5204 for (i
= 0; i
< n_elts
; i
++)
5205 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
5209 /* If the constructor has fewer elements than the vector,
5210 clear the whole array first. Similarly if this is static
5211 constructor of a non-BLKmode object. */
5214 else if (REG_P (target
) && TREE_STATIC (exp
))
5218 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
5221 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
5223 int n_elts_here
= tree_low_cst
5224 (int_const_binop (TRUNC_DIV_EXPR
,
5225 TYPE_SIZE (TREE_TYPE (value
)),
5226 TYPE_SIZE (elttype
), 0), 1);
5228 count
+= n_elts_here
;
5229 if (mostly_zeros_p (value
))
5230 zero_count
+= n_elts_here
;
5233 /* Clear the entire vector first if there are any missing elements,
5234 or if the incidence of zero elements is >= 75%. */
5235 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
5238 if (need_to_clear
&& size
> 0 && !vector
)
5241 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5243 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5247 /* Inform later passes that the old value is dead. */
5248 if (!cleared
&& REG_P (target
))
5249 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5251 /* Store each element of the constructor into the corresponding
5252 element of TARGET, determined by counting the elements. */
5253 for (idx
= 0, i
= 0;
5254 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), idx
, ce
);
5255 idx
++, i
+= bitsize
/ elt_size
)
5257 HOST_WIDE_INT eltpos
;
5258 tree value
= ce
->value
;
5260 bitsize
= tree_low_cst (TYPE_SIZE (TREE_TYPE (value
)), 1);
5261 if (cleared
&& initializer_zerop (value
))
5265 eltpos
= tree_low_cst (ce
->index
, 1);
5271 /* Vector CONSTRUCTORs should only be built from smaller
5272 vectors in the case of BLKmode vectors. */
5273 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
5274 RTVEC_ELT (vector
, eltpos
)
5275 = expand_expr (value
, NULL_RTX
, VOIDmode
, 0);
5279 enum machine_mode value_mode
=
5280 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
5281 ? TYPE_MODE (TREE_TYPE (value
))
5283 bitpos
= eltpos
* elt_size
;
5284 store_constructor_field (target
, bitsize
, bitpos
,
5285 value_mode
, value
, type
,
5286 cleared
, get_alias_set (elttype
));
5291 emit_insn (GEN_FCN (icode
)
5293 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
5302 /* Store the value of EXP (an expression tree)
5303 into a subfield of TARGET which has mode MODE and occupies
5304 BITSIZE bits, starting BITPOS bits from the start of TARGET.
5305 If MODE is VOIDmode, it means that we are storing into a bit-field.
5307 Always return const0_rtx unless we have something particular to
5310 TYPE is the type of the underlying object,
5312 ALIAS_SET is the alias set for the destination. This value will
5313 (in general) be different from that for TARGET, since TARGET is a
5314 reference to the containing structure. */
5317 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
5318 enum machine_mode mode
, tree exp
, tree type
, int alias_set
)
5320 HOST_WIDE_INT width_mask
= 0;
5322 if (TREE_CODE (exp
) == ERROR_MARK
)
5325 /* If we have nothing to store, do nothing unless the expression has
5328 return expand_expr (exp
, const0_rtx
, VOIDmode
, 0);
5329 else if (bitsize
>= 0 && bitsize
< HOST_BITS_PER_WIDE_INT
)
5330 width_mask
= ((HOST_WIDE_INT
) 1 << bitsize
) - 1;
5332 /* If we are storing into an unaligned field of an aligned union that is
5333 in a register, we may have the mode of TARGET being an integer mode but
5334 MODE == BLKmode. In that case, get an aligned object whose size and
5335 alignment are the same as TARGET and store TARGET into it (we can avoid
5336 the store if the field being stored is the entire width of TARGET). Then
5337 call ourselves recursively to store the field into a BLKmode version of
5338 that object. Finally, load from the object into TARGET. This is not
5339 very efficient in general, but should only be slightly more expensive
5340 than the otherwise-required unaligned accesses. Perhaps this can be
5341 cleaned up later. It's tempting to make OBJECT readonly, but it's set
5342 twice, once with emit_move_insn and once via store_field. */
5345 && (REG_P (target
) || GET_CODE (target
) == SUBREG
))
5347 rtx object
= assign_temp (type
, 0, 1, 1);
5348 rtx blk_object
= adjust_address (object
, BLKmode
, 0);
5350 if (bitsize
!= (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (target
)))
5351 emit_move_insn (object
, target
);
5353 store_field (blk_object
, bitsize
, bitpos
, mode
, exp
, type
, alias_set
);
5355 emit_move_insn (target
, object
);
5357 /* We want to return the BLKmode version of the data. */
5361 if (GET_CODE (target
) == CONCAT
)
5363 /* We're storing into a struct containing a single __complex. */
5365 gcc_assert (!bitpos
);
5366 return store_expr (exp
, target
, 0);
5369 /* If the structure is in a register or if the component
5370 is a bit field, we cannot use addressing to access it.
5371 Use bit-field techniques or SUBREG to store in it. */
5373 if (mode
== VOIDmode
5374 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
5375 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
5376 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
5378 || GET_CODE (target
) == SUBREG
5379 /* If the field isn't aligned enough to store as an ordinary memref,
5380 store it as a bit field. */
5382 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
5383 || bitpos
% GET_MODE_ALIGNMENT (mode
))
5384 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
5385 || (bitpos
% BITS_PER_UNIT
!= 0)))
5386 /* If the RHS and field are a constant size and the size of the
5387 RHS isn't the same size as the bitfield, we must use bitfield
5390 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
5391 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0))
5395 /* If EXP is a NOP_EXPR of precision less than its mode, then that
5396 implies a mask operation. If the precision is the same size as
5397 the field we're storing into, that mask is redundant. This is
5398 particularly common with bit field assignments generated by the
5400 if (TREE_CODE (exp
) == NOP_EXPR
)
5402 tree type
= TREE_TYPE (exp
);
5403 if (INTEGRAL_TYPE_P (type
)
5404 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
5405 && bitsize
== TYPE_PRECISION (type
))
5407 type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
5408 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
5409 exp
= TREE_OPERAND (exp
, 0);
5413 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, 0);
5415 /* If BITSIZE is narrower than the size of the type of EXP
5416 we will be narrowing TEMP. Normally, what's wanted are the
5417 low-order bits. However, if EXP's type is a record and this is
5418 big-endian machine, we want the upper BITSIZE bits. */
5419 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
5420 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
5421 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
5422 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
5423 size_int (GET_MODE_BITSIZE (GET_MODE (temp
))
5427 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to
5429 if (mode
!= VOIDmode
&& mode
!= BLKmode
5430 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
5431 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
5433 /* If the modes of TARGET and TEMP are both BLKmode, both
5434 must be in memory and BITPOS must be aligned on a byte
5435 boundary. If so, we simply do a block copy. */
5436 if (GET_MODE (target
) == BLKmode
&& GET_MODE (temp
) == BLKmode
)
5438 gcc_assert (MEM_P (target
) && MEM_P (temp
)
5439 && !(bitpos
% BITS_PER_UNIT
));
5441 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5442 emit_block_move (target
, temp
,
5443 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
5450 /* Store the value in the bitfield. */
5451 store_bit_field (target
, bitsize
, bitpos
, mode
, temp
);
5457 /* Now build a reference to just the desired component. */
5458 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
5460 if (to_rtx
== target
)
5461 to_rtx
= copy_rtx (to_rtx
);
5463 MEM_SET_IN_STRUCT_P (to_rtx
, 1);
5464 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
5465 set_mem_alias_set (to_rtx
, alias_set
);
5467 return store_expr (exp
, to_rtx
, 0);
5471 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
5472 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
5473 codes and find the ultimate containing object, which we return.
5475 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
5476 bit position, and *PUNSIGNEDP to the signedness of the field.
5477 If the position of the field is variable, we store a tree
5478 giving the variable offset (in units) in *POFFSET.
5479 This offset is in addition to the bit position.
5480 If the position is not variable, we store 0 in *POFFSET.
5482 If any of the extraction expressions is volatile,
5483 we store 1 in *PVOLATILEP. Otherwise we don't change that.
5485 If the field is a bit-field, *PMODE is set to VOIDmode. Otherwise, it
5486 is a mode that can be used to access the field. In that case, *PBITSIZE
5489 If the field describes a variable-sized object, *PMODE is set to
5490 VOIDmode and *PBITSIZE is set to -1. An access cannot be made in
5491 this case, but the address of the object can be found.
5493 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
5494 look through nodes that serve as markers of a greater alignment than
5495 the one that can be deduced from the expression. These nodes make it
5496 possible for front-ends to prevent temporaries from being created by
5497 the middle-end on alignment considerations. For that purpose, the
5498 normal operating mode at high-level is to always pass FALSE so that
5499 the ultimate containing object is really returned; moreover, the
5500 associated predicate handled_component_p will always return TRUE
5501 on these nodes, thus indicating that they are essentially handled
5502 by get_inner_reference. TRUE should only be passed when the caller
5503 is scanning the expression in order to build another representation
5504 and specifically knows how to handle these nodes; as such, this is
5505 the normal operating mode in the RTL expanders. */
5508 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
5509 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
5510 enum machine_mode
*pmode
, int *punsignedp
,
5511 int *pvolatilep
, bool keep_aligning
)
5514 enum machine_mode mode
= VOIDmode
;
5515 tree offset
= size_zero_node
;
5516 tree bit_offset
= bitsize_zero_node
;
5519 /* First get the mode, signedness, and size. We do this from just the
5520 outermost expression. */
5521 if (TREE_CODE (exp
) == COMPONENT_REF
)
5523 size_tree
= DECL_SIZE (TREE_OPERAND (exp
, 1));
5524 if (! DECL_BIT_FIELD (TREE_OPERAND (exp
, 1)))
5525 mode
= DECL_MODE (TREE_OPERAND (exp
, 1));
5527 *punsignedp
= DECL_UNSIGNED (TREE_OPERAND (exp
, 1));
5529 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
5531 size_tree
= TREE_OPERAND (exp
, 1);
5532 *punsignedp
= BIT_FIELD_REF_UNSIGNED (exp
);
5536 mode
= TYPE_MODE (TREE_TYPE (exp
));
5537 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
5539 if (mode
== BLKmode
)
5540 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
5542 *pbitsize
= GET_MODE_BITSIZE (mode
);
5547 if (! host_integerp (size_tree
, 1))
5548 mode
= BLKmode
, *pbitsize
= -1;
5550 *pbitsize
= tree_low_cst (size_tree
, 1);
5553 /* Compute cumulative bit-offset for nested component-refs and array-refs,
5554 and find the ultimate containing object. */
5557 switch (TREE_CODE (exp
))
5560 bit_offset
= size_binop (PLUS_EXPR
, bit_offset
,
5561 TREE_OPERAND (exp
, 2));
5566 tree field
= TREE_OPERAND (exp
, 1);
5567 tree this_offset
= component_ref_field_offset (exp
);
5569 /* If this field hasn't been filled in yet, don't go past it.
5570 This should only happen when folding expressions made during
5571 type construction. */
5572 if (this_offset
== 0)
5575 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
5576 bit_offset
= size_binop (PLUS_EXPR
, bit_offset
,
5577 DECL_FIELD_BIT_OFFSET (field
));
5579 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
5584 case ARRAY_RANGE_REF
:
5586 tree index
= TREE_OPERAND (exp
, 1);
5587 tree low_bound
= array_ref_low_bound (exp
);
5588 tree unit_size
= array_ref_element_size (exp
);
5590 /* We assume all arrays have sizes that are a multiple of a byte.
5591 First subtract the lower bound, if any, in the type of the
5592 index, then convert to sizetype and multiply by the size of
5593 the array element. */
5594 if (! integer_zerop (low_bound
))
5595 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
5598 offset
= size_binop (PLUS_EXPR
, offset
,
5599 size_binop (MULT_EXPR
,
5600 convert (sizetype
, index
),
5609 bit_offset
= size_binop (PLUS_EXPR
, bit_offset
,
5610 bitsize_int (*pbitsize
));
5613 case VIEW_CONVERT_EXPR
:
5614 if (keep_aligning
&& STRICT_ALIGNMENT
5615 && (TYPE_ALIGN (TREE_TYPE (exp
))
5616 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
5617 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
5618 < BIGGEST_ALIGNMENT
)
5619 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
5620 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
5628 /* If any reference in the chain is volatile, the effect is volatile. */
5629 if (TREE_THIS_VOLATILE (exp
))
5632 exp
= TREE_OPERAND (exp
, 0);
5636 /* If OFFSET is constant, see if we can return the whole thing as a
5637 constant bit position. Otherwise, split it up. */
5638 if (host_integerp (offset
, 0)
5639 && 0 != (tem
= size_binop (MULT_EXPR
, convert (bitsizetype
, offset
),
5641 && 0 != (tem
= size_binop (PLUS_EXPR
, tem
, bit_offset
))
5642 && host_integerp (tem
, 0))
5643 *pbitpos
= tree_low_cst (tem
, 0), *poffset
= 0;
5645 *pbitpos
= tree_low_cst (bit_offset
, 0), *poffset
= offset
;
5651 /* Return a tree of sizetype representing the size, in bytes, of the element
5652 of EXP, an ARRAY_REF. */
5655 array_ref_element_size (tree exp
)
5657 tree aligned_size
= TREE_OPERAND (exp
, 3);
5658 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
5660 /* If a size was specified in the ARRAY_REF, it's the size measured
5661 in alignment units of the element type. So multiply by that value. */
5664 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
5665 sizetype from another type of the same width and signedness. */
5666 if (TREE_TYPE (aligned_size
) != sizetype
)
5667 aligned_size
= fold_convert (sizetype
, aligned_size
);
5668 return size_binop (MULT_EXPR
, aligned_size
,
5669 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
5672 /* Otherwise, take the size from that of the element type. Substitute
5673 any PLACEHOLDER_EXPR that we have. */
5675 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
5678 /* Return a tree representing the lower bound of the array mentioned in
5679 EXP, an ARRAY_REF. */
5682 array_ref_low_bound (tree exp
)
5684 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
5686 /* If a lower bound is specified in EXP, use it. */
5687 if (TREE_OPERAND (exp
, 2))
5688 return TREE_OPERAND (exp
, 2);
5690 /* Otherwise, if there is a domain type and it has a lower bound, use it,
5691 substituting for a PLACEHOLDER_EXPR as needed. */
5692 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
5693 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
5695 /* Otherwise, return a zero of the appropriate type. */
5696 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
5699 /* Return a tree representing the upper bound of the array mentioned in
5700 EXP, an ARRAY_REF. */
5703 array_ref_up_bound (tree exp
)
5705 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
5707 /* If there is a domain type and it has an upper bound, use it, substituting
5708 for a PLACEHOLDER_EXPR as needed. */
5709 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
5710 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
5712 /* Otherwise fail. */
5716 /* Return a tree representing the offset, in bytes, of the field referenced
5717 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
5720 component_ref_field_offset (tree exp
)
5722 tree aligned_offset
= TREE_OPERAND (exp
, 2);
5723 tree field
= TREE_OPERAND (exp
, 1);
5725 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
5726 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
5730 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
5731 sizetype from another type of the same width and signedness. */
5732 if (TREE_TYPE (aligned_offset
) != sizetype
)
5733 aligned_offset
= fold_convert (sizetype
, aligned_offset
);
5734 return size_binop (MULT_EXPR
, aligned_offset
,
5735 size_int (DECL_OFFSET_ALIGN (field
) / BITS_PER_UNIT
));
5738 /* Otherwise, take the offset from that of the field. Substitute
5739 any PLACEHOLDER_EXPR that we have. */
5741 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
5744 /* Return 1 if T is an expression that get_inner_reference handles. */
5747 handled_component_p (tree t
)
5749 switch (TREE_CODE (t
))
5754 case ARRAY_RANGE_REF
:
5755 case VIEW_CONVERT_EXPR
:
5765 /* Given an rtx VALUE that may contain additions and multiplications, return
5766 an equivalent value that just refers to a register, memory, or constant.
5767 This is done by generating instructions to perform the arithmetic and
5768 returning a pseudo-register containing the value.
5770 The returned value may be a REG, SUBREG, MEM or constant. */
5773 force_operand (rtx value
, rtx target
)
5776 /* Use subtarget as the target for operand 0 of a binary operation. */
5777 rtx subtarget
= get_subtarget (target
);
5778 enum rtx_code code
= GET_CODE (value
);
5780 /* Check for subreg applied to an expression produced by loop optimizer. */
5782 && !REG_P (SUBREG_REG (value
))
5783 && !MEM_P (SUBREG_REG (value
)))
5785 value
= simplify_gen_subreg (GET_MODE (value
),
5786 force_reg (GET_MODE (SUBREG_REG (value
)),
5787 force_operand (SUBREG_REG (value
),
5789 GET_MODE (SUBREG_REG (value
)),
5790 SUBREG_BYTE (value
));
5791 code
= GET_CODE (value
);
5794 /* Check for a PIC address load. */
5795 if ((code
== PLUS
|| code
== MINUS
)
5796 && XEXP (value
, 0) == pic_offset_table_rtx
5797 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
5798 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
5799 || GET_CODE (XEXP (value
, 1)) == CONST
))
5802 subtarget
= gen_reg_rtx (GET_MODE (value
));
5803 emit_move_insn (subtarget
, value
);
5807 if (code
== ZERO_EXTEND
|| code
== SIGN_EXTEND
)
5810 target
= gen_reg_rtx (GET_MODE (value
));
5811 convert_move (target
, force_operand (XEXP (value
, 0), NULL
),
5812 code
== ZERO_EXTEND
);
5816 if (ARITHMETIC_P (value
))
5818 op2
= XEXP (value
, 1);
5819 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
5821 if (code
== MINUS
&& GET_CODE (op2
) == CONST_INT
)
5824 op2
= negate_rtx (GET_MODE (value
), op2
);
5827 /* Check for an addition with OP2 a constant integer and our first
5828 operand a PLUS of a virtual register and something else. In that
5829 case, we want to emit the sum of the virtual register and the
5830 constant first and then add the other value. This allows virtual
5831 register instantiation to simply modify the constant rather than
5832 creating another one around this addition. */
5833 if (code
== PLUS
&& GET_CODE (op2
) == CONST_INT
5834 && GET_CODE (XEXP (value
, 0)) == PLUS
5835 && REG_P (XEXP (XEXP (value
, 0), 0))
5836 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
5837 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
5839 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
5840 XEXP (XEXP (value
, 0), 0), op2
,
5841 subtarget
, 0, OPTAB_LIB_WIDEN
);
5842 return expand_simple_binop (GET_MODE (value
), code
, temp
,
5843 force_operand (XEXP (XEXP (value
,
5845 target
, 0, OPTAB_LIB_WIDEN
);
5848 op1
= force_operand (XEXP (value
, 0), subtarget
);
5849 op2
= force_operand (op2
, NULL_RTX
);
5853 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
5855 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
5856 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
5857 target
, 1, OPTAB_LIB_WIDEN
);
5859 return expand_divmod (0,
5860 FLOAT_MODE_P (GET_MODE (value
))
5861 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
5862 GET_MODE (value
), op1
, op2
, target
, 0);
5865 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
5869 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
5873 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
5877 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
5878 target
, 0, OPTAB_LIB_WIDEN
);
5881 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
5882 target
, 1, OPTAB_LIB_WIDEN
);
5885 if (UNARY_P (value
))
5887 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
5888 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
5891 #ifdef INSN_SCHEDULING
5892 /* On machines that have insn scheduling, we want all memory reference to be
5893 explicit, so we need to deal with such paradoxical SUBREGs. */
5894 if (GET_CODE (value
) == SUBREG
&& MEM_P (SUBREG_REG (value
))
5895 && (GET_MODE_SIZE (GET_MODE (value
))
5896 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (value
)))))
5898 = simplify_gen_subreg (GET_MODE (value
),
5899 force_reg (GET_MODE (SUBREG_REG (value
)),
5900 force_operand (SUBREG_REG (value
),
5902 GET_MODE (SUBREG_REG (value
)),
5903 SUBREG_BYTE (value
));
5909 /* Subroutine of expand_expr: return nonzero iff there is no way that
5910 EXP can reference X, which is being modified. TOP_P is nonzero if this
5911 call is going to be used to determine whether we need a temporary
5912 for EXP, as opposed to a recursive call to this function.
5914 It is always safe for this routine to return zero since it merely
5915 searches for optimization opportunities. */
5918 safe_from_p (rtx x
, tree exp
, int top_p
)
5924 /* If EXP has varying size, we MUST use a target since we currently
5925 have no way of allocating temporaries of variable size
5926 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
5927 So we assume here that something at a higher level has prevented a
5928 clash. This is somewhat bogus, but the best we can do. Only
5929 do this when X is BLKmode and when we are at the top level. */
5930 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
5931 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
5932 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
5933 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
5934 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
5936 && GET_MODE (x
) == BLKmode
)
5937 /* If X is in the outgoing argument area, it is always safe. */
5939 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
5940 || (GET_CODE (XEXP (x
, 0)) == PLUS
5941 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
5944 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
5945 find the underlying pseudo. */
5946 if (GET_CODE (x
) == SUBREG
)
5949 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
5953 /* Now look at our tree code and possibly recurse. */
5954 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
5956 case tcc_declaration
:
5957 exp_rtl
= DECL_RTL_IF_SET (exp
);
5963 case tcc_exceptional
:
5964 if (TREE_CODE (exp
) == TREE_LIST
)
5968 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
5970 exp
= TREE_CHAIN (exp
);
5973 if (TREE_CODE (exp
) != TREE_LIST
)
5974 return safe_from_p (x
, exp
, 0);
5977 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
5979 constructor_elt
*ce
;
5980 unsigned HOST_WIDE_INT idx
;
5983 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), idx
, ce
);
5985 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
5986 || !safe_from_p (x
, ce
->value
, 0))
5990 else if (TREE_CODE (exp
) == ERROR_MARK
)
5991 return 1; /* An already-visited SAVE_EXPR? */
5996 /* The only case we look at here is the DECL_INITIAL inside a
5998 return (TREE_CODE (exp
) != DECL_EXPR
5999 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
6000 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
6001 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
6004 case tcc_comparison
:
6005 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
6010 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
6012 case tcc_expression
:
6014 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
6015 the expression. If it is set, we conflict iff we are that rtx or
6016 both are in memory. Otherwise, we check all operands of the
6017 expression recursively. */
6019 switch (TREE_CODE (exp
))
6022 /* If the operand is static or we are static, we can't conflict.
6023 Likewise if we don't conflict with the operand at all. */
6024 if (staticp (TREE_OPERAND (exp
, 0))
6025 || TREE_STATIC (exp
)
6026 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
6029 /* Otherwise, the only way this can conflict is if we are taking
6030 the address of a DECL a that address if part of X, which is
6032 exp
= TREE_OPERAND (exp
, 0);
6035 if (!DECL_RTL_SET_P (exp
)
6036 || !MEM_P (DECL_RTL (exp
)))
6039 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
6043 case MISALIGNED_INDIRECT_REF
:
6044 case ALIGN_INDIRECT_REF
:
6047 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
6048 get_alias_set (exp
)))
6053 /* Assume that the call will clobber all hard registers and
6055 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
6060 case WITH_CLEANUP_EXPR
:
6061 case CLEANUP_POINT_EXPR
:
6062 /* Lowered by gimplify.c. */
6066 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
6072 /* If we have an rtx, we do not need to scan our operands. */
6076 nops
= TREE_CODE_LENGTH (TREE_CODE (exp
));
6077 for (i
= 0; i
< nops
; i
++)
6078 if (TREE_OPERAND (exp
, i
) != 0
6079 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
6082 /* If this is a language-specific tree code, it may require
6083 special handling. */
6084 if ((unsigned int) TREE_CODE (exp
)
6085 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
6086 && !lang_hooks
.safe_from_p (x
, exp
))
6091 /* Should never get a type here. */
6095 /* If we have an rtl, find any enclosed object. Then see if we conflict
6099 if (GET_CODE (exp_rtl
) == SUBREG
)
6101 exp_rtl
= SUBREG_REG (exp_rtl
);
6103 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
6107 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
6108 are memory and they conflict. */
6109 return ! (rtx_equal_p (x
, exp_rtl
)
6110 || (MEM_P (x
) && MEM_P (exp_rtl
)
6111 && true_dependence (exp_rtl
, VOIDmode
, x
,
6112 rtx_addr_varies_p
)));
6115 /* If we reach here, it is safe. */
6120 /* Return the highest power of two that EXP is known to be a multiple of.
6121 This is used in updating alignment of MEMs in array references. */
6123 unsigned HOST_WIDE_INT
6124 highest_pow2_factor (tree exp
)
6126 unsigned HOST_WIDE_INT c0
, c1
;
6128 switch (TREE_CODE (exp
))
6131 /* We can find the lowest bit that's a one. If the low
6132 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
6133 We need to handle this case since we can find it in a COND_EXPR,
6134 a MIN_EXPR, or a MAX_EXPR. If the constant overflows, we have an
6135 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
6137 if (TREE_CONSTANT_OVERFLOW (exp
))
6138 return BIGGEST_ALIGNMENT
;
6141 /* Note: tree_low_cst is intentionally not used here,
6142 we don't care about the upper bits. */
6143 c0
= TREE_INT_CST_LOW (exp
);
6145 return c0
? c0
: BIGGEST_ALIGNMENT
;
6149 case PLUS_EXPR
: case MINUS_EXPR
: case MIN_EXPR
: case MAX_EXPR
:
6150 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
6151 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
6152 return MIN (c0
, c1
);
6155 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
6156 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
6159 case ROUND_DIV_EXPR
: case TRUNC_DIV_EXPR
: case FLOOR_DIV_EXPR
:
6161 if (integer_pow2p (TREE_OPERAND (exp
, 1))
6162 && host_integerp (TREE_OPERAND (exp
, 1), 1))
6164 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
6165 c1
= tree_low_cst (TREE_OPERAND (exp
, 1), 1);
6166 return MAX (1, c0
/ c1
);
6170 case NON_LVALUE_EXPR
: case NOP_EXPR
: case CONVERT_EXPR
:
6172 return highest_pow2_factor (TREE_OPERAND (exp
, 0));
6175 return highest_pow2_factor (TREE_OPERAND (exp
, 1));
6178 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
6179 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 2));
6180 return MIN (c0
, c1
);
6189 /* Similar, except that the alignment requirements of TARGET are
6190 taken into account. Assume it is at least as aligned as its
6191 type, unless it is a COMPONENT_REF in which case the layout of
6192 the structure gives the alignment. */
6194 static unsigned HOST_WIDE_INT
6195 highest_pow2_factor_for_target (tree target
, tree exp
)
6197 unsigned HOST_WIDE_INT target_align
, factor
;
6199 factor
= highest_pow2_factor (exp
);
6200 if (TREE_CODE (target
) == COMPONENT_REF
)
6201 target_align
= DECL_ALIGN_UNIT (TREE_OPERAND (target
, 1));
6203 target_align
= TYPE_ALIGN_UNIT (TREE_TYPE (target
));
6204 return MAX (factor
, target_align
);
6207 /* Expands variable VAR. */
6210 expand_var (tree var
)
6212 if (DECL_EXTERNAL (var
))
6215 if (TREE_STATIC (var
))
6216 /* If this is an inlined copy of a static local variable,
6217 look up the original decl. */
6218 var
= DECL_ORIGIN (var
);
6220 if (TREE_STATIC (var
)
6221 ? !TREE_ASM_WRITTEN (var
)
6222 : !DECL_RTL_SET_P (var
))
6224 if (TREE_CODE (var
) == VAR_DECL
&& DECL_HAS_VALUE_EXPR_P (var
))
6225 /* Should be ignored. */;
6226 else if (lang_hooks
.expand_decl (var
))
6228 else if (TREE_CODE (var
) == VAR_DECL
&& !TREE_STATIC (var
))
6230 else if (TREE_CODE (var
) == VAR_DECL
&& TREE_STATIC (var
))
6231 rest_of_decl_compilation (var
, 0, 0);
6233 /* No expansion needed. */
6234 gcc_assert (TREE_CODE (var
) == TYPE_DECL
6235 || TREE_CODE (var
) == CONST_DECL
6236 || TREE_CODE (var
) == FUNCTION_DECL
6237 || TREE_CODE (var
) == LABEL_DECL
);
6241 /* Subroutine of expand_expr. Expand the two operands of a binary
6242 expression EXP0 and EXP1 placing the results in OP0 and OP1.
6243 The value may be stored in TARGET if TARGET is nonzero. The
6244 MODIFIER argument is as documented by expand_expr. */
6247 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
6248 enum expand_modifier modifier
)
6250 if (! safe_from_p (target
, exp1
, 1))
6252 if (operand_equal_p (exp0
, exp1
, 0))
6254 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
6255 *op1
= copy_rtx (*op0
);
6259 /* If we need to preserve evaluation order, copy exp0 into its own
6260 temporary variable so that it can't be clobbered by exp1. */
6261 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
6262 exp0
= save_expr (exp0
);
6263 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
6264 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
6269 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
6270 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
6273 expand_expr_addr_expr_1 (tree exp
, rtx target
, enum machine_mode tmode
,
6274 enum expand_modifier modifier
)
6276 rtx result
, subtarget
;
6278 HOST_WIDE_INT bitsize
, bitpos
;
6279 int volatilep
, unsignedp
;
6280 enum machine_mode mode1
;
6282 /* If we are taking the address of a constant and are at the top level,
6283 we have to use output_constant_def since we can't call force_const_mem
6285 /* ??? This should be considered a front-end bug. We should not be
6286 generating ADDR_EXPR of something that isn't an LVALUE. The only
6287 exception here is STRING_CST. */
6288 if (TREE_CODE (exp
) == CONSTRUCTOR
6289 || CONSTANT_CLASS_P (exp
))
6290 return XEXP (output_constant_def (exp
, 0), 0);
6292 /* Everything must be something allowed by is_gimple_addressable. */
6293 switch (TREE_CODE (exp
))
6296 /* This case will happen via recursion for &a->b. */
6297 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, EXPAND_NORMAL
);
6300 /* Recurse and make the output_constant_def clause above handle this. */
6301 return expand_expr_addr_expr_1 (DECL_INITIAL (exp
), target
,
6305 /* The real part of the complex number is always first, therefore
6306 the address is the same as the address of the parent object. */
6309 inner
= TREE_OPERAND (exp
, 0);
6313 /* The imaginary part of the complex number is always second.
6314 The expression is therefore always offset by the size of the
6317 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
6318 inner
= TREE_OPERAND (exp
, 0);
6322 /* If the object is a DECL, then expand it for its rtl. Don't bypass
6323 expand_expr, as that can have various side effects; LABEL_DECLs for
6324 example, may not have their DECL_RTL set yet. Assume language
6325 specific tree nodes can be expanded in some interesting way. */
6327 || TREE_CODE (exp
) >= LAST_AND_UNUSED_TREE_CODE
)
6329 result
= expand_expr (exp
, target
, tmode
,
6330 modifier
== EXPAND_INITIALIZER
6331 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
6333 /* If the DECL isn't in memory, then the DECL wasn't properly
6334 marked TREE_ADDRESSABLE, which will be either a front-end
6335 or a tree optimizer bug. */
6336 gcc_assert (MEM_P (result
));
6337 result
= XEXP (result
, 0);
6339 /* ??? Is this needed anymore? */
6340 if (DECL_P (exp
) && !TREE_USED (exp
) == 0)
6342 assemble_external (exp
);
6343 TREE_USED (exp
) = 1;
6346 if (modifier
!= EXPAND_INITIALIZER
6347 && modifier
!= EXPAND_CONST_ADDRESS
)
6348 result
= force_operand (result
, target
);
6352 /* Pass FALSE as the last argument to get_inner_reference although
6353 we are expanding to RTL. The rationale is that we know how to
6354 handle "aligning nodes" here: we can just bypass them because
6355 they won't change the final object whose address will be returned
6356 (they actually exist only for that purpose). */
6357 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
6358 &mode1
, &unsignedp
, &volatilep
, false);
6362 /* We must have made progress. */
6363 gcc_assert (inner
!= exp
);
6365 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
6366 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
);
6372 if (modifier
!= EXPAND_NORMAL
)
6373 result
= force_operand (result
, NULL
);
6374 tmp
= expand_expr (offset
, NULL
, tmode
, EXPAND_NORMAL
);
6376 result
= convert_memory_address (tmode
, result
);
6377 tmp
= convert_memory_address (tmode
, tmp
);
6379 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
6380 result
= gen_rtx_PLUS (tmode
, result
, tmp
);
6383 subtarget
= bitpos
? NULL_RTX
: target
;
6384 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
6385 1, OPTAB_LIB_WIDEN
);
6391 /* Someone beforehand should have rejected taking the address
6392 of such an object. */
6393 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
6395 result
= plus_constant (result
, bitpos
/ BITS_PER_UNIT
);
6396 if (modifier
< EXPAND_SUM
)
6397 result
= force_operand (result
, target
);
6403 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
6404 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
6407 expand_expr_addr_expr (tree exp
, rtx target
, enum machine_mode tmode
,
6408 enum expand_modifier modifier
)
6410 enum machine_mode rmode
;
6413 /* Target mode of VOIDmode says "whatever's natural". */
6414 if (tmode
== VOIDmode
)
6415 tmode
= TYPE_MODE (TREE_TYPE (exp
));
6417 /* We can get called with some Weird Things if the user does silliness
6418 like "(short) &a". In that case, convert_memory_address won't do
6419 the right thing, so ignore the given target mode. */
6420 if (tmode
!= Pmode
&& tmode
!= ptr_mode
)
6423 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
6426 /* Despite expand_expr claims concerning ignoring TMODE when not
6427 strictly convenient, stuff breaks if we don't honor it. Note
6428 that combined with the above, we only do this for pointer modes. */
6429 rmode
= GET_MODE (result
);
6430 if (rmode
== VOIDmode
)
6433 result
= convert_memory_address (tmode
, result
);
6439 /* expand_expr: generate code for computing expression EXP.
6440 An rtx for the computed value is returned. The value is never null.
6441 In the case of a void EXP, const0_rtx is returned.
6443 The value may be stored in TARGET if TARGET is nonzero.
6444 TARGET is just a suggestion; callers must assume that
6445 the rtx returned may not be the same as TARGET.
6447 If TARGET is CONST0_RTX, it means that the value will be ignored.
6449 If TMODE is not VOIDmode, it suggests generating the
6450 result in mode TMODE. But this is done only when convenient.
6451 Otherwise, TMODE is ignored and the value generated in its natural mode.
6452 TMODE is just a suggestion; callers must assume that
6453 the rtx returned may not have mode TMODE.
6455 Note that TARGET may have neither TMODE nor MODE. In that case, it
6456 probably will not be used.
6458 If MODIFIER is EXPAND_SUM then when EXP is an addition
6459 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
6460 or a nest of (PLUS ...) and (MINUS ...) where the terms are
6461 products as above, or REG or MEM, or constant.
6462 Ordinarily in such cases we would output mul or add instructions
6463 and then return a pseudo reg containing the sum.
6465 EXPAND_INITIALIZER is much like EXPAND_SUM except that
6466 it also marks a label as absolutely required (it can't be dead).
6467 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
6468 This is used for outputting expressions used in initializers.
6470 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
6471 with a constant address even if that address is not normally legitimate.
6472 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
6474 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
6475 a call parameter. Such targets require special care as we haven't yet
6476 marked TARGET so that it's safe from being trashed by libcalls. We
6477 don't want to use TARGET for anything but the final result;
6478 Intermediate values must go elsewhere. Additionally, calls to
6479 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
6481 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
6482 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
6483 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
6484 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
6487 static rtx
expand_expr_real_1 (tree
, rtx
, enum machine_mode
,
6488 enum expand_modifier
, rtx
*);
6491 expand_expr_real (tree exp
, rtx target
, enum machine_mode tmode
,
6492 enum expand_modifier modifier
, rtx
*alt_rtl
)
6495 rtx ret
, last
= NULL
;
6497 /* Handle ERROR_MARK before anybody tries to access its type. */
6498 if (TREE_CODE (exp
) == ERROR_MARK
6499 || TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
)
6501 ret
= CONST0_RTX (tmode
);
6502 return ret
? ret
: const0_rtx
;
6505 if (flag_non_call_exceptions
)
6507 rn
= lookup_stmt_eh_region (exp
);
6508 /* If rn < 0, then either (1) tree-ssa not used or (2) doesn't throw. */
6510 last
= get_last_insn ();
6513 /* If this is an expression of some kind and it has an associated line
6514 number, then emit the line number before expanding the expression.
6516 We need to save and restore the file and line information so that
6517 errors discovered during expansion are emitted with the right
6518 information. It would be better of the diagnostic routines
6519 used the file/line information embedded in the tree nodes rather
6521 if (cfun
&& cfun
->ib_boundaries_block
&& EXPR_HAS_LOCATION (exp
))
6523 location_t saved_location
= input_location
;
6524 input_location
= EXPR_LOCATION (exp
);
6525 emit_line_note (input_location
);
6527 /* Record where the insns produced belong. */
6528 record_block_change (TREE_BLOCK (exp
));
6530 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
6532 input_location
= saved_location
;
6536 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
6539 /* If using non-call exceptions, mark all insns that may trap.
6540 expand_call() will mark CALL_INSNs before we get to this code,
6541 but it doesn't handle libcalls, and these may trap. */
6545 for (insn
= next_real_insn (last
); insn
;
6546 insn
= next_real_insn (insn
))
6548 if (! find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
)
6549 /* If we want exceptions for non-call insns, any
6550 may_trap_p instruction may throw. */
6551 && GET_CODE (PATTERN (insn
)) != CLOBBER
6552 && GET_CODE (PATTERN (insn
)) != USE
6553 && (CALL_P (insn
) || may_trap_p (PATTERN (insn
))))
6555 REG_NOTES (insn
) = alloc_EXPR_LIST (REG_EH_REGION
, GEN_INT (rn
),
6565 expand_expr_real_1 (tree exp
, rtx target
, enum machine_mode tmode
,
6566 enum expand_modifier modifier
, rtx
*alt_rtl
)
6569 tree type
= TREE_TYPE (exp
);
6571 enum machine_mode mode
;
6572 enum tree_code code
= TREE_CODE (exp
);
6574 rtx subtarget
, original_target
;
6577 bool reduce_bit_field
= false;
6578 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field && !ignore \
6579 ? reduce_to_bit_field_precision ((expr), \
6584 mode
= TYPE_MODE (type
);
6585 unsignedp
= TYPE_UNSIGNED (type
);
6586 if (lang_hooks
.reduce_bit_field_operations
6587 && TREE_CODE (type
) == INTEGER_TYPE
6588 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
))
6590 /* An operation in what may be a bit-field type needs the
6591 result to be reduced to the precision of the bit-field type,
6592 which is narrower than that of the type's mode. */
6593 reduce_bit_field
= true;
6594 if (modifier
== EXPAND_STACK_PARM
)
6598 /* Use subtarget as the target for operand 0 of a binary operation. */
6599 subtarget
= get_subtarget (target
);
6600 original_target
= target
;
6601 ignore
= (target
== const0_rtx
6602 || ((code
== NON_LVALUE_EXPR
|| code
== NOP_EXPR
6603 || code
== CONVERT_EXPR
|| code
== COND_EXPR
6604 || code
== VIEW_CONVERT_EXPR
)
6605 && TREE_CODE (type
) == VOID_TYPE
));
6607 /* If we are going to ignore this result, we need only do something
6608 if there is a side-effect somewhere in the expression. If there
6609 is, short-circuit the most common cases here. Note that we must
6610 not call expand_expr with anything but const0_rtx in case this
6611 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
6615 if (! TREE_SIDE_EFFECTS (exp
))
6618 /* Ensure we reference a volatile object even if value is ignored, but
6619 don't do this if all we are doing is taking its address. */
6620 if (TREE_THIS_VOLATILE (exp
)
6621 && TREE_CODE (exp
) != FUNCTION_DECL
6622 && mode
!= VOIDmode
&& mode
!= BLKmode
6623 && modifier
!= EXPAND_CONST_ADDRESS
)
6625 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
6627 temp
= copy_to_reg (temp
);
6631 if (TREE_CODE_CLASS (code
) == tcc_unary
6632 || code
== COMPONENT_REF
|| code
== INDIRECT_REF
)
6633 return expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
6636 else if (TREE_CODE_CLASS (code
) == tcc_binary
6637 || TREE_CODE_CLASS (code
) == tcc_comparison
6638 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
6640 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
, modifier
);
6641 expand_expr (TREE_OPERAND (exp
, 1), const0_rtx
, VOIDmode
, modifier
);
6644 else if (code
== BIT_FIELD_REF
)
6646 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
, modifier
);
6647 expand_expr (TREE_OPERAND (exp
, 1), const0_rtx
, VOIDmode
, modifier
);
6648 expand_expr (TREE_OPERAND (exp
, 2), const0_rtx
, VOIDmode
, modifier
);
6660 tree function
= decl_function_context (exp
);
6662 temp
= label_rtx (exp
);
6663 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
6665 if (function
!= current_function_decl
6667 LABEL_REF_NONLOCAL_P (temp
) = 1;
6669 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
6674 return expand_expr_real_1 (SSA_NAME_VAR (exp
), target
, tmode
, modifier
,
6679 /* If a static var's type was incomplete when the decl was written,
6680 but the type is complete now, lay out the decl now. */
6681 if (DECL_SIZE (exp
) == 0
6682 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
6683 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
6684 layout_decl (exp
, 0);
6686 /* ... fall through ... */
6690 gcc_assert (DECL_RTL (exp
));
6692 /* Ensure variable marked as used even if it doesn't go through
6693 a parser. If it hasn't be used yet, write out an external
6695 if (! TREE_USED (exp
))
6697 assemble_external (exp
);
6698 TREE_USED (exp
) = 1;
6701 /* Show we haven't gotten RTL for this yet. */
6704 /* Variables inherited from containing functions should have
6705 been lowered by this point. */
6706 context
= decl_function_context (exp
);
6707 gcc_assert (!context
6708 || context
== current_function_decl
6709 || TREE_STATIC (exp
)
6710 /* ??? C++ creates functions that are not TREE_STATIC. */
6711 || TREE_CODE (exp
) == FUNCTION_DECL
);
6713 /* This is the case of an array whose size is to be determined
6714 from its initializer, while the initializer is still being parsed.
6717 if (MEM_P (DECL_RTL (exp
))
6718 && REG_P (XEXP (DECL_RTL (exp
), 0)))
6719 temp
= validize_mem (DECL_RTL (exp
));
6721 /* If DECL_RTL is memory, we are in the normal case and either
6722 the address is not valid or it is not a register and -fforce-addr
6723 is specified, get the address into a register. */
6725 else if (MEM_P (DECL_RTL (exp
))
6726 && modifier
!= EXPAND_CONST_ADDRESS
6727 && modifier
!= EXPAND_SUM
6728 && modifier
!= EXPAND_INITIALIZER
6729 && (! memory_address_p (DECL_MODE (exp
),
6730 XEXP (DECL_RTL (exp
), 0))
6732 && !REG_P (XEXP (DECL_RTL (exp
), 0)))))
6735 *alt_rtl
= DECL_RTL (exp
);
6736 temp
= replace_equiv_address (DECL_RTL (exp
),
6737 copy_rtx (XEXP (DECL_RTL (exp
), 0)));
6740 /* If we got something, return it. But first, set the alignment
6741 if the address is a register. */
6744 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
6745 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
6750 /* If the mode of DECL_RTL does not match that of the decl, it
6751 must be a promoted value. We return a SUBREG of the wanted mode,
6752 but mark it so that we know that it was already extended. */
6754 if (REG_P (DECL_RTL (exp
))
6755 && GET_MODE (DECL_RTL (exp
)) != DECL_MODE (exp
))
6757 enum machine_mode pmode
;
6759 /* Get the signedness used for this variable. Ensure we get the
6760 same mode we got when the variable was declared. */
6761 pmode
= promote_mode (type
, DECL_MODE (exp
), &unsignedp
,
6762 (TREE_CODE (exp
) == RESULT_DECL
? 1 : 0));
6763 gcc_assert (GET_MODE (DECL_RTL (exp
)) == pmode
);
6765 temp
= gen_lowpart_SUBREG (mode
, DECL_RTL (exp
));
6766 SUBREG_PROMOTED_VAR_P (temp
) = 1;
6767 SUBREG_PROMOTED_UNSIGNED_SET (temp
, unsignedp
);
6771 return DECL_RTL (exp
);
6774 temp
= immed_double_const (TREE_INT_CST_LOW (exp
),
6775 TREE_INT_CST_HIGH (exp
), mode
);
6777 /* ??? If overflow is set, fold will have done an incomplete job,
6778 which can result in (plus xx (const_int 0)), which can get
6779 simplified by validate_replace_rtx during virtual register
6780 instantiation, which can result in unrecognizable insns.
6781 Avoid this by forcing all overflows into registers. */
6782 if (TREE_CONSTANT_OVERFLOW (exp
)
6783 && modifier
!= EXPAND_INITIALIZER
)
6784 temp
= force_reg (mode
, temp
);
6789 if (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (exp
))) == MODE_VECTOR_INT
6790 || GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (exp
))) == MODE_VECTOR_FLOAT
)
6791 return const_vector_from_tree (exp
);
6793 return expand_expr (build_constructor_from_list
6795 TREE_VECTOR_CST_ELTS (exp
)),
6796 ignore
? const0_rtx
: target
, tmode
, modifier
);
6799 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
6802 /* If optimized, generate immediate CONST_DOUBLE
6803 which will be turned into memory by reload if necessary.
6805 We used to force a register so that loop.c could see it. But
6806 this does not allow gen_* patterns to perform optimizations with
6807 the constants. It also produces two insns in cases like "x = 1.0;".
6808 On most machines, floating-point constants are not permitted in
6809 many insns, so we'd end up copying it to a register in any case.
6811 Now, we do the copying in expand_binop, if appropriate. */
6812 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
6813 TYPE_MODE (TREE_TYPE (exp
)));
6816 /* Handle evaluating a complex constant in a CONCAT target. */
6817 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
6819 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
6822 rtarg
= XEXP (original_target
, 0);
6823 itarg
= XEXP (original_target
, 1);
6825 /* Move the real and imaginary parts separately. */
6826 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, 0);
6827 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, 0);
6830 emit_move_insn (rtarg
, op0
);
6832 emit_move_insn (itarg
, op1
);
6834 return original_target
;
6837 /* ... fall through ... */
6840 temp
= output_constant_def (exp
, 1);
6842 /* temp contains a constant address.
6843 On RISC machines where a constant address isn't valid,
6844 make some insns to get that address into a register. */
6845 if (modifier
!= EXPAND_CONST_ADDRESS
6846 && modifier
!= EXPAND_INITIALIZER
6847 && modifier
!= EXPAND_SUM
6848 && (! memory_address_p (mode
, XEXP (temp
, 0))
6849 || flag_force_addr
))
6850 return replace_equiv_address (temp
,
6851 copy_rtx (XEXP (temp
, 0)));
6856 tree val
= TREE_OPERAND (exp
, 0);
6857 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
);
6859 if (!SAVE_EXPR_RESOLVED_P (exp
))
6861 /* We can indeed still hit this case, typically via builtin
6862 expanders calling save_expr immediately before expanding
6863 something. Assume this means that we only have to deal
6864 with non-BLKmode values. */
6865 gcc_assert (GET_MODE (ret
) != BLKmode
);
6867 val
= build_decl (VAR_DECL
, NULL
, TREE_TYPE (exp
));
6868 DECL_ARTIFICIAL (val
) = 1;
6869 DECL_IGNORED_P (val
) = 1;
6870 TREE_OPERAND (exp
, 0) = val
;
6871 SAVE_EXPR_RESOLVED_P (exp
) = 1;
6873 if (!CONSTANT_P (ret
))
6874 ret
= copy_to_reg (ret
);
6875 SET_DECL_RTL (val
, ret
);
6882 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == LABEL_DECL
)
6883 expand_goto (TREE_OPERAND (exp
, 0));
6885 expand_computed_goto (TREE_OPERAND (exp
, 0));
6889 /* If we don't need the result, just ensure we evaluate any
6893 unsigned HOST_WIDE_INT idx
;
6896 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6897 expand_expr (value
, const0_rtx
, VOIDmode
, 0);
6902 /* Try to avoid creating a temporary at all. This is possible
6903 if all of the initializer is zero.
6904 FIXME: try to handle all [0..255] initializers we can handle
6906 else if (TREE_STATIC (exp
)
6907 && !TREE_ADDRESSABLE (exp
)
6908 && target
!= 0 && mode
== BLKmode
6909 && all_zeros_p (exp
))
6911 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
6915 /* All elts simple constants => refer to a constant in memory. But
6916 if this is a non-BLKmode mode, let it store a field at a time
6917 since that should make a CONST_INT or CONST_DOUBLE when we
6918 fold. Likewise, if we have a target we can use, it is best to
6919 store directly into the target unless the type is large enough
6920 that memcpy will be used. If we are making an initializer and
6921 all operands are constant, put it in memory as well.
6923 FIXME: Avoid trying to fill vector constructors piece-meal.
6924 Output them with output_constant_def below unless we're sure
6925 they're zeros. This should go away when vector initializers
6926 are treated like VECTOR_CST instead of arrays.
6928 else if ((TREE_STATIC (exp
)
6929 && ((mode
== BLKmode
6930 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
6931 || TREE_ADDRESSABLE (exp
)
6932 || (host_integerp (TYPE_SIZE_UNIT (type
), 1)
6933 && (! MOVE_BY_PIECES_P
6934 (tree_low_cst (TYPE_SIZE_UNIT (type
), 1),
6936 && ! mostly_zeros_p (exp
))))
6937 || ((modifier
== EXPAND_INITIALIZER
6938 || modifier
== EXPAND_CONST_ADDRESS
)
6939 && TREE_CONSTANT (exp
)))
6941 rtx constructor
= output_constant_def (exp
, 1);
6943 if (modifier
!= EXPAND_CONST_ADDRESS
6944 && modifier
!= EXPAND_INITIALIZER
6945 && modifier
!= EXPAND_SUM
)
6946 constructor
= validize_mem (constructor
);
6952 /* Handle calls that pass values in multiple non-contiguous
6953 locations. The Irix 6 ABI has examples of this. */
6954 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
6955 || GET_CODE (target
) == PARALLEL
6956 || modifier
== EXPAND_STACK_PARM
)
6958 = assign_temp (build_qualified_type (type
,
6960 | (TREE_READONLY (exp
)
6961 * TYPE_QUAL_CONST
))),
6962 0, TREE_ADDRESSABLE (exp
), 1);
6964 store_constructor (exp
, target
, 0, int_expr_size (exp
));
6968 case MISALIGNED_INDIRECT_REF
:
6969 case ALIGN_INDIRECT_REF
:
6972 tree exp1
= TREE_OPERAND (exp
, 0);
6974 if (modifier
!= EXPAND_WRITE
)
6978 t
= fold_read_from_constant_string (exp
);
6980 return expand_expr (t
, target
, tmode
, modifier
);
6983 op0
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
6984 op0
= memory_address (mode
, op0
);
6986 if (code
== ALIGN_INDIRECT_REF
)
6988 int align
= TYPE_ALIGN_UNIT (type
);
6989 op0
= gen_rtx_AND (Pmode
, op0
, GEN_INT (-align
));
6990 op0
= memory_address (mode
, op0
);
6993 temp
= gen_rtx_MEM (mode
, op0
);
6995 set_mem_attributes (temp
, exp
, 0);
6997 /* Resolve the misalignment now, so that we don't have to remember
6998 to resolve it later. Of course, this only works for reads. */
6999 /* ??? When we get around to supporting writes, we'll have to handle
7000 this in store_expr directly. The vectorizer isn't generating
7001 those yet, however. */
7002 if (code
== MISALIGNED_INDIRECT_REF
)
7007 gcc_assert (modifier
== EXPAND_NORMAL
7008 || modifier
== EXPAND_STACK_PARM
);
7010 /* The vectorizer should have already checked the mode. */
7011 icode
= movmisalign_optab
->handlers
[mode
].insn_code
;
7012 gcc_assert (icode
!= CODE_FOR_nothing
);
7014 /* We've already validated the memory, and we're creating a
7015 new pseudo destination. The predicates really can't fail. */
7016 reg
= gen_reg_rtx (mode
);
7018 /* Nor can the insn generator. */
7019 insn
= GEN_FCN (icode
) (reg
, temp
);
7028 case TARGET_MEM_REF
:
7030 struct mem_address addr
;
7032 get_address_description (exp
, &addr
);
7033 op0
= addr_for_mem_ref (&addr
, true);
7034 op0
= memory_address (mode
, op0
);
7035 temp
= gen_rtx_MEM (mode
, op0
);
7036 set_mem_attributes (temp
, TMR_ORIGINAL (exp
), 0);
7043 tree array
= TREE_OPERAND (exp
, 0);
7044 tree index
= TREE_OPERAND (exp
, 1);
7046 /* Fold an expression like: "foo"[2].
7047 This is not done in fold so it won't happen inside &.
7048 Don't fold if this is for wide characters since it's too
7049 difficult to do correctly and this is a very rare case. */
7051 if (modifier
!= EXPAND_CONST_ADDRESS
7052 && modifier
!= EXPAND_INITIALIZER
7053 && modifier
!= EXPAND_MEMORY
)
7055 tree t
= fold_read_from_constant_string (exp
);
7058 return expand_expr (t
, target
, tmode
, modifier
);
7061 /* If this is a constant index into a constant array,
7062 just get the value from the array. Handle both the cases when
7063 we have an explicit constructor and when our operand is a variable
7064 that was declared const. */
7066 if (modifier
!= EXPAND_CONST_ADDRESS
7067 && modifier
!= EXPAND_INITIALIZER
7068 && modifier
!= EXPAND_MEMORY
7069 && TREE_CODE (array
) == CONSTRUCTOR
7070 && ! TREE_SIDE_EFFECTS (array
)
7071 && TREE_CODE (index
) == INTEGER_CST
)
7073 unsigned HOST_WIDE_INT ix
;
7076 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
7078 if (tree_int_cst_equal (field
, index
))
7080 if (!TREE_SIDE_EFFECTS (value
))
7081 return expand_expr (fold (value
), target
, tmode
, modifier
);
7086 else if (optimize
>= 1
7087 && modifier
!= EXPAND_CONST_ADDRESS
7088 && modifier
!= EXPAND_INITIALIZER
7089 && modifier
!= EXPAND_MEMORY
7090 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
7091 && TREE_CODE (array
) == VAR_DECL
&& DECL_INITIAL (array
)
7092 && TREE_CODE (DECL_INITIAL (array
)) != ERROR_MARK
7093 && targetm
.binds_local_p (array
))
7095 if (TREE_CODE (index
) == INTEGER_CST
)
7097 tree init
= DECL_INITIAL (array
);
7099 if (TREE_CODE (init
) == CONSTRUCTOR
)
7101 unsigned HOST_WIDE_INT ix
;
7104 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
7106 if (tree_int_cst_equal (field
, index
))
7108 if (!TREE_SIDE_EFFECTS (value
))
7109 return expand_expr (fold (value
), target
, tmode
,
7114 else if(TREE_CODE (init
) == STRING_CST
)
7116 tree index1
= index
;
7117 tree low_bound
= array_ref_low_bound (exp
);
7118 index1
= fold_convert (sizetype
, TREE_OPERAND (exp
, 1));
7120 /* Optimize the special-case of a zero lower bound.
7122 We convert the low_bound to sizetype to avoid some problems
7123 with constant folding. (E.g. suppose the lower bound is 1,
7124 and its mode is QI. Without the conversion,l (ARRAY
7125 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
7126 +INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
7128 if (! integer_zerop (low_bound
))
7129 index1
= size_diffop (index1
, fold_convert (sizetype
,
7132 if (0 > compare_tree_int (index1
,
7133 TREE_STRING_LENGTH (init
)))
7135 tree type
= TREE_TYPE (TREE_TYPE (init
));
7136 enum machine_mode mode
= TYPE_MODE (type
);
7138 if (GET_MODE_CLASS (mode
) == MODE_INT
7139 && GET_MODE_SIZE (mode
) == 1)
7140 return gen_int_mode (TREE_STRING_POINTER (init
)
7141 [TREE_INT_CST_LOW (index1
)],
7148 goto normal_inner_ref
;
7151 /* If the operand is a CONSTRUCTOR, we can just extract the
7152 appropriate field if it is present. */
7153 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == CONSTRUCTOR
)
7155 unsigned HOST_WIDE_INT idx
;
7158 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (TREE_OPERAND (exp
, 0)),
7160 if (field
== TREE_OPERAND (exp
, 1)
7161 /* We can normally use the value of the field in the
7162 CONSTRUCTOR. However, if this is a bitfield in
7163 an integral mode that we can fit in a HOST_WIDE_INT,
7164 we must mask only the number of bits in the bitfield,
7165 since this is done implicitly by the constructor. If
7166 the bitfield does not meet either of those conditions,
7167 we can't do this optimization. */
7168 && (! DECL_BIT_FIELD (field
)
7169 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
7170 && (GET_MODE_BITSIZE (DECL_MODE (field
))
7171 <= HOST_BITS_PER_WIDE_INT
))))
7173 if (DECL_BIT_FIELD (field
)
7174 && modifier
== EXPAND_STACK_PARM
)
7176 op0
= expand_expr (value
, target
, tmode
, modifier
);
7177 if (DECL_BIT_FIELD (field
))
7179 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
7180 enum machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
7182 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
7184 op1
= GEN_INT (((HOST_WIDE_INT
) 1 << bitsize
) - 1);
7185 op0
= expand_and (imode
, op0
, op1
, target
);
7190 = build_int_cst (NULL_TREE
,
7191 GET_MODE_BITSIZE (imode
) - bitsize
);
7193 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
7195 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
7203 goto normal_inner_ref
;
7206 case ARRAY_RANGE_REF
:
7209 enum machine_mode mode1
;
7210 HOST_WIDE_INT bitsize
, bitpos
;
7213 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7214 &mode1
, &unsignedp
, &volatilep
, true);
7217 /* If we got back the original object, something is wrong. Perhaps
7218 we are evaluating an expression too early. In any event, don't
7219 infinitely recurse. */
7220 gcc_assert (tem
!= exp
);
7222 /* If TEM's type is a union of variable size, pass TARGET to the inner
7223 computation, since it will need a temporary and TARGET is known
7224 to have to do. This occurs in unchecked conversion in Ada. */
7228 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
7229 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
7231 && modifier
!= EXPAND_STACK_PARM
7232 ? target
: NULL_RTX
),
7234 (modifier
== EXPAND_INITIALIZER
7235 || modifier
== EXPAND_CONST_ADDRESS
7236 || modifier
== EXPAND_STACK_PARM
)
7237 ? modifier
: EXPAND_NORMAL
);
7239 /* If this is a constant, put it into a register if it is a legitimate
7240 constant, OFFSET is 0, and we won't try to extract outside the
7241 register (in case we were passed a partially uninitialized object
7242 or a view_conversion to a larger size). Force the constant to
7243 memory otherwise. */
7244 if (CONSTANT_P (op0
))
7246 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (tem
));
7247 if (mode
!= BLKmode
&& LEGITIMATE_CONSTANT_P (op0
)
7249 && bitpos
+ bitsize
<= GET_MODE_BITSIZE (mode
))
7250 op0
= force_reg (mode
, op0
);
7252 op0
= validize_mem (force_const_mem (mode
, op0
));
7255 /* Otherwise, if this object not in memory and we either have an
7256 offset, a BLKmode result, or a reference outside the object, put it
7257 there. Such cases can occur in Ada if we have unchecked conversion
7258 of an expression from a scalar type to an array or record type or
7259 for an ARRAY_RANGE_REF whose type is BLKmode. */
7260 else if (!MEM_P (op0
)
7262 || (bitpos
+ bitsize
> GET_MODE_BITSIZE (GET_MODE (op0
)))
7263 || (code
== ARRAY_RANGE_REF
&& mode
== BLKmode
)))
7265 tree nt
= build_qualified_type (TREE_TYPE (tem
),
7266 (TYPE_QUALS (TREE_TYPE (tem
))
7267 | TYPE_QUAL_CONST
));
7268 rtx memloc
= assign_temp (nt
, 1, 1, 1);
7270 emit_move_insn (memloc
, op0
);
7276 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
7279 gcc_assert (MEM_P (op0
));
7281 #ifdef POINTERS_EXTEND_UNSIGNED
7282 if (GET_MODE (offset_rtx
) != Pmode
)
7283 offset_rtx
= convert_to_mode (Pmode
, offset_rtx
, 0);
7285 if (GET_MODE (offset_rtx
) != ptr_mode
)
7286 offset_rtx
= convert_to_mode (ptr_mode
, offset_rtx
, 0);
7289 if (GET_MODE (op0
) == BLKmode
7290 /* A constant address in OP0 can have VOIDmode, we must
7291 not try to call force_reg in that case. */
7292 && GET_MODE (XEXP (op0
, 0)) != VOIDmode
7294 && (bitpos
% bitsize
) == 0
7295 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
7296 && MEM_ALIGN (op0
) == GET_MODE_ALIGNMENT (mode1
))
7298 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
7302 op0
= offset_address (op0
, offset_rtx
,
7303 highest_pow2_factor (offset
));
7306 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
7307 record its alignment as BIGGEST_ALIGNMENT. */
7308 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
7309 && is_aligning_offset (offset
, tem
))
7310 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
7312 /* Don't forget about volatility even if this is a bitfield. */
7313 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
7315 if (op0
== orig_op0
)
7316 op0
= copy_rtx (op0
);
7318 MEM_VOLATILE_P (op0
) = 1;
7321 /* The following code doesn't handle CONCAT.
7322 Assume only bitpos == 0 can be used for CONCAT, due to
7323 one element arrays having the same mode as its element. */
7324 if (GET_CODE (op0
) == CONCAT
)
7326 gcc_assert (bitpos
== 0
7327 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)));
7331 /* In cases where an aligned union has an unaligned object
7332 as a field, we might be extracting a BLKmode value from
7333 an integer-mode (e.g., SImode) object. Handle this case
7334 by doing the extract into an object as wide as the field
7335 (which we know to be the width of a basic mode), then
7336 storing into memory, and changing the mode to BLKmode. */
7337 if (mode1
== VOIDmode
7338 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
7339 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
7340 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
7341 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
7342 && modifier
!= EXPAND_CONST_ADDRESS
7343 && modifier
!= EXPAND_INITIALIZER
)
7344 /* If the field isn't aligned enough to fetch as a memref,
7345 fetch it as a bit field. */
7346 || (mode1
!= BLKmode
7347 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
7348 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
7350 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
7351 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
7352 && ((modifier
== EXPAND_CONST_ADDRESS
7353 || modifier
== EXPAND_INITIALIZER
)
7355 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
7356 || (bitpos
% BITS_PER_UNIT
!= 0)))
7357 /* If the type and the field are a constant size and the
7358 size of the type isn't the same size as the bitfield,
7359 we must use bitfield operations. */
7361 && TYPE_SIZE (TREE_TYPE (exp
))
7362 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
7363 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
7366 enum machine_mode ext_mode
= mode
;
7368 if (ext_mode
== BLKmode
7369 && ! (target
!= 0 && MEM_P (op0
)
7371 && bitpos
% BITS_PER_UNIT
== 0))
7372 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
7374 if (ext_mode
== BLKmode
)
7377 target
= assign_temp (type
, 0, 1, 1);
7382 /* In this case, BITPOS must start at a byte boundary and
7383 TARGET, if specified, must be a MEM. */
7384 gcc_assert (MEM_P (op0
)
7385 && (!target
|| MEM_P (target
))
7386 && !(bitpos
% BITS_PER_UNIT
));
7388 emit_block_move (target
,
7389 adjust_address (op0
, VOIDmode
,
7390 bitpos
/ BITS_PER_UNIT
),
7391 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
7393 (modifier
== EXPAND_STACK_PARM
7394 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
7399 op0
= validize_mem (op0
);
7401 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
7402 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
7404 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
7405 (modifier
== EXPAND_STACK_PARM
7406 ? NULL_RTX
: target
),
7407 ext_mode
, ext_mode
);
7409 /* If the result is a record type and BITSIZE is narrower than
7410 the mode of OP0, an integral mode, and this is a big endian
7411 machine, we must put the field into the high-order bits. */
7412 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
7413 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
7414 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
7415 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
7416 size_int (GET_MODE_BITSIZE (GET_MODE (op0
))
7420 /* If the result type is BLKmode, store the data into a temporary
7421 of the appropriate type, but with the mode corresponding to the
7422 mode for the data we have (op0's mode). It's tempting to make
7423 this a constant type, since we know it's only being stored once,
7424 but that can cause problems if we are taking the address of this
7425 COMPONENT_REF because the MEM of any reference via that address
7426 will have flags corresponding to the type, which will not
7427 necessarily be constant. */
7428 if (mode
== BLKmode
)
7431 = assign_stack_temp_for_type
7432 (ext_mode
, GET_MODE_BITSIZE (ext_mode
), 0, type
);
7434 emit_move_insn (new, op0
);
7435 op0
= copy_rtx (new);
7436 PUT_MODE (op0
, BLKmode
);
7437 set_mem_attributes (op0
, exp
, 1);
7443 /* If the result is BLKmode, use that to access the object
7445 if (mode
== BLKmode
)
7448 /* Get a reference to just this component. */
7449 if (modifier
== EXPAND_CONST_ADDRESS
7450 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7451 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
7453 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
7455 if (op0
== orig_op0
)
7456 op0
= copy_rtx (op0
);
7458 set_mem_attributes (op0
, exp
, 0);
7459 if (REG_P (XEXP (op0
, 0)))
7460 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
7462 MEM_VOLATILE_P (op0
) |= volatilep
;
7463 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
7464 || modifier
== EXPAND_CONST_ADDRESS
7465 || modifier
== EXPAND_INITIALIZER
)
7467 else if (target
== 0)
7468 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
7470 convert_move (target
, op0
, unsignedp
);
7475 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
7478 /* Check for a built-in function. */
7479 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
7480 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
7482 && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)))
7484 if (DECL_BUILT_IN_CLASS (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
7485 == BUILT_IN_FRONTEND
)
7486 return lang_hooks
.expand_expr (exp
, original_target
,
7490 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
7493 return expand_call (exp
, target
, ignore
);
7495 case NON_LVALUE_EXPR
:
7498 if (TREE_OPERAND (exp
, 0) == error_mark_node
)
7501 if (TREE_CODE (type
) == UNION_TYPE
)
7503 tree valtype
= TREE_TYPE (TREE_OPERAND (exp
, 0));
7505 /* If both input and output are BLKmode, this conversion isn't doing
7506 anything except possibly changing memory attribute. */
7507 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
7509 rtx result
= expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
,
7512 result
= copy_rtx (result
);
7513 set_mem_attributes (result
, exp
, 0);
7519 if (TYPE_MODE (type
) != BLKmode
)
7520 target
= gen_reg_rtx (TYPE_MODE (type
));
7522 target
= assign_temp (type
, 0, 1, 1);
7526 /* Store data into beginning of memory target. */
7527 store_expr (TREE_OPERAND (exp
, 0),
7528 adjust_address (target
, TYPE_MODE (valtype
), 0),
7529 modifier
== EXPAND_STACK_PARM
);
7533 gcc_assert (REG_P (target
));
7535 /* Store this field into a union of the proper type. */
7536 store_field (target
,
7537 MIN ((int_size_in_bytes (TREE_TYPE
7538 (TREE_OPERAND (exp
, 0)))
7540 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
7541 0, TYPE_MODE (valtype
), TREE_OPERAND (exp
, 0),
7545 /* Return the entire union. */
7549 if (mode
== TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0))))
7551 op0
= expand_expr (TREE_OPERAND (exp
, 0), target
, VOIDmode
,
7554 /* If the signedness of the conversion differs and OP0 is
7555 a promoted SUBREG, clear that indication since we now
7556 have to do the proper extension. */
7557 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0))) != unsignedp
7558 && GET_CODE (op0
) == SUBREG
)
7559 SUBREG_PROMOTED_VAR_P (op0
) = 0;
7561 return REDUCE_BIT_FIELD (op0
);
7564 op0
= expand_expr (TREE_OPERAND (exp
, 0), NULL_RTX
, mode
,
7565 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
7566 if (GET_MODE (op0
) == mode
)
7569 /* If OP0 is a constant, just convert it into the proper mode. */
7570 else if (CONSTANT_P (op0
))
7572 tree inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
7573 enum machine_mode inner_mode
= TYPE_MODE (inner_type
);
7575 if (modifier
== EXPAND_INITIALIZER
)
7576 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
7577 subreg_lowpart_offset (mode
,
7580 op0
= convert_modes (mode
, inner_mode
, op0
,
7581 TYPE_UNSIGNED (inner_type
));
7584 else if (modifier
== EXPAND_INITIALIZER
)
7585 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
7587 else if (target
== 0)
7588 op0
= convert_to_mode (mode
, op0
,
7589 TYPE_UNSIGNED (TREE_TYPE
7590 (TREE_OPERAND (exp
, 0))));
7593 convert_move (target
, op0
,
7594 TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0))));
7598 return REDUCE_BIT_FIELD (op0
);
7600 case VIEW_CONVERT_EXPR
:
7601 op0
= expand_expr (TREE_OPERAND (exp
, 0), NULL_RTX
, mode
, modifier
);
7603 /* If the input and output modes are both the same, we are done. */
7604 if (TYPE_MODE (type
) == GET_MODE (op0
))
7606 /* If neither mode is BLKmode, and both modes are the same size
7607 then we can use gen_lowpart. */
7608 else if (TYPE_MODE (type
) != BLKmode
&& GET_MODE (op0
) != BLKmode
7609 && GET_MODE_SIZE (TYPE_MODE (type
))
7610 == GET_MODE_SIZE (GET_MODE (op0
)))
7612 if (GET_CODE (op0
) == SUBREG
)
7613 op0
= force_reg (GET_MODE (op0
), op0
);
7614 op0
= gen_lowpart (TYPE_MODE (type
), op0
);
7616 /* If both modes are integral, then we can convert from one to the
7618 else if (SCALAR_INT_MODE_P (GET_MODE (op0
))
7619 && SCALAR_INT_MODE_P (TYPE_MODE (type
)))
7620 op0
= convert_modes (TYPE_MODE (type
), GET_MODE (op0
), op0
,
7621 TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0))));
7622 /* As a last resort, spill op0 to memory, and reload it in a
7624 else if (!MEM_P (op0
))
7626 /* If the operand is not a MEM, force it into memory. Since we
7627 are going to be be changing the mode of the MEM, don't call
7628 force_const_mem for constants because we don't allow pool
7629 constants to change mode. */
7630 tree inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
7632 gcc_assert (!TREE_ADDRESSABLE (exp
));
7634 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
7636 = assign_stack_temp_for_type
7637 (TYPE_MODE (inner_type
),
7638 GET_MODE_SIZE (TYPE_MODE (inner_type
)), 0, inner_type
);
7640 emit_move_insn (target
, op0
);
7644 /* At this point, OP0 is in the correct mode. If the output type is such
7645 that the operand is known to be aligned, indicate that it is.
7646 Otherwise, we need only be concerned about alignment for non-BLKmode
7650 op0
= copy_rtx (op0
);
7652 if (TYPE_ALIGN_OK (type
))
7653 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
7654 else if (TYPE_MODE (type
) != BLKmode
&& STRICT_ALIGNMENT
7655 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (TYPE_MODE (type
)))
7657 tree inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
7658 HOST_WIDE_INT temp_size
7659 = MAX (int_size_in_bytes (inner_type
),
7660 (HOST_WIDE_INT
) GET_MODE_SIZE (TYPE_MODE (type
)));
7661 rtx
new = assign_stack_temp_for_type (TYPE_MODE (type
),
7662 temp_size
, 0, type
);
7663 rtx new_with_op0_mode
= adjust_address (new, GET_MODE (op0
), 0);
7665 gcc_assert (!TREE_ADDRESSABLE (exp
));
7667 if (GET_MODE (op0
) == BLKmode
)
7668 emit_block_move (new_with_op0_mode
, op0
,
7669 GEN_INT (GET_MODE_SIZE (TYPE_MODE (type
))),
7670 (modifier
== EXPAND_STACK_PARM
7671 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
7673 emit_move_insn (new_with_op0_mode
, op0
);
7678 op0
= adjust_address (op0
, TYPE_MODE (type
), 0);
7684 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
7685 something else, make sure we add the register to the constant and
7686 then to the other thing. This case can occur during strength
7687 reduction and doing it this way will produce better code if the
7688 frame pointer or argument pointer is eliminated.
7690 fold-const.c will ensure that the constant is always in the inner
7691 PLUS_EXPR, so the only case we need to do anything about is if
7692 sp, ap, or fp is our second argument, in which case we must swap
7693 the innermost first argument and our second argument. */
7695 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == PLUS_EXPR
7696 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 1)) == INTEGER_CST
7697 && TREE_CODE (TREE_OPERAND (exp
, 1)) == VAR_DECL
7698 && (DECL_RTL (TREE_OPERAND (exp
, 1)) == frame_pointer_rtx
7699 || DECL_RTL (TREE_OPERAND (exp
, 1)) == stack_pointer_rtx
7700 || DECL_RTL (TREE_OPERAND (exp
, 1)) == arg_pointer_rtx
))
7702 tree t
= TREE_OPERAND (exp
, 1);
7704 TREE_OPERAND (exp
, 1) = TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
7705 TREE_OPERAND (TREE_OPERAND (exp
, 0), 0) = t
;
7708 /* If the result is to be ptr_mode and we are adding an integer to
7709 something, we might be forming a constant. So try to use
7710 plus_constant. If it produces a sum and we can't accept it,
7711 use force_operand. This allows P = &ARR[const] to generate
7712 efficient code on machines where a SYMBOL_REF is not a valid
7715 If this is an EXPAND_SUM call, always return the sum. */
7716 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
7717 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
7719 if (modifier
== EXPAND_STACK_PARM
)
7721 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == INTEGER_CST
7722 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
7723 && TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
7727 op1
= expand_expr (TREE_OPERAND (exp
, 1), subtarget
, VOIDmode
,
7729 /* Use immed_double_const to ensure that the constant is
7730 truncated according to the mode of OP1, then sign extended
7731 to a HOST_WIDE_INT. Using the constant directly can result
7732 in non-canonical RTL in a 64x32 cross compile. */
7734 = immed_double_const (TREE_INT_CST_LOW (TREE_OPERAND (exp
, 0)),
7736 TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 1))));
7737 op1
= plus_constant (op1
, INTVAL (constant_part
));
7738 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
7739 op1
= force_operand (op1
, target
);
7740 return REDUCE_BIT_FIELD (op1
);
7743 else if (TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
7744 && GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
7745 && TREE_CONSTANT (TREE_OPERAND (exp
, 0)))
7749 op0
= expand_expr (TREE_OPERAND (exp
, 0), subtarget
, VOIDmode
,
7750 (modifier
== EXPAND_INITIALIZER
7751 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
7752 if (! CONSTANT_P (op0
))
7754 op1
= expand_expr (TREE_OPERAND (exp
, 1), NULL_RTX
,
7755 VOIDmode
, modifier
);
7756 /* Return a PLUS if modifier says it's OK. */
7757 if (modifier
== EXPAND_SUM
7758 || modifier
== EXPAND_INITIALIZER
)
7759 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
7762 /* Use immed_double_const to ensure that the constant is
7763 truncated according to the mode of OP1, then sign extended
7764 to a HOST_WIDE_INT. Using the constant directly can result
7765 in non-canonical RTL in a 64x32 cross compile. */
7767 = immed_double_const (TREE_INT_CST_LOW (TREE_OPERAND (exp
, 1)),
7769 TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
7770 op0
= plus_constant (op0
, INTVAL (constant_part
));
7771 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
7772 op0
= force_operand (op0
, target
);
7773 return REDUCE_BIT_FIELD (op0
);
7777 /* No sense saving up arithmetic to be done
7778 if it's all in the wrong mode to form part of an address.
7779 And force_operand won't know whether to sign-extend or
7781 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
7782 || mode
!= ptr_mode
)
7784 expand_operands (TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
7785 subtarget
, &op0
, &op1
, 0);
7786 if (op0
== const0_rtx
)
7788 if (op1
== const0_rtx
)
7793 expand_operands (TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
7794 subtarget
, &op0
, &op1
, modifier
);
7795 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
7798 /* For initializers, we are allowed to return a MINUS of two
7799 symbolic constants. Here we handle all cases when both operands
7801 /* Handle difference of two symbolic constants,
7802 for the sake of an initializer. */
7803 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7804 && really_constant_p (TREE_OPERAND (exp
, 0))
7805 && really_constant_p (TREE_OPERAND (exp
, 1)))
7807 expand_operands (TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
7808 NULL_RTX
, &op0
, &op1
, modifier
);
7810 /* If the last operand is a CONST_INT, use plus_constant of
7811 the negated constant. Else make the MINUS. */
7812 if (GET_CODE (op1
) == CONST_INT
)
7813 return REDUCE_BIT_FIELD (plus_constant (op0
, - INTVAL (op1
)));
7815 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
7818 /* No sense saving up arithmetic to be done
7819 if it's all in the wrong mode to form part of an address.
7820 And force_operand won't know whether to sign-extend or
7822 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
7823 || mode
!= ptr_mode
)
7826 expand_operands (TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
7827 subtarget
, &op0
, &op1
, modifier
);
7829 /* Convert A - const to A + (-const). */
7830 if (GET_CODE (op1
) == CONST_INT
)
7832 op1
= negate_rtx (mode
, op1
);
7833 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
7839 /* If first operand is constant, swap them.
7840 Thus the following special case checks need only
7841 check the second operand. */
7842 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == INTEGER_CST
)
7844 tree t1
= TREE_OPERAND (exp
, 0);
7845 TREE_OPERAND (exp
, 0) = TREE_OPERAND (exp
, 1);
7846 TREE_OPERAND (exp
, 1) = t1
;
7849 /* Attempt to return something suitable for generating an
7850 indexed address, for machines that support that. */
7852 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
7853 && host_integerp (TREE_OPERAND (exp
, 1), 0))
7855 tree exp1
= TREE_OPERAND (exp
, 1);
7857 op0
= expand_expr (TREE_OPERAND (exp
, 0), subtarget
, VOIDmode
,
7861 op0
= force_operand (op0
, NULL_RTX
);
7863 op0
= copy_to_mode_reg (mode
, op0
);
7865 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
7866 gen_int_mode (tree_low_cst (exp1
, 0),
7867 TYPE_MODE (TREE_TYPE (exp1
)))));
7870 if (modifier
== EXPAND_STACK_PARM
)
7873 /* Check for multiplying things that have been extended
7874 from a narrower type. If this machine supports multiplying
7875 in that narrower type with a result in the desired type,
7876 do it that way, and avoid the explicit type-conversion. */
7877 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == NOP_EXPR
7878 && TREE_CODE (type
) == INTEGER_TYPE
7879 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)))
7880 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp
, 0))))
7881 && ((TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
7882 && int_fits_type_p (TREE_OPERAND (exp
, 1),
7883 TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)))
7884 /* Don't use a widening multiply if a shift will do. */
7885 && ((GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 1))))
7886 > HOST_BITS_PER_WIDE_INT
)
7887 || exact_log2 (TREE_INT_CST_LOW (TREE_OPERAND (exp
, 1))) < 0))
7889 (TREE_CODE (TREE_OPERAND (exp
, 1)) == NOP_EXPR
7890 && (TYPE_PRECISION (TREE_TYPE
7891 (TREE_OPERAND (TREE_OPERAND (exp
, 1), 0)))
7892 == TYPE_PRECISION (TREE_TYPE
7894 (TREE_OPERAND (exp
, 0), 0))))
7895 /* If both operands are extended, they must either both
7896 be zero-extended or both be sign-extended. */
7897 && (TYPE_UNSIGNED (TREE_TYPE
7898 (TREE_OPERAND (TREE_OPERAND (exp
, 1), 0)))
7899 == TYPE_UNSIGNED (TREE_TYPE
7901 (TREE_OPERAND (exp
, 0), 0)))))))
7903 tree op0type
= TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0));
7904 enum machine_mode innermode
= TYPE_MODE (op0type
);
7905 bool zextend_p
= TYPE_UNSIGNED (op0type
);
7906 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
7907 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
7909 if (mode
== GET_MODE_2XWIDER_MODE (innermode
))
7911 if (this_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
)
7913 if (TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
)
7914 expand_operands (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0),
7915 TREE_OPERAND (exp
, 1),
7916 NULL_RTX
, &op0
, &op1
, 0);
7918 expand_operands (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0),
7919 TREE_OPERAND (TREE_OPERAND (exp
, 1), 0),
7920 NULL_RTX
, &op0
, &op1
, 0);
7923 else if (other_optab
->handlers
[(int) mode
].insn_code
!= CODE_FOR_nothing
7924 && innermode
== word_mode
)
7927 op0
= expand_expr (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0),
7928 NULL_RTX
, VOIDmode
, 0);
7929 if (TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
)
7930 op1
= convert_modes (innermode
, mode
,
7931 expand_expr (TREE_OPERAND (exp
, 1),
7932 NULL_RTX
, VOIDmode
, 0),
7935 op1
= expand_expr (TREE_OPERAND (TREE_OPERAND (exp
, 1), 0),
7936 NULL_RTX
, VOIDmode
, 0);
7937 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
7938 unsignedp
, OPTAB_LIB_WIDEN
);
7939 hipart
= gen_highpart (innermode
, temp
);
7940 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
7944 emit_move_insn (hipart
, htem
);
7945 return REDUCE_BIT_FIELD (temp
);
7949 expand_operands (TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
7950 subtarget
, &op0
, &op1
, 0);
7951 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
7953 case TRUNC_DIV_EXPR
:
7954 case FLOOR_DIV_EXPR
:
7956 case ROUND_DIV_EXPR
:
7957 case EXACT_DIV_EXPR
:
7958 if (modifier
== EXPAND_STACK_PARM
)
7960 /* Possible optimization: compute the dividend with EXPAND_SUM
7961 then if the divisor is constant can optimize the case
7962 where some terms of the dividend have coeffs divisible by it. */
7963 expand_operands (TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
7964 subtarget
, &op0
, &op1
, 0);
7965 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
7970 case TRUNC_MOD_EXPR
:
7971 case FLOOR_MOD_EXPR
:
7973 case ROUND_MOD_EXPR
:
7974 if (modifier
== EXPAND_STACK_PARM
)
7976 expand_operands (TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
7977 subtarget
, &op0
, &op1
, 0);
7978 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
7980 case FIX_ROUND_EXPR
:
7981 case FIX_FLOOR_EXPR
:
7983 gcc_unreachable (); /* Not used for C. */
7985 case FIX_TRUNC_EXPR
:
7986 op0
= expand_expr (TREE_OPERAND (exp
, 0), NULL_RTX
, VOIDmode
, 0);
7987 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
7988 target
= gen_reg_rtx (mode
);
7989 expand_fix (target
, op0
, unsignedp
);
7993 op0
= expand_expr (TREE_OPERAND (exp
, 0), NULL_RTX
, VOIDmode
, 0);
7994 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
7995 target
= gen_reg_rtx (mode
);
7996 /* expand_float can't figure out what to do if FROM has VOIDmode.
7997 So give it the correct mode. With -O, cse will optimize this. */
7998 if (GET_MODE (op0
) == VOIDmode
)
7999 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0))),
8001 expand_float (target
, op0
,
8002 TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0))));
8006 op0
= expand_expr (TREE_OPERAND (exp
, 0), subtarget
, VOIDmode
, 0);
8007 if (modifier
== EXPAND_STACK_PARM
)
8009 temp
= expand_unop (mode
,
8010 optab_for_tree_code (NEGATE_EXPR
, type
),
8013 return REDUCE_BIT_FIELD (temp
);
8016 op0
= expand_expr (TREE_OPERAND (exp
, 0), subtarget
, VOIDmode
, 0);
8017 if (modifier
== EXPAND_STACK_PARM
)
8020 /* ABS_EXPR is not valid for complex arguments. */
8021 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8022 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8024 /* Unsigned abs is simply the operand. Testing here means we don't
8025 risk generating incorrect code below. */
8026 if (TYPE_UNSIGNED (type
))
8029 return expand_abs (mode
, op0
, target
, unsignedp
,
8030 safe_from_p (target
, TREE_OPERAND (exp
, 0), 1));
8034 target
= original_target
;
8036 || modifier
== EXPAND_STACK_PARM
8037 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8038 || GET_MODE (target
) != mode
8040 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8041 target
= gen_reg_rtx (mode
);
8042 expand_operands (TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
8043 target
, &op0
, &op1
, 0);
8045 /* First try to do it with a special MIN or MAX instruction.
8046 If that does not win, use a conditional jump to select the proper
8048 this_optab
= optab_for_tree_code (code
, type
);
8049 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8054 /* At this point, a MEM target is no longer useful; we will get better
8057 if (! REG_P (target
))
8058 target
= gen_reg_rtx (mode
);
8060 /* If op1 was placed in target, swap op0 and op1. */
8061 if (target
!= op0
&& target
== op1
)
8068 /* We generate better code and avoid problems with op1 mentioning
8069 target by forcing op1 into a pseudo if it isn't a constant. */
8070 if (! CONSTANT_P (op1
))
8071 op1
= force_reg (mode
, op1
);
8074 enum rtx_code comparison_code
;
8077 if (code
== MAX_EXPR
)
8078 comparison_code
= unsignedp
? GEU
: GE
;
8080 comparison_code
= unsignedp
? LEU
: LE
;
8082 /* Canonicalize to comparsions against 0. */
8083 if (op1
== const1_rtx
)
8085 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8086 or (a != 0 ? a : 1) for unsigned.
8087 For MIN we are safe converting (a <= 1 ? a : 1)
8088 into (a <= 0 ? a : 1) */
8089 cmpop1
= const0_rtx
;
8090 if (code
== MAX_EXPR
)
8091 comparison_code
= unsignedp
? NE
: GT
;
8093 if (op1
== constm1_rtx
&& !unsignedp
)
8095 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8096 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8097 cmpop1
= const0_rtx
;
8098 if (code
== MIN_EXPR
)
8099 comparison_code
= LT
;
8101 #ifdef HAVE_conditional_move
8102 /* Use a conditional move if possible. */
8103 if (can_conditionally_move_p (mode
))
8107 /* ??? Same problem as in expmed.c: emit_conditional_move
8108 forces a stack adjustment via compare_from_rtx, and we
8109 lose the stack adjustment if the sequence we are about
8110 to create is discarded. */
8111 do_pending_stack_adjust ();
8115 /* Try to emit the conditional move. */
8116 insn
= emit_conditional_move (target
, comparison_code
,
8121 /* If we could do the conditional move, emit the sequence,
8125 rtx seq
= get_insns ();
8131 /* Otherwise discard the sequence and fall back to code with
8137 emit_move_insn (target
, op0
);
8139 temp
= gen_label_rtx ();
8141 /* If this mode is an integer too wide to compare properly,
8142 compare word by word. Rely on cse to optimize constant cases. */
8143 if (GET_MODE_CLASS (mode
) == MODE_INT
8144 && ! can_compare_p (GE
, mode
, ccp_jump
))
8146 if (code
== MAX_EXPR
)
8147 do_jump_by_parts_greater_rtx (mode
, unsignedp
, target
, op1
,
8150 do_jump_by_parts_greater_rtx (mode
, unsignedp
, op1
, target
,
8155 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8156 unsignedp
, mode
, NULL_RTX
, NULL_RTX
, temp
);
8159 emit_move_insn (target
, op1
);
8164 op0
= expand_expr (TREE_OPERAND (exp
, 0), subtarget
, VOIDmode
, 0);
8165 if (modifier
== EXPAND_STACK_PARM
)
8167 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8171 /* ??? Can optimize bitwise operations with one arg constant.
8172 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8173 and (a bitwise1 b) bitwise2 b (etc)
8174 but that is probably not worth while. */
8176 /* BIT_AND_EXPR is for bitwise anding. TRUTH_AND_EXPR is for anding two
8177 boolean values when we want in all cases to compute both of them. In
8178 general it is fastest to do TRUTH_AND_EXPR by computing both operands
8179 as actual zero-or-1 values and then bitwise anding. In cases where
8180 there cannot be any side effects, better code would be made by
8181 treating TRUTH_AND_EXPR like TRUTH_ANDIF_EXPR; but the question is
8182 how to recognize those cases. */
8184 case TRUTH_AND_EXPR
:
8185 code
= BIT_AND_EXPR
;
8190 code
= BIT_IOR_EXPR
;
8194 case TRUTH_XOR_EXPR
:
8195 code
= BIT_XOR_EXPR
;
8203 if (! safe_from_p (subtarget
, TREE_OPERAND (exp
, 1), 1))
8205 if (modifier
== EXPAND_STACK_PARM
)
8207 op0
= expand_expr (TREE_OPERAND (exp
, 0), subtarget
, VOIDmode
, 0);
8208 return expand_shift (code
, mode
, op0
, TREE_OPERAND (exp
, 1), target
,
8211 /* Could determine the answer when only additive constants differ. Also,
8212 the addition of one can be handled by changing the condition. */
8219 case UNORDERED_EXPR
:
8227 temp
= do_store_flag (exp
,
8228 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8229 tmode
!= VOIDmode
? tmode
: mode
, 0);
8233 /* For foo != 0, load foo, and if it is nonzero load 1 instead. */
8234 if (code
== NE_EXPR
&& integer_zerop (TREE_OPERAND (exp
, 1))
8236 && REG_P (original_target
)
8237 && (GET_MODE (original_target
)
8238 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
8240 temp
= expand_expr (TREE_OPERAND (exp
, 0), original_target
,
8243 /* If temp is constant, we can just compute the result. */
8244 if (GET_CODE (temp
) == CONST_INT
)
8246 if (INTVAL (temp
) != 0)
8247 emit_move_insn (target
, const1_rtx
);
8249 emit_move_insn (target
, const0_rtx
);
8254 if (temp
!= original_target
)
8256 enum machine_mode mode1
= GET_MODE (temp
);
8257 if (mode1
== VOIDmode
)
8258 mode1
= tmode
!= VOIDmode
? tmode
: mode
;
8260 temp
= copy_to_mode_reg (mode1
, temp
);
8263 op1
= gen_label_rtx ();
8264 emit_cmp_and_jump_insns (temp
, const0_rtx
, EQ
, NULL_RTX
,
8265 GET_MODE (temp
), unsignedp
, op1
);
8266 emit_move_insn (temp
, const1_rtx
);
8271 /* If no set-flag instruction, must generate a conditional store
8272 into a temporary variable. Drop through and handle this
8277 || modifier
== EXPAND_STACK_PARM
8278 || ! safe_from_p (target
, exp
, 1)
8279 /* Make sure we don't have a hard reg (such as function's return
8280 value) live across basic blocks, if not optimizing. */
8281 || (!optimize
&& REG_P (target
)
8282 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8283 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8286 emit_move_insn (target
, const0_rtx
);
8288 op1
= gen_label_rtx ();
8289 jumpifnot (exp
, op1
);
8292 emit_move_insn (target
, const1_rtx
);
8295 return ignore
? const0_rtx
: target
;
8297 case TRUTH_NOT_EXPR
:
8298 if (modifier
== EXPAND_STACK_PARM
)
8300 op0
= expand_expr (TREE_OPERAND (exp
, 0), target
, VOIDmode
, 0);
8301 /* The parser is careful to generate TRUTH_NOT_EXPR
8302 only with operands that are always zero or one. */
8303 temp
= expand_binop (mode
, xor_optab
, op0
, const1_rtx
,
8304 target
, 1, OPTAB_LIB_WIDEN
);
8308 case STATEMENT_LIST
:
8310 tree_stmt_iterator iter
;
8312 gcc_assert (ignore
);
8314 for (iter
= tsi_start (exp
); !tsi_end_p (iter
); tsi_next (&iter
))
8315 expand_expr (tsi_stmt (iter
), const0_rtx
, VOIDmode
, modifier
);
8320 /* A COND_EXPR with its type being VOID_TYPE represents a
8321 conditional jump and is handled in
8322 expand_gimple_cond_expr. */
8323 gcc_assert (!VOID_TYPE_P (TREE_TYPE (exp
)));
8325 /* Note that COND_EXPRs whose type is a structure or union
8326 are required to be constructed to contain assignments of
8327 a temporary variable, so that we can evaluate them here
8328 for side effect only. If type is void, we must do likewise. */
8330 gcc_assert (!TREE_ADDRESSABLE (type
)
8332 && TREE_TYPE (TREE_OPERAND (exp
, 1)) != void_type_node
8333 && TREE_TYPE (TREE_OPERAND (exp
, 2)) != void_type_node
);
8335 /* If we are not to produce a result, we have no target. Otherwise,
8336 if a target was specified use it; it will not be used as an
8337 intermediate target unless it is safe. If no target, use a
8340 if (modifier
!= EXPAND_STACK_PARM
8342 && safe_from_p (original_target
, TREE_OPERAND (exp
, 0), 1)
8343 && GET_MODE (original_target
) == mode
8344 #ifdef HAVE_conditional_move
8345 && (! can_conditionally_move_p (mode
)
8346 || REG_P (original_target
))
8348 && !MEM_P (original_target
))
8349 temp
= original_target
;
8351 temp
= assign_temp (type
, 0, 0, 1);
8353 do_pending_stack_adjust ();
8355 op0
= gen_label_rtx ();
8356 op1
= gen_label_rtx ();
8357 jumpifnot (TREE_OPERAND (exp
, 0), op0
);
8358 store_expr (TREE_OPERAND (exp
, 1), temp
,
8359 modifier
== EXPAND_STACK_PARM
);
8361 emit_jump_insn (gen_jump (op1
));
8364 store_expr (TREE_OPERAND (exp
, 2), temp
,
8365 modifier
== EXPAND_STACK_PARM
);
8372 target
= expand_vec_cond_expr (exp
, target
);
8377 tree lhs
= TREE_OPERAND (exp
, 0);
8378 tree rhs
= TREE_OPERAND (exp
, 1);
8380 gcc_assert (ignore
);
8382 /* Check for |= or &= of a bitfield of size one into another bitfield
8383 of size 1. In this case, (unless we need the result of the
8384 assignment) we can do this more efficiently with a
8385 test followed by an assignment, if necessary.
8387 ??? At this point, we can't get a BIT_FIELD_REF here. But if
8388 things change so we do, this code should be enhanced to
8390 if (TREE_CODE (lhs
) == COMPONENT_REF
8391 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
8392 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
8393 && TREE_OPERAND (rhs
, 0) == lhs
8394 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
8395 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
8396 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
8398 rtx label
= gen_label_rtx ();
8400 do_jump (TREE_OPERAND (rhs
, 1),
8401 TREE_CODE (rhs
) == BIT_IOR_EXPR
? label
: 0,
8402 TREE_CODE (rhs
) == BIT_AND_EXPR
? label
: 0);
8403 expand_assignment (lhs
, convert (TREE_TYPE (rhs
),
8404 (TREE_CODE (rhs
) == BIT_IOR_EXPR
8406 : integer_zero_node
)));
8407 do_pending_stack_adjust ();
8412 expand_assignment (lhs
, rhs
);
8418 if (!TREE_OPERAND (exp
, 0))
8419 expand_null_return ();
8421 expand_return (TREE_OPERAND (exp
, 0));
8425 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
8428 /* Get the rtx code of the operands. */
8429 op0
= expand_expr (TREE_OPERAND (exp
, 0), 0, VOIDmode
, 0);
8430 op1
= expand_expr (TREE_OPERAND (exp
, 1), 0, VOIDmode
, 0);
8433 target
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp
)));
8435 /* Move the real (op0) and imaginary (op1) parts to their location. */
8436 write_complex_part (target
, op0
, false);
8437 write_complex_part (target
, op1
, true);
8442 op0
= expand_expr (TREE_OPERAND (exp
, 0), 0, VOIDmode
, 0);
8443 return read_complex_part (op0
, false);
8446 op0
= expand_expr (TREE_OPERAND (exp
, 0), 0, VOIDmode
, 0);
8447 return read_complex_part (op0
, true);
8450 expand_resx_expr (exp
);
8453 case TRY_CATCH_EXPR
:
8455 case EH_FILTER_EXPR
:
8456 case TRY_FINALLY_EXPR
:
8457 /* Lowered by tree-eh.c. */
8460 case WITH_CLEANUP_EXPR
:
8461 case CLEANUP_POINT_EXPR
:
8463 case CASE_LABEL_EXPR
:
8469 case PREINCREMENT_EXPR
:
8470 case PREDECREMENT_EXPR
:
8471 case POSTINCREMENT_EXPR
:
8472 case POSTDECREMENT_EXPR
:
8475 case TRUTH_ANDIF_EXPR
:
8476 case TRUTH_ORIF_EXPR
:
8477 /* Lowered by gimplify.c. */
8481 return get_exception_pointer (cfun
);
8484 return get_exception_filter (cfun
);
8487 /* Function descriptors are not valid except for as
8488 initialization constants, and should not be expanded. */
8496 expand_label (TREE_OPERAND (exp
, 0));
8500 expand_asm_expr (exp
);
8503 case WITH_SIZE_EXPR
:
8504 /* WITH_SIZE_EXPR expands to its first argument. The caller should
8505 have pulled out the size to use in whatever context it needed. */
8506 return expand_expr_real (TREE_OPERAND (exp
, 0), original_target
, tmode
,
8509 case REALIGN_LOAD_EXPR
:
8511 tree oprnd0
= TREE_OPERAND (exp
, 0);
8512 tree oprnd1
= TREE_OPERAND (exp
, 1);
8513 tree oprnd2
= TREE_OPERAND (exp
, 2);
8516 this_optab
= optab_for_tree_code (code
, type
);
8517 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, 0);
8518 op2
= expand_expr (oprnd2
, NULL_RTX
, VOIDmode
, 0);
8519 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
8525 case REDUC_MAX_EXPR
:
8526 case REDUC_MIN_EXPR
:
8527 case REDUC_PLUS_EXPR
:
8529 op0
= expand_expr (TREE_OPERAND (exp
, 0), NULL_RTX
, VOIDmode
, 0);
8530 this_optab
= optab_for_tree_code (code
, type
);
8531 temp
= expand_unop (mode
, this_optab
, op0
, target
, unsignedp
);
8536 case VEC_LSHIFT_EXPR
:
8537 case VEC_RSHIFT_EXPR
:
8539 target
= expand_vec_shift_expr (exp
, target
);
8544 return lang_hooks
.expand_expr (exp
, original_target
, tmode
,
8548 /* Here to do an ordinary binary operator. */
8550 expand_operands (TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
8551 subtarget
, &op0
, &op1
, 0);
8553 this_optab
= optab_for_tree_code (code
, type
);
8555 if (modifier
== EXPAND_STACK_PARM
)
8557 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
8558 unsignedp
, OPTAB_LIB_WIDEN
);
8560 return REDUCE_BIT_FIELD (temp
);
8562 #undef REDUCE_BIT_FIELD
8564 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
8565 signedness of TYPE), possibly returning the result in TARGET. */
8567 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
8569 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
8570 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
8572 if (TYPE_UNSIGNED (type
))
8575 if (prec
< HOST_BITS_PER_WIDE_INT
)
8576 mask
= immed_double_const (((unsigned HOST_WIDE_INT
) 1 << prec
) - 1, 0,
8579 mask
= immed_double_const ((unsigned HOST_WIDE_INT
) -1,
8580 ((unsigned HOST_WIDE_INT
) 1
8581 << (prec
- HOST_BITS_PER_WIDE_INT
)) - 1,
8583 return expand_and (GET_MODE (exp
), exp
, mask
, target
);
8587 tree count
= build_int_cst (NULL_TREE
,
8588 GET_MODE_BITSIZE (GET_MODE (exp
)) - prec
);
8589 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
), exp
, count
, target
, 0);
8590 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
), exp
, count
, target
, 0);
8594 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
8595 when applied to the address of EXP produces an address known to be
8596 aligned more than BIGGEST_ALIGNMENT. */
8599 is_aligning_offset (tree offset
, tree exp
)
8601 /* Strip off any conversions. */
8602 while (TREE_CODE (offset
) == NON_LVALUE_EXPR
8603 || TREE_CODE (offset
) == NOP_EXPR
8604 || TREE_CODE (offset
) == CONVERT_EXPR
)
8605 offset
= TREE_OPERAND (offset
, 0);
8607 /* We must now have a BIT_AND_EXPR with a constant that is one less than
8608 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
8609 if (TREE_CODE (offset
) != BIT_AND_EXPR
8610 || !host_integerp (TREE_OPERAND (offset
, 1), 1)
8611 || compare_tree_int (TREE_OPERAND (offset
, 1),
8612 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
8613 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset
, 1), 1) + 1) < 0)
8616 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
8617 It must be NEGATE_EXPR. Then strip any more conversions. */
8618 offset
= TREE_OPERAND (offset
, 0);
8619 while (TREE_CODE (offset
) == NON_LVALUE_EXPR
8620 || TREE_CODE (offset
) == NOP_EXPR
8621 || TREE_CODE (offset
) == CONVERT_EXPR
)
8622 offset
= TREE_OPERAND (offset
, 0);
8624 if (TREE_CODE (offset
) != NEGATE_EXPR
)
8627 offset
= TREE_OPERAND (offset
, 0);
8628 while (TREE_CODE (offset
) == NON_LVALUE_EXPR
8629 || TREE_CODE (offset
) == NOP_EXPR
8630 || TREE_CODE (offset
) == CONVERT_EXPR
)
8631 offset
= TREE_OPERAND (offset
, 0);
8633 /* This must now be the address of EXP. */
8634 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
8637 /* Return the tree node if an ARG corresponds to a string constant or zero
8638 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
8639 in bytes within the string that ARG is accessing. The type of the
8640 offset will be `sizetype'. */
8643 string_constant (tree arg
, tree
*ptr_offset
)
8648 if (TREE_CODE (arg
) == ADDR_EXPR
)
8650 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
8652 *ptr_offset
= size_zero_node
;
8653 return TREE_OPERAND (arg
, 0);
8655 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
8657 array
= TREE_OPERAND (arg
, 0);
8658 offset
= size_zero_node
;
8660 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
8662 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
8663 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
8664 if (TREE_CODE (array
) != STRING_CST
8665 && TREE_CODE (array
) != VAR_DECL
)
8671 else if (TREE_CODE (arg
) == PLUS_EXPR
)
8673 tree arg0
= TREE_OPERAND (arg
, 0);
8674 tree arg1
= TREE_OPERAND (arg
, 1);
8679 if (TREE_CODE (arg0
) == ADDR_EXPR
8680 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
8681 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
8683 array
= TREE_OPERAND (arg0
, 0);
8686 else if (TREE_CODE (arg1
) == ADDR_EXPR
8687 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
8688 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
8690 array
= TREE_OPERAND (arg1
, 0);
8699 if (TREE_CODE (array
) == STRING_CST
)
8701 *ptr_offset
= convert (sizetype
, offset
);
8704 else if (TREE_CODE (array
) == VAR_DECL
)
8708 /* Variables initialized to string literals can be handled too. */
8709 if (DECL_INITIAL (array
) == NULL_TREE
8710 || TREE_CODE (DECL_INITIAL (array
)) != STRING_CST
)
8713 /* If they are read-only, non-volatile and bind locally. */
8714 if (! TREE_READONLY (array
)
8715 || TREE_SIDE_EFFECTS (array
)
8716 || ! targetm
.binds_local_p (array
))
8719 /* Avoid const char foo[4] = "abcde"; */
8720 if (DECL_SIZE_UNIT (array
) == NULL_TREE
8721 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
8722 || (length
= TREE_STRING_LENGTH (DECL_INITIAL (array
))) <= 0
8723 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
8726 /* If variable is bigger than the string literal, OFFSET must be constant
8727 and inside of the bounds of the string literal. */
8728 offset
= convert (sizetype
, offset
);
8729 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
8730 && (! host_integerp (offset
, 1)
8731 || compare_tree_int (offset
, length
) >= 0))
8734 *ptr_offset
= offset
;
8735 return DECL_INITIAL (array
);
8741 /* Generate code to calculate EXP using a store-flag instruction
8742 and return an rtx for the result. EXP is either a comparison
8743 or a TRUTH_NOT_EXPR whose operand is a comparison.
8745 If TARGET is nonzero, store the result there if convenient.
8747 If ONLY_CHEAP is nonzero, only do this if it is likely to be very
8750 Return zero if there is no suitable set-flag instruction
8751 available on this machine.
8753 Once expand_expr has been called on the arguments of the comparison,
8754 we are committed to doing the store flag, since it is not safe to
8755 re-evaluate the expression. We emit the store-flag insn by calling
8756 emit_store_flag, but only expand the arguments if we have a reason
8757 to believe that emit_store_flag will be successful. If we think that
8758 it will, but it isn't, we have to simulate the store-flag with a
8759 set/jump/set sequence. */
8762 do_store_flag (tree exp
, rtx target
, enum machine_mode mode
, int only_cheap
)
8765 tree arg0
, arg1
, type
;
8767 enum machine_mode operand_mode
;
8771 enum insn_code icode
;
8772 rtx subtarget
= target
;
8775 /* If this is a TRUTH_NOT_EXPR, set a flag indicating we must invert the
8776 result at the end. We can't simply invert the test since it would
8777 have already been inverted if it were valid. This case occurs for
8778 some floating-point comparisons. */
8780 if (TREE_CODE (exp
) == TRUTH_NOT_EXPR
)
8781 invert
= 1, exp
= TREE_OPERAND (exp
, 0);
8783 arg0
= TREE_OPERAND (exp
, 0);
8784 arg1
= TREE_OPERAND (exp
, 1);
8786 /* Don't crash if the comparison was erroneous. */
8787 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
8790 type
= TREE_TYPE (arg0
);
8791 operand_mode
= TYPE_MODE (type
);
8792 unsignedp
= TYPE_UNSIGNED (type
);
8794 /* We won't bother with BLKmode store-flag operations because it would mean
8795 passing a lot of information to emit_store_flag. */
8796 if (operand_mode
== BLKmode
)
8799 /* We won't bother with store-flag operations involving function pointers
8800 when function pointers must be canonicalized before comparisons. */
8801 #ifdef HAVE_canonicalize_funcptr_for_compare
8802 if (HAVE_canonicalize_funcptr_for_compare
8803 && ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == POINTER_TYPE
8804 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))))
8806 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 1))) == POINTER_TYPE
8807 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 1))))
8808 == FUNCTION_TYPE
))))
8815 /* Get the rtx comparison code to use. We know that EXP is a comparison
8816 operation of some type. Some comparisons against 1 and -1 can be
8817 converted to comparisons with zero. Do so here so that the tests
8818 below will be aware that we have a comparison with zero. These
8819 tests will not catch constants in the first operand, but constants
8820 are rarely passed as the first operand. */
8822 switch (TREE_CODE (exp
))
8831 if (integer_onep (arg1
))
8832 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
8834 code
= unsignedp
? LTU
: LT
;
8837 if (! unsignedp
&& integer_all_onesp (arg1
))
8838 arg1
= integer_zero_node
, code
= LT
;
8840 code
= unsignedp
? LEU
: LE
;
8843 if (! unsignedp
&& integer_all_onesp (arg1
))
8844 arg1
= integer_zero_node
, code
= GE
;
8846 code
= unsignedp
? GTU
: GT
;
8849 if (integer_onep (arg1
))
8850 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
8852 code
= unsignedp
? GEU
: GE
;
8855 case UNORDERED_EXPR
:
8884 /* Put a constant second. */
8885 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
)
8887 tem
= arg0
; arg0
= arg1
; arg1
= tem
;
8888 code
= swap_condition (code
);
8891 /* If this is an equality or inequality test of a single bit, we can
8892 do this by shifting the bit being tested to the low-order bit and
8893 masking the result with the constant 1. If the condition was EQ,
8894 we xor it with 1. This does not require an scc insn and is faster
8895 than an scc insn even if we have it.
8897 The code to make this transformation was moved into fold_single_bit_test,
8898 so we just call into the folder and expand its result. */
8900 if ((code
== NE
|| code
== EQ
)
8901 && TREE_CODE (arg0
) == BIT_AND_EXPR
&& integer_zerop (arg1
)
8902 && integer_pow2p (TREE_OPERAND (arg0
, 1)))
8904 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
8905 return expand_expr (fold_single_bit_test (code
== NE
? NE_EXPR
: EQ_EXPR
,
8907 target
, VOIDmode
, EXPAND_NORMAL
);
8910 /* Now see if we are likely to be able to do this. Return if not. */
8911 if (! can_compare_p (code
, operand_mode
, ccp_store_flag
))
8914 icode
= setcc_gen_code
[(int) code
];
8915 if (icode
== CODE_FOR_nothing
8916 || (only_cheap
&& insn_data
[(int) icode
].operand
[0].mode
!= mode
))
8918 /* We can only do this if it is one of the special cases that
8919 can be handled without an scc insn. */
8920 if ((code
== LT
&& integer_zerop (arg1
))
8921 || (! only_cheap
&& code
== GE
&& integer_zerop (arg1
)))
8923 else if (! only_cheap
&& (code
== NE
|| code
== EQ
)
8924 && TREE_CODE (type
) != REAL_TYPE
8925 && ((abs_optab
->handlers
[(int) operand_mode
].insn_code
8926 != CODE_FOR_nothing
)
8927 || (ffs_optab
->handlers
[(int) operand_mode
].insn_code
8928 != CODE_FOR_nothing
)))
8934 if (! get_subtarget (target
)
8935 || GET_MODE (subtarget
) != operand_mode
)
8938 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, 0);
8941 target
= gen_reg_rtx (mode
);
8943 result
= emit_store_flag (target
, code
, op0
, op1
,
8944 operand_mode
, unsignedp
, 1);
8949 result
= expand_binop (mode
, xor_optab
, result
, const1_rtx
,
8950 result
, 0, OPTAB_LIB_WIDEN
);
8954 /* If this failed, we have to do this with set/compare/jump/set code. */
8956 || reg_mentioned_p (target
, op0
) || reg_mentioned_p (target
, op1
))
8957 target
= gen_reg_rtx (GET_MODE (target
));
8959 emit_move_insn (target
, invert
? const0_rtx
: const1_rtx
);
8960 result
= compare_from_rtx (op0
, op1
, code
, unsignedp
,
8961 operand_mode
, NULL_RTX
);
8962 if (GET_CODE (result
) == CONST_INT
)
8963 return (((result
== const0_rtx
&& ! invert
)
8964 || (result
!= const0_rtx
&& invert
))
8965 ? const0_rtx
: const1_rtx
);
8967 /* The code of RESULT may not match CODE if compare_from_rtx
8968 decided to swap its operands and reverse the original code.
8970 We know that compare_from_rtx returns either a CONST_INT or
8971 a new comparison code, so it is safe to just extract the
8972 code from RESULT. */
8973 code
= GET_CODE (result
);
8975 label
= gen_label_rtx ();
8976 gcc_assert (bcc_gen_fctn
[(int) code
]);
8978 emit_jump_insn ((*bcc_gen_fctn
[(int) code
]) (label
));
8979 emit_move_insn (target
, invert
? const1_rtx
: const0_rtx
);
8986 /* Stubs in case we haven't got a casesi insn. */
8988 # define HAVE_casesi 0
8989 # define gen_casesi(a, b, c, d, e) (0)
8990 # define CODE_FOR_casesi CODE_FOR_nothing
8993 /* If the machine does not have a case insn that compares the bounds,
8994 this means extra overhead for dispatch tables, which raises the
8995 threshold for using them. */
8996 #ifndef CASE_VALUES_THRESHOLD
8997 #define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
8998 #endif /* CASE_VALUES_THRESHOLD */
9001 case_values_threshold (void)
9003 return CASE_VALUES_THRESHOLD
;
9006 /* Attempt to generate a casesi instruction. Returns 1 if successful,
9007 0 otherwise (i.e. if there is no casesi instruction). */
9009 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
9010 rtx table_label ATTRIBUTE_UNUSED
, rtx default_label
)
9012 enum machine_mode index_mode
= SImode
;
9013 int index_bits
= GET_MODE_BITSIZE (index_mode
);
9014 rtx op1
, op2
, index
;
9015 enum machine_mode op_mode
;
9020 /* Convert the index to SImode. */
9021 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
9023 enum machine_mode omode
= TYPE_MODE (index_type
);
9024 rtx rangertx
= expand_expr (range
, NULL_RTX
, VOIDmode
, 0);
9026 /* We must handle the endpoints in the original mode. */
9027 index_expr
= build2 (MINUS_EXPR
, index_type
,
9028 index_expr
, minval
);
9029 minval
= integer_zero_node
;
9030 index
= expand_expr (index_expr
, NULL_RTX
, VOIDmode
, 0);
9031 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
9032 omode
, 1, default_label
);
9033 /* Now we can safely truncate. */
9034 index
= convert_to_mode (index_mode
, index
, 0);
9038 if (TYPE_MODE (index_type
) != index_mode
)
9040 index_expr
= convert (lang_hooks
.types
.type_for_size
9041 (index_bits
, 0), index_expr
);
9042 index_type
= TREE_TYPE (index_expr
);
9045 index
= expand_expr (index_expr
, NULL_RTX
, VOIDmode
, 0);
9048 do_pending_stack_adjust ();
9050 op_mode
= insn_data
[(int) CODE_FOR_casesi
].operand
[0].mode
;
9051 if (! (*insn_data
[(int) CODE_FOR_casesi
].operand
[0].predicate
)
9053 index
= copy_to_mode_reg (op_mode
, index
);
9055 op1
= expand_expr (minval
, NULL_RTX
, VOIDmode
, 0);
9057 op_mode
= insn_data
[(int) CODE_FOR_casesi
].operand
[1].mode
;
9058 op1
= convert_modes (op_mode
, TYPE_MODE (TREE_TYPE (minval
)),
9059 op1
, TYPE_UNSIGNED (TREE_TYPE (minval
)));
9060 if (! (*insn_data
[(int) CODE_FOR_casesi
].operand
[1].predicate
)
9062 op1
= copy_to_mode_reg (op_mode
, op1
);
9064 op2
= expand_expr (range
, NULL_RTX
, VOIDmode
, 0);
9066 op_mode
= insn_data
[(int) CODE_FOR_casesi
].operand
[2].mode
;
9067 op2
= convert_modes (op_mode
, TYPE_MODE (TREE_TYPE (range
)),
9068 op2
, TYPE_UNSIGNED (TREE_TYPE (range
)));
9069 if (! (*insn_data
[(int) CODE_FOR_casesi
].operand
[2].predicate
)
9071 op2
= copy_to_mode_reg (op_mode
, op2
);
9073 emit_jump_insn (gen_casesi (index
, op1
, op2
,
9074 table_label
, default_label
));
9078 /* Attempt to generate a tablejump instruction; same concept. */
9079 #ifndef HAVE_tablejump
9080 #define HAVE_tablejump 0
9081 #define gen_tablejump(x, y) (0)
9084 /* Subroutine of the next function.
9086 INDEX is the value being switched on, with the lowest value
9087 in the table already subtracted.
9088 MODE is its expected mode (needed if INDEX is constant).
9089 RANGE is the length of the jump table.
9090 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
9092 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
9093 index value is out of range. */
9096 do_tablejump (rtx index
, enum machine_mode mode
, rtx range
, rtx table_label
,
9101 if (INTVAL (range
) > cfun
->max_jumptable_ents
)
9102 cfun
->max_jumptable_ents
= INTVAL (range
);
9104 /* Do an unsigned comparison (in the proper mode) between the index
9105 expression and the value which represents the length of the range.
9106 Since we just finished subtracting the lower bound of the range
9107 from the index expression, this comparison allows us to simultaneously
9108 check that the original index expression value is both greater than
9109 or equal to the minimum value of the range and less than or equal to
9110 the maximum value of the range. */
9112 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
9115 /* If index is in range, it must fit in Pmode.
9116 Convert to Pmode so we can index with it. */
9118 index
= convert_to_mode (Pmode
, index
, 1);
9120 /* Don't let a MEM slip through, because then INDEX that comes
9121 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
9122 and break_out_memory_refs will go to work on it and mess it up. */
9123 #ifdef PIC_CASE_VECTOR_ADDRESS
9124 if (flag_pic
&& !REG_P (index
))
9125 index
= copy_to_mode_reg (Pmode
, index
);
9128 /* If flag_force_addr were to affect this address
9129 it could interfere with the tricky assumptions made
9130 about addresses that contain label-refs,
9131 which may be valid only very near the tablejump itself. */
9132 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
9133 GET_MODE_SIZE, because this indicates how large insns are. The other
9134 uses should all be Pmode, because they are addresses. This code
9135 could fail if addresses and insns are not the same size. */
9136 index
= gen_rtx_PLUS (Pmode
,
9137 gen_rtx_MULT (Pmode
, index
,
9138 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE
))),
9139 gen_rtx_LABEL_REF (Pmode
, table_label
));
9140 #ifdef PIC_CASE_VECTOR_ADDRESS
9142 index
= PIC_CASE_VECTOR_ADDRESS (index
);
9145 index
= memory_address_noforce (CASE_VECTOR_MODE
, index
);
9146 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
9147 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
9148 convert_move (temp
, vector
, 0);
9150 emit_jump_insn (gen_tablejump (temp
, table_label
));
9152 /* If we are generating PIC code or if the table is PC-relative, the
9153 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
9154 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
9159 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
9160 rtx table_label
, rtx default_label
)
9164 if (! HAVE_tablejump
)
9167 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
9168 convert (index_type
, index_expr
),
9169 convert (index_type
, minval
));
9170 index
= expand_expr (index_expr
, NULL_RTX
, VOIDmode
, 0);
9171 do_pending_stack_adjust ();
9173 do_tablejump (index
, TYPE_MODE (index_type
),
9174 convert_modes (TYPE_MODE (index_type
),
9175 TYPE_MODE (TREE_TYPE (range
)),
9176 expand_expr (range
, NULL_RTX
,
9178 TYPE_UNSIGNED (TREE_TYPE (range
))),
9179 table_label
, default_label
);
9183 /* Nonzero if the mode is a valid vector mode for this architecture.
9184 This returns nonzero even if there is no hardware support for the
9185 vector mode, but we can emulate with narrower modes. */
9188 vector_mode_valid_p (enum machine_mode mode
)
9190 enum mode_class
class = GET_MODE_CLASS (mode
);
9191 enum machine_mode innermode
;
9193 /* Doh! What's going on? */
9194 if (class != MODE_VECTOR_INT
9195 && class != MODE_VECTOR_FLOAT
)
9198 /* Hardware support. Woo hoo! */
9199 if (targetm
.vector_mode_supported_p (mode
))
9202 innermode
= GET_MODE_INNER (mode
);
9204 /* We should probably return 1 if requesting V4DI and we have no DI,
9205 but we have V2DI, but this is probably very unlikely. */
9207 /* If we have support for the inner mode, we can safely emulate it.
9208 We may not have V2DI, but me can emulate with a pair of DIs. */
9209 return targetm
.scalar_mode_supported_p (innermode
);
9212 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
9214 const_vector_from_tree (tree exp
)
9219 enum machine_mode inner
, mode
;
9221 mode
= TYPE_MODE (TREE_TYPE (exp
));
9223 if (initializer_zerop (exp
))
9224 return CONST0_RTX (mode
);
9226 units
= GET_MODE_NUNITS (mode
);
9227 inner
= GET_MODE_INNER (mode
);
9229 v
= rtvec_alloc (units
);
9231 link
= TREE_VECTOR_CST_ELTS (exp
);
9232 for (i
= 0; link
; link
= TREE_CHAIN (link
), ++i
)
9234 elt
= TREE_VALUE (link
);
9236 if (TREE_CODE (elt
) == REAL_CST
)
9237 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
9240 RTVEC_ELT (v
, i
) = immed_double_const (TREE_INT_CST_LOW (elt
),
9241 TREE_INT_CST_HIGH (elt
),
9245 /* Initialize remaining elements to 0. */
9246 for (; i
< units
; ++i
)
9247 RTVEC_ELT (v
, i
) = CONST0_RTX (inner
);
9249 return gen_rtx_CONST_VECTOR (mode
, v
);
9251 #include "gt-expr.h"