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 #ifdef TARGET_UNWIND_INFO
170 static void arm_unwind_emit (FILE *, rtx);
171 static bool arm_output_ttype (rtx);
173 static void arm_dwarf_handle_frame_unspec (const char *, rtx, int);
175 static tree arm_cxx_guard_type (void);
176 static bool arm_cxx_guard_mask_bit (void);
177 static tree arm_get_cookie_size (tree);
178 static bool arm_cookie_has_size (void);
179 static bool arm_cxx_cdtor_returns_this (void);
180 static bool arm_cxx_key_method_may_be_inline (void);
181 static void arm_cxx_determine_class_data_visibility (tree);
182 static bool arm_cxx_class_data_always_comdat (void);
183 static bool arm_cxx_use_aeabi_atexit (void);
184 static void arm_init_libfuncs (void);
185 static bool arm_handle_option (size_t, const char *, int);
186 static void arm_target_help (void);
187 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode);
188 static bool arm_cannot_copy_insn_p (rtx);
189 static bool arm_tls_symbol_p (rtx x);
190 static int arm_issue_rate (void);
191 static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
194 /* Initialize the GCC target structure. */
195 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
196 #undef TARGET_MERGE_DECL_ATTRIBUTES
197 #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
200 #undef TARGET_ATTRIBUTE_TABLE
201 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
203 #undef TARGET_ASM_FILE_START
204 #define TARGET_ASM_FILE_START arm_file_start
205 #undef TARGET_ASM_FILE_END
206 #define TARGET_ASM_FILE_END arm_file_end
208 #undef TARGET_ASM_ALIGNED_SI_OP
209 #define TARGET_ASM_ALIGNED_SI_OP NULL
210 #undef TARGET_ASM_INTEGER
211 #define TARGET_ASM_INTEGER arm_assemble_integer
213 #undef TARGET_ASM_FUNCTION_PROLOGUE
214 #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue
216 #undef TARGET_ASM_FUNCTION_EPILOGUE
217 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
219 #undef TARGET_DEFAULT_TARGET_FLAGS
220 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_SCHED_PROLOG)
221 #undef TARGET_HANDLE_OPTION
222 #define TARGET_HANDLE_OPTION arm_handle_option
224 #define TARGET_HELP arm_target_help
226 #undef TARGET_COMP_TYPE_ATTRIBUTES
227 #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes
229 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
230 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes
232 #undef TARGET_SCHED_ADJUST_COST
233 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
235 #undef TARGET_ENCODE_SECTION_INFO
237 #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info
239 #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info
242 #undef TARGET_STRIP_NAME_ENCODING
243 #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding
245 #undef TARGET_ASM_INTERNAL_LABEL
246 #define TARGET_ASM_INTERNAL_LABEL arm_internal_label
248 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
249 #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall
251 #undef TARGET_ASM_OUTPUT_MI_THUNK
252 #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk
253 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
254 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
256 /* This will be overridden in arm_override_options. */
257 #undef TARGET_RTX_COSTS
258 #define TARGET_RTX_COSTS arm_slowmul_rtx_costs
259 #undef TARGET_ADDRESS_COST
260 #define TARGET_ADDRESS_COST arm_address_cost
262 #undef TARGET_SHIFT_TRUNCATION_MASK
263 #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask
264 #undef TARGET_VECTOR_MODE_SUPPORTED_P
265 #define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p
267 #undef TARGET_MACHINE_DEPENDENT_REORG
268 #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg
270 #undef TARGET_INIT_BUILTINS
271 #define TARGET_INIT_BUILTINS arm_init_builtins
272 #undef TARGET_EXPAND_BUILTIN
273 #define TARGET_EXPAND_BUILTIN arm_expand_builtin
275 #undef TARGET_INIT_LIBFUNCS
276 #define TARGET_INIT_LIBFUNCS arm_init_libfuncs
278 #undef TARGET_PROMOTE_FUNCTION_ARGS
279 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_const_tree_true
280 #undef TARGET_PROMOTE_FUNCTION_RETURN
281 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_const_tree_true
282 #undef TARGET_PROMOTE_PROTOTYPES
283 #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes
284 #undef TARGET_PASS_BY_REFERENCE
285 #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference
286 #undef TARGET_ARG_PARTIAL_BYTES
287 #define TARGET_ARG_PARTIAL_BYTES arm_arg_partial_bytes
289 #undef TARGET_SETUP_INCOMING_VARARGS
290 #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs
292 #undef TARGET_DEFAULT_SHORT_ENUMS
293 #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
295 #undef TARGET_ALIGN_ANON_BITFIELD
296 #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield
298 #undef TARGET_NARROW_VOLATILE_BITFIELD
299 #define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
301 #undef TARGET_CXX_GUARD_TYPE
302 #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type
304 #undef TARGET_CXX_GUARD_MASK_BIT
305 #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit
307 #undef TARGET_CXX_GET_COOKIE_SIZE
308 #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size
310 #undef TARGET_CXX_COOKIE_HAS_SIZE
311 #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size
313 #undef TARGET_CXX_CDTOR_RETURNS_THIS
314 #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this
316 #undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE
317 #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline
319 #undef TARGET_CXX_USE_AEABI_ATEXIT
320 #define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit
322 #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY
323 #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \
324 arm_cxx_determine_class_data_visibility
326 #undef TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT
327 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT arm_cxx_class_data_always_comdat
329 #undef TARGET_RETURN_IN_MSB
330 #define TARGET_RETURN_IN_MSB arm_return_in_msb
332 #undef TARGET_MUST_PASS_IN_STACK
333 #define TARGET_MUST_PASS_IN_STACK arm_must_pass_in_stack
335 #ifdef TARGET_UNWIND_INFO
336 #undef TARGET_UNWIND_EMIT
337 #define TARGET_UNWIND_EMIT arm_unwind_emit
339 /* EABI unwinding tables use a different format for the typeinfo tables. */
340 #undef TARGET_ASM_TTYPE
341 #define TARGET_ASM_TTYPE arm_output_ttype
343 #undef TARGET_ARM_EABI_UNWINDER
344 #define TARGET_ARM_EABI_UNWINDER true
345 #endif /* TARGET_UNWIND_INFO */
347 #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC
348 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC arm_dwarf_handle_frame_unspec
350 #undef TARGET_CANNOT_COPY_INSN_P
351 #define TARGET_CANNOT_COPY_INSN_P arm_cannot_copy_insn_p
354 #undef TARGET_HAVE_TLS
355 #define TARGET_HAVE_TLS true
358 #undef TARGET_CANNOT_FORCE_CONST_MEM
359 #define TARGET_CANNOT_FORCE_CONST_MEM arm_cannot_force_const_mem
361 #undef TARGET_SCHED_ISSUE_RATE
362 #define TARGET_SCHED_ISSUE_RATE arm_issue_rate
364 #undef TARGET_MANGLE_TYPE
365 #define TARGET_MANGLE_TYPE arm_mangle_type
368 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
369 #define TARGET_ASM_OUTPUT_DWARF_DTPREL arm_output_dwarf_dtprel
372 struct gcc_target targetm = TARGET_INITIALIZER;
374 /* Obstack for minipool constant handling. */
375 static struct obstack minipool_obstack;
376 static char * minipool_startobj;
378 /* The maximum number of insns skipped which
379 will be conditionalised if possible. */
380 static int max_insns_skipped = 5;
382 extern FILE * asm_out_file;
384 /* True if we are currently building a constant table. */
385 int making_const_table;
387 /* Define the information needed to generate branch insns. This is
388 stored from the compare operation. */
389 rtx arm_compare_op0, arm_compare_op1;
391 /* The processor for which instructions should be scheduled. */
392 enum processor_type arm_tune = arm_none;
394 /* The default processor used if not overridden by commandline. */
395 static enum processor_type arm_default_cpu = arm_none;
397 /* Which floating point model to use. */
398 enum arm_fp_model arm_fp_model;
400 /* Which floating point hardware is available. */
401 enum fputype arm_fpu_arch;
403 /* Which floating point hardware to schedule for. */
404 enum fputype arm_fpu_tune;
406 /* Whether to use floating point hardware. */
407 enum float_abi_type arm_float_abi;
409 /* Which ABI to use. */
410 enum arm_abi_type arm_abi;
412 /* Which thread pointer model to use. */
413 enum arm_tp_type target_thread_pointer = TP_AUTO;
415 /* Used to parse -mstructure_size_boundary command line option. */
416 int arm_structure_size_boundary = DEFAULT_STRUCTURE_SIZE_BOUNDARY;
418 /* Used for Thumb call_via trampolines. */
419 rtx thumb_call_via_label[14];
420 static int thumb_call_reg_needed;
422 /* Bit values used to identify processor capabilities. */
423 #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */
424 #define FL_ARCH3M (1 << 1) /* Extended multiply */
425 #define FL_MODE26 (1 << 2) /* 26-bit mode support */
426 #define FL_MODE32 (1 << 3) /* 32-bit mode support */
427 #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */
428 #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */
429 #define FL_THUMB (1 << 6) /* Thumb aware */
430 #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */
431 #define FL_STRONG (1 << 8) /* StrongARM */
432 #define FL_ARCH5E (1 << 9) /* DSP extensions to v5 */
433 #define FL_XSCALE (1 << 10) /* XScale */
434 #define FL_CIRRUS (1 << 11) /* Cirrus/DSP. */
435 #define FL_ARCH6 (1 << 12) /* Architecture rel 6. Adds
436 media instructions. */
437 #define FL_VFPV2 (1 << 13) /* Vector Floating Point V2. */
438 #define FL_WBUF (1 << 14) /* Schedule for write buffer ops.
439 Note: ARM6 & 7 derivatives only. */
440 #define FL_ARCH6K (1 << 15) /* Architecture rel 6 K extensions. */
441 #define FL_THUMB2 (1 << 16) /* Thumb-2. */
442 #define FL_NOTM (1 << 17) /* Instructions not present in the 'M'
444 #define FL_DIV (1 << 18) /* Hardware divide. */
445 #define FL_VFPV3 (1 << 19) /* Vector Floating Point V3. */
446 #define FL_NEON (1 << 20) /* Neon instructions. */
448 #define FL_IWMMXT (1 << 29) /* XScale v2 or "Intel Wireless MMX technology". */
450 #define FL_FOR_ARCH2 FL_NOTM
451 #define FL_FOR_ARCH3 (FL_FOR_ARCH2 | FL_MODE32)
452 #define FL_FOR_ARCH3M (FL_FOR_ARCH3 | FL_ARCH3M)
453 #define FL_FOR_ARCH4 (FL_FOR_ARCH3M | FL_ARCH4)
454 #define FL_FOR_ARCH4T (FL_FOR_ARCH4 | FL_THUMB)
455 #define FL_FOR_ARCH5 (FL_FOR_ARCH4 | FL_ARCH5)
456 #define FL_FOR_ARCH5T (FL_FOR_ARCH5 | FL_THUMB)
457 #define FL_FOR_ARCH5E (FL_FOR_ARCH5 | FL_ARCH5E)
458 #define FL_FOR_ARCH5TE (FL_FOR_ARCH5E | FL_THUMB)
459 #define FL_FOR_ARCH5TEJ FL_FOR_ARCH5TE
460 #define FL_FOR_ARCH6 (FL_FOR_ARCH5TE | FL_ARCH6)
461 #define FL_FOR_ARCH6J FL_FOR_ARCH6
462 #define FL_FOR_ARCH6K (FL_FOR_ARCH6 | FL_ARCH6K)
463 #define FL_FOR_ARCH6Z FL_FOR_ARCH6
464 #define FL_FOR_ARCH6ZK FL_FOR_ARCH6K
465 #define FL_FOR_ARCH6T2 (FL_FOR_ARCH6 | FL_THUMB2)
466 #define FL_FOR_ARCH6M (FL_FOR_ARCH6 & ~FL_NOTM)
467 #define FL_FOR_ARCH7 (FL_FOR_ARCH6T2 &~ FL_NOTM)
468 #define FL_FOR_ARCH7A (FL_FOR_ARCH7 | FL_NOTM)
469 #define FL_FOR_ARCH7R (FL_FOR_ARCH7A | FL_DIV)
470 #define FL_FOR_ARCH7M (FL_FOR_ARCH7 | FL_DIV)
472 /* The bits in this mask specify which
473 instructions we are allowed to generate. */
474 static unsigned long insn_flags = 0;
476 /* The bits in this mask specify which instruction scheduling options should
478 static unsigned long tune_flags = 0;
480 /* The following are used in the arm.md file as equivalents to bits
481 in the above two flag variables. */
483 /* Nonzero if this chip supports the ARM Architecture 3M extensions. */
486 /* Nonzero if this chip supports the ARM Architecture 4 extensions. */
489 /* Nonzero if this chip supports the ARM Architecture 4t extensions. */
492 /* Nonzero if this chip supports the ARM Architecture 5 extensions. */
495 /* Nonzero if this chip supports the ARM Architecture 5E extensions. */
498 /* Nonzero if this chip supports the ARM Architecture 6 extensions. */
501 /* Nonzero if this chip supports the ARM 6K extensions. */
504 /* Nonzero if instructions not present in the 'M' profile can be used. */
505 int arm_arch_notm = 0;
507 /* Nonzero if this chip can benefit from load scheduling. */
508 int arm_ld_sched = 0;
510 /* Nonzero if this chip is a StrongARM. */
511 int arm_tune_strongarm = 0;
513 /* Nonzero if this chip is a Cirrus variant. */
514 int arm_arch_cirrus = 0;
516 /* Nonzero if this chip supports Intel Wireless MMX technology. */
517 int arm_arch_iwmmxt = 0;
519 /* Nonzero if this chip is an XScale. */
520 int arm_arch_xscale = 0;
522 /* Nonzero if tuning for XScale */
523 int arm_tune_xscale = 0;
525 /* Nonzero if we want to tune for stores that access the write-buffer.
526 This typically means an ARM6 or ARM7 with MMU or MPU. */
527 int arm_tune_wbuf = 0;
529 /* Nonzero if generating Thumb instructions. */
532 /* Nonzero if we should define __THUMB_INTERWORK__ in the
534 XXX This is a bit of a hack, it's intended to help work around
535 problems in GLD which doesn't understand that armv5t code is
536 interworking clean. */
537 int arm_cpp_interwork = 0;
539 /* Nonzero if chip supports Thumb 2. */
542 /* Nonzero if chip supports integer division instruction. */
545 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, we
546 must report the mode of the memory reference from PRINT_OPERAND to
547 PRINT_OPERAND_ADDRESS. */
548 enum machine_mode output_memory_reference_mode;
550 /* The register number to be used for the PIC offset register. */
551 unsigned arm_pic_register = INVALID_REGNUM;
553 /* Set to 1 when a return insn is output, this means that the epilogue
555 int return_used_this_function;
557 /* Set to 1 after arm_reorg has started. Reset to start at the start of
558 the next function. */
559 static int after_arm_reorg = 0;
561 /* The maximum number of insns to be used when loading a constant. */
562 static int arm_constant_limit = 3;
564 /* For an explanation of these variables, see final_prescan_insn below. */
566 /* arm_current_cc is also used for Thumb-2 cond_exec blocks. */
567 enum arm_cond_code arm_current_cc;
569 int arm_target_label;
570 /* The number of conditionally executed insns, including the current insn. */
571 int arm_condexec_count = 0;
572 /* A bitmask specifying the patterns for the IT block.
573 Zero means do not output an IT block before this insn. */
574 int arm_condexec_mask = 0;
575 /* The number of bits used in arm_condexec_mask. */
576 int arm_condexec_masklen = 0;
578 /* The condition codes of the ARM, and the inverse function. */
579 static const char * const arm_condition_codes[] =
581 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
582 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
585 #define ARM_LSL_NAME (TARGET_UNIFIED_ASM ? "lsl" : "asl")
586 #define streq(string1, string2) (strcmp (string1, string2) == 0)
588 #define THUMB2_WORK_REGS (0xff & ~( (1 << THUMB_HARD_FRAME_POINTER_REGNUM) \
589 | (1 << SP_REGNUM) | (1 << PC_REGNUM) \
590 | (1 << PIC_OFFSET_TABLE_REGNUM)))
592 /* Initialization code. */
596 const char *const name;
597 enum processor_type core;
599 const unsigned long flags;
600 bool (* rtx_costs) (rtx, int, int, int *);
603 /* Not all of these give usefully different compilation alternatives,
604 but there is no simple way of generalizing them. */
605 static const struct processors all_cores[] =
608 #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \
609 {NAME, arm_none, #ARCH, FLAGS | FL_FOR_ARCH##ARCH, arm_##COSTS##_rtx_costs},
610 #include "arm-cores.def"
612 {NULL, arm_none, NULL, 0, NULL}
615 static const struct processors all_architectures[] =
617 /* ARM Architectures */
618 /* We don't specify rtx_costs here as it will be figured out
621 {"armv2", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
622 {"armv2a", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
623 {"armv3", arm6, "3", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3, NULL},
624 {"armv3m", arm7m, "3M", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3M, NULL},
625 {"armv4", arm7tdmi, "4", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH4, NULL},
626 /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no
627 implementations that support it, so we will leave it out for now. */
628 {"armv4t", arm7tdmi, "4T", FL_CO_PROC | FL_FOR_ARCH4T, NULL},
629 {"armv5", arm10tdmi, "5", FL_CO_PROC | FL_FOR_ARCH5, NULL},
630 {"armv5t", arm10tdmi, "5T", FL_CO_PROC | FL_FOR_ARCH5T, NULL},
631 {"armv5e", arm1026ejs, "5E", FL_CO_PROC | FL_FOR_ARCH5E, NULL},
632 {"armv5te", arm1026ejs, "5TE", FL_CO_PROC | FL_FOR_ARCH5TE, NULL},
633 {"armv6", arm1136js, "6", FL_CO_PROC | FL_FOR_ARCH6, NULL},
634 {"armv6j", arm1136js, "6J", FL_CO_PROC | FL_FOR_ARCH6J, NULL},
635 {"armv6k", mpcore, "6K", FL_CO_PROC | FL_FOR_ARCH6K, NULL},
636 {"armv6z", arm1176jzs, "6Z", FL_CO_PROC | FL_FOR_ARCH6Z, NULL},
637 {"armv6zk", arm1176jzs, "6ZK", FL_CO_PROC | FL_FOR_ARCH6ZK, NULL},
638 {"armv6t2", arm1156t2s, "6T2", FL_CO_PROC | FL_FOR_ARCH6T2, NULL},
639 {"armv6-m", cortexm1, "6M", FL_FOR_ARCH6M, NULL},
640 {"armv7", cortexa8, "7", FL_CO_PROC | FL_FOR_ARCH7, NULL},
641 {"armv7-a", cortexa8, "7A", FL_CO_PROC | FL_FOR_ARCH7A, NULL},
642 {"armv7-r", cortexr4, "7R", FL_CO_PROC | FL_FOR_ARCH7R, NULL},
643 {"armv7-m", cortexm3, "7M", FL_CO_PROC | FL_FOR_ARCH7M, NULL},
644 {"ep9312", ep9312, "4T", FL_LDSCHED | FL_CIRRUS | FL_FOR_ARCH4, NULL},
645 {"iwmmxt", iwmmxt, "5TE", FL_LDSCHED | FL_STRONG | FL_FOR_ARCH5TE | FL_XSCALE | FL_IWMMXT , NULL},
646 {NULL, arm_none, NULL, 0 , NULL}
649 struct arm_cpu_select
653 const struct processors * processors;
656 /* This is a magic structure. The 'string' field is magically filled in
657 with a pointer to the value specified by the user on the command line
658 assuming that the user has specified such a value. */
660 static struct arm_cpu_select arm_select[] =
662 /* string name processors */
663 { NULL, "-mcpu=", all_cores },
664 { NULL, "-march=", all_architectures },
665 { NULL, "-mtune=", all_cores }
668 /* Defines representing the indexes into the above table. */
669 #define ARM_OPT_SET_CPU 0
670 #define ARM_OPT_SET_ARCH 1
671 #define ARM_OPT_SET_TUNE 2
673 /* The name of the preprocessor macro to define for this architecture. */
675 char arm_arch_name[] = "__ARM_ARCH_0UNK__";
684 /* Available values for -mfpu=. */
686 static const struct fpu_desc all_fpus[] =
688 {"fpa", FPUTYPE_FPA},
689 {"fpe2", FPUTYPE_FPA_EMU2},
690 {"fpe3", FPUTYPE_FPA_EMU2},
691 {"maverick", FPUTYPE_MAVERICK},
692 {"vfp", FPUTYPE_VFP},
693 {"vfp3", FPUTYPE_VFP3},
694 {"neon", FPUTYPE_NEON}
698 /* Floating point models used by the different hardware.
699 See fputype in arm.h. */
701 static const enum fputype fp_model_for_fpu[] =
703 /* No FP hardware. */
704 ARM_FP_MODEL_UNKNOWN, /* FPUTYPE_NONE */
705 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA */
706 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA_EMU2 */
707 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA_EMU3 */
708 ARM_FP_MODEL_MAVERICK, /* FPUTYPE_MAVERICK */
709 ARM_FP_MODEL_VFP, /* FPUTYPE_VFP */
710 ARM_FP_MODEL_VFP, /* FPUTYPE_VFP3 */
711 ARM_FP_MODEL_VFP /* FPUTYPE_NEON */
718 enum float_abi_type abi_type;
722 /* Available values for -mfloat-abi=. */
724 static const struct float_abi all_float_abis[] =
726 {"soft", ARM_FLOAT_ABI_SOFT},
727 {"softfp", ARM_FLOAT_ABI_SOFTFP},
728 {"hard", ARM_FLOAT_ABI_HARD}
735 enum arm_abi_type abi_type;
739 /* Available values for -mabi=. */
741 static const struct abi_name arm_all_abis[] =
743 {"apcs-gnu", ARM_ABI_APCS},
744 {"atpcs", ARM_ABI_ATPCS},
745 {"aapcs", ARM_ABI_AAPCS},
746 {"iwmmxt", ARM_ABI_IWMMXT},
747 {"aapcs-linux", ARM_ABI_AAPCS_LINUX}
750 /* Supported TLS relocations. */
760 /* Emit an insn that's a simple single-set. Both the operands must be known
763 emit_set_insn (rtx x, rtx y)
765 return emit_insn (gen_rtx_SET (VOIDmode, x, y));
768 /* Return the number of bits set in VALUE. */
770 bit_count (unsigned long value)
772 unsigned long count = 0;
777 value &= value - 1; /* Clear the least-significant set bit. */
783 /* Set up library functions unique to ARM. */
786 arm_init_libfuncs (void)
788 /* There are no special library functions unless we are using the
793 /* The functions below are described in Section 4 of the "Run-Time
794 ABI for the ARM architecture", Version 1.0. */
796 /* Double-precision floating-point arithmetic. Table 2. */
797 set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd");
798 set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv");
799 set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul");
800 set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg");
801 set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub");
803 /* Double-precision comparisons. Table 3. */
804 set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq");
805 set_optab_libfunc (ne_optab, DFmode, NULL);
806 set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt");
807 set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple");
808 set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge");
809 set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt");
810 set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun");
812 /* Single-precision floating-point arithmetic. Table 4. */
813 set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd");
814 set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv");
815 set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul");
816 set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg");
817 set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub");
819 /* Single-precision comparisons. Table 5. */
820 set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq");
821 set_optab_libfunc (ne_optab, SFmode, NULL);
822 set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt");
823 set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple");
824 set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge");
825 set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt");
826 set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun");
828 /* Floating-point to integer conversions. Table 6. */
829 set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz");
830 set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz");
831 set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz");
832 set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz");
833 set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz");
834 set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz");
835 set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz");
836 set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz");
838 /* Conversions between floating types. Table 7. */
839 set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f");
840 set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d");
842 /* Integer to floating-point conversions. Table 8. */
843 set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d");
844 set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d");
845 set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d");
846 set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d");
847 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f");
848 set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f");
849 set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f");
850 set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f");
852 /* Long long. Table 9. */
853 set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul");
854 set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod");
855 set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod");
856 set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl");
857 set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr");
858 set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr");
859 set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp");
860 set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp");
862 /* Integer (32/32->32) division. \S 4.3.1. */
863 set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod");
864 set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod");
866 /* The divmod functions are designed so that they can be used for
867 plain division, even though they return both the quotient and the
868 remainder. The quotient is returned in the usual location (i.e.,
869 r0 for SImode, {r0, r1} for DImode), just as would be expected
870 for an ordinary division routine. Because the AAPCS calling
871 conventions specify that all of { r0, r1, r2, r3 } are
872 callee-saved registers, there is no need to tell the compiler
873 explicitly that those registers are clobbered by these
875 set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod");
876 set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod");
878 /* For SImode division the ABI provides div-without-mod routines,
880 set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idiv");
881 set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidiv");
883 /* We don't have mod libcalls. Fortunately gcc knows how to use the
884 divmod libcalls instead. */
885 set_optab_libfunc (smod_optab, DImode, NULL);
886 set_optab_libfunc (umod_optab, DImode, NULL);
887 set_optab_libfunc (smod_optab, SImode, NULL);
888 set_optab_libfunc (umod_optab, SImode, NULL);
891 /* Implement TARGET_HANDLE_OPTION. */
894 arm_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
899 arm_select[1].string = arg;
903 arm_select[0].string = arg;
906 case OPT_mhard_float:
907 target_float_abi_name = "hard";
910 case OPT_msoft_float:
911 target_float_abi_name = "soft";
915 arm_select[2].string = arg;
924 arm_target_help (void)
927 static int columns = 0;
930 /* If we have not done so already, obtain the desired maximum width of
931 the output. Note - this is a duplication of the code at the start of
932 gcc/opts.c:print_specific_help() - the two copies should probably be
933 replaced by a single function. */
938 GET_ENVIRONMENT (p, "COLUMNS");
941 int value = atoi (p);
948 /* Use a reasonable default. */
952 printf (" Known ARM CPUs (for use with the -mcpu= and -mtune= options):\n");
954 /* The - 2 is because we know that the last entry in the array is NULL. */
955 i = ARRAY_SIZE (all_cores) - 2;
957 printf (" %s", all_cores[i].name);
958 remaining = columns - (strlen (all_cores[i].name) + 4);
959 gcc_assert (remaining >= 0);
963 int len = strlen (all_cores[i].name);
965 if (remaining > len + 2)
967 printf (", %s", all_cores[i].name);
968 remaining -= len + 2;
974 printf ("\n %s", all_cores[i].name);
975 remaining = columns - (len + 4);
979 printf ("\n\n Known ARM architectures (for use with the -march= option):\n");
981 i = ARRAY_SIZE (all_architectures) - 2;
984 printf (" %s", all_architectures[i].name);
985 remaining = columns - (strlen (all_architectures[i].name) + 4);
986 gcc_assert (remaining >= 0);
990 int len = strlen (all_architectures[i].name);
992 if (remaining > len + 2)
994 printf (", %s", all_architectures[i].name);
995 remaining -= len + 2;
1001 printf ("\n %s", all_architectures[i].name);
1002 remaining = columns - (len + 4);
1009 /* Fix up any incompatible options that the user has specified.
1010 This has now turned into a maze. */
1012 arm_override_options (void)
1015 enum processor_type target_arch_cpu = arm_none;
1017 /* Set up the flags based on the cpu/architecture selected by the user. */
1018 for (i = ARRAY_SIZE (arm_select); i--;)
1020 struct arm_cpu_select * ptr = arm_select + i;
1022 if (ptr->string != NULL && ptr->string[0] != '\0')
1024 const struct processors * sel;
1026 for (sel = ptr->processors; sel->name != NULL; sel++)
1027 if (streq (ptr->string, sel->name))
1029 /* Set the architecture define. */
1030 if (i != ARM_OPT_SET_TUNE)
1031 sprintf (arm_arch_name, "__ARM_ARCH_%s__", sel->arch);
1033 /* Determine the processor core for which we should
1034 tune code-generation. */
1035 if (/* -mcpu= is a sensible default. */
1036 i == ARM_OPT_SET_CPU
1037 /* -mtune= overrides -mcpu= and -march=. */
1038 || i == ARM_OPT_SET_TUNE)
1039 arm_tune = (enum processor_type) (sel - ptr->processors);
1041 /* Remember the CPU associated with this architecture.
1042 If no other option is used to set the CPU type,
1043 we'll use this to guess the most suitable tuning
1045 if (i == ARM_OPT_SET_ARCH)
1046 target_arch_cpu = sel->core;
1048 if (i != ARM_OPT_SET_TUNE)
1050 /* If we have been given an architecture and a processor
1051 make sure that they are compatible. We only generate
1052 a warning though, and we prefer the CPU over the
1054 if (insn_flags != 0 && (insn_flags ^ sel->flags))
1055 warning (0, "switch -mcpu=%s conflicts with -march= switch",
1058 insn_flags = sel->flags;
1064 if (sel->name == NULL)
1065 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
1069 /* Guess the tuning options from the architecture if necessary. */
1070 if (arm_tune == arm_none)
1071 arm_tune = target_arch_cpu;
1073 /* If the user did not specify a processor, choose one for them. */
1074 if (insn_flags == 0)
1076 const struct processors * sel;
1077 unsigned int sought;
1078 enum processor_type cpu;
1080 cpu = TARGET_CPU_DEFAULT;
1081 if (cpu == arm_none)
1083 #ifdef SUBTARGET_CPU_DEFAULT
1084 /* Use the subtarget default CPU if none was specified by
1086 cpu = SUBTARGET_CPU_DEFAULT;
1088 /* Default to ARM6. */
1089 if (cpu == arm_none)
1092 sel = &all_cores[cpu];
1094 insn_flags = sel->flags;
1096 /* Now check to see if the user has specified some command line
1097 switch that require certain abilities from the cpu. */
1100 if (TARGET_INTERWORK || TARGET_THUMB)
1102 sought |= (FL_THUMB | FL_MODE32);
1104 /* There are no ARM processors that support both APCS-26 and
1105 interworking. Therefore we force FL_MODE26 to be removed
1106 from insn_flags here (if it was set), so that the search
1107 below will always be able to find a compatible processor. */
1108 insn_flags &= ~FL_MODE26;
1111 if (sought != 0 && ((sought & insn_flags) != sought))
1113 /* Try to locate a CPU type that supports all of the abilities
1114 of the default CPU, plus the extra abilities requested by
1116 for (sel = all_cores; sel->name != NULL; sel++)
1117 if ((sel->flags & sought) == (sought | insn_flags))
1120 if (sel->name == NULL)
1122 unsigned current_bit_count = 0;
1123 const struct processors * best_fit = NULL;
1125 /* Ideally we would like to issue an error message here
1126 saying that it was not possible to find a CPU compatible
1127 with the default CPU, but which also supports the command
1128 line options specified by the programmer, and so they
1129 ought to use the -mcpu=<name> command line option to
1130 override the default CPU type.
1132 If we cannot find a cpu that has both the
1133 characteristics of the default cpu and the given
1134 command line options we scan the array again looking
1135 for a best match. */
1136 for (sel = all_cores; sel->name != NULL; sel++)
1137 if ((sel->flags & sought) == sought)
1141 count = bit_count (sel->flags & insn_flags);
1143 if (count >= current_bit_count)
1146 current_bit_count = count;
1150 gcc_assert (best_fit);
1154 insn_flags = sel->flags;
1156 sprintf (arm_arch_name, "__ARM_ARCH_%s__", sel->arch);
1157 arm_default_cpu = (enum processor_type) (sel - all_cores);
1158 if (arm_tune == arm_none)
1159 arm_tune = arm_default_cpu;
1162 /* The processor for which we should tune should now have been
1164 gcc_assert (arm_tune != arm_none);
1166 tune_flags = all_cores[(int)arm_tune].flags;
1168 targetm.rtx_costs = arm_size_rtx_costs;
1170 targetm.rtx_costs = all_cores[(int)arm_tune].rtx_costs;
1172 /* Make sure that the processor choice does not conflict with any of the
1173 other command line choices. */
1174 if (TARGET_ARM && !(insn_flags & FL_NOTM))
1175 error ("target CPU does not support ARM mode");
1177 if (TARGET_INTERWORK && !(insn_flags & FL_THUMB))
1179 warning (0, "target CPU does not support interworking" );
1180 target_flags &= ~MASK_INTERWORK;
1183 if (TARGET_THUMB && !(insn_flags & FL_THUMB))
1185 warning (0, "target CPU does not support THUMB instructions");
1186 target_flags &= ~MASK_THUMB;
1189 if (TARGET_APCS_FRAME && TARGET_THUMB)
1191 /* warning (0, "ignoring -mapcs-frame because -mthumb was used"); */
1192 target_flags &= ~MASK_APCS_FRAME;
1195 /* Callee super interworking implies thumb interworking. Adding
1196 this to the flags here simplifies the logic elsewhere. */
1197 if (TARGET_THUMB && TARGET_CALLEE_INTERWORKING)
1198 target_flags |= MASK_INTERWORK;
1200 /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done
1201 from here where no function is being compiled currently. */
1202 if ((TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) && TARGET_ARM)
1203 warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb");
1205 if (TARGET_ARM && TARGET_CALLEE_INTERWORKING)
1206 warning (0, "enabling callee interworking support is only meaningful when compiling for the Thumb");
1208 if (TARGET_ARM && TARGET_CALLER_INTERWORKING)
1209 warning (0, "enabling caller interworking support is only meaningful when compiling for the Thumb");
1211 if (TARGET_APCS_STACK && !TARGET_APCS_FRAME)
1213 warning (0, "-mapcs-stack-check incompatible with -mno-apcs-frame");
1214 target_flags |= MASK_APCS_FRAME;
1217 if (TARGET_POKE_FUNCTION_NAME)
1218 target_flags |= MASK_APCS_FRAME;
1220 if (TARGET_APCS_REENT && flag_pic)
1221 error ("-fpic and -mapcs-reent are incompatible");
1223 if (TARGET_APCS_REENT)
1224 warning (0, "APCS reentrant code not supported. Ignored");
1226 /* If this target is normally configured to use APCS frames, warn if they
1227 are turned off and debugging is turned on. */
1229 && write_symbols != NO_DEBUG
1230 && !TARGET_APCS_FRAME
1231 && (TARGET_DEFAULT & MASK_APCS_FRAME))
1232 warning (0, "-g with -mno-apcs-frame may not give sensible debugging");
1234 if (TARGET_APCS_FLOAT)
1235 warning (0, "passing floating point arguments in fp regs not yet supported");
1237 /* Initialize boolean versions of the flags, for use in the arm.md file. */
1238 arm_arch3m = (insn_flags & FL_ARCH3M) != 0;
1239 arm_arch4 = (insn_flags & FL_ARCH4) != 0;
1240 arm_arch4t = arm_arch4 & ((insn_flags & FL_THUMB) != 0);
1241 arm_arch5 = (insn_flags & FL_ARCH5) != 0;
1242 arm_arch5e = (insn_flags & FL_ARCH5E) != 0;
1243 arm_arch6 = (insn_flags & FL_ARCH6) != 0;
1244 arm_arch6k = (insn_flags & FL_ARCH6K) != 0;
1245 arm_arch_notm = (insn_flags & FL_NOTM) != 0;
1246 arm_arch_thumb2 = (insn_flags & FL_THUMB2) != 0;
1247 arm_arch_xscale = (insn_flags & FL_XSCALE) != 0;
1248 arm_arch_cirrus = (insn_flags & FL_CIRRUS) != 0;
1250 arm_ld_sched = (tune_flags & FL_LDSCHED) != 0;
1251 arm_tune_strongarm = (tune_flags & FL_STRONG) != 0;
1252 thumb_code = (TARGET_ARM == 0);
1253 arm_tune_wbuf = (tune_flags & FL_WBUF) != 0;
1254 arm_tune_xscale = (tune_flags & FL_XSCALE) != 0;
1255 arm_arch_iwmmxt = (insn_flags & FL_IWMMXT) != 0;
1256 arm_arch_hwdiv = (insn_flags & FL_DIV) != 0;
1258 /* V5 code we generate is completely interworking capable, so we turn off
1259 TARGET_INTERWORK here to avoid many tests later on. */
1261 /* XXX However, we must pass the right pre-processor defines to CPP
1262 or GLD can get confused. This is a hack. */
1263 if (TARGET_INTERWORK)
1264 arm_cpp_interwork = 1;
1267 target_flags &= ~MASK_INTERWORK;
1269 if (target_abi_name)
1271 for (i = 0; i < ARRAY_SIZE (arm_all_abis); i++)
1273 if (streq (arm_all_abis[i].name, target_abi_name))
1275 arm_abi = arm_all_abis[i].abi_type;
1279 if (i == ARRAY_SIZE (arm_all_abis))
1280 error ("invalid ABI option: -mabi=%s", target_abi_name);
1283 arm_abi = ARM_DEFAULT_ABI;
1285 if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN)
1286 error ("iwmmxt requires an AAPCS compatible ABI for proper operation");
1288 if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT)
1289 error ("iwmmxt abi requires an iwmmxt capable cpu");
1291 arm_fp_model = ARM_FP_MODEL_UNKNOWN;
1292 if (target_fpu_name == NULL && target_fpe_name != NULL)
1294 if (streq (target_fpe_name, "2"))
1295 target_fpu_name = "fpe2";
1296 else if (streq (target_fpe_name, "3"))
1297 target_fpu_name = "fpe3";
1299 error ("invalid floating point emulation option: -mfpe=%s",
1302 if (target_fpu_name != NULL)
1304 /* The user specified a FPU. */
1305 for (i = 0; i < ARRAY_SIZE (all_fpus); i++)
1307 if (streq (all_fpus[i].name, target_fpu_name))
1309 arm_fpu_arch = all_fpus[i].fpu;
1310 arm_fpu_tune = arm_fpu_arch;
1311 arm_fp_model = fp_model_for_fpu[arm_fpu_arch];
1315 if (arm_fp_model == ARM_FP_MODEL_UNKNOWN)
1316 error ("invalid floating point option: -mfpu=%s", target_fpu_name);
1320 #ifdef FPUTYPE_DEFAULT
1321 /* Use the default if it is specified for this platform. */
1322 arm_fpu_arch = FPUTYPE_DEFAULT;
1323 arm_fpu_tune = FPUTYPE_DEFAULT;
1325 /* Pick one based on CPU type. */
1326 /* ??? Some targets assume FPA is the default.
1327 if ((insn_flags & FL_VFP) != 0)
1328 arm_fpu_arch = FPUTYPE_VFP;
1331 if (arm_arch_cirrus)
1332 arm_fpu_arch = FPUTYPE_MAVERICK;
1334 arm_fpu_arch = FPUTYPE_FPA_EMU2;
1336 if (tune_flags & FL_CO_PROC && arm_fpu_arch == FPUTYPE_FPA_EMU2)
1337 arm_fpu_tune = FPUTYPE_FPA;
1339 arm_fpu_tune = arm_fpu_arch;
1340 arm_fp_model = fp_model_for_fpu[arm_fpu_arch];
1341 gcc_assert (arm_fp_model != ARM_FP_MODEL_UNKNOWN);
1344 if (target_float_abi_name != NULL)
1346 /* The user specified a FP ABI. */
1347 for (i = 0; i < ARRAY_SIZE (all_float_abis); i++)
1349 if (streq (all_float_abis[i].name, target_float_abi_name))
1351 arm_float_abi = all_float_abis[i].abi_type;
1355 if (i == ARRAY_SIZE (all_float_abis))
1356 error ("invalid floating point abi: -mfloat-abi=%s",
1357 target_float_abi_name);
1360 arm_float_abi = TARGET_DEFAULT_FLOAT_ABI;
1362 if (arm_float_abi == ARM_FLOAT_ABI_HARD && TARGET_VFP)
1363 sorry ("-mfloat-abi=hard and VFP");
1365 /* FPA and iWMMXt are incompatible because the insn encodings overlap.
1366 VFP and iWMMXt can theoretically coexist, but it's unlikely such silicon
1367 will ever exist. GCC makes no attempt to support this combination. */
1368 if (TARGET_IWMMXT && !TARGET_SOFT_FLOAT)
1369 sorry ("iWMMXt and hardware floating point");
1371 /* ??? iWMMXt insn patterns need auditing for Thumb-2. */
1372 if (TARGET_THUMB2 && TARGET_IWMMXT)
1373 sorry ("Thumb-2 iWMMXt");
1375 /* If soft-float is specified then don't use FPU. */
1376 if (TARGET_SOFT_FLOAT)
1377 arm_fpu_arch = FPUTYPE_NONE;
1379 /* For arm2/3 there is no need to do any scheduling if there is only
1380 a floating point emulator, or we are doing software floating-point. */
1381 if ((TARGET_SOFT_FLOAT
1382 || arm_fpu_tune == FPUTYPE_FPA_EMU2
1383 || arm_fpu_tune == FPUTYPE_FPA_EMU3)
1384 && (tune_flags & FL_MODE32) == 0)
1385 flag_schedule_insns = flag_schedule_insns_after_reload = 0;
1387 if (target_thread_switch)
1389 if (strcmp (target_thread_switch, "soft") == 0)
1390 target_thread_pointer = TP_SOFT;
1391 else if (strcmp (target_thread_switch, "auto") == 0)
1392 target_thread_pointer = TP_AUTO;
1393 else if (strcmp (target_thread_switch, "cp15") == 0)
1394 target_thread_pointer = TP_CP15;
1396 error ("invalid thread pointer option: -mtp=%s", target_thread_switch);
1399 /* Use the cp15 method if it is available. */
1400 if (target_thread_pointer == TP_AUTO)
1402 if (arm_arch6k && !TARGET_THUMB)
1403 target_thread_pointer = TP_CP15;
1405 target_thread_pointer = TP_SOFT;
1408 if (TARGET_HARD_TP && TARGET_THUMB1)
1409 error ("can not use -mtp=cp15 with 16-bit Thumb");
1411 /* Override the default structure alignment for AAPCS ABI. */
1412 if (TARGET_AAPCS_BASED)
1413 arm_structure_size_boundary = 8;
1415 if (structure_size_string != NULL)
1417 int size = strtol (structure_size_string, NULL, 0);
1419 if (size == 8 || size == 32
1420 || (ARM_DOUBLEWORD_ALIGN && size == 64))
1421 arm_structure_size_boundary = size;
1423 warning (0, "structure size boundary can only be set to %s",
1424 ARM_DOUBLEWORD_ALIGN ? "8, 32 or 64": "8 or 32");
1427 if (!TARGET_ARM && TARGET_VXWORKS_RTP && flag_pic)
1429 error ("RTP PIC is incompatible with Thumb");
1433 /* If stack checking is disabled, we can use r10 as the PIC register,
1434 which keeps r9 available. The EABI specifies r9 as the PIC register. */
1435 if (flag_pic && TARGET_SINGLE_PIC_BASE)
1437 if (TARGET_VXWORKS_RTP)
1438 warning (0, "RTP PIC is incompatible with -msingle-pic-base");
1439 arm_pic_register = (TARGET_APCS_STACK || TARGET_AAPCS_BASED) ? 9 : 10;
1442 if (flag_pic && TARGET_VXWORKS_RTP)
1443 arm_pic_register = 9;
1445 if (arm_pic_register_string != NULL)
1447 int pic_register = decode_reg_name (arm_pic_register_string);
1450 warning (0, "-mpic-register= is useless without -fpic");
1452 /* Prevent the user from choosing an obviously stupid PIC register. */
1453 else if (pic_register < 0 || call_used_regs[pic_register]
1454 || pic_register == HARD_FRAME_POINTER_REGNUM
1455 || pic_register == STACK_POINTER_REGNUM
1456 || pic_register >= PC_REGNUM
1457 || (TARGET_VXWORKS_RTP
1458 && (unsigned int) pic_register != arm_pic_register))
1459 error ("unable to use '%s' for PIC register", arm_pic_register_string);
1461 arm_pic_register = pic_register;
1464 /* ??? We might want scheduling for thumb2. */
1465 if (TARGET_THUMB && flag_schedule_insns)
1467 /* Don't warn since it's on by default in -O2. */
1468 flag_schedule_insns = 0;
1473 arm_constant_limit = 1;
1475 /* If optimizing for size, bump the number of instructions that we
1476 are prepared to conditionally execute (even on a StrongARM). */
1477 max_insns_skipped = 6;
1481 /* For processors with load scheduling, it never costs more than
1482 2 cycles to load a constant, and the load scheduler may well
1483 reduce that to 1. */
1485 arm_constant_limit = 1;
1487 /* On XScale the longer latency of a load makes it more difficult
1488 to achieve a good schedule, so it's faster to synthesize
1489 constants that can be done in two insns. */
1490 if (arm_tune_xscale)
1491 arm_constant_limit = 2;
1493 /* StrongARM has early execution of branches, so a sequence
1494 that is worth skipping is shorter. */
1495 if (arm_tune_strongarm)
1496 max_insns_skipped = 3;
1499 /* Register global variables with the garbage collector. */
1500 arm_add_gc_roots ();
1504 arm_add_gc_roots (void)
1506 gcc_obstack_init(&minipool_obstack);
1507 minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0);
1510 /* A table of known ARM exception types.
1511 For use with the interrupt function attribute. */
1515 const char *const arg;
1516 const unsigned long return_value;
1520 static const isr_attribute_arg isr_attribute_args [] =
1522 { "IRQ", ARM_FT_ISR },
1523 { "irq", ARM_FT_ISR },
1524 { "FIQ", ARM_FT_FIQ },
1525 { "fiq", ARM_FT_FIQ },
1526 { "ABORT", ARM_FT_ISR },
1527 { "abort", ARM_FT_ISR },
1528 { "ABORT", ARM_FT_ISR },
1529 { "abort", ARM_FT_ISR },
1530 { "UNDEF", ARM_FT_EXCEPTION },
1531 { "undef", ARM_FT_EXCEPTION },
1532 { "SWI", ARM_FT_EXCEPTION },
1533 { "swi", ARM_FT_EXCEPTION },
1534 { NULL, ARM_FT_NORMAL }
1537 /* Returns the (interrupt) function type of the current
1538 function, or ARM_FT_UNKNOWN if the type cannot be determined. */
1540 static unsigned long
1541 arm_isr_value (tree argument)
1543 const isr_attribute_arg * ptr;
1547 return ARM_FT_NORMAL | ARM_FT_STACKALIGN;
1549 /* No argument - default to IRQ. */
1550 if (argument == NULL_TREE)
1553 /* Get the value of the argument. */
1554 if (TREE_VALUE (argument) == NULL_TREE
1555 || TREE_CODE (TREE_VALUE (argument)) != STRING_CST)
1556 return ARM_FT_UNKNOWN;
1558 arg = TREE_STRING_POINTER (TREE_VALUE (argument));
1560 /* Check it against the list of known arguments. */
1561 for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)
1562 if (streq (arg, ptr->arg))
1563 return ptr->return_value;
1565 /* An unrecognized interrupt type. */
1566 return ARM_FT_UNKNOWN;
1569 /* Computes the type of the current function. */
1571 static unsigned long
1572 arm_compute_func_type (void)
1574 unsigned long type = ARM_FT_UNKNOWN;
1578 gcc_assert (TREE_CODE (current_function_decl) == FUNCTION_DECL);
1580 /* Decide if the current function is volatile. Such functions
1581 never return, and many memory cycles can be saved by not storing
1582 register values that will never be needed again. This optimization
1583 was added to speed up context switching in a kernel application. */
1585 && (TREE_NOTHROW (current_function_decl)
1586 || !(flag_unwind_tables
1587 || (flag_exceptions && !USING_SJLJ_EXCEPTIONS)))
1588 && TREE_THIS_VOLATILE (current_function_decl))
1589 type |= ARM_FT_VOLATILE;
1591 if (cfun->static_chain_decl != NULL)
1592 type |= ARM_FT_NESTED;
1594 attr = DECL_ATTRIBUTES (current_function_decl);
1596 a = lookup_attribute ("naked", attr);
1598 type |= ARM_FT_NAKED;
1600 a = lookup_attribute ("isr", attr);
1602 a = lookup_attribute ("interrupt", attr);
1605 type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL;
1607 type |= arm_isr_value (TREE_VALUE (a));
1612 /* Returns the type of the current function. */
1615 arm_current_func_type (void)
1617 if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN)
1618 cfun->machine->func_type = arm_compute_func_type ();
1620 return cfun->machine->func_type;
1623 /* Return 1 if it is possible to return using a single instruction.
1624 If SIBLING is non-null, this is a test for a return before a sibling
1625 call. SIBLING is the call insn, so we can examine its register usage. */
1628 use_return_insn (int iscond, rtx sibling)
1631 unsigned int func_type;
1632 unsigned long saved_int_regs;
1633 unsigned HOST_WIDE_INT stack_adjust;
1634 arm_stack_offsets *offsets;
1636 /* Never use a return instruction before reload has run. */
1637 if (!reload_completed)
1640 func_type = arm_current_func_type ();
1642 /* Naked, volatile and stack alignment functions need special
1644 if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED | ARM_FT_STACKALIGN))
1647 /* So do interrupt functions that use the frame pointer and Thumb
1648 interrupt functions. */
1649 if (IS_INTERRUPT (func_type) && (frame_pointer_needed || TARGET_THUMB))
1652 offsets = arm_get_frame_offsets ();
1653 stack_adjust = offsets->outgoing_args - offsets->saved_regs;
1655 /* As do variadic functions. */
1656 if (crtl->args.pretend_args_size
1657 || cfun->machine->uses_anonymous_args
1658 /* Or if the function calls __builtin_eh_return () */
1659 || current_function_calls_eh_return
1660 /* Or if the function calls alloca */
1661 || current_function_calls_alloca
1662 /* Or if there is a stack adjustment. However, if the stack pointer
1663 is saved on the stack, we can use a pre-incrementing stack load. */
1664 || !(stack_adjust == 0 || (TARGET_APCS_FRAME && frame_pointer_needed
1665 && stack_adjust == 4)))
1668 saved_int_regs = offsets->saved_regs_mask;
1670 /* Unfortunately, the insn
1672 ldmib sp, {..., sp, ...}
1674 triggers a bug on most SA-110 based devices, such that the stack
1675 pointer won't be correctly restored if the instruction takes a
1676 page fault. We work around this problem by popping r3 along with
1677 the other registers, since that is never slower than executing
1678 another instruction.
1680 We test for !arm_arch5 here, because code for any architecture
1681 less than this could potentially be run on one of the buggy
1683 if (stack_adjust == 4 && !arm_arch5 && TARGET_ARM)
1685 /* Validate that r3 is a call-clobbered register (always true in
1686 the default abi) ... */
1687 if (!call_used_regs[3])
1690 /* ... that it isn't being used for a return value ... */
1691 if (arm_size_return_regs () >= (4 * UNITS_PER_WORD))
1694 /* ... or for a tail-call argument ... */
1697 gcc_assert (GET_CODE (sibling) == CALL_INSN);
1699 if (find_regno_fusage (sibling, USE, 3))
1703 /* ... and that there are no call-saved registers in r0-r2
1704 (always true in the default ABI). */
1705 if (saved_int_regs & 0x7)
1709 /* Can't be done if interworking with Thumb, and any registers have been
1711 if (TARGET_INTERWORK && saved_int_regs != 0 && !IS_INTERRUPT(func_type))
1714 /* On StrongARM, conditional returns are expensive if they aren't
1715 taken and multiple registers have been stacked. */
1716 if (iscond && arm_tune_strongarm)
1718 /* Conditional return when just the LR is stored is a simple
1719 conditional-load instruction, that's not expensive. */
1720 if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM))
1724 && arm_pic_register != INVALID_REGNUM
1725 && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM))
1729 /* If there are saved registers but the LR isn't saved, then we need
1730 two instructions for the return. */
1731 if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM)))
1734 /* Can't be done if any of the FPA regs are pushed,
1735 since this also requires an insn. */
1736 if (TARGET_HARD_FLOAT && TARGET_FPA)
1737 for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++)
1738 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
1741 /* Likewise VFP regs. */
1742 if (TARGET_HARD_FLOAT && TARGET_VFP)
1743 for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++)
1744 if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
1747 if (TARGET_REALLY_IWMMXT)
1748 for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++)
1749 if (df_regs_ever_live_p (regno) && ! call_used_regs[regno])
1755 /* Return TRUE if int I is a valid immediate ARM constant. */
1758 const_ok_for_arm (HOST_WIDE_INT i)
1762 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
1763 be all zero, or all one. */
1764 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
1765 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
1766 != ((~(unsigned HOST_WIDE_INT) 0)
1767 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
1770 i &= (unsigned HOST_WIDE_INT) 0xffffffff;
1772 /* Fast return for 0 and small values. We must do this for zero, since
1773 the code below can't handle that one case. */
1774 if ((i & ~(unsigned HOST_WIDE_INT) 0xff) == 0)
1777 /* Get the number of trailing zeros. */
1778 lowbit = ffs((int) i) - 1;
1780 /* Only even shifts are allowed in ARM mode so round down to the
1781 nearest even number. */
1785 if ((i & ~(((unsigned HOST_WIDE_INT) 0xff) << lowbit)) == 0)
1790 /* Allow rotated constants in ARM mode. */
1792 && ((i & ~0xc000003f) == 0
1793 || (i & ~0xf000000f) == 0
1794 || (i & ~0xfc000003) == 0))
1801 /* Allow repeated pattern. */
1804 if (i == v || i == (v | (v << 8)))
1811 /* Return true if I is a valid constant for the operation CODE. */
1813 const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code)
1815 if (const_ok_for_arm (i))
1821 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
1823 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
1829 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
1836 /* Emit a sequence of insns to handle a large constant.
1837 CODE is the code of the operation required, it can be any of SET, PLUS,
1838 IOR, AND, XOR, MINUS;
1839 MODE is the mode in which the operation is being performed;
1840 VAL is the integer to operate on;
1841 SOURCE is the other operand (a register, or a null-pointer for SET);
1842 SUBTARGETS means it is safe to create scratch registers if that will
1843 either produce a simpler sequence, or we will want to cse the values.
1844 Return value is the number of insns emitted. */
1846 /* ??? Tweak this for thumb2. */
1848 arm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn,
1849 HOST_WIDE_INT val, rtx target, rtx source, int subtargets)
1853 if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC)
1854 cond = COND_EXEC_TEST (PATTERN (insn));
1858 if (subtargets || code == SET
1859 || (GET_CODE (target) == REG && GET_CODE (source) == REG
1860 && REGNO (target) != REGNO (source)))
1862 /* After arm_reorg has been called, we can't fix up expensive
1863 constants by pushing them into memory so we must synthesize
1864 them in-line, regardless of the cost. This is only likely to
1865 be more costly on chips that have load delay slots and we are
1866 compiling without running the scheduler (so no splitting
1867 occurred before the final instruction emission).
1869 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
1871 if (!after_arm_reorg
1873 && (arm_gen_constant (code, mode, NULL_RTX, val, target, source,
1875 > arm_constant_limit + (code != SET)))
1879 /* Currently SET is the only monadic value for CODE, all
1880 the rest are diadic. */
1881 emit_set_insn (target, GEN_INT (val));
1886 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
1888 emit_set_insn (temp, GEN_INT (val));
1889 /* For MINUS, the value is subtracted from, since we never
1890 have subtraction of a constant. */
1892 emit_set_insn (target, gen_rtx_MINUS (mode, temp, source));
1894 emit_set_insn (target,
1895 gen_rtx_fmt_ee (code, mode, source, temp));
1901 return arm_gen_constant (code, mode, cond, val, target, source, subtargets,
1905 /* Return the number of ARM instructions required to synthesize the given
1908 count_insns_for_constant (HOST_WIDE_INT remainder, int i)
1910 HOST_WIDE_INT temp1;
1918 if (remainder & (3 << (i - 2)))
1923 temp1 = remainder & ((0x0ff << end)
1924 | ((i < end) ? (0xff >> (32 - end)) : 0));
1925 remainder &= ~temp1;
1930 } while (remainder);
1934 /* Emit an instruction with the indicated PATTERN. If COND is
1935 non-NULL, conditionalize the execution of the instruction on COND
1939 emit_constant_insn (rtx cond, rtx pattern)
1942 pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern);
1943 emit_insn (pattern);
1946 /* As above, but extra parameter GENERATE which, if clear, suppresses
1948 /* ??? This needs more work for thumb2. */
1951 arm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond,
1952 HOST_WIDE_INT val, rtx target, rtx source, int subtargets,
1957 int can_negate_initial = 0;
1960 int num_bits_set = 0;
1961 int set_sign_bit_copies = 0;
1962 int clear_sign_bit_copies = 0;
1963 int clear_zero_bit_copies = 0;
1964 int set_zero_bit_copies = 0;
1966 unsigned HOST_WIDE_INT temp1, temp2;
1967 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
1969 /* Find out which operations are safe for a given CODE. Also do a quick
1970 check for degenerate cases; these can occur when DImode operations
1982 can_negate_initial = 1;
1986 if (remainder == 0xffffffff)
1989 emit_constant_insn (cond,
1990 gen_rtx_SET (VOIDmode, target,
1991 GEN_INT (ARM_SIGN_EXTEND (val))));
1996 if (reload_completed && rtx_equal_p (target, source))
1999 emit_constant_insn (cond,
2000 gen_rtx_SET (VOIDmode, target, source));
2009 emit_constant_insn (cond,
2010 gen_rtx_SET (VOIDmode, target, const0_rtx));
2013 if (remainder == 0xffffffff)
2015 if (reload_completed && rtx_equal_p (target, source))
2018 emit_constant_insn (cond,
2019 gen_rtx_SET (VOIDmode, target, source));
2028 if (reload_completed && rtx_equal_p (target, source))
2031 emit_constant_insn (cond,
2032 gen_rtx_SET (VOIDmode, target, source));
2036 /* We don't know how to handle other cases yet. */
2037 gcc_assert (remainder == 0xffffffff);
2040 emit_constant_insn (cond,
2041 gen_rtx_SET (VOIDmode, target,
2042 gen_rtx_NOT (mode, source)));
2046 /* We treat MINUS as (val - source), since (source - val) is always
2047 passed as (source + (-val)). */
2051 emit_constant_insn (cond,
2052 gen_rtx_SET (VOIDmode, target,
2053 gen_rtx_NEG (mode, source)));
2056 if (const_ok_for_arm (val))
2059 emit_constant_insn (cond,
2060 gen_rtx_SET (VOIDmode, target,
2061 gen_rtx_MINUS (mode, GEN_INT (val),
2073 /* If we can do it in one insn get out quickly. */
2074 if (const_ok_for_arm (val)
2075 || (can_negate_initial && const_ok_for_arm (-val))
2076 || (can_invert && const_ok_for_arm (~val)))
2079 emit_constant_insn (cond,
2080 gen_rtx_SET (VOIDmode, target,
2082 ? gen_rtx_fmt_ee (code, mode, source,
2088 /* Calculate a few attributes that may be useful for specific
2090 for (i = 31; i >= 0; i--)
2092 if ((remainder & (1 << i)) == 0)
2093 clear_sign_bit_copies++;
2098 for (i = 31; i >= 0; i--)
2100 if ((remainder & (1 << i)) != 0)
2101 set_sign_bit_copies++;
2106 for (i = 0; i <= 31; i++)
2108 if ((remainder & (1 << i)) == 0)
2109 clear_zero_bit_copies++;
2114 for (i = 0; i <= 31; i++)
2116 if ((remainder & (1 << i)) != 0)
2117 set_zero_bit_copies++;
2125 /* See if we can use movw. */
2126 if (arm_arch_thumb2 && (remainder & 0xffff0000) == 0)
2129 emit_constant_insn (cond, gen_rtx_SET (VOIDmode, target,
2134 /* See if we can do this by sign_extending a constant that is known
2135 to be negative. This is a good, way of doing it, since the shift
2136 may well merge into a subsequent insn. */
2137 if (set_sign_bit_copies > 1)
2139 if (const_ok_for_arm
2140 (temp1 = ARM_SIGN_EXTEND (remainder
2141 << (set_sign_bit_copies - 1))))
2145 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2146 emit_constant_insn (cond,
2147 gen_rtx_SET (VOIDmode, new_src,
2149 emit_constant_insn (cond,
2150 gen_ashrsi3 (target, new_src,
2151 GEN_INT (set_sign_bit_copies - 1)));
2155 /* For an inverted constant, we will need to set the low bits,
2156 these will be shifted out of harm's way. */
2157 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
2158 if (const_ok_for_arm (~temp1))
2162 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2163 emit_constant_insn (cond,
2164 gen_rtx_SET (VOIDmode, new_src,
2166 emit_constant_insn (cond,
2167 gen_ashrsi3 (target, new_src,
2168 GEN_INT (set_sign_bit_copies - 1)));
2174 /* See if we can calculate the value as the difference between two
2175 valid immediates. */
2176 if (clear_sign_bit_copies + clear_zero_bit_copies <= 16)
2178 int topshift = clear_sign_bit_copies & ~1;
2180 temp1 = ARM_SIGN_EXTEND ((remainder + (0x00800000 >> topshift))
2181 & (0xff000000 >> topshift));
2183 /* If temp1 is zero, then that means the 9 most significant
2184 bits of remainder were 1 and we've caused it to overflow.
2185 When topshift is 0 we don't need to do anything since we
2186 can borrow from 'bit 32'. */
2187 if (temp1 == 0 && topshift != 0)
2188 temp1 = 0x80000000 >> (topshift - 1);
2190 temp2 = ARM_SIGN_EXTEND (temp1 - remainder);
2192 if (const_ok_for_arm (temp2))
2196 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2197 emit_constant_insn (cond,
2198 gen_rtx_SET (VOIDmode, new_src,
2200 emit_constant_insn (cond,
2201 gen_addsi3 (target, new_src,
2209 /* See if we can generate this by setting the bottom (or the top)
2210 16 bits, and then shifting these into the other half of the
2211 word. We only look for the simplest cases, to do more would cost
2212 too much. Be careful, however, not to generate this when the
2213 alternative would take fewer insns. */
2214 if (val & 0xffff0000)
2216 temp1 = remainder & 0xffff0000;
2217 temp2 = remainder & 0x0000ffff;
2219 /* Overlaps outside this range are best done using other methods. */
2220 for (i = 9; i < 24; i++)
2222 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
2223 && !const_ok_for_arm (temp2))
2225 rtx new_src = (subtargets
2226 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
2228 insns = arm_gen_constant (code, mode, cond, temp2, new_src,
2229 source, subtargets, generate);
2237 gen_rtx_ASHIFT (mode, source,
2244 /* Don't duplicate cases already considered. */
2245 for (i = 17; i < 24; i++)
2247 if (((temp1 | (temp1 >> i)) == remainder)
2248 && !const_ok_for_arm (temp1))
2250 rtx new_src = (subtargets
2251 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
2253 insns = arm_gen_constant (code, mode, cond, temp1, new_src,
2254 source, subtargets, generate);
2259 gen_rtx_SET (VOIDmode, target,
2262 gen_rtx_LSHIFTRT (mode, source,
2273 /* If we have IOR or XOR, and the constant can be loaded in a
2274 single instruction, and we can find a temporary to put it in,
2275 then this can be done in two instructions instead of 3-4. */
2277 /* TARGET can't be NULL if SUBTARGETS is 0 */
2278 || (reload_completed && !reg_mentioned_p (target, source)))
2280 if (const_ok_for_arm (ARM_SIGN_EXTEND (~val)))
2284 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2286 emit_constant_insn (cond,
2287 gen_rtx_SET (VOIDmode, sub,
2289 emit_constant_insn (cond,
2290 gen_rtx_SET (VOIDmode, target,
2291 gen_rtx_fmt_ee (code, mode,
2301 if (set_sign_bit_copies > 8
2302 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
2306 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2307 rtx shift = GEN_INT (set_sign_bit_copies);
2311 gen_rtx_SET (VOIDmode, sub,
2313 gen_rtx_ASHIFT (mode,
2318 gen_rtx_SET (VOIDmode, target,
2320 gen_rtx_LSHIFTRT (mode, sub,
2326 if (set_zero_bit_copies > 8
2327 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
2331 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2332 rtx shift = GEN_INT (set_zero_bit_copies);
2336 gen_rtx_SET (VOIDmode, sub,
2338 gen_rtx_LSHIFTRT (mode,
2343 gen_rtx_SET (VOIDmode, target,
2345 gen_rtx_ASHIFT (mode, sub,
2351 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val)))
2355 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2356 emit_constant_insn (cond,
2357 gen_rtx_SET (VOIDmode, sub,
2358 gen_rtx_NOT (mode, source)));
2361 sub = gen_reg_rtx (mode);
2362 emit_constant_insn (cond,
2363 gen_rtx_SET (VOIDmode, sub,
2364 gen_rtx_AND (mode, source,
2366 emit_constant_insn (cond,
2367 gen_rtx_SET (VOIDmode, target,
2368 gen_rtx_NOT (mode, sub)));
2375 /* See if two shifts will do 2 or more insn's worth of work. */
2376 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
2378 HOST_WIDE_INT shift_mask = ((0xffffffff
2379 << (32 - clear_sign_bit_copies))
2382 if ((remainder | shift_mask) != 0xffffffff)
2386 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2387 insns = arm_gen_constant (AND, mode, cond,
2388 remainder | shift_mask,
2389 new_src, source, subtargets, 1);
2394 rtx targ = subtargets ? NULL_RTX : target;
2395 insns = arm_gen_constant (AND, mode, cond,
2396 remainder | shift_mask,
2397 targ, source, subtargets, 0);
2403 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2404 rtx shift = GEN_INT (clear_sign_bit_copies);
2406 emit_insn (gen_ashlsi3 (new_src, source, shift));
2407 emit_insn (gen_lshrsi3 (target, new_src, shift));
2413 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
2415 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
2417 if ((remainder | shift_mask) != 0xffffffff)
2421 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2423 insns = arm_gen_constant (AND, mode, cond,
2424 remainder | shift_mask,
2425 new_src, source, subtargets, 1);
2430 rtx targ = subtargets ? NULL_RTX : target;
2432 insns = arm_gen_constant (AND, mode, cond,
2433 remainder | shift_mask,
2434 targ, source, subtargets, 0);
2440 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2441 rtx shift = GEN_INT (clear_zero_bit_copies);
2443 emit_insn (gen_lshrsi3 (new_src, source, shift));
2444 emit_insn (gen_ashlsi3 (target, new_src, shift));
2456 for (i = 0; i < 32; i++)
2457 if (remainder & (1 << i))
2460 if (code == AND || (can_invert && num_bits_set > 16))
2461 remainder = (~remainder) & 0xffffffff;
2462 else if (code == PLUS && num_bits_set > 16)
2463 remainder = (-remainder) & 0xffffffff;
2470 /* Now try and find a way of doing the job in either two or three
2472 We start by looking for the largest block of zeros that are aligned on
2473 a 2-bit boundary, we then fill up the temps, wrapping around to the
2474 top of the word when we drop off the bottom.
2475 In the worst case this code should produce no more than four insns.
2476 Thumb-2 constants are shifted, not rotated, so the MSB is always the
2477 best place to start. */
2479 /* ??? Use thumb2 replicated constants when the high and low halfwords are
2485 int best_consecutive_zeros = 0;
2487 for (i = 0; i < 32; i += 2)
2489 int consecutive_zeros = 0;
2491 if (!(remainder & (3 << i)))
2493 while ((i < 32) && !(remainder & (3 << i)))
2495 consecutive_zeros += 2;
2498 if (consecutive_zeros > best_consecutive_zeros)
2500 best_consecutive_zeros = consecutive_zeros;
2501 best_start = i - consecutive_zeros;
2507 /* So long as it won't require any more insns to do so, it's
2508 desirable to emit a small constant (in bits 0...9) in the last
2509 insn. This way there is more chance that it can be combined with
2510 a later addressing insn to form a pre-indexed load or store
2511 operation. Consider:
2513 *((volatile int *)0xe0000100) = 1;
2514 *((volatile int *)0xe0000110) = 2;
2516 We want this to wind up as:
2520 str rB, [rA, #0x100]
2522 str rB, [rA, #0x110]
2524 rather than having to synthesize both large constants from scratch.
2526 Therefore, we calculate how many insns would be required to emit
2527 the constant starting from `best_start', and also starting from
2528 zero (i.e. with bit 31 first to be output). If `best_start' doesn't
2529 yield a shorter sequence, we may as well use zero. */
2531 && ((((unsigned HOST_WIDE_INT) 1) << best_start) < remainder)
2532 && (count_insns_for_constant (remainder, 0) <=
2533 count_insns_for_constant (remainder, best_start)))
2537 /* Now start emitting the insns. */
2545 if (remainder & (3 << (i - 2)))
2550 temp1 = remainder & ((0x0ff << end)
2551 | ((i < end) ? (0xff >> (32 - end)) : 0));
2552 remainder &= ~temp1;
2556 rtx new_src, temp1_rtx;
2558 if (code == SET || code == MINUS)
2560 new_src = (subtargets ? gen_reg_rtx (mode) : target);
2561 if (can_invert && code != MINUS)
2566 if (remainder && subtargets)
2567 new_src = gen_reg_rtx (mode);
2572 else if (can_negate)
2576 temp1 = trunc_int_for_mode (temp1, mode);
2577 temp1_rtx = GEN_INT (temp1);
2581 else if (code == MINUS)
2582 temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source);
2584 temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx);
2586 emit_constant_insn (cond,
2587 gen_rtx_SET (VOIDmode, new_src,
2597 else if (code == MINUS)
2606 /* Arm allows rotates by a multiple of two. Thumb-2 allows arbitrary
2619 /* Canonicalize a comparison so that we are more likely to recognize it.
2620 This can be done for a few constant compares, where we can make the
2621 immediate value easier to load. */
2624 arm_canonicalize_comparison (enum rtx_code code, enum machine_mode mode,
2627 unsigned HOST_WIDE_INT i = INTVAL (*op1);
2628 unsigned HOST_WIDE_INT maxval;
2629 maxval = (((unsigned HOST_WIDE_INT) 1) << (GET_MODE_BITSIZE(mode) - 1)) - 1;
2640 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
2642 *op1 = GEN_INT (i + 1);
2643 return code == GT ? GE : LT;
2650 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
2652 *op1 = GEN_INT (i - 1);
2653 return code == GE ? GT : LE;
2659 if (i != ~((unsigned HOST_WIDE_INT) 0)
2660 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
2662 *op1 = GEN_INT (i + 1);
2663 return code == GTU ? GEU : LTU;
2670 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
2672 *op1 = GEN_INT (i - 1);
2673 return code == GEU ? GTU : LEU;
2685 /* Define how to find the value returned by a function. */
2688 arm_function_value(const_tree type, const_tree func ATTRIBUTE_UNUSED)
2690 enum machine_mode mode;
2691 int unsignedp ATTRIBUTE_UNUSED;
2692 rtx r ATTRIBUTE_UNUSED;
2694 mode = TYPE_MODE (type);
2695 /* Promote integer types. */
2696 if (INTEGRAL_TYPE_P (type))
2697 PROMOTE_FUNCTION_MODE (mode, unsignedp, type);
2699 /* Promotes small structs returned in a register to full-word size
2700 for big-endian AAPCS. */
2701 if (arm_return_in_msb (type))
2703 HOST_WIDE_INT size = int_size_in_bytes (type);
2704 if (size % UNITS_PER_WORD != 0)
2706 size += UNITS_PER_WORD - size % UNITS_PER_WORD;
2707 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2711 return LIBCALL_VALUE(mode);
2714 /* Determine the amount of memory needed to store the possible return
2715 registers of an untyped call. */
2717 arm_apply_result_size (void)
2723 if (TARGET_HARD_FLOAT_ABI)
2727 if (TARGET_MAVERICK)
2730 if (TARGET_IWMMXT_ABI)
2737 /* Decide whether a type should be returned in memory (true)
2738 or in a register (false). This is called by the macro
2739 RETURN_IN_MEMORY. */
2741 arm_return_in_memory (const_tree type)
2745 size = int_size_in_bytes (type);
2747 /* Vector values should be returned using ARM registers, not memory (unless
2748 they're over 16 bytes, which will break since we only have four
2749 call-clobbered registers to play with). */
2750 if (TREE_CODE (type) == VECTOR_TYPE)
2751 return (size < 0 || size > (4 * UNITS_PER_WORD));
2753 if (!AGGREGATE_TYPE_P (type) &&
2754 !(TARGET_AAPCS_BASED && TREE_CODE (type) == COMPLEX_TYPE))
2755 /* All simple types are returned in registers.
2756 For AAPCS, complex types are treated the same as aggregates. */
2759 if (arm_abi != ARM_ABI_APCS)
2761 /* ATPCS and later return aggregate types in memory only if they are
2762 larger than a word (or are variable size). */
2763 return (size < 0 || size > UNITS_PER_WORD);
2766 /* For the arm-wince targets we choose to be compatible with Microsoft's
2767 ARM and Thumb compilers, which always return aggregates in memory. */
2769 /* All structures/unions bigger than one word are returned in memory.
2770 Also catch the case where int_size_in_bytes returns -1. In this case
2771 the aggregate is either huge or of variable size, and in either case
2772 we will want to return it via memory and not in a register. */
2773 if (size < 0 || size > UNITS_PER_WORD)
2776 if (TREE_CODE (type) == RECORD_TYPE)
2780 /* For a struct the APCS says that we only return in a register
2781 if the type is 'integer like' and every addressable element
2782 has an offset of zero. For practical purposes this means
2783 that the structure can have at most one non bit-field element
2784 and that this element must be the first one in the structure. */
2786 /* Find the first field, ignoring non FIELD_DECL things which will
2787 have been created by C++. */
2788 for (field = TYPE_FIELDS (type);
2789 field && TREE_CODE (field) != FIELD_DECL;
2790 field = TREE_CHAIN (field))
2794 return 0; /* An empty structure. Allowed by an extension to ANSI C. */
2796 /* Check that the first field is valid for returning in a register. */
2798 /* ... Floats are not allowed */
2799 if (FLOAT_TYPE_P (TREE_TYPE (field)))
2802 /* ... Aggregates that are not themselves valid for returning in
2803 a register are not allowed. */
2804 if (RETURN_IN_MEMORY (TREE_TYPE (field)))
2807 /* Now check the remaining fields, if any. Only bitfields are allowed,
2808 since they are not addressable. */
2809 for (field = TREE_CHAIN (field);
2811 field = TREE_CHAIN (field))
2813 if (TREE_CODE (field) != FIELD_DECL)
2816 if (!DECL_BIT_FIELD_TYPE (field))
2823 if (TREE_CODE (type) == UNION_TYPE)
2827 /* Unions can be returned in registers if every element is
2828 integral, or can be returned in an integer register. */
2829 for (field = TYPE_FIELDS (type);
2831 field = TREE_CHAIN (field))
2833 if (TREE_CODE (field) != FIELD_DECL)
2836 if (FLOAT_TYPE_P (TREE_TYPE (field)))
2839 if (RETURN_IN_MEMORY (TREE_TYPE (field)))
2845 #endif /* not ARM_WINCE */
2847 /* Return all other types in memory. */
2851 /* Indicate whether or not words of a double are in big-endian order. */
2854 arm_float_words_big_endian (void)
2856 if (TARGET_MAVERICK)
2859 /* For FPA, float words are always big-endian. For VFP, floats words
2860 follow the memory system mode. */
2868 return (TARGET_BIG_END ? 1 : 0);
2873 /* Initialize a variable CUM of type CUMULATIVE_ARGS
2874 for a call to a function whose data type is FNTYPE.
2875 For a library call, FNTYPE is NULL. */
2877 arm_init_cumulative_args (CUMULATIVE_ARGS *pcum, tree fntype,
2878 rtx libname ATTRIBUTE_UNUSED,
2879 tree fndecl ATTRIBUTE_UNUSED)
2881 /* On the ARM, the offset starts at 0. */
2883 pcum->iwmmxt_nregs = 0;
2884 pcum->can_split = true;
2886 /* Varargs vectors are treated the same as long long.
2887 named_count avoids having to change the way arm handles 'named' */
2888 pcum->named_count = 0;
2891 if (TARGET_REALLY_IWMMXT && fntype)
2895 for (fn_arg = TYPE_ARG_TYPES (fntype);
2897 fn_arg = TREE_CHAIN (fn_arg))
2898 pcum->named_count += 1;
2900 if (! pcum->named_count)
2901 pcum->named_count = INT_MAX;
2906 /* Return true if mode/type need doubleword alignment. */
2908 arm_needs_doubleword_align (enum machine_mode mode, tree type)
2910 return (GET_MODE_ALIGNMENT (mode) > PARM_BOUNDARY
2911 || (type && TYPE_ALIGN (type) > PARM_BOUNDARY));
2915 /* Determine where to put an argument to a function.
2916 Value is zero to push the argument on the stack,
2917 or a hard register in which to store the argument.
2919 MODE is the argument's machine mode.
2920 TYPE is the data type of the argument (as a tree).
2921 This is null for libcalls where that information may
2923 CUM is a variable of type CUMULATIVE_ARGS which gives info about
2924 the preceding args and about the function being called.
2925 NAMED is nonzero if this argument is a named parameter
2926 (otherwise it is an extra parameter matching an ellipsis). */
2929 arm_function_arg (CUMULATIVE_ARGS *pcum, enum machine_mode mode,
2930 tree type, int named)
2934 /* Varargs vectors are treated the same as long long.
2935 named_count avoids having to change the way arm handles 'named' */
2936 if (TARGET_IWMMXT_ABI
2937 && arm_vector_mode_supported_p (mode)
2938 && pcum->named_count > pcum->nargs + 1)
2940 if (pcum->iwmmxt_nregs <= 9)
2941 return gen_rtx_REG (mode, pcum->iwmmxt_nregs + FIRST_IWMMXT_REGNUM);
2944 pcum->can_split = false;
2949 /* Put doubleword aligned quantities in even register pairs. */
2951 && ARM_DOUBLEWORD_ALIGN
2952 && arm_needs_doubleword_align (mode, type))
2955 if (mode == VOIDmode)
2956 /* Pick an arbitrary value for operand 2 of the call insn. */
2959 /* Only allow splitting an arg between regs and memory if all preceding
2960 args were allocated to regs. For args passed by reference we only count
2961 the reference pointer. */
2962 if (pcum->can_split)
2965 nregs = ARM_NUM_REGS2 (mode, type);
2967 if (!named || pcum->nregs + nregs > NUM_ARG_REGS)
2970 return gen_rtx_REG (mode, pcum->nregs);
2974 arm_arg_partial_bytes (CUMULATIVE_ARGS *pcum, enum machine_mode mode,
2975 tree type, bool named ATTRIBUTE_UNUSED)
2977 int nregs = pcum->nregs;
2979 if (TARGET_IWMMXT_ABI && arm_vector_mode_supported_p (mode))
2982 if (NUM_ARG_REGS > nregs
2983 && (NUM_ARG_REGS < nregs + ARM_NUM_REGS2 (mode, type))
2985 return (NUM_ARG_REGS - nregs) * UNITS_PER_WORD;
2990 /* Variable sized types are passed by reference. This is a GCC
2991 extension to the ARM ABI. */
2994 arm_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
2995 enum machine_mode mode ATTRIBUTE_UNUSED,
2996 const_tree type, bool named ATTRIBUTE_UNUSED)
2998 return type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST;
3001 /* Encode the current state of the #pragma [no_]long_calls. */
3004 OFF, /* No #pragma [no_]long_calls is in effect. */
3005 LONG, /* #pragma long_calls is in effect. */
3006 SHORT /* #pragma no_long_calls is in effect. */
3009 static arm_pragma_enum arm_pragma_long_calls = OFF;
3012 arm_pr_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
3014 arm_pragma_long_calls = LONG;
3018 arm_pr_no_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
3020 arm_pragma_long_calls = SHORT;
3024 arm_pr_long_calls_off (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
3026 arm_pragma_long_calls = OFF;
3029 /* Table of machine attributes. */
3030 const struct attribute_spec arm_attribute_table[] =
3032 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
3033 /* Function calls made to this symbol must be done indirectly, because
3034 it may lie outside of the 26 bit addressing range of a normal function
3036 { "long_call", 0, 0, false, true, true, NULL },
3037 /* Whereas these functions are always known to reside within the 26 bit
3038 addressing range. */
3039 { "short_call", 0, 0, false, true, true, NULL },
3040 /* Interrupt Service Routines have special prologue and epilogue requirements. */
3041 { "isr", 0, 1, false, false, false, arm_handle_isr_attribute },
3042 { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute },
3043 { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute },
3045 /* ARM/PE has three new attributes:
3047 dllexport - for exporting a function/variable that will live in a dll
3048 dllimport - for importing a function/variable from a dll
3050 Microsoft allows multiple declspecs in one __declspec, separating
3051 them with spaces. We do NOT support this. Instead, use __declspec
3054 { "dllimport", 0, 0, true, false, false, NULL },
3055 { "dllexport", 0, 0, true, false, false, NULL },
3056 { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute },
3057 #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
3058 { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
3059 { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
3060 { "notshared", 0, 0, false, true, false, arm_handle_notshared_attribute },
3062 { NULL, 0, 0, false, false, false, NULL }
3065 /* Handle an attribute requiring a FUNCTION_DECL;
3066 arguments as in struct attribute_spec.handler. */
3068 arm_handle_fndecl_attribute (tree *node, tree name, tree args ATTRIBUTE_UNUSED,
3069 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
3071 if (TREE_CODE (*node) != FUNCTION_DECL)
3073 warning (OPT_Wattributes, "%qs attribute only applies to functions",
3074 IDENTIFIER_POINTER (name));
3075 *no_add_attrs = true;
3081 /* Handle an "interrupt" or "isr" attribute;
3082 arguments as in struct attribute_spec.handler. */
3084 arm_handle_isr_attribute (tree *node, tree name, tree args, int flags,
3089 if (TREE_CODE (*node) != FUNCTION_DECL)
3091 warning (OPT_Wattributes, "%qs attribute only applies to functions",
3092 IDENTIFIER_POINTER (name));
3093 *no_add_attrs = true;
3095 /* FIXME: the argument if any is checked for type attributes;
3096 should it be checked for decl ones? */
3100 if (TREE_CODE (*node) == FUNCTION_TYPE
3101 || TREE_CODE (*node) == METHOD_TYPE)
3103 if (arm_isr_value (args) == ARM_FT_UNKNOWN)
3105 warning (OPT_Wattributes, "%qs attribute ignored",
3106 IDENTIFIER_POINTER (name));
3107 *no_add_attrs = true;
3110 else if (TREE_CODE (*node) == POINTER_TYPE
3111 && (TREE_CODE (TREE_TYPE (*node)) == FUNCTION_TYPE
3112 || TREE_CODE (TREE_TYPE (*node)) == METHOD_TYPE)
3113 && arm_isr_value (args) != ARM_FT_UNKNOWN)
3115 *node = build_variant_type_copy (*node);
3116 TREE_TYPE (*node) = build_type_attribute_variant
3118 tree_cons (name, args, TYPE_ATTRIBUTES (TREE_TYPE (*node))));
3119 *no_add_attrs = true;
3123 /* Possibly pass this attribute on from the type to a decl. */
3124 if (flags & ((int) ATTR_FLAG_DECL_NEXT
3125 | (int) ATTR_FLAG_FUNCTION_NEXT
3126 | (int) ATTR_FLAG_ARRAY_NEXT))
3128 *no_add_attrs = true;
3129 return tree_cons (name, args, NULL_TREE);
3133 warning (OPT_Wattributes, "%qs attribute ignored",
3134 IDENTIFIER_POINTER (name));
3142 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3143 /* Handle the "notshared" attribute. This attribute is another way of
3144 requesting hidden visibility. ARM's compiler supports
3145 "__declspec(notshared)"; we support the same thing via an
3149 arm_handle_notshared_attribute (tree *node,
3150 tree name ATTRIBUTE_UNUSED,
3151 tree args ATTRIBUTE_UNUSED,
3152 int flags ATTRIBUTE_UNUSED,
3155 tree decl = TYPE_NAME (*node);
3159 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
3160 DECL_VISIBILITY_SPECIFIED (decl) = 1;
3161 *no_add_attrs = false;
3167 /* Return 0 if the attributes for two types are incompatible, 1 if they
3168 are compatible, and 2 if they are nearly compatible (which causes a
3169 warning to be generated). */
3171 arm_comp_type_attributes (const_tree type1, const_tree type2)
3175 /* Check for mismatch of non-default calling convention. */
3176 if (TREE_CODE (type1) != FUNCTION_TYPE)
3179 /* Check for mismatched call attributes. */
3180 l1 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type1)) != NULL;
3181 l2 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type2)) != NULL;
3182 s1 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type1)) != NULL;
3183 s2 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type2)) != NULL;
3185 /* Only bother to check if an attribute is defined. */
3186 if (l1 | l2 | s1 | s2)
3188 /* If one type has an attribute, the other must have the same attribute. */
3189 if ((l1 != l2) || (s1 != s2))
3192 /* Disallow mixed attributes. */
3193 if ((l1 & s2) || (l2 & s1))
3197 /* Check for mismatched ISR attribute. */
3198 l1 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type1)) != NULL;
3200 l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1)) != NULL;
3201 l2 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type2)) != NULL;
3203 l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2)) != NULL;
3210 /* Assigns default attributes to newly defined type. This is used to
3211 set short_call/long_call attributes for function types of
3212 functions defined inside corresponding #pragma scopes. */
3214 arm_set_default_type_attributes (tree type)
3216 /* Add __attribute__ ((long_call)) to all functions, when
3217 inside #pragma long_calls or __attribute__ ((short_call)),
3218 when inside #pragma no_long_calls. */
3219 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
3221 tree type_attr_list, attr_name;
3222 type_attr_list = TYPE_ATTRIBUTES (type);
3224 if (arm_pragma_long_calls == LONG)
3225 attr_name = get_identifier ("long_call");
3226 else if (arm_pragma_long_calls == SHORT)
3227 attr_name = get_identifier ("short_call");
3231 type_attr_list = tree_cons (attr_name, NULL_TREE, type_attr_list);
3232 TYPE_ATTRIBUTES (type) = type_attr_list;
3236 /* Return true if DECL is known to be linked into section SECTION. */
3239 arm_function_in_section_p (tree decl, section *section)
3241 /* We can only be certain about functions defined in the same
3242 compilation unit. */
3243 if (!TREE_STATIC (decl))
3246 /* Make sure that SYMBOL always binds to the definition in this
3247 compilation unit. */
3248 if (!targetm.binds_local_p (decl))
3251 /* If DECL_SECTION_NAME is set, assume it is trustworthy. */
3252 if (!DECL_SECTION_NAME (decl))
3254 /* Only cater for unit-at-a-time mode, where we know that the user
3255 cannot later specify a section for DECL. */
3256 if (!flag_unit_at_a_time)
3259 /* Make sure that we will not create a unique section for DECL. */
3260 if (flag_function_sections || DECL_ONE_ONLY (decl))
3264 return function_section (decl) == section;
3267 /* Return nonzero if a 32-bit "long_call" should be generated for
3268 a call from the current function to DECL. We generate a long_call
3271 a. has an __attribute__((long call))
3272 or b. is within the scope of a #pragma long_calls
3273 or c. the -mlong-calls command line switch has been specified
3275 However we do not generate a long call if the function:
3277 d. has an __attribute__ ((short_call))
3278 or e. is inside the scope of a #pragma no_long_calls
3279 or f. is defined in the same section as the current function. */
3282 arm_is_long_call_p (tree decl)
3287 return TARGET_LONG_CALLS;
3289 attrs = TYPE_ATTRIBUTES (TREE_TYPE (decl));
3290 if (lookup_attribute ("short_call", attrs))
3293 /* For "f", be conservative, and only cater for cases in which the
3294 whole of the current function is placed in the same section. */
3295 if (!flag_reorder_blocks_and_partition
3296 && arm_function_in_section_p (decl, current_function_section ()))
3299 if (lookup_attribute ("long_call", attrs))
3302 return TARGET_LONG_CALLS;
3305 /* Return nonzero if it is ok to make a tail-call to DECL. */
3307 arm_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
3309 unsigned long func_type;
3311 if (cfun->machine->sibcall_blocked)
3314 /* Never tailcall something for which we have no decl, or if we
3315 are in Thumb mode. */
3316 if (decl == NULL || TARGET_THUMB)
3319 /* The PIC register is live on entry to VxWorks PLT entries, so we
3320 must make the call before restoring the PIC register. */
3321 if (TARGET_VXWORKS_RTP && flag_pic && !targetm.binds_local_p (decl))
3324 /* Cannot tail-call to long calls, since these are out of range of
3325 a branch instruction. */
3326 if (arm_is_long_call_p (decl))
3329 /* If we are interworking and the function is not declared static
3330 then we can't tail-call it unless we know that it exists in this
3331 compilation unit (since it might be a Thumb routine). */
3332 if (TARGET_INTERWORK && TREE_PUBLIC (decl) && !TREE_ASM_WRITTEN (decl))
3335 func_type = arm_current_func_type ();
3336 /* Never tailcall from an ISR routine - it needs a special exit sequence. */
3337 if (IS_INTERRUPT (func_type))
3340 /* Never tailcall if function may be called with a misaligned SP. */
3341 if (IS_STACKALIGN (func_type))
3344 /* Everything else is ok. */
3349 /* Addressing mode support functions. */
3351 /* Return nonzero if X is a legitimate immediate operand when compiling
3352 for PIC. We know that X satisfies CONSTANT_P and flag_pic is true. */
3354 legitimate_pic_operand_p (rtx x)
3356 if (GET_CODE (x) == SYMBOL_REF
3357 || (GET_CODE (x) == CONST
3358 && GET_CODE (XEXP (x, 0)) == PLUS
3359 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF))
3365 /* Record that the current function needs a PIC register. Initialize
3366 cfun->machine->pic_reg if we have not already done so. */
3369 require_pic_register (void)
3371 /* A lot of the logic here is made obscure by the fact that this
3372 routine gets called as part of the rtx cost estimation process.
3373 We don't want those calls to affect any assumptions about the real
3374 function; and further, we can't call entry_of_function() until we
3375 start the real expansion process. */
3376 if (!current_function_uses_pic_offset_table)
3378 gcc_assert (can_create_pseudo_p ());
3379 if (arm_pic_register != INVALID_REGNUM)
3381 cfun->machine->pic_reg = gen_rtx_REG (Pmode, arm_pic_register);
3383 /* Play games to avoid marking the function as needing pic
3384 if we are being called as part of the cost-estimation
3386 if (current_ir_type () != IR_GIMPLE)
3387 current_function_uses_pic_offset_table = 1;
3393 cfun->machine->pic_reg = gen_reg_rtx (Pmode);
3395 /* Play games to avoid marking the function as needing pic
3396 if we are being called as part of the cost-estimation
3398 if (current_ir_type () != IR_GIMPLE)
3400 current_function_uses_pic_offset_table = 1;
3403 arm_load_pic_register (0UL);
3407 emit_insn_after (seq, entry_of_function ());
3414 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
3416 if (GET_CODE (orig) == SYMBOL_REF
3417 || GET_CODE (orig) == LABEL_REF)
3419 rtx pic_ref, address;
3423 /* If this function doesn't have a pic register, create one now. */
3424 require_pic_register ();
3428 gcc_assert (can_create_pseudo_p ());
3429 reg = gen_reg_rtx (Pmode);
3435 address = gen_reg_rtx (Pmode);