1 /* Output routines for GCC for ARM.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5 Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl)
6 and Martin Simmons (@harleqn.co.uk).
7 More major hacks by Richard Earnshaw (rearnsha@arm.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published
13 by the Free Software Foundation; either version 3, or (at your
14 option) any later version.
16 GCC is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 #include "coretypes.h"
33 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "conditions.h"
37 #include "insn-attr.h"
43 #include "diagnostic-core.h"
48 #include "c-family/c-pragma.h" /* ??? */
49 #include "integrate.h"
52 #include "target-def.h"
54 #include "langhooks.h"
61 /* Forward definitions of types. */
62 typedef struct minipool_node Mnode;
63 typedef struct minipool_fixup Mfix;
65 void (*arm_lang_output_object_attributes_hook)(void);
72 /* Forward function declarations. */
73 static bool arm_needs_doubleword_align (enum machine_mode, const_tree);
74 static int arm_compute_static_chain_stack_bytes (void);
75 static arm_stack_offsets *arm_get_frame_offsets (void);
76 static void arm_add_gc_roots (void);
77 static int arm_gen_constant (enum rtx_code, enum machine_mode, rtx,
78 HOST_WIDE_INT, rtx, rtx, int, int);
79 static unsigned bit_count (unsigned long);
80 static int arm_address_register_rtx_p (rtx, int);
81 static int arm_legitimate_index_p (enum machine_mode, rtx, RTX_CODE, int);
82 static int thumb2_legitimate_index_p (enum machine_mode, rtx, int);
83 static int thumb1_base_register_rtx_p (rtx, enum machine_mode, int);
84 static rtx arm_legitimize_address (rtx, rtx, enum machine_mode);
85 static rtx thumb_legitimize_address (rtx, rtx, enum machine_mode);
86 inline static int thumb1_index_register_rtx_p (rtx, int);
87 static bool arm_legitimate_address_p (enum machine_mode, rtx, bool);
88 static int thumb_far_jump_used_p (void);
89 static bool thumb_force_lr_save (void);
90 static rtx emit_sfm (int, int);
91 static unsigned arm_size_return_regs (void);
92 static bool arm_assemble_integer (rtx, unsigned int, int);
93 static void arm_print_operand (FILE *, rtx, int);
94 static void arm_print_operand_address (FILE *, rtx);
95 static bool arm_print_operand_punct_valid_p (unsigned char code);
96 static const char *fp_const_from_val (REAL_VALUE_TYPE *);
97 static arm_cc get_arm_condition_code (rtx);
98 static HOST_WIDE_INT int_log2 (HOST_WIDE_INT);
99 static rtx is_jump_table (rtx);
100 static const char *output_multi_immediate (rtx *, const char *, const char *,
102 static const char *shift_op (rtx, HOST_WIDE_INT *);
103 static struct machine_function *arm_init_machine_status (void);
104 static void thumb_exit (FILE *, int);
105 static rtx is_jump_table (rtx);
106 static HOST_WIDE_INT get_jump_table_size (rtx);
107 static Mnode *move_minipool_fix_forward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
108 static Mnode *add_minipool_forward_ref (Mfix *);
109 static Mnode *move_minipool_fix_backward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
110 static Mnode *add_minipool_backward_ref (Mfix *);
111 static void assign_minipool_offsets (Mfix *);
112 static void arm_print_value (FILE *, rtx);
113 static void dump_minipool (rtx);
114 static int arm_barrier_cost (rtx);
115 static Mfix *create_fix_barrier (Mfix *, HOST_WIDE_INT);
116 static void push_minipool_barrier (rtx, HOST_WIDE_INT);
117 static void push_minipool_fix (rtx, HOST_WIDE_INT, rtx *, enum machine_mode,
119 static void arm_reorg (void);
120 static bool note_invalid_constants (rtx, HOST_WIDE_INT, int);
121 static unsigned long arm_compute_save_reg0_reg12_mask (void);
122 static unsigned long arm_compute_save_reg_mask (void);
123 static unsigned long arm_isr_value (tree);
124 static unsigned long arm_compute_func_type (void);
125 static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
126 static tree arm_handle_pcs_attribute (tree *, tree, tree, int, bool *);
127 static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *);
128 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
129 static tree arm_handle_notshared_attribute (tree *, tree, tree, int, bool *);
131 static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT);
132 static void arm_output_function_prologue (FILE *, HOST_WIDE_INT);
133 static int arm_comp_type_attributes (const_tree, const_tree);
134 static void arm_set_default_type_attributes (tree);
135 static int arm_adjust_cost (rtx, rtx, rtx, int);
136 static int optimal_immediate_sequence (enum rtx_code code,
137 unsigned HOST_WIDE_INT val,
138 struct four_ints *return_sequence);
139 static int optimal_immediate_sequence_1 (enum rtx_code code,
140 unsigned HOST_WIDE_INT val,
141 struct four_ints *return_sequence,
143 static int arm_get_strip_length (int);
144 static bool arm_function_ok_for_sibcall (tree, tree);
145 static enum machine_mode arm_promote_function_mode (const_tree,
146 enum machine_mode, int *,
148 static bool arm_return_in_memory (const_tree, const_tree);
149 static rtx arm_function_value (const_tree, const_tree, bool);
150 static rtx arm_libcall_value_1 (enum machine_mode);
151 static rtx arm_libcall_value (enum machine_mode, const_rtx);
152 static bool arm_function_value_regno_p (const unsigned int);
153 static void arm_internal_label (FILE *, const char *, unsigned long);
154 static void arm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
156 static bool arm_have_conditional_execution (void);
157 static bool arm_cannot_force_const_mem (enum machine_mode, rtx);
158 static bool arm_legitimate_constant_p (enum machine_mode, rtx);
159 static bool arm_rtx_costs_1 (rtx, enum rtx_code, int*, bool);
160 static bool arm_size_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *);
161 static bool arm_slowmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
162 static bool arm_fastmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
163 static bool arm_xscale_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
164 static bool arm_9e_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
165 static bool arm_rtx_costs (rtx, int, int, int, int *, bool);
166 static int arm_address_cost (rtx, bool);
167 static int arm_register_move_cost (enum machine_mode, reg_class_t, reg_class_t);
168 static int arm_memory_move_cost (enum machine_mode, reg_class_t, bool);
169 static bool arm_memory_load_p (rtx);
170 static bool arm_cirrus_insn_p (rtx);
171 static void cirrus_reorg (rtx);
172 static void arm_init_builtins (void);
173 static void arm_init_iwmmxt_builtins (void);
174 static rtx safe_vector_operand (rtx, enum machine_mode);
175 static rtx arm_expand_binop_builtin (enum insn_code, tree, rtx);
176 static rtx arm_expand_unop_builtin (enum insn_code, tree, rtx, int);
177 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
178 static tree arm_builtin_decl (unsigned, bool);
179 static void emit_constant_insn (rtx cond, rtx pattern);
180 static rtx emit_set_insn (rtx, rtx);
181 static int arm_arg_partial_bytes (cumulative_args_t, enum machine_mode,
183 static rtx arm_function_arg (cumulative_args_t, enum machine_mode,
185 static void arm_function_arg_advance (cumulative_args_t, enum machine_mode,
187 static unsigned int arm_function_arg_boundary (enum machine_mode, const_tree);
188 static rtx aapcs_allocate_return_reg (enum machine_mode, const_tree,
190 static rtx aapcs_libcall_value (enum machine_mode);
191 static int aapcs_select_return_coproc (const_tree, const_tree);
193 #ifdef OBJECT_FORMAT_ELF
194 static void arm_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED;
195 static void arm_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED;
198 static void arm_encode_section_info (tree, rtx, int);
201 static void arm_file_end (void);
202 static void arm_file_start (void);
204 static void arm_setup_incoming_varargs (cumulative_args_t, enum machine_mode,
206 static bool arm_pass_by_reference (cumulative_args_t,
207 enum machine_mode, const_tree, bool);
208 static bool arm_promote_prototypes (const_tree);
209 static bool arm_default_short_enums (void);
210 static bool arm_align_anon_bitfield (void);
211 static bool arm_return_in_msb (const_tree);
212 static bool arm_must_pass_in_stack (enum machine_mode, const_tree);
213 static bool arm_return_in_memory (const_tree, const_tree);
215 static void arm_unwind_emit (FILE *, rtx);
216 static bool arm_output_ttype (rtx);
217 static void arm_asm_emit_except_personality (rtx);
218 static void arm_asm_init_sections (void);
220 static rtx arm_dwarf_register_span (rtx);
222 static tree arm_cxx_guard_type (void);
223 static bool arm_cxx_guard_mask_bit (void);
224 static tree arm_get_cookie_size (tree);
225 static bool arm_cookie_has_size (void);
226 static bool arm_cxx_cdtor_returns_this (void);
227 static bool arm_cxx_key_method_may_be_inline (void);
228 static void arm_cxx_determine_class_data_visibility (tree);
229 static bool arm_cxx_class_data_always_comdat (void);
230 static bool arm_cxx_use_aeabi_atexit (void);
231 static void arm_init_libfuncs (void);
232 static tree arm_build_builtin_va_list (void);
233 static void arm_expand_builtin_va_start (tree, rtx);
234 static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
235 static void arm_option_override (void);
236 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode);
237 static bool arm_cannot_copy_insn_p (rtx);
238 static bool arm_tls_symbol_p (rtx x);
239 static int arm_issue_rate (void);
240 static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
241 static bool arm_output_addr_const_extra (FILE *, rtx);
242 static bool arm_allocate_stack_slots_for_args (void);
243 static const char *arm_invalid_parameter_type (const_tree t);
244 static const char *arm_invalid_return_type (const_tree t);
245 static tree arm_promoted_type (const_tree t);
246 static tree arm_convert_to_type (tree type, tree expr);
247 static bool arm_scalar_mode_supported_p (enum machine_mode);
248 static bool arm_frame_pointer_required (void);
249 static bool arm_can_eliminate (const int, const int);
250 static void arm_asm_trampoline_template (FILE *);
251 static void arm_trampoline_init (rtx, tree, rtx);
252 static rtx arm_trampoline_adjust_address (rtx);
253 static rtx arm_pic_static_addr (rtx orig, rtx reg);
254 static bool cortex_a9_sched_adjust_cost (rtx, rtx, rtx, int *);
255 static bool xscale_sched_adjust_cost (rtx, rtx, rtx, int *);
256 static bool fa726te_sched_adjust_cost (rtx, rtx, rtx, int *);
257 static bool arm_array_mode_supported_p (enum machine_mode,
258 unsigned HOST_WIDE_INT);
259 static enum machine_mode arm_preferred_simd_mode (enum machine_mode);
260 static bool arm_class_likely_spilled_p (reg_class_t);
261 static bool arm_vector_alignment_reachable (const_tree type, bool is_packed);
262 static bool arm_builtin_support_vector_misalignment (enum machine_mode mode,
266 static void arm_conditional_register_usage (void);
267 static reg_class_t arm_preferred_rename_class (reg_class_t rclass);
268 static unsigned int arm_autovectorize_vector_sizes (void);
269 static int arm_default_branch_cost (bool, bool);
270 static int arm_cortex_a5_branch_cost (bool, bool);
273 /* Table of machine attributes. */
274 static const struct attribute_spec arm_attribute_table[] =
276 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
277 affects_type_identity } */
278 /* Function calls made to this symbol must be done indirectly, because
279 it may lie outside of the 26 bit addressing range of a normal function
281 { "long_call", 0, 0, false, true, true, NULL, false },
282 /* Whereas these functions are always known to reside within the 26 bit
284 { "short_call", 0, 0, false, true, true, NULL, false },
285 /* Specify the procedure call conventions for a function. */
286 { "pcs", 1, 1, false, true, true, arm_handle_pcs_attribute,
288 /* Interrupt Service Routines have special prologue and epilogue requirements. */
289 { "isr", 0, 1, false, false, false, arm_handle_isr_attribute,
291 { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute,
293 { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute,
296 /* ARM/PE has three new attributes:
298 dllexport - for exporting a function/variable that will live in a dll
299 dllimport - for importing a function/variable from a dll
301 Microsoft allows multiple declspecs in one __declspec, separating
302 them with spaces. We do NOT support this. Instead, use __declspec
305 { "dllimport", 0, 0, true, false, false, NULL, false },
306 { "dllexport", 0, 0, true, false, false, NULL, false },
307 { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute,
309 #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
310 { "dllimport", 0, 0, false, false, false, handle_dll_attribute, false },
311 { "dllexport", 0, 0, false, false, false, handle_dll_attribute, false },
312 { "notshared", 0, 0, false, true, false, arm_handle_notshared_attribute,
315 { NULL, 0, 0, false, false, false, NULL, false }
318 /* Initialize the GCC target structure. */
319 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
320 #undef TARGET_MERGE_DECL_ATTRIBUTES
321 #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
324 #undef TARGET_LEGITIMIZE_ADDRESS
325 #define TARGET_LEGITIMIZE_ADDRESS arm_legitimize_address
327 #undef TARGET_ATTRIBUTE_TABLE
328 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
330 #undef TARGET_ASM_FILE_START
331 #define TARGET_ASM_FILE_START arm_file_start
332 #undef TARGET_ASM_FILE_END
333 #define TARGET_ASM_FILE_END arm_file_end
335 #undef TARGET_ASM_ALIGNED_SI_OP
336 #define TARGET_ASM_ALIGNED_SI_OP NULL
337 #undef TARGET_ASM_INTEGER
338 #define TARGET_ASM_INTEGER arm_assemble_integer
340 #undef TARGET_PRINT_OPERAND
341 #define TARGET_PRINT_OPERAND arm_print_operand
342 #undef TARGET_PRINT_OPERAND_ADDRESS
343 #define TARGET_PRINT_OPERAND_ADDRESS arm_print_operand_address
344 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
345 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P arm_print_operand_punct_valid_p
347 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
348 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA arm_output_addr_const_extra
350 #undef TARGET_ASM_FUNCTION_PROLOGUE
351 #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue
353 #undef TARGET_ASM_FUNCTION_EPILOGUE
354 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
356 #undef TARGET_OPTION_OVERRIDE
357 #define TARGET_OPTION_OVERRIDE arm_option_override
359 #undef TARGET_COMP_TYPE_ATTRIBUTES
360 #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes
362 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
363 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes
365 #undef TARGET_SCHED_ADJUST_COST
366 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
368 #undef TARGET_REGISTER_MOVE_COST
369 #define TARGET_REGISTER_MOVE_COST arm_register_move_cost
371 #undef TARGET_MEMORY_MOVE_COST
372 #define TARGET_MEMORY_MOVE_COST arm_memory_move_cost
374 #undef TARGET_ENCODE_SECTION_INFO
376 #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info
378 #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info
381 #undef TARGET_STRIP_NAME_ENCODING
382 #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding
384 #undef TARGET_ASM_INTERNAL_LABEL
385 #define TARGET_ASM_INTERNAL_LABEL arm_internal_label
387 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
388 #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall
390 #undef TARGET_FUNCTION_VALUE
391 #define TARGET_FUNCTION_VALUE arm_function_value
393 #undef TARGET_LIBCALL_VALUE
394 #define TARGET_LIBCALL_VALUE arm_libcall_value
396 #undef TARGET_FUNCTION_VALUE_REGNO_P
397 #define TARGET_FUNCTION_VALUE_REGNO_P arm_function_value_regno_p
399 #undef TARGET_ASM_OUTPUT_MI_THUNK
400 #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk
401 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
402 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
404 #undef TARGET_RTX_COSTS
405 #define TARGET_RTX_COSTS arm_rtx_costs
406 #undef TARGET_ADDRESS_COST
407 #define TARGET_ADDRESS_COST arm_address_cost
409 #undef TARGET_SHIFT_TRUNCATION_MASK
410 #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask
411 #undef TARGET_VECTOR_MODE_SUPPORTED_P
412 #define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p
413 #undef TARGET_ARRAY_MODE_SUPPORTED_P
414 #define TARGET_ARRAY_MODE_SUPPORTED_P arm_array_mode_supported_p
415 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
416 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE arm_preferred_simd_mode
417 #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES
418 #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES \
419 arm_autovectorize_vector_sizes
421 #undef TARGET_MACHINE_DEPENDENT_REORG
422 #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg
424 #undef TARGET_INIT_BUILTINS
425 #define TARGET_INIT_BUILTINS arm_init_builtins
426 #undef TARGET_EXPAND_BUILTIN
427 #define TARGET_EXPAND_BUILTIN arm_expand_builtin
428 #undef TARGET_BUILTIN_DECL
429 #define TARGET_BUILTIN_DECL arm_builtin_decl
431 #undef TARGET_INIT_LIBFUNCS
432 #define TARGET_INIT_LIBFUNCS arm_init_libfuncs
434 #undef TARGET_PROMOTE_FUNCTION_MODE
435 #define TARGET_PROMOTE_FUNCTION_MODE arm_promote_function_mode
436 #undef TARGET_PROMOTE_PROTOTYPES
437 #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes
438 #undef TARGET_PASS_BY_REFERENCE
439 #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference
440 #undef TARGET_ARG_PARTIAL_BYTES
441 #define TARGET_ARG_PARTIAL_BYTES arm_arg_partial_bytes
442 #undef TARGET_FUNCTION_ARG
443 #define TARGET_FUNCTION_ARG arm_function_arg
444 #undef TARGET_FUNCTION_ARG_ADVANCE
445 #define TARGET_FUNCTION_ARG_ADVANCE arm_function_arg_advance
446 #undef TARGET_FUNCTION_ARG_BOUNDARY
447 #define TARGET_FUNCTION_ARG_BOUNDARY arm_function_arg_boundary
449 #undef TARGET_SETUP_INCOMING_VARARGS
450 #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs
452 #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
453 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args
455 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
456 #define TARGET_ASM_TRAMPOLINE_TEMPLATE arm_asm_trampoline_template
457 #undef TARGET_TRAMPOLINE_INIT
458 #define TARGET_TRAMPOLINE_INIT arm_trampoline_init
459 #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
460 #define TARGET_TRAMPOLINE_ADJUST_ADDRESS arm_trampoline_adjust_address
462 #undef TARGET_DEFAULT_SHORT_ENUMS
463 #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
465 #undef TARGET_ALIGN_ANON_BITFIELD
466 #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield
468 #undef TARGET_NARROW_VOLATILE_BITFIELD
469 #define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
471 #undef TARGET_CXX_GUARD_TYPE
472 #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type
474 #undef TARGET_CXX_GUARD_MASK_BIT
475 #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit
477 #undef TARGET_CXX_GET_COOKIE_SIZE
478 #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size
480 #undef TARGET_CXX_COOKIE_HAS_SIZE
481 #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size
483 #undef TARGET_CXX_CDTOR_RETURNS_THIS
484 #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this
486 #undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE
487 #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline
489 #undef TARGET_CXX_USE_AEABI_ATEXIT
490 #define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit
492 #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY
493 #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \
494 arm_cxx_determine_class_data_visibility
496 #undef TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT
497 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT arm_cxx_class_data_always_comdat
499 #undef TARGET_RETURN_IN_MSB
500 #define TARGET_RETURN_IN_MSB arm_return_in_msb
502 #undef TARGET_RETURN_IN_MEMORY
503 #define TARGET_RETURN_IN_MEMORY arm_return_in_memory
505 #undef TARGET_MUST_PASS_IN_STACK
506 #define TARGET_MUST_PASS_IN_STACK arm_must_pass_in_stack
509 #undef TARGET_ASM_UNWIND_EMIT
510 #define TARGET_ASM_UNWIND_EMIT arm_unwind_emit
512 /* EABI unwinding tables use a different format for the typeinfo tables. */
513 #undef TARGET_ASM_TTYPE
514 #define TARGET_ASM_TTYPE arm_output_ttype
516 #undef TARGET_ARM_EABI_UNWINDER
517 #define TARGET_ARM_EABI_UNWINDER true
519 #undef TARGET_ASM_EMIT_EXCEPT_PERSONALITY
520 #define TARGET_ASM_EMIT_EXCEPT_PERSONALITY arm_asm_emit_except_personality
522 #undef TARGET_ASM_INIT_SECTIONS
523 #define TARGET_ASM_INIT_SECTIONS arm_asm_init_sections
524 #endif /* ARM_UNWIND_INFO */
526 #undef TARGET_DWARF_REGISTER_SPAN
527 #define TARGET_DWARF_REGISTER_SPAN arm_dwarf_register_span
529 #undef TARGET_CANNOT_COPY_INSN_P
530 #define TARGET_CANNOT_COPY_INSN_P arm_cannot_copy_insn_p
533 #undef TARGET_HAVE_TLS
534 #define TARGET_HAVE_TLS true
537 #undef TARGET_HAVE_CONDITIONAL_EXECUTION
538 #define TARGET_HAVE_CONDITIONAL_EXECUTION arm_have_conditional_execution
540 #undef TARGET_LEGITIMATE_CONSTANT_P
541 #define TARGET_LEGITIMATE_CONSTANT_P arm_legitimate_constant_p
543 #undef TARGET_CANNOT_FORCE_CONST_MEM
544 #define TARGET_CANNOT_FORCE_CONST_MEM arm_cannot_force_const_mem
546 #undef TARGET_MAX_ANCHOR_OFFSET
547 #define TARGET_MAX_ANCHOR_OFFSET 4095
549 /* The minimum is set such that the total size of the block
550 for a particular anchor is -4088 + 1 + 4095 bytes, which is
551 divisible by eight, ensuring natural spacing of anchors. */
552 #undef TARGET_MIN_ANCHOR_OFFSET
553 #define TARGET_MIN_ANCHOR_OFFSET -4088
555 #undef TARGET_SCHED_ISSUE_RATE
556 #define TARGET_SCHED_ISSUE_RATE arm_issue_rate
558 #undef TARGET_MANGLE_TYPE
559 #define TARGET_MANGLE_TYPE arm_mangle_type
561 #undef TARGET_BUILD_BUILTIN_VA_LIST
562 #define TARGET_BUILD_BUILTIN_VA_LIST arm_build_builtin_va_list
563 #undef TARGET_EXPAND_BUILTIN_VA_START
564 #define TARGET_EXPAND_BUILTIN_VA_START arm_expand_builtin_va_start
565 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
566 #define TARGET_GIMPLIFY_VA_ARG_EXPR arm_gimplify_va_arg_expr
569 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
570 #define TARGET_ASM_OUTPUT_DWARF_DTPREL arm_output_dwarf_dtprel
573 #undef TARGET_LEGITIMATE_ADDRESS_P
574 #define TARGET_LEGITIMATE_ADDRESS_P arm_legitimate_address_p
576 #undef TARGET_INVALID_PARAMETER_TYPE
577 #define TARGET_INVALID_PARAMETER_TYPE arm_invalid_parameter_type
579 #undef TARGET_INVALID_RETURN_TYPE
580 #define TARGET_INVALID_RETURN_TYPE arm_invalid_return_type
582 #undef TARGET_PROMOTED_TYPE
583 #define TARGET_PROMOTED_TYPE arm_promoted_type
585 #undef TARGET_CONVERT_TO_TYPE
586 #define TARGET_CONVERT_TO_TYPE arm_convert_to_type
588 #undef TARGET_SCALAR_MODE_SUPPORTED_P
589 #define TARGET_SCALAR_MODE_SUPPORTED_P arm_scalar_mode_supported_p
591 #undef TARGET_FRAME_POINTER_REQUIRED
592 #define TARGET_FRAME_POINTER_REQUIRED arm_frame_pointer_required
594 #undef TARGET_CAN_ELIMINATE
595 #define TARGET_CAN_ELIMINATE arm_can_eliminate
597 #undef TARGET_CONDITIONAL_REGISTER_USAGE
598 #define TARGET_CONDITIONAL_REGISTER_USAGE arm_conditional_register_usage
600 #undef TARGET_CLASS_LIKELY_SPILLED_P
601 #define TARGET_CLASS_LIKELY_SPILLED_P arm_class_likely_spilled_p
603 #undef TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE
604 #define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE \
605 arm_vector_alignment_reachable
607 #undef TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT
608 #define TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT \
609 arm_builtin_support_vector_misalignment
611 #undef TARGET_PREFERRED_RENAME_CLASS
612 #define TARGET_PREFERRED_RENAME_CLASS \
613 arm_preferred_rename_class
615 struct gcc_target targetm = TARGET_INITIALIZER;
617 /* Obstack for minipool constant handling. */
618 static struct obstack minipool_obstack;
619 static char * minipool_startobj;
621 /* The maximum number of insns skipped which
622 will be conditionalised if possible. */
623 static int max_insns_skipped = 5;
625 extern FILE * asm_out_file;
627 /* True if we are currently building a constant table. */
628 int making_const_table;
630 /* The processor for which instructions should be scheduled. */
631 enum processor_type arm_tune = arm_none;
633 /* The current tuning set. */
634 const struct tune_params *current_tune;
636 /* Which floating point hardware to schedule for. */
639 /* Which floating popint hardware to use. */
640 const struct arm_fpu_desc *arm_fpu_desc;
642 /* Used for Thumb call_via trampolines. */
643 rtx thumb_call_via_label[14];
644 static int thumb_call_reg_needed;
646 /* Bit values used to identify processor capabilities. */
647 #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */
648 #define FL_ARCH3M (1 << 1) /* Extended multiply */
649 #define FL_MODE26 (1 << 2) /* 26-bit mode support */
650 #define FL_MODE32 (1 << 3) /* 32-bit mode support */
651 #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */
652 #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */
653 #define FL_THUMB (1 << 6) /* Thumb aware */
654 #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */
655 #define FL_STRONG (1 << 8) /* StrongARM */
656 #define FL_ARCH5E (1 << 9) /* DSP extensions to v5 */
657 #define FL_XSCALE (1 << 10) /* XScale */
658 #define FL_CIRRUS (1 << 11) /* Cirrus/DSP. */
659 #define FL_ARCH6 (1 << 12) /* Architecture rel 6. Adds
660 media instructions. */
661 #define FL_VFPV2 (1 << 13) /* Vector Floating Point V2. */
662 #define FL_WBUF (1 << 14) /* Schedule for write buffer ops.
663 Note: ARM6 & 7 derivatives only. */
664 #define FL_ARCH6K (1 << 15) /* Architecture rel 6 K extensions. */
665 #define FL_THUMB2 (1 << 16) /* Thumb-2. */
666 #define FL_NOTM (1 << 17) /* Instructions not present in the 'M'
668 #define FL_THUMB_DIV (1 << 18) /* Hardware divide (Thumb mode). */
669 #define FL_VFPV3 (1 << 19) /* Vector Floating Point V3. */
670 #define FL_NEON (1 << 20) /* Neon instructions. */
671 #define FL_ARCH7EM (1 << 21) /* Instructions present in the ARMv7E-M
673 #define FL_ARCH7 (1 << 22) /* Architecture 7. */
674 #define FL_ARM_DIV (1 << 23) /* Hardware divide (ARM mode). */
676 #define FL_IWMMXT (1 << 29) /* XScale v2 or "Intel Wireless MMX technology". */
678 /* Flags that only effect tuning, not available instructions. */
679 #define FL_TUNE (FL_WBUF | FL_VFPV2 | FL_STRONG | FL_LDSCHED \
682 #define FL_FOR_ARCH2 FL_NOTM
683 #define FL_FOR_ARCH3 (FL_FOR_ARCH2 | FL_MODE32)
684 #define FL_FOR_ARCH3M (FL_FOR_ARCH3 | FL_ARCH3M)
685 #define FL_FOR_ARCH4 (FL_FOR_ARCH3M | FL_ARCH4)
686 #define FL_FOR_ARCH4T (FL_FOR_ARCH4 | FL_THUMB)
687 #define FL_FOR_ARCH5 (FL_FOR_ARCH4 | FL_ARCH5)
688 #define FL_FOR_ARCH5T (FL_FOR_ARCH5 | FL_THUMB)
689 #define FL_FOR_ARCH5E (FL_FOR_ARCH5 | FL_ARCH5E)
690 #define FL_FOR_ARCH5TE (FL_FOR_ARCH5E | FL_THUMB)
691 #define FL_FOR_ARCH5TEJ FL_FOR_ARCH5TE
692 #define FL_FOR_ARCH6 (FL_FOR_ARCH5TE | FL_ARCH6)
693 #define FL_FOR_ARCH6J FL_FOR_ARCH6
694 #define FL_FOR_ARCH6K (FL_FOR_ARCH6 | FL_ARCH6K)
695 #define FL_FOR_ARCH6Z FL_FOR_ARCH6
696 #define FL_FOR_ARCH6ZK FL_FOR_ARCH6K
697 #define FL_FOR_ARCH6T2 (FL_FOR_ARCH6 | FL_THUMB2)
698 #define FL_FOR_ARCH6M (FL_FOR_ARCH6 & ~FL_NOTM)
699 #define FL_FOR_ARCH7 ((FL_FOR_ARCH6T2 & ~FL_NOTM) | FL_ARCH7)
700 #define FL_FOR_ARCH7A (FL_FOR_ARCH7 | FL_NOTM | FL_ARCH6K)
701 #define FL_FOR_ARCH7R (FL_FOR_ARCH7A | FL_THUMB_DIV)
702 #define FL_FOR_ARCH7M (FL_FOR_ARCH7 | FL_THUMB_DIV)
703 #define FL_FOR_ARCH7EM (FL_FOR_ARCH7M | FL_ARCH7EM)
705 /* The bits in this mask specify which
706 instructions we are allowed to generate. */
707 static unsigned long insn_flags = 0;
709 /* The bits in this mask specify which instruction scheduling options should
711 static unsigned long tune_flags = 0;
713 /* The following are used in the arm.md file as equivalents to bits
714 in the above two flag variables. */
716 /* Nonzero if this chip supports the ARM Architecture 3M extensions. */
719 /* Nonzero if this chip supports the ARM Architecture 4 extensions. */
722 /* Nonzero if this chip supports the ARM Architecture 4t extensions. */
725 /* Nonzero if this chip supports the ARM Architecture 5 extensions. */
728 /* Nonzero if this chip supports the ARM Architecture 5E extensions. */
731 /* Nonzero if this chip supports the ARM Architecture 6 extensions. */
734 /* Nonzero if this chip supports the ARM 6K extensions. */
737 /* Nonzero if this chip supports the ARM 7 extensions. */
740 /* Nonzero if instructions not present in the 'M' profile can be used. */
741 int arm_arch_notm = 0;
743 /* Nonzero if instructions present in ARMv7E-M can be used. */
746 /* Nonzero if this chip can benefit from load scheduling. */
747 int arm_ld_sched = 0;
749 /* Nonzero if this chip is a StrongARM. */
750 int arm_tune_strongarm = 0;
752 /* Nonzero if this chip is a Cirrus variant. */
753 int arm_arch_cirrus = 0;
755 /* Nonzero if this chip supports Intel Wireless MMX technology. */
756 int arm_arch_iwmmxt = 0;
758 /* Nonzero if this chip is an XScale. */
759 int arm_arch_xscale = 0;
761 /* Nonzero if tuning for XScale */
762 int arm_tune_xscale = 0;
764 /* Nonzero if we want to tune for stores that access the write-buffer.
765 This typically means an ARM6 or ARM7 with MMU or MPU. */
766 int arm_tune_wbuf = 0;
768 /* Nonzero if tuning for Cortex-A9. */
769 int arm_tune_cortex_a9 = 0;
771 /* Nonzero if generating Thumb instructions. */
774 /* Nonzero if generating Thumb-1 instructions. */
777 /* Nonzero if we should define __THUMB_INTERWORK__ in the
779 XXX This is a bit of a hack, it's intended to help work around
780 problems in GLD which doesn't understand that armv5t code is
781 interworking clean. */
782 int arm_cpp_interwork = 0;
784 /* Nonzero if chip supports Thumb 2. */
787 /* Nonzero if chip supports integer division instruction. */
788 int arm_arch_arm_hwdiv;
789 int arm_arch_thumb_hwdiv;
791 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference,
792 we must report the mode of the memory reference from
793 TARGET_PRINT_OPERAND to TARGET_PRINT_OPERAND_ADDRESS. */
794 enum machine_mode output_memory_reference_mode;
796 /* The register number to be used for the PIC offset register. */
797 unsigned arm_pic_register = INVALID_REGNUM;
799 /* Set to 1 after arm_reorg has started. Reset to start at the start of
800 the next function. */
801 static int after_arm_reorg = 0;
803 enum arm_pcs arm_pcs_default;
805 /* For an explanation of these variables, see final_prescan_insn below. */
807 /* arm_current_cc is also used for Thumb-2 cond_exec blocks. */
808 enum arm_cond_code arm_current_cc;
811 int arm_target_label;
812 /* The number of conditionally executed insns, including the current insn. */
813 int arm_condexec_count = 0;
814 /* A bitmask specifying the patterns for the IT block.
815 Zero means do not output an IT block before this insn. */
816 int arm_condexec_mask = 0;
817 /* The number of bits used in arm_condexec_mask. */
818 int arm_condexec_masklen = 0;
820 /* The condition codes of the ARM, and the inverse function. */
821 static const char * const arm_condition_codes[] =
823 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
824 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
827 /* The register numbers in sequence, for passing to arm_gen_load_multiple. */
828 int arm_regs_in_sequence[] =
830 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
833 #define ARM_LSL_NAME (TARGET_UNIFIED_ASM ? "lsl" : "asl")
834 #define streq(string1, string2) (strcmp (string1, string2) == 0)
836 #define THUMB2_WORK_REGS (0xff & ~( (1 << THUMB_HARD_FRAME_POINTER_REGNUM) \
837 | (1 << SP_REGNUM) | (1 << PC_REGNUM) \
838 | (1 << PIC_OFFSET_TABLE_REGNUM)))
840 /* Initialization code. */
844 const char *const name;
845 enum processor_type core;
847 const unsigned long flags;
848 const struct tune_params *const tune;
852 #define ARM_PREFETCH_NOT_BENEFICIAL 0, -1, -1
853 #define ARM_PREFETCH_BENEFICIAL(prefetch_slots,l1_size,l1_line_size) \
858 const struct tune_params arm_slowmul_tune =
860 arm_slowmul_rtx_costs,
862 3, /* Constant limit. */
863 5, /* Max cond insns. */
864 ARM_PREFETCH_NOT_BENEFICIAL,
865 true, /* Prefer constant pool. */
866 arm_default_branch_cost
869 const struct tune_params arm_fastmul_tune =
871 arm_fastmul_rtx_costs,
873 1, /* Constant limit. */
874 5, /* Max cond insns. */
875 ARM_PREFETCH_NOT_BENEFICIAL,
876 true, /* Prefer constant pool. */
877 arm_default_branch_cost
880 /* StrongARM has early execution of branches, so a sequence that is worth
881 skipping is shorter. Set max_insns_skipped to a lower value. */
883 const struct tune_params arm_strongarm_tune =
885 arm_fastmul_rtx_costs,
887 1, /* Constant limit. */
888 3, /* Max cond insns. */
889 ARM_PREFETCH_NOT_BENEFICIAL,
890 true, /* Prefer constant pool. */
891 arm_default_branch_cost
894 const struct tune_params arm_xscale_tune =
896 arm_xscale_rtx_costs,
897 xscale_sched_adjust_cost,
898 2, /* Constant limit. */
899 3, /* Max cond insns. */
900 ARM_PREFETCH_NOT_BENEFICIAL,
901 true, /* Prefer constant pool. */
902 arm_default_branch_cost
905 const struct tune_params arm_9e_tune =
909 1, /* Constant limit. */
910 5, /* Max cond insns. */
911 ARM_PREFETCH_NOT_BENEFICIAL,
912 true, /* Prefer constant pool. */
913 arm_default_branch_cost
916 const struct tune_params arm_v6t2_tune =
920 1, /* Constant limit. */
921 5, /* Max cond insns. */
922 ARM_PREFETCH_NOT_BENEFICIAL,
923 false, /* Prefer constant pool. */
924 arm_default_branch_cost
927 /* Generic Cortex tuning. Use more specific tunings if appropriate. */
928 const struct tune_params arm_cortex_tune =
932 1, /* Constant limit. */
933 5, /* Max cond insns. */
934 ARM_PREFETCH_NOT_BENEFICIAL,
935 false, /* Prefer constant pool. */
936 arm_default_branch_cost
939 /* Branches can be dual-issued on Cortex-A5, so conditional execution is
940 less appealing. Set max_insns_skipped to a low value. */
942 const struct tune_params arm_cortex_a5_tune =
946 1, /* Constant limit. */
947 1, /* Max cond insns. */
948 ARM_PREFETCH_NOT_BENEFICIAL,
949 false, /* Prefer constant pool. */
950 arm_cortex_a5_branch_cost
953 const struct tune_params arm_cortex_a9_tune =
956 cortex_a9_sched_adjust_cost,
957 1, /* Constant limit. */
958 5, /* Max cond insns. */
959 ARM_PREFETCH_BENEFICIAL(4,32,32),
960 false, /* Prefer constant pool. */
961 arm_default_branch_cost
964 const struct tune_params arm_fa726te_tune =
967 fa726te_sched_adjust_cost,
968 1, /* Constant limit. */
969 5, /* Max cond insns. */
970 ARM_PREFETCH_NOT_BENEFICIAL,
971 true, /* Prefer constant pool. */
972 arm_default_branch_cost
976 /* Not all of these give usefully different compilation alternatives,
977 but there is no simple way of generalizing them. */
978 static const struct processors all_cores[] =
981 #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \
982 {NAME, IDENT, #ARCH, FLAGS | FL_FOR_ARCH##ARCH, &arm_##COSTS##_tune},
983 #include "arm-cores.def"
985 {NULL, arm_none, NULL, 0, NULL}
988 static const struct processors all_architectures[] =
990 /* ARM Architectures */
991 /* We don't specify tuning costs here as it will be figured out
994 #define ARM_ARCH(NAME, CORE, ARCH, FLAGS) \
995 {NAME, CORE, #ARCH, FLAGS, NULL},
996 #include "arm-arches.def"
998 {NULL, arm_none, NULL, 0 , NULL}
1002 /* These are populated as commandline arguments are processed, or NULL
1003 if not specified. */
1004 static const struct processors *arm_selected_arch;
1005 static const struct processors *arm_selected_cpu;
1006 static const struct processors *arm_selected_tune;
1008 /* The name of the preprocessor macro to define for this architecture. */
1010 char arm_arch_name[] = "__ARM_ARCH_0UNK__";
1012 /* Available values for -mfpu=. */
1014 static const struct arm_fpu_desc all_fpus[] =
1016 #define ARM_FPU(NAME, MODEL, REV, VFP_REGS, NEON, FP16) \
1017 { NAME, MODEL, REV, VFP_REGS, NEON, FP16 },
1018 #include "arm-fpus.def"
1023 /* Supported TLS relocations. */
1031 TLS_DESCSEQ /* GNU scheme */
1034 /* The maximum number of insns to be used when loading a constant. */
1036 arm_constant_limit (bool size_p)
1038 return size_p ? 1 : current_tune->constant_limit;
1041 /* Emit an insn that's a simple single-set. Both the operands must be known
1044 emit_set_insn (rtx x, rtx y)
1046 return emit_insn (gen_rtx_SET (VOIDmode, x, y));
1049 /* Return the number of bits set in VALUE. */
1051 bit_count (unsigned long value)
1053 unsigned long count = 0;
1058 value &= value - 1; /* Clear the least-significant set bit. */
1066 enum machine_mode mode;
1068 } arm_fixed_mode_set;
1070 /* A small helper for setting fixed-point library libfuncs. */
1073 arm_set_fixed_optab_libfunc (optab optable, enum machine_mode mode,
1074 const char *funcname, const char *modename,
1079 if (num_suffix == 0)
1080 sprintf (buffer, "__gnu_%s%s", funcname, modename);
1082 sprintf (buffer, "__gnu_%s%s%d", funcname, modename, num_suffix);
1084 set_optab_libfunc (optable, mode, buffer);
1088 arm_set_fixed_conv_libfunc (convert_optab optable, enum machine_mode to,
1089 enum machine_mode from, const char *funcname,
1090 const char *toname, const char *fromname)
1093 const char *maybe_suffix_2 = "";
1095 /* Follow the logic for selecting a "2" suffix in fixed-bit.h. */
1096 if (ALL_FIXED_POINT_MODE_P (from) && ALL_FIXED_POINT_MODE_P (to)
1097 && UNSIGNED_FIXED_POINT_MODE_P (from) == UNSIGNED_FIXED_POINT_MODE_P (to)
1098 && ALL_FRACT_MODE_P (from) == ALL_FRACT_MODE_P (to))
1099 maybe_suffix_2 = "2";
1101 sprintf (buffer, "__gnu_%s%s%s%s", funcname, fromname, toname,
1104 set_conv_libfunc (optable, to, from, buffer);
1107 /* Set up library functions unique to ARM. */
1110 arm_init_libfuncs (void)
1112 /* For Linux, we have access to kernel support for atomic operations. */
1113 if (arm_abi == ARM_ABI_AAPCS_LINUX)
1114 init_sync_libfuncs (2 * UNITS_PER_WORD);
1116 /* There are no special library functions unless we are using the
1121 /* The functions below are described in Section 4 of the "Run-Time
1122 ABI for the ARM architecture", Version 1.0. */
1124 /* Double-precision floating-point arithmetic. Table 2. */
1125 set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd");
1126 set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv");
1127 set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul");
1128 set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg");
1129 set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub");
1131 /* Double-precision comparisons. Table 3. */
1132 set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq");
1133 set_optab_libfunc (ne_optab, DFmode, NULL);
1134 set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt");
1135 set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple");
1136 set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge");
1137 set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt");
1138 set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun");
1140 /* Single-precision floating-point arithmetic. Table 4. */
1141 set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd");
1142 set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv");
1143 set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul");
1144 set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg");
1145 set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub");
1147 /* Single-precision comparisons. Table 5. */
1148 set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq");
1149 set_optab_libfunc (ne_optab, SFmode, NULL);
1150 set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt");
1151 set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple");
1152 set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge");
1153 set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt");
1154 set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun");
1156 /* Floating-point to integer conversions. Table 6. */
1157 set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz");
1158 set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz");
1159 set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz");
1160 set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz");
1161 set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz");
1162 set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz");
1163 set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz");
1164 set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz");
1166 /* Conversions between floating types. Table 7. */
1167 set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f");
1168 set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d");
1170 /* Integer to floating-point conversions. Table 8. */
1171 set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d");
1172 set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d");
1173 set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d");
1174 set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d");
1175 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f");
1176 set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f");
1177 set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f");
1178 set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f");
1180 /* Long long. Table 9. */
1181 set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul");
1182 set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod");
1183 set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod");
1184 set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl");
1185 set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr");
1186 set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr");
1187 set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp");
1188 set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp");
1190 /* Integer (32/32->32) division. \S 4.3.1. */
1191 set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod");
1192 set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod");
1194 /* The divmod functions are designed so that they can be used for
1195 plain division, even though they return both the quotient and the
1196 remainder. The quotient is returned in the usual location (i.e.,
1197 r0 for SImode, {r0, r1} for DImode), just as would be expected
1198 for an ordinary division routine. Because the AAPCS calling
1199 conventions specify that all of { r0, r1, r2, r3 } are
1200 callee-saved registers, there is no need to tell the compiler
1201 explicitly that those registers are clobbered by these
1203 set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod");
1204 set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod");
1206 /* For SImode division the ABI provides div-without-mod routines,
1207 which are faster. */
1208 set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idiv");
1209 set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidiv");
1211 /* We don't have mod libcalls. Fortunately gcc knows how to use the
1212 divmod libcalls instead. */
1213 set_optab_libfunc (smod_optab, DImode, NULL);
1214 set_optab_libfunc (umod_optab, DImode, NULL);
1215 set_optab_libfunc (smod_optab, SImode, NULL);
1216 set_optab_libfunc (umod_optab, SImode, NULL);
1218 /* Half-precision float operations. The compiler handles all operations
1219 with NULL libfuncs by converting the SFmode. */
1220 switch (arm_fp16_format)
1222 case ARM_FP16_FORMAT_IEEE:
1223 case ARM_FP16_FORMAT_ALTERNATIVE:
1226 set_conv_libfunc (trunc_optab, HFmode, SFmode,
1227 (arm_fp16_format == ARM_FP16_FORMAT_IEEE
1229 : "__gnu_f2h_alternative"));
1230 set_conv_libfunc (sext_optab, SFmode, HFmode,
1231 (arm_fp16_format == ARM_FP16_FORMAT_IEEE
1233 : "__gnu_h2f_alternative"));
1236 set_optab_libfunc (add_optab, HFmode, NULL);
1237 set_optab_libfunc (sdiv_optab, HFmode, NULL);
1238 set_optab_libfunc (smul_optab, HFmode, NULL);
1239 set_optab_libfunc (neg_optab, HFmode, NULL);
1240 set_optab_libfunc (sub_optab, HFmode, NULL);
1243 set_optab_libfunc (eq_optab, HFmode, NULL);
1244 set_optab_libfunc (ne_optab, HFmode, NULL);
1245 set_optab_libfunc (lt_optab, HFmode, NULL);
1246 set_optab_libfunc (le_optab, HFmode, NULL);
1247 set_optab_libfunc (ge_optab, HFmode, NULL);
1248 set_optab_libfunc (gt_optab, HFmode, NULL);
1249 set_optab_libfunc (unord_optab, HFmode, NULL);
1256 /* Use names prefixed with __gnu_ for fixed-point helper functions. */
1258 const arm_fixed_mode_set fixed_arith_modes[] =
1279 const arm_fixed_mode_set fixed_conv_modes[] =
1309 for (i = 0; i < ARRAY_SIZE (fixed_arith_modes); i++)
1311 arm_set_fixed_optab_libfunc (add_optab, fixed_arith_modes[i].mode,
1312 "add", fixed_arith_modes[i].name, 3);
1313 arm_set_fixed_optab_libfunc (ssadd_optab, fixed_arith_modes[i].mode,
1314 "ssadd", fixed_arith_modes[i].name, 3);
1315 arm_set_fixed_optab_libfunc (usadd_optab, fixed_arith_modes[i].mode,
1316 "usadd", fixed_arith_modes[i].name, 3);
1317 arm_set_fixed_optab_libfunc (sub_optab, fixed_arith_modes[i].mode,
1318 "sub", fixed_arith_modes[i].name, 3);
1319 arm_set_fixed_optab_libfunc (sssub_optab, fixed_arith_modes[i].mode,
1320 "sssub", fixed_arith_modes[i].name, 3);
1321 arm_set_fixed_optab_libfunc (ussub_optab, fixed_arith_modes[i].mode,
1322 "ussub", fixed_arith_modes[i].name, 3);
1323 arm_set_fixed_optab_libfunc (smul_optab, fixed_arith_modes[i].mode,
1324 "mul", fixed_arith_modes[i].name, 3);
1325 arm_set_fixed_optab_libfunc (ssmul_optab, fixed_arith_modes[i].mode,
1326 "ssmul", fixed_arith_modes[i].name, 3);
1327 arm_set_fixed_optab_libfunc (usmul_optab, fixed_arith_modes[i].mode,
1328 "usmul", fixed_arith_modes[i].name, 3);
1329 arm_set_fixed_optab_libfunc (sdiv_optab, fixed_arith_modes[i].mode,
1330 "div", fixed_arith_modes[i].name, 3);
1331 arm_set_fixed_optab_libfunc (udiv_optab, fixed_arith_modes[i].mode,
1332 "udiv", fixed_arith_modes[i].name, 3);
1333 arm_set_fixed_optab_libfunc (ssdiv_optab, fixed_arith_modes[i].mode,
1334 "ssdiv", fixed_arith_modes[i].name, 3);
1335 arm_set_fixed_optab_libfunc (usdiv_optab, fixed_arith_modes[i].mode,
1336 "usdiv", fixed_arith_modes[i].name, 3);
1337 arm_set_fixed_optab_libfunc (neg_optab, fixed_arith_modes[i].mode,
1338 "neg", fixed_arith_modes[i].name, 2);
1339 arm_set_fixed_optab_libfunc (ssneg_optab, fixed_arith_modes[i].mode,
1340 "ssneg", fixed_arith_modes[i].name, 2);
1341 arm_set_fixed_optab_libfunc (usneg_optab, fixed_arith_modes[i].mode,
1342 "usneg", fixed_arith_modes[i].name, 2);
1343 arm_set_fixed_optab_libfunc (ashl_optab, fixed_arith_modes[i].mode,
1344 "ashl", fixed_arith_modes[i].name, 3);
1345 arm_set_fixed_optab_libfunc (ashr_optab, fixed_arith_modes[i].mode,
1346 "ashr", fixed_arith_modes[i].name, 3);
1347 arm_set_fixed_optab_libfunc (lshr_optab, fixed_arith_modes[i].mode,
1348 "lshr", fixed_arith_modes[i].name, 3);
1349 arm_set_fixed_optab_libfunc (ssashl_optab, fixed_arith_modes[i].mode,
1350 "ssashl", fixed_arith_modes[i].name, 3);
1351 arm_set_fixed_optab_libfunc (usashl_optab, fixed_arith_modes[i].mode,
1352 "usashl", fixed_arith_modes[i].name, 3);
1353 arm_set_fixed_optab_libfunc (cmp_optab, fixed_arith_modes[i].mode,
1354 "cmp", fixed_arith_modes[i].name, 2);
1357 for (i = 0; i < ARRAY_SIZE (fixed_conv_modes); i++)
1358 for (j = 0; j < ARRAY_SIZE (fixed_conv_modes); j++)
1361 || (!ALL_FIXED_POINT_MODE_P (fixed_conv_modes[i].mode)
1362 && !ALL_FIXED_POINT_MODE_P (fixed_conv_modes[j].mode)))
1365 arm_set_fixed_conv_libfunc (fract_optab, fixed_conv_modes[i].mode,
1366 fixed_conv_modes[j].mode, "fract",
1367 fixed_conv_modes[i].name,
1368 fixed_conv_modes[j].name);
1369 arm_set_fixed_conv_libfunc (satfract_optab,
1370 fixed_conv_modes[i].mode,
1371 fixed_conv_modes[j].mode, "satfract",
1372 fixed_conv_modes[i].name,
1373 fixed_conv_modes[j].name);
1374 arm_set_fixed_conv_libfunc (fractuns_optab,
1375 fixed_conv_modes[i].mode,
1376 fixed_conv_modes[j].mode, "fractuns",
1377 fixed_conv_modes[i].name,
1378 fixed_conv_modes[j].name);
1379 arm_set_fixed_conv_libfunc (satfractuns_optab,
1380 fixed_conv_modes[i].mode,
1381 fixed_conv_modes[j].mode, "satfractuns",
1382 fixed_conv_modes[i].name,
1383 fixed_conv_modes[j].name);
1387 if (TARGET_AAPCS_BASED)
1388 synchronize_libfunc = init_one_libfunc ("__sync_synchronize");
1391 /* On AAPCS systems, this is the "struct __va_list". */
1392 static GTY(()) tree va_list_type;
1394 /* Return the type to use as __builtin_va_list. */
1396 arm_build_builtin_va_list (void)
1401 if (!TARGET_AAPCS_BASED)
1402 return std_build_builtin_va_list ();
1404 /* AAPCS \S 7.1.4 requires that va_list be a typedef for a type
1412 The C Library ABI further reinforces this definition in \S
1415 We must follow this definition exactly. The structure tag
1416 name is visible in C++ mangled names, and thus forms a part
1417 of the ABI. The field name may be used by people who
1418 #include <stdarg.h>. */
1419 /* Create the type. */
1420 va_list_type = lang_hooks.types.make_type (RECORD_TYPE);
1421 /* Give it the required name. */
1422 va_list_name = build_decl (BUILTINS_LOCATION,
1424 get_identifier ("__va_list"),
1426 DECL_ARTIFICIAL (va_list_name) = 1;
1427 TYPE_NAME (va_list_type) = va_list_name;
1428 TYPE_STUB_DECL (va_list_type) = va_list_name;
1429 /* Create the __ap field. */
1430 ap_field = build_decl (BUILTINS_LOCATION,
1432 get_identifier ("__ap"),
1434 DECL_ARTIFICIAL (ap_field) = 1;
1435 DECL_FIELD_CONTEXT (ap_field) = va_list_type;
1436 TYPE_FIELDS (va_list_type) = ap_field;
1437 /* Compute its layout. */
1438 layout_type (va_list_type);
1440 return va_list_type;
1443 /* Return an expression of type "void *" pointing to the next
1444 available argument in a variable-argument list. VALIST is the
1445 user-level va_list object, of type __builtin_va_list. */
1447 arm_extract_valist_ptr (tree valist)
1449 if (TREE_TYPE (valist) == error_mark_node)
1450 return error_mark_node;
1452 /* On an AAPCS target, the pointer is stored within "struct
1454 if (TARGET_AAPCS_BASED)
1456 tree ap_field = TYPE_FIELDS (TREE_TYPE (valist));
1457 valist = build3 (COMPONENT_REF, TREE_TYPE (ap_field),
1458 valist, ap_field, NULL_TREE);
1464 /* Implement TARGET_EXPAND_BUILTIN_VA_START. */
1466 arm_expand_builtin_va_start (tree valist, rtx nextarg)
1468 valist = arm_extract_valist_ptr (valist);
1469 std_expand_builtin_va_start (valist, nextarg);
1472 /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */
1474 arm_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
1477 valist = arm_extract_valist_ptr (valist);
1478 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
1481 /* Fix up any incompatible options that the user has specified. */
1483 arm_option_override (void)
1485 if (global_options_set.x_arm_arch_option)
1486 arm_selected_arch = &all_architectures[arm_arch_option];
1488 if (global_options_set.x_arm_cpu_option)
1489 arm_selected_cpu = &all_cores[(int) arm_cpu_option];
1491 if (global_options_set.x_arm_tune_option)
1492 arm_selected_tune = &all_cores[(int) arm_tune_option];
1494 #ifdef SUBTARGET_OVERRIDE_OPTIONS
1495 SUBTARGET_OVERRIDE_OPTIONS;
1498 if (arm_selected_arch)
1500 if (arm_selected_cpu)
1502 /* Check for conflict between mcpu and march. */
1503 if ((arm_selected_cpu->flags ^ arm_selected_arch->flags) & ~FL_TUNE)
1505 warning (0, "switch -mcpu=%s conflicts with -march=%s switch",
1506 arm_selected_cpu->name, arm_selected_arch->name);
1507 /* -march wins for code generation.
1508 -mcpu wins for default tuning. */
1509 if (!arm_selected_tune)
1510 arm_selected_tune = arm_selected_cpu;
1512 arm_selected_cpu = arm_selected_arch;
1516 arm_selected_arch = NULL;
1519 /* Pick a CPU based on the architecture. */
1520 arm_selected_cpu = arm_selected_arch;
1523 /* If the user did not specify a processor, choose one for them. */
1524 if (!arm_selected_cpu)
1526 const struct processors * sel;
1527 unsigned int sought;
1529 arm_selected_cpu = &all_cores[TARGET_CPU_DEFAULT];
1530 if (!arm_selected_cpu->name)
1532 #ifdef SUBTARGET_CPU_DEFAULT
1533 /* Use the subtarget default CPU if none was specified by
1535 arm_selected_cpu = &all_cores[SUBTARGET_CPU_DEFAULT];
1537 /* Default to ARM6. */
1538 if (!arm_selected_cpu->name)
1539 arm_selected_cpu = &all_cores[arm6];
1542 sel = arm_selected_cpu;
1543 insn_flags = sel->flags;
1545 /* Now check to see if the user has specified some command line
1546 switch that require certain abilities from the cpu. */
1549 if (TARGET_INTERWORK || TARGET_THUMB)
1551 sought |= (FL_THUMB | FL_MODE32);
1553 /* There are no ARM processors that support both APCS-26 and
1554 interworking. Therefore we force FL_MODE26 to be removed
1555 from insn_flags here (if it was set), so that the search
1556 below will always be able to find a compatible processor. */
1557 insn_flags &= ~FL_MODE26;
1560 if (sought != 0 && ((sought & insn_flags) != sought))
1562 /* Try to locate a CPU type that supports all of the abilities
1563 of the default CPU, plus the extra abilities requested by
1565 for (sel = all_cores; sel->name != NULL; sel++)
1566 if ((sel->flags & sought) == (sought | insn_flags))
1569 if (sel->name == NULL)
1571 unsigned current_bit_count = 0;
1572 const struct processors * best_fit = NULL;
1574 /* Ideally we would like to issue an error message here
1575 saying that it was not possible to find a CPU compatible
1576 with the default CPU, but which also supports the command
1577 line options specified by the programmer, and so they
1578 ought to use the -mcpu=<name> command line option to
1579 override the default CPU type.
1581 If we cannot find a cpu that has both the
1582 characteristics of the default cpu and the given
1583 command line options we scan the array again looking
1584 for a best match. */
1585 for (sel = all_cores; sel->name != NULL; sel++)
1586 if ((sel->flags & sought) == sought)
1590 count = bit_count (sel->flags & insn_flags);
1592 if (count >= current_bit_count)
1595 current_bit_count = count;
1599 gcc_assert (best_fit);
1603 arm_selected_cpu = sel;
1607 gcc_assert (arm_selected_cpu);
1608 /* The selected cpu may be an architecture, so lookup tuning by core ID. */
1609 if (!arm_selected_tune)
1610 arm_selected_tune = &all_cores[arm_selected_cpu->core];
1612 sprintf (arm_arch_name, "__ARM_ARCH_%s__", arm_selected_cpu->arch);
1613 insn_flags = arm_selected_cpu->flags;
1615 arm_tune = arm_selected_tune->core;
1616 tune_flags = arm_selected_tune->flags;
1617 current_tune = arm_selected_tune->tune;
1619 /* Make sure that the processor choice does not conflict with any of the
1620 other command line choices. */
1621 if (TARGET_ARM && !(insn_flags & FL_NOTM))
1622 error ("target CPU does not support ARM mode");
1624 /* BPABI targets use linker tricks to allow interworking on cores
1625 without thumb support. */
1626 if (TARGET_INTERWORK && !((insn_flags & FL_THUMB) || TARGET_BPABI))
1628 warning (0, "target CPU does not support interworking" );
1629 target_flags &= ~MASK_INTERWORK;
1632 if (TARGET_THUMB && !(insn_flags & FL_THUMB))
1634 warning (0, "target CPU does not support THUMB instructions");
1635 target_flags &= ~MASK_THUMB;
1638 if (TARGET_APCS_FRAME && TARGET_THUMB)
1640 /* warning (0, "ignoring -mapcs-frame because -mthumb was used"); */
1641 target_flags &= ~MASK_APCS_FRAME;
1644 /* Callee super interworking implies thumb interworking. Adding
1645 this to the flags here simplifies the logic elsewhere. */
1646 if (TARGET_THUMB && TARGET_CALLEE_INTERWORKING)
1647 target_flags |= MASK_INTERWORK;
1649 /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done
1650 from here where no function is being compiled currently. */
1651 if ((TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) && TARGET_ARM)
1652 warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb");
1654 if (TARGET_ARM && TARGET_CALLEE_INTERWORKING)
1655 warning (0, "enabling callee interworking support is only meaningful when compiling for the Thumb");
1657 if (TARGET_APCS_STACK && !TARGET_APCS_FRAME)
1659 warning (0, "-mapcs-stack-check incompatible with -mno-apcs-frame");
1660 target_flags |= MASK_APCS_FRAME;
1663 if (TARGET_POKE_FUNCTION_NAME)
1664 target_flags |= MASK_APCS_FRAME;
1666 if (TARGET_APCS_REENT && flag_pic)
1667 error ("-fpic and -mapcs-reent are incompatible");
1669 if (TARGET_APCS_REENT)
1670 warning (0, "APCS reentrant code not supported. Ignored");
1672 /* If this target is normally configured to use APCS frames, warn if they
1673 are turned off and debugging is turned on. */
1675 && write_symbols != NO_DEBUG
1676 && !TARGET_APCS_FRAME
1677 && (TARGET_DEFAULT & MASK_APCS_FRAME))
1678 warning (0, "-g with -mno-apcs-frame may not give sensible debugging");
1680 if (TARGET_APCS_FLOAT)
1681 warning (0, "passing floating point arguments in fp regs not yet supported");
1683 if (TARGET_LITTLE_WORDS)
1684 warning (OPT_Wdeprecated, "%<mwords-little-endian%> is deprecated and "
1685 "will be removed in a future release");
1687 /* Initialize boolean versions of the flags, for use in the arm.md file. */
1688 arm_arch3m = (insn_flags & FL_ARCH3M) != 0;
1689 arm_arch4 = (insn_flags & FL_ARCH4) != 0;
1690 arm_arch4t = arm_arch4 & ((insn_flags & FL_THUMB) != 0);
1691 arm_arch5 = (insn_flags & FL_ARCH5) != 0;
1692 arm_arch5e = (insn_flags & FL_ARCH5E) != 0;
1693 arm_arch6 = (insn_flags & FL_ARCH6) != 0;
1694 arm_arch6k = (insn_flags & FL_ARCH6K) != 0;
1695 arm_arch_notm = (insn_flags & FL_NOTM) != 0;
1696 arm_arch7 = (insn_flags & FL_ARCH7) != 0;
1697 arm_arch7em = (insn_flags & FL_ARCH7EM) != 0;
1698 arm_arch_thumb2 = (insn_flags & FL_THUMB2) != 0;
1699 arm_arch_xscale = (insn_flags & FL_XSCALE) != 0;
1700 arm_arch_cirrus = (insn_flags & FL_CIRRUS) != 0;
1702 arm_ld_sched = (tune_flags & FL_LDSCHED) != 0;
1703 arm_tune_strongarm = (tune_flags & FL_STRONG) != 0;
1704 thumb_code = TARGET_ARM == 0;
1705 thumb1_code = TARGET_THUMB1 != 0;
1706 arm_tune_wbuf = (tune_flags & FL_WBUF) != 0;
1707 arm_tune_xscale = (tune_flags & FL_XSCALE) != 0;
1708 arm_arch_iwmmxt = (insn_flags & FL_IWMMXT) != 0;
1709 arm_arch_thumb_hwdiv = (insn_flags & FL_THUMB_DIV) != 0;
1710 arm_arch_arm_hwdiv = (insn_flags & FL_ARM_DIV) != 0;
1711 arm_tune_cortex_a9 = (arm_tune == cortexa9) != 0;
1713 /* If we are not using the default (ARM mode) section anchor offset
1714 ranges, then set the correct ranges now. */
1717 /* Thumb-1 LDR instructions cannot have negative offsets.
1718 Permissible positive offset ranges are 5-bit (for byte loads),
1719 6-bit (for halfword loads), or 7-bit (for word loads).
1720 Empirical results suggest a 7-bit anchor range gives the best
1721 overall code size. */
1722 targetm.min_anchor_offset = 0;
1723 targetm.max_anchor_offset = 127;
1725 else if (TARGET_THUMB2)
1727 /* The minimum is set such that the total size of the block
1728 for a particular anchor is 248 + 1 + 4095 bytes, which is
1729 divisible by eight, ensuring natural spacing of anchors. */
1730 targetm.min_anchor_offset = -248;
1731 targetm.max_anchor_offset = 4095;
1734 /* V5 code we generate is completely interworking capable, so we turn off
1735 TARGET_INTERWORK here to avoid many tests later on. */
1737 /* XXX However, we must pass the right pre-processor defines to CPP
1738 or GLD can get confused. This is a hack. */
1739 if (TARGET_INTERWORK)
1740 arm_cpp_interwork = 1;
1743 target_flags &= ~MASK_INTERWORK;
1745 if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN)
1746 error ("iwmmxt requires an AAPCS compatible ABI for proper operation");
1748 if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT)
1749 error ("iwmmxt abi requires an iwmmxt capable cpu");
1751 if (!global_options_set.x_arm_fpu_index)
1753 const char *target_fpu_name;
1756 #ifdef FPUTYPE_DEFAULT
1757 target_fpu_name = FPUTYPE_DEFAULT;
1759 if (arm_arch_cirrus)
1760 target_fpu_name = "maverick";
1762 target_fpu_name = "fpe2";
1765 ok = opt_enum_arg_to_value (OPT_mfpu_, target_fpu_name, &arm_fpu_index,
1770 arm_fpu_desc = &all_fpus[arm_fpu_index];
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_AAPCS_BASED
1796 && (arm_fpu_desc->model == ARM_FP_MODEL_FPA))
1797 error ("FPA is unsupported in the AAPCS");
1799 if (TARGET_AAPCS_BASED)
1801 if (TARGET_CALLER_INTERWORKING)
1802 error ("AAPCS does not support -mcaller-super-interworking");
1804 if (TARGET_CALLEE_INTERWORKING)
1805 error ("AAPCS does not support -mcallee-super-interworking");
1808 /* FPA and iWMMXt are incompatible because the insn encodings overlap.
1809 VFP and iWMMXt can theoretically coexist, but it's unlikely such silicon
1810 will ever exist. GCC makes no attempt to support this combination. */
1811 if (TARGET_IWMMXT && !TARGET_SOFT_FLOAT)
1812 sorry ("iWMMXt and hardware floating point");
1814 /* ??? iWMMXt insn patterns need auditing for Thumb-2. */
1815 if (TARGET_THUMB2 && TARGET_IWMMXT)
1816 sorry ("Thumb-2 iWMMXt");
1818 /* __fp16 support currently assumes the core has ldrh. */
1819 if (!arm_arch4 && arm_fp16_format != ARM_FP16_FORMAT_NONE)
1820 sorry ("__fp16 and no ldrh");
1822 /* If soft-float is specified then don't use FPU. */
1823 if (TARGET_SOFT_FLOAT)
1824 arm_fpu_attr = FPU_NONE;
1826 if (TARGET_AAPCS_BASED)
1828 if (arm_abi == ARM_ABI_IWMMXT)
1829 arm_pcs_default = ARM_PCS_AAPCS_IWMMXT;
1830 else if (arm_float_abi == ARM_FLOAT_ABI_HARD
1831 && TARGET_HARD_FLOAT
1833 arm_pcs_default = ARM_PCS_AAPCS_VFP;
1835 arm_pcs_default = ARM_PCS_AAPCS;
1839 if (arm_float_abi == ARM_FLOAT_ABI_HARD && TARGET_VFP)
1840 sorry ("-mfloat-abi=hard and VFP");
1842 if (arm_abi == ARM_ABI_APCS)
1843 arm_pcs_default = ARM_PCS_APCS;
1845 arm_pcs_default = ARM_PCS_ATPCS;
1848 /* For arm2/3 there is no need to do any scheduling if there is only
1849 a floating point emulator, or we are doing software floating-point. */
1850 if ((TARGET_SOFT_FLOAT
1851 || (TARGET_FPA && arm_fpu_desc->rev))
1852 && (tune_flags & FL_MODE32) == 0)
1853 flag_schedule_insns = flag_schedule_insns_after_reload = 0;
1855 /* Use the cp15 method if it is available. */
1856 if (target_thread_pointer == TP_AUTO)
1858 if (arm_arch6k && !TARGET_THUMB1)
1859 target_thread_pointer = TP_CP15;
1861 target_thread_pointer = TP_SOFT;
1864 if (TARGET_HARD_TP && TARGET_THUMB1)
1865 error ("can not use -mtp=cp15 with 16-bit Thumb");
1867 /* Override the default structure alignment for AAPCS ABI. */
1868 if (!global_options_set.x_arm_structure_size_boundary)
1870 if (TARGET_AAPCS_BASED)
1871 arm_structure_size_boundary = 8;
1875 if (arm_structure_size_boundary != 8
1876 && arm_structure_size_boundary != 32
1877 && !(ARM_DOUBLEWORD_ALIGN && arm_structure_size_boundary == 64))
1879 if (ARM_DOUBLEWORD_ALIGN)
1881 "structure size boundary can only be set to 8, 32 or 64");
1883 warning (0, "structure size boundary can only be set to 8 or 32");
1884 arm_structure_size_boundary
1885 = (TARGET_AAPCS_BASED ? 8 : DEFAULT_STRUCTURE_SIZE_BOUNDARY);
1889 if (!TARGET_ARM && TARGET_VXWORKS_RTP && flag_pic)
1891 error ("RTP PIC is incompatible with Thumb");
1895 /* If stack checking is disabled, we can use r10 as the PIC register,
1896 which keeps r9 available. The EABI specifies r9 as the PIC register. */
1897 if (flag_pic && TARGET_SINGLE_PIC_BASE)
1899 if (TARGET_VXWORKS_RTP)
1900 warning (0, "RTP PIC is incompatible with -msingle-pic-base");
1901 arm_pic_register = (TARGET_APCS_STACK || TARGET_AAPCS_BASED) ? 9 : 10;
1904 if (flag_pic && TARGET_VXWORKS_RTP)
1905 arm_pic_register = 9;
1907 if (arm_pic_register_string != NULL)
1909 int pic_register = decode_reg_name (arm_pic_register_string);
1912 warning (0, "-mpic-register= is useless without -fpic");
1914 /* Prevent the user from choosing an obviously stupid PIC register. */
1915 else if (pic_register < 0 || call_used_regs[pic_register]
1916 || pic_register == HARD_FRAME_POINTER_REGNUM
1917 || pic_register == STACK_POINTER_REGNUM
1918 || pic_register >= PC_REGNUM
1919 || (TARGET_VXWORKS_RTP
1920 && (unsigned int) pic_register != arm_pic_register))
1921 error ("unable to use '%s' for PIC register", arm_pic_register_string);
1923 arm_pic_register = pic_register;
1926 /* Enable -mfix-cortex-m3-ldrd by default for Cortex-M3 cores. */
1927 if (fix_cm3_ldrd == 2)
1929 if (arm_selected_cpu->core == cortexm3)
1935 /* Enable -munaligned-access by default for
1936 - all ARMv6 architecture-based processors
1937 - ARMv7-A, ARMv7-R, and ARMv7-M architecture-based processors.
1939 Disable -munaligned-access by default for
1940 - all pre-ARMv6 architecture-based processors
1941 - ARMv6-M architecture-based processors. */
1943 if (unaligned_access == 2)
1945 if (arm_arch6 && (arm_arch_notm || arm_arch7))
1946 unaligned_access = 1;
1948 unaligned_access = 0;
1950 else if (unaligned_access == 1
1951 && !(arm_arch6 && (arm_arch_notm || arm_arch7)))
1953 warning (0, "target CPU does not support unaligned accesses");
1954 unaligned_access = 0;
1957 if (TARGET_THUMB1 && flag_schedule_insns)
1959 /* Don't warn since it's on by default in -O2. */
1960 flag_schedule_insns = 0;
1965 /* If optimizing for size, bump the number of instructions that we
1966 are prepared to conditionally execute (even on a StrongARM). */
1967 max_insns_skipped = 6;
1970 max_insns_skipped = current_tune->max_insns_skipped;
1972 /* Hot/Cold partitioning is not currently supported, since we can't
1973 handle literal pool placement in that case. */
1974 if (flag_reorder_blocks_and_partition)
1976 inform (input_location,
1977 "-freorder-blocks-and-partition not supported on this architecture");
1978 flag_reorder_blocks_and_partition = 0;
1979 flag_reorder_blocks = 1;
1983 /* Hoisting PIC address calculations more aggressively provides a small,
1984 but measurable, size reduction for PIC code. Therefore, we decrease
1985 the bar for unrestricted expression hoisting to the cost of PIC address
1986 calculation, which is 2 instructions. */
1987 maybe_set_param_value (PARAM_GCSE_UNRESTRICTED_COST, 2,
1988 global_options.x_param_values,
1989 global_options_set.x_param_values);
1991 /* ARM EABI defaults to strict volatile bitfields. */
1992 if (TARGET_AAPCS_BASED && flag_strict_volatile_bitfields < 0
1993 && abi_version_at_least(2))
1994 flag_strict_volatile_bitfields = 1;
1996 /* Enable sw prefetching at -O3 for CPUS that have prefetch, and we have deemed
1997 it beneficial (signified by setting num_prefetch_slots to 1 or more.) */
1998 if (flag_prefetch_loop_arrays < 0
2001 && current_tune->num_prefetch_slots > 0)
2002 flag_prefetch_loop_arrays = 1;
2004 /* Set up parameters to be used in prefetching algorithm. Do not override the
2005 defaults unless we are tuning for a core we have researched values for. */
2006 if (current_tune->num_prefetch_slots > 0)
2007 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
2008 current_tune->num_prefetch_slots,
2009 global_options.x_param_values,
2010 global_options_set.x_param_values);
2011 if (current_tune->l1_cache_line_size >= 0)
2012 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE,
2013 current_tune->l1_cache_line_size,
2014 global_options.x_param_values,
2015 global_options_set.x_param_values);
2016 if (current_tune->l1_cache_size >= 0)
2017 maybe_set_param_value (PARAM_L1_CACHE_SIZE,
2018 current_tune->l1_cache_size,
2019 global_options.x_param_values,
2020 global_options_set.x_param_values);
2022 /* Register global variables with the garbage collector. */
2023 arm_add_gc_roots ();
2027 arm_add_gc_roots (void)
2029 gcc_obstack_init(&minipool_obstack);
2030 minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0);
2033 /* A table of known ARM exception types.
2034 For use with the interrupt function attribute. */
2038 const char *const arg;
2039 const unsigned long return_value;
2043 static const isr_attribute_arg isr_attribute_args [] =
2045 { "IRQ", ARM_FT_ISR },
2046 { "irq", ARM_FT_ISR },
2047 { "FIQ", ARM_FT_FIQ },
2048 { "fiq", ARM_FT_FIQ },
2049 { "ABORT", ARM_FT_ISR },
2050 { "abort", ARM_FT_ISR },
2051 { "ABORT", ARM_FT_ISR },
2052 { "abort", ARM_FT_ISR },
2053 { "UNDEF", ARM_FT_EXCEPTION },
2054 { "undef", ARM_FT_EXCEPTION },
2055 { "SWI", ARM_FT_EXCEPTION },
2056 { "swi", ARM_FT_EXCEPTION },
2057 { NULL, ARM_FT_NORMAL }
2060 /* Returns the (interrupt) function type of the current
2061 function, or ARM_FT_UNKNOWN if the type cannot be determined. */
2063 static unsigned long
2064 arm_isr_value (tree argument)
2066 const isr_attribute_arg * ptr;
2070 return ARM_FT_NORMAL | ARM_FT_STACKALIGN;
2072 /* No argument - default to IRQ. */
2073 if (argument == NULL_TREE)
2076 /* Get the value of the argument. */
2077 if (TREE_VALUE (argument) == NULL_TREE
2078 || TREE_CODE (TREE_VALUE (argument)) != STRING_CST)
2079 return ARM_FT_UNKNOWN;
2081 arg = TREE_STRING_POINTER (TREE_VALUE (argument));
2083 /* Check it against the list of known arguments. */
2084 for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)
2085 if (streq (arg, ptr->arg))
2086 return ptr->return_value;
2088 /* An unrecognized interrupt type. */
2089 return ARM_FT_UNKNOWN;
2092 /* Computes the type of the current function. */
2094 static unsigned long
2095 arm_compute_func_type (void)
2097 unsigned long type = ARM_FT_UNKNOWN;
2101 gcc_assert (TREE_CODE (current_function_decl) == FUNCTION_DECL);
2103 /* Decide if the current function is volatile. Such functions
2104 never return, and many memory cycles can be saved by not storing
2105 register values that will never be needed again. This optimization
2106 was added to speed up context switching in a kernel application. */
2108 && (TREE_NOTHROW (current_function_decl)
2109 || !(flag_unwind_tables
2111 && arm_except_unwind_info (&global_options) != UI_SJLJ)))
2112 && TREE_THIS_VOLATILE (current_function_decl))
2113 type |= ARM_FT_VOLATILE;
2115 if (cfun->static_chain_decl != NULL)
2116 type |= ARM_FT_NESTED;
2118 attr = DECL_ATTRIBUTES (current_function_decl);
2120 a = lookup_attribute ("naked", attr);
2122 type |= ARM_FT_NAKED;
2124 a = lookup_attribute ("isr", attr);
2126 a = lookup_attribute ("interrupt", attr);
2129 type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL;
2131 type |= arm_isr_value (TREE_VALUE (a));
2136 /* Returns the type of the current function. */
2139 arm_current_func_type (void)
2141 if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN)
2142 cfun->machine->func_type = arm_compute_func_type ();
2144 return cfun->machine->func_type;
2148 arm_allocate_stack_slots_for_args (void)
2150 /* Naked functions should not allocate stack slots for arguments. */
2151 return !IS_NAKED (arm_current_func_type ());
2155 /* Output assembler code for a block containing the constant parts
2156 of a trampoline, leaving space for the variable parts.
2158 On the ARM, (if r8 is the static chain regnum, and remembering that
2159 referencing pc adds an offset of 8) the trampoline looks like:
2162 .word static chain value
2163 .word function's address
2164 XXX FIXME: When the trampoline returns, r8 will be clobbered. */
2167 arm_asm_trampoline_template (FILE *f)
2171 asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", STATIC_CHAIN_REGNUM, PC_REGNUM);
2172 asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", PC_REGNUM, PC_REGNUM);
2174 else if (TARGET_THUMB2)
2176 /* The Thumb-2 trampoline is similar to the arm implementation.
2177 Unlike 16-bit Thumb, we enter the stub in thumb mode. */
2178 asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n",
2179 STATIC_CHAIN_REGNUM, PC_REGNUM);
2180 asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n", PC_REGNUM, PC_REGNUM);
2184 ASM_OUTPUT_ALIGN (f, 2);
2185 fprintf (f, "\t.code\t16\n");
2186 fprintf (f, ".Ltrampoline_start:\n");
2187 asm_fprintf (f, "\tpush\t{r0, r1}\n");
2188 asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM);
2189 asm_fprintf (f, "\tmov\t%r, r0\n", STATIC_CHAIN_REGNUM);
2190 asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM);
2191 asm_fprintf (f, "\tstr\tr0, [%r, #4]\n", SP_REGNUM);
2192 asm_fprintf (f, "\tpop\t{r0, %r}\n", PC_REGNUM);
2194 assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
2195 assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
2198 /* Emit RTL insns to initialize the variable parts of a trampoline. */
2201 arm_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
2203 rtx fnaddr, mem, a_tramp;
2205 emit_block_move (m_tramp, assemble_trampoline_template (),
2206 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
2208 mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 8 : 12);
2209 emit_move_insn (mem, chain_value);
2211 mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 12 : 16);
2212 fnaddr = XEXP (DECL_RTL (fndecl), 0);
2213 emit_move_insn (mem, fnaddr);
2215 a_tramp = XEXP (m_tramp, 0);
2216 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"),
2217 LCT_NORMAL, VOIDmode, 2, a_tramp, Pmode,
2218 plus_constant (a_tramp, TRAMPOLINE_SIZE), Pmode);
2221 /* Thumb trampolines should be entered in thumb mode, so set
2222 the bottom bit of the address. */
2225 arm_trampoline_adjust_address (rtx addr)
2228 addr = expand_simple_binop (Pmode, IOR, addr, const1_rtx,
2229 NULL, 0, OPTAB_LIB_WIDEN);
2233 /* Return 1 if it is possible to return using a single instruction.
2234 If SIBLING is non-null, this is a test for a return before a sibling
2235 call. SIBLING is the call insn, so we can examine its register usage. */
2238 use_return_insn (int iscond, rtx sibling)
2241 unsigned int func_type;
2242 unsigned long saved_int_regs;
2243 unsigned HOST_WIDE_INT stack_adjust;
2244 arm_stack_offsets *offsets;
2246 /* Never use a return instruction before reload has run. */
2247 if (!reload_completed)
2250 func_type = arm_current_func_type ();
2252 /* Naked, volatile and stack alignment functions need special
2254 if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED | ARM_FT_STACKALIGN))
2257 /* So do interrupt functions that use the frame pointer and Thumb
2258 interrupt functions. */
2259 if (IS_INTERRUPT (func_type) && (frame_pointer_needed || TARGET_THUMB))
2262 offsets = arm_get_frame_offsets ();
2263 stack_adjust = offsets->outgoing_args - offsets->saved_regs;
2265 /* As do variadic functions. */
2266 if (crtl->args.pretend_args_size
2267 || cfun->machine->uses_anonymous_args
2268 /* Or if the function calls __builtin_eh_return () */
2269 || crtl->calls_eh_return
2270 /* Or if the function calls alloca */
2271 || cfun->calls_alloca
2272 /* Or if there is a stack adjustment. However, if the stack pointer
2273 is saved on the stack, we can use a pre-incrementing stack load. */
2274 || !(stack_adjust == 0 || (TARGET_APCS_FRAME && frame_pointer_needed
2275 && stack_adjust == 4)))
2278 saved_int_regs = offsets->saved_regs_mask;
2280 /* Unfortunately, the insn
2282 ldmib sp, {..., sp, ...}
2284 triggers a bug on most SA-110 based devices, such that the stack
2285 pointer won't be correctly restored if the instruction takes a
2286 page fault. We work around this problem by popping r3 along with
2287 the other registers, since that is never slower than executing
2288 another instruction.
2290 We test for !arm_arch5 here, because code for any architecture
2291 less than this could potentially be run on one of the buggy
2293 if (stack_adjust == 4 && !arm_arch5 && TARGET_ARM)
2295 /* Validate that r3 is a call-clobbered register (always true in
2296 the default abi) ... */
2297 if (!call_used_regs[3])
2300 /* ... that it isn't being used for a return value ... */
2301 if (arm_size_return_regs () >= (4 * UNITS_PER_WORD))
2304 /* ... or for a tail-call argument ... */
2307 gcc_assert (GET_CODE (sibling) == CALL_INSN);
2309 if (find_regno_fusage (sibling, USE, 3))
2313 /* ... and that there are no call-saved registers in r0-r2
2314 (always true in the default ABI). */
2315 if (saved_int_regs & 0x7)
2319 /* Can't be done if interworking with Thumb, and any registers have been
2321 if (TARGET_INTERWORK && saved_int_regs != 0 && !IS_INTERRUPT(func_type))
2324 /* On StrongARM, conditional returns are expensive if they aren't
2325 taken and multiple registers have been stacked. */
2326 if (iscond && arm_tune_strongarm)
2328 /* Conditional return when just the LR is stored is a simple
2329 conditional-load instruction, that's not expensive. */
2330 if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM))
2334 && arm_pic_register != INVALID_REGNUM
2335 && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM))
2339 /* If there are saved registers but the LR isn't saved, then we need
2340 two instructions for the return. */
2341 if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM)))
2344 /* Can't be done if any of the FPA regs are pushed,
2345 since this also requires an insn. */
2346 if (TARGET_HARD_FLOAT && TARGET_FPA)
2347 for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++)
2348 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
2351 /* Likewise VFP regs. */
2352 if (TARGET_HARD_FLOAT && TARGET_VFP)
2353 for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++)
2354 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
2357 if (TARGET_REALLY_IWMMXT)
2358 for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++)
2359 if (df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2365 /* Return TRUE if int I is a valid immediate ARM constant. */
2368 const_ok_for_arm (HOST_WIDE_INT i)
2372 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
2373 be all zero, or all one. */
2374 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
2375 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
2376 != ((~(unsigned HOST_WIDE_INT) 0)
2377 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
2380 i &= (unsigned HOST_WIDE_INT) 0xffffffff;
2382 /* Fast return for 0 and small values. We must do this for zero, since
2383 the code below can't handle that one case. */
2384 if ((i & ~(unsigned HOST_WIDE_INT) 0xff) == 0)
2387 /* Get the number of trailing zeros. */
2388 lowbit = ffs((int) i) - 1;
2390 /* Only even shifts are allowed in ARM mode so round down to the
2391 nearest even number. */
2395 if ((i & ~(((unsigned HOST_WIDE_INT) 0xff) << lowbit)) == 0)
2400 /* Allow rotated constants in ARM mode. */
2402 && ((i & ~0xc000003f) == 0
2403 || (i & ~0xf000000f) == 0
2404 || (i & ~0xfc000003) == 0))
2411 /* Allow repeated patterns 0x00XY00XY or 0xXYXYXYXY. */
2414 if (i == v || i == (v | (v << 8)))
2417 /* Allow repeated pattern 0xXY00XY00. */
2427 /* Return true if I is a valid constant for the operation CODE. */
2429 const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code)
2431 if (const_ok_for_arm (i))
2437 /* See if we can use movw. */
2438 if (arm_arch_thumb2 && (i & 0xffff0000) == 0)
2441 /* Otherwise, try mvn. */
2442 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
2445 /* See if we can use addw or subw. */
2447 && ((i & 0xfffff000) == 0
2448 || ((-i) & 0xfffff000) == 0))
2450 /* else fall through. */
2470 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
2472 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
2478 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
2482 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
2489 /* Emit a sequence of insns to handle a large constant.
2490 CODE is the code of the operation required, it can be any of SET, PLUS,
2491 IOR, AND, XOR, MINUS;
2492 MODE is the mode in which the operation is being performed;
2493 VAL is the integer to operate on;
2494 SOURCE is the other operand (a register, or a null-pointer for SET);
2495 SUBTARGETS means it is safe to create scratch registers if that will
2496 either produce a simpler sequence, or we will want to cse the values.
2497 Return value is the number of insns emitted. */
2499 /* ??? Tweak this for thumb2. */
2501 arm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn,
2502 HOST_WIDE_INT val, rtx target, rtx source, int subtargets)
2506 if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC)
2507 cond = COND_EXEC_TEST (PATTERN (insn));
2511 if (subtargets || code == SET
2512 || (GET_CODE (target) == REG && GET_CODE (source) == REG
2513 && REGNO (target) != REGNO (source)))
2515 /* After arm_reorg has been called, we can't fix up expensive
2516 constants by pushing them into memory so we must synthesize
2517 them in-line, regardless of the cost. This is only likely to
2518 be more costly on chips that have load delay slots and we are
2519 compiling without running the scheduler (so no splitting
2520 occurred before the final instruction emission).
2522 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
2524 if (!after_arm_reorg
2526 && (arm_gen_constant (code, mode, NULL_RTX, val, target, source,
2528 > (arm_constant_limit (optimize_function_for_size_p (cfun))
2533 /* Currently SET is the only monadic value for CODE, all
2534 the rest are diadic. */
2535 if (TARGET_USE_MOVT)
2536 arm_emit_movpair (target, GEN_INT (val));
2538 emit_set_insn (target, GEN_INT (val));
2544 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
2546 if (TARGET_USE_MOVT)
2547 arm_emit_movpair (temp, GEN_INT (val));
2549 emit_set_insn (temp, GEN_INT (val));
2551 /* For MINUS, the value is subtracted from, since we never
2552 have subtraction of a constant. */
2554 emit_set_insn (target, gen_rtx_MINUS (mode, temp, source));
2556 emit_set_insn (target,
2557 gen_rtx_fmt_ee (code, mode, source, temp));
2563 return arm_gen_constant (code, mode, cond, val, target, source, subtargets,
2567 /* Return a sequence of integers, in RETURN_SEQUENCE that fit into
2568 ARM/THUMB2 immediates, and add up to VAL.
2569 Thr function return value gives the number of insns required. */
2571 optimal_immediate_sequence (enum rtx_code code, unsigned HOST_WIDE_INT val,
2572 struct four_ints *return_sequence)
2574 int best_consecutive_zeros = 0;
2578 struct four_ints tmp_sequence;
2580 /* If we aren't targetting ARM, the best place to start is always at
2581 the bottom, otherwise look more closely. */
2584 for (i = 0; i < 32; i += 2)
2586 int consecutive_zeros = 0;
2588 if (!(val & (3 << i)))
2590 while ((i < 32) && !(val & (3 << i)))
2592 consecutive_zeros += 2;
2595 if (consecutive_zeros > best_consecutive_zeros)
2597 best_consecutive_zeros = consecutive_zeros;
2598 best_start = i - consecutive_zeros;
2605 /* So long as it won't require any more insns to do so, it's
2606 desirable to emit a small constant (in bits 0...9) in the last
2607 insn. This way there is more chance that it can be combined with
2608 a later addressing insn to form a pre-indexed load or store
2609 operation. Consider:
2611 *((volatile int *)0xe0000100) = 1;
2612 *((volatile int *)0xe0000110) = 2;
2614 We want this to wind up as:
2618 str rB, [rA, #0x100]
2620 str rB, [rA, #0x110]
2622 rather than having to synthesize both large constants from scratch.
2624 Therefore, we calculate how many insns would be required to emit
2625 the constant starting from `best_start', and also starting from
2626 zero (i.e. with bit 31 first to be output). If `best_start' doesn't
2627 yield a shorter sequence, we may as well use zero. */
2628 insns1 = optimal_immediate_sequence_1 (code, val, return_sequence, best_start);
2630 && ((((unsigned HOST_WIDE_INT) 1) << best_start) < val))
2632 insns2 = optimal_immediate_sequence_1 (code, val, &tmp_sequence, 0);
2633 if (insns2 <= insns1)
2635 *return_sequence = tmp_sequence;
2643 /* As for optimal_immediate_sequence, but starting at bit-position I. */
2645 optimal_immediate_sequence_1 (enum rtx_code code, unsigned HOST_WIDE_INT val,
2646 struct four_ints *return_sequence, int i)
2648 int remainder = val & 0xffffffff;
2651 /* Try and find a way of doing the job in either two or three
2654 In ARM mode we can use 8-bit constants, rotated to any 2-bit aligned
2655 location. We start at position I. This may be the MSB, or
2656 optimial_immediate_sequence may have positioned it at the largest block
2657 of zeros that are aligned on a 2-bit boundary. We then fill up the temps,
2658 wrapping around to the top of the word when we drop off the bottom.
2659 In the worst case this code should produce no more than four insns.
2661 In Thumb2 mode, we can use 32/16-bit replicated constants, and 8-bit
2662 constants, shifted to any arbitrary location. We should always start
2667 unsigned int b1, b2, b3, b4;
2668 unsigned HOST_WIDE_INT result;
2671 gcc_assert (insns < 4);
2676 /* First, find the next normal 12/8-bit shifted/rotated immediate. */
2677 if (remainder & ((TARGET_ARM ? (3 << (i - 2)) : (1 << (i - 1)))))
2680 if (i <= 12 && TARGET_THUMB2 && code == PLUS)
2681 /* We can use addw/subw for the last 12 bits. */
2685 /* Use an 8-bit shifted/rotated immediate. */
2689 result = remainder & ((0x0ff << end)
2690 | ((i < end) ? (0xff >> (32 - end))
2697 /* Arm allows rotates by a multiple of two. Thumb-2 allows
2698 arbitrary shifts. */
2699 i -= TARGET_ARM ? 2 : 1;
2703 /* Next, see if we can do a better job with a thumb2 replicated
2706 We do it this way around to catch the cases like 0x01F001E0 where
2707 two 8-bit immediates would work, but a replicated constant would
2710 TODO: 16-bit constants that don't clear all the bits, but still win.
2711 TODO: Arithmetic splitting for set/add/sub, rather than bitwise. */
2714 b1 = (remainder & 0xff000000) >> 24;
2715 b2 = (remainder & 0x00ff0000) >> 16;
2716 b3 = (remainder & 0x0000ff00) >> 8;
2717 b4 = remainder & 0xff;
2721 /* The 8-bit immediate already found clears b1 (and maybe b2),
2722 but must leave b3 and b4 alone. */
2724 /* First try to find a 32-bit replicated constant that clears
2725 almost everything. We can assume that we can't do it in one,
2726 or else we wouldn't be here. */
2727 unsigned int tmp = b1 & b2 & b3 & b4;
2728 unsigned int tmp2 = tmp + (tmp << 8) + (tmp << 16)
2730 unsigned int matching_bytes = (tmp == b1) + (tmp == b2)
2731 + (tmp == b3) + (tmp == b4);
2733 && (matching_bytes >= 3
2734 || (matching_bytes == 2
2735 && const_ok_for_op (remainder & ~tmp2, code))))
2737 /* At least 3 of the bytes match, and the fourth has at
2738 least as many bits set, or two of the bytes match
2739 and it will only require one more insn to finish. */
2747 /* Second, try to find a 16-bit replicated constant that can
2748 leave three of the bytes clear. If b2 or b4 is already
2749 zero, then we can. If the 8-bit from above would not
2750 clear b2 anyway, then we still win. */
2751 else if (b1 == b3 && (!b2 || !b4
2752 || (remainder & 0x00ff0000 & ~result)))
2754 result = remainder & 0xff00ff00;
2760 /* The 8-bit immediate already found clears b2 (and maybe b3)
2761 and we don't get here unless b1 is alredy clear, but it will
2762 leave b4 unchanged. */
2764 /* If we can clear b2 and b4 at once, then we win, since the
2765 8-bits couldn't possibly reach that far. */
2768 result = remainder & 0x00ff00ff;
2774 return_sequence->i[insns++] = result;
2775 remainder &= ~result;
2777 if (code == SET || code == MINUS)
2785 /* Emit an instruction with the indicated PATTERN. If COND is
2786 non-NULL, conditionalize the execution of the instruction on COND
2790 emit_constant_insn (rtx cond, rtx pattern)
2793 pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern);
2794 emit_insn (pattern);
2797 /* As above, but extra parameter GENERATE which, if clear, suppresses
2801 arm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond,
2802 HOST_WIDE_INT val, rtx target, rtx source, int subtargets,
2807 int final_invert = 0;
2809 int set_sign_bit_copies = 0;
2810 int clear_sign_bit_copies = 0;
2811 int clear_zero_bit_copies = 0;
2812 int set_zero_bit_copies = 0;
2813 int insns = 0, neg_insns, inv_insns;
2814 unsigned HOST_WIDE_INT temp1, temp2;
2815 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
2816 struct four_ints *immediates;
2817 struct four_ints pos_immediates, neg_immediates, inv_immediates;
2819 /* Find out which operations are safe for a given CODE. Also do a quick
2820 check for degenerate cases; these can occur when DImode operations
2833 if (remainder == 0xffffffff)
2836 emit_constant_insn (cond,
2837 gen_rtx_SET (VOIDmode, target,
2838 GEN_INT (ARM_SIGN_EXTEND (val))));
2844 if (reload_completed && rtx_equal_p (target, source))
2848 emit_constant_insn (cond,
2849 gen_rtx_SET (VOIDmode, target, source));
2858 emit_constant_insn (cond,
2859 gen_rtx_SET (VOIDmode, target, const0_rtx));
2862 if (remainder == 0xffffffff)
2864 if (reload_completed && rtx_equal_p (target, source))
2867 emit_constant_insn (cond,
2868 gen_rtx_SET (VOIDmode, target, source));
2877 if (reload_completed && rtx_equal_p (target, source))
2880 emit_constant_insn (cond,
2881 gen_rtx_SET (VOIDmode, target, source));
2885 if (remainder == 0xffffffff)
2888 emit_constant_insn (cond,
2889 gen_rtx_SET (VOIDmode, target,
2890 gen_rtx_NOT (mode, source)));
2897 /* We treat MINUS as (val - source), since (source - val) is always
2898 passed as (source + (-val)). */
2902 emit_constant_insn (cond,
2903 gen_rtx_SET (VOIDmode, target,
2904 gen_rtx_NEG (mode, source)));
2907 if (const_ok_for_arm (val))
2910 emit_constant_insn (cond,
2911 gen_rtx_SET (VOIDmode, target,
2912 gen_rtx_MINUS (mode, GEN_INT (val),
2923 /* If we can do it in one insn get out quickly. */
2924 if (const_ok_for_op (val, code))
2927 emit_constant_insn (cond,
2928 gen_rtx_SET (VOIDmode, target,
2930 ? gen_rtx_fmt_ee (code, mode, source,
2936 /* Calculate a few attributes that may be useful for specific
2938 /* Count number of leading zeros. */
2939 for (i = 31; i >= 0; i--)
2941 if ((remainder & (1 << i)) == 0)
2942 clear_sign_bit_copies++;
2947 /* Count number of leading 1's. */
2948 for (i = 31; i >= 0; i--)
2950 if ((remainder & (1 << i)) != 0)
2951 set_sign_bit_copies++;
2956 /* Count number of trailing zero's. */
2957 for (i = 0; i <= 31; i++)
2959 if ((remainder & (1 << i)) == 0)
2960 clear_zero_bit_copies++;
2965 /* Count number of trailing 1's. */
2966 for (i = 0; i <= 31; i++)
2968 if ((remainder & (1 << i)) != 0)
2969 set_zero_bit_copies++;
2977 /* See if we can do this by sign_extending a constant that is known
2978 to be negative. This is a good, way of doing it, since the shift
2979 may well merge into a subsequent insn. */
2980 if (set_sign_bit_copies > 1)
2982 if (const_ok_for_arm
2983 (temp1 = ARM_SIGN_EXTEND (remainder
2984 << (set_sign_bit_copies - 1))))
2988 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2989 emit_constant_insn (cond,
2990 gen_rtx_SET (VOIDmode, new_src,
2992 emit_constant_insn (cond,
2993 gen_ashrsi3 (target, new_src,
2994 GEN_INT (set_sign_bit_copies - 1)));
2998 /* For an inverted constant, we will need to set the low bits,
2999 these will be shifted out of harm's way. */
3000 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
3001 if (const_ok_for_arm (~temp1))
3005 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3006 emit_constant_insn (cond,
3007 gen_rtx_SET (VOIDmode, new_src,
3009 emit_constant_insn (cond,
3010 gen_ashrsi3 (target, new_src,
3011 GEN_INT (set_sign_bit_copies - 1)));
3017 /* See if we can calculate the value as the difference between two
3018 valid immediates. */
3019 if (clear_sign_bit_copies + clear_zero_bit_copies <= 16)
3021 int topshift = clear_sign_bit_copies & ~1;
3023 temp1 = ARM_SIGN_EXTEND ((remainder + (0x00800000 >> topshift))
3024 & (0xff000000 >> topshift));
3026 /* If temp1 is zero, then that means the 9 most significant
3027 bits of remainder were 1 and we've caused it to overflow.
3028 When topshift is 0 we don't need to do anything since we
3029 can borrow from 'bit 32'. */
3030 if (temp1 == 0 && topshift != 0)
3031 temp1 = 0x80000000 >> (topshift - 1);
3033 temp2 = ARM_SIGN_EXTEND (temp1 - remainder);
3035 if (const_ok_for_arm (temp2))
3039 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3040 emit_constant_insn (cond,
3041 gen_rtx_SET (VOIDmode, new_src,
3043 emit_constant_insn (cond,
3044 gen_addsi3 (target, new_src,
3052 /* See if we can generate this by setting the bottom (or the top)
3053 16 bits, and then shifting these into the other half of the
3054 word. We only look for the simplest cases, to do more would cost
3055 too much. Be careful, however, not to generate this when the
3056 alternative would take fewer insns. */
3057 if (val & 0xffff0000)
3059 temp1 = remainder & 0xffff0000;
3060 temp2 = remainder & 0x0000ffff;
3062 /* Overlaps outside this range are best done using other methods. */
3063 for (i = 9; i < 24; i++)
3065 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
3066 && !const_ok_for_arm (temp2))
3068 rtx new_src = (subtargets
3069 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
3071 insns = arm_gen_constant (code, mode, cond, temp2, new_src,
3072 source, subtargets, generate);
3080 gen_rtx_ASHIFT (mode, source,
3087 /* Don't duplicate cases already considered. */
3088 for (i = 17; i < 24; i++)
3090 if (((temp1 | (temp1 >> i)) == remainder)
3091 && !const_ok_for_arm (temp1))
3093 rtx new_src = (subtargets
3094 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
3096 insns = arm_gen_constant (code, mode, cond, temp1, new_src,
3097 source, subtargets, generate);
3102 gen_rtx_SET (VOIDmode, target,
3105 gen_rtx_LSHIFTRT (mode, source,
3116 /* If we have IOR or XOR, and the constant can be loaded in a
3117 single instruction, and we can find a temporary to put it in,
3118 then this can be done in two instructions instead of 3-4. */
3120 /* TARGET can't be NULL if SUBTARGETS is 0 */
3121 || (reload_completed && !reg_mentioned_p (target, source)))
3123 if (const_ok_for_arm (ARM_SIGN_EXTEND (~val)))
3127 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3129 emit_constant_insn (cond,
3130 gen_rtx_SET (VOIDmode, sub,
3132 emit_constant_insn (cond,
3133 gen_rtx_SET (VOIDmode, target,
3134 gen_rtx_fmt_ee (code, mode,
3145 x = y | constant ( which is composed of set_sign_bit_copies of leading 1s
3146 and the remainder 0s for e.g. 0xfff00000)
3147 x = ~(~(y ashift set_sign_bit_copies) lshiftrt set_sign_bit_copies)
3149 This can be done in 2 instructions by using shifts with mov or mvn.
3154 mvn r0, r0, lsr #12 */
3155 if (set_sign_bit_copies > 8
3156 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
3160 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3161 rtx shift = GEN_INT (set_sign_bit_copies);
3165 gen_rtx_SET (VOIDmode, sub,
3167 gen_rtx_ASHIFT (mode,
3172 gen_rtx_SET (VOIDmode, target,
3174 gen_rtx_LSHIFTRT (mode, sub,
3181 x = y | constant (which has set_zero_bit_copies number of trailing ones).
3183 x = ~((~y lshiftrt set_zero_bit_copies) ashift set_zero_bit_copies).
3185 For eg. r0 = r0 | 0xfff
3190 if (set_zero_bit_copies > 8
3191 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
3195 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3196 rtx shift = GEN_INT (set_zero_bit_copies);
3200 gen_rtx_SET (VOIDmode, sub,
3202 gen_rtx_LSHIFTRT (mode,
3207 gen_rtx_SET (VOIDmode, target,
3209 gen_rtx_ASHIFT (mode, sub,
3215 /* This will never be reached for Thumb2 because orn is a valid
3216 instruction. This is for Thumb1 and the ARM 32 bit cases.
3218 x = y | constant (such that ~constant is a valid constant)
3220 x = ~(~y & ~constant).
3222 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val)))
3226 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3227 emit_constant_insn (cond,
3228 gen_rtx_SET (VOIDmode, sub,
3229 gen_rtx_NOT (mode, source)));
3232 sub = gen_reg_rtx (mode);
3233 emit_constant_insn (cond,
3234 gen_rtx_SET (VOIDmode, sub,
3235 gen_rtx_AND (mode, source,
3237 emit_constant_insn (cond,
3238 gen_rtx_SET (VOIDmode, target,
3239 gen_rtx_NOT (mode, sub)));
3246 /* See if two shifts will do 2 or more insn's worth of work. */
3247 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
3249 HOST_WIDE_INT shift_mask = ((0xffffffff
3250 << (32 - clear_sign_bit_copies))
3253 if ((remainder | shift_mask) != 0xffffffff)
3257 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3258 insns = arm_gen_constant (AND, mode, cond,
3259 remainder | shift_mask,
3260 new_src, source, subtargets, 1);
3265 rtx targ = subtargets ? NULL_RTX : target;
3266 insns = arm_gen_constant (AND, mode, cond,
3267 remainder | shift_mask,
3268 targ, source, subtargets, 0);
3274 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3275 rtx shift = GEN_INT (clear_sign_bit_copies);
3277 emit_insn (gen_ashlsi3 (new_src, source, shift));
3278 emit_insn (gen_lshrsi3 (target, new_src, shift));
3284 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
3286 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
3288 if ((remainder | shift_mask) != 0xffffffff)
3292 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3294 insns = arm_gen_constant (AND, mode, cond,
3295 remainder | shift_mask,
3296 new_src, source, subtargets, 1);
3301 rtx targ = subtargets ? NULL_RTX : target;
3303 insns = arm_gen_constant (AND, mode, cond,
3304 remainder | shift_mask,
3305 targ, source, subtargets, 0);
3311 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3312 rtx shift = GEN_INT (clear_zero_bit_copies);
3314 emit_insn (gen_lshrsi3 (new_src, source, shift));
3315 emit_insn (gen_ashlsi3 (target, new_src, shift));
3327 /* Calculate what the instruction sequences would be if we generated it
3328 normally, negated, or inverted. */
3330 /* AND cannot be split into multiple insns, so invert and use BIC. */
3333 insns = optimal_immediate_sequence (code, remainder, &pos_immediates);
3336 neg_insns = optimal_immediate_sequence (code, (-remainder) & 0xffffffff,
3341 if (can_invert || final_invert)
3342 inv_insns = optimal_immediate_sequence (code, remainder ^ 0xffffffff,
3347 immediates = &pos_immediates;
3349 /* Is the negated immediate sequence more efficient? */
3350 if (neg_insns < insns && neg_insns <= inv_insns)
3353 immediates = &neg_immediates;
3358 /* Is the inverted immediate sequence more efficient?
3359 We must allow for an extra NOT instruction for XOR operations, although
3360 there is some chance that the final 'mvn' will get optimized later. */
3361 if ((inv_insns + 1) < insns || (!final_invert && inv_insns < insns))
3364 immediates = &inv_immediates;
3372 /* Now output the chosen sequence as instructions. */
3375 for (i = 0; i < insns; i++)
3377 rtx new_src, temp1_rtx;
3379 temp1 = immediates->i[i];
3381 if (code == SET || code == MINUS)
3382 new_src = (subtargets ? gen_reg_rtx (mode) : target);
3383 else if ((final_invert || i < (insns - 1)) && subtargets)
3384 new_src = gen_reg_rtx (mode);
3390 else if (can_negate)
3393 temp1 = trunc_int_for_mode (temp1, mode);
3394 temp1_rtx = GEN_INT (temp1);
3398 else if (code == MINUS)
3399 temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source);
3401 temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx);
3403 emit_constant_insn (cond,
3404 gen_rtx_SET (VOIDmode, new_src,
3410 can_negate = can_invert;
3414 else if (code == MINUS)
3422 emit_constant_insn (cond, gen_rtx_SET (VOIDmode, target,
3423 gen_rtx_NOT (mode, source)));
3430 /* Canonicalize a comparison so that we are more likely to recognize it.
3431 This can be done for a few constant compares, where we can make the
3432 immediate value easier to load. */
3435 arm_canonicalize_comparison (enum rtx_code code, rtx *op0, rtx *op1)
3437 enum machine_mode mode;
3438 unsigned HOST_WIDE_INT i, maxval;
3440 mode = GET_MODE (*op0);
3441 if (mode == VOIDmode)
3442 mode = GET_MODE (*op1);
3444 maxval = (((unsigned HOST_WIDE_INT) 1) << (GET_MODE_BITSIZE(mode) - 1)) - 1;
3446 /* For DImode, we have GE/LT/GEU/LTU comparisons. In ARM mode
3447 we can also use cmp/cmpeq for GTU/LEU. GT/LE must be either
3448 reversed or (for constant OP1) adjusted to GE/LT. Similarly
3449 for GTU/LEU in Thumb mode. */
3454 /* To keep things simple, always use the Cirrus cfcmp64 if it is
3456 if (TARGET_ARM && TARGET_HARD_FLOAT && TARGET_MAVERICK)
3459 if (code == GT || code == LE
3460 || (!TARGET_ARM && (code == GTU || code == LEU)))
3462 /* Missing comparison. First try to use an available
3464 if (GET_CODE (*op1) == CONST_INT)
3472 && arm_const_double_by_immediates (GEN_INT (i + 1)))
3474 *op1 = GEN_INT (i + 1);
3475 return code == GT ? GE : LT;
3480 if (i != ~((unsigned HOST_WIDE_INT) 0)
3481 && arm_const_double_by_immediates (GEN_INT (i + 1)))
3483 *op1 = GEN_INT (i + 1);
3484 return code == GTU ? GEU : LTU;
3492 /* If that did not work, reverse the condition. */
3496 return swap_condition (code);
3502 /* If *op0 is (zero_extend:SI (subreg:QI (reg:SI) 0)) and comparing
3503 with const0_rtx, change it to (and:SI (reg:SI) (const_int 255)),
3504 to facilitate possible combining with a cmp into 'ands'. */
3506 && GET_CODE (*op0) == ZERO_EXTEND
3507 && GET_CODE (XEXP (*op0, 0)) == SUBREG
3508 && GET_MODE (XEXP (*op0, 0)) == QImode
3509 && GET_MODE (SUBREG_REG (XEXP (*op0, 0))) == SImode
3510 && subreg_lowpart_p (XEXP (*op0, 0))
3511 && *op1 == const0_rtx)
3512 *op0 = gen_rtx_AND (SImode, SUBREG_REG (XEXP (*op0, 0)),
3515 /* Comparisons smaller than DImode. Only adjust comparisons against
3516 an out-of-range constant. */
3517 if (GET_CODE (*op1) != CONST_INT
3518 || const_ok_for_arm (INTVAL (*op1))
3519 || const_ok_for_arm (- INTVAL (*op1)))
3533 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
3535 *op1 = GEN_INT (i + 1);
3536 return code == GT ? GE : LT;
3543 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
3545 *op1 = GEN_INT (i - 1);
3546 return code == GE ? GT : LE;
3552 if (i != ~((unsigned HOST_WIDE_INT) 0)
3553 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
3555 *op1 = GEN_INT (i + 1);
3556 return code == GTU ? GEU : LTU;
3563 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
3565 *op1 = GEN_INT (i - 1);
3566 return code == GEU ? GTU : LEU;
3578 /* Define how to find the value returned by a function. */
3581 arm_function_value(const_tree type, const_tree func,
3582 bool outgoing ATTRIBUTE_UNUSED)
3584 enum machine_mode mode;
3585 int unsignedp ATTRIBUTE_UNUSED;
3586 rtx r ATTRIBUTE_UNUSED;
3588 mode = TYPE_MODE (type);
3590 if (TARGET_AAPCS_BASED)
3591 return aapcs_allocate_return_reg (mode, type, func);
3593 /* Promote integer types. */
3594 if (INTEGRAL_TYPE_P (type))
3595 mode = arm_promote_function_mode (type, mode, &unsignedp, func, 1);
3597 /* Promotes small structs returned in a register to full-word size
3598 for big-endian AAPCS. */
3599 if (arm_return_in_msb (type))
3601 HOST_WIDE_INT size = int_size_in_bytes (type);
3602 if (size % UNITS_PER_WORD != 0)
3604 size += UNITS_PER_WORD - size % UNITS_PER_WORD;
3605 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
3609 return arm_libcall_value_1 (mode);
3613 libcall_eq (const void *p1, const void *p2)
3615 return rtx_equal_p ((const_rtx) p1, (const_rtx) p2);
3619 libcall_hash (const void *p1)
3621 return hash_rtx ((const_rtx) p1, VOIDmode, NULL, NULL, FALSE);
3625 add_libcall (htab_t htab, rtx libcall)
3627 *htab_find_slot (htab, libcall, INSERT) = libcall;
3631 arm_libcall_uses_aapcs_base (const_rtx libcall)
3633 static bool init_done = false;
3634 static htab_t libcall_htab;
3640 libcall_htab = htab_create (31, libcall_hash, libcall_eq,
3642 add_libcall (libcall_htab,
3643 convert_optab_libfunc (sfloat_optab, SFmode, SImode));
3644 add_libcall (libcall_htab,
3645 convert_optab_libfunc (sfloat_optab, DFmode, SImode));
3646 add_libcall (libcall_htab,
3647 convert_optab_libfunc (sfloat_optab, SFmode, DImode));
3648 add_libcall (libcall_htab,
3649 convert_optab_libfunc (sfloat_optab, DFmode, DImode));
3651 add_libcall (libcall_htab,
3652 convert_optab_libfunc (ufloat_optab, SFmode, SImode));
3653 add_libcall (libcall_htab,
3654 convert_optab_libfunc (ufloat_optab, DFmode, SImode));
3655 add_libcall (libcall_htab,
3656 convert_optab_libfunc (ufloat_optab, SFmode, DImode));
3657 add_libcall (libcall_htab,
3658 convert_optab_libfunc (ufloat_optab, DFmode, DImode));
3660 add_libcall (libcall_htab,
3661 convert_optab_libfunc (sext_optab, SFmode, HFmode));
3662 add_libcall (libcall_htab,
3663 convert_optab_libfunc (trunc_optab, HFmode, SFmode));
3664 add_libcall (libcall_htab,
3665 convert_optab_libfunc (sfix_optab, DImode, DFmode));
3666 add_libcall (libcall_htab,
3667 convert_optab_libfunc (ufix_optab, DImode, DFmode));
3668 add_libcall (libcall_htab,
3669 convert_optab_libfunc (sfix_optab, DImode, SFmode));
3670 add_libcall (libcall_htab,
3671 convert_optab_libfunc (ufix_optab, DImode, SFmode));
3673 /* Values from double-precision helper functions are returned in core
3674 registers if the selected core only supports single-precision
3675 arithmetic, even if we are using the hard-float ABI. The same is
3676 true for single-precision helpers, but we will never be using the
3677 hard-float ABI on a CPU which doesn't support single-precision
3678 operations in hardware. */
3679 add_libcall (libcall_htab, optab_libfunc (add_optab, DFmode));
3680 add_libcall (libcall_htab, optab_libfunc (sdiv_optab, DFmode));
3681 add_libcall (libcall_htab, optab_libfunc (smul_optab, DFmode));
3682 add_libcall (libcall_htab, optab_libfunc (neg_optab, DFmode));
3683 add_libcall (libcall_htab, optab_libfunc (sub_optab, DFmode));
3684 add_libcall (libcall_htab, optab_libfunc (eq_optab, DFmode));
3685 add_libcall (libcall_htab, optab_libfunc (lt_optab, DFmode));
3686 add_libcall (libcall_htab, optab_libfunc (le_optab, DFmode));
3687 add_libcall (libcall_htab, optab_libfunc (ge_optab, DFmode));
3688 add_libcall (libcall_htab, optab_libfunc (gt_optab, DFmode));
3689 add_libcall (libcall_htab, optab_libfunc (unord_optab, DFmode));
3690 add_libcall (libcall_htab, convert_optab_libfunc (sext_optab, DFmode,
3692 add_libcall (libcall_htab, convert_optab_libfunc (trunc_optab, SFmode,
3696 return libcall && htab_find (libcall_htab, libcall) != NULL;
3700 arm_libcall_value_1 (enum machine_mode mode)
3702 if (TARGET_AAPCS_BASED)
3703 return aapcs_libcall_value (mode);
3704 else if (TARGET_32BIT
3705 && TARGET_HARD_FLOAT_ABI
3707 && GET_MODE_CLASS (mode) == MODE_FLOAT)
3708 return gen_rtx_REG (mode, FIRST_FPA_REGNUM);
3709 else if (TARGET_32BIT
3710 && TARGET_HARD_FLOAT_ABI
3712 && GET_MODE_CLASS (mode) == MODE_FLOAT)
3713 return gen_rtx_REG (mode, FIRST_CIRRUS_FP_REGNUM);
3714 else if (TARGET_IWMMXT_ABI
3715 && arm_vector_mode_supported_p (mode))
3716 return gen_rtx_REG (mode, FIRST_IWMMXT_REGNUM);
3718 return gen_rtx_REG (mode, ARG_REGISTER (1));
3721 /* Define how to find the value returned by a library function
3722 assuming the value has mode MODE. */
3725 arm_libcall_value (enum machine_mode mode, const_rtx libcall)
3727 if (TARGET_AAPCS_BASED && arm_pcs_default != ARM_PCS_AAPCS
3728 && GET_MODE_CLASS (mode) == MODE_FLOAT)
3730 /* The following libcalls return their result in integer registers,
3731 even though they return a floating point value. */
3732 if (arm_libcall_uses_aapcs_base (libcall))
3733 return gen_rtx_REG (mode, ARG_REGISTER(1));
3737 return arm_libcall_value_1 (mode);
3740 /* Implement TARGET_FUNCTION_VALUE_REGNO_P. */
3743 arm_function_value_regno_p (const unsigned int regno)
3745 if (regno == ARG_REGISTER (1)
3747 && TARGET_AAPCS_BASED
3749 && TARGET_HARD_FLOAT
3750 && regno == FIRST_VFP_REGNUM)
3752 && TARGET_HARD_FLOAT_ABI
3754 && regno == FIRST_CIRRUS_FP_REGNUM)
3755 || (TARGET_IWMMXT_ABI
3756 && regno == FIRST_IWMMXT_REGNUM)
3758 && TARGET_HARD_FLOAT_ABI
3760 && regno == FIRST_FPA_REGNUM))
3766 /* Determine the amount of memory needed to store the possible return
3767 registers of an untyped call. */
3769 arm_apply_result_size (void)
3775 if (TARGET_HARD_FLOAT_ABI)
3781 if (TARGET_MAVERICK)
3784 if (TARGET_IWMMXT_ABI)
3791 /* Decide whether TYPE should be returned in memory (true)
3792 or in a register (false). FNTYPE is the type of the function making
3795 arm_return_in_memory (const_tree type, const_tree fntype)
3799 size = int_size_in_bytes (type); /* Negative if not fixed size. */
3801 if (TARGET_AAPCS_BASED)
3803 /* Simple, non-aggregate types (ie not including vectors and
3804 complex) are always returned in a register (or registers).
3805 We don't care about which register here, so we can short-cut
3806 some of the detail. */
3807 if (!AGGREGATE_TYPE_P (type)
3808 && TREE_CODE (type) != VECTOR_TYPE
3809 && TREE_CODE (type) != COMPLEX_TYPE)
3812 /* Any return value that is no larger than one word can be
3814 if (((unsigned HOST_WIDE_INT) size) <= UNITS_PER_WORD)
3817 /* Check any available co-processors to see if they accept the
3818 type as a register candidate (VFP, for example, can return
3819 some aggregates in consecutive registers). These aren't
3820 available if the call is variadic. */
3821 if (aapcs_select_return_coproc (type, fntype) >= 0)
3824 /* Vector values should be returned using ARM registers, not
3825 memory (unless they're over 16 bytes, which will break since
3826 we only have four call-clobbered registers to play with). */
3827 if (TREE_CODE (type) == VECTOR_TYPE)
3828 return (size < 0 || size > (4 * UNITS_PER_WORD));
3830 /* The rest go in memory. */
3834 if (TREE_CODE (type) == VECTOR_TYPE)
3835 return (size < 0 || size > (4 * UNITS_PER_WORD));
3837 if (!AGGREGATE_TYPE_P (type) &&
3838 (TREE_CODE (type) != VECTOR_TYPE))
3839 /* All simple types are returned in registers. */
3842 if (arm_abi != ARM_ABI_APCS)
3844 /* ATPCS and later return aggregate types in memory only if they are
3845 larger than a word (or are variable size). */
3846 return (size < 0 || size > UNITS_PER_WORD);
3849 /* For the arm-wince targets we choose to be compatible with Microsoft's
3850 ARM and Thumb compilers, which always return aggregates in memory. */
3852 /* All structures/unions bigger than one word are returned in memory.
3853 Also catch the case where int_size_in_bytes returns -1. In this case
3854 the aggregate is either huge or of variable size, and in either case
3855 we will want to return it via memory and not in a register. */
3856 if (size < 0 || size > UNITS_PER_WORD)
3859 if (TREE_CODE (type) == RECORD_TYPE)
3863 /* For a struct the APCS says that we only return in a register
3864 if the type is 'integer like' and every addressable element
3865 has an offset of zero. For practical purposes this means
3866 that the structure can have at most one non bit-field element
3867 and that this element must be the first one in the structure. */
3869 /* Find the first field, ignoring non FIELD_DECL things which will
3870 have been created by C++. */
3871 for (field = TYPE_FIELDS (type);
3872 field && TREE_CODE (field) != FIELD_DECL;
3873 field = DECL_CHAIN (field))
3877 return false; /* An empty structure. Allowed by an extension to ANSI C. */
3879 /* Check that the first field is valid for returning in a register. */
3881 /* ... Floats are not allowed */
3882 if (FLOAT_TYPE_P (TREE_TYPE (field)))
3885 /* ... Aggregates that are not themselves valid for returning in
3886 a register are not allowed. */
3887 if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE))
3890 /* Now check the remaining fields, if any. Only bitfields are allowed,
3891 since they are not addressable. */
3892 for (field = DECL_CHAIN (field);
3894 field = DECL_CHAIN (field))
3896 if (TREE_CODE (field) != FIELD_DECL)
3899 if (!DECL_BIT_FIELD_TYPE (field))
3906 if (TREE_CODE (type) == UNION_TYPE)
3910 /* Unions can be returned in registers if every element is
3911 integral, or can be returned in an integer register. */
3912 for (field = TYPE_FIELDS (type);
3914 field = DECL_CHAIN (field))
3916 if (TREE_CODE (field) != FIELD_DECL)
3919 if (FLOAT_TYPE_P (TREE_TYPE (field)))
3922 if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE))
3928 #endif /* not ARM_WINCE */
3930 /* Return all other types in memory. */
3934 /* Indicate whether or not words of a double are in big-endian order. */
3937 arm_float_words_big_endian (void)
3939 if (TARGET_MAVERICK)
3942 /* For FPA, float words are always big-endian. For VFP, floats words
3943 follow the memory system mode. */
3951 return (TARGET_BIG_END ? 1 : 0);
3956 const struct pcs_attribute_arg
3960 } pcs_attribute_args[] =
3962 {"aapcs", ARM_PCS_AAPCS},
3963 {"aapcs-vfp", ARM_PCS_AAPCS_VFP},
3965 /* We could recognize these, but changes would be needed elsewhere
3966 * to implement them. */
3967 {"aapcs-iwmmxt", ARM_PCS_AAPCS_IWMMXT},