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 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 2, 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 COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
27 #include "coretypes.h"
33 #include "hard-reg-set.h"
35 #include "insn-config.h"
36 #include "conditions.h"
38 #include "insn-attr.h"
49 #include "integrate.h"
52 #include "target-def.h"
54 #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 /* Forward function declarations. */
63 static arm_stack_offsets *arm_get_frame_offsets (void);
64 static void arm_add_gc_roots (void);
65 static int arm_gen_constant (enum rtx_code, enum machine_mode, rtx,
66 HOST_WIDE_INT, rtx, rtx, int, int);
67 static unsigned bit_count (unsigned long);
68 static int arm_address_register_rtx_p (rtx, int);
69 static int arm_legitimate_index_p (enum machine_mode, rtx, RTX_CODE, int);
70 static int thumb_base_register_rtx_p (rtx, enum machine_mode, int);
71 inline static int thumb_index_register_rtx_p (rtx, int);
72 static int thumb_far_jump_used_p (void);
73 static bool thumb_force_lr_save (void);
74 static int const_ok_for_op (HOST_WIDE_INT, enum rtx_code);
75 static rtx emit_sfm (int, int);
77 static bool arm_assemble_integer (rtx, unsigned int, int);
79 static const char *fp_const_from_val (REAL_VALUE_TYPE *);
80 static arm_cc get_arm_condition_code (rtx);
81 static HOST_WIDE_INT int_log2 (HOST_WIDE_INT);
82 static rtx is_jump_table (rtx);
83 static const char *output_multi_immediate (rtx *, const char *, const char *,
85 static const char *shift_op (rtx, HOST_WIDE_INT *);
86 static struct machine_function *arm_init_machine_status (void);
87 static void thumb_exit (FILE *, int);
88 static rtx is_jump_table (rtx);
89 static HOST_WIDE_INT get_jump_table_size (rtx);
90 static Mnode *move_minipool_fix_forward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
91 static Mnode *add_minipool_forward_ref (Mfix *);
92 static Mnode *move_minipool_fix_backward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
93 static Mnode *add_minipool_backward_ref (Mfix *);
94 static void assign_minipool_offsets (Mfix *);
95 static void arm_print_value (FILE *, rtx);
96 static void dump_minipool (rtx);
97 static int arm_barrier_cost (rtx);
98 static Mfix *create_fix_barrier (Mfix *, HOST_WIDE_INT);
99 static void push_minipool_barrier (rtx, HOST_WIDE_INT);
100 static void push_minipool_fix (rtx, HOST_WIDE_INT, rtx *, enum machine_mode,
102 static void arm_reorg (void);
103 static bool note_invalid_constants (rtx, HOST_WIDE_INT, int);
104 static int current_file_function_operand (rtx);
105 static unsigned long arm_compute_save_reg0_reg12_mask (void);
106 static unsigned long arm_compute_save_reg_mask (void);
107 static unsigned long arm_isr_value (tree);
108 static unsigned long arm_compute_func_type (void);
109 static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
110 static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *);
111 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
112 static tree arm_handle_notshared_attribute (tree *, tree, tree, int, bool *);
114 static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT);
115 static void arm_output_function_prologue (FILE *, HOST_WIDE_INT);
116 static void thumb_output_function_prologue (FILE *, HOST_WIDE_INT);
117 static int arm_comp_type_attributes (tree, tree);
118 static void arm_set_default_type_attributes (tree);
119 static int arm_adjust_cost (rtx, rtx, rtx, int);
120 static int count_insns_for_constant (HOST_WIDE_INT, int);
121 static int arm_get_strip_length (int);
122 static bool arm_function_ok_for_sibcall (tree, tree);
123 static void arm_internal_label (FILE *, const char *, unsigned long);
124 static void arm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
126 static int arm_rtx_costs_1 (rtx, enum rtx_code, enum rtx_code);
127 static bool arm_size_rtx_costs (rtx, int, int, int *);
128 static bool arm_slowmul_rtx_costs (rtx, int, int, int *);
129 static bool arm_fastmul_rtx_costs (rtx, int, int, int *);
130 static bool arm_xscale_rtx_costs (rtx, int, int, int *);
131 static bool arm_9e_rtx_costs (rtx, int, int, int *);
132 static int arm_address_cost (rtx);
133 static bool arm_memory_load_p (rtx);
134 static bool arm_cirrus_insn_p (rtx);
135 static void cirrus_reorg (rtx);
136 static void arm_init_builtins (void);
137 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
138 static void arm_init_iwmmxt_builtins (void);
139 static rtx safe_vector_operand (rtx, enum machine_mode);
140 static rtx arm_expand_binop_builtin (enum insn_code, tree, rtx);
141 static rtx arm_expand_unop_builtin (enum insn_code, tree, rtx, int);
142 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
143 static void emit_constant_insn (rtx cond, rtx pattern);
144 static int arm_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
147 #ifdef OBJECT_FORMAT_ELF
148 static void arm_elf_asm_constructor (rtx, int);
151 static void arm_encode_section_info (tree, rtx, int);
154 static void arm_file_end (void);
157 static void aof_globalize_label (FILE *, const char *);
158 static void aof_dump_imports (FILE *);
159 static void aof_dump_pic_table (FILE *);
160 static void aof_file_start (void);
161 static void aof_file_end (void);
163 static rtx arm_struct_value_rtx (tree, int);
164 static void arm_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
166 static bool arm_pass_by_reference (CUMULATIVE_ARGS *,
167 enum machine_mode, tree, bool);
168 static bool arm_promote_prototypes (tree);
169 static bool arm_default_short_enums (void);
170 static bool arm_align_anon_bitfield (void);
171 static bool arm_return_in_msb (tree);
172 static bool arm_must_pass_in_stack (enum machine_mode, tree);
174 static tree arm_cxx_guard_type (void);
175 static bool arm_cxx_guard_mask_bit (void);
176 static tree arm_get_cookie_size (tree);
177 static bool arm_cookie_has_size (void);
178 static bool arm_cxx_cdtor_returns_this (void);
179 static bool arm_cxx_key_method_may_be_inline (void);
180 static void arm_cxx_determine_class_data_visibility (tree);
181 static bool arm_cxx_class_data_always_comdat (void);
182 static bool arm_cxx_use_aeabi_atexit (void);
183 static void arm_init_libfuncs (void);
184 static bool arm_handle_option (size_t, const char *, int);
185 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode);
187 /* Initialize the GCC target structure. */
188 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
189 #undef TARGET_MERGE_DECL_ATTRIBUTES
190 #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
193 #undef TARGET_ATTRIBUTE_TABLE
194 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
196 #undef TARGET_ASM_FILE_END
197 #define TARGET_ASM_FILE_END arm_file_end
200 #undef TARGET_ASM_BYTE_OP
201 #define TARGET_ASM_BYTE_OP "\tDCB\t"
202 #undef TARGET_ASM_ALIGNED_HI_OP
203 #define TARGET_ASM_ALIGNED_HI_OP "\tDCW\t"
204 #undef TARGET_ASM_ALIGNED_SI_OP
205 #define TARGET_ASM_ALIGNED_SI_OP "\tDCD\t"
206 #undef TARGET_ASM_GLOBALIZE_LABEL
207 #define TARGET_ASM_GLOBALIZE_LABEL aof_globalize_label
208 #undef TARGET_ASM_FILE_START
209 #define TARGET_ASM_FILE_START aof_file_start
210 #undef TARGET_ASM_FILE_END
211 #define TARGET_ASM_FILE_END aof_file_end
213 #undef TARGET_ASM_ALIGNED_SI_OP
214 #define TARGET_ASM_ALIGNED_SI_OP NULL
215 #undef TARGET_ASM_INTEGER
216 #define TARGET_ASM_INTEGER arm_assemble_integer
219 #undef TARGET_ASM_FUNCTION_PROLOGUE
220 #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue
222 #undef TARGET_ASM_FUNCTION_EPILOGUE
223 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
225 #undef TARGET_DEFAULT_TARGET_FLAGS
226 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_SCHED_PROLOG)
227 #undef TARGET_HANDLE_OPTION
228 #define TARGET_HANDLE_OPTION arm_handle_option
230 #undef TARGET_COMP_TYPE_ATTRIBUTES
231 #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes
233 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
234 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes
236 #undef TARGET_SCHED_ADJUST_COST
237 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
239 #undef TARGET_ENCODE_SECTION_INFO
241 #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info
243 #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info
246 #undef TARGET_STRIP_NAME_ENCODING
247 #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding
249 #undef TARGET_ASM_INTERNAL_LABEL
250 #define TARGET_ASM_INTERNAL_LABEL arm_internal_label
252 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
253 #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall
255 #undef TARGET_ASM_OUTPUT_MI_THUNK
256 #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk
257 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
258 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
260 /* This will be overridden in arm_override_options. */
261 #undef TARGET_RTX_COSTS
262 #define TARGET_RTX_COSTS arm_slowmul_rtx_costs
263 #undef TARGET_ADDRESS_COST
264 #define TARGET_ADDRESS_COST arm_address_cost
266 #undef TARGET_SHIFT_TRUNCATION_MASK
267 #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask
268 #undef TARGET_VECTOR_MODE_SUPPORTED_P
269 #define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p
271 #undef TARGET_MACHINE_DEPENDENT_REORG
272 #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg
274 #undef TARGET_INIT_BUILTINS
275 #define TARGET_INIT_BUILTINS arm_init_builtins
276 #undef TARGET_EXPAND_BUILTIN
277 #define TARGET_EXPAND_BUILTIN arm_expand_builtin
279 #undef TARGET_INIT_LIBFUNCS
280 #define TARGET_INIT_LIBFUNCS arm_init_libfuncs
282 #undef TARGET_PROMOTE_FUNCTION_ARGS
283 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
284 #undef TARGET_PROMOTE_FUNCTION_RETURN
285 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
286 #undef TARGET_PROMOTE_PROTOTYPES
287 #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes
288 #undef TARGET_PASS_BY_REFERENCE
289 #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference
290 #undef TARGET_ARG_PARTIAL_BYTES
291 #define TARGET_ARG_PARTIAL_BYTES arm_arg_partial_bytes
293 #undef TARGET_STRUCT_VALUE_RTX
294 #define TARGET_STRUCT_VALUE_RTX arm_struct_value_rtx
296 #undef TARGET_SETUP_INCOMING_VARARGS
297 #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs
299 #undef TARGET_DEFAULT_SHORT_ENUMS
300 #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
302 #undef TARGET_ALIGN_ANON_BITFIELD
303 #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield
305 #undef TARGET_CXX_GUARD_TYPE
306 #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type
308 #undef TARGET_CXX_GUARD_MASK_BIT
309 #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit
311 #undef TARGET_CXX_GET_COOKIE_SIZE
312 #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size
314 #undef TARGET_CXX_COOKIE_HAS_SIZE
315 #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size
317 #undef TARGET_CXX_CDTOR_RETURNS_THIS
318 #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this
320 #undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE
321 #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline
323 #undef TARGET_CXX_USE_AEABI_ATEXIT
324 #define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit
326 #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY
327 #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \
328 arm_cxx_determine_class_data_visibility
330 #undef TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT
331 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT arm_cxx_class_data_always_comdat
333 #undef TARGET_RETURN_IN_MSB
334 #define TARGET_RETURN_IN_MSB arm_return_in_msb
336 #undef TARGET_MUST_PASS_IN_STACK
337 #define TARGET_MUST_PASS_IN_STACK arm_must_pass_in_stack
339 struct gcc_target targetm = TARGET_INITIALIZER;
341 /* Obstack for minipool constant handling. */
342 static struct obstack minipool_obstack;
343 static char * minipool_startobj;
345 /* The maximum number of insns skipped which
346 will be conditionalised if possible. */
347 static int max_insns_skipped = 5;
349 extern FILE * asm_out_file;
351 /* True if we are currently building a constant table. */
352 int making_const_table;
354 /* Define the information needed to generate branch insns. This is
355 stored from the compare operation. */
356 rtx arm_compare_op0, arm_compare_op1;
358 /* The processor for which instructions should be scheduled. */
359 enum processor_type arm_tune = arm_none;
361 /* Which floating point model to use. */
362 enum arm_fp_model arm_fp_model;
364 /* Which floating point hardware is available. */
365 enum fputype arm_fpu_arch;
367 /* Which floating point hardware to schedule for. */
368 enum fputype arm_fpu_tune;
370 /* Whether to use floating point hardware. */
371 enum float_abi_type arm_float_abi;
373 /* Which ABI to use. */
374 enum arm_abi_type arm_abi;
376 /* Set by the -mfpu=... option. */
377 static const char * target_fpu_name = NULL;
379 /* Set by the -mfpe=... option. */
380 static const char * target_fpe_name = NULL;
382 /* Set by the -mfloat-abi=... option. */
383 static const char * target_float_abi_name = NULL;
385 /* Set by the -mabi=... option. */
386 static const char * target_abi_name = NULL;
388 /* Used to parse -mstructure_size_boundary command line option. */
389 static const char * structure_size_string = NULL;
390 int arm_structure_size_boundary = DEFAULT_STRUCTURE_SIZE_BOUNDARY;
392 /* Used for Thumb call_via trampolines. */
393 rtx thumb_call_via_label[14];
394 static int thumb_call_reg_needed;
396 /* Bit values used to identify processor capabilities. */
397 #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */
398 #define FL_ARCH3M (1 << 1) /* Extended multiply */
399 #define FL_MODE26 (1 << 2) /* 26-bit mode support */
400 #define FL_MODE32 (1 << 3) /* 32-bit mode support */
401 #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */
402 #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */
403 #define FL_THUMB (1 << 6) /* Thumb aware */
404 #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */
405 #define FL_STRONG (1 << 8) /* StrongARM */
406 #define FL_ARCH5E (1 << 9) /* DSP extensions to v5 */
407 #define FL_XSCALE (1 << 10) /* XScale */
408 #define FL_CIRRUS (1 << 11) /* Cirrus/DSP. */
409 #define FL_ARCH6 (1 << 12) /* Architecture rel 6. Adds
410 media instructions. */
411 #define FL_VFPV2 (1 << 13) /* Vector Floating Point V2. */
412 #define FL_WBUF (1 << 14) /* Schedule for write buffer ops.
413 Note: ARM6 & 7 derivatives only. */
415 #define FL_IWMMXT (1 << 29) /* XScale v2 or "Intel Wireless MMX technology". */
417 #define FL_FOR_ARCH2 0
418 #define FL_FOR_ARCH3 FL_MODE32
419 #define FL_FOR_ARCH3M (FL_FOR_ARCH3 | FL_ARCH3M)
420 #define FL_FOR_ARCH4 (FL_FOR_ARCH3M | FL_ARCH4)
421 #define FL_FOR_ARCH4T (FL_FOR_ARCH4 | FL_THUMB)
422 #define FL_FOR_ARCH5 (FL_FOR_ARCH4 | FL_ARCH5)
423 #define FL_FOR_ARCH5T (FL_FOR_ARCH5 | FL_THUMB)
424 #define FL_FOR_ARCH5E (FL_FOR_ARCH5 | FL_ARCH5E)
425 #define FL_FOR_ARCH5TE (FL_FOR_ARCH5E | FL_THUMB)
426 #define FL_FOR_ARCH5TEJ FL_FOR_ARCH5TE
427 #define FL_FOR_ARCH6 (FL_FOR_ARCH5TE | FL_ARCH6)
428 #define FL_FOR_ARCH6J FL_FOR_ARCH6
429 #define FL_FOR_ARCH6K FL_FOR_ARCH6
430 #define FL_FOR_ARCH6Z FL_FOR_ARCH6
431 #define FL_FOR_ARCH6ZK FL_FOR_ARCH6
433 /* The bits in this mask specify which
434 instructions we are allowed to generate. */
435 static unsigned long insn_flags = 0;
437 /* The bits in this mask specify which instruction scheduling options should
439 static unsigned long tune_flags = 0;
441 /* The following are used in the arm.md file as equivalents to bits
442 in the above two flag variables. */
444 /* Nonzero if this chip supports the ARM Architecture 3M extensions. */
447 /* Nonzero if this chip supports the ARM Architecture 4 extensions. */
450 /* Nonzero if this chip supports the ARM Architecture 4t extensions. */
453 /* Nonzero if this chip supports the ARM Architecture 5 extensions. */
456 /* Nonzero if this chip supports the ARM Architecture 5E extensions. */
459 /* Nonzero if this chip supports the ARM Architecture 6 extensions. */
462 /* Nonzero if this chip can benefit from load scheduling. */
463 int arm_ld_sched = 0;
465 /* Nonzero if this chip is a StrongARM. */
466 int arm_tune_strongarm = 0;
468 /* Nonzero if this chip is a Cirrus variant. */
469 int arm_arch_cirrus = 0;
471 /* Nonzero if this chip supports Intel Wireless MMX technology. */
472 int arm_arch_iwmmxt = 0;
474 /* Nonzero if this chip is an XScale. */
475 int arm_arch_xscale = 0;
477 /* Nonzero if tuning for XScale */
478 int arm_tune_xscale = 0;
480 /* Nonzero if we want to tune for stores that access the write-buffer.
481 This typically means an ARM6 or ARM7 with MMU or MPU. */
482 int arm_tune_wbuf = 0;
484 /* Nonzero if generating Thumb instructions. */
487 /* Nonzero if we should define __THUMB_INTERWORK__ in the
489 XXX This is a bit of a hack, it's intended to help work around
490 problems in GLD which doesn't understand that armv5t code is
491 interworking clean. */
492 int arm_cpp_interwork = 0;
494 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, we
495 must report the mode of the memory reference from PRINT_OPERAND to
496 PRINT_OPERAND_ADDRESS. */
497 enum machine_mode output_memory_reference_mode;
499 /* The register number to be used for the PIC offset register. */
500 static const char * arm_pic_register_string = NULL;
501 int arm_pic_register = INVALID_REGNUM;
503 /* Set to 1 when a return insn is output, this means that the epilogue
505 int return_used_this_function;
507 /* Set to 1 after arm_reorg has started. Reset to start at the start of
508 the next function. */
509 static int after_arm_reorg = 0;
511 /* The maximum number of insns to be used when loading a constant. */
512 static int arm_constant_limit = 3;
514 /* For an explanation of these variables, see final_prescan_insn below. */
516 enum arm_cond_code arm_current_cc;
518 int arm_target_label;
520 /* The condition codes of the ARM, and the inverse function. */
521 static const char * const arm_condition_codes[] =
523 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
524 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
527 #define streq(string1, string2) (strcmp (string1, string2) == 0)
529 /* Initialization code. */
533 const char *const name;
534 enum processor_type core;
536 const unsigned long flags;
537 bool (* rtx_costs) (rtx, int, int, int *);
540 /* Not all of these give usefully different compilation alternatives,
541 but there is no simple way of generalizing them. */
542 static const struct processors all_cores[] =
545 #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \
546 {NAME, arm_none, #ARCH, FLAGS | FL_FOR_ARCH##ARCH, arm_##COSTS##_rtx_costs},
547 #include "arm-cores.def"
549 {NULL, arm_none, NULL, 0, NULL}
552 static const struct processors all_architectures[] =
554 /* ARM Architectures */
555 /* We don't specify rtx_costs here as it will be figured out
558 {"armv2", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
559 {"armv2a", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
560 {"armv3", arm6, "3", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3, NULL},
561 {"armv3m", arm7m, "3M", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3M, NULL},
562 {"armv4", arm7tdmi, "4", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH4, NULL},
563 /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no
564 implementations that support it, so we will leave it out for now. */
565 {"armv4t", arm7tdmi, "4T", FL_CO_PROC | FL_FOR_ARCH4T, NULL},
566 {"armv5", arm10tdmi, "5", FL_CO_PROC | FL_FOR_ARCH5, NULL},
567 {"armv5t", arm10tdmi, "5T", FL_CO_PROC | FL_FOR_ARCH5T, NULL},
568 {"armv5e", arm1026ejs, "5E", FL_CO_PROC | FL_FOR_ARCH5E, NULL},
569 {"armv5te", arm1026ejs, "5TE", FL_CO_PROC | FL_FOR_ARCH5TE, NULL},
570 {"armv6", arm1136js, "6", FL_CO_PROC | FL_FOR_ARCH6, NULL},
571 {"armv6j", arm1136js, "6J", FL_CO_PROC | FL_FOR_ARCH6J, NULL},
572 {"armv6k", mpcore, "6K", FL_CO_PROC | FL_FOR_ARCH6K, NULL},
573 {"armv6z", arm1176jzs, "6Z", FL_CO_PROC | FL_FOR_ARCH6Z, NULL},
574 {"armv6zk", arm1176jzs, "6ZK", FL_CO_PROC | FL_FOR_ARCH6ZK, NULL},
575 {"ep9312", ep9312, "4T", FL_LDSCHED | FL_CIRRUS | FL_FOR_ARCH4, NULL},
576 {"iwmmxt", iwmmxt, "5TE", FL_LDSCHED | FL_STRONG | FL_FOR_ARCH5TE | FL_XSCALE | FL_IWMMXT , NULL},
577 {NULL, arm_none, NULL, 0 , NULL}
580 struct arm_cpu_select
584 const struct processors * processors;
587 /* This is a magic structure. The 'string' field is magically filled in
588 with a pointer to the value specified by the user on the command line
589 assuming that the user has specified such a value. */
591 static struct arm_cpu_select arm_select[] =
593 /* string name processors */
594 { NULL, "-mcpu=", all_cores },
595 { NULL, "-march=", all_architectures },
596 { NULL, "-mtune=", all_cores }
599 /* Defines representing the indexes into the above table. */
600 #define ARM_OPT_SET_CPU 0
601 #define ARM_OPT_SET_ARCH 1
602 #define ARM_OPT_SET_TUNE 2
604 /* The name of the proprocessor macro to define for this architecture. */
606 char arm_arch_name[] = "__ARM_ARCH_0UNK__";
615 /* Available values for for -mfpu=. */
617 static const struct fpu_desc all_fpus[] =
619 {"fpa", FPUTYPE_FPA},
620 {"fpe2", FPUTYPE_FPA_EMU2},
621 {"fpe3", FPUTYPE_FPA_EMU2},
622 {"maverick", FPUTYPE_MAVERICK},
627 /* Floating point models used by the different hardware.
628 See fputype in arm.h. */
630 static const enum fputype fp_model_for_fpu[] =
632 /* No FP hardware. */
633 ARM_FP_MODEL_UNKNOWN, /* FPUTYPE_NONE */
634 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA */
635 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA_EMU2 */
636 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA_EMU3 */
637 ARM_FP_MODEL_MAVERICK, /* FPUTYPE_MAVERICK */
638 ARM_FP_MODEL_VFP /* FPUTYPE_VFP */
645 enum float_abi_type abi_type;
649 /* Available values for -mfloat-abi=. */
651 static const struct float_abi all_float_abis[] =
653 {"soft", ARM_FLOAT_ABI_SOFT},
654 {"softfp", ARM_FLOAT_ABI_SOFTFP},
655 {"hard", ARM_FLOAT_ABI_HARD}
662 enum arm_abi_type abi_type;
666 /* Available values for -mabi=. */
668 static const struct abi_name arm_all_abis[] =
670 {"apcs-gnu", ARM_ABI_APCS},
671 {"atpcs", ARM_ABI_ATPCS},
672 {"aapcs", ARM_ABI_AAPCS},
673 {"iwmmxt", ARM_ABI_IWMMXT}
676 /* Return the number of bits set in VALUE. */
678 bit_count (unsigned long value)
680 unsigned long count = 0;
685 value &= value - 1; /* Clear the least-significant set bit. */
691 /* Set up library functions unique to ARM. */
694 arm_init_libfuncs (void)
696 /* There are no special library functions unless we are using the
701 /* The functions below are described in Section 4 of the "Run-Time
702 ABI for the ARM architecture", Version 1.0. */
704 /* Double-precision floating-point arithmetic. Table 2. */
705 set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd");
706 set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv");
707 set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul");
708 set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg");
709 set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub");
711 /* Double-precision comparisons. Table 3. */
712 set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq");
713 set_optab_libfunc (ne_optab, DFmode, NULL);
714 set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt");
715 set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple");
716 set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge");
717 set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt");
718 set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun");
720 /* Single-precision floating-point arithmetic. Table 4. */
721 set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd");
722 set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv");
723 set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul");
724 set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg");
725 set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub");
727 /* Single-precision comparisons. Table 5. */
728 set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq");
729 set_optab_libfunc (ne_optab, SFmode, NULL);
730 set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt");
731 set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple");
732 set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge");
733 set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt");
734 set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun");
736 /* Floating-point to integer conversions. Table 6. */
737 set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz");
738 set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz");
739 set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz");
740 set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz");
741 set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz");
742 set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz");
743 set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz");
744 set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz");
746 /* Conversions between floating types. Table 7. */
747 set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f");
748 set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d");
750 /* Integer to floating-point conversions. Table 8. */
751 set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d");
752 set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d");
753 set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d");
754 set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d");
755 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f");
756 set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f");
757 set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f");
758 set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f");
760 /* Long long. Table 9. */
761 set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul");
762 set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod");
763 set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod");
764 set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl");
765 set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr");
766 set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr");
767 set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp");
768 set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp");
770 /* Integer (32/32->32) division. \S 4.3.1. */
771 set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod");
772 set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod");
774 /* The divmod functions are designed so that they can be used for
775 plain division, even though they return both the quotient and the
776 remainder. The quotient is returned in the usual location (i.e.,
777 r0 for SImode, {r0, r1} for DImode), just as would be expected
778 for an ordinary division routine. Because the AAPCS calling
779 conventions specify that all of { r0, r1, r2, r3 } are
780 callee-saved registers, there is no need to tell the compiler
781 explicitly that those registers are clobbered by these
783 set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod");
784 set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod");
785 set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idivmod");
786 set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidivmod");
788 /* We don't have mod libcalls. Fortunately gcc knows how to use the
789 divmod libcalls instead. */
790 set_optab_libfunc (smod_optab, DImode, NULL);
791 set_optab_libfunc (umod_optab, DImode, NULL);
792 set_optab_libfunc (smod_optab, SImode, NULL);
793 set_optab_libfunc (umod_optab, SImode, NULL);
796 /* Implement TARGET_HANDLE_OPTION. */
799 arm_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
804 target_abi_name = arg;
808 arm_select[1].string = arg;
812 arm_select[0].string = arg;
815 case OPT_mfloat_abi_:
816 target_float_abi_name = arg;
821 target_fpe_name = arg;
825 target_fpu_name = arg;
828 case OPT_mhard_float:
829 target_float_abi_name = "hard";
832 case OPT_mpic_register_:
833 arm_pic_register_string = arg;
836 case OPT_msoft_float:
837 target_float_abi_name = "soft";
840 case OPT_mstructure_size_boundary_:
841 structure_size_string = arg;
845 arm_select[2].string = arg;
853 /* Fix up any incompatible options that the user has specified.
854 This has now turned into a maze. */
856 arm_override_options (void)
859 enum processor_type target_arch_cpu = arm_none;
861 /* Set up the flags based on the cpu/architecture selected by the user. */
862 for (i = ARRAY_SIZE (arm_select); i--;)
864 struct arm_cpu_select * ptr = arm_select + i;
866 if (ptr->string != NULL && ptr->string[0] != '\0')
868 const struct processors * sel;
870 for (sel = ptr->processors; sel->name != NULL; sel++)
871 if (streq (ptr->string, sel->name))
873 /* Set the architecture define. */
874 if (i != ARM_OPT_SET_TUNE)
875 sprintf (arm_arch_name, "__ARM_ARCH_%s__", sel->arch);
877 /* Determine the processor core for which we should
878 tune code-generation. */
879 if (/* -mcpu= is a sensible default. */
881 /* -mtune= overrides -mcpu= and -march=. */
882 || i == ARM_OPT_SET_TUNE)
883 arm_tune = (enum processor_type) (sel - ptr->processors);
885 /* Remember the CPU associated with this architecture.
886 If no other option is used to set the CPU type,
887 we'll use this to guess the most suitable tuning
889 if (i == ARM_OPT_SET_ARCH)
890 target_arch_cpu = sel->core;
892 if (i != ARM_OPT_SET_TUNE)
894 /* If we have been given an architecture and a processor
895 make sure that they are compatible. We only generate
896 a warning though, and we prefer the CPU over the
898 if (insn_flags != 0 && (insn_flags ^ sel->flags))
899 warning (0, "switch -mcpu=%s conflicts with -march= switch",
902 insn_flags = sel->flags;
908 if (sel->name == NULL)
909 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
913 /* Guess the tuning options from the architecture if necessary. */
914 if (arm_tune == arm_none)
915 arm_tune = target_arch_cpu;
917 /* If the user did not specify a processor, choose one for them. */
920 const struct processors * sel;
922 enum processor_type cpu;
924 cpu = TARGET_CPU_DEFAULT;
927 #ifdef SUBTARGET_CPU_DEFAULT
928 /* Use the subtarget default CPU if none was specified by
930 cpu = SUBTARGET_CPU_DEFAULT;
932 /* Default to ARM6. */
936 sel = &all_cores[cpu];
938 insn_flags = sel->flags;
940 /* Now check to see if the user has specified some command line
941 switch that require certain abilities from the cpu. */
944 if (TARGET_INTERWORK || TARGET_THUMB)
946 sought |= (FL_THUMB | FL_MODE32);
948 /* There are no ARM processors that support both APCS-26 and
949 interworking. Therefore we force FL_MODE26 to be removed
950 from insn_flags here (if it was set), so that the search
951 below will always be able to find a compatible processor. */
952 insn_flags &= ~FL_MODE26;
955 if (sought != 0 && ((sought & insn_flags) != sought))
957 /* Try to locate a CPU type that supports all of the abilities
958 of the default CPU, plus the extra abilities requested by
960 for (sel = all_cores; sel->name != NULL; sel++)
961 if ((sel->flags & sought) == (sought | insn_flags))
964 if (sel->name == NULL)
966 unsigned current_bit_count = 0;
967 const struct processors * best_fit = NULL;
969 /* Ideally we would like to issue an error message here
970 saying that it was not possible to find a CPU compatible
971 with the default CPU, but which also supports the command
972 line options specified by the programmer, and so they
973 ought to use the -mcpu=<name> command line option to
974 override the default CPU type.
976 If we cannot find a cpu that has both the
977 characteristics of the default cpu and the given
978 command line options we scan the array again looking
980 for (sel = all_cores; sel->name != NULL; sel++)
981 if ((sel->flags & sought) == sought)
985 count = bit_count (sel->flags & insn_flags);
987 if (count >= current_bit_count)
990 current_bit_count = count;
994 gcc_assert (best_fit);
998 insn_flags = sel->flags;
1000 sprintf (arm_arch_name, "__ARM_ARCH_%s__", sel->arch);
1001 if (arm_tune == arm_none)
1002 arm_tune = (enum processor_type) (sel - all_cores);
1005 /* The processor for which we should tune should now have been
1007 gcc_assert (arm_tune != arm_none);
1009 tune_flags = all_cores[(int)arm_tune].flags;
1011 targetm.rtx_costs = arm_size_rtx_costs;
1013 targetm.rtx_costs = all_cores[(int)arm_tune].rtx_costs;
1015 /* Make sure that the processor choice does not conflict with any of the
1016 other command line choices. */
1017 if (TARGET_INTERWORK && !(insn_flags & FL_THUMB))
1019 warning (0, "target CPU does not support interworking" );
1020 target_flags &= ~MASK_INTERWORK;
1023 if (TARGET_THUMB && !(insn_flags & FL_THUMB))
1025 warning (0, "target CPU does not support THUMB instructions");
1026 target_flags &= ~MASK_THUMB;
1029 if (TARGET_APCS_FRAME && TARGET_THUMB)
1031 /* warning (0, "ignoring -mapcs-frame because -mthumb was used"); */
1032 target_flags &= ~MASK_APCS_FRAME;
1035 /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done
1036 from here where no function is being compiled currently. */
1037 if ((TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) && TARGET_ARM)
1038 warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb");
1040 if (TARGET_ARM && TARGET_CALLEE_INTERWORKING)
1041 warning (0, "enabling callee interworking support is only meaningful when compiling for the Thumb");
1043 if (TARGET_ARM && TARGET_CALLER_INTERWORKING)
1044 warning (0, "enabling caller interworking support is only meaningful when compiling for the Thumb");
1046 if (TARGET_APCS_STACK && !TARGET_APCS_FRAME)
1048 warning (0, "-mapcs-stack-check incompatible with -mno-apcs-frame");
1049 target_flags |= MASK_APCS_FRAME;
1052 if (TARGET_POKE_FUNCTION_NAME)
1053 target_flags |= MASK_APCS_FRAME;
1055 if (TARGET_APCS_REENT && flag_pic)
1056 error ("-fpic and -mapcs-reent are incompatible");
1058 if (TARGET_APCS_REENT)
1059 warning (0, "APCS reentrant code not supported. Ignored");
1061 /* If this target is normally configured to use APCS frames, warn if they
1062 are turned off and debugging is turned on. */
1064 && write_symbols != NO_DEBUG
1065 && !TARGET_APCS_FRAME
1066 && (TARGET_DEFAULT & MASK_APCS_FRAME))
1067 warning (0, "-g with -mno-apcs-frame may not give sensible debugging");
1069 /* If stack checking is disabled, we can use r10 as the PIC register,
1070 which keeps r9 available. */
1072 arm_pic_register = TARGET_APCS_STACK ? 9 : 10;
1074 if (TARGET_APCS_FLOAT)
1075 warning (0, "passing floating point arguments in fp regs not yet supported");
1077 /* Initialize boolean versions of the flags, for use in the arm.md file. */
1078 arm_arch3m = (insn_flags & FL_ARCH3M) != 0;
1079 arm_arch4 = (insn_flags & FL_ARCH4) != 0;
1080 arm_arch4t = arm_arch4 & ((insn_flags & FL_THUMB) != 0);
1081 arm_arch5 = (insn_flags & FL_ARCH5) != 0;
1082 arm_arch5e = (insn_flags & FL_ARCH5E) != 0;
1083 arm_arch6 = (insn_flags & FL_ARCH6) != 0;
1084 arm_arch_xscale = (insn_flags & FL_XSCALE) != 0;
1085 arm_arch_cirrus = (insn_flags & FL_CIRRUS) != 0;
1087 arm_ld_sched = (tune_flags & FL_LDSCHED) != 0;
1088 arm_tune_strongarm = (tune_flags & FL_STRONG) != 0;
1089 thumb_code = (TARGET_ARM == 0);
1090 arm_tune_wbuf = (tune_flags & FL_WBUF) != 0;
1091 arm_tune_xscale = (tune_flags & FL_XSCALE) != 0;
1092 arm_arch_iwmmxt = (insn_flags & FL_IWMMXT) != 0;
1094 /* V5 code we generate is completely interworking capable, so we turn off
1095 TARGET_INTERWORK here to avoid many tests later on. */
1097 /* XXX However, we must pass the right pre-processor defines to CPP
1098 or GLD can get confused. This is a hack. */
1099 if (TARGET_INTERWORK)
1100 arm_cpp_interwork = 1;
1103 target_flags &= ~MASK_INTERWORK;
1105 if (target_abi_name)
1107 for (i = 0; i < ARRAY_SIZE (arm_all_abis); i++)
1109 if (streq (arm_all_abis[i].name, target_abi_name))
1111 arm_abi = arm_all_abis[i].abi_type;
1115 if (i == ARRAY_SIZE (arm_all_abis))
1116 error ("invalid ABI option: -mabi=%s", target_abi_name);
1119 arm_abi = ARM_DEFAULT_ABI;
1121 if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN)
1122 error ("iwmmxt requires an AAPCS compatible ABI for proper operation");
1124 if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT)
1125 error ("iwmmxt abi requires an iwmmxt capable cpu");
1127 arm_fp_model = ARM_FP_MODEL_UNKNOWN;
1128 if (target_fpu_name == NULL && target_fpe_name != NULL)
1130 if (streq (target_fpe_name, "2"))
1131 target_fpu_name = "fpe2";
1132 else if (streq (target_fpe_name, "3"))
1133 target_fpu_name = "fpe3";
1135 error ("invalid floating point emulation option: -mfpe=%s",
1138 if (target_fpu_name != NULL)
1140 /* The user specified a FPU. */
1141 for (i = 0; i < ARRAY_SIZE (all_fpus); i++)
1143 if (streq (all_fpus[i].name, target_fpu_name))
1145 arm_fpu_arch = all_fpus[i].fpu;
1146 arm_fpu_tune = arm_fpu_arch;
1147 arm_fp_model = fp_model_for_fpu[arm_fpu_arch];
1151 if (arm_fp_model == ARM_FP_MODEL_UNKNOWN)
1152 error ("invalid floating point option: -mfpu=%s", target_fpu_name);
1156 #ifdef FPUTYPE_DEFAULT
1157 /* Use the default if it is specified for this platform. */
1158 arm_fpu_arch = FPUTYPE_DEFAULT;
1159 arm_fpu_tune = FPUTYPE_DEFAULT;
1161 /* Pick one based on CPU type. */
1162 /* ??? Some targets assume FPA is the default.
1163 if ((insn_flags & FL_VFP) != 0)
1164 arm_fpu_arch = FPUTYPE_VFP;
1167 if (arm_arch_cirrus)
1168 arm_fpu_arch = FPUTYPE_MAVERICK;
1170 arm_fpu_arch = FPUTYPE_FPA_EMU2;
1172 if (tune_flags & FL_CO_PROC && arm_fpu_arch == FPUTYPE_FPA_EMU2)
1173 arm_fpu_tune = FPUTYPE_FPA;
1175 arm_fpu_tune = arm_fpu_arch;
1176 arm_fp_model = fp_model_for_fpu[arm_fpu_arch];
1177 gcc_assert (arm_fp_model != ARM_FP_MODEL_UNKNOWN);
1180 if (target_float_abi_name != NULL)
1182 /* The user specified a FP ABI. */
1183 for (i = 0; i < ARRAY_SIZE (all_float_abis); i++)
1185 if (streq (all_float_abis[i].name, target_float_abi_name))
1187 arm_float_abi = all_float_abis[i].abi_type;
1191 if (i == ARRAY_SIZE (all_float_abis))
1192 error ("invalid floating point abi: -mfloat-abi=%s",
1193 target_float_abi_name);
1196 arm_float_abi = TARGET_DEFAULT_FLOAT_ABI;
1198 if (arm_float_abi == ARM_FLOAT_ABI_HARD && TARGET_VFP)
1199 sorry ("-mfloat-abi=hard and VFP");
1201 /* If soft-float is specified then don't use FPU. */
1202 if (TARGET_SOFT_FLOAT)
1203 arm_fpu_arch = FPUTYPE_NONE;
1205 /* For arm2/3 there is no need to do any scheduling if there is only
1206 a floating point emulator, or we are doing software floating-point. */
1207 if ((TARGET_SOFT_FLOAT
1208 || arm_fpu_tune == FPUTYPE_FPA_EMU2
1209 || arm_fpu_tune == FPUTYPE_FPA_EMU3)
1210 && (tune_flags & FL_MODE32) == 0)
1211 flag_schedule_insns = flag_schedule_insns_after_reload = 0;
1213 /* Override the default structure alignment for AAPCS ABI. */
1214 if (arm_abi == ARM_ABI_AAPCS)
1215 arm_structure_size_boundary = 8;
1217 if (structure_size_string != NULL)
1219 int size = strtol (structure_size_string, NULL, 0);
1221 if (size == 8 || size == 32
1222 || (ARM_DOUBLEWORD_ALIGN && size == 64))
1223 arm_structure_size_boundary = size;
1225 warning (0, "structure size boundary can only be set to %s",
1226 ARM_DOUBLEWORD_ALIGN ? "8, 32 or 64": "8 or 32");
1229 if (arm_pic_register_string != NULL)
1231 int pic_register = decode_reg_name (arm_pic_register_string);
1234 warning (0, "-mpic-register= is useless without -fpic");
1236 /* Prevent the user from choosing an obviously stupid PIC register. */
1237 else if (pic_register < 0 || call_used_regs[pic_register]
1238 || pic_register == HARD_FRAME_POINTER_REGNUM
1239 || pic_register == STACK_POINTER_REGNUM
1240 || pic_register >= PC_REGNUM)
1241 error ("unable to use '%s' for PIC register", arm_pic_register_string);
1243 arm_pic_register = pic_register;
1246 if (TARGET_THUMB && flag_schedule_insns)
1248 /* Don't warn since it's on by default in -O2. */
1249 flag_schedule_insns = 0;
1254 /* There's some dispute as to whether this should be 1 or 2. However,
1255 experiments seem to show that in pathological cases a setting of
1256 1 degrades less severely than a setting of 2. This could change if
1257 other parts of the compiler change their behavior. */
1258 arm_constant_limit = 1;
1260 /* If optimizing for size, bump the number of instructions that we
1261 are prepared to conditionally execute (even on a StrongARM). */
1262 max_insns_skipped = 6;
1266 /* For processors with load scheduling, it never costs more than
1267 2 cycles to load a constant, and the load scheduler may well
1268 reduce that to 1. */
1270 arm_constant_limit = 1;
1272 /* On XScale the longer latency of a load makes it more difficult
1273 to achieve a good schedule, so it's faster to synthesize
1274 constants that can be done in two insns. */
1275 if (arm_tune_xscale)
1276 arm_constant_limit = 2;
1278 /* StrongARM has early execution of branches, so a sequence
1279 that is worth skipping is shorter. */
1280 if (arm_tune_strongarm)
1281 max_insns_skipped = 3;
1284 /* Register global variables with the garbage collector. */
1285 arm_add_gc_roots ();
1289 arm_add_gc_roots (void)
1291 gcc_obstack_init(&minipool_obstack);
1292 minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0);
1295 /* A table of known ARM exception types.
1296 For use with the interrupt function attribute. */
1300 const char *const arg;
1301 const unsigned long return_value;
1305 static const isr_attribute_arg isr_attribute_args [] =
1307 { "IRQ", ARM_FT_ISR },
1308 { "irq", ARM_FT_ISR },
1309 { "FIQ", ARM_FT_FIQ },
1310 { "fiq", ARM_FT_FIQ },
1311 { "ABORT", ARM_FT_ISR },
1312 { "abort", ARM_FT_ISR },
1313 { "ABORT", ARM_FT_ISR },
1314 { "abort", ARM_FT_ISR },
1315 { "UNDEF", ARM_FT_EXCEPTION },
1316 { "undef", ARM_FT_EXCEPTION },
1317 { "SWI", ARM_FT_EXCEPTION },
1318 { "swi", ARM_FT_EXCEPTION },
1319 { NULL, ARM_FT_NORMAL }
1322 /* Returns the (interrupt) function type of the current
1323 function, or ARM_FT_UNKNOWN if the type cannot be determined. */
1325 static unsigned long
1326 arm_isr_value (tree argument)
1328 const isr_attribute_arg * ptr;
1331 /* No argument - default to IRQ. */
1332 if (argument == NULL_TREE)
1335 /* Get the value of the argument. */
1336 if (TREE_VALUE (argument) == NULL_TREE
1337 || TREE_CODE (TREE_VALUE (argument)) != STRING_CST)
1338 return ARM_FT_UNKNOWN;
1340 arg = TREE_STRING_POINTER (TREE_VALUE (argument));
1342 /* Check it against the list of known arguments. */
1343 for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)
1344 if (streq (arg, ptr->arg))
1345 return ptr->return_value;
1347 /* An unrecognized interrupt type. */
1348 return ARM_FT_UNKNOWN;
1351 /* Computes the type of the current function. */
1353 static unsigned long
1354 arm_compute_func_type (void)
1356 unsigned long type = ARM_FT_UNKNOWN;
1360 gcc_assert (TREE_CODE (current_function_decl) == FUNCTION_DECL);
1362 /* Decide if the current function is volatile. Such functions
1363 never return, and many memory cycles can be saved by not storing
1364 register values that will never be needed again. This optimization
1365 was added to speed up context switching in a kernel application. */
1367 && TREE_NOTHROW (current_function_decl)
1368 && TREE_THIS_VOLATILE (current_function_decl))
1369 type |= ARM_FT_VOLATILE;
1371 if (cfun->static_chain_decl != NULL)
1372 type |= ARM_FT_NESTED;
1374 attr = DECL_ATTRIBUTES (current_function_decl);
1376 a = lookup_attribute ("naked", attr);
1378 type |= ARM_FT_NAKED;
1380 a = lookup_attribute ("isr", attr);
1382 a = lookup_attribute ("interrupt", attr);
1385 type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL;
1387 type |= arm_isr_value (TREE_VALUE (a));
1392 /* Returns the type of the current function. */
1395 arm_current_func_type (void)
1397 if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN)
1398 cfun->machine->func_type = arm_compute_func_type ();
1400 return cfun->machine->func_type;
1403 /* Return 1 if it is possible to return using a single instruction.
1404 If SIBLING is non-null, this is a test for a return before a sibling
1405 call. SIBLING is the call insn, so we can examine its register usage. */
1408 use_return_insn (int iscond, rtx sibling)
1411 unsigned int func_type;
1412 unsigned long saved_int_regs;
1413 unsigned HOST_WIDE_INT stack_adjust;
1414 arm_stack_offsets *offsets;
1416 /* Never use a return instruction before reload has run. */
1417 if (!reload_completed)
1420 func_type = arm_current_func_type ();
1422 /* Naked functions and volatile functions need special
1424 if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED))
1427 /* So do interrupt functions that use the frame pointer. */
1428 if (IS_INTERRUPT (func_type) && frame_pointer_needed)
1431 offsets = arm_get_frame_offsets ();
1432 stack_adjust = offsets->outgoing_args - offsets->saved_regs;
1434 /* As do variadic functions. */
1435 if (current_function_pretend_args_size
1436 || cfun->machine->uses_anonymous_args
1437 /* Or if the function calls __builtin_eh_return () */
1438 || current_function_calls_eh_return
1439 /* Or if the function calls alloca */
1440 || current_function_calls_alloca
1441 /* Or if there is a stack adjustment. However, if the stack pointer
1442 is saved on the stack, we can use a pre-incrementing stack load. */
1443 || !(stack_adjust == 0 || (frame_pointer_needed && stack_adjust == 4)))
1446 saved_int_regs = arm_compute_save_reg_mask ();
1448 /* Unfortunately, the insn
1450 ldmib sp, {..., sp, ...}
1452 triggers a bug on most SA-110 based devices, such that the stack
1453 pointer won't be correctly restored if the instruction takes a
1454 page fault. We work around this problem by popping r3 along with
1455 the other registers, since that is never slower than executing
1456 another instruction.
1458 We test for !arm_arch5 here, because code for any architecture
1459 less than this could potentially be run on one of the buggy
1461 if (stack_adjust == 4 && !arm_arch5)
1463 /* Validate that r3 is a call-clobbered register (always true in
1464 the default abi) ... */
1465 if (!call_used_regs[3])
1468 /* ... that it isn't being used for a return value (always true
1469 until we implement return-in-regs), or for a tail-call
1473 gcc_assert (GET_CODE (sibling) == CALL_INSN);
1475 if (find_regno_fusage (sibling, USE, 3))
1479 /* ... and that there are no call-saved registers in r0-r2
1480 (always true in the default ABI). */
1481 if (saved_int_regs & 0x7)
1485 /* Can't be done if interworking with Thumb, and any registers have been
1487 if (TARGET_INTERWORK && saved_int_regs != 0)
1490 /* On StrongARM, conditional returns are expensive if they aren't
1491 taken and multiple registers have been stacked. */
1492 if (iscond && arm_tune_strongarm)
1494 /* Conditional return when just the LR is stored is a simple
1495 conditional-load instruction, that's not expensive. */
1496 if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM))
1499 if (flag_pic && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
1503 /* If there are saved registers but the LR isn't saved, then we need
1504 two instructions for the return. */
1505 if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM)))
1508 /* Can't be done if any of the FPA regs are pushed,
1509 since this also requires an insn. */
1510 if (TARGET_HARD_FLOAT && TARGET_FPA)
1511 for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++)
1512 if (regs_ever_live[regno] && !call_used_regs[regno])
1515 /* Likewise VFP regs. */
1516 if (TARGET_HARD_FLOAT && TARGET_VFP)
1517 for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++)
1518 if (regs_ever_live[regno] && !call_used_regs[regno])
1521 if (TARGET_REALLY_IWMMXT)
1522 for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++)
1523 if (regs_ever_live[regno] && ! call_used_regs [regno])
1529 /* Return TRUE if int I is a valid immediate ARM constant. */
1532 const_ok_for_arm (HOST_WIDE_INT i)
1536 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
1537 be all zero, or all one. */
1538 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
1539 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
1540 != ((~(unsigned HOST_WIDE_INT) 0)
1541 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
1544 i &= (unsigned HOST_WIDE_INT) 0xffffffff;
1546 /* Fast return for 0 and small values. We must do this for zero, since
1547 the code below can't handle that one case. */
1548 if ((i & ~(unsigned HOST_WIDE_INT) 0xff) == 0)
1551 /* Get the number of trailing zeros, rounded down to the nearest even
1553 lowbit = (ffs ((int) i) - 1) & ~1;
1555 if ((i & ~(((unsigned HOST_WIDE_INT) 0xff) << lowbit)) == 0)
1557 else if (lowbit <= 4
1558 && ((i & ~0xc000003f) == 0
1559 || (i & ~0xf000000f) == 0
1560 || (i & ~0xfc000003) == 0))
1566 /* Return true if I is a valid constant for the operation CODE. */
1568 const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code)
1570 if (const_ok_for_arm (i))
1576 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
1578 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
1584 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
1591 /* Emit a sequence of insns to handle a large constant.
1592 CODE is the code of the operation required, it can be any of SET, PLUS,
1593 IOR, AND, XOR, MINUS;
1594 MODE is the mode in which the operation is being performed;
1595 VAL is the integer to operate on;
1596 SOURCE is the other operand (a register, or a null-pointer for SET);
1597 SUBTARGETS means it is safe to create scratch registers if that will
1598 either produce a simpler sequence, or we will want to cse the values.
1599 Return value is the number of insns emitted. */
1602 arm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn,
1603 HOST_WIDE_INT val, rtx target, rtx source, int subtargets)
1607 if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC)
1608 cond = COND_EXEC_TEST (PATTERN (insn));
1612 if (subtargets || code == SET
1613 || (GET_CODE (target) == REG && GET_CODE (source) == REG
1614 && REGNO (target) != REGNO (source)))
1616 /* After arm_reorg has been called, we can't fix up expensive
1617 constants by pushing them into memory so we must synthesize
1618 them in-line, regardless of the cost. This is only likely to
1619 be more costly on chips that have load delay slots and we are
1620 compiling without running the scheduler (so no splitting
1621 occurred before the final instruction emission).
1623 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
1625 if (!after_arm_reorg
1627 && (arm_gen_constant (code, mode, NULL_RTX, val, target, source,
1629 > arm_constant_limit + (code != SET)))
1633 /* Currently SET is the only monadic value for CODE, all
1634 the rest are diadic. */
1635 emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (val)));
1640 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
1642 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (val)));
1643 /* For MINUS, the value is subtracted from, since we never
1644 have subtraction of a constant. */
1646 emit_insn (gen_rtx_SET (VOIDmode, target,
1647 gen_rtx_MINUS (mode, temp, source)));
1649 emit_insn (gen_rtx_SET (VOIDmode, target,
1650 gen_rtx_fmt_ee (code, mode, source, temp)));
1656 return arm_gen_constant (code, mode, cond, val, target, source, subtargets,
1661 count_insns_for_constant (HOST_WIDE_INT remainder, int i)
1663 HOST_WIDE_INT temp1;
1671 if (remainder & (3 << (i - 2)))
1676 temp1 = remainder & ((0x0ff << end)
1677 | ((i < end) ? (0xff >> (32 - end)) : 0));
1678 remainder &= ~temp1;
1683 } while (remainder);
1687 /* Emit an instruction with the indicated PATTERN. If COND is
1688 non-NULL, conditionalize the execution of the instruction on COND
1692 emit_constant_insn (rtx cond, rtx pattern)
1695 pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern);
1696 emit_insn (pattern);
1699 /* As above, but extra parameter GENERATE which, if clear, suppresses
1703 arm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond,
1704 HOST_WIDE_INT val, rtx target, rtx source, int subtargets,
1709 int can_negate_initial = 0;
1712 int num_bits_set = 0;
1713 int set_sign_bit_copies = 0;
1714 int clear_sign_bit_copies = 0;
1715 int clear_zero_bit_copies = 0;
1716 int set_zero_bit_copies = 0;
1718 unsigned HOST_WIDE_INT temp1, temp2;
1719 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
1721 /* Find out which operations are safe for a given CODE. Also do a quick
1722 check for degenerate cases; these can occur when DImode operations
1734 can_negate_initial = 1;
1738 if (remainder == 0xffffffff)
1741 emit_constant_insn (cond,
1742 gen_rtx_SET (VOIDmode, target,
1743 GEN_INT (ARM_SIGN_EXTEND (val))));
1748 if (reload_completed && rtx_equal_p (target, source))
1751 emit_constant_insn (cond,
1752 gen_rtx_SET (VOIDmode, target, source));
1761 emit_constant_insn (cond,
1762 gen_rtx_SET (VOIDmode, target, const0_rtx));
1765 if (remainder == 0xffffffff)
1767 if (reload_completed && rtx_equal_p (target, source))
1770 emit_constant_insn (cond,
1771 gen_rtx_SET (VOIDmode, target, source));
1780 if (reload_completed && rtx_equal_p (target, source))
1783 emit_constant_insn (cond,
1784 gen_rtx_SET (VOIDmode, target, source));
1788 /* We don't know how to handle other cases yet. */
1789 gcc_assert (remainder == 0xffffffff);
1792 emit_constant_insn (cond,
1793 gen_rtx_SET (VOIDmode, target,
1794 gen_rtx_NOT (mode, source)));
1798 /* We treat MINUS as (val - source), since (source - val) is always
1799 passed as (source + (-val)). */
1803 emit_constant_insn (cond,
1804 gen_rtx_SET (VOIDmode, target,
1805 gen_rtx_NEG (mode, source)));
1808 if (const_ok_for_arm (val))
1811 emit_constant_insn (cond,
1812 gen_rtx_SET (VOIDmode, target,
1813 gen_rtx_MINUS (mode, GEN_INT (val),
1825 /* If we can do it in one insn get out quickly. */
1826 if (const_ok_for_arm (val)
1827 || (can_negate_initial && const_ok_for_arm (-val))
1828 || (can_invert && const_ok_for_arm (~val)))
1831 emit_constant_insn (cond,
1832 gen_rtx_SET (VOIDmode, target,
1834 ? gen_rtx_fmt_ee (code, mode, source,
1840 /* Calculate a few attributes that may be useful for specific
1842 for (i = 31; i >= 0; i--)
1844 if ((remainder & (1 << i)) == 0)
1845 clear_sign_bit_copies++;
1850 for (i = 31; i >= 0; i--)
1852 if ((remainder & (1 << i)) != 0)
1853 set_sign_bit_copies++;
1858 for (i = 0; i <= 31; i++)
1860 if ((remainder & (1 << i)) == 0)
1861 clear_zero_bit_copies++;
1866 for (i = 0; i <= 31; i++)
1868 if ((remainder & (1 << i)) != 0)
1869 set_zero_bit_copies++;
1877 /* See if we can do this by sign_extending a constant that is known
1878 to be negative. This is a good, way of doing it, since the shift
1879 may well merge into a subsequent insn. */
1880 if (set_sign_bit_copies > 1)
1882 if (const_ok_for_arm
1883 (temp1 = ARM_SIGN_EXTEND (remainder
1884 << (set_sign_bit_copies - 1))))
1888 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1889 emit_constant_insn (cond,
1890 gen_rtx_SET (VOIDmode, new_src,
1892 emit_constant_insn (cond,
1893 gen_ashrsi3 (target, new_src,
1894 GEN_INT (set_sign_bit_copies - 1)));
1898 /* For an inverted constant, we will need to set the low bits,
1899 these will be shifted out of harm's way. */
1900 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
1901 if (const_ok_for_arm (~temp1))
1905 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1906 emit_constant_insn (cond,
1907 gen_rtx_SET (VOIDmode, new_src,
1909 emit_constant_insn (cond,
1910 gen_ashrsi3 (target, new_src,
1911 GEN_INT (set_sign_bit_copies - 1)));
1917 /* See if we can calculate the value as the difference between two
1918 valid immediates. */
1919 if (clear_sign_bit_copies + clear_zero_bit_copies <= 16)
1921 int topshift = clear_sign_bit_copies & ~1;
1923 temp1 = ARM_SIGN_EXTEND ((remainder + (0x00800000 >> topshift))
1924 & (0xff000000 >> topshift));
1926 /* If temp1 is zero, then that means the 9 most significant
1927 bits of remainder were 1 and we've caused it to overflow.
1928 When topshift is 0 we don't need to do anything since we
1929 can borrow from 'bit 32'. */
1930 if (temp1 == 0 && topshift != 0)
1931 temp1 = 0x80000000 >> (topshift - 1);
1933 temp2 = ARM_SIGN_EXTEND (temp1 - remainder);
1935 if (const_ok_for_arm (temp2))
1939 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1940 emit_constant_insn (cond,
1941 gen_rtx_SET (VOIDmode, new_src,
1943 emit_constant_insn (cond,
1944 gen_addsi3 (target, new_src,
1952 /* See if we can generate this by setting the bottom (or the top)
1953 16 bits, and then shifting these into the other half of the
1954 word. We only look for the simplest cases, to do more would cost
1955 too much. Be careful, however, not to generate this when the
1956 alternative would take fewer insns. */
1957 if (val & 0xffff0000)
1959 temp1 = remainder & 0xffff0000;
1960 temp2 = remainder & 0x0000ffff;
1962 /* Overlaps outside this range are best done using other methods. */
1963 for (i = 9; i < 24; i++)
1965 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
1966 && !const_ok_for_arm (temp2))
1968 rtx new_src = (subtargets
1969 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
1971 insns = arm_gen_constant (code, mode, cond, temp2, new_src,
1972 source, subtargets, generate);
1980 gen_rtx_ASHIFT (mode, source,
1987 /* Don't duplicate cases already considered. */
1988 for (i = 17; i < 24; i++)
1990 if (((temp1 | (temp1 >> i)) == remainder)
1991 && !const_ok_for_arm (temp1))
1993 rtx new_src = (subtargets
1994 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
1996 insns = arm_gen_constant (code, mode, cond, temp1, new_src,
1997 source, subtargets, generate);
2002 gen_rtx_SET (VOIDmode, target,
2005 gen_rtx_LSHIFTRT (mode, source,
2016 /* If we have IOR or XOR, and the constant can be loaded in a
2017 single instruction, and we can find a temporary to put it in,
2018 then this can be done in two instructions instead of 3-4. */
2020 /* TARGET can't be NULL if SUBTARGETS is 0 */
2021 || (reload_completed && !reg_mentioned_p (target, source)))
2023 if (const_ok_for_arm (ARM_SIGN_EXTEND (~val)))
2027 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2029 emit_constant_insn (cond,
2030 gen_rtx_SET (VOIDmode, sub,
2032 emit_constant_insn (cond,
2033 gen_rtx_SET (VOIDmode, target,
2034 gen_rtx_fmt_ee (code, mode,
2044 if (set_sign_bit_copies > 8
2045 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
2049 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2050 rtx shift = GEN_INT (set_sign_bit_copies);
2054 gen_rtx_SET (VOIDmode, sub,
2056 gen_rtx_ASHIFT (mode,
2061 gen_rtx_SET (VOIDmode, target,
2063 gen_rtx_LSHIFTRT (mode, sub,
2069 if (set_zero_bit_copies > 8
2070 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
2074 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2075 rtx shift = GEN_INT (set_zero_bit_copies);
2079 gen_rtx_SET (VOIDmode, sub,
2081 gen_rtx_LSHIFTRT (mode,
2086 gen_rtx_SET (VOIDmode, target,
2088 gen_rtx_ASHIFT (mode, sub,
2094 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val)))
2098 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
2099 emit_constant_insn (cond,
2100 gen_rtx_SET (VOIDmode, sub,
2101 gen_rtx_NOT (mode, source)));
2104 sub = gen_reg_rtx (mode);
2105 emit_constant_insn (cond,
2106 gen_rtx_SET (VOIDmode, sub,
2107 gen_rtx_AND (mode, source,
2109 emit_constant_insn (cond,
2110 gen_rtx_SET (VOIDmode, target,
2111 gen_rtx_NOT (mode, sub)));
2118 /* See if two shifts will do 2 or more insn's worth of work. */
2119 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
2121 HOST_WIDE_INT shift_mask = ((0xffffffff
2122 << (32 - clear_sign_bit_copies))
2125 if ((remainder | shift_mask) != 0xffffffff)
2129 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2130 insns = arm_gen_constant (AND, mode, cond,
2131 remainder | shift_mask,
2132 new_src, source, subtargets, 1);
2137 rtx targ = subtargets ? NULL_RTX : target;
2138 insns = arm_gen_constant (AND, mode, cond,
2139 remainder | shift_mask,
2140 targ, source, subtargets, 0);
2146 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2147 rtx shift = GEN_INT (clear_sign_bit_copies);
2149 emit_insn (gen_ashlsi3 (new_src, source, shift));
2150 emit_insn (gen_lshrsi3 (target, new_src, shift));
2156 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
2158 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
2160 if ((remainder | shift_mask) != 0xffffffff)
2164 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2166 insns = arm_gen_constant (AND, mode, cond,
2167 remainder | shift_mask,
2168 new_src, source, subtargets, 1);
2173 rtx targ = subtargets ? NULL_RTX : target;
2175 insns = arm_gen_constant (AND, mode, cond,
2176 remainder | shift_mask,
2177 targ, source, subtargets, 0);
2183 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2184 rtx shift = GEN_INT (clear_zero_bit_copies);
2186 emit_insn (gen_lshrsi3 (new_src, source, shift));
2187 emit_insn (gen_ashlsi3 (target, new_src, shift));
2199 for (i = 0; i < 32; i++)
2200 if (remainder & (1 << i))
2203 if (code == AND || (can_invert && num_bits_set > 16))
2204 remainder = (~remainder) & 0xffffffff;
2205 else if (code == PLUS && num_bits_set > 16)
2206 remainder = (-remainder) & 0xffffffff;
2213 /* Now try and find a way of doing the job in either two or three
2215 We start by looking for the largest block of zeros that are aligned on
2216 a 2-bit boundary, we then fill up the temps, wrapping around to the
2217 top of the word when we drop off the bottom.
2218 In the worst case this code should produce no more than four insns. */
2221 int best_consecutive_zeros = 0;
2223 for (i = 0; i < 32; i += 2)
2225 int consecutive_zeros = 0;
2227 if (!(remainder & (3 << i)))
2229 while ((i < 32) && !(remainder & (3 << i)))
2231 consecutive_zeros += 2;
2234 if (consecutive_zeros > best_consecutive_zeros)
2236 best_consecutive_zeros = consecutive_zeros;
2237 best_start = i - consecutive_zeros;
2243 /* So long as it won't require any more insns to do so, it's
2244 desirable to emit a small constant (in bits 0...9) in the last
2245 insn. This way there is more chance that it can be combined with
2246 a later addressing insn to form a pre-indexed load or store
2247 operation. Consider:
2249 *((volatile int *)0xe0000100) = 1;
2250 *((volatile int *)0xe0000110) = 2;
2252 We want this to wind up as:
2256 str rB, [rA, #0x100]
2258 str rB, [rA, #0x110]
2260 rather than having to synthesize both large constants from scratch.
2262 Therefore, we calculate how many insns would be required to emit
2263 the constant starting from `best_start', and also starting from
2264 zero (i.e. with bit 31 first to be output). If `best_start' doesn't
2265 yield a shorter sequence, we may as well use zero. */
2267 && ((((unsigned HOST_WIDE_INT) 1) << best_start) < remainder)
2268 && (count_insns_for_constant (remainder, 0) <=
2269 count_insns_for_constant (remainder, best_start)))
2272 /* Now start emitting the insns. */
2280 if (remainder & (3 << (i - 2)))
2285 temp1 = remainder & ((0x0ff << end)
2286 | ((i < end) ? (0xff >> (32 - end)) : 0));
2287 remainder &= ~temp1;
2291 rtx new_src, temp1_rtx;
2293 if (code == SET || code == MINUS)
2295 new_src = (subtargets ? gen_reg_rtx (mode) : target);
2296 if (can_invert && code != MINUS)
2301 if (remainder && subtargets)
2302 new_src = gen_reg_rtx (mode);
2307 else if (can_negate)
2311 temp1 = trunc_int_for_mode (temp1, mode);
2312 temp1_rtx = GEN_INT (temp1);
2316 else if (code == MINUS)
2317 temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source);
2319 temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx);
2321 emit_constant_insn (cond,
2322 gen_rtx_SET (VOIDmode, new_src,
2332 else if (code == MINUS)
2346 /* Canonicalize a comparison so that we are more likely to recognize it.
2347 This can be done for a few constant compares, where we can make the
2348 immediate value easier to load. */
2351 arm_canonicalize_comparison (enum rtx_code code, rtx * op1)
2353 unsigned HOST_WIDE_INT i = INTVAL (*op1);
2363 if (i != ((((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1)) - 1)
2364 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
2366 *op1 = GEN_INT (i + 1);
2367 return code == GT ? GE : LT;
2373 if (i != (((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1))
2374 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
2376 *op1 = GEN_INT (i - 1);
2377 return code == GE ? GT : LE;
2383 if (i != ~((unsigned HOST_WIDE_INT) 0)
2384 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
2386 *op1 = GEN_INT (i + 1);
2387 return code == GTU ? GEU : LTU;
2394 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
2396 *op1 = GEN_INT (i - 1);
2397 return code == GEU ? GTU : LEU;
2409 /* Define how to find the value returned by a function. */
2412 arm_function_value(tree type, tree func ATTRIBUTE_UNUSED)
2414 enum machine_mode mode;
2415 int unsignedp ATTRIBUTE_UNUSED;
2416 rtx r ATTRIBUTE_UNUSED;
2418 mode = TYPE_MODE (type);
2419 /* Promote integer types. */
2420 if (INTEGRAL_TYPE_P (type))
2421 PROMOTE_FUNCTION_MODE (mode, unsignedp, type);
2423 /* Promotes small structs returned in a register to full-word size
2424 for big-endian AAPCS. */
2425 if (arm_return_in_msb (type))
2427 HOST_WIDE_INT size = int_size_in_bytes (type);
2428 if (size % UNITS_PER_WORD != 0)
2430 size += UNITS_PER_WORD - size % UNITS_PER_WORD;
2431 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2435 return LIBCALL_VALUE(mode);
2438 /* Determine the amount of memory needed to store the possible return
2439 registers of an untyped call. */
2441 arm_apply_result_size (void)
2447 if (TARGET_HARD_FLOAT_ABI)
2451 if (TARGET_MAVERICK)
2454 if (TARGET_IWMMXT_ABI)
2461 /* Decide whether a type should be returned in memory (true)
2462 or in a register (false). This is called by the macro
2463 RETURN_IN_MEMORY. */
2465 arm_return_in_memory (tree type)
2469 if (!AGGREGATE_TYPE_P (type) &&
2470 !(TARGET_AAPCS_BASED && TREE_CODE (type) == COMPLEX_TYPE))
2471 /* All simple types are returned in registers.
2472 For AAPCS, complex types are treated the same as aggregates. */
2475 size = int_size_in_bytes (type);
2477 if (arm_abi != ARM_ABI_APCS)
2479 /* ATPCS and later return aggregate types in memory only if they are
2480 larger than a word (or are variable size). */
2481 return (size < 0 || size > UNITS_PER_WORD);
2484 /* For the arm-wince targets we choose to be compatible with Microsoft's
2485 ARM and Thumb compilers, which always return aggregates in memory. */
2487 /* All structures/unions bigger than one word are returned in memory.
2488 Also catch the case where int_size_in_bytes returns -1. In this case
2489 the aggregate is either huge or of variable size, and in either case
2490 we will want to return it via memory and not in a register. */
2491 if (size < 0 || size > UNITS_PER_WORD)
2494 if (TREE_CODE (type) == RECORD_TYPE)
2498 /* For a struct the APCS says that we only return in a register
2499 if the type is 'integer like' and every addressable element
2500 has an offset of zero. For practical purposes this means
2501 that the structure can have at most one non bit-field element
2502 and that this element must be the first one in the structure. */
2504 /* Find the first field, ignoring non FIELD_DECL things which will
2505 have been created by C++. */
2506 for (field = TYPE_FIELDS (type);
2507 field && TREE_CODE (field) != FIELD_DECL;
2508 field = TREE_CHAIN (field))
2512 return 0; /* An empty structure. Allowed by an extension to ANSI C. */
2514 /* Check that the first field is valid for returning in a register. */
2516 /* ... Floats are not allowed */
2517 if (FLOAT_TYPE_P (TREE_TYPE (field)))
2520 /* ... Aggregates that are not themselves valid for returning in
2521 a register are not allowed. */
2522 if (RETURN_IN_MEMORY (TREE_TYPE (field)))
2525 /* Now check the remaining fields, if any. Only bitfields are allowed,
2526 since they are not addressable. */
2527 for (field = TREE_CHAIN (field);
2529 field = TREE_CHAIN (field))
2531 if (TREE_CODE (field) != FIELD_DECL)
2534 if (!DECL_BIT_FIELD_TYPE (field))
2541 if (TREE_CODE (type) == UNION_TYPE)
2545 /* Unions can be returned in registers if every element is
2546 integral, or can be returned in an integer register. */
2547 for (field = TYPE_FIELDS (type);
2549 field = TREE_CHAIN (field))
2551 if (TREE_CODE (field) != FIELD_DECL)
2554 if (FLOAT_TYPE_P (TREE_TYPE (field)))
2557 if (RETURN_IN_MEMORY (TREE_TYPE (field)))
2563 #endif /* not ARM_WINCE */
2565 /* Return all other types in memory. */
2569 /* Indicate whether or not words of a double are in big-endian order. */
2572 arm_float_words_big_endian (void)
2574 if (TARGET_MAVERICK)
2577 /* For FPA, float words are always big-endian. For VFP, floats words
2578 follow the memory system mode. */
2586 return (TARGET_BIG_END ? 1 : 0);
2591 /* Initialize a variable CUM of type CUMULATIVE_ARGS
2592 for a call to a function whose data type is FNTYPE.
2593 For a library call, FNTYPE is NULL. */
2595 arm_init_cumulative_args (CUMULATIVE_ARGS *pcum, tree fntype,
2596 rtx libname ATTRIBUTE_UNUSED,
2597 tree fndecl ATTRIBUTE_UNUSED)
2599 /* On the ARM, the offset starts at 0. */
2600 pcum->nregs = ((fntype && aggregate_value_p (TREE_TYPE (fntype), fntype)) ? 1 : 0);
2601 pcum->iwmmxt_nregs = 0;
2602 pcum->can_split = true;
2604 pcum->call_cookie = CALL_NORMAL;
2606 if (TARGET_LONG_CALLS)
2607 pcum->call_cookie = CALL_LONG;
2609 /* Check for long call/short call attributes. The attributes
2610 override any command line option. */
2613 if (lookup_attribute ("short_call", TYPE_ATTRIBUTES (fntype)))
2614 pcum->call_cookie = CALL_SHORT;
2615 else if (lookup_attribute ("long_call", TYPE_ATTRIBUTES (fntype)))
2616 pcum->call_cookie = CALL_LONG;
2619 /* Varargs vectors are treated the same as long long.
2620 named_count avoids having to change the way arm handles 'named' */
2621 pcum->named_count = 0;
2624 if (TARGET_REALLY_IWMMXT && fntype)
2628 for (fn_arg = TYPE_ARG_TYPES (fntype);
2630 fn_arg = TREE_CHAIN (fn_arg))
2631 pcum->named_count += 1;
2633 if (! pcum->named_count)
2634 pcum->named_count = INT_MAX;
2639 /* Return true if mode/type need doubleword alignment. */
2641 arm_needs_doubleword_align (enum machine_mode mode, tree type)
2643 return (GET_MODE_ALIGNMENT (mode) > PARM_BOUNDARY
2644 || (type && TYPE_ALIGN (type) > PARM_BOUNDARY));
2648 /* Determine where to put an argument to a function.
2649 Value is zero to push the argument on the stack,
2650 or a hard register in which to store the argument.
2652 MODE is the argument's machine mode.
2653 TYPE is the data type of the argument (as a tree).
2654 This is null for libcalls where that information may
2656 CUM is a variable of type CUMULATIVE_ARGS which gives info about
2657 the preceding args and about the function being called.
2658 NAMED is nonzero if this argument is a named parameter
2659 (otherwise it is an extra parameter matching an ellipsis). */
2662 arm_function_arg (CUMULATIVE_ARGS *pcum, enum machine_mode mode,
2663 tree type, int named)
2667 /* Varargs vectors are treated the same as long long.
2668 named_count avoids having to change the way arm handles 'named' */
2669 if (TARGET_IWMMXT_ABI
2670 && arm_vector_mode_supported_p (mode)
2671 && pcum->named_count > pcum->nargs + 1)
2673 if (pcum->iwmmxt_nregs <= 9)
2674 return gen_rtx_REG (mode, pcum->iwmmxt_nregs + FIRST_IWMMXT_REGNUM);
2677 pcum->can_split = false;
2682 /* Put doubleword aligned quantities in even register pairs. */
2684 && ARM_DOUBLEWORD_ALIGN
2685 && arm_needs_doubleword_align (mode, type))
2688 if (mode == VOIDmode)
2689 /* Compute operand 2 of the call insn. */
2690 return GEN_INT (pcum->call_cookie);
2692 /* Only allow splitting an arg between regs and memory if all preceding
2693 args were allocated to regs. For args passed by reference we only count
2694 the reference pointer. */
2695 if (pcum->can_split)
2698 nregs = ARM_NUM_REGS2 (mode, type);
2700 if (!named || pcum->nregs + nregs > NUM_ARG_REGS)
2703 return gen_rtx_REG (mode, pcum->nregs);
2707 arm_arg_partial_bytes (CUMULATIVE_ARGS *pcum, enum machine_mode mode,
2708 tree type, bool named ATTRIBUTE_UNUSED)
2710 int nregs = pcum->nregs;
2712 if (arm_vector_mode_supported_p (mode))
2715 if (NUM_ARG_REGS > nregs
2716 && (NUM_ARG_REGS < nregs + ARM_NUM_REGS2 (mode, type))
2718 return (NUM_ARG_REGS - nregs) * UNITS_PER_WORD;
2723 /* Variable sized types are passed by reference. This is a GCC
2724 extension to the ARM ABI. */
2727 arm_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
2728 enum machine_mode mode ATTRIBUTE_UNUSED,
2729 tree type, bool named ATTRIBUTE_UNUSED)
2731 return type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST;
2734 /* Encode the current state of the #pragma [no_]long_calls. */
2737 OFF, /* No #pramgma [no_]long_calls is in effect. */
2738 LONG, /* #pragma long_calls is in effect. */
2739 SHORT /* #pragma no_long_calls is in effect. */
2742 static arm_pragma_enum arm_pragma_long_calls = OFF;
2745 arm_pr_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
2747 arm_pragma_long_calls = LONG;
2751 arm_pr_no_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
2753 arm_pragma_long_calls = SHORT;
2757 arm_pr_long_calls_off (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
2759 arm_pragma_long_calls = OFF;
2762 /* Table of machine attributes. */
2763 const struct attribute_spec arm_attribute_table[] =
2765 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2766 /* Function calls made to this symbol must be done indirectly, because
2767 it may lie outside of the 26 bit addressing range of a normal function
2769 { "long_call", 0, 0, false, true, true, NULL },
2770 /* Whereas these functions are always known to reside within the 26 bit
2771 addressing range. */
2772 { "short_call", 0, 0, false, true, true, NULL },
2773 /* Interrupt Service Routines have special prologue and epilogue requirements. */
2774 { "isr", 0, 1, false, false, false, arm_handle_isr_attribute },
2775 { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute },
2776 { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute },
2778 /* ARM/PE has three new attributes:
2780 dllexport - for exporting a function/variable that will live in a dll
2781 dllimport - for importing a function/variable from a dll
2783 Microsoft allows multiple declspecs in one __declspec, separating
2784 them with spaces. We do NOT support this. Instead, use __declspec
2787 { "dllimport", 0, 0, true, false, false, NULL },
2788 { "dllexport", 0, 0, true, false, false, NULL },
2789 { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute },
2790 #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
2791 { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
2792 { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
2793 { "notshared", 0, 0, false, true, false, arm_handle_notshared_attribute },
2795 { NULL, 0, 0, false, false, false, NULL }
2798 /* Handle an attribute requiring a FUNCTION_DECL;
2799 arguments as in struct attribute_spec.handler. */
2801 arm_handle_fndecl_attribute (tree *node, tree name, tree args ATTRIBUTE_UNUSED,
2802 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
2804 if (TREE_CODE (*node) != FUNCTION_DECL)
2806 warning (0, "%qs attribute only applies to functions",
2807 IDENTIFIER_POINTER (name));
2808 *no_add_attrs = true;
2814 /* Handle an "interrupt" or "isr" attribute;
2815 arguments as in struct attribute_spec.handler. */
2817 arm_handle_isr_attribute (tree *node, tree name, tree args, int flags,
2822 if (TREE_CODE (*node) != FUNCTION_DECL)
2824 warning (0, "%qs attribute only applies to functions",
2825 IDENTIFIER_POINTER (name));
2826 *no_add_attrs = true;
2828 /* FIXME: the argument if any is checked for type attributes;
2829 should it be checked for decl ones? */
2833 if (TREE_CODE (*node) == FUNCTION_TYPE
2834 || TREE_CODE (*node) == METHOD_TYPE)
2836 if (arm_isr_value (args) == ARM_FT_UNKNOWN)
2838 warning (0, "%qs attribute ignored", IDENTIFIER_POINTER (name));
2839 *no_add_attrs = true;
2842 else if (TREE_CODE (*node) == POINTER_TYPE
2843 && (TREE_CODE (TREE_TYPE (*node)) == FUNCTION_TYPE
2844 || TREE_CODE (TREE_TYPE (*node)) == METHOD_TYPE)
2845 && arm_isr_value (args) != ARM_FT_UNKNOWN)
2847 *node = build_variant_type_copy (*node);
2848 TREE_TYPE (*node) = build_type_attribute_variant
2850 tree_cons (name, args, TYPE_ATTRIBUTES (TREE_TYPE (*node))));
2851 *no_add_attrs = true;
2855 /* Possibly pass this attribute on from the type to a decl. */
2856 if (flags & ((int) ATTR_FLAG_DECL_NEXT
2857 | (int) ATTR_FLAG_FUNCTION_NEXT
2858 | (int) ATTR_FLAG_ARRAY_NEXT))
2860 *no_add_attrs = true;
2861 return tree_cons (name, args, NULL_TREE);
2865 warning (0, "%qs attribute ignored", IDENTIFIER_POINTER (name));
2873 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
2874 /* Handle the "notshared" attribute. This attribute is another way of
2875 requesting hidden visibility. ARM's compiler supports
2876 "__declspec(notshared)"; we support the same thing via an
2880 arm_handle_notshared_attribute (tree *node,
2881 tree name ATTRIBUTE_UNUSED,
2882 tree args ATTRIBUTE_UNUSED,
2883 int flags ATTRIBUTE_UNUSED,
2886 tree decl = TYPE_NAME (*node);
2890 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
2891 DECL_VISIBILITY_SPECIFIED (decl) = 1;
2892 *no_add_attrs = false;
2898 /* Return 0 if the attributes for two types are incompatible, 1 if they
2899 are compatible, and 2 if they are nearly compatible (which causes a
2900 warning to be generated). */
2902 arm_comp_type_attributes (tree type1, tree type2)
2906 /* Check for mismatch of non-default calling convention. */
2907 if (TREE_CODE (type1) != FUNCTION_TYPE)
2910 /* Check for mismatched call attributes. */
2911 l1 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type1)) != NULL;
2912 l2 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type2)) != NULL;
2913 s1 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type1)) != NULL;
2914 s2 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type2)) != NULL;
2916 /* Only bother to check if an attribute is defined. */
2917 if (l1 | l2 | s1 | s2)
2919 /* If one type has an attribute, the other must have the same attribute. */
2920 if ((l1 != l2) || (s1 != s2))
2923 /* Disallow mixed attributes. */
2924 if ((l1 & s2) || (l2 & s1))
2928 /* Check for mismatched ISR attribute. */
2929 l1 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type1)) != NULL;
2931 l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1)) != NULL;
2932 l2 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type2)) != NULL;
2934 l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2)) != NULL;
2941 /* Encode long_call or short_call attribute by prefixing
2942 symbol name in DECL with a special character FLAG. */
2944 arm_encode_call_attribute (tree decl, int flag)
2946 const char * str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2947 int len = strlen (str);
2950 /* Do not allow weak functions to be treated as short call. */
2951 if (DECL_WEAK (decl) && flag == SHORT_CALL_FLAG_CHAR)
2954 newstr = alloca (len + 2);
2956 strcpy (newstr + 1, str);
2958 newstr = (char *) ggc_alloc_string (newstr, len + 1);
2959 XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
2962 /* Assigns default attributes to newly defined type. This is used to
2963 set short_call/long_call attributes for function types of
2964 functions defined inside corresponding #pragma scopes. */
2966 arm_set_default_type_attributes (tree type)
2968 /* Add __attribute__ ((long_call)) to all functions, when
2969 inside #pragma long_calls or __attribute__ ((short_call)),
2970 when inside #pragma no_long_calls. */
2971 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
2973 tree type_attr_list, attr_name;
2974 type_attr_list = TYPE_ATTRIBUTES (type);
2976 if (arm_pragma_long_calls == LONG)
2977 attr_name = get_identifier ("long_call");
2978 else if (arm_pragma_long_calls == SHORT)
2979 attr_name = get_identifier ("short_call");
2983 type_attr_list = tree_cons (attr_name, NULL_TREE, type_attr_list);
2984 TYPE_ATTRIBUTES (type) = type_attr_list;
2988 /* Return 1 if the operand is a SYMBOL_REF for a function known to be
2989 defined within the current compilation unit. If this cannot be
2990 determined, then 0 is returned. */
2992 current_file_function_operand (rtx sym_ref)
2994 /* This is a bit of a fib. A function will have a short call flag
2995 applied to its name if it has the short call attribute, or it has
2996 already been defined within the current compilation unit. */
2997 if (ENCODED_SHORT_CALL_ATTR_P (XSTR (sym_ref, 0)))
3000 /* The current function is always defined within the current compilation
3001 unit. If it s a weak definition however, then this may not be the real
3002 definition of the function, and so we have to say no. */
3003 if (sym_ref == XEXP (DECL_RTL (current_function_decl), 0)
3004 && !DECL_WEAK (current_function_decl))
3007 /* We cannot make the determination - default to returning 0. */
3011 /* Return nonzero if a 32 bit "long_call" should be generated for
3012 this call. We generate a long_call if the function:
3014 a. has an __attribute__((long call))
3015 or b. is within the scope of a #pragma long_calls
3016 or c. the -mlong-calls command line switch has been specified
3018 1. -ffunction-sections is in effect
3019 or 2. the current function has __attribute__ ((section))
3020 or 3. the target function has __attribute__ ((section))
3022 However we do not generate a long call if the function:
3024 d. has an __attribute__ ((short_call))
3025 or e. is inside the scope of a #pragma no_long_calls
3026 or f. is defined within the current compilation unit.
3028 This function will be called by C fragments contained in the machine
3029 description file. SYM_REF and CALL_COOKIE correspond to the matched
3030 rtl operands. CALL_SYMBOL is used to distinguish between
3031 two different callers of the function. It is set to 1 in the
3032 "call_symbol" and "call_symbol_value" patterns and to 0 in the "call"
3033 and "call_value" patterns. This is because of the difference in the
3034 SYM_REFs passed by these patterns. */
3036 arm_is_longcall_p (rtx sym_ref, int call_cookie, int call_symbol)
3040 if (GET_CODE (sym_ref) != MEM)
3043 sym_ref = XEXP (sym_ref, 0);
3046 if (GET_CODE (sym_ref) != SYMBOL_REF)
3049 if (call_cookie & CALL_SHORT)
3052 if (TARGET_LONG_CALLS)
3054 if (flag_function_sections
3055 || DECL_SECTION_NAME (current_function_decl))
3056 /* c.3 is handled by the definition of the
3057 ARM_DECLARE_FUNCTION_SIZE macro. */
3061 if (current_file_function_operand (sym_ref))
3064 return (call_cookie & CALL_LONG)
3065 || ENCODED_LONG_CALL_ATTR_P (XSTR (sym_ref, 0))
3066 || TARGET_LONG_CALLS;
3069 /* Return nonzero if it is ok to make a tail-call to DECL. */
3071 arm_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
3073 int call_type = TARGET_LONG_CALLS ? CALL_LONG : CALL_NORMAL;
3075 if (cfun->machine->sibcall_blocked)
3078 /* Never tailcall something for which we have no decl, or if we
3079 are in Thumb mode. */
3080 if (decl == NULL || TARGET_THUMB)
3083 /* Get the calling method. */
3084 if (lookup_attribute ("short_call", TYPE_ATTRIBUTES (TREE_TYPE (decl))))
3085 call_type = CALL_SHORT;
3086 else if (lookup_attribute ("long_call", TYPE_ATTRIBUTES (TREE_TYPE (decl))))
3087 call_type = CALL_LONG;
3089 /* Cannot tail-call to long calls, since these are out of range of
3090 a branch instruction. However, if not compiling PIC, we know
3091 we can reach the symbol if it is in this compilation unit. */
3092 if (call_type == CALL_LONG && (flag_pic || !TREE_ASM_WRITTEN (decl)))
3095 /* If we are interworking and the function is not declared static
3096 then we can't tail-call it unless we know that it exists in this
3097 compilation unit (since it might be a Thumb routine). */
3098 if (TARGET_INTERWORK && TREE_PUBLIC (decl) && !TREE_ASM_WRITTEN (decl))
3101 /* Never tailcall from an ISR routine - it needs a special exit sequence. */
3102 if (IS_INTERRUPT (arm_current_func_type ()))
3105 /* Everything else is ok. */
3110 /* Addressing mode support functions. */
3112 /* Return nonzero if X is a legitimate immediate operand when compiling
3115 legitimate_pic_operand_p (rtx x)
3119 && (GET_CODE (x) == SYMBOL_REF
3120 || (GET_CODE (x) == CONST
3121 && GET_CODE (XEXP (x, 0)) == PLUS
3122 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)))
3129 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
3131 if (GET_CODE (orig) == SYMBOL_REF
3132 || GET_CODE (orig) == LABEL_REF)
3134 #ifndef AOF_ASSEMBLER
3135 rtx pic_ref, address;
3142 gcc_assert (!no_new_pseudos);
3143 reg = gen_reg_rtx (Pmode);
3148 #ifdef AOF_ASSEMBLER
3149 /* The AOF assembler can generate relocations for these directly, and
3150 understands that the PIC register has to be added into the offset. */
3151 insn = emit_insn (gen_pic_load_addr_based (reg, orig));
3154 address = gen_reg_rtx (Pmode);
3159 emit_insn (gen_pic_load_addr_arm (address, orig));
3161 emit_insn (gen_pic_load_addr_thumb (address, orig));
3163 if ((GET_CODE (orig) == LABEL_REF
3164 || (GET_CODE (orig) == SYMBOL_REF &&
3165 SYMBOL_REF_LOCAL_P (orig)))
3167 pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, address);
3170 pic_ref = gen_const_mem (Pmode,
3171 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3175 insn = emit_move_insn (reg, pic_ref);
3177 current_function_uses_pic_offset_table = 1;
3178 /* Put a REG_EQUAL note on this insn, so that it can be optimized
3180 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
3184 else if (GET_CODE (orig) == CONST)
3188 if (GET_CODE (XEXP (orig, 0)) == PLUS
3189 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
3194 gcc_assert (!no_new_pseudos);
3195 reg = gen_reg_rtx (Pmode);
3198 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
3200 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
3201 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
3202 base == reg ? 0 : reg);
3204 if (GET_CODE (offset) == CONST_INT)
3206 /* The base register doesn't really matter, we only want to
3207 test the index for the appropriate mode. */
3208 if (!arm_legitimate_index_p (mode, offset, SET, 0))
3210 gcc_assert (!no_new_pseudos);
3211 offset = force_reg (Pmode, offset);
3214 if (GET_CODE (offset) == CONST_INT)
3215 return plus_constant (base, INTVAL (offset));
3218 if (GET_MODE_SIZE (mode) > 4
3219 && (GET_MODE_CLASS (mode) == MODE_INT
3220 || TARGET_SOFT_FLOAT))
3222 emit_insn (gen_addsi3 (reg, base, offset));
3226 return gen_rtx_PLUS (Pmode, base, offset);
3233 /* Find a spare low register to use during the prolog of a function. */
3236 thumb_find_work_register (unsigned long pushed_regs_mask)
3240 /* Check the argument registers first as these are call-used. The
3241 register allocation order means that sometimes r3 might be used
3242 but earlier argument registers might not, so check them all. */
3243 for (reg = LAST_ARG_REGNUM; reg >= 0; reg --)
3244 if (!regs_ever_live[reg])
3247 /* Before going on to check the call-saved registers we can try a couple
3248 more ways of deducing that r3 is available. The first is when we are
3249 pushing anonymous arguments onto the stack and we have less than 4
3250 registers worth of fixed arguments(*). In this case r3 will be part of
3251 the variable argument list and so we can be sure that it will be
3252 pushed right at the start of the function. Hence it will be available
3253 for the rest of the prologue.
3254 (*): ie current_function_pretend_args_size is greater than 0. */
3255 if (cfun->machine->uses_anonymous_args
3256 && current_function_pretend_args_size > 0)
3257 return LAST_ARG_REGNUM;
3259 /* The other case is when we have fixed arguments but less than 4 registers
3260 worth. In this case r3 might be used in the body of the function, but
3261 it is not being used to convey an argument into the function. In theory
3262 we could just check current_function_args_size to see how many bytes are
3263 being passed in argument registers, but it seems that it is unreliable.
3264 Sometimes it will have the value 0 when in fact arguments are being
3265 passed. (See testcase execute/20021111-1.c for an example). So we also
3266 check the args_info.nregs field as well. The problem with this field is
3267 that it makes no allowances for arguments that are passed to the
3268 function but which are not used. Hence we could miss an opportunity
3269 when a function has an unused argument in r3. But it is better to be
3270 safe than to be sorry. */
3271 if (! cfun->machine->uses_anonymous_args
3272 && current_function_args_size >= 0
3273 && current_function_args_size <= (LAST_ARG_REGNUM * UNITS_PER_WORD)
3274 && cfun->args_info.nregs < 4)
3275 return LAST_ARG_REGNUM;
3277 /* Otherwise look for a call-saved register that is going to be pushed. */
3278 for (reg = LAST_LO_REGNUM; reg > LAST_ARG_REGNUM; reg --)
3279 if (pushed_regs_mask & (1 << reg))
3282 /* Something went wrong - thumb_compute_save_reg_mask()
3283 should have arranged for a suitable register to be pushed. */
3288 /* Generate code to load the PIC register. In thumb mode SCRATCH is a
3292 arm_load_pic_register (unsigned int scratch)
3294 #ifndef AOF_ASSEMBLER
3295 rtx l1, pic_tmp, pic_tmp2, pic_rtx;
3296 rtx global_offset_table;
3298 if (current_function_uses_pic_offset_table == 0 || TARGET_SINGLE_PIC_BASE)
3301 gcc_assert (flag_pic);
3303 l1 = gen_label_rtx ();
3305 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3306 /* On the ARM the PC register contains 'dot + 8' at the time of the
3307 addition, on the Thumb it is 'dot + 4'. */
3308 pic_tmp = plus_constant (gen_rtx_LABEL_REF (Pmode, l1), TARGET_ARM ? 8 : 4);
3310 pic_tmp2 = gen_rtx_CONST (VOIDmode,
3311 gen_rtx_PLUS (Pmode, global_offset_table, pc_rtx));
3313 pic_tmp2 = gen_rtx_CONST (VOIDmode, global_offset_table);
3315 pic_rtx = gen_rtx_CONST (Pmode, gen_rtx_MINUS (Pmode, pic_tmp2, pic_tmp));
3319 emit_insn (gen_pic_load_addr_arm (pic_offset_table_rtx, pic_rtx));
3320 emit_insn (gen_pic_add_dot_plus_eight (pic_offset_table_rtx, l1));
3324 if (REGNO (pic_offset_table_rtx) > LAST_LO_REGNUM)
3326 /* We will have pushed the pic register, so should always be
3327 able to find a work register. */
3328 pic_tmp = gen_rtx_REG (SImode, scratch);
3329 emit_insn (gen_pic_load_addr_thumb (pic_tmp, pic_rtx));
3330 emit_insn (gen_movsi (pic_offset_table_rtx, pic_tmp));
3333 emit_insn (gen_pic_load_addr_thumb (pic_offset_table_rtx, pic_rtx));
3334 emit_insn (gen_pic_add_dot_plus_four (pic_offset_table_rtx, l1));
3337 /* Need to emit this whether or not we obey regdecls,
3338 since setjmp/longjmp can cause life info to screw up. */
3339 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
3340 #endif /* AOF_ASSEMBLER */
3344 /* Return nonzero if X is valid as an ARM state addressing register. */
3346 arm_address_register_rtx_p (rtx x, int strict_p)
3350 if (GET_CODE (x) != REG)
3356 return ARM_REGNO_OK_FOR_BASE_P (regno);
3358 return (regno <= LAST_ARM_REGNUM
3359 || regno >= FIRST_PSEUDO_REGISTER
3360 || regno == FRAME_POINTER_REGNUM
3361 || regno == ARG_POINTER_REGNUM);
3364 /* Return nonzero if X is a valid ARM state address operand. */
3366 arm_legitimate_address_p (enum machine_mode mode, rtx x, RTX_CODE outer,
3370 enum rtx_code code = GET_CODE (x);
3372 if (arm_address_register_rtx_p (x, strict_p))
3375 use_ldrd = (TARGET_LDRD
3377 || (mode == DFmode && (TARGET_SOFT_FLOAT || TARGET_VFP))));
3379 if (code == POST_INC || code == PRE_DEC
3380 || ((code == PRE_INC || code == POST_DEC)
3381 && (use_ldrd || GET_MODE_SIZE (mode) <= 4)))
3382 return arm_address_register_rtx_p (XEXP (x, 0), strict_p);
3384 else if ((code == POST_MODIFY || code == PRE_MODIFY)
3385 && arm_address_register_rtx_p (XEXP (x, 0), strict_p)
3386 && GET_CODE (XEXP (x, 1)) == PLUS
3387 && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0)))
3389 rtx addend = XEXP (XEXP (x, 1), 1);
3391 /* Don't allow ldrd post increment by register because it's hard
3392 to fixup invalid register choices. */
3394 && GET_CODE (x) == POST_MODIFY
3395 && GET_CODE (addend) == REG)
3398 return ((use_ldrd || GET_MODE_SIZE (mode) <= 4)
3399 && arm_legitimate_index_p (mode, addend, outer, strict_p));
3402 /* After reload constants split into minipools will have addresses
3403 from a LABEL_REF. */
3404 else if (reload_completed
3405 && (code == LABEL_REF
3407 && GET_CODE (XEXP (x, 0)) == PLUS
3408 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3409 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)))
3412 else if (mode == TImode)
3415 else if (code == PLUS)
3417 rtx xop0 = XEXP (x, 0);
3418 rtx xop1 = XEXP (x, 1);
3420 return ((arm_address_register_rtx_p (xop0, strict_p)
3421 && arm_legitimate_index_p (mode, xop1, outer, strict_p))
3422 || (arm_address_register_rtx_p (xop1, strict_p)
3423 && arm_legitimate_index_p (mode, xop0, outer, strict_p)));
3427 /* Reload currently can't handle MINUS, so disable this for now */
3428 else if (GET_CODE (x) == MINUS)
3430 rtx xop0 = XEXP (x, 0);
3431 rtx xop1 = XEXP (x, 1);
3433 return (arm_address_register_rtx_p (xop0, strict_p)
3434 && arm_legitimate_index_p (mode, xop1, outer, strict_p));
3438 else if (GET_MODE_CLASS (mode) != MODE_FLOAT
3439 && code == SYMBOL_REF
3440 && CONSTANT_POOL_ADDRESS_P (x)
3442 && symbol_mentioned_p (get_pool_constant (x))))
3448 /* Return nonzero if INDEX is valid for an address index operand in
3451 arm_legitimate_index_p (enum machine_mode mode, rtx index, RTX_CODE outer,
3454 HOST_WIDE_INT range;
3455 enum rtx_code code = GET_CODE (index);
3457 /* Standard coprocessor addressing modes. */
3458 if (TARGET_HARD_FLOAT
3459 && (TARGET_FPA || TARGET_MAVERICK)
3460 && (GET_MODE_CLASS (mode) == MODE_FLOAT
3461 || (TARGET_MAVERICK && mode == DImode)))
3462 return (code == CONST_INT && INTVAL (index) < 1024
3463 && INTVAL (index) > -1024
3464 && (INTVAL (index) & 3) == 0);
3466 if (TARGET_REALLY_IWMMXT && VALID_IWMMXT_REG_MODE (mode))
3467 return (code == CONST_INT
3468 && INTVAL (index) < 1024
3469 && INTVAL (index) > -1024
3470 && (INTVAL (index) & 3) == 0);
3472 if (arm_address_register_rtx_p (index, strict_p)
3473 && (GET_MODE_SIZE (mode) <= 4))
3476 if (mode == DImode || mode == DFmode)
3478 if (code == CONST_INT)
3480 HOST_WIDE_INT val = INTVAL (index);
3483 return val > -256 && val < 256;
3485 return val > -4096 && val < 4092;
3488 return TARGET_LDRD && arm_address_register_rtx_p (index, strict_p);
3491 if (GET_MODE_SIZE (mode) <= 4
3494 || (mode == QImode && outer == SIGN_EXTEND))))
3498 rtx xiop0 = XEXP (index, 0);
3499 rtx xiop1 = XEXP (index, 1);
3501 return ((arm_address_register_rtx_p (xiop0, strict_p)
3502 && power_of_two_operand (xiop1, SImode))
3503 || (arm_address_register_rtx_p (xiop1, strict_p)
3504 && power_of_two_operand (xiop0, SImode)));
3506 else if (code == LSHIFTRT || code == ASHIFTRT
3507 || code == ASHIFT || code == ROTATERT)
3509 rtx op = XEXP (index, 1);
3511 return (arm_address_register_rtx_p (XEXP (index, 0), strict_p)
3512 && GET_CODE (op) == CONST_INT
3514 && INTVAL (op) <= 31);
3518 /* For ARM v4 we may be doing a sign-extend operation during the
3522 if (mode == HImode || (outer == SIGN_EXTEND && mode == QImode))
3528 range = (mode == HImode) ? 4095 : 4096;
3530 return (code == CONST_INT
3531 && INTVAL (index) < range
3532 && INTVAL (index) > -range);
3535 /* Return nonzero if X is valid as a Thumb state base register. */
3537 thumb_base_register_rtx_p (rtx x, enum machine_mode mode, int strict_p)
3541 if (GET_CODE (x) != REG)
3547 return THUMB_REGNO_MODE_OK_FOR_BASE_P (regno, mode);
3549 return (regno <= LAST_LO_REGNUM
3550 || regno > LAST_VIRTUAL_REGISTER
3551 || regno == FRAME_POINTER_REGNUM
3552 || (GET_MODE_SIZE (mode) >= 4
3553 && (regno == STACK_POINTER_REGNUM
3554 || regno >= FIRST_PSEUDO_REGISTER
3555 || x == hard_frame_pointer_rtx
3556 || x == arg_pointer_rtx)));
3559 /* Return nonzero if x is a legitimate index register. This is the case
3560 for any base register that can access a QImode object. */
3562 thumb_index_register_rtx_p (rtx x, int strict_p)
3564 return thumb_base_register_rtx_p (x, QImode, strict_p);
3567 /* Return nonzero if x is a legitimate Thumb-state address.
3569 The AP may be eliminated to either the SP or the FP, so we use the
3570 least common denominator, e.g. SImode, and offsets from 0 to 64.
3572 ??? Verify whether the above is the right approach.
3574 ??? Also, the FP may be eliminated to the SP, so perhaps that
3575 needs special handling also.
3577 ??? Look at how the mips16 port solves this problem. It probably uses
3578 better ways to solve some of these problems.
3580 Although it is not incorrect, we don't accept QImode and HImode
3581 addresses based on the frame pointer or arg pointer until the
3582 reload pass starts. This is so that eliminating such addresses
3583 into stack based ones won't produce impossible code. */
3585 thumb_legitimate_address_p (enum machine_mode mode, rtx x, int strict_p)
3587 /* ??? Not clear if this is right. Experiment. */
3588 if (GET_MODE_SIZE (mode) < 4
3589 && !(reload_in_progress || reload_completed)
3590 && (reg_mentioned_p (frame_pointer_rtx, x)
3591 || reg_mentioned_p (arg_pointer_rtx, x)
3592 || reg_mentioned_p (virtual_incoming_args_rtx, x)
3593 || reg_mentioned_p (virtual_outgoing_args_rtx, x)
3594 || reg_mentioned_p (virtual_stack_dynamic_rtx, x)
3595 || reg_mentioned_p (virtual_stack_vars_rtx, x)))
3598 /* Accept any base register. SP only in SImode or larger. */
3599 else if (thumb_base_register_rtx_p (x, mode, strict_p))
3602 /* This is PC relative data before arm_reorg runs. */
3603 else if (GET_MODE_SIZE (mode) >= 4 && CONSTANT_P (x)
3604 && GET_CODE (x) == SYMBOL_REF
3605 && CONSTANT_POOL_ADDRESS_P (x) && ! flag_pic)
3608 /* This is PC relative data after arm_reorg runs. */
3609 else if (GET_MODE_SIZE (mode) >= 4 && reload_completed
3610 && (GET_CODE (x) == LABEL_REF
3611 || (GET_CODE (x) == CONST
3612 && GET_CODE (XEXP (x, 0)) == PLUS
3613 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3614 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)))
3617 /* Post-inc indexing only supported for SImode and larger. */
3618 else if (GET_CODE (x) == POST_INC && GET_MODE_SIZE (mode) >= 4
3619 && thumb_index_register_rtx_p (XEXP (x, 0), strict_p))
3622 else if (GET_CODE (x) == PLUS)
3624 /* REG+REG address can be any two index registers. */
3625 /* We disallow FRAME+REG addressing since we know that FRAME
3626 will be replaced with STACK, and SP relative addressing only
3627 permits SP+OFFSET. */
3628 if (GET_MODE_SIZE (mode) <= 4
3629 && XEXP (x, 0) != frame_pointer_rtx
3630 && XEXP (x, 1) != frame_pointer_rtx
3631 && thumb_index_register_rtx_p (XEXP (x, 0), strict_p)
3632 && thumb_index_register_rtx_p (XEXP (x, 1), strict_p))
3635 /* REG+const has 5-7 bit offset for non-SP registers. */
3636 else if ((thumb_index_register_rtx_p (XEXP (x, 0), strict_p)
3637 || XEXP (x, 0) == arg_pointer_rtx)
3638 && GET_CODE (XEXP (x, 1)) == CONST_INT
3639 && thumb_legitimate_offset_p (mode, INTVAL (XEXP (x, 1))))
3642 /* REG+const has 10 bit offset for SP, but only SImode and
3643 larger is supported. */
3644 /* ??? Should probably check for DI/DFmode overflow here
3645 just like GO_IF_LEGITIMATE_OFFSET does. */
3646 else if (GET_CODE (XEXP (x, 0)) == REG
3647 && REGNO (XEXP (x, 0)) == STACK_POINTER_REGNUM
3648 && GET_MODE_SIZE (mode) >= 4
3649 && GET_CODE (XEXP (x, 1)) == CONST_INT
3650 && INTVAL (XEXP (x, 1)) >= 0
3651 && INTVAL (XEXP (x, 1)) + GET_MODE_SIZE (mode) <= 1024
3652 && (INTVAL (XEXP (x, 1)) & 3) == 0)
3655 else if (GET_CODE (XEXP (x, 0)) == REG
3656 && REGNO (XEXP (x, 0)) == FRAME_POINTER_REGNUM
3657 && GET_MODE_SIZE (mode) >= 4
3658 && GET_CODE (XEXP (x, 1)) == CONST_INT
3659 && (INTVAL (XEXP (x, 1)) & 3) == 0)
3663 else if (GET_MODE_CLASS (mode) != MODE_FLOAT
3664 && GET_MODE_SIZE (mode) == 4
3665 && GET_CODE (x) == SYMBOL_REF
3666 && CONSTANT_POOL_ADDRESS_P (x)
3668 && symbol_mentioned_p (get_pool_constant (x))))
3674 /* Return nonzero if VAL can be used as an offset in a Thumb-state address
3675 instruction of mode MODE. */
3677 thumb_legitimate_offset_p (enum machine_mode mode, HOST_WIDE_INT val)
3679 switch (GET_MODE_SIZE (mode))
3682 return val >= 0 && val < 32;
3685 return val >= 0 && val < 64 && (val & 1) == 0;
3689 && (val + GET_MODE_SIZE (mode)) <= 128
3694 /* Try machine-dependent ways of modifying an illegitimate address
3695 to be legitimate. If we find one, return the new, valid address. */
3697 arm_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode)
3699 if (GET_CODE (x) == PLUS)
3701 rtx xop0 = XEXP (x, 0);
3702 rtx xop1 = XEXP (x, 1);
3704 if (CONSTANT_P (xop0) && !symbol_mentioned_p (xop0))
3705 xop0 = force_reg (SImode, xop0);
3707 if (CONSTANT_P (xop1) && !symbol_mentioned_p (xop1))
3708 xop1 = force_reg (SImode, xop1);
3710 if (ARM_BASE_REGISTER_RTX_P (xop0)
3711 && GET_CODE (xop1) == CONST_INT)
3713 HOST_WIDE_INT n, low_n;
3717 /* VFP addressing modes actually allow greater offsets, but for
3718 now we just stick with the lowest common denominator. */
3720 || ((TARGET_SOFT_FLOAT || TARGET_VFP) && mode == DFmode))
3732 low_n = ((mode) == TImode ? 0
3733 : n >= 0 ? (n & 0xfff) : -((-n) & 0xfff));
3737 base_reg = gen_reg_rtx (SImode);
3738 val = force_operand (gen_rtx_PLUS (SImode, xop0,
3739 GEN_INT (n)), NULL_RTX);
3740 emit_move_insn (base_reg, val);
3741 x = (low_n == 0 ? base_reg
3742 : gen_rtx_PLUS (SImode, base_reg, GEN_INT (low_n)));
3744 else if (xop0 != XEXP (x, 0) || xop1 != XEXP (x, 1))
3745 x = gen_rtx_PLUS (SImode, xop0, xop1);
3748 /* XXX We don't allow MINUS any more -- see comment in
3749 arm_legitimate_address_p (). */
3750 else if (GET_CODE (x) == MINUS)
3752 rtx xop0 = XEXP (x, 0);
3753 rtx xop1 = XEXP (x, 1);
3755 if (CONSTANT_P (xop0))
3756 xop0 = force_reg (SImode, xop0);
3758 if (CONSTANT_P (xop1) && ! symbol_mentioned_p (xop1))
3759 xop1 = force_reg (SImode, xop1);
3761 if (xop0 != XEXP (x, 0) || xop1 != XEXP (x, 1))
3762 x = gen_rtx_MINUS (SImode, xop0, xop1);
3767 /* We need to find and carefully transform any SYMBOL and LABEL
3768 references; so go back to the original address expression. */
3769 rtx new_x = legitimize_pic_address (orig_x, mode, NULL_RTX);
3771 if (new_x != orig_x)
3779 /* Try machine-dependent ways of modifying an illegitimate Thumb address
3780 to be legitimate. If we find one, return the new, valid address. */
3782 thumb_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode)
3784 if (GET_CODE (x) == PLUS
3785 && GET_CODE (XEXP (x, 1)) == CONST_INT
3786 && (INTVAL (XEXP (x, 1)) >= 32 * GET_MODE_SIZE (mode)
3787 || INTVAL (XEXP (x, 1)) < 0))
3789 rtx xop0 = XEXP (x, 0);
3790 rtx xop1 = XEXP (x, 1);
3791 HOST_WIDE_INT offset = INTVAL (xop1);
3793 /* Try and fold the offset into a biasing of the base register and
3794 then offsetting that. Don't do this when optimizing for space
3795 since it can cause too many CSEs. */
3796 if (optimize_size && offset >= 0
3797 && offset < 256 + 31 * GET_MODE_SIZE (mode))
3799 HOST_WIDE_INT delta;
3802 delta = offset - (256 - GET_MODE_SIZE (mode));
3803 else if (offset < 32 * GET_MODE_SIZE (mode) + 8)
3804 delta = 31 * GET_MODE_SIZE (mode);
3806 delta = offset & (~31 * GET_MODE_SIZE (mode));
3808 xop0 = force_operand (plus_constant (xop0, offset - delta),
3810 x = plus_constant (xop0, delta);
3812 else if (offset < 0 && offset > -256)
3813 /* Small negative offsets are best done with a subtract before the
3814 dereference, forcing these into a register normally takes two
3816 x = force_operand (x, NULL_RTX);
3819 /* For the remaining cases, force the constant into a register. */
3820 xop1 = force_reg (SImode, xop1);
3821 x = gen_rtx_PLUS (SImode, xop0, xop1);
3824 else if (GET_CODE (x) == PLUS
3825 && s_register_operand (XEXP (x, 1), SImode)
3826 && !s_register_operand (XEXP (x, 0), SImode))
3828 rtx xop0 = force_operand (XEXP (x, 0), NULL_RTX);
3830 x = gen_rtx_PLUS (SImode, xop0, XEXP (x, 1));
3835 /* We need to find and carefully transform any SYMBOL and LABEL
3836 references; so go back to the original address expression. */
3837 rtx new_x = legitimize_pic_address (orig_x, mode, NULL_RTX);
3839 if (new_x != orig_x)
3848 #define REG_OR_SUBREG_REG(X) \
3849 (GET_CODE (X) == REG \
3850 || (GET_CODE (X) == SUBREG && GET_CODE (SUBREG_REG (X)) == REG))
3852 #define REG_OR_SUBREG_RTX(X) \
3853 (GET_CODE (X) == REG ? (X) : SUBREG_REG (X))
3855 #ifndef COSTS_N_INSNS
3856 #define COSTS_N_INSNS(N) ((N) * 4 - 2)
3859 thumb_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer)
3861 enum machine_mode mode = GET_MODE (x);
3874 return COSTS_N_INSNS (1);
3877 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
3880 unsigned HOST_WIDE_INT i = INTVAL (XEXP (x, 1));
3887 return COSTS_N_INSNS (2) + cycles;
3889 return COSTS_N_INSNS (1) + 16;
3892 return (COSTS_N_INSNS (1)
3893 + 4 * ((GET_CODE (SET_SRC (x)) == MEM)
3894 + GET_CODE (SET_DEST (x)) == MEM));
3899 if ((unsigned HOST_WIDE_INT) INTVAL (x) < 256)
3901 if (thumb_shiftable_const (INTVAL (x)))
3902 return COSTS_N_INSNS (2);
3903 return COSTS_N_INSNS (3);
3905 else if ((outer == PLUS || outer == COMPARE)
3906 && INTVAL (x) < 256 && INTVAL (x) > -256)
3908 else if (outer == AND
3909 && INTVAL (x) < 256 && INTVAL (x) >= -256)
3910 return COSTS_N_INSNS (1);
3911 else if (outer == ASHIFT || outer == ASHIFTRT
3912 || outer == LSHIFTRT)
3914 return COSTS_N_INSNS (2);
3920 return COSTS_N_INSNS (3);
3938 /* XXX another guess. */
3939 /* Memory costs quite a lot for the first word, but subsequent words
3940 load at the equivalent of a single insn each. */
3941 return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD)
3942 + ((GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
3947 if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC)
3952 /* XXX still guessing. */
3953 switch (GET_MODE (XEXP (x, 0)))
3956 return (1 + (mode == DImode ? 4 : 0)
3957 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
3960 return (4 + (mode == DImode ? 4 : 0)
3961 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
3964 return (1 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
3976 /* Worker routine for arm_rtx_costs. */
3978 arm_rtx_costs_1 (rtx x, enum rtx_code code, enum rtx_code outer)
3980 enum machine_mode mode = GET_MODE (x);
3981 enum rtx_code subcode;
3987 /* Memory costs quite a lot for the first word, but subsequent words
3988 load at the equivalent of a single insn each. */
3989 return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD)
3990 + (GET_CODE (x) == SYMBOL_REF
3991 && CONSTANT_POOL_ADDRESS_P (x) ? 4 : 0));
3997 return optimize_size ? COSTS_N_INSNS (2) : 100;
4000 if (mode == SImode && GET_CODE (XEXP (x, 1)) == REG)
4007 case ASHIFT: case LSHIFTRT: case ASHIFTRT:
4009 return (8 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : 8)
4010 + ((GET_CODE (XEXP (x, 0)) == REG
4011 || (GET_CODE (XEXP (x, 0)) == SUBREG
4012 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
4014 return (1 + ((GET_CODE (XEXP (x, 0)) == REG
4015 || (GET_CODE (XEXP (x, 0)) == SUBREG
4016 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
4018 + ((GET_CODE (XEXP (x, 1)) == REG