1 /* Output routines for GCC for ARM.
2 Copyright (C) 1991-2017 Free Software Foundation, Inc.
3 Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl)
4 and Martin Simmons (@harleqn.co.uk).
5 More major hacks by Richard Earnshaw (rearnsha@arm.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published
11 by the Free Software Foundation; either version 3, or (at your
12 option) any later version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
34 #include "stringpool.h"
41 #include "diagnostic-core.h"
43 #include "fold-const.h"
44 #include "stor-layout.h"
48 #include "insn-attr.h"
54 #include "sched-int.h"
55 #include "common/common-target.h"
56 #include "langhooks.h"
62 #include "target-globals.h"
64 #include "tm-constrs.h"
66 #include "optabs-libfuncs.h"
71 /* This file should be included last. */
72 #include "target-def.h"
74 /* Forward definitions of types. */
75 typedef struct minipool_node Mnode
;
76 typedef struct minipool_fixup Mfix
;
78 void (*arm_lang_output_object_attributes_hook
)(void);
85 /* Forward function declarations. */
86 static bool arm_const_not_ok_for_debug_p (rtx
);
87 static int arm_needs_doubleword_align (machine_mode
, const_tree
);
88 static int arm_compute_static_chain_stack_bytes (void);
89 static arm_stack_offsets
*arm_get_frame_offsets (void);
90 static void arm_compute_frame_layout (void);
91 static void arm_add_gc_roots (void);
92 static int arm_gen_constant (enum rtx_code
, machine_mode
, rtx
,
93 unsigned HOST_WIDE_INT
, rtx
, rtx
, int, int);
94 static unsigned bit_count (unsigned long);
95 static unsigned bitmap_popcount (const sbitmap
);
96 static int arm_address_register_rtx_p (rtx
, int);
97 static int arm_legitimate_index_p (machine_mode
, rtx
, RTX_CODE
, int);
98 static bool is_called_in_ARM_mode (tree
);
99 static int thumb2_legitimate_index_p (machine_mode
, rtx
, int);
100 static int thumb1_base_register_rtx_p (rtx
, machine_mode
, int);
101 static rtx
arm_legitimize_address (rtx
, rtx
, machine_mode
);
102 static reg_class_t
arm_preferred_reload_class (rtx
, reg_class_t
);
103 static rtx
thumb_legitimize_address (rtx
, rtx
, machine_mode
);
104 inline static int thumb1_index_register_rtx_p (rtx
, int);
105 static int thumb_far_jump_used_p (void);
106 static bool thumb_force_lr_save (void);
107 static unsigned arm_size_return_regs (void);
108 static bool arm_assemble_integer (rtx
, unsigned int, int);
109 static void arm_print_operand (FILE *, rtx
, int);
110 static void arm_print_operand_address (FILE *, machine_mode
, rtx
);
111 static bool arm_print_operand_punct_valid_p (unsigned char code
);
112 static const char *fp_const_from_val (REAL_VALUE_TYPE
*);
113 static arm_cc
get_arm_condition_code (rtx
);
114 static bool arm_fixed_condition_code_regs (unsigned int *, unsigned int *);
115 static const char *output_multi_immediate (rtx
*, const char *, const char *,
117 static const char *shift_op (rtx
, HOST_WIDE_INT
*);
118 static struct machine_function
*arm_init_machine_status (void);
119 static void thumb_exit (FILE *, int);
120 static HOST_WIDE_INT
get_jump_table_size (rtx_jump_table_data
*);
121 static Mnode
*move_minipool_fix_forward_ref (Mnode
*, Mnode
*, HOST_WIDE_INT
);
122 static Mnode
*add_minipool_forward_ref (Mfix
*);
123 static Mnode
*move_minipool_fix_backward_ref (Mnode
*, Mnode
*, HOST_WIDE_INT
);
124 static Mnode
*add_minipool_backward_ref (Mfix
*);
125 static void assign_minipool_offsets (Mfix
*);
126 static void arm_print_value (FILE *, rtx
);
127 static void dump_minipool (rtx_insn
*);
128 static int arm_barrier_cost (rtx_insn
*);
129 static Mfix
*create_fix_barrier (Mfix
*, HOST_WIDE_INT
);
130 static void push_minipool_barrier (rtx_insn
*, HOST_WIDE_INT
);
131 static void push_minipool_fix (rtx_insn
*, HOST_WIDE_INT
, rtx
*,
133 static void arm_reorg (void);
134 static void note_invalid_constants (rtx_insn
*, HOST_WIDE_INT
, int);
135 static unsigned long arm_compute_save_reg0_reg12_mask (void);
136 static unsigned long arm_compute_save_core_reg_mask (void);
137 static unsigned long arm_isr_value (tree
);
138 static unsigned long arm_compute_func_type (void);
139 static tree
arm_handle_fndecl_attribute (tree
*, tree
, tree
, int, bool *);
140 static tree
arm_handle_pcs_attribute (tree
*, tree
, tree
, int, bool *);
141 static tree
arm_handle_isr_attribute (tree
*, tree
, tree
, int, bool *);
142 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
143 static tree
arm_handle_notshared_attribute (tree
*, tree
, tree
, int, bool *);
145 static tree
arm_handle_cmse_nonsecure_entry (tree
*, tree
, tree
, int, bool *);
146 static tree
arm_handle_cmse_nonsecure_call (tree
*, tree
, tree
, int, bool *);
147 static void arm_output_function_epilogue (FILE *);
148 static void arm_output_function_prologue (FILE *);
149 static int arm_comp_type_attributes (const_tree
, const_tree
);
150 static void arm_set_default_type_attributes (tree
);
151 static int arm_adjust_cost (rtx_insn
*, int, rtx_insn
*, int, unsigned int);
152 static int arm_sched_reorder (FILE *, int, rtx_insn
**, int *, int);
153 static int optimal_immediate_sequence (enum rtx_code code
,
154 unsigned HOST_WIDE_INT val
,
155 struct four_ints
*return_sequence
);
156 static int optimal_immediate_sequence_1 (enum rtx_code code
,
157 unsigned HOST_WIDE_INT val
,
158 struct four_ints
*return_sequence
,
160 static int arm_get_strip_length (int);
161 static bool arm_function_ok_for_sibcall (tree
, tree
);
162 static machine_mode
arm_promote_function_mode (const_tree
,
165 static bool arm_return_in_memory (const_tree
, const_tree
);
166 static rtx
arm_function_value (const_tree
, const_tree
, bool);
167 static rtx
arm_libcall_value_1 (machine_mode
);
168 static rtx
arm_libcall_value (machine_mode
, const_rtx
);
169 static bool arm_function_value_regno_p (const unsigned int);
170 static void arm_internal_label (FILE *, const char *, unsigned long);
171 static void arm_output_mi_thunk (FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
,
173 static bool arm_have_conditional_execution (void);
174 static bool arm_cannot_force_const_mem (machine_mode
, rtx
);
175 static bool arm_legitimate_constant_p (machine_mode
, rtx
);
176 static bool arm_rtx_costs (rtx
, machine_mode
, int, int, int *, bool);
177 static int arm_address_cost (rtx
, machine_mode
, addr_space_t
, bool);
178 static int arm_register_move_cost (machine_mode
, reg_class_t
, reg_class_t
);
179 static int arm_memory_move_cost (machine_mode
, reg_class_t
, bool);
180 static void emit_constant_insn (rtx cond
, rtx pattern
);
181 static rtx_insn
*emit_set_insn (rtx
, rtx
);
182 static rtx
emit_multi_reg_push (unsigned long, unsigned long);
183 static int arm_arg_partial_bytes (cumulative_args_t
, machine_mode
,
185 static rtx
arm_function_arg (cumulative_args_t
, machine_mode
,
187 static void arm_function_arg_advance (cumulative_args_t
, machine_mode
,
189 static pad_direction
arm_function_arg_padding (machine_mode
, const_tree
);
190 static unsigned int arm_function_arg_boundary (machine_mode
, const_tree
);
191 static rtx
aapcs_allocate_return_reg (machine_mode
, const_tree
,
193 static rtx
aapcs_libcall_value (machine_mode
);
194 static int aapcs_select_return_coproc (const_tree
, const_tree
);
196 #ifdef OBJECT_FORMAT_ELF
197 static void arm_elf_asm_constructor (rtx
, int) ATTRIBUTE_UNUSED
;
198 static void arm_elf_asm_destructor (rtx
, int) ATTRIBUTE_UNUSED
;
201 static void arm_encode_section_info (tree
, rtx
, int);
204 static void arm_file_end (void);
205 static void arm_file_start (void);
206 static void arm_insert_attributes (tree
, tree
*);
208 static void arm_setup_incoming_varargs (cumulative_args_t
, machine_mode
,
210 static bool arm_pass_by_reference (cumulative_args_t
,
211 machine_mode
, const_tree
, bool);
212 static bool arm_promote_prototypes (const_tree
);
213 static bool arm_default_short_enums (void);
214 static bool arm_align_anon_bitfield (void);
215 static bool arm_return_in_msb (const_tree
);
216 static bool arm_must_pass_in_stack (machine_mode
, const_tree
);
217 static bool arm_return_in_memory (const_tree
, const_tree
);
219 static void arm_unwind_emit (FILE *, rtx_insn
*);
220 static bool arm_output_ttype (rtx
);
221 static void arm_asm_emit_except_personality (rtx
);
223 static void arm_asm_init_sections (void);
224 static rtx
arm_dwarf_register_span (rtx
);
226 static tree
arm_cxx_guard_type (void);
227 static bool arm_cxx_guard_mask_bit (void);
228 static tree
arm_get_cookie_size (tree
);
229 static bool arm_cookie_has_size (void);
230 static bool arm_cxx_cdtor_returns_this (void);
231 static bool arm_cxx_key_method_may_be_inline (void);
232 static void arm_cxx_determine_class_data_visibility (tree
);
233 static bool arm_cxx_class_data_always_comdat (void);
234 static bool arm_cxx_use_aeabi_atexit (void);
235 static void arm_init_libfuncs (void);
236 static tree
arm_build_builtin_va_list (void);
237 static void arm_expand_builtin_va_start (tree
, rtx
);
238 static tree
arm_gimplify_va_arg_expr (tree
, tree
, gimple_seq
*, gimple_seq
*);
239 static void arm_option_override (void);
240 static void arm_option_save (struct cl_target_option
*, struct gcc_options
*);
241 static void arm_option_restore (struct gcc_options
*,
242 struct cl_target_option
*);
243 static void arm_override_options_after_change (void);
244 static void arm_option_print (FILE *, int, struct cl_target_option
*);
245 static void arm_set_current_function (tree
);
246 static bool arm_can_inline_p (tree
, tree
);
247 static void arm_relayout_function (tree
);
248 static bool arm_valid_target_attribute_p (tree
, tree
, tree
, int);
249 static unsigned HOST_WIDE_INT
arm_shift_truncation_mask (machine_mode
);
250 static bool arm_sched_can_speculate_insn (rtx_insn
*);
251 static bool arm_macro_fusion_p (void);
252 static bool arm_cannot_copy_insn_p (rtx_insn
*);
253 static int arm_issue_rate (void);
254 static int arm_first_cycle_multipass_dfa_lookahead (void);
255 static int arm_first_cycle_multipass_dfa_lookahead_guard (rtx_insn
*, int);
256 static void arm_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
257 static bool arm_output_addr_const_extra (FILE *, rtx
);
258 static bool arm_allocate_stack_slots_for_args (void);
259 static bool arm_warn_func_return (tree
);
260 static tree
arm_promoted_type (const_tree t
);
261 static bool arm_scalar_mode_supported_p (scalar_mode
);
262 static bool arm_frame_pointer_required (void);
263 static bool arm_can_eliminate (const int, const int);
264 static void arm_asm_trampoline_template (FILE *);
265 static void arm_trampoline_init (rtx
, tree
, rtx
);
266 static rtx
arm_trampoline_adjust_address (rtx
);
267 static rtx_insn
*arm_pic_static_addr (rtx orig
, rtx reg
);
268 static bool cortex_a9_sched_adjust_cost (rtx_insn
*, int, rtx_insn
*, int *);
269 static bool xscale_sched_adjust_cost (rtx_insn
*, int, rtx_insn
*, int *);
270 static bool fa726te_sched_adjust_cost (rtx_insn
*, int, rtx_insn
*, int *);
271 static bool arm_array_mode_supported_p (machine_mode
,
272 unsigned HOST_WIDE_INT
);
273 static machine_mode
arm_preferred_simd_mode (scalar_mode
);
274 static bool arm_class_likely_spilled_p (reg_class_t
);
275 static HOST_WIDE_INT
arm_vector_alignment (const_tree type
);
276 static bool arm_vector_alignment_reachable (const_tree type
, bool is_packed
);
277 static bool arm_builtin_support_vector_misalignment (machine_mode mode
,
281 static void arm_conditional_register_usage (void);
282 static enum flt_eval_method
arm_excess_precision (enum excess_precision_type
);
283 static reg_class_t
arm_preferred_rename_class (reg_class_t rclass
);
284 static unsigned int arm_autovectorize_vector_sizes (void);
285 static int arm_default_branch_cost (bool, bool);
286 static int arm_cortex_a5_branch_cost (bool, bool);
287 static int arm_cortex_m_branch_cost (bool, bool);
288 static int arm_cortex_m7_branch_cost (bool, bool);
290 static bool arm_vectorize_vec_perm_const_ok (machine_mode
, vec_perm_indices
);
292 static bool aarch_macro_fusion_pair_p (rtx_insn
*, rtx_insn
*);
294 static int arm_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost
,
296 int misalign ATTRIBUTE_UNUSED
);
297 static unsigned arm_add_stmt_cost (void *data
, int count
,
298 enum vect_cost_for_stmt kind
,
299 struct _stmt_vec_info
*stmt_info
,
301 enum vect_cost_model_location where
);
303 static void arm_canonicalize_comparison (int *code
, rtx
*op0
, rtx
*op1
,
304 bool op0_preserve_value
);
305 static unsigned HOST_WIDE_INT
arm_asan_shadow_offset (void);
307 static void arm_sched_fusion_priority (rtx_insn
*, int, int *, int*);
308 static bool arm_can_output_mi_thunk (const_tree
, HOST_WIDE_INT
, HOST_WIDE_INT
,
310 static section
*arm_function_section (tree
, enum node_frequency
, bool, bool);
311 static bool arm_asm_elf_flags_numeric (unsigned int flags
, unsigned int *num
);
312 static unsigned int arm_elf_section_type_flags (tree decl
, const char *name
,
314 static void arm_expand_divmod_libfunc (rtx
, machine_mode
, rtx
, rtx
, rtx
*, rtx
*);
315 static opt_scalar_float_mode
arm_floatn_mode (int, bool);
316 static unsigned int arm_hard_regno_nregs (unsigned int, machine_mode
);
317 static bool arm_hard_regno_mode_ok (unsigned int, machine_mode
);
318 static bool arm_modes_tieable_p (machine_mode
, machine_mode
);
319 static HOST_WIDE_INT
arm_constant_alignment (const_tree
, HOST_WIDE_INT
);
321 /* Table of machine attributes. */
322 static const struct attribute_spec arm_attribute_table
[] =
324 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
325 affects_type_identity } */
326 /* Function calls made to this symbol must be done indirectly, because
327 it may lie outside of the 26 bit addressing range of a normal function
329 { "long_call", 0, 0, false, true, true, NULL
, false },
330 /* Whereas these functions are always known to reside within the 26 bit
332 { "short_call", 0, 0, false, true, true, NULL
, false },
333 /* Specify the procedure call conventions for a function. */
334 { "pcs", 1, 1, false, true, true, arm_handle_pcs_attribute
,
336 /* Interrupt Service Routines have special prologue and epilogue requirements. */
337 { "isr", 0, 1, false, false, false, arm_handle_isr_attribute
,
339 { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute
,
341 { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute
,
344 /* ARM/PE has three new attributes:
346 dllexport - for exporting a function/variable that will live in a dll
347 dllimport - for importing a function/variable from a dll
349 Microsoft allows multiple declspecs in one __declspec, separating
350 them with spaces. We do NOT support this. Instead, use __declspec
353 { "dllimport", 0, 0, true, false, false, NULL
, false },
354 { "dllexport", 0, 0, true, false, false, NULL
, false },
355 { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute
,
357 #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
358 { "dllimport", 0, 0, false, false, false, handle_dll_attribute
, false },
359 { "dllexport", 0, 0, false, false, false, handle_dll_attribute
, false },
360 { "notshared", 0, 0, false, true, false, arm_handle_notshared_attribute
,
363 /* ARMv8-M Security Extensions support. */
364 { "cmse_nonsecure_entry", 0, 0, true, false, false,
365 arm_handle_cmse_nonsecure_entry
, false },
366 { "cmse_nonsecure_call", 0, 0, true, false, false,
367 arm_handle_cmse_nonsecure_call
, true },
368 { NULL
, 0, 0, false, false, false, NULL
, false }
371 /* Initialize the GCC target structure. */
372 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
373 #undef TARGET_MERGE_DECL_ATTRIBUTES
374 #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
377 #undef TARGET_LEGITIMIZE_ADDRESS
378 #define TARGET_LEGITIMIZE_ADDRESS arm_legitimize_address
380 #undef TARGET_ATTRIBUTE_TABLE
381 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
383 #undef TARGET_INSERT_ATTRIBUTES
384 #define TARGET_INSERT_ATTRIBUTES arm_insert_attributes
386 #undef TARGET_ASM_FILE_START
387 #define TARGET_ASM_FILE_START arm_file_start
388 #undef TARGET_ASM_FILE_END
389 #define TARGET_ASM_FILE_END arm_file_end
391 #undef TARGET_ASM_ALIGNED_SI_OP
392 #define TARGET_ASM_ALIGNED_SI_OP NULL
393 #undef TARGET_ASM_INTEGER
394 #define TARGET_ASM_INTEGER arm_assemble_integer
396 #undef TARGET_PRINT_OPERAND
397 #define TARGET_PRINT_OPERAND arm_print_operand
398 #undef TARGET_PRINT_OPERAND_ADDRESS
399 #define TARGET_PRINT_OPERAND_ADDRESS arm_print_operand_address
400 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
401 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P arm_print_operand_punct_valid_p
403 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
404 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA arm_output_addr_const_extra
406 #undef TARGET_ASM_FUNCTION_PROLOGUE
407 #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue
409 #undef TARGET_ASM_FUNCTION_EPILOGUE
410 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
412 #undef TARGET_CAN_INLINE_P
413 #define TARGET_CAN_INLINE_P arm_can_inline_p
415 #undef TARGET_RELAYOUT_FUNCTION
416 #define TARGET_RELAYOUT_FUNCTION arm_relayout_function
418 #undef TARGET_OPTION_OVERRIDE
419 #define TARGET_OPTION_OVERRIDE arm_option_override
421 #undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
422 #define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE arm_override_options_after_change
424 #undef TARGET_OPTION_SAVE
425 #define TARGET_OPTION_SAVE arm_option_save
427 #undef TARGET_OPTION_RESTORE
428 #define TARGET_OPTION_RESTORE arm_option_restore
430 #undef TARGET_OPTION_PRINT
431 #define TARGET_OPTION_PRINT arm_option_print
433 #undef TARGET_COMP_TYPE_ATTRIBUTES
434 #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes
436 #undef TARGET_SCHED_CAN_SPECULATE_INSN
437 #define TARGET_SCHED_CAN_SPECULATE_INSN arm_sched_can_speculate_insn
439 #undef TARGET_SCHED_MACRO_FUSION_P
440 #define TARGET_SCHED_MACRO_FUSION_P arm_macro_fusion_p
442 #undef TARGET_SCHED_MACRO_FUSION_PAIR_P
443 #define TARGET_SCHED_MACRO_FUSION_PAIR_P aarch_macro_fusion_pair_p
445 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
446 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes
448 #undef TARGET_SCHED_ADJUST_COST
449 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
451 #undef TARGET_SET_CURRENT_FUNCTION
452 #define TARGET_SET_CURRENT_FUNCTION arm_set_current_function
454 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
455 #define TARGET_OPTION_VALID_ATTRIBUTE_P arm_valid_target_attribute_p
457 #undef TARGET_SCHED_REORDER
458 #define TARGET_SCHED_REORDER arm_sched_reorder
460 #undef TARGET_REGISTER_MOVE_COST
461 #define TARGET_REGISTER_MOVE_COST arm_register_move_cost
463 #undef TARGET_MEMORY_MOVE_COST
464 #define TARGET_MEMORY_MOVE_COST arm_memory_move_cost
466 #undef TARGET_ENCODE_SECTION_INFO
468 #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info
470 #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info
473 #undef TARGET_STRIP_NAME_ENCODING
474 #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding
476 #undef TARGET_ASM_INTERNAL_LABEL
477 #define TARGET_ASM_INTERNAL_LABEL arm_internal_label
479 #undef TARGET_FLOATN_MODE
480 #define TARGET_FLOATN_MODE arm_floatn_mode
482 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
483 #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall
485 #undef TARGET_FUNCTION_VALUE
486 #define TARGET_FUNCTION_VALUE arm_function_value
488 #undef TARGET_LIBCALL_VALUE
489 #define TARGET_LIBCALL_VALUE arm_libcall_value
491 #undef TARGET_FUNCTION_VALUE_REGNO_P
492 #define TARGET_FUNCTION_VALUE_REGNO_P arm_function_value_regno_p
494 #undef TARGET_ASM_OUTPUT_MI_THUNK
495 #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk
496 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
497 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK arm_can_output_mi_thunk
499 #undef TARGET_RTX_COSTS
500 #define TARGET_RTX_COSTS arm_rtx_costs
501 #undef TARGET_ADDRESS_COST
502 #define TARGET_ADDRESS_COST arm_address_cost
504 #undef TARGET_SHIFT_TRUNCATION_MASK
505 #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask
506 #undef TARGET_VECTOR_MODE_SUPPORTED_P
507 #define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p
508 #undef TARGET_ARRAY_MODE_SUPPORTED_P
509 #define TARGET_ARRAY_MODE_SUPPORTED_P arm_array_mode_supported_p
510 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
511 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE arm_preferred_simd_mode
512 #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES
513 #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES \
514 arm_autovectorize_vector_sizes
516 #undef TARGET_MACHINE_DEPENDENT_REORG
517 #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg
519 #undef TARGET_INIT_BUILTINS
520 #define TARGET_INIT_BUILTINS arm_init_builtins
521 #undef TARGET_EXPAND_BUILTIN
522 #define TARGET_EXPAND_BUILTIN arm_expand_builtin
523 #undef TARGET_BUILTIN_DECL
524 #define TARGET_BUILTIN_DECL arm_builtin_decl
526 #undef TARGET_INIT_LIBFUNCS
527 #define TARGET_INIT_LIBFUNCS arm_init_libfuncs
529 #undef TARGET_PROMOTE_FUNCTION_MODE
530 #define TARGET_PROMOTE_FUNCTION_MODE arm_promote_function_mode
531 #undef TARGET_PROMOTE_PROTOTYPES
532 #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes
533 #undef TARGET_PASS_BY_REFERENCE
534 #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference
535 #undef TARGET_ARG_PARTIAL_BYTES
536 #define TARGET_ARG_PARTIAL_BYTES arm_arg_partial_bytes
537 #undef TARGET_FUNCTION_ARG
538 #define TARGET_FUNCTION_ARG arm_function_arg
539 #undef TARGET_FUNCTION_ARG_ADVANCE
540 #define TARGET_FUNCTION_ARG_ADVANCE arm_function_arg_advance
541 #undef TARGET_FUNCTION_ARG_PADDING
542 #define TARGET_FUNCTION_ARG_PADDING arm_function_arg_padding
543 #undef TARGET_FUNCTION_ARG_BOUNDARY
544 #define TARGET_FUNCTION_ARG_BOUNDARY arm_function_arg_boundary
546 #undef TARGET_SETUP_INCOMING_VARARGS
547 #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs
549 #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
550 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args
552 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
553 #define TARGET_ASM_TRAMPOLINE_TEMPLATE arm_asm_trampoline_template
554 #undef TARGET_TRAMPOLINE_INIT
555 #define TARGET_TRAMPOLINE_INIT arm_trampoline_init
556 #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
557 #define TARGET_TRAMPOLINE_ADJUST_ADDRESS arm_trampoline_adjust_address
559 #undef TARGET_WARN_FUNC_RETURN
560 #define TARGET_WARN_FUNC_RETURN arm_warn_func_return
562 #undef TARGET_DEFAULT_SHORT_ENUMS
563 #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
565 #undef TARGET_ALIGN_ANON_BITFIELD
566 #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield
568 #undef TARGET_NARROW_VOLATILE_BITFIELD
569 #define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
571 #undef TARGET_CXX_GUARD_TYPE
572 #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type
574 #undef TARGET_CXX_GUARD_MASK_BIT
575 #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit
577 #undef TARGET_CXX_GET_COOKIE_SIZE
578 #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size
580 #undef TARGET_CXX_COOKIE_HAS_SIZE
581 #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size
583 #undef TARGET_CXX_CDTOR_RETURNS_THIS
584 #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this
586 #undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE
587 #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline
589 #undef TARGET_CXX_USE_AEABI_ATEXIT
590 #define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit
592 #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY
593 #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \
594 arm_cxx_determine_class_data_visibility
596 #undef TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT
597 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT arm_cxx_class_data_always_comdat
599 #undef TARGET_RETURN_IN_MSB
600 #define TARGET_RETURN_IN_MSB arm_return_in_msb
602 #undef TARGET_RETURN_IN_MEMORY
603 #define TARGET_RETURN_IN_MEMORY arm_return_in_memory
605 #undef TARGET_MUST_PASS_IN_STACK
606 #define TARGET_MUST_PASS_IN_STACK arm_must_pass_in_stack
609 #undef TARGET_ASM_UNWIND_EMIT
610 #define TARGET_ASM_UNWIND_EMIT arm_unwind_emit
612 /* EABI unwinding tables use a different format for the typeinfo tables. */
613 #undef TARGET_ASM_TTYPE
614 #define TARGET_ASM_TTYPE arm_output_ttype
616 #undef TARGET_ARM_EABI_UNWINDER
617 #define TARGET_ARM_EABI_UNWINDER true
619 #undef TARGET_ASM_EMIT_EXCEPT_PERSONALITY
620 #define TARGET_ASM_EMIT_EXCEPT_PERSONALITY arm_asm_emit_except_personality
622 #endif /* ARM_UNWIND_INFO */
624 #undef TARGET_ASM_INIT_SECTIONS
625 #define TARGET_ASM_INIT_SECTIONS arm_asm_init_sections
627 #undef TARGET_DWARF_REGISTER_SPAN
628 #define TARGET_DWARF_REGISTER_SPAN arm_dwarf_register_span
630 #undef TARGET_CANNOT_COPY_INSN_P
631 #define TARGET_CANNOT_COPY_INSN_P arm_cannot_copy_insn_p
634 #undef TARGET_HAVE_TLS
635 #define TARGET_HAVE_TLS true
638 #undef TARGET_HAVE_CONDITIONAL_EXECUTION
639 #define TARGET_HAVE_CONDITIONAL_EXECUTION arm_have_conditional_execution
641 #undef TARGET_LEGITIMATE_CONSTANT_P
642 #define TARGET_LEGITIMATE_CONSTANT_P arm_legitimate_constant_p
644 #undef TARGET_CANNOT_FORCE_CONST_MEM
645 #define TARGET_CANNOT_FORCE_CONST_MEM arm_cannot_force_const_mem
647 #undef TARGET_MAX_ANCHOR_OFFSET
648 #define TARGET_MAX_ANCHOR_OFFSET 4095
650 /* The minimum is set such that the total size of the block
651 for a particular anchor is -4088 + 1 + 4095 bytes, which is
652 divisible by eight, ensuring natural spacing of anchors. */
653 #undef TARGET_MIN_ANCHOR_OFFSET
654 #define TARGET_MIN_ANCHOR_OFFSET -4088
656 #undef TARGET_SCHED_ISSUE_RATE
657 #define TARGET_SCHED_ISSUE_RATE arm_issue_rate
659 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
660 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
661 arm_first_cycle_multipass_dfa_lookahead
663 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD
664 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD \
665 arm_first_cycle_multipass_dfa_lookahead_guard
667 #undef TARGET_MANGLE_TYPE
668 #define TARGET_MANGLE_TYPE arm_mangle_type
670 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
671 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV arm_atomic_assign_expand_fenv
673 #undef TARGET_BUILD_BUILTIN_VA_LIST
674 #define TARGET_BUILD_BUILTIN_VA_LIST arm_build_builtin_va_list
675 #undef TARGET_EXPAND_BUILTIN_VA_START
676 #define TARGET_EXPAND_BUILTIN_VA_START arm_expand_builtin_va_start
677 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
678 #define TARGET_GIMPLIFY_VA_ARG_EXPR arm_gimplify_va_arg_expr
681 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
682 #define TARGET_ASM_OUTPUT_DWARF_DTPREL arm_output_dwarf_dtprel
685 #undef TARGET_LEGITIMATE_ADDRESS_P
686 #define TARGET_LEGITIMATE_ADDRESS_P arm_legitimate_address_p
688 #undef TARGET_PREFERRED_RELOAD_CLASS
689 #define TARGET_PREFERRED_RELOAD_CLASS arm_preferred_reload_class
691 #undef TARGET_PROMOTED_TYPE
692 #define TARGET_PROMOTED_TYPE arm_promoted_type
694 #undef TARGET_SCALAR_MODE_SUPPORTED_P
695 #define TARGET_SCALAR_MODE_SUPPORTED_P arm_scalar_mode_supported_p
697 #undef TARGET_COMPUTE_FRAME_LAYOUT
698 #define TARGET_COMPUTE_FRAME_LAYOUT arm_compute_frame_layout
700 #undef TARGET_FRAME_POINTER_REQUIRED
701 #define TARGET_FRAME_POINTER_REQUIRED arm_frame_pointer_required
703 #undef TARGET_CAN_ELIMINATE
704 #define TARGET_CAN_ELIMINATE arm_can_eliminate
706 #undef TARGET_CONDITIONAL_REGISTER_USAGE
707 #define TARGET_CONDITIONAL_REGISTER_USAGE arm_conditional_register_usage
709 #undef TARGET_CLASS_LIKELY_SPILLED_P
710 #define TARGET_CLASS_LIKELY_SPILLED_P arm_class_likely_spilled_p
712 #undef TARGET_VECTORIZE_BUILTINS
713 #define TARGET_VECTORIZE_BUILTINS
715 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
716 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
717 arm_builtin_vectorized_function
719 #undef TARGET_VECTOR_ALIGNMENT
720 #define TARGET_VECTOR_ALIGNMENT arm_vector_alignment
722 #undef TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE
723 #define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE \
724 arm_vector_alignment_reachable
726 #undef TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT
727 #define TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT \
728 arm_builtin_support_vector_misalignment
730 #undef TARGET_PREFERRED_RENAME_CLASS
731 #define TARGET_PREFERRED_RENAME_CLASS \
732 arm_preferred_rename_class
734 #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
735 #define TARGET_VECTORIZE_VEC_PERM_CONST_OK \
736 arm_vectorize_vec_perm_const_ok
738 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
739 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST \
740 arm_builtin_vectorization_cost
741 #undef TARGET_VECTORIZE_ADD_STMT_COST
742 #define TARGET_VECTORIZE_ADD_STMT_COST arm_add_stmt_cost
744 #undef TARGET_CANONICALIZE_COMPARISON
745 #define TARGET_CANONICALIZE_COMPARISON \
746 arm_canonicalize_comparison
748 #undef TARGET_ASAN_SHADOW_OFFSET
749 #define TARGET_ASAN_SHADOW_OFFSET arm_asan_shadow_offset
751 #undef MAX_INSN_PER_IT_BLOCK
752 #define MAX_INSN_PER_IT_BLOCK (arm_restrict_it ? 1 : 4)
754 #undef TARGET_CAN_USE_DOLOOP_P
755 #define TARGET_CAN_USE_DOLOOP_P can_use_doloop_if_innermost
757 #undef TARGET_CONST_NOT_OK_FOR_DEBUG_P
758 #define TARGET_CONST_NOT_OK_FOR_DEBUG_P arm_const_not_ok_for_debug_p
760 #undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS
761 #define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true
763 #undef TARGET_SCHED_FUSION_PRIORITY
764 #define TARGET_SCHED_FUSION_PRIORITY arm_sched_fusion_priority
766 #undef TARGET_ASM_FUNCTION_SECTION
767 #define TARGET_ASM_FUNCTION_SECTION arm_function_section
769 #undef TARGET_ASM_ELF_FLAGS_NUMERIC
770 #define TARGET_ASM_ELF_FLAGS_NUMERIC arm_asm_elf_flags_numeric
772 #undef TARGET_SECTION_TYPE_FLAGS
773 #define TARGET_SECTION_TYPE_FLAGS arm_elf_section_type_flags
775 #undef TARGET_EXPAND_DIVMOD_LIBFUNC
776 #define TARGET_EXPAND_DIVMOD_LIBFUNC arm_expand_divmod_libfunc
778 #undef TARGET_C_EXCESS_PRECISION
779 #define TARGET_C_EXCESS_PRECISION arm_excess_precision
781 /* Although the architecture reserves bits 0 and 1, only the former is
782 used for ARM/Thumb ISA selection in v7 and earlier versions. */
783 #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
784 #define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 2
786 #undef TARGET_FIXED_CONDITION_CODE_REGS
787 #define TARGET_FIXED_CONDITION_CODE_REGS arm_fixed_condition_code_regs
789 #undef TARGET_HARD_REGNO_NREGS
790 #define TARGET_HARD_REGNO_NREGS arm_hard_regno_nregs
791 #undef TARGET_HARD_REGNO_MODE_OK
792 #define TARGET_HARD_REGNO_MODE_OK arm_hard_regno_mode_ok
794 #undef TARGET_MODES_TIEABLE_P
795 #define TARGET_MODES_TIEABLE_P arm_modes_tieable_p
797 #undef TARGET_CAN_CHANGE_MODE_CLASS
798 #define TARGET_CAN_CHANGE_MODE_CLASS arm_can_change_mode_class
800 #undef TARGET_CONSTANT_ALIGNMENT
801 #define TARGET_CONSTANT_ALIGNMENT arm_constant_alignment
803 /* Obstack for minipool constant handling. */
804 static struct obstack minipool_obstack
;
805 static char * minipool_startobj
;
807 /* The maximum number of insns skipped which
808 will be conditionalised if possible. */
809 static int max_insns_skipped
= 5;
811 extern FILE * asm_out_file
;
813 /* True if we are currently building a constant table. */
814 int making_const_table
;
816 /* The processor for which instructions should be scheduled. */
817 enum processor_type arm_tune
= TARGET_CPU_arm_none
;
819 /* The current tuning set. */
820 const struct tune_params
*current_tune
;
822 /* Which floating point hardware to schedule for. */
825 /* Used for Thumb call_via trampolines. */
826 rtx thumb_call_via_label
[14];
827 static int thumb_call_reg_needed
;
829 /* The bits in this mask specify which instruction scheduling options should
831 unsigned int tune_flags
= 0;
833 /* The highest ARM architecture version supported by the
835 enum base_architecture arm_base_arch
= BASE_ARCH_0
;
837 /* Active target architecture and tuning. */
839 struct arm_build_target arm_active_target
;
841 /* The following are used in the arm.md file as equivalents to bits
842 in the above two flag variables. */
844 /* Nonzero if this chip supports the ARM Architecture 3M extensions. */
847 /* Nonzero if this chip supports the ARM Architecture 4 extensions. */
850 /* Nonzero if this chip supports the ARM Architecture 4t extensions. */
853 /* Nonzero if this chip supports the ARM Architecture 5 extensions. */
856 /* Nonzero if this chip supports the ARM Architecture 5E extensions. */
859 /* Nonzero if this chip supports the ARM Architecture 5TE extensions. */
862 /* Nonzero if this chip supports the ARM Architecture 6 extensions. */
865 /* Nonzero if this chip supports the ARM 6K extensions. */
868 /* Nonzero if this chip supports the ARM 6KZ extensions. */
871 /* Nonzero if instructions present in ARMv6-M can be used. */
874 /* Nonzero if this chip supports the ARM 7 extensions. */
877 /* Nonzero if this chip supports the Large Physical Address Extension. */
878 int arm_arch_lpae
= 0;
880 /* Nonzero if instructions not present in the 'M' profile can be used. */
881 int arm_arch_notm
= 0;
883 /* Nonzero if instructions present in ARMv7E-M can be used. */
886 /* Nonzero if instructions present in ARMv8 can be used. */
889 /* Nonzero if this chip supports the ARMv8.1 extensions. */
892 /* Nonzero if this chip supports the ARM Architecture 8.2 extensions. */
895 /* Nonzero if this chip supports the FP16 instructions extension of ARM
897 int arm_fp16_inst
= 0;
899 /* Nonzero if this chip can benefit from load scheduling. */
900 int arm_ld_sched
= 0;
902 /* Nonzero if this chip is a StrongARM. */
903 int arm_tune_strongarm
= 0;
905 /* Nonzero if this chip supports Intel Wireless MMX technology. */
906 int arm_arch_iwmmxt
= 0;
908 /* Nonzero if this chip supports Intel Wireless MMX2 technology. */
909 int arm_arch_iwmmxt2
= 0;
911 /* Nonzero if this chip is an XScale. */
912 int arm_arch_xscale
= 0;
914 /* Nonzero if tuning for XScale */
915 int arm_tune_xscale
= 0;
917 /* Nonzero if we want to tune for stores that access the write-buffer.
918 This typically means an ARM6 or ARM7 with MMU or MPU. */
919 int arm_tune_wbuf
= 0;
921 /* Nonzero if tuning for Cortex-A9. */
922 int arm_tune_cortex_a9
= 0;
924 /* Nonzero if we should define __THUMB_INTERWORK__ in the
926 XXX This is a bit of a hack, it's intended to help work around
927 problems in GLD which doesn't understand that armv5t code is
928 interworking clean. */
929 int arm_cpp_interwork
= 0;
931 /* Nonzero if chip supports Thumb 1. */
934 /* Nonzero if chip supports Thumb 2. */
937 /* Nonzero if chip supports integer division instruction. */
938 int arm_arch_arm_hwdiv
;
939 int arm_arch_thumb_hwdiv
;
941 /* Nonzero if chip disallows volatile memory access in IT block. */
942 int arm_arch_no_volatile_ce
;
944 /* Nonzero if we should use Neon to handle 64-bits operations rather
945 than core registers. */
946 int prefer_neon_for_64bits
= 0;
948 /* Nonzero if we shouldn't use literal pools. */
949 bool arm_disable_literal_pool
= false;
951 /* The register number to be used for the PIC offset register. */
952 unsigned arm_pic_register
= INVALID_REGNUM
;
954 enum arm_pcs arm_pcs_default
;
956 /* For an explanation of these variables, see final_prescan_insn below. */
958 /* arm_current_cc is also used for Thumb-2 cond_exec blocks. */
959 enum arm_cond_code arm_current_cc
;
962 int arm_target_label
;
963 /* The number of conditionally executed insns, including the current insn. */
964 int arm_condexec_count
= 0;
965 /* A bitmask specifying the patterns for the IT block.
966 Zero means do not output an IT block before this insn. */
967 int arm_condexec_mask
= 0;
968 /* The number of bits used in arm_condexec_mask. */
969 int arm_condexec_masklen
= 0;
971 /* Nonzero if chip supports the ARMv8 CRC instructions. */
972 int arm_arch_crc
= 0;
974 /* Nonzero if chip supports the ARMv8-M security extensions. */
975 int arm_arch_cmse
= 0;
977 /* Nonzero if the core has a very small, high-latency, multiply unit. */
978 int arm_m_profile_small_mul
= 0;
980 /* The condition codes of the ARM, and the inverse function. */
981 static const char * const arm_condition_codes
[] =
983 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
984 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
987 /* The register numbers in sequence, for passing to arm_gen_load_multiple. */
988 int arm_regs_in_sequence
[] =
990 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
993 #define ARM_LSL_NAME "lsl"
994 #define streq(string1, string2) (strcmp (string1, string2) == 0)
996 #define THUMB2_WORK_REGS (0xff & ~( (1 << THUMB_HARD_FRAME_POINTER_REGNUM) \
997 | (1 << SP_REGNUM) | (1 << PC_REGNUM) \
998 | (1 << PIC_OFFSET_TABLE_REGNUM)))
1000 /* Initialization code. */
1004 enum processor_type scheduler
;
1005 unsigned int tune_flags
;
1006 const struct tune_params
*tune
;
1009 #define ARM_PREFETCH_NOT_BENEFICIAL { 0, -1, -1 }
1010 #define ARM_PREFETCH_BENEFICIAL(num_slots,l1_size,l1_line_size) \
1017 /* arm generic vectorizer costs. */
1019 struct cpu_vec_costs arm_default_vec_cost
= {
1020 1, /* scalar_stmt_cost. */
1021 1, /* scalar load_cost. */
1022 1, /* scalar_store_cost. */
1023 1, /* vec_stmt_cost. */
1024 1, /* vec_to_scalar_cost. */
1025 1, /* scalar_to_vec_cost. */
1026 1, /* vec_align_load_cost. */
1027 1, /* vec_unalign_load_cost. */
1028 1, /* vec_unalign_store_cost. */
1029 1, /* vec_store_cost. */
1030 3, /* cond_taken_branch_cost. */
1031 1, /* cond_not_taken_branch_cost. */
1034 /* Cost tables for AArch32 + AArch64 cores should go in aarch-cost-tables.h */
1035 #include "aarch-cost-tables.h"
1039 const struct cpu_cost_table cortexa9_extra_costs
=
1046 COSTS_N_INSNS (1), /* shift_reg. */
1047 COSTS_N_INSNS (1), /* arith_shift. */
1048 COSTS_N_INSNS (2), /* arith_shift_reg. */
1050 COSTS_N_INSNS (1), /* log_shift_reg. */
1051 COSTS_N_INSNS (1), /* extend. */
1052 COSTS_N_INSNS (2), /* extend_arith. */
1053 COSTS_N_INSNS (1), /* bfi. */
1054 COSTS_N_INSNS (1), /* bfx. */
1058 true /* non_exec_costs_exec. */
1063 COSTS_N_INSNS (3), /* simple. */
1064 COSTS_N_INSNS (3), /* flag_setting. */
1065 COSTS_N_INSNS (2), /* extend. */
1066 COSTS_N_INSNS (3), /* add. */
1067 COSTS_N_INSNS (2), /* extend_add. */
1068 COSTS_N_INSNS (30) /* idiv. No HW div on Cortex A9. */
1072 0, /* simple (N/A). */
1073 0, /* flag_setting (N/A). */
1074 COSTS_N_INSNS (4), /* extend. */
1076 COSTS_N_INSNS (4), /* extend_add. */
1082 COSTS_N_INSNS (2), /* load. */
1083 COSTS_N_INSNS (2), /* load_sign_extend. */
1084 COSTS_N_INSNS (2), /* ldrd. */
1085 COSTS_N_INSNS (2), /* ldm_1st. */
1086 1, /* ldm_regs_per_insn_1st. */
1087 2, /* ldm_regs_per_insn_subsequent. */
1088 COSTS_N_INSNS (5), /* loadf. */
1089 COSTS_N_INSNS (5), /* loadd. */
1090 COSTS_N_INSNS (1), /* load_unaligned. */
1091 COSTS_N_INSNS (2), /* store. */
1092 COSTS_N_INSNS (2), /* strd. */
1093 COSTS_N_INSNS (2), /* stm_1st. */
1094 1, /* stm_regs_per_insn_1st. */
1095 2, /* stm_regs_per_insn_subsequent. */
1096 COSTS_N_INSNS (1), /* storef. */
1097 COSTS_N_INSNS (1), /* stored. */
1098 COSTS_N_INSNS (1), /* store_unaligned. */
1099 COSTS_N_INSNS (1), /* loadv. */
1100 COSTS_N_INSNS (1) /* storev. */
1105 COSTS_N_INSNS (14), /* div. */
1106 COSTS_N_INSNS (4), /* mult. */
1107 COSTS_N_INSNS (7), /* mult_addsub. */
1108 COSTS_N_INSNS (30), /* fma. */
1109 COSTS_N_INSNS (3), /* addsub. */
1110 COSTS_N_INSNS (1), /* fpconst. */
1111 COSTS_N_INSNS (1), /* neg. */
1112 COSTS_N_INSNS (3), /* compare. */
1113 COSTS_N_INSNS (3), /* widen. */
1114 COSTS_N_INSNS (3), /* narrow. */
1115 COSTS_N_INSNS (3), /* toint. */
1116 COSTS_N_INSNS (3), /* fromint. */
1117 COSTS_N_INSNS (3) /* roundint. */
1121 COSTS_N_INSNS (24), /* div. */
1122 COSTS_N_INSNS (5), /* mult. */
1123 COSTS_N_INSNS (8), /* mult_addsub. */
1124 COSTS_N_INSNS (30), /* fma. */
1125 COSTS_N_INSNS (3), /* addsub. */
1126 COSTS_N_INSNS (1), /* fpconst. */
1127 COSTS_N_INSNS (1), /* neg. */
1128 COSTS_N_INSNS (3), /* compare. */
1129 COSTS_N_INSNS (3), /* widen. */
1130 COSTS_N_INSNS (3), /* narrow. */
1131 COSTS_N_INSNS (3), /* toint. */
1132 COSTS_N_INSNS (3), /* fromint. */
1133 COSTS_N_INSNS (3) /* roundint. */
1138 COSTS_N_INSNS (1) /* alu. */
1142 const struct cpu_cost_table cortexa8_extra_costs
=
1148 COSTS_N_INSNS (1), /* shift. */
1150 COSTS_N_INSNS (1), /* arith_shift. */
1151 0, /* arith_shift_reg. */
1152 COSTS_N_INSNS (1), /* log_shift. */
1153 0, /* log_shift_reg. */
1155 0, /* extend_arith. */
1161 true /* non_exec_costs_exec. */
1166 COSTS_N_INSNS (1), /* simple. */
1167 COSTS_N_INSNS (1), /* flag_setting. */
1168 COSTS_N_INSNS (1), /* extend. */
1169 COSTS_N_INSNS (1), /* add. */
1170 COSTS_N_INSNS (1), /* extend_add. */
1171 COSTS_N_INSNS (30) /* idiv. No HW div on Cortex A8. */
1175 0, /* simple (N/A). */
1176 0, /* flag_setting (N/A). */
1177 COSTS_N_INSNS (2), /* extend. */
1179 COSTS_N_INSNS (2), /* extend_add. */
1185 COSTS_N_INSNS (1), /* load. */
1186 COSTS_N_INSNS (1), /* load_sign_extend. */
1187 COSTS_N_INSNS (1), /* ldrd. */
1188 COSTS_N_INSNS (1), /* ldm_1st. */
1189 1, /* ldm_regs_per_insn_1st. */
1190 2, /* ldm_regs_per_insn_subsequent. */
1191 COSTS_N_INSNS (1), /* loadf. */
1192 COSTS_N_INSNS (1), /* loadd. */
1193 COSTS_N_INSNS (1), /* load_unaligned. */
1194 COSTS_N_INSNS (1), /* store. */
1195 COSTS_N_INSNS (1), /* strd. */
1196 COSTS_N_INSNS (1), /* stm_1st. */
1197 1, /* stm_regs_per_insn_1st. */
1198 2, /* stm_regs_per_insn_subsequent. */
1199 COSTS_N_INSNS (1), /* storef. */
1200 COSTS_N_INSNS (1), /* stored. */
1201 COSTS_N_INSNS (1), /* store_unaligned. */
1202 COSTS_N_INSNS (1), /* loadv. */
1203 COSTS_N_INSNS (1) /* storev. */
1208 COSTS_N_INSNS (36), /* div. */
1209 COSTS_N_INSNS (11), /* mult. */
1210 COSTS_N_INSNS (20), /* mult_addsub. */
1211 COSTS_N_INSNS (30), /* fma. */
1212 COSTS_N_INSNS (9), /* addsub. */
1213 COSTS_N_INSNS (3), /* fpconst. */
1214 COSTS_N_INSNS (3), /* neg. */
1215 COSTS_N_INSNS (6), /* compare. */
1216 COSTS_N_INSNS (4), /* widen. */
1217 COSTS_N_INSNS (4), /* narrow. */
1218 COSTS_N_INSNS (8), /* toint. */
1219 COSTS_N_INSNS (8), /* fromint. */
1220 COSTS_N_INSNS (8) /* roundint. */
1224 COSTS_N_INSNS (64), /* div. */
1225 COSTS_N_INSNS (16), /* mult. */
1226 COSTS_N_INSNS (25), /* mult_addsub. */
1227 COSTS_N_INSNS (30), /* fma. */
1228 COSTS_N_INSNS (9), /* addsub. */
1229 COSTS_N_INSNS (3), /* fpconst. */
1230 COSTS_N_INSNS (3), /* neg. */
1231 COSTS_N_INSNS (6), /* compare. */
1232 COSTS_N_INSNS (6), /* widen. */
1233 COSTS_N_INSNS (6), /* narrow. */
1234 COSTS_N_INSNS (8), /* toint. */
1235 COSTS_N_INSNS (8), /* fromint. */
1236 COSTS_N_INSNS (8) /* roundint. */
1241 COSTS_N_INSNS (1) /* alu. */
1245 const struct cpu_cost_table cortexa5_extra_costs
=
1251 COSTS_N_INSNS (1), /* shift. */
1252 COSTS_N_INSNS (1), /* shift_reg. */
1253 COSTS_N_INSNS (1), /* arith_shift. */
1254 COSTS_N_INSNS (1), /* arith_shift_reg. */
1255 COSTS_N_INSNS (1), /* log_shift. */
1256 COSTS_N_INSNS (1), /* log_shift_reg. */
1257 COSTS_N_INSNS (1), /* extend. */
1258 COSTS_N_INSNS (1), /* extend_arith. */
1259 COSTS_N_INSNS (1), /* bfi. */
1260 COSTS_N_INSNS (1), /* bfx. */
1261 COSTS_N_INSNS (1), /* clz. */
1262 COSTS_N_INSNS (1), /* rev. */
1264 true /* non_exec_costs_exec. */
1271 COSTS_N_INSNS (1), /* flag_setting. */
1272 COSTS_N_INSNS (1), /* extend. */
1273 COSTS_N_INSNS (1), /* add. */
1274 COSTS_N_INSNS (1), /* extend_add. */
1275 COSTS_N_INSNS (7) /* idiv. */
1279 0, /* simple (N/A). */
1280 0, /* flag_setting (N/A). */
1281 COSTS_N_INSNS (1), /* extend. */
1283 COSTS_N_INSNS (2), /* extend_add. */
1289 COSTS_N_INSNS (1), /* load. */
1290 COSTS_N_INSNS (1), /* load_sign_extend. */
1291 COSTS_N_INSNS (6), /* ldrd. */
1292 COSTS_N_INSNS (1), /* ldm_1st. */
1293 1, /* ldm_regs_per_insn_1st. */
1294 2, /* ldm_regs_per_insn_subsequent. */
1295 COSTS_N_INSNS (2), /* loadf. */
1296 COSTS_N_INSNS (4), /* loadd. */
1297 COSTS_N_INSNS (1), /* load_unaligned. */
1298 COSTS_N_INSNS (1), /* store. */
1299 COSTS_N_INSNS (3), /* strd. */
1300 COSTS_N_INSNS (1), /* stm_1st. */
1301 1, /* stm_regs_per_insn_1st. */
1302 2, /* stm_regs_per_insn_subsequent. */
1303 COSTS_N_INSNS (2), /* storef. */
1304 COSTS_N_INSNS (2), /* stored. */
1305 COSTS_N_INSNS (1), /* store_unaligned. */
1306 COSTS_N_INSNS (1), /* loadv. */
1307 COSTS_N_INSNS (1) /* storev. */
1312 COSTS_N_INSNS (15), /* div. */
1313 COSTS_N_INSNS (3), /* mult. */
1314 COSTS_N_INSNS (7), /* mult_addsub. */
1315 COSTS_N_INSNS (7), /* fma. */
1316 COSTS_N_INSNS (3), /* addsub. */
1317 COSTS_N_INSNS (3), /* fpconst. */
1318 COSTS_N_INSNS (3), /* neg. */
1319 COSTS_N_INSNS (3), /* compare. */
1320 COSTS_N_INSNS (3), /* widen. */
1321 COSTS_N_INSNS (3), /* narrow. */
1322 COSTS_N_INSNS (3), /* toint. */
1323 COSTS_N_INSNS (3), /* fromint. */
1324 COSTS_N_INSNS (3) /* roundint. */
1328 COSTS_N_INSNS (30), /* div. */
1329 COSTS_N_INSNS (6), /* mult. */
1330 COSTS_N_INSNS (10), /* mult_addsub. */
1331 COSTS_N_INSNS (7), /* fma. */
1332 COSTS_N_INSNS (3), /* addsub. */
1333 COSTS_N_INSNS (3), /* fpconst. */
1334 COSTS_N_INSNS (3), /* neg. */
1335 COSTS_N_INSNS (3), /* compare. */
1336 COSTS_N_INSNS (3), /* widen. */
1337 COSTS_N_INSNS (3), /* narrow. */
1338 COSTS_N_INSNS (3), /* toint. */
1339 COSTS_N_INSNS (3), /* fromint. */
1340 COSTS_N_INSNS (3) /* roundint. */
1345 COSTS_N_INSNS (1) /* alu. */
1350 const struct cpu_cost_table cortexa7_extra_costs
=
1356 COSTS_N_INSNS (1), /* shift. */
1357 COSTS_N_INSNS (1), /* shift_reg. */
1358 COSTS_N_INSNS (1), /* arith_shift. */
1359 COSTS_N_INSNS (1), /* arith_shift_reg. */
1360 COSTS_N_INSNS (1), /* log_shift. */
1361 COSTS_N_INSNS (1), /* log_shift_reg. */
1362 COSTS_N_INSNS (1), /* extend. */
1363 COSTS_N_INSNS (1), /* extend_arith. */
1364 COSTS_N_INSNS (1), /* bfi. */
1365 COSTS_N_INSNS (1), /* bfx. */
1366 COSTS_N_INSNS (1), /* clz. */
1367 COSTS_N_INSNS (1), /* rev. */
1369 true /* non_exec_costs_exec. */
1376 COSTS_N_INSNS (1), /* flag_setting. */
1377 COSTS_N_INSNS (1), /* extend. */
1378 COSTS_N_INSNS (1), /* add. */
1379 COSTS_N_INSNS (1), /* extend_add. */
1380 COSTS_N_INSNS (7) /* idiv. */
1384 0, /* simple (N/A). */
1385 0, /* flag_setting (N/A). */
1386 COSTS_N_INSNS (1), /* extend. */
1388 COSTS_N_INSNS (2), /* extend_add. */
1394 COSTS_N_INSNS (1), /* load. */
1395 COSTS_N_INSNS (1), /* load_sign_extend. */
1396 COSTS_N_INSNS (3), /* ldrd. */
1397 COSTS_N_INSNS (1), /* ldm_1st. */
1398 1, /* ldm_regs_per_insn_1st. */
1399 2, /* ldm_regs_per_insn_subsequent. */
1400 COSTS_N_INSNS (2), /* loadf. */
1401 COSTS_N_INSNS (2), /* loadd. */
1402 COSTS_N_INSNS (1), /* load_unaligned. */
1403 COSTS_N_INSNS (1), /* store. */
1404 COSTS_N_INSNS (3), /* strd. */
1405 COSTS_N_INSNS (1), /* stm_1st. */
1406 1, /* stm_regs_per_insn_1st. */
1407 2, /* stm_regs_per_insn_subsequent. */
1408 COSTS_N_INSNS (2), /* storef. */
1409 COSTS_N_INSNS (2), /* stored. */
1410 COSTS_N_INSNS (1), /* store_unaligned. */
1411 COSTS_N_INSNS (1), /* loadv. */
1412 COSTS_N_INSNS (1) /* storev. */
1417 COSTS_N_INSNS (15), /* div. */
1418 COSTS_N_INSNS (3), /* mult. */
1419 COSTS_N_INSNS (7), /* mult_addsub. */
1420 COSTS_N_INSNS (7), /* fma. */
1421 COSTS_N_INSNS (3), /* addsub. */
1422 COSTS_N_INSNS (3), /* fpconst. */
1423 COSTS_N_INSNS (3), /* neg. */
1424 COSTS_N_INSNS (3), /* compare. */
1425 COSTS_N_INSNS (3), /* widen. */
1426 COSTS_N_INSNS (3), /* narrow. */
1427 COSTS_N_INSNS (3), /* toint. */
1428 COSTS_N_INSNS (3), /* fromint. */
1429 COSTS_N_INSNS (3) /* roundint. */
1433 COSTS_N_INSNS (30), /* div. */
1434 COSTS_N_INSNS (6), /* mult. */
1435 COSTS_N_INSNS (10), /* mult_addsub. */
1436 COSTS_N_INSNS (7), /* fma. */
1437 COSTS_N_INSNS (3), /* addsub. */
1438 COSTS_N_INSNS (3), /* fpconst. */
1439 COSTS_N_INSNS (3), /* neg. */
1440 COSTS_N_INSNS (3), /* compare. */
1441 COSTS_N_INSNS (3), /* widen. */
1442 COSTS_N_INSNS (3), /* narrow. */
1443 COSTS_N_INSNS (3), /* toint. */
1444 COSTS_N_INSNS (3), /* fromint. */
1445 COSTS_N_INSNS (3) /* roundint. */
1450 COSTS_N_INSNS (1) /* alu. */
1454 const struct cpu_cost_table cortexa12_extra_costs
=
1461 COSTS_N_INSNS (1), /* shift_reg. */
1462 COSTS_N_INSNS (1), /* arith_shift. */
1463 COSTS_N_INSNS (1), /* arith_shift_reg. */
1464 COSTS_N_INSNS (1), /* log_shift. */
1465 COSTS_N_INSNS (1), /* log_shift_reg. */
1467 COSTS_N_INSNS (1), /* extend_arith. */
1469 COSTS_N_INSNS (1), /* bfx. */
1470 COSTS_N_INSNS (1), /* clz. */
1471 COSTS_N_INSNS (1), /* rev. */
1473 true /* non_exec_costs_exec. */
1478 COSTS_N_INSNS (2), /* simple. */
1479 COSTS_N_INSNS (3), /* flag_setting. */
1480 COSTS_N_INSNS (2), /* extend. */
1481 COSTS_N_INSNS (3), /* add. */
1482 COSTS_N_INSNS (2), /* extend_add. */
1483 COSTS_N_INSNS (18) /* idiv. */
1487 0, /* simple (N/A). */
1488 0, /* flag_setting (N/A). */
1489 COSTS_N_INSNS (3), /* extend. */
1491 COSTS_N_INSNS (3), /* extend_add. */
1497 COSTS_N_INSNS (3), /* load. */
1498 COSTS_N_INSNS (3), /* load_sign_extend. */
1499 COSTS_N_INSNS (3), /* ldrd. */
1500 COSTS_N_INSNS (3), /* ldm_1st. */
1501 1, /* ldm_regs_per_insn_1st. */
1502 2, /* ldm_regs_per_insn_subsequent. */
1503 COSTS_N_INSNS (3), /* loadf. */
1504 COSTS_N_INSNS (3), /* loadd. */
1505 0, /* load_unaligned. */
1509 1, /* stm_regs_per_insn_1st. */
1510 2, /* stm_regs_per_insn_subsequent. */
1511 COSTS_N_INSNS (2), /* storef. */
1512 COSTS_N_INSNS (2), /* stored. */
1513 0, /* store_unaligned. */
1514 COSTS_N_INSNS (1), /* loadv. */
1515 COSTS_N_INSNS (1) /* storev. */
1520 COSTS_N_INSNS (17), /* div. */
1521 COSTS_N_INSNS (4), /* mult. */
1522 COSTS_N_INSNS (8), /* mult_addsub. */
1523 COSTS_N_INSNS (8), /* fma. */
1524 COSTS_N_INSNS (4), /* addsub. */
1525 COSTS_N_INSNS (2), /* fpconst. */
1526 COSTS_N_INSNS (2), /* neg. */
1527 COSTS_N_INSNS (2), /* compare. */
1528 COSTS_N_INSNS (4), /* widen. */
1529 COSTS_N_INSNS (4), /* narrow. */
1530 COSTS_N_INSNS (4), /* toint. */
1531 COSTS_N_INSNS (4), /* fromint. */
1532 COSTS_N_INSNS (4) /* roundint. */
1536 COSTS_N_INSNS (31), /* div. */
1537 COSTS_N_INSNS (4), /* mult. */
1538 COSTS_N_INSNS (8), /* mult_addsub. */
1539 COSTS_N_INSNS (8), /* fma. */
1540 COSTS_N_INSNS (4), /* addsub. */
1541 COSTS_N_INSNS (2), /* fpconst. */
1542 COSTS_N_INSNS (2), /* neg. */
1543 COSTS_N_INSNS (2), /* compare. */
1544 COSTS_N_INSNS (4), /* widen. */
1545 COSTS_N_INSNS (4), /* narrow. */
1546 COSTS_N_INSNS (4), /* toint. */
1547 COSTS_N_INSNS (4), /* fromint. */
1548 COSTS_N_INSNS (4) /* roundint. */
1553 COSTS_N_INSNS (1) /* alu. */
1557 const struct cpu_cost_table cortexa15_extra_costs
=
1565 COSTS_N_INSNS (1), /* arith_shift. */
1566 COSTS_N_INSNS (1), /* arith_shift_reg. */
1567 COSTS_N_INSNS (1), /* log_shift. */
1568 COSTS_N_INSNS (1), /* log_shift_reg. */
1570 COSTS_N_INSNS (1), /* extend_arith. */
1571 COSTS_N_INSNS (1), /* bfi. */
1576 true /* non_exec_costs_exec. */
1581 COSTS_N_INSNS (2), /* simple. */
1582 COSTS_N_INSNS (3), /* flag_setting. */
1583 COSTS_N_INSNS (2), /* extend. */
1584 COSTS_N_INSNS (2), /* add. */
1585 COSTS_N_INSNS (2), /* extend_add. */
1586 COSTS_N_INSNS (18) /* idiv. */
1590 0, /* simple (N/A). */
1591 0, /* flag_setting (N/A). */
1592 COSTS_N_INSNS (3), /* extend. */
1594 COSTS_N_INSNS (3), /* extend_add. */
1600 COSTS_N_INSNS (3), /* load. */
1601 COSTS_N_INSNS (3), /* load_sign_extend. */
1602 COSTS_N_INSNS (3), /* ldrd. */
1603 COSTS_N_INSNS (4), /* ldm_1st. */
1604 1, /* ldm_regs_per_insn_1st. */
1605 2, /* ldm_regs_per_insn_subsequent. */
1606 COSTS_N_INSNS (4), /* loadf. */
1607 COSTS_N_INSNS (4), /* loadd. */
1608 0, /* load_unaligned. */
1611 COSTS_N_INSNS (1), /* stm_1st. */
1612 1, /* stm_regs_per_insn_1st. */
1613 2, /* stm_regs_per_insn_subsequent. */
1616 0, /* store_unaligned. */
1617 COSTS_N_INSNS (1), /* loadv. */
1618 COSTS_N_INSNS (1) /* storev. */
1623 COSTS_N_INSNS (17), /* div. */
1624 COSTS_N_INSNS (4), /* mult. */
1625 COSTS_N_INSNS (8), /* mult_addsub. */
1626 COSTS_N_INSNS (8), /* fma. */
1627 COSTS_N_INSNS (4), /* addsub. */
1628 COSTS_N_INSNS (2), /* fpconst. */
1629 COSTS_N_INSNS (2), /* neg. */
1630 COSTS_N_INSNS (5), /* compare. */
1631 COSTS_N_INSNS (4), /* widen. */
1632 COSTS_N_INSNS (4), /* narrow. */
1633 COSTS_N_INSNS (4), /* toint. */
1634 COSTS_N_INSNS (4), /* fromint. */
1635 COSTS_N_INSNS (4) /* roundint. */
1639 COSTS_N_INSNS (31), /* div. */
1640 COSTS_N_INSNS (4), /* mult. */
1641 COSTS_N_INSNS (8), /* mult_addsub. */
1642 COSTS_N_INSNS (8), /* fma. */
1643 COSTS_N_INSNS (4), /* addsub. */
1644 COSTS_N_INSNS (2), /* fpconst. */
1645 COSTS_N_INSNS (2), /* neg. */
1646 COSTS_N_INSNS (2), /* compare. */
1647 COSTS_N_INSNS (4), /* widen. */
1648 COSTS_N_INSNS (4), /* narrow. */
1649 COSTS_N_INSNS (4), /* toint. */
1650 COSTS_N_INSNS (4), /* fromint. */
1651 COSTS_N_INSNS (4) /* roundint. */
1656 COSTS_N_INSNS (1) /* alu. */
1660 const struct cpu_cost_table v7m_extra_costs
=
1668 0, /* arith_shift. */
1669 COSTS_N_INSNS (1), /* arith_shift_reg. */
1671 COSTS_N_INSNS (1), /* log_shift_reg. */
1673 COSTS_N_INSNS (1), /* extend_arith. */
1678 COSTS_N_INSNS (1), /* non_exec. */
1679 false /* non_exec_costs_exec. */
1684 COSTS_N_INSNS (1), /* simple. */
1685 COSTS_N_INSNS (1), /* flag_setting. */
1686 COSTS_N_INSNS (2), /* extend. */
1687 COSTS_N_INSNS (1), /* add. */
1688 COSTS_N_INSNS (3), /* extend_add. */
1689 COSTS_N_INSNS (8) /* idiv. */
1693 0, /* simple (N/A). */
1694 0, /* flag_setting (N/A). */
1695 COSTS_N_INSNS (2), /* extend. */
1697 COSTS_N_INSNS (3), /* extend_add. */
1703 COSTS_N_INSNS (2), /* load. */
1704 0, /* load_sign_extend. */
1705 COSTS_N_INSNS (3), /* ldrd. */
1706 COSTS_N_INSNS (2), /* ldm_1st. */
1707 1, /* ldm_regs_per_insn_1st. */
1708 1, /* ldm_regs_per_insn_subsequent. */
1709 COSTS_N_INSNS (2), /* loadf. */
1710 COSTS_N_INSNS (3), /* loadd. */
1711 COSTS_N_INSNS (1), /* load_unaligned. */
1712 COSTS_N_INSNS (2), /* store. */
1713 COSTS_N_INSNS (3), /* strd. */
1714 COSTS_N_INSNS (2), /* stm_1st. */
1715 1, /* stm_regs_per_insn_1st. */
1716 1, /* stm_regs_per_insn_subsequent. */
1717 COSTS_N_INSNS (2), /* storef. */
1718 COSTS_N_INSNS (3), /* stored. */
1719 COSTS_N_INSNS (1), /* store_unaligned. */
1720 COSTS_N_INSNS (1), /* loadv. */
1721 COSTS_N_INSNS (1) /* storev. */
1726 COSTS_N_INSNS (7), /* div. */
1727 COSTS_N_INSNS (2), /* mult. */
1728 COSTS_N_INSNS (5), /* mult_addsub. */
1729 COSTS_N_INSNS (3), /* fma. */
1730 COSTS_N_INSNS (1), /* addsub. */
1742 COSTS_N_INSNS (15), /* div. */
1743 COSTS_N_INSNS (5), /* mult. */
1744 COSTS_N_INSNS (7), /* mult_addsub. */
1745 COSTS_N_INSNS (7), /* fma. */
1746 COSTS_N_INSNS (3), /* addsub. */
1759 COSTS_N_INSNS (1) /* alu. */
1763 const struct tune_params arm_slowmul_tune
=
1765 &generic_extra_costs
, /* Insn extra costs. */
1766 NULL
, /* Sched adj cost. */
1767 arm_default_branch_cost
,
1768 &arm_default_vec_cost
,
1769 3, /* Constant limit. */
1770 5, /* Max cond insns. */
1771 8, /* Memset max inline. */
1772 1, /* Issue rate. */
1773 ARM_PREFETCH_NOT_BENEFICIAL
,
1774 tune_params::PREF_CONST_POOL_TRUE
,
1775 tune_params::PREF_LDRD_FALSE
,
1776 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
1777 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
1778 tune_params::DISPARAGE_FLAGS_NEITHER
,
1779 tune_params::PREF_NEON_64_FALSE
,
1780 tune_params::PREF_NEON_STRINGOPS_FALSE
,
1781 tune_params::FUSE_NOTHING
,
1782 tune_params::SCHED_AUTOPREF_OFF
1785 const struct tune_params arm_fastmul_tune
=
1787 &generic_extra_costs
, /* Insn extra costs. */
1788 NULL
, /* Sched adj cost. */
1789 arm_default_branch_cost
,
1790 &arm_default_vec_cost
,
1791 1, /* Constant limit. */
1792 5, /* Max cond insns. */
1793 8, /* Memset max inline. */
1794 1, /* Issue rate. */
1795 ARM_PREFETCH_NOT_BENEFICIAL
,
1796 tune_params::PREF_CONST_POOL_TRUE
,
1797 tune_params::PREF_LDRD_FALSE
,
1798 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
1799 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
1800 tune_params::DISPARAGE_FLAGS_NEITHER
,
1801 tune_params::PREF_NEON_64_FALSE
,
1802 tune_params::PREF_NEON_STRINGOPS_FALSE
,
1803 tune_params::FUSE_NOTHING
,
1804 tune_params::SCHED_AUTOPREF_OFF
1807 /* StrongARM has early execution of branches, so a sequence that is worth
1808 skipping is shorter. Set max_insns_skipped to a lower value. */
1810 const struct tune_params arm_strongarm_tune
=
1812 &generic_extra_costs
, /* Insn extra costs. */
1813 NULL
, /* Sched adj cost. */
1814 arm_default_branch_cost
,
1815 &arm_default_vec_cost
,
1816 1, /* Constant limit. */
1817 3, /* Max cond insns. */
1818 8, /* Memset max inline. */
1819 1, /* Issue rate. */
1820 ARM_PREFETCH_NOT_BENEFICIAL
,
1821 tune_params::PREF_CONST_POOL_TRUE
,
1822 tune_params::PREF_LDRD_FALSE
,
1823 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
1824 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
1825 tune_params::DISPARAGE_FLAGS_NEITHER
,
1826 tune_params::PREF_NEON_64_FALSE
,
1827 tune_params::PREF_NEON_STRINGOPS_FALSE
,
1828 tune_params::FUSE_NOTHING
,
1829 tune_params::SCHED_AUTOPREF_OFF
1832 const struct tune_params arm_xscale_tune
=
1834 &generic_extra_costs
, /* Insn extra costs. */
1835 xscale_sched_adjust_cost
,
1836 arm_default_branch_cost
,
1837 &arm_default_vec_cost
,
1838 2, /* Constant limit. */
1839 3, /* Max cond insns. */
1840 8, /* Memset max inline. */
1841 1, /* Issue rate. */
1842 ARM_PREFETCH_NOT_BENEFICIAL
,
1843 tune_params::PREF_CONST_POOL_TRUE
,
1844 tune_params::PREF_LDRD_FALSE
,
1845 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
1846 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
1847 tune_params::DISPARAGE_FLAGS_NEITHER
,
1848 tune_params::PREF_NEON_64_FALSE
,
1849 tune_params::PREF_NEON_STRINGOPS_FALSE
,
1850 tune_params::FUSE_NOTHING
,
1851 tune_params::SCHED_AUTOPREF_OFF
1854 const struct tune_params arm_9e_tune
=
1856 &generic_extra_costs
, /* Insn extra costs. */
1857 NULL
, /* Sched adj cost. */
1858 arm_default_branch_cost
,
1859 &arm_default_vec_cost
,
1860 1, /* Constant limit. */
1861 5, /* Max cond insns. */
1862 8, /* Memset max inline. */
1863 1, /* Issue rate. */
1864 ARM_PREFETCH_NOT_BENEFICIAL
,
1865 tune_params::PREF_CONST_POOL_TRUE
,
1866 tune_params::PREF_LDRD_FALSE
,
1867 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
1868 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
1869 tune_params::DISPARAGE_FLAGS_NEITHER
,
1870 tune_params::PREF_NEON_64_FALSE
,
1871 tune_params::PREF_NEON_STRINGOPS_FALSE
,
1872 tune_params::FUSE_NOTHING
,
1873 tune_params::SCHED_AUTOPREF_OFF
1876 const struct tune_params arm_marvell_pj4_tune
=
1878 &generic_extra_costs
, /* Insn extra costs. */
1879 NULL
, /* Sched adj cost. */
1880 arm_default_branch_cost
,
1881 &arm_default_vec_cost
,
1882 1, /* Constant limit. */
1883 5, /* Max cond insns. */
1884 8, /* Memset max inline. */
1885 2, /* Issue rate. */
1886 ARM_PREFETCH_NOT_BENEFICIAL
,
1887 tune_params::PREF_CONST_POOL_TRUE
,
1888 tune_params::PREF_LDRD_FALSE
,
1889 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
1890 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
1891 tune_params::DISPARAGE_FLAGS_NEITHER
,
1892 tune_params::PREF_NEON_64_FALSE
,
1893 tune_params::PREF_NEON_STRINGOPS_FALSE
,
1894 tune_params::FUSE_NOTHING
,
1895 tune_params::SCHED_AUTOPREF_OFF
1898 const struct tune_params arm_v6t2_tune
=
1900 &generic_extra_costs
, /* Insn extra costs. */
1901 NULL
, /* Sched adj cost. */
1902 arm_default_branch_cost
,
1903 &arm_default_vec_cost
,
1904 1, /* Constant limit. */
1905 5, /* Max cond insns. */
1906 8, /* Memset max inline. */
1907 1, /* Issue rate. */
1908 ARM_PREFETCH_NOT_BENEFICIAL
,
1909 tune_params::PREF_CONST_POOL_FALSE
,
1910 tune_params::PREF_LDRD_FALSE
,
1911 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
1912 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
1913 tune_params::DISPARAGE_FLAGS_NEITHER
,
1914 tune_params::PREF_NEON_64_FALSE
,
1915 tune_params::PREF_NEON_STRINGOPS_FALSE
,
1916 tune_params::FUSE_NOTHING
,
1917 tune_params::SCHED_AUTOPREF_OFF
1921 /* Generic Cortex tuning. Use more specific tunings if appropriate. */
1922 const struct tune_params arm_cortex_tune
=
1924 &generic_extra_costs
,
1925 NULL
, /* Sched adj cost. */
1926 arm_default_branch_cost
,
1927 &arm_default_vec_cost
,
1928 1, /* Constant limit. */
1929 5, /* Max cond insns. */
1930 8, /* Memset max inline. */
1931 2, /* Issue rate. */
1932 ARM_PREFETCH_NOT_BENEFICIAL
,
1933 tune_params::PREF_CONST_POOL_FALSE
,
1934 tune_params::PREF_LDRD_FALSE
,
1935 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
1936 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
1937 tune_params::DISPARAGE_FLAGS_NEITHER
,
1938 tune_params::PREF_NEON_64_FALSE
,
1939 tune_params::PREF_NEON_STRINGOPS_FALSE
,
1940 tune_params::FUSE_NOTHING
,
1941 tune_params::SCHED_AUTOPREF_OFF
1944 const struct tune_params arm_cortex_a8_tune
=
1946 &cortexa8_extra_costs
,
1947 NULL
, /* Sched adj cost. */
1948 arm_default_branch_cost
,
1949 &arm_default_vec_cost
,
1950 1, /* Constant limit. */
1951 5, /* Max cond insns. */
1952 8, /* Memset max inline. */
1953 2, /* Issue rate. */
1954 ARM_PREFETCH_NOT_BENEFICIAL
,
1955 tune_params::PREF_CONST_POOL_FALSE
,
1956 tune_params::PREF_LDRD_FALSE
,
1957 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
1958 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
1959 tune_params::DISPARAGE_FLAGS_NEITHER
,
1960 tune_params::PREF_NEON_64_FALSE
,
1961 tune_params::PREF_NEON_STRINGOPS_TRUE
,
1962 tune_params::FUSE_NOTHING
,
1963 tune_params::SCHED_AUTOPREF_OFF
1966 const struct tune_params arm_cortex_a7_tune
=
1968 &cortexa7_extra_costs
,
1969 NULL
, /* Sched adj cost. */
1970 arm_default_branch_cost
,
1971 &arm_default_vec_cost
,
1972 1, /* Constant limit. */
1973 5, /* Max cond insns. */
1974 8, /* Memset max inline. */
1975 2, /* Issue rate. */
1976 ARM_PREFETCH_NOT_BENEFICIAL
,
1977 tune_params::PREF_CONST_POOL_FALSE
,
1978 tune_params::PREF_LDRD_FALSE
,
1979 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
1980 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
1981 tune_params::DISPARAGE_FLAGS_NEITHER
,
1982 tune_params::PREF_NEON_64_FALSE
,
1983 tune_params::PREF_NEON_STRINGOPS_TRUE
,
1984 tune_params::FUSE_NOTHING
,
1985 tune_params::SCHED_AUTOPREF_OFF
1988 const struct tune_params arm_cortex_a15_tune
=
1990 &cortexa15_extra_costs
,
1991 NULL
, /* Sched adj cost. */
1992 arm_default_branch_cost
,
1993 &arm_default_vec_cost
,
1994 1, /* Constant limit. */
1995 2, /* Max cond insns. */
1996 8, /* Memset max inline. */
1997 3, /* Issue rate. */
1998 ARM_PREFETCH_NOT_BENEFICIAL
,
1999 tune_params::PREF_CONST_POOL_FALSE
,
2000 tune_params::PREF_LDRD_TRUE
,
2001 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
2002 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
2003 tune_params::DISPARAGE_FLAGS_ALL
,
2004 tune_params::PREF_NEON_64_FALSE
,
2005 tune_params::PREF_NEON_STRINGOPS_TRUE
,
2006 tune_params::FUSE_NOTHING
,
2007 tune_params::SCHED_AUTOPREF_FULL
2010 const struct tune_params arm_cortex_a35_tune
=
2012 &cortexa53_extra_costs
,
2013 NULL
, /* Sched adj cost. */
2014 arm_default_branch_cost
,
2015 &arm_default_vec_cost
,
2016 1, /* Constant limit. */
2017 5, /* Max cond insns. */
2018 8, /* Memset max inline. */
2019 1, /* Issue rate. */
2020 ARM_PREFETCH_NOT_BENEFICIAL
,
2021 tune_params::PREF_CONST_POOL_FALSE
,
2022 tune_params::PREF_LDRD_FALSE
,
2023 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
2024 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
2025 tune_params::DISPARAGE_FLAGS_NEITHER
,
2026 tune_params::PREF_NEON_64_FALSE
,
2027 tune_params::PREF_NEON_STRINGOPS_TRUE
,
2028 FUSE_OPS (tune_params::FUSE_MOVW_MOVT
),
2029 tune_params::SCHED_AUTOPREF_OFF
2032 const struct tune_params arm_cortex_a53_tune
=
2034 &cortexa53_extra_costs
,
2035 NULL
, /* Sched adj cost. */
2036 arm_default_branch_cost
,
2037 &arm_default_vec_cost
,
2038 1, /* Constant limit. */
2039 5, /* Max cond insns. */
2040 8, /* Memset max inline. */
2041 2, /* Issue rate. */
2042 ARM_PREFETCH_NOT_BENEFICIAL
,
2043 tune_params::PREF_CONST_POOL_FALSE
,
2044 tune_params::PREF_LDRD_FALSE
,
2045 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
2046 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
2047 tune_params::DISPARAGE_FLAGS_NEITHER
,
2048 tune_params::PREF_NEON_64_FALSE
,
2049 tune_params::PREF_NEON_STRINGOPS_TRUE
,
2050 FUSE_OPS (tune_params::FUSE_MOVW_MOVT
| tune_params::FUSE_AES_AESMC
),
2051 tune_params::SCHED_AUTOPREF_OFF
2054 const struct tune_params arm_cortex_a57_tune
=
2056 &cortexa57_extra_costs
,
2057 NULL
, /* Sched adj cost. */
2058 arm_default_branch_cost
,
2059 &arm_default_vec_cost
,
2060 1, /* Constant limit. */
2061 2, /* Max cond insns. */
2062 8, /* Memset max inline. */
2063 3, /* Issue rate. */
2064 ARM_PREFETCH_NOT_BENEFICIAL
,
2065 tune_params::PREF_CONST_POOL_FALSE
,
2066 tune_params::PREF_LDRD_TRUE
,
2067 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
2068 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
2069 tune_params::DISPARAGE_FLAGS_ALL
,
2070 tune_params::PREF_NEON_64_FALSE
,
2071 tune_params::PREF_NEON_STRINGOPS_TRUE
,
2072 FUSE_OPS (tune_params::FUSE_MOVW_MOVT
| tune_params::FUSE_AES_AESMC
),
2073 tune_params::SCHED_AUTOPREF_FULL
2076 const struct tune_params arm_exynosm1_tune
=
2078 &exynosm1_extra_costs
,
2079 NULL
, /* Sched adj cost. */
2080 arm_default_branch_cost
,
2081 &arm_default_vec_cost
,
2082 1, /* Constant limit. */
2083 2, /* Max cond insns. */
2084 8, /* Memset max inline. */
2085 3, /* Issue rate. */
2086 ARM_PREFETCH_NOT_BENEFICIAL
,
2087 tune_params::PREF_CONST_POOL_FALSE
,
2088 tune_params::PREF_LDRD_TRUE
,
2089 tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE
, /* Thumb. */
2090 tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE
, /* ARM. */
2091 tune_params::DISPARAGE_FLAGS_ALL
,
2092 tune_params::PREF_NEON_64_FALSE
,
2093 tune_params::PREF_NEON_STRINGOPS_TRUE
,
2094 tune_params::FUSE_NOTHING
,
2095 tune_params::SCHED_AUTOPREF_OFF
2098 const struct tune_params arm_xgene1_tune
=
2100 &xgene1_extra_costs
,
2101 NULL
, /* Sched adj cost. */
2102 arm_default_branch_cost
,
2103 &arm_default_vec_cost
,
2104 1, /* Constant limit. */
2105 2, /* Max cond insns. */
2106 32, /* Memset max inline. */
2107 4, /* Issue rate. */
2108 ARM_PREFETCH_NOT_BENEFICIAL
,
2109 tune_params::PREF_CONST_POOL_FALSE
,
2110 tune_params::PREF_LDRD_TRUE
,
2111 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
2112 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
2113 tune_params::DISPARAGE_FLAGS_ALL
,
2114 tune_params::PREF_NEON_64_FALSE
,
2115 tune_params::PREF_NEON_STRINGOPS_FALSE
,
2116 tune_params::FUSE_NOTHING
,
2117 tune_params::SCHED_AUTOPREF_OFF
2120 /* Branches can be dual-issued on Cortex-A5, so conditional execution is
2121 less appealing. Set max_insns_skipped to a low value. */
2123 const struct tune_params arm_cortex_a5_tune
=
2125 &cortexa5_extra_costs
,
2126 NULL
, /* Sched adj cost. */
2127 arm_cortex_a5_branch_cost
,
2128 &arm_default_vec_cost
,
2129 1, /* Constant limit. */
2130 1, /* Max cond insns. */
2131 8, /* Memset max inline. */
2132 2, /* Issue rate. */
2133 ARM_PREFETCH_NOT_BENEFICIAL
,
2134 tune_params::PREF_CONST_POOL_FALSE
,
2135 tune_params::PREF_LDRD_FALSE
,
2136 tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE
, /* Thumb. */
2137 tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE
, /* ARM. */
2138 tune_params::DISPARAGE_FLAGS_NEITHER
,
2139 tune_params::PREF_NEON_64_FALSE
,
2140 tune_params::PREF_NEON_STRINGOPS_TRUE
,
2141 tune_params::FUSE_NOTHING
,
2142 tune_params::SCHED_AUTOPREF_OFF
2145 const struct tune_params arm_cortex_a9_tune
=
2147 &cortexa9_extra_costs
,
2148 cortex_a9_sched_adjust_cost
,
2149 arm_default_branch_cost
,
2150 &arm_default_vec_cost
,
2151 1, /* Constant limit. */
2152 5, /* Max cond insns. */
2153 8, /* Memset max inline. */
2154 2, /* Issue rate. */
2155 ARM_PREFETCH_BENEFICIAL(4,32,32),
2156 tune_params::PREF_CONST_POOL_FALSE
,
2157 tune_params::PREF_LDRD_FALSE
,
2158 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
2159 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
2160 tune_params::DISPARAGE_FLAGS_NEITHER
,
2161 tune_params::PREF_NEON_64_FALSE
,
2162 tune_params::PREF_NEON_STRINGOPS_FALSE
,
2163 tune_params::FUSE_NOTHING
,
2164 tune_params::SCHED_AUTOPREF_OFF
2167 const struct tune_params arm_cortex_a12_tune
=
2169 &cortexa12_extra_costs
,
2170 NULL
, /* Sched adj cost. */
2171 arm_default_branch_cost
,
2172 &arm_default_vec_cost
, /* Vectorizer costs. */
2173 1, /* Constant limit. */
2174 2, /* Max cond insns. */
2175 8, /* Memset max inline. */
2176 2, /* Issue rate. */
2177 ARM_PREFETCH_NOT_BENEFICIAL
,
2178 tune_params::PREF_CONST_POOL_FALSE
,
2179 tune_params::PREF_LDRD_TRUE
,
2180 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
2181 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
2182 tune_params::DISPARAGE_FLAGS_ALL
,
2183 tune_params::PREF_NEON_64_FALSE
,
2184 tune_params::PREF_NEON_STRINGOPS_TRUE
,
2185 FUSE_OPS (tune_params::FUSE_MOVW_MOVT
),
2186 tune_params::SCHED_AUTOPREF_OFF
2189 const struct tune_params arm_cortex_a73_tune
=
2191 &cortexa57_extra_costs
,
2192 NULL
, /* Sched adj cost. */
2193 arm_default_branch_cost
,
2194 &arm_default_vec_cost
, /* Vectorizer costs. */
2195 1, /* Constant limit. */
2196 2, /* Max cond insns. */
2197 8, /* Memset max inline. */
2198 2, /* Issue rate. */
2199 ARM_PREFETCH_NOT_BENEFICIAL
,
2200 tune_params::PREF_CONST_POOL_FALSE
,
2201 tune_params::PREF_LDRD_TRUE
,
2202 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
2203 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
2204 tune_params::DISPARAGE_FLAGS_ALL
,
2205 tune_params::PREF_NEON_64_FALSE
,
2206 tune_params::PREF_NEON_STRINGOPS_TRUE
,
2207 FUSE_OPS (tune_params::FUSE_AES_AESMC
| tune_params::FUSE_MOVW_MOVT
),
2208 tune_params::SCHED_AUTOPREF_FULL
2211 /* armv7m tuning. On Cortex-M4 cores for example, MOVW/MOVT take a single
2212 cycle to execute each. An LDR from the constant pool also takes two cycles
2213 to execute, but mildly increases pipelining opportunity (consecutive
2214 loads/stores can be pipelined together, saving one cycle), and may also
2215 improve icache utilisation. Hence we prefer the constant pool for such
2218 const struct tune_params arm_v7m_tune
=
2221 NULL
, /* Sched adj cost. */
2222 arm_cortex_m_branch_cost
,
2223 &arm_default_vec_cost
,
2224 1, /* Constant limit. */
2225 2, /* Max cond insns. */
2226 8, /* Memset max inline. */
2227 1, /* Issue rate. */
2228 ARM_PREFETCH_NOT_BENEFICIAL
,
2229 tune_params::PREF_CONST_POOL_TRUE
,
2230 tune_params::PREF_LDRD_FALSE
,
2231 tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE
, /* Thumb. */
2232 tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE
, /* ARM. */
2233 tune_params::DISPARAGE_FLAGS_NEITHER
,
2234 tune_params::PREF_NEON_64_FALSE
,
2235 tune_params::PREF_NEON_STRINGOPS_FALSE
,
2236 tune_params::FUSE_NOTHING
,
2237 tune_params::SCHED_AUTOPREF_OFF
2240 /* Cortex-M7 tuning. */
2242 const struct tune_params arm_cortex_m7_tune
=
2245 NULL
, /* Sched adj cost. */
2246 arm_cortex_m7_branch_cost
,
2247 &arm_default_vec_cost
,
2248 0, /* Constant limit. */
2249 1, /* Max cond insns. */
2250 8, /* Memset max inline. */
2251 2, /* Issue rate. */
2252 ARM_PREFETCH_NOT_BENEFICIAL
,
2253 tune_params::PREF_CONST_POOL_TRUE
,
2254 tune_params::PREF_LDRD_FALSE
,
2255 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
2256 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
2257 tune_params::DISPARAGE_FLAGS_NEITHER
,
2258 tune_params::PREF_NEON_64_FALSE
,
2259 tune_params::PREF_NEON_STRINGOPS_FALSE
,
2260 tune_params::FUSE_NOTHING
,
2261 tune_params::SCHED_AUTOPREF_OFF
2264 /* The arm_v6m_tune is duplicated from arm_cortex_tune, rather than
2265 arm_v6t2_tune. It is used for cortex-m0, cortex-m1, cortex-m0plus and
2267 const struct tune_params arm_v6m_tune
=
2269 &generic_extra_costs
, /* Insn extra costs. */
2270 NULL
, /* Sched adj cost. */
2271 arm_default_branch_cost
,
2272 &arm_default_vec_cost
, /* Vectorizer costs. */
2273 1, /* Constant limit. */
2274 5, /* Max cond insns. */
2275 8, /* Memset max inline. */
2276 1, /* Issue rate. */
2277 ARM_PREFETCH_NOT_BENEFICIAL
,
2278 tune_params::PREF_CONST_POOL_FALSE
,
2279 tune_params::PREF_LDRD_FALSE
,
2280 tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE
, /* Thumb. */
2281 tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE
, /* ARM. */
2282 tune_params::DISPARAGE_FLAGS_NEITHER
,
2283 tune_params::PREF_NEON_64_FALSE
,
2284 tune_params::PREF_NEON_STRINGOPS_FALSE
,
2285 tune_params::FUSE_NOTHING
,
2286 tune_params::SCHED_AUTOPREF_OFF
2289 const struct tune_params arm_fa726te_tune
=
2291 &generic_extra_costs
, /* Insn extra costs. */
2292 fa726te_sched_adjust_cost
,
2293 arm_default_branch_cost
,
2294 &arm_default_vec_cost
,
2295 1, /* Constant limit. */
2296 5, /* Max cond insns. */
2297 8, /* Memset max inline. */
2298 2, /* Issue rate. */
2299 ARM_PREFETCH_NOT_BENEFICIAL
,
2300 tune_params::PREF_CONST_POOL_TRUE
,
2301 tune_params::PREF_LDRD_FALSE
,
2302 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* Thumb. */
2303 tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE
, /* ARM. */
2304 tune_params::DISPARAGE_FLAGS_NEITHER
,
2305 tune_params::PREF_NEON_64_FALSE
,
2306 tune_params::PREF_NEON_STRINGOPS_FALSE
,
2307 tune_params::FUSE_NOTHING
,
2308 tune_params::SCHED_AUTOPREF_OFF
2311 /* Auto-generated CPU, FPU and architecture tables. */
2312 #include "arm-cpu-data.h"
2314 /* The name of the preprocessor macro to define for this architecture. PROFILE
2315 is replaced by the architecture name (eg. 8A) in arm_option_override () and
2316 is thus chosen to be big enough to hold the longest architecture name. */
2318 char arm_arch_name
[] = "__ARM_ARCH_PROFILE__";
2320 /* Supported TLS relocations. */
2328 TLS_DESCSEQ
/* GNU scheme */
2331 /* The maximum number of insns to be used when loading a constant. */
2333 arm_constant_limit (bool size_p
)
2335 return size_p
? 1 : current_tune
->constant_limit
;
2338 /* Emit an insn that's a simple single-set. Both the operands must be known
2340 inline static rtx_insn
*
2341 emit_set_insn (rtx x
, rtx y
)
2343 return emit_insn (gen_rtx_SET (x
, y
));
2346 /* Return the number of bits set in VALUE. */
2348 bit_count (unsigned long value
)
2350 unsigned long count
= 0;
2355 value
&= value
- 1; /* Clear the least-significant set bit. */
2361 /* Return the number of bits set in BMAP. */
2363 bitmap_popcount (const sbitmap bmap
)
2365 unsigned int count
= 0;
2367 sbitmap_iterator sbi
;
2369 EXECUTE_IF_SET_IN_BITMAP (bmap
, 0, n
, sbi
)
2378 } arm_fixed_mode_set
;
2380 /* A small helper for setting fixed-point library libfuncs. */
2383 arm_set_fixed_optab_libfunc (optab optable
, machine_mode mode
,
2384 const char *funcname
, const char *modename
,
2389 if (num_suffix
== 0)
2390 sprintf (buffer
, "__gnu_%s%s", funcname
, modename
);
2392 sprintf (buffer
, "__gnu_%s%s%d", funcname
, modename
, num_suffix
);
2394 set_optab_libfunc (optable
, mode
, buffer
);
2398 arm_set_fixed_conv_libfunc (convert_optab optable
, machine_mode to
,
2399 machine_mode from
, const char *funcname
,
2400 const char *toname
, const char *fromname
)
2403 const char *maybe_suffix_2
= "";
2405 /* Follow the logic for selecting a "2" suffix in fixed-bit.h. */
2406 if (ALL_FIXED_POINT_MODE_P (from
) && ALL_FIXED_POINT_MODE_P (to
)
2407 && UNSIGNED_FIXED_POINT_MODE_P (from
) == UNSIGNED_FIXED_POINT_MODE_P (to
)
2408 && ALL_FRACT_MODE_P (from
) == ALL_FRACT_MODE_P (to
))
2409 maybe_suffix_2
= "2";
2411 sprintf (buffer
, "__gnu_%s%s%s%s", funcname
, fromname
, toname
,
2414 set_conv_libfunc (optable
, to
, from
, buffer
);
2417 /* Set up library functions unique to ARM. */
2420 arm_init_libfuncs (void)
2422 /* For Linux, we have access to kernel support for atomic operations. */
2423 if (arm_abi
== ARM_ABI_AAPCS_LINUX
)
2424 init_sync_libfuncs (MAX_SYNC_LIBFUNC_SIZE
);
2426 /* There are no special library functions unless we are using the
2431 /* The functions below are described in Section 4 of the "Run-Time
2432 ABI for the ARM architecture", Version 1.0. */
2434 /* Double-precision floating-point arithmetic. Table 2. */
2435 set_optab_libfunc (add_optab
, DFmode
, "__aeabi_dadd");
2436 set_optab_libfunc (sdiv_optab
, DFmode
, "__aeabi_ddiv");
2437 set_optab_libfunc (smul_optab
, DFmode
, "__aeabi_dmul");
2438 set_optab_libfunc (neg_optab
, DFmode
, "__aeabi_dneg");
2439 set_optab_libfunc (sub_optab
, DFmode
, "__aeabi_dsub");
2441 /* Double-precision comparisons. Table 3. */
2442 set_optab_libfunc (eq_optab
, DFmode
, "__aeabi_dcmpeq");
2443 set_optab_libfunc (ne_optab
, DFmode
, NULL
);
2444 set_optab_libfunc (lt_optab
, DFmode
, "__aeabi_dcmplt");
2445 set_optab_libfunc (le_optab
, DFmode
, "__aeabi_dcmple");
2446 set_optab_libfunc (ge_optab
, DFmode
, "__aeabi_dcmpge");
2447 set_optab_libfunc (gt_optab
, DFmode
, "__aeabi_dcmpgt");
2448 set_optab_libfunc (unord_optab
, DFmode
, "__aeabi_dcmpun");
2450 /* Single-precision floating-point arithmetic. Table 4. */
2451 set_optab_libfunc (add_optab
, SFmode
, "__aeabi_fadd");
2452 set_optab_libfunc (sdiv_optab
, SFmode
, "__aeabi_fdiv");
2453 set_optab_libfunc (smul_optab
, SFmode
, "__aeabi_fmul");
2454 set_optab_libfunc (neg_optab
, SFmode
, "__aeabi_fneg");
2455 set_optab_libfunc (sub_optab
, SFmode
, "__aeabi_fsub");
2457 /* Single-precision comparisons. Table 5. */
2458 set_optab_libfunc (eq_optab
, SFmode
, "__aeabi_fcmpeq");
2459 set_optab_libfunc (ne_optab
, SFmode
, NULL
);
2460 set_optab_libfunc (lt_optab
, SFmode
, "__aeabi_fcmplt");
2461 set_optab_libfunc (le_optab
, SFmode
, "__aeabi_fcmple");
2462 set_optab_libfunc (ge_optab
, SFmode
, "__aeabi_fcmpge");
2463 set_optab_libfunc (gt_optab
, SFmode
, "__aeabi_fcmpgt");
2464 set_optab_libfunc (unord_optab
, SFmode
, "__aeabi_fcmpun");
2466 /* Floating-point to integer conversions. Table 6. */
2467 set_conv_libfunc (sfix_optab
, SImode
, DFmode
, "__aeabi_d2iz");
2468 set_conv_libfunc (ufix_optab
, SImode
, DFmode
, "__aeabi_d2uiz");
2469 set_conv_libfunc (sfix_optab
, DImode
, DFmode
, "__aeabi_d2lz");
2470 set_conv_libfunc (ufix_optab
, DImode
, DFmode
, "__aeabi_d2ulz");
2471 set_conv_libfunc (sfix_optab
, SImode
, SFmode
, "__aeabi_f2iz");
2472 set_conv_libfunc (ufix_optab
, SImode
, SFmode
, "__aeabi_f2uiz");
2473 set_conv_libfunc (sfix_optab
, DImode
, SFmode
, "__aeabi_f2lz");
2474 set_conv_libfunc (ufix_optab
, DImode
, SFmode
, "__aeabi_f2ulz");
2476 /* Conversions between floating types. Table 7. */
2477 set_conv_libfunc (trunc_optab
, SFmode
, DFmode
, "__aeabi_d2f");
2478 set_conv_libfunc (sext_optab
, DFmode
, SFmode
, "__aeabi_f2d");
2480 /* Integer to floating-point conversions. Table 8. */
2481 set_conv_libfunc (sfloat_optab
, DFmode
, SImode
, "__aeabi_i2d");
2482 set_conv_libfunc (ufloat_optab
, DFmode
, SImode
, "__aeabi_ui2d");
2483 set_conv_libfunc (sfloat_optab
, DFmode
, DImode
, "__aeabi_l2d");
2484 set_conv_libfunc (ufloat_optab
, DFmode
, DImode
, "__aeabi_ul2d");
2485 set_conv_libfunc (sfloat_optab
, SFmode
, SImode
, "__aeabi_i2f");
2486 set_conv_libfunc (ufloat_optab
, SFmode
, SImode
, "__aeabi_ui2f");
2487 set_conv_libfunc (sfloat_optab
, SFmode
, DImode
, "__aeabi_l2f");
2488 set_conv_libfunc (ufloat_optab
, SFmode
, DImode
, "__aeabi_ul2f");
2490 /* Long long. Table 9. */
2491 set_optab_libfunc (smul_optab
, DImode
, "__aeabi_lmul");
2492 set_optab_libfunc (sdivmod_optab
, DImode
, "__aeabi_ldivmod");
2493 set_optab_libfunc (udivmod_optab
, DImode
, "__aeabi_uldivmod");
2494 set_optab_libfunc (ashl_optab
, DImode
, "__aeabi_llsl");
2495 set_optab_libfunc (lshr_optab
, DImode
, "__aeabi_llsr");
2496 set_optab_libfunc (ashr_optab
, DImode
, "__aeabi_lasr");
2497 set_optab_libfunc (cmp_optab
, DImode
, "__aeabi_lcmp");
2498 set_optab_libfunc (ucmp_optab
, DImode
, "__aeabi_ulcmp");
2500 /* Integer (32/32->32) division. \S 4.3.1. */
2501 set_optab_libfunc (sdivmod_optab
, SImode
, "__aeabi_idivmod");
2502 set_optab_libfunc (udivmod_optab
, SImode
, "__aeabi_uidivmod");
2504 /* The divmod functions are designed so that they can be used for
2505 plain division, even though they return both the quotient and the
2506 remainder. The quotient is returned in the usual location (i.e.,
2507 r0 for SImode, {r0, r1} for DImode), just as would be expected
2508 for an ordinary division routine. Because the AAPCS calling
2509 conventions specify that all of { r0, r1, r2, r3 } are
2510 callee-saved registers, there is no need to tell the compiler
2511 explicitly that those registers are clobbered by these
2513 set_optab_libfunc (sdiv_optab
, DImode
, "__aeabi_ldivmod");
2514 set_optab_libfunc (udiv_optab
, DImode
, "__aeabi_uldivmod");
2516 /* For SImode division the ABI provides div-without-mod routines,
2517 which are faster. */
2518 set_optab_libfunc (sdiv_optab
, SImode
, "__aeabi_idiv");
2519 set_optab_libfunc (udiv_optab
, SImode
, "__aeabi_uidiv");
2521 /* We don't have mod libcalls. Fortunately gcc knows how to use the
2522 divmod libcalls instead. */
2523 set_optab_libfunc (smod_optab
, DImode
, NULL
);
2524 set_optab_libfunc (umod_optab
, DImode
, NULL
);
2525 set_optab_libfunc (smod_optab
, SImode
, NULL
);
2526 set_optab_libfunc (umod_optab
, SImode
, NULL
);
2528 /* Half-precision float operations. The compiler handles all operations
2529 with NULL libfuncs by converting the SFmode. */
2530 switch (arm_fp16_format
)
2532 case ARM_FP16_FORMAT_IEEE
:
2533 case ARM_FP16_FORMAT_ALTERNATIVE
:
2536 set_conv_libfunc (trunc_optab
, HFmode
, SFmode
,
2537 (arm_fp16_format
== ARM_FP16_FORMAT_IEEE
2539 : "__gnu_f2h_alternative"));
2540 set_conv_libfunc (sext_optab
, SFmode
, HFmode
,
2541 (arm_fp16_format
== ARM_FP16_FORMAT_IEEE
2543 : "__gnu_h2f_alternative"));
2545 set_conv_libfunc (trunc_optab
, HFmode
, DFmode
,
2546 (arm_fp16_format
== ARM_FP16_FORMAT_IEEE
2548 : "__gnu_d2h_alternative"));
2551 set_optab_libfunc (add_optab
, HFmode
, NULL
);
2552 set_optab_libfunc (sdiv_optab
, HFmode
, NULL
);
2553 set_optab_libfunc (smul_optab
, HFmode
, NULL
);
2554 set_optab_libfunc (neg_optab
, HFmode
, NULL
);
2555 set_optab_libfunc (sub_optab
, HFmode
, NULL
);
2558 set_optab_libfunc (eq_optab
, HFmode
, NULL
);
2559 set_optab_libfunc (ne_optab
, HFmode
, NULL
);
2560 set_optab_libfunc (lt_optab
, HFmode
, NULL
);
2561 set_optab_libfunc (le_optab
, HFmode
, NULL
);
2562 set_optab_libfunc (ge_optab
, HFmode
, NULL
);
2563 set_optab_libfunc (gt_optab
, HFmode
, NULL
);
2564 set_optab_libfunc (unord_optab
, HFmode
, NULL
);
2571 /* Use names prefixed with __gnu_ for fixed-point helper functions. */
2573 const arm_fixed_mode_set fixed_arith_modes
[] =
2576 { E_UQQmode
, "uqq" },
2578 { E_UHQmode
, "uhq" },
2580 { E_USQmode
, "usq" },
2582 { E_UDQmode
, "udq" },
2584 { E_UTQmode
, "utq" },
2586 { E_UHAmode
, "uha" },
2588 { E_USAmode
, "usa" },
2590 { E_UDAmode
, "uda" },
2592 { E_UTAmode
, "uta" }
2594 const arm_fixed_mode_set fixed_conv_modes
[] =
2597 { E_UQQmode
, "uqq" },
2599 { E_UHQmode
, "uhq" },
2601 { E_USQmode
, "usq" },
2603 { E_UDQmode
, "udq" },
2605 { E_UTQmode
, "utq" },
2607 { E_UHAmode
, "uha" },
2609 { E_USAmode
, "usa" },
2611 { E_UDAmode
, "uda" },
2613 { E_UTAmode
, "uta" },
2624 for (i
= 0; i
< ARRAY_SIZE (fixed_arith_modes
); i
++)
2626 arm_set_fixed_optab_libfunc (add_optab
, fixed_arith_modes
[i
].mode
,
2627 "add", fixed_arith_modes
[i
].name
, 3);
2628 arm_set_fixed_optab_libfunc (ssadd_optab
, fixed_arith_modes
[i
].mode
,
2629 "ssadd", fixed_arith_modes
[i
].name
, 3);
2630 arm_set_fixed_optab_libfunc (usadd_optab
, fixed_arith_modes
[i
].mode
,
2631 "usadd", fixed_arith_modes
[i
].name
, 3);
2632 arm_set_fixed_optab_libfunc (sub_optab
, fixed_arith_modes
[i
].mode
,
2633 "sub", fixed_arith_modes
[i
].name
, 3);
2634 arm_set_fixed_optab_libfunc (sssub_optab
, fixed_arith_modes
[i
].mode
,
2635 "sssub", fixed_arith_modes
[i
].name
, 3);
2636 arm_set_fixed_optab_libfunc (ussub_optab
, fixed_arith_modes
[i
].mode
,
2637 "ussub", fixed_arith_modes
[i
].name
, 3);
2638 arm_set_fixed_optab_libfunc (smul_optab
, fixed_arith_modes
[i
].mode
,
2639 "mul", fixed_arith_modes
[i
].name
, 3);
2640 arm_set_fixed_optab_libfunc (ssmul_optab
, fixed_arith_modes
[i
].mode
,
2641 "ssmul", fixed_arith_modes
[i
].name
, 3);
2642 arm_set_fixed_optab_libfunc (usmul_optab
, fixed_arith_modes
[i
].mode
,
2643 "usmul", fixed_arith_modes
[i
].name
, 3);
2644 arm_set_fixed_optab_libfunc (sdiv_optab
, fixed_arith_modes
[i
].mode
,
2645 "div", fixed_arith_modes
[i
].name
, 3);
2646 arm_set_fixed_optab_libfunc (udiv_optab
, fixed_arith_modes
[i
].mode
,
2647 "udiv", fixed_arith_modes
[i
].name
, 3);
2648 arm_set_fixed_optab_libfunc (ssdiv_optab
, fixed_arith_modes
[i
].mode
,
2649 "ssdiv", fixed_arith_modes
[i
].name
, 3);
2650 arm_set_fixed_optab_libfunc (usdiv_optab
, fixed_arith_modes
[i
].mode
,
2651 "usdiv", fixed_arith_modes
[i
].name
, 3);
2652 arm_set_fixed_optab_libfunc (neg_optab
, fixed_arith_modes
[i
].mode
,
2653 "neg", fixed_arith_modes
[i
].name
, 2);
2654 arm_set_fixed_optab_libfunc (ssneg_optab
, fixed_arith_modes
[i
].mode
,
2655 "ssneg", fixed_arith_modes
[i
].name
, 2);
2656 arm_set_fixed_optab_libfunc (usneg_optab
, fixed_arith_modes
[i
].mode
,
2657 "usneg", fixed_arith_modes
[i
].name
, 2);
2658 arm_set_fixed_optab_libfunc (ashl_optab
, fixed_arith_modes
[i
].mode
,
2659 "ashl", fixed_arith_modes
[i
].name
, 3);
2660 arm_set_fixed_optab_libfunc (ashr_optab
, fixed_arith_modes
[i
].mode
,
2661 "ashr", fixed_arith_modes
[i
].name
, 3);
2662 arm_set_fixed_optab_libfunc (lshr_optab
, fixed_arith_modes
[i
].mode
,
2663 "lshr", fixed_arith_modes
[i
].name
, 3);
2664 arm_set_fixed_optab_libfunc (ssashl_optab
, fixed_arith_modes
[i
].mode
,
2665 "ssashl", fixed_arith_modes
[i
].name
, 3);
2666 arm_set_fixed_optab_libfunc (usashl_optab
, fixed_arith_modes
[i
].mode
,
2667 "usashl", fixed_arith_modes
[i
].name
, 3);
2668 arm_set_fixed_optab_libfunc (cmp_optab
, fixed_arith_modes
[i
].mode
,
2669 "cmp", fixed_arith_modes
[i
].name
, 2);
2672 for (i
= 0; i
< ARRAY_SIZE (fixed_conv_modes
); i
++)
2673 for (j
= 0; j
< ARRAY_SIZE (fixed_conv_modes
); j
++)
2676 || (!ALL_FIXED_POINT_MODE_P (fixed_conv_modes
[i
].mode
)
2677 && !ALL_FIXED_POINT_MODE_P (fixed_conv_modes
[j
].mode
)))
2680 arm_set_fixed_conv_libfunc (fract_optab
, fixed_conv_modes
[i
].mode
,
2681 fixed_conv_modes
[j
].mode
, "fract",
2682 fixed_conv_modes
[i
].name
,
2683 fixed_conv_modes
[j
].name
);
2684 arm_set_fixed_conv_libfunc (satfract_optab
,
2685 fixed_conv_modes
[i
].mode
,
2686 fixed_conv_modes
[j
].mode
, "satfract",
2687 fixed_conv_modes
[i
].name
,
2688 fixed_conv_modes
[j
].name
);
2689 arm_set_fixed_conv_libfunc (fractuns_optab
,
2690 fixed_conv_modes
[i
].mode
,
2691 fixed_conv_modes
[j
].mode
, "fractuns",
2692 fixed_conv_modes
[i
].name
,
2693 fixed_conv_modes
[j
].name
);
2694 arm_set_fixed_conv_libfunc (satfractuns_optab
,
2695 fixed_conv_modes
[i
].mode
,
2696 fixed_conv_modes
[j
].mode
, "satfractuns",
2697 fixed_conv_modes
[i
].name
,
2698 fixed_conv_modes
[j
].name
);
2702 if (TARGET_AAPCS_BASED
)
2703 synchronize_libfunc
= init_one_libfunc ("__sync_synchronize");
2706 /* On AAPCS systems, this is the "struct __va_list". */
2707 static GTY(()) tree va_list_type
;
2709 /* Return the type to use as __builtin_va_list. */
2711 arm_build_builtin_va_list (void)
2716 if (!TARGET_AAPCS_BASED
)
2717 return std_build_builtin_va_list ();
2719 /* AAPCS \S 7.1.4 requires that va_list be a typedef for a type
2727 The C Library ABI further reinforces this definition in \S
2730 We must follow this definition exactly. The structure tag
2731 name is visible in C++ mangled names, and thus forms a part
2732 of the ABI. The field name may be used by people who
2733 #include <stdarg.h>. */
2734 /* Create the type. */
2735 va_list_type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
2736 /* Give it the required name. */
2737 va_list_name
= build_decl (BUILTINS_LOCATION
,
2739 get_identifier ("__va_list"),
2741 DECL_ARTIFICIAL (va_list_name
) = 1;
2742 TYPE_NAME (va_list_type
) = va_list_name
;
2743 TYPE_STUB_DECL (va_list_type
) = va_list_name
;
2744 /* Create the __ap field. */
2745 ap_field
= build_decl (BUILTINS_LOCATION
,
2747 get_identifier ("__ap"),
2749 DECL_ARTIFICIAL (ap_field
) = 1;
2750 DECL_FIELD_CONTEXT (ap_field
) = va_list_type
;
2751 TYPE_FIELDS (va_list_type
) = ap_field
;
2752 /* Compute its layout. */
2753 layout_type (va_list_type
);
2755 return va_list_type
;
2758 /* Return an expression of type "void *" pointing to the next
2759 available argument in a variable-argument list. VALIST is the
2760 user-level va_list object, of type __builtin_va_list. */
2762 arm_extract_valist_ptr (tree valist
)
2764 if (TREE_TYPE (valist
) == error_mark_node
)
2765 return error_mark_node
;
2767 /* On an AAPCS target, the pointer is stored within "struct
2769 if (TARGET_AAPCS_BASED
)
2771 tree ap_field
= TYPE_FIELDS (TREE_TYPE (valist
));
2772 valist
= build3 (COMPONENT_REF
, TREE_TYPE (ap_field
),
2773 valist
, ap_field
, NULL_TREE
);
2779 /* Implement TARGET_EXPAND_BUILTIN_VA_START. */
2781 arm_expand_builtin_va_start (tree valist
, rtx nextarg
)
2783 valist
= arm_extract_valist_ptr (valist
);
2784 std_expand_builtin_va_start (valist
, nextarg
);
2787 /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */
2789 arm_gimplify_va_arg_expr (tree valist
, tree type
, gimple_seq
*pre_p
,
2792 valist
= arm_extract_valist_ptr (valist
);
2793 return std_gimplify_va_arg_expr (valist
, type
, pre_p
, post_p
);
2796 /* Check any incompatible options that the user has specified. */
2798 arm_option_check_internal (struct gcc_options
*opts
)
2800 int flags
= opts
->x_target_flags
;
2802 /* iWMMXt and NEON are incompatible. */
2804 && bitmap_bit_p (arm_active_target
.isa
, isa_bit_neon
))
2805 error ("iWMMXt and NEON are incompatible");
2807 /* Make sure that the processor choice does not conflict with any of the
2808 other command line choices. */
2809 if (TARGET_ARM_P (flags
)
2810 && !bitmap_bit_p (arm_active_target
.isa
, isa_bit_notm
))
2811 error ("target CPU does not support ARM mode");
2813 /* TARGET_BACKTRACE cannot be used here as crtl->is_leaf is not set yet. */
2814 if ((TARGET_TPCS_FRAME
|| TARGET_TPCS_LEAF_FRAME
) && TARGET_ARM_P (flags
))
2815 warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb");
2817 if (TARGET_ARM_P (flags
) && TARGET_CALLEE_INTERWORKING
)
2818 warning (0, "enabling callee interworking support is only meaningful when compiling for the Thumb");
2820 /* If this target is normally configured to use APCS frames, warn if they
2821 are turned off and debugging is turned on. */
2822 if (TARGET_ARM_P (flags
)
2823 && write_symbols
!= NO_DEBUG
2824 && !TARGET_APCS_FRAME
2825 && (TARGET_DEFAULT
& MASK_APCS_FRAME
))
2826 warning (0, "-g with -mno-apcs-frame may not give sensible debugging");
2828 /* iWMMXt unsupported under Thumb mode. */
2829 if (TARGET_THUMB_P (flags
) && TARGET_IWMMXT
)
2830 error ("iWMMXt unsupported under Thumb mode");
2832 if (TARGET_HARD_TP
&& TARGET_THUMB1_P (flags
))
2833 error ("can not use -mtp=cp15 with 16-bit Thumb");
2835 if (TARGET_THUMB_P (flags
) && TARGET_VXWORKS_RTP
&& flag_pic
)
2837 error ("RTP PIC is incompatible with Thumb");
2841 /* We only support -mpure-code and -mslow-flash-data on M-profile targets
2843 if ((target_pure_code
|| target_slow_flash_data
)
2844 && (!TARGET_HAVE_MOVT
|| arm_arch_notm
|| flag_pic
|| TARGET_NEON
))
2846 const char *flag
= (target_pure_code
? "-mpure-code" :
2847 "-mslow-flash-data");
2848 error ("%s only supports non-pic code on M-profile targets with the "
2849 "MOVT instruction", flag
);
2854 /* Recompute the global settings depending on target attribute options. */
2857 arm_option_params_internal (void)
2859 /* If we are not using the default (ARM mode) section anchor offset
2860 ranges, then set the correct ranges now. */
2863 /* Thumb-1 LDR instructions cannot have negative offsets.
2864 Permissible positive offset ranges are 5-bit (for byte loads),
2865 6-bit (for halfword loads), or 7-bit (for word loads).
2866 Empirical results suggest a 7-bit anchor range gives the best
2867 overall code size. */
2868 targetm
.min_anchor_offset
= 0;
2869 targetm
.max_anchor_offset
= 127;
2871 else if (TARGET_THUMB2
)
2873 /* The minimum is set such that the total size of the block
2874 for a particular anchor is 248 + 1 + 4095 bytes, which is
2875 divisible by eight, ensuring natural spacing of anchors. */
2876 targetm
.min_anchor_offset
= -248;
2877 targetm
.max_anchor_offset
= 4095;
2881 targetm
.min_anchor_offset
= TARGET_MIN_ANCHOR_OFFSET
;
2882 targetm
.max_anchor_offset
= TARGET_MAX_ANCHOR_OFFSET
;
2885 /* Increase the number of conditional instructions with -Os. */
2886 max_insns_skipped
= optimize_size
? 4 : current_tune
->max_insns_skipped
;
2888 /* For THUMB2, we limit the conditional sequence to one IT block. */
2890 max_insns_skipped
= MIN (max_insns_skipped
, MAX_INSN_PER_IT_BLOCK
);
2893 /* True if -mflip-thumb should next add an attribute for the default
2894 mode, false if it should next add an attribute for the opposite mode. */
2895 static GTY(()) bool thumb_flipper
;
2897 /* Options after initial target override. */
2898 static GTY(()) tree init_optimize
;
2901 arm_override_options_after_change_1 (struct gcc_options
*opts
)
2903 if (opts
->x_align_functions
<= 0)
2904 opts
->x_align_functions
= TARGET_THUMB_P (opts
->x_target_flags
)
2905 && opts
->x_optimize_size
? 2 : 4;
2908 /* Implement targetm.override_options_after_change. */
2911 arm_override_options_after_change (void)
2913 arm_configure_build_target (&arm_active_target
,
2914 TREE_TARGET_OPTION (target_option_default_node
),
2915 &global_options_set
, false);
2917 arm_override_options_after_change_1 (&global_options
);
2920 /* Implement TARGET_OPTION_SAVE. */
2922 arm_option_save (struct cl_target_option
*ptr
, struct gcc_options
*opts
)
2924 ptr
->x_arm_arch_string
= opts
->x_arm_arch_string
;
2925 ptr
->x_arm_cpu_string
= opts
->x_arm_cpu_string
;
2926 ptr
->x_arm_tune_string
= opts
->x_arm_tune_string
;
2929 /* Implement TARGET_OPTION_RESTORE. */
2931 arm_option_restore (struct gcc_options
*opts
, struct cl_target_option
*ptr
)
2933 opts
->x_arm_arch_string
= ptr
->x_arm_arch_string
;
2934 opts
->x_arm_cpu_string
= ptr
->x_arm_cpu_string
;
2935 opts
->x_arm_tune_string
= ptr
->x_arm_tune_string
;
2936 arm_configure_build_target (&arm_active_target
, ptr
, &global_options_set
,
2940 /* Reset options between modes that the user has specified. */
2942 arm_option_override_internal (struct gcc_options
*opts
,
2943 struct gcc_options
*opts_set
)
2945 arm_override_options_after_change_1 (opts
);
2947 if (TARGET_INTERWORK
&& !bitmap_bit_p (arm_active_target
.isa
, isa_bit_thumb
))
2949 /* The default is to enable interworking, so this warning message would
2950 be confusing to users who have just compiled with, eg, -march=armv3. */
2951 /* warning (0, "ignoring -minterwork because target CPU does not support THUMB"); */
2952 opts
->x_target_flags
&= ~MASK_INTERWORK
;
2955 if (TARGET_THUMB_P (opts
->x_target_flags
)
2956 && !bitmap_bit_p (arm_active_target
.isa
, isa_bit_thumb
))
2958 warning (0, "target CPU does not support THUMB instructions");
2959 opts
->x_target_flags
&= ~MASK_THUMB
;
2962 if (TARGET_APCS_FRAME
&& TARGET_THUMB_P (opts
->x_target_flags
))
2964 /* warning (0, "ignoring -mapcs-frame because -mthumb was used"); */
2965 opts
->x_target_flags
&= ~MASK_APCS_FRAME
;
2968 /* Callee super interworking implies thumb interworking. Adding
2969 this to the flags here simplifies the logic elsewhere. */
2970 if (TARGET_THUMB_P (opts
->x_target_flags
) && TARGET_CALLEE_INTERWORKING
)
2971 opts
->x_target_flags
|= MASK_INTERWORK
;
2973 /* need to remember initial values so combinaisons of options like
2974 -mflip-thumb -mthumb -fno-schedule-insns work for any attribute. */
2975 cl_optimization
*to
= TREE_OPTIMIZATION (init_optimize
);
2977 if (! opts_set
->x_arm_restrict_it
)
2978 opts
->x_arm_restrict_it
= arm_arch8
;
2980 /* ARM execution state and M profile don't have [restrict] IT. */
2981 if (!TARGET_THUMB2_P (opts
->x_target_flags
) || !arm_arch_notm
)
2982 opts
->x_arm_restrict_it
= 0;
2984 /* Enable -munaligned-access by default for
2985 - all ARMv6 architecture-based processors when compiling for a 32-bit ISA
2986 i.e. Thumb2 and ARM state only.
2987 - ARMv7-A, ARMv7-R, and ARMv7-M architecture-based processors.
2988 - ARMv8 architecture-base processors.
2990 Disable -munaligned-access by default for
2991 - all pre-ARMv6 architecture-based processors
2992 - ARMv6-M architecture-based processors
2993 - ARMv8-M Baseline processors. */
2995 if (! opts_set
->x_unaligned_access
)
2997 opts
->x_unaligned_access
= (TARGET_32BIT_P (opts
->x_target_flags
)
2998 && arm_arch6
&& (arm_arch_notm
|| arm_arch7
));
3000 else if (opts
->x_unaligned_access
== 1
3001 && !(arm_arch6
&& (arm_arch_notm
|| arm_arch7
)))
3003 warning (0, "target CPU does not support unaligned accesses");
3004 opts
->x_unaligned_access
= 0;
3007 /* Don't warn since it's on by default in -O2. */
3008 if (TARGET_THUMB1_P (opts
->x_target_flags
))
3009 opts
->x_flag_schedule_insns
= 0;
3011 opts
->x_flag_schedule_insns
= to
->x_flag_schedule_insns
;
3013 /* Disable shrink-wrap when optimizing function for size, since it tends to
3014 generate additional returns. */
3015 if (optimize_function_for_size_p (cfun
)
3016 && TARGET_THUMB2_P (opts
->x_target_flags
))
3017 opts
->x_flag_shrink_wrap
= false;
3019 opts
->x_flag_shrink_wrap
= to
->x_flag_shrink_wrap
;
3021 /* In Thumb1 mode, we emit the epilogue in RTL, but the last insn
3022 - epilogue_insns - does not accurately model the corresponding insns
3023 emitted in the asm file. In particular, see the comment in thumb_exit
3024 'Find out how many of the (return) argument registers we can corrupt'.
3025 As a consequence, the epilogue may clobber registers without fipa-ra
3026 finding out about it. Therefore, disable fipa-ra in Thumb1 mode.
3027 TODO: Accurately model clobbers for epilogue_insns and reenable
3029 if (TARGET_THUMB1_P (opts
->x_target_flags
))
3030 opts
->x_flag_ipa_ra
= 0;
3032 opts
->x_flag_ipa_ra
= to
->x_flag_ipa_ra
;
3034 /* Thumb2 inline assembly code should always use unified syntax.
3035 This will apply to ARM and Thumb1 eventually. */
3036 opts
->x_inline_asm_unified
= TARGET_THUMB2_P (opts
->x_target_flags
);
3038 #ifdef SUBTARGET_OVERRIDE_INTERNAL_OPTIONS
3039 SUBTARGET_OVERRIDE_INTERNAL_OPTIONS
;
3043 static sbitmap isa_all_fpubits
;
3044 static sbitmap isa_quirkbits
;
3046 /* Configure a build target TARGET from the user-specified options OPTS and
3047 OPTS_SET. If WARN_COMPATIBLE, emit a diagnostic if both the CPU and
3048 architecture have been specified, but the two are not identical. */
3050 arm_configure_build_target (struct arm_build_target
*target
,
3051 struct cl_target_option
*opts
,
3052 struct gcc_options
*opts_set
,
3053 bool warn_compatible
)
3055 const cpu_option
*arm_selected_tune
= NULL
;
3056 const arch_option
*arm_selected_arch
= NULL
;
3057 const cpu_option
*arm_selected_cpu
= NULL
;
3058 const arm_fpu_desc
*arm_selected_fpu
= NULL
;
3059 const char *tune_opts
= NULL
;
3060 const char *arch_opts
= NULL
;
3061 const char *cpu_opts
= NULL
;
3063 bitmap_clear (target
->isa
);
3064 target
->core_name
= NULL
;
3065 target
->arch_name
= NULL
;
3067 if (opts_set
->x_arm_arch_string
)
3069 arm_selected_arch
= arm_parse_arch_option_name (all_architectures
,
3071 opts
->x_arm_arch_string
);
3072 arch_opts
= strchr (opts
->x_arm_arch_string
, '+');
3075 if (opts_set
->x_arm_cpu_string
)
3077 arm_selected_cpu
= arm_parse_cpu_option_name (all_cores
, "-mcpu",
3078 opts
->x_arm_cpu_string
);
3079 cpu_opts
= strchr (opts
->x_arm_cpu_string
, '+');
3080 arm_selected_tune
= arm_selected_cpu
;
3081 /* If taking the tuning from -mcpu, we don't need to rescan the
3082 options for tuning. */
3085 if (opts_set
->x_arm_tune_string
)
3087 arm_selected_tune
= arm_parse_cpu_option_name (all_cores
, "-mtune",
3088 opts
->x_arm_tune_string
);
3089 tune_opts
= strchr (opts
->x_arm_tune_string
, '+');
3092 if (arm_selected_arch
)
3094 arm_initialize_isa (target
->isa
, arm_selected_arch
->common
.isa_bits
);
3095 arm_parse_option_features (target
->isa
, &arm_selected_arch
->common
,
3098 if (arm_selected_cpu
)
3100 auto_sbitmap
cpu_isa (isa_num_bits
);
3101 auto_sbitmap
isa_delta (isa_num_bits
);
3103 arm_initialize_isa (cpu_isa
, arm_selected_cpu
->common
.isa_bits
);
3104 arm_parse_option_features (cpu_isa
, &arm_selected_cpu
->common
,
3106 bitmap_xor (isa_delta
, cpu_isa
, target
->isa
);
3107 /* Ignore any bits that are quirk bits. */
3108 bitmap_and_compl (isa_delta
, isa_delta
, isa_quirkbits
);
3109 /* Ignore (for now) any bits that might be set by -mfpu. */
3110 bitmap_and_compl (isa_delta
, isa_delta
, isa_all_fpubits
);
3112 if (!bitmap_empty_p (isa_delta
))
3114 if (warn_compatible
)
3115 warning (0, "switch -mcpu=%s conflicts with -march=%s switch",
3116 arm_selected_cpu
->common
.name
,
3117 arm_selected_arch
->common
.name
);
3118 /* -march wins for code generation.
3119 -mcpu wins for default tuning. */
3120 if (!arm_selected_tune
)
3121 arm_selected_tune
= arm_selected_cpu
;
3123 arm_selected_cpu
= all_cores
+ arm_selected_arch
->tune_id
;
3124 target
->arch_name
= arm_selected_arch
->common
.name
;
3128 /* Architecture and CPU are essentially the same.
3129 Prefer the CPU setting. */
3130 arm_selected_arch
= all_architectures
+ arm_selected_cpu
->arch
;
3131 target
->core_name
= arm_selected_cpu
->common
.name
;
3132 /* Copy the CPU's capabilities, so that we inherit the
3133 appropriate extensions and quirks. */
3134 bitmap_copy (target
->isa
, cpu_isa
);
3139 /* Pick a CPU based on the architecture. */
3140 arm_selected_cpu
= all_cores
+ arm_selected_arch
->tune_id
;
3141 target
->arch_name
= arm_selected_arch
->common
.name
;
3142 /* Note: target->core_name is left unset in this path. */
3145 else if (arm_selected_cpu
)
3147 target
->core_name
= arm_selected_cpu
->common
.name
;
3148 arm_initialize_isa (target
->isa
, arm_selected_cpu
->common
.isa_bits
);
3149 arm_parse_option_features (target
->isa
, &arm_selected_cpu
->common
,
3151 arm_selected_arch
= all_architectures
+ arm_selected_cpu
->arch
;
3153 /* If the user did not specify a processor or architecture, choose
3157 const cpu_option
*sel
;
3158 auto_sbitmap
sought_isa (isa_num_bits
);
3159 bitmap_clear (sought_isa
);
3160 auto_sbitmap
default_isa (isa_num_bits
);
3162 arm_selected_cpu
= arm_parse_cpu_option_name (all_cores
, "default CPU",
3163 TARGET_CPU_DEFAULT
);
3164 cpu_opts
= strchr (TARGET_CPU_DEFAULT
, '+');
3165 gcc_assert (arm_selected_cpu
->common
.name
);
3167 /* RWE: All of the selection logic below (to the end of this
3168 'if' clause) looks somewhat suspect. It appears to be mostly
3169 there to support forcing thumb support when the default CPU
3170 does not have thumb (somewhat dubious in terms of what the
3171 user might be expecting). I think it should be removed once
3172 support for the pre-thumb era cores is removed. */
3173 sel
= arm_selected_cpu
;
3174 arm_initialize_isa (default_isa
, sel
->common
.isa_bits
);
3175 arm_parse_option_features (default_isa
, &arm_selected_cpu
->common
,
3178 /* Now check to see if the user has specified any command line
3179 switches that require certain abilities from the cpu. */
3181 if (TARGET_INTERWORK
|| TARGET_THUMB
)
3183 bitmap_set_bit (sought_isa
, isa_bit_thumb
);
3184 bitmap_set_bit (sought_isa
, isa_bit_mode32
);
3186 /* There are no ARM processors that support both APCS-26 and
3187 interworking. Therefore we forcibly remove MODE26 from
3188 from the isa features here (if it was set), so that the
3189 search below will always be able to find a compatible
3191 bitmap_clear_bit (default_isa
, isa_bit_mode26
);
3194 /* If there are such requirements and the default CPU does not
3195 satisfy them, we need to run over the complete list of
3196 cores looking for one that is satisfactory. */
3197 if (!bitmap_empty_p (sought_isa
)
3198 && !bitmap_subset_p (sought_isa
, default_isa
))
3200 auto_sbitmap
candidate_isa (isa_num_bits
);
3201 /* We're only interested in a CPU with at least the
3202 capabilities of the default CPU and the required
3203 additional features. */
3204 bitmap_ior (default_isa
, default_isa
, sought_isa
);
3206 /* Try to locate a CPU type that supports all of the abilities
3207 of the default CPU, plus the extra abilities requested by
3209 for (sel
= all_cores
; sel
->common
.name
!= NULL
; sel
++)
3211 arm_initialize_isa (candidate_isa
, sel
->common
.isa_bits
);
3212 /* An exact match? */
3213 if (bitmap_equal_p (default_isa
, candidate_isa
))
3217 if (sel
->common
.name
== NULL
)
3219 unsigned current_bit_count
= isa_num_bits
;
3220 const cpu_option
*best_fit
= NULL
;
3222 /* Ideally we would like to issue an error message here
3223 saying that it was not possible to find a CPU compatible
3224 with the default CPU, but which also supports the command
3225 line options specified by the programmer, and so they
3226 ought to use the -mcpu=<name> command line option to
3227 override the default CPU type.
3229 If we cannot find a CPU that has exactly the
3230 characteristics of the default CPU and the given
3231 command line options we scan the array again looking
3232 for a best match. The best match must have at least
3233 the capabilities of the perfect match. */
3234 for (sel
= all_cores
; sel
->common
.name
!= NULL
; sel
++)
3236 arm_initialize_isa (candidate_isa
, sel
->common
.isa_bits
);
3238 if (bitmap_subset_p (default_isa
, candidate_isa
))
3242 bitmap_and_compl (candidate_isa
, candidate_isa
,
3244 count
= bitmap_popcount (candidate_isa
);
3246 if (count
< current_bit_count
)
3249 current_bit_count
= count
;
3253 gcc_assert (best_fit
);
3257 arm_selected_cpu
= sel
;
3260 /* Now we know the CPU, we can finally initialize the target
3262 target
->core_name
= arm_selected_cpu
->common
.name
;
3263 arm_initialize_isa (target
->isa
, arm_selected_cpu
->common
.isa_bits
);
3264 arm_parse_option_features (target
->isa
, &arm_selected_cpu
->common
,
3266 arm_selected_arch
= all_architectures
+ arm_selected_cpu
->arch
;
3269 gcc_assert (arm_selected_cpu
);
3270 gcc_assert (arm_selected_arch
);
3272 if (opts
->x_arm_fpu_index
!= TARGET_FPU_auto
)
3274 arm_selected_fpu
= &all_fpus
[opts
->x_arm_fpu_index
];
3275 auto_sbitmap
fpu_bits (isa_num_bits
);
3277 arm_initialize_isa (fpu_bits
, arm_selected_fpu
->isa_bits
);
3278 bitmap_and_compl (target
->isa
, target
->isa
, isa_all_fpubits
);
3279 bitmap_ior (target
->isa
, target
->isa
, fpu_bits
);
3282 if (!arm_selected_tune
)
3283 arm_selected_tune
= arm_selected_cpu
;
3284 else /* Validate the features passed to -mtune. */
3285 arm_parse_option_features (NULL
, &arm_selected_tune
->common
, tune_opts
);
3287 const cpu_tune
*tune_data
= &all_tunes
[arm_selected_tune
- all_cores
];
3289 /* Finish initializing the target structure. */
3290 target
->arch_pp_name
= arm_selected_arch
->arch
;
3291 target
->base_arch
= arm_selected_arch
->base_arch
;
3292 target
->profile
= arm_selected_arch
->profile
;
3294 target
->tune_flags
= tune_data
->tune_flags
;
3295 target
->tune
= tune_data
->tune
;
3296 target
->tune_core
= tune_data
->scheduler
;
3299 /* Fix up any incompatible options that the user has specified. */
3301 arm_option_override (void)
3303 static const enum isa_feature fpu_bitlist
[]
3304 = { ISA_ALL_FPU_INTERNAL
, isa_nobit
};
3305 static const enum isa_feature quirk_bitlist
[] = { ISA_ALL_QUIRKS
, isa_nobit
};
3306 cl_target_option opts
;
3308 isa_quirkbits
= sbitmap_alloc (isa_num_bits
);
3309 arm_initialize_isa (isa_quirkbits
, quirk_bitlist
);
3311 isa_all_fpubits
= sbitmap_alloc (isa_num_bits
);
3312 arm_initialize_isa (isa_all_fpubits
, fpu_bitlist
);
3314 arm_active_target
.isa
= sbitmap_alloc (isa_num_bits
);
3316 if (!global_options_set
.x_arm_fpu_index
)
3321 ok
= opt_enum_arg_to_value (OPT_mfpu_
, FPUTYPE_AUTO
, &fpu_index
,
3324 arm_fpu_index
= (enum fpu_type
) fpu_index
;
3327 cl_target_option_save (&opts
, &global_options
);
3328 arm_configure_build_target (&arm_active_target
, &opts
, &global_options_set
,
3331 #ifdef SUBTARGET_OVERRIDE_OPTIONS
3332 SUBTARGET_OVERRIDE_OPTIONS
;
3335 sprintf (arm_arch_name
, "__ARM_ARCH_%s__", arm_active_target
.arch_pp_name
);
3336 arm_base_arch
= arm_active_target
.base_arch
;
3338 arm_tune
= arm_active_target
.tune_core
;
3339 tune_flags
= arm_active_target
.tune_flags
;
3340 current_tune
= arm_active_target
.tune
;
3342 /* TBD: Dwarf info for apcs frame is not handled yet. */
3343 if (TARGET_APCS_FRAME
)
3344 flag_shrink_wrap
= false;
3346 /* BPABI targets use linker tricks to allow interworking on cores
3347 without thumb support. */
3348 if (TARGET_INTERWORK
3350 && !bitmap_bit_p (arm_active_target
.isa
, isa_bit_thumb
))
3352 warning (0, "target CPU does not support interworking" );
3353 target_flags
&= ~MASK_INTERWORK
;
3356 if (TARGET_APCS_STACK
&& !TARGET_APCS_FRAME
)
3358 warning (0, "-mapcs-stack-check incompatible with -mno-apcs-frame");
3359 target_flags
|= MASK_APCS_FRAME
;
3362 if (TARGET_POKE_FUNCTION_NAME
)
3363 target_flags
|= MASK_APCS_FRAME
;
3365 if (TARGET_APCS_REENT
&& flag_pic
)
3366 error ("-fpic and -mapcs-reent are incompatible");
3368 if (TARGET_APCS_REENT
)
3369 warning (0, "APCS reentrant code not supported. Ignored");
3371 /* Initialize boolean versions of the architectural flags, for use
3372 in the arm.md file. */
3373 arm_arch3m
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_armv3m
);
3374 arm_arch4
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_armv4
);
3375 arm_arch4t
= arm_arch4
&& bitmap_bit_p (arm_active_target
.isa
, isa_bit_thumb
);
3376 arm_arch5
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_armv5
);
3377 arm_arch5e
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_armv5e
);
3378 arm_arch5te
= arm_arch5e
3379 && bitmap_bit_p (arm_active_target
.isa
, isa_bit_thumb
);
3380 arm_arch6
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_armv6
);
3381 arm_arch6k
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_armv6k
);
3382 arm_arch_notm
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_notm
);
3383 arm_arch6m
= arm_arch6
&& !arm_arch_notm
;
3384 arm_arch7
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_armv7
);
3385 arm_arch7em
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_armv7em
);
3386 arm_arch8
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_armv8
);
3387 arm_arch8_1
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_armv8_1
);
3388 arm_arch8_2
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_armv8_2
);
3389 arm_arch_thumb1
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_thumb
);
3390 arm_arch_thumb2
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_thumb2
);
3391 arm_arch_xscale
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_xscale
);
3392 arm_arch_iwmmxt
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_iwmmxt
);
3393 arm_arch_iwmmxt2
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_iwmmxt2
);
3394 arm_arch_thumb_hwdiv
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_tdiv
);
3395 arm_arch_arm_hwdiv
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_adiv
);
3396 arm_arch_crc
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_crc32
);
3397 arm_arch_cmse
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_cmse
);
3398 arm_fp16_inst
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_fp16
);
3399 arm_arch_lpae
= bitmap_bit_p (arm_active_target
.isa
, isa_bit_lpae
);
3402 if (arm_fp16_format
== ARM_FP16_FORMAT_ALTERNATIVE
)
3403 error ("selected fp16 options are incompatible");
3404 arm_fp16_format
= ARM_FP16_FORMAT_IEEE
;
3408 /* Set up some tuning parameters. */
3409 arm_ld_sched
= (tune_flags
& TF_LDSCHED
) != 0;
3410 arm_tune_strongarm
= (tune_flags
& TF_STRONG
) != 0;
3411 arm_tune_wbuf
= (tune_flags
& TF_WBUF
) != 0;
3412 arm_tune_xscale
= (tune_flags
& TF_XSCALE
) != 0;
3413 arm_tune_cortex_a9
= (arm_tune
== TARGET_CPU_cortexa9
) != 0;
3414 arm_m_profile_small_mul
= (tune_flags
& TF_SMALLMUL
) != 0;
3416 /* And finally, set up some quirks. */
3417 arm_arch_no_volatile_ce
3418 = bitmap_bit_p (arm_active_target
.isa
, isa_bit_quirk_no_volatile_ce
);
3419 arm_arch6kz
= arm_arch6k
&& bitmap_bit_p (arm_active_target
.isa
,
3420 isa_bit_quirk_armv6kz
);
3422 /* V5 code we generate is completely interworking capable, so we turn off
3423 TARGET_INTERWORK here to avoid many tests later on. */
3425 /* XXX However, we must pass the right pre-processor defines to CPP
3426 or GLD can get confused. This is a hack. */
3427 if (TARGET_INTERWORK
)
3428 arm_cpp_interwork
= 1;
3431 target_flags
&= ~MASK_INTERWORK
;
3433 if (TARGET_IWMMXT
&& !ARM_DOUBLEWORD_ALIGN
)
3434 error ("iwmmxt requires an AAPCS compatible ABI for proper operation");
3436 if (TARGET_IWMMXT_ABI
&& !TARGET_IWMMXT
)
3437 error ("iwmmxt abi requires an iwmmxt capable cpu");
3439 /* If soft-float is specified then don't use FPU. */
3440 if (TARGET_SOFT_FLOAT
)
3441 arm_fpu_attr
= FPU_NONE
;
3443 arm_fpu_attr
= FPU_VFP
;
3445 if (TARGET_AAPCS_BASED
)
3447 if (TARGET_CALLER_INTERWORKING
)
3448 error ("AAPCS does not support -mcaller-super-interworking");
3450 if (TARGET_CALLEE_INTERWORKING
)
3451 error ("AAPCS does not support -mcallee-super-interworking");
3454 /* __fp16 support currently assumes the core has ldrh. */
3455 if (!arm_arch4
&& arm_fp16_format
!= ARM_FP16_FORMAT_NONE
)
3456 sorry ("__fp16 and no ldrh");
3458 if (TARGET_AAPCS_BASED
)
3460 if (arm_abi
== ARM_ABI_IWMMXT
)
3461 arm_pcs_default
= ARM_PCS_AAPCS_IWMMXT
;
3462 else if (TARGET_HARD_FLOAT_ABI
)
3464 arm_pcs_default
= ARM_PCS_AAPCS_VFP
;
3465 if (!bitmap_bit_p (arm_active_target
.isa
, isa_bit_vfpv2
))
3466 error ("-mfloat-abi=hard: selected processor lacks an FPU");
3469 arm_pcs_default
= ARM_PCS_AAPCS
;
3473 if (arm_float_abi
== ARM_FLOAT_ABI_HARD
)
3474 sorry ("-mfloat-abi=hard and VFP");
3476 if (arm_abi
== ARM_ABI_APCS
)
3477 arm_pcs_default
= ARM_PCS_APCS
;
3479 arm_pcs_default
= ARM_PCS_ATPCS
;
3482 /* For arm2/3 there is no need to do any scheduling if we are doing
3483 software floating-point. */
3484 if (TARGET_SOFT_FLOAT
&& (tune_flags
& TF_NO_MODE32
))
3485 flag_schedule_insns
= flag_schedule_insns_after_reload
= 0;
3487 /* Use the cp15 method if it is available. */
3488 if (target_thread_pointer
== TP_AUTO
)
3490 if (arm_arch6k
&& !TARGET_THUMB1
)
3491 target_thread_pointer
= TP_CP15
;
3493 target_thread_pointer
= TP_SOFT
;
3496 /* Override the default structure alignment for AAPCS ABI. */
3497 if (!global_options_set
.x_arm_structure_size_boundary
)
3499 if (TARGET_AAPCS_BASED
)
3500 arm_structure_size_boundary
= 8;
3504 warning (0, "option %<-mstructure-size-boundary%> is deprecated");
3506 if (arm_structure_size_boundary
!= 8
3507 && arm_structure_size_boundary
!= 32
3508 && !(ARM_DOUBLEWORD_ALIGN
&& arm_structure_size_boundary
== 64))
3510 if (ARM_DOUBLEWORD_ALIGN
)
3512 "structure size boundary can only be set to 8, 32 or 64");
3514 warning (0, "structure size boundary can only be set to 8 or 32");
3515 arm_structure_size_boundary
3516 = (TARGET_AAPCS_BASED
? 8 : DEFAULT_STRUCTURE_SIZE_BOUNDARY
);
3520 if (TARGET_VXWORKS_RTP
)
3522 if (!global_options_set
.x_arm_pic_data_is_text_relative
)
3523 arm_pic_data_is_text_relative
= 0;
3526 && !arm_pic_data_is_text_relative
3527 && !(global_options_set
.x_target_flags
& MASK_SINGLE_PIC_BASE
))
3528 /* When text & data segments don't have a fixed displacement, the
3529 intended use is with a single, read only, pic base register.
3530 Unless the user explicitly requested not to do that, set
3532 target_flags
|= MASK_SINGLE_PIC_BASE
;
3534 /* If stack checking is disabled, we can use r10 as the PIC register,
3535 which keeps r9 available. The EABI specifies r9 as the PIC register. */
3536 if (flag_pic
&& TARGET_SINGLE_PIC_BASE
)
3538 if (TARGET_VXWORKS_RTP
)
3539 warning (0, "RTP PIC is incompatible with -msingle-pic-base");
3540 arm_pic_register
= (TARGET_APCS_STACK
|| TARGET_AAPCS_BASED
) ? 9 : 10;
3543 if (flag_pic
&& TARGET_VXWORKS_RTP
)
3544 arm_pic_register
= 9;
3546 if (arm_pic_register_string
!= NULL
)
3548 int pic_register
= decode_reg_name (arm_pic_register_string
);
3551 warning (0, "-mpic-register= is useless without -fpic");
3553 /* Prevent the user from choosing an obviously stupid PIC register. */
3554 else if (pic_register
< 0 || call_used_regs
[pic_register
]
3555 || pic_register
== HARD_FRAME_POINTER_REGNUM
3556 || pic_register
== STACK_POINTER_REGNUM
3557 || pic_register
>= PC_REGNUM
3558 || (TARGET_VXWORKS_RTP
3559 && (unsigned int) pic_register
!= arm_pic_register
))
3560 error ("unable to use '%s' for PIC register", arm_pic_register_string
);
3562 arm_pic_register
= pic_register
;
3565 /* Enable -mfix-cortex-m3-ldrd by default for Cortex-M3 cores. */
3566 if (fix_cm3_ldrd
== 2)
3568 if (bitmap_bit_p (arm_active_target
.isa
, isa_bit_quirk_cm3_ldrd
))
3574 /* Hot/Cold partitioning is not currently supported, since we can't
3575 handle literal pool placement in that case. */
3576 if (flag_reorder_blocks_and_partition
)
3578 inform (input_location
,
3579 "-freorder-blocks-and-partition not supported on this architecture");
3580 flag_reorder_blocks_and_partition
= 0;
3581 flag_reorder_blocks
= 1;
3585 /* Hoisting PIC address calculations more aggressively provides a small,
3586 but measurable, size reduction for PIC code. Therefore, we decrease
3587 the bar for unrestricted expression hoisting to the cost of PIC address
3588 calculation, which is 2 instructions. */
3589 maybe_set_param_value (PARAM_GCSE_UNRESTRICTED_COST
, 2,
3590 global_options
.x_param_values
,
3591 global_options_set
.x_param_values
);
3593 /* ARM EABI defaults to strict volatile bitfields. */
3594 if (TARGET_AAPCS_BASED
&& flag_strict_volatile_bitfields
< 0
3595 && abi_version_at_least(2))
3596 flag_strict_volatile_bitfields
= 1;
3598 /* Enable sw prefetching at -O3 for CPUS that have prefetch, and we
3599 have deemed it beneficial (signified by setting
3600 prefetch.num_slots to 1 or more). */
3601 if (flag_prefetch_loop_arrays
< 0
3604 && current_tune
->prefetch
.num_slots
> 0)
3605 flag_prefetch_loop_arrays
= 1;
3607 /* Set up parameters to be used in prefetching algorithm. Do not
3608 override the defaults unless we are tuning for a core we have
3609 researched values for. */
3610 if (current_tune
->prefetch
.num_slots
> 0)
3611 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES
,
3612 current_tune
->prefetch
.num_slots
,
3613 global_options
.x_param_values
,
3614 global_options_set
.x_param_values
);
3615 if (current_tune
->prefetch
.l1_cache_line_size
>= 0)
3616 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE
,
3617 current_tune
->prefetch
.l1_cache_line_size
,
3618 global_options
.x_param_values
,
3619 global_options_set
.x_param_values
);
3620 if (current_tune
->prefetch
.l1_cache_size
>= 0)
3621 maybe_set_param_value (PARAM_L1_CACHE_SIZE
,
3622 current_tune
->prefetch
.l1_cache_size
,
3623 global_options
.x_param_values
,
3624 global_options_set
.x_param_values
);
3626 /* Use Neon to perform 64-bits operations rather than core
3628 prefer_neon_for_64bits
= current_tune
->prefer_neon_for_64bits
;
3629 if (use_neon_for_64bits
== 1)
3630 prefer_neon_for_64bits
= true;
3632 /* Use the alternative scheduling-pressure algorithm by default. */
3633 maybe_set_param_value (PARAM_SCHED_PRESSURE_ALGORITHM
, SCHED_PRESSURE_MODEL
,
3634 global_options
.x_param_values
,
3635 global_options_set
.x_param_values
);
3637 /* Look through ready list and all of queue for instructions
3638 relevant for L2 auto-prefetcher. */
3639 int param_sched_autopref_queue_depth
;
3641 switch (current_tune
->sched_autopref
)
3643 case tune_params::SCHED_AUTOPREF_OFF
:
3644 param_sched_autopref_queue_depth
= -1;
3647 case tune_params::SCHED_AUTOPREF_RANK
:
3648 param_sched_autopref_queue_depth
= 0;
3651 case tune_params::SCHED_AUTOPREF_FULL
:
3652 param_sched_autopref_queue_depth
= max_insn_queue_index
+ 1;
3659 maybe_set_param_value (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH
,
3660 param_sched_autopref_queue_depth
,
3661 global_options
.x_param_values
,
3662 global_options_set
.x_param_values
);
3664 /* Currently, for slow flash data, we just disable literal pools. We also
3665 disable it for pure-code. */
3666 if (target_slow_flash_data
|| target_pure_code
)
3667 arm_disable_literal_pool
= true;
3669 if (use_cmse
&& !arm_arch_cmse
)
3670 error ("target CPU does not support ARMv8-M Security Extensions");
3672 /* We don't clear D16-D31 VFP registers for cmse_nonsecure_call functions
3673 and ARMv8-M Baseline and Mainline do not allow such configuration. */
3674 if (use_cmse
&& LAST_VFP_REGNUM
> LAST_LO_VFP_REGNUM
)
3675 error ("ARMv8-M Security Extensions incompatible with selected FPU");
3677 /* Disable scheduling fusion by default if it's not armv7 processor
3678 or doesn't prefer ldrd/strd. */
3679 if (flag_schedule_fusion
== 2
3680 && (!arm_arch7
|| !current_tune
->prefer_ldrd_strd
))
3681 flag_schedule_fusion
= 0;
3683 /* Need to remember initial options before they are overriden. */
3684 init_optimize
= build_optimization_node (&global_options
);
3686 arm_option_override_internal (&global_options
, &global_options_set
);
3687 arm_option_check_internal (&global_options
);
3688 arm_option_params_internal ();
3690 /* Create the default target_options structure. */
3691 target_option_default_node
= target_option_current_node
3692 = build_target_option_node (&global_options
);
3694 /* Register global variables with the garbage collector. */
3695 arm_add_gc_roots ();
3697 /* Init initial mode for testing. */
3698 thumb_flipper
= TARGET_THUMB
;
3702 arm_add_gc_roots (void)
3704 gcc_obstack_init(&minipool_obstack
);
3705 minipool_startobj
= (char *) obstack_alloc (&minipool_obstack
, 0);
3708 /* A table of known ARM exception types.
3709 For use with the interrupt function attribute. */
3713 const char *const arg
;
3714 const unsigned long return_value
;
3718 static const isr_attribute_arg isr_attribute_args
[] =
3720 { "IRQ", ARM_FT_ISR
},
3721 { "irq", ARM_FT_ISR
},
3722 { "FIQ", ARM_FT_FIQ
},
3723 { "fiq", ARM_FT_FIQ
},
3724 { "ABORT", ARM_FT_ISR
},
3725 { "abort", ARM_FT_ISR
},
3726 { "ABORT", ARM_FT_ISR
},
3727 { "abort", ARM_FT_ISR
},
3728 { "UNDEF", ARM_FT_EXCEPTION
},
3729 { "undef", ARM_FT_EXCEPTION
},
3730 { "SWI", ARM_FT_EXCEPTION
},
3731 { "swi", ARM_FT_EXCEPTION
},
3732 { NULL
, ARM_FT_NORMAL
}
3735 /* Returns the (interrupt) function type of the current
3736 function, or ARM_FT_UNKNOWN if the type cannot be determined. */
3738 static unsigned long
3739 arm_isr_value (tree argument
)
3741 const isr_attribute_arg
* ptr
;
3745 return ARM_FT_NORMAL
| ARM_FT_STACKALIGN
;
3747 /* No argument - default to IRQ. */
3748 if (argument
== NULL_TREE
)
3751 /* Get the value of the argument. */
3752 if (TREE_VALUE (argument
) == NULL_TREE
3753 || TREE_CODE (TREE_VALUE (argument
)) != STRING_CST
)
3754 return ARM_FT_UNKNOWN
;
3756 arg
= TREE_STRING_POINTER (TREE_VALUE (argument
));
3758 /* Check it against the list of known arguments. */
3759 for (ptr
= isr_attribute_args
; ptr
->arg
!= NULL
; ptr
++)
3760 if (streq (arg
, ptr
->arg
))
3761 return ptr
->return_value
;
3763 /* An unrecognized interrupt type. */
3764 return ARM_FT_UNKNOWN
;
3767 /* Computes the type of the current function. */
3769 static unsigned long
3770 arm_compute_func_type (void)
3772 unsigned long type
= ARM_FT_UNKNOWN
;
3776 gcc_assert (TREE_CODE (current_function_decl
) == FUNCTION_DECL
);
3778 /* Decide if the current function is volatile. Such functions
3779 never return, and many memory cycles can be saved by not storing
3780 register values that will never be needed again. This optimization
3781 was added to speed up context switching in a kernel application. */
3783 && (TREE_NOTHROW (current_function_decl
)
3784 || !(flag_unwind_tables
3786 && arm_except_unwind_info (&global_options
) != UI_SJLJ
)))
3787 && TREE_THIS_VOLATILE (current_function_decl
))
3788 type
|= ARM_FT_VOLATILE
;
3790 if (cfun
->static_chain_decl
!= NULL
)
3791 type
|= ARM_FT_NESTED
;
3793 attr
= DECL_ATTRIBUTES (current_function_decl
);
3795 a
= lookup_attribute ("naked", attr
);
3797 type
|= ARM_FT_NAKED
;
3799 a
= lookup_attribute ("isr", attr
);
3801 a
= lookup_attribute ("interrupt", attr
);
3804 type
|= TARGET_INTERWORK
? ARM_FT_INTERWORKED
: ARM_FT_NORMAL
;
3806 type
|= arm_isr_value (TREE_VALUE (a
));
3808 if (lookup_attribute ("cmse_nonsecure_entry", attr
))
3809 type
|= ARM_FT_CMSE_ENTRY
;
3814 /* Returns the type of the current function. */
3817 arm_current_func_type (void)
3819 if (ARM_FUNC_TYPE (cfun
->machine
->func_type
) == ARM_FT_UNKNOWN
)
3820 cfun
->machine
->func_type
= arm_compute_func_type ();
3822 return cfun
->machine
->func_type
;
3826 arm_allocate_stack_slots_for_args (void)
3828 /* Naked functions should not allocate stack slots for arguments. */
3829 return !IS_NAKED (arm_current_func_type ());
3833 arm_warn_func_return (tree decl
)
3835 /* Naked functions are implemented entirely in assembly, including the
3836 return sequence, so suppress warnings about this. */
3837 return lookup_attribute ("naked", DECL_ATTRIBUTES (decl
)) == NULL_TREE
;
3841 /* Output assembler code for a block containing the constant parts
3842 of a trampoline, leaving space for the variable parts.
3844 On the ARM, (if r8 is the static chain regnum, and remembering that
3845 referencing pc adds an offset of 8) the trampoline looks like:
3848 .word static chain value
3849 .word function's address
3850 XXX FIXME: When the trampoline returns, r8 will be clobbered. */
3853 arm_asm_trampoline_template (FILE *f
)
3855 fprintf (f
, "\t.syntax unified\n");
3859 fprintf (f
, "\t.arm\n");
3860 asm_fprintf (f
, "\tldr\t%r, [%r, #0]\n", STATIC_CHAIN_REGNUM
, PC_REGNUM
);
3861 asm_fprintf (f
, "\tldr\t%r, [%r, #0]\n", PC_REGNUM
, PC_REGNUM
);
3863 else if (TARGET_THUMB2
)
3865 fprintf (f
, "\t.thumb\n");
3866 /* The Thumb-2 trampoline is similar to the arm implementation.
3867 Unlike 16-bit Thumb, we enter the stub in thumb mode. */
3868 asm_fprintf (f
, "\tldr.w\t%r, [%r, #4]\n",
3869 STATIC_CHAIN_REGNUM
, PC_REGNUM
);
3870 asm_fprintf (f
, "\tldr.w\t%r, [%r, #4]\n", PC_REGNUM
, PC_REGNUM
);
3874 ASM_OUTPUT_ALIGN (f
, 2);
3875 fprintf (f
, "\t.code\t16\n");
3876 fprintf (f
, ".Ltrampoline_start:\n");
3877 asm_fprintf (f
, "\tpush\t{r0, r1}\n");
3878 asm_fprintf (f
, "\tldr\tr0, [%r, #8]\n", PC_REGNUM
);
3879 asm_fprintf (f
, "\tmov\t%r, r0\n", STATIC_CHAIN_REGNUM
);
3880 asm_fprintf (f
, "\tldr\tr0, [%r, #8]\n", PC_REGNUM
);
3881 asm_fprintf (f
, "\tstr\tr0, [%r, #4]\n", SP_REGNUM
);
3882 asm_fprintf (f
, "\tpop\t{r0, %r}\n", PC_REGNUM
);
3884 assemble_aligned_integer (UNITS_PER_WORD
, const0_rtx
);
3885 assemble_aligned_integer (UNITS_PER_WORD
, const0_rtx
);
3888 /* Emit RTL insns to initialize the variable parts of a trampoline. */
3891 arm_trampoline_init (rtx m_tramp
, tree fndecl
, rtx chain_value
)
3893 rtx fnaddr
, mem
, a_tramp
;
3895 emit_block_move (m_tramp
, assemble_trampoline_template (),
3896 GEN_INT (TRAMPOLINE_SIZE
), BLOCK_OP_NORMAL
);
3898 mem
= adjust_address (m_tramp
, SImode
, TARGET_32BIT
? 8 : 12);
3899 emit_move_insn (mem
, chain_value
);
3901 mem
= adjust_address (m_tramp
, SImode
, TARGET_32BIT
? 12 : 16);
3902 fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
3903 emit_move_insn (mem
, fnaddr
);
3905 a_tramp
= XEXP (m_tramp
, 0);
3906 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, "__clear_cache"),
3907 LCT_NORMAL
, VOIDmode
, a_tramp
, Pmode
,
3908 plus_constant (Pmode
, a_tramp
, TRAMPOLINE_SIZE
), Pmode
);
3911 /* Thumb trampolines should be entered in thumb mode, so set
3912 the bottom bit of the address. */
3915 arm_trampoline_adjust_address (rtx addr
)
3918 addr
= expand_simple_binop (Pmode
, IOR
, addr
, const1_rtx
,
3919 NULL
, 0, OPTAB_LIB_WIDEN
);
3923 /* Return 1 if it is possible to return using a single instruction.
3924 If SIBLING is non-null, this is a test for a return before a sibling
3925 call. SIBLING is the call insn, so we can examine its register usage. */
3928 use_return_insn (int iscond
, rtx sibling
)
3931 unsigned int func_type
;
3932 unsigned long saved_int_regs
;
3933 unsigned HOST_WIDE_INT stack_adjust
;
3934 arm_stack_offsets
*offsets
;
3936 /* Never use a return instruction before reload has run. */
3937 if (!reload_completed
)
3940 func_type
= arm_current_func_type ();
3942 /* Naked, volatile and stack alignment functions need special
3944 if (func_type
& (ARM_FT_VOLATILE
| ARM_FT_NAKED
| ARM_FT_STACKALIGN
))
3947 /* So do interrupt functions that use the frame pointer and Thumb
3948 interrupt functions. */
3949 if (IS_INTERRUPT (func_type
) && (frame_pointer_needed
|| TARGET_THUMB
))
3952 if (TARGET_LDRD
&& current_tune
->prefer_ldrd_strd
3953 && !optimize_function_for_size_p (cfun
))
3956 offsets
= arm_get_frame_offsets ();
3957 stack_adjust
= offsets
->outgoing_args
- offsets
->saved_regs
;
3959 /* As do variadic functions. */
3960 if (crtl
->args
.pretend_args_size
3961 || cfun
->machine
->uses_anonymous_args
3962 /* Or if the function calls __builtin_eh_return () */
3963 || crtl
->calls_eh_return
3964 /* Or if the function calls alloca */
3965 || cfun
->calls_alloca
3966 /* Or if there is a stack adjustment. However, if the stack pointer
3967 is saved on the stack, we can use a pre-incrementing stack load. */
3968 || !(stack_adjust
== 0 || (TARGET_APCS_FRAME
&& frame_pointer_needed
3969 && stack_adjust
== 4))
3970 /* Or if the static chain register was saved above the frame, under the
3971 assumption that the stack pointer isn't saved on the stack. */
3972 || (!(TARGET_APCS_FRAME
&& frame_pointer_needed
)
3973 && arm_compute_static_chain_stack_bytes() != 0))
3976 saved_int_regs
= offsets
->saved_regs_mask
;
3978 /* Unfortunately, the insn
3980 ldmib sp, {..., sp, ...}
3982 triggers a bug on most SA-110 based devices, such that the stack
3983 pointer won't be correctly restored if the instruction takes a
3984 page fault. We work around this problem by popping r3 along with
3985 the other registers, since that is never slower than executing
3986 another instruction.
3988 We test for !arm_arch5 here, because code for any architecture
3989 less than this could potentially be run on one of the buggy
3991 if (stack_adjust
== 4 && !arm_arch5
&& TARGET_ARM
)
3993 /* Validate that r3 is a call-clobbered register (always true in
3994 the default abi) ... */
3995 if (!call_used_regs
[3])
3998 /* ... that it isn't being used for a return value ... */
3999 if (arm_size_return_regs () >= (4 * UNITS_PER_WORD
))
4002 /* ... or for a tail-call argument ... */
4005 gcc_assert (CALL_P (sibling
));
4007 if (find_regno_fusage (sibling
, USE
, 3))
4011 /* ... and that there are no call-saved registers in r0-r2
4012 (always true in the default ABI). */
4013 if (saved_int_regs
& 0x7)
4017 /* Can't be done if interworking with Thumb, and any registers have been
4019 if (TARGET_INTERWORK
&& saved_int_regs
!= 0 && !IS_INTERRUPT(func_type
))
4022 /* On StrongARM, conditional returns are expensive if they aren't
4023 taken and multiple registers have been stacked. */
4024 if (iscond
&& arm_tune_strongarm
)
4026 /* Conditional return when just the LR is stored is a simple
4027 conditional-load instruction, that's not expensive. */
4028 if (saved_int_regs
!= 0 && saved_int_regs
!= (1 << LR_REGNUM
))
4032 && arm_pic_register
!= INVALID_REGNUM
4033 && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
))
4037 /* ARMv8-M nonsecure entry function need to use bxns to return and thus need
4038 several instructions if anything needs to be popped. */
4039 if (saved_int_regs
&& IS_CMSE_ENTRY (func_type
))
4042 /* If there are saved registers but the LR isn't saved, then we need
4043 two instructions for the return. */
4044 if (saved_int_regs
&& !(saved_int_regs
& (1 << LR_REGNUM
)))
4047 /* Can't be done if any of the VFP regs are pushed,
4048 since this also requires an insn. */
4049 if (TARGET_HARD_FLOAT
)
4050 for (regno
= FIRST_VFP_REGNUM
; regno
<= LAST_VFP_REGNUM
; regno
++)
4051 if (df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
4054 if (TARGET_REALLY_IWMMXT
)
4055 for (regno
= FIRST_IWMMXT_REGNUM
; regno
<= LAST_IWMMXT_REGNUM
; regno
++)
4056 if (df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
4062 /* Return TRUE if we should try to use a simple_return insn, i.e. perform
4063 shrink-wrapping if possible. This is the case if we need to emit a
4064 prologue, which we can test by looking at the offsets. */
4066 use_simple_return_p (void)
4068 arm_stack_offsets
*offsets
;
4070 /* Note this function can be called before or after reload. */
4071 if (!reload_completed
)
4072 arm_compute_frame_layout ();
4074 offsets
= arm_get_frame_offsets ();
4075 return offsets
->outgoing_args
!= 0;
4078 /* Return TRUE if int I is a valid immediate ARM constant. */
4081 const_ok_for_arm (HOST_WIDE_INT i
)
4085 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
4086 be all zero, or all one. */
4087 if ((i
& ~(unsigned HOST_WIDE_INT
) 0xffffffff) != 0
4088 && ((i
& ~(unsigned HOST_WIDE_INT
) 0xffffffff)
4089 != ((~(unsigned HOST_WIDE_INT
) 0)
4090 & ~(unsigned HOST_WIDE_INT
) 0xffffffff)))
4093 i
&= (unsigned HOST_WIDE_INT
) 0xffffffff;
4095 /* Fast return for 0 and small values. We must do this for zero, since
4096 the code below can't handle that one case. */
4097 if ((i
& ~(unsigned HOST_WIDE_INT
) 0xff) == 0)
4100 /* Get the number of trailing zeros. */
4101 lowbit
= ffs((int) i
) - 1;
4103 /* Only even shifts are allowed in ARM mode so round down to the
4104 nearest even number. */
4108 if ((i
& ~(((unsigned HOST_WIDE_INT
) 0xff) << lowbit
)) == 0)
4113 /* Allow rotated constants in ARM mode. */
4115 && ((i
& ~0xc000003f) == 0
4116 || (i
& ~0xf000000f) == 0
4117 || (i
& ~0xfc000003) == 0))
4120 else if (TARGET_THUMB2
)
4124 /* Allow repeated patterns 0x00XY00XY or 0xXYXYXYXY. */
4127 if (i
== v
|| i
== (v
| (v
<< 8)))
4130 /* Allow repeated pattern 0xXY00XY00. */
4136 else if (TARGET_HAVE_MOVT
)
4138 /* Thumb-1 Targets with MOVT. */
4148 /* Return true if I is a valid constant for the operation CODE. */
4150 const_ok_for_op (HOST_WIDE_INT i
, enum rtx_code code
)
4152 if (const_ok_for_arm (i
))
4158 /* See if we can use movw. */
4159 if (TARGET_HAVE_MOVT
&& (i
& 0xffff0000) == 0)
4162 /* Otherwise, try mvn. */
4163 return const_ok_for_arm (ARM_SIGN_EXTEND (~i
));
4166 /* See if we can use addw or subw. */
4168 && ((i
& 0xfffff000) == 0
4169 || ((-i
) & 0xfffff000) == 0))
4190 return const_ok_for_arm (ARM_SIGN_EXTEND (-i
));
4192 case MINUS
: /* Should only occur with (MINUS I reg) => rsb */
4198 return const_ok_for_arm (ARM_SIGN_EXTEND (~i
));
4202 return const_ok_for_arm (ARM_SIGN_EXTEND (~i
));
4209 /* Return true if I is a valid di mode constant for the operation CODE. */
4211 const_ok_for_dimode_op (HOST_WIDE_INT i
, enum rtx_code code
)
4213 HOST_WIDE_INT hi_val
= (i
>> 32) & 0xFFFFFFFF;
4214 HOST_WIDE_INT lo_val
= i
& 0xFFFFFFFF;
4215 rtx hi
= GEN_INT (hi_val
);
4216 rtx lo
= GEN_INT (lo_val
);
4226 return (const_ok_for_op (hi_val
, code
) || hi_val
== 0xFFFFFFFF)
4227 && (const_ok_for_op (lo_val
, code
) || lo_val
== 0xFFFFFFFF);
4229 return arm_not_operand (hi
, SImode
) && arm_add_operand (lo
, SImode
);
4236 /* Emit a sequence of insns to handle a large constant.
4237 CODE is the code of the operation required, it can be any of SET, PLUS,
4238 IOR, AND, XOR, MINUS;
4239 MODE is the mode in which the operation is being performed;
4240 VAL is the integer to operate on;
4241 SOURCE is the other operand (a register, or a null-pointer for SET);
4242 SUBTARGETS means it is safe to create scratch registers if that will
4243 either produce a simpler sequence, or we will want to cse the values.
4244 Return value is the number of insns emitted. */
4246 /* ??? Tweak this for thumb2. */
4248 arm_split_constant (enum rtx_code code
, machine_mode mode
, rtx insn
,
4249 HOST_WIDE_INT val
, rtx target
, rtx source
, int subtargets
)
4253 if (insn
&& GET_CODE (PATTERN (insn
)) == COND_EXEC
)
4254 cond
= COND_EXEC_TEST (PATTERN (insn
));
4258 if (subtargets
|| code
== SET
4259 || (REG_P (target
) && REG_P (source
)
4260 && REGNO (target
) != REGNO (source
)))
4262 /* After arm_reorg has been called, we can't fix up expensive
4263 constants by pushing them into memory so we must synthesize
4264 them in-line, regardless of the cost. This is only likely to
4265 be more costly on chips that have load delay slots and we are
4266 compiling without running the scheduler (so no splitting
4267 occurred before the final instruction emission).
4269 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
4271 if (!cfun
->machine
->after_arm_reorg
4273 && (arm_gen_constant (code
, mode
, NULL_RTX
, val
, target
, source
,
4275 > (arm_constant_limit (optimize_function_for_size_p (cfun
))
4280 /* Currently SET is the only monadic value for CODE, all
4281 the rest are diadic. */
4282 if (TARGET_USE_MOVT
)
4283 arm_emit_movpair (target
, GEN_INT (val
));
4285 emit_set_insn (target
, GEN_INT (val
));
4291 rtx temp
= subtargets
? gen_reg_rtx (mode
) : target
;
4293 if (TARGET_USE_MOVT
)
4294 arm_emit_movpair (temp
, GEN_INT (val
));
4296 emit_set_insn (temp
, GEN_INT (val
));
4298 /* For MINUS, the value is subtracted from, since we never
4299 have subtraction of a constant. */
4301 emit_set_insn (target
, gen_rtx_MINUS (mode
, temp
, source
));
4303 emit_set_insn (target
,
4304 gen_rtx_fmt_ee (code
, mode
, source
, temp
));
4310 return arm_gen_constant (code
, mode
, cond
, val
, target
, source
, subtargets
,
4314 /* Return a sequence of integers, in RETURN_SEQUENCE that fit into
4315 ARM/THUMB2 immediates, and add up to VAL.
4316 Thr function return value gives the number of insns required. */
4318 optimal_immediate_sequence (enum rtx_code code
, unsigned HOST_WIDE_INT val
,
4319 struct four_ints
*return_sequence
)
4321 int best_consecutive_zeros
= 0;
4325 struct four_ints tmp_sequence
;
4327 /* If we aren't targeting ARM, the best place to start is always at
4328 the bottom, otherwise look more closely. */
4331 for (i
= 0; i
< 32; i
+= 2)
4333 int consecutive_zeros
= 0;
4335 if (!(val
& (3 << i
)))
4337 while ((i
< 32) && !(val
& (3 << i
)))
4339 consecutive_zeros
+= 2;
4342 if (consecutive_zeros
> best_consecutive_zeros
)
4344 best_consecutive_zeros
= consecutive_zeros
;
4345 best_start
= i
- consecutive_zeros
;
4352 /* So long as it won't require any more insns to do so, it's
4353 desirable to emit a small constant (in bits 0...9) in the last
4354 insn. This way there is more chance that it can be combined with
4355 a later addressing insn to form a pre-indexed load or store
4356 operation. Consider:
4358 *((volatile int *)0xe0000100) = 1;
4359 *((volatile int *)0xe0000110) = 2;
4361 We want this to wind up as:
4365 str rB, [rA, #0x100]
4367 str rB, [rA, #0x110]
4369 rather than having to synthesize both large constants from scratch.
4371 Therefore, we calculate how many insns would be required to emit
4372 the constant starting from `best_start', and also starting from
4373 zero (i.e. with bit 31 first to be output). If `best_start' doesn't
4374 yield a shorter sequence, we may as well use zero. */
4375 insns1
= optimal_immediate_sequence_1 (code
, val
, return_sequence
, best_start
);
4377 && ((HOST_WIDE_INT_1U
<< best_start
) < val
))
4379 insns2
= optimal_immediate_sequence_1 (code
, val
, &tmp_sequence
, 0);
4380 if (insns2
<= insns1
)
4382 *return_sequence
= tmp_sequence
;
4390 /* As for optimal_immediate_sequence, but starting at bit-position I. */
4392 optimal_immediate_sequence_1 (enum rtx_code code
, unsigned HOST_WIDE_INT val
,
4393 struct four_ints
*return_sequence
, int i
)
4395 int remainder
= val
& 0xffffffff;
4398 /* Try and find a way of doing the job in either two or three
4401 In ARM mode we can use 8-bit constants, rotated to any 2-bit aligned
4402 location. We start at position I. This may be the MSB, or
4403 optimial_immediate_sequence may have positioned it at the largest block
4404 of zeros that are aligned on a 2-bit boundary. We then fill up the temps,
4405 wrapping around to the top of the word when we drop off the bottom.
4406 In the worst case this code should produce no more than four insns.
4408 In Thumb2 mode, we can use 32/16-bit replicated constants, and 8-bit
4409 constants, shifted to any arbitrary location. We should always start
4414 unsigned int b1
, b2
, b3
, b4
;
4415 unsigned HOST_WIDE_INT result
;
4418 gcc_assert (insns
< 4);
4423 /* First, find the next normal 12/8-bit shifted/rotated immediate. */
4424 if (remainder
& ((TARGET_ARM
? (3 << (i
- 2)) : (1 << (i
- 1)))))
4427 if (i
<= 12 && TARGET_THUMB2
&& code
== PLUS
)
4428 /* We can use addw/subw for the last 12 bits. */
4432 /* Use an 8-bit shifted/rotated immediate. */
4436 result
= remainder
& ((0x0ff << end
)
4437 | ((i
< end
) ? (0xff >> (32 - end
))
4444 /* Arm allows rotates by a multiple of two. Thumb-2 allows
4445 arbitrary shifts. */
4446 i
-= TARGET_ARM
? 2 : 1;
4450 /* Next, see if we can do a better job with a thumb2 replicated
4453 We do it this way around to catch the cases like 0x01F001E0 where
4454 two 8-bit immediates would work, but a replicated constant would
4457 TODO: 16-bit constants that don't clear all the bits, but still win.
4458 TODO: Arithmetic splitting for set/add/sub, rather than bitwise. */
4461 b1
= (remainder
& 0xff000000) >> 24;
4462 b2
= (remainder
& 0x00ff0000) >> 16;
4463 b3
= (remainder
& 0x0000ff00) >> 8;
4464 b4
= remainder
& 0xff;
4468 /* The 8-bit immediate already found clears b1 (and maybe b2),
4469 but must leave b3 and b4 alone. */
4471 /* First try to find a 32-bit replicated constant that clears
4472 almost everything. We can assume that we can't do it in one,
4473 or else we wouldn't be here. */
4474 unsigned int tmp
= b1
& b2
& b3
& b4
;
4475 unsigned int tmp2
= tmp
+ (tmp
<< 8) + (tmp
<< 16)
4477 unsigned int matching_bytes
= (tmp
== b1
) + (tmp
== b2
)
4478 + (tmp
== b3
) + (tmp
== b4
);
4480 && (matching_bytes
>= 3
4481 || (matching_bytes
== 2
4482 && const_ok_for_op (remainder
& ~tmp2
, code
))))
4484 /* At least 3 of the bytes match, and the fourth has at
4485 least as many bits set, or two of the bytes match
4486 and it will only require one more insn to finish. */
4494 /* Second, try to find a 16-bit replicated constant that can
4495 leave three of the bytes clear. If b2 or b4 is already
4496 zero, then we can. If the 8-bit from above would not
4497 clear b2 anyway, then we still win. */
4498 else if (b1
== b3
&& (!b2
|| !b4
4499 || (remainder
& 0x00ff0000 & ~result
)))
4501 result
= remainder
& 0xff00ff00;
4507 /* The 8-bit immediate already found clears b2 (and maybe b3)
4508 and we don't get here unless b1 is alredy clear, but it will
4509 leave b4 unchanged. */
4511 /* If we can clear b2 and b4 at once, then we win, since the
4512 8-bits couldn't possibly reach that far. */
4515 result
= remainder
& 0x00ff00ff;
4521 return_sequence
->i
[insns
++] = result
;
4522 remainder
&= ~result
;
4524 if (code
== SET
|| code
== MINUS
)
4532 /* Emit an instruction with the indicated PATTERN. If COND is
4533 non-NULL, conditionalize the execution of the instruction on COND
4537 emit_constant_insn (rtx cond
, rtx pattern
)
4540 pattern
= gen_rtx_COND_EXEC (VOIDmode
, copy_rtx (cond
), pattern
);
4541 emit_insn (pattern
);
4544 /* As above, but extra parameter GENERATE which, if clear, suppresses
4548 arm_gen_constant (enum rtx_code code
, machine_mode mode
, rtx cond
,
4549 unsigned HOST_WIDE_INT val
, rtx target
, rtx source
,
4550 int subtargets
, int generate
)
4554 int final_invert
= 0;
4556 int set_sign_bit_copies
= 0;
4557 int clear_sign_bit_copies
= 0;
4558 int clear_zero_bit_copies
= 0;
4559 int set_zero_bit_copies
= 0;
4560 int insns
= 0, neg_insns
, inv_insns
;
4561 unsigned HOST_WIDE_INT temp1
, temp2
;
4562 unsigned HOST_WIDE_INT remainder
= val
& 0xffffffff;
4563 struct four_ints
*immediates
;
4564 struct four_ints pos_immediates
, neg_immediates
, inv_immediates
;
4566 /* Find out which operations are safe for a given CODE. Also do a quick
4567 check for degenerate cases; these can occur when DImode operations
4580 if (remainder
== 0xffffffff)
4583 emit_constant_insn (cond
,
4584 gen_rtx_SET (target
,
4585 GEN_INT (ARM_SIGN_EXTEND (val
))));
4591 if (reload_completed
&& rtx_equal_p (target
, source
))
4595 emit_constant_insn (cond
, gen_rtx_SET (target
, source
));
4604 emit_constant_insn (cond
, gen_rtx_SET (target
, const0_rtx
));
4607 if (remainder
== 0xffffffff)
4609 if (reload_completed
&& rtx_equal_p (target
, source
))
4612 emit_constant_insn (cond
, gen_rtx_SET (target
, source
));
4621 if (reload_completed
&& rtx_equal_p (target
, source
))
4624 emit_constant_insn (cond
, gen_rtx_SET (target
, source
));
4628 if (remainder
== 0xffffffff)
4631 emit_constant_insn (cond
,
4632 gen_rtx_SET (target
,
4633 gen_rtx_NOT (mode
, source
)));
4640 /* We treat MINUS as (val - source), since (source - val) is always
4641 passed as (source + (-val)). */
4645 emit_constant_insn (cond
,
4646 gen_rtx_SET (target
,
4647 gen_rtx_NEG (mode
, source
)));
4650 if (const_ok_for_arm (val
))
4653 emit_constant_insn (cond
,
4654 gen_rtx_SET (target
,
4655 gen_rtx_MINUS (mode
, GEN_INT (val
),
4666 /* If we can do it in one insn get out quickly. */
4667 if (const_ok_for_op (val
, code
))
4670 emit_constant_insn (cond
,
4671 gen_rtx_SET (target
,
4673 ? gen_rtx_fmt_ee (code
, mode
, source
,
4679 /* On targets with UXTH/UBFX, we can deal with AND (2^N)-1 in a single
4681 if (code
== AND
&& (i
= exact_log2 (remainder
+ 1)) > 0
4682 && (arm_arch_thumb2
|| (i
== 16 && arm_arch6
&& mode
== SImode
)))
4686 if (mode
== SImode
&& i
== 16)
4687 /* Use UXTH in preference to UBFX, since on Thumb2 it's a
4689 emit_constant_insn (cond
,
4690 gen_zero_extendhisi2
4691 (target
, gen_lowpart (HImode
, source
)));
4693 /* Extz only supports SImode, but we can coerce the operands
4695 emit_constant_insn (cond
,
4696 gen_extzv_t2 (gen_lowpart (SImode
, target
),
4697 gen_lowpart (SImode
, source
),
4698 GEN_INT (i
), const0_rtx
));
4704 /* Calculate a few attributes that may be useful for specific
4706 /* Count number of leading zeros. */
4707 for (i
= 31; i
>= 0; i
--)
4709 if ((remainder
& (1 << i
)) == 0)
4710 clear_sign_bit_copies
++;
4715 /* Count number of leading 1's. */
4716 for (i
= 31; i
>= 0; i
--)
4718 if ((remainder
& (1 << i
)) != 0)
4719 set_sign_bit_copies
++;
4724 /* Count number of trailing zero's. */
4725 for (i
= 0; i
<= 31; i
++)
4727 if ((remainder
& (1 << i
)) == 0)
4728 clear_zero_bit_copies
++;
4733 /* Count number of trailing 1's. */
4734 for (i
= 0; i
<= 31; i
++)
4736 if ((remainder
& (1 << i
)) != 0)
4737 set_zero_bit_copies
++;
4745 /* See if we can do this by sign_extending a constant that is known
4746 to be negative. This is a good, way of doing it, since the shift
4747 may well merge into a subsequent insn. */
4748 if (set_sign_bit_copies
> 1)
4750 if (const_ok_for_arm
4751 (temp1
= ARM_SIGN_EXTEND (remainder
4752 << (set_sign_bit_copies
- 1))))
4756 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
4757 emit_constant_insn (cond
,
4758 gen_rtx_SET (new_src
, GEN_INT (temp1
)));
4759 emit_constant_insn (cond
,
4760 gen_ashrsi3 (target
, new_src
,
4761 GEN_INT (set_sign_bit_copies
- 1)));
4765 /* For an inverted constant, we will need to set the low bits,
4766 these will be shifted out of harm's way. */
4767 temp1
|= (1 << (set_sign_bit_copies
- 1)) - 1;
4768 if (const_ok_for_arm (~temp1
))
4772 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
4773 emit_constant_insn (cond
,
4774 gen_rtx_SET (new_src
, GEN_INT (temp1
)));
4775 emit_constant_insn (cond
,
4776 gen_ashrsi3 (target
, new_src
,
4777 GEN_INT (set_sign_bit_copies
- 1)));
4783 /* See if we can calculate the value as the difference between two
4784 valid immediates. */
4785 if (clear_sign_bit_copies
+ clear_zero_bit_copies
<= 16)
4787 int topshift
= clear_sign_bit_copies
& ~1;
4789 temp1
= ARM_SIGN_EXTEND ((remainder
+ (0x00800000 >> topshift
))
4790 & (0xff000000 >> topshift
));
4792 /* If temp1 is zero, then that means the 9 most significant
4793 bits of remainder were 1 and we've caused it to overflow.
4794 When topshift is 0 we don't need to do anything since we
4795 can borrow from 'bit 32'. */
4796 if (temp1
== 0 && topshift
!= 0)
4797 temp1
= 0x80000000 >> (topshift
- 1);
4799 temp2
= ARM_SIGN_EXTEND (temp1
- remainder
);
4801 if (const_ok_for_arm (temp2
))
4805 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
4806 emit_constant_insn (cond
,
4807 gen_rtx_SET (new_src
, GEN_INT (temp1
)));
4808 emit_constant_insn (cond
,
4809 gen_addsi3 (target
, new_src
,
4817 /* See if we can generate this by setting the bottom (or the top)
4818 16 bits, and then shifting these into the other half of the
4819 word. We only look for the simplest cases, to do more would cost
4820 too much. Be careful, however, not to generate this when the
4821 alternative would take fewer insns. */
4822 if (val
& 0xffff0000)
4824 temp1
= remainder
& 0xffff0000;
4825 temp2
= remainder
& 0x0000ffff;
4827 /* Overlaps outside this range are best done using other methods. */
4828 for (i
= 9; i
< 24; i
++)
4830 if ((((temp2
| (temp2
<< i
)) & 0xffffffff) == remainder
)
4831 && !const_ok_for_arm (temp2
))
4833 rtx new_src
= (subtargets
4834 ? (generate
? gen_reg_rtx (mode
) : NULL_RTX
)
4836 insns
= arm_gen_constant (code
, mode
, cond
, temp2
, new_src
,
4837 source
, subtargets
, generate
);
4845 gen_rtx_ASHIFT (mode
, source
,
4852 /* Don't duplicate cases already considered. */
4853 for (i
= 17; i
< 24; i
++)
4855 if (((temp1
| (temp1
>> i
)) == remainder
)
4856 && !const_ok_for_arm (temp1
))
4858 rtx new_src
= (subtargets
4859 ? (generate
? gen_reg_rtx (mode
) : NULL_RTX
)
4861 insns
= arm_gen_constant (code
, mode
, cond
, temp1
, new_src
,
4862 source
, subtargets
, generate
);
4867 gen_rtx_SET (target
,
4870 gen_rtx_LSHIFTRT (mode
, source
,
4881 /* If we have IOR or XOR, and the constant can be loaded in a
4882 single instruction, and we can find a temporary to put it in,
4883 then this can be done in two instructions instead of 3-4. */
4885 /* TARGET can't be NULL if SUBTARGETS is 0 */
4886 || (reload_completed
&& !reg_mentioned_p (target
, source
)))
4888 if (const_ok_for_arm (ARM_SIGN_EXTEND (~val
)))
4892 rtx sub
= subtargets
? gen_reg_rtx (mode
) : target
;
4894 emit_constant_insn (cond
,
4895 gen_rtx_SET (sub
, GEN_INT (val
)));
4896 emit_constant_insn (cond
,
4897 gen_rtx_SET (target
,
4898 gen_rtx_fmt_ee (code
, mode
,
4909 x = y | constant ( which is composed of set_sign_bit_copies of leading 1s
4910 and the remainder 0s for e.g. 0xfff00000)
4911 x = ~(~(y ashift set_sign_bit_copies) lshiftrt set_sign_bit_copies)
4913 This can be done in 2 instructions by using shifts with mov or mvn.
4918 mvn r0, r0, lsr #12 */
4919 if (set_sign_bit_copies
> 8
4920 && (val
& (HOST_WIDE_INT_M1U
<< (32 - set_sign_bit_copies
))) == val
)
4924 rtx sub
= subtargets
? gen_reg_rtx (mode
) : target
;
4925 rtx shift
= GEN_INT (set_sign_bit_copies
);
4931 gen_rtx_ASHIFT (mode
,
4936 gen_rtx_SET (target
,
4938 gen_rtx_LSHIFTRT (mode
, sub
,
4945 x = y | constant (which has set_zero_bit_copies number of trailing ones).
4947 x = ~((~y lshiftrt set_zero_bit_copies) ashift set_zero_bit_copies).
4949 For eg. r0 = r0 | 0xfff
4954 if (set_zero_bit_copies
> 8
4955 && (remainder
& ((1 << set_zero_bit_copies
) - 1)) == remainder
)
4959 rtx sub
= subtargets
? gen_reg_rtx (mode
) : target
;
4960 rtx shift
= GEN_INT (set_zero_bit_copies
);
4966 gen_rtx_LSHIFTRT (mode
,
4971 gen_rtx_SET (target
,
4973 gen_rtx_ASHIFT (mode
, sub
,
4979 /* This will never be reached for Thumb2 because orn is a valid
4980 instruction. This is for Thumb1 and the ARM 32 bit cases.
4982 x = y | constant (such that ~constant is a valid constant)
4984 x = ~(~y & ~constant).
4986 if (const_ok_for_arm (temp1
= ARM_SIGN_EXTEND (~val
)))
4990 rtx sub
= subtargets
? gen_reg_rtx (mode
) : target
;
4991 emit_constant_insn (cond
,
4993 gen_rtx_NOT (mode
, source
)));
4996 sub
= gen_reg_rtx (mode
);
4997 emit_constant_insn (cond
,
4999 gen_rtx_AND (mode
, source
,
5001 emit_constant_insn (cond
,
5002 gen_rtx_SET (target
,
5003 gen_rtx_NOT (mode
, sub
)));
5010 /* See if two shifts will do 2 or more insn's worth of work. */
5011 if (clear_sign_bit_copies
>= 16 && clear_sign_bit_copies
< 24)
5013 HOST_WIDE_INT shift_mask
= ((0xffffffff
5014 << (32 - clear_sign_bit_copies
))
5017 if ((remainder
| shift_mask
) != 0xffffffff)
5019 HOST_WIDE_INT new_val
5020 = ARM_SIGN_EXTEND (remainder
| shift_mask
);
5024 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
5025 insns
= arm_gen_constant (AND
, SImode
, cond
, new_val
,
5026 new_src
, source
, subtargets
, 1);
5031 rtx targ
= subtargets
? NULL_RTX
: target
;
5032 insns
= arm_gen_constant (AND
, mode
, cond
, new_val
,
5033 targ
, source
, subtargets
, 0);
5039 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
5040 rtx shift
= GEN_INT (clear_sign_bit_copies
);
5042 emit_insn (gen_ashlsi3 (new_src
, source
, shift
));
5043 emit_insn (gen_lshrsi3 (target
, new_src
, shift
));
5049 if (clear_zero_bit_copies
>= 16 && clear_zero_bit_copies
< 24)
5051 HOST_WIDE_INT shift_mask
= (1 << clear_zero_bit_copies
) - 1;
5053 if ((remainder
| shift_mask
) != 0xffffffff)
5055 HOST_WIDE_INT new_val
5056 = ARM_SIGN_EXTEND (remainder
| shift_mask
);
5059 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
5061 insns
= arm_gen_constant (AND
, mode
, cond
, new_val
,
5062 new_src
, source
, subtargets
, 1);
5067 rtx targ
= subtargets
? NULL_RTX
: target
;
5069 insns
= arm_gen_constant (AND
, mode
, cond
, new_val
,
5070 targ
, source
, subtargets
, 0);
5076 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
5077 rtx shift
= GEN_INT (clear_zero_bit_copies
);
5079 emit_insn (gen_lshrsi3 (new_src
, source
, shift
));
5080 emit_insn (gen_ashlsi3 (target
, new_src
, shift
));
5092 /* Calculate what the instruction sequences would be if we generated it
5093 normally, negated, or inverted. */
5095 /* AND cannot be split into multiple insns, so invert and use BIC. */
5098 insns
= optimal_immediate_sequence (code
, remainder
, &pos_immediates
);
5101 neg_insns
= optimal_immediate_sequence (code
, (-remainder
) & 0xffffffff,
5106 if (can_invert
|| final_invert
)
5107 inv_insns
= optimal_immediate_sequence (code
, remainder
^ 0xffffffff,
5112 immediates
= &pos_immediates
;
5114 /* Is the negated immediate sequence more efficient? */
5115 if (neg_insns
< insns
&& neg_insns
<= inv_insns
)
5118 immediates
= &neg_immediates
;
5123 /* Is the inverted immediate sequence more efficient?
5124 We must allow for an extra NOT instruction for XOR operations, although
5125 there is some chance that the final 'mvn' will get optimized later. */
5126 if ((inv_insns
+ 1) < insns
|| (!final_invert
&& inv_insns
< insns
))
5129 immediates
= &inv_immediates
;
5137 /* Now output the chosen sequence as instructions. */
5140 for (i
= 0; i
< insns
; i
++)
5142 rtx new_src
, temp1_rtx
;
5144 temp1
= immediates
->i
[i
];
5146 if (code
== SET
|| code
== MINUS
)
5147 new_src
= (subtargets
? gen_reg_rtx (mode
) : target
);
5148 else if ((final_invert
|| i
< (insns
- 1)) && subtargets
)
5149 new_src
= gen_reg_rtx (mode
);
5155 else if (can_negate
)
5158 temp1
= trunc_int_for_mode (temp1
, mode
);
5159 temp1_rtx
= GEN_INT (temp1
);
5163 else if (code
== MINUS
)
5164 temp1_rtx
= gen_rtx_MINUS (mode
, temp1_rtx
, source
);
5166 temp1_rtx
= gen_rtx_fmt_ee (code
, mode
, source
, temp1_rtx
);
5168 emit_constant_insn (cond
, gen_rtx_SET (new_src
, temp1_rtx
));
5173 can_negate
= can_invert
;
5177 else if (code
== MINUS
)
5185 emit_constant_insn (cond
, gen_rtx_SET (target
,
5186 gen_rtx_NOT (mode
, source
)));
5193 /* Canonicalize a comparison so that we are more likely to recognize it.
5194 This can be done for a few constant compares, where we can make the
5195 immediate value easier to load. */
5198 arm_canonicalize_comparison (int *code
, rtx
*op0
, rtx
*op1
,
5199 bool op0_preserve_value
)
5202 unsigned HOST_WIDE_INT i
, maxval
;
5204 mode
= GET_MODE (*op0
);
5205 if (mode
== VOIDmode
)
5206 mode
= GET_MODE (*op1
);
5208 maxval
= (HOST_WIDE_INT_1U
<< (GET_MODE_BITSIZE (mode
) - 1)) - 1;
5210 /* For DImode, we have GE/LT/GEU/LTU comparisons. In ARM mode
5211 we can also use cmp/cmpeq for GTU/LEU. GT/LE must be either
5212 reversed or (for constant OP1) adjusted to GE/LT. Similarly
5213 for GTU/LEU in Thumb mode. */
5217 if (*code
== GT
|| *code
== LE
5218 || (!TARGET_ARM
&& (*code
== GTU
|| *code
== LEU
)))
5220 /* Missing comparison. First try to use an available
5222 if (CONST_INT_P (*op1
))
5230 && arm_const_double_by_immediates (GEN_INT (i
+ 1)))
5232 *op1
= GEN_INT (i
+ 1);
5233 *code
= *code
== GT
? GE
: LT
;
5239 if (i
!= ~((unsigned HOST_WIDE_INT
) 0)
5240 && arm_const_double_by_immediates (GEN_INT (i
+ 1)))
5242 *op1
= GEN_INT (i
+ 1);
5243 *code
= *code
== GTU
? GEU
: LTU
;
5252 /* If that did not work, reverse the condition. */
5253 if (!op0_preserve_value
)
5255 std::swap (*op0
, *op1
);
5256 *code
= (int)swap_condition ((enum rtx_code
)*code
);
5262 /* If *op0 is (zero_extend:SI (subreg:QI (reg:SI) 0)) and comparing
5263 with const0_rtx, change it to (and:SI (reg:SI) (const_int 255)),
5264 to facilitate possible combining with a cmp into 'ands'. */
5266 && GET_CODE (*op0
) == ZERO_EXTEND
5267 && GET_CODE (XEXP (*op0
, 0)) == SUBREG
5268 && GET_MODE (XEXP (*op0
, 0)) == QImode
5269 && GET_MODE (SUBREG_REG (XEXP (*op0
, 0))) == SImode
5270 && subreg_lowpart_p (XEXP (*op0
, 0))
5271 && *op1
== const0_rtx
)
5272 *op0
= gen_rtx_AND (SImode
, SUBREG_REG (XEXP (*op0
, 0)),
5275 /* Comparisons smaller than DImode. Only adjust comparisons against
5276 an out-of-range constant. */
5277 if (!CONST_INT_P (*op1
)
5278 || const_ok_for_arm (INTVAL (*op1
))
5279 || const_ok_for_arm (- INTVAL (*op1
)))
5293 && (const_ok_for_arm (i
+ 1) || const_ok_for_arm (-(i
+ 1))))
5295 *op1
= GEN_INT (ARM_SIGN_EXTEND (i
+ 1));
5296 *code
= *code
== GT
? GE
: LT
;
5304 && (const_ok_for_arm (i
- 1) || const_ok_for_arm (-(i
- 1))))
5306 *op1
= GEN_INT (i
- 1);
5307 *code
= *code
== GE
? GT
: LE
;
5314 if (i
!= ~((unsigned HOST_WIDE_INT
) 0)
5315 && (const_ok_for_arm (i
+ 1) || const_ok_for_arm (-(i
+ 1))))
5317 *op1
= GEN_INT (ARM_SIGN_EXTEND (i
+ 1));
5318 *code
= *code
== GTU
? GEU
: LTU
;
5326 && (const_ok_for_arm (i
- 1) || const_ok_for_arm (-(i
- 1))))
5328 *op1
= GEN_INT (i
- 1);
5329 *code
= *code
== GEU
? GTU
: LEU
;
5340 /* Define how to find the value returned by a function. */
5343 arm_function_value(const_tree type
, const_tree func
,
5344 bool outgoing ATTRIBUTE_UNUSED
)
5347 int unsignedp ATTRIBUTE_UNUSED
;
5348 rtx r ATTRIBUTE_UNUSED
;
5350 mode
= TYPE_MODE (type
);
5352 if (TARGET_AAPCS_BASED
)
5353 return aapcs_allocate_return_reg (mode
, type
, func
);
5355 /* Promote integer types. */
5356 if (INTEGRAL_TYPE_P (type
))
5357 mode
= arm_promote_function_mode (type
, mode
, &unsignedp
, func
, 1);
5359 /* Promotes small structs returned in a register to full-word size
5360 for big-endian AAPCS. */
5361 if (arm_return_in_msb (type
))
5363 HOST_WIDE_INT size
= int_size_in_bytes (type
);
5364 if (size
% UNITS_PER_WORD
!= 0)
5366 size
+= UNITS_PER_WORD
- size
% UNITS_PER_WORD
;
5367 mode
= int_mode_for_size (size
* BITS_PER_UNIT
, 0).require ();
5371 return arm_libcall_value_1 (mode
);
5374 /* libcall hashtable helpers. */
5376 struct libcall_hasher
: nofree_ptr_hash
<const rtx_def
>
5378 static inline hashval_t
hash (const rtx_def
*);
5379 static inline bool equal (const rtx_def
*, const rtx_def
*);
5380 static inline void remove (rtx_def
*);
5384 libcall_hasher::equal (const rtx_def
*p1
, const rtx_def
*p2
)
5386 return rtx_equal_p (p1
, p2
);
5390 libcall_hasher::hash (const rtx_def
*p1
)
5392 return hash_rtx (p1
, VOIDmode
, NULL
, NULL
, FALSE
);
5395 typedef hash_table
<libcall_hasher
> libcall_table_type
;
5398 add_libcall (libcall_table_type
*htab
, rtx libcall
)
5400 *htab
->find_slot (libcall
, INSERT
) = libcall
;
5404 arm_libcall_uses_aapcs_base (const_rtx libcall
)
5406 static bool init_done
= false;
5407 static libcall_table_type
*libcall_htab
= NULL
;
5413 libcall_htab
= new libcall_table_type (31);
5414 add_libcall (libcall_htab
,
5415 convert_optab_libfunc (sfloat_optab
, SFmode
, SImode
));
5416 add_libcall (libcall_htab
,
5417 convert_optab_libfunc (sfloat_optab
, DFmode
, SImode
));
5418 add_libcall (libcall_htab
,
5419 convert_optab_libfunc (sfloat_optab
, SFmode
, DImode
));
5420 add_libcall (libcall_htab
,
5421 convert_optab_libfunc (sfloat_optab
, DFmode
, DImode
));
5423 add_libcall (libcall_htab
,
5424 convert_optab_libfunc (ufloat_optab
, SFmode
, SImode
));
5425 add_libcall (libcall_htab
,
5426 convert_optab_libfunc (ufloat_optab
, DFmode
, SImode
));
5427 add_libcall (libcall_htab
,
5428 convert_optab_libfunc (ufloat_optab
, SFmode
, DImode
));
5429 add_libcall (libcall_htab
,
5430 convert_optab_libfunc (ufloat_optab
, DFmode
, DImode
));
5432 add_libcall (libcall_htab
,
5433 convert_optab_libfunc (sext_optab
, SFmode
, HFmode
));
5434 add_libcall (libcall_htab
,
5435 convert_optab_libfunc (trunc_optab
, HFmode
, SFmode
));
5436 add_libcall (libcall_htab
,
5437 convert_optab_libfunc (sfix_optab
, SImode
, DFmode
));
5438 add_libcall (libcall_htab
,
5439 convert_optab_libfunc (ufix_optab
, SImode
, DFmode
));
5440 add_libcall (libcall_htab
,
5441 convert_optab_libfunc (sfix_optab
, DImode
, DFmode
));
5442 add_libcall (libcall_htab
,
5443 convert_optab_libfunc (ufix_optab
, DImode
, DFmode
));
5444 add_libcall (libcall_htab
,
5445 convert_optab_libfunc (sfix_optab
, DImode
, SFmode
));
5446 add_libcall (libcall_htab
,
5447 convert_optab_libfunc (ufix_optab
, DImode
, SFmode
));
5449 /* Values from double-precision helper functions are returned in core
5450 registers if the selected core only supports single-precision
5451 arithmetic, even if we are using the hard-float ABI. The same is
5452 true for single-precision helpers, but we will never be using the
5453 hard-float ABI on a CPU which doesn't support single-precision
5454 operations in hardware. */
5455 add_libcall (libcall_htab
, optab_libfunc (add_optab
, DFmode
));
5456 add_libcall (libcall_htab
, optab_libfunc (sdiv_optab
, DFmode
));
5457 add_libcall (libcall_htab
, optab_libfunc (smul_optab
, DFmode
));
5458 add_libcall (libcall_htab
, optab_libfunc (neg_optab
, DFmode
));
5459 add_libcall (libcall_htab
, optab_libfunc (sub_optab
, DFmode
));
5460 add_libcall (libcall_htab
, optab_libfunc (eq_optab
, DFmode
));
5461 add_libcall (libcall_htab
, optab_libfunc (lt_optab
, DFmode
));
5462 add_libcall (libcall_htab
, optab_libfunc (le_optab
, DFmode
));
5463 add_libcall (libcall_htab
, optab_libfunc (ge_optab
, DFmode
));
5464 add_libcall (libcall_htab
, optab_libfunc (gt_optab
, DFmode
));
5465 add_libcall (libcall_htab
, optab_libfunc (unord_optab
, DFmode
));
5466 add_libcall (libcall_htab
, convert_optab_libfunc (sext_optab
, DFmode
,
5468 add_libcall (libcall_htab
, convert_optab_libfunc (trunc_optab
, SFmode
,
5470 add_libcall (libcall_htab
,
5471 convert_optab_libfunc (trunc_optab
, HFmode
, DFmode
));
5474 return libcall
&& libcall_htab
->find (libcall
) != NULL
;
5478 arm_libcall_value_1 (machine_mode mode
)
5480 if (TARGET_AAPCS_BASED
)
5481 return aapcs_libcall_value (mode
);
5482 else if (TARGET_IWMMXT_ABI
5483 && arm_vector_mode_supported_p (mode
))
5484 return gen_rtx_REG (mode
, FIRST_IWMMXT_REGNUM
);
5486 return gen_rtx_REG (mode
, ARG_REGISTER (1));
5489 /* Define how to find the value returned by a library function
5490 assuming the value has mode MODE. */
5493 arm_libcall_value (machine_mode mode
, const_rtx libcall
)
5495 if (TARGET_AAPCS_BASED
&& arm_pcs_default
!= ARM_PCS_AAPCS
5496 && GET_MODE_CLASS (mode
) == MODE_FLOAT
)
5498 /* The following libcalls return their result in integer registers,
5499 even though they return a floating point value. */
5500 if (arm_libcall_uses_aapcs_base (libcall
))
5501 return gen_rtx_REG (mode
, ARG_REGISTER(1));
5505 return arm_libcall_value_1 (mode
);
5508 /* Implement TARGET_FUNCTION_VALUE_REGNO_P. */
5511 arm_function_value_regno_p (const unsigned int regno
)
5513 if (regno
== ARG_REGISTER (1)
5515 && TARGET_AAPCS_BASED
5516 && TARGET_HARD_FLOAT
5517 && regno
== FIRST_VFP_REGNUM
)
5518 || (TARGET_IWMMXT_ABI
5519 && regno
== FIRST_IWMMXT_REGNUM
))
5525 /* Determine the amount of memory needed to store the possible return
5526 registers of an untyped call. */
5528 arm_apply_result_size (void)
5534 if (TARGET_HARD_FLOAT_ABI
)
5536 if (TARGET_IWMMXT_ABI
)
5543 /* Decide whether TYPE should be returned in memory (true)
5544 or in a register (false). FNTYPE is the type of the function making
5547 arm_return_in_memory (const_tree type
, const_tree fntype
)
5551 size
= int_size_in_bytes (type
); /* Negative if not fixed size. */
5553 if (TARGET_AAPCS_BASED
)
5555 /* Simple, non-aggregate types (ie not including vectors and
5556 complex) are always returned in a register (or registers).
5557 We don't care about which register here, so we can short-cut
5558 some of the detail. */
5559 if (!AGGREGATE_TYPE_P (type
)
5560 && TREE_CODE (type
) != VECTOR_TYPE
5561 && TREE_CODE (type
) != COMPLEX_TYPE
)
5564 /* Any return value that is no larger than one word can be
5566 if (((unsigned HOST_WIDE_INT
) size
) <= UNITS_PER_WORD
)
5569 /* Check any available co-processors to see if they accept the
5570 type as a register candidate (VFP, for example, can return
5571 some aggregates in consecutive registers). These aren't
5572 available if the call is variadic. */
5573 if (aapcs_select_return_coproc (type
, fntype
) >= 0)
5576 /* Vector values should be returned using ARM registers, not
5577 memory (unless they're over 16 bytes, which will break since
5578 we only have four call-clobbered registers to play with). */
5579 if (TREE_CODE (type
) == VECTOR_TYPE
)
5580 return (size
< 0 || size
> (4 * UNITS_PER_WORD
));
5582 /* The rest go in memory. */
5586 if (TREE_CODE (type
) == VECTOR_TYPE
)
5587 return (size
< 0 || size
> (4 * UNITS_PER_WORD
));
5589 if (!AGGREGATE_TYPE_P (type
) &&
5590 (TREE_CODE (type
) != VECTOR_TYPE
))
5591 /* All simple types are returned in registers. */
5594 if (arm_abi
!= ARM_ABI_APCS
)
5596 /* ATPCS and later return aggregate types in memory only if they are
5597 larger than a word (or are variable size). */
5598 return (size
< 0 || size
> UNITS_PER_WORD
);
5601 /* For the arm-wince targets we choose to be compatible with Microsoft's
5602 ARM and Thumb compilers, which always return aggregates in memory. */
5604 /* All structures/unions bigger than one word are returned in memory.
5605 Also catch the case where int_size_in_bytes returns -1. In this case
5606 the aggregate is either huge or of variable size, and in either case
5607 we will want to return it via memory and not in a register. */
5608 if (size
< 0 || size
> UNITS_PER_WORD
)
5611 if (TREE_CODE (type
) == RECORD_TYPE
)
5615 /* For a struct the APCS says that we only return in a register
5616 if the type is 'integer like' and every addressable element
5617 has an offset of zero. For practical purposes this means
5618 that the structure can have at most one non bit-field element
5619 and that this element must be the first one in the structure. */
5621 /* Find the first field, ignoring non FIELD_DECL things which will
5622 have been created by C++. */
5623 for (field
= TYPE_FIELDS (type
);
5624 field
&& TREE_CODE (field
) != FIELD_DECL
;
5625 field
= DECL_CHAIN (field
))
5629 return false; /* An empty structure. Allowed by an extension to ANSI C. */
5631 /* Check that the first field is valid for returning in a register. */
5633 /* ... Floats are not allowed */
5634 if (FLOAT_TYPE_P (TREE_TYPE (field
)))
5637 /* ... Aggregates that are not themselves valid for returning in
5638 a register are not allowed. */
5639 if (arm_return_in_memory (TREE_TYPE (field
), NULL_TREE
))
5642 /* Now check the remaining fields, if any. Only bitfields are allowed,
5643 since they are not addressable. */
5644 for (field
= DECL_CHAIN (field
);
5646 field
= DECL_CHAIN (field
))
5648 if (TREE_CODE (field
) != FIELD_DECL
)
5651 if (!DECL_BIT_FIELD_TYPE (field
))
5658 if (TREE_CODE (type
) == UNION_TYPE
)
5662 /* Unions can be returned in registers if every element is
5663 integral, or can be returned in an integer register. */
5664 for (field
= TYPE_FIELDS (type
);
5666 field
= DECL_CHAIN (field
))
5668 if (TREE_CODE (field
) != FIELD_DECL
)
5671 if (FLOAT_TYPE_P (TREE_TYPE (field
)))
5674 if (arm_return_in_memory (TREE_TYPE (field
), NULL_TREE
))
5680 #endif /* not ARM_WINCE */
5682 /* Return all other types in memory. */
5686 const struct pcs_attribute_arg
5690 } pcs_attribute_args
[] =
5692 {"aapcs", ARM_PCS_AAPCS
},
5693 {"aapcs-vfp", ARM_PCS_AAPCS_VFP
},
5695 /* We could recognize these, but changes would be needed elsewhere
5696 * to implement them. */
5697 {"aapcs-iwmmxt", ARM_PCS_AAPCS_IWMMXT
},
5698 {"atpcs", ARM_PCS_ATPCS
},
5699 {"apcs", ARM_PCS_APCS
},
5701 {NULL
, ARM_PCS_UNKNOWN
}
5705 arm_pcs_from_attribute (tree attr
)
5707 const struct pcs_attribute_arg
*ptr
;
5710 /* Get the value of the argument. */
5711 if (TREE_VALUE (attr
) == NULL_TREE
5712 || TREE_CODE (TREE_VALUE (attr
)) != STRING_CST
)
5713 return ARM_PCS_UNKNOWN
;
5715 arg
= TREE_STRING_POINTER (TREE_VALUE (attr
));
5717 /* Check it against the list of known arguments. */
5718 for (ptr
= pcs_attribute_args
; ptr
->arg
!= NULL
; ptr
++)
5719 if (streq (arg
, ptr
->arg
))
5722 /* An unrecognized interrupt type. */
5723 return ARM_PCS_UNKNOWN
;
5726 /* Get the PCS variant to use for this call. TYPE is the function's type
5727 specification, DECL is the specific declartion. DECL may be null if
5728 the call could be indirect or if this is a library call. */
5730 arm_get_pcs_model (const_tree type
, const_tree decl
)
5732 bool user_convention
= false;
5733 enum arm_pcs user_pcs
= arm_pcs_default
;
5738 attr
= lookup_attribute ("pcs", TYPE_ATTRIBUTES (type
));
5741 user_pcs
= arm_pcs_from_attribute (TREE_VALUE (attr
));
5742 user_convention
= true;
5745 if (TARGET_AAPCS_BASED
)
5747 /* Detect varargs functions. These always use the base rules
5748 (no argument is ever a candidate for a co-processor
5750 bool base_rules
= stdarg_p (type
);
5752 if (user_convention
)
5754 if (user_pcs
> ARM_PCS_AAPCS_LOCAL
)
5755 sorry ("non-AAPCS derived PCS variant");
5756 else if (base_rules
&& user_pcs
!= ARM_PCS_AAPCS
)
5757 error ("variadic functions must use the base AAPCS variant");
5761 return ARM_PCS_AAPCS
;
5762 else if (user_convention
)
5764 else if (decl
&& flag_unit_at_a_time
)
5766 /* Local functions never leak outside this compilation unit,
5767 so we are free to use whatever conventions are
5769 /* FIXME: remove CONST_CAST_TREE when cgraph is constified. */
5770 cgraph_local_info
*i
= cgraph_node::local_info (CONST_CAST_TREE(decl
));
5772 return ARM_PCS_AAPCS_LOCAL
;
5775 else if (user_convention
&& user_pcs
!= arm_pcs_default
)
5776 sorry ("PCS variant");
5778 /* For everything else we use the target's default. */
5779 return arm_pcs_default
;
5784 aapcs_vfp_cum_init (CUMULATIVE_ARGS
*pcum ATTRIBUTE_UNUSED
,
5785 const_tree fntype ATTRIBUTE_UNUSED
,
5786 rtx libcall ATTRIBUTE_UNUSED
,
5787 const_tree fndecl ATTRIBUTE_UNUSED
)
5789 /* Record the unallocated VFP registers. */
5790 pcum
->aapcs_vfp_regs_free
= (1 << NUM_VFP_ARG_REGS
) - 1;
5791 pcum
->aapcs_vfp_reg_alloc
= 0;
5794 /* Walk down the type tree of TYPE counting consecutive base elements.
5795 If *MODEP is VOIDmode, then set it to the first valid floating point
5796 type. If a non-floating point type is found, or if a floating point
5797 type that doesn't match a non-VOIDmode *MODEP is found, then return -1,
5798 otherwise return the count in the sub-tree. */
5800 aapcs_vfp_sub_candidate (const_tree type
, machine_mode
*modep
)
5805 switch (TREE_CODE (type
))
5808 mode
= TYPE_MODE (type
);
5809 if (mode
!= DFmode
&& mode
!= SFmode
&& mode
!= HFmode
)
5812 if (*modep
== VOIDmode
)
5821 mode
= TYPE_MODE (TREE_TYPE (type
));
5822 if (mode
!= DFmode
&& mode
!= SFmode
)
5825 if (*modep
== VOIDmode
)
5834 /* Use V2SImode and V4SImode as representatives of all 64-bit
5835 and 128-bit vector types, whether or not those modes are
5836 supported with the present options. */
5837 size
= int_size_in_bytes (type
);
5850 if (*modep
== VOIDmode
)
5853 /* Vector modes are considered to be opaque: two vectors are
5854 equivalent for the purposes of being homogeneous aggregates
5855 if they are the same size. */
5864 tree index
= TYPE_DOMAIN (type
);
5866 /* Can't handle incomplete types nor sizes that are not
5868 if (!COMPLETE_TYPE_P (type
)
5869 || TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
5872 count
= aapcs_vfp_sub_candidate (TREE_TYPE (type
), modep
);
5875 || !TYPE_MAX_VALUE (index
)
5876 || !tree_fits_uhwi_p (TYPE_MAX_VALUE (index
))
5877 || !TYPE_MIN_VALUE (index
)
5878 || !tree_fits_uhwi_p (TYPE_MIN_VALUE (index
))
5882 count
*= (1 + tree_to_uhwi (TYPE_MAX_VALUE (index
))
5883 - tree_to_uhwi (TYPE_MIN_VALUE (index
)));
5885 /* There must be no padding. */
5886 if (wi::ne_p (TYPE_SIZE (type
), count
* GET_MODE_BITSIZE (*modep
)))
5898 /* Can't handle incomplete types nor sizes that are not
5900 if (!COMPLETE_TYPE_P (type
)
5901 || TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
5904 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
5906 if (TREE_CODE (field
) != FIELD_DECL
)
5909 sub_count
= aapcs_vfp_sub_candidate (TREE_TYPE (field
), modep
);
5915 /* There must be no padding. */
5916 if (wi::ne_p (TYPE_SIZE (type
), count
* GET_MODE_BITSIZE (*modep
)))
5923 case QUAL_UNION_TYPE
:
5925 /* These aren't very interesting except in a degenerate case. */
5930 /* Can't handle incomplete types nor sizes that are not
5932 if (!COMPLETE_TYPE_P (type
)
5933 || TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
5936 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
5938 if (TREE_CODE (field
) != FIELD_DECL
)
5941 sub_count
= aapcs_vfp_sub_candidate (TREE_TYPE (field
), modep
);
5944 count
= count
> sub_count
? count
: sub_count
;
5947 /* There must be no padding. */
5948 if (wi::ne_p (TYPE_SIZE (type
), count
* GET_MODE_BITSIZE (*modep
)))
5961 /* Return true if PCS_VARIANT should use VFP registers. */
5963 use_vfp_abi (enum arm_pcs pcs_variant
, bool is_double
)
5965 if (pcs_variant
== ARM_PCS_AAPCS_VFP
)
5967 static bool seen_thumb1_vfp
= false;
5969 if (TARGET_THUMB1
&& !seen_thumb1_vfp
)
5971 sorry ("Thumb-1 hard-float VFP ABI");
5972 /* sorry() is not immediately fatal, so only display this once. */
5973 seen_thumb1_vfp
= true;
5979 if (pcs_variant
!= ARM_PCS_AAPCS_LOCAL
)
5982 return (TARGET_32BIT
&& TARGET_HARD_FLOAT
&&
5983 (TARGET_VFP_DOUBLE
|| !is_double
));
5986 /* Return true if an argument whose type is TYPE, or mode is MODE, is
5987 suitable for passing or returning in VFP registers for the PCS
5988 variant selected. If it is, then *BASE_MODE is updated to contain
5989 a machine mode describing each element of the argument's type and
5990 *COUNT to hold the number of such elements. */
5992 aapcs_vfp_is_call_or_return_candidate (enum arm_pcs pcs_variant
,
5993 machine_mode mode
, const_tree type
,
5994 machine_mode
*base_mode
, int *count
)
5996 machine_mode new_mode
= VOIDmode
;
5998 /* If we have the type information, prefer that to working things
5999 out from the mode. */
6002 int ag_count
= aapcs_vfp_sub_candidate (type
, &new_mode
);
6004 if (ag_count
> 0 && ag_count
<= 4)
6009 else if (GET_MODE_CLASS (mode
) == MODE_FLOAT
6010 || GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
6011 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
)
6016 else if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
6019 new_mode
= (mode
== DCmode
? DFmode
: SFmode
);
6025 if (!use_vfp_abi (pcs_variant
, ARM_NUM_REGS (new_mode
) > 1))
6028 *base_mode
= new_mode
;
6033 aapcs_vfp_is_return_candidate (enum arm_pcs pcs_variant
,
6034 machine_mode mode
, const_tree type
)
6036 int count ATTRIBUTE_UNUSED
;
6037 machine_mode ag_mode ATTRIBUTE_UNUSED
;
6039 if (!use_vfp_abi (pcs_variant
, false))
6041 return aapcs_vfp_is_call_or_return_candidate (pcs_variant
, mode
, type
,
6046 aapcs_vfp_is_call_candidate (CUMULATIVE_ARGS
*pcum
, machine_mode mode
,
6049 if (!use_vfp_abi (pcum
->pcs_variant
, false))
6052 return aapcs_vfp_is_call_or_return_candidate (pcum
->pcs_variant
, mode
, type
,
6053 &pcum
->aapcs_vfp_rmode
,
6054 &pcum
->aapcs_vfp_rcount
);
6057 /* Implement the allocate field in aapcs_cp_arg_layout. See the comment there
6058 for the behaviour of this function. */
6061 aapcs_vfp_allocate (CUMULATIVE_ARGS
*pcum
, machine_mode mode
,
6062 const_tree type ATTRIBUTE_UNUSED
)
6065 = MAX (GET_MODE_SIZE (pcum
->aapcs_vfp_rmode
), GET_MODE_SIZE (SFmode
));
6066 int shift
= rmode_size
/ GET_MODE_SIZE (SFmode
);
6067 unsigned mask
= (1 << (shift
* pcum
->aapcs_vfp_rcount
)) - 1;
6070 for (regno
= 0; regno
< NUM_VFP_ARG_REGS
; regno
+= shift
)
6071 if (((pcum
->aapcs_vfp_regs_free
>> regno
) & mask
) == mask
)
6073 pcum
->aapcs_vfp_reg_alloc
= mask
<< regno
;
6075 || (mode
== TImode
&& ! TARGET_NEON
)
6076 || ! arm_hard_regno_mode_ok (FIRST_VFP_REGNUM
+ regno
, mode
))
6079 int rcount
= pcum
->aapcs_vfp_rcount
;
6081 machine_mode rmode
= pcum
->aapcs_vfp_rmode
;
6085 /* Avoid using unsupported vector modes. */
6086 if (rmode
== V2SImode
)
6088 else if (rmode
== V4SImode
)
6095 par
= gen_rtx_PARALLEL (mode
, rtvec_alloc (rcount
));
6096 for (i
= 0; i
< rcount
; i
++)
6098 rtx tmp
= gen_rtx_REG (rmode
,
6099 FIRST_VFP_REGNUM
+ regno
+ i
* rshift
);
6100 tmp
= gen_rtx_EXPR_LIST
6102 GEN_INT (i
* GET_MODE_SIZE (rmode
)));
6103 XVECEXP (par
, 0, i
) = tmp
;
6106 pcum
->aapcs_reg
= par
;
6109 pcum
->aapcs_reg
= gen_rtx_REG (mode
, FIRST_VFP_REGNUM
+ regno
);
6115 /* Implement the allocate_return_reg field in aapcs_cp_arg_layout. See the
6116 comment there for the behaviour of this function. */
6119 aapcs_vfp_allocate_return_reg (enum arm_pcs pcs_variant ATTRIBUTE_UNUSED
,
6121 const_tree type ATTRIBUTE_UNUSED
)
6123 if (!use_vfp_abi (pcs_variant
, false))
6127 || (GET_MODE_CLASS (mode
) == MODE_INT
6128 && GET_MODE_SIZE (mode
) >= GET_MODE_SIZE (TImode
)
6132 machine_mode ag_mode
;
6137 aapcs_vfp_is_call_or_return_candidate (pcs_variant
, mode
, type
,
6142 if (ag_mode
== V2SImode
)
6144 else if (ag_mode
== V4SImode
)
6150 shift
= GET_MODE_SIZE(ag_mode
) / GET_MODE_SIZE(SFmode
);
6151 par
= gen_rtx_PARALLEL (mode
, rtvec_alloc (count
));
6152 for (i
= 0; i
< count
; i
++)
6154 rtx tmp
= gen_rtx_REG (ag_mode
, FIRST_VFP_REGNUM
+ i
* shift
);
6155 tmp
= gen_rtx_EXPR_LIST (VOIDmode
, tmp
,
6156 GEN_INT (i
* GET_MODE_SIZE (ag_mode
)));
6157 XVECEXP (par
, 0, i
) = tmp
;
6163 return gen_rtx_REG (mode
, FIRST_VFP_REGNUM
);
6167 aapcs_vfp_advance (CUMULATIVE_ARGS
*pcum ATTRIBUTE_UNUSED
,
6168 machine_mode mode ATTRIBUTE_UNUSED
,
6169 const_tree type ATTRIBUTE_UNUSED
)
6171 pcum
->aapcs_vfp_regs_free
&= ~pcum
->aapcs_vfp_reg_alloc
;
6172 pcum
->aapcs_vfp_reg_alloc
= 0;
6176 #define AAPCS_CP(X) \
6178 aapcs_ ## X ## _cum_init, \
6179 aapcs_ ## X ## _is_call_candidate, \
6180 aapcs_ ## X ## _allocate, \
6181 aapcs_ ## X ## _is_return_candidate, \
6182 aapcs_ ## X ## _allocate_return_reg, \
6183 aapcs_ ## X ## _advance \
6186 /* Table of co-processors that can be used to pass arguments in
6187 registers. Idealy no arugment should be a candidate for more than
6188 one co-processor table entry, but the table is processed in order
6189 and stops after the first match. If that entry then fails to put
6190 the argument into a co-processor register, the argument will go on
6194 /* Initialize co-processor related state in CUMULATIVE_ARGS structure. */
6195 void (*cum_init
) (CUMULATIVE_ARGS
*, const_tree
, rtx
, const_tree
);
6197 /* Return true if an argument of mode MODE (or type TYPE if MODE is
6198 BLKmode) is a candidate for this co-processor's registers; this
6199 function should ignore any position-dependent state in
6200 CUMULATIVE_ARGS and only use call-type dependent information. */
6201 bool (*is_call_candidate
) (CUMULATIVE_ARGS
*, machine_mode
, const_tree
);
6203 /* Return true if the argument does get a co-processor register; it
6204 should set aapcs_reg to an RTX of the register allocated as is
6205 required for a return from FUNCTION_ARG. */
6206 bool (*allocate
) (CUMULATIVE_ARGS
*, machine_mode
, const_tree
);
6208 /* Return true if a result of mode MODE (or type TYPE if MODE is BLKmode) can
6209 be returned in this co-processor's registers. */
6210 bool (*is_return_candidate
) (enum arm_pcs
, machine_mode
, const_tree
);
6212 /* Allocate and return an RTX element to hold the return type of a call. This
6213 routine must not fail and will only be called if is_return_candidate
6214 returned true with the same parameters. */
6215 rtx (*allocate_return_reg
) (enum arm_pcs
, machine_mode
, const_tree
);
6217 /* Finish processing this argument and prepare to start processing
6219 void (*advance
) (CUMULATIVE_ARGS
*, machine_mode
, const_tree
);
6220 } aapcs_cp_arg_layout
[ARM_NUM_COPROC_SLOTS
] =
6228 aapcs_select_call_coproc (CUMULATIVE_ARGS
*pcum
, machine_mode mode
,
6233 for (i
= 0; i
< ARM_NUM_COPROC_SLOTS
; i
++)
6234 if (aapcs_cp_arg_layout
[i
].is_call_candidate (pcum
, mode
, type
))
6241 aapcs_select_return_coproc (const_tree type
, const_tree fntype
)
6243 /* We aren't passed a decl, so we can't check that a call is local.
6244 However, it isn't clear that that would be a win anyway, since it
6245 might limit some tail-calling opportunities. */
6246 enum arm_pcs pcs_variant
;
6250 const_tree fndecl
= NULL_TREE
;
6252 if (TREE_CODE (fntype
) == FUNCTION_DECL
)
6255 fntype
= TREE_TYPE (fntype
);
6258 pcs_variant
= arm_get_pcs_model (fntype
, fndecl
);
6261 pcs_variant
= arm_pcs_default
;
6263 if (pcs_variant
!= ARM_PCS_AAPCS
)
6267 for (i
= 0; i
< ARM_NUM_COPROC_SLOTS
; i
++)
6268 if (aapcs_cp_arg_layout
[i
].is_return_candidate (pcs_variant
,
6277 aapcs_allocate_return_reg (machine_mode mode
, const_tree type
,
6280 /* We aren't passed a decl, so we can't check that a call is local.
6281 However, it isn't clear that that would be a win anyway, since it
6282 might limit some tail-calling opportunities. */
6283 enum arm_pcs pcs_variant
;
6284 int unsignedp ATTRIBUTE_UNUSED
;
6288 const_tree fndecl
= NULL_TREE
;
6290 if (TREE_CODE (fntype
) == FUNCTION_DECL
)
6293 fntype
= TREE_TYPE (fntype
);
6296 pcs_variant
= arm_get_pcs_model (fntype
, fndecl
);
6299 pcs_variant
= arm_pcs_default
;
6301 /* Promote integer types. */
6302 if (type
&& INTEGRAL_TYPE_P (type
))
6303 mode
= arm_promote_function_mode (type
, mode
, &unsignedp
, fntype
, 1);
6305 if (pcs_variant
!= ARM_PCS_AAPCS
)
6309 for (i
= 0; i
< ARM_NUM_COPROC_SLOTS
; i
++)
6310 if (aapcs_cp_arg_layout
[i
].is_return_candidate (pcs_variant
, mode
,
6312 return aapcs_cp_arg_layout
[i
].allocate_return_reg (pcs_variant
,
6316 /* Promotes small structs returned in a register to full-word size
6317 for big-endian AAPCS. */
6318 if (type
&& arm_return_in_msb (type
))
6320 HOST_WIDE_INT size
= int_size_in_bytes (type
);
6321 if (size
% UNITS_PER_WORD
!= 0)
6323 size
+= UNITS_PER_WORD
- size
% UNITS_PER_WORD
;
6324 mode
= int_mode_for_size (size
* BITS_PER_UNIT
, 0).require ();
6328 return gen_rtx_REG (mode
, R0_REGNUM
);
6332 aapcs_libcall_value (machine_mode mode
)
6334 if (BYTES_BIG_ENDIAN
&& ALL_FIXED_POINT_MODE_P (mode
)
6335 && GET_MODE_SIZE (mode
) <= 4)
6338 return aapcs_allocate_return_reg (mode
, NULL_TREE
, NULL_TREE
);
6341 /* Lay out a function argument using the AAPCS rules. The rule
6342 numbers referred to here are those in the AAPCS. */
6344 aapcs_layout_arg (CUMULATIVE_ARGS
*pcum
, machine_mode mode
,
6345 const_tree type
, bool named
)
6350 /* We only need to do this once per argument. */
6351 if (pcum
->aapcs_arg_processed
)
6354 pcum
->aapcs_arg_processed
= true;
6356 /* Special case: if named is false then we are handling an incoming
6357 anonymous argument which is on the stack. */
6361 /* Is this a potential co-processor register candidate? */
6362 if (pcum
->pcs_variant
!= ARM_PCS_AAPCS
)
6364 int slot
= aapcs_select_call_coproc (pcum
, mode
, type
);
6365 pcum
->aapcs_cprc_slot
= slot
;
6367 /* We don't have to apply any of the rules from part B of the
6368 preparation phase, these are handled elsewhere in the
6373 /* A Co-processor register candidate goes either in its own
6374 class of registers or on the stack. */
6375 if (!pcum
->aapcs_cprc_failed
[slot
])
6377 /* C1.cp - Try to allocate the argument to co-processor
6379 if (aapcs_cp_arg_layout
[slot
].allocate (pcum
, mode
, type
))
6382 /* C2.cp - Put the argument on the stack and note that we
6383 can't assign any more candidates in this slot. We also
6384 need to note that we have allocated stack space, so that
6385 we won't later try to split a non-cprc candidate between
6386 core registers and the stack. */
6387 pcum
->aapcs_cprc_failed
[slot
] = true;
6388 pcum
->can_split
= false;
6391 /* We didn't get a register, so this argument goes on the
6393 gcc_assert (pcum
->can_split
== false);
6398 /* C3 - For double-word aligned arguments, round the NCRN up to the
6399 next even number. */
6400 ncrn
= pcum
->aapcs_ncrn
;
6403 int res
= arm_needs_doubleword_align (mode
, type
);
6404 /* Only warn during RTL expansion of call stmts, otherwise we would
6405 warn e.g. during gimplification even on functions that will be
6406 always inlined, and we'd warn multiple times. Don't warn when
6407 called in expand_function_start either, as we warn instead in
6408 arm_function_arg_boundary in that case. */
6409 if (res
< 0 && warn_psabi
&& currently_expanding_gimple_stmt
)
6410 inform (input_location
, "parameter passing for argument of type "
6411 "%qT changed in GCC 7.1", type
);
6416 nregs
= ARM_NUM_REGS2(mode
, type
);
6418 /* Sigh, this test should really assert that nregs > 0, but a GCC
6419 extension allows empty structs and then gives them empty size; it
6420 then allows such a structure to be passed by value. For some of
6421 the code below we have to pretend that such an argument has
6422 non-zero size so that we 'locate' it correctly either in
6423 registers or on the stack. */
6424 gcc_assert (nregs
>= 0);
6426 nregs2
= nregs
? nregs
: 1;
6428 /* C4 - Argument fits entirely in core registers. */
6429 if (ncrn
+ nregs2
<= NUM_ARG_REGS
)
6431 pcum
->aapcs_reg
= gen_rtx_REG (mode
, ncrn
);
6432 pcum
->aapcs_next_ncrn
= ncrn
+ nregs
;
6436 /* C5 - Some core registers left and there are no arguments already
6437 on the stack: split this argument between the remaining core
6438 registers and the stack. */
6439 if (ncrn
< NUM_ARG_REGS
&& pcum
->can_split
)
6441 pcum
->aapcs_reg
= gen_rtx_REG (mode
, ncrn
);
6442 pcum
->aapcs_next_ncrn
= NUM_ARG_REGS
;
6443 pcum
->aapcs_partial
= (NUM_ARG_REGS
- ncrn
) * UNITS_PER_WORD
;
6447 /* C6 - NCRN is set to 4. */
6448 pcum
->aapcs_next_ncrn
= NUM_ARG_REGS
;
6450 /* C7,C8 - arugment goes on the stack. We have nothing to do here. */
6454 /* Initialize a variable CUM of type CUMULATIVE_ARGS
6455 for a call to a function whose data type is FNTYPE.
6456 For a library call, FNTYPE is NULL. */
6458 arm_init_cumulative_args (CUMULATIVE_ARGS
*pcum
, tree fntype
,
6460 tree fndecl ATTRIBUTE_UNUSED
)
6462 /* Long call handling. */
6464 pcum
->pcs_variant
= arm_get_pcs_model (fntype
, fndecl
);
6466 pcum
->pcs_variant
= arm_pcs_default
;
6468 if (pcum
->pcs_variant
<= ARM_PCS_AAPCS_LOCAL
)
6470 if (arm_libcall_uses_aapcs_base (libname
))
6471 pcum
->pcs_variant
= ARM_PCS_AAPCS
;
6473 pcum
->aapcs_ncrn
= pcum
->aapcs_next_ncrn
= 0;
6474 pcum
->aapcs_reg
= NULL_RTX
;
6475 pcum
->aapcs_partial
= 0;
6476 pcum
->aapcs_arg_processed
= false;
6477 pcum
->aapcs_cprc_slot
= -1;
6478 pcum
->can_split
= true;
6480 if (pcum
->pcs_variant
!= ARM_PCS_AAPCS
)
6484 for (i
= 0; i
< ARM_NUM_COPROC_SLOTS
; i
++)
6486 pcum
->aapcs_cprc_failed
[i
] = false;
6487 aapcs_cp_arg_layout
[i
].cum_init (pcum
, fntype
, libname
, fndecl
);
6495 /* On the ARM, the offset starts at 0. */
6497 pcum
->iwmmxt_nregs
= 0;
6498 pcum
->can_split
= true;
6500 /* Varargs vectors are treated the same as long long.
6501 named_count avoids having to change the way arm handles 'named' */
6502 pcum
->named_count
= 0;
6505 if (TARGET_REALLY_IWMMXT
&& fntype
)
6509 for (fn_arg
= TYPE_ARG_TYPES (fntype
);
6511 fn_arg
= TREE_CHAIN (fn_arg
))
6512 pcum
->named_count
+= 1;
6514 if (! pcum
->named_count
)
6515 pcum
->named_count
= INT_MAX
;
6519 /* Return 1 if double word alignment is required for argument passing.
6520 Return -1 if double word alignment used to be required for argument
6521 passing before PR77728 ABI fix, but is not required anymore.
6522 Return 0 if double word alignment is not required and wasn't requried
6525 arm_needs_doubleword_align (machine_mode mode
, const_tree type
)
6528 return GET_MODE_ALIGNMENT (mode
) > PARM_BOUNDARY
;
6530 /* Scalar and vector types: Use natural alignment, i.e. of base type. */
6531 if (!AGGREGATE_TYPE_P (type
))
6532 return TYPE_ALIGN (TYPE_MAIN_VARIANT (type
)) > PARM_BOUNDARY
;
6534 /* Array types: Use member alignment of element type. */
6535 if (TREE_CODE (type
) == ARRAY_TYPE
)
6536 return TYPE_ALIGN (TREE_TYPE (type
)) > PARM_BOUNDARY
;
6539 /* Record/aggregate types: Use greatest member alignment of any member. */
6540 for (tree field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
6541 if (DECL_ALIGN (field
) > PARM_BOUNDARY
)
6543 if (TREE_CODE (field
) == FIELD_DECL
)
6546 /* Before PR77728 fix, we were incorrectly considering also
6547 other aggregate fields, like VAR_DECLs, TYPE_DECLs etc.
6548 Make sure we can warn about that with -Wpsabi. */
6556 /* Determine where to put an argument to a function.
6557 Value is zero to push the argument on the stack,
6558 or a hard register in which to store the argument.
6560 MODE is the argument's machine mode.
6561 TYPE is the data type of the argument (as a tree).
6562 This is null for libcalls where that information may
6564 CUM is a variable of type CUMULATIVE_ARGS which gives info about
6565 the preceding args and about the function being called.
6566 NAMED is nonzero if this argument is a named parameter
6567 (otherwise it is an extra parameter matching an ellipsis).
6569 On the ARM, normally the first 16 bytes are passed in registers r0-r3; all
6570 other arguments are passed on the stack. If (NAMED == 0) (which happens
6571 only in assign_parms, since TARGET_SETUP_INCOMING_VARARGS is
6572 defined), say it is passed in the stack (function_prologue will
6573 indeed make it pass in the stack if necessary). */
6576 arm_function_arg (cumulative_args_t pcum_v
, machine_mode mode
,
6577 const_tree type
, bool named
)
6579 CUMULATIVE_ARGS
*pcum
= get_cumulative_args (pcum_v
);
6582 /* Handle the special case quickly. Pick an arbitrary value for op2 of
6583 a call insn (op3 of a call_value insn). */
6584 if (mode
== VOIDmode
)
6587 if (pcum
->pcs_variant
<= ARM_PCS_AAPCS_LOCAL
)
6589 aapcs_layout_arg (pcum
, mode
, type
, named
);
6590 return pcum
->aapcs_reg
;
6593 /* Varargs vectors are treated the same as long long.
6594 named_count avoids having to change the way arm handles 'named' */
6595 if (TARGET_IWMMXT_ABI
6596 && arm_vector_mode_supported_p (mode
)
6597 && pcum
->named_count
> pcum
->nargs
+ 1)
6599 if (pcum
->iwmmxt_nregs
<= 9)
6600 return gen_rtx_REG (mode
, pcum
->iwmmxt_nregs
+ FIRST_IWMMXT_REGNUM
);
6603 pcum
->can_split
= false;
6608 /* Put doubleword aligned quantities in even register pairs. */
6609 if ((pcum
->nregs
& 1) && ARM_DOUBLEWORD_ALIGN
)
6611 int res
= arm_needs_doubleword_align (mode
, type
);
6612 if (res
< 0 && warn_psabi
)
6613 inform (input_location
, "parameter passing for argument of type "
6614 "%qT changed in GCC 7.1", type
);
6619 /* Only allow splitting an arg between regs and memory if all preceding
6620 args were allocated to regs. For args passed by reference we only count
6621 the reference pointer. */
6622 if (pcum
->can_split
)
6625 nregs
= ARM_NUM_REGS2 (mode
, type
);
6627 if (!named
|| pcum
->nregs
+ nregs
> NUM_ARG_REGS
)
6630 return gen_rtx_REG (mode
, pcum
->nregs
);
6634 arm_function_arg_boundary (machine_mode mode
, const_tree type
)
6636 if (!ARM_DOUBLEWORD_ALIGN
)
6637 return PARM_BOUNDARY
;
6639 int res
= arm_needs_doubleword_align (mode
, type
);
6640 if (res
< 0 && warn_psabi
)
6641 inform (input_location
, "parameter passing for argument of type %qT "
6642 "changed in GCC 7.1", type
);
6644 return res
> 0 ? DOUBLEWORD_ALIGNMENT
: PARM_BOUNDARY
;
6648 arm_arg_partial_bytes (cumulative_args_t pcum_v
, machine_mode mode
,
6649 tree type
, bool named
)
6651 CUMULATIVE_ARGS
*pcum
= get_cumulative_args (pcum_v
);
6652 int nregs
= pcum
->nregs
;
6654 if (pcum
->pcs_variant
<= ARM_PCS_AAPCS_LOCAL
)
6656 aapcs_layout_arg (pcum
, mode
, type
, named
);
6657 return pcum
->aapcs_partial
;
6660 if (TARGET_IWMMXT_ABI
&& arm_vector_mode_supported_p (mode
))
6663 if (NUM_ARG_REGS
> nregs
6664 && (NUM_ARG_REGS
< nregs
+ ARM_NUM_REGS2 (mode
, type
))
6666 return (NUM_ARG_REGS
- nregs
) * UNITS_PER_WORD
;
6671 /* Update the data in PCUM to advance over an argument
6672 of mode MODE and data type TYPE.
6673 (TYPE is null for libcalls where that information may not be available.) */
6676 arm_function_arg_advance (cumulative_args_t pcum_v
, machine_mode mode
,
6677 const_tree type
, bool named
)
6679 CUMULATIVE_ARGS
*pcum
= get_cumulative_args (pcum_v
);
6681 if (pcum
->pcs_variant
<= ARM_PCS_AAPCS_LOCAL
)
6683 aapcs_layout_arg (pcum
, mode
, type
, named
);
6685 if (pcum
->aapcs_cprc_slot
>= 0)
6687 aapcs_cp_arg_layout
[pcum
->aapcs_cprc_slot
].advance (pcum
, mode
,
6689 pcum
->aapcs_cprc_slot
= -1;
6692 /* Generic stuff. */
6693 pcum
->aapcs_arg_processed
= false;
6694 pcum
->aapcs_ncrn
= pcum
->aapcs_next_ncrn
;
6695 pcum
->aapcs_reg
= NULL_RTX
;
6696 pcum
->aapcs_partial
= 0;
6701 if (arm_vector_mode_supported_p (mode
)
6702 && pcum
->named_count
> pcum
->nargs
6703 && TARGET_IWMMXT_ABI
)
6704 pcum
->iwmmxt_nregs
+= 1;
6706 pcum
->nregs
+= ARM_NUM_REGS2 (mode
, type
);
6710 /* Variable sized types are passed by reference. This is a GCC
6711 extension to the ARM ABI. */
6714 arm_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED
,
6715 machine_mode mode ATTRIBUTE_UNUSED
,
6716 const_tree type
, bool named ATTRIBUTE_UNUSED
)
6718 return type
&& TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
;
6721 /* Encode the current state of the #pragma [no_]long_calls. */
6724 OFF
, /* No #pragma [no_]long_calls is in effect. */
6725 LONG
, /* #pragma long_calls is in effect. */
6726 SHORT
/* #pragma no_long_calls is in effect. */
6729 static arm_pragma_enum arm_pragma_long_calls
= OFF
;
6732 arm_pr_long_calls (struct cpp_reader
* pfile ATTRIBUTE_UNUSED
)
6734 arm_pragma_long_calls
= LONG
;
6738 arm_pr_no_long_calls (struct cpp_reader
* pfile ATTRIBUTE_UNUSED
)
6740 arm_pragma_long_calls
= SHORT
;
6744 arm_pr_long_calls_off (struct cpp_reader
* pfile ATTRIBUTE_UNUSED
)
6746 arm_pragma_long_calls
= OFF
;
6749 /* Handle an attribute requiring a FUNCTION_DECL;
6750 arguments as in struct attribute_spec.handler. */
6752 arm_handle_fndecl_attribute (tree
*node
, tree name
, tree args ATTRIBUTE_UNUSED
,
6753 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6755 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6757 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
6759 *no_add_attrs
= true;
6765 /* Handle an "interrupt" or "isr" attribute;
6766 arguments as in struct attribute_spec.handler. */
6768 arm_handle_isr_attribute (tree
*node
, tree name
, tree args
, int flags
,
6773 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6775 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
6777 *no_add_attrs
= true;
6779 /* FIXME: the argument if any is checked for type attributes;
6780 should it be checked for decl ones? */
6784 if (TREE_CODE (*node
) == FUNCTION_TYPE
6785 || TREE_CODE (*node
) == METHOD_TYPE
)
6787 if (arm_isr_value (args
) == ARM_FT_UNKNOWN
)
6789 warning (OPT_Wattributes
, "%qE attribute ignored",
6791 *no_add_attrs
= true;
6794 else if (TREE_CODE (*node
) == POINTER_TYPE
6795 && (TREE_CODE (TREE_TYPE (*node
)) == FUNCTION_TYPE
6796 || TREE_CODE (TREE_TYPE (*node
)) == METHOD_TYPE
)
6797 && arm_isr_value (args
) != ARM_FT_UNKNOWN
)
6799 *node
= build_variant_type_copy (*node
);
6800 TREE_TYPE (*node
) = build_type_attribute_variant
6802 tree_cons (name
, args
, TYPE_ATTRIBUTES (TREE_TYPE (*node
))));
6803 *no_add_attrs
= true;
6807 /* Possibly pass this attribute on from the type to a decl. */
6808 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
6809 | (int) ATTR_FLAG_FUNCTION_NEXT
6810 | (int) ATTR_FLAG_ARRAY_NEXT
))
6812 *no_add_attrs
= true;
6813 return tree_cons (name
, args
, NULL_TREE
);
6817 warning (OPT_Wattributes
, "%qE attribute ignored",
6826 /* Handle a "pcs" attribute; arguments as in struct
6827 attribute_spec.handler. */
6829 arm_handle_pcs_attribute (tree
*node ATTRIBUTE_UNUSED
, tree name
, tree args
,
6830 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
6832 if (arm_pcs_from_attribute (args
) == ARM_PCS_UNKNOWN
)
6834 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6835 *no_add_attrs
= true;
6840 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
6841 /* Handle the "notshared" attribute. This attribute is another way of
6842 requesting hidden visibility. ARM's compiler supports
6843 "__declspec(notshared)"; we support the same thing via an
6847 arm_handle_notshared_attribute (tree
*node
,
6848 tree name ATTRIBUTE_UNUSED
,
6849 tree args ATTRIBUTE_UNUSED
,
6850 int flags ATTRIBUTE_UNUSED
,
6853 tree decl
= TYPE_NAME (*node
);
6857 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
6858 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
6859 *no_add_attrs
= false;
6865 /* This function returns true if a function with declaration FNDECL and type
6866 FNTYPE uses the stack to pass arguments or return variables and false
6867 otherwise. This is used for functions with the attributes
6868 'cmse_nonsecure_call' or 'cmse_nonsecure_entry' and this function will issue
6869 diagnostic messages if the stack is used. NAME is the name of the attribute
6873 cmse_func_args_or_return_in_stack (tree fndecl
, tree name
, tree fntype
)
6875 function_args_iterator args_iter
;
6876 CUMULATIVE_ARGS args_so_far_v
;
6877 cumulative_args_t args_so_far
;
6878 bool first_param
= true;
6879 tree arg_type
, prev_arg_type
= NULL_TREE
, ret_type
;
6881 /* Error out if any argument is passed on the stack. */
6882 arm_init_cumulative_args (&args_so_far_v
, fntype
, NULL_RTX
, fndecl
);
6883 args_so_far
= pack_cumulative_args (&args_so_far_v
);
6884 FOREACH_FUNCTION_ARGS (fntype
, arg_type
, args_iter
)
6887 machine_mode arg_mode
= TYPE_MODE (arg_type
);
6889 prev_arg_type
= arg_type
;
6890 if (VOID_TYPE_P (arg_type
))
6894 arm_function_arg_advance (args_so_far
, arg_mode
, arg_type
, true);
6895 arg_rtx
= arm_function_arg (args_so_far
, arg_mode
, arg_type
, true);
6897 || arm_arg_partial_bytes (args_so_far
, arg_mode
, arg_type
, true))
6899 error ("%qE attribute not available to functions with arguments "
6900 "passed on the stack", name
);
6903 first_param
= false;
6906 /* Error out for variadic functions since we cannot control how many
6907 arguments will be passed and thus stack could be used. stdarg_p () is not
6908 used for the checking to avoid browsing arguments twice. */
6909 if (prev_arg_type
!= NULL_TREE
&& !VOID_TYPE_P (prev_arg_type
))
6911 error ("%qE attribute not available to functions with variable number "
6912 "of arguments", name
);
6916 /* Error out if return value is passed on the stack. */
6917 ret_type
= TREE_TYPE (fntype
);
6918 if (arm_return_in_memory (ret_type
, fntype
))
6920 error ("%qE attribute not available to functions that return value on "
6927 /* Called upon detection of the use of the cmse_nonsecure_entry attribute, this
6928 function will check whether the attribute is allowed here and will add the
6929 attribute to the function declaration tree or otherwise issue a warning. */
6932 arm_handle_cmse_nonsecure_entry (tree
*node
, tree name
,
6941 *no_add_attrs
= true;
6942 warning (OPT_Wattributes
, "%qE attribute ignored without -mcmse option.",
6947 /* Ignore attribute for function types. */
6948 if (TREE_CODE (*node
) != FUNCTION_DECL
)
6950 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
6952 *no_add_attrs
= true;
6958 /* Warn for static linkage functions. */
6959 if (!TREE_PUBLIC (fndecl
))
6961 warning (OPT_Wattributes
, "%qE attribute has no effect on functions "
6962 "with static linkage", name
);
6963 *no_add_attrs
= true;
6967 *no_add_attrs
|= cmse_func_args_or_return_in_stack (fndecl
, name
,
6968 TREE_TYPE (fndecl
));
6973 /* Called upon detection of the use of the cmse_nonsecure_call attribute, this
6974 function will check whether the attribute is allowed here and will add the
6975 attribute to the function type tree or otherwise issue a diagnostic. The
6976 reason we check this at declaration time is to only allow the use of the
6977 attribute with declarations of function pointers and not function
6978 declarations. This function checks NODE is of the expected type and issues
6979 diagnostics otherwise using NAME. If it is not of the expected type
6980 *NO_ADD_ATTRS will be set to true. */
6983 arm_handle_cmse_nonsecure_call (tree
*node
, tree name
,
6988 tree decl
= NULL_TREE
, fntype
= NULL_TREE
;
6993 *no_add_attrs
= true;
6994 warning (OPT_Wattributes
, "%qE attribute ignored without -mcmse option.",
6999 if (TREE_CODE (*node
) == VAR_DECL
|| TREE_CODE (*node
) == TYPE_DECL
)
7002 fntype
= TREE_TYPE (decl
);
7005 while (fntype
!= NULL_TREE
&& TREE_CODE (fntype
) == POINTER_TYPE
)
7006 fntype
= TREE_TYPE (fntype
);
7008 if (!decl
|| TREE_CODE (fntype
) != FUNCTION_TYPE
)
7010 warning (OPT_Wattributes
, "%qE attribute only applies to base type of a "
7011 "function pointer", name
);
7012 *no_add_attrs
= true;
7016 *no_add_attrs
|= cmse_func_args_or_return_in_stack (NULL
, name
, fntype
);
7021 /* Prevent trees being shared among function types with and without
7022 cmse_nonsecure_call attribute. */
7023 type
= TREE_TYPE (decl
);
7025 type
= build_distinct_type_copy (type
);
7026 TREE_TYPE (decl
) = type
;
7029 while (TREE_CODE (fntype
) != FUNCTION_TYPE
)
7032 fntype
= TREE_TYPE (fntype
);
7033 fntype
= build_distinct_type_copy (fntype
);
7034 TREE_TYPE (type
) = fntype
;
7037 /* Construct a type attribute and add it to the function type. */
7038 tree attrs
= tree_cons (get_identifier ("cmse_nonsecure_call"), NULL_TREE
,
7039 TYPE_ATTRIBUTES (fntype
));
7040 TYPE_ATTRIBUTES (fntype
) = attrs
;
7044 /* Return 0 if the attributes for two types are incompatible, 1 if they
7045 are compatible, and 2 if they are nearly compatible (which causes a
7046 warning to be generated). */
7048 arm_comp_type_attributes (const_tree type1
, const_tree type2
)
7052 /* Check for mismatch of non-default calling convention. */
7053 if (TREE_CODE (type1
) != FUNCTION_TYPE
)
7056 /* Check for mismatched call attributes. */
7057 l1
= lookup_attribute ("long_call", TYPE_ATTRIBUTES (type1
)) != NULL
;
7058 l2
= lookup_attribute ("long_call", TYPE_ATTRIBUTES (type2
)) != NULL
;
7059 s1
= lookup_attribute ("short_call", TYPE_ATTRIBUTES (type1
)) != NULL
;
7060 s2
= lookup_attribute ("short_call", TYPE_ATTRIBUTES (type2
)) != NULL
;
7062 /* Only bother to check if an attribute is defined. */
7063 if (l1
| l2
| s1
| s2
)
7065 /* If one type has an attribute, the other must have the same attribute. */
7066 if ((l1
!= l2
) || (s1
!= s2
))
7069 /* Disallow mixed attributes. */
7070 if ((l1
& s2
) || (l2
& s1
))
7074 /* Check for mismatched ISR attribute. */
7075 l1
= lookup_attribute ("isr", TYPE_ATTRIBUTES (type1
)) != NULL
;
7077 l1
= lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1
)) != NULL
;
7078 l2
= lookup_attribute ("isr", TYPE_ATTRIBUTES (type2
)) != NULL
;
7080 l1
= lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2
)) != NULL
;
7084 l1
= lookup_attribute ("cmse_nonsecure_call",
7085 TYPE_ATTRIBUTES (type1
)) != NULL
;
7086 l2
= lookup_attribute ("cmse_nonsecure_call",
7087 TYPE_ATTRIBUTES (type2
)) != NULL
;
7095 /* Assigns default attributes to newly defined type. This is used to
7096 set short_call/long_call attributes for function types of
7097 functions defined inside corresponding #pragma scopes. */
7099 arm_set_default_type_attributes (tree type
)
7101 /* Add __attribute__ ((long_call)) to all functions, when
7102 inside #pragma long_calls or __attribute__ ((short_call)),
7103 when inside #pragma no_long_calls. */
7104 if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
7106 tree type_attr_list
, attr_name
;
7107 type_attr_list
= TYPE_ATTRIBUTES (type
);
7109 if (arm_pragma_long_calls
== LONG
)
7110 attr_name
= get_identifier ("long_call");
7111 else if (arm_pragma_long_calls
== SHORT
)
7112 attr_name
= get_identifier ("short_call");
7116 type_attr_list
= tree_cons (attr_name
, NULL_TREE
, type_attr_list
);
7117 TYPE_ATTRIBUTES (type
) = type_attr_list
;
7121 /* Return true if DECL is known to be linked into section SECTION. */
7124 arm_function_in_section_p (tree decl
, section
*section
)
7126 /* We can only be certain about the prevailing symbol definition. */
7127 if (!decl_binds_to_current_def_p (decl
))
7130 /* If DECL_SECTION_NAME is set, assume it is trustworthy. */
7131 if (!DECL_SECTION_NAME (decl
))
7133 /* Make sure that we will not create a unique section for DECL. */
7134 if (flag_function_sections
|| DECL_COMDAT_GROUP (decl
))
7138 return function_section (decl
) == section
;
7141 /* Return nonzero if a 32-bit "long_call" should be generated for
7142 a call from the current function to DECL. We generate a long_call
7145 a. has an __attribute__((long call))
7146 or b. is within the scope of a #pragma long_calls
7147 or c. the -mlong-calls command line switch has been specified
7149 However we do not generate a long call if the function:
7151 d. has an __attribute__ ((short_call))
7152 or e. is inside the scope of a #pragma no_long_calls
7153 or f. is defined in the same section as the current function. */
7156 arm_is_long_call_p (tree decl
)
7161 return TARGET_LONG_CALLS
;
7163 attrs
= TYPE_ATTRIBUTES (TREE_TYPE (decl
));
7164 if (lookup_attribute ("short_call", attrs
))
7167 /* For "f", be conservative, and only cater for cases in which the
7168 whole of the current function is placed in the same section. */
7169 if (!flag_reorder_blocks_and_partition
7170 && TREE_CODE (decl
) == FUNCTION_DECL
7171 && arm_function_in_section_p (decl
, current_function_section ()))
7174 if (lookup_attribute ("long_call", attrs
))
7177 return TARGET_LONG_CALLS
;
7180 /* Return nonzero if it is ok to make a tail-call to DECL. */
7182 arm_function_ok_for_sibcall (tree decl
, tree exp
)
7184 unsigned long func_type
;
7186 if (cfun
->machine
->sibcall_blocked
)
7189 /* Never tailcall something if we are generating code for Thumb-1. */
7193 /* The PIC register is live on entry to VxWorks PLT entries, so we
7194 must make the call before restoring the PIC register. */
7195 if (TARGET_VXWORKS_RTP
&& flag_pic
&& decl
&& !targetm
.binds_local_p (decl
))
7198 /* ??? Cannot tail-call to long calls with APCS frame and VFP, because IP
7199 may be used both as target of the call and base register for restoring
7200 the VFP registers */
7201 if (TARGET_APCS_FRAME
&& TARGET_ARM
7202 && TARGET_HARD_FLOAT
7203 && decl
&& arm_is_long_call_p (decl
))
7206 /* If we are interworking and the function is not declared static
7207 then we can't tail-call it unless we know that it exists in this
7208 compilation unit (since it might be a Thumb routine). */
7209 if (TARGET_INTERWORK
&& decl
&& TREE_PUBLIC (decl
)
7210 && !TREE_ASM_WRITTEN (decl
))
7213 func_type
= arm_current_func_type ();
7214 /* Never tailcall from an ISR routine - it needs a special exit sequence. */
7215 if (IS_INTERRUPT (func_type
))
7218 /* ARMv8-M non-secure entry functions need to return with bxns which is only
7219 generated for entry functions themselves. */
7220 if (IS_CMSE_ENTRY (arm_current_func_type ()))
7223 /* We do not allow ARMv8-M non-secure calls to be turned into sibling calls,
7224 this would complicate matters for later code generation. */
7225 if (TREE_CODE (exp
) == CALL_EXPR
)
7227 tree fntype
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp
)));
7228 if (lookup_attribute ("cmse_nonsecure_call", TYPE_ATTRIBUTES (fntype
)))
7232 if (!VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun
->decl
))))
7234 /* Check that the return value locations are the same. For
7235 example that we aren't returning a value from the sibling in
7236 a VFP register but then need to transfer it to a core
7239 tree decl_or_type
= decl
;
7241 /* If it is an indirect function pointer, get the function type. */
7243 decl_or_type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp
)));
7245 a
= arm_function_value (TREE_TYPE (exp
), decl_or_type
, false);
7246 b
= arm_function_value (TREE_TYPE (DECL_RESULT (cfun
->decl
)),
7248 if (!rtx_equal_p (a
, b
))
7252 /* Never tailcall if function may be called with a misaligned SP. */
7253 if (IS_STACKALIGN (func_type
))
7256 /* The AAPCS says that, on bare-metal, calls to unresolved weak
7257 references should become a NOP. Don't convert such calls into
7259 if (TARGET_AAPCS_BASED
7260 && arm_abi
== ARM_ABI_AAPCS
7262 && DECL_WEAK (decl
))
7265 /* We cannot do a tailcall for an indirect call by descriptor if all the
7266 argument registers are used because the only register left to load the
7267 address is IP and it will already contain the static chain. */
7268 if (!decl
&& CALL_EXPR_BY_DESCRIPTOR (exp
) && !flag_trampolines
)
7270 tree fntype
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp
)));
7271 CUMULATIVE_ARGS cum
;
7272 cumulative_args_t cum_v
;
7274 arm_init_cumulative_args (&cum
, fntype
, NULL_RTX
, NULL_TREE
);
7275 cum_v
= pack_cumulative_args (&cum
);
7277 for (tree t
= TYPE_ARG_TYPES (fntype
); t
; t
= TREE_CHAIN (t
))
7279 tree type
= TREE_VALUE (t
);
7280 if (!VOID_TYPE_P (type
))
7281 arm_function_arg_advance (cum_v
, TYPE_MODE (type
), type
, true);
7284 if (!arm_function_arg (cum_v
, SImode
, integer_type_node
, true))
7288 /* Everything else is ok. */
7293 /* Addressing mode support functions. */
7295 /* Return nonzero if X is a legitimate immediate operand when compiling
7296 for PIC. We know that X satisfies CONSTANT_P and flag_pic is true. */
7298 legitimate_pic_operand_p (rtx x
)
7300 if (GET_CODE (x
) == SYMBOL_REF
7301 || (GET_CODE (x
) == CONST
7302 && GET_CODE (XEXP (x
, 0)) == PLUS
7303 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == SYMBOL_REF
))
7309 /* Record that the current function needs a PIC register. Initialize
7310 cfun->machine->pic_reg if we have not already done so. */
7313 require_pic_register (void)
7315 /* A lot of the logic here is made obscure by the fact that this
7316 routine gets called as part of the rtx cost estimation process.
7317 We don't want those calls to affect any assumptions about the real
7318 function; and further, we can't call entry_of_function() until we
7319 start the real expansion process. */
7320 if (!crtl
->uses_pic_offset_table
)
7322 gcc_assert (can_create_pseudo_p ());
7323 if (arm_pic_register
!= INVALID_REGNUM
7324 && !(TARGET_THUMB1
&& arm_pic_register
> LAST_LO_REGNUM
))
7326 if (!cfun
->machine
->pic_reg
)
7327 cfun
->machine
->pic_reg
= gen_rtx_REG (Pmode
, arm_pic_register
);
7329 /* Play games to avoid marking the function as needing pic
7330 if we are being called as part of the cost-estimation
7332 if (current_ir_type () != IR_GIMPLE
|| currently_expanding_to_rtl
)
7333 crtl
->uses_pic_offset_table
= 1;
7337 rtx_insn
*seq
, *insn
;
7339 if (!cfun
->machine
->pic_reg
)
7340 cfun
->machine
->pic_reg
= gen_reg_rtx (Pmode
);
7342 /* Play games to avoid marking the function as needing pic
7343 if we are being called as part of the cost-estimation
7345 if (current_ir_type () != IR_GIMPLE
|| currently_expanding_to_rtl
)
7347 crtl
->uses_pic_offset_table
= 1;
7350 if (TARGET_THUMB1
&& arm_pic_register
!= INVALID_REGNUM
7351 && arm_pic_register
> LAST_LO_REGNUM
)
7352 emit_move_insn (cfun
->machine
->pic_reg
,
7353 gen_rtx_REG (Pmode
, arm_pic_register
));
7355 arm_load_pic_register (0UL);
7360 for (insn
= seq
; insn
; insn
= NEXT_INSN (insn
))
7362 INSN_LOCATION (insn
) = prologue_location
;
7364 /* We can be called during expansion of PHI nodes, where
7365 we can't yet emit instructions directly in the final
7366 insn stream. Queue the insns on the entry edge, they will
7367 be committed after everything else is expanded. */
7368 insert_insn_on_edge (seq
,
7369 single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun
)));
7376 legitimize_pic_address (rtx orig
, machine_mode mode
, rtx reg
)
7378 if (GET_CODE (orig
) == SYMBOL_REF
7379 || GET_CODE (orig
) == LABEL_REF
)
7383 gcc_assert (can_create_pseudo_p ());
7384 reg
= gen_reg_rtx (Pmode
);
7387 /* VxWorks does not impose a fixed gap between segments; the run-time
7388 gap can be different from the object-file gap. We therefore can't
7389 use GOTOFF unless we are absolutely sure that the symbol is in the
7390 same segment as the GOT. Unfortunately, the flexibility of linker
7391 scripts means that we can't be sure of that in general, so assume
7392 that GOTOFF is never valid on VxWorks. */
7393 /* References to weak symbols cannot be resolved locally: they
7394 may be overridden by a non-weak definition at link time. */
7396 if ((GET_CODE (orig
) == LABEL_REF
7397 || (GET_CODE (orig
) == SYMBOL_REF
7398 && SYMBOL_REF_LOCAL_P (orig
)
7399 && (SYMBOL_REF_DECL (orig
)
7400 ? !DECL_WEAK (SYMBOL_REF_DECL (orig
)) : 1)))
7402 && arm_pic_data_is_text_relative
)
7403 insn
= arm_pic_static_addr (orig
, reg
);
7409 /* If this function doesn't have a pic register, create one now. */
7410 require_pic_register ();
7412 pat
= gen_calculate_pic_address (reg
, cfun
->machine
->pic_reg
, orig
);
7414 /* Make the MEM as close to a constant as possible. */
7415 mem
= SET_SRC (pat
);
7416 gcc_assert (MEM_P (mem
) && !MEM_VOLATILE_P (mem
));
7417 MEM_READONLY_P (mem
) = 1;
7418 MEM_NOTRAP_P (mem
) = 1;
7420 insn
= emit_insn (pat
);
7423 /* Put a REG_EQUAL note on this insn, so that it can be optimized
7425 set_unique_reg_note (insn
, REG_EQUAL
, orig
);
7429 else if (GET_CODE (orig
) == CONST
)
7433 if (GET_CODE (XEXP (orig
, 0)) == PLUS
7434 && XEXP (XEXP (orig
, 0), 0) == cfun
->machine
->pic_reg
)
7437 /* Handle the case where we have: const (UNSPEC_TLS). */
7438 if (GET_CODE (XEXP (orig
, 0)) == UNSPEC
7439 && XINT (XEXP (orig
, 0), 1) == UNSPEC_TLS
)
7442 /* Handle the case where we have:
7443 const (plus (UNSPEC_TLS) (ADDEND)). The ADDEND must be a
7445 if (GET_CODE (XEXP (orig
, 0)) == PLUS
7446 && GET_CODE (XEXP (XEXP (orig
, 0), 0)) == UNSPEC
7447 && XINT (XEXP (XEXP (orig
, 0), 0), 1) == UNSPEC_TLS
)
7449 gcc_assert (CONST_INT_P (XEXP (XEXP (orig
, 0), 1)));
7455 gcc_assert (can_create_pseudo_p ());
7456 reg
= gen_reg_rtx (Pmode
);
7459 gcc_assert (GET_CODE (XEXP (orig
, 0)) == PLUS
);
7461 base
= legitimize_pic_address (XEXP (XEXP (orig
, 0), 0), Pmode
, reg
);
7462 offset
= legitimize_pic_address (XEXP (XEXP (orig
, 0), 1), Pmode
,
7463 base
== reg
? 0 : reg
);
7465 if (CONST_INT_P (offset
))
7467 /* The base register doesn't really matter, we only want to
7468 test the index for the appropriate mode. */
7469 if (!arm_legitimate_index_p (mode
, offset
, SET
, 0))
7471 gcc_assert (can_create_pseudo_p ());
7472 offset
= force_reg (Pmode
, offset
);
7475 if (CONST_INT_P (offset
))
7476 return plus_constant (Pmode
, base
, INTVAL (offset
));
7479 if (GET_MODE_SIZE (mode
) > 4
7480 && (GET_MODE_CLASS (mode
) == MODE_INT
7481 || TARGET_SOFT_FLOAT
))
7483 emit_insn (gen_addsi3 (reg
, base
, offset
));
7487 return gen_rtx_PLUS (Pmode
, base
, offset
);
7494 /* Find a spare register to use during the prolog of a function. */
7497 thumb_find_work_register (unsigned long pushed_regs_mask
)
7501 /* Check the argument registers first as these are call-used. The
7502 register allocation order means that sometimes r3 might be used
7503 but earlier argument registers might not, so check them all. */
7504 for (reg
= LAST_ARG_REGNUM
; reg
>= 0; reg
--)
7505 if (!df_regs_ever_live_p (reg
))
7508 /* Before going on to check the call-saved registers we can try a couple
7509 more ways of deducing that r3 is available. The first is when we are
7510 pushing anonymous arguments onto the stack and we have less than 4
7511 registers worth of fixed arguments(*). In this case r3 will be part of
7512 the variable argument list and so we can be sure that it will be
7513 pushed right at the start of the function. Hence it will be available
7514 for the rest of the prologue.
7515 (*): ie crtl->args.pretend_args_size is greater than 0. */
7516 if (cfun
->machine
->uses_anonymous_args
7517 && crtl
->args
.pretend_args_size
> 0)
7518 return LAST_ARG_REGNUM
;
7520 /* The other case is when we have fixed arguments but less than 4 registers
7521 worth. In this case r3 might be used in the body of the function, but
7522 it is not being used to convey an argument into the function. In theory
7523 we could just check crtl->args.size to see how many bytes are
7524 being passed in argument registers, but it seems that it is unreliable.
7525 Sometimes it will have the value 0 when in fact arguments are being
7526 passed. (See testcase execute/20021111-1.c for an example). So we also
7527 check the args_info.nregs field as well. The problem with this field is
7528 that it makes no allowances for arguments that are passed to the
7529 function but which are not used. Hence we could miss an opportunity
7530 when a function has an unused argument in r3. But it is better to be
7531 safe than to be sorry. */
7532 if (! cfun
->machine
->uses_anonymous_args
7533 && crtl
->args
.size
>= 0
7534 && crtl
->args
.size
<= (LAST_ARG_REGNUM
* UNITS_PER_WORD
)
7535 && (TARGET_AAPCS_BASED
7536 ? crtl
->args
.info
.aapcs_ncrn
< 4
7537 : crtl
->args
.info
.nregs
< 4))
7538 return LAST_ARG_REGNUM
;
7540 /* Otherwise look for a call-saved register that is going to be pushed. */
7541 for (reg
= LAST_LO_REGNUM
; reg
> LAST_ARG_REGNUM
; reg
--)
7542 if (pushed_regs_mask
& (1 << reg
))
7547 /* Thumb-2 can use high regs. */
7548 for (reg
= FIRST_HI_REGNUM
; reg
< 15; reg
++)
7549 if (pushed_regs_mask
& (1 << reg
))
7552 /* Something went wrong - thumb_compute_save_reg_mask()
7553 should have arranged for a suitable register to be pushed. */
7557 static GTY(()) int pic_labelno
;
7559 /* Generate code to load the PIC register. In thumb mode SCRATCH is a
7563 arm_load_pic_register (unsigned long saved_regs ATTRIBUTE_UNUSED
)
7565 rtx l1
, labelno
, pic_tmp
, pic_rtx
, pic_reg
;
7567 if (crtl
->uses_pic_offset_table
== 0 || TARGET_SINGLE_PIC_BASE
)
7570 gcc_assert (flag_pic
);
7572 pic_reg
= cfun
->machine
->pic_reg
;
7573 if (TARGET_VXWORKS_RTP
)
7575 pic_rtx
= gen_rtx_SYMBOL_REF (Pmode
, VXWORKS_GOTT_BASE
);
7576 pic_rtx
= gen_rtx_CONST (Pmode
, pic_rtx
);
7577 emit_insn (gen_pic_load_addr_32bit (pic_reg
, pic_rtx
));
7579 emit_insn (gen_rtx_SET (pic_reg
, gen_rtx_MEM (Pmode
, pic_reg
)));
7581 pic_tmp
= gen_rtx_SYMBOL_REF (Pmode
, VXWORKS_GOTT_INDEX
);
7582 emit_insn (gen_pic_offset_arm (pic_reg
, pic_reg
, pic_tmp
));
7586 /* We use an UNSPEC rather than a LABEL_REF because this label
7587 never appears in the code stream. */
7589 labelno
= GEN_INT (pic_labelno
++);
7590 l1
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, labelno
), UNSPEC_PIC_LABEL
);
7591 l1
= gen_rtx_CONST (VOIDmode
, l1
);
7593 /* On the ARM the PC register contains 'dot + 8' at the time of the
7594 addition, on the Thumb it is 'dot + 4'. */
7595 pic_rtx
= plus_constant (Pmode
, l1
, TARGET_ARM
? 8 : 4);
7596 pic_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, pic_rtx
),
7598 pic_rtx
= gen_rtx_CONST (Pmode
, pic_rtx
);
7602 emit_insn (gen_pic_load_addr_unified (pic_reg
, pic_rtx
, labelno
));
7604 else /* TARGET_THUMB1 */
7606 if (arm_pic_register
!= INVALID_REGNUM
7607 && REGNO (pic_reg
) > LAST_LO_REGNUM
)
7609 /* We will have pushed the pic register, so we should always be
7610 able to find a work register. */
7611 pic_tmp
= gen_rtx_REG (SImode
,
7612 thumb_find_work_register (saved_regs
));
7613 emit_insn (gen_pic_load_addr_thumb1 (pic_tmp
, pic_rtx
));
7614 emit_insn (gen_movsi (pic_offset_table_rtx
, pic_tmp
));
7615 emit_insn (gen_pic_add_dot_plus_four (pic_reg
, pic_reg
, labelno
));
7617 else if (arm_pic_register
!= INVALID_REGNUM
7618 && arm_pic_register
> LAST_LO_REGNUM
7619 && REGNO (pic_reg
) <= LAST_LO_REGNUM
)
7621 emit_insn (gen_pic_load_addr_unified (pic_reg
, pic_rtx
, labelno
));
7622 emit_move_insn (gen_rtx_REG (Pmode
, arm_pic_register
), pic_reg
);
7623 emit_use (gen_rtx_REG (Pmode
, arm_pic_register
));
7626 emit_insn (gen_pic_load_addr_unified (pic_reg
, pic_rtx
, labelno
));
7630 /* Need to emit this whether or not we obey regdecls,
7631 since setjmp/longjmp can cause life info to screw up. */
7635 /* Generate code to load the address of a static var when flag_pic is set. */
7637 arm_pic_static_addr (rtx orig
, rtx reg
)
7639 rtx l1
, labelno
, offset_rtx
;
7641 gcc_assert (flag_pic
);
7643 /* We use an UNSPEC rather than a LABEL_REF because this label
7644 never appears in the code stream. */
7645 labelno
= GEN_INT (pic_labelno
++);
7646 l1
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, labelno
), UNSPEC_PIC_LABEL
);
7647 l1
= gen_rtx_CONST (VOIDmode
, l1
);
7649 /* On the ARM the PC register contains 'dot + 8' at the time of the
7650 addition, on the Thumb it is 'dot + 4'. */
7651 offset_rtx
= plus_constant (Pmode
, l1
, TARGET_ARM
? 8 : 4);
7652 offset_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, orig
, offset_rtx
),
7653 UNSPEC_SYMBOL_OFFSET
);
7654 offset_rtx
= gen_rtx_CONST (Pmode
, offset_rtx
);
7656 return emit_insn (gen_pic_load_addr_unified (reg
, offset_rtx
, labelno
));
7659 /* Return nonzero if X is valid as an ARM state addressing register. */
7661 arm_address_register_rtx_p (rtx x
, int strict_p
)
7671 return ARM_REGNO_OK_FOR_BASE_P (regno
);
7673 return (regno
<= LAST_ARM_REGNUM
7674 || regno
>= FIRST_PSEUDO_REGISTER
7675 || regno
== FRAME_POINTER_REGNUM
7676 || regno
== ARG_POINTER_REGNUM
);
7679 /* Return TRUE if this rtx is the difference of a symbol and a label,
7680 and will reduce to a PC-relative relocation in the object file.
7681 Expressions like this can be left alone when generating PIC, rather
7682 than forced through the GOT. */
7684 pcrel_constant_p (rtx x
)
7686 if (GET_CODE (x
) == MINUS
)
7687 return symbol_mentioned_p (XEXP (x
, 0)) && label_mentioned_p (XEXP (x
, 1));
7692 /* Return true if X will surely end up in an index register after next
7695 will_be_in_index_register (const_rtx x
)
7697 /* arm.md: calculate_pic_address will split this into a register. */
7698 return GET_CODE (x
) == UNSPEC
&& (XINT (x
, 1) == UNSPEC_PIC_SYM
);
7701 /* Return nonzero if X is a valid ARM state address operand. */
7703 arm_legitimate_address_outer_p (machine_mode mode
, rtx x
, RTX_CODE outer
,
7707 enum rtx_code code
= GET_CODE (x
);
7709 if (arm_address_register_rtx_p (x
, strict_p
))
7712 use_ldrd
= (TARGET_LDRD
7713 && (mode
== DImode
|| mode
== DFmode
));
7715 if (code
== POST_INC
|| code
== PRE_DEC
7716 || ((code
== PRE_INC
|| code
== POST_DEC
)
7717 && (use_ldrd
|| GET_MODE_SIZE (mode
) <= 4)))
7718 return arm_address_register_rtx_p (XEXP (x
, 0), strict_p
);
7720 else if ((code
== POST_MODIFY
|| code
== PRE_MODIFY
)
7721 && arm_address_register_rtx_p (XEXP (x
, 0), strict_p
)
7722 && GET_CODE (XEXP (x
, 1)) == PLUS
7723 && rtx_equal_p (XEXP (XEXP (x
, 1), 0), XEXP (x
, 0)))
7725 rtx addend
= XEXP (XEXP (x
, 1), 1);
7727 /* Don't allow ldrd post increment by register because it's hard
7728 to fixup invalid register choices. */
7730 && GET_CODE (x
) == POST_MODIFY
7734 return ((use_ldrd
|| GET_MODE_SIZE (mode
) <= 4)
7735 && arm_legitimate_index_p (mode
, addend
, outer
, strict_p
));
7738 /* After reload constants split into minipools will have addresses
7739 from a LABEL_REF. */
7740 else if (reload_completed
7741 && (code
== LABEL_REF
7743 && GET_CODE (XEXP (x
, 0)) == PLUS
7744 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == LABEL_REF
7745 && CONST_INT_P (XEXP (XEXP (x
, 0), 1)))))
7748 else if (mode
== TImode
|| (TARGET_NEON
&& VALID_NEON_STRUCT_MODE (mode
)))
7751 else if (code
== PLUS
)
7753 rtx xop0
= XEXP (x
, 0);
7754 rtx xop1
= XEXP (x
, 1);
7756 return ((arm_address_register_rtx_p (xop0
, strict_p
)
7757 && ((CONST_INT_P (xop1
)
7758 && arm_legitimate_index_p (mode
, xop1
, outer
, strict_p
))
7759 || (!strict_p
&& will_be_in_index_register (xop1
))))
7760 || (arm_address_register_rtx_p (xop1
, strict_p
)
7761 && arm_legitimate_index_p (mode
, xop0
, outer
, strict_p
)));
7765 /* Reload currently can't handle MINUS, so disable this for now */
7766 else if (GET_CODE (x
) == MINUS
)
7768 rtx xop0
= XEXP (x
, 0);
7769 rtx xop1
= XEXP (x
, 1);
7771 return (arm_address_register_rtx_p (xop0
, strict_p
)
7772 && arm_legitimate_index_p (mode
, xop1
, outer
, strict_p
));
7776 else if (GET_MODE_CLASS (mode
) != MODE_FLOAT
7777 && code
== SYMBOL_REF
7778 && CONSTANT_POOL_ADDRESS_P (x
)
7780 && symbol_mentioned_p (get_pool_constant (x
))
7781 && ! pcrel_constant_p (get_pool_constant (x
))))
7787 /* Return true if we can avoid creating a constant pool entry for x. */
7789 can_avoid_literal_pool_for_label_p (rtx x
)
7791 /* Normally we can assign constant values to target registers without
7792 the help of constant pool. But there are cases we have to use constant
7794 1) assign a label to register.
7795 2) sign-extend a 8bit value to 32bit and then assign to register.
7797 Constant pool access in format:
7798 (set (reg r0) (mem (symbol_ref (".LC0"))))
7799 will cause the use of literal pool (later in function arm_reorg).
7800 So here we mark such format as an invalid format, then the compiler
7801 will adjust it into:
7802 (set (reg r0) (symbol_ref (".LC0")))
7803 (set (reg r0) (mem (reg r0))).
7804 No extra register is required, and (mem (reg r0)) won't cause the use
7805 of literal pools. */
7806 if (arm_disable_literal_pool
&& GET_CODE (x
) == SYMBOL_REF
7807 && CONSTANT_POOL_ADDRESS_P (x
))
7813 /* Return nonzero if X is a valid Thumb-2 address operand. */
7815 thumb2_legitimate_address_p (machine_mode mode
, rtx x
, int strict_p
)
7818 enum rtx_code code
= GET_CODE (x
);
7820 if (arm_address_register_rtx_p (x
, strict_p
))
7823 use_ldrd
= (TARGET_LDRD
7824 && (mode
== DImode
|| mode
== DFmode
));
7826 if (code
== POST_INC
|| code
== PRE_DEC
7827 || ((code
== PRE_INC
|| code
== POST_DEC
)
7828 && (use_ldrd
|| GET_MODE_SIZE (mode
) <= 4)))
7829 return arm_address_register_rtx_p (XEXP (x
, 0), strict_p
);
7831 else if ((code
== POST_MODIFY
|| code
== PRE_MODIFY
)
7832 && arm_address_register_rtx_p (XEXP (x
, 0), strict_p
)
7833 && GET_CODE (XEXP (x
, 1)) == PLUS
7834 && rtx_equal_p (XEXP (XEXP (x
, 1), 0), XEXP (x
, 0)))
7836 /* Thumb-2 only has autoincrement by constant. */
7837 rtx addend
= XEXP (XEXP (x
, 1), 1);
7838 HOST_WIDE_INT offset
;
7840 if (!CONST_INT_P (addend
))
7843 offset
= INTVAL(addend
);
7844 if (GET_MODE_SIZE (mode
) <= 4)
7845 return (offset
> -256 && offset
< 256);
7847 return (use_ldrd
&& offset
> -1024 && offset
< 1024
7848 && (offset
& 3) == 0);
7851 /* After reload constants split into minipools will have addresses
7852 from a LABEL_REF. */
7853 else if (reload_completed
7854 && (code
== LABEL_REF
7856 && GET_CODE (XEXP (x
, 0)) == PLUS
7857 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == LABEL_REF
7858 && CONST_INT_P (XEXP (XEXP (x
, 0), 1)))))
7861 else if (mode
== TImode
|| (TARGET_NEON
&& VALID_NEON_STRUCT_MODE (mode
)))
7864 else if (code
== PLUS
)
7866 rtx xop0
= XEXP (x
, 0);
7867 rtx xop1
= XEXP (x
, 1);
7869 return ((arm_address_register_rtx_p (xop0
, strict_p
)
7870 && (thumb2_legitimate_index_p (mode
, xop1
, strict_p
)
7871 || (!strict_p
&& will_be_in_index_register (xop1
))))
7872 || (arm_address_register_rtx_p (xop1
, strict_p
)
7873 && thumb2_legitimate_index_p (mode
, xop0
, strict_p
)));
7876 else if (can_avoid_literal_pool_for_label_p (x
))
7879 else if (GET_MODE_CLASS (mode
) != MODE_FLOAT
7880 && code
== SYMBOL_REF
7881 && CONSTANT_POOL_ADDRESS_P (x
)
7883 && symbol_mentioned_p (get_pool_constant (x
))
7884 && ! pcrel_constant_p (get_pool_constant (x
))))
7890 /* Return nonzero if INDEX is valid for an address index operand in
7893 arm_legitimate_index_p (machine_mode mode
, rtx index
, RTX_CODE outer
,
7896 HOST_WIDE_INT range
;
7897 enum rtx_code code
= GET_CODE (index
);
7899 /* Standard coprocessor addressing modes. */
7900 if (TARGET_HARD_FLOAT
7901 && (mode
== SFmode
|| mode
== DFmode
))
7902 return (code
== CONST_INT
&& INTVAL (index
) < 1024
7903 && INTVAL (index
) > -1024
7904 && (INTVAL (index
) & 3) == 0);
7906 /* For quad modes, we restrict the constant offset to be slightly less
7907 than what the instruction format permits. We do this because for
7908 quad mode moves, we will actually decompose them into two separate
7909 double-mode reads or writes. INDEX must therefore be a valid
7910 (double-mode) offset and so should INDEX+8. */
7911 if (TARGET_NEON
&& VALID_NEON_QREG_MODE (mode
))
7912 return (code
== CONST_INT
7913 && INTVAL (index
) < 1016
7914 && INTVAL (index
) > -1024
7915 && (INTVAL (index
) & 3) == 0);
7917 /* We have no such constraint on double mode offsets, so we permit the
7918 full range of the instruction format. */
7919 if (TARGET_NEON
&& VALID_NEON_DREG_MODE (mode
))
7920 return (code
== CONST_INT
7921 && INTVAL (index
) < 1024
7922 && INTVAL (index
) > -1024
7923 && (INTVAL (index
) & 3) == 0);
7925 if (TARGET_REALLY_IWMMXT
&& VALID_IWMMXT_REG_MODE (mode
))
7926 return (code
== CONST_INT
7927 && INTVAL (index
) < 1024
7928 && INTVAL (index
) > -1024
7929 && (INTVAL (index
) & 3) == 0);
7931 if (arm_address_register_rtx_p (index
, strict_p
)
7932 && (GET_MODE_SIZE (mode
) <= 4))
7935 if (mode
== DImode
|| mode
== DFmode
)
7937 if (code
== CONST_INT
)
7939 HOST_WIDE_INT val
= INTVAL (index
);
7941 /* Assume we emit ldrd or 2x ldr if !TARGET_LDRD.
7942 If vldr is selected it uses arm_coproc_mem_operand. */
7944 return val
> -256 && val
< 256;
7946 return val
> -4096 && val
< 4092;
7949 return TARGET_LDRD
&& arm_address_register_rtx_p (index
, strict_p
);
7952 if (GET_MODE_SIZE (mode
) <= 4
7956 || (mode
== QImode
&& outer
== SIGN_EXTEND
))))
7960 rtx xiop0
= XEXP (index
, 0);
7961 rtx xiop1
= XEXP (index
, 1);
7963 return ((arm_address_register_rtx_p (xiop0
, strict_p
)
7964 && power_of_two_operand (xiop1
, SImode
))
7965 || (arm_address_register_rtx_p (xiop1
, strict_p
)
7966 && power_of_two_operand (xiop0
, SImode
)));
7968 else if (code
== LSHIFTRT
|| code
== ASHIFTRT
7969 || code
== ASHIFT
|| code
== ROTATERT
)
7971 rtx op
= XEXP (index
, 1);
7973 return (arm_address_register_rtx_p (XEXP (index
, 0), strict_p
)
7976 && INTVAL (op
) <= 31);
7980 /* For ARM v4 we may be doing a sign-extend operation during the
7986 || (outer
== SIGN_EXTEND
&& mode
== QImode
))
7992 range
= (mode
== HImode
|| mode
== HFmode
) ? 4095 : 4096;
7994 return (code
== CONST_INT
7995 && INTVAL (index
) < range
7996 && INTVAL (index
) > -range
);
7999 /* Return true if OP is a valid index scaling factor for Thumb-2 address
8000 index operand. i.e. 1, 2, 4 or 8. */
8002 thumb2_index_mul_operand (rtx op
)
8006 if (!CONST_INT_P (op
))
8010 return (val
== 1 || val
== 2 || val
== 4 || val
== 8);
8013 /* Return nonzero if INDEX is a valid Thumb-2 address index operand. */
8015 thumb2_legitimate_index_p (machine_mode mode
, rtx index
, int strict_p
)
8017 enum rtx_code code
= GET_CODE (index
);
8019 /* ??? Combine arm and thumb2 coprocessor addressing modes. */
8020 /* Standard coprocessor addressing modes. */
8021 if (TARGET_HARD_FLOAT
8022 && (mode
== SFmode
|| mode
== DFmode
))
8023 return (code
== CONST_INT
&& INTVAL (index
) < 1024
8024 /* Thumb-2 allows only > -256 index range for it's core register
8025 load/stores. Since we allow SF/DF in core registers, we have
8026 to use the intersection between -256~4096 (core) and -1024~1024
8028 && INTVAL (index
) > -256
8029 && (INTVAL (index
) & 3) == 0);
8031 if (TARGET_REALLY_IWMMXT
&& VALID_IWMMXT_REG_MODE (mode
))
8033 /* For DImode assume values will usually live in core regs
8034 and only allow LDRD addressing modes. */
8035 if (!TARGET_LDRD
|| mode
!= DImode
)
8036 return (code
== CONST_INT
8037 && INTVAL (index
) < 1024
8038 && INTVAL (index
) > -1024
8039 && (INTVAL (index
) & 3) == 0);
8042 /* For quad modes, we restrict the constant offset to be slightly less
8043 than what the instruction format permits. We do this because for
8044 quad mode moves, we will actually decompose them into two separate
8045 double-mode reads or writes. INDEX must therefore be a valid
8046 (double-mode) offset and so should INDEX+8. */
8047 if (TARGET_NEON
&& VALID_NEON_QREG_MODE (mode
))
8048 return (code
== CONST_INT
8049 && INTVAL (index
) < 1016
8050 && INTVAL (index
) > -1024
8051 && (INTVAL (index
) & 3) == 0);
8053 /* We have no such constraint on double mode offsets, so we permit the
8054 full range of the instruction format. */
8055 if (TARGET_NEON
&& VALID_NEON_DREG_MODE (mode
))
8056 return (code
== CONST_INT
8057 && INTVAL (index
) < 1024
8058 && INTVAL (index
) > -1024
8059 && (INTVAL (index
) & 3) == 0);
8061 if (arm_address_register_rtx_p (index
, strict_p
)
8062 && (GET_MODE_SIZE (mode
) <= 4))
8065 if (mode
== DImode
|| mode
== DFmode
)
8067 if (code
== CONST_INT
)
8069 HOST_WIDE_INT val
= INTVAL (index
);
8070 /* Thumb-2 ldrd only has reg+const addressing modes.
8071 Assume we emit ldrd or 2x ldr if !TARGET_LDRD.
8072 If vldr is selected it uses arm_coproc_mem_operand. */
8074 return IN_RANGE (val
, -1020, 1020) && (val
& 3) == 0;
8076 return IN_RANGE (val
, -255, 4095 - 4);
8084 rtx xiop0
= XEXP (index
, 0);
8085 rtx xiop1
= XEXP (index
, 1);
8087 return ((arm_address_register_rtx_p (xiop0
, strict_p
)
8088 && thumb2_index_mul_operand (xiop1
))
8089 || (arm_address_register_rtx_p (xiop1
, strict_p
)
8090 && thumb2_index_mul_operand (xiop0
)));
8092 else if (code
== ASHIFT
)
8094 rtx op
= XEXP (index
, 1);
8096 return (arm_address_register_rtx_p (XEXP (index
, 0), strict_p
)
8099 && INTVAL (op
) <= 3);
8102 return (code
== CONST_INT
8103 && INTVAL (index
) < 4096
8104 && INTVAL (index
) > -256);
8107 /* Return nonzero if X is valid as a 16-bit Thumb state base register. */
8109 thumb1_base_register_rtx_p (rtx x
, machine_mode mode
, int strict_p
)
8119 return THUMB1_REGNO_MODE_OK_FOR_BASE_P (regno
, mode
);
8121 return (regno
<= LAST_LO_REGNUM
8122 || regno
> LAST_VIRTUAL_REGISTER
8123 || regno
== FRAME_POINTER_REGNUM
8124 || (GET_MODE_SIZE (mode
) >= 4
8125 && (regno
== STACK_POINTER_REGNUM
8126 || regno
>= FIRST_PSEUDO_REGISTER
8127 || x
== hard_frame_pointer_rtx
8128 || x
== arg_pointer_rtx
)));
8131 /* Return nonzero if x is a legitimate index register. This is the case
8132 for any base register that can access a QImode object. */
8134 thumb1_index_register_rtx_p (rtx x
, int strict_p
)
8136 return thumb1_base_register_rtx_p (x
, QImode
, strict_p
);
8139 /* Return nonzero if x is a legitimate 16-bit Thumb-state address.
8141 The AP may be eliminated to either the SP or the FP, so we use the
8142 least common denominator, e.g. SImode, and offsets from 0 to 64.
8144 ??? Verify whether the above is the right approach.
8146 ??? Also, the FP may be eliminated to the SP, so perhaps that
8147 needs special handling also.
8149 ??? Look at how the mips16 port solves this problem. It probably uses
8150 better ways to solve some of these problems.
8152 Although it is not incorrect, we don't accept QImode and HImode
8153 addresses based on the frame pointer or arg pointer until the
8154 reload pass starts. This is so that eliminating such addresses
8155 into stack based ones won't produce impossible code. */
8157 thumb1_legitimate_address_p (machine_mode mode
, rtx x
, int strict_p
)
8159 if (TARGET_HAVE_MOVT
&& can_avoid_literal_pool_for_label_p (x
))
8162 /* ??? Not clear if this is right. Experiment. */
8163 if (GET_MODE_SIZE (mode
) < 4
8164 && !(reload_in_progress
|| reload_completed
)
8165 && (reg_mentioned_p (frame_pointer_rtx
, x
)
8166 || reg_mentioned_p (arg_pointer_rtx
, x
)
8167 || reg_mentioned_p (virtual_incoming_args_rtx
, x
)
8168 || reg_mentioned_p (virtual_outgoing_args_rtx
, x
)
8169 || reg_mentioned_p (virtual_stack_dynamic_rtx
, x
)
8170 || reg_mentioned_p (virtual_stack_vars_rtx
, x
)))
8173 /* Accept any base register. SP only in SImode or larger. */
8174 else if (thumb1_base_register_rtx_p (x
, mode
, strict_p
))
8177 /* This is PC relative data before arm_reorg runs. */
8178 else if (GET_MODE_SIZE (mode
) >= 4 && CONSTANT_P (x
)
8179 && GET_CODE (x
) == SYMBOL_REF
8180 && CONSTANT_POOL_ADDRESS_P (x
) && !flag_pic
)
8183 /* This is PC relative data after arm_reorg runs. */
8184 else if ((GET_MODE_SIZE (mode
) >= 4 || mode
== HFmode
)
8186 && (GET_CODE (x
) == LABEL_REF
8187 || (GET_CODE (x
) == CONST
8188 && GET_CODE (XEXP (x
, 0)) == PLUS
8189 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == LABEL_REF
8190 && CONST_INT_P (XEXP (XEXP (x
, 0), 1)))))
8193 /* Post-inc indexing only supported for SImode and larger. */
8194 else if (GET_CODE (x
) == POST_INC
&& GET_MODE_SIZE (mode
) >= 4
8195 && thumb1_index_register_rtx_p (XEXP (x
, 0), strict_p
))
8198 else if (GET_CODE (x
) == PLUS
)
8200 /* REG+REG address can be any two index registers. */
8201 /* We disallow FRAME+REG addressing since we know that FRAME
8202 will be replaced with STACK, and SP relative addressing only
8203 permits SP+OFFSET. */
8204 if (GET_MODE_SIZE (mode
) <= 4
8205 && XEXP (x
, 0) != frame_pointer_rtx
8206 && XEXP (x
, 1) != frame_pointer_rtx
8207 && thumb1_index_register_rtx_p (XEXP (x
, 0), strict_p
)
8208 && (thumb1_index_register_rtx_p (XEXP (x
, 1), strict_p
)
8209 || (!strict_p
&& will_be_in_index_register (XEXP (x
, 1)))))
8212 /* REG+const has 5-7 bit offset for non-SP registers. */
8213 else if ((thumb1_index_register_rtx_p (XEXP (x
, 0), strict_p
)
8214 || XEXP (x
, 0) == arg_pointer_rtx
)
8215 && CONST_INT_P (XEXP (x
, 1))
8216 && thumb_legitimate_offset_p (mode
, INTVAL (XEXP (x
, 1))))
8219 /* REG+const has 10-bit offset for SP, but only SImode and
8220 larger is supported. */
8221 /* ??? Should probably check for DI/DFmode overflow here
8222 just like GO_IF_LEGITIMATE_OFFSET does. */
8223 else if (REG_P (XEXP (x
, 0))
8224 && REGNO (XEXP (x
, 0)) == STACK_POINTER_REGNUM
8225 && GET_MODE_SIZE (mode
) >= 4
8226 && CONST_INT_P (XEXP (x
, 1))
8227 && INTVAL (XEXP (x
, 1)) >= 0
8228 && INTVAL (XEXP (x
, 1)) + GET_MODE_SIZE (mode
) <= 1024
8229 && (INTVAL (XEXP (x
, 1)) & 3) == 0)
8232 else if (REG_P (XEXP (x
, 0))
8233 && (REGNO (XEXP (x
, 0)) == FRAME_POINTER_REGNUM
8234 || REGNO (XEXP (x
, 0)) == ARG_POINTER_REGNUM
8235 || (REGNO (XEXP (x
, 0)) >= FIRST_VIRTUAL_REGISTER
8236 && REGNO (XEXP (x
, 0))
8237 <= LAST_VIRTUAL_POINTER_REGISTER
))
8238 && GET_MODE_SIZE (mode
) >= 4
8239 && CONST_INT_P (XEXP (x
, 1))
8240 && (INTVAL (XEXP (x
, 1)) & 3) == 0)
8244 else if (GET_MODE_CLASS (mode
) != MODE_FLOAT
8245 && GET_MODE_SIZE (mode
) == 4
8246 && GET_CODE (x
) == SYMBOL_REF
8247 && CONSTANT_POOL_ADDRESS_P (x
)
8249 && symbol_mentioned_p (get_pool_constant (x
))
8250 && ! pcrel_constant_p (get_pool_constant (x
))))
8256 /* Return nonzero if VAL can be used as an offset in a Thumb-state address
8257 instruction of mode MODE. */
8259 thumb_legitimate_offset_p (machine_mode mode
, HOST_WIDE_INT val
)
8261 switch (GET_MODE_SIZE (mode
))
8264 return val
>= 0 && val
< 32;
8267 return val
>= 0 && val
< 64 && (val
& 1) == 0;
8271 && (val
+ GET_MODE_SIZE (mode
)) <= 128
8277 arm_legitimate_address_p (machine_mode mode
, rtx x
, bool strict_p
)
8280 return arm_legitimate_address_outer_p (mode
, x
, SET
, strict_p
);
8281 else if (TARGET_THUMB2
)
8282 return thumb2_legitimate_address_p (mode
, x
, strict_p
);
8283 else /* if (TARGET_THUMB1) */
8284 return thumb1_legitimate_address_p (mode
, x
, strict_p
);
8287 /* Worker function for TARGET_PREFERRED_RELOAD_CLASS.
8289 Given an rtx X being reloaded into a reg required to be
8290 in class CLASS, return the class of reg to actually use.
8291 In general this is just CLASS, but for the Thumb core registers and
8292 immediate constants we prefer a LO_REGS class or a subset. */
8295 arm_preferred_reload_class (rtx x ATTRIBUTE_UNUSED
, reg_class_t rclass
)
8301 if (rclass
== GENERAL_REGS
)
8308 /* Build the SYMBOL_REF for __tls_get_addr. */
8310 static GTY(()) rtx tls_get_addr_libfunc
;
8313 get_tls_get_addr (void)
8315 if (!tls_get_addr_libfunc
)
8316 tls_get_addr_libfunc
= init_one_libfunc ("__tls_get_addr");
8317 return tls_get_addr_libfunc
;
8321 arm_load_tp (rtx target
)
8324 target
= gen_reg_rtx (SImode
);
8328 /* Can return in any reg. */
8329 emit_insn (gen_load_tp_hard (target
));
8333 /* Always returned in r0. Immediately copy the result into a pseudo,
8334 otherwise other uses of r0 (e.g. setting up function arguments) may
8335 clobber the value. */
8339 emit_insn (gen_load_tp_soft ());
8341 tmp
= gen_rtx_REG (SImode
, R0_REGNUM
);
8342 emit_move_insn (target
, tmp
);
8348 load_tls_operand (rtx x
, rtx reg
)
8352 if (reg
== NULL_RTX
)
8353 reg
= gen_reg_rtx (SImode
);
8355 tmp
= gen_rtx_CONST (SImode
, x
);
8357 emit_move_insn (reg
, tmp
);
8363 arm_call_tls_get_addr (rtx x
, rtx reg
, rtx
*valuep
, int reloc
)
8365 rtx label
, labelno
, sum
;
8367 gcc_assert (reloc
!= TLS_DESCSEQ
);
8370 labelno
= GEN_INT (pic_labelno
++);
8371 label
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, labelno
), UNSPEC_PIC_LABEL
);
8372 label
= gen_rtx_CONST (VOIDmode
, label
);
8374 sum
= gen_rtx_UNSPEC (Pmode
,
8375 gen_rtvec (4, x
, GEN_INT (reloc
), label
,
8376 GEN_INT (TARGET_ARM
? 8 : 4)),
8378 reg
= load_tls_operand (sum
, reg
);
8381 emit_insn (gen_pic_add_dot_plus_eight (reg
, reg
, labelno
));
8383 emit_insn (gen_pic_add_dot_plus_four (reg
, reg
, labelno
));
8385 *valuep
= emit_library_call_value (get_tls_get_addr (), NULL_RTX
,
8386 LCT_PURE
, /* LCT_CONST? */
8389 rtx_insn
*insns
= get_insns ();
8396 arm_tls_descseq_addr (rtx x
, rtx reg
)
8398 rtx labelno
= GEN_INT (pic_labelno
++);
8399 rtx label
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, labelno
), UNSPEC_PIC_LABEL
);
8400 rtx sum
= gen_rtx_UNSPEC (Pmode
,
8401 gen_rtvec (4, x
, GEN_INT (TLS_DESCSEQ
),
8402 gen_rtx_CONST (VOIDmode
, label
),
8403 GEN_INT (!TARGET_ARM
)),
8405 rtx reg0
= load_tls_operand (sum
, gen_rtx_REG (SImode
, R0_REGNUM
));
8407 emit_insn (gen_tlscall (x
, labelno
));
8409 reg
= gen_reg_rtx (SImode
);
8411 gcc_assert (REGNO (reg
) != R0_REGNUM
);
8413 emit_move_insn (reg
, reg0
);
8419 legitimize_tls_address (rtx x
, rtx reg
)
8421 rtx dest
, tp
, label
, labelno
, sum
, ret
, eqv
, addend
;
8423 unsigned int model
= SYMBOL_REF_TLS_MODEL (x
);
8427 case TLS_MODEL_GLOBAL_DYNAMIC
:
8428 if (TARGET_GNU2_TLS
)
8430 reg
= arm_tls_descseq_addr (x
, reg
);
8432 tp
= arm_load_tp (NULL_RTX
);
8434 dest
= gen_rtx_PLUS (Pmode
, tp
, reg
);
8438 /* Original scheme */
8439 insns
= arm_call_tls_get_addr (x
, reg
, &ret
, TLS_GD32
);
8440 dest
= gen_reg_rtx (Pmode
);
8441 emit_libcall_block (insns
, dest
, ret
, x
);
8445 case TLS_MODEL_LOCAL_DYNAMIC
:
8446 if (TARGET_GNU2_TLS
)
8448 reg
= arm_tls_descseq_addr (x
, reg
);
8450 tp
= arm_load_tp (NULL_RTX
);
8452 dest
= gen_rtx_PLUS (Pmode
, tp
, reg
);
8456 insns
= arm_call_tls_get_addr (x
, reg
, &ret
, TLS_LDM32
);
8458 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
8459 share the LDM result with other LD model accesses. */
8460 eqv
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const1_rtx
),
8462 dest
= gen_reg_rtx (Pmode
);
8463 emit_libcall_block (insns
, dest
, ret
, eqv
);
8465 /* Load the addend. */
8466 addend
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, x
,
8467 GEN_INT (TLS_LDO32
)),
8469 addend
= force_reg (SImode
, gen_rtx_CONST (SImode
, addend
));
8470 dest
= gen_rtx_PLUS (Pmode
, dest
, addend
);
8474 case TLS_MODEL_INITIAL_EXEC
:
8475 labelno
= GEN_INT (pic_labelno
++);
8476 label
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, labelno
), UNSPEC_PIC_LABEL
);
8477 label
= gen_rtx_CONST (VOIDmode
, label
);
8478 sum
= gen_rtx_UNSPEC (Pmode
,
8479 gen_rtvec (4, x
, GEN_INT (TLS_IE32
), label
,
8480 GEN_INT (TARGET_ARM
? 8 : 4)),
8482 reg
= load_tls_operand (sum
, reg
);
8485 emit_insn (gen_tls_load_dot_plus_eight (reg
, reg
, labelno
));
8486 else if (TARGET_THUMB2
)
8487 emit_insn (gen_tls_load_dot_plus_four (reg
, NULL
, reg
, labelno
));
8490 emit_insn (gen_pic_add_dot_plus_four (reg
, reg
, labelno
));
8491 emit_move_insn (reg
, gen_const_mem (SImode
, reg
));
8494 tp
= arm_load_tp (NULL_RTX
);
8496 return gen_rtx_PLUS (Pmode
, tp
, reg
);
8498 case TLS_MODEL_LOCAL_EXEC
:
8499 tp
= arm_load_tp (NULL_RTX
);
8501 reg
= gen_rtx_UNSPEC (Pmode
,
8502 gen_rtvec (2, x
, GEN_INT (TLS_LE32
)),
8504 reg
= force_reg (SImode
, gen_rtx_CONST (SImode
, reg
));
8506 return gen_rtx_PLUS (Pmode
, tp
, reg
);
8513 /* Try machine-dependent ways of modifying an illegitimate address
8514 to be legitimate. If we find one, return the new, valid address. */
8516 arm_legitimize_address (rtx x
, rtx orig_x
, machine_mode mode
)
8518 if (arm_tls_referenced_p (x
))
8522 if (GET_CODE (x
) == CONST
&& GET_CODE (XEXP (x
, 0)) == PLUS
)
8524 addend
= XEXP (XEXP (x
, 0), 1);
8525 x
= XEXP (XEXP (x
, 0), 0);
8528 if (GET_CODE (x
) != SYMBOL_REF
)
8531 gcc_assert (SYMBOL_REF_TLS_MODEL (x
) != 0);
8533 x
= legitimize_tls_address (x
, NULL_RTX
);
8537 x
= gen_rtx_PLUS (SImode
, x
, addend
);
8546 /* TODO: legitimize_address for Thumb2. */
8549 return thumb_legitimize_address (x
, orig_x
, mode
);
8552 if (GET_CODE (x
) == PLUS
)
8554 rtx xop0
= XEXP (x
, 0);
8555 rtx xop1
= XEXP (x
, 1);
8557 if (CONSTANT_P (xop0
) && !symbol_mentioned_p (xop0
))
8558 xop0
= force_reg (SImode
, xop0
);
8560 if (CONSTANT_P (xop1
) && !CONST_INT_P (xop1
)
8561 && !symbol_mentioned_p (xop1
))
8562 xop1
= force_reg (SImode
, xop1
);
8564 if (ARM_BASE_REGISTER_RTX_P (xop0
)
8565 && CONST_INT_P (xop1
))
8567 HOST_WIDE_INT n
, low_n
;
8571 /* VFP addressing modes actually allow greater offsets, but for
8572 now we just stick with the lowest common denominator. */
8573 if (mode
== DImode
|| mode
== DFmode
)
8585 low_n
= ((mode
) == TImode
? 0
8586 : n
>= 0 ? (n
& 0xfff) : -((-n
) & 0xfff));
8590 base_reg
= gen_reg_rtx (SImode
);
8591 val
= force_operand (plus_constant (Pmode
, xop0
, n
), NULL_RTX
);
8592 emit_move_insn (base_reg
, val
);
8593 x
= plus_constant (Pmode
, base_reg
, low_n
);
8595 else if (xop0
!= XEXP (x
, 0) || xop1
!= XEXP (x
, 1))
8596 x
= gen_rtx_PLUS (SImode
, xop0
, xop1
);
8599 /* XXX We don't allow MINUS any more -- see comment in
8600 arm_legitimate_address_outer_p (). */
8601 else if (GET_CODE (x
) == MINUS
)
8603 rtx xop0
= XEXP (x
, 0);
8604 rtx xop1
= XEXP (x
, 1);
8606 if (CONSTANT_P (xop0
))
8607 xop0
= force_reg (SImode
, xop0
);
8609 if (CONSTANT_P (xop1
) && ! symbol_mentioned_p (xop1
))
8610 xop1
= force_reg (SImode
, xop1
);
8612 if (xop0
!= XEXP (x
, 0) || xop1
!= XEXP (x
, 1))
8613 x
= gen_rtx_MINUS (SImode
, xop0
, xop1
);
8616 /* Make sure to take full advantage of the pre-indexed addressing mode
8617 with absolute addresses which often allows for the base register to
8618 be factorized for multiple adjacent memory references, and it might
8619 even allows for the mini pool to be avoided entirely. */
8620 else if (CONST_INT_P (x
) && optimize
> 0)
8623 HOST_WIDE_INT mask
, base
, index
;
8626 /* ldr and ldrb can use a 12-bit index, ldrsb and the rest can only
8627 use a 8-bit index. So let's use a 12-bit index for SImode only and
8628 hope that arm_gen_constant will enable ldrb to use more bits. */
8629 bits
= (mode
== SImode
) ? 12 : 8;
8630 mask
= (1 << bits
) - 1;
8631 base
= INTVAL (x
) & ~mask
;
8632 index
= INTVAL (x
) & mask
;
8633 if (bit_count (base
& 0xffffffff) > (32 - bits
)/2)
8635 /* It'll most probably be more efficient to generate the base
8636 with more bits set and use a negative index instead. */
8640 base_reg
= force_reg (SImode
, GEN_INT (base
));
8641 x
= plus_constant (Pmode
, base_reg
, index
);
8646 /* We need to find and carefully transform any SYMBOL and LABEL
8647 references; so go back to the original address expression. */
8648 rtx new_x
= legitimize_pic_address (orig_x
, mode
, NULL_RTX
);
8650 if (new_x
!= orig_x
)
8658 /* Try machine-dependent ways of modifying an illegitimate Thumb address
8659 to be legitimate. If we find one, return the new, valid address. */
8661 thumb_legitimize_address (rtx x
, rtx orig_x
, machine_mode mode
)
8663 if (GET_CODE (x
) == PLUS
8664 && CONST_INT_P (XEXP (x
, 1))
8665 && (INTVAL (XEXP (x
, 1)) >= 32 * GET_MODE_SIZE (mode
)
8666 || INTVAL (XEXP (x
, 1)) < 0))
8668 rtx xop0
= XEXP (x
, 0);
8669 rtx xop1
= XEXP (x
, 1);
8670 HOST_WIDE_INT offset
= INTVAL (xop1
);
8672 /* Try and fold the offset into a biasing of the base register and
8673 then offsetting that. Don't do this when optimizing for space
8674 since it can cause too many CSEs. */
8675 if (optimize_size
&& offset
>= 0
8676 && offset
< 256 + 31 * GET_MODE_SIZE (mode
))
8678 HOST_WIDE_INT delta
;
8681 delta
= offset
- (256 - GET_MODE_SIZE (mode
));
8682 else if (offset
< 32 * GET_MODE_SIZE (mode
) + 8)
8683 delta
= 31 * GET_MODE_SIZE (mode
);
8685 delta
= offset
& (~31 * GET_MODE_SIZE (mode
));
8687 xop0
= force_operand (plus_constant (Pmode
, xop0
, offset
- delta
),
8689 x
= plus_constant (Pmode
, xop0
, delta
);
8691 else if (offset
< 0 && offset
> -256)
8692 /* Small negative offsets are best done with a subtract before the
8693 dereference, forcing these into a register normally takes two
8695 x
= force_operand (x
, NULL_RTX
);
8698 /* For the remaining cases, force the constant into a register. */
8699 xop1
= force_reg (SImode
, xop1
);
8700 x
= gen_rtx_PLUS (SImode
, xop0
, xop1
);
8703 else if (GET_CODE (x
) == PLUS
8704 && s_register_operand (XEXP (x
, 1), SImode
)
8705 && !s_register_operand (XEXP (x
, 0), SImode
))
8707 rtx xop0
= force_operand (XEXP (x
, 0), NULL_RTX
);
8709 x
= gen_rtx_PLUS (SImode
, xop0
, XEXP (x
, 1));
8714 /* We need to find and carefully transform any SYMBOL and LABEL
8715 references; so go back to the original address expression. */
8716 rtx new_x
= legitimize_pic_address (orig_x
, mode
, NULL_RTX
);
8718 if (new_x
!= orig_x
)
8725 /* Return TRUE if X contains any TLS symbol references. */
8728 arm_tls_referenced_p (rtx x
)
8730 if (! TARGET_HAVE_TLS
)
8733 subrtx_iterator::array_type array
;
8734 FOR_EACH_SUBRTX (iter
, array
, x
, ALL
)
8736 const_rtx x
= *iter
;
8737 if (GET_CODE (x
) == SYMBOL_REF
&& SYMBOL_REF_TLS_MODEL (x
) != 0)
8739 /* ARM currently does not provide relocations to encode TLS variables
8740 into AArch32 instructions, only data, so there is no way to
8741 currently implement these if a literal pool is disabled. */
8742 if (arm_disable_literal_pool
)
8743 sorry ("accessing thread-local storage is not currently supported "
8744 "with -mpure-code or -mslow-flash-data");
8749 /* Don't recurse into UNSPEC_TLS looking for TLS symbols; these are
8750 TLS offsets, not real symbol references. */
8751 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLS
)
8752 iter
.skip_subrtxes ();
8757 /* Implement TARGET_LEGITIMATE_CONSTANT_P.
8759 On the ARM, allow any integer (invalid ones are removed later by insn
8760 patterns), nice doubles and symbol_refs which refer to the function's
8763 When generating pic allow anything. */
8766 arm_legitimate_constant_p_1 (machine_mode
, rtx x
)
8768 return flag_pic
|| !label_mentioned_p (x
);
8772 thumb_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED
, rtx x
)
8774 /* Splitters for TARGET_USE_MOVT call arm_emit_movpair which creates high
8775 RTX. These RTX must therefore be allowed for Thumb-1 so that when run
8776 for ARMv8-M Baseline or later the result is valid. */
8777 if (TARGET_HAVE_MOVT
&& GET_CODE (x
) == HIGH
)
8780 return (CONST_INT_P (x
)
8781 || CONST_DOUBLE_P (x
)
8782 || CONSTANT_ADDRESS_P (x
)
8783 || (TARGET_HAVE_MOVT
&& GET_CODE (x
) == SYMBOL_REF
)
8788 arm_legitimate_constant_p (machine_mode mode
, rtx x
)
8790 return (!arm_cannot_force_const_mem (mode
, x
)
8792 ? arm_legitimate_constant_p_1 (mode
, x
)
8793 : thumb_legitimate_constant_p (mode
, x
)));
8796 /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */
8799 arm_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED
, rtx x
)
8803 if (ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P
)
8805 split_const (x
, &base
, &offset
);
8806 if (GET_CODE (base
) == SYMBOL_REF
8807 && !offset_within_block_p (base
, INTVAL (offset
)))
8810 return arm_tls_referenced_p (x
);
8813 #define REG_OR_SUBREG_REG(X) \
8815 || (GET_CODE (X) == SUBREG && REG_P (SUBREG_REG (X))))
8817 #define REG_OR_SUBREG_RTX(X) \
8818 (REG_P (X) ? (X) : SUBREG_REG (X))
8821 thumb1_rtx_costs (rtx x
, enum rtx_code code
, enum rtx_code outer
)
8823 machine_mode mode
= GET_MODE (x
);
8832 return (mode
== SImode
) ? COSTS_N_INSNS (1) : COSTS_N_INSNS (2);
8839 return COSTS_N_INSNS (1);
8842 if (arm_arch6m
&& arm_m_profile_small_mul
)
8843 return COSTS_N_INSNS (32);
8845 if (CONST_INT_P (XEXP (x
, 1)))
8848 unsigned HOST_WIDE_INT i
= INTVAL (XEXP (x
, 1));
8855 return COSTS_N_INSNS (2) + cycles
;
8857 return COSTS_N_INSNS (1) + 16;
8860 /* A SET doesn't have a mode, so let's look at the SET_DEST to get
8862 words
= ARM_NUM_INTS (GET_MODE_SIZE (GET_MODE (SET_DEST (x
))));
8863 return (COSTS_N_INSNS (words
)
8864 + 4 * ((MEM_P (SET_SRC (x
)))
8865 + MEM_P (SET_DEST (x
))));
8870 if (UINTVAL (x
) < 256
8871 /* 16-bit constant. */
8872 || (TARGET_HAVE_MOVT
&& !(INTVAL (x
) & 0xffff0000)))
8874 if (thumb_shiftable_const (INTVAL (x
)))
8875 return COSTS_N_INSNS (2);
8876 return COSTS_N_INSNS (3);
8878 else if ((outer
== PLUS
|| outer
== COMPARE
)
8879 && INTVAL (x
) < 256 && INTVAL (x
) > -256)
8881 else if ((outer
== IOR
|| outer
== XOR
|| outer
== AND
)
8882 && INTVAL (x
) < 256 && INTVAL (x
) >= -256)
8883 return COSTS_N_INSNS (1);
8884 else if (outer
== AND
)
8887 /* This duplicates the tests in the andsi3 expander. */
8888 for (i
= 9; i
<= 31; i
++)
8889 if ((HOST_WIDE_INT_1
<< i
) - 1 == INTVAL (x
)
8890 || (HOST_WIDE_INT_1
<< i
) - 1 == ~INTVAL (x
))
8891 return COSTS_N_INSNS (2);
8893 else if (outer
== ASHIFT
|| outer
== ASHIFTRT
8894 || outer
== LSHIFTRT
)
8896 return COSTS_N_INSNS (2);
8902 return COSTS_N_INSNS (3);
8920 /* XXX another guess. */
8921 /* Memory costs quite a lot for the first word, but subsequent words
8922 load at the equivalent of a single insn each. */
8923 return (10 + 4 * ((GET_MODE_SIZE (mode
) - 1) / UNITS_PER_WORD
)
8924 + ((GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
8929 if (GET_CODE (XEXP (x
, 1)) == PC
|| GET_CODE (XEXP (x
, 2)) == PC
)
8935 total
= mode
== DImode
? COSTS_N_INSNS (1) : 0;
8936 total
+= thumb1_rtx_costs (XEXP (x
, 0), GET_CODE (XEXP (x
, 0)), code
);
8942 return total
+ COSTS_N_INSNS (1);
8944 /* Assume a two-shift sequence. Increase the cost slightly so
8945 we prefer actual shifts over an extend operation. */
8946 return total
+ 1 + COSTS_N_INSNS (2);
8953 /* Estimates the size cost of thumb1 instructions.
8954 For now most of the code is copied from thumb1_rtx_costs. We need more
8955 fine grain tuning when we have more related test cases. */
8957 thumb1_size_rtx_costs (rtx x
, enum rtx_code code
, enum rtx_code outer
)
8959 machine_mode mode
= GET_MODE (x
);
8968 return (mode
== SImode
) ? COSTS_N_INSNS (1) : COSTS_N_INSNS (2);
8972 /* Thumb-1 needs two instructions to fulfill shiftadd/shiftsub0/shiftsub1
8973 defined by RTL expansion, especially for the expansion of
8975 if ((GET_CODE (XEXP (x
, 0)) == MULT
8976 && power_of_two_operand (XEXP (XEXP (x
,0),1), SImode
))
8977 || (GET_CODE (XEXP (x
, 1)) == MULT
8978 && power_of_two_operand (XEXP (XEXP (x
, 1), 1), SImode
)))
8979 return COSTS_N_INSNS (2);
8984 return COSTS_N_INSNS (1);
8987 if (CONST_INT_P (XEXP (x
, 1)))
8989 /* Thumb1 mul instruction can't operate on const. We must Load it
8990 into a register first. */
8991 int const_size
= thumb1_size_rtx_costs (XEXP (x
, 1), CONST_INT
, SET
);
8992 /* For the targets which have a very small and high-latency multiply
8993 unit, we prefer to synthesize the mult with up to 5 instructions,
8994 giving a good balance between size and performance. */
8995 if (arm_arch6m
&& arm_m_profile_small_mul
)
8996 return COSTS_N_INSNS (5);
8998 return COSTS_N_INSNS (1) + const_size
;
9000 return COSTS_N_INSNS (1);
9003 /* A SET doesn't have a mode, so let's look at the SET_DEST to get
9005 words
= ARM_NUM_INTS (GET_MODE_SIZE (GET_MODE (SET_DEST (x
))));
9006 cost
= COSTS_N_INSNS (words
);
9007 if (satisfies_constraint_J (SET_SRC (x
))
9008 || satisfies_constraint_K (SET_SRC (x
))
9009 /* Too big an immediate for a 2-byte mov, using MOVT. */
9010 || (CONST_INT_P (SET_SRC (x
))
9011 && UINTVAL (SET_SRC (x
)) >= 256
9013 && satisfies_constraint_j (SET_SRC (x
)))
9014 /* thumb1_movdi_insn. */
9015 || ((words
> 1) && MEM_P (SET_SRC (x
))))
9016 cost
+= COSTS_N_INSNS (1);
9022 if (UINTVAL (x
) < 256)
9023 return COSTS_N_INSNS (1);
9024 /* movw is 4byte long. */
9025 if (TARGET_HAVE_MOVT
&& !(INTVAL (x
) & 0xffff0000))
9026 return COSTS_N_INSNS (2);
9027 /* See split "TARGET_THUMB1 && satisfies_constraint_J". */
9028 if (INTVAL (x
) >= -255 && INTVAL (x
) <= -1)
9029 return COSTS_N_INSNS (2);
9030 /* See split "TARGET_THUMB1 && satisfies_constraint_K". */
9031 if (thumb_shiftable_const (INTVAL (x
)))
9032 return COSTS_N_INSNS (2);
9033 return COSTS_N_INSNS (3);
9035 else if ((outer
== PLUS
|| outer
== COMPARE
)
9036 && INTVAL (x
) < 256 && INTVAL (x
) > -256)
9038 else if ((outer
== IOR
|| outer
== XOR
|| outer
== AND
)
9039 && INTVAL (x
) < 256 && INTVAL (x
) >= -256)
9040 return COSTS_N_INSNS (1);
9041 else if (outer
== AND
)
9044 /* This duplicates the tests in the andsi3 expander. */
9045 for (i
= 9; i
<= 31; i
++)
9046 if ((HOST_WIDE_INT_1
<< i
) - 1 == INTVAL (x
)
9047 || (HOST_WIDE_INT_1
<< i
) - 1 == ~INTVAL (x
))
9048 return COSTS_N_INSNS (2);
9050 else if (outer
== ASHIFT
|| outer
== ASHIFTRT
9051 || outer
== LSHIFTRT
)
9053 return COSTS_N_INSNS (2);
9059 return COSTS_N_INSNS (3);
9073 return COSTS_N_INSNS (1);
9076 return (COSTS_N_INSNS (1)
9078 * ((GET_MODE_SIZE (mode
) - 1) / UNITS_PER_WORD
)
9079 + ((GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
9080 ? COSTS_N_INSNS (1) : 0));
9084 if (GET_CODE (XEXP (x
, 1)) == PC
|| GET_CODE (XEXP (x
, 2)) == PC
)
9089 /* XXX still guessing. */
9090 switch (GET_MODE (XEXP (x
, 0)))
9093 return (1 + (mode
== DImode
? 4 : 0)
9094 + (MEM_P (XEXP (x
, 0)) ? 10 : 0));
9097 return (4 + (mode
== DImode
? 4 : 0)
9098 + (MEM_P (XEXP (x
, 0)) ? 10 : 0));
9101 return (1 + (MEM_P (XEXP (x
, 0)) ? 10 : 0));
9112 /* Helper function for arm_rtx_costs. If the operand is a valid shift
9113 operand, then return the operand that is being shifted. If the shift
9114 is not by a constant, then set SHIFT_REG to point to the operand.
9115 Return NULL if OP is not a shifter operand. */
9117 shifter_op_p (rtx op
, rtx
*shift_reg
)
9119 enum rtx_code code
= GET_CODE (op
);
9121 if (code
== MULT
&& CONST_INT_P (XEXP (op
, 1))
9122 && exact_log2 (INTVAL (XEXP (op
, 1))) > 0)
9123 return XEXP (op
, 0);
9124 else if (code
== ROTATE
&& CONST_INT_P (XEXP (op
, 1)))
9125 return XEXP (op
, 0);
9126 else if (code
== ROTATERT
|| code
== ASHIFT
|| code
== LSHIFTRT
9127 || code
== ASHIFTRT
)
9129 if (!CONST_INT_P (XEXP (op
, 1)))
9130 *shift_reg
= XEXP (op
, 1);
9131 return XEXP (op
, 0);
9138 arm_unspec_cost (rtx x
, enum rtx_code
/* outer_code */, bool speed_p
, int *cost
)
9140 const struct cpu_cost_table
*extra_cost
= current_tune
->insn_extra_cost
;
9141 rtx_code code
= GET_CODE (x
);
9142 gcc_assert (code
== UNSPEC
|| code
== UNSPEC_VOLATILE
);
9144 switch (XINT (x
, 1))
9146 case UNSPEC_UNALIGNED_LOAD
:
9147 /* We can only do unaligned loads into the integer unit, and we can't
9149 *cost
= COSTS_N_INSNS (ARM_NUM_REGS (GET_MODE (x
)));
9151 *cost
+= (ARM_NUM_REGS (GET_MODE (x
)) * extra_cost
->ldst
.load
9152 + extra_cost
->ldst
.load_unaligned
);
9155 *cost
+= arm_address_cost (XEXP (XVECEXP (x
, 0, 0), 0), GET_MODE (x
),
9156 ADDR_SPACE_GENERIC
, speed_p
);
9160 case UNSPEC_UNALIGNED_STORE
:
9161 *cost
= COSTS_N_INSNS (ARM_NUM_REGS (GET_MODE (x
)));
9163 *cost
+= (ARM_NUM_REGS (GET_MODE (x
)) * extra_cost
->ldst
.store
9164 + extra_cost
->ldst
.store_unaligned
);
9166 *cost
+= rtx_cost (XVECEXP (x
, 0, 0), VOIDmode
, UNSPEC
, 0, speed_p
);
9168 *cost
+= arm_address_cost (XEXP (XVECEXP (x
, 0, 0), 0), GET_MODE (x
),
9169 ADDR_SPACE_GENERIC
, speed_p
);
9180 *cost
+= extra_cost
->fp
[GET_MODE (x
) == DFmode
].roundint
;
9184 *cost
= COSTS_N_INSNS (2);
9190 /* Cost of a libcall. We assume one insn per argument, an amount for the
9191 call (one insn for -Os) and then one for processing the result. */
9192 #define LIBCALL_COST(N) COSTS_N_INSNS (N + (speed_p ? 18 : 2))
9194 #define HANDLE_NARROW_SHIFT_ARITH(OP, IDX) \
9197 shift_op = shifter_op_p (XEXP (x, IDX), &shift_reg); \
9198 if (shift_op != NULL \
9199 && arm_rtx_shift_left_p (XEXP (x, IDX))) \
9204 *cost += extra_cost->alu.arith_shift_reg; \
9205 *cost += rtx_cost (shift_reg, GET_MODE (shift_reg), \
9206 ASHIFT, 1, speed_p); \
9209 *cost += extra_cost->alu.arith_shift; \
9211 *cost += (rtx_cost (shift_op, GET_MODE (shift_op), \
9212 ASHIFT, 0, speed_p) \
9213 + rtx_cost (XEXP (x, 1 - IDX), \
9214 GET_MODE (shift_op), \
9221 /* RTX costs. Make an estimate of the cost of executing the operation
9222 X, which is contained with an operation with code OUTER_CODE.
9223 SPEED_P indicates whether the cost desired is the performance cost,
9224 or the size cost. The estimate is stored in COST and the return
9225 value is TRUE if the cost calculation is final, or FALSE if the
9226 caller should recurse through the operands of X to add additional
9229 We currently make no attempt to model the size savings of Thumb-2
9230 16-bit instructions. At the normal points in compilation where
9231 this code is called we have no measure of whether the condition
9232 flags are live or not, and thus no realistic way to determine what
9233 the size will eventually be. */
9235 arm_rtx_costs_internal (rtx x
, enum rtx_code code
, enum rtx_code outer_code
,
9236 const struct cpu_cost_table
*extra_cost
,
9237 int *cost
, bool speed_p
)
9239 machine_mode mode
= GET_MODE (x
);
9241 *cost
= COSTS_N_INSNS (1);
9246 *cost
= thumb1_rtx_costs (x
, code
, outer_code
);
9248 *cost
= thumb1_size_rtx_costs (x
, code
, outer_code
);
9256 /* SET RTXs don't have a mode so we get it from the destination. */
9257 mode
= GET_MODE (SET_DEST (x
));
9259 if (REG_P (SET_SRC (x
))
9260 && REG_P (SET_DEST (x
)))
9262 /* Assume that most copies can be done with a single insn,
9263 unless we don't have HW FP, in which case everything
9264 larger than word mode will require two insns. */
9265 *cost
= COSTS_N_INSNS (((!TARGET_HARD_FLOAT
9266 && GET_MODE_SIZE (mode
) > 4)
9269 /* Conditional register moves can be encoded
9270 in 16 bits in Thumb mode. */
9271 if (!speed_p
&& TARGET_THUMB
&& outer_code
== COND_EXEC
)
9277 if (CONST_INT_P (SET_SRC (x
)))
9279 /* Handle CONST_INT here, since the value doesn't have a mode
9280 and we would otherwise be unable to work out the true cost. */
9281 *cost
= rtx_cost (SET_DEST (x
), GET_MODE (SET_DEST (x
)), SET
,
9284 /* Slightly lower the cost of setting a core reg to a constant.
9285 This helps break up chains and allows for better scheduling. */
9286 if (REG_P (SET_DEST (x
))
9287 && REGNO (SET_DEST (x
)) <= LR_REGNUM
)
9290 /* Immediate moves with an immediate in the range [0, 255] can be
9291 encoded in 16 bits in Thumb mode. */
9292 if (!speed_p
&& TARGET_THUMB
&& GET_MODE (x
) == SImode
9293 && INTVAL (x
) >= 0 && INTVAL (x
) <=255)
9295 goto const_int_cost
;
9301 /* A memory access costs 1 insn if the mode is small, or the address is
9302 a single register, otherwise it costs one insn per word. */
9303 if (REG_P (XEXP (x
, 0)))
9304 *cost
= COSTS_N_INSNS (1);
9306 && GET_CODE (XEXP (x
, 0)) == PLUS
9307 && will_be_in_index_register (XEXP (XEXP (x
, 0), 1)))
9308 /* This will be split into two instructions.
9309 See arm.md:calculate_pic_address. */
9310 *cost
= COSTS_N_INSNS (2);
9312 *cost
= COSTS_N_INSNS (ARM_NUM_REGS (mode
));
9314 /* For speed optimizations, add the costs of the address and
9315 accessing memory. */
9318 *cost
+= (extra_cost
->ldst
.load
9319 + arm_address_cost (XEXP (x
, 0), mode
,
9320 ADDR_SPACE_GENERIC
, speed_p
));
9322 *cost
+= extra_cost
->ldst
.load
;
9328 /* Calculations of LDM costs are complex. We assume an initial cost
9329 (ldm_1st) which will load the number of registers mentioned in
9330 ldm_regs_per_insn_1st registers; then each additional
9331 ldm_regs_per_insn_subsequent registers cost one more insn. The
9332 formula for N regs is thus:
9334 ldm_1st + COSTS_N_INSNS ((max (N - ldm_regs_per_insn_1st, 0)
9335 + ldm_regs_per_insn_subsequent - 1)
9336 / ldm_regs_per_insn_subsequent).
9338 Additional costs may also be added for addressing. A similar
9339 formula is used for STM. */
9341 bool is_ldm
= load_multiple_operation (x
, SImode
);
9342 bool is_stm
= store_multiple_operation (x
, SImode
);
9344 if (is_ldm
|| is_stm
)
9348 HOST_WIDE_INT nregs
= XVECLEN (x
, 0);
9349 HOST_WIDE_INT regs_per_insn_1st
= is_ldm
9350 ? extra_cost
->ldst
.ldm_regs_per_insn_1st
9351 : extra_cost
->ldst
.stm_regs_per_insn_1st
;
9352 HOST_WIDE_INT regs_per_insn_sub
= is_ldm
9353 ? extra_cost
->ldst
.ldm_regs_per_insn_subsequent
9354 : extra_cost
->ldst
.stm_regs_per_insn_subsequent
;
9356 *cost
+= regs_per_insn_1st
9357 + COSTS_N_INSNS (((MAX (nregs
- regs_per_insn_1st
, 0))
9358 + regs_per_insn_sub
- 1)
9359 / regs_per_insn_sub
);
9368 if (TARGET_HARD_FLOAT
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
9369 && (mode
== SFmode
|| !TARGET_VFP_SINGLE
))
9370 *cost
+= COSTS_N_INSNS (speed_p
9371 ? extra_cost
->fp
[mode
!= SFmode
].div
: 0);
9372 else if (mode
== SImode
&& TARGET_IDIV
)
9373 *cost
+= COSTS_N_INSNS (speed_p
? extra_cost
->mult
[0].idiv
: 0);
9375 *cost
= LIBCALL_COST (2);
9377 /* Make the cost of sdiv more expensive so when both sdiv and udiv are
9378 possible udiv is prefered. */
9379 *cost
+= (code
== DIV
? COSTS_N_INSNS (1) : 0);
9380 return false; /* All arguments must be in registers. */
9383 /* MOD by a power of 2 can be expanded as:
9385 and r0, r0, #(n - 1)
9386 and r1, r1, #(n - 1)
9387 rsbpl r0, r1, #0. */
9388 if (CONST_INT_P (XEXP (x
, 1))
9389 && exact_log2 (INTVAL (XEXP (x
, 1))) > 0
9392 *cost
+= COSTS_N_INSNS (3);
9395 *cost
+= 2 * extra_cost
->alu
.logical
9396 + extra_cost
->alu
.arith
;
9402 /* Make the cost of sdiv more expensive so when both sdiv and udiv are
9403 possible udiv is prefered. */
9404 *cost
= LIBCALL_COST (2) + (code
== MOD
? COSTS_N_INSNS (1) : 0);
9405 return false; /* All arguments must be in registers. */
9408 if (mode
== SImode
&& REG_P (XEXP (x
, 1)))
9410 *cost
+= (COSTS_N_INSNS (1)
9411 + rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
));
9413 *cost
+= extra_cost
->alu
.shift_reg
;
9421 if (mode
== DImode
&& CONST_INT_P (XEXP (x
, 1)))
9423 *cost
+= (COSTS_N_INSNS (2)
9424 + rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
));
9426 *cost
+= 2 * extra_cost
->alu
.shift
;
9429 else if (mode
== SImode
)
9431 *cost
+= rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
);
9432 /* Slightly disparage register shifts at -Os, but not by much. */
9433 if (!CONST_INT_P (XEXP (x
, 1)))
9434 *cost
+= (speed_p
? extra_cost
->alu
.shift_reg
: 1
9435 + rtx_cost (XEXP (x
, 1), mode
, code
, 1, speed_p
));
9438 else if (GET_MODE_CLASS (mode
) == MODE_INT
9439 && GET_MODE_SIZE (mode
) < 4)
9443 *cost
+= rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
);
9444 /* Slightly disparage register shifts at -Os, but not by
9446 if (!CONST_INT_P (XEXP (x
, 1)))
9447 *cost
+= (speed_p
? extra_cost
->alu
.shift_reg
: 1
9448 + rtx_cost (XEXP (x
, 1), mode
, code
, 1, speed_p
));
9450 else if (code
== LSHIFTRT
|| code
== ASHIFTRT
)
9452 if (arm_arch_thumb2
&& CONST_INT_P (XEXP (x
, 1)))
9454 /* Can use SBFX/UBFX. */
9456 *cost
+= extra_cost
->alu
.bfx
;
9457 *cost
+= rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
);
9461 *cost
+= COSTS_N_INSNS (1);
9462 *cost
+= rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
);
9465 if (CONST_INT_P (XEXP (x
, 1)))
9466 *cost
+= 2 * extra_cost
->alu
.shift
;
9468 *cost
+= (extra_cost
->alu
.shift
9469 + extra_cost
->alu
.shift_reg
);
9472 /* Slightly disparage register shifts. */
9473 *cost
+= !CONST_INT_P (XEXP (x
, 1));
9478 *cost
= COSTS_N_INSNS (2 + !CONST_INT_P (XEXP (x
, 1)));
9479 *cost
+= rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
);
9482 if (CONST_INT_P (XEXP (x
, 1)))
9483 *cost
+= (2 * extra_cost
->alu
.shift
9484 + extra_cost
->alu
.log_shift
);
9486 *cost
+= (extra_cost
->alu
.shift
9487 + extra_cost
->alu
.shift_reg
9488 + extra_cost
->alu
.log_shift_reg
);
9494 *cost
= LIBCALL_COST (2);
9503 *cost
+= extra_cost
->alu
.rev
;
9510 /* No rev instruction available. Look at arm_legacy_rev
9511 and thumb_legacy_rev for the form of RTL used then. */
9514 *cost
+= COSTS_N_INSNS (9);
9518 *cost
+= 6 * extra_cost
->alu
.shift
;
9519 *cost
+= 3 * extra_cost
->alu
.logical
;
9524 *cost
+= COSTS_N_INSNS (4);
9528 *cost
+= 2 * extra_cost
->alu
.shift
;
9529 *cost
+= extra_cost
->alu
.arith_shift
;
9530 *cost
+= 2 * extra_cost
->alu
.logical
;
9538 if (TARGET_HARD_FLOAT
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
9539 && (mode
== SFmode
|| !TARGET_VFP_SINGLE
))
9541 if (GET_CODE (XEXP (x
, 0)) == MULT
9542 || GET_CODE (XEXP (x
, 1)) == MULT
)
9544 rtx mul_op0
, mul_op1
, sub_op
;
9547 *cost
+= extra_cost
->fp
[mode
!= SFmode
].mult_addsub
;
9549 if (GET_CODE (XEXP (x
, 0)) == MULT
)
9551 mul_op0
= XEXP (XEXP (x
, 0), 0);
9552 mul_op1
= XEXP (XEXP (x
, 0), 1);
9553 sub_op
= XEXP (x
, 1);
9557 mul_op0
= XEXP (XEXP (x
, 1), 0);
9558 mul_op1
= XEXP (XEXP (x
, 1), 1);
9559 sub_op
= XEXP (x
, 0);
9562 /* The first operand of the multiply may be optionally
9564 if (GET_CODE (mul_op0
) == NEG
)
9565 mul_op0
= XEXP (mul_op0
, 0);
9567 *cost
+= (rtx_cost (mul_op0
, mode
, code
, 0, speed_p
)
9568 + rtx_cost (mul_op1
, mode
, code
, 0, speed_p
)
9569 + rtx_cost (sub_op
, mode
, code
, 0, speed_p
));
9575 *cost
+= extra_cost
->fp
[mode
!= SFmode
].addsub
;
9581 rtx shift_by_reg
= NULL
;
9585 shift_op
= shifter_op_p (XEXP (x
, 0), &shift_by_reg
);
9586 if (shift_op
== NULL
)
9588 shift_op
= shifter_op_p (XEXP (x
, 1), &shift_by_reg
);
9589 non_shift_op
= XEXP (x
, 0);
9592 non_shift_op
= XEXP (x
, 1);
9594 if (shift_op
!= NULL
)
9596 if (shift_by_reg
!= NULL
)
9599 *cost
+= extra_cost
->alu
.arith_shift_reg
;
9600 *cost
+= rtx_cost (shift_by_reg
, mode
, code
, 0, speed_p
);
9603 *cost
+= extra_cost
->alu
.arith_shift
;
9605 *cost
+= rtx_cost (shift_op
, mode
, code
, 0, speed_p
);
9606 *cost
+= rtx_cost (non_shift_op
, mode
, code
, 0, speed_p
);
9611 && GET_CODE (XEXP (x
, 1)) == MULT
)
9615 *cost
+= extra_cost
->mult
[0].add
;
9616 *cost
+= rtx_cost (XEXP (x
, 0), mode
, MINUS
, 0, speed_p
);
9617 *cost
+= rtx_cost (XEXP (XEXP (x
, 1), 0), mode
, MULT
, 0, speed_p
);
9618 *cost
+= rtx_cost (XEXP (XEXP (x
, 1), 1), mode
, MULT
, 1, speed_p
);
9622 if (CONST_INT_P (XEXP (x
, 0)))
9624 int insns
= arm_gen_constant (MINUS
, SImode
, NULL_RTX
,
9625 INTVAL (XEXP (x
, 0)), NULL_RTX
,
9627 *cost
= COSTS_N_INSNS (insns
);
9629 *cost
+= insns
* extra_cost
->alu
.arith
;
9630 *cost
+= rtx_cost (XEXP (x
, 1), mode
, code
, 1, speed_p
);
9634 *cost
+= extra_cost
->alu
.arith
;
9639 if (GET_MODE_CLASS (mode
) == MODE_INT
9640 && GET_MODE_SIZE (mode
) < 4)
9642 rtx shift_op
, shift_reg
;
9645 /* We check both sides of the MINUS for shifter operands since,
9646 unlike PLUS, it's not commutative. */
9648 HANDLE_NARROW_SHIFT_ARITH (MINUS
, 0)
9649 HANDLE_NARROW_SHIFT_ARITH (MINUS
, 1)
9651 /* Slightly disparage, as we might need to widen the result. */
9654 *cost
+= extra_cost
->alu
.arith
;
9656 if (CONST_INT_P (XEXP (x
, 0)))
9658 *cost
+= rtx_cost (XEXP (x
, 1), mode
, code
, 1, speed_p
);
9667 *cost
+= COSTS_N_INSNS (1);
9669 if (GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
)
9671 rtx op1
= XEXP (x
, 1);
9674 *cost
+= 2 * extra_cost
->alu
.arith
;
9676 if (GET_CODE (op1
) == ZERO_EXTEND
)
9677 *cost
+= rtx_cost (XEXP (op1
, 0), VOIDmode
, ZERO_EXTEND
,
9680 *cost
+= rtx_cost (op1
, mode
, MINUS
, 1, speed_p
);
9681 *cost
+= rtx_cost (XEXP (XEXP (x
, 0), 0), VOIDmode
, ZERO_EXTEND
,
9685 else if (GET_CODE (XEXP (x
, 0)) == SIGN_EXTEND
)
9688 *cost
+= extra_cost
->alu
.arith
+ extra_cost
->alu
.arith_shift
;
9689 *cost
+= (rtx_cost (XEXP (XEXP (x
, 0), 0), VOIDmode
, SIGN_EXTEND
,
9691 + rtx_cost (XEXP (x
, 1), mode
, MINUS
, 1, speed_p
));
9694 else if (GET_CODE (XEXP (x
, 1)) == ZERO_EXTEND
9695 || GET_CODE (XEXP (x
, 1)) == SIGN_EXTEND
)
9698 *cost
+= (extra_cost
->alu
.arith
9699 + (GET_CODE (XEXP (x
, 1)) == ZERO_EXTEND
9700 ? extra_cost
->alu
.arith
9701 : extra_cost
->alu
.arith_shift
));
9702 *cost
+= (rtx_cost (XEXP (x
, 0), mode
, MINUS
, 0, speed_p
)
9703 + rtx_cost (XEXP (XEXP (x
, 1), 0), VOIDmode
,
9704 GET_CODE (XEXP (x
, 1)), 0, speed_p
));
9709 *cost
+= 2 * extra_cost
->alu
.arith
;
9715 *cost
= LIBCALL_COST (2);
9719 if (TARGET_HARD_FLOAT
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
9720 && (mode
== SFmode
|| !TARGET_VFP_SINGLE
))
9722 if (GET_CODE (XEXP (x
, 0)) == MULT
)
9724 rtx mul_op0
, mul_op1
, add_op
;
9727 *cost
+= extra_cost
->fp
[mode
!= SFmode
].mult_addsub
;
9729 mul_op0
= XEXP (XEXP (x
, 0), 0);
9730 mul_op1
= XEXP (XEXP (x
, 0), 1);
9731 add_op
= XEXP (x
, 1);
9733 *cost
+= (rtx_cost (mul_op0
, mode
, code
, 0, speed_p
)
9734 + rtx_cost (mul_op1
, mode
, code
, 0, speed_p
)
9735 + rtx_cost (add_op
, mode
, code
, 0, speed_p
));
9741 *cost
+= extra_cost
->fp
[mode
!= SFmode
].addsub
;
9744 else if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
9746 *cost
= LIBCALL_COST (2);
9750 /* Narrow modes can be synthesized in SImode, but the range
9751 of useful sub-operations is limited. Check for shift operations
9752 on one of the operands. Only left shifts can be used in the
9754 if (GET_MODE_CLASS (mode
) == MODE_INT
9755 && GET_MODE_SIZE (mode
) < 4)
9757 rtx shift_op
, shift_reg
;
9760 HANDLE_NARROW_SHIFT_ARITH (PLUS
, 0)
9762 if (CONST_INT_P (XEXP (x
, 1)))
9764 int insns
= arm_gen_constant (PLUS
, SImode
, NULL_RTX
,
9765 INTVAL (XEXP (x
, 1)), NULL_RTX
,
9767 *cost
= COSTS_N_INSNS (insns
);
9769 *cost
+= insns
* extra_cost
->alu
.arith
;
9770 /* Slightly penalize a narrow operation as the result may
9772 *cost
+= 1 + rtx_cost (XEXP (x
, 0), mode
, PLUS
, 0, speed_p
);
9776 /* Slightly penalize a narrow operation as the result may
9780 *cost
+= extra_cost
->alu
.arith
;
9787 rtx shift_op
, shift_reg
;
9790 && (GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
9791 || GET_CODE (XEXP (x
, 0)) == SIGN_EXTEND
))
9793 /* UXTA[BH] or SXTA[BH]. */
9795 *cost
+= extra_cost
->alu
.extend_arith
;
9796 *cost
+= (rtx_cost (XEXP (XEXP (x
, 0), 0), VOIDmode
, ZERO_EXTEND
,
9798 + rtx_cost (XEXP (x
, 1), mode
, PLUS
, 0, speed_p
));
9803 shift_op
= shifter_op_p (XEXP (x
, 0), &shift_reg
);
9804 if (shift_op
!= NULL
)
9809 *cost
+= extra_cost
->alu
.arith_shift_reg
;
9810 *cost
+= rtx_cost (shift_reg
, mode
, ASHIFT
, 1, speed_p
);
9813 *cost
+= extra_cost
->alu
.arith_shift
;
9815 *cost
+= (rtx_cost (shift_op
, mode
, ASHIFT
, 0, speed_p
)
9816 + rtx_cost (XEXP (x
, 1), mode
, PLUS
, 1, speed_p
));
9819 if (GET_CODE (XEXP (x
, 0)) == MULT
)
9821 rtx mul_op
= XEXP (x
, 0);
9823 if (TARGET_DSP_MULTIPLY
9824 && ((GET_CODE (XEXP (mul_op
, 0)) == SIGN_EXTEND
9825 && (GET_CODE (XEXP (mul_op
, 1)) == SIGN_EXTEND
9826 || (GET_CODE (XEXP (mul_op
, 1)) == ASHIFTRT
9827 && CONST_INT_P (XEXP (XEXP (mul_op
, 1), 1))
9828 && INTVAL (XEXP (XEXP (mul_op
, 1), 1)) == 16)))
9829 || (GET_CODE (XEXP (mul_op
, 0)) == ASHIFTRT
9830 && CONST_INT_P (XEXP (XEXP (mul_op
, 0), 1))
9831 && INTVAL (XEXP (XEXP (mul_op
, 0), 1)) == 16
9832 && (GET_CODE (XEXP (mul_op
, 1)) == SIGN_EXTEND
9833 || (GET_CODE (XEXP (mul_op
, 1)) == ASHIFTRT
9834 && CONST_INT_P (XEXP (XEXP (mul_op
, 1), 1))
9835 && (INTVAL (XEXP (XEXP (mul_op
, 1), 1))
9840 *cost
+= extra_cost
->mult
[0].extend_add
;
9841 *cost
+= (rtx_cost (XEXP (XEXP (mul_op
, 0), 0), mode
,
9842 SIGN_EXTEND
, 0, speed_p
)
9843 + rtx_cost (XEXP (XEXP (mul_op
, 1), 0), mode
,
9844 SIGN_EXTEND
, 0, speed_p
)
9845 + rtx_cost (XEXP (x
, 1), mode
, PLUS
, 1, speed_p
));
9850 *cost
+= extra_cost
->mult
[0].add
;
9851 *cost
+= (rtx_cost (XEXP (mul_op
, 0), mode
, MULT
, 0, speed_p
)
9852 + rtx_cost (XEXP (mul_op
, 1), mode
, MULT
, 1, speed_p
)
9853 + rtx_cost (XEXP (x
, 1), mode
, PLUS
, 1, speed_p
));
9856 if (CONST_INT_P (XEXP (x
, 1)))
9858 int insns
= arm_gen_constant (PLUS
, SImode
, NULL_RTX
,
9859 INTVAL (XEXP (x
, 1)), NULL_RTX
,
9861 *cost
= COSTS_N_INSNS (insns
);
9863 *cost
+= insns
* extra_cost
->alu
.arith
;
9864 *cost
+= rtx_cost (XEXP (x
, 0), mode
, PLUS
, 0, speed_p
);
9868 *cost
+= extra_cost
->alu
.arith
;
9876 && GET_CODE (XEXP (x
, 0)) == MULT
9877 && ((GET_CODE (XEXP (XEXP (x
, 0), 0)) == ZERO_EXTEND
9878 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == ZERO_EXTEND
)
9879 || (GET_CODE (XEXP (XEXP (x
, 0), 0)) == SIGN_EXTEND
9880 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == SIGN_EXTEND
)))
9883 *cost
+= extra_cost
->mult
[1].extend_add
;
9884 *cost
+= (rtx_cost (XEXP (XEXP (XEXP (x
, 0), 0), 0), mode
,
9885 ZERO_EXTEND
, 0, speed_p
)
9886 + rtx_cost (XEXP (XEXP (XEXP (x
, 0), 1), 0), mode
,
9887 ZERO_EXTEND
, 0, speed_p
)
9888 + rtx_cost (XEXP (x
, 1), mode
, PLUS
, 1, speed_p
));
9892 *cost
+= COSTS_N_INSNS (1);
9894 if (GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
9895 || GET_CODE (XEXP (x
, 0)) == SIGN_EXTEND
)
9898 *cost
+= (extra_cost
->alu
.arith
9899 + (GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
9900 ? extra_cost
->alu
.arith
9901 : extra_cost
->alu
.arith_shift
));
9903 *cost
+= (rtx_cost (XEXP (XEXP (x
, 0), 0), VOIDmode
, ZERO_EXTEND
,
9905 + rtx_cost (XEXP (x
, 1), mode
, PLUS
, 1, speed_p
));
9910 *cost
+= 2 * extra_cost
->alu
.arith
;
9915 *cost
= LIBCALL_COST (2);
9918 if (mode
== SImode
&& arm_arch6
&& aarch_rev16_p (x
))
9921 *cost
+= extra_cost
->alu
.rev
;
9929 enum rtx_code subcode
= GET_CODE (XEXP (x
, 0));
9930 rtx op0
= XEXP (x
, 0);
9931 rtx shift_op
, shift_reg
;
9935 || (code
== IOR
&& TARGET_THUMB2
)))
9936 op0
= XEXP (op0
, 0);
9939 shift_op
= shifter_op_p (op0
, &shift_reg
);
9940 if (shift_op
!= NULL
)
9945 *cost
+= extra_cost
->alu
.log_shift_reg
;
9946 *cost
+= rtx_cost (shift_reg
, mode
, ASHIFT
, 1, speed_p
);
9949 *cost
+= extra_cost
->alu
.log_shift
;
9951 *cost
+= (rtx_cost (shift_op
, mode
, ASHIFT
, 0, speed_p
)
9952 + rtx_cost (XEXP (x
, 1), mode
, code
, 1, speed_p
));
9956 if (CONST_INT_P (XEXP (x
, 1)))
9958 int insns
= arm_gen_constant (code
, SImode
, NULL_RTX
,
9959 INTVAL (XEXP (x
, 1)), NULL_RTX
,
9962 *cost
= COSTS_N_INSNS (insns
);
9964 *cost
+= insns
* extra_cost
->alu
.logical
;
9965 *cost
+= rtx_cost (op0
, mode
, code
, 0, speed_p
);
9970 *cost
+= extra_cost
->alu
.logical
;
9971 *cost
+= (rtx_cost (op0
, mode
, code
, 0, speed_p
)
9972 + rtx_cost (XEXP (x
, 1), mode
, code
, 1, speed_p
));
9978 rtx op0
= XEXP (x
, 0);
9979 enum rtx_code subcode
= GET_CODE (op0
);
9981 *cost
+= COSTS_N_INSNS (1);
9985 || (code
== IOR
&& TARGET_THUMB2
)))
9986 op0
= XEXP (op0
, 0);
9988 if (GET_CODE (op0
) == ZERO_EXTEND
)
9991 *cost
+= 2 * extra_cost
->alu
.logical
;
9993 *cost
+= (rtx_cost (XEXP (op0
, 0), VOIDmode
, ZERO_EXTEND
,
9995 + rtx_cost (XEXP (x
, 1), mode
, code
, 0, speed_p
));
9998 else if (GET_CODE (op0
) == SIGN_EXTEND
)
10001 *cost
+= extra_cost
->alu
.logical
+ extra_cost
->alu
.log_shift
;
10003 *cost
+= (rtx_cost (XEXP (op0
, 0), VOIDmode
, SIGN_EXTEND
,
10005 + rtx_cost (XEXP (x
, 1), mode
, code
, 0, speed_p
));
10010 *cost
+= 2 * extra_cost
->alu
.logical
;
10016 *cost
= LIBCALL_COST (2);
10020 if (TARGET_HARD_FLOAT
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
10021 && (mode
== SFmode
|| !TARGET_VFP_SINGLE
))
10023 rtx op0
= XEXP (x
, 0);
10025 if (GET_CODE (op0
) == NEG
&& !flag_rounding_math
)
10026 op0
= XEXP (op0
, 0);
10029 *cost
+= extra_cost
->fp
[mode
!= SFmode
].mult
;
10031 *cost
+= (rtx_cost (op0
, mode
, MULT
, 0, speed_p
)
10032 + rtx_cost (XEXP (x
, 1), mode
, MULT
, 1, speed_p
));
10035 else if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
10037 *cost
= LIBCALL_COST (2);
10041 if (mode
== SImode
)
10043 if (TARGET_DSP_MULTIPLY
10044 && ((GET_CODE (XEXP (x
, 0)) == SIGN_EXTEND
10045 && (GET_CODE (XEXP (x
, 1)) == SIGN_EXTEND
10046 || (GET_CODE (XEXP (x
, 1)) == ASHIFTRT
10047 && CONST_INT_P (XEXP (XEXP (x
, 1), 1))
10048 && INTVAL (XEXP (XEXP (x
, 1), 1)) == 16)))
10049 || (GET_CODE (XEXP (x
, 0)) == ASHIFTRT
10050 && CONST_INT_P (XEXP (XEXP (x
, 0), 1))
10051 && INTVAL (XEXP (XEXP (x
, 0), 1)) == 16
10052 && (GET_CODE (XEXP (x
, 1)) == SIGN_EXTEND
10053 || (GET_CODE (XEXP (x
, 1)) == ASHIFTRT
10054 && CONST_INT_P (XEXP (XEXP (x
, 1), 1))
10055 && (INTVAL (XEXP (XEXP (x
, 1), 1))
10058 /* SMUL[TB][TB]. */
10060 *cost
+= extra_cost
->mult
[0].extend
;
10061 *cost
+= rtx_cost (XEXP (XEXP (x
, 0), 0), mode
,
10062 SIGN_EXTEND
, 0, speed_p
);
10063 *cost
+= rtx_cost (XEXP (XEXP (x
, 1), 0), mode
,
10064 SIGN_EXTEND
, 1, speed_p
);
10068 *cost
+= extra_cost
->mult
[0].simple
;
10072 if (mode
== DImode
)
10075 && ((GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
10076 && GET_CODE (XEXP (x
, 1)) == ZERO_EXTEND
)
10077 || (GET_CODE (XEXP (x
, 0)) == SIGN_EXTEND
10078 && GET_CODE (XEXP (x
, 1)) == SIGN_EXTEND
)))
10081 *cost
+= extra_cost
->mult
[1].extend
;
10082 *cost
+= (rtx_cost (XEXP (XEXP (x
, 0), 0), VOIDmode
,
10083 ZERO_EXTEND
, 0, speed_p
)
10084 + rtx_cost (XEXP (XEXP (x
, 1), 0), VOIDmode
,
10085 ZERO_EXTEND
, 0, speed_p
));
10089 *cost
= LIBCALL_COST (2);
10094 *cost
= LIBCALL_COST (2);
10098 if (TARGET_HARD_FLOAT
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
10099 && (mode
== SFmode
|| !TARGET_VFP_SINGLE
))
10101 if (GET_CODE (XEXP (x
, 0)) == MULT
)
10104 *cost
= rtx_cost (XEXP (x
, 0), mode
, NEG
, 0, speed_p
);
10109 *cost
+= extra_cost
->fp
[mode
!= SFmode
].neg
;
10113 else if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
10115 *cost
= LIBCALL_COST (1);
10119 if (mode
== SImode
)
10121 if (GET_CODE (XEXP (x
, 0)) == ABS
)
10123 *cost
+= COSTS_N_INSNS (1);
10124 /* Assume the non-flag-changing variant. */
10126 *cost
+= (extra_cost
->alu
.log_shift
10127 + extra_cost
->alu
.arith_shift
);
10128 *cost
+= rtx_cost (XEXP (XEXP (x
, 0), 0), mode
, ABS
, 0, speed_p
);
10132 if (GET_RTX_CLASS (GET_CODE (XEXP (x
, 0))) == RTX_COMPARE
10133 || GET_RTX_CLASS (GET_CODE (XEXP (x
, 0))) == RTX_COMM_COMPARE
)
10135 *cost
+= COSTS_N_INSNS (1);
10136 /* No extra cost for MOV imm and MVN imm. */
10137 /* If the comparison op is using the flags, there's no further
10138 cost, otherwise we need to add the cost of the comparison. */
10139 if (!(REG_P (XEXP (XEXP (x
, 0), 0))
10140 && REGNO (XEXP (XEXP (x
, 0), 0)) == CC_REGNUM
10141 && XEXP (XEXP (x
, 0), 1) == const0_rtx
))
10143 mode
= GET_MODE (XEXP (XEXP (x
, 0), 0));
10144 *cost
+= (COSTS_N_INSNS (1)
10145 + rtx_cost (XEXP (XEXP (x
, 0), 0), mode
, COMPARE
,
10147 + rtx_cost (XEXP (XEXP (x
, 0), 1), mode
, COMPARE
,
10150 *cost
+= extra_cost
->alu
.arith
;
10156 *cost
+= extra_cost
->alu
.arith
;
10160 if (GET_MODE_CLASS (mode
) == MODE_INT
10161 && GET_MODE_SIZE (mode
) < 4)
10163 /* Slightly disparage, as we might need an extend operation. */
10166 *cost
+= extra_cost
->alu
.arith
;
10170 if (mode
== DImode
)
10172 *cost
+= COSTS_N_INSNS (1);
10174 *cost
+= 2 * extra_cost
->alu
.arith
;
10179 *cost
= LIBCALL_COST (1);
10183 if (mode
== SImode
)
10186 rtx shift_reg
= NULL
;
10188 shift_op
= shifter_op_p (XEXP (x
, 0), &shift_reg
);
10192 if (shift_reg
!= NULL
)
10195 *cost
+= extra_cost
->alu
.log_shift_reg
;
10196 *cost
+= rtx_cost (shift_reg
, mode
, ASHIFT
, 1, speed_p
);
10199 *cost
+= extra_cost
->alu
.log_shift
;
10200 *cost
+= rtx_cost (shift_op
, mode
, ASHIFT
, 0, speed_p
);
10205 *cost
+= extra_cost
->alu
.logical
;
10208 if (mode
== DImode
)
10210 *cost
+= COSTS_N_INSNS (1);
10216 *cost
+= LIBCALL_COST (1);
10221 if (GET_CODE (XEXP (x
, 1)) == PC
|| GET_CODE (XEXP (x
, 2)) == PC
)
10223 *cost
+= COSTS_N_INSNS (3);
10226 int op1cost
= rtx_cost (XEXP (x
, 1), mode
, SET
, 1, speed_p
);
10227 int op2cost
= rtx_cost (XEXP (x
, 2), mode
, SET
, 1, speed_p
);
10229 *cost
= rtx_cost (XEXP (x
, 0), mode
, IF_THEN_ELSE
, 0, speed_p
);
10230 /* Assume that if one arm of the if_then_else is a register,
10231 that it will be tied with the result and eliminate the
10232 conditional insn. */
10233 if (REG_P (XEXP (x
, 1)))
10235 else if (REG_P (XEXP (x
, 2)))
10241 if (extra_cost
->alu
.non_exec_costs_exec
)
10242 *cost
+= op1cost
+ op2cost
+ extra_cost
->alu
.non_exec
;
10244 *cost
+= MAX (op1cost
, op2cost
) + extra_cost
->alu
.non_exec
;
10247 *cost
+= op1cost
+ op2cost
;
10253 if (cc_register (XEXP (x
, 0), VOIDmode
) && XEXP (x
, 1) == const0_rtx
)
10257 machine_mode op0mode
;
10258 /* We'll mostly assume that the cost of a compare is the cost of the
10259 LHS. However, there are some notable exceptions. */
10261 /* Floating point compares are never done as side-effects. */
10262 op0mode
= GET_MODE (XEXP (x
, 0));
10263 if (TARGET_HARD_FLOAT
&& GET_MODE_CLASS (op0mode
) == MODE_FLOAT
10264 && (op0mode
== SFmode
|| !TARGET_VFP_SINGLE
))
10267 *cost
+= extra_cost
->fp
[op0mode
!= SFmode
].compare
;
10269 if (XEXP (x
, 1) == CONST0_RTX (op0mode
))
10271 *cost
+= rtx_cost (XEXP (x
, 0), op0mode
, code
, 0, speed_p
);
10277 else if (GET_MODE_CLASS (op0mode
) == MODE_FLOAT
)
10279 *cost
= LIBCALL_COST (2);
10283 /* DImode compares normally take two insns. */
10284 if (op0mode
== DImode
)
10286 *cost
+= COSTS_N_INSNS (1);
10288 *cost
+= 2 * extra_cost
->alu
.arith
;
10292 if (op0mode
== SImode
)
10297 if (XEXP (x
, 1) == const0_rtx
10298 && !(REG_P (XEXP (x
, 0))
10299 || (GET_CODE (XEXP (x
, 0)) == SUBREG
10300 && REG_P (SUBREG_REG (XEXP (x
, 0))))))
10302 *cost
= rtx_cost (XEXP (x
, 0), op0mode
, COMPARE
, 0, speed_p
);
10304 /* Multiply operations that set the flags are often
10305 significantly more expensive. */
10307 && GET_CODE (XEXP (x
, 0)) == MULT
10308 && !power_of_two_operand (XEXP (XEXP (x
, 0), 1), mode
))
10309 *cost
+= extra_cost
->mult
[0].flag_setting
;
10312 && GET_CODE (XEXP (x
, 0)) == PLUS
10313 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == MULT
10314 && !power_of_two_operand (XEXP (XEXP (XEXP (x
, 0),
10316 *cost
+= extra_cost
->mult
[0].flag_setting
;
10321 shift_op
= shifter_op_p (XEXP (x
, 0), &shift_reg
);
10322 if (shift_op
!= NULL
)
10324 if (shift_reg
!= NULL
)
10326 *cost
+= rtx_cost (shift_reg
, op0mode
, ASHIFT
,
10329 *cost
+= extra_cost
->alu
.arith_shift_reg
;
10332 *cost
+= extra_cost
->alu
.arith_shift
;
10333 *cost
+= rtx_cost (shift_op
, op0mode
, ASHIFT
, 0, speed_p
);
10334 *cost
+= rtx_cost (XEXP (x
, 1), op0mode
, COMPARE
, 1, speed_p
);
10339 *cost
+= extra_cost
->alu
.arith
;
10340 if (CONST_INT_P (XEXP (x
, 1))
10341 && const_ok_for_op (INTVAL (XEXP (x
, 1)), COMPARE
))
10343 *cost
+= rtx_cost (XEXP (x
, 0), op0mode
, COMPARE
, 0, speed_p
);
10351 *cost
= LIBCALL_COST (2);
10374 if (outer_code
== SET
)
10376 /* Is it a store-flag operation? */
10377 if (REG_P (XEXP (x
, 0)) && REGNO (XEXP (x
, 0)) == CC_REGNUM
10378 && XEXP (x
, 1) == const0_rtx
)
10380 /* Thumb also needs an IT insn. */
10381 *cost
+= COSTS_N_INSNS (TARGET_THUMB
? 2 : 1);
10384 if (XEXP (x
, 1) == const0_rtx
)
10389 /* LSR Rd, Rn, #31. */
10391 *cost
+= extra_cost
->alu
.shift
;
10401 *cost
+= COSTS_N_INSNS (1);
10405 /* RSBS T1, Rn, Rn, LSR #31
10407 *cost
+= COSTS_N_INSNS (1);
10409 *cost
+= extra_cost
->alu
.arith_shift
;
10413 /* RSB Rd, Rn, Rn, ASR #1
10414 LSR Rd, Rd, #31. */
10415 *cost
+= COSTS_N_INSNS (1);
10417 *cost
+= (extra_cost
->alu
.arith_shift
10418 + extra_cost
->alu
.shift
);
10424 *cost
+= COSTS_N_INSNS (1);
10426 *cost
+= extra_cost
->alu
.shift
;
10430 /* Remaining cases are either meaningless or would take
10431 three insns anyway. */
10432 *cost
= COSTS_N_INSNS (3);
10435 *cost
+= rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
);
10440 *cost
+= COSTS_N_INSNS (TARGET_THUMB
? 3 : 2);
10441 if (CONST_INT_P (XEXP (x
, 1))
10442 && const_ok_for_op (INTVAL (XEXP (x
, 1)), COMPARE
))
10444 *cost
+= rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
);
10451 /* Not directly inside a set. If it involves the condition code
10452 register it must be the condition for a branch, cond_exec or
10453 I_T_E operation. Since the comparison is performed elsewhere
10454 this is just the control part which has no additional
10456 else if (REG_P (XEXP (x
, 0)) && REGNO (XEXP (x
, 0)) == CC_REGNUM
10457 && XEXP (x
, 1) == const0_rtx
)
10465 if (TARGET_HARD_FLOAT
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
10466 && (mode
== SFmode
|| !TARGET_VFP_SINGLE
))
10469 *cost
+= extra_cost
->fp
[mode
!= SFmode
].neg
;
10473 else if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
10475 *cost
= LIBCALL_COST (1);
10479 if (mode
== SImode
)
10482 *cost
+= extra_cost
->alu
.log_shift
+ extra_cost
->alu
.arith_shift
;
10486 *cost
= LIBCALL_COST (1);
10490 if ((arm_arch4
|| GET_MODE (XEXP (x
, 0)) == SImode
)
10491 && MEM_P (XEXP (x
, 0)))
10493 if (mode
== DImode
)
10494 *cost
+= COSTS_N_INSNS (1);
10499 if (GET_MODE (XEXP (x
, 0)) == SImode
)
10500 *cost
+= extra_cost
->ldst
.load
;
10502 *cost
+= extra_cost
->ldst
.load_sign_extend
;
10504 if (mode
== DImode
)
10505 *cost
+= extra_cost
->alu
.shift
;
10510 /* Widening from less than 32-bits requires an extend operation. */
10511 if (GET_MODE (XEXP (x
, 0)) != SImode
&& arm_arch6
)
10513 /* We have SXTB/SXTH. */
10514 *cost
+= rtx_cost (XEXP (x
, 0), VOIDmode
, code
, 0, speed_p
);
10516 *cost
+= extra_cost
->alu
.extend
;
10518 else if (GET_MODE (XEXP (x
, 0)) != SImode
)
10520 /* Needs two shifts. */
10521 *cost
+= COSTS_N_INSNS (1);
10522 *cost
+= rtx_cost (XEXP (x
, 0), VOIDmode
, code
, 0, speed_p
);
10524 *cost
+= 2 * extra_cost
->alu
.shift
;
10527 /* Widening beyond 32-bits requires one more insn. */
10528 if (mode
== DImode
)
10530 *cost
+= COSTS_N_INSNS (1);
10532 *cost
+= extra_cost
->alu
.shift
;
10539 || GET_MODE (XEXP (x
, 0)) == SImode
10540 || GET_MODE (XEXP (x
, 0)) == QImode
)
10541 && MEM_P (XEXP (x
, 0)))
10543 *cost
= rtx_cost (XEXP (x
, 0), VOIDmode
, code
, 0, speed_p
);
10545 if (mode
== DImode
)
10546 *cost
+= COSTS_N_INSNS (1); /* No speed penalty. */
10551 /* Widening from less than 32-bits requires an extend operation. */
10552 if (GET_MODE (XEXP (x
, 0)) == QImode
)
10554 /* UXTB can be a shorter instruction in Thumb2, but it might
10555 be slower than the AND Rd, Rn, #255 alternative. When
10556 optimizing for speed it should never be slower to use
10557 AND, and we don't really model 16-bit vs 32-bit insns
10560 *cost
+= extra_cost
->alu
.logical
;
10562 else if (GET_MODE (XEXP (x
, 0)) != SImode
&& arm_arch6
)
10564 /* We have UXTB/UXTH. */
10565 *cost
+= rtx_cost (XEXP (x
, 0), VOIDmode
, code
, 0, speed_p
);
10567 *cost
+= extra_cost
->alu
.extend
;
10569 else if (GET_MODE (XEXP (x
, 0)) != SImode
)
10571 /* Needs two shifts. It's marginally preferable to use
10572 shifts rather than two BIC instructions as the second
10573 shift may merge with a subsequent insn as a shifter
10575 *cost
= COSTS_N_INSNS (2);
10576 *cost
+= rtx_cost (XEXP (x
, 0), VOIDmode
, code
, 0, speed_p
);
10578 *cost
+= 2 * extra_cost
->alu
.shift
;
10581 /* Widening beyond 32-bits requires one more insn. */
10582 if (mode
== DImode
)
10584 *cost
+= COSTS_N_INSNS (1); /* No speed penalty. */
10591 /* CONST_INT has no mode, so we cannot tell for sure how many
10592 insns are really going to be needed. The best we can do is
10593 look at the value passed. If it fits in SImode, then assume
10594 that's the mode it will be used for. Otherwise assume it
10595 will be used in DImode. */
10596 if (INTVAL (x
) == trunc_int_for_mode (INTVAL (x
), SImode
))
10601 /* Avoid blowing up in arm_gen_constant (). */
10602 if (!(outer_code
== PLUS
10603 || outer_code
== AND
10604 || outer_code
== IOR
10605 || outer_code
== XOR
10606 || outer_code
== MINUS
))
10610 if (mode
== SImode
)
10612 *cost
+= COSTS_N_INSNS (arm_gen_constant (outer_code
, SImode
, NULL
,
10613 INTVAL (x
), NULL
, NULL
,
10619 *cost
+= COSTS_N_INSNS (arm_gen_constant
10620 (outer_code
, SImode
, NULL
,
10621 trunc_int_for_mode (INTVAL (x
), SImode
),
10623 + arm_gen_constant (outer_code
, SImode
, NULL
,
10624 INTVAL (x
) >> 32, NULL
,
10636 if (arm_arch_thumb2
&& !flag_pic
)
10637 *cost
+= COSTS_N_INSNS (1);
10639 *cost
+= extra_cost
->ldst
.load
;
10642 *cost
+= COSTS_N_INSNS (1);
10646 *cost
+= COSTS_N_INSNS (1);
10648 *cost
+= extra_cost
->alu
.arith
;
10654 *cost
= COSTS_N_INSNS (4);
10659 if (TARGET_HARD_FLOAT
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
10660 && (mode
== SFmode
|| !TARGET_VFP_SINGLE
))
10662 if (vfp3_const_double_rtx (x
))
10665 *cost
+= extra_cost
->fp
[mode
== DFmode
].fpconst
;
10671 if (mode
== DFmode
)
10672 *cost
+= extra_cost
->ldst
.loadd
;
10674 *cost
+= extra_cost
->ldst
.loadf
;
10677 *cost
+= COSTS_N_INSNS (1 + (mode
== DFmode
));
10681 *cost
= COSTS_N_INSNS (4);
10687 && TARGET_HARD_FLOAT
10688 && (VALID_NEON_DREG_MODE (mode
) || VALID_NEON_QREG_MODE (mode
))
10689 && neon_immediate_valid_for_move (x
, mode
, NULL
, NULL
))
10690 *cost
= COSTS_N_INSNS (1);
10692 *cost
= COSTS_N_INSNS (4);
10697 /* When optimizing for size, we prefer constant pool entries to
10698 MOVW/MOVT pairs, so bump the cost of these slightly. */
10705 *cost
+= extra_cost
->alu
.clz
;
10709 if (XEXP (x
, 1) == const0_rtx
)
10712 *cost
+= extra_cost
->alu
.log_shift
;
10713 *cost
+= rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
);
10716 /* Fall through. */
10720 *cost
+= COSTS_N_INSNS (1);
10724 if (GET_CODE (XEXP (x
, 0)) == ASHIFTRT
10725 && CONST_INT_P (XEXP (XEXP (x
, 0), 1))
10726 && INTVAL (XEXP (XEXP (x
, 0), 1)) == 32
10727 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == MULT
10728 && ((GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)) == SIGN_EXTEND
10729 && GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 1)) == SIGN_EXTEND
)
10730 || (GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)) == ZERO_EXTEND
10731 && (GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 1))
10735 *cost
+= extra_cost
->mult
[1].extend
;
10736 *cost
+= (rtx_cost (XEXP (XEXP (XEXP (x
, 0), 0), 0), VOIDmode
,
10737 ZERO_EXTEND
, 0, speed_p
)
10738 + rtx_cost (XEXP (XEXP (XEXP (x
, 0), 0), 1), VOIDmode
,
10739 ZERO_EXTEND
, 0, speed_p
));
10742 *cost
= LIBCALL_COST (1);
10745 case UNSPEC_VOLATILE
:
10747 return arm_unspec_cost (x
, outer_code
, speed_p
, cost
);
10750 /* Reading the PC is like reading any other register. Writing it
10751 is more expensive, but we take that into account elsewhere. */
10756 /* TODO: Simple zero_extract of bottom bits using AND. */
10757 /* Fall through. */
10761 && CONST_INT_P (XEXP (x
, 1))
10762 && CONST_INT_P (XEXP (x
, 2)))
10765 *cost
+= extra_cost
->alu
.bfx
;
10766 *cost
+= rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
);
10769 /* Without UBFX/SBFX, need to resort to shift operations. */
10770 *cost
+= COSTS_N_INSNS (1);
10772 *cost
+= 2 * extra_cost
->alu
.shift
;
10773 *cost
+= rtx_cost (XEXP (x
, 0), mode
, ASHIFT
, 0, speed_p
);
10777 if (TARGET_HARD_FLOAT
)
10780 *cost
+= extra_cost
->fp
[mode
== DFmode
].widen
;
10782 && GET_MODE (XEXP (x
, 0)) == HFmode
)
10784 /* Pre v8, widening HF->DF is a two-step process, first
10785 widening to SFmode. */
10786 *cost
+= COSTS_N_INSNS (1);
10788 *cost
+= extra_cost
->fp
[0].widen
;
10790 *cost
+= rtx_cost (XEXP (x
, 0), VOIDmode
, code
, 0, speed_p
);
10794 *cost
= LIBCALL_COST (1);
10797 case FLOAT_TRUNCATE
:
10798 if (TARGET_HARD_FLOAT
)
10801 *cost
+= extra_cost
->fp
[mode
== DFmode
].narrow
;
10802 *cost
+= rtx_cost (XEXP (x
, 0), VOIDmode
, code
, 0, speed_p
);
10804 /* Vector modes? */
10806 *cost
= LIBCALL_COST (1);
10810 if (TARGET_32BIT
&& TARGET_HARD_FLOAT
&& TARGET_FMA
)
10812 rtx op0
= XEXP (x
, 0);
10813 rtx op1
= XEXP (x
, 1);
10814 rtx op2
= XEXP (x
, 2);
10817 /* vfms or vfnma. */
10818 if (GET_CODE (op0
) == NEG
)
10819 op0
= XEXP (op0
, 0);
10821 /* vfnms or vfnma. */
10822 if (GET_CODE (op2
) == NEG
)
10823 op2
= XEXP (op2
, 0);
10825 *cost
+= rtx_cost (op0
, mode
, FMA
, 0, speed_p
);
10826 *cost
+= rtx_cost (op1
, mode
, FMA
, 1, speed_p
);
10827 *cost
+= rtx_cost (op2
, mode
, FMA
, 2, speed_p
);
10830 *cost
+= extra_cost
->fp
[mode
==DFmode
].fma
;
10835 *cost
= LIBCALL_COST (3);
10840 if (TARGET_HARD_FLOAT
)
10842 /* The *combine_vcvtf2i reduces a vmul+vcvt into
10843 a vcvt fixed-point conversion. */
10844 if (code
== FIX
&& mode
== SImode
10845 && GET_CODE (XEXP (x
, 0)) == FIX
10846 && GET_MODE (XEXP (x
, 0)) == SFmode
10847 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == MULT
10848 && vfp3_const_double_for_bits (XEXP (XEXP (XEXP (x
, 0), 0), 1))
10852 *cost
+= extra_cost
->fp
[0].toint
;
10854 *cost
+= rtx_cost (XEXP (XEXP (XEXP (x
, 0), 0), 0), mode
,
10859 if (GET_MODE_CLASS (mode
) == MODE_INT
)
10861 mode
= GET_MODE (XEXP (x
, 0));
10863 *cost
+= extra_cost
->fp
[mode
== DFmode
].toint
;
10864 /* Strip of the 'cost' of rounding towards zero. */
10865 if (GET_CODE (XEXP (x
, 0)) == FIX
)
10866 *cost
+= rtx_cost (XEXP (XEXP (x
, 0), 0), mode
, code
,
10869 *cost
+= rtx_cost (XEXP (x
, 0), mode
, code
, 0, speed_p
);
10870 /* ??? Increase the cost to deal with transferring from
10871 FP -> CORE registers? */
10874 else if (GET_MODE_CLASS (mode
) == MODE_FLOAT
10878 *cost
+= extra_cost
->fp
[mode
== DFmode
].roundint
;
10881 /* Vector costs? */
10883 *cost
= LIBCALL_COST (1);
10887 case UNSIGNED_FLOAT
:
10888 if (TARGET_HARD_FLOAT
)
10890 /* ??? Increase the cost to deal with transferring from CORE
10891 -> FP registers? */
10893 *cost
+= extra_cost
->fp
[mode
== DFmode
].fromint
;
10896 *cost
= LIBCALL_COST (1);
10904 /* Just a guess. Guess number of instructions in the asm
10905 plus one insn per input. Always a minimum of COSTS_N_INSNS (1)
10906 though (see PR60663). */
10907 int asm_length
= MAX (1, asm_str_count (ASM_OPERANDS_TEMPLATE (x
)));
10908 int num_operands
= ASM_OPERANDS_INPUT_LENGTH (x
);
10910 *cost
= COSTS_N_INSNS (asm_length
+ num_operands
);
10914 if (mode
!= VOIDmode
)
10915 *cost
= COSTS_N_INSNS (ARM_NUM_REGS (mode
));
10917 *cost
= COSTS_N_INSNS (4); /* Who knows? */
10922 #undef HANDLE_NARROW_SHIFT_ARITH
10924 /* RTX costs entry point. */
10927 arm_rtx_costs (rtx x
, machine_mode mode ATTRIBUTE_UNUSED
, int outer_code
,
10928 int opno ATTRIBUTE_UNUSED
, int *total
, bool speed
)
10931 int code
= GET_CODE (x
);
10932 gcc_assert (current_tune
->insn_extra_cost
);
10934 result
= arm_rtx_costs_internal (x
, (enum rtx_code
) code
,
10935 (enum rtx_code
) outer_code
,
10936 current_tune
->insn_extra_cost
,
10939 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10941 print_rtl_single (dump_file
, x
);
10942 fprintf (dump_file
, "\n%s cost: %d (%s)\n", speed
? "Hot" : "Cold",
10943 *total
, result
? "final" : "partial");
10948 /* All address computations that can be done are free, but rtx cost returns
10949 the same for practically all of them. So we weight the different types
10950 of address here in the order (most pref first):
10951 PRE/POST_INC/DEC, SHIFT or NON-INT sum, INT sum, REG, MEM or LABEL. */
10953 arm_arm_address_cost (rtx x
)
10955 enum rtx_code c
= GET_CODE (x
);
10957 if (c
== PRE_INC
|| c
== PRE_DEC
|| c
== POST_INC
|| c
== POST_DEC
)
10959 if (c
== MEM
|| c
== LABEL_REF
|| c
== SYMBOL_REF
)
10964 if (CONST_INT_P (XEXP (x
, 1)))
10967 if (ARITHMETIC_P (XEXP (x
, 0)) || ARITHMETIC_P (XEXP (x
, 1)))
10977 arm_thumb_address_cost (rtx x
)
10979 enum rtx_code c
= GET_CODE (x
);
10984 && REG_P (XEXP (x
, 0))
10985 && CONST_INT_P (XEXP (x
, 1)))
10992 arm_address_cost (rtx x
, machine_mode mode ATTRIBUTE_UNUSED
,
10993 addr_space_t as ATTRIBUTE_UNUSED
, bool speed ATTRIBUTE_UNUSED
)
10995 return TARGET_32BIT
? arm_arm_address_cost (x
) : arm_thumb_address_cost (x
);
10998 /* Adjust cost hook for XScale. */
11000 xscale_sched_adjust_cost (rtx_insn
*insn
, int dep_type
, rtx_insn
*dep
,
11003 /* Some true dependencies can have a higher cost depending
11004 on precisely how certain input operands are used. */
11006 && recog_memoized (insn
) >= 0
11007 && recog_memoized (dep
) >= 0)
11009 int shift_opnum
= get_attr_shift (insn
);
11010 enum attr_type attr_type
= get_attr_type (dep
);
11012 /* If nonzero, SHIFT_OPNUM contains the operand number of a shifted
11013 operand for INSN. If we have a shifted input operand and the
11014 instruction we depend on is another ALU instruction, then we may
11015 have to account for an additional stall. */
11016 if (shift_opnum
!= 0
11017 && (attr_type
== TYPE_ALU_SHIFT_IMM
11018 || attr_type
== TYPE_ALUS_SHIFT_IMM
11019 || attr_type
== TYPE_LOGIC_SHIFT_IMM
11020 || attr_type
== TYPE_LOGICS_SHIFT_IMM
11021 || attr_type
== TYPE_ALU_SHIFT_REG
11022 || attr_type
== TYPE_ALUS_SHIFT_REG
11023 || attr_type
== TYPE_LOGIC_SHIFT_REG
11024 || attr_type
== TYPE_LOGICS_SHIFT_REG
11025 || attr_type
== TYPE_MOV_SHIFT
11026 || attr_type
== TYPE_MVN_SHIFT
11027 || attr_type
== TYPE_MOV_SHIFT_REG
11028 || attr_type
== TYPE_MVN_SHIFT_REG
))
11030 rtx shifted_operand
;
11033 /* Get the shifted operand. */
11034 extract_insn (insn
);
11035 shifted_operand
= recog_data
.operand
[shift_opnum
];
11037 /* Iterate over all the operands in DEP. If we write an operand
11038 that overlaps with SHIFTED_OPERAND, then we have increase the
11039 cost of this dependency. */
11040 extract_insn (dep
);
11041 preprocess_constraints (dep
);
11042 for (opno
= 0; opno
< recog_data
.n_operands
; opno
++)
11044 /* We can ignore strict inputs. */
11045 if (recog_data
.operand_type
[opno
] == OP_IN
)
11048 if (reg_overlap_mentioned_p (recog_data
.operand
[opno
],
11060 /* Adjust cost hook for Cortex A9. */
11062 cortex_a9_sched_adjust_cost (rtx_insn
*insn
, int dep_type
, rtx_insn
*dep
,
11072 case REG_DEP_OUTPUT
:
11073 if (recog_memoized (insn
) >= 0
11074 && recog_memoized (dep
) >= 0)
11076 if (GET_CODE (PATTERN (insn
)) == SET
)
11079 (GET_MODE (SET_DEST (PATTERN (insn
)))) == MODE_FLOAT
11081 (GET_MODE (SET_SRC (PATTERN (insn
)))) == MODE_FLOAT
)
11083 enum attr_type attr_type_insn
= get_attr_type (insn
);
11084 enum attr_type attr_type_dep
= get_attr_type (dep
);
11086 /* By default all dependencies of the form
11089 have an extra latency of 1 cycle because
11090 of the input and output dependency in this
11091 case. However this gets modeled as an true
11092 dependency and hence all these checks. */
11093 if (REG_P (SET_DEST (PATTERN (insn
)))
11094 && reg_set_p (SET_DEST (PATTERN (insn
)), dep
))
11096 /* FMACS is a special case where the dependent
11097 instruction can be issued 3 cycles before
11098 the normal latency in case of an output
11100 if ((attr_type_insn
== TYPE_FMACS
11101 || attr_type_insn
== TYPE_FMACD
)
11102 && (attr_type_dep
== TYPE_FMACS
11103 || attr_type_dep
== TYPE_FMACD
))
11105 if (dep_type
== REG_DEP_OUTPUT
)
11106 *cost
= insn_default_latency (dep
) - 3;
11108 *cost
= insn_default_latency (dep
);
11113 if (dep_type
== REG_DEP_OUTPUT
)
11114 *cost
= insn_default_latency (dep
) + 1;
11116 *cost
= insn_default_latency (dep
);
11126 gcc_unreachable ();
11132 /* Adjust cost hook for FA726TE. */
11134 fa726te_sched_adjust_cost (rtx_insn
*insn
, int dep_type
, rtx_insn
*dep
,
11137 /* For FA726TE, true dependency on CPSR (i.e. set cond followed by predicated)
11138 have penalty of 3. */
11139 if (dep_type
== REG_DEP_TRUE
11140 && recog_memoized (insn
) >= 0
11141 && recog_memoized (dep
) >= 0
11142 && get_attr_conds (dep
) == CONDS_SET
)
11144 /* Use of carry (e.g. 64-bit arithmetic) in ALU: 3-cycle latency. */
11145 if (get_attr_conds (insn
) == CONDS_USE
11146 && get_attr_type (insn
) != TYPE_BRANCH
)
11152 if (GET_CODE (PATTERN (insn
)) == COND_EXEC
11153 || get_attr_conds (insn
) == CONDS_USE
)
11163 /* Implement TARGET_REGISTER_MOVE_COST.
11165 Moves between VFP_REGS and GENERAL_REGS are a single insn, but
11166 it is typically more expensive than a single memory access. We set
11167 the cost to less than two memory accesses so that floating
11168 point to integer conversion does not go through memory. */
11171 arm_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED
,
11172 reg_class_t from
, reg_class_t to
)
11176 if ((IS_VFP_CLASS (from
) && !IS_VFP_CLASS (to
))
11177 || (!IS_VFP_CLASS (from
) && IS_VFP_CLASS (to
)))
11179 else if ((from
== IWMMXT_REGS
&& to
!= IWMMXT_REGS
)
11180 || (from
!= IWMMXT_REGS
&& to
== IWMMXT_REGS
))
11182 else if (from
== IWMMXT_GR_REGS
|| to
== IWMMXT_GR_REGS
)
11189 if (from
== HI_REGS
|| to
== HI_REGS
)
11196 /* Implement TARGET_MEMORY_MOVE_COST. */
11199 arm_memory_move_cost (machine_mode mode
, reg_class_t rclass
,
11200 bool in ATTRIBUTE_UNUSED
)
11206 if (GET_MODE_SIZE (mode
) < 4)
11209 return ((2 * GET_MODE_SIZE (mode
)) * (rclass
== LO_REGS
? 1 : 2));
11213 /* Vectorizer cost model implementation. */
11215 /* Implement targetm.vectorize.builtin_vectorization_cost. */
11217 arm_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost
,
11219 int misalign ATTRIBUTE_UNUSED
)
11223 switch (type_of_cost
)
11226 return current_tune
->vec_costs
->scalar_stmt_cost
;
11229 return current_tune
->vec_costs
->scalar_load_cost
;
11232 return current_tune
->vec_costs
->scalar_store_cost
;
11235 return current_tune
->vec_costs
->vec_stmt_cost
;
11238 return current_tune
->vec_costs
->vec_align_load_cost
;
11241 return current_tune
->vec_costs
->vec_store_cost
;
11243 case vec_to_scalar
:
11244 return current_tune
->vec_costs
->vec_to_scalar_cost
;
11246 case scalar_to_vec
:
11247 return current_tune
->vec_costs
->scalar_to_vec_cost
;
11249 case unaligned_load
:
11250 return current_tune
->vec_costs
->vec_unalign_load_cost
;
11252 case unaligned_store
:
11253 return current_tune
->vec_costs
->vec_unalign_store_cost
;
11255 case cond_branch_taken
:
11256 return current_tune
->vec_costs
->cond_taken_branch_cost
;
11258 case cond_branch_not_taken
:
11259 return current_tune
->vec_costs
->cond_not_taken_branch_cost
;
11262 case vec_promote_demote
:
11263 return current_tune
->vec_costs
->vec_stmt_cost
;
11265 case vec_construct
:
11266 elements
= TYPE_VECTOR_SUBPARTS (vectype
);
11267 return elements
/ 2 + 1;
11270 gcc_unreachable ();
11274 /* Implement targetm.vectorize.add_stmt_cost. */
11277 arm_add_stmt_cost (void *data
, int count
, enum vect_cost_for_stmt kind
,
11278 struct _stmt_vec_info
*stmt_info
, int misalign
,
11279 enum vect_cost_model_location where
)
11281 unsigned *cost
= (unsigned *) data
;
11282 unsigned retval
= 0;
11284 if (flag_vect_cost_model
)
11286 tree vectype
= stmt_info
? stmt_vectype (stmt_info
) : NULL_TREE
;
11287 int stmt_cost
= arm_builtin_vectorization_cost (kind
, vectype
, misalign
);
11289 /* Statements in an inner loop relative to the loop being
11290 vectorized are weighted more heavily. The value here is
11291 arbitrary and could potentially be improved with analysis. */
11292 if (where
== vect_body
&& stmt_info
&& stmt_in_inner_loop_p (stmt_info
))
11293 count
*= 50; /* FIXME. */
11295 retval
= (unsigned) (count
* stmt_cost
);
11296 cost
[where
] += retval
;
11302 /* Return true if and only if this insn can dual-issue only as older. */
11304 cortexa7_older_only (rtx_insn
*insn
)
11306 if (recog_memoized (insn
) < 0)
11309 switch (get_attr_type (insn
))
11311 case TYPE_ALU_DSP_REG
:
11312 case TYPE_ALU_SREG
:
11313 case TYPE_ALUS_SREG
:
11314 case TYPE_LOGIC_REG
:
11315 case TYPE_LOGICS_REG
:
11317 case TYPE_ADCS_REG
:
11322 case TYPE_SHIFT_IMM
:
11323 case TYPE_SHIFT_REG
:
11324 case TYPE_LOAD_BYTE
:
11327 case TYPE_FFARITHS
:
11329 case TYPE_FFARITHD
:
11347 case TYPE_F_STORES
:
11354 /* Return true if and only if this insn can dual-issue as younger. */
11356 cortexa7_younger (FILE *file
, int verbose
, rtx_insn
*insn
)
11358 if (recog_memoized (insn
) < 0)
11361 fprintf (file
, ";; not cortexa7_younger %d\n", INSN_UID (insn
));
11365 switch (get_attr_type (insn
))
11368 case TYPE_ALUS_IMM
:
11369 case TYPE_LOGIC_IMM
:
11370 case TYPE_LOGICS_IMM
:
11375 case TYPE_MOV_SHIFT
:
11376 case TYPE_MOV_SHIFT_REG
:
11386 /* Look for an instruction that can dual issue only as an older
11387 instruction, and move it in front of any instructions that can
11388 dual-issue as younger, while preserving the relative order of all
11389 other instructions in the ready list. This is a hueuristic to help
11390 dual-issue in later cycles, by postponing issue of more flexible
11391 instructions. This heuristic may affect dual issue opportunities
11392 in the current cycle. */
11394 cortexa7_sched_reorder (FILE *file
, int verbose
, rtx_insn
**ready
,
11395 int *n_readyp
, int clock
)
11398 int first_older_only
= -1, first_younger
= -1;
11402 ";; sched_reorder for cycle %d with %d insns in ready list\n",
11406 /* Traverse the ready list from the head (the instruction to issue
11407 first), and looking for the first instruction that can issue as
11408 younger and the first instruction that can dual-issue only as
11410 for (i
= *n_readyp
- 1; i
>= 0; i
--)
11412 rtx_insn
*insn
= ready
[i
];
11413 if (cortexa7_older_only (insn
))
11415 first_older_only
= i
;
11417 fprintf (file
, ";; reorder older found %d\n", INSN_UID (insn
));
11420 else if (cortexa7_younger (file
, verbose
, insn
) && first_younger
== -1)
11424 /* Nothing to reorder because either no younger insn found or insn
11425 that can dual-issue only as older appears before any insn that
11426 can dual-issue as younger. */
11427 if (first_younger
== -1)
11430 fprintf (file
, ";; sched_reorder nothing to reorder as no younger\n");
11434 /* Nothing to reorder because no older-only insn in the ready list. */
11435 if (first_older_only
== -1)
11438 fprintf (file
, ";; sched_reorder nothing to reorder as no older_only\n");
11442 /* Move first_older_only insn before first_younger. */
11444 fprintf (file
, ";; cortexa7_sched_reorder insn %d before %d\n",
11445 INSN_UID(ready
[first_older_only
]),
11446 INSN_UID(ready
[first_younger
]));
11447 rtx_insn
*first_older_only_insn
= ready
[first_older_only
];
11448 for (i
= first_older_only
; i
< first_younger
; i
++)
11450 ready
[i
] = ready
[i
+1];
11453 ready
[i
] = first_older_only_insn
;
11457 /* Implement TARGET_SCHED_REORDER. */
11459 arm_sched_reorder (FILE *file
, int verbose
, rtx_insn
**ready
, int *n_readyp
,
11464 case TARGET_CPU_cortexa7
:
11465 cortexa7_sched_reorder (file
, verbose
, ready
, n_readyp
, clock
);
11468 /* Do nothing for other cores. */
11472 return arm_issue_rate ();
11475 /* This function implements the target macro TARGET_SCHED_ADJUST_COST.
11476 It corrects the value of COST based on the relationship between
11477 INSN and DEP through the dependence LINK. It returns the new
11478 value. There is a per-core adjust_cost hook to adjust scheduler costs
11479 and the per-core hook can choose to completely override the generic
11480 adjust_cost function. Only put bits of code into arm_adjust_cost that
11481 are common across all cores. */
11483 arm_adjust_cost (rtx_insn
*insn
, int dep_type
, rtx_insn
*dep
, int cost
,
11488 /* When generating Thumb-1 code, we want to place flag-setting operations
11489 close to a conditional branch which depends on them, so that we can
11490 omit the comparison. */
11493 && recog_memoized (insn
) == CODE_FOR_cbranchsi4_insn
11494 && recog_memoized (dep
) >= 0
11495 && get_attr_conds (dep
) == CONDS_SET
)
11498 if (current_tune
->sched_adjust_cost
!= NULL
)
11500 if (!current_tune
->sched_adjust_cost (insn
, dep_type
, dep
, &cost
))
11504 /* XXX Is this strictly true? */
11505 if (dep_type
== REG_DEP_ANTI
11506 || dep_type
== REG_DEP_OUTPUT
)
11509 /* Call insns don't incur a stall, even if they follow a load. */
11514 if ((i_pat
= single_set (insn
)) != NULL
11515 && MEM_P (SET_SRC (i_pat
))
11516 && (d_pat
= single_set (dep
)) != NULL
11517 && MEM_P (SET_DEST (d_pat
)))
11519 rtx src_mem
= XEXP (SET_SRC (i_pat
), 0);
11520 /* This is a load after a store, there is no conflict if the load reads
11521 from a cached area. Assume that loads from the stack, and from the
11522 constant pool are cached, and that others will miss. This is a
11525 if ((GET_CODE (src_mem
) == SYMBOL_REF
11526 && CONSTANT_POOL_ADDRESS_P (src_mem
))
11527 || reg_mentioned_p (stack_pointer_rtx
, src_mem
)
11528 || reg_mentioned_p (frame_pointer_rtx
, src_mem
)
11529 || reg_mentioned_p (hard_frame_pointer_rtx
, src_mem
))
11537 arm_max_conditional_execute (void)
11539 return max_insns_skipped
;
11543 arm_default_branch_cost (bool speed_p
, bool predictable_p ATTRIBUTE_UNUSED
)
11546 return (TARGET_THUMB2
&& !speed_p
) ? 1 : 4;
11548 return (optimize
> 0) ? 2 : 0;
11552 arm_cortex_a5_branch_cost (bool speed_p
, bool predictable_p
)
11554 return speed_p
? 0 : arm_default_branch_cost (speed_p
, predictable_p
);
11557 /* Thumb-2 branches are relatively cheap on Cortex-M processors ("1 + P cycles"
11558 on Cortex-M4, where P varies from 1 to 3 according to some criteria), since
11559 sequences of non-executed instructions in IT blocks probably take the same
11560 amount of time as executed instructions (and the IT instruction itself takes
11561 space in icache). This function was experimentally determined to give good
11562 results on a popular embedded benchmark. */
11565 arm_cortex_m_branch_cost (bool speed_p
, bool predictable_p
)
11567 return (TARGET_32BIT
&& speed_p
) ? 1
11568 : arm_default_branch_cost (speed_p
, predictable_p
);
11572 arm_cortex_m7_branch_cost (bool speed_p
, bool predictable_p
)
11574 return speed_p
? 0 : arm_default_branch_cost (speed_p
, predictable_p
);
11577 static bool fp_consts_inited
= false;
11579 static REAL_VALUE_TYPE value_fp0
;
11582 init_fp_table (void)
11586 r
= REAL_VALUE_ATOF ("0", DFmode
);
11588 fp_consts_inited
= true;
11591 /* Return TRUE if rtx X is a valid immediate FP constant. */
11593 arm_const_double_rtx (rtx x
)
11595 const REAL_VALUE_TYPE
*r
;
11597 if (!fp_consts_inited
)
11600 r
= CONST_DOUBLE_REAL_VALUE (x
);
11601 if (REAL_VALUE_MINUS_ZERO (*r
))
11604 if (real_equal (r
, &value_fp0
))
11610 /* VFPv3 has a fairly wide range of representable immediates, formed from
11611 "quarter-precision" floating-point values. These can be evaluated using this
11612 formula (with ^ for exponentiation):
11616 Where 's' is a sign bit (0/1), 'n' and 'r' are integers such that
11617 16 <= n <= 31 and 0 <= r <= 7.
11619 These values are mapped onto an 8-bit integer ABCDEFGH s.t.
11621 - A (most-significant) is the sign bit.
11622 - BCD are the exponent (encoded as r XOR 3).
11623 - EFGH are the mantissa (encoded as n - 16).
11626 /* Return an integer index for a VFPv3 immediate operand X suitable for the
11627 fconst[sd] instruction, or -1 if X isn't suitable. */
11629 vfp3_const_double_index (rtx x
)
11631 REAL_VALUE_TYPE r
, m
;
11632 int sign
, exponent
;
11633 unsigned HOST_WIDE_INT mantissa
, mant_hi
;
11634 unsigned HOST_WIDE_INT mask
;
11635 int point_pos
= 2 * HOST_BITS_PER_WIDE_INT
- 1;
11638 if (!TARGET_VFP3
|| !CONST_DOUBLE_P (x
))
11641 r
= *CONST_DOUBLE_REAL_VALUE (x
);
11643 /* We can't represent these things, so detect them first. */
11644 if (REAL_VALUE_ISINF (r
) || REAL_VALUE_ISNAN (r
) || REAL_VALUE_MINUS_ZERO (r
))
11647 /* Extract sign, exponent and mantissa. */
11648 sign
= REAL_VALUE_NEGATIVE (r
) ? 1 : 0;
11649 r
= real_value_abs (&r
);
11650 exponent
= REAL_EXP (&r
);
11651 /* For the mantissa, we expand into two HOST_WIDE_INTS, apart from the
11652 highest (sign) bit, with a fixed binary point at bit point_pos.
11653 WARNING: If there's ever a VFP version which uses more than 2 * H_W_I - 1
11654 bits for the mantissa, this may fail (low bits would be lost). */
11655 real_ldexp (&m
, &r
, point_pos
- exponent
);
11656 wide_int w
= real_to_integer (&m
, &fail
, HOST_BITS_PER_WIDE_INT
* 2);
11657 mantissa
= w
.elt (0);
11658 mant_hi
= w
.elt (1);
11660 /* If there are bits set in the low part of the mantissa, we can't
11661 represent this value. */
11665 /* Now make it so that mantissa contains the most-significant bits, and move
11666 the point_pos to indicate that the least-significant bits have been
11668 point_pos
-= HOST_BITS_PER_WIDE_INT
;
11669 mantissa
= mant_hi
;
11671 /* We can permit four significant bits of mantissa only, plus a high bit
11672 which is always 1. */
11673 mask
= (HOST_WIDE_INT_1U
<< (point_pos
- 5)) - 1;
11674 if ((mantissa
& mask
) != 0)
11677 /* Now we know the mantissa is in range, chop off the unneeded bits. */
11678 mantissa
>>= point_pos
- 5;
11680 /* The mantissa may be zero. Disallow that case. (It's possible to load the
11681 floating-point immediate zero with Neon using an integer-zero load, but
11682 that case is handled elsewhere.) */
11686 gcc_assert (mantissa
>= 16 && mantissa
<= 31);
11688 /* The value of 5 here would be 4 if GCC used IEEE754-like encoding (where
11689 normalized significands are in the range [1, 2). (Our mantissa is shifted
11690 left 4 places at this point relative to normalized IEEE754 values). GCC
11691 internally uses [0.5, 1) (see real.c), so the exponent returned from
11692 REAL_EXP must be altered. */
11693 exponent
= 5 - exponent
;
11695 if (exponent
< 0 || exponent
> 7)
11698 /* Sign, mantissa and exponent are now in the correct form to plug into the
11699 formula described in the comment above. */
11700 return (sign
<< 7) | ((exponent
^ 3) << 4) | (mantissa
- 16);
11703 /* Return TRUE if rtx X is a valid immediate VFPv3 constant. */
11705 vfp3_const_double_rtx (rtx x
)
11710 return vfp3_const_double_index (x
) != -1;
11713 /* Recognize immediates which can be used in various Neon instructions. Legal
11714 immediates are described by the following table (for VMVN variants, the
11715 bitwise inverse of the constant shown is recognized. In either case, VMOV
11716 is output and the correct instruction to use for a given constant is chosen
11717 by the assembler). The constant shown is replicated across all elements of
11718 the destination vector.
11720 insn elems variant constant (binary)
11721 ---- ----- ------- -----------------
11722 vmov i32 0 00000000 00000000 00000000 abcdefgh
11723 vmov i32 1 00000000 00000000 abcdefgh 00000000
11724 vmov i32 2 00000000 abcdefgh 00000000 00000000
11725 vmov i32 3 abcdefgh 00000000 00000000 00000000
11726 vmov i16 4 00000000 abcdefgh
11727 vmov i16 5 abcdefgh 00000000
11728 vmvn i32 6 00000000 00000000 00000000 abcdefgh
11729 vmvn i32 7 00000000 00000000 abcdefgh 00000000
11730 vmvn i32 8 00000000 abcdefgh 00000000 00000000
11731 vmvn i32 9 abcdefgh 00000000 00000000 00000000
11732 vmvn i16 10 00000000 abcdefgh
11733 vmvn i16 11 abcdefgh 00000000
11734 vmov i32 12 00000000 00000000 abcdefgh 11111111
11735 vmvn i32 13 00000000 00000000 abcdefgh 11111111
11736 vmov i32 14 00000000 abcdefgh 11111111 11111111
11737 vmvn i32 15 00000000 abcdefgh 11111111 11111111
11738 vmov i8 16 abcdefgh
11739 vmov i64 17 aaaaaaaa bbbbbbbb cccccccc dddddddd
11740 eeeeeeee ffffffff gggggggg hhhhhhhh
11741 vmov f32 18 aBbbbbbc defgh000 00000000 00000000
11742 vmov f32 19 00000000 00000000 00000000 00000000
11744 For case 18, B = !b. Representable values are exactly those accepted by
11745 vfp3_const_double_index, but are output as floating-point numbers rather
11748 For case 19, we will change it to vmov.i32 when assembling.
11750 Variants 0-5 (inclusive) may also be used as immediates for the second
11751 operand of VORR/VBIC instructions.
11753 The INVERSE argument causes the bitwise inverse of the given operand to be
11754 recognized instead (used for recognizing legal immediates for the VAND/VORN
11755 pseudo-instructions). If INVERSE is true, the value placed in *MODCONST is
11756 *not* inverted (i.e. the pseudo-instruction forms vand/vorn should still be
11757 output, rather than the real insns vbic/vorr).
11759 INVERSE makes no difference to the recognition of float vectors.
11761 The return value is the variant of immediate as shown in the above table, or
11762 -1 if the given value doesn't match any of the listed patterns.
11765 neon_valid_immediate (rtx op
, machine_mode mode
, int inverse
,
11766 rtx
*modconst
, int *elementwidth
)
11768 #define CHECK(STRIDE, ELSIZE, CLASS, TEST) \
11770 for (i = 0; i < idx; i += (STRIDE)) \
11775 immtype = (CLASS); \
11776 elsize = (ELSIZE); \
11780 unsigned int i
, elsize
= 0, idx
= 0, n_elts
;
11781 unsigned int innersize
;
11782 unsigned char bytes
[16];
11783 int immtype
= -1, matches
;
11784 unsigned int invmask
= inverse
? 0xff : 0;
11785 bool vector
= GET_CODE (op
) == CONST_VECTOR
;
11788 n_elts
= CONST_VECTOR_NUNITS (op
);
11792 if (mode
== VOIDmode
)
11796 innersize
= GET_MODE_UNIT_SIZE (mode
);
11798 /* Vectors of float constants. */
11799 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
)
11801 rtx el0
= CONST_VECTOR_ELT (op
, 0);
11803 if (!vfp3_const_double_rtx (el0
) && el0
!= CONST0_RTX (GET_MODE (el0
)))
11806 /* FP16 vectors cannot be represented. */
11807 if (GET_MODE_INNER (mode
) == HFmode
)
11810 /* All elements in the vector must be the same. Note that 0.0 and -0.0
11811 are distinct in this context. */
11812 if (!const_vec_duplicate_p (op
))
11816 *modconst
= CONST_VECTOR_ELT (op
, 0);
11821 if (el0
== CONST0_RTX (GET_MODE (el0
)))
11827 /* The tricks done in the code below apply for little-endian vector layout.
11828 For big-endian vectors only allow vectors of the form { a, a, a..., a }.
11829 FIXME: Implement logic for big-endian vectors. */
11830 if (BYTES_BIG_ENDIAN
&& vector
&& !const_vec_duplicate_p (op
))
11833 /* Splat vector constant out into a byte vector. */
11834 for (i
= 0; i
< n_elts
; i
++)
11836 rtx el
= vector
? CONST_VECTOR_ELT (op
, i
) : op
;
11837 unsigned HOST_WIDE_INT elpart
;
11839 gcc_assert (CONST_INT_P (el
));
11840 elpart
= INTVAL (el
);
11842 for (unsigned int byte
= 0; byte
< innersize
; byte
++)
11844 bytes
[idx
++] = (elpart
& 0xff) ^ invmask
;
11845 elpart
>>= BITS_PER_UNIT
;
11849 /* Sanity check. */
11850 gcc_assert (idx
== GET_MODE_SIZE (mode
));
11854 CHECK (4, 32, 0, bytes
[i
] == bytes
[0] && bytes
[i
+ 1] == 0
11855 && bytes
[i
+ 2] == 0 && bytes
[i
+ 3] == 0);
11857 CHECK (4, 32, 1, bytes
[i
] == 0 && bytes
[i
+ 1] == bytes
[1]
11858 && bytes
[i
+ 2] == 0 && bytes
[i
+ 3] == 0);
11860 CHECK (4, 32, 2, bytes
[i
] == 0 && bytes
[i
+ 1] == 0
11861 && bytes
[i
+ 2] == bytes
[2] && bytes
[i
+ 3] == 0);
11863 CHECK (4, 32, 3, bytes
[i
] == 0 && bytes
[i
+ 1] == 0
11864 && bytes
[i
+ 2] == 0 && bytes
[i
+ 3] == bytes
[3]);
11866 CHECK (2, 16, 4, bytes
[i
] == bytes
[0] && bytes
[i
+ 1] == 0);
11868 CHECK (2, 16, 5, bytes
[i
] == 0 && bytes
[i
+ 1] == bytes
[1]);
11870 CHECK (4, 32, 6, bytes
[i
] == bytes
[0] && bytes
[i
+ 1] == 0xff
11871 && bytes
[i
+ 2] == 0xff && bytes
[i
+ 3] == 0xff);
11873 CHECK (4, 32, 7, bytes
[i
] == 0xff && bytes
[i
+ 1] == bytes
[1]
11874 && bytes
[i
+ 2] == 0xff && bytes
[i
+ 3] == 0xff);
11876 CHECK (4, 32, 8, bytes
[i
] == 0xff && bytes
[i
+ 1] == 0xff
11877 && bytes
[i
+ 2] == bytes
[2] && bytes
[i
+ 3] == 0xff);
11879 CHECK (4, 32, 9, bytes
[i
] == 0xff && bytes
[i
+ 1] == 0xff
11880 && bytes
[i
+ 2] == 0xff && bytes
[i
+ 3] == bytes
[3]);
11882 CHECK (2, 16, 10, bytes
[i
] == bytes
[0] && bytes
[i
+ 1] == 0xff);
11884 CHECK (2, 16, 11, bytes
[i
] == 0xff && bytes
[i
+ 1] == bytes
[1]);
11886 CHECK (4, 32, 12, bytes
[i
] == 0xff && bytes
[i
+ 1] == bytes
[1]
11887 && bytes
[i
+ 2] == 0 && bytes
[i
+ 3] == 0);
11889 CHECK (4, 32, 13, bytes
[i
] == 0 && bytes
[i
+ 1] == bytes
[1]
11890 && bytes
[i
+ 2] == 0xff && bytes
[i
+ 3] == 0xff);
11892 CHECK (4, 32, 14, bytes
[i
] == 0xff && bytes
[i
+ 1] == 0xff
11893 && bytes
[i
+ 2] == bytes
[2] && bytes
[i
+ 3] == 0);
11895 CHECK (4, 32, 15, bytes
[i
] == 0 && bytes
[i
+ 1] == 0
11896 && bytes
[i
+ 2] == bytes
[2] && bytes
[i
+ 3] == 0xff);
11898 CHECK (1, 8, 16, bytes
[i
] == bytes
[0]);
11900 CHECK (1, 64, 17, (bytes
[i
] == 0 || bytes
[i
] == 0xff)
11901 && bytes
[i
] == bytes
[(i
+ 8) % idx
]);
11909 *elementwidth
= elsize
;
11913 unsigned HOST_WIDE_INT imm
= 0;
11915 /* Un-invert bytes of recognized vector, if necessary. */
11917 for (i
= 0; i
< idx
; i
++)
11918 bytes
[i
] ^= invmask
;
11922 /* FIXME: Broken on 32-bit H_W_I hosts. */
11923 gcc_assert (sizeof (HOST_WIDE_INT
) == 8);
11925 for (i
= 0; i
< 8; i
++)
11926 imm
|= (unsigned HOST_WIDE_INT
) (bytes
[i
] ? 0xff : 0)
11927 << (i
* BITS_PER_UNIT
);
11929 *modconst
= GEN_INT (imm
);
11933 unsigned HOST_WIDE_INT imm
= 0;
11935 for (i
= 0; i
< elsize
/ BITS_PER_UNIT
; i
++)
11936 imm
|= (unsigned HOST_WIDE_INT
) bytes
[i
] << (i
* BITS_PER_UNIT
);
11938 *modconst
= GEN_INT (imm
);
11946 /* Return TRUE if rtx X is legal for use as either a Neon VMOV (or, implicitly,
11947 VMVN) immediate. Write back width per element to *ELEMENTWIDTH (or zero for
11948 float elements), and a modified constant (whatever should be output for a
11949 VMOV) in *MODCONST. */
11952 neon_immediate_valid_for_move (rtx op
, machine_mode mode
,
11953 rtx
*modconst
, int *elementwidth
)
11957 int retval
= neon_valid_immediate (op
, mode
, 0, &tmpconst
, &tmpwidth
);
11963 *modconst
= tmpconst
;
11966 *elementwidth
= tmpwidth
;
11971 /* Return TRUE if rtx X is legal for use in a VORR or VBIC instruction. If
11972 the immediate is valid, write a constant suitable for using as an operand
11973 to VORR/VBIC/VAND/VORN to *MODCONST and the corresponding element width to
11974 *ELEMENTWIDTH. See neon_valid_immediate for description of INVERSE. */
11977 neon_immediate_valid_for_logic (rtx op
, machine_mode mode
, int inverse
,
11978 rtx
*modconst
, int *elementwidth
)
11982 int retval
= neon_valid_immediate (op
, mode
, inverse
, &tmpconst
, &tmpwidth
);
11984 if (retval
< 0 || retval
> 5)
11988 *modconst
= tmpconst
;
11991 *elementwidth
= tmpwidth
;
11996 /* Return TRUE if rtx OP is legal for use in a VSHR or VSHL instruction. If
11997 the immediate is valid, write a constant suitable for using as an operand
11998 to VSHR/VSHL to *MODCONST and the corresponding element width to
11999 *ELEMENTWIDTH. ISLEFTSHIFT is for determine left or right shift,
12000 because they have different limitations. */
12003 neon_immediate_valid_for_shift (rtx op
, machine_mode mode
,
12004 rtx
*modconst
, int *elementwidth
,
12007 unsigned int innersize
= GET_MODE_UNIT_SIZE (mode
);
12008 unsigned int n_elts
= CONST_VECTOR_NUNITS (op
), i
;
12009 unsigned HOST_WIDE_INT last_elt
= 0;
12010 unsigned HOST_WIDE_INT maxshift
;
12012 /* Split vector constant out into a byte vector. */
12013 for (i
= 0; i
< n_elts
; i
++)
12015 rtx el
= CONST_VECTOR_ELT (op
, i
);
12016 unsigned HOST_WIDE_INT elpart
;
12018 if (CONST_INT_P (el
))
12019 elpart
= INTVAL (el
);
12020 else if (CONST_DOUBLE_P (el
))
12023 gcc_unreachable ();
12025 if (i
!= 0 && elpart
!= last_elt
)
12031 /* Shift less than element size. */
12032 maxshift
= innersize
* 8;
12036 /* Left shift immediate value can be from 0 to <size>-1. */
12037 if (last_elt
>= maxshift
)
12042 /* Right shift immediate value can be from 1 to <size>. */
12043 if (last_elt
== 0 || last_elt
> maxshift
)
12048 *elementwidth
= innersize
* 8;
12051 *modconst
= CONST_VECTOR_ELT (op
, 0);
12056 /* Return a string suitable for output of Neon immediate logic operation
12060 neon_output_logic_immediate (const char *mnem
, rtx
*op2
, machine_mode mode
,
12061 int inverse
, int quad
)
12063 int width
, is_valid
;
12064 static char templ
[40];
12066 is_valid
= neon_immediate_valid_for_logic (*op2
, mode
, inverse
, op2
, &width
);
12068 gcc_assert (is_valid
!= 0);
12071 sprintf (templ
, "%s.i%d\t%%q0, %%2", mnem
, width
);
12073 sprintf (templ
, "%s.i%d\t%%P0, %%2", mnem
, width
);
12078 /* Return a string suitable for output of Neon immediate shift operation
12079 (VSHR or VSHL) MNEM. */
12082 neon_output_shift_immediate (const char *mnem
, char sign
, rtx
*op2
,
12083 machine_mode mode
, int quad
,
12086 int width
, is_valid
;
12087 static char templ
[40];
12089 is_valid
= neon_immediate_valid_for_shift (*op2
, mode
, op2
, &width
, isleftshift
);
12090 gcc_assert (is_valid
!= 0);
12093 sprintf (templ
, "%s.%c%d\t%%q0, %%q1, %%2", mnem
, sign
, width
);
12095 sprintf (templ
, "%s.%c%d\t%%P0, %%P1, %%2", mnem
, sign
, width
);
12100 /* Output a sequence of pairwise operations to implement a reduction.
12101 NOTE: We do "too much work" here, because pairwise operations work on two
12102 registers-worth of operands in one go. Unfortunately we can't exploit those
12103 extra calculations to do the full operation in fewer steps, I don't think.
12104 Although all vector elements of the result but the first are ignored, we
12105 actually calculate the same result in each of the elements. An alternative
12106 such as initially loading a vector with zero to use as each of the second
12107 operands would use up an additional register and take an extra instruction,
12108 for no particular gain. */
12111 neon_pairwise_reduce (rtx op0
, rtx op1
, machine_mode mode
,
12112 rtx (*reduc
) (rtx
, rtx
, rtx
))
12114 unsigned int i
, parts
= GET_MODE_SIZE (mode
) / GET_MODE_UNIT_SIZE (mode
);
12117 for (i
= parts
/ 2; i
>= 1; i
/= 2)
12119 rtx dest
= (i
== 1) ? op0
: gen_reg_rtx (mode
);
12120 emit_insn (reduc (dest
, tmpsum
, tmpsum
));
12125 /* If VALS is a vector constant that can be loaded into a register
12126 using VDUP, generate instructions to do so and return an RTX to
12127 assign to the register. Otherwise return NULL_RTX. */
12130 neon_vdup_constant (rtx vals
)
12132 machine_mode mode
= GET_MODE (vals
);
12133 machine_mode inner_mode
= GET_MODE_INNER (mode
);
12136 if (GET_CODE (vals
) != CONST_VECTOR
|| GET_MODE_SIZE (inner_mode
) > 4)
12139 if (!const_vec_duplicate_p (vals
, &x
))
12140 /* The elements are not all the same. We could handle repeating
12141 patterns of a mode larger than INNER_MODE here (e.g. int8x8_t
12142 {0, C, 0, C, 0, C, 0, C} which can be loaded using
12146 /* We can load this constant by using VDUP and a constant in a
12147 single ARM register. This will be cheaper than a vector
12150 x
= copy_to_mode_reg (inner_mode
, x
);
12151 return gen_rtx_VEC_DUPLICATE (mode
, x
);
12154 /* Generate code to load VALS, which is a PARALLEL containing only
12155 constants (for vec_init) or CONST_VECTOR, efficiently into a
12156 register. Returns an RTX to copy into the register, or NULL_RTX
12157 for a PARALLEL that can not be converted into a CONST_VECTOR. */
12160 neon_make_constant (rtx vals
)
12162 machine_mode mode
= GET_MODE (vals
);
12164 rtx const_vec
= NULL_RTX
;
12165 int n_elts
= GET_MODE_NUNITS (mode
);
12169 if (GET_CODE (vals
) == CONST_VECTOR
)
12171 else if (GET_CODE (vals
) == PARALLEL
)
12173 /* A CONST_VECTOR must contain only CONST_INTs and
12174 CONST_DOUBLEs, but CONSTANT_P allows more (e.g. SYMBOL_REF).
12175 Only store valid constants in a CONST_VECTOR. */
12176 for (i
= 0; i
< n_elts
; ++i
)
12178 rtx x
= XVECEXP (vals
, 0, i
);
12179 if (CONST_INT_P (x
) || CONST_DOUBLE_P (x
))
12182 if (n_const
== n_elts
)
12183 const_vec
= gen_rtx_CONST_VECTOR (mode
, XVEC (vals
, 0));
12186 gcc_unreachable ();
12188 if (const_vec
!= NULL
12189 && neon_immediate_valid_for_move (const_vec
, mode
, NULL
, NULL
))
12190 /* Load using VMOV. On Cortex-A8 this takes one cycle. */
12192 else if ((target
= neon_vdup_constant (vals
)) != NULL_RTX
)
12193 /* Loaded using VDUP. On Cortex-A8 the VDUP takes one NEON
12194 pipeline cycle; creating the constant takes one or two ARM
12195 pipeline cycles. */
12197 else if (const_vec
!= NULL_RTX
)
12198 /* Load from constant pool. On Cortex-A8 this takes two cycles
12199 (for either double or quad vectors). We can not take advantage
12200 of single-cycle VLD1 because we need a PC-relative addressing
12204 /* A PARALLEL containing something not valid inside CONST_VECTOR.
12205 We can not construct an initializer. */
12209 /* Initialize vector TARGET to VALS. */
12212 neon_expand_vector_init (rtx target
, rtx vals
)
12214 machine_mode mode
= GET_MODE (target
);
12215 machine_mode inner_mode
= GET_MODE_INNER (mode
);
12216 int n_elts
= GET_MODE_NUNITS (mode
);
12217 int n_var
= 0, one_var
= -1;
12218 bool all_same
= true;
12222 for (i
= 0; i
< n_elts
; ++i
)
12224 x
= XVECEXP (vals
, 0, i
);
12225 if (!CONSTANT_P (x
))
12226 ++n_var
, one_var
= i
;
12228 if (i
> 0 && !rtx_equal_p (x
, XVECEXP (vals
, 0, 0)))
12234 rtx constant
= neon_make_constant (vals
);
12235 if (constant
!= NULL_RTX
)
12237 emit_move_insn (target
, constant
);
12242 /* Splat a single non-constant element if we can. */
12243 if (all_same
&& GET_MODE_SIZE (inner_mode
) <= 4)
12245 x
= copy_to_mode_reg (inner_mode
, XVECEXP (vals
, 0, 0));
12246 emit_insn (gen_rtx_SET (target
, gen_rtx_VEC_DUPLICATE (mode
, x
)));
12250 /* One field is non-constant. Load constant then overwrite varying
12251 field. This is more efficient than using the stack. */
12254 rtx copy
= copy_rtx (vals
);
12255 rtx index
= GEN_INT (one_var
);
12257 /* Load constant part of vector, substitute neighboring value for
12258 varying element. */
12259 XVECEXP (copy
, 0, one_var
) = XVECEXP (vals
, 0, (one_var
+ 1) % n_elts
);
12260 neon_expand_vector_init (target
, copy
);
12262 /* Insert variable. */
12263 x
= copy_to_mode_reg (inner_mode
, XVECEXP (vals
, 0, one_var
));
12267 emit_insn (gen_neon_vset_lanev8qi (target
, x
, target
, index
));
12270 emit_insn (gen_neon_vset_lanev16qi (target
, x
, target
, index
));
12273 emit_insn (gen_neon_vset_lanev4hi (target
, x
, target
, index
));
12276 emit_insn (gen_neon_vset_lanev8hi (target
, x
, target
, index
));
12279 emit_insn (gen_neon_vset_lanev2si (target
, x
, target
, index
));
12282 emit_insn (gen_neon_vset_lanev4si (target
, x
, target
, index
));
12285 emit_insn (gen_neon_vset_lanev2sf (target
, x
, target
, index
));
12288 emit_insn (gen_neon_vset_lanev4sf (target
, x
, target
, index
));
12291 emit_insn (gen_neon_vset_lanev2di (target
, x
, target
, index
));
12294 gcc_unreachable ();
12299 /* Construct the vector in memory one field at a time
12300 and load the whole vector. */
12301 mem
= assign_stack_temp (mode
, GET_MODE_SIZE (mode
));
12302 for (i
= 0; i
< n_elts
; i
++)
12303 emit_move_insn (adjust_address_nv (mem
, inner_mode
,
12304 i
* GET_MODE_SIZE (inner_mode
)),
12305 XVECEXP (vals
, 0, i
));
12306 emit_move_insn (target
, mem
);
12309 /* Ensure OPERAND lies between LOW (inclusive) and HIGH (exclusive). Raise
12310 ERR if it doesn't. EXP indicates the source location, which includes the
12311 inlining history for intrinsics. */
12314 bounds_check (rtx operand
, HOST_WIDE_INT low
, HOST_WIDE_INT high
,
12315 const_tree exp
, const char *desc
)
12317 HOST_WIDE_INT lane
;
12319 gcc_assert (CONST_INT_P (operand
));
12321 lane
= INTVAL (operand
);
12323 if (lane
< low
|| lane
>= high
)
12326 error ("%K%s %wd out of range %wd - %wd",
12327 exp
, desc
, lane
, low
, high
- 1);
12329 error ("%s %wd out of range %wd - %wd", desc
, lane
, low
, high
- 1);
12333 /* Bounds-check lanes. */
12336 neon_lane_bounds (rtx operand
, HOST_WIDE_INT low
, HOST_WIDE_INT high
,
12339 bounds_check (operand
, low
, high
, exp
, "lane");
12342 /* Bounds-check constants. */
12345 arm_const_bounds (rtx operand
, HOST_WIDE_INT low
, HOST_WIDE_INT high
)
12347 bounds_check (operand
, low
, high
, NULL_TREE
, "constant");
12351 neon_element_bits (machine_mode mode
)
12353 return GET_MODE_UNIT_BITSIZE (mode
);
12357 /* Predicates for `match_operand' and `match_operator'. */
12359 /* Return TRUE if OP is a valid coprocessor memory address pattern.
12360 WB is true if full writeback address modes are allowed and is false
12361 if limited writeback address modes (POST_INC and PRE_DEC) are
12365 arm_coproc_mem_operand (rtx op
, bool wb
)
12369 /* Reject eliminable registers. */
12370 if (! (reload_in_progress
|| reload_completed
|| lra_in_progress
)
12371 && ( reg_mentioned_p (frame_pointer_rtx
, op
)
12372 || reg_mentioned_p (arg_pointer_rtx
, op
)
12373 || reg_mentioned_p (virtual_incoming_args_rtx
, op
)
12374 || reg_mentioned_p (virtual_outgoing_args_rtx
, op
)
12375 || reg_mentioned_p (virtual_stack_dynamic_rtx
, op
)
12376 || reg_mentioned_p (virtual_stack_vars_rtx
, op
)))
12379 /* Constants are converted into offsets from labels. */
12383 ind
= XEXP (op
, 0);
12385 if (reload_completed
12386 && (GET_CODE (ind
) == LABEL_REF
12387 || (GET_CODE (ind
) == CONST
12388 && GET_CODE (XEXP (ind
, 0)) == PLUS
12389 && GET_CODE (XEXP (XEXP (ind
, 0), 0)) == LABEL_REF
12390 && CONST_INT_P (XEXP (XEXP (ind
, 0), 1)))))
12393 /* Match: (mem (reg)). */
12395 return arm_address_register_rtx_p (ind
, 0);
12397 /* Autoincremment addressing modes. POST_INC and PRE_DEC are
12398 acceptable in any case (subject to verification by
12399 arm_address_register_rtx_p). We need WB to be true to accept
12400 PRE_INC and POST_DEC. */
12401 if (GET_CODE (ind
) == POST_INC
12402 || GET_CODE (ind
) == PRE_DEC
12404 && (GET_CODE (ind
) == PRE_INC
12405 || GET_CODE (ind
) == POST_DEC
)))
12406 return arm_address_register_rtx_p (XEXP (ind
, 0), 0);
12409 && (GET_CODE (ind
) == POST_MODIFY
|| GET_CODE (ind
) == PRE_MODIFY
)
12410 && arm_address_register_rtx_p (XEXP (ind
, 0), 0)
12411 && GET_CODE (XEXP (ind
, 1)) == PLUS
12412 && rtx_equal_p (XEXP (XEXP (ind
, 1), 0), XEXP (ind
, 0)))
12413 ind
= XEXP (ind
, 1);
12418 if (GET_CODE (ind
) == PLUS
12419 && REG_P (XEXP (ind
, 0))
12420 && REG_MODE_OK_FOR_BASE_P (XEXP (ind
, 0), VOIDmode
)
12421 && CONST_INT_P (XEXP (ind
, 1))
12422 && INTVAL (XEXP (ind
, 1)) > -1024
12423 && INTVAL (XEXP (ind
, 1)) < 1024
12424 && (INTVAL (XEXP (ind
, 1)) & 3) == 0)
12430 /* Return TRUE if OP is a memory operand which we can load or store a vector
12431 to/from. TYPE is one of the following values:
12432 0 - Vector load/stor (vldr)
12433 1 - Core registers (ldm)
12434 2 - Element/structure loads (vld1)
12437 neon_vector_mem_operand (rtx op
, int type
, bool strict
)
12441 /* Reject eliminable registers. */
12442 if (strict
&& ! (reload_in_progress
|| reload_completed
)
12443 && (reg_mentioned_p (frame_pointer_rtx
, op
)
12444 || reg_mentioned_p (arg_pointer_rtx
, op
)
12445 || reg_mentioned_p (virtual_incoming_args_rtx
, op
)
12446 || reg_mentioned_p (virtual_outgoing_args_rtx
, op
)
12447 || reg_mentioned_p (virtual_stack_dynamic_rtx
, op
)
12448 || reg_mentioned_p (virtual_stack_vars_rtx
, op
)))
12451 /* Constants are converted into offsets from labels. */
12455 ind
= XEXP (op
, 0);
12457 if (reload_completed
12458 && (GET_CODE (ind
) == LABEL_REF
12459 || (GET_CODE (ind
) == CONST
12460 && GET_CODE (XEXP (ind
, 0)) == PLUS
12461 && GET_CODE (XEXP (XEXP (ind
, 0), 0)) == LABEL_REF
12462 && CONST_INT_P (XEXP (XEXP (ind
, 0), 1)))))
12465 /* Match: (mem (reg)). */
12467 return arm_address_register_rtx_p (ind
, 0);
12469 /* Allow post-increment with Neon registers. */
12470 if ((type
!= 1 && GET_CODE (ind
) == POST_INC
)
12471 || (type
== 0 && GET_CODE (ind
) == PRE_DEC
))
12472 return arm_address_register_rtx_p (XEXP (ind
, 0), 0);
12474 /* Allow post-increment by register for VLDn */
12475 if (type
== 2 && GET_CODE (ind
) == POST_MODIFY
12476 && GET_CODE (XEXP (ind
, 1)) == PLUS
12477 && REG_P (XEXP (XEXP (ind
, 1), 1)))
12484 && GET_CODE (ind
) == PLUS
12485 && REG_P (XEXP (ind
, 0))
12486 && REG_MODE_OK_FOR_BASE_P (XEXP (ind
, 0), VOIDmode
)
12487 && CONST_INT_P (XEXP (ind
, 1))
12488 && INTVAL (XEXP (ind
, 1)) > -1024
12489 /* For quad modes, we restrict the constant offset to be slightly less
12490 than what the instruction format permits. We have no such constraint
12491 on double mode offsets. (This must match arm_legitimate_index_p.) */
12492 && (INTVAL (XEXP (ind
, 1))
12493 < (VALID_NEON_QREG_MODE (GET_MODE (op
))? 1016 : 1024))
12494 && (INTVAL (XEXP (ind
, 1)) & 3) == 0)
12500 /* Return TRUE if OP is a mem suitable for loading/storing a Neon struct
12503 neon_struct_mem_operand (rtx op
)
12507 /* Reject eliminable registers. */
12508 if (! (reload_in_progress
|| reload_completed
)
12509 && ( reg_mentioned_p (frame_pointer_rtx
, op
)
12510 || reg_mentioned_p (arg_pointer_rtx
, op
)
12511 || reg_mentioned_p (virtual_incoming_args_rtx
, op
)
12512 || reg_mentioned_p (virtual_outgoing_args_rtx
, op
)
12513 || reg_mentioned_p (virtual_stack_dynamic_rtx
, op
)
12514 || reg_mentioned_p (virtual_stack_vars_rtx
, op
)))
12517 /* Constants are converted into offsets from labels. */
12521 ind
= XEXP (op
, 0);
12523 if (reload_completed
12524 && (GET_CODE (ind
) == LABEL_REF
12525 || (GET_CODE (ind
) == CONST
12526 && GET_CODE (XEXP (ind
, 0)) == PLUS
12527 && GET_CODE (XEXP (XEXP (ind
, 0), 0)) == LABEL_REF
12528 && CONST_INT_P (XEXP (XEXP (ind
, 0), 1)))))
12531 /* Match: (mem (reg)). */
12533 return arm_address_register_rtx_p (ind
, 0);
12535 /* vldm/vstm allows POST_INC (ia) and PRE_DEC (db). */
12536 if (GET_CODE (ind
) == POST_INC
12537 || GET_CODE (ind
) == PRE_DEC
)
12538 return arm_address_register_rtx_p (XEXP (ind
, 0), 0);
12543 /* Return true if X is a register that will be eliminated later on. */
12545 arm_eliminable_register (rtx x
)
12547 return REG_P (x
) && (REGNO (x
) == FRAME_POINTER_REGNUM
12548 || REGNO (x
) == ARG_POINTER_REGNUM
12549 || (REGNO (x
) >= FIRST_VIRTUAL_REGISTER
12550 && REGNO (x
) <= LAST_VIRTUAL_REGISTER
));
12553 /* Return GENERAL_REGS if a scratch register required to reload x to/from
12554 coprocessor registers. Otherwise return NO_REGS. */
12557 coproc_secondary_reload_class (machine_mode mode
, rtx x
, bool wb
)
12559 if (mode
== HFmode
)
12561 if (!TARGET_NEON_FP16
&& !TARGET_VFP_FP16INST
)
12562 return GENERAL_REGS
;
12563 if (s_register_operand (x
, mode
) || neon_vector_mem_operand (x
, 2, true))
12565 return GENERAL_REGS
;
12568 /* The neon move patterns handle all legitimate vector and struct
12571 && (MEM_P (x
) || GET_CODE (x
) == CONST_VECTOR
)
12572 && (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
12573 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
12574 || VALID_NEON_STRUCT_MODE (mode
)))
12577 if (arm_coproc_mem_operand (x
, wb
) || s_register_operand (x
, mode
))
12580 return GENERAL_REGS
;
12583 /* Values which must be returned in the most-significant end of the return
12587 arm_return_in_msb (const_tree valtype
)
12589 return (TARGET_AAPCS_BASED
12590 && BYTES_BIG_ENDIAN
12591 && (AGGREGATE_TYPE_P (valtype
)
12592 || TREE_CODE (valtype
) == COMPLEX_TYPE
12593 || FIXED_POINT_TYPE_P (valtype
)));
12596 /* Return TRUE if X references a SYMBOL_REF. */
12598 symbol_mentioned_p (rtx x
)
12603 if (GET_CODE (x
) == SYMBOL_REF
)
12606 /* UNSPEC_TLS entries for a symbol include the SYMBOL_REF, but they
12607 are constant offsets, not symbols. */
12608 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLS
)
12611 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
12613 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
12619 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
12620 if (symbol_mentioned_p (XVECEXP (x
, i
, j
)))
12623 else if (fmt
[i
] == 'e' && symbol_mentioned_p (XEXP (x
, i
)))
12630 /* Return TRUE if X references a LABEL_REF. */
12632 label_mentioned_p (rtx x
)
12637 if (GET_CODE (x
) == LABEL_REF
)
12640 /* UNSPEC_TLS entries for a symbol include a LABEL_REF for the referencing
12641 instruction, but they are constant offsets, not symbols. */
12642 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLS
)
12645 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
12646 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
12652 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
12653 if (label_mentioned_p (XVECEXP (x
, i
, j
)))
12656 else if (fmt
[i
] == 'e' && label_mentioned_p (XEXP (x
, i
)))
12664 tls_mentioned_p (rtx x
)
12666 switch (GET_CODE (x
))
12669 return tls_mentioned_p (XEXP (x
, 0));
12672 if (XINT (x
, 1) == UNSPEC_TLS
)
12675 /* Fall through. */
12681 /* Must not copy any rtx that uses a pc-relative address.
12682 Also, disallow copying of load-exclusive instructions that
12683 may appear after splitting of compare-and-swap-style operations
12684 so as to prevent those loops from being transformed away from their
12685 canonical forms (see PR 69904). */
12688 arm_cannot_copy_insn_p (rtx_insn
*insn
)
12690 /* The tls call insn cannot be copied, as it is paired with a data
12692 if (recog_memoized (insn
) == CODE_FOR_tlscall
)
12695 subrtx_iterator::array_type array
;
12696 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), ALL
)
12698 const_rtx x
= *iter
;
12699 if (GET_CODE (x
) == UNSPEC
12700 && (XINT (x
, 1) == UNSPEC_PIC_BASE
12701 || XINT (x
, 1) == UNSPEC_PIC_UNIFIED
))
12705 rtx set
= single_set (insn
);
12708 rtx src
= SET_SRC (set
);
12709 if (GET_CODE (src
) == ZERO_EXTEND
)
12710 src
= XEXP (src
, 0);
12712 /* Catch the load-exclusive and load-acquire operations. */
12713 if (GET_CODE (src
) == UNSPEC_VOLATILE
12714 && (XINT (src
, 1) == VUNSPEC_LL
12715 || XINT (src
, 1) == VUNSPEC_LAX
))
12722 minmax_code (rtx x
)
12724 enum rtx_code code
= GET_CODE (x
);
12737 gcc_unreachable ();
12741 /* Match pair of min/max operators that can be implemented via usat/ssat. */
12744 arm_sat_operator_match (rtx lo_bound
, rtx hi_bound
,
12745 int *mask
, bool *signed_sat
)
12747 /* The high bound must be a power of two minus one. */
12748 int log
= exact_log2 (INTVAL (hi_bound
) + 1);
12752 /* The low bound is either zero (for usat) or one less than the
12753 negation of the high bound (for ssat). */
12754 if (INTVAL (lo_bound
) == 0)
12759 *signed_sat
= false;
12764 if (INTVAL (lo_bound
) == -INTVAL (hi_bound
) - 1)
12769 *signed_sat
= true;
12777 /* Return 1 if memory locations are adjacent. */
12779 adjacent_mem_locations (rtx a
, rtx b
)
12781 /* We don't guarantee to preserve the order of these memory refs. */
12782 if (volatile_refs_p (a
) || volatile_refs_p (b
))
12785 if ((REG_P (XEXP (a
, 0))
12786 || (GET_CODE (XEXP (a
, 0)) == PLUS
12787 && CONST_INT_P (XEXP (XEXP (a
, 0), 1))))
12788 && (REG_P (XEXP (b
, 0))
12789 || (GET_CODE (XEXP (b
, 0)) == PLUS
12790 && CONST_INT_P (XEXP (XEXP (b
, 0), 1)))))
12792 HOST_WIDE_INT val0
= 0, val1
= 0;
12796 if (GET_CODE (XEXP (a
, 0)) == PLUS
)
12798 reg0
= XEXP (XEXP (a
, 0), 0);
12799 val0
= INTVAL (XEXP (XEXP (a
, 0), 1));
12802 reg0
= XEXP (a
, 0);
12804 if (GET_CODE (XEXP (b
, 0)) == PLUS
)
12806 reg1
= XEXP (XEXP (b
, 0), 0);
12807 val1
= INTVAL (XEXP (XEXP (b
, 0), 1));
12810 reg1
= XEXP (b
, 0);
12812 /* Don't accept any offset that will require multiple
12813 instructions to handle, since this would cause the
12814 arith_adjacentmem pattern to output an overlong sequence. */
12815 if (!const_ok_for_op (val0
, PLUS
) || !const_ok_for_op (val1
, PLUS
))
12818 /* Don't allow an eliminable register: register elimination can make
12819 the offset too large. */
12820 if (arm_eliminable_register (reg0
))
12823 val_diff
= val1
- val0
;
12827 /* If the target has load delay slots, then there's no benefit
12828 to using an ldm instruction unless the offset is zero and
12829 we are optimizing for size. */
12830 return (optimize_size
&& (REGNO (reg0
) == REGNO (reg1
))
12831 && (val0
== 0 || val1
== 0 || val0
== 4 || val1
== 4)
12832 && (val_diff
== 4 || val_diff
== -4));
12835 return ((REGNO (reg0
) == REGNO (reg1
))
12836 && (val_diff
== 4 || val_diff
== -4));
12842 /* Return true if OP is a valid load or store multiple operation. LOAD is true
12843 for load operations, false for store operations. CONSECUTIVE is true
12844 if the register numbers in the operation must be consecutive in the register
12845 bank. RETURN_PC is true if value is to be loaded in PC.
12846 The pattern we are trying to match for load is:
12847 [(SET (R_d0) (MEM (PLUS (addr) (offset))))
12848 (SET (R_d1) (MEM (PLUS (addr) (offset + <reg_increment>))))
12851 (SET (R_dn) (MEM (PLUS (addr) (offset + n * <reg_increment>))))
12854 1. If offset is 0, first insn should be (SET (R_d0) (MEM (src_addr))).
12855 2. REGNO (R_d0) < REGNO (R_d1) < ... < REGNO (R_dn).
12856 3. If consecutive is TRUE, then for kth register being loaded,
12857 REGNO (R_dk) = REGNO (R_d0) + k.
12858 The pattern for store is similar. */
12860 ldm_stm_operation_p (rtx op
, bool load
, machine_mode mode
,
12861 bool consecutive
, bool return_pc
)
12863 HOST_WIDE_INT count
= XVECLEN (op
, 0);
12864 rtx reg
, mem
, addr
;
12866 unsigned first_regno
;
12867 HOST_WIDE_INT i
= 1, base
= 0, offset
= 0;
12869 bool addr_reg_in_reglist
= false;
12870 bool update
= false;
12875 /* If not in SImode, then registers must be consecutive
12876 (e.g., VLDM instructions for DFmode). */
12877 gcc_assert ((mode
== SImode
) || consecutive
);
12878 /* Setting return_pc for stores is illegal. */
12879 gcc_assert (!return_pc
|| load
);
12881 /* Set up the increments and the regs per val based on the mode. */
12882 reg_increment
= GET_MODE_SIZE (mode
);
12883 regs_per_val
= reg_increment
/ 4;
12884 offset_adj
= return_pc
? 1 : 0;
12887 || GET_CODE (XVECEXP (op
, 0, offset_adj
)) != SET
12888 || (load
&& !REG_P (SET_DEST (XVECEXP (op
, 0, offset_adj
)))))
12891 /* Check if this is a write-back. */
12892 elt
= XVECEXP (op
, 0, offset_adj
);
12893 if (GET_CODE (SET_SRC (elt
)) == PLUS
)
12899 /* The offset adjustment must be the number of registers being
12900 popped times the size of a single register. */
12901 if (!REG_P (SET_DEST (elt
))
12902 || !REG_P (XEXP (SET_SRC (elt
), 0))
12903 || (REGNO (SET_DEST (elt
)) != REGNO (XEXP (SET_SRC (elt
), 0)))
12904 || !CONST_INT_P (XEXP (SET_SRC (elt
), 1))
12905 || INTVAL (XEXP (SET_SRC (elt
), 1)) !=
12906 ((count
- 1 - offset_adj
) * reg_increment
))
12910 i
= i
+ offset_adj
;
12911 base
= base
+ offset_adj
;
12912 /* Perform a quick check so we don't blow up below. If only one reg is loaded,
12913 success depends on the type: VLDM can do just one reg,
12914 LDM must do at least two. */
12915 if ((count
<= i
) && (mode
== SImode
))
12918 elt
= XVECEXP (op
, 0, i
- 1);
12919 if (GET_CODE (elt
) != SET
)
12924 reg
= SET_DEST (elt
);
12925 mem
= SET_SRC (elt
);
12929 reg
= SET_SRC (elt
);
12930 mem
= SET_DEST (elt
);
12933 if (!REG_P (reg
) || !MEM_P (mem
))
12936 regno
= REGNO (reg
);
12937 first_regno
= regno
;
12938 addr
= XEXP (mem
, 0);
12939 if (GET_CODE (addr
) == PLUS
)
12941 if (!CONST_INT_P (XEXP (addr
, 1)))
12944 offset
= INTVAL (XEXP (addr
, 1));
12945 addr
= XEXP (addr
, 0);
12951 /* Don't allow SP to be loaded unless it is also the base register. It
12952 guarantees that SP is reset correctly when an LDM instruction
12953 is interrupted. Otherwise, we might end up with a corrupt stack. */
12954 if (load
&& (REGNO (reg
) == SP_REGNUM
) && (REGNO (addr
) != SP_REGNUM
))
12957 for (; i
< count
; i
++)
12959 elt
= XVECEXP (op
, 0, i
);
12960 if (GET_CODE (elt
) != SET
)
12965 reg
= SET_DEST (elt
);
12966 mem
= SET_SRC (elt
);
12970 reg
= SET_SRC (elt
);
12971 mem
= SET_DEST (elt
);
12975 || GET_MODE (reg
) != mode
12976 || REGNO (reg
) <= regno
12979 (unsigned int) (first_regno
+ regs_per_val
* (i
- base
))))
12980 /* Don't allow SP to be loaded unless it is also the base register. It
12981 guarantees that SP is reset correctly when an LDM instruction
12982 is interrupted. Otherwise, we might end up with a corrupt stack. */
12983 || (load
&& (REGNO (reg
) == SP_REGNUM
) && (REGNO (addr
) != SP_REGNUM
))
12985 || GET_MODE (mem
) != mode
12986 || ((GET_CODE (XEXP (mem
, 0)) != PLUS
12987 || !rtx_equal_p (XEXP (XEXP (mem
, 0), 0), addr
)
12988 || !CONST_INT_P (XEXP (XEXP (mem
, 0), 1))
12989 || (INTVAL (XEXP (XEXP (mem
, 0), 1)) !=
12990 offset
+ (i
- base
) * reg_increment
))
12991 && (!REG_P (XEXP (mem
, 0))
12992 || offset
+ (i
- base
) * reg_increment
!= 0)))
12995 regno
= REGNO (reg
);
12996 if (regno
== REGNO (addr
))
12997 addr_reg_in_reglist
= true;
13002 if (update
&& addr_reg_in_reglist
)
13005 /* For Thumb-1, address register is always modified - either by write-back
13006 or by explicit load. If the pattern does not describe an update,
13007 then the address register must be in the list of loaded registers. */
13009 return update
|| addr_reg_in_reglist
;
13015 /* Return true iff it would be profitable to turn a sequence of NOPS loads
13016 or stores (depending on IS_STORE) into a load-multiple or store-multiple
13017 instruction. ADD_OFFSET is nonzero if the base address register needs
13018 to be modified with an add instruction before we can use it. */
13021 multiple_operation_profitable_p (bool is_store ATTRIBUTE_UNUSED
,
13022 int nops
, HOST_WIDE_INT add_offset
)
13024 /* For ARM8,9 & StrongARM, 2 ldr instructions are faster than an ldm
13025 if the offset isn't small enough. The reason 2 ldrs are faster
13026 is because these ARMs are able to do more than one cache access
13027 in a single cycle. The ARM9 and StrongARM have Harvard caches,
13028 whilst the ARM8 has a double bandwidth cache. This means that
13029 these cores can do both an instruction fetch and a data fetch in
13030 a single cycle, so the trick of calculating the address into a
13031 scratch register (one of the result regs) and then doing a load
13032 multiple actually becomes slower (and no smaller in code size).
13033 That is the transformation
13035 ldr rd1, [rbase + offset]
13036 ldr rd2, [rbase + offset + 4]
13040 add rd1, rbase, offset
13041 ldmia rd1, {rd1, rd2}
13043 produces worse code -- '3 cycles + any stalls on rd2' instead of
13044 '2 cycles + any stalls on rd2'. On ARMs with only one cache
13045 access per cycle, the first sequence could never complete in less
13046 than 6 cycles, whereas the ldm sequence would only take 5 and
13047 would make better use of sequential accesses if not hitting the
13050 We cheat here and test 'arm_ld_sched' which we currently know to
13051 only be true for the ARM8, ARM9 and StrongARM. If this ever
13052 changes, then the test below needs to be reworked. */
13053 if (nops
== 2 && arm_ld_sched
&& add_offset
!= 0)
13056 /* XScale has load-store double instructions, but they have stricter
13057 alignment requirements than load-store multiple, so we cannot
13060 For XScale ldm requires 2 + NREGS cycles to complete and blocks
13061 the pipeline until completion.
13069 An ldr instruction takes 1-3 cycles, but does not block the
13078 Best case ldr will always win. However, the more ldr instructions
13079 we issue, the less likely we are to be able to schedule them well.
13080 Using ldr instructions also increases code size.
13082 As a compromise, we use ldr for counts of 1 or 2 regs, and ldm
13083 for counts of 3 or 4 regs. */
13084 if (nops
<= 2 && arm_tune_xscale
&& !optimize_size
)
13089 /* Subroutine of load_multiple_sequence and store_multiple_sequence.
13090 Given an array of UNSORTED_OFFSETS, of which there are NOPS, compute
13091 an array ORDER which describes the sequence to use when accessing the
13092 offsets that produces an ascending order. In this sequence, each
13093 offset must be larger by exactly 4 than the previous one. ORDER[0]
13094 must have been filled in with the lowest offset by the caller.
13095 If UNSORTED_REGS is nonnull, it is an array of register numbers that
13096 we use to verify that ORDER produces an ascending order of registers.
13097 Return true if it was possible to construct such an order, false if
13101 compute_offset_order (int nops
, HOST_WIDE_INT
*unsorted_offsets
, int *order
,
13102 int *unsorted_regs
)
13105 for (i
= 1; i
< nops
; i
++)
13109 order
[i
] = order
[i
- 1];
13110 for (j
= 0; j
< nops
; j
++)
13111 if (unsorted_offsets
[j
] == unsorted_offsets
[order
[i
- 1]] + 4)
13113 /* We must find exactly one offset that is higher than the
13114 previous one by 4. */
13115 if (order
[i
] != order
[i
- 1])
13119 if (order
[i
] == order
[i
- 1])
13121 /* The register numbers must be ascending. */
13122 if (unsorted_regs
!= NULL
13123 && unsorted_regs
[order
[i
]] <= unsorted_regs
[order
[i
- 1]])
13129 /* Used to determine in a peephole whether a sequence of load
13130 instructions can be changed into a load-multiple instruction.
13131 NOPS is the number of separate load instructions we are examining. The
13132 first NOPS entries in OPERANDS are the destination registers, the
13133 next NOPS entries are memory operands. If this function is
13134 successful, *BASE is set to the common base register of the memory
13135 accesses; *LOAD_OFFSET is set to the first memory location's offset
13136 from that base register.
13137 REGS is an array filled in with the destination register numbers.
13138 SAVED_ORDER (if nonnull), is an array filled in with an order that maps
13139 insn numbers to an ascending order of stores. If CHECK_REGS is true,
13140 the sequence of registers in REGS matches the loads from ascending memory
13141 locations, and the function verifies that the register numbers are
13142 themselves ascending. If CHECK_REGS is false, the register numbers
13143 are stored in the order they are found in the operands. */
13145 load_multiple_sequence (rtx
*operands
, int nops
, int *regs
, int *saved_order
,
13146 int *base
, HOST_WIDE_INT
*load_offset
, bool check_regs
)
13148 int unsorted_regs
[MAX_LDM_STM_OPS
];
13149 HOST_WIDE_INT unsorted_offsets
[MAX_LDM_STM_OPS
];
13150 int order
[MAX_LDM_STM_OPS
];
13151 rtx base_reg_rtx
= NULL
;
13155 /* Can only handle up to MAX_LDM_STM_OPS insns at present, though could be
13156 easily extended if required. */
13157 gcc_assert (nops
>= 2 && nops
<= MAX_LDM_STM_OPS
);
13159 memset (order
, 0, MAX_LDM_STM_OPS
* sizeof (int));
13161 /* Loop over the operands and check that the memory references are
13162 suitable (i.e. immediate offsets from the same base register). At
13163 the same time, extract the target register, and the memory
13165 for (i
= 0; i
< nops
; i
++)
13170 /* Convert a subreg of a mem into the mem itself. */
13171 if (GET_CODE (operands
[nops
+ i
]) == SUBREG
)
13172 operands
[nops
+ i
] = alter_subreg (operands
+ (nops
+ i
), true);
13174 gcc_assert (MEM_P (operands
[nops
+ i
]));
13176 /* Don't reorder volatile memory references; it doesn't seem worth
13177 looking for the case where the order is ok anyway. */
13178 if (MEM_VOLATILE_P (operands
[nops
+ i
]))
13181 offset
= const0_rtx
;
13183 if ((REG_P (reg
= XEXP (operands
[nops
+ i
], 0))
13184 || (GET_CODE (reg
) == SUBREG
13185 && REG_P (reg
= SUBREG_REG (reg
))))
13186 || (GET_CODE (XEXP (operands
[nops
+ i
], 0)) == PLUS
13187 && ((REG_P (reg
= XEXP (XEXP (operands
[nops
+ i
], 0), 0)))
13188 || (GET_CODE (reg
) == SUBREG
13189 && REG_P (reg
= SUBREG_REG (reg
))))
13190 && (CONST_INT_P (offset
13191 = XEXP (XEXP (operands
[nops
+ i
], 0), 1)))))
13195 base_reg
= REGNO (reg
);
13196 base_reg_rtx
= reg
;
13197 if (TARGET_THUMB1
&& base_reg
> LAST_LO_REGNUM
)
13200 else if (base_reg
!= (int) REGNO (reg
))
13201 /* Not addressed from the same base register. */
13204 unsorted_regs
[i
] = (REG_P (operands
[i
])
13205 ? REGNO (operands
[i
])
13206 : REGNO (SUBREG_REG (operands
[i
])));
13208 /* If it isn't an integer register, or if it overwrites the
13209 base register but isn't the last insn in the list, then
13210 we can't do this. */
13211 if (unsorted_regs
[i
] < 0
13212 || (TARGET_THUMB1
&& unsorted_regs
[i
] > LAST_LO_REGNUM
)
13213 || unsorted_regs
[i
] > 14
13214 || (i
!= nops
- 1 && unsorted_regs
[i
] == base_reg
))
13217 /* Don't allow SP to be loaded unless it is also the base
13218 register. It guarantees that SP is reset correctly when
13219 an LDM instruction is interrupted. Otherwise, we might
13220 end up with a corrupt stack. */
13221 if (unsorted_regs
[i
] == SP_REGNUM
&& base_reg
!= SP_REGNUM
)
13224 unsorted_offsets
[i
] = INTVAL (offset
);
13225 if (i
== 0 || unsorted_offsets
[i
] < unsorted_offsets
[order
[0]])
13229 /* Not a suitable memory address. */
13233 /* All the useful information has now been extracted from the
13234 operands into unsorted_regs and unsorted_offsets; additionally,
13235 order[0] has been set to the lowest offset in the list. Sort
13236 the offsets into order, verifying that they are adjacent, and
13237 check that the register numbers are ascending. */
13238 if (!compute_offset_order (nops
, unsorted_offsets
, order
,
13239 check_regs
? unsorted_regs
: NULL
))
13243 memcpy (saved_order
, order
, sizeof order
);
13249 for (i
= 0; i
< nops
; i
++)
13250 regs
[i
] = unsorted_regs
[check_regs
? order
[i
] : i
];
13252 *load_offset
= unsorted_offsets
[order
[0]];
13256 && !peep2_reg_dead_p (nops
, base_reg_rtx
))
13259 if (unsorted_offsets
[order
[0]] == 0)
13260 ldm_case
= 1; /* ldmia */
13261 else if (TARGET_ARM
&& unsorted_offsets
[order
[0]] == 4)
13262 ldm_case
= 2; /* ldmib */
13263 else if (TARGET_ARM
&& unsorted_offsets
[order
[nops
- 1]] == 0)
13264 ldm_case
= 3; /* ldmda */
13265 else if (TARGET_32BIT
&& unsorted_offsets
[order
[nops
- 1]] == -4)
13266 ldm_case
= 4; /* ldmdb */
13267 else if (const_ok_for_arm (unsorted_offsets
[order
[0]])
13268 || const_ok_for_arm (-unsorted_offsets
[order
[0]]))
13273 if (!multiple_operation_profitable_p (false, nops
,
13275 ? unsorted_offsets
[order
[0]] : 0))
13281 /* Used to determine in a peephole whether a sequence of store instructions can
13282 be changed into a store-multiple instruction.
13283 NOPS is the number of separate store instructions we are examining.
13284 NOPS_TOTAL is the total number of instructions recognized by the peephole
13286 The first NOPS entries in OPERANDS are the source registers, the next
13287 NOPS entries are memory operands. If this function is successful, *BASE is
13288 set to the common base register of the memory accesses; *LOAD_OFFSET is set
13289 to the first memory location's offset from that base register. REGS is an
13290 array filled in with the source register numbers, REG_RTXS (if nonnull) is
13291 likewise filled with the corresponding rtx's.
13292 SAVED_ORDER (if nonnull), is an array filled in with an order that maps insn
13293 numbers to an ascending order of stores.
13294 If CHECK_REGS is true, the sequence of registers in *REGS matches the stores
13295 from ascending memory locations, and the function verifies that the register
13296 numbers are themselves ascending. If CHECK_REGS is false, the register
13297 numbers are stored in the order they are found in the operands. */
13299 store_multiple_sequence (rtx
*operands
, int nops
, int nops_total
,
13300 int *regs
, rtx
*reg_rtxs
, int *saved_order
, int *base
,
13301 HOST_WIDE_INT
*load_offset
, bool check_regs
)
13303 int unsorted_regs
[MAX_LDM_STM_OPS
];
13304 rtx unsorted_reg_rtxs
[MAX_LDM_STM_OPS
];
13305 HOST_WIDE_INT unsorted_offsets
[MAX_LDM_STM_OPS
];
13306 int order
[MAX_LDM_STM_OPS
];
13308 rtx base_reg_rtx
= NULL
;
13311 /* Write back of base register is currently only supported for Thumb 1. */
13312 int base_writeback
= TARGET_THUMB1
;
13314 /* Can only handle up to MAX_LDM_STM_OPS insns at present, though could be
13315 easily extended if required. */
13316 gcc_assert (nops
>= 2 && nops
<= MAX_LDM_STM_OPS
);
13318 memset (order
, 0, MAX_LDM_STM_OPS
* sizeof (int));
13320 /* Loop over the operands and check that the memory references are
13321 suitable (i.e. immediate offsets from the same base register). At
13322 the same time, extract the target register, and the memory
13324 for (i
= 0; i
< nops
; i
++)
13329 /* Convert a subreg of a mem into the mem itself. */
13330 if (GET_CODE (operands
[nops
+ i
]) == SUBREG
)
13331 operands
[nops
+ i
] = alter_subreg (operands
+ (nops
+ i
), true);
13333 gcc_assert (MEM_P (operands
[nops
+ i
]));
13335 /* Don't reorder volatile memory references; it doesn't seem worth
13336 looking for the case where the order is ok anyway. */
13337 if (MEM_VOLATILE_P (operands
[nops
+ i
]))
13340 offset
= const0_rtx
;
13342 if ((REG_P (reg
= XEXP (operands
[nops
+ i
], 0))
13343 || (GET_CODE (reg
) == SUBREG
13344 && REG_P (reg
= SUBREG_REG (reg
))))
13345 || (GET_CODE (XEXP (operands
[nops
+ i
], 0)) == PLUS
13346 && ((REG_P (reg
= XEXP (XEXP (operands
[nops
+ i
], 0), 0)))
13347 || (GET_CODE (reg
) == SUBREG
13348 && REG_P (reg
= SUBREG_REG (reg
))))
13349 && (CONST_INT_P (offset
13350 = XEXP (XEXP (operands
[nops
+ i
], 0), 1)))))
13352 unsorted_reg_rtxs
[i
] = (REG_P (operands
[i
])
13353 ? operands
[i
] : SUBREG_REG (operands
[i
]));
13354 unsorted_regs
[i
] = REGNO (unsorted_reg_rtxs
[i
]);
13358 base_reg
= REGNO (reg
);
13359 base_reg_rtx
= reg
;
13360 if (TARGET_THUMB1
&& base_reg
> LAST_LO_REGNUM
)
13363 else if (base_reg
!= (int) REGNO (reg
))
13364 /* Not addressed from the same base register. */
13367 /* If it isn't an integer register, then we can't do this. */
13368 if (unsorted_regs
[i
] < 0
13369 || (TARGET_THUMB1
&& unsorted_regs
[i
] > LAST_LO_REGNUM
)
13370 /* The effects are unpredictable if the base register is
13371 both updated and stored. */
13372 || (base_writeback
&& unsorted_regs
[i
] == base_reg
)
13373 || (TARGET_THUMB2
&& unsorted_regs
[i
] == SP_REGNUM
)
13374 || unsorted_regs
[i
] > 14)
13377 unsorted_offsets
[i
] = INTVAL (offset
);
13378 if (i
== 0 || unsorted_offsets
[i
] < unsorted_offsets
[order
[0]])
13382 /* Not a suitable memory address. */
13386 /* All the useful information has now been extracted from the
13387 operands into unsorted_regs and unsorted_offsets; additionally,
13388 order[0] has been set to the lowest offset in the list. Sort
13389 the offsets into order, verifying that they are adjacent, and
13390 check that the register numbers are ascending. */
13391 if (!compute_offset_order (nops
, unsorted_offsets
, order
,
13392 check_regs
? unsorted_regs
: NULL
))
13396 memcpy (saved_order
, order
, sizeof order
);
13402 for (i
= 0; i
< nops
; i
++)
13404 regs
[i
] = unsorted_regs
[check_regs
? order
[i
] : i
];
13406 reg_rtxs
[i
] = unsorted_reg_rtxs
[check_regs
? order
[i
] : i
];
13409 *load_offset
= unsorted_offsets
[order
[0]];
13413 && !peep2_reg_dead_p (nops_total
, base_reg_rtx
))
13416 if (unsorted_offsets
[order
[0]] == 0)
13417 stm_case
= 1; /* stmia */
13418 else if (TARGET_ARM
&& unsorted_offsets
[order
[0]] == 4)
13419 stm_case
= 2; /* stmib */
13420 else if (TARGET_ARM
&& unsorted_offsets
[order
[nops
- 1]] == 0)
13421 stm_case
= 3; /* stmda */
13422 else if (TARGET_32BIT
&& unsorted_offsets
[order
[nops
- 1]] == -4)
13423 stm_case
= 4; /* stmdb */
13427 if (!multiple_operation_profitable_p (false, nops
, 0))
13433 /* Routines for use in generating RTL. */
13435 /* Generate a load-multiple instruction. COUNT is the number of loads in
13436 the instruction; REGS and MEMS are arrays containing the operands.
13437 BASEREG is the base register to be used in addressing the memory operands.
13438 WBACK_OFFSET is nonzero if the instruction should update the base
13442 arm_gen_load_multiple_1 (int count
, int *regs
, rtx
*mems
, rtx basereg
,
13443 HOST_WIDE_INT wback_offset
)
13448 if (!multiple_operation_profitable_p (false, count
, 0))
13454 for (i
= 0; i
< count
; i
++)
13455 emit_move_insn (gen_rtx_REG (SImode
, regs
[i
]), mems
[i
]);
13457 if (wback_offset
!= 0)
13458 emit_move_insn (basereg
, plus_constant (Pmode
, basereg
, wback_offset
));
13460 seq
= get_insns ();
13466 result
= gen_rtx_PARALLEL (VOIDmode
,
13467 rtvec_alloc (count
+ (wback_offset
!= 0 ? 1 : 0)));
13468 if (wback_offset
!= 0)
13470 XVECEXP (result
, 0, 0)
13471 = gen_rtx_SET (basereg
, plus_constant (Pmode
, basereg
, wback_offset
));
13476 for (j
= 0; i
< count
; i
++, j
++)
13477 XVECEXP (result
, 0, i
)
13478 = gen_rtx_SET (gen_rtx_REG (SImode
, regs
[j
]), mems
[j
]);
13483 /* Generate a store-multiple instruction. COUNT is the number of stores in
13484 the instruction; REGS and MEMS are arrays containing the operands.
13485 BASEREG is the base register to be used in addressing the memory operands.
13486 WBACK_OFFSET is nonzero if the instruction should update the base
13490 arm_gen_store_multiple_1 (int count
, int *regs
, rtx
*mems
, rtx basereg
,
13491 HOST_WIDE_INT wback_offset
)
13496 if (GET_CODE (basereg
) == PLUS
)
13497 basereg
= XEXP (basereg
, 0);
13499 if (!multiple_operation_profitable_p (false, count
, 0))
13505 for (i
= 0; i
< count
; i
++)
13506 emit_move_insn (mems
[i
], gen_rtx_REG (SImode
, regs
[i
]));
13508 if (wback_offset
!= 0)
13509 emit_move_insn (basereg
, plus_constant (Pmode
, basereg
, wback_offset
));
13511 seq
= get_insns ();
13517 result
= gen_rtx_PARALLEL (VOIDmode
,
13518 rtvec_alloc (count
+ (wback_offset
!= 0 ? 1 : 0)));
13519 if (wback_offset
!= 0)
13521 XVECEXP (result
, 0, 0)
13522 = gen_rtx_SET (basereg
, plus_constant (Pmode
, basereg
, wback_offset
));
13527 for (j
= 0; i
< count
; i
++, j
++)
13528 XVECEXP (result
, 0, i
)
13529 = gen_rtx_SET (mems
[j
], gen_rtx_REG (SImode
, regs
[j
]));
13534 /* Generate either a load-multiple or a store-multiple instruction. This
13535 function can be used in situations where we can start with a single MEM
13536 rtx and adjust its address upwards.
13537 COUNT is the number of operations in the instruction, not counting a
13538 possible update of the base register. REGS is an array containing the
13540 BASEREG is the base register to be used in addressing the memory operands,
13541 which are constructed from BASEMEM.
13542 WRITE_BACK specifies whether the generated instruction should include an
13543 update of the base register.
13544 OFFSETP is used to pass an offset to and from this function; this offset
13545 is not used when constructing the address (instead BASEMEM should have an
13546 appropriate offset in its address), it is used only for setting
13547 MEM_OFFSET. It is updated only if WRITE_BACK is true.*/
13550 arm_gen_multiple_op (bool is_load
, int *regs
, int count
, rtx basereg
,
13551 bool write_back
, rtx basemem
, HOST_WIDE_INT
*offsetp
)
13553 rtx mems
[MAX_LDM_STM_OPS
];
13554 HOST_WIDE_INT offset
= *offsetp
;
13557 gcc_assert (count
<= MAX_LDM_STM_OPS
);
13559 if (GET_CODE (basereg
) == PLUS
)
13560 basereg
= XEXP (basereg
, 0);
13562 for (i
= 0; i
< count
; i
++)
13564 rtx addr
= plus_constant (Pmode
, basereg
, i
* 4);
13565 mems
[i
] = adjust_automodify_address_nv (basemem
, SImode
, addr
, offset
);
13573 return arm_gen_load_multiple_1 (count
, regs
, mems
, basereg
,
13574 write_back
? 4 * count
: 0);
13576 return arm_gen_store_multiple_1 (count
, regs
, mems
, basereg
,
13577 write_back
? 4 * count
: 0);
13581 arm_gen_load_multiple (int *regs
, int count
, rtx basereg
, int write_back
,
13582 rtx basemem
, HOST_WIDE_INT
*offsetp
)
13584 return arm_gen_multiple_op (TRUE
, regs
, count
, basereg
, write_back
, basemem
,
13589 arm_gen_store_multiple (int *regs
, int count
, rtx basereg
, int write_back
,
13590 rtx basemem
, HOST_WIDE_INT
*offsetp
)
13592 return arm_gen_multiple_op (FALSE
, regs
, count
, basereg
, write_back
, basemem
,
13596 /* Called from a peephole2 expander to turn a sequence of loads into an
13597 LDM instruction. OPERANDS are the operands found by the peephole matcher;
13598 NOPS indicates how many separate loads we are trying to combine. SORT_REGS
13599 is true if we can reorder the registers because they are used commutatively
13601 Returns true iff we could generate a new instruction. */
13604 gen_ldm_seq (rtx
*operands
, int nops
, bool sort_regs
)
13606 int regs
[MAX_LDM_STM_OPS
], mem_order
[MAX_LDM_STM_OPS
];
13607 rtx mems
[MAX_LDM_STM_OPS
];
13608 int i
, j
, base_reg
;
13610 HOST_WIDE_INT offset
;
13611 int write_back
= FALSE
;
13615 ldm_case
= load_multiple_sequence (operands
, nops
, regs
, mem_order
,
13616 &base_reg
, &offset
, !sort_regs
);
13622 for (i
= 0; i
< nops
- 1; i
++)
13623 for (j
= i
+ 1; j
< nops
; j
++)
13624 if (regs
[i
] > regs
[j
])
13630 base_reg_rtx
= gen_rtx_REG (Pmode
, base_reg
);
13634 gcc_assert (peep2_reg_dead_p (nops
, base_reg_rtx
));
13635 gcc_assert (ldm_case
== 1 || ldm_case
== 5);
13641 rtx newbase
= TARGET_THUMB1
? base_reg_rtx
: gen_rtx_REG (SImode
, regs
[0]);
13642 emit_insn (gen_addsi3 (newbase
, base_reg_rtx
, GEN_INT (offset
)));
13644 if (!TARGET_THUMB1
)
13645 base_reg_rtx
= newbase
;
13648 for (i
= 0; i
< nops
; i
++)
13650 addr
= plus_constant (Pmode
, base_reg_rtx
, offset
+ i
* 4);
13651 mems
[i
] = adjust_automodify_address_nv (operands
[nops
+ mem_order
[i
]],
13654 emit_insn (arm_gen_load_multiple_1 (nops
, regs
, mems
, base_reg_rtx
,
13655 write_back
? offset
+ i
* 4 : 0));
13659 /* Called from a peephole2 expander to turn a sequence of stores into an
13660 STM instruction. OPERANDS are the operands found by the peephole matcher;
13661 NOPS indicates how many separate stores we are trying to combine.
13662 Returns true iff we could generate a new instruction. */
13665 gen_stm_seq (rtx
*operands
, int nops
)
13668 int regs
[MAX_LDM_STM_OPS
], mem_order
[MAX_LDM_STM_OPS
];
13669 rtx mems
[MAX_LDM_STM_OPS
];
13672 HOST_WIDE_INT offset
;
13673 int write_back
= FALSE
;
13676 bool base_reg_dies
;
13678 stm_case
= store_multiple_sequence (operands
, nops
, nops
, regs
, NULL
,
13679 mem_order
, &base_reg
, &offset
, true);
13684 base_reg_rtx
= gen_rtx_REG (Pmode
, base_reg
);
13686 base_reg_dies
= peep2_reg_dead_p (nops
, base_reg_rtx
);
13689 gcc_assert (base_reg_dies
);
13695 gcc_assert (base_reg_dies
);
13696 emit_insn (gen_addsi3 (base_reg_rtx
, base_reg_rtx
, GEN_INT (offset
)));
13700 addr
= plus_constant (Pmode
, base_reg_rtx
, offset
);
13702 for (i
= 0; i
< nops
; i
++)
13704 addr
= plus_constant (Pmode
, base_reg_rtx
, offset
+ i
* 4);
13705 mems
[i
] = adjust_automodify_address_nv (operands
[nops
+ mem_order
[i
]],
13708 emit_insn (arm_gen_store_multiple_1 (nops
, regs
, mems
, base_reg_rtx
,
13709 write_back
? offset
+ i
* 4 : 0));
13713 /* Called from a peephole2 expander to turn a sequence of stores that are
13714 preceded by constant loads into an STM instruction. OPERANDS are the
13715 operands found by the peephole matcher; NOPS indicates how many
13716 separate stores we are trying to combine; there are 2 * NOPS
13717 instructions in the peephole.
13718 Returns true iff we could generate a new instruction. */
13721 gen_const_stm_seq (rtx
*operands
, int nops
)
13723 int regs
[MAX_LDM_STM_OPS
], sorted_regs
[MAX_LDM_STM_OPS
];
13724 int reg_order
[MAX_LDM_STM_OPS
], mem_order
[MAX_LDM_STM_OPS
];
13725 rtx reg_rtxs
[MAX_LDM_STM_OPS
], orig_reg_rtxs
[MAX_LDM_STM_OPS
];
13726 rtx mems
[MAX_LDM_STM_OPS
];
13729 HOST_WIDE_INT offset
;
13730 int write_back
= FALSE
;
13733 bool base_reg_dies
;
13735 HARD_REG_SET allocated
;
13737 stm_case
= store_multiple_sequence (operands
, nops
, 2 * nops
, regs
, reg_rtxs
,
13738 mem_order
, &base_reg
, &offset
, false);
13743 memcpy (orig_reg_rtxs
, reg_rtxs
, sizeof orig_reg_rtxs
);
13745 /* If the same register is used more than once, try to find a free
13747 CLEAR_HARD_REG_SET (allocated
);
13748 for (i
= 0; i
< nops
; i
++)
13750 for (j
= i
+ 1; j
< nops
; j
++)
13751 if (regs
[i
] == regs
[j
])
13753 rtx t
= peep2_find_free_register (0, nops
* 2,
13754 TARGET_THUMB1
? "l" : "r",
13755 SImode
, &allocated
);
13759 regs
[i
] = REGNO (t
);
13763 /* Compute an ordering that maps the register numbers to an ascending
13766 for (i
= 0; i
< nops
; i
++)
13767 if (regs
[i
] < regs
[reg_order
[0]])
13770 for (i
= 1; i
< nops
; i
++)
13772 int this_order
= reg_order
[i
- 1];
13773 for (j
= 0; j
< nops
; j
++)
13774 if (regs
[j
] > regs
[reg_order
[i
- 1]]
13775 && (this_order
== reg_order
[i
- 1]
13776 || regs
[j
] < regs
[this_order
]))
13778 reg_order
[i
] = this_order
;
13781 /* Ensure that registers that must be live after the instruction end
13782 up with the correct value. */
13783 for (i
= 0; i
< nops
; i
++)
13785 int this_order
= reg_order
[i
];
13786 if ((this_order
!= mem_order
[i
]
13787 || orig_reg_rtxs
[this_order
] != reg_rtxs
[this_order
])
13788 && !peep2_reg_dead_p (nops
* 2, orig_reg_rtxs
[this_order
]))
13792 /* Load the constants. */
13793 for (i
= 0; i
< nops
; i
++)
13795 rtx op
= operands
[2 * nops
+ mem_order
[i
]];
13796 sorted_regs
[i
] = regs
[reg_order
[i
]];
13797 emit_move_insn (reg_rtxs
[reg_order
[i
]], op
);
13800 base_reg_rtx
= gen_rtx_REG (Pmode
, base_reg
);
13802 base_reg_dies
= peep2_reg_dead_p (nops
* 2, base_reg_rtx
);
13805 gcc_assert (base_reg_dies
);
13811 gcc_assert (base_reg_dies
);
13812 emit_insn (gen_addsi3 (base_reg_rtx
, base_reg_rtx
, GEN_INT (offset
)));
13816 addr
= plus_constant (Pmode
, base_reg_rtx
, offset
);
13818 for (i
= 0; i
< nops
; i
++)
13820 addr
= plus_constant (Pmode
, base_reg_rtx
, offset
+ i
* 4);
13821 mems
[i
] = adjust_automodify_address_nv (operands
[nops
+ mem_order
[i
]],
13824 emit_insn (arm_gen_store_multiple_1 (nops
, sorted_regs
, mems
, base_reg_rtx
,
13825 write_back
? offset
+ i
* 4 : 0));
13829 /* Copy a block of memory using plain ldr/str/ldrh/strh instructions, to permit
13830 unaligned copies on processors which support unaligned semantics for those
13831 instructions. INTERLEAVE_FACTOR can be used to attempt to hide load latency
13832 (using more registers) by doing e.g. load/load/store/store for a factor of 2.
13833 An interleave factor of 1 (the minimum) will perform no interleaving.
13834 Load/store multiple are used for aligned addresses where possible. */
13837 arm_block_move_unaligned_straight (rtx dstbase
, rtx srcbase
,
13838 HOST_WIDE_INT length
,
13839 unsigned int interleave_factor
)
13841 rtx
*regs
= XALLOCAVEC (rtx
, interleave_factor
);
13842 int *regnos
= XALLOCAVEC (int, interleave_factor
);
13843 HOST_WIDE_INT block_size_bytes
= interleave_factor
* UNITS_PER_WORD
;
13844 HOST_WIDE_INT i
, j
;
13845 HOST_WIDE_INT remaining
= length
, words
;
13846 rtx halfword_tmp
= NULL
, byte_tmp
= NULL
;
13848 bool src_aligned
= MEM_ALIGN (srcbase
) >= BITS_PER_WORD
;
13849 bool dst_aligned
= MEM_ALIGN (dstbase
) >= BITS_PER_WORD
;
13850 HOST_WIDE_INT srcoffset
, dstoffset
;
13851 HOST_WIDE_INT src_autoinc
, dst_autoinc
;
13854 gcc_assert (1 <= interleave_factor
&& interleave_factor
<= 4);
13856 /* Use hard registers if we have aligned source or destination so we can use
13857 load/store multiple with contiguous registers. */
13858 if (dst_aligned
|| src_aligned
)
13859 for (i
= 0; i
< interleave_factor
; i
++)
13860 regs
[i
] = gen_rtx_REG (SImode
, i
);
13862 for (i
= 0; i
< interleave_factor
; i
++)
13863 regs
[i
] = gen_reg_rtx (SImode
);
13865 dst
= copy_addr_to_reg (XEXP (dstbase
, 0));
13866 src
= copy_addr_to_reg (XEXP (srcbase
, 0));
13868 srcoffset
= dstoffset
= 0;
13870 /* Calls to arm_gen_load_multiple and arm_gen_store_multiple update SRC/DST.
13871 For copying the last bytes we want to subtract this offset again. */
13872 src_autoinc
= dst_autoinc
= 0;
13874 for (i
= 0; i
< interleave_factor
; i
++)
13877 /* Copy BLOCK_SIZE_BYTES chunks. */
13879 for (i
= 0; i
+ block_size_bytes
<= length
; i
+= block_size_bytes
)
13882 if (src_aligned
&& interleave_factor
> 1)
13884 emit_insn (arm_gen_load_multiple (regnos
, interleave_factor
, src
,
13885 TRUE
, srcbase
, &srcoffset
));
13886 src_autoinc
+= UNITS_PER_WORD
* interleave_factor
;
13890 for (j
= 0; j
< interleave_factor
; j
++)
13892 addr
= plus_constant (Pmode
, src
, (srcoffset
+ j
* UNITS_PER_WORD
13894 mem
= adjust_automodify_address (srcbase
, SImode
, addr
,
13895 srcoffset
+ j
* UNITS_PER_WORD
);
13896 emit_insn (gen_unaligned_loadsi (regs
[j
], mem
));
13898 srcoffset
+= block_size_bytes
;
13902 if (dst_aligned
&& interleave_factor
> 1)
13904 emit_insn (arm_gen_store_multiple (regnos
, interleave_factor
, dst
,
13905 TRUE
, dstbase
, &dstoffset
));
13906 dst_autoinc
+= UNITS_PER_WORD
* interleave_factor
;
13910 for (j
= 0; j
< interleave_factor
; j
++)
13912 addr
= plus_constant (Pmode
, dst
, (dstoffset
+ j
* UNITS_PER_WORD
13914 mem
= adjust_automodify_address (dstbase
, SImode
, addr
,
13915 dstoffset
+ j
* UNITS_PER_WORD
);
13916 emit_insn (gen_unaligned_storesi (mem
, regs
[j
]));
13918 dstoffset
+= block_size_bytes
;
13921 remaining
-= block_size_bytes
;
13924 /* Copy any whole words left (note these aren't interleaved with any
13925 subsequent halfword/byte load/stores in the interests of simplicity). */
13927 words
= remaining
/ UNITS_PER_WORD
;
13929 gcc_assert (words
< interleave_factor
);
13931 if (src_aligned
&& words
> 1)
13933 emit_insn (arm_gen_load_multiple (regnos
, words
, src
, TRUE
, srcbase
,
13935 src_autoinc
+= UNITS_PER_WORD
* words
;
13939 for (j
= 0; j
< words
; j
++)
13941 addr
= plus_constant (Pmode
, src
,
13942 srcoffset
+ j
* UNITS_PER_WORD
- src_autoinc
);
13943 mem
= adjust_automodify_address (srcbase
, SImode
, addr
,
13944 srcoffset
+ j
* UNITS_PER_WORD
);
13946 emit_move_insn (regs
[j
], mem
);
13948 emit_insn (gen_unaligned_loadsi (regs
[j
], mem
));
13950 srcoffset
+= words
* UNITS_PER_WORD
;
13953 if (dst_aligned
&& words
> 1)
13955 emit_insn (arm_gen_store_multiple (regnos
, words
, dst
, TRUE
, dstbase
,
13957 dst_autoinc
+= words
* UNITS_PER_WORD
;
13961 for (j
= 0; j
< words
; j
++)
13963 addr
= plus_constant (Pmode
, dst
,
13964 dstoffset
+ j
* UNITS_PER_WORD
- dst_autoinc
);
13965 mem
= adjust_automodify_address (dstbase
, SImode
, addr
,
13966 dstoffset
+ j
* UNITS_PER_WORD
);
13968 emit_move_insn (mem
, regs
[j
]);
13970 emit_insn (gen_unaligned_storesi (mem
, regs
[j
]));
13972 dstoffset
+= words
* UNITS_PER_WORD
;
13975 remaining
-= words
* UNITS_PER_WORD
;
13977 gcc_assert (remaining
< 4);
13979 /* Copy a halfword if necessary. */
13981 if (remaining
>= 2)
13983 halfword_tmp
= gen_reg_rtx (SImode
);
13985 addr
= plus_constant (Pmode
, src
, srcoffset
- src_autoinc
);
13986 mem
= adjust_automodify_address (srcbase
, HImode
, addr
, srcoffset
);
13987 emit_insn (gen_unaligned_loadhiu (halfword_tmp
, mem
));
13989 /* Either write out immediately, or delay until we've loaded the last
13990 byte, depending on interleave factor. */
13991 if (interleave_factor
== 1)
13993 addr
= plus_constant (Pmode
, dst
, dstoffset
- dst_autoinc
);
13994 mem
= adjust_automodify_address (dstbase
, HImode
, addr
, dstoffset
);
13995 emit_insn (gen_unaligned_storehi (mem
,
13996 gen_lowpart (HImode
, halfword_tmp
)));
13997 halfword_tmp
= NULL
;
14005 gcc_assert (remaining
< 2);
14007 /* Copy last byte. */
14009 if ((remaining
& 1) != 0)
14011 byte_tmp
= gen_reg_rtx (SImode
);
14013 addr
= plus_constant (Pmode
, src
, srcoffset
- src_autoinc
);
14014 mem
= adjust_automodify_address (srcbase
, QImode
, addr
, srcoffset
);
14015 emit_move_insn (gen_lowpart (QImode
, byte_tmp
), mem
);
14017 if (interleave_factor
== 1)
14019 addr
= plus_constant (Pmode
, dst
, dstoffset
- dst_autoinc
);
14020 mem
= adjust_automodify_address (dstbase
, QImode
, addr
, dstoffset
);
14021 emit_move_insn (mem
, gen_lowpart (QImode
, byte_tmp
));
14030 /* Store last halfword if we haven't done so already. */
14034 addr
= plus_constant (Pmode
, dst
, dstoffset
- dst_autoinc
);
14035 mem
= adjust_automodify_address (dstbase
, HImode
, addr
, dstoffset
);
14036 emit_insn (gen_unaligned_storehi (mem
,
14037 gen_lowpart (HImode
, halfword_tmp
)));
14041 /* Likewise for last byte. */
14045 addr
= plus_constant (Pmode
, dst
, dstoffset
- dst_autoinc
);
14046 mem
= adjust_automodify_address (dstbase
, QImode
, addr
, dstoffset
);
14047 emit_move_insn (mem
, gen_lowpart (QImode
, byte_tmp
));
14051 gcc_assert (remaining
== 0 && srcoffset
== dstoffset
);
14054 /* From mips_adjust_block_mem:
14056 Helper function for doing a loop-based block operation on memory
14057 reference MEM. Each iteration of the loop will operate on LENGTH
14060 Create a new base register for use within the loop and point it to
14061 the start of MEM. Create a new memory reference that uses this
14062 register. Store them in *LOOP_REG and *LOOP_MEM respectively. */
14065 arm_adjust_block_mem (rtx mem
, HOST_WIDE_INT length
, rtx
*loop_reg
,
14068 *loop_reg
= copy_addr_to_reg (XEXP (mem
, 0));
14070 /* Although the new mem does not refer to a known location,
14071 it does keep up to LENGTH bytes of alignment. */
14072 *loop_mem
= change_address (mem
, BLKmode
, *loop_reg
);
14073 set_mem_align (*loop_mem
, MIN (MEM_ALIGN (mem
), length
* BITS_PER_UNIT
));
14076 /* From mips_block_move_loop:
14078 Move LENGTH bytes from SRC to DEST using a loop that moves BYTES_PER_ITER
14079 bytes at a time. LENGTH must be at least BYTES_PER_ITER. Assume that
14080 the memory regions do not overlap. */
14083 arm_block_move_unaligned_loop (rtx dest
, rtx src
, HOST_WIDE_INT length
,
14084 unsigned int interleave_factor
,
14085 HOST_WIDE_INT bytes_per_iter
)
14087 rtx src_reg
, dest_reg
, final_src
, test
;
14088 HOST_WIDE_INT leftover
;
14090 leftover
= length
% bytes_per_iter
;
14091 length
-= leftover
;
14093 /* Create registers and memory references for use within the loop. */
14094 arm_adjust_block_mem (src
, bytes_per_iter
, &src_reg
, &src
);
14095 arm_adjust_block_mem (dest
, bytes_per_iter
, &dest_reg
, &dest
);
14097 /* Calculate the value that SRC_REG should have after the last iteration of
14099 final_src
= expand_simple_binop (Pmode
, PLUS
, src_reg
, GEN_INT (length
),
14100 0, 0, OPTAB_WIDEN
);
14102 /* Emit the start of the loop. */
14103 rtx_code_label
*label
= gen_label_rtx ();
14104 emit_label (label
);
14106 /* Emit the loop body. */
14107 arm_block_move_unaligned_straight (dest
, src
, bytes_per_iter
,
14108 interleave_factor
);
14110 /* Move on to the next block. */
14111 emit_move_insn (src_reg
, plus_constant (Pmode
, src_reg
, bytes_per_iter
));
14112 emit_move_insn (dest_reg
, plus_constant (Pmode
, dest_reg
, bytes_per_iter
));
14114 /* Emit the loop condition. */
14115 test
= gen_rtx_NE (VOIDmode
, src_reg
, final_src
);
14116 emit_jump_insn (gen_cbranchsi4 (test
, src_reg
, final_src
, label
));
14118 /* Mop up any left-over bytes. */
14120 arm_block_move_unaligned_straight (dest
, src
, leftover
, interleave_factor
);
14123 /* Emit a block move when either the source or destination is unaligned (not
14124 aligned to a four-byte boundary). This may need further tuning depending on
14125 core type, optimize_size setting, etc. */
14128 arm_movmemqi_unaligned (rtx
*operands
)
14130 HOST_WIDE_INT length
= INTVAL (operands
[2]);
14134 bool src_aligned
= MEM_ALIGN (operands
[1]) >= BITS_PER_WORD
;
14135 bool dst_aligned
= MEM_ALIGN (operands
[0]) >= BITS_PER_WORD
;
14136 /* Inlined memcpy using ldr/str/ldrh/strh can be quite big: try to limit
14137 size of code if optimizing for size. We'll use ldm/stm if src_aligned
14138 or dst_aligned though: allow more interleaving in those cases since the
14139 resulting code can be smaller. */
14140 unsigned int interleave_factor
= (src_aligned
|| dst_aligned
) ? 2 : 1;
14141 HOST_WIDE_INT bytes_per_iter
= (src_aligned
|| dst_aligned
) ? 8 : 4;
14144 arm_block_move_unaligned_loop (operands
[0], operands
[1], length
,
14145 interleave_factor
, bytes_per_iter
);
14147 arm_block_move_unaligned_straight (operands
[0], operands
[1], length
,
14148 interleave_factor
);
14152 /* Note that the loop created by arm_block_move_unaligned_loop may be
14153 subject to loop unrolling, which makes tuning this condition a little
14156 arm_block_move_unaligned_loop (operands
[0], operands
[1], length
, 4, 16);
14158 arm_block_move_unaligned_straight (operands
[0], operands
[1], length
, 4);
14165 arm_gen_movmemqi (rtx
*operands
)
14167 HOST_WIDE_INT in_words_to_go
, out_words_to_go
, last_bytes
;
14168 HOST_WIDE_INT srcoffset
, dstoffset
;
14169 rtx src
, dst
, srcbase
, dstbase
;
14170 rtx part_bytes_reg
= NULL
;
14173 if (!CONST_INT_P (operands
[2])
14174 || !CONST_INT_P (operands
[3])
14175 || INTVAL (operands
[2]) > 64)
14178 if (unaligned_access
&& (INTVAL (operands
[3]) & 3) != 0)
14179 return arm_movmemqi_unaligned (operands
);
14181 if (INTVAL (operands
[3]) & 3)
14184 dstbase
= operands
[0];
14185 srcbase
= operands
[1];
14187 dst
= copy_to_mode_reg (SImode
, XEXP (dstbase
, 0));
14188 src
= copy_to_mode_reg (SImode
, XEXP (srcbase
, 0));
14190 in_words_to_go
= ARM_NUM_INTS (INTVAL (operands
[2]));
14191 out_words_to_go
= INTVAL (operands
[2]) / 4;
14192 last_bytes
= INTVAL (operands
[2]) & 3;
14193 dstoffset
= srcoffset
= 0;
14195 if (out_words_to_go
!= in_words_to_go
&& ((in_words_to_go
- 1) & 3) != 0)
14196 part_bytes_reg
= gen_rtx_REG (SImode
, (in_words_to_go
- 1) & 3);
14198 while (in_words_to_go
>= 2)
14200 if (in_words_to_go
> 4)
14201 emit_insn (arm_gen_load_multiple (arm_regs_in_sequence
, 4, src
,
14202 TRUE
, srcbase
, &srcoffset
));
14204 emit_insn (arm_gen_load_multiple (arm_regs_in_sequence
, in_words_to_go
,
14205 src
, FALSE
, srcbase
,
14208 if (out_words_to_go
)
14210 if (out_words_to_go
> 4)
14211 emit_insn (arm_gen_store_multiple (arm_regs_in_sequence
, 4, dst
,
14212 TRUE
, dstbase
, &dstoffset
));
14213 else if (out_words_to_go
!= 1)
14214 emit_insn (arm_gen_store_multiple (arm_regs_in_sequence
,
14215 out_words_to_go
, dst
,
14218 dstbase
, &dstoffset
));
14221 mem
= adjust_automodify_address (dstbase
, SImode
, dst
, dstoffset
);
14222 emit_move_insn (mem
, gen_rtx_REG (SImode
, R0_REGNUM
));
14223 if (last_bytes
!= 0)
14225 emit_insn (gen_addsi3 (dst
, dst
, GEN_INT (4)));
14231 in_words_to_go
-= in_words_to_go
< 4 ? in_words_to_go
: 4;
14232 out_words_to_go
-= out_words_to_go
< 4 ? out_words_to_go
: 4;
14235 /* OUT_WORDS_TO_GO will be zero here if there are byte stores to do. */
14236 if (out_words_to_go
)
14240 mem
= adjust_automodify_address (srcbase
, SImode
, src
, srcoffset
);
14241 sreg
= copy_to_reg (mem
);
14243 mem
= adjust_automodify_address (dstbase
, SImode
, dst
, dstoffset
);
14244 emit_move_insn (mem
, sreg
);
14247 gcc_assert (!in_words_to_go
); /* Sanity check */
14250 if (in_words_to_go
)
14252 gcc_assert (in_words_to_go
> 0);
14254 mem
= adjust_automodify_address (srcbase
, SImode
, src
, srcoffset
);
14255 part_bytes_reg
= copy_to_mode_reg (SImode
, mem
);
14258 gcc_assert (!last_bytes
|| part_bytes_reg
);
14260 if (BYTES_BIG_ENDIAN
&& last_bytes
)
14262 rtx tmp
= gen_reg_rtx (SImode
);
14264 /* The bytes we want are in the top end of the word. */
14265 emit_insn (gen_lshrsi3 (tmp
, part_bytes_reg
,
14266 GEN_INT (8 * (4 - last_bytes
))));
14267 part_bytes_reg
= tmp
;
14271 mem
= adjust_automodify_address (dstbase
, QImode
,
14272 plus_constant (Pmode
, dst
,
14274 dstoffset
+ last_bytes
- 1);
14275 emit_move_insn (mem
, gen_lowpart (QImode
, part_bytes_reg
));
14279 tmp
= gen_reg_rtx (SImode
);
14280 emit_insn (gen_lshrsi3 (tmp
, part_bytes_reg
, GEN_INT (8)));
14281 part_bytes_reg
= tmp
;
14288 if (last_bytes
> 1)
14290 mem
= adjust_automodify_address (dstbase
, HImode
, dst
, dstoffset
);
14291 emit_move_insn (mem
, gen_lowpart (HImode
, part_bytes_reg
));
14295 rtx tmp
= gen_reg_rtx (SImode
);
14296 emit_insn (gen_addsi3 (dst
, dst
, const2_rtx
));
14297 emit_insn (gen_lshrsi3 (tmp
, part_bytes_reg
, GEN_INT (16)));
14298 part_bytes_reg
= tmp
;
14305 mem
= adjust_automodify_address (dstbase
, QImode
, dst
, dstoffset
);
14306 emit_move_insn (mem
, gen_lowpart (QImode
, part_bytes_reg
));
14313 /* Helper for gen_movmem_ldrd_strd. Increase the address of memory rtx
14316 next_consecutive_mem (rtx mem
)
14318 machine_mode mode
= GET_MODE (mem
);
14319 HOST_WIDE_INT offset
= GET_MODE_SIZE (mode
);
14320 rtx addr
= plus_constant (Pmode
, XEXP (mem
, 0), offset
);
14322 return adjust_automodify_address (mem
, mode
, addr
, offset
);
14325 /* Copy using LDRD/STRD instructions whenever possible.
14326 Returns true upon success. */
14328 gen_movmem_ldrd_strd (rtx
*operands
)
14330 unsigned HOST_WIDE_INT len
;
14331 HOST_WIDE_INT align
;
14332 rtx src
, dst
, base
;
14334 bool src_aligned
, dst_aligned
;
14335 bool src_volatile
, dst_volatile
;
14337 gcc_assert (CONST_INT_P (operands
[2]));
14338 gcc_assert (CONST_INT_P (operands
[3]));
14340 len
= UINTVAL (operands
[2]);
14344 /* Maximum alignment we can assume for both src and dst buffers. */
14345 align
= INTVAL (operands
[3]);
14347 if ((!unaligned_access
) && (len
>= 4) && ((align
& 3) != 0))
14350 /* Place src and dst addresses in registers
14351 and update the corresponding mem rtx. */
14353 dst_volatile
= MEM_VOLATILE_P (dst
);
14354 dst_aligned
= MEM_ALIGN (dst
) >= BITS_PER_WORD
;
14355 base
= copy_to_mode_reg (SImode
, XEXP (dst
, 0));
14356 dst
= adjust_automodify_address (dst
, VOIDmode
, base
, 0);
14359 src_volatile
= MEM_VOLATILE_P (src
);
14360 src_aligned
= MEM_ALIGN (src
) >= BITS_PER_WORD
;
14361 base
= copy_to_mode_reg (SImode
, XEXP (src
, 0));
14362 src
= adjust_automodify_address (src
, VOIDmode
, base
, 0);
14364 if (!unaligned_access
&& !(src_aligned
&& dst_aligned
))
14367 if (src_volatile
|| dst_volatile
)
14370 /* If we cannot generate any LDRD/STRD, try to generate LDM/STM. */
14371 if (!(dst_aligned
|| src_aligned
))
14372 return arm_gen_movmemqi (operands
);
14374 /* If the either src or dst is unaligned we'll be accessing it as pairs
14375 of unaligned SImode accesses. Otherwise we can generate DImode
14376 ldrd/strd instructions. */
14377 src
= adjust_address (src
, src_aligned
? DImode
: SImode
, 0);
14378 dst
= adjust_address (dst
, dst_aligned
? DImode
: SImode
, 0);
14383 reg0
= gen_reg_rtx (DImode
);
14384 rtx low_reg
= NULL_RTX
;
14385 rtx hi_reg
= NULL_RTX
;
14387 if (!src_aligned
|| !dst_aligned
)
14389 low_reg
= gen_lowpart (SImode
, reg0
);
14390 hi_reg
= gen_highpart_mode (SImode
, DImode
, reg0
);
14393 emit_move_insn (reg0
, src
);
14396 emit_insn (gen_unaligned_loadsi (low_reg
, src
));
14397 src
= next_consecutive_mem (src
);
14398 emit_insn (gen_unaligned_loadsi (hi_reg
, src
));
14402 emit_move_insn (dst
, reg0
);
14405 emit_insn (gen_unaligned_storesi (dst
, low_reg
));
14406 dst
= next_consecutive_mem (dst
);
14407 emit_insn (gen_unaligned_storesi (dst
, hi_reg
));
14410 src
= next_consecutive_mem (src
);
14411 dst
= next_consecutive_mem (dst
);
14414 gcc_assert (len
< 8);
14417 /* More than a word but less than a double-word to copy. Copy a word. */
14418 reg0
= gen_reg_rtx (SImode
);
14419 src
= adjust_address (src
, SImode
, 0);
14420 dst
= adjust_address (dst
, SImode
, 0);
14422 emit_move_insn (reg0
, src
);
14424 emit_insn (gen_unaligned_loadsi (reg0
, src
));
14427 emit_move_insn (dst
, reg0
);
14429 emit_insn (gen_unaligned_storesi (dst
, reg0
));
14431 src
= next_consecutive_mem (src
);
14432 dst
= next_consecutive_mem (dst
);
14439 /* Copy the remaining bytes. */
14442 dst
= adjust_address (dst
, HImode
, 0);
14443 src
= adjust_address (src
, HImode
, 0);
14444 reg0
= gen_reg_rtx (SImode
);
14446 emit_insn (gen_zero_extendhisi2 (reg0
, src
));
14448 emit_insn (gen_unaligned_loadhiu (reg0
, src
));
14451 emit_insn (gen_movhi (dst
, gen_lowpart(HImode
, reg0
)));
14453 emit_insn (gen_unaligned_storehi (dst
, gen_lowpart (HImode
, reg0
)));
14455 src
= next_consecutive_mem (src
);
14456 dst
= next_consecutive_mem (dst
);
14461 dst
= adjust_address (dst
, QImode
, 0);
14462 src
= adjust_address (src
, QImode
, 0);
14463 reg0
= gen_reg_rtx (QImode
);
14464 emit_move_insn (reg0
, src
);
14465 emit_move_insn (dst
, reg0
);
14469 /* Select a dominance comparison mode if possible for a test of the general
14470 form (OP (COND_OR (X) (Y)) (const_int 0)). We support three forms.
14471 COND_OR == DOM_CC_X_AND_Y => (X && Y)
14472 COND_OR == DOM_CC_NX_OR_Y => ((! X) || Y)
14473 COND_OR == DOM_CC_X_OR_Y => (X || Y)
14474 In all cases OP will be either EQ or NE, but we don't need to know which
14475 here. If we are unable to support a dominance comparison we return
14476 CC mode. This will then fail to match for the RTL expressions that
14477 generate this call. */
14479 arm_select_dominance_cc_mode (rtx x
, rtx y
, HOST_WIDE_INT cond_or
)
14481 enum rtx_code cond1
, cond2
;
14484 /* Currently we will probably get the wrong result if the individual
14485 comparisons are not simple. This also ensures that it is safe to
14486 reverse a comparison if necessary. */
14487 if ((arm_select_cc_mode (cond1
= GET_CODE (x
), XEXP (x
, 0), XEXP (x
, 1))
14489 || (arm_select_cc_mode (cond2
= GET_CODE (y
), XEXP (y
, 0), XEXP (y
, 1))
14493 /* The if_then_else variant of this tests the second condition if the
14494 first passes, but is true if the first fails. Reverse the first
14495 condition to get a true "inclusive-or" expression. */
14496 if (cond_or
== DOM_CC_NX_OR_Y
)
14497 cond1
= reverse_condition (cond1
);
14499 /* If the comparisons are not equal, and one doesn't dominate the other,
14500 then we can't do this. */
14502 && !comparison_dominates_p (cond1
, cond2
)
14503 && (swapped
= 1, !comparison_dominates_p (cond2
, cond1
)))
14507 std::swap (cond1
, cond2
);
14512 if (cond_or
== DOM_CC_X_AND_Y
)
14517 case EQ
: return CC_DEQmode
;
14518 case LE
: return CC_DLEmode
;
14519 case LEU
: return CC_DLEUmode
;
14520 case GE
: return CC_DGEmode
;
14521 case GEU
: return CC_DGEUmode
;
14522 default: gcc_unreachable ();
14526 if (cond_or
== DOM_CC_X_AND_Y
)
14538 gcc_unreachable ();
14542 if (cond_or
== DOM_CC_X_AND_Y
)
14554 gcc_unreachable ();
14558 if (cond_or
== DOM_CC_X_AND_Y
)
14559 return CC_DLTUmode
;
14564 return CC_DLTUmode
;
14566 return CC_DLEUmode
;
14570 gcc_unreachable ();
14574 if (cond_or
== DOM_CC_X_AND_Y
)
14575 return CC_DGTUmode
;
14580 return CC_DGTUmode
;
14582 return CC_DGEUmode
;
14586 gcc_unreachable ();
14589 /* The remaining cases only occur when both comparisons are the
14592 gcc_assert (cond1
== cond2
);
14596 gcc_assert (cond1
== cond2
);
14600 gcc_assert (cond1
== cond2
);
14604 gcc_assert (cond1
== cond2
);
14605 return CC_DLEUmode
;
14608 gcc_assert (cond1
== cond2
);
14609 return CC_DGEUmode
;
14612 gcc_unreachable ();
14617 arm_select_cc_mode (enum rtx_code op
, rtx x
, rtx y
)
14619 /* All floating point compares return CCFP if it is an equality
14620 comparison, and CCFPE otherwise. */
14621 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
14644 gcc_unreachable ();
14648 /* A compare with a shifted operand. Because of canonicalization, the
14649 comparison will have to be swapped when we emit the assembler. */
14650 if (GET_MODE (y
) == SImode
14651 && (REG_P (y
) || (GET_CODE (y
) == SUBREG
))
14652 && (GET_CODE (x
) == ASHIFT
|| GET_CODE (x
) == ASHIFTRT
14653 || GET_CODE (x
) == LSHIFTRT
|| GET_CODE (x
) == ROTATE
14654 || GET_CODE (x
) == ROTATERT
))
14657 /* This operation is performed swapped, but since we only rely on the Z
14658 flag we don't need an additional mode. */
14659 if (GET_MODE (y
) == SImode
14660 && (REG_P (y
) || (GET_CODE (y
) == SUBREG
))
14661 && GET_CODE (x
) == NEG
14662 && (op
== EQ
|| op
== NE
))
14665 /* This is a special case that is used by combine to allow a
14666 comparison of a shifted byte load to be split into a zero-extend
14667 followed by a comparison of the shifted integer (only valid for
14668 equalities and unsigned inequalities). */
14669 if (GET_MODE (x
) == SImode
14670 && GET_CODE (x
) == ASHIFT
14671 && CONST_INT_P (XEXP (x
, 1)) && INTVAL (XEXP (x
, 1)) == 24
14672 && GET_CODE (XEXP (x
, 0)) == SUBREG
14673 && MEM_P (SUBREG_REG (XEXP (x
, 0)))
14674 && GET_MODE (SUBREG_REG (XEXP (x
, 0))) == QImode
14675 && (op
== EQ
|| op
== NE
14676 || op
== GEU
|| op
== GTU
|| op
== LTU
|| op
== LEU
)
14677 && CONST_INT_P (y
))
14680 /* A construct for a conditional compare, if the false arm contains
14681 0, then both conditions must be true, otherwise either condition
14682 must be true. Not all conditions are possible, so CCmode is
14683 returned if it can't be done. */
14684 if (GET_CODE (x
) == IF_THEN_ELSE
14685 && (XEXP (x
, 2) == const0_rtx
14686 || XEXP (x
, 2) == const1_rtx
)
14687 && COMPARISON_P (XEXP (x
, 0))
14688 && COMPARISON_P (XEXP (x
, 1)))
14689 return arm_select_dominance_cc_mode (XEXP (x
, 0), XEXP (x
, 1),
14690 INTVAL (XEXP (x
, 2)));
14692 /* Alternate canonicalizations of the above. These are somewhat cleaner. */
14693 if (GET_CODE (x
) == AND
14694 && (op
== EQ
|| op
== NE
)
14695 && COMPARISON_P (XEXP (x
, 0))
14696 && COMPARISON_P (XEXP (x
, 1)))
14697 return arm_select_dominance_cc_mode (XEXP (x
, 0), XEXP (x
, 1),
14700 if (GET_CODE (x
) == IOR
14701 && (op
== EQ
|| op
== NE
)
14702 && COMPARISON_P (XEXP (x
, 0))
14703 && COMPARISON_P (XEXP (x
, 1)))
14704 return arm_select_dominance_cc_mode (XEXP (x
, 0), XEXP (x
, 1),
14707 /* An operation (on Thumb) where we want to test for a single bit.
14708 This is done by shifting that bit up into the top bit of a
14709 scratch register; we can then branch on the sign bit. */
14711 && GET_MODE (x
) == SImode
14712 && (op
== EQ
|| op
== NE
)
14713 && GET_CODE (x
) == ZERO_EXTRACT
14714 && XEXP (x
, 1) == const1_rtx
)
14717 /* An operation that sets the condition codes as a side-effect, the
14718 V flag is not set correctly, so we can only use comparisons where
14719 this doesn't matter. (For LT and GE we can use "mi" and "pl"
14721 /* ??? Does the ZERO_EXTRACT case really apply to thumb2? */
14722 if (GET_MODE (x
) == SImode
14724 && (op
== EQ
|| op
== NE
|| op
== LT
|| op
== GE
)
14725 && (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
14726 || GET_CODE (x
) == AND
|| GET_CODE (x
) == IOR
14727 || GET_CODE (x
) == XOR
|| GET_CODE (x
) == MULT
14728 || GET_CODE (x
) == NOT
|| GET_CODE (x
) == NEG
14729 || GET_CODE (x
) == LSHIFTRT
14730 || GET_CODE (x
) == ASHIFT
|| GET_CODE (x
) == ASHIFTRT
14731 || GET_CODE (x
) == ROTATERT
14732 || (TARGET_32BIT
&& GET_CODE (x
) == ZERO_EXTRACT
)))
14733 return CC_NOOVmode
;
14735 if (GET_MODE (x
) == QImode
&& (op
== EQ
|| op
== NE
))
14738 if (GET_MODE (x
) == SImode
&& (op
== LTU
|| op
== GEU
)
14739 && GET_CODE (x
) == PLUS
14740 && (rtx_equal_p (XEXP (x
, 0), y
) || rtx_equal_p (XEXP (x
, 1), y
)))
14743 if (GET_MODE (x
) == DImode
|| GET_MODE (y
) == DImode
)
14749 /* A DImode comparison against zero can be implemented by
14750 or'ing the two halves together. */
14751 if (y
== const0_rtx
)
14754 /* We can do an equality test in three Thumb instructions. */
14764 /* DImode unsigned comparisons can be implemented by cmp +
14765 cmpeq without a scratch register. Not worth doing in
14776 /* DImode signed and unsigned comparisons can be implemented
14777 by cmp + sbcs with a scratch register, but that does not
14778 set the Z flag - we must reverse GT/LE/GTU/LEU. */
14779 gcc_assert (op
!= EQ
&& op
!= NE
);
14783 gcc_unreachable ();
14787 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_CC
)
14788 return GET_MODE (x
);
14793 /* X and Y are two things to compare using CODE. Emit the compare insn and
14794 return the rtx for register 0 in the proper mode. FP means this is a
14795 floating point compare: I don't think that it is needed on the arm. */
14797 arm_gen_compare_reg (enum rtx_code code
, rtx x
, rtx y
, rtx scratch
)
14801 int dimode_comparison
= GET_MODE (x
) == DImode
|| GET_MODE (y
) == DImode
;
14803 /* We might have X as a constant, Y as a register because of the predicates
14804 used for cmpdi. If so, force X to a register here. */
14805 if (dimode_comparison
&& !REG_P (x
))
14806 x
= force_reg (DImode
, x
);
14808 mode
= SELECT_CC_MODE (code
, x
, y
);
14809 cc_reg
= gen_rtx_REG (mode
, CC_REGNUM
);
14811 if (dimode_comparison
14812 && mode
!= CC_CZmode
)
14816 /* To compare two non-zero values for equality, XOR them and
14817 then compare against zero. Not used for ARM mode; there
14818 CC_CZmode is cheaper. */
14819 if (mode
== CC_Zmode
&& y
!= const0_rtx
)
14821 gcc_assert (!reload_completed
);
14822 x
= expand_binop (DImode
, xor_optab
, x
, y
, NULL_RTX
, 0, OPTAB_WIDEN
);
14826 /* A scratch register is required. */
14827 if (reload_completed
)
14828 gcc_assert (scratch
!= NULL
&& GET_MODE (scratch
) == SImode
);
14830 scratch
= gen_rtx_SCRATCH (SImode
);
14832 clobber
= gen_rtx_CLOBBER (VOIDmode
, scratch
);
14833 set
= gen_rtx_SET (cc_reg
, gen_rtx_COMPARE (mode
, x
, y
));
14834 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, set
, clobber
)));
14837 emit_set_insn (cc_reg
, gen_rtx_COMPARE (mode
, x
, y
));
14842 /* Generate a sequence of insns that will generate the correct return
14843 address mask depending on the physical architecture that the program
14846 arm_gen_return_addr_mask (void)
14848 rtx reg
= gen_reg_rtx (Pmode
);
14850 emit_insn (gen_return_addr_mask (reg
));
14855 arm_reload_in_hi (rtx
*operands
)
14857 rtx ref
= operands
[1];
14859 HOST_WIDE_INT offset
= 0;
14861 if (GET_CODE (ref
) == SUBREG
)
14863 offset
= SUBREG_BYTE (ref
);
14864 ref
= SUBREG_REG (ref
);
14869 /* We have a pseudo which has been spilt onto the stack; there
14870 are two cases here: the first where there is a simple
14871 stack-slot replacement and a second where the stack-slot is
14872 out of range, or is used as a subreg. */
14873 if (reg_equiv_mem (REGNO (ref
)))
14875 ref
= reg_equiv_mem (REGNO (ref
));
14876 base
= find_replacement (&XEXP (ref
, 0));
14879 /* The slot is out of range, or was dressed up in a SUBREG. */
14880 base
= reg_equiv_address (REGNO (ref
));
14882 /* PR 62554: If there is no equivalent memory location then just move
14883 the value as an SImode register move. This happens when the target
14884 architecture variant does not have an HImode register move. */
14887 gcc_assert (REG_P (operands
[0]));
14888 emit_insn (gen_movsi (gen_rtx_SUBREG (SImode
, operands
[0], 0),
14889 gen_rtx_SUBREG (SImode
, ref
, 0)));
14894 base
= find_replacement (&XEXP (ref
, 0));
14896 /* Handle the case where the address is too complex to be offset by 1. */
14897 if (GET_CODE (base
) == MINUS
14898 || (GET_CODE (base
) == PLUS
&& !CONST_INT_P (XEXP (base
, 1))))
14900 rtx base_plus
= gen_rtx_REG (SImode
, REGNO (operands
[2]) + 1);
14902 emit_set_insn (base_plus
, base
);
14905 else if (GET_CODE (base
) == PLUS
)
14907 /* The addend must be CONST_INT, or we would have dealt with it above. */
14908 HOST_WIDE_INT hi
, lo
;
14910 offset
+= INTVAL (XEXP (base
, 1));
14911 base
= XEXP (base
, 0);
14913 /* Rework the address into a legal sequence of insns. */
14914 /* Valid range for lo is -4095 -> 4095 */
14917 : -((-offset
) & 0xfff));
14919 /* Corner case, if lo is the max offset then we would be out of range
14920 once we have added the additional 1 below, so bump the msb into the
14921 pre-loading insn(s). */
14925 hi
= ((((offset
- lo
) & (HOST_WIDE_INT
) 0xffffffff)
14926 ^ (HOST_WIDE_INT
) 0x80000000)
14927 - (HOST_WIDE_INT
) 0x80000000);
14929 gcc_assert (hi
+ lo
== offset
);
14933 rtx base_plus
= gen_rtx_REG (SImode
, REGNO (operands
[2]) + 1);
14935 /* Get the base address; addsi3 knows how to handle constants
14936 that require more than one insn. */
14937 emit_insn (gen_addsi3 (base_plus
, base
, GEN_INT (hi
)));
14943 /* Operands[2] may overlap operands[0] (though it won't overlap
14944 operands[1]), that's why we asked for a DImode reg -- so we can
14945 use the bit that does not overlap. */
14946 if (REGNO (operands
[2]) == REGNO (operands
[0]))
14947 scratch
= gen_rtx_REG (SImode
, REGNO (operands
[2]) + 1);
14949 scratch
= gen_rtx_REG (SImode
, REGNO (operands
[2]));
14951 emit_insn (gen_zero_extendqisi2 (scratch
,
14952 gen_rtx_MEM (QImode
,
14953 plus_constant (Pmode
, base
,
14955 emit_insn (gen_zero_extendqisi2 (gen_rtx_SUBREG (SImode
, operands
[0], 0),
14956 gen_rtx_MEM (QImode
,
14957 plus_constant (Pmode
, base
,
14959 if (!BYTES_BIG_ENDIAN
)
14960 emit_set_insn (gen_rtx_SUBREG (SImode
, operands
[0], 0),
14961 gen_rtx_IOR (SImode
,
14964 gen_rtx_SUBREG (SImode
, operands
[0], 0),
14968 emit_set_insn (gen_rtx_SUBREG (SImode
, operands
[0], 0),
14969 gen_rtx_IOR (SImode
,
14970 gen_rtx_ASHIFT (SImode
, scratch
,
14972 gen_rtx_SUBREG (SImode
, operands
[0], 0)));
14975 /* Handle storing a half-word to memory during reload by synthesizing as two
14976 byte stores. Take care not to clobber the input values until after we
14977 have moved them somewhere safe. This code assumes that if the DImode
14978 scratch in operands[2] overlaps either the input value or output address
14979 in some way, then that value must die in this insn (we absolutely need
14980 two scratch registers for some corner cases). */
14982 arm_reload_out_hi (rtx
*operands
)
14984 rtx ref
= operands
[0];
14985 rtx outval
= operands
[1];
14987 HOST_WIDE_INT offset
= 0;
14989 if (GET_CODE (ref
) == SUBREG
)
14991 offset
= SUBREG_BYTE (ref
);
14992 ref
= SUBREG_REG (ref
);
14997 /* We have a pseudo which has been spilt onto the stack; there
14998 are two cases here: the first where there is a simple
14999 stack-slot replacement and a second where the stack-slot is
15000 out of range, or is used as a subreg. */
15001 if (reg_equiv_mem (REGNO (ref
)))
15003 ref
= reg_equiv_mem (REGNO (ref
));
15004 base
= find_replacement (&XEXP (ref
, 0));
15007 /* The slot is out of range, or was dressed up in a SUBREG. */
15008 base
= reg_equiv_address (REGNO (ref
));
15010 /* PR 62254: If there is no equivalent memory location then just move
15011 the value as an SImode register move. This happens when the target
15012 architecture variant does not have an HImode register move. */
15015 gcc_assert (REG_P (outval
) || SUBREG_P (outval
));
15017 if (REG_P (outval
))
15019 emit_insn (gen_movsi (gen_rtx_SUBREG (SImode
, ref
, 0),
15020 gen_rtx_SUBREG (SImode
, outval
, 0)));
15022 else /* SUBREG_P (outval) */
15024 if (GET_MODE (SUBREG_REG (outval
)) == SImode
)
15025 emit_insn (gen_movsi (gen_rtx_SUBREG (SImode
, ref
, 0),
15026 SUBREG_REG (outval
)));
15028 /* FIXME: Handle other cases ? */
15029 gcc_unreachable ();
15035 base
= find_replacement (&XEXP (ref
, 0));
15037 scratch
= gen_rtx_REG (SImode
, REGNO (operands
[2]));
15039 /* Handle the case where the address is too complex to be offset by 1. */
15040 if (GET_CODE (base
) == MINUS
15041 || (GET_CODE (base
) == PLUS
&& !CONST_INT_P (XEXP (base
, 1))))
15043 rtx base_plus
= gen_rtx_REG (SImode
, REGNO (operands
[2]) + 1);
15045 /* Be careful not to destroy OUTVAL. */
15046 if (reg_overlap_mentioned_p (base_plus
, outval
))
15048 /* Updating base_plus might destroy outval, see if we can
15049 swap the scratch and base_plus. */
15050 if (!reg_overlap_mentioned_p (scratch
, outval
))
15051 std::swap (scratch
, base_plus
);
15054 rtx scratch_hi
= gen_rtx_REG (HImode
, REGNO (operands
[2]));
15056 /* Be conservative and copy OUTVAL into the scratch now,
15057 this should only be necessary if outval is a subreg
15058 of something larger than a word. */
15059 /* XXX Might this clobber base? I can't see how it can,
15060 since scratch is known to overlap with OUTVAL, and
15061 must be wider than a word. */
15062 emit_insn (gen_movhi (scratch_hi
, outval
));
15063 outval
= scratch_hi
;
15067 emit_set_insn (base_plus
, base
);
15070 else if (GET_CODE (base
) == PLUS
)
15072 /* The addend must be CONST_INT, or we would have dealt with it above. */
15073 HOST_WIDE_INT hi
, lo
;
15075 offset
+= INTVAL (XEXP (base
, 1));
15076 base
= XEXP (base
, 0);
15078 /* Rework the address into a legal sequence of insns. */
15079 /* Valid range for lo is -4095 -> 4095 */
15082 : -((-offset
) & 0xfff));
15084 /* Corner case, if lo is the max offset then we would be out of range
15085 once we have added the additional 1 below, so bump the msb into the
15086 pre-loading insn(s). */
15090 hi
= ((((offset
- lo
) & (HOST_WIDE_INT
) 0xffffffff)
15091 ^ (HOST_WIDE_INT
) 0x80000000)
15092 - (HOST_WIDE_INT
) 0x80000000);
15094 gcc_assert (hi
+ lo
== offset
);
15098 rtx base_plus
= gen_rtx_REG (SImode
, REGNO (operands
[2]) + 1);
15100 /* Be careful not to destroy OUTVAL. */
15101 if (reg_overlap_mentioned_p (base_plus
, outval
))
15103 /* Updating base_plus might destroy outval, see if we
15104 can swap the scratch and base_plus. */
15105 if (!reg_overlap_mentioned_p (scratch
, outval
))
15106 std::swap (scratch
, base_plus
);
15109 rtx scratch_hi
= gen_rtx_REG (HImode
, REGNO (operands
[2]));
15111 /* Be conservative and copy outval into scratch now,
15112 this should only be necessary if outval is a
15113 subreg of something larger than a word. */
15114 /* XXX Might this clobber base? I can't see how it
15115 can, since scratch is known to overlap with
15117 emit_insn (gen_movhi (scratch_hi
, outval
));
15118 outval
= scratch_hi
;
15122 /* Get the base address; addsi3 knows how to handle constants
15123 that require more than one insn. */
15124 emit_insn (gen_addsi3 (base_plus
, base
, GEN_INT (hi
)));
15130 if (BYTES_BIG_ENDIAN
)
15132 emit_insn (gen_movqi (gen_rtx_MEM (QImode
,
15133 plus_constant (Pmode
, base
,
15135 gen_lowpart (QImode
, outval
)));
15136 emit_insn (gen_lshrsi3 (scratch
,
15137 gen_rtx_SUBREG (SImode
, outval
, 0),
15139 emit_insn (gen_movqi (gen_rtx_MEM (QImode
, plus_constant (Pmode
, base
,
15141 gen_lowpart (QImode
, scratch
)));
15145 emit_insn (gen_movqi (gen_rtx_MEM (QImode
, plus_constant (Pmode
, base
,
15147 gen_lowpart (QImode
, outval
)));
15148 emit_insn (gen_lshrsi3 (scratch
,
15149 gen_rtx_SUBREG (SImode
, outval
, 0),
15151 emit_insn (gen_movqi (gen_rtx_MEM (QImode
,
15152 plus_constant (Pmode
, base
,
15154 gen_lowpart (QImode
, scratch
)));
15158 /* Return true if a type must be passed in memory. For AAPCS, small aggregates
15159 (padded to the size of a word) should be passed in a register. */
15162 arm_must_pass_in_stack (machine_mode mode
, const_tree type
)
15164 if (TARGET_AAPCS_BASED
)
15165 return must_pass_in_stack_var_size (mode
, type
);
15167 return must_pass_in_stack_var_size_or_pad (mode
, type
);
15171 /* Implement TARGET_FUNCTION_ARG_PADDING; return PAD_UPWARD if the lowest
15172 byte of a stack argument has useful data. For legacy APCS ABIs we use
15173 the default. For AAPCS based ABIs small aggregate types are placed
15174 in the lowest memory address. */
15176 static pad_direction
15177 arm_function_arg_padding (machine_mode mode
, const_tree type
)
15179 if (!TARGET_AAPCS_BASED
)
15180 return default_function_arg_padding (mode
, type
);
15182 if (type
&& BYTES_BIG_ENDIAN
&& INTEGRAL_TYPE_P (type
))
15183 return PAD_DOWNWARD
;
15189 /* Similarly, for use by BLOCK_REG_PADDING (MODE, TYPE, FIRST).
15190 Return !BYTES_BIG_ENDIAN if the least significant byte of the
15191 register has useful data, and return the opposite if the most
15192 significant byte does. */
15195 arm_pad_reg_upward (machine_mode mode
,
15196 tree type
, int first ATTRIBUTE_UNUSED
)
15198 if (TARGET_AAPCS_BASED
&& BYTES_BIG_ENDIAN
)
15200 /* For AAPCS, small aggregates, small fixed-point types,
15201 and small complex types are always padded upwards. */
15204 if ((AGGREGATE_TYPE_P (type
)
15205 || TREE_CODE (type
) == COMPLEX_TYPE
15206 || FIXED_POINT_TYPE_P (type
))
15207 && int_size_in_bytes (type
) <= 4)
15212 if ((COMPLEX_MODE_P (mode
) || ALL_FIXED_POINT_MODE_P (mode
))
15213 && GET_MODE_SIZE (mode
) <= 4)
15218 /* Otherwise, use default padding. */
15219 return !BYTES_BIG_ENDIAN
;
15222 /* Returns true iff OFFSET is valid for use in an LDRD/STRD instruction,
15223 assuming that the address in the base register is word aligned. */
15225 offset_ok_for_ldrd_strd (HOST_WIDE_INT offset
)
15227 HOST_WIDE_INT max_offset
;
15229 /* Offset must be a multiple of 4 in Thumb mode. */
15230 if (TARGET_THUMB2
&& ((offset
& 3) != 0))
15235 else if (TARGET_ARM
)
15240 return ((offset
<= max_offset
) && (offset
>= -max_offset
));
15243 /* Checks whether the operands are valid for use in an LDRD/STRD instruction.
15244 Assumes that RT, RT2, and RN are REG. This is guaranteed by the patterns.
15245 Assumes that the address in the base register RN is word aligned. Pattern
15246 guarantees that both memory accesses use the same base register,
15247 the offsets are constants within the range, and the gap between the offsets is 4.
15248 If preload complete then check that registers are legal. WBACK indicates whether
15249 address is updated. LOAD indicates whether memory access is load or store. */
15251 operands_ok_ldrd_strd (rtx rt
, rtx rt2
, rtx rn
, HOST_WIDE_INT offset
,
15252 bool wback
, bool load
)
15254 unsigned int t
, t2
, n
;
15256 if (!reload_completed
)
15259 if (!offset_ok_for_ldrd_strd (offset
))
15266 if ((TARGET_THUMB2
)
15267 && ((wback
&& (n
== t
|| n
== t2
))
15268 || (t
== SP_REGNUM
)
15269 || (t
== PC_REGNUM
)
15270 || (t2
== SP_REGNUM
)
15271 || (t2
== PC_REGNUM
)
15272 || (!load
&& (n
== PC_REGNUM
))
15273 || (load
&& (t
== t2
))
15274 /* Triggers Cortex-M3 LDRD errata. */
15275 || (!wback
&& load
&& fix_cm3_ldrd
&& (n
== t
))))
15279 && ((wback
&& (n
== t
|| n
== t2
))
15280 || (t2
== PC_REGNUM
)
15281 || (t
% 2 != 0) /* First destination register is not even. */
15283 /* PC can be used as base register (for offset addressing only),
15284 but it is depricated. */
15285 || (n
== PC_REGNUM
)))
15291 /* Helper for gen_operands_ldrd_strd. Returns true iff the memory
15292 operand MEM's address contains an immediate offset from the base
15293 register and has no side effects, in which case it sets BASE and
15294 OFFSET accordingly. */
15296 mem_ok_for_ldrd_strd (rtx mem
, rtx
*base
, rtx
*offset
)
15300 gcc_assert (base
!= NULL
&& offset
!= NULL
);
15302 /* TODO: Handle more general memory operand patterns, such as
15303 PRE_DEC and PRE_INC. */
15305 if (side_effects_p (mem
))
15308 /* Can't deal with subregs. */
15309 if (GET_CODE (mem
) == SUBREG
)
15312 gcc_assert (MEM_P (mem
));
15314 *offset
= const0_rtx
;
15316 addr
= XEXP (mem
, 0);
15318 /* If addr isn't valid for DImode, then we can't handle it. */
15319 if (!arm_legitimate_address_p (DImode
, addr
,
15320 reload_in_progress
|| reload_completed
))
15328 else if (GET_CODE (addr
) == PLUS
|| GET_CODE (addr
) == MINUS
)
15330 *base
= XEXP (addr
, 0);
15331 *offset
= XEXP (addr
, 1);
15332 return (REG_P (*base
) && CONST_INT_P (*offset
));
15338 /* Called from a peephole2 to replace two word-size accesses with a
15339 single LDRD/STRD instruction. Returns true iff we can generate a
15340 new instruction sequence. That is, both accesses use the same base
15341 register and the gap between constant offsets is 4. This function
15342 may reorder its operands to match ldrd/strd RTL templates.
15343 OPERANDS are the operands found by the peephole matcher;
15344 OPERANDS[0,1] are register operands, and OPERANDS[2,3] are the
15345 corresponding memory operands. LOAD indicaates whether the access
15346 is load or store. CONST_STORE indicates a store of constant
15347 integer values held in OPERANDS[4,5] and assumes that the pattern
15348 is of length 4 insn, for the purpose of checking dead registers.
15349 COMMUTE indicates that register operands may be reordered. */
15351 gen_operands_ldrd_strd (rtx
*operands
, bool load
,
15352 bool const_store
, bool commute
)
15355 HOST_WIDE_INT offsets
[2], offset
;
15356 rtx base
= NULL_RTX
;
15357 rtx cur_base
, cur_offset
, tmp
;
15359 HARD_REG_SET regset
;
15361 gcc_assert (!const_store
|| !load
);
15362 /* Check that the memory references are immediate offsets from the
15363 same base register. Extract the base register, the destination
15364 registers, and the corresponding memory offsets. */
15365 for (i
= 0; i
< nops
; i
++)
15367 if (!mem_ok_for_ldrd_strd (operands
[nops
+i
], &cur_base
, &cur_offset
))
15372 else if (REGNO (base
) != REGNO (cur_base
))
15375 offsets
[i
] = INTVAL (cur_offset
);
15376 if (GET_CODE (operands
[i
]) == SUBREG
)
15378 tmp
= SUBREG_REG (operands
[i
]);
15379 gcc_assert (GET_MODE (operands
[i
]) == GET_MODE (tmp
));
15384 /* Make sure there is no dependency between the individual loads. */
15385 if (load
&& REGNO (operands
[0]) == REGNO (base
))
15386 return false; /* RAW */
15388 if (load
&& REGNO (operands
[0]) == REGNO (operands
[1]))
15389 return false; /* WAW */
15391 /* If the same input register is used in both stores
15392 when storing different constants, try to find a free register.
15393 For example, the code
15398 can be transformed into
15402 in Thumb mode assuming that r1 is free.
15403 For ARM mode do the same but only if the starting register
15404 can be made to be even. */
15406 && REGNO (operands
[0]) == REGNO (operands
[1])
15407 && INTVAL (operands
[4]) != INTVAL (operands
[5]))
15411 CLEAR_HARD_REG_SET (regset
);
15412 tmp
= peep2_find_free_register (0, 4, "r", SImode
, ®set
);
15413 if (tmp
== NULL_RTX
)
15416 /* Use the new register in the first load to ensure that
15417 if the original input register is not dead after peephole,
15418 then it will have the correct constant value. */
15421 else if (TARGET_ARM
)
15423 int regno
= REGNO (operands
[0]);
15424 if (!peep2_reg_dead_p (4, operands
[0]))
15426 /* When the input register is even and is not dead after the
15427 pattern, it has to hold the second constant but we cannot
15428 form a legal STRD in ARM mode with this register as the second
15430 if (regno
% 2 == 0)
15433 /* Is regno-1 free? */
15434 SET_HARD_REG_SET (regset
);
15435 CLEAR_HARD_REG_BIT(regset
, regno
- 1);
15436 tmp
= peep2_find_free_register (0, 4, "r", SImode
, ®set
);
15437 if (tmp
== NULL_RTX
)
15444 /* Find a DImode register. */
15445 CLEAR_HARD_REG_SET (regset
);
15446 tmp
= peep2_find_free_register (0, 4, "r", DImode
, ®set
);
15447 if (tmp
!= NULL_RTX
)
15449 operands
[0] = simplify_gen_subreg (SImode
, tmp
, DImode
, 0);
15450 operands
[1] = simplify_gen_subreg (SImode
, tmp
, DImode
, 4);
15454 /* Can we use the input register to form a DI register? */
15455 SET_HARD_REG_SET (regset
);
15456 CLEAR_HARD_REG_BIT(regset
,
15457 regno
% 2 == 0 ? regno
+ 1 : regno
- 1);
15458 tmp
= peep2_find_free_register (0, 4, "r", SImode
, ®set
);
15459 if (tmp
== NULL_RTX
)
15461 operands
[regno
% 2 == 1 ? 0 : 1] = tmp
;
15465 gcc_assert (operands
[0] != NULL_RTX
);
15466 gcc_assert (operands
[1] != NULL_RTX
);
15467 gcc_assert (REGNO (operands
[0]) % 2 == 0);
15468 gcc_assert (REGNO (operands
[1]) == REGNO (operands
[0]) + 1);
15472 /* Make sure the instructions are ordered with lower memory access first. */
15473 if (offsets
[0] > offsets
[1])
15475 gap
= offsets
[0] - offsets
[1];
15476 offset
= offsets
[1];
15478 /* Swap the instructions such that lower memory is accessed first. */
15479 std::swap (operands
[0], operands
[1]);
15480 std::swap (operands
[2], operands
[3]);
15482 std::swap (operands
[4], operands
[5]);
15486 gap
= offsets
[1] - offsets
[0];
15487 offset
= offsets
[0];
15490 /* Make sure accesses are to consecutive memory locations. */
15494 /* Make sure we generate legal instructions. */
15495 if (operands_ok_ldrd_strd (operands
[0], operands
[1], base
, offset
,
15499 /* In Thumb state, where registers are almost unconstrained, there
15500 is little hope to fix it. */
15504 if (load
&& commute
)
15506 /* Try reordering registers. */
15507 std::swap (operands
[0], operands
[1]);
15508 if (operands_ok_ldrd_strd (operands
[0], operands
[1], base
, offset
,
15515 /* If input registers are dead after this pattern, they can be
15516 reordered or replaced by other registers that are free in the
15517 current pattern. */
15518 if (!peep2_reg_dead_p (4, operands
[0])
15519 || !peep2_reg_dead_p (4, operands
[1]))
15522 /* Try to reorder the input registers. */
15523 /* For example, the code
15528 can be transformed into
15533 if (operands_ok_ldrd_strd (operands
[1], operands
[0], base
, offset
,
15536 std::swap (operands
[0], operands
[1]);
15540 /* Try to find a free DI register. */
15541 CLEAR_HARD_REG_SET (regset
);
15542 add_to_hard_reg_set (®set
, SImode
, REGNO (operands
[0]));
15543 add_to_hard_reg_set (®set
, SImode
, REGNO (operands
[1]));
15546 tmp
= peep2_find_free_register (0, 4, "r", DImode
, ®set
);
15547 if (tmp
== NULL_RTX
)
15550 /* DREG must be an even-numbered register in DImode.
15551 Split it into SI registers. */
15552 operands
[0] = simplify_gen_subreg (SImode
, tmp
, DImode
, 0);
15553 operands
[1] = simplify_gen_subreg (SImode
, tmp
, DImode
, 4);
15554 gcc_assert (operands
[0] != NULL_RTX
);
15555 gcc_assert (operands
[1] != NULL_RTX
);
15556 gcc_assert (REGNO (operands
[0]) % 2 == 0);
15557 gcc_assert (REGNO (operands
[0]) + 1 == REGNO (operands
[1]));
15559 return (operands_ok_ldrd_strd (operands
[0], operands
[1],
15571 /* Print a symbolic form of X to the debug file, F. */
15573 arm_print_value (FILE *f
, rtx x
)
15575 switch (GET_CODE (x
))
15578 fprintf (f
, HOST_WIDE_INT_PRINT_HEX
, INTVAL (x
));
15582 fprintf (f
, "<0x%lx,0x%lx>", (long)XWINT (x
, 2), (long)XWINT (x
, 3));
15590 for (i
= 0; i
< CONST_VECTOR_NUNITS (x
); i
++)
15592 fprintf (f
, HOST_WIDE_INT_PRINT_HEX
, INTVAL (CONST_VECTOR_ELT (x
, i
)));
15593 if (i
< (CONST_VECTOR_NUNITS (x
) - 1))
15601 fprintf (f
, "\"%s\"", XSTR (x
, 0));
15605 fprintf (f
, "`%s'", XSTR (x
, 0));
15609 fprintf (f
, "L%d", INSN_UID (XEXP (x
, 0)));
15613 arm_print_value (f
, XEXP (x
, 0));
15617 arm_print_value (f
, XEXP (x
, 0));
15619 arm_print_value (f
, XEXP (x
, 1));
15627 fprintf (f
, "????");
15632 /* Routines for manipulation of the constant pool. */
15634 /* Arm instructions cannot load a large constant directly into a
15635 register; they have to come from a pc relative load. The constant
15636 must therefore be placed in the addressable range of the pc
15637 relative load. Depending on the precise pc relative load
15638 instruction the range is somewhere between 256 bytes and 4k. This
15639 means that we often have to dump a constant inside a function, and
15640 generate code to branch around it.
15642 It is important to minimize this, since the branches will slow
15643 things down and make the code larger.
15645 Normally we can hide the table after an existing unconditional
15646 branch so that there is no interruption of the flow, but in the
15647 worst case the code looks like this:
15665 We fix this by performing a scan after scheduling, which notices
15666 which instructions need to have their operands fetched from the
15667 constant table and builds the table.
15669 The algorithm starts by building a table of all the constants that
15670 need fixing up and all the natural barriers in the function (places
15671 where a constant table can be dropped without breaking the flow).
15672 For each fixup we note how far the pc-relative replacement will be
15673 able to reach and the offset of the instruction into the function.
15675 Having built the table we then group the fixes together to form
15676 tables that are as large as possible (subject to addressing
15677 constraints) and emit each table of constants after the last
15678 barrier that is within range of all the instructions in the group.
15679 If a group does not contain a barrier, then we forcibly create one
15680 by inserting a jump instruction into the flow. Once the table has
15681 been inserted, the insns are then modified to reference the
15682 relevant entry in the pool.
15684 Possible enhancements to the algorithm (not implemented) are:
15686 1) For some processors and object formats, there may be benefit in
15687 aligning the pools to the start of cache lines; this alignment
15688 would need to be taken into account when calculating addressability
15691 /* These typedefs are located at the start of this file, so that
15692 they can be used in the prototypes there. This comment is to
15693 remind readers of that fact so that the following structures
15694 can be understood more easily.
15696 typedef struct minipool_node Mnode;
15697 typedef struct minipool_fixup Mfix; */
15699 struct minipool_node
15701 /* Doubly linked chain of entries. */
15704 /* The maximum offset into the code that this entry can be placed. While
15705 pushing fixes for forward references, all entries are sorted in order
15706 of increasing max_address. */
15707 HOST_WIDE_INT max_address
;
15708 /* Similarly for an entry inserted for a backwards ref. */
15709 HOST_WIDE_INT min_address
;
15710 /* The number of fixes referencing this entry. This can become zero
15711 if we "unpush" an entry. In this case we ignore the entry when we
15712 come to emit the code. */
15714 /* The offset from the start of the minipool. */
15715 HOST_WIDE_INT offset
;
15716 /* The value in table. */
15718 /* The mode of value. */
15720 /* The size of the value. With iWMMXt enabled
15721 sizes > 4 also imply an alignment of 8-bytes. */
15725 struct minipool_fixup
15729 HOST_WIDE_INT address
;
15735 HOST_WIDE_INT forwards
;
15736 HOST_WIDE_INT backwards
;
15739 /* Fixes less than a word need padding out to a word boundary. */
15740 #define MINIPOOL_FIX_SIZE(mode) \
15741 (GET_MODE_SIZE ((mode)) >= 4 ? GET_MODE_SIZE ((mode)) : 4)
15743 static Mnode
* minipool_vector_head
;
15744 static Mnode
* minipool_vector_tail
;
15745 static rtx_code_label
*minipool_vector_label
;
15746 static int minipool_pad
;
15748 /* The linked list of all minipool fixes required for this function. */
15749 Mfix
* minipool_fix_head
;
15750 Mfix
* minipool_fix_tail
;
15751 /* The fix entry for the current minipool, once it has been placed. */
15752 Mfix
* minipool_barrier
;
15754 #ifndef JUMP_TABLES_IN_TEXT_SECTION
15755 #define JUMP_TABLES_IN_TEXT_SECTION 0
15758 static HOST_WIDE_INT
15759 get_jump_table_size (rtx_jump_table_data
*insn
)
15761 /* ADDR_VECs only take room if read-only data does into the text
15763 if (JUMP_TABLES_IN_TEXT_SECTION
|| readonly_data_section
== text_section
)
15765 rtx body
= PATTERN (insn
);
15766 int elt
= GET_CODE (body
) == ADDR_DIFF_VEC
? 1 : 0;
15767 HOST_WIDE_INT size
;
15768 HOST_WIDE_INT modesize
;
15770 modesize
= GET_MODE_SIZE (GET_MODE (body
));
15771 size
= modesize
* XVECLEN (body
, elt
);
15775 /* Round up size of TBB table to a halfword boundary. */
15776 size
= (size
+ 1) & ~HOST_WIDE_INT_1
;
15779 /* No padding necessary for TBH. */
15782 /* Add two bytes for alignment on Thumb. */
15787 gcc_unreachable ();
15795 /* Return the maximum amount of padding that will be inserted before
15798 static HOST_WIDE_INT
15799 get_label_padding (rtx label
)
15801 HOST_WIDE_INT align
, min_insn_size
;
15803 align
= 1 << label_to_alignment (label
);
15804 min_insn_size
= TARGET_THUMB
? 2 : 4;
15805 return align
> min_insn_size
? align
- min_insn_size
: 0;
15808 /* Move a minipool fix MP from its current location to before MAX_MP.
15809 If MAX_MP is NULL, then MP doesn't need moving, but the addressing
15810 constraints may need updating. */
15812 move_minipool_fix_forward_ref (Mnode
*mp
, Mnode
*max_mp
,
15813 HOST_WIDE_INT max_address
)
15815 /* The code below assumes these are different. */
15816 gcc_assert (mp
!= max_mp
);
15818 if (max_mp
== NULL
)
15820 if (max_address
< mp
->max_address
)
15821 mp
->max_address
= max_address
;
15825 if (max_address
> max_mp
->max_address
- mp
->fix_size
)
15826 mp
->max_address
= max_mp
->max_address
- mp
->fix_size
;
15828 mp
->max_address
= max_address
;
15830 /* Unlink MP from its current position. Since max_mp is non-null,
15831 mp->prev must be non-null. */
15832 mp
->prev
->next
= mp
->next
;
15833 if (mp
->next
!= NULL
)
15834 mp
->next
->prev
= mp
->prev
;
15836 minipool_vector_tail
= mp
->prev
;
15838 /* Re-insert it before MAX_MP. */
15840 mp
->prev
= max_mp
->prev
;
15843 if (mp
->prev
!= NULL
)
15844 mp
->prev
->next
= mp
;
15846 minipool_vector_head
= mp
;
15849 /* Save the new entry. */
15852 /* Scan over the preceding entries and adjust their addresses as
15854 while (mp
->prev
!= NULL
15855 && mp
->prev
->max_address
> mp
->max_address
- mp
->prev
->fix_size
)
15857 mp
->prev
->max_address
= mp
->max_address
- mp
->prev
->fix_size
;
15864 /* Add a constant to the minipool for a forward reference. Returns the
15865 node added or NULL if the constant will not fit in this pool. */
15867 add_minipool_forward_ref (Mfix
*fix
)
15869 /* If set, max_mp is the first pool_entry that has a lower
15870 constraint than the one we are trying to add. */
15871 Mnode
* max_mp
= NULL
;
15872 HOST_WIDE_INT max_address
= fix
->address
+ fix
->forwards
- minipool_pad
;
15875 /* If the minipool starts before the end of FIX->INSN then this FIX
15876 can not be placed into the current pool. Furthermore, adding the
15877 new constant pool entry may cause the pool to start FIX_SIZE bytes
15879 if (minipool_vector_head
&&
15880 (fix
->address
+ get_attr_length (fix
->insn
)
15881 >= minipool_vector_head
->max_address
- fix
->fix_size
))
15884 /* Scan the pool to see if a constant with the same value has
15885 already been added. While we are doing this, also note the
15886 location where we must insert the constant if it doesn't already
15888 for (mp
= minipool_vector_head
; mp
!= NULL
; mp
= mp
->next
)
15890 if (GET_CODE (fix
->value
) == GET_CODE (mp
->value
)
15891 && fix
->mode
== mp
->mode
15892 && (!LABEL_P (fix
->value
)
15893 || (CODE_LABEL_NUMBER (fix
->value
)
15894 == CODE_LABEL_NUMBER (mp
->value
)))
15895 && rtx_equal_p (fix
->value
, mp
->value
))
15897 /* More than one fix references this entry. */
15899 return move_minipool_fix_forward_ref (mp
, max_mp
, max_address
);
15902 /* Note the insertion point if necessary. */
15904 && mp
->max_address
> max_address
)
15907 /* If we are inserting an 8-bytes aligned quantity and
15908 we have not already found an insertion point, then
15909 make sure that all such 8-byte aligned quantities are
15910 placed at the start of the pool. */
15911 if (ARM_DOUBLEWORD_ALIGN
15913 && fix
->fix_size
>= 8
15914 && mp
->fix_size
< 8)
15917 max_address
= mp
->max_address
;
15921 /* The value is not currently in the minipool, so we need to create
15922 a new entry for it. If MAX_MP is NULL, the entry will be put on
15923 the end of the list since the placement is less constrained than
15924 any existing entry. Otherwise, we insert the new fix before
15925 MAX_MP and, if necessary, adjust the constraints on the other
15928 mp
->fix_size
= fix
->fix_size
;
15929 mp
->mode
= fix
->mode
;
15930 mp
->value
= fix
->value
;
15932 /* Not yet required for a backwards ref. */
15933 mp
->min_address
= -65536;
15935 if (max_mp
== NULL
)
15937 mp
->max_address
= max_address
;
15939 mp
->prev
= minipool_vector_tail
;
15941 if (mp
->prev
== NULL
)
15943 minipool_vector_head
= mp
;
15944 minipool_vector_label
= gen_label_rtx ();
15947 mp
->prev
->next
= mp
;
15949 minipool_vector_tail
= mp
;
15953 if (max_address
> max_mp
->max_address
- mp
->fix_size
)
15954 mp
->max_address
= max_mp
->max_address
- mp
->fix_size
;
15956 mp
->max_address
= max_address
;
15959 mp
->prev
= max_mp
->prev
;
15961 if (mp
->prev
!= NULL
)
15962 mp
->prev
->next
= mp
;
15964 minipool_vector_head
= mp
;
15967 /* Save the new entry. */
15970 /* Scan over the preceding entries and adjust their addresses as
15972 while (mp
->prev
!= NULL
15973 && mp
->prev
->max_address
> mp
->max_address
- mp
->prev
->fix_size
)
15975 mp
->prev
->max_address
= mp
->max_address
- mp
->prev
->fix_size
;
15983 move_minipool_fix_backward_ref (Mnode
*mp
, Mnode
*min_mp
,
15984 HOST_WIDE_INT min_address
)
15986 HOST_WIDE_INT offset
;
15988 /* The code below assumes these are different. */
15989 gcc_assert (mp
!= min_mp
);
15991 if (min_mp
== NULL
)
15993 if (min_address
> mp
->min_address
)
15994 mp
->min_address
= min_address
;
15998 /* We will adjust this below if it is too loose. */
15999 mp
->min_address
= min_address
;
16001 /* Unlink MP from its current position. Since min_mp is non-null,
16002 mp->next must be non-null. */
16003 mp
->next
->prev
= mp
->prev
;
16004 if (mp
->prev
!= NULL
)
16005 mp
->prev
->next
= mp
->next
;
16007 minipool_vector_head
= mp
->next
;
16009 /* Reinsert it after MIN_MP. */
16011 mp
->next
= min_mp
->next
;
16013 if (mp
->next
!= NULL
)
16014 mp
->next
->prev
= mp
;
16016 minipool_vector_tail
= mp
;
16022 for (mp
= minipool_vector_head
; mp
!= NULL
; mp
= mp
->next
)
16024 mp
->offset
= offset
;
16025 if (mp
->refcount
> 0)
16026 offset
+= mp
->fix_size
;
16028 if (mp
->next
&& mp
->next
->min_address
< mp
->min_address
+ mp
->fix_size
)
16029 mp
->next
->min_address
= mp
->min_address
+ mp
->fix_size
;
16035 /* Add a constant to the minipool for a backward reference. Returns the
16036 node added or NULL if the constant will not fit in this pool.
16038 Note that the code for insertion for a backwards reference can be
16039 somewhat confusing because the calculated offsets for each fix do
16040 not take into account the size of the pool (which is still under
16043 add_minipool_backward_ref (Mfix
*fix
)
16045 /* If set, min_mp is the last pool_entry that has a lower constraint
16046 than the one we are trying to add. */
16047 Mnode
*min_mp
= NULL
;
16048 /* This can be negative, since it is only a constraint. */
16049 HOST_WIDE_INT min_address
= fix
->address
- fix
->backwards
;
16052 /* If we can't reach the current pool from this insn, or if we can't
16053 insert this entry at the end of the pool without pushing other
16054 fixes out of range, then we don't try. This ensures that we
16055 can't fail later on. */
16056 if (min_address
>= minipool_barrier
->address
16057 || (minipool_vector_tail
->min_address
+ fix
->fix_size
16058 >= minipool_barrier
->address
))
16061 /* Scan the pool to see if a constant with the same value has
16062 already been added. While we are doing this, also note the
16063 location where we must insert the constant if it doesn't already
16065 for (mp
= minipool_vector_tail
; mp
!= NULL
; mp
= mp
->prev
)
16067 if (GET_CODE (fix
->value
) == GET_CODE (mp
->value
)
16068 && fix
->mode
== mp
->mode
16069 && (!LABEL_P (fix
->value
)
16070 || (CODE_LABEL_NUMBER (fix
->value
)
16071 == CODE_LABEL_NUMBER (mp
->value
)))
16072 && rtx_equal_p (fix
->value
, mp
->value
)
16073 /* Check that there is enough slack to move this entry to the
16074 end of the table (this is conservative). */
16075 && (mp
->max_address
16076 > (minipool_barrier
->address
16077 + minipool_vector_tail
->offset
16078 + minipool_vector_tail
->fix_size
)))
16081 return move_minipool_fix_backward_ref (mp
, min_mp
, min_address
);
16084 if (min_mp
!= NULL
)
16085 mp
->min_address
+= fix
->fix_size
;
16088 /* Note the insertion point if necessary. */
16089 if (mp
->min_address
< min_address
)
16091 /* For now, we do not allow the insertion of 8-byte alignment
16092 requiring nodes anywhere but at the start of the pool. */
16093 if (ARM_DOUBLEWORD_ALIGN
16094 && fix
->fix_size
>= 8 && mp
->fix_size
< 8)
16099 else if (mp
->max_address
16100 < minipool_barrier
->address
+ mp
->offset
+ fix
->fix_size
)
16102 /* Inserting before this entry would push the fix beyond
16103 its maximum address (which can happen if we have
16104 re-located a forwards fix); force the new fix to come
16106 if (ARM_DOUBLEWORD_ALIGN
16107 && fix
->fix_size
>= 8 && mp
->fix_size
< 8)
16112 min_address
= mp
->min_address
+ fix
->fix_size
;
16115 /* Do not insert a non-8-byte aligned quantity before 8-byte
16116 aligned quantities. */
16117 else if (ARM_DOUBLEWORD_ALIGN
16118 && fix
->fix_size
< 8
16119 && mp
->fix_size
>= 8)
16122 min_address
= mp
->min_address
+ fix
->fix_size
;
16127 /* We need to create a new entry. */
16129 mp
->fix_size
= fix
->fix_size
;
16130 mp
->mode
= fix
->mode
;
16131 mp
->value
= fix
->value
;
16133 mp
->max_address
= minipool_barrier
->address
+ 65536;
16135 mp
->min_address
= min_address
;
16137 if (min_mp
== NULL
)
16140 mp
->next
= minipool_vector_head
;
16142 if (mp
->next
== NULL
)
16144 minipool_vector_tail
= mp
;
16145 minipool_vector_label
= gen_label_rtx ();
16148 mp
->next
->prev
= mp
;
16150 minipool_vector_head
= mp
;
16154 mp
->next
= min_mp
->next
;
16158 if (mp
->next
!= NULL
)
16159 mp
->next
->prev
= mp
;
16161 minipool_vector_tail
= mp
;
16164 /* Save the new entry. */
16172 /* Scan over the following entries and adjust their offsets. */
16173 while (mp
->next
!= NULL
)
16175 if (mp
->next
->min_address
< mp
->min_address
+ mp
->fix_size
)
16176 mp
->next
->min_address
= mp
->min_address
+ mp
->fix_size
;
16179 mp
->next
->offset
= mp
->offset
+ mp
->fix_size
;
16181 mp
->next
->offset
= mp
->offset
;
16190 assign_minipool_offsets (Mfix
*barrier
)
16192 HOST_WIDE_INT offset
= 0;
16195 minipool_barrier
= barrier
;
16197 for (mp
= minipool_vector_head
; mp
!= NULL
; mp
= mp
->next
)
16199 mp
->offset
= offset
;
16201 if (mp
->refcount
> 0)
16202 offset
+= mp
->fix_size
;
16206 /* Output the literal table */
16208 dump_minipool (rtx_insn
*scan
)
16214 if (ARM_DOUBLEWORD_ALIGN
)
16215 for (mp
= minipool_vector_head
; mp
!= NULL
; mp
= mp
->next
)
16216 if (mp
->refcount
> 0 && mp
->fix_size
>= 8)
16223 fprintf (dump_file
,
16224 ";; Emitting minipool after insn %u; address %ld; align %d (bytes)\n",
16225 INSN_UID (scan
), (unsigned long) minipool_barrier
->address
, align64
? 8 : 4);
16227 scan
= emit_label_after (gen_label_rtx (), scan
);
16228 scan
= emit_insn_after (align64
? gen_align_8 () : gen_align_4 (), scan
);
16229 scan
= emit_label_after (minipool_vector_label
, scan
);
16231 for (mp
= minipool_vector_head
; mp
!= NULL
; mp
= nmp
)
16233 if (mp
->refcount
> 0)
16237 fprintf (dump_file
,
16238 ";; Offset %u, min %ld, max %ld ",
16239 (unsigned) mp
->offset
, (unsigned long) mp
->min_address
,
16240 (unsigned long) mp
->max_address
);
16241 arm_print_value (dump_file
, mp
->value
);
16242 fputc ('\n', dump_file
);
16245 rtx val
= copy_rtx (mp
->value
);
16247 switch (GET_MODE_SIZE (mp
->mode
))
16249 #ifdef HAVE_consttable_1
16251 scan
= emit_insn_after (gen_consttable_1 (val
), scan
);
16255 #ifdef HAVE_consttable_2
16257 scan
= emit_insn_after (gen_consttable_2 (val
), scan
);
16261 #ifdef HAVE_consttable_4
16263 scan
= emit_insn_after (gen_consttable_4 (val
), scan
);
16267 #ifdef HAVE_consttable_8
16269 scan
= emit_insn_after (gen_consttable_8 (val
), scan
);
16273 #ifdef HAVE_consttable_16
16275 scan
= emit_insn_after (gen_consttable_16 (val
), scan
);
16280 gcc_unreachable ();
16288 minipool_vector_head
= minipool_vector_tail
= NULL
;
16289 scan
= emit_insn_after (gen_consttable_end (), scan
);
16290 scan
= emit_barrier_after (scan
);
16293 /* Return the cost of forcibly inserting a barrier after INSN. */
16295 arm_barrier_cost (rtx_insn
*insn
)
16297 /* Basing the location of the pool on the loop depth is preferable,
16298 but at the moment, the basic block information seems to be
16299 corrupt by this stage of the compilation. */
16300 int base_cost
= 50;
16301 rtx_insn
*next
= next_nonnote_insn (insn
);
16303 if (next
!= NULL
&& LABEL_P (next
))
16306 switch (GET_CODE (insn
))
16309 /* It will always be better to place the table before the label, rather
16318 return base_cost
- 10;
16321 return base_cost
+ 10;
16325 /* Find the best place in the insn stream in the range
16326 (FIX->address,MAX_ADDRESS) to forcibly insert a minipool barrier.
16327 Create the barrier by inserting a jump and add a new fix entry for
16330 create_fix_barrier (Mfix
*fix
, HOST_WIDE_INT max_address
)
16332 HOST_WIDE_INT count
= 0;
16333 rtx_barrier
*barrier
;
16334 rtx_insn
*from
= fix
->insn
;
16335 /* The instruction after which we will insert the jump. */
16336 rtx_insn
*selected
= NULL
;
16338 /* The address at which the jump instruction will be placed. */
16339 HOST_WIDE_INT selected_address
;
16341 HOST_WIDE_INT max_count
= max_address
- fix
->address
;
16342 rtx_code_label
*label
= gen_label_rtx ();
16344 selected_cost
= arm_barrier_cost (from
);
16345 selected_address
= fix
->address
;
16347 while (from
&& count
< max_count
)
16349 rtx_jump_table_data
*tmp
;
16352 /* This code shouldn't have been called if there was a natural barrier
16354 gcc_assert (!BARRIER_P (from
));
16356 /* Count the length of this insn. This must stay in sync with the
16357 code that pushes minipool fixes. */
16358 if (LABEL_P (from
))
16359 count
+= get_label_padding (from
);
16361 count
+= get_attr_length (from
);
16363 /* If there is a jump table, add its length. */
16364 if (tablejump_p (from
, NULL
, &tmp
))
16366 count
+= get_jump_table_size (tmp
);
16368 /* Jump tables aren't in a basic block, so base the cost on
16369 the dispatch insn. If we select this location, we will
16370 still put the pool after the table. */
16371 new_cost
= arm_barrier_cost (from
);
16373 if (count
< max_count
16374 && (!selected
|| new_cost
<= selected_cost
))
16377 selected_cost
= new_cost
;
16378 selected_address
= fix
->address
+ count
;
16381 /* Continue after the dispatch table. */
16382 from
= NEXT_INSN (tmp
);
16386 new_cost
= arm_barrier_cost (from
);
16388 if (count
< max_count
16389 && (!selected
|| new_cost
<= selected_cost
))
16392 selected_cost
= new_cost
;
16393 selected_address
= fix
->address
+ count
;
16396 from
= NEXT_INSN (from
);
16399 /* Make sure that we found a place to insert the jump. */
16400 gcc_assert (selected
);
16402 /* Make sure we do not split a call and its corresponding
16403 CALL_ARG_LOCATION note. */
16404 if (CALL_P (selected
))
16406 rtx_insn
*next
= NEXT_INSN (selected
);
16407 if (next
&& NOTE_P (next
)
16408 && NOTE_KIND (next
) == NOTE_INSN_CALL_ARG_LOCATION
)
16412 /* Create a new JUMP_INSN that branches around a barrier. */
16413 from
= emit_jump_insn_after (gen_jump (label
), selected
);
16414 JUMP_LABEL (from
) = label
;
16415 barrier
= emit_barrier_after (from
);
16416 emit_label_after (label
, barrier
);
16418 /* Create a minipool barrier entry for the new barrier. */
16419 new_fix
= (Mfix
*) obstack_alloc (&minipool_obstack
, sizeof (* new_fix
));
16420 new_fix
->insn
= barrier
;
16421 new_fix
->address
= selected_address
;
16422 new_fix
->next
= fix
->next
;
16423 fix
->next
= new_fix
;
16428 /* Record that there is a natural barrier in the insn stream at
16431 push_minipool_barrier (rtx_insn
*insn
, HOST_WIDE_INT address
)
16433 Mfix
* fix
= (Mfix
*) obstack_alloc (&minipool_obstack
, sizeof (* fix
));
16436 fix
->address
= address
;
16439 if (minipool_fix_head
!= NULL
)
16440 minipool_fix_tail
->next
= fix
;
16442 minipool_fix_head
= fix
;
16444 minipool_fix_tail
= fix
;
16447 /* Record INSN, which will need fixing up to load a value from the
16448 minipool. ADDRESS is the offset of the insn since the start of the
16449 function; LOC is a pointer to the part of the insn which requires
16450 fixing; VALUE is the constant that must be loaded, which is of type
16453 push_minipool_fix (rtx_insn
*insn
, HOST_WIDE_INT address
, rtx
*loc
,
16454 machine_mode mode
, rtx value
)
16456 gcc_assert (!arm_disable_literal_pool
);
16457 Mfix
* fix
= (Mfix
*) obstack_alloc (&minipool_obstack
, sizeof (* fix
));
16460 fix
->address
= address
;
16463 fix
->fix_size
= MINIPOOL_FIX_SIZE (mode
);
16464 fix
->value
= value
;
16465 fix
->forwards
= get_attr_pool_range (insn
);
16466 fix
->backwards
= get_attr_neg_pool_range (insn
);
16467 fix
->minipool
= NULL
;
16469 /* If an insn doesn't have a range defined for it, then it isn't
16470 expecting to be reworked by this code. Better to stop now than
16471 to generate duff assembly code. */
16472 gcc_assert (fix
->forwards
|| fix
->backwards
);
16474 /* If an entry requires 8-byte alignment then assume all constant pools
16475 require 4 bytes of padding. Trying to do this later on a per-pool
16476 basis is awkward because existing pool entries have to be modified. */
16477 if (ARM_DOUBLEWORD_ALIGN
&& fix
->fix_size
>= 8)
16482 fprintf (dump_file
,
16483 ";; %smode fixup for i%d; addr %lu, range (%ld,%ld): ",
16484 GET_MODE_NAME (mode
),
16485 INSN_UID (insn
), (unsigned long) address
,
16486 -1 * (long)fix
->backwards
, (long)fix
->forwards
);
16487 arm_print_value (dump_file
, fix
->value
);
16488 fprintf (dump_file
, "\n");
16491 /* Add it to the chain of fixes. */
16494 if (minipool_fix_head
!= NULL
)
16495 minipool_fix_tail
->next
= fix
;
16497 minipool_fix_head
= fix
;
16499 minipool_fix_tail
= fix
;
16502 /* Return maximum allowed cost of synthesizing a 64-bit constant VAL inline.
16503 Returns the number of insns needed, or 99 if we always want to synthesize
16506 arm_max_const_double_inline_cost ()
16508 return ((optimize_size
|| arm_ld_sched
) ? 3 : 4);
16511 /* Return the cost of synthesizing a 64-bit constant VAL inline.
16512 Returns the number of insns needed, or 99 if we don't know how to
16515 arm_const_double_inline_cost (rtx val
)
16517 rtx lowpart
, highpart
;
16520 mode
= GET_MODE (val
);
16522 if (mode
== VOIDmode
)
16525 gcc_assert (GET_MODE_SIZE (mode
) == 8);
16527 lowpart
= gen_lowpart (SImode
, val
);
16528 highpart
= gen_highpart_mode (SImode
, mode
, val
);
16530 gcc_assert (CONST_INT_P (lowpart
));
16531 gcc_assert (CONST_INT_P (highpart
));
16533 return (arm_gen_constant (SET
, SImode
, NULL_RTX
, INTVAL (lowpart
),
16534 NULL_RTX
, NULL_RTX
, 0, 0)
16535 + arm_gen_constant (SET
, SImode
, NULL_RTX
, INTVAL (highpart
),
16536 NULL_RTX
, NULL_RTX
, 0, 0));
16539 /* Cost of loading a SImode constant. */
16541 arm_const_inline_cost (enum rtx_code code
, rtx val
)
16543 return arm_gen_constant (code
, SImode
, NULL_RTX
, INTVAL (val
),
16544 NULL_RTX
, NULL_RTX
, 1, 0);
16547 /* Return true if it is worthwhile to split a 64-bit constant into two
16548 32-bit operations. This is the case if optimizing for size, or
16549 if we have load delay slots, or if one 32-bit part can be done with
16550 a single data operation. */
16552 arm_const_double_by_parts (rtx val
)
16554 machine_mode mode
= GET_MODE (val
);
16557 if (optimize_size
|| arm_ld_sched
)
16560 if (mode
== VOIDmode
)
16563 part
= gen_highpart_mode (SImode
, mode
, val
);
16565 gcc_assert (CONST_INT_P (part
));
16567 if (const_ok_for_arm (INTVAL (part
))
16568 || const_ok_for_arm (~INTVAL (part
)))
16571 part
= gen_lowpart (SImode
, val
);
16573 gcc_assert (CONST_INT_P (part
));
16575 if (const_ok_for_arm (INTVAL (part
))
16576 || const_ok_for_arm (~INTVAL (part
)))
16582 /* Return true if it is possible to inline both the high and low parts
16583 of a 64-bit constant into 32-bit data processing instructions. */
16585 arm_const_double_by_immediates (rtx val
)
16587 machine_mode mode
= GET_MODE (val
);
16590 if (mode
== VOIDmode
)
16593 part
= gen_highpart_mode (SImode
, mode
, val
);
16595 gcc_assert (CONST_INT_P (part
));
16597 if (!const_ok_for_arm (INTVAL (part
)))
16600 part
= gen_lowpart (SImode
, val
);
16602 gcc_assert (CONST_INT_P (part
));
16604 if (!const_ok_for_arm (INTVAL (part
)))
16610 /* Scan INSN and note any of its operands that need fixing.
16611 If DO_PUSHES is false we do not actually push any of the fixups
16614 note_invalid_constants (rtx_insn
*insn
, HOST_WIDE_INT address
, int do_pushes
)
16618 extract_constrain_insn (insn
);
16620 if (recog_data
.n_alternatives
== 0)
16623 /* Fill in recog_op_alt with information about the constraints of
16625 preprocess_constraints (insn
);
16627 const operand_alternative
*op_alt
= which_op_alt ();
16628 for (opno
= 0; opno
< recog_data
.n_operands
; opno
++)
16630 /* Things we need to fix can only occur in inputs. */
16631 if (recog_data
.operand_type
[opno
] != OP_IN
)
16634 /* If this alternative is a memory reference, then any mention
16635 of constants in this alternative is really to fool reload
16636 into allowing us to accept one there. We need to fix them up
16637 now so that we output the right code. */
16638 if (op_alt
[opno
].memory_ok
)
16640 rtx op
= recog_data
.operand
[opno
];
16642 if (CONSTANT_P (op
))
16645 push_minipool_fix (insn
, address
, recog_data
.operand_loc
[opno
],
16646 recog_data
.operand_mode
[opno
], op
);
16648 else if (MEM_P (op
)
16649 && GET_CODE (XEXP (op
, 0)) == SYMBOL_REF
16650 && CONSTANT_POOL_ADDRESS_P (XEXP (op
, 0)))
16654 rtx cop
= avoid_constant_pool_reference (op
);
16656 /* Casting the address of something to a mode narrower
16657 than a word can cause avoid_constant_pool_reference()
16658 to return the pool reference itself. That's no good to
16659 us here. Lets just hope that we can use the
16660 constant pool value directly. */
16662 cop
= get_pool_constant (XEXP (op
, 0));
16664 push_minipool_fix (insn
, address
,
16665 recog_data
.operand_loc
[opno
],
16666 recog_data
.operand_mode
[opno
], cop
);
16676 /* This function computes the clear mask and PADDING_BITS_TO_CLEAR for structs
16677 and unions in the context of ARMv8-M Security Extensions. It is used as a
16678 helper function for both 'cmse_nonsecure_call' and 'cmse_nonsecure_entry'
16679 functions. The PADDING_BITS_TO_CLEAR pointer can be the base to either one
16680 or four masks, depending on whether it is being computed for a
16681 'cmse_nonsecure_entry' return value or a 'cmse_nonsecure_call' argument
16682 respectively. The tree for the type of the argument or a field within an
16683 argument is passed in ARG_TYPE, the current register this argument or field
16684 starts in is kept in the pointer REGNO and updated accordingly, the bit this
16685 argument or field starts at is passed in STARTING_BIT and the last used bit
16686 is kept in LAST_USED_BIT which is also updated accordingly. */
16688 static unsigned HOST_WIDE_INT
16689 comp_not_to_clear_mask_str_un (tree arg_type
, int * regno
,
16690 uint32_t * padding_bits_to_clear
,
16691 unsigned starting_bit
, int * last_used_bit
)
16694 unsigned HOST_WIDE_INT not_to_clear_reg_mask
= 0;
16696 if (TREE_CODE (arg_type
) == RECORD_TYPE
)
16698 unsigned current_bit
= starting_bit
;
16700 long int offset
, size
;
16703 field
= TYPE_FIELDS (arg_type
);
16706 /* The offset within a structure is always an offset from
16707 the start of that structure. Make sure we take that into the
16708 calculation of the register based offset that we use here. */
16709 offset
= starting_bit
;
16710 offset
+= TREE_INT_CST_ELT (DECL_FIELD_BIT_OFFSET (field
), 0);
16713 /* This is the actual size of the field, for bitfields this is the
16714 bitfield width and not the container size. */
16715 size
= TREE_INT_CST_ELT (DECL_SIZE (field
), 0);
16717 if (*last_used_bit
!= offset
)
16719 if (offset
< *last_used_bit
)
16721 /* This field's offset is before the 'last_used_bit', that
16722 means this field goes on the next register. So we need to
16723 pad the rest of the current register and increase the
16724 register number. */
16726 mask
= ((uint32_t)-1) - ((uint32_t) 1 << *last_used_bit
);
16729 padding_bits_to_clear
[*regno
] |= mask
;
16730 not_to_clear_reg_mask
|= HOST_WIDE_INT_1U
<< *regno
;
16735 /* Otherwise we pad the bits between the last field's end and
16736 the start of the new field. */
16739 mask
= ((uint32_t)-1) >> (32 - offset
);
16740 mask
-= ((uint32_t) 1 << *last_used_bit
) - 1;
16741 padding_bits_to_clear
[*regno
] |= mask
;
16743 current_bit
= offset
;
16746 /* Calculate further padding bits for inner structs/unions too. */
16747 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field
)))
16749 *last_used_bit
= current_bit
;
16750 not_to_clear_reg_mask
16751 |= comp_not_to_clear_mask_str_un (TREE_TYPE (field
), regno
,
16752 padding_bits_to_clear
, offset
,
16757 /* Update 'current_bit' with this field's size. If the
16758 'current_bit' lies in a subsequent register, update 'regno' and
16759 reset 'current_bit' to point to the current bit in that new
16761 current_bit
+= size
;
16762 while (current_bit
>= 32)
16765 not_to_clear_reg_mask
|= HOST_WIDE_INT_1U
<< *regno
;
16768 *last_used_bit
= current_bit
;
16771 field
= TREE_CHAIN (field
);
16773 not_to_clear_reg_mask
|= HOST_WIDE_INT_1U
<< *regno
;
16775 else if (TREE_CODE (arg_type
) == UNION_TYPE
)
16777 tree field
, field_t
;
16778 int i
, regno_t
, field_size
;
16782 uint32_t padding_bits_to_clear_res
[NUM_ARG_REGS
]
16783 = {-1, -1, -1, -1};
16785 /* To compute the padding bits in a union we only consider bits as
16786 padding bits if they are always either a padding bit or fall outside a
16787 fields size for all fields in the union. */
16788 field
= TYPE_FIELDS (arg_type
);
16791 uint32_t padding_bits_to_clear_t
[NUM_ARG_REGS
]
16792 = {0U, 0U, 0U, 0U};
16793 int last_used_bit_t
= *last_used_bit
;
16795 field_t
= TREE_TYPE (field
);
16797 /* If the field's type is either a record or a union make sure to
16798 compute their padding bits too. */
16799 if (RECORD_OR_UNION_TYPE_P (field_t
))
16800 not_to_clear_reg_mask
16801 |= comp_not_to_clear_mask_str_un (field_t
, ®no_t
,
16802 &padding_bits_to_clear_t
[0],
16803 starting_bit
, &last_used_bit_t
);
16806 field_size
= TREE_INT_CST_ELT (DECL_SIZE (field
), 0);
16807 regno_t
= (field_size
/ 32) + *regno
;
16808 last_used_bit_t
= (starting_bit
+ field_size
) % 32;
16811 for (i
= *regno
; i
< regno_t
; i
++)
16813 /* For all but the last register used by this field only keep the
16814 padding bits that were padding bits in this field. */
16815 padding_bits_to_clear_res
[i
] &= padding_bits_to_clear_t
[i
];
16818 /* For the last register, keep all padding bits that were padding
16819 bits in this field and any padding bits that are still valid
16820 as padding bits but fall outside of this field's size. */
16821 mask
= (((uint32_t) -1) - ((uint32_t) 1 << last_used_bit_t
)) + 1;
16822 padding_bits_to_clear_res
[regno_t
]
16823 &= padding_bits_to_clear_t
[regno_t
] | mask
;
16825 /* Update the maximum size of the fields in terms of registers used
16826 ('max_reg') and the 'last_used_bit' in said register. */
16827 if (max_reg
< regno_t
)
16830 max_bit
= last_used_bit_t
;
16832 else if (max_reg
== regno_t
&& max_bit
< last_used_bit_t
)
16833 max_bit
= last_used_bit_t
;
16835 field
= TREE_CHAIN (field
);
16838 /* Update the current padding_bits_to_clear using the intersection of the
16839 padding bits of all the fields. */
16840 for (i
=*regno
; i
< max_reg
; i
++)
16841 padding_bits_to_clear
[i
] |= padding_bits_to_clear_res
[i
];
16843 /* Do not keep trailing padding bits, we do not know yet whether this
16844 is the end of the argument. */
16845 mask
= ((uint32_t) 1 << max_bit
) - 1;
16846 padding_bits_to_clear
[max_reg
]
16847 |= padding_bits_to_clear_res
[max_reg
] & mask
;
16850 *last_used_bit
= max_bit
;
16853 /* This function should only be used for structs and unions. */
16854 gcc_unreachable ();
16856 return not_to_clear_reg_mask
;
16859 /* In the context of ARMv8-M Security Extensions, this function is used for both
16860 'cmse_nonsecure_call' and 'cmse_nonsecure_entry' functions to compute what
16861 registers are used when returning or passing arguments, which is then
16862 returned as a mask. It will also compute a mask to indicate padding/unused
16863 bits for each of these registers, and passes this through the
16864 PADDING_BITS_TO_CLEAR pointer. The tree of the argument type is passed in
16865 ARG_TYPE, the rtl representation of the argument is passed in ARG_RTX and
16866 the starting register used to pass this argument or return value is passed
16867 in REGNO. It makes use of 'comp_not_to_clear_mask_str_un' to compute these
16868 for struct and union types. */
16870 static unsigned HOST_WIDE_INT
16871 compute_not_to_clear_mask (tree arg_type
, rtx arg_rtx
, int regno
,
16872 uint32_t * padding_bits_to_clear
)
16875 int last_used_bit
= 0;
16876 unsigned HOST_WIDE_INT not_to_clear_mask
;
16878 if (RECORD_OR_UNION_TYPE_P (arg_type
))
16881 = comp_not_to_clear_mask_str_un (arg_type
, ®no
,
16882 padding_bits_to_clear
, 0,
16886 /* If the 'last_used_bit' is not zero, that means we are still using a
16887 part of the last 'regno'. In such cases we must clear the trailing
16888 bits. Otherwise we are not using regno and we should mark it as to
16890 if (last_used_bit
!= 0)
16891 padding_bits_to_clear
[regno
]
16892 |= ((uint32_t)-1) - ((uint32_t) 1 << last_used_bit
) + 1;
16894 not_to_clear_mask
&= ~(HOST_WIDE_INT_1U
<< regno
);
16898 not_to_clear_mask
= 0;
16899 /* We are not dealing with structs nor unions. So these arguments may be
16900 passed in floating point registers too. In some cases a BLKmode is
16901 used when returning or passing arguments in multiple VFP registers. */
16902 if (GET_MODE (arg_rtx
) == BLKmode
)
16907 /* This should really only occur when dealing with the hard-float
16909 gcc_assert (TARGET_HARD_FLOAT_ABI
);
16911 for (i
= 0; i
< XVECLEN (arg_rtx
, 0); i
++)
16913 reg
= XEXP (XVECEXP (arg_rtx
, 0, i
), 0);
16914 gcc_assert (REG_P (reg
));
16916 not_to_clear_mask
|= HOST_WIDE_INT_1U
<< REGNO (reg
);
16918 /* If we are dealing with DF mode, make sure we don't
16919 clear either of the registers it addresses. */
16920 arg_regs
= ARM_NUM_REGS (GET_MODE (reg
));
16923 unsigned HOST_WIDE_INT mask
;
16924 mask
= HOST_WIDE_INT_1U
<< (REGNO (reg
) + arg_regs
);
16925 mask
-= HOST_WIDE_INT_1U
<< REGNO (reg
);
16926 not_to_clear_mask
|= mask
;
16932 /* Otherwise we can rely on the MODE to determine how many registers
16933 are being used by this argument. */
16934 int arg_regs
= ARM_NUM_REGS (GET_MODE (arg_rtx
));
16935 not_to_clear_mask
|= HOST_WIDE_INT_1U
<< REGNO (arg_rtx
);
16938 unsigned HOST_WIDE_INT
16939 mask
= HOST_WIDE_INT_1U
<< (REGNO (arg_rtx
) + arg_regs
);
16940 mask
-= HOST_WIDE_INT_1U
<< REGNO (arg_rtx
);
16941 not_to_clear_mask
|= mask
;
16946 return not_to_clear_mask
;
16949 /* Clears caller saved registers not used to pass arguments before a
16950 cmse_nonsecure_call. Saving, clearing and restoring of callee saved
16951 registers is done in __gnu_cmse_nonsecure_call libcall.
16952 See libgcc/config/arm/cmse_nonsecure_call.S. */
16955 cmse_nonsecure_call_clear_caller_saved (void)
16959 FOR_EACH_BB_FN (bb
, cfun
)
16963 FOR_BB_INSNS (bb
, insn
)
16965 uint64_t to_clear_mask
, float_mask
;
16967 rtx pat
, call
, unspec
, reg
, cleared_reg
, tmp
;
16968 unsigned int regno
, maxregno
;
16970 CUMULATIVE_ARGS args_so_far_v
;
16971 cumulative_args_t args_so_far
;
16972 tree arg_type
, fntype
;
16973 bool using_r4
, first_param
= true;
16974 function_args_iterator args_iter
;
16975 uint32_t padding_bits_to_clear
[4] = {0U, 0U, 0U, 0U};
16976 uint32_t * padding_bits_to_clear_ptr
= &padding_bits_to_clear
[0];
16978 if (!NONDEBUG_INSN_P (insn
))
16981 if (!CALL_P (insn
))
16984 pat
= PATTERN (insn
);
16985 gcc_assert (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 0);
16986 call
= XVECEXP (pat
, 0, 0);
16988 /* Get the real call RTX if the insn sets a value, ie. returns. */
16989 if (GET_CODE (call
) == SET
)
16990 call
= SET_SRC (call
);
16992 /* Check if it is a cmse_nonsecure_call. */
16993 unspec
= XEXP (call
, 0);
16994 if (GET_CODE (unspec
) != UNSPEC
16995 || XINT (unspec
, 1) != UNSPEC_NONSECURE_MEM
)
16998 /* Determine the caller-saved registers we need to clear. */
16999 to_clear_mask
= (1LL << (NUM_ARG_REGS
)) - 1;
17000 maxregno
= NUM_ARG_REGS
- 1;
17001 /* Only look at the caller-saved floating point registers in case of
17002 -mfloat-abi=hard. For -mfloat-abi=softfp we will be using the
17003 lazy store and loads which clear both caller- and callee-saved
17005 if (TARGET_HARD_FLOAT_ABI
)
17007 float_mask
= (1LL << (D7_VFP_REGNUM
+ 1)) - 1;
17008 float_mask
&= ~((1LL << FIRST_VFP_REGNUM
) - 1);
17009 to_clear_mask
|= float_mask
;
17010 maxregno
= D7_VFP_REGNUM
;
17013 /* Make sure the register used to hold the function address is not
17015 address
= RTVEC_ELT (XVEC (unspec
, 0), 0);
17016 gcc_assert (MEM_P (address
));
17017 gcc_assert (REG_P (XEXP (address
, 0)));
17018 to_clear_mask
&= ~(1LL << REGNO (XEXP (address
, 0)));
17020 /* Set basic block of call insn so that df rescan is performed on
17021 insns inserted here. */
17022 set_block_for_insn (insn
, bb
);
17023 df_set_flags (DF_DEFER_INSN_RESCAN
);
17026 /* Make sure the scheduler doesn't schedule other insns beyond
17028 emit_insn (gen_blockage ());
17030 /* Walk through all arguments and clear registers appropriately.
17032 fntype
= TREE_TYPE (MEM_EXPR (address
));
17033 arm_init_cumulative_args (&args_so_far_v
, fntype
, NULL_RTX
,
17035 args_so_far
= pack_cumulative_args (&args_so_far_v
);
17036 FOREACH_FUNCTION_ARGS (fntype
, arg_type
, args_iter
)
17039 machine_mode arg_mode
= TYPE_MODE (arg_type
);
17041 if (VOID_TYPE_P (arg_type
))
17045 arm_function_arg_advance (args_so_far
, arg_mode
, arg_type
,
17048 arg_rtx
= arm_function_arg (args_so_far
, arg_mode
, arg_type
,
17050 gcc_assert (REG_P (arg_rtx
));
17052 &= ~compute_not_to_clear_mask (arg_type
, arg_rtx
,
17054 padding_bits_to_clear_ptr
);
17056 first_param
= false;
17059 /* Clear padding bits where needed. */
17060 cleared_reg
= XEXP (address
, 0);
17061 reg
= gen_rtx_REG (SImode
, IP_REGNUM
);
17063 for (regno
= R0_REGNUM
; regno
< NUM_ARG_REGS
; regno
++)
17065 if (padding_bits_to_clear
[regno
] == 0)
17068 /* If this is a Thumb-1 target copy the address of the function
17069 we are calling from 'r4' into 'ip' such that we can use r4 to
17070 clear the unused bits in the arguments. */
17071 if (TARGET_THUMB1
&& !using_r4
)
17075 emit_move_insn (gen_rtx_REG (SImode
, IP_REGNUM
),
17079 tmp
= GEN_INT ((((~padding_bits_to_clear
[regno
]) << 16u) >> 16u));
17080 emit_move_insn (reg
, tmp
);
17081 /* Also fill the top half of the negated
17082 padding_bits_to_clear. */
17083 if (((~padding_bits_to_clear
[regno
]) >> 16) > 0)
17085 tmp
= GEN_INT ((~padding_bits_to_clear
[regno
]) >> 16);
17086 emit_insn (gen_rtx_SET (gen_rtx_ZERO_EXTRACT (SImode
, reg
,
17092 emit_insn (gen_andsi3 (gen_rtx_REG (SImode
, regno
),
17093 gen_rtx_REG (SImode
, regno
),
17098 emit_move_insn (cleared_reg
,
17099 gen_rtx_REG (SImode
, IP_REGNUM
));
17101 /* We use right shift and left shift to clear the LSB of the address
17102 we jump to instead of using bic, to avoid having to use an extra
17103 register on Thumb-1. */
17104 tmp
= gen_rtx_LSHIFTRT (SImode
, cleared_reg
, const1_rtx
);
17105 emit_insn (gen_rtx_SET (cleared_reg
, tmp
));
17106 tmp
= gen_rtx_ASHIFT (SImode
, cleared_reg
, const1_rtx
);
17107 emit_insn (gen_rtx_SET (cleared_reg
, tmp
));
17109 /* Clearing all registers that leak before doing a non-secure
17111 for (regno
= R0_REGNUM
; regno
<= maxregno
; regno
++)
17113 if (!(to_clear_mask
& (1LL << regno
)))
17116 /* If regno is an even vfp register and its successor is also to
17117 be cleared, use vmov. */
17118 if (IS_VFP_REGNUM (regno
))
17120 if (TARGET_VFP_DOUBLE
17121 && VFP_REGNO_OK_FOR_DOUBLE (regno
)
17122 && to_clear_mask
& (1LL << (regno
+ 1)))
17123 emit_move_insn (gen_rtx_REG (DFmode
, regno
++),
17124 CONST0_RTX (DFmode
));
17126 emit_move_insn (gen_rtx_REG (SFmode
, regno
),
17127 CONST0_RTX (SFmode
));
17130 emit_move_insn (gen_rtx_REG (SImode
, regno
), cleared_reg
);
17133 seq
= get_insns ();
17135 emit_insn_before (seq
, insn
);
17141 /* Rewrite move insn into subtract of 0 if the condition codes will
17142 be useful in next conditional jump insn. */
17145 thumb1_reorg (void)
17149 FOR_EACH_BB_FN (bb
, cfun
)
17152 rtx cmp
, op0
, op1
, set
= NULL
;
17153 rtx_insn
*prev
, *insn
= BB_END (bb
);
17154 bool insn_clobbered
= false;
17156 while (insn
!= BB_HEAD (bb
) && !NONDEBUG_INSN_P (insn
))
17157 insn
= PREV_INSN (insn
);
17159 /* Find the last cbranchsi4_insn in basic block BB. */
17160 if (insn
== BB_HEAD (bb
)
17161 || INSN_CODE (insn
) != CODE_FOR_cbranchsi4_insn
)
17164 /* Get the register with which we are comparing. */
17165 cmp
= XEXP (SET_SRC (PATTERN (insn
)), 0);
17166 op0
= XEXP (cmp
, 0);
17167 op1
= XEXP (cmp
, 1);
17169 /* Check that comparison is against ZERO. */
17170 if (!CONST_INT_P (op1
) || INTVAL (op1
) != 0)
17173 /* Find the first flag setting insn before INSN in basic block BB. */
17174 gcc_assert (insn
!= BB_HEAD (bb
));
17175 for (prev
= PREV_INSN (insn
);
17177 && prev
!= BB_HEAD (bb
)
17179 || DEBUG_INSN_P (prev
)
17180 || ((set
= single_set (prev
)) != NULL
17181 && get_attr_conds (prev
) == CONDS_NOCOND
)));
17182 prev
= PREV_INSN (prev
))
17184 if (reg_set_p (op0
, prev
))
17185 insn_clobbered
= true;
17188 /* Skip if op0 is clobbered by insn other than prev. */
17189 if (insn_clobbered
)
17195 dest
= SET_DEST (set
);
17196 src
= SET_SRC (set
);
17197 if (!low_register_operand (dest
, SImode
)
17198 || !low_register_operand (src
, SImode
))
17201 /* Rewrite move into subtract of 0 if its operand is compared with ZERO
17202 in INSN. Both src and dest of the move insn are checked. */
17203 if (REGNO (op0
) == REGNO (src
) || REGNO (op0
) == REGNO (dest
))
17205 dest
= copy_rtx (dest
);
17206 src
= copy_rtx (src
);
17207 src
= gen_rtx_MINUS (SImode
, src
, const0_rtx
);
17208 PATTERN (prev
) = gen_rtx_SET (dest
, src
);
17209 INSN_CODE (prev
) = -1;
17210 /* Set test register in INSN to dest. */
17211 XEXP (cmp
, 0) = copy_rtx (dest
);
17212 INSN_CODE (insn
) = -1;
17217 /* Convert instructions to their cc-clobbering variant if possible, since
17218 that allows us to use smaller encodings. */
17221 thumb2_reorg (void)
17226 INIT_REG_SET (&live
);
17228 /* We are freeing block_for_insn in the toplev to keep compatibility
17229 with old MDEP_REORGS that are not CFG based. Recompute it now. */
17230 compute_bb_for_insn ();
17233 enum Convert_Action
{SKIP
, CONV
, SWAP_CONV
};
17235 FOR_EACH_BB_FN (bb
, cfun
)
17237 if ((current_tune
->disparage_flag_setting_t16_encodings
17238 == tune_params::DISPARAGE_FLAGS_ALL
)
17239 && optimize_bb_for_speed_p (bb
))
17243 Convert_Action action
= SKIP
;
17244 Convert_Action action_for_partial_flag_setting
17245 = ((current_tune
->disparage_flag_setting_t16_encodings
17246 != tune_params::DISPARAGE_FLAGS_NEITHER
)
17247 && optimize_bb_for_speed_p (bb
))
17250 COPY_REG_SET (&live
, DF_LR_OUT (bb
));
17251 df_simulate_initialize_backwards (bb
, &live
);
17252 FOR_BB_INSNS_REVERSE (bb
, insn
)
17254 if (NONJUMP_INSN_P (insn
)
17255 && !REGNO_REG_SET_P (&live
, CC_REGNUM
)
17256 && GET_CODE (PATTERN (insn
)) == SET
)
17259 rtx pat
= PATTERN (insn
);
17260 rtx dst
= XEXP (pat
, 0);
17261 rtx src
= XEXP (pat
, 1);
17262 rtx op0
= NULL_RTX
, op1
= NULL_RTX
;
17264 if (UNARY_P (src
) || BINARY_P (src
))
17265 op0
= XEXP (src
, 0);
17267 if (BINARY_P (src
))
17268 op1
= XEXP (src
, 1);
17270 if (low_register_operand (dst
, SImode
))
17272 switch (GET_CODE (src
))
17275 /* Adding two registers and storing the result
17276 in the first source is already a 16-bit
17278 if (rtx_equal_p (dst
, op0
)
17279 && register_operand (op1
, SImode
))
17282 if (low_register_operand (op0
, SImode
))
17284 /* ADDS <Rd>,<Rn>,<Rm> */
17285 if (low_register_operand (op1
, SImode
))
17287 /* ADDS <Rdn>,#<imm8> */
17288 /* SUBS <Rdn>,#<imm8> */
17289 else if (rtx_equal_p (dst
, op0
)
17290 && CONST_INT_P (op1
)
17291 && IN_RANGE (INTVAL (op1
), -255, 255))
17293 /* ADDS <Rd>,<Rn>,#<imm3> */
17294 /* SUBS <Rd>,<Rn>,#<imm3> */
17295 else if (CONST_INT_P (op1
)
17296 && IN_RANGE (INTVAL (op1
), -7, 7))
17299 /* ADCS <Rd>, <Rn> */
17300 else if (GET_CODE (XEXP (src
, 0)) == PLUS
17301 && rtx_equal_p (XEXP (XEXP (src
, 0), 0), dst
)
17302 && low_register_operand (XEXP (XEXP (src
, 0), 1),
17304 && COMPARISON_P (op1
)
17305 && cc_register (XEXP (op1
, 0), VOIDmode
)
17306 && maybe_get_arm_condition_code (op1
) == ARM_CS
17307 && XEXP (op1
, 1) == const0_rtx
)
17312 /* RSBS <Rd>,<Rn>,#0
17313 Not handled here: see NEG below. */
17314 /* SUBS <Rd>,<Rn>,#<imm3>
17316 Not handled here: see PLUS above. */
17317 /* SUBS <Rd>,<Rn>,<Rm> */
17318 if (low_register_operand (op0
, SImode
)
17319 && low_register_operand (op1
, SImode
))
17324 /* MULS <Rdm>,<Rn>,<Rdm>
17325 As an exception to the rule, this is only used
17326 when optimizing for size since MULS is slow on all
17327 known implementations. We do not even want to use
17328 MULS in cold code, if optimizing for speed, so we
17329 test the global flag here. */
17330 if (!optimize_size
)
17332 /* Fall through. */
17336 /* ANDS <Rdn>,<Rm> */
17337 if (rtx_equal_p (dst
, op0
)
17338 && low_register_operand (op1
, SImode
))
17339 action
= action_for_partial_flag_setting
;
17340 else if (rtx_equal_p (dst
, op1
)
17341 && low_register_operand (op0
, SImode
))
17342 action
= action_for_partial_flag_setting
== SKIP
17343 ? SKIP
: SWAP_CONV
;
17349 /* ASRS <Rdn>,<Rm> */
17350 /* LSRS <Rdn>,<Rm> */
17351 /* LSLS <Rdn>,<Rm> */
17352 if (rtx_equal_p (dst
, op0
)
17353 && low_register_operand (op1
, SImode
))
17354 action
= action_for_partial_flag_setting
;
17355 /* ASRS <Rd>,<Rm>,#<imm5> */
17356 /* LSRS <Rd>,<Rm>,#<imm5> */
17357 /* LSLS <Rd>,<Rm>,#<imm5> */
17358 else if (low_register_operand (op0
, SImode
)
17359 && CONST_INT_P (op1
)
17360 && IN_RANGE (INTVAL (op1
), 0, 31))
17361 action
= action_for_partial_flag_setting
;
17365 /* RORS <Rdn>,<Rm> */
17366 if (rtx_equal_p (dst
, op0
)
17367 && low_register_operand (op1
, SImode
))
17368 action
= action_for_partial_flag_setting
;
17372 /* MVNS <Rd>,<Rm> */
17373 if (low_register_operand (op0
, SImode
))
17374 action
= action_for_partial_flag_setting
;
17378 /* NEGS <Rd>,<Rm> (a.k.a RSBS) */
17379 if (low_register_operand (op0
, SImode
))
17384 /* MOVS <Rd>,#<imm8> */
17385 if (CONST_INT_P (src
)
17386 && IN_RANGE (INTVAL (src
), 0, 255))
17387 action
= action_for_partial_flag_setting
;
17391 /* MOVS and MOV<c> with registers have different
17392 encodings, so are not relevant here. */
17400 if (action
!= SKIP
)
17402 rtx ccreg
= gen_rtx_REG (CCmode
, CC_REGNUM
);
17403 rtx clobber
= gen_rtx_CLOBBER (VOIDmode
, ccreg
);
17406 if (action
== SWAP_CONV
)
17408 src
= copy_rtx (src
);
17409 XEXP (src
, 0) = op1
;
17410 XEXP (src
, 1) = op0
;
17411 pat
= gen_rtx_SET (dst
, src
);
17412 vec
= gen_rtvec (2, pat
, clobber
);
17414 else /* action == CONV */
17415 vec
= gen_rtvec (2, pat
, clobber
);
17417 PATTERN (insn
) = gen_rtx_PARALLEL (VOIDmode
, vec
);
17418 INSN_CODE (insn
) = -1;
17422 if (NONDEBUG_INSN_P (insn
))
17423 df_simulate_one_insn_backwards (bb
, insn
, &live
);
17427 CLEAR_REG_SET (&live
);
17430 /* Gcc puts the pool in the wrong place for ARM, since we can only
17431 load addresses a limited distance around the pc. We do some
17432 special munging to move the constant pool values to the correct
17433 point in the code. */
17438 HOST_WIDE_INT address
= 0;
17442 cmse_nonsecure_call_clear_caller_saved ();
17445 else if (TARGET_THUMB2
)
17448 /* Ensure all insns that must be split have been split at this point.
17449 Otherwise, the pool placement code below may compute incorrect
17450 insn lengths. Note that when optimizing, all insns have already
17451 been split at this point. */
17453 split_all_insns_noflow ();
17455 /* Make sure we do not attempt to create a literal pool even though it should
17456 no longer be necessary to create any. */
17457 if (arm_disable_literal_pool
)
17460 minipool_fix_head
= minipool_fix_tail
= NULL
;
17462 /* The first insn must always be a note, or the code below won't
17463 scan it properly. */
17464 insn
= get_insns ();
17465 gcc_assert (NOTE_P (insn
));
17468 /* Scan all the insns and record the operands that will need fixing. */
17469 for (insn
= next_nonnote_insn (insn
); insn
; insn
= next_nonnote_insn (insn
))
17471 if (BARRIER_P (insn
))
17472 push_minipool_barrier (insn
, address
);
17473 else if (INSN_P (insn
))
17475 rtx_jump_table_data
*table
;
17477 note_invalid_constants (insn
, address
, true);
17478 address
+= get_attr_length (insn
);
17480 /* If the insn is a vector jump, add the size of the table
17481 and skip the table. */
17482 if (tablejump_p (insn
, NULL
, &table
))
17484 address
+= get_jump_table_size (table
);
17488 else if (LABEL_P (insn
))
17489 /* Add the worst-case padding due to alignment. We don't add
17490 the _current_ padding because the minipool insertions
17491 themselves might change it. */
17492 address
+= get_label_padding (insn
);
17495 fix
= minipool_fix_head
;
17497 /* Now scan the fixups and perform the required changes. */
17502 Mfix
* last_added_fix
;
17503 Mfix
* last_barrier
= NULL
;
17506 /* Skip any further barriers before the next fix. */
17507 while (fix
&& BARRIER_P (fix
->insn
))
17510 /* No more fixes. */
17514 last_added_fix
= NULL
;
17516 for (ftmp
= fix
; ftmp
; ftmp
= ftmp
->next
)
17518 if (BARRIER_P (ftmp
->insn
))
17520 if (ftmp
->address
>= minipool_vector_head
->max_address
)
17523 last_barrier
= ftmp
;
17525 else if ((ftmp
->minipool
= add_minipool_forward_ref (ftmp
)) == NULL
)
17528 last_added_fix
= ftmp
; /* Keep track of the last fix added. */
17531 /* If we found a barrier, drop back to that; any fixes that we
17532 could have reached but come after the barrier will now go in
17533 the next mini-pool. */
17534 if (last_barrier
!= NULL
)
17536 /* Reduce the refcount for those fixes that won't go into this
17538 for (fdel
= last_barrier
->next
;
17539 fdel
&& fdel
!= ftmp
;
17542 fdel
->minipool
->refcount
--;
17543 fdel
->minipool
= NULL
;
17546 ftmp
= last_barrier
;
17550 /* ftmp is first fix that we can't fit into this pool and
17551 there no natural barriers that we could use. Insert a
17552 new barrier in the code somewhere between the previous
17553 fix and this one, and arrange to jump around it. */
17554 HOST_WIDE_INT max_address
;
17556 /* The last item on the list of fixes must be a barrier, so
17557 we can never run off the end of the list of fixes without
17558 last_barrier being set. */
17561 max_address
= minipool_vector_head
->max_address
;
17562 /* Check that there isn't another fix that is in range that
17563 we couldn't fit into this pool because the pool was
17564 already too large: we need to put the pool before such an
17565 instruction. The pool itself may come just after the
17566 fix because create_fix_barrier also allows space for a
17567 jump instruction. */
17568 if (ftmp
->address
< max_address
)
17569 max_address
= ftmp
->address
+ 1;
17571 last_barrier
= create_fix_barrier (last_added_fix
, max_address
);
17574 assign_minipool_offsets (last_barrier
);
17578 if (!BARRIER_P (ftmp
->insn
)
17579 && ((ftmp
->minipool
= add_minipool_backward_ref (ftmp
))
17586 /* Scan over the fixes we have identified for this pool, fixing them
17587 up and adding the constants to the pool itself. */
17588 for (this_fix
= fix
; this_fix
&& ftmp
!= this_fix
;
17589 this_fix
= this_fix
->next
)
17590 if (!BARRIER_P (this_fix
->insn
))
17593 = plus_constant (Pmode
,
17594 gen_rtx_LABEL_REF (VOIDmode
,
17595 minipool_vector_label
),
17596 this_fix
->minipool
->offset
);
17597 *this_fix
->loc
= gen_rtx_MEM (this_fix
->mode
, addr
);
17600 dump_minipool (last_barrier
->insn
);
17604 /* From now on we must synthesize any constants that we can't handle
17605 directly. This can happen if the RTL gets split during final
17606 instruction generation. */
17607 cfun
->machine
->after_arm_reorg
= 1;
17609 /* Free the minipool memory. */
17610 obstack_free (&minipool_obstack
, minipool_startobj
);
17613 /* Routines to output assembly language. */
17615 /* Return string representation of passed in real value. */
17616 static const char *
17617 fp_const_from_val (REAL_VALUE_TYPE
*r
)
17619 if (!fp_consts_inited
)
17622 gcc_assert (real_equal (r
, &value_fp0
));
17626 /* OPERANDS[0] is the entire list of insns that constitute pop,
17627 OPERANDS[1] is the base register, RETURN_PC is true iff return insn
17628 is in the list, UPDATE is true iff the list contains explicit
17629 update of base register. */
17631 arm_output_multireg_pop (rtx
*operands
, bool return_pc
, rtx cond
, bool reverse
,
17637 const char *conditional
;
17638 int num_saves
= XVECLEN (operands
[0], 0);
17639 unsigned int regno
;
17640 unsigned int regno_base
= REGNO (operands
[1]);
17641 bool interrupt_p
= IS_INTERRUPT (arm_current_func_type ());
17644 offset
+= update
? 1 : 0;
17645 offset
+= return_pc
? 1 : 0;
17647 /* Is the base register in the list? */
17648 for (i
= offset
; i
< num_saves
; i
++)
17650 regno
= REGNO (XEXP (XVECEXP (operands
[0], 0, i
), 0));
17651 /* If SP is in the list, then the base register must be SP. */
17652 gcc_assert ((regno
!= SP_REGNUM
) || (regno_base
== SP_REGNUM
));
17653 /* If base register is in the list, there must be no explicit update. */
17654 if (regno
== regno_base
)
17655 gcc_assert (!update
);
17658 conditional
= reverse
? "%?%D0" : "%?%d0";
17659 /* Can't use POP if returning from an interrupt. */
17660 if ((regno_base
== SP_REGNUM
) && update
&& !(interrupt_p
&& return_pc
))
17661 sprintf (pattern
, "pop%s\t{", conditional
);
17664 /* Output ldmfd when the base register is SP, otherwise output ldmia.
17665 It's just a convention, their semantics are identical. */
17666 if (regno_base
== SP_REGNUM
)
17667 sprintf (pattern
, "ldmfd%s\t", conditional
);
17669 sprintf (pattern
, "ldmia%s\t", conditional
);
17671 sprintf (pattern
, "ldm%s\t", conditional
);
17673 strcat (pattern
, reg_names
[regno_base
]);
17675 strcat (pattern
, "!, {");
17677 strcat (pattern
, ", {");
17680 /* Output the first destination register. */
17682 reg_names
[REGNO (XEXP (XVECEXP (operands
[0], 0, offset
), 0))]);
17684 /* Output the rest of the destination registers. */
17685 for (i
= offset
+ 1; i
< num_saves
; i
++)
17687 strcat (pattern
, ", ");
17689 reg_names
[REGNO (XEXP (XVECEXP (operands
[0], 0, i
), 0))]);
17692 strcat (pattern
, "}");
17694 if (interrupt_p
&& return_pc
)
17695 strcat (pattern
, "^");
17697 output_asm_insn (pattern
, &cond
);
17701 /* Output the assembly for a store multiple. */
17704 vfp_output_vstmd (rtx
* operands
)
17710 rtx addr_reg
= REG_P (XEXP (operands
[0], 0))
17711 ? XEXP (operands
[0], 0)
17712 : XEXP (XEXP (operands
[0], 0), 0);
17713 bool push_p
= REGNO (addr_reg
) == SP_REGNUM
;
17716 strcpy (pattern
, "vpush%?.64\t{%P1");
17718 strcpy (pattern
, "vstmdb%?.64\t%m0!, {%P1");
17720 p
= strlen (pattern
);
17722 gcc_assert (REG_P (operands
[1]));
17724 base
= (REGNO (operands
[1]) - FIRST_VFP_REGNUM
) / 2;
17725 for (i
= 1; i
< XVECLEN (operands
[2], 0); i
++)
17727 p
+= sprintf (&pattern
[p
], ", d%d", base
+ i
);
17729 strcpy (&pattern
[p
], "}");
17731 output_asm_insn (pattern
, operands
);
17736 /* Emit RTL to save block of VFP register pairs to the stack. Returns the
17737 number of bytes pushed. */
17740 vfp_emit_fstmd (int base_reg
, int count
)
17747 /* Workaround ARM10 VFPr1 bug. Data corruption can occur when exactly two
17748 register pairs are stored by a store multiple insn. We avoid this
17749 by pushing an extra pair. */
17750 if (count
== 2 && !arm_arch6
)
17752 if (base_reg
== LAST_VFP_REGNUM
- 3)
17757 /* FSTMD may not store more than 16 doubleword registers at once. Split
17758 larger stores into multiple parts (up to a maximum of two, in
17763 /* NOTE: base_reg is an internal register number, so each D register
17765 saved
= vfp_emit_fstmd (base_reg
+ 32, count
- 16);
17766 saved
+= vfp_emit_fstmd (base_reg
, 16);
17770 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (count
));
17771 dwarf
= gen_rtx_SEQUENCE (VOIDmode
, rtvec_alloc (count
+ 1));
17773 reg
= gen_rtx_REG (DFmode
, base_reg
);
17776 XVECEXP (par
, 0, 0)
17777 = gen_rtx_SET (gen_frame_mem
17779 gen_rtx_PRE_MODIFY (Pmode
,
17782 (Pmode
, stack_pointer_rtx
,
17785 gen_rtx_UNSPEC (BLKmode
,
17786 gen_rtvec (1, reg
),
17787 UNSPEC_PUSH_MULT
));
17789 tmp
= gen_rtx_SET (stack_pointer_rtx
,
17790 plus_constant (Pmode
, stack_pointer_rtx
, -(count
* 8)));
17791 RTX_FRAME_RELATED_P (tmp
) = 1;
17792 XVECEXP (dwarf
, 0, 0) = tmp
;
17794 tmp
= gen_rtx_SET (gen_frame_mem (DFmode
, stack_pointer_rtx
), reg
);
17795 RTX_FRAME_RELATED_P (tmp
) = 1;
17796 XVECEXP (dwarf
, 0, 1) = tmp
;
17798 for (i
= 1; i
< count
; i
++)
17800 reg
= gen_rtx_REG (DFmode
, base_reg
);
17802 XVECEXP (par
, 0, i
) = gen_rtx_USE (VOIDmode
, reg
);
17804 tmp
= gen_rtx_SET (gen_frame_mem (DFmode
,
17805 plus_constant (Pmode
,
17809 RTX_FRAME_RELATED_P (tmp
) = 1;
17810 XVECEXP (dwarf
, 0, i
+ 1) = tmp
;
17813 par
= emit_insn (par
);
17814 add_reg_note (par
, REG_FRAME_RELATED_EXPR
, dwarf
);
17815 RTX_FRAME_RELATED_P (par
) = 1;
17820 /* Returns true if -mcmse has been passed and the function pointed to by 'addr'
17821 has the cmse_nonsecure_call attribute and returns false otherwise. */
17824 detect_cmse_nonsecure_call (tree addr
)
17829 tree fntype
= TREE_TYPE (addr
);
17830 if (use_cmse
&& lookup_attribute ("cmse_nonsecure_call",
17831 TYPE_ATTRIBUTES (fntype
)))
17837 /* Emit a call instruction with pattern PAT. ADDR is the address of
17838 the call target. */
17841 arm_emit_call_insn (rtx pat
, rtx addr
, bool sibcall
)
17845 insn
= emit_call_insn (pat
);
17847 /* The PIC register is live on entry to VxWorks PIC PLT entries.
17848 If the call might use such an entry, add a use of the PIC register
17849 to the instruction's CALL_INSN_FUNCTION_USAGE. */
17850 if (TARGET_VXWORKS_RTP
17853 && GET_CODE (addr
) == SYMBOL_REF
17854 && (SYMBOL_REF_DECL (addr
)
17855 ? !targetm
.binds_local_p (SYMBOL_REF_DECL (addr
))
17856 : !SYMBOL_REF_LOCAL_P (addr
)))
17858 require_pic_register ();
17859 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), cfun
->machine
->pic_reg
);
17862 if (TARGET_AAPCS_BASED
)
17864 /* For AAPCS, IP and CC can be clobbered by veneers inserted by the
17865 linker. We need to add an IP clobber to allow setting
17866 TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS to true. A CC clobber
17867 is not needed since it's a fixed register. */
17868 rtx
*fusage
= &CALL_INSN_FUNCTION_USAGE (insn
);
17869 clobber_reg (fusage
, gen_rtx_REG (word_mode
, IP_REGNUM
));
17873 /* Output a 'call' insn. */
17875 output_call (rtx
*operands
)
17877 gcc_assert (!arm_arch5
); /* Patterns should call blx <reg> directly. */
17879 /* Handle calls to lr using ip (which may be clobbered in subr anyway). */
17880 if (REGNO (operands
[0]) == LR_REGNUM
)
17882 operands
[0] = gen_rtx_REG (SImode
, IP_REGNUM
);
17883 output_asm_insn ("mov%?\t%0, %|lr", operands
);
17886 output_asm_insn ("mov%?\t%|lr, %|pc", operands
);
17888 if (TARGET_INTERWORK
|| arm_arch4t
)
17889 output_asm_insn ("bx%?\t%0", operands
);
17891 output_asm_insn ("mov%?\t%|pc, %0", operands
);
17896 /* Output a move from arm registers to arm registers of a long double
17897 OPERANDS[0] is the destination.
17898 OPERANDS[1] is the source. */
17900 output_mov_long_double_arm_from_arm (rtx
*operands
)
17902 /* We have to be careful here because the two might overlap. */
17903 int dest_start
= REGNO (operands
[0]);
17904 int src_start
= REGNO (operands
[1]);
17908 if (dest_start
< src_start
)
17910 for (i
= 0; i
< 3; i
++)
17912 ops
[0] = gen_rtx_REG (SImode
, dest_start
+ i
);
17913 ops
[1] = gen_rtx_REG (SImode
, src_start
+ i
);
17914 output_asm_insn ("mov%?\t%0, %1", ops
);
17919 for (i
= 2; i
>= 0; i
--)
17921 ops
[0] = gen_rtx_REG (SImode
, dest_start
+ i
);
17922 ops
[1] = gen_rtx_REG (SImode
, src_start
+ i
);
17923 output_asm_insn ("mov%?\t%0, %1", ops
);
17931 arm_emit_movpair (rtx dest
, rtx src
)
17933 /* If the src is an immediate, simplify it. */
17934 if (CONST_INT_P (src
))
17936 HOST_WIDE_INT val
= INTVAL (src
);
17937 emit_set_insn (dest
, GEN_INT (val
& 0x0000ffff));
17938 if ((val
>> 16) & 0x0000ffff)
17940 emit_set_insn (gen_rtx_ZERO_EXTRACT (SImode
, dest
, GEN_INT (16),
17942 GEN_INT ((val
>> 16) & 0x0000ffff));
17943 rtx_insn
*insn
= get_last_insn ();
17944 set_unique_reg_note (insn
, REG_EQUAL
, copy_rtx (src
));
17948 emit_set_insn (dest
, gen_rtx_HIGH (SImode
, src
));
17949 emit_set_insn (dest
, gen_rtx_LO_SUM (SImode
, dest
, src
));
17950 rtx_insn
*insn
= get_last_insn ();
17951 set_unique_reg_note (insn
, REG_EQUAL
, copy_rtx (src
));
17954 /* Output a move between double words. It must be REG<-MEM
17957 output_move_double (rtx
*operands
, bool emit
, int *count
)
17959 enum rtx_code code0
= GET_CODE (operands
[0]);
17960 enum rtx_code code1
= GET_CODE (operands
[1]);
17965 /* The only case when this might happen is when
17966 you are looking at the length of a DImode instruction
17967 that has an invalid constant in it. */
17968 if (code0
== REG
&& code1
!= MEM
)
17970 gcc_assert (!emit
);
17977 unsigned int reg0
= REGNO (operands
[0]);
17979 otherops
[0] = gen_rtx_REG (SImode
, 1 + reg0
);
17981 gcc_assert (code1
== MEM
); /* Constraints should ensure this. */
17983 switch (GET_CODE (XEXP (operands
[1], 0)))
17990 && !(fix_cm3_ldrd
&& reg0
== REGNO(XEXP (operands
[1], 0))))
17991 output_asm_insn ("ldrd%?\t%0, [%m1]", operands
);
17993 output_asm_insn ("ldmia%?\t%m1, %M0", operands
);
17998 gcc_assert (TARGET_LDRD
);
18000 output_asm_insn ("ldrd%?\t%0, [%m1, #8]!", operands
);
18007 output_asm_insn ("ldrd%?\t%0, [%m1, #-8]!", operands
);
18009 output_asm_insn ("ldmdb%?\t%m1!, %M0", operands
);
18017 output_asm_insn ("ldrd%?\t%0, [%m1], #8", operands
);
18019 output_asm_insn ("ldmia%?\t%m1!, %M0", operands
);
18024 gcc_assert (TARGET_LDRD
);
18026 output_asm_insn ("ldrd%?\t%0, [%m1], #-8", operands
);
18031 /* Autoicrement addressing modes should never have overlapping
18032 base and destination registers, and overlapping index registers
18033 are already prohibited, so this doesn't need to worry about
18035 otherops
[0] = operands
[0];
18036 otherops
[1] = XEXP (XEXP (XEXP (operands
[1], 0), 1), 0);
18037 otherops
[2] = XEXP (XEXP (XEXP (operands
[1], 0), 1), 1);
18039 if (GET_CODE (XEXP (operands
[1], 0)) == PRE_MODIFY
)
18041 if (reg_overlap_mentioned_p (otherops
[0], otherops
[2]))
18043 /* Registers overlap so split out the increment. */
18046 output_asm_insn ("add%?\t%1, %1, %2", otherops
);
18047 output_asm_insn ("ldrd%?\t%0, [%1] @split", otherops
);
18054 /* Use a single insn if we can.
18055 FIXME: IWMMXT allows offsets larger than ldrd can
18056 handle, fix these up with a pair of ldr. */
18058 || !CONST_INT_P (otherops
[2])
18059 || (INTVAL (otherops
[2]) > -256
18060 && INTVAL (otherops
[2]) < 256))
18063 output_asm_insn ("ldrd%?\t%0, [%1, %2]!", otherops
);
18069 output_asm_insn ("ldr%?\t%0, [%1, %2]!", otherops
);
18070 output_asm_insn ("ldr%?\t%H0, [%1, #4]", otherops
);
18080 /* Use a single insn if we can.
18081 FIXME: IWMMXT allows offsets larger than ldrd can handle,
18082 fix these up with a pair of ldr. */
18084 || !CONST_INT_P (otherops
[2])
18085 || (INTVAL (otherops
[2]) > -256
18086 && INTVAL (otherops
[2]) < 256))
18089 output_asm_insn ("ldrd%?\t%0, [%1], %2", otherops
);
18095 output_asm_insn ("ldr%?\t%H0, [%1, #4]", otherops
);
18096 output_asm_insn ("ldr%?\t%0, [%1], %2", otherops
);
18106 /* We might be able to use ldrd %0, %1 here. However the range is
18107 different to ldr/adr, and it is broken on some ARMv7-M
18108 implementations. */
18109 /* Use the second register of the pair to avoid problematic
18111 otherops
[1] = operands
[1];
18113 output_asm_insn ("adr%?\t%0, %1", otherops
);
18114 operands
[1] = otherops
[0];
18118 output_asm_insn ("ldrd%?\t%0, [%1]", operands
);
18120 output_asm_insn ("ldmia%?\t%1, %M0", operands
);
18127 /* ??? This needs checking for thumb2. */
18129 if (arm_add_operand (XEXP (XEXP (operands
[1], 0), 1),
18130 GET_MODE (XEXP (XEXP (operands
[1], 0), 1))))
18132 otherops
[0] = operands
[0];
18133 otherops
[1] = XEXP (XEXP (operands
[1], 0), 0);
18134 otherops
[2] = XEXP (XEXP (operands
[1], 0), 1);
18136 if (GET_CODE (XEXP (operands
[1], 0)) == PLUS
)
18138 if (CONST_INT_P (otherops
[2]) && !TARGET_LDRD
)
18140 switch ((int) INTVAL (otherops
[2]))
18144 output_asm_insn ("ldmdb%?\t%1, %M0", otherops
);
18150 output_asm_insn ("ldmda%?\t%1, %M0", otherops
);
18156 output_asm_insn ("ldmib%?\t%1, %M0", otherops
);
18160 otherops
[0] = gen_rtx_REG(SImode
, REGNO(operands
[0]) + 1);
18161 operands
[1] = otherops
[0];
18163 && (REG_P (otherops
[2])
18165 || (CONST_INT_P (otherops
[2])
18166 && INTVAL (otherops
[2]) > -256
18167 && INTVAL (otherops
[2]) < 256)))
18169 if (reg_overlap_mentioned_p (operands
[0],
18172 /* Swap base and index registers over to
18173 avoid a conflict. */
18174 std::swap (otherops
[1], otherops
[2]);
18176 /* If both registers conflict, it will usually
18177 have been fixed by a splitter. */
18178 if (reg_overlap_mentioned_p (operands
[0], otherops
[2])
18179 || (fix_cm3_ldrd
&& reg0
== REGNO (otherops
[1])))
18183 output_asm_insn ("add%?\t%0, %1, %2", otherops
);
18184 output_asm_insn ("ldrd%?\t%0, [%1]", operands
);
18191 otherops
[0] = operands
[0];
18193 output_asm_insn ("ldrd%?\t%0, [%1, %2]", otherops
);
18198 if (CONST_INT_P (otherops
[2]))
18202 if (!(const_ok_for_arm (INTVAL (otherops
[2]))))
18203 output_asm_insn ("sub%?\t%0, %1, #%n2", otherops
);
18205 output_asm_insn ("add%?\t%0, %1, %2", otherops
);
18211 output_asm_insn ("add%?\t%0, %1, %2", otherops
);
18217 output_asm_insn ("sub%?\t%0, %1, %2", otherops
);
18224 return "ldrd%?\t%0, [%1]";
18226 return "ldmia%?\t%1, %M0";
18230 otherops
[1] = adjust_address (operands
[1], SImode
, 4);
18231 /* Take care of overlapping base/data reg. */
18232 if (reg_mentioned_p (operands
[0], operands
[1]))
18236 output_asm_insn ("ldr%?\t%0, %1", otherops
);
18237 output_asm_insn ("ldr%?\t%0, %1", operands
);
18247 output_asm_insn ("ldr%?\t%0, %1", operands
);
18248 output_asm_insn ("ldr%?\t%0, %1", otherops
);
18258 /* Constraints should ensure this. */
18259 gcc_assert (code0
== MEM
&& code1
== REG
);
18260 gcc_assert ((REGNO (operands
[1]) != IP_REGNUM
)
18261 || (TARGET_ARM
&& TARGET_LDRD
));
18263 switch (GET_CODE (XEXP (operands
[0], 0)))
18269 output_asm_insn ("strd%?\t%1, [%m0]", operands
);
18271 output_asm_insn ("stm%?\t%m0, %M1", operands
);
18276 gcc_assert (TARGET_LDRD
);
18278 output_asm_insn ("strd%?\t%1, [%m0, #8]!", operands
);
18285 output_asm_insn ("strd%?\t%1, [%m0, #-8]!", operands
);
18287 output_asm_insn ("stmdb%?\t%m0!, %M1", operands
);
18295 output_asm_insn ("strd%?\t%1, [%m0], #8", operands
);
18297 output_asm_insn ("stm%?\t%m0!, %M1", operands
);
18302 gcc_assert (TARGET_LDRD
);
18304 output_asm_insn ("strd%?\t%1, [%m0], #-8", operands
);
18309 otherops
[0] = operands
[1];
18310 otherops
[1] = XEXP (XEXP (XEXP (operands
[0], 0), 1), 0);
18311 otherops
[2] = XEXP (XEXP (XEXP (operands
[0], 0), 1), 1);
18313 /* IWMMXT allows offsets larger than ldrd can handle,
18314 fix these up with a pair of ldr. */
18316 && CONST_INT_P (otherops
[2])
18317 && (INTVAL(otherops
[2]) <= -256
18318 || INTVAL(otherops
[2]) >= 256))
18320 if (GET_CODE (XEXP (operands
[0], 0)) == PRE_MODIFY
)
18324 output_asm_insn ("str%?\t%0, [%1, %2]!", otherops
);
18325 output_asm_insn ("str%?\t%H0, [%1, #4]", otherops
);
18334 output_asm_insn ("str%?\t%H0, [%1, #4]", otherops
);
18335 output_asm_insn ("str%?\t%0, [%1], %2", otherops
);
18341 else if (GET_CODE (XEXP (operands
[0], 0)) == PRE_MODIFY
)
18344 output_asm_insn ("strd%?\t%0, [%1, %2]!", otherops
);
18349 output_asm_insn ("strd%?\t%0, [%1], %2", otherops
);
18354 otherops
[2] = XEXP (XEXP (operands
[0], 0), 1);
18355 if (CONST_INT_P (otherops
[2]) && !TARGET_LDRD
)
18357 switch ((int) INTVAL (XEXP (XEXP (operands
[0], 0), 1)))
18361 output_asm_insn ("stmdb%?\t%m0, %M1", operands
);
18368 output_asm_insn ("stmda%?\t%m0, %M1", operands
);
18375 output_asm_insn ("stmib%?\t%m0, %M1", operands
);
18380 && (REG_P (otherops
[2])
18382 || (CONST_INT_P (otherops
[2])
18383 && INTVAL (otherops
[2]) > -256
18384 && INTVAL (otherops
[2]) < 256)))
18386 otherops
[0] = operands
[1];
18387 otherops
[1] = XEXP (XEXP (operands
[0], 0), 0);
18389 output_asm_insn ("strd%?\t%0, [%1, %2]", otherops
);
18395 otherops
[0] = adjust_address (operands
[0], SImode
, 4);
18396 otherops
[1] = operands
[1];
18399 output_asm_insn ("str%?\t%1, %0", operands
);
18400 output_asm_insn ("str%?\t%H1, %0", otherops
);
18410 /* Output a move, load or store for quad-word vectors in ARM registers. Only
18411 handles MEMs accepted by neon_vector_mem_operand with TYPE=1. */
18414 output_move_quad (rtx
*operands
)
18416 if (REG_P (operands
[0]))
18418 /* Load, or reg->reg move. */
18420 if (MEM_P (operands
[1]))
18422 switch (GET_CODE (XEXP (operands
[1], 0)))
18425 output_asm_insn ("ldmia%?\t%m1, %M0", operands
);
18430 output_asm_insn ("adr%?\t%0, %1", operands
);
18431 output_asm_insn ("ldmia%?\t%0, %M0", operands
);
18435 gcc_unreachable ();
18443 gcc_assert (REG_P (operands
[1]));
18445 dest
= REGNO (operands
[0]);
18446 src
= REGNO (operands
[1]);
18448 /* This seems pretty dumb, but hopefully GCC won't try to do it
18451 for (i
= 0; i
< 4; i
++)
18453 ops
[0] = gen_rtx_REG (SImode
, dest
+ i
);
18454 ops
[1] = gen_rtx_REG (SImode
, src
+ i
);
18455 output_asm_insn ("mov%?\t%0, %1", ops
);
18458 for (i
= 3; i
>= 0; i
--)
18460 ops
[0] = gen_rtx_REG (SImode
, dest
+ i
);
18461 ops
[1] = gen_rtx_REG (SImode
, src
+ i
);
18462 output_asm_insn ("mov%?\t%0, %1", ops
);
18468 gcc_assert (MEM_P (operands
[0]));
18469 gcc_assert (REG_P (operands
[1]));
18470 gcc_assert (!reg_overlap_mentioned_p (operands
[1], operands
[0]));
18472 switch (GET_CODE (XEXP (operands
[0], 0)))
18475 output_asm_insn ("stm%?\t%m0, %M1", operands
);
18479 gcc_unreachable ();
18486 /* Output a VFP load or store instruction. */
18489 output_move_vfp (rtx
*operands
)
18491 rtx reg
, mem
, addr
, ops
[2];
18492 int load
= REG_P (operands
[0]);
18493 int dp
= GET_MODE_SIZE (GET_MODE (operands
[0])) == 8;
18494 int sp
= (!TARGET_VFP_FP16INST
18495 || GET_MODE_SIZE (GET_MODE (operands
[0])) == 4);
18496 int integer_p
= GET_MODE_CLASS (GET_MODE (operands
[0])) == MODE_INT
;
18501 reg
= operands
[!load
];
18502 mem
= operands
[load
];
18504 mode
= GET_MODE (reg
);
18506 gcc_assert (REG_P (reg
));
18507 gcc_assert (IS_VFP_REGNUM (REGNO (reg
)));
18508 gcc_assert ((mode
== HFmode
&& TARGET_HARD_FLOAT
)
18514 || (TARGET_NEON
&& VALID_NEON_DREG_MODE (mode
)));
18515 gcc_assert (MEM_P (mem
));
18517 addr
= XEXP (mem
, 0);
18519 switch (GET_CODE (addr
))
18522 templ
= "v%smdb%%?.%s\t%%0!, {%%%s1}%s";
18523 ops
[0] = XEXP (addr
, 0);
18528 templ
= "v%smia%%?.%s\t%%0!, {%%%s1}%s";
18529 ops
[0] = XEXP (addr
, 0);
18534 templ
= "v%sr%%?.%s\t%%%s0, %%1%s";
18540 sprintf (buff
, templ
,
18541 load
? "ld" : "st",
18542 dp
? "64" : sp
? "32" : "16",
18544 integer_p
? "\t%@ int" : "");
18545 output_asm_insn (buff
, ops
);
18550 /* Output a Neon double-word or quad-word load or store, or a load
18551 or store for larger structure modes.
18553 WARNING: The ordering of elements is weird in big-endian mode,
18554 because the EABI requires that vectors stored in memory appear
18555 as though they were stored by a VSTM, as required by the EABI.
18556 GCC RTL defines element ordering based on in-memory order.
18557 This can be different from the architectural ordering of elements
18558 within a NEON register. The intrinsics defined in arm_neon.h use the
18559 NEON register element ordering, not the GCC RTL element ordering.
18561 For example, the in-memory ordering of a big-endian a quadword
18562 vector with 16-bit elements when stored from register pair {d0,d1}
18563 will be (lowest address first, d0[N] is NEON register element N):
18565 [d0[3], d0[2], d0[1], d0[0], d1[7], d1[6], d1[5], d1[4]]
18567 When necessary, quadword registers (dN, dN+1) are moved to ARM
18568 registers from rN in the order:
18570 dN -> (rN+1, rN), dN+1 -> (rN+3, rN+2)
18572 So that STM/LDM can be used on vectors in ARM registers, and the
18573 same memory layout will result as if VSTM/VLDM were used.
18575 Instead of VSTM/VLDM we prefer to use VST1.64/VLD1.64 where
18576 possible, which allows use of appropriate alignment tags.
18577 Note that the choice of "64" is independent of the actual vector
18578 element size; this size simply ensures that the behavior is
18579 equivalent to VSTM/VLDM in both little-endian and big-endian mode.
18581 Due to limitations of those instructions, use of VST1.64/VLD1.64
18582 is not possible if:
18583 - the address contains PRE_DEC, or
18584 - the mode refers to more than 4 double-word registers
18586 In those cases, it would be possible to replace VSTM/VLDM by a
18587 sequence of instructions; this is not currently implemented since
18588 this is not certain to actually improve performance. */
18591 output_move_neon (rtx
*operands
)
18593 rtx reg
, mem
, addr
, ops
[2];
18594 int regno
, nregs
, load
= REG_P (operands
[0]);
18599 reg
= operands
[!load
];
18600 mem
= operands
[load
];
18602 mode
= GET_MODE (reg
);
18604 gcc_assert (REG_P (reg
));
18605 regno
= REGNO (reg
);
18606 nregs
= REG_NREGS (reg
) / 2;
18607 gcc_assert (VFP_REGNO_OK_FOR_DOUBLE (regno
)
18608 || NEON_REGNO_OK_FOR_QUAD (regno
));
18609 gcc_assert (VALID_NEON_DREG_MODE (mode
)
18610 || VALID_NEON_QREG_MODE (mode
)
18611 || VALID_NEON_STRUCT_MODE (mode
));
18612 gcc_assert (MEM_P (mem
));
18614 addr
= XEXP (mem
, 0);
18616 /* Strip off const from addresses like (const (plus (...))). */
18617 if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
)
18618 addr
= XEXP (addr
, 0);
18620 switch (GET_CODE (addr
))
18623 /* We have to use vldm / vstm for too-large modes. */
18626 templ
= "v%smia%%?\t%%0!, %%h1";
18627 ops
[0] = XEXP (addr
, 0);
18631 templ
= "v%s1.64\t%%h1, %%A0";
18638 /* We have to use vldm / vstm in this case, since there is no
18639 pre-decrement form of the vld1 / vst1 instructions. */
18640 templ
= "v%smdb%%?\t%%0!, %%h1";
18641 ops
[0] = XEXP (addr
, 0);
18646 /* FIXME: Not currently enabled in neon_vector_mem_operand. */
18647 gcc_unreachable ();
18650 /* We have to use vldm / vstm for too-large modes. */
18654 templ
= "v%smia%%?\t%%m0, %%h1";
18656 templ
= "v%s1.64\t%%h1, %%A0";
18662 /* Fall through. */
18668 for (i
= 0; i
< nregs
; i
++)
18670 /* We're only using DImode here because it's a convenient size. */
18671 ops
[0] = gen_rtx_REG (DImode
, REGNO (reg
) + 2 * i
);
18672 ops
[1] = adjust_address (mem
, DImode
, 8 * i
);
18673 if (reg_overlap_mentioned_p (ops
[0], mem
))
18675 gcc_assert (overlap
== -1);
18680 sprintf (buff
, "v%sr%%?\t%%P0, %%1", load
? "ld" : "st");
18681 output_asm_insn (buff
, ops
);
18686 ops
[0] = gen_rtx_REG (DImode
, REGNO (reg
) + 2 * overlap
);
18687 ops
[1] = adjust_address (mem
, SImode
, 8 * overlap
);
18688 sprintf (buff
, "v%sr%%?\t%%P0, %%1", load
? "ld" : "st");
18689 output_asm_insn (buff
, ops
);
18696 gcc_unreachable ();
18699 sprintf (buff
, templ
, load
? "ld" : "st");
18700 output_asm_insn (buff
, ops
);
18705 /* Compute and return the length of neon_mov<mode>, where <mode> is
18706 one of VSTRUCT modes: EI, OI, CI or XI. */
18708 arm_attr_length_move_neon (rtx_insn
*insn
)
18710 rtx reg
, mem
, addr
;
18714 extract_insn_cached (insn
);
18716 if (REG_P (recog_data
.operand
[0]) && REG_P (recog_data
.operand
[1]))
18718 mode
= GET_MODE (recog_data
.operand
[0]);
18729 gcc_unreachable ();
18733 load
= REG_P (recog_data
.operand
[0]);
18734 reg
= recog_data
.operand
[!load
];
18735 mem
= recog_data
.operand
[load
];
18737 gcc_assert (MEM_P (mem
));
18739 addr
= XEXP (mem
, 0);
18741 /* Strip off const from addresses like (const (plus (...))). */
18742 if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
)
18743 addr
= XEXP (addr
, 0);
18745 if (GET_CODE (addr
) == LABEL_REF
|| GET_CODE (addr
) == PLUS
)
18747 int insns
= REG_NREGS (reg
) / 2;
18754 /* Return nonzero if the offset in the address is an immediate. Otherwise,
18758 arm_address_offset_is_imm (rtx_insn
*insn
)
18762 extract_insn_cached (insn
);
18764 if (REG_P (recog_data
.operand
[0]))
18767 mem
= recog_data
.operand
[0];
18769 gcc_assert (MEM_P (mem
));
18771 addr
= XEXP (mem
, 0);
18774 || (GET_CODE (addr
) == PLUS
18775 && REG_P (XEXP (addr
, 0))
18776 && CONST_INT_P (XEXP (addr
, 1))))
18782 /* Output an ADD r, s, #n where n may be too big for one instruction.
18783 If adding zero to one register, output nothing. */
18785 output_add_immediate (rtx
*operands
)
18787 HOST_WIDE_INT n
= INTVAL (operands
[2]);
18789 if (n
!= 0 || REGNO (operands
[0]) != REGNO (operands
[1]))
18792 output_multi_immediate (operands
,
18793 "sub%?\t%0, %1, %2", "sub%?\t%0, %0, %2", 2,
18796 output_multi_immediate (operands
,
18797 "add%?\t%0, %1, %2", "add%?\t%0, %0, %2", 2,
18804 /* Output a multiple immediate operation.
18805 OPERANDS is the vector of operands referred to in the output patterns.
18806 INSTR1 is the output pattern to use for the first constant.
18807 INSTR2 is the output pattern to use for subsequent constants.
18808 IMMED_OP is the index of the constant slot in OPERANDS.
18809 N is the constant value. */
18810 static const char *
18811 output_multi_immediate (rtx
*operands
, const char *instr1
, const char *instr2
,
18812 int immed_op
, HOST_WIDE_INT n
)
18814 #if HOST_BITS_PER_WIDE_INT > 32
18820 /* Quick and easy output. */
18821 operands
[immed_op
] = const0_rtx
;
18822 output_asm_insn (instr1
, operands
);
18827 const char * instr
= instr1
;
18829 /* Note that n is never zero here (which would give no output). */
18830 for (i
= 0; i
< 32; i
+= 2)
18834 operands
[immed_op
] = GEN_INT (n
& (255 << i
));
18835 output_asm_insn (instr
, operands
);
18845 /* Return the name of a shifter operation. */
18846 static const char *
18847 arm_shift_nmem(enum rtx_code code
)
18852 return ARM_LSL_NAME
;
18868 /* Return the appropriate ARM instruction for the operation code.
18869 The returned result should not be overwritten. OP is the rtx of the
18870 operation. SHIFT_FIRST_ARG is TRUE if the first argument of the operator
18873 arithmetic_instr (rtx op
, int shift_first_arg
)
18875 switch (GET_CODE (op
))
18881 return shift_first_arg
? "rsb" : "sub";
18896 return arm_shift_nmem(GET_CODE(op
));
18899 gcc_unreachable ();
18903 /* Ensure valid constant shifts and return the appropriate shift mnemonic
18904 for the operation code. The returned result should not be overwritten.
18905 OP is the rtx code of the shift.
18906 On exit, *AMOUNTP will be -1 if the shift is by a register, or a constant
18908 static const char *
18909 shift_op (rtx op
, HOST_WIDE_INT
*amountp
)
18912 enum rtx_code code
= GET_CODE (op
);
18917 if (!CONST_INT_P (XEXP (op
, 1)))
18919 output_operand_lossage ("invalid shift operand");
18924 *amountp
= 32 - INTVAL (XEXP (op
, 1));
18932 mnem
= arm_shift_nmem(code
);
18933 if (CONST_INT_P (XEXP (op
, 1)))
18935 *amountp
= INTVAL (XEXP (op
, 1));
18937 else if (REG_P (XEXP (op
, 1)))
18944 output_operand_lossage ("invalid shift operand");
18950 /* We never have to worry about the amount being other than a
18951 power of 2, since this case can never be reloaded from a reg. */
18952 if (!CONST_INT_P (XEXP (op
, 1)))
18954 output_operand_lossage ("invalid shift operand");
18958 *amountp
= INTVAL (XEXP (op
, 1)) & 0xFFFFFFFF;
18960 /* Amount must be a power of two. */
18961 if (*amountp
& (*amountp
- 1))
18963 output_operand_lossage ("invalid shift operand");
18967 *amountp
= exact_log2 (*amountp
);
18968 gcc_assert (IN_RANGE (*amountp
, 0, 31));
18969 return ARM_LSL_NAME
;
18972 output_operand_lossage ("invalid shift operand");
18976 /* This is not 100% correct, but follows from the desire to merge
18977 multiplication by a power of 2 with the recognizer for a
18978 shift. >=32 is not a valid shift for "lsl", so we must try and
18979 output a shift that produces the correct arithmetical result.
18980 Using lsr #32 is identical except for the fact that the carry bit
18981 is not set correctly if we set the flags; but we never use the
18982 carry bit from such an operation, so we can ignore that. */
18983 if (code
== ROTATERT
)
18984 /* Rotate is just modulo 32. */
18986 else if (*amountp
!= (*amountp
& 31))
18988 if (code
== ASHIFT
)
18993 /* Shifts of 0 are no-ops. */
19000 /* Output a .ascii pseudo-op, keeping track of lengths. This is
19001 because /bin/as is horribly restrictive. The judgement about
19002 whether or not each character is 'printable' (and can be output as
19003 is) or not (and must be printed with an octal escape) must be made
19004 with reference to the *host* character set -- the situation is
19005 similar to that discussed in the comments above pp_c_char in
19006 c-pretty-print.c. */
19008 #define MAX_ASCII_LEN 51
19011 output_ascii_pseudo_op (FILE *stream
, const unsigned char *p
, int len
)
19014 int len_so_far
= 0;
19016 fputs ("\t.ascii\t\"", stream
);
19018 for (i
= 0; i
< len
; i
++)
19022 if (len_so_far
>= MAX_ASCII_LEN
)
19024 fputs ("\"\n\t.ascii\t\"", stream
);
19030 if (c
== '\\' || c
== '\"')
19032 putc ('\\', stream
);
19040 fprintf (stream
, "\\%03o", c
);
19045 fputs ("\"\n", stream
);
19048 /* Whether a register is callee saved or not. This is necessary because high
19049 registers are marked as caller saved when optimizing for size on Thumb-1
19050 targets despite being callee saved in order to avoid using them. */
19051 #define callee_saved_reg_p(reg) \
19052 (!call_used_regs[reg] \
19053 || (TARGET_THUMB1 && optimize_size \
19054 && reg >= FIRST_HI_REGNUM && reg <= LAST_HI_REGNUM))
19056 /* Compute the register save mask for registers 0 through 12
19057 inclusive. This code is used by arm_compute_save_core_reg_mask (). */
19059 static unsigned long
19060 arm_compute_save_reg0_reg12_mask (void)
19062 unsigned long func_type
= arm_current_func_type ();
19063 unsigned long save_reg_mask
= 0;
19066 if (IS_INTERRUPT (func_type
))
19068 unsigned int max_reg
;
19069 /* Interrupt functions must not corrupt any registers,
19070 even call clobbered ones. If this is a leaf function
19071 we can just examine the registers used by the RTL, but
19072 otherwise we have to assume that whatever function is
19073 called might clobber anything, and so we have to save
19074 all the call-clobbered registers as well. */
19075 if (ARM_FUNC_TYPE (func_type
) == ARM_FT_FIQ
)
19076 /* FIQ handlers have registers r8 - r12 banked, so
19077 we only need to check r0 - r7, Normal ISRs only
19078 bank r14 and r15, so we must check up to r12.
19079 r13 is the stack pointer which is always preserved,
19080 so we do not need to consider it here. */
19085 for (reg
= 0; reg
<= max_reg
; reg
++)
19086 if (df_regs_ever_live_p (reg
)
19087 || (! crtl
->is_leaf
&& call_used_regs
[reg
]))
19088 save_reg_mask
|= (1 << reg
);
19090 /* Also save the pic base register if necessary. */
19092 && !TARGET_SINGLE_PIC_BASE
19093 && arm_pic_register
!= INVALID_REGNUM
19094 && crtl
->uses_pic_offset_table
)
19095 save_reg_mask
|= 1 << PIC_OFFSET_TABLE_REGNUM
;
19097 else if (IS_VOLATILE(func_type
))
19099 /* For noreturn functions we historically omitted register saves
19100 altogether. However this really messes up debugging. As a
19101 compromise save just the frame pointers. Combined with the link
19102 register saved elsewhere this should be sufficient to get
19104 if (frame_pointer_needed
)
19105 save_reg_mask
|= 1 << HARD_FRAME_POINTER_REGNUM
;
19106 if (df_regs_ever_live_p (ARM_HARD_FRAME_POINTER_REGNUM
))
19107 save_reg_mask
|= 1 << ARM_HARD_FRAME_POINTER_REGNUM
;
19108 if (df_regs_ever_live_p (THUMB_HARD_FRAME_POINTER_REGNUM
))
19109 save_reg_mask
|= 1 << THUMB_HARD_FRAME_POINTER_REGNUM
;
19113 /* In the normal case we only need to save those registers
19114 which are call saved and which are used by this function. */
19115 for (reg
= 0; reg
<= 11; reg
++)
19116 if (df_regs_ever_live_p (reg
) && callee_saved_reg_p (reg
))
19117 save_reg_mask
|= (1 << reg
);
19119 /* Handle the frame pointer as a special case. */
19120 if (frame_pointer_needed
)
19121 save_reg_mask
|= 1 << HARD_FRAME_POINTER_REGNUM
;
19123 /* If we aren't loading the PIC register,
19124 don't stack it even though it may be live. */
19126 && !TARGET_SINGLE_PIC_BASE
19127 && arm_pic_register
!= INVALID_REGNUM
19128 && (df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
)
19129 || crtl
->uses_pic_offset_table
))
19130 save_reg_mask
|= 1 << PIC_OFFSET_TABLE_REGNUM
;
19132 /* The prologue will copy SP into R0, so save it. */
19133 if (IS_STACKALIGN (func_type
))
19134 save_reg_mask
|= 1;
19137 /* Save registers so the exception handler can modify them. */
19138 if (crtl
->calls_eh_return
)
19144 reg
= EH_RETURN_DATA_REGNO (i
);
19145 if (reg
== INVALID_REGNUM
)
19147 save_reg_mask
|= 1 << reg
;
19151 return save_reg_mask
;
19154 /* Return true if r3 is live at the start of the function. */
19157 arm_r3_live_at_start_p (void)
19159 /* Just look at cfg info, which is still close enough to correct at this
19160 point. This gives false positives for broken functions that might use
19161 uninitialized data that happens to be allocated in r3, but who cares? */
19162 return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun
)), 3);
19165 /* Compute the number of bytes used to store the static chain register on the
19166 stack, above the stack frame. We need to know this accurately to get the
19167 alignment of the rest of the stack frame correct. */
19170 arm_compute_static_chain_stack_bytes (void)
19172 /* See the defining assertion in arm_expand_prologue. */
19173 if (IS_NESTED (arm_current_func_type ())
19174 && ((TARGET_APCS_FRAME
&& frame_pointer_needed
&& TARGET_ARM
)
19175 || ((flag_stack_check
== STATIC_BUILTIN_STACK_CHECK
19176 || flag_stack_clash_protection
)
19177 && !df_regs_ever_live_p (LR_REGNUM
)))
19178 && arm_r3_live_at_start_p ()
19179 && crtl
->args
.pretend_args_size
== 0)
19185 /* Compute a bit mask of which core registers need to be
19186 saved on the stack for the current function.
19187 This is used by arm_compute_frame_layout, which may add extra registers. */
19189 static unsigned long
19190 arm_compute_save_core_reg_mask (void)
19192 unsigned int save_reg_mask
= 0;
19193 unsigned long func_type
= arm_current_func_type ();
19196 if (IS_NAKED (func_type
))
19197 /* This should never really happen. */
19200 /* If we are creating a stack frame, then we must save the frame pointer,
19201 IP (which will hold the old stack pointer), LR and the PC. */
19202 if (TARGET_APCS_FRAME
&& frame_pointer_needed
&& TARGET_ARM
)
19204 (1 << ARM_HARD_FRAME_POINTER_REGNUM
)
19207 | (1 << PC_REGNUM
);
19209 save_reg_mask
|= arm_compute_save_reg0_reg12_mask ();
19211 /* Decide if we need to save the link register.
19212 Interrupt routines have their own banked link register,
19213 so they never need to save it.
19214 Otherwise if we do not use the link register we do not need to save
19215 it. If we are pushing other registers onto the stack however, we
19216 can save an instruction in the epilogue by pushing the link register
19217 now and then popping it back into the PC. This incurs extra memory
19218 accesses though, so we only do it when optimizing for size, and only
19219 if we know that we will not need a fancy return sequence. */
19220 if (df_regs_ever_live_p (LR_REGNUM
)
19223 && ARM_FUNC_TYPE (func_type
) == ARM_FT_NORMAL
19224 && !crtl
->tail_call_emit
19225 && !crtl
->calls_eh_return
))
19226 save_reg_mask
|= 1 << LR_REGNUM
;
19228 if (cfun
->machine
->lr_save_eliminated
)
19229 save_reg_mask
&= ~ (1 << LR_REGNUM
);
19231 if (TARGET_REALLY_IWMMXT
19232 && ((bit_count (save_reg_mask
)
19233 + ARM_NUM_INTS (crtl
->args
.pretend_args_size
+
19234 arm_compute_static_chain_stack_bytes())
19237 /* The total number of registers that are going to be pushed
19238 onto the stack is odd. We need to ensure that the stack
19239 is 64-bit aligned before we start to save iWMMXt registers,
19240 and also before we start to create locals. (A local variable
19241 might be a double or long long which we will load/store using
19242 an iWMMXt instruction). Therefore we need to push another
19243 ARM register, so that the stack will be 64-bit aligned. We
19244 try to avoid using the arg registers (r0 -r3) as they might be
19245 used to pass values in a tail call. */
19246 for (reg
= 4; reg
<= 12; reg
++)
19247 if ((save_reg_mask
& (1 << reg
)) == 0)
19251 save_reg_mask
|= (1 << reg
);
19254 cfun
->machine
->sibcall_blocked
= 1;
19255 save_reg_mask
|= (1 << 3);
19259 /* We may need to push an additional register for use initializing the
19260 PIC base register. */
19261 if (TARGET_THUMB2
&& IS_NESTED (func_type
) && flag_pic
19262 && (save_reg_mask
& THUMB2_WORK_REGS
) == 0)
19264 reg
= thumb_find_work_register (1 << 4);
19265 if (!call_used_regs
[reg
])
19266 save_reg_mask
|= (1 << reg
);
19269 return save_reg_mask
;
19272 /* Compute a bit mask of which core registers need to be
19273 saved on the stack for the current function. */
19274 static unsigned long
19275 thumb1_compute_save_core_reg_mask (void)
19277 unsigned long mask
;
19281 for (reg
= 0; reg
< 12; reg
++)
19282 if (df_regs_ever_live_p (reg
) && callee_saved_reg_p (reg
))
19285 /* Handle the frame pointer as a special case. */
19286 if (frame_pointer_needed
)
19287 mask
|= 1 << HARD_FRAME_POINTER_REGNUM
;
19290 && !TARGET_SINGLE_PIC_BASE
19291 && arm_pic_register
!= INVALID_REGNUM
19292 && crtl
->uses_pic_offset_table
)
19293 mask
|= 1 << PIC_OFFSET_TABLE_REGNUM
;
19295 /* See if we might need r11 for calls to _interwork_r11_call_via_rN(). */
19296 if (!frame_pointer_needed
&& CALLER_INTERWORKING_SLOT_SIZE
> 0)
19297 mask
|= 1 << ARM_HARD_FRAME_POINTER_REGNUM
;
19299 /* LR will also be pushed if any lo regs are pushed. */
19300 if (mask
& 0xff || thumb_force_lr_save ())
19301 mask
|= (1 << LR_REGNUM
);
19303 /* Make sure we have a low work register if we need one.
19304 We will need one if we are going to push a high register,
19305 but we are not currently intending to push a low register. */
19306 if ((mask
& 0xff) == 0
19307 && ((mask
& 0x0f00) || TARGET_BACKTRACE
))
19309 /* Use thumb_find_work_register to choose which register
19310 we will use. If the register is live then we will
19311 have to push it. Use LAST_LO_REGNUM as our fallback
19312 choice for the register to select. */
19313 reg
= thumb_find_work_register (1 << LAST_LO_REGNUM
);
19314 /* Make sure the register returned by thumb_find_work_register is
19315 not part of the return value. */
19316 if (reg
* UNITS_PER_WORD
<= (unsigned) arm_size_return_regs ())
19317 reg
= LAST_LO_REGNUM
;
19319 if (callee_saved_reg_p (reg
))
19323 /* The 504 below is 8 bytes less than 512 because there are two possible
19324 alignment words. We can't tell here if they will be present or not so we
19325 have to play it safe and assume that they are. */
19326 if ((CALLER_INTERWORKING_SLOT_SIZE
+
19327 ROUND_UP_WORD (get_frame_size ()) +
19328 crtl
->outgoing_args_size
) >= 504)
19330 /* This is the same as the code in thumb1_expand_prologue() which
19331 determines which register to use for stack decrement. */
19332 for (reg
= LAST_ARG_REGNUM
+ 1; reg
<= LAST_LO_REGNUM
; reg
++)
19333 if (mask
& (1 << reg
))
19336 if (reg
> LAST_LO_REGNUM
)
19338 /* Make sure we have a register available for stack decrement. */
19339 mask
|= 1 << LAST_LO_REGNUM
;
19347 /* Return the number of bytes required to save VFP registers. */
19349 arm_get_vfp_saved_size (void)
19351 unsigned int regno
;
19356 /* Space for saved VFP registers. */
19357 if (TARGET_HARD_FLOAT
)
19360 for (regno
= FIRST_VFP_REGNUM
;
19361 regno
< LAST_VFP_REGNUM
;
19364 if ((!df_regs_ever_live_p (regno
) || call_used_regs
[regno
])
19365 && (!df_regs_ever_live_p (regno
+ 1) || call_used_regs
[regno
+ 1]))
19369 /* Workaround ARM10 VFPr1 bug. */
19370 if (count
== 2 && !arm_arch6
)
19372 saved
+= count
* 8;
19381 if (count
== 2 && !arm_arch6
)
19383 saved
+= count
* 8;
19390 /* Generate a function exit sequence. If REALLY_RETURN is false, then do
19391 everything bar the final return instruction. If simple_return is true,
19392 then do not output epilogue, because it has already been emitted in RTL. */
19394 output_return_instruction (rtx operand
, bool really_return
, bool reverse
,
19395 bool simple_return
)
19397 char conditional
[10];
19400 unsigned long live_regs_mask
;
19401 unsigned long func_type
;
19402 arm_stack_offsets
*offsets
;
19404 func_type
= arm_current_func_type ();
19406 if (IS_NAKED (func_type
))
19409 if (IS_VOLATILE (func_type
) && TARGET_ABORT_NORETURN
)
19411 /* If this function was declared non-returning, and we have
19412 found a tail call, then we have to trust that the called
19413 function won't return. */
19418 /* Otherwise, trap an attempted return by aborting. */
19420 ops
[1] = gen_rtx_SYMBOL_REF (Pmode
, NEED_PLT_RELOC
? "abort(PLT)"
19422 assemble_external_libcall (ops
[1]);
19423 output_asm_insn (reverse
? "bl%D0\t%a1" : "bl%d0\t%a1", ops
);
19429 gcc_assert (!cfun
->calls_alloca
|| really_return
);
19431 sprintf (conditional
, "%%?%%%c0", reverse
? 'D' : 'd');
19433 cfun
->machine
->return_used_this_function
= 1;
19435 offsets
= arm_get_frame_offsets ();
19436 live_regs_mask
= offsets
->saved_regs_mask
;
19438 if (!simple_return
&& live_regs_mask
)
19440 const char * return_reg
;
19442 /* If we do not have any special requirements for function exit
19443 (e.g. interworking) then we can load the return address
19444 directly into the PC. Otherwise we must load it into LR. */
19446 && !IS_CMSE_ENTRY (func_type
)
19447 && (IS_INTERRUPT (func_type
) || !TARGET_INTERWORK
))
19448 return_reg
= reg_names
[PC_REGNUM
];
19450 return_reg
= reg_names
[LR_REGNUM
];
19452 if ((live_regs_mask
& (1 << IP_REGNUM
)) == (1 << IP_REGNUM
))
19454 /* There are three possible reasons for the IP register
19455 being saved. 1) a stack frame was created, in which case
19456 IP contains the old stack pointer, or 2) an ISR routine
19457 corrupted it, or 3) it was saved to align the stack on
19458 iWMMXt. In case 1, restore IP into SP, otherwise just
19460 if (frame_pointer_needed
)
19462 live_regs_mask
&= ~ (1 << IP_REGNUM
);
19463 live_regs_mask
|= (1 << SP_REGNUM
);
19466 gcc_assert (IS_INTERRUPT (func_type
) || TARGET_REALLY_IWMMXT
);
19469 /* On some ARM architectures it is faster to use LDR rather than
19470 LDM to load a single register. On other architectures, the
19471 cost is the same. In 26 bit mode, or for exception handlers,
19472 we have to use LDM to load the PC so that the CPSR is also
19474 for (reg
= 0; reg
<= LAST_ARM_REGNUM
; reg
++)
19475 if (live_regs_mask
== (1U << reg
))
19478 if (reg
<= LAST_ARM_REGNUM
19479 && (reg
!= LR_REGNUM
19481 || ! IS_INTERRUPT (func_type
)))
19483 sprintf (instr
, "ldr%s\t%%|%s, [%%|sp], #4", conditional
,
19484 (reg
== LR_REGNUM
) ? return_reg
: reg_names
[reg
]);
19491 /* Generate the load multiple instruction to restore the
19492 registers. Note we can get here, even if
19493 frame_pointer_needed is true, but only if sp already
19494 points to the base of the saved core registers. */
19495 if (live_regs_mask
& (1 << SP_REGNUM
))
19497 unsigned HOST_WIDE_INT stack_adjust
;
19499 stack_adjust
= offsets
->outgoing_args
- offsets
->saved_regs
;
19500 gcc_assert (stack_adjust
== 0 || stack_adjust
== 4);
19502 if (stack_adjust
&& arm_arch5
&& TARGET_ARM
)
19503 sprintf (instr
, "ldmib%s\t%%|sp, {", conditional
);
19506 /* If we can't use ldmib (SA110 bug),
19507 then try to pop r3 instead. */
19509 live_regs_mask
|= 1 << 3;
19511 sprintf (instr
, "ldmfd%s\t%%|sp, {", conditional
);
19514 /* For interrupt returns we have to use an LDM rather than
19515 a POP so that we can use the exception return variant. */
19516 else if (IS_INTERRUPT (func_type
))
19517 sprintf (instr
, "ldmfd%s\t%%|sp!, {", conditional
);
19519 sprintf (instr
, "pop%s\t{", conditional
);
19521 p
= instr
+ strlen (instr
);
19523 for (reg
= 0; reg
<= SP_REGNUM
; reg
++)
19524 if (live_regs_mask
& (1 << reg
))
19526 int l
= strlen (reg_names
[reg
]);
19532 memcpy (p
, ", ", 2);
19536 memcpy (p
, "%|", 2);
19537 memcpy (p
+ 2, reg_names
[reg
], l
);
19541 if (live_regs_mask
& (1 << LR_REGNUM
))
19543 sprintf (p
, "%s%%|%s}", first
? "" : ", ", return_reg
);
19544 /* If returning from an interrupt, restore the CPSR. */
19545 if (IS_INTERRUPT (func_type
))
19552 output_asm_insn (instr
, & operand
);
19554 /* See if we need to generate an extra instruction to
19555 perform the actual function return. */
19557 && func_type
!= ARM_FT_INTERWORKED
19558 && (live_regs_mask
& (1 << LR_REGNUM
)) != 0)
19560 /* The return has already been handled
19561 by loading the LR into the PC. */
19568 switch ((int) ARM_FUNC_TYPE (func_type
))
19572 /* ??? This is wrong for unified assembly syntax. */
19573 sprintf (instr
, "sub%ss\t%%|pc, %%|lr, #4", conditional
);
19576 case ARM_FT_INTERWORKED
:
19577 gcc_assert (arm_arch5
|| arm_arch4t
);
19578 sprintf (instr
, "bx%s\t%%|lr", conditional
);
19581 case ARM_FT_EXCEPTION
:
19582 /* ??? This is wrong for unified assembly syntax. */
19583 sprintf (instr
, "mov%ss\t%%|pc, %%|lr", conditional
);
19587 if (IS_CMSE_ENTRY (func_type
))
19589 /* Check if we have to clear the 'GE bits' which is only used if
19590 parallel add and subtraction instructions are available. */
19591 if (TARGET_INT_SIMD
)
19592 snprintf (instr
, sizeof (instr
),
19593 "msr%s\tAPSR_nzcvqg, %%|lr", conditional
);
19595 snprintf (instr
, sizeof (instr
),
19596 "msr%s\tAPSR_nzcvq, %%|lr", conditional
);
19598 output_asm_insn (instr
, & operand
);
19599 if (TARGET_HARD_FLOAT
&& !TARGET_THUMB1
)
19601 /* Clear the cumulative exception-status bits (0-4,7) and the
19602 condition code bits (28-31) of the FPSCR. We need to
19603 remember to clear the first scratch register used (IP) and
19604 save and restore the second (r4). */
19605 snprintf (instr
, sizeof (instr
), "push\t{%%|r4}");
19606 output_asm_insn (instr
, & operand
);
19607 snprintf (instr
, sizeof (instr
), "vmrs\t%%|ip, fpscr");
19608 output_asm_insn (instr
, & operand
);
19609 snprintf (instr
, sizeof (instr
), "movw\t%%|r4, #65376");
19610 output_asm_insn (instr
, & operand
);
19611 snprintf (instr
, sizeof (instr
), "movt\t%%|r4, #4095");
19612 output_asm_insn (instr
, & operand
);
19613 snprintf (instr
, sizeof (instr
), "and\t%%|ip, %%|r4");
19614 output_asm_insn (instr
, & operand
);
19615 snprintf (instr
, sizeof (instr
), "vmsr\tfpscr, %%|ip");
19616 output_asm_insn (instr
, & operand
);
19617 snprintf (instr
, sizeof (instr
), "pop\t{%%|r4}");
19618 output_asm_insn (instr
, & operand
);
19619 snprintf (instr
, sizeof (instr
), "mov\t%%|ip, %%|lr");
19620 output_asm_insn (instr
, & operand
);
19622 snprintf (instr
, sizeof (instr
), "bxns\t%%|lr");
19624 /* Use bx if it's available. */
19625 else if (arm_arch5
|| arm_arch4t
)
19626 sprintf (instr
, "bx%s\t%%|lr", conditional
);
19628 sprintf (instr
, "mov%s\t%%|pc, %%|lr", conditional
);
19632 output_asm_insn (instr
, & operand
);
19638 /* Output in FILE asm statements needed to declare the NAME of the function
19639 defined by its DECL node. */
19642 arm_asm_declare_function_name (FILE *file
, const char *name
, tree decl
)
19644 size_t cmse_name_len
;
19645 char *cmse_name
= 0;
19646 char cmse_prefix
[] = "__acle_se_";
19648 /* When compiling with ARMv8-M Security Extensions enabled, we should print an
19649 extra function label for each function with the 'cmse_nonsecure_entry'
19650 attribute. This extra function label should be prepended with
19651 '__acle_se_', telling the linker that it needs to create secure gateway
19652 veneers for this function. */
19653 if (use_cmse
&& lookup_attribute ("cmse_nonsecure_entry",
19654 DECL_ATTRIBUTES (decl
)))
19656 cmse_name_len
= sizeof (cmse_prefix
) + strlen (name
);
19657 cmse_name
= XALLOCAVEC (char, cmse_name_len
);
19658 snprintf (cmse_name
, cmse_name_len
, "%s%s", cmse_prefix
, name
);
19659 targetm
.asm_out
.globalize_label (file
, cmse_name
);
19661 ARM_DECLARE_FUNCTION_NAME (file
, cmse_name
, decl
);
19662 ASM_OUTPUT_TYPE_DIRECTIVE (file
, cmse_name
, "function");
19665 ARM_DECLARE_FUNCTION_NAME (file
, name
, decl
);
19666 ASM_OUTPUT_TYPE_DIRECTIVE (file
, name
, "function");
19667 ASM_DECLARE_RESULT (file
, DECL_RESULT (decl
));
19668 ASM_OUTPUT_LABEL (file
, name
);
19671 ASM_OUTPUT_LABEL (file
, cmse_name
);
19673 ARM_OUTPUT_FN_UNWIND (file
, TRUE
);
19676 /* Write the function name into the code section, directly preceding
19677 the function prologue.
19679 Code will be output similar to this:
19681 .ascii "arm_poke_function_name", 0
19684 .word 0xff000000 + (t1 - t0)
19685 arm_poke_function_name
19687 stmfd sp!, {fp, ip, lr, pc}
19690 When performing a stack backtrace, code can inspect the value
19691 of 'pc' stored at 'fp' + 0. If the trace function then looks
19692 at location pc - 12 and the top 8 bits are set, then we know
19693 that there is a function name embedded immediately preceding this
19694 location and has length ((pc[-3]) & 0xff000000).
19696 We assume that pc is declared as a pointer to an unsigned long.
19698 It is of no benefit to output the function name if we are assembling
19699 a leaf function. These function types will not contain a stack
19700 backtrace structure, therefore it is not possible to determine the
19703 arm_poke_function_name (FILE *stream
, const char *name
)
19705 unsigned long alignlength
;
19706 unsigned long length
;
19709 length
= strlen (name
) + 1;
19710 alignlength
= ROUND_UP_WORD (length
);
19712 ASM_OUTPUT_ASCII (stream
, name
, length
);
19713 ASM_OUTPUT_ALIGN (stream
, 2);
19714 x
= GEN_INT ((unsigned HOST_WIDE_INT
) 0xff000000 + alignlength
);
19715 assemble_aligned_integer (UNITS_PER_WORD
, x
);
19718 /* Place some comments into the assembler stream
19719 describing the current function. */
19721 arm_output_function_prologue (FILE *f
)
19723 unsigned long func_type
;
19725 /* Sanity check. */
19726 gcc_assert (!arm_ccfsm_state
&& !arm_target_insn
);
19728 func_type
= arm_current_func_type ();
19730 switch ((int) ARM_FUNC_TYPE (func_type
))
19733 case ARM_FT_NORMAL
:
19735 case ARM_FT_INTERWORKED
:
19736 asm_fprintf (f
, "\t%@ Function supports interworking.\n");
19739 asm_fprintf (f
, "\t%@ Interrupt Service Routine.\n");
19742 asm_fprintf (f
, "\t%@ Fast Interrupt Service Routine.\n");
19744 case ARM_FT_EXCEPTION
:
19745 asm_fprintf (f
, "\t%@ ARM Exception Handler.\n");
19749 if (IS_NAKED (func_type
))
19750 asm_fprintf (f
, "\t%@ Naked Function: prologue and epilogue provided by programmer.\n");
19752 if (IS_VOLATILE (func_type
))
19753 asm_fprintf (f
, "\t%@ Volatile: function does not return.\n");
19755 if (IS_NESTED (func_type
))
19756 asm_fprintf (f
, "\t%@ Nested: function declared inside another function.\n");
19757 if (IS_STACKALIGN (func_type
))
19758 asm_fprintf (f
, "\t%@ Stack Align: May be called with mis-aligned SP.\n");
19759 if (IS_CMSE_ENTRY (func_type
))
19760 asm_fprintf (f
, "\t%@ Non-secure entry function: called from non-secure code.\n");
19762 asm_fprintf (f
, "\t%@ args = %d, pretend = %d, frame = %wd\n",
19764 crtl
->args
.pretend_args_size
,
19765 (HOST_WIDE_INT
) get_frame_size ());
19767 asm_fprintf (f
, "\t%@ frame_needed = %d, uses_anonymous_args = %d\n",
19768 frame_pointer_needed
,
19769 cfun
->machine
->uses_anonymous_args
);
19771 if (cfun
->machine
->lr_save_eliminated
)
19772 asm_fprintf (f
, "\t%@ link register save eliminated.\n");
19774 if (crtl
->calls_eh_return
)
19775 asm_fprintf (f
, "\t@ Calls __builtin_eh_return.\n");
19780 arm_output_function_epilogue (FILE *)
19782 arm_stack_offsets
*offsets
;
19788 /* Emit any call-via-reg trampolines that are needed for v4t support
19789 of call_reg and call_value_reg type insns. */
19790 for (regno
= 0; regno
< LR_REGNUM
; regno
++)
19792 rtx label
= cfun
->machine
->call_via
[regno
];
19796 switch_to_section (function_section (current_function_decl
));
19797 targetm
.asm_out
.internal_label (asm_out_file
, "L",
19798 CODE_LABEL_NUMBER (label
));
19799 asm_fprintf (asm_out_file
, "\tbx\t%r\n", regno
);
19803 /* ??? Probably not safe to set this here, since it assumes that a
19804 function will be emitted as assembly immediately after we generate
19805 RTL for it. This does not happen for inline functions. */
19806 cfun
->machine
->return_used_this_function
= 0;
19808 else /* TARGET_32BIT */
19810 /* We need to take into account any stack-frame rounding. */
19811 offsets
= arm_get_frame_offsets ();
19813 gcc_assert (!use_return_insn (FALSE
, NULL
)
19814 || (cfun
->machine
->return_used_this_function
!= 0)
19815 || offsets
->saved_regs
== offsets
->outgoing_args
19816 || frame_pointer_needed
);
19820 /* Generate and emit a sequence of insns equivalent to PUSH, but using
19821 STR and STRD. If an even number of registers are being pushed, one
19822 or more STRD patterns are created for each register pair. If an
19823 odd number of registers are pushed, emit an initial STR followed by
19824 as many STRD instructions as are needed. This works best when the
19825 stack is initially 64-bit aligned (the normal case), since it
19826 ensures that each STRD is also 64-bit aligned. */
19828 thumb2_emit_strd_push (unsigned long saved_regs_mask
)
19833 rtx par
= NULL_RTX
;
19834 rtx dwarf
= NULL_RTX
;
19838 num_regs
= bit_count (saved_regs_mask
);
19840 /* Must be at least one register to save, and can't save SP or PC. */
19841 gcc_assert (num_regs
> 0 && num_regs
<= 14);
19842 gcc_assert (!(saved_regs_mask
& (1 << SP_REGNUM
)));
19843 gcc_assert (!(saved_regs_mask
& (1 << PC_REGNUM
)));
19845 /* Create sequence for DWARF info. All the frame-related data for
19846 debugging is held in this wrapper. */
19847 dwarf
= gen_rtx_SEQUENCE (VOIDmode
, rtvec_alloc (num_regs
+ 1));
19849 /* Describe the stack adjustment. */
19850 tmp
= gen_rtx_SET (stack_pointer_rtx
,
19851 plus_constant (Pmode
, stack_pointer_rtx
, -4 * num_regs
));
19852 RTX_FRAME_RELATED_P (tmp
) = 1;
19853 XVECEXP (dwarf
, 0, 0) = tmp
;
19855 /* Find the first register. */
19856 for (regno
= 0; (saved_regs_mask
& (1 << regno
)) == 0; regno
++)
19861 /* If there's an odd number of registers to push. Start off by
19862 pushing a single register. This ensures that subsequent strd
19863 operations are dword aligned (assuming that SP was originally
19864 64-bit aligned). */
19865 if ((num_regs
& 1) != 0)
19867 rtx reg
, mem
, insn
;
19869 reg
= gen_rtx_REG (SImode
, regno
);
19871 mem
= gen_frame_mem (Pmode
, gen_rtx_PRE_DEC (Pmode
,
19872 stack_pointer_rtx
));
19874 mem
= gen_frame_mem (Pmode
,
19876 (Pmode
, stack_pointer_rtx
,
19877 plus_constant (Pmode
, stack_pointer_rtx
,
19880 tmp
= gen_rtx_SET (mem
, reg
);
19881 RTX_FRAME_RELATED_P (tmp
) = 1;
19882 insn
= emit_insn (tmp
);
19883 RTX_FRAME_RELATED_P (insn
) = 1;
19884 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, dwarf
);
19885 tmp
= gen_rtx_SET (gen_frame_mem (Pmode
, stack_pointer_rtx
), reg
);
19886 RTX_FRAME_RELATED_P (tmp
) = 1;
19889 XVECEXP (dwarf
, 0, i
) = tmp
;
19893 while (i
< num_regs
)
19894 if (saved_regs_mask
& (1 << regno
))
19896 rtx reg1
, reg2
, mem1
, mem2
;
19897 rtx tmp0
, tmp1
, tmp2
;
19900 /* Find the register to pair with this one. */
19901 for (regno2
= regno
+ 1; (saved_regs_mask
& (1 << regno2
)) == 0;
19905 reg1
= gen_rtx_REG (SImode
, regno
);
19906 reg2
= gen_rtx_REG (SImode
, regno2
);
19913 mem1
= gen_frame_mem (Pmode
, plus_constant (Pmode
,
19916 mem2
= gen_frame_mem (Pmode
, plus_constant (Pmode
,
19918 -4 * (num_regs
- 1)));
19919 tmp0
= gen_rtx_SET (stack_pointer_rtx
,
19920 plus_constant (Pmode
, stack_pointer_rtx
,
19922 tmp1
= gen_rtx_SET (mem1
, reg1
);
19923 tmp2
= gen_rtx_SET (mem2
, reg2
);
19924 RTX_FRAME_RELATED_P (tmp0
) = 1;
19925 RTX_FRAME_RELATED_P (tmp1
) = 1;
19926 RTX_FRAME_RELATED_P (tmp2
) = 1;
19927 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (3));
19928 XVECEXP (par
, 0, 0) = tmp0
;
19929 XVECEXP (par
, 0, 1) = tmp1
;
19930 XVECEXP (par
, 0, 2) = tmp2
;
19931 insn
= emit_insn (par
);
19932 RTX_FRAME_RELATED_P (insn
) = 1;
19933 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, dwarf
);
19937 mem1
= gen_frame_mem (Pmode
, plus_constant (Pmode
,
19940 mem2
= gen_frame_mem (Pmode
, plus_constant (Pmode
,
19943 tmp1
= gen_rtx_SET (mem1
, reg1
);
19944 tmp2
= gen_rtx_SET (mem2
, reg2
);
19945 RTX_FRAME_RELATED_P (tmp1
) = 1;
19946 RTX_FRAME_RELATED_P (tmp2
) = 1;
19947 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (2));
19948 XVECEXP (par
, 0, 0) = tmp1
;
19949 XVECEXP (par
, 0, 1) = tmp2
;
19953 /* Create unwind information. This is an approximation. */
19954 tmp1
= gen_rtx_SET (gen_frame_mem (Pmode
,
19955 plus_constant (Pmode
,
19959 tmp2
= gen_rtx_SET (gen_frame_mem (Pmode
,
19960 plus_constant (Pmode
,
19965 RTX_FRAME_RELATED_P (tmp1
) = 1;
19966 RTX_FRAME_RELATED_P (tmp2
) = 1;
19967 XVECEXP (dwarf
, 0, i
+ 1) = tmp1
;
19968 XVECEXP (dwarf
, 0, i
+ 2) = tmp2
;
19970 regno
= regno2
+ 1;
19978 /* STRD in ARM mode requires consecutive registers. This function emits STRD
19979 whenever possible, otherwise it emits single-word stores. The first store
19980 also allocates stack space for all saved registers, using writeback with
19981 post-addressing mode. All other stores use offset addressing. If no STRD
19982 can be emitted, this function emits a sequence of single-word stores,
19983 and not an STM as before, because single-word stores provide more freedom
19984 scheduling and can be turned into an STM by peephole optimizations. */
19986 arm_emit_strd_push (unsigned long saved_regs_mask
)
19989 int i
, j
, dwarf_index
= 0;
19991 rtx dwarf
= NULL_RTX
;
19992 rtx insn
= NULL_RTX
;
19995 /* TODO: A more efficient code can be emitted by changing the
19996 layout, e.g., first push all pairs that can use STRD to keep the
19997 stack aligned, and then push all other registers. */
19998 for (i
= 0; i
<= LAST_ARM_REGNUM
; i
++)
19999 if (saved_regs_mask
& (1 << i
))
20002 gcc_assert (!(saved_regs_mask
& (1 << SP_REGNUM
)));
20003 gcc_assert (!(saved_regs_mask
& (1 << PC_REGNUM
)));
20004 gcc_assert (num_regs
> 0);
20006 /* Create sequence for DWARF info. */
20007 dwarf
= gen_rtx_SEQUENCE (VOIDmode
, rtvec_alloc (num_regs
+ 1));
20009 /* For dwarf info, we generate explicit stack update. */
20010 tmp
= gen_rtx_SET (stack_pointer_rtx
,
20011 plus_constant (Pmode
, stack_pointer_rtx
, -4 * num_regs
));
20012 RTX_FRAME_RELATED_P (tmp
) = 1;
20013 XVECEXP (dwarf
, 0, dwarf_index
++) = tmp
;
20015 /* Save registers. */
20016 offset
= - 4 * num_regs
;
20018 while (j
<= LAST_ARM_REGNUM
)
20019 if (saved_regs_mask
& (1 << j
))
20022 && (saved_regs_mask
& (1 << (j
+ 1))))
20024 /* Current register and previous register form register pair for
20025 which STRD can be generated. */
20028 /* Allocate stack space for all saved registers. */
20029 tmp
= plus_constant (Pmode
, stack_pointer_rtx
, offset
);
20030 tmp
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, tmp
);
20031 mem
= gen_frame_mem (DImode
, tmp
);
20034 else if (offset
> 0)
20035 mem
= gen_frame_mem (DImode
,
20036 plus_constant (Pmode
,
20040 mem
= gen_frame_mem (DImode
, stack_pointer_rtx
);
20042 tmp
= gen_rtx_SET (mem
, gen_rtx_REG (DImode
, j
));
20043 RTX_FRAME_RELATED_P (tmp
) = 1;
20044 tmp
= emit_insn (tmp
);
20046 /* Record the first store insn. */
20047 if (dwarf_index
== 1)
20050 /* Generate dwarf info. */
20051 mem
= gen_frame_mem (SImode
,
20052 plus_constant (Pmode
,
20055 tmp
= gen_rtx_SET (mem
, gen_rtx_REG (SImode
, j
));
20056 RTX_FRAME_RELATED_P (tmp
) = 1;
20057 XVECEXP (dwarf
, 0, dwarf_index
++) = tmp
;
20059 mem
= gen_frame_mem (SImode
,
20060 plus_constant (Pmode
,
20063 tmp
= gen_rtx_SET (mem
, gen_rtx_REG (SImode
, j
+ 1));
20064 RTX_FRAME_RELATED_P (tmp
) = 1;
20065 XVECEXP (dwarf
, 0, dwarf_index
++) = tmp
;
20072 /* Emit a single word store. */
20075 /* Allocate stack space for all saved registers. */
20076 tmp
= plus_constant (Pmode
, stack_pointer_rtx
, offset
);
20077 tmp
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, tmp
);
20078 mem
= gen_frame_mem (SImode
, tmp
);
20081 else if (offset
> 0)
20082 mem
= gen_frame_mem (SImode
,
20083 plus_constant (Pmode
,
20087 mem
= gen_frame_mem (SImode
, stack_pointer_rtx
);
20089 tmp
= gen_rtx_SET (mem
, gen_rtx_REG (SImode
, j
));
20090 RTX_FRAME_RELATED_P (tmp
) = 1;
20091 tmp
= emit_insn (tmp
);
20093 /* Record the first store insn. */
20094 if (dwarf_index
== 1)
20097 /* Generate dwarf info. */
20098 mem
= gen_frame_mem (SImode
,
20099 plus_constant(Pmode
,
20102 tmp
= gen_rtx_SET (mem
, gen_rtx_REG (SImode
, j
));
20103 RTX_FRAME_RELATED_P (tmp
) = 1;
20104 XVECEXP (dwarf
, 0, dwarf_index
++) = tmp
;
20113 /* Attach dwarf info to the first insn we generate. */
20114 gcc_assert (insn
!= NULL_RTX
);
20115 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, dwarf
);
20116 RTX_FRAME_RELATED_P (insn
) = 1;
20119 /* Generate and emit an insn that we will recognize as a push_multi.
20120 Unfortunately, since this insn does not reflect very well the actual
20121 semantics of the operation, we need to annotate the insn for the benefit
20122 of DWARF2 frame unwind information. DWARF_REGS_MASK is a subset of
20123 MASK for registers that should be annotated for DWARF2 frame unwind
20126 emit_multi_reg_push (unsigned long mask
, unsigned long dwarf_regs_mask
)
20129 int num_dwarf_regs
= 0;
20133 int dwarf_par_index
;
20136 /* We don't record the PC in the dwarf frame information. */
20137 dwarf_regs_mask
&= ~(1 << PC_REGNUM
);
20139 for (i
= 0; i
<= LAST_ARM_REGNUM
; i
++)
20141 if (mask
& (1 << i
))
20143 if (dwarf_regs_mask
& (1 << i
))
20147 gcc_assert (num_regs
&& num_regs
<= 16);
20148 gcc_assert ((dwarf_regs_mask
& ~mask
) == 0);
20150 /* For the body of the insn we are going to generate an UNSPEC in
20151 parallel with several USEs. This allows the insn to be recognized
20152 by the push_multi pattern in the arm.md file.
20154 The body of the insn looks something like this:
20157 (set (mem:BLK (pre_modify:SI (reg:SI sp)
20158 (const_int:SI <num>)))
20159 (unspec:BLK [(reg:SI r4)] UNSPEC_PUSH_MULT))
20165 For the frame note however, we try to be more explicit and actually
20166 show each register being stored into the stack frame, plus a (single)
20167 decrement of the stack pointer. We do it this way in order to be
20168 friendly to the stack unwinding code, which only wants to see a single
20169 stack decrement per instruction. The RTL we generate for the note looks
20170 something like this:
20173 (set (reg:SI sp) (plus:SI (reg:SI sp) (const_int -20)))
20174 (set (mem:SI (reg:SI sp)) (reg:SI r4))
20175 (set (mem:SI (plus:SI (reg:SI sp) (const_int 4))) (reg:SI XX))
20176 (set (mem:SI (plus:SI (reg:SI sp) (const_int 8))) (reg:SI YY))
20180 FIXME:: In an ideal world the PRE_MODIFY would not exist and
20181 instead we'd have a parallel expression detailing all
20182 the stores to the various memory addresses so that debug
20183 information is more up-to-date. Remember however while writing
20184 this to take care of the constraints with the push instruction.
20186 Note also that this has to be taken care of for the VFP registers.
20188 For more see PR43399. */
20190 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (num_regs
));
20191 dwarf
= gen_rtx_SEQUENCE (VOIDmode
, rtvec_alloc (num_dwarf_regs
+ 1));
20192 dwarf_par_index
= 1;
20194 for (i
= 0; i
<= LAST_ARM_REGNUM
; i
++)
20196 if (mask
& (1 << i
))
20198 reg
= gen_rtx_REG (SImode
, i
);
20200 XVECEXP (par
, 0, 0)
20201 = gen_rtx_SET (gen_frame_mem
20203 gen_rtx_PRE_MODIFY (Pmode
,
20206 (Pmode
, stack_pointer_rtx
,
20209 gen_rtx_UNSPEC (BLKmode
,
20210 gen_rtvec (1, reg
),
20211 UNSPEC_PUSH_MULT
));
20213 if (dwarf_regs_mask
& (1 << i
))
20215 tmp
= gen_rtx_SET (gen_frame_mem (SImode
, stack_pointer_rtx
),
20217 RTX_FRAME_RELATED_P (tmp
) = 1;
20218 XVECEXP (dwarf
, 0, dwarf_par_index
++) = tmp
;
20225 for (j
= 1, i
++; j
< num_regs
; i
++)
20227 if (mask
& (1 << i
))
20229 reg
= gen_rtx_REG (SImode
, i
);
20231 XVECEXP (par
, 0, j
) = gen_rtx_USE (VOIDmode
, reg
);
20233 if (dwarf_regs_mask
& (1 << i
))
20236 = gen_rtx_SET (gen_frame_mem
20238 plus_constant (Pmode
, stack_pointer_rtx
,
20241 RTX_FRAME_RELATED_P (tmp
) = 1;
20242 XVECEXP (dwarf
, 0, dwarf_par_index
++) = tmp
;
20249 par
= emit_insn (par
);
20251 tmp
= gen_rtx_SET (stack_pointer_rtx
,
20252 plus_constant (Pmode
, stack_pointer_rtx
, -4 * num_regs
));
20253 RTX_FRAME_RELATED_P (tmp
) = 1;
20254 XVECEXP (dwarf
, 0, 0) = tmp
;
20256 add_reg_note (par
, REG_FRAME_RELATED_EXPR
, dwarf
);
20261 /* Add a REG_CFA_ADJUST_CFA REG note to INSN.
20262 SIZE is the offset to be adjusted.
20263 DEST and SRC might be stack_pointer_rtx or hard_frame_pointer_rtx. */
20265 arm_add_cfa_adjust_cfa_note (rtx insn
, int size
, rtx dest
, rtx src
)
20269 RTX_FRAME_RELATED_P (insn
) = 1;
20270 dwarf
= gen_rtx_SET (dest
, plus_constant (Pmode
, src
, size
));
20271 add_reg_note (insn
, REG_CFA_ADJUST_CFA
, dwarf
);
20274 /* Generate and emit an insn pattern that we will recognize as a pop_multi.
20275 SAVED_REGS_MASK shows which registers need to be restored.
20277 Unfortunately, since this insn does not reflect very well the actual
20278 semantics of the operation, we need to annotate the insn for the benefit
20279 of DWARF2 frame unwind information. */
20281 arm_emit_multi_reg_pop (unsigned long saved_regs_mask
)
20286 rtx dwarf
= NULL_RTX
;
20288 bool return_in_pc
= saved_regs_mask
& (1 << PC_REGNUM
);
20292 offset_adj
= return_in_pc
? 1 : 0;
20293 for (i
= 0; i
<= LAST_ARM_REGNUM
; i
++)
20294 if (saved_regs_mask
& (1 << i
))
20297 gcc_assert (num_regs
&& num_regs
<= 16);
20299 /* If SP is in reglist, then we don't emit SP update insn. */
20300 emit_update
= (saved_regs_mask
& (1 << SP_REGNUM
)) ? 0 : 1;
20302 /* The parallel needs to hold num_regs SETs
20303 and one SET for the stack update. */
20304 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (num_regs
+ emit_update
+ offset_adj
));
20307 XVECEXP (par
, 0, 0) = ret_rtx
;
20311 /* Increment the stack pointer, based on there being
20312 num_regs 4-byte registers to restore. */
20313 tmp
= gen_rtx_SET (stack_pointer_rtx
,
20314 plus_constant (Pmode
,
20317 RTX_FRAME_RELATED_P (tmp
) = 1;
20318 XVECEXP (par
, 0, offset_adj
) = tmp
;
20321 /* Now restore every reg, which may include PC. */
20322 for (j
= 0, i
= 0; j
< num_regs
; i
++)
20323 if (saved_regs_mask
& (1 << i
))
20325 reg
= gen_rtx_REG (SImode
, i
);
20326 if ((num_regs
== 1) && emit_update
&& !return_in_pc
)
20328 /* Emit single load with writeback. */
20329 tmp
= gen_frame_mem (SImode
,
20330 gen_rtx_POST_INC (Pmode
,
20331 stack_pointer_rtx
));
20332 tmp
= emit_insn (gen_rtx_SET (reg
, tmp
));
20333 REG_NOTES (tmp
) = alloc_reg_note (REG_CFA_RESTORE
, reg
, dwarf
);
20337 tmp
= gen_rtx_SET (reg
,
20340 plus_constant (Pmode
, stack_pointer_rtx
, 4 * j
)));
20341 RTX_FRAME_RELATED_P (tmp
) = 1;
20342 XVECEXP (par
, 0, j
+ emit_update
+ offset_adj
) = tmp
;
20344 /* We need to maintain a sequence for DWARF info too. As dwarf info
20345 should not have PC, skip PC. */
20346 if (i
!= PC_REGNUM
)
20347 dwarf
= alloc_reg_note (REG_CFA_RESTORE
, reg
, dwarf
);
20353 par
= emit_jump_insn (par
);
20355 par
= emit_insn (par
);
20357 REG_NOTES (par
) = dwarf
;
20359 arm_add_cfa_adjust_cfa_note (par
, UNITS_PER_WORD
* num_regs
,
20360 stack_pointer_rtx
, stack_pointer_rtx
);
20363 /* Generate and emit an insn pattern that we will recognize as a pop_multi
20364 of NUM_REGS consecutive VFP regs, starting at FIRST_REG.
20366 Unfortunately, since this insn does not reflect very well the actual
20367 semantics of the operation, we need to annotate the insn for the benefit
20368 of DWARF2 frame unwind information. */
20370 arm_emit_vfp_multi_reg_pop (int first_reg
, int num_regs
, rtx base_reg
)
20374 rtx dwarf
= NULL_RTX
;
20377 gcc_assert (num_regs
&& num_regs
<= 32);
20379 /* Workaround ARM10 VFPr1 bug. */
20380 if (num_regs
== 2 && !arm_arch6
)
20382 if (first_reg
== 15)
20388 /* We can emit at most 16 D-registers in a single pop_multi instruction, and
20389 there could be up to 32 D-registers to restore.
20390 If there are more than 16 D-registers, make two recursive calls,
20391 each of which emits one pop_multi instruction. */
20394 arm_emit_vfp_multi_reg_pop (first_reg
, 16, base_reg
);
20395 arm_emit_vfp_multi_reg_pop (first_reg
+ 16, num_regs
- 16, base_reg
);
20399 /* The parallel needs to hold num_regs SETs
20400 and one SET for the stack update. */
20401 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (num_regs
+ 1));
20403 /* Increment the stack pointer, based on there being
20404 num_regs 8-byte registers to restore. */
20405 tmp
= gen_rtx_SET (base_reg
, plus_constant (Pmode
, base_reg
, 8 * num_regs
));
20406 RTX_FRAME_RELATED_P (tmp
) = 1;
20407 XVECEXP (par
, 0, 0) = tmp
;
20409 /* Now show every reg that will be restored, using a SET for each. */
20410 for (j
= 0, i
=first_reg
; j
< num_regs
; i
+= 2)
20412 reg
= gen_rtx_REG (DFmode
, i
);
20414 tmp
= gen_rtx_SET (reg
,
20417 plus_constant (Pmode
, base_reg
, 8 * j
)));
20418 RTX_FRAME_RELATED_P (tmp
) = 1;
20419 XVECEXP (par
, 0, j
+ 1) = tmp
;
20421 dwarf
= alloc_reg_note (REG_CFA_RESTORE
, reg
, dwarf
);
20426 par
= emit_insn (par
);
20427 REG_NOTES (par
) = dwarf
;
20429 /* Make sure cfa doesn't leave with IP_REGNUM to allow unwinding fron FP. */
20430 if (REGNO (base_reg
) == IP_REGNUM
)
20432 RTX_FRAME_RELATED_P (par
) = 1;
20433 add_reg_note (par
, REG_CFA_DEF_CFA
, hard_frame_pointer_rtx
);
20436 arm_add_cfa_adjust_cfa_note (par
, 2 * UNITS_PER_WORD
* num_regs
,
20437 base_reg
, base_reg
);
20440 /* Generate and emit a pattern that will be recognized as LDRD pattern. If even
20441 number of registers are being popped, multiple LDRD patterns are created for
20442 all register pairs. If odd number of registers are popped, last register is
20443 loaded by using LDR pattern. */
20445 thumb2_emit_ldrd_pop (unsigned long saved_regs_mask
)
20449 rtx par
= NULL_RTX
;
20450 rtx dwarf
= NULL_RTX
;
20451 rtx tmp
, reg
, tmp1
;
20452 bool return_in_pc
= saved_regs_mask
& (1 << PC_REGNUM
);
20454 for (i
= 0; i
<= LAST_ARM_REGNUM
; i
++)
20455 if (saved_regs_mask
& (1 << i
))
20458 gcc_assert (num_regs
&& num_regs
<= 16);
20460 /* We cannot generate ldrd for PC. Hence, reduce the count if PC is
20461 to be popped. So, if num_regs is even, now it will become odd,
20462 and we can generate pop with PC. If num_regs is odd, it will be
20463 even now, and ldr with return can be generated for PC. */
20467 gcc_assert (!(saved_regs_mask
& (1 << SP_REGNUM
)));
20469 /* Var j iterates over all the registers to gather all the registers in
20470 saved_regs_mask. Var i gives index of saved registers in stack frame.
20471 A PARALLEL RTX of register-pair is created here, so that pattern for
20472 LDRD can be matched. As PC is always last register to be popped, and
20473 we have already decremented num_regs if PC, we don't have to worry
20474 about PC in this loop. */
20475 for (i
= 0, j
= 0; i
< (num_regs
- (num_regs
% 2)); j
++)
20476 if (saved_regs_mask
& (1 << j
))
20478 /* Create RTX for memory load. */
20479 reg
= gen_rtx_REG (SImode
, j
);
20480 tmp
= gen_rtx_SET (reg
,
20481 gen_frame_mem (SImode
,
20482 plus_constant (Pmode
,
20483 stack_pointer_rtx
, 4 * i
)));
20484 RTX_FRAME_RELATED_P (tmp
) = 1;
20488 /* When saved-register index (i) is even, the RTX to be emitted is
20489 yet to be created. Hence create it first. The LDRD pattern we
20490 are generating is :
20491 [ (SET (reg_t0) (MEM (PLUS (SP) (NUM))))
20492 (SET (reg_t1) (MEM (PLUS (SP) (NUM + 4)))) ]
20493 where target registers need not be consecutive. */
20494 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (2));
20498 /* ith register is added in PARALLEL RTX. If i is even, the reg_i is
20499 added as 0th element and if i is odd, reg_i is added as 1st element
20500 of LDRD pattern shown above. */
20501 XVECEXP (par
, 0, (i
% 2)) = tmp
;
20502 dwarf
= alloc_reg_note (REG_CFA_RESTORE
, reg
, dwarf
);
20506 /* When saved-register index (i) is odd, RTXs for both the registers
20507 to be loaded are generated in above given LDRD pattern, and the
20508 pattern can be emitted now. */
20509 par
= emit_insn (par
);
20510 REG_NOTES (par
) = dwarf
;
20511 RTX_FRAME_RELATED_P (par
) = 1;
20517 /* If the number of registers pushed is odd AND return_in_pc is false OR
20518 number of registers are even AND return_in_pc is true, last register is
20519 popped using LDR. It can be PC as well. Hence, adjust the stack first and
20520 then LDR with post increment. */
20522 /* Increment the stack pointer, based on there being
20523 num_regs 4-byte registers to restore. */
20524 tmp
= gen_rtx_SET (stack_pointer_rtx
,
20525 plus_constant (Pmode
, stack_pointer_rtx
, 4 * i
));
20526 RTX_FRAME_RELATED_P (tmp
) = 1;
20527 tmp
= emit_insn (tmp
);
20530 arm_add_cfa_adjust_cfa_note (tmp
, UNITS_PER_WORD
* i
,
20531 stack_pointer_rtx
, stack_pointer_rtx
);
20536 if (((num_regs
% 2) == 1 && !return_in_pc
)
20537 || ((num_regs
% 2) == 0 && return_in_pc
))
20539 /* Scan for the single register to be popped. Skip until the saved
20540 register is found. */
20541 for (; (saved_regs_mask
& (1 << j
)) == 0; j
++);
20543 /* Gen LDR with post increment here. */
20544 tmp1
= gen_rtx_MEM (SImode
,
20545 gen_rtx_POST_INC (SImode
,
20546 stack_pointer_rtx
));
20547 set_mem_alias_set (tmp1
, get_frame_alias_set ());
20549 reg
= gen_rtx_REG (SImode
, j
);
20550 tmp
= gen_rtx_SET (reg
, tmp1
);
20551 RTX_FRAME_RELATED_P (tmp
) = 1;
20552 dwarf
= alloc_reg_note (REG_CFA_RESTORE
, reg
, dwarf
);
20556 /* If return_in_pc, j must be PC_REGNUM. */
20557 gcc_assert (j
== PC_REGNUM
);
20558 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (2));
20559 XVECEXP (par
, 0, 0) = ret_rtx
;
20560 XVECEXP (par
, 0, 1) = tmp
;
20561 par
= emit_jump_insn (par
);
20565 par
= emit_insn (tmp
);
20566 REG_NOTES (par
) = dwarf
;
20567 arm_add_cfa_adjust_cfa_note (par
, UNITS_PER_WORD
,
20568 stack_pointer_rtx
, stack_pointer_rtx
);
20572 else if ((num_regs
% 2) == 1 && return_in_pc
)
20574 /* There are 2 registers to be popped. So, generate the pattern
20575 pop_multiple_with_stack_update_and_return to pop in PC. */
20576 arm_emit_multi_reg_pop (saved_regs_mask
& (~((1 << j
) - 1)));
20582 /* LDRD in ARM mode needs consecutive registers as operands. This function
20583 emits LDRD whenever possible, otherwise it emits single-word loads. It uses
20584 offset addressing and then generates one separate stack udpate. This provides
20585 more scheduling freedom, compared to writeback on every load. However,
20586 if the function returns using load into PC directly
20587 (i.e., if PC is in SAVED_REGS_MASK), the stack needs to be updated
20588 before the last load. TODO: Add a peephole optimization to recognize
20589 the new epilogue sequence as an LDM instruction whenever possible. TODO: Add
20590 peephole optimization to merge the load at stack-offset zero
20591 with the stack update instruction using load with writeback
20592 in post-index addressing mode. */
20594 arm_emit_ldrd_pop (unsigned long saved_regs_mask
)
20598 rtx par
= NULL_RTX
;
20599 rtx dwarf
= NULL_RTX
;
20602 /* Restore saved registers. */
20603 gcc_assert (!((saved_regs_mask
& (1 << SP_REGNUM
))));
20605 while (j
<= LAST_ARM_REGNUM
)
20606 if (saved_regs_mask
& (1 << j
))
20609 && (saved_regs_mask
& (1 << (j
+ 1)))
20610 && (j
+ 1) != PC_REGNUM
)
20612 /* Current register and next register form register pair for which
20613 LDRD can be generated. PC is always the last register popped, and
20614 we handle it separately. */
20616 mem
= gen_frame_mem (DImode
,
20617 plus_constant (Pmode
,
20621 mem
= gen_frame_mem (DImode
, stack_pointer_rtx
);
20623 tmp
= gen_rtx_SET (gen_rtx_REG (DImode
, j
), mem
);
20624 tmp
= emit_insn (tmp
);
20625 RTX_FRAME_RELATED_P (tmp
) = 1;
20627 /* Generate dwarf info. */
20629 dwarf
= alloc_reg_note (REG_CFA_RESTORE
,
20630 gen_rtx_REG (SImode
, j
),
20632 dwarf
= alloc_reg_note (REG_CFA_RESTORE
,
20633 gen_rtx_REG (SImode
, j
+ 1),
20636 REG_NOTES (tmp
) = dwarf
;
20641 else if (j
!= PC_REGNUM
)
20643 /* Emit a single word load. */
20645 mem
= gen_frame_mem (SImode
,
20646 plus_constant (Pmode
,
20650 mem
= gen_frame_mem (SImode
, stack_pointer_rtx
);
20652 tmp
= gen_rtx_SET (gen_rtx_REG (SImode
, j
), mem
);
20653 tmp
= emit_insn (tmp
);
20654 RTX_FRAME_RELATED_P (tmp
) = 1;
20656 /* Generate dwarf info. */
20657 REG_NOTES (tmp
) = alloc_reg_note (REG_CFA_RESTORE
,
20658 gen_rtx_REG (SImode
, j
),
20664 else /* j == PC_REGNUM */
20670 /* Update the stack. */
20673 tmp
= gen_rtx_SET (stack_pointer_rtx
,
20674 plus_constant (Pmode
,
20677 tmp
= emit_insn (tmp
);
20678 arm_add_cfa_adjust_cfa_note (tmp
, offset
,
20679 stack_pointer_rtx
, stack_pointer_rtx
);
20683 if (saved_regs_mask
& (1 << PC_REGNUM
))
20685 /* Only PC is to be popped. */
20686 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (2));
20687 XVECEXP (par
, 0, 0) = ret_rtx
;
20688 tmp
= gen_rtx_SET (gen_rtx_REG (SImode
, PC_REGNUM
),
20689 gen_frame_mem (SImode
,
20690 gen_rtx_POST_INC (SImode
,
20691 stack_pointer_rtx
)));
20692 RTX_FRAME_RELATED_P (tmp
) = 1;
20693 XVECEXP (par
, 0, 1) = tmp
;
20694 par
= emit_jump_insn (par
);
20696 /* Generate dwarf info. */
20697 dwarf
= alloc_reg_note (REG_CFA_RESTORE
,
20698 gen_rtx_REG (SImode
, PC_REGNUM
),
20700 REG_NOTES (par
) = dwarf
;
20701 arm_add_cfa_adjust_cfa_note (par
, UNITS_PER_WORD
,
20702 stack_pointer_rtx
, stack_pointer_rtx
);
20706 /* Calculate the size of the return value that is passed in registers. */
20708 arm_size_return_regs (void)
20712 if (crtl
->return_rtx
!= 0)
20713 mode
= GET_MODE (crtl
->return_rtx
);
20715 mode
= DECL_MODE (DECL_RESULT (current_function_decl
));
20717 return GET_MODE_SIZE (mode
);
20720 /* Return true if the current function needs to save/restore LR. */
20722 thumb_force_lr_save (void)
20724 return !cfun
->machine
->lr_save_eliminated
20726 || thumb_far_jump_used_p ()
20727 || df_regs_ever_live_p (LR_REGNUM
));
20730 /* We do not know if r3 will be available because
20731 we do have an indirect tailcall happening in this
20732 particular case. */
20734 is_indirect_tailcall_p (rtx call
)
20736 rtx pat
= PATTERN (call
);
20738 /* Indirect tail call. */
20739 pat
= XVECEXP (pat
, 0, 0);
20740 if (GET_CODE (pat
) == SET
)
20741 pat
= SET_SRC (pat
);
20743 pat
= XEXP (XEXP (pat
, 0), 0);
20744 return REG_P (pat
);
20747 /* Return true if r3 is used by any of the tail call insns in the
20748 current function. */
20750 any_sibcall_could_use_r3 (void)
20755 if (!crtl
->tail_call_emit
)
20757 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
)
20758 if (e
->flags
& EDGE_SIBCALL
)
20760 rtx_insn
*call
= BB_END (e
->src
);
20761 if (!CALL_P (call
))
20762 call
= prev_nonnote_nondebug_insn (call
);
20763 gcc_assert (CALL_P (call
) && SIBLING_CALL_P (call
));
20764 if (find_regno_fusage (call
, USE
, 3)
20765 || is_indirect_tailcall_p (call
))
20772 /* Compute the distance from register FROM to register TO.
20773 These can be the arg pointer (26), the soft frame pointer (25),
20774 the stack pointer (13) or the hard frame pointer (11).
20775 In thumb mode r7 is used as the soft frame pointer, if needed.
20776 Typical stack layout looks like this:
20778 old stack pointer -> | |
20781 | | saved arguments for
20782 | | vararg functions
20785 hard FP & arg pointer -> | | \
20793 soft frame pointer -> | | /
20798 locals base pointer -> | | /
20803 current stack pointer -> | | /
20806 For a given function some or all of these stack components
20807 may not be needed, giving rise to the possibility of
20808 eliminating some of the registers.
20810 The values returned by this function must reflect the behavior
20811 of arm_expand_prologue () and arm_compute_save_core_reg_mask ().
20813 The sign of the number returned reflects the direction of stack
20814 growth, so the values are positive for all eliminations except
20815 from the soft frame pointer to the hard frame pointer.
20817 SFP may point just inside the local variables block to ensure correct
20821 /* Return cached stack offsets. */
20823 static arm_stack_offsets
*
20824 arm_get_frame_offsets (void)
20826 struct arm_stack_offsets
*offsets
;
20828 offsets
= &cfun
->machine
->stack_offsets
;
20834 /* Calculate stack offsets. These are used to calculate register elimination
20835 offsets and in prologue/epilogue code. Also calculates which registers
20836 should be saved. */
20839 arm_compute_frame_layout (void)
20841 struct arm_stack_offsets
*offsets
;
20842 unsigned long func_type
;
20845 HOST_WIDE_INT frame_size
;
20848 offsets
= &cfun
->machine
->stack_offsets
;
20850 /* Initially this is the size of the local variables. It will translated
20851 into an offset once we have determined the size of preceding data. */
20852 frame_size
= ROUND_UP_WORD (get_frame_size ());
20854 /* Space for variadic functions. */
20855 offsets
->saved_args
= crtl
->args
.pretend_args_size
;
20857 /* In Thumb mode this is incorrect, but never used. */
20859 = (offsets
->saved_args
20860 + arm_compute_static_chain_stack_bytes ()
20861 + (frame_pointer_needed
? 4 : 0));
20865 unsigned int regno
;
20867 offsets
->saved_regs_mask
= arm_compute_save_core_reg_mask ();
20868 core_saved
= bit_count (offsets
->saved_regs_mask
) * 4;
20869 saved
= core_saved
;
20871 /* We know that SP will be doubleword aligned on entry, and we must
20872 preserve that condition at any subroutine call. We also require the
20873 soft frame pointer to be doubleword aligned. */
20875 if (TARGET_REALLY_IWMMXT
)
20877 /* Check for the call-saved iWMMXt registers. */
20878 for (regno
= FIRST_IWMMXT_REGNUM
;
20879 regno
<= LAST_IWMMXT_REGNUM
;
20881 if (df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
20885 func_type
= arm_current_func_type ();
20886 /* Space for saved VFP registers. */
20887 if (! IS_VOLATILE (func_type
)
20888 && TARGET_HARD_FLOAT
)
20889 saved
+= arm_get_vfp_saved_size ();
20891 else /* TARGET_THUMB1 */
20893 offsets
->saved_regs_mask
= thumb1_compute_save_core_reg_mask ();
20894 core_saved
= bit_count (offsets
->saved_regs_mask
) * 4;
20895 saved
= core_saved
;
20896 if (TARGET_BACKTRACE
)
20900 /* Saved registers include the stack frame. */
20901 offsets
->saved_regs
20902 = offsets
->saved_args
+ arm_compute_static_chain_stack_bytes () + saved
;
20903 offsets
->soft_frame
= offsets
->saved_regs
+ CALLER_INTERWORKING_SLOT_SIZE
;
20905 /* A leaf function does not need any stack alignment if it has nothing
20907 if (crtl
->is_leaf
&& frame_size
== 0
20908 /* However if it calls alloca(), we have a dynamically allocated
20909 block of BIGGEST_ALIGNMENT on stack, so still do stack alignment. */
20910 && ! cfun
->calls_alloca
)
20912 offsets
->outgoing_args
= offsets
->soft_frame
;
20913 offsets
->locals_base
= offsets
->soft_frame
;
20917 /* Ensure SFP has the correct alignment. */
20918 if (ARM_DOUBLEWORD_ALIGN
20919 && (offsets
->soft_frame
& 7))
20921 offsets
->soft_frame
+= 4;
20922 /* Try to align stack by pushing an extra reg. Don't bother doing this
20923 when there is a stack frame as the alignment will be rolled into
20924 the normal stack adjustment. */
20925 if (frame_size
+ crtl
->outgoing_args_size
== 0)
20929 /* Register r3 is caller-saved. Normally it does not need to be
20930 saved on entry by the prologue. However if we choose to save
20931 it for padding then we may confuse the compiler into thinking
20932 a prologue sequence is required when in fact it is not. This
20933 will occur when shrink-wrapping if r3 is used as a scratch
20934 register and there are no other callee-saved writes.
20936 This situation can be avoided when other callee-saved registers
20937 are available and r3 is not mandatory if we choose a callee-saved
20938 register for padding. */
20939 bool prefer_callee_reg_p
= false;
20941 /* If it is safe to use r3, then do so. This sometimes
20942 generates better code on Thumb-2 by avoiding the need to
20943 use 32-bit push/pop instructions. */
20944 if (! any_sibcall_could_use_r3 ()
20945 && arm_size_return_regs () <= 12
20946 && (offsets
->saved_regs_mask
& (1 << 3)) == 0
20948 || !(TARGET_LDRD
&& current_tune
->prefer_ldrd_strd
)))
20951 if (!TARGET_THUMB2
)
20952 prefer_callee_reg_p
= true;
20955 || prefer_callee_reg_p
)
20957 for (i
= 4; i
<= (TARGET_THUMB1
? LAST_LO_REGNUM
: 11); i
++)
20959 /* Avoid fixed registers; they may be changed at
20960 arbitrary times so it's unsafe to restore them
20961 during the epilogue. */
20963 && (offsets
->saved_regs_mask
& (1 << i
)) == 0)
20973 offsets
->saved_regs
+= 4;
20974 offsets
->saved_regs_mask
|= (1 << reg
);
20979 offsets
->locals_base
= offsets
->soft_frame
+ frame_size
;
20980 offsets
->outgoing_args
= (offsets
->locals_base
20981 + crtl
->outgoing_args_size
);
20983 if (ARM_DOUBLEWORD_ALIGN
)
20985 /* Ensure SP remains doubleword aligned. */
20986 if (offsets
->outgoing_args
& 7)
20987 offsets
->outgoing_args
+= 4;
20988 gcc_assert (!(offsets
->outgoing_args
& 7));
20993 /* Calculate the relative offsets for the different stack pointers. Positive
20994 offsets are in the direction of stack growth. */
20997 arm_compute_initial_elimination_offset (unsigned int from
, unsigned int to
)
20999 arm_stack_offsets
*offsets
;
21001 offsets
= arm_get_frame_offsets ();
21003 /* OK, now we have enough information to compute the distances.
21004 There must be an entry in these switch tables for each pair
21005 of registers in ELIMINABLE_REGS, even if some of the entries
21006 seem to be redundant or useless. */
21009 case ARG_POINTER_REGNUM
:
21012 case THUMB_HARD_FRAME_POINTER_REGNUM
:
21015 case FRAME_POINTER_REGNUM
:
21016 /* This is the reverse of the soft frame pointer
21017 to hard frame pointer elimination below. */
21018 return offsets
->soft_frame
- offsets
->saved_args
;
21020 case ARM_HARD_FRAME_POINTER_REGNUM
:
21021 /* This is only non-zero in the case where the static chain register
21022 is stored above the frame. */
21023 return offsets
->frame
- offsets
->saved_args
- 4;
21025 case STACK_POINTER_REGNUM
:
21026 /* If nothing has been pushed on the stack at all
21027 then this will return -4. This *is* correct! */
21028 return offsets
->outgoing_args
- (offsets
->saved_args
+ 4);
21031 gcc_unreachable ();
21033 gcc_unreachable ();
21035 case FRAME_POINTER_REGNUM
:
21038 case THUMB_HARD_FRAME_POINTER_REGNUM
:
21041 case ARM_HARD_FRAME_POINTER_REGNUM
:
21042 /* The hard frame pointer points to the top entry in the
21043 stack frame. The soft frame pointer to the bottom entry
21044 in the stack frame. If there is no stack frame at all,
21045 then they are identical. */
21047 return offsets
->frame
- offsets
->soft_frame
;
21049 case STACK_POINTER_REGNUM
:
21050 return offsets
->outgoing_args
- offsets
->soft_frame
;
21053 gcc_unreachable ();
21055 gcc_unreachable ();
21058 /* You cannot eliminate from the stack pointer.
21059 In theory you could eliminate from the hard frame
21060 pointer to the stack pointer, but this will never
21061 happen, since if a stack frame is not needed the
21062 hard frame pointer will never be used. */
21063 gcc_unreachable ();
21067 /* Given FROM and TO register numbers, say whether this elimination is
21068 allowed. Frame pointer elimination is automatically handled.
21070 All eliminations are permissible. Note that ARG_POINTER_REGNUM and
21071 HARD_FRAME_POINTER_REGNUM are in fact the same thing. If we need a frame
21072 pointer, we must eliminate FRAME_POINTER_REGNUM into
21073 HARD_FRAME_POINTER_REGNUM and not into STACK_POINTER_REGNUM or
21074 ARG_POINTER_REGNUM. */
21077 arm_can_eliminate (const int from
, const int to
)
21079 return ((to
== FRAME_POINTER_REGNUM
&& from
== ARG_POINTER_REGNUM
) ? false :
21080 (to
== STACK_POINTER_REGNUM
&& frame_pointer_needed
) ? false :
21081 (to
== ARM_HARD_FRAME_POINTER_REGNUM
&& TARGET_THUMB
) ? false :
21082 (to
== THUMB_HARD_FRAME_POINTER_REGNUM
&& TARGET_ARM
) ? false :
21086 /* Emit RTL to save coprocessor registers on function entry. Returns the
21087 number of bytes pushed. */
21090 arm_save_coproc_regs(void)
21092 int saved_size
= 0;
21094 unsigned start_reg
;
21097 for (reg
= LAST_IWMMXT_REGNUM
; reg
>= FIRST_IWMMXT_REGNUM
; reg
--)
21098 if (df_regs_ever_live_p (reg
) && ! call_used_regs
[reg
])
21100 insn
= gen_rtx_PRE_DEC (Pmode
, stack_pointer_rtx
);
21101 insn
= gen_rtx_MEM (V2SImode
, insn
);
21102 insn
= emit_set_insn (insn
, gen_rtx_REG (V2SImode
, reg
));
21103 RTX_FRAME_RELATED_P (insn
) = 1;
21107 if (TARGET_HARD_FLOAT
)
21109 start_reg
= FIRST_VFP_REGNUM
;
21111 for (reg
= FIRST_VFP_REGNUM
; reg
< LAST_VFP_REGNUM
; reg
+= 2)
21113 if ((!df_regs_ever_live_p (reg
) || call_used_regs
[reg
])
21114 && (!df_regs_ever_live_p (reg
+ 1) || call_used_regs
[reg
+ 1]))
21116 if (start_reg
!= reg
)
21117 saved_size
+= vfp_emit_fstmd (start_reg
,
21118 (reg
- start_reg
) / 2);
21119 start_reg
= reg
+ 2;
21122 if (start_reg
!= reg
)
21123 saved_size
+= vfp_emit_fstmd (start_reg
,
21124 (reg
- start_reg
) / 2);
21130 /* Set the Thumb frame pointer from the stack pointer. */
21133 thumb_set_frame_pointer (arm_stack_offsets
*offsets
)
21135 HOST_WIDE_INT amount
;
21138 amount
= offsets
->outgoing_args
- offsets
->locals_base
;
21140 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
21141 stack_pointer_rtx
, GEN_INT (amount
)));
21144 emit_insn (gen_movsi (hard_frame_pointer_rtx
, GEN_INT (amount
)));
21145 /* Thumb-2 RTL patterns expect sp as the first input. Thumb-1
21146 expects the first two operands to be the same. */
21149 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
21151 hard_frame_pointer_rtx
));
21155 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
21156 hard_frame_pointer_rtx
,
21157 stack_pointer_rtx
));
21159 dwarf
= gen_rtx_SET (hard_frame_pointer_rtx
,
21160 plus_constant (Pmode
, stack_pointer_rtx
, amount
));
21161 RTX_FRAME_RELATED_P (dwarf
) = 1;
21162 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, dwarf
);
21165 RTX_FRAME_RELATED_P (insn
) = 1;
21168 struct scratch_reg
{
21173 /* Return a short-lived scratch register for use as a 2nd scratch register on
21174 function entry after the registers are saved in the prologue. This register
21175 must be released by means of release_scratch_register_on_entry. IP is not
21176 considered since it is always used as the 1st scratch register if available.
21178 REGNO1 is the index number of the 1st scratch register and LIVE_REGS is the
21179 mask of live registers. */
21182 get_scratch_register_on_entry (struct scratch_reg
*sr
, unsigned int regno1
,
21183 unsigned long live_regs
)
21189 if (regno1
!= LR_REGNUM
&& (live_regs
& (1 << LR_REGNUM
)) != 0)
21195 for (i
= 4; i
< 11; i
++)
21196 if (regno1
!= i
&& (live_regs
& (1 << i
)) != 0)
21204 /* If IP is used as the 1st scratch register for a nested function,
21205 then either r3 wasn't available or is used to preserve IP. */
21206 if (regno1
== IP_REGNUM
&& IS_NESTED (arm_current_func_type ()))
21208 regno
= (regno1
== 3 ? 2 : 3);
21210 = REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun
)),
21215 sr
->reg
= gen_rtx_REG (SImode
, regno
);
21218 rtx addr
= gen_rtx_PRE_DEC (Pmode
, stack_pointer_rtx
);
21219 rtx insn
= emit_set_insn (gen_frame_mem (SImode
, addr
), sr
->reg
);
21220 rtx x
= gen_rtx_SET (stack_pointer_rtx
,
21221 plus_constant (Pmode
, stack_pointer_rtx
, -4));
21222 RTX_FRAME_RELATED_P (insn
) = 1;
21223 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, x
);
21227 /* Release a scratch register obtained from the preceding function. */
21230 release_scratch_register_on_entry (struct scratch_reg
*sr
)
21234 rtx addr
= gen_rtx_POST_INC (Pmode
, stack_pointer_rtx
);
21235 rtx insn
= emit_set_insn (sr
->reg
, gen_frame_mem (SImode
, addr
));
21236 rtx x
= gen_rtx_SET (stack_pointer_rtx
,
21237 plus_constant (Pmode
, stack_pointer_rtx
, 4));
21238 RTX_FRAME_RELATED_P (insn
) = 1;
21239 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, x
);
21243 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
21245 #if PROBE_INTERVAL > 4096
21246 #error Cannot use indexed addressing mode for stack probing
21249 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
21250 inclusive. These are offsets from the current stack pointer. REGNO1
21251 is the index number of the 1st scratch register and LIVE_REGS is the
21252 mask of live registers. */
21255 arm_emit_probe_stack_range (HOST_WIDE_INT first
, HOST_WIDE_INT size
,
21256 unsigned int regno1
, unsigned long live_regs
)
21258 rtx reg1
= gen_rtx_REG (Pmode
, regno1
);
21260 /* See if we have a constant small number of probes to generate. If so,
21261 that's the easy case. */
21262 if (size
<= PROBE_INTERVAL
)
21264 emit_move_insn (reg1
, GEN_INT (first
+ PROBE_INTERVAL
));
21265 emit_set_insn (reg1
, gen_rtx_MINUS (Pmode
, stack_pointer_rtx
, reg1
));
21266 emit_stack_probe (plus_constant (Pmode
, reg1
, PROBE_INTERVAL
- size
));
21269 /* The run-time loop is made up of 10 insns in the generic case while the
21270 compile-time loop is made up of 4+2*(n-2) insns for n # of intervals. */
21271 else if (size
<= 5 * PROBE_INTERVAL
)
21273 HOST_WIDE_INT i
, rem
;
21275 emit_move_insn (reg1
, GEN_INT (first
+ PROBE_INTERVAL
));
21276 emit_set_insn (reg1
, gen_rtx_MINUS (Pmode
, stack_pointer_rtx
, reg1
));
21277 emit_stack_probe (reg1
);
21279 /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 2 until
21280 it exceeds SIZE. If only two probes are needed, this will not
21281 generate any code. Then probe at FIRST + SIZE. */
21282 for (i
= 2 * PROBE_INTERVAL
; i
< size
; i
+= PROBE_INTERVAL
)
21284 emit_set_insn (reg1
, plus_constant (Pmode
, reg1
, -PROBE_INTERVAL
));
21285 emit_stack_probe (reg1
);
21288 rem
= size
- (i
- PROBE_INTERVAL
);
21289 if (rem
> 4095 || (TARGET_THUMB2
&& rem
> 255))
21291 emit_set_insn (reg1
, plus_constant (Pmode
, reg1
, -PROBE_INTERVAL
));
21292 emit_stack_probe (plus_constant (Pmode
, reg1
, PROBE_INTERVAL
- rem
));
21295 emit_stack_probe (plus_constant (Pmode
, reg1
, -rem
));
21298 /* Otherwise, do the same as above, but in a loop. Note that we must be
21299 extra careful with variables wrapping around because we might be at
21300 the very top (or the very bottom) of the address space and we have
21301 to be able to handle this case properly; in particular, we use an
21302 equality test for the loop condition. */
21305 HOST_WIDE_INT rounded_size
;
21306 struct scratch_reg sr
;
21308 get_scratch_register_on_entry (&sr
, regno1
, live_regs
);
21310 emit_move_insn (reg1
, GEN_INT (first
));
21313 /* Step 1: round SIZE to the previous multiple of the interval. */
21315 rounded_size
= size
& -PROBE_INTERVAL
;
21316 emit_move_insn (sr
.reg
, GEN_INT (rounded_size
));
21319 /* Step 2: compute initial and final value of the loop counter. */
21321 /* TEST_ADDR = SP + FIRST. */
21322 emit_set_insn (reg1
, gen_rtx_MINUS (Pmode
, stack_pointer_rtx
, reg1
));
21324 /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */
21325 emit_set_insn (sr
.reg
, gen_rtx_MINUS (Pmode
, reg1
, sr
.reg
));
21328 /* Step 3: the loop
21332 TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
21335 while (TEST_ADDR != LAST_ADDR)
21337 probes at FIRST + N * PROBE_INTERVAL for values of N from 1
21338 until it is equal to ROUNDED_SIZE. */
21340 emit_insn (gen_probe_stack_range (reg1
, reg1
, sr
.reg
));
21343 /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
21344 that SIZE is equal to ROUNDED_SIZE. */
21346 if (size
!= rounded_size
)
21348 HOST_WIDE_INT rem
= size
- rounded_size
;
21350 if (rem
> 4095 || (TARGET_THUMB2
&& rem
> 255))
21352 emit_set_insn (sr
.reg
,
21353 plus_constant (Pmode
, sr
.reg
, -PROBE_INTERVAL
));
21354 emit_stack_probe (plus_constant (Pmode
, sr
.reg
,
21355 PROBE_INTERVAL
- rem
));
21358 emit_stack_probe (plus_constant (Pmode
, sr
.reg
, -rem
));
21361 release_scratch_register_on_entry (&sr
);
21364 /* Make sure nothing is scheduled before we are done. */
21365 emit_insn (gen_blockage ());
21368 /* Probe a range of stack addresses from REG1 to REG2 inclusive. These are
21369 absolute addresses. */
21372 output_probe_stack_range (rtx reg1
, rtx reg2
)
21374 static int labelno
= 0;
21378 ASM_GENERATE_INTERNAL_LABEL (loop_lab
, "LPSRL", labelno
++);
21381 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, loop_lab
);
21383 /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
21385 xops
[1] = GEN_INT (PROBE_INTERVAL
);
21386 output_asm_insn ("sub\t%0, %0, %1", xops
);
21388 /* Probe at TEST_ADDR. */
21389 output_asm_insn ("str\tr0, [%0, #0]", xops
);
21391 /* Test if TEST_ADDR == LAST_ADDR. */
21393 output_asm_insn ("cmp\t%0, %1", xops
);
21396 fputs ("\tbne\t", asm_out_file
);
21397 assemble_name_raw (asm_out_file
, loop_lab
);
21398 fputc ('\n', asm_out_file
);
21403 /* Generate the prologue instructions for entry into an ARM or Thumb-2
21406 arm_expand_prologue (void)
21411 unsigned long live_regs_mask
;
21412 unsigned long func_type
;
21414 int saved_pretend_args
= 0;
21415 int saved_regs
= 0;
21416 unsigned HOST_WIDE_INT args_to_push
;
21417 HOST_WIDE_INT size
;
21418 arm_stack_offsets
*offsets
;
21421 func_type
= arm_current_func_type ();
21423 /* Naked functions don't have prologues. */
21424 if (IS_NAKED (func_type
))
21426 if (flag_stack_usage_info
)
21427 current_function_static_stack_size
= 0;
21431 /* Make a copy of c_f_p_a_s as we may need to modify it locally. */
21432 args_to_push
= crtl
->args
.pretend_args_size
;
21434 /* Compute which register we will have to save onto the stack. */
21435 offsets
= arm_get_frame_offsets ();
21436 live_regs_mask
= offsets
->saved_regs_mask
;
21438 ip_rtx
= gen_rtx_REG (SImode
, IP_REGNUM
);
21440 if (IS_STACKALIGN (func_type
))
21444 /* Handle a word-aligned stack pointer. We generate the following:
21449 <save and restore r0 in normal prologue/epilogue>
21453 The unwinder doesn't need to know about the stack realignment.
21454 Just tell it we saved SP in r0. */
21455 gcc_assert (TARGET_THUMB2
&& !arm_arch_notm
&& args_to_push
== 0);
21457 r0
= gen_rtx_REG (SImode
, R0_REGNUM
);
21458 r1
= gen_rtx_REG (SImode
, R1_REGNUM
);
21460 insn
= emit_insn (gen_movsi (r0
, stack_pointer_rtx
));
21461 RTX_FRAME_RELATED_P (insn
) = 1;
21462 add_reg_note (insn
, REG_CFA_REGISTER
, NULL
);
21464 emit_insn (gen_andsi3 (r1
, r0
, GEN_INT (~(HOST_WIDE_INT
)7)));
21466 /* ??? The CFA changes here, which may cause GDB to conclude that it
21467 has entered a different function. That said, the unwind info is
21468 correct, individually, before and after this instruction because
21469 we've described the save of SP, which will override the default
21470 handling of SP as restoring from the CFA. */
21471 emit_insn (gen_movsi (stack_pointer_rtx
, r1
));
21474 /* The static chain register is the same as the IP register. If it is
21475 clobbered when creating the frame, we need to save and restore it. */
21476 clobber_ip
= IS_NESTED (func_type
)
21477 && ((TARGET_APCS_FRAME
&& frame_pointer_needed
&& TARGET_ARM
)
21478 || ((flag_stack_check
== STATIC_BUILTIN_STACK_CHECK
21479 || flag_stack_clash_protection
)
21480 && !df_regs_ever_live_p (LR_REGNUM
)
21481 && arm_r3_live_at_start_p ()));
21483 /* Find somewhere to store IP whilst the frame is being created.
21484 We try the following places in order:
21486 1. The last argument register r3 if it is available.
21487 2. A slot on the stack above the frame if there are no
21488 arguments to push onto the stack.
21489 3. Register r3 again, after pushing the argument registers
21490 onto the stack, if this is a varargs function.
21491 4. The last slot on the stack created for the arguments to
21492 push, if this isn't a varargs function.
21494 Note - we only need to tell the dwarf2 backend about the SP
21495 adjustment in the second variant; the static chain register
21496 doesn't need to be unwound, as it doesn't contain a value
21497 inherited from the caller. */
21500 if (!arm_r3_live_at_start_p ())
21501 insn
= emit_set_insn (gen_rtx_REG (SImode
, 3), ip_rtx
);
21502 else if (args_to_push
== 0)
21506 gcc_assert(arm_compute_static_chain_stack_bytes() == 4);
21509 addr
= gen_rtx_PRE_DEC (Pmode
, stack_pointer_rtx
);
21510 insn
= emit_set_insn (gen_frame_mem (SImode
, addr
), ip_rtx
);
21513 /* Just tell the dwarf backend that we adjusted SP. */
21514 dwarf
= gen_rtx_SET (stack_pointer_rtx
,
21515 plus_constant (Pmode
, stack_pointer_rtx
,
21517 RTX_FRAME_RELATED_P (insn
) = 1;
21518 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, dwarf
);
21522 /* Store the args on the stack. */
21523 if (cfun
->machine
->uses_anonymous_args
)
21525 insn
= emit_multi_reg_push ((0xf0 >> (args_to_push
/ 4)) & 0xf,
21526 (0xf0 >> (args_to_push
/ 4)) & 0xf);
21527 emit_set_insn (gen_rtx_REG (SImode
, 3), ip_rtx
);
21528 saved_pretend_args
= 1;
21534 if (args_to_push
== 4)
21535 addr
= gen_rtx_PRE_DEC (Pmode
, stack_pointer_rtx
);
21537 addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
,
21538 plus_constant (Pmode
,
21542 insn
= emit_set_insn (gen_frame_mem (SImode
, addr
), ip_rtx
);
21544 /* Just tell the dwarf backend that we adjusted SP. */
21545 dwarf
= gen_rtx_SET (stack_pointer_rtx
,
21546 plus_constant (Pmode
, stack_pointer_rtx
,
21548 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, dwarf
);
21551 RTX_FRAME_RELATED_P (insn
) = 1;
21552 fp_offset
= args_to_push
;
21557 if (TARGET_APCS_FRAME
&& frame_pointer_needed
&& TARGET_ARM
)
21559 if (IS_INTERRUPT (func_type
))
21561 /* Interrupt functions must not corrupt any registers.
21562 Creating a frame pointer however, corrupts the IP
21563 register, so we must push it first. */
21564 emit_multi_reg_push (1 << IP_REGNUM
, 1 << IP_REGNUM
);
21566 /* Do not set RTX_FRAME_RELATED_P on this insn.
21567 The dwarf stack unwinding code only wants to see one
21568 stack decrement per function, and this is not it. If
21569 this instruction is labeled as being part of the frame
21570 creation sequence then dwarf2out_frame_debug_expr will
21571 die when it encounters the assignment of IP to FP
21572 later on, since the use of SP here establishes SP as
21573 the CFA register and not IP.
21575 Anyway this instruction is not really part of the stack
21576 frame creation although it is part of the prologue. */
21579 insn
= emit_set_insn (ip_rtx
,
21580 plus_constant (Pmode
, stack_pointer_rtx
,
21582 RTX_FRAME_RELATED_P (insn
) = 1;
21587 /* Push the argument registers, or reserve space for them. */
21588 if (cfun
->machine
->uses_anonymous_args
)
21589 insn
= emit_multi_reg_push
21590 ((0xf0 >> (args_to_push
/ 4)) & 0xf,
21591 (0xf0 >> (args_to_push
/ 4)) & 0xf);
21594 (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
21595 GEN_INT (- args_to_push
)));
21596 RTX_FRAME_RELATED_P (insn
) = 1;
21599 /* If this is an interrupt service routine, and the link register
21600 is going to be pushed, and we're not generating extra
21601 push of IP (needed when frame is needed and frame layout if apcs),
21602 subtracting four from LR now will mean that the function return
21603 can be done with a single instruction. */
21604 if ((func_type
== ARM_FT_ISR
|| func_type
== ARM_FT_FIQ
)
21605 && (live_regs_mask
& (1 << LR_REGNUM
)) != 0
21606 && !(frame_pointer_needed
&& TARGET_APCS_FRAME
)
21609 rtx lr
= gen_rtx_REG (SImode
, LR_REGNUM
);
21611 emit_set_insn (lr
, plus_constant (SImode
, lr
, -4));
21614 if (live_regs_mask
)
21616 unsigned long dwarf_regs_mask
= live_regs_mask
;
21618 saved_regs
+= bit_count (live_regs_mask
) * 4;
21619 if (optimize_size
&& !frame_pointer_needed
21620 && saved_regs
== offsets
->saved_regs
- offsets
->saved_args
)
21622 /* If no coprocessor registers are being pushed and we don't have
21623 to worry about a frame pointer then push extra registers to
21624 create the stack frame. This is done in a way that does not
21625 alter the frame layout, so is independent of the epilogue. */
21629 while (n
< 8 && (live_regs_mask
& (1 << n
)) == 0)
21631 frame
= offsets
->outgoing_args
- (offsets
->saved_args
+ saved_regs
);
21632 if (frame
&& n
* 4 >= frame
)
21635 live_regs_mask
|= (1 << n
) - 1;
21636 saved_regs
+= frame
;
21641 && current_tune
->prefer_ldrd_strd
21642 && !optimize_function_for_size_p (cfun
))
21644 gcc_checking_assert (live_regs_mask
== dwarf_regs_mask
);
21646 thumb2_emit_strd_push (live_regs_mask
);
21647 else if (TARGET_ARM
21648 && !TARGET_APCS_FRAME
21649 && !IS_INTERRUPT (func_type
))
21650 arm_emit_strd_push (live_regs_mask
);
21653 insn
= emit_multi_reg_push (live_regs_mask
, live_regs_mask
);
21654 RTX_FRAME_RELATED_P (insn
) = 1;
21659 insn
= emit_multi_reg_push (live_regs_mask
, dwarf_regs_mask
);
21660 RTX_FRAME_RELATED_P (insn
) = 1;
21664 if (! IS_VOLATILE (func_type
))
21665 saved_regs
+= arm_save_coproc_regs ();
21667 if (frame_pointer_needed
&& TARGET_ARM
)
21669 /* Create the new frame pointer. */
21670 if (TARGET_APCS_FRAME
)
21672 insn
= GEN_INT (-(4 + args_to_push
+ fp_offset
));
21673 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
, ip_rtx
, insn
));
21674 RTX_FRAME_RELATED_P (insn
) = 1;
21678 insn
= GEN_INT (saved_regs
- (4 + fp_offset
));
21679 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
21680 stack_pointer_rtx
, insn
));
21681 RTX_FRAME_RELATED_P (insn
) = 1;
21685 size
= offsets
->outgoing_args
- offsets
->saved_args
;
21686 if (flag_stack_usage_info
)
21687 current_function_static_stack_size
= size
;
21689 /* If this isn't an interrupt service routine and we have a frame, then do
21690 stack checking. We use IP as the first scratch register, except for the
21691 non-APCS nested functions if LR or r3 are available (see clobber_ip). */
21692 if (!IS_INTERRUPT (func_type
)
21693 && (flag_stack_check
== STATIC_BUILTIN_STACK_CHECK
21694 || flag_stack_clash_protection
))
21696 unsigned int regno
;
21698 if (!IS_NESTED (func_type
) || clobber_ip
)
21700 else if (df_regs_ever_live_p (LR_REGNUM
))
21705 if (crtl
->is_leaf
&& !cfun
->calls_alloca
)
21707 if (size
> PROBE_INTERVAL
&& size
> get_stack_check_protect ())
21708 arm_emit_probe_stack_range (get_stack_check_protect (),
21709 size
- get_stack_check_protect (),
21710 regno
, live_regs_mask
);
21713 arm_emit_probe_stack_range (get_stack_check_protect (), size
,
21714 regno
, live_regs_mask
);
21717 /* Recover the static chain register. */
21720 if (!arm_r3_live_at_start_p () || saved_pretend_args
)
21721 insn
= gen_rtx_REG (SImode
, 3);
21724 insn
= plus_constant (Pmode
, hard_frame_pointer_rtx
, 4);
21725 insn
= gen_frame_mem (SImode
, insn
);
21727 emit_set_insn (ip_rtx
, insn
);
21728 emit_insn (gen_force_register_use (ip_rtx
));
21731 if (offsets
->outgoing_args
!= offsets
->saved_args
+ saved_regs
)
21733 /* This add can produce multiple insns for a large constant, so we
21734 need to get tricky. */
21735 rtx_insn
*last
= get_last_insn ();
21737 amount
= GEN_INT (offsets
->saved_args
+ saved_regs
21738 - offsets
->outgoing_args
);
21740 insn
= emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
21744 last
= last
? NEXT_INSN (last
) : get_insns ();
21745 RTX_FRAME_RELATED_P (last
) = 1;
21747 while (last
!= insn
);
21749 /* If the frame pointer is needed, emit a special barrier that
21750 will prevent the scheduler from moving stores to the frame
21751 before the stack adjustment. */
21752 if (frame_pointer_needed
)
21753 emit_insn (gen_stack_tie (stack_pointer_rtx
,
21754 hard_frame_pointer_rtx
));
21758 if (frame_pointer_needed
&& TARGET_THUMB2
)
21759 thumb_set_frame_pointer (offsets
);
21761 if (flag_pic
&& arm_pic_register
!= INVALID_REGNUM
)
21763 unsigned long mask
;
21765 mask
= live_regs_mask
;
21766 mask
&= THUMB2_WORK_REGS
;
21767 if (!IS_NESTED (func_type
))
21768 mask
|= (1 << IP_REGNUM
);
21769 arm_load_pic_register (mask
);
21772 /* If we are profiling, make sure no instructions are scheduled before
21773 the call to mcount. Similarly if the user has requested no
21774 scheduling in the prolog. Similarly if we want non-call exceptions
21775 using the EABI unwinder, to prevent faulting instructions from being
21776 swapped with a stack adjustment. */
21777 if (crtl
->profile
|| !TARGET_SCHED_PROLOG
21778 || (arm_except_unwind_info (&global_options
) == UI_TARGET
21779 && cfun
->can_throw_non_call_exceptions
))
21780 emit_insn (gen_blockage ());
21782 /* If the link register is being kept alive, with the return address in it,
21783 then make sure that it does not get reused by the ce2 pass. */
21784 if ((live_regs_mask
& (1 << LR_REGNUM
)) == 0)
21785 cfun
->machine
->lr_save_eliminated
= 1;
21788 /* Print condition code to STREAM. Helper function for arm_print_operand. */
21790 arm_print_condition (FILE *stream
)
21792 if (arm_ccfsm_state
== 3 || arm_ccfsm_state
== 4)
21794 /* Branch conversion is not implemented for Thumb-2. */
21797 output_operand_lossage ("predicated Thumb instruction");
21800 if (current_insn_predicate
!= NULL
)
21802 output_operand_lossage
21803 ("predicated instruction in conditional sequence");
21807 fputs (arm_condition_codes
[arm_current_cc
], stream
);
21809 else if (current_insn_predicate
)
21811 enum arm_cond_code code
;
21815 output_operand_lossage ("predicated Thumb instruction");
21819 code
= get_arm_condition_code (current_insn_predicate
);
21820 fputs (arm_condition_codes
[code
], stream
);
21825 /* Globally reserved letters: acln
21826 Puncutation letters currently used: @_|?().!#
21827 Lower case letters currently used: bcdefhimpqtvwxyz
21828 Upper case letters currently used: ABCDFGHJKLMNOPQRSTU
21829 Letters previously used, but now deprecated/obsolete: sVWXYZ.
21831 Note that the global reservation for 'c' is only for CONSTANT_ADDRESS_P.
21833 If CODE is 'd', then the X is a condition operand and the instruction
21834 should only be executed if the condition is true.
21835 if CODE is 'D', then the X is a condition operand and the instruction
21836 should only be executed if the condition is false: however, if the mode
21837 of the comparison is CCFPEmode, then always execute the instruction -- we
21838 do this because in these circumstances !GE does not necessarily imply LT;
21839 in these cases the instruction pattern will take care to make sure that
21840 an instruction containing %d will follow, thereby undoing the effects of
21841 doing this instruction unconditionally.
21842 If CODE is 'N' then X is a floating point operand that must be negated
21844 If CODE is 'B' then output a bitwise inverted value of X (a const int).
21845 If X is a REG and CODE is `M', output a ldm/stm style multi-reg. */
21847 arm_print_operand (FILE *stream
, rtx x
, int code
)
21852 fputs (ASM_COMMENT_START
, stream
);
21856 fputs (user_label_prefix
, stream
);
21860 fputs (REGISTER_PREFIX
, stream
);
21864 arm_print_condition (stream
);
21868 /* The current condition code for a condition code setting instruction.
21869 Preceded by 's' in unified syntax, otherwise followed by 's'. */
21870 fputc('s', stream
);
21871 arm_print_condition (stream
);
21875 /* If the instruction is conditionally executed then print
21876 the current condition code, otherwise print 's'. */
21877 gcc_assert (TARGET_THUMB2
);
21878 if (current_insn_predicate
)
21879 arm_print_condition (stream
);
21881 fputc('s', stream
);
21884 /* %# is a "break" sequence. It doesn't output anything, but is used to
21885 separate e.g. operand numbers from following text, if that text consists
21886 of further digits which we don't want to be part of the operand
21894 r
= real_value_negate (CONST_DOUBLE_REAL_VALUE (x
));
21895 fprintf (stream
, "%s", fp_const_from_val (&r
));
21899 /* An integer or symbol address without a preceding # sign. */
21901 switch (GET_CODE (x
))
21904 fprintf (stream
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
21908 output_addr_const (stream
, x
);
21912 if (GET_CODE (XEXP (x
, 0)) == PLUS
21913 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == SYMBOL_REF
)
21915 output_addr_const (stream
, x
);
21918 /* Fall through. */
21921 output_operand_lossage ("Unsupported operand for code '%c'", code
);
21925 /* An integer that we want to print in HEX. */
21927 switch (GET_CODE (x
))
21930 fprintf (stream
, "#" HOST_WIDE_INT_PRINT_HEX
, INTVAL (x
));
21934 output_operand_lossage ("Unsupported operand for code '%c'", code
);
21939 if (CONST_INT_P (x
))
21942 val
= ARM_SIGN_EXTEND (~INTVAL (x
));
21943 fprintf (stream
, HOST_WIDE_INT_PRINT_DEC
, val
);
21947 putc ('~', stream
);
21948 output_addr_const (stream
, x
);
21953 /* Print the log2 of a CONST_INT. */
21957 if (!CONST_INT_P (x
)
21958 || (val
= exact_log2 (INTVAL (x
) & 0xffffffff)) < 0)
21959 output_operand_lossage ("Unsupported operand for code '%c'", code
);
21961 fprintf (stream
, "#" HOST_WIDE_INT_PRINT_DEC
, val
);
21966 /* The low 16 bits of an immediate constant. */
21967 fprintf (stream
, HOST_WIDE_INT_PRINT_DEC
, INTVAL(x
) & 0xffff);
21971 fprintf (stream
, "%s", arithmetic_instr (x
, 1));
21975 fprintf (stream
, "%s", arithmetic_instr (x
, 0));
21983 shift
= shift_op (x
, &val
);
21987 fprintf (stream
, ", %s ", shift
);
21989 arm_print_operand (stream
, XEXP (x
, 1), 0);
21991 fprintf (stream
, "#" HOST_WIDE_INT_PRINT_DEC
, val
);
21996 /* An explanation of the 'Q', 'R' and 'H' register operands:
21998 In a pair of registers containing a DI or DF value the 'Q'
21999 operand returns the register number of the register containing
22000 the least significant part of the value. The 'R' operand returns
22001 the register number of the register containing the most
22002 significant part of the value.
22004 The 'H' operand returns the higher of the two register numbers.
22005 On a run where WORDS_BIG_ENDIAN is true the 'H' operand is the
22006 same as the 'Q' operand, since the most significant part of the
22007 value is held in the lower number register. The reverse is true
22008 on systems where WORDS_BIG_ENDIAN is false.
22010 The purpose of these operands is to distinguish between cases
22011 where the endian-ness of the values is important (for example
22012 when they are added together), and cases where the endian-ness
22013 is irrelevant, but the order of register operations is important.
22014 For example when loading a value from memory into a register
22015 pair, the endian-ness does not matter. Provided that the value
22016 from the lower memory address is put into the lower numbered
22017 register, and the value from the higher address is put into the
22018 higher numbered register, the load will work regardless of whether
22019 the value being loaded is big-wordian or little-wordian. The
22020 order of the two register loads can matter however, if the address
22021 of the memory location is actually held in one of the registers
22022 being overwritten by the load.
22024 The 'Q' and 'R' constraints are also available for 64-bit
22027 if (CONST_INT_P (x
) || CONST_DOUBLE_P (x
))
22029 rtx part
= gen_lowpart (SImode
, x
);
22030 fprintf (stream
, "#" HOST_WIDE_INT_PRINT_DEC
, INTVAL (part
));
22034 if (!REG_P (x
) || REGNO (x
) > LAST_ARM_REGNUM
)
22036 output_operand_lossage ("invalid operand for code '%c'", code
);
22040 asm_fprintf (stream
, "%r", REGNO (x
) + (WORDS_BIG_ENDIAN
? 1 : 0));
22044 if (CONST_INT_P (x
) || CONST_DOUBLE_P (x
))
22046 machine_mode mode
= GET_MODE (x
);
22049 if (mode
== VOIDmode
)
22051 part
= gen_highpart_mode (SImode
, mode
, x
);
22052 fprintf (stream
, "#" HOST_WIDE_INT_PRINT_DEC
, INTVAL (part
));
22056 if (!REG_P (x
) || REGNO (x
) > LAST_ARM_REGNUM
)
22058 output_operand_lossage ("invalid operand for code '%c'", code
);
22062 asm_fprintf (stream
, "%r", REGNO (x
) + (WORDS_BIG_ENDIAN
? 0 : 1));
22066 if (!REG_P (x
) || REGNO (x
) > LAST_ARM_REGNUM
)
22068 output_operand_lossage ("invalid operand for code '%c'", code
);
22072 asm_fprintf (stream
, "%r", REGNO (x
) + 1);
22076 if (!REG_P (x
) || REGNO (x
) > LAST_ARM_REGNUM
)
22078 output_operand_lossage ("invalid operand for code '%c'", code
);
22082 asm_fprintf (stream
, "%r", REGNO (x
) + (WORDS_BIG_ENDIAN
? 3 : 2));
22086 if (!REG_P (x
) || REGNO (x
) > LAST_ARM_REGNUM
)
22088 output_operand_lossage ("invalid operand for code '%c'", code
);
22092 asm_fprintf (stream
, "%r", REGNO (x
) + (WORDS_BIG_ENDIAN
? 2 : 3));
22096 asm_fprintf (stream
, "%r",
22097 REG_P (XEXP (x
, 0))
22098 ? REGNO (XEXP (x
, 0)) : REGNO (XEXP (XEXP (x
, 0), 0)));
22102 asm_fprintf (stream
, "{%r-%r}",
22104 REGNO (x
) + ARM_NUM_REGS (GET_MODE (x
)) - 1);
22107 /* Like 'M', but writing doubleword vector registers, for use by Neon
22111 int regno
= (REGNO (x
) - FIRST_VFP_REGNUM
) / 2;
22112 int numregs
= ARM_NUM_REGS (GET_MODE (x
)) / 2;
22114 asm_fprintf (stream
, "{d%d}", regno
);
22116 asm_fprintf (stream
, "{d%d-d%d}", regno
, regno
+ numregs
- 1);
22121 /* CONST_TRUE_RTX means always -- that's the default. */
22122 if (x
== const_true_rtx
)
22125 if (!COMPARISON_P (x
))
22127 output_operand_lossage ("invalid operand for code '%c'", code
);
22131 fputs (arm_condition_codes
[get_arm_condition_code (x
)],
22136 /* CONST_TRUE_RTX means not always -- i.e. never. We shouldn't ever
22137 want to do that. */
22138 if (x
== const_true_rtx
)
22140 output_operand_lossage ("instruction never executed");
22143 if (!COMPARISON_P (x
))
22145 output_operand_lossage ("invalid operand for code '%c'", code
);
22149 fputs (arm_condition_codes
[ARM_INVERSE_CONDITION_CODE
22150 (get_arm_condition_code (x
))],
22160 /* Former Maverick support, removed after GCC-4.7. */
22161 output_operand_lossage ("obsolete Maverick format code '%c'", code
);
22166 || REGNO (x
) < FIRST_IWMMXT_GR_REGNUM
22167 || REGNO (x
) > LAST_IWMMXT_GR_REGNUM
)
22168 /* Bad value for wCG register number. */
22170 output_operand_lossage ("invalid operand for code '%c'", code
);
22175 fprintf (stream
, "%d", REGNO (x
) - FIRST_IWMMXT_GR_REGNUM
);
22178 /* Print an iWMMXt control register name. */
22180 if (!CONST_INT_P (x
)
22182 || INTVAL (x
) >= 16)
22183 /* Bad value for wC register number. */
22185 output_operand_lossage ("invalid operand for code '%c'", code
);
22191 static const char * wc_reg_names
[16] =
22193 "wCID", "wCon", "wCSSF", "wCASF",
22194 "wC4", "wC5", "wC6", "wC7",
22195 "wCGR0", "wCGR1", "wCGR2", "wCGR3",
22196 "wC12", "wC13", "wC14", "wC15"
22199 fputs (wc_reg_names
[INTVAL (x
)], stream
);
22203 /* Print the high single-precision register of a VFP double-precision
22207 machine_mode mode
= GET_MODE (x
);
22210 if (GET_MODE_SIZE (mode
) != 8 || !REG_P (x
))
22212 output_operand_lossage ("invalid operand for code '%c'", code
);
22217 if (!VFP_REGNO_OK_FOR_DOUBLE (regno
))
22219 output_operand_lossage ("invalid operand for code '%c'", code
);
22223 fprintf (stream
, "s%d", regno
- FIRST_VFP_REGNUM
+ 1);
22227 /* Print a VFP/Neon double precision or quad precision register name. */
22231 machine_mode mode
= GET_MODE (x
);
22232 int is_quad
= (code
== 'q');
22235 if (GET_MODE_SIZE (mode
) != (is_quad
? 16 : 8))
22237 output_operand_lossage ("invalid operand for code '%c'", code
);
22242 || !IS_VFP_REGNUM (REGNO (x
)))
22244 output_operand_lossage ("invalid operand for code '%c'", code
);
22249 if ((is_quad
&& !NEON_REGNO_OK_FOR_QUAD (regno
))
22250 || (!is_quad
&& !VFP_REGNO_OK_FOR_DOUBLE (regno
)))
22252 output_operand_lossage ("invalid operand for code '%c'", code
);
22256 fprintf (stream
, "%c%d", is_quad
? 'q' : 'd',
22257 (regno
- FIRST_VFP_REGNUM
) >> (is_quad
? 2 : 1));
22261 /* These two codes print the low/high doubleword register of a Neon quad
22262 register, respectively. For pair-structure types, can also print
22263 low/high quadword registers. */
22267 machine_mode mode
= GET_MODE (x
);
22270 if ((GET_MODE_SIZE (mode
) != 16
22271 && GET_MODE_SIZE (mode
) != 32) || !REG_P (x
))
22273 output_operand_lossage ("invalid operand for code '%c'", code
);
22278 if (!NEON_REGNO_OK_FOR_QUAD (regno
))
22280 output_operand_lossage ("invalid operand for code '%c'", code
);
22284 if (GET_MODE_SIZE (mode
) == 16)
22285 fprintf (stream
, "d%d", ((regno
- FIRST_VFP_REGNUM
) >> 1)
22286 + (code
== 'f' ? 1 : 0));
22288 fprintf (stream
, "q%d", ((regno
- FIRST_VFP_REGNUM
) >> 2)
22289 + (code
== 'f' ? 1 : 0));
22293 /* Print a VFPv3 floating-point constant, represented as an integer
22297 int index
= vfp3_const_double_index (x
);
22298 gcc_assert (index
!= -1);
22299 fprintf (stream
, "%d", index
);
22303 /* Print bits representing opcode features for Neon.
22305 Bit 0 is 1 for signed, 0 for unsigned. Floats count as signed
22306 and polynomials as unsigned.
22308 Bit 1 is 1 for floats and polynomials, 0 for ordinary integers.
22310 Bit 2 is 1 for rounding functions, 0 otherwise. */
22312 /* Identify the type as 's', 'u', 'p' or 'f'. */
22315 HOST_WIDE_INT bits
= INTVAL (x
);
22316 fputc ("uspf"[bits
& 3], stream
);
22320 /* Likewise, but signed and unsigned integers are both 'i'. */
22323 HOST_WIDE_INT bits
= INTVAL (x
);
22324 fputc ("iipf"[bits
& 3], stream
);
22328 /* As for 'T', but emit 'u' instead of 'p'. */
22331 HOST_WIDE_INT bits
= INTVAL (x
);
22332 fputc ("usuf"[bits
& 3], stream
);
22336 /* Bit 2: rounding (vs none). */
22339 HOST_WIDE_INT bits
= INTVAL (x
);
22340 fputs ((bits
& 4) != 0 ? "r" : "", stream
);
22344 /* Memory operand for vld1/vst1 instruction. */
22348 bool postinc
= FALSE
;
22349 rtx postinc_reg
= NULL
;
22350 unsigned align
, memsize
, align_bits
;
22352 gcc_assert (MEM_P (x
));
22353 addr
= XEXP (x
, 0);
22354 if (GET_CODE (addr
) == POST_INC
)
22357 addr
= XEXP (addr
, 0);
22359 if (GET_CODE (addr
) == POST_MODIFY
)
22361 postinc_reg
= XEXP( XEXP (addr
, 1), 1);
22362 addr
= XEXP (addr
, 0);
22364 asm_fprintf (stream
, "[%r", REGNO (addr
));
22366 /* We know the alignment of this access, so we can emit a hint in the
22367 instruction (for some alignments) as an aid to the memory subsystem
22369 align
= MEM_ALIGN (x
) >> 3;
22370 memsize
= MEM_SIZE (x
);
22372 /* Only certain alignment specifiers are supported by the hardware. */
22373 if (memsize
== 32 && (align
% 32) == 0)
22375 else if ((memsize
== 16 || memsize
== 32) && (align
% 16) == 0)
22377 else if (memsize
>= 8 && (align
% 8) == 0)
22382 if (align_bits
!= 0)
22383 asm_fprintf (stream
, ":%d", align_bits
);
22385 asm_fprintf (stream
, "]");
22388 fputs("!", stream
);
22390 asm_fprintf (stream
, ", %r", REGNO (postinc_reg
));
22398 gcc_assert (MEM_P (x
));
22399 addr
= XEXP (x
, 0);
22400 gcc_assert (REG_P (addr
));
22401 asm_fprintf (stream
, "[%r]", REGNO (addr
));
22405 /* Translate an S register number into a D register number and element index. */
22408 machine_mode mode
= GET_MODE (x
);
22411 if (GET_MODE_SIZE (mode
) != 4 || !REG_P (x
))
22413 output_operand_lossage ("invalid operand for code '%c'", code
);
22418 if (!VFP_REGNO_OK_FOR_SINGLE (regno
))
22420 output_operand_lossage ("invalid operand for code '%c'", code
);
22424 regno
= regno
- FIRST_VFP_REGNUM
;
22425 fprintf (stream
, "d%d[%d]", regno
/ 2, regno
% 2);
22430 gcc_assert (CONST_DOUBLE_P (x
));
22432 result
= vfp3_const_double_for_fract_bits (x
);
22434 result
= vfp3_const_double_for_bits (x
);
22435 fprintf (stream
, "#%d", result
);
22438 /* Register specifier for vld1.16/vst1.16. Translate the S register
22439 number into a D register number and element index. */
22442 machine_mode mode
= GET_MODE (x
);
22445 if (GET_MODE_SIZE (mode
) != 2 || !REG_P (x
))
22447 output_operand_lossage ("invalid operand for code '%c'", code
);
22452 if (!VFP_REGNO_OK_FOR_SINGLE (regno
))
22454 output_operand_lossage ("invalid operand for code '%c'", code
);
22458 regno
= regno
- FIRST_VFP_REGNUM
;
22459 fprintf (stream
, "d%d[%d]", regno
/2, ((regno
% 2) ? 2 : 0));
22466 output_operand_lossage ("missing operand");
22470 switch (GET_CODE (x
))
22473 asm_fprintf (stream
, "%r", REGNO (x
));
22477 output_address (GET_MODE (x
), XEXP (x
, 0));
22483 real_to_decimal (fpstr
, CONST_DOUBLE_REAL_VALUE (x
),
22484 sizeof (fpstr
), 0, 1);
22485 fprintf (stream
, "#%s", fpstr
);
22490 gcc_assert (GET_CODE (x
) != NEG
);
22491 fputc ('#', stream
);
22492 if (GET_CODE (x
) == HIGH
)
22494 fputs (":lower16:", stream
);
22498 output_addr_const (stream
, x
);
22504 /* Target hook for printing a memory address. */
22506 arm_print_operand_address (FILE *stream
, machine_mode mode
, rtx x
)
22510 int is_minus
= GET_CODE (x
) == MINUS
;
22513 asm_fprintf (stream
, "[%r]", REGNO (x
));
22514 else if (GET_CODE (x
) == PLUS
|| is_minus
)
22516 rtx base
= XEXP (x
, 0);
22517 rtx index
= XEXP (x
, 1);
22518 HOST_WIDE_INT offset
= 0;
22520 || (REG_P (index
) && REGNO (index
) == SP_REGNUM
))
22522 /* Ensure that BASE is a register. */
22523 /* (one of them must be). */
22524 /* Also ensure the SP is not used as in index register. */
22525 std::swap (base
, index
);
22527 switch (GET_CODE (index
))
22530 offset
= INTVAL (index
);
22533 asm_fprintf (stream
, "[%r, #%wd]",
22534 REGNO (base
), offset
);
22538 asm_fprintf (stream
, "[%r, %s%r]",
22539 REGNO (base
), is_minus
? "-" : "",
22549 asm_fprintf (stream
, "[%r, %s%r",
22550 REGNO (base
), is_minus
? "-" : "",
22551 REGNO (XEXP (index
, 0)));
22552 arm_print_operand (stream
, index
, 'S');
22553 fputs ("]", stream
);
22558 gcc_unreachable ();
22561 else if (GET_CODE (x
) == PRE_INC
|| GET_CODE (x
) == POST_INC
22562 || GET_CODE (x
) == PRE_DEC
|| GET_CODE (x
) == POST_DEC
)
22564 gcc_assert (REG_P (XEXP (x
, 0)));
22566 if (GET_CODE (x
) == PRE_DEC
|| GET_CODE (x
) == PRE_INC
)
22567 asm_fprintf (stream
, "[%r, #%s%d]!",
22568 REGNO (XEXP (x
, 0)),
22569 GET_CODE (x
) == PRE_DEC
? "-" : "",
22570 GET_MODE_SIZE (mode
));
22572 asm_fprintf (stream
, "[%r], #%s%d",
22573 REGNO (XEXP (x
, 0)),
22574 GET_CODE (x
) == POST_DEC
? "-" : "",
22575 GET_MODE_SIZE (mode
));
22577 else if (GET_CODE (x
) == PRE_MODIFY
)
22579 asm_fprintf (stream
, "[%r, ", REGNO (XEXP (x
, 0)));
22580 if (CONST_INT_P (XEXP (XEXP (x
, 1), 1)))
22581 asm_fprintf (stream
, "#%wd]!",
22582 INTVAL (XEXP (XEXP (x
, 1), 1)));
22584 asm_fprintf (stream
, "%r]!",
22585 REGNO (XEXP (XEXP (x
, 1), 1)));
22587 else if (GET_CODE (x
) == POST_MODIFY
)
22589 asm_fprintf (stream
, "[%r], ", REGNO (XEXP (x
, 0)));
22590 if (CONST_INT_P (XEXP (XEXP (x
, 1), 1)))
22591 asm_fprintf (stream
, "#%wd",
22592 INTVAL (XEXP (XEXP (x
, 1), 1)));
22594 asm_fprintf (stream
, "%r",
22595 REGNO (XEXP (XEXP (x
, 1), 1)));
22597 else output_addr_const (stream
, x
);
22602 asm_fprintf (stream
, "[%r]", REGNO (x
));
22603 else if (GET_CODE (x
) == POST_INC
)
22604 asm_fprintf (stream
, "%r!", REGNO (XEXP (x
, 0)));
22605 else if (GET_CODE (x
) == PLUS
)
22607 gcc_assert (REG_P (XEXP (x
, 0)));
22608 if (CONST_INT_P (XEXP (x
, 1)))
22609 asm_fprintf (stream
, "[%r, #%wd]",
22610 REGNO (XEXP (x
, 0)),
22611 INTVAL (XEXP (x
, 1)));
22613 asm_fprintf (stream
, "[%r, %r]",
22614 REGNO (XEXP (x
, 0)),
22615 REGNO (XEXP (x
, 1)));
22618 output_addr_const (stream
, x
);
22622 /* Target hook for indicating whether a punctuation character for
22623 TARGET_PRINT_OPERAND is valid. */
22625 arm_print_operand_punct_valid_p (unsigned char code
)
22627 return (code
== '@' || code
== '|' || code
== '.'
22628 || code
== '(' || code
== ')' || code
== '#'
22629 || (TARGET_32BIT
&& (code
== '?'))
22630 || (TARGET_THUMB2
&& (code
== '!'))
22631 || (TARGET_THUMB
&& (code
== '_')));
22634 /* Target hook for assembling integer objects. The ARM version needs to
22635 handle word-sized values specially. */
22637 arm_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
22641 if (size
== UNITS_PER_WORD
&& aligned_p
)
22643 fputs ("\t.word\t", asm_out_file
);
22644 output_addr_const (asm_out_file
, x
);
22646 /* Mark symbols as position independent. We only do this in the
22647 .text segment, not in the .data segment. */
22648 if (NEED_GOT_RELOC
&& flag_pic
&& making_const_table
&&
22649 (GET_CODE (x
) == SYMBOL_REF
|| GET_CODE (x
) == LABEL_REF
))
22651 /* See legitimize_pic_address for an explanation of the
22652 TARGET_VXWORKS_RTP check. */
22653 /* References to weak symbols cannot be resolved locally:
22654 they may be overridden by a non-weak definition at link
22656 if (!arm_pic_data_is_text_relative
22657 || (GET_CODE (x
) == SYMBOL_REF
22658 && (!SYMBOL_REF_LOCAL_P (x
)
22659 || (SYMBOL_REF_DECL (x
)
22660 ? DECL_WEAK (SYMBOL_REF_DECL (x
)) : 0))))
22661 fputs ("(GOT)", asm_out_file
);
22663 fputs ("(GOTOFF)", asm_out_file
);
22665 fputc ('\n', asm_out_file
);
22669 mode
= GET_MODE (x
);
22671 if (arm_vector_mode_supported_p (mode
))
22675 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
22677 units
= CONST_VECTOR_NUNITS (x
);
22678 size
= GET_MODE_UNIT_SIZE (mode
);
22680 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
)
22681 for (i
= 0; i
< units
; i
++)
22683 rtx elt
= CONST_VECTOR_ELT (x
, i
);
22685 (elt
, size
, i
== 0 ? BIGGEST_ALIGNMENT
: size
* BITS_PER_UNIT
, 1);
22688 for (i
= 0; i
< units
; i
++)
22690 rtx elt
= CONST_VECTOR_ELT (x
, i
);
22692 (*CONST_DOUBLE_REAL_VALUE (elt
),
22693 as_a
<scalar_float_mode
> (GET_MODE_INNER (mode
)),
22694 i
== 0 ? BIGGEST_ALIGNMENT
: size
* BITS_PER_UNIT
);
22700 return default_assemble_integer (x
, size
, aligned_p
);
22704 arm_elf_asm_cdtor (rtx symbol
, int priority
, bool is_ctor
)
22708 if (!TARGET_AAPCS_BASED
)
22711 default_named_section_asm_out_constructor
22712 : default_named_section_asm_out_destructor
) (symbol
, priority
);
22716 /* Put these in the .init_array section, using a special relocation. */
22717 if (priority
!= DEFAULT_INIT_PRIORITY
)
22720 sprintf (buf
, "%s.%.5u",
22721 is_ctor
? ".init_array" : ".fini_array",
22723 s
= get_section (buf
, SECTION_WRITE
| SECTION_NOTYPE
, NULL_TREE
);
22730 switch_to_section (s
);
22731 assemble_align (POINTER_SIZE
);
22732 fputs ("\t.word\t", asm_out_file
);
22733 output_addr_const (asm_out_file
, symbol
);
22734 fputs ("(target1)\n", asm_out_file
);
22737 /* Add a function to the list of static constructors. */
22740 arm_elf_asm_constructor (rtx symbol
, int priority
)
22742 arm_elf_asm_cdtor (symbol
, priority
, /*is_ctor=*/true);
22745 /* Add a function to the list of static destructors. */
22748 arm_elf_asm_destructor (rtx symbol
, int priority
)
22750 arm_elf_asm_cdtor (symbol
, priority
, /*is_ctor=*/false);
22753 /* A finite state machine takes care of noticing whether or not instructions
22754 can be conditionally executed, and thus decrease execution time and code
22755 size by deleting branch instructions. The fsm is controlled by
22756 final_prescan_insn, and controls the actions of ASM_OUTPUT_OPCODE. */
22758 /* The state of the fsm controlling condition codes are:
22759 0: normal, do nothing special
22760 1: make ASM_OUTPUT_OPCODE not output this instruction
22761 2: make ASM_OUTPUT_OPCODE not output this instruction
22762 3: make instructions conditional
22763 4: make instructions conditional
22765 State transitions (state->state by whom under condition):
22766 0 -> 1 final_prescan_insn if the `target' is a label
22767 0 -> 2 final_prescan_insn if the `target' is an unconditional branch
22768 1 -> 3 ASM_OUTPUT_OPCODE after not having output the conditional branch
22769 2 -> 4 ASM_OUTPUT_OPCODE after not having output the conditional branch
22770 3 -> 0 (*targetm.asm_out.internal_label) if the `target' label is reached
22771 (the target label has CODE_LABEL_NUMBER equal to arm_target_label).
22772 4 -> 0 final_prescan_insn if the `target' unconditional branch is reached
22773 (the target insn is arm_target_insn).
22775 If the jump clobbers the conditions then we use states 2 and 4.
22777 A similar thing can be done with conditional return insns.
22779 XXX In case the `target' is an unconditional branch, this conditionalising
22780 of the instructions always reduces code size, but not always execution
22781 time. But then, I want to reduce the code size to somewhere near what
22782 /bin/cc produces. */
22784 /* In addition to this, state is maintained for Thumb-2 COND_EXEC
22785 instructions. When a COND_EXEC instruction is seen the subsequent
22786 instructions are scanned so that multiple conditional instructions can be
22787 combined into a single IT block. arm_condexec_count and arm_condexec_mask
22788 specify the length and true/false mask for the IT block. These will be
22789 decremented/zeroed by arm_asm_output_opcode as the insns are output. */
22791 /* Returns the index of the ARM condition code string in
22792 `arm_condition_codes', or ARM_NV if the comparison is invalid.
22793 COMPARISON should be an rtx like `(eq (...) (...))'. */
22796 maybe_get_arm_condition_code (rtx comparison
)
22798 machine_mode mode
= GET_MODE (XEXP (comparison
, 0));
22799 enum arm_cond_code code
;
22800 enum rtx_code comp_code
= GET_CODE (comparison
);
22802 if (GET_MODE_CLASS (mode
) != MODE_CC
)
22803 mode
= SELECT_CC_MODE (comp_code
, XEXP (comparison
, 0),
22804 XEXP (comparison
, 1));
22808 case E_CC_DNEmode
: code
= ARM_NE
; goto dominance
;
22809 case E_CC_DEQmode
: code
= ARM_EQ
; goto dominance
;
22810 case E_CC_DGEmode
: code
= ARM_GE
; goto dominance
;
22811 case E_CC_DGTmode
: code
= ARM_GT
; goto dominance
;
22812 case E_CC_DLEmode
: code
= ARM_LE
; goto dominance
;
22813 case E_CC_DLTmode
: code
= ARM_LT
; goto dominance
;
22814 case E_CC_DGEUmode
: code
= ARM_CS
; goto dominance
;
22815 case E_CC_DGTUmode
: code
= ARM_HI
; goto dominance
;
22816 case E_CC_DLEUmode
: code
= ARM_LS
; goto dominance
;
22817 case E_CC_DLTUmode
: code
= ARM_CC
;
22820 if (comp_code
== EQ
)
22821 return ARM_INVERSE_CONDITION_CODE (code
);
22822 if (comp_code
== NE
)
22826 case E_CC_NOOVmode
:
22829 case NE
: return ARM_NE
;
22830 case EQ
: return ARM_EQ
;
22831 case GE
: return ARM_PL
;
22832 case LT
: return ARM_MI
;
22833 default: return ARM_NV
;
22839 case NE
: return ARM_NE
;
22840 case EQ
: return ARM_EQ
;
22841 default: return ARM_NV
;
22847 case NE
: return ARM_MI
;
22848 case EQ
: return ARM_PL
;
22849 default: return ARM_NV
;
22854 /* We can handle all cases except UNEQ and LTGT. */
22857 case GE
: return ARM_GE
;
22858 case GT
: return ARM_GT
;
22859 case LE
: return ARM_LS
;
22860 case LT
: return ARM_MI
;
22861 case NE
: return ARM_NE
;
22862 case EQ
: return ARM_EQ
;
22863 case ORDERED
: return ARM_VC
;
22864 case UNORDERED
: return ARM_VS
;
22865 case UNLT
: return ARM_LT
;
22866 case UNLE
: return ARM_LE
;
22867 case UNGT
: return ARM_HI
;
22868 case UNGE
: return ARM_PL
;
22869 /* UNEQ and LTGT do not have a representation. */
22870 case UNEQ
: /* Fall through. */
22871 case LTGT
: /* Fall through. */
22872 default: return ARM_NV
;
22878 case NE
: return ARM_NE
;
22879 case EQ
: return ARM_EQ
;
22880 case GE
: return ARM_LE
;
22881 case GT
: return ARM_LT
;
22882 case LE
: return ARM_GE
;
22883 case LT
: return ARM_GT
;
22884 case GEU
: return ARM_LS
;
22885 case GTU
: return ARM_CC
;
22886 case LEU
: return ARM_CS
;
22887 case LTU
: return ARM_HI
;
22888 default: return ARM_NV
;
22894 case LTU
: return ARM_CS
;
22895 case GEU
: return ARM_CC
;
22896 case NE
: return ARM_CS
;
22897 case EQ
: return ARM_CC
;
22898 default: return ARM_NV
;
22904 case NE
: return ARM_NE
;
22905 case EQ
: return ARM_EQ
;
22906 case GEU
: return ARM_CS
;
22907 case GTU
: return ARM_HI
;
22908 case LEU
: return ARM_LS
;
22909 case LTU
: return ARM_CC
;
22910 default: return ARM_NV
;
22916 case GE
: return ARM_GE
;
22917 case LT
: return ARM_LT
;
22918 case GEU
: return ARM_CS
;
22919 case LTU
: return ARM_CC
;
22920 default: return ARM_NV
;
22926 case NE
: return ARM_VS
;
22927 case EQ
: return ARM_VC
;
22928 default: return ARM_NV
;
22934 case NE
: return ARM_NE
;
22935 case EQ
: return ARM_EQ
;
22936 case GE
: return ARM_GE
;
22937 case GT
: return ARM_GT
;
22938 case LE
: return ARM_LE
;
22939 case LT
: return ARM_LT
;
22940 case GEU
: return ARM_CS
;
22941 case GTU
: return ARM_HI
;
22942 case LEU
: return ARM_LS
;
22943 case LTU
: return ARM_CC
;
22944 default: return ARM_NV
;
22947 default: gcc_unreachable ();
22951 /* Like maybe_get_arm_condition_code, but never return ARM_NV. */
22952 static enum arm_cond_code
22953 get_arm_condition_code (rtx comparison
)
22955 enum arm_cond_code code
= maybe_get_arm_condition_code (comparison
);
22956 gcc_assert (code
!= ARM_NV
);
22960 /* Implement TARGET_FIXED_CONDITION_CODE_REGS. We only have condition
22961 code registers when not targetting Thumb1. The VFP condition register
22962 only exists when generating hard-float code. */
22964 arm_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
22970 *p2
= TARGET_HARD_FLOAT
? VFPCC_REGNUM
: INVALID_REGNUM
;
22974 /* Tell arm_asm_output_opcode to output IT blocks for conditionally executed
22977 thumb2_final_prescan_insn (rtx_insn
*insn
)
22979 rtx_insn
*first_insn
= insn
;
22980 rtx body
= PATTERN (insn
);
22982 enum arm_cond_code code
;
22987 /* max_insns_skipped in the tune was already taken into account in the
22988 cost model of ifcvt pass when generating COND_EXEC insns. At this stage
22989 just emit the IT blocks as we can. It does not make sense to split
22991 max
= MAX_INSN_PER_IT_BLOCK
;
22993 /* Remove the previous insn from the count of insns to be output. */
22994 if (arm_condexec_count
)
22995 arm_condexec_count
--;
22997 /* Nothing to do if we are already inside a conditional block. */
22998 if (arm_condexec_count
)
23001 if (GET_CODE (body
) != COND_EXEC
)
23004 /* Conditional jumps are implemented directly. */
23008 predicate
= COND_EXEC_TEST (body
);
23009 arm_current_cc
= get_arm_condition_code (predicate
);
23011 n
= get_attr_ce_count (insn
);
23012 arm_condexec_count
= 1;
23013 arm_condexec_mask
= (1 << n
) - 1;
23014 arm_condexec_masklen
= n
;
23015 /* See if subsequent instructions can be combined into the same block. */
23018 insn
= next_nonnote_insn (insn
);
23020 /* Jumping into the middle of an IT block is illegal, so a label or
23021 barrier terminates the block. */
23022 if (!NONJUMP_INSN_P (insn
) && !JUMP_P (insn
))
23025 body
= PATTERN (insn
);
23026 /* USE and CLOBBER aren't really insns, so just skip them. */
23027 if (GET_CODE (body
) == USE
23028 || GET_CODE (body
) == CLOBBER
)
23031 /* ??? Recognize conditional jumps, and combine them with IT blocks. */
23032 if (GET_CODE (body
) != COND_EXEC
)
23034 /* Maximum number of conditionally executed instructions in a block. */
23035 n
= get_attr_ce_count (insn
);
23036 if (arm_condexec_masklen
+ n
> max
)
23039 predicate
= COND_EXEC_TEST (body
);
23040 code
= get_arm_condition_code (predicate
);
23041 mask
= (1 << n
) - 1;
23042 if (arm_current_cc
== code
)
23043 arm_condexec_mask
|= (mask
<< arm_condexec_masklen
);
23044 else if (arm_current_cc
!= ARM_INVERSE_CONDITION_CODE(code
))
23047 arm_condexec_count
++;
23048 arm_condexec_masklen
+= n
;
23050 /* A jump must be the last instruction in a conditional block. */
23054 /* Restore recog_data (getting the attributes of other insns can
23055 destroy this array, but final.c assumes that it remains intact
23056 across this call). */
23057 extract_constrain_insn_cached (first_insn
);
23061 arm_final_prescan_insn (rtx_insn
*insn
)
23063 /* BODY will hold the body of INSN. */
23064 rtx body
= PATTERN (insn
);
23066 /* This will be 1 if trying to repeat the trick, and things need to be
23067 reversed if it appears to fail. */
23070 /* If we start with a return insn, we only succeed if we find another one. */
23071 int seeking_return
= 0;
23072 enum rtx_code return_code
= UNKNOWN
;
23074 /* START_INSN will hold the insn from where we start looking. This is the
23075 first insn after the following code_label if REVERSE is true. */
23076 rtx_insn
*start_insn
= insn
;
23078 /* If in state 4, check if the target branch is reached, in order to
23079 change back to state 0. */
23080 if (arm_ccfsm_state
== 4)
23082 if (insn
== arm_target_insn
)
23084 arm_target_insn
= NULL
;
23085 arm_ccfsm_state
= 0;
23090 /* If in state 3, it is possible to repeat the trick, if this insn is an
23091 unconditional branch to a label, and immediately following this branch
23092 is the previous target label which is only used once, and the label this
23093 branch jumps to is not too far off. */
23094 if (arm_ccfsm_state
== 3)
23096 if (simplejump_p (insn
))
23098 start_insn
= next_nonnote_insn (start_insn
);
23099 if (BARRIER_P (start_insn
))
23101 /* XXX Isn't this always a barrier? */
23102 start_insn
= next_nonnote_insn (start_insn
);
23104 if (LABEL_P (start_insn
)
23105 && CODE_LABEL_NUMBER (start_insn
) == arm_target_label
23106 && LABEL_NUSES (start_insn
) == 1)
23111 else if (ANY_RETURN_P (body
))
23113 start_insn
= next_nonnote_insn (start_insn
);
23114 if (BARRIER_P (start_insn
))
23115 start_insn
= next_nonnote_insn (start_insn
);
23116 if (LABEL_P (start_insn
)
23117 && CODE_LABEL_NUMBER (start_insn
) == arm_target_label
23118 && LABEL_NUSES (start_insn
) == 1)
23121 seeking_return
= 1;
23122 return_code
= GET_CODE (body
);
23131 gcc_assert (!arm_ccfsm_state
|| reverse
);
23132 if (!JUMP_P (insn
))
23135 /* This jump might be paralleled with a clobber of the condition codes
23136 the jump should always come first */
23137 if (GET_CODE (body
) == PARALLEL
&& XVECLEN (body
, 0) > 0)
23138 body
= XVECEXP (body
, 0, 0);
23141 || (GET_CODE (body
) == SET
&& GET_CODE (SET_DEST (body
)) == PC
23142 && GET_CODE (SET_SRC (body
)) == IF_THEN_ELSE
))
23145 int fail
= FALSE
, succeed
= FALSE
;
23146 /* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */
23147 int then_not_else
= TRUE
;
23148 rtx_insn
*this_insn
= start_insn
;
23151 /* Register the insn jumped to. */
23154 if (!seeking_return
)
23155 label
= XEXP (SET_SRC (body
), 0);
23157 else if (GET_CODE (XEXP (SET_SRC (body
), 1)) == LABEL_REF
)
23158 label
= XEXP (XEXP (SET_SRC (body
), 1), 0);
23159 else if (GET_CODE (XEXP (SET_SRC (body
), 2)) == LABEL_REF
)
23161 label
= XEXP (XEXP (SET_SRC (body
), 2), 0);
23162 then_not_else
= FALSE
;
23164 else if (ANY_RETURN_P (XEXP (SET_SRC (body
), 1)))
23166 seeking_return
= 1;
23167 return_code
= GET_CODE (XEXP (SET_SRC (body
), 1));
23169 else if (ANY_RETURN_P (XEXP (SET_SRC (body
), 2)))
23171 seeking_return
= 1;
23172 return_code
= GET_CODE (XEXP (SET_SRC (body
), 2));
23173 then_not_else
= FALSE
;
23176 gcc_unreachable ();
23178 /* See how many insns this branch skips, and what kind of insns. If all
23179 insns are okay, and the label or unconditional branch to the same
23180 label is not too far away, succeed. */
23181 for (insns_skipped
= 0;
23182 !fail
&& !succeed
&& insns_skipped
++ < max_insns_skipped
;)
23186 this_insn
= next_nonnote_insn (this_insn
);
23190 switch (GET_CODE (this_insn
))
23193 /* Succeed if it is the target label, otherwise fail since
23194 control falls in from somewhere else. */
23195 if (this_insn
== label
)
23197 arm_ccfsm_state
= 1;
23205 /* Succeed if the following insn is the target label.
23207 If return insns are used then the last insn in a function
23208 will be a barrier. */
23209 this_insn
= next_nonnote_insn (this_insn
);
23210 if (this_insn
&& this_insn
== label
)
23212 arm_ccfsm_state
= 1;
23220 /* The AAPCS says that conditional calls should not be
23221 used since they make interworking inefficient (the
23222 linker can't transform BL<cond> into BLX). That's
23223 only a problem if the machine has BLX. */
23230 /* Succeed if the following insn is the target label, or
23231 if the following two insns are a barrier and the
23233 this_insn
= next_nonnote_insn (this_insn
);
23234 if (this_insn
&& BARRIER_P (this_insn
))
23235 this_insn
= next_nonnote_insn (this_insn
);
23237 if (this_insn
&& this_insn
== label
23238 && insns_skipped
< max_insns_skipped
)
23240 arm_ccfsm_state
= 1;
23248 /* If this is an unconditional branch to the same label, succeed.
23249 If it is to another label, do nothing. If it is conditional,
23251 /* XXX Probably, the tests for SET and the PC are
23254 scanbody
= PATTERN (this_insn
);
23255 if (GET_CODE (scanbody
) == SET
23256 && GET_CODE (SET_DEST (scanbody
)) == PC
)
23258 if (GET_CODE (SET_SRC (scanbody
)) == LABEL_REF
23259 && XEXP (SET_SRC (scanbody
), 0) == label
&& !reverse
)
23261 arm_ccfsm_state
= 2;
23264 else if (GET_CODE (SET_SRC (scanbody
)) == IF_THEN_ELSE
)
23267 /* Fail if a conditional return is undesirable (e.g. on a
23268 StrongARM), but still allow this if optimizing for size. */
23269 else if (GET_CODE (scanbody
) == return_code
23270 && !use_return_insn (TRUE
, NULL
)
23273 else if (GET_CODE (scanbody
) == return_code
)
23275 arm_ccfsm_state
= 2;
23278 else if (GET_CODE (scanbody
) == PARALLEL
)
23280 switch (get_attr_conds (this_insn
))
23290 fail
= TRUE
; /* Unrecognized jump (e.g. epilogue). */
23295 /* Instructions using or affecting the condition codes make it
23297 scanbody
= PATTERN (this_insn
);
23298 if (!(GET_CODE (scanbody
) == SET
23299 || GET_CODE (scanbody
) == PARALLEL
)
23300 || get_attr_conds (this_insn
) != CONDS_NOCOND
)
23310 if ((!seeking_return
) && (arm_ccfsm_state
== 1 || reverse
))
23311 arm_target_label
= CODE_LABEL_NUMBER (label
);
23314 gcc_assert (seeking_return
|| arm_ccfsm_state
== 2);
23316 while (this_insn
&& GET_CODE (PATTERN (this_insn
)) == USE
)
23318 this_insn
= next_nonnote_insn (this_insn
);
23319 gcc_assert (!this_insn
23320 || (!BARRIER_P (this_insn
)
23321 && !LABEL_P (this_insn
)));
23325 /* Oh, dear! we ran off the end.. give up. */
23326 extract_constrain_insn_cached (insn
);
23327 arm_ccfsm_state
= 0;
23328 arm_target_insn
= NULL
;
23331 arm_target_insn
= this_insn
;
23334 /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from
23337 arm_current_cc
= get_arm_condition_code (XEXP (SET_SRC (body
), 0));
23339 if (reverse
|| then_not_else
)
23340 arm_current_cc
= ARM_INVERSE_CONDITION_CODE (arm_current_cc
);
23343 /* Restore recog_data (getting the attributes of other insns can
23344 destroy this array, but final.c assumes that it remains intact
23345 across this call. */
23346 extract_constrain_insn_cached (insn
);
23350 /* Output IT instructions. */
23352 thumb2_asm_output_opcode (FILE * stream
)
23357 if (arm_condexec_mask
)
23359 for (n
= 0; n
< arm_condexec_masklen
; n
++)
23360 buff
[n
] = (arm_condexec_mask
& (1 << n
)) ? 't' : 'e';
23362 asm_fprintf(stream
, "i%s\t%s\n\t", buff
,
23363 arm_condition_codes
[arm_current_cc
]);
23364 arm_condexec_mask
= 0;
23368 /* Implement TARGET_HARD_REGNO_NREGS. On the ARM core regs are
23369 UNITS_PER_WORD bytes wide. */
23370 static unsigned int
23371 arm_hard_regno_nregs (unsigned int regno
, machine_mode mode
)
23374 && regno
> PC_REGNUM
23375 && regno
!= FRAME_POINTER_REGNUM
23376 && regno
!= ARG_POINTER_REGNUM
23377 && !IS_VFP_REGNUM (regno
))
23380 return ARM_NUM_REGS (mode
);
23383 /* Implement TARGET_HARD_REGNO_MODE_OK. */
23385 arm_hard_regno_mode_ok (unsigned int regno
, machine_mode mode
)
23387 if (GET_MODE_CLASS (mode
) == MODE_CC
)
23388 return (regno
== CC_REGNUM
23389 || (TARGET_HARD_FLOAT
23390 && regno
== VFPCC_REGNUM
));
23392 if (regno
== CC_REGNUM
&& GET_MODE_CLASS (mode
) != MODE_CC
)
23396 /* For the Thumb we only allow values bigger than SImode in
23397 registers 0 - 6, so that there is always a second low
23398 register available to hold the upper part of the value.
23399 We probably we ought to ensure that the register is the
23400 start of an even numbered register pair. */
23401 return (ARM_NUM_REGS (mode
) < 2) || (regno
< LAST_LO_REGNUM
);
23403 if (TARGET_HARD_FLOAT
&& IS_VFP_REGNUM (regno
))
23405 if (mode
== SFmode
|| mode
== SImode
)
23406 return VFP_REGNO_OK_FOR_SINGLE (regno
);
23408 if (mode
== DFmode
)
23409 return VFP_REGNO_OK_FOR_DOUBLE (regno
);
23411 if (mode
== HFmode
)
23412 return VFP_REGNO_OK_FOR_SINGLE (regno
);
23414 /* VFP registers can hold HImode values. */
23415 if (mode
== HImode
)
23416 return VFP_REGNO_OK_FOR_SINGLE (regno
);
23419 return (VALID_NEON_DREG_MODE (mode
) && VFP_REGNO_OK_FOR_DOUBLE (regno
))
23420 || (VALID_NEON_QREG_MODE (mode
)
23421 && NEON_REGNO_OK_FOR_QUAD (regno
))
23422 || (mode
== TImode
&& NEON_REGNO_OK_FOR_NREGS (regno
, 2))
23423 || (mode
== EImode
&& NEON_REGNO_OK_FOR_NREGS (regno
, 3))
23424 || (mode
== OImode
&& NEON_REGNO_OK_FOR_NREGS (regno
, 4))
23425 || (mode
== CImode
&& NEON_REGNO_OK_FOR_NREGS (regno
, 6))
23426 || (mode
== XImode
&& NEON_REGNO_OK_FOR_NREGS (regno
, 8));
23431 if (TARGET_REALLY_IWMMXT
)
23433 if (IS_IWMMXT_GR_REGNUM (regno
))
23434 return mode
== SImode
;
23436 if (IS_IWMMXT_REGNUM (regno
))
23437 return VALID_IWMMXT_REG_MODE (mode
);
23440 /* We allow almost any value to be stored in the general registers.
23441 Restrict doubleword quantities to even register pairs in ARM state
23442 so that we can use ldrd. Do not allow very large Neon structure
23443 opaque modes in general registers; they would use too many. */
23444 if (regno
<= LAST_ARM_REGNUM
)
23446 if (ARM_NUM_REGS (mode
) > 4)
23452 return !(TARGET_LDRD
&& GET_MODE_SIZE (mode
) > 4 && (regno
& 1) != 0);
23455 if (regno
== FRAME_POINTER_REGNUM
23456 || regno
== ARG_POINTER_REGNUM
)
23457 /* We only allow integers in the fake hard registers. */
23458 return GET_MODE_CLASS (mode
) == MODE_INT
;
23463 /* Implement TARGET_MODES_TIEABLE_P. */
23466 arm_modes_tieable_p (machine_mode mode1
, machine_mode mode2
)
23468 if (GET_MODE_CLASS (mode1
) == GET_MODE_CLASS (mode2
))
23471 /* We specifically want to allow elements of "structure" modes to
23472 be tieable to the structure. This more general condition allows
23473 other rarer situations too. */
23475 && (VALID_NEON_DREG_MODE (mode1
)
23476 || VALID_NEON_QREG_MODE (mode1
)
23477 || VALID_NEON_STRUCT_MODE (mode1
))
23478 && (VALID_NEON_DREG_MODE (mode2
)
23479 || VALID_NEON_QREG_MODE (mode2
)
23480 || VALID_NEON_STRUCT_MODE (mode2
)))
23486 /* For efficiency and historical reasons LO_REGS, HI_REGS and CC_REGS are
23487 not used in arm mode. */
23490 arm_regno_class (int regno
)
23492 if (regno
== PC_REGNUM
)
23497 if (regno
== STACK_POINTER_REGNUM
)
23499 if (regno
== CC_REGNUM
)
23506 if (TARGET_THUMB2
&& regno
< 8)
23509 if ( regno
<= LAST_ARM_REGNUM
23510 || regno
== FRAME_POINTER_REGNUM
23511 || regno
== ARG_POINTER_REGNUM
)
23512 return TARGET_THUMB2
? HI_REGS
: GENERAL_REGS
;
23514 if (regno
== CC_REGNUM
|| regno
== VFPCC_REGNUM
)
23515 return TARGET_THUMB2
? CC_REG
: NO_REGS
;
23517 if (IS_VFP_REGNUM (regno
))
23519 if (regno
<= D7_VFP_REGNUM
)
23520 return VFP_D0_D7_REGS
;
23521 else if (regno
<= LAST_LO_VFP_REGNUM
)
23522 return VFP_LO_REGS
;
23524 return VFP_HI_REGS
;
23527 if (IS_IWMMXT_REGNUM (regno
))
23528 return IWMMXT_REGS
;
23530 if (IS_IWMMXT_GR_REGNUM (regno
))
23531 return IWMMXT_GR_REGS
;
23536 /* Handle a special case when computing the offset
23537 of an argument from the frame pointer. */
23539 arm_debugger_arg_offset (int value
, rtx addr
)
23543 /* We are only interested if dbxout_parms() failed to compute the offset. */
23547 /* We can only cope with the case where the address is held in a register. */
23551 /* If we are using the frame pointer to point at the argument, then
23552 an offset of 0 is correct. */
23553 if (REGNO (addr
) == (unsigned) HARD_FRAME_POINTER_REGNUM
)
23556 /* If we are using the stack pointer to point at the
23557 argument, then an offset of 0 is correct. */
23558 /* ??? Check this is consistent with thumb2 frame layout. */
23559 if ((TARGET_THUMB
|| !frame_pointer_needed
)
23560 && REGNO (addr
) == SP_REGNUM
)
23563 /* Oh dear. The argument is pointed to by a register rather
23564 than being held in a register, or being stored at a known
23565 offset from the frame pointer. Since GDB only understands
23566 those two kinds of argument we must translate the address
23567 held in the register into an offset from the frame pointer.
23568 We do this by searching through the insns for the function
23569 looking to see where this register gets its value. If the
23570 register is initialized from the frame pointer plus an offset
23571 then we are in luck and we can continue, otherwise we give up.
23573 This code is exercised by producing debugging information
23574 for a function with arguments like this:
23576 double func (double a, double b, int c, double d) {return d;}
23578 Without this code the stab for parameter 'd' will be set to
23579 an offset of 0 from the frame pointer, rather than 8. */
23581 /* The if() statement says:
23583 If the insn is a normal instruction
23584 and if the insn is setting the value in a register
23585 and if the register being set is the register holding the address of the argument
23586 and if the address is computing by an addition
23587 that involves adding to a register
23588 which is the frame pointer
23593 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
23595 if ( NONJUMP_INSN_P (insn
)
23596 && GET_CODE (PATTERN (insn
)) == SET
23597 && REGNO (XEXP (PATTERN (insn
), 0)) == REGNO (addr
)
23598 && GET_CODE (XEXP (PATTERN (insn
), 1)) == PLUS
23599 && REG_P (XEXP (XEXP (PATTERN (insn
), 1), 0))
23600 && REGNO (XEXP (XEXP (PATTERN (insn
), 1), 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM
23601 && CONST_INT_P (XEXP (XEXP (PATTERN (insn
), 1), 1))
23604 value
= INTVAL (XEXP (XEXP (PATTERN (insn
), 1), 1));
23613 warning (0, "unable to compute real location of stacked parameter");
23614 value
= 8; /* XXX magic hack */
23620 /* Implement TARGET_PROMOTED_TYPE. */
23623 arm_promoted_type (const_tree t
)
23625 if (SCALAR_FLOAT_TYPE_P (t
)
23626 && TYPE_PRECISION (t
) == 16
23627 && TYPE_MAIN_VARIANT (t
) == arm_fp16_type_node
)
23628 return float_type_node
;
23632 /* Implement TARGET_SCALAR_MODE_SUPPORTED_P.
23633 This simply adds HFmode as a supported mode; even though we don't
23634 implement arithmetic on this type directly, it's supported by
23635 optabs conversions, much the way the double-word arithmetic is
23636 special-cased in the default hook. */
23639 arm_scalar_mode_supported_p (scalar_mode mode
)
23641 if (mode
== HFmode
)
23642 return (arm_fp16_format
!= ARM_FP16_FORMAT_NONE
);
23643 else if (ALL_FIXED_POINT_MODE_P (mode
))
23646 return default_scalar_mode_supported_p (mode
);
23649 /* Set the value of FLT_EVAL_METHOD.
23650 ISO/IEC TS 18661-3 defines two values that we'd like to make use of:
23652 0: evaluate all operations and constants, whose semantic type has at
23653 most the range and precision of type float, to the range and
23654 precision of float; evaluate all other operations and constants to
23655 the range and precision of the semantic type;
23657 N, where _FloatN is a supported interchange floating type
23658 evaluate all operations and constants, whose semantic type has at
23659 most the range and precision of _FloatN type, to the range and
23660 precision of the _FloatN type; evaluate all other operations and
23661 constants to the range and precision of the semantic type;
23663 If we have the ARMv8.2-A extensions then we support _Float16 in native
23664 precision, so we should set this to 16. Otherwise, we support the type,
23665 but want to evaluate expressions in float precision, so set this to
23668 static enum flt_eval_method
23669 arm_excess_precision (enum excess_precision_type type
)
23673 case EXCESS_PRECISION_TYPE_FAST
:
23674 case EXCESS_PRECISION_TYPE_STANDARD
:
23675 /* We can calculate either in 16-bit range and precision or
23676 32-bit range and precision. Make that decision based on whether
23677 we have native support for the ARMv8.2-A 16-bit floating-point
23678 instructions or not. */
23679 return (TARGET_VFP_FP16INST
23680 ? FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16
23681 : FLT_EVAL_METHOD_PROMOTE_TO_FLOAT
);
23682 case EXCESS_PRECISION_TYPE_IMPLICIT
:
23683 return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16
;
23685 gcc_unreachable ();
23687 return FLT_EVAL_METHOD_UNPREDICTABLE
;
23691 /* Implement TARGET_FLOATN_MODE. Make very sure that we don't provide
23692 _Float16 if we are using anything other than ieee format for 16-bit
23693 floating point. Otherwise, punt to the default implementation. */
23694 static opt_scalar_float_mode
23695 arm_floatn_mode (int n
, bool extended
)
23697 if (!extended
&& n
== 16)
23699 if (arm_fp16_format
== ARM_FP16_FORMAT_IEEE
)
23701 return opt_scalar_float_mode ();
23704 return default_floatn_mode (n
, extended
);
23708 /* Set up OPERANDS for a register copy from SRC to DEST, taking care
23709 not to early-clobber SRC registers in the process.
23711 We assume that the operands described by SRC and DEST represent a
23712 decomposed copy of OPERANDS[1] into OPERANDS[0]. COUNT is the
23713 number of components into which the copy has been decomposed. */
23715 neon_disambiguate_copy (rtx
*operands
, rtx
*dest
, rtx
*src
, unsigned int count
)
23719 if (!reg_overlap_mentioned_p (operands
[0], operands
[1])
23720 || REGNO (operands
[0]) < REGNO (operands
[1]))
23722 for (i
= 0; i
< count
; i
++)
23724 operands
[2 * i
] = dest
[i
];
23725 operands
[2 * i
+ 1] = src
[i
];
23730 for (i
= 0; i
< count
; i
++)
23732 operands
[2 * i
] = dest
[count
- i
- 1];
23733 operands
[2 * i
+ 1] = src
[count
- i
- 1];
23738 /* Split operands into moves from op[1] + op[2] into op[0]. */
23741 neon_split_vcombine (rtx operands
[3])
23743 unsigned int dest
= REGNO (operands
[0]);
23744 unsigned int src1
= REGNO (operands
[1]);
23745 unsigned int src2
= REGNO (operands
[2]);
23746 machine_mode halfmode
= GET_MODE (operands
[1]);
23747 unsigned int halfregs
= REG_NREGS (operands
[1]);
23748 rtx destlo
, desthi
;
23750 if (src1
== dest
&& src2
== dest
+ halfregs
)
23752 /* No-op move. Can't split to nothing; emit something. */
23753 emit_note (NOTE_INSN_DELETED
);
23757 /* Preserve register attributes for variable tracking. */
23758 destlo
= gen_rtx_REG_offset (operands
[0], halfmode
, dest
, 0);
23759 desthi
= gen_rtx_REG_offset (operands
[0], halfmode
, dest
+ halfregs
,
23760 GET_MODE_SIZE (halfmode
));
23762 /* Special case of reversed high/low parts. Use VSWP. */
23763 if (src2
== dest
&& src1
== dest
+ halfregs
)
23765 rtx x
= gen_rtx_SET (destlo
, operands
[1]);
23766 rtx y
= gen_rtx_SET (desthi
, operands
[2]);
23767 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, x
, y
)));
23771 if (!reg_overlap_mentioned_p (operands
[2], destlo
))
23773 /* Try to avoid unnecessary moves if part of the result
23774 is in the right place already. */
23776 emit_move_insn (destlo
, operands
[1]);
23777 if (src2
!= dest
+ halfregs
)
23778 emit_move_insn (desthi
, operands
[2]);
23782 if (src2
!= dest
+ halfregs
)
23783 emit_move_insn (desthi
, operands
[2]);
23785 emit_move_insn (destlo
, operands
[1]);
23789 /* Return the number (counting from 0) of
23790 the least significant set bit in MASK. */
23793 number_of_first_bit_set (unsigned mask
)
23795 return ctz_hwi (mask
);
23798 /* Like emit_multi_reg_push, but allowing for a different set of
23799 registers to be described as saved. MASK is the set of registers
23800 to be saved; REAL_REGS is the set of registers to be described as
23801 saved. If REAL_REGS is 0, only describe the stack adjustment. */
23804 thumb1_emit_multi_reg_push (unsigned long mask
, unsigned long real_regs
)
23806 unsigned long regno
;
23807 rtx par
[10], tmp
, reg
;
23811 /* Build the parallel of the registers actually being stored. */
23812 for (i
= 0; mask
; ++i
, mask
&= mask
- 1)
23814 regno
= ctz_hwi (mask
);
23815 reg
= gen_rtx_REG (SImode
, regno
);
23818 tmp
= gen_rtx_UNSPEC (BLKmode
, gen_rtvec (1, reg
), UNSPEC_PUSH_MULT
);
23820 tmp
= gen_rtx_USE (VOIDmode
, reg
);
23825 tmp
= plus_constant (Pmode
, stack_pointer_rtx
, -4 * i
);
23826 tmp
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, tmp
);
23827 tmp
= gen_frame_mem (BLKmode
, tmp
);
23828 tmp
= gen_rtx_SET (tmp
, par
[0]);
23831 tmp
= gen_rtx_PARALLEL (VOIDmode
, gen_rtvec_v (i
, par
));
23832 insn
= emit_insn (tmp
);
23834 /* Always build the stack adjustment note for unwind info. */
23835 tmp
= plus_constant (Pmode
, stack_pointer_rtx
, -4 * i
);
23836 tmp
= gen_rtx_SET (stack_pointer_rtx
, tmp
);
23839 /* Build the parallel of the registers recorded as saved for unwind. */
23840 for (j
= 0; real_regs
; ++j
, real_regs
&= real_regs
- 1)
23842 regno
= ctz_hwi (real_regs
);
23843 reg
= gen_rtx_REG (SImode
, regno
);
23845 tmp
= plus_constant (Pmode
, stack_pointer_rtx
, j
* 4);
23846 tmp
= gen_frame_mem (SImode
, tmp
);
23847 tmp
= gen_rtx_SET (tmp
, reg
);
23848 RTX_FRAME_RELATED_P (tmp
) = 1;
23856 RTX_FRAME_RELATED_P (par
[0]) = 1;
23857 tmp
= gen_rtx_SEQUENCE (VOIDmode
, gen_rtvec_v (j
+ 1, par
));
23860 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, tmp
);
23865 /* Emit code to push or pop registers to or from the stack. F is the
23866 assembly file. MASK is the registers to pop. */
23868 thumb_pop (FILE *f
, unsigned long mask
)
23871 int lo_mask
= mask
& 0xFF;
23875 if (lo_mask
== 0 && (mask
& (1 << PC_REGNUM
)))
23877 /* Special case. Do not generate a POP PC statement here, do it in
23879 thumb_exit (f
, -1);
23883 fprintf (f
, "\tpop\t{");
23885 /* Look at the low registers first. */
23886 for (regno
= 0; regno
<= LAST_LO_REGNUM
; regno
++, lo_mask
>>= 1)
23890 asm_fprintf (f
, "%r", regno
);
23892 if ((lo_mask
& ~1) != 0)
23897 if (mask
& (1 << PC_REGNUM
))
23899 /* Catch popping the PC. */
23900 if (TARGET_INTERWORK
|| TARGET_BACKTRACE
|| crtl
->calls_eh_return
23901 || IS_CMSE_ENTRY (arm_current_func_type ()))
23903 /* The PC is never poped directly, instead
23904 it is popped into r3 and then BX is used. */
23905 fprintf (f
, "}\n");
23907 thumb_exit (f
, -1);
23916 asm_fprintf (f
, "%r", PC_REGNUM
);
23920 fprintf (f
, "}\n");
23923 /* Generate code to return from a thumb function.
23924 If 'reg_containing_return_addr' is -1, then the return address is
23925 actually on the stack, at the stack pointer. */
23927 thumb_exit (FILE *f
, int reg_containing_return_addr
)
23929 unsigned regs_available_for_popping
;
23930 unsigned regs_to_pop
;
23932 unsigned available
;
23936 int restore_a4
= FALSE
;
23938 /* Compute the registers we need to pop. */
23942 if (reg_containing_return_addr
== -1)
23944 regs_to_pop
|= 1 << LR_REGNUM
;
23948 if (TARGET_BACKTRACE
)
23950 /* Restore the (ARM) frame pointer and stack pointer. */
23951 regs_to_pop
|= (1 << ARM_HARD_FRAME_POINTER_REGNUM
) | (1 << SP_REGNUM
);
23955 /* If there is nothing to pop then just emit the BX instruction and
23957 if (pops_needed
== 0)
23959 if (crtl
->calls_eh_return
)
23960 asm_fprintf (f
, "\tadd\t%r, %r\n", SP_REGNUM
, ARM_EH_STACKADJ_REGNUM
);
23962 if (IS_CMSE_ENTRY (arm_current_func_type ()))
23964 asm_fprintf (f
, "\tmsr\tAPSR_nzcvq, %r\n",
23965 reg_containing_return_addr
);
23966 asm_fprintf (f
, "\tbxns\t%r\n", reg_containing_return_addr
);
23969 asm_fprintf (f
, "\tbx\t%r\n", reg_containing_return_addr
);
23972 /* Otherwise if we are not supporting interworking and we have not created
23973 a backtrace structure and the function was not entered in ARM mode then
23974 just pop the return address straight into the PC. */
23975 else if (!TARGET_INTERWORK
23976 && !TARGET_BACKTRACE
23977 && !is_called_in_ARM_mode (current_function_decl
)
23978 && !crtl
->calls_eh_return
23979 && !IS_CMSE_ENTRY (arm_current_func_type ()))
23981 asm_fprintf (f
, "\tpop\t{%r}\n", PC_REGNUM
);
23985 /* Find out how many of the (return) argument registers we can corrupt. */
23986 regs_available_for_popping
= 0;
23988 /* If returning via __builtin_eh_return, the bottom three registers
23989 all contain information needed for the return. */
23990 if (crtl
->calls_eh_return
)
23994 /* If we can deduce the registers used from the function's
23995 return value. This is more reliable that examining
23996 df_regs_ever_live_p () because that will be set if the register is
23997 ever used in the function, not just if the register is used
23998 to hold a return value. */
24000 if (crtl
->return_rtx
!= 0)
24001 mode
= GET_MODE (crtl
->return_rtx
);
24003 mode
= DECL_MODE (DECL_RESULT (current_function_decl
));
24005 size
= GET_MODE_SIZE (mode
);
24009 /* In a void function we can use any argument register.
24010 In a function that returns a structure on the stack
24011 we can use the second and third argument registers. */
24012 if (mode
== VOIDmode
)
24013 regs_available_for_popping
=
24014 (1 << ARG_REGISTER (1))
24015 | (1 << ARG_REGISTER (2))
24016 | (1 << ARG_REGISTER (3));
24018 regs_available_for_popping
=
24019 (1 << ARG_REGISTER (2))
24020 | (1 << ARG_REGISTER (3));
24022 else if (size
<= 4)
24023 regs_available_for_popping
=
24024 (1 << ARG_REGISTER (2))
24025 | (1 << ARG_REGISTER (3));
24026 else if (size
<= 8)
24027 regs_available_for_popping
=
24028 (1 << ARG_REGISTER (3));
24031 /* Match registers to be popped with registers into which we pop them. */
24032 for (available
= regs_available_for_popping
,
24033 required
= regs_to_pop
;
24034 required
!= 0 && available
!= 0;
24035 available
&= ~(available
& - available
),
24036 required
&= ~(required
& - required
))
24039 /* If we have any popping registers left over, remove them. */
24041 regs_available_for_popping
&= ~available
;
24043 /* Otherwise if we need another popping register we can use
24044 the fourth argument register. */
24045 else if (pops_needed
)
24047 /* If we have not found any free argument registers and
24048 reg a4 contains the return address, we must move it. */
24049 if (regs_available_for_popping
== 0
24050 && reg_containing_return_addr
== LAST_ARG_REGNUM
)
24052 asm_fprintf (f
, "\tmov\t%r, %r\n", LR_REGNUM
, LAST_ARG_REGNUM
);
24053 reg_containing_return_addr
= LR_REGNUM
;
24055 else if (size
> 12)
24057 /* Register a4 is being used to hold part of the return value,
24058 but we have dire need of a free, low register. */
24061 asm_fprintf (f
, "\tmov\t%r, %r\n",IP_REGNUM
, LAST_ARG_REGNUM
);
24064 if (reg_containing_return_addr
!= LAST_ARG_REGNUM
)
24066 /* The fourth argument register is available. */
24067 regs_available_for_popping
|= 1 << LAST_ARG_REGNUM
;
24073 /* Pop as many registers as we can. */
24074 thumb_pop (f
, regs_available_for_popping
);
24076 /* Process the registers we popped. */
24077 if (reg_containing_return_addr
== -1)
24079 /* The return address was popped into the lowest numbered register. */
24080 regs_to_pop
&= ~(1 << LR_REGNUM
);
24082 reg_containing_return_addr
=
24083 number_of_first_bit_set (regs_available_for_popping
);
24085 /* Remove this register for the mask of available registers, so that
24086 the return address will not be corrupted by further pops. */
24087 regs_available_for_popping
&= ~(1 << reg_containing_return_addr
);
24090 /* If we popped other registers then handle them here. */
24091 if (regs_available_for_popping
)
24095 /* Work out which register currently contains the frame pointer. */
24096 frame_pointer
= number_of_first_bit_set (regs_available_for_popping
);
24098 /* Move it into the correct place. */
24099 asm_fprintf (f
, "\tmov\t%r, %r\n",
24100 ARM_HARD_FRAME_POINTER_REGNUM
, frame_pointer
);
24102 /* (Temporarily) remove it from the mask of popped registers. */
24103 regs_available_for_popping
&= ~(1 << frame_pointer
);
24104 regs_to_pop
&= ~(1 << ARM_HARD_FRAME_POINTER_REGNUM
);
24106 if (regs_available_for_popping
)
24110 /* We popped the stack pointer as well,
24111 find the register that contains it. */
24112 stack_pointer
= number_of_first_bit_set (regs_available_for_popping
);
24114 /* Move it into the stack register. */
24115 asm_fprintf (f
, "\tmov\t%r, %r\n", SP_REGNUM
, stack_pointer
);
24117 /* At this point we have popped all necessary registers, so
24118 do not worry about restoring regs_available_for_popping
24119 to its correct value:
24121 assert (pops_needed == 0)
24122 assert (regs_available_for_popping == (1 << frame_pointer))
24123 assert (regs_to_pop == (1 << STACK_POINTER)) */
24127 /* Since we have just move the popped value into the frame
24128 pointer, the popping register is available for reuse, and
24129 we know that we still have the stack pointer left to pop. */
24130 regs_available_for_popping
|= (1 << frame_pointer
);
24134 /* If we still have registers left on the stack, but we no longer have
24135 any registers into which we can pop them, then we must move the return
24136 address into the link register and make available the register that
24138 if (regs_available_for_popping
== 0 && pops_needed
> 0)
24140 regs_available_for_popping
|= 1 << reg_containing_return_addr
;
24142 asm_fprintf (f
, "\tmov\t%r, %r\n", LR_REGNUM
,
24143 reg_containing_return_addr
);
24145 reg_containing_return_addr
= LR_REGNUM
;
24148 /* If we have registers left on the stack then pop some more.
24149 We know that at most we will want to pop FP and SP. */
24150 if (pops_needed
> 0)
24155 thumb_pop (f
, regs_available_for_popping
);
24157 /* We have popped either FP or SP.
24158 Move whichever one it is into the correct register. */
24159 popped_into
= number_of_first_bit_set (regs_available_for_popping
);
24160 move_to
= number_of_first_bit_set (regs_to_pop
);
24162 asm_fprintf (f
, "\tmov\t%r, %r\n", move_to
, popped_into
);
24166 /* If we still have not popped everything then we must have only
24167 had one register available to us and we are now popping the SP. */
24168 if (pops_needed
> 0)
24172 thumb_pop (f
, regs_available_for_popping
);
24174 popped_into
= number_of_first_bit_set (regs_available_for_popping
);
24176 asm_fprintf (f
, "\tmov\t%r, %r\n", SP_REGNUM
, popped_into
);
24178 assert (regs_to_pop == (1 << STACK_POINTER))
24179 assert (pops_needed == 1)
24183 /* If necessary restore the a4 register. */
24186 if (reg_containing_return_addr
!= LR_REGNUM
)
24188 asm_fprintf (f
, "\tmov\t%r, %r\n", LR_REGNUM
, LAST_ARG_REGNUM
);
24189 reg_containing_return_addr
= LR_REGNUM
;
24192 asm_fprintf (f
, "\tmov\t%r, %r\n", LAST_ARG_REGNUM
, IP_REGNUM
);
24195 if (crtl
->calls_eh_return
)
24196 asm_fprintf (f
, "\tadd\t%r, %r\n", SP_REGNUM
, ARM_EH_STACKADJ_REGNUM
);
24198 /* Return to caller. */
24199 if (IS_CMSE_ENTRY (arm_current_func_type ()))
24201 /* This is for the cases where LR is not being used to contain the return
24202 address. It may therefore contain information that we might not want
24203 to leak, hence it must be cleared. The value in R0 will never be a
24204 secret at this point, so it is safe to use it, see the clearing code
24205 in 'cmse_nonsecure_entry_clear_before_return'. */
24206 if (reg_containing_return_addr
!= LR_REGNUM
)
24207 asm_fprintf (f
, "\tmov\tlr, r0\n");
24209 asm_fprintf (f
, "\tmsr\tAPSR_nzcvq, %r\n", reg_containing_return_addr
);
24210 asm_fprintf (f
, "\tbxns\t%r\n", reg_containing_return_addr
);
24213 asm_fprintf (f
, "\tbx\t%r\n", reg_containing_return_addr
);
24216 /* Scan INSN just before assembler is output for it.
24217 For Thumb-1, we track the status of the condition codes; this
24218 information is used in the cbranchsi4_insn pattern. */
24220 thumb1_final_prescan_insn (rtx_insn
*insn
)
24222 if (flag_print_asm_name
)
24223 asm_fprintf (asm_out_file
, "%@ 0x%04x\n",
24224 INSN_ADDRESSES (INSN_UID (insn
)));
24225 /* Don't overwrite the previous setter when we get to a cbranch. */
24226 if (INSN_CODE (insn
) != CODE_FOR_cbranchsi4_insn
)
24228 enum attr_conds conds
;
24230 if (cfun
->machine
->thumb1_cc_insn
)
24232 if (modified_in_p (cfun
->machine
->thumb1_cc_op0
, insn
)
24233 || modified_in_p (cfun
->machine
->thumb1_cc_op1
, insn
))
24236 conds
= get_attr_conds (insn
);
24237 if (conds
== CONDS_SET
)
24239 rtx set
= single_set (insn
);
24240 cfun
->machine
->thumb1_cc_insn
= insn
;
24241 cfun
->machine
->thumb1_cc_op0
= SET_DEST (set
);
24242 cfun
->machine
->thumb1_cc_op1
= const0_rtx
;
24243 cfun
->machine
->thumb1_cc_mode
= CC_NOOVmode
;
24244 if (INSN_CODE (insn
) == CODE_FOR_thumb1_subsi3_insn
)
24246 rtx src1
= XEXP (SET_SRC (set
), 1);
24247 if (src1
== const0_rtx
)
24248 cfun
->machine
->thumb1_cc_mode
= CCmode
;
24250 else if (REG_P (SET_DEST (set
)) && REG_P (SET_SRC (set
)))
24252 /* Record the src register operand instead of dest because
24253 cprop_hardreg pass propagates src. */
24254 cfun
->machine
->thumb1_cc_op0
= SET_SRC (set
);
24257 else if (conds
!= CONDS_NOCOND
)
24258 cfun
->machine
->thumb1_cc_insn
= NULL_RTX
;
24261 /* Check if unexpected far jump is used. */
24262 if (cfun
->machine
->lr_save_eliminated
24263 && get_attr_far_jump (insn
) == FAR_JUMP_YES
)
24264 internal_error("Unexpected thumb1 far jump");
24268 thumb_shiftable_const (unsigned HOST_WIDE_INT val
)
24270 unsigned HOST_WIDE_INT mask
= 0xff;
24273 val
= val
& (unsigned HOST_WIDE_INT
)0xffffffffu
;
24274 if (val
== 0) /* XXX */
24277 for (i
= 0; i
< 25; i
++)
24278 if ((val
& (mask
<< i
)) == val
)
24284 /* Returns nonzero if the current function contains,
24285 or might contain a far jump. */
24287 thumb_far_jump_used_p (void)
24290 bool far_jump
= false;
24291 unsigned int func_size
= 0;
24293 /* If we have already decided that far jumps may be used,
24294 do not bother checking again, and always return true even if
24295 it turns out that they are not being used. Once we have made
24296 the decision that far jumps are present (and that hence the link
24297 register will be pushed onto the stack) we cannot go back on it. */
24298 if (cfun
->machine
->far_jump_used
)
24301 /* If this function is not being called from the prologue/epilogue
24302 generation code then it must be being called from the
24303 INITIAL_ELIMINATION_OFFSET macro. */
24304 if (!(ARM_DOUBLEWORD_ALIGN
|| reload_completed
))
24306 /* In this case we know that we are being asked about the elimination
24307 of the arg pointer register. If that register is not being used,
24308 then there are no arguments on the stack, and we do not have to
24309 worry that a far jump might force the prologue to push the link
24310 register, changing the stack offsets. In this case we can just
24311 return false, since the presence of far jumps in the function will
24312 not affect stack offsets.
24314 If the arg pointer is live (or if it was live, but has now been
24315 eliminated and so set to dead) then we do have to test to see if
24316 the function might contain a far jump. This test can lead to some
24317 false negatives, since before reload is completed, then length of
24318 branch instructions is not known, so gcc defaults to returning their
24319 longest length, which in turn sets the far jump attribute to true.
24321 A false negative will not result in bad code being generated, but it
24322 will result in a needless push and pop of the link register. We
24323 hope that this does not occur too often.
24325 If we need doubleword stack alignment this could affect the other
24326 elimination offsets so we can't risk getting it wrong. */
24327 if (df_regs_ever_live_p (ARG_POINTER_REGNUM
))
24328 cfun
->machine
->arg_pointer_live
= 1;
24329 else if (!cfun
->machine
->arg_pointer_live
)
24333 /* We should not change far_jump_used during or after reload, as there is
24334 no chance to change stack frame layout. */
24335 if (reload_in_progress
|| reload_completed
)
24338 /* Check to see if the function contains a branch
24339 insn with the far jump attribute set. */
24340 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
24342 if (JUMP_P (insn
) && get_attr_far_jump (insn
) == FAR_JUMP_YES
)
24346 func_size
+= get_attr_length (insn
);
24349 /* Attribute far_jump will always be true for thumb1 before
24350 shorten_branch pass. So checking far_jump attribute before
24351 shorten_branch isn't much useful.
24353 Following heuristic tries to estimate more accurately if a far jump
24354 may finally be used. The heuristic is very conservative as there is
24355 no chance to roll-back the decision of not to use far jump.
24357 Thumb1 long branch offset is -2048 to 2046. The worst case is each
24358 2-byte insn is associated with a 4 byte constant pool. Using
24359 function size 2048/3 as the threshold is conservative enough. */
24362 if ((func_size
* 3) >= 2048)
24364 /* Record the fact that we have decided that
24365 the function does use far jumps. */
24366 cfun
->machine
->far_jump_used
= 1;
24374 /* Return nonzero if FUNC must be entered in ARM mode. */
24376 is_called_in_ARM_mode (tree func
)
24378 gcc_assert (TREE_CODE (func
) == FUNCTION_DECL
);
24380 /* Ignore the problem about functions whose address is taken. */
24381 if (TARGET_CALLEE_INTERWORKING
&& TREE_PUBLIC (func
))
24385 return lookup_attribute ("interfacearm", DECL_ATTRIBUTES (func
)) != NULL_TREE
;
24391 /* Given the stack offsets and register mask in OFFSETS, decide how
24392 many additional registers to push instead of subtracting a constant
24393 from SP. For epilogues the principle is the same except we use pop.
24394 FOR_PROLOGUE indicates which we're generating. */
24396 thumb1_extra_regs_pushed (arm_stack_offsets
*offsets
, bool for_prologue
)
24398 HOST_WIDE_INT amount
;
24399 unsigned long live_regs_mask
= offsets
->saved_regs_mask
;
24400 /* Extract a mask of the ones we can give to the Thumb's push/pop
24402 unsigned long l_mask
= live_regs_mask
& (for_prologue
? 0x40ff : 0xff);
24403 /* Then count how many other high registers will need to be pushed. */
24404 unsigned long high_regs_pushed
= bit_count (live_regs_mask
& 0x0f00);
24405 int n_free
, reg_base
, size
;
24407 if (!for_prologue
&& frame_pointer_needed
)
24408 amount
= offsets
->locals_base
- offsets
->saved_regs
;
24410 amount
= offsets
->outgoing_args
- offsets
->saved_regs
;
24412 /* If the stack frame size is 512 exactly, we can save one load
24413 instruction, which should make this a win even when optimizing
24415 if (!optimize_size
&& amount
!= 512)
24418 /* Can't do this if there are high registers to push. */
24419 if (high_regs_pushed
!= 0)
24422 /* Shouldn't do it in the prologue if no registers would normally
24423 be pushed at all. In the epilogue, also allow it if we'll have
24424 a pop insn for the PC. */
24427 || TARGET_BACKTRACE
24428 || (live_regs_mask
& 1 << LR_REGNUM
) == 0
24429 || TARGET_INTERWORK
24430 || crtl
->args
.pretend_args_size
!= 0))
24433 /* Don't do this if thumb_expand_prologue wants to emit instructions
24434 between the push and the stack frame allocation. */
24436 && ((flag_pic
&& arm_pic_register
!= INVALID_REGNUM
)
24437 || (!frame_pointer_needed
&& CALLER_INTERWORKING_SLOT_SIZE
> 0)))
24444 size
= arm_size_return_regs ();
24445 reg_base
= ARM_NUM_INTS (size
);
24446 live_regs_mask
>>= reg_base
;
24449 while (reg_base
+ n_free
< 8 && !(live_regs_mask
& 1)
24450 && (for_prologue
|| call_used_regs
[reg_base
+ n_free
]))
24452 live_regs_mask
>>= 1;
24458 gcc_assert (amount
/ 4 * 4 == amount
);
24460 if (amount
>= 512 && (amount
- n_free
* 4) < 512)
24461 return (amount
- 508) / 4;
24462 if (amount
<= n_free
* 4)
24467 /* The bits which aren't usefully expanded as rtl. */
24469 thumb1_unexpanded_epilogue (void)
24471 arm_stack_offsets
*offsets
;
24473 unsigned long live_regs_mask
= 0;
24474 int high_regs_pushed
= 0;
24476 int had_to_push_lr
;
24479 if (cfun
->machine
->return_used_this_function
!= 0)
24482 if (IS_NAKED (arm_current_func_type ()))
24485 offsets
= arm_get_frame_offsets ();
24486 live_regs_mask
= offsets
->saved_regs_mask
;
24487 high_regs_pushed
= bit_count (live_regs_mask
& 0x0f00);
24489 /* If we can deduce the registers used from the function's return value.
24490 This is more reliable that examining df_regs_ever_live_p () because that
24491 will be set if the register is ever used in the function, not just if
24492 the register is used to hold a return value. */
24493 size
= arm_size_return_regs ();
24495 extra_pop
= thumb1_extra_regs_pushed (offsets
, false);
24498 unsigned long extra_mask
= (1 << extra_pop
) - 1;
24499 live_regs_mask
|= extra_mask
<< ARM_NUM_INTS (size
);
24502 /* The prolog may have pushed some high registers to use as
24503 work registers. e.g. the testsuite file:
24504 gcc/testsuite/gcc/gcc.c-torture/execute/complex-2.c
24505 compiles to produce:
24506 push {r4, r5, r6, r7, lr}
24510 as part of the prolog. We have to undo that pushing here. */
24512 if (high_regs_pushed
)
24514 unsigned long mask
= live_regs_mask
& 0xff;
24517 /* The available low registers depend on the size of the value we are
24525 /* Oh dear! We have no low registers into which we can pop
24528 ("no low registers available for popping high registers");
24530 for (next_hi_reg
= 8; next_hi_reg
< 13; next_hi_reg
++)
24531 if (live_regs_mask
& (1 << next_hi_reg
))
24534 while (high_regs_pushed
)
24536 /* Find lo register(s) into which the high register(s) can
24538 for (regno
= 0; regno
<= LAST_LO_REGNUM
; regno
++)
24540 if (mask
& (1 << regno
))
24541 high_regs_pushed
--;
24542 if (high_regs_pushed
== 0)
24546 mask
&= (2 << regno
) - 1; /* A noop if regno == 8 */
24548 /* Pop the values into the low register(s). */
24549 thumb_pop (asm_out_file
, mask
);
24551 /* Move the value(s) into the high registers. */
24552 for (regno
= 0; regno
<= LAST_LO_REGNUM
; regno
++)
24554 if (mask
& (1 << regno
))
24556 asm_fprintf (asm_out_file
, "\tmov\t%r, %r\n", next_hi_reg
,
24559 for (next_hi_reg
++; next_hi_reg
< 13; next_hi_reg
++)
24560 if (live_regs_mask
& (1 << next_hi_reg
))
24565 live_regs_mask
&= ~0x0f00;
24568 had_to_push_lr
= (live_regs_mask
& (1 << LR_REGNUM
)) != 0;
24569 live_regs_mask
&= 0xff;
24571 if (crtl
->args
.pretend_args_size
== 0 || TARGET_BACKTRACE
)
24573 /* Pop the return address into the PC. */
24574 if (had_to_push_lr
)
24575 live_regs_mask
|= 1 << PC_REGNUM
;
24577 /* Either no argument registers were pushed or a backtrace
24578 structure was created which includes an adjusted stack
24579 pointer, so just pop everything. */
24580 if (live_regs_mask
)
24581 thumb_pop (asm_out_file
, live_regs_mask
);
24583 /* We have either just popped the return address into the
24584 PC or it is was kept in LR for the entire function.
24585 Note that thumb_pop has already called thumb_exit if the
24586 PC was in the list. */
24587 if (!had_to_push_lr
)
24588 thumb_exit (asm_out_file
, LR_REGNUM
);
24592 /* Pop everything but the return address. */
24593 if (live_regs_mask
)
24594 thumb_pop (asm_out_file
, live_regs_mask
);
24596 if (had_to_push_lr
)
24600 /* We have no free low regs, so save one. */
24601 asm_fprintf (asm_out_file
, "\tmov\t%r, %r\n", IP_REGNUM
,
24605 /* Get the return address into a temporary register. */
24606 thumb_pop (asm_out_file
, 1 << LAST_ARG_REGNUM
);
24610 /* Move the return address to lr. */
24611 asm_fprintf (asm_out_file
, "\tmov\t%r, %r\n", LR_REGNUM
,
24613 /* Restore the low register. */
24614 asm_fprintf (asm_out_file
, "\tmov\t%r, %r\n", LAST_ARG_REGNUM
,
24619 regno
= LAST_ARG_REGNUM
;
24624 /* Remove the argument registers that were pushed onto the stack. */
24625 asm_fprintf (asm_out_file
, "\tadd\t%r, %r, #%d\n",
24626 SP_REGNUM
, SP_REGNUM
,
24627 crtl
->args
.pretend_args_size
);
24629 thumb_exit (asm_out_file
, regno
);
24635 /* Functions to save and restore machine-specific function data. */
24636 static struct machine_function
*
24637 arm_init_machine_status (void)
24639 struct machine_function
*machine
;
24640 machine
= ggc_cleared_alloc
<machine_function
> ();
24642 #if ARM_FT_UNKNOWN != 0
24643 machine
->func_type
= ARM_FT_UNKNOWN
;
24648 /* Return an RTX indicating where the return address to the
24649 calling function can be found. */
24651 arm_return_addr (int count
, rtx frame ATTRIBUTE_UNUSED
)
24656 return get_hard_reg_initial_val (Pmode
, LR_REGNUM
);
24659 /* Do anything needed before RTL is emitted for each function. */
24661 arm_init_expanders (void)
24663 /* Arrange to initialize and mark the machine per-function status. */
24664 init_machine_status
= arm_init_machine_status
;
24666 /* This is to stop the combine pass optimizing away the alignment
24667 adjustment of va_arg. */
24668 /* ??? It is claimed that this should not be necessary. */
24670 mark_reg_pointer (arg_pointer_rtx
, PARM_BOUNDARY
);
24673 /* Check that FUNC is called with a different mode. */
24676 arm_change_mode_p (tree func
)
24678 if (TREE_CODE (func
) != FUNCTION_DECL
)
24681 tree callee_tree
= DECL_FUNCTION_SPECIFIC_TARGET (func
);
24684 callee_tree
= target_option_default_node
;
24686 struct cl_target_option
*callee_opts
= TREE_TARGET_OPTION (callee_tree
);
24687 int flags
= callee_opts
->x_target_flags
;
24689 return (TARGET_THUMB_P (flags
) != TARGET_THUMB
);
24692 /* Like arm_compute_initial_elimination offset. Simpler because there
24693 isn't an ABI specified frame pointer for Thumb. Instead, we set it
24694 to point at the base of the local variables after static stack
24695 space for a function has been allocated. */
24698 thumb_compute_initial_elimination_offset (unsigned int from
, unsigned int to
)
24700 arm_stack_offsets
*offsets
;
24702 offsets
= arm_get_frame_offsets ();
24706 case ARG_POINTER_REGNUM
:
24709 case STACK_POINTER_REGNUM
:
24710 return offsets
->outgoing_args
- offsets
->saved_args
;
24712 case FRAME_POINTER_REGNUM
:
24713 return offsets
->soft_frame
- offsets
->saved_args
;
24715 case ARM_HARD_FRAME_POINTER_REGNUM
:
24716 return offsets
->saved_regs
- offsets
->saved_args
;
24718 case THUMB_HARD_FRAME_POINTER_REGNUM
:
24719 return offsets
->locals_base
- offsets
->saved_args
;
24722 gcc_unreachable ();
24726 case FRAME_POINTER_REGNUM
:
24729 case STACK_POINTER_REGNUM
:
24730 return offsets
->outgoing_args
- offsets
->soft_frame
;
24732 case ARM_HARD_FRAME_POINTER_REGNUM
:
24733 return offsets
->saved_regs
- offsets
->soft_frame
;
24735 case THUMB_HARD_FRAME_POINTER_REGNUM
:
24736 return offsets
->locals_base
- offsets
->soft_frame
;
24739 gcc_unreachable ();
24744 gcc_unreachable ();
24748 /* Generate the function's prologue. */
24751 thumb1_expand_prologue (void)
24755 HOST_WIDE_INT amount
;
24756 HOST_WIDE_INT size
;
24757 arm_stack_offsets
*offsets
;
24758 unsigned long func_type
;
24760 unsigned long live_regs_mask
;
24761 unsigned long l_mask
;
24762 unsigned high_regs_pushed
= 0;
24763 bool lr_needs_saving
;
24765 func_type
= arm_current_func_type ();
24767 /* Naked functions don't have prologues. */
24768 if (IS_NAKED (func_type
))
24770 if (flag_stack_usage_info
)
24771 current_function_static_stack_size
= 0;
24775 if (IS_INTERRUPT (func_type
))
24777 error ("interrupt Service Routines cannot be coded in Thumb mode");
24781 if (is_called_in_ARM_mode (current_function_decl
))
24782 emit_insn (gen_prologue_thumb1_interwork ());
24784 offsets
= arm_get_frame_offsets ();
24785 live_regs_mask
= offsets
->saved_regs_mask
;
24786 lr_needs_saving
= live_regs_mask
& (1 << LR_REGNUM
);
24788 /* Extract a mask of the ones we can give to the Thumb's push instruction. */
24789 l_mask
= live_regs_mask
& 0x40ff;
24790 /* Then count how many other high registers will need to be pushed. */
24791 high_regs_pushed
= bit_count (live_regs_mask
& 0x0f00);
24793 if (crtl
->args
.pretend_args_size
)
24795 rtx x
= GEN_INT (-crtl
->args
.pretend_args_size
);
24797 if (cfun
->machine
->uses_anonymous_args
)
24799 int num_pushes
= ARM_NUM_INTS (crtl
->args
.pretend_args_size
);
24800 unsigned long mask
;
24802 mask
= 1ul << (LAST_ARG_REGNUM
+ 1);
24803 mask
-= 1ul << (LAST_ARG_REGNUM
+ 1 - num_pushes
);
24805 insn
= thumb1_emit_multi_reg_push (mask
, 0);
24809 insn
= emit_insn (gen_addsi3 (stack_pointer_rtx
,
24810 stack_pointer_rtx
, x
));
24812 RTX_FRAME_RELATED_P (insn
) = 1;
24815 if (TARGET_BACKTRACE
)
24817 HOST_WIDE_INT offset
= 0;
24818 unsigned work_register
;
24819 rtx work_reg
, x
, arm_hfp_rtx
;
24821 /* We have been asked to create a stack backtrace structure.
24822 The code looks like this:
24826 0 sub SP, #16 Reserve space for 4 registers.
24827 2 push {R7} Push low registers.
24828 4 add R7, SP, #20 Get the stack pointer before the push.
24829 6 str R7, [SP, #8] Store the stack pointer
24830 (before reserving the space).
24831 8 mov R7, PC Get hold of the start of this code + 12.
24832 10 str R7, [SP, #16] Store it.
24833 12 mov R7, FP Get hold of the current frame pointer.
24834 14 str R7, [SP, #4] Store it.
24835 16 mov R7, LR Get hold of the current return address.
24836 18 str R7, [SP, #12] Store it.
24837 20 add R7, SP, #16 Point at the start of the
24838 backtrace structure.
24839 22 mov FP, R7 Put this value into the frame pointer. */
24841 work_register
= thumb_find_work_register (live_regs_mask
);
24842 work_reg
= gen_rtx_REG (SImode
, work_register
);
24843 arm_hfp_rtx
= gen_rtx_REG (SImode
, ARM_HARD_FRAME_POINTER_REGNUM
);
24845 insn
= emit_insn (gen_addsi3 (stack_pointer_rtx
,
24846 stack_pointer_rtx
, GEN_INT (-16)));
24847 RTX_FRAME_RELATED_P (insn
) = 1;
24851 insn
= thumb1_emit_multi_reg_push (l_mask
, l_mask
);
24852 RTX_FRAME_RELATED_P (insn
) = 1;
24853 lr_needs_saving
= false;
24855 offset
= bit_count (l_mask
) * UNITS_PER_WORD
;
24858 x
= GEN_INT (offset
+ 16 + crtl
->args
.pretend_args_size
);
24859 emit_insn (gen_addsi3 (work_reg
, stack_pointer_rtx
, x
));
24861 x
= plus_constant (Pmode
, stack_pointer_rtx
, offset
+ 4);
24862 x
= gen_frame_mem (SImode
, x
);
24863 emit_move_insn (x
, work_reg
);
24865 /* Make sure that the instruction fetching the PC is in the right place
24866 to calculate "start of backtrace creation code + 12". */
24867 /* ??? The stores using the common WORK_REG ought to be enough to
24868 prevent the scheduler from doing anything weird. Failing that
24869 we could always move all of the following into an UNSPEC_VOLATILE. */
24872 x
= gen_rtx_REG (SImode
, PC_REGNUM
);
24873 emit_move_insn (work_reg
, x
);
24875 x
= plus_constant (Pmode
, stack_pointer_rtx
, offset
+ 12);
24876 x
= gen_frame_mem (SImode
, x
);
24877 emit_move_insn (x
, work_reg
);
24879 emit_move_insn (work_reg
, arm_hfp_rtx
);
24881 x
= plus_constant (Pmode
, stack_pointer_rtx
, offset
);
24882 x
= gen_frame_mem (SImode
, x
);
24883 emit_move_insn (x
, work_reg
);
24887 emit_move_insn (work_reg
, arm_hfp_rtx
);
24889 x
= plus_constant (Pmode
, stack_pointer_rtx
, offset
);
24890 x
= gen_frame_mem (SImode
, x
);
24891 emit_move_insn (x
, work_reg
);
24893 x
= gen_rtx_REG (SImode
, PC_REGNUM
);
24894 emit_move_insn (work_reg
, x
);
24896 x
= plus_constant (Pmode
, stack_pointer_rtx
, offset
+ 12);
24897 x
= gen_frame_mem (SImode
, x
);
24898 emit_move_insn (x
, work_reg
);
24901 x
= gen_rtx_REG (SImode
, LR_REGNUM
);
24902 emit_move_insn (work_reg
, x
);
24904 x
= plus_constant (Pmode
, stack_pointer_rtx
, offset
+ 8);
24905 x
= gen_frame_mem (SImode
, x
);
24906 emit_move_insn (x
, work_reg
);
24908 x
= GEN_INT (offset
+ 12);
24909 emit_insn (gen_addsi3 (work_reg
, stack_pointer_rtx
, x
));
24911 emit_move_insn (arm_hfp_rtx
, work_reg
);
24913 /* Optimization: If we are not pushing any low registers but we are going
24914 to push some high registers then delay our first push. This will just
24915 be a push of LR and we can combine it with the push of the first high
24917 else if ((l_mask
& 0xff) != 0
24918 || (high_regs_pushed
== 0 && lr_needs_saving
))
24920 unsigned long mask
= l_mask
;
24921 mask
|= (1 << thumb1_extra_regs_pushed (offsets
, true)) - 1;
24922 insn
= thumb1_emit_multi_reg_push (mask
, mask
);
24923 RTX_FRAME_RELATED_P (insn
) = 1;
24924 lr_needs_saving
= false;
24927 if (high_regs_pushed
)
24929 unsigned pushable_regs
;
24930 unsigned next_hi_reg
;
24931 unsigned arg_regs_num
= TARGET_AAPCS_BASED
? crtl
->args
.info
.aapcs_ncrn
24932 : crtl
->args
.info
.nregs
;
24933 unsigned arg_regs_mask
= (1 << arg_regs_num
) - 1;
24935 for (next_hi_reg
= 12; next_hi_reg
> LAST_LO_REGNUM
; next_hi_reg
--)
24936 if (live_regs_mask
& (1 << next_hi_reg
))
24939 /* Here we need to mask out registers used for passing arguments
24940 even if they can be pushed. This is to avoid using them to stash the high
24941 registers. Such kind of stash may clobber the use of arguments. */
24942 pushable_regs
= l_mask
& (~arg_regs_mask
);
24943 if (lr_needs_saving
)
24944 pushable_regs
&= ~(1 << LR_REGNUM
);
24946 if (pushable_regs
== 0)
24947 pushable_regs
= 1 << thumb_find_work_register (live_regs_mask
);
24949 while (high_regs_pushed
> 0)
24951 unsigned long real_regs_mask
= 0;
24952 unsigned long push_mask
= 0;
24954 for (regno
= LR_REGNUM
; regno
>= 0; regno
--)
24956 if (pushable_regs
& (1 << regno
))
24958 emit_move_insn (gen_rtx_REG (SImode
, regno
),
24959 gen_rtx_REG (SImode
, next_hi_reg
));
24961 high_regs_pushed
--;
24962 real_regs_mask
|= (1 << next_hi_reg
);
24963 push_mask
|= (1 << regno
);
24965 if (high_regs_pushed
)
24967 for (next_hi_reg
--; next_hi_reg
> LAST_LO_REGNUM
;
24969 if (live_regs_mask
& (1 << next_hi_reg
))
24977 /* If we had to find a work register and we have not yet
24978 saved the LR then add it to the list of regs to push. */
24979 if (lr_needs_saving
)
24981 push_mask
|= 1 << LR_REGNUM
;
24982 real_regs_mask
|= 1 << LR_REGNUM
;
24983 lr_needs_saving
= false;
24986 insn
= thumb1_emit_multi_reg_push (push_mask
, real_regs_mask
);
24987 RTX_FRAME_RELATED_P (insn
) = 1;
24991 /* Load the pic register before setting the frame pointer,
24992 so we can use r7 as a temporary work register. */
24993 if (flag_pic
&& arm_pic_register
!= INVALID_REGNUM
)
24994 arm_load_pic_register (live_regs_mask
);
24996 if (!frame_pointer_needed
&& CALLER_INTERWORKING_SLOT_SIZE
> 0)
24997 emit_move_insn (gen_rtx_REG (Pmode
, ARM_HARD_FRAME_POINTER_REGNUM
),
24998 stack_pointer_rtx
);
25000 size
= offsets
->outgoing_args
- offsets
->saved_args
;
25001 if (flag_stack_usage_info
)
25002 current_function_static_stack_size
= size
;
25004 /* If we have a frame, then do stack checking. FIXME: not implemented. */
25005 if ((flag_stack_check
== STATIC_BUILTIN_STACK_CHECK
25006 || flag_stack_clash_protection
)
25008 sorry ("-fstack-check=specific for Thumb-1");
25010 amount
= offsets
->outgoing_args
- offsets
->saved_regs
;
25011 amount
-= 4 * thumb1_extra_regs_pushed (offsets
, true);
25016 insn
= emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
25017 GEN_INT (- amount
)));
25018 RTX_FRAME_RELATED_P (insn
) = 1;
25024 /* The stack decrement is too big for an immediate value in a single
25025 insn. In theory we could issue multiple subtracts, but after
25026 three of them it becomes more space efficient to place the full
25027 value in the constant pool and load into a register. (Also the
25028 ARM debugger really likes to see only one stack decrement per
25029 function). So instead we look for a scratch register into which
25030 we can load the decrement, and then we subtract this from the
25031 stack pointer. Unfortunately on the thumb the only available
25032 scratch registers are the argument registers, and we cannot use
25033 these as they may hold arguments to the function. Instead we
25034 attempt to locate a call preserved register which is used by this
25035 function. If we can find one, then we know that it will have
25036 been pushed at the start of the prologue and so we can corrupt
25038 for (regno
= LAST_ARG_REGNUM
+ 1; regno
<= LAST_LO_REGNUM
; regno
++)
25039 if (live_regs_mask
& (1 << regno
))
25042 gcc_assert(regno
<= LAST_LO_REGNUM
);
25044 reg
= gen_rtx_REG (SImode
, regno
);
25046 emit_insn (gen_movsi (reg
, GEN_INT (- amount
)));
25048 insn
= emit_insn (gen_addsi3 (stack_pointer_rtx
,
25049 stack_pointer_rtx
, reg
));
25051 dwarf
= gen_rtx_SET (stack_pointer_rtx
,
25052 plus_constant (Pmode
, stack_pointer_rtx
,
25054 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, dwarf
);
25055 RTX_FRAME_RELATED_P (insn
) = 1;
25059 if (frame_pointer_needed
)
25060 thumb_set_frame_pointer (offsets
);
25062 /* If we are profiling, make sure no instructions are scheduled before
25063 the call to mcount. Similarly if the user has requested no
25064 scheduling in the prolog. Similarly if we want non-call exceptions
25065 using the EABI unwinder, to prevent faulting instructions from being
25066 swapped with a stack adjustment. */
25067 if (crtl
->profile
|| !TARGET_SCHED_PROLOG
25068 || (arm_except_unwind_info (&global_options
) == UI_TARGET
25069 && cfun
->can_throw_non_call_exceptions
))
25070 emit_insn (gen_blockage ());
25072 cfun
->machine
->lr_save_eliminated
= !thumb_force_lr_save ();
25073 if (live_regs_mask
& 0xff)
25074 cfun
->machine
->lr_save_eliminated
= 0;
25077 /* Clear caller saved registers not used to pass return values and leaked
25078 condition flags before exiting a cmse_nonsecure_entry function. */
25081 cmse_nonsecure_entry_clear_before_return (void)
25083 int regno
, maxregno
= TARGET_HARD_FLOAT
? LAST_VFP_REGNUM
: IP_REGNUM
;
25084 uint32_t padding_bits_to_clear
= 0;
25085 uint32_t * padding_bits_to_clear_ptr
= &padding_bits_to_clear
;
25086 auto_sbitmap
to_clear_bitmap (maxregno
+ 1);
25090 bitmap_clear (to_clear_bitmap
);
25091 bitmap_set_range (to_clear_bitmap
, R0_REGNUM
, NUM_ARG_REGS
);
25092 bitmap_set_bit (to_clear_bitmap
, IP_REGNUM
);
25094 /* If we are not dealing with -mfloat-abi=soft we will need to clear VFP
25096 if (TARGET_HARD_FLOAT
)
25098 int float_bits
= D7_VFP_REGNUM
- FIRST_VFP_REGNUM
+ 1;
25100 bitmap_set_range (to_clear_bitmap
, FIRST_VFP_REGNUM
, float_bits
);
25102 /* Make sure we don't clear the two scratch registers used to clear the
25103 relevant FPSCR bits in output_return_instruction. */
25104 emit_use (gen_rtx_REG (SImode
, IP_REGNUM
));
25105 bitmap_clear_bit (to_clear_bitmap
, IP_REGNUM
);
25106 emit_use (gen_rtx_REG (SImode
, 4));
25107 bitmap_clear_bit (to_clear_bitmap
, 4);
25110 /* If the user has defined registers to be caller saved, these are no longer
25111 restored by the function before returning and must thus be cleared for
25112 security purposes. */
25113 for (regno
= NUM_ARG_REGS
; regno
<= maxregno
; regno
++)
25115 /* We do not touch registers that can be used to pass arguments as per
25116 the AAPCS, since these should never be made callee-saved by user
25118 if (IN_RANGE (regno
, FIRST_VFP_REGNUM
, D7_VFP_REGNUM
))
25120 if (IN_RANGE (regno
, IP_REGNUM
, PC_REGNUM
))
25122 if (call_used_regs
[regno
])
25123 bitmap_set_bit (to_clear_bitmap
, regno
);
25126 /* Make sure we do not clear the registers used to return the result in. */
25127 result_type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
25128 if (!VOID_TYPE_P (result_type
))
25130 uint64_t to_clear_return_mask
;
25131 result_rtl
= arm_function_value (result_type
, current_function_decl
, 0);
25133 /* No need to check that we return in registers, because we don't
25134 support returning on stack yet. */
25135 gcc_assert (REG_P (result_rtl
));
25136 to_clear_return_mask
25137 = compute_not_to_clear_mask (result_type
, result_rtl
, 0,
25138 padding_bits_to_clear_ptr
);
25139 if (to_clear_return_mask
)
25141 gcc_assert ((unsigned) maxregno
< sizeof (long long) * __CHAR_BIT__
);
25142 for (regno
= R0_REGNUM
; regno
<= maxregno
; regno
++)
25144 if (to_clear_return_mask
& (1ULL << regno
))
25145 bitmap_clear_bit (to_clear_bitmap
, regno
);
25150 if (padding_bits_to_clear
!= 0)
25153 auto_sbitmap
to_clear_arg_regs_bitmap (R0_REGNUM
+ NUM_ARG_REGS
);
25155 /* Padding bits to clear is not 0 so we know we are dealing with
25156 returning a composite type, which only uses r0. Let's make sure that
25157 r1-r3 is cleared too, we will use r1 as a scratch register. */
25158 bitmap_clear (to_clear_arg_regs_bitmap
);
25159 bitmap_set_range (to_clear_arg_regs_bitmap
, R0_REGNUM
+ 1,
25161 gcc_assert (bitmap_subset_p (to_clear_arg_regs_bitmap
, to_clear_bitmap
));
25163 reg_rtx
= gen_rtx_REG (SImode
, R1_REGNUM
);
25165 /* Fill the lower half of the negated padding_bits_to_clear. */
25166 emit_move_insn (reg_rtx
,
25167 GEN_INT ((((~padding_bits_to_clear
) << 16u) >> 16u)));
25169 /* Also fill the top half of the negated padding_bits_to_clear. */
25170 if (((~padding_bits_to_clear
) >> 16) > 0)
25171 emit_insn (gen_rtx_SET (gen_rtx_ZERO_EXTRACT (SImode
, reg_rtx
,
25174 GEN_INT ((~padding_bits_to_clear
) >> 16)));
25176 emit_insn (gen_andsi3 (gen_rtx_REG (SImode
, R0_REGNUM
),
25177 gen_rtx_REG (SImode
, R0_REGNUM
),
25181 for (regno
= R0_REGNUM
; regno
<= maxregno
; regno
++)
25183 if (!bitmap_bit_p (to_clear_bitmap
, regno
))
25186 if (IS_VFP_REGNUM (regno
))
25188 /* If regno is an even vfp register and its successor is also to
25189 be cleared, use vmov. */
25190 if (TARGET_VFP_DOUBLE
25191 && VFP_REGNO_OK_FOR_DOUBLE (regno
)
25192 && bitmap_bit_p (to_clear_bitmap
, regno
+ 1))
25194 emit_move_insn (gen_rtx_REG (DFmode
, regno
),
25195 CONST1_RTX (DFmode
));
25196 emit_use (gen_rtx_REG (DFmode
, regno
));
25201 emit_move_insn (gen_rtx_REG (SFmode
, regno
),
25202 CONST1_RTX (SFmode
));
25203 emit_use (gen_rtx_REG (SFmode
, regno
));
25210 if (regno
== R0_REGNUM
)
25211 emit_move_insn (gen_rtx_REG (SImode
, regno
),
25214 /* R0 has either been cleared before, see code above, or it
25215 holds a return value, either way it is not secret
25217 emit_move_insn (gen_rtx_REG (SImode
, regno
),
25218 gen_rtx_REG (SImode
, R0_REGNUM
));
25219 emit_use (gen_rtx_REG (SImode
, regno
));
25223 emit_move_insn (gen_rtx_REG (SImode
, regno
),
25224 gen_rtx_REG (SImode
, LR_REGNUM
));
25225 emit_use (gen_rtx_REG (SImode
, regno
));
25231 /* Generate pattern *pop_multiple_with_stack_update_and_return if single
25232 POP instruction can be generated. LR should be replaced by PC. All
25233 the checks required are already done by USE_RETURN_INSN (). Hence,
25234 all we really need to check here is if single register is to be
25235 returned, or multiple register return. */
25237 thumb2_expand_return (bool simple_return
)
25240 unsigned long saved_regs_mask
;
25241 arm_stack_offsets
*offsets
;
25243 offsets
= arm_get_frame_offsets ();
25244 saved_regs_mask
= offsets
->saved_regs_mask
;
25246 for (i
= 0, num_regs
= 0; i
<= LAST_ARM_REGNUM
; i
++)
25247 if (saved_regs_mask
& (1 << i
))
25250 if (!simple_return
&& saved_regs_mask
)
25252 /* TODO: Verify that this path is never taken for cmse_nonsecure_entry
25253 functions or adapt code to handle according to ACLE. This path should
25254 not be reachable for cmse_nonsecure_entry functions though we prefer
25255 to assert it for now to ensure that future code changes do not silently
25256 change this behavior. */
25257 gcc_assert (!IS_CMSE_ENTRY (arm_current_func_type ()));
25260 rtx par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (2));
25261 rtx reg
= gen_rtx_REG (SImode
, PC_REGNUM
);
25262 rtx addr
= gen_rtx_MEM (SImode
,
25263 gen_rtx_POST_INC (SImode
,
25264 stack_pointer_rtx
));
25265 set_mem_alias_set (addr
, get_frame_alias_set ());
25266 XVECEXP (par
, 0, 0) = ret_rtx
;
25267 XVECEXP (par
, 0, 1) = gen_rtx_SET (reg
, addr
);
25268 RTX_FRAME_RELATED_P (XVECEXP (par
, 0, 1)) = 1;
25269 emit_jump_insn (par
);
25273 saved_regs_mask
&= ~ (1 << LR_REGNUM
);
25274 saved_regs_mask
|= (1 << PC_REGNUM
);
25275 arm_emit_multi_reg_pop (saved_regs_mask
);
25280 if (IS_CMSE_ENTRY (arm_current_func_type ()))
25281 cmse_nonsecure_entry_clear_before_return ();
25282 emit_jump_insn (simple_return_rtx
);
25287 thumb1_expand_epilogue (void)
25289 HOST_WIDE_INT amount
;
25290 arm_stack_offsets
*offsets
;
25293 /* Naked functions don't have prologues. */
25294 if (IS_NAKED (arm_current_func_type ()))
25297 offsets
= arm_get_frame_offsets ();
25298 amount
= offsets
->outgoing_args
- offsets
->saved_regs
;
25300 if (frame_pointer_needed
)
25302 emit_insn (gen_movsi (stack_pointer_rtx
, hard_frame_pointer_rtx
));
25303 amount
= offsets
->locals_base
- offsets
->saved_regs
;
25305 amount
-= 4 * thumb1_extra_regs_pushed (offsets
, false);
25307 gcc_assert (amount
>= 0);
25310 emit_insn (gen_blockage ());
25313 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
25314 GEN_INT (amount
)));
25317 /* r3 is always free in the epilogue. */
25318 rtx reg
= gen_rtx_REG (SImode
, LAST_ARG_REGNUM
);
25320 emit_insn (gen_movsi (reg
, GEN_INT (amount
)));
25321 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, reg
));
25325 /* Emit a USE (stack_pointer_rtx), so that
25326 the stack adjustment will not be deleted. */
25327 emit_insn (gen_force_register_use (stack_pointer_rtx
));
25329 if (crtl
->profile
|| !TARGET_SCHED_PROLOG
)
25330 emit_insn (gen_blockage ());
25332 /* Emit a clobber for each insn that will be restored in the epilogue,
25333 so that flow2 will get register lifetimes correct. */
25334 for (regno
= 0; regno
< 13; regno
++)
25335 if (df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
25336 emit_clobber (gen_rtx_REG (SImode
, regno
));
25338 if (! df_regs_ever_live_p (LR_REGNUM
))
25339 emit_use (gen_rtx_REG (SImode
, LR_REGNUM
));
25341 /* Clear all caller-saved regs that are not used to return. */
25342 if (IS_CMSE_ENTRY (arm_current_func_type ()))
25343 cmse_nonsecure_entry_clear_before_return ();
25346 /* Epilogue code for APCS frame. */
25348 arm_expand_epilogue_apcs_frame (bool really_return
)
25350 unsigned long func_type
;
25351 unsigned long saved_regs_mask
;
25354 int floats_from_frame
= 0;
25355 arm_stack_offsets
*offsets
;
25357 gcc_assert (TARGET_APCS_FRAME
&& frame_pointer_needed
&& TARGET_ARM
);
25358 func_type
= arm_current_func_type ();
25360 /* Get frame offsets for ARM. */
25361 offsets
= arm_get_frame_offsets ();
25362 saved_regs_mask
= offsets
->saved_regs_mask
;
25364 /* Find the offset of the floating-point save area in the frame. */
25366 = (offsets
->saved_args
25367 + arm_compute_static_chain_stack_bytes ()
25370 /* Compute how many core registers saved and how far away the floats are. */
25371 for (i
= 0; i
<= LAST_ARM_REGNUM
; i
++)
25372 if (saved_regs_mask
& (1 << i
))
25375 floats_from_frame
+= 4;
25378 if (TARGET_HARD_FLOAT
)
25381 rtx ip_rtx
= gen_rtx_REG (SImode
, IP_REGNUM
);
25383 /* The offset is from IP_REGNUM. */
25384 int saved_size
= arm_get_vfp_saved_size ();
25385 if (saved_size
> 0)
25388 floats_from_frame
+= saved_size
;
25389 insn
= emit_insn (gen_addsi3 (ip_rtx
,
25390 hard_frame_pointer_rtx
,
25391 GEN_INT (-floats_from_frame
)));
25392 arm_add_cfa_adjust_cfa_note (insn
, -floats_from_frame
,
25393 ip_rtx
, hard_frame_pointer_rtx
);
25396 /* Generate VFP register multi-pop. */
25397 start_reg
= FIRST_VFP_REGNUM
;
25399 for (i
= FIRST_VFP_REGNUM
; i
< LAST_VFP_REGNUM
; i
+= 2)
25400 /* Look for a case where a reg does not need restoring. */
25401 if ((!df_regs_ever_live_p (i
) || call_used_regs
[i
])
25402 && (!df_regs_ever_live_p (i
+ 1)
25403 || call_used_regs
[i
+ 1]))
25405 if (start_reg
!= i
)
25406 arm_emit_vfp_multi_reg_pop (start_reg
,
25407 (i
- start_reg
) / 2,
25408 gen_rtx_REG (SImode
,
25413 /* Restore the remaining regs that we have discovered (or possibly
25414 even all of them, if the conditional in the for loop never
25416 if (start_reg
!= i
)
25417 arm_emit_vfp_multi_reg_pop (start_reg
,
25418 (i
- start_reg
) / 2,
25419 gen_rtx_REG (SImode
, IP_REGNUM
));
25424 /* The frame pointer is guaranteed to be non-double-word aligned, as
25425 it is set to double-word-aligned old_stack_pointer - 4. */
25427 int lrm_count
= (num_regs
% 2) ? (num_regs
+ 2) : (num_regs
+ 1);
25429 for (i
= LAST_IWMMXT_REGNUM
; i
>= FIRST_IWMMXT_REGNUM
; i
--)
25430 if (df_regs_ever_live_p (i
) && !call_used_regs
[i
])
25432 rtx addr
= gen_frame_mem (V2SImode
,
25433 plus_constant (Pmode
, hard_frame_pointer_rtx
,
25435 insn
= emit_insn (gen_movsi (gen_rtx_REG (V2SImode
, i
), addr
));
25436 REG_NOTES (insn
) = alloc_reg_note (REG_CFA_RESTORE
,
25437 gen_rtx_REG (V2SImode
, i
),
25443 /* saved_regs_mask should contain IP which contains old stack pointer
25444 at the time of activation creation. Since SP and IP are adjacent registers,
25445 we can restore the value directly into SP. */
25446 gcc_assert (saved_regs_mask
& (1 << IP_REGNUM
));
25447 saved_regs_mask
&= ~(1 << IP_REGNUM
);
25448 saved_regs_mask
|= (1 << SP_REGNUM
);
25450 /* There are two registers left in saved_regs_mask - LR and PC. We
25451 only need to restore LR (the return address), but to
25452 save time we can load it directly into PC, unless we need a
25453 special function exit sequence, or we are not really returning. */
25455 && ARM_FUNC_TYPE (func_type
) == ARM_FT_NORMAL
25456 && !crtl
->calls_eh_return
)
25457 /* Delete LR from the register mask, so that LR on
25458 the stack is loaded into the PC in the register mask. */
25459 saved_regs_mask
&= ~(1 << LR_REGNUM
);
25461 saved_regs_mask
&= ~(1 << PC_REGNUM
);
25463 num_regs
= bit_count (saved_regs_mask
);
25464 if ((offsets
->outgoing_args
!= (1 + num_regs
)) || cfun
->calls_alloca
)
25467 emit_insn (gen_blockage ());
25468 /* Unwind the stack to just below the saved registers. */
25469 insn
= emit_insn (gen_addsi3 (stack_pointer_rtx
,
25470 hard_frame_pointer_rtx
,
25471 GEN_INT (- 4 * num_regs
)));
25473 arm_add_cfa_adjust_cfa_note (insn
, - 4 * num_regs
,
25474 stack_pointer_rtx
, hard_frame_pointer_rtx
);
25477 arm_emit_multi_reg_pop (saved_regs_mask
);
25479 if (IS_INTERRUPT (func_type
))
25481 /* Interrupt handlers will have pushed the
25482 IP onto the stack, so restore it now. */
25484 rtx addr
= gen_rtx_MEM (SImode
,
25485 gen_rtx_POST_INC (SImode
,
25486 stack_pointer_rtx
));
25487 set_mem_alias_set (addr
, get_frame_alias_set ());
25488 insn
= emit_insn (gen_movsi (gen_rtx_REG (SImode
, IP_REGNUM
), addr
));
25489 REG_NOTES (insn
) = alloc_reg_note (REG_CFA_RESTORE
,
25490 gen_rtx_REG (SImode
, IP_REGNUM
),
25494 if (!really_return
|| (saved_regs_mask
& (1 << PC_REGNUM
)))
25497 if (crtl
->calls_eh_return
)
25498 emit_insn (gen_addsi3 (stack_pointer_rtx
,
25500 gen_rtx_REG (SImode
, ARM_EH_STACKADJ_REGNUM
)));
25502 if (IS_STACKALIGN (func_type
))
25503 /* Restore the original stack pointer. Before prologue, the stack was
25504 realigned and the original stack pointer saved in r0. For details,
25505 see comment in arm_expand_prologue. */
25506 emit_insn (gen_movsi (stack_pointer_rtx
, gen_rtx_REG (SImode
, R0_REGNUM
)));
25508 emit_jump_insn (simple_return_rtx
);
25511 /* Generate RTL to represent ARM epilogue. Really_return is true if the
25512 function is not a sibcall. */
25514 arm_expand_epilogue (bool really_return
)
25516 unsigned long func_type
;
25517 unsigned long saved_regs_mask
;
25521 arm_stack_offsets
*offsets
;
25523 func_type
= arm_current_func_type ();
25525 /* Naked functions don't have epilogue. Hence, generate return pattern, and
25526 let output_return_instruction take care of instruction emission if any. */
25527 if (IS_NAKED (func_type
)
25528 || (IS_VOLATILE (func_type
) && TARGET_ABORT_NORETURN
))
25531 emit_jump_insn (simple_return_rtx
);
25535 /* If we are throwing an exception, then we really must be doing a
25536 return, so we can't tail-call. */
25537 gcc_assert (!crtl
->calls_eh_return
|| really_return
);
25539 if (TARGET_APCS_FRAME
&& frame_pointer_needed
&& TARGET_ARM
)
25541 arm_expand_epilogue_apcs_frame (really_return
);
25545 /* Get frame offsets for ARM. */
25546 offsets
= arm_get_frame_offsets ();
25547 saved_regs_mask
= offsets
->saved_regs_mask
;
25548 num_regs
= bit_count (saved_regs_mask
);
25550 if (frame_pointer_needed
)
25553 /* Restore stack pointer if necessary. */
25556 /* In ARM mode, frame pointer points to first saved register.
25557 Restore stack pointer to last saved register. */
25558 amount
= offsets
->frame
- offsets
->saved_regs
;
25560 /* Force out any pending memory operations that reference stacked data
25561 before stack de-allocation occurs. */
25562 emit_insn (gen_blockage ());
25563 insn
= emit_insn (gen_addsi3 (stack_pointer_rtx
,
25564 hard_frame_pointer_rtx
,
25565 GEN_INT (amount
)));
25566 arm_add_cfa_adjust_cfa_note (insn
, amount
,
25568 hard_frame_pointer_rtx
);
25570 /* Emit USE(stack_pointer_rtx) to ensure that stack adjustment is not
25572 emit_insn (gen_force_register_use (stack_pointer_rtx
));
25576 /* In Thumb-2 mode, the frame pointer points to the last saved
25578 amount
= offsets
->locals_base
- offsets
->saved_regs
;
25581 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
25582 hard_frame_pointer_rtx
,
25583 GEN_INT (amount
)));
25584 arm_add_cfa_adjust_cfa_note (insn
, amount
,
25585 hard_frame_pointer_rtx
,
25586 hard_frame_pointer_rtx
);
25589 /* Force out any pending memory operations that reference stacked data
25590 before stack de-allocation occurs. */
25591 emit_insn (gen_blockage ());
25592 insn
= emit_insn (gen_movsi (stack_pointer_rtx
,
25593 hard_frame_pointer_rtx
));
25594 arm_add_cfa_adjust_cfa_note (insn
, 0,
25596 hard_frame_pointer_rtx
);
25597 /* Emit USE(stack_pointer_rtx) to ensure that stack adjustment is not
25599 emit_insn (gen_force_register_use (stack_pointer_rtx
));
25604 /* Pop off outgoing args and local frame to adjust stack pointer to
25605 last saved register. */
25606 amount
= offsets
->outgoing_args
- offsets
->saved_regs
;
25610 /* Force out any pending memory operations that reference stacked data
25611 before stack de-allocation occurs. */
25612 emit_insn (gen_blockage ());
25613 tmp
= emit_insn (gen_addsi3 (stack_pointer_rtx
,
25615 GEN_INT (amount
)));
25616 arm_add_cfa_adjust_cfa_note (tmp
, amount
,
25617 stack_pointer_rtx
, stack_pointer_rtx
);
25618 /* Emit USE(stack_pointer_rtx) to ensure that stack adjustment is
25620 emit_insn (gen_force_register_use (stack_pointer_rtx
));
25624 if (TARGET_HARD_FLOAT
)
25626 /* Generate VFP register multi-pop. */
25627 int end_reg
= LAST_VFP_REGNUM
+ 1;
25629 /* Scan the registers in reverse order. We need to match
25630 any groupings made in the prologue and generate matching
25631 vldm operations. The need to match groups is because,
25632 unlike pop, vldm can only do consecutive regs. */
25633 for (i
= LAST_VFP_REGNUM
- 1; i
>= FIRST_VFP_REGNUM
; i
-= 2)
25634 /* Look for a case where a reg does not need restoring. */
25635 if ((!df_regs_ever_live_p (i
) || call_used_regs
[i
])
25636 && (!df_regs_ever_live_p (i
+ 1)
25637 || call_used_regs
[i
+ 1]))
25639 /* Restore the regs discovered so far (from reg+2 to
25641 if (end_reg
> i
+ 2)
25642 arm_emit_vfp_multi_reg_pop (i
+ 2,
25643 (end_reg
- (i
+ 2)) / 2,
25644 stack_pointer_rtx
);
25648 /* Restore the remaining regs that we have discovered (or possibly
25649 even all of them, if the conditional in the for loop never
25651 if (end_reg
> i
+ 2)
25652 arm_emit_vfp_multi_reg_pop (i
+ 2,
25653 (end_reg
- (i
+ 2)) / 2,
25654 stack_pointer_rtx
);
25658 for (i
= FIRST_IWMMXT_REGNUM
; i
<= LAST_IWMMXT_REGNUM
; i
++)
25659 if (df_regs_ever_live_p (i
) && !call_used_regs
[i
])
25662 rtx addr
= gen_rtx_MEM (V2SImode
,
25663 gen_rtx_POST_INC (SImode
,
25664 stack_pointer_rtx
));
25665 set_mem_alias_set (addr
, get_frame_alias_set ());
25666 insn
= emit_insn (gen_movsi (gen_rtx_REG (V2SImode
, i
), addr
));
25667 REG_NOTES (insn
) = alloc_reg_note (REG_CFA_RESTORE
,
25668 gen_rtx_REG (V2SImode
, i
),
25670 arm_add_cfa_adjust_cfa_note (insn
, UNITS_PER_WORD
,
25671 stack_pointer_rtx
, stack_pointer_rtx
);
25674 if (saved_regs_mask
)
25677 bool return_in_pc
= false;
25679 if (ARM_FUNC_TYPE (func_type
) != ARM_FT_INTERWORKED
25680 && (TARGET_ARM
|| ARM_FUNC_TYPE (func_type
) == ARM_FT_NORMAL
)
25681 && !IS_CMSE_ENTRY (func_type
)
25682 && !IS_STACKALIGN (func_type
)
25684 && crtl
->args
.pretend_args_size
== 0
25685 && saved_regs_mask
& (1 << LR_REGNUM
)
25686 && !crtl
->calls_eh_return
)
25688 saved_regs_mask
&= ~(1 << LR_REGNUM
);
25689 saved_regs_mask
|= (1 << PC_REGNUM
);
25690 return_in_pc
= true;
25693 if (num_regs
== 1 && (!IS_INTERRUPT (func_type
) || !return_in_pc
))
25695 for (i
= 0; i
<= LAST_ARM_REGNUM
; i
++)
25696 if (saved_regs_mask
& (1 << i
))
25698 rtx addr
= gen_rtx_MEM (SImode
,
25699 gen_rtx_POST_INC (SImode
,
25700 stack_pointer_rtx
));
25701 set_mem_alias_set (addr
, get_frame_alias_set ());
25703 if (i
== PC_REGNUM
)
25705 insn
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (2));
25706 XVECEXP (insn
, 0, 0) = ret_rtx
;
25707 XVECEXP (insn
, 0, 1) = gen_rtx_SET (gen_rtx_REG (SImode
, i
),
25709 RTX_FRAME_RELATED_P (XVECEXP (insn
, 0, 1)) = 1;
25710 insn
= emit_jump_insn (insn
);
25714 insn
= emit_insn (gen_movsi (gen_rtx_REG (SImode
, i
),
25716 REG_NOTES (insn
) = alloc_reg_note (REG_CFA_RESTORE
,
25717 gen_rtx_REG (SImode
, i
),
25719 arm_add_cfa_adjust_cfa_note (insn
, UNITS_PER_WORD
,
25721 stack_pointer_rtx
);
25728 && current_tune
->prefer_ldrd_strd
25729 && !optimize_function_for_size_p (cfun
))
25732 thumb2_emit_ldrd_pop (saved_regs_mask
);
25733 else if (TARGET_ARM
&& !IS_INTERRUPT (func_type
))
25734 arm_emit_ldrd_pop (saved_regs_mask
);
25736 arm_emit_multi_reg_pop (saved_regs_mask
);
25739 arm_emit_multi_reg_pop (saved_regs_mask
);
25747 = crtl
->args
.pretend_args_size
+ arm_compute_static_chain_stack_bytes();
25751 rtx dwarf
= NULL_RTX
;
25753 emit_insn (gen_addsi3 (stack_pointer_rtx
,
25755 GEN_INT (amount
)));
25757 RTX_FRAME_RELATED_P (tmp
) = 1;
25759 if (cfun
->machine
->uses_anonymous_args
)
25761 /* Restore pretend args. Refer arm_expand_prologue on how to save
25762 pretend_args in stack. */
25763 int num_regs
= crtl
->args
.pretend_args_size
/ 4;
25764 saved_regs_mask
= (0xf0 >> num_regs
) & 0xf;
25765 for (j
= 0, i
= 0; j
< num_regs
; i
++)
25766 if (saved_regs_mask
& (1 << i
))
25768 rtx reg
= gen_rtx_REG (SImode
, i
);
25769 dwarf
= alloc_reg_note (REG_CFA_RESTORE
, reg
, dwarf
);
25772 REG_NOTES (tmp
) = dwarf
;
25774 arm_add_cfa_adjust_cfa_note (tmp
, amount
,
25775 stack_pointer_rtx
, stack_pointer_rtx
);
25778 /* Clear all caller-saved regs that are not used to return. */
25779 if (IS_CMSE_ENTRY (arm_current_func_type ()))
25781 /* CMSE_ENTRY always returns. */
25782 gcc_assert (really_return
);
25783 cmse_nonsecure_entry_clear_before_return ();
25786 if (!really_return
)
25789 if (crtl
->calls_eh_return
)
25790 emit_insn (gen_addsi3 (stack_pointer_rtx
,
25792 gen_rtx_REG (SImode
, ARM_EH_STACKADJ_REGNUM
)));
25794 if (IS_STACKALIGN (func_type
))
25795 /* Restore the original stack pointer. Before prologue, the stack was
25796 realigned and the original stack pointer saved in r0. For details,
25797 see comment in arm_expand_prologue. */
25798 emit_insn (gen_movsi (stack_pointer_rtx
, gen_rtx_REG (SImode
, R0_REGNUM
)));
25800 emit_jump_insn (simple_return_rtx
);
25803 /* Implementation of insn prologue_thumb1_interwork. This is the first
25804 "instruction" of a function called in ARM mode. Swap to thumb mode. */
25807 thumb1_output_interwork (void)
25810 FILE *f
= asm_out_file
;
25812 gcc_assert (MEM_P (DECL_RTL (current_function_decl
)));
25813 gcc_assert (GET_CODE (XEXP (DECL_RTL (current_function_decl
), 0))
25815 name
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
25817 /* Generate code sequence to switch us into Thumb mode. */
25818 /* The .code 32 directive has already been emitted by
25819 ASM_DECLARE_FUNCTION_NAME. */
25820 asm_fprintf (f
, "\torr\t%r, %r, #1\n", IP_REGNUM
, PC_REGNUM
);
25821 asm_fprintf (f
, "\tbx\t%r\n", IP_REGNUM
);
25823 /* Generate a label, so that the debugger will notice the
25824 change in instruction sets. This label is also used by
25825 the assembler to bypass the ARM code when this function
25826 is called from a Thumb encoded function elsewhere in the
25827 same file. Hence the definition of STUB_NAME here must
25828 agree with the definition in gas/config/tc-arm.c. */
25830 #define STUB_NAME ".real_start_of"
25832 fprintf (f
, "\t.code\t16\n");
25834 if (arm_dllexport_name_p (name
))
25835 name
= arm_strip_name_encoding (name
);
25837 asm_fprintf (f
, "\t.globl %s%U%s\n", STUB_NAME
, name
);
25838 fprintf (f
, "\t.thumb_func\n");
25839 asm_fprintf (f
, "%s%U%s:\n", STUB_NAME
, name
);
25844 /* Handle the case of a double word load into a low register from
25845 a computed memory address. The computed address may involve a
25846 register which is overwritten by the load. */
25848 thumb_load_double_from_address (rtx
*operands
)
25856 gcc_assert (REG_P (operands
[0]));
25857 gcc_assert (MEM_P (operands
[1]));
25859 /* Get the memory address. */
25860 addr
= XEXP (operands
[1], 0);
25862 /* Work out how the memory address is computed. */
25863 switch (GET_CODE (addr
))
25866 operands
[2] = adjust_address (operands
[1], SImode
, 4);
25868 if (REGNO (operands
[0]) == REGNO (addr
))
25870 output_asm_insn ("ldr\t%H0, %2", operands
);
25871 output_asm_insn ("ldr\t%0, %1", operands
);
25875 output_asm_insn ("ldr\t%0, %1", operands
);
25876 output_asm_insn ("ldr\t%H0, %2", operands
);
25881 /* Compute <address> + 4 for the high order load. */
25882 operands
[2] = adjust_address (operands
[1], SImode
, 4);
25884 output_asm_insn ("ldr\t%0, %1", operands
);
25885 output_asm_insn ("ldr\t%H0, %2", operands
);
25889 arg1
= XEXP (addr
, 0);
25890 arg2
= XEXP (addr
, 1);
25892 if (CONSTANT_P (arg1
))
25893 base
= arg2
, offset
= arg1
;
25895 base
= arg1
, offset
= arg2
;
25897 gcc_assert (REG_P (base
));
25899 /* Catch the case of <address> = <reg> + <reg> */
25900 if (REG_P (offset
))
25902 int reg_offset
= REGNO (offset
);
25903 int reg_base
= REGNO (base
);
25904 int reg_dest
= REGNO (operands
[0]);
25906 /* Add the base and offset registers together into the
25907 higher destination register. */
25908 asm_fprintf (asm_out_file
, "\tadd\t%r, %r, %r",
25909 reg_dest
+ 1, reg_base
, reg_offset
);
25911 /* Load the lower destination register from the address in
25912 the higher destination register. */
25913 asm_fprintf (asm_out_file
, "\tldr\t%r, [%r, #0]",
25914 reg_dest
, reg_dest
+ 1);
25916 /* Load the higher destination register from its own address
25918 asm_fprintf (asm_out_file
, "\tldr\t%r, [%r, #4]",
25919 reg_dest
+ 1, reg_dest
+ 1);
25923 /* Compute <address> + 4 for the high order load. */
25924 operands
[2] = adjust_address (operands
[1], SImode
, 4);
25926 /* If the computed address is held in the low order register
25927 then load the high order register first, otherwise always
25928 load the low order register first. */
25929 if (REGNO (operands
[0]) == REGNO (base
))
25931 output_asm_insn ("ldr\t%H0, %2", operands
);
25932 output_asm_insn ("ldr\t%0, %1", operands
);
25936 output_asm_insn ("ldr\t%0, %1", operands
);
25937 output_asm_insn ("ldr\t%H0, %2", operands
);
25943 /* With no registers to worry about we can just load the value
25945 operands
[2] = adjust_address (operands
[1], SImode
, 4);
25947 output_asm_insn ("ldr\t%H0, %2", operands
);
25948 output_asm_insn ("ldr\t%0, %1", operands
);
25952 gcc_unreachable ();
25959 thumb_output_move_mem_multiple (int n
, rtx
*operands
)
25964 if (REGNO (operands
[4]) > REGNO (operands
[5]))
25965 std::swap (operands
[4], operands
[5]);
25967 output_asm_insn ("ldmia\t%1!, {%4, %5}", operands
);
25968 output_asm_insn ("stmia\t%0!, {%4, %5}", operands
);
25972 if (REGNO (operands
[4]) > REGNO (operands
[5]))
25973 std::swap (operands
[4], operands
[5]);
25974 if (REGNO (operands
[5]) > REGNO (operands
[6]))
25975 std::swap (operands
[5], operands
[6]);
25976 if (REGNO (operands
[4]) > REGNO (operands
[5]))
25977 std::swap (operands
[4], operands
[5]);
25979 output_asm_insn ("ldmia\t%1!, {%4, %5, %6}", operands
);
25980 output_asm_insn ("stmia\t%0!, {%4, %5, %6}", operands
);
25984 gcc_unreachable ();
25990 /* Output a call-via instruction for thumb state. */
25992 thumb_call_via_reg (rtx reg
)
25994 int regno
= REGNO (reg
);
25997 gcc_assert (regno
< LR_REGNUM
);
25999 /* If we are in the normal text section we can use a single instance
26000 per compilation unit. If we are doing function sections, then we need
26001 an entry per section, since we can't rely on reachability. */
26002 if (in_section
== text_section
)
26004 thumb_call_reg_needed
= 1;
26006 if (thumb_call_via_label
[regno
] == NULL
)
26007 thumb_call_via_label
[regno
] = gen_label_rtx ();
26008 labelp
= thumb_call_via_label
+ regno
;
26012 if (cfun
->machine
->call_via
[regno
] == NULL
)
26013 cfun
->machine
->call_via
[regno
] = gen_label_rtx ();
26014 labelp
= cfun
->machine
->call_via
+ regno
;
26017 output_asm_insn ("bl\t%a0", labelp
);
26021 /* Routines for generating rtl. */
26023 thumb_expand_movmemqi (rtx
*operands
)
26025 rtx out
= copy_to_mode_reg (SImode
, XEXP (operands
[0], 0));
26026 rtx in
= copy_to_mode_reg (SImode
, XEXP (operands
[1], 0));
26027 HOST_WIDE_INT len
= INTVAL (operands
[2]);
26028 HOST_WIDE_INT offset
= 0;
26032 emit_insn (gen_movmem12b (out
, in
, out
, in
));
26038 emit_insn (gen_movmem8b (out
, in
, out
, in
));
26044 rtx reg
= gen_reg_rtx (SImode
);
26045 emit_insn (gen_movsi (reg
, gen_rtx_MEM (SImode
, in
)));
26046 emit_insn (gen_movsi (gen_rtx_MEM (SImode
, out
), reg
));
26053 rtx reg
= gen_reg_rtx (HImode
);
26054 emit_insn (gen_movhi (reg
, gen_rtx_MEM (HImode
,
26055 plus_constant (Pmode
, in
,
26057 emit_insn (gen_movhi (gen_rtx_MEM (HImode
, plus_constant (Pmode
, out
,
26066 rtx reg
= gen_reg_rtx (QImode
);
26067 emit_insn (gen_movqi (reg
, gen_rtx_MEM (QImode
,
26068 plus_constant (Pmode
, in
,
26070 emit_insn (gen_movqi (gen_rtx_MEM (QImode
, plus_constant (Pmode
, out
,
26077 thumb_reload_out_hi (rtx
*operands
)
26079 emit_insn (gen_thumb_movhi_clobber (operands
[0], operands
[1], operands
[2]));
26082 /* Return the length of a function name prefix
26083 that starts with the character 'c'. */
26085 arm_get_strip_length (int c
)
26089 ARM_NAME_ENCODING_LENGTHS
26094 /* Return a pointer to a function's name with any
26095 and all prefix encodings stripped from it. */
26097 arm_strip_name_encoding (const char *name
)
26101 while ((skip
= arm_get_strip_length (* name
)))
26107 /* If there is a '*' anywhere in the name's prefix, then
26108 emit the stripped name verbatim, otherwise prepend an
26109 underscore if leading underscores are being used. */
26111 arm_asm_output_labelref (FILE *stream
, const char *name
)
26116 while ((skip
= arm_get_strip_length (* name
)))
26118 verbatim
|= (*name
== '*');
26123 fputs (name
, stream
);
26125 asm_fprintf (stream
, "%U%s", name
);
26128 /* This function is used to emit an EABI tag and its associated value.
26129 We emit the numerical value of the tag in case the assembler does not
26130 support textual tags. (Eg gas prior to 2.20). If requested we include
26131 the tag name in a comment so that anyone reading the assembler output
26132 will know which tag is being set.
26134 This function is not static because arm-c.c needs it too. */
26137 arm_emit_eabi_attribute (const char *name
, int num
, int val
)
26139 asm_fprintf (asm_out_file
, "\t.eabi_attribute %d, %d", num
, val
);
26140 if (flag_verbose_asm
|| flag_debug_asm
)
26141 asm_fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
, name
);
26142 asm_fprintf (asm_out_file
, "\n");
26145 /* This function is used to print CPU tuning information as comment
26146 in assembler file. Pointers are not printed for now. */
26149 arm_print_tune_info (void)
26151 asm_fprintf (asm_out_file
, "\t" ASM_COMMENT_START
".tune parameters\n");
26152 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
"constant_limit:\t%d\n",
26153 current_tune
->constant_limit
);
26154 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26155 "max_insns_skipped:\t%d\n", current_tune
->max_insns_skipped
);
26156 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26157 "prefetch.num_slots:\t%d\n", current_tune
->prefetch
.num_slots
);
26158 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26159 "prefetch.l1_cache_size:\t%d\n",
26160 current_tune
->prefetch
.l1_cache_size
);
26161 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26162 "prefetch.l1_cache_line_size:\t%d\n",
26163 current_tune
->prefetch
.l1_cache_line_size
);
26164 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26165 "prefer_constant_pool:\t%d\n",
26166 (int) current_tune
->prefer_constant_pool
);
26167 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26168 "branch_cost:\t(s:speed, p:predictable)\n");
26169 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
"\t\ts&p\tcost\n");
26170 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
"\t\t00\t%d\n",
26171 current_tune
->branch_cost (false, false));
26172 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
"\t\t01\t%d\n",
26173 current_tune
->branch_cost (false, true));
26174 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
"\t\t10\t%d\n",
26175 current_tune
->branch_cost (true, false));
26176 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
"\t\t11\t%d\n",
26177 current_tune
->branch_cost (true, true));
26178 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26179 "prefer_ldrd_strd:\t%d\n",
26180 (int) current_tune
->prefer_ldrd_strd
);
26181 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26182 "logical_op_non_short_circuit:\t[%d,%d]\n",
26183 (int) current_tune
->logical_op_non_short_circuit_thumb
,
26184 (int) current_tune
->logical_op_non_short_circuit_arm
);
26185 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26186 "prefer_neon_for_64bits:\t%d\n",
26187 (int) current_tune
->prefer_neon_for_64bits
);
26188 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26189 "disparage_flag_setting_t16_encodings:\t%d\n",
26190 (int) current_tune
->disparage_flag_setting_t16_encodings
);
26191 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26192 "string_ops_prefer_neon:\t%d\n",
26193 (int) current_tune
->string_ops_prefer_neon
);
26194 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
26195 "max_insns_inline_memset:\t%d\n",
26196 current_tune
->max_insns_inline_memset
);
26197 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
"fusible_ops:\t%u\n",
26198 current_tune
->fusible_ops
);
26199 asm_fprintf (asm_out_file
, "\t\t" ASM_COMMENT_START
"sched_autopref:\t%d\n",
26200 (int) current_tune
->sched_autopref
);
26203 /* Print .arch and .arch_extension directives corresponding to the
26204 current architecture configuration. */
26206 arm_print_asm_arch_directives ()
26208 const arch_option
*arch
26209 = arm_parse_arch_option_name (all_architectures
, "-march",
26210 arm_active_target
.arch_name
);
26211 auto_sbitmap
opt_bits (isa_num_bits
);
26215 asm_fprintf (asm_out_file
, "\t.arch %s\n", arm_active_target
.arch_name
);
26216 if (!arch
->common
.extensions
)
26219 for (const struct cpu_arch_extension
*opt
= arch
->common
.extensions
;
26225 arm_initialize_isa (opt_bits
, opt
->isa_bits
);
26227 /* If every feature bit of this option is set in the target
26228 ISA specification, print out the option name. However,
26229 don't print anything if all the bits are part of the
26230 FPU specification. */
26231 if (bitmap_subset_p (opt_bits
, arm_active_target
.isa
)
26232 && !bitmap_subset_p (opt_bits
, isa_all_fpubits
))
26233 asm_fprintf (asm_out_file
, "\t.arch_extension %s\n", opt
->name
);
26239 arm_file_start (void)
26245 /* We don't have a specified CPU. Use the architecture to
26248 Note: it might be better to do this unconditionally, then the
26249 assembler would not need to know about all new CPU names as
26251 if (!arm_active_target
.core_name
)
26253 /* armv7ve doesn't support any extensions. */
26254 if (strcmp (arm_active_target
.arch_name
, "armv7ve") == 0)
26256 /* Keep backward compatability for assemblers
26257 which don't support armv7ve. */
26258 asm_fprintf (asm_out_file
, "\t.arch armv7-a\n");
26259 asm_fprintf (asm_out_file
, "\t.arch_extension virt\n");
26260 asm_fprintf (asm_out_file
, "\t.arch_extension idiv\n");
26261 asm_fprintf (asm_out_file
, "\t.arch_extension sec\n");
26262 asm_fprintf (asm_out_file
, "\t.arch_extension mp\n");
26265 arm_print_asm_arch_directives ();
26267 else if (strncmp (arm_active_target
.core_name
, "generic", 7) == 0)
26268 asm_fprintf (asm_out_file
, "\t.arch %s\n",
26269 arm_active_target
.core_name
+ 8);
26272 const char* truncated_name
26273 = arm_rewrite_selected_cpu (arm_active_target
.core_name
);
26274 asm_fprintf (asm_out_file
, "\t.cpu %s\n", truncated_name
);
26277 if (print_tune_info
)
26278 arm_print_tune_info ();
26280 if (! TARGET_SOFT_FLOAT
)
26282 if (TARGET_HARD_FLOAT
&& TARGET_VFP_SINGLE
)
26283 arm_emit_eabi_attribute ("Tag_ABI_HardFP_use", 27, 1);
26285 if (TARGET_HARD_FLOAT_ABI
)
26286 arm_emit_eabi_attribute ("Tag_ABI_VFP_args", 28, 1);
26289 /* Some of these attributes only apply when the corresponding features
26290 are used. However we don't have any easy way of figuring this out.
26291 Conservatively record the setting that would have been used. */
26293 if (flag_rounding_math
)
26294 arm_emit_eabi_attribute ("Tag_ABI_FP_rounding", 19, 1);
26296 if (!flag_unsafe_math_optimizations
)
26298 arm_emit_eabi_attribute ("Tag_ABI_FP_denormal", 20, 1);
26299 arm_emit_eabi_attribute ("Tag_ABI_FP_exceptions", 21, 1);
26301 if (flag_signaling_nans
)
26302 arm_emit_eabi_attribute ("Tag_ABI_FP_user_exceptions", 22, 1);
26304 arm_emit_eabi_attribute ("Tag_ABI_FP_number_model", 23,
26305 flag_finite_math_only
? 1 : 3);
26307 arm_emit_eabi_attribute ("Tag_ABI_align8_needed", 24, 1);
26308 arm_emit_eabi_attribute ("Tag_ABI_align8_preserved", 25, 1);
26309 arm_emit_eabi_attribute ("Tag_ABI_enum_size", 26,
26310 flag_short_enums
? 1 : 2);
26312 /* Tag_ABI_optimization_goals. */
26315 else if (optimize
>= 2)
26321 arm_emit_eabi_attribute ("Tag_ABI_optimization_goals", 30, val
);
26323 arm_emit_eabi_attribute ("Tag_CPU_unaligned_access", 34,
26326 if (arm_fp16_format
)
26327 arm_emit_eabi_attribute ("Tag_ABI_FP_16bit_format", 38,
26328 (int) arm_fp16_format
);
26330 if (arm_lang_output_object_attributes_hook
)
26331 arm_lang_output_object_attributes_hook();
26334 default_file_start ();
26338 arm_file_end (void)
26342 if (NEED_INDICATE_EXEC_STACK
)
26343 /* Add .note.GNU-stack. */
26344 file_end_indicate_exec_stack ();
26346 if (! thumb_call_reg_needed
)
26349 switch_to_section (text_section
);
26350 asm_fprintf (asm_out_file
, "\t.code 16\n");
26351 ASM_OUTPUT_ALIGN (asm_out_file
, 1);
26353 for (regno
= 0; regno
< LR_REGNUM
; regno
++)
26355 rtx label
= thumb_call_via_label
[regno
];
26359 targetm
.asm_out
.internal_label (asm_out_file
, "L",
26360 CODE_LABEL_NUMBER (label
));
26361 asm_fprintf (asm_out_file
, "\tbx\t%r\n", regno
);
26367 /* Symbols in the text segment can be accessed without indirecting via the
26368 constant pool; it may take an extra binary operation, but this is still
26369 faster than indirecting via memory. Don't do this when not optimizing,
26370 since we won't be calculating al of the offsets necessary to do this
26374 arm_encode_section_info (tree decl
, rtx rtl
, int first
)
26376 if (optimize
> 0 && TREE_CONSTANT (decl
))
26377 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = 1;
26379 default_encode_section_info (decl
, rtl
, first
);
26381 #endif /* !ARM_PE */
26384 arm_internal_label (FILE *stream
, const char *prefix
, unsigned long labelno
)
26386 if (arm_ccfsm_state
== 3 && (unsigned) arm_target_label
== labelno
26387 && !strcmp (prefix
, "L"))
26389 arm_ccfsm_state
= 0;
26390 arm_target_insn
= NULL
;
26392 default_internal_label (stream
, prefix
, labelno
);
26395 /* Output code to add DELTA to the first argument, and then jump
26396 to FUNCTION. Used for C++ multiple inheritance. */
26399 arm_thumb1_mi_thunk (FILE *file
, tree
, HOST_WIDE_INT delta
,
26400 HOST_WIDE_INT
, tree function
)
26402 static int thunk_label
= 0;
26405 int mi_delta
= delta
;
26406 const char *const mi_op
= mi_delta
< 0 ? "sub" : "add";
26408 int this_regno
= (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
)
26411 mi_delta
= - mi_delta
;
26413 final_start_function (emit_barrier (), file
, 1);
26417 int labelno
= thunk_label
++;
26418 ASM_GENERATE_INTERNAL_LABEL (label
, "LTHUMBFUNC", labelno
);
26419 /* Thunks are entered in arm mode when available. */
26420 if (TARGET_THUMB1_ONLY
)
26422 /* push r3 so we can use it as a temporary. */
26423 /* TODO: Omit this save if r3 is not used. */
26424 fputs ("\tpush {r3}\n", file
);
26425 fputs ("\tldr\tr3, ", file
);
26429 fputs ("\tldr\tr12, ", file
);
26431 assemble_name (file
, label
);
26432 fputc ('\n', file
);
26435 /* If we are generating PIC, the ldr instruction below loads
26436 "(target - 7) - .LTHUNKPCn" into r12. The pc reads as
26437 the address of the add + 8, so we have:
26439 r12 = (target - 7) - .LTHUNKPCn + (.LTHUNKPCn + 8)
26442 Note that we have "+ 1" because some versions of GNU ld
26443 don't set the low bit of the result for R_ARM_REL32
26444 relocations against thumb function symbols.
26445 On ARMv6M this is +4, not +8. */
26446 ASM_GENERATE_INTERNAL_LABEL (labelpc
, "LTHUNKPC", labelno
);
26447 assemble_name (file
, labelpc
);
26448 fputs (":\n", file
);
26449 if (TARGET_THUMB1_ONLY
)
26451 /* This is 2 insns after the start of the thunk, so we know it
26452 is 4-byte aligned. */
26453 fputs ("\tadd\tr3, pc, r3\n", file
);
26454 fputs ("\tmov r12, r3\n", file
);
26457 fputs ("\tadd\tr12, pc, r12\n", file
);
26459 else if (TARGET_THUMB1_ONLY
)
26460 fputs ("\tmov r12, r3\n", file
);
26462 if (TARGET_THUMB1_ONLY
)
26464 if (mi_delta
> 255)
26466 fputs ("\tldr\tr3, ", file
);
26467 assemble_name (file
, label
);
26468 fputs ("+4\n", file
);
26469 asm_fprintf (file
, "\t%ss\t%r, %r, r3\n",
26470 mi_op
, this_regno
, this_regno
);
26472 else if (mi_delta
!= 0)
26474 /* Thumb1 unified syntax requires s suffix in instruction name when
26475 one of the operands is immediate. */
26476 asm_fprintf (file
, "\t%ss\t%r, %r, #%d\n",
26477 mi_op
, this_regno
, this_regno
,
26483 /* TODO: Use movw/movt for large constants when available. */
26484 while (mi_delta
!= 0)
26486 if ((mi_delta
& (3 << shift
)) == 0)
26490 asm_fprintf (file
, "\t%s\t%r, %r, #%d\n",
26491 mi_op
, this_regno
, this_regno
,
26492 mi_delta
& (0xff << shift
));
26493 mi_delta
&= ~(0xff << shift
);
26500 if (TARGET_THUMB1_ONLY
)
26501 fputs ("\tpop\t{r3}\n", file
);
26503 fprintf (file
, "\tbx\tr12\n");
26504 ASM_OUTPUT_ALIGN (file
, 2);
26505 assemble_name (file
, label
);
26506 fputs (":\n", file
);
26509 /* Output ".word .LTHUNKn-[3,7]-.LTHUNKPCn". */
26510 rtx tem
= XEXP (DECL_RTL (function
), 0);
26511 /* For TARGET_THUMB1_ONLY the thunk is in Thumb mode, so the PC
26512 pipeline offset is four rather than eight. Adjust the offset
26514 tem
= plus_constant (GET_MODE (tem
), tem
,
26515 TARGET_THUMB1_ONLY
? -3 : -7);
26516 tem
= gen_rtx_MINUS (GET_MODE (tem
),
26518 gen_rtx_SYMBOL_REF (Pmode
,
26519 ggc_strdup (labelpc
)));
26520 assemble_integer (tem
, 4, BITS_PER_WORD
, 1);
26523 /* Output ".word .LTHUNKn". */
26524 assemble_integer (XEXP (DECL_RTL (function
), 0), 4, BITS_PER_WORD
, 1);
26526 if (TARGET_THUMB1_ONLY
&& mi_delta
> 255)
26527 assemble_integer (GEN_INT(mi_delta
), 4, BITS_PER_WORD
, 1);
26531 fputs ("\tb\t", file
);
26532 assemble_name (file
, XSTR (XEXP (DECL_RTL (function
), 0), 0));
26533 if (NEED_PLT_RELOC
)
26534 fputs ("(PLT)", file
);
26535 fputc ('\n', file
);
26538 final_end_function ();
26541 /* MI thunk handling for TARGET_32BIT. */
26544 arm32_output_mi_thunk (FILE *file
, tree
, HOST_WIDE_INT delta
,
26545 HOST_WIDE_INT vcall_offset
, tree function
)
26547 /* On ARM, this_regno is R0 or R1 depending on
26548 whether the function returns an aggregate or not.
26550 int this_regno
= (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)),
26552 ? R1_REGNUM
: R0_REGNUM
);
26554 rtx temp
= gen_rtx_REG (Pmode
, IP_REGNUM
);
26555 rtx this_rtx
= gen_rtx_REG (Pmode
, this_regno
);
26556 reload_completed
= 1;
26557 emit_note (NOTE_INSN_PROLOGUE_END
);
26559 /* Add DELTA to THIS_RTX. */
26561 arm_split_constant (PLUS
, Pmode
, NULL_RTX
,
26562 delta
, this_rtx
, this_rtx
, false);
26564 /* Add *(*THIS_RTX + VCALL_OFFSET) to THIS_RTX. */
26565 if (vcall_offset
!= 0)
26567 /* Load *THIS_RTX. */
26568 emit_move_insn (temp
, gen_rtx_MEM (Pmode
, this_rtx
));
26569 /* Compute *THIS_RTX + VCALL_OFFSET. */
26570 arm_split_constant (PLUS
, Pmode
, NULL_RTX
, vcall_offset
, temp
, temp
,
26572 /* Compute *(*THIS_RTX + VCALL_OFFSET). */
26573 emit_move_insn (temp
, gen_rtx_MEM (Pmode
, temp
));
26574 emit_insn (gen_add3_insn (this_rtx
, this_rtx
, temp
));
26577 /* Generate a tail call to the target function. */
26578 if (!TREE_USED (function
))
26580 assemble_external (function
);
26581 TREE_USED (function
) = 1;
26583 rtx funexp
= XEXP (DECL_RTL (function
), 0);
26584 funexp
= gen_rtx_MEM (FUNCTION_MODE
, funexp
);
26585 rtx_insn
* insn
= emit_call_insn (gen_sibcall (funexp
, const0_rtx
, NULL_RTX
));
26586 SIBLING_CALL_P (insn
) = 1;
26588 insn
= get_insns ();
26589 shorten_branches (insn
);
26590 final_start_function (insn
, file
, 1);
26591 final (insn
, file
, 1);
26592 final_end_function ();
26594 /* Stop pretending this is a post-reload pass. */
26595 reload_completed
= 0;
26598 /* Output code to add DELTA to the first argument, and then jump
26599 to FUNCTION. Used for C++ multiple inheritance. */
26602 arm_output_mi_thunk (FILE *file
, tree thunk
, HOST_WIDE_INT delta
,
26603 HOST_WIDE_INT vcall_offset
, tree function
)
26606 arm32_output_mi_thunk (file
, thunk
, delta
, vcall_offset
, function
);
26608 arm_thumb1_mi_thunk (file
, thunk
, delta
, vcall_offset
, function
);
26612 arm_emit_vector_const (FILE *file
, rtx x
)
26615 const char * pattern
;
26617 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
26619 switch (GET_MODE (x
))
26621 case E_V2SImode
: pattern
= "%08x"; break;
26622 case E_V4HImode
: pattern
= "%04x"; break;
26623 case E_V8QImode
: pattern
= "%02x"; break;
26624 default: gcc_unreachable ();
26627 fprintf (file
, "0x");
26628 for (i
= CONST_VECTOR_NUNITS (x
); i
--;)
26632 element
= CONST_VECTOR_ELT (x
, i
);
26633 fprintf (file
, pattern
, INTVAL (element
));
26639 /* Emit a fp16 constant appropriately padded to occupy a 4-byte word.
26640 HFmode constant pool entries are actually loaded with ldr. */
26642 arm_emit_fp16_const (rtx c
)
26646 bits
= real_to_target (NULL
, CONST_DOUBLE_REAL_VALUE (c
), HFmode
);
26647 if (WORDS_BIG_ENDIAN
)
26648 assemble_zeros (2);
26649 assemble_integer (GEN_INT (bits
), 2, BITS_PER_WORD
, 1);
26650 if (!WORDS_BIG_ENDIAN
)
26651 assemble_zeros (2);
26655 arm_output_load_gr (rtx
*operands
)
26662 if (!MEM_P (operands
[1])
26663 || GET_CODE (sum
= XEXP (operands
[1], 0)) != PLUS
26664 || !REG_P (reg
= XEXP (sum
, 0))
26665 || !CONST_INT_P (offset
= XEXP (sum
, 1))
26666 || ((INTVAL (offset
) < 1024) && (INTVAL (offset
) > -1024)))
26667 return "wldrw%?\t%0, %1";
26669 /* Fix up an out-of-range load of a GR register. */
26670 output_asm_insn ("str%?\t%0, [sp, #-4]!\t@ Start of GR load expansion", & reg
);
26671 wcgr
= operands
[0];
26673 output_asm_insn ("ldr%?\t%0, %1", operands
);
26675 operands
[0] = wcgr
;
26677 output_asm_insn ("tmcr%?\t%0, %1", operands
);
26678 output_asm_insn ("ldr%?\t%0, [sp], #4\t@ End of GR load expansion", & reg
);
26683 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.
26685 On the ARM, PRETEND_SIZE is set in order to have the prologue push the last
26686 named arg and all anonymous args onto the stack.
26687 XXX I know the prologue shouldn't be pushing registers, but it is faster
26691 arm_setup_incoming_varargs (cumulative_args_t pcum_v
,
26695 int second_time ATTRIBUTE_UNUSED
)
26697 CUMULATIVE_ARGS
*pcum
= get_cumulative_args (pcum_v
);
26700 cfun
->machine
->uses_anonymous_args
= 1;
26701 if (pcum
->pcs_variant
<= ARM_PCS_AAPCS_LOCAL
)
26703 nregs
= pcum
->aapcs_ncrn
;
26706 int res
= arm_needs_doubleword_align (mode
, type
);
26707 if (res
< 0 && warn_psabi
)
26708 inform (input_location
, "parameter passing for argument of "
26709 "type %qT changed in GCC 7.1", type
);
26715 nregs
= pcum
->nregs
;
26717 if (nregs
< NUM_ARG_REGS
)
26718 *pretend_size
= (NUM_ARG_REGS
- nregs
) * UNITS_PER_WORD
;
26721 /* We can't rely on the caller doing the proper promotion when
26722 using APCS or ATPCS. */
26725 arm_promote_prototypes (const_tree t ATTRIBUTE_UNUSED
)
26727 return !TARGET_AAPCS_BASED
;
26730 static machine_mode
26731 arm_promote_function_mode (const_tree type ATTRIBUTE_UNUSED
,
26733 int *punsignedp ATTRIBUTE_UNUSED
,
26734 const_tree fntype ATTRIBUTE_UNUSED
,
26735 int for_return ATTRIBUTE_UNUSED
)
26737 if (GET_MODE_CLASS (mode
) == MODE_INT
26738 && GET_MODE_SIZE (mode
) < 4)
26746 arm_default_short_enums (void)
26748 return ARM_DEFAULT_SHORT_ENUMS
;
26752 /* AAPCS requires that anonymous bitfields affect structure alignment. */
26755 arm_align_anon_bitfield (void)
26757 return TARGET_AAPCS_BASED
;
26761 /* The generic C++ ABI says 64-bit (long long). The EABI says 32-bit. */
26764 arm_cxx_guard_type (void)
26766 return TARGET_AAPCS_BASED
? integer_type_node
: long_long_integer_type_node
;
26770 /* The EABI says test the least significant bit of a guard variable. */
26773 arm_cxx_guard_mask_bit (void)
26775 return TARGET_AAPCS_BASED
;
26779 /* The EABI specifies that all array cookies are 8 bytes long. */
26782 arm_get_cookie_size (tree type
)
26786 if (!TARGET_AAPCS_BASED
)
26787 return default_cxx_get_cookie_size (type
);
26789 size
= build_int_cst (sizetype
, 8);
26794 /* The EABI says that array cookies should also contain the element size. */
26797 arm_cookie_has_size (void)
26799 return TARGET_AAPCS_BASED
;
26803 /* The EABI says constructors and destructors should return a pointer to
26804 the object constructed/destroyed. */
26807 arm_cxx_cdtor_returns_this (void)
26809 return TARGET_AAPCS_BASED
;
26812 /* The EABI says that an inline function may never be the key
26816 arm_cxx_key_method_may_be_inline (void)
26818 return !TARGET_AAPCS_BASED
;
26822 arm_cxx_determine_class_data_visibility (tree decl
)
26824 if (!TARGET_AAPCS_BASED
26825 || !TARGET_DLLIMPORT_DECL_ATTRIBUTES
)
26828 /* In general, \S 3.2.5.5 of the ARM EABI requires that class data
26829 is exported. However, on systems without dynamic vague linkage,
26830 \S 3.2.5.6 says that COMDAT class data has hidden linkage. */
26831 if (!TARGET_ARM_DYNAMIC_VAGUE_LINKAGE_P
&& DECL_COMDAT (decl
))
26832 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
26834 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
26835 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
26839 arm_cxx_class_data_always_comdat (void)
26841 /* \S 3.2.5.4 of the ARM C++ ABI says that class data only have
26842 vague linkage if the class has no key function. */
26843 return !TARGET_AAPCS_BASED
;
26847 /* The EABI says __aeabi_atexit should be used to register static
26851 arm_cxx_use_aeabi_atexit (void)
26853 return TARGET_AAPCS_BASED
;
26858 arm_set_return_address (rtx source
, rtx scratch
)
26860 arm_stack_offsets
*offsets
;
26861 HOST_WIDE_INT delta
;
26863 unsigned long saved_regs
;
26865 offsets
= arm_get_frame_offsets ();
26866 saved_regs
= offsets
->saved_regs_mask
;
26868 if ((saved_regs
& (1 << LR_REGNUM
)) == 0)
26869 emit_move_insn (gen_rtx_REG (Pmode
, LR_REGNUM
), source
);
26872 if (frame_pointer_needed
)
26873 addr
= plus_constant (Pmode
, hard_frame_pointer_rtx
, -4);
26876 /* LR will be the first saved register. */
26877 delta
= offsets
->outgoing_args
- (offsets
->frame
+ 4);
26882 emit_insn (gen_addsi3 (scratch
, stack_pointer_rtx
,
26883 GEN_INT (delta
& ~4095)));
26888 addr
= stack_pointer_rtx
;
26890 addr
= plus_constant (Pmode
, addr
, delta
);
26892 /* The store needs to be marked as frame related in order to prevent
26893 DSE from deleting it as dead if it is based on fp. */
26894 rtx insn
= emit_move_insn (gen_frame_mem (Pmode
, addr
), source
);
26895 RTX_FRAME_RELATED_P (insn
) = 1;
26896 add_reg_note (insn
, REG_CFA_RESTORE
, gen_rtx_REG (Pmode
, LR_REGNUM
));
26902 thumb_set_return_address (rtx source
, rtx scratch
)
26904 arm_stack_offsets
*offsets
;
26905 HOST_WIDE_INT delta
;
26906 HOST_WIDE_INT limit
;
26909 unsigned long mask
;
26913 offsets
= arm_get_frame_offsets ();
26914 mask
= offsets
->saved_regs_mask
;
26915 if (mask
& (1 << LR_REGNUM
))
26918 /* Find the saved regs. */
26919 if (frame_pointer_needed
)
26921 delta
= offsets
->soft_frame
- offsets
->saved_args
;
26922 reg
= THUMB_HARD_FRAME_POINTER_REGNUM
;
26928 delta
= offsets
->outgoing_args
- offsets
->saved_args
;
26931 /* Allow for the stack frame. */
26932 if (TARGET_THUMB1
&& TARGET_BACKTRACE
)
26934 /* The link register is always the first saved register. */
26937 /* Construct the address. */
26938 addr
= gen_rtx_REG (SImode
, reg
);
26941 emit_insn (gen_movsi (scratch
, GEN_INT (delta
)));
26942 emit_insn (gen_addsi3 (scratch
, scratch
, stack_pointer_rtx
));
26946 addr
= plus_constant (Pmode
, addr
, delta
);
26948 /* The store needs to be marked as frame related in order to prevent
26949 DSE from deleting it as dead if it is based on fp. */
26950 rtx insn
= emit_move_insn (gen_frame_mem (Pmode
, addr
), source
);
26951 RTX_FRAME_RELATED_P (insn
) = 1;
26952 add_reg_note (insn
, REG_CFA_RESTORE
, gen_rtx_REG (Pmode
, LR_REGNUM
));
26955 emit_move_insn (gen_rtx_REG (Pmode
, LR_REGNUM
), source
);
26958 /* Implements target hook vector_mode_supported_p. */
26960 arm_vector_mode_supported_p (machine_mode mode
)
26962 /* Neon also supports V2SImode, etc. listed in the clause below. */
26963 if (TARGET_NEON
&& (mode
== V2SFmode
|| mode
== V4SImode
|| mode
== V8HImode
26964 || mode
== V4HFmode
|| mode
== V16QImode
|| mode
== V4SFmode
26965 || mode
== V2DImode
|| mode
== V8HFmode
))
26968 if ((TARGET_NEON
|| TARGET_IWMMXT
)
26969 && ((mode
== V2SImode
)
26970 || (mode
== V4HImode
)
26971 || (mode
== V8QImode
)))
26974 if (TARGET_INT_SIMD
&& (mode
== V4UQQmode
|| mode
== V4QQmode
26975 || mode
== V2UHQmode
|| mode
== V2HQmode
|| mode
== V2UHAmode
26976 || mode
== V2HAmode
))
26982 /* Implements target hook array_mode_supported_p. */
26985 arm_array_mode_supported_p (machine_mode mode
,
26986 unsigned HOST_WIDE_INT nelems
)
26989 && (VALID_NEON_DREG_MODE (mode
) || VALID_NEON_QREG_MODE (mode
))
26990 && (nelems
>= 2 && nelems
<= 4))
26996 /* Use the option -mvectorize-with-neon-double to override the use of quardword
26997 registers when autovectorizing for Neon, at least until multiple vector
26998 widths are supported properly by the middle-end. */
27000 static machine_mode
27001 arm_preferred_simd_mode (scalar_mode mode
)
27007 return TARGET_NEON_VECTORIZE_DOUBLE
? V2SFmode
: V4SFmode
;
27009 return TARGET_NEON_VECTORIZE_DOUBLE
? V2SImode
: V4SImode
;
27011 return TARGET_NEON_VECTORIZE_DOUBLE
? V4HImode
: V8HImode
;
27013 return TARGET_NEON_VECTORIZE_DOUBLE
? V8QImode
: V16QImode
;
27015 if (!TARGET_NEON_VECTORIZE_DOUBLE
)
27022 if (TARGET_REALLY_IWMMXT
)
27038 /* Implement TARGET_CLASS_LIKELY_SPILLED_P.
27040 We need to define this for LO_REGS on Thumb-1. Otherwise we can end up
27041 using r0-r4 for function arguments, r7 for the stack frame and don't have
27042 enough left over to do doubleword arithmetic. For Thumb-2 all the
27043 potentially problematic instructions accept high registers so this is not
27044 necessary. Care needs to be taken to avoid adding new Thumb-2 patterns
27045 that require many low registers. */
27047 arm_class_likely_spilled_p (reg_class_t rclass
)
27049 if ((TARGET_THUMB1
&& rclass
== LO_REGS
)
27050 || rclass
== CC_REG
)
27056 /* Implements target hook small_register_classes_for_mode_p. */
27058 arm_small_register_classes_for_mode_p (machine_mode mode ATTRIBUTE_UNUSED
)
27060 return TARGET_THUMB1
;
27063 /* Implement TARGET_SHIFT_TRUNCATION_MASK. SImode shifts use normal
27064 ARM insns and therefore guarantee that the shift count is modulo 256.
27065 DImode shifts (those implemented by lib1funcs.S or by optabs.c)
27066 guarantee no particular behavior for out-of-range counts. */
27068 static unsigned HOST_WIDE_INT
27069 arm_shift_truncation_mask (machine_mode mode
)
27071 return mode
== SImode
? 255 : 0;
27075 /* Map internal gcc register numbers to DWARF2 register numbers. */
27078 arm_dbx_register_number (unsigned int regno
)
27083 if (IS_VFP_REGNUM (regno
))
27085 /* See comment in arm_dwarf_register_span. */
27086 if (VFP_REGNO_OK_FOR_SINGLE (regno
))
27087 return 64 + regno
- FIRST_VFP_REGNUM
;
27089 return 256 + (regno
- FIRST_VFP_REGNUM
) / 2;
27092 if (IS_IWMMXT_GR_REGNUM (regno
))
27093 return 104 + regno
- FIRST_IWMMXT_GR_REGNUM
;
27095 if (IS_IWMMXT_REGNUM (regno
))
27096 return 112 + regno
- FIRST_IWMMXT_REGNUM
;
27098 return DWARF_FRAME_REGISTERS
;
27101 /* Dwarf models VFPv3 registers as 32 64-bit registers.
27102 GCC models tham as 64 32-bit registers, so we need to describe this to
27103 the DWARF generation code. Other registers can use the default. */
27105 arm_dwarf_register_span (rtx rtl
)
27113 regno
= REGNO (rtl
);
27114 if (!IS_VFP_REGNUM (regno
))
27117 /* XXX FIXME: The EABI defines two VFP register ranges:
27118 64-95: Legacy VFPv2 numbering for S0-S31 (obsolescent)
27120 The recommended encoding for S0-S31 is a DW_OP_bit_piece of the
27121 corresponding D register. Until GDB supports this, we shall use the
27122 legacy encodings. We also use these encodings for D0-D15 for
27123 compatibility with older debuggers. */
27124 mode
= GET_MODE (rtl
);
27125 if (GET_MODE_SIZE (mode
) < 8)
27128 if (VFP_REGNO_OK_FOR_SINGLE (regno
))
27130 nregs
= GET_MODE_SIZE (mode
) / 4;
27131 for (i
= 0; i
< nregs
; i
+= 2)
27132 if (TARGET_BIG_END
)
27134 parts
[i
] = gen_rtx_REG (SImode
, regno
+ i
+ 1);
27135 parts
[i
+ 1] = gen_rtx_REG (SImode
, regno
+ i
);
27139 parts
[i
] = gen_rtx_REG (SImode
, regno
+ i
);
27140 parts
[i
+ 1] = gen_rtx_REG (SImode
, regno
+ i
+ 1);
27145 nregs
= GET_MODE_SIZE (mode
) / 8;
27146 for (i
= 0; i
< nregs
; i
++)
27147 parts
[i
] = gen_rtx_REG (DImode
, regno
+ i
);
27150 return gen_rtx_PARALLEL (VOIDmode
, gen_rtvec_v (nregs
, parts
));
27153 #if ARM_UNWIND_INFO
27154 /* Emit unwind directives for a store-multiple instruction or stack pointer
27155 push during alignment.
27156 These should only ever be generated by the function prologue code, so
27157 expect them to have a particular form.
27158 The store-multiple instruction sometimes pushes pc as the last register,
27159 although it should not be tracked into unwind information, or for -Os
27160 sometimes pushes some dummy registers before first register that needs
27161 to be tracked in unwind information; such dummy registers are there just
27162 to avoid separate stack adjustment, and will not be restored in the
27166 arm_unwind_emit_sequence (FILE * asm_out_file
, rtx p
)
27169 HOST_WIDE_INT offset
;
27170 HOST_WIDE_INT nregs
;
27174 unsigned padfirst
= 0, padlast
= 0;
27177 e
= XVECEXP (p
, 0, 0);
27178 gcc_assert (GET_CODE (e
) == SET
);
27180 /* First insn will adjust the stack pointer. */
27181 gcc_assert (GET_CODE (e
) == SET
27182 && REG_P (SET_DEST (e
))
27183 && REGNO (SET_DEST (e
)) == SP_REGNUM
27184 && GET_CODE (SET_SRC (e
)) == PLUS
);
27186 offset
= -INTVAL (XEXP (SET_SRC (e
), 1));
27187 nregs
= XVECLEN (p
, 0) - 1;
27188 gcc_assert (nregs
);
27190 reg
= REGNO (SET_SRC (XVECEXP (p
, 0, 1)));
27193 /* For -Os dummy registers can be pushed at the beginning to
27194 avoid separate stack pointer adjustment. */
27195 e
= XVECEXP (p
, 0, 1);
27196 e
= XEXP (SET_DEST (e
), 0);
27197 if (GET_CODE (e
) == PLUS
)
27198 padfirst
= INTVAL (XEXP (e
, 1));
27199 gcc_assert (padfirst
== 0 || optimize_size
);
27200 /* The function prologue may also push pc, but not annotate it as it is
27201 never restored. We turn this into a stack pointer adjustment. */
27202 e
= XVECEXP (p
, 0, nregs
);
27203 e
= XEXP (SET_DEST (e
), 0);
27204 if (GET_CODE (e
) == PLUS
)
27205 padlast
= offset
- INTVAL (XEXP (e
, 1)) - 4;
27207 padlast
= offset
- 4;
27208 gcc_assert (padlast
== 0 || padlast
== 4);
27210 fprintf (asm_out_file
, "\t.pad #4\n");
27212 fprintf (asm_out_file
, "\t.save {");
27214 else if (IS_VFP_REGNUM (reg
))
27217 fprintf (asm_out_file
, "\t.vsave {");
27220 /* Unknown register type. */
27221 gcc_unreachable ();
27223 /* If the stack increment doesn't match the size of the saved registers,
27224 something has gone horribly wrong. */
27225 gcc_assert (offset
== padfirst
+ nregs
* reg_size
+ padlast
);
27229 /* The remaining insns will describe the stores. */
27230 for (i
= 1; i
<= nregs
; i
++)
27232 /* Expect (set (mem <addr>) (reg)).
27233 Where <addr> is (reg:SP) or (plus (reg:SP) (const_int)). */
27234 e
= XVECEXP (p
, 0, i
);
27235 gcc_assert (GET_CODE (e
) == SET
27236 && MEM_P (SET_DEST (e
))
27237 && REG_P (SET_SRC (e
)));
27239 reg
= REGNO (SET_SRC (e
));
27240 gcc_assert (reg
>= lastreg
);
27243 fprintf (asm_out_file
, ", ");
27244 /* We can't use %r for vfp because we need to use the
27245 double precision register names. */
27246 if (IS_VFP_REGNUM (reg
))
27247 asm_fprintf (asm_out_file
, "d%d", (reg
- FIRST_VFP_REGNUM
) / 2);
27249 asm_fprintf (asm_out_file
, "%r", reg
);
27253 /* Check that the addresses are consecutive. */
27254 e
= XEXP (SET_DEST (e
), 0);
27255 if (GET_CODE (e
) == PLUS
)
27256 gcc_assert (REG_P (XEXP (e
, 0))
27257 && REGNO (XEXP (e
, 0)) == SP_REGNUM
27258 && CONST_INT_P (XEXP (e
, 1))
27259 && offset
== INTVAL (XEXP (e
, 1)));
27263 && REGNO (e
) == SP_REGNUM
);
27264 offset
+= reg_size
;
27267 fprintf (asm_out_file
, "}\n");
27269 fprintf (asm_out_file
, "\t.pad #%d\n", padfirst
);
27272 /* Emit unwind directives for a SET. */
27275 arm_unwind_emit_set (FILE * asm_out_file
, rtx p
)
27283 switch (GET_CODE (e0
))
27286 /* Pushing a single register. */
27287 if (GET_CODE (XEXP (e0
, 0)) != PRE_DEC
27288 || !REG_P (XEXP (XEXP (e0
, 0), 0))
27289 || REGNO (XEXP (XEXP (e0
, 0), 0)) != SP_REGNUM
)
27292 asm_fprintf (asm_out_file
, "\t.save ");
27293 if (IS_VFP_REGNUM (REGNO (e1
)))
27294 asm_fprintf(asm_out_file
, "{d%d}\n",
27295 (REGNO (e1
) - FIRST_VFP_REGNUM
) / 2);
27297 asm_fprintf(asm_out_file
, "{%r}\n", REGNO (e1
));
27301 if (REGNO (e0
) == SP_REGNUM
)
27303 /* A stack increment. */
27304 if (GET_CODE (e1
) != PLUS
27305 || !REG_P (XEXP (e1
, 0))
27306 || REGNO (XEXP (e1
, 0)) != SP_REGNUM
27307 || !CONST_INT_P (XEXP (e1
, 1)))
27310 asm_fprintf (asm_out_file
, "\t.pad #%wd\n",
27311 -INTVAL (XEXP (e1
, 1)));
27313 else if (REGNO (e0
) == HARD_FRAME_POINTER_REGNUM
)
27315 HOST_WIDE_INT offset
;
27317 if (GET_CODE (e1
) == PLUS
)
27319 if (!REG_P (XEXP (e1
, 0))
27320 || !CONST_INT_P (XEXP (e1
, 1)))
27322 reg
= REGNO (XEXP (e1
, 0));
27323 offset
= INTVAL (XEXP (e1
, 1));
27324 asm_fprintf (asm_out_file
, "\t.setfp %r, %r, #%wd\n",
27325 HARD_FRAME_POINTER_REGNUM
, reg
,
27328 else if (REG_P (e1
))
27331 asm_fprintf (asm_out_file
, "\t.setfp %r, %r\n",
27332 HARD_FRAME_POINTER_REGNUM
, reg
);
27337 else if (REG_P (e1
) && REGNO (e1
) == SP_REGNUM
)
27339 /* Move from sp to reg. */
27340 asm_fprintf (asm_out_file
, "\t.movsp %r\n", REGNO (e0
));
27342 else if (GET_CODE (e1
) == PLUS
27343 && REG_P (XEXP (e1
, 0))
27344 && REGNO (XEXP (e1
, 0)) == SP_REGNUM
27345 && CONST_INT_P (XEXP (e1
, 1)))
27347 /* Set reg to offset from sp. */
27348 asm_fprintf (asm_out_file
, "\t.movsp %r, #%d\n",
27349 REGNO (e0
), (int)INTVAL(XEXP (e1
, 1)));
27361 /* Emit unwind directives for the given insn. */
27364 arm_unwind_emit (FILE * asm_out_file
, rtx_insn
*insn
)
27367 bool handled_one
= false;
27369 if (arm_except_unwind_info (&global_options
) != UI_TARGET
)
27372 if (!(flag_unwind_tables
|| crtl
->uses_eh_lsda
)
27373 && (TREE_NOTHROW (current_function_decl
)
27374 || crtl
->all_throwers_are_sibcalls
))
27377 if (NOTE_P (insn
) || !RTX_FRAME_RELATED_P (insn
))
27380 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
27382 switch (REG_NOTE_KIND (note
))
27384 case REG_FRAME_RELATED_EXPR
:
27385 pat
= XEXP (note
, 0);
27388 case REG_CFA_REGISTER
:
27389 pat
= XEXP (note
, 0);
27392 pat
= PATTERN (insn
);
27393 if (GET_CODE (pat
) == PARALLEL
)
27394 pat
= XVECEXP (pat
, 0, 0);
27397 /* Only emitted for IS_STACKALIGN re-alignment. */
27402 src
= SET_SRC (pat
);
27403 dest
= SET_DEST (pat
);
27405 gcc_assert (src
== stack_pointer_rtx
);
27406 reg
= REGNO (dest
);
27407 asm_fprintf (asm_out_file
, "\t.unwind_raw 0, 0x%x @ vsp = r%d\n",
27410 handled_one
= true;
27413 /* The INSN is generated in epilogue. It is set as RTX_FRAME_RELATED_P
27414 to get correct dwarf information for shrink-wrap. We should not
27415 emit unwind information for it because these are used either for
27416 pretend arguments or notes to adjust sp and restore registers from
27418 case REG_CFA_DEF_CFA
:
27419 case REG_CFA_ADJUST_CFA
:
27420 case REG_CFA_RESTORE
:
27423 case REG_CFA_EXPRESSION
:
27424 case REG_CFA_OFFSET
:
27425 /* ??? Only handling here what we actually emit. */
27426 gcc_unreachable ();
27434 pat
= PATTERN (insn
);
27437 switch (GET_CODE (pat
))
27440 arm_unwind_emit_set (asm_out_file
, pat
);
27444 /* Store multiple. */
27445 arm_unwind_emit_sequence (asm_out_file
, pat
);
27454 /* Output a reference from a function exception table to the type_info
27455 object X. The EABI specifies that the symbol should be relocated by
27456 an R_ARM_TARGET2 relocation. */
27459 arm_output_ttype (rtx x
)
27461 fputs ("\t.word\t", asm_out_file
);
27462 output_addr_const (asm_out_file
, x
);
27463 /* Use special relocations for symbol references. */
27464 if (!CONST_INT_P (x
))
27465 fputs ("(TARGET2)", asm_out_file
);
27466 fputc ('\n', asm_out_file
);
27471 /* Implement TARGET_ASM_EMIT_EXCEPT_PERSONALITY. */
27474 arm_asm_emit_except_personality (rtx personality
)
27476 fputs ("\t.personality\t", asm_out_file
);
27477 output_addr_const (asm_out_file
, personality
);
27478 fputc ('\n', asm_out_file
);
27480 #endif /* ARM_UNWIND_INFO */
27482 /* Implement TARGET_ASM_INITIALIZE_SECTIONS. */
27485 arm_asm_init_sections (void)
27487 #if ARM_UNWIND_INFO
27488 exception_section
= get_unnamed_section (0, output_section_asm_op
,
27490 #endif /* ARM_UNWIND_INFO */
27492 #ifdef OBJECT_FORMAT_ELF
27493 if (target_pure_code
)
27494 text_section
->unnamed
.data
= "\t.section .text,\"0x20000006\",%progbits";
27498 /* Output unwind directives for the start/end of a function. */
27501 arm_output_fn_unwind (FILE * f
, bool prologue
)
27503 if (arm_except_unwind_info (&global_options
) != UI_TARGET
)
27507 fputs ("\t.fnstart\n", f
);
27510 /* If this function will never be unwound, then mark it as such.
27511 The came condition is used in arm_unwind_emit to suppress
27512 the frame annotations. */
27513 if (!(flag_unwind_tables
|| crtl
->uses_eh_lsda
)
27514 && (TREE_NOTHROW (current_function_decl
)
27515 || crtl
->all_throwers_are_sibcalls
))
27516 fputs("\t.cantunwind\n", f
);
27518 fputs ("\t.fnend\n", f
);
27523 arm_emit_tls_decoration (FILE *fp
, rtx x
)
27525 enum tls_reloc reloc
;
27528 val
= XVECEXP (x
, 0, 0);
27529 reloc
= (enum tls_reloc
) INTVAL (XVECEXP (x
, 0, 1));
27531 output_addr_const (fp
, val
);
27536 fputs ("(tlsgd)", fp
);
27539 fputs ("(tlsldm)", fp
);
27542 fputs ("(tlsldo)", fp
);
27545 fputs ("(gottpoff)", fp
);
27548 fputs ("(tpoff)", fp
);
27551 fputs ("(tlsdesc)", fp
);
27554 gcc_unreachable ();
27563 fputs (" + (. - ", fp
);
27564 output_addr_const (fp
, XVECEXP (x
, 0, 2));
27565 /* For DESCSEQ the 3rd operand encodes thumbness, and is added */
27566 fputs (reloc
== TLS_DESCSEQ
? " + " : " - ", fp
);
27567 output_addr_const (fp
, XVECEXP (x
, 0, 3));
27577 /* ARM implementation of TARGET_ASM_OUTPUT_DWARF_DTPREL. */
27580 arm_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
27582 gcc_assert (size
== 4);
27583 fputs ("\t.word\t", file
);
27584 output_addr_const (file
, x
);
27585 fputs ("(tlsldo)", file
);
27588 /* Implement TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA. */
27591 arm_output_addr_const_extra (FILE *fp
, rtx x
)
27593 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLS
)
27594 return arm_emit_tls_decoration (fp
, x
);
27595 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_PIC_LABEL
)
27598 int labelno
= INTVAL (XVECEXP (x
, 0, 0));
27600 ASM_GENERATE_INTERNAL_LABEL (label
, "LPIC", labelno
);
27601 assemble_name_raw (fp
, label
);
27605 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_GOTSYM_OFF
)
27607 assemble_name (fp
, "_GLOBAL_OFFSET_TABLE_");
27611 output_addr_const (fp
, XVECEXP (x
, 0, 0));
27615 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_SYMBOL_OFFSET
)
27617 output_addr_const (fp
, XVECEXP (x
, 0, 0));
27621 output_addr_const (fp
, XVECEXP (x
, 0, 1));
27625 else if (GET_CODE (x
) == CONST_VECTOR
)
27626 return arm_emit_vector_const (fp
, x
);
27631 /* Output assembly for a shift instruction.
27632 SET_FLAGS determines how the instruction modifies the condition codes.
27633 0 - Do not set condition codes.
27634 1 - Set condition codes.
27635 2 - Use smallest instruction. */
27637 arm_output_shift(rtx
* operands
, int set_flags
)
27640 static const char flag_chars
[3] = {'?', '.', '!'};
27645 c
= flag_chars
[set_flags
];
27646 shift
= shift_op(operands
[3], &val
);
27650 operands
[2] = GEN_INT(val
);
27651 sprintf (pattern
, "%s%%%c\t%%0, %%1, %%2", shift
, c
);
27654 sprintf (pattern
, "mov%%%c\t%%0, %%1", c
);
27656 output_asm_insn (pattern
, operands
);
27660 /* Output assembly for a WMMX immediate shift instruction. */
27662 arm_output_iwmmxt_shift_immediate (const char *insn_name
, rtx
*operands
, bool wror_or_wsra
)
27664 int shift
= INTVAL (operands
[2]);
27666 machine_mode opmode
= GET_MODE (operands
[0]);
27668 gcc_assert (shift
>= 0);
27670 /* If the shift value in the register versions is > 63 (for D qualifier),
27671 31 (for W qualifier) or 15 (for H qualifier). */
27672 if (((opmode
== V4HImode
) && (shift
> 15))
27673 || ((opmode
== V2SImode
) && (shift
> 31))
27674 || ((opmode
== DImode
) && (shift
> 63)))
27678 sprintf (templ
, "%s\t%%0, %%1, #%d", insn_name
, 32);
27679 output_asm_insn (templ
, operands
);
27680 if (opmode
== DImode
)
27682 sprintf (templ
, "%s\t%%0, %%0, #%d", insn_name
, 32);
27683 output_asm_insn (templ
, operands
);
27688 /* The destination register will contain all zeros. */
27689 sprintf (templ
, "wzero\t%%0");
27690 output_asm_insn (templ
, operands
);
27695 if ((opmode
== DImode
) && (shift
> 32))
27697 sprintf (templ
, "%s\t%%0, %%1, #%d", insn_name
, 32);
27698 output_asm_insn (templ
, operands
);
27699 sprintf (templ
, "%s\t%%0, %%0, #%d", insn_name
, shift
- 32);
27700 output_asm_insn (templ
, operands
);
27704 sprintf (templ
, "%s\t%%0, %%1, #%d", insn_name
, shift
);
27705 output_asm_insn (templ
, operands
);
27710 /* Output assembly for a WMMX tinsr instruction. */
27712 arm_output_iwmmxt_tinsr (rtx
*operands
)
27714 int mask
= INTVAL (operands
[3]);
27717 int units
= mode_nunits
[GET_MODE (operands
[0])];
27718 gcc_assert ((mask
& (mask
- 1)) == 0);
27719 for (i
= 0; i
< units
; ++i
)
27721 if ((mask
& 0x01) == 1)
27727 gcc_assert (i
< units
);
27729 switch (GET_MODE (operands
[0]))
27732 sprintf (templ
, "tinsrb%%?\t%%0, %%2, #%d", i
);
27735 sprintf (templ
, "tinsrh%%?\t%%0, %%2, #%d", i
);
27738 sprintf (templ
, "tinsrw%%?\t%%0, %%2, #%d", i
);
27741 gcc_unreachable ();
27744 output_asm_insn (templ
, operands
);
27749 /* Output a Thumb-1 casesi dispatch sequence. */
27751 thumb1_output_casesi (rtx
*operands
)
27753 rtx diff_vec
= PATTERN (NEXT_INSN (as_a
<rtx_insn
*> (operands
[0])));
27755 gcc_assert (GET_CODE (diff_vec
) == ADDR_DIFF_VEC
);
27757 switch (GET_MODE(diff_vec
))
27760 return (ADDR_DIFF_VEC_FLAGS (diff_vec
).offset_unsigned
?
27761 "bl\t%___gnu_thumb1_case_uqi" : "bl\t%___gnu_thumb1_case_sqi");
27763 return (ADDR_DIFF_VEC_FLAGS (diff_vec
).offset_unsigned
?
27764 "bl\t%___gnu_thumb1_case_uhi" : "bl\t%___gnu_thumb1_case_shi");
27766 return "bl\t%___gnu_thumb1_case_si";
27768 gcc_unreachable ();
27772 /* Output a Thumb-2 casesi instruction. */
27774 thumb2_output_casesi (rtx
*operands
)
27776 rtx diff_vec
= PATTERN (NEXT_INSN (as_a
<rtx_insn
*> (operands
[2])));
27778 gcc_assert (GET_CODE (diff_vec
) == ADDR_DIFF_VEC
);
27780 output_asm_insn ("cmp\t%0, %1", operands
);
27781 output_asm_insn ("bhi\t%l3", operands
);
27782 switch (GET_MODE(diff_vec
))
27785 return "tbb\t[%|pc, %0]";
27787 return "tbh\t[%|pc, %0, lsl #1]";
27791 output_asm_insn ("adr\t%4, %l2", operands
);
27792 output_asm_insn ("ldr\t%5, [%4, %0, lsl #2]", operands
);
27793 output_asm_insn ("add\t%4, %4, %5", operands
);
27798 output_asm_insn ("adr\t%4, %l2", operands
);
27799 return "ldr\t%|pc, [%4, %0, lsl #2]";
27802 gcc_unreachable ();
27806 /* Implement TARGET_SCHED_ISSUE_RATE. Lookup the issue rate in the
27807 per-core tuning structs. */
27809 arm_issue_rate (void)
27811 return current_tune
->issue_rate
;
27814 /* Return how many instructions should scheduler lookahead to choose the
27817 arm_first_cycle_multipass_dfa_lookahead (void)
27819 int issue_rate
= arm_issue_rate ();
27821 return issue_rate
> 1 && !sched_fusion
? issue_rate
: 0;
27824 /* Enable modeling of L2 auto-prefetcher. */
27826 arm_first_cycle_multipass_dfa_lookahead_guard (rtx_insn
*insn
, int ready_index
)
27828 return autopref_multipass_dfa_lookahead_guard (insn
, ready_index
);
27832 arm_mangle_type (const_tree type
)
27834 /* The ARM ABI documents (10th October 2008) say that "__va_list"
27835 has to be managled as if it is in the "std" namespace. */
27836 if (TARGET_AAPCS_BASED
27837 && lang_hooks
.types_compatible_p (CONST_CAST_TREE (type
), va_list_type
))
27838 return "St9__va_list";
27840 /* Half-precision float. */
27841 if (TREE_CODE (type
) == REAL_TYPE
&& TYPE_PRECISION (type
) == 16)
27844 /* Try mangling as a Neon type, TYPE_NAME is non-NULL if this is a
27846 if (TYPE_NAME (type
) != NULL
)
27847 return arm_mangle_builtin_type (type
);
27849 /* Use the default mangling. */
27853 /* Order of allocation of core registers for Thumb: this allocation is
27854 written over the corresponding initial entries of the array
27855 initialized with REG_ALLOC_ORDER. We allocate all low registers
27856 first. Saving and restoring a low register is usually cheaper than
27857 using a call-clobbered high register. */
27859 static const int thumb_core_reg_alloc_order
[] =
27861 3, 2, 1, 0, 4, 5, 6, 7,
27862 12, 14, 8, 9, 10, 11
27865 /* Adjust register allocation order when compiling for Thumb. */
27868 arm_order_regs_for_local_alloc (void)
27870 const int arm_reg_alloc_order
[] = REG_ALLOC_ORDER
;
27871 memcpy(reg_alloc_order
, arm_reg_alloc_order
, sizeof (reg_alloc_order
));
27873 memcpy (reg_alloc_order
, thumb_core_reg_alloc_order
,
27874 sizeof (thumb_core_reg_alloc_order
));
27877 /* Implement TARGET_FRAME_POINTER_REQUIRED. */
27880 arm_frame_pointer_required (void)
27882 if (SUBTARGET_FRAME_POINTER_REQUIRED
)
27885 /* If the function receives nonlocal gotos, it needs to save the frame
27886 pointer in the nonlocal_goto_save_area object. */
27887 if (cfun
->has_nonlocal_label
)
27890 /* The frame pointer is required for non-leaf APCS frames. */
27891 if (TARGET_ARM
&& TARGET_APCS_FRAME
&& !crtl
->is_leaf
)
27894 /* If we are probing the stack in the prologue, we will have a faulting
27895 instruction prior to the stack adjustment and this requires a frame
27896 pointer if we want to catch the exception using the EABI unwinder. */
27897 if (!IS_INTERRUPT (arm_current_func_type ())
27898 && (flag_stack_check
== STATIC_BUILTIN_STACK_CHECK
27899 || flag_stack_clash_protection
)
27900 && arm_except_unwind_info (&global_options
) == UI_TARGET
27901 && cfun
->can_throw_non_call_exceptions
)
27903 HOST_WIDE_INT size
= get_frame_size ();
27905 /* That's irrelevant if there is no stack adjustment. */
27909 /* That's relevant only if there is a stack probe. */
27910 if (crtl
->is_leaf
&& !cfun
->calls_alloca
)
27912 /* We don't have the final size of the frame so adjust. */
27913 size
+= 32 * UNITS_PER_WORD
;
27914 if (size
> PROBE_INTERVAL
&& size
> get_stack_check_protect ())
27924 /* Only thumb1 can't support conditional execution, so return true if
27925 the target is not thumb1. */
27927 arm_have_conditional_execution (void)
27929 return !TARGET_THUMB1
;
27932 /* The AAPCS sets the maximum alignment of a vector to 64 bits. */
27933 static HOST_WIDE_INT
27934 arm_vector_alignment (const_tree type
)
27936 HOST_WIDE_INT align
= tree_to_shwi (TYPE_SIZE (type
));
27938 if (TARGET_AAPCS_BASED
)
27939 align
= MIN (align
, 64);
27944 static unsigned int
27945 arm_autovectorize_vector_sizes (void)
27947 return TARGET_NEON_VECTORIZE_DOUBLE
? 0 : (16 | 8);
27951 arm_vector_alignment_reachable (const_tree type
, bool is_packed
)
27953 /* Vectors which aren't in packed structures will not be less aligned than
27954 the natural alignment of their element type, so this is safe. */
27955 if (TARGET_NEON
&& !BYTES_BIG_ENDIAN
&& unaligned_access
)
27958 return default_builtin_vector_alignment_reachable (type
, is_packed
);
27962 arm_builtin_support_vector_misalignment (machine_mode mode
,
27963 const_tree type
, int misalignment
,
27966 if (TARGET_NEON
&& !BYTES_BIG_ENDIAN
&& unaligned_access
)
27968 HOST_WIDE_INT align
= TYPE_ALIGN_UNIT (type
);
27973 /* If the misalignment is unknown, we should be able to handle the access
27974 so long as it is not to a member of a packed data structure. */
27975 if (misalignment
== -1)
27978 /* Return true if the misalignment is a multiple of the natural alignment
27979 of the vector's element type. This is probably always going to be
27980 true in practice, since we've already established that this isn't a
27982 return ((misalignment
% align
) == 0);
27985 return default_builtin_support_vector_misalignment (mode
, type
, misalignment
,
27990 arm_conditional_register_usage (void)
27994 if (TARGET_THUMB1
&& optimize_size
)
27996 /* When optimizing for size on Thumb-1, it's better not
27997 to use the HI regs, because of the overhead of
27999 for (regno
= FIRST_HI_REGNUM
; regno
<= LAST_HI_REGNUM
; ++regno
)
28000 fixed_regs
[regno
] = call_used_regs
[regno
] = 1;
28003 /* The link register can be clobbered by any branch insn,
28004 but we have no way to track that at present, so mark
28005 it as unavailable. */
28007 fixed_regs
[LR_REGNUM
] = call_used_regs
[LR_REGNUM
] = 1;
28009 if (TARGET_32BIT
&& TARGET_HARD_FLOAT
)
28011 /* VFPv3 registers are disabled when earlier VFP
28012 versions are selected due to the definition of
28013 LAST_VFP_REGNUM. */
28014 for (regno
= FIRST_VFP_REGNUM
;
28015 regno
<= LAST_VFP_REGNUM
; ++ regno
)
28017 fixed_regs
[regno
] = 0;
28018 call_used_regs
[regno
] = regno
< FIRST_VFP_REGNUM
+ 16
28019 || regno
>= FIRST_VFP_REGNUM
+ 32;
28023 if (TARGET_REALLY_IWMMXT
)
28025 regno
= FIRST_IWMMXT_GR_REGNUM
;
28026 /* The 2002/10/09 revision of the XScale ABI has wCG0
28027 and wCG1 as call-preserved registers. The 2002/11/21
28028 revision changed this so that all wCG registers are
28029 scratch registers. */
28030 for (regno
= FIRST_IWMMXT_GR_REGNUM
;
28031 regno
<= LAST_IWMMXT_GR_REGNUM
; ++ regno
)
28032 fixed_regs
[regno
] = 0;
28033 /* The XScale ABI has wR0 - wR9 as scratch registers,
28034 the rest as call-preserved registers. */
28035 for (regno
= FIRST_IWMMXT_REGNUM
;
28036 regno
<= LAST_IWMMXT_REGNUM
; ++ regno
)
28038 fixed_regs
[regno
] = 0;
28039 call_used_regs
[regno
] = regno
< FIRST_IWMMXT_REGNUM
+ 10;
28043 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
)
28045 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
28046 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
28048 else if (TARGET_APCS_STACK
)
28050 fixed_regs
[10] = 1;
28051 call_used_regs
[10] = 1;
28053 /* -mcaller-super-interworking reserves r11 for calls to
28054 _interwork_r11_call_via_rN(). Making the register global
28055 is an easy way of ensuring that it remains valid for all
28057 if (TARGET_APCS_FRAME
|| TARGET_CALLER_INTERWORKING
28058 || TARGET_TPCS_FRAME
|| TARGET_TPCS_LEAF_FRAME
)
28060 fixed_regs
[ARM_HARD_FRAME_POINTER_REGNUM
] = 1;
28061 call_used_regs
[ARM_HARD_FRAME_POINTER_REGNUM
] = 1;
28062 if (TARGET_CALLER_INTERWORKING
)
28063 global_regs
[ARM_HARD_FRAME_POINTER_REGNUM
] = 1;
28065 SUBTARGET_CONDITIONAL_REGISTER_USAGE
28069 arm_preferred_rename_class (reg_class_t rclass
)
28071 /* Thumb-2 instructions using LO_REGS may be smaller than instructions
28072 using GENERIC_REGS. During register rename pass, we prefer LO_REGS,
28073 and code size can be reduced. */
28074 if (TARGET_THUMB2
&& rclass
== GENERAL_REGS
)
28080 /* Compute the attribute "length" of insn "*push_multi".
28081 So this function MUST be kept in sync with that insn pattern. */
28083 arm_attr_length_push_multi(rtx parallel_op
, rtx first_op
)
28085 int i
, regno
, hi_reg
;
28086 int num_saves
= XVECLEN (parallel_op
, 0);
28096 regno
= REGNO (first_op
);
28097 /* For PUSH/STM under Thumb2 mode, we can use 16-bit encodings if the register
28098 list is 8-bit. Normally this means all registers in the list must be
28099 LO_REGS, that is (R0 -R7). If any HI_REGS used, then we must use 32-bit
28100 encodings. There is one exception for PUSH that LR in HI_REGS can be used
28101 with 16-bit encoding. */
28102 hi_reg
= (REGNO_REG_CLASS (regno
) == HI_REGS
) && (regno
!= LR_REGNUM
);
28103 for (i
= 1; i
< num_saves
&& !hi_reg
; i
++)
28105 regno
= REGNO (XEXP (XVECEXP (parallel_op
, 0, i
), 0));
28106 hi_reg
|= (REGNO_REG_CLASS (regno
) == HI_REGS
) && (regno
!= LR_REGNUM
);
28114 /* Compute the attribute "length" of insn. Currently, this function is used
28115 for "*load_multiple_with_writeback", "*pop_multiple_with_return" and
28116 "*pop_multiple_with_writeback_and_return". OPERANDS is the toplevel PARALLEL
28117 rtx, RETURN_PC is true if OPERANDS contains return insn. WRITE_BACK_P is
28118 true if OPERANDS contains insn which explicit updates base register. */
28121 arm_attr_length_pop_multi (rtx
*operands
, bool return_pc
, bool write_back_p
)
28130 rtx parallel_op
= operands
[0];
28131 /* Initialize to elements number of PARALLEL. */
28132 unsigned indx
= XVECLEN (parallel_op
, 0) - 1;
28133 /* Initialize the value to base register. */
28134 unsigned regno
= REGNO (operands
[1]);
28135 /* Skip return and write back pattern.
28136 We only need register pop pattern for later analysis. */
28137 unsigned first_indx
= 0;
28138 first_indx
+= return_pc
? 1 : 0;
28139 first_indx
+= write_back_p
? 1 : 0;
28141 /* A pop operation can be done through LDM or POP. If the base register is SP
28142 and if it's with write back, then a LDM will be alias of POP. */
28143 bool pop_p
= (regno
== SP_REGNUM
&& write_back_p
);
28144 bool ldm_p
= !pop_p
;
28146 /* Check base register for LDM. */
28147 if (ldm_p
&& REGNO_REG_CLASS (regno
) == HI_REGS
)
28150 /* Check each register in the list. */
28151 for (; indx
>= first_indx
; indx
--)
28153 regno
= REGNO (XEXP (XVECEXP (parallel_op
, 0, indx
), 0));
28154 /* For POP, PC in HI_REGS can be used with 16-bit encoding. See similar
28155 comment in arm_attr_length_push_multi. */
28156 if (REGNO_REG_CLASS (regno
) == HI_REGS
28157 && (regno
!= PC_REGNUM
|| ldm_p
))
28164 /* Compute the number of instructions emitted by output_move_double. */
28166 arm_count_output_move_double_insns (rtx
*operands
)
28170 /* output_move_double may modify the operands array, so call it
28171 here on a copy of the array. */
28172 ops
[0] = operands
[0];
28173 ops
[1] = operands
[1];
28174 output_move_double (ops
, false, &count
);
28179 vfp3_const_double_for_fract_bits (rtx operand
)
28181 REAL_VALUE_TYPE r0
;
28183 if (!CONST_DOUBLE_P (operand
))
28186 r0
= *CONST_DOUBLE_REAL_VALUE (operand
);
28187 if (exact_real_inverse (DFmode
, &r0
)
28188 && !REAL_VALUE_NEGATIVE (r0
))
28190 if (exact_real_truncate (DFmode
, &r0
))
28192 HOST_WIDE_INT value
= real_to_integer (&r0
);
28193 value
= value
& 0xffffffff;
28194 if ((value
!= 0) && ( (value
& (value
- 1)) == 0))
28196 int ret
= exact_log2 (value
);
28197 gcc_assert (IN_RANGE (ret
, 0, 31));
28205 /* If X is a CONST_DOUBLE with a value that is a power of 2 whose
28206 log2 is in [1, 32], return that log2. Otherwise return -1.
28207 This is used in the patterns for vcvt.s32.f32 floating-point to
28208 fixed-point conversions. */
28211 vfp3_const_double_for_bits (rtx x
)
28213 const REAL_VALUE_TYPE
*r
;
28215 if (!CONST_DOUBLE_P (x
))
28218 r
= CONST_DOUBLE_REAL_VALUE (x
);
28220 if (REAL_VALUE_NEGATIVE (*r
)
28221 || REAL_VALUE_ISNAN (*r
)
28222 || REAL_VALUE_ISINF (*r
)
28223 || !real_isinteger (r
, SFmode
))
28226 HOST_WIDE_INT hwint
= exact_log2 (real_to_integer (r
));
28228 /* The exact_log2 above will have returned -1 if this is
28229 not an exact log2. */
28230 if (!IN_RANGE (hwint
, 1, 32))
28237 /* Emit a memory barrier around an atomic sequence according to MODEL. */
28240 arm_pre_atomic_barrier (enum memmodel model
)
28242 if (need_atomic_barrier_p (model
, true))
28243 emit_insn (gen_memory_barrier ());
28247 arm_post_atomic_barrier (enum memmodel model
)
28249 if (need_atomic_barrier_p (model
, false))
28250 emit_insn (gen_memory_barrier ());
28253 /* Emit the load-exclusive and store-exclusive instructions.
28254 Use acquire and release versions if necessary. */
28257 arm_emit_load_exclusive (machine_mode mode
, rtx rval
, rtx mem
, bool acq
)
28259 rtx (*gen
) (rtx
, rtx
);
28265 case E_QImode
: gen
= gen_arm_load_acquire_exclusiveqi
; break;
28266 case E_HImode
: gen
= gen_arm_load_acquire_exclusivehi
; break;
28267 case E_SImode
: gen
= gen_arm_load_acquire_exclusivesi
; break;
28268 case E_DImode
: gen
= gen_arm_load_acquire_exclusivedi
; break;
28270 gcc_unreachable ();
28277 case E_QImode
: gen
= gen_arm_load_exclusiveqi
; break;
28278 case E_HImode
: gen
= gen_arm_load_exclusivehi
; break;
28279 case E_SImode
: gen
= gen_arm_load_exclusivesi
; break;
28280 case E_DImode
: gen
= gen_arm_load_exclusivedi
; break;
28282 gcc_unreachable ();
28286 emit_insn (gen (rval
, mem
));
28290 arm_emit_store_exclusive (machine_mode mode
, rtx bval
, rtx rval
,
28293 rtx (*gen
) (rtx
, rtx
, rtx
);
28299 case E_QImode
: gen
= gen_arm_store_release_exclusiveqi
; break;
28300 case E_HImode
: gen
= gen_arm_store_release_exclusivehi
; break;
28301 case E_SImode
: gen
= gen_arm_store_release_exclusivesi
; break;
28302 case E_DImode
: gen
= gen_arm_store_release_exclusivedi
; break;
28304 gcc_unreachable ();
28311 case E_QImode
: gen
= gen_arm_store_exclusiveqi
; break;
28312 case E_HImode
: gen
= gen_arm_store_exclusivehi
; break;
28313 case E_SImode
: gen
= gen_arm_store_exclusivesi
; break;
28314 case E_DImode
: gen
= gen_arm_store_exclusivedi
; break;
28316 gcc_unreachable ();
28320 emit_insn (gen (bval
, rval
, mem
));
28323 /* Mark the previous jump instruction as unlikely. */
28326 emit_unlikely_jump (rtx insn
)
28328 rtx_insn
*jump
= emit_jump_insn (insn
);
28329 add_reg_br_prob_note (jump
, profile_probability::very_unlikely ());
28332 /* Expand a compare and swap pattern. */
28335 arm_expand_compare_and_swap (rtx operands
[])
28337 rtx bval
, bdst
, rval
, mem
, oldval
, newval
, is_weak
, mod_s
, mod_f
, x
;
28339 rtx (*gen
) (rtx
, rtx
, rtx
, rtx
, rtx
, rtx
, rtx
, rtx
);
28341 bval
= operands
[0];
28342 rval
= operands
[1];
28344 oldval
= operands
[3];
28345 newval
= operands
[4];
28346 is_weak
= operands
[5];
28347 mod_s
= operands
[6];
28348 mod_f
= operands
[7];
28349 mode
= GET_MODE (mem
);
28351 /* Normally the succ memory model must be stronger than fail, but in the
28352 unlikely event of fail being ACQUIRE and succ being RELEASE we need to
28353 promote succ to ACQ_REL so that we don't lose the acquire semantics. */
28355 if (TARGET_HAVE_LDACQ
28356 && is_mm_acquire (memmodel_from_int (INTVAL (mod_f
)))
28357 && is_mm_release (memmodel_from_int (INTVAL (mod_s
))))
28358 mod_s
= GEN_INT (MEMMODEL_ACQ_REL
);
28364 /* For narrow modes, we're going to perform the comparison in SImode,
28365 so do the zero-extension now. */
28366 rval
= gen_reg_rtx (SImode
);
28367 oldval
= convert_modes (SImode
, mode
, oldval
, true);
28371 /* Force the value into a register if needed. We waited until after
28372 the zero-extension above to do this properly. */
28373 if (!arm_add_operand (oldval
, SImode
))
28374 oldval
= force_reg (SImode
, oldval
);
28378 if (!cmpdi_operand (oldval
, mode
))
28379 oldval
= force_reg (mode
, oldval
);
28383 gcc_unreachable ();
28390 case E_QImode
: gen
= gen_atomic_compare_and_swapt1qi_1
; break;
28391 case E_HImode
: gen
= gen_atomic_compare_and_swapt1hi_1
; break;
28392 case E_SImode
: gen
= gen_atomic_compare_and_swapt1si_1
; break;
28393 case E_DImode
: gen
= gen_atomic_compare_and_swapt1di_1
; break;
28395 gcc_unreachable ();
28402 case E_QImode
: gen
= gen_atomic_compare_and_swap32qi_1
; break;
28403 case E_HImode
: gen
= gen_atomic_compare_and_swap32hi_1
; break;
28404 case E_SImode
: gen
= gen_atomic_compare_and_swap32si_1
; break;
28405 case E_DImode
: gen
= gen_atomic_compare_and_swap32di_1
; break;
28407 gcc_unreachable ();
28411 bdst
= TARGET_THUMB1
? bval
: gen_rtx_REG (CC_Zmode
, CC_REGNUM
);
28412 emit_insn (gen (bdst
, rval
, mem
, oldval
, newval
, is_weak
, mod_s
, mod_f
));
28414 if (mode
== QImode
|| mode
== HImode
)
28415 emit_move_insn (operands
[1], gen_lowpart (mode
, rval
));
28417 /* In all cases, we arrange for success to be signaled by Z set.
28418 This arrangement allows for the boolean result to be used directly
28419 in a subsequent branch, post optimization. For Thumb-1 targets, the
28420 boolean negation of the result is also stored in bval because Thumb-1
28421 backend lacks dependency tracking for CC flag due to flag-setting not
28422 being represented at RTL level. */
28424 emit_insn (gen_cstoresi_eq0_thumb1 (bval
, bdst
));
28427 x
= gen_rtx_EQ (SImode
, bdst
, const0_rtx
);
28428 emit_insn (gen_rtx_SET (bval
, x
));
28432 /* Split a compare and swap pattern. It is IMPLEMENTATION DEFINED whether
28433 another memory store between the load-exclusive and store-exclusive can
28434 reset the monitor from Exclusive to Open state. This means we must wait
28435 until after reload to split the pattern, lest we get a register spill in
28436 the middle of the atomic sequence. Success of the compare and swap is
28437 indicated by the Z flag set for 32bit targets and by neg_bval being zero
28438 for Thumb-1 targets (ie. negation of the boolean value returned by
28439 atomic_compare_and_swapmode standard pattern in operand 0). */
28442 arm_split_compare_and_swap (rtx operands
[])
28444 rtx rval
, mem
, oldval
, newval
, neg_bval
;
28446 enum memmodel mod_s
, mod_f
;
28448 rtx_code_label
*label1
, *label2
;
28451 rval
= operands
[1];
28453 oldval
= operands
[3];
28454 newval
= operands
[4];
28455 is_weak
= (operands
[5] != const0_rtx
);
28456 mod_s
= memmodel_from_int (INTVAL (operands
[6]));
28457 mod_f
= memmodel_from_int (INTVAL (operands
[7]));
28458 neg_bval
= TARGET_THUMB1
? operands
[0] : operands
[8];
28459 mode
= GET_MODE (mem
);
28461 bool is_armv8_sync
= arm_arch8
&& is_mm_sync (mod_s
);
28463 bool use_acquire
= TARGET_HAVE_LDACQ
28464 && !(is_mm_relaxed (mod_s
) || is_mm_consume (mod_s
)
28465 || is_mm_release (mod_s
));
28467 bool use_release
= TARGET_HAVE_LDACQ
28468 && !(is_mm_relaxed (mod_s
) || is_mm_consume (mod_s
)
28469 || is_mm_acquire (mod_s
));
28471 /* For ARMv8, the load-acquire is too weak for __sync memory orders. Instead,
28472 a full barrier is emitted after the store-release. */
28474 use_acquire
= false;
28476 /* Checks whether a barrier is needed and emits one accordingly. */
28477 if (!(use_acquire
|| use_release
))
28478 arm_pre_atomic_barrier (mod_s
);
28483 label1
= gen_label_rtx ();
28484 emit_label (label1
);
28486 label2
= gen_label_rtx ();
28488 arm_emit_load_exclusive (mode
, rval
, mem
, use_acquire
);
28490 /* Z is set to 0 for 32bit targets (resp. rval set to 1) if oldval != rval,
28491 as required to communicate with arm_expand_compare_and_swap. */
28494 cond
= arm_gen_compare_reg (NE
, rval
, oldval
, neg_bval
);
28495 x
= gen_rtx_NE (VOIDmode
, cond
, const0_rtx
);
28496 x
= gen_rtx_IF_THEN_ELSE (VOIDmode
, x
,
28497 gen_rtx_LABEL_REF (Pmode
, label2
), pc_rtx
);
28498 emit_unlikely_jump (gen_rtx_SET (pc_rtx
, x
));
28502 emit_move_insn (neg_bval
, const1_rtx
);
28503 cond
= gen_rtx_NE (VOIDmode
, rval
, oldval
);
28504 if (thumb1_cmpneg_operand (oldval
, SImode
))
28505 emit_unlikely_jump (gen_cbranchsi4_scratch (neg_bval
, rval
, oldval
,
28508 emit_unlikely_jump (gen_cbranchsi4_insn (cond
, rval
, oldval
, label2
));
28511 arm_emit_store_exclusive (mode
, neg_bval
, mem
, newval
, use_release
);
28513 /* Weak or strong, we want EQ to be true for success, so that we
28514 match the flags that we got from the compare above. */
28517 cond
= gen_rtx_REG (CCmode
, CC_REGNUM
);
28518 x
= gen_rtx_COMPARE (CCmode
, neg_bval
, const0_rtx
);
28519 emit_insn (gen_rtx_SET (cond
, x
));
28524 /* Z is set to boolean value of !neg_bval, as required to communicate
28525 with arm_expand_compare_and_swap. */
28526 x
= gen_rtx_NE (VOIDmode
, neg_bval
, const0_rtx
);
28527 emit_unlikely_jump (gen_cbranchsi4 (x
, neg_bval
, const0_rtx
, label1
));
28530 if (!is_mm_relaxed (mod_f
))
28531 emit_label (label2
);
28533 /* Checks whether a barrier is needed and emits one accordingly. */
28535 || !(use_acquire
|| use_release
))
28536 arm_post_atomic_barrier (mod_s
);
28538 if (is_mm_relaxed (mod_f
))
28539 emit_label (label2
);
28542 /* Split an atomic operation pattern. Operation is given by CODE and is one
28543 of PLUS, MINUS, IOR, XOR, SET (for an exchange operation) or NOT (for a nand
28544 operation). Operation is performed on the content at MEM and on VALUE
28545 following the memory model MODEL_RTX. The content at MEM before and after
28546 the operation is returned in OLD_OUT and NEW_OUT respectively while the
28547 success of the operation is returned in COND. Using a scratch register or
28548 an operand register for these determines what result is returned for that
28552 arm_split_atomic_op (enum rtx_code code
, rtx old_out
, rtx new_out
, rtx mem
,
28553 rtx value
, rtx model_rtx
, rtx cond
)
28555 enum memmodel model
= memmodel_from_int (INTVAL (model_rtx
));
28556 machine_mode mode
= GET_MODE (mem
);
28557 machine_mode wmode
= (mode
== DImode
? DImode
: SImode
);
28558 rtx_code_label
*label
;
28559 bool all_low_regs
, bind_old_new
;
28562 bool is_armv8_sync
= arm_arch8
&& is_mm_sync (model
);
28564 bool use_acquire
= TARGET_HAVE_LDACQ
28565 && !(is_mm_relaxed (model
) || is_mm_consume (model
)
28566 || is_mm_release (model
));
28568 bool use_release
= TARGET_HAVE_LDACQ
28569 && !(is_mm_relaxed (model
) || is_mm_consume (model
)
28570 || is_mm_acquire (model
));
28572 /* For ARMv8, a load-acquire is too weak for __sync memory orders. Instead,
28573 a full barrier is emitted after the store-release. */
28575 use_acquire
= false;
28577 /* Checks whether a barrier is needed and emits one accordingly. */
28578 if (!(use_acquire
|| use_release
))
28579 arm_pre_atomic_barrier (model
);
28581 label
= gen_label_rtx ();
28582 emit_label (label
);
28585 new_out
= gen_lowpart (wmode
, new_out
);
28587 old_out
= gen_lowpart (wmode
, old_out
);
28590 value
= simplify_gen_subreg (wmode
, value
, mode
, 0);
28592 arm_emit_load_exclusive (mode
, old_out
, mem
, use_acquire
);
28594 /* Does the operation require destination and first operand to use the same
28595 register? This is decided by register constraints of relevant insn
28596 patterns in thumb1.md. */
28597 gcc_assert (!new_out
|| REG_P (new_out
));
28598 all_low_regs
= REG_P (value
) && REGNO_REG_CLASS (REGNO (value
)) == LO_REGS
28599 && new_out
&& REGNO_REG_CLASS (REGNO (new_out
)) == LO_REGS
28600 && REGNO_REG_CLASS (REGNO (old_out
)) == LO_REGS
;
28605 && (code
!= PLUS
|| (!all_low_regs
&& !satisfies_constraint_L (value
))));
28607 /* We want to return the old value while putting the result of the operation
28608 in the same register as the old value so copy the old value over to the
28609 destination register and use that register for the operation. */
28610 if (old_out
&& bind_old_new
)
28612 emit_move_insn (new_out
, old_out
);
28623 x
= gen_rtx_AND (wmode
, old_out
, value
);
28624 emit_insn (gen_rtx_SET (new_out
, x
));
28625 x
= gen_rtx_NOT (wmode
, new_out
);
28626 emit_insn (gen_rtx_SET (new_out
, x
));
28630 if (CONST_INT_P (value
))
28632 value
= GEN_INT (-INTVAL (value
));
28638 if (mode
== DImode
)
28640 /* DImode plus/minus need to clobber flags. */
28641 /* The adddi3 and subdi3 patterns are incorrectly written so that
28642 they require matching operands, even when we could easily support
28643 three operands. Thankfully, this can be fixed up post-splitting,
28644 as the individual add+adc patterns do accept three operands and
28645 post-reload cprop can make these moves go away. */
28646 emit_move_insn (new_out
, old_out
);
28648 x
= gen_adddi3 (new_out
, new_out
, value
);
28650 x
= gen_subdi3 (new_out
, new_out
, value
);
28657 x
= gen_rtx_fmt_ee (code
, wmode
, old_out
, value
);
28658 emit_insn (gen_rtx_SET (new_out
, x
));
28662 arm_emit_store_exclusive (mode
, cond
, mem
, gen_lowpart (mode
, new_out
),
28665 x
= gen_rtx_NE (VOIDmode
, cond
, const0_rtx
);
28666 emit_unlikely_jump (gen_cbranchsi4 (x
, cond
, const0_rtx
, label
));
28668 /* Checks whether a barrier is needed and emits one accordingly. */
28670 || !(use_acquire
|| use_release
))
28671 arm_post_atomic_barrier (model
);
28674 #define MAX_VECT_LEN 16
28676 struct expand_vec_perm_d
28678 rtx target
, op0
, op1
;
28679 auto_vec_perm_indices perm
;
28680 machine_mode vmode
;
28685 /* Generate a variable permutation. */
28688 arm_expand_vec_perm_1 (rtx target
, rtx op0
, rtx op1
, rtx sel
)
28690 machine_mode vmode
= GET_MODE (target
);
28691 bool one_vector_p
= rtx_equal_p (op0
, op1
);
28693 gcc_checking_assert (vmode
== V8QImode
|| vmode
== V16QImode
);
28694 gcc_checking_assert (GET_MODE (op0
) == vmode
);
28695 gcc_checking_assert (GET_MODE (op1
) == vmode
);
28696 gcc_checking_assert (GET_MODE (sel
) == vmode
);
28697 gcc_checking_assert (TARGET_NEON
);
28701 if (vmode
== V8QImode
)
28702 emit_insn (gen_neon_vtbl1v8qi (target
, op0
, sel
));
28704 emit_insn (gen_neon_vtbl1v16qi (target
, op0
, sel
));
28710 if (vmode
== V8QImode
)
28712 pair
= gen_reg_rtx (V16QImode
);
28713 emit_insn (gen_neon_vcombinev8qi (pair
, op0
, op1
));
28714 pair
= gen_lowpart (TImode
, pair
);
28715 emit_insn (gen_neon_vtbl2v8qi (target
, pair
, sel
));
28719 pair
= gen_reg_rtx (OImode
);
28720 emit_insn (gen_neon_vcombinev16qi (pair
, op0
, op1
));
28721 emit_insn (gen_neon_vtbl2v16qi (target
, pair
, sel
));
28727 arm_expand_vec_perm (rtx target
, rtx op0
, rtx op1
, rtx sel
)
28729 machine_mode vmode
= GET_MODE (target
);
28730 unsigned int i
, nelt
= GET_MODE_NUNITS (vmode
);
28731 bool one_vector_p
= rtx_equal_p (op0
, op1
);
28732 rtx rmask
[MAX_VECT_LEN
], mask
;
28734 /* TODO: ARM's VTBL indexing is little-endian. In order to handle GCC's
28735 numbering of elements for big-endian, we must reverse the order. */
28736 gcc_checking_assert (!BYTES_BIG_ENDIAN
);
28738 /* The VTBL instruction does not use a modulo index, so we must take care
28739 of that ourselves. */
28740 mask
= GEN_INT (one_vector_p
? nelt
- 1 : 2 * nelt
- 1);
28741 for (i
= 0; i
< nelt
; ++i
)
28743 mask
= gen_rtx_CONST_VECTOR (vmode
, gen_rtvec_v (nelt
, rmask
));
28744 sel
= expand_simple_binop (vmode
, AND
, sel
, mask
, NULL
, 0, OPTAB_LIB_WIDEN
);
28746 arm_expand_vec_perm_1 (target
, op0
, op1
, sel
);
28749 /* Map lane ordering between architectural lane order, and GCC lane order,
28750 taking into account ABI. See comment above output_move_neon for details. */
28753 neon_endian_lane_map (machine_mode mode
, int lane
)
28755 if (BYTES_BIG_ENDIAN
)
28757 int nelems
= GET_MODE_NUNITS (mode
);
28758 /* Reverse lane order. */
28759 lane
= (nelems
- 1 - lane
);
28760 /* Reverse D register order, to match ABI. */
28761 if (GET_MODE_SIZE (mode
) == 16)
28762 lane
= lane
^ (nelems
/ 2);
28767 /* Some permutations index into pairs of vectors, this is a helper function
28768 to map indexes into those pairs of vectors. */
28771 neon_pair_endian_lane_map (machine_mode mode
, int lane
)
28773 int nelem
= GET_MODE_NUNITS (mode
);
28774 if (BYTES_BIG_ENDIAN
)
28776 neon_endian_lane_map (mode
, lane
& (nelem
- 1)) + (lane
& nelem
);
28780 /* Generate or test for an insn that supports a constant permutation. */
28782 /* Recognize patterns for the VUZP insns. */
28785 arm_evpc_neon_vuzp (struct expand_vec_perm_d
*d
)
28787 unsigned int i
, odd
, mask
, nelt
= d
->perm
.length ();
28788 rtx out0
, out1
, in0
, in1
;
28789 rtx (*gen
)(rtx
, rtx
, rtx
, rtx
);
28793 if (GET_MODE_UNIT_SIZE (d
->vmode
) >= 8)
28796 /* arm_expand_vec_perm_const_1 () helpfully swaps the operands for the
28797 big endian pattern on 64 bit vectors, so we correct for that. */
28798 swap_nelt
= BYTES_BIG_ENDIAN
&& !d
->one_vector_p
28799 && GET_MODE_SIZE (d
->vmode
) == 8 ? nelt
: 0;
28801 first_elem
= d
->perm
[neon_endian_lane_map (d
->vmode
, 0)] ^ swap_nelt
;
28803 if (first_elem
== neon_endian_lane_map (d
->vmode
, 0))
28805 else if (first_elem
== neon_endian_lane_map (d
->vmode
, 1))
28809 mask
= (d
->one_vector_p
? nelt
- 1 : 2 * nelt
- 1);
28811 for (i
= 0; i
< nelt
; i
++)
28814 (neon_pair_endian_lane_map (d
->vmode
, i
) * 2 + odd
) & mask
;
28815 if ((d
->perm
[i
] ^ swap_nelt
) != neon_pair_endian_lane_map (d
->vmode
, elt
))
28825 case E_V16QImode
: gen
= gen_neon_vuzpv16qi_internal
; break;
28826 case E_V8QImode
: gen
= gen_neon_vuzpv8qi_internal
; break;
28827 case E_V8HImode
: gen
= gen_neon_vuzpv8hi_internal
; break;
28828 case E_V4HImode
: gen
= gen_neon_vuzpv4hi_internal
; break;
28829 case E_V8HFmode
: gen
= gen_neon_vuzpv8hf_internal
; break;
28830 case E_V4HFmode
: gen
= gen_neon_vuzpv4hf_internal
; break;
28831 case E_V4SImode
: gen
= gen_neon_vuzpv4si_internal
; break;
28832 case E_V2SImode
: gen
= gen_neon_vuzpv2si_internal
; break;
28833 case E_V2SFmode
: gen
= gen_neon_vuzpv2sf_internal
; break;
28834 case E_V4SFmode
: gen
= gen_neon_vuzpv4sf_internal
; break;
28836 gcc_unreachable ();
28841 if (swap_nelt
!= 0)
28842 std::swap (in0
, in1
);
28845 out1
= gen_reg_rtx (d
->vmode
);
28847 std::swap (out0
, out1
);
28849 emit_insn (gen (out0
, in0
, in1
, out1
));
28853 /* Recognize patterns for the VZIP insns. */
28856 arm_evpc_neon_vzip (struct expand_vec_perm_d
*d
)
28858 unsigned int i
, high
, mask
, nelt
= d
->perm
.length ();
28859 rtx out0
, out1
, in0
, in1
;
28860 rtx (*gen
)(rtx
, rtx
, rtx
, rtx
);
28864 if (GET_MODE_UNIT_SIZE (d
->vmode
) >= 8)
28867 is_swapped
= BYTES_BIG_ENDIAN
;
28869 first_elem
= d
->perm
[neon_endian_lane_map (d
->vmode
, 0) ^ is_swapped
];
28872 if (first_elem
== neon_endian_lane_map (d
->vmode
, high
))
28874 else if (first_elem
== neon_endian_lane_map (d
->vmode
, 0))
28878 mask
= (d
->one_vector_p
? nelt
- 1 : 2 * nelt
- 1);
28880 for (i
= 0; i
< nelt
/ 2; i
++)
28883 neon_pair_endian_lane_map (d
->vmode
, i
+ high
) & mask
;
28884 if (d
->perm
[neon_pair_endian_lane_map (d
->vmode
, 2 * i
+ is_swapped
)]
28888 neon_pair_endian_lane_map (d
->vmode
, i
+ nelt
+ high
) & mask
;
28889 if (d
->perm
[neon_pair_endian_lane_map (d
->vmode
, 2 * i
+ !is_swapped
)]
28900 case E_V16QImode
: gen
= gen_neon_vzipv16qi_internal
; break;
28901 case E_V8QImode
: gen
= gen_neon_vzipv8qi_internal
; break;
28902 case E_V8HImode
: gen
= gen_neon_vzipv8hi_internal
; break;
28903 case E_V4HImode
: gen
= gen_neon_vzipv4hi_internal
; break;
28904 case E_V8HFmode
: gen
= gen_neon_vzipv8hf_internal
; break;
28905 case E_V4HFmode
: gen
= gen_neon_vzipv4hf_internal
; break;
28906 case E_V4SImode
: gen
= gen_neon_vzipv4si_internal
; break;
28907 case E_V2SImode
: gen
= gen_neon_vzipv2si_internal
; break;
28908 case E_V2SFmode
: gen
= gen_neon_vzipv2sf_internal
; break;
28909 case E_V4SFmode
: gen
= gen_neon_vzipv4sf_internal
; break;
28911 gcc_unreachable ();
28917 std::swap (in0
, in1
);
28920 out1
= gen_reg_rtx (d
->vmode
);
28922 std::swap (out0
, out1
);
28924 emit_insn (gen (out0
, in0
, in1
, out1
));
28928 /* Recognize patterns for the VREV insns. */
28931 arm_evpc_neon_vrev (struct expand_vec_perm_d
*d
)
28933 unsigned int i
, j
, diff
, nelt
= d
->perm
.length ();
28934 rtx (*gen
)(rtx
, rtx
);
28936 if (!d
->one_vector_p
)
28945 case E_V16QImode
: gen
= gen_neon_vrev64v16qi
; break;
28946 case E_V8QImode
: gen
= gen_neon_vrev64v8qi
; break;
28954 case E_V16QImode
: gen
= gen_neon_vrev32v16qi
; break;
28955 case E_V8QImode
: gen
= gen_neon_vrev32v8qi
; break;
28956 case E_V8HImode
: gen
= gen_neon_vrev64v8hi
; break;
28957 case E_V4HImode
: gen
= gen_neon_vrev64v4hi
; break;
28958 case E_V8HFmode
: gen
= gen_neon_vrev64v8hf
; break;
28959 case E_V4HFmode
: gen
= gen_neon_vrev64v4hf
; break;
28967 case E_V16QImode
: gen
= gen_neon_vrev16v16qi
; break;
28968 case E_V8QImode
: gen
= gen_neon_vrev16v8qi
; break;
28969 case E_V8HImode
: gen
= gen_neon_vrev32v8hi
; break;
28970 case E_V4HImode
: gen
= gen_neon_vrev32v4hi
; break;
28971 case E_V4SImode
: gen
= gen_neon_vrev64v4si
; break;
28972 case E_V2SImode
: gen
= gen_neon_vrev64v2si
; break;
28973 case E_V4SFmode
: gen
= gen_neon_vrev64v4sf
; break;
28974 case E_V2SFmode
: gen
= gen_neon_vrev64v2sf
; break;
28983 for (i
= 0; i
< nelt
; i
+= diff
+ 1)
28984 for (j
= 0; j
<= diff
; j
+= 1)
28986 /* This is guaranteed to be true as the value of diff
28987 is 7, 3, 1 and we should have enough elements in the
28988 queue to generate this. Getting a vector mask with a
28989 value of diff other than these values implies that
28990 something is wrong by the time we get here. */
28991 gcc_assert (i
+ j
< nelt
);
28992 if (d
->perm
[i
+ j
] != i
+ diff
- j
)
29000 emit_insn (gen (d
->target
, d
->op0
));
29004 /* Recognize patterns for the VTRN insns. */
29007 arm_evpc_neon_vtrn (struct expand_vec_perm_d
*d
)
29009 unsigned int i
, odd
, mask
, nelt
= d
->perm
.length ();
29010 rtx out0
, out1
, in0
, in1
;
29011 rtx (*gen
)(rtx
, rtx
, rtx
, rtx
);
29013 if (GET_MODE_UNIT_SIZE (d
->vmode
) >= 8)
29016 /* Note that these are little-endian tests. Adjust for big-endian later. */
29017 if (d
->perm
[0] == 0)
29019 else if (d
->perm
[0] == 1)
29023 mask
= (d
->one_vector_p
? nelt
- 1 : 2 * nelt
- 1);
29025 for (i
= 0; i
< nelt
; i
+= 2)
29027 if (d
->perm
[i
] != i
+ odd
)
29029 if (d
->perm
[i
+ 1] != ((i
+ nelt
+ odd
) & mask
))
29039 case E_V16QImode
: gen
= gen_neon_vtrnv16qi_internal
; break;
29040 case E_V8QImode
: gen
= gen_neon_vtrnv8qi_internal
; break;
29041 case E_V8HImode
: gen
= gen_neon_vtrnv8hi_internal
; break;
29042 case E_V4HImode
: gen
= gen_neon_vtrnv4hi_internal
; break;
29043 case E_V8HFmode
: gen
= gen_neon_vtrnv8hf_internal
; break;
29044 case E_V4HFmode
: gen
= gen_neon_vtrnv4hf_internal
; break;
29045 case E_V4SImode
: gen
= gen_neon_vtrnv4si_internal
; break;
29046 case E_V2SImode
: gen
= gen_neon_vtrnv2si_internal
; break;
29047 case E_V2SFmode
: gen
= gen_neon_vtrnv2sf_internal
; break;
29048 case E_V4SFmode
: gen
= gen_neon_vtrnv4sf_internal
; break;
29050 gcc_unreachable ();
29055 if (BYTES_BIG_ENDIAN
)
29057 std::swap (in0
, in1
);
29062 out1
= gen_reg_rtx (d
->vmode
);
29064 std::swap (out0
, out1
);
29066 emit_insn (gen (out0
, in0
, in1
, out1
));
29070 /* Recognize patterns for the VEXT insns. */
29073 arm_evpc_neon_vext (struct expand_vec_perm_d
*d
)
29075 unsigned int i
, nelt
= d
->perm
.length ();
29076 rtx (*gen
) (rtx
, rtx
, rtx
, rtx
);
29079 unsigned int location
;
29081 unsigned int next
= d
->perm
[0] + 1;
29083 /* TODO: Handle GCC's numbering of elements for big-endian. */
29084 if (BYTES_BIG_ENDIAN
)
29087 /* Check if the extracted indexes are increasing by one. */
29088 for (i
= 1; i
< nelt
; next
++, i
++)
29090 /* If we hit the most significant element of the 2nd vector in
29091 the previous iteration, no need to test further. */
29092 if (next
== 2 * nelt
)
29095 /* If we are operating on only one vector: it could be a
29096 rotation. If there are only two elements of size < 64, let
29097 arm_evpc_neon_vrev catch it. */
29098 if (d
->one_vector_p
&& (next
== nelt
))
29100 if ((nelt
== 2) && (d
->vmode
!= V2DImode
))
29106 if (d
->perm
[i
] != next
)
29110 location
= d
->perm
[0];
29114 case E_V16QImode
: gen
= gen_neon_vextv16qi
; break;
29115 case E_V8QImode
: gen
= gen_neon_vextv8qi
; break;
29116 case E_V4HImode
: gen
= gen_neon_vextv4hi
; break;
29117 case E_V8HImode
: gen
= gen_neon_vextv8hi
; break;
29118 case E_V2SImode
: gen
= gen_neon_vextv2si
; break;
29119 case E_V4SImode
: gen
= gen_neon_vextv4si
; break;
29120 case E_V4HFmode
: gen
= gen_neon_vextv4hf
; break;
29121 case E_V8HFmode
: gen
= gen_neon_vextv8hf
; break;
29122 case E_V2SFmode
: gen
= gen_neon_vextv2sf
; break;
29123 case E_V4SFmode
: gen
= gen_neon_vextv4sf
; break;
29124 case E_V2DImode
: gen
= gen_neon_vextv2di
; break;
29133 offset
= GEN_INT (location
);
29134 emit_insn (gen (d
->target
, d
->op0
, d
->op1
, offset
));
29138 /* The NEON VTBL instruction is a fully variable permuation that's even
29139 stronger than what we expose via VEC_PERM_EXPR. What it doesn't do
29140 is mask the index operand as VEC_PERM_EXPR requires. Therefore we
29141 can do slightly better by expanding this as a constant where we don't
29142 have to apply a mask. */
29145 arm_evpc_neon_vtbl (struct expand_vec_perm_d
*d
)
29147 rtx rperm
[MAX_VECT_LEN
], sel
;
29148 machine_mode vmode
= d
->vmode
;
29149 unsigned int i
, nelt
= d
->perm
.length ();
29151 /* TODO: ARM's VTBL indexing is little-endian. In order to handle GCC's
29152 numbering of elements for big-endian, we must reverse the order. */
29153 if (BYTES_BIG_ENDIAN
)
29159 /* Generic code will try constant permutation twice. Once with the
29160 original mode and again with the elements lowered to QImode.
29161 So wait and don't do the selector expansion ourselves. */
29162 if (vmode
!= V8QImode
&& vmode
!= V16QImode
)
29165 for (i
= 0; i
< nelt
; ++i
)
29166 rperm
[i
] = GEN_INT (d
->perm
[i
]);
29167 sel
= gen_rtx_CONST_VECTOR (vmode
, gen_rtvec_v (nelt
, rperm
));
29168 sel
= force_reg (vmode
, sel
);
29170 arm_expand_vec_perm_1 (d
->target
, d
->op0
, d
->op1
, sel
);
29175 arm_expand_vec_perm_const_1 (struct expand_vec_perm_d
*d
)
29177 /* Check if the input mask matches vext before reordering the
29180 if (arm_evpc_neon_vext (d
))
29183 /* The pattern matching functions above are written to look for a small
29184 number to begin the sequence (0, 1, N/2). If we begin with an index
29185 from the second operand, we can swap the operands. */
29186 unsigned int nelt
= d
->perm
.length ();
29187 if (d
->perm
[0] >= nelt
)
29189 for (unsigned int i
= 0; i
< nelt
; ++i
)
29190 d
->perm
[i
] = (d
->perm
[i
] + nelt
) & (2 * nelt
- 1);
29192 std::swap (d
->op0
, d
->op1
);
29197 if (arm_evpc_neon_vuzp (d
))
29199 if (arm_evpc_neon_vzip (d
))
29201 if (arm_evpc_neon_vrev (d
))
29203 if (arm_evpc_neon_vtrn (d
))
29205 return arm_evpc_neon_vtbl (d
);
29210 /* Expand a vec_perm_const pattern. */
29213 arm_expand_vec_perm_const (rtx target
, rtx op0
, rtx op1
, rtx sel
)
29215 struct expand_vec_perm_d d
;
29216 int i
, nelt
, which
;
29222 d
.vmode
= GET_MODE (target
);
29223 gcc_assert (VECTOR_MODE_P (d
.vmode
));
29224 d
.testing_p
= false;
29226 nelt
= GET_MODE_NUNITS (d
.vmode
);
29227 d
.perm
.reserve (nelt
);
29228 for (i
= which
= 0; i
< nelt
; ++i
)
29230 rtx e
= XVECEXP (sel
, 0, i
);
29231 int ei
= INTVAL (e
) & (2 * nelt
- 1);
29232 which
|= (ei
< nelt
? 1 : 2);
29233 d
.perm
.quick_push (ei
);
29242 d
.one_vector_p
= false;
29243 if (!rtx_equal_p (op0
, op1
))
29246 /* The elements of PERM do not suggest that only the first operand
29247 is used, but both operands are identical. Allow easier matching
29248 of the permutation by folding the permutation into the single
29252 for (i
= 0; i
< nelt
; ++i
)
29253 d
.perm
[i
] &= nelt
- 1;
29255 d
.one_vector_p
= true;
29260 d
.one_vector_p
= true;
29264 return arm_expand_vec_perm_const_1 (&d
);
29267 /* Implement TARGET_VECTORIZE_VEC_PERM_CONST_OK. */
29270 arm_vectorize_vec_perm_const_ok (machine_mode vmode
, vec_perm_indices sel
)
29272 struct expand_vec_perm_d d
;
29273 unsigned int i
, nelt
, which
;
29277 d
.testing_p
= true;
29278 d
.perm
.safe_splice (sel
);
29280 /* Categorize the set of elements in the selector. */
29281 nelt
= GET_MODE_NUNITS (d
.vmode
);
29282 for (i
= which
= 0; i
< nelt
; ++i
)
29284 unsigned int e
= d
.perm
[i
];
29285 gcc_assert (e
< 2 * nelt
);
29286 which
|= (e
< nelt
? 1 : 2);
29289 /* For all elements from second vector, fold the elements to first. */
29291 for (i
= 0; i
< nelt
; ++i
)
29294 /* Check whether the mask can be applied to the vector type. */
29295 d
.one_vector_p
= (which
!= 3);
29297 d
.target
= gen_raw_REG (d
.vmode
, LAST_VIRTUAL_REGISTER
+ 1);
29298 d
.op1
= d
.op0
= gen_raw_REG (d
.vmode
, LAST_VIRTUAL_REGISTER
+ 2);
29299 if (!d
.one_vector_p
)
29300 d
.op1
= gen_raw_REG (d
.vmode
, LAST_VIRTUAL_REGISTER
+ 3);
29303 ret
= arm_expand_vec_perm_const_1 (&d
);
29310 arm_autoinc_modes_ok_p (machine_mode mode
, enum arm_auto_incmodes code
)
29312 /* If we are soft float and we do not have ldrd
29313 then all auto increment forms are ok. */
29314 if (TARGET_SOFT_FLOAT
&& (TARGET_LDRD
|| GET_MODE_SIZE (mode
) <= 4))
29319 /* Post increment and Pre Decrement are supported for all
29320 instruction forms except for vector forms. */
29323 if (VECTOR_MODE_P (mode
))
29325 if (code
!= ARM_PRE_DEC
)
29335 /* Without LDRD and mode size greater than
29336 word size, there is no point in auto-incrementing
29337 because ldm and stm will not have these forms. */
29338 if (!TARGET_LDRD
&& GET_MODE_SIZE (mode
) > 4)
29341 /* Vector and floating point modes do not support
29342 these auto increment forms. */
29343 if (FLOAT_MODE_P (mode
) || VECTOR_MODE_P (mode
))
29356 /* The default expansion of general 64-bit shifts in core-regs is suboptimal,
29357 on ARM, since we know that shifts by negative amounts are no-ops.
29358 Additionally, the default expansion code is not available or suitable
29359 for post-reload insn splits (this can occur when the register allocator
29360 chooses not to do a shift in NEON).
29362 This function is used in both initial expand and post-reload splits, and
29363 handles all kinds of 64-bit shifts.
29365 Input requirements:
29366 - It is safe for the input and output to be the same register, but
29367 early-clobber rules apply for the shift amount and scratch registers.
29368 - Shift by register requires both scratch registers. In all other cases
29369 the scratch registers may be NULL.
29370 - Ashiftrt by a register also clobbers the CC register. */
29372 arm_emit_coreregs_64bit_shift (enum rtx_code code
, rtx out
, rtx in
,
29373 rtx amount
, rtx scratch1
, rtx scratch2
)
29375 rtx out_high
= gen_highpart (SImode
, out
);
29376 rtx out_low
= gen_lowpart (SImode
, out
);
29377 rtx in_high
= gen_highpart (SImode
, in
);
29378 rtx in_low
= gen_lowpart (SImode
, in
);
29381 in = the register pair containing the input value.
29382 out = the destination register pair.
29383 up = the high- or low-part of each pair.
29384 down = the opposite part to "up".
29385 In a shift, we can consider bits to shift from "up"-stream to
29386 "down"-stream, so in a left-shift "up" is the low-part and "down"
29387 is the high-part of each register pair. */
29389 rtx out_up
= code
== ASHIFT
? out_low
: out_high
;
29390 rtx out_down
= code
== ASHIFT
? out_high
: out_low
;
29391 rtx in_up
= code
== ASHIFT
? in_low
: in_high
;
29392 rtx in_down
= code
== ASHIFT
? in_high
: in_low
;
29394 gcc_assert (code
== ASHIFT
|| code
== ASHIFTRT
|| code
== LSHIFTRT
);
29396 && (REG_P (out
) || GET_CODE (out
) == SUBREG
)
29397 && GET_MODE (out
) == DImode
);
29399 && (REG_P (in
) || GET_CODE (in
) == SUBREG
)
29400 && GET_MODE (in
) == DImode
);
29402 && (((REG_P (amount
) || GET_CODE (amount
) == SUBREG
)
29403 && GET_MODE (amount
) == SImode
)
29404 || CONST_INT_P (amount
)));
29405 gcc_assert (scratch1
== NULL
29406 || (GET_CODE (scratch1
) == SCRATCH
)
29407 || (GET_MODE (scratch1
) == SImode
29408 && REG_P (scratch1
)));
29409 gcc_assert (scratch2
== NULL
29410 || (GET_CODE (scratch2
) == SCRATCH
)
29411 || (GET_MODE (scratch2
) == SImode
29412 && REG_P (scratch2
)));
29413 gcc_assert (!REG_P (out
) || !REG_P (amount
)
29414 || !HARD_REGISTER_P (out
)
29415 || (REGNO (out
) != REGNO (amount
)
29416 && REGNO (out
) + 1 != REGNO (amount
)));
29418 /* Macros to make following code more readable. */
29419 #define SUB_32(DEST,SRC) \
29420 gen_addsi3 ((DEST), (SRC), GEN_INT (-32))
29421 #define RSB_32(DEST,SRC) \
29422 gen_subsi3 ((DEST), GEN_INT (32), (SRC))
29423 #define SUB_S_32(DEST,SRC) \
29424 gen_addsi3_compare0 ((DEST), (SRC), \
29426 #define SET(DEST,SRC) \
29427 gen_rtx_SET ((DEST), (SRC))
29428 #define SHIFT(CODE,SRC,AMOUNT) \
29429 gen_rtx_fmt_ee ((CODE), SImode, (SRC), (AMOUNT))
29430 #define LSHIFT(CODE,SRC,AMOUNT) \
29431 gen_rtx_fmt_ee ((CODE) == ASHIFT ? ASHIFT : LSHIFTRT, \
29432 SImode, (SRC), (AMOUNT))
29433 #define REV_LSHIFT(CODE,SRC,AMOUNT) \
29434 gen_rtx_fmt_ee ((CODE) == ASHIFT ? LSHIFTRT : ASHIFT, \
29435 SImode, (SRC), (AMOUNT))
29437 gen_rtx_IOR (SImode, (A), (B))
29438 #define BRANCH(COND,LABEL) \
29439 gen_arm_cond_branch ((LABEL), \
29440 gen_rtx_ ## COND (CCmode, cc_reg, \
29444 /* Shifts by register and shifts by constant are handled separately. */
29445 if (CONST_INT_P (amount
))
29447 /* We have a shift-by-constant. */
29449 /* First, handle out-of-range shift amounts.
29450 In both cases we try to match the result an ARM instruction in a
29451 shift-by-register would give. This helps reduce execution
29452 differences between optimization levels, but it won't stop other
29453 parts of the compiler doing different things. This is "undefined
29454 behavior, in any case. */
29455 if (INTVAL (amount
) <= 0)
29456 emit_insn (gen_movdi (out
, in
));
29457 else if (INTVAL (amount
) >= 64)
29459 if (code
== ASHIFTRT
)
29461 rtx const31_rtx
= GEN_INT (31);
29462 emit_insn (SET (out_down
, SHIFT (code
, in_up
, const31_rtx
)));
29463 emit_insn (SET (out_up
, SHIFT (code
, in_up
, const31_rtx
)));
29466 emit_insn (gen_movdi (out
, const0_rtx
));
29469 /* Now handle valid shifts. */
29470 else if (INTVAL (amount
) < 32)
29472 /* Shifts by a constant less than 32. */
29473 rtx reverse_amount
= GEN_INT (32 - INTVAL (amount
));
29475 /* Clearing the out register in DImode first avoids lots
29476 of spilling and results in less stack usage.
29477 Later this redundant insn is completely removed.
29478 Do that only if "in" and "out" are different registers. */
29479 if (REG_P (out
) && REG_P (in
) && REGNO (out
) != REGNO (in
))
29480 emit_insn (SET (out
, const0_rtx
));
29481 emit_insn (SET (out_down
, LSHIFT (code
, in_down
, amount
)));
29482 emit_insn (SET (out_down
,
29483 ORR (REV_LSHIFT (code
, in_up
, reverse_amount
),
29485 emit_insn (SET (out_up
, SHIFT (code
, in_up
, amount
)));
29489 /* Shifts by a constant greater than 31. */
29490 rtx adj_amount
= GEN_INT (INTVAL (amount
) - 32);
29492 if (REG_P (out
) && REG_P (in
) && REGNO (out
) != REGNO (in
))
29493 emit_insn (SET (out
, const0_rtx
));
29494 emit_insn (SET (out_down
, SHIFT (code
, in_up
, adj_amount
)));
29495 if (code
== ASHIFTRT
)
29496 emit_insn (gen_ashrsi3 (out_up
, in_up
,
29499 emit_insn (SET (out_up
, const0_rtx
));
29504 /* We have a shift-by-register. */
29505 rtx cc_reg
= gen_rtx_REG (CC_NOOVmode
, CC_REGNUM
);
29507 /* This alternative requires the scratch registers. */
29508 gcc_assert (scratch1
&& REG_P (scratch1
));
29509 gcc_assert (scratch2
&& REG_P (scratch2
));
29511 /* We will need the values "amount-32" and "32-amount" later.
29512 Swapping them around now allows the later code to be more general. */
29516 emit_insn (SUB_32 (scratch1
, amount
));
29517 emit_insn (RSB_32 (scratch2
, amount
));
29520 emit_insn (RSB_32 (scratch1
, amount
));
29521 /* Also set CC = amount > 32. */
29522 emit_insn (SUB_S_32 (scratch2
, amount
));
29525 emit_insn (RSB_32 (scratch1
, amount
));
29526 emit_insn (SUB_32 (scratch2
, amount
));
29529 gcc_unreachable ();
29532 /* Emit code like this:
29535 out_down = in_down << amount;
29536 out_down = (in_up << (amount - 32)) | out_down;
29537 out_down = ((unsigned)in_up >> (32 - amount)) | out_down;
29538 out_up = in_up << amount;
29541 out_down = in_down >> amount;
29542 out_down = (in_up << (32 - amount)) | out_down;
29544 out_down = ((signed)in_up >> (amount - 32)) | out_down;
29545 out_up = in_up << amount;
29548 out_down = in_down >> amount;
29549 out_down = (in_up << (32 - amount)) | out_down;
29551 out_down = ((unsigned)in_up >> (amount - 32)) | out_down;
29552 out_up = in_up << amount;
29554 The ARM and Thumb2 variants are the same but implemented slightly
29555 differently. If this were only called during expand we could just
29556 use the Thumb2 case and let combine do the right thing, but this
29557 can also be called from post-reload splitters. */
29559 emit_insn (SET (out_down
, LSHIFT (code
, in_down
, amount
)));
29561 if (!TARGET_THUMB2
)
29563 /* Emit code for ARM mode. */
29564 emit_insn (SET (out_down
,
29565 ORR (SHIFT (ASHIFT
, in_up
, scratch1
), out_down
)));
29566 if (code
== ASHIFTRT
)
29568 rtx_code_label
*done_label
= gen_label_rtx ();
29569 emit_jump_insn (BRANCH (LT
, done_label
));
29570 emit_insn (SET (out_down
, ORR (SHIFT (ASHIFTRT
, in_up
, scratch2
),
29572 emit_label (done_label
);
29575 emit_insn (SET (out_down
, ORR (SHIFT (LSHIFTRT
, in_up
, scratch2
),
29580 /* Emit code for Thumb2 mode.
29581 Thumb2 can't do shift and or in one insn. */
29582 emit_insn (SET (scratch1
, SHIFT (ASHIFT
, in_up
, scratch1
)));
29583 emit_insn (gen_iorsi3 (out_down
, out_down
, scratch1
));
29585 if (code
== ASHIFTRT
)
29587 rtx_code_label
*done_label
= gen_label_rtx ();
29588 emit_jump_insn (BRANCH (LT
, done_label
));
29589 emit_insn (SET (scratch2
, SHIFT (ASHIFTRT
, in_up
, scratch2
)));
29590 emit_insn (SET (out_down
, ORR (out_down
, scratch2
)));
29591 emit_label (done_label
);
29595 emit_insn (SET (scratch2
, SHIFT (LSHIFTRT
, in_up
, scratch2
)));
29596 emit_insn (gen_iorsi3 (out_down
, out_down
, scratch2
));
29600 emit_insn (SET (out_up
, SHIFT (code
, in_up
, amount
)));
29614 /* Returns true if the pattern is a valid symbolic address, which is either a
29615 symbol_ref or (symbol_ref + addend).
29617 According to the ARM ELF ABI, the initial addend of REL-type relocations
29618 processing MOVW and MOVT instructions is formed by interpreting the 16-bit
29619 literal field of the instruction as a 16-bit signed value in the range
29620 -32768 <= A < 32768. */
29623 arm_valid_symbolic_address_p (rtx addr
)
29625 rtx xop0
, xop1
= NULL_RTX
;
29628 if (GET_CODE (tmp
) == SYMBOL_REF
|| GET_CODE (tmp
) == LABEL_REF
)
29631 /* (const (plus: symbol_ref const_int)) */
29632 if (GET_CODE (addr
) == CONST
)
29633 tmp
= XEXP (addr
, 0);
29635 if (GET_CODE (tmp
) == PLUS
)
29637 xop0
= XEXP (tmp
, 0);
29638 xop1
= XEXP (tmp
, 1);
29640 if (GET_CODE (xop0
) == SYMBOL_REF
&& CONST_INT_P (xop1
))
29641 return IN_RANGE (INTVAL (xop1
), -0x8000, 0x7fff);
29647 /* Returns true if a valid comparison operation and makes
29648 the operands in a form that is valid. */
29650 arm_validize_comparison (rtx
*comparison
, rtx
* op1
, rtx
* op2
)
29652 enum rtx_code code
= GET_CODE (*comparison
);
29654 machine_mode mode
= (GET_MODE (*op1
) == VOIDmode
)
29655 ? GET_MODE (*op2
) : GET_MODE (*op1
);
29657 gcc_assert (GET_MODE (*op1
) != VOIDmode
|| GET_MODE (*op2
) != VOIDmode
);
29659 if (code
== UNEQ
|| code
== LTGT
)
29662 code_int
= (int)code
;
29663 arm_canonicalize_comparison (&code_int
, op1
, op2
, 0);
29664 PUT_CODE (*comparison
, (enum rtx_code
)code_int
);
29669 if (!arm_add_operand (*op1
, mode
))
29670 *op1
= force_reg (mode
, *op1
);
29671 if (!arm_add_operand (*op2
, mode
))
29672 *op2
= force_reg (mode
, *op2
);
29676 if (!cmpdi_operand (*op1
, mode
))
29677 *op1
= force_reg (mode
, *op1
);
29678 if (!cmpdi_operand (*op2
, mode
))
29679 *op2
= force_reg (mode
, *op2
);
29683 if (!TARGET_VFP_FP16INST
)
29685 /* FP16 comparisons are done in SF mode. */
29687 *op1
= convert_to_mode (mode
, *op1
, 1);
29688 *op2
= convert_to_mode (mode
, *op2
, 1);
29689 /* Fall through. */
29692 if (!vfp_compare_operand (*op1
, mode
))
29693 *op1
= force_reg (mode
, *op1
);
29694 if (!vfp_compare_operand (*op2
, mode
))
29695 *op2
= force_reg (mode
, *op2
);
29705 /* Maximum number of instructions to set block of memory. */
29707 arm_block_set_max_insns (void)
29709 if (optimize_function_for_size_p (cfun
))
29712 return current_tune
->max_insns_inline_memset
;
29715 /* Return TRUE if it's profitable to set block of memory for
29716 non-vectorized case. VAL is the value to set the memory
29717 with. LENGTH is the number of bytes to set. ALIGN is the
29718 alignment of the destination memory in bytes. UNALIGNED_P
29719 is TRUE if we can only set the memory with instructions
29720 meeting alignment requirements. USE_STRD_P is TRUE if we
29721 can use strd to set the memory. */
29723 arm_block_set_non_vect_profit_p (rtx val
,
29724 unsigned HOST_WIDE_INT length
,
29725 unsigned HOST_WIDE_INT align
,
29726 bool unaligned_p
, bool use_strd_p
)
29729 /* For leftovers in bytes of 0-7, we can set the memory block using
29730 strb/strh/str with minimum instruction number. */
29731 const int leftover
[8] = {0, 1, 1, 2, 1, 2, 2, 3};
29735 num
= arm_const_inline_cost (SET
, val
);
29736 num
+= length
/ align
+ length
% align
;
29738 else if (use_strd_p
)
29740 num
= arm_const_double_inline_cost (val
);
29741 num
+= (length
>> 3) + leftover
[length
& 7];
29745 num
= arm_const_inline_cost (SET
, val
);
29746 num
+= (length
>> 2) + leftover
[length
& 3];
29749 /* We may be able to combine last pair STRH/STRB into a single STR
29750 by shifting one byte back. */
29751 if (unaligned_access
&& length
> 3 && (length
& 3) == 3)
29754 return (num
<= arm_block_set_max_insns ());
29757 /* Return TRUE if it's profitable to set block of memory for
29758 vectorized case. LENGTH is the number of bytes to set.
29759 ALIGN is the alignment of destination memory in bytes.
29760 MODE is the vector mode used to set the memory. */
29762 arm_block_set_vect_profit_p (unsigned HOST_WIDE_INT length
,
29763 unsigned HOST_WIDE_INT align
,
29767 bool unaligned_p
= ((align
& 3) != 0);
29768 unsigned int nelt
= GET_MODE_NUNITS (mode
);
29770 /* Instruction loading constant value. */
29772 /* Instructions storing the memory. */
29773 num
+= (length
+ nelt
- 1) / nelt
;
29774 /* Instructions adjusting the address expression. Only need to
29775 adjust address expression if it's 4 bytes aligned and bytes
29776 leftover can only be stored by mis-aligned store instruction. */
29777 if (!unaligned_p
&& (length
& 3) != 0)
29780 /* Store the first 16 bytes using vst1:v16qi for the aligned case. */
29781 if (!unaligned_p
&& mode
== V16QImode
)
29784 return (num
<= arm_block_set_max_insns ());
29787 /* Set a block of memory using vectorization instructions for the
29788 unaligned case. We fill the first LENGTH bytes of the memory
29789 area starting from DSTBASE with byte constant VALUE. ALIGN is
29790 the alignment requirement of memory. Return TRUE if succeeded. */
29792 arm_block_set_unaligned_vect (rtx dstbase
,
29793 unsigned HOST_WIDE_INT length
,
29794 unsigned HOST_WIDE_INT value
,
29795 unsigned HOST_WIDE_INT align
)
29797 unsigned int i
, j
, nelt_v16
, nelt_v8
, nelt_mode
;
29799 rtx val_elt
, val_vec
, reg
;
29800 rtx rval
[MAX_VECT_LEN
];
29801 rtx (*gen_func
) (rtx
, rtx
);
29803 unsigned HOST_WIDE_INT v
= value
;
29804 unsigned int offset
= 0;
29805 gcc_assert ((align
& 0x3) != 0);
29806 nelt_v8
= GET_MODE_NUNITS (V8QImode
);
29807 nelt_v16
= GET_MODE_NUNITS (V16QImode
);
29808 if (length
>= nelt_v16
)
29811 gen_func
= gen_movmisalignv16qi
;
29816 gen_func
= gen_movmisalignv8qi
;
29818 nelt_mode
= GET_MODE_NUNITS (mode
);
29819 gcc_assert (length
>= nelt_mode
);
29820 /* Skip if it isn't profitable. */
29821 if (!arm_block_set_vect_profit_p (length
, align
, mode
))
29824 dst
= copy_addr_to_reg (XEXP (dstbase
, 0));
29825 mem
= adjust_automodify_address (dstbase
, mode
, dst
, offset
);
29827 v
= sext_hwi (v
, BITS_PER_WORD
);
29828 val_elt
= GEN_INT (v
);
29829 for (j
= 0; j
< nelt_mode
; j
++)
29832 reg
= gen_reg_rtx (mode
);
29833 val_vec
= gen_rtx_CONST_VECTOR (mode
, gen_rtvec_v (nelt_mode
, rval
));
29834 /* Emit instruction loading the constant value. */
29835 emit_move_insn (reg
, val_vec
);
29837 /* Handle nelt_mode bytes in a vector. */
29838 for (i
= 0; (i
+ nelt_mode
<= length
); i
+= nelt_mode
)
29840 emit_insn ((*gen_func
) (mem
, reg
));
29841 if (i
+ 2 * nelt_mode
<= length
)
29843 emit_insn (gen_add2_insn (dst
, GEN_INT (nelt_mode
)));
29844 offset
+= nelt_mode
;
29845 mem
= adjust_automodify_address (dstbase
, mode
, dst
, offset
);
29849 /* If there are not less than nelt_v8 bytes leftover, we must be in
29851 gcc_assert ((i
+ nelt_v8
) > length
|| mode
== V16QImode
);
29853 /* Handle (8, 16) bytes leftover. */
29854 if (i
+ nelt_v8
< length
)
29856 emit_insn (gen_add2_insn (dst
, GEN_INT (length
- i
)));
29857 offset
+= length
- i
;
29858 mem
= adjust_automodify_address (dstbase
, mode
, dst
, offset
);
29860 /* We are shifting bytes back, set the alignment accordingly. */
29861 if ((length
& 1) != 0 && align
>= 2)
29862 set_mem_align (mem
, BITS_PER_UNIT
);
29864 emit_insn (gen_movmisalignv16qi (mem
, reg
));
29866 /* Handle (0, 8] bytes leftover. */
29867 else if (i
< length
&& i
+ nelt_v8
>= length
)
29869 if (mode
== V16QImode
)
29870 reg
= gen_lowpart (V8QImode
, reg
);
29872 emit_insn (gen_add2_insn (dst
, GEN_INT ((length
- i
)
29873 + (nelt_mode
- nelt_v8
))));
29874 offset
+= (length
- i
) + (nelt_mode
- nelt_v8
);
29875 mem
= adjust_automodify_address (dstbase
, V8QImode
, dst
, offset
);
29877 /* We are shifting bytes back, set the alignment accordingly. */
29878 if ((length
& 1) != 0 && align
>= 2)
29879 set_mem_align (mem
, BITS_PER_UNIT
);
29881 emit_insn (gen_movmisalignv8qi (mem
, reg
));
29887 /* Set a block of memory using vectorization instructions for the
29888 aligned case. We fill the first LENGTH bytes of the memory area
29889 starting from DSTBASE with byte constant VALUE. ALIGN is the
29890 alignment requirement of memory. Return TRUE if succeeded. */
29892 arm_block_set_aligned_vect (rtx dstbase
,
29893 unsigned HOST_WIDE_INT length
,
29894 unsigned HOST_WIDE_INT value
,
29895 unsigned HOST_WIDE_INT align
)
29897 unsigned int i
, j
, nelt_v8
, nelt_v16
, nelt_mode
;
29898 rtx dst
, addr
, mem
;
29899 rtx val_elt
, val_vec
, reg
;
29900 rtx rval
[MAX_VECT_LEN
];
29902 unsigned HOST_WIDE_INT v
= value
;
29903 unsigned int offset
= 0;
29905 gcc_assert ((align
& 0x3) == 0);
29906 nelt_v8
= GET_MODE_NUNITS (V8QImode
);
29907 nelt_v16
= GET_MODE_NUNITS (V16QImode
);
29908 if (length
>= nelt_v16
&& unaligned_access
&& !BYTES_BIG_ENDIAN
)
29913 nelt_mode
= GET_MODE_NUNITS (mode
);
29914 gcc_assert (length
>= nelt_mode
);
29915 /* Skip if it isn't profitable. */
29916 if (!arm_block_set_vect_profit_p (length
, align
, mode
))
29919 dst
= copy_addr_to_reg (XEXP (dstbase
, 0));
29921 v
= sext_hwi (v
, BITS_PER_WORD
);
29922 val_elt
= GEN_INT (v
);
29923 for (j
= 0; j
< nelt_mode
; j
++)
29926 reg
= gen_reg_rtx (mode
);
29927 val_vec
= gen_rtx_CONST_VECTOR (mode
, gen_rtvec_v (nelt_mode
, rval
));
29928 /* Emit instruction loading the constant value. */
29929 emit_move_insn (reg
, val_vec
);
29932 /* Handle first 16 bytes specially using vst1:v16qi instruction. */
29933 if (mode
== V16QImode
)
29935 mem
= adjust_automodify_address (dstbase
, mode
, dst
, offset
);
29936 emit_insn (gen_movmisalignv16qi (mem
, reg
));
29938 /* Handle (8, 16) bytes leftover using vst1:v16qi again. */
29939 if (i
+ nelt_v8
< length
&& i
+ nelt_v16
> length
)
29941 emit_insn (gen_add2_insn (dst
, GEN_INT (length
- nelt_mode
)));
29942 offset
+= length
- nelt_mode
;
29943 mem
= adjust_automodify_address (dstbase
, mode
, dst
, offset
);
29944 /* We are shifting bytes back, set the alignment accordingly. */
29945 if ((length
& 0x3) == 0)
29946 set_mem_align (mem
, BITS_PER_UNIT
* 4);
29947 else if ((length
& 0x1) == 0)
29948 set_mem_align (mem
, BITS_PER_UNIT
* 2);
29950 set_mem_align (mem
, BITS_PER_UNIT
);
29952 emit_insn (gen_movmisalignv16qi (mem
, reg
));
29955 /* Fall through for bytes leftover. */
29957 nelt_mode
= GET_MODE_NUNITS (mode
);
29958 reg
= gen_lowpart (V8QImode
, reg
);
29961 /* Handle 8 bytes in a vector. */
29962 for (; (i
+ nelt_mode
<= length
); i
+= nelt_mode
)
29964 addr
= plus_constant (Pmode
, dst
, i
);
29965 mem
= adjust_automodify_address (dstbase
, mode
, addr
, offset
+ i
);
29966 emit_move_insn (mem
, reg
);
29969 /* Handle single word leftover by shifting 4 bytes back. We can
29970 use aligned access for this case. */
29971 if (i
+ UNITS_PER_WORD
== length
)
29973 addr
= plus_constant (Pmode
, dst
, i
- UNITS_PER_WORD
);
29974 offset
+= i
- UNITS_PER_WORD
;
29975 mem
= adjust_automodify_address (dstbase
, mode
, addr
, offset
);
29976 /* We are shifting 4 bytes back, set the alignment accordingly. */
29977 if (align
> UNITS_PER_WORD
)
29978 set_mem_align (mem
, BITS_PER_UNIT
* UNITS_PER_WORD
);
29980 emit_move_insn (mem
, reg
);
29982 /* Handle (0, 4), (4, 8) bytes leftover by shifting bytes back.
29983 We have to use unaligned access for this case. */
29984 else if (i
< length
)
29986 emit_insn (gen_add2_insn (dst
, GEN_INT (length
- nelt_mode
)));
29987 offset
+= length
- nelt_mode
;
29988 mem
= adjust_automodify_address (dstbase
, mode
, dst
, offset
);
29989 /* We are shifting bytes back, set the alignment accordingly. */
29990 if ((length
& 1) == 0)
29991 set_mem_align (mem
, BITS_PER_UNIT
* 2);
29993 set_mem_align (mem
, BITS_PER_UNIT
);
29995 emit_insn (gen_movmisalignv8qi (mem
, reg
));
30001 /* Set a block of memory using plain strh/strb instructions, only
30002 using instructions allowed by ALIGN on processor. We fill the
30003 first LENGTH bytes of the memory area starting from DSTBASE
30004 with byte constant VALUE. ALIGN is the alignment requirement
30007 arm_block_set_unaligned_non_vect (rtx dstbase
,
30008 unsigned HOST_WIDE_INT length
,
30009 unsigned HOST_WIDE_INT value
,
30010 unsigned HOST_WIDE_INT align
)
30013 rtx dst
, addr
, mem
;
30014 rtx val_exp
, val_reg
, reg
;
30016 HOST_WIDE_INT v
= value
;
30018 gcc_assert (align
== 1 || align
== 2);
30021 v
|= (value
<< BITS_PER_UNIT
);
30023 v
= sext_hwi (v
, BITS_PER_WORD
);
30024 val_exp
= GEN_INT (v
);
30025 /* Skip if it isn't profitable. */
30026 if (!arm_block_set_non_vect_profit_p (val_exp
, length
,
30027 align
, true, false))
30030 dst
= copy_addr_to_reg (XEXP (dstbase
, 0));
30031 mode
= (align
== 2 ? HImode
: QImode
);
30032 val_reg
= force_reg (SImode
, val_exp
);
30033 reg
= gen_lowpart (mode
, val_reg
);
30035 for (i
= 0; (i
+ GET_MODE_SIZE (mode
) <= length
); i
+= GET_MODE_SIZE (mode
))
30037 addr
= plus_constant (Pmode
, dst
, i
);
30038 mem
= adjust_automodify_address (dstbase
, mode
, addr
, i
);
30039 emit_move_insn (mem
, reg
);
30042 /* Handle single byte leftover. */
30043 if (i
+ 1 == length
)
30045 reg
= gen_lowpart (QImode
, val_reg
);
30046 addr
= plus_constant (Pmode
, dst
, i
);
30047 mem
= adjust_automodify_address (dstbase
, QImode
, addr
, i
);
30048 emit_move_insn (mem
, reg
);
30052 gcc_assert (i
== length
);
30056 /* Set a block of memory using plain strd/str/strh/strb instructions,
30057 to permit unaligned copies on processors which support unaligned
30058 semantics for those instructions. We fill the first LENGTH bytes
30059 of the memory area starting from DSTBASE with byte constant VALUE.
30060 ALIGN is the alignment requirement of memory. */
30062 arm_block_set_aligned_non_vect (rtx dstbase
,
30063 unsigned HOST_WIDE_INT length
,
30064 unsigned HOST_WIDE_INT value
,
30065 unsigned HOST_WIDE_INT align
)
30068 rtx dst
, addr
, mem
;
30069 rtx val_exp
, val_reg
, reg
;
30070 unsigned HOST_WIDE_INT v
;
30073 use_strd_p
= (length
>= 2 * UNITS_PER_WORD
&& (align
& 3) == 0
30074 && TARGET_LDRD
&& current_tune
->prefer_ldrd_strd
);
30076 v
= (value
| (value
<< 8) | (value
<< 16) | (value
<< 24));
30077 if (length
< UNITS_PER_WORD
)
30078 v
&= (0xFFFFFFFF >> (UNITS_PER_WORD
- length
) * BITS_PER_UNIT
);
30081 v
|= (v
<< BITS_PER_WORD
);
30083 v
= sext_hwi (v
, BITS_PER_WORD
);
30085 val_exp
= GEN_INT (v
);
30086 /* Skip if it isn't profitable. */
30087 if (!arm_block_set_non_vect_profit_p (val_exp
, length
,
30088 align
, false, use_strd_p
))
30093 /* Try without strd. */
30094 v
= (v
>> BITS_PER_WORD
);
30095 v
= sext_hwi (v
, BITS_PER_WORD
);
30096 val_exp
= GEN_INT (v
);
30097 use_strd_p
= false;
30098 if (!arm_block_set_non_vect_profit_p (val_exp
, length
,
30099 align
, false, use_strd_p
))
30104 dst
= copy_addr_to_reg (XEXP (dstbase
, 0));
30105 /* Handle double words using strd if possible. */
30108 val_reg
= force_reg (DImode
, val_exp
);
30110 for (; (i
+ 8 <= length
); i
+= 8)
30112 addr
= plus_constant (Pmode
, dst
, i
);
30113 mem
= adjust_automodify_address (dstbase
, DImode
, addr
, i
);
30114 emit_move_insn (mem
, reg
);
30118 val_reg
= force_reg (SImode
, val_exp
);
30120 /* Handle words. */
30121 reg
= (use_strd_p
? gen_lowpart (SImode
, val_reg
) : val_reg
);
30122 for (; (i
+ 4 <= length
); i
+= 4)
30124 addr
= plus_constant (Pmode
, dst
, i
);
30125 mem
= adjust_automodify_address (dstbase
, SImode
, addr
, i
);
30126 if ((align
& 3) == 0)
30127 emit_move_insn (mem
, reg
);
30129 emit_insn (gen_unaligned_storesi (mem
, reg
));
30132 /* Merge last pair of STRH and STRB into a STR if possible. */
30133 if (unaligned_access
&& i
> 0 && (i
+ 3) == length
)
30135 addr
= plus_constant (Pmode
, dst
, i
- 1);
30136 mem
= adjust_automodify_address (dstbase
, SImode
, addr
, i
- 1);
30137 /* We are shifting one byte back, set the alignment accordingly. */
30138 if ((align
& 1) == 0)
30139 set_mem_align (mem
, BITS_PER_UNIT
);
30141 /* Most likely this is an unaligned access, and we can't tell at
30142 compilation time. */
30143 emit_insn (gen_unaligned_storesi (mem
, reg
));
30147 /* Handle half word leftover. */
30148 if (i
+ 2 <= length
)
30150 reg
= gen_lowpart (HImode
, val_reg
);
30151 addr
= plus_constant (Pmode
, dst
, i
);
30152 mem
= adjust_automodify_address (dstbase
, HImode
, addr
, i
);
30153 if ((align
& 1) == 0)
30154 emit_move_insn (mem
, reg
);
30156 emit_insn (gen_unaligned_storehi (mem
, reg
));
30161 /* Handle single byte leftover. */
30162 if (i
+ 1 == length
)
30164 reg
= gen_lowpart (QImode
, val_reg
);
30165 addr
= plus_constant (Pmode
, dst
, i
);
30166 mem
= adjust_automodify_address (dstbase
, QImode
, addr
, i
);
30167 emit_move_insn (mem
, reg
);
30173 /* Set a block of memory using vectorization instructions for both
30174 aligned and unaligned cases. We fill the first LENGTH bytes of
30175 the memory area starting from DSTBASE with byte constant VALUE.
30176 ALIGN is the alignment requirement of memory. */
30178 arm_block_set_vect (rtx dstbase
,
30179 unsigned HOST_WIDE_INT length
,
30180 unsigned HOST_WIDE_INT value
,
30181 unsigned HOST_WIDE_INT align
)
30183 /* Check whether we need to use unaligned store instruction. */
30184 if (((align
& 3) != 0 || (length
& 3) != 0)
30185 /* Check whether unaligned store instruction is available. */
30186 && (!unaligned_access
|| BYTES_BIG_ENDIAN
))
30189 if ((align
& 3) == 0)
30190 return arm_block_set_aligned_vect (dstbase
, length
, value
, align
);
30192 return arm_block_set_unaligned_vect (dstbase
, length
, value
, align
);
30195 /* Expand string store operation. Firstly we try to do that by using
30196 vectorization instructions, then try with ARM unaligned access and
30197 double-word store if profitable. OPERANDS[0] is the destination,
30198 OPERANDS[1] is the number of bytes, operands[2] is the value to
30199 initialize the memory, OPERANDS[3] is the known alignment of the
30202 arm_gen_setmem (rtx
*operands
)
30204 rtx dstbase
= operands
[0];
30205 unsigned HOST_WIDE_INT length
;
30206 unsigned HOST_WIDE_INT value
;
30207 unsigned HOST_WIDE_INT align
;
30209 if (!CONST_INT_P (operands
[2]) || !CONST_INT_P (operands
[1]))
30212 length
= UINTVAL (operands
[1]);
30216 value
= (UINTVAL (operands
[2]) & 0xFF);
30217 align
= UINTVAL (operands
[3]);
30218 if (TARGET_NEON
&& length
>= 8
30219 && current_tune
->string_ops_prefer_neon
30220 && arm_block_set_vect (dstbase
, length
, value
, align
))
30223 if (!unaligned_access
&& (align
& 3) != 0)
30224 return arm_block_set_unaligned_non_vect (dstbase
, length
, value
, align
);
30226 return arm_block_set_aligned_non_vect (dstbase
, length
, value
, align
);
30231 arm_macro_fusion_p (void)
30233 return current_tune
->fusible_ops
!= tune_params::FUSE_NOTHING
;
30236 /* Return true if the two back-to-back sets PREV_SET, CURR_SET are suitable
30237 for MOVW / MOVT macro fusion. */
30240 arm_sets_movw_movt_fusible_p (rtx prev_set
, rtx curr_set
)
30242 /* We are trying to fuse
30243 movw imm / movt imm
30244 instructions as a group that gets scheduled together. */
30246 rtx set_dest
= SET_DEST (curr_set
);
30248 if (GET_MODE (set_dest
) != SImode
)
30251 /* We are trying to match:
30252 prev (movw) == (set (reg r0) (const_int imm16))
30253 curr (movt) == (set (zero_extract (reg r0)
30256 (const_int imm16_1))
30258 prev (movw) == (set (reg r1)
30259 (high (symbol_ref ("SYM"))))
30260 curr (movt) == (set (reg r0)
30262 (symbol_ref ("SYM")))) */
30264 if (GET_CODE (set_dest
) == ZERO_EXTRACT
)
30266 if (CONST_INT_P (SET_SRC (curr_set
))
30267 && CONST_INT_P (SET_SRC (prev_set
))
30268 && REG_P (XEXP (set_dest
, 0))
30269 && REG_P (SET_DEST (prev_set
))
30270 && REGNO (XEXP (set_dest
, 0)) == REGNO (SET_DEST (prev_set
)))
30274 else if (GET_CODE (SET_SRC (curr_set
)) == LO_SUM
30275 && REG_P (SET_DEST (curr_set
))
30276 && REG_P (SET_DEST (prev_set
))
30277 && GET_CODE (SET_SRC (prev_set
)) == HIGH
30278 && REGNO (SET_DEST (curr_set
)) == REGNO (SET_DEST (prev_set
)))
30285 aarch_macro_fusion_pair_p (rtx_insn
* prev
, rtx_insn
* curr
)
30287 rtx prev_set
= single_set (prev
);
30288 rtx curr_set
= single_set (curr
);
30294 if (any_condjump_p (curr
))
30297 if (!arm_macro_fusion_p ())
30300 if (current_tune
->fusible_ops
& tune_params::FUSE_AES_AESMC
30301 && aarch_crypto_can_dual_issue (prev
, curr
))
30304 if (current_tune
->fusible_ops
& tune_params::FUSE_MOVW_MOVT
30305 && arm_sets_movw_movt_fusible_p (prev_set
, curr_set
))
30311 /* Return true iff the instruction fusion described by OP is enabled. */
30313 arm_fusion_enabled_p (tune_params::fuse_ops op
)
30315 return current_tune
->fusible_ops
& op
;
30318 /* Implement TARGET_SCHED_CAN_SPECULATE_INSN. Return true if INSN can be
30319 scheduled for speculative execution. Reject the long-running division
30320 and square-root instructions. */
30323 arm_sched_can_speculate_insn (rtx_insn
*insn
)
30325 switch (get_attr_type (insn
))
30333 case TYPE_NEON_FP_SQRT_S
:
30334 case TYPE_NEON_FP_SQRT_D
:
30335 case TYPE_NEON_FP_SQRT_S_Q
:
30336 case TYPE_NEON_FP_SQRT_D_Q
:
30337 case TYPE_NEON_FP_DIV_S
:
30338 case TYPE_NEON_FP_DIV_D
:
30339 case TYPE_NEON_FP_DIV_S_Q
:
30340 case TYPE_NEON_FP_DIV_D_Q
:
30347 /* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */
30349 static unsigned HOST_WIDE_INT
30350 arm_asan_shadow_offset (void)
30352 return HOST_WIDE_INT_1U
<< 29;
30356 /* This is a temporary fix for PR60655. Ideally we need
30357 to handle most of these cases in the generic part but
30358 currently we reject minus (..) (sym_ref). We try to
30359 ameliorate the case with minus (sym_ref1) (sym_ref2)
30360 where they are in the same section. */
30363 arm_const_not_ok_for_debug_p (rtx p
)
30365 tree decl_op0
= NULL
;
30366 tree decl_op1
= NULL
;
30368 if (GET_CODE (p
) == MINUS
)
30370 if (GET_CODE (XEXP (p
, 1)) == SYMBOL_REF
)
30372 decl_op1
= SYMBOL_REF_DECL (XEXP (p
, 1));
30374 && GET_CODE (XEXP (p
, 0)) == SYMBOL_REF
30375 && (decl_op0
= SYMBOL_REF_DECL (XEXP (p
, 0))))
30377 if ((VAR_P (decl_op1
)
30378 || TREE_CODE (decl_op1
) == CONST_DECL
)
30379 && (VAR_P (decl_op0
)
30380 || TREE_CODE (decl_op0
) == CONST_DECL
))
30381 return (get_variable_section (decl_op1
, false)
30382 != get_variable_section (decl_op0
, false));
30384 if (TREE_CODE (decl_op1
) == LABEL_DECL
30385 && TREE_CODE (decl_op0
) == LABEL_DECL
)
30386 return (DECL_CONTEXT (decl_op1
)
30387 != DECL_CONTEXT (decl_op0
));
30397 /* return TRUE if x is a reference to a value in a constant pool */
30399 arm_is_constant_pool_ref (rtx x
)
30402 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
30403 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)));
30406 /* Remember the last target of arm_set_current_function. */
30407 static GTY(()) tree arm_previous_fndecl
;
30409 /* Restore or save the TREE_TARGET_GLOBALS from or to NEW_TREE. */
30412 save_restore_target_globals (tree new_tree
)
30414 /* If we have a previous state, use it. */
30415 if (TREE_TARGET_GLOBALS (new_tree
))
30416 restore_target_globals (TREE_TARGET_GLOBALS (new_tree
));
30417 else if (new_tree
== target_option_default_node
)
30418 restore_target_globals (&default_target_globals
);
30421 /* Call target_reinit and save the state for TARGET_GLOBALS. */
30422 TREE_TARGET_GLOBALS (new_tree
) = save_target_globals_default_opts ();
30425 arm_option_params_internal ();
30428 /* Invalidate arm_previous_fndecl. */
30431 arm_reset_previous_fndecl (void)
30433 arm_previous_fndecl
= NULL_TREE
;
30436 /* Establish appropriate back-end context for processing the function
30437 FNDECL. The argument might be NULL to indicate processing at top
30438 level, outside of any function scope. */
30441 arm_set_current_function (tree fndecl
)
30443 if (!fndecl
|| fndecl
== arm_previous_fndecl
)
30446 tree old_tree
= (arm_previous_fndecl
30447 ? DECL_FUNCTION_SPECIFIC_TARGET (arm_previous_fndecl
)
30450 tree new_tree
= DECL_FUNCTION_SPECIFIC_TARGET (fndecl
);
30452 /* If current function has no attributes but previous one did,
30453 use the default node. */
30454 if (! new_tree
&& old_tree
)
30455 new_tree
= target_option_default_node
;
30457 /* If nothing to do return. #pragma GCC reset or #pragma GCC pop to
30458 the default have been handled by save_restore_target_globals from
30459 arm_pragma_target_parse. */
30460 if (old_tree
== new_tree
)
30463 arm_previous_fndecl
= fndecl
;
30465 /* First set the target options. */
30466 cl_target_option_restore (&global_options
, TREE_TARGET_OPTION (new_tree
));
30468 save_restore_target_globals (new_tree
);
30471 /* Implement TARGET_OPTION_PRINT. */
30474 arm_option_print (FILE *file
, int indent
, struct cl_target_option
*ptr
)
30476 int flags
= ptr
->x_target_flags
;
30477 const char *fpu_name
;
30479 fpu_name
= (ptr
->x_arm_fpu_index
== TARGET_FPU_auto
30480 ? "auto" : all_fpus
[ptr
->x_arm_fpu_index
].name
);
30482 fprintf (file
, "%*sselected isa %s\n", indent
, "",
30483 TARGET_THUMB2_P (flags
) ? "thumb2" :
30484 TARGET_THUMB_P (flags
) ? "thumb1" :
30487 if (ptr
->x_arm_arch_string
)
30488 fprintf (file
, "%*sselected architecture %s\n", indent
, "",
30489 ptr
->x_arm_arch_string
);
30491 if (ptr
->x_arm_cpu_string
)
30492 fprintf (file
, "%*sselected CPU %s\n", indent
, "",
30493 ptr
->x_arm_cpu_string
);
30495 if (ptr
->x_arm_tune_string
)
30496 fprintf (file
, "%*sselected tune %s\n", indent
, "",
30497 ptr
->x_arm_tune_string
);
30499 fprintf (file
, "%*sselected fpu %s\n", indent
, "", fpu_name
);
30502 /* Hook to determine if one function can safely inline another. */
30505 arm_can_inline_p (tree caller
, tree callee
)
30507 tree caller_tree
= DECL_FUNCTION_SPECIFIC_TARGET (caller
);
30508 tree callee_tree
= DECL_FUNCTION_SPECIFIC_TARGET (callee
);
30509 bool can_inline
= true;
30511 struct cl_target_option
*caller_opts
30512 = TREE_TARGET_OPTION (caller_tree
? caller_tree
30513 : target_option_default_node
);
30515 struct cl_target_option
*callee_opts
30516 = TREE_TARGET_OPTION (callee_tree
? callee_tree
30517 : target_option_default_node
);
30519 if (callee_opts
== caller_opts
)
30522 /* Callee's ISA features should be a subset of the caller's. */
30523 struct arm_build_target caller_target
;
30524 struct arm_build_target callee_target
;
30525 caller_target
.isa
= sbitmap_alloc (isa_num_bits
);
30526 callee_target
.isa
= sbitmap_alloc (isa_num_bits
);
30528 arm_configure_build_target (&caller_target
, caller_opts
, &global_options_set
,
30530 arm_configure_build_target (&callee_target
, callee_opts
, &global_options_set
,
30532 if (!bitmap_subset_p (callee_target
.isa
, caller_target
.isa
))
30533 can_inline
= false;
30535 sbitmap_free (caller_target
.isa
);
30536 sbitmap_free (callee_target
.isa
);
30538 /* OK to inline between different modes.
30539 Function with mode specific instructions, e.g using asm,
30540 must be explicitly protected with noinline. */
30544 /* Hook to fix function's alignment affected by target attribute. */
30547 arm_relayout_function (tree fndecl
)
30549 if (DECL_USER_ALIGN (fndecl
))
30552 tree callee_tree
= DECL_FUNCTION_SPECIFIC_TARGET (fndecl
);
30555 callee_tree
= target_option_default_node
;
30557 struct cl_target_option
*opts
= TREE_TARGET_OPTION (callee_tree
);
30560 FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY_P (opts
->x_target_flags
)));
30563 /* Inner function to process the attribute((target(...))), take an argument and
30564 set the current options from the argument. If we have a list, recursively
30565 go over the list. */
30568 arm_valid_target_attribute_rec (tree args
, struct gcc_options
*opts
)
30570 if (TREE_CODE (args
) == TREE_LIST
)
30574 for (; args
; args
= TREE_CHAIN (args
))
30575 if (TREE_VALUE (args
)
30576 && !arm_valid_target_attribute_rec (TREE_VALUE (args
), opts
))
30581 else if (TREE_CODE (args
) != STRING_CST
)
30583 error ("attribute %<target%> argument not a string");
30587 char *argstr
= ASTRDUP (TREE_STRING_POINTER (args
));
30590 while ((q
= strtok (argstr
, ",")) != NULL
)
30592 while (ISSPACE (*q
)) ++q
;
30595 if (!strncmp (q
, "thumb", 5))
30596 opts
->x_target_flags
|= MASK_THUMB
;
30598 else if (!strncmp (q
, "arm", 3))
30599 opts
->x_target_flags
&= ~MASK_THUMB
;
30601 else if (!strncmp (q
, "fpu=", 4))
30604 if (! opt_enum_arg_to_value (OPT_mfpu_
, q
+4,
30605 &fpu_index
, CL_TARGET
))
30607 error ("invalid fpu for attribute(target(\"%s\"))", q
);
30610 if (fpu_index
== TARGET_FPU_auto
)
30612 /* This doesn't really make sense until we support
30613 general dynamic selection of the architecture and all
30615 sorry ("auto fpu selection not currently permitted here");
30618 opts
->x_arm_fpu_index
= (enum fpu_type
) fpu_index
;
30622 error ("attribute(target(\"%s\")) is unknown", q
);
30630 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL. */
30633 arm_valid_target_attribute_tree (tree args
, struct gcc_options
*opts
,
30634 struct gcc_options
*opts_set
)
30636 struct cl_target_option cl_opts
;
30638 if (!arm_valid_target_attribute_rec (args
, opts
))
30641 cl_target_option_save (&cl_opts
, opts
);
30642 arm_configure_build_target (&arm_active_target
, &cl_opts
, opts_set
, false);
30643 arm_option_check_internal (opts
);
30644 /* Do any overrides, such as global options arch=xxx. */
30645 arm_option_override_internal (opts
, opts_set
);
30647 return build_target_option_node (opts
);
30651 add_attribute (const char * mode
, tree
*attributes
)
30653 size_t len
= strlen (mode
);
30654 tree value
= build_string (len
, mode
);
30656 TREE_TYPE (value
) = build_array_type (char_type_node
,
30657 build_index_type (size_int (len
)));
30659 *attributes
= tree_cons (get_identifier ("target"),
30660 build_tree_list (NULL_TREE
, value
),
30664 /* For testing. Insert thumb or arm modes alternatively on functions. */
30667 arm_insert_attributes (tree fndecl
, tree
* attributes
)
30671 if (! TARGET_FLIP_THUMB
)
30674 if (TREE_CODE (fndecl
) != FUNCTION_DECL
|| DECL_EXTERNAL(fndecl
)
30675 || DECL_BUILT_IN (fndecl
) || DECL_ARTIFICIAL (fndecl
))
30678 /* Nested definitions must inherit mode. */
30679 if (current_function_decl
)
30681 mode
= TARGET_THUMB
? "thumb" : "arm";
30682 add_attribute (mode
, attributes
);
30686 /* If there is already a setting don't change it. */
30687 if (lookup_attribute ("target", *attributes
) != NULL
)
30690 mode
= thumb_flipper
? "thumb" : "arm";
30691 add_attribute (mode
, attributes
);
30693 thumb_flipper
= !thumb_flipper
;
30696 /* Hook to validate attribute((target("string"))). */
30699 arm_valid_target_attribute_p (tree fndecl
, tree
ARG_UNUSED (name
),
30700 tree args
, int ARG_UNUSED (flags
))
30703 struct gcc_options func_options
;
30704 tree cur_tree
, new_optimize
;
30705 gcc_assert ((fndecl
!= NULL_TREE
) && (args
!= NULL_TREE
));
30707 /* Get the optimization options of the current function. */
30708 tree func_optimize
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl
);
30710 /* If the function changed the optimization levels as well as setting target
30711 options, start with the optimizations specified. */
30712 if (!func_optimize
)
30713 func_optimize
= optimization_default_node
;
30715 /* Init func_options. */
30716 memset (&func_options
, 0, sizeof (func_options
));
30717 init_options_struct (&func_options
, NULL
);
30718 lang_hooks
.init_options_struct (&func_options
);
30720 /* Initialize func_options to the defaults. */
30721 cl_optimization_restore (&func_options
,
30722 TREE_OPTIMIZATION (func_optimize
));
30724 cl_target_option_restore (&func_options
,
30725 TREE_TARGET_OPTION (target_option_default_node
));
30727 /* Set func_options flags with new target mode. */
30728 cur_tree
= arm_valid_target_attribute_tree (args
, &func_options
,
30729 &global_options_set
);
30731 if (cur_tree
== NULL_TREE
)
30734 new_optimize
= build_optimization_node (&func_options
);
30736 DECL_FUNCTION_SPECIFIC_TARGET (fndecl
) = cur_tree
;
30738 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl
) = new_optimize
;
30740 finalize_options_struct (&func_options
);
30745 /* Match an ISA feature bitmap to a named FPU. We always use the
30746 first entry that exactly matches the feature set, so that we
30747 effectively canonicalize the FPU name for the assembler. */
30749 arm_identify_fpu_from_isa (sbitmap isa
)
30751 auto_sbitmap
fpubits (isa_num_bits
);
30752 auto_sbitmap
cand_fpubits (isa_num_bits
);
30754 bitmap_and (fpubits
, isa
, isa_all_fpubits
);
30756 /* If there are no ISA feature bits relating to the FPU, we must be
30757 doing soft-float. */
30758 if (bitmap_empty_p (fpubits
))
30761 for (unsigned int i
= 0; i
< TARGET_FPU_auto
; i
++)
30763 arm_initialize_isa (cand_fpubits
, all_fpus
[i
].isa_bits
);
30764 if (bitmap_equal_p (fpubits
, cand_fpubits
))
30765 return all_fpus
[i
].name
;
30767 /* We must find an entry, or things have gone wrong. */
30768 gcc_unreachable ();
30772 arm_declare_function_name (FILE *stream
, const char *name
, tree decl
)
30775 fprintf (stream
, "\t.syntax unified\n");
30779 if (is_called_in_ARM_mode (decl
)
30780 || (TARGET_THUMB1
&& !TARGET_THUMB1_ONLY
30781 && cfun
->is_thunk
))
30782 fprintf (stream
, "\t.code 32\n");
30783 else if (TARGET_THUMB1
)
30784 fprintf (stream
, "\t.code\t16\n\t.thumb_func\n");
30786 fprintf (stream
, "\t.thumb\n\t.thumb_func\n");
30789 fprintf (stream
, "\t.arm\n");
30791 asm_fprintf (asm_out_file
, "\t.fpu %s\n",
30794 : arm_identify_fpu_from_isa (arm_active_target
.isa
)));
30796 if (TARGET_POKE_FUNCTION_NAME
)
30797 arm_poke_function_name (stream
, (const char *) name
);
30800 /* If MEM is in the form of [base+offset], extract the two parts
30801 of address and set to BASE and OFFSET, otherwise return false
30802 after clearing BASE and OFFSET. */
30805 extract_base_offset_in_addr (rtx mem
, rtx
*base
, rtx
*offset
)
30809 gcc_assert (MEM_P (mem
));
30811 addr
= XEXP (mem
, 0);
30813 /* Strip off const from addresses like (const (addr)). */
30814 if (GET_CODE (addr
) == CONST
)
30815 addr
= XEXP (addr
, 0);
30817 if (GET_CODE (addr
) == REG
)
30820 *offset
= const0_rtx
;
30824 if (GET_CODE (addr
) == PLUS
30825 && GET_CODE (XEXP (addr
, 0)) == REG
30826 && CONST_INT_P (XEXP (addr
, 1)))
30828 *base
= XEXP (addr
, 0);
30829 *offset
= XEXP (addr
, 1);
30834 *offset
= NULL_RTX
;
30839 /* If INSN is a load or store of address in the form of [base+offset],
30840 extract the two parts and set to BASE and OFFSET. IS_LOAD is set
30841 to TRUE if it's a load. Return TRUE if INSN is such an instruction,
30842 otherwise return FALSE. */
30845 fusion_load_store (rtx_insn
*insn
, rtx
*base
, rtx
*offset
, bool *is_load
)
30849 gcc_assert (INSN_P (insn
));
30850 x
= PATTERN (insn
);
30851 if (GET_CODE (x
) != SET
)
30855 dest
= SET_DEST (x
);
30856 if (GET_CODE (src
) == REG
&& GET_CODE (dest
) == MEM
)
30859 extract_base_offset_in_addr (dest
, base
, offset
);
30861 else if (GET_CODE (src
) == MEM
&& GET_CODE (dest
) == REG
)
30864 extract_base_offset_in_addr (src
, base
, offset
);
30869 return (*base
!= NULL_RTX
&& *offset
!= NULL_RTX
);
30872 /* Implement the TARGET_SCHED_FUSION_PRIORITY hook.
30874 Currently we only support to fuse ldr or str instructions, so FUSION_PRI
30875 and PRI are only calculated for these instructions. For other instruction,
30876 FUSION_PRI and PRI are simply set to MAX_PRI. In the future, other kind
30877 instruction fusion can be supported by returning different priorities.
30879 It's important that irrelevant instructions get the largest FUSION_PRI. */
30882 arm_sched_fusion_priority (rtx_insn
*insn
, int max_pri
,
30883 int *fusion_pri
, int *pri
)
30889 gcc_assert (INSN_P (insn
));
30892 if (!fusion_load_store (insn
, &base
, &offset
, &is_load
))
30899 /* Load goes first. */
30901 *fusion_pri
= tmp
- 1;
30903 *fusion_pri
= tmp
- 2;
30907 /* INSN with smaller base register goes first. */
30908 tmp
-= ((REGNO (base
) & 0xff) << 20);
30910 /* INSN with smaller offset goes first. */
30911 off_val
= (int)(INTVAL (offset
));
30913 tmp
-= (off_val
& 0xfffff);
30915 tmp
+= ((- off_val
) & 0xfffff);
30922 /* Construct and return a PARALLEL RTX vector with elements numbering the
30923 lanes of either the high (HIGH == TRUE) or low (HIGH == FALSE) half of
30924 the vector - from the perspective of the architecture. This does not
30925 line up with GCC's perspective on lane numbers, so we end up with
30926 different masks depending on our target endian-ness. The diagram
30927 below may help. We must draw the distinction when building masks
30928 which select one half of the vector. An instruction selecting
30929 architectural low-lanes for a big-endian target, must be described using
30930 a mask selecting GCC high-lanes.
30932 Big-Endian Little-Endian
30934 GCC 0 1 2 3 3 2 1 0
30935 | x | x | x | x | | x | x | x | x |
30936 Architecture 3 2 1 0 3 2 1 0
30938 Low Mask: { 2, 3 } { 0, 1 }
30939 High Mask: { 0, 1 } { 2, 3 }
30943 arm_simd_vect_par_cnst_half (machine_mode mode
, bool high
)
30945 int nunits
= GET_MODE_NUNITS (mode
);
30946 rtvec v
= rtvec_alloc (nunits
/ 2);
30947 int high_base
= nunits
/ 2;
30953 if (BYTES_BIG_ENDIAN
)
30954 base
= high
? low_base
: high_base
;
30956 base
= high
? high_base
: low_base
;
30958 for (i
= 0; i
< nunits
/ 2; i
++)
30959 RTVEC_ELT (v
, i
) = GEN_INT (base
+ i
);
30961 t1
= gen_rtx_PARALLEL (mode
, v
);
30965 /* Check OP for validity as a PARALLEL RTX vector with elements
30966 numbering the lanes of either the high (HIGH == TRUE) or low lanes,
30967 from the perspective of the architecture. See the diagram above
30968 arm_simd_vect_par_cnst_half_p for more details. */
30971 arm_simd_check_vect_par_cnst_half_p (rtx op
, machine_mode mode
,
30974 rtx ideal
= arm_simd_vect_par_cnst_half (mode
, high
);
30975 HOST_WIDE_INT count_op
= XVECLEN (op
, 0);
30976 HOST_WIDE_INT count_ideal
= XVECLEN (ideal
, 0);
30979 if (!VECTOR_MODE_P (mode
))
30982 if (count_op
!= count_ideal
)
30985 for (i
= 0; i
< count_ideal
; i
++)
30987 rtx elt_op
= XVECEXP (op
, 0, i
);
30988 rtx elt_ideal
= XVECEXP (ideal
, 0, i
);
30990 if (!CONST_INT_P (elt_op
)
30991 || INTVAL (elt_ideal
) != INTVAL (elt_op
))
30997 /* Can output mi_thunk for all cases except for non-zero vcall_offset
31000 arm_can_output_mi_thunk (const_tree
, HOST_WIDE_INT
, HOST_WIDE_INT vcall_offset
,
31003 /* For now, we punt and not handle this for TARGET_THUMB1. */
31004 if (vcall_offset
&& TARGET_THUMB1
)
31007 /* Otherwise ok. */
31011 /* Generate RTL for a conditional branch with rtx comparison CODE in
31012 mode CC_MODE. The destination of the unlikely conditional branch
31016 arm_gen_unlikely_cbranch (enum rtx_code code
, machine_mode cc_mode
,
31020 x
= gen_rtx_fmt_ee (code
, VOIDmode
,
31021 gen_rtx_REG (cc_mode
, CC_REGNUM
),
31024 x
= gen_rtx_IF_THEN_ELSE (VOIDmode
, x
,
31025 gen_rtx_LABEL_REF (VOIDmode
, label_ref
),
31027 emit_unlikely_jump (gen_rtx_SET (pc_rtx
, x
));
31030 /* Implement the TARGET_ASM_ELF_FLAGS_NUMERIC hook.
31032 For pure-code sections there is no letter code for this attribute, so
31033 output all the section flags numerically when this is needed. */
31036 arm_asm_elf_flags_numeric (unsigned int flags
, unsigned int *num
)
31039 if (flags
& SECTION_ARM_PURECODE
)
31043 if (!(flags
& SECTION_DEBUG
))
31045 if (flags
& SECTION_EXCLUDE
)
31046 *num
|= 0x80000000;
31047 if (flags
& SECTION_WRITE
)
31049 if (flags
& SECTION_CODE
)
31051 if (flags
& SECTION_MERGE
)
31053 if (flags
& SECTION_STRINGS
)
31055 if (flags
& SECTION_TLS
)
31057 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
31066 /* Implement the TARGET_ASM_FUNCTION_SECTION hook.
31068 If pure-code is passed as an option, make sure all functions are in
31069 sections that have the SHF_ARM_PURECODE attribute. */
31072 arm_function_section (tree decl
, enum node_frequency freq
,
31073 bool startup
, bool exit
)
31075 const char * section_name
;
31078 if (!decl
|| TREE_CODE (decl
) != FUNCTION_DECL
)
31079 return default_function_section (decl
, freq
, startup
, exit
);
31081 if (!target_pure_code
)
31082 return default_function_section (decl
, freq
, startup
, exit
);
31085 section_name
= DECL_SECTION_NAME (decl
);
31087 /* If a function is not in a named section then it falls under the 'default'
31088 text section, also known as '.text'. We can preserve previous behavior as
31089 the default text section already has the SHF_ARM_PURECODE section
31093 section
*default_sec
= default_function_section (decl
, freq
, startup
,
31096 /* If default_sec is not null, then it must be a special section like for
31097 example .text.startup. We set the pure-code attribute and return the
31098 same section to preserve existing behavior. */
31100 default_sec
->common
.flags
|= SECTION_ARM_PURECODE
;
31101 return default_sec
;
31104 /* Otherwise look whether a section has already been created with
31106 sec
= get_named_section (decl
, section_name
, 0);
31108 /* If that is not the case passing NULL as the section's name to
31109 'get_named_section' will create a section with the declaration's
31111 sec
= get_named_section (decl
, NULL
, 0);
31113 /* Set the SHF_ARM_PURECODE attribute. */
31114 sec
->common
.flags
|= SECTION_ARM_PURECODE
;
31119 /* Implements the TARGET_SECTION_FLAGS hook.
31121 If DECL is a function declaration and pure-code is passed as an option
31122 then add the SFH_ARM_PURECODE attribute to the section flags. NAME is the
31123 section's name and RELOC indicates whether the declarations initializer may
31124 contain runtime relocations. */
31126 static unsigned int
31127 arm_elf_section_type_flags (tree decl
, const char *name
, int reloc
)
31129 unsigned int flags
= default_section_type_flags (decl
, name
, reloc
);
31131 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
&& target_pure_code
)
31132 flags
|= SECTION_ARM_PURECODE
;
31137 /* Generate call to __aeabi_[mode]divmod (op0, op1). */
31140 arm_expand_divmod_libfunc (rtx libfunc
, machine_mode mode
,
31142 rtx
*quot_p
, rtx
*rem_p
)
31144 if (mode
== SImode
)
31145 gcc_assert (!TARGET_IDIV
);
31147 scalar_int_mode libval_mode
31148 = smallest_int_mode_for_size (2 * GET_MODE_BITSIZE (mode
));
31150 rtx libval
= emit_library_call_value (libfunc
, NULL_RTX
, LCT_CONST
,
31152 op0
, GET_MODE (op0
),
31153 op1
, GET_MODE (op1
));
31155 rtx quotient
= simplify_gen_subreg (mode
, libval
, libval_mode
, 0);
31156 rtx remainder
= simplify_gen_subreg (mode
, libval
, libval_mode
,
31157 GET_MODE_SIZE (mode
));
31159 gcc_assert (quotient
);
31160 gcc_assert (remainder
);
31162 *quot_p
= quotient
;
31163 *rem_p
= remainder
;
31166 /* This function checks for the availability of the coprocessor builtin passed
31167 in BUILTIN for the current target. Returns true if it is available and
31168 false otherwise. If a BUILTIN is passed for which this function has not
31169 been implemented it will cause an exception. */
31172 arm_coproc_builtin_available (enum unspecv builtin
)
31174 /* None of these builtins are available in Thumb mode if the target only
31175 supports Thumb-1. */
31193 case VUNSPEC_LDC2L
:
31195 case VUNSPEC_STC2L
:
31198 /* Only present in ARMv5*, ARMv6 (but not ARMv6-M), ARMv7* and
31205 /* Only present in ARMv5TE, ARMv6 (but not ARMv6-M), ARMv7* and
31207 if (arm_arch6
|| arm_arch5te
)
31210 case VUNSPEC_MCRR2
:
31211 case VUNSPEC_MRRC2
:
31216 gcc_unreachable ();
31221 /* This function returns true if OP is a valid memory operand for the ldc and
31222 stc coprocessor instructions and false otherwise. */
31225 arm_coproc_ldc_stc_legitimate_address (rtx op
)
31227 HOST_WIDE_INT range
;
31228 /* Has to be a memory operand. */
31234 /* We accept registers. */
31238 switch GET_CODE (op
)
31242 /* Or registers with an offset. */
31243 if (!REG_P (XEXP (op
, 0)))
31248 /* The offset must be an immediate though. */
31249 if (!CONST_INT_P (op
))
31252 range
= INTVAL (op
);
31254 /* Within the range of [-1020,1020]. */
31255 if (!IN_RANGE (range
, -1020, 1020))
31258 /* And a multiple of 4. */
31259 return (range
% 4) == 0;
31265 return REG_P (XEXP (op
, 0));
31267 gcc_unreachable ();
31272 /* Implement TARGET_CAN_CHANGE_MODE_CLASS.
31274 In VFPv1, VFP registers could only be accessed in the mode they were
31275 set, so subregs would be invalid there. However, we don't support
31276 VFPv1 at the moment, and the restriction was lifted in VFPv2.
31278 In big-endian mode, modes greater than word size (i.e. DFmode) are stored in
31279 VFP registers in little-endian order. We can't describe that accurately to
31280 GCC, so avoid taking subregs of such values.
31282 The only exception is going from a 128-bit to a 64-bit type. In that
31283 case the data layout happens to be consistent for big-endian, so we
31284 explicitly allow that case. */
31287 arm_can_change_mode_class (machine_mode from
, machine_mode to
,
31288 reg_class_t rclass
)
31291 && !(GET_MODE_SIZE (from
) == 16 && GET_MODE_SIZE (to
) == 8)
31292 && (GET_MODE_SIZE (from
) > UNITS_PER_WORD
31293 || GET_MODE_SIZE (to
) > UNITS_PER_WORD
)
31294 && reg_classes_intersect_p (VFP_REGS
, rclass
))
31299 /* Implement TARGET_CONSTANT_ALIGNMENT. Make strings word-aligned so
31300 strcpy from constants will be faster. */
31302 static HOST_WIDE_INT
31303 arm_constant_alignment (const_tree exp
, HOST_WIDE_INT align
)
31305 unsigned int factor
= (TARGET_THUMB
|| ! arm_tune_xscale
? 1 : 2);
31306 if (TREE_CODE (exp
) == STRING_CST
&& !optimize_size
)
31307 return MAX (align
, BITS_PER_WORD
* factor
);
31312 namespace selftest
{
31314 /* Scan the static data tables generated by parsecpu.awk looking for
31315 potential issues with the data. We primarily check for
31316 inconsistencies in the option extensions at present (extensions
31317 that duplicate others but aren't marked as aliases). Furthermore,
31318 for correct canonicalization later options must never be a subset
31319 of an earlier option. Any extension should also only specify other
31320 feature bits and never an architecture bit. The architecture is inferred
31321 from the declaration of the extension. */
31323 arm_test_cpu_arch_data (void)
31325 const arch_option
*arch
;
31326 const cpu_option
*cpu
;
31327 auto_sbitmap
target_isa (isa_num_bits
);
31328 auto_sbitmap
isa1 (isa_num_bits
);
31329 auto_sbitmap
isa2 (isa_num_bits
);
31331 for (arch
= all_architectures
; arch
->common
.name
!= NULL
; ++arch
)
31333 const cpu_arch_extension
*ext1
, *ext2
;
31335 if (arch
->common
.extensions
== NULL
)
31338 arm_initialize_isa (target_isa
, arch
->common
.isa_bits
);
31340 for (ext1
= arch
->common
.extensions
; ext1
->name
!= NULL
; ++ext1
)
31345 arm_initialize_isa (isa1
, ext1
->isa_bits
);
31346 for (ext2
= ext1
+ 1; ext2
->name
!= NULL
; ++ext2
)
31348 if (ext2
->alias
|| ext1
->remove
!= ext2
->remove
)
31351 arm_initialize_isa (isa2
, ext2
->isa_bits
);
31352 /* If the option is a subset of the parent option, it doesn't
31353 add anything and so isn't useful. */
31354 ASSERT_TRUE (!bitmap_subset_p (isa2
, isa1
));
31356 /* If the extension specifies any architectural bits then
31357 disallow it. Extensions should only specify feature bits. */
31358 ASSERT_TRUE (!bitmap_intersect_p (isa2
, target_isa
));
31363 for (cpu
= all_cores
; cpu
->common
.name
!= NULL
; ++cpu
)
31365 const cpu_arch_extension
*ext1
, *ext2
;
31367 if (cpu
->common
.extensions
== NULL
)
31370 arm_initialize_isa (target_isa
, arch
->common
.isa_bits
);
31372 for (ext1
= cpu
->common
.extensions
; ext1
->name
!= NULL
; ++ext1
)
31377 arm_initialize_isa (isa1
, ext1
->isa_bits
);
31378 for (ext2
= ext1
+ 1; ext2
->name
!= NULL
; ++ext2
)
31380 if (ext2
->alias
|| ext1
->remove
!= ext2
->remove
)
31383 arm_initialize_isa (isa2
, ext2
->isa_bits
);
31384 /* If the option is a subset of the parent option, it doesn't
31385 add anything and so isn't useful. */
31386 ASSERT_TRUE (!bitmap_subset_p (isa2
, isa1
));
31388 /* If the extension specifies any architectural bits then
31389 disallow it. Extensions should only specify feature bits. */
31390 ASSERT_TRUE (!bitmap_intersect_p (isa2
, target_isa
));
31396 /* Scan the static data tables generated by parsecpu.awk looking for
31397 potential issues with the data. Here we check for consistency between the
31398 fpu bits, in particular we check that ISA_ALL_FPU_INTERNAL does not contain
31399 a feature bit that is not defined by any FPU flag. */
31401 arm_test_fpu_data (void)
31403 auto_sbitmap
isa_all_fpubits (isa_num_bits
);
31404 auto_sbitmap
fpubits (isa_num_bits
);
31405 auto_sbitmap
tmpset (isa_num_bits
);
31407 static const enum isa_feature fpu_bitlist
[]
31408 = { ISA_ALL_FPU_INTERNAL
, isa_nobit
};
31409 arm_initialize_isa (isa_all_fpubits
, fpu_bitlist
);
31411 for (unsigned int i
= 0; i
< TARGET_FPU_auto
; i
++)
31413 arm_initialize_isa (fpubits
, all_fpus
[i
].isa_bits
);
31414 bitmap_and_compl (tmpset
, isa_all_fpubits
, fpubits
);
31415 bitmap_clear (isa_all_fpubits
);
31416 bitmap_copy (isa_all_fpubits
, tmpset
);
31419 if (!bitmap_empty_p (isa_all_fpubits
))
31421 fprintf (stderr
, "Error: found feature bits in the ALL_FPU_INTERAL"
31422 " group that are not defined by any FPU.\n"
31423 " Check your arm-cpus.in.\n");
31424 ASSERT_TRUE (bitmap_empty_p (isa_all_fpubits
));
31429 arm_run_selftests (void)
31431 arm_test_cpu_arch_data ();
31432 arm_test_fpu_data ();
31434 } /* Namespace selftest. */
31436 #undef TARGET_RUN_TARGET_SELFTESTS
31437 #define TARGET_RUN_TARGET_SELFTESTS selftest::arm_run_selftests
31438 #endif /* CHECKING_P */
31440 struct gcc_target targetm
= TARGET_INITIALIZER
;
31442 #include "gt-arm.h"