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
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"
60 /* Forward definitions of types. */
61 typedef struct minipool_node Mnode;
62 typedef struct minipool_fixup Mfix;
64 void (*arm_lang_output_object_attributes_hook)(void);
66 /* Forward function declarations. */
67 static bool arm_needs_doubleword_align (enum machine_mode, const_tree);
68 static int arm_compute_static_chain_stack_bytes (void);
69 static arm_stack_offsets *arm_get_frame_offsets (void);
70 static void arm_add_gc_roots (void);
71 static int arm_gen_constant (enum rtx_code, enum machine_mode, rtx,
72 HOST_WIDE_INT, rtx, rtx, int, int);
73 static unsigned bit_count (unsigned long);
74 static int arm_address_register_rtx_p (rtx, int);
75 static int arm_legitimate_index_p (enum machine_mode, rtx, RTX_CODE, int);
76 static int thumb2_legitimate_index_p (enum machine_mode, rtx, int);
77 static int thumb1_base_register_rtx_p (rtx, enum machine_mode, int);
78 static rtx arm_legitimize_address (rtx, rtx, enum machine_mode);
79 static rtx thumb_legitimize_address (rtx, rtx, enum machine_mode);
80 inline static int thumb1_index_register_rtx_p (rtx, int);
81 static bool arm_legitimate_address_p (enum machine_mode, rtx, bool);
82 static int thumb_far_jump_used_p (void);
83 static bool thumb_force_lr_save (void);
84 static int const_ok_for_op (HOST_WIDE_INT, enum rtx_code);
85 static rtx emit_sfm (int, int);
86 static unsigned arm_size_return_regs (void);
87 static bool arm_assemble_integer (rtx, unsigned int, int);
88 static void arm_print_operand (FILE *, rtx, int);
89 static void arm_print_operand_address (FILE *, rtx);
90 static bool arm_print_operand_punct_valid_p (unsigned char code);
91 static const char *fp_const_from_val (REAL_VALUE_TYPE *);
92 static arm_cc get_arm_condition_code (rtx);
93 static HOST_WIDE_INT int_log2 (HOST_WIDE_INT);
94 static rtx is_jump_table (rtx);
95 static const char *output_multi_immediate (rtx *, const char *, const char *,
97 static const char *shift_op (rtx, HOST_WIDE_INT *);
98 static struct machine_function *arm_init_machine_status (void);
99 static void thumb_exit (FILE *, int);
100 static rtx is_jump_table (rtx);
101 static HOST_WIDE_INT get_jump_table_size (rtx);
102 static Mnode *move_minipool_fix_forward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
103 static Mnode *add_minipool_forward_ref (Mfix *);
104 static Mnode *move_minipool_fix_backward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
105 static Mnode *add_minipool_backward_ref (Mfix *);
106 static void assign_minipool_offsets (Mfix *);
107 static void arm_print_value (FILE *, rtx);
108 static void dump_minipool (rtx);
109 static int arm_barrier_cost (rtx);
110 static Mfix *create_fix_barrier (Mfix *, HOST_WIDE_INT);
111 static void push_minipool_barrier (rtx, HOST_WIDE_INT);
112 static void push_minipool_fix (rtx, HOST_WIDE_INT, rtx *, enum machine_mode,
114 static void arm_reorg (void);
115 static bool note_invalid_constants (rtx, HOST_WIDE_INT, int);
116 static unsigned long arm_compute_save_reg0_reg12_mask (void);
117 static unsigned long arm_compute_save_reg_mask (void);
118 static unsigned long arm_isr_value (tree);
119 static unsigned long arm_compute_func_type (void);
120 static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
121 static tree arm_handle_pcs_attribute (tree *, tree, tree, int, bool *);
122 static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *);
123 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
124 static tree arm_handle_notshared_attribute (tree *, tree, tree, int, bool *);
126 static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT);
127 static void arm_output_function_prologue (FILE *, HOST_WIDE_INT);
128 static void thumb1_output_function_prologue (FILE *, HOST_WIDE_INT);
129 static int arm_comp_type_attributes (const_tree, const_tree);
130 static void arm_set_default_type_attributes (tree);
131 static int arm_adjust_cost (rtx, rtx, rtx, int);
132 static int count_insns_for_constant (HOST_WIDE_INT, int);
133 static int arm_get_strip_length (int);
134 static bool arm_function_ok_for_sibcall (tree, tree);
135 static enum machine_mode arm_promote_function_mode (const_tree,
136 enum machine_mode, int *,
138 static bool arm_return_in_memory (const_tree, const_tree);
139 static rtx arm_function_value (const_tree, const_tree, bool);
140 static rtx arm_libcall_value (enum machine_mode, const_rtx);
142 static void arm_internal_label (FILE *, const char *, unsigned long);
143 static void arm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
145 static bool arm_have_conditional_execution (void);
146 static bool arm_rtx_costs_1 (rtx, enum rtx_code, int*, bool);
147 static bool arm_size_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *);
148 static bool arm_slowmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
149 static bool arm_fastmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
150 static bool arm_xscale_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
151 static bool arm_9e_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
152 static bool arm_rtx_costs (rtx, int, int, int *, bool);
153 static int arm_address_cost (rtx, bool);
154 static bool arm_memory_load_p (rtx);
155 static bool arm_cirrus_insn_p (rtx);
156 static void cirrus_reorg (rtx);
157 static void arm_init_builtins (void);
158 static void arm_init_iwmmxt_builtins (void);
159 static rtx safe_vector_operand (rtx, enum machine_mode);
160 static rtx arm_expand_binop_builtin (enum insn_code, tree, rtx);
161 static rtx arm_expand_unop_builtin (enum insn_code, tree, rtx, int);
162 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
163 static void emit_constant_insn (rtx cond, rtx pattern);
164 static rtx emit_set_insn (rtx, rtx);
165 static int arm_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
167 static rtx arm_function_arg (CUMULATIVE_ARGS *, enum machine_mode,
169 static void arm_function_arg_advance (CUMULATIVE_ARGS *, enum machine_mode,
171 static unsigned int arm_function_arg_boundary (enum machine_mode, const_tree);
172 static rtx aapcs_allocate_return_reg (enum machine_mode, const_tree,
174 static int aapcs_select_return_coproc (const_tree, const_tree);
176 #ifdef OBJECT_FORMAT_ELF
177 static void arm_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED;
178 static void arm_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED;
181 static void arm_encode_section_info (tree, rtx, int);
184 static void arm_file_end (void);
185 static void arm_file_start (void);
187 static void arm_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
189 static bool arm_pass_by_reference (CUMULATIVE_ARGS *,
190 enum machine_mode, const_tree, bool);
191 static bool arm_promote_prototypes (const_tree);
192 static bool arm_default_short_enums (void);
193 static bool arm_align_anon_bitfield (void);
194 static bool arm_return_in_msb (const_tree);
195 static bool arm_must_pass_in_stack (enum machine_mode, const_tree);
196 static bool arm_return_in_memory (const_tree, const_tree);
198 static void arm_unwind_emit (FILE *, rtx);
199 static bool arm_output_ttype (rtx);
200 static void arm_asm_emit_except_personality (rtx);
201 static void arm_asm_init_sections (void);
203 static enum unwind_info_type arm_except_unwind_info (struct gcc_options *);
204 static void arm_dwarf_handle_frame_unspec (const char *, rtx, int);
205 static rtx arm_dwarf_register_span (rtx);
207 static tree arm_cxx_guard_type (void);
208 static bool arm_cxx_guard_mask_bit (void);
209 static tree arm_get_cookie_size (tree);
210 static bool arm_cookie_has_size (void);
211 static bool arm_cxx_cdtor_returns_this (void);
212 static bool arm_cxx_key_method_may_be_inline (void);
213 static void arm_cxx_determine_class_data_visibility (tree);
214 static bool arm_cxx_class_data_always_comdat (void);
215 static bool arm_cxx_use_aeabi_atexit (void);
216 static void arm_init_libfuncs (void);
217 static tree arm_build_builtin_va_list (void);
218 static void arm_expand_builtin_va_start (tree, rtx);
219 static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
220 static void arm_option_override (void);
221 static bool arm_handle_option (size_t, const char *, int);
222 static void arm_target_help (void);
223 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode);
224 static bool arm_cannot_copy_insn_p (rtx);
225 static bool arm_tls_symbol_p (rtx x);
226 static int arm_issue_rate (void);
227 static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
228 static bool arm_output_addr_const_extra (FILE *, rtx);
229 static bool arm_allocate_stack_slots_for_args (void);
230 static const char *arm_invalid_parameter_type (const_tree t);
231 static const char *arm_invalid_return_type (const_tree t);
232 static tree arm_promoted_type (const_tree t);
233 static tree arm_convert_to_type (tree type, tree expr);
234 static bool arm_scalar_mode_supported_p (enum machine_mode);
235 static bool arm_frame_pointer_required (void);
236 static bool arm_can_eliminate (const int, const int);
237 static void arm_asm_trampoline_template (FILE *);
238 static void arm_trampoline_init (rtx, tree, rtx);
239 static rtx arm_trampoline_adjust_address (rtx);
240 static rtx arm_pic_static_addr (rtx orig, rtx reg);
241 static bool cortex_a9_sched_adjust_cost (rtx, rtx, rtx, int *);
242 static bool xscale_sched_adjust_cost (rtx, rtx, rtx, int *);
243 static enum machine_mode arm_preferred_simd_mode (enum machine_mode);
244 static bool arm_class_likely_spilled_p (reg_class_t);
245 static bool arm_vector_alignment_reachable (const_tree type, bool is_packed);
246 static bool arm_builtin_support_vector_misalignment (enum machine_mode mode,
250 static void arm_conditional_register_usage (void);
251 static reg_class_t arm_preferred_rename_class (reg_class_t class);
254 /* Table of machine attributes. */
255 static const struct attribute_spec arm_attribute_table[] =
257 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
258 /* Function calls made to this symbol must be done indirectly, because
259 it may lie outside of the 26 bit addressing range of a normal function
261 { "long_call", 0, 0, false, true, true, NULL },
262 /* Whereas these functions are always known to reside within the 26 bit
264 { "short_call", 0, 0, false, true, true, NULL },
265 /* Specify the procedure call conventions for a function. */
266 { "pcs", 1, 1, false, true, true, arm_handle_pcs_attribute },
267 /* Interrupt Service Routines have special prologue and epilogue requirements. */
268 { "isr", 0, 1, false, false, false, arm_handle_isr_attribute },
269 { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute },
270 { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute },
272 /* ARM/PE has three new attributes:
274 dllexport - for exporting a function/variable that will live in a dll
275 dllimport - for importing a function/variable from a dll
277 Microsoft allows multiple declspecs in one __declspec, separating
278 them with spaces. We do NOT support this. Instead, use __declspec
281 { "dllimport", 0, 0, true, false, false, NULL },
282 { "dllexport", 0, 0, true, false, false, NULL },
283 { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute },
284 #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
285 { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
286 { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
287 { "notshared", 0, 0, false, true, false, arm_handle_notshared_attribute },
289 { NULL, 0, 0, false, false, false, NULL }
292 /* Set default optimization options. */
293 static const struct default_options arm_option_optimization_table[] =
295 /* Enable section anchors by default at -O1 or higher. */
296 { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
297 { OPT_LEVELS_1_PLUS, OPT_fomit_frame_pointer, NULL, 1 },
298 { OPT_LEVELS_NONE, 0, NULL, 0 }
301 /* Initialize the GCC target structure. */
302 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
303 #undef TARGET_MERGE_DECL_ATTRIBUTES
304 #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
307 #undef TARGET_LEGITIMIZE_ADDRESS
308 #define TARGET_LEGITIMIZE_ADDRESS arm_legitimize_address
310 #undef TARGET_ATTRIBUTE_TABLE
311 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
313 #undef TARGET_ASM_FILE_START
314 #define TARGET_ASM_FILE_START arm_file_start
315 #undef TARGET_ASM_FILE_END
316 #define TARGET_ASM_FILE_END arm_file_end
318 #undef TARGET_ASM_ALIGNED_SI_OP
319 #define TARGET_ASM_ALIGNED_SI_OP NULL
320 #undef TARGET_ASM_INTEGER
321 #define TARGET_ASM_INTEGER arm_assemble_integer
323 #undef TARGET_PRINT_OPERAND
324 #define TARGET_PRINT_OPERAND arm_print_operand
325 #undef TARGET_PRINT_OPERAND_ADDRESS
326 #define TARGET_PRINT_OPERAND_ADDRESS arm_print_operand_address
327 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
328 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P arm_print_operand_punct_valid_p
330 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
331 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA arm_output_addr_const_extra
333 #undef TARGET_ASM_FUNCTION_PROLOGUE
334 #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue
336 #undef TARGET_ASM_FUNCTION_EPILOGUE
337 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
339 #undef TARGET_DEFAULT_TARGET_FLAGS
340 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_SCHED_PROLOG)
341 #undef TARGET_HANDLE_OPTION
342 #define TARGET_HANDLE_OPTION arm_handle_option
344 #define TARGET_HELP arm_target_help
345 #undef TARGET_OPTION_OVERRIDE
346 #define TARGET_OPTION_OVERRIDE arm_option_override
347 #undef TARGET_OPTION_OPTIMIZATION_TABLE
348 #define TARGET_OPTION_OPTIMIZATION_TABLE arm_option_optimization_table
350 #undef TARGET_COMP_TYPE_ATTRIBUTES
351 #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes
353 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
354 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes
356 #undef TARGET_SCHED_ADJUST_COST
357 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
359 #undef TARGET_ENCODE_SECTION_INFO
361 #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info
363 #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info
366 #undef TARGET_STRIP_NAME_ENCODING
367 #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding
369 #undef TARGET_ASM_INTERNAL_LABEL
370 #define TARGET_ASM_INTERNAL_LABEL arm_internal_label
372 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
373 #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall
375 #undef TARGET_FUNCTION_VALUE
376 #define TARGET_FUNCTION_VALUE arm_function_value
378 #undef TARGET_LIBCALL_VALUE
379 #define TARGET_LIBCALL_VALUE arm_libcall_value
381 #undef TARGET_ASM_OUTPUT_MI_THUNK
382 #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk
383 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
384 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
386 #undef TARGET_RTX_COSTS
387 #define TARGET_RTX_COSTS arm_rtx_costs
388 #undef TARGET_ADDRESS_COST
389 #define TARGET_ADDRESS_COST arm_address_cost
391 #undef TARGET_SHIFT_TRUNCATION_MASK
392 #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask
393 #undef TARGET_VECTOR_MODE_SUPPORTED_P
394 #define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p
395 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
396 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE arm_preferred_simd_mode
398 #undef TARGET_MACHINE_DEPENDENT_REORG
399 #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg
401 #undef TARGET_INIT_BUILTINS
402 #define TARGET_INIT_BUILTINS arm_init_builtins
403 #undef TARGET_EXPAND_BUILTIN
404 #define TARGET_EXPAND_BUILTIN arm_expand_builtin
406 #undef TARGET_INIT_LIBFUNCS
407 #define TARGET_INIT_LIBFUNCS arm_init_libfuncs
409 #undef TARGET_PROMOTE_FUNCTION_MODE
410 #define TARGET_PROMOTE_FUNCTION_MODE arm_promote_function_mode
411 #undef TARGET_PROMOTE_PROTOTYPES
412 #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes
413 #undef TARGET_PASS_BY_REFERENCE
414 #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference
415 #undef TARGET_ARG_PARTIAL_BYTES
416 #define TARGET_ARG_PARTIAL_BYTES arm_arg_partial_bytes
417 #undef TARGET_FUNCTION_ARG
418 #define TARGET_FUNCTION_ARG arm_function_arg
419 #undef TARGET_FUNCTION_ARG_ADVANCE
420 #define TARGET_FUNCTION_ARG_ADVANCE arm_function_arg_advance
421 #undef TARGET_FUNCTION_ARG_BOUNDARY
422 #define TARGET_FUNCTION_ARG_BOUNDARY arm_function_arg_boundary
424 #undef TARGET_SETUP_INCOMING_VARARGS
425 #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs
427 #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
428 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args
430 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
431 #define TARGET_ASM_TRAMPOLINE_TEMPLATE arm_asm_trampoline_template
432 #undef TARGET_TRAMPOLINE_INIT
433 #define TARGET_TRAMPOLINE_INIT arm_trampoline_init
434 #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
435 #define TARGET_TRAMPOLINE_ADJUST_ADDRESS arm_trampoline_adjust_address
437 #undef TARGET_DEFAULT_SHORT_ENUMS
438 #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
440 #undef TARGET_ALIGN_ANON_BITFIELD
441 #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield
443 #undef TARGET_NARROW_VOLATILE_BITFIELD
444 #define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
446 #undef TARGET_CXX_GUARD_TYPE
447 #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type
449 #undef TARGET_CXX_GUARD_MASK_BIT
450 #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit
452 #undef TARGET_CXX_GET_COOKIE_SIZE
453 #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size
455 #undef TARGET_CXX_COOKIE_HAS_SIZE
456 #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size
458 #undef TARGET_CXX_CDTOR_RETURNS_THIS
459 #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this
461 #undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE
462 #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline
464 #undef TARGET_CXX_USE_AEABI_ATEXIT
465 #define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit
467 #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY
468 #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \
469 arm_cxx_determine_class_data_visibility
471 #undef TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT
472 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT arm_cxx_class_data_always_comdat
474 #undef TARGET_RETURN_IN_MSB
475 #define TARGET_RETURN_IN_MSB arm_return_in_msb
477 #undef TARGET_RETURN_IN_MEMORY
478 #define TARGET_RETURN_IN_MEMORY arm_return_in_memory
480 #undef TARGET_MUST_PASS_IN_STACK
481 #define TARGET_MUST_PASS_IN_STACK arm_must_pass_in_stack
484 #undef TARGET_ASM_UNWIND_EMIT
485 #define TARGET_ASM_UNWIND_EMIT arm_unwind_emit
487 /* EABI unwinding tables use a different format for the typeinfo tables. */
488 #undef TARGET_ASM_TTYPE
489 #define TARGET_ASM_TTYPE arm_output_ttype
491 #undef TARGET_ARM_EABI_UNWINDER
492 #define TARGET_ARM_EABI_UNWINDER true
494 #undef TARGET_ASM_EMIT_EXCEPT_PERSONALITY
495 #define TARGET_ASM_EMIT_EXCEPT_PERSONALITY arm_asm_emit_except_personality
497 #undef TARGET_ASM_INIT_SECTIONS
498 #define TARGET_ASM_INIT_SECTIONS arm_asm_init_sections
499 #endif /* ARM_UNWIND_INFO */
501 #undef TARGET_EXCEPT_UNWIND_INFO
502 #define TARGET_EXCEPT_UNWIND_INFO arm_except_unwind_info
504 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
505 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC arm_dwarf_handle_frame_unspec
507 #undef TARGET_DWARF_REGISTER_SPAN
508 #define TARGET_DWARF_REGISTER_SPAN arm_dwarf_register_span
510 #undef TARGET_CANNOT_COPY_INSN_P
511 #define TARGET_CANNOT_COPY_INSN_P arm_cannot_copy_insn_p
514 #undef TARGET_HAVE_TLS
515 #define TARGET_HAVE_TLS true
518 #undef TARGET_HAVE_CONDITIONAL_EXECUTION
519 #define TARGET_HAVE_CONDITIONAL_EXECUTION arm_have_conditional_execution
521 #undef TARGET_CANNOT_FORCE_CONST_MEM
522 #define TARGET_CANNOT_FORCE_CONST_MEM arm_cannot_force_const_mem
524 #undef TARGET_MAX_ANCHOR_OFFSET
525 #define TARGET_MAX_ANCHOR_OFFSET 4095
527 /* The minimum is set such that the total size of the block
528 for a particular anchor is -4088 + 1 + 4095 bytes, which is
529 divisible by eight, ensuring natural spacing of anchors. */
530 #undef TARGET_MIN_ANCHOR_OFFSET
531 #define TARGET_MIN_ANCHOR_OFFSET -4088
533 #undef TARGET_SCHED_ISSUE_RATE
534 #define TARGET_SCHED_ISSUE_RATE arm_issue_rate
536 #undef TARGET_MANGLE_TYPE
537 #define TARGET_MANGLE_TYPE arm_mangle_type
539 #undef TARGET_BUILD_BUILTIN_VA_LIST
540 #define TARGET_BUILD_BUILTIN_VA_LIST arm_build_builtin_va_list
541 #undef TARGET_EXPAND_BUILTIN_VA_START
542 #define TARGET_EXPAND_BUILTIN_VA_START arm_expand_builtin_va_start
543 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
544 #define TARGET_GIMPLIFY_VA_ARG_EXPR arm_gimplify_va_arg_expr
547 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
548 #define TARGET_ASM_OUTPUT_DWARF_DTPREL arm_output_dwarf_dtprel
551 #undef TARGET_LEGITIMATE_ADDRESS_P
552 #define TARGET_LEGITIMATE_ADDRESS_P arm_legitimate_address_p
554 #undef TARGET_INVALID_PARAMETER_TYPE
555 #define TARGET_INVALID_PARAMETER_TYPE arm_invalid_parameter_type
557 #undef TARGET_INVALID_RETURN_TYPE
558 #define TARGET_INVALID_RETURN_TYPE arm_invalid_return_type
560 #undef TARGET_PROMOTED_TYPE
561 #define TARGET_PROMOTED_TYPE arm_promoted_type
563 #undef TARGET_CONVERT_TO_TYPE
564 #define TARGET_CONVERT_TO_TYPE arm_convert_to_type
566 #undef TARGET_SCALAR_MODE_SUPPORTED_P
567 #define TARGET_SCALAR_MODE_SUPPORTED_P arm_scalar_mode_supported_p
569 #undef TARGET_FRAME_POINTER_REQUIRED
570 #define TARGET_FRAME_POINTER_REQUIRED arm_frame_pointer_required
572 #undef TARGET_CAN_ELIMINATE
573 #define TARGET_CAN_ELIMINATE arm_can_eliminate
575 #undef TARGET_CONDITIONAL_REGISTER_USAGE
576 #define TARGET_CONDITIONAL_REGISTER_USAGE arm_conditional_register_usage
578 #undef TARGET_CLASS_LIKELY_SPILLED_P
579 #define TARGET_CLASS_LIKELY_SPILLED_P arm_class_likely_spilled_p
581 #undef TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE
582 #define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE \
583 arm_vector_alignment_reachable
585 #undef TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT
586 #define TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT \
587 arm_builtin_support_vector_misalignment
589 #undef TARGET_PREFERRED_RENAME_CLASS
590 #define TARGET_PREFERRED_RENAME_CLASS \
591 arm_preferred_rename_class
593 struct gcc_target targetm = TARGET_INITIALIZER;
595 /* Obstack for minipool constant handling. */
596 static struct obstack minipool_obstack;
597 static char * minipool_startobj;
599 /* The maximum number of insns skipped which
600 will be conditionalised if possible. */
601 static int max_insns_skipped = 5;
603 extern FILE * asm_out_file;
605 /* True if we are currently building a constant table. */
606 int making_const_table;
608 /* The processor for which instructions should be scheduled. */
609 enum processor_type arm_tune = arm_none;
611 /* The current tuning set. */
612 const struct tune_params *current_tune;
614 /* Which floating point hardware to schedule for. */
617 /* Which floating popint hardware to use. */
618 const struct arm_fpu_desc *arm_fpu_desc;
620 /* Whether to use floating point hardware. */
621 enum float_abi_type arm_float_abi;
623 /* Which __fp16 format to use. */
624 enum arm_fp16_format_type arm_fp16_format;
626 /* Which ABI to use. */
627 enum arm_abi_type arm_abi;
629 /* Which thread pointer model to use. */
630 enum arm_tp_type target_thread_pointer = TP_AUTO;
632 /* Used to parse -mstructure_size_boundary command line option. */
633 int arm_structure_size_boundary = DEFAULT_STRUCTURE_SIZE_BOUNDARY;
635 /* Used for Thumb call_via trampolines. */
636 rtx thumb_call_via_label[14];
637 static int thumb_call_reg_needed;
639 /* Bit values used to identify processor capabilities. */
640 #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */
641 #define FL_ARCH3M (1 << 1) /* Extended multiply */
642 #define FL_MODE26 (1 << 2) /* 26-bit mode support */
643 #define FL_MODE32 (1 << 3) /* 32-bit mode support */
644 #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */
645 #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */
646 #define FL_THUMB (1 << 6) /* Thumb aware */
647 #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */
648 #define FL_STRONG (1 << 8) /* StrongARM */
649 #define FL_ARCH5E (1 << 9) /* DSP extensions to v5 */
650 #define FL_XSCALE (1 << 10) /* XScale */
651 #define FL_CIRRUS (1 << 11) /* Cirrus/DSP. */
652 #define FL_ARCH6 (1 << 12) /* Architecture rel 6. Adds
653 media instructions. */
654 #define FL_VFPV2 (1 << 13) /* Vector Floating Point V2. */
655 #define FL_WBUF (1 << 14) /* Schedule for write buffer ops.
656 Note: ARM6 & 7 derivatives only. */
657 #define FL_ARCH6K (1 << 15) /* Architecture rel 6 K extensions. */
658 #define FL_THUMB2 (1 << 16) /* Thumb-2. */
659 #define FL_NOTM (1 << 17) /* Instructions not present in the 'M'
661 #define FL_DIV (1 << 18) /* Hardware divide. */
662 #define FL_VFPV3 (1 << 19) /* Vector Floating Point V3. */
663 #define FL_NEON (1 << 20) /* Neon instructions. */
664 #define FL_ARCH7EM (1 << 21) /* Instructions present in the ARMv7E-M
666 #define FL_ARCH7 (1 << 22) /* Architecture 7. */
668 #define FL_IWMMXT (1 << 29) /* XScale v2 or "Intel Wireless MMX technology". */
670 /* Flags that only effect tuning, not available instructions. */
671 #define FL_TUNE (FL_WBUF | FL_VFPV2 | FL_STRONG | FL_LDSCHED \
674 #define FL_FOR_ARCH2 FL_NOTM
675 #define FL_FOR_ARCH3 (FL_FOR_ARCH2 | FL_MODE32)
676 #define FL_FOR_ARCH3M (FL_FOR_ARCH3 | FL_ARCH3M)
677 #define FL_FOR_ARCH4 (FL_FOR_ARCH3M | FL_ARCH4)
678 #define FL_FOR_ARCH4T (FL_FOR_ARCH4 | FL_THUMB)
679 #define FL_FOR_ARCH5 (FL_FOR_ARCH4 | FL_ARCH5)
680 #define FL_FOR_ARCH5T (FL_FOR_ARCH5 | FL_THUMB)
681 #define FL_FOR_ARCH5E (FL_FOR_ARCH5 | FL_ARCH5E)
682 #define FL_FOR_ARCH5TE (FL_FOR_ARCH5E | FL_THUMB)
683 #define FL_FOR_ARCH5TEJ FL_FOR_ARCH5TE
684 #define FL_FOR_ARCH6 (FL_FOR_ARCH5TE | FL_ARCH6)
685 #define FL_FOR_ARCH6J FL_FOR_ARCH6
686 #define FL_FOR_ARCH6K (FL_FOR_ARCH6 | FL_ARCH6K)
687 #define FL_FOR_ARCH6Z FL_FOR_ARCH6
688 #define FL_FOR_ARCH6ZK FL_FOR_ARCH6K
689 #define FL_FOR_ARCH6T2 (FL_FOR_ARCH6 | FL_THUMB2)
690 #define FL_FOR_ARCH6M (FL_FOR_ARCH6 & ~FL_NOTM)
691 #define FL_FOR_ARCH7 ((FL_FOR_ARCH6T2 & ~FL_NOTM) | FL_ARCH7)
692 #define FL_FOR_ARCH7A (FL_FOR_ARCH7 | FL_NOTM | FL_ARCH6K)
693 #define FL_FOR_ARCH7R (FL_FOR_ARCH7A | FL_DIV)
694 #define FL_FOR_ARCH7M (FL_FOR_ARCH7 | FL_DIV)
695 #define FL_FOR_ARCH7EM (FL_FOR_ARCH7M | FL_ARCH7EM)
697 /* The bits in this mask specify which
698 instructions we are allowed to generate. */
699 static unsigned long insn_flags = 0;
701 /* The bits in this mask specify which instruction scheduling options should
703 static unsigned long tune_flags = 0;
705 /* The following are used in the arm.md file as equivalents to bits
706 in the above two flag variables. */
708 /* Nonzero if this chip supports the ARM Architecture 3M extensions. */
711 /* Nonzero if this chip supports the ARM Architecture 4 extensions. */
714 /* Nonzero if this chip supports the ARM Architecture 4t extensions. */
717 /* Nonzero if this chip supports the ARM Architecture 5 extensions. */
720 /* Nonzero if this chip supports the ARM Architecture 5E extensions. */
723 /* Nonzero if this chip supports the ARM Architecture 6 extensions. */
726 /* Nonzero if this chip supports the ARM 6K extensions. */
729 /* Nonzero if this chip supports the ARM 7 extensions. */
732 /* Nonzero if instructions not present in the 'M' profile can be used. */
733 int arm_arch_notm = 0;
735 /* Nonzero if instructions present in ARMv7E-M can be used. */
738 /* Nonzero if this chip can benefit from load scheduling. */
739 int arm_ld_sched = 0;
741 /* Nonzero if this chip is a StrongARM. */
742 int arm_tune_strongarm = 0;
744 /* Nonzero if this chip is a Cirrus variant. */
745 int arm_arch_cirrus = 0;
747 /* Nonzero if this chip supports Intel Wireless MMX technology. */
748 int arm_arch_iwmmxt = 0;
750 /* Nonzero if this chip is an XScale. */
751 int arm_arch_xscale = 0;
753 /* Nonzero if tuning for XScale */
754 int arm_tune_xscale = 0;
756 /* Nonzero if we want to tune for stores that access the write-buffer.
757 This typically means an ARM6 or ARM7 with MMU or MPU. */
758 int arm_tune_wbuf = 0;
760 /* Nonzero if tuning for Cortex-A9. */
761 int arm_tune_cortex_a9 = 0;
763 /* Nonzero if generating Thumb instructions. */
766 /* Nonzero if generating Thumb-1 instructions. */
769 /* Nonzero if we should define __THUMB_INTERWORK__ in the
771 XXX This is a bit of a hack, it's intended to help work around
772 problems in GLD which doesn't understand that armv5t code is
773 interworking clean. */
774 int arm_cpp_interwork = 0;
776 /* Nonzero if chip supports Thumb 2. */
779 /* Nonzero if chip supports integer division instruction. */
782 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference,
783 we must report the mode of the memory reference from
784 TARGET_PRINT_OPERAND to TARGET_PRINT_OPERAND_ADDRESS. */
785 enum machine_mode output_memory_reference_mode;
787 /* The register number to be used for the PIC offset register. */
788 unsigned arm_pic_register = INVALID_REGNUM;
790 /* Set to 1 after arm_reorg has started. Reset to start at the start of
791 the next function. */
792 static int after_arm_reorg = 0;
794 enum arm_pcs arm_pcs_default;
796 /* For an explanation of these variables, see final_prescan_insn below. */
798 /* arm_current_cc is also used for Thumb-2 cond_exec blocks. */
799 enum arm_cond_code arm_current_cc;
802 int arm_target_label;
803 /* The number of conditionally executed insns, including the current insn. */
804 int arm_condexec_count = 0;
805 /* A bitmask specifying the patterns for the IT block.
806 Zero means do not output an IT block before this insn. */
807 int arm_condexec_mask = 0;
808 /* The number of bits used in arm_condexec_mask. */
809 int arm_condexec_masklen = 0;
811 /* The condition codes of the ARM, and the inverse function. */
812 static const char * const arm_condition_codes[] =
814 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
815 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
818 /* The register numbers in sequence, for passing to arm_gen_load_multiple. */
819 int arm_regs_in_sequence[] =
821 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
824 #define ARM_LSL_NAME (TARGET_UNIFIED_ASM ? "lsl" : "asl")
825 #define streq(string1, string2) (strcmp (string1, string2) == 0)
827 #define THUMB2_WORK_REGS (0xff & ~( (1 << THUMB_HARD_FRAME_POINTER_REGNUM) \
828 | (1 << SP_REGNUM) | (1 << PC_REGNUM) \
829 | (1 << PIC_OFFSET_TABLE_REGNUM)))
831 /* Initialization code. */
835 const char *const name;
836 enum processor_type core;
838 const unsigned long flags;
839 const struct tune_params *const tune;
843 #define ARM_PREFETCH_NOT_BENEFICIAL 0, -1, -1
844 #define ARM_PREFETCH_BENEFICIAL(prefetch_slots,l1_size,l1_line_size) \
849 const struct tune_params arm_slowmul_tune =
851 arm_slowmul_rtx_costs,
854 ARM_PREFETCH_NOT_BENEFICIAL
857 const struct tune_params arm_fastmul_tune =
859 arm_fastmul_rtx_costs,
862 ARM_PREFETCH_NOT_BENEFICIAL
865 const struct tune_params arm_xscale_tune =
867 arm_xscale_rtx_costs,
868 xscale_sched_adjust_cost,
870 ARM_PREFETCH_NOT_BENEFICIAL
873 const struct tune_params arm_9e_tune =
878 ARM_PREFETCH_NOT_BENEFICIAL
881 const struct tune_params arm_cortex_a9_tune =
884 cortex_a9_sched_adjust_cost,
886 ARM_PREFETCH_BENEFICIAL(4,32,32)
890 /* Not all of these give usefully different compilation alternatives,
891 but there is no simple way of generalizing them. */
892 static const struct processors all_cores[] =
895 #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \
896 {NAME, IDENT, #ARCH, FLAGS | FL_FOR_ARCH##ARCH, &arm_##COSTS##_tune},
897 #include "arm-cores.def"
899 {NULL, arm_none, NULL, 0, NULL}
902 static const struct processors all_architectures[] =
904 /* ARM Architectures */
905 /* We don't specify tuning costs here as it will be figured out
908 {"armv2", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
909 {"armv2a", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
910 {"armv3", arm6, "3", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3, NULL},
911 {"armv3m", arm7m, "3M", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3M, NULL},
912 {"armv4", arm7tdmi, "4", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH4, NULL},
913 /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no
914 implementations that support it, so we will leave it out for now. */
915 {"armv4t", arm7tdmi, "4T", FL_CO_PROC | FL_FOR_ARCH4T, NULL},
916 {"armv5", arm10tdmi, "5", FL_CO_PROC | FL_FOR_ARCH5, NULL},
917 {"armv5t", arm10tdmi, "5T", FL_CO_PROC | FL_FOR_ARCH5T, NULL},
918 {"armv5e", arm1026ejs, "5E", FL_CO_PROC | FL_FOR_ARCH5E, NULL},
919 {"armv5te", arm1026ejs, "5TE", FL_CO_PROC | FL_FOR_ARCH5TE, NULL},
920 {"armv6", arm1136js, "6", FL_CO_PROC | FL_FOR_ARCH6, NULL},
921 {"armv6j", arm1136js, "6J", FL_CO_PROC | FL_FOR_ARCH6J, NULL},
922 {"armv6k", mpcore, "6K", FL_CO_PROC | FL_FOR_ARCH6K, NULL},
923 {"armv6z", arm1176jzs, "6Z", FL_CO_PROC | FL_FOR_ARCH6Z, NULL},
924 {"armv6zk", arm1176jzs, "6ZK", FL_CO_PROC | FL_FOR_ARCH6ZK, NULL},
925 {"armv6t2", arm1156t2s, "6T2", FL_CO_PROC | FL_FOR_ARCH6T2, NULL},
926 {"armv6-m", cortexm1, "6M", FL_FOR_ARCH6M, NULL},
927 {"armv7", cortexa8, "7", FL_CO_PROC | FL_FOR_ARCH7, NULL},
928 {"armv7-a", cortexa8, "7A", FL_CO_PROC | FL_FOR_ARCH7A, NULL},
929 {"armv7-r", cortexr4, "7R", FL_CO_PROC | FL_FOR_ARCH7R, NULL},
930 {"armv7-m", cortexm3, "7M", FL_CO_PROC | FL_FOR_ARCH7M, NULL},
931 {"armv7e-m", cortexm4, "7EM", FL_CO_PROC | FL_FOR_ARCH7EM, NULL},
932 {"ep9312", ep9312, "4T", FL_LDSCHED | FL_CIRRUS | FL_FOR_ARCH4, NULL},
933 {"iwmmxt", iwmmxt, "5TE", FL_LDSCHED | FL_STRONG | FL_FOR_ARCH5TE | FL_XSCALE | FL_IWMMXT , NULL},
934 {"iwmmxt2", iwmmxt2, "5TE", FL_LDSCHED | FL_STRONG | FL_FOR_ARCH5TE | FL_XSCALE | FL_IWMMXT , NULL},
935 {NULL, arm_none, NULL, 0 , NULL}
939 /* These are populated as commandline arguments are processed, or NULL
941 static const struct processors *arm_selected_arch;
942 static const struct processors *arm_selected_cpu;
943 static const struct processors *arm_selected_tune;
945 /* The name of the preprocessor macro to define for this architecture. */
947 char arm_arch_name[] = "__ARM_ARCH_0UNK__";
949 /* Available values for -mfpu=. */
951 static const struct arm_fpu_desc all_fpus[] =
953 {"fpa", ARM_FP_MODEL_FPA, 0, VFP_NONE, false, false},
954 {"fpe2", ARM_FP_MODEL_FPA, 2, VFP_NONE, false, false},
955 {"fpe3", ARM_FP_MODEL_FPA, 3, VFP_NONE, false, false},
956 {"maverick", ARM_FP_MODEL_MAVERICK, 0, VFP_NONE, false, false},
957 {"vfp", ARM_FP_MODEL_VFP, 2, VFP_REG_D16, false, false},
958 {"vfpv3", ARM_FP_MODEL_VFP, 3, VFP_REG_D32, false, false},
959 {"vfpv3-fp16", ARM_FP_MODEL_VFP, 3, VFP_REG_D32, false, true},
960 {"vfpv3-d16", ARM_FP_MODEL_VFP, 3, VFP_REG_D16, false, false},
961 {"vfpv3-d16-fp16", ARM_FP_MODEL_VFP, 3, VFP_REG_D16, false, true},
962 {"vfpv3xd", ARM_FP_MODEL_VFP, 3, VFP_REG_SINGLE, false, false},
963 {"vfpv3xd-fp16", ARM_FP_MODEL_VFP, 3, VFP_REG_SINGLE, false, true},
964 {"neon", ARM_FP_MODEL_VFP, 3, VFP_REG_D32, true , false},
965 {"neon-fp16", ARM_FP_MODEL_VFP, 3, VFP_REG_D32, true , true },
966 {"vfpv4", ARM_FP_MODEL_VFP, 4, VFP_REG_D32, false, true},
967 {"vfpv4-d16", ARM_FP_MODEL_VFP, 4, VFP_REG_D16, false, true},
968 {"fpv4-sp-d16", ARM_FP_MODEL_VFP, 4, VFP_REG_SINGLE, false, true},
969 {"neon-vfpv4", ARM_FP_MODEL_VFP, 4, VFP_REG_D32, true, true},
970 /* Compatibility aliases. */
971 {"vfp3", ARM_FP_MODEL_VFP, 3, VFP_REG_D32, false, false},
978 enum float_abi_type abi_type;
982 /* Available values for -mfloat-abi=. */
984 static const struct float_abi all_float_abis[] =
986 {"soft", ARM_FLOAT_ABI_SOFT},
987 {"softfp", ARM_FLOAT_ABI_SOFTFP},
988 {"hard", ARM_FLOAT_ABI_HARD}
995 enum arm_fp16_format_type fp16_format_type;
999 /* Available values for -mfp16-format=. */
1001 static const struct fp16_format all_fp16_formats[] =
1003 {"none", ARM_FP16_FORMAT_NONE},
1004 {"ieee", ARM_FP16_FORMAT_IEEE},
1005 {"alternative", ARM_FP16_FORMAT_ALTERNATIVE}
1012 enum arm_abi_type abi_type;
1016 /* Available values for -mabi=. */
1018 static const struct abi_name arm_all_abis[] =
1020 {"apcs-gnu", ARM_ABI_APCS},
1021 {"atpcs", ARM_ABI_ATPCS},
1022 {"aapcs", ARM_ABI_AAPCS},
1023 {"iwmmxt", ARM_ABI_IWMMXT},
1024 {"aapcs-linux", ARM_ABI_AAPCS_LINUX}
1027 /* Supported TLS relocations. */
1037 /* The maximum number of insns to be used when loading a constant. */
1039 arm_constant_limit (bool size_p)
1041 return size_p ? 1 : current_tune->constant_limit;
1044 /* Emit an insn that's a simple single-set. Both the operands must be known
1047 emit_set_insn (rtx x, rtx y)
1049 return emit_insn (gen_rtx_SET (VOIDmode, x, y));
1052 /* Return the number of bits set in VALUE. */
1054 bit_count (unsigned long value)
1056 unsigned long count = 0;
1061 value &= value - 1; /* Clear the least-significant set bit. */
1067 /* Set up library functions unique to ARM. */
1070 arm_init_libfuncs (void)
1072 /* There are no special library functions unless we are using the
1077 /* The functions below are described in Section 4 of the "Run-Time
1078 ABI for the ARM architecture", Version 1.0. */
1080 /* Double-precision floating-point arithmetic. Table 2. */
1081 set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd");
1082 set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv");
1083 set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul");
1084 set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg");
1085 set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub");
1087 /* Double-precision comparisons. Table 3. */
1088 set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq");
1089 set_optab_libfunc (ne_optab, DFmode, NULL);
1090 set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt");
1091 set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple");
1092 set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge");
1093 set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt");
1094 set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun");
1096 /* Single-precision floating-point arithmetic. Table 4. */
1097 set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd");
1098 set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv");
1099 set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul");
1100 set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg");
1101 set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub");
1103 /* Single-precision comparisons. Table 5. */
1104 set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq");
1105 set_optab_libfunc (ne_optab, SFmode, NULL);
1106 set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt");
1107 set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple");
1108 set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge");
1109 set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt");
1110 set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun");
1112 /* Floating-point to integer conversions. Table 6. */
1113 set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz");
1114 set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz");
1115 set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz");
1116 set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz");
1117 set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz");
1118 set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz");
1119 set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz");
1120 set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz");
1122 /* Conversions between floating types. Table 7. */
1123 set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f");
1124 set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d");
1126 /* Integer to floating-point conversions. Table 8. */
1127 set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d");
1128 set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d");
1129 set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d");
1130 set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d");
1131 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f");
1132 set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f");
1133 set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f");
1134 set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f");
1136 /* Long long. Table 9. */
1137 set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul");
1138 set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod");
1139 set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod");
1140 set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl");
1141 set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr");
1142 set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr");
1143 set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp");
1144 set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp");
1146 /* Integer (32/32->32) division. \S 4.3.1. */
1147 set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod");
1148 set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod");
1150 /* The divmod functions are designed so that they can be used for
1151 plain division, even though they return both the quotient and the
1152 remainder. The quotient is returned in the usual location (i.e.,
1153 r0 for SImode, {r0, r1} for DImode), just as would be expected
1154 for an ordinary division routine. Because the AAPCS calling
1155 conventions specify that all of { r0, r1, r2, r3 } are
1156 callee-saved registers, there is no need to tell the compiler
1157 explicitly that those registers are clobbered by these
1159 set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod");
1160 set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod");
1162 /* For SImode division the ABI provides div-without-mod routines,
1163 which are faster. */
1164 set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idiv");
1165 set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidiv");
1167 /* We don't have mod libcalls. Fortunately gcc knows how to use the
1168 divmod libcalls instead. */
1169 set_optab_libfunc (smod_optab, DImode, NULL);
1170 set_optab_libfunc (umod_optab, DImode, NULL);
1171 set_optab_libfunc (smod_optab, SImode, NULL);
1172 set_optab_libfunc (umod_optab, SImode, NULL);
1174 /* Half-precision float operations. The compiler handles all operations
1175 with NULL libfuncs by converting the SFmode. */
1176 switch (arm_fp16_format)
1178 case ARM_FP16_FORMAT_IEEE:
1179 case ARM_FP16_FORMAT_ALTERNATIVE:
1182 set_conv_libfunc (trunc_optab, HFmode, SFmode,
1183 (arm_fp16_format == ARM_FP16_FORMAT_IEEE
1185 : "__gnu_f2h_alternative"));
1186 set_conv_libfunc (sext_optab, SFmode, HFmode,
1187 (arm_fp16_format == ARM_FP16_FORMAT_IEEE
1189 : "__gnu_h2f_alternative"));
1192 set_optab_libfunc (add_optab, HFmode, NULL);
1193 set_optab_libfunc (sdiv_optab, HFmode, NULL);
1194 set_optab_libfunc (smul_optab, HFmode, NULL);
1195 set_optab_libfunc (neg_optab, HFmode, NULL);
1196 set_optab_libfunc (sub_optab, HFmode, NULL);
1199 set_optab_libfunc (eq_optab, HFmode, NULL);
1200 set_optab_libfunc (ne_optab, HFmode, NULL);
1201 set_optab_libfunc (lt_optab, HFmode, NULL);
1202 set_optab_libfunc (le_optab, HFmode, NULL);
1203 set_optab_libfunc (ge_optab, HFmode, NULL);
1204 set_optab_libfunc (gt_optab, HFmode, NULL);
1205 set_optab_libfunc (unord_optab, HFmode, NULL);
1212 if (TARGET_AAPCS_BASED)
1213 synchronize_libfunc = init_one_libfunc ("__sync_synchronize");
1216 /* On AAPCS systems, this is the "struct __va_list". */
1217 static GTY(()) tree va_list_type;
1219 /* Return the type to use as __builtin_va_list. */
1221 arm_build_builtin_va_list (void)
1226 if (!TARGET_AAPCS_BASED)
1227 return std_build_builtin_va_list ();
1229 /* AAPCS \S 7.1.4 requires that va_list be a typedef for a type
1237 The C Library ABI further reinforces this definition in \S
1240 We must follow this definition exactly. The structure tag
1241 name is visible in C++ mangled names, and thus forms a part
1242 of the ABI. The field name may be used by people who
1243 #include <stdarg.h>. */
1244 /* Create the type. */
1245 va_list_type = lang_hooks.types.make_type (RECORD_TYPE);
1246 /* Give it the required name. */
1247 va_list_name = build_decl (BUILTINS_LOCATION,
1249 get_identifier ("__va_list"),
1251 DECL_ARTIFICIAL (va_list_name) = 1;
1252 TYPE_NAME (va_list_type) = va_list_name;
1253 TYPE_STUB_DECL (va_list_type) = va_list_name;
1254 /* Create the __ap field. */
1255 ap_field = build_decl (BUILTINS_LOCATION,
1257 get_identifier ("__ap"),
1259 DECL_ARTIFICIAL (ap_field) = 1;
1260 DECL_FIELD_CONTEXT (ap_field) = va_list_type;
1261 TYPE_FIELDS (va_list_type) = ap_field;
1262 /* Compute its layout. */
1263 layout_type (va_list_type);
1265 return va_list_type;
1268 /* Return an expression of type "void *" pointing to the next
1269 available argument in a variable-argument list. VALIST is the
1270 user-level va_list object, of type __builtin_va_list. */
1272 arm_extract_valist_ptr (tree valist)
1274 if (TREE_TYPE (valist) == error_mark_node)
1275 return error_mark_node;
1277 /* On an AAPCS target, the pointer is stored within "struct
1279 if (TARGET_AAPCS_BASED)
1281 tree ap_field = TYPE_FIELDS (TREE_TYPE (valist));
1282 valist = build3 (COMPONENT_REF, TREE_TYPE (ap_field),
1283 valist, ap_field, NULL_TREE);
1289 /* Implement TARGET_EXPAND_BUILTIN_VA_START. */
1291 arm_expand_builtin_va_start (tree valist, rtx nextarg)
1293 valist = arm_extract_valist_ptr (valist);
1294 std_expand_builtin_va_start (valist, nextarg);
1297 /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */
1299 arm_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
1302 valist = arm_extract_valist_ptr (valist);
1303 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
1306 /* Lookup NAME in SEL. */
1308 static const struct processors *
1309 arm_find_cpu (const char *name, const struct processors *sel, const char *desc)
1311 if (!(name && *name))
1314 for (; sel->name != NULL; sel++)
1316 if (streq (name, sel->name))
1320 error ("bad value (%s) for %s switch", name, desc);
1324 /* Implement TARGET_HANDLE_OPTION. */
1327 arm_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
1332 arm_selected_arch = arm_find_cpu(arg, all_architectures, "-march");
1336 arm_selected_cpu = arm_find_cpu(arg, all_cores, "-mcpu");
1339 case OPT_mhard_float:
1340 target_float_abi_name = "hard";
1343 case OPT_msoft_float:
1344 target_float_abi_name = "soft";
1348 arm_selected_tune = arm_find_cpu(arg, all_cores, "-mtune");
1357 arm_target_help (void)
1360 static int columns = 0;
1363 /* If we have not done so already, obtain the desired maximum width of
1364 the output. Note - this is a duplication of the code at the start of
1365 gcc/opts.c:print_specific_help() - the two copies should probably be
1366 replaced by a single function. */
1371 p = getenv ("COLUMNS");
1374 int value = atoi (p);
1381 /* Use a reasonable default. */
1385 printf (" Known ARM CPUs (for use with the -mcpu= and -mtune= options):\n");
1387 /* The - 2 is because we know that the last entry in the array is NULL. */
1388 i = ARRAY_SIZE (all_cores) - 2;
1390 printf (" %s", all_cores[i].name);
1391 remaining = columns - (strlen (all_cores[i].name) + 4);
1392 gcc_assert (remaining >= 0);
1396 int len = strlen (all_cores[i].name);
1398 if (remaining > len + 2)
1400 printf (", %s", all_cores[i].name);
1401 remaining -= len + 2;
1407 printf ("\n %s", all_cores[i].name);
1408 remaining = columns - (len + 4);
1412 printf ("\n\n Known ARM architectures (for use with the -march= option):\n");
1414 i = ARRAY_SIZE (all_architectures) - 2;
1417 printf (" %s", all_architectures[i].name);
1418 remaining = columns - (strlen (all_architectures[i].name) + 4);
1419 gcc_assert (remaining >= 0);
1423 int len = strlen (all_architectures[i].name);
1425 if (remaining > len + 2)
1427 printf (", %s", all_architectures[i].name);
1428 remaining -= len + 2;
1434 printf ("\n %s", all_architectures[i].name);
1435 remaining = columns - (len + 4);
1442 /* Fix up any incompatible options that the user has specified. */
1444 arm_option_override (void)
1448 #ifdef SUBTARGET_OVERRIDE_OPTIONS
1449 SUBTARGET_OVERRIDE_OPTIONS;
1452 if (arm_selected_arch)
1454 if (arm_selected_cpu)
1456 /* Check for conflict between mcpu and march. */
1457 if ((arm_selected_cpu->flags ^ arm_selected_arch->flags) & ~FL_TUNE)
1459 warning (0, "switch -mcpu=%s conflicts with -march=%s switch",
1460 arm_selected_cpu->name, arm_selected_arch->name);
1461 /* -march wins for code generation.
1462 -mcpu wins for default tuning. */
1463 if (!arm_selected_tune)
1464 arm_selected_tune = arm_selected_cpu;
1466 arm_selected_cpu = arm_selected_arch;
1470 arm_selected_arch = NULL;
1473 /* Pick a CPU based on the architecture. */
1474 arm_selected_cpu = arm_selected_arch;
1477 /* If the user did not specify a processor, choose one for them. */
1478 if (!arm_selected_cpu)
1480 const struct processors * sel;
1481 unsigned int sought;
1483 arm_selected_cpu = &all_cores[TARGET_CPU_DEFAULT];
1484 if (!arm_selected_cpu->name)
1486 #ifdef SUBTARGET_CPU_DEFAULT
1487 /* Use the subtarget default CPU if none was specified by
1489 arm_selected_cpu = &all_cores[SUBTARGET_CPU_DEFAULT];
1491 /* Default to ARM6. */
1492 if (!arm_selected_cpu->name)
1493 arm_selected_cpu = &all_cores[arm6];
1496 sel = arm_selected_cpu;
1497 insn_flags = sel->flags;
1499 /* Now check to see if the user has specified some command line
1500 switch that require certain abilities from the cpu. */
1503 if (TARGET_INTERWORK || TARGET_THUMB)
1505 sought |= (FL_THUMB | FL_MODE32);
1507 /* There are no ARM processors that support both APCS-26 and
1508 interworking. Therefore we force FL_MODE26 to be removed
1509 from insn_flags here (if it was set), so that the search
1510 below will always be able to find a compatible processor. */
1511 insn_flags &= ~FL_MODE26;
1514 if (sought != 0 && ((sought & insn_flags) != sought))
1516 /* Try to locate a CPU type that supports all of the abilities
1517 of the default CPU, plus the extra abilities requested by
1519 for (sel = all_cores; sel->name != NULL; sel++)
1520 if ((sel->flags & sought) == (sought | insn_flags))
1523 if (sel->name == NULL)
1525 unsigned current_bit_count = 0;
1526 const struct processors * best_fit = NULL;
1528 /* Ideally we would like to issue an error message here
1529 saying that it was not possible to find a CPU compatible
1530 with the default CPU, but which also supports the command
1531 line options specified by the programmer, and so they
1532 ought to use the -mcpu=<name> command line option to
1533 override the default CPU type.
1535 If we cannot find a cpu that has both the
1536 characteristics of the default cpu and the given
1537 command line options we scan the array again looking
1538 for a best match. */
1539 for (sel = all_cores; sel->name != NULL; sel++)
1540 if ((sel->flags & sought) == sought)
1544 count = bit_count (sel->flags & insn_flags);
1546 if (count >= current_bit_count)
1549 current_bit_count = count;
1553 gcc_assert (best_fit);
1557 arm_selected_cpu = sel;
1561 gcc_assert (arm_selected_cpu);
1562 /* The selected cpu may be an architecture, so lookup tuning by core ID. */
1563 if (!arm_selected_tune)
1564 arm_selected_tune = &all_cores[arm_selected_cpu->core];
1566 sprintf (arm_arch_name, "__ARM_ARCH_%s__", arm_selected_cpu->arch);
1567 insn_flags = arm_selected_cpu->flags;
1569 arm_tune = arm_selected_tune->core;
1570 tune_flags = arm_selected_tune->flags;
1571 current_tune = arm_selected_tune->tune;
1573 if (target_fp16_format_name)
1575 for (i = 0; i < ARRAY_SIZE (all_fp16_formats); i++)
1577 if (streq (all_fp16_formats[i].name, target_fp16_format_name))
1579 arm_fp16_format = all_fp16_formats[i].fp16_format_type;
1583 if (i == ARRAY_SIZE (all_fp16_formats))
1584 error ("invalid __fp16 format option: -mfp16-format=%s",
1585 target_fp16_format_name);
1588 arm_fp16_format = ARM_FP16_FORMAT_NONE;
1590 if (target_abi_name)
1592 for (i = 0; i < ARRAY_SIZE (arm_all_abis); i++)
1594 if (streq (arm_all_abis[i].name, target_abi_name))
1596 arm_abi = arm_all_abis[i].abi_type;
1600 if (i == ARRAY_SIZE (arm_all_abis))
1601 error ("invalid ABI option: -mabi=%s", target_abi_name);
1604 arm_abi = ARM_DEFAULT_ABI;
1606 /* Make sure that the processor choice does not conflict with any of the
1607 other command line choices. */
1608 if (TARGET_ARM && !(insn_flags & FL_NOTM))
1609 error ("target CPU does not support ARM mode");
1611 /* BPABI targets use linker tricks to allow interworking on cores
1612 without thumb support. */
1613 if (TARGET_INTERWORK && !((insn_flags & FL_THUMB) || TARGET_BPABI))
1615 warning (0, "target CPU does not support interworking" );
1616 target_flags &= ~MASK_INTERWORK;
1619 if (TARGET_THUMB && !(insn_flags & FL_THUMB))
1621 warning (0, "target CPU does not support THUMB instructions");
1622 target_flags &= ~MASK_THUMB;
1625 if (TARGET_APCS_FRAME && TARGET_THUMB)
1627 /* warning (0, "ignoring -mapcs-frame because -mthumb was used"); */
1628 target_flags &= ~MASK_APCS_FRAME;
1631 /* Callee super interworking implies thumb interworking. Adding
1632 this to the flags here simplifies the logic elsewhere. */
1633 if (TARGET_THUMB && TARGET_CALLEE_INTERWORKING)
1634 target_flags |= MASK_INTERWORK;
1636 /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done
1637 from here where no function is being compiled currently. */
1638 if ((TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) && TARGET_ARM)
1639 warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb");
1641 if (TARGET_ARM && TARGET_CALLEE_INTERWORKING)
1642 warning (0, "enabling callee interworking support is only meaningful when compiling for the Thumb");
1644 if (TARGET_APCS_STACK && !TARGET_APCS_FRAME)
1646 warning (0, "-mapcs-stack-check incompatible with -mno-apcs-frame");
1647 target_flags |= MASK_APCS_FRAME;
1650 if (TARGET_POKE_FUNCTION_NAME)
1651 target_flags |= MASK_APCS_FRAME;
1653 if (TARGET_APCS_REENT && flag_pic)
1654 error ("-fpic and -mapcs-reent are incompatible");
1656 if (TARGET_APCS_REENT)
1657 warning (0, "APCS reentrant code not supported. Ignored");
1659 /* If this target is normally configured to use APCS frames, warn if they
1660 are turned off and debugging is turned on. */
1662 && write_symbols != NO_DEBUG
1663 && !TARGET_APCS_FRAME
1664 && (TARGET_DEFAULT & MASK_APCS_FRAME))
1665 warning (0, "-g with -mno-apcs-frame may not give sensible debugging");
1667 if (TARGET_APCS_FLOAT)
1668 warning (0, "passing floating point arguments in fp regs not yet supported");
1670 /* Initialize boolean versions of the flags, for use in the arm.md file. */
1671 arm_arch3m = (insn_flags & FL_ARCH3M) != 0;
1672 arm_arch4 = (insn_flags & FL_ARCH4) != 0;
1673 arm_arch4t = arm_arch4 & ((insn_flags & FL_THUMB) != 0);
1674 arm_arch5 = (insn_flags & FL_ARCH5) != 0;
1675 arm_arch5e = (insn_flags & FL_ARCH5E) != 0;
1676 arm_arch6 = (insn_flags & FL_ARCH6) != 0;
1677 arm_arch6k = (insn_flags & FL_ARCH6K) != 0;
1678 arm_arch_notm = (insn_flags & FL_NOTM) != 0;
1679 arm_arch7 = (insn_flags & FL_ARCH7) != 0;
1680 arm_arch7em = (insn_flags & FL_ARCH7EM) != 0;
1681 arm_arch_thumb2 = (insn_flags & FL_THUMB2) != 0;
1682 arm_arch_xscale = (insn_flags & FL_XSCALE) != 0;
1683 arm_arch_cirrus = (insn_flags & FL_CIRRUS) != 0;
1685 arm_ld_sched = (tune_flags & FL_LDSCHED) != 0;
1686 arm_tune_strongarm = (tune_flags & FL_STRONG) != 0;
1687 thumb_code = TARGET_ARM == 0;
1688 thumb1_code = TARGET_THUMB1 != 0;
1689 arm_tune_wbuf = (tune_flags & FL_WBUF) != 0;
1690 arm_tune_xscale = (tune_flags & FL_XSCALE) != 0;
1691 arm_arch_iwmmxt = (insn_flags & FL_IWMMXT) != 0;
1692 arm_arch_hwdiv = (insn_flags & FL_DIV) != 0;
1693 arm_tune_cortex_a9 = (arm_tune == cortexa9) != 0;
1695 /* If we are not using the default (ARM mode) section anchor offset
1696 ranges, then set the correct ranges now. */
1699 /* Thumb-1 LDR instructions cannot have negative offsets.
1700 Permissible positive offset ranges are 5-bit (for byte loads),
1701 6-bit (for halfword loads), or 7-bit (for word loads).
1702 Empirical results suggest a 7-bit anchor range gives the best
1703 overall code size. */
1704 targetm.min_anchor_offset = 0;
1705 targetm.max_anchor_offset = 127;
1707 else if (TARGET_THUMB2)
1709 /* The minimum is set such that the total size of the block
1710 for a particular anchor is 248 + 1 + 4095 bytes, which is
1711 divisible by eight, ensuring natural spacing of anchors. */
1712 targetm.min_anchor_offset = -248;
1713 targetm.max_anchor_offset = 4095;
1716 /* V5 code we generate is completely interworking capable, so we turn off
1717 TARGET_INTERWORK here to avoid many tests later on. */
1719 /* XXX However, we must pass the right pre-processor defines to CPP
1720 or GLD can get confused. This is a hack. */
1721 if (TARGET_INTERWORK)
1722 arm_cpp_interwork = 1;
1725 target_flags &= ~MASK_INTERWORK;
1727 if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN)
1728 error ("iwmmxt requires an AAPCS compatible ABI for proper operation");
1730 if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT)
1731 error ("iwmmxt abi requires an iwmmxt capable cpu");
1733 if (target_fpu_name == NULL && target_fpe_name != NULL)
1735 if (streq (target_fpe_name, "2"))
1736 target_fpu_name = "fpe2";
1737 else if (streq (target_fpe_name, "3"))
1738 target_fpu_name = "fpe3";
1740 error ("invalid floating point emulation option: -mfpe=%s",
1744 if (target_fpu_name == NULL)
1746 #ifdef FPUTYPE_DEFAULT
1747 target_fpu_name = FPUTYPE_DEFAULT;
1749 if (arm_arch_cirrus)
1750 target_fpu_name = "maverick";
1752 target_fpu_name = "fpe2";
1756 arm_fpu_desc = NULL;
1757 for (i = 0; i < ARRAY_SIZE (all_fpus); i++)
1759 if (streq (all_fpus[i].name, target_fpu_name))
1761 arm_fpu_desc = &all_fpus[i];
1768 error ("invalid floating point option: -mfpu=%s", target_fpu_name);
1772 switch (arm_fpu_desc->model)
1774 case ARM_FP_MODEL_FPA:
1775 if (arm_fpu_desc->rev == 2)
1776 arm_fpu_attr = FPU_FPE2;
1777 else if (arm_fpu_desc->rev == 3)
1778 arm_fpu_attr = FPU_FPE3;
1780 arm_fpu_attr = FPU_FPA;
1783 case ARM_FP_MODEL_MAVERICK:
1784 arm_fpu_attr = FPU_MAVERICK;
1787 case ARM_FP_MODEL_VFP:
1788 arm_fpu_attr = FPU_VFP;
1795 if (target_float_abi_name != NULL)
1797 /* The user specified a FP ABI. */
1798 for (i = 0; i < ARRAY_SIZE (all_float_abis); i++)
1800 if (streq (all_float_abis[i].name, target_float_abi_name))
1802 arm_float_abi = all_float_abis[i].abi_type;
1806 if (i == ARRAY_SIZE (all_float_abis))
1807 error ("invalid floating point abi: -mfloat-abi=%s",
1808 target_float_abi_name);
1811 arm_float_abi = TARGET_DEFAULT_FLOAT_ABI;
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 if (target_thread_switch)
1875 if (strcmp (target_thread_switch, "soft") == 0)
1876 target_thread_pointer = TP_SOFT;
1877 else if (strcmp (target_thread_switch, "auto") == 0)
1878 target_thread_pointer = TP_AUTO;
1879 else if (strcmp (target_thread_switch, "cp15") == 0)
1880 target_thread_pointer = TP_CP15;
1882 error ("invalid thread pointer option: -mtp=%s", target_thread_switch);
1885 /* Use the cp15 method if it is available. */
1886 if (target_thread_pointer == TP_AUTO)
1888 if (arm_arch6k && !TARGET_THUMB1)
1889 target_thread_pointer = TP_CP15;
1891 target_thread_pointer = TP_SOFT;
1894 if (TARGET_HARD_TP && TARGET_THUMB1)
1895 error ("can not use -mtp=cp15 with 16-bit Thumb");
1897 /* Override the default structure alignment for AAPCS ABI. */
1898 if (TARGET_AAPCS_BASED)
1899 arm_structure_size_boundary = 8;
1901 if (structure_size_string != NULL)
1903 int size = strtol (structure_size_string, NULL, 0);
1905 if (size == 8 || size == 32
1906 || (ARM_DOUBLEWORD_ALIGN && size == 64))
1907 arm_structure_size_boundary = size;
1909 warning (0, "structure size boundary can only be set to %s",
1910 ARM_DOUBLEWORD_ALIGN ? "8, 32 or 64": "8 or 32");
1913 if (!TARGET_ARM && TARGET_VXWORKS_RTP && flag_pic)
1915 error ("RTP PIC is incompatible with Thumb");
1919 /* If stack checking is disabled, we can use r10 as the PIC register,
1920 which keeps r9 available. The EABI specifies r9 as the PIC register. */
1921 if (flag_pic && TARGET_SINGLE_PIC_BASE)
1923 if (TARGET_VXWORKS_RTP)
1924 warning (0, "RTP PIC is incompatible with -msingle-pic-base");
1925 arm_pic_register = (TARGET_APCS_STACK || TARGET_AAPCS_BASED) ? 9 : 10;
1928 if (flag_pic && TARGET_VXWORKS_RTP)
1929 arm_pic_register = 9;
1931 if (arm_pic_register_string != NULL)
1933 int pic_register = decode_reg_name (arm_pic_register_string);
1936 warning (0, "-mpic-register= is useless without -fpic");
1938 /* Prevent the user from choosing an obviously stupid PIC register. */
1939 else if (pic_register < 0 || call_used_regs[pic_register]
1940 || pic_register == HARD_FRAME_POINTER_REGNUM
1941 || pic_register == STACK_POINTER_REGNUM
1942 || pic_register >= PC_REGNUM
1943 || (TARGET_VXWORKS_RTP
1944 && (unsigned int) pic_register != arm_pic_register))
1945 error ("unable to use '%s' for PIC register", arm_pic_register_string);
1947 arm_pic_register = pic_register;
1950 /* Enable -mfix-cortex-m3-ldrd by default for Cortex-M3 cores. */
1951 if (fix_cm3_ldrd == 2)
1953 if (arm_selected_cpu->core == cortexm3)
1959 if (TARGET_THUMB1 && flag_schedule_insns)
1961 /* Don't warn since it's on by default in -O2. */
1962 flag_schedule_insns = 0;
1967 /* If optimizing for size, bump the number of instructions that we
1968 are prepared to conditionally execute (even on a StrongARM). */
1969 max_insns_skipped = 6;
1973 /* StrongARM has early execution of branches, so a sequence
1974 that is worth skipping is shorter. */
1975 if (arm_tune_strongarm)
1976 max_insns_skipped = 3;
1979 /* Hot/Cold partitioning is not currently supported, since we can't
1980 handle literal pool placement in that case. */
1981 if (flag_reorder_blocks_and_partition)
1983 inform (input_location,
1984 "-freorder-blocks-and-partition not supported on this architecture");
1985 flag_reorder_blocks_and_partition = 0;
1986 flag_reorder_blocks = 1;
1990 /* Hoisting PIC address calculations more aggressively provides a small,
1991 but measurable, size reduction for PIC code. Therefore, we decrease
1992 the bar for unrestricted expression hoisting to the cost of PIC address
1993 calculation, which is 2 instructions. */
1994 maybe_set_param_value (PARAM_GCSE_UNRESTRICTED_COST, 2,
1995 global_options.x_param_values,
1996 global_options_set.x_param_values);
1998 /* ARM EABI defaults to strict volatile bitfields. */
1999 if (TARGET_AAPCS_BASED && flag_strict_volatile_bitfields < 0)
2000 flag_strict_volatile_bitfields = 1;
2002 /* Enable sw prefetching at -O3 for CPUS that have prefetch, and we have deemed
2003 it beneficial (signified by setting num_prefetch_slots to 1 or more.) */
2004 if (flag_prefetch_loop_arrays < 0
2007 && current_tune->num_prefetch_slots > 0)
2008 flag_prefetch_loop_arrays = 1;
2010 /* Set up parameters to be used in prefetching algorithm. Do not override the
2011 defaults unless we are tuning for a core we have researched values for. */
2012 if (current_tune->num_prefetch_slots > 0)
2013 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
2014 current_tune->num_prefetch_slots,
2015 global_options.x_param_values,
2016 global_options_set.x_param_values);
2017 if (current_tune->l1_cache_line_size >= 0)
2018 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE,
2019 current_tune->l1_cache_line_size,
2020 global_options.x_param_values,
2021 global_options_set.x_param_values);
2022 if (current_tune->l1_cache_size >= 0)
2023 maybe_set_param_value (PARAM_L1_CACHE_SIZE,
2024 current_tune->l1_cache_size,
2025 global_options.x_param_values,
2026 global_options_set.x_param_values);
2028 /* Register global variables with the garbage collector. */
2029 arm_add_gc_roots ();
2033 arm_add_gc_roots (void)
2035 gcc_obstack_init(&minipool_obstack);
2036 minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0);
2039 /* A table of known ARM exception types.
2040 For use with the interrupt function attribute. */
2044 const char *const arg;
2045 const unsigned long return_value;
2049 static const isr_attribute_arg isr_attribute_args [] =
2051 { "IRQ", ARM_FT_ISR },
2052 { "irq", ARM_FT_ISR },
2053 { "FIQ", ARM_FT_FIQ },
2054 { "fiq", ARM_FT_FIQ },
2055 { "ABORT", ARM_FT_ISR },
2056 { "abort", ARM_FT_ISR },
2057 { "ABORT", ARM_FT_ISR },
2058 { "abort", ARM_FT_ISR },
2059 { "UNDEF", ARM_FT_EXCEPTION },
2060 { "undef", ARM_FT_EXCEPTION },
2061 { "SWI", ARM_FT_EXCEPTION },
2062 { "swi", ARM_FT_EXCEPTION },
2063 { NULL, ARM_FT_NORMAL }
2066 /* Returns the (interrupt) function type of the current
2067 function, or ARM_FT_UNKNOWN if the type cannot be determined. */
2069 static unsigned long
2070 arm_isr_value (tree argument)
2072 const isr_attribute_arg * ptr;
2076 return ARM_FT_NORMAL | ARM_FT_STACKALIGN;
2078 /* No argument - default to IRQ. */
2079 if (argument == NULL_TREE)
2082 /* Get the value of the argument. */
2083 if (TREE_VALUE (argument) == NULL_TREE
2084 || TREE_CODE (TREE_VALUE (argument)) != STRING_CST)
2085 return ARM_FT_UNKNOWN;
2087 arg = TREE_STRING_POINTER (TREE_VALUE (argument));
2089 /* Check it against the list of known arguments. */
2090 for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)
2091 if (streq (arg, ptr->arg))
2092 return ptr->return_value;
2094 /* An unrecognized interrupt type. */
2095 return ARM_FT_UNKNOWN;
2098 /* Computes the type of the current function. */
2100 static unsigned long
2101 arm_compute_func_type (void)
2103 unsigned long type = ARM_FT_UNKNOWN;
2107 gcc_assert (TREE_CODE (current_function_decl) == FUNCTION_DECL);
2109 /* Decide if the current function is volatile. Such functions
2110 never return, and many memory cycles can be saved by not storing
2111 register values that will never be needed again. This optimization
2112 was added to speed up context switching in a kernel application. */
2114 && (TREE_NOTHROW (current_function_decl)
2115 || !(flag_unwind_tables
2117 && arm_except_unwind_info (&global_options) != UI_SJLJ)))
2118 && TREE_THIS_VOLATILE (current_function_decl))
2119 type |= ARM_FT_VOLATILE;
2121 if (cfun->static_chain_decl != NULL)
2122 type |= ARM_FT_NESTED;
2124 attr = DECL_ATTRIBUTES (current_function_decl);
2126 a = lookup_attribute ("naked", attr);
2128 type |= ARM_FT_NAKED;
2130 a = lookup_attribute ("isr", attr);
2132 a = lookup_attribute ("interrupt", attr);
2135 type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL;
2137 type |= arm_isr_value (TREE_VALUE (a));
2142 /* Returns the type of the current function. */
2145 arm_current_func_type (void)
2147 if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN)
2148 cfun->machine->func_type = arm_compute_func_type ();
2150 return cfun->machine->func_type;
2154 arm_allocate_stack_slots_for_args (void)
2156 /* Naked functions should not allocate stack slots for arguments. */
2157 return !IS_NAKED (arm_current_func_type ());
2161 /* Output assembler code for a block containing the constant parts
2162 of a trampoline, leaving space for the variable parts.
2164 On the ARM, (if r8 is the static chain regnum, and remembering that
2165 referencing pc adds an offset of 8) the trampoline looks like:
2168 .word static chain value
2169 .word function's address
2170 XXX FIXME: When the trampoline returns, r8 will be clobbered. */
2173 arm_asm_trampoline_template (FILE *f)
2177 asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", STATIC_CHAIN_REGNUM, PC_REGNUM);
2178 asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", PC_REGNUM, PC_REGNUM);
2180 else if (TARGET_THUMB2)
2182 /* The Thumb-2 trampoline is similar to the arm implementation.
2183 Unlike 16-bit Thumb, we enter the stub in thumb mode. */
2184 asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n",
2185 STATIC_CHAIN_REGNUM, PC_REGNUM);
2186 asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n", PC_REGNUM, PC_REGNUM);
2190 ASM_OUTPUT_ALIGN (f, 2);
2191 fprintf (f, "\t.code\t16\n");
2192 fprintf (f, ".Ltrampoline_start:\n");
2193 asm_fprintf (f, "\tpush\t{r0, r1}\n");
2194 asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM);
2195 asm_fprintf (f, "\tmov\t%r, r0\n", STATIC_CHAIN_REGNUM);
2196 asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM);
2197 asm_fprintf (f, "\tstr\tr0, [%r, #4]\n", SP_REGNUM);
2198 asm_fprintf (f, "\tpop\t{r0, %r}\n", PC_REGNUM);
2200 assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
2201 assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
2204 /* Emit RTL insns to initialize the variable parts of a trampoline. */
2207 arm_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
2209 rtx fnaddr, mem, a_tramp;
2211 emit_block_move (m_tramp, assemble_trampoline_template (),
2212 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
2214 mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 8 : 12);
2215 emit_move_insn (mem, chain_value);
2217 mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 12 : 16);
2218 fnaddr = XEXP (DECL_RTL (fndecl), 0);
2219 emit_move_insn (mem, fnaddr);
2221 a_tramp = XEXP (m_tramp, 0);
2222 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"),
2223 LCT_NORMAL, VOIDmode, 2, a_tramp, Pmode,
2224 plus_constant (a_tramp, TRAMPOLINE_SIZE), Pmode);
2227 /* Thumb trampolines should be entered in thumb mode, so set
2228 the bottom bit of the address. */
2231 arm_trampoline_adjust_address (rtx addr)
2234 addr = expand_simple_binop (Pmode, IOR, addr, const1_rtx,
2235 NULL, 0, OPTAB_LIB_WIDEN);
2239 /* Return 1 if it is possible to return using a single instruction.
2240 If SIBLING is non-null, this is a test for a return before a sibling
2241 call. SIBLING is the call insn, so we can examine its register usage. */
2244 use_return_insn (int iscond, rtx sibling)
2247 unsigned int func_type;
2248 unsigned long saved_int_regs;
2249 unsigned HOST_WIDE_INT stack_adjust;
2250 arm_stack_offsets *offsets;
2252 /* Never use a return instruction before reload has run. */
2253 if (!reload_completed)
2256 func_type = arm_current_func_type ();
2258 /* Naked, volatile and stack alignment functions need special
2260 if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED | ARM_FT_STACKALIGN))
2263 /* So do interrupt functions that use the frame pointer and Thumb
2264 interrupt functions. */
2265 if (IS_INTERRUPT (func_type) && (frame_pointer_needed || TARGET_THUMB))
2268 offsets = arm_get_frame_offsets ();
2269 stack_adjust = offsets->outgoing_args - offsets->saved_regs;
2271 /* As do variadic functions. */
2272 if (crtl->args.pretend_args_size
2273 || cfun->machine->uses_anonymous_args
2274 /* Or if the function calls __builtin_eh_return () */
2275 || crtl->calls_eh_return
2276 /* Or if the function calls alloca */
2277 || cfun->calls_alloca
2278 /* Or if there is a stack adjustment. However, if the stack pointer
2279 is saved on the stack, we can use a pre-incrementing stack load. */
2280 || !(stack_adjust == 0 || (TARGET_APCS_FRAME && frame_pointer_needed
2281 && stack_adjust == 4)))
2284 saved_int_regs = offsets->saved_regs_mask;
2286 /* Unfortunately, the insn
2288 ldmib sp, {..., sp, ...}
2290 triggers a bug on most SA-110 based devices, such that the stack
2291 pointer won't be correctly restored if the instruction takes a
2292 page fault. We work around this problem by popping r3 along with
2293 the other registers, since that is never slower than executing
2294 another instruction.
2296 We test for !arm_arch5 here, because code for any architecture
2297 less than this could potentially be run on one of the buggy
2299 if (stack_adjust == 4 && !arm_arch5 && TARGET_ARM)
2301 /* Validate that r3 is a call-clobbered register (always true in
2302 the default abi) ... */
2303 if (!call_used_regs[3])
2306 /* ... that it isn't being used for a return value ... */
2307 if (arm_size_return_regs () >= (4 * UNITS_PER_WORD))
2310 /* ... or for a tail-call argument ... */
2313 gcc_assert (GET_CODE (sibling) == CALL_INSN);
2315 if (find_regno_fusage (sibling, USE, 3))
2319 /* ... and that there are no call-saved registers in r0-r2
2320 (always true in the default ABI). */
2321 if (saved_int_regs & 0x7)
2325 /* Can't be done if interworking with Thumb, and any registers have been
2327 if (TARGET_INTERWORK && saved_int_regs != 0 && !IS_INTERRUPT(func_type))
2330 /* On StrongARM, conditional returns are expensive if they aren't
2331 taken and multiple registers have been stacked. */
2332 if (iscond && arm_tune_strongarm)
2334 /* Conditional return when just the LR is stored is a simple
2335 conditional-load instruction, that's not expensive. */
2336 if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM))
2340 && arm_pic_register != INVALID_REGNUM
2341 && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM))
2345 /* If there are saved registers but the LR isn't saved, then we need
2346 two instructions for the return. */
2347 if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM)))
2350 /* Can't be done if any of the FPA regs are pushed,
2351 since this also requires an insn. */
2352 if (TARGET_HARD_FLOAT && TARGET_FPA)
2353 for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++)
2354 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
2357 /* Likewise VFP regs. */
2358 if (TARGET_HARD_FLOAT && TARGET_VFP)
2359 for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++)
2360 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
2363 if (TARGET_REALLY_IWMMXT)
2364 for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++)
2365 if (df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2371 /* Return TRUE if int I is a valid immediate ARM constant. */
2374 const_ok_for_arm (HOST_WIDE_INT i)
2378 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
2379 be all zero, or all one. */
2380 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
2381 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
2382 != ((~(unsigned HOST_WIDE_INT) 0)
2383 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
2386 i &= (unsigned HOST_WIDE_INT) 0xffffffff;
2388 /* Fast return for 0 and small values. We must do this for zero, since
2389 the code below can't handle that one case. */
2390 if ((i & ~(unsigned HOST_WIDE_INT) 0xff) == 0)
2393 /* Get the number of trailing zeros. */
2394 lowbit = ffs((int) i) - 1;
2396 /* Only even shifts are allowed in ARM mode so round down to the
2397 nearest even number. */
2401 if ((i & ~(((unsigned HOST_WIDE_INT) 0xff) << lowbit)) == 0)
2406 /* Allow rotated constants in ARM mode. */
2408 && ((i & ~0xc000003f) == 0
2409 || (i & ~0xf000000f) == 0
2410 || (i & ~0xfc000003) == 0))
2417 /* Allow repeated patterns 0x00XY00XY or 0xXYXYXYXY. */
2420 if (i == v || i == (v | (v << 8)))
2423 /* Allow repeated pattern 0xXY00XY00. */
2433 /* Return true if I is a valid constant for the operation CODE. */
2435 const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code)
2437 if (const_ok_for_arm (i))
2461 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
2463 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
2469 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
2473 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
2480 /* Emit a sequence of insns to handle a large constant.
2481 CODE is the code of the operation required, it can be any of SET, PLUS,
2482 IOR, AND, XOR, MINUS;
2483 MODE is the mode in which the operation is being performed;
2484 VAL is the integer to operate on;
2485 SOURCE is the other operand (a register, or a null-pointer for SET);
2486 SUBTARGETS means it is safe to create scratch registers if that will
2487 either produce a simpler sequence, or we will want to cse the values.
2488 Return value is the number of insns emitted. */
2490 /* ??? Tweak this for thumb2. */
2492 arm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn,
2493 HOST_WIDE_INT val, rtx target, rtx source, int subtargets)
2497 if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC)
2498 cond = COND_EXEC_TEST (PATTERN (insn));
2502 if (subtargets || code == SET
2503 || (GET_CODE (target) == REG && GET_CODE (source) == REG
2504 && REGNO (target) != REGNO (source)))
2506 /* After arm_reorg has been called, we can't fix up expensive
2507 constants by pushing them into memory so we must synthesize
2508 them in-line, regardless of the cost. This is only likely to
2509 be more costly on chips that have load delay slots and we are
2510 compiling without running the scheduler (so no splitting
2511 occurred before the final instruction emission).
2513 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
2515 if (!after_arm_reorg
2517 && (arm_gen_constant (code, mode, NULL_RTX, val, target, source,
2519 > (arm_constant_limit (optimize_function_for_size_p (cfun))
2524 /* Currently SET is the only monadic value for CODE, all
2525 the rest are diadic. */
2526 if (TARGET_USE_MOVT)
2527 arm_emit_movpair (target, GEN_INT (val));
2529 emit_set_insn (target, GEN_INT (val));
2535 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
2537 if (TARGET_USE_MOVT)
2538 arm_emit_movpair (temp, GEN_INT (val));
2540 emit_set_insn (temp, GEN_INT (val));
2542 /* For MINUS, the value is subtracted from, since we never
2543 have subtraction of a constant. */
2545 emit_set_insn (target, gen_rtx_MINUS (mode, temp, source));
2547 emit_set_insn (target,
2548 gen_rtx_fmt_ee (code, mode, source, temp));
2554 return arm_gen_constant (code, mode, cond, val, target, source, subtargets,
2558 /* Return the number of instructions required to synthesize the given
2559 constant, if we start emitting them from bit-position I. */
2561 count_insns_for_constant (HOST_WIDE_INT remainder, int i)
2563 HOST_WIDE_INT temp1;
2564 int step_size = TARGET_ARM ? 2 : 1;
2567 gcc_assert (TARGET_ARM || i == 0);
2575 if (remainder & (((1 << step_size) - 1) << (i - step_size)))
2580 temp1 = remainder & ((0x0ff << end)
2581 | ((i < end) ? (0xff >> (32 - end)) : 0));
2582 remainder &= ~temp1;
2587 } while (remainder);
2592 find_best_start (unsigned HOST_WIDE_INT remainder)
2594 int best_consecutive_zeros = 0;
2598 /* If we aren't targetting ARM, the best place to start is always at
2603 for (i = 0; i < 32; i += 2)
2605 int consecutive_zeros = 0;
2607 if (!(remainder & (3 << i)))
2609 while ((i < 32) && !(remainder & (3 << i)))
2611 consecutive_zeros += 2;
2614 if (consecutive_zeros > best_consecutive_zeros)
2616 best_consecutive_zeros = consecutive_zeros;
2617 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. */
2647 && ((((unsigned HOST_WIDE_INT) 1) << best_start) < remainder)
2648 && (count_insns_for_constant (remainder, 0) <=
2649 count_insns_for_constant (remainder, best_start)))
2655 /* Emit an instruction with the indicated PATTERN. If COND is
2656 non-NULL, conditionalize the execution of the instruction on COND
2660 emit_constant_insn (rtx cond, rtx pattern)
2663 pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern);
2664 emit_insn (pattern);
2667 /* As above, but extra parameter GENERATE which, if clear, suppresses
2669 /* ??? This needs more work for thumb2. */
2672 arm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond,
2673 HOST_WIDE_INT val, rtx target, rtx source, int subtargets,
2678 int final_invert = 0;
2679 int can_negate_initial = 0;
2681 int num_bits_set = 0;
2682 int set_sign_bit_copies = 0;
2683 int clear_sign_bit_copies = 0;
2684 int clear_zero_bit_copies = 0;
2685 int set_zero_bit_copies = 0;
2687 unsigned HOST_WIDE_INT temp1, temp2;
2688 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
2689 int step_size = TARGET_ARM ? 2 : 1;
2691 /* Find out which operations are safe for a given CODE. Also do a quick
2692 check for degenerate cases; these can occur when DImode operations
2703 can_negate_initial = 1;
2707 if (remainder == 0xffffffff)
2710 emit_constant_insn (cond,
2711 gen_rtx_SET (VOIDmode, target,
2712 GEN_INT (ARM_SIGN_EXTEND (val))));
2718 if (reload_completed && rtx_equal_p (target, source))
2722 emit_constant_insn (cond,
2723 gen_rtx_SET (VOIDmode, target, source));
2735 emit_constant_insn (cond,
2736 gen_rtx_SET (VOIDmode, target, const0_rtx));
2739 if (remainder == 0xffffffff)
2741 if (reload_completed && rtx_equal_p (target, source))
2744 emit_constant_insn (cond,
2745 gen_rtx_SET (VOIDmode, target, source));
2754 if (reload_completed && rtx_equal_p (target, source))
2757 emit_constant_insn (cond,
2758 gen_rtx_SET (VOIDmode, target, source));
2762 if (remainder == 0xffffffff)
2765 emit_constant_insn (cond,
2766 gen_rtx_SET (VOIDmode, target,
2767 gen_rtx_NOT (mode, source)));
2773 /* We treat MINUS as (val - source), since (source - val) is always
2774 passed as (source + (-val)). */
2778 emit_constant_insn (cond,
2779 gen_rtx_SET (VOIDmode, target,
2780 gen_rtx_NEG (mode, source)));
2783 if (const_ok_for_arm (val))
2786 emit_constant_insn (cond,
2787 gen_rtx_SET (VOIDmode, target,
2788 gen_rtx_MINUS (mode, GEN_INT (val),
2800 /* If we can do it in one insn get out quickly. */
2801 if (const_ok_for_arm (val)
2802 || (can_negate_initial && const_ok_for_arm (-val))
2803 || (can_invert && const_ok_for_arm (~val)))
2806 emit_constant_insn (cond,
2807 gen_rtx_SET (VOIDmode, target,
2809 ? gen_rtx_fmt_ee (code, mode, source,
2815 /* Calculate a few attributes that may be useful for specific
2817 /* Count number of leading zeros. */
2818 for (i = 31; i >= 0; i--)
2820 if ((remainder & (1 << i)) == 0)
2821 clear_sign_bit_copies++;
2826 /* Count number of leading 1's. */
2827 for (i = 31; i >= 0; i--)
2829 if ((remainder & (1 << i)) != 0)
2830 set_sign_bit_copies++;
2835 /* Count number of trailing zero's. */
2836 for (i = 0; i <= 31; i++)
2838 if ((remainder & (1 << i)) == 0)
2839 clear_zero_bit_copies++;
2844 /* Count number of trailing 1's. */
2845 for (i = 0; i <= 31; i++)
2847 if ((remainder & (1 << i)) != 0)
2848 set_zero_bit_copies++;
2856 /* See if we can use movw. */
2857 if (arm_arch_thumb2 && (remainder & 0xffff0000) == 0)
2860 emit_constant_insn (cond, gen_rtx_SET (VOIDmode, target,
2865 /* See if we can do this by sign_extending a constant that is known
2866 to be negative. This is a good, way of doing it, since the shift
2867 may well merge into a subsequent insn. */
2868 if (set_sign_bit_copies > 1)
2870 if (const_ok_for_arm
2871 (temp1 = ARM_SIGN_EXTEND (remainder
2872 << (set_sign_bit_copies - 1))))
2876 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2877 emit_constant_insn (cond,
2878 gen_rtx_SET (VOIDmode, new_src,
2880 emit_constant_insn (cond,
2881 gen_ashrsi3 (target, new_src,
2882 GEN_INT (set_sign_bit_copies - 1)));
2886 /* For an inverted constant, we will need to set the low bits,
2887 these will be shifted out of harm's way. */
2888 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
2889 if (const_ok_for_arm (~temp1))
2893 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2894 emit_constant_insn (cond,
2895 gen_rtx_SET (VOIDmode, new_src,
2897 emit_constant_insn (cond,
2898 gen_ashrsi3 (target, new_src,
2899 GEN_INT (set_sign_bit_copies - 1)));
2905 /* See if we can calculate the value as the difference between two
2906 valid immediates. */
2907 if (clear_sign_bit_copies + clear_zero_bit_copies <= 16)
2909 int topshift = clear_sign_bit_copies & ~1;
2911 temp1 = ARM_SIGN_EXTEND ((remainder + (0x00800000 >> topshift))
2912 & (0xff000000 >> topshift));
2914 /* If temp1 is zero, then that means the 9 most significant
2915 bits of remainder were 1 and we've caused it to overflow.
2916 When topshift is 0 we don't need to do anything since we
2917 can borrow from 'bit 32'. */
2918 if (temp1 == 0 && topshift != 0)
2919 temp1 = 0x80000000 >> (topshift - 1);
2921 temp2 = ARM_SIGN_EXTEND (temp1 - remainder);
2923 if (const_ok_for_arm (temp2))
2927 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2928 emit_constant_insn (cond,
2929 gen_rtx_SET (VOIDmode, new_src,
2931 emit_constant_insn (cond,
2932 gen_addsi3 (target, new_src,
2940 /* See if we can generate this by setting the bottom (or the top)
2941 16 bits, and then shifting these into the other half of the
2942 word. We only look for the simplest cases, to do more would cost
2943 too much. Be careful, however, not to generate this when the
2944 alternative would take fewer insns. */
2945 if (val & 0xffff0000)
2947 temp1 = remainder & 0xffff0000;
2948 temp2 = remainder & 0x0000ffff;
2950 /* Overlaps outside this range are best done using other methods. */
2951 for (i = 9; i < 24; i++)
2953 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
2954 && !const_ok_for_arm (temp2))
2956 rtx new_src = (subtargets
2957 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
2959 insns = arm_gen_constant (code, mode, cond, temp2, new_src,
2960 source, subtargets, generate);
2968 gen_rtx_ASHIFT (mode, source,
2975 /* Don't duplicate cases already considered. */
2976 for (i = 17; i < 24; i++)
2978 if (((temp1 | (temp1 >> i)) == remainder)
2979 && !const_ok_for_arm (temp1))
2981 rtx new_src = (subtargets
2982 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
2984 insns = arm_gen_constant (code, mode, cond, temp1, new_src,
2985 source, subtargets, generate);
2990 gen_rtx_SET (VOIDmode, target,
2993 gen_rtx_LSHIFTRT (mode, source,
3004 /* If we have IOR or XOR, and the constant can be loaded in a
3005 single instruction, and we can find a temporary to put it in,
3006 then this can be done in two instructions instead of 3-4. */
3008 /* TARGET can't be NULL if SUBTARGETS is 0 */
3009 || (reload_completed && !reg_mentioned_p (target, source)))
3011 if (const_ok_for_arm (ARM_SIGN_EXTEND (~val)))
3015 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3017 emit_constant_insn (cond,
3018 gen_rtx_SET (VOIDmode, sub,
3020 emit_constant_insn (cond,
3021 gen_rtx_SET (VOIDmode, target,
3022 gen_rtx_fmt_ee (code, mode,
3033 x = y | constant ( which is composed of set_sign_bit_copies of leading 1s
3034 and the remainder 0s for e.g. 0xfff00000)
3035 x = ~(~(y ashift set_sign_bit_copies) lshiftrt set_sign_bit_copies)
3037 This can be done in 2 instructions by using shifts with mov or mvn.
3042 mvn r0, r0, lsr #12 */
3043 if (set_sign_bit_copies > 8
3044 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
3048 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3049 rtx shift = GEN_INT (set_sign_bit_copies);
3053 gen_rtx_SET (VOIDmode, sub,
3055 gen_rtx_ASHIFT (mode,
3060 gen_rtx_SET (VOIDmode, target,
3062 gen_rtx_LSHIFTRT (mode, sub,
3069 x = y | constant (which has set_zero_bit_copies number of trailing ones).
3071 x = ~((~y lshiftrt set_zero_bit_copies) ashift set_zero_bit_copies).
3073 For eg. r0 = r0 | 0xfff
3078 if (set_zero_bit_copies > 8
3079 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
3083 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3084 rtx shift = GEN_INT (set_zero_bit_copies);
3088 gen_rtx_SET (VOIDmode, sub,
3090 gen_rtx_LSHIFTRT (mode,
3095 gen_rtx_SET (VOIDmode, target,
3097 gen_rtx_ASHIFT (mode, sub,
3103 /* This will never be reached for Thumb2 because orn is a valid
3104 instruction. This is for Thumb1 and the ARM 32 bit cases.
3106 x = y | constant (such that ~constant is a valid constant)
3108 x = ~(~y & ~constant).
3110 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val)))
3114 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3115 emit_constant_insn (cond,
3116 gen_rtx_SET (VOIDmode, sub,
3117 gen_rtx_NOT (mode, source)));
3120 sub = gen_reg_rtx (mode);
3121 emit_constant_insn (cond,
3122 gen_rtx_SET (VOIDmode, sub,
3123 gen_rtx_AND (mode, source,
3125 emit_constant_insn (cond,
3126 gen_rtx_SET (VOIDmode, target,
3127 gen_rtx_NOT (mode, sub)));
3134 /* See if two shifts will do 2 or more insn's worth of work. */
3135 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
3137 HOST_WIDE_INT shift_mask = ((0xffffffff
3138 << (32 - clear_sign_bit_copies))
3141 if ((remainder | shift_mask) != 0xffffffff)
3145 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3146 insns = arm_gen_constant (AND, mode, cond,
3147 remainder | shift_mask,
3148 new_src, source, subtargets, 1);
3153 rtx targ = subtargets ? NULL_RTX : target;
3154 insns = arm_gen_constant (AND, mode, cond,
3155 remainder | shift_mask,
3156 targ, source, subtargets, 0);
3162 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3163 rtx shift = GEN_INT (clear_sign_bit_copies);
3165 emit_insn (gen_ashlsi3 (new_src, source, shift));
3166 emit_insn (gen_lshrsi3 (target, new_src, shift));
3172 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
3174 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
3176 if ((remainder | shift_mask) != 0xffffffff)
3180 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3182 insns = arm_gen_constant (AND, mode, cond,
3183 remainder | shift_mask,
3184 new_src, source, subtargets, 1);
3189 rtx targ = subtargets ? NULL_RTX : target;
3191 insns = arm_gen_constant (AND, mode, cond,
3192 remainder | shift_mask,
3193 targ, source, subtargets, 0);
3199 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3200 rtx shift = GEN_INT (clear_zero_bit_copies);
3202 emit_insn (gen_lshrsi3 (new_src, source, shift));
3203 emit_insn (gen_ashlsi3 (target, new_src, shift));
3215 for (i = 0; i < 32; i++)
3216 if (remainder & (1 << i))
3220 || (code != IOR && can_invert && num_bits_set > 16))
3221 remainder ^= 0xffffffff;
3222 else if (code == PLUS && num_bits_set > 16)
3223 remainder = (-remainder) & 0xffffffff;
3225 /* For XOR, if more than half the bits are set and there's a sequence
3226 of more than 8 consecutive ones in the pattern then we can XOR by the
3227 inverted constant and then invert the final result; this may save an
3228 instruction and might also lead to the final mvn being merged with
3229 some other operation. */
3230 else if (code == XOR && num_bits_set > 16
3231 && (count_insns_for_constant (remainder ^ 0xffffffff,
3233 (remainder ^ 0xffffffff))
3234 < count_insns_for_constant (remainder,
3235 find_best_start (remainder))))
3237 remainder ^= 0xffffffff;
3246 /* Now try and find a way of doing the job in either two or three
3248 We start by looking for the largest block of zeros that are aligned on
3249 a 2-bit boundary, we then fill up the temps, wrapping around to the
3250 top of the word when we drop off the bottom.
3251 In the worst case this code should produce no more than four insns.
3252 Thumb-2 constants are shifted, not rotated, so the MSB is always the
3253 best place to start. */
3255 /* ??? Use thumb2 replicated constants when the high and low halfwords are
3258 /* Now start emitting the insns. */
3259 i = find_best_start (remainder);
3266 if (remainder & (3 << (i - 2)))
3271 temp1 = remainder & ((0x0ff << end)
3272 | ((i < end) ? (0xff >> (32 - end)) : 0));
3273 remainder &= ~temp1;
3277 rtx new_src, temp1_rtx;
3279 if (code == SET || code == MINUS)
3281 new_src = (subtargets ? gen_reg_rtx (mode) : target);
3282 if (can_invert && code != MINUS)
3287 if ((final_invert || remainder) && subtargets)
3288 new_src = gen_reg_rtx (mode);
3293 else if (can_negate)
3297 temp1 = trunc_int_for_mode (temp1, mode);
3298 temp1_rtx = GEN_INT (temp1);
3302 else if (code == MINUS)
3303 temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source);
3305 temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx);
3307 emit_constant_insn (cond,
3308 gen_rtx_SET (VOIDmode, new_src,
3318 else if (code == MINUS)
3324 /* Arm allows rotates by a multiple of two. Thumb-2 allows arbitrary
3334 emit_constant_insn (cond, gen_rtx_SET (VOIDmode, target,
3335 gen_rtx_NOT (mode, source)));
3342 /* Canonicalize a comparison so that we are more likely to recognize it.
3343 This can be done for a few constant compares, where we can make the
3344 immediate value easier to load. */
3347 arm_canonicalize_comparison (enum rtx_code code, rtx *op0, rtx *op1)
3349 enum machine_mode mode;
3350 unsigned HOST_WIDE_INT i, maxval;
3352 mode = GET_MODE (*op0);
3353 if (mode == VOIDmode)
3354 mode = GET_MODE (*op1);
3356 maxval = (((unsigned HOST_WIDE_INT) 1) << (GET_MODE_BITSIZE(mode) - 1)) - 1;
3358 /* For DImode, we have GE/LT/GEU/LTU comparisons. In ARM mode
3359 we can also use cmp/cmpeq for GTU/LEU. GT/LE must be either
3360 reversed or (for constant OP1) adjusted to GE/LT. Similarly
3361 for GTU/LEU in Thumb mode. */
3366 /* To keep things simple, always use the Cirrus cfcmp64 if it is
3368 if (TARGET_ARM && TARGET_HARD_FLOAT && TARGET_MAVERICK)
3371 if (code == GT || code == LE
3372 || (!TARGET_ARM && (code == GTU || code == LEU)))
3374 /* Missing comparison. First try to use an available
3376 if (GET_CODE (*op1) == CONST_INT)
3384 && arm_const_double_by_immediates (GEN_INT (i + 1)))
3386 *op1 = GEN_INT (i + 1);
3387 return code == GT ? GE : LT;
3392 if (i != ~((unsigned HOST_WIDE_INT) 0)
3393 && arm_const_double_by_immediates (GEN_INT (i + 1)))
3395 *op1 = GEN_INT (i + 1);
3396 return code == GTU ? GEU : LTU;
3404 /* If that did not work, reverse the condition. */
3408 return swap_condition (code);
3414 /* Comparisons smaller than DImode. Only adjust comparisons against
3415 an out-of-range constant. */
3416 if (GET_CODE (*op1) != CONST_INT
3417 || const_ok_for_arm (INTVAL (*op1))
3418 || const_ok_for_arm (- INTVAL (*op1)))
3432 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
3434 *op1 = GEN_INT (i + 1);
3435 return code == GT ? GE : LT;