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 Free Software Foundation, Inc.
4 Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl)
5 and Martin Simmons (@harleqn.co.uk).
6 More major hacks by Richard Earnshaw (rearnsha@arm.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published
12 by the Free Software Foundation; either version 3, or (at your
13 option) any later version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18 License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
32 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "conditions.h"
37 #include "insn-attr.h"
48 #include "integrate.h"
51 #include "target-def.h"
53 #include "langhooks.h"
56 /* Forward definitions of types. */
57 typedef struct minipool_node Mnode;
58 typedef struct minipool_fixup Mfix;
60 const struct attribute_spec arm_attribute_table[];
62 void (*arm_lang_output_object_attributes_hook)(void);
64 /* Forward function declarations. */
65 static arm_stack_offsets *arm_get_frame_offsets (void);
66 static void arm_add_gc_roots (void);
67 static int arm_gen_constant (enum rtx_code, enum machine_mode, rtx,
68 HOST_WIDE_INT, rtx, rtx, int, int);
69 static unsigned bit_count (unsigned long);
70 static int arm_address_register_rtx_p (rtx, int);
71 static int arm_legitimate_index_p (enum machine_mode, rtx, RTX_CODE, int);
72 static int thumb2_legitimate_index_p (enum machine_mode, rtx, int);
73 static int thumb1_base_register_rtx_p (rtx, enum machine_mode, int);
74 inline static int thumb1_index_register_rtx_p (rtx, int);
75 static int thumb_far_jump_used_p (void);
76 static bool thumb_force_lr_save (void);
77 static int const_ok_for_op (HOST_WIDE_INT, enum rtx_code);
78 static rtx emit_sfm (int, int);
79 static unsigned arm_size_return_regs (void);
80 static bool arm_assemble_integer (rtx, unsigned int, int);
81 static const char *fp_const_from_val (REAL_VALUE_TYPE *);
82 static arm_cc get_arm_condition_code (rtx);
83 static HOST_WIDE_INT int_log2 (HOST_WIDE_INT);
84 static rtx is_jump_table (rtx);
85 static const char *output_multi_immediate (rtx *, const char *, const char *,
87 static const char *shift_op (rtx, HOST_WIDE_INT *);
88 static struct machine_function *arm_init_machine_status (void);
89 static void thumb_exit (FILE *, int);
90 static rtx is_jump_table (rtx);
91 static HOST_WIDE_INT get_jump_table_size (rtx);
92 static Mnode *move_minipool_fix_forward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
93 static Mnode *add_minipool_forward_ref (Mfix *);
94 static Mnode *move_minipool_fix_backward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
95 static Mnode *add_minipool_backward_ref (Mfix *);
96 static void assign_minipool_offsets (Mfix *);
97 static void arm_print_value (FILE *, rtx);
98 static void dump_minipool (rtx);
99 static int arm_barrier_cost (rtx);
100 static Mfix *create_fix_barrier (Mfix *, HOST_WIDE_INT);
101 static void push_minipool_barrier (rtx, HOST_WIDE_INT);
102 static void push_minipool_fix (rtx, HOST_WIDE_INT, rtx *, enum machine_mode,
104 static void arm_reorg (void);
105 static bool note_invalid_constants (rtx, HOST_WIDE_INT, int);
106 static unsigned long arm_compute_save_reg0_reg12_mask (void);
107 static unsigned long arm_compute_save_reg_mask (void);
108 static unsigned long arm_isr_value (tree);
109 static unsigned long arm_compute_func_type (void);
110 static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
111 static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *);
112 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
113 static tree arm_handle_notshared_attribute (tree *, tree, tree, int, bool *);
115 static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT);
116 static void arm_output_function_prologue (FILE *, HOST_WIDE_INT);
117 static void thumb1_output_function_prologue (FILE *, HOST_WIDE_INT);
118 static int arm_comp_type_attributes (const_tree, const_tree);
119 static void arm_set_default_type_attributes (tree);
120 static int arm_adjust_cost (rtx, rtx, rtx, int);
121 static int count_insns_for_constant (HOST_WIDE_INT, int);
122 static int arm_get_strip_length (int);
123 static bool arm_function_ok_for_sibcall (tree, tree);
124 static void arm_internal_label (FILE *, const char *, unsigned long);
125 static void arm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
127 static int arm_rtx_costs_1 (rtx, enum rtx_code, enum rtx_code);
128 static bool arm_size_rtx_costs (rtx, int, int, int *);
129 static bool arm_slowmul_rtx_costs (rtx, int, int, int *);
130 static bool arm_fastmul_rtx_costs (rtx, int, int, int *);
131 static bool arm_xscale_rtx_costs (rtx, int, int, int *);
132 static bool arm_9e_rtx_costs (rtx, int, int, int *);
133 static int arm_address_cost (rtx);
134 static bool arm_memory_load_p (rtx);
135 static bool arm_cirrus_insn_p (rtx);
136 static void cirrus_reorg (rtx);
137 static void arm_init_builtins (void);
138 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
139 static void arm_init_iwmmxt_builtins (void);
140 static rtx safe_vector_operand (rtx, enum machine_mode);
141 static rtx arm_expand_binop_builtin (enum insn_code, tree, rtx);
142 static rtx arm_expand_unop_builtin (enum insn_code, tree, rtx, int);
143 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
144 static void emit_constant_insn (rtx cond, rtx pattern);
145 static rtx emit_set_insn (rtx, rtx);
146 static int arm_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
149 #ifdef OBJECT_FORMAT_ELF
150 static void arm_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED;
151 static void arm_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED;
154 static void arm_encode_section_info (tree, rtx, int);
157 static void arm_file_end (void);
158 static void arm_file_start (void);
160 static void arm_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
162 static bool arm_pass_by_reference (CUMULATIVE_ARGS *,
163 enum machine_mode, const_tree, bool);
164 static bool arm_promote_prototypes (const_tree);
165 static bool arm_default_short_enums (void);
166 static bool arm_align_anon_bitfield (void);
167 static bool arm_return_in_msb (const_tree);
168 static bool arm_must_pass_in_stack (enum machine_mode, const_tree);
169 static bool arm_return_in_memory (const_tree, const_tree);
170 #ifdef TARGET_UNWIND_INFO
171 static void arm_unwind_emit (FILE *, rtx);
172 static bool arm_output_ttype (rtx);
174 static void arm_dwarf_handle_frame_unspec (const char *, rtx, int);
176 static tree arm_cxx_guard_type (void);
177 static bool arm_cxx_guard_mask_bit (void);
178 static tree arm_get_cookie_size (tree);
179 static bool arm_cookie_has_size (void);
180 static bool arm_cxx_cdtor_returns_this (void);
181 static bool arm_cxx_key_method_may_be_inline (void);
182 static void arm_cxx_determine_class_data_visibility (tree);
183 static bool arm_cxx_class_data_always_comdat (void);
184 static bool arm_cxx_use_aeabi_atexit (void);
185 static void arm_init_libfuncs (void);
186 static bool arm_handle_option (size_t, const char *, int);
187 static void arm_target_help (void);
188 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode);
189 static bool arm_cannot_copy_insn_p (rtx);
190 static bool arm_tls_symbol_p (rtx x);
191 static int arm_issue_rate (void);
192 static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
193 static bool arm_allocate_stack_slots_for_args (void);
196 /* Initialize the GCC target structure. */
197 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
198 #undef TARGET_MERGE_DECL_ATTRIBUTES
199 #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
202 #undef TARGET_ATTRIBUTE_TABLE
203 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
205 #undef TARGET_ASM_FILE_START
206 #define TARGET_ASM_FILE_START arm_file_start
207 #undef TARGET_ASM_FILE_END
208 #define TARGET_ASM_FILE_END arm_file_end
210 #undef TARGET_ASM_ALIGNED_SI_OP
211 #define TARGET_ASM_ALIGNED_SI_OP NULL
212 #undef TARGET_ASM_INTEGER
213 #define TARGET_ASM_INTEGER arm_assemble_integer
215 #undef TARGET_ASM_FUNCTION_PROLOGUE
216 #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue
218 #undef TARGET_ASM_FUNCTION_EPILOGUE
219 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
221 #undef TARGET_DEFAULT_TARGET_FLAGS
222 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_SCHED_PROLOG)
223 #undef TARGET_HANDLE_OPTION
224 #define TARGET_HANDLE_OPTION arm_handle_option
226 #define TARGET_HELP arm_target_help
228 #undef TARGET_COMP_TYPE_ATTRIBUTES
229 #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes
231 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
232 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes
234 #undef TARGET_SCHED_ADJUST_COST
235 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
237 #undef TARGET_ENCODE_SECTION_INFO
239 #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info
241 #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info
244 #undef TARGET_STRIP_NAME_ENCODING
245 #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding
247 #undef TARGET_ASM_INTERNAL_LABEL
248 #define TARGET_ASM_INTERNAL_LABEL arm_internal_label
250 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
251 #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall
253 #undef TARGET_ASM_OUTPUT_MI_THUNK
254 #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk
255 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
256 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
258 /* This will be overridden in arm_override_options. */
259 #undef TARGET_RTX_COSTS
260 #define TARGET_RTX_COSTS arm_slowmul_rtx_costs
261 #undef TARGET_ADDRESS_COST
262 #define TARGET_ADDRESS_COST arm_address_cost
264 #undef TARGET_SHIFT_TRUNCATION_MASK
265 #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask
266 #undef TARGET_VECTOR_MODE_SUPPORTED_P
267 #define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p
269 #undef TARGET_MACHINE_DEPENDENT_REORG
270 #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg
272 #undef TARGET_INIT_BUILTINS
273 #define TARGET_INIT_BUILTINS arm_init_builtins
274 #undef TARGET_EXPAND_BUILTIN
275 #define TARGET_EXPAND_BUILTIN arm_expand_builtin
277 #undef TARGET_INIT_LIBFUNCS
278 #define TARGET_INIT_LIBFUNCS arm_init_libfuncs
280 #undef TARGET_PROMOTE_FUNCTION_ARGS
281 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_const_tree_true
282 #undef TARGET_PROMOTE_FUNCTION_RETURN
283 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_const_tree_true
284 #undef TARGET_PROMOTE_PROTOTYPES
285 #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes
286 #undef TARGET_PASS_BY_REFERENCE
287 #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference
288 #undef TARGET_ARG_PARTIAL_BYTES
289 #define TARGET_ARG_PARTIAL_BYTES arm_arg_partial_bytes
291 #undef TARGET_SETUP_INCOMING_VARARGS
292 #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs
294 #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
295 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args
297 #undef TARGET_DEFAULT_SHORT_ENUMS
298 #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
300 #undef TARGET_ALIGN_ANON_BITFIELD
301 #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield
303 #undef TARGET_NARROW_VOLATILE_BITFIELD
304 #define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
306 #undef TARGET_CXX_GUARD_TYPE
307 #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type
309 #undef TARGET_CXX_GUARD_MASK_BIT
310 #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit
312 #undef TARGET_CXX_GET_COOKIE_SIZE
313 #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size
315 #undef TARGET_CXX_COOKIE_HAS_SIZE
316 #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size
318 #undef TARGET_CXX_CDTOR_RETURNS_THIS
319 #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this
321 #undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE
322 #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline
324 #undef TARGET_CXX_USE_AEABI_ATEXIT
325 #define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit
327 #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY
328 #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \
329 arm_cxx_determine_class_data_visibility
331 #undef TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT
332 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT arm_cxx_class_data_always_comdat
334 #undef TARGET_RETURN_IN_MSB
335 #define TARGET_RETURN_IN_MSB arm_return_in_msb
337 #undef TARGET_RETURN_IN_MEMORY
338 #define TARGET_RETURN_IN_MEMORY arm_return_in_memory
340 #undef TARGET_MUST_PASS_IN_STACK
341 #define TARGET_MUST_PASS_IN_STACK arm_must_pass_in_stack
343 #ifdef TARGET_UNWIND_INFO
344 #undef TARGET_UNWIND_EMIT
345 #define TARGET_UNWIND_EMIT arm_unwind_emit
347 /* EABI unwinding tables use a different format for the typeinfo tables. */
348 #undef TARGET_ASM_TTYPE
349 #define TARGET_ASM_TTYPE arm_output_ttype
351 #undef TARGET_ARM_EABI_UNWINDER
352 #define TARGET_ARM_EABI_UNWINDER true
353 #endif /* TARGET_UNWIND_INFO */
355 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
356 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC arm_dwarf_handle_frame_unspec
358 #undef TARGET_CANNOT_COPY_INSN_P
359 #define TARGET_CANNOT_COPY_INSN_P arm_cannot_copy_insn_p
362 #undef TARGET_HAVE_TLS
363 #define TARGET_HAVE_TLS true
366 #undef TARGET_CANNOT_FORCE_CONST_MEM
367 #define TARGET_CANNOT_FORCE_CONST_MEM arm_cannot_force_const_mem
369 #undef TARGET_SCHED_ISSUE_RATE
370 #define TARGET_SCHED_ISSUE_RATE arm_issue_rate
372 #undef TARGET_MANGLE_TYPE
373 #define TARGET_MANGLE_TYPE arm_mangle_type
376 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
377 #define TARGET_ASM_OUTPUT_DWARF_DTPREL arm_output_dwarf_dtprel
380 struct gcc_target targetm = TARGET_INITIALIZER;
382 /* Obstack for minipool constant handling. */
383 static struct obstack minipool_obstack;
384 static char * minipool_startobj;
386 /* The maximum number of insns skipped which
387 will be conditionalised if possible. */
388 static int max_insns_skipped = 5;
390 extern FILE * asm_out_file;
392 /* True if we are currently building a constant table. */
393 int making_const_table;
395 /* Define the information needed to generate branch insns. This is
396 stored from the compare operation. */
397 rtx arm_compare_op0, arm_compare_op1;
399 /* The processor for which instructions should be scheduled. */
400 enum processor_type arm_tune = arm_none;
402 /* The default processor used if not overridden by commandline. */
403 static enum processor_type arm_default_cpu = arm_none;
405 /* Which floating point model to use. */
406 enum arm_fp_model arm_fp_model;
408 /* Which floating point hardware is available. */
409 enum fputype arm_fpu_arch;
411 /* Which floating point hardware to schedule for. */
412 enum fputype arm_fpu_tune;
414 /* Whether to use floating point hardware. */
415 enum float_abi_type arm_float_abi;
417 /* Which ABI to use. */
418 enum arm_abi_type arm_abi;
420 /* Which thread pointer model to use. */
421 enum arm_tp_type target_thread_pointer = TP_AUTO;
423 /* Used to parse -mstructure_size_boundary command line option. */
424 int arm_structure_size_boundary = DEFAULT_STRUCTURE_SIZE_BOUNDARY;
426 /* Used for Thumb call_via trampolines. */
427 rtx thumb_call_via_label[14];
428 static int thumb_call_reg_needed;
430 /* Bit values used to identify processor capabilities. */
431 #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */
432 #define FL_ARCH3M (1 << 1) /* Extended multiply */
433 #define FL_MODE26 (1 << 2) /* 26-bit mode support */
434 #define FL_MODE32 (1 << 3) /* 32-bit mode support */
435 #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */
436 #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */
437 #define FL_THUMB (1 << 6) /* Thumb aware */
438 #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */
439 #define FL_STRONG (1 << 8) /* StrongARM */
440 #define FL_ARCH5E (1 << 9) /* DSP extensions to v5 */
441 #define FL_XSCALE (1 << 10) /* XScale */
442 #define FL_CIRRUS (1 << 11) /* Cirrus/DSP. */
443 #define FL_ARCH6 (1 << 12) /* Architecture rel 6. Adds
444 media instructions. */
445 #define FL_VFPV2 (1 << 13) /* Vector Floating Point V2. */
446 #define FL_WBUF (1 << 14) /* Schedule for write buffer ops.
447 Note: ARM6 & 7 derivatives only. */
448 #define FL_ARCH6K (1 << 15) /* Architecture rel 6 K extensions. */
449 #define FL_THUMB2 (1 << 16) /* Thumb-2. */
450 #define FL_NOTM (1 << 17) /* Instructions not present in the 'M'
452 #define FL_DIV (1 << 18) /* Hardware divide. */
453 #define FL_VFPV3 (1 << 19) /* Vector Floating Point V3. */
454 #define FL_NEON (1 << 20) /* Neon instructions. */
456 #define FL_IWMMXT (1 << 29) /* XScale v2 or "Intel Wireless MMX technology". */
458 #define FL_FOR_ARCH2 FL_NOTM
459 #define FL_FOR_ARCH3 (FL_FOR_ARCH2 | FL_MODE32)
460 #define FL_FOR_ARCH3M (FL_FOR_ARCH3 | FL_ARCH3M)
461 #define FL_FOR_ARCH4 (FL_FOR_ARCH3M | FL_ARCH4)
462 #define FL_FOR_ARCH4T (FL_FOR_ARCH4 | FL_THUMB)
463 #define FL_FOR_ARCH5 (FL_FOR_ARCH4 | FL_ARCH5)
464 #define FL_FOR_ARCH5T (FL_FOR_ARCH5 | FL_THUMB)
465 #define FL_FOR_ARCH5E (FL_FOR_ARCH5 | FL_ARCH5E)
466 #define FL_FOR_ARCH5TE (FL_FOR_ARCH5E | FL_THUMB)
467 #define FL_FOR_ARCH5TEJ FL_FOR_ARCH5TE
468 #define FL_FOR_ARCH6 (FL_FOR_ARCH5TE | FL_ARCH6)
469 #define FL_FOR_ARCH6J FL_FOR_ARCH6
470 #define FL_FOR_ARCH6K (FL_FOR_ARCH6 | FL_ARCH6K)
471 #define FL_FOR_ARCH6Z FL_FOR_ARCH6
472 #define FL_FOR_ARCH6ZK FL_FOR_ARCH6K
473 #define FL_FOR_ARCH6T2 (FL_FOR_ARCH6 | FL_THUMB2)
474 #define FL_FOR_ARCH6M (FL_FOR_ARCH6 & ~FL_NOTM)
475 #define FL_FOR_ARCH7 (FL_FOR_ARCH6T2 &~ FL_NOTM)
476 #define FL_FOR_ARCH7A (FL_FOR_ARCH7 | FL_NOTM)
477 #define FL_FOR_ARCH7R (FL_FOR_ARCH7A | FL_DIV)
478 #define FL_FOR_ARCH7M (FL_FOR_ARCH7 | FL_DIV)
480 /* The bits in this mask specify which
481 instructions we are allowed to generate. */
482 static unsigned long insn_flags = 0;
484 /* The bits in this mask specify which instruction scheduling options should
486 static unsigned long tune_flags = 0;
488 /* The following are used in the arm.md file as equivalents to bits
489 in the above two flag variables. */
491 /* Nonzero if this chip supports the ARM Architecture 3M extensions. */
494 /* Nonzero if this chip supports the ARM Architecture 4 extensions. */
497 /* Nonzero if this chip supports the ARM Architecture 4t extensions. */
500 /* Nonzero if this chip supports the ARM Architecture 5 extensions. */
503 /* Nonzero if this chip supports the ARM Architecture 5E extensions. */
506 /* Nonzero if this chip supports the ARM Architecture 6 extensions. */
509 /* Nonzero if this chip supports the ARM 6K extensions. */
512 /* Nonzero if instructions not present in the 'M' profile can be used. */
513 int arm_arch_notm = 0;
515 /* Nonzero if this chip can benefit from load scheduling. */
516 int arm_ld_sched = 0;
518 /* Nonzero if this chip is a StrongARM. */
519 int arm_tune_strongarm = 0;
521 /* Nonzero if this chip is a Cirrus variant. */
522 int arm_arch_cirrus = 0;
524 /* Nonzero if this chip supports Intel Wireless MMX technology. */
525 int arm_arch_iwmmxt = 0;
527 /* Nonzero if this chip is an XScale. */
528 int arm_arch_xscale = 0;
530 /* Nonzero if tuning for XScale */
531 int arm_tune_xscale = 0;
533 /* Nonzero if we want to tune for stores that access the write-buffer.
534 This typically means an ARM6 or ARM7 with MMU or MPU. */
535 int arm_tune_wbuf = 0;
537 /* Nonzero if generating Thumb instructions. */
540 /* Nonzero if we should define __THUMB_INTERWORK__ in the
542 XXX This is a bit of a hack, it's intended to help work around
543 problems in GLD which doesn't understand that armv5t code is
544 interworking clean. */
545 int arm_cpp_interwork = 0;
547 /* Nonzero if chip supports Thumb 2. */
550 /* Nonzero if chip supports integer division instruction. */
553 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, we
554 must report the mode of the memory reference from PRINT_OPERAND to
555 PRINT_OPERAND_ADDRESS. */
556 enum machine_mode output_memory_reference_mode;
558 /* The register number to be used for the PIC offset register. */
559 unsigned arm_pic_register = INVALID_REGNUM;
561 /* Set to 1 when a return insn is output, this means that the epilogue
563 int return_used_this_function;
565 /* Set to 1 after arm_reorg has started. Reset to start at the start of
566 the next function. */
567 static int after_arm_reorg = 0;
569 /* The maximum number of insns to be used when loading a constant. */
570 static int arm_constant_limit = 3;
572 /* For an explanation of these variables, see final_prescan_insn below. */
574 /* arm_current_cc is also used for Thumb-2 cond_exec blocks. */
575 enum arm_cond_code arm_current_cc;
577 int arm_target_label;
578 /* The number of conditionally executed insns, including the current insn. */
579 int arm_condexec_count = 0;
580 /* A bitmask specifying the patterns for the IT block.
581 Zero means do not output an IT block before this insn. */
582 int arm_condexec_mask = 0;
583 /* The number of bits used in arm_condexec_mask. */
584 int arm_condexec_masklen = 0;
586 /* The condition codes of the ARM, and the inverse function. */
587 static const char * const arm_condition_codes[] =
589 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
590 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
593 #define ARM_LSL_NAME (TARGET_UNIFIED_ASM ? "lsl" : "asl")
594 #define streq(string1, string2) (strcmp (string1, string2) == 0)
596 #define THUMB2_WORK_REGS (0xff & ~( (1 << THUMB_HARD_FRAME_POINTER_REGNUM) \
597 | (1 << SP_REGNUM) | (1 << PC_REGNUM) \
598 | (1 << PIC_OFFSET_TABLE_REGNUM)))
600 /* Initialization code. */
604 const char *const name;
605 enum processor_type core;
607 const unsigned long flags;
608 bool (* rtx_costs) (rtx, int, int, int *);
611 /* Not all of these give usefully different compilation alternatives,
612 but there is no simple way of generalizing them. */
613 static const struct processors all_cores[] =
616 #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \
617 {NAME, arm_none, #ARCH, FLAGS | FL_FOR_ARCH##ARCH, arm_##COSTS##_rtx_costs},
618 #include "arm-cores.def"
620 {NULL, arm_none, NULL, 0, NULL}
623 static const struct processors all_architectures[] =
625 /* ARM Architectures */
626 /* We don't specify rtx_costs here as it will be figured out
629 {"armv2", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
630 {"armv2a", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
631 {"armv3", arm6, "3", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3, NULL},
632 {"armv3m", arm7m, "3M", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3M, NULL},
633 {"armv4", arm7tdmi, "4", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH4, NULL},
634 /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no
635 implementations that support it, so we will leave it out for now. */
636 {"armv4t", arm7tdmi, "4T", FL_CO_PROC | FL_FOR_ARCH4T, NULL},
637 {"armv5", arm10tdmi, "5", FL_CO_PROC | FL_FOR_ARCH5, NULL},
638 {"armv5t", arm10tdmi, "5T", FL_CO_PROC | FL_FOR_ARCH5T, NULL},
639 {"armv5e", arm1026ejs, "5E", FL_CO_PROC | FL_FOR_ARCH5E, NULL},
640 {"armv5te", arm1026ejs, "5TE", FL_CO_PROC | FL_FOR_ARCH5TE, NULL},
641 {"armv6", arm1136js, "6", FL_CO_PROC | FL_FOR_ARCH6, NULL},
642 {"armv6j", arm1136js, "6J", FL_CO_PROC | FL_FOR_ARCH6J, NULL},
643 {"armv6k", mpcore, "6K", FL_CO_PROC | FL_FOR_ARCH6K, NULL},
644 {"armv6z", arm1176jzs, "6Z", FL_CO_PROC | FL_FOR_ARCH6Z, NULL},
645 {"armv6zk", arm1176jzs, "6ZK", FL_CO_PROC | FL_FOR_ARCH6ZK, NULL},
646 {"armv6t2", arm1156t2s, "6T2", FL_CO_PROC | FL_FOR_ARCH6T2, NULL},
647 {"armv6-m", cortexm1, "6M", FL_FOR_ARCH6M, NULL},
648 {"armv7", cortexa8, "7", FL_CO_PROC | FL_FOR_ARCH7, NULL},
649 {"armv7-a", cortexa8, "7A", FL_CO_PROC | FL_FOR_ARCH7A, NULL},
650 {"armv7-r", cortexr4, "7R", FL_CO_PROC | FL_FOR_ARCH7R, NULL},
651 {"armv7-m", cortexm3, "7M", FL_CO_PROC | FL_FOR_ARCH7M, NULL},
652 {"ep9312", ep9312, "4T", FL_LDSCHED | FL_CIRRUS | FL_FOR_ARCH4, NULL},
653 {"iwmmxt", iwmmxt, "5TE", FL_LDSCHED | FL_STRONG | FL_FOR_ARCH5TE | FL_XSCALE | FL_IWMMXT , NULL},
654 {NULL, arm_none, NULL, 0 , NULL}
657 struct arm_cpu_select
661 const struct processors * processors;
664 /* This is a magic structure. The 'string' field is magically filled in
665 with a pointer to the value specified by the user on the command line
666 assuming that the user has specified such a value. */
668 static struct arm_cpu_select arm_select[] =
670 /* string name processors */
671 { NULL, "-mcpu=", all_cores },
672 { NULL, "-march=", all_architectures },
673 { NULL, "-mtune=", all_cores }
676 /* Defines representing the indexes into the above table. */
677 #define ARM_OPT_SET_CPU 0
678 #define ARM_OPT_SET_ARCH 1
679 #define ARM_OPT_SET_TUNE 2
681 /* The name of the preprocessor macro to define for this architecture. */
683 char arm_arch_name[] = "__ARM_ARCH_0UNK__";
692 /* Available values for -mfpu=. */
694 static const struct fpu_desc all_fpus[] =
696 {"fpa", FPUTYPE_FPA},
697 {"fpe2", FPUTYPE_FPA_EMU2},
698 {"fpe3", FPUTYPE_FPA_EMU2},
699 {"maverick", FPUTYPE_MAVERICK},
700 {"vfp", FPUTYPE_VFP},
701 {"vfp3", FPUTYPE_VFP3},
702 {"neon", FPUTYPE_NEON}
706 /* Floating point models used by the different hardware.
707 See fputype in arm.h. */
709 static const enum fputype fp_model_for_fpu[] =
711 /* No FP hardware. */
712 ARM_FP_MODEL_UNKNOWN, /* FPUTYPE_NONE */
713 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA */
714 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA_EMU2 */
715 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA_EMU3 */
716 ARM_FP_MODEL_MAVERICK, /* FPUTYPE_MAVERICK */
717 ARM_FP_MODEL_VFP, /* FPUTYPE_VFP */
718 ARM_FP_MODEL_VFP, /* FPUTYPE_VFP3 */
719 ARM_FP_MODEL_VFP /* FPUTYPE_NEON */
726 enum float_abi_type abi_type;
730 /* Available values for -mfloat-abi=. */
732 static const struct float_abi all_float_abis[] =
734 {"soft", ARM_FLOAT_ABI_SOFT},
735 {"softfp", ARM_FLOAT_ABI_SOFTFP},
736 {"hard", ARM_FLOAT_ABI_HARD}
743 enum arm_abi_type abi_type;
747 /* Available values for -mabi=. */
749 static const struct abi_name arm_all_abis[] =
751 {"apcs-gnu", ARM_ABI_APCS},
752 {"atpcs", ARM_ABI_ATPCS},
753 {"aapcs", ARM_ABI_AAPCS},
754 {"iwmmxt", ARM_ABI_IWMMXT},
755 {"aapcs-linux", ARM_ABI_AAPCS_LINUX}
758 /* Supported TLS relocations. */
768 /* Emit an insn that's a simple single-set. Both the operands must be known
771 emit_set_insn (rtx x, rtx y)
773 return emit_insn (gen_rtx_SET (VOIDmode, x, y));
776 /* Return the number of bits set in VALUE. */
778 bit_count (unsigned long value)
780 unsigned long count = 0;
785 value &= value - 1; /* Clear the least-significant set bit. */
791 /* Set up library functions unique to ARM. */
794 arm_init_libfuncs (void)
796 /* There are no special library functions unless we are using the
801 /* The functions below are described in Section 4 of the "Run-Time
802 ABI for the ARM architecture", Version 1.0. */
804 /* Double-precision floating-point arithmetic. Table 2. */
805 set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd");
806 set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv");
807 set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul");
808 set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg");
809 set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub");
811 /* Double-precision comparisons. Table 3. */
812 set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq");
813 set_optab_libfunc (ne_optab, DFmode, NULL);
814 set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt");
815 set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple");
816 set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge");
817 set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt");
818 set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun");
820 /* Single-precision floating-point arithmetic. Table 4. */
821 set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd");
822 set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv");
823 set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul");
824 set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg");
825 set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub");
827 /* Single-precision comparisons. Table 5. */
828 set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq");
829 set_optab_libfunc (ne_optab, SFmode, NULL);
830 set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt");
831 set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple");
832 set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge");
833 set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt");
834 set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun");
836 /* Floating-point to integer conversions. Table 6. */
837 set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz");
838 set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz");
839 set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz");
840 set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz");
841 set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz");
842 set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz");
843 set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz");
844 set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz");
846 /* Conversions between floating types. Table 7. */
847 set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f");
848 set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d");
850 /* Integer to floating-point conversions. Table 8. */
851 set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d");
852 set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d");
853 set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d");
854 set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d");
855 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f");
856 set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f");
857 set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f");
858 set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f");
860 /* Long long. Table 9. */
861 set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul");
862 set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod");
863 set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod");
864 set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl");
865 set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr");
866 set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr");
867 set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp");
868 set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp");
870 /* Integer (32/32->32) division. \S 4.3.1. */
871 set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod");
872 set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod");
874 /* The divmod functions are designed so that they can be used for
875 plain division, even though they return both the quotient and the
876 remainder. The quotient is returned in the usual location (i.e.,
877 r0 for SImode, {r0, r1} for DImode), just as would be expected
878 for an ordinary division routine. Because the AAPCS calling
879 conventions specify that all of { r0, r1, r2, r3 } are
880 callee-saved registers, there is no need to tell the compiler
881 explicitly that those registers are clobbered by these
883 set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod");
884 set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod");
886 /* For SImode division the ABI provides div-without-mod routines,
888 set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idiv");
889 set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidiv");
891 /* We don't have mod libcalls. Fortunately gcc knows how to use the
892 divmod libcalls instead. */
893 set_optab_libfunc (smod_optab, DImode, NULL);
894 set_optab_libfunc (umod_optab, DImode, NULL);
895 set_optab_libfunc (smod_optab, SImode, NULL);
896 set_optab_libfunc (umod_optab, SImode, NULL);
899 /* Implement TARGET_HANDLE_OPTION. */
902 arm_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
907 arm_select[1].string = arg;
911 arm_select[0].string = arg;
914 case OPT_mhard_float:
915 target_float_abi_name = "hard";
918 case OPT_msoft_float:
919 target_float_abi_name = "soft";
923 arm_select[2].string = arg;
932 arm_target_help (void)
935 static int columns = 0;
938 /* If we have not done so already, obtain the desired maximum width of
939 the output. Note - this is a duplication of the code at the start of
940 gcc/opts.c:print_specific_help() - the two copies should probably be
941 replaced by a single function. */
946 GET_ENVIRONMENT (p, "COLUMNS");
949 int value = atoi (p);
956 /* Use a reasonable default. */
960 printf (" Known ARM CPUs (for use with the -mcpu= and -mtune= options):\n");
962 /* The - 2 is because we know that the last entry in the array is NULL. */
963 i = ARRAY_SIZE (all_cores) - 2;
965 printf (" %s", all_cores[i].name);
966 remaining = columns - (strlen (all_cores[i].name) + 4);
967 gcc_assert (remaining >= 0);
971 int len = strlen (all_cores[i].name);
973 if (remaining > len + 2)
975 printf (", %s", all_cores[i].name);
976 remaining -= len + 2;
982 printf ("\n %s", all_cores[i].name);
983 remaining = columns - (len + 4);
987 printf ("\n\n Known ARM architectures (for use with the -march= option):\n");
989 i = ARRAY_SIZE (all_architectures) - 2;
992 printf (" %s", all_architectures[i].name);
993 remaining = columns - (strlen (all_architectures[i].name) + 4);
994 gcc_assert (remaining >= 0);
998 int len = strlen (all_architectures[i].name);
1000 if (remaining > len + 2)
1002 printf (", %s", all_architectures[i].name);
1003 remaining -= len + 2;
1009 printf ("\n %s", all_architectures[i].name);
1010 remaining = columns - (len + 4);
1017 /* Fix up any incompatible options that the user has specified.
1018 This has now turned into a maze. */
1020 arm_override_options (void)
1023 enum processor_type target_arch_cpu = arm_none;
1025 /* Set up the flags based on the cpu/architecture selected by the user. */
1026 for (i = ARRAY_SIZE (arm_select); i--;)
1028 struct arm_cpu_select * ptr = arm_select + i;
1030 if (ptr->string != NULL && ptr->string[0] != '\0')
1032 const struct processors * sel;
1034 for (sel = ptr->processors; sel->name != NULL; sel++)
1035 if (streq (ptr->string, sel->name))
1037 /* Set the architecture define. */
1038 if (i != ARM_OPT_SET_TUNE)
1039 sprintf (arm_arch_name, "__ARM_ARCH_%s__", sel->arch);
1041 /* Determine the processor core for which we should
1042 tune code-generation. */
1043 if (/* -mcpu= is a sensible default. */
1044 i == ARM_OPT_SET_CPU
1045 /* -mtune= overrides -mcpu= and -march=. */
1046 || i == ARM_OPT_SET_TUNE)
1047 arm_tune = (enum processor_type) (sel - ptr->processors);
1049 /* Remember the CPU associated with this architecture.
1050 If no other option is used to set the CPU type,
1051 we'll use this to guess the most suitable tuning
1053 if (i == ARM_OPT_SET_ARCH)
1054 target_arch_cpu = sel->core;
1056 if (i != ARM_OPT_SET_TUNE)
1058 /* If we have been given an architecture and a processor
1059 make sure that they are compatible. We only generate
1060 a warning though, and we prefer the CPU over the
1062 if (insn_flags != 0 && (insn_flags ^ sel->flags))
1063 warning (0, "switch -mcpu=%s conflicts with -march= switch",
1066 insn_flags = sel->flags;
1072 if (sel->name == NULL)
1073 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
1077 /* Guess the tuning options from the architecture if necessary. */
1078 if (arm_tune == arm_none)
1079 arm_tune = target_arch_cpu;
1081 /* If the user did not specify a processor, choose one for them. */
1082 if (insn_flags == 0)
1084 const struct processors * sel;
1085 unsigned int sought;
1086 enum processor_type cpu;
1088 cpu = TARGET_CPU_DEFAULT;
1089 if (cpu == arm_none)
1091 #ifdef SUBTARGET_CPU_DEFAULT
1092 /* Use the subtarget default CPU if none was specified by
1094 cpu = SUBTARGET_CPU_DEFAULT;
1096 /* Default to ARM6. */
1097 if (cpu == arm_none)
1100 sel = &all_cores[cpu];
1102 insn_flags = sel->flags;
1104 /* Now check to see if the user has specified some command line
1105 switch that require certain abilities from the cpu. */
1108 if (TARGET_INTERWORK || TARGET_THUMB)
1110 sought |= (FL_THUMB | FL_MODE32);
1112 /* There are no ARM processors that support both APCS-26 and
1113 interworking. Therefore we force FL_MODE26 to be removed
1114 from insn_flags here (if it was set), so that the search
1115 below will always be able to find a compatible processor. */
1116 insn_flags &= ~FL_MODE26;
1119 if (sought != 0 && ((sought & insn_flags) != sought))
1121 /* Try to locate a CPU type that supports all of the abilities
1122 of the default CPU, plus the extra abilities requested by
1124 for (sel = all_cores; sel->name != NULL; sel++)
1125 if ((sel->flags & sought) == (sought | insn_flags))
1128 if (sel->name == NULL)
1130 unsigned current_bit_count = 0;
1131 const struct processors * best_fit = NULL;
1133 /* Ideally we would like to issue an error message here
1134 saying that it was not possible to find a CPU compatible
1135 with the default CPU, but which also supports the command
1136 line options specified by the programmer, and so they
1137 ought to use the -mcpu=<name> command line option to
1138 override the default CPU type.
1140 If we cannot find a cpu that has both the
1141 characteristics of the default cpu and the given
1142 command line options we scan the array again looking
1143 for a best match. */
1144 for (sel = all_cores; sel->name != NULL; sel++)
1145 if ((sel->flags & sought) == sought)
1149 count = bit_count (sel->flags & insn_flags);
1151 if (count >= current_bit_count)
1154 current_bit_count = count;
1158 gcc_assert (best_fit);
1162 insn_flags = sel->flags;
1164 sprintf (arm_arch_name, "__ARM_ARCH_%s__", sel->arch);
1165 arm_default_cpu = (enum processor_type) (sel - all_cores);
1166 if (arm_tune == arm_none)
1167 arm_tune = arm_default_cpu;
1170 /* The processor for which we should tune should now have been
1172 gcc_assert (arm_tune != arm_none);
1174 tune_flags = all_cores[(int)arm_tune].flags;
1176 targetm.rtx_costs = arm_size_rtx_costs;
1178 targetm.rtx_costs = all_cores[(int)arm_tune].rtx_costs;
1180 /* Make sure that the processor choice does not conflict with any of the
1181 other command line choices. */
1182 if (TARGET_ARM && !(insn_flags & FL_NOTM))
1183 error ("target CPU does not support ARM mode");
1185 if (TARGET_INTERWORK && !(insn_flags & FL_THUMB))
1187 warning (0, "target CPU does not support interworking" );
1188 target_flags &= ~MASK_INTERWORK;
1191 if (TARGET_THUMB && !(insn_flags & FL_THUMB))
1193 warning (0, "target CPU does not support THUMB instructions");
1194 target_flags &= ~MASK_THUMB;
1197 if (TARGET_APCS_FRAME && TARGET_THUMB)
1199 /* warning (0, "ignoring -mapcs-frame because -mthumb was used"); */
1200 target_flags &= ~MASK_APCS_FRAME;
1203 /* Callee super interworking implies thumb interworking. Adding
1204 this to the flags here simplifies the logic elsewhere. */
1205 if (TARGET_THUMB && TARGET_CALLEE_INTERWORKING)
1206 target_flags |= MASK_INTERWORK;
1208 /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done
1209 from here where no function is being compiled currently. */
1210 if ((TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) && TARGET_ARM)
1211 warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb");
1213 if (TARGET_ARM && TARGET_CALLEE_INTERWORKING)
1214 warning (0, "enabling callee interworking support is only meaningful when compiling for the Thumb");
1216 if (TARGET_ARM && TARGET_CALLER_INTERWORKING)
1217 warning (0, "enabling caller interworking support is only meaningful when compiling for the Thumb");
1219 if (TARGET_APCS_STACK && !TARGET_APCS_FRAME)
1221 warning (0, "-mapcs-stack-check incompatible with -mno-apcs-frame");
1222 target_flags |= MASK_APCS_FRAME;
1225 if (TARGET_POKE_FUNCTION_NAME)
1226 target_flags |= MASK_APCS_FRAME;
1228 if (TARGET_APCS_REENT && flag_pic)
1229 error ("-fpic and -mapcs-reent are incompatible");
1231 if (TARGET_APCS_REENT)
1232 warning (0, "APCS reentrant code not supported. Ignored");
1234 /* If this target is normally configured to use APCS frames, warn if they
1235 are turned off and debugging is turned on. */
1237 && write_symbols != NO_DEBUG
1238 && !TARGET_APCS_FRAME
1239 && (TARGET_DEFAULT & MASK_APCS_FRAME))
1240 warning (0, "-g with -mno-apcs-frame may not give sensible debugging");
1242 if (TARGET_APCS_FLOAT)
1243 warning (0, "passing floating point arguments in fp regs not yet supported");
1245 /* Initialize boolean versions of the flags, for use in the arm.md file. */
1246 arm_arch3m = (insn_flags & FL_ARCH3M) != 0;
1247 arm_arch4 = (insn_flags & FL_ARCH4) != 0;
1248 arm_arch4t = arm_arch4 & ((insn_flags & FL_THUMB) != 0);
1249 arm_arch5 = (insn_flags & FL_ARCH5) != 0;
1250 arm_arch5e = (insn_flags & FL_ARCH5E) != 0;
1251 arm_arch6 = (insn_flags & FL_ARCH6) != 0;
1252 arm_arch6k = (insn_flags & FL_ARCH6K) != 0;
1253 arm_arch_notm = (insn_flags & FL_NOTM) != 0;
1254 arm_arch_thumb2 = (insn_flags & FL_THUMB2) != 0;
1255 arm_arch_xscale = (insn_flags & FL_XSCALE) != 0;
1256 arm_arch_cirrus = (insn_flags & FL_CIRRUS) != 0;
1258 arm_ld_sched = (tune_flags & FL_LDSCHED) != 0;
1259 arm_tune_strongarm = (tune_flags & FL_STRONG) != 0;
1260 thumb_code = (TARGET_ARM == 0);
1261 arm_tune_wbuf = (tune_flags & FL_WBUF) != 0;
1262 arm_tune_xscale = (tune_flags & FL_XSCALE) != 0;
1263 arm_arch_iwmmxt = (insn_flags & FL_IWMMXT) != 0;
1264 arm_arch_hwdiv = (insn_flags & FL_DIV) != 0;
1266 /* V5 code we generate is completely interworking capable, so we turn off
1267 TARGET_INTERWORK here to avoid many tests later on. */
1269 /* XXX However, we must pass the right pre-processor defines to CPP
1270 or GLD can get confused. This is a hack. */
1271 if (TARGET_INTERWORK)
1272 arm_cpp_interwork = 1;
1275 target_flags &= ~MASK_INTERWORK;
1277 if (target_abi_name)
1279 for (i = 0; i < ARRAY_SIZE (arm_all_abis); i++)
1281 if (streq (arm_all_abis[i].name, target_abi_name))
1283 arm_abi = arm_all_abis[i].abi_type;
1287 if (i == ARRAY_SIZE (arm_all_abis))
1288 error ("invalid ABI option: -mabi=%s", target_abi_name);
1291 arm_abi = ARM_DEFAULT_ABI;
1293 if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN)
1294 error ("iwmmxt requires an AAPCS compatible ABI for proper operation");
1296 if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT)
1297 error ("iwmmxt abi requires an iwmmxt capable cpu");
1299 arm_fp_model = ARM_FP_MODEL_UNKNOWN;
1300 if (target_fpu_name == NULL && target_fpe_name != NULL)
1302 if (streq (target_fpe_name, "2"))
1303 target_fpu_name = "fpe2";
1304 else if (streq (target_fpe_name, "3"))
1305 target_fpu_name = "fpe3";
1307 error ("invalid floating point emulation option: -mfpe=%s",
1310 if (target_fpu_name != NULL)
1312 /* The user specified a FPU. */
1313 for (i = 0; i < ARRAY_SIZE (all_fpus); i++)
1315 if (streq (all_fpus[i].name, target_fpu_name))
1317 arm_fpu_arch = all_fpus[i].fpu;
1318 arm_fpu_tune = arm_fpu_arch;
1319 arm_fp_model = fp_model_for_fpu[arm_fpu_arch];
1323 if (arm_fp_model == ARM_FP_MODEL_UNKNOWN)
1324 error ("invalid floating point option: -mfpu=%s", target_fpu_name);
1328 #ifdef FPUTYPE_DEFAULT
1329 /* Use the default if it is specified for this platform. */
1330 arm_fpu_arch = FPUTYPE_DEFAULT;
1331 arm_fpu_tune = FPUTYPE_DEFAULT;
1333 /* Pick one based on CPU type. */
1334 /* ??? Some targets assume FPA is the default.
1335 if ((insn_flags & FL_VFP) != 0)
1336 arm_fpu_arch = FPUTYPE_VFP;
1339 if (arm_arch_cirrus)
1340 arm_fpu_arch = FPUTYPE_MAVERICK;
1342 arm_fpu_arch = FPUTYPE_FPA_EMU2;
1344 if (tune_flags & FL_CO_PROC && arm_fpu_arch == FPUTYPE_FPA_EMU2)
1345 arm_fpu_tune = FPUTYPE_FPA;
1347 arm_fpu_tune = arm_fpu_arch;
1348 arm_fp_model = fp_model_for_fpu[arm_fpu_arch];
1349 gcc_assert (arm_fp_model != ARM_FP_MODEL_UNKNOWN);
1352 if (target_float_abi_name != NULL)
1354 /* The user specified a FP ABI. */
1355 for (i = 0; i < ARRAY_SIZE (all_float_abis); i++)
1357 if (streq (all_float_abis[i].name, target_float_abi_name))
1359 arm_float_abi = all_float_abis[i].abi_type;
1363 if (i == ARRAY_SIZE (all_float_abis))
1364 error ("invalid floating point abi: -mfloat-abi=%s",
1365 target_float_abi_name);
1368 arm_float_abi = TARGET_DEFAULT_FLOAT_ABI;
1370 if (arm_float_abi == ARM_FLOAT_ABI_HARD && TARGET_VFP)
1371 sorry ("-mfloat-abi=hard and VFP");
1373 /* FPA and iWMMXt are incompatible because the insn encodings overlap.
1374 VFP and iWMMXt can theoretically coexist, but it's unlikely such silicon
1375 will ever exist. GCC makes no attempt to support this combination. */
1376 if (TARGET_IWMMXT && !TARGET_SOFT_FLOAT)
1377 sorry ("iWMMXt and hardware floating point");
1379 /* ??? iWMMXt insn patterns need auditing for Thumb-2. */
1380 if (TARGET_THUMB2 && TARGET_IWMMXT)
1381 sorry ("Thumb-2 iWMMXt");
1383 /* If soft-float is specified then don't use FPU. */
1384 if (TARGET_SOFT_FLOAT)
1385 arm_fpu_arch = FPUTYPE_NONE;
1387 /* For arm2/3 there is no need to do any scheduling if there is only
1388 a floating point emulator, or we are doing software floating-point. */
1389 if ((TARGET_SOFT_FLOAT
1390 || arm_fpu_tune == FPUTYPE_FPA_EMU2
1391 || arm_fpu_tune == FPUTYPE_FPA_EMU3)
1392 && (tune_flags & FL_MODE32) == 0)
1393 flag_schedule_insns = flag_schedule_insns_after_reload = 0;
1395 if (target_thread_switch)
1397 if (strcmp (target_thread_switch, "soft") == 0)
1398 target_thread_pointer = TP_SOFT;
1399 else if (strcmp (target_thread_switch, "auto") == 0)
1400 target_thread_pointer = TP_AUTO;
1401 else if (strcmp (target_thread_switch, "cp15") == 0)
1402 target_thread_pointer = TP_CP15;
1404 error ("invalid thread pointer option: -mtp=%s", target_thread_switch);
1407 /* Use the cp15 method if it is available. */
1408 if (target_thread_pointer == TP_AUTO)
1410 if (arm_arch6k && !TARGET_THUMB)
1411 target_thread_pointer = TP_CP15;
1413 target_thread_pointer = TP_SOFT;
1416 if (TARGET_HARD_TP && TARGET_THUMB1)
1417 error ("can not use -mtp=cp15 with 16-bit Thumb");
1419 /* Override the default structure alignment for AAPCS ABI. */
1420 if (TARGET_AAPCS_BASED)
1421 arm_structure_size_boundary = 8;
1423 if (structure_size_string != NULL)
1425 int size = strtol (structure_size_string, NULL, 0);
1427 if (size == 8 || size == 32
1428 || (ARM_DOUBLEWORD_ALIGN && size == 64))
1429 arm_structure_size_boundary = size;
1431 warning (0, "structure size boundary can only be set to %s",
1432 ARM_DOUBLEWORD_ALIGN ? "8, 32 or 64": "8 or 32");
1435 if (!TARGET_ARM && TARGET_VXWORKS_RTP && flag_pic)
1437 error ("RTP PIC is incompatible with Thumb");
1441 /* If stack checking is disabled, we can use r10 as the PIC register,
1442 which keeps r9 available. The EABI specifies r9 as the PIC register. */
1443 if (flag_pic && TARGET_SINGLE_PIC_BASE)
1445 if (TARGET_VXWORKS_RTP)
1446 warning (0, "RTP PIC is incompatible with -msingle-pic-base");
1447 arm_pic_register = (TARGET_APCS_STACK || TARGET_AAPCS_BASED) ? 9 : 10;
1450 if (flag_pic && TARGET_VXWORKS_RTP)
1451 arm_pic_register = 9;
1453 if (arm_pic_register_string != NULL)
1455 int pic_register = decode_reg_name (arm_pic_register_string);
1458 warning (0, "-mpic-register= is useless without -fpic");
1460 /* Prevent the user from choosing an obviously stupid PIC register. */
1461 else if (pic_register < 0 || call_used_regs[pic_register]
1462 || pic_register == HARD_FRAME_POINTER_REGNUM
1463 || pic_register == STACK_POINTER_REGNUM
1464 || pic_register >= PC_REGNUM
1465 || (TARGET_VXWORKS_RTP
1466 && (unsigned int) pic_register != arm_pic_register))
1467 error ("unable to use '%s' for PIC register", arm_pic_register_string);
1469 arm_pic_register = pic_register;
1472 /* ??? We might want scheduling for thumb2. */
1473 if (TARGET_THUMB && flag_schedule_insns)
1475 /* Don't warn since it's on by default in -O2. */
1476 flag_schedule_insns = 0;
1481 arm_constant_limit = 1;
1483 /* If optimizing for size, bump the number of instructions that we
1484 are prepared to conditionally execute (even on a StrongARM). */
1485 max_insns_skipped = 6;
1489 /* For processors with load scheduling, it never costs more than
1490 2 cycles to load a constant, and the load scheduler may well
1491 reduce that to 1. */
1493 arm_constant_limit = 1;
1495 /* On XScale the longer latency of a load makes it more difficult
1496 to achieve a good schedule, so it's faster to synthesize
1497 constants that can be done in two insns. */
1498 if (arm_tune_xscale)
1499 arm_constant_limit = 2;
1501 /* StrongARM has early execution of branches, so a sequence
1502 that is worth skipping is shorter. */
1503 if (arm_tune_strongarm)
1504 max_insns_skipped = 3;
1507 /* Register global variables with the garbage collector. */
1508 arm_add_gc_roots ();
1512 arm_add_gc_roots (void)
1514 gcc_obstack_init(&minipool_obstack);
1515 minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0);
1518 /* A table of known ARM exception types.
1519 For use with the interrupt function attribute. */
1523 const char *const arg;
1524 const unsigned long return_value;
1528 static const isr_attribute_arg isr_attribute_args [] =
1530 { "IRQ", ARM_FT_ISR },
1531 { "irq", ARM_FT_ISR },
1532 { "FIQ", ARM_FT_FIQ },
1533 { "fiq", ARM_FT_FIQ },
1534 { "ABORT", ARM_FT_ISR },
1535 { "abort", ARM_FT_ISR },
1536 { "ABORT", ARM_FT_ISR },
1537 { "abort", ARM_FT_ISR },
1538 { "UNDEF", ARM_FT_EXCEPTION },
1539 { "undef", ARM_FT_EXCEPTION },
1540 { "SWI", ARM_FT_EXCEPTION },
1541 { "swi", ARM_FT_EXCEPTION },
1542 { NULL, ARM_FT_NORMAL }
1545 /* Returns the (interrupt) function type of the current
1546 function, or ARM_FT_UNKNOWN if the type cannot be determined. */
1548 static unsigned long
1549 arm_isr_value (tree argument)
1551 const isr_attribute_arg * ptr;
1555 return ARM_FT_NORMAL | ARM_FT_STACKALIGN;
1557 /* No argument - default to IRQ. */
1558 if (argument == NULL_TREE)
1561 /* Get the value of the argument. */
1562 if (TREE_VALUE (argument) == NULL_TREE
1563 || TREE_CODE (TREE_VALUE (argument)) != STRING_CST)
1564 return ARM_FT_UNKNOWN;
1566 arg = TREE_STRING_POINTER (TREE_VALUE (argument));
1568 /* Check it against the list of known arguments. */
1569 for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)
1570 if (streq (arg, ptr->arg))
1571 return ptr->return_value;
1573 /* An unrecognized interrupt type. */
1574 return ARM_FT_UNKNOWN;
1577 /* Computes the type of the current function. */
1579 static unsigned long
1580 arm_compute_func_type (void)
1582 unsigned long type = ARM_FT_UNKNOWN;
1586 gcc_assert (TREE_CODE (current_function_decl) == FUNCTION_DECL);
1588 /* Decide if the current function is volatile. Such functions
1589 never return, and many memory cycles can be saved by not storing
1590 register values that will never be needed again. This optimization
1591 was added to speed up context switching in a kernel application. */
1593 && (TREE_NOTHROW (current_function_decl)
1594 || !(flag_unwind_tables
1595 || (flag_exceptions && !USING_SJLJ_EXCEPTIONS)))
1596 && TREE_THIS_VOLATILE (current_function_decl))
1597 type |= ARM_FT_VOLATILE;
1599 if (cfun->static_chain_decl != NULL)
1600 type |= ARM_FT_NESTED;
1602 attr = DECL_ATTRIBUTES (current_function_decl);
1604 a = lookup_attribute ("naked", attr);
1606 type |= ARM_FT_NAKED;
1608 a = lookup_attribute ("isr", attr);
1610 a = lookup_attribute ("interrupt", attr);
1613 type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL;
1615 type |= arm_isr_value (TREE_VALUE (a));
1620 /* Returns the type of the current function. */
1623 arm_current_func_type (void)
1625 if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN)
1626 cfun->machine->func_type = arm_compute_func_type ();
1628 return cfun->machine->func_type;
1632 arm_allocate_stack_slots_for_args (void)
1634 /* Naked functions should not allocate stack slots for arguments. */
1635 return !IS_NAKED (arm_current_func_type ());
1639 /* Return 1 if it is possible to return using a single instruction.
1640 If SIBLING is non-null, this is a test for a return before a sibling
1641 call. SIBLING is the call insn, so we can examine its register usage. */
1644 use_return_insn (int iscond, rtx sibling)
1647 unsigned int func_type;
1648 unsigned long saved_int_regs;
1649 unsigned HOST_WIDE_INT stack_adjust;
1650 arm_stack_offsets *offsets;
1652 /* Never use a return instruction before reload has run. */
1653 if (!reload_completed)
1656 func_type = arm_current_func_type ();
1658 /* Naked, volatile and stack alignment functions need special
1660 if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED | ARM_FT_STACKALIGN))
1663 /* So do interrupt functions that use the frame pointer and Thumb
1664 interrupt functions. */
1665 if (IS_INTERRUPT (func_type) && (frame_pointer_needed || TARGET_THUMB))
1668 offsets = arm_get_frame_offsets ();
1669 stack_adjust = offsets->outgoing_args - offsets->saved_regs;
1671 /* As do variadic functions. */
1672 if (crtl->args.pretend_args_size
1673 || cfun->machine->uses_anonymous_args
1674 /* Or if the function calls __builtin_eh_return () */
1675 || crtl->calls_eh_return
1676 /* Or if the function calls alloca */
1677 || cfun->calls_alloca
1678 /* Or if there is a stack adjustment. However, if the stack pointer
1679 is saved on the stack, we can use a pre-incrementing stack load. */
1680 || !(stack_adjust == 0 || (TARGET_APCS_FRAME && frame_pointer_needed
1681 && stack_adjust == 4)))
1684 saved_int_regs = offsets->saved_regs_mask;
1686 /* Unfortunately, the insn
1688 ldmib sp, {..., sp, ...}
1690 triggers a bug on most SA-110 based devices, such that the stack
1691 pointer won't be correctly restored if the instruction takes a
1692 page fault. We work around this problem by popping r3 along with
1693 the other registers, since that is never slower than executing
1694 another instruction.
1696 We test for !arm_arch5 here, because code for any architecture
1697 less than this could potentially be run on one of the buggy
1699 if (stack_adjust == 4 && !arm_arch5 && TARGET_ARM)
1701 /* Validate that r3 is a call-clobbered register (always true in
1702 the default abi) ... */
1703 if (!call_used_regs[3])
1706 /* ... that it isn't being used for a return value ... */
1707 if (arm_size_return_regs () >= (4 * UNITS_PER_WORD))
1710 /* ... or for a tail-call argument ... */
1713 gcc_assert (GET_CODE (sibling) == CALL_INSN);
1715 if (find_regno_fusage (sibling, USE, 3))
1719 /* ... and that there are no call-saved registers in r0-r2
1720 (always true in the default ABI). */
1721 if (saved_int_regs & 0x7)
1725 /* Can't be done if interworking with Thumb, and any registers have been
1727 if (TARGET_INTERWORK && saved_int_regs != 0 && !IS_INTERRUPT(func_type))
1730 /* On StrongARM, conditional returns are expensive if they aren't
1731 taken and multiple registers have been stacked. */
1732 if (iscond && arm_tune_strongarm)
1734 /* Conditional return when just the LR is stored is a simple
1735 conditional-load instruction, that's not expensive. */
1736 if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM))
1740 && arm_pic_register != INVALID_REGNUM
1741 && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM))
1745 /* If there are saved registers but the LR isn't saved, then we need
1746 two instructions for the return. */
1747 if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM)))
1750 /* Can't be done if any of the FPA regs are pushed,
1751 since this also requires an insn. */
1752 if (TARGET_HARD_FLOAT && TARGET_FPA)
1753 for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++)
1754 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
1757 /* Likewise VFP regs. */
1758 if (TARGET_HARD_FLOAT && TARGET_VFP)
1759 for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++)
1760 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
1763 if (TARGET_REALLY_IWMMXT)
1764 for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++)
1765 if (df_regs_ever_live_p (regno) && ! call_used_regs[regno])
1771 /* Return TRUE if int I is a valid immediate ARM constant. */
1774 const_ok_for_arm (HOST_WIDE_INT i)
1778 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
1779 be all zero, or all one. */
1780 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
1781 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
1782 != ((~(unsigned HOST_WIDE_INT) 0)
1783 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
1786 i &= (unsigned HOST_WIDE_INT) 0xffffffff;
1788 /* Fast return for 0 and small values. We must do this for zero, since
1789 the code below can't handle that one case. */
1790 if ((i & ~(unsigned HOST_WIDE_INT) 0xff) == 0)
1793 /* Get the number of trailing zeros. */
1794 lowbit = ffs((int) i) - 1;
1796 /* Only even shifts are allowed in ARM mode so round down to the
1797 nearest even number. */
1801 if ((i & ~(((unsigned HOST_WIDE_INT) 0xff) << lowbit)) == 0)
1806 /* Allow rotated constants in ARM mode. */
1808 && ((i & ~0xc000003f) == 0
1809 || (i & ~0xf000000f) == 0
1810 || (i & ~0xfc000003) == 0))
1817 /* Allow repeated pattern. */
1820 if (i == v || i == (v | (v << 8)))
1827 /* Return true if I is a valid constant for the operation CODE. */
1829 const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code)
1831 if (const_ok_for_arm (i))
1837 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
1839 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
1845 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
1852 /* Emit a sequence of insns to handle a large constant.
1853 CODE is the code of the operation required, it can be any of SET, PLUS,
1854 IOR, AND, XOR, MINUS;
1855 MODE is the mode in which the operation is being performed;
1856 VAL is the integer to operate on;
1857 SOURCE is the other operand (a register, or a null-pointer for SET);
1858 SUBTARGETS means it is safe to create scratch registers if that will
1859 either produce a simpler sequence, or we will want to cse the values.
1860 Return value is the number of insns emitted. */
1862 /* ??? Tweak this for thumb2. */
1864 arm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn,
1865 HOST_WIDE_INT val, rtx target, rtx source, int subtargets)
1869 if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC)
1870 cond = COND_EXEC_TEST (PATTERN (insn));
1874 if (subtargets || code == SET
1875 || (GET_CODE (target) == REG && GET_CODE (source) == REG
1876 && REGNO (target) != REGNO (source)))
1878 /* After arm_reorg has been called, we can't fix up expensive
1879 constants by pushing them into memory so we must synthesize
1880 them in-line, regardless of the cost. This is only likely to
1881 be more costly on chips that have load delay slots and we are
1882 compiling without running the scheduler (so no splitting
1883 occurred before the final instruction emission).
1885 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
1887 if (!after_arm_reorg
1889 && (arm_gen_constant (code, mode, NULL_RTX, val, target, source,
1891 > arm_constant_limit + (code != SET)))
1895 /* Currently SET is the only monadic value for CODE, all
1896 the rest are diadic. */
1897 emit_set_insn (target, GEN_INT (val));
1902 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
1904 emit_set_insn (temp, GEN_INT (val));
1905 /* For MINUS, the value is subtracted from, since we never
1906 have subtraction of a constant. */
1908 emit_set_insn (target, gen_rtx_MINUS (mode, temp, source));
1910 emit_set_insn (target,
1911 gen_rtx_fmt_ee (code, mode, source, temp));
1917 return arm_gen_constant (code, mode, cond, val, target, source, subtargets,
1921 /* Return the number of ARM instructions required to synthesize the given
1924 count_insns_for_constant (HOST_WIDE_INT remainder, int i)
1926 HOST_WIDE_INT temp1;
1934 if (remainder & (3 << (i - 2)))
1939 temp1 = remainder & ((0x0ff << end)
1940 | ((i < end) ? (0xff >> (32 - end)) : 0));
1941 remainder &= ~temp1;
1946 } while (remainder);
1950 /* Emit an instruction with the indicated PATTERN. If COND is
1951 non-NULL, conditionalize the execution of the instruction on COND
1955 emit_constant_insn (rtx cond, rtx pattern)
1958 pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern);
1959 emit_insn (pattern);
1962 /* As above, but extra parameter GENERATE which, if clear, suppresses
1964 /* ??? This needs more work for thumb2. */
1967 arm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond,
1968 HOST_WIDE_INT val, rtx target, rtx source, int subtargets,
1973 int can_negate_initial = 0;
1976 int num_bits_set = 0;
1977 int set_sign_bit_copies = 0;
1978 int clear_sign_bit_copies = 0;
1979 int clear_zero_bit_copies = 0;
1980 int set_zero_bit_copies = 0;
1982 unsigned HOST_WIDE_INT temp1, temp2;
1983 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
1985 /* Find out which operations are safe for a given CODE. Also do a quick
1986 check for degenerate cases; these can occur when DImode operations
1998 can_negate_initial = 1;
2002 if (remainder == 0xffffffff)
2005 emit_constant_insn (cond,
2006 gen_rtx_SET (VOIDmode, target,
2007 GEN_INT (ARM_SIGN_EXTEND (val))));
2012 if (reload_completed && rtx_equal_p (target, source))
2015 emit_constant_insn (cond,
2016 gen_rtx_SET (VOIDmode, target, source));
2025 emit_constant_insn (cond,
2026 gen_rtx_SET (VOIDmode, target, const0_rtx));
2029 if (remainder == 0xffffffff)
2031 if (reload_completed && rtx_equal_p (target, source))
2034 emit_constant_insn (cond,
2035 gen_rtx_SET (VOIDmode, target, source));
2044 if (reload_completed && rtx_equal_p (target, source))
2047 emit_constant_insn (cond,
2048 gen_rtx_SET (VOIDmode, target, source));
2052 /* We don't know how to handle other cases yet. */
2053 gcc_assert (remainder == 0xffffffff);
2056 emit_constant_insn (cond,
2057 gen_rtx_SET (VOIDmode, target,
2058 gen_rtx_NOT (mode, source)));
2062 /* We treat MINUS as (val - source), since (source - val) is always
2063 passed as (source + (-val)). */
2067 emit_constant_insn (cond,
2068 gen_rtx_SET (VOIDmode, target,
2069 gen_rtx_NEG (mode, source)));
2072 if (const_ok_for_arm (val))
2075 emit_constant_insn (cond,
2076 gen_rtx_SET (VOIDmode, target,
2077 gen_rtx_MINUS (mode, GEN_INT (val),
2089 /* If we can do it in one insn get out quickly. */
2090 if (const_ok_for_arm (val)
2091 || (can_negate_initial && const_ok_for_arm (-val))
2092 || (can_invert && const_ok_for_arm (~val)))
2095 emit_constant_insn (cond,
2096 gen_rtx_SET (VOIDmode, target,
2098 ? gen_rtx_fmt_ee (code, mode, source,
2104 /* Calculate a few attributes that may be useful for specific
2106 for (i = 31; i >= 0; i--)
2108 if ((remainder & (1 << i)) == 0)
2109 clear_sign_bit_copies++;
2114 for (i = 31; i >= 0; i--)
2116 if ((remainder & (1 << i)) != 0)
2117 set_sign_bit_copies++;
2122 for (i = 0; i <= 31; i++)
2124 if ((remainder & (1 << i)) == 0)
2125 clear_zero_bit_copies++;
2130 for (i = 0; i <= 31; i++)
2132 if ((remainder & (1 << i)) != 0)
2133 set_zero_bit_copies++;
2141 /* See if we can use movw. */
2142 if (arm_arch_thumb2 && (remainder & 0xffff0000) == 0)
2145 emit_constant_insn (cond, gen_rtx_SET (VOIDmode, target,
2150 /* See if we can do this by sign_extending a constant that is known
2151 to be negative. This is a good, way of doing it, since the shift
2152 may well merge into a subsequent insn. */
2153 if (set_sign_bit_copies > 1)
2155 if (const_ok_for_arm
2156 (temp1 = ARM_SIGN_EXTEND (remainder
2157 << (set_sign_bit_copies - 1))))
2161 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2162 emit_constant_insn (cond,
2163 gen_rtx_SET (VOIDmode, new_src,
2165 emit_constant_insn (cond,
2166 gen_ashrsi3 (target, new_src,
2167 GEN_INT (set_sign_bit_copies - 1)));
2171 /* For an inverted constant, we will need to set the low bits,
2172 these will be shifted out of harm's way. */
2173 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
2174 if (const_ok_for_arm (~temp1))
2178 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2179 emit_constant_insn (cond,
2180 gen_rtx_SET (VOIDmode, new_src,
2182 emit_constant_insn (cond,
2183 gen_ashrsi3 (target, new_src,
2184 GEN_INT (set_sign_bit_copies - 1)));
2190 /* See if we can calculate the value as the difference between two
2191 valid immediates. */
2192 if (clear_sign_bit_copies + clear_zero_bit_copies <= 16)
2194 int topshift = clear_sign_bit_copies & ~1;
2196 temp1 = ARM_SIGN_EXTEND ((remainder + (0x00800000 >> topshift))
2197 & (0xff000000 >> topshift));
2199 /* If temp1 is zero, then that means the 9 most significant
2200 bits of remainder were 1 and we've caused it to overflow.
2201 When topshift is 0 we don't need to do anything since we
2202 can borrow from 'bit 32'. */
2203 if (temp1 == 0 && topshift != 0)
2204 temp1 = 0x80000000 >> (topshift - 1);
2206 temp2 = ARM_SIGN_EXTEND (temp1 - remainder);
2208 if (const_ok_for_arm (temp2))
2212 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2213 emit_constant_insn (cond,
2214 gen_rtx_SET (VOIDmode, new_src,
2216 emit_constant_insn (cond,
2217 gen_addsi3 (target, new_src,
2225 /* See if we can generate this by setting the bottom (or the top)
2226 16 bits, and then shifting these into the other half of the
2227 word. We only look for the simplest cases, to do more would cost
2228 too much. Be careful, however, not to generate this when the
2229 alternative would take fewer insns. */
2230 if (val & 0xffff0000)
2232 temp1 = remainder & 0xffff0000;
2233 temp2 = remainder & 0x0000ffff;
2235 /* Overlaps outside this range are best done using other methods. */
2236 for (i = 9; i < 24; i++)
2238 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
2239 && !const_ok_for_arm (temp2))
2241 rtx new_src = (subtargets
2242 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
2244 insns = arm_gen_constant (code, mode, cond, temp2, new_src,
2245 source, subtargets, generate);
2253 gen_rtx_ASHIFT (mode, source,
2260 /* Don't duplicate cases already considered. */
2261 for (i = 17; i < 24; i++)
2263 if (((temp1 | (temp1 >> i)) == remainder)
2264 && !const_ok_for_arm (temp1))
2266 rtx new_src = (subtargets
2267 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
2269 insns = arm_gen_constant (code, mode, cond, temp1, new_src,
2270 source, subtargets, generate);
2275 gen_rtx_SET (VOIDmode, target,
2278 gen_rtx_LSHIFTRT (mode, source,
2289 /* If we have IOR or XOR, and the constant can be loaded in a
2290 single instruction, and we can find a temporary to put it in,
2291 then this can be done in two instructions instead of 3-4. */
2293 /* TARGET can't be NULL if SUBTARGETS is 0 */
2294 || (reload_completed && !reg_mentioned_p (target, source)))
2296 if (const_ok_for_arm (ARM_SIGN_EXTEND (~val)))
2300 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2302 emit_constant_insn (cond,
2303 gen_rtx_SET (VOIDmode, sub,
2305 emit_constant_insn (cond,
2306 gen_rtx_SET (VOIDmode, target,
2307 gen_rtx_fmt_ee (code, mode,
2317 if (set_sign_bit_copies > 8
2318 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
2322 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2323 rtx shift = GEN_INT (set_sign_bit_copies);
2327 gen_rtx_SET (VOIDmode, sub,
2329 gen_rtx_ASHIFT (mode,
2334 gen_rtx_SET (VOIDmode, target,
2336 gen_rtx_LSHIFTRT (mode, sub,
2342 if (set_zero_bit_copies > 8
2343 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
2347 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2348 rtx shift = GEN_INT (set_zero_bit_copies);
2352 gen_rtx_SET (VOIDmode, sub,
2354 gen_rtx_LSHIFTRT (mode,
2359 gen_rtx_SET (VOIDmode, target,
2361 gen_rtx_ASHIFT (mode, sub,
2367 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val)))
2371 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2372 emit_constant_insn (cond,
2373 gen_rtx_SET (VOIDmode, sub,
2374 gen_rtx_NOT (mode, source)));
2377 sub = gen_reg_rtx (mode);
2378 emit_constant_insn (cond,
2379 gen_rtx_SET (VOIDmode, sub,
2380 gen_rtx_AND (mode, source,
2382 emit_constant_insn (cond,
2383 gen_rtx_SET (VOIDmode, target,
2384 gen_rtx_NOT (mode, sub)));
2391 /* See if two shifts will do 2 or more insn's worth of work. */
2392 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
2394 HOST_WIDE_INT shift_mask = ((0xffffffff
2395 << (32 - clear_sign_bit_copies))
2398 if ((remainder | shift_mask) != 0xffffffff)
2402 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2403 insns = arm_gen_constant (AND, mode, cond,
2404 remainder | shift_mask,
2405 new_src, source, subtargets, 1);
2410 rtx targ = subtargets ? NULL_RTX : target;
2411 insns = arm_gen_constant (AND, mode, cond,
2412 remainder | shift_mask,
2413 targ, source, subtargets, 0);
2419 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2420 rtx shift = GEN_INT (clear_sign_bit_copies);
2422 emit_insn (gen_ashlsi3 (new_src, source, shift));
2423 emit_insn (gen_lshrsi3 (target, new_src, shift));
2429 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
2431 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
2433 if ((remainder | shift_mask) != 0xffffffff)
2437 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2439 insns = arm_gen_constant (AND, mode, cond,
2440 remainder | shift_mask,
2441 new_src, source, subtargets, 1);
2446 rtx targ = subtargets ? NULL_RTX : target;
2448 insns = arm_gen_constant (AND, mode, cond,
2449 remainder | shift_mask,
2450 targ, source, subtargets, 0);
2456 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2457 rtx shift = GEN_INT (clear_zero_bit_copies);
2459 emit_insn (gen_lshrsi3 (new_src, source, shift));
2460 emit_insn (gen_ashlsi3 (target, new_src, shift));
2472 for (i = 0; i < 32; i++)
2473 if (remainder & (1 << i))
2476 if (code == AND || (can_invert && num_bits_set > 16))
2477 remainder = (~remainder) & 0xffffffff;
2478 else if (code == PLUS && num_bits_set > 16)
2479 remainder = (-remainder) & 0xffffffff;
2486 /* Now try and find a way of doing the job in either two or three
2488 We start by looking for the largest block of zeros that are aligned on
2489 a 2-bit boundary, we then fill up the temps, wrapping around to the
2490 top of the word when we drop off the bottom.
2491 In the worst case this code should produce no more than four insns.
2492 Thumb-2 constants are shifted, not rotated, so the MSB is always the
2493 best place to start. */
2495 /* ??? Use thumb2 replicated constants when the high and low halfwords are
2501 int best_consecutive_zeros = 0;
2503 for (i = 0; i < 32; i += 2)
2505 int consecutive_zeros = 0;
2507 if (!(remainder & (3 << i)))
2509 while ((i < 32) && !(remainder & (3 << i)))
2511 consecutive_zeros += 2;
2514 if (consecutive_zeros > best_consecutive_zeros)
2516 best_consecutive_zeros = consecutive_zeros;
2517 best_start = i - consecutive_zeros;
2523 /* So long as it won't require any more insns to do so, it's
2524 desirable to emit a small constant (in bits 0...9) in the last
2525 insn. This way there is more chance that it can be combined with
2526 a later addressing insn to form a pre-indexed load or store
2527 operation. Consider:
2529 *((volatile int *)0xe0000100) = 1;
2530 *((volatile int *)0xe0000110) = 2;
2532 We want this to wind up as:
2536 str rB, [rA, #0x100]
2538 str rB, [rA, #0x110]
2540 rather than having to synthesize both large constants from scratch.
2542 Therefore, we calculate how many insns would be required to emit
2543 the constant starting from `best_start', and also starting from
2544 zero (i.e. with bit 31 first to be output). If `best_start' doesn't
2545 yield a shorter sequence, we may as well use zero. */
2547 && ((((unsigned HOST_WIDE_INT) 1) << best_start) < remainder)
2548 && (count_insns_for_constant (remainder, 0) <=
2549 count_insns_for_constant (remainder, best_start)))
2553 /* Now start emitting the insns. */
2561 if (remainder & (3 << (i - 2)))
2566 temp1 = remainder & ((0x0ff << end)
2567 | ((i < end) ? (0xff >> (32 - end)) : 0));
2568 remainder &= ~temp1;
2572 rtx new_src, temp1_rtx;
2574 if (code == SET || code == MINUS)
2576 new_src = (subtargets ? gen_reg_rtx (mode) : target);
2577 if (can_invert && code != MINUS)
2582 if (remainder && subtargets)
2583 new_src = gen_reg_rtx (mode);
2588 else if (can_negate)
2592 temp1 = trunc_int_for_mode (temp1, mode);
2593 temp1_rtx = GEN_INT (temp1);
2597 else if (code == MINUS)
2598 temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source);
2600 temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx);
2602 emit_constant_insn (cond,
2603 gen_rtx_SET (VOIDmode, new_src,
2613 else if (code == MINUS)
2622 /* Arm allows rotates by a multiple of two. Thumb-2 allows arbitrary
2635 /* Canonicalize a comparison so that we are more likely to recognize it.
2636 This can be done for a few constant compares, where we can make the
2637 immediate value easier to load. */
2640 arm_canonicalize_comparison (enum rtx_code code, enum machine_mode mode,
2643 unsigned HOST_WIDE_INT i = INTVAL (*op1);
2644 unsigned HOST_WIDE_INT maxval;
2645 maxval = (((unsigned HOST_WIDE_INT) 1) << (GET_MODE_BITSIZE(mode) - 1)) - 1;
2656 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
2658 *op1 = GEN_INT (i + 1);
2659 return code == GT ? GE : LT;
2666 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
2668 *op1 = GEN_INT (i - 1);
2669 return code == GE ? GT : LE;
2675 if (i != ~((unsigned HOST_WIDE_INT) 0)
2676 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
2678 *op1 = GEN_INT (i + 1);
2679 return code == GTU ? GEU : LTU;
2686 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
2688 *op1 = GEN_INT (i - 1);
2689 return code == GEU ? GTU : LEU;
2701 /* Define how to find the value returned by a function. */
2704 arm_function_value(const_tree type, const_tree func ATTRIBUTE_UNUSED)
2706 enum machine_mode mode;
2707 int unsignedp ATTRIBUTE_UNUSED;
2708 rtx r ATTRIBUTE_UNUSED;
2710 mode = TYPE_MODE (type);
2711 /* Promote integer types. */
2712 if (INTEGRAL_TYPE_P (type))
2713 PROMOTE_FUNCTION_MODE (mode, unsignedp, type);
2715 /* Promotes small structs returned in a register to full-word size
2716 for big-endian AAPCS. */
2717 if (arm_return_in_msb (type))
2719 HOST_WIDE_INT size = int_size_in_bytes (type);
2720 if (size % UNITS_PER_WORD != 0)
2722 size += UNITS_PER_WORD - size % UNITS_PER_WORD;
2723 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2727 return LIBCALL_VALUE(mode);
2730 /* Determine the amount of memory needed to store the possible return
2731 registers of an untyped call. */
2733 arm_apply_result_size (void)
2739 if (TARGET_HARD_FLOAT_ABI)
2743 if (TARGET_MAVERICK)
2746 if (TARGET_IWMMXT_ABI)
2753 /* Decide whether a type should be returned in memory (true)
2754 or in a register (false). This is called as the target hook
2755 TARGET_RETURN_IN_MEMORY. */
2757 arm_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
2761 size = int_size_in_bytes (type);
2763 /* Vector values should be returned using ARM registers, not memory (unless
2764 they're over 16 bytes, which will break since we only have four
2765 call-clobbered registers to play with). */
2766 if (TREE_CODE (type) == VECTOR_TYPE)
2767 return (size < 0 || size > (4 * UNITS_PER_WORD));
2769 if (!AGGREGATE_TYPE_P (type) &&
2770 !(TARGET_AAPCS_BASED && TREE_CODE (type) == COMPLEX_TYPE))
2771 /* All simple types are returned in registers.
2772 For AAPCS, complex types are treated the same as aggregates. */
2775 if (arm_abi != ARM_ABI_APCS)
2777 /* ATPCS and later return aggregate types in memory only if they are
2778 larger than a word (or are variable size). */
2779 return (size < 0 || size > UNITS_PER_WORD);
2782 /* For the arm-wince targets we choose to be compatible with Microsoft's
2783 ARM and Thumb compilers, which always return aggregates in memory. */
2785 /* All structures/unions bigger than one word are returned in memory.
2786 Also catch the case where int_size_in_bytes returns -1. In this case
2787 the aggregate is either huge or of variable size, and in either case
2788 we will want to return it via memory and not in a register. */
2789 if (size < 0 || size > UNITS_PER_WORD)
2792 if (TREE_CODE (type) == RECORD_TYPE)
2796 /* For a struct the APCS says that we only return in a register
2797 if the type is 'integer like' and every addressable element
2798 has an offset of zero. For practical purposes this means
2799 that the structure can have at most one non bit-field element
2800 and that this element must be the first one in the structure. */
2802 /* Find the first field, ignoring non FIELD_DECL things which will
2803 have been created by C++. */
2804 for (field = TYPE_FIELDS (type);
2805 field && TREE_CODE (field) != FIELD_DECL;
2806 field = TREE_CHAIN (field))
2810 return 0; /* An empty structure. Allowed by an extension to ANSI C. */
2812 /* Check that the first field is valid for returning in a register. */
2814 /* ... Floats are not allowed */
2815 if (FLOAT_TYPE_P (TREE_TYPE (field)))
2818 /* ... Aggregates that are not themselves valid for returning in
2819 a register are not allowed. */
2820 if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE))
2823 /* Now check the remaining fields, if any. Only bitfields are allowed,
2824 since they are not addressable. */
2825 for (field = TREE_CHAIN (field);
2827 field = TREE_CHAIN (field))
2829 if (TREE_CODE (field) != FIELD_DECL)
2832 if (!DECL_BIT_FIELD_TYPE (field))
2839 if (TREE_CODE (type) == UNION_TYPE)
2843 /* Unions can be returned in registers if every element is
2844 integral, or can be returned in an integer register. */
2845 for (field = TYPE_FIELDS (type);
2847 field = TREE_CHAIN (field))
2849 if (TREE_CODE (field) != FIELD_DECL)
2852 if (FLOAT_TYPE_P (TREE_TYPE (field)))
2855 if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE))
2861 #endif /* not ARM_WINCE */
2863 /* Return all other types in memory. */
2867 /* Indicate whether or not words of a double are in big-endian order. */
2870 arm_float_words_big_endian (void)
2872 if (TARGET_MAVERICK)
2875 /* For FPA, float words are always big-endian. For VFP, floats words
2876 follow the memory system mode. */
2884 return (TARGET_BIG_END ? 1 : 0);
2889 /* Initialize a variable CUM of type CUMULATIVE_ARGS
2890 for a call to a function whose data type is FNTYPE.
2891 For a library call, FNTYPE is NULL. */
2893 arm_init_cumulative_args (CUMULATIVE_ARGS *pcum, tree fntype,
2894 rtx libname ATTRIBUTE_UNUSED,
2895 tree fndecl ATTRIBUTE_UNUSED)
2897 /* On the ARM, the offset starts at 0. */
2899 pcum->iwmmxt_nregs = 0;
2900 pcum->can_split = true;
2902 /* Varargs vectors are treated the same as long long.
2903 named_count avoids having to change the way arm handles 'named' */
2904 pcum->named_count = 0;
2907 if (TARGET_REALLY_IWMMXT && fntype)
2911 for (fn_arg = TYPE_ARG_TYPES (fntype);
2913 fn_arg = TREE_CHAIN (fn_arg))
2914 pcum->named_count += 1;
2916 if (! pcum->named_count)
2917 pcum->named_count = INT_MAX;
2922 /* Return true if mode/type need doubleword alignment. */
2924 arm_needs_doubleword_align (enum machine_mode mode, tree type)
2926 return (GET_MODE_ALIGNMENT (mode) > PARM_BOUNDARY
2927 || (type && TYPE_ALIGN (type) > PARM_BOUNDARY));
2931 /* Determine where to put an argument to a function.
2932 Value is zero to push the argument on the stack,
2933 or a hard register in which to store the argument.
2935 MODE is the argument's machine mode.
2936 TYPE is the data type of the argument (as a tree).
2937 This is null for libcalls where that information may
2939 CUM is a variable of type CUMULATIVE_ARGS which gives info about
2940 the preceding args and about the function being called.
2941 NAMED is nonzero if this argument is a named parameter
2942 (otherwise it is an extra parameter matching an ellipsis). */
2945 arm_function_arg (CUMULATIVE_ARGS *pcum, enum machine_mode mode,
2946 tree type, int named)
2950 /* Varargs vectors are treated the same as long long.
2951 named_count avoids having to change the way arm handles 'named' */
2952 if (TARGET_IWMMXT_ABI
2953 && arm_vector_mode_supported_p (mode)
2954 && pcum->named_count > pcum->nargs + 1)
2956 if (pcum->iwmmxt_nregs <= 9)
2957 return gen_rtx_REG (mode, pcum->iwmmxt_nregs + FIRST_IWMMXT_REGNUM);
2960 pcum->can_split = false;
2965 /* Put doubleword aligned quantities in even register pairs. */
2967 && ARM_DOUBLEWORD_ALIGN
2968 && arm_needs_doubleword_align (mode, type))
2971 if (mode == VOIDmode)
2972 /* Pick an arbitrary value for operand 2 of the call insn. */
2975 /* Only allow splitting an arg between regs and memory if all preceding
2976 args were allocated to regs. For args passed by reference we only count
2977 the reference pointer. */
2978 if (pcum->can_split)
2981 nregs = ARM_NUM_REGS2 (mode, type);
2983 if (!named || pcum->nregs + nregs > NUM_ARG_REGS)
2986 return gen_rtx_REG (mode, pcum->nregs);
2990 arm_arg_partial_bytes (CUMULATIVE_ARGS *pcum, enum machine_mode mode,
2991 tree type, bool named ATTRIBUTE_UNUSED)
2993 int nregs = pcum->nregs;
2995 if (TARGET_IWMMXT_ABI && arm_vector_mode_supported_p (mode))
2998 if (NUM_ARG_REGS > nregs
2999 && (NUM_ARG_REGS < nregs + ARM_NUM_REGS2 (mode, type))
3001 return (NUM_ARG_REGS - nregs) * UNITS_PER_WORD;
3006 /* Variable sized types are passed by reference. This is a GCC
3007 extension to the ARM ABI. */
3010 arm_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
3011 enum machine_mode mode ATTRIBUTE_UNUSED,
3012 const_tree type, bool named ATTRIBUTE_UNUSED)
3014 return type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST;
3017 /* Encode the current state of the #pragma [no_]long_calls. */
3020 OFF, /* No #pragma [no_]long_calls is in effect. */
3021 LONG, /* #pragma long_calls is in effect. */
3022 SHORT /* #pragma no_long_calls is in effect. */
3025 static arm_pragma_enum arm_pragma_long_calls = OFF;
3028 arm_pr_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
3030 arm_pragma_long_calls = LONG;
3034 arm_pr_no_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
3036 arm_pragma_long_calls = SHORT;
3040 arm_pr_long_calls_off (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
3042 arm_pragma_long_calls = OFF;
3045 /* Table of machine attributes. */
3046 const struct attribute_spec arm_attribute_table[] =
3048 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
3049 /* Function calls made to this symbol must be done indirectly, because
3050 it may lie outside of the 26 bit addressing range of a normal function
3052 { "long_call", 0, 0, false, true, true, NULL },
3053 /* Whereas these functions are always known to reside within the 26 bit
3054 addressing range. */
3055 { "short_call", 0, 0, false, true, true, NULL },
3056 /* Interrupt Service Routines have special prologue and epilogue requirements. */
3057 { "isr", 0, 1, false, false, false, arm_handle_isr_attribute },
3058 { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute },
3059 { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute },
3061 /* ARM/PE has three new attributes:
3063 dllexport - for exporting a function/variable that will live in a dll
3064 dllimport - for importing a function/variable from a dll
3066 Microsoft allows multiple declspecs in one __declspec, separating
3067 them with spaces. We do NOT support this. Instead, use __declspec
3070 { "dllimport", 0, 0, true, false, false, NULL },
3071 { "dllexport", 0, 0, true, false, false, NULL },
3072 { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute },
3073 #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
3074 { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
3075 { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
3076 { "notshared", 0, 0, false, true, false, arm_handle_notshared_attribute },
3078 { NULL, 0, 0, false, false, false, NULL }
3081 /* Handle an attribute requiring a FUNCTION_DECL;
3082 arguments as in struct attribute_spec.handler. */
3084 arm_handle_fndecl_attribute (tree *node, tree name, tree args ATTRIBUTE_UNUSED,
3085 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
3087 if (TREE_CODE (*node) != FUNCTION_DECL)
3089 warning (OPT_Wattributes, "%qs attribute only applies to functions",
3090 IDENTIFIER_POINTER (name));
3091 *no_add_attrs = true;
3097 /* Handle an "interrupt" or "isr" attribute;
3098 arguments as in struct attribute_spec.handler. */
3100 arm_handle_isr_attribute (tree *node, tree name, tree args, int flags,
3105 if (TREE_CODE (*node) != FUNCTION_DECL)
3107 warning (OPT_Wattributes, "%qs attribute only applies to functions",
3108 IDENTIFIER_POINTER (name));
3109 *no_add_attrs = true;
3111 /* FIXME: the argument if any is checked for type attributes;
3112 should it be checked for decl ones? */
3116 if (TREE_CODE (*node) == FUNCTION_TYPE
3117 || TREE_CODE (*node) == METHOD_TYPE)
3119 if (arm_isr_value (args) == ARM_FT_UNKNOWN)
3121 warning (OPT_Wattributes, "%qs attribute ignored",
3122 IDENTIFIER_POINTER (name));
3123 *no_add_attrs = true;
3126 else if (TREE_CODE (*node) == POINTER_TYPE
3127 && (TREE_CODE (TREE_TYPE (*node)) == FUNCTION_TYPE
3128 || TREE_CODE (TREE_TYPE (*node)) == METHOD_TYPE)
3129 && arm_isr_value (args) != ARM_FT_UNKNOWN)
3131 *node = build_variant_type_copy (*node);
3132 TREE_TYPE (*node) = build_type_attribute_variant
3134 tree_cons (name, args, TYPE_ATTRIBUTES (TREE_TYPE (*node))));
3135 *no_add_attrs = true;
3139 /* Possibly pass this attribute on from the type to a decl. */
3140 if (flags & ((int) ATTR_FLAG_DECL_NEXT
3141 | (int) ATTR_FLAG_FUNCTION_NEXT
3142 | (int) ATTR_FLAG_ARRAY_NEXT))
3144 *no_add_attrs = true;
3145 return tree_cons (name, args, NULL_TREE);
3149 warning (OPT_Wattributes, "%qs attribute ignored",
3150 IDENTIFIER_POINTER (name));
3158 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3159 /* Handle the "notshared" attribute. This attribute is another way of
3160 requesting hidden visibility. ARM's compiler supports
3161 "__declspec(notshared)"; we support the same thing via an
3165 arm_handle_notshared_attribute (tree *node,
3166 tree name ATTRIBUTE_UNUSED,
3167 tree args ATTRIBUTE_UNUSED,
3168 int flags ATTRIBUTE_UNUSED,
3171 tree decl = TYPE_NAME (*node);
3175 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
3176 DECL_VISIBILITY_SPECIFIED (decl) = 1;
3177 *no_add_attrs = false;
3183 /* Return 0 if the attributes for two types are incompatible, 1 if they
3184 are compatible, and 2 if they are nearly compatible (which causes a
3185 warning to be generated). */
3187 arm_comp_type_attributes (const_tree type1, const_tree type2)
3191 /* Check for mismatch of non-default calling convention. */
3192 if (TREE_CODE (type1) != FUNCTION_TYPE)
3195 /* Check for mismatched call attributes. */
3196 l1 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type1)) != NULL;
3197 l2 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type2)) != NULL;
3198 s1 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type1)) != NULL;
3199 s2 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type2)) != NULL;
3201 /* Only bother to check if an attribute is defined. */
3202 if (l1 | l2 | s1 | s2)
3204 /* If one type has an attribute, the other must have the same attribute. */
3205 if ((l1 != l2) || (s1 != s2))
3208 /* Disallow mixed attributes. */
3209 if ((l1 & s2) || (l2 & s1))
3213 /* Check for mismatched ISR attribute. */
3214 l1 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type1)) != NULL;
3216 l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1)) != NULL;
3217 l2 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type2)) != NULL;
3219 l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2)) != NULL;
3226 /* Assigns default attributes to newly defined type. This is used to
3227 set short_call/long_call attributes for function types of
3228 functions defined inside corresponding #pragma scopes. */
3230 arm_set_default_type_attributes (tree type)
3232 /* Add __attribute__ ((long_call)) to all functions, when
3233 inside #pragma long_calls or __attribute__ ((short_call)),
3234 when inside #pragma no_long_calls. */
3235 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
3237 tree type_attr_list, attr_name;
3238 type_attr_list = TYPE_ATTRIBUTES (type);
3240 if (arm_pragma_long_calls == LONG)
3241 attr_name = get_identifier ("long_call");
3242 else if (arm_pragma_long_calls == SHORT)
3243 attr_name = get_identifier ("short_call");
3247 type_attr_list = tree_cons (attr_name, NULL_TREE, type_attr_list);
3248 TYPE_ATTRIBUTES (type) = type_attr_list;
3252 /* Return true if DECL is known to be linked into section SECTION. */
3255 arm_function_in_section_p (tree decl, section *section)
3257 /* We can only be certain about functions defined in the same
3258 compilation unit. */
3259 if (!TREE_STATIC (decl))
3262 /* Make sure that SYMBOL always binds to the definition in this
3263 compilation unit. */
3264 if (!targetm.binds_local_p (decl))
3267 /* If DECL_SECTION_NAME is set, assume it is trustworthy. */
3268 if (!DECL_SECTION_NAME (decl))
3270 /* Only cater for unit-at-a-time mode, where we know that the user
3271 cannot later specify a section for DECL. */
3272 if (!flag_unit_at_a_time)
3275 /* Make sure that we will not create a unique section for DECL. */
3276 if (flag_function_sections || DECL_ONE_ONLY (decl))
3280 return function_section (decl) == section;
3283 /* Return nonzero if a 32-bit "long_call" should be generated for
3284 a call from the current function to DECL. We generate a long_call
3287 a. has an __attribute__((long call))
3288 or b. is within the scope of a #pragma long_calls
3289 or c. the -mlong-calls command line switch has been specified
3291 However we do not generate a long call if the function:
3293 d. has an __attribute__ ((short_call))
3294 or e. is inside the scope of a #pragma no_long_calls
3295 or f. is defined in the same section as the current function. */
3298 arm_is_long_call_p (tree decl)
3303 return TARGET_LONG_CALLS;
3305 attrs = TYPE_ATTRIBUTES (TREE_TYPE (decl));
3306 if (lookup_attribute ("short_call", attrs))
3309 /* For "f", be conservative, and only cater for cases in which the
3310 whole of the current function is placed in the same section. */
3311 if (!flag_reorder_blocks_and_partition
3312 && arm_function_in_section_p (decl, current_function_section ()))
3315 if (lookup_attribute ("long_call", attrs))
3318 return TARGET_LONG_CALLS;
3321 /* Return nonzero if it is ok to make a tail-call to DECL. */
3323 arm_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
3325 unsigned long func_type;
3327 if (cfun->machine->sibcall_blocked)
3330 /* Never tailcall something for which we have no decl, or if we
3331 are in Thumb mode. */
3332 if (decl == NULL || TARGET_THUMB)
3335 /* The PIC register is live on entry to VxWorks PLT entries, so we
3336 must make the call before restoring the PIC register. */
3337 if (TARGET_VXWORKS_RTP && flag_pic && !targetm.binds_local_p (decl))
3340 /* Cannot tail-call to long calls, since these are out of range of
3341 a branch instruction. */
3342 if (arm_is_long_call_p (decl))
3345 /* If we are interworking and the function is not declared static
3346 then we can't tail-call it unless we know that it exists in this
3347 compilation unit (since it might be a Thumb routine). */
3348 if (TARGET_INTERWORK && TREE_PUBLIC (decl) && !TREE_ASM_WRITTEN (decl))
3351 func_type = arm_current_func_type ();
3352 /* Never tailcall from an ISR routine - it needs a special exit sequence. */
3353 if (IS_INTERRUPT (func_type))
3356 /* Never tailcall if function may be called with a misaligned SP. */
3357 if (IS_STACKALIGN (func_type))
3360 /* Everything else is ok. */
3365 /* Addressing mode support functions. */
3367 /* Return nonzero if X is a legitimate immediate operand when compiling
3368 for PIC. We know that X satisfies CONSTANT_P and flag_pic is true. */
3370 legitimate_pic_operand_p (rtx x)
3372 if (GET_CODE (x) == SYMBOL_REF
3373 || (GET_CODE (x) == CONST
3374 && GET_CODE (XEXP (x, 0)) == PLUS
3375 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF))
3381 /* Record that the current function needs a PIC register. Initialize
3382 cfun->machine->pic_reg if we have not already done so. */
3385 require_pic_register (void)
3387 /* A lot of the logic here is made obscure by the fact that this
3388 routine gets called as part of the rtx cost estimation process.
3389 We don't want those calls to affect any assumptions about the real
3390 function; and further, we can't call entry_of_function() until we
3391 start the real expansion process. */
3392 if (!crtl->uses_pic_offset_table)
3394 gcc_assert (can_create_pseudo_p ());
3395 if (arm_pic_register != INVALID_REGNUM)
3397 cfun->machine->pic_reg = gen_rtx_REG (Pmode, arm_pic_register);
3399 /* Play games to avoid marking the function as needing pic
3400 if we are being called as part of the cost-estimation
3402 if (current_ir_type () != IR_GIMPLE)
3403 crtl->uses_pic_offset_table = 1;
3409 cfun->machine->pic_reg = gen_reg_rtx (Pmode);
3411 /* Play games to avoid marking the function as needing pic
3412 if we are being called as part of the cost-estimation
3414 if (current_ir_type () != IR_GIMPLE)
3416 crtl->uses_pic_offset_table = 1;
3419 arm_load_pic_register (0UL);
3423 emit_insn_after (seq, entry_of_function ());
3430 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
3432 if (GET_CODE (orig) == SYMBOL_REF
3433 || GET_CODE (orig) == LABEL_REF)
3435 rtx pic_ref, address;
3439 /* If this function doesn't have a pic register, create one now. */
3440 require_pic_register ();