1 /* Output routines for GCC for ARM.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004 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 unsigned long thumb_compute_save_reg_mask (void);
75 static int const_ok_for_op (HOST_WIDE_INT, enum rtx_code);
76 static rtx emit_multi_reg_push (int);
77 static rtx emit_sfm (int, int);
79 static bool arm_assemble_integer (rtx, unsigned int, int);
81 static const char *fp_const_from_val (REAL_VALUE_TYPE *);
82 static arm_cc get_arm_condition_code (rtx);
83 static HOST_WIDE_INT int_log2 (HOST_WIDE_INT);
84 static rtx is_jump_table (rtx);
85 static const char *output_multi_immediate (rtx *, const char *, const char *,
87 static void print_multi_reg (FILE *, const char *, int, int);
88 static const char *shift_op (rtx, HOST_WIDE_INT *);
89 static struct machine_function *arm_init_machine_status (void);
90 static int number_of_first_bit_set (int);
91 static void replace_symbols_in_block (tree, rtx, rtx);
92 static void thumb_exit (FILE *, int);
93 static void thumb_pushpop (FILE *, int, int, int *, int);
94 static rtx is_jump_table (rtx);
95 static HOST_WIDE_INT get_jump_table_size (rtx);
96 static Mnode *move_minipool_fix_forward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
97 static Mnode *add_minipool_forward_ref (Mfix *);
98 static Mnode *move_minipool_fix_backward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
99 static Mnode *add_minipool_backward_ref (Mfix *);
100 static void assign_minipool_offsets (Mfix *);
101 static void arm_print_value (FILE *, rtx);
102 static void dump_minipool (rtx);
103 static int arm_barrier_cost (rtx);
104 static Mfix *create_fix_barrier (Mfix *, HOST_WIDE_INT);
105 static void push_minipool_barrier (rtx, HOST_WIDE_INT);
106 static void push_minipool_fix (rtx, HOST_WIDE_INT, rtx *, enum machine_mode,
108 static void arm_reorg (void);
109 static bool note_invalid_constants (rtx, HOST_WIDE_INT, int);
110 static int current_file_function_operand (rtx);
111 static unsigned long arm_compute_save_reg0_reg12_mask (void);
112 static unsigned long arm_compute_save_reg_mask (void);
113 static unsigned long arm_isr_value (tree);
114 static unsigned long arm_compute_func_type (void);
115 static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
116 static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *);
117 static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT);
118 static void arm_output_function_prologue (FILE *, HOST_WIDE_INT);
119 static void thumb_output_function_prologue (FILE *, HOST_WIDE_INT);
120 static int arm_comp_type_attributes (tree, tree);
121 static void arm_set_default_type_attributes (tree);
122 static int arm_adjust_cost (rtx, rtx, rtx, int);
123 static int count_insns_for_constant (HOST_WIDE_INT, int);
124 static int arm_get_strip_length (int);
125 static bool arm_function_ok_for_sibcall (tree, tree);
126 static void arm_internal_label (FILE *, const char *, unsigned long);
127 static void arm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
129 static int arm_rtx_costs_1 (rtx, enum rtx_code, enum rtx_code);
130 static bool arm_size_rtx_costs (rtx, int, int, int *);
131 static bool arm_slowmul_rtx_costs (rtx, int, int, int *);
132 static bool arm_fastmul_rtx_costs (rtx, int, int, int *);
133 static bool arm_xscale_rtx_costs (rtx, int, int, int *);
134 static bool arm_9e_rtx_costs (rtx, int, int, int *);
135 static int arm_address_cost (rtx);
136 static bool arm_memory_load_p (rtx);
137 static bool arm_cirrus_insn_p (rtx);
138 static void cirrus_reorg (rtx);
139 static void arm_init_builtins (void);
140 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
141 static void arm_init_iwmmxt_builtins (void);
142 static rtx safe_vector_operand (rtx, enum machine_mode);
143 static rtx arm_expand_binop_builtin (enum insn_code, tree, rtx);
144 static rtx arm_expand_unop_builtin (enum insn_code, tree, rtx, int);
145 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
146 static void emit_constant_insn (rtx cond, rtx pattern);
149 static void arm_encode_section_info (tree, rtx, int);
152 static void aof_globalize_label (FILE *, const char *);
153 static void aof_dump_imports (FILE *);
154 static void aof_dump_pic_table (FILE *);
155 static void aof_file_start (void);
156 static void aof_file_end (void);
158 static rtx arm_struct_value_rtx (tree, int);
159 static void arm_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
161 static bool arm_pass_by_reference (CUMULATIVE_ARGS *,
162 enum machine_mode, tree, bool);
163 static bool arm_promote_prototypes (tree);
164 static bool arm_default_short_enums (void);
165 static bool arm_align_anon_bitfield (void);
167 static tree arm_cxx_guard_type (void);
168 static bool arm_cxx_guard_mask_bit (void);
169 static tree arm_get_cookie_size (tree);
170 static bool arm_cookie_has_size (void);
171 static bool arm_cxx_cdtor_returns_this (void);
172 static bool arm_cxx_key_method_may_be_inline (void);
173 static bool arm_cxx_export_class_data (void);
174 static void arm_init_libfuncs (void);
175 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode);
177 /* Initialize the GCC target structure. */
178 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
179 #undef TARGET_MERGE_DECL_ATTRIBUTES
180 #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
183 #undef TARGET_ATTRIBUTE_TABLE
184 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
187 #undef TARGET_ASM_BYTE_OP
188 #define TARGET_ASM_BYTE_OP "\tDCB\t"
189 #undef TARGET_ASM_ALIGNED_HI_OP
190 #define TARGET_ASM_ALIGNED_HI_OP "\tDCW\t"
191 #undef TARGET_ASM_ALIGNED_SI_OP
192 #define TARGET_ASM_ALIGNED_SI_OP "\tDCD\t"
193 #undef TARGET_ASM_GLOBALIZE_LABEL
194 #define TARGET_ASM_GLOBALIZE_LABEL aof_globalize_label
195 #undef TARGET_ASM_FILE_START
196 #define TARGET_ASM_FILE_START aof_file_start
197 #undef TARGET_ASM_FILE_END
198 #define TARGET_ASM_FILE_END aof_file_end
200 #undef TARGET_ASM_ALIGNED_SI_OP
201 #define TARGET_ASM_ALIGNED_SI_OP NULL
202 #undef TARGET_ASM_INTEGER
203 #define TARGET_ASM_INTEGER arm_assemble_integer
206 #undef TARGET_ASM_FUNCTION_PROLOGUE
207 #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue
209 #undef TARGET_ASM_FUNCTION_EPILOGUE
210 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
212 #undef TARGET_COMP_TYPE_ATTRIBUTES
213 #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes
215 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
216 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes
218 #undef TARGET_SCHED_ADJUST_COST
219 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
221 #undef TARGET_ENCODE_SECTION_INFO
223 #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info
225 #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info
228 #undef TARGET_STRIP_NAME_ENCODING
229 #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding
231 #undef TARGET_ASM_INTERNAL_LABEL
232 #define TARGET_ASM_INTERNAL_LABEL arm_internal_label
234 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
235 #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall
237 #undef TARGET_ASM_OUTPUT_MI_THUNK
238 #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk
239 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
240 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
242 /* This will be overridden in arm_override_options. */
243 #undef TARGET_RTX_COSTS
244 #define TARGET_RTX_COSTS arm_slowmul_rtx_costs
245 #undef TARGET_ADDRESS_COST
246 #define TARGET_ADDRESS_COST arm_address_cost
248 #undef TARGET_SHIFT_TRUNCATION_MASK
249 #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask
250 #undef TARGET_VECTOR_MODE_SUPPORTED_P
251 #define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p
253 #undef TARGET_MACHINE_DEPENDENT_REORG
254 #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg
256 #undef TARGET_INIT_BUILTINS
257 #define TARGET_INIT_BUILTINS arm_init_builtins
258 #undef TARGET_EXPAND_BUILTIN
259 #define TARGET_EXPAND_BUILTIN arm_expand_builtin
261 #undef TARGET_INIT_LIBFUNCS
262 #define TARGET_INIT_LIBFUNCS arm_init_libfuncs
264 #undef TARGET_PROMOTE_FUNCTION_ARGS
265 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
266 #undef TARGET_PROMOTE_FUNCTION_RETURN
267 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
268 #undef TARGET_PROMOTE_PROTOTYPES
269 #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes
270 #undef TARGET_PASS_BY_REFERENCE
271 #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference
273 #undef TARGET_STRUCT_VALUE_RTX
274 #define TARGET_STRUCT_VALUE_RTX arm_struct_value_rtx
276 #undef TARGET_SETUP_INCOMING_VARARGS
277 #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs
279 #undef TARGET_DEFAULT_SHORT_ENUMS
280 #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
282 #undef TARGET_ALIGN_ANON_BITFIELD
283 #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield
285 #undef TARGET_CXX_GUARD_TYPE
286 #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type
288 #undef TARGET_CXX_GUARD_MASK_BIT
289 #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit
291 #undef TARGET_CXX_GET_COOKIE_SIZE
292 #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size
294 #undef TARGET_CXX_COOKIE_HAS_SIZE
295 #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size
297 #undef TARGET_CXX_CDTOR_RETURNS_THIS
298 #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this
300 #undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE
301 #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline
303 #undef TARGET_CXX_EXPORT_CLASS_DATA
304 #define TARGET_CXX_EXPORT_CLASS_DATA arm_cxx_export_class_data
306 struct gcc_target targetm = TARGET_INITIALIZER;
308 /* Obstack for minipool constant handling. */
309 static struct obstack minipool_obstack;
310 static char * minipool_startobj;
312 /* The maximum number of insns skipped which
313 will be conditionalised if possible. */
314 static int max_insns_skipped = 5;
316 extern FILE * asm_out_file;
318 /* True if we are currently building a constant table. */
319 int making_const_table;
321 /* Define the information needed to generate branch insns. This is
322 stored from the compare operation. */
323 rtx arm_compare_op0, arm_compare_op1;
325 /* The processor for which instructions should be scheduled. */
326 enum processor_type arm_tune = arm_none;
328 /* Which floating point model to use. */
329 enum arm_fp_model arm_fp_model;
331 /* Which floating point hardware is available. */
332 enum fputype arm_fpu_arch;
334 /* Which floating point hardware to schedule for. */
335 enum fputype arm_fpu_tune;
337 /* Whether to use floating point hardware. */
338 enum float_abi_type arm_float_abi;
340 /* Which ABI to use. */
341 enum arm_abi_type arm_abi;
343 /* Set by the -mfpu=... option. */
344 const char * target_fpu_name = NULL;
346 /* Set by the -mfpe=... option. */
347 const char * target_fpe_name = NULL;
349 /* Set by the -mfloat-abi=... option. */
350 const char * target_float_abi_name = NULL;
352 /* Set by the -mabi=... option. */
353 const char * target_abi_name = NULL;
355 /* Used to parse -mstructure_size_boundary command line option. */
356 const char * structure_size_string = NULL;
357 int arm_structure_size_boundary = DEFAULT_STRUCTURE_SIZE_BOUNDARY;
359 /* Bit values used to identify processor capabilities. */
360 #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */
361 #define FL_ARCH3M (1 << 1) /* Extended multiply */
362 #define FL_MODE26 (1 << 2) /* 26-bit mode support */
363 #define FL_MODE32 (1 << 3) /* 32-bit mode support */
364 #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */
365 #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */
366 #define FL_THUMB (1 << 6) /* Thumb aware */
367 #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */
368 #define FL_STRONG (1 << 8) /* StrongARM */
369 #define FL_ARCH5E (1 << 9) /* DSP extensions to v5 */
370 #define FL_XSCALE (1 << 10) /* XScale */
371 #define FL_CIRRUS (1 << 11) /* Cirrus/DSP. */
372 #define FL_ARCH6 (1 << 12) /* Architecture rel 6. Adds
373 media instructions. */
374 #define FL_VFPV2 (1 << 13) /* Vector Floating Point V2. */
376 #define FL_IWMMXT (1 << 29) /* XScale v2 or "Intel Wireless MMX technology". */
378 #define FL_FOR_ARCH2 0
379 #define FL_FOR_ARCH3 FL_MODE32
380 #define FL_FOR_ARCH3M (FL_FOR_ARCH3 | FL_ARCH3M)
381 #define FL_FOR_ARCH4 (FL_FOR_ARCH3M | FL_ARCH4)
382 #define FL_FOR_ARCH4T (FL_FOR_ARCH4 | FL_THUMB)
383 #define FL_FOR_ARCH5 (FL_FOR_ARCH4 | FL_ARCH5)
384 #define FL_FOR_ARCH5T (FL_FOR_ARCH5 | FL_THUMB)
385 #define FL_FOR_ARCH5E (FL_FOR_ARCH5 | FL_ARCH5E)
386 #define FL_FOR_ARCH5TE (FL_FOR_ARCH5E | FL_THUMB)
387 #define FL_FOR_ARCH5TEJ FL_FOR_ARCH5TE
388 #define FL_FOR_ARCH6 (FL_FOR_ARCH5TE | FL_ARCH6)
389 #define FL_FOR_ARCH6J FL_FOR_ARCH6
391 /* The bits in this mask specify which
392 instructions we are allowed to generate. */
393 static unsigned long insn_flags = 0;
395 /* The bits in this mask specify which instruction scheduling options should
397 static unsigned long tune_flags = 0;
399 /* The following are used in the arm.md file as equivalents to bits
400 in the above two flag variables. */
402 /* Nonzero if this chip supports the ARM Architecture 3M extensions. */
405 /* Nonzero if this chip supports the ARM Architecture 4 extensions. */
408 /* Nonzero if this chip supports the ARM Architecture 4t extensions. */
411 /* Nonzero if this chip supports the ARM Architecture 5 extensions. */
414 /* Nonzero if this chip supports the ARM Architecture 5E extensions. */
417 /* Nonzero if this chip supports the ARM Architecture 6 extensions. */
420 /* Nonzero if this chip can benefit from load scheduling. */
421 int arm_ld_sched = 0;
423 /* Nonzero if this chip is a StrongARM. */
424 int arm_is_strong = 0;
426 /* Nonzero if this chip is a Cirrus variant. */
427 int arm_arch_cirrus = 0;
429 /* Nonzero if this chip supports Intel Wireless MMX technology. */
430 int arm_arch_iwmmxt = 0;
432 /* Nonzero if this chip is an XScale. */
433 int arm_arch_xscale = 0;
435 /* Nonzero if tuning for XScale */
436 int arm_tune_xscale = 0;
438 /* Nonzero if this chip is an ARM6 or an ARM7. */
439 int arm_is_6_or_7 = 0;
441 /* Nonzero if generating Thumb instructions. */
444 /* Nonzero if we should define __THUMB_INTERWORK__ in the
446 XXX This is a bit of a hack, it's intended to help work around
447 problems in GLD which doesn't understand that armv5t code is
448 interworking clean. */
449 int arm_cpp_interwork = 0;
451 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, we
452 must report the mode of the memory reference from PRINT_OPERAND to
453 PRINT_OPERAND_ADDRESS. */
454 enum machine_mode output_memory_reference_mode;
456 /* The register number to be used for the PIC offset register. */
457 const char * arm_pic_register_string = NULL;
458 int arm_pic_register = INVALID_REGNUM;
460 /* Set to 1 when a return insn is output, this means that the epilogue
462 int return_used_this_function;
464 /* Set to 1 after arm_reorg has started. Reset to start at the start of
465 the next function. */
466 static int after_arm_reorg = 0;
468 /* The maximum number of insns to be used when loading a constant. */
469 static int arm_constant_limit = 3;
471 /* For an explanation of these variables, see final_prescan_insn below. */
473 enum arm_cond_code arm_current_cc;
475 int arm_target_label;
477 /* The condition codes of the ARM, and the inverse function. */
478 static const char * const arm_condition_codes[] =
480 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
481 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
484 #define streq(string1, string2) (strcmp (string1, string2) == 0)
486 /* Initialization code. */
490 const char *const name;
491 enum processor_type core;
493 const unsigned long flags;
494 bool (* rtx_costs) (rtx, int, int, int *);
497 /* Not all of these give usefully different compilation alternatives,
498 but there is no simple way of generalizing them. */
499 static const struct processors all_cores[] =
502 #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \
503 {NAME, arm_none, #ARCH, FLAGS | FL_FOR_ARCH##ARCH, arm_##COSTS##_rtx_costs},
504 #include "arm-cores.def"
506 {NULL, arm_none, NULL, 0, NULL}
509 static const struct processors all_architectures[] =
511 /* ARM Architectures */
512 /* We don't specify rtx_costs here as it will be figured out
515 {"armv2", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
516 {"armv2a", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
517 {"armv3", arm6, "3", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3, NULL},
518 {"armv3m", arm7m, "3M", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3M, NULL},
519 {"armv4", arm7tdmi, "4", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH4, NULL},
520 /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no
521 implementations that support it, so we will leave it out for now. */
522 {"armv4t", arm7tdmi, "4T", FL_CO_PROC | FL_FOR_ARCH4T, NULL},
523 {"armv5", arm10tdmi, "5", FL_CO_PROC | FL_FOR_ARCH5, NULL},
524 {"armv5t", arm10tdmi, "5T", FL_CO_PROC | FL_FOR_ARCH5T, NULL},
525 {"armv5e", arm1026ejs, "5E", FL_CO_PROC | FL_FOR_ARCH5E, NULL},
526 {"armv5te", arm1026ejs, "5TE", FL_CO_PROC | FL_FOR_ARCH5TE, NULL},
527 {"armv6", arm1136js, "6", FL_CO_PROC | FL_FOR_ARCH6, NULL},
528 {"armv6j", arm1136js, "6J", FL_CO_PROC | FL_FOR_ARCH6J, NULL},
529 {"ep9312", ep9312, "4T", FL_LDSCHED | FL_CIRRUS | FL_FOR_ARCH4, NULL},
530 {"iwmmxt", iwmmxt, "5TE", FL_LDSCHED | FL_STRONG | FL_FOR_ARCH5TE | FL_XSCALE | FL_IWMMXT , NULL},
531 {NULL, arm_none, NULL, 0 , NULL}
534 /* This is a magic structure. The 'string' field is magically filled in
535 with a pointer to the value specified by the user on the command line
536 assuming that the user has specified such a value. */
538 struct arm_cpu_select arm_select[] =
540 /* string name processors */
541 { NULL, "-mcpu=", all_cores },
542 { NULL, "-march=", all_architectures },
543 { NULL, "-mtune=", all_cores }
547 /* The name of the proprocessor macro to define for this architecture. */
549 char arm_arch_name[] = "__ARM_ARCH_0UNK__";
558 /* Available values for for -mfpu=. */
560 static const struct fpu_desc all_fpus[] =
562 {"fpa", FPUTYPE_FPA},
563 {"fpe2", FPUTYPE_FPA_EMU2},
564 {"fpe3", FPUTYPE_FPA_EMU2},
565 {"maverick", FPUTYPE_MAVERICK},
570 /* Floating point models used by the different hardware.
571 See fputype in arm.h. */
573 static const enum fputype fp_model_for_fpu[] =
575 /* No FP hardware. */
576 ARM_FP_MODEL_UNKNOWN, /* FPUTYPE_NONE */
577 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA */
578 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA_EMU2 */
579 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA_EMU3 */
580 ARM_FP_MODEL_MAVERICK, /* FPUTYPE_MAVERICK */
581 ARM_FP_MODEL_VFP /* FPUTYPE_VFP */
588 enum float_abi_type abi_type;
592 /* Available values for -mfloat-abi=. */
594 static const struct float_abi all_float_abis[] =
596 {"soft", ARM_FLOAT_ABI_SOFT},
597 {"softfp", ARM_FLOAT_ABI_SOFTFP},
598 {"hard", ARM_FLOAT_ABI_HARD}
605 enum arm_abi_type abi_type;
609 /* Available values for -mabi=. */
611 static const struct abi_name arm_all_abis[] =
613 {"apcs-gnu", ARM_ABI_APCS},
614 {"atpcs", ARM_ABI_ATPCS},
615 {"aapcs", ARM_ABI_AAPCS},
616 {"iwmmxt", ARM_ABI_IWMMXT}
619 /* Return the number of bits set in VALUE. */
621 bit_count (unsigned long value)
623 unsigned long count = 0;
628 value &= value - 1; /* Clear the least-significant set bit. */
634 /* Set up library functions unique to ARM. */
637 arm_init_libfuncs (void)
639 /* There are no special library functions unless we are using the
644 /* The functions below are described in Section 4 of the "Run-Time
645 ABI for the ARM architecture", Version 1.0. */
647 /* Double-precision floating-point arithmetic. Table 2. */
648 set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd");
649 set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv");
650 set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul");
651 set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg");
652 set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub");
654 /* Double-precision comparisons. Table 3. */
655 set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq");
656 set_optab_libfunc (ne_optab, DFmode, NULL);
657 set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt");
658 set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple");
659 set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge");
660 set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt");
661 set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun");
663 /* Single-precision floating-point arithmetic. Table 4. */
664 set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd");
665 set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv");
666 set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul");
667 set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg");
668 set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub");
670 /* Single-precision comparisons. Table 5. */
671 set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq");
672 set_optab_libfunc (ne_optab, SFmode, NULL);
673 set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt");
674 set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple");
675 set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge");
676 set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt");
677 set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun");
679 /* Floating-point to integer conversions. Table 6. */
680 set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz");
681 set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz");
682 set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz");
683 set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz");
684 set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz");
685 set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz");
686 set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz");
687 set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz");
689 /* Conversions between floating types. Table 7. */
690 set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f");
691 set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d");
693 /* Integer to floating-point conversions. Table 8. */
694 set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d");
695 set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d");
696 set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d");
697 set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d");
698 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f");
699 set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f");
700 set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f");
701 set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f");
703 /* Long long. Table 9. */
704 set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul");
705 set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod");
706 set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod");
707 set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl");
708 set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr");
709 set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr");
710 set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp");
711 set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp");
713 /* Integer (32/32->32) division. \S 4.3.1. */
714 set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod");
715 set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod");
717 /* The divmod functions are designed so that they can be used for
718 plain division, even though they return both the quotient and the
719 remainder. The quotient is returned in the usual location (i.e.,
720 r0 for SImode, {r0, r1} for DImode), just as would be expected
721 for an ordinary division routine. Because the AAPCS calling
722 conventions specify that all of { r0, r1, r2, r3 } are
723 callee-saved registers, there is no need to tell the compiler
724 explicitly that those registers are clobbered by these
726 set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod");
727 set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod");
728 set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idivmod");
729 set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidivmod");
732 /* Fix up any incompatible options that the user has specified.
733 This has now turned into a maze. */
735 arm_override_options (void)
739 /* Set up the flags based on the cpu/architecture selected by the user. */
740 for (i = ARRAY_SIZE (arm_select); i--;)
742 struct arm_cpu_select * ptr = arm_select + i;
744 if (ptr->string != NULL && ptr->string[0] != '\0')
746 const struct processors * sel;
748 for (sel = ptr->processors; sel->name != NULL; sel++)
749 if (streq (ptr->string, sel->name))
751 /* Set the architecture define. */
753 sprintf (arm_arch_name, "__ARM_ARCH_%s__", sel->arch);
755 /* Determine the processor core for which we should
756 tune code-generation. */
757 if (/* -mcpu= is a sensible default. */
759 /* If -march= is used, and -mcpu= has not been used,
760 assume that we should tune for a representative
761 CPU from that architecture. */
763 /* -mtune= overrides -mcpu= and -march=. */
765 arm_tune = (enum processor_type) (sel - ptr->processors);
769 /* If we have been given an architecture and a processor
770 make sure that they are compatible. We only generate
771 a warning though, and we prefer the CPU over the
773 if (insn_flags != 0 && (insn_flags ^ sel->flags))
774 warning ("switch -mcpu=%s conflicts with -march= switch",
777 insn_flags = sel->flags;
783 if (sel->name == NULL)
784 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
788 /* If the user did not specify a processor, choose one for them. */
791 const struct processors * sel;
793 enum processor_type cpu;
795 cpu = TARGET_CPU_DEFAULT;
798 #ifdef SUBTARGET_CPU_DEFAULT
799 /* Use the subtarget default CPU if none was specified by
801 cpu = SUBTARGET_CPU_DEFAULT;
803 /* Default to ARM6. */
807 sel = &all_cores[cpu];
809 insn_flags = sel->flags;
811 /* Now check to see if the user has specified some command line
812 switch that require certain abilities from the cpu. */
815 if (TARGET_INTERWORK || TARGET_THUMB)
817 sought |= (FL_THUMB | FL_MODE32);
819 /* There are no ARM processors that support both APCS-26 and
820 interworking. Therefore we force FL_MODE26 to be removed
821 from insn_flags here (if it was set), so that the search
822 below will always be able to find a compatible processor. */
823 insn_flags &= ~FL_MODE26;
826 if (sought != 0 && ((sought & insn_flags) != sought))
828 /* Try to locate a CPU type that supports all of the abilities
829 of the default CPU, plus the extra abilities requested by
831 for (sel = all_cores; sel->name != NULL; sel++)
832 if ((sel->flags & sought) == (sought | insn_flags))
835 if (sel->name == NULL)
837 unsigned current_bit_count = 0;
838 const struct processors * best_fit = NULL;
840 /* Ideally we would like to issue an error message here
841 saying that it was not possible to find a CPU compatible
842 with the default CPU, but which also supports the command
843 line options specified by the programmer, and so they
844 ought to use the -mcpu=<name> command line option to
845 override the default CPU type.
847 If we cannot find a cpu that has both the
848 characteristics of the default cpu and the given
849 command line options we scan the array again looking
851 for (sel = all_cores; sel->name != NULL; sel++)
852 if ((sel->flags & sought) == sought)
856 count = bit_count (sel->flags & insn_flags);
858 if (count >= current_bit_count)
861 current_bit_count = count;
865 if (best_fit == NULL)
871 insn_flags = sel->flags;
873 sprintf (arm_arch_name, "__ARM_ARCH_%s__", sel->arch);
874 if (arm_tune == arm_none)
875 arm_tune = (enum processor_type) (sel - all_cores);
878 /* The processor for which we should tune should now have been
880 if (arm_tune == arm_none)
883 tune_flags = all_cores[(int)arm_tune].flags;
885 targetm.rtx_costs = arm_size_rtx_costs;
887 targetm.rtx_costs = all_cores[(int)arm_tune].rtx_costs;
889 /* Make sure that the processor choice does not conflict with any of the
890 other command line choices. */
891 if (TARGET_INTERWORK && !(insn_flags & FL_THUMB))
893 warning ("target CPU does not support interworking" );
894 target_flags &= ~ARM_FLAG_INTERWORK;
897 if (TARGET_THUMB && !(insn_flags & FL_THUMB))
899 warning ("target CPU does not support THUMB instructions");
900 target_flags &= ~ARM_FLAG_THUMB;
903 if (TARGET_APCS_FRAME && TARGET_THUMB)
905 /* warning ("ignoring -mapcs-frame because -mthumb was used"); */
906 target_flags &= ~ARM_FLAG_APCS_FRAME;
909 /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done
910 from here where no function is being compiled currently. */
911 if ((target_flags & (THUMB_FLAG_LEAF_BACKTRACE | THUMB_FLAG_BACKTRACE))
913 warning ("enabling backtrace support is only meaningful when compiling for the Thumb");
915 if (TARGET_ARM && TARGET_CALLEE_INTERWORKING)
916 warning ("enabling callee interworking support is only meaningful when compiling for the Thumb");
918 if (TARGET_ARM && TARGET_CALLER_INTERWORKING)
919 warning ("enabling caller interworking support is only meaningful when compiling for the Thumb");
921 if (TARGET_APCS_STACK && !TARGET_APCS_FRAME)
923 warning ("-mapcs-stack-check incompatible with -mno-apcs-frame");
924 target_flags |= ARM_FLAG_APCS_FRAME;
927 if (TARGET_POKE_FUNCTION_NAME)
928 target_flags |= ARM_FLAG_APCS_FRAME;
930 if (TARGET_APCS_REENT && flag_pic)
931 error ("-fpic and -mapcs-reent are incompatible");
933 if (TARGET_APCS_REENT)
934 warning ("APCS reentrant code not supported. Ignored");
936 /* If this target is normally configured to use APCS frames, warn if they
937 are turned off and debugging is turned on. */
939 && write_symbols != NO_DEBUG
940 && !TARGET_APCS_FRAME
941 && (TARGET_DEFAULT & ARM_FLAG_APCS_FRAME))
942 warning ("-g with -mno-apcs-frame may not give sensible debugging");
944 /* If stack checking is disabled, we can use r10 as the PIC register,
945 which keeps r9 available. */
947 arm_pic_register = TARGET_APCS_STACK ? 9 : 10;
949 if (TARGET_APCS_FLOAT)
950 warning ("passing floating point arguments in fp regs not yet supported");
952 /* Initialize boolean versions of the flags, for use in the arm.md file. */
953 arm_arch3m = (insn_flags & FL_ARCH3M) != 0;
954 arm_arch4 = (insn_flags & FL_ARCH4) != 0;
955 arm_arch4t = arm_arch4 & ((insn_flags & FL_THUMB) != 0);
956 arm_arch5 = (insn_flags & FL_ARCH5) != 0;
957 arm_arch5e = (insn_flags & FL_ARCH5E) != 0;
958 arm_arch6 = (insn_flags & FL_ARCH6) != 0;
959 arm_arch_xscale = (insn_flags & FL_XSCALE) != 0;
960 arm_arch_cirrus = (insn_flags & FL_CIRRUS) != 0;
962 arm_ld_sched = (tune_flags & FL_LDSCHED) != 0;
963 arm_is_strong = (tune_flags & FL_STRONG) != 0;
964 thumb_code = (TARGET_ARM == 0);
965 arm_is_6_or_7 = (((tune_flags & (FL_MODE26 | FL_MODE32))
966 && !(tune_flags & FL_ARCH4))) != 0;
967 arm_tune_xscale = (tune_flags & FL_XSCALE) != 0;
968 arm_arch_iwmmxt = (insn_flags & FL_IWMMXT) != 0;
970 /* V5 code we generate is completely interworking capable, so we turn off
971 TARGET_INTERWORK here to avoid many tests later on. */
973 /* XXX However, we must pass the right pre-processor defines to CPP
974 or GLD can get confused. This is a hack. */
975 if (TARGET_INTERWORK)
976 arm_cpp_interwork = 1;
979 target_flags &= ~ARM_FLAG_INTERWORK;
983 for (i = 0; i < ARRAY_SIZE (arm_all_abis); i++)
985 if (streq (arm_all_abis[i].name, target_abi_name))
987 arm_abi = arm_all_abis[i].abi_type;
991 if (i == ARRAY_SIZE (arm_all_abis))
992 error ("invalid ABI option: -mabi=%s", target_abi_name);
995 arm_abi = ARM_DEFAULT_ABI;
997 if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN)
998 error ("iwmmxt requires an AAPCS compatible ABI for proper operation");
1000 if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT)
1001 error ("iwmmxt abi requires an iwmmxt capable cpu");
1003 arm_fp_model = ARM_FP_MODEL_UNKNOWN;
1004 if (target_fpu_name == NULL && target_fpe_name != NULL)
1006 if (streq (target_fpe_name, "2"))
1007 target_fpu_name = "fpe2";
1008 else if (streq (target_fpe_name, "3"))
1009 target_fpu_name = "fpe3";
1011 error ("invalid floating point emulation option: -mfpe=%s",
1014 if (target_fpu_name != NULL)
1016 /* The user specified a FPU. */
1017 for (i = 0; i < ARRAY_SIZE (all_fpus); i++)
1019 if (streq (all_fpus[i].name, target_fpu_name))
1021 arm_fpu_arch = all_fpus[i].fpu;
1022 arm_fpu_tune = arm_fpu_arch;
1023 arm_fp_model = fp_model_for_fpu[arm_fpu_arch];
1027 if (arm_fp_model == ARM_FP_MODEL_UNKNOWN)
1028 error ("invalid floating point option: -mfpu=%s", target_fpu_name);
1032 #ifdef FPUTYPE_DEFAULT
1033 /* Use the default if it is specified for this platform. */
1034 arm_fpu_arch = FPUTYPE_DEFAULT;
1035 arm_fpu_tune = FPUTYPE_DEFAULT;
1037 /* Pick one based on CPU type. */
1038 /* ??? Some targets assume FPA is the default.
1039 if ((insn_flags & FL_VFP) != 0)
1040 arm_fpu_arch = FPUTYPE_VFP;
1043 if (arm_arch_cirrus)
1044 arm_fpu_arch = FPUTYPE_MAVERICK;
1046 arm_fpu_arch = FPUTYPE_FPA_EMU2;
1048 if (tune_flags & FL_CO_PROC && arm_fpu_arch == FPUTYPE_FPA_EMU2)
1049 arm_fpu_tune = FPUTYPE_FPA;
1051 arm_fpu_tune = arm_fpu_arch;
1052 arm_fp_model = fp_model_for_fpu[arm_fpu_arch];
1053 if (arm_fp_model == ARM_FP_MODEL_UNKNOWN)
1057 if (target_float_abi_name != NULL)
1059 /* The user specified a FP ABI. */
1060 for (i = 0; i < ARRAY_SIZE (all_float_abis); i++)
1062 if (streq (all_float_abis[i].name, target_float_abi_name))
1064 arm_float_abi = all_float_abis[i].abi_type;
1068 if (i == ARRAY_SIZE (all_float_abis))
1069 error ("invalid floating point abi: -mfloat-abi=%s",
1070 target_float_abi_name);
1074 /* Use soft-float target flag. */
1075 if (target_flags & ARM_FLAG_SOFT_FLOAT)
1076 arm_float_abi = ARM_FLOAT_ABI_SOFT;
1078 arm_float_abi = ARM_FLOAT_ABI_HARD;
1081 if (arm_float_abi == ARM_FLOAT_ABI_HARD && TARGET_VFP)
1082 sorry ("-mfloat-abi=hard and VFP");
1084 /* If soft-float is specified then don't use FPU. */
1085 if (TARGET_SOFT_FLOAT)
1086 arm_fpu_arch = FPUTYPE_NONE;
1088 /* For arm2/3 there is no need to do any scheduling if there is only
1089 a floating point emulator, or we are doing software floating-point. */
1090 if ((TARGET_SOFT_FLOAT
1091 || arm_fpu_tune == FPUTYPE_FPA_EMU2
1092 || arm_fpu_tune == FPUTYPE_FPA_EMU3)
1093 && (tune_flags & FL_MODE32) == 0)
1094 flag_schedule_insns = flag_schedule_insns_after_reload = 0;
1096 /* Override the default structure alignment for AAPCS ABI. */
1097 if (arm_abi == ARM_ABI_AAPCS)
1098 arm_structure_size_boundary = 8;
1100 if (structure_size_string != NULL)
1102 int size = strtol (structure_size_string, NULL, 0);
1104 if (size == 8 || size == 32
1105 || (ARM_DOUBLEWORD_ALIGN && size == 64))
1106 arm_structure_size_boundary = size;
1108 warning ("structure size boundary can only be set to %s",
1109 ARM_DOUBLEWORD_ALIGN ? "8, 32 or 64": "8 or 32");
1112 if (arm_pic_register_string != NULL)
1114 int pic_register = decode_reg_name (arm_pic_register_string);
1117 warning ("-mpic-register= is useless without -fpic");
1119 /* Prevent the user from choosing an obviously stupid PIC register. */
1120 else if (pic_register < 0 || call_used_regs[pic_register]
1121 || pic_register == HARD_FRAME_POINTER_REGNUM
1122 || pic_register == STACK_POINTER_REGNUM
1123 || pic_register >= PC_REGNUM)
1124 error ("unable to use '%s' for PIC register", arm_pic_register_string);
1126 arm_pic_register = pic_register;
1129 if (TARGET_THUMB && flag_schedule_insns)
1131 /* Don't warn since it's on by default in -O2. */
1132 flag_schedule_insns = 0;
1137 /* There's some dispute as to whether this should be 1 or 2. However,
1138 experiments seem to show that in pathological cases a setting of
1139 1 degrades less severely than a setting of 2. This could change if
1140 other parts of the compiler change their behavior. */
1141 arm_constant_limit = 1;
1143 /* If optimizing for size, bump the number of instructions that we
1144 are prepared to conditionally execute (even on a StrongARM). */
1145 max_insns_skipped = 6;
1149 /* For processors with load scheduling, it never costs more than
1150 2 cycles to load a constant, and the load scheduler may well
1151 reduce that to 1. */
1152 if (tune_flags & FL_LDSCHED)
1153 arm_constant_limit = 1;
1155 /* On XScale the longer latency of a load makes it more difficult
1156 to achieve a good schedule, so it's faster to synthesize
1157 constants that can be done in two insns. */
1158 if (arm_tune_xscale)
1159 arm_constant_limit = 2;
1161 /* StrongARM has early execution of branches, so a sequence
1162 that is worth skipping is shorter. */
1164 max_insns_skipped = 3;
1167 /* Register global variables with the garbage collector. */
1168 arm_add_gc_roots ();
1172 arm_add_gc_roots (void)
1174 gcc_obstack_init(&minipool_obstack);
1175 minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0);
1178 /* A table of known ARM exception types.
1179 For use with the interrupt function attribute. */
1183 const char *const arg;
1184 const unsigned long return_value;
1188 static const isr_attribute_arg isr_attribute_args [] =
1190 { "IRQ", ARM_FT_ISR },
1191 { "irq", ARM_FT_ISR },
1192 { "FIQ", ARM_FT_FIQ },
1193 { "fiq", ARM_FT_FIQ },
1194 { "ABORT", ARM_FT_ISR },
1195 { "abort", ARM_FT_ISR },
1196 { "ABORT", ARM_FT_ISR },
1197 { "abort", ARM_FT_ISR },
1198 { "UNDEF", ARM_FT_EXCEPTION },
1199 { "undef", ARM_FT_EXCEPTION },
1200 { "SWI", ARM_FT_EXCEPTION },
1201 { "swi", ARM_FT_EXCEPTION },
1202 { NULL, ARM_FT_NORMAL }
1205 /* Returns the (interrupt) function type of the current
1206 function, or ARM_FT_UNKNOWN if the type cannot be determined. */
1208 static unsigned long
1209 arm_isr_value (tree argument)
1211 const isr_attribute_arg * ptr;
1214 /* No argument - default to IRQ. */
1215 if (argument == NULL_TREE)
1218 /* Get the value of the argument. */
1219 if (TREE_VALUE (argument) == NULL_TREE
1220 || TREE_CODE (TREE_VALUE (argument)) != STRING_CST)
1221 return ARM_FT_UNKNOWN;
1223 arg = TREE_STRING_POINTER (TREE_VALUE (argument));
1225 /* Check it against the list of known arguments. */
1226 for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)
1227 if (streq (arg, ptr->arg))
1228 return ptr->return_value;
1230 /* An unrecognized interrupt type. */
1231 return ARM_FT_UNKNOWN;
1234 /* Computes the type of the current function. */
1236 static unsigned long
1237 arm_compute_func_type (void)
1239 unsigned long type = ARM_FT_UNKNOWN;
1243 if (TREE_CODE (current_function_decl) != FUNCTION_DECL)
1246 /* Decide if the current function is volatile. Such functions
1247 never return, and many memory cycles can be saved by not storing
1248 register values that will never be needed again. This optimization
1249 was added to speed up context switching in a kernel application. */
1251 && TREE_NOTHROW (current_function_decl)
1252 && TREE_THIS_VOLATILE (current_function_decl))
1253 type |= ARM_FT_VOLATILE;
1255 if (cfun->static_chain_decl != NULL)
1256 type |= ARM_FT_NESTED;
1258 attr = DECL_ATTRIBUTES (current_function_decl);
1260 a = lookup_attribute ("naked", attr);
1262 type |= ARM_FT_NAKED;
1264 a = lookup_attribute ("isr", attr);
1266 a = lookup_attribute ("interrupt", attr);
1269 type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL;
1271 type |= arm_isr_value (TREE_VALUE (a));
1276 /* Returns the type of the current function. */
1279 arm_current_func_type (void)
1281 if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN)
1282 cfun->machine->func_type = arm_compute_func_type ();
1284 return cfun->machine->func_type;
1287 /* Return 1 if it is possible to return using a single instruction.
1288 If SIBLING is non-null, this is a test for a return before a sibling
1289 call. SIBLING is the call insn, so we can examine its register usage. */
1292 use_return_insn (int iscond, rtx sibling)
1295 unsigned int func_type;
1296 unsigned long saved_int_regs;
1297 unsigned HOST_WIDE_INT stack_adjust;
1298 arm_stack_offsets *offsets;
1300 /* Never use a return instruction before reload has run. */
1301 if (!reload_completed)
1304 func_type = arm_current_func_type ();
1306 /* Naked functions and volatile functions need special
1308 if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED))
1311 /* So do interrupt functions that use the frame pointer. */
1312 if (IS_INTERRUPT (func_type) && frame_pointer_needed)
1315 offsets = arm_get_frame_offsets ();
1316 stack_adjust = offsets->outgoing_args - offsets->saved_regs;
1318 /* As do variadic functions. */
1319 if (current_function_pretend_args_size
1320 || cfun->machine->uses_anonymous_args
1321 /* Or if the function calls __builtin_eh_return () */
1322 || current_function_calls_eh_return
1323 /* Or if the function calls alloca */
1324 || current_function_calls_alloca
1325 /* Or if there is a stack adjustment. However, if the stack pointer
1326 is saved on the stack, we can use a pre-incrementing stack load. */
1327 || !(stack_adjust == 0 || (frame_pointer_needed && stack_adjust == 4)))
1330 saved_int_regs = arm_compute_save_reg_mask ();
1332 /* Unfortunately, the insn
1334 ldmib sp, {..., sp, ...}
1336 triggers a bug on most SA-110 based devices, such that the stack
1337 pointer won't be correctly restored if the instruction takes a
1338 page fault. We work around this problem by popping r3 along with
1339 the other registers, since that is never slower than executing
1340 another instruction.
1342 We test for !arm_arch5 here, because code for any architecture
1343 less than this could potentially be run on one of the buggy
1345 if (stack_adjust == 4 && !arm_arch5)
1347 /* Validate that r3 is a call-clobbered register (always true in
1348 the default abi) ... */
1349 if (!call_used_regs[3])
1352 /* ... that it isn't being used for a return value (always true
1353 until we implement return-in-regs), or for a tail-call
1357 if (GET_CODE (sibling) != CALL_INSN)
1360 if (find_regno_fusage (sibling, USE, 3))
1364 /* ... and that there are no call-saved registers in r0-r2
1365 (always true in the default ABI). */
1366 if (saved_int_regs & 0x7)
1370 /* Can't be done if interworking with Thumb, and any registers have been
1372 if (TARGET_INTERWORK && saved_int_regs != 0)
1375 /* On StrongARM, conditional returns are expensive if they aren't
1376 taken and multiple registers have been stacked. */
1377 if (iscond && arm_is_strong)
1379 /* Conditional return when just the LR is stored is a simple
1380 conditional-load instruction, that's not expensive. */
1381 if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM))
1384 if (flag_pic && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
1388 /* If there are saved registers but the LR isn't saved, then we need
1389 two instructions for the return. */
1390 if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM)))
1393 /* Can't be done if any of the FPA regs are pushed,
1394 since this also requires an insn. */
1395 if (TARGET_HARD_FLOAT && TARGET_FPA)
1396 for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++)
1397 if (regs_ever_live[regno] && !call_used_regs[regno])
1400 /* Likewise VFP regs. */
1401 if (TARGET_HARD_FLOAT && TARGET_VFP)
1402 for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++)
1403 if (regs_ever_live[regno] && !call_used_regs[regno])
1406 if (TARGET_REALLY_IWMMXT)
1407 for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++)
1408 if (regs_ever_live[regno] && ! call_used_regs [regno])
1414 /* Return TRUE if int I is a valid immediate ARM constant. */
1417 const_ok_for_arm (HOST_WIDE_INT i)
1419 unsigned HOST_WIDE_INT mask = ~(unsigned HOST_WIDE_INT)0xFF;
1421 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
1422 be all zero, or all one. */
1423 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
1424 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
1425 != ((~(unsigned HOST_WIDE_INT) 0)
1426 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
1429 /* Fast return for 0 and powers of 2 */
1430 if ((i & (i - 1)) == 0)
1435 if ((i & mask & (unsigned HOST_WIDE_INT) 0xffffffff) == 0)
1438 (mask << 2) | ((mask & (unsigned HOST_WIDE_INT) 0xffffffff)
1439 >> (32 - 2)) | ~(unsigned HOST_WIDE_INT) 0xffffffff;
1441 while (mask != ~(unsigned HOST_WIDE_INT) 0xFF);
1446 /* Return true if I is a valid constant for the operation CODE. */
1448 const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code)
1450 if (const_ok_for_arm (i))
1456 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
1458 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
1464 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
1471 /* Emit a sequence of insns to handle a large constant.
1472 CODE is the code of the operation required, it can be any of SET, PLUS,
1473 IOR, AND, XOR, MINUS;
1474 MODE is the mode in which the operation is being performed;
1475 VAL is the integer to operate on;
1476 SOURCE is the other operand (a register, or a null-pointer for SET);
1477 SUBTARGETS means it is safe to create scratch registers if that will
1478 either produce a simpler sequence, or we will want to cse the values.
1479 Return value is the number of insns emitted. */
1482 arm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn,
1483 HOST_WIDE_INT val, rtx target, rtx source, int subtargets)
1487 if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC)
1488 cond = COND_EXEC_TEST (PATTERN (insn));
1492 if (subtargets || code == SET
1493 || (GET_CODE (target) == REG && GET_CODE (source) == REG
1494 && REGNO (target) != REGNO (source)))
1496 /* After arm_reorg has been called, we can't fix up expensive
1497 constants by pushing them into memory so we must synthesize
1498 them in-line, regardless of the cost. This is only likely to
1499 be more costly on chips that have load delay slots and we are
1500 compiling without running the scheduler (so no splitting
1501 occurred before the final instruction emission).
1503 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
1505 if (!after_arm_reorg
1507 && (arm_gen_constant (code, mode, NULL_RTX, val, target, source,
1509 > arm_constant_limit + (code != SET)))
1513 /* Currently SET is the only monadic value for CODE, all
1514 the rest are diadic. */
1515 emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (val)));
1520 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
1522 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (val)));
1523 /* For MINUS, the value is subtracted from, since we never
1524 have subtraction of a constant. */
1526 emit_insn (gen_rtx_SET (VOIDmode, target,
1527 gen_rtx_MINUS (mode, temp, source)));
1529 emit_insn (gen_rtx_SET (VOIDmode, target,
1530 gen_rtx_fmt_ee (code, mode, source, temp)));
1536 return arm_gen_constant (code, mode, cond, val, target, source, subtargets,
1541 count_insns_for_constant (HOST_WIDE_INT remainder, int i)
1543 HOST_WIDE_INT temp1;
1551 if (remainder & (3 << (i - 2)))
1556 temp1 = remainder & ((0x0ff << end)
1557 | ((i < end) ? (0xff >> (32 - end)) : 0));
1558 remainder &= ~temp1;
1563 } while (remainder);
1567 /* Emit an instruction with the indicated PATTERN. If COND is
1568 non-NULL, conditionalize the execution of the instruction on COND
1572 emit_constant_insn (rtx cond, rtx pattern)
1575 pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern);
1576 emit_insn (pattern);
1579 /* As above, but extra parameter GENERATE which, if clear, suppresses
1583 arm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond,
1584 HOST_WIDE_INT val, rtx target, rtx source, int subtargets,
1589 int can_negate_initial = 0;
1592 int num_bits_set = 0;
1593 int set_sign_bit_copies = 0;
1594 int clear_sign_bit_copies = 0;
1595 int clear_zero_bit_copies = 0;
1596 int set_zero_bit_copies = 0;
1598 unsigned HOST_WIDE_INT temp1, temp2;
1599 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
1601 /* Find out which operations are safe for a given CODE. Also do a quick
1602 check for degenerate cases; these can occur when DImode operations
1614 can_negate_initial = 1;
1618 if (remainder == 0xffffffff)
1621 emit_constant_insn (cond,
1622 gen_rtx_SET (VOIDmode, target,
1623 GEN_INT (ARM_SIGN_EXTEND (val))));
1628 if (reload_completed && rtx_equal_p (target, source))
1631 emit_constant_insn (cond,
1632 gen_rtx_SET (VOIDmode, target, source));
1641 emit_constant_insn (cond,
1642 gen_rtx_SET (VOIDmode, target, const0_rtx));
1645 if (remainder == 0xffffffff)
1647 if (reload_completed && rtx_equal_p (target, source))
1650 emit_constant_insn (cond,
1651 gen_rtx_SET (VOIDmode, target, source));
1660 if (reload_completed && rtx_equal_p (target, source))
1663 emit_constant_insn (cond,
1664 gen_rtx_SET (VOIDmode, target, source));
1667 if (remainder == 0xffffffff)
1670 emit_constant_insn (cond,
1671 gen_rtx_SET (VOIDmode, target,
1672 gen_rtx_NOT (mode, source)));
1676 /* We don't know how to handle this yet below. */
1680 /* We treat MINUS as (val - source), since (source - val) is always
1681 passed as (source + (-val)). */
1685 emit_constant_insn (cond,
1686 gen_rtx_SET (VOIDmode, target,
1687 gen_rtx_NEG (mode, source)));
1690 if (const_ok_for_arm (val))
1693 emit_constant_insn (cond,
1694 gen_rtx_SET (VOIDmode, target,
1695 gen_rtx_MINUS (mode, GEN_INT (val),
1707 /* If we can do it in one insn get out quickly. */
1708 if (const_ok_for_arm (val)
1709 || (can_negate_initial && const_ok_for_arm (-val))
1710 || (can_invert && const_ok_for_arm (~val)))
1713 emit_constant_insn (cond,
1714 gen_rtx_SET (VOIDmode, target,
1716 ? gen_rtx_fmt_ee (code, mode, source,
1722 /* Calculate a few attributes that may be useful for specific
1724 for (i = 31; i >= 0; i--)
1726 if ((remainder & (1 << i)) == 0)
1727 clear_sign_bit_copies++;
1732 for (i = 31; i >= 0; i--)
1734 if ((remainder & (1 << i)) != 0)
1735 set_sign_bit_copies++;
1740 for (i = 0; i <= 31; i++)
1742 if ((remainder & (1 << i)) == 0)
1743 clear_zero_bit_copies++;
1748 for (i = 0; i <= 31; i++)
1750 if ((remainder & (1 << i)) != 0)
1751 set_zero_bit_copies++;
1759 /* See if we can do this by sign_extending a constant that is known
1760 to be negative. This is a good, way of doing it, since the shift
1761 may well merge into a subsequent insn. */
1762 if (set_sign_bit_copies > 1)
1764 if (const_ok_for_arm
1765 (temp1 = ARM_SIGN_EXTEND (remainder
1766 << (set_sign_bit_copies - 1))))
1770 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1771 emit_constant_insn (cond,
1772 gen_rtx_SET (VOIDmode, new_src,
1774 emit_constant_insn (cond,
1775 gen_ashrsi3 (target, new_src,
1776 GEN_INT (set_sign_bit_copies - 1)));
1780 /* For an inverted constant, we will need to set the low bits,
1781 these will be shifted out of harm's way. */
1782 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
1783 if (const_ok_for_arm (~temp1))
1787 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1788 emit_constant_insn (cond,
1789 gen_rtx_SET (VOIDmode, new_src,
1791 emit_constant_insn (cond,
1792 gen_ashrsi3 (target, new_src,
1793 GEN_INT (set_sign_bit_copies - 1)));
1799 /* See if we can generate this by setting the bottom (or the top)
1800 16 bits, and then shifting these into the other half of the
1801 word. We only look for the simplest cases, to do more would cost
1802 too much. Be careful, however, not to generate this when the
1803 alternative would take fewer insns. */
1804 if (val & 0xffff0000)
1806 temp1 = remainder & 0xffff0000;
1807 temp2 = remainder & 0x0000ffff;
1809 /* Overlaps outside this range are best done using other methods. */
1810 for (i = 9; i < 24; i++)
1812 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
1813 && !const_ok_for_arm (temp2))
1815 rtx new_src = (subtargets
1816 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
1818 insns = arm_gen_constant (code, mode, cond, temp2, new_src,
1819 source, subtargets, generate);
1827 gen_rtx_ASHIFT (mode, source,
1834 /* Don't duplicate cases already considered. */
1835 for (i = 17; i < 24; i++)
1837 if (((temp1 | (temp1 >> i)) == remainder)
1838 && !const_ok_for_arm (temp1))
1840 rtx new_src = (subtargets
1841 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
1843 insns = arm_gen_constant (code, mode, cond, temp1, new_src,
1844 source, subtargets, generate);
1849 gen_rtx_SET (VOIDmode, target,
1852 gen_rtx_LSHIFTRT (mode, source,
1863 /* If we have IOR or XOR, and the constant can be loaded in a
1864 single instruction, and we can find a temporary to put it in,
1865 then this can be done in two instructions instead of 3-4. */
1867 /* TARGET can't be NULL if SUBTARGETS is 0 */
1868 || (reload_completed && !reg_mentioned_p (target, source)))
1870 if (const_ok_for_arm (ARM_SIGN_EXTEND (~val)))
1874 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1876 emit_constant_insn (cond,
1877 gen_rtx_SET (VOIDmode, sub,
1879 emit_constant_insn (cond,
1880 gen_rtx_SET (VOIDmode, target,
1881 gen_rtx_fmt_ee (code, mode,
1891 if (set_sign_bit_copies > 8
1892 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
1896 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1897 rtx shift = GEN_INT (set_sign_bit_copies);
1901 gen_rtx_SET (VOIDmode, sub,
1903 gen_rtx_ASHIFT (mode,
1908 gen_rtx_SET (VOIDmode, target,
1910 gen_rtx_LSHIFTRT (mode, sub,
1916 if (set_zero_bit_copies > 8
1917 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
1921 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1922 rtx shift = GEN_INT (set_zero_bit_copies);
1926 gen_rtx_SET (VOIDmode, sub,
1928 gen_rtx_LSHIFTRT (mode,
1933 gen_rtx_SET (VOIDmode, target,
1935 gen_rtx_ASHIFT (mode, sub,
1941 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val)))
1945 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1946 emit_constant_insn (cond,
1947 gen_rtx_SET (VOIDmode, sub,
1948 gen_rtx_NOT (mode, source)));
1951 sub = gen_reg_rtx (mode);
1952 emit_constant_insn (cond,
1953 gen_rtx_SET (VOIDmode, sub,
1954 gen_rtx_AND (mode, source,
1956 emit_constant_insn (cond,
1957 gen_rtx_SET (VOIDmode, target,
1958 gen_rtx_NOT (mode, sub)));
1965 /* See if two shifts will do 2 or more insn's worth of work. */
1966 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
1968 HOST_WIDE_INT shift_mask = ((0xffffffff
1969 << (32 - clear_sign_bit_copies))
1972 if ((remainder | shift_mask) != 0xffffffff)
1976 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1977 insns = arm_gen_constant (AND, mode, cond,
1978 remainder | shift_mask,
1979 new_src, source, subtargets, 1);
1984 rtx targ = subtargets ? NULL_RTX : target;
1985 insns = arm_gen_constant (AND, mode, cond,
1986 remainder | shift_mask,
1987 targ, source, subtargets, 0);
1993 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1994 rtx shift = GEN_INT (clear_sign_bit_copies);
1996 emit_insn (gen_ashlsi3 (new_src, source, shift));
1997 emit_insn (gen_lshrsi3 (target, new_src, shift));
2003 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
2005 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
2007 if ((remainder | shift_mask) != 0xffffffff)
2011 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2013 insns = arm_gen_constant (AND, mode, cond,
2014 remainder | shift_mask,
2015 new_src, source, subtargets, 1);
2020 rtx targ = subtargets ? NULL_RTX : target;
2022 insns = arm_gen_constant (AND, mode, cond,
2023 remainder | shift_mask,
2024 targ, source, subtargets, 0);
2030 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2031 rtx shift = GEN_INT (clear_zero_bit_copies);
2033 emit_insn (gen_lshrsi3 (new_src, source, shift));
2034 emit_insn (gen_ashlsi3 (target, new_src, shift));
2046 for (i = 0; i < 32; i++)
2047 if (remainder & (1 << i))
2050 if (code == AND || (can_invert && num_bits_set > 16))
2051 remainder = (~remainder) & 0xffffffff;
2052 else if (code == PLUS && num_bits_set > 16)
2053 remainder = (-remainder) & 0xffffffff;
2060 /* Now try and find a way of doing the job in either two or three
2062 We start by looking for the largest block of zeros that are aligned on
2063 a 2-bit boundary, we then fill up the temps, wrapping around to the
2064 top of the word when we drop off the bottom.
2065 In the worst case this code should produce no more than four insns. */
2068 int best_consecutive_zeros = 0;
2070 for (i = 0; i < 32; i += 2)
2072 int consecutive_zeros = 0;
2074 if (!(remainder & (3 << i)))
2076 while ((i < 32) && !(remainder & (3 << i)))
2078 consecutive_zeros += 2;
2081 if (consecutive_zeros > best_consecutive_zeros)
2083 best_consecutive_zeros = consecutive_zeros;
2084 best_start = i - consecutive_zeros;
2090 /* So long as it won't require any more insns to do so, it's
2091 desirable to emit a small constant (in bits 0...9) in the last
2092 insn. This way there is more chance that it can be combined with
2093 a later addressing insn to form a pre-indexed load or store
2094 operation. Consider:
2096 *((volatile int *)0xe0000100) = 1;
2097 *((volatile int *)0xe0000110) = 2;
2099 We want this to wind up as:
2103 str rB, [rA, #0x100]
2105 str rB, [rA, #0x110]
2107 rather than having to synthesize both large constants from scratch.
2109 Therefore, we calculate how many insns would be required to emit
2110 the constant starting from `best_start', and also starting from
2111 zero (i.e. with bit 31 first to be output). If `best_start' doesn't
2112 yield a shorter sequence, we may as well use zero. */
2114 && ((((unsigned HOST_WIDE_INT) 1) << best_start) < remainder)
2115 && (count_insns_for_constant (remainder, 0) <=
2116 count_insns_for_constant (remainder, best_start)))
2119 /* Now start emitting the insns. */
2127 if (remainder & (3 << (i - 2)))
2132 temp1 = remainder & ((0x0ff << end)
2133 | ((i < end) ? (0xff >> (32 - end)) : 0));
2134 remainder &= ~temp1;
2138 rtx new_src, temp1_rtx;
2140 if (code == SET || code == MINUS)
2142 new_src = (subtargets ? gen_reg_rtx (mode) : target);
2143 if (can_invert && code != MINUS)
2148 if (remainder && subtargets)
2149 new_src = gen_reg_rtx (mode);
2154 else if (can_negate)
2158 temp1 = trunc_int_for_mode (temp1, mode);
2159 temp1_rtx = GEN_INT (temp1);
2163 else if (code == MINUS)
2164 temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source);
2166 temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx);
2168 emit_constant_insn (cond,
2169 gen_rtx_SET (VOIDmode, new_src,
2179 else if (code == MINUS)
2193 /* Canonicalize a comparison so that we are more likely to recognize it.
2194 This can be done for a few constant compares, where we can make the
2195 immediate value easier to load. */
2198 arm_canonicalize_comparison (enum rtx_code code, rtx * op1)
2200 unsigned HOST_WIDE_INT i = INTVAL (*op1);
2210 if (i != ((((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1)) - 1)
2211 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
2213 *op1 = GEN_INT (i + 1);
2214 return code == GT ? GE : LT;
2220 if (i != (((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1))
2221 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
2223 *op1 = GEN_INT (i - 1);
2224 return code == GE ? GT : LE;
2230 if (i != ~((unsigned HOST_WIDE_INT) 0)
2231 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
2233 *op1 = GEN_INT (i + 1);
2234 return code == GTU ? GEU : LTU;
2241 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
2243 *op1 = GEN_INT (i - 1);
2244 return code == GEU ? GTU : LEU;
2256 /* Define how to find the value returned by a function. */
2258 rtx arm_function_value(tree type, tree func ATTRIBUTE_UNUSED)
2260 enum machine_mode mode;
2261 int unsignedp ATTRIBUTE_UNUSED;
2262 rtx r ATTRIBUTE_UNUSED;
2265 mode = TYPE_MODE (type);
2266 /* Promote integer types. */
2267 if (INTEGRAL_TYPE_P (type))
2268 PROMOTE_FUNCTION_MODE (mode, unsignedp, type);
2269 return LIBCALL_VALUE(mode);
2273 /* Decide whether a type should be returned in memory (true)
2274 or in a register (false). This is called by the macro
2275 RETURN_IN_MEMORY. */
2277 arm_return_in_memory (tree type)
2281 if (!AGGREGATE_TYPE_P (type))
2282 /* All simple types are returned in registers. */
2285 size = int_size_in_bytes (type);
2287 if (arm_abi != ARM_ABI_APCS)
2289 /* ATPCS and later return aggregate types in memory only if they are
2290 larger than a word (or are variable size). */
2291 return (size < 0 || size > UNITS_PER_WORD);
2294 /* For the arm-wince targets we choose to be compatible with Microsoft's
2295 ARM and Thumb compilers, which always return aggregates in memory. */
2297 /* All structures/unions bigger than one word are returned in memory.
2298 Also catch the case where int_size_in_bytes returns -1. In this case
2299 the aggregate is either huge or of variable size, and in either case
2300 we will want to return it via memory and not in a register. */
2301 if (size < 0 || size > UNITS_PER_WORD)
2304 if (TREE_CODE (type) == RECORD_TYPE)
2308 /* For a struct the APCS says that we only return in a register
2309 if the type is 'integer like' and every addressable element
2310 has an offset of zero. For practical purposes this means
2311 that the structure can have at most one non bit-field element
2312 and that this element must be the first one in the structure. */
2314 /* Find the first field, ignoring non FIELD_DECL things which will
2315 have been created by C++. */
2316 for (field = TYPE_FIELDS (type);
2317 field && TREE_CODE (field) != FIELD_DECL;
2318 field = TREE_CHAIN (field))
2322 return 0; /* An empty structure. Allowed by an extension to ANSI C. */
2324 /* Check that the first field is valid for returning in a register. */
2326 /* ... Floats are not allowed */
2327 if (FLOAT_TYPE_P (TREE_TYPE (field)))
2330 /* ... Aggregates that are not themselves valid for returning in
2331 a register are not allowed. */
2332 if (RETURN_IN_MEMORY (TREE_TYPE (field)))
2335 /* Now check the remaining fields, if any. Only bitfields are allowed,
2336 since they are not addressable. */
2337 for (field = TREE_CHAIN (field);
2339 field = TREE_CHAIN (field))
2341 if (TREE_CODE (field) != FIELD_DECL)
2344 if (!DECL_BIT_FIELD_TYPE (field))
2351 if (TREE_CODE (type) == UNION_TYPE)
2355 /* Unions can be returned in registers if every element is
2356 integral, or can be returned in an integer register. */
2357 for (field = TYPE_FIELDS (type);
2359 field = TREE_CHAIN (field))
2361 if (TREE_CODE (field) != FIELD_DECL)
2364 if (FLOAT_TYPE_P (TREE_TYPE (field)))
2367 if (RETURN_IN_MEMORY (TREE_TYPE (field)))
2373 #endif /* not ARM_WINCE */
2375 /* Return all other types in memory. */
2379 /* Indicate whether or not words of a double are in big-endian order. */
2382 arm_float_words_big_endian (void)
2384 if (TARGET_MAVERICK)
2387 /* For FPA, float words are always big-endian. For VFP, floats words
2388 follow the memory system mode. */
2396 return (TARGET_BIG_END ? 1 : 0);
2401 /* Initialize a variable CUM of type CUMULATIVE_ARGS
2402 for a call to a function whose data type is FNTYPE.
2403 For a library call, FNTYPE is NULL. */
2405 arm_init_cumulative_args (CUMULATIVE_ARGS *pcum, tree fntype,
2406 rtx libname ATTRIBUTE_UNUSED,
2407 tree fndecl ATTRIBUTE_UNUSED)
2409 /* On the ARM, the offset starts at 0. */
2410 pcum->nregs = ((fntype && aggregate_value_p (TREE_TYPE (fntype), fntype)) ? 1 : 0);
2411 pcum->iwmmxt_nregs = 0;
2412 pcum->can_split = true;
2414 pcum->call_cookie = CALL_NORMAL;
2416 if (TARGET_LONG_CALLS)
2417 pcum->call_cookie = CALL_LONG;
2419 /* Check for long call/short call attributes. The attributes
2420 override any command line option. */
2423 if (lookup_attribute ("short_call", TYPE_ATTRIBUTES (fntype)))
2424 pcum->call_cookie = CALL_SHORT;
2425 else if (lookup_attribute ("long_call", TYPE_ATTRIBUTES (fntype)))
2426 pcum->call_cookie = CALL_LONG;
2429 /* Varargs vectors are treated the same as long long.
2430 named_count avoids having to change the way arm handles 'named' */
2431 pcum->named_count = 0;
2434 if (TARGET_REALLY_IWMMXT && fntype)
2438 for (fn_arg = TYPE_ARG_TYPES (fntype);
2440 fn_arg = TREE_CHAIN (fn_arg))
2441 pcum->named_count += 1;
2443 if (! pcum->named_count)
2444 pcum->named_count = INT_MAX;
2449 /* Return true if mode/type need doubleword alignment. */
2451 arm_needs_doubleword_align (enum machine_mode mode, tree type)
2453 return (GET_MODE_ALIGNMENT (mode) > PARM_BOUNDARY
2454 || (type && TYPE_ALIGN (type) > PARM_BOUNDARY));
2458 /* Determine where to put an argument to a function.
2459 Value is zero to push the argument on the stack,
2460 or a hard register in which to store the argument.
2462 MODE is the argument's machine mode.
2463 TYPE is the data type of the argument (as a tree).
2464 This is null for libcalls where that information may
2466 CUM is a variable of type CUMULATIVE_ARGS which gives info about
2467 the preceding args and about the function being called.
2468 NAMED is nonzero if this argument is a named parameter
2469 (otherwise it is an extra parameter matching an ellipsis). */
2472 arm_function_arg (CUMULATIVE_ARGS *pcum, enum machine_mode mode,
2473 tree type, int named)
2477 /* Varargs vectors are treated the same as long long.
2478 named_count avoids having to change the way arm handles 'named' */
2479 if (TARGET_IWMMXT_ABI
2480 && arm_vector_mode_supported_p (mode)
2481 && pcum->named_count > pcum->nargs + 1)
2483 if (pcum->iwmmxt_nregs <= 9)
2484 return gen_rtx_REG (mode, pcum->iwmmxt_nregs + FIRST_IWMMXT_REGNUM);
2487 pcum->can_split = false;
2492 /* Put doubleword aligned quantities in even register pairs. */
2494 && ARM_DOUBLEWORD_ALIGN
2495 && arm_needs_doubleword_align (mode, type))
2498 if (mode == VOIDmode)
2499 /* Compute operand 2 of the call insn. */
2500 return GEN_INT (pcum->call_cookie);
2502 /* Only allow splitting an arg between regs and memory if all preceding
2503 args were allocated to regs. For args passed by reference we only count
2504 the reference pointer. */
2505 if (pcum->can_split)
2508 nregs = ARM_NUM_REGS2 (mode, type);
2510 if (!named || pcum->nregs + nregs > NUM_ARG_REGS)
2513 return gen_rtx_REG (mode, pcum->nregs);
2516 /* Variable sized types are passed by reference. This is a GCC
2517 extension to the ARM ABI. */
2520 arm_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
2521 enum machine_mode mode ATTRIBUTE_UNUSED,
2522 tree type, bool named ATTRIBUTE_UNUSED)
2524 return type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST;
2527 /* Encode the current state of the #pragma [no_]long_calls. */
2530 OFF, /* No #pramgma [no_]long_calls is in effect. */
2531 LONG, /* #pragma long_calls is in effect. */
2532 SHORT /* #pragma no_long_calls is in effect. */
2535 static arm_pragma_enum arm_pragma_long_calls = OFF;
2538 arm_pr_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
2540 arm_pragma_long_calls = LONG;
2544 arm_pr_no_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
2546 arm_pragma_long_calls = SHORT;
2550 arm_pr_long_calls_off (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
2552 arm_pragma_long_calls = OFF;
2555 /* Table of machine attributes. */
2556 const struct attribute_spec arm_attribute_table[] =
2558 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2559 /* Function calls made to this symbol must be done indirectly, because
2560 it may lie outside of the 26 bit addressing range of a normal function
2562 { "long_call", 0, 0, false, true, true, NULL },
2563 /* Whereas these functions are always known to reside within the 26 bit
2564 addressing range. */
2565 { "short_call", 0, 0, false, true, true, NULL },
2566 /* Interrupt Service Routines have special prologue and epilogue requirements. */
2567 { "isr", 0, 1, false, false, false, arm_handle_isr_attribute },
2568 { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute },
2569 { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute },
2571 /* ARM/PE has three new attributes:
2573 dllexport - for exporting a function/variable that will live in a dll
2574 dllimport - for importing a function/variable from a dll
2576 Microsoft allows multiple declspecs in one __declspec, separating
2577 them with spaces. We do NOT support this. Instead, use __declspec
2580 { "dllimport", 0, 0, true, false, false, NULL },
2581 { "dllexport", 0, 0, true, false, false, NULL },
2582 { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute },
2583 #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
2584 { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
2585 { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
2587 { NULL, 0, 0, false, false, false, NULL }
2590 /* Handle an attribute requiring a FUNCTION_DECL;
2591 arguments as in struct attribute_spec.handler. */
2593 arm_handle_fndecl_attribute (tree *node, tree name, tree args ATTRIBUTE_UNUSED,
2594 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
2596 if (TREE_CODE (*node) != FUNCTION_DECL)
2598 warning ("`%s' attribute only applies to functions",
2599 IDENTIFIER_POINTER (name));
2600 *no_add_attrs = true;
2606 /* Handle an "interrupt" or "isr" attribute;
2607 arguments as in struct attribute_spec.handler. */
2609 arm_handle_isr_attribute (tree *node, tree name, tree args, int flags,
2614 if (TREE_CODE (*node) != FUNCTION_DECL)
2616 warning ("`%s' attribute only applies to functions",
2617 IDENTIFIER_POINTER (name));
2618 *no_add_attrs = true;
2620 /* FIXME: the argument if any is checked for type attributes;
2621 should it be checked for decl ones? */
2625 if (TREE_CODE (*node) == FUNCTION_TYPE
2626 || TREE_CODE (*node) == METHOD_TYPE)
2628 if (arm_isr_value (args) == ARM_FT_UNKNOWN)
2630 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
2631 *no_add_attrs = true;
2634 else if (TREE_CODE (*node) == POINTER_TYPE
2635 && (TREE_CODE (TREE_TYPE (*node)) == FUNCTION_TYPE
2636 || TREE_CODE (TREE_TYPE (*node)) == METHOD_TYPE)
2637 && arm_isr_value (args) != ARM_FT_UNKNOWN)
2639 *node = build_variant_type_copy (*node);
2640 TREE_TYPE (*node) = build_type_attribute_variant
2642 tree_cons (name, args, TYPE_ATTRIBUTES (TREE_TYPE (*node))));
2643 *no_add_attrs = true;
2647 /* Possibly pass this attribute on from the type to a decl. */
2648 if (flags & ((int) ATTR_FLAG_DECL_NEXT
2649 | (int) ATTR_FLAG_FUNCTION_NEXT
2650 | (int) ATTR_FLAG_ARRAY_NEXT))
2652 *no_add_attrs = true;
2653 return tree_cons (name, args, NULL_TREE);
2657 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
2665 /* Return 0 if the attributes for two types are incompatible, 1 if they
2666 are compatible, and 2 if they are nearly compatible (which causes a
2667 warning to be generated). */
2669 arm_comp_type_attributes (tree type1, tree type2)
2673 /* Check for mismatch of non-default calling convention. */
2674 if (TREE_CODE (type1) != FUNCTION_TYPE)
2677 /* Check for mismatched call attributes. */
2678 l1 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type1)) != NULL;
2679 l2 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type2)) != NULL;
2680 s1 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type1)) != NULL;
2681 s2 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type2)) != NULL;
2683 /* Only bother to check if an attribute is defined. */
2684 if (l1 | l2 | s1 | s2)
2686 /* If one type has an attribute, the other must have the same attribute. */
2687 if ((l1 != l2) || (s1 != s2))
2690 /* Disallow mixed attributes. */
2691 if ((l1 & s2) || (l2 & s1))
2695 /* Check for mismatched ISR attribute. */
2696 l1 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type1)) != NULL;
2698 l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1)) != NULL;
2699 l2 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type2)) != NULL;
2701 l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2)) != NULL;
2708 /* Encode long_call or short_call attribute by prefixing
2709 symbol name in DECL with a special character FLAG. */
2711 arm_encode_call_attribute (tree decl, int flag)
2713 const char * str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2714 int len = strlen (str);
2717 /* Do not allow weak functions to be treated as short call. */
2718 if (DECL_WEAK (decl) && flag == SHORT_CALL_FLAG_CHAR)
2721 newstr = alloca (len + 2);
2723 strcpy (newstr + 1, str);
2725 newstr = (char *) ggc_alloc_string (newstr, len + 1);
2726 XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
2729 /* Assigns default attributes to newly defined type. This is used to
2730 set short_call/long_call attributes for function types of
2731 functions defined inside corresponding #pragma scopes. */
2733 arm_set_default_type_attributes (tree type)
2735 /* Add __attribute__ ((long_call)) to all functions, when
2736 inside #pragma long_calls or __attribute__ ((short_call)),
2737 when inside #pragma no_long_calls. */
2738 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
2740 tree type_attr_list, attr_name;
2741 type_attr_list = TYPE_ATTRIBUTES (type);
2743 if (arm_pragma_long_calls == LONG)
2744 attr_name = get_identifier ("long_call");
2745 else if (arm_pragma_long_calls == SHORT)
2746 attr_name = get_identifier ("short_call");
2750 type_attr_list = tree_cons (attr_name, NULL_TREE, type_attr_list);
2751 TYPE_ATTRIBUTES (type) = type_attr_list;
2755 /* Return 1 if the operand is a SYMBOL_REF for a function known to be
2756 defined within the current compilation unit. If this cannot be
2757 determined, then 0 is returned. */
2759 current_file_function_operand (rtx sym_ref)
2761 /* This is a bit of a fib. A function will have a short call flag
2762 applied to its name if it has the short call attribute, or it has
2763 already been defined within the current compilation unit. */
2764 if (ENCODED_SHORT_CALL_ATTR_P (XSTR (sym_ref, 0)))
2767 /* The current function is always defined within the current compilation
2768 unit. If it s a weak definition however, then this may not be the real
2769 definition of the function, and so we have to say no. */
2770 if (sym_ref == XEXP (DECL_RTL (current_function_decl), 0)
2771 && !DECL_WEAK (current_function_decl))
2774 /* We cannot make the determination - default to returning 0. */
2778 /* Return nonzero if a 32 bit "long_call" should be generated for
2779 this call. We generate a long_call if the function:
2781 a. has an __attribute__((long call))
2782 or b. is within the scope of a #pragma long_calls
2783 or c. the -mlong-calls command line switch has been specified
2785 1. -ffunction-sections is in effect
2786 or 2. the current function has __attribute__ ((section))
2787 or 3. the target function has __attribute__ ((section))
2789 However we do not generate a long call if the function:
2791 d. has an __attribute__ ((short_call))
2792 or e. is inside the scope of a #pragma no_long_calls
2793 or f. is defined within the current compilation unit.
2795 This function will be called by C fragments contained in the machine
2796 description file. SYM_REF and CALL_COOKIE correspond to the matched
2797 rtl operands. CALL_SYMBOL is used to distinguish between
2798 two different callers of the function. It is set to 1 in the
2799 "call_symbol" and "call_symbol_value" patterns and to 0 in the "call"
2800 and "call_value" patterns. This is because of the difference in the
2801 SYM_REFs passed by these patterns. */
2803 arm_is_longcall_p (rtx sym_ref, int call_cookie, int call_symbol)
2807 if (GET_CODE (sym_ref) != MEM)
2810 sym_ref = XEXP (sym_ref, 0);
2813 if (GET_CODE (sym_ref) != SYMBOL_REF)
2816 if (call_cookie & CALL_SHORT)
2819 if (TARGET_LONG_CALLS)
2821 if (flag_function_sections
2822 || DECL_SECTION_NAME (current_function_decl))
2823 /* c.3 is handled by the definition of the
2824 ARM_DECLARE_FUNCTION_SIZE macro. */
2828 if (current_file_function_operand (sym_ref))
2831 return (call_cookie & CALL_LONG)
2832 || ENCODED_LONG_CALL_ATTR_P (XSTR (sym_ref, 0))
2833 || TARGET_LONG_CALLS;
2836 /* Return nonzero if it is ok to make a tail-call to DECL. */
2838 arm_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
2840 int call_type = TARGET_LONG_CALLS ? CALL_LONG : CALL_NORMAL;
2842 if (cfun->machine->sibcall_blocked)
2845 /* Never tailcall something for which we have no decl, or if we
2846 are in Thumb mode. */
2847 if (decl == NULL || TARGET_THUMB)
2850 /* Get the calling method. */
2851 if (lookup_attribute ("short_call", TYPE_ATTRIBUTES (TREE_TYPE (decl))))
2852 call_type = CALL_SHORT;
2853 else if (lookup_attribute ("long_call", TYPE_ATTRIBUTES (TREE_TYPE (decl))))
2854 call_type = CALL_LONG;
2856 /* Cannot tail-call to long calls, since these are out of range of
2857 a branch instruction. However, if not compiling PIC, we know
2858 we can reach the symbol if it is in this compilation unit. */
2859 if (call_type == CALL_LONG && (flag_pic || !TREE_ASM_WRITTEN (decl)))
2862 /* If we are interworking and the function is not declared static
2863 then we can't tail-call it unless we know that it exists in this
2864 compilation unit (since it might be a Thumb routine). */
2865 if (TARGET_INTERWORK && TREE_PUBLIC (decl) && !TREE_ASM_WRITTEN (decl))
2868 /* Never tailcall from an ISR routine - it needs a special exit sequence. */
2869 if (IS_INTERRUPT (arm_current_func_type ()))
2872 /* Everything else is ok. */
2877 /* Addressing mode support functions. */
2879 /* Return nonzero if X is a legitimate immediate operand when compiling
2882 legitimate_pic_operand_p (rtx x)
2886 && (GET_CODE (x) == SYMBOL_REF
2887 || (GET_CODE (x) == CONST
2888 && GET_CODE (XEXP (x, 0)) == PLUS
2889 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)))
2896 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
2898 if (GET_CODE (orig) == SYMBOL_REF
2899 || GET_CODE (orig) == LABEL_REF)
2901 #ifndef AOF_ASSEMBLER
2902 rtx pic_ref, address;
2912 reg = gen_reg_rtx (Pmode);
2917 #ifdef AOF_ASSEMBLER
2918 /* The AOF assembler can generate relocations for these directly, and
2919 understands that the PIC register has to be added into the offset. */
2920 insn = emit_insn (gen_pic_load_addr_based (reg, orig));
2923 address = gen_reg_rtx (Pmode);
2928 emit_insn (gen_pic_load_addr_arm (address, orig));
2930 emit_insn (gen_pic_load_addr_thumb (address, orig));
2932 if ((GET_CODE (orig) == LABEL_REF
2933 || (GET_CODE (orig) == SYMBOL_REF &&
2934 SYMBOL_REF_LOCAL_P (orig)))
2936 pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, address);
2939 pic_ref = gen_const_mem (Pmode,
2940 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
2944 insn = emit_move_insn (reg, pic_ref);
2946 current_function_uses_pic_offset_table = 1;
2947 /* Put a REG_EQUAL note on this insn, so that it can be optimized
2949 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
2953 else if (GET_CODE (orig) == CONST)
2957 if (GET_CODE (XEXP (orig, 0)) == PLUS
2958 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
2966 reg = gen_reg_rtx (Pmode);
2969 if (GET_CODE (XEXP (orig, 0)) == PLUS)
2971 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
2972 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
2973 base == reg ? 0 : reg);
2978 if (GET_CODE (offset) == CONST_INT)
2980 /* The base register doesn't really matter, we only want to
2981 test the index for the appropriate mode. */
2982 if (!arm_legitimate_index_p (mode, offset, SET, 0))
2984 if (!no_new_pseudos)
2985 offset = force_reg (Pmode, offset);
2990 if (GET_CODE (offset) == CONST_INT)
2991 return plus_constant (base, INTVAL (offset));
2994 if (GET_MODE_SIZE (mode) > 4
2995 && (GET_MODE_CLASS (mode) == MODE_INT
2996 || TARGET_SOFT_FLOAT))
2998 emit_insn (gen_addsi3 (reg, base, offset));
3002 return gen_rtx_PLUS (Pmode, base, offset);
3009 /* Find a spare low register. */
3012 thumb_find_work_register (int live_regs_mask)
3016 /* Use a spare arg register. */
3017 if (!regs_ever_live[LAST_ARG_REGNUM])
3018 return LAST_ARG_REGNUM;
3020 /* Look for a pushed register. */
3021 for (reg = 0; reg < LAST_LO_REGNUM; reg++)
3022 if (live_regs_mask & (1 << reg))
3025 /* Something went wrong. */
3030 /* Generate code to load the PIC register. */
3033 arm_load_pic_register (void)
3035 #ifndef AOF_ASSEMBLER
3036 rtx l1, pic_tmp, pic_tmp2, pic_rtx;
3037 rtx global_offset_table;
3039 if (current_function_uses_pic_offset_table == 0 || TARGET_SINGLE_PIC_BASE)
3045 l1 = gen_label_rtx ();
3047 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3048 /* On the ARM the PC register contains 'dot + 8' at the time of the
3049 addition, on the Thumb it is 'dot + 4'. */
3050 pic_tmp = plus_constant (gen_rtx_LABEL_REF (Pmode, l1), TARGET_ARM ? 8 : 4);
3052 pic_tmp2 = gen_rtx_CONST (VOIDmode,
3053 gen_rtx_PLUS (Pmode, global_offset_table, pc_rtx));
3055 pic_tmp2 = gen_rtx_CONST (VOIDmode, global_offset_table);
3057 pic_rtx = gen_rtx_CONST (Pmode, gen_rtx_MINUS (Pmode, pic_tmp2, pic_tmp));
3061 emit_insn (gen_pic_load_addr_arm (pic_offset_table_rtx, pic_rtx));
3062 emit_insn (gen_pic_add_dot_plus_eight (pic_offset_table_rtx, l1));
3066 if (REGNO (pic_offset_table_rtx) > LAST_LO_REGNUM)
3070 /* We will have pushed the pic register, so should always be
3071 able to find a work register. */
3072 reg = thumb_find_work_register (thumb_compute_save_reg_mask ());
3073 pic_tmp = gen_rtx_REG (SImode, reg);
3074 emit_insn (gen_pic_load_addr_thumb (pic_tmp, pic_rtx));
3075 emit_insn (gen_movsi (pic_offset_table_rtx, pic_tmp));
3078 emit_insn (gen_pic_load_addr_thumb (pic_offset_table_rtx, pic_rtx));
3079 emit_insn (gen_pic_add_dot_plus_four (pic_offset_table_rtx, l1));
3082 /* Need to emit this whether or not we obey regdecls,
3083 since setjmp/longjmp can cause life info to screw up. */
3084 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
3085 #endif /* AOF_ASSEMBLER */
3089 /* Return nonzero if X is valid as an ARM state addressing register. */
3091 arm_address_register_rtx_p (rtx x, int strict_p)
3095 if (GET_CODE (x) != REG)
3101 return ARM_REGNO_OK_FOR_BASE_P (regno);
3103 return (regno <= LAST_ARM_REGNUM
3104 || regno >= FIRST_PSEUDO_REGISTER
3105 || regno == FRAME_POINTER_REGNUM
3106 || regno == ARG_POINTER_REGNUM);
3109 /* Return nonzero if X is a valid ARM state address operand. */
3111 arm_legitimate_address_p (enum machine_mode mode, rtx x, RTX_CODE outer,
3115 enum rtx_code code = GET_CODE (x);
3117 if (arm_address_register_rtx_p (x, strict_p))
3120 use_ldrd = (TARGET_LDRD
3122 || (mode == DFmode && (TARGET_SOFT_FLOAT || TARGET_VFP))));
3124 if (code == POST_INC || code == PRE_DEC
3125 || ((code == PRE_INC || code == POST_DEC)
3126 && (use_ldrd || GET_MODE_SIZE (mode) <= 4)))
3127 return arm_address_register_rtx_p (XEXP (x, 0), strict_p);
3129 else if ((code == POST_MODIFY || code == PRE_MODIFY)
3130 && arm_address_register_rtx_p (XEXP (x, 0), strict_p)
3131 && GET_CODE (XEXP (x, 1)) == PLUS
3132 && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0)))
3134 rtx addend = XEXP (XEXP (x, 1), 1);
3136 /* Don't allow ldrd post increment by register because it's hard
3137 to fixup invalid register choices. */
3139 && GET_CODE (x) == POST_MODIFY
3140 && GET_CODE (addend) == REG)
3143 return ((use_ldrd || GET_MODE_SIZE (mode) <= 4)
3144 && arm_legitimate_index_p (mode, addend, outer, strict_p));
3147 /* After reload constants split into minipools will have addresses
3148 from a LABEL_REF. */
3149 else if (reload_completed
3150 && (code == LABEL_REF
3152 && GET_CODE (XEXP (x, 0)) == PLUS
3153 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3154 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)))
3157 else if (mode == TImode)
3160 else if (code == PLUS)
3162 rtx xop0 = XEXP (x, 0);
3163 rtx xop1 = XEXP (x, 1);
3165 return ((arm_address_register_rtx_p (xop0, strict_p)
3166 && arm_legitimate_index_p (mode, xop1, outer, strict_p))
3167 || (arm_address_register_rtx_p (xop1, strict_p)
3168 && arm_legitimate_index_p (mode, xop0, outer, strict_p)));
3172 /* Reload currently can't handle MINUS, so disable this for now */
3173 else if (GET_CODE (x) == MINUS)
3175 rtx xop0 = XEXP (x, 0);
3176 rtx xop1 = XEXP (x, 1);
3178 return (arm_address_register_rtx_p (xop0, strict_p)
3179 && arm_legitimate_index_p (mode, xop1, outer, strict_p));
3183 else if (GET_MODE_CLASS (mode) != MODE_FLOAT
3184 && code == SYMBOL_REF
3185 && CONSTANT_POOL_ADDRESS_P (x)
3187 && symbol_mentioned_p (get_pool_constant (x))))
3193 /* Return nonzero if INDEX is valid for an address index operand in
3196 arm_legitimate_index_p (enum machine_mode mode, rtx index, RTX_CODE outer,
3199 HOST_WIDE_INT range;
3200 enum rtx_code code = GET_CODE (index);
3202 /* Standard coprocessor addressing modes. */
3203 if (TARGET_HARD_FLOAT
3204 && (TARGET_FPA || TARGET_MAVERICK)
3205 && (GET_MODE_CLASS (mode) == MODE_FLOAT
3206 || (TARGET_MAVERICK && mode == DImode)))
3207 return (code == CONST_INT && INTVAL (index) < 1024
3208 && INTVAL (index) > -1024
3209 && (INTVAL (index) & 3) == 0);
3211 if (TARGET_REALLY_IWMMXT && VALID_IWMMXT_REG_MODE (mode))
3212 return (code == CONST_INT
3213 && INTVAL (index) < 1024
3214 && INTVAL (index) > -1024
3215 && (INTVAL (index) & 3) == 0);
3217 if (arm_address_register_rtx_p (index, strict_p)
3218 && (GET_MODE_SIZE (mode) <= 4))
3221 if (mode == DImode || mode == DFmode)
3223 if (code == CONST_INT)
3225 HOST_WIDE_INT val = INTVAL (index);
3228 return val > -256 && val < 256;
3230 return val > -4096 && val < 4092;
3233 return TARGET_LDRD && arm_address_register_rtx_p (index, strict_p);
3236 if (GET_MODE_SIZE (mode) <= 4
3239 || (mode == QImode && outer == SIGN_EXTEND))))
3243 rtx xiop0 = XEXP (index, 0);
3244 rtx xiop1 = XEXP (index, 1);
3246 return ((arm_address_register_rtx_p (xiop0, strict_p)
3247 && power_of_two_operand (xiop1, SImode))
3248 || (arm_address_register_rtx_p (xiop1, strict_p)
3249 && power_of_two_operand (xiop0, SImode)));
3251 else if (code == LSHIFTRT || code == ASHIFTRT
3252 || code == ASHIFT || code == ROTATERT)
3254 rtx op = XEXP (index, 1);
3256 return (arm_address_register_rtx_p (XEXP (index, 0), strict_p)
3257 && GET_CODE (op) == CONST_INT
3259 && INTVAL (op) <= 31);
3263 /* For ARM v4 we may be doing a sign-extend operation during the
3267 if (mode == HImode || (outer == SIGN_EXTEND && mode == QImode))
3273 range = (mode == HImode) ? 4095 : 4096;
3275 return (code == CONST_INT
3276 && INTVAL (index) < range
3277 && INTVAL (index) > -range);
3280 /* Return nonzero if X is valid as a Thumb state base register. */
3282 thumb_base_register_rtx_p (rtx x, enum machine_mode mode, int strict_p)
3286 if (GET_CODE (x) != REG)
3292 return THUMB_REGNO_MODE_OK_FOR_BASE_P (regno, mode);
3294 return (regno <= LAST_LO_REGNUM
3295 || regno > LAST_VIRTUAL_REGISTER
3296 || regno == FRAME_POINTER_REGNUM
3297 || (GET_MODE_SIZE (mode) >= 4
3298 && (regno == STACK_POINTER_REGNUM
3299 || regno >= FIRST_PSEUDO_REGISTER
3300 || x == hard_frame_pointer_rtx
3301 || x == arg_pointer_rtx)));
3304 /* Return nonzero if x is a legitimate index register. This is the case
3305 for any base register that can access a QImode object. */
3307 thumb_index_register_rtx_p (rtx x, int strict_p)
3309 return thumb_base_register_rtx_p (x, QImode, strict_p);
3312 /* Return nonzero if x is a legitimate Thumb-state address.
3314 The AP may be eliminated to either the SP or the FP, so we use the
3315 least common denominator, e.g. SImode, and offsets from 0 to 64.
3317 ??? Verify whether the above is the right approach.
3319 ??? Also, the FP may be eliminated to the SP, so perhaps that
3320 needs special handling also.
3322 ??? Look at how the mips16 port solves this problem. It probably uses
3323 better ways to solve some of these problems.
3325 Although it is not incorrect, we don't accept QImode and HImode
3326 addresses based on the frame pointer or arg pointer until the
3327 reload pass starts. This is so that eliminating such addresses
3328 into stack based ones won't produce impossible code. */
3330 thumb_legitimate_address_p (enum machine_mode mode, rtx x, int strict_p)
3332 /* ??? Not clear if this is right. Experiment. */
3333 if (GET_MODE_SIZE (mode) < 4
3334 && !(reload_in_progress || reload_completed)
3335 && (reg_mentioned_p (frame_pointer_rtx, x)
3336 || reg_mentioned_p (arg_pointer_rtx, x)
3337 || reg_mentioned_p (virtual_incoming_args_rtx, x)
3338 || reg_mentioned_p (virtual_outgoing_args_rtx, x)
3339 || reg_mentioned_p (virtual_stack_dynamic_rtx, x)
3340 || reg_mentioned_p (virtual_stack_vars_rtx, x)))
3343 /* Accept any base register. SP only in SImode or larger. */
3344 else if (thumb_base_register_rtx_p (x, mode, strict_p))
3347 /* This is PC relative data before arm_reorg runs. */
3348 else if (GET_MODE_SIZE (mode) >= 4 && CONSTANT_P (x)
3349 && GET_CODE (x) == SYMBOL_REF
3350 && CONSTANT_POOL_ADDRESS_P (x) && ! flag_pic)
3353 /* This is PC relative data after arm_reorg runs. */
3354 else if (GET_MODE_SIZE (mode) >= 4 && reload_completed
3355 && (GET_CODE (x) == LABEL_REF
3356 || (GET_CODE (x) == CONST
3357 && GET_CODE (XEXP (x, 0)) == PLUS
3358 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3359 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)))
3362 /* Post-inc indexing only supported for SImode and larger. */
3363 else if (GET_CODE (x) == POST_INC && GET_MODE_SIZE (mode) >= 4
3364 && thumb_index_register_rtx_p (XEXP (x, 0), strict_p))
3367 else if (GET_CODE (x) == PLUS)
3369 /* REG+REG address can be any two index registers. */
3370 /* We disallow FRAME+REG addressing since we know that FRAME
3371 will be replaced with STACK, and SP relative addressing only
3372 permits SP+OFFSET. */
3373 if (GET_MODE_SIZE (mode) <= 4
3374 && XEXP (x, 0) != frame_pointer_rtx
3375 && XEXP (x, 1) != frame_pointer_rtx
3376 && thumb_index_register_rtx_p (XEXP (x, 0), strict_p)
3377 && thumb_index_register_rtx_p (XEXP (x, 1), strict_p))
3380 /* REG+const has 5-7 bit offset for non-SP registers. */
3381 else if ((thumb_index_register_rtx_p (XEXP (x, 0), strict_p)
3382 || XEXP (x, 0) == arg_pointer_rtx)
3383 && GET_CODE (XEXP (x, 1)) == CONST_INT
3384 && thumb_legitimate_offset_p (mode, INTVAL (XEXP (x, 1))))
3387 /* REG+const has 10 bit offset for SP, but only SImode and
3388 larger is supported. */
3389 /* ??? Should probably check for DI/DFmode overflow here
3390 just like GO_IF_LEGITIMATE_OFFSET does. */
3391 else if (GET_CODE (XEXP (x, 0)) == REG
3392 && REGNO (XEXP (x, 0)) == STACK_POINTER_REGNUM
3393 && GET_MODE_SIZE (mode) >= 4
3394 && GET_CODE (XEXP (x, 1)) == CONST_INT
3395 && INTVAL (XEXP (x, 1)) >= 0
3396 && INTVAL (XEXP (x, 1)) + GET_MODE_SIZE (mode) <= 1024
3397 && (INTVAL (XEXP (x, 1)) & 3) == 0)
3400 else if (GET_CODE (XEXP (x, 0)) == REG
3401 && REGNO (XEXP (x, 0)) == FRAME_POINTER_REGNUM
3402 && GET_MODE_SIZE (mode) >= 4
3403 && GET_CODE (XEXP (x, 1)) == CONST_INT
3404 && (INTVAL (XEXP (x, 1)) & 3) == 0)
3408 else if (GET_MODE_CLASS (mode) != MODE_FLOAT
3409 && GET_MODE_SIZE (mode) == 4
3410 && GET_CODE (x) == SYMBOL_REF
3411 && CONSTANT_POOL_ADDRESS_P (x)
3413 && symbol_mentioned_p (get_pool_constant (x))))
3419 /* Return nonzero if VAL can be used as an offset in a Thumb-state address
3420 instruction of mode MODE. */
3422 thumb_legitimate_offset_p (enum machine_mode mode, HOST_WIDE_INT val)
3424 switch (GET_MODE_SIZE (mode))
3427 return val >= 0 && val < 32;
3430 return val >= 0 && val < 64 && (val & 1) == 0;