1 /* Output routines for GCC for ARM.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl)
6 and Martin Simmons (@harleqn.co.uk).
7 More major hacks by Richard Earnshaw (rearnsha@arm.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published
13 by the Free Software Foundation; either version 3, or (at your
14 option) any later version.
16 GCC is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 #include "coretypes.h"
33 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "conditions.h"
37 #include "insn-attr.h"
43 #include "diagnostic-core.h"
48 #include "c-family/c-pragma.h" /* ??? */
49 #include "integrate.h"
52 #include "target-def.h"
54 #include "langhooks.h"
61 /* Forward definitions of types. */
62 typedef struct minipool_node Mnode;
63 typedef struct minipool_fixup Mfix;
65 void (*arm_lang_output_object_attributes_hook)(void);
72 /* Forward function declarations. */
73 static bool arm_needs_doubleword_align (enum machine_mode, const_tree);
74 static int arm_compute_static_chain_stack_bytes (void);
75 static arm_stack_offsets *arm_get_frame_offsets (void);
76 static void arm_add_gc_roots (void);
77 static int arm_gen_constant (enum rtx_code, enum machine_mode, rtx,
78 HOST_WIDE_INT, rtx, rtx, int, int);
79 static unsigned bit_count (unsigned long);
80 static int arm_address_register_rtx_p (rtx, int);
81 static int arm_legitimate_index_p (enum machine_mode, rtx, RTX_CODE, int);
82 static int thumb2_legitimate_index_p (enum machine_mode, rtx, int);
83 static int thumb1_base_register_rtx_p (rtx, enum machine_mode, int);
84 static rtx arm_legitimize_address (rtx, rtx, enum machine_mode);
85 static rtx thumb_legitimize_address (rtx, rtx, enum machine_mode);
86 inline static int thumb1_index_register_rtx_p (rtx, int);
87 static bool arm_legitimate_address_p (enum machine_mode, rtx, bool);
88 static int thumb_far_jump_used_p (void);
89 static bool thumb_force_lr_save (void);
90 static rtx emit_sfm (int, int);
91 static unsigned arm_size_return_regs (void);
92 static bool arm_assemble_integer (rtx, unsigned int, int);
93 static void arm_print_operand (FILE *, rtx, int);
94 static void arm_print_operand_address (FILE *, rtx);
95 static bool arm_print_operand_punct_valid_p (unsigned char code);
96 static const char *fp_const_from_val (REAL_VALUE_TYPE *);
97 static arm_cc get_arm_condition_code (rtx);
98 static HOST_WIDE_INT int_log2 (HOST_WIDE_INT);
99 static rtx is_jump_table (rtx);
100 static const char *output_multi_immediate (rtx *, const char *, const char *,
102 static const char *shift_op (rtx, HOST_WIDE_INT *);
103 static struct machine_function *arm_init_machine_status (void);
104 static void thumb_exit (FILE *, int);
105 static rtx is_jump_table (rtx);
106 static HOST_WIDE_INT get_jump_table_size (rtx);
107 static Mnode *move_minipool_fix_forward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
108 static Mnode *add_minipool_forward_ref (Mfix *);
109 static Mnode *move_minipool_fix_backward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
110 static Mnode *add_minipool_backward_ref (Mfix *);
111 static void assign_minipool_offsets (Mfix *);
112 static void arm_print_value (FILE *, rtx);
113 static void dump_minipool (rtx);
114 static int arm_barrier_cost (rtx);
115 static Mfix *create_fix_barrier (Mfix *, HOST_WIDE_INT);
116 static void push_minipool_barrier (rtx, HOST_WIDE_INT);
117 static void push_minipool_fix (rtx, HOST_WIDE_INT, rtx *, enum machine_mode,
119 static void arm_reorg (void);
120 static bool note_invalid_constants (rtx, HOST_WIDE_INT, int);
121 static unsigned long arm_compute_save_reg0_reg12_mask (void);
122 static unsigned long arm_compute_save_reg_mask (void);
123 static unsigned long arm_isr_value (tree);
124 static unsigned long arm_compute_func_type (void);
125 static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
126 static tree arm_handle_pcs_attribute (tree *, tree, tree, int, bool *);
127 static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *);
128 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
129 static tree arm_handle_notshared_attribute (tree *, tree, tree, int, bool *);
131 static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT);
132 static void arm_output_function_prologue (FILE *, HOST_WIDE_INT);
133 static int arm_comp_type_attributes (const_tree, const_tree);
134 static void arm_set_default_type_attributes (tree);
135 static int arm_adjust_cost (rtx, rtx, rtx, int);
136 static int optimal_immediate_sequence (enum rtx_code code,
137 unsigned HOST_WIDE_INT val,
138 struct four_ints *return_sequence);
139 static int optimal_immediate_sequence_1 (enum rtx_code code,
140 unsigned HOST_WIDE_INT val,
141 struct four_ints *return_sequence,
143 static int arm_get_strip_length (int);
144 static bool arm_function_ok_for_sibcall (tree, tree);
145 static enum machine_mode arm_promote_function_mode (const_tree,
146 enum machine_mode, int *,
148 static bool arm_return_in_memory (const_tree, const_tree);
149 static rtx arm_function_value (const_tree, const_tree, bool);
150 static rtx arm_libcall_value_1 (enum machine_mode);
151 static rtx arm_libcall_value (enum machine_mode, const_rtx);
152 static bool arm_function_value_regno_p (const unsigned int);
153 static void arm_internal_label (FILE *, const char *, unsigned long);
154 static void arm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
156 static bool arm_have_conditional_execution (void);
157 static bool arm_cannot_force_const_mem (enum machine_mode, rtx);
158 static bool arm_legitimate_constant_p (enum machine_mode, rtx);
159 static bool arm_rtx_costs_1 (rtx, enum rtx_code, int*, bool);
160 static bool arm_size_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *);
161 static bool arm_slowmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
162 static bool arm_fastmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
163 static bool arm_xscale_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
164 static bool arm_9e_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
165 static bool arm_rtx_costs (rtx, int, int, int, int *, bool);
166 static int arm_address_cost (rtx, bool);
167 static int arm_register_move_cost (enum machine_mode, reg_class_t, reg_class_t);
168 static int arm_memory_move_cost (enum machine_mode, reg_class_t, bool);
169 static bool arm_memory_load_p (rtx);
170 static bool arm_cirrus_insn_p (rtx);
171 static void cirrus_reorg (rtx);
172 static void arm_init_builtins (void);
173 static void arm_init_iwmmxt_builtins (void);
174 static rtx safe_vector_operand (rtx, enum machine_mode);
175 static rtx arm_expand_binop_builtin (enum insn_code, tree, rtx);
176 static rtx arm_expand_unop_builtin (enum insn_code, tree, rtx, int);
177 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
178 static tree arm_builtin_decl (unsigned, bool);
179 static void emit_constant_insn (rtx cond, rtx pattern);
180 static rtx emit_set_insn (rtx, rtx);
181 static int arm_arg_partial_bytes (cumulative_args_t, enum machine_mode,
183 static rtx arm_function_arg (cumulative_args_t, enum machine_mode,
185 static void arm_function_arg_advance (cumulative_args_t, enum machine_mode,
187 static unsigned int arm_function_arg_boundary (enum machine_mode, const_tree);
188 static rtx aapcs_allocate_return_reg (enum machine_mode, const_tree,
190 static rtx aapcs_libcall_value (enum machine_mode);
191 static int aapcs_select_return_coproc (const_tree, const_tree);
193 #ifdef OBJECT_FORMAT_ELF
194 static void arm_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED;
195 static void arm_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED;
198 static void arm_encode_section_info (tree, rtx, int);
201 static void arm_file_end (void);
202 static void arm_file_start (void);
204 static void arm_setup_incoming_varargs (cumulative_args_t, enum machine_mode,
206 static bool arm_pass_by_reference (cumulative_args_t,
207 enum machine_mode, const_tree, bool);
208 static bool arm_promote_prototypes (const_tree);
209 static bool arm_default_short_enums (void);
210 static bool arm_align_anon_bitfield (void);
211 static bool arm_return_in_msb (const_tree);
212 static bool arm_must_pass_in_stack (enum machine_mode, const_tree);
213 static bool arm_return_in_memory (const_tree, const_tree);
215 static void arm_unwind_emit (FILE *, rtx);
216 static bool arm_output_ttype (rtx);
217 static void arm_asm_emit_except_personality (rtx);
218 static void arm_asm_init_sections (void);
220 static rtx arm_dwarf_register_span (rtx);
222 static tree arm_cxx_guard_type (void);
223 static bool arm_cxx_guard_mask_bit (void);
224 static tree arm_get_cookie_size (tree);
225 static bool arm_cookie_has_size (void);
226 static bool arm_cxx_cdtor_returns_this (void);
227 static bool arm_cxx_key_method_may_be_inline (void);
228 static void arm_cxx_determine_class_data_visibility (tree);
229 static bool arm_cxx_class_data_always_comdat (void);
230 static bool arm_cxx_use_aeabi_atexit (void);
231 static void arm_init_libfuncs (void);
232 static tree arm_build_builtin_va_list (void);
233 static void arm_expand_builtin_va_start (tree, rtx);
234 static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
235 static void arm_option_override (void);
236 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode);
237 static bool arm_cannot_copy_insn_p (rtx);
238 static bool arm_tls_symbol_p (rtx x);
239 static int arm_issue_rate (void);
240 static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
241 static bool arm_output_addr_const_extra (FILE *, rtx);
242 static bool arm_allocate_stack_slots_for_args (void);
243 static const char *arm_invalid_parameter_type (const_tree t);
244 static const char *arm_invalid_return_type (const_tree t);
245 static tree arm_promoted_type (const_tree t);
246 static tree arm_convert_to_type (tree type, tree expr);
247 static bool arm_scalar_mode_supported_p (enum machine_mode);
248 static bool arm_frame_pointer_required (void);
249 static bool arm_can_eliminate (const int, const int);
250 static void arm_asm_trampoline_template (FILE *);
251 static void arm_trampoline_init (rtx, tree, rtx);
252 static rtx arm_trampoline_adjust_address (rtx);
253 static rtx arm_pic_static_addr (rtx orig, rtx reg);
254 static bool cortex_a9_sched_adjust_cost (rtx, rtx, rtx, int *);
255 static bool xscale_sched_adjust_cost (rtx, rtx, rtx, int *);
256 static bool fa726te_sched_adjust_cost (rtx, rtx, rtx, int *);
257 static bool arm_array_mode_supported_p (enum machine_mode,
258 unsigned HOST_WIDE_INT);
259 static enum machine_mode arm_preferred_simd_mode (enum machine_mode);
260 static bool arm_class_likely_spilled_p (reg_class_t);
261 static bool arm_vector_alignment_reachable (const_tree type, bool is_packed);
262 static bool arm_builtin_support_vector_misalignment (enum machine_mode mode,
266 static void arm_conditional_register_usage (void);
267 static reg_class_t arm_preferred_rename_class (reg_class_t rclass);
268 static unsigned int arm_autovectorize_vector_sizes (void);
269 static int arm_default_branch_cost (bool, bool);
270 static int arm_cortex_a5_branch_cost (bool, bool);
272 static bool arm_vectorize_vec_perm_const_ok (enum machine_mode vmode,
273 const unsigned char *sel);
276 /* Table of machine attributes. */
277 static const struct attribute_spec arm_attribute_table[] =
279 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
280 affects_type_identity } */
281 /* Function calls made to this symbol must be done indirectly, because
282 it may lie outside of the 26 bit addressing range of a normal function
284 { "long_call", 0, 0, false, true, true, NULL, false },
285 /* Whereas these functions are always known to reside within the 26 bit
287 { "short_call", 0, 0, false, true, true, NULL, false },
288 /* Specify the procedure call conventions for a function. */
289 { "pcs", 1, 1, false, true, true, arm_handle_pcs_attribute,
291 /* Interrupt Service Routines have special prologue and epilogue requirements. */
292 { "isr", 0, 1, false, false, false, arm_handle_isr_attribute,
294 { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute,
296 { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute,
299 /* ARM/PE has three new attributes:
301 dllexport - for exporting a function/variable that will live in a dll
302 dllimport - for importing a function/variable from a dll
304 Microsoft allows multiple declspecs in one __declspec, separating
305 them with spaces. We do NOT support this. Instead, use __declspec
308 { "dllimport", 0, 0, true, false, false, NULL, false },
309 { "dllexport", 0, 0, true, false, false, NULL, false },
310 { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute,
312 #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
313 { "dllimport", 0, 0, false, false, false, handle_dll_attribute, false },
314 { "dllexport", 0, 0, false, false, false, handle_dll_attribute, false },
315 { "notshared", 0, 0, false, true, false, arm_handle_notshared_attribute,
318 { NULL, 0, 0, false, false, false, NULL, false }
321 /* Initialize the GCC target structure. */
322 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
323 #undef TARGET_MERGE_DECL_ATTRIBUTES
324 #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
327 #undef TARGET_LEGITIMIZE_ADDRESS
328 #define TARGET_LEGITIMIZE_ADDRESS arm_legitimize_address
330 #undef TARGET_ATTRIBUTE_TABLE
331 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
333 #undef TARGET_ASM_FILE_START
334 #define TARGET_ASM_FILE_START arm_file_start
335 #undef TARGET_ASM_FILE_END
336 #define TARGET_ASM_FILE_END arm_file_end
338 #undef TARGET_ASM_ALIGNED_SI_OP
339 #define TARGET_ASM_ALIGNED_SI_OP NULL
340 #undef TARGET_ASM_INTEGER
341 #define TARGET_ASM_INTEGER arm_assemble_integer
343 #undef TARGET_PRINT_OPERAND
344 #define TARGET_PRINT_OPERAND arm_print_operand
345 #undef TARGET_PRINT_OPERAND_ADDRESS
346 #define TARGET_PRINT_OPERAND_ADDRESS arm_print_operand_address
347 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
348 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P arm_print_operand_punct_valid_p
350 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
351 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA arm_output_addr_const_extra
353 #undef TARGET_ASM_FUNCTION_PROLOGUE
354 #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue
356 #undef TARGET_ASM_FUNCTION_EPILOGUE
357 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
359 #undef TARGET_OPTION_OVERRIDE
360 #define TARGET_OPTION_OVERRIDE arm_option_override
362 #undef TARGET_COMP_TYPE_ATTRIBUTES
363 #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes
365 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
366 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes
368 #undef TARGET_SCHED_ADJUST_COST
369 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
371 #undef TARGET_REGISTER_MOVE_COST
372 #define TARGET_REGISTER_MOVE_COST arm_register_move_cost
374 #undef TARGET_MEMORY_MOVE_COST
375 #define TARGET_MEMORY_MOVE_COST arm_memory_move_cost
377 #undef TARGET_ENCODE_SECTION_INFO
379 #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info
381 #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info
384 #undef TARGET_STRIP_NAME_ENCODING
385 #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding
387 #undef TARGET_ASM_INTERNAL_LABEL
388 #define TARGET_ASM_INTERNAL_LABEL arm_internal_label
390 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
391 #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall
393 #undef TARGET_FUNCTION_VALUE
394 #define TARGET_FUNCTION_VALUE arm_function_value
396 #undef TARGET_LIBCALL_VALUE
397 #define TARGET_LIBCALL_VALUE arm_libcall_value
399 #undef TARGET_FUNCTION_VALUE_REGNO_P
400 #define TARGET_FUNCTION_VALUE_REGNO_P arm_function_value_regno_p
402 #undef TARGET_ASM_OUTPUT_MI_THUNK
403 #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk
404 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
405 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
407 #undef TARGET_RTX_COSTS
408 #define TARGET_RTX_COSTS arm_rtx_costs
409 #undef TARGET_ADDRESS_COST
410 #define TARGET_ADDRESS_COST arm_address_cost
412 #undef TARGET_SHIFT_TRUNCATION_MASK
413 #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask
414 #undef TARGET_VECTOR_MODE_SUPPORTED_P
415 #define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p
416 #undef TARGET_ARRAY_MODE_SUPPORTED_P
417 #define TARGET_ARRAY_MODE_SUPPORTED_P arm_array_mode_supported_p
418 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
419 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE arm_preferred_simd_mode
420 #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES
421 #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES \
422 arm_autovectorize_vector_sizes
424 #undef TARGET_MACHINE_DEPENDENT_REORG
425 #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg
427 #undef TARGET_INIT_BUILTINS
428 #define TARGET_INIT_BUILTINS arm_init_builtins
429 #undef TARGET_EXPAND_BUILTIN
430 #define TARGET_EXPAND_BUILTIN arm_expand_builtin
431 #undef TARGET_BUILTIN_DECL
432 #define TARGET_BUILTIN_DECL arm_builtin_decl
434 #undef TARGET_INIT_LIBFUNCS
435 #define TARGET_INIT_LIBFUNCS arm_init_libfuncs
437 #undef TARGET_PROMOTE_FUNCTION_MODE
438 #define TARGET_PROMOTE_FUNCTION_MODE arm_promote_function_mode
439 #undef TARGET_PROMOTE_PROTOTYPES
440 #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes
441 #undef TARGET_PASS_BY_REFERENCE
442 #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference
443 #undef TARGET_ARG_PARTIAL_BYTES
444 #define TARGET_ARG_PARTIAL_BYTES arm_arg_partial_bytes
445 #undef TARGET_FUNCTION_ARG
446 #define TARGET_FUNCTION_ARG arm_function_arg
447 #undef TARGET_FUNCTION_ARG_ADVANCE
448 #define TARGET_FUNCTION_ARG_ADVANCE arm_function_arg_advance
449 #undef TARGET_FUNCTION_ARG_BOUNDARY
450 #define TARGET_FUNCTION_ARG_BOUNDARY arm_function_arg_boundary
452 #undef TARGET_SETUP_INCOMING_VARARGS
453 #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs
455 #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
456 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args
458 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
459 #define TARGET_ASM_TRAMPOLINE_TEMPLATE arm_asm_trampoline_template
460 #undef TARGET_TRAMPOLINE_INIT
461 #define TARGET_TRAMPOLINE_INIT arm_trampoline_init
462 #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
463 #define TARGET_TRAMPOLINE_ADJUST_ADDRESS arm_trampoline_adjust_address
465 #undef TARGET_DEFAULT_SHORT_ENUMS
466 #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
468 #undef TARGET_ALIGN_ANON_BITFIELD
469 #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield
471 #undef TARGET_NARROW_VOLATILE_BITFIELD
472 #define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
474 #undef TARGET_CXX_GUARD_TYPE
475 #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type
477 #undef TARGET_CXX_GUARD_MASK_BIT
478 #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit
480 #undef TARGET_CXX_GET_COOKIE_SIZE
481 #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size
483 #undef TARGET_CXX_COOKIE_HAS_SIZE
484 #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size
486 #undef TARGET_CXX_CDTOR_RETURNS_THIS
487 #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this
489 #undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE
490 #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline
492 #undef TARGET_CXX_USE_AEABI_ATEXIT
493 #define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit
495 #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY
496 #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \
497 arm_cxx_determine_class_data_visibility
499 #undef TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT
500 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT arm_cxx_class_data_always_comdat
502 #undef TARGET_RETURN_IN_MSB
503 #define TARGET_RETURN_IN_MSB arm_return_in_msb
505 #undef TARGET_RETURN_IN_MEMORY
506 #define TARGET_RETURN_IN_MEMORY arm_return_in_memory
508 #undef TARGET_MUST_PASS_IN_STACK
509 #define TARGET_MUST_PASS_IN_STACK arm_must_pass_in_stack
512 #undef TARGET_ASM_UNWIND_EMIT
513 #define TARGET_ASM_UNWIND_EMIT arm_unwind_emit
515 /* EABI unwinding tables use a different format for the typeinfo tables. */
516 #undef TARGET_ASM_TTYPE
517 #define TARGET_ASM_TTYPE arm_output_ttype
519 #undef TARGET_ARM_EABI_UNWINDER
520 #define TARGET_ARM_EABI_UNWINDER true
522 #undef TARGET_ASM_EMIT_EXCEPT_PERSONALITY
523 #define TARGET_ASM_EMIT_EXCEPT_PERSONALITY arm_asm_emit_except_personality
525 #undef TARGET_ASM_INIT_SECTIONS
526 #define TARGET_ASM_INIT_SECTIONS arm_asm_init_sections
527 #endif /* ARM_UNWIND_INFO */
529 #undef TARGET_DWARF_REGISTER_SPAN
530 #define TARGET_DWARF_REGISTER_SPAN arm_dwarf_register_span
532 #undef TARGET_CANNOT_COPY_INSN_P
533 #define TARGET_CANNOT_COPY_INSN_P arm_cannot_copy_insn_p
536 #undef TARGET_HAVE_TLS
537 #define TARGET_HAVE_TLS true
540 #undef TARGET_HAVE_CONDITIONAL_EXECUTION
541 #define TARGET_HAVE_CONDITIONAL_EXECUTION arm_have_conditional_execution
543 #undef TARGET_LEGITIMATE_CONSTANT_P
544 #define TARGET_LEGITIMATE_CONSTANT_P arm_legitimate_constant_p
546 #undef TARGET_CANNOT_FORCE_CONST_MEM
547 #define TARGET_CANNOT_FORCE_CONST_MEM arm_cannot_force_const_mem
549 #undef TARGET_MAX_ANCHOR_OFFSET
550 #define TARGET_MAX_ANCHOR_OFFSET 4095
552 /* The minimum is set such that the total size of the block
553 for a particular anchor is -4088 + 1 + 4095 bytes, which is
554 divisible by eight, ensuring natural spacing of anchors. */
555 #undef TARGET_MIN_ANCHOR_OFFSET
556 #define TARGET_MIN_ANCHOR_OFFSET -4088
558 #undef TARGET_SCHED_ISSUE_RATE
559 #define TARGET_SCHED_ISSUE_RATE arm_issue_rate
561 #undef TARGET_MANGLE_TYPE
562 #define TARGET_MANGLE_TYPE arm_mangle_type
564 #undef TARGET_BUILD_BUILTIN_VA_LIST
565 #define TARGET_BUILD_BUILTIN_VA_LIST arm_build_builtin_va_list
566 #undef TARGET_EXPAND_BUILTIN_VA_START
567 #define TARGET_EXPAND_BUILTIN_VA_START arm_expand_builtin_va_start
568 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
569 #define TARGET_GIMPLIFY_VA_ARG_EXPR arm_gimplify_va_arg_expr
572 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
573 #define TARGET_ASM_OUTPUT_DWARF_DTPREL arm_output_dwarf_dtprel
576 #undef TARGET_LEGITIMATE_ADDRESS_P
577 #define TARGET_LEGITIMATE_ADDRESS_P arm_legitimate_address_p
579 #undef TARGET_INVALID_PARAMETER_TYPE
580 #define TARGET_INVALID_PARAMETER_TYPE arm_invalid_parameter_type
582 #undef TARGET_INVALID_RETURN_TYPE
583 #define TARGET_INVALID_RETURN_TYPE arm_invalid_return_type
585 #undef TARGET_PROMOTED_TYPE
586 #define TARGET_PROMOTED_TYPE arm_promoted_type
588 #undef TARGET_CONVERT_TO_TYPE
589 #define TARGET_CONVERT_TO_TYPE arm_convert_to_type
591 #undef TARGET_SCALAR_MODE_SUPPORTED_P
592 #define TARGET_SCALAR_MODE_SUPPORTED_P arm_scalar_mode_supported_p
594 #undef TARGET_FRAME_POINTER_REQUIRED
595 #define TARGET_FRAME_POINTER_REQUIRED arm_frame_pointer_required
597 #undef TARGET_CAN_ELIMINATE
598 #define TARGET_CAN_ELIMINATE arm_can_eliminate
600 #undef TARGET_CONDITIONAL_REGISTER_USAGE
601 #define TARGET_CONDITIONAL_REGISTER_USAGE arm_conditional_register_usage
603 #undef TARGET_CLASS_LIKELY_SPILLED_P
604 #define TARGET_CLASS_LIKELY_SPILLED_P arm_class_likely_spilled_p
606 #undef TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE
607 #define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE \
608 arm_vector_alignment_reachable
610 #undef TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT
611 #define TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT \
612 arm_builtin_support_vector_misalignment
614 #undef TARGET_PREFERRED_RENAME_CLASS
615 #define TARGET_PREFERRED_RENAME_CLASS \
616 arm_preferred_rename_class
618 #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
619 #define TARGET_VECTORIZE_VEC_PERM_CONST_OK \
620 arm_vectorize_vec_perm_const_ok
622 struct gcc_target targetm = TARGET_INITIALIZER;
624 /* Obstack for minipool constant handling. */
625 static struct obstack minipool_obstack;
626 static char * minipool_startobj;
628 /* The maximum number of insns skipped which
629 will be conditionalised if possible. */
630 static int max_insns_skipped = 5;
632 extern FILE * asm_out_file;
634 /* True if we are currently building a constant table. */
635 int making_const_table;
637 /* The processor for which instructions should be scheduled. */
638 enum processor_type arm_tune = arm_none;
640 /* The current tuning set. */
641 const struct tune_params *current_tune;
643 /* Which floating point hardware to schedule for. */
646 /* Which floating popint hardware to use. */
647 const struct arm_fpu_desc *arm_fpu_desc;
649 /* Used for Thumb call_via trampolines. */
650 rtx thumb_call_via_label[14];
651 static int thumb_call_reg_needed;
653 /* Bit values used to identify processor capabilities. */
654 #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */
655 #define FL_ARCH3M (1 << 1) /* Extended multiply */
656 #define FL_MODE26 (1 << 2) /* 26-bit mode support */
657 #define FL_MODE32 (1 << 3) /* 32-bit mode support */
658 #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */
659 #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */
660 #define FL_THUMB (1 << 6) /* Thumb aware */
661 #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */
662 #define FL_STRONG (1 << 8) /* StrongARM */
663 #define FL_ARCH5E (1 << 9) /* DSP extensions to v5 */
664 #define FL_XSCALE (1 << 10) /* XScale */
665 #define FL_CIRRUS (1 << 11) /* Cirrus/DSP. */
666 #define FL_ARCH6 (1 << 12) /* Architecture rel 6. Adds
667 media instructions. */
668 #define FL_VFPV2 (1 << 13) /* Vector Floating Point V2. */
669 #define FL_WBUF (1 << 14) /* Schedule for write buffer ops.
670 Note: ARM6 & 7 derivatives only. */
671 #define FL_ARCH6K (1 << 15) /* Architecture rel 6 K extensions. */
672 #define FL_THUMB2 (1 << 16) /* Thumb-2. */
673 #define FL_NOTM (1 << 17) /* Instructions not present in the 'M'
675 #define FL_THUMB_DIV (1 << 18) /* Hardware divide (Thumb mode). */
676 #define FL_VFPV3 (1 << 19) /* Vector Floating Point V3. */
677 #define FL_NEON (1 << 20) /* Neon instructions. */
678 #define FL_ARCH7EM (1 << 21) /* Instructions present in the ARMv7E-M
680 #define FL_ARCH7 (1 << 22) /* Architecture 7. */
681 #define FL_ARM_DIV (1 << 23) /* Hardware divide (ARM mode). */
683 #define FL_IWMMXT (1 << 29) /* XScale v2 or "Intel Wireless MMX technology". */
685 /* Flags that only effect tuning, not available instructions. */
686 #define FL_TUNE (FL_WBUF | FL_VFPV2 | FL_STRONG | FL_LDSCHED \
689 #define FL_FOR_ARCH2 FL_NOTM
690 #define FL_FOR_ARCH3 (FL_FOR_ARCH2 | FL_MODE32)
691 #define FL_FOR_ARCH3M (FL_FOR_ARCH3 | FL_ARCH3M)
692 #define FL_FOR_ARCH4 (FL_FOR_ARCH3M | FL_ARCH4)
693 #define FL_FOR_ARCH4T (FL_FOR_ARCH4 | FL_THUMB)
694 #define FL_FOR_ARCH5 (FL_FOR_ARCH4 | FL_ARCH5)
695 #define FL_FOR_ARCH5T (FL_FOR_ARCH5 | FL_THUMB)
696 #define FL_FOR_ARCH5E (FL_FOR_ARCH5 | FL_ARCH5E)
697 #define FL_FOR_ARCH5TE (FL_FOR_ARCH5E | FL_THUMB)
698 #define FL_FOR_ARCH5TEJ FL_FOR_ARCH5TE
699 #define FL_FOR_ARCH6 (FL_FOR_ARCH5TE | FL_ARCH6)
700 #define FL_FOR_ARCH6J FL_FOR_ARCH6
701 #define FL_FOR_ARCH6K (FL_FOR_ARCH6 | FL_ARCH6K)
702 #define FL_FOR_ARCH6Z FL_FOR_ARCH6
703 #define FL_FOR_ARCH6ZK FL_FOR_ARCH6K
704 #define FL_FOR_ARCH6T2 (FL_FOR_ARCH6 | FL_THUMB2)
705 #define FL_FOR_ARCH6M (FL_FOR_ARCH6 & ~FL_NOTM)
706 #define FL_FOR_ARCH7 ((FL_FOR_ARCH6T2 & ~FL_NOTM) | FL_ARCH7)
707 #define FL_FOR_ARCH7A (FL_FOR_ARCH7 | FL_NOTM | FL_ARCH6K)
708 #define FL_FOR_ARCH7R (FL_FOR_ARCH7A | FL_THUMB_DIV)
709 #define FL_FOR_ARCH7M (FL_FOR_ARCH7 | FL_THUMB_DIV)
710 #define FL_FOR_ARCH7EM (FL_FOR_ARCH7M | FL_ARCH7EM)
712 /* The bits in this mask specify which
713 instructions we are allowed to generate. */
714 static unsigned long insn_flags = 0;
716 /* The bits in this mask specify which instruction scheduling options should
718 static unsigned long tune_flags = 0;
720 /* The following are used in the arm.md file as equivalents to bits
721 in the above two flag variables. */
723 /* Nonzero if this chip supports the ARM Architecture 3M extensions. */
726 /* Nonzero if this chip supports the ARM Architecture 4 extensions. */
729 /* Nonzero if this chip supports the ARM Architecture 4t extensions. */
732 /* Nonzero if this chip supports the ARM Architecture 5 extensions. */
735 /* Nonzero if this chip supports the ARM Architecture 5E extensions. */
738 /* Nonzero if this chip supports the ARM Architecture 6 extensions. */
741 /* Nonzero if this chip supports the ARM 6K extensions. */
744 /* Nonzero if this chip supports the ARM 7 extensions. */
747 /* Nonzero if instructions not present in the 'M' profile can be used. */
748 int arm_arch_notm = 0;
750 /* Nonzero if instructions present in ARMv7E-M can be used. */
753 /* Nonzero if this chip can benefit from load scheduling. */
754 int arm_ld_sched = 0;
756 /* Nonzero if this chip is a StrongARM. */
757 int arm_tune_strongarm = 0;
759 /* Nonzero if this chip is a Cirrus variant. */
760 int arm_arch_cirrus = 0;
762 /* Nonzero if this chip supports Intel Wireless MMX technology. */
763 int arm_arch_iwmmxt = 0;
765 /* Nonzero if this chip is an XScale. */
766 int arm_arch_xscale = 0;
768 /* Nonzero if tuning for XScale */
769 int arm_tune_xscale = 0;
771 /* Nonzero if we want to tune for stores that access the write-buffer.
772 This typically means an ARM6 or ARM7 with MMU or MPU. */
773 int arm_tune_wbuf = 0;
775 /* Nonzero if tuning for Cortex-A9. */
776 int arm_tune_cortex_a9 = 0;
778 /* Nonzero if generating Thumb instructions. */
781 /* Nonzero if generating Thumb-1 instructions. */
784 /* Nonzero if we should define __THUMB_INTERWORK__ in the
786 XXX This is a bit of a hack, it's intended to help work around
787 problems in GLD which doesn't understand that armv5t code is
788 interworking clean. */
789 int arm_cpp_interwork = 0;
791 /* Nonzero if chip supports Thumb 2. */
794 /* Nonzero if chip supports integer division instruction. */
795 int arm_arch_arm_hwdiv;
796 int arm_arch_thumb_hwdiv;
798 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference,
799 we must report the mode of the memory reference from
800 TARGET_PRINT_OPERAND to TARGET_PRINT_OPERAND_ADDRESS. */
801 enum machine_mode output_memory_reference_mode;
803 /* The register number to be used for the PIC offset register. */
804 unsigned arm_pic_register = INVALID_REGNUM;
806 /* Set to 1 after arm_reorg has started. Reset to start at the start of
807 the next function. */
808 static int after_arm_reorg = 0;
810 enum arm_pcs arm_pcs_default;
812 /* For an explanation of these variables, see final_prescan_insn below. */
814 /* arm_current_cc is also used for Thumb-2 cond_exec blocks. */
815 enum arm_cond_code arm_current_cc;
818 int arm_target_label;
819 /* The number of conditionally executed insns, including the current insn. */
820 int arm_condexec_count = 0;
821 /* A bitmask specifying the patterns for the IT block.
822 Zero means do not output an IT block before this insn. */
823 int arm_condexec_mask = 0;
824 /* The number of bits used in arm_condexec_mask. */
825 int arm_condexec_masklen = 0;
827 /* The condition codes of the ARM, and the inverse function. */
828 static const char * const arm_condition_codes[] =
830 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
831 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
834 /* The register numbers in sequence, for passing to arm_gen_load_multiple. */
835 int arm_regs_in_sequence[] =
837 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
840 #define ARM_LSL_NAME (TARGET_UNIFIED_ASM ? "lsl" : "asl")
841 #define streq(string1, string2) (strcmp (string1, string2) == 0)
843 #define THUMB2_WORK_REGS (0xff & ~( (1 << THUMB_HARD_FRAME_POINTER_REGNUM) \
844 | (1 << SP_REGNUM) | (1 << PC_REGNUM) \
845 | (1 << PIC_OFFSET_TABLE_REGNUM)))
847 /* Initialization code. */
851 const char *const name;
852 enum processor_type core;
854 const unsigned long flags;
855 const struct tune_params *const tune;
859 #define ARM_PREFETCH_NOT_BENEFICIAL 0, -1, -1
860 #define ARM_PREFETCH_BENEFICIAL(prefetch_slots,l1_size,l1_line_size) \
865 const struct tune_params arm_slowmul_tune =
867 arm_slowmul_rtx_costs,
869 3, /* Constant limit. */
870 5, /* Max cond insns. */
871 ARM_PREFETCH_NOT_BENEFICIAL,
872 true, /* Prefer constant pool. */
873 arm_default_branch_cost
876 const struct tune_params arm_fastmul_tune =
878 arm_fastmul_rtx_costs,
880 1, /* Constant limit. */
881 5, /* Max cond insns. */
882 ARM_PREFETCH_NOT_BENEFICIAL,
883 true, /* Prefer constant pool. */
884 arm_default_branch_cost
887 /* StrongARM has early execution of branches, so a sequence that is worth
888 skipping is shorter. Set max_insns_skipped to a lower value. */
890 const struct tune_params arm_strongarm_tune =
892 arm_fastmul_rtx_costs,
894 1, /* Constant limit. */
895 3, /* Max cond insns. */
896 ARM_PREFETCH_NOT_BENEFICIAL,
897 true, /* Prefer constant pool. */
898 arm_default_branch_cost
901 const struct tune_params arm_xscale_tune =
903 arm_xscale_rtx_costs,
904 xscale_sched_adjust_cost,
905 2, /* Constant limit. */
906 3, /* Max cond insns. */
907 ARM_PREFETCH_NOT_BENEFICIAL,
908 true, /* Prefer constant pool. */
909 arm_default_branch_cost
912 const struct tune_params arm_9e_tune =
916 1, /* Constant limit. */
917 5, /* Max cond insns. */
918 ARM_PREFETCH_NOT_BENEFICIAL,
919 true, /* Prefer constant pool. */
920 arm_default_branch_cost
923 const struct tune_params arm_v6t2_tune =
927 1, /* Constant limit. */
928 5, /* Max cond insns. */
929 ARM_PREFETCH_NOT_BENEFICIAL,
930 false, /* Prefer constant pool. */
931 arm_default_branch_cost
934 /* Generic Cortex tuning. Use more specific tunings if appropriate. */
935 const struct tune_params arm_cortex_tune =
939 1, /* Constant limit. */
940 5, /* Max cond insns. */
941 ARM_PREFETCH_NOT_BENEFICIAL,
942 false, /* Prefer constant pool. */
943 arm_default_branch_cost
946 /* Branches can be dual-issued on Cortex-A5, so conditional execution is
947 less appealing. Set max_insns_skipped to a low value. */
949 const struct tune_params arm_cortex_a5_tune =
953 1, /* Constant limit. */
954 1, /* Max cond insns. */
955 ARM_PREFETCH_NOT_BENEFICIAL,
956 false, /* Prefer constant pool. */
957 arm_cortex_a5_branch_cost
960 const struct tune_params arm_cortex_a9_tune =
963 cortex_a9_sched_adjust_cost,
964 1, /* Constant limit. */
965 5, /* Max cond insns. */
966 ARM_PREFETCH_BENEFICIAL(4,32,32),
967 false, /* Prefer constant pool. */
968 arm_default_branch_cost
971 const struct tune_params arm_fa726te_tune =
974 fa726te_sched_adjust_cost,
975 1, /* Constant limit. */
976 5, /* Max cond insns. */
977 ARM_PREFETCH_NOT_BENEFICIAL,
978 true, /* Prefer constant pool. */
979 arm_default_branch_cost
983 /* Not all of these give usefully different compilation alternatives,
984 but there is no simple way of generalizing them. */
985 static const struct processors all_cores[] =
988 #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \
989 {NAME, IDENT, #ARCH, FLAGS | FL_FOR_ARCH##ARCH, &arm_##COSTS##_tune},
990 #include "arm-cores.def"
992 {NULL, arm_none, NULL, 0, NULL}
995 static const struct processors all_architectures[] =
997 /* ARM Architectures */
998 /* We don't specify tuning costs here as it will be figured out
1001 #define ARM_ARCH(NAME, CORE, ARCH, FLAGS) \
1002 {NAME, CORE, #ARCH, FLAGS, NULL},
1003 #include "arm-arches.def"
1005 {NULL, arm_none, NULL, 0 , NULL}
1009 /* These are populated as commandline arguments are processed, or NULL
1010 if not specified. */
1011 static const struct processors *arm_selected_arch;
1012 static const struct processors *arm_selected_cpu;
1013 static const struct processors *arm_selected_tune;
1015 /* The name of the preprocessor macro to define for this architecture. */
1017 char arm_arch_name[] = "__ARM_ARCH_0UNK__";
1019 /* Available values for -mfpu=. */
1021 static const struct arm_fpu_desc all_fpus[] =
1023 #define ARM_FPU(NAME, MODEL, REV, VFP_REGS, NEON, FP16) \
1024 { NAME, MODEL, REV, VFP_REGS, NEON, FP16 },
1025 #include "arm-fpus.def"
1030 /* Supported TLS relocations. */
1038 TLS_DESCSEQ /* GNU scheme */
1041 /* The maximum number of insns to be used when loading a constant. */
1043 arm_constant_limit (bool size_p)
1045 return size_p ? 1 : current_tune->constant_limit;
1048 /* Emit an insn that's a simple single-set. Both the operands must be known
1051 emit_set_insn (rtx x, rtx y)
1053 return emit_insn (gen_rtx_SET (VOIDmode, x, y));
1056 /* Return the number of bits set in VALUE. */
1058 bit_count (unsigned long value)
1060 unsigned long count = 0;
1065 value &= value - 1; /* Clear the least-significant set bit. */
1073 enum machine_mode mode;
1075 } arm_fixed_mode_set;
1077 /* A small helper for setting fixed-point library libfuncs. */
1080 arm_set_fixed_optab_libfunc (optab optable, enum machine_mode mode,
1081 const char *funcname, const char *modename,
1086 if (num_suffix == 0)
1087 sprintf (buffer, "__gnu_%s%s", funcname, modename);
1089 sprintf (buffer, "__gnu_%s%s%d", funcname, modename, num_suffix);
1091 set_optab_libfunc (optable, mode, buffer);
1095 arm_set_fixed_conv_libfunc (convert_optab optable, enum machine_mode to,
1096 enum machine_mode from, const char *funcname,
1097 const char *toname, const char *fromname)
1100 const char *maybe_suffix_2 = "";
1102 /* Follow the logic for selecting a "2" suffix in fixed-bit.h. */
1103 if (ALL_FIXED_POINT_MODE_P (from) && ALL_FIXED_POINT_MODE_P (to)
1104 && UNSIGNED_FIXED_POINT_MODE_P (from) == UNSIGNED_FIXED_POINT_MODE_P (to)
1105 && ALL_FRACT_MODE_P (from) == ALL_FRACT_MODE_P (to))
1106 maybe_suffix_2 = "2";
1108 sprintf (buffer, "__gnu_%s%s%s%s", funcname, fromname, toname,
1111 set_conv_libfunc (optable, to, from, buffer);
1114 /* Set up library functions unique to ARM. */
1117 arm_init_libfuncs (void)
1119 /* For Linux, we have access to kernel support for atomic operations. */
1120 if (arm_abi == ARM_ABI_AAPCS_LINUX)
1121 init_sync_libfuncs (2 * UNITS_PER_WORD);
1123 /* There are no special library functions unless we are using the
1128 /* The functions below are described in Section 4 of the "Run-Time
1129 ABI for the ARM architecture", Version 1.0. */
1131 /* Double-precision floating-point arithmetic. Table 2. */
1132 set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd");
1133 set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv");
1134 set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul");
1135 set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg");
1136 set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub");
1138 /* Double-precision comparisons. Table 3. */
1139 set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq");
1140 set_optab_libfunc (ne_optab, DFmode, NULL);
1141 set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt");
1142 set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple");
1143 set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge");
1144 set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt");
1145 set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun");
1147 /* Single-precision floating-point arithmetic. Table 4. */
1148 set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd");
1149 set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv");
1150 set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul");
1151 set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg");
1152 set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub");
1154 /* Single-precision comparisons. Table 5. */
1155 set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq");
1156 set_optab_libfunc (ne_optab, SFmode, NULL);
1157 set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt");
1158 set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple");
1159 set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge");
1160 set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt");
1161 set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun");
1163 /* Floating-point to integer conversions. Table 6. */
1164 set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz");
1165 set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz");
1166 set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz");
1167 set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz");
1168 set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz");
1169 set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz");
1170 set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz");
1171 set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz");
1173 /* Conversions between floating types. Table 7. */
1174 set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f");
1175 set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d");
1177 /* Integer to floating-point conversions. Table 8. */
1178 set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d");
1179 set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d");
1180 set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d");
1181 set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d");
1182 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f");
1183 set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f");
1184 set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f");
1185 set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f");
1187 /* Long long. Table 9. */
1188 set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul");
1189 set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod");
1190 set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod");
1191 set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl");
1192 set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr");
1193 set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr");
1194 set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp");
1195 set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp");
1197 /* Integer (32/32->32) division. \S 4.3.1. */
1198 set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod");
1199 set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod");
1201 /* The divmod functions are designed so that they can be used for
1202 plain division, even though they return both the quotient and the
1203 remainder. The quotient is returned in the usual location (i.e.,
1204 r0 for SImode, {r0, r1} for DImode), just as would be expected
1205 for an ordinary division routine. Because the AAPCS calling
1206 conventions specify that all of { r0, r1, r2, r3 } are
1207 callee-saved registers, there is no need to tell the compiler
1208 explicitly that those registers are clobbered by these
1210 set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod");
1211 set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod");
1213 /* For SImode division the ABI provides div-without-mod routines,
1214 which are faster. */
1215 set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idiv");
1216 set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidiv");
1218 /* We don't have mod libcalls. Fortunately gcc knows how to use the
1219 divmod libcalls instead. */
1220 set_optab_libfunc (smod_optab, DImode, NULL);
1221 set_optab_libfunc (umod_optab, DImode, NULL);
1222 set_optab_libfunc (smod_optab, SImode, NULL);
1223 set_optab_libfunc (umod_optab, SImode, NULL);
1225 /* Half-precision float operations. The compiler handles all operations
1226 with NULL libfuncs by converting the SFmode. */
1227 switch (arm_fp16_format)
1229 case ARM_FP16_FORMAT_IEEE:
1230 case ARM_FP16_FORMAT_ALTERNATIVE:
1233 set_conv_libfunc (trunc_optab, HFmode, SFmode,
1234 (arm_fp16_format == ARM_FP16_FORMAT_IEEE
1236 : "__gnu_f2h_alternative"));
1237 set_conv_libfunc (sext_optab, SFmode, HFmode,
1238 (arm_fp16_format == ARM_FP16_FORMAT_IEEE
1240 : "__gnu_h2f_alternative"));
1243 set_optab_libfunc (add_optab, HFmode, NULL);
1244 set_optab_libfunc (sdiv_optab, HFmode, NULL);
1245 set_optab_libfunc (smul_optab, HFmode, NULL);
1246 set_optab_libfunc (neg_optab, HFmode, NULL);
1247 set_optab_libfunc (sub_optab, HFmode, NULL);
1250 set_optab_libfunc (eq_optab, HFmode, NULL);
1251 set_optab_libfunc (ne_optab, HFmode, NULL);
1252 set_optab_libfunc (lt_optab, HFmode, NULL);
1253 set_optab_libfunc (le_optab, HFmode, NULL);
1254 set_optab_libfunc (ge_optab, HFmode, NULL);
1255 set_optab_libfunc (gt_optab, HFmode, NULL);
1256 set_optab_libfunc (unord_optab, HFmode, NULL);
1263 /* Use names prefixed with __gnu_ for fixed-point helper functions. */
1265 const arm_fixed_mode_set fixed_arith_modes[] =
1286 const arm_fixed_mode_set fixed_conv_modes[] =
1316 for (i = 0; i < ARRAY_SIZE (fixed_arith_modes); i++)
1318 arm_set_fixed_optab_libfunc (add_optab, fixed_arith_modes[i].mode,
1319 "add", fixed_arith_modes[i].name, 3);
1320 arm_set_fixed_optab_libfunc (ssadd_optab, fixed_arith_modes[i].mode,
1321 "ssadd", fixed_arith_modes[i].name, 3);
1322 arm_set_fixed_optab_libfunc (usadd_optab, fixed_arith_modes[i].mode,
1323 "usadd", fixed_arith_modes[i].name, 3);
1324 arm_set_fixed_optab_libfunc (sub_optab, fixed_arith_modes[i].mode,
1325 "sub", fixed_arith_modes[i].name, 3);
1326 arm_set_fixed_optab_libfunc (sssub_optab, fixed_arith_modes[i].mode,
1327 "sssub", fixed_arith_modes[i].name, 3);
1328 arm_set_fixed_optab_libfunc (ussub_optab, fixed_arith_modes[i].mode,
1329 "ussub", fixed_arith_modes[i].name, 3);
1330 arm_set_fixed_optab_libfunc (smul_optab, fixed_arith_modes[i].mode,
1331 "mul", fixed_arith_modes[i].name, 3);
1332 arm_set_fixed_optab_libfunc (ssmul_optab, fixed_arith_modes[i].mode,
1333 "ssmul", fixed_arith_modes[i].name, 3);
1334 arm_set_fixed_optab_libfunc (usmul_optab, fixed_arith_modes[i].mode,
1335 "usmul", fixed_arith_modes[i].name, 3);
1336 arm_set_fixed_optab_libfunc (sdiv_optab, fixed_arith_modes[i].mode,
1337 "div", fixed_arith_modes[i].name, 3);
1338 arm_set_fixed_optab_libfunc (udiv_optab, fixed_arith_modes[i].mode,
1339 "udiv", fixed_arith_modes[i].name, 3);
1340 arm_set_fixed_optab_libfunc (ssdiv_optab, fixed_arith_modes[i].mode,
1341 "ssdiv", fixed_arith_modes[i].name, 3);
1342 arm_set_fixed_optab_libfunc (usdiv_optab, fixed_arith_modes[i].mode,
1343 "usdiv", fixed_arith_modes[i].name, 3);
1344 arm_set_fixed_optab_libfunc (neg_optab, fixed_arith_modes[i].mode,
1345 "neg", fixed_arith_modes[i].name, 2);
1346 arm_set_fixed_optab_libfunc (ssneg_optab, fixed_arith_modes[i].mode,
1347 "ssneg", fixed_arith_modes[i].name, 2);
1348 arm_set_fixed_optab_libfunc (usneg_optab, fixed_arith_modes[i].mode,
1349 "usneg", fixed_arith_modes[i].name, 2);
1350 arm_set_fixed_optab_libfunc (ashl_optab, fixed_arith_modes[i].mode,
1351 "ashl", fixed_arith_modes[i].name, 3);
1352 arm_set_fixed_optab_libfunc (ashr_optab, fixed_arith_modes[i].mode,
1353 "ashr", fixed_arith_modes[i].name, 3);
1354 arm_set_fixed_optab_libfunc (lshr_optab, fixed_arith_modes[i].mode,
1355 "lshr", fixed_arith_modes[i].name, 3);
1356 arm_set_fixed_optab_libfunc (ssashl_optab, fixed_arith_modes[i].mode,
1357 "ssashl", fixed_arith_modes[i].name, 3);
1358 arm_set_fixed_optab_libfunc (usashl_optab, fixed_arith_modes[i].mode,
1359 "usashl", fixed_arith_modes[i].name, 3);
1360 arm_set_fixed_optab_libfunc (cmp_optab, fixed_arith_modes[i].mode,
1361 "cmp", fixed_arith_modes[i].name, 2);
1364 for (i = 0; i < ARRAY_SIZE (fixed_conv_modes); i++)
1365 for (j = 0; j < ARRAY_SIZE (fixed_conv_modes); j++)
1368 || (!ALL_FIXED_POINT_MODE_P (fixed_conv_modes[i].mode)
1369 && !ALL_FIXED_POINT_MODE_P (fixed_conv_modes[j].mode)))
1372 arm_set_fixed_conv_libfunc (fract_optab, fixed_conv_modes[i].mode,
1373 fixed_conv_modes[j].mode, "fract",
1374 fixed_conv_modes[i].name,
1375 fixed_conv_modes[j].name);
1376 arm_set_fixed_conv_libfunc (satfract_optab,
1377 fixed_conv_modes[i].mode,
1378 fixed_conv_modes[j].mode, "satfract",
1379 fixed_conv_modes[i].name,
1380 fixed_conv_modes[j].name);
1381 arm_set_fixed_conv_libfunc (fractuns_optab,
1382 fixed_conv_modes[i].mode,
1383 fixed_conv_modes[j].mode, "fractuns",
1384 fixed_conv_modes[i].name,
1385 fixed_conv_modes[j].name);
1386 arm_set_fixed_conv_libfunc (satfractuns_optab,
1387 fixed_conv_modes[i].mode,
1388 fixed_conv_modes[j].mode, "satfractuns",
1389 fixed_conv_modes[i].name,
1390 fixed_conv_modes[j].name);
1394 if (TARGET_AAPCS_BASED)
1395 synchronize_libfunc = init_one_libfunc ("__sync_synchronize");
1398 /* On AAPCS systems, this is the "struct __va_list". */
1399 static GTY(()) tree va_list_type;
1401 /* Return the type to use as __builtin_va_list. */
1403 arm_build_builtin_va_list (void)
1408 if (!TARGET_AAPCS_BASED)
1409 return std_build_builtin_va_list ();
1411 /* AAPCS \S 7.1.4 requires that va_list be a typedef for a type
1419 The C Library ABI further reinforces this definition in \S
1422 We must follow this definition exactly. The structure tag
1423 name is visible in C++ mangled names, and thus forms a part
1424 of the ABI. The field name may be used by people who
1425 #include <stdarg.h>. */
1426 /* Create the type. */
1427 va_list_type = lang_hooks.types.make_type (RECORD_TYPE);
1428 /* Give it the required name. */
1429 va_list_name = build_decl (BUILTINS_LOCATION,
1431 get_identifier ("__va_list"),
1433 DECL_ARTIFICIAL (va_list_name) = 1;
1434 TYPE_NAME (va_list_type) = va_list_name;
1435 TYPE_STUB_DECL (va_list_type) = va_list_name;
1436 /* Create the __ap field. */
1437 ap_field = build_decl (BUILTINS_LOCATION,
1439 get_identifier ("__ap"),
1441 DECL_ARTIFICIAL (ap_field) = 1;
1442 DECL_FIELD_CONTEXT (ap_field) = va_list_type;
1443 TYPE_FIELDS (va_list_type) = ap_field;
1444 /* Compute its layout. */
1445 layout_type (va_list_type);
1447 return va_list_type;
1450 /* Return an expression of type "void *" pointing to the next
1451 available argument in a variable-argument list. VALIST is the
1452 user-level va_list object, of type __builtin_va_list. */
1454 arm_extract_valist_ptr (tree valist)
1456 if (TREE_TYPE (valist) == error_mark_node)
1457 return error_mark_node;
1459 /* On an AAPCS target, the pointer is stored within "struct
1461 if (TARGET_AAPCS_BASED)
1463 tree ap_field = TYPE_FIELDS (TREE_TYPE (valist));
1464 valist = build3 (COMPONENT_REF, TREE_TYPE (ap_field),
1465 valist, ap_field, NULL_TREE);
1471 /* Implement TARGET_EXPAND_BUILTIN_VA_START. */
1473 arm_expand_builtin_va_start (tree valist, rtx nextarg)
1475 valist = arm_extract_valist_ptr (valist);
1476 std_expand_builtin_va_start (valist, nextarg);
1479 /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */
1481 arm_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
1484 valist = arm_extract_valist_ptr (valist);
1485 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
1488 /* Fix up any incompatible options that the user has specified. */
1490 arm_option_override (void)
1492 if (global_options_set.x_arm_arch_option)
1493 arm_selected_arch = &all_architectures[arm_arch_option];
1495 if (global_options_set.x_arm_cpu_option)
1496 arm_selected_cpu = &all_cores[(int) arm_cpu_option];
1498 if (global_options_set.x_arm_tune_option)
1499 arm_selected_tune = &all_cores[(int) arm_tune_option];
1501 #ifdef SUBTARGET_OVERRIDE_OPTIONS
1502 SUBTARGET_OVERRIDE_OPTIONS;
1505 if (arm_selected_arch)
1507 if (arm_selected_cpu)
1509 /* Check for conflict between mcpu and march. */
1510 if ((arm_selected_cpu->flags ^ arm_selected_arch->flags) & ~FL_TUNE)
1512 warning (0, "switch -mcpu=%s conflicts with -march=%s switch",
1513 arm_selected_cpu->name, arm_selected_arch->name);
1514 /* -march wins for code generation.
1515 -mcpu wins for default tuning. */
1516 if (!arm_selected_tune)
1517 arm_selected_tune = arm_selected_cpu;
1519 arm_selected_cpu = arm_selected_arch;
1523 arm_selected_arch = NULL;
1526 /* Pick a CPU based on the architecture. */
1527 arm_selected_cpu = arm_selected_arch;
1530 /* If the user did not specify a processor, choose one for them. */
1531 if (!arm_selected_cpu)
1533 const struct processors * sel;
1534 unsigned int sought;
1536 arm_selected_cpu = &all_cores[TARGET_CPU_DEFAULT];
1537 if (!arm_selected_cpu->name)
1539 #ifdef SUBTARGET_CPU_DEFAULT
1540 /* Use the subtarget default CPU if none was specified by
1542 arm_selected_cpu = &all_cores[SUBTARGET_CPU_DEFAULT];
1544 /* Default to ARM6. */
1545 if (!arm_selected_cpu->name)
1546 arm_selected_cpu = &all_cores[arm6];
1549 sel = arm_selected_cpu;
1550 insn_flags = sel->flags;
1552 /* Now check to see if the user has specified some command line
1553 switch that require certain abilities from the cpu. */
1556 if (TARGET_INTERWORK || TARGET_THUMB)
1558 sought |= (FL_THUMB | FL_MODE32);
1560 /* There are no ARM processors that support both APCS-26 and
1561 interworking. Therefore we force FL_MODE26 to be removed
1562 from insn_flags here (if it was set), so that the search
1563 below will always be able to find a compatible processor. */
1564 insn_flags &= ~FL_MODE26;
1567 if (sought != 0 && ((sought & insn_flags) != sought))
1569 /* Try to locate a CPU type that supports all of the abilities
1570 of the default CPU, plus the extra abilities requested by
1572 for (sel = all_cores; sel->name != NULL; sel++)
1573 if ((sel->flags & sought) == (sought | insn_flags))
1576 if (sel->name == NULL)
1578 unsigned current_bit_count = 0;
1579 const struct processors * best_fit = NULL;
1581 /* Ideally we would like to issue an error message here
1582 saying that it was not possible to find a CPU compatible
1583 with the default CPU, but which also supports the command
1584 line options specified by the programmer, and so they
1585 ought to use the -mcpu=<name> command line option to
1586 override the default CPU type.
1588 If we cannot find a cpu that has both the
1589 characteristics of the default cpu and the given
1590 command line options we scan the array again looking
1591 for a best match. */
1592 for (sel = all_cores; sel->name != NULL; sel++)
1593 if ((sel->flags & sought) == sought)
1597 count = bit_count (sel->flags & insn_flags);
1599 if (count >= current_bit_count)
1602 current_bit_count = count;
1606 gcc_assert (best_fit);
1610 arm_selected_cpu = sel;
1614 gcc_assert (arm_selected_cpu);
1615 /* The selected cpu may be an architecture, so lookup tuning by core ID. */
1616 if (!arm_selected_tune)
1617 arm_selected_tune = &all_cores[arm_selected_cpu->core];
1619 sprintf (arm_arch_name, "__ARM_ARCH_%s__", arm_selected_cpu->arch);
1620 insn_flags = arm_selected_cpu->flags;
1622 arm_tune = arm_selected_tune->core;
1623 tune_flags = arm_selected_tune->flags;
1624 current_tune = arm_selected_tune->tune;
1626 /* Make sure that the processor choice does not conflict with any of the
1627 other command line choices. */
1628 if (TARGET_ARM && !(insn_flags & FL_NOTM))
1629 error ("target CPU does not support ARM mode");
1631 /* BPABI targets use linker tricks to allow interworking on cores
1632 without thumb support. */
1633 if (TARGET_INTERWORK && !((insn_flags & FL_THUMB) || TARGET_BPABI))
1635 warning (0, "target CPU does not support interworking" );
1636 target_flags &= ~MASK_INTERWORK;
1639 if (TARGET_THUMB && !(insn_flags & FL_THUMB))
1641 warning (0, "target CPU does not support THUMB instructions");
1642 target_flags &= ~MASK_THUMB;
1645 if (TARGET_APCS_FRAME && TARGET_THUMB)
1647 /* warning (0, "ignoring -mapcs-frame because -mthumb was used"); */
1648 target_flags &= ~MASK_APCS_FRAME;
1651 /* Callee super interworking implies thumb interworking. Adding
1652 this to the flags here simplifies the logic elsewhere. */
1653 if (TARGET_THUMB && TARGET_CALLEE_INTERWORKING)
1654 target_flags |= MASK_INTERWORK;
1656 /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done
1657 from here where no function is being compiled currently. */
1658 if ((TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) && TARGET_ARM)
1659 warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb");
1661 if (TARGET_ARM && TARGET_CALLEE_INTERWORKING)
1662 warning (0, "enabling callee interworking support is only meaningful when compiling for the Thumb");
1664 if (TARGET_APCS_STACK && !TARGET_APCS_FRAME)
1666 warning (0, "-mapcs-stack-check incompatible with -mno-apcs-frame");
1667 target_flags |= MASK_APCS_FRAME;
1670 if (TARGET_POKE_FUNCTION_NAME)
1671 target_flags |= MASK_APCS_FRAME;
1673 if (TARGET_APCS_REENT && flag_pic)
1674 error ("-fpic and -mapcs-reent are incompatible");
1676 if (TARGET_APCS_REENT)
1677 warning (0, "APCS reentrant code not supported. Ignored");
1679 /* If this target is normally configured to use APCS frames, warn if they
1680 are turned off and debugging is turned on. */
1682 && write_symbols != NO_DEBUG
1683 && !TARGET_APCS_FRAME
1684 && (TARGET_DEFAULT & MASK_APCS_FRAME))
1685 warning (0, "-g with -mno-apcs-frame may not give sensible debugging");
1687 if (TARGET_APCS_FLOAT)
1688 warning (0, "passing floating point arguments in fp regs not yet supported");
1690 if (TARGET_LITTLE_WORDS)
1691 warning (OPT_Wdeprecated, "%<mwords-little-endian%> is deprecated and "
1692 "will be removed in a future release");
1694 /* Initialize boolean versions of the flags, for use in the arm.md file. */
1695 arm_arch3m = (insn_flags & FL_ARCH3M) != 0;
1696 arm_arch4 = (insn_flags & FL_ARCH4) != 0;
1697 arm_arch4t = arm_arch4 & ((insn_flags & FL_THUMB) != 0);
1698 arm_arch5 = (insn_flags & FL_ARCH5) != 0;
1699 arm_arch5e = (insn_flags & FL_ARCH5E) != 0;
1700 arm_arch6 = (insn_flags & FL_ARCH6) != 0;
1701 arm_arch6k = (insn_flags & FL_ARCH6K) != 0;
1702 arm_arch_notm = (insn_flags & FL_NOTM) != 0;
1703 arm_arch7 = (insn_flags & FL_ARCH7) != 0;
1704 arm_arch7em = (insn_flags & FL_ARCH7EM) != 0;
1705 arm_arch_thumb2 = (insn_flags & FL_THUMB2) != 0;
1706 arm_arch_xscale = (insn_flags & FL_XSCALE) != 0;
1707 arm_arch_cirrus = (insn_flags & FL_CIRRUS) != 0;
1709 arm_ld_sched = (tune_flags & FL_LDSCHED) != 0;
1710 arm_tune_strongarm = (tune_flags & FL_STRONG) != 0;
1711 thumb_code = TARGET_ARM == 0;
1712 thumb1_code = TARGET_THUMB1 != 0;
1713 arm_tune_wbuf = (tune_flags & FL_WBUF) != 0;
1714 arm_tune_xscale = (tune_flags & FL_XSCALE) != 0;
1715 arm_arch_iwmmxt = (insn_flags & FL_IWMMXT) != 0;
1716 arm_arch_thumb_hwdiv = (insn_flags & FL_THUMB_DIV) != 0;
1717 arm_arch_arm_hwdiv = (insn_flags & FL_ARM_DIV) != 0;
1718 arm_tune_cortex_a9 = (arm_tune == cortexa9) != 0;
1720 /* If we are not using the default (ARM mode) section anchor offset
1721 ranges, then set the correct ranges now. */
1724 /* Thumb-1 LDR instructions cannot have negative offsets.
1725 Permissible positive offset ranges are 5-bit (for byte loads),
1726 6-bit (for halfword loads), or 7-bit (for word loads).
1727 Empirical results suggest a 7-bit anchor range gives the best
1728 overall code size. */
1729 targetm.min_anchor_offset = 0;
1730 targetm.max_anchor_offset = 127;
1732 else if (TARGET_THUMB2)
1734 /* The minimum is set such that the total size of the block
1735 for a particular anchor is 248 + 1 + 4095 bytes, which is
1736 divisible by eight, ensuring natural spacing of anchors. */
1737 targetm.min_anchor_offset = -248;
1738 targetm.max_anchor_offset = 4095;
1741 /* V5 code we generate is completely interworking capable, so we turn off
1742 TARGET_INTERWORK here to avoid many tests later on. */
1744 /* XXX However, we must pass the right pre-processor defines to CPP
1745 or GLD can get confused. This is a hack. */
1746 if (TARGET_INTERWORK)
1747 arm_cpp_interwork = 1;
1750 target_flags &= ~MASK_INTERWORK;
1752 if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN)
1753 error ("iwmmxt requires an AAPCS compatible ABI for proper operation");
1755 if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT)
1756 error ("iwmmxt abi requires an iwmmxt capable cpu");
1758 if (!global_options_set.x_arm_fpu_index)
1760 const char *target_fpu_name;
1763 #ifdef FPUTYPE_DEFAULT
1764 target_fpu_name = FPUTYPE_DEFAULT;
1766 if (arm_arch_cirrus)
1767 target_fpu_name = "maverick";
1769 target_fpu_name = "fpe2";
1772 ok = opt_enum_arg_to_value (OPT_mfpu_, target_fpu_name, &arm_fpu_index,
1777 arm_fpu_desc = &all_fpus[arm_fpu_index];
1779 switch (arm_fpu_desc->model)
1781 case ARM_FP_MODEL_FPA:
1782 if (arm_fpu_desc->rev == 2)
1783 arm_fpu_attr = FPU_FPE2;
1784 else if (arm_fpu_desc->rev == 3)
1785 arm_fpu_attr = FPU_FPE3;
1787 arm_fpu_attr = FPU_FPA;
1790 case ARM_FP_MODEL_MAVERICK:
1791 arm_fpu_attr = FPU_MAVERICK;
1794 case ARM_FP_MODEL_VFP:
1795 arm_fpu_attr = FPU_VFP;
1802 if (TARGET_AAPCS_BASED
1803 && (arm_fpu_desc->model == ARM_FP_MODEL_FPA))
1804 error ("FPA is unsupported in the AAPCS");
1806 if (TARGET_AAPCS_BASED)
1808 if (TARGET_CALLER_INTERWORKING)
1809 error ("AAPCS does not support -mcaller-super-interworking");
1811 if (TARGET_CALLEE_INTERWORKING)
1812 error ("AAPCS does not support -mcallee-super-interworking");
1815 /* FPA and iWMMXt are incompatible because the insn encodings overlap.
1816 VFP and iWMMXt can theoretically coexist, but it's unlikely such silicon
1817 will ever exist. GCC makes no attempt to support this combination. */
1818 if (TARGET_IWMMXT && !TARGET_SOFT_FLOAT)
1819 sorry ("iWMMXt and hardware floating point");
1821 /* ??? iWMMXt insn patterns need auditing for Thumb-2. */
1822 if (TARGET_THUMB2 && TARGET_IWMMXT)
1823 sorry ("Thumb-2 iWMMXt");
1825 /* __fp16 support currently assumes the core has ldrh. */
1826 if (!arm_arch4 && arm_fp16_format != ARM_FP16_FORMAT_NONE)
1827 sorry ("__fp16 and no ldrh");
1829 /* If soft-float is specified then don't use FPU. */
1830 if (TARGET_SOFT_FLOAT)
1831 arm_fpu_attr = FPU_NONE;
1833 if (TARGET_AAPCS_BASED)
1835 if (arm_abi == ARM_ABI_IWMMXT)
1836 arm_pcs_default = ARM_PCS_AAPCS_IWMMXT;
1837 else if (arm_float_abi == ARM_FLOAT_ABI_HARD
1838 && TARGET_HARD_FLOAT
1840 arm_pcs_default = ARM_PCS_AAPCS_VFP;
1842 arm_pcs_default = ARM_PCS_AAPCS;
1846 if (arm_float_abi == ARM_FLOAT_ABI_HARD && TARGET_VFP)
1847 sorry ("-mfloat-abi=hard and VFP");
1849 if (arm_abi == ARM_ABI_APCS)
1850 arm_pcs_default = ARM_PCS_APCS;
1852 arm_pcs_default = ARM_PCS_ATPCS;
1855 /* For arm2/3 there is no need to do any scheduling if there is only
1856 a floating point emulator, or we are doing software floating-point. */
1857 if ((TARGET_SOFT_FLOAT
1858 || (TARGET_FPA && arm_fpu_desc->rev))
1859 && (tune_flags & FL_MODE32) == 0)
1860 flag_schedule_insns = flag_schedule_insns_after_reload = 0;
1862 /* Use the cp15 method if it is available. */
1863 if (target_thread_pointer == TP_AUTO)
1865 if (arm_arch6k && !TARGET_THUMB1)
1866 target_thread_pointer = TP_CP15;
1868 target_thread_pointer = TP_SOFT;
1871 if (TARGET_HARD_TP && TARGET_THUMB1)
1872 error ("can not use -mtp=cp15 with 16-bit Thumb");
1874 /* Override the default structure alignment for AAPCS ABI. */
1875 if (!global_options_set.x_arm_structure_size_boundary)
1877 if (TARGET_AAPCS_BASED)
1878 arm_structure_size_boundary = 8;
1882 if (arm_structure_size_boundary != 8
1883 && arm_structure_size_boundary != 32
1884 && !(ARM_DOUBLEWORD_ALIGN && arm_structure_size_boundary == 64))
1886 if (ARM_DOUBLEWORD_ALIGN)
1888 "structure size boundary can only be set to 8, 32 or 64");
1890 warning (0, "structure size boundary can only be set to 8 or 32");
1891 arm_structure_size_boundary
1892 = (TARGET_AAPCS_BASED ? 8 : DEFAULT_STRUCTURE_SIZE_BOUNDARY);
1896 if (!TARGET_ARM && TARGET_VXWORKS_RTP && flag_pic)
1898 error ("RTP PIC is incompatible with Thumb");
1902 /* If stack checking is disabled, we can use r10 as the PIC register,
1903 which keeps r9 available. The EABI specifies r9 as the PIC register. */
1904 if (flag_pic && TARGET_SINGLE_PIC_BASE)
1906 if (TARGET_VXWORKS_RTP)
1907 warning (0, "RTP PIC is incompatible with -msingle-pic-base");
1908 arm_pic_register = (TARGET_APCS_STACK || TARGET_AAPCS_BASED) ? 9 : 10;
1911 if (flag_pic && TARGET_VXWORKS_RTP)
1912 arm_pic_register = 9;
1914 if (arm_pic_register_string != NULL)
1916 int pic_register = decode_reg_name (arm_pic_register_string);
1919 warning (0, "-mpic-register= is useless without -fpic");
1921 /* Prevent the user from choosing an obviously stupid PIC register. */
1922 else if (pic_register < 0 || call_used_regs[pic_register]
1923 || pic_register == HARD_FRAME_POINTER_REGNUM
1924 || pic_register == STACK_POINTER_REGNUM
1925 || pic_register >= PC_REGNUM
1926 || (TARGET_VXWORKS_RTP
1927 && (unsigned int) pic_register != arm_pic_register))
1928 error ("unable to use '%s' for PIC register", arm_pic_register_string);
1930 arm_pic_register = pic_register;
1933 /* Enable -mfix-cortex-m3-ldrd by default for Cortex-M3 cores. */
1934 if (fix_cm3_ldrd == 2)
1936 if (arm_selected_cpu->core == cortexm3)
1942 /* Enable -munaligned-access by default for
1943 - all ARMv6 architecture-based processors
1944 - ARMv7-A, ARMv7-R, and ARMv7-M architecture-based processors.
1946 Disable -munaligned-access by default for
1947 - all pre-ARMv6 architecture-based processors
1948 - ARMv6-M architecture-based processors. */
1950 if (unaligned_access == 2)
1952 if (arm_arch6 && (arm_arch_notm || arm_arch7))
1953 unaligned_access = 1;
1955 unaligned_access = 0;
1957 else if (unaligned_access == 1
1958 && !(arm_arch6 && (arm_arch_notm || arm_arch7)))
1960 warning (0, "target CPU does not support unaligned accesses");
1961 unaligned_access = 0;
1964 if (TARGET_THUMB1 && flag_schedule_insns)
1966 /* Don't warn since it's on by default in -O2. */
1967 flag_schedule_insns = 0;
1972 /* If optimizing for size, bump the number of instructions that we
1973 are prepared to conditionally execute (even on a StrongARM). */
1974 max_insns_skipped = 6;
1977 max_insns_skipped = current_tune->max_insns_skipped;
1979 /* Hot/Cold partitioning is not currently supported, since we can't
1980 handle literal pool placement in that case. */
1981 if (flag_reorder_blocks_and_partition)
1983 inform (input_location,
1984 "-freorder-blocks-and-partition not supported on this architecture");
1985 flag_reorder_blocks_and_partition = 0;
1986 flag_reorder_blocks = 1;
1990 /* Hoisting PIC address calculations more aggressively provides a small,
1991 but measurable, size reduction for PIC code. Therefore, we decrease
1992 the bar for unrestricted expression hoisting to the cost of PIC address
1993 calculation, which is 2 instructions. */
1994 maybe_set_param_value (PARAM_GCSE_UNRESTRICTED_COST, 2,
1995 global_options.x_param_values,
1996 global_options_set.x_param_values);
1998 /* ARM EABI defaults to strict volatile bitfields. */
1999 if (TARGET_AAPCS_BASED && flag_strict_volatile_bitfields < 0
2000 && abi_version_at_least(2))
2001 flag_strict_volatile_bitfields = 1;
2003 /* Enable sw prefetching at -O3 for CPUS that have prefetch, and we have deemed
2004 it beneficial (signified by setting num_prefetch_slots to 1 or more.) */
2005 if (flag_prefetch_loop_arrays < 0
2008 && current_tune->num_prefetch_slots > 0)
2009 flag_prefetch_loop_arrays = 1;
2011 /* Set up parameters to be used in prefetching algorithm. Do not override the
2012 defaults unless we are tuning for a core we have researched values for. */
2013 if (current_tune->num_prefetch_slots > 0)
2014 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
2015 current_tune->num_prefetch_slots,
2016 global_options.x_param_values,
2017 global_options_set.x_param_values);
2018 if (current_tune->l1_cache_line_size >= 0)
2019 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE,
2020 current_tune->l1_cache_line_size,
2021 global_options.x_param_values,
2022 global_options_set.x_param_values);
2023 if (current_tune->l1_cache_size >= 0)
2024 maybe_set_param_value (PARAM_L1_CACHE_SIZE,
2025 current_tune->l1_cache_size,
2026 global_options.x_param_values,
2027 global_options_set.x_param_values);
2029 /* Register global variables with the garbage collector. */
2030 arm_add_gc_roots ();
2034 arm_add_gc_roots (void)
2036 gcc_obstack_init(&minipool_obstack);
2037 minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0);
2040 /* A table of known ARM exception types.
2041 For use with the interrupt function attribute. */
2045 const char *const arg;
2046 const unsigned long return_value;
2050 static const isr_attribute_arg isr_attribute_args [] =
2052 { "IRQ", ARM_FT_ISR },
2053 { "irq", ARM_FT_ISR },
2054 { "FIQ", ARM_FT_FIQ },
2055 { "fiq", ARM_FT_FIQ },
2056 { "ABORT", ARM_FT_ISR },
2057 { "abort", ARM_FT_ISR },
2058 { "ABORT", ARM_FT_ISR },
2059 { "abort", ARM_FT_ISR },
2060 { "UNDEF", ARM_FT_EXCEPTION },
2061 { "undef", ARM_FT_EXCEPTION },
2062 { "SWI", ARM_FT_EXCEPTION },
2063 { "swi", ARM_FT_EXCEPTION },
2064 { NULL, ARM_FT_NORMAL }
2067 /* Returns the (interrupt) function type of the current
2068 function, or ARM_FT_UNKNOWN if the type cannot be determined. */
2070 static unsigned long
2071 arm_isr_value (tree argument)
2073 const isr_attribute_arg * ptr;
2077 return ARM_FT_NORMAL | ARM_FT_STACKALIGN;
2079 /* No argument - default to IRQ. */
2080 if (argument == NULL_TREE)
2083 /* Get the value of the argument. */
2084 if (TREE_VALUE (argument) == NULL_TREE
2085 || TREE_CODE (TREE_VALUE (argument)) != STRING_CST)
2086 return ARM_FT_UNKNOWN;
2088 arg = TREE_STRING_POINTER (TREE_VALUE (argument));
2090 /* Check it against the list of known arguments. */
2091 for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)
2092 if (streq (arg, ptr->arg))
2093 return ptr->return_value;
2095 /* An unrecognized interrupt type. */
2096 return ARM_FT_UNKNOWN;
2099 /* Computes the type of the current function. */
2101 static unsigned long
2102 arm_compute_func_type (void)
2104 unsigned long type = ARM_FT_UNKNOWN;
2108 gcc_assert (TREE_CODE (current_function_decl) == FUNCTION_DECL);
2110 /* Decide if the current function is volatile. Such functions
2111 never return, and many memory cycles can be saved by not storing
2112 register values that will never be needed again. This optimization
2113 was added to speed up context switching in a kernel application. */
2115 && (TREE_NOTHROW (current_function_decl)
2116 || !(flag_unwind_tables
2118 && arm_except_unwind_info (&global_options) != UI_SJLJ)))
2119 && TREE_THIS_VOLATILE (current_function_decl))
2120 type |= ARM_FT_VOLATILE;
2122 if (cfun->static_chain_decl != NULL)
2123 type |= ARM_FT_NESTED;
2125 attr = DECL_ATTRIBUTES (current_function_decl);
2127 a = lookup_attribute ("naked", attr);
2129 type |= ARM_FT_NAKED;
2131 a = lookup_attribute ("isr", attr);
2133 a = lookup_attribute ("interrupt", attr);
2136 type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL;
2138 type |= arm_isr_value (TREE_VALUE (a));
2143 /* Returns the type of the current function. */
2146 arm_current_func_type (void)
2148 if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN)
2149 cfun->machine->func_type = arm_compute_func_type ();
2151 return cfun->machine->func_type;
2155 arm_allocate_stack_slots_for_args (void)
2157 /* Naked functions should not allocate stack slots for arguments. */
2158 return !IS_NAKED (arm_current_func_type ());
2162 /* Output assembler code for a block containing the constant parts
2163 of a trampoline, leaving space for the variable parts.
2165 On the ARM, (if r8 is the static chain regnum, and remembering that
2166 referencing pc adds an offset of 8) the trampoline looks like:
2169 .word static chain value
2170 .word function's address
2171 XXX FIXME: When the trampoline returns, r8 will be clobbered. */
2174 arm_asm_trampoline_template (FILE *f)
2178 asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", STATIC_CHAIN_REGNUM, PC_REGNUM);
2179 asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", PC_REGNUM, PC_REGNUM);
2181 else if (TARGET_THUMB2)
2183 /* The Thumb-2 trampoline is similar to the arm implementation.
2184 Unlike 16-bit Thumb, we enter the stub in thumb mode. */
2185 asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n",
2186 STATIC_CHAIN_REGNUM, PC_REGNUM);
2187 asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n", PC_REGNUM, PC_REGNUM);
2191 ASM_OUTPUT_ALIGN (f, 2);
2192 fprintf (f, "\t.code\t16\n");
2193 fprintf (f, ".Ltrampoline_start:\n");
2194 asm_fprintf (f, "\tpush\t{r0, r1}\n");
2195 asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM);
2196 asm_fprintf (f, "\tmov\t%r, r0\n", STATIC_CHAIN_REGNUM);
2197 asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM);
2198 asm_fprintf (f, "\tstr\tr0, [%r, #4]\n", SP_REGNUM);
2199 asm_fprintf (f, "\tpop\t{r0, %r}\n", PC_REGNUM);
2201 assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
2202 assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
2205 /* Emit RTL insns to initialize the variable parts of a trampoline. */
2208 arm_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
2210 rtx fnaddr, mem, a_tramp;
2212 emit_block_move (m_tramp, assemble_trampoline_template (),
2213 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
2215 mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 8 : 12);
2216 emit_move_insn (mem, chain_value);
2218 mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 12 : 16);
2219 fnaddr = XEXP (DECL_RTL (fndecl), 0);
2220 emit_move_insn (mem, fnaddr);
2222 a_tramp = XEXP (m_tramp, 0);
2223 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"),
2224 LCT_NORMAL, VOIDmode, 2, a_tramp, Pmode,
2225 plus_constant (a_tramp, TRAMPOLINE_SIZE), Pmode);
2228 /* Thumb trampolines should be entered in thumb mode, so set
2229 the bottom bit of the address. */
2232 arm_trampoline_adjust_address (rtx addr)
2235 addr = expand_simple_binop (Pmode, IOR, addr, const1_rtx,
2236 NULL, 0, OPTAB_LIB_WIDEN);
2240 /* Return 1 if it is possible to return using a single instruction.
2241 If SIBLING is non-null, this is a test for a return before a sibling
2242 call. SIBLING is the call insn, so we can examine its register usage. */
2245 use_return_insn (int iscond, rtx sibling)
2248 unsigned int func_type;
2249 unsigned long saved_int_regs;
2250 unsigned HOST_WIDE_INT stack_adjust;
2251 arm_stack_offsets *offsets;
2253 /* Never use a return instruction before reload has run. */
2254 if (!reload_completed)
2257 func_type = arm_current_func_type ();
2259 /* Naked, volatile and stack alignment functions need special
2261 if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED | ARM_FT_STACKALIGN))
2264 /* So do interrupt functions that use the frame pointer and Thumb
2265 interrupt functions. */
2266 if (IS_INTERRUPT (func_type) && (frame_pointer_needed || TARGET_THUMB))
2269 offsets = arm_get_frame_offsets ();
2270 stack_adjust = offsets->outgoing_args - offsets->saved_regs;
2272 /* As do variadic functions. */
2273 if (crtl->args.pretend_args_size
2274 || cfun->machine->uses_anonymous_args
2275 /* Or if the function calls __builtin_eh_return () */
2276 || crtl->calls_eh_return
2277 /* Or if the function calls alloca */
2278 || cfun->calls_alloca
2279 /* Or if there is a stack adjustment. However, if the stack pointer
2280 is saved on the stack, we can use a pre-incrementing stack load. */
2281 || !(stack_adjust == 0 || (TARGET_APCS_FRAME && frame_pointer_needed
2282 && stack_adjust == 4)))
2285 saved_int_regs = offsets->saved_regs_mask;
2287 /* Unfortunately, the insn
2289 ldmib sp, {..., sp, ...}
2291 triggers a bug on most SA-110 based devices, such that the stack
2292 pointer won't be correctly restored if the instruction takes a
2293 page fault. We work around this problem by popping r3 along with
2294 the other registers, since that is never slower than executing
2295 another instruction.
2297 We test for !arm_arch5 here, because code for any architecture
2298 less than this could potentially be run on one of the buggy
2300 if (stack_adjust == 4 && !arm_arch5 && TARGET_ARM)
2302 /* Validate that r3 is a call-clobbered register (always true in
2303 the default abi) ... */
2304 if (!call_used_regs[3])
2307 /* ... that it isn't being used for a return value ... */
2308 if (arm_size_return_regs () >= (4 * UNITS_PER_WORD))
2311 /* ... or for a tail-call argument ... */
2314 gcc_assert (GET_CODE (sibling) == CALL_INSN);
2316 if (find_regno_fusage (sibling, USE, 3))
2320 /* ... and that there are no call-saved registers in r0-r2
2321 (always true in the default ABI). */
2322 if (saved_int_regs & 0x7)
2326 /* Can't be done if interworking with Thumb, and any registers have been
2328 if (TARGET_INTERWORK && saved_int_regs != 0 && !IS_INTERRUPT(func_type))
2331 /* On StrongARM, conditional returns are expensive if they aren't
2332 taken and multiple registers have been stacked. */
2333 if (iscond && arm_tune_strongarm)
2335 /* Conditional return when just the LR is stored is a simple
2336 conditional-load instruction, that's not expensive. */
2337 if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM))
2341 && arm_pic_register != INVALID_REGNUM
2342 && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM))
2346 /* If there are saved registers but the LR isn't saved, then we need
2347 two instructions for the return. */
2348 if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM)))
2351 /* Can't be done if any of the FPA regs are pushed,
2352 since this also requires an insn. */
2353 if (TARGET_HARD_FLOAT && TARGET_FPA)
2354 for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++)
2355 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
2358 /* Likewise VFP regs. */
2359 if (TARGET_HARD_FLOAT && TARGET_VFP)
2360 for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++)
2361 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
2364 if (TARGET_REALLY_IWMMXT)
2365 for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++)
2366 if (df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2372 /* Return TRUE if int I is a valid immediate ARM constant. */
2375 const_ok_for_arm (HOST_WIDE_INT i)
2379 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
2380 be all zero, or all one. */
2381 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
2382 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
2383 != ((~(unsigned HOST_WIDE_INT) 0)
2384 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
2387 i &= (unsigned HOST_WIDE_INT) 0xffffffff;
2389 /* Fast return for 0 and small values. We must do this for zero, since
2390 the code below can't handle that one case. */
2391 if ((i & ~(unsigned HOST_WIDE_INT) 0xff) == 0)
2394 /* Get the number of trailing zeros. */
2395 lowbit = ffs((int) i) - 1;
2397 /* Only even shifts are allowed in ARM mode so round down to the
2398 nearest even number. */
2402 if ((i & ~(((unsigned HOST_WIDE_INT) 0xff) << lowbit)) == 0)
2407 /* Allow rotated constants in ARM mode. */
2409 && ((i & ~0xc000003f) == 0
2410 || (i & ~0xf000000f) == 0
2411 || (i & ~0xfc000003) == 0))
2418 /* Allow repeated patterns 0x00XY00XY or 0xXYXYXYXY. */
2421 if (i == v || i == (v | (v << 8)))
2424 /* Allow repeated pattern 0xXY00XY00. */
2434 /* Return true if I is a valid constant for the operation CODE. */
2436 const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code)
2438 if (const_ok_for_arm (i))
2444 /* See if we can use movw. */
2445 if (arm_arch_thumb2 && (i & 0xffff0000) == 0)
2448 /* Otherwise, try mvn. */
2449 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
2452 /* See if we can use addw or subw. */
2454 && ((i & 0xfffff000) == 0
2455 || ((-i) & 0xfffff000) == 0))
2457 /* else fall through. */
2477 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
2479 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
2485 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
2489 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
2496 /* Emit a sequence of insns to handle a large constant.
2497 CODE is the code of the operation required, it can be any of SET, PLUS,
2498 IOR, AND, XOR, MINUS;
2499 MODE is the mode in which the operation is being performed;
2500 VAL is the integer to operate on;
2501 SOURCE is the other operand (a register, or a null-pointer for SET);
2502 SUBTARGETS means it is safe to create scratch registers if that will
2503 either produce a simpler sequence, or we will want to cse the values.
2504 Return value is the number of insns emitted. */
2506 /* ??? Tweak this for thumb2. */
2508 arm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn,
2509 HOST_WIDE_INT val, rtx target, rtx source, int subtargets)
2513 if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC)
2514 cond = COND_EXEC_TEST (PATTERN (insn));
2518 if (subtargets || code == SET
2519 || (GET_CODE (target) == REG && GET_CODE (source) == REG
2520 && REGNO (target) != REGNO (source)))
2522 /* After arm_reorg has been called, we can't fix up expensive
2523 constants by pushing them into memory so we must synthesize
2524 them in-line, regardless of the cost. This is only likely to
2525 be more costly on chips that have load delay slots and we are
2526 compiling without running the scheduler (so no splitting
2527 occurred before the final instruction emission).
2529 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
2531 if (!after_arm_reorg
2533 && (arm_gen_constant (code, mode, NULL_RTX, val, target, source,
2535 > (arm_constant_limit (optimize_function_for_size_p (cfun))
2540 /* Currently SET is the only monadic value for CODE, all
2541 the rest are diadic. */
2542 if (TARGET_USE_MOVT)
2543 arm_emit_movpair (target, GEN_INT (val));
2545 emit_set_insn (target, GEN_INT (val));
2551 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
2553 if (TARGET_USE_MOVT)
2554 arm_emit_movpair (temp, GEN_INT (val));
2556 emit_set_insn (temp, GEN_INT (val));
2558 /* For MINUS, the value is subtracted from, since we never
2559 have subtraction of a constant. */
2561 emit_set_insn (target, gen_rtx_MINUS (mode, temp, source));
2563 emit_set_insn (target,
2564 gen_rtx_fmt_ee (code, mode, source, temp));
2570 return arm_gen_constant (code, mode, cond, val, target, source, subtargets,
2574 /* Return a sequence of integers, in RETURN_SEQUENCE that fit into
2575 ARM/THUMB2 immediates, and add up to VAL.
2576 Thr function return value gives the number of insns required. */
2578 optimal_immediate_sequence (enum rtx_code code, unsigned HOST_WIDE_INT val,
2579 struct four_ints *return_sequence)
2581 int best_consecutive_zeros = 0;
2585 struct four_ints tmp_sequence;
2587 /* If we aren't targetting ARM, the best place to start is always at
2588 the bottom, otherwise look more closely. */
2591 for (i = 0; i < 32; i += 2)
2593 int consecutive_zeros = 0;
2595 if (!(val & (3 << i)))
2597 while ((i < 32) && !(val & (3 << i)))
2599 consecutive_zeros += 2;
2602 if (consecutive_zeros > best_consecutive_zeros)
2604 best_consecutive_zeros = consecutive_zeros;
2605 best_start = i - consecutive_zeros;
2612 /* So long as it won't require any more insns to do so, it's
2613 desirable to emit a small constant (in bits 0...9) in the last
2614 insn. This way there is more chance that it can be combined with
2615 a later addressing insn to form a pre-indexed load or store
2616 operation. Consider:
2618 *((volatile int *)0xe0000100) = 1;
2619 *((volatile int *)0xe0000110) = 2;
2621 We want this to wind up as:
2625 str rB, [rA, #0x100]
2627 str rB, [rA, #0x110]
2629 rather than having to synthesize both large constants from scratch.
2631 Therefore, we calculate how many insns would be required to emit
2632 the constant starting from `best_start', and also starting from
2633 zero (i.e. with bit 31 first to be output). If `best_start' doesn't
2634 yield a shorter sequence, we may as well use zero. */
2635 insns1 = optimal_immediate_sequence_1 (code, val, return_sequence, best_start);
2637 && ((((unsigned HOST_WIDE_INT) 1) << best_start) < val))
2639 insns2 = optimal_immediate_sequence_1 (code, val, &tmp_sequence, 0);
2640 if (insns2 <= insns1)
2642 *return_sequence = tmp_sequence;
2650 /* As for optimal_immediate_sequence, but starting at bit-position I. */
2652 optimal_immediate_sequence_1 (enum rtx_code code, unsigned HOST_WIDE_INT val,
2653 struct four_ints *return_sequence, int i)
2655 int remainder = val & 0xffffffff;
2658 /* Try and find a way of doing the job in either two or three
2661 In ARM mode we can use 8-bit constants, rotated to any 2-bit aligned
2662 location. We start at position I. This may be the MSB, or
2663 optimial_immediate_sequence may have positioned it at the largest block
2664 of zeros that are aligned on a 2-bit boundary. We then fill up the temps,
2665 wrapping around to the top of the word when we drop off the bottom.
2666 In the worst case this code should produce no more than four insns.
2668 In Thumb2 mode, we can use 32/16-bit replicated constants, and 8-bit
2669 constants, shifted to any arbitrary location. We should always start
2674 unsigned int b1, b2, b3, b4;
2675 unsigned HOST_WIDE_INT result;
2678 gcc_assert (insns < 4);
2683 /* First, find the next normal 12/8-bit shifted/rotated immediate. */
2684 if (remainder & ((TARGET_ARM ? (3 << (i - 2)) : (1 << (i - 1)))))
2687 if (i <= 12 && TARGET_THUMB2 && code == PLUS)
2688 /* We can use addw/subw for the last 12 bits. */
2692 /* Use an 8-bit shifted/rotated immediate. */
2696 result = remainder & ((0x0ff << end)
2697 | ((i < end) ? (0xff >> (32 - end))
2704 /* Arm allows rotates by a multiple of two. Thumb-2 allows
2705 arbitrary shifts. */
2706 i -= TARGET_ARM ? 2 : 1;
2710 /* Next, see if we can do a better job with a thumb2 replicated
2713 We do it this way around to catch the cases like 0x01F001E0 where
2714 two 8-bit immediates would work, but a replicated constant would
2717 TODO: 16-bit constants that don't clear all the bits, but still win.
2718 TODO: Arithmetic splitting for set/add/sub, rather than bitwise. */
2721 b1 = (remainder & 0xff000000) >> 24;
2722 b2 = (remainder & 0x00ff0000) >> 16;
2723 b3 = (remainder & 0x0000ff00) >> 8;
2724 b4 = remainder & 0xff;
2728 /* The 8-bit immediate already found clears b1 (and maybe b2),
2729 but must leave b3 and b4 alone. */
2731 /* First try to find a 32-bit replicated constant that clears
2732 almost everything. We can assume that we can't do it in one,
2733 or else we wouldn't be here. */
2734 unsigned int tmp = b1 & b2 & b3 & b4;
2735 unsigned int tmp2 = tmp + (tmp << 8) + (tmp << 16)
2737 unsigned int matching_bytes = (tmp == b1) + (tmp == b2)
2738 + (tmp == b3) + (tmp == b4);
2740 && (matching_bytes >= 3
2741 || (matching_bytes == 2
2742 && const_ok_for_op (remainder & ~tmp2, code))))
2744 /* At least 3 of the bytes match, and the fourth has at
2745 least as many bits set, or two of the bytes match
2746 and it will only require one more insn to finish. */
2754 /* Second, try to find a 16-bit replicated constant that can
2755 leave three of the bytes clear. If b2 or b4 is already
2756 zero, then we can. If the 8-bit from above would not
2757 clear b2 anyway, then we still win. */
2758 else if (b1 == b3 && (!b2 || !b4
2759 || (remainder & 0x00ff0000 & ~result)))
2761 result = remainder & 0xff00ff00;
2767 /* The 8-bit immediate already found clears b2 (and maybe b3)
2768 and we don't get here unless b1 is alredy clear, but it will
2769 leave b4 unchanged. */
2771 /* If we can clear b2 and b4 at once, then we win, since the
2772 8-bits couldn't possibly reach that far. */
2775 result = remainder & 0x00ff00ff;
2781 return_sequence->i[insns++] = result;
2782 remainder &= ~result;
2784 if (code == SET || code == MINUS)
2792 /* Emit an instruction with the indicated PATTERN. If COND is
2793 non-NULL, conditionalize the execution of the instruction on COND
2797 emit_constant_insn (rtx cond, rtx pattern)
2800 pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern);
2801 emit_insn (pattern);
2804 /* As above, but extra parameter GENERATE which, if clear, suppresses
2808 arm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond,
2809 HOST_WIDE_INT val, rtx target, rtx source, int subtargets,
2814 int final_invert = 0;
2816 int set_sign_bit_copies = 0;
2817 int clear_sign_bit_copies = 0;
2818 int clear_zero_bit_copies = 0;
2819 int set_zero_bit_copies = 0;
2820 int insns = 0, neg_insns, inv_insns;
2821 unsigned HOST_WIDE_INT temp1, temp2;
2822 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
2823 struct four_ints *immediates;
2824 struct four_ints pos_immediates, neg_immediates, inv_immediates;
2826 /* Find out which operations are safe for a given CODE. Also do a quick
2827 check for degenerate cases; these can occur when DImode operations
2840 if (remainder == 0xffffffff)
2843 emit_constant_insn (cond,
2844 gen_rtx_SET (VOIDmode, target,
2845 GEN_INT (ARM_SIGN_EXTEND (val))));
2851 if (reload_completed && rtx_equal_p (target, source))
2855 emit_constant_insn (cond,
2856 gen_rtx_SET (VOIDmode, target, source));
2865 emit_constant_insn (cond,
2866 gen_rtx_SET (VOIDmode, target, const0_rtx));
2869 if (remainder == 0xffffffff)
2871 if (reload_completed && rtx_equal_p (target, source))
2874 emit_constant_insn (cond,
2875 gen_rtx_SET (VOIDmode, target, source));
2884 if (reload_completed && rtx_equal_p (target, source))
2887 emit_constant_insn (cond,
2888 gen_rtx_SET (VOIDmode, target, source));
2892 if (remainder == 0xffffffff)
2895 emit_constant_insn (cond,
2896 gen_rtx_SET (VOIDmode, target,
2897 gen_rtx_NOT (mode, source)));
2904 /* We treat MINUS as (val - source), since (source - val) is always
2905 passed as (source + (-val)). */
2909 emit_constant_insn (cond,
2910 gen_rtx_SET (VOIDmode, target,
2911 gen_rtx_NEG (mode, source)));
2914 if (const_ok_for_arm (val))
2917 emit_constant_insn (cond,
2918 gen_rtx_SET (VOIDmode, target,
2919 gen_rtx_MINUS (mode, GEN_INT (val),
2930 /* If we can do it in one insn get out quickly. */
2931 if (const_ok_for_op (val, code))
2934 emit_constant_insn (cond,
2935 gen_rtx_SET (VOIDmode, target,
2937 ? gen_rtx_fmt_ee (code, mode, source,
2943 /* Calculate a few attributes that may be useful for specific
2945 /* Count number of leading zeros. */
2946 for (i = 31; i >= 0; i--)
2948 if ((remainder & (1 << i)) == 0)
2949 clear_sign_bit_copies++;
2954 /* Count number of leading 1's. */
2955 for (i = 31; i >= 0; i--)
2957 if ((remainder & (1 << i)) != 0)
2958 set_sign_bit_copies++;
2963 /* Count number of trailing zero's. */
2964 for (i = 0; i <= 31; i++)
2966 if ((remainder & (1 << i)) == 0)
2967 clear_zero_bit_copies++;
2972 /* Count number of trailing 1's. */
2973 for (i = 0; i <= 31; i++)
2975 if ((remainder & (1 << i)) != 0)
2976 set_zero_bit_copies++;
2984 /* See if we can do this by sign_extending a constant that is known
2985 to be negative. This is a good, way of doing it, since the shift
2986 may well merge into a subsequent insn. */
2987 if (set_sign_bit_copies > 1)
2989 if (const_ok_for_arm
2990 (temp1 = ARM_SIGN_EXTEND (remainder
2991 << (set_sign_bit_copies - 1))))
2995 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2996 emit_constant_insn (cond,
2997 gen_rtx_SET (VOIDmode, new_src,
2999 emit_constant_insn (cond,
3000 gen_ashrsi3 (target, new_src,
3001 GEN_INT (set_sign_bit_copies - 1)));
3005 /* For an inverted constant, we will need to set the low bits,
3006 these will be shifted out of harm's way. */
3007 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
3008 if (const_ok_for_arm (~temp1))
3012 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3013 emit_constant_insn (cond,
3014 gen_rtx_SET (VOIDmode, new_src,
3016 emit_constant_insn (cond,
3017 gen_ashrsi3 (target, new_src,
3018 GEN_INT (set_sign_bit_copies - 1)));
3024 /* See if we can calculate the value as the difference between two
3025 valid immediates. */
3026 if (clear_sign_bit_copies + clear_zero_bit_copies <= 16)
3028 int topshift = clear_sign_bit_copies & ~1;
3030 temp1 = ARM_SIGN_EXTEND ((remainder + (0x00800000 >> topshift))
3031 & (0xff000000 >> topshift));
3033 /* If temp1 is zero, then that means the 9 most significant
3034 bits of remainder were 1 and we've caused it to overflow.
3035 When topshift is 0 we don't need to do anything since we
3036 can borrow from 'bit 32'. */
3037 if (temp1 == 0 && topshift != 0)
3038 temp1 = 0x80000000 >> (topshift - 1);
3040 temp2 = ARM_SIGN_EXTEND (temp1 - remainder);
3042 if (const_ok_for_arm (temp2))
3046 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3047 emit_constant_insn (cond,
3048 gen_rtx_SET (VOIDmode, new_src,
3050 emit_constant_insn (cond,
3051 gen_addsi3 (target, new_src,
3059 /* See if we can generate this by setting the bottom (or the top)
3060 16 bits, and then shifting these into the other half of the
3061 word. We only look for the simplest cases, to do more would cost
3062 too much. Be careful, however, not to generate this when the
3063 alternative would take fewer insns. */
3064 if (val & 0xffff0000)
3066 temp1 = remainder & 0xffff0000;
3067 temp2 = remainder & 0x0000ffff;
3069 /* Overlaps outside this range are best done using other methods. */
3070 for (i = 9; i < 24; i++)
3072 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
3073 && !const_ok_for_arm (temp2))
3075 rtx new_src = (subtargets
3076 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
3078 insns = arm_gen_constant (code, mode, cond, temp2, new_src,
3079 source, subtargets, generate);
3087 gen_rtx_ASHIFT (mode, source,
3094 /* Don't duplicate cases already considered. */
3095 for (i = 17; i < 24; i++)
3097 if (((temp1 | (temp1 >> i)) == remainder)
3098 && !const_ok_for_arm (temp1))
3100 rtx new_src = (subtargets
3101 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
3103 insns = arm_gen_constant (code, mode, cond, temp1, new_src,
3104 source, subtargets, generate);
3109 gen_rtx_SET (VOIDmode, target,
3112 gen_rtx_LSHIFTRT (mode, source,
3123 /* If we have IOR or XOR, and the constant can be loaded in a
3124 single instruction, and we can find a temporary to put it in,
3125 then this can be done in two instructions instead of 3-4. */
3127 /* TARGET can't be NULL if SUBTARGETS is 0 */
3128 || (reload_completed && !reg_mentioned_p (target, source)))
3130 if (const_ok_for_arm (ARM_SIGN_EXTEND (~val)))
3134 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3136 emit_constant_insn (cond,
3137 gen_rtx_SET (VOIDmode, sub,
3139 emit_constant_insn (cond,
3140 gen_rtx_SET (VOIDmode, target,
3141 gen_rtx_fmt_ee (code, mode,
3152 x = y | constant ( which is composed of set_sign_bit_copies of leading 1s
3153 and the remainder 0s for e.g. 0xfff00000)
3154 x = ~(~(y ashift set_sign_bit_copies) lshiftrt set_sign_bit_copies)
3156 This can be done in 2 instructions by using shifts with mov or mvn.
3161 mvn r0, r0, lsr #12 */
3162 if (set_sign_bit_copies > 8
3163 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
3167 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3168 rtx shift = GEN_INT (set_sign_bit_copies);
3172 gen_rtx_SET (VOIDmode, sub,
3174 gen_rtx_ASHIFT (mode,
3179 gen_rtx_SET (VOIDmode, target,
3181 gen_rtx_LSHIFTRT (mode, sub,
3188 x = y | constant (which has set_zero_bit_copies number of trailing ones).
3190 x = ~((~y lshiftrt set_zero_bit_copies) ashift set_zero_bit_copies).
3192 For eg. r0 = r0 | 0xfff
3197 if (set_zero_bit_copies > 8
3198 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
3202 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3203 rtx shift = GEN_INT (set_zero_bit_copies);
3207 gen_rtx_SET (VOIDmode, sub,
3209 gen_rtx_LSHIFTRT (mode,
3214 gen_rtx_SET (VOIDmode, target,
3216 gen_rtx_ASHIFT (mode, sub,
3222 /* This will never be reached for Thumb2 because orn is a valid
3223 instruction. This is for Thumb1 and the ARM 32 bit cases.
3225 x = y | constant (such that ~constant is a valid constant)
3227 x = ~(~y & ~constant).
3229 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val)))
3233 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
3234 emit_constant_insn (cond,
3235 gen_rtx_SET (VOIDmode, sub,
3236 gen_rtx_NOT (mode, source)));
3239 sub = gen_reg_rtx (mode);
3240 emit_constant_insn (cond,
3241 gen_rtx_SET (VOIDmode, sub,
3242 gen_rtx_AND (mode, source,
3244 emit_constant_insn (cond,
3245 gen_rtx_SET (VOIDmode, target,
3246 gen_rtx_NOT (mode, sub)));
3253 /* See if two shifts will do 2 or more insn's worth of work. */
3254 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
3256 HOST_WIDE_INT shift_mask = ((0xffffffff
3257 << (32 - clear_sign_bit_copies))
3260 if ((remainder | shift_mask) != 0xffffffff)
3264 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3265 insns = arm_gen_constant (AND, mode, cond,
3266 remainder | shift_mask,
3267 new_src, source, subtargets, 1);
3272 rtx targ = subtargets ? NULL_RTX : target;
3273 insns = arm_gen_constant (AND, mode, cond,
3274 remainder | shift_mask,
3275 targ, source, subtargets, 0);
3281 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3282 rtx shift = GEN_INT (clear_sign_bit_copies);
3284 emit_insn (gen_ashlsi3 (new_src, source, shift));
3285 emit_insn (gen_lshrsi3 (target, new_src, shift));
3291 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
3293 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
3295 if ((remainder | shift_mask) != 0xffffffff)
3299 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3301 insns = arm_gen_constant (AND, mode, cond,
3302 remainder | shift_mask,
3303 new_src, source, subtargets, 1);
3308 rtx targ = subtargets ? NULL_RTX : target;
3310 insns = arm_gen_constant (AND, mode, cond,
3311 remainder | shift_mask,
3312 targ, source, subtargets, 0);
3318 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
3319 rtx shift = GEN_INT (clear_zero_bit_copies);
3321 emit_insn (gen_lshrsi3 (new_src, source, shift));
3322 emit_insn (gen_ashlsi3 (target, new_src, shift));
3334 /* Calculate what the instruction sequences would be if we generated it
3335 normally, negated, or inverted. */
3337 /* AND cannot be split into multiple insns, so invert and use BIC. */
3340 insns = optimal_immediate_sequence (code, remainder, &pos_immediates);
3343 neg_insns = optimal_immediate_sequence (code, (-remainder) & 0xffffffff,
3348 if (can_invert || final_invert)
3349 inv_insns = optimal_immediate_sequence (code, remainder ^ 0xffffffff,
3354 immediates = &pos_immediates;
3356 /* Is the negated immediate sequence more efficient? */
3357 if (neg_insns < insns && neg_insns <= inv_insns)
3360 immediates = &neg_immediates;
3365 /* Is the inverted immediate sequence more efficient?
3366 We must allow for an extra NOT instruction for XOR operations, although
3367 there is some chance that the final 'mvn' will get optimized later. */
3368 if ((inv_insns + 1) < insns || (!final_invert && inv_insns < insns))
3371 immediates = &inv_immediates;
3379 /* Now output the chosen sequence as instructions. */
3382 for (i = 0; i < insns; i++)
3384 rtx new_src, temp1_rtx;
3386 temp1 = immediates->i[i];
3388 if (code == SET || code == MINUS)
3389 new_src = (subtargets ? gen_reg_rtx (mode) : target);
3390 else if ((final_invert || i < (insns - 1)) && subtargets)
3391 new_src = gen_reg_rtx (mode);
3397 else if (can_negate)
3400 temp1 = trunc_int_for_mode (temp1, mode);
3401 temp1_rtx = GEN_INT (temp1);
3405 else if (code == MINUS)
3406 temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source);
3408 temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx);
3410 emit_constant_insn (cond,
3411 gen_rtx_SET (VOIDmode, new_src,
3417 can_negate = can_invert;
3421 else if (code == MINUS)
3429 emit_constant_insn (cond, gen_rtx_SET (VOIDmode, target,
3430 gen_rtx_NOT (mode, source)));
3437 /* Canonicalize a comparison so that we are more likely to recognize it.
3438 This can be done for a few constant compares, where we can make the
3439 immediate value easier to load. */
3442 arm_canonicalize_comparison (enum rtx_code code, rtx *op0, rtx *op1)
3444 enum machine_mode mode;
3445 unsigned HOST_WIDE_INT i, maxval;
3447 mode = GET_MODE (*op0);
3448 if (mode == VOIDmode)
3449 mode = GET_MODE (*op1);
3451 maxval = (((unsigned HOST_WIDE_INT) 1) << (GET_MODE_BITSIZE(mode) - 1)) - 1;
3453 /* For DImode, we have GE/LT/GEU/LTU comparisons. In ARM mode
3454 we can also use cmp/cmpeq for GTU/LEU. GT/LE must be either
3455 reversed or (for constant OP1) adjusted to GE/LT. Similarly
3456 for GTU/LEU in Thumb mode. */
3461 /* To keep things simple, always use the Cirrus cfcmp64 if it is
3463 if (TARGET_ARM && TARGET_HARD_FLOAT && TARGET_MAVERICK)
3466 if (code == GT || code == LE
3467 || (!TARGET_ARM && (code == GTU || code == LEU)))
3469 /* Missing comparison. First try to use an available
3471 if (GET_CODE (*op1) == CONST_INT)
3479 && arm_const_double_by_immediates (GEN_INT (i + 1)))
3481 *op1 = GEN_INT (i + 1);
3482 return code == GT ? GE : LT;
3487 if (i != ~((unsigned HOST_WIDE_INT) 0)
3488 && arm_const_double_by_immediates (GEN_INT (i + 1)))
3490 *op1 = GEN_INT (i + 1);
3491 return code == GTU ? GEU : LTU;
3499 /* If that did not work, reverse the condition. */
3503 return swap_condition (code);
3509 /* If *op0 is (zero_extend:SI (subreg:QI (reg:SI) 0)) and comparing
3510 with const0_rtx, change it to (and:SI (reg:SI) (const_int 255)),
3511 to facilitate possible combining with a cmp into 'ands'. */
3513 && GET_CODE (*op0) == ZERO_EXTEND
3514 && GET_CODE (XEXP (*op0, 0)) == SUBREG
3515 && GET_MODE (XEXP (*op0, 0)) == QImode
3516 && GET_MODE (SUBREG_REG (XEXP (*op0, 0))) == SImode
3517 && subreg_lowpart_p (XEXP (*op0, 0))
3518 && *op1 == const0_rtx)
3519 *op0 = gen_rtx_AND (SImode, SUBREG_REG (XEXP (*op0, 0)),
3522 /* Comparisons smaller than DImode. Only adjust comparisons against
3523 an out-of-range constant. */
3524 if (GET_CODE (*op1) != CONST_INT
3525 || const_ok_for_arm (INTVAL (*op1))
3526 || const_ok_for_arm (- INTVAL (*op1)))
3540 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
3542 *op1 = GEN_INT (i + 1);
3543 return code == GT ? GE : LT;
3550 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
3552 *op1 = GEN_INT (i - 1);
3553 return code == GE ? GT : LE;
3559 if (i != ~((unsigned HOST_WIDE_INT) 0)
3560 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
3562 *op1 = GEN_INT (i + 1);
3563 return code == GTU ? GEU : LTU;
3570 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
3572 *op1 = GEN_INT (i - 1);
3573 return code == GEU ? GTU : LEU;
3585 /* Define how to find the value returned by a function. */
3588 arm_function_value(const_tree type, const_tree func,
3589 bool outgoing ATTRIBUTE_UNUSED)
3591 enum machine_mode mode;
3592 int unsignedp ATTRIBUTE_UNUSED;
3593 rtx r ATTRIBUTE_UNUSED;
3595 mode = TYPE_MODE (type);
3597 if (TARGET_AAPCS_BASED)
3598 return aapcs_allocate_return_reg (mode, type, func);
3600 /* Promote integer types. */
3601 if (INTEGRAL_TYPE_P (type))
3602 mode = arm_promote_function_mode (type, mode, &unsignedp, func, 1);
3604 /* Promotes small structs returned in a register to full-word size
3605 for big-endian AAPCS. */
3606 if (arm_return_in_msb (type))
3608 HOST_WIDE_INT size = int_size_in_bytes (type);
3609 if (size % UNITS_PER_WORD != 0)
3611 size += UNITS_PER_WORD - size % UNITS_PER_WORD;
3612 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
3616 return arm_libcall_value_1 (mode);
3620 libcall_eq (const void *p1, const void *p2)
3622 return rtx_equal_p ((const_rtx) p1, (const_rtx) p2);
3626 libcall_hash (const void *p1)
3628 return hash_rtx ((const_rtx) p1, VOIDmode, NULL, NULL, FALSE);
3632 add_libcall (htab_t htab, rtx libcall)
3634 *htab_find_slot (htab, libcall, INSERT) = libcall;
3638 arm_libcall_uses_aapcs_base (const_rtx libcall)
3640 static bool init_done = false;
3641 static htab_t libcall_htab;
3647 libcall_htab = htab_create (31, libcall_hash, libcall_eq,
3649 add_libcall (libcall_htab,
3650 convert_optab_libfunc (sfloat_optab, SFmode, SImode));
3651 add_libcall (libcall_htab,
3652 convert_optab_libfunc (sfloat_optab, DFmode, SImode));
3653 add_libcall (libcall_htab,
3654 convert_optab_libfunc (sfloat_optab, SFmode, DImode));
3655 add_libcall (libcall_htab,
3656 convert_optab_libfunc (sfloat_optab, DFmode, DImode));
3658 add_libcall (libcall_htab,
3659 convert_optab_libfunc (ufloat_optab, SFmode, SImode));
3660 add_libcall (libcall_htab,
3661 convert_optab_libfunc (ufloat_optab, DFmode, SImode));
3662 add_libcall (libcall_htab,
3663 convert_optab_libfunc (ufloat_optab, SFmode, DImode));
3664 add_libcall (libcall_htab,
3665 convert_optab_libfunc (ufloat_optab, DFmode, DImode));
3667 add_libcall (libcall_htab,
3668 convert_optab_libfunc (sext_optab, SFmode, HFmode));
3669 add_libcall (libcall_htab,
3670 convert_optab_libfunc (trunc_optab, HFmode, SFmode));
3671 add_libcall (libcall_htab,
3672 convert_optab_libfunc (sfix_optab, SImode, DFmode));
3673 add_libcall (libcall_htab,
3674 convert_optab_libfunc (ufix_optab, SImode, DFmode));
3675 add_libcall (libcall_htab,
3676 convert_optab_libfunc (sfix_optab, DImode, DFmode));
3677 add_libcall (libcall_htab,
3678 convert_optab_libfunc (ufix_optab, DImode, DFmode));
3679 add_libcall (libcall_htab,
3680 convert_optab_libfunc (sfix_optab, DImode, SFmode));
3681 add_libcall (libcall_htab,
3682 convert_optab_libfunc (ufix_optab, DImode, SFmode));
3684 /* Values from double-precision helper functions are returned in core
3685 registers if the selected core only supports single-precision
3686 arithmetic, even if we are using the hard-float ABI. The same is
3687 true for single-precision helpers, but we will never be using the
3688 hard-float ABI on a CPU which doesn't support single-precision
3689 operations in hardware. */
3690 add_libcall (libcall_htab, optab_libfunc (add_optab, DFmode));
3691 add_libcall (libcall_htab, optab_libfunc (sdiv_optab, DFmode));
3692 add_libcall (libcall_htab, optab_libfunc (smul_optab, DFmode));
3693 add_libcall (libcall_htab, optab_libfunc (neg_optab, DFmode));
3694 add_libcall (libcall_htab, optab_libfunc (sub_optab, DFmode));
3695 add_libcall (libcall_htab, optab_libfunc (eq_optab, DFmode));
3696 add_libcall (libcall_htab, optab_libfunc (lt_optab, DFmode));
3697 add_libcall (libcall_htab, optab_libfunc (le_optab, DFmode));
3698 add_libcall (libcall_htab, optab_libfunc (ge_optab, DFmode));
3699 add_libcall (libcall_htab, optab_libfunc (gt_optab, DFmode));
3700 add_libcall (libcall_htab, optab_libfunc (unord_optab, DFmode));
3701 add_libcall (libcall_htab, convert_optab_libfunc (sext_optab, DFmode,
3703 add_libcall (libcall_htab, convert_optab_libfunc (trunc_optab, SFmode,
3707 return libcall && htab_find (libcall_htab, libcall) != NULL;
3711 arm_libcall_value_1 (enum machine_mode mode)
3713 if (TARGET_AAPCS_BASED)
3714 return aapcs_libcall_value (mode);
3715 else if (TARGET_32BIT
3716 && TARGET_HARD_FLOAT_ABI
3718 && GET_MODE_CLASS (mode) == MODE_FLOAT)
3719 return gen_rtx_REG (mode, FIRST_FPA_REGNUM);
3720 else if (TARGET_32BIT
3721 && TARGET_HARD_FLOAT_ABI
3723 && GET_MODE_CLASS (mode) == MODE_FLOAT)
3724 return gen_rtx_REG (mode, FIRST_CIRRUS_FP_REGNUM);
3725 else if (TARGET_IWMMXT_ABI
3726 && arm_vector_mode_supported_p (mode))
3727 return gen_rtx_REG (mode, FIRST_IWMMXT_REGNUM);
3729 return gen_rtx_REG (mode, ARG_REGISTER (1));
3732 /* Define how to find the value returned by a library function
3733 assuming the value has mode MODE. */
3736 arm_libcall_value (enum machine_mode mode, const_rtx libcall)
3738 if (TARGET_AAPCS_BASED && arm_pcs_default != ARM_PCS_AAPCS
3739 && GET_MODE_CLASS (mode) == MODE_FLOAT)
3741 /* The following libcalls return their result in integer registers,
3742 even though they return a floating point value. */
3743 if (arm_libcall_uses_aapcs_base (libcall))
3744 return gen_rtx_REG (mode, ARG_REGISTER(1));
3748 return arm_libcall_value_1 (mode);
3751 /* Implement TARGET_FUNCTION_VALUE_REGNO_P. */
3754 arm_function_value_regno_p (const unsigned int regno)
3756 if (regno == ARG_REGISTER (1)
3758 && TARGET_AAPCS_BASED
3760 && TARGET_HARD_FLOAT
3761 && regno == FIRST_VFP_REGNUM)
3763 && TARGET_HARD_FLOAT_ABI
3765 && regno == FIRST_CIRRUS_FP_REGNUM)
3766 || (TARGET_IWMMXT_ABI
3767 && regno == FIRST_IWMMXT_REGNUM)
3769 && TARGET_HARD_FLOAT_ABI
3771 && regno == FIRST_FPA_REGNUM))
3777 /* Determine the amount of memory needed to store the possible return
3778 registers of an untyped call. */
3780 arm_apply_result_size (void)
3786 if (TARGET_HARD_FLOAT_ABI)
3792 if (TARGET_MAVERICK)
3795 if (TARGET_IWMMXT_ABI)
3802 /* Decide whether TYPE should be returned in memory (true)
3803 or in a register (false). FNTYPE is the type of the function making
3806 arm_return_in_memory (const_tree type, const_tree fntype)
3810 size = int_size_in_bytes (type); /* Negative if not fixed size. */
3812 if (TARGET_AAPCS_BASED)
3814 /* Simple, non-aggregate types (ie not including vectors and
3815 complex) are always returned in a register (or registers).
3816 We don't care about which register here, so we can short-cut
3817 some of the detail. */
3818 if (!AGGREGATE_TYPE_P (type)
3819 && TREE_CODE (type) != VECTOR_TYPE
3820 && TREE_CODE (type) != COMPLEX_TYPE)
3823 /* Any return value that is no larger than one word can be
3825 if (((unsigned HOST_WIDE_INT) size) <= UNITS_PER_WORD)
3828 /* Check any available co-processors to see if they accept the
3829 type as a register candidate (VFP, for example, can return
3830 some aggregates in consecutive registers). These aren't
3831 available if the call is variadic. */
3832 if (aapcs_select_return_coproc (type, fntype) >= 0)
3835 /* Vector values should be returned using ARM registers, not
3836 memory (unless they're over 16 bytes, which will break since
3837 we only have four call-clobbered registers to play with). */
3838 if (TREE_CODE (type) == VECTOR_TYPE)
3839 return (size < 0 || size > (4 * UNITS_PER_WORD));
3841 /* The rest go in memory. */
3845 if (TREE_CODE (type) == VECTOR_TYPE)
3846 return (size < 0 || size > (4 * UNITS_PER_WORD));
3848 if (!AGGREGATE_TYPE_P (type) &&
3849 (TREE_CODE (type) != VECTOR_TYPE))
3850 /* All simple types are returned in registers. */
3853 if (arm_abi != ARM_ABI_APCS)
3855 /* ATPCS and later return aggregate types in memory only if they are
3856 larger than a word (or are variable size). */
3857 return (size < 0 || size > UNITS_PER_WORD);
3860 /* For the arm-wince targets we choose to be compatible with Microsoft's
3861 ARM and Thumb compilers, which always return aggregates in memory. */
3863 /* All structures/unions bigger than one word are returned in memory.
3864 Also catch the case where int_size_in_bytes returns -1. In this case
3865 the aggregate is either huge or of variable size, and in either case
3866 we will want to return it via memory and not in a register. */
3867 if (size < 0 || size > UNITS_PER_WORD)
3870 if (TREE_CODE (type) == RECORD_TYPE)
3874 /* For a struct the APCS says that we only return in a register
3875 if the type is 'integer like' and every addressable element
3876 has an offset of zero. For practical purposes this means
3877 that the structure can have at most one non bit-field element
3878 and that this element must be the first one in the structure. */
3880 /* Find the first field, ignoring non FIELD_DECL things which will
3881 have been created by C++. */
3882 for (field = TYPE_FIELDS (type);
3883 field && TREE_CODE (field) != FIELD_DECL;
3884 field = DECL_CHAIN (field))
3888 return false; /* An empty structure. Allowed by an extension to ANSI C. */
3890 /* Check that the first field is valid for returning in a register. */
3892 /* ... Floats are not allowed */
3893 if (FLOAT_TYPE_P (TREE_TYPE (field)))
3896 /* ... Aggregates that are not themselves valid for returning in
3897 a register are not allowed. */
3898 if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE))
3901 /* Now check the remaining fields, if any. Only bitfields are allowed,
3902 since they are not addressable. */
3903 for (field = DECL_CHAIN (field);
3905 field = DECL_CHAIN (field))
3907 if (TREE_CODE (field) != FIELD_DECL)
3910 if (!DECL_BIT_FIELD_TYPE (field))
3917 if (TREE_CODE (type) == UNION_TYPE)
3921 /* Unions can be returned in registers if every element is
3922 integral, or can be returned in an integer register. */
3923 for (field = TYPE_FIELDS (type);
3925 field = DECL_CHAIN (field))
3927 if (TREE_CODE (field) != FIELD_DECL)
3930 if (FLOAT_TYPE_P (TREE_TYPE (field)))
3933 if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE))
3939 #endif /* not ARM_WINCE */
3941 /* Return all other types in memory. */
3945 /* Indicate whether or not words of a double are in big-endian order. */
3948 arm_float_words_big_endian (void)
3950 if (TARGET_MAVERICK)
3953 /* For FPA, float words are always big-endian. For VFP, floats words
3954 follow the memory system mode. */
3962 return (TARGET_BIG_END ? 1 : 0);