1 /* Output routines for GCC for ARM.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl)
6 and Martin Simmons (@harleqn.co.uk).
7 More major hacks by Richard Earnshaw (rearnsha@arm.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published
13 by the Free Software Foundation; either version 3, or (at your
14 option) any later version.
16 GCC is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 #include "coretypes.h"
33 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "conditions.h"
37 #include "insn-attr.h"
43 #include "diagnostic-core.h"
48 #include "c-family/c-pragma.h" /* ??? */
49 #include "integrate.h"
52 #include "target-def.h"
54 #include "langhooks.h"
61 /* Forward definitions of types. */
62 typedef struct minipool_node Mnode;
63 typedef struct minipool_fixup Mfix;
65 void (*arm_lang_output_object_attributes_hook)(void);
72 /* Forward function declarations. */
73 static bool arm_needs_doubleword_align (enum machine_mode, const_tree);
74 static int arm_compute_static_chain_stack_bytes (void);
75 static arm_stack_offsets *arm_get_frame_offsets (void);
76 static void arm_add_gc_roots (void);
77 static int arm_gen_constant (enum rtx_code, enum machine_mode, rtx,
78 HOST_WIDE_INT, rtx, rtx, int, int);
79 static unsigned bit_count (unsigned long);
80 static int arm_address_register_rtx_p (rtx, int);
81 static int arm_legitimate_index_p (enum machine_mode, rtx, RTX_CODE, int);
82 static int thumb2_legitimate_index_p (enum machine_mode, rtx, int);
83 static int thumb1_base_register_rtx_p (rtx, enum machine_mode, int);
84 static rtx arm_legitimize_address (rtx, rtx, enum machine_mode);
85 static rtx thumb_legitimize_address (rtx, rtx, enum machine_mode);
86 inline static int thumb1_index_register_rtx_p (rtx, int);
87 static bool arm_legitimate_address_p (enum machine_mode, rtx, bool);
88 static int thumb_far_jump_used_p (void);
89 static bool thumb_force_lr_save (void);
90 static rtx emit_sfm (int, int);
91 static unsigned arm_size_return_regs (void);
92 static bool arm_assemble_integer (rtx, unsigned int, int);
93 static void arm_print_operand (FILE *, rtx, int);
94 static void arm_print_operand_address (FILE *, rtx);
95 static bool arm_print_operand_punct_valid_p (unsigned char code);
96 static const char *fp_const_from_val (REAL_VALUE_TYPE *);
97 static arm_cc get_arm_condition_code (rtx);
98 static HOST_WIDE_INT int_log2 (HOST_WIDE_INT);
99 static rtx is_jump_table (rtx);
100 static const char *output_multi_immediate (rtx *, const char *, const char *,
102 static const char *shift_op (rtx, HOST_WIDE_INT *);
103 static struct machine_function *arm_init_machine_status (void);
104 static void thumb_exit (FILE *, int);
105 static rtx is_jump_table (rtx);
106 static HOST_WIDE_INT get_jump_table_size (rtx);
107 static Mnode *move_minipool_fix_forward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
108 static Mnode *add_minipool_forward_ref (Mfix *);
109 static Mnode *move_minipool_fix_backward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
110 static Mnode *add_minipool_backward_ref (Mfix *);
111 static void assign_minipool_offsets (Mfix *);
112 static void arm_print_value (FILE *, rtx);
113 static void dump_minipool (rtx);
114 static int arm_barrier_cost (rtx);
115 static Mfix *create_fix_barrier (Mfix *, HOST_WIDE_INT);
116 static void push_minipool_barrier (rtx, HOST_WIDE_INT);
117 static void push_minipool_fix (rtx, HOST_WIDE_INT, rtx *, enum machine_mode,
119 static void arm_reorg (void);
120 static bool note_invalid_constants (rtx, HOST_WIDE_INT, int);
121 static unsigned long arm_compute_save_reg0_reg12_mask (void);
122 static unsigned long arm_compute_save_reg_mask (void);
123 static unsigned long arm_isr_value (tree);
124 static unsigned long arm_compute_func_type (void);
125 static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
126 static tree arm_handle_pcs_attribute (tree *, tree, tree, int, bool *);
127 static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *);
128 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
129 static tree arm_handle_notshared_attribute (tree *, tree, tree, int, bool *);
131 static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT);
132 static void arm_output_function_prologue (FILE *, HOST_WIDE_INT);
133 static int arm_comp_type_attributes (const_tree, const_tree);
134 static void arm_set_default_type_attributes (tree);
135 static int arm_adjust_cost (rtx, rtx, rtx, int);
136 static int optimal_immediate_sequence (enum rtx_code code,
137 unsigned HOST_WIDE_INT val,
138 struct four_ints *return_sequence);
139 static int optimal_immediate_sequence_1 (enum rtx_code code,
140 unsigned HOST_WIDE_INT val,
141 struct four_ints *return_sequence,
143 static int arm_get_strip_length (int);
144 static bool arm_function_ok_for_sibcall (tree, tree);
145 static enum machine_mode arm_promote_function_mode (const_tree,
146 enum machine_mode, int *,
148 static bool arm_return_in_memory (const_tree, const_tree);
149 static rtx arm_function_value (const_tree, const_tree, bool);
150 static rtx arm_libcall_value_1 (enum machine_mode);
151 static rtx arm_libcall_value (enum machine_mode, const_rtx);
152 static bool arm_function_value_regno_p (const unsigned int);
153 static void arm_internal_label (FILE *, const char *, unsigned long);
154 static void arm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
156 static bool arm_have_conditional_execution (void);
157 static bool arm_cannot_force_const_mem (enum machine_mode, rtx);
158 static bool arm_legitimate_constant_p (enum machine_mode, rtx);
159 static bool arm_rtx_costs_1 (rtx, enum rtx_code, int*, bool);
160 static bool arm_size_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *);
161 static bool arm_slowmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
162 static bool arm_fastmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
163 static bool arm_xscale_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
164 static bool arm_9e_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
165 static bool arm_rtx_costs (rtx, int, int, int, int *, bool);
166 static int arm_address_cost (rtx, bool);
167 static int arm_register_move_cost (enum machine_mode, reg_class_t, reg_class_t);
168 static int arm_memory_move_cost (enum machine_mode, reg_class_t, bool);
169 static bool arm_memory_load_p (rtx);
170 static bool arm_cirrus_insn_p (rtx);
171 static void cirrus_reorg (rtx);
172 static void arm_init_builtins (void);
173 static void arm_init_iwmmxt_builtins (void);
174 static rtx safe_vector_operand (rtx, enum machine_mode);
175 static rtx arm_expand_binop_builtin (enum insn_code, tree, rtx);
176 static rtx arm_expand_unop_builtin (enum insn_code, tree, rtx, int);
177 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
178 static tree arm_builtin_decl (unsigned, bool);
179 static void emit_constant_insn (rtx cond, rtx pattern);
180 static rtx emit_set_insn (rtx, rtx);
181 static int arm_arg_partial_bytes (cumulative_args_t, enum machine_mode,
183 static rtx arm_function_arg (cumulative_args_t, enum machine_mode,
185 static void arm_function_arg_advance (cumulative_args_t, enum machine_mode,
187 static unsigned int arm_function_arg_boundary (enum machine_mode, const_tree);
188 static rtx aapcs_allocate_return_reg (enum machine_mode, const_tree,
190 static rtx aapcs_libcall_value (enum machine_mode);
191 static int aapcs_select_return_coproc (const_tree, const_tree);
193 #ifdef OBJECT_FORMAT_ELF
194 static void arm_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED;
195 static void arm_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED;
198 static void arm_encode_section_info (tree, rtx, int);
201 static void arm_file_end (void);
202 static void arm_file_start (void);
204 static void arm_setup_incoming_varargs (cumulative_args_t, enum machine_mode,
206 static bool arm_pass_by_reference (cumulative_args_t,
207 enum machine_mode, const_tree, bool);
208 static bool arm_promote_prototypes (const_tree);
209 static bool arm_default_short_enums (void);
210 static bool arm_align_anon_bitfield (void);
211 static bool arm_return_in_msb (const_tree);
212 static bool arm_must_pass_in_stack (enum machine_mode, const_tree);
213 static bool arm_return_in_memory (const_tree, const_tree);
215 static void arm_unwind_emit (FILE *, rtx);
216 static bool arm_output_ttype (rtx);
217 static void arm_asm_emit_except_personality (rtx);
218 static void arm_asm_init_sections (void);
220 static rtx arm_dwarf_register_span (rtx);
222 static tree arm_cxx_guard_type (void);
223 static bool arm_cxx_guard_mask_bit (void);
224 static tree arm_get_cookie_size (tree);
225 static bool arm_cookie_has_size (void);
226 static bool arm_cxx_cdtor_returns_this (void);
227 static bool arm_cxx_key_method_may_be_inline (void);
228 static void arm_cxx_determine_class_data_visibility (tree);
229 static bool arm_cxx_class_data_always_comdat (void);
230 static bool arm_cxx_use_aeabi_atexit (void);
231 static void arm_init_libfuncs (void);
232 static tree arm_build_builtin_va_list (void);
233 static void arm_expand_builtin_va_start (tree, rtx);
234 static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
235 static void arm_option_override (void);
236 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode);
237 static bool arm_cannot_copy_insn_p (rtx);
238 static bool arm_tls_symbol_p (rtx x);
239 static int arm_issue_rate (void);
240 static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
241 static bool arm_output_addr_const_extra (FILE *, rtx);
242 static bool arm_allocate_stack_slots_for_args (void);
243 static const char *arm_invalid_parameter_type (const_tree t);
244 static const char *arm_invalid_return_type (const_tree t);
245 static tree arm_promoted_type (const_tree t);
246 static tree arm_convert_to_type (tree type, tree expr);
247 static bool arm_scalar_mode_supported_p (enum machine_mode);
248 static bool arm_frame_pointer_required (void);
249 static bool arm_can_eliminate (const int, const int);
250 static void arm_asm_trampoline_template (FILE *);
251 static void arm_trampoline_init (rtx, tree, rtx);
252 static rtx arm_trampoline_adjust_address (rtx);
253 static rtx arm_pic_static_addr (rtx orig, rtx reg);
254 static bool cortex_a9_sched_adjust_cost (rtx, rtx, rtx, int *);
255 static bool xscale_sched_adjust_cost (rtx, rtx, rtx, int *);
256 static bool fa726te_sched_adjust_cost (rtx, rtx, rtx, int *);
257 static bool arm_array_mode_supported_p (enum machine_mode,
258 unsigned HOST_WIDE_INT);
259 static enum machine_mode arm_preferred_simd_mode (enum machine_mode);
260 static bool arm_class_likely_spilled_p (reg_class_t);
261 static bool arm_vector_alignment_reachable (const_tree type, bool is_packed);
262 static bool arm_builtin_support_vector_misalignment (enum machine_mode mode,
266 static void arm_conditional_register_usage (void);
267 static reg_class_t arm_preferred_rename_class (reg_class_t rclass);
268 static unsigned int arm_autovectorize_vector_sizes (void);
269 static int arm_default_branch_cost (bool, bool);
270 static int arm_cortex_a5_branch_cost (bool, bool);
272 static bool arm_vectorize_vec_perm_const_ok (enum machine_mode vmode,
273 const unsigned char *sel);
276 /* Table of machine attributes. */
277 static const struct attribute_spec arm_attribute_table[] =
279 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
280 affects_type_identity } */
281 /* Function calls made to this symbol must be done indirectly, because
282 it may lie outside of the 26 bit addressing range of a normal function
284 { "long_call", 0, 0, false, true, true, NULL, false },
285 /* Whereas these functions are always known to reside within the 26 bit
287 { "short_call", 0, 0, false, true, true, NULL, false },
288 /* Specify the procedure call conventions for a function. */
289 { "pcs", 1, 1, false, true, true, arm_handle_pcs_attribute,
291 /* Interrupt Service Routines have special prologue and epilogue requirements. */
292 { "isr", 0, 1, false, false, false, arm_handle_isr_attribute,
294 { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute,
296 { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute,
299 /* ARM/PE has three new attributes:
301 dllexport - for exporting a function/variable that will live in a dll
302 dllimport - for importing a function/variable from a dll
304 Microsoft allows multiple declspecs in one __declspec, separating
305 them with spaces. We do NOT support this. Instead, use __declspec
308 { "dllimport", 0, 0, true, false, false, NULL, false },
309 { "dllexport", 0, 0, true, false, false, NULL, false },
310 { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute,
312 #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
313 { "dllimport", 0, 0, false, false, false, handle_dll_attribute, false },
314 { "dllexport", 0, 0, false, false, false, handle_dll_attribute, false },
315 { "notshared", 0, 0, false, true, false, arm_handle_notshared_attribute,
318 { NULL, 0, 0, false, false, false, NULL, false }
321 /* Initialize the GCC target structure. */
322 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
323 #undef TARGET_MERGE_DECL_ATTRIBUTES
324 #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
327 #undef TARGET_LEGITIMIZE_ADDRESS
328 #define TARGET_LEGITIMIZE_ADDRESS arm_legitimize_address
330 #undef TARGET_ATTRIBUTE_TABLE
331 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
333 #undef TARGET_ASM_FILE_START
334 #define TARGET_ASM_FILE_START arm_file_start
335 #undef TARGET_ASM_FILE_END
336 #define TARGET_ASM_FILE_END arm_file_end
338 #undef TARGET_ASM_ALIGNED_SI_OP
339 #define TARGET_ASM_ALIGNED_SI_OP NULL
340 #undef TARGET_ASM_INTEGER
341 #define TARGET_ASM_INTEGER arm_assemble_integer
343 #undef TARGET_PRINT_OPERAND
344 #define TARGET_PRINT_OPERAND arm_print_operand
345 #undef TARGET_PRINT_OPERAND_ADDRESS
346 #define TARGET_PRINT_OPERAND_ADDRESS arm_print_operand_address
347 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
348 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P arm_print_operand_punct_valid_p
350 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
351 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA arm_output_addr_const_extra
353 #undef TARGET_ASM_FUNCTION_PROLOGUE
354 #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue
356 #undef TARGET_ASM_FUNCTION_EPILOGUE
357 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
359 #undef TARGET_OPTION_OVERRIDE
360 #define TARGET_OPTION_OVERRIDE arm_option_override
362 #undef TARGET_COMP_TYPE_ATTRIBUTES
363 #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes
365 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
366 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes
368 #undef TARGET_SCHED_ADJUST_COST
369 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
371 #undef TARGET_REGISTER_MOVE_COST
372 #define TARGET_REGISTER_MOVE_COST arm_register_move_cost
374 #undef TARGET_MEMORY_MOVE_COST
375 #define TARGET_MEMORY_MOVE_COST arm_memory_move_cost
377 #undef TARGET_ENCODE_SECTION_INFO
379 #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info
381 #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info
384 #undef TARGET_STRIP_NAME_ENCODING
385 #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding
387 #undef TARGET_ASM_INTERNAL_LABEL
388 #define TARGET_ASM_INTERNAL_LABEL arm_internal_label
390 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
391 #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall
393 #undef TARGET_FUNCTION_VALUE
394 #define TARGET_FUNCTION_VALUE arm_function_value
396 #undef TARGET_LIBCALL_VALUE
397 #define TARGET_LIBCALL_VALUE arm_libcall_value
399 #undef TARGET_FUNCTION_VALUE_REGNO_P
400 #define TARGET_FUNCTION_VALUE_REGNO_P arm_function_value_regno_p
402 #undef TARGET_ASM_OUTPUT_MI_THUNK
403 #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk
404 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
405 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
407 #undef TARGET_RTX_COSTS
408 #define TARGET_RTX_COSTS arm_rtx_costs
409 #undef TARGET_ADDRESS_COST
410 #define TARGET_ADDRESS_COST arm_address_cost
412 #undef TARGET_SHIFT_TRUNCATION_MASK
413 #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask
414 #undef TARGET_VECTOR_MODE_SUPPORTED_P
415 #define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p
416 #undef TARGET_ARRAY_MODE_SUPPORTED_P
417 #define TARGET_ARRAY_MODE_SUPPORTED_P arm_array_mode_supported_p
418 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
419 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE arm_preferred_simd_mode
420 #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES
421 #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES \
422 arm_autovectorize_vector_sizes
424 #undef TARGET_MACHINE_DEPENDENT_REORG
425 #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg
427 #undef TARGET_INIT_BUILTINS
428 #define TARGET_INIT_BUILTINS arm_init_builtins
429 #undef TARGET_EXPAND_BUILTIN
430 #define TARGET_EXPAND_BUILTIN arm_expand_builtin
431 #undef TARGET_BUILTIN_DECL
432 #define TARGET_BUILTIN_DECL arm_builtin_decl
434 #undef TARGET_INIT_LIBFUNCS
435 #define TARGET_INIT_LIBFUNCS arm_init_libfuncs
437 #undef TARGET_PROMOTE_FUNCTION_MODE
438 #define TARGET_PROMOTE_FUNCTION_MODE arm_promote_function_mode
439 #undef TARGET_PROMOTE_PROTOTYPES
440 #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes
441 #undef TARGET_PASS_BY_REFERENCE
442 #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference
443 #undef TARGET_ARG_PARTIAL_BYTES
444 #define TARGET_ARG_PARTIAL_BYTES arm_arg_partial_bytes
445 #undef TARGET_FUNCTION_ARG
446 #define TARGET_FUNCTION_ARG arm_function_arg
447 #undef TARGET_FUNCTION_ARG_ADVANCE
448 #define TARGET_FUNCTION_ARG_ADVANCE arm_function_arg_advance
449 #undef TARGET_FUNCTION_ARG_BOUNDARY
450 #define TARGET_FUNCTION_ARG_BOUNDARY arm_function_arg_boundary
452 #undef TARGET_SETUP_INCOMING_VARARGS
453 #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs
455 #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
456 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args
458 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
459 #define TARGET_ASM_TRAMPOLINE_TEMPLATE arm_asm_trampoline_template
460 #undef TARGET_TRAMPOLINE_INIT
461 #define TARGET_TRAMPOLINE_INIT arm_trampoline_init
462 #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
463 #define TARGET_TRAMPOLINE_ADJUST_ADDRESS arm_trampoline_adjust_address
465 #undef TARGET_DEFAULT_SHORT_ENUMS
466 #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
468 #undef TARGET_ALIGN_ANON_BITFIELD
469 #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield
471 #undef TARGET_NARROW_VOLATILE_BITFIELD
472 #define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
474 #undef TARGET_CXX_GUARD_TYPE
475 #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type
477 #undef TARGET_CXX_GUARD_MASK_BIT
478 #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit
480 #undef TARGET_CXX_GET_COOKIE_SIZE
481 #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size
483 #undef TARGET_CXX_COOKIE_HAS_SIZE
484 #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size
486 #undef TARGET_CXX_CDTOR_RETURNS_THIS
487 #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this
489 #undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE
490 #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline
492 #undef TARGET_CXX_USE_AEABI_ATEXIT
493 #define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit
495 #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY
496 #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \
497 arm_cxx_determine_class_data_visibility
499 #undef TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT
500 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT arm_cxx_class_data_always_comdat
502 #undef TARGET_RETURN_IN_MSB
503 #define TARGET_RETURN_IN_MSB arm_return_in_msb
505 #undef TARGET_RETURN_IN_MEMORY
506 #define TARGET_RETURN_IN_MEMORY arm_return_in_memory
508 #undef TARGET_MUST_PASS_IN_STACK
509 #define TARGET_MUST_PASS_IN_STACK arm_must_pass_in_stack
512 #undef TARGET_ASM_UNWIND_EMIT
513 #define TARGET_ASM_UNWIND_EMIT arm_unwind_emit
515 /* EABI unwinding tables use a different format for the typeinfo tables. */
516 #undef TARGET_ASM_TTYPE
517 #define TARGET_ASM_TTYPE arm_output_ttype
519 #undef TARGET_ARM_EABI_UNWINDER
520 #define TARGET_ARM_EABI_UNWINDER true
522 #undef TARGET_ASM_EMIT_EXCEPT_PERSONALITY
523 #define TARGET_ASM_EMIT_EXCEPT_PERSONALITY arm_asm_emit_except_personality
525 #undef TARGET_ASM_INIT_SECTIONS
526 #define TARGET_ASM_INIT_SECTIONS arm_asm_init_sections
527 #endif /* ARM_UNWIND_INFO */
529 #undef TARGET_DWARF_REGISTER_SPAN
530 #define TARGET_DWARF_REGISTER_SPAN arm_dwarf_register_span
532 #undef TARGET_CANNOT_COPY_INSN_P
533 #define TARGET_CANNOT_COPY_INSN_P arm_cannot_copy_insn_p
536 #undef TARGET_HAVE_TLS
537 #define TARGET_HAVE_TLS true
540 #undef TARGET_HAVE_CONDITIONAL_EXECUTION
541 #define TARGET_HAVE_CONDITIONAL_EXECUTION arm_have_conditional_execution
543 #undef TARGET_LEGITIMATE_CONSTANT_P
544 #define TARGET_LEGITIMATE_CONSTANT_P arm_legitimate_constant_p
546 #undef TARGET_CANNOT_FORCE_CONST_MEM
547 #define TARGET_CANNOT_FORCE_CONST_MEM arm_cannot_force_const_mem
549 #undef TARGET_MAX_ANCHOR_OFFSET
550 #define TARGET_MAX_ANCHOR_OFFSET 4095
552 /* The minimum is set such that the total size of the block
553 for a particular anchor is -4088 + 1 + 4095 bytes, which is
554 divisible by eight, ensuring natural spacing of anchors. */
555 #undef TARGET_MIN_ANCHOR_OFFSET
556 #define TARGET_MIN_ANCHOR_OFFSET -4088
558 #undef TARGET_SCHED_ISSUE_RATE
559 #define TARGET_SCHED_ISSUE_RATE arm_issue_rate
561 #undef TARGET_MANGLE_TYPE
562 #define TARGET_MANGLE_TYPE arm_mangle_type
564 #undef TARGET_BUILD_BUILTIN_VA_LIST
565 #define TARGET_BUILD_BUILTIN_VA_LIST arm_build_builtin_va_list
566 #undef TARGET_EXPAND_BUILTIN_VA_START
567 #define TARGET_EXPAND_BUILTIN_VA_START arm_expand_builtin_va_start
568 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
569 #define TARGET_GIMPLIFY_VA_ARG_EXPR arm_gimplify_va_arg_expr
572 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
573 #define TARGET_ASM_OUTPUT_DWARF_DTPREL arm_output_dwarf_dtprel
576 #undef TARGET_LEGITIMATE_ADDRESS_P
577 #define TARGET_LEGITIMATE_ADDRESS_P arm_legitimate_address_p
579 #undef TARGET_INVALID_PARAMETER_TYPE
580 #define TARGET_INVALID_PARAMETER_TYPE arm_invalid_parameter_type
582 #undef TARGET_INVALID_RETURN_TYPE
583 #define TARGET_INVALID_RETURN_TYPE arm_invalid_return_type
585 #undef TARGET_PROMOTED_TYPE
586 #define TARGET_PROMOTED_TYPE arm_promoted_type
588 #undef TARGET_CONVERT_TO_TYPE
589 #define TARGET_CONVERT_TO_TYPE arm_convert_to_type
591 #undef TARGET_SCALAR_MODE_SUPPORTED_P
592 #define TARGET_SCALAR_MODE_SUPPORTED_P arm_scalar_mode_supported_p
594 #undef TARGET_FRAME_POINTER_REQUIRED
595 #define TARGET_FRAME_POINTER_REQUIRED arm_frame_pointer_required
597 #undef TARGET_CAN_ELIMINATE
598 #define TARGET_CAN_ELIMINATE arm_can_eliminate
600 #undef TARGET_CONDITIONAL_REGISTER_USAGE
601 #define TARGET_CONDITIONAL_REGISTER_USAGE arm_conditional_register_usage
603 #undef TARGET_CLASS_LIKELY_SPILLED_P
604 #define TARGET_CLASS_LIKELY_SPILLED_P arm_class_likely_spilled_p
606 #undef TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE
607 #define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE \
608 arm_vector_alignment_reachable
610 #undef TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT
611 #define TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT \
612 arm_builtin_support_vector_misalignment
614 #undef TARGET_PREFERRED_RENAME_CLASS
615 #define TARGET_PREFERRED_RENAME_CLASS \
616 arm_preferred_rename_class
618 #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
619 #define TARGET_VECTORIZE_VEC_PERM_CONST_OK \
620 arm_vectorize_vec_perm_const_ok
622 struct gcc_target targetm = TARGET_INITIALIZER;
624 /* Obstack for minipool constant handling. */
625 static struct obstack minipool_obstack;
626 static char * minipool_startobj;
628 /* The maximum number of insns skipped which
629 will be conditionalised if possible. */
630 static int max_insns_skipped = 5;
632 extern FILE * asm_out_file;
634 /* True if we are currently building a constant table. */
635 int making_const_table;
637 /* The processor for which instructions should be scheduled. */
638 enum processor_type arm_tune = arm_none;
640 /* The current tuning set. */
641 const struct tune_params *current_tune;
643 /* Which floating point hardware to schedule for. */
646 /* Which floating popint hardware to use. */
647 const struct arm_fpu_desc *arm_fpu_desc;
649 /* Used for Thumb call_via trampolines. */
650 rtx thumb_call_via_label[14];
651 static int thumb_call_reg_needed;
653 /* Bit values used to identify processor capabilities. */
654 #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */
655 #define FL_ARCH3M (1 << 1) /* Extended multiply */
656 #define FL_MODE26 (1 << 2) /* 26-bit mode support */
657 #define FL_MODE32 (1 << 3) /* 32-bit mode support */
658 #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */
659 #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */
660 #define FL_THUMB (1 << 6) /* Thumb aware */
661 #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */
662 #define FL_STRONG (1 << 8) /* StrongARM */
663 #define FL_ARCH5E (1 << 9) /* DSP extensions to v5 */
664 #define FL_XSCALE (1 << 10) /* XScale */
665 #define FL_CIRRUS (1 << 11) /* Cirrus/DSP. */
666 #define FL_ARCH6 (1 << 12) /* Architecture rel 6. Adds
667 media instructions. */
668 #define FL_VFPV2 (1 << 13) /* Vector Floating Point V2. */
669 #define FL_WBUF (1 << 14) /* Schedule for write buffer ops.
670 Note: ARM6 & 7 derivatives only. */
671 #define FL_ARCH6K (1 << 15) /* Architecture rel 6 K extensions. */
672 #define FL_THUMB2 (1 << 16) /* Thumb-2. */
673 #define FL_NOTM (1 << 17) /* Instructions not present in the 'M'
675 #define FL_THUMB_DIV (1 << 18) /* Hardware divide (Thumb mode). */
676 #define FL_VFPV3 (1 << 19) /* Vector Floating Point V3. */
677 #define FL_NEON (1 << 20) /* Neon instructions. */
678 #define FL_ARCH7EM (1 << 21) /* Instructions present in the ARMv7E-M
680 #define FL_ARCH7 (1 << 22) /* Architecture 7. */
681 #define FL_ARM_DIV (1 << 23) /* Hardware divide (ARM mode). */
683 #define FL_IWMMXT (1 << 29) /* XScale v2 or "Intel Wireless MMX technology". */
685 /* Flags that only effect tuning, not available instructions. */
686 #define FL_TUNE (FL_WBUF | FL_VFPV2 | FL_STRONG | FL_LDSCHED \
689 #define FL_FOR_ARCH2 FL_NOTM
690 #define FL_FOR_ARCH3 (FL_FOR_ARCH2 | FL_MODE32)
691 #define FL_FOR_ARCH3M (FL_FOR_ARCH3 | FL_ARCH3M)
692 #define FL_FOR_ARCH4 (FL_FOR_ARCH3M | FL_ARCH4)
693 #define FL_FOR_ARCH4T (FL_FOR_ARCH4 | FL_THUMB)
694 #define FL_FOR_ARCH5 (FL_FOR_ARCH4 | FL_ARCH5)
695 #define FL_FOR_ARCH5T (FL_FOR_ARCH5 | FL_THUMB)
696 #define FL_FOR_ARCH5E (FL_FOR_ARCH5 | FL_ARCH5E)
697 #define FL_FOR_ARCH5TE (FL_FOR_ARCH5E | FL_THUMB)
698 #define FL_FOR_ARCH5TEJ FL_FOR_ARCH5TE
699 #define FL_FOR_ARCH6 (FL_FOR_ARCH5TE | FL_ARCH6)
700 #define FL_FOR_ARCH6J FL_FOR_ARCH6
701 #define FL_FOR_ARCH6K (FL_FOR_ARCH6 | FL_ARCH6K)
702 #define FL_FOR_ARCH6Z FL_FOR_ARCH6
703 #define FL_FOR_ARCH6ZK FL_FOR_ARCH6K
704 #define FL_FOR_ARCH6T2 (FL_FOR_ARCH6 | FL_THUMB2)
705 #define FL_FOR_ARCH6M (FL_FOR_ARCH6 & ~FL_NOTM)
706 #define FL_FOR_ARCH7 ((FL_FOR_ARCH6T2 & ~FL_NOTM) | FL_ARCH7)
707 #define FL_FOR_ARCH7A (FL_FOR_ARCH7 | FL_NOTM | FL_ARCH6K)
708 #define FL_FOR_ARCH7R (FL_FOR_ARCH7A | FL_THUMB_DIV)
709 #define FL_FOR_ARCH7M (FL_FOR_ARCH7 | FL_THUMB_DIV)
710 #define FL_FOR_ARCH7EM (FL_FOR_ARCH7M | FL_ARCH7EM)
712 /* The bits in this mask specify which
713 instructions we are allowed to generate. */
714 static unsigned long insn_flags = 0;
716 /* The bits in this mask specify which instruction scheduling options should
718 static unsigned long tune_flags = 0;
720 /* The following are used in the arm.md file as equivalents to bits
721 in the above two flag variables. */
723 /* Nonzero if this chip supports the ARM Architecture 3M extensions. */
726 /* Nonzero if this chip supports the ARM Architecture 4 extensions. */
729 /* Nonzero if this chip supports the ARM Architecture 4t extensions. */
732 /* Nonzero if this chip supports the ARM Architecture 5 extensions. */
735 /* Nonzero if this chip supports the ARM Architecture 5E extensions. */
738 /* Nonzero if this chip supports the ARM Architecture 6 extensions. */
741 /* Nonzero if this chip supports the ARM 6K extensions. */
744 /* Nonzero if this chip supports the ARM 7 extensions. */
747 /* Nonzero if instructions not present in the 'M' profile can be used. */
748 int arm_arch_notm = 0;
750 /* Nonzero if instructions present in ARMv7E-M can be used. */
753 /* Nonzero if this chip can benefit from load scheduling. */
754 int arm_ld_sched = 0;
756 /* Nonzero if this chip is a StrongARM. */
757 int arm_tune_strongarm = 0;
759 /* Nonzero if this chip is a Cirrus variant. */
760 int arm_arch_cirrus = 0;
762 /* Nonzero if this chip supports Intel Wireless MMX technology. */
763 int arm_arch_iwmmxt = 0;
765 /* Nonzero if this chip is an XScale. */
766 int arm_arch_xscale = 0;
768 /* Nonzero if tuning for XScale */
769 int arm_tune_xscale = 0;
771 /* Nonzero if we want to tune for stores that access the write-buffer.
772 This typically means an ARM6 or ARM7 with MMU or MPU. */
773 int arm_tune_wbuf = 0;
775 /* Nonzero if tuning for Cortex-A9. */
776 int arm_tune_cortex_a9 = 0;
778 /* Nonzero if generating Thumb instructions. */
781 /* Nonzero if generating Thumb-1 instructions. */
784 /* Nonzero if we should define __THUMB_INTERWORK__ in the
786 XXX This is a bit of a hack, it's intended to help work around
787 problems in GLD which doesn't understand that armv5t code is
788 interworking clean. */
789 int arm_cpp_interwork = 0;
791 /* Nonzero if chip supports Thumb 2. */
794 /* Nonzero if chip supports integer division instruction. */
795 int arm_arch_arm_hwdiv;
796 int arm_arch_thumb_hwdiv;
798 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference,
799 we must report the mode of the memory reference from
800 TARGET_PRINT_OPERAND to TARGET_PRINT_OPERAND_ADDRESS. */
801 enum machine_mode output_memory_reference_mode;
803 /* The register number to be used for the PIC offset register. */
804 unsigned arm_pic_register = INVALID_REGNUM;
806 /* Set to 1 after arm_reorg has started. Reset to start at the start of
807 the next function. */
808 static int after_arm_reorg = 0;
810 enum arm_pcs arm_pcs_default;
812 /* For an explanation of these variables, see final_prescan_insn below. */
814 /* arm_current_cc is also used for Thumb-2 cond_exec blocks. */
815 enum arm_cond_code arm_current_cc;
818 int arm_target_label;
819 /* The number of conditionally executed insns, including the current insn. */
820 int arm_condexec_count = 0;
821 /* A bitmask specifying the patterns for the IT block.
822 Zero means do not output an IT block before this insn. */
823 int arm_condexec_mask = 0;
824 /* The number of bits used in arm_condexec_mask. */
825 int arm_condexec_masklen = 0;
827 /* The condition codes of the ARM, and the inverse function. */
828 static const char * const arm_condition_codes[] =
830 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
831 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
834 /* The register numbers in sequence, for passing to arm_gen_load_multiple. */
835 int arm_regs_in_sequence[] =
837 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
840 #define ARM_LSL_NAME (TARGET_UNIFIED_ASM ? "lsl" : "asl")
841 #define streq(string1, string2) (strcmp (string1, string2) == 0)
843 #define THUMB2_WORK_REGS (0xff & ~( (1 << THUMB_HARD_FRAME_POINTER_REGNUM) \
844 | (1 << SP_REGNUM) | (1 << PC_REGNUM) \
845 | (1 << PIC_OFFSET_TABLE_REGNUM)))
847 /* Initialization code. */
851 const char *const name;
852 enum processor_type core;
854 const unsigned long flags;
855 const struct tune_params *const tune;
859 #define ARM_PREFETCH_NOT_BENEFICIAL 0, -1, -1
860 #define ARM_PREFETCH_BENEFICIAL(prefetch_slots,l1_size,l1_line_size) \
865 const struct tune_params arm_slowmul_tune =
867 arm_slowmul_rtx_costs,
869 3, /* Constant limit. */
870 5, /* Max cond insns. */
871 ARM_PREFETCH_NOT_BENEFICIAL,
872 true, /* Prefer constant pool. */
873 arm_default_branch_cost
876 const struct tune_params arm_fastmul_tune =
878 arm_fastmul_rtx_costs,
880 1, /* Constant limit. */
881 5, /* Max cond insns. */
882 ARM_PREFETCH_NOT_BENEFICIAL,
883 true, /* Prefer constant pool. */
884 arm_default_branch_cost
887 /* StrongARM has early execution of branches, so a sequence that is worth
888 skipping is shorter. Set max_insns_skipped to a lower value. */
890 const struct tune_params arm_strongarm_tune =
892 arm_fastmul_rtx_costs,
894 1, /* Constant limit. */
895 3, /* Max cond insns. */
896 ARM_PREFETCH_NOT_BENEFICIAL,
897 true, /* Prefer constant pool. */
898 arm_default_branch_cost
901 const struct tune_params arm_xscale_tune =
903 arm_xscale_rtx_costs,
904 xscale_sched_adjust_cost,
905 2, /* Constant limit. */
906 3, /* Max cond insns. */
907 ARM_PREFETCH_NOT_BENEFICIAL,
908 true, /* Prefer constant pool. */
909 arm_default_branch_cost
912 const struct tune_params arm_9e_tune =
916 1, /* Constant limit. */
917 5, /* Max cond insns. */
918 ARM_PREFETCH_NOT_BENEFICIAL,
919 true, /* Prefer constant pool. */
920 arm_default_branch_cost
923 const struct tune_params arm_v6t2_tune =
927 1, /* Constant limit. */
928 5, /* Max cond insns. */
929 ARM_PREFETCH_NOT_BENEFICIAL,
930 false, /* Prefer constant pool. */
931 arm_default_branch_cost
934 /* Generic Cortex tuning. Use more specific tunings if appropriate. */
935 const struct tune_params arm_cortex_tune =
939 1, /* Constant limit. */
940 5, /* Max cond insns. */
941 ARM_PREFETCH_NOT_BENEFICIAL,
942 false, /* Prefer constant pool. */
943 arm_default_branch_cost
946 /* Branches can be dual-issued on Cortex-A5, so conditional execution is
947 less appealing. Set max_insns_skipped to a low value. */
949 const struct tune_params arm_cortex_a5_tune =
953 1, /* Constant limit. */
954 1, /* Max cond insns. */
955 ARM_PREFETCH_NOT_BENEFICIAL,
956 false, /* Prefer constant pool. */
957 arm_cortex_a5_branch_cost
960 const struct tune_params arm_cortex_a9_tune =
963 cortex_a9_sched_adjust_cost,
964 1, /* Constant limit. */
965 5, /* Max cond insns. */
966 ARM_PREFETCH_BENEFICIAL(4,32,32),
967 false, /* Prefer constant pool. */
968 arm_default_branch_cost
971 const struct tune_params arm_cortex_a15_tune =
975 1, /* Constant limit. */
976 1, /* Max cond insns. */
977 ARM_PREFETCH_NOT_BENEFICIAL, /* TODO: Calculate correct values. */
978 false, /* Prefer constant pool. */
979 arm_cortex_a5_branch_cost
982 const struct tune_params arm_fa726te_tune =
985 fa726te_sched_adjust_cost,
986 1, /* Constant limit. */
987 5, /* Max cond insns. */
988 ARM_PREFETCH_NOT_BENEFICIAL,
989 true, /* Prefer constant pool. */
990 arm_default_branch_cost
994 /* Not all of these give usefully different compilation alternatives,
995 but there is no simple way of generalizing them. */
996 static const struct processors all_cores[] =
999 #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \
1000 {NAME, IDENT, #ARCH, FLAGS | FL_FOR_ARCH##ARCH, &arm_##COSTS##_tune},
1001 #include "arm-cores.def"
1003 {NULL, arm_none, NULL, 0, NULL}
1006 static const struct processors all_architectures[] =
1008 /* ARM Architectures */
1009 /* We don't specify tuning costs here as it will be figured out
1012 #define ARM_ARCH(NAME, CORE, ARCH, FLAGS) \
1013 {NAME, CORE, #ARCH, FLAGS, NULL},
1014 #include "arm-arches.def"
1016 {NULL, arm_none, NULL, 0 , NULL}
1020 /* These are populated as commandline arguments are processed, or NULL
1021 if not specified. */
1022 static const struct processors *arm_selected_arch;
1023 static const struct processors *arm_selected_cpu;
1024 static const struct processors *arm_selected_tune;
1026 /* The name of the preprocessor macro to define for this architecture. */
1028 char arm_arch_name[] = "__ARM_ARCH_0UNK__";
1030 /* Available values for -mfpu=. */
1032 static const struct arm_fpu_desc all_fpus[] =
1034 #define ARM_FPU(NAME, MODEL, REV, VFP_REGS, NEON, FP16) \
1035 { NAME, MODEL, REV, VFP_REGS, NEON, FP16 },
1036 #include "arm-fpus.def"
1041 /* Supported TLS relocations. */
1049 TLS_DESCSEQ /* GNU scheme */
1052 /* The maximum number of insns to be used when loading a constant. */
1054 arm_constant_limit (bool size_p)
1056 return size_p ? 1 : current_tune->constant_limit;
1059 /* Emit an insn that's a simple single-set. Both the operands must be known
1062 emit_set_insn (rtx x, rtx y)
1064 return emit_insn (gen_rtx_SET (VOIDmode, x, y));
1067 /* Return the number of bits set in VALUE. */
1069 bit_count (unsigned long value)
1071 unsigned long count = 0;
1076 value &= value - 1; /* Clear the least-significant set bit. */
1084 enum machine_mode mode;
1086 } arm_fixed_mode_set;
1088 /* A small helper for setting fixed-point library libfuncs. */
1091 arm_set_fixed_optab_libfunc (optab optable, enum machine_mode mode,
1092 const char *funcname, const char *modename,
1097 if (num_suffix == 0)
1098 sprintf (buffer, "__gnu_%s%s", funcname, modename);
1100 sprintf (buffer, "__gnu_%s%s%d", funcname, modename, num_suffix);
1102 set_optab_libfunc (optable, mode, buffer);
1106 arm_set_fixed_conv_libfunc (convert_optab optable, enum machine_mode to,
1107 enum machine_mode from, const char *funcname,
1108 const char *toname, const char *fromname)
1111 const char *maybe_suffix_2 = "";
1113 /* Follow the logic for selecting a "2" suffix in fixed-bit.h. */
1114 if (ALL_FIXED_POINT_MODE_P (from) && ALL_FIXED_POINT_MODE_P (to)
1115 && UNSIGNED_FIXED_POINT_MODE_P (from) == UNSIGNED_FIXED_POINT_MODE_P (to)
1116 && ALL_FRACT_MODE_P (from) == ALL_FRACT_MODE_P (to))
1117 maybe_suffix_2 = "2";
1119 sprintf (buffer, "__gnu_%s%s%s%s", funcname, fromname, toname,
1122 set_conv_libfunc (optable, to, from, buffer);
1125 /* Set up library functions unique to ARM. */
1128 arm_init_libfuncs (void)
1130 /* For Linux, we have access to kernel support for atomic operations. */
1131 if (arm_abi == ARM_ABI_AAPCS_LINUX)
1132 init_sync_libfuncs (2 * UNITS_PER_WORD);
1134 /* There are no special library functions unless we are using the
1139 /* The functions below are described in Section 4 of the "Run-Time
1140 ABI for the ARM architecture", Version 1.0. */
1142 /* Double-precision floating-point arithmetic. Table 2. */
1143 set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd");
1144 set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv");
1145 set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul");
1146 set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg");
1147 set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub");
1149 /* Double-precision comparisons. Table 3. */
1150 set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq");
1151 set_optab_libfunc (ne_optab, DFmode, NULL);
1152 set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt");
1153 set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple");
1154 set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge");
1155 set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt");
1156 set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun");
1158 /* Single-precision floating-point arithmetic. Table 4. */
1159 set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd");
1160 set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv");
1161 set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul");
1162 set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg");
1163 set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub");
1165 /* Single-precision comparisons. Table 5. */
1166 set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq");
1167 set_optab_libfunc (ne_optab, SFmode, NULL);
1168 set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt");
1169 set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple");
1170 set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge");
1171 set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt");
1172 set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun");
1174 /* Floating-point to integer conversions. Table 6. */
1175 set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz");
1176 set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz");
1177 set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz");
1178 set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz");
1179 set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz");
1180 set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz");
1181 set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz");
1182 set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz");
1184 /* Conversions between floating types. Table 7. */
1185 set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f");
1186 set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d");
1188 /* Integer to floating-point conversions. Table 8. */
1189 set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d");
1190 set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d");
1191 set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d");
1192 set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d");
1193 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f");
1194 set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f");
1195 set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f");
1196 set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f");
1198 /* Long long. Table 9. */
1199 set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul");
1200 set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod");
1201 set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod");
1202 set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl");
1203 set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr");
1204 set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr");
1205 set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp");
1206 set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp");
1208 /* Integer (32/32->32) division. \S 4.3.1. */
1209 set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod");
1210 set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod");
1212 /* The divmod functions are designed so that they can be used for
1213 plain division, even though they return both the quotient and the
1214 remainder. The quotient is returned in the usual location (i.e.,
1215 r0 for SImode, {r0, r1} for DImode), just as would be expected
1216 for an ordinary division routine. Because the AAPCS calling
1217 conventions specify that all of { r0, r1, r2, r3 } are
1218 callee-saved registers, there is no need to tell the compiler
1219 explicitly that those registers are clobbered by these
1221 set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod");
1222 set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod");
1224 /* For SImode division the ABI provides div-without-mod routines,
1225 which are faster. */
1226 set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idiv");
1227 set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidiv");
1229 /* We don't have mod libcalls. Fortunately gcc knows how to use the
1230 divmod libcalls instead. */
1231 set_optab_libfunc (smod_optab, DImode, NULL);
1232 set_optab_libfunc (umod_optab, DImode, NULL);
1233 set_optab_libfunc (smod_optab, SImode, NULL);
1234 set_optab_libfunc (umod_optab, SImode, NULL);
1236 /* Half-precision float operations. The compiler handles all operations
1237 with NULL libfuncs by converting the SFmode. */
1238 switch (arm_fp16_format)
1240 case ARM_FP16_FORMAT_IEEE:
1241 case ARM_FP16_FORMAT_ALTERNATIVE:
1244 set_conv_libfunc (trunc_optab, HFmode, SFmode,
1245 (arm_fp16_format == ARM_FP16_FORMAT_IEEE
1247 : "__gnu_f2h_alternative"));
1248 set_conv_libfunc (sext_optab, SFmode, HFmode,
1249 (arm_fp16_format == ARM_FP16_FORMAT_IEEE
1251 : "__gnu_h2f_alternative"));
1254 set_optab_libfunc (add_optab, HFmode, NULL);
1255 set_optab_libfunc (sdiv_optab, HFmode, NULL);
1256 set_optab_libfunc (smul_optab, HFmode, NULL);
1257 set_optab_libfunc (neg_optab, HFmode, NULL);
1258 set_optab_libfunc (sub_optab, HFmode, NULL);
1261 set_optab_libfunc (eq_optab, HFmode, NULL);
1262 set_optab_libfunc (ne_optab, HFmode, NULL);
1263 set_optab_libfunc (lt_optab, HFmode, NULL);
1264 set_optab_libfunc (le_optab, HFmode, NULL);
1265 set_optab_libfunc (ge_optab, HFmode, NULL);
1266 set_optab_libfunc (gt_optab, HFmode, NULL);
1267 set_optab_libfunc (unord_optab, HFmode, NULL);
1274 /* Use names prefixed with __gnu_ for fixed-point helper functions. */
1276 const arm_fixed_mode_set fixed_arith_modes[] =
1297 const arm_fixed_mode_set fixed_conv_modes[] =
1327 for (i = 0; i < ARRAY_SIZE (fixed_arith_modes); i++)
1329 arm_set_fixed_optab_libfunc (add_optab, fixed_arith_modes[i].mode,
1330 "add", fixed_arith_modes[i].name, 3);
1331 arm_set_fixed_optab_libfunc (ssadd_optab, fixed_arith_modes[i].mode,
1332 "ssadd", fixed_arith_modes[i].name, 3);
1333 arm_set_fixed_optab_libfunc (usadd_optab, fixed_arith_modes[i].mode,
1334 "usadd", fixed_arith_modes[i].name, 3);
1335 arm_set_fixed_optab_libfunc (sub_optab, fixed_arith_modes[i].mode,
1336 "sub", fixed_arith_modes[i].name, 3);
1337 arm_set_fixed_optab_libfunc (sssub_optab, fixed_arith_modes[i].mode,
1338 "sssub", fixed_arith_modes[i].name, 3);
1339 arm_set_fixed_optab_libfunc (ussub_optab, fixed_arith_modes[i].mode,
1340 "ussub", fixed_arith_modes[i].name, 3);
1341 arm_set_fixed_optab_libfunc (smul_optab, fixed_arith_modes[i].mode,
1342 "mul", fixed_arith_modes[i].name, 3);
1343 arm_set_fixed_optab_libfunc (ssmul_optab, fixed_arith_modes[i].mode,
1344 "ssmul", fixed_arith_modes[i].name, 3);
1345 arm_set_fixed_optab_libfunc (usmul_optab, fixed_arith_modes[i].mode,
1346 "usmul", fixed_arith_modes[i].name, 3);
1347 arm_set_fixed_optab_libfunc (sdiv_optab, fixed_arith_modes[i].mode,
1348 "div", fixed_arith_modes[i].name, 3);
1349 arm_set_fixed_optab_libfunc (udiv_optab, fixed_arith_modes[i].mode,
1350 "udiv", fixed_arith_modes[i].name, 3);
1351 arm_set_fixed_optab_libfunc (ssdiv_optab, fixed_arith_modes[i].mode,
1352 "ssdiv", fixed_arith_modes[i].name, 3);
1353 arm_set_fixed_optab_libfunc (usdiv_optab, fixed_arith_modes[i].mode,
1354 "usdiv", fixed_arith_modes[i].name, 3);
1355 arm_set_fixed_optab_libfunc (neg_optab, fixed_arith_modes[i].mode,
1356 "neg", fixed_arith_modes[i].name, 2);
1357 arm_set_fixed_optab_libfunc (ssneg_optab, fixed_arith_modes[i].mode,
1358 "ssneg", fixed_arith_modes[i].name, 2);
1359 arm_set_fixed_optab_libfunc (usneg_optab, fixed_arith_modes[i].mode,
1360 "usneg", fixed_arith_modes[i].name, 2);
1361 arm_set_fixed_optab_libfunc (ashl_optab, fixed_arith_modes[i].mode,
1362 "ashl", fixed_arith_modes[i].name, 3);
1363 arm_set_fixed_optab_libfunc (ashr_optab, fixed_arith_modes[i].mode,
1364 "ashr", fixed_arith_modes[i].name, 3);
1365 arm_set_fixed_optab_libfunc (lshr_optab, fixed_arith_modes[i].mode,
1366 "lshr", fixed_arith_modes[i].name, 3);
1367 arm_set_fixed_optab_libfunc (ssashl_optab, fixed_arith_modes[i].mode,
1368 "ssashl", fixed_arith_modes[i].name, 3);
1369 arm_set_fixed_optab_libfunc (usashl_optab, fixed_arith_modes[i].mode,
1370 "usashl", fixed_arith_modes[i].name, 3);
1371 arm_set_fixed_optab_libfunc (cmp_optab, fixed_arith_modes[i].mode,
1372 "cmp", fixed_arith_modes[i].name, 2);
1375 for (i = 0; i < ARRAY_SIZE (fixed_conv_modes); i++)
1376 for (j = 0; j < ARRAY_SIZE (fixed_conv_modes); j++)
1379 || (!ALL_FIXED_POINT_MODE_P (fixed_conv_modes[i].mode)
1380 && !ALL_FIXED_POINT_MODE_P (fixed_conv_modes[j].mode)))
1383 arm_set_fixed_conv_libfunc (fract_optab, fixed_conv_modes[i].mode,
1384 fixed_conv_modes[j].mode, "fract",
1385 fixed_conv_modes[i].name,
1386 fixed_conv_modes[j].name);
1387 arm_set_fixed_conv_libfunc (satfract_optab,
1388 fixed_conv_modes[i].mode,
1389 fixed_conv_modes[j].mode, "satfract",
1390 fixed_conv_modes[i].name,
1391 fixed_conv_modes[j].name);
1392 arm_set_fixed_conv_libfunc (fractuns_optab,
1393 fixed_conv_modes[i].mode,
1394 fixed_conv_modes[j].mode, "fractuns",
1395 fixed_conv_modes[i].name,
1396 fixed_conv_modes[j].name);
1397 arm_set_fixed_conv_libfunc (satfractuns_optab,
1398 fixed_conv_modes[i].mode,
1399 fixed_conv_modes[j].mode, "satfractuns",
1400 fixed_conv_modes[i].name,
1401 fixed_conv_modes[j].name);
1405 if (TARGET_AAPCS_BASED)
1406 synchronize_libfunc = init_one_libfunc ("__sync_synchronize");
1409 /* On AAPCS systems, this is the "struct __va_list". */
1410 static GTY(()) tree va_list_type;
1412 /* Return the type to use as __builtin_va_list. */
1414 arm_build_builtin_va_list (void)
1419 if (!TARGET_AAPCS_BASED)
1420 return std_build_builtin_va_list ();
1422 /* AAPCS \S 7.1.4 requires that va_list be a typedef for a type
1430 The C Library ABI further reinforces this definition in \S
1433 We must follow this definition exactly. The structure tag
1434 name is visible in C++ mangled names, and thus forms a part
1435 of the ABI. The field name may be used by people who
1436 #include <stdarg.h>. */
1437 /* Create the type. */
1438 va_list_type = lang_hooks.types.make_type (RECORD_TYPE);
1439 /* Give it the required name. */
1440 va_list_name = build_decl (BUILTINS_LOCATION,
1442 get_identifier ("__va_list"),
1444 DECL_ARTIFICIAL (va_list_name) = 1;
1445 TYPE_NAME (va_list_type) = va_list_name;
1446 TYPE_STUB_DECL (va_list_type) = va_list_name;
1447 /* Create the __ap field. */
1448 ap_field = build_decl (BUILTINS_LOCATION,
1450 get_identifier ("__ap"),
1452 DECL_ARTIFICIAL (ap_field) = 1;
1453 DECL_FIELD_CONTEXT (ap_field) = va_list_type;
1454 TYPE_FIELDS (va_list_type) = ap_field;
1455 /* Compute its layout. */
1456 layout_type (va_list_type);
1458 return va_list_type;
1461 /* Return an expression of type "void *" pointing to the next
1462 available argument in a variable-argument list. VALIST is the
1463 user-level va_list object, of type __builtin_va_list. */
1465 arm_extract_valist_ptr (tree valist)
1467 if (TREE_TYPE (valist) == error_mark_node)
1468 return error_mark_node;
1470 /* On an AAPCS target, the pointer is stored within "struct
1472 if (TARGET_AAPCS_BASED)
1474 tree ap_field = TYPE_FIELDS (TREE_TYPE (valist));
1475 valist = build3 (COMPONENT_REF, TREE_TYPE (ap_field),
1476 valist, ap_field, NULL_TREE);
1482 /* Implement TARGET_EXPAND_BUILTIN_VA_START. */
1484 arm_expand_builtin_va_start (tree valist, rtx nextarg)
1486 valist = arm_extract_valist_ptr (valist);
1487 std_expand_builtin_va_start (valist, nextarg);
1490 /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */
1492 arm_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
1495 valist = arm_extract_valist_ptr (valist);
1496 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
1499 /* Fix up any incompatible options that the user has specified. */
1501 arm_option_override (void)
1503 if (global_options_set.x_arm_arch_option)
1504 arm_selected_arch = &all_architectures[arm_arch_option];
1506 if (global_options_set.x_arm_cpu_option)
1507 arm_selected_cpu = &all_cores[(int) arm_cpu_option];
1509 if (global_options_set.x_arm_tune_option)
1510 arm_selected_tune = &all_cores[(int) arm_tune_option];
1512 #ifdef SUBTARGET_OVERRIDE_OPTIONS
1513 SUBTARGET_OVERRIDE_OPTIONS;
1516 if (arm_selected_arch)
1518 if (arm_selected_cpu)
1520 /* Check for conflict between mcpu and march. */
1521 if ((arm_selected_cpu->flags ^ arm_selected_arch->flags) & ~FL_TUNE)
1523 warning (0, "switch -mcpu=%s conflicts with -march=%s switch",
1524 arm_selected_cpu->name, arm_selected_arch->name);
1525 /* -march wins for code generation.
1526 -mcpu wins for default tuning. */
1527 if (!arm_selected_tune)
1528 arm_selected_tune = arm_selected_cpu;
1530 arm_selected_cpu = arm_selected_arch;
1534 arm_selected_arch = NULL;
1537 /* Pick a CPU based on the architecture. */
1538 arm_selected_cpu = arm_selected_arch;
1541 /* If the user did not specify a processor, choose one for them. */
1542 if (!arm_selected_cpu)
1544 const struct processors * sel;
1545 unsigned int sought;
1547 arm_selected_cpu = &all_cores[TARGET_CPU_DEFAULT];
1548 if (!arm_selected_cpu->name)
1550 #ifdef SUBTARGET_CPU_DEFAULT
1551 /* Use the subtarget default CPU if none was specified by
1553 arm_selected_cpu = &all_cores[SUBTARGET_CPU_DEFAULT];
1555 /* Default to ARM6. */
1556 if (!arm_selected_cpu->name)
1557 arm_selected_cpu = &all_cores[arm6];
1560 sel = arm_selected_cpu;
1561 insn_flags = sel->flags;
1563 /* Now check to see if the user has specified some command line
1564 switch that require certain abilities from the cpu. */
1567 if (TARGET_INTERWORK || TARGET_THUMB)
1569 sought |= (FL_THUMB | FL_MODE32);
1571 /* There are no ARM processors that support both APCS-26 and
1572 interworking. Therefore we force FL_MODE26 to be removed
1573 from insn_flags here (if it was set), so that the search
1574 below will always be able to find a compatible processor. */
1575 insn_flags &= ~FL_MODE26;
1578 if (sought != 0 && ((sought & insn_flags) != sought))
1580 /* Try to locate a CPU type that supports all of the abilities
1581 of the default CPU, plus the extra abilities requested by
1583 for (sel = all_cores; sel->name != NULL; sel++)
1584 if ((sel->flags & sought) == (sought | insn_flags))
1587 if (sel->name == NULL)
1589 unsigned current_bit_count = 0;
1590 const struct processors * best_fit = NULL;
1592 /* Ideally we would like to issue an error message here
1593 saying that it was not possible to find a CPU compatible
1594 with the default CPU, but which also supports the command
1595 line options specified by the programmer, and so they
1596 ought to use the -mcpu=<name> command line option to
1597 override the default CPU type.
1599 If we cannot find a cpu that has both the
1600 characteristics of the default cpu and the given
1601 command line options we scan the array again looking
1602 for a best match. */
1603 for (sel = all_cores; sel->name != NULL; sel++)
1604 if ((sel->flags & sought) == sought)
1608 count = bit_count (sel->flags & insn_flags);
1610 if (count >= current_bit_count)
1613 current_bit_count = count;
1617 gcc_assert (best_fit);
1621 arm_selected_cpu = sel;
1625 gcc_assert (arm_selected_cpu);
1626 /* The selected cpu may be an architecture, so lookup tuning by core ID. */
1627 if (!arm_selected_tune)
1628 arm_selected_tune = &all_cores[arm_selected_cpu->core];
1630 sprintf (arm_arch_name, "__ARM_ARCH_%s__", arm_selected_cpu->arch);
1631 insn_flags = arm_selected_cpu->flags;
1633 arm_tune = arm_selected_tune->core;
1634 tune_flags = arm_selected_tune->flags;
1635 current_tune = arm_selected_tune->tune;
1637 /* Make sure that the processor choice does not conflict with any of the
1638 other command line choices. */
1639 if (TARGET_ARM && !(insn_flags & FL_NOTM))
1640 error ("target CPU does not support ARM mode");
1642 /* BPABI targets use linker tricks to allow interworking on cores
1643 without thumb support. */
1644 if (TARGET_INTERWORK && !((insn_flags & FL_THUMB) || TARGET_BPABI))
1646 warning (0, "target CPU does not support interworking" );
1647 target_flags &= ~MASK_INTERWORK;
1650 if (TARGET_THUMB && !(insn_flags & FL_THUMB))
1652 warning (0, "target CPU does not support THUMB instructions");
1653 target_flags &= ~MASK_THUMB;
1656 if (TARGET_APCS_FRAME && TARGET_THUMB)
1658 /* warning (0, "ignoring -mapcs-frame because -mthumb was used"); */
1659 target_flags &= ~MASK_APCS_FRAME;
1662 /* Callee super interworking implies thumb interworking. Adding
1663 this to the flags here simplifies the logic elsewhere. */
1664 if (TARGET_THUMB && TARGET_CALLEE_INTERWORKING)
1665 target_flags |= MASK_INTERWORK;
1667 /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done
1668 from here where no function is being compiled currently. */
1669 if ((TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) && TARGET_ARM)
1670 warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb");
1672 if (TARGET_ARM && TARGET_CALLEE_INTERWORKING)
1673 warning (0, "enabling callee interworking support is only meaningful when compiling for the Thumb");
1675 if (TARGET_APCS_STACK && !TARGET_APCS_FRAME)
1677 warning (0, "-mapcs-stack-check incompatible with -mno-apcs-frame");
1678 target_flags |= MASK_APCS_FRAME;
1681 if (TARGET_POKE_FUNCTION_NAME)
1682 target_flags |= MASK_APCS_FRAME;
1684 if (TARGET_APCS_REENT && flag_pic)
1685 error ("-fpic and -mapcs-reent are incompatible");
1687 if (TARGET_APCS_REENT)
1688 warning (0, "APCS reentrant code not supported. Ignored");
1690 /* If this target is normally configured to use APCS frames, warn if they
1691 are turned off and debugging is turned on. */
1693 && write_symbols != NO_DEBUG
1694 && !TARGET_APCS_FRAME
1695 && (TARGET_DEFAULT & MASK_APCS_FRAME))
1696 warning (0, "-g with -mno-apcs-frame may not give sensible debugging");
1698 if (TARGET_APCS_FLOAT)
1699 warning (0, "passing floating point arguments in fp regs not yet supported");
1701 if (TARGET_LITTLE_WORDS)
1702 warning (OPT_Wdeprecated, "%<mwords-little-endian%> is deprecated and "
1703 "will be removed in a future release");
1705 /* Initialize boolean versions of the flags, for use in the arm.md file. */
1706 arm_arch3m = (insn_flags & FL_ARCH3M) != 0;
1707 arm_arch4 = (insn_flags & FL_ARCH4) != 0;
1708 arm_arch4t = arm_arch4 & ((insn_flags & FL_THUMB) != 0);
1709 arm_arch5 = (insn_flags & FL_ARCH5) != 0;
1710 arm_arch5e = (insn_flags & FL_ARCH5E) != 0;
1711 arm_arch6 = (insn_flags & FL_ARCH6) != 0;
1712 arm_arch6k = (insn_flags & FL_ARCH6K) != 0;
1713 arm_arch_notm = (insn_flags & FL_NOTM) != 0;
1714 arm_arch7 = (insn_flags & FL_ARCH7) != 0;
1715 arm_arch7em = (insn_flags & FL_ARCH7EM) != 0;
1716 arm_arch_thumb2 = (insn_flags & FL_THUMB2) != 0;
1717 arm_arch_xscale = (insn_flags & FL_XSCALE) != 0;
1718 arm_arch_cirrus = (insn_flags & FL_CIRRUS) != 0;
1720 arm_ld_sched = (tune_flags & FL_LDSCHED) != 0;
1721 arm_tune_strongarm = (tune_flags & FL_STRONG) != 0;
1722 thumb_code = TARGET_ARM == 0;
1723 thumb1_code = TARGET_THUMB1 != 0;
1724 arm_tune_wbuf = (tune_flags & FL_WBUF) != 0;
1725 arm_tune_xscale = (tune_flags & FL_XSCALE) != 0;
1726 arm_arch_iwmmxt = (insn_flags & FL_IWMMXT) != 0;
1727 arm_arch_thumb_hwdiv = (insn_flags & FL_THUMB_DIV) != 0;
1728 arm_arch_arm_hwdiv = (insn_flags & FL_ARM_DIV) != 0;
1729 arm_tune_cortex_a9 = (arm_tune == cortexa9) != 0;
1731 /* If we are not using the default (ARM mode) section anchor offset
1732 ranges, then set the correct ranges now. */
1735 /* Thumb-1 LDR instructions cannot have negative offsets.
1736 Permissible positive offset ranges are 5-bit (for byte loads),
1737 6-bit (for halfword loads), or 7-bit (for word loads).
1738 Empirical results suggest a 7-bit anchor range gives the best
1739 overall code size. */
1740 targetm.min_anchor_offset = 0;
1741 targetm.max_anchor_offset = 127;
1743 else if (TARGET_THUMB2)
1745 /* The minimum is set such that the total size of the block
1746 for a particular anchor is 248 + 1 + 4095 bytes, which is
1747 divisible by eight, ensuring natural spacing of anchors. */
1748 targetm.min_anchor_offset = -248;
1749 targetm.max_anchor_offset = 4095;
1752 /* V5 code we generate is completely interworking capable, so we turn off
1753 TARGET_INTERWORK here to avoid many tests later on. */
1755 /* XXX However, we must pass the right pre-processor defines to CPP
1756 or GLD can get confused. This is a hack. */
1757 if (TARGET_INTERWORK)
1758 arm_cpp_interwork = 1;
1761 target_flags &= ~MASK_INTERWORK;
1763 if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN)
1764 error ("iwmmxt requires an AAPCS compatible ABI for proper operation");
1766 if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT)
1767 error ("iwmmxt abi requires an iwmmxt capable cpu");
1769 if (!global_options_set.x_arm_fpu_index)
1771 const char *target_fpu_name;
1774 #ifdef FPUTYPE_DEFAULT
1775 target_fpu_name = FPUTYPE_DEFAULT;
1777 if (arm_arch_cirrus)
1778 target_fpu_name = "maverick";
1780 target_fpu_name = "fpe2";
1783 ok = opt_enum_arg_to_value (OPT_mfpu_, target_fpu_name, &arm_fpu_index,
1788 arm_fpu_desc = &all_fpus[arm_fpu_index];
1790 switch (arm_fpu_desc->model)
1792 case ARM_FP_MODEL_FPA:
1793 if (arm_fpu_desc->rev == 2)
1794 arm_fpu_attr = FPU_FPE2;
1795 else if (arm_fpu_desc->rev == 3)
1796 arm_fpu_attr = FPU_FPE3;
1798 arm_fpu_attr = FPU_FPA;
1801 case ARM_FP_MODEL_MAVERICK:
1802 arm_fpu_attr = FPU_MAVERICK;
1805 case ARM_FP_MODEL_VFP:
1806 arm_fpu_attr = FPU_VFP;
1813 if (TARGET_AAPCS_BASED
1814 && (arm_fpu_desc->model == ARM_FP_MODEL_FPA))
1815 error ("FPA is unsupported in the AAPCS");
1817 if (TARGET_AAPCS_BASED)
1819 if (TARGET_CALLER_INTERWORKING)
1820 error ("AAPCS does not support -mcaller-super-interworking");
1822 if (TARGET_CALLEE_INTERWORKING)
1823 error ("AAPCS does not support -mcallee-super-interworking");
1826 /* FPA and iWMMXt are incompatible because the insn encodings overlap.
1827 VFP and iWMMXt can theoretically coexist, but it's unlikely such silicon
1828 will ever exist. GCC makes no attempt to support this combination. */
1829 if (TARGET_IWMMXT && !TARGET_SOFT_FLOAT)
1830 sorry ("iWMMXt and hardware floating point");
1832 /* ??? iWMMXt insn patterns need auditing for Thumb-2. */
1833 if (TARGET_THUMB2 && TARGET_IWMMXT)
1834 sorry ("Thumb-2 iWMMXt");
1836 /* __fp16 support currently assumes the core has ldrh. */
1837 if (!arm_arch4 && arm_fp16_format != ARM_FP16_FORMAT_NONE)
1838 sorry ("__fp16 and no ldrh");
1840 /* If soft-float is specified then don't use FPU. */
1841 if (TARGET_SOFT_FLOAT)
1842 arm_fpu_attr = FPU_NONE;
1844 if (TARGET_AAPCS_BASED)
1846 if (arm_abi == ARM_ABI_IWMMXT)
1847 arm_pcs_default = ARM_PCS_AAPCS_IWMMXT;
1848 else if (arm_float_abi == ARM_FLOAT_ABI_HARD
1849 && TARGET_HARD_FLOAT
1851 arm_pcs_default = ARM_PCS_AAPCS_VFP;
1853 arm_pcs_default = ARM_PCS_AAPCS;
1857 if (arm_float_abi == ARM_FLOAT_ABI_HARD && TARGET_VFP)
1858 sorry ("-mfloat-abi=hard and VFP");
1860 if (arm_abi == ARM_ABI_APCS)
1861 arm_pcs_default = ARM_PCS_APCS;
1863 arm_pcs_default = ARM_PCS_ATPCS;
1866 /* For arm2/3 there is no need to do any scheduling if there is only
1867 a floating point emulator, or we are doing software floating-point. */
1868 if ((TARGET_SOFT_FLOAT
1869 || (TARGET_FPA && arm_fpu_desc->rev))
1870 && (tune_flags & FL_MODE32) == 0)
1871 flag_schedule_insns = flag_schedule_insns_after_reload = 0;
1873 /* Use the cp15 method if it is available. */
1874 if (target_thread_pointer == TP_AUTO)
1876 if (arm_arch6k && !TARGET_THUMB1)
1877 target_thread_pointer = TP_CP15;
1879 target_thread_pointer = TP_SOFT;
1882 if (TARGET_HARD_TP && TARGET_THUMB1)
1883 error ("can not use -mtp=cp15 with 16-bit Thumb");
1885 /* Override the default structure alignment for AAPCS ABI. */
1886 if (!global_options_set.x_arm_structure_size_boundary)
1888 if (TARGET_AAPCS_BASED)
1889 arm_structure_size_boundary = 8;
1893 if (arm_structure_size_boundary != 8
1894 && arm_structure_size_boundary != 32
1895 && !(ARM_DOUBLEWORD_ALIGN && arm_structure_size_boundary == 64))
1897 if (ARM_DOUBLEWORD_ALIGN)
1899 "structure size boundary can only be set to 8, 32 or 64");
1901 warning (0, "structure size boundary can only be set to 8 or 32");
1902 arm_structure_size_boundary
1903 = (TARGET_AAPCS_BASED ? 8 : DEFAULT_STRUCTURE_SIZE_BOUNDARY);
1907 if (!TARGET_ARM && TARGET_VXWORKS_RTP && flag_pic)
1909 error ("RTP PIC is incompatible with Thumb");
1913 /* If stack checking is disabled, we can use r10 as the PIC register,
1914 which keeps r9 available. The EABI specifies r9 as the PIC register. */
1915 if (flag_pic && TARGET_SINGLE_PIC_BASE)
1917 if (TARGET_VXWORKS_RTP)
1918 warning (0, "RTP PIC is incompatible with -msingle-pic-base");
1919 arm_pic_register = (TARGET_APCS_STACK || TARGET_AAPCS_BASED) ? 9 : 10;
1922 if (flag_pic && TARGET_VXWORKS_RTP)
1923 arm_pic_register = 9;
1925 if (arm_pic_register_string != NULL)
1927 int pic_register = decode_reg_name (arm_pic_register_string);
1930 warning (0, "-mpic-register= is useless without -fpic");
1932 /* Prevent the user from choosing an obviously stupid PIC register. */
1933 else if (pic_register < 0 || call_used_regs[pic_register]
1934 || pic_register == HARD_FRAME_POINTER_REGNUM
1935 || pic_register == STACK_POINTER_REGNUM
1936 || pic_register >= PC_REGNUM
1937 || (TARGET_VXWORKS_RTP
1938 && (unsigned int) pic_register != arm_pic_register))
1939 error ("unable to use '%s' for PIC register", arm_pic_register_string);
1941 arm_pic_register = pic_register;
1944 /* Enable -mfix-cortex-m3-ldrd by default for Cortex-M3 cores. */
1945 if (fix_cm3_ldrd == 2)
1947 if (arm_selected_cpu->core == cortexm3)
1953 /* Enable -munaligned-access by default for
1954 - all ARMv6 architecture-based processors
1955 - ARMv7-A, ARMv7-R, and ARMv7-M architecture-based processors.
1957 Disable -munaligned-access by default for
1958 - all pre-ARMv6 architecture-based processors
1959 - ARMv6-M architecture-based processors. */
1961 if (unaligned_access == 2)
1963 if (arm_arch6 && (arm_arch_notm || arm_arch7))
1964 unaligned_access = 1;
1966 unaligned_access = 0;
1968 else if (unaligned_access == 1
1969 && !(arm_arch6 && (arm_arch_notm || arm_arch7)))
1971 warning (0, "target CPU does not support unaligned accesses");
1972 unaligned_access = 0;
1975 if (TARGET_THUMB1 && flag_schedule_insns)
1977 /* Don't warn since it's on by default in -O2. */
1978 flag_schedule_insns = 0;
1983 /* If optimizing for size, bump the number of instructions that we
1984 are prepared to conditionally execute (even on a StrongARM). */
1985 max_insns_skipped = 6;
1988 max_insns_skipped = current_tune->max_insns_skipped;
1990 /* Hot/Cold partitioning is not currently supported, since we can't
1991 handle literal pool placement in that case. */
1992 if (flag_reorder_blocks_and_partition)
1994 inform (input_location,
1995 "-freorder-blocks-and-partition not supported on this architecture");
1996 flag_reorder_blocks_and_partition = 0;
1997 flag_reorder_blocks = 1;
2001 /* Hoisting PIC address calculations more aggressively provides a small,
2002 but measurable, size reduction for PIC code. Therefore, we decrease
2003 the bar for unrestricted expression hoisting to the cost of PIC address
2004 calculation, which is 2 instructions. */
2005 maybe_set_param_value (PARAM_GCSE_UNRESTRICTED_COST, 2,
2006 global_options.x_param_values,
2007 global_options_set.x_param_values);
2009 /* ARM EABI defaults to strict volatile bitfields. */
2010 if (TARGET_AAPCS_BASED && flag_strict_volatile_bitfields < 0
2011 && abi_version_at_least(2))
2012 flag_strict_volatile_bitfields = 1;
2014 /* Enable sw prefetching at -O3 for CPUS that have prefetch, and we have deemed
2015 it beneficial (signified by setting num_prefetch_slots to 1 or more.) */
2016 if (flag_prefetch_loop_arrays < 0
2019 && current_tune->num_prefetch_slots > 0)
2020 flag_prefetch_loop_arrays = 1;
2022 /* Set up parameters to be used in prefetching algorithm. Do not override the
2023 defaults unless we are tuning for a core we have researched values for. */
2024 if (current_tune->num_prefetch_slots > 0)
2025 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
2026 current_tune->num_prefetch_slots,
2027 global_options.x_param_values,
2028 global_options_set.x_param_values);
2029 if (current_tune->l1_cache_line_size >= 0)
2030 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE,
2031 current_tune->l1_cache_line_size,
2032 global_options.x_param_values,
2033 global_options_set.x_param_values);
2034 if (current_tune->l1_cache_size >= 0)
2035 maybe_set_param_value (PARAM_L1_CACHE_SIZE,
2036 current_tune->l1_cache_size,
2037 global_options.x_param_values,
2038 global_options_set.x_param_values);
2040 /* Register global variables with the garbage collector. */
2041 arm_add_gc_roots ();
2045 arm_add_gc_roots (void)
2047 gcc_obstack_init(&minipool_obstack);
2048 minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0);
2051 /* A table of known ARM exception types.
2052 For use with the interrupt function attribute. */
2056 const char *const arg;
2057 const unsigned long return_value;
2061 static const isr_attribute_arg isr_attribute_args [] =
2063 { "IRQ", ARM_FT_ISR },
2064 { "irq", ARM_FT_ISR },
2065 { "FIQ", ARM_FT_FIQ },
2066 { "fiq", ARM_FT_FIQ },
2067 { "ABORT", ARM_FT_ISR },
2068 { "abort", ARM_FT_ISR },
2069 { "ABORT", ARM_FT_ISR },
2070 { "abort", ARM_FT_ISR },
2071 { "UNDEF", ARM_FT_EXCEPTION },
2072 { "undef", ARM_FT_EXCEPTION },
2073 { "SWI", ARM_FT_EXCEPTION },
2074 { "swi", ARM_FT_EXCEPTION },
2075 { NULL, ARM_FT_NORMAL }
2078 /* Returns the (interrupt) function type of the current
2079 function, or ARM_FT_UNKNOWN if the type cannot be determined. */
2081 static unsigned long
2082 arm_isr_value (tree argument)
2084 const isr_attribute_arg * ptr;
2088 return ARM_FT_NORMAL | ARM_FT_STACKALIGN;
2090 /* No argument - default to IRQ. */
2091 if (argument == NULL_TREE)
2094 /* Get the value of the argument. */
2095 if (TREE_VALUE (argument) == NULL_TREE
2096 || TREE_CODE (TREE_VALUE (argument)) != STRING_CST)
2097 return ARM_FT_UNKNOWN;
2099 arg = TREE_STRING_POINTER (TREE_VALUE (argument));
2101 /* Check it against the list of known arguments. */
2102 for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)
2103 if (streq (arg, ptr->arg))
2104 return ptr->return_value;
2106 /* An unrecognized interrupt type. */
2107 return ARM_FT_UNKNOWN;
2110 /* Computes the type of the current function. */
2112 static unsigned long
2113 arm_compute_func_type (void)
2115 unsigned long type = ARM_FT_UNKNOWN;
2119 gcc_assert (TREE_CODE (current_function_decl) == FUNCTION_DECL);
2121 /* Decide if the current function is volatile. Such functions
2122 never return, and many memory cycles can be saved by not storing
2123 register values that will never be needed again. This optimization
2124 was added to speed up context switching in a kernel application. */
2126 && (TREE_NOTHROW (current_function_decl)
2127 || !(flag_unwind_tables
2129 && arm_except_unwind_info (&global_options) != UI_SJLJ)))
2130 && TREE_THIS_VOLATILE (current_function_decl))
2131 type |= ARM_FT_VOLATILE;
2133 if (cfun->static_chain_decl != NULL)
2134 type |= ARM_FT_NESTED;
2136 attr = DECL_ATTRIBUTES (current_function_decl);
2138 a = lookup_attribute ("naked", attr);
2140 type |= ARM_FT_NAKED;
2142 a = lookup_attribute ("isr", attr);
2144 a = lookup_attribute ("interrupt", attr);
2147 type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL;
2149 type |= arm_isr_value (TREE_VALUE (a));
2154 /* Returns the type of the current function. */
2157 arm_current_func_type (void)
2159 if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN)
2160 cfun->machine->func_type = arm_compute_func_type ();
2162 return cfun->machine->func_type;
2166 arm_allocate_stack_slots_for_args (void)
2168 /* Naked functions should not allocate stack slots for arguments. */
2169 return !IS_NAKED (arm_current_func_type ());
2173 /* Output assembler code for a block containing the constant parts
2174 of a trampoline, leaving space for the variable parts.
2176 On the ARM, (if r8 is the static chain regnum, and remembering that
2177 referencing pc adds an offset of 8) the trampoline looks like:
2180 .word static chain value
2181 .word function's address
2182 XXX FIXME: When the trampoline returns, r8 will be clobbered. */
2185 arm_asm_trampoline_template (FILE *f)
2189 asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", STATIC_CHAIN_REGNUM, PC_REGNUM);
2190 asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", PC_REGNUM, PC_REGNUM);
2192 else if (TARGET_THUMB2)
2194 /* The Thumb-2 trampoline is similar to the arm implementation.
2195 Unlike 16-bit Thumb, we enter the stub in thumb mode. */
2196 asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n",
2197 STATIC_CHAIN_REGNUM, PC_REGNUM);
2198 asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n", PC_REGNUM, PC_REGNUM);
2202 ASM_OUTPUT_ALIGN (f, 2);
2203 fprintf (f, "\t.code\t16\n");
2204 fprintf (f, ".Ltrampoline_start:\n");
2205 asm_fprintf (f, "\tpush\t{r0, r1}\n");
2206 asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM);
2207 asm_fprintf (f, "\tmov\t%r, r0\n", STATIC_CHAIN_REGNUM);
2208 asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM);
2209 asm_fprintf (f, "\tstr\tr0, [%r, #4]\n", SP_REGNUM);
2210 asm_fprintf (f, "\tpop\t{r0, %r}\n", PC_REGNUM);
2212 assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
2213 assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
2216 /* Emit RTL insns to initialize the variable parts of a trampoline. */
2219 arm_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
2221 rtx fnaddr, mem, a_tramp;
2223 emit_block_move (m_tramp, assemble_trampoline_template (),
2224 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
2226 mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 8 : 12);
2227 emit_move_insn (mem, chain_value);
2229 mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 12 : 16);
2230 fnaddr = XEXP (DECL_RTL (fndecl), 0);
2231 emit_move_insn (mem, fnaddr);
2233 a_tramp = XEXP (m_tramp, 0);
2234 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"),
2235 LCT_NORMAL, VOIDmode, 2, a_tramp, Pmode,
2236 plus_constant (a_tramp, TRAMPOLINE_SIZE), Pmode);
2239 /* Thumb trampolines should be entered in thumb mode, so set
2240 the bottom bit of the address. */
2243 arm_trampoline_adjust_address (rtx addr)
2246 addr = expand_simple_binop (Pmode, IOR, addr, const1_rtx,
2247 NULL, 0, OPTAB_LIB_WIDEN);
2251 /* Return 1 if it is possible to return using a single instruction.
2252 If SIBLING is non-null, this is a test for a return before a sibling
2253 call. SIBLING is the call insn, so we can examine its register usage. */
2256 use_return_insn (int iscond, rtx sibling)
2259 unsigned int func_type;
2260 unsigned long saved_int_regs;
2261 unsigned HOST_WIDE_INT stack_adjust;
2262 arm_stack_offsets *offsets;
2264 /* Never use a return instruction before reload has run. */
2265 if (!reload_completed)
2268 func_type = arm_current_func_type ();
2270 /* Naked, volatile and stack alignment functions need special
2272 if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED | ARM_FT_STACKALIGN))
2275 /* So do interrupt functions that use the frame pointer and Thumb
2276 interrupt functions. */
2277 if (IS_INTERRUPT (func_type) && (frame_pointer_needed || TARGET_THUMB))
2280 offsets = arm_get_frame_offsets ();
2281 stack_adjust = offsets->outgoing_args - offsets->saved_regs;
2283 /* As do variadic functions. */
2284 if (crtl->args.pretend_args_size
2285 || cfun->machine->uses_anonymous_args
2286 /* Or if the function calls __builtin_eh_return () */
2287 || crtl->calls_eh_return
2288 /* Or if the function calls alloca */
2289 || cfun->calls_alloca
2290 /* Or if there is a stack adjustment. However, if the stack pointer
2291 is saved on the stack, we can use a pre-incrementing stack load. */
2292 || !(stack_adjust == 0 || (TARGET_APCS_FRAME && frame_pointer_needed
2293 && stack_adjust == 4)))
2296 saved_int_regs = offsets->saved_regs_mask;
2298 /* Unfortunately, the insn
2300 ldmib sp, {..., sp, ...}
2302 triggers a bug on most SA-110 based devices, such that the stack
2303 pointer won't be correctly restored if the instruction takes a
2304 page fault. We work around this problem by popping r3 along with
2305 the other registers, since that is never slower than executing
2306 another instruction.
2308 We test for !arm_arch5 here, because code for any architecture
2309 less than this could potentially be run on one of the buggy
2311 if (stack_adjust == 4 && !arm_arch5 && TARGET_ARM)
2313 /* Validate that r3 is a call-clobbered register (always true in
2314 the default abi) ... */
2315 if (!call_used_regs[3])
2318 /* ... that it isn't being used for a return value ... */
2319 if (arm_size_return_regs () >= (4 * UNITS_PER_WORD))
2322 /* ... or for a tail-call argument ... */
2325 gcc_assert (GET_CODE (sibling) == CALL_INSN);
2327 if (find_regno_fusage (sibling, USE, 3))
2331 /* ... and that there are no call-saved registers in r0-r2
2332 (always true in the default ABI). */
2333 if (saved_int_regs & 0x7)
2337 /* Can't be done if interworking with Thumb, and any registers have been
2339 if (TARGET_INTERWORK && saved_int_regs != 0 && !IS_INTERRUPT(func_type))
2342 /* On StrongARM, conditional returns are expensive if they aren't
2343 taken and multiple registers have been stacked. */
2344 if (iscond && arm_tune_strongarm)
2346 /* Conditional return when just the LR is stored is a simple
2347 conditional-load instruction, that's not expensive. */
2348 if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM))
2352 && arm_pic_register != INVALID_REGNUM
2353 && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM))
2357 /* If there are saved registers but the LR isn't saved, then we need
2358 two instructions for the return. */
2359 if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM)))
2362 /* Can't be done if any of the FPA regs are pushed,
2363 since this also requires an insn. */
2364 if (TARGET_HARD_FLOAT && TARGET_FPA)
2365 for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++)
2366 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
2369 /* Likewise VFP regs. */
2370 if (TARGET_HARD_FLOAT && TARGET_VFP)
2371 for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++)
2372 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
2375 if (TARGET_REALLY_IWMMXT)
2376 for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++)
2377 if (df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2383 /* Return TRUE if int I is a valid immediate ARM constant. */
2386 const_ok_for_arm (HOST_WIDE_INT i)
2390 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
2391 be all zero, or all one. */
2392 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
2393 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
2394 != ((~(unsigned HOST_WIDE_INT) 0)
2395 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
2398 i &= (unsigned HOST_WIDE_INT) 0xffffffff;
2400 /* Fast return for 0 and small values. We must do this for zero, since
2401 the code below can't handle that one case. */
2402 if ((i & ~(unsigned HOST_WIDE_INT) 0xff) == 0)
2405 /* Get the number of trailing zeros. */
2406 lowbit = ffs((int) i) - 1;
2408 /* Only even shifts are allowed in ARM mode so round down to the
2409 nearest even number. */
2413 if ((i & ~(((unsigned HOST_WIDE_INT) 0xff) << lowbit)) == 0)
2418 /* Allow rotated constants in ARM mode. */
2420 && ((i & ~0xc000003f) == 0
2421 || (i & ~0xf000000f) == 0
2422 || (i & ~0xfc000003) == 0))
2429 /* Allow repeated patterns 0x00XY00XY or 0xXYXYXYXY. */
2432 if (i == v || i == (v | (v << 8)))
2435 /* Allow repeated pattern 0xXY00XY00. */
2445 /* Return true if I is a valid constant for the operation CODE. */
2447 const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code)
2449 if (const_ok_for_arm (i))
2455 /* See if we can use movw. */
2456 if (arm_arch_thumb2 && (i & 0xffff0000) == 0)
2459 /* Otherwise, try mvn. */
2460 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
2463 /* See if we can use addw or subw. */
2465 && ((i & 0xfffff000) == 0
2466 || ((-i) & 0xfffff000) == 0))
2468 /* else fall through. */
2488 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
2490 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
2496 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
2500 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
2507 /* Emit a sequence of insns to handle a large constant.
2508 CODE is the code of the operation required, it can be any of SET, PLUS,
2509 IOR, AND, XOR, MINUS;
2510 MODE is the mode in which the operation is being performed;
2511 VAL is the integer to operate on;
2512 SOURCE is the other operand (a register, or a null-pointer for SET);
2513 SUBTARGETS means it is safe to create scratch registers if that will
2514 either produce a simpler sequence, or we will want to cse the values.
2515 Return value is the number of insns emitted. */
2517 /* ??? Tweak this for thumb2. */
2519 arm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn,
2520 HOST_WIDE_INT val, rtx target, rtx source, int subtargets)
2524 if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC)
2525 cond = COND_EXEC_TEST (PATTERN (insn));
2529 if (subtargets || code == SET
2530 || (GET_CODE (target) == REG && GET_CODE (source) == REG
2531 && REGNO (target) != REGNO (source)))
2533 /* After arm_reorg has been called, we can't fix up expensive
2534 constants by pushing them into memory so we must synthesize
2535 them in-line, regardless of the cost. This is only likely to
2536 be more costly on chips that have load delay slots and we are
2537 compiling without running the scheduler (so no splitting
2538 occurred before the final instruction emission).
2540 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
2542 if (!after_arm_reorg
2544 && (arm_gen_constant (code, mode, NULL_RTX, val, target, source,
2546 > (arm_constant_limit (optimize_function_for_size_p (cfun))
2551 /* Currently SET is the only monadic value for CODE, all
2552 the rest are diadic. */
2553 if (TARGET_USE_MOVT)
2554 arm_emit_movpair (target, GEN_INT (val));
2556 emit_set_insn (target, GEN_INT (val));
2562 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
2564 if (TARGET_USE_MOVT)
2565 arm_emit_movpair (temp, GEN_INT (val));
2567 emit_set_insn (temp, GEN_INT (val));
2569 /* For MINUS, the value is subtracted from, since we never
2570 have subtraction of a constant. */
2572 emit_set_insn (target, gen_rtx_MINUS (mode, temp, source));
2574 emit_set_insn (target,
2575 gen_rtx_fmt_ee (code, mode, source, temp));
2581 return arm_gen_constant (code, mode, cond, val, target, source, subtargets,
2585 /* Return a sequence of integers, in RETURN_SEQUENCE that fit into
2586 ARM/THUMB2 immediates, and add up to VAL.
2587 Thr function return value gives the number of insns required. */
2589 optimal_immediate_sequence (enum rtx_code code, unsigned HOST_WIDE_INT val,
2590 struct four_ints *return_sequence)
2592 int best_consecutive_zeros = 0;
2596 struct four_ints tmp_sequence;
2598 /* If we aren't targetting ARM, the best place to start is always at
2599 the bottom, otherwise look more closely. */
2602 for (i = 0; i < 32; i += 2)
2604 int consecutive_zeros = 0;
2606 if (!(val & (3 << i)))
2608 while ((i < 32) && !(val & (3 << i)))
2610 consecutive_zeros += 2;
2613 if (consecutive_zeros > best_consecutive_zeros)
2615 best_consecutive_zeros = consecutive_zeros;
2616 best_start = i - consecutive_zeros;
2623 /* So long as it won't require any more insns to do so, it's
2624 desirable to emit a small constant (in bits 0...9) in the last
2625 insn. This way there is more chance that it can be combined with
2626 a later addressing insn to form a pre-indexed load or store
2627 operation. Consider:
2629 *((volatile int *)0xe0000100) = 1;
2630 *((volatile int *)0xe0000110) = 2;
2632 We want this to wind up as:
2636 str rB, [rA, #0x100]
2638 str rB, [rA, #0x110]
2640 rather than having to synthesize both large constants from scratch.
2642 Therefore, we calculate how many insns would be required to emit
2643 the constant starting from `best_start', and also starting from
2644 zero (i.e. with bit 31 first to be output). If `best_start' doesn't
2645 yield a shorter sequence, we may as well use zero. */
2646 insns1 = optimal_immediate_sequence_1 (code, val, return_sequence, best_start);
2648 && ((((unsigned HOST_WIDE_INT) 1) << best_start) < val))
2650 insns2 = optimal_immediate_sequence_1 (code, val, &tmp_sequence, 0);
2651 if (insns2 <= insns1)
2653 *return_sequence = tmp_sequence;
2661 /* As for optimal_immediate_sequence, but starting at bit-position I. */
2663 optimal_immediate_sequence_1 (enum rtx_code code, unsigned HOST_WIDE_INT val,
2664 struct four_ints *return_sequence, int i)
2666 int remainder = val & 0xffffffff;
2669 /* Try and find a way of doing the job in either two or three
2672 In ARM mode we can use 8-bit constants, rotated to any 2-bit aligned
2673 location. We start at position I. This may be the MSB, or
2674 optimial_immediate_sequence may have positioned it at the largest block
2675 of zeros that are aligned on a 2-bit boundary. We then fill up the temps,
2676 wrapping around to the top of the word when we drop off the bottom.
2677 In the worst case this code should produce no more than four insns.
2679 In Thumb2 mode, we can use 32/16-bit replicated constants, and 8-bit
2680 constants, shifted to any arbitrary location. We should always start
2685 unsigned int b1, b2, b3, b4;
2686 unsigned HOST_WIDE_INT result;
2689 gcc_assert (insns < 4);
2694 /* First, find the next normal 12/8-bit shifted/rotated immediate. */
2695 if (remainder & ((TARGET_ARM ? (3 << (i - 2)) : (1 << (i - 1)))))
2698 if (i <= 12 && TARGET_THUMB2 && code == PLUS)
2699 /* We can use addw/subw for the last 12 bits. */
2703 /* Use an 8-bit shifted/rotated immediate. */
2707 result = remainder & ((0x0ff << end)
2708 | ((i < end) ? (0xff >> (32 - end))
2715 /* Arm allows rotates by a multiple of two. Thumb-2 allows
2716 arbitrary shifts. */
2717 i -= TARGET_ARM ? 2 : 1;
2721 /* Next, see if we can do a better job with a thumb2 replicated
2724 We do it this way around to catch the cases like 0x01F001E0 where
2725 two 8-bit immediates would work, but a replicated constant would
2728 TODO: 16-bit constants that don't clear all the bits, but still win.
2729 TODO: Arithmetic splitting for set/add/sub, rather than bitwise. */
2732 b1 = (remainder & 0xff000000) >> 24;
2733 b2 = (remainder & 0x00ff0000) >> 16;
2734 b3 = (remainder & 0x0000ff00) >> 8;
2735 b4 = remainder & 0xff;
2739 /* The 8-bit immediate already found clears b1 (and maybe b2),
2740 but must leave b3 and b4 alone. */
2742 /* First try to find a 32-bit replicated constant that clears
2743 almost everything. We can assume that we can't do it in one,
2744 or else we wouldn't be here. */
2745 unsigned int tmp = b1 & b2 & b3 & b4;
2746 unsigned int tmp2 = tmp + (tmp << 8) + (tmp << 16)
2748 unsigned int matching_bytes = (tmp == b1) + (tmp == b2)
2749 + (tmp == b3) + (tmp == b4);
2751 && (matching_bytes >= 3
2752 || (matching_bytes == 2
2753 && const_ok_for_op (remainder & ~tmp2, code))))
2755 /* At least 3 of the bytes match, and the fourth has at
2756 least as many bits set, or two of the bytes match
2757 and it will only require one more insn to finish. */
2765 /* Second, try to find a 16-bit replicated constant that can
2766 leave three of the bytes clear. If b2 or b4 is already
2767 zero, then we can. If the 8-bit from above would not
2768 clear b2 anyway, then we still win. */
2769 else if (b1 == b3 && (!b2 || !b4
2770 || (remainder & 0x00ff0000 & ~result)))
2772 result = remainder & 0xff00ff00;
2778 /* The 8-bit immediate already found clears b2 (and maybe b3)
2779 and we don't get here unless b1 is alredy clear, but it will
2780 leave b4 unchanged. */
2782 /* If we can clear b2 and b4 at once, then we win, since the
2783 8-bits couldn't possibly reach that far. */
2786 result = remainder & 0x00ff00ff;
2792 return_sequence->i[insns++] = result;
2793 remainder &= ~result;
2795 if (code == SET || code == MINUS)
2803 /* Emit an instruction with the indicated PATTERN. If COND is
2804 non-NULL, conditionalize the execution of the instruction on COND
2808 emit_constant_insn (rtx cond, rtx pattern)
2811 pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern);
2812 emit_insn (pattern);
2815 /* As above, but extra parameter GENERATE which, if clear, suppresses
2819 arm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond,
2820 HOST_WIDE_INT val, rtx target, rtx source, int subtargets,
2825 int final_invert = 0;
2827 int set_sign_bit_copies = 0;
2828 int clear_sign_bit_copies = 0;
2829 int clear_zero_bit_copies = 0;
2830 int set_zero_bit_copies = 0;
2831 int insns = 0, neg_insns, inv_insns;
2832 unsigned HOST_WIDE_INT temp1, temp2;
2833 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
2834 struct four_ints *immediates;
2835 struct four_ints pos_immediates, neg_immediates, inv_immediates;
2837 /* Find out which operations are safe for a given CODE. Also do a quick
2838 check for degenerate cases; these can occur when DImode operations
2851 if (remainder == 0xffffffff)
2854 emit_constant_insn (cond,
2855 gen_rtx_SET (VOIDmode, target,
2856 GEN_INT (ARM_SIGN_EXTEND (val))));
2862 if (reload_completed && rtx_equal_p (target, source))
2866 emit_constant_insn (cond,
2867 gen_rtx_SET (VOIDmode, target, source));
2876 emit_constant_insn (cond,
2877 gen_rtx_SET (VOIDmode, target, const0_rtx));
2880 if (remainder == 0xffffffff)
2882 if (reload_completed && rtx_equal_p (target, source))
2885 emit_constant_insn (cond,
2886 gen_rtx_SET (VOIDmode, target, source));
2895 if (reload_completed && rtx_equal_p (target, source))
2898 emit_constant_insn (cond,
2899 gen_rtx_SET (VOIDmode, target, source));
2903 if (remainder == 0xffffffff)
2906 emit_constant_insn (cond,
2907 gen_rtx_SET (VOIDmode, target,
2908 gen_rtx_NOT (mode, source)));
2915 /* We treat MINUS as (val - source), since (source - val) is always
2916 passed as (source + (-val)). */
2920 emit_constant_insn (cond,
2921 gen_rtx_SET (VOIDmode, target,
2922 gen_rtx_NEG (mode, source)));
2925 if (const_ok_for_arm (val))
2928 emit_constant_insn (cond,
2929 gen_rtx_SET (VOIDmode, target,
2930 gen_rtx_MINUS (mode, GEN_INT (val),
2941 /* If we can do it in one insn get out quickly. */
2942 if (const_ok_for_op (val, code))
2945 emit_constant_insn (cond,
2946 gen_rtx_SET (VOIDmode, target,
2948 ? gen_rtx_fmt_ee (code, mode, source,
2954 /* Calculate a few attributes that may be useful for specific
2956 /* Count number of leading zeros. */
2957 for (i = 31; i >= 0; i--)
2959 if ((remainder & (1 << i)) == 0)
2960 clear_sign_bit_copies++;
2965 /* Count number of leading 1's. */
2966 for (i = 31; i >= 0; i--)
2968 if ((remainder & (1 << i)) != 0)
2969 set_sign_bit_copies++;
2974 /* Count number of trailing zero's. */
2975 for (i = 0; i <= 31; i++)
2977 if ((remainder & (1 << i)) == 0)
2978 clear_zero_bit_copies++;
2983 /* Count number of trailing 1's. */
2984 for (i = 0; i <= 31; i++)
2986 if ((remainder & (1 << i)) != 0)
2987 set_zero_bit_copies++;
2995 /* See if we can do this by sign_extending a constant that is known
2996 to be negative. This is a good, way of doing it, since the shift
2997 may well merge into a subsequent insn. */
2998 if (set_sign_bit_copies > 1)
3000 if (const_ok_for_arm
3001 (temp1 = ARM_SIGN_EXTEND (remainder
3002 << (set_sign_bit_copies - 1))))
3006 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3007 emit_constant_insn (cond,
3008 gen_rtx_SET (VOIDmode, new_src,
3010 emit_constant_insn (cond,
3011 gen_ashrsi3 (target, new_src,
3012 GEN_INT (set_sign_bit_copies - 1)));
3016 /* For an inverted constant, we will need to set the low bits,
3017 these will be shifted out of harm's way. */
3018 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
3019 if (const_ok_for_arm (~temp1))
3023 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3024 emit_constant_insn (cond,
3025 gen_rtx_SET (VOIDmode, new_src,
3027 emit_constant_insn (cond,
3028 gen_ashrsi3 (target, new_src,
3029 GEN_INT (set_sign_bit_copies - 1)));
3035 /* See if we can calculate the value as the difference between two
3036 valid immediates. */
3037 if (clear_sign_bit_copies + clear_zero_bit_copies <= 16)
3039 int topshift = clear_sign_bit_copies & ~1;
3041 temp1 = ARM_SIGN_EXTEND ((remainder + (0x00800000 >> topshift))
3042 & (0xff000000 >> topshift));
3044 /* If temp1 is zero, then that means the 9 most significant
3045 bits of remainder were 1 and we've caused it to overflow.
3046 When topshift is 0 we don't need to do anything since we
3047 can borrow from 'bit 32'. */
3048 if (temp1 == 0 && topshift != 0)
3049 temp1 = 0x80000000 >> (topshift - 1);
3051 temp2 = ARM_SIGN_EXTEND (temp1 - remainder);
3053 if (const_ok_for_arm (temp2))
3057 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3058 emit_constant_insn (cond,
3059 gen_rtx_SET (VOIDmode, new_src,
3061 emit_constant_insn (cond,
3062 gen_addsi3 (target, new_src,
3070 /* See if we can generate this by setting the bottom (or the top)
3071 16 bits, and then shifting these into the other half of the
3072 word. We only look for the simplest cases, to do more would cost
3073 too much. Be careful, however, not to generate this when the
3074 alternative would take fewer insns. */
3075 if (val & 0xffff0000)
3077 temp1 = remainder & 0xffff0000;
3078 temp2 = remainder & 0x0000ffff;
3080 /* Overlaps outside this range are best done using other methods. */
3081 for (i = 9; i < 24; i++)
3083 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
3084 && !const_ok_for_arm (temp2))
3086 rtx new_src = (subtargets
3087 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
3089 insns = arm_gen_constant (code, mode, cond, temp2, new_src,
3090 source, subtargets, generate);
3098 gen_rtx_ASHIFT (mode, source,
3105 /* Don't duplicate cases already considered. */
3106 for (i = 17; i < 24; i++)
3108 if (((temp1 | (temp1 >> i)) == remainder)
3109 && !const_ok_for_arm (temp1))
3111 rtx new_src = (subtargets
3112 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
3114 insns = arm_gen_constant (code, mode, cond, temp1, new_src,
3115 source, subtargets, generate);
3120 gen_rtx_SET (VOIDmode, target,
3123 gen_rtx_LSHIFTRT (mode, source,
3134 /* If we have IOR or XOR, and the constant can be loaded in a
3135 single instruction, and we can find a temporary to put it in,
3136 then this can be done in two instructions instead of 3-4. */
3138 /* TARGET can't be NULL if SUBTARGETS is 0 */
3139 || (reload_completed && !reg_mentioned_p (target, source)))
3141 if (const_ok_for_arm (ARM_SIGN_EXTEND (~val)))
3145 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3147 emit_constant_insn (cond,
3148 gen_rtx_SET (VOIDmode, sub,
3150 emit_constant_insn (cond,
3151 gen_rtx_SET (VOIDmode, target,
3152 gen_rtx_fmt_ee (code, mode,
3163 x = y | constant ( which is composed of set_sign_bit_copies of leading 1s
3164 and the remainder 0s for e.g. 0xfff00000)
3165 x = ~(~(y ashift set_sign_bit_copies) lshiftrt set_sign_bit_copies)
3167 This can be done in 2 instructions by using shifts with mov or mvn.
3172 mvn r0, r0, lsr #12 */
3173 if (set_sign_bit_copies > 8
3174 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
3178 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3179 rtx shift = GEN_INT (set_sign_bit_copies);
3183 gen_rtx_SET (VOIDmode, sub,
3185 gen_rtx_ASHIFT (mode,
3190 gen_rtx_SET (VOIDmode, target,
3192 gen_rtx_LSHIFTRT (mode, sub,
3199 x = y | constant (which has set_zero_bit_copies number of trailing ones).
3201 x = ~((~y lshiftrt set_zero_bit_copies) ashift set_zero_bit_copies).
3203 For eg. r0 = r0 | 0xfff
3208 if (set_zero_bit_copies > 8
3209 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
3213 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3214 rtx shift = GEN_INT (set_zero_bit_copies);
3218 gen_rtx_SET (VOIDmode, sub,
3220 gen_rtx_LSHIFTRT (mode,
3225 gen_rtx_SET (VOIDmode, target,
3227 gen_rtx_ASHIFT (mode, sub,
3233 /* This will never be reached for Thumb2 because orn is a valid
3234 instruction. This is for Thumb1 and the ARM 32 bit cases.
3236 x = y | constant (such that ~constant is a valid constant)
3238 x = ~(~y & ~constant).
3240 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val)))
3244 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3245 emit_constant_insn (cond,
3246 gen_rtx_SET (VOIDmode, sub,
3247 gen_rtx_NOT (mode, source)));
3250 sub = gen_reg_rtx (mode);
3251 emit_constant_insn (cond,
3252 gen_rtx_SET (VOIDmode, sub,
3253 gen_rtx_AND (mode, source,
3255 emit_constant_insn (cond,
3256 gen_rtx_SET (VOIDmode, target,
3257 gen_rtx_NOT (mode, sub)));
3264 /* See if two shifts will do 2 or more insn's worth of work. */
3265 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
3267 HOST_WIDE_INT shift_mask = ((0xffffffff
3268 << (32 - clear_sign_bit_copies))
3271 if ((remainder | shift_mask) != 0xffffffff)
3275 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3276 insns = arm_gen_constant (AND, mode, cond,
3277 remainder | shift_mask,
3278 new_src, source, subtargets, 1);
3283 rtx targ = subtargets ? NULL_RTX : target;
3284 insns = arm_gen_constant (AND, mode, cond,
3285 remainder | shift_mask,
3286 targ, source, subtargets, 0);
3292 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3293 rtx shift = GEN_INT (clear_sign_bit_copies);
3295 emit_insn (gen_ashlsi3 (new_src, source, shift));
3296 emit_insn (gen_lshrsi3 (target, new_src, shift));
3302 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
3304 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
3306 if ((remainder | shift_mask) != 0xffffffff)
3310 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3312 insns = arm_gen_constant (AND, mode, cond,
3313 remainder | shift_mask,
3314 new_src, source, subtargets, 1);
3319 rtx targ = subtargets ? NULL_RTX : target;
3321 insns = arm_gen_constant (AND, mode, cond,
3322 remainder | shift_mask,
3323 targ, source, subtargets, 0);
3329 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3330 rtx shift = GEN_INT (clear_zero_bit_copies);
3332 emit_insn (gen_lshrsi3 (new_src, source, shift));
3333 emit_insn (gen_ashlsi3 (target, new_src, shift));
3345 /* Calculate what the instruction sequences would be if we generated it
3346 normally, negated, or inverted. */
3348 /* AND cannot be split into multiple insns, so invert and use BIC. */
3351 insns = optimal_immediate_sequence (code, remainder, &pos_immediates);
3354 neg_insns = optimal_immediate_sequence (code, (-remainder) & 0xffffffff,
3359 if (can_invert || final_invert)
3360 inv_insns = optimal_immediate_sequence (code, remainder ^ 0xffffffff,
3365 immediates = &pos_immediates;
3367 /* Is the negated immediate sequence more efficient? */
3368 if (neg_insns < insns && neg_insns <= inv_insns)
3371 immediates = &neg_immediates;
3376 /* Is the inverted immediate sequence more efficient?
3377 We must allow for an extra NOT instruction for XOR operations, although
3378 there is some chance that the final 'mvn' will get optimized later. */
3379 if ((inv_insns + 1) < insns || (!final_invert && inv_insns < insns))
3382 immediates = &inv_immediates;
3390 /* Now output the chosen sequence as instructions. */
3393 for (i = 0; i < insns; i++)
3395 rtx new_src, temp1_rtx;
3397 temp1 = immediates->i[i];
3399 if (code == SET || code == MINUS)
3400 new_src = (subtargets ? gen_reg_rtx (mode) : target);
3401 else if ((final_invert || i < (insns - 1)) && subtargets)
3402 new_src = gen_reg_rtx (mode);
3408 else if (can_negate)
3411 temp1 = trunc_int_for_mode (temp1, mode);
3412 temp1_rtx = GEN_INT (temp1);
3416 else if (code == MINUS)
3417 temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source);
3419 temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx);
3421 emit_constant_insn (cond,
3422 gen_rtx_SET (VOIDmode, new_src,
3428 can_negate = can_invert;
3432 else if (code == MINUS)
3440 emit_constant_insn (cond, gen_rtx_SET (VOIDmode, target,
3441 gen_rtx_NOT (mode, source)));
3448 /* Canonicalize a comparison so that we are more likely to recognize it.
3449 This can be done for a few constant compares, where we can make the
3450 immediate value easier to load. */
3453 arm_canonicalize_comparison (enum rtx_code code, rtx *op0, rtx *op1)
3455 enum machine_mode mode;
3456 unsigned HOST_WIDE_INT i, maxval;
3458 mode = GET_MODE (*op0);
3459 if (mode == VOIDmode)
3460 mode = GET_MODE (*op1);
3462 maxval = (((unsigned HOST_WIDE_INT) 1) << (GET_MODE_BITSIZE(mode) - 1)) - 1;
3464 /* For DImode, we have GE/LT/GEU/LTU comparisons. In ARM mode
3465 we can also use cmp/cmpeq for GTU/LEU. GT/LE must be either
3466 reversed or (for constant OP1) adjusted to GE/LT. Similarly
3467 for GTU/LEU in Thumb mode. */
3472 /* To keep things simple, always use the Cirrus cfcmp64 if it is
3474 if (TARGET_ARM && TARGET_HARD_FLOAT && TARGET_MAVERICK)
3477 if (code == GT || code == LE
3478 || (!TARGET_ARM && (code == GTU || code == LEU)))
3480 /* Missing comparison. First try to use an available
3482 if (GET_CODE (*op1) == CONST_INT)
3490 && arm_const_double_by_immediates (GEN_INT (i + 1)))
3492 *op1 = GEN_INT (i + 1);
3493 return code == GT ? GE : LT;
3498 if (i != ~((unsigned HOST_WIDE_INT) 0)
3499 && arm_const_double_by_immediates (GEN_INT (i + 1)))
3501 *op1 = GEN_INT (i + 1);
3502 return code == GTU ? GEU : LTU;
3510 /* If that did not work, reverse the condition. */
3514 return swap_condition (code);
3520 /* If *op0 is (zero_extend:SI (subreg:QI (reg:SI) 0)) and comparing
3521 with const0_rtx, change it to (and:SI (reg:SI) (const_int 255)),
3522 to facilitate possible combining with a cmp into 'ands'. */
3524 && GET_CODE (*op0) == ZERO_EXTEND
3525 && GET_CODE (XEXP (*op0, 0)) == SUBREG
3526 && GET_MODE (XEXP (*op0, 0)) == QImode
3527 && GET_MODE (SUBREG_REG (XEXP (*op0, 0))) == SImode
3528 && subreg_lowpart_p (XEXP (*op0, 0))
3529 && *op1 == const0_rtx)
3530 *op0 = gen_rtx_AND (SImode, SUBREG_REG (XEXP (*op0, 0)),
3533 /* Comparisons smaller than DImode. Only adjust comparisons against
3534 an out-of-range constant. */
3535 if (GET_CODE (*op1) != CONST_INT
3536 || const_ok_for_arm (INTVAL (*op1))
3537 || const_ok_for_arm (- INTVAL (*op1)))
3551 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
3553 *op1 = GEN_INT (i + 1);
3554 return code == GT ? GE : LT;
3561 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
3563 *op1 = GEN_INT (i - 1);
3564 return code == GE ? GT : LE;
3570 if (i != ~((unsigned HOST_WIDE_INT) 0)
3571 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
3573 *op1 = GEN_INT (i + 1);
3574 return code == GTU ? GEU : LTU;
3581 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
3583 *op1 = GEN_INT (i - 1);
3584 return code == GEU ? GTU : LEU;
3596 /* Define how to find the value returned by a function. */
3599 arm_function_value(const_tree type, const_tree func,
3600 bool outgoing ATTRIBUTE_UNUSED)
3602 enum machine_mode mode;
3603 int unsignedp ATTRIBUTE_UNUSED;
3604 rtx r ATTRIBUTE_UNUSED;
3606 mode = TYPE_MODE (type);
3608 if (TARGET_AAPCS_BASED)
3609 return aapcs_allocate_return_reg (mode, type, func);
3611 /* Promote integer types. */
3612 if (INTEGRAL_TYPE_P (type))
3613 mode = arm_promote_function_mode (type, mode, &unsignedp, func, 1);
3615 /* Promotes small structs returned in a register to full-word size
3616 for big-endian AAPCS. */
3617 if (arm_return_in_msb (type))
3619 HOST_WIDE_INT size = int_size_in_bytes (type);
3620 if (size % UNITS_PER_WORD != 0)
3622 size += UNITS_PER_WORD - size % UNITS_PER_WORD;
3623 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
3627 return arm_libcall_value_1 (mode);
3631 libcall_eq (const void *p1, const void *p2)
3633 return rtx_equal_p ((const_rtx) p1, (const_rtx) p2);
3637 libcall_hash (const void *p1)
3639 return hash_rtx ((const_rtx) p1, VOIDmode, NULL, NULL, FALSE);
3643 add_libcall (htab_t htab, rtx libcall)
3645 *htab_find_slot (htab, libcall, INSERT) = libcall;
3649 arm_libcall_uses_aapcs_base (const_rtx libcall)
3651 static bool init_done = false;
3652 static htab_t libcall_htab;
3658 libcall_htab = htab_create (31, libcall_hash, libcall_eq,
3660 add_libcall (libcall_htab,
3661 convert_optab_libfunc (sfloat_optab, SFmode, SImode));
3662 add_libcall (libcall_htab,
3663 convert_optab_libfunc (sfloat_optab, DFmode, SImode));
3664 add_libcall (libcall_htab,
3665 convert_optab_libfunc (sfloat_optab, SFmode, DImode));
3666 add_libcall (libcall_htab,
3667 convert_optab_libfunc (sfloat_optab, DFmode, DImode));
3669 add_libcall (libcall_htab,
3670 convert_optab_libfunc (ufloat_optab, SFmode, SImode));
3671 add_libcall (libcall_htab,
3672 convert_optab_libfunc (ufloat_optab, DFmode, SImode));
3673 add_libcall (libcall_htab,
3674 convert_optab_libfunc (ufloat_optab, SFmode, DImode));
3675 add_libcall (libcall_htab,
3676 convert_optab_libfunc (ufloat_optab, DFmode, DImode));
3678 add_libcall (libcall_htab,
3679 convert_optab_libfunc (sext_optab, SFmode, HFmode));
3680 add_libcall (libcall_htab,
3681 convert_optab_libfunc (trunc_optab, HFmode, SFmode));
3682 add_libcall (libcall_htab,
3683 convert_optab_libfunc (sfix_optab, DImode, DFmode));
3684 add_libcall (libcall_htab,
3685 convert_optab_libfunc (ufix_optab, DImode, DFmode));
3686 add_libcall (libcall_htab,
3687 convert_optab_libfunc (sfix_optab, DImode, SFmode));
3688 add_libcall (libcall_htab,
3689 convert_optab_libfunc (ufix_optab, DImode, SFmode));
3691 /* Values from double-precision helper functions are returned in core
3692 registers if the selected core only supports single-precision
3693 arithmetic, even if we are using the hard-float ABI. The same is
3694 true for single-precision helpers, but we will never be using the
3695 hard-float ABI on a CPU which doesn't support single-precision
3696 operations in hardware. */
3697 add_libcall (libcall_htab, optab_libfunc (add_optab, DFmode));
3698 add_libcall (libcall_htab, optab_libfunc (sdiv_optab, DFmode));
3699 add_libcall (libcall_htab, optab_libfunc (smul_optab, DFmode));
3700 add_libcall (libcall_htab, optab_libfunc (neg_optab, DFmode));
3701 add_libcall (libcall_htab, optab_libfunc (sub_optab, DFmode));
3702 add_libcall (libcall_htab, optab_libfunc (eq_optab, DFmode));
3703 add_libcall (libcall_htab, optab_libfunc (lt_optab, DFmode));
3704 add_libcall (libcall_htab, optab_libfunc (le_optab, DFmode));
3705 add_libcall (libcall_htab, optab_libfunc (ge_optab, DFmode));
3706 add_libcall (libcall_htab, optab_libfunc (gt_optab, DFmode));
3707 add_libcall (libcall_htab, optab_libfunc (unord_optab, DFmode));
3708 add_libcall (libcall_htab, convert_optab_libfunc (sext_optab, DFmode,
3710 add_libcall (libcall_htab, convert_optab_libfunc (trunc_optab, SFmode,
3714 return libcall && htab_find (libcall_htab, libcall) != NULL;
3718 arm_libcall_value_1 (enum machine_mode mode)
3720 if (TARGET_AAPCS_BASED)
3721 return aapcs_libcall_value (mode);
3722 else if (TARGET_32BIT
3723 && TARGET_HARD_FLOAT_ABI
3725 && GET_MODE_CLASS (mode) == MODE_FLOAT)
3726 return gen_rtx_REG (mode, FIRST_FPA_REGNUM);
3727 else if (TARGET_32BIT
3728 && TARGET_HARD_FLOAT_ABI
3730 && GET_MODE_CLASS (mode) == MODE_FLOAT)
3731 return gen_rtx_REG (mode, FIRST_CIRRUS_FP_REGNUM);
3732 else if (TARGET_IWMMXT_ABI
3733 && arm_vector_mode_supported_p (mode))
3734 return gen_rtx_REG (mode, FIRST_IWMMXT_REGNUM);
3736 return gen_rtx_REG (mode, ARG_REGISTER (1));
3739 /* Define how to find the value returned by a library function
3740 assuming the value has mode MODE. */
3743 arm_libcall_value (enum machine_mode mode, const_rtx libcall)
3745 if (TARGET_AAPCS_BASED && arm_pcs_default != ARM_PCS_AAPCS
3746 && GET_MODE_CLASS (mode) == MODE_FLOAT)
3748 /* The following libcalls return their result in integer registers,
3749 even though they return a floating point value. */
3750 if (arm_libcall_uses_aapcs_base (libcall))
3751 return gen_rtx_REG (mode, ARG_REGISTER(1));
3755 return arm_libcall_value_1 (mode);
3758 /* Implement TARGET_FUNCTION_VALUE_REGNO_P. */
3761 arm_function_value_regno_p (const unsigned int regno)
3763 if (regno == ARG_REGISTER (1)
3765 && TARGET_AAPCS_BASED
3767 && TARGET_HARD_FLOAT
3768 && regno == FIRST_VFP_REGNUM)
3770 && TARGET_HARD_FLOAT_ABI
3772 && regno == FIRST_CIRRUS_FP_REGNUM)
3773 || (TARGET_IWMMXT_ABI
3774 && regno == FIRST_IWMMXT_REGNUM)
3776 && TARGET_HARD_FLOAT_ABI
3778 && regno == FIRST_FPA_REGNUM))
3784 /* Determine the amount of memory needed to store the possible return
3785 registers of an untyped call. */
3787 arm_apply_result_size (void)
3793 if (TARGET_HARD_FLOAT_ABI)
3799 if (TARGET_MAVERICK)
3802 if (TARGET_IWMMXT_ABI)
3809 /* Decide whether TYPE should be returned in memory (true)
3810 or in a register (false). FNTYPE is the type of the function making
3813 arm_return_in_memory (const_tree type, const_tree fntype)
3817 size = int_size_in_bytes (type); /* Negative if not fixed size. */
3819 if (TARGET_AAPCS_BASED)
3821 /* Simple, non-aggregate types (ie not including vectors and
3822 complex) are always returned in a register (or registers).
3823 We don't care about which register here, so we can short-cut
3824 some of the detail. */
3825 if (!AGGREGATE_TYPE_P (type)
3826 && TREE_CODE (type) != VECTOR_TYPE
3827 && TREE_CODE (type) != COMPLEX_TYPE)
3830 /* Any return value that is no larger than one word can be
3832 if (((unsigned HOST_WIDE_INT) size) <= UNITS_PER_WORD)
3835 /* Check any available co-processors to see if they accept the
3836 type as a register candidate (VFP, for example, can return
3837 some aggregates in consecutive registers). These aren't
3838 available if the call is variadic. */
3839 if (aapcs_select_return_coproc (type, fntype) >= 0)
3842 /* Vector values should be returned using ARM registers, not
3843 memory (unless they're over 16 bytes, which will break since
3844 we only have four call-clobbered registers to play with). */
3845 if (TREE_CODE (type) == VECTOR_TYPE)
3846 return (size < 0 || size > (4 * UNITS_PER_WORD));
3848 /* The rest go in memory. */
3852 if (TREE_CODE (type) == VECTOR_TYPE)
3853 return (size < 0 || size > (4 * UNITS_PER_WORD));
3855 if (!AGGREGATE_TYPE_P (type) &&
3856 (TREE_CODE (type) != VECTOR_TYPE))
3857 /* All simple types are returned in registers. */
3860 if (arm_abi != ARM_ABI_APCS)
3862 /* ATPCS and later return aggregate types in memory only if they are
3863 larger than a word (or are variable size). */
3864 return (size < 0 || size > UNITS_PER_WORD);
3867 /* For the arm-wince targets we choose to be compatible with Microsoft's
3868 ARM and Thumb compilers, which always return aggregates in memory. */
3870 /* All structures/unions bigger than one word are returned in memory.
3871 Also catch the case where int_size_in_bytes returns -1. In this case
3872 the aggregate is either huge or of variable size, and in either case
3873 we will want to return it via memory and not in a register. */
3874 if (size < 0 || size > UNITS_PER_WORD)
3877 if (TREE_CODE (type) == RECORD_TYPE)
3881 /* For a struct the APCS says that we only return in a register
3882 if the type is 'integer like' and every addressable element
3883 has an offset of zero. For practical purposes this means
3884 that the structure can have at most one non bit-field element
3885 and that this element must be the first one in the structure. */
3887 /* Find the first field, ignoring non FIELD_DECL things which will
3888 have been created by C++. */
3889 for (field = TYPE_FIELDS (type);
3890 field && TREE_CODE (field) != FIELD_DECL;
3891 field = DECL_CHAIN (field))
3895 return false; /* An empty structure. Allowed by an extension to ANSI C. */
3897 /* Check that the first field is valid for returning in a register. */
3899 /* ... Floats are not allowed */
3900 if (FLOAT_TYPE_P (TREE_TYPE (field)))
3903 /* ... Aggregates that are not themselves valid for returning in
3904 a register are not allowed. */
3905 if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE))
3908 /* Now check the remaining fields, if any. Only bitfields are allowed,
3909 since they are not addressable. */
3910 for (field = DECL_CHAIN (field);
3912 field = DECL_CHAIN (field))
3914 if (TREE_CODE (field) != FIELD_DECL)
3917 if (!DECL_BIT_FIELD_TYPE (field))
3924 if (TREE_CODE (type) == UNION_TYPE)
3928 /* Unions can be returned in registers if every element is
3929 integral, or can be returned in an integer register. */
3930 for (field = TYPE_FIELDS (type);
3932 field = DECL_CHAIN (field))
3934 if (TREE_CODE (field) != FIELD_DECL)
3937 if (FLOAT_TYPE_P (TREE_TYPE (field)))
3940 if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE))
3946 #endif /* not ARM_WINCE */
3948 /* Return all other types in memory. */
3952 /* Indicate whether or not words of a double are in big-endian order. */
3955 arm_float_words_big_endian (void)
3957 if (TARGET_MAVERICK)
3960 /* For FPA, float words are always big-endian. For VFP, floats words
3961 follow the memory system mode. */