]>
Commit | Line | Data |
---|---|---|
b36ba79f | 1 | /* Output routines for GCC for ARM. |
f954388e | 2 | Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
147a0bcf | 3 | 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
b3a796bc | 4 | Free Software Foundation, Inc. |
cce8749e | 5 | Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl) |
956d6950 | 6 | and Martin Simmons (@harleqn.co.uk). |
b36ba79f | 7 | More major hacks by Richard Earnshaw (rearnsha@arm.com). |
cce8749e | 8 | |
4f448245 | 9 | This file is part of GCC. |
cce8749e | 10 | |
4f448245 NC |
11 | GCC is free software; you can redistribute it and/or modify it |
12 | under the terms of the GNU General Public License as published | |
2f83c7d6 | 13 | by the Free Software Foundation; either version 3, or (at your |
4f448245 | 14 | option) any later version. |
cce8749e | 15 | |
4f448245 NC |
16 | GCC is distributed in the hope that it will be useful, but WITHOUT |
17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
18 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | |
19 | License for more details. | |
cce8749e | 20 | |
4f448245 | 21 | You should have received a copy of the GNU General Public License |
2f83c7d6 NC |
22 | along with GCC; see the file COPYING3. If not see |
23 | <http://www.gnu.org/licenses/>. */ | |
f676971a | 24 | |
56636818 | 25 | #include "config.h" |
43cffd11 | 26 | #include "system.h" |
4977bab6 ZW |
27 | #include "coretypes.h" |
28 | #include "tm.h" | |
cce8749e | 29 | #include "rtl.h" |
d5b7b3ae | 30 | #include "tree.h" |
c7319d87 | 31 | #include "obstack.h" |
cce8749e CH |
32 | #include "regs.h" |
33 | #include "hard-reg-set.h" | |
cce8749e CH |
34 | #include "insn-config.h" |
35 | #include "conditions.h" | |
cce8749e CH |
36 | #include "output.h" |
37 | #include "insn-attr.h" | |
38 | #include "flags.h" | |
af48348a | 39 | #include "reload.h" |
49ad7cfa | 40 | #include "function.h" |
bee06f3d | 41 | #include "expr.h" |
e78d8e51 | 42 | #include "optabs.h" |
718f9c0f | 43 | #include "diagnostic-core.h" |
aec3cfba | 44 | #include "recog.h" |
390b17c2 | 45 | #include "cgraph.h" |
92a432f4 | 46 | #include "ggc.h" |
d5b7b3ae | 47 | #include "except.h" |
39dabefd | 48 | #include "c-family/c-pragma.h" /* ??? */ |
7b8b8ade | 49 | #include "integrate.h" |
c27ba912 | 50 | #include "tm_p.h" |
672a6f42 NB |
51 | #include "target.h" |
52 | #include "target-def.h" | |
980e61bb | 53 | #include "debug.h" |
6e34d3a3 | 54 | #include "langhooks.h" |
6fb5fa3c | 55 | #include "df.h" |
0fd8c3ad | 56 | #include "intl.h" |
353a58f7 | 57 | #include "libfuncs.h" |
ec3728ad | 58 | #include "params.h" |
96e45421 | 59 | #include "opts.h" |
cce8749e | 60 | |
d5b7b3ae RE |
61 | /* Forward definitions of types. */ |
62 | typedef struct minipool_node Mnode; | |
63 | typedef struct minipool_fixup Mfix; | |
64 | ||
b76c3c4b PB |
65 | void (*arm_lang_output_object_attributes_hook)(void); |
66 | ||
d5b7b3ae | 67 | /* Forward function declarations. */ |
c2ed6cf8 | 68 | static bool arm_needs_doubleword_align (enum machine_mode, const_tree); |
35596784 | 69 | static int arm_compute_static_chain_stack_bytes (void); |
5848830f | 70 | static arm_stack_offsets *arm_get_frame_offsets (void); |
e32bac5b | 71 | static void arm_add_gc_roots (void); |
a406f566 MM |
72 | static int arm_gen_constant (enum rtx_code, enum machine_mode, rtx, |
73 | HOST_WIDE_INT, rtx, rtx, int, int); | |
e32bac5b RE |
74 | static unsigned bit_count (unsigned long); |
75 | static int arm_address_register_rtx_p (rtx, int); | |
1e1ab407 | 76 | static int arm_legitimate_index_p (enum machine_mode, rtx, RTX_CODE, int); |
5b3e6663 PB |
77 | static int thumb2_legitimate_index_p (enum machine_mode, rtx, int); |
78 | static int thumb1_base_register_rtx_p (rtx, enum machine_mode, int); | |
506d7b68 PB |
79 | static rtx arm_legitimize_address (rtx, rtx, enum machine_mode); |
80 | static rtx thumb_legitimize_address (rtx, rtx, enum machine_mode); | |
5b3e6663 | 81 | inline static int thumb1_index_register_rtx_p (rtx, int); |
c6c3dba9 | 82 | static bool arm_legitimate_address_p (enum machine_mode, rtx, bool); |
5848830f | 83 | static int thumb_far_jump_used_p (void); |
57934c39 | 84 | static bool thumb_force_lr_save (void); |
e32bac5b | 85 | static int const_ok_for_op (HOST_WIDE_INT, enum rtx_code); |
e32bac5b | 86 | static rtx emit_sfm (int, int); |
466e4b7a | 87 | static unsigned arm_size_return_regs (void); |
e32bac5b | 88 | static bool arm_assemble_integer (rtx, unsigned int, int); |
944442bb NF |
89 | static void arm_print_operand (FILE *, rtx, int); |
90 | static void arm_print_operand_address (FILE *, rtx); | |
91 | static bool arm_print_operand_punct_valid_p (unsigned char code); | |
e32bac5b RE |
92 | static const char *fp_const_from_val (REAL_VALUE_TYPE *); |
93 | static arm_cc get_arm_condition_code (rtx); | |
e32bac5b RE |
94 | static HOST_WIDE_INT int_log2 (HOST_WIDE_INT); |
95 | static rtx is_jump_table (rtx); | |
96 | static const char *output_multi_immediate (rtx *, const char *, const char *, | |
97 | int, HOST_WIDE_INT); | |
e32bac5b RE |
98 | static const char *shift_op (rtx, HOST_WIDE_INT *); |
99 | static struct machine_function *arm_init_machine_status (void); | |
c9ca9b88 | 100 | static void thumb_exit (FILE *, int); |
e32bac5b RE |
101 | static rtx is_jump_table (rtx); |
102 | static HOST_WIDE_INT get_jump_table_size (rtx); | |
103 | static Mnode *move_minipool_fix_forward_ref (Mnode *, Mnode *, HOST_WIDE_INT); | |
104 | static Mnode *add_minipool_forward_ref (Mfix *); | |
105 | static Mnode *move_minipool_fix_backward_ref (Mnode *, Mnode *, HOST_WIDE_INT); | |
106 | static Mnode *add_minipool_backward_ref (Mfix *); | |
107 | static void assign_minipool_offsets (Mfix *); | |
108 | static void arm_print_value (FILE *, rtx); | |
109 | static void dump_minipool (rtx); | |
110 | static int arm_barrier_cost (rtx); | |
111 | static Mfix *create_fix_barrier (Mfix *, HOST_WIDE_INT); | |
112 | static void push_minipool_barrier (rtx, HOST_WIDE_INT); | |
113 | static void push_minipool_fix (rtx, HOST_WIDE_INT, rtx *, enum machine_mode, | |
114 | rtx); | |
115 | static void arm_reorg (void); | |
116 | static bool note_invalid_constants (rtx, HOST_WIDE_INT, int); | |
e32bac5b RE |
117 | static unsigned long arm_compute_save_reg0_reg12_mask (void); |
118 | static unsigned long arm_compute_save_reg_mask (void); | |
119 | static unsigned long arm_isr_value (tree); | |
120 | static unsigned long arm_compute_func_type (void); | |
121 | static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *); | |
390b17c2 | 122 | static tree arm_handle_pcs_attribute (tree *, tree, tree, int, bool *); |
e32bac5b | 123 | static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *); |
7bff66a7 | 124 | #if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
04fb56d5 | 125 | static tree arm_handle_notshared_attribute (tree *, tree, tree, int, bool *); |
7bff66a7 | 126 | #endif |
e32bac5b RE |
127 | static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT); |
128 | static void arm_output_function_prologue (FILE *, HOST_WIDE_INT); | |
3101faab | 129 | static int arm_comp_type_attributes (const_tree, const_tree); |
e32bac5b RE |
130 | static void arm_set_default_type_attributes (tree); |
131 | static int arm_adjust_cost (rtx, rtx, rtx, int); | |
e32bac5b RE |
132 | static int count_insns_for_constant (HOST_WIDE_INT, int); |
133 | static int arm_get_strip_length (int); | |
134 | static bool arm_function_ok_for_sibcall (tree, tree); | |
390b17c2 RE |
135 | static enum machine_mode arm_promote_function_mode (const_tree, |
136 | enum machine_mode, int *, | |
137 | const_tree, int); | |
138 | static bool arm_return_in_memory (const_tree, const_tree); | |
139 | static rtx arm_function_value (const_tree, const_tree, bool); | |
7fc6a96b | 140 | static rtx arm_libcall_value (enum machine_mode, const_rtx); |
390b17c2 | 141 | |
e32bac5b RE |
142 | static void arm_internal_label (FILE *, const char *, unsigned long); |
143 | static void arm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, | |
144 | tree); | |
2929029c | 145 | static bool arm_have_conditional_execution (void); |
1a627b35 RS |
146 | static bool arm_cannot_force_const_mem (enum machine_mode, rtx); |
147 | static bool arm_legitimate_constant_p (enum machine_mode, rtx); | |
d5a0a47b RE |
148 | static bool arm_rtx_costs_1 (rtx, enum rtx_code, int*, bool); |
149 | static bool arm_size_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *); | |
150 | static bool arm_slowmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool); | |
151 | static bool arm_fastmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool); | |
152 | static bool arm_xscale_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool); | |
153 | static bool arm_9e_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool); | |
68f932c4 | 154 | static bool arm_rtx_costs (rtx, int, int, int, int *, bool); |
f40751dd | 155 | static int arm_address_cost (rtx, bool); |
e32bac5b RE |
156 | static bool arm_memory_load_p (rtx); |
157 | static bool arm_cirrus_insn_p (rtx); | |
158 | static void cirrus_reorg (rtx); | |
5a9335ef | 159 | static void arm_init_builtins (void); |
5a9335ef NC |
160 | static void arm_init_iwmmxt_builtins (void); |
161 | static rtx safe_vector_operand (rtx, enum machine_mode); | |
162 | static rtx arm_expand_binop_builtin (enum insn_code, tree, rtx); | |
163 | static rtx arm_expand_unop_builtin (enum insn_code, tree, rtx, int); | |
164 | static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int); | |
229a1c59 | 165 | static tree arm_builtin_decl (unsigned, bool); |
a406f566 | 166 | static void emit_constant_insn (rtx cond, rtx pattern); |
d66437c5 | 167 | static rtx emit_set_insn (rtx, rtx); |
d5cc9181 | 168 | static int arm_arg_partial_bytes (cumulative_args_t, enum machine_mode, |
78a52f11 | 169 | tree, bool); |
d5cc9181 | 170 | static rtx arm_function_arg (cumulative_args_t, enum machine_mode, |
9c6a2bee | 171 | const_tree, bool); |
d5cc9181 | 172 | static void arm_function_arg_advance (cumulative_args_t, enum machine_mode, |
9c6a2bee | 173 | const_tree, bool); |
c2ed6cf8 | 174 | static unsigned int arm_function_arg_boundary (enum machine_mode, const_tree); |
390b17c2 RE |
175 | static rtx aapcs_allocate_return_reg (enum machine_mode, const_tree, |
176 | const_tree); | |
177 | static int aapcs_select_return_coproc (const_tree, const_tree); | |
5a9335ef | 178 | |
7abc66b1 | 179 | #ifdef OBJECT_FORMAT_ELF |
9403b7f7 RS |
180 | static void arm_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED; |
181 | static void arm_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED; | |
7abc66b1 | 182 | #endif |
fb49053f | 183 | #ifndef ARM_PE |
e32bac5b | 184 | static void arm_encode_section_info (tree, rtx, int); |
fb49053f | 185 | #endif |
b12a00f1 RE |
186 | |
187 | static void arm_file_end (void); | |
6c6aa1af | 188 | static void arm_file_start (void); |
b12a00f1 | 189 | |
d5cc9181 | 190 | static void arm_setup_incoming_varargs (cumulative_args_t, enum machine_mode, |
1cc9f5f5 | 191 | tree, int *, int); |
d5cc9181 | 192 | static bool arm_pass_by_reference (cumulative_args_t, |
586de218 KG |
193 | enum machine_mode, const_tree, bool); |
194 | static bool arm_promote_prototypes (const_tree); | |
6b045785 | 195 | static bool arm_default_short_enums (void); |
13c1cd82 | 196 | static bool arm_align_anon_bitfield (void); |
586de218 KG |
197 | static bool arm_return_in_msb (const_tree); |
198 | static bool arm_must_pass_in_stack (enum machine_mode, const_tree); | |
23668cf7 | 199 | static bool arm_return_in_memory (const_tree, const_tree); |
f0a0390e | 200 | #if ARM_UNWIND_INFO |
617a1b71 PB |
201 | static void arm_unwind_emit (FILE *, rtx); |
202 | static bool arm_output_ttype (rtx); | |
a68b5e52 RH |
203 | static void arm_asm_emit_except_personality (rtx); |
204 | static void arm_asm_init_sections (void); | |
617a1b71 | 205 | #endif |
854b8a40 | 206 | static rtx arm_dwarf_register_span (rtx); |
c237e94a | 207 | |
4185ae53 PB |
208 | static tree arm_cxx_guard_type (void); |
209 | static bool arm_cxx_guard_mask_bit (void); | |
46e995e0 PB |
210 | static tree arm_get_cookie_size (tree); |
211 | static bool arm_cookie_has_size (void); | |
44d10c10 | 212 | static bool arm_cxx_cdtor_returns_this (void); |
505970fc | 213 | static bool arm_cxx_key_method_may_be_inline (void); |
1e731102 MM |
214 | static void arm_cxx_determine_class_data_visibility (tree); |
215 | static bool arm_cxx_class_data_always_comdat (void); | |
9f62c3e3 | 216 | static bool arm_cxx_use_aeabi_atexit (void); |
b3f8d95d | 217 | static void arm_init_libfuncs (void); |
07d8efe3 MM |
218 | static tree arm_build_builtin_va_list (void); |
219 | static void arm_expand_builtin_va_start (tree, rtx); | |
ae46a823 | 220 | static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *); |
c5387660 | 221 | static void arm_option_override (void); |
273a2526 | 222 | static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode); |
d3585b76 DJ |
223 | static bool arm_cannot_copy_insn_p (rtx); |
224 | static bool arm_tls_symbol_p (rtx x); | |
bd4dc3cd | 225 | static int arm_issue_rate (void); |
afcc986d | 226 | static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED; |
ffda8a0d | 227 | static bool arm_output_addr_const_extra (FILE *, rtx); |
007e61c2 | 228 | static bool arm_allocate_stack_slots_for_args (void); |
0fd8c3ad SL |
229 | static const char *arm_invalid_parameter_type (const_tree t); |
230 | static const char *arm_invalid_return_type (const_tree t); | |
231 | static tree arm_promoted_type (const_tree t); | |
232 | static tree arm_convert_to_type (tree type, tree expr); | |
bdc4827b | 233 | static bool arm_scalar_mode_supported_p (enum machine_mode); |
b52b1749 | 234 | static bool arm_frame_pointer_required (void); |
7b5cbb57 | 235 | static bool arm_can_eliminate (const int, const int); |
0ef9304b RH |
236 | static void arm_asm_trampoline_template (FILE *); |
237 | static void arm_trampoline_init (rtx, tree, rtx); | |
238 | static rtx arm_trampoline_adjust_address (rtx); | |
85c9bcd4 | 239 | static rtx arm_pic_static_addr (rtx orig, rtx reg); |
b0c13111 RR |
240 | static bool cortex_a9_sched_adjust_cost (rtx, rtx, rtx, int *); |
241 | static bool xscale_sched_adjust_cost (rtx, rtx, rtx, int *); | |
c02a5ccb | 242 | static bool fa726te_sched_adjust_cost (rtx, rtx, rtx, int *); |
0f6d54f7 RS |
243 | static bool arm_array_mode_supported_p (enum machine_mode, |
244 | unsigned HOST_WIDE_INT); | |
cc4b5170 | 245 | static enum machine_mode arm_preferred_simd_mode (enum machine_mode); |
d163e655 | 246 | static bool arm_class_likely_spilled_p (reg_class_t); |
c452684d JB |
247 | static bool arm_vector_alignment_reachable (const_tree type, bool is_packed); |
248 | static bool arm_builtin_support_vector_misalignment (enum machine_mode mode, | |
249 | const_tree type, | |
250 | int misalignment, | |
251 | bool is_packed); | |
5efd84c5 | 252 | static void arm_conditional_register_usage (void); |
6d3fbe2f | 253 | static reg_class_t arm_preferred_rename_class (reg_class_t rclass); |
69d52339 | 254 | static unsigned int arm_autovectorize_vector_sizes (void); |
153668ec | 255 | static int arm_default_branch_cost (bool, bool); |
288f605f | 256 | static int arm_cortex_a5_branch_cost (bool, bool); |
b52b1749 | 257 | |
5a82ecd9 ILT |
258 | \f |
259 | /* Table of machine attributes. */ | |
260 | static const struct attribute_spec arm_attribute_table[] = | |
261 | { | |
62d784f7 KT |
262 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler, |
263 | affects_type_identity } */ | |
5a82ecd9 ILT |
264 | /* Function calls made to this symbol must be done indirectly, because |
265 | it may lie outside of the 26 bit addressing range of a normal function | |
266 | call. */ | |
62d784f7 | 267 | { "long_call", 0, 0, false, true, true, NULL, false }, |
5a82ecd9 ILT |
268 | /* Whereas these functions are always known to reside within the 26 bit |
269 | addressing range. */ | |
62d784f7 | 270 | { "short_call", 0, 0, false, true, true, NULL, false }, |
390b17c2 | 271 | /* Specify the procedure call conventions for a function. */ |
62d784f7 KT |
272 | { "pcs", 1, 1, false, true, true, arm_handle_pcs_attribute, |
273 | false }, | |
5a82ecd9 | 274 | /* Interrupt Service Routines have special prologue and epilogue requirements. */ |
62d784f7 KT |
275 | { "isr", 0, 1, false, false, false, arm_handle_isr_attribute, |
276 | false }, | |
277 | { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute, | |
278 | false }, | |
279 | { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute, | |
280 | false }, | |
5a82ecd9 ILT |
281 | #ifdef ARM_PE |
282 | /* ARM/PE has three new attributes: | |
283 | interfacearm - ? | |
284 | dllexport - for exporting a function/variable that will live in a dll | |
285 | dllimport - for importing a function/variable from a dll | |
d3585b76 | 286 | |
5a82ecd9 ILT |
287 | Microsoft allows multiple declspecs in one __declspec, separating |
288 | them with spaces. We do NOT support this. Instead, use __declspec | |
289 | multiple times. | |
290 | */ | |
62d784f7 KT |
291 | { "dllimport", 0, 0, true, false, false, NULL, false }, |
292 | { "dllexport", 0, 0, true, false, false, NULL, false }, | |
293 | { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute, | |
294 | false }, | |
5a82ecd9 | 295 | #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES |
62d784f7 KT |
296 | { "dllimport", 0, 0, false, false, false, handle_dll_attribute, false }, |
297 | { "dllexport", 0, 0, false, false, false, handle_dll_attribute, false }, | |
298 | { "notshared", 0, 0, false, true, false, arm_handle_notshared_attribute, | |
299 | false }, | |
5a82ecd9 | 300 | #endif |
62d784f7 | 301 | { NULL, 0, 0, false, false, false, NULL, false } |
5a82ecd9 | 302 | }; |
672a6f42 NB |
303 | \f |
304 | /* Initialize the GCC target structure. */ | |
b2ca3702 | 305 | #if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
1d6e90ac | 306 | #undef TARGET_MERGE_DECL_ATTRIBUTES |
672a6f42 NB |
307 | #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes |
308 | #endif | |
f3bb6135 | 309 | |
506d7b68 PB |
310 | #undef TARGET_LEGITIMIZE_ADDRESS |
311 | #define TARGET_LEGITIMIZE_ADDRESS arm_legitimize_address | |
312 | ||
1d6e90ac | 313 | #undef TARGET_ATTRIBUTE_TABLE |
91d231cb | 314 | #define TARGET_ATTRIBUTE_TABLE arm_attribute_table |
672a6f42 | 315 | |
6c6aa1af PB |
316 | #undef TARGET_ASM_FILE_START |
317 | #define TARGET_ASM_FILE_START arm_file_start | |
b12a00f1 RE |
318 | #undef TARGET_ASM_FILE_END |
319 | #define TARGET_ASM_FILE_END arm_file_end | |
320 | ||
1d6e90ac | 321 | #undef TARGET_ASM_ALIGNED_SI_OP |
301d03af | 322 | #define TARGET_ASM_ALIGNED_SI_OP NULL |
1d6e90ac | 323 | #undef TARGET_ASM_INTEGER |
301d03af | 324 | #define TARGET_ASM_INTEGER arm_assemble_integer |
301d03af | 325 | |
944442bb NF |
326 | #undef TARGET_PRINT_OPERAND |
327 | #define TARGET_PRINT_OPERAND arm_print_operand | |
328 | #undef TARGET_PRINT_OPERAND_ADDRESS | |
329 | #define TARGET_PRINT_OPERAND_ADDRESS arm_print_operand_address | |
330 | #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P | |
331 | #define TARGET_PRINT_OPERAND_PUNCT_VALID_P arm_print_operand_punct_valid_p | |
332 | ||
ffda8a0d AS |
333 | #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA |
334 | #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA arm_output_addr_const_extra | |
335 | ||
1d6e90ac | 336 | #undef TARGET_ASM_FUNCTION_PROLOGUE |
08c148a8 NB |
337 | #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue |
338 | ||
1d6e90ac | 339 | #undef TARGET_ASM_FUNCTION_EPILOGUE |
08c148a8 NB |
340 | #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue |
341 | ||
c5387660 JM |
342 | #undef TARGET_OPTION_OVERRIDE |
343 | #define TARGET_OPTION_OVERRIDE arm_option_override | |
c54c7322 | 344 | |
1d6e90ac | 345 | #undef TARGET_COMP_TYPE_ATTRIBUTES |
8d8e52be JM |
346 | #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes |
347 | ||
1d6e90ac | 348 | #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES |
8d8e52be JM |
349 | #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes |
350 | ||
1d6e90ac | 351 | #undef TARGET_SCHED_ADJUST_COST |
c237e94a ZW |
352 | #define TARGET_SCHED_ADJUST_COST arm_adjust_cost |
353 | ||
fb49053f RH |
354 | #undef TARGET_ENCODE_SECTION_INFO |
355 | #ifdef ARM_PE | |
356 | #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info | |
357 | #else | |
358 | #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info | |
359 | #endif | |
360 | ||
5a9335ef | 361 | #undef TARGET_STRIP_NAME_ENCODING |
772c5265 RH |
362 | #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding |
363 | ||
5a9335ef | 364 | #undef TARGET_ASM_INTERNAL_LABEL |
4977bab6 ZW |
365 | #define TARGET_ASM_INTERNAL_LABEL arm_internal_label |
366 | ||
5a9335ef | 367 | #undef TARGET_FUNCTION_OK_FOR_SIBCALL |
4977bab6 ZW |
368 | #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall |
369 | ||
390b17c2 RE |
370 | #undef TARGET_FUNCTION_VALUE |
371 | #define TARGET_FUNCTION_VALUE arm_function_value | |
372 | ||
373 | #undef TARGET_LIBCALL_VALUE | |
374 | #define TARGET_LIBCALL_VALUE arm_libcall_value | |
375 | ||
5a9335ef | 376 | #undef TARGET_ASM_OUTPUT_MI_THUNK |
c590b625 | 377 | #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk |
5a9335ef | 378 | #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK |
3961e8fe | 379 | #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall |
c590b625 | 380 | |
5a9335ef | 381 | #undef TARGET_RTX_COSTS |
f40751dd | 382 | #define TARGET_RTX_COSTS arm_rtx_costs |
5a9335ef | 383 | #undef TARGET_ADDRESS_COST |
dcefdf67 | 384 | #define TARGET_ADDRESS_COST arm_address_cost |
3c50106f | 385 | |
273a2526 RS |
386 | #undef TARGET_SHIFT_TRUNCATION_MASK |
387 | #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask | |
f676971a EC |
388 | #undef TARGET_VECTOR_MODE_SUPPORTED_P |
389 | #define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p | |
0f6d54f7 RS |
390 | #undef TARGET_ARRAY_MODE_SUPPORTED_P |
391 | #define TARGET_ARRAY_MODE_SUPPORTED_P arm_array_mode_supported_p | |
cc4b5170 RG |
392 | #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE |
393 | #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE arm_preferred_simd_mode | |
69d52339 IR |
394 | #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES |
395 | #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES \ | |
396 | arm_autovectorize_vector_sizes | |
f676971a | 397 | |
5a9335ef | 398 | #undef TARGET_MACHINE_DEPENDENT_REORG |
18dbd950 RS |
399 | #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg |
400 | ||
5a9335ef NC |
401 | #undef TARGET_INIT_BUILTINS |
402 | #define TARGET_INIT_BUILTINS arm_init_builtins | |
403 | #undef TARGET_EXPAND_BUILTIN | |
404 | #define TARGET_EXPAND_BUILTIN arm_expand_builtin | |
229a1c59 JZ |
405 | #undef TARGET_BUILTIN_DECL |
406 | #define TARGET_BUILTIN_DECL arm_builtin_decl | |
5a9335ef | 407 | |
b3f8d95d MM |
408 | #undef TARGET_INIT_LIBFUNCS |
409 | #define TARGET_INIT_LIBFUNCS arm_init_libfuncs | |
410 | ||
cde0f3fd PB |
411 | #undef TARGET_PROMOTE_FUNCTION_MODE |
412 | #define TARGET_PROMOTE_FUNCTION_MODE arm_promote_function_mode | |
f9ba5949 | 413 | #undef TARGET_PROMOTE_PROTOTYPES |
70301b45 | 414 | #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes |
8cd5a4e0 RH |
415 | #undef TARGET_PASS_BY_REFERENCE |
416 | #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference | |
78a52f11 RH |
417 | #undef TARGET_ARG_PARTIAL_BYTES |
418 | #define TARGET_ARG_PARTIAL_BYTES arm_arg_partial_bytes | |
9c6a2bee NF |
419 | #undef TARGET_FUNCTION_ARG |
420 | #define TARGET_FUNCTION_ARG arm_function_arg | |
421 | #undef TARGET_FUNCTION_ARG_ADVANCE | |
422 | #define TARGET_FUNCTION_ARG_ADVANCE arm_function_arg_advance | |
c2ed6cf8 NF |
423 | #undef TARGET_FUNCTION_ARG_BOUNDARY |
424 | #define TARGET_FUNCTION_ARG_BOUNDARY arm_function_arg_boundary | |
f9ba5949 | 425 | |
1cc9f5f5 KH |
426 | #undef TARGET_SETUP_INCOMING_VARARGS |
427 | #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs | |
428 | ||
007e61c2 PB |
429 | #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS |
430 | #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args | |
431 | ||
0ef9304b RH |
432 | #undef TARGET_ASM_TRAMPOLINE_TEMPLATE |
433 | #define TARGET_ASM_TRAMPOLINE_TEMPLATE arm_asm_trampoline_template | |
434 | #undef TARGET_TRAMPOLINE_INIT | |
435 | #define TARGET_TRAMPOLINE_INIT arm_trampoline_init | |
436 | #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS | |
437 | #define TARGET_TRAMPOLINE_ADJUST_ADDRESS arm_trampoline_adjust_address | |
438 | ||
6b045785 PB |
439 | #undef TARGET_DEFAULT_SHORT_ENUMS |
440 | #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums | |
441 | ||
13c1cd82 PB |
442 | #undef TARGET_ALIGN_ANON_BITFIELD |
443 | #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield | |
444 | ||
c2a64439 PB |
445 | #undef TARGET_NARROW_VOLATILE_BITFIELD |
446 | #define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false | |
447 | ||
4185ae53 PB |
448 | #undef TARGET_CXX_GUARD_TYPE |
449 | #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type | |
450 | ||
451 | #undef TARGET_CXX_GUARD_MASK_BIT | |
452 | #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit | |
453 | ||
46e995e0 PB |
454 | #undef TARGET_CXX_GET_COOKIE_SIZE |
455 | #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size | |
456 | ||
457 | #undef TARGET_CXX_COOKIE_HAS_SIZE | |
458 | #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size | |
459 | ||
44d10c10 PB |
460 | #undef TARGET_CXX_CDTOR_RETURNS_THIS |
461 | #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this | |
462 | ||
505970fc MM |
463 | #undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE |
464 | #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline | |
465 | ||
9f62c3e3 PB |
466 | #undef TARGET_CXX_USE_AEABI_ATEXIT |
467 | #define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit | |
468 | ||
1e731102 MM |
469 | #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY |
470 | #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \ | |
471 | arm_cxx_determine_class_data_visibility | |
472 | ||
473 | #undef TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT | |
474 | #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT arm_cxx_class_data_always_comdat | |
505970fc | 475 | |
866af8a9 JB |
476 | #undef TARGET_RETURN_IN_MSB |
477 | #define TARGET_RETURN_IN_MSB arm_return_in_msb | |
478 | ||
23668cf7 CLT |
479 | #undef TARGET_RETURN_IN_MEMORY |
480 | #define TARGET_RETURN_IN_MEMORY arm_return_in_memory | |
481 | ||
866af8a9 JB |
482 | #undef TARGET_MUST_PASS_IN_STACK |
483 | #define TARGET_MUST_PASS_IN_STACK arm_must_pass_in_stack | |
484 | ||
f0a0390e | 485 | #if ARM_UNWIND_INFO |
38f8b050 JR |
486 | #undef TARGET_ASM_UNWIND_EMIT |
487 | #define TARGET_ASM_UNWIND_EMIT arm_unwind_emit | |
617a1b71 PB |
488 | |
489 | /* EABI unwinding tables use a different format for the typeinfo tables. */ | |
490 | #undef TARGET_ASM_TTYPE | |
491 | #define TARGET_ASM_TTYPE arm_output_ttype | |
492 | ||
493 | #undef TARGET_ARM_EABI_UNWINDER | |
494 | #define TARGET_ARM_EABI_UNWINDER true | |
a68b5e52 RH |
495 | |
496 | #undef TARGET_ASM_EMIT_EXCEPT_PERSONALITY | |
497 | #define TARGET_ASM_EMIT_EXCEPT_PERSONALITY arm_asm_emit_except_personality | |
498 | ||
499 | #undef TARGET_ASM_INIT_SECTIONS | |
500 | #define TARGET_ASM_INIT_SECTIONS arm_asm_init_sections | |
f0a0390e RH |
501 | #endif /* ARM_UNWIND_INFO */ |
502 | ||
854b8a40 JB |
503 | #undef TARGET_DWARF_REGISTER_SPAN |
504 | #define TARGET_DWARF_REGISTER_SPAN arm_dwarf_register_span | |
505 | ||
d3585b76 DJ |
506 | #undef TARGET_CANNOT_COPY_INSN_P |
507 | #define TARGET_CANNOT_COPY_INSN_P arm_cannot_copy_insn_p | |
508 | ||
509 | #ifdef HAVE_AS_TLS | |
510 | #undef TARGET_HAVE_TLS | |
511 | #define TARGET_HAVE_TLS true | |
512 | #endif | |
513 | ||
2929029c WG |
514 | #undef TARGET_HAVE_CONDITIONAL_EXECUTION |
515 | #define TARGET_HAVE_CONDITIONAL_EXECUTION arm_have_conditional_execution | |
516 | ||
1a627b35 RS |
517 | #undef TARGET_LEGITIMATE_CONSTANT_P |
518 | #define TARGET_LEGITIMATE_CONSTANT_P arm_legitimate_constant_p | |
519 | ||
d3585b76 | 520 | #undef TARGET_CANNOT_FORCE_CONST_MEM |
8426b956 | 521 | #define TARGET_CANNOT_FORCE_CONST_MEM arm_cannot_force_const_mem |
d3585b76 | 522 | |
f67358da PB |
523 | #undef TARGET_MAX_ANCHOR_OFFSET |
524 | #define TARGET_MAX_ANCHOR_OFFSET 4095 | |
525 | ||
526 | /* The minimum is set such that the total size of the block | |
527 | for a particular anchor is -4088 + 1 + 4095 bytes, which is | |
528 | divisible by eight, ensuring natural spacing of anchors. */ | |
529 | #undef TARGET_MIN_ANCHOR_OFFSET | |
530 | #define TARGET_MIN_ANCHOR_OFFSET -4088 | |
531 | ||
bd4dc3cd PB |
532 | #undef TARGET_SCHED_ISSUE_RATE |
533 | #define TARGET_SCHED_ISSUE_RATE arm_issue_rate | |
534 | ||
608063c3 JB |
535 | #undef TARGET_MANGLE_TYPE |
536 | #define TARGET_MANGLE_TYPE arm_mangle_type | |
537 | ||
07d8efe3 MM |
538 | #undef TARGET_BUILD_BUILTIN_VA_LIST |
539 | #define TARGET_BUILD_BUILTIN_VA_LIST arm_build_builtin_va_list | |
540 | #undef TARGET_EXPAND_BUILTIN_VA_START | |
541 | #define TARGET_EXPAND_BUILTIN_VA_START arm_expand_builtin_va_start | |
542 | #undef TARGET_GIMPLIFY_VA_ARG_EXPR | |
543 | #define TARGET_GIMPLIFY_VA_ARG_EXPR arm_gimplify_va_arg_expr | |
544 | ||
afcc986d JM |
545 | #ifdef HAVE_AS_TLS |
546 | #undef TARGET_ASM_OUTPUT_DWARF_DTPREL | |
547 | #define TARGET_ASM_OUTPUT_DWARF_DTPREL arm_output_dwarf_dtprel | |
548 | #endif | |
549 | ||
c6c3dba9 PB |
550 | #undef TARGET_LEGITIMATE_ADDRESS_P |
551 | #define TARGET_LEGITIMATE_ADDRESS_P arm_legitimate_address_p | |
552 | ||
0fd8c3ad SL |
553 | #undef TARGET_INVALID_PARAMETER_TYPE |
554 | #define TARGET_INVALID_PARAMETER_TYPE arm_invalid_parameter_type | |
555 | ||
556 | #undef TARGET_INVALID_RETURN_TYPE | |
557 | #define TARGET_INVALID_RETURN_TYPE arm_invalid_return_type | |
558 | ||
559 | #undef TARGET_PROMOTED_TYPE | |
560 | #define TARGET_PROMOTED_TYPE arm_promoted_type | |
561 | ||
562 | #undef TARGET_CONVERT_TO_TYPE | |
563 | #define TARGET_CONVERT_TO_TYPE arm_convert_to_type | |
564 | ||
bdc4827b SL |
565 | #undef TARGET_SCALAR_MODE_SUPPORTED_P |
566 | #define TARGET_SCALAR_MODE_SUPPORTED_P arm_scalar_mode_supported_p | |
567 | ||
b52b1749 AS |
568 | #undef TARGET_FRAME_POINTER_REQUIRED |
569 | #define TARGET_FRAME_POINTER_REQUIRED arm_frame_pointer_required | |
570 | ||
7b5cbb57 AS |
571 | #undef TARGET_CAN_ELIMINATE |
572 | #define TARGET_CAN_ELIMINATE arm_can_eliminate | |
573 | ||
5efd84c5 NF |
574 | #undef TARGET_CONDITIONAL_REGISTER_USAGE |
575 | #define TARGET_CONDITIONAL_REGISTER_USAGE arm_conditional_register_usage | |
576 | ||
d163e655 AS |
577 | #undef TARGET_CLASS_LIKELY_SPILLED_P |
578 | #define TARGET_CLASS_LIKELY_SPILLED_P arm_class_likely_spilled_p | |
579 | ||
c452684d JB |
580 | #undef TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE |
581 | #define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE \ | |
582 | arm_vector_alignment_reachable | |
583 | ||
584 | #undef TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT | |
585 | #define TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT \ | |
586 | arm_builtin_support_vector_misalignment | |
587 | ||
74e32076 YQ |
588 | #undef TARGET_PREFERRED_RENAME_CLASS |
589 | #define TARGET_PREFERRED_RENAME_CLASS \ | |
590 | arm_preferred_rename_class | |
591 | ||
f6897b10 | 592 | struct gcc_target targetm = TARGET_INITIALIZER; |
672a6f42 | 593 | \f |
c7319d87 RE |
594 | /* Obstack for minipool constant handling. */ |
595 | static struct obstack minipool_obstack; | |
1d6e90ac | 596 | static char * minipool_startobj; |
c7319d87 | 597 | |
1d6e90ac NC |
598 | /* The maximum number of insns skipped which |
599 | will be conditionalised if possible. */ | |
c27ba912 DM |
600 | static int max_insns_skipped = 5; |
601 | ||
602 | extern FILE * asm_out_file; | |
603 | ||
6354dc9b | 604 | /* True if we are currently building a constant table. */ |
13bd191d PB |
605 | int making_const_table; |
606 | ||
9b66ebb1 PB |
607 | /* The processor for which instructions should be scheduled. */ |
608 | enum processor_type arm_tune = arm_none; | |
609 | ||
1b78f575 RE |
610 | /* The current tuning set. */ |
611 | const struct tune_params *current_tune; | |
612 | ||
9b66ebb1 | 613 | /* Which floating point hardware to schedule for. */ |
d79f3032 PB |
614 | int arm_fpu_attr; |
615 | ||
616 | /* Which floating popint hardware to use. */ | |
617 | const struct arm_fpu_desc *arm_fpu_desc; | |
9b66ebb1 | 618 | |
b12a00f1 | 619 | /* Used for Thumb call_via trampolines. */ |
57ecec57 | 620 | rtx thumb_call_via_label[14]; |
b12a00f1 RE |
621 | static int thumb_call_reg_needed; |
622 | ||
aec3cfba | 623 | /* Bit values used to identify processor capabilities. */ |
62b10bbc | 624 | #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */ |
9b66ebb1 | 625 | #define FL_ARCH3M (1 << 1) /* Extended multiply */ |
62b10bbc NC |
626 | #define FL_MODE26 (1 << 2) /* 26-bit mode support */ |
627 | #define FL_MODE32 (1 << 3) /* 32-bit mode support */ | |
628 | #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */ | |
629 | #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */ | |
630 | #define FL_THUMB (1 << 6) /* Thumb aware */ | |
631 | #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */ | |
632 | #define FL_STRONG (1 << 8) /* StrongARM */ | |
6bc82793 | 633 | #define FL_ARCH5E (1 << 9) /* DSP extensions to v5 */ |
d19fb8e3 | 634 | #define FL_XSCALE (1 << 10) /* XScale */ |
9b6b54e2 | 635 | #define FL_CIRRUS (1 << 11) /* Cirrus/DSP. */ |
9b66ebb1 | 636 | #define FL_ARCH6 (1 << 12) /* Architecture rel 6. Adds |
81f9037c MM |
637 | media instructions. */ |
638 | #define FL_VFPV2 (1 << 13) /* Vector Floating Point V2. */ | |
abac3b49 RE |
639 | #define FL_WBUF (1 << 14) /* Schedule for write buffer ops. |
640 | Note: ARM6 & 7 derivatives only. */ | |
d3585b76 | 641 | #define FL_ARCH6K (1 << 15) /* Architecture rel 6 K extensions. */ |
5b3e6663 PB |
642 | #define FL_THUMB2 (1 << 16) /* Thumb-2. */ |
643 | #define FL_NOTM (1 << 17) /* Instructions not present in the 'M' | |
644 | profile. */ | |
572070ef | 645 | #define FL_THUMB_DIV (1 << 18) /* Hardware divide (Thumb mode). */ |
f1adb0a9 | 646 | #define FL_VFPV3 (1 << 19) /* Vector Floating Point V3. */ |
88f77cba | 647 | #define FL_NEON (1 << 20) /* Neon instructions. */ |
60bd3528 PB |
648 | #define FL_ARCH7EM (1 << 21) /* Instructions present in the ARMv7E-M |
649 | architecture. */ | |
029e79eb | 650 | #define FL_ARCH7 (1 << 22) /* Architecture 7. */ |
572070ef | 651 | #define FL_ARM_DIV (1 << 23) /* Hardware divide (ARM mode). */ |
aec3cfba | 652 | |
9b66ebb1 PB |
653 | #define FL_IWMMXT (1 << 29) /* XScale v2 or "Intel Wireless MMX technology". */ |
654 | ||
12a0a4d4 PB |
655 | /* Flags that only effect tuning, not available instructions. */ |
656 | #define FL_TUNE (FL_WBUF | FL_VFPV2 | FL_STRONG | FL_LDSCHED \ | |
657 | | FL_CO_PROC) | |
658 | ||
5b3e6663 PB |
659 | #define FL_FOR_ARCH2 FL_NOTM |
660 | #define FL_FOR_ARCH3 (FL_FOR_ARCH2 | FL_MODE32) | |
78011587 PB |
661 | #define FL_FOR_ARCH3M (FL_FOR_ARCH3 | FL_ARCH3M) |
662 | #define FL_FOR_ARCH4 (FL_FOR_ARCH3M | FL_ARCH4) | |
663 | #define FL_FOR_ARCH4T (FL_FOR_ARCH4 | FL_THUMB) | |
664 | #define FL_FOR_ARCH5 (FL_FOR_ARCH4 | FL_ARCH5) | |
665 | #define FL_FOR_ARCH5T (FL_FOR_ARCH5 | FL_THUMB) | |
666 | #define FL_FOR_ARCH5E (FL_FOR_ARCH5 | FL_ARCH5E) | |
667 | #define FL_FOR_ARCH5TE (FL_FOR_ARCH5E | FL_THUMB) | |
668 | #define FL_FOR_ARCH5TEJ FL_FOR_ARCH5TE | |
669 | #define FL_FOR_ARCH6 (FL_FOR_ARCH5TE | FL_ARCH6) | |
670 | #define FL_FOR_ARCH6J FL_FOR_ARCH6 | |
d3585b76 | 671 | #define FL_FOR_ARCH6K (FL_FOR_ARCH6 | FL_ARCH6K) |
fa91adc6 | 672 | #define FL_FOR_ARCH6Z FL_FOR_ARCH6 |
d3585b76 | 673 | #define FL_FOR_ARCH6ZK FL_FOR_ARCH6K |
5b3e6663 | 674 | #define FL_FOR_ARCH6T2 (FL_FOR_ARCH6 | FL_THUMB2) |
bf98ec6c | 675 | #define FL_FOR_ARCH6M (FL_FOR_ARCH6 & ~FL_NOTM) |
029e79eb | 676 | #define FL_FOR_ARCH7 ((FL_FOR_ARCH6T2 & ~FL_NOTM) | FL_ARCH7) |
87d05b44 | 677 | #define FL_FOR_ARCH7A (FL_FOR_ARCH7 | FL_NOTM | FL_ARCH6K) |
572070ef PB |
678 | #define FL_FOR_ARCH7R (FL_FOR_ARCH7A | FL_THUMB_DIV) |
679 | #define FL_FOR_ARCH7M (FL_FOR_ARCH7 | FL_THUMB_DIV) | |
60bd3528 | 680 | #define FL_FOR_ARCH7EM (FL_FOR_ARCH7M | FL_ARCH7EM) |
78011587 | 681 | |
1d6e90ac NC |
682 | /* The bits in this mask specify which |
683 | instructions we are allowed to generate. */ | |
0977774b | 684 | static unsigned long insn_flags = 0; |
d5b7b3ae | 685 | |
aec3cfba | 686 | /* The bits in this mask specify which instruction scheduling options should |
9b66ebb1 | 687 | be used. */ |
0977774b | 688 | static unsigned long tune_flags = 0; |
aec3cfba NC |
689 | |
690 | /* The following are used in the arm.md file as equivalents to bits | |
691 | in the above two flag variables. */ | |
692 | ||
9b66ebb1 PB |
693 | /* Nonzero if this chip supports the ARM Architecture 3M extensions. */ |
694 | int arm_arch3m = 0; | |
2b835d68 | 695 | |
6354dc9b | 696 | /* Nonzero if this chip supports the ARM Architecture 4 extensions. */ |
2b835d68 RE |
697 | int arm_arch4 = 0; |
698 | ||
68d560d4 RE |
699 | /* Nonzero if this chip supports the ARM Architecture 4t extensions. */ |
700 | int arm_arch4t = 0; | |
701 | ||
6354dc9b | 702 | /* Nonzero if this chip supports the ARM Architecture 5 extensions. */ |
62b10bbc NC |
703 | int arm_arch5 = 0; |
704 | ||
b15bca31 RE |
705 | /* Nonzero if this chip supports the ARM Architecture 5E extensions. */ |
706 | int arm_arch5e = 0; | |
707 | ||
9b66ebb1 PB |
708 | /* Nonzero if this chip supports the ARM Architecture 6 extensions. */ |
709 | int arm_arch6 = 0; | |
710 | ||
d3585b76 DJ |
711 | /* Nonzero if this chip supports the ARM 6K extensions. */ |
712 | int arm_arch6k = 0; | |
713 | ||
029e79eb MS |
714 | /* Nonzero if this chip supports the ARM 7 extensions. */ |
715 | int arm_arch7 = 0; | |
716 | ||
5b3e6663 PB |
717 | /* Nonzero if instructions not present in the 'M' profile can be used. */ |
718 | int arm_arch_notm = 0; | |
719 | ||
60bd3528 PB |
720 | /* Nonzero if instructions present in ARMv7E-M can be used. */ |
721 | int arm_arch7em = 0; | |
722 | ||
aec3cfba | 723 | /* Nonzero if this chip can benefit from load scheduling. */ |
f5a1b0d2 NC |
724 | int arm_ld_sched = 0; |
725 | ||
726 | /* Nonzero if this chip is a StrongARM. */ | |
abac3b49 | 727 | int arm_tune_strongarm = 0; |
f5a1b0d2 | 728 | |
78011587 PB |
729 | /* Nonzero if this chip is a Cirrus variant. */ |
730 | int arm_arch_cirrus = 0; | |
731 | ||
5a9335ef NC |
732 | /* Nonzero if this chip supports Intel Wireless MMX technology. */ |
733 | int arm_arch_iwmmxt = 0; | |
734 | ||
d19fb8e3 | 735 | /* Nonzero if this chip is an XScale. */ |
4b3c2e48 PB |
736 | int arm_arch_xscale = 0; |
737 | ||
738 | /* Nonzero if tuning for XScale */ | |
739 | int arm_tune_xscale = 0; | |
d19fb8e3 | 740 | |
e0b92319 | 741 | /* Nonzero if we want to tune for stores that access the write-buffer. |
c5d34bb2 | 742 | This typically means an ARM6 or ARM7 with MMU or MPU. */ |
abac3b49 | 743 | int arm_tune_wbuf = 0; |
b111229a | 744 | |
7612f14d PB |
745 | /* Nonzero if tuning for Cortex-A9. */ |
746 | int arm_tune_cortex_a9 = 0; | |
747 | ||
0616531f RE |
748 | /* Nonzero if generating Thumb instructions. */ |
749 | int thumb_code = 0; | |
750 | ||
906668bb BS |
751 | /* Nonzero if generating Thumb-1 instructions. */ |
752 | int thumb1_code = 0; | |
753 | ||
2ad4dcf9 | 754 | /* Nonzero if we should define __THUMB_INTERWORK__ in the |
f676971a | 755 | preprocessor. |
2ad4dcf9 RE |
756 | XXX This is a bit of a hack, it's intended to help work around |
757 | problems in GLD which doesn't understand that armv5t code is | |
758 | interworking clean. */ | |
759 | int arm_cpp_interwork = 0; | |
760 | ||
5b3e6663 PB |
761 | /* Nonzero if chip supports Thumb 2. */ |
762 | int arm_arch_thumb2; | |
763 | ||
764 | /* Nonzero if chip supports integer division instruction. */ | |
572070ef PB |
765 | int arm_arch_arm_hwdiv; |
766 | int arm_arch_thumb_hwdiv; | |
5b3e6663 | 767 | |
944442bb NF |
768 | /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, |
769 | we must report the mode of the memory reference from | |
770 | TARGET_PRINT_OPERAND to TARGET_PRINT_OPERAND_ADDRESS. */ | |
f3bb6135 | 771 | enum machine_mode output_memory_reference_mode; |
cce8749e | 772 | |
32de079a | 773 | /* The register number to be used for the PIC offset register. */ |
020a4035 | 774 | unsigned arm_pic_register = INVALID_REGNUM; |
32de079a | 775 | |
aec3cfba NC |
776 | /* Set to 1 after arm_reorg has started. Reset to start at the start of |
777 | the next function. */ | |
4b632bf1 RE |
778 | static int after_arm_reorg = 0; |
779 | ||
12ffc7d5 | 780 | enum arm_pcs arm_pcs_default; |
390b17c2 | 781 | |
cce8749e CH |
782 | /* For an explanation of these variables, see final_prescan_insn below. */ |
783 | int arm_ccfsm_state; | |
5b3e6663 | 784 | /* arm_current_cc is also used for Thumb-2 cond_exec blocks. */ |
84ed5e79 | 785 | enum arm_cond_code arm_current_cc; |
906668bb | 786 | |
cce8749e CH |
787 | rtx arm_target_insn; |
788 | int arm_target_label; | |
5b3e6663 PB |
789 | /* The number of conditionally executed insns, including the current insn. */ |
790 | int arm_condexec_count = 0; | |
791 | /* A bitmask specifying the patterns for the IT block. | |
792 | Zero means do not output an IT block before this insn. */ | |
793 | int arm_condexec_mask = 0; | |
794 | /* The number of bits used in arm_condexec_mask. */ | |
795 | int arm_condexec_masklen = 0; | |
9997d19d RE |
796 | |
797 | /* The condition codes of the ARM, and the inverse function. */ | |
1d6e90ac | 798 | static const char * const arm_condition_codes[] = |
9997d19d RE |
799 | { |
800 | "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc", | |
801 | "hi", "ls", "ge", "lt", "gt", "le", "al", "nv" | |
802 | }; | |
803 | ||
37119410 BS |
804 | /* The register numbers in sequence, for passing to arm_gen_load_multiple. */ |
805 | int arm_regs_in_sequence[] = | |
806 | { | |
807 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 | |
808 | }; | |
809 | ||
5b3e6663 | 810 | #define ARM_LSL_NAME (TARGET_UNIFIED_ASM ? "lsl" : "asl") |
f5a1b0d2 | 811 | #define streq(string1, string2) (strcmp (string1, string2) == 0) |
5b3e6663 PB |
812 | |
813 | #define THUMB2_WORK_REGS (0xff & ~( (1 << THUMB_HARD_FRAME_POINTER_REGNUM) \ | |
814 | | (1 << SP_REGNUM) | (1 << PC_REGNUM) \ | |
815 | | (1 << PIC_OFFSET_TABLE_REGNUM))) | |
2b835d68 | 816 | \f |
6354dc9b | 817 | /* Initialization code. */ |
2b835d68 | 818 | |
2b835d68 RE |
819 | struct processors |
820 | { | |
8b60264b | 821 | const char *const name; |
9b66ebb1 | 822 | enum processor_type core; |
78011587 | 823 | const char *arch; |
0977774b | 824 | const unsigned long flags; |
1b78f575 RE |
825 | const struct tune_params *const tune; |
826 | }; | |
827 | ||
911de8a3 IB |
828 | |
829 | #define ARM_PREFETCH_NOT_BENEFICIAL 0, -1, -1 | |
830 | #define ARM_PREFETCH_BENEFICIAL(prefetch_slots,l1_size,l1_line_size) \ | |
831 | prefetch_slots, \ | |
832 | l1_size, \ | |
833 | l1_line_size | |
834 | ||
1b78f575 RE |
835 | const struct tune_params arm_slowmul_tune = |
836 | { | |
837 | arm_slowmul_rtx_costs, | |
b0c13111 | 838 | NULL, |
7ec70105 | 839 | 3, /* Constant limit. */ |
16868d84 | 840 | 5, /* Max cond insns. */ |
7ec70105 | 841 | ARM_PREFETCH_NOT_BENEFICIAL, |
153668ec JB |
842 | true, /* Prefer constant pool. */ |
843 | arm_default_branch_cost | |
1b78f575 RE |
844 | }; |
845 | ||
846 | const struct tune_params arm_fastmul_tune = | |
847 | { | |
848 | arm_fastmul_rtx_costs, | |
b0c13111 | 849 | NULL, |
7ec70105 | 850 | 1, /* Constant limit. */ |
16868d84 JB |
851 | 5, /* Max cond insns. */ |
852 | ARM_PREFETCH_NOT_BENEFICIAL, | |
853 | true, /* Prefer constant pool. */ | |
854 | arm_default_branch_cost | |
855 | }; | |
856 | ||
857 | /* StrongARM has early execution of branches, so a sequence that is worth | |
858 | skipping is shorter. Set max_insns_skipped to a lower value. */ | |
859 | ||
860 | const struct tune_params arm_strongarm_tune = | |
861 | { | |
862 | arm_fastmul_rtx_costs, | |
863 | NULL, | |
864 | 1, /* Constant limit. */ | |
865 | 3, /* Max cond insns. */ | |
7ec70105 | 866 | ARM_PREFETCH_NOT_BENEFICIAL, |
153668ec JB |
867 | true, /* Prefer constant pool. */ |
868 | arm_default_branch_cost | |
1b78f575 RE |
869 | }; |
870 | ||
871 | const struct tune_params arm_xscale_tune = | |
872 | { | |
873 | arm_xscale_rtx_costs, | |
b0c13111 | 874 | xscale_sched_adjust_cost, |
7ec70105 | 875 | 2, /* Constant limit. */ |
16868d84 | 876 | 3, /* Max cond insns. */ |
7ec70105 | 877 | ARM_PREFETCH_NOT_BENEFICIAL, |
153668ec JB |
878 | true, /* Prefer constant pool. */ |
879 | arm_default_branch_cost | |
1b78f575 RE |
880 | }; |
881 | ||
882 | const struct tune_params arm_9e_tune = | |
883 | { | |
884 | arm_9e_rtx_costs, | |
b0c13111 | 885 | NULL, |
7ec70105 | 886 | 1, /* Constant limit. */ |
16868d84 | 887 | 5, /* Max cond insns. */ |
7ec70105 | 888 | ARM_PREFETCH_NOT_BENEFICIAL, |
153668ec JB |
889 | true, /* Prefer constant pool. */ |
890 | arm_default_branch_cost | |
7ec70105 JB |
891 | }; |
892 | ||
893 | const struct tune_params arm_v6t2_tune = | |
894 | { | |
895 | arm_9e_rtx_costs, | |
896 | NULL, | |
897 | 1, /* Constant limit. */ | |
16868d84 | 898 | 5, /* Max cond insns. */ |
7ec70105 | 899 | ARM_PREFETCH_NOT_BENEFICIAL, |
153668ec JB |
900 | false, /* Prefer constant pool. */ |
901 | arm_default_branch_cost | |
7ec70105 JB |
902 | }; |
903 | ||
904 | /* Generic Cortex tuning. Use more specific tunings if appropriate. */ | |
905 | const struct tune_params arm_cortex_tune = | |
906 | { | |
907 | arm_9e_rtx_costs, | |
908 | NULL, | |
909 | 1, /* Constant limit. */ | |
16868d84 | 910 | 5, /* Max cond insns. */ |
7ec70105 | 911 | ARM_PREFETCH_NOT_BENEFICIAL, |
153668ec JB |
912 | false, /* Prefer constant pool. */ |
913 | arm_default_branch_cost | |
2b835d68 RE |
914 | }; |
915 | ||
16868d84 JB |
916 | /* Branches can be dual-issued on Cortex-A5, so conditional execution is |
917 | less appealing. Set max_insns_skipped to a low value. */ | |
918 | ||
288f605f JB |
919 | const struct tune_params arm_cortex_a5_tune = |
920 | { | |
921 | arm_9e_rtx_costs, | |
922 | NULL, | |
923 | 1, /* Constant limit. */ | |
16868d84 | 924 | 1, /* Max cond insns. */ |
288f605f JB |
925 | ARM_PREFETCH_NOT_BENEFICIAL, |
926 | false, /* Prefer constant pool. */ | |
927 | arm_cortex_a5_branch_cost | |
928 | }; | |
929 | ||
b0c13111 RR |
930 | const struct tune_params arm_cortex_a9_tune = |
931 | { | |
932 | arm_9e_rtx_costs, | |
933 | cortex_a9_sched_adjust_cost, | |
7ec70105 | 934 | 1, /* Constant limit. */ |
16868d84 | 935 | 5, /* Max cond insns. */ |
7ec70105 | 936 | ARM_PREFETCH_BENEFICIAL(4,32,32), |
153668ec JB |
937 | false, /* Prefer constant pool. */ |
938 | arm_default_branch_cost | |
b0c13111 RR |
939 | }; |
940 | ||
c02a5ccb SL |
941 | const struct tune_params arm_fa726te_tune = |
942 | { | |
943 | arm_9e_rtx_costs, | |
944 | fa726te_sched_adjust_cost, | |
7ec70105 | 945 | 1, /* Constant limit. */ |
16868d84 | 946 | 5, /* Max cond insns. */ |
7ec70105 | 947 | ARM_PREFETCH_NOT_BENEFICIAL, |
153668ec JB |
948 | true, /* Prefer constant pool. */ |
949 | arm_default_branch_cost | |
c02a5ccb SL |
950 | }; |
951 | ||
b0c13111 | 952 | |
2b835d68 RE |
953 | /* Not all of these give usefully different compilation alternatives, |
954 | but there is no simple way of generalizing them. */ | |
8b60264b | 955 | static const struct processors all_cores[] = |
f5a1b0d2 NC |
956 | { |
957 | /* ARM Cores */ | |
d98a72fd | 958 | #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \ |
12a0a4d4 | 959 | {NAME, IDENT, #ARCH, FLAGS | FL_FOR_ARCH##ARCH, &arm_##COSTS##_tune}, |
9b66ebb1 PB |
960 | #include "arm-cores.def" |
961 | #undef ARM_CORE | |
78011587 | 962 | {NULL, arm_none, NULL, 0, NULL} |
f5a1b0d2 NC |
963 | }; |
964 | ||
8b60264b | 965 | static const struct processors all_architectures[] = |
2b835d68 | 966 | { |
f5a1b0d2 | 967 | /* ARM Architectures */ |
1b78f575 | 968 | /* We don't specify tuning costs here as it will be figured out |
9b66ebb1 | 969 | from the core. */ |
f676971a | 970 | |
ad7be009 JM |
971 | #define ARM_ARCH(NAME, CORE, ARCH, FLAGS) \ |
972 | {NAME, CORE, #ARCH, FLAGS, NULL}, | |
973 | #include "arm-arches.def" | |
974 | #undef ARM_ARCH | |
78011587 | 975 | {NULL, arm_none, NULL, 0 , NULL} |
f5a1b0d2 NC |
976 | }; |
977 | ||
f5a1b0d2 | 978 | |
12a0a4d4 PB |
979 | /* These are populated as commandline arguments are processed, or NULL |
980 | if not specified. */ | |
981 | static const struct processors *arm_selected_arch; | |
982 | static const struct processors *arm_selected_cpu; | |
983 | static const struct processors *arm_selected_tune; | |
78011587 | 984 | |
afc0a4ba | 985 | /* The name of the preprocessor macro to define for this architecture. */ |
78011587 PB |
986 | |
987 | char arm_arch_name[] = "__ARM_ARCH_0UNK__"; | |
988 | ||
56f42830 | 989 | /* Available values for -mfpu=. */ |
9b66ebb1 | 990 | |
d79f3032 PB |
991 | static const struct arm_fpu_desc all_fpus[] = |
992 | { | |
12d844c8 JM |
993 | #define ARM_FPU(NAME, MODEL, REV, VFP_REGS, NEON, FP16) \ |
994 | { NAME, MODEL, REV, VFP_REGS, NEON, FP16 }, | |
995 | #include "arm-fpus.def" | |
996 | #undef ARM_FPU | |
9b66ebb1 PB |
997 | }; |
998 | ||
999 | ||
d3585b76 DJ |
1000 | /* Supported TLS relocations. */ |
1001 | ||
1002 | enum tls_reloc { | |
1003 | TLS_GD32, | |
1004 | TLS_LDM32, | |
1005 | TLS_LDO32, | |
1006 | TLS_IE32, | |
ccdc2164 NS |
1007 | TLS_LE32, |
1008 | TLS_DESCSEQ /* GNU scheme */ | |
d3585b76 DJ |
1009 | }; |
1010 | ||
1b78f575 RE |
1011 | /* The maximum number of insns to be used when loading a constant. */ |
1012 | inline static int | |
1013 | arm_constant_limit (bool size_p) | |
1014 | { | |
1015 | return size_p ? 1 : current_tune->constant_limit; | |
1016 | } | |
1017 | ||
d66437c5 RE |
1018 | /* Emit an insn that's a simple single-set. Both the operands must be known |
1019 | to be valid. */ | |
1020 | inline static rtx | |
1021 | emit_set_insn (rtx x, rtx y) | |
1022 | { | |
1023 | return emit_insn (gen_rtx_SET (VOIDmode, x, y)); | |
1024 | } | |
1025 | ||
0977774b JT |
1026 | /* Return the number of bits set in VALUE. */ |
1027 | static unsigned | |
e32bac5b | 1028 | bit_count (unsigned long value) |
aec3cfba | 1029 | { |
d5b7b3ae | 1030 | unsigned long count = 0; |
f676971a | 1031 | |
aec3cfba NC |
1032 | while (value) |
1033 | { | |
0977774b JT |
1034 | count++; |
1035 | value &= value - 1; /* Clear the least-significant set bit. */ | |
aec3cfba NC |
1036 | } |
1037 | ||
1038 | return count; | |
1039 | } | |
1040 | ||
655b30bf JB |
1041 | typedef struct |
1042 | { | |
1043 | enum machine_mode mode; | |
1044 | const char *name; | |
1045 | } arm_fixed_mode_set; | |
1046 | ||
1047 | /* A small helper for setting fixed-point library libfuncs. */ | |
1048 | ||
1049 | static void | |
1050 | arm_set_fixed_optab_libfunc (optab optable, enum machine_mode mode, | |
1051 | const char *funcname, const char *modename, | |
1052 | int num_suffix) | |
1053 | { | |
1054 | char buffer[50]; | |
1055 | ||
1056 | if (num_suffix == 0) | |
1057 | sprintf (buffer, "__gnu_%s%s", funcname, modename); | |
1058 | else | |
1059 | sprintf (buffer, "__gnu_%s%s%d", funcname, modename, num_suffix); | |
1060 | ||
1061 | set_optab_libfunc (optable, mode, buffer); | |
1062 | } | |
1063 | ||
1064 | static void | |
1065 | arm_set_fixed_conv_libfunc (convert_optab optable, enum machine_mode to, | |
1066 | enum machine_mode from, const char *funcname, | |
1067 | const char *toname, const char *fromname) | |
1068 | { | |
1069 | char buffer[50]; | |
6eb9142a | 1070 | const char *maybe_suffix_2 = ""; |
655b30bf JB |
1071 | |
1072 | /* Follow the logic for selecting a "2" suffix in fixed-bit.h. */ | |
1073 | if (ALL_FIXED_POINT_MODE_P (from) && ALL_FIXED_POINT_MODE_P (to) | |
1074 | && UNSIGNED_FIXED_POINT_MODE_P (from) == UNSIGNED_FIXED_POINT_MODE_P (to) | |
1075 | && ALL_FRACT_MODE_P (from) == ALL_FRACT_MODE_P (to)) | |
1076 | maybe_suffix_2 = "2"; | |
1077 | ||
1078 | sprintf (buffer, "__gnu_%s%s%s%s", funcname, fromname, toname, | |
1079 | maybe_suffix_2); | |
1080 | ||
1081 | set_conv_libfunc (optable, to, from, buffer); | |
1082 | } | |
1083 | ||
c112cf2b | 1084 | /* Set up library functions unique to ARM. */ |
b3f8d95d MM |
1085 | |
1086 | static void | |
1087 | arm_init_libfuncs (void) | |
1088 | { | |
1089 | /* There are no special library functions unless we are using the | |
1090 | ARM BPABI. */ | |
1091 | if (!TARGET_BPABI) | |
1092 | return; | |
1093 | ||
1094 | /* The functions below are described in Section 4 of the "Run-Time | |
1095 | ABI for the ARM architecture", Version 1.0. */ | |
1096 | ||
1097 | /* Double-precision floating-point arithmetic. Table 2. */ | |
1098 | set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd"); | |
1099 | set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv"); | |
1100 | set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul"); | |
1101 | set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg"); | |
1102 | set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub"); | |
1103 | ||
c112cf2b | 1104 | /* Double-precision comparisons. Table 3. */ |
b3f8d95d MM |
1105 | set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq"); |
1106 | set_optab_libfunc (ne_optab, DFmode, NULL); | |
1107 | set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt"); | |
1108 | set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple"); | |
1109 | set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge"); | |
1110 | set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt"); | |
1111 | set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun"); | |
1112 | ||
1113 | /* Single-precision floating-point arithmetic. Table 4. */ | |
1114 | set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd"); | |
1115 | set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv"); | |
1116 | set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul"); | |
1117 | set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg"); | |
1118 | set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub"); | |
f676971a | 1119 | |
c112cf2b | 1120 | /* Single-precision comparisons. Table 5. */ |
b3f8d95d MM |
1121 | set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq"); |
1122 | set_optab_libfunc (ne_optab, SFmode, NULL); | |
1123 | set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt"); | |
1124 | set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple"); | |
1125 | set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge"); | |
1126 | set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt"); | |
1127 | set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun"); | |
1128 | ||
1129 | /* Floating-point to integer conversions. Table 6. */ | |
1130 | set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz"); | |
1131 | set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz"); | |
1132 | set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz"); | |
1133 | set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz"); | |
1134 | set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz"); | |
1135 | set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz"); | |
1136 | set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz"); | |
1137 | set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz"); | |
1138 | ||
1139 | /* Conversions between floating types. Table 7. */ | |
1140 | set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f"); | |
1141 | set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d"); | |
1142 | ||
c112cf2b | 1143 | /* Integer to floating-point conversions. Table 8. */ |
b3f8d95d MM |
1144 | set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d"); |
1145 | set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d"); | |
1146 | set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d"); | |
1147 | set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d"); | |
1148 | set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f"); | |
1149 | set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f"); | |
1150 | set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f"); | |
1151 | set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f"); | |
1152 | ||
1153 | /* Long long. Table 9. */ | |
1154 | set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul"); | |
1155 | set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod"); | |
1156 | set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod"); | |
1157 | set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl"); | |
1158 | set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr"); | |
1159 | set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr"); | |
1160 | set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp"); | |
1161 | set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp"); | |
1162 | ||
1163 | /* Integer (32/32->32) division. \S 4.3.1. */ | |
1164 | set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod"); | |
1165 | set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod"); | |
1166 | ||
1167 | /* The divmod functions are designed so that they can be used for | |
1168 | plain division, even though they return both the quotient and the | |
1169 | remainder. The quotient is returned in the usual location (i.e., | |
1170 | r0 for SImode, {r0, r1} for DImode), just as would be expected | |
1171 | for an ordinary division routine. Because the AAPCS calling | |
1172 | conventions specify that all of { r0, r1, r2, r3 } are | |
1173 | callee-saved registers, there is no need to tell the compiler | |
1174 | explicitly that those registers are clobbered by these | |
1175 | routines. */ | |
1176 | set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod"); | |
1177 | set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod"); | |
e993ba8f DJ |
1178 | |
1179 | /* For SImode division the ABI provides div-without-mod routines, | |
1180 | which are faster. */ | |
1181 | set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idiv"); | |
1182 | set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidiv"); | |
01c19d47 PB |
1183 | |
1184 | /* We don't have mod libcalls. Fortunately gcc knows how to use the | |
1185 | divmod libcalls instead. */ | |
1186 | set_optab_libfunc (smod_optab, DImode, NULL); | |
1187 | set_optab_libfunc (umod_optab, DImode, NULL); | |
1188 | set_optab_libfunc (smod_optab, SImode, NULL); | |
1189 | set_optab_libfunc (umod_optab, SImode, NULL); | |
0fd8c3ad SL |
1190 | |
1191 | /* Half-precision float operations. The compiler handles all operations | |
1192 | with NULL libfuncs by converting the SFmode. */ | |
1193 | switch (arm_fp16_format) | |
1194 | { | |
1195 | case ARM_FP16_FORMAT_IEEE: | |
1196 | case ARM_FP16_FORMAT_ALTERNATIVE: | |
1197 | ||
1198 | /* Conversions. */ | |
1199 | set_conv_libfunc (trunc_optab, HFmode, SFmode, | |
1200 | (arm_fp16_format == ARM_FP16_FORMAT_IEEE | |
1201 | ? "__gnu_f2h_ieee" | |
1202 | : "__gnu_f2h_alternative")); | |
1203 | set_conv_libfunc (sext_optab, SFmode, HFmode, | |
1204 | (arm_fp16_format == ARM_FP16_FORMAT_IEEE | |
1205 | ? "__gnu_h2f_ieee" | |
1206 | : "__gnu_h2f_alternative")); | |
1207 | ||
1208 | /* Arithmetic. */ | |
1209 | set_optab_libfunc (add_optab, HFmode, NULL); | |
1210 | set_optab_libfunc (sdiv_optab, HFmode, NULL); | |
1211 | set_optab_libfunc (smul_optab, HFmode, NULL); | |
1212 | set_optab_libfunc (neg_optab, HFmode, NULL); | |
1213 | set_optab_libfunc (sub_optab, HFmode, NULL); | |
1214 | ||
1215 | /* Comparisons. */ | |
1216 | set_optab_libfunc (eq_optab, HFmode, NULL); | |
1217 | set_optab_libfunc (ne_optab, HFmode, NULL); | |
1218 | set_optab_libfunc (lt_optab, HFmode, NULL); | |
1219 | set_optab_libfunc (le_optab, HFmode, NULL); | |
1220 | set_optab_libfunc (ge_optab, HFmode, NULL); | |
1221 | set_optab_libfunc (gt_optab, HFmode, NULL); | |
1222 | set_optab_libfunc (unord_optab, HFmode, NULL); | |
1223 | break; | |
1224 | ||
1225 | default: | |
1226 | break; | |
1227 | } | |
353a58f7 | 1228 | |
655b30bf JB |
1229 | /* Use names prefixed with __gnu_ for fixed-point helper functions. */ |
1230 | { | |
1231 | const arm_fixed_mode_set fixed_arith_modes[] = | |
1232 | { | |
1233 | { QQmode, "qq" }, | |
1234 | { UQQmode, "uqq" }, | |
1235 | { HQmode, "hq" }, | |
1236 | { UHQmode, "uhq" }, | |
1237 | { SQmode, "sq" }, | |
1238 | { USQmode, "usq" }, | |
1239 | { DQmode, "dq" }, | |
1240 | { UDQmode, "udq" }, | |
1241 | { TQmode, "tq" }, | |
1242 | { UTQmode, "utq" }, | |
1243 | { HAmode, "ha" }, | |
1244 | { UHAmode, "uha" }, | |
1245 | { SAmode, "sa" }, | |
1246 | { USAmode, "usa" }, | |
1247 | { DAmode, "da" }, | |
1248 | { UDAmode, "uda" }, | |
1249 | { TAmode, "ta" }, | |
1250 | { UTAmode, "uta" } | |
1251 | }; | |
1252 | const arm_fixed_mode_set fixed_conv_modes[] = | |
1253 | { | |
1254 | { QQmode, "qq" }, | |
1255 | { UQQmode, "uqq" }, | |
1256 | { HQmode, "hq" }, | |
1257 | { UHQmode, "uhq" }, | |
1258 | { SQmode, "sq" }, | |
1259 | { USQmode, "usq" }, | |
1260 | { DQmode, "dq" }, | |
1261 | { UDQmode, "udq" }, | |
1262 | { TQmode, "tq" }, | |
1263 | { UTQmode, "utq" }, | |
1264 | { HAmode, "ha" }, | |
1265 | { UHAmode, "uha" }, | |
1266 | { SAmode, "sa" }, | |
1267 | { USAmode, "usa" }, | |
1268 | { DAmode, "da" }, | |
1269 | { UDAmode, "uda" }, | |
1270 | { TAmode, "ta" }, | |
1271 | { UTAmode, "uta" }, | |
1272 | { QImode, "qi" }, | |
1273 | { HImode, "hi" }, | |
1274 | { SImode, "si" }, | |
1275 | { DImode, "di" }, | |
1276 | { TImode, "ti" }, | |
1277 | { SFmode, "sf" }, | |
1278 | { DFmode, "df" } | |
1279 | }; | |
1280 | unsigned int i, j; | |
1281 | ||
1282 | for (i = 0; i < ARRAY_SIZE (fixed_arith_modes); i++) | |
1283 | { | |
1284 | arm_set_fixed_optab_libfunc (add_optab, fixed_arith_modes[i].mode, | |
1285 | "add", fixed_arith_modes[i].name, 3); | |
1286 | arm_set_fixed_optab_libfunc (ssadd_optab, fixed_arith_modes[i].mode, | |
1287 | "ssadd", fixed_arith_modes[i].name, 3); | |
1288 | arm_set_fixed_optab_libfunc (usadd_optab, fixed_arith_modes[i].mode, | |
1289 | "usadd", fixed_arith_modes[i].name, 3); | |
1290 | arm_set_fixed_optab_libfunc (sub_optab, fixed_arith_modes[i].mode, | |
1291 | "sub", fixed_arith_modes[i].name, 3); | |
1292 | arm_set_fixed_optab_libfunc (sssub_optab, fixed_arith_modes[i].mode, | |
1293 | "sssub", fixed_arith_modes[i].name, 3); | |
1294 | arm_set_fixed_optab_libfunc (ussub_optab, fixed_arith_modes[i].mode, | |
1295 | "ussub", fixed_arith_modes[i].name, 3); | |
1296 | arm_set_fixed_optab_libfunc (smul_optab, fixed_arith_modes[i].mode, | |
1297 | "mul", fixed_arith_modes[i].name, 3); | |
1298 | arm_set_fixed_optab_libfunc (ssmul_optab, fixed_arith_modes[i].mode, | |
1299 | "ssmul", fixed_arith_modes[i].name, 3); | |
1300 | arm_set_fixed_optab_libfunc (usmul_optab, fixed_arith_modes[i].mode, | |
1301 | "usmul", fixed_arith_modes[i].name, 3); | |
1302 | arm_set_fixed_optab_libfunc (sdiv_optab, fixed_arith_modes[i].mode, | |
1303 | "div", fixed_arith_modes[i].name, 3); | |
1304 | arm_set_fixed_optab_libfunc (udiv_optab, fixed_arith_modes[i].mode, | |
1305 | "udiv", fixed_arith_modes[i].name, 3); | |
1306 | arm_set_fixed_optab_libfunc (ssdiv_optab, fixed_arith_modes[i].mode, | |
1307 | "ssdiv", fixed_arith_modes[i].name, 3); | |
1308 | arm_set_fixed_optab_libfunc (usdiv_optab, fixed_arith_modes[i].mode, | |
1309 | "usdiv", fixed_arith_modes[i].name, 3); | |
1310 | arm_set_fixed_optab_libfunc (neg_optab, fixed_arith_modes[i].mode, | |
1311 | "neg", fixed_arith_modes[i].name, 2); | |
1312 | arm_set_fixed_optab_libfunc (ssneg_optab, fixed_arith_modes[i].mode, | |
1313 | "ssneg", fixed_arith_modes[i].name, 2); | |
1314 | arm_set_fixed_optab_libfunc (usneg_optab, fixed_arith_modes[i].mode, | |
1315 | "usneg", fixed_arith_modes[i].name, 2); | |
1316 | arm_set_fixed_optab_libfunc (ashl_optab, fixed_arith_modes[i].mode, | |
1317 | "ashl", fixed_arith_modes[i].name, 3); | |
1318 | arm_set_fixed_optab_libfunc (ashr_optab, fixed_arith_modes[i].mode, | |
1319 | "ashr", fixed_arith_modes[i].name, 3); | |
1320 | arm_set_fixed_optab_libfunc (lshr_optab, fixed_arith_modes[i].mode, | |
1321 | "lshr", fixed_arith_modes[i].name, 3); | |
1322 | arm_set_fixed_optab_libfunc (ssashl_optab, fixed_arith_modes[i].mode, | |
1323 | "ssashl", fixed_arith_modes[i].name, 3); | |
1324 | arm_set_fixed_optab_libfunc (usashl_optab, fixed_arith_modes[i].mode, | |
1325 | "usashl", fixed_arith_modes[i].name, 3); | |
1326 | arm_set_fixed_optab_libfunc (cmp_optab, fixed_arith_modes[i].mode, | |
1327 | "cmp", fixed_arith_modes[i].name, 2); | |
1328 | } | |
1329 | ||
1330 | for (i = 0; i < ARRAY_SIZE (fixed_conv_modes); i++) | |
1331 | for (j = 0; j < ARRAY_SIZE (fixed_conv_modes); j++) | |
1332 | { | |
1333 | if (i == j | |
1334 | || (!ALL_FIXED_POINT_MODE_P (fixed_conv_modes[i].mode) | |
1335 | && !ALL_FIXED_POINT_MODE_P (fixed_conv_modes[j].mode))) | |
1336 | continue; | |
1337 | ||
1338 | arm_set_fixed_conv_libfunc (fract_optab, fixed_conv_modes[i].mode, | |
1339 | fixed_conv_modes[j].mode, "fract", | |
1340 | fixed_conv_modes[i].name, | |
1341 | fixed_conv_modes[j].name); | |
1342 | arm_set_fixed_conv_libfunc (satfract_optab, | |
1343 | fixed_conv_modes[i].mode, | |
1344 | fixed_conv_modes[j].mode, "satfract", | |
1345 | fixed_conv_modes[i].name, | |
1346 | fixed_conv_modes[j].name); | |
1347 | arm_set_fixed_conv_libfunc (fractuns_optab, | |
1348 | fixed_conv_modes[i].mode, | |
1349 | fixed_conv_modes[j].mode, "fractuns", | |
1350 | fixed_conv_modes[i].name, | |
1351 | fixed_conv_modes[j].name); | |
1352 | arm_set_fixed_conv_libfunc (satfractuns_optab, | |
1353 | fixed_conv_modes[i].mode, | |
1354 | fixed_conv_modes[j].mode, "satfractuns", | |
1355 | fixed_conv_modes[i].name, | |
1356 | fixed_conv_modes[j].name); | |
1357 | } | |
1358 | } | |
1359 | ||
353a58f7 AH |
1360 | if (TARGET_AAPCS_BASED) |
1361 | synchronize_libfunc = init_one_libfunc ("__sync_synchronize"); | |
b3f8d95d MM |
1362 | } |
1363 | ||
07d8efe3 MM |
1364 | /* On AAPCS systems, this is the "struct __va_list". */ |
1365 | static GTY(()) tree va_list_type; | |
1366 | ||
1367 | /* Return the type to use as __builtin_va_list. */ | |
1368 | static tree | |
1369 | arm_build_builtin_va_list (void) | |
1370 | { | |
1371 | tree va_list_name; | |
1372 | tree ap_field; | |
1373 | ||
1374 | if (!TARGET_AAPCS_BASED) | |
1375 | return std_build_builtin_va_list (); | |
1376 | ||
1377 | /* AAPCS \S 7.1.4 requires that va_list be a typedef for a type | |
1378 | defined as: | |
1379 | ||
1380 | struct __va_list | |
1381 | { | |
1382 | void *__ap; | |
1383 | }; | |
1384 | ||
1385 | The C Library ABI further reinforces this definition in \S | |
1386 | 4.1. | |
1387 | ||
1388 | We must follow this definition exactly. The structure tag | |
1389 | name is visible in C++ mangled names, and thus forms a part | |
1390 | of the ABI. The field name may be used by people who | |
1391 | #include <stdarg.h>. */ | |
1392 | /* Create the type. */ | |
1393 | va_list_type = lang_hooks.types.make_type (RECORD_TYPE); | |
1394 | /* Give it the required name. */ | |
4c4bde29 AH |
1395 | va_list_name = build_decl (BUILTINS_LOCATION, |
1396 | TYPE_DECL, | |
07d8efe3 MM |
1397 | get_identifier ("__va_list"), |
1398 | va_list_type); | |
1399 | DECL_ARTIFICIAL (va_list_name) = 1; | |
1400 | TYPE_NAME (va_list_type) = va_list_name; | |
56f01f0b | 1401 | TYPE_STUB_DECL (va_list_type) = va_list_name; |
07d8efe3 | 1402 | /* Create the __ap field. */ |
4c4bde29 AH |
1403 | ap_field = build_decl (BUILTINS_LOCATION, |
1404 | FIELD_DECL, | |
07d8efe3 MM |
1405 | get_identifier ("__ap"), |
1406 | ptr_type_node); | |
1407 | DECL_ARTIFICIAL (ap_field) = 1; | |
1408 | DECL_FIELD_CONTEXT (ap_field) = va_list_type; | |
1409 | TYPE_FIELDS (va_list_type) = ap_field; | |
1410 | /* Compute its layout. */ | |
1411 | layout_type (va_list_type); | |
1412 | ||
1413 | return va_list_type; | |
1414 | } | |
1415 | ||
1416 | /* Return an expression of type "void *" pointing to the next | |
1417 | available argument in a variable-argument list. VALIST is the | |
1418 | user-level va_list object, of type __builtin_va_list. */ | |
1419 | static tree | |
1420 | arm_extract_valist_ptr (tree valist) | |
1421 | { | |
1422 | if (TREE_TYPE (valist) == error_mark_node) | |
1423 | return error_mark_node; | |
1424 | ||
1425 | /* On an AAPCS target, the pointer is stored within "struct | |
1426 | va_list". */ | |
1427 | if (TARGET_AAPCS_BASED) | |
1428 | { | |
1429 | tree ap_field = TYPE_FIELDS (TREE_TYPE (valist)); | |
1430 | valist = build3 (COMPONENT_REF, TREE_TYPE (ap_field), | |
1431 | valist, ap_field, NULL_TREE); | |
1432 | } | |
1433 | ||
1434 | return valist; | |
1435 | } | |
1436 | ||
1437 | /* Implement TARGET_EXPAND_BUILTIN_VA_START. */ | |
1438 | static void | |
1439 | arm_expand_builtin_va_start (tree valist, rtx nextarg) | |
1440 | { | |
1441 | valist = arm_extract_valist_ptr (valist); | |
1442 | std_expand_builtin_va_start (valist, nextarg); | |
1443 | } | |
1444 | ||
1445 | /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */ | |
1446 | static tree | |
ae46a823 JM |
1447 | arm_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, |
1448 | gimple_seq *post_p) | |
07d8efe3 MM |
1449 | { |
1450 | valist = arm_extract_valist_ptr (valist); | |
1451 | return std_gimplify_va_arg_expr (valist, type, pre_p, post_p); | |
1452 | } | |
1453 | ||
c5387660 JM |
1454 | /* Fix up any incompatible options that the user has specified. */ |
1455 | static void | |
1456 | arm_option_override (void) | |
2b835d68 | 1457 | { |
ad7be009 JM |
1458 | if (global_options_set.x_arm_arch_option) |
1459 | arm_selected_arch = &all_architectures[arm_arch_option]; | |
1460 | ||
1461 | if (global_options_set.x_arm_cpu_option) | |
1462 | arm_selected_cpu = &all_cores[(int) arm_cpu_option]; | |
1463 | ||
1464 | if (global_options_set.x_arm_tune_option) | |
1465 | arm_selected_tune = &all_cores[(int) arm_tune_option]; | |
1466 | ||
c5387660 JM |
1467 | #ifdef SUBTARGET_OVERRIDE_OPTIONS |
1468 | SUBTARGET_OVERRIDE_OPTIONS; | |
1469 | #endif | |
1470 | ||
12a0a4d4 | 1471 | if (arm_selected_arch) |
bd9c7e23 | 1472 | { |
12a0a4d4 PB |
1473 | if (arm_selected_cpu) |
1474 | { | |
1475 | /* Check for conflict between mcpu and march. */ | |
1476 | if ((arm_selected_cpu->flags ^ arm_selected_arch->flags) & ~FL_TUNE) | |
1477 | { | |
1478 | warning (0, "switch -mcpu=%s conflicts with -march=%s switch", | |
1479 | arm_selected_cpu->name, arm_selected_arch->name); | |
1480 | /* -march wins for code generation. | |
1481 | -mcpu wins for default tuning. */ | |
1482 | if (!arm_selected_tune) | |
1483 | arm_selected_tune = arm_selected_cpu; | |
1484 | ||
1485 | arm_selected_cpu = arm_selected_arch; | |
1486 | } | |
1487 | else | |
1488 | /* -mcpu wins. */ | |
1489 | arm_selected_arch = NULL; | |
1490 | } | |
1491 | else | |
1492 | /* Pick a CPU based on the architecture. */ | |
1493 | arm_selected_cpu = arm_selected_arch; | |
bd9c7e23 | 1494 | } |
f676971a | 1495 | |
f5a1b0d2 | 1496 | /* If the user did not specify a processor, choose one for them. */ |
12a0a4d4 | 1497 | if (!arm_selected_cpu) |
f5a1b0d2 | 1498 | { |
8b60264b | 1499 | const struct processors * sel; |
aec3cfba | 1500 | unsigned int sought; |
aec3cfba | 1501 | |
12a0a4d4 PB |
1502 | arm_selected_cpu = &all_cores[TARGET_CPU_DEFAULT]; |
1503 | if (!arm_selected_cpu->name) | |
78011587 PB |
1504 | { |
1505 | #ifdef SUBTARGET_CPU_DEFAULT | |
1506 | /* Use the subtarget default CPU if none was specified by | |
1507 | configure. */ | |
12a0a4d4 | 1508 | arm_selected_cpu = &all_cores[SUBTARGET_CPU_DEFAULT]; |
78011587 PB |
1509 | #endif |
1510 | /* Default to ARM6. */ | |
fe7645b9 | 1511 | if (!arm_selected_cpu->name) |
12a0a4d4 | 1512 | arm_selected_cpu = &all_cores[arm6]; |
78011587 | 1513 | } |
aec3cfba | 1514 | |
12a0a4d4 | 1515 | sel = arm_selected_cpu; |
aec3cfba | 1516 | insn_flags = sel->flags; |
9b66ebb1 | 1517 | |
aec3cfba NC |
1518 | /* Now check to see if the user has specified some command line |
1519 | switch that require certain abilities from the cpu. */ | |
1520 | sought = 0; | |
f676971a | 1521 | |
d5b7b3ae | 1522 | if (TARGET_INTERWORK || TARGET_THUMB) |
f5a1b0d2 | 1523 | { |
aec3cfba | 1524 | sought |= (FL_THUMB | FL_MODE32); |
f676971a | 1525 | |
d5b7b3ae | 1526 | /* There are no ARM processors that support both APCS-26 and |
aec3cfba NC |
1527 | interworking. Therefore we force FL_MODE26 to be removed |
1528 | from insn_flags here (if it was set), so that the search | |
1529 | below will always be able to find a compatible processor. */ | |
5895f793 | 1530 | insn_flags &= ~FL_MODE26; |
f5a1b0d2 | 1531 | } |
f676971a | 1532 | |
aec3cfba | 1533 | if (sought != 0 && ((sought & insn_flags) != sought)) |
f5a1b0d2 | 1534 | { |
aec3cfba NC |
1535 | /* Try to locate a CPU type that supports all of the abilities |
1536 | of the default CPU, plus the extra abilities requested by | |
1537 | the user. */ | |
5895f793 | 1538 | for (sel = all_cores; sel->name != NULL; sel++) |
aec3cfba | 1539 | if ((sel->flags & sought) == (sought | insn_flags)) |
f5a1b0d2 NC |
1540 | break; |
1541 | ||
1542 | if (sel->name == NULL) | |
aec3cfba | 1543 | { |
0977774b | 1544 | unsigned current_bit_count = 0; |
8b60264b | 1545 | const struct processors * best_fit = NULL; |
f676971a | 1546 | |
aec3cfba NC |
1547 | /* Ideally we would like to issue an error message here |
1548 | saying that it was not possible to find a CPU compatible | |
1549 | with the default CPU, but which also supports the command | |
1550 | line options specified by the programmer, and so they | |
1551 | ought to use the -mcpu=<name> command line option to | |
1552 | override the default CPU type. | |
1553 | ||
61f0ccff RE |
1554 | If we cannot find a cpu that has both the |
1555 | characteristics of the default cpu and the given | |
1556 | command line options we scan the array again looking | |
1557 | for a best match. */ | |
5895f793 | 1558 | for (sel = all_cores; sel->name != NULL; sel++) |
aec3cfba NC |
1559 | if ((sel->flags & sought) == sought) |
1560 | { | |
0977774b | 1561 | unsigned count; |
aec3cfba NC |
1562 | |
1563 | count = bit_count (sel->flags & insn_flags); | |
1564 | ||
1565 | if (count >= current_bit_count) | |
1566 | { | |
1567 | best_fit = sel; | |
1568 | current_bit_count = count; | |
1569 | } | |
1570 | } | |
f5a1b0d2 | 1571 | |
e6d29d15 NS |
1572 | gcc_assert (best_fit); |
1573 | sel = best_fit; | |
aec3cfba NC |
1574 | } |
1575 | ||
12a0a4d4 | 1576 | arm_selected_cpu = sel; |
f5a1b0d2 NC |
1577 | } |
1578 | } | |
f676971a | 1579 | |
12a0a4d4 PB |
1580 | gcc_assert (arm_selected_cpu); |
1581 | /* The selected cpu may be an architecture, so lookup tuning by core ID. */ | |
1582 | if (!arm_selected_tune) | |
1583 | arm_selected_tune = &all_cores[arm_selected_cpu->core]; | |
1584 | ||
1585 | sprintf (arm_arch_name, "__ARM_ARCH_%s__", arm_selected_cpu->arch); | |
1586 | insn_flags = arm_selected_cpu->flags; | |
f676971a | 1587 | |
12a0a4d4 PB |
1588 | arm_tune = arm_selected_tune->core; |
1589 | tune_flags = arm_selected_tune->flags; | |
1590 | current_tune = arm_selected_tune->tune; | |
e26053d1 | 1591 | |
f5a1b0d2 NC |
1592 | /* Make sure that the processor choice does not conflict with any of the |
1593 | other command line choices. */ | |
5b3e6663 PB |
1594 | if (TARGET_ARM && !(insn_flags & FL_NOTM)) |
1595 | error ("target CPU does not support ARM mode"); | |
1596 | ||
26272ba2 PB |
1597 | /* BPABI targets use linker tricks to allow interworking on cores |
1598 | without thumb support. */ | |
1599 | if (TARGET_INTERWORK && !((insn_flags & FL_THUMB) || TARGET_BPABI)) | |
f5a1b0d2 | 1600 | { |
d4ee4d25 | 1601 | warning (0, "target CPU does not support interworking" ); |
c54c7322 | 1602 | target_flags &= ~MASK_INTERWORK; |
f5a1b0d2 | 1603 | } |
f676971a | 1604 | |
d5b7b3ae RE |
1605 | if (TARGET_THUMB && !(insn_flags & FL_THUMB)) |
1606 | { | |
d4ee4d25 | 1607 | warning (0, "target CPU does not support THUMB instructions"); |
c54c7322 | 1608 | target_flags &= ~MASK_THUMB; |
d5b7b3ae RE |
1609 | } |
1610 | ||
1611 | if (TARGET_APCS_FRAME && TARGET_THUMB) | |
1612 | { | |
d4ee4d25 | 1613 | /* warning (0, "ignoring -mapcs-frame because -mthumb was used"); */ |
c54c7322 | 1614 | target_flags &= ~MASK_APCS_FRAME; |
d5b7b3ae | 1615 | } |
d19fb8e3 | 1616 | |
da8ce8be RE |
1617 | /* Callee super interworking implies thumb interworking. Adding |
1618 | this to the flags here simplifies the logic elsewhere. */ | |
1619 | if (TARGET_THUMB && TARGET_CALLEE_INTERWORKING) | |
4546a2ef | 1620 | target_flags |= MASK_INTERWORK; |
da8ce8be | 1621 | |
d5b7b3ae RE |
1622 | /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done |
1623 | from here where no function is being compiled currently. */ | |
c54c7322 | 1624 | if ((TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) && TARGET_ARM) |
d4ee4d25 | 1625 | warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb"); |
d5b7b3ae RE |
1626 | |
1627 | if (TARGET_ARM && TARGET_CALLEE_INTERWORKING) | |
d4ee4d25 | 1628 | warning (0, "enabling callee interworking support is only meaningful when compiling for the Thumb"); |
d5b7b3ae | 1629 | |
5895f793 | 1630 | if (TARGET_APCS_STACK && !TARGET_APCS_FRAME) |
f5a1b0d2 | 1631 | { |
d4ee4d25 | 1632 | warning (0, "-mapcs-stack-check incompatible with -mno-apcs-frame"); |
c54c7322 | 1633 | target_flags |= MASK_APCS_FRAME; |
f5a1b0d2 | 1634 | } |
f676971a | 1635 | |
2b835d68 | 1636 | if (TARGET_POKE_FUNCTION_NAME) |
c54c7322 | 1637 | target_flags |= MASK_APCS_FRAME; |
f676971a | 1638 | |
2b835d68 | 1639 | if (TARGET_APCS_REENT && flag_pic) |
400500c4 | 1640 | error ("-fpic and -mapcs-reent are incompatible"); |
f676971a | 1641 | |
2b835d68 | 1642 | if (TARGET_APCS_REENT) |
d4ee4d25 | 1643 | warning (0, "APCS reentrant code not supported. Ignored"); |
f676971a | 1644 | |
d5b7b3ae RE |
1645 | /* If this target is normally configured to use APCS frames, warn if they |
1646 | are turned off and debugging is turned on. */ | |
1647 | if (TARGET_ARM | |
1648 | && write_symbols != NO_DEBUG | |
5895f793 | 1649 | && !TARGET_APCS_FRAME |
c54c7322 | 1650 | && (TARGET_DEFAULT & MASK_APCS_FRAME)) |
d4ee4d25 | 1651 | warning (0, "-g with -mno-apcs-frame may not give sensible debugging"); |
f676971a | 1652 | |
2b835d68 | 1653 | if (TARGET_APCS_FLOAT) |
d4ee4d25 | 1654 | warning (0, "passing floating point arguments in fp regs not yet supported"); |
f676971a | 1655 | |
38460025 RS |
1656 | if (TARGET_LITTLE_WORDS) |
1657 | warning (OPT_Wdeprecated, "%<mwords-little-endian%> is deprecated and " | |
1658 | "will be removed in a future release"); | |
1659 | ||
4912a07c | 1660 | /* Initialize boolean versions of the flags, for use in the arm.md file. */ |
9b66ebb1 PB |
1661 | arm_arch3m = (insn_flags & FL_ARCH3M) != 0; |
1662 | arm_arch4 = (insn_flags & FL_ARCH4) != 0; | |
68d560d4 | 1663 | arm_arch4t = arm_arch4 & ((insn_flags & FL_THUMB) != 0); |
9b66ebb1 PB |
1664 | arm_arch5 = (insn_flags & FL_ARCH5) != 0; |
1665 | arm_arch5e = (insn_flags & FL_ARCH5E) != 0; | |
1666 | arm_arch6 = (insn_flags & FL_ARCH6) != 0; | |
d3585b76 | 1667 | arm_arch6k = (insn_flags & FL_ARCH6K) != 0; |
5b3e6663 | 1668 | arm_arch_notm = (insn_flags & FL_NOTM) != 0; |
029e79eb | 1669 | arm_arch7 = (insn_flags & FL_ARCH7) != 0; |
60bd3528 | 1670 | arm_arch7em = (insn_flags & FL_ARCH7EM) != 0; |
5b3e6663 | 1671 | arm_arch_thumb2 = (insn_flags & FL_THUMB2) != 0; |
9b66ebb1 | 1672 | arm_arch_xscale = (insn_flags & FL_XSCALE) != 0; |
78011587 | 1673 | arm_arch_cirrus = (insn_flags & FL_CIRRUS) != 0; |
9b66ebb1 PB |
1674 | |
1675 | arm_ld_sched = (tune_flags & FL_LDSCHED) != 0; | |
abac3b49 | 1676 | arm_tune_strongarm = (tune_flags & FL_STRONG) != 0; |
906668bb BS |
1677 | thumb_code = TARGET_ARM == 0; |
1678 | thumb1_code = TARGET_THUMB1 != 0; | |
abac3b49 | 1679 | arm_tune_wbuf = (tune_flags & FL_WBUF) != 0; |
9b66ebb1 PB |
1680 | arm_tune_xscale = (tune_flags & FL_XSCALE) != 0; |
1681 | arm_arch_iwmmxt = (insn_flags & FL_IWMMXT) != 0; | |
572070ef PB |
1682 | arm_arch_thumb_hwdiv = (insn_flags & FL_THUMB_DIV) != 0; |
1683 | arm_arch_arm_hwdiv = (insn_flags & FL_ARM_DIV) != 0; | |
7612f14d | 1684 | arm_tune_cortex_a9 = (arm_tune == cortexa9) != 0; |
5a9335ef | 1685 | |
f67358da PB |
1686 | /* If we are not using the default (ARM mode) section anchor offset |
1687 | ranges, then set the correct ranges now. */ | |
1688 | if (TARGET_THUMB1) | |
1689 | { | |
1690 | /* Thumb-1 LDR instructions cannot have negative offsets. | |
1691 | Permissible positive offset ranges are 5-bit (for byte loads), | |
1692 | 6-bit (for halfword loads), or 7-bit (for word loads). | |
1693 | Empirical results suggest a 7-bit anchor range gives the best | |
1694 | overall code size. */ | |
1695 | targetm.min_anchor_offset = 0; | |
1696 | targetm.max_anchor_offset = 127; | |
1697 | } | |
1698 | else if (TARGET_THUMB2) | |
1699 | { | |
1700 | /* The minimum is set such that the total size of the block | |
1701 | for a particular anchor is 248 + 1 + 4095 bytes, which is | |
1702 | divisible by eight, ensuring natural spacing of anchors. */ | |
1703 | targetm.min_anchor_offset = -248; | |
1704 | targetm.max_anchor_offset = 4095; | |
1705 | } | |
1706 | ||
68d560d4 RE |
1707 | /* V5 code we generate is completely interworking capable, so we turn off |
1708 | TARGET_INTERWORK here to avoid many tests later on. */ | |
2ad4dcf9 RE |
1709 | |
1710 | /* XXX However, we must pass the right pre-processor defines to CPP | |
1711 | or GLD can get confused. This is a hack. */ | |
1712 | if (TARGET_INTERWORK) | |
1713 | arm_cpp_interwork = 1; | |
1714 | ||
68d560d4 | 1715 | if (arm_arch5) |
c54c7322 | 1716 | target_flags &= ~MASK_INTERWORK; |
68d560d4 | 1717 | |
5848830f PB |
1718 | if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN) |
1719 | error ("iwmmxt requires an AAPCS compatible ABI for proper operation"); | |
1720 | ||
1721 | if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT) | |
1722 | error ("iwmmxt abi requires an iwmmxt capable cpu"); | |
6f7ebcbb | 1723 | |
12d844c8 | 1724 | if (!global_options_set.x_arm_fpu_index) |
2b835d68 | 1725 | { |
12d844c8 JM |
1726 | const char *target_fpu_name; |
1727 | bool ok; | |
1728 | ||
9b66ebb1 | 1729 | #ifdef FPUTYPE_DEFAULT |
d79f3032 | 1730 | target_fpu_name = FPUTYPE_DEFAULT; |
9b66ebb1 | 1731 | #else |
78011587 | 1732 | if (arm_arch_cirrus) |
d79f3032 | 1733 | target_fpu_name = "maverick"; |
9b66ebb1 | 1734 | else |
d79f3032 | 1735 | target_fpu_name = "fpe2"; |
9b66ebb1 | 1736 | #endif |
d79f3032 | 1737 | |
12d844c8 JM |
1738 | ok = opt_enum_arg_to_value (OPT_mfpu_, target_fpu_name, &arm_fpu_index, |
1739 | CL_TARGET); | |
1740 | gcc_assert (ok); | |
d79f3032 | 1741 | } |
b761dbe6 | 1742 | |
12d844c8 | 1743 | arm_fpu_desc = &all_fpus[arm_fpu_index]; |
d79f3032 PB |
1744 | |
1745 | switch (arm_fpu_desc->model) | |
1746 | { | |
1747 | case ARM_FP_MODEL_FPA: | |
1748 | if (arm_fpu_desc->rev == 2) | |
1749 | arm_fpu_attr = FPU_FPE2; | |
1750 | else if (arm_fpu_desc->rev == 3) | |
1751 | arm_fpu_attr = FPU_FPE3; | |
2b835d68 | 1752 | else |
d79f3032 PB |
1753 | arm_fpu_attr = FPU_FPA; |
1754 | break; | |
1755 | ||
1756 | case ARM_FP_MODEL_MAVERICK: | |
1757 | arm_fpu_attr = FPU_MAVERICK; | |
1758 | break; | |
1759 | ||
1760 | case ARM_FP_MODEL_VFP: | |
1761 | arm_fpu_attr = FPU_VFP; | |
1762 | break; | |
1763 | ||
1764 | default: | |
1765 | gcc_unreachable(); | |
9b66ebb1 PB |
1766 | } |
1767 | ||
0c48a567 | 1768 | if (TARGET_AAPCS_BASED |
d79f3032 | 1769 | && (arm_fpu_desc->model == ARM_FP_MODEL_FPA)) |
0c48a567 RR |
1770 | error ("FPA is unsupported in the AAPCS"); |
1771 | ||
3ce14752 | 1772 | if (TARGET_AAPCS_BASED) |
9df5bfe4 RR |
1773 | { |
1774 | if (TARGET_CALLER_INTERWORKING) | |
1775 | error ("AAPCS does not support -mcaller-super-interworking"); | |
1776 | else | |
1777 | if (TARGET_CALLEE_INTERWORKING) | |
1778 | error ("AAPCS does not support -mcallee-super-interworking"); | |
1779 | } | |
3ce14752 | 1780 | |
87b24aaf PB |
1781 | /* FPA and iWMMXt are incompatible because the insn encodings overlap. |
1782 | VFP and iWMMXt can theoretically coexist, but it's unlikely such silicon | |
1783 | will ever exist. GCC makes no attempt to support this combination. */ | |
1784 | if (TARGET_IWMMXT && !TARGET_SOFT_FLOAT) | |
1785 | sorry ("iWMMXt and hardware floating point"); | |
1786 | ||
5b3e6663 PB |
1787 | /* ??? iWMMXt insn patterns need auditing for Thumb-2. */ |
1788 | if (TARGET_THUMB2 && TARGET_IWMMXT) | |
1789 | sorry ("Thumb-2 iWMMXt"); | |
1790 | ||
0fd8c3ad SL |
1791 | /* __fp16 support currently assumes the core has ldrh. */ |
1792 | if (!arm_arch4 && arm_fp16_format != ARM_FP16_FORMAT_NONE) | |
1793 | sorry ("__fp16 and no ldrh"); | |
1794 | ||
9b66ebb1 PB |
1795 | /* If soft-float is specified then don't use FPU. */ |
1796 | if (TARGET_SOFT_FLOAT) | |
d79f3032 | 1797 | arm_fpu_attr = FPU_NONE; |
f676971a | 1798 | |
390b17c2 RE |
1799 | if (TARGET_AAPCS_BASED) |
1800 | { | |
1801 | if (arm_abi == ARM_ABI_IWMMXT) | |
1802 | arm_pcs_default = ARM_PCS_AAPCS_IWMMXT; | |
1803 | else if (arm_float_abi == ARM_FLOAT_ABI_HARD | |
1804 | && TARGET_HARD_FLOAT | |
1805 | && TARGET_VFP) | |
1806 | arm_pcs_default = ARM_PCS_AAPCS_VFP; | |
1807 | else | |
1808 | arm_pcs_default = ARM_PCS_AAPCS; | |
1809 | } | |
1810 | else | |
1811 | { | |
1812 | if (arm_float_abi == ARM_FLOAT_ABI_HARD && TARGET_VFP) | |
1813 | sorry ("-mfloat-abi=hard and VFP"); | |
1814 | ||
1815 | if (arm_abi == ARM_ABI_APCS) | |
1816 | arm_pcs_default = ARM_PCS_APCS; | |
1817 | else | |
1818 | arm_pcs_default = ARM_PCS_ATPCS; | |
1819 | } | |
1820 | ||
f5a1b0d2 NC |
1821 | /* For arm2/3 there is no need to do any scheduling if there is only |
1822 | a floating point emulator, or we are doing software floating-point. */ | |
9b66ebb1 | 1823 | if ((TARGET_SOFT_FLOAT |
d79f3032 | 1824 | || (TARGET_FPA && arm_fpu_desc->rev)) |
ed0e6530 | 1825 | && (tune_flags & FL_MODE32) == 0) |
f5a1b0d2 | 1826 | flag_schedule_insns = flag_schedule_insns_after_reload = 0; |
f676971a | 1827 | |
d3585b76 DJ |
1828 | /* Use the cp15 method if it is available. */ |
1829 | if (target_thread_pointer == TP_AUTO) | |
1830 | { | |
87d05b44 | 1831 | if (arm_arch6k && !TARGET_THUMB1) |
d3585b76 DJ |
1832 | target_thread_pointer = TP_CP15; |
1833 | else | |
1834 | target_thread_pointer = TP_SOFT; | |
1835 | } | |
1836 | ||
5b3e6663 PB |
1837 | if (TARGET_HARD_TP && TARGET_THUMB1) |
1838 | error ("can not use -mtp=cp15 with 16-bit Thumb"); | |
d3585b76 | 1839 | |
5848830f | 1840 | /* Override the default structure alignment for AAPCS ABI. */ |
ba163417 | 1841 | if (!global_options_set.x_arm_structure_size_boundary) |
b355a481 | 1842 | { |
ba163417 JM |
1843 | if (TARGET_AAPCS_BASED) |
1844 | arm_structure_size_boundary = 8; | |
1845 | } | |
1846 | else | |
1847 | { | |
1848 | if (arm_structure_size_boundary != 8 | |
1849 | && arm_structure_size_boundary != 32 | |
1850 | && !(ARM_DOUBLEWORD_ALIGN && arm_structure_size_boundary == 64)) | |
1851 | { | |
1852 | if (ARM_DOUBLEWORD_ALIGN) | |
1853 | warning (0, | |
1854 | "structure size boundary can only be set to 8, 32 or 64"); | |
1855 | else | |
1856 | warning (0, "structure size boundary can only be set to 8 or 32"); | |
1857 | arm_structure_size_boundary | |
1858 | = (TARGET_AAPCS_BASED ? 8 : DEFAULT_STRUCTURE_SIZE_BOUNDARY); | |
1859 | } | |
b355a481 | 1860 | } |
ed0e6530 | 1861 | |
9403b7f7 RS |
1862 | if (!TARGET_ARM && TARGET_VXWORKS_RTP && flag_pic) |
1863 | { | |
1864 | error ("RTP PIC is incompatible with Thumb"); | |
1865 | flag_pic = 0; | |
1866 | } | |
1867 | ||
c147eacb PB |
1868 | /* If stack checking is disabled, we can use r10 as the PIC register, |
1869 | which keeps r9 available. The EABI specifies r9 as the PIC register. */ | |
1870 | if (flag_pic && TARGET_SINGLE_PIC_BASE) | |
9403b7f7 RS |
1871 | { |
1872 | if (TARGET_VXWORKS_RTP) | |
1873 | warning (0, "RTP PIC is incompatible with -msingle-pic-base"); | |
1874 | arm_pic_register = (TARGET_APCS_STACK || TARGET_AAPCS_BASED) ? 9 : 10; | |
1875 | } | |
1876 | ||
1877 | if (flag_pic && TARGET_VXWORKS_RTP) | |
1878 | arm_pic_register = 9; | |
c147eacb | 1879 | |
ed0e6530 PB |
1880 | if (arm_pic_register_string != NULL) |
1881 | { | |
5b43fed1 | 1882 | int pic_register = decode_reg_name (arm_pic_register_string); |
e26053d1 | 1883 | |
5895f793 | 1884 | if (!flag_pic) |
d4ee4d25 | 1885 | warning (0, "-mpic-register= is useless without -fpic"); |
ed0e6530 | 1886 | |
ed0e6530 | 1887 | /* Prevent the user from choosing an obviously stupid PIC register. */ |
5b43fed1 RH |
1888 | else if (pic_register < 0 || call_used_regs[pic_register] |
1889 | || pic_register == HARD_FRAME_POINTER_REGNUM | |
1890 | || pic_register == STACK_POINTER_REGNUM | |
9403b7f7 RS |
1891 | || pic_register >= PC_REGNUM |
1892 | || (TARGET_VXWORKS_RTP | |
1893 | && (unsigned int) pic_register != arm_pic_register)) | |
c725bd79 | 1894 | error ("unable to use '%s' for PIC register", arm_pic_register_string); |
ed0e6530 PB |
1895 | else |
1896 | arm_pic_register = pic_register; | |
1897 | } | |
d5b7b3ae | 1898 | |
5fd42423 PB |
1899 | /* Enable -mfix-cortex-m3-ldrd by default for Cortex-M3 cores. */ |
1900 | if (fix_cm3_ldrd == 2) | |
1901 | { | |
12a0a4d4 | 1902 | if (arm_selected_cpu->core == cortexm3) |
5fd42423 PB |
1903 | fix_cm3_ldrd = 1; |
1904 | else | |
1905 | fix_cm3_ldrd = 0; | |
1906 | } | |
1907 | ||
4aef21c8 | 1908 | if (TARGET_THUMB1 && flag_schedule_insns) |
d5b7b3ae RE |
1909 | { |
1910 | /* Don't warn since it's on by default in -O2. */ | |
1911 | flag_schedule_insns = 0; | |
1912 | } | |
1913 | ||
f5a1b0d2 | 1914 | if (optimize_size) |
be03ccc9 | 1915 | { |
be03ccc9 | 1916 | /* If optimizing for size, bump the number of instructions that we |
d6b4baa4 | 1917 | are prepared to conditionally execute (even on a StrongARM). */ |
be03ccc9 NP |
1918 | max_insns_skipped = 6; |
1919 | } | |
1920 | else | |
16868d84 | 1921 | max_insns_skipped = current_tune->max_insns_skipped; |
92a432f4 | 1922 | |
70041f8a RE |
1923 | /* Hot/Cold partitioning is not currently supported, since we can't |
1924 | handle literal pool placement in that case. */ | |
1925 | if (flag_reorder_blocks_and_partition) | |
1926 | { | |
1927 | inform (input_location, | |
1928 | "-freorder-blocks-and-partition not supported on this architecture"); | |
1929 | flag_reorder_blocks_and_partition = 0; | |
1930 | flag_reorder_blocks = 1; | |
1931 | } | |
1932 | ||
128dc8e2 | 1933 | if (flag_pic) |
ec3728ad MK |
1934 | /* Hoisting PIC address calculations more aggressively provides a small, |
1935 | but measurable, size reduction for PIC code. Therefore, we decrease | |
1936 | the bar for unrestricted expression hoisting to the cost of PIC address | |
1937 | calculation, which is 2 instructions. */ | |
48476d13 JM |
1938 | maybe_set_param_value (PARAM_GCSE_UNRESTRICTED_COST, 2, |
1939 | global_options.x_param_values, | |
1940 | global_options_set.x_param_values); | |
ec3728ad | 1941 | |
f5c88dbf JZ |
1942 | /* ARM EABI defaults to strict volatile bitfields. */ |
1943 | if (TARGET_AAPCS_BASED && flag_strict_volatile_bitfields < 0) | |
1944 | flag_strict_volatile_bitfields = 1; | |
1945 | ||
911de8a3 IB |
1946 | /* Enable sw prefetching at -O3 for CPUS that have prefetch, and we have deemed |
1947 | it beneficial (signified by setting num_prefetch_slots to 1 or more.) */ | |
1948 | if (flag_prefetch_loop_arrays < 0 | |
1949 | && HAVE_prefetch | |
1950 | && optimize >= 3 | |
1951 | && current_tune->num_prefetch_slots > 0) | |
1952 | flag_prefetch_loop_arrays = 1; | |
1953 | ||
1954 | /* Set up parameters to be used in prefetching algorithm. Do not override the | |
1955 | defaults unless we are tuning for a core we have researched values for. */ | |
1956 | if (current_tune->num_prefetch_slots > 0) | |
1957 | maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES, | |
1958 | current_tune->num_prefetch_slots, | |
1959 | global_options.x_param_values, | |
1960 | global_options_set.x_param_values); | |
1961 | if (current_tune->l1_cache_line_size >= 0) | |
1962 | maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE, | |
1963 | current_tune->l1_cache_line_size, | |
1964 | global_options.x_param_values, | |
1965 | global_options_set.x_param_values); | |
1966 | if (current_tune->l1_cache_size >= 0) | |
1967 | maybe_set_param_value (PARAM_L1_CACHE_SIZE, | |
1968 | current_tune->l1_cache_size, | |
1969 | global_options.x_param_values, | |
1970 | global_options_set.x_param_values); | |
1971 | ||
92a432f4 RE |
1972 | /* Register global variables with the garbage collector. */ |
1973 | arm_add_gc_roots (); | |
1974 | } | |
1975 | ||
1976 | static void | |
e32bac5b | 1977 | arm_add_gc_roots (void) |
92a432f4 | 1978 | { |
c7319d87 RE |
1979 | gcc_obstack_init(&minipool_obstack); |
1980 | minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0); | |
2b835d68 | 1981 | } |
cce8749e | 1982 | \f |
6d3d9133 NC |
1983 | /* A table of known ARM exception types. |
1984 | For use with the interrupt function attribute. */ | |
1985 | ||
1986 | typedef struct | |
1987 | { | |
8b60264b KG |
1988 | const char *const arg; |
1989 | const unsigned long return_value; | |
6d3d9133 NC |
1990 | } |
1991 | isr_attribute_arg; | |
1992 | ||
8b60264b | 1993 | static const isr_attribute_arg isr_attribute_args [] = |
6d3d9133 NC |
1994 | { |
1995 | { "IRQ", ARM_FT_ISR }, | |
1996 | { "irq", ARM_FT_ISR }, | |
1997 | { "FIQ", ARM_FT_FIQ }, | |
1998 | { "fiq", ARM_FT_FIQ }, | |
1999 | { "ABORT", ARM_FT_ISR }, | |
2000 | { "abort", ARM_FT_ISR }, | |
2001 | { "ABORT", ARM_FT_ISR }, | |
2002 | { "abort", ARM_FT_ISR }, | |
2003 | { "UNDEF", ARM_FT_EXCEPTION }, | |
2004 | { "undef", ARM_FT_EXCEPTION }, | |
2005 | { "SWI", ARM_FT_EXCEPTION }, | |
2006 | { "swi", ARM_FT_EXCEPTION }, | |
2007 | { NULL, ARM_FT_NORMAL } | |
2008 | }; | |
2009 | ||
2010 | /* Returns the (interrupt) function type of the current | |
2011 | function, or ARM_FT_UNKNOWN if the type cannot be determined. */ | |
2012 | ||
2013 | static unsigned long | |
e32bac5b | 2014 | arm_isr_value (tree argument) |
6d3d9133 | 2015 | { |
8b60264b | 2016 | const isr_attribute_arg * ptr; |
1d6e90ac | 2017 | const char * arg; |
6d3d9133 | 2018 | |
5b3e6663 PB |
2019 | if (!arm_arch_notm) |
2020 | return ARM_FT_NORMAL | ARM_FT_STACKALIGN; | |
2021 | ||
6d3d9133 NC |
2022 | /* No argument - default to IRQ. */ |
2023 | if (argument == NULL_TREE) | |
2024 | return ARM_FT_ISR; | |
2025 | ||
2026 | /* Get the value of the argument. */ | |
2027 | if (TREE_VALUE (argument) == NULL_TREE | |
2028 | || TREE_CODE (TREE_VALUE (argument)) != STRING_CST) | |
2029 | return ARM_FT_UNKNOWN; | |
2030 | ||
2031 | arg = TREE_STRING_POINTER (TREE_VALUE (argument)); | |
2032 | ||
2033 | /* Check it against the list of known arguments. */ | |
5a9335ef | 2034 | for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++) |
1d6e90ac NC |
2035 | if (streq (arg, ptr->arg)) |
2036 | return ptr->return_value; | |
6d3d9133 | 2037 | |
05713b80 | 2038 | /* An unrecognized interrupt type. */ |
6d3d9133 NC |
2039 | return ARM_FT_UNKNOWN; |
2040 | } | |
2041 | ||
2042 | /* Computes the type of the current function. */ | |
2043 | ||
2044 | static unsigned long | |
e32bac5b | 2045 | arm_compute_func_type (void) |
6d3d9133 NC |
2046 | { |
2047 | unsigned long type = ARM_FT_UNKNOWN; | |
2048 | tree a; | |
2049 | tree attr; | |
f676971a | 2050 | |
e6d29d15 | 2051 | gcc_assert (TREE_CODE (current_function_decl) == FUNCTION_DECL); |
6d3d9133 NC |
2052 | |
2053 | /* Decide if the current function is volatile. Such functions | |
2054 | never return, and many memory cycles can be saved by not storing | |
2055 | register values that will never be needed again. This optimization | |
2056 | was added to speed up context switching in a kernel application. */ | |
2057 | if (optimize > 0 | |
cf1955dc PB |
2058 | && (TREE_NOTHROW (current_function_decl) |
2059 | || !(flag_unwind_tables | |
d5fabb58 JM |
2060 | || (flag_exceptions |
2061 | && arm_except_unwind_info (&global_options) != UI_SJLJ))) | |
6d3d9133 NC |
2062 | && TREE_THIS_VOLATILE (current_function_decl)) |
2063 | type |= ARM_FT_VOLATILE; | |
f676971a | 2064 | |
6de9cd9a | 2065 | if (cfun->static_chain_decl != NULL) |
6d3d9133 NC |
2066 | type |= ARM_FT_NESTED; |
2067 | ||
91d231cb | 2068 | attr = DECL_ATTRIBUTES (current_function_decl); |
f676971a | 2069 | |
6d3d9133 NC |
2070 | a = lookup_attribute ("naked", attr); |
2071 | if (a != NULL_TREE) | |
2072 | type |= ARM_FT_NAKED; | |
2073 | ||
c9ca9b88 PB |
2074 | a = lookup_attribute ("isr", attr); |
2075 | if (a == NULL_TREE) | |
2076 | a = lookup_attribute ("interrupt", attr); | |
f676971a | 2077 | |
c9ca9b88 PB |
2078 | if (a == NULL_TREE) |
2079 | type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL; | |
6d3d9133 | 2080 | else |
c9ca9b88 | 2081 | type |= arm_isr_value (TREE_VALUE (a)); |
f676971a | 2082 | |
6d3d9133 NC |
2083 | return type; |
2084 | } | |
2085 | ||
2086 | /* Returns the type of the current function. */ | |
2087 | ||
2088 | unsigned long | |
e32bac5b | 2089 | arm_current_func_type (void) |
6d3d9133 NC |
2090 | { |
2091 | if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN) | |
2092 | cfun->machine->func_type = arm_compute_func_type (); | |
2093 | ||
2094 | return cfun->machine->func_type; | |
2095 | } | |
007e61c2 PB |
2096 | |
2097 | bool | |
2098 | arm_allocate_stack_slots_for_args (void) | |
2099 | { | |
2100 | /* Naked functions should not allocate stack slots for arguments. */ | |
2101 | return !IS_NAKED (arm_current_func_type ()); | |
2102 | } | |
2103 | ||
0ef9304b RH |
2104 | \f |
2105 | /* Output assembler code for a block containing the constant parts | |
2106 | of a trampoline, leaving space for the variable parts. | |
2107 | ||
2108 | On the ARM, (if r8 is the static chain regnum, and remembering that | |
2109 | referencing pc adds an offset of 8) the trampoline looks like: | |
2110 | ldr r8, [pc, #0] | |
2111 | ldr pc, [pc] | |
2112 | .word static chain value | |
2113 | .word function's address | |
2114 | XXX FIXME: When the trampoline returns, r8 will be clobbered. */ | |
2115 | ||
2116 | static void | |
2117 | arm_asm_trampoline_template (FILE *f) | |
2118 | { | |
2119 | if (TARGET_ARM) | |
2120 | { | |
2121 | asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", STATIC_CHAIN_REGNUM, PC_REGNUM); | |
2122 | asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", PC_REGNUM, PC_REGNUM); | |
2123 | } | |
2124 | else if (TARGET_THUMB2) | |
2125 | { | |
2126 | /* The Thumb-2 trampoline is similar to the arm implementation. | |
2127 | Unlike 16-bit Thumb, we enter the stub in thumb mode. */ | |
2128 | asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n", | |
2129 | STATIC_CHAIN_REGNUM, PC_REGNUM); | |
2130 | asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n", PC_REGNUM, PC_REGNUM); | |
2131 | } | |
2132 | else | |
2133 | { | |
2134 | ASM_OUTPUT_ALIGN (f, 2); | |
2135 | fprintf (f, "\t.code\t16\n"); | |
2136 | fprintf (f, ".Ltrampoline_start:\n"); | |
2137 | asm_fprintf (f, "\tpush\t{r0, r1}\n"); | |
2138 | asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM); | |
2139 | asm_fprintf (f, "\tmov\t%r, r0\n", STATIC_CHAIN_REGNUM); | |
2140 | asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM); | |
2141 | asm_fprintf (f, "\tstr\tr0, [%r, #4]\n", SP_REGNUM); | |
2142 | asm_fprintf (f, "\tpop\t{r0, %r}\n", PC_REGNUM); | |
2143 | } | |
2144 | assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); | |
2145 | assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); | |
2146 | } | |
2147 | ||
2148 | /* Emit RTL insns to initialize the variable parts of a trampoline. */ | |
2149 | ||
2150 | static void | |
2151 | arm_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) | |
2152 | { | |
2153 | rtx fnaddr, mem, a_tramp; | |
2154 | ||
2155 | emit_block_move (m_tramp, assemble_trampoline_template (), | |
2156 | GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL); | |
2157 | ||
2158 | mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 8 : 12); | |
2159 | emit_move_insn (mem, chain_value); | |
2160 | ||
2161 | mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 12 : 16); | |
2162 | fnaddr = XEXP (DECL_RTL (fndecl), 0); | |
2163 | emit_move_insn (mem, fnaddr); | |
2164 | ||
2165 | a_tramp = XEXP (m_tramp, 0); | |
2166 | emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"), | |
2167 | LCT_NORMAL, VOIDmode, 2, a_tramp, Pmode, | |
2168 | plus_constant (a_tramp, TRAMPOLINE_SIZE), Pmode); | |
2169 | } | |
2170 | ||
2171 | /* Thumb trampolines should be entered in thumb mode, so set | |
2172 | the bottom bit of the address. */ | |
2173 | ||
2174 | static rtx | |
2175 | arm_trampoline_adjust_address (rtx addr) | |
2176 | { | |
2177 | if (TARGET_THUMB) | |
2178 | addr = expand_simple_binop (Pmode, IOR, addr, const1_rtx, | |
2179 | NULL, 0, OPTAB_LIB_WIDEN); | |
2180 | return addr; | |
2181 | } | |
6d3d9133 | 2182 | \f |
f676971a | 2183 | /* Return 1 if it is possible to return using a single instruction. |
a72d4945 RE |
2184 | If SIBLING is non-null, this is a test for a return before a sibling |
2185 | call. SIBLING is the call insn, so we can examine its register usage. */ | |
6d3d9133 | 2186 | |
ff9940b0 | 2187 | int |
a72d4945 | 2188 | use_return_insn (int iscond, rtx sibling) |
ff9940b0 RE |
2189 | { |
2190 | int regno; | |
9b598fa0 | 2191 | unsigned int func_type; |
d5db54a1 | 2192 | unsigned long saved_int_regs; |
a72d4945 | 2193 | unsigned HOST_WIDE_INT stack_adjust; |
5848830f | 2194 | arm_stack_offsets *offsets; |
ff9940b0 | 2195 | |
d5b7b3ae | 2196 | /* Never use a return instruction before reload has run. */ |
6d3d9133 NC |
2197 | if (!reload_completed) |
2198 | return 0; | |
efc2515b | 2199 | |
9b598fa0 RE |
2200 | func_type = arm_current_func_type (); |
2201 | ||
5b3e6663 | 2202 | /* Naked, volatile and stack alignment functions need special |
3a7731fd | 2203 | consideration. */ |
5b3e6663 | 2204 | if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED | ARM_FT_STACKALIGN)) |
6d3d9133 | 2205 | return 0; |
06bea5aa | 2206 | |
a15908a4 PB |
2207 | /* So do interrupt functions that use the frame pointer and Thumb |
2208 | interrupt functions. */ | |
2209 | if (IS_INTERRUPT (func_type) && (frame_pointer_needed || TARGET_THUMB)) | |
06bea5aa | 2210 | return 0; |
a72d4945 | 2211 | |
5848830f PB |
2212 | offsets = arm_get_frame_offsets (); |
2213 | stack_adjust = offsets->outgoing_args - offsets->saved_regs; | |
a72d4945 | 2214 | |
6d3d9133 | 2215 | /* As do variadic functions. */ |
38173d38 | 2216 | if (crtl->args.pretend_args_size |
3cb66fd7 | 2217 | || cfun->machine->uses_anonymous_args |
699a4925 | 2218 | /* Or if the function calls __builtin_eh_return () */ |
e3b5732b | 2219 | || crtl->calls_eh_return |
699a4925 | 2220 | /* Or if the function calls alloca */ |
e3b5732b | 2221 | || cfun->calls_alloca |
a72d4945 RE |
2222 | /* Or if there is a stack adjustment. However, if the stack pointer |
2223 | is saved on the stack, we can use a pre-incrementing stack load. */ | |
ec6237e4 PB |
2224 | || !(stack_adjust == 0 || (TARGET_APCS_FRAME && frame_pointer_needed |
2225 | && stack_adjust == 4))) | |
ff9940b0 RE |
2226 | return 0; |
2227 | ||
954954d1 | 2228 | saved_int_regs = offsets->saved_regs_mask; |
d5db54a1 | 2229 | |
a72d4945 RE |
2230 | /* Unfortunately, the insn |
2231 | ||
2232 | ldmib sp, {..., sp, ...} | |
2233 | ||
2234 | triggers a bug on most SA-110 based devices, such that the stack | |
2235 | pointer won't be correctly restored if the instruction takes a | |
839a4992 | 2236 | page fault. We work around this problem by popping r3 along with |
a72d4945 | 2237 | the other registers, since that is never slower than executing |
f676971a | 2238 | another instruction. |
a72d4945 RE |
2239 | |
2240 | We test for !arm_arch5 here, because code for any architecture | |
2241 | less than this could potentially be run on one of the buggy | |
2242 | chips. */ | |
5b3e6663 | 2243 | if (stack_adjust == 4 && !arm_arch5 && TARGET_ARM) |
a72d4945 RE |
2244 | { |
2245 | /* Validate that r3 is a call-clobbered register (always true in | |
d6b4baa4 | 2246 | the default abi) ... */ |
a72d4945 RE |
2247 | if (!call_used_regs[3]) |
2248 | return 0; | |
2249 | ||
4f5dfed0 JC |
2250 | /* ... that it isn't being used for a return value ... */ |
2251 | if (arm_size_return_regs () >= (4 * UNITS_PER_WORD)) | |
2252 | return 0; | |
2253 | ||
2254 | /* ... or for a tail-call argument ... */ | |
a72d4945 RE |
2255 | if (sibling) |
2256 | { | |
e6d29d15 | 2257 | gcc_assert (GET_CODE (sibling) == CALL_INSN); |
a72d4945 RE |
2258 | |
2259 | if (find_regno_fusage (sibling, USE, 3)) | |
2260 | return 0; | |
2261 | } | |
2262 | ||
2263 | /* ... and that there are no call-saved registers in r0-r2 | |
2264 | (always true in the default ABI). */ | |
2265 | if (saved_int_regs & 0x7) | |
2266 | return 0; | |
2267 | } | |
2268 | ||
b111229a | 2269 | /* Can't be done if interworking with Thumb, and any registers have been |
d5db54a1 | 2270 | stacked. */ |
a15908a4 | 2271 | if (TARGET_INTERWORK && saved_int_regs != 0 && !IS_INTERRUPT(func_type)) |
b36ba79f | 2272 | return 0; |
d5db54a1 RE |
2273 | |
2274 | /* On StrongARM, conditional returns are expensive if they aren't | |
2275 | taken and multiple registers have been stacked. */ | |
abac3b49 | 2276 | if (iscond && arm_tune_strongarm) |
6ed30148 | 2277 | { |
f676971a | 2278 | /* Conditional return when just the LR is stored is a simple |
d5db54a1 RE |
2279 | conditional-load instruction, that's not expensive. */ |
2280 | if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM)) | |
2281 | return 0; | |
6ed30148 | 2282 | |
020a4035 RE |
2283 | if (flag_pic |
2284 | && arm_pic_register != INVALID_REGNUM | |
6fb5fa3c | 2285 | && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM)) |
b111229a | 2286 | return 0; |
6ed30148 | 2287 | } |
d5db54a1 RE |
2288 | |
2289 | /* If there are saved registers but the LR isn't saved, then we need | |
2290 | two instructions for the return. */ | |
2291 | if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM))) | |
2292 | return 0; | |
2293 | ||
3b684012 | 2294 | /* Can't be done if any of the FPA regs are pushed, |
6d3d9133 | 2295 | since this also requires an insn. */ |
9b66ebb1 PB |
2296 | if (TARGET_HARD_FLOAT && TARGET_FPA) |
2297 | for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++) | |
6fb5fa3c | 2298 | if (df_regs_ever_live_p (regno) && !call_used_regs[regno]) |
9b66ebb1 PB |
2299 | return 0; |
2300 | ||
2301 | /* Likewise VFP regs. */ | |
2302 | if (TARGET_HARD_FLOAT && TARGET_VFP) | |
2303 | for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++) | |
6fb5fa3c | 2304 | if (df_regs_ever_live_p (regno) && !call_used_regs[regno]) |
d5b7b3ae | 2305 | return 0; |
ff9940b0 | 2306 | |
5a9335ef NC |
2307 | if (TARGET_REALLY_IWMMXT) |
2308 | for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++) | |
6fb5fa3c | 2309 | if (df_regs_ever_live_p (regno) && ! call_used_regs[regno]) |
5a9335ef NC |
2310 | return 0; |
2311 | ||
ff9940b0 RE |
2312 | return 1; |
2313 | } | |
2314 | ||
cce8749e CH |
2315 | /* Return TRUE if int I is a valid immediate ARM constant. */ |
2316 | ||
2317 | int | |
e32bac5b | 2318 | const_ok_for_arm (HOST_WIDE_INT i) |
cce8749e | 2319 | { |
4642ccb1 | 2320 | int lowbit; |
e0b92319 | 2321 | |
f676971a | 2322 | /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must |
56636818 | 2323 | be all zero, or all one. */ |
30cf4896 KG |
2324 | if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0 |
2325 | && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) | |
2326 | != ((~(unsigned HOST_WIDE_INT) 0) | |
2327 | & ~(unsigned HOST_WIDE_INT) 0xffffffff))) | |
56636818 | 2328 | return FALSE; |
f676971a | 2329 | |
4642ccb1 | 2330 | i &= (unsigned HOST_WIDE_INT) 0xffffffff; |
e0b92319 | 2331 | |
4642ccb1 RE |
2332 | /* Fast return for 0 and small values. We must do this for zero, since |
2333 | the code below can't handle that one case. */ | |
2334 | if ((i & ~(unsigned HOST_WIDE_INT) 0xff) == 0) | |
e2c671ba RE |
2335 | return TRUE; |
2336 | ||
5b3e6663 PB |
2337 | /* Get the number of trailing zeros. */ |
2338 | lowbit = ffs((int) i) - 1; | |
2339 | ||
2340 | /* Only even shifts are allowed in ARM mode so round down to the | |
2341 | nearest even number. */ | |
2342 | if (TARGET_ARM) | |
2343 | lowbit &= ~1; | |
4642ccb1 RE |
2344 | |
2345 | if ((i & ~(((unsigned HOST_WIDE_INT) 0xff) << lowbit)) == 0) | |
2346 | return TRUE; | |
5b3e6663 PB |
2347 | |
2348 | if (TARGET_ARM) | |
2349 | { | |
2350 | /* Allow rotated constants in ARM mode. */ | |
2351 | if (lowbit <= 4 | |
4642ccb1 RE |
2352 | && ((i & ~0xc000003f) == 0 |
2353 | || (i & ~0xf000000f) == 0 | |
2354 | || (i & ~0xfc000003) == 0)) | |
5b3e6663 PB |
2355 | return TRUE; |
2356 | } | |
2357 | else | |
2358 | { | |
2359 | HOST_WIDE_INT v; | |
2360 | ||
d724c8f0 | 2361 | /* Allow repeated patterns 0x00XY00XY or 0xXYXYXYXY. */ |
5b3e6663 PB |
2362 | v = i & 0xff; |
2363 | v |= v << 16; | |
2364 | if (i == v || i == (v | (v << 8))) | |
2365 | return TRUE; | |
d724c8f0 AS |
2366 | |
2367 | /* Allow repeated pattern 0xXY00XY00. */ | |
2368 | v = i & 0xff00; | |
2369 | v |= v << 16; | |
2370 | if (i == v) | |
2371 | return TRUE; | |
5b3e6663 | 2372 | } |
cce8749e | 2373 | |
f3bb6135 RE |
2374 | return FALSE; |
2375 | } | |
cce8749e | 2376 | |
6354dc9b | 2377 | /* Return true if I is a valid constant for the operation CODE. */ |
74bbc178 | 2378 | static int |
e32bac5b | 2379 | const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code) |
e2c671ba RE |
2380 | { |
2381 | if (const_ok_for_arm (i)) | |
2382 | return 1; | |
2383 | ||
2384 | switch (code) | |
2385 | { | |
bc2c1a60 AS |
2386 | case SET: |
2387 | /* See if we can use movw. */ | |
2388 | if (arm_arch_thumb2 && (i & 0xffff0000) == 0) | |
2389 | return 1; | |
2390 | else | |
0127c76f RR |
2391 | /* Otherwise, try mvn. */ |
2392 | return const_ok_for_arm (ARM_SIGN_EXTEND (~i)); | |
bc2c1a60 | 2393 | |
e2c671ba | 2394 | case PLUS: |
d5a0a47b RE |
2395 | case COMPARE: |
2396 | case EQ: | |
2397 | case NE: | |
2398 | case GT: | |
2399 | case LE: | |
2400 | case LT: | |
2401 | case GE: | |
2402 | case GEU: | |
2403 | case LTU: | |
2404 | case GTU: | |
2405 | case LEU: | |
2406 | case UNORDERED: | |
2407 | case ORDERED: | |
2408 | case UNEQ: | |
2409 | case UNGE: | |
2410 | case UNLT: | |
2411 | case UNGT: | |
2412 | case UNLE: | |
e2c671ba RE |
2413 | return const_ok_for_arm (ARM_SIGN_EXTEND (-i)); |
2414 | ||
2415 | case MINUS: /* Should only occur with (MINUS I reg) => rsb */ | |
2416 | case XOR: | |
a7994a57 RR |
2417 | return 0; |
2418 | ||
e2c671ba | 2419 | case IOR: |
a7994a57 RR |
2420 | if (TARGET_THUMB2) |
2421 | return const_ok_for_arm (ARM_SIGN_EXTEND (~i)); | |
e2c671ba RE |
2422 | return 0; |
2423 | ||
2424 | case AND: | |
2425 | return const_ok_for_arm (ARM_SIGN_EXTEND (~i)); | |
2426 | ||
2427 | default: | |
e6d29d15 | 2428 | gcc_unreachable (); |
e2c671ba RE |
2429 | } |
2430 | } | |
2431 | ||
2432 | /* Emit a sequence of insns to handle a large constant. | |
2433 | CODE is the code of the operation required, it can be any of SET, PLUS, | |
2434 | IOR, AND, XOR, MINUS; | |
2435 | MODE is the mode in which the operation is being performed; | |
2436 | VAL is the integer to operate on; | |
2437 | SOURCE is the other operand (a register, or a null-pointer for SET); | |
2438 | SUBTARGETS means it is safe to create scratch registers if that will | |
2b835d68 RE |
2439 | either produce a simpler sequence, or we will want to cse the values. |
2440 | Return value is the number of insns emitted. */ | |
e2c671ba | 2441 | |
5b3e6663 | 2442 | /* ??? Tweak this for thumb2. */ |
e2c671ba | 2443 | int |
a406f566 | 2444 | arm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn, |
e32bac5b | 2445 | HOST_WIDE_INT val, rtx target, rtx source, int subtargets) |
2b835d68 | 2446 | { |
a406f566 MM |
2447 | rtx cond; |
2448 | ||
2449 | if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC) | |
2450 | cond = COND_EXEC_TEST (PATTERN (insn)); | |
2451 | else | |
2452 | cond = NULL_RTX; | |
2453 | ||
2b835d68 RE |
2454 | if (subtargets || code == SET |
2455 | || (GET_CODE (target) == REG && GET_CODE (source) == REG | |
2456 | && REGNO (target) != REGNO (source))) | |
2457 | { | |
4b632bf1 | 2458 | /* After arm_reorg has been called, we can't fix up expensive |
05713b80 | 2459 | constants by pushing them into memory so we must synthesize |
4b632bf1 RE |
2460 | them in-line, regardless of the cost. This is only likely to |
2461 | be more costly on chips that have load delay slots and we are | |
2462 | compiling without running the scheduler (so no splitting | |
aec3cfba NC |
2463 | occurred before the final instruction emission). |
2464 | ||
2465 | Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c | |
aec3cfba | 2466 | */ |
5895f793 | 2467 | if (!after_arm_reorg |
a406f566 | 2468 | && !cond |
f676971a | 2469 | && (arm_gen_constant (code, mode, NULL_RTX, val, target, source, |
a406f566 | 2470 | 1, 0) |
1b78f575 RE |
2471 | > (arm_constant_limit (optimize_function_for_size_p (cfun)) |
2472 | + (code != SET)))) | |
2b835d68 RE |
2473 | { |
2474 | if (code == SET) | |
2475 | { | |
2476 | /* Currently SET is the only monadic value for CODE, all | |
2477 | the rest are diadic. */ | |
571191af PB |
2478 | if (TARGET_USE_MOVT) |
2479 | arm_emit_movpair (target, GEN_INT (val)); | |
2480 | else | |
2481 | emit_set_insn (target, GEN_INT (val)); | |
2482 | ||
2b835d68 RE |
2483 | return 1; |
2484 | } | |
2485 | else | |
2486 | { | |
2487 | rtx temp = subtargets ? gen_reg_rtx (mode) : target; | |
2488 | ||
571191af PB |
2489 | if (TARGET_USE_MOVT) |
2490 | arm_emit_movpair (temp, GEN_INT (val)); | |
2491 | else | |
2492 | emit_set_insn (temp, GEN_INT (val)); | |
2493 | ||
2b835d68 RE |
2494 | /* For MINUS, the value is subtracted from, since we never |
2495 | have subtraction of a constant. */ | |
2496 | if (code == MINUS) | |
d66437c5 | 2497 | emit_set_insn (target, gen_rtx_MINUS (mode, temp, source)); |
2b835d68 | 2498 | else |
d66437c5 RE |
2499 | emit_set_insn (target, |
2500 | gen_rtx_fmt_ee (code, mode, source, temp)); | |
2b835d68 RE |
2501 | return 2; |
2502 | } | |
2503 | } | |
2504 | } | |
2505 | ||
f676971a | 2506 | return arm_gen_constant (code, mode, cond, val, target, source, subtargets, |
a406f566 | 2507 | 1); |
2b835d68 RE |
2508 | } |
2509 | ||
162e4591 RE |
2510 | /* Return the number of instructions required to synthesize the given |
2511 | constant, if we start emitting them from bit-position I. */ | |
ceebdb09 | 2512 | static int |
e32bac5b | 2513 | count_insns_for_constant (HOST_WIDE_INT remainder, int i) |
ceebdb09 PB |
2514 | { |
2515 | HOST_WIDE_INT temp1; | |
162e4591 | 2516 | int step_size = TARGET_ARM ? 2 : 1; |
ceebdb09 | 2517 | int num_insns = 0; |
162e4591 RE |
2518 | |
2519 | gcc_assert (TARGET_ARM || i == 0); | |
2520 | ||
ceebdb09 PB |
2521 | do |
2522 | { | |
2523 | int end; | |
f676971a | 2524 | |
ceebdb09 PB |
2525 | if (i <= 0) |
2526 | i += 32; | |
162e4591 | 2527 | if (remainder & (((1 << step_size) - 1) << (i - step_size))) |
ceebdb09 PB |
2528 | { |
2529 | end = i - 8; | |
2530 | if (end < 0) | |
2531 | end += 32; | |
2532 | temp1 = remainder & ((0x0ff << end) | |
2533 | | ((i < end) ? (0xff >> (32 - end)) : 0)); | |
2534 | remainder &= ~temp1; | |
2535 | num_insns++; | |
162e4591 | 2536 | i -= 8 - step_size; |
ceebdb09 | 2537 | } |
162e4591 | 2538 | i -= step_size; |
ceebdb09 PB |
2539 | } while (remainder); |
2540 | return num_insns; | |
2541 | } | |
2542 | ||
162e4591 | 2543 | static int |
90e77553 | 2544 | find_best_start (unsigned HOST_WIDE_INT remainder) |
162e4591 RE |
2545 | { |
2546 | int best_consecutive_zeros = 0; | |
2547 | int i; | |
2548 | int best_start = 0; | |
2549 | ||
2550 | /* If we aren't targetting ARM, the best place to start is always at | |
2551 | the bottom. */ | |
2552 | if (! TARGET_ARM) | |
2553 | return 0; | |
2554 | ||
2555 | for (i = 0; i < 32; i += 2) | |
2556 | { | |
2557 | int consecutive_zeros = 0; | |
2558 | ||
2559 | if (!(remainder & (3 << i))) | |
2560 | { | |
2561 | while ((i < 32) && !(remainder & (3 << i))) | |
2562 | { | |
2563 | consecutive_zeros += 2; | |
2564 | i += 2; | |
2565 | } | |
2566 | if (consecutive_zeros > best_consecutive_zeros) | |
2567 | { | |
2568 | best_consecutive_zeros = consecutive_zeros; | |
2569 | best_start = i - consecutive_zeros; | |
2570 | } | |
2571 | i -= 2; | |
2572 | } | |
2573 | } | |
2574 | ||
2575 | /* So long as it won't require any more insns to do so, it's | |
2576 | desirable to emit a small constant (in bits 0...9) in the last | |
2577 | insn. This way there is more chance that it can be combined with | |
2578 | a later addressing insn to form a pre-indexed load or store | |
2579 | operation. Consider: | |
2580 | ||
2581 | *((volatile int *)0xe0000100) = 1; | |
2582 | *((volatile int *)0xe0000110) = 2; | |
2583 | ||
2584 | We want this to wind up as: | |
2585 | ||
2586 | mov rA, #0xe0000000 | |
2587 | mov rB, #1 | |
2588 | str rB, [rA, #0x100] | |
2589 | mov rB, #2 | |
2590 | str rB, [rA, #0x110] | |
2591 | ||
2592 | rather than having to synthesize both large constants from scratch. | |
2593 | ||
2594 | Therefore, we calculate how many insns would be required to emit | |
2595 | the constant starting from `best_start', and also starting from | |
2596 | zero (i.e. with bit 31 first to be output). If `best_start' doesn't | |
2597 | yield a shorter sequence, we may as well use zero. */ | |
2598 | if (best_start != 0 | |
2599 | && ((((unsigned HOST_WIDE_INT) 1) << best_start) < remainder) | |
2600 | && (count_insns_for_constant (remainder, 0) <= | |
2601 | count_insns_for_constant (remainder, best_start))) | |
2602 | best_start = 0; | |
2603 | ||
2604 | return best_start; | |
2605 | } | |
2606 | ||
a406f566 MM |
2607 | /* Emit an instruction with the indicated PATTERN. If COND is |
2608 | non-NULL, conditionalize the execution of the instruction on COND | |
2609 | being true. */ | |
2610 | ||
2611 | static void | |
2612 | emit_constant_insn (rtx cond, rtx pattern) | |
2613 | { | |
2614 | if (cond) | |
2615 | pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern); | |
2616 | emit_insn (pattern); | |
2617 | } | |
2618 | ||
2b835d68 RE |
2619 | /* As above, but extra parameter GENERATE which, if clear, suppresses |
2620 | RTL generation. */ | |
5b3e6663 | 2621 | /* ??? This needs more work for thumb2. */ |
1d6e90ac | 2622 | |
d5b7b3ae | 2623 | static int |
a406f566 | 2624 | arm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond, |
e32bac5b RE |
2625 | HOST_WIDE_INT val, rtx target, rtx source, int subtargets, |
2626 | int generate) | |
e2c671ba | 2627 | { |
e2c671ba RE |
2628 | int can_invert = 0; |
2629 | int can_negate = 0; | |
162e4591 | 2630 | int final_invert = 0; |
e2c671ba RE |
2631 | int i; |
2632 | int num_bits_set = 0; | |
2633 | int set_sign_bit_copies = 0; | |
2634 | int clear_sign_bit_copies = 0; | |
2635 | int clear_zero_bit_copies = 0; | |
2636 | int set_zero_bit_copies = 0; | |
2637 | int insns = 0; | |
e2c671ba | 2638 | unsigned HOST_WIDE_INT temp1, temp2; |
30cf4896 | 2639 | unsigned HOST_WIDE_INT remainder = val & 0xffffffff; |
162e4591 | 2640 | int step_size = TARGET_ARM ? 2 : 1; |
e2c671ba | 2641 | |
d5b7b3ae | 2642 | /* Find out which operations are safe for a given CODE. Also do a quick |
e2c671ba RE |
2643 | check for degenerate cases; these can occur when DImode operations |
2644 | are split. */ | |
2645 | switch (code) | |
2646 | { | |
2647 | case SET: | |
2648 | can_invert = 1; | |
e2c671ba RE |
2649 | can_negate = 1; |
2650 | break; | |
2651 | ||
2652 | case PLUS: | |
2653 | can_negate = 1; | |
e2c671ba RE |
2654 | break; |
2655 | ||
2656 | case IOR: | |
30cf4896 | 2657 | if (remainder == 0xffffffff) |
e2c671ba | 2658 | { |
2b835d68 | 2659 | if (generate) |
a406f566 MM |
2660 | emit_constant_insn (cond, |
2661 | gen_rtx_SET (VOIDmode, target, | |
2662 | GEN_INT (ARM_SIGN_EXTEND (val)))); | |
e2c671ba RE |
2663 | return 1; |
2664 | } | |
a7994a57 | 2665 | |
e2c671ba RE |
2666 | if (remainder == 0) |
2667 | { | |
2668 | if (reload_completed && rtx_equal_p (target, source)) | |
2669 | return 0; | |
a7994a57 | 2670 | |
2b835d68 | 2671 | if (generate) |
a406f566 MM |
2672 | emit_constant_insn (cond, |
2673 | gen_rtx_SET (VOIDmode, target, source)); | |
e2c671ba RE |
2674 | return 1; |
2675 | } | |
2676 | break; | |
2677 | ||
2678 | case AND: | |
2679 | if (remainder == 0) | |
2680 | { | |
2b835d68 | 2681 | if (generate) |
a406f566 MM |
2682 | emit_constant_insn (cond, |
2683 | gen_rtx_SET (VOIDmode, target, const0_rtx)); | |
e2c671ba RE |
2684 | return 1; |
2685 | } | |
30cf4896 | 2686 | if (remainder == 0xffffffff) |
e2c671ba RE |
2687 | { |
2688 | if (reload_completed && rtx_equal_p (target, source)) | |
2689 | return 0; | |
2b835d68 | 2690 | if (generate) |
a406f566 MM |
2691 | emit_constant_insn (cond, |
2692 | gen_rtx_SET (VOIDmode, target, source)); | |
e2c671ba RE |
2693 | return 1; |
2694 | } | |
2695 | can_invert = 1; | |
2696 | break; | |
2697 | ||
2698 | case XOR: | |
2699 | if (remainder == 0) | |
2700 | { | |
2701 | if (reload_completed && rtx_equal_p (target, source)) | |
2702 | return 0; | |
2b835d68 | 2703 | if (generate) |
a406f566 MM |
2704 | emit_constant_insn (cond, |
2705 | gen_rtx_SET (VOIDmode, target, source)); | |
e2c671ba RE |
2706 | return 1; |
2707 | } | |
e0b92319 | 2708 | |
162e4591 RE |
2709 | if (remainder == 0xffffffff) |
2710 | { | |
2711 | if (generate) | |
2712 | emit_constant_insn (cond, | |
2713 | gen_rtx_SET (VOIDmode, target, | |
2714 | gen_rtx_NOT (mode, source))); | |
2715 | return 1; | |
2716 | } | |
2717 | break; | |
e2c671ba RE |
2718 | |
2719 | case MINUS: | |
2720 | /* We treat MINUS as (val - source), since (source - val) is always | |
2721 | passed as (source + (-val)). */ | |
2722 | if (remainder == 0) | |
2723 | { | |
2b835d68 | 2724 | if (generate) |
a406f566 MM |
2725 | emit_constant_insn (cond, |
2726 | gen_rtx_SET (VOIDmode, target, | |
2727 | gen_rtx_NEG (mode, source))); | |
e2c671ba RE |
2728 | return 1; |
2729 | } | |
2730 | if (const_ok_for_arm (val)) | |
2731 | { | |
2b835d68 | 2732 | if (generate) |
a406f566 | 2733 | emit_constant_insn (cond, |
f676971a | 2734 | gen_rtx_SET (VOIDmode, target, |
a406f566 MM |
2735 | gen_rtx_MINUS (mode, GEN_INT (val), |
2736 | source))); | |
e2c671ba RE |
2737 | return 1; |
2738 | } | |
2739 | can_negate = 1; | |
2740 | ||
2741 | break; | |
2742 | ||
2743 | default: | |
e6d29d15 | 2744 | gcc_unreachable (); |
e2c671ba RE |
2745 | } |
2746 | ||
6354dc9b | 2747 | /* If we can do it in one insn get out quickly. */ |
bc2c1a60 | 2748 | if (const_ok_for_op (val, code)) |
e2c671ba | 2749 | { |
2b835d68 | 2750 | if (generate) |
a406f566 MM |
2751 | emit_constant_insn (cond, |
2752 | gen_rtx_SET (VOIDmode, target, | |
f676971a | 2753 | (source |
a406f566 MM |
2754 | ? gen_rtx_fmt_ee (code, mode, source, |
2755 | GEN_INT (val)) | |
2756 | : GEN_INT (val)))); | |
e2c671ba RE |
2757 | return 1; |
2758 | } | |
2759 | ||
e2c671ba | 2760 | /* Calculate a few attributes that may be useful for specific |
6354dc9b | 2761 | optimizations. */ |
a7994a57 | 2762 | /* Count number of leading zeros. */ |
e2c671ba RE |
2763 | for (i = 31; i >= 0; i--) |
2764 | { | |
2765 | if ((remainder & (1 << i)) == 0) | |
2766 | clear_sign_bit_copies++; | |
2767 | else | |
2768 | break; | |
2769 | } | |
2770 | ||
a7994a57 | 2771 | /* Count number of leading 1's. */ |
e2c671ba RE |
2772 | for (i = 31; i >= 0; i--) |
2773 | { | |
2774 | if ((remainder & (1 << i)) != 0) | |
2775 | set_sign_bit_copies++; | |
2776 | else | |
2777 | break; | |
2778 | } | |
2779 | ||
a7994a57 | 2780 | /* Count number of trailing zero's. */ |
e2c671ba RE |
2781 | for (i = 0; i <= 31; i++) |
2782 | { | |
2783 | if ((remainder & (1 << i)) == 0) | |
2784 | clear_zero_bit_copies++; | |
2785 | else | |
2786 | break; | |
2787 | } | |
2788 | ||
a7994a57 | 2789 | /* Count number of trailing 1's. */ |
e2c671ba RE |
2790 | for (i = 0; i <= 31; i++) |
2791 | { | |
2792 | if ((remainder & (1 << i)) != 0) | |
2793 | set_zero_bit_copies++; | |
2794 | else | |
2795 | break; | |
2796 | } | |
2797 | ||
2798 | switch (code) | |
2799 | { | |
2800 | case SET: | |
2801 | /* See if we can do this by sign_extending a constant that is known | |
2802 | to be negative. This is a good, way of doing it, since the shift | |
2803 | may well merge into a subsequent insn. */ | |
2804 | if (set_sign_bit_copies > 1) | |
2805 | { | |
2806 | if (const_ok_for_arm | |
f676971a | 2807 | (temp1 = ARM_SIGN_EXTEND (remainder |
e2c671ba RE |
2808 | << (set_sign_bit_copies - 1)))) |
2809 | { | |
2b835d68 RE |
2810 | if (generate) |
2811 | { | |
d499463f | 2812 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
a406f566 | 2813 | emit_constant_insn (cond, |
f676971a | 2814 | gen_rtx_SET (VOIDmode, new_src, |
a406f566 MM |
2815 | GEN_INT (temp1))); |
2816 | emit_constant_insn (cond, | |
f676971a | 2817 | gen_ashrsi3 (target, new_src, |
a406f566 | 2818 | GEN_INT (set_sign_bit_copies - 1))); |
2b835d68 | 2819 | } |
e2c671ba RE |
2820 | return 2; |
2821 | } | |
2822 | /* For an inverted constant, we will need to set the low bits, | |
2823 | these will be shifted out of harm's way. */ | |
2824 | temp1 |= (1 << (set_sign_bit_copies - 1)) - 1; | |
2825 | if (const_ok_for_arm (~temp1)) | |
2826 | { | |
2b835d68 RE |
2827 | if (generate) |
2828 | { | |
d499463f | 2829 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
a406f566 MM |
2830 | emit_constant_insn (cond, |
2831 | gen_rtx_SET (VOIDmode, new_src, | |
2832 | GEN_INT (temp1))); | |
2833 | emit_constant_insn (cond, | |
f676971a | 2834 | gen_ashrsi3 (target, new_src, |
a406f566 | 2835 | GEN_INT (set_sign_bit_copies - 1))); |
2b835d68 | 2836 | } |
e2c671ba RE |
2837 | return 2; |
2838 | } | |
2839 | } | |
2840 | ||
c87e6352 RE |
2841 | /* See if we can calculate the value as the difference between two |
2842 | valid immediates. */ | |
2843 | if (clear_sign_bit_copies + clear_zero_bit_copies <= 16) | |
2844 | { | |
2845 | int topshift = clear_sign_bit_copies & ~1; | |
2846 | ||
fa2c88a0 RE |
2847 | temp1 = ARM_SIGN_EXTEND ((remainder + (0x00800000 >> topshift)) |
2848 | & (0xff000000 >> topshift)); | |
c87e6352 RE |
2849 | |
2850 | /* If temp1 is zero, then that means the 9 most significant | |
2851 | bits of remainder were 1 and we've caused it to overflow. | |
2852 | When topshift is 0 we don't need to do anything since we | |
2853 | can borrow from 'bit 32'. */ | |
2854 | if (temp1 == 0 && topshift != 0) | |
2855 | temp1 = 0x80000000 >> (topshift - 1); | |
2856 | ||
fa2c88a0 | 2857 | temp2 = ARM_SIGN_EXTEND (temp1 - remainder); |
e0b92319 | 2858 | |
c87e6352 RE |
2859 | if (const_ok_for_arm (temp2)) |
2860 | { | |
2861 | if (generate) | |
2862 | { | |
2863 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; | |
2864 | emit_constant_insn (cond, | |
2865 | gen_rtx_SET (VOIDmode, new_src, | |
2866 | GEN_INT (temp1))); | |
2867 | emit_constant_insn (cond, | |
2868 | gen_addsi3 (target, new_src, | |
2869 | GEN_INT (-temp2))); | |
2870 | } | |
2871 | ||
2872 | return 2; | |
2873 | } | |
2874 | } | |
2875 | ||
e2c671ba RE |
2876 | /* See if we can generate this by setting the bottom (or the top) |
2877 | 16 bits, and then shifting these into the other half of the | |
2878 | word. We only look for the simplest cases, to do more would cost | |
2879 | too much. Be careful, however, not to generate this when the | |
2880 | alternative would take fewer insns. */ | |
30cf4896 | 2881 | if (val & 0xffff0000) |
e2c671ba | 2882 | { |
30cf4896 | 2883 | temp1 = remainder & 0xffff0000; |
e2c671ba RE |
2884 | temp2 = remainder & 0x0000ffff; |
2885 | ||
6354dc9b | 2886 | /* Overlaps outside this range are best done using other methods. */ |
e2c671ba RE |
2887 | for (i = 9; i < 24; i++) |
2888 | { | |
30cf4896 | 2889 | if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder) |
5895f793 | 2890 | && !const_ok_for_arm (temp2)) |
e2c671ba | 2891 | { |
d499463f RE |
2892 | rtx new_src = (subtargets |
2893 | ? (generate ? gen_reg_rtx (mode) : NULL_RTX) | |
2894 | : target); | |
a406f566 | 2895 | insns = arm_gen_constant (code, mode, cond, temp2, new_src, |
2b835d68 | 2896 | source, subtargets, generate); |
e2c671ba | 2897 | source = new_src; |
2b835d68 | 2898 | if (generate) |
f676971a | 2899 | emit_constant_insn |
a406f566 MM |
2900 | (cond, |
2901 | gen_rtx_SET | |
2902 | (VOIDmode, target, | |
2903 | gen_rtx_IOR (mode, | |
2904 | gen_rtx_ASHIFT (mode, source, | |
2905 | GEN_INT (i)), | |
2906 | source))); | |
e2c671ba RE |
2907 | return insns + 1; |
2908 | } | |
2909 | } | |
2910 | ||
6354dc9b | 2911 | /* Don't duplicate cases already considered. */ |
e2c671ba RE |
2912 | for (i = 17; i < 24; i++) |
2913 | { | |
2914 | if (((temp1 | (temp1 >> i)) == remainder) | |
5895f793 | 2915 | && !const_ok_for_arm (temp1)) |
e2c671ba | 2916 | { |
d499463f RE |
2917 | rtx new_src = (subtargets |
2918 | ? (generate ? gen_reg_rtx (mode) : NULL_RTX) | |
2919 | : target); | |
a406f566 | 2920 | insns = arm_gen_constant (code, mode, cond, temp1, new_src, |
2b835d68 | 2921 | source, subtargets, generate); |
e2c671ba | 2922 | source = new_src; |
2b835d68 | 2923 | if (generate) |
a406f566 MM |
2924 | emit_constant_insn |
2925 | (cond, | |
2926 | gen_rtx_SET (VOIDmode, target, | |
43cffd11 RE |
2927 | gen_rtx_IOR |
2928 | (mode, | |
2929 | gen_rtx_LSHIFTRT (mode, source, | |
2930 | GEN_INT (i)), | |
2931 | source))); | |
e2c671ba RE |
2932 | return insns + 1; |
2933 | } | |
2934 | } | |
2935 | } | |
2936 | break; | |
2937 | ||
2938 | case IOR: | |
2939 | case XOR: | |
7b64da89 RE |
2940 | /* If we have IOR or XOR, and the constant can be loaded in a |
2941 | single instruction, and we can find a temporary to put it in, | |
e2c671ba RE |
2942 | then this can be done in two instructions instead of 3-4. */ |
2943 | if (subtargets | |
d499463f | 2944 | /* TARGET can't be NULL if SUBTARGETS is 0 */ |
5895f793 | 2945 | || (reload_completed && !reg_mentioned_p (target, source))) |
e2c671ba | 2946 | { |
5895f793 | 2947 | if (const_ok_for_arm (ARM_SIGN_EXTEND (~val))) |
e2c671ba | 2948 | { |
2b835d68 RE |
2949 | if (generate) |
2950 | { | |
2951 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
e2c671ba | 2952 | |
a406f566 | 2953 | emit_constant_insn (cond, |
f676971a | 2954 | gen_rtx_SET (VOIDmode, sub, |
a406f566 MM |
2955 | GEN_INT (val))); |
2956 | emit_constant_insn (cond, | |
f676971a | 2957 | gen_rtx_SET (VOIDmode, target, |
a406f566 MM |
2958 | gen_rtx_fmt_ee (code, mode, |
2959 | source, sub))); | |
2b835d68 | 2960 | } |
e2c671ba RE |
2961 | return 2; |
2962 | } | |
2963 | } | |
2964 | ||
2965 | if (code == XOR) | |
2966 | break; | |
2967 | ||
a7994a57 RR |
2968 | /* Convert. |
2969 | x = y | constant ( which is composed of set_sign_bit_copies of leading 1s | |
2970 | and the remainder 0s for e.g. 0xfff00000) | |
2971 | x = ~(~(y ashift set_sign_bit_copies) lshiftrt set_sign_bit_copies) | |
2972 | ||
2973 | This can be done in 2 instructions by using shifts with mov or mvn. | |
2974 | e.g. for | |
2975 | x = x | 0xfff00000; | |
2976 | we generate. | |
2977 | mvn r0, r0, asl #12 | |
2978 | mvn r0, r0, lsr #12 */ | |
e2c671ba RE |
2979 | if (set_sign_bit_copies > 8 |
2980 | && (val & (-1 << (32 - set_sign_bit_copies))) == val) | |
2981 | { | |
2b835d68 RE |
2982 | if (generate) |
2983 | { | |
2984 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
2985 | rtx shift = GEN_INT (set_sign_bit_copies); | |
2986 | ||
f676971a | 2987 | emit_constant_insn |
a406f566 MM |
2988 | (cond, |
2989 | gen_rtx_SET (VOIDmode, sub, | |
f676971a | 2990 | gen_rtx_NOT (mode, |
a406f566 | 2991 | gen_rtx_ASHIFT (mode, |
f676971a | 2992 | source, |
a406f566 | 2993 | shift)))); |
f676971a | 2994 | emit_constant_insn |
a406f566 MM |
2995 | (cond, |
2996 | gen_rtx_SET (VOIDmode, target, | |
2997 | gen_rtx_NOT (mode, | |
2998 | gen_rtx_LSHIFTRT (mode, sub, | |
2999 | shift)))); | |
2b835d68 | 3000 | } |
e2c671ba RE |
3001 | return 2; |
3002 | } | |
3003 | ||
a7994a57 RR |
3004 | /* Convert |
3005 | x = y | constant (which has set_zero_bit_copies number of trailing ones). | |
3006 | to | |
3007 | x = ~((~y lshiftrt set_zero_bit_copies) ashift set_zero_bit_copies). | |
3008 | ||
3009 | For eg. r0 = r0 | 0xfff | |
3010 | mvn r0, r0, lsr #12 | |
3011 | mvn r0, r0, asl #12 | |
3012 | ||
3013 | */ | |
e2c671ba RE |
3014 | if (set_zero_bit_copies > 8 |
3015 | && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder) | |
3016 | { | |
2b835d68 RE |
3017 | if (generate) |
3018 | { | |
3019 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
3020 | rtx shift = GEN_INT (set_zero_bit_copies); | |
3021 | ||
a406f566 MM |
3022 | emit_constant_insn |
3023 | (cond, | |
3024 | gen_rtx_SET (VOIDmode, sub, | |
3025 | gen_rtx_NOT (mode, | |
3026 | gen_rtx_LSHIFTRT (mode, | |
3027 | source, | |
3028 | shift)))); | |
f676971a | 3029 | emit_constant_insn |
a406f566 MM |
3030 | (cond, |
3031 | gen_rtx_SET (VOIDmode, target, | |
3032 | gen_rtx_NOT (mode, | |
3033 | gen_rtx_ASHIFT (mode, sub, | |
3034 | shift)))); | |
2b835d68 | 3035 | } |
e2c671ba RE |
3036 | return 2; |
3037 | } | |
3038 | ||
a7994a57 RR |
3039 | /* This will never be reached for Thumb2 because orn is a valid |
3040 | instruction. This is for Thumb1 and the ARM 32 bit cases. | |
3041 | ||
3042 | x = y | constant (such that ~constant is a valid constant) | |
3043 | Transform this to | |
3044 | x = ~(~y & ~constant). | |
3045 | */ | |
5895f793 | 3046 | if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val))) |
e2c671ba | 3047 | { |
2b835d68 RE |
3048 | if (generate) |
3049 | { | |
3050 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
a406f566 MM |
3051 | emit_constant_insn (cond, |
3052 | gen_rtx_SET (VOIDmode, sub, | |
3053 | gen_rtx_NOT (mode, source))); | |
2b835d68 RE |
3054 | source = sub; |
3055 | if (subtargets) | |
3056 | sub = gen_reg_rtx (mode); | |
a406f566 MM |
3057 | emit_constant_insn (cond, |
3058 | gen_rtx_SET (VOIDmode, sub, | |
f676971a | 3059 | gen_rtx_AND (mode, source, |
a406f566 MM |
3060 | GEN_INT (temp1)))); |
3061 | emit_constant_insn (cond, | |
3062 | gen_rtx_SET (VOIDmode, target, | |
3063 | gen_rtx_NOT (mode, sub))); | |
2b835d68 | 3064 | } |
e2c671ba RE |
3065 | return 3; |
3066 | } | |
3067 | break; | |
3068 | ||
3069 | case AND: | |
3070 | /* See if two shifts will do 2 or more insn's worth of work. */ | |
3071 | if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24) | |
3072 | { | |
30cf4896 | 3073 | HOST_WIDE_INT shift_mask = ((0xffffffff |
e2c671ba | 3074 | << (32 - clear_sign_bit_copies)) |
30cf4896 | 3075 | & 0xffffffff); |
e2c671ba | 3076 | |
30cf4896 | 3077 | if ((remainder | shift_mask) != 0xffffffff) |
e2c671ba | 3078 | { |
2b835d68 RE |
3079 | if (generate) |
3080 | { | |
d499463f | 3081 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
f676971a | 3082 | insns = arm_gen_constant (AND, mode, cond, |
a406f566 | 3083 | remainder | shift_mask, |
d499463f RE |
3084 | new_src, source, subtargets, 1); |
3085 | source = new_src; | |
2b835d68 RE |
3086 | } |
3087 | else | |
d499463f RE |
3088 | { |
3089 | rtx targ = subtargets ? NULL_RTX : target; | |
a406f566 MM |
3090 | insns = arm_gen_constant (AND, mode, cond, |
3091 | remainder | shift_mask, | |
d499463f RE |
3092 | targ, source, subtargets, 0); |
3093 | } | |
2b835d68 RE |
3094 | } |
3095 | ||
3096 | if (generate) | |
3097 | { | |
d499463f RE |
3098 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
3099 | rtx shift = GEN_INT (clear_sign_bit_copies); | |
3100 | ||
3101 | emit_insn (gen_ashlsi3 (new_src, source, shift)); | |
3102 | emit_insn (gen_lshrsi3 (target, new_src, shift)); | |
e2c671ba RE |
3103 | } |
3104 | ||
e2c671ba RE |
3105 | return insns + 2; |
3106 | } | |
3107 | ||
3108 | if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24) | |
3109 | { | |
3110 | HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1; | |
f676971a | 3111 | |
30cf4896 | 3112 | if ((remainder | shift_mask) != 0xffffffff) |
e2c671ba | 3113 | { |
2b835d68 RE |
3114 | if (generate) |
3115 | { | |
d499463f RE |
3116 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
3117 | ||
a406f566 MM |
3118 | insns = arm_gen_constant (AND, mode, cond, |
3119 | remainder | shift_mask, | |
d499463f RE |
3120 | new_src, source, subtargets, 1); |
3121 | source = new_src; | |
2b835d68 RE |
3122 | } |
3123 | else | |
d499463f RE |
3124 | { |
3125 | rtx targ = subtargets ? NULL_RTX : target; | |
3126 | ||
a406f566 MM |
3127 | insns = arm_gen_constant (AND, mode, cond, |
3128 | remainder | shift_mask, | |
d499463f RE |
3129 | targ, source, subtargets, 0); |
3130 | } | |
2b835d68 RE |
3131 | } |
3132 | ||
3133 | if (generate) | |
3134 | { | |
d499463f RE |
3135 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
3136 | rtx shift = GEN_INT (clear_zero_bit_copies); | |
3137 | ||
3138 | emit_insn (gen_lshrsi3 (new_src, source, shift)); | |
3139 | emit_insn (gen_ashlsi3 (target, new_src, shift)); | |
e2c671ba RE |
3140 | } |
3141 | ||
e2c671ba RE |
3142 | return insns + 2; |
3143 | } | |
3144 | ||
3145 | break; | |
3146 | ||
3147 | default: | |
3148 | break; | |
3149 | } | |
3150 | ||
3151 | for (i = 0; i < 32; i++) | |
3152 | if (remainder & (1 << i)) | |
3153 | num_bits_set++; | |
3154 | ||
422c0989 | 3155 | if ((code == AND) || (can_invert && num_bits_set > 16)) |
162e4591 | 3156 | remainder ^= 0xffffffff; |
e2c671ba | 3157 | else if (code == PLUS && num_bits_set > 16) |
30cf4896 | 3158 | remainder = (-remainder) & 0xffffffff; |
162e4591 RE |
3159 | |
3160 | /* For XOR, if more than half the bits are set and there's a sequence | |
3161 | of more than 8 consecutive ones in the pattern then we can XOR by the | |
3162 | inverted constant and then invert the final result; this may save an | |
3163 | instruction and might also lead to the final mvn being merged with | |
3164 | some other operation. */ | |
3165 | else if (code == XOR && num_bits_set > 16 | |
3166 | && (count_insns_for_constant (remainder ^ 0xffffffff, | |
3167 | find_best_start | |
3168 | (remainder ^ 0xffffffff)) | |
3169 | < count_insns_for_constant (remainder, | |
3170 | find_best_start (remainder)))) | |
3171 | { | |
3172 | remainder ^= 0xffffffff; | |
3173 | final_invert = 1; | |
3174 | } | |
e2c671ba RE |
3175 | else |
3176 | { | |
3177 | can_invert = 0; | |
3178 | can_negate = 0; | |
3179 | } | |
3180 | ||
3181 | /* Now try and find a way of doing the job in either two or three | |
3182 | instructions. | |
3183 | We start by looking for the largest block of zeros that are aligned on | |
3184 | a 2-bit boundary, we then fill up the temps, wrapping around to the | |
3185 | top of the word when we drop off the bottom. | |
5b3e6663 PB |
3186 | In the worst case this code should produce no more than four insns. |
3187 | Thumb-2 constants are shifted, not rotated, so the MSB is always the | |
3188 | best place to start. */ | |
3189 | ||
3190 | /* ??? Use thumb2 replicated constants when the high and low halfwords are | |
3191 | the same. */ | |
e2c671ba | 3192 | { |
ceebdb09 | 3193 | /* Now start emitting the insns. */ |
162e4591 | 3194 | i = find_best_start (remainder); |
e2c671ba RE |
3195 | do |
3196 | { | |
3197 | int end; | |
3198 | ||
3199 | if (i <= 0) | |
3200 | i += 32; | |
3201 | if (remainder & (3 << (i - 2))) | |
3202 | { | |
3203 | end = i - 8; | |
3204 | if (end < 0) | |
3205 | end += 32; | |
3206 | temp1 = remainder & ((0x0ff << end) | |
3207 | | ((i < end) ? (0xff >> (32 - end)) : 0)); | |
3208 | remainder &= ~temp1; | |
3209 | ||
d499463f | 3210 | if (generate) |
e2c671ba | 3211 | { |
9503f3d1 RH |
3212 | rtx new_src, temp1_rtx; |
3213 | ||
3214 | if (code == SET || code == MINUS) | |
3215 | { | |
3216 | new_src = (subtargets ? gen_reg_rtx (mode) : target); | |
96ae8197 | 3217 | if (can_invert && code != MINUS) |
9503f3d1 RH |
3218 | temp1 = ~temp1; |
3219 | } | |
3220 | else | |
3221 | { | |
162e4591 | 3222 | if ((final_invert || remainder) && subtargets) |
9503f3d1 | 3223 | new_src = gen_reg_rtx (mode); |
96ae8197 NC |
3224 | else |
3225 | new_src = target; | |
9503f3d1 RH |
3226 | if (can_invert) |
3227 | temp1 = ~temp1; | |
3228 | else if (can_negate) | |
3229 | temp1 = -temp1; | |
3230 | } | |
3231 | ||
3232 | temp1 = trunc_int_for_mode (temp1, mode); | |
3233 | temp1_rtx = GEN_INT (temp1); | |
d499463f RE |
3234 | |
3235 | if (code == SET) | |
9503f3d1 | 3236 | ; |
d499463f | 3237 | else if (code == MINUS) |
9503f3d1 | 3238 | temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source); |
d499463f | 3239 | else |
9503f3d1 RH |
3240 | temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx); |
3241 | ||
a406f566 | 3242 | emit_constant_insn (cond, |
f676971a | 3243 | gen_rtx_SET (VOIDmode, new_src, |
a406f566 | 3244 | temp1_rtx)); |
d499463f | 3245 | source = new_src; |
e2c671ba RE |
3246 | } |
3247 | ||
d499463f RE |
3248 | if (code == SET) |
3249 | { | |
3250 | can_invert = 0; | |
3251 | code = PLUS; | |
3252 | } | |
3253 | else if (code == MINUS) | |
3254 | code = PLUS; | |
3255 | ||
e2c671ba | 3256 | insns++; |
162e4591 | 3257 | i -= 8 - step_size; |
e2c671ba | 3258 | } |
7a085dce | 3259 | /* Arm allows rotates by a multiple of two. Thumb-2 allows arbitrary |
5b3e6663 | 3260 | shifts. */ |
162e4591 | 3261 | i -= step_size; |
1d6e90ac NC |
3262 | } |
3263 | while (remainder); | |
e2c671ba | 3264 | } |
1d6e90ac | 3265 | |
162e4591 RE |
3266 | if (final_invert) |
3267 | { | |
3268 | if (generate) | |
3269 | emit_constant_insn (cond, gen_rtx_SET (VOIDmode, target, | |
3270 | gen_rtx_NOT (mode, source))); | |
3271 | insns++; | |
3272 | } | |
3273 | ||
e2c671ba RE |
3274 | return insns; |
3275 | } | |
3276 | ||
bd9c7e23 RE |
3277 | /* Canonicalize a comparison so that we are more likely to recognize it. |
3278 | This can be done for a few constant compares, where we can make the | |
3279 | immediate value easier to load. */ | |
1d6e90ac | 3280 | |
bd9c7e23 | 3281 | enum rtx_code |
73160ba9 | 3282 | arm_canonicalize_comparison (enum rtx_code code, rtx *op0, rtx *op1) |
bd9c7e23 | 3283 | { |
73160ba9 DJ |
3284 | enum machine_mode mode; |
3285 | unsigned HOST_WIDE_INT i, maxval; | |
3286 | ||
3287 | mode = GET_MODE (*op0); | |
3288 | if (mode == VOIDmode) | |
3289 | mode = GET_MODE (*op1); | |
3290 | ||
a14b88bb | 3291 | maxval = (((unsigned HOST_WIDE_INT) 1) << (GET_MODE_BITSIZE(mode) - 1)) - 1; |
bd9c7e23 | 3292 | |
73160ba9 DJ |
3293 | /* For DImode, we have GE/LT/GEU/LTU comparisons. In ARM mode |
3294 | we can also use cmp/cmpeq for GTU/LEU. GT/LE must be either | |
3295 | reversed or (for constant OP1) adjusted to GE/LT. Similarly | |
3296 | for GTU/LEU in Thumb mode. */ | |
3297 | if (mode == DImode) | |
3298 | { | |
3299 | rtx tem; | |
3300 | ||
3301 | /* To keep things simple, always use the Cirrus cfcmp64 if it is | |
3302 | available. */ | |
3303 | if (TARGET_ARM && TARGET_HARD_FLOAT && TARGET_MAVERICK) | |
3304 | return code; | |
3305 | ||
3306 | if (code == GT || code == LE | |
3307 | || (!TARGET_ARM && (code == GTU || code == LEU))) | |
3308 | { | |
3309 | /* Missing comparison. First try to use an available | |
3310 | comparison. */ | |
3311 | if (GET_CODE (*op1) == CONST_INT) | |
3312 | { | |
3313 | i = INTVAL (*op1); | |
3314 | switch (code) | |
3315 | { | |
3316 | case GT: | |
3317 | case LE: | |
3318 | if (i != maxval | |
3319 | && arm_const_double_by_immediates (GEN_INT (i + 1))) | |
3320 | { | |
3321 | *op1 = GEN_INT (i + 1); | |
3322 | return code == GT ? GE : LT; | |
3323 | } | |
3324 | break; | |
3325 | case GTU: | |
3326 | case LEU: | |
3327 | if (i != ~((unsigned HOST_WIDE_INT) 0) | |
3328 | && arm_const_double_by_immediates (GEN_INT (i + 1))) | |
3329 | { | |
3330 | *op1 = GEN_INT (i + 1); | |
3331 | return code == GTU ? GEU : LTU; | |
3332 | } | |
3333 | break; | |
3334 | default: | |
3335 | gcc_unreachable (); | |
3336 | } | |
3337 | } | |
3338 | ||
3339 | /* If that did not work, reverse the condition. */ | |
3340 | tem = *op0; | |
3341 | *op0 = *op1; | |
3342 | *op1 = tem; | |
3343 | return swap_condition (code); | |
3344 | } | |
3345 | ||
3346 | return code; | |
3347 | } | |
3348 | ||
b0e43da8 CLT |
3349 | /* If *op0 is (zero_extend:SI (subreg:QI (reg:SI) 0)) and comparing |
3350 | with const0_rtx, change it to (and:SI (reg:SI) (const_int 255)), | |
3351 | to facilitate possible combining with a cmp into 'ands'. */ | |
3352 | if (mode == SImode | |
3353 | && GET_CODE (*op0) == ZERO_EXTEND | |
3354 | && GET_CODE (XEXP (*op0, 0)) == SUBREG | |
3355 | && GET_MODE (XEXP (*op0, 0)) == QImode | |
3356 | && GET_MODE (SUBREG_REG (XEXP (*op0, 0))) == SImode | |
3357 | && subreg_lowpart_p (XEXP (*op0, 0)) | |
3358 | && *op1 == const0_rtx) | |
3359 | *op0 = gen_rtx_AND (SImode, SUBREG_REG (XEXP (*op0, 0)), | |
3360 | GEN_INT (255)); | |
3361 | ||
73160ba9 DJ |
3362 | /* Comparisons smaller than DImode. Only adjust comparisons against |
3363 | an out-of-range constant. */ | |
3364 | if (GET_CODE (*op1) != CONST_INT | |
3365 | || const_ok_for_arm (INTVAL (*op1)) | |
3366 | || const_ok_for_arm (- INTVAL (*op1))) | |
3367 | return code; | |
3368 | ||
3369 | i = INTVAL (*op1); | |
3370 | ||
bd9c7e23 RE |
3371 | switch (code) |
3372 | { | |
3373 | case EQ: | |
3374 | case NE: | |
3375 | return code; | |
3376 | ||
3377 | case GT: | |
3378 | case LE: | |
a14b88bb | 3379 | if (i != maxval |
5895f793 | 3380 | && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1)))) |
bd9c7e23 | 3381 | { |
5895f793 | 3382 | *op1 = GEN_INT (i + 1); |
bd9c7e23 RE |
3383 | return code == GT ? GE : LT; |
3384 | } | |
3385 | break; | |
3386 | ||
3387 | case GE: | |
3388 | case LT: | |
a14b88bb | 3389 | if (i != ~maxval |
5895f793 | 3390 | && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1)))) |
bd9c7e23 | 3391 | { |
5895f793 | 3392 | *op1 = GEN_INT (i - 1); |
bd9c7e23 RE |
3393 | return code == GE ? GT : LE; |
3394 | } | |
3395 | break; | |
3396 | ||
3397 | case GTU: | |
3398 | case LEU: | |
30cf4896 | 3399 | if (i != ~((unsigned HOST_WIDE_INT) 0) |
5895f793 | 3400 | && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1)))) |
bd9c7e23 RE |
3401 | { |
3402 | *op1 = GEN_INT (i + 1); | |
3403 | return code == GTU ? GEU : LTU; | |
3404 | } | |
3405 | break; | |
3406 | ||
3407 | case GEU: | |
3408 | case LTU: | |
3409 | if (i != 0 | |
5895f793 | 3410 | && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1)))) |
bd9c7e23 RE |
3411 | { |
3412 | *op1 = GEN_INT (i - 1); | |
3413 | return code == GEU ? GTU : LEU; | |
3414 | } | |
3415 | break; | |
3416 | ||
3417 | default: | |
e6d29d15 | 3418 | gcc_unreachable (); |
bd9c7e23 RE |
3419 | } |
3420 | ||
3421 | return code; | |
3422 | } | |
bd9c7e23 | 3423 | |
d4453b7a PB |
3424 | |
3425 | /* Define how to find the value returned by a function. */ | |
3426 | ||
390b17c2 RE |
3427 | static rtx |
3428 | arm_function_value(const_tree type, const_tree func, | |
3429 | bool outgoing ATTRIBUTE_UNUSED) | |
d4453b7a PB |
3430 | { |
3431 | enum machine_mode mode; | |
3432 | int unsignedp ATTRIBUTE_UNUSED; | |
3433 | rtx r ATTRIBUTE_UNUSED; | |
3434 | ||
d4453b7a | 3435 | mode = TYPE_MODE (type); |
390b17c2 RE |
3436 | |
3437 | if (TARGET_AAPCS_BASED) | |
3438 | return aapcs_allocate_return_reg (mode, type, func); | |
3439 | ||
d4453b7a PB |
3440 | /* Promote integer types. */ |
3441 | if (INTEGRAL_TYPE_P (type)) | |
cde0f3fd | 3442 | mode = arm_promote_function_mode (type, mode, &unsignedp, func, 1); |
866af8a9 JB |
3443 | |
3444 | /* Promotes small structs returned in a register to full-word size | |
3445 | for big-endian AAPCS. */ | |
3446 | if (arm_return_in_msb (type)) | |
3447 | { | |
3448 | HOST_WIDE_INT size = int_size_in_bytes (type); | |
3449 | if (size % UNITS_PER_WORD != 0) | |
3450 | { | |
3451 | size += UNITS_PER_WORD - size % UNITS_PER_WORD; | |
3452 | mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0); | |
3453 | } | |
3454 | } | |
e0b92319 | 3455 | |
390b17c2 RE |
3456 | return LIBCALL_VALUE (mode); |
3457 | } | |
3458 | ||
3459 | static int | |
3460 | libcall_eq (const void *p1, const void *p2) | |
3461 | { | |
3462 | return rtx_equal_p ((const_rtx) p1, (const_rtx) p2); | |
3463 | } | |
3464 | ||
3465 | static hashval_t | |
3466 | libcall_hash (const void *p1) | |
3467 | { | |
3468 | return hash_rtx ((const_rtx) p1, VOIDmode, NULL, NULL, FALSE); | |
3469 | } | |
3470 | ||
3471 | static void | |
3472 | add_libcall (htab_t htab, rtx libcall) | |
3473 | { | |
3474 | *htab_find_slot (htab, libcall, INSERT) = libcall; | |
3475 | } | |
3476 | ||
3477 | static bool | |
7fc6a96b | 3478 | arm_libcall_uses_aapcs_base (const_rtx libcall) |
390b17c2 RE |
3479 | { |
3480 | static bool init_done = false; | |
3481 | static htab_t libcall_htab; | |
3482 | ||
3483 | if (!init_done) | |
3484 | { | |
3485 | init_done = true; | |
3486 | ||
3487 | libcall_htab = htab_create (31, libcall_hash, libcall_eq, | |
3488 | NULL); | |
3489 | add_libcall (libcall_htab, | |
3490 | convert_optab_libfunc (sfloat_optab, SFmode, SImode)); | |
3491 | add_libcall (libcall_htab, | |
3492 | convert_optab_libfunc (sfloat_optab, DFmode, SImode)); | |
3493 | add_libcall (libcall_htab, | |
3494 | convert_optab_libfunc (sfloat_optab, SFmode, DImode)); | |
3495 | add_libcall (libcall_htab, | |
3496 | convert_optab_libfunc (sfloat_optab, DFmode, DImode)); | |
3497 | ||
3498 | add_libcall (libcall_htab, | |
3499 | convert_optab_libfunc (ufloat_optab, SFmode, SImode)); | |
3500 | add_libcall (libcall_htab, | |
3501 | convert_optab_libfunc (ufloat_optab, DFmode, SImode)); | |
3502 | add_libcall (libcall_htab, | |
3503 | convert_optab_libfunc (ufloat_optab, SFmode, DImode)); | |
3504 | add_libcall (libcall_htab, | |
3505 | convert_optab_libfunc (ufloat_optab, DFmode, DImode)); | |
3506 | ||
3507 | add_libcall (libcall_htab, | |
3508 | convert_optab_libfunc (sext_optab, SFmode, HFmode)); | |
3509 | add_libcall (libcall_htab, | |
3510 | convert_optab_libfunc (trunc_optab, HFmode, SFmode)); | |
3511 | add_libcall (libcall_htab, | |
3512 | convert_optab_libfunc (sfix_optab, DImode, DFmode)); | |
3513 | add_libcall (libcall_htab, | |
3514 | convert_optab_libfunc (ufix_optab, DImode, DFmode)); | |
3515 | add_libcall (libcall_htab, | |
3516 | convert_optab_libfunc (sfix_optab, DImode, SFmode)); | |
3517 | add_libcall (libcall_htab, | |
3518 | convert_optab_libfunc (ufix_optab, DImode, SFmode)); | |
b1def36c JB |
3519 | |
3520 | /* Values from double-precision helper functions are returned in core | |
3521 | registers if the selected core only supports single-precision | |
3522 | arithmetic, even if we are using the hard-float ABI. The same is | |
3523 | true for single-precision helpers, but we will never be using the | |
3524 | hard-float ABI on a CPU which doesn't support single-precision | |
3525 | operations in hardware. */ | |
3526 | add_libcall (libcall_htab, optab_libfunc (add_optab, DFmode)); | |
3527 | add_libcall (libcall_htab, optab_libfunc (sdiv_optab, DFmode)); | |
3528 | add_libcall (libcall_htab, optab_libfunc (smul_optab, DFmode)); | |
3529 | add_libcall (libcall_htab, optab_libfunc (neg_optab, DFmode)); | |
3530 | add_libcall (libcall_htab, optab_libfunc (sub_optab, DFmode)); | |
3531 | add_libcall (libcall_htab, optab_libfunc (eq_optab, DFmode)); | |
3532 | add_libcall (libcall_htab, optab_libfunc (lt_optab, DFmode)); | |
3533 | add_libcall (libcall_htab, optab_libfunc (le_optab, DFmode)); | |
3534 | add_libcall (libcall_htab, optab_libfunc (ge_optab, DFmode)); | |
3535 | add_libcall (libcall_htab, optab_libfunc (gt_optab, DFmode)); | |
3536 | add_libcall (libcall_htab, optab_libfunc (unord_optab, DFmode)); | |
3537 | add_libcall (libcall_htab, convert_optab_libfunc (sext_optab, DFmode, | |
3538 | SFmode)); | |
3539 | add_libcall (libcall_htab, convert_optab_libfunc (trunc_optab, SFmode, | |
3540 | DFmode)); | |
390b17c2 RE |
3541 | } |
3542 | ||
3543 | return libcall && htab_find (libcall_htab, libcall) != NULL; | |
3544 | } | |
3545 | ||
3546 | rtx | |
7fc6a96b | 3547 | arm_libcall_value (enum machine_mode mode, const_rtx libcall) |
390b17c2 RE |
3548 | { |
3549 | if (TARGET_AAPCS_BASED && arm_pcs_default != ARM_PCS_AAPCS | |
3550 | && GET_MODE_CLASS (mode) == MODE_FLOAT) | |
3551 | { | |
3552 | /* The following libcalls return their result in integer registers, | |
3553 | even though they return a floating point value. */ | |
3554 | if (arm_libcall_uses_aapcs_base (libcall)) | |
3555 | return gen_rtx_REG (mode, ARG_REGISTER(1)); | |
3556 | ||
3557 | } | |
3558 | ||
3559 | return LIBCALL_VALUE (mode); | |
d4453b7a PB |
3560 | } |
3561 | ||
e0b92319 | 3562 | /* Determine the amount of memory needed to store the possible return |
9f7bf991 RE |
3563 | registers of an untyped call. */ |
3564 | int | |
3565 | arm_apply_result_size (void) | |
3566 | { | |
3567 | int size = 16; | |
3568 | ||
390b17c2 | 3569 | if (TARGET_32BIT) |
9f7bf991 RE |
3570 | { |
3571 | if (TARGET_HARD_FLOAT_ABI) | |
3572 | { | |
390b17c2 RE |
3573 | if (TARGET_VFP) |
3574 | size += 32; | |
9f7bf991 RE |
3575 | if (TARGET_FPA) |
3576 | size += 12; | |
3577 | if (TARGET_MAVERICK) | |
3578 | size += 8; | |
3579 | } | |
3580 | if (TARGET_IWMMXT_ABI) | |
3581 | size += 8; | |
3582 | } | |
3583 | ||
3584 | return size; | |
3585 | } | |
d4453b7a | 3586 | |
390b17c2 RE |
3587 | /* Decide whether TYPE should be returned in memory (true) |
3588 | or in a register (false). FNTYPE is the type of the function making | |
3589 | the call. */ | |
23668cf7 | 3590 | static bool |
390b17c2 | 3591 | arm_return_in_memory (const_tree type, const_tree fntype) |
2b835d68 | 3592 | { |
dc0ba55a JT |
3593 | HOST_WIDE_INT size; |
3594 | ||
390b17c2 RE |
3595 | size = int_size_in_bytes (type); /* Negative if not fixed size. */ |
3596 | ||
3597 | if (TARGET_AAPCS_BASED) | |
3598 | { | |
3599 | /* Simple, non-aggregate types (ie not including vectors and | |
3600 | complex) are always returned in a register (or registers). | |
3601 | We don't care about which register here, so we can short-cut | |
3602 | some of the detail. */ | |
3603 | if (!AGGREGATE_TYPE_P (type) | |
3604 | && TREE_CODE (type) != VECTOR_TYPE | |
3605 | && TREE_CODE (type) != COMPLEX_TYPE) | |
3606 | return false; | |
3607 | ||
3608 | /* Any return value that is no larger than one word can be | |
3609 | returned in r0. */ | |
3610 | if (((unsigned HOST_WIDE_INT) size) <= UNITS_PER_WORD) | |
3611 | return false; | |
3612 | ||
3613 | /* Check any available co-processors to see if they accept the | |
3614 | type as a register candidate (VFP, for example, can return | |
3615 | some aggregates in consecutive registers). These aren't | |
3616 | available if the call is variadic. */ | |
3617 | if (aapcs_select_return_coproc (type, fntype) >= 0) | |
3618 | return false; | |
3619 | ||
3620 | /* Vector values should be returned using ARM registers, not | |
3621 | memory (unless they're over 16 bytes, which will break since | |
3622 | we only have four call-clobbered registers to play with). */ | |
3623 | if (TREE_CODE (type) == VECTOR_TYPE) | |
3624 | return (size < 0 || size > (4 * UNITS_PER_WORD)); | |
3625 | ||
3626 | /* The rest go in memory. */ | |
3627 | return true; | |
3628 | } | |
88f77cba | 3629 | |
88f77cba JB |
3630 | if (TREE_CODE (type) == VECTOR_TYPE) |
3631 | return (size < 0 || size > (4 * UNITS_PER_WORD)); | |
3632 | ||
3dd7ab65 | 3633 | if (!AGGREGATE_TYPE_P (type) && |
390b17c2 RE |
3634 | (TREE_CODE (type) != VECTOR_TYPE)) |
3635 | /* All simple types are returned in registers. */ | |
3636 | return false; | |
dc0ba55a | 3637 | |
5848830f | 3638 | if (arm_abi != ARM_ABI_APCS) |
dc0ba55a | 3639 | { |
5848830f | 3640 | /* ATPCS and later return aggregate types in memory only if they are |
dc0ba55a JT |
3641 | larger than a word (or are variable size). */ |
3642 | return (size < 0 || size > UNITS_PER_WORD); | |
3643 | } | |
f676971a | 3644 | |
6bc82793 | 3645 | /* For the arm-wince targets we choose to be compatible with Microsoft's |
d5b7b3ae RE |
3646 | ARM and Thumb compilers, which always return aggregates in memory. */ |
3647 | #ifndef ARM_WINCE | |
e529bd42 NC |
3648 | /* All structures/unions bigger than one word are returned in memory. |
3649 | Also catch the case where int_size_in_bytes returns -1. In this case | |
6bc82793 | 3650 | the aggregate is either huge or of variable size, and in either case |
e529bd42 | 3651 | we will want to return it via memory and not in a register. */ |
dc0ba55a | 3652 | if (size < 0 || size > UNITS_PER_WORD) |
390b17c2 | 3653 | return true; |
f676971a | 3654 | |
d7d01975 | 3655 | if (TREE_CODE (type) == RECORD_TYPE) |
2b835d68 RE |
3656 | { |
3657 | tree field; | |
3658 | ||
3a2ea258 RE |
3659 | /* For a struct the APCS says that we only return in a register |
3660 | if the type is 'integer like' and every addressable element | |
3661 | has an offset of zero. For practical purposes this means | |
3662 | that the structure can have at most one non bit-field element | |
3663 | and that this element must be the first one in the structure. */ | |
f676971a | 3664 | |
f5a1b0d2 NC |
3665 | /* Find the first field, ignoring non FIELD_DECL things which will |
3666 | have been created by C++. */ | |
3667 | for (field = TYPE_FIELDS (type); | |
3668 | field && TREE_CODE (field) != FIELD_DECL; | |
910ad8de | 3669 | field = DECL_CHAIN (field)) |
f5a1b0d2 | 3670 | continue; |
f676971a | 3671 | |
f5a1b0d2 | 3672 | if (field == NULL) |
390b17c2 | 3673 | return false; /* An empty structure. Allowed by an extension to ANSI C. */ |
f5a1b0d2 | 3674 | |
d5b7b3ae RE |
3675 | /* Check that the first field is valid for returning in a register. */ |
3676 | ||
3677 | /* ... Floats are not allowed */ | |
9e291dbe | 3678 | if (FLOAT_TYPE_P (TREE_TYPE (field))) |
390b17c2 | 3679 | return true; |
3a2ea258 | 3680 | |
d5b7b3ae RE |
3681 | /* ... Aggregates that are not themselves valid for returning in |
3682 | a register are not allowed. */ | |
81464b2c | 3683 | if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE)) |
390b17c2 | 3684 | return true; |
6f7ebcbb | 3685 | |
3a2ea258 RE |
3686 | /* Now check the remaining fields, if any. Only bitfields are allowed, |
3687 | since they are not addressable. */ | |
910ad8de | 3688 | for (field = DECL_CHAIN (field); |
f5a1b0d2 | 3689 | field; |
910ad8de | 3690 | field = DECL_CHAIN (field)) |
f5a1b0d2 NC |
3691 | { |
3692 | if (TREE_CODE (field) != FIELD_DECL) | |
3693 | continue; | |
f676971a | 3694 | |
5895f793 | 3695 | if (!DECL_BIT_FIELD_TYPE (field)) |
390b17c2 | 3696 | return true; |
f5a1b0d2 | 3697 | } |
2b835d68 | 3698 | |
390b17c2 | 3699 | return false; |
2b835d68 | 3700 | } |
f676971a | 3701 | |
d7d01975 | 3702 | if (TREE_CODE (type) == UNION_TYPE) |
2b835d68 RE |
3703 | { |
3704 | tree field; | |
3705 | ||
3706 | /* Unions can be returned in registers if every element is | |
3707 | integral, or can be returned in an integer register. */ | |
f5a1b0d2 NC |
3708 | for (field = TYPE_FIELDS (type); |
3709 | field; | |
910ad8de | 3710 | field = DECL_CHAIN (field)) |
2b835d68 | 3711 | { |
f5a1b0d2 NC |
3712 | if (TREE_CODE (field) != FIELD_DECL) |
3713 | continue; | |
3714 | ||
6cc8c0b3 | 3715 | if (FLOAT_TYPE_P (TREE_TYPE (field))) |
390b17c2 | 3716 | return true; |
f676971a | 3717 | |
81464b2c | 3718 | if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE)) |
390b17c2 | 3719 | return true; |
2b835d68 | 3720 | } |
f676971a | 3721 | |
390b17c2 | 3722 | return false; |
2b835d68 | 3723 | } |
f676971a EC |
3724 | #endif /* not ARM_WINCE */ |
3725 | ||
d5b7b3ae | 3726 | /* Return all other types in memory. */ |
390b17c2 | 3727 | return true; |
2b835d68 RE |
3728 | } |
3729 | ||
d6b4baa4 | 3730 | /* Indicate whether or not words of a double are in big-endian order. */ |
3717da94 JT |
3731 | |
3732 | int | |
e32bac5b | 3733 | arm_float_words_big_endian (void) |
3717da94 | 3734 | { |
9b66ebb1 | 3735 | if (TARGET_MAVERICK) |
9b6b54e2 | 3736 | return 0; |
3717da94 JT |
3737 | |
3738 | /* For FPA, float words are always big-endian. For VFP, floats words | |
3739 | follow the memory system mode. */ | |
3740 | ||
9b66ebb1 | 3741 | if (TARGET_FPA) |
3717da94 | 3742 | { |
3717da94 JT |
3743 | return 1; |
3744 | } | |
3745 | ||
3746 | if (TARGET_VFP) | |
3747 | return (TARGET_BIG_END ? 1 : 0); | |
3748 | ||
3749 | return 1; | |
3750 | } | |
3751 | ||
390b17c2 RE |
3752 | const struct pcs_attribute_arg |
3753 | { | |
3754 | const char *arg; | |
3755 | enum arm_pcs value; | |
3756 | } pcs_attribute_args[] = | |
3757 | { | |
3758 | {"aapcs", ARM_PCS_AAPCS}, | |
3759 | {"aapcs-vfp", ARM_PCS_AAPCS_VFP}, | |
0f1a24df RE |
3760 | #if 0 |
3761 | /* We could recognize these, but changes would be needed elsewhere | |
3762 | * to implement them. */ | |
390b17c2 RE |
3763 | {"aapcs-iwmmxt", ARM_PCS_AAPCS_IWMMXT}, |
3764 | {"atpcs", ARM_PCS_ATPCS}, | |
3765 | {"apcs", ARM_PCS_APCS}, | |
0f1a24df | 3766 | #endif |
390b17c2 RE |
3767 | {NULL, ARM_PCS_UNKNOWN} |
3768 | }; | |
3769 | ||
3770 | static enum arm_pcs | |
3771 | arm_pcs_from_attribute (tree attr) | |
3772 | { | |
3773 | const struct pcs_attribute_arg *ptr; | |
3774 | const char *arg; | |
3775 | ||
3776 | /* Get the value of the argument. */ | |
3777 | if (TREE_VALUE (attr) == NULL_TREE | |
3778 | || TREE_CODE (TREE_VALUE (attr)) != STRING_CST) | |
3779 | return ARM_PCS_UNKNOWN; | |
3780 | ||
3781 | arg = TREE_STRING_POINTER (TREE_VALUE (attr)); | |
3782 | ||
3783 | /* Check it against the list of known arguments. */ | |
3784 | for (ptr = pcs_attribute_args; ptr->arg != NULL; ptr++) | |
3785 | if (streq (arg, ptr->arg)) | |
3786 | return ptr->value; | |
3787 | ||
3788 | /* An unrecognized interrupt type. */ | |
3789 | return ARM_PCS_UNKNOWN; | |
3790 | } | |
3791 | ||
3792 | /* Get the PCS variant to use for this call. TYPE is the function's type | |
3793 | specification, DECL is the specific declartion. DECL may be null if | |
3794 | the call could be indirect or if this is a library call. */ | |
3795 | static enum arm_pcs | |
3796 | arm_get_pcs_model (const_tree type, const_tree decl) | |
3797 | { | |
3798 | bool user_convention = false; | |
3799 | enum arm_pcs user_pcs = arm_pcs_default; | |
3800 | tree attr; | |
3801 | ||
3802 | gcc_assert (type); | |
3803 | ||
3804 | attr = lookup_attribute ("pcs", TYPE_ATTRIBUTES (type)); | |
3805 | if (attr) | |
3806 | { | |
3807 | user_pcs = arm_pcs_from_attribute (TREE_VALUE (attr)); | |
3808 | user_convention = true; | |
3809 | } | |
3810 | ||
3811 | if (TARGET_AAPCS_BASED) | |
3812 | { | |
3813 | /* Detect varargs functions. These always use the base rules | |
3814 | (no argument is ever a candidate for a co-processor | |
3815 | register). */ | |
f38958e8 | 3816 | bool base_rules = stdarg_p (type); |
390b17c2 RE |
3817 | |
3818 | if (user_convention) | |
3819 | { | |
3820 | if (user_pcs > ARM_PCS_AAPCS_LOCAL) | |
d8a07487 | 3821 | sorry ("non-AAPCS derived PCS variant"); |
390b17c2 | 3822 | else if (base_rules && user_pcs != ARM_PCS_AAPCS) |
d8a07487 | 3823 | error ("variadic functions must use the base AAPCS variant"); |
390b17c2 RE |
3824 | } |
3825 | ||
3826 | if (base_rules) | |
3827 | return ARM_PCS_AAPCS; | |
3828 | else if (user_convention) | |
3829 | return user_pcs; | |
3830 | else if (decl && flag_unit_at_a_time) | |
3831 | { | |
3832 | /* Local functions never leak outside this compilation unit, | |
3833 | so we are free to use whatever conventions are | |
3834 | appropriate. */ | |
3835 | /* FIXME: remove CONST_CAST_TREE when cgraph is constified. */ | |
3836 | struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl)); | |
3837 | if (i && i->local) | |
3838 | return ARM_PCS_AAPCS_LOCAL; | |
3839 | } | |
3840 | } | |
3841 | else if (user_convention && user_pcs != arm_pcs_default) | |
3842 | sorry ("PCS variant"); | |
3843 | ||
3844 | /* For everything else we use the target's default. */ | |
3845 | return arm_pcs_default; | |
3846 | } | |
3847 | ||
3848 | ||
3849 | static void | |
3850 | aapcs_vfp_cum_init (CUMULATIVE_ARGS *pcum ATTRIBUTE_UNUSED, | |
3851 | const_tree fntype ATTRIBUTE_UNUSED, | |
3852 | rtx libcall ATTRIBUTE_UNUSED, | |
3853 | const_tree fndecl ATTRIBUTE_UNUSED) | |
3854 | { | |
3855 | /* Record the unallocated VFP registers. */ | |
3856 | pcum->aapcs_vfp_regs_free = (1 << NUM_VFP_ARG_REGS) - 1; | |
3857 | pcum->aapcs_vfp_reg_alloc = 0; | |
3858 | } | |
3859 | ||
3860 | /* Walk down the type tree of TYPE counting consecutive base elements. | |
3861 | If *MODEP is VOIDmode, then set it to the first valid floating point | |
3862 | type. If a non-floating point type is found, or if a floating point | |
3863 | type that doesn't match a non-VOIDmode *MODEP is found, then return -1, | |
3864 | otherwise return the count in the sub-tree. */ | |
3865 | static int | |
3866 | aapcs_vfp_sub_candidate (const_tree type, enum machine_mode *modep) | |
3867 | { | |
3868 | enum machine_mode mode; | |
3869 | HOST_WIDE_INT size; | |
3870 | ||
3871 | switch (TREE_CODE (type)) | |
3872 | { | |
3873 | case REAL_TYPE: | |
3874 | mode = TYPE_MODE (type); | |
3875 | if (mode != DFmode && mode != SFmode) | |
3876 | return -1; | |
3877 | ||
3878 | if (*modep == VOIDmode) | |
3879 | *modep = mode; | |
3880 | ||
3881 | if (*modep == mode) | |
3882 | return 1; | |
3883 | ||
3884 | break; | |
3885 | ||
3886 | case COMPLEX_TYPE: | |
3887 | mode = TYPE_MODE (TREE_TYPE (type)); | |
3888 | if (mode != DFmode && mode != SFmode) | |
3889 | return -1; | |
3890 | ||
3891 | if (*modep == VOIDmode) | |
3892 | *modep = mode; | |
3893 | ||
3894 | if (*modep == mode) | |
3895 | return 2; | |
3896 | ||
3897 | break; | |
3898 | ||
3899 | case VECTOR_TYPE: | |
3900 | /* Use V2SImode and V4SImode as representatives of all 64-bit | |
3901 | and 128-bit vector types, whether or not those modes are | |
3902 | supported with the present options. */ | |
3903 | size = int_size_in_bytes (type); | |
3904 | switch (size) | |
3905 | { | |
3906 | case 8: | |
3907 | mode = V2SImode; | |
3908 | break; | |
3909 | case 16: | |
3910 | mode = V4SImode; | |
3911 | break; | |
3912 | default: | |
3913 | return -1; | |
3914 | } | |
3915 | ||
3916 | if (*modep == VOIDmode) | |
3917 | *modep = mode; | |
3918 | ||
3919 | /* Vector modes are considered to be opaque: two vectors are | |
3920 | equivalent for the purposes of being homogeneous aggregates | |
3921 | if they are the same size. */ | |
3922 | if (*modep == mode) | |
3923 | return 1; | |
3924 | ||
3925 | break; | |
3926 | ||
3927 | case ARRAY_TYPE: | |
3928 | { | |
3929 | int count; | |
3930 | tree index = TYPE_DOMAIN (type); | |
3931 | ||
3932 | /* Can't handle incomplete types. */ | |
3933 | if (!COMPLETE_TYPE_P(type)) | |
3934 | return -1; | |
3935 | ||
3936 | count = aapcs_vfp_sub_candidate (TREE_TYPE (type), modep); | |
3937 | if (count == -1 | |
3938 | || !index | |
3939 | || !TYPE_MAX_VALUE (index) | |
3940 | || !host_integerp (TYPE_MAX_VALUE (index), 1) | |
3941 | || !TYPE_MIN_VALUE (index) | |
3942 | || !host_integerp (TYPE_MIN_VALUE (index), 1) | |
3943 | || count < 0) | |
3944 | return -1; | |
3945 | ||
3946 | count *= (1 + tree_low_cst (TYPE_MAX_VALUE (index), 1) | |
3947 | - tree_low_cst (TYPE_MIN_VALUE (index), 1)); | |
3948 | ||
3949 | /* There must be no padding. */ | |
3950 | if (!host_integerp (TYPE_SIZE (type), 1) | |
3951 | || (tree_low_cst (TYPE_SIZE (type), 1) | |
3952 | != count * GET_MODE_BITSIZE (*modep))) | |
3953 | return -1; | |
3954 | ||
3955 | return count; | |
3956 | } | |
3957 | ||
3958 | case RECORD_TYPE: | |
3959 | { | |
3960 | int count = 0; | |
3961 | int sub_count; | |
3962 | tree field; | |
3963 | ||
3964 | /* Can't handle incomplete types. */ | |
3965 | if (!COMPLETE_TYPE_P(type)) | |
3966 | return -1; | |
3967 | ||
910ad8de | 3968 | for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
390b17c2 RE |
3969 | { |
3970 | if (TREE_CODE (field) != FIELD_DECL) | |
3971 | continue; | |
3972 | ||
3973 | sub_count = aapcs_vfp_sub_candidate (TREE_TYPE (field), modep); | |
3974 | if (sub_count < 0) | |
3975 | return -1; | |
3976 | count += sub_count; | |
3977 | } | |
3978 | ||
3979 | /* There must be no padding. */ | |
3980 | if (!host_integerp (TYPE_SIZE (type), 1) | |
3981 | || (tree_low_cst (TYPE_SIZE (type), 1) | |
3982 | != count * GET_MODE_BITSIZE (*modep))) | |
3983 | return -1; | |
3984 | ||
3985 | return count; | |
3986 | } | |
3987 | ||
3988 | case UNION_TYPE: | |
3989 | case QUAL_UNION_TYPE: | |
3990 | { | |
3991 | /* These aren't very interesting except in a degenerate case. */ | |
3992 | int count = 0; | |
3993 | int sub_count; | |
3994 | tree field; | |
3995 | ||
3996 | /* Can't handle incomplete types. */ | |
3997 | if (!COMPLETE_TYPE_P(type)) | |
3998 | return -1; | |
3999 | ||
910ad8de | 4000 | for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
390b17c2 RE |
4001 | { |
4002 | if (TREE_CODE (field) != FIELD_DECL) | |
4003 | continue; | |
4004 | ||
4005 | sub_count = aapcs_vfp_sub_candidate (TREE_TYPE (field), modep); | |
4006 | if (sub_count < 0) | |
4007 | return -1; | |
4008 | count = count > sub_count ? count : sub_count; | |
4009 | } | |
4010 | ||
4011 | /* There must be no padding. */ | |
4012 | if (!host_integerp (TYPE_SIZE (type), 1) | |
4013 | || (tree_low_cst (TYPE_SIZE (type), 1) | |
4014 | != count * GET_MODE_BITSIZE (*modep))) | |
4015 | return -1; | |
4016 | ||
4017 | return count; | |
4018 | } | |
4019 | ||
4020 | default: | |
4021 | break; | |
4022 | } | |
4023 | ||
4024 | return -1; | |
4025 | } | |
4026 | ||
e0dc3601 | 4027 | /* Return true if PCS_VARIANT should use VFP registers. */ |
390b17c2 | 4028 | static bool |
e0dc3601 | 4029 | use_vfp_abi (enum arm_pcs pcs_variant, bool is_double) |
390b17c2 | 4030 | { |
e0dc3601 | 4031 | if (pcs_variant == ARM_PCS_AAPCS_VFP) |
50416c61 PB |
4032 | { |
4033 | static bool seen_thumb1_vfp = false; | |
4034 | ||
4035 | if (TARGET_THUMB1 && !seen_thumb1_vfp) | |
4036 | { | |
4037 | sorry ("Thumb-1 hard-float VFP ABI"); | |
4038 | /* sorry() is not immediately fatal, so only display this once. */ | |
4039 | seen_thumb1_vfp = true; | |
4040 | } | |
4041 | ||
4042 | return true; | |
4043 | } | |
e0dc3601 PB |
4044 | |
4045 | if (pcs_variant != ARM_PCS_AAPCS_LOCAL) | |
4046 | return false; | |
4047 | ||
4048 | return (TARGET_32BIT && TARGET_VFP && TARGET_HARD_FLOAT && | |
4049 | (TARGET_VFP_DOUBLE || !is_double)); | |
4050 | } | |
4051 | ||
4052 | static bool | |
4053 | aapcs_vfp_is_call_or_return_candidate (enum arm_pcs pcs_variant, | |
4054 | enum machine_mode mode, const_tree type, | |
70dd156a | 4055 | enum machine_mode *base_mode, int *count) |
e0dc3601 PB |
4056 | { |
4057 | enum machine_mode new_mode = VOIDmode; | |
4058 | ||
390b17c2 RE |
4059 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
4060 | || GET_MODE_CLASS (mode) == MODE_VECTOR_INT | |
4061 | || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT) | |
4062 | { | |
4063 | *count = 1; | |
e0dc3601 | 4064 | new_mode = mode; |
390b17c2 RE |
4065 | } |
4066 | else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT) | |
4067 | { | |
4068 | *count = 2; | |
e0dc3601 | 4069 | new_mode = (mode == DCmode ? DFmode : SFmode); |
390b17c2 RE |
4070 | } |
4071 | else if (type && (mode == BLKmode || TREE_CODE (type) == VECTOR_TYPE)) | |
4072 | { | |
e0dc3601 | 4073 | int ag_count = aapcs_vfp_sub_candidate (type, &new_mode); |
390b17c2 RE |
4074 | |
4075 | if (ag_count > 0 && ag_count <= 4) | |
e0dc3601 PB |
4076 | *count = ag_count; |
4077 | else | |
4078 | return false; | |
390b17c2 | 4079 | } |
e0dc3601 PB |
4080 | else |
4081 | return false; | |
4082 | ||
4083 | ||
4084 | if (!use_vfp_abi (pcs_variant, ARM_NUM_REGS (new_mode) > 1)) | |
4085 | return false; | |
4086 | ||
4087 | *base_mode = new_mode; | |
4088 | return true; | |
390b17c2 RE |
4089 | } |
4090 | ||
4091 | static bool | |
4092 | aapcs_vfp_is_return_candidate (enum arm_pcs pcs_variant, | |
4093 | enum machine_mode mode, const_tree type) | |
4094 | { | |
4095 | int count ATTRIBUTE_UNUSED; | |
46107b99 | 4096 | enum machine_mode ag_mode ATTRIBUTE_UNUSED; |
390b17c2 | 4097 | |
e0dc3601 | 4098 | if (!use_vfp_abi (pcs_variant, false)) |
390b17c2 | 4099 | return false; |
e0dc3601 PB |
4100 | return aapcs_vfp_is_call_or_return_candidate (pcs_variant, mode, type, |
4101 | &ag_mode, &count); | |
390b17c2 RE |
4102 | } |
4103 | ||
4104 | static bool | |
4105 | aapcs_vfp_is_call_candidate (CUMULATIVE_ARGS *pcum, enum machine_mode mode, | |
4106 | const_tree type) | |
4107 | { | |
e0dc3601 | 4108 | if (!use_vfp_abi (pcum->pcs_variant, false)) |
390b17c2 | 4109 | return false; |
e0dc3601 PB |
4110 | |
4111 | return aapcs_vfp_is_call_or_return_candidate (pcum->pcs_variant, mode, type, | |
390b17c2 RE |
4112 | &pcum->aapcs_vfp_rmode, |
4113 | &pcum->aapcs_vfp_rcount); | |
4114 | } | |
4115 | ||
4116 | static bool | |
4117 | aapcs_vfp_allocate (CUMULATIVE_ARGS *pcum, enum machine_mode mode, | |
4118 | const_tree type ATTRIBUTE_UNUSED) | |
4119 | { | |
4120 | int shift = GET_MODE_SIZE (pcum->aapcs_vfp_rmode) / GET_MODE_SIZE (SFmode); | |
4121 | unsigned mask = (1 << (shift * pcum->aapcs_vfp_rcount)) - 1; | |
4122 | int regno; | |
4123 | ||
4124 | for (regno = 0; regno < NUM_VFP_ARG_REGS; regno += shift) | |
4125 | if (((pcum->aapcs_vfp_regs_free >> regno) & mask) == mask) | |
4126 | { | |
4127 | pcum->aapcs_vfp_reg_alloc = mask << regno; | |
4128 | if (mode == BLKmode || (mode == TImode && !TARGET_NEON)) | |
4129 | { | |
4130 | int i; | |
4131 | int rcount = pcum->aapcs_vfp_rcount; | |
4132 | int rshift = shift; | |
4133 | enum machine_mode rmode = pcum->aapcs_vfp_rmode; | |
4134 | rtx par; | |
4135 | if (!TARGET_NEON) | |
4136 | { | |
4137 | /* Avoid using unsupported vector modes. */ | |
4138 | if (rmode == V2SImode) | |
4139 | rmode = DImode; | |
4140 | else if (rmode == V4SImode) | |
4141 | { | |
4142 | rmode = DImode; | |
4143 | rcount *= 2; | |
4144 | rshift /= 2; | |
4145 | } | |
4146 | } | |
4147 | par = gen_rtx_PARALLEL (mode, rtvec_alloc (rcount)); | |
4148 | for (i = 0; i < rcount; i++) | |
4149 | { | |
4150 | rtx tmp = gen_rtx_REG (rmode, | |
4151 | FIRST_VFP_REGNUM + regno + i * rshift); | |
4152 | tmp = gen_rtx_EXPR_LIST | |
4153 | (VOIDmode, tmp, | |
4154 | GEN_INT (i * GET_MODE_SIZE (rmode))); | |
4155 | XVECEXP (par, 0, i) = tmp; | |
4156 | } | |
4157 | ||
4158 | pcum->aapcs_reg = par; | |
4159 | } | |
4160 | else | |
4161 | pcum->aapcs_reg = gen_rtx_REG (mode, FIRST_VFP_REGNUM + regno); | |
4162 | return true; | |
4163 | } | |
4164 | return false; | |
4165 | } | |
4166 | ||
4167 | static rtx | |
4168 | aapcs_vfp_allocate_return_reg (enum arm_pcs pcs_variant ATTRIBUTE_UNUSED, | |
4169 | enum machine_mode mode, | |
4170 | const_tree type ATTRIBUTE_UNUSED) | |
4171 | { | |
e0dc3601 | 4172 | if (!use_vfp_abi (pcs_variant, false)) |
e0170551 | 4173 | return NULL; |
e0dc3601 | 4174 | |
390b17c2 RE |
4175 | if (mode == BLKmode || (mode == TImode && !TARGET_NEON)) |
4176 | { | |
4177 | int count; | |
46107b99 | 4178 | enum machine_mode ag_mode; |
390b17c2 RE |
4179 | int i; |
4180 | rtx par; | |
4181 | int shift; | |
4182 | ||
e0dc3601 PB |
4183 | aapcs_vfp_is_call_or_return_candidate (pcs_variant, mode, type, |
4184 | &ag_mode, &count); | |
390b17c2 RE |
4185 | |
4186 | if (!TARGET_NEON) | |
4187 | { | |
4188 | if (ag_mode == V2SImode) | |
4189 | ag_mode = DImode; | |
4190 | else if (ag_mode == V4SImode) | |
4191 | { | |
4192 | ag_mode = DImode; | |
4193 | count *= 2; | |
4194 | } | |
4195 | } | |
4196 | shift = GET_MODE_SIZE(ag_mode) / GET_MODE_SIZE(SFmode); | |
4197 | par = gen_rtx_PARALLEL (mode, rtvec_alloc (count)); | |
4198 | for (i = 0; i < count; i++) | |
4199 | { | |
4200 | rtx tmp = gen_rtx_REG (ag_mode, FIRST_VFP_REGNUM + i * shift); | |
4201 | tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, | |
4202 | GEN_INT (i * GET_MODE_SIZE (ag_mode))); | |
4203 | XVECEXP (par, 0, i) = tmp; | |
4204 | } | |
4205 | ||
4206 | return par; | |
4207 | } | |
4208 | ||
4209 | return gen_rtx_REG (mode, FIRST_VFP_REGNUM); | |
4210 | } | |
4211 | ||
4212 | static void | |
4213 | aapcs_vfp_advance (CUMULATIVE_ARGS *pcum ATTRIBUTE_UNUSED, | |
4214 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
4215 | const_tree type ATTRIBUTE_UNUSED) | |
4216 | { | |
4217 | pcum->aapcs_vfp_regs_free &= ~pcum->aapcs_vfp_reg_alloc; | |
4218 | pcum->aapcs_vfp_reg_alloc = 0; | |
4219 | return; | |
4220 | } | |
4221 | ||
4222 | #define AAPCS_CP(X) \ | |
4223 | { \ | |
4224 | aapcs_ ## X ## _cum_init, \ | |
4225 | aapcs_ ## X ## _is_call_candidate, \ | |
4226 | aapcs_ ## X ## _allocate, \ | |
4227 | aapcs_ ## X ## _is_return_candidate, \ | |
4228 | aapcs_ ## X ## _allocate_return_reg, \ | |
4229 | aapcs_ ## X ## _advance \ | |
4230 | } | |
4231 | ||
4232 | /* Table of co-processors that can be used to pass arguments in | |
4233 | registers. Idealy no arugment should be a candidate for more than | |
4234 | one co-processor table entry, but the table is processed in order | |
4235 | and stops after the first match. If that entry then fails to put | |
4236 | the argument into a co-processor register, the argument will go on | |
4237 | the stack. */ | |
4238 | static struct | |
4239 | { | |
4240 | /* Initialize co-processor related state in CUMULATIVE_ARGS structure. */ | |
4241 | void (*cum_init) (CUMULATIVE_ARGS *, const_tree, rtx, const_tree); | |
4242 | ||
4243 | /* Return true if an argument of mode MODE (or type TYPE if MODE is | |
4244 | BLKmode) is a candidate for this co-processor's registers; this | |
4245 | function should ignore any position-dependent state in | |
4246 | CUMULATIVE_ARGS and only use call-type dependent information. */ | |
4247 | bool (*is_call_candidate) (CUMULATIVE_ARGS *, enum machine_mode, const_tree); | |
4248 | ||
4249 | /* Return true if the argument does get a co-processor register; it | |
4250 | should set aapcs_reg to an RTX of the register allocated as is | |
4251 | required for a return from FUNCTION_ARG. */ | |
4252 | bool (*allocate) (CUMULATIVE_ARGS *, enum machine_mode, const_tree); | |
4253 | ||
4254 | /* Return true if a result of mode MODE (or type TYPE if MODE is | |
4255 | BLKmode) is can be returned in this co-processor's registers. */ | |
4256 | bool (*is_return_candidate) (enum arm_pcs, enum machine_mode, const_tree); | |
4257 | ||
4258 | /* Allocate and return an RTX element to hold the return type of a | |
4259 | call, this routine must not fail and will only be called if | |
4260 | is_return_candidate returned true with the same parameters. */ | |
4261 | rtx (*allocate_return_reg) (enum arm_pcs, enum machine_mode, const_tree); | |
4262 | ||
4263 | /* Finish processing this argument and prepare to start processing | |
4264 | the next one. */ | |
4265 | void (*advance) (CUMULATIVE_ARGS *, enum machine_mode, const_tree); | |
4266 | } aapcs_cp_arg_layout[ARM_NUM_COPROC_SLOTS] = | |
4267 | { | |
4268 | AAPCS_CP(vfp) | |
4269 | }; | |
4270 | ||
4271 | #undef AAPCS_CP | |
4272 | ||
4273 | static int | |
4274 | aapcs_select_call_coproc (CUMULATIVE_ARGS *pcum, enum machine_mode mode, | |
9c6a2bee | 4275 | const_tree type) |
390b17c2 RE |
4276 | { |
4277 | int i; | |
4278 | ||
4279 | for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) | |
4280 | if (aapcs_cp_arg_layout[i].is_call_candidate (pcum, mode, type)) | |
4281 | return i; | |
4282 | ||
4283 | return -1; | |
4284 | } | |
4285 | ||
4286 | static int | |
4287 | aapcs_select_return_coproc (const_tree type, const_tree fntype) | |
4288 | { | |
4289 | /* We aren't passed a decl, so we can't check that a call is local. | |
4290 | However, it isn't clear that that would be a win anyway, since it | |
4291 | might limit some tail-calling opportunities. */ | |
4292 | enum arm_pcs pcs_variant; | |
4293 | ||
4294 | if (fntype) | |
4295 | { | |
4296 | const_tree fndecl = NULL_TREE; | |
4297 | ||
4298 | if (TREE_CODE (fntype) == FUNCTION_DECL) | |
4299 | { | |
4300 | fndecl = fntype; | |
4301 | fntype = TREE_TYPE (fntype); | |
4302 | } | |
4303 | ||
4304 | pcs_variant = arm_get_pcs_model (fntype, fndecl); | |
4305 | } | |
4306 | else | |
4307 | pcs_variant = arm_pcs_default; | |
4308 | ||
4309 | if (pcs_variant != ARM_PCS_AAPCS) | |
4310 | { | |
4311 | int i; | |
4312 | ||
4313 | for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) | |
4314 | if (aapcs_cp_arg_layout[i].is_return_candidate (pcs_variant, | |
4315 | TYPE_MODE (type), | |
4316 | type)) | |
4317 | return i; | |
4318 | } | |
4319 | return -1; | |
4320 | } | |
4321 | ||
4322 | static rtx | |
4323 | aapcs_allocate_return_reg (enum machine_mode mode, const_tree type, | |
4324 | const_tree fntype) | |
4325 | { | |
4326 | /* We aren't passed a decl, so we can't check that a call is local. | |
4327 | However, it isn't clear that that would be a win anyway, since it | |
4328 | might limit some tail-calling opportunities. */ | |
4329 | enum arm_pcs pcs_variant; | |
4330 | int unsignedp ATTRIBUTE_UNUSED; | |
4331 | ||
4332 | if (fntype) | |
4333 | { | |
4334 | const_tree fndecl = NULL_TREE; | |
4335 | ||
4336 | if (TREE_CODE (fntype) == FUNCTION_DECL) | |
4337 | { | |
4338 | fndecl = fntype; | |
4339 | fntype = TREE_TYPE (fntype); | |
4340 | } | |
4341 | ||
4342 | pcs_variant = arm_get_pcs_model (fntype, fndecl); | |
4343 | } | |
4344 | else | |
4345 | pcs_variant = arm_pcs_default; | |
4346 | ||
4347 | /* Promote integer types. */ | |
4348 | if (type && INTEGRAL_TYPE_P (type)) | |
4349 | mode = arm_promote_function_mode (type, mode, &unsignedp, fntype, 1); | |
4350 | ||
4351 | if (pcs_variant != ARM_PCS_AAPCS) | |
4352 | { | |
4353 | int i; | |
4354 | ||
4355 | for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) | |
4356 | if (aapcs_cp_arg_layout[i].is_return_candidate (pcs_variant, mode, | |
4357 | type)) | |
4358 | return aapcs_cp_arg_layout[i].allocate_return_reg (pcs_variant, | |
4359 | mode, type); | |
4360 | } | |
4361 | ||
4362 | /* Promotes small structs returned in a register to full-word size | |
4363 | for big-endian AAPCS. */ | |
4364 | if (type && arm_return_in_msb (type)) | |
4365 | { | |
4366 | HOST_WIDE_INT size = int_size_in_bytes (type); | |
4367 | if (size % UNITS_PER_WORD != 0) | |
4368 | { | |
4369 | size += UNITS_PER_WORD - size % UNITS_PER_WORD; | |
4370 | mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0); | |
4371 | } | |
4372 | } | |
4373 | ||
4374 | return gen_rtx_REG (mode, R0_REGNUM); | |
4375 | } | |
4376 | ||
4377 | rtx | |
4378 | aapcs_libcall_value (enum machine_mode mode) | |
4379 | { | |
655b30bf JB |
4380 | if (BYTES_BIG_ENDIAN && ALL_FIXED_POINT_MODE_P (mode) |
4381 | && GET_MODE_SIZE (mode) <= 4) | |
4382 | mode = SImode; | |
4383 | ||
390b17c2 RE |
4384 | return aapcs_allocate_return_reg (mode, NULL_TREE, NULL_TREE); |
4385 | } | |
4386 | ||
4387 | /* Lay out a function argument using the AAPCS rules. The rule | |
4388 | numbers referred to here are those in the AAPCS. */ | |
4389 | static void | |
4390 | aapcs_layout_arg (CUMULATIVE_ARGS *pcum, enum machine_mode mode, | |
9c6a2bee | 4391 | const_tree type, bool named) |
390b17c2 RE |
4392 | { |
4393 | int nregs, nregs2; | |
4394 | int ncrn; | |
4395 | ||
4396 | /* We only need to do this once per argument. */ | |
4397 | if (pcum->aapcs_arg_processed) | |
4398 | return; | |
4399 | ||
4400 | pcum->aapcs_arg_processed = true; | |
4401 | ||
4402 | /* Special case: if named is false then we are handling an incoming | |
4403 | anonymous argument which is on the stack. */ | |
4404 | if (!named) | |
4405 | return; | |
4406 | ||
4407 | /* Is this a potential co-processor register candidate? */ | |
4408 | if (pcum->pcs_variant != ARM_PCS_AAPCS) | |
4409 | { | |
4410 | int slot = aapcs_select_call_coproc (pcum, mode, type); | |
4411 | pcum->aapcs_cprc_slot = slot; | |
4412 | ||
4413 | /* We don't have to apply any of the rules from part B of the | |
4414 | preparation phase, these are handled elsewhere in the | |
4415 | compiler. */ | |
4416 | ||
4417 | if (slot >= 0) | |
4418 | { | |
4419 | /* A Co-processor register candidate goes either in its own | |
4420 | class of registers or on the stack. */ | |
4421 | if (!pcum->aapcs_cprc_failed[slot]) | |
4422 | { | |
4423 | /* C1.cp - Try to allocate the argument to co-processor | |
4424 | registers. */ | |
4425 | if (aapcs_cp_arg_layout[slot].allocate (pcum, mode, type)) | |
4426 | return; | |
4427 | ||
4428 | /* C2.cp - Put the argument on the stack and note that we | |
4429 | can't assign any more candidates in this slot. We also | |
4430 | need to note that we have allocated stack space, so that | |
4431 | we won't later try to split a non-cprc candidate between | |
4432 | core registers and the stack. */ | |
4433 | pcum->aapcs_cprc_failed[slot] = true; | |
4434 | pcum->can_split = false; | |
4435 | } | |
4436 | ||
4437 | /* We didn't get a register, so this argument goes on the | |
4438 | stack. */ | |
4439 | gcc_assert (pcum->can_split == false); | |
4440 | return; | |
4441 | } | |
4442 | } | |
4443 | ||
4444 | /* C3 - For double-word aligned arguments, round the NCRN up to the | |
4445 | next even number. */ | |
4446 | ncrn = pcum->aapcs_ncrn; | |
4447 | if ((ncrn & 1) && arm_needs_doubleword_align (mode, type)) | |
4448 | ncrn++; | |
4449 | ||
4450 | nregs = ARM_NUM_REGS2(mode, type); | |
4451 | ||
4452 | /* Sigh, this test should really assert that nregs > 0, but a GCC | |
4453 | extension allows empty structs and then gives them empty size; it | |
4454 | then allows such a structure to be passed by value. For some of | |
4455 | the code below we have to pretend that such an argument has | |
4456 | non-zero size so that we 'locate' it correctly either in | |
4457 | registers or on the stack. */ | |
4458 | gcc_assert (nregs >= 0); | |
4459 | ||
4460 | nregs2 = nregs ? nregs : 1; | |
4461 | ||
4462 | /* C4 - Argument fits entirely in core registers. */ | |
4463 | if (ncrn + nregs2 <= NUM_ARG_REGS) | |
4464 | { | |
4465 | pcum->aapcs_reg = gen_rtx_REG (mode, ncrn); | |
4466 | pcum->aapcs_next_ncrn = ncrn + nregs; | |
4467 | return; | |
4468 | } | |
4469 | ||
4470 | /* C5 - Some core registers left and there are no arguments already | |
4471 | on the stack: split this argument between the remaining core | |
4472 | registers and the stack. */ | |
4473 | if (ncrn < NUM_ARG_REGS && pcum->can_split) | |
4474 | { | |
4475 | pcum->aapcs_reg = gen_rtx_REG (mode, ncrn); | |
4476 | pcum->aapcs_next_ncrn = NUM_ARG_REGS; | |
4477 | pcum->aapcs_partial = (NUM_ARG_REGS - ncrn) * UNITS_PER_WORD; | |
4478 | return; | |
4479 | } | |
4480 | ||
4481 | /* C6 - NCRN is set to 4. */ | |
4482 | pcum->aapcs_next_ncrn = NUM_ARG_REGS; | |
4483 | ||
4484 | /* C7,C8 - arugment goes on the stack. We have nothing to do here. */ | |
4485 | return; | |
4486 | } | |
4487 | ||
82e9d970 PB |
4488 | /* Initialize a variable CUM of type CUMULATIVE_ARGS |
4489 | for a call to a function whose data type is FNTYPE. | |
4490 | For a library call, FNTYPE is NULL. */ | |
4491 | void | |
f676971a | 4492 | arm_init_cumulative_args (CUMULATIVE_ARGS *pcum, tree fntype, |
390b17c2 | 4493 | rtx libname, |
e32bac5b | 4494 | tree fndecl ATTRIBUTE_UNUSED) |
82e9d970 | 4495 | { |
390b17c2 RE |
4496 | /* Long call handling. */ |
4497 | if (fntype) | |
4498 | pcum->pcs_variant = arm_get_pcs_model (fntype, fndecl); | |
4499 | else | |
4500 | pcum->pcs_variant = arm_pcs_default; | |
4501 | ||
4502 | if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) | |
4503 | { | |
4504 | if (arm_libcall_uses_aapcs_base (libname)) | |
4505 | pcum->pcs_variant = ARM_PCS_AAPCS; | |
4506 | ||
4507 | pcum->aapcs_ncrn = pcum->aapcs_next_ncrn = 0; | |
4508 | pcum->aapcs_reg = NULL_RTX; | |
4509 | pcum->aapcs_partial = 0; | |
4510 | pcum->aapcs_arg_processed = false; | |
4511 | pcum->aapcs_cprc_slot = -1; | |
4512 | pcum->can_split = true; | |
4513 | ||
4514 | if (pcum->pcs_variant != ARM_PCS_AAPCS) | |
4515 | { | |
4516 | int i; | |
4517 | ||
4518 | for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) | |
4519 | { | |
4520 | pcum->aapcs_cprc_failed[i] = false; | |
4521 | aapcs_cp_arg_layout[i].cum_init (pcum, fntype, libname, fndecl); | |
4522 | } | |
4523 | } | |
4524 | return; | |
4525 | } | |
4526 | ||
4527 | /* Legacy ABIs */ | |
4528 | ||
82e9d970 | 4529 | /* On the ARM, the offset starts at 0. */ |
29e339b9 | 4530 | pcum->nregs = 0; |
5a9335ef | 4531 | pcum->iwmmxt_nregs = 0; |
5848830f | 4532 | pcum->can_split = true; |
f676971a | 4533 | |
5a9335ef NC |
4534 | /* Varargs vectors are treated the same as long long. |
4535 | named_count avoids having to change the way arm handles 'named' */ | |
4536 | pcum->named_count = 0; | |
4537 | pcum->nargs = 0; | |
4538 | ||
4539 | if (TARGET_REALLY_IWMMXT && fntype) | |
4540 | { | |
4541 | tree fn_arg; | |
4542 | ||
4543 | for (fn_arg = TYPE_ARG_TYPES (fntype); | |
4544 | fn_arg; | |
4545 | fn_arg = TREE_CHAIN (fn_arg)) | |
4546 | pcum->named_count += 1; | |
4547 | ||
4548 | if (! pcum->named_count) | |
4549 | pcum->named_count = INT_MAX; | |
4550 | } | |
82e9d970 PB |
4551 | } |
4552 | ||
5848830f PB |
4553 | |
4554 | /* Return true if mode/type need doubleword alignment. */ | |
c2ed6cf8 | 4555 | static bool |
9c6a2bee | 4556 | arm_needs_doubleword_align (enum machine_mode mode, const_tree type) |
5848830f | 4557 | { |
65a939f7 PB |
4558 | return (GET_MODE_ALIGNMENT (mode) > PARM_BOUNDARY |
4559 | || (type && TYPE_ALIGN (type) > PARM_BOUNDARY)); | |
5848830f PB |
4560 | } |
4561 | ||
4562 | ||
82e9d970 PB |
4563 | /* Determine where to put an argument to a function. |
4564 | Value is zero to push the argument on the stack, | |
4565 | or a hard register in which to store the argument. | |
4566 | ||
4567 | MODE is the argument's machine mode. | |
4568 | TYPE is the data type of the argument (as a tree). | |
4569 | This is null for libcalls where that information may | |
4570 | not be available. | |
4571 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
4572 | the preceding args and about the function being called. | |
4573 | NAMED is nonzero if this argument is a named parameter | |
9c6a2bee | 4574 | (otherwise it is an extra parameter matching an ellipsis). |
1d6e90ac | 4575 | |
9c6a2bee NF |
4576 | On the ARM, normally the first 16 bytes are passed in registers r0-r3; all |
4577 | other arguments are passed on the stack. If (NAMED == 0) (which happens | |
4578 | only in assign_parms, since TARGET_SETUP_INCOMING_VARARGS is | |
4579 | defined), say it is passed in the stack (function_prologue will | |
4580 | indeed make it pass in the stack if necessary). */ | |
4581 | ||
4582 | static rtx | |
d5cc9181 | 4583 | arm_function_arg (cumulative_args_t pcum_v, enum machine_mode mode, |
9c6a2bee | 4584 | const_tree type, bool named) |
82e9d970 | 4585 | { |
d5cc9181 | 4586 | CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v); |
5848830f PB |
4587 | int nregs; |
4588 | ||
390b17c2 RE |
4589 | /* Handle the special case quickly. Pick an arbitrary value for op2 of |
4590 | a call insn (op3 of a call_value insn). */ | |
4591 | if (mode == VOIDmode) | |
4592 | return const0_rtx; | |
4593 | ||
4594 | if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) | |
4595 | { | |
4596 | aapcs_layout_arg (pcum, mode, type, named); | |
4597 | return pcum->aapcs_reg; | |
4598 | } | |
4599 | ||
5848830f PB |
4600 | /* Varargs vectors are treated the same as long long. |
4601 | named_count avoids having to change the way arm handles 'named' */ | |
4602 | if (TARGET_IWMMXT_ABI | |
f676971a | 4603 | && arm_vector_mode_supported_p (mode) |
5848830f | 4604 | && pcum->named_count > pcum->nargs + 1) |
5a9335ef | 4605 | { |
5848830f PB |
4606 | if (pcum->iwmmxt_nregs <= 9) |
4607 | return gen_rtx_REG (mode, pcum->iwmmxt_nregs + FIRST_IWMMXT_REGNUM); | |
4608 | else | |
5a9335ef | 4609 | { |
5848830f PB |
4610 | pcum->can_split = false; |
4611 | return NULL_RTX; | |
5a9335ef | 4612 | } |
5a9335ef NC |
4613 | } |
4614 | ||
5848830f PB |
4615 | /* Put doubleword aligned quantities in even register pairs. */ |
4616 | if (pcum->nregs & 1 | |
4617 | && ARM_DOUBLEWORD_ALIGN | |
4618 | && arm_needs_doubleword_align (mode, type)) | |
4619 | pcum->nregs++; | |
4620 | ||
666c27b9 | 4621 | /* Only allow splitting an arg between regs and memory if all preceding |
5848830f PB |
4622 | args were allocated to regs. For args passed by reference we only count |
4623 | the reference pointer. */ | |
4624 | if (pcum->can_split) | |
4625 | nregs = 1; | |
4626 | else | |
4627 | nregs = ARM_NUM_REGS2 (mode, type); | |
4628 | ||
4629 | if (!named || pcum->nregs + nregs > NUM_ARG_REGS) | |
82e9d970 | 4630 | return NULL_RTX; |
f676971a | 4631 | |
82e9d970 PB |
4632 | return gen_rtx_REG (mode, pcum->nregs); |
4633 | } | |
1741620c | 4634 | |
c2ed6cf8 NF |
4635 | static unsigned int |
4636 | arm_function_arg_boundary (enum machine_mode mode, const_tree type) | |
4637 | { | |
4638 | return (ARM_DOUBLEWORD_ALIGN && arm_needs_doubleword_align (mode, type) | |
4639 | ? DOUBLEWORD_ALIGNMENT | |
4640 | : PARM_BOUNDARY); | |
4641 | } | |
4642 | ||
78a52f11 | 4643 | static int |
d5cc9181 | 4644 | arm_arg_partial_bytes (cumulative_args_t pcum_v, enum machine_mode mode, |
390b17c2 | 4645 | tree type, bool named) |
78a52f11 | 4646 | { |
d5cc9181 | 4647 | CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v); |
78a52f11 RH |
4648 | int nregs = pcum->nregs; |
4649 | ||
390b17c2 RE |
4650 | if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) |
4651 | { | |
4652 | aapcs_layout_arg (pcum, mode, type, named); | |
4653 | return pcum->aapcs_partial; | |
4654 | } | |
4655 | ||
88f77cba | 4656 | if (TARGET_IWMMXT_ABI && arm_vector_mode_supported_p (mode)) |
78a52f11 RH |
4657 | return 0; |
4658 | ||
4659 | if (NUM_ARG_REGS > nregs | |
4660 | && (NUM_ARG_REGS < nregs + ARM_NUM_REGS2 (mode, type)) | |
4661 | && pcum->can_split) | |
4662 | return (NUM_ARG_REGS - nregs) * UNITS_PER_WORD; | |
4663 | ||
4664 | return 0; | |
4665 | } | |
4666 | ||
9c6a2bee NF |
4667 | /* Update the data in PCUM to advance over an argument |
4668 | of mode MODE and data type TYPE. | |
4669 | (TYPE is null for libcalls where that information may not be available.) */ | |
4670 | ||
4671 | static void | |
d5cc9181 | 4672 | arm_function_arg_advance (cumulative_args_t pcum_v, enum machine_mode mode, |
9c6a2bee | 4673 | const_tree type, bool named) |
390b17c2 | 4674 | { |
d5cc9181 JR |
4675 | CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v); |
4676 | ||
390b17c2 RE |
4677 | if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) |
4678 | { | |
4679 | aapcs_layout_arg (pcum, mode, type, named); | |
4680 | ||
4681 | if (pcum->aapcs_cprc_slot >= 0) | |
4682 | { | |
4683 | aapcs_cp_arg_layout[pcum->aapcs_cprc_slot].advance (pcum, mode, | |
4684 | type); | |
4685 | pcum->aapcs_cprc_slot = -1; | |
4686 | } | |
4687 | ||
4688 | /* Generic stuff. */ | |
4689 | pcum->aapcs_arg_processed = false; | |
4690 | pcum->aapcs_ncrn = pcum->aapcs_next_ncrn; | |
4691 | pcum->aapcs_reg = NULL_RTX; | |
4692 | pcum->aapcs_partial = 0; | |
4693 | } | |
4694 | else | |
4695 | { | |
4696 | pcum->nargs += 1; | |
4697 | if (arm_vector_mode_supported_p (mode) | |
4698 | && pcum->named_count > pcum->nargs | |
4699 | && TARGET_IWMMXT_ABI) | |
4700 | pcum->iwmmxt_nregs += 1; | |
4701 | else | |
4702 | pcum->nregs += ARM_NUM_REGS2 (mode, type); | |
4703 | } | |
4704 | } | |
4705 | ||
1741620c JD |
4706 | /* Variable sized types are passed by reference. This is a GCC |
4707 | extension to the ARM ABI. */ | |
4708 | ||
8cd5a4e0 | 4709 | static bool |
d5cc9181 | 4710 | arm_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED, |
8cd5a4e0 | 4711 | enum machine_mode mode ATTRIBUTE_UNUSED, |
586de218 | 4712 | const_tree type, bool named ATTRIBUTE_UNUSED) |
1741620c JD |
4713 | { |
4714 | return type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST; | |
4715 | } | |
82e9d970 | 4716 | \f |
c27ba912 DM |
4717 | /* Encode the current state of the #pragma [no_]long_calls. */ |
4718 | typedef enum | |
82e9d970 | 4719 | { |
6fc0bb99 | 4720 | OFF, /* No #pragma [no_]long_calls is in effect. */ |
c27ba912 DM |
4721 | LONG, /* #pragma long_calls is in effect. */ |
4722 | SHORT /* #pragma no_long_calls is in effect. */ | |
4723 | } arm_pragma_enum; | |
82e9d970 | 4724 | |
c27ba912 | 4725 | static arm_pragma_enum arm_pragma_long_calls = OFF; |
82e9d970 | 4726 | |
8b97c5f8 | 4727 | void |
e32bac5b | 4728 | arm_pr_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED) |
82e9d970 | 4729 | { |
8b97c5f8 ZW |
4730 | arm_pragma_long_calls = LONG; |
4731 | } | |
4732 | ||
4733 | void | |
e32bac5b | 4734 | arm_pr_no_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED) |
8b97c5f8 ZW |
4735 | { |
4736 | arm_pragma_long_calls = SHORT; | |
4737 | } | |
4738 | ||
4739 | void | |
e32bac5b | 4740 | arm_pr_long_calls_off (struct cpp_reader * pfile ATTRIBUTE_UNUSED) |
8b97c5f8 ZW |
4741 | { |
4742 | arm_pragma_long_calls = OFF; | |
82e9d970 PB |
4743 | } |
4744 | \f | |
91d231cb JM |
4745 | /* Handle an attribute requiring a FUNCTION_DECL; |
4746 | arguments as in struct attribute_spec.handler. */ | |
4747 | static tree | |
e32bac5b RE |
4748 | arm_handle_fndecl_attribute (tree *node, tree name, tree args ATTRIBUTE_UNUSED, |
4749 | int flags ATTRIBUTE_UNUSED, bool *no_add_attrs) | |
91d231cb JM |
4750 | { |
4751 | if (TREE_CODE (*node) != FUNCTION_DECL) | |
4752 | { | |
29d08eba JM |
4753 | warning (OPT_Wattributes, "%qE attribute only applies to functions", |
4754 | name); | |
91d231cb JM |
4755 | *no_add_attrs = true; |
4756 | } | |
4757 | ||
4758 | return NULL_TREE; | |
4759 | } | |
4760 | ||
4761 | /* Handle an "interrupt" or "isr" attribute; | |
4762 | arguments as in struct attribute_spec.handler. */ | |
4763 | static tree | |
e32bac5b RE |
4764 | arm_handle_isr_attribute (tree *node, tree name, tree args, int flags, |
4765 | bool *no_add_attrs) | |
91d231cb JM |
4766 | { |
4767 | if (DECL_P (*node)) | |
4768 | { | |
4769 | if (TREE_CODE (*node) != FUNCTION_DECL) | |
4770 | { | |
29d08eba JM |
4771 | warning (OPT_Wattributes, "%qE attribute only applies to functions", |
4772 | name); | |
91d231cb JM |
4773 | *no_add_attrs = true; |
4774 | } | |
4775 | /* FIXME: the argument if any is checked for type attributes; | |
4776 | should it be checked for decl ones? */ | |
4777 | } | |
4778 | else | |
4779 | { | |
4780 | if (TREE_CODE (*node) == FUNCTION_TYPE | |
4781 | || TREE_CODE (*node) == METHOD_TYPE) | |
4782 | { | |
4783 | if (arm_isr_value (args) == ARM_FT_UNKNOWN) | |
4784 | { | |
29d08eba JM |
4785 | warning (OPT_Wattributes, "%qE attribute ignored", |
4786 | name); | |
91d231cb JM |
4787 | *no_add_attrs = true; |
4788 | } | |
4789 | } | |
4790 | else if (TREE_CODE (*node) == POINTER_TYPE | |
4791 | && (TREE_CODE (TREE_TYPE (*node)) == FUNCTION_TYPE | |
4792 | || TREE_CODE (TREE_TYPE (*node)) == METHOD_TYPE) | |
4793 | && arm_isr_value (args) != ARM_FT_UNKNOWN) | |
4794 | { | |
8dd16ecc | 4795 | *node = build_variant_type_copy (*node); |
1d6e90ac NC |
4796 | TREE_TYPE (*node) = build_type_attribute_variant |
4797 | (TREE_TYPE (*node), | |
4798 | tree_cons (name, args, TYPE_ATTRIBUTES (TREE_TYPE (*node)))); | |
91d231cb JM |
4799 | *no_add_attrs = true; |
4800 | } | |
4801 | else | |
4802 | { | |
4803 | /* Possibly pass this attribute on from the type to a decl. */ | |
4804 | if (flags & ((int) ATTR_FLAG_DECL_NEXT | |
4805 | | (int) ATTR_FLAG_FUNCTION_NEXT | |
4806 | | (int) ATTR_FLAG_ARRAY_NEXT)) | |
4807 | { | |
4808 | *no_add_attrs = true; | |
4809 | return tree_cons (name, args, NULL_TREE); | |
4810 | } | |
4811 | else | |
4812 | { | |
29d08eba JM |
4813 | warning (OPT_Wattributes, "%qE attribute ignored", |
4814 | name); | |
91d231cb JM |
4815 | } |
4816 | } | |
4817 | } | |
4818 | ||
4819 | return NULL_TREE; | |
82e9d970 PB |
4820 | } |
4821 | ||
390b17c2 RE |
4822 | /* Handle a "pcs" attribute; arguments as in struct |
4823 | attribute_spec.handler. */ | |
4824 | static tree | |
4825 | arm_handle_pcs_attribute (tree *node ATTRIBUTE_UNUSED, tree name, tree args, | |
4826 | int flags ATTRIBUTE_UNUSED, bool *no_add_attrs) | |
4827 | { | |
4828 | if (arm_pcs_from_attribute (args) == ARM_PCS_UNKNOWN) | |
4829 | { | |
a9717079 | 4830 | warning (OPT_Wattributes, "%qE attribute ignored", name); |
390b17c2 RE |
4831 | *no_add_attrs = true; |
4832 | } | |
4833 | return NULL_TREE; | |
4834 | } | |
4835 | ||
7bff66a7 | 4836 | #if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
04fb56d5 MM |
4837 | /* Handle the "notshared" attribute. This attribute is another way of |
4838 | requesting hidden visibility. ARM's compiler supports | |
4839 | "__declspec(notshared)"; we support the same thing via an | |
4840 | attribute. */ | |
4841 | ||
4842 | static tree | |
e0b92319 NC |
4843 | arm_handle_notshared_attribute (tree *node, |
4844 | tree name ATTRIBUTE_UNUSED, | |
4845 | tree args ATTRIBUTE_UNUSED, | |
4846 | int flags ATTRIBUTE_UNUSED, | |
04fb56d5 MM |
4847 | bool *no_add_attrs) |
4848 | { | |
4849 | tree decl = TYPE_NAME (*node); | |
4850 | ||
4851 | if (decl) | |
4852 | { | |
4853 | DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; | |
4854 | DECL_VISIBILITY_SPECIFIED (decl) = 1; | |
4855 | *no_add_attrs = false; | |
4856 | } | |
4857 | return NULL_TREE; | |
4858 | } | |
7bff66a7 | 4859 | #endif |
04fb56d5 | 4860 | |
82e9d970 PB |
4861 | /* Return 0 if the attributes for two types are incompatible, 1 if they |
4862 | are compatible, and 2 if they are nearly compatible (which causes a | |
4863 | warning to be generated). */ | |
8d8e52be | 4864 | static int |
3101faab | 4865 | arm_comp_type_attributes (const_tree type1, const_tree type2) |
82e9d970 | 4866 | { |
1cb8d58a | 4867 | int l1, l2, s1, s2; |
f676971a | 4868 | |
82e9d970 PB |
4869 | /* Check for mismatch of non-default calling convention. */ |
4870 | if (TREE_CODE (type1) != FUNCTION_TYPE) | |
4871 | return 1; | |
4872 | ||
4873 | /* Check for mismatched call attributes. */ | |
1cb8d58a NC |
4874 | l1 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type1)) != NULL; |
4875 | l2 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type2)) != NULL; | |
4876 | s1 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type1)) != NULL; | |
4877 | s2 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type2)) != NULL; | |
bd7fc26f NC |
4878 | |
4879 | /* Only bother to check if an attribute is defined. */ | |
4880 | if (l1 | l2 | s1 | s2) | |
4881 | { | |
4882 | /* If one type has an attribute, the other must have the same attribute. */ | |
1cb8d58a | 4883 | if ((l1 != l2) || (s1 != s2)) |
bd7fc26f | 4884 | return 0; |
82e9d970 | 4885 | |
bd7fc26f NC |
4886 | /* Disallow mixed attributes. */ |
4887 | if ((l1 & s2) || (l2 & s1)) | |
4888 | return 0; | |
4889 | } | |
f676971a | 4890 | |
6d3d9133 NC |
4891 | /* Check for mismatched ISR attribute. */ |
4892 | l1 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type1)) != NULL; | |
4893 | if (! l1) | |
4894 | l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1)) != NULL; | |
4895 | l2 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type2)) != NULL; | |
4896 | if (! l2) | |
4897 | l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2)) != NULL; | |
4898 | if (l1 != l2) | |
4899 | return 0; | |
4900 | ||
bd7fc26f | 4901 | return 1; |
82e9d970 PB |
4902 | } |
4903 | ||
c27ba912 DM |
4904 | /* Assigns default attributes to newly defined type. This is used to |
4905 | set short_call/long_call attributes for function types of | |
4906 | functions defined inside corresponding #pragma scopes. */ | |
8d8e52be | 4907 | static void |
e32bac5b | 4908 | arm_set_default_type_attributes (tree type) |
c27ba912 DM |
4909 | { |
4910 | /* Add __attribute__ ((long_call)) to all functions, when | |
4911 | inside #pragma long_calls or __attribute__ ((short_call)), | |
4912 | when inside #pragma no_long_calls. */ | |
4913 | if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) | |
4914 | { | |
4915 | tree type_attr_list, attr_name; | |
4916 | type_attr_list = TYPE_ATTRIBUTES (type); | |
4917 | ||
4918 | if (arm_pragma_long_calls == LONG) | |
4919 | attr_name = get_identifier ("long_call"); | |
4920 | else if (arm_pragma_long_calls == SHORT) | |
4921 | attr_name = get_identifier ("short_call"); | |
4922 | else | |
4923 | return; | |
4924 | ||
4925 | type_attr_list = tree_cons (attr_name, NULL_TREE, type_attr_list); | |
4926 | TYPE_ATTRIBUTES (type) = type_attr_list; | |
4927 | } | |
4928 | } | |
4929 | \f | |
25a65198 RS |
4930 | /* Return true if DECL is known to be linked into section SECTION. */ |
4931 | ||
4932 | static bool | |
4933 | arm_function_in_section_p (tree decl, section *section) | |
c27ba912 | 4934 | { |
25a65198 RS |
4935 | /* We can only be certain about functions defined in the same |
4936 | compilation unit. */ | |
4937 | if (!TREE_STATIC (decl)) | |
4938 | return false; | |
c27ba912 | 4939 | |
25a65198 RS |
4940 | /* Make sure that SYMBOL always binds to the definition in this |
4941 | compilation unit. */ | |
4942 | if (!targetm.binds_local_p (decl)) | |
4943 | return false; | |
c27ba912 | 4944 | |
25a65198 RS |
4945 | /* If DECL_SECTION_NAME is set, assume it is trustworthy. */ |
4946 | if (!DECL_SECTION_NAME (decl)) | |
4947 | { | |
25a65198 RS |
4948 | /* Make sure that we will not create a unique section for DECL. */ |
4949 | if (flag_function_sections || DECL_ONE_ONLY (decl)) | |
4950 | return false; | |
4951 | } | |
4952 | ||
4953 | return function_section (decl) == section; | |
c27ba912 DM |
4954 | } |
4955 | ||
a50aa827 | 4956 | /* Return nonzero if a 32-bit "long_call" should be generated for |
25a65198 RS |
4957 | a call from the current function to DECL. We generate a long_call |
4958 | if the function: | |
c27ba912 DM |
4959 | |
4960 | a. has an __attribute__((long call)) | |
4961 | or b. is within the scope of a #pragma long_calls | |
4962 | or c. the -mlong-calls command line switch has been specified | |
4963 | ||
4964 | However we do not generate a long call if the function: | |
f676971a | 4965 | |
c27ba912 DM |
4966 | d. has an __attribute__ ((short_call)) |
4967 | or e. is inside the scope of a #pragma no_long_calls | |
25a65198 | 4968 | or f. is defined in the same section as the current function. */ |
c27ba912 | 4969 | |
25a65198 RS |
4970 | bool |
4971 | arm_is_long_call_p (tree decl) | |
4972 | { | |
4973 | tree attrs; | |
c27ba912 | 4974 | |
25a65198 RS |
4975 | if (!decl) |
4976 | return TARGET_LONG_CALLS; | |
c27ba912 | 4977 | |
25a65198 RS |
4978 | attrs = TYPE_ATTRIBUTES (TREE_TYPE (decl)); |
4979 | if (lookup_attribute ("short_call", attrs)) | |
4980 | return false; | |
c27ba912 | 4981 | |
25a65198 RS |
4982 | /* For "f", be conservative, and only cater for cases in which the |
4983 | whole of the current function is placed in the same section. */ | |
4984 | if (!flag_reorder_blocks_and_partition | |
b3a796bc | 4985 | && TREE_CODE (decl) == FUNCTION_DECL |
25a65198 RS |
4986 | && arm_function_in_section_p (decl, current_function_section ())) |
4987 | return false; | |
a77655b1 | 4988 | |
25a65198 RS |
4989 | if (lookup_attribute ("long_call", attrs)) |
4990 | return true; | |
f676971a | 4991 | |
25a65198 | 4992 | return TARGET_LONG_CALLS; |
c27ba912 | 4993 | } |
f99fce0c | 4994 | |
825dda42 | 4995 | /* Return nonzero if it is ok to make a tail-call to DECL. */ |
4977bab6 | 4996 | static bool |
390b17c2 | 4997 | arm_function_ok_for_sibcall (tree decl, tree exp) |
f99fce0c | 4998 | { |
5b3e6663 | 4999 | unsigned long func_type; |
f99fce0c | 5000 | |
5a9335ef NC |
5001 | if (cfun->machine->sibcall_blocked) |
5002 | return false; | |
5003 | ||
f99fce0c | 5004 | /* Never tailcall something for which we have no decl, or if we |
7c19c715 JB |
5005 | are generating code for Thumb-1. */ |
5006 | if (decl == NULL || TARGET_THUMB1) | |
4977bab6 | 5007 | return false; |
f99fce0c | 5008 | |
9403b7f7 RS |
5009 | /* The PIC register is live on entry to VxWorks PLT entries, so we |
5010 | must make the call before restoring the PIC register. */ | |
5011 | if (TARGET_VXWORKS_RTP && flag_pic && !targetm.binds_local_p (decl)) | |
5012 | return false; | |
5013 | ||
f99fce0c | 5014 | /* Cannot tail-call to long calls, since these are out of range of |
25a65198 RS |
5015 | a branch instruction. */ |
5016 | if (arm_is_long_call_p (decl)) | |
4977bab6 | 5017 | return false; |
f99fce0c RE |
5018 | |
5019 | /* If we are interworking and the function is not declared static | |
f676971a | 5020 | then we can't tail-call it unless we know that it exists in this |
f99fce0c | 5021 | compilation unit (since it might be a Thumb routine). */ |
5895f793 | 5022 | if (TARGET_INTERWORK && TREE_PUBLIC (decl) && !TREE_ASM_WRITTEN (decl)) |
4977bab6 | 5023 | return false; |
f99fce0c | 5024 | |
5b3e6663 | 5025 | func_type = arm_current_func_type (); |
6d3d9133 | 5026 | /* Never tailcall from an ISR routine - it needs a special exit sequence. */ |
5b3e6663 PB |
5027 | if (IS_INTERRUPT (func_type)) |
5028 | return false; | |
5029 | ||
390b17c2 RE |
5030 | if (!VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl)))) |
5031 | { | |
5032 | /* Check that the return value locations are the same. For | |
5033 | example that we aren't returning a value from the sibling in | |
5034 | a VFP register but then need to transfer it to a core | |
5035 | register. */ | |
5036 | rtx a, b; | |
5037 | ||
5038 | a = arm_function_value (TREE_TYPE (exp), decl, false); | |
5039 | b = arm_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)), | |
5040 | cfun->decl, false); | |
5041 | if (!rtx_equal_p (a, b)) | |
5042 | return false; | |
5043 | } | |
5044 | ||
5b3e6663 PB |
5045 | /* Never tailcall if function may be called with a misaligned SP. */ |
5046 | if (IS_STACKALIGN (func_type)) | |
4977bab6 | 5047 | return false; |
6d3d9133 | 5048 | |
f99fce0c | 5049 | /* Everything else is ok. */ |
4977bab6 | 5050 | return true; |
f99fce0c RE |
5051 | } |
5052 | ||
82e9d970 | 5053 | \f |
6b990f6b RE |
5054 | /* Addressing mode support functions. */ |
5055 | ||
0b4be7de | 5056 | /* Return nonzero if X is a legitimate immediate operand when compiling |
020a4035 | 5057 | for PIC. We know that X satisfies CONSTANT_P and flag_pic is true. */ |
32de079a | 5058 | int |
e32bac5b | 5059 | legitimate_pic_operand_p (rtx x) |
32de079a | 5060 | { |
020a4035 RE |
5061 | if (GET_CODE (x) == SYMBOL_REF |
5062 | || (GET_CODE (x) == CONST | |
5063 | && GET_CODE (XEXP (x, 0)) == PLUS | |
5064 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)) | |
32de079a RE |
5065 | return 0; |
5066 | ||
5067 | return 1; | |
5068 | } | |
5069 | ||
9403b7f7 RS |
5070 | /* Record that the current function needs a PIC register. Initialize |
5071 | cfun->machine->pic_reg if we have not already done so. */ | |
5072 | ||
5073 | static void | |
5074 | require_pic_register (void) | |
5075 | { | |
5076 | /* A lot of the logic here is made obscure by the fact that this | |
5077 | routine gets called as part of the rtx cost estimation process. | |
5078 | We don't want those calls to affect any assumptions about the real | |
5079 | function; and further, we can't call entry_of_function() until we | |
5080 | start the real expansion process. */ | |
e3b5732b | 5081 | if (!crtl->uses_pic_offset_table) |
9403b7f7 | 5082 | { |
b3a13419 | 5083 | gcc_assert (can_create_pseudo_p ()); |
9403b7f7 RS |
5084 | if (arm_pic_register != INVALID_REGNUM) |
5085 | { | |
6d2538f5 JB |
5086 | if (!cfun->machine->pic_reg) |
5087 | cfun->machine->pic_reg = gen_rtx_REG (Pmode, arm_pic_register); | |
9403b7f7 RS |
5088 | |
5089 | /* Play games to avoid marking the function as needing pic | |
5090 | if we are being called as part of the cost-estimation | |
5091 | process. */ | |
04ef80ce | 5092 | if (current_ir_type () != IR_GIMPLE || currently_expanding_to_rtl) |
e3b5732b | 5093 | crtl->uses_pic_offset_table = 1; |
9403b7f7 RS |
5094 | } |
5095 | else | |
5096 | { | |
cb227aa9 | 5097 | rtx seq, insn; |
9403b7f7 | 5098 | |
6d2538f5 JB |
5099 | if (!cfun->machine->pic_reg) |
5100 | cfun->machine->pic_reg = gen_reg_rtx (Pmode); | |
9403b7f7 RS |
5101 | |
5102 | /* Play games to avoid marking the function as needing pic | |
5103 | if we are being called as part of the cost-estimation | |
5104 | process. */ | |
04ef80ce | 5105 | if (current_ir_type () != IR_GIMPLE || currently_expanding_to_rtl) |
9403b7f7 | 5106 | { |
e3b5732b | 5107 | crtl->uses_pic_offset_table = 1; |
9403b7f7 RS |
5108 | start_sequence (); |
5109 | ||
5110 | arm_load_pic_register (0UL); | |
5111 | ||
5112 | seq = get_insns (); | |
5113 | end_sequence (); | |
cb227aa9 UW |
5114 | |
5115 | for (insn = seq; insn; insn = NEXT_INSN (insn)) | |
5116 | if (INSN_P (insn)) | |
5117 | INSN_LOCATOR (insn) = prologue_locator; | |
5118 | ||
af618949 MM |
5119 | /* We can be called during expansion of PHI nodes, where |
5120 | we can't yet emit instructions directly in the final | |
5121 | insn stream. Queue the insns on the entry edge, they will | |
5122 | be committed after everything else is expanded. */ | |
5123 | insert_insn_on_edge (seq, single_succ_edge (ENTRY_BLOCK_PTR)); | |
9403b7f7 RS |
5124 | } |
5125 | } | |
5126 | } | |
5127 | } | |
5128 | ||
32de079a | 5129 | rtx |
e32bac5b | 5130 | legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg) |
32de079a | 5131 | { |
a3c48721 RE |
5132 | if (GET_CODE (orig) == SYMBOL_REF |
5133 | || GET_CODE (orig) == LABEL_REF) | |
32de079a | 5134 | { |
32de079a | 5135 | rtx insn; |
020a4035 | 5136 | |
32de079a RE |
5137 | if (reg == 0) |
5138 | { | |
b3a13419 | 5139 | gcc_assert (can_create_pseudo_p ()); |
e6d29d15 | 5140 | reg = gen_reg_rtx (Pmode); |
32de079a | 5141 | } |
32de079a | 5142 | |
9403b7f7 RS |
5143 | /* VxWorks does not impose a fixed gap between segments; the run-time |
5144 | gap can be different from the object-file gap. We therefore can't | |
5145 | use GOTOFF unless we are absolutely sure that the symbol is in the | |
5146 | same segment as the GOT. Unfortunately, the flexibility of linker | |
5147 | scripts means that we can't be sure of that in general, so assume | |
5148 | that GOTOFF is never valid on VxWorks. */ | |
14f583b8 | 5149 | if ((GET_CODE (orig) == LABEL_REF |
f676971a | 5150 | || (GET_CODE (orig) == SYMBOL_REF && |
94428622 | 5151 | SYMBOL_REF_LOCAL_P (orig))) |
9403b7f7 RS |
5152 | && NEED_GOT_RELOC |
5153 | && !TARGET_VXWORKS_RTP) | |
85c9bcd4 | 5154 | insn = arm_pic_static_addr (orig, reg); |
a3c48721 RE |
5155 | else |
5156 | { | |
d37c3c62 MK |
5157 | rtx pat; |
5158 | rtx mem; | |
5159 | ||
85c9bcd4 WG |
5160 | /* If this function doesn't have a pic register, create one now. */ |
5161 | require_pic_register (); | |
5162 | ||
d37c3c62 | 5163 | pat = gen_calculate_pic_address (reg, cfun->machine->pic_reg, orig); |
85c9bcd4 | 5164 | |
d37c3c62 MK |
5165 | /* Make the MEM as close to a constant as possible. */ |
5166 | mem = SET_SRC (pat); | |
5167 | gcc_assert (MEM_P (mem) && !MEM_VOLATILE_P (mem)); | |
5168 | MEM_READONLY_P (mem) = 1; | |
5169 | MEM_NOTRAP_P (mem) = 1; | |
5170 | ||
5171 | insn = emit_insn (pat); | |
a3c48721 RE |
5172 | } |
5173 | ||
32de079a RE |
5174 | /* Put a REG_EQUAL note on this insn, so that it can be optimized |
5175 | by loop. */ | |
bd94cb6e SB |
5176 | set_unique_reg_note (insn, REG_EQUAL, orig); |
5177 | ||
32de079a RE |
5178 | return reg; |
5179 | } | |
5180 | else if (GET_CODE (orig) == CONST) | |
5181 | { | |
5182 | rtx base, offset; | |
5183 | ||
5184 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
020a4035 | 5185 | && XEXP (XEXP (orig, 0), 0) == cfun->machine->pic_reg) |
32de079a RE |
5186 | return orig; |
5187 | ||
f67358da | 5188 | /* Handle the case where we have: const (UNSPEC_TLS). */ |
d3585b76 DJ |
5189 | if (GET_CODE (XEXP (orig, 0)) == UNSPEC |
5190 | && XINT (XEXP (orig, 0), 1) == UNSPEC_TLS) | |
5191 | return orig; | |
5192 | ||
f67358da PB |
5193 | /* Handle the case where we have: |
5194 | const (plus (UNSPEC_TLS) (ADDEND)). The ADDEND must be a | |
5195 | CONST_INT. */ | |
5196 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
5197 | && GET_CODE (XEXP (XEXP (orig, 0), 0)) == UNSPEC | |
5198 | && XINT (XEXP (XEXP (orig, 0), 0), 1) == UNSPEC_TLS) | |
5199 | { | |
5200 | gcc_assert (GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT); | |
5201 | return orig; | |
5202 | } | |
5203 | ||
32de079a RE |
5204 | if (reg == 0) |
5205 | { | |
b3a13419 | 5206 | gcc_assert (can_create_pseudo_p ()); |
e6d29d15 | 5207 | reg = gen_reg_rtx (Pmode); |
32de079a RE |
5208 | } |
5209 | ||
e6d29d15 | 5210 | gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS); |
e0b92319 | 5211 | |
e6d29d15 NS |
5212 | base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg); |
5213 | offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode, | |
5214 | base == reg ? 0 : reg); | |
32de079a RE |
5215 | |
5216 | if (GET_CODE (offset) == CONST_INT) | |
5217 | { | |
5218 | /* The base register doesn't really matter, we only want to | |
5219 | test the index for the appropriate mode. */ | |
1e1ab407 | 5220 | if (!arm_legitimate_index_p (mode, offset, SET, 0)) |
6b990f6b | 5221 | { |
b3a13419 | 5222 | gcc_assert (can_create_pseudo_p ()); |
e6d29d15 | 5223 | offset = force_reg (Pmode, offset); |
6b990f6b | 5224 | } |
32de079a | 5225 | |
32de079a | 5226 | if (GET_CODE (offset) == CONST_INT) |
ed8908e7 | 5227 | return plus_constant (base, INTVAL (offset)); |
32de079a RE |
5228 | } |
5229 | ||
5230 | if (GET_MODE_SIZE (mode) > 4 | |
5231 | && (GET_MODE_CLASS (mode) == MODE_INT | |
5232 | || TARGET_SOFT_FLOAT)) | |
5233 | { | |
5234 | emit_insn (gen_addsi3 (reg, base, offset)); | |
5235 | return reg; | |
5236 | } | |
5237 | ||
43cffd11 | 5238 | return gen_rtx_PLUS (Pmode, base, offset); |
32de079a | 5239 | } |
32de079a RE |
5240 | |
5241 | return orig; | |
5242 | } | |
5243 | ||
57934c39 | 5244 | |
5b3e6663 | 5245 | /* Find a spare register to use during the prolog of a function. */ |
57934c39 PB |
5246 | |
5247 | static int | |
b279b20a | 5248 | thumb_find_work_register (unsigned long pushed_regs_mask) |
57934c39 PB |
5249 | { |
5250 | int reg; | |
5251 | ||
b279b20a NC |
5252 | /* Check the argument registers first as these are call-used. The |
5253 | register allocation order means that sometimes r3 might be used | |
5254 | but earlier argument registers might not, so check them all. */ | |
5255 | for (reg = LAST_ARG_REGNUM; reg >= 0; reg --) | |
6fb5fa3c | 5256 | if (!df_regs_ever_live_p (reg)) |
b279b20a NC |
5257 | return reg; |
5258 | ||
5259 | /* Before going on to check the call-saved registers we can try a couple | |
5260 | more ways of deducing that r3 is available. The first is when we are | |
5261 | pushing anonymous arguments onto the stack and we have less than 4 | |
5262 | registers worth of fixed arguments(*). In this case r3 will be part of | |
5263 | the variable argument list and so we can be sure that it will be | |
5264 | pushed right at the start of the function. Hence it will be available | |
5265 | for the rest of the prologue. | |
38173d38 | 5266 | (*): ie crtl->args.pretend_args_size is greater than 0. */ |
b279b20a | 5267 | if (cfun->machine->uses_anonymous_args |
38173d38 | 5268 | && crtl->args.pretend_args_size > 0) |
57934c39 PB |
5269 | return LAST_ARG_REGNUM; |
5270 | ||
b279b20a NC |
5271 | /* The other case is when we have fixed arguments but less than 4 registers |
5272 | worth. In this case r3 might be used in the body of the function, but | |
5273 | it is not being used to convey an argument into the function. In theory | |
38173d38 | 5274 | we could just check crtl->args.size to see how many bytes are |
b279b20a NC |
5275 | being passed in argument registers, but it seems that it is unreliable. |
5276 | Sometimes it will have the value 0 when in fact arguments are being | |
5277 | passed. (See testcase execute/20021111-1.c for an example). So we also | |
5278 | check the args_info.nregs field as well. The problem with this field is | |
5279 | that it makes no allowances for arguments that are passed to the | |
5280 | function but which are not used. Hence we could miss an opportunity | |
5281 | when a function has an unused argument in r3. But it is better to be | |
5282 | safe than to be sorry. */ | |
5283 | if (! cfun->machine->uses_anonymous_args | |
38173d38 JH |
5284 | && crtl->args.size >= 0 |
5285 | && crtl->args.size <= (LAST_ARG_REGNUM * UNITS_PER_WORD) | |
f6d2671e | 5286 | && crtl->args.info.nregs < 4) |
b279b20a | 5287 | return LAST_ARG_REGNUM; |
e0b92319 | 5288 | |
b279b20a NC |
5289 | /* Otherwise look for a call-saved register that is going to be pushed. */ |
5290 | for (reg = LAST_LO_REGNUM; reg > LAST_ARG_REGNUM; reg --) | |
5291 | if (pushed_regs_mask & (1 << reg)) | |
57934c39 PB |
5292 | return reg; |
5293 | ||
5b3e6663 PB |
5294 | if (TARGET_THUMB2) |
5295 | { | |
5296 | /* Thumb-2 can use high regs. */ | |
5297 | for (reg = FIRST_HI_REGNUM; reg < 15; reg ++) | |
5298 | if (pushed_regs_mask & (1 << reg)) | |
5299 | return reg; | |
5300 | } | |
b279b20a NC |
5301 | /* Something went wrong - thumb_compute_save_reg_mask() |
5302 | should have arranged for a suitable register to be pushed. */ | |
e6d29d15 | 5303 | gcc_unreachable (); |
57934c39 PB |
5304 | } |
5305 | ||
f16fe45f | 5306 | static GTY(()) int pic_labelno; |
876f13b0 | 5307 | |
fe013435 PB |
5308 | /* Generate code to load the PIC register. In thumb mode SCRATCH is a |
5309 | low register. */ | |
876f13b0 | 5310 | |
32de079a | 5311 | void |
e55ef7f4 | 5312 | arm_load_pic_register (unsigned long saved_regs ATTRIBUTE_UNUSED) |
32de079a | 5313 | { |
f9bd1a89 | 5314 | rtx l1, labelno, pic_tmp, pic_rtx, pic_reg; |
32de079a | 5315 | |
e3b5732b | 5316 | if (crtl->uses_pic_offset_table == 0 || TARGET_SINGLE_PIC_BASE) |
32de079a RE |
5317 | return; |
5318 | ||
e6d29d15 | 5319 | gcc_assert (flag_pic); |
32de079a | 5320 | |
9403b7f7 RS |
5321 | pic_reg = cfun->machine->pic_reg; |
5322 | if (TARGET_VXWORKS_RTP) | |
5323 | { | |
5324 | pic_rtx = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE); | |
5325 | pic_rtx = gen_rtx_CONST (Pmode, pic_rtx); | |
87d05b44 | 5326 | emit_insn (gen_pic_load_addr_32bit (pic_reg, pic_rtx)); |
43cffd11 | 5327 | |
9403b7f7 | 5328 | emit_insn (gen_rtx_SET (Pmode, pic_reg, gen_rtx_MEM (Pmode, pic_reg))); |
f676971a | 5329 | |
9403b7f7 RS |
5330 | pic_tmp = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX); |
5331 | emit_insn (gen_pic_offset_arm (pic_reg, pic_reg, pic_tmp)); | |
4bec9f7d | 5332 | } |
9403b7f7 | 5333 | else |
5b3e6663 | 5334 | { |
9403b7f7 RS |
5335 | /* We use an UNSPEC rather than a LABEL_REF because this label |
5336 | never appears in the code stream. */ | |
5337 | ||
5338 | labelno = GEN_INT (pic_labelno++); | |
5339 | l1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); | |
5340 | l1 = gen_rtx_CONST (VOIDmode, l1); | |
5341 | ||
9403b7f7 RS |
5342 | /* On the ARM the PC register contains 'dot + 8' at the time of the |
5343 | addition, on the Thumb it is 'dot + 4'. */ | |
f9bd1a89 RS |
5344 | pic_rtx = plus_constant (l1, TARGET_ARM ? 8 : 4); |
5345 | pic_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, pic_rtx), | |
5346 | UNSPEC_GOTSYM_OFF); | |
9403b7f7 RS |
5347 | pic_rtx = gen_rtx_CONST (Pmode, pic_rtx); |
5348 | ||
87d05b44 | 5349 | if (TARGET_32BIT) |
9403b7f7 | 5350 | { |
87d05b44 RE |
5351 | emit_insn (gen_pic_load_addr_32bit (pic_reg, pic_rtx)); |
5352 | if (TARGET_ARM) | |
5353 | emit_insn (gen_pic_add_dot_plus_eight (pic_reg, pic_reg, labelno)); | |
9403b7f7 | 5354 | else |
87d05b44 | 5355 | emit_insn (gen_pic_add_dot_plus_four (pic_reg, pic_reg, labelno)); |
9403b7f7 RS |
5356 | } |
5357 | else /* TARGET_THUMB1 */ | |
876f13b0 | 5358 | { |
9403b7f7 RS |
5359 | if (arm_pic_register != INVALID_REGNUM |
5360 | && REGNO (pic_reg) > LAST_LO_REGNUM) | |
5361 | { | |
5362 | /* We will have pushed the pic register, so we should always be | |
5363 | able to find a work register. */ | |
5364 | pic_tmp = gen_rtx_REG (SImode, | |
5365 | thumb_find_work_register (saved_regs)); | |
5366 | emit_insn (gen_pic_load_addr_thumb1 (pic_tmp, pic_rtx)); | |
5367 | emit_insn (gen_movsi (pic_offset_table_rtx, pic_tmp)); | |
5368 | } | |
5369 | else | |
5370 | emit_insn (gen_pic_load_addr_thumb1 (pic_reg, pic_rtx)); | |
5371 | emit_insn (gen_pic_add_dot_plus_four (pic_reg, pic_reg, labelno)); | |
876f13b0 | 5372 | } |
4bec9f7d | 5373 | } |
32de079a | 5374 | |
32de079a RE |
5375 | /* Need to emit this whether or not we obey regdecls, |
5376 | since setjmp/longjmp can cause life info to screw up. */ | |
c41c1387 | 5377 | emit_use (pic_reg); |
32de079a RE |
5378 | } |
5379 | ||
85c9bcd4 WG |
5380 | /* Generate code to load the address of a static var when flag_pic is set. */ |
5381 | static rtx | |
5382 | arm_pic_static_addr (rtx orig, rtx reg) | |
5383 | { | |
5384 | rtx l1, labelno, offset_rtx, insn; | |
5385 | ||
5386 | gcc_assert (flag_pic); | |
5387 | ||
5388 | /* We use an UNSPEC rather than a LABEL_REF because this label | |
5389 | never appears in the code stream. */ | |
5390 | labelno = GEN_INT (pic_labelno++); | |
5391 | l1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); | |
5392 | l1 = gen_rtx_CONST (VOIDmode, l1); | |
5393 | ||
5394 | /* On the ARM the PC register contains 'dot + 8' at the time of the | |
5395 | addition, on the Thumb it is 'dot + 4'. */ | |
5396 | offset_rtx = plus_constant (l1, TARGET_ARM ? 8 : 4); | |
5397 | offset_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, orig, offset_rtx), | |
5398 | UNSPEC_SYMBOL_OFFSET); | |
5399 | offset_rtx = gen_rtx_CONST (Pmode, offset_rtx); | |
5400 | ||
5401 | if (TARGET_32BIT) | |
5402 | { | |
5403 | emit_insn (gen_pic_load_addr_32bit (reg, offset_rtx)); | |
5404 | if (TARGET_ARM) | |
5405 | insn = emit_insn (gen_pic_add_dot_plus_eight (reg, reg, labelno)); | |
5406 | else | |
5407 | insn = emit_insn (gen_pic_add_dot_plus_four (reg, reg, labelno)); | |
5408 | } | |
5409 | else /* TARGET_THUMB1 */ | |
5410 | { | |
5411 | emit_insn (gen_pic_load_addr_thumb1 (reg, offset_rtx)); | |
5412 | insn = emit_insn (gen_pic_add_dot_plus_four (reg, reg, labelno)); | |
5413 | } | |
5414 | ||
5415 | return insn; | |
5416 | } | |
876f13b0 | 5417 | |
6b990f6b RE |
5418 | /* Return nonzero if X is valid as an ARM state addressing register. */ |
5419 | static int | |
e32bac5b | 5420 | arm_address_register_rtx_p (rtx x, int strict_p) |
6b990f6b RE |
5421 | { |
5422 | int regno; | |
5423 | ||
5424 | if (GET_CODE (x) != REG) | |
5425 | return 0; | |
5426 | ||
5427 | regno = REGNO (x); | |
5428 | ||
5429 | if (strict_p) | |
5430 | return ARM_REGNO_OK_FOR_BASE_P (regno); | |
5431 | ||
5432 | return (regno <= LAST_ARM_REGNUM | |
5433 | || regno >= FIRST_PSEUDO_REGISTER | |
5434 | || regno == FRAME_POINTER_REGNUM | |
5435 | || regno == ARG_POINTER_REGNUM); | |
5436 | } | |
5437 | ||
d3585b76 DJ |
5438 | /* Return TRUE if this rtx is the difference of a symbol and a label, |
5439 | and will reduce to a PC-relative relocation in the object file. | |
5440 | Expressions like this can be left alone when generating PIC, rather | |
5441 | than forced through the GOT. */ | |
5442 | static int | |
5443 | pcrel_constant_p (rtx x) | |
5444 | { | |
5445 | if (GET_CODE (x) == MINUS) | |
5446 | return symbol_mentioned_p (XEXP (x, 0)) && label_mentioned_p (XEXP (x, 1)); | |
5447 | ||
5448 | return FALSE; | |
5449 | } | |
5450 | ||
d37c3c62 MK |
5451 | /* Return true if X will surely end up in an index register after next |
5452 | splitting pass. */ | |
5453 | static bool | |
5454 | will_be_in_index_register (const_rtx x) | |
5455 | { | |
5456 | /* arm.md: calculate_pic_address will split this into a register. */ | |
5457 | return GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_PIC_SYM; | |
5458 | } | |
5459 | ||
6b990f6b RE |
5460 | /* Return nonzero if X is a valid ARM state address operand. */ |
5461 | int | |
c6c3dba9 PB |
5462 | arm_legitimate_address_outer_p (enum machine_mode mode, rtx x, RTX_CODE outer, |
5463 | int strict_p) | |
6b990f6b | 5464 | { |
fdd695fd PB |
5465 | bool use_ldrd; |
5466 | enum rtx_code code = GET_CODE (x); | |
f676971a | 5467 | |
6b990f6b RE |
5468 | if (arm_address_register_rtx_p (x, strict_p)) |
5469 | return 1; | |
5470 | ||
fdd695fd PB |
5471 | use_ldrd = (TARGET_LDRD |
5472 | && (mode == DImode | |
5473 | || (mode == DFmode && (TARGET_SOFT_FLOAT || TARGET_VFP)))); | |
5474 | ||
5475 | if (code == POST_INC || code == PRE_DEC | |
5476 | || ((code == PRE_INC || code == POST_DEC) | |
5477 | && (use_ldrd || GET_MODE_SIZE (mode) <= 4))) | |
6b990f6b RE |
5478 | return arm_address_register_rtx_p (XEXP (x, 0), strict_p); |
5479 | ||
fdd695fd | 5480 | else if ((code == POST_MODIFY || code == PRE_MODIFY) |
6b990f6b RE |
5481 | && arm_address_register_rtx_p (XEXP (x, 0), strict_p) |
5482 | && GET_CODE (XEXP (x, 1)) == PLUS | |
386d3a16 | 5483 | && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0))) |
fdd695fd PB |
5484 | { |
5485 | rtx addend = XEXP (XEXP (x, 1), 1); | |
5486 | ||
112cdef5 | 5487 | /* Don't allow ldrd post increment by register because it's hard |
fdd695fd PB |
5488 | to fixup invalid register choices. */ |
5489 | if (use_ldrd | |
5490 | && GET_CODE (x) == POST_MODIFY | |
5491 | && GET_CODE (addend) == REG) | |
5492 | return 0; | |
5493 | ||
5494 | return ((use_ldrd || GET_MODE_SIZE (mode) <= 4) | |
5495 | && arm_legitimate_index_p (mode, addend, outer, strict_p)); | |
5496 | } | |
6b990f6b RE |
5497 | |
5498 | /* After reload constants split into minipools will have addresses | |
5499 | from a LABEL_REF. */ | |
0bfb39ef | 5500 | else if (reload_completed |
fdd695fd PB |
5501 | && (code == LABEL_REF |
5502 | || (code == CONST | |
6b990f6b RE |
5503 | && GET_CODE (XEXP (x, 0)) == PLUS |
5504 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF | |
5505 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))) | |
5506 | return 1; | |
5507 | ||
88f77cba | 5508 | else if (mode == TImode || (TARGET_NEON && VALID_NEON_STRUCT_MODE (mode))) |
6b990f6b RE |
5509 | return 0; |
5510 | ||
fdd695fd | 5511 | else if (code == PLUS) |
6b990f6b RE |
5512 | { |
5513 | rtx xop0 = XEXP (x, 0); | |
5514 | rtx xop1 = XEXP (x, 1); | |
5515 | ||
5516 | return ((arm_address_register_rtx_p (xop0, strict_p) | |
d37c3c62 MK |
5517 | && ((GET_CODE(xop1) == CONST_INT |
5518 | && arm_legitimate_index_p (mode, xop1, outer, strict_p)) | |
5519 | || (!strict_p && will_be_in_index_register (xop1)))) | |
6b990f6b | 5520 | || (arm_address_register_rtx_p (xop1, strict_p) |
1e1ab407 | 5521 | && arm_legitimate_index_p (mode, xop0, outer, strict_p))); |
6b990f6b RE |
5522 | } |
5523 | ||
5524 | #if 0 | |
5525 | /* Reload currently can't handle MINUS, so disable this for now */ | |
5526 | else if (GET_CODE (x) == MINUS) | |
5527 | { | |
5528 | rtx xop0 = XEXP (x, 0); | |
5529 | rtx xop1 = XEXP (x, 1); | |
5530 | ||
5531 | return (arm_address_register_rtx_p (xop0, strict_p) | |
1e1ab407 | 5532 | && arm_legitimate_index_p (mode, xop1, outer, strict_p)); |
6b990f6b RE |
5533 | } |
5534 | #endif | |
5535 | ||
5536 | else if (GET_MODE_CLASS (mode) != MODE_FLOAT | |
fdd695fd | 5537 | && code == SYMBOL_REF |
6b990f6b RE |
5538 | && CONSTANT_POOL_ADDRESS_P (x) |
5539 | && ! (flag_pic | |
d3585b76 DJ |
5540 | && symbol_mentioned_p (get_pool_constant (x)) |
5541 | && ! pcrel_constant_p (get_pool_constant (x)))) | |
6b990f6b RE |
5542 | return 1; |
5543 | ||
6b990f6b RE |
5544 | return 0; |
5545 | } | |
5546 | ||
5b3e6663 | 5547 | /* Return nonzero if X is a valid Thumb-2 address operand. */ |
c6c3dba9 | 5548 | static int |
5b3e6663 PB |
5549 | thumb2_legitimate_address_p (enum machine_mode mode, rtx x, int strict_p) |
5550 | { | |
5551 | bool use_ldrd; | |
5552 | enum rtx_code code = GET_CODE (x); | |
5553 | ||
5554 | if (arm_address_register_rtx_p (x, strict_p)) | |
5555 | return 1; | |
5556 | ||
5557 | use_ldrd = (TARGET_LDRD | |
5558 | && (mode == DImode | |
5559 | || (mode == DFmode && (TARGET_SOFT_FLOAT || TARGET_VFP)))); | |
5560 | ||
5561 | if (code == POST_INC || code == PRE_DEC | |
5562 | || ((code == PRE_INC || code == POST_DEC) | |
5563 | && (use_ldrd || GET_MODE_SIZE (mode) <= 4))) | |
5564 | return arm_address_register_rtx_p (XEXP (x, 0), strict_p); | |
5565 | ||
5566 | else if ((code == POST_MODIFY || code == PRE_MODIFY) | |
5567 | && arm_address_register_rtx_p (XEXP (x, 0), strict_p) | |
5568 | && GET_CODE (XEXP (x, 1)) == PLUS | |
5569 | && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0))) | |
5570 | { | |
5571 | /* Thumb-2 only has autoincrement by constant. */ | |
5572 | rtx addend = XEXP (XEXP (x, 1), 1); | |
5573 | HOST_WIDE_INT offset; | |
5574 | ||
5575 | if (GET_CODE (addend) != CONST_INT) | |
5576 | return 0; | |
5577 | ||
5578 | offset = INTVAL(addend); | |
5579 | if (GET_MODE_SIZE (mode) <= 4) | |
5580 | return (offset > -256 && offset < 256); | |
5581 | ||
5582 | return (use_ldrd && offset > -1024 && offset < 1024 | |
5583 | && (offset & 3) == 0); | |
5584 | } | |
5585 | ||
5586 | /* After reload constants split into minipools will have addresses | |
5587 | from a LABEL_REF. */ | |
5588 | else if (reload_completed | |
5589 | && (code == LABEL_REF | |
5590 | || (code == CONST | |
5591 | && GET_CODE (XEXP (x, 0)) == PLUS | |
5592 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF | |
5593 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))) | |
5594 | return 1; | |
5595 | ||
88f77cba | 5596 | else if (mode == TImode || (TARGET_NEON && VALID_NEON_STRUCT_MODE (mode))) |
5b3e6663 PB |
5597 | return 0; |
5598 | ||
5599 | else if (code == PLUS) | |
5600 | { | |
5601 | rtx xop0 = XEXP (x, 0); | |
5602 | rtx xop1 = XEXP (x, 1); | |
5603 | ||
5604 | return ((arm_address_register_rtx_p (xop0, strict_p) | |
d37c3c62 MK |
5605 | && (thumb2_legitimate_index_p (mode, xop1, strict_p) |
5606 | || (!strict_p && will_be_in_index_register (xop1)))) | |
5b3e6663 PB |
5607 | || (arm_address_register_rtx_p (xop1, strict_p) |
5608 | && thumb2_legitimate_index_p (mode, xop0, strict_p))); | |
5609 | } | |
5610 | ||
5611 | else if (GET_MODE_CLASS (mode) != MODE_FLOAT | |
5612 | && code == SYMBOL_REF | |
5613 | && CONSTANT_POOL_ADDRESS_P (x) | |
5614 | && ! (flag_pic | |
5615 | && symbol_mentioned_p (get_pool_constant (x)) | |
5616 | && ! pcrel_constant_p (get_pool_constant (x)))) | |
5617 | return 1; | |
5618 | ||
5619 | return 0; | |
5620 | } | |
5621 | ||
6b990f6b RE |
5622 | /* Return nonzero if INDEX is valid for an address index operand in |
5623 | ARM state. */ | |
5624 | static int | |
1e1ab407 RE |
5625 | arm_legitimate_index_p (enum machine_mode mode, rtx index, RTX_CODE outer, |
5626 | int strict_p) | |
6b990f6b RE |
5627 | { |
5628 | HOST_WIDE_INT range; | |
5629 | enum rtx_code code = GET_CODE (index); | |
5630 | ||
778ebdd9 PB |
5631 | /* Standard coprocessor addressing modes. */ |
5632 | if (TARGET_HARD_FLOAT | |
f3fb6590 CLT |
5633 | && (TARGET_VFP || TARGET_FPA || TARGET_MAVERICK) |
5634 | && (mode == SFmode || mode == DFmode | |
778ebdd9 | 5635 | || (TARGET_MAVERICK && mode == DImode))) |
6b990f6b RE |
5636 | return (code == CONST_INT && INTVAL (index) < 1024 |
5637 | && INTVAL (index) > -1024 | |
5638 | && (INTVAL (index) & 3) == 0); | |
5639 | ||
49460951 NF |
5640 | /* For quad modes, we restrict the constant offset to be slightly less |
5641 | than what the instruction format permits. We do this because for | |
5642 | quad mode moves, we will actually decompose them into two separate | |
5643 | double-mode reads or writes. INDEX must therefore be a valid | |
5644 | (double-mode) offset and so should INDEX+8. */ | |
5645 | if (TARGET_NEON && VALID_NEON_QREG_MODE (mode)) | |
88f77cba JB |
5646 | return (code == CONST_INT |
5647 | && INTVAL (index) < 1016 | |
5648 | && INTVAL (index) > -1024 | |
5649 | && (INTVAL (index) & 3) == 0); | |
5650 | ||
49460951 NF |
5651 | /* We have no such constraint on double mode offsets, so we permit the |
5652 | full range of the instruction format. */ | |
5653 | if (TARGET_NEON && VALID_NEON_DREG_MODE (mode)) | |
5654 | return (code == CONST_INT | |
5655 | && INTVAL (index) < 1024 | |
5656 | && INTVAL (index) > -1024 | |
5657 | && (INTVAL (index) & 3) == 0); | |
5658 | ||
5a9335ef NC |
5659 | if (TARGET_REALLY_IWMMXT && VALID_IWMMXT_REG_MODE (mode)) |
5660 | return (code == CONST_INT | |
3657dc3e PB |
5661 | && INTVAL (index) < 1024 |
5662 | && INTVAL (index) > -1024 | |
5663 | && (INTVAL (index) & 3) == 0); | |
5a9335ef | 5664 | |
fdd695fd PB |
5665 | if (arm_address_register_rtx_p (index, strict_p) |
5666 | && (GET_MODE_SIZE (mode) <= 4)) | |
5667 | return 1; | |
5668 | ||
5669 | if (mode == DImode || mode == DFmode) | |
5670 | { | |
5671 | if (code == CONST_INT) | |
5672 | { | |
5673 | HOST_WIDE_INT val = INTVAL (index); | |
5674 | ||
5675 | if (TARGET_LDRD) | |
5676 | return val > -256 && val < 256; | |
5677 | else | |
f372c932 | 5678 | return val > -4096 && val < 4092; |
fdd695fd PB |
5679 | } |
5680 | ||
5681 | return TARGET_LDRD && arm_address_register_rtx_p (index, strict_p); | |
5682 | } | |
5683 | ||
6b990f6b | 5684 | if (GET_MODE_SIZE (mode) <= 4 |
1e1ab407 RE |
5685 | && ! (arm_arch4 |
5686 | && (mode == HImode | |
0fd8c3ad | 5687 | || mode == HFmode |
1e1ab407 | 5688 | || (mode == QImode && outer == SIGN_EXTEND)))) |
6b990f6b | 5689 | { |
1e1ab407 RE |
5690 | if (code == MULT) |
5691 | { | |
5692 | rtx xiop0 = XEXP (index, 0); | |
5693 | rtx xiop1 = XEXP (index, 1); | |
5694 | ||
5695 | return ((arm_address_register_rtx_p (xiop0, strict_p) | |
5696 | && power_of_two_operand (xiop1, SImode)) | |
5697 | || (arm_address_register_rtx_p (xiop1, strict_p) | |
5698 | && power_of_two_operand (xiop0, SImode))); | |
5699 | } | |
5700 | else if (code == LSHIFTRT || code == ASHIFTRT | |
5701 | || code == ASHIFT || code == ROTATERT) | |
5702 | { | |
5703 | rtx op = XEXP (index, 1); | |
6b990f6b | 5704 | |
1e1ab407 RE |
5705 | return (arm_address_register_rtx_p (XEXP (index, 0), strict_p) |
5706 | && GET_CODE (op) == CONST_INT | |
5707 | && INTVAL (op) > 0 | |
5708 | && INTVAL (op) <= 31); | |
5709 | } | |
6b990f6b RE |
5710 | } |
5711 | ||
1e1ab407 RE |
5712 | /* For ARM v4 we may be doing a sign-extend operation during the |
5713 | load. */ | |
e1471c91 | 5714 | if (arm_arch4) |
1e1ab407 | 5715 | { |
0fd8c3ad SL |
5716 | if (mode == HImode |
5717 | || mode == HFmode | |
5718 | || (outer == SIGN_EXTEND && mode == QImode)) | |
1e1ab407 RE |
5719 | range = 256; |
5720 | else | |
5721 | range = 4096; | |
5722 | } | |
e1471c91 | 5723 | else |
0fd8c3ad | 5724 | range = (mode == HImode || mode == HFmode) ? 4095 : 4096; |
6b990f6b RE |
5725 | |
5726 | return (code == CONST_INT | |
5727 | && INTVAL (index) < range | |
5728 | && INTVAL (index) > -range); | |
76a318e9 RE |
5729 | } |
5730 | ||
5b3e6663 PB |
5731 | /* Return true if OP is a valid index scaling factor for Thumb-2 address |
5732 | index operand. i.e. 1, 2, 4 or 8. */ | |
5733 | static bool | |
5734 | thumb2_index_mul_operand (rtx op) | |
5735 | { | |
5736 | HOST_WIDE_INT val; | |
5737 | ||
5738 | if (GET_CODE(op) != CONST_INT) | |
5739 | return false; | |
5740 | ||
5741 | val = INTVAL(op); | |
5742 | return (val == 1 || val == 2 || val == 4 || val == 8); | |
5743 | } | |
5744 | ||
5745 | /* Return nonzero if INDEX is a valid Thumb-2 address index operand. */ | |
5746 | static int | |
5747 | thumb2_legitimate_index_p (enum machine_mode mode, rtx index, int strict_p) | |
5748 | { | |
5749 | enum rtx_code code = GET_CODE (index); | |
5750 | ||
5751 | /* ??? Combine arm and thumb2 coprocessor addressing modes. */ | |
5752 | /* Standard coprocessor addressing modes. */ | |
5753 | if (TARGET_HARD_FLOAT | |
f3fb6590 CLT |
5754 | && (TARGET_VFP || TARGET_FPA || TARGET_MAVERICK) |
5755 | && (mode == SFmode || mode == DFmode | |
5b3e6663 PB |
5756 | || (TARGET_MAVERICK && mode == DImode))) |
5757 | return (code == CONST_INT && INTVAL (index) < 1024 | |
bff99262 CLT |
5758 | /* Thumb-2 allows only > -256 index range for it's core register |
5759 | load/stores. Since we allow SF/DF in core registers, we have | |
5760 | to use the intersection between -256~4096 (core) and -1024~1024 | |
5761 | (coprocessor). */ | |
5762 | && INTVAL (index) > -256 | |
5b3e6663 PB |
5763 | && (INTVAL (index) & 3) == 0); |
5764 | ||
5765 | if (TARGET_REALLY_IWMMXT && VALID_IWMMXT_REG_MODE (mode)) | |
fe2d934b PB |
5766 | { |
5767 | /* For DImode assume values will usually live in core regs | |
5768 | and only allow LDRD addressing modes. */ | |
5769 | if (!TARGET_LDRD || mode != DImode) | |
5770 | return (code == CONST_INT | |
5771 | && INTVAL (index) < 1024 | |
5772 | && INTVAL (index) > -1024 | |
5773 | && (INTVAL (index) & 3) == 0); | |
5774 | } | |
5b3e6663 | 5775 | |
49460951 NF |
5776 | /* For quad modes, we restrict the constant offset to be slightly less |
5777 | than what the instruction format permits. We do this because for | |
5778 | quad mode moves, we will actually decompose them into two separate | |
5779 | double-mode reads or writes. INDEX must therefore be a valid | |
5780 | (double-mode) offset and so should INDEX+8. */ | |
5781 | if (TARGET_NEON && VALID_NEON_QREG_MODE (mode)) | |
88f77cba JB |
5782 | return (code == CONST_INT |
5783 | && INTVAL (index) < 1016 | |
5784 | && INTVAL (index) > -1024 | |
5785 | && (INTVAL (index) & 3) == 0); | |
5786 | ||
49460951 NF |
5787 | /* We have no such constraint on double mode offsets, so we permit the |
5788 | full range of the instruction format. */ | |
5789 | if (TARGET_NEON && VALID_NEON_DREG_MODE (mode)) | |
5790 | return (code == CONST_INT | |
5791 | && INTVAL (index) < 1024 | |
5792 | && INTVAL (index) > -1024 | |
5793 | && (INTVAL (index) & 3) == 0); | |
5794 | ||
5b3e6663 PB |
5795 | if (arm_address_register_rtx_p (index, strict_p) |
5796 | && (GET_MODE_SIZE (mode) <= 4)) | |
5797 | return 1; | |
5798 | ||
5799 | if (mode == DImode || mode == DFmode) | |
5800 | { | |
e07e020b RR |
5801 | if (code == CONST_INT) |
5802 | { | |
5803 | HOST_WIDE_INT val = INTVAL (index); | |
5804 | /* ??? Can we assume ldrd for thumb2? */ | |
5805 | /* Thumb-2 ldrd only has reg+const addressing modes. */ | |
5806 | /* ldrd supports offsets of +-1020. | |
5807 | However the ldr fallback does not. */ | |
5808 | return val > -256 && val < 256 && (val & 3) == 0; | |
5809 | } | |
5810 | else | |
5b3e6663 | 5811 | return 0; |
5b3e6663 PB |
5812 | } |
5813 | ||
5814 | if (code == MULT) | |
5815 | { | |
5816 | rtx xiop0 = XEXP (index, 0); | |
5817 | rtx xiop1 = XEXP (index, 1); | |
5818 | ||
5819 | return ((arm_address_register_rtx_p (xiop0, strict_p) | |
5820 | && thumb2_index_mul_operand (xiop1)) | |
5821 | || (arm_address_register_rtx_p (xiop1, strict_p) | |
5822 | && thumb2_index_mul_operand (xiop0))); | |
5823 | } | |
5824 | else if (code == ASHIFT) | |
5825 | { | |
5826 | rtx op = XEXP (index, 1); | |
5827 | ||
5828 | return (arm_address_register_rtx_p (XEXP (index, 0), strict_p) | |
5829 | && GET_CODE (op) == CONST_INT | |
5830 | && INTVAL (op) > 0 | |
5831 | && INTVAL (op) <= 3); | |
5832 | } | |
5833 | ||
5834 | return (code == CONST_INT | |
5835 | && INTVAL (index) < 4096 | |
5836 | && INTVAL (index) > -256); | |
5837 | } | |
5838 | ||
5839 | /* Return nonzero if X is valid as a 16-bit Thumb state base register. */ | |
76a318e9 | 5840 | static int |
5b3e6663 | 5841 | thumb1_base_register_rtx_p (rtx x, enum machine_mode mode, int strict_p) |
76a318e9 RE |
5842 | { |
5843 | int regno; | |
5844 | ||
5845 | if (GET_CODE (x) != REG) | |
5846 | return 0; | |
5847 | ||
5848 | regno = REGNO (x); | |
5849 | ||
5850 | if (strict_p) | |
5b3e6663 | 5851 | return THUMB1_REGNO_MODE_OK_FOR_BASE_P (regno, mode); |
76a318e9 RE |
5852 | |
5853 | return (regno <= LAST_LO_REGNUM | |
07e58265 | 5854 | || regno > LAST_VIRTUAL_REGISTER |
76a318e9 RE |
5855 | || regno == FRAME_POINTER_REGNUM |
5856 | || (GET_MODE_SIZE (mode) >= 4 | |
5857 | && (regno == STACK_POINTER_REGNUM | |
edf7cee8 | 5858 | || regno >= FIRST_PSEUDO_REGISTER |
76a318e9 RE |
5859 | || x == hard_frame_pointer_rtx |
5860 | || x == arg_pointer_rtx))); | |
5861 | } | |
5862 | ||
5863 | /* Return nonzero if x is a legitimate index register. This is the case | |
5864 | for any base register that can access a QImode object. */ | |
5865 | inline static int | |
5b3e6663 | 5866 | thumb1_index_register_rtx_p (rtx x, int strict_p) |
76a318e9 | 5867 | { |
5b3e6663 | 5868 | return thumb1_base_register_rtx_p (x, QImode, strict_p); |
76a318e9 RE |
5869 | } |
5870 | ||
5b3e6663 | 5871 | /* Return nonzero if x is a legitimate 16-bit Thumb-state address. |
f676971a | 5872 | |
76a318e9 RE |
5873 | The AP may be eliminated to either the SP or the FP, so we use the |
5874 | least common denominator, e.g. SImode, and offsets from 0 to 64. | |
5875 | ||
5876 | ??? Verify whether the above is the right approach. | |
5877 | ||
5878 | ??? Also, the FP may be eliminated to the SP, so perhaps that | |
5879 | needs special handling also. | |
5880 | ||
5881 | ??? Look at how the mips16 port solves this problem. It probably uses | |
5882 | better ways to solve some of these problems. | |
5883 | ||
5884 | Although it is not incorrect, we don't accept QImode and HImode | |
5885 | addresses based on the frame pointer or arg pointer until the | |
5886 | reload pass starts. This is so that eliminating such addresses | |
5887 | into stack based ones won't produce impossible code. */ | |
363ee90e | 5888 | int |
5b3e6663 | 5889 | thumb1_legitimate_address_p (enum machine_mode mode, rtx x, int strict_p) |
76a318e9 RE |
5890 | { |
5891 | /* ??? Not clear if this is right. Experiment. */ | |
5892 | if (GET_MODE_SIZE (mode) < 4 | |
5893 | && !(reload_in_progress || reload_completed) | |
5894 | && (reg_mentioned_p (frame_pointer_rtx, x) | |
5895 | || reg_mentioned_p (arg_pointer_rtx, x) | |
5896 | || reg_mentioned_p (virtual_incoming_args_rtx, x) | |
5897 | || reg_mentioned_p (virtual_outgoing_args_rtx, x) | |
5898 | || reg_mentioned_p (virtual_stack_dynamic_rtx, x) | |
5899 | || reg_mentioned_p (virtual_stack_vars_rtx, x))) | |
5900 | return 0; | |
5901 | ||
5902 | /* Accept any base register. SP only in SImode or larger. */ | |
5b3e6663 | 5903 | else if (thumb1_base_register_rtx_p (x, mode, strict_p)) |
76a318e9 RE |
5904 | return 1; |
5905 | ||
18dbd950 | 5906 | /* This is PC relative data before arm_reorg runs. */ |
76a318e9 RE |
5907 | else if (GET_MODE_SIZE (mode) >= 4 && CONSTANT_P (x) |
5908 | && GET_CODE (x) == SYMBOL_REF | |
020a4035 | 5909 | && CONSTANT_POOL_ADDRESS_P (x) && !flag_pic) |
76a318e9 RE |
5910 | return 1; |
5911 | ||
18dbd950 | 5912 | /* This is PC relative data after arm_reorg runs. */ |
0fd8c3ad SL |
5913 | else if ((GET_MODE_SIZE (mode) >= 4 || mode == HFmode) |
5914 | && reload_completed | |
76a318e9 RE |
5915 | && (GET_CODE (x) == LABEL_REF |
5916 | || (GET_CODE (x) == CONST | |
5917 | && GET_CODE (XEXP (x, 0)) == PLUS | |
5918 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF | |
5919 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))) | |
5920 | return 1; | |
5921 | ||
5922 | /* Post-inc indexing only supported for SImode and larger. */ | |
5923 | else if (GET_CODE (x) == POST_INC && GET_MODE_SIZE (mode) >= 4 | |
5b3e6663 | 5924 | && thumb1_index_register_rtx_p (XEXP (x, 0), strict_p)) |
76a318e9 RE |
5925 | return 1; |
5926 | ||
5927 | else if (GET_CODE (x) == PLUS) | |
5928 | { | |
5929 | /* REG+REG address can be any two index registers. */ | |
5930 | /* We disallow FRAME+REG addressing since we know that FRAME | |
5931 | will be replaced with STACK, and SP relative addressing only | |
5932 | permits SP+OFFSET. */ | |
5933 | if (GET_MODE_SIZE (mode) <= 4 | |
5934 | && XEXP (x, 0) != frame_pointer_rtx | |
5935 | && XEXP (x, 1) != frame_pointer_rtx | |
5b3e6663 | 5936 | && thumb1_index_register_rtx_p (XEXP (x, 0), strict_p) |
d37c3c62 MK |
5937 | && (thumb1_index_register_rtx_p (XEXP (x, 1), strict_p) |
5938 | || (!strict_p && will_be_in_index_register (XEXP (x, 1))))) | |
76a318e9 RE |
5939 | return 1; |
5940 | ||
5941 | /* REG+const has 5-7 bit offset for non-SP registers. */ | |
5b3e6663 | 5942 | else if ((thumb1_index_register_rtx_p (XEXP (x, 0), strict_p) |
76a318e9 RE |
5943 | || XEXP (x, 0) == arg_pointer_rtx) |
5944 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
5945 | && thumb_legitimate_offset_p (mode, INTVAL (XEXP (x, 1)))) | |
5946 | return 1; | |
5947 | ||
a50aa827 | 5948 | /* REG+const has 10-bit offset for SP, but only SImode and |
76a318e9 RE |
5949 | larger is supported. */ |
5950 | /* ??? Should probably check for DI/DFmode overflow here | |
5951 | just like GO_IF_LEGITIMATE_OFFSET does. */ | |
5952 | else if (GET_CODE (XEXP (x, 0)) == REG | |
5953 | && REGNO (XEXP (x, 0)) == STACK_POINTER_REGNUM | |
5954 | && GET_MODE_SIZE (mode) >= 4 | |
5955 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
5956 | && INTVAL (XEXP (x, 1)) >= 0 | |
5957 | && INTVAL (XEXP (x, 1)) + GET_MODE_SIZE (mode) <= 1024 | |
5958 | && (INTVAL (XEXP (x, 1)) & 3) == 0) | |
5959 | return 1; | |
5960 | ||
5961 | else if (GET_CODE (XEXP (x, 0)) == REG | |
c5289e45 RE |
5962 | && (REGNO (XEXP (x, 0)) == FRAME_POINTER_REGNUM |
5963 | || REGNO (XEXP (x, 0)) == ARG_POINTER_REGNUM | |
5964 | || (REGNO (XEXP (x, 0)) >= FIRST_VIRTUAL_REGISTER | |
32990d5b JJ |
5965 | && REGNO (XEXP (x, 0)) |
5966 | <= LAST_VIRTUAL_POINTER_REGISTER)) | |
76a318e9 RE |
5967 | && GET_MODE_SIZE (mode) >= 4 |
5968 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
5969 | && (INTVAL (XEXP (x, 1)) & 3) == 0) | |
5970 | return 1; | |
5971 | } | |
5972 | ||
5973 | else if (GET_MODE_CLASS (mode) != MODE_FLOAT | |
f954388e | 5974 | && GET_MODE_SIZE (mode) == 4 |
76a318e9 RE |
5975 | && GET_CODE (x) == SYMBOL_REF |
5976 | && CONSTANT_POOL_ADDRESS_P (x) | |
d3585b76 DJ |
5977 | && ! (flag_pic |
5978 | && symbol_mentioned_p (get_pool_constant (x)) | |
5979 | && ! pcrel_constant_p (get_pool_constant (x)))) | |
76a318e9 RE |
5980 | return 1; |
5981 | ||
5982 | return 0; | |
5983 | } | |
5984 | ||
5985 | /* Return nonzero if VAL can be used as an offset in a Thumb-state address | |
5986 | instruction of mode MODE. */ | |
5987 | int | |
e32bac5b | 5988 | thumb_legitimate_offset_p (enum machine_mode mode, HOST_WIDE_INT val) |
76a318e9 RE |
5989 | { |
5990 | switch (GET_MODE_SIZE (mode)) | |
5991 | { | |
5992 | case 1: | |
5993 | return val >= 0 && val < 32; | |
5994 | ||
5995 | case 2: | |
5996 | return val >= 0 && val < 64 && (val & 1) == 0; | |
5997 | ||
5998 | default: | |
5999 | return (val >= 0 | |
6000 | && (val + GET_MODE_SIZE (mode)) <= 128 | |
6001 | && (val & 3) == 0); | |
6002 | } | |
6003 | } | |
6004 | ||
c6c3dba9 PB |
6005 | bool |
6006 | arm_legitimate_address_p (enum machine_mode mode, rtx x, bool strict_p) | |
6007 | { | |
6008 | if (TARGET_ARM) | |
6009 | return arm_legitimate_address_outer_p (mode, x, SET, strict_p); | |
6010 | else if (TARGET_THUMB2) | |
6011 | return thumb2_legitimate_address_p (mode, x, strict_p); | |
6012 | else /* if (TARGET_THUMB1) */ | |
6013 | return thumb1_legitimate_address_p (mode, x, strict_p); | |
6014 | } | |
6015 | ||
d3585b76 DJ |
6016 | /* Build the SYMBOL_REF for __tls_get_addr. */ |
6017 | ||
6018 | static GTY(()) rtx tls_get_addr_libfunc; | |
6019 | ||
6020 | static rtx | |
6021 | get_tls_get_addr (void) | |
6022 | { | |
6023 | if (!tls_get_addr_libfunc) | |
6024 | tls_get_addr_libfunc = init_one_libfunc ("__tls_get_addr"); | |
6025 | return tls_get_addr_libfunc; | |
6026 | } | |
6027 | ||
6028 | static rtx | |
6029 | arm_load_tp (rtx target) | |
6030 | { | |
6031 | if (!target) | |
6032 | target = gen_reg_rtx (SImode); | |
6033 | ||
6034 | if (TARGET_HARD_TP) | |
6035 | { | |
6036 | /* Can return in any reg. */ | |
6037 | emit_insn (gen_load_tp_hard (target)); | |
6038 | } | |
6039 | else | |
6040 | { | |
6041 | /* Always returned in r0. Immediately copy the result into a pseudo, | |
6042 | otherwise other uses of r0 (e.g. setting up function arguments) may | |
6043 | clobber the value. */ | |
6044 | ||
6045 | rtx tmp; | |
6046 | ||
6047 | emit_insn (gen_load_tp_soft ()); | |
6048 | ||
6049 | tmp = gen_rtx_REG (SImode, 0); | |
6050 | emit_move_insn (target, tmp); | |
6051 | } | |
6052 | return target; | |
6053 | } | |
6054 | ||
6055 | static rtx | |
6056 | load_tls_operand (rtx x, rtx reg) | |
6057 | { | |
6058 | rtx tmp; | |
6059 | ||
6060 | if (reg == NULL_RTX) | |
6061 | reg = gen_reg_rtx (SImode); | |
6062 | ||
6063 | tmp = gen_rtx_CONST (SImode, x); | |
6064 | ||
6065 | emit_move_insn (reg, tmp); | |
6066 | ||
6067 | return reg; | |
6068 | } | |
6069 | ||
6070 | static rtx | |
6071 | arm_call_tls_get_addr (rtx x, rtx reg, rtx *valuep, int reloc) | |
6072 | { | |
f16fe45f | 6073 | rtx insns, label, labelno, sum; |
d3585b76 | 6074 | |
ccdc2164 | 6075 | gcc_assert (reloc != TLS_DESCSEQ); |
d3585b76 DJ |
6076 | start_sequence (); |
6077 | ||
f16fe45f DJ |
6078 | labelno = GEN_INT (pic_labelno++); |
6079 | label = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); | |
6080 | label = gen_rtx_CONST (VOIDmode, label); | |
6081 | ||
d3585b76 | 6082 | sum = gen_rtx_UNSPEC (Pmode, |
f16fe45f | 6083 | gen_rtvec (4, x, GEN_INT (reloc), label, |
d3585b76 DJ |
6084 | GEN_INT (TARGET_ARM ? 8 : 4)), |
6085 | UNSPEC_TLS); | |
6086 | reg = load_tls_operand (sum, reg); | |
6087 | ||
6088 | if (TARGET_ARM) | |
f16fe45f | 6089 | emit_insn (gen_pic_add_dot_plus_eight (reg, reg, labelno)); |
ccdc2164 | 6090 | else |
f16fe45f | 6091 | emit_insn (gen_pic_add_dot_plus_four (reg, reg, labelno)); |
ccdc2164 NS |
6092 | |
6093 | *valuep = emit_library_call_value (get_tls_get_addr (), NULL_RTX, | |
6094 | LCT_PURE, /* LCT_CONST? */ | |
d3585b76 | 6095 | Pmode, 1, reg, Pmode); |
ccdc2164 | 6096 | |
d3585b76 DJ |
6097 | insns = get_insns (); |
6098 | end_sequence (); | |
6099 | ||
6100 | return insns; | |
6101 | } | |
6102 | ||
ccdc2164 NS |
6103 | static rtx |
6104 | arm_tls_descseq_addr (rtx x, rtx reg) | |
6105 | { | |
6106 | rtx labelno = GEN_INT (pic_labelno++); | |
6107 | rtx label = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); | |
6108 | rtx sum = gen_rtx_UNSPEC (Pmode, | |
6109 | gen_rtvec (4, x, GEN_INT (TLS_DESCSEQ), | |
6110 | gen_rtx_CONST (VOIDmode, label), | |
6111 | GEN_INT (!TARGET_ARM)), | |
6112 | UNSPEC_TLS); | |
6113 | rtx reg0 = load_tls_operand (sum, gen_rtx_REG (SImode, 0)); | |
6114 | ||
6115 | emit_insn (gen_tlscall (x, labelno)); | |
6116 | if (!reg) | |
6117 | reg = gen_reg_rtx (SImode); | |
6118 | else | |
6119 | gcc_assert (REGNO (reg) != 0); | |
6120 | ||
6121 | emit_move_insn (reg, reg0); | |
6122 | ||
6123 | return reg; | |
6124 | } | |
6125 | ||
d3585b76 DJ |
6126 | rtx |
6127 | legitimize_tls_address (rtx x, rtx reg) | |
6128 | { | |
f16fe45f | 6129 | rtx dest, tp, label, labelno, sum, insns, ret, eqv, addend; |
d3585b76 DJ |
6130 | unsigned int model = SYMBOL_REF_TLS_MODEL (x); |
6131 | ||
6132 | switch (model) | |
6133 | { | |
6134 | case TLS_MODEL_GLOBAL_DYNAMIC: | |
ccdc2164 NS |
6135 | if (TARGET_GNU2_TLS) |
6136 | { | |
6137 | reg = arm_tls_descseq_addr (x, reg); | |
6138 | ||
6139 | tp = arm_load_tp (NULL_RTX); | |
6140 | ||
6141 | dest = gen_rtx_PLUS (Pmode, tp, reg); | |
6142 | } | |
6143 | else | |
6144 | { | |
6145 | /* Original scheme */ | |
6146 | insns = arm_call_tls_get_addr (x, reg, &ret, TLS_GD32); | |
6147 | dest = gen_reg_rtx (Pmode); | |
6148 | emit_libcall_block (insns, dest, ret, x); | |
6149 | } | |
d3585b76 DJ |
6150 | return dest; |
6151 | ||
6152 | case TLS_MODEL_LOCAL_DYNAMIC: | |
ccdc2164 NS |
6153 | if (TARGET_GNU2_TLS) |
6154 | { | |
6155 | reg = arm_tls_descseq_addr (x, reg); | |
d3585b76 | 6156 | |
ccdc2164 NS |
6157 | tp = arm_load_tp (NULL_RTX); |
6158 | ||
6159 | dest = gen_rtx_PLUS (Pmode, tp, reg); | |
6160 | } | |
6161 | else | |
6162 | { | |
6163 | insns = arm_call_tls_get_addr (x, reg, &ret, TLS_LDM32); | |
6164 | ||
6165 | /* Attach a unique REG_EQUIV, to allow the RTL optimizers to | |
6166 | share the LDM result with other LD model accesses. */ | |
6167 | eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const1_rtx), | |
6168 | UNSPEC_TLS); | |
6169 | dest = gen_reg_rtx (Pmode); | |
6170 | emit_libcall_block (insns, dest, ret, eqv); | |
6171 | ||
6172 | /* Load the addend. */ | |
6173 | addend = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, x, | |
6174 | GEN_INT (TLS_LDO32)), | |
6175 | UNSPEC_TLS); | |
6176 | addend = force_reg (SImode, gen_rtx_CONST (SImode, addend)); | |
6177 | dest = gen_rtx_PLUS (Pmode, dest, addend); | |
6178 | } | |
6179 | return dest; | |
d3585b76 DJ |
6180 | |
6181 | case TLS_MODEL_INITIAL_EXEC: | |
f16fe45f DJ |
6182 | labelno = GEN_INT (pic_labelno++); |
6183 | label = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); | |
6184 | label = gen_rtx_CONST (VOIDmode, label); | |
d3585b76 | 6185 | sum = gen_rtx_UNSPEC (Pmode, |
f16fe45f | 6186 | gen_rtvec (4, x, GEN_INT (TLS_IE32), label, |
d3585b76 DJ |
6187 | GEN_INT (TARGET_ARM ? 8 : 4)), |
6188 | UNSPEC_TLS); | |
6189 | reg = load_tls_operand (sum, reg); | |
6190 | ||
6191 | if (TARGET_ARM) | |
f16fe45f | 6192 | emit_insn (gen_tls_load_dot_plus_eight (reg, reg, labelno)); |
5b3e6663 | 6193 | else if (TARGET_THUMB2) |
2e5505a4 | 6194 | emit_insn (gen_tls_load_dot_plus_four (reg, NULL, reg, labelno)); |
d3585b76 DJ |
6195 | else |
6196 | { | |
f16fe45f | 6197 | emit_insn (gen_pic_add_dot_plus_four (reg, reg, labelno)); |
d3585b76 DJ |
6198 | emit_move_insn (reg, gen_const_mem (SImode, reg)); |
6199 | } | |
6200 | ||
6201 | tp = arm_load_tp (NULL_RTX); | |
6202 | ||
6203 | return gen_rtx_PLUS (Pmode, tp, reg); | |
6204 | ||
6205 | case TLS_MODEL_LOCAL_EXEC: | |
6206 | tp = arm_load_tp (NULL_RTX); | |
6207 | ||
6208 | reg = gen_rtx_UNSPEC (Pmode, | |
6209 | gen_rtvec (2, x, GEN_INT (TLS_LE32)), | |
6210 | UNSPEC_TLS); | |
6211 | reg = force_reg (SImode, gen_rtx_CONST (SImode, reg)); | |
6212 | ||
6213 | return gen_rtx_PLUS (Pmode, tp, reg); | |
6214 | ||
6215 | default: | |
6216 | abort (); | |
6217 | } | |
6218 | } | |
6219 | ||
ccf4d512 RE |
6220 | /* Try machine-dependent ways of modifying an illegitimate address |
6221 | to be legitimate. If we find one, return the new, valid address. */ | |
ccf4d512 | 6222 | rtx |
e32bac5b | 6223 | arm_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode) |
ccf4d512 | 6224 | { |
506d7b68 PB |
6225 | if (!TARGET_ARM) |
6226 | { | |
6227 | /* TODO: legitimize_address for Thumb2. */ | |
6228 | if (TARGET_THUMB2) | |
6229 | return x; | |
6230 | return thumb_legitimize_address (x, orig_x, mode); | |
6231 | } | |
6232 | ||
d3585b76 DJ |
6233 | if (arm_tls_symbol_p (x)) |
6234 | return legitimize_tls_address (x, NULL_RTX); | |
6235 | ||
ccf4d512 RE |
6236 | if (GET_CODE (x) == PLUS) |
6237 | { | |
6238 | rtx xop0 = XEXP (x, 0); | |
6239 | rtx xop1 = XEXP (x, 1); | |
6240 | ||
6241 | if (CONSTANT_P (xop0) && !symbol_mentioned_p (xop0)) | |
6242 | xop0 = force_reg (SImode, xop0); | |
6243 | ||
6244 | if (CONSTANT_P (xop1) && !symbol_mentioned_p (xop1)) | |
6245 | xop1 = force_reg (SImode, xop1); | |
6246 | ||
6247 | if (ARM_BASE_REGISTER_RTX_P (xop0) | |
6248 | && GET_CODE (xop1) == CONST_INT) | |
6249 | { | |
6250 | HOST_WIDE_INT n, low_n; | |
6251 | rtx base_reg, val; | |
6252 | n = INTVAL (xop1); | |
6253 | ||
9b66ebb1 PB |
6254 | /* VFP addressing modes actually allow greater offsets, but for |
6255 | now we just stick with the lowest common denominator. */ | |
6256 | if (mode == DImode | |
6257 | || ((TARGET_SOFT_FLOAT || TARGET_VFP) && mode == DFmode)) | |
ccf4d512 RE |
6258 | { |
6259 | low_n = n & 0x0f; | |
6260 | n &= ~0x0f; | |
6261 | if (low_n > 4) | |
6262 | { | |
6263 | n += 16; | |
6264 | low_n -= 16; | |
6265 | } | |
6266 | } | |
6267 | else | |
6268 | { | |
6269 | low_n = ((mode) == TImode ? 0 | |
6270 | : n >= 0 ? (n & 0xfff) : -((-n) & 0xfff)); | |
6271 | n -= low_n; | |
6272 | } | |
6273 | ||
6274 | base_reg = gen_reg_rtx (SImode); | |
d66437c5 | 6275 | val = force_operand (plus_constant (xop0, n), NULL_RTX); |
ccf4d512 | 6276 | emit_move_insn (base_reg, val); |
d66437c5 | 6277 | x = plus_constant (base_reg, low_n); |
ccf4d512 RE |
6278 | } |
6279 | else if (xop0 != XEXP (x, 0) || xop1 != XEXP (x, 1)) | |
6280 | x = gen_rtx_PLUS (SImode, xop0, xop1); | |
6281 | } | |
6282 | ||
6283 | /* XXX We don't allow MINUS any more -- see comment in | |
c6c3dba9 | 6284 | arm_legitimate_address_outer_p (). */ |
ccf4d512 RE |
6285 | else if (GET_CODE (x) == MINUS) |
6286 | { | |
6287 | rtx xop0 = XEXP (x, 0); | |
6288 | rtx xop1 = XEXP (x, 1); | |
6289 | ||
6290 | if (CONSTANT_P (xop0)) | |
6291 | xop0 = force_reg (SImode, xop0); | |
6292 | ||
6293 | if (CONSTANT_P (xop1) && ! symbol_mentioned_p (xop1)) | |
6294 | xop1 = force_reg (SImode, xop1); | |
6295 | ||
6296 | if (xop0 != XEXP (x, 0) || xop1 != XEXP (x, 1)) | |
6297 | x = gen_rtx_MINUS (SImode, xop0, xop1); | |
6298 | } | |
6299 | ||
86805759 NP |
6300 | /* Make sure to take full advantage of the pre-indexed addressing mode |
6301 | with absolute addresses which often allows for the base register to | |
6302 | be factorized for multiple adjacent memory references, and it might | |
6303 | even allows for the mini pool to be avoided entirely. */ | |
6304 | else if (GET_CODE (x) == CONST_INT && optimize > 0) | |
6305 | { | |
6306 | unsigned int bits; | |
6307 | HOST_WIDE_INT mask, base, index; | |
6308 | rtx base_reg; | |
6309 | ||
a50aa827 KH |
6310 | /* ldr and ldrb can use a 12-bit index, ldrsb and the rest can only |
6311 | use a 8-bit index. So let's use a 12-bit index for SImode only and | |
86805759 NP |
6312 | hope that arm_gen_constant will enable ldrb to use more bits. */ |
6313 | bits = (mode == SImode) ? 12 : 8; | |
6314 | mask = (1 << bits) - 1; | |
6315 | base = INTVAL (x) & ~mask; | |
6316 | index = INTVAL (x) & mask; | |
b107d743 | 6317 | if (bit_count (base & 0xffffffff) > (32 - bits)/2) |
86805759 NP |
6318 | { |
6319 | /* It'll most probably be more efficient to generate the base | |
6320 | with more bits set and use a negative index instead. */ | |
6321 | base |= mask; | |
6322 | index -= mask; | |
6323 | } | |
6324 | base_reg = force_reg (SImode, GEN_INT (base)); | |
d66437c5 | 6325 | x = plus_constant (base_reg, index); |
86805759 NP |
6326 | } |
6327 | ||
ccf4d512 RE |
6328 | if (flag_pic) |
6329 | { | |
6330 | /* We need to find and carefully transform any SYMBOL and LABEL | |
6331 | references; so go back to the original address expression. */ | |
6332 | rtx new_x = legitimize_pic_address (orig_x, mode, NULL_RTX); | |
6333 | ||
6334 | if (new_x != orig_x) | |
6335 | x = new_x; | |
6336 | } | |
6337 | ||
6338 | return x; | |
6339 | } | |
6340 | ||
6f5b4f3e RE |
6341 | |
6342 | /* Try machine-dependent ways of modifying an illegitimate Thumb address | |
6343 | to be legitimate. If we find one, return the new, valid address. */ | |
6344 | rtx | |
6345 | thumb_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode) | |
6346 | { | |
d3585b76 DJ |
6347 | if (arm_tls_symbol_p (x)) |
6348 | return legitimize_tls_address (x, NULL_RTX); | |
6349 | ||
6f5b4f3e RE |
6350 | if (GET_CODE (x) == PLUS |
6351 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
6352 | && (INTVAL (XEXP (x, 1)) >= 32 * GET_MODE_SIZE (mode) | |
6353 | || INTVAL (XEXP (x, 1)) < 0)) | |
6354 | { | |
6355 | rtx xop0 = XEXP (x, 0); | |
6356 | rtx xop1 = XEXP (x, 1); | |
6357 | HOST_WIDE_INT offset = INTVAL (xop1); | |
6358 | ||
6359 | /* Try and fold the offset into a biasing of the base register and | |
6360 | then offsetting that. Don't do this when optimizing for space | |
6361 | since it can cause too many CSEs. */ | |
6362 | if (optimize_size && offset >= 0 | |
6363 | && offset < 256 + 31 * GET_MODE_SIZE (mode)) | |
6364 | { | |
6365 | HOST_WIDE_INT delta; | |
6366 | ||
6367 | if (offset >= 256) | |
6368 | delta = offset - (256 - GET_MODE_SIZE (mode)); | |
6369 | else if (offset < 32 * GET_MODE_SIZE (mode) + 8) | |
6370 | delta = 31 * GET_MODE_SIZE (mode); | |
6371 | else | |
6372 | delta = offset & (~31 * GET_MODE_SIZE (mode)); | |
6373 | ||
6374 | xop0 = force_operand (plus_constant (xop0, offset - delta), | |
6375 | NULL_RTX); | |
6376 | x = plus_constant (xop0, delta); | |
6377 | } | |
6378 | else if (offset < 0 && offset > -256) | |
6379 | /* Small negative offsets are best done with a subtract before the | |
6380 | dereference, forcing these into a register normally takes two | |
6381 | instructions. */ | |
6382 | x = force_operand (x, NULL_RTX); | |
6383 | else | |
6384 | { | |
6385 | /* For the remaining cases, force the constant into a register. */ | |
6386 | xop1 = force_reg (SImode, xop1); | |
6387 | x = gen_rtx_PLUS (SImode, xop0, xop1); | |
6388 | } | |
6389 | } | |
6390 | else if (GET_CODE (x) == PLUS | |
6391 | && s_register_operand (XEXP (x, 1), SImode) | |
6392 | && !s_register_operand (XEXP (x, 0), SImode)) | |
6393 | { | |
6394 | rtx xop0 = force_operand (XEXP (x, 0), NULL_RTX); | |
6395 | ||
6396 | x = gen_rtx_PLUS (SImode, xop0, XEXP (x, 1)); | |
6397 | } | |
6398 | ||
6399 | if (flag_pic) | |
6400 | { | |
6401 | /* We need to find and carefully transform any SYMBOL and LABEL | |
6402 | references; so go back to the original address expression. */ | |
6403 | rtx new_x = legitimize_pic_address (orig_x, mode, NULL_RTX); | |
6404 | ||
6405 | if (new_x != orig_x) | |
6406 | x = new_x; | |
6407 | } | |
6408 | ||
6409 | return x; | |
6410 | } | |
6411 | ||
0cd98787 JZ |
6412 | bool |
6413 | arm_legitimize_reload_address (rtx *p, | |
6414 | enum machine_mode mode, | |
6415 | int opnum, int type, | |
6416 | int ind_levels ATTRIBUTE_UNUSED) | |
6417 | { | |
6418 | if (GET_CODE (*p) == PLUS | |
6419 | && GET_CODE (XEXP (*p, 0)) == REG | |
6420 | && ARM_REGNO_OK_FOR_BASE_P (REGNO (XEXP (*p, 0))) | |
6421 | && GET_CODE (XEXP (*p, 1)) == CONST_INT) | |
6422 | { | |
6423 | HOST_WIDE_INT val = INTVAL (XEXP (*p, 1)); | |
6424 | HOST_WIDE_INT low, high; | |
6425 | ||
06eb52ca CLT |
6426 | /* Detect coprocessor load/stores. */ |
6427 | bool coproc_p = ((TARGET_HARD_FLOAT | |
6428 | && (TARGET_VFP || TARGET_FPA || TARGET_MAVERICK) | |
6429 | && (mode == SFmode || mode == DFmode | |
6430 | || (mode == DImode && TARGET_MAVERICK))) | |
6431 | || (TARGET_REALLY_IWMMXT | |
6432 | && VALID_IWMMXT_REG_MODE (mode)) | |
6433 | || (TARGET_NEON | |
6434 | && (VALID_NEON_DREG_MODE (mode) | |
6435 | || VALID_NEON_QREG_MODE (mode)))); | |
6436 | ||
6437 | /* For some conditions, bail out when lower two bits are unaligned. */ | |
6438 | if ((val & 0x3) != 0 | |
6439 | /* Coprocessor load/store indexes are 8-bits + '00' appended. */ | |
6440 | && (coproc_p | |
6441 | /* For DI, and DF under soft-float: */ | |
6442 | || ((mode == DImode || mode == DFmode) | |
6443 | /* Without ldrd, we use stm/ldm, which does not | |
6444 | fair well with unaligned bits. */ | |
6445 | && (! TARGET_LDRD | |
6446 | /* Thumb-2 ldrd/strd is [-1020,+1020] in steps of 4. */ | |
6447 | || TARGET_THUMB2)))) | |
6448 | return false; | |
6449 | ||
6450 | /* When breaking down a [reg+index] reload address into [(reg+high)+low], | |
6451 | of which the (reg+high) gets turned into a reload add insn, | |
6452 | we try to decompose the index into high/low values that can often | |
6453 | also lead to better reload CSE. | |
6454 | For example: | |
6455 | ldr r0, [r2, #4100] // Offset too large | |
6456 | ldr r1, [r2, #4104] // Offset too large | |
6457 | ||
6458 | is best reloaded as: | |
6459 | add t1, r2, #4096 | |
6460 | ldr r0, [t1, #4] | |
6461 | add t2, r2, #4096 | |
6462 | ldr r1, [t2, #8] | |
6463 | ||
6464 | which post-reload CSE can simplify in most cases to eliminate the | |
6465 | second add instruction: | |
6466 | add t1, r2, #4096 | |
6467 | ldr r0, [t1, #4] | |
6468 | ldr r1, [t1, #8] | |
6469 | ||
6470 | The idea here is that we want to split out the bits of the constant | |
6471 | as a mask, rather than as subtracting the maximum offset that the | |
6472 | respective type of load/store used can handle. | |
6473 | ||
6474 | When encountering negative offsets, we can still utilize it even if | |
6475 | the overall offset is positive; sometimes this may lead to an immediate | |
6476 | that can be constructed with fewer instructions. | |
6477 | For example: | |
6478 | ldr r0, [r2, #0x3FFFFC] | |
6479 | ||
6480 | This is best reloaded as: | |
6481 | add t1, r2, #0x400000 | |
6482 | ldr r0, [t1, #-4] | |
6483 | ||
6484 | The trick for spotting this for a load insn with N bits of offset | |
6485 | (i.e. bits N-1:0) is to look at bit N; if it is set, then chose a | |
6486 | negative offset that is going to make bit N and all the bits below | |
6487 | it become zero in the remainder part. | |
6488 | ||
6489 | The SIGN_MAG_LOW_ADDR_BITS macro below implements this, with respect | |
6490 | to sign-magnitude addressing (i.e. separate +- bit, or 1's complement), | |
6491 | used in most cases of ARM load/store instructions. */ | |
6492 | ||
6493 | #define SIGN_MAG_LOW_ADDR_BITS(VAL, N) \ | |
6494 | (((VAL) & ((1 << (N)) - 1)) \ | |
6495 | ? (((VAL) & ((1 << ((N) + 1)) - 1)) ^ (1 << (N))) - (1 << (N)) \ | |
6496 | : 0) | |
6497 | ||
6498 | if (coproc_p) | |
01475747 CLT |
6499 | { |
6500 | low = SIGN_MAG_LOW_ADDR_BITS (val, 10); | |
6501 | ||
6502 | /* NEON quad-word load/stores are made of two double-word accesses, | |
6503 | so the valid index range is reduced by 8. Treat as 9-bit range if | |
6504 | we go over it. */ | |
6505 | if (TARGET_NEON && VALID_NEON_QREG_MODE (mode) && low >= 1016) | |
6506 | low = SIGN_MAG_LOW_ADDR_BITS (val, 9); | |
6507 | } | |
06eb52ca CLT |
6508 | else if (GET_MODE_SIZE (mode) == 8) |
6509 | { | |
6510 | if (TARGET_LDRD) | |
6511 | low = (TARGET_THUMB2 | |
6512 | ? SIGN_MAG_LOW_ADDR_BITS (val, 10) | |
6513 | : SIGN_MAG_LOW_ADDR_BITS (val, 8)); | |
6514 | else | |
6515 | /* For pre-ARMv5TE (without ldrd), we use ldm/stm(db/da/ib) | |
6516 | to access doublewords. The supported load/store offsets are | |
6517 | -8, -4, and 4, which we try to produce here. */ | |
6518 | low = ((val & 0xf) ^ 0x8) - 0x8; | |
6519 | } | |
6520 | else if (GET_MODE_SIZE (mode) < 8) | |
6521 | { | |
6522 | /* NEON element load/stores do not have an offset. */ | |
6523 | if (TARGET_NEON_FP16 && mode == HFmode) | |
6524 | return false; | |
6525 | ||
6526 | if (TARGET_THUMB2) | |
6527 | { | |
6528 | /* Thumb-2 has an asymmetrical index range of (-256,4096). | |
6529 | Try the wider 12-bit range first, and re-try if the result | |
6530 | is out of range. */ | |
6531 | low = SIGN_MAG_LOW_ADDR_BITS (val, 12); | |
6532 | if (low < -255) | |
6533 | low = SIGN_MAG_LOW_ADDR_BITS (val, 8); | |
6534 | } | |
6535 | else | |
6536 | { | |
6537 | if (mode == HImode || mode == HFmode) | |
6538 | { | |
6539 | if (arm_arch4) | |
6540 | low = SIGN_MAG_LOW_ADDR_BITS (val, 8); | |
6541 | else | |
6542 | { | |
6543 | /* The storehi/movhi_bytes fallbacks can use only | |
6544 | [-4094,+4094] of the full ldrb/strb index range. */ | |
6545 | low = SIGN_MAG_LOW_ADDR_BITS (val, 12); | |
6546 | if (low == 4095 || low == -4095) | |
6547 | return false; | |
6548 | } | |
6549 | } | |
6550 | else | |
6551 | low = SIGN_MAG_LOW_ADDR_BITS (val, 12); | |
6552 | } | |
6553 | } | |
0cd98787 JZ |
6554 | else |
6555 | return false; | |
6556 | ||
6557 | high = ((((val - low) & (unsigned HOST_WIDE_INT) 0xffffffff) | |
6558 | ^ (unsigned HOST_WIDE_INT) 0x80000000) | |
6559 | - (unsigned HOST_WIDE_INT) 0x80000000); | |
6560 | /* Check for overflow or zero */ | |
6561 | if (low == 0 || high == 0 || (high + low != val)) | |
6562 | return false; | |
6563 | ||
6564 | /* Reload the high part into a base reg; leave the low part | |
6565 | in the mem. */ | |
6566 | *p = gen_rtx_PLUS (GET_MODE (*p), | |
6567 | gen_rtx_PLUS (GET_MODE (*p), XEXP (*p, 0), | |
6568 | GEN_INT (high)), | |
6569 | GEN_INT (low)); | |
6570 | push_reload (XEXP (*p, 0), NULL_RTX, &XEXP (*p, 0), NULL, | |
6571 | MODE_BASE_REG_CLASS (mode), GET_MODE (*p), | |
6572 | VOIDmode, 0, 0, opnum, (enum reload_type) type); | |
6573 | return true; | |
6574 | } | |
6575 | ||
6576 | return false; | |
6577 | } | |
6578 | ||
a132dad6 | 6579 | rtx |
e0b92319 NC |
6580 | thumb_legitimize_reload_address (rtx *x_p, |
6581 | enum machine_mode mode, | |
6582 | int opnum, int type, | |
6583 | int ind_levels ATTRIBUTE_UNUSED) | |
a132dad6 RE |
6584 | { |
6585 | rtx x = *x_p; | |
e0b92319 | 6586 | |
a132dad6 RE |
6587 | if (GET_CODE (x) == PLUS |
6588 | && GET_MODE_SIZE (mode) < 4 | |
6589 | && REG_P (XEXP (x, 0)) | |
6590 | && XEXP (x, 0) == stack_pointer_rtx | |
6591 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
6592 | && !thumb_legitimate_offset_p (mode, INTVAL (XEXP (x, 1)))) | |
6593 | { | |
6594 | rtx orig_x = x; | |
6595 | ||
6596 | x = copy_rtx (x); | |
6597 | push_reload (orig_x, NULL_RTX, x_p, NULL, MODE_BASE_REG_CLASS (mode), | |
bbbbb16a | 6598 | Pmode, VOIDmode, 0, 0, opnum, (enum reload_type) type); |
a132dad6 RE |
6599 | return x; |
6600 | } | |
6601 | ||
6602 | /* If both registers are hi-regs, then it's better to reload the | |
6603 | entire expression rather than each register individually. That | |
6604 | only requires one reload register rather than two. */ | |
6605 | if (GET_CODE (x) == PLUS | |
6606 | && REG_P (XEXP (x, 0)) | |
6607 | && REG_P (XEXP (x, 1)) | |
6608 | && !REG_MODE_OK_FOR_REG_BASE_P (XEXP (x, 0), mode) | |
6609 | && !REG_MODE_OK_FOR_REG_BASE_P (XEXP (x, 1), mode)) | |
6610 | { | |
6611 | rtx orig_x = x; | |
6612 | ||
6613 | x = copy_rtx (x); | |
6614 | push_reload (orig_x, NULL_RTX, x_p, NULL, MODE_BASE_REG_CLASS (mode), | |
bbbbb16a | 6615 | Pmode, VOIDmode, 0, 0, opnum, (enum reload_type) type); |
a132dad6 RE |
6616 | return x; |
6617 | } | |
6618 | ||
6619 | return NULL; | |
6620 | } | |
d3585b76 DJ |
6621 | |
6622 | /* Test for various thread-local symbols. */ | |
6623 | ||
6624 | /* Return TRUE if X is a thread-local symbol. */ | |
6625 | ||
6626 | static bool | |
6627 | arm_tls_symbol_p (rtx x) | |
6628 | { | |
6629 | if (! TARGET_HAVE_TLS) | |
6630 | return false; | |
6631 | ||
6632 | if (GET_CODE (x) != SYMBOL_REF) | |
6633 | return false; | |
6634 | ||
6635 | return SYMBOL_REF_TLS_MODEL (x) != 0; | |
6636 | } | |
6637 | ||
6638 | /* Helper for arm_tls_referenced_p. */ | |
6639 | ||
6640 | static int | |
6641 | arm_tls_operand_p_1 (rtx *x, void *data ATTRIBUTE_UNUSED) | |
6642 | { | |
6643 | if (GET_CODE (*x) == SYMBOL_REF) | |
6644 | return SYMBOL_REF_TLS_MODEL (*x) != 0; | |
6645 | ||
6646 | /* Don't recurse into UNSPEC_TLS looking for TLS symbols; these are | |
6647 | TLS offsets, not real symbol references. */ | |
6648 | if (GET_CODE (*x) == UNSPEC | |
6649 | && XINT (*x, 1) == UNSPEC_TLS) | |
6650 | return -1; | |
6651 | ||
6652 | return 0; | |
6653 | } | |
6654 | ||
6655 | /* Return TRUE if X contains any TLS symbol references. */ | |
6656 | ||
6657 | bool | |
6658 | arm_tls_referenced_p (rtx x) | |
6659 | { | |
6660 | if (! TARGET_HAVE_TLS) | |
6661 | return false; | |
6662 | ||
6663 | return for_each_rtx (&x, arm_tls_operand_p_1, NULL); | |
6664 | } | |
8426b956 | 6665 | |
1a627b35 RS |
6666 | /* Implement TARGET_LEGITIMATE_CONSTANT_P. |
6667 | ||
6668 | On the ARM, allow any integer (invalid ones are removed later by insn | |
6669 | patterns), nice doubles and symbol_refs which refer to the function's | |
6670 | constant pool XXX. | |
6671 | ||
6672 | When generating pic allow anything. */ | |
6673 | ||
6674 | static bool | |
4b18d683 | 6675 | arm_legitimate_constant_p_1 (enum machine_mode mode, rtx x) |
1a627b35 | 6676 | { |
4b18d683 RS |
6677 | /* At present, we have no support for Neon structure constants, so forbid |
6678 | them here. It might be possible to handle simple cases like 0 and -1 | |
6679 | in future. */ | |
6680 | if (TARGET_NEON && VALID_NEON_STRUCT_MODE (mode)) | |
6681 | return false; | |
6682 | ||
1a627b35 RS |
6683 | return flag_pic || !label_mentioned_p (x); |
6684 | } | |
6685 | ||
6686 | static bool | |
6687 | thumb_legitimate_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx x) | |
6688 | { | |
6689 | return (GET_CODE (x) == CONST_INT | |
6690 | || GET_CODE (x) == CONST_DOUBLE | |
6691 | || CONSTANT_ADDRESS_P (x) | |
6692 | || flag_pic); | |
6693 | } | |
6694 | ||
6695 | static bool | |
6696 | arm_legitimate_constant_p (enum machine_mode mode, rtx x) | |
6697 | { | |
6698 | return (!arm_cannot_force_const_mem (mode, x) | |
6699 | && (TARGET_32BIT | |
6700 | ? arm_legitimate_constant_p_1 (mode, x) | |
6701 | : thumb_legitimate_constant_p (mode, x))); | |
6702 | } | |
6703 | ||
8426b956 RS |
6704 | /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */ |
6705 | ||
1a627b35 | 6706 | static bool |
fbbf66e7 | 6707 | arm_cannot_force_const_mem (enum machine_mode mode ATTRIBUTE_UNUSED, rtx x) |
8426b956 RS |
6708 | { |
6709 | rtx base, offset; | |
6710 | ||
6711 | if (ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P) | |
6712 | { | |
6713 | split_const (x, &base, &offset); | |
6714 | if (GET_CODE (base) == SYMBOL_REF | |
6715 | && !offset_within_block_p (base, INTVAL (offset))) | |
6716 | return true; | |
6717 | } | |
6718 | return arm_tls_referenced_p (x); | |
6719 | } | |
6b990f6b | 6720 | \f |
e2c671ba RE |
6721 | #define REG_OR_SUBREG_REG(X) \ |
6722 | (GET_CODE (X) == REG \ | |
6723 | || (GET_CODE (X) == SUBREG && GET_CODE (SUBREG_REG (X)) == REG)) | |
6724 | ||
6725 | #define REG_OR_SUBREG_RTX(X) \ | |
6726 | (GET_CODE (X) == REG ? (X) : SUBREG_REG (X)) | |
6727 | ||
3c50106f | 6728 | static inline int |
5b3e6663 | 6729 | thumb1_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer) |
e2c671ba RE |
6730 | { |
6731 | enum machine_mode mode = GET_MODE (x); | |
e4c6a07a | 6732 | int total; |
e2c671ba | 6733 | |
9b66ebb1 | 6734 | switch (code) |
d5b7b3ae | 6735 | { |
9b66ebb1 PB |
6736 | case ASHIFT: |
6737 | case ASHIFTRT: | |
6738 | case LSHIFTRT: | |
f676971a | 6739 | case ROTATERT: |
9b66ebb1 PB |
6740 | case PLUS: |
6741 | case MINUS: | |
6742 | case COMPARE: | |
6743 | case NEG: | |
f676971a | 6744 | case NOT: |
9b66ebb1 | 6745 | return COSTS_N_INSNS (1); |
f676971a EC |
6746 | |
6747 | case MULT: | |
6748 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
6749 | { | |
6750 | int cycles = 0; | |
9b66ebb1 | 6751 | unsigned HOST_WIDE_INT i = INTVAL (XEXP (x, 1)); |
f676971a EC |
6752 | |
6753 | while (i) | |
6754 | { | |
6755 | i >>= 2; | |
6756 | cycles++; | |
6757 | } | |
6758 | return COSTS_N_INSNS (2) + cycles; | |
9b66ebb1 PB |
6759 | } |
6760 | return COSTS_N_INSNS (1) + 16; | |
f676971a EC |
6761 | |
6762 | case SET: | |
6763 | return (COSTS_N_INSNS (1) | |
6764 | + 4 * ((GET_CODE (SET_SRC (x)) == MEM) | |
9b66ebb1 | 6765 | + GET_CODE (SET_DEST (x)) == MEM)); |
f676971a EC |
6766 | |
6767 | case CONST_INT: | |
6768 | if (outer == SET) | |
6769 | { | |
6770 | if ((unsigned HOST_WIDE_INT) INTVAL (x) < 256) | |
6771 | return 0; | |
6772 | if (thumb_shiftable_const (INTVAL (x))) | |
6773 | return COSTS_N_INSNS (2); | |
6774 | return COSTS_N_INSNS (3); | |
6775 | } | |
9b66ebb1 | 6776 | else if ((outer == PLUS || outer == COMPARE) |
f676971a | 6777 | && INTVAL (x) < 256 && INTVAL (x) > -256) |
9b66ebb1 | 6778 | return 0; |
582021ba | 6779 | else if ((outer == IOR || outer == XOR || outer == AND) |
9b66ebb1 PB |
6780 | && INTVAL (x) < 256 && INTVAL (x) >= -256) |
6781 | return COSTS_N_INSNS (1); | |
c99102b8 BS |
6782 | else if (outer == AND) |
6783 | { | |
6784 | int i; | |
6785 | /* This duplicates the tests in the andsi3 expander. */ | |
6786 | for (i = 9; i <= 31; i++) | |
6787 | if ((((HOST_WIDE_INT) 1) << i) - 1 == INTVAL (x) | |
6788 | || (((HOST_WIDE_INT) 1) << i) - 1 == ~INTVAL (x)) | |
6789 | return COSTS_N_INSNS (2); | |
6790 | } | |
f676971a EC |
6791 | else if (outer == ASHIFT || outer == ASHIFTRT |
6792 | || outer == LSHIFTRT) | |
6793 | return 0; | |
9b66ebb1 | 6794 | return COSTS_N_INSNS (2); |
f676971a EC |
6795 | |
6796 | case CONST: | |
6797 | case CONST_DOUBLE: | |
6798 | case LABEL_REF: | |
6799 | case SYMBOL_REF: | |
9b66ebb1 | 6800 | return COSTS_N_INSNS (3); |
f676971a | 6801 | |
9b66ebb1 PB |
6802 | case UDIV: |
6803 | case UMOD: | |
6804 | case DIV: | |
6805 | case MOD: | |
6806 | return 100; | |
d5b7b3ae | 6807 | |
9b66ebb1 PB |
6808 | case TRUNCATE: |
6809 | return 99; | |
d5b7b3ae | 6810 | |
9b66ebb1 PB |
6811 | case AND: |
6812 | case XOR: | |
f676971a | 6813 | case IOR: |
ff482c8d | 6814 | /* XXX guess. */ |
9b66ebb1 | 6815 | return 8; |
d5b7b3ae | 6816 | |
9b66ebb1 PB |
6817 | case MEM: |
6818 | /* XXX another guess. */ | |
6819 | /* Memory costs quite a lot for the first word, but subsequent words | |
6820 | load at the equivalent of a single insn each. */ | |
6821 | return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD) | |
6822 | + ((GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x)) | |
6823 | ? 4 : 0)); | |
6824 | ||
6825 | case IF_THEN_ELSE: | |
ff482c8d | 6826 | /* XXX a guess. */ |
9b66ebb1 PB |
6827 | if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC) |
6828 | return 14; | |
6829 | return 2; | |
6830 | ||
e4c6a07a | 6831 | case SIGN_EXTEND: |
9b66ebb1 | 6832 | case ZERO_EXTEND: |
e4c6a07a BS |
6833 | total = mode == DImode ? COSTS_N_INSNS (1) : 0; |
6834 | total += thumb1_rtx_costs (XEXP (x, 0), GET_CODE (XEXP (x, 0)), code); | |
f676971a | 6835 | |
e4c6a07a BS |
6836 | if (mode == SImode) |
6837 | return total; | |
f676971a | 6838 | |
e4c6a07a BS |
6839 | if (arm_arch6) |
6840 | return total + COSTS_N_INSNS (1); | |
f676971a | 6841 | |
e4c6a07a BS |
6842 | /* Assume a two-shift sequence. Increase the cost slightly so |
6843 | we prefer actual shifts over an extend operation. */ | |
6844 | return total + 1 + COSTS_N_INSNS (2); | |
f676971a | 6845 | |
9b66ebb1 PB |
6846 | default: |
6847 | return 99; | |
d5b7b3ae | 6848 | } |
9b66ebb1 PB |
6849 | } |
6850 | ||
d5a0a47b RE |
6851 | static inline bool |
6852 | arm_rtx_costs_1 (rtx x, enum rtx_code outer, int* total, bool speed) | |
9b66ebb1 PB |
6853 | { |
6854 | enum machine_mode mode = GET_MODE (x); | |
6855 | enum rtx_code subcode; | |
d5a0a47b RE |
6856 | rtx operand; |
6857 | enum rtx_code code = GET_CODE (x); | |
d5a0a47b | 6858 | *total = 0; |
9b66ebb1 | 6859 | |
e2c671ba RE |
6860 | switch (code) |
6861 | { | |
6862 | case MEM: | |
6863 | /* Memory costs quite a lot for the first word, but subsequent words | |
6864 | load at the equivalent of a single insn each. */ | |
d5a0a47b RE |
6865 | *total = COSTS_N_INSNS (2 + ARM_NUM_REGS (mode)); |
6866 | return true; | |
e2c671ba RE |
6867 | |
6868 | case DIV: | |
6869 | case MOD: | |
b9c53150 RS |
6870 | case UDIV: |
6871 | case UMOD: | |
d5a0a47b RE |
6872 | if (TARGET_HARD_FLOAT && mode == SFmode) |
6873 | *total = COSTS_N_INSNS (2); | |
e0dc3601 | 6874 | else if (TARGET_HARD_FLOAT && mode == DFmode && !TARGET_VFP_SINGLE) |
d5a0a47b RE |
6875 | *total = COSTS_N_INSNS (4); |
6876 | else | |
6877 | *total = COSTS_N_INSNS (20); | |
6878 | return false; | |
e2c671ba RE |
6879 | |
6880 | case ROTATE: | |
d5a0a47b RE |
6881 | if (GET_CODE (XEXP (x, 1)) == REG) |
6882 | *total = COSTS_N_INSNS (1); /* Need to subtract from 32 */ | |
6883 | else if (GET_CODE (XEXP (x, 1)) != CONST_INT) | |
68f932c4 | 6884 | *total = rtx_cost (XEXP (x, 1), code, 1, speed); |
d5a0a47b | 6885 | |
e2c671ba RE |
6886 | /* Fall through */ |
6887 | case ROTATERT: | |
6888 | if (mode != SImode) | |
d5a0a47b RE |
6889 | { |
6890 | *total += COSTS_N_INSNS (4); | |
6891 | return true; | |
6892 | } | |
6893 | ||
e2c671ba RE |
6894 | /* Fall through */ |
6895 | case ASHIFT: case LSHIFTRT: case ASHIFTRT: | |
68f932c4 | 6896 | *total += rtx_cost (XEXP (x, 0), code, 0, speed); |
e2c671ba | 6897 | if (mode == DImode) |
d5a0a47b RE |
6898 | { |
6899 | *total += COSTS_N_INSNS (3); | |
6900 | return true; | |
6901 | } | |
7612f14d | 6902 | |
d5a0a47b | 6903 | *total += COSTS_N_INSNS (1); |
7612f14d PB |
6904 | /* Increase the cost of complex shifts because they aren't any faster, |
6905 | and reduce dual issue opportunities. */ | |
6906 | if (arm_tune_cortex_a9 | |
6907 | && outer != SET && GET_CODE (XEXP (x, 1)) != CONST_INT) | |
d5a0a47b RE |
6908 | ++*total; |
6909 | ||
6910 | return true; | |
e2c671ba RE |
6911 | |
6912 | case MINUS: | |
6913 | if (mode == DImode) | |
d5a0a47b RE |
6914 | { |
6915 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
6916 | if (GET_CODE (XEXP (x, 0)) == CONST_INT | |
6917 | && const_ok_for_arm (INTVAL (XEXP (x, 0)))) | |
6918 | { | |
68f932c4 | 6919 | *total += rtx_cost (XEXP (x, 1), code, 1, speed); |
d5a0a47b RE |
6920 | return true; |
6921 | } | |
6922 | ||
6923 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
6924 | && const_ok_for_arm (INTVAL (XEXP (x, 1)))) | |
6925 | { | |
68f932c4 | 6926 | *total += rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
6927 | return true; |
6928 | } | |
6929 | ||
6930 | return false; | |
6931 | } | |
e2c671ba RE |
6932 | |
6933 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
d5a0a47b | 6934 | { |
e0dc3601 PB |
6935 | if (TARGET_HARD_FLOAT |
6936 | && (mode == SFmode | |
6937 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
6938 | { |
6939 | *total = COSTS_N_INSNS (1); | |
6940 | if (GET_CODE (XEXP (x, 0)) == CONST_DOUBLE | |
6941 | && arm_const_double_rtx (XEXP (x, 0))) | |
6942 | { | |
68f932c4 | 6943 | *total += rtx_cost (XEXP (x, 1), code, 1, speed); |
d5a0a47b RE |
6944 | return true; |
6945 | } | |
6946 | ||
6947 | if (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE | |
6948 | && arm_const_double_rtx (XEXP (x, 1))) | |
6949 | { | |
68f932c4 | 6950 | *total += rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
6951 | return true; |
6952 | } | |
6953 | ||
6954 | return false; | |
6955 | } | |
6956 | *total = COSTS_N_INSNS (20); | |
6957 | return false; | |
6958 | } | |
6959 | ||
6960 | *total = COSTS_N_INSNS (1); | |
6961 | if (GET_CODE (XEXP (x, 0)) == CONST_INT | |
6962 | && const_ok_for_arm (INTVAL (XEXP (x, 0)))) | |
6963 | { | |
68f932c4 | 6964 | *total += rtx_cost (XEXP (x, 1), code, 1, speed); |
d5a0a47b RE |
6965 | return true; |
6966 | } | |
6967 | ||
6968 | subcode = GET_CODE (XEXP (x, 1)); | |
6969 | if (subcode == ASHIFT || subcode == ASHIFTRT | |
6970 | || subcode == LSHIFTRT | |
6971 | || subcode == ROTATE || subcode == ROTATERT) | |
6972 | { | |
68f932c4 RS |
6973 | *total += rtx_cost (XEXP (x, 0), code, 0, speed); |
6974 | *total += rtx_cost (XEXP (XEXP (x, 1), 0), subcode, 0, speed); | |
d5a0a47b RE |
6975 | return true; |
6976 | } | |
6977 | ||
b32f6fff KH |
6978 | /* A shift as a part of RSB costs no more than RSB itself. */ |
6979 | if (GET_CODE (XEXP (x, 0)) == MULT | |
4c7c486a | 6980 | && power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode)) |
b32f6fff | 6981 | { |
68f932c4 RS |
6982 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), code, 0, speed); |
6983 | *total += rtx_cost (XEXP (x, 1), code, 1, speed); | |
b32f6fff KH |
6984 | return true; |
6985 | } | |
6986 | ||
d5a0a47b | 6987 | if (subcode == MULT |
4c7c486a | 6988 | && power_of_two_operand (XEXP (XEXP (x, 1), 1), SImode)) |
d5a0a47b | 6989 | { |
68f932c4 RS |
6990 | *total += rtx_cost (XEXP (x, 0), code, 0, speed); |
6991 | *total += rtx_cost (XEXP (XEXP (x, 1), 0), subcode, 0, speed); | |
d5a0a47b RE |
6992 | return true; |
6993 | } | |
6994 | ||
6995 | if (GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == RTX_COMPARE | |
6996 | || GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == RTX_COMM_COMPARE) | |
6997 | { | |
68f932c4 | 6998 | *total = COSTS_N_INSNS (1) + rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
6999 | if (GET_CODE (XEXP (XEXP (x, 1), 0)) == REG |
7000 | && REGNO (XEXP (XEXP (x, 1), 0)) != CC_REGNUM) | |
7001 | *total += COSTS_N_INSNS (1); | |
7002 | ||
7003 | return true; | |
7004 | } | |
7005 | ||
e2c671ba RE |
7006 | /* Fall through */ |
7007 | ||
f676971a | 7008 | case PLUS: |
d5a0a47b | 7009 | if (code == PLUS && arm_arch6 && mode == SImode |
ff069900 PB |
7010 | && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND |
7011 | || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)) | |
d5a0a47b RE |
7012 | { |
7013 | *total = COSTS_N_INSNS (1); | |
7014 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), GET_CODE (XEXP (x, 0)), | |
68f932c4 RS |
7015 | 0, speed); |
7016 | *total += rtx_cost (XEXP (x, 1), code, 1, speed); | |
d5a0a47b RE |
7017 | return true; |
7018 | } | |
ff069900 | 7019 | |
d5a0a47b RE |
7020 | /* MLA: All arguments must be registers. We filter out |
7021 | multiplication by a power of two, so that we fall down into | |
7022 | the code below. */ | |
7023 | if (GET_CODE (XEXP (x, 0)) == MULT | |
4c7c486a | 7024 | && !power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode)) |
26da58dd | 7025 | { |
d5a0a47b RE |
7026 | /* The cost comes from the cost of the multiply. */ |
7027 | return false; | |
26da58dd PB |
7028 | } |
7029 | ||
e2c671ba | 7030 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) |
d5a0a47b | 7031 | { |
e0dc3601 PB |
7032 | if (TARGET_HARD_FLOAT |
7033 | && (mode == SFmode | |
7034 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
7035 | { |
7036 | *total = COSTS_N_INSNS (1); | |
7037 | if (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE | |
7038 | && arm_const_double_rtx (XEXP (x, 1))) | |
7039 | { | |
68f932c4 | 7040 | *total += rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
7041 | return true; |
7042 | } | |
7043 | ||
7044 | return false; | |
7045 | } | |
7046 | ||
7047 | *total = COSTS_N_INSNS (20); | |
7048 | return false; | |
7049 | } | |
7050 | ||
7051 | if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_COMPARE | |
7052 | || GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_COMM_COMPARE) | |
7053 | { | |
68f932c4 | 7054 | *total = COSTS_N_INSNS (1) + rtx_cost (XEXP (x, 1), code, 1, speed); |
d5a0a47b RE |
7055 | if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG |
7056 | && REGNO (XEXP (XEXP (x, 0), 0)) != CC_REGNUM) | |
7057 | *total += COSTS_N_INSNS (1); | |
7058 | return true; | |
7059 | } | |
e2c671ba RE |
7060 | |
7061 | /* Fall through */ | |
d5a0a47b | 7062 | |
f676971a | 7063 | case AND: case XOR: case IOR: |
e2c671ba RE |
7064 | |
7065 | /* Normally the frame registers will be spilt into reg+const during | |
7066 | reload, so it is a bad idea to combine them with other instructions, | |
7067 | since then they might not be moved outside of loops. As a compromise | |
7068 | we allow integration with ops that have a constant as their second | |
7069 | operand. */ | |
13cc4787 BS |
7070 | if (REG_OR_SUBREG_REG (XEXP (x, 0)) |
7071 | && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0))) | |
7072 | && GET_CODE (XEXP (x, 1)) != CONST_INT) | |
7073 | *total = COSTS_N_INSNS (1); | |
e2c671ba RE |
7074 | |
7075 | if (mode == DImode) | |
d5a0a47b RE |
7076 | { |
7077 | *total += COSTS_N_INSNS (2); | |
7078 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
7079 | && const_ok_for_op (INTVAL (XEXP (x, 1)), code)) | |
7080 | { | |
68f932c4 | 7081 | *total += rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
7082 | return true; |
7083 | } | |
e2c671ba | 7084 | |
d5a0a47b RE |
7085 | return false; |
7086 | } | |
7087 | ||
7088 | *total += COSTS_N_INSNS (1); | |
7089 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
7090 | && const_ok_for_op (INTVAL (XEXP (x, 1)), code)) | |
7091 | { | |
68f932c4 | 7092 | *total += rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
7093 | return true; |
7094 | } | |
7095 | subcode = GET_CODE (XEXP (x, 0)); | |
7096 | if (subcode == ASHIFT || subcode == ASHIFTRT | |
7097 | || subcode == LSHIFTRT | |
7098 | || subcode == ROTATE || subcode == ROTATERT) | |
7099 | { | |
68f932c4 RS |
7100 | *total += rtx_cost (XEXP (x, 1), code, 1, speed); |
7101 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), subcode, 0, speed); | |
d5a0a47b RE |
7102 | return true; |
7103 | } | |
7104 | ||
7105 | if (subcode == MULT | |
4c7c486a | 7106 | && power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode)) |
d5a0a47b | 7107 | { |
68f932c4 RS |
7108 | *total += rtx_cost (XEXP (x, 1), code, 1, speed); |
7109 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), subcode, 0, speed); | |
d5a0a47b RE |
7110 | return true; |
7111 | } | |
7112 | ||
7113 | if (subcode == UMIN || subcode == UMAX | |
7114 | || subcode == SMIN || subcode == SMAX) | |
7115 | { | |
7116 | *total = COSTS_N_INSNS (3); | |
7117 | return true; | |
7118 | } | |
7119 | ||
7120 | return false; | |
e2c671ba RE |
7121 | |
7122 | case MULT: | |
9b66ebb1 | 7123 | /* This should have been handled by the CPU specific routines. */ |
e6d29d15 | 7124 | gcc_unreachable (); |
e2c671ba | 7125 | |
56636818 | 7126 | case TRUNCATE: |
9b66ebb1 | 7127 | if (arm_arch3m && mode == SImode |
56636818 JL |
7128 | && GET_CODE (XEXP (x, 0)) == LSHIFTRT |
7129 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT | |
7130 | && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) | |
7131 | == GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1))) | |
7132 | && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND | |
7133 | || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND)) | |
d5a0a47b | 7134 | { |
68f932c4 | 7135 | *total = rtx_cost (XEXP (XEXP (x, 0), 0), LSHIFTRT, 0, speed); |
d5a0a47b RE |
7136 | return true; |
7137 | } | |
7138 | *total = COSTS_N_INSNS (2); /* Plus the cost of the MULT */ | |
7139 | return false; | |
56636818 | 7140 | |
e2c671ba RE |
7141 | case NEG: |
7142 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
d5a0a47b | 7143 | { |
e0dc3601 PB |
7144 | if (TARGET_HARD_FLOAT |
7145 | && (mode == SFmode | |
7146 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
7147 | { |
7148 | *total = COSTS_N_INSNS (1); | |
7149 | return false; | |
7150 | } | |
7151 | *total = COSTS_N_INSNS (2); | |
7152 | return false; | |
7153 | } | |
7154 | ||
e2c671ba RE |
7155 | /* Fall through */ |
7156 | case NOT: | |
d5a0a47b RE |
7157 | *total = COSTS_N_INSNS (ARM_NUM_REGS(mode)); |
7158 | if (mode == SImode && code == NOT) | |
7159 | { | |
7160 | subcode = GET_CODE (XEXP (x, 0)); | |
7161 | if (subcode == ASHIFT || subcode == ASHIFTRT | |
7162 | || subcode == LSHIFTRT | |
7163 | || subcode == ROTATE || subcode == ROTATERT | |
7164 | || (subcode == MULT | |
4c7c486a | 7165 | && power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode))) |
d5a0a47b | 7166 | { |
68f932c4 | 7167 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), subcode, 0, speed); |
d5a0a47b RE |
7168 | /* Register shifts cost an extra cycle. */ |
7169 | if (GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT) | |
7170 | *total += COSTS_N_INSNS (1) + rtx_cost (XEXP (XEXP (x, 0), 1), | |
68f932c4 | 7171 | subcode, 1, speed); |
d5a0a47b RE |
7172 | return true; |
7173 | } | |
7174 | } | |
e2c671ba | 7175 | |
d5a0a47b | 7176 | return false; |
e2c671ba RE |
7177 | |
7178 | case IF_THEN_ELSE: | |
7179 | if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC) | |
d5a0a47b RE |
7180 | { |
7181 | *total = COSTS_N_INSNS (4); | |
7182 | return true; | |
7183 | } | |
7184 | ||
7185 | operand = XEXP (x, 0); | |
7186 | ||
7187 | if (!((GET_RTX_CLASS (GET_CODE (operand)) == RTX_COMPARE | |
7188 | || GET_RTX_CLASS (GET_CODE (operand)) == RTX_COMM_COMPARE) | |
7189 | && GET_CODE (XEXP (operand, 0)) == REG | |
7190 | && REGNO (XEXP (operand, 0)) == CC_REGNUM)) | |
7191 | *total += COSTS_N_INSNS (1); | |
68f932c4 RS |
7192 | *total += (rtx_cost (XEXP (x, 1), code, 1, speed) |
7193 | + rtx_cost (XEXP (x, 2), code, 2, speed)); | |
d5a0a47b RE |
7194 | return true; |
7195 | ||
7196 | case NE: | |
7197 | if (mode == SImode && XEXP (x, 1) == const0_rtx) | |
7198 | { | |
68f932c4 | 7199 | *total = COSTS_N_INSNS (2) + rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
7200 | return true; |
7201 | } | |
7202 | goto scc_insn; | |
7203 | ||
7204 | case GE: | |
7205 | if ((GET_CODE (XEXP (x, 0)) != REG || REGNO (XEXP (x, 0)) != CC_REGNUM) | |
7206 | && mode == SImode && XEXP (x, 1) == const0_rtx) | |
7207 | { | |
68f932c4 | 7208 | *total = COSTS_N_INSNS (2) + rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
7209 | return true; |
7210 | } | |
7211 | goto scc_insn; | |
7212 | ||
7213 | case LT: | |
7214 | if ((GET_CODE (XEXP (x, 0)) != REG || REGNO (XEXP (x, 0)) != CC_REGNUM) | |
7215 | && mode == SImode && XEXP (x, 1) == const0_rtx) | |
7216 | { | |
68f932c4 | 7217 | *total = COSTS_N_INSNS (1) + rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
7218 | return true; |
7219 | } | |
7220 | goto scc_insn; | |
7221 | ||
7222 | case EQ: | |
7223 | case GT: | |
7224 | case LE: | |
7225 | case GEU: | |
7226 | case LTU: | |
7227 | case GTU: | |
7228 | case LEU: | |
7229 | case UNORDERED: | |
7230 | case ORDERED: | |
7231 | case UNEQ: | |
7232 | case UNGE: | |
7233 | case UNLT: | |
7234 | case UNGT: | |
7235 | case UNLE: | |
7236 | scc_insn: | |
7237 | /* SCC insns. In the case where the comparison has already been | |
7238 | performed, then they cost 2 instructions. Otherwise they need | |
7239 | an additional comparison before them. */ | |
7240 | *total = COSTS_N_INSNS (2); | |
7241 | if (GET_CODE (XEXP (x, 0)) == REG && REGNO (XEXP (x, 0)) == CC_REGNUM) | |
7242 | { | |
7243 | return true; | |
7244 | } | |
e2c671ba | 7245 | |
d5a0a47b | 7246 | /* Fall through */ |
e2c671ba | 7247 | case COMPARE: |
d5a0a47b RE |
7248 | if (GET_CODE (XEXP (x, 0)) == REG && REGNO (XEXP (x, 0)) == CC_REGNUM) |
7249 | { | |
7250 | *total = 0; | |
7251 | return true; | |
7252 | } | |
7253 | ||
7254 | *total += COSTS_N_INSNS (1); | |
7255 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
7256 | && const_ok_for_op (INTVAL (XEXP (x, 1)), code)) | |
7257 | { | |
68f932c4 | 7258 | *total += rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
7259 | return true; |
7260 | } | |
7261 | ||
7262 | subcode = GET_CODE (XEXP (x, 0)); | |
7263 | if (subcode == ASHIFT || subcode == ASHIFTRT | |
7264 | || subcode == LSHIFTRT | |
7265 | || subcode == ROTATE || subcode == ROTATERT) | |
7266 | { | |
68f932c4 RS |
7267 | *total += rtx_cost (XEXP (x, 1), code, 1, speed); |
7268 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), subcode, 0, speed); | |
d5a0a47b RE |
7269 | return true; |
7270 | } | |
7271 | ||
7272 | if (subcode == MULT | |
4c7c486a | 7273 | && power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode)) |
d5a0a47b | 7274 | { |
68f932c4 RS |
7275 | *total += rtx_cost (XEXP (x, 1), code, 1, speed); |
7276 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), subcode, 0, speed); | |
d5a0a47b RE |
7277 | return true; |
7278 | } | |
7279 | ||
7280 | return false; | |
7281 | ||
7282 | case UMIN: | |
7283 | case UMAX: | |
7284 | case SMIN: | |
7285 | case SMAX: | |
68f932c4 | 7286 | *total = COSTS_N_INSNS (2) + rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
7287 | if (GET_CODE (XEXP (x, 1)) != CONST_INT |
7288 | || !const_ok_for_arm (INTVAL (XEXP (x, 1)))) | |
68f932c4 | 7289 | *total += rtx_cost (XEXP (x, 1), code, 1, speed); |
d5a0a47b | 7290 | return true; |
e2c671ba RE |
7291 | |
7292 | case ABS: | |
bbbbb16a | 7293 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) |
d5a0a47b | 7294 | { |
e0dc3601 PB |
7295 | if (TARGET_HARD_FLOAT |
7296 | && (mode == SFmode | |
7297 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
7298 | { |
7299 | *total = COSTS_N_INSNS (1); | |
7300 | return false; | |
7301 | } | |
7302 | *total = COSTS_N_INSNS (20); | |
7303 | return false; | |
7304 | } | |
7305 | *total = COSTS_N_INSNS (1); | |
7306 | if (mode == DImode) | |
7307 | *total += COSTS_N_INSNS (3); | |
7308 | return false; | |
e2c671ba RE |
7309 | |
7310 | case SIGN_EXTEND: | |
e2c671ba | 7311 | case ZERO_EXTEND: |
d5a0a47b RE |
7312 | *total = 0; |
7313 | if (GET_MODE_CLASS (mode) == MODE_INT) | |
e2c671ba | 7314 | { |
e4c6a07a BS |
7315 | rtx op = XEXP (x, 0); |
7316 | enum machine_mode opmode = GET_MODE (op); | |
7317 | ||
d5a0a47b RE |
7318 | if (mode == DImode) |
7319 | *total += COSTS_N_INSNS (1); | |
e2c671ba | 7320 | |
e4c6a07a | 7321 | if (opmode != SImode) |
d5a0a47b | 7322 | { |
e4c6a07a | 7323 | if (MEM_P (op)) |
d5a0a47b | 7324 | { |
e4c6a07a BS |
7325 | /* If !arm_arch4, we use one of the extendhisi2_mem |
7326 | or movhi_bytes patterns for HImode. For a QImode | |
7327 | sign extension, we first zero-extend from memory | |
7328 | and then perform a shift sequence. */ | |
7329 | if (!arm_arch4 && (opmode != QImode || code == SIGN_EXTEND)) | |
7330 | *total += COSTS_N_INSNS (2); | |
d5a0a47b | 7331 | } |
e4c6a07a BS |
7332 | else if (arm_arch6) |
7333 | *total += COSTS_N_INSNS (1); | |
7334 | ||
7335 | /* We don't have the necessary insn, so we need to perform some | |
7336 | other operation. */ | |
7337 | else if (TARGET_ARM && code == ZERO_EXTEND && mode == QImode) | |
7338 | /* An and with constant 255. */ | |
7339 | *total += COSTS_N_INSNS (1); | |
7340 | else | |
7341 | /* A shift sequence. Increase costs slightly to avoid | |
7342 | combining two shifts into an extend operation. */ | |
7343 | *total += COSTS_N_INSNS (2) + 1; | |
d5a0a47b | 7344 | } |
e2c671ba | 7345 | |
d5a0a47b RE |
7346 | return false; |
7347 | } | |
ad076f4e | 7348 | |
d5a0a47b RE |
7349 | switch (GET_MODE (XEXP (x, 0))) |
7350 | { | |
5a9335ef NC |
7351 | case V8QImode: |
7352 | case V4HImode: | |
7353 | case V2SImode: | |
7354 | case V4QImode: | |
7355 | case V2HImode: | |
d5a0a47b RE |
7356 | *total = COSTS_N_INSNS (1); |
7357 | return false; | |
5a9335ef | 7358 | |
ad076f4e | 7359 | default: |
e6d29d15 | 7360 | gcc_unreachable (); |
e2c671ba | 7361 | } |
e6d29d15 | 7362 | gcc_unreachable (); |
e2c671ba | 7363 | |
d5a0a47b RE |
7364 | case ZERO_EXTRACT: |
7365 | case SIGN_EXTRACT: | |
68f932c4 | 7366 | *total = COSTS_N_INSNS (1) + rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b RE |
7367 | return true; |
7368 | ||
f676971a | 7369 | case CONST_INT: |
d5a0a47b RE |
7370 | if (const_ok_for_arm (INTVAL (x)) |
7371 | || const_ok_for_arm (~INTVAL (x))) | |
7372 | *total = COSTS_N_INSNS (1); | |
f676971a | 7373 | else |
d5a0a47b RE |
7374 | *total = COSTS_N_INSNS (arm_gen_constant (SET, mode, NULL_RTX, |
7375 | INTVAL (x), NULL_RTX, | |
7376 | NULL_RTX, 0, 0)); | |
7377 | return true; | |
f676971a EC |
7378 | |
7379 | case CONST: | |
7380 | case LABEL_REF: | |
7381 | case SYMBOL_REF: | |
d5a0a47b RE |
7382 | *total = COSTS_N_INSNS (3); |
7383 | return true; | |
f676971a | 7384 | |
571191af | 7385 | case HIGH: |
d5a0a47b RE |
7386 | *total = COSTS_N_INSNS (1); |
7387 | return true; | |
7388 | ||
571191af | 7389 | case LO_SUM: |
d5a0a47b | 7390 | *total = COSTS_N_INSNS (1); |
68f932c4 | 7391 | *total += rtx_cost (XEXP (x, 0), code, 0, speed); |
d5a0a47b | 7392 | return true; |
571191af | 7393 | |
f676971a | 7394 | case CONST_DOUBLE: |
e0dc3601 PB |
7395 | if (TARGET_HARD_FLOAT && vfp3_const_double_rtx (x) |
7396 | && (mode == SFmode || !TARGET_VFP_SINGLE)) | |
d5a0a47b RE |
7397 | *total = COSTS_N_INSNS (1); |
7398 | else | |
7399 | *total = COSTS_N_INSNS (4); | |
7400 | return true; | |
f676971a | 7401 | |
e2c671ba | 7402 | default: |
d5a0a47b RE |
7403 | *total = COSTS_N_INSNS (4); |
7404 | return false; | |
e2c671ba RE |
7405 | } |
7406 | } | |
32de079a | 7407 | |
7548c1be WG |
7408 | /* Estimates the size cost of thumb1 instructions. |
7409 | For now most of the code is copied from thumb1_rtx_costs. We need more | |
7410 | fine grain tuning when we have more related test cases. */ | |
7411 | static inline int | |
7412 | thumb1_size_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer) | |
7413 | { | |
7414 | enum machine_mode mode = GET_MODE (x); | |
7415 | ||
7416 | switch (code) | |
7417 | { | |
7418 | case ASHIFT: | |
7419 | case ASHIFTRT: | |
7420 | case LSHIFTRT: | |
7421 | case ROTATERT: | |
7422 | case PLUS: | |
7423 | case MINUS: | |
7424 | case COMPARE: | |
7425 | case NEG: | |
7426 | case NOT: | |
7427 | return COSTS_N_INSNS (1); | |
7428 | ||
7429 | case MULT: | |
7430 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
7431 | { | |
7432 | /* Thumb1 mul instruction can't operate on const. We must Load it | |
7433 | into a register first. */ | |
7434 | int const_size = thumb1_size_rtx_costs (XEXP (x, 1), CONST_INT, SET); | |
7435 | return COSTS_N_INSNS (1) + const_size; | |
7436 | } | |
7437 | return COSTS_N_INSNS (1); | |
7438 | ||
7439 | case SET: | |
7440 | return (COSTS_N_INSNS (1) | |
7441 | + 4 * ((GET_CODE (SET_SRC (x)) == MEM) | |
7442 | + GET_CODE (SET_DEST (x)) == MEM)); | |
7443 | ||
7444 | case CONST_INT: | |
7445 | if (outer == SET) | |
7446 | { | |
7447 | if ((unsigned HOST_WIDE_INT) INTVAL (x) < 256) | |
9b9ee6d3 | 7448 | return COSTS_N_INSNS (1); |
3393e880 MK |
7449 | /* See split "TARGET_THUMB1 && satisfies_constraint_J". */ |
7450 | if (INTVAL (x) >= -255 && INTVAL (x) <= -1) | |
7451 | return COSTS_N_INSNS (2); | |
7452 | /* See split "TARGET_THUMB1 && satisfies_constraint_K". */ | |
7548c1be WG |
7453 | if (thumb_shiftable_const (INTVAL (x))) |
7454 | return COSTS_N_INSNS (2); | |
7455 | return COSTS_N_INSNS (3); | |
7456 | } | |
7457 | else if ((outer == PLUS || outer == COMPARE) | |
7458 | && INTVAL (x) < 256 && INTVAL (x) > -256) | |
7459 | return 0; | |
7460 | else if ((outer == IOR || outer == XOR || outer == AND) | |
7461 | && INTVAL (x) < 256 && INTVAL (x) >= -256) | |
7462 | return COSTS_N_INSNS (1); | |
7463 | else if (outer == AND) | |
7464 | { | |
7465 | int i; | |
7466 | /* This duplicates the tests in the andsi3 expander. */ | |
7467 | for (i = 9; i <= 31; i++) | |
7468 | if ((((HOST_WIDE_INT) 1) << i) - 1 == INTVAL (x) | |
7469 | || (((HOST_WIDE_INT) 1) << i) - 1 == ~INTVAL (x)) | |
7470 | return COSTS_N_INSNS (2); | |
7471 | } | |
7472 | else if (outer == ASHIFT || outer == ASHIFTRT | |
7473 | || outer == LSHIFTRT) | |
7474 | return 0; | |
7475 | return COSTS_N_INSNS (2); | |
7476 | ||
7477 | case CONST: | |
7478 | case CONST_DOUBLE: | |
7479 | case LABEL_REF: | |
7480 | case SYMBOL_REF: | |
7481 | return COSTS_N_INSNS (3); | |
7482 | ||
7483 | case UDIV: | |
7484 | case UMOD: | |
7485 | case DIV: | |
7486 | case MOD: | |
7487 | return 100; | |
7488 | ||
7489 | case TRUNCATE: | |
7490 | return 99; | |
7491 | ||
7492 | case AND: | |
7493 | case XOR: | |
7494 | case IOR: | |
7495 | /* XXX guess. */ | |
7496 | return 8; | |
7497 | ||
7498 | case MEM: | |
7499 | /* XXX another guess. */ | |
7500 | /* Memory costs quite a lot for the first word, but subsequent words | |
7501 | load at the equivalent of a single insn each. */ | |
7502 | return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD) | |
7503 | + ((GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x)) | |
7504 | ? 4 : 0)); | |
7505 | ||
7506 | case IF_THEN_ELSE: | |
7507 | /* XXX a guess. */ | |
7508 | if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC) | |
7509 | return 14; | |
7510 | return 2; | |
7511 | ||
7512 | case ZERO_EXTEND: | |
7513 | /* XXX still guessing. */ | |
7514 | switch (GET_MODE (XEXP (x, 0))) | |
7515 | { | |
7516 | case QImode: | |
7517 | return (1 + (mode == DImode ? 4 : 0) | |
7518 | + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
7519 | ||
7520 | case HImode: | |
7521 | return (4 + (mode == DImode ? 4 : 0) | |
7522 | + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
7523 | ||
7524 | case SImode: | |
7525 | return (1 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
7526 | ||
7527 | default: | |
7528 | return 99; | |
7529 | } | |
7530 | ||
7531 | default: | |
7532 | return 99; | |
7533 | } | |
7534 | } | |
7535 | ||
21b5653c RE |
7536 | /* RTX costs when optimizing for size. */ |
7537 | static bool | |
d5a0a47b RE |
7538 | arm_size_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer_code, |
7539 | int *total) | |
21b5653c RE |
7540 | { |
7541 | enum machine_mode mode = GET_MODE (x); | |
09754904 | 7542 | if (TARGET_THUMB1) |
21b5653c | 7543 | { |
7548c1be | 7544 | *total = thumb1_size_rtx_costs (x, code, outer_code); |
21b5653c RE |
7545 | return true; |
7546 | } | |
7547 | ||
09754904 | 7548 | /* FIXME: This makes no attempt to prefer narrow Thumb-2 instructions. */ |
21b5653c RE |
7549 | switch (code) |
7550 | { | |
7551 | case MEM: | |
f676971a | 7552 | /* A memory access costs 1 insn if the mode is small, or the address is |
21b5653c RE |
7553 | a single register, otherwise it costs one insn per word. */ |
7554 | if (REG_P (XEXP (x, 0))) | |
7555 | *total = COSTS_N_INSNS (1); | |
d37c3c62 MK |
7556 | else if (flag_pic |
7557 | && GET_CODE (XEXP (x, 0)) == PLUS | |
7558 | && will_be_in_index_register (XEXP (XEXP (x, 0), 1))) | |
7559 | /* This will be split into two instructions. | |
7560 | See arm.md:calculate_pic_address. */ | |
7561 | *total = COSTS_N_INSNS (2); | |
21b5653c RE |
7562 | else |
7563 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7564 | return true; | |
7565 | ||
7566 | case DIV: | |
7567 | case MOD: | |
7568 | case UDIV: | |
7569 | case UMOD: | |
7570 | /* Needs a libcall, so it costs about this. */ | |
7571 | *total = COSTS_N_INSNS (2); | |
7572 | return false; | |
7573 | ||
7574 | case ROTATE: | |
7575 | if (mode == SImode && GET_CODE (XEXP (x, 1)) == REG) | |
7576 | { | |
68f932c4 | 7577 | *total = COSTS_N_INSNS (2) + rtx_cost (XEXP (x, 0), code, 0, false); |
21b5653c RE |
7578 | return true; |
7579 | } | |
7580 | /* Fall through */ | |
7581 | case ROTATERT: | |
7582 | case ASHIFT: | |
7583 | case LSHIFTRT: | |
7584 | case ASHIFTRT: | |
7585 | if (mode == DImode && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
7586 | { | |
68f932c4 | 7587 | *total = COSTS_N_INSNS (3) + rtx_cost (XEXP (x, 0), code, 0, false); |
21b5653c RE |
7588 | return true; |
7589 | } | |
7590 | else if (mode == SImode) | |
7591 | { | |
68f932c4 | 7592 | *total = COSTS_N_INSNS (1) + rtx_cost (XEXP (x, 0), code, 0, false); |
21b5653c RE |
7593 | /* Slightly disparage register shifts, but not by much. */ |
7594 | if (GET_CODE (XEXP (x, 1)) != CONST_INT) | |
68f932c4 | 7595 | *total += 1 + rtx_cost (XEXP (x, 1), code, 1, false); |
21b5653c RE |
7596 | return true; |
7597 | } | |
7598 | ||
7599 | /* Needs a libcall. */ | |
7600 | *total = COSTS_N_INSNS (2); | |
7601 | return false; | |
7602 | ||
7603 | case MINUS: | |
e0dc3601 PB |
7604 | if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
7605 | && (mode == SFmode || !TARGET_VFP_SINGLE)) | |
21b5653c RE |
7606 | { |
7607 | *total = COSTS_N_INSNS (1); | |
7608 | return false; | |
7609 | } | |
7610 | ||
7611 | if (mode == SImode) | |
7612 | { | |
7613 | enum rtx_code subcode0 = GET_CODE (XEXP (x, 0)); | |
7614 | enum rtx_code subcode1 = GET_CODE (XEXP (x, 1)); | |
7615 | ||
7616 | if (subcode0 == ROTATE || subcode0 == ROTATERT || subcode0 == ASHIFT | |
7617 | || subcode0 == LSHIFTRT || subcode0 == ASHIFTRT | |
7618 | || subcode1 == ROTATE || subcode1 == ROTATERT | |
7619 | || subcode1 == ASHIFT || subcode1 == LSHIFTRT | |
7620 | || subcode1 == ASHIFTRT) | |
7621 | { | |
7622 | /* It's just the cost of the two operands. */ | |
7623 | *total = 0; | |
7624 | return false; | |
7625 | } | |
7626 | ||
7627 | *total = COSTS_N_INSNS (1); | |
7628 | return false; | |
7629 | } | |
7630 | ||
7631 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7632 | return false; | |
7633 | ||
f676971a | 7634 | case PLUS: |
e0dc3601 PB |
7635 | if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
7636 | && (mode == SFmode || !TARGET_VFP_SINGLE)) | |
21b5653c RE |
7637 | { |
7638 | *total = COSTS_N_INSNS (1); | |
7639 | return false; | |
7640 | } | |
7641 | ||
6e782a29 KH |
7642 | /* A shift as a part of ADD costs nothing. */ |
7643 | if (GET_CODE (XEXP (x, 0)) == MULT | |
7644 | && power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode)) | |
7645 | { | |
7646 | *total = COSTS_N_INSNS (TARGET_THUMB2 ? 2 : 1); | |
68f932c4 RS |
7647 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), code, 0, false); |
7648 | *total += rtx_cost (XEXP (x, 1), code, 1, false); | |
6e782a29 KH |
7649 | return true; |
7650 | } | |
7651 | ||
21b5653c RE |
7652 | /* Fall through */ |
7653 | case AND: case XOR: case IOR: | |
7654 | if (mode == SImode) | |
7655 | { | |
7656 | enum rtx_code subcode = GET_CODE (XEXP (x, 0)); | |
7657 | ||
7658 | if (subcode == ROTATE || subcode == ROTATERT || subcode == ASHIFT | |
7659 | || subcode == LSHIFTRT || subcode == ASHIFTRT | |
7660 | || (code == AND && subcode == NOT)) | |
7661 | { | |
7662 | /* It's just the cost of the two operands. */ | |
7663 | *total = 0; | |
7664 | return false; | |
7665 | } | |
7666 | } | |
7667 | ||
7668 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7669 | return false; | |
7670 | ||
7671 | case MULT: | |
7672 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7673 | return false; | |
7674 | ||
7675 | case NEG: | |
e0dc3601 PB |
7676 | if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
7677 | && (mode == SFmode || !TARGET_VFP_SINGLE)) | |
7ce8451d MG |
7678 | { |
7679 | *total = COSTS_N_INSNS (1); | |
7680 | return false; | |
7681 | } | |
7682 | ||
21b5653c RE |
7683 | /* Fall through */ |
7684 | case NOT: | |
7685 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7686 | ||
7687 | return false; | |
7688 | ||
7689 | case IF_THEN_ELSE: | |
7690 | *total = 0; | |
7691 | return false; | |
7692 | ||
7693 | case COMPARE: | |
7694 | if (cc_register (XEXP (x, 0), VOIDmode)) | |
7695 | * total = 0; | |
7696 | else | |
7697 | *total = COSTS_N_INSNS (1); | |
7698 | return false; | |
7699 | ||
7700 | case ABS: | |
e0dc3601 PB |
7701 | if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
7702 | && (mode == SFmode || !TARGET_VFP_SINGLE)) | |
21b5653c RE |
7703 | *total = COSTS_N_INSNS (1); |
7704 | else | |
7705 | *total = COSTS_N_INSNS (1 + ARM_NUM_REGS (mode)); | |
7706 | return false; | |
7707 | ||
7708 | case SIGN_EXTEND: | |
21b5653c | 7709 | case ZERO_EXTEND: |
e4c6a07a | 7710 | return arm_rtx_costs_1 (x, outer_code, total, 0); |
21b5653c | 7711 | |
f676971a EC |
7712 | case CONST_INT: |
7713 | if (const_ok_for_arm (INTVAL (x))) | |
6e782a29 KH |
7714 | /* A multiplication by a constant requires another instruction |
7715 | to load the constant to a register. */ | |
7716 | *total = COSTS_N_INSNS ((outer_code == SET || outer_code == MULT) | |
7717 | ? 1 : 0); | |
21b5653c RE |
7718 | else if (const_ok_for_arm (~INTVAL (x))) |
7719 | *total = COSTS_N_INSNS (outer_code == AND ? 0 : 1); | |
7720 | else if (const_ok_for_arm (-INTVAL (x))) | |
7721 | { | |
7722 | if (outer_code == COMPARE || outer_code == PLUS | |
7723 | || outer_code == MINUS) | |
7724 | *total = 0; | |
7725 | else | |
7726 | *total = COSTS_N_INSNS (1); | |
7727 | } | |
7728 | else | |
7729 | *total = COSTS_N_INSNS (2); | |
7730 | return true; | |
f676971a EC |
7731 | |
7732 | case CONST: | |
7733 | case LABEL_REF: | |
7734 | case SYMBOL_REF: | |
21b5653c RE |
7735 | *total = COSTS_N_INSNS (2); |
7736 | return true; | |
f676971a | 7737 | |
21b5653c RE |
7738 | case CONST_DOUBLE: |
7739 | *total = COSTS_N_INSNS (4); | |
7740 | return true; | |
7741 | ||
571191af PB |
7742 | case HIGH: |
7743 | case LO_SUM: | |
7744 | /* We prefer constant pool entries to MOVW/MOVT pairs, so bump the | |
7745 | cost of these slightly. */ | |
7746 | *total = COSTS_N_INSNS (1) + 1; | |
7747 | return true; | |
7748 | ||
21b5653c RE |
7749 | default: |
7750 | if (mode != VOIDmode) | |
7751 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7752 | else | |
7753 | *total = COSTS_N_INSNS (4); /* How knows? */ | |
7754 | return false; | |
7755 | } | |
7756 | } | |
7757 | ||
f40751dd JH |
7758 | /* RTX costs when optimizing for size. */ |
7759 | static bool | |
68f932c4 RS |
7760 | arm_rtx_costs (rtx x, int code, int outer_code, int opno ATTRIBUTE_UNUSED, |
7761 | int *total, bool speed) | |
f40751dd JH |
7762 | { |
7763 | if (!speed) | |
bbbbb16a ILT |
7764 | return arm_size_rtx_costs (x, (enum rtx_code) code, |
7765 | (enum rtx_code) outer_code, total); | |
f40751dd | 7766 | else |
1b78f575 RE |
7767 | return current_tune->rtx_costs (x, (enum rtx_code) code, |
7768 | (enum rtx_code) outer_code, | |
7769 | total, speed); | |
f40751dd JH |
7770 | } |
7771 | ||
5b3e6663 PB |
7772 | /* RTX costs for cores with a slow MUL implementation. Thumb-2 is not |
7773 | supported on any "slowmul" cores, so it can be ignored. */ | |
9b66ebb1 | 7774 | |
3c50106f | 7775 | static bool |
d5a0a47b RE |
7776 | arm_slowmul_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer_code, |
7777 | int *total, bool speed) | |
3c50106f | 7778 | { |
9b66ebb1 PB |
7779 | enum machine_mode mode = GET_MODE (x); |
7780 | ||
7781 | if (TARGET_THUMB) | |
7782 | { | |
5b3e6663 | 7783 | *total = thumb1_rtx_costs (x, code, outer_code); |
9b66ebb1 PB |
7784 | return true; |
7785 | } | |
f676971a | 7786 | |
9b66ebb1 PB |
7787 | switch (code) |
7788 | { | |
7789 | case MULT: | |
7790 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
7791 | || mode == DImode) | |
7792 | { | |
d5a0a47b RE |
7793 | *total = COSTS_N_INSNS (20); |
7794 | return false; | |
9b66ebb1 PB |
7795 | } |
7796 | ||
7797 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
7798 | { | |
7799 | unsigned HOST_WIDE_INT i = (INTVAL (XEXP (x, 1)) | |
7800 | & (unsigned HOST_WIDE_INT) 0xffffffff); | |
7801 | int cost, const_ok = const_ok_for_arm (i); | |
7802 | int j, booth_unit_size; | |
7803 | ||
f676971a | 7804 | /* Tune as appropriate. */ |
9b66ebb1 PB |
7805 | cost = const_ok ? 4 : 8; |
7806 | booth_unit_size = 2; | |
7807 | for (j = 0; i && j < 32; j += booth_unit_size) | |
7808 | { | |
7809 | i >>= booth_unit_size; | |
d5a0a47b | 7810 | cost++; |
9b66ebb1 PB |
7811 | } |
7812 | ||
d5a0a47b | 7813 | *total = COSTS_N_INSNS (cost); |
68f932c4 | 7814 | *total += rtx_cost (XEXP (x, 0), code, 0, speed); |
9b66ebb1 PB |
7815 | return true; |
7816 | } | |
7817 | ||
d5a0a47b RE |
7818 | *total = COSTS_N_INSNS (20); |
7819 | return false; | |
f676971a | 7820 | |
9b66ebb1 | 7821 | default: |
d5a0a47b | 7822 | return arm_rtx_costs_1 (x, outer_code, total, speed);; |
9b66ebb1 | 7823 | } |
3c50106f RH |
7824 | } |
7825 | ||
9b66ebb1 PB |
7826 | |
7827 | /* RTX cost for cores with a fast multiply unit (M variants). */ | |
7828 | ||
7829 | static bool | |
d5a0a47b RE |
7830 | arm_fastmul_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer_code, |
7831 | int *total, bool speed) | |
9b66ebb1 PB |
7832 | { |
7833 | enum machine_mode mode = GET_MODE (x); | |
7834 | ||
5b3e6663 | 7835 | if (TARGET_THUMB1) |
9b66ebb1 | 7836 | { |
5b3e6663 | 7837 | *total = thumb1_rtx_costs (x, code, outer_code); |
9b66ebb1 PB |
7838 | return true; |
7839 | } | |
f676971a | 7840 | |
5b3e6663 | 7841 | /* ??? should thumb2 use different costs? */ |
9b66ebb1 PB |
7842 | switch (code) |
7843 | { | |
7844 | case MULT: | |
7845 | /* There is no point basing this on the tuning, since it is always the | |
7846 | fast variant if it exists at all. */ | |
7847 | if (mode == DImode | |
7848 | && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1))) | |
7849 | && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND | |
7850 | || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)) | |
7851 | { | |
d5a0a47b RE |
7852 | *total = COSTS_N_INSNS(2); |
7853 | return false; | |
9b66ebb1 | 7854 | } |
f676971a | 7855 | |
9b66ebb1 | 7856 | |
d5a0a47b | 7857 | if (mode == DImode) |
9b66ebb1 | 7858 | { |
d5a0a47b RE |
7859 | *total = COSTS_N_INSNS (5); |
7860 | return false; | |
9b66ebb1 PB |
7861 | } |
7862 | ||
7863 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
7864 | { | |
7865 | unsigned HOST_WIDE_INT i = (INTVAL (XEXP (x, 1)) | |
7866 | & (unsigned HOST_WIDE_INT) 0xffffffff); | |
7867 | int cost, const_ok = const_ok_for_arm (i); | |
7868 | int j, booth_unit_size; | |
7869 | ||
f676971a | 7870 | /* Tune as appropriate. */ |
9b66ebb1 PB |
7871 | cost = const_ok ? 4 : 8; |
7872 | booth_unit_size = 8; | |
7873 | for (j = 0; i && j < 32; j += booth_unit_size) | |
7874 | { | |
7875 | i >>= booth_unit_size; | |
d5a0a47b | 7876 | cost++; |
9b66ebb1 PB |
7877 | } |
7878 | ||
d5a0a47b RE |
7879 | *total = COSTS_N_INSNS(cost); |
7880 | return false; | |
9b66ebb1 PB |
7881 | } |
7882 | ||
d5a0a47b RE |
7883 | if (mode == SImode) |
7884 | { | |
7885 | *total = COSTS_N_INSNS (4); | |
7886 | return false; | |
7887 | } | |
7888 | ||
7889 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
7890 | { | |
e0dc3601 PB |
7891 | if (TARGET_HARD_FLOAT |
7892 | && (mode == SFmode | |
7893 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
7894 | { |
7895 | *total = COSTS_N_INSNS (1); | |
7896 | return false; | |
7897 | } | |
7898 | } | |
7899 | ||
7900 | /* Requires a lib call */ | |
7901 | *total = COSTS_N_INSNS (20); | |
7902 | return false; | |
f676971a | 7903 | |
9b66ebb1 | 7904 | default: |
d5a0a47b | 7905 | return arm_rtx_costs_1 (x, outer_code, total, speed); |
9b66ebb1 PB |
7906 | } |
7907 | } | |
7908 | ||
7909 | ||
5b3e6663 PB |
7910 | /* RTX cost for XScale CPUs. Thumb-2 is not supported on any xscale cores, |
7911 | so it can be ignored. */ | |
9b66ebb1 PB |
7912 | |
7913 | static bool | |
1b78f575 RE |
7914 | arm_xscale_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer_code, |
7915 | int *total, bool speed) | |
9b66ebb1 PB |
7916 | { |
7917 | enum machine_mode mode = GET_MODE (x); | |
7918 | ||
7919 | if (TARGET_THUMB) | |
7920 | { | |
5b3e6663 | 7921 | *total = thumb1_rtx_costs (x, code, outer_code); |
9b66ebb1 PB |
7922 | return true; |
7923 | } | |
f676971a | 7924 | |
9b66ebb1 PB |
7925 | switch (code) |
7926 | { | |
d5a0a47b RE |
7927 | case COMPARE: |
7928 | if (GET_CODE (XEXP (x, 0)) != MULT) | |
7929 | return arm_rtx_costs_1 (x, outer_code, total, speed); | |
7930 | ||
7931 | /* A COMPARE of a MULT is slow on XScale; the muls instruction | |
7932 | will stall until the multiplication is complete. */ | |
7933 | *total = COSTS_N_INSNS (3); | |
7934 | return false; | |
7935 | ||
9b66ebb1 PB |
7936 | case MULT: |
7937 | /* There is no point basing this on the tuning, since it is always the | |
7938 | fast variant if it exists at all. */ | |
7939 | if (mode == DImode | |
7940 | && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1))) | |
7941 | && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND | |
7942 | || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)) | |
7943 | { | |
d5a0a47b RE |
7944 | *total = COSTS_N_INSNS (2); |
7945 | return false; | |
9b66ebb1 | 7946 | } |
f676971a | 7947 | |
9b66ebb1 | 7948 | |
d5a0a47b | 7949 | if (mode == DImode) |
9b66ebb1 | 7950 | { |
d5a0a47b RE |
7951 | *total = COSTS_N_INSNS (5); |
7952 | return false; | |
9b66ebb1 PB |
7953 | } |
7954 | ||
7955 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
7956 | { | |
d5a0a47b RE |
7957 | /* If operand 1 is a constant we can more accurately |
7958 | calculate the cost of the multiply. The multiplier can | |
7959 | retire 15 bits on the first cycle and a further 12 on the | |
7960 | second. We do, of course, have to load the constant into | |
7961 | a register first. */ | |
7962 | unsigned HOST_WIDE_INT i = INTVAL (XEXP (x, 1)); | |
7963 | /* There's a general overhead of one cycle. */ | |
7964 | int cost = 1; | |
9b66ebb1 PB |
7965 | unsigned HOST_WIDE_INT masked_const; |
7966 | ||
d5a0a47b RE |
7967 | if (i & 0x80000000) |
7968 | i = ~i; | |
7969 | ||
7970 | i &= (unsigned HOST_WIDE_INT) 0xffffffff; | |
7971 | ||
9b66ebb1 | 7972 | masked_const = i & 0xffff8000; |
d5a0a47b | 7973 | if (masked_const != 0) |
9b66ebb1 | 7974 | { |
d5a0a47b | 7975 | cost++; |
9b66ebb1 | 7976 | masked_const = i & 0xf8000000; |
d5a0a47b RE |
7977 | if (masked_const != 0) |
7978 | cost++; | |
9b66ebb1 | 7979 | } |
d5a0a47b RE |
7980 | *total = COSTS_N_INSNS (cost); |
7981 | return false; | |
9b66ebb1 PB |
7982 | } |
7983 | ||
d5a0a47b RE |
7984 | if (mode == SImode) |
7985 | { | |
7986 | *total = COSTS_N_INSNS (3); | |
7987 | return false; | |
7988 | } | |
f676971a | 7989 | |
d5a0a47b RE |
7990 | /* Requires a lib call */ |
7991 | *total = COSTS_N_INSNS (20); | |
7992 | return false; | |
06d5588c | 7993 | |
9b66ebb1 | 7994 | default: |
d5a0a47b | 7995 | return arm_rtx_costs_1 (x, outer_code, total, speed); |
9b66ebb1 PB |
7996 | } |
7997 | } | |
7998 | ||
7999 | ||
8000 | /* RTX costs for 9e (and later) cores. */ | |
8001 | ||
8002 | static bool | |
d5a0a47b RE |
8003 | arm_9e_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer_code, |
8004 | int *total, bool speed) | |
9b66ebb1 PB |
8005 | { |
8006 | enum machine_mode mode = GET_MODE (x); | |
f676971a | 8007 | |
5b3e6663 | 8008 | if (TARGET_THUMB1) |
9b66ebb1 PB |
8009 | { |
8010 | switch (code) | |
8011 | { | |
8012 | case MULT: | |
8013 | *total = COSTS_N_INSNS (3); | |
8014 | return true; | |
f676971a | 8015 | |
9b66ebb1 | 8016 | default: |
5b3e6663 | 8017 | *total = thumb1_rtx_costs (x, code, outer_code); |
9b66ebb1 PB |
8018 | return true; |
8019 | } | |
8020 | } | |
f676971a | 8021 | |
9b66ebb1 PB |
8022 | switch (code) |
8023 | { | |
8024 | case MULT: | |
8025 | /* There is no point basing this on the tuning, since it is always the | |
8026 | fast variant if it exists at all. */ | |
8027 | if (mode == DImode | |
8028 | && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1))) | |
8029 | && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND | |
8030 | || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)) | |
8031 | { | |
d5a0a47b RE |
8032 | *total = COSTS_N_INSNS (2); |
8033 | return false; | |
9b66ebb1 | 8034 | } |
f676971a | 8035 | |
9b66ebb1 | 8036 | |
9b66ebb1 PB |
8037 | if (mode == DImode) |
8038 | { | |
d5a0a47b RE |
8039 | *total = COSTS_N_INSNS (5); |
8040 | return false; | |
9b66ebb1 | 8041 | } |
d5a0a47b RE |
8042 | |
8043 | if (mode == SImode) | |
9b66ebb1 | 8044 | { |
d5a0a47b RE |
8045 | *total = COSTS_N_INSNS (2); |
8046 | return false; | |
9b66ebb1 PB |
8047 | } |
8048 | ||
d5a0a47b RE |
8049 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) |
8050 | { | |
e0dc3601 PB |
8051 | if (TARGET_HARD_FLOAT |
8052 | && (mode == SFmode | |
8053 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
8054 | { |
8055 | *total = COSTS_N_INSNS (1); | |
8056 | return false; | |
8057 | } | |
8058 | } | |
9b66ebb1 | 8059 | |
d5a0a47b RE |
8060 | *total = COSTS_N_INSNS (20); |
8061 | return false; | |
f676971a | 8062 | |
9b66ebb1 | 8063 | default: |
d5a0a47b | 8064 | return arm_rtx_costs_1 (x, outer_code, total, speed); |
9b66ebb1 PB |
8065 | } |
8066 | } | |
dcefdf67 RH |
8067 | /* All address computations that can be done are free, but rtx cost returns |
8068 | the same for practically all of them. So we weight the different types | |
8069 | of address here in the order (most pref first): | |
d6b4baa4 | 8070 | PRE/POST_INC/DEC, SHIFT or NON-INT sum, INT sum, REG, MEM or LABEL. */ |
d2b6eb76 ZW |
8071 | static inline int |
8072 | arm_arm_address_cost (rtx x) | |
8073 | { | |
8074 | enum rtx_code c = GET_CODE (x); | |
8075 | ||
8076 | if (c == PRE_INC || c == PRE_DEC || c == POST_INC || c == POST_DEC) | |
8077 | return 0; | |
8078 | if (c == MEM || c == LABEL_REF || c == SYMBOL_REF) | |
8079 | return 10; | |
8080 | ||
17eb4921 | 8081 | if (c == PLUS) |
d2b6eb76 | 8082 | { |
17eb4921 | 8083 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) |
d2b6eb76 ZW |
8084 | return 2; |
8085 | ||
ec8e098d | 8086 | if (ARITHMETIC_P (XEXP (x, 0)) || ARITHMETIC_P (XEXP (x, 1))) |
d2b6eb76 ZW |
8087 | return 3; |
8088 | ||
8089 | return 4; | |
8090 | } | |
8091 | ||
8092 | return 6; | |
8093 | } | |
8094 | ||
8095 | static inline int | |
8096 | arm_thumb_address_cost (rtx x) | |
8097 | { | |
8098 | enum rtx_code c = GET_CODE (x); | |
8099 | ||
8100 | if (c == REG) | |
8101 | return 1; | |
8102 | if (c == PLUS | |
8103 | && GET_CODE (XEXP (x, 0)) == REG | |
8104 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
8105 | return 1; | |
8106 | ||
8107 | return 2; | |
8108 | } | |
8109 | ||
dcefdf67 | 8110 | static int |
f40751dd | 8111 | arm_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED) |
dcefdf67 | 8112 | { |
5b3e6663 | 8113 | return TARGET_32BIT ? arm_arm_address_cost (x) : arm_thumb_address_cost (x); |
dcefdf67 | 8114 | } |
906668bb | 8115 | |
b0c13111 RR |
8116 | /* Adjust cost hook for XScale. */ |
8117 | static bool | |
8118 | xscale_sched_adjust_cost (rtx insn, rtx link, rtx dep, int * cost) | |
8119 | { | |
d19fb8e3 NC |
8120 | /* Some true dependencies can have a higher cost depending |
8121 | on precisely how certain input operands are used. */ | |
b0c13111 | 8122 | if (REG_NOTE_KIND(link) == 0 |
eda833e3 BE |
8123 | && recog_memoized (insn) >= 0 |
8124 | && recog_memoized (dep) >= 0) | |
d19fb8e3 NC |
8125 | { |
8126 | int shift_opnum = get_attr_shift (insn); | |
8127 | enum attr_type attr_type = get_attr_type (dep); | |
8128 | ||
8129 | /* If nonzero, SHIFT_OPNUM contains the operand number of a shifted | |
8130 | operand for INSN. If we have a shifted input operand and the | |
8131 | instruction we depend on is another ALU instruction, then we may | |
8132 | have to account for an additional stall. */ | |
9b66ebb1 PB |
8133 | if (shift_opnum != 0 |
8134 | && (attr_type == TYPE_ALU_SHIFT || attr_type == TYPE_ALU_SHIFT_REG)) | |
d19fb8e3 NC |
8135 | { |
8136 | rtx shifted_operand; | |
8137 | int opno; | |
f676971a | 8138 | |
d19fb8e3 NC |
8139 | /* Get the shifted operand. */ |
8140 | extract_insn (insn); | |
8141 | shifted_operand = recog_data.operand[shift_opnum]; | |
8142 | ||
8143 | /* Iterate over all the operands in DEP. If we write an operand | |
8144 | that overlaps with SHIFTED_OPERAND, then we have increase the | |
8145 | cost of this dependency. */ | |
8146 | extract_insn (dep); | |
8147 | preprocess_constraints (); | |
8148 | for (opno = 0; opno < recog_data.n_operands; opno++) | |
8149 | { | |
8150 | /* We can ignore strict inputs. */ | |
8151 | if (recog_data.operand_type[opno] == OP_IN) | |
8152 | continue; | |
8153 | ||
8154 | if (reg_overlap_mentioned_p (recog_data.operand[opno], | |
8155 | shifted_operand)) | |
b0c13111 RR |
8156 | { |
8157 | *cost = 2; | |
8158 | return false; | |
8159 | } | |
d19fb8e3 NC |
8160 | } |
8161 | } | |
8162 | } | |
b0c13111 RR |
8163 | return true; |
8164 | } | |
8165 | ||
8166 | /* Adjust cost hook for Cortex A9. */ | |
8167 | static bool | |
8168 | cortex_a9_sched_adjust_cost (rtx insn, rtx link, rtx dep, int * cost) | |
8169 | { | |
8170 | switch (REG_NOTE_KIND (link)) | |
8171 | { | |
8172 | case REG_DEP_ANTI: | |
8173 | *cost = 0; | |
8174 | return false; | |
8175 | ||
8176 | case REG_DEP_TRUE: | |
8177 | case REG_DEP_OUTPUT: | |
8178 | if (recog_memoized (insn) >= 0 | |
8179 | && recog_memoized (dep) >= 0) | |
8180 | { | |
8181 | if (GET_CODE (PATTERN (insn)) == SET) | |
8182 | { | |
8183 | if (GET_MODE_CLASS | |
8184 | (GET_MODE (SET_DEST (PATTERN (insn)))) == MODE_FLOAT | |
8185 | || GET_MODE_CLASS | |
8186 | (GET_MODE (SET_SRC (PATTERN (insn)))) == MODE_FLOAT) | |
8187 | { | |
8188 | enum attr_type attr_type_insn = get_attr_type (insn); | |
8189 | enum attr_type attr_type_dep = get_attr_type (dep); | |
8190 | ||
8191 | /* By default all dependencies of the form | |
8192 | s0 = s0 <op> s1 | |
8193 | s0 = s0 <op> s2 | |
8194 | have an extra latency of 1 cycle because | |
8195 | of the input and output dependency in this | |
8196 | case. However this gets modeled as an true | |
8197 | dependency and hence all these checks. */ | |
8198 | if (REG_P (SET_DEST (PATTERN (insn))) | |
8199 | && REG_P (SET_DEST (PATTERN (dep))) | |
8200 | && reg_overlap_mentioned_p (SET_DEST (PATTERN (insn)), | |
8201 | SET_DEST (PATTERN (dep)))) | |
8202 | { | |
8203 | /* FMACS is a special case where the dependant | |
8204 | instruction can be issued 3 cycles before | |
8205 | the normal latency in case of an output | |
8206 | dependency. */ | |
8207 | if ((attr_type_insn == TYPE_FMACS | |
8208 | || attr_type_insn == TYPE_FMACD) | |
8209 | && (attr_type_dep == TYPE_FMACS | |
8210 | || attr_type_dep == TYPE_FMACD)) | |
8211 | { | |
8212 | if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT) | |
8213 | *cost = insn_default_latency (dep) - 3; | |
8214 | else | |
8215 | *cost = insn_default_latency (dep); | |
8216 | return false; | |
8217 | } | |
8218 | else | |
8219 | { | |
8220 | if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT) | |
8221 | *cost = insn_default_latency (dep) + 1; | |
8222 | else | |
8223 | *cost = insn_default_latency (dep); | |
8224 | } | |
8225 | return false; | |
8226 | } | |
8227 | } | |
8228 | } | |
8229 | } | |
8230 | break; | |
8231 | ||
8232 | default: | |
8233 | gcc_unreachable (); | |
8234 | } | |
8235 | ||
8236 | return true; | |
8237 | } | |
8238 | ||
c02a5ccb SL |
8239 | /* Adjust cost hook for FA726TE. */ |
8240 | static bool | |
8241 | fa726te_sched_adjust_cost (rtx insn, rtx link, rtx dep, int * cost) | |
8242 | { | |
8243 | /* For FA726TE, true dependency on CPSR (i.e. set cond followed by predicated) | |
8244 | have penalty of 3. */ | |
8245 | if (REG_NOTE_KIND (link) == REG_DEP_TRUE | |
8246 | && recog_memoized (insn) >= 0 | |
8247 | && recog_memoized (dep) >= 0 | |
8248 | && get_attr_conds (dep) == CONDS_SET) | |
8249 | { | |
8250 | /* Use of carry (e.g. 64-bit arithmetic) in ALU: 3-cycle latency. */ | |
8251 | if (get_attr_conds (insn) == CONDS_USE | |
8252 | && get_attr_type (insn) != TYPE_BRANCH) | |
8253 | { | |
8254 | *cost = 3; | |
8255 | return false; | |
8256 | } | |
8257 | ||
8258 | if (GET_CODE (PATTERN (insn)) == COND_EXEC | |
8259 | || get_attr_conds (insn) == CONDS_USE) | |
8260 | { | |
8261 | *cost = 0; | |
8262 | return false; | |
8263 | } | |
8264 | } | |
8265 | ||
8266 | return true; | |
8267 | } | |
8268 | ||
b0c13111 RR |
8269 | /* This function implements the target macro TARGET_SCHED_ADJUST_COST. |
8270 | It corrects the value of COST based on the relationship between | |
8271 | INSN and DEP through the dependence LINK. It returns the new | |
8272 | value. There is a per-core adjust_cost hook to adjust scheduler costs | |
8273 | and the per-core hook can choose to completely override the generic | |
8274 | adjust_cost function. Only put bits of code into arm_adjust_cost that | |
8275 | are common across all cores. */ | |
8276 | static int | |
8277 | arm_adjust_cost (rtx insn, rtx link, rtx dep, int cost) | |
8278 | { | |
8279 | rtx i_pat, d_pat; | |
8280 | ||
8281 | /* When generating Thumb-1 code, we want to place flag-setting operations | |
8282 | close to a conditional branch which depends on them, so that we can | |
8283 | omit the comparison. */ | |
8284 | if (TARGET_THUMB1 | |
8285 | && REG_NOTE_KIND (link) == 0 | |
8286 | && recog_memoized (insn) == CODE_FOR_cbranchsi4_insn | |
8287 | && recog_memoized (dep) >= 0 | |
8288 | && get_attr_conds (dep) == CONDS_SET) | |
8289 | return 0; | |
8290 | ||
8291 | if (current_tune->sched_adjust_cost != NULL) | |
8292 | { | |
8293 | if (!current_tune->sched_adjust_cost (insn, link, dep, &cost)) | |
8294 | return cost; | |
8295 | } | |
d19fb8e3 | 8296 | |
6354dc9b | 8297 | /* XXX This is not strictly true for the FPA. */ |
d5b7b3ae RE |
8298 | if (REG_NOTE_KIND (link) == REG_DEP_ANTI |
8299 | || REG_NOTE_KIND (link) == REG_DEP_OUTPUT) | |
b36ba79f RE |
8300 | return 0; |
8301 | ||
d5b7b3ae RE |
8302 | /* Call insns don't incur a stall, even if they follow a load. */ |
8303 | if (REG_NOTE_KIND (link) == 0 | |
8304 | && GET_CODE (insn) == CALL_INSN) | |
8305 | return 1; | |
8306 | ||
32de079a RE |
8307 | if ((i_pat = single_set (insn)) != NULL |
8308 | && GET_CODE (SET_SRC (i_pat)) == MEM | |
8309 | && (d_pat = single_set (dep)) != NULL | |
8310 | && GET_CODE (SET_DEST (d_pat)) == MEM) | |
8311 | { | |
48f6efae | 8312 | rtx src_mem = XEXP (SET_SRC (i_pat), 0); |
32de079a RE |
8313 | /* This is a load after a store, there is no conflict if the load reads |
8314 | from a cached area. Assume that loads from the stack, and from the | |
f676971a | 8315 | constant pool are cached, and that others will miss. This is a |
6354dc9b | 8316 | hack. */ |
f676971a | 8317 | |
b0c13111 RR |
8318 | if ((GET_CODE (src_mem) == SYMBOL_REF |
8319 | && CONSTANT_POOL_ADDRESS_P (src_mem)) | |
48f6efae NC |
8320 | || reg_mentioned_p (stack_pointer_rtx, src_mem) |
8321 | || reg_mentioned_p (frame_pointer_rtx, src_mem) | |
8322 | || reg_mentioned_p (hard_frame_pointer_rtx, src_mem)) | |
949d79eb | 8323 | return 1; |
32de079a RE |
8324 | } |
8325 | ||
8326 | return cost; | |
8327 | } | |
8328 | ||
153668ec JB |
8329 | static int |
8330 | arm_default_branch_cost (bool speed_p, bool predictable_p ATTRIBUTE_UNUSED) | |
8331 | { | |
8332 | if (TARGET_32BIT) | |
8333 | return (TARGET_THUMB2 && !speed_p) ? 1 : 4; | |
8334 | else | |
8335 | return (optimize > 0) ? 2 : 0; | |
8336 | } | |
8337 | ||
288f605f JB |
8338 | static int |
8339 | arm_cortex_a5_branch_cost (bool speed_p, bool predictable_p) | |
8340 | { | |
8341 | return speed_p ? 0 : arm_default_branch_cost (speed_p, predictable_p); | |
8342 | } | |
8343 | ||
9b66ebb1 | 8344 | static int fp_consts_inited = 0; |
ff9940b0 | 8345 | |
9b66ebb1 PB |
8346 | /* Only zero is valid for VFP. Other values are also valid for FPA. */ |
8347 | static const char * const strings_fp[8] = | |
62b10bbc | 8348 | { |
2b835d68 RE |
8349 | "0", "1", "2", "3", |
8350 | "4", "5", "0.5", "10" | |
8351 | }; | |
ff9940b0 | 8352 | |
9b66ebb1 | 8353 | static REAL_VALUE_TYPE values_fp[8]; |
ff9940b0 RE |
8354 | |
8355 | static void | |
9b66ebb1 | 8356 | init_fp_table (void) |
ff9940b0 RE |
8357 | { |
8358 | int i; | |
8359 | REAL_VALUE_TYPE r; | |
8360 | ||
9b66ebb1 PB |
8361 | if (TARGET_VFP) |
8362 | fp_consts_inited = 1; | |
8363 | else | |
8364 | fp_consts_inited = 8; | |
8365 | ||
8366 | for (i = 0; i < fp_consts_inited; i++) | |
ff9940b0 | 8367 | { |
9b66ebb1 PB |
8368 | r = REAL_VALUE_ATOF (strings_fp[i], DFmode); |
8369 | values_fp[i] = r; | |
ff9940b0 | 8370 | } |
ff9940b0 RE |
8371 | } |
8372 | ||
9b66ebb1 | 8373 | /* Return TRUE if rtx X is a valid immediate FP constant. */ |
cce8749e | 8374 | int |
9b66ebb1 | 8375 | arm_const_double_rtx (rtx x) |
cce8749e | 8376 | { |
ff9940b0 RE |
8377 | REAL_VALUE_TYPE r; |
8378 | int i; | |
f676971a | 8379 | |
9b66ebb1 PB |
8380 | if (!fp_consts_inited) |
8381 | init_fp_table (); | |
f676971a | 8382 | |
ff9940b0 RE |
8383 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); |
8384 | if (REAL_VALUE_MINUS_ZERO (r)) | |
8385 | return 0; | |
f3bb6135 | 8386 | |
9b66ebb1 PB |
8387 | for (i = 0; i < fp_consts_inited; i++) |
8388 | if (REAL_VALUES_EQUAL (r, values_fp[i])) | |
ff9940b0 | 8389 | return 1; |
f3bb6135 | 8390 | |
ff9940b0 | 8391 | return 0; |
f3bb6135 | 8392 | } |
ff9940b0 | 8393 | |
3b684012 | 8394 | /* Return TRUE if rtx X is a valid immediate FPA constant. */ |
ff9940b0 | 8395 | int |
e32bac5b | 8396 | neg_const_double_rtx_ok_for_fpa (rtx x) |
ff9940b0 RE |
8397 | { |
8398 | REAL_VALUE_TYPE r; | |
8399 | int i; | |
f676971a | 8400 | |
9b66ebb1 PB |
8401 | if (!fp_consts_inited) |
8402 | init_fp_table (); | |
f676971a | 8403 | |
ff9940b0 | 8404 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); |
d49b6e1e | 8405 | r = real_value_negate (&r); |
ff9940b0 RE |
8406 | if (REAL_VALUE_MINUS_ZERO (r)) |
8407 | return 0; | |
f3bb6135 | 8408 | |
ff9940b0 | 8409 | for (i = 0; i < 8; i++) |
9b66ebb1 | 8410 | if (REAL_VALUES_EQUAL (r, values_fp[i])) |
ff9940b0 | 8411 | return 1; |
f3bb6135 | 8412 | |
ff9940b0 | 8413 | return 0; |
f3bb6135 | 8414 | } |
f1adb0a9 JB |
8415 | |
8416 | ||
8417 | /* VFPv3 has a fairly wide range of representable immediates, formed from | |
8418 | "quarter-precision" floating-point values. These can be evaluated using this | |
8419 | formula (with ^ for exponentiation): | |
8420 | ||
8421 | -1^s * n * 2^-r | |
8422 | ||
8423 | Where 's' is a sign bit (0/1), 'n' and 'r' are integers such that | |
8424 | 16 <= n <= 31 and 0 <= r <= 7. | |
8425 | ||
8426 | These values are mapped onto an 8-bit integer ABCDEFGH s.t. | |
8427 | ||
8428 | - A (most-significant) is the sign bit. | |
8429 | - BCD are the exponent (encoded as r XOR 3). | |
8430 | - EFGH are the mantissa (encoded as n - 16). | |
8431 | */ | |
8432 | ||
8433 | /* Return an integer index for a VFPv3 immediate operand X suitable for the | |
8434 | fconst[sd] instruction, or -1 if X isn't suitable. */ | |
8435 | static int | |
8436 | vfp3_const_double_index (rtx x) | |
8437 | { | |
8438 | REAL_VALUE_TYPE r, m; | |
8439 | int sign, exponent; | |
8440 | unsigned HOST_WIDE_INT mantissa, mant_hi; | |
8441 | unsigned HOST_WIDE_INT mask; | |
8e39e9af | 8442 | HOST_WIDE_INT m1, m2; |
f1adb0a9 JB |
8443 | int point_pos = 2 * HOST_BITS_PER_WIDE_INT - 1; |
8444 | ||
8445 | if (!TARGET_VFP3 || GET_CODE (x) != CONST_DOUBLE) | |
8446 | return -1; | |
8447 | ||
8448 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); | |
8449 | ||
8450 | /* We can't represent these things, so detect them first. */ | |
8451 | if (REAL_VALUE_ISINF (r) || REAL_VALUE_ISNAN (r) || REAL_VALUE_MINUS_ZERO (r)) | |
8452 | return -1; | |
8453 | ||
8454 | /* Extract sign, exponent and mantissa. */ | |
8455 | sign = REAL_VALUE_NEGATIVE (r) ? 1 : 0; | |
d49b6e1e | 8456 | r = real_value_abs (&r); |
f1adb0a9 JB |
8457 | exponent = REAL_EXP (&r); |
8458 | /* For the mantissa, we expand into two HOST_WIDE_INTS, apart from the | |
8459 | highest (sign) bit, with a fixed binary point at bit point_pos. | |
8460 | WARNING: If there's ever a VFP version which uses more than 2 * H_W_I - 1 | |
8461 | bits for the mantissa, this may fail (low bits would be lost). */ | |
8462 | real_ldexp (&m, &r, point_pos - exponent); | |
8e39e9af RE |
8463 | REAL_VALUE_TO_INT (&m1, &m2, m); |
8464 | mantissa = m1; | |
8465 | mant_hi = m2; | |
f1adb0a9 JB |
8466 | |
8467 | /* If there are bits set in the low part of the mantissa, we can't | |
8468 | represent this value. */ | |
8469 | if (mantissa != 0) | |
8470 | return -1; | |
8471 | ||
8472 | /* Now make it so that mantissa contains the most-significant bits, and move | |
8473 | the point_pos to indicate that the least-significant bits have been | |
8474 | discarded. */ | |
8475 | point_pos -= HOST_BITS_PER_WIDE_INT; | |
8476 | mantissa = mant_hi; | |
8477 | ||
8478 | /* We can permit four significant bits of mantissa only, plus a high bit | |
8479 | which is always 1. */ | |
8480 | mask = ((unsigned HOST_WIDE_INT)1 << (point_pos - 5)) - 1; | |
8481 | if ((mantissa & mask) != 0) | |
8482 | return -1; | |
8483 | ||
8484 | /* Now we know the mantissa is in range, chop off the unneeded bits. */ | |
8485 | mantissa >>= point_pos - 5; | |
8486 | ||
8487 | /* The mantissa may be zero. Disallow that case. (It's possible to load the | |
8488 | floating-point immediate zero with Neon using an integer-zero load, but | |
8489 | that case is handled elsewhere.) */ | |
8490 | if (mantissa == 0) | |
8491 | return -1; | |
8492 | ||
8493 | gcc_assert (mantissa >= 16 && mantissa <= 31); | |
8494 | ||
8495 | /* The value of 5 here would be 4 if GCC used IEEE754-like encoding (where | |
6ed3da00 KH |
8496 | normalized significands are in the range [1, 2). (Our mantissa is shifted |
8497 | left 4 places at this point relative to normalized IEEE754 values). GCC | |
f1adb0a9 JB |
8498 | internally uses [0.5, 1) (see real.c), so the exponent returned from |
8499 | REAL_EXP must be altered. */ | |
8500 | exponent = 5 - exponent; | |
8501 | ||
8502 | if (exponent < 0 || exponent > 7) | |
8503 | return -1; | |
8504 | ||
8505 | /* Sign, mantissa and exponent are now in the correct form to plug into the | |
15dc95cb | 8506 | formula described in the comment above. */ |
f1adb0a9 JB |
8507 | return (sign << 7) | ((exponent ^ 3) << 4) | (mantissa - 16); |
8508 | } | |
8509 | ||
8510 | /* Return TRUE if rtx X is a valid immediate VFPv3 constant. */ | |
8511 | int | |
8512 | vfp3_const_double_rtx (rtx x) | |
8513 | { | |
8514 | if (!TARGET_VFP3) | |
8515 | return 0; | |
8516 | ||
8517 | return vfp3_const_double_index (x) != -1; | |
8518 | } | |
8519 | ||
88f77cba JB |
8520 | /* Recognize immediates which can be used in various Neon instructions. Legal |
8521 | immediates are described by the following table (for VMVN variants, the | |
8522 | bitwise inverse of the constant shown is recognized. In either case, VMOV | |
8523 | is output and the correct instruction to use for a given constant is chosen | |
8524 | by the assembler). The constant shown is replicated across all elements of | |
8525 | the destination vector. | |
8526 | ||
8527 | insn elems variant constant (binary) | |
8528 | ---- ----- ------- ----------------- | |
8529 | vmov i32 0 00000000 00000000 00000000 abcdefgh | |
8530 | vmov i32 1 00000000 00000000 abcdefgh 00000000 | |
8531 | vmov i32 2 00000000 abcdefgh 00000000 00000000 | |
8532 | vmov i32 3 abcdefgh 00000000 00000000 00000000 | |
8533 | vmov i16 4 00000000 abcdefgh | |
8534 | vmov i16 5 abcdefgh 00000000 | |
8535 | vmvn i32 6 00000000 00000000 00000000 abcdefgh | |
8536 | vmvn i32 7 00000000 00000000 abcdefgh 00000000 | |
8537 | vmvn i32 8 00000000 abcdefgh 00000000 00000000 | |
8538 | vmvn i32 9 abcdefgh 00000000 00000000 00000000 | |
8539 | vmvn i16 10 00000000 abcdefgh | |
8540 | vmvn i16 11 abcdefgh 00000000 | |
8541 | vmov i32 12 00000000 00000000 abcdefgh 11111111 | |
8542 | vmvn i32 13 00000000 00000000 abcdefgh 11111111 | |
8543 | vmov i32 14 00000000 abcdefgh 11111111 11111111 | |
8544 | vmvn i32 15 00000000 abcdefgh 11111111 11111111 | |
8545 | vmov i8 16 abcdefgh | |
8546 | vmov i64 17 aaaaaaaa bbbbbbbb cccccccc dddddddd | |
8547 | eeeeeeee ffffffff gggggggg hhhhhhhh | |
8548 | vmov f32 18 aBbbbbbc defgh000 00000000 00000000 | |
8549 | ||
8550 | For case 18, B = !b. Representable values are exactly those accepted by | |
8551 | vfp3_const_double_index, but are output as floating-point numbers rather | |
8552 | than indices. | |
8553 | ||
8554 | Variants 0-5 (inclusive) may also be used as immediates for the second | |
8555 | operand of VORR/VBIC instructions. | |
8556 | ||
8557 | The INVERSE argument causes the bitwise inverse of the given operand to be | |
8558 | recognized instead (used for recognizing legal immediates for the VAND/VORN | |
8559 | pseudo-instructions). If INVERSE is true, the value placed in *MODCONST is | |
8560 | *not* inverted (i.e. the pseudo-instruction forms vand/vorn should still be | |
8561 | output, rather than the real insns vbic/vorr). | |
8562 | ||
8563 | INVERSE makes no difference to the recognition of float vectors. | |
8564 | ||
8565 | The return value is the variant of immediate as shown in the above table, or | |
8566 | -1 if the given value doesn't match any of the listed patterns. | |
8567 | */ | |
8568 | static int | |
8569 | neon_valid_immediate (rtx op, enum machine_mode mode, int inverse, | |
8570 | rtx *modconst, int *elementwidth) | |
8571 | { | |
8572 | #define CHECK(STRIDE, ELSIZE, CLASS, TEST) \ | |
8573 | matches = 1; \ | |
8574 | for (i = 0; i < idx; i += (STRIDE)) \ | |
8575 | if (!(TEST)) \ | |
8576 | matches = 0; \ | |
8577 | if (matches) \ | |
8578 | { \ | |
8579 | immtype = (CLASS); \ | |
8580 | elsize = (ELSIZE); \ | |
8581 | break; \ | |
8582 | } | |
8583 | ||
ff128632 | 8584 | unsigned int i, elsize = 0, idx = 0, n_elts = CONST_VECTOR_NUNITS (op); |
88f77cba JB |
8585 | unsigned int innersize = GET_MODE_SIZE (GET_MODE_INNER (mode)); |
8586 | unsigned char bytes[16]; | |
8587 | int immtype = -1, matches; | |
8588 | unsigned int invmask = inverse ? 0xff : 0; | |
8589 | ||
8590 | /* Vectors of float constants. */ | |
8591 | if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT) | |
8592 | { | |
8593 | rtx el0 = CONST_VECTOR_ELT (op, 0); | |
8594 | REAL_VALUE_TYPE r0; | |
8595 | ||
8596 | if (!vfp3_const_double_rtx (el0)) | |
8597 | return -1; | |
8598 | ||
8599 | REAL_VALUE_FROM_CONST_DOUBLE (r0, el0); | |
8600 | ||
8601 | for (i = 1; i < n_elts; i++) | |
8602 | { | |
8603 | rtx elt = CONST_VECTOR_ELT (op, i); | |
8604 | REAL_VALUE_TYPE re; | |
8605 | ||
8606 | REAL_VALUE_FROM_CONST_DOUBLE (re, elt); | |
8607 | ||
8608 | if (!REAL_VALUES_EQUAL (r0, re)) | |
8609 | return -1; | |
8610 | } | |
8611 | ||
8612 | if (modconst) | |
8613 | *modconst = CONST_VECTOR_ELT (op, 0); | |
8614 | ||
8615 | if (elementwidth) | |
8616 | *elementwidth = 0; | |
8617 | ||
8618 | return 18; | |
8619 | } | |
8620 | ||
8621 | /* Splat vector constant out into a byte vector. */ | |
8622 | for (i = 0; i < n_elts; i++) | |
8623 | { | |
8624 | rtx el = CONST_VECTOR_ELT (op, i); | |
8625 | unsigned HOST_WIDE_INT elpart; | |
8626 | unsigned int part, parts; | |
8627 | ||
8628 | if (GET_CODE (el) == CONST_INT) | |
8629 | { | |
8630 | elpart = INTVAL (el); | |
8631 | parts = 1; | |
8632 | } | |
8633 | else if (GET_CODE (el) == CONST_DOUBLE) | |
8634 | { | |
8635 | elpart = CONST_DOUBLE_LOW (el); | |
8636 | parts = 2; | |
8637 | } | |
8638 | else | |
8639 | gcc_unreachable (); | |
8640 | ||
8641 | for (part = 0; part < parts; part++) | |
8642 | { | |
8643 | unsigned int byte; | |
8644 | for (byte = 0; byte < innersize; byte++) | |
8645 | { | |
8646 | bytes[idx++] = (elpart & 0xff) ^ invmask; | |
8647 | elpart >>= BITS_PER_UNIT; | |
8648 | } | |
8649 | if (GET_CODE (el) == CONST_DOUBLE) | |
8650 | elpart = CONST_DOUBLE_HIGH (el); | |
8651 | } | |
8652 | } | |
8653 | ||
8654 | /* Sanity check. */ | |
8655 | gcc_assert (idx == GET_MODE_SIZE (mode)); | |
8656 | ||
8657 | do | |
8658 | { | |
8659 | CHECK (4, 32, 0, bytes[i] == bytes[0] && bytes[i + 1] == 0 | |
8660 | && bytes[i + 2] == 0 && bytes[i + 3] == 0); | |
8661 | ||
8662 | CHECK (4, 32, 1, bytes[i] == 0 && bytes[i + 1] == bytes[1] | |
8663 | && bytes[i + 2] == 0 && bytes[i + 3] == 0); | |
8664 | ||
8665 | CHECK (4, 32, 2, bytes[i] == 0 && bytes[i + 1] == 0 | |
8666 | && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0); | |
8667 | ||
8668 | CHECK (4, 32, 3, bytes[i] == 0 && bytes[i + 1] == 0 | |
8669 | && bytes[i + 2] == 0 && bytes[i + 3] == bytes[3]); | |
8670 | ||
8671 | CHECK (2, 16, 4, bytes[i] == bytes[0] && bytes[i + 1] == 0); | |
8672 | ||
8673 | CHECK (2, 16, 5, bytes[i] == 0 && bytes[i + 1] == bytes[1]); | |
8674 | ||
8675 | CHECK (4, 32, 6, bytes[i] == bytes[0] && bytes[i + 1] == 0xff | |
8676 | && bytes[i + 2] == 0xff && bytes[i + 3] == 0xff); | |
8677 | ||
8678 | CHECK (4, 32, 7, bytes[i] == 0xff && bytes[i + 1] == bytes[1] | |
8679 | && bytes[i + 2] == 0xff && bytes[i + 3] == 0xff); | |
8680 | ||
8681 | CHECK (4, 32, 8, bytes[i] == 0xff && bytes[i + 1] == 0xff | |
8682 | && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0xff); | |
8683 | ||
8684 | CHECK (4, 32, 9, bytes[i] == 0xff && bytes[i + 1] == 0xff | |
8685 | && bytes[i + 2] == 0xff && bytes[i + 3] == bytes[3]); | |
8686 | ||
8687 | CHECK (2, 16, 10, bytes[i] == bytes[0] && bytes[i + 1] == 0xff); | |
8688 | ||
8689 | CHECK (2, 16, 11, bytes[i] == 0xff && bytes[i + 1] == bytes[1]); | |
8690 | ||
8691 | CHECK (4, 32, 12, bytes[i] == 0xff && bytes[i + 1] == bytes[1] | |
8692 | && bytes[i + 2] == 0 && bytes[i + 3] == 0); | |
8693 | ||
8694 | CHECK (4, 32, 13, bytes[i] == 0 && bytes[i + 1] == bytes[1] | |
8695 | && bytes[i + 2] == 0xff && bytes[i + 3] == 0xff); | |
8696 | ||
8697 | CHECK (4, 32, 14, bytes[i] == 0xff && bytes[i + 1] == 0xff | |
8698 | && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0); | |
8699 | ||
8700 | CHECK (4, 32, 15, bytes[i] == 0 && bytes[i + 1] == 0 | |
8701 | && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0xff); | |
8702 | ||
8703 | CHECK (1, 8, 16, bytes[i] == bytes[0]); | |
8704 | ||
8705 | CHECK (1, 64, 17, (bytes[i] == 0 || bytes[i] == 0xff) | |
8706 | && bytes[i] == bytes[(i + 8) % idx]); | |
8707 | } | |
8708 | while (0); | |
8709 | ||
8710 | if (immtype == -1) | |
8711 | return -1; | |
8712 | ||
8713 | if (elementwidth) | |
8714 | *elementwidth = elsize; | |
8715 | ||
8716 | if (modconst) | |
8717 | { | |
8718 | unsigned HOST_WIDE_INT imm = 0; | |
8719 | ||
cea618ac | 8720 | /* Un-invert bytes of recognized vector, if necessary. */ |
88f77cba JB |
8721 | if (invmask != 0) |
8722 | for (i = 0; i < idx; i++) | |
8723 | bytes[i] ^= invmask; | |
8724 | ||
8725 | if (immtype == 17) | |
8726 | { | |
8727 | /* FIXME: Broken on 32-bit H_W_I hosts. */ | |
8728 | gcc_assert (sizeof (HOST_WIDE_INT) == 8); | |
8729 | ||
8730 | for (i = 0; i < 8; i++) | |
8731 | imm |= (unsigned HOST_WIDE_INT) (bytes[i] ? 0xff : 0) | |
8732 | << (i * BITS_PER_UNIT); | |
8733 | ||
8734 | *modconst = GEN_INT (imm); | |
8735 | } | |
8736 | else | |
8737 | { | |
8738 | unsigned HOST_WIDE_INT imm = 0; | |
8739 | ||
8740 | for (i = 0; i < elsize / BITS_PER_UNIT; i++) | |
8741 | imm |= (unsigned HOST_WIDE_INT) bytes[i] << (i * BITS_PER_UNIT); | |
8742 | ||
8743 | *modconst = GEN_INT (imm); | |
8744 | } | |
8745 | } | |
8746 | ||
8747 | return immtype; | |
8748 | #undef CHECK | |
8749 | } | |
8750 | ||
8751 | /* Return TRUE if rtx X is legal for use as either a Neon VMOV (or, implicitly, | |
8752 | VMVN) immediate. Write back width per element to *ELEMENTWIDTH (or zero for | |
8753 | float elements), and a modified constant (whatever should be output for a | |
8754 | VMOV) in *MODCONST. */ | |
8755 | ||
8756 | int | |
8757 | neon_immediate_valid_for_move (rtx op, enum machine_mode mode, | |
8758 | rtx *modconst, int *elementwidth) | |
8759 | { | |
8760 | rtx tmpconst; | |
8761 | int tmpwidth; | |
8762 | int retval = neon_valid_immediate (op, mode, 0, &tmpconst, &tmpwidth); | |
8763 | ||
8764 | if (retval == -1) | |
8765 | return 0; | |
8766 | ||
8767 | if (modconst) | |
8768 | *modconst = tmpconst; | |
8769 | ||
8770 | if (elementwidth) | |
8771 | *elementwidth = tmpwidth; | |
8772 | ||
8773 | return 1; | |
8774 | } | |
8775 | ||
8776 | /* Return TRUE if rtx X is legal for use in a VORR or VBIC instruction. If | |
8777 | the immediate is valid, write a constant suitable for using as an operand | |
8778 | to VORR/VBIC/VAND/VORN to *MODCONST and the corresponding element width to | |
8779 | *ELEMENTWIDTH. See neon_valid_immediate for description of INVERSE. */ | |
8780 | ||
8781 | int | |
8782 | neon_immediate_valid_for_logic (rtx op, enum machine_mode mode, int inverse, | |
8783 | rtx *modconst, int *elementwidth) | |
8784 | { | |
8785 | rtx tmpconst; | |
8786 | int tmpwidth; | |
8787 | int retval = neon_valid_immediate (op, mode, inverse, &tmpconst, &tmpwidth); | |
8788 | ||
8789 | if (retval < 0 || retval > 5) | |
8790 | return 0; | |
8791 | ||
8792 | if (modconst) | |
8793 | *modconst = tmpconst; | |
8794 | ||
8795 | if (elementwidth) | |
8796 | *elementwidth = tmpwidth; | |
8797 | ||
8798 | return 1; | |
8799 | } | |
8800 | ||
31a0c825 DP |
8801 | /* Return TRUE if rtx OP is legal for use in a VSHR or VSHL instruction. If |
8802 | the immediate is valid, write a constant suitable for using as an operand | |
8803 | to VSHR/VSHL to *MODCONST and the corresponding element width to | |
8804 | *ELEMENTWIDTH. ISLEFTSHIFT is for determine left or right shift, | |
8805 | because they have different limitations. */ | |
8806 | ||
8807 | int | |
8808 | neon_immediate_valid_for_shift (rtx op, enum machine_mode mode, | |
8809 | rtx *modconst, int *elementwidth, | |
8810 | bool isleftshift) | |
8811 | { | |
8812 | unsigned int innersize = GET_MODE_SIZE (GET_MODE_INNER (mode)); | |
8813 | unsigned int n_elts = CONST_VECTOR_NUNITS (op), i; | |
8814 | unsigned HOST_WIDE_INT last_elt = 0; | |
8815 | unsigned HOST_WIDE_INT maxshift; | |
8816 | ||
8817 | /* Split vector constant out into a byte vector. */ | |
8818 | for (i = 0; i < n_elts; i++) | |
8819 | { | |
8820 | rtx el = CONST_VECTOR_ELT (op, i); | |
8821 | unsigned HOST_WIDE_INT elpart; | |
8822 | ||
8823 | if (GET_CODE (el) == CONST_INT) | |
8824 | elpart = INTVAL (el); | |
8825 | else if (GET_CODE (el) == CONST_DOUBLE) | |
8826 | return 0; | |
8827 | else | |
8828 | gcc_unreachable (); | |
8829 | ||
8830 | if (i != 0 && elpart != last_elt) | |
8831 | return 0; | |
8832 | ||
8833 | last_elt = elpart; | |
8834 | } | |
8835 | ||
8836 | /* Shift less than element size. */ | |
8837 | maxshift = innersize * 8; | |
8838 | ||
8839 | if (isleftshift) | |
8840 | { | |
8841 | /* Left shift immediate value can be from 0 to <size>-1. */ | |
8842 | if (last_elt >= maxshift) | |
8843 | return 0; | |
8844 | } | |
8845 | else | |
8846 | { | |
8847 | /* Right shift immediate value can be from 1 to <size>. */ | |
8848 | if (last_elt == 0 || last_elt > maxshift) | |
8849 | return 0; | |
8850 | } | |
8851 | ||
8852 | if (elementwidth) | |
8853 | *elementwidth = innersize * 8; | |
8854 | ||
8855 | if (modconst) | |
8856 | *modconst = CONST_VECTOR_ELT (op, 0); | |
8857 | ||
8858 | return 1; | |
8859 | } | |
8860 | ||
88f77cba JB |
8861 | /* Return a string suitable for output of Neon immediate logic operation |
8862 | MNEM. */ | |
8863 | ||
8864 | char * | |
8865 | neon_output_logic_immediate (const char *mnem, rtx *op2, enum machine_mode mode, | |
8866 | int inverse, int quad) | |
8867 | { | |
8868 | int width, is_valid; | |
8869 | static char templ[40]; | |
8870 | ||
8871 | is_valid = neon_immediate_valid_for_logic (*op2, mode, inverse, op2, &width); | |
8872 | ||
8873 | gcc_assert (is_valid != 0); | |
8874 | ||
8875 | if (quad) | |
8876 | sprintf (templ, "%s.i%d\t%%q0, %%2", mnem, width); | |
8877 | else | |
8878 | sprintf (templ, "%s.i%d\t%%P0, %%2", mnem, width); | |
8879 | ||
8880 | return templ; | |
8881 | } | |
8882 | ||
31a0c825 DP |
8883 | /* Return a string suitable for output of Neon immediate shift operation |
8884 | (VSHR or VSHL) MNEM. */ | |
8885 | ||
8886 | char * | |
8887 | neon_output_shift_immediate (const char *mnem, char sign, rtx *op2, | |
8888 | enum machine_mode mode, int quad, | |
8889 | bool isleftshift) | |
8890 | { | |
8891 | int width, is_valid; | |
8892 | static char templ[40]; | |
8893 | ||
8894 | is_valid = neon_immediate_valid_for_shift (*op2, mode, op2, &width, isleftshift); | |
8895 | gcc_assert (is_valid != 0); | |
8896 | ||
8897 | if (quad) | |
8898 | sprintf (templ, "%s.%c%d\t%%q0, %%q1, %%2", mnem, sign, width); | |
8899 | else | |
8900 | sprintf (templ, "%s.%c%d\t%%P0, %%P1, %%2", mnem, sign, width); | |
8901 | ||
8902 | return templ; | |
8903 | } | |
8904 | ||
88f77cba JB |
8905 | /* Output a sequence of pairwise operations to implement a reduction. |
8906 | NOTE: We do "too much work" here, because pairwise operations work on two | |
8907 | registers-worth of operands in one go. Unfortunately we can't exploit those | |
8908 | extra calculations to do the full operation in fewer steps, I don't think. | |
8909 | Although all vector elements of the result but the first are ignored, we | |
8910 | actually calculate the same result in each of the elements. An alternative | |
8911 | such as initially loading a vector with zero to use as each of the second | |
8912 | operands would use up an additional register and take an extra instruction, | |
8913 | for no particular gain. */ | |
8914 | ||
8915 | void | |
8916 | neon_pairwise_reduce (rtx op0, rtx op1, enum machine_mode mode, | |
8917 | rtx (*reduc) (rtx, rtx, rtx)) | |
8918 | { | |
8919 | enum machine_mode inner = GET_MODE_INNER (mode); | |
8920 | unsigned int i, parts = GET_MODE_SIZE (mode) / GET_MODE_SIZE (inner); | |
8921 | rtx tmpsum = op1; | |
8922 | ||
8923 | for (i = parts / 2; i >= 1; i /= 2) | |
8924 | { | |
8925 | rtx dest = (i == 1) ? op0 : gen_reg_rtx (mode); | |
8926 | emit_insn (reduc (dest, tmpsum, tmpsum)); | |
8927 | tmpsum = dest; | |
8928 | } | |
8929 | } | |
8930 | ||
814a4c3b DJ |
8931 | /* If VALS is a vector constant that can be loaded into a register |
8932 | using VDUP, generate instructions to do so and return an RTX to | |
8933 | assign to the register. Otherwise return NULL_RTX. */ | |
8934 | ||
8935 | static rtx | |
8936 | neon_vdup_constant (rtx vals) | |
8937 | { | |
8938 | enum machine_mode mode = GET_MODE (vals); | |
8939 | enum machine_mode inner_mode = GET_MODE_INNER (mode); | |
8940 | int n_elts = GET_MODE_NUNITS (mode); | |
8941 | bool all_same = true; | |
8942 | rtx x; | |
8943 | int i; | |
8944 | ||
8945 | if (GET_CODE (vals) != CONST_VECTOR || GET_MODE_SIZE (inner_mode) > 4) | |
8946 | return NULL_RTX; | |
8947 | ||
8948 | for (i = 0; i < n_elts; ++i) | |
8949 | { | |
8950 | x = XVECEXP (vals, 0, i); | |
8951 | if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0))) | |
8952 | all_same = false; | |
8953 | } | |
8954 | ||
8955 | if (!all_same) | |
8956 | /* The elements are not all the same. We could handle repeating | |
8957 | patterns of a mode larger than INNER_MODE here (e.g. int8x8_t | |
8958 | {0, C, 0, C, 0, C, 0, C} which can be loaded using | |
8959 | vdup.i16). */ | |
8960 | return NULL_RTX; | |
8961 | ||
8962 | /* We can load this constant by using VDUP and a constant in a | |
8963 | single ARM register. This will be cheaper than a vector | |
8964 | load. */ | |
8965 | ||
8966 | x = copy_to_mode_reg (inner_mode, XVECEXP (vals, 0, 0)); | |
a277dd9b | 8967 | return gen_rtx_VEC_DUPLICATE (mode, x); |
814a4c3b DJ |
8968 | } |
8969 | ||
8970 | /* Generate code to load VALS, which is a PARALLEL containing only | |
8971 | constants (for vec_init) or CONST_VECTOR, efficiently into a | |
8972 | register. Returns an RTX to copy into the register, or NULL_RTX | |
8973 | for a PARALLEL that can not be converted into a CONST_VECTOR. */ | |
8974 | ||
8975 | rtx | |
8976 | neon_make_constant (rtx vals) | |
8977 | { | |
8978 | enum machine_mode mode = GET_MODE (vals); | |
8979 | rtx target; | |
8980 | rtx const_vec = NULL_RTX; | |
8981 | int n_elts = GET_MODE_NUNITS (mode); | |
8982 | int n_const = 0; | |
8983 | int i; | |
8984 | ||
8985 | if (GET_CODE (vals) == CONST_VECTOR) | |
8986 | const_vec = vals; | |
8987 | else if (GET_CODE (vals) == PARALLEL) | |
8988 | { | |
8989 | /* A CONST_VECTOR must contain only CONST_INTs and | |
8990 | CONST_DOUBLEs, but CONSTANT_P allows more (e.g. SYMBOL_REF). | |
8991 | Only store valid constants in a CONST_VECTOR. */ | |
8992 | for (i = 0; i < n_elts; ++i) | |
8993 | { | |
8994 | rtx x = XVECEXP (vals, 0, i); | |
8995 | if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) | |
8996 | n_const++; | |
8997 | } | |
8998 | if (n_const == n_elts) | |
8999 | const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)); | |
9000 | } | |
9001 | else | |
9002 | gcc_unreachable (); | |
9003 | ||
9004 | if (const_vec != NULL | |
9005 | && neon_immediate_valid_for_move (const_vec, mode, NULL, NULL)) | |
9006 | /* Load using VMOV. On Cortex-A8 this takes one cycle. */ | |
9007 | return const_vec; | |
9008 | else if ((target = neon_vdup_constant (vals)) != NULL_RTX) | |
9009 | /* Loaded using VDUP. On Cortex-A8 the VDUP takes one NEON | |
9010 | pipeline cycle; creating the constant takes one or two ARM | |
9011 | pipeline cycles. */ | |
9012 | return target; | |
9013 | else if (const_vec != NULL_RTX) | |
9014 | /* Load from constant pool. On Cortex-A8 this takes two cycles | |
9015 | (for either double or quad vectors). We can not take advantage | |
9016 | of single-cycle VLD1 because we need a PC-relative addressing | |
9017 | mode. */ | |
9018 | return const_vec; | |
9019 | else | |
9020 | /* A PARALLEL containing something not valid inside CONST_VECTOR. | |
9021 | We can not construct an initializer. */ | |
9022 | return NULL_RTX; | |
9023 | } | |
9024 | ||
9025 | /* Initialize vector TARGET to VALS. */ | |
88f77cba JB |
9026 | |
9027 | void | |
9028 | neon_expand_vector_init (rtx target, rtx vals) | |
9029 | { | |
9030 | enum machine_mode mode = GET_MODE (target); | |
814a4c3b DJ |
9031 | enum machine_mode inner_mode = GET_MODE_INNER (mode); |
9032 | int n_elts = GET_MODE_NUNITS (mode); | |
9033 | int n_var = 0, one_var = -1; | |
9034 | bool all_same = true; | |
9035 | rtx x, mem; | |
9036 | int i; | |
88f77cba | 9037 | |
814a4c3b DJ |
9038 | for (i = 0; i < n_elts; ++i) |
9039 | { | |
9040 | x = XVECEXP (vals, 0, i); | |
9041 | if (!CONSTANT_P (x)) | |
9042 | ++n_var, one_var = i; | |
9043 | ||
9044 | if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0))) | |
9045 | all_same = false; | |
9046 | } | |
88f77cba | 9047 | |
814a4c3b DJ |
9048 | if (n_var == 0) |
9049 | { | |
9050 | rtx constant = neon_make_constant (vals); | |
9051 | if (constant != NULL_RTX) | |
9052 | { | |
9053 | emit_move_insn (target, constant); | |
9054 | return; | |
9055 | } | |
9056 | } | |
9057 | ||
9058 | /* Splat a single non-constant element if we can. */ | |
9059 | if (all_same && GET_MODE_SIZE (inner_mode) <= 4) | |
9060 | { | |
9061 | x = copy_to_mode_reg (inner_mode, XVECEXP (vals, 0, 0)); | |
9062 | emit_insn (gen_rtx_SET (VOIDmode, target, | |
a277dd9b | 9063 | gen_rtx_VEC_DUPLICATE (mode, x))); |
814a4c3b DJ |
9064 | return; |
9065 | } | |
9066 | ||
9067 | /* One field is non-constant. Load constant then overwrite varying | |
9068 | field. This is more efficient than using the stack. */ | |
9069 | if (n_var == 1) | |
9070 | { | |
9071 | rtx copy = copy_rtx (vals); | |
a277dd9b | 9072 | rtx index = GEN_INT (one_var); |
814a4c3b DJ |
9073 | |
9074 | /* Load constant part of vector, substitute neighboring value for | |
9075 | varying element. */ | |
9076 | XVECEXP (copy, 0, one_var) = XVECEXP (vals, 0, (one_var + 1) % n_elts); | |
9077 | neon_expand_vector_init (target, copy); | |
9078 | ||
9079 | /* Insert variable. */ | |
9080 | x = copy_to_mode_reg (inner_mode, XVECEXP (vals, 0, one_var)); | |
a277dd9b SL |
9081 | switch (mode) |
9082 | { | |
9083 | case V8QImode: | |
9084 | emit_insn (gen_neon_vset_lanev8qi (target, x, target, index)); | |
9085 | break; | |
9086 | case V16QImode: | |
9087 | emit_insn (gen_neon_vset_lanev16qi (target, x, target, index)); | |
9088 | break; | |
9089 | case V4HImode: | |
9090 | emit_insn (gen_neon_vset_lanev4hi (target, x, target, index)); | |
9091 | break; | |
9092 | case V8HImode: | |
9093 | emit_insn (gen_neon_vset_lanev8hi (target, x, target, index)); | |
9094 | break; | |
9095 | case V2SImode: | |
9096 | emit_insn (gen_neon_vset_lanev2si (target, x, target, index)); | |
9097 | break; | |
9098 | case V4SImode: | |
9099 | emit_insn (gen_neon_vset_lanev4si (target, x, target, index)); | |
9100 | break; | |
9101 | case V2SFmode: | |
9102 | emit_insn (gen_neon_vset_lanev2sf (target, x, target, index)); | |
9103 | break; | |
9104 | case V4SFmode: | |
9105 | emit_insn (gen_neon_vset_lanev4sf (target, x, target, index)); | |
9106 | break; | |
9107 | case V2DImode: | |
9108 | emit_insn (gen_neon_vset_lanev2di (target, x, target, index)); | |
9109 | break; | |
9110 | default: | |
9111 | gcc_unreachable (); | |
9112 | } | |
814a4c3b DJ |
9113 | return; |
9114 | } | |
9115 | ||
9116 | /* Construct the vector in memory one field at a time | |
9117 | and load the whole vector. */ | |
88f77cba JB |
9118 | mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0); |
9119 | for (i = 0; i < n_elts; i++) | |
814a4c3b DJ |
9120 | emit_move_insn (adjust_address_nv (mem, inner_mode, |
9121 | i * GET_MODE_SIZE (inner_mode)), | |
9122 | XVECEXP (vals, 0, i)); | |
88f77cba JB |
9123 | emit_move_insn (target, mem); |
9124 | } | |
9125 | ||
b617fc71 JB |
9126 | /* Ensure OPERAND lies between LOW (inclusive) and HIGH (exclusive). Raise |
9127 | ERR if it doesn't. FIXME: NEON bounds checks occur late in compilation, so | |
9128 | reported source locations are bogus. */ | |
9129 | ||
9130 | static void | |
9131 | bounds_check (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high, | |
9132 | const char *err) | |
9133 | { | |
9134 | HOST_WIDE_INT lane; | |
9135 | ||
9136 | gcc_assert (GET_CODE (operand) == CONST_INT); | |
9137 | ||
9138 | lane = INTVAL (operand); | |
9139 | ||
9140 | if (lane < low || lane >= high) | |
9141 | error (err); | |
9142 | } | |
9143 | ||
9144 | /* Bounds-check lanes. */ | |
9145 | ||
9146 | void | |
9147 | neon_lane_bounds (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high) | |
9148 | { | |
9149 | bounds_check (operand, low, high, "lane out of range"); | |
9150 | } | |
9151 | ||
9152 | /* Bounds-check constants. */ | |
9153 | ||
9154 | void | |
9155 | neon_const_bounds (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high) | |
9156 | { | |
9157 | bounds_check (operand, low, high, "constant out of range"); | |
9158 | } | |
9159 | ||
9160 | HOST_WIDE_INT | |
9161 | neon_element_bits (enum machine_mode mode) | |
9162 | { | |
9163 | if (mode == DImode) | |
9164 | return GET_MODE_BITSIZE (mode); | |
9165 | else | |
9166 | return GET_MODE_BITSIZE (GET_MODE_INNER (mode)); | |
9167 | } | |
9168 | ||
cce8749e CH |
9169 | \f |
9170 | /* Predicates for `match_operand' and `match_operator'. */ | |
9171 | ||
9b6b54e2 | 9172 | /* Return nonzero if OP is a valid Cirrus memory address pattern. */ |
9b6b54e2 | 9173 | int |
e32bac5b | 9174 | cirrus_memory_offset (rtx op) |
9b6b54e2 NC |
9175 | { |
9176 | /* Reject eliminable registers. */ | |
9177 | if (! (reload_in_progress || reload_completed) | |
9178 | && ( reg_mentioned_p (frame_pointer_rtx, op) | |
9179 | || reg_mentioned_p (arg_pointer_rtx, op) | |
9180 | || reg_mentioned_p (virtual_incoming_args_rtx, op) | |
9181 | || reg_mentioned_p (virtual_outgoing_args_rtx, op) | |
9182 | || reg_mentioned_p (virtual_stack_dynamic_rtx, op) | |
9183 | || reg_mentioned_p (virtual_stack_vars_rtx, op))) | |
9184 | return 0; | |
9185 | ||
9186 | if (GET_CODE (op) == MEM) | |
9187 | { | |
9188 | rtx ind; | |
9189 | ||
9190 | ind = XEXP (op, 0); | |
9191 | ||
9192 | /* Match: (mem (reg)). */ | |
9193 | if (GET_CODE (ind) == REG) | |
9194 | return 1; | |
9195 | ||
9196 | /* Match: | |
9197 | (mem (plus (reg) | |
9198 | (const))). */ | |
9199 | if (GET_CODE (ind) == PLUS | |
9200 | && GET_CODE (XEXP (ind, 0)) == REG | |
9201 | && REG_MODE_OK_FOR_BASE_P (XEXP (ind, 0), VOIDmode) | |
9202 | && GET_CODE (XEXP (ind, 1)) == CONST_INT) | |
9203 | return 1; | |
9204 | } | |
9205 | ||
9206 | return 0; | |
9207 | } | |
9208 | ||
f26b8ec9 | 9209 | /* Return TRUE if OP is a valid coprocessor memory address pattern. |
5b3e6663 PB |
9210 | WB is true if full writeback address modes are allowed and is false |
9211 | if limited writeback address modes (POST_INC and PRE_DEC) are | |
9212 | allowed. */ | |
9b66ebb1 PB |
9213 | |
9214 | int | |
fdd695fd | 9215 | arm_coproc_mem_operand (rtx op, bool wb) |
9b66ebb1 | 9216 | { |
fdd695fd | 9217 | rtx ind; |
9b66ebb1 | 9218 | |
fdd695fd | 9219 | /* Reject eliminable registers. */ |
9b66ebb1 PB |
9220 | if (! (reload_in_progress || reload_completed) |
9221 | && ( reg_mentioned_p (frame_pointer_rtx, op) | |
9222 | || reg_mentioned_p (arg_pointer_rtx, op) | |
9223 | || reg_mentioned_p (virtual_incoming_args_rtx, op) | |
9224 | || reg_mentioned_p (virtual_outgoing_args_rtx, op) | |
9225 | || reg_mentioned_p (virtual_stack_dynamic_rtx, op) | |
9226 | || reg_mentioned_p (virtual_stack_vars_rtx, op))) | |
9227 | return FALSE; | |
9228 | ||
59b9a953 | 9229 | /* Constants are converted into offsets from labels. */ |
fdd695fd PB |
9230 | if (GET_CODE (op) != MEM) |
9231 | return FALSE; | |
9b66ebb1 | 9232 | |
fdd695fd | 9233 | ind = XEXP (op, 0); |
9b66ebb1 | 9234 | |
fdd695fd PB |
9235 | if (reload_completed |
9236 | && (GET_CODE (ind) == LABEL_REF | |
9237 | || (GET_CODE (ind) == CONST | |
9238 | && GET_CODE (XEXP (ind, 0)) == PLUS | |
9239 | && GET_CODE (XEXP (XEXP (ind, 0), 0)) == LABEL_REF | |
9240 | && GET_CODE (XEXP (XEXP (ind, 0), 1)) == CONST_INT))) | |
9241 | return TRUE; | |
9b66ebb1 | 9242 | |
fdd695fd PB |
9243 | /* Match: (mem (reg)). */ |
9244 | if (GET_CODE (ind) == REG) | |
9245 | return arm_address_register_rtx_p (ind, 0); | |
9246 | ||
5b3e6663 PB |
9247 | /* Autoincremment addressing modes. POST_INC and PRE_DEC are |
9248 | acceptable in any case (subject to verification by | |
9249 | arm_address_register_rtx_p). We need WB to be true to accept | |
9250 | PRE_INC and POST_DEC. */ | |
9251 | if (GET_CODE (ind) == POST_INC | |
9252 | || GET_CODE (ind) == PRE_DEC | |
9253 | || (wb | |
9254 | && (GET_CODE (ind) == PRE_INC | |
9255 | || GET_CODE (ind) == POST_DEC))) | |
fdd695fd PB |
9256 | return arm_address_register_rtx_p (XEXP (ind, 0), 0); |
9257 | ||
9258 | if (wb | |
9259 | && (GET_CODE (ind) == POST_MODIFY || GET_CODE (ind) == PRE_MODIFY) | |
9260 | && arm_address_register_rtx_p (XEXP (ind, 0), 0) | |
9261 | && GET_CODE (XEXP (ind, 1)) == PLUS | |
9262 | && rtx_equal_p (XEXP (XEXP (ind, 1), 0), XEXP (ind, 0))) | |
9263 | ind = XEXP (ind, 1); | |
9264 | ||
9265 | /* Match: | |
9266 | (plus (reg) | |
9267 | (const)). */ | |
9268 | if (GET_CODE (ind) == PLUS | |
9269 | && GET_CODE (XEXP (ind, 0)) == REG | |
9270 | && REG_MODE_OK_FOR_BASE_P (XEXP (ind, 0), VOIDmode) | |
9271 | && GET_CODE (XEXP (ind, 1)) == CONST_INT | |
9272 | && INTVAL (XEXP (ind, 1)) > -1024 | |
9273 | && INTVAL (XEXP (ind, 1)) < 1024 | |
9274 | && (INTVAL (XEXP (ind, 1)) & 3) == 0) | |
9275 | return TRUE; | |
9b66ebb1 PB |
9276 | |
9277 | return FALSE; | |
9278 | } | |
9279 | ||
88f77cba | 9280 | /* Return TRUE if OP is a memory operand which we can load or store a vector |
dc34db56 PB |
9281 | to/from. TYPE is one of the following values: |
9282 | 0 - Vector load/stor (vldr) | |
9283 | 1 - Core registers (ldm) | |
9284 | 2 - Element/structure loads (vld1) | |
9285 | */ | |
88f77cba | 9286 | int |
dc34db56 | 9287 | neon_vector_mem_operand (rtx op, int type) |
88f77cba JB |
9288 | { |
9289 | rtx ind; | |
9290 | ||
9291 | /* Reject eliminable registers. */ | |
9292 | if (! (reload_in_progress || reload_completed) | |
9293 | && ( reg_mentioned_p (frame_pointer_rtx, op) | |
9294 | || reg_mentioned_p (arg_pointer_rtx, op) | |
9295 | || reg_mentioned_p (virtual_incoming_args_rtx, op) | |
9296 | || reg_mentioned_p (virtual_outgoing_args_rtx, op) | |
9297 | || reg_mentioned_p (virtual_stack_dynamic_rtx, op) | |
9298 | || reg_mentioned_p (virtual_stack_vars_rtx, op))) | |
9299 | return FALSE; | |
9300 | ||
9301 | /* Constants are converted into offsets from labels. */ | |
9302 | if (GET_CODE (op) != MEM) | |
9303 | return FALSE; | |
9304 | ||
9305 | ind = XEXP (op, 0); | |
9306 | ||
9307 | if (reload_completed | |
9308 | && (GET_CODE (ind) == LABEL_REF | |
9309 | || (GET_CODE (ind) == CONST | |
9310 | && GET_CODE (XEXP (ind, 0)) == PLUS | |
9311 | && GET_CODE (XEXP (XEXP (ind, 0), 0)) == LABEL_REF | |
9312 | && GET_CODE (XEXP (XEXP (ind, 0), 1)) == CONST_INT))) | |
9313 | return TRUE; | |
9314 | ||
9315 | /* Match: (mem (reg)). */ | |
9316 | if (GET_CODE (ind) == REG) | |
9317 | return arm_address_register_rtx_p (ind, 0); | |
9318 | ||
9319 | /* Allow post-increment with Neon registers. */ | |
c452684d JB |
9320 | if ((type != 1 && GET_CODE (ind) == POST_INC) |
9321 | || (type == 0 && GET_CODE (ind) == PRE_DEC)) | |
88f77cba JB |
9322 | return arm_address_register_rtx_p (XEXP (ind, 0), 0); |
9323 | ||
dc34db56 | 9324 | /* FIXME: vld1 allows register post-modify. */ |
88f77cba JB |
9325 | |
9326 | /* Match: | |
9327 | (plus (reg) | |
9328 | (const)). */ | |
dc34db56 | 9329 | if (type == 0 |
88f77cba JB |
9330 | && GET_CODE (ind) == PLUS |
9331 | && GET_CODE (XEXP (ind, 0)) == REG | |
9332 | && REG_MODE_OK_FOR_BASE_P (XEXP (ind, 0), VOIDmode) | |
9333 | && GET_CODE (XEXP (ind, 1)) == CONST_INT | |
9334 | && INTVAL (XEXP (ind, 1)) > -1024 | |
9335 | && INTVAL (XEXP (ind, 1)) < 1016 | |
9336 | && (INTVAL (XEXP (ind, 1)) & 3) == 0) | |
9337 | return TRUE; | |
9338 | ||
9339 | return FALSE; | |
9340 | } | |
9341 | ||
9342 | /* Return TRUE if OP is a mem suitable for loading/storing a Neon struct | |
9343 | type. */ | |
9344 | int | |
9345 | neon_struct_mem_operand (rtx op) | |
9346 | { | |
9347 | rtx ind; | |
9348 | ||
9349 | /* Reject eliminable registers. */ | |
9350 | if (! (reload_in_progress || reload_completed) | |
9351 | && ( reg_mentioned_p (frame_pointer_rtx, op) | |
9352 | || reg_mentioned_p (arg_pointer_rtx, op) | |
9353 | || reg_mentioned_p (virtual_incoming_args_rtx, op) | |
9354 | || reg_mentioned_p (virtual_outgoing_args_rtx, op) | |
9355 | || reg_mentioned_p (virtual_stack_dynamic_rtx, op) | |
9356 | || reg_mentioned_p (virtual_stack_vars_rtx, op))) | |
9357 | return FALSE; | |
9358 | ||
9359 | /* Constants are converted into offsets from labels. */ | |
9360 | if (GET_CODE (op) != MEM) | |
9361 | return FALSE; | |
9362 | ||
9363 | ind = XEXP (op, 0); | |
9364 | ||
9365 | if (reload_completed | |
9366 | && (GET_CODE (ind) == LABEL_REF | |
9367 | || (GET_CODE (ind) == CONST | |
9368 | && GET_CODE (XEXP (ind, 0)) == PLUS | |
9369 | && GET_CODE (XEXP (XEXP (ind, 0), 0)) == LABEL_REF | |
9370 | && GET_CODE (XEXP (XEXP (ind, 0), 1)) == CONST_INT))) | |
9371 | return TRUE; | |
9372 | ||
9373 | /* Match: (mem (reg)). */ | |
9374 | if (GET_CODE (ind) == REG) | |
9375 | return arm_address_register_rtx_p (ind, 0); | |
9376 | ||
e54170f4 CLT |
9377 | /* vldm/vstm allows POST_INC (ia) and PRE_DEC (db). */ |
9378 | if (GET_CODE (ind) == POST_INC | |
9379 | || GET_CODE (ind) == PRE_DEC) | |
9380 | return arm_address_register_rtx_p (XEXP (ind, 0), 0); | |
9381 | ||
88f77cba JB |
9382 | return FALSE; |
9383 | } | |
9384 | ||
6555b6bd RE |
9385 | /* Return true if X is a register that will be eliminated later on. */ |
9386 | int | |
9387 | arm_eliminable_register (rtx x) | |
9388 | { | |
9389 | return REG_P (x) && (REGNO (x) == FRAME_POINTER_REGNUM | |
9390 | || REGNO (x) == ARG_POINTER_REGNUM | |
9391 | || (REGNO (x) >= FIRST_VIRTUAL_REGISTER | |
9392 | && REGNO (x) <= LAST_VIRTUAL_REGISTER)); | |
9393 | } | |
9b66ebb1 | 9394 | |
9b66ebb1 | 9395 | /* Return GENERAL_REGS if a scratch register required to reload x to/from |
fe2d934b | 9396 | coprocessor registers. Otherwise return NO_REGS. */ |
9b66ebb1 PB |
9397 | |
9398 | enum reg_class | |
fe2d934b | 9399 | coproc_secondary_reload_class (enum machine_mode mode, rtx x, bool wb) |
9b66ebb1 | 9400 | { |
0fd8c3ad SL |
9401 | if (mode == HFmode) |
9402 | { | |
e0dc3601 PB |
9403 | if (!TARGET_NEON_FP16) |
9404 | return GENERAL_REGS; | |
0fd8c3ad SL |
9405 | if (s_register_operand (x, mode) || neon_vector_mem_operand (x, 2)) |
9406 | return NO_REGS; | |
9407 | return GENERAL_REGS; | |
9408 | } | |
9409 | ||
159b81b0 RS |
9410 | /* The neon move patterns handle all legitimate vector and struct |
9411 | addresses. */ | |
88f77cba | 9412 | if (TARGET_NEON |
8973b112 | 9413 | && (MEM_P (x) || GET_CODE (x) == CONST_VECTOR) |
88f77cba | 9414 | && (GET_MODE_CLASS (mode) == MODE_VECTOR_INT |
159b81b0 RS |
9415 | || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT |
9416 | || VALID_NEON_STRUCT_MODE (mode))) | |
9417 | return NO_REGS; | |
88f77cba | 9418 | |
fe2d934b | 9419 | if (arm_coproc_mem_operand (x, wb) || s_register_operand (x, mode)) |
9b66ebb1 PB |
9420 | return NO_REGS; |
9421 | ||
9422 | return GENERAL_REGS; | |
9423 | } | |
9424 | ||
866af8a9 JB |
9425 | /* Values which must be returned in the most-significant end of the return |
9426 | register. */ | |
9427 | ||
9428 | static bool | |
586de218 | 9429 | arm_return_in_msb (const_tree valtype) |
866af8a9 JB |
9430 | { |
9431 | return (TARGET_AAPCS_BASED | |
9432 | && BYTES_BIG_ENDIAN | |
655b30bf JB |
9433 | && (AGGREGATE_TYPE_P (valtype) |
9434 | || TREE_CODE (valtype) == COMPLEX_TYPE | |
9435 | || FIXED_POINT_TYPE_P (valtype))); | |
866af8a9 | 9436 | } |
9b66ebb1 | 9437 | |
f0375c66 NC |
9438 | /* Returns TRUE if INSN is an "LDR REG, ADDR" instruction. |
9439 | Use by the Cirrus Maverick code which has to workaround | |
9440 | a hardware bug triggered by such instructions. */ | |
f0375c66 | 9441 | static bool |
e32bac5b | 9442 | arm_memory_load_p (rtx insn) |
9b6b54e2 NC |
9443 | { |
9444 | rtx body, lhs, rhs;; | |
9445 | ||
f0375c66 NC |
9446 | if (insn == NULL_RTX || GET_CODE (insn) != INSN) |
9447 | return false; | |
9b6b54e2 NC |
9448 | |
9449 | body = PATTERN (insn); | |
9450 | ||
9451 | if (GET_CODE (body) != SET) | |
f0375c66 | 9452 | return false; |
9b6b54e2 NC |
9453 | |
9454 | lhs = XEXP (body, 0); | |
9455 | rhs = XEXP (body, 1); | |
9456 | ||
f0375c66 NC |
9457 | lhs = REG_OR_SUBREG_RTX (lhs); |
9458 | ||
9459 | /* If the destination is not a general purpose | |
9460 | register we do not have to worry. */ | |
9461 | if (GET_CODE (lhs) != REG | |
9462 | || REGNO_REG_CLASS (REGNO (lhs)) != GENERAL_REGS) | |
9463 | return false; | |
9464 | ||
9465 | /* As well as loads from memory we also have to react | |
9466 | to loads of invalid constants which will be turned | |
9467 | into loads from the minipool. */ | |
9468 | return (GET_CODE (rhs) == MEM | |
9469 | || GET_CODE (rhs) == SYMBOL_REF | |
9470 | || note_invalid_constants (insn, -1, false)); | |
9b6b54e2 NC |
9471 | } |
9472 | ||
f0375c66 | 9473 | /* Return TRUE if INSN is a Cirrus instruction. */ |
f0375c66 | 9474 | static bool |
e32bac5b | 9475 | arm_cirrus_insn_p (rtx insn) |
9b6b54e2 NC |
9476 | { |
9477 | enum attr_cirrus attr; | |
9478 | ||
e6d29d15 | 9479 | /* get_attr cannot accept USE or CLOBBER. */ |
9b6b54e2 NC |
9480 | if (!insn |
9481 | || GET_CODE (insn) != INSN | |
9482 | || GET_CODE (PATTERN (insn)) == USE | |
9483 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
9484 | return 0; | |
9485 | ||
9486 | attr = get_attr_cirrus (insn); | |
9487 | ||
f0375c66 | 9488 | return attr != CIRRUS_NOT; |
9b6b54e2 NC |
9489 | } |
9490 | ||
9491 | /* Cirrus reorg for invalid instruction combinations. */ | |
9b6b54e2 | 9492 | static void |
e32bac5b | 9493 | cirrus_reorg (rtx first) |
9b6b54e2 NC |
9494 | { |
9495 | enum attr_cirrus attr; | |
9496 | rtx body = PATTERN (first); | |
9497 | rtx t; | |
9498 | int nops; | |
9499 | ||
9500 | /* Any branch must be followed by 2 non Cirrus instructions. */ | |
9501 | if (GET_CODE (first) == JUMP_INSN && GET_CODE (body) != RETURN) | |
9502 | { | |
9503 | nops = 0; | |
9504 | t = next_nonnote_insn (first); | |
9505 | ||
f0375c66 | 9506 | if (arm_cirrus_insn_p (t)) |
9b6b54e2 NC |
9507 | ++ nops; |
9508 | ||
f0375c66 | 9509 | if (arm_cirrus_insn_p (next_nonnote_insn (t))) |
9b6b54e2 NC |
9510 | ++ nops; |
9511 | ||
9512 | while (nops --) | |
9513 | emit_insn_after (gen_nop (), first); | |
9514 | ||
9515 | return; | |
9516 | } | |
9517 | ||
9518 | /* (float (blah)) is in parallel with a clobber. */ | |
9519 | if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0) | |
9520 | body = XVECEXP (body, 0, 0); | |
9521 | ||
9522 | if (GET_CODE (body) == SET) | |
9523 | { | |
9524 | rtx lhs = XEXP (body, 0), rhs = XEXP (body, 1); | |
9525 | ||
9526 | /* cfldrd, cfldr64, cfstrd, cfstr64 must | |
9527 | be followed by a non Cirrus insn. */ | |
9528 | if (get_attr_cirrus (first) == CIRRUS_DOUBLE) | |
9529 | { | |
f0375c66 | 9530 | if (arm_cirrus_insn_p (next_nonnote_insn (first))) |
9b6b54e2 NC |
9531 | emit_insn_after (gen_nop (), first); |
9532 | ||
9533 | return; | |
9534 | } | |
f0375c66 | 9535 | else if (arm_memory_load_p (first)) |
9b6b54e2 NC |
9536 | { |
9537 | unsigned int arm_regno; | |
9538 | ||
9539 | /* Any ldr/cfmvdlr, ldr/cfmvdhr, ldr/cfmvsr, ldr/cfmv64lr, | |
9540 | ldr/cfmv64hr combination where the Rd field is the same | |
9541 | in both instructions must be split with a non Cirrus | |
9542 | insn. Example: | |
9543 | ||
9544 | ldr r0, blah | |
9545 | nop | |
9546 | cfmvsr mvf0, r0. */ | |
9547 | ||
9548 | /* Get Arm register number for ldr insn. */ | |
9549 | if (GET_CODE (lhs) == REG) | |
9550 | arm_regno = REGNO (lhs); | |
9b6b54e2 | 9551 | else |
e6d29d15 NS |
9552 | { |
9553 | gcc_assert (GET_CODE (rhs) == REG); | |
9554 | arm_regno = REGNO (rhs); | |
9555 | } | |
9b6b54e2 NC |
9556 | |
9557 | /* Next insn. */ | |
9558 | first = next_nonnote_insn (first); | |
9559 | ||
f0375c66 | 9560 | if (! arm_cirrus_insn_p (first)) |
9b6b54e2 NC |
9561 | return; |
9562 | ||
9563 | body = PATTERN (first); | |
9564 | ||
9565 | /* (float (blah)) is in parallel with a clobber. */ | |
9566 | if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0)) | |
9567 | body = XVECEXP (body, 0, 0); | |
9568 | ||
9569 | if (GET_CODE (body) == FLOAT) | |
9570 | body = XEXP (body, 0); | |
9571 | ||
9572 | if (get_attr_cirrus (first) == CIRRUS_MOVE | |
9573 | && GET_CODE (XEXP (body, 1)) == REG | |
9574 | && arm_regno == REGNO (XEXP (body, 1))) | |
9575 | emit_insn_after (gen_nop (), first); | |
9576 | ||
9577 | return; | |
9578 | } | |
9579 | } | |
9580 | ||
e6d29d15 | 9581 | /* get_attr cannot accept USE or CLOBBER. */ |
9b6b54e2 NC |
9582 | if (!first |
9583 | || GET_CODE (first) != INSN | |
9584 | || GET_CODE (PATTERN (first)) == USE | |
9585 | || GET_CODE (PATTERN (first)) == CLOBBER) | |
9586 | return; | |
9587 | ||
9588 | attr = get_attr_cirrus (first); | |
9589 | ||
9590 | /* Any coprocessor compare instruction (cfcmps, cfcmpd, ...) | |
9591 | must be followed by a non-coprocessor instruction. */ | |
9592 | if (attr == CIRRUS_COMPARE) | |
9593 | { | |
9594 | nops = 0; | |
9595 | ||
9596 | t = next_nonnote_insn (first); | |
9597 | ||
f0375c66 | 9598 | if (arm_cirrus_insn_p (t)) |
9b6b54e2 NC |
9599 | ++ nops; |
9600 | ||
f0375c66 | 9601 | if (arm_cirrus_insn_p (next_nonnote_insn (t))) |
9b6b54e2 NC |
9602 | ++ nops; |
9603 | ||
9604 | while (nops --) | |
9605 | emit_insn_after (gen_nop (), first); | |
9606 | ||
9607 | return; | |
9608 | } | |
9609 | } | |
9610 | ||
2b835d68 RE |
9611 | /* Return TRUE if X references a SYMBOL_REF. */ |
9612 | int | |
e32bac5b | 9613 | symbol_mentioned_p (rtx x) |
2b835d68 | 9614 | { |
1d6e90ac NC |
9615 | const char * fmt; |
9616 | int i; | |
2b835d68 RE |
9617 | |
9618 | if (GET_CODE (x) == SYMBOL_REF) | |
9619 | return 1; | |
9620 | ||
d3585b76 DJ |
9621 | /* UNSPEC_TLS entries for a symbol include the SYMBOL_REF, but they |
9622 | are constant offsets, not symbols. */ | |
9623 | if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS) | |
9624 | return 0; | |
9625 | ||
2b835d68 | 9626 | fmt = GET_RTX_FORMAT (GET_CODE (x)); |
f676971a | 9627 | |
2b835d68 RE |
9628 | for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) |
9629 | { | |
9630 | if (fmt[i] == 'E') | |
9631 | { | |
1d6e90ac | 9632 | int j; |
2b835d68 RE |
9633 | |
9634 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) | |
9635 | if (symbol_mentioned_p (XVECEXP (x, i, j))) | |
9636 | return 1; | |
9637 | } | |
9638 | else if (fmt[i] == 'e' && symbol_mentioned_p (XEXP (x, i))) | |
9639 | return 1; | |
9640 | } | |
9641 | ||
9642 | return 0; | |
9643 | } | |
9644 | ||
9645 | /* Return TRUE if X references a LABEL_REF. */ | |
9646 | int | |
e32bac5b | 9647 | label_mentioned_p (rtx x) |
2b835d68 | 9648 | { |
1d6e90ac NC |
9649 | const char * fmt; |
9650 | int i; | |
2b835d68 RE |
9651 | |
9652 | if (GET_CODE (x) == LABEL_REF) | |
9653 | return 1; | |
9654 | ||
d3585b76 DJ |
9655 | /* UNSPEC_TLS entries for a symbol include a LABEL_REF for the referencing |
9656 | instruction, but they are constant offsets, not symbols. */ | |
9657 | if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS) | |
9658 | return 0; | |
9659 | ||
2b835d68 RE |
9660 | fmt = GET_RTX_FORMAT (GET_CODE (x)); |
9661 | for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) | |
9662 | { | |
9663 | if (fmt[i] == 'E') | |
9664 | { | |
1d6e90ac | 9665 | int j; |
2b835d68 RE |
9666 | |
9667 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) | |
9668 | if (label_mentioned_p (XVECEXP (x, i, j))) | |
9669 | return 1; | |
9670 | } | |
9671 | else if (fmt[i] == 'e' && label_mentioned_p (XEXP (x, i))) | |
9672 | return 1; | |
9673 | } | |
9674 | ||
9675 | return 0; | |
9676 | } | |
9677 | ||
d3585b76 DJ |
9678 | int |
9679 | tls_mentioned_p (rtx x) | |
9680 | { | |
9681 | switch (GET_CODE (x)) | |
9682 | { | |
9683 | case CONST: | |
9684 | return tls_mentioned_p (XEXP (x, 0)); | |
9685 | ||
9686 | case UNSPEC: | |
9687 | if (XINT (x, 1) == UNSPEC_TLS) | |
9688 | return 1; | |
9689 | ||
9690 | default: | |
9691 | return 0; | |
9692 | } | |
9693 | } | |
9694 | ||
2e5505a4 RE |
9695 | /* Must not copy any rtx that uses a pc-relative address. */ |
9696 | ||
9697 | static int | |
9698 | arm_note_pic_base (rtx *x, void *date ATTRIBUTE_UNUSED) | |
9699 | { | |
9700 | if (GET_CODE (*x) == UNSPEC | |
9701 | && XINT (*x, 1) == UNSPEC_PIC_BASE) | |
9702 | return 1; | |
9703 | return 0; | |
9704 | } | |
d3585b76 DJ |
9705 | |
9706 | static bool | |
9707 | arm_cannot_copy_insn_p (rtx insn) | |
9708 | { | |
ccdc2164 NS |
9709 | /* The tls call insn cannot be copied, as it is paired with a data |
9710 | word. */ | |
9711 | if (recog_memoized (insn) == CODE_FOR_tlscall) | |
9712 | return true; | |
9713 | ||
2e5505a4 | 9714 | return for_each_rtx (&PATTERN (insn), arm_note_pic_base, NULL); |
d3585b76 DJ |
9715 | } |
9716 | ||
ff9940b0 | 9717 | enum rtx_code |
e32bac5b | 9718 | minmax_code (rtx x) |
ff9940b0 RE |
9719 | { |
9720 | enum rtx_code code = GET_CODE (x); | |
9721 | ||
e6d29d15 NS |
9722 | switch (code) |
9723 | { | |
9724 | case SMAX: | |
9725 | return GE; | |
9726 | case SMIN: | |
9727 | return LE; | |
9728 | case UMIN: | |
9729 | return LEU; | |
9730 | case UMAX: | |
9731 | return GEU; | |
9732 | default: | |
9733 | gcc_unreachable (); | |
9734 | } | |
ff9940b0 RE |
9735 | } |
9736 | ||
6354dc9b | 9737 | /* Return 1 if memory locations are adjacent. */ |
f3bb6135 | 9738 | int |
e32bac5b | 9739 | adjacent_mem_locations (rtx a, rtx b) |
ff9940b0 | 9740 | { |
15b5c4c1 RE |
9741 | /* We don't guarantee to preserve the order of these memory refs. */ |
9742 | if (volatile_refs_p (a) || volatile_refs_p (b)) | |
9743 | return 0; | |
9744 | ||
ff9940b0 RE |
9745 | if ((GET_CODE (XEXP (a, 0)) == REG |
9746 | || (GET_CODE (XEXP (a, 0)) == PLUS | |
9747 | && GET_CODE (XEXP (XEXP (a, 0), 1)) == CONST_INT)) | |
9748 | && (GET_CODE (XEXP (b, 0)) == REG | |
9749 | || (GET_CODE (XEXP (b, 0)) == PLUS | |
9750 | && GET_CODE (XEXP (XEXP (b, 0), 1)) == CONST_INT))) | |
9751 | { | |
6555b6bd RE |
9752 | HOST_WIDE_INT val0 = 0, val1 = 0; |
9753 | rtx reg0, reg1; | |
9754 | int val_diff; | |
f676971a | 9755 | |
ff9940b0 RE |
9756 | if (GET_CODE (XEXP (a, 0)) == PLUS) |
9757 | { | |
6555b6bd | 9758 | reg0 = XEXP (XEXP (a, 0), 0); |
ff9940b0 RE |
9759 | val0 = INTVAL (XEXP (XEXP (a, 0), 1)); |
9760 | } | |
9761 | else | |
6555b6bd | 9762 | reg0 = XEXP (a, 0); |
1d6e90ac | 9763 | |
ff9940b0 RE |
9764 | if (GET_CODE (XEXP (b, 0)) == PLUS) |
9765 | { | |
6555b6bd | 9766 | reg1 = XEXP (XEXP (b, 0), 0); |
ff9940b0 RE |
9767 | val1 = INTVAL (XEXP (XEXP (b, 0), 1)); |
9768 | } | |
9769 | else | |
6555b6bd | 9770 | reg1 = XEXP (b, 0); |
1d6e90ac | 9771 | |
e32bac5b RE |
9772 | /* Don't accept any offset that will require multiple |
9773 | instructions to handle, since this would cause the | |
9774 | arith_adjacentmem pattern to output an overlong sequence. */ | |
bbbbb16a | 9775 | if (!const_ok_for_op (val0, PLUS) || !const_ok_for_op (val1, PLUS)) |
c75a3ddc | 9776 | return 0; |
f676971a | 9777 | |
6555b6bd RE |
9778 | /* Don't allow an eliminable register: register elimination can make |
9779 | the offset too large. */ | |
9780 | if (arm_eliminable_register (reg0)) | |
9781 | return 0; | |
9782 | ||
9783 | val_diff = val1 - val0; | |
15b5c4c1 RE |
9784 | |
9785 | if (arm_ld_sched) | |
9786 | { | |
9787 | /* If the target has load delay slots, then there's no benefit | |
9788 | to using an ldm instruction unless the offset is zero and | |
9789 | we are optimizing for size. */ | |
9790 | return (optimize_size && (REGNO (reg0) == REGNO (reg1)) | |
9791 | && (val0 == 0 || val1 == 0 || val0 == 4 || val1 == 4) | |
9792 | && (val_diff == 4 || val_diff == -4)); | |
9793 | } | |
9794 | ||
6555b6bd RE |
9795 | return ((REGNO (reg0) == REGNO (reg1)) |
9796 | && (val_diff == 4 || val_diff == -4)); | |
ff9940b0 | 9797 | } |
6555b6bd | 9798 | |
ff9940b0 RE |
9799 | return 0; |
9800 | } | |
9801 | ||
93b338c3 BS |
9802 | /* Return true iff it would be profitable to turn a sequence of NOPS loads |
9803 | or stores (depending on IS_STORE) into a load-multiple or store-multiple | |
9804 | instruction. ADD_OFFSET is nonzero if the base address register needs | |
9805 | to be modified with an add instruction before we can use it. */ | |
9806 | ||
9807 | static bool | |
9808 | multiple_operation_profitable_p (bool is_store ATTRIBUTE_UNUSED, | |
9809 | int nops, HOST_WIDE_INT add_offset) | |
9810 | { | |
9811 | /* For ARM8,9 & StrongARM, 2 ldr instructions are faster than an ldm | |
9812 | if the offset isn't small enough. The reason 2 ldrs are faster | |
9813 | is because these ARMs are able to do more than one cache access | |
9814 | in a single cycle. The ARM9 and StrongARM have Harvard caches, | |
9815 | whilst the ARM8 has a double bandwidth cache. This means that | |
9816 | these cores can do both an instruction fetch and a data fetch in | |
9817 | a single cycle, so the trick of calculating the address into a | |
9818 | scratch register (one of the result regs) and then doing a load | |
9819 | multiple actually becomes slower (and no smaller in code size). | |
9820 | That is the transformation | |
9821 | ||
9822 | ldr rd1, [rbase + offset] | |
9823 | ldr rd2, [rbase + offset + 4] | |
9824 | ||
9825 | to | |
9826 | ||
9827 | add rd1, rbase, offset | |
9828 | ldmia rd1, {rd1, rd2} | |
9829 | ||
9830 | produces worse code -- '3 cycles + any stalls on rd2' instead of | |
9831 | '2 cycles + any stalls on rd2'. On ARMs with only one cache | |
9832 | access per cycle, the first sequence could never complete in less | |
9833 | than 6 cycles, whereas the ldm sequence would only take 5 and | |
9834 | would make better use of sequential accesses if not hitting the | |
9835 | cache. | |
9836 | ||
9837 | We cheat here and test 'arm_ld_sched' which we currently know to | |
9838 | only be true for the ARM8, ARM9 and StrongARM. If this ever | |
9839 | changes, then the test below needs to be reworked. */ | |
9840 | if (nops == 2 && arm_ld_sched && add_offset != 0) | |
9841 | return false; | |
9842 | ||
8f4c6e28 BS |
9843 | /* XScale has load-store double instructions, but they have stricter |
9844 | alignment requirements than load-store multiple, so we cannot | |
9845 | use them. | |
9846 | ||
9847 | For XScale ldm requires 2 + NREGS cycles to complete and blocks | |
9848 | the pipeline until completion. | |
9849 | ||
9850 | NREGS CYCLES | |
9851 | 1 3 | |
9852 | 2 4 | |
9853 | 3 5 | |
9854 | 4 6 | |
9855 | ||
9856 | An ldr instruction takes 1-3 cycles, but does not block the | |
9857 | pipeline. | |
9858 | ||
9859 | NREGS CYCLES | |
9860 | 1 1-3 | |
9861 | 2 2-6 | |
9862 | 3 3-9 | |
9863 | 4 4-12 | |
9864 | ||
9865 | Best case ldr will always win. However, the more ldr instructions | |
9866 | we issue, the less likely we are to be able to schedule them well. | |
9867 | Using ldr instructions also increases code size. | |
9868 | ||
9869 | As a compromise, we use ldr for counts of 1 or 2 regs, and ldm | |
9870 | for counts of 3 or 4 regs. */ | |
9871 | if (nops <= 2 && arm_tune_xscale && !optimize_size) | |
9872 | return false; | |
93b338c3 BS |
9873 | return true; |
9874 | } | |
9875 | ||
9876 | /* Subroutine of load_multiple_sequence and store_multiple_sequence. | |
9877 | Given an array of UNSORTED_OFFSETS, of which there are NOPS, compute | |
9878 | an array ORDER which describes the sequence to use when accessing the | |
9879 | offsets that produces an ascending order. In this sequence, each | |
9880 | offset must be larger by exactly 4 than the previous one. ORDER[0] | |
9881 | must have been filled in with the lowest offset by the caller. | |
9882 | If UNSORTED_REGS is nonnull, it is an array of register numbers that | |
9883 | we use to verify that ORDER produces an ascending order of registers. | |
9884 | Return true if it was possible to construct such an order, false if | |
9885 | not. */ | |
9886 | ||
9887 | static bool | |
9888 | compute_offset_order (int nops, HOST_WIDE_INT *unsorted_offsets, int *order, | |
9889 | int *unsorted_regs) | |
9890 | { | |
9891 | int i; | |
9892 | for (i = 1; i < nops; i++) | |
9893 | { | |
9894 | int j; | |
9895 | ||
9896 | order[i] = order[i - 1]; | |
9897 | for (j = 0; j < nops; j++) | |
9898 | if (unsorted_offsets[j] == unsorted_offsets[order[i - 1]] + 4) | |
9899 | { | |
9900 | /* We must find exactly one offset that is higher than the | |
9901 | previous one by 4. */ | |
9902 | if (order[i] != order[i - 1]) | |
9903 | return false; | |
9904 | order[i] = j; | |
9905 | } | |
9906 | if (order[i] == order[i - 1]) | |
9907 | return false; | |
9908 | /* The register numbers must be ascending. */ | |
9909 | if (unsorted_regs != NULL | |
9910 | && unsorted_regs[order[i]] <= unsorted_regs[order[i - 1]]) | |
9911 | return false; | |
9912 | } | |
9913 | return true; | |
9914 | } | |
9915 | ||
37119410 BS |
9916 | /* Used to determine in a peephole whether a sequence of load |
9917 | instructions can be changed into a load-multiple instruction. | |
9918 | NOPS is the number of separate load instructions we are examining. The | |
9919 | first NOPS entries in OPERANDS are the destination registers, the | |
9920 | next NOPS entries are memory operands. If this function is | |
9921 | successful, *BASE is set to the common base register of the memory | |
9922 | accesses; *LOAD_OFFSET is set to the first memory location's offset | |
9923 | from that base register. | |
9924 | REGS is an array filled in with the destination register numbers. | |
9925 | SAVED_ORDER (if nonnull), is an array filled in with an order that maps | |
dd5a833e | 9926 | insn numbers to an ascending order of stores. If CHECK_REGS is true, |
37119410 BS |
9927 | the sequence of registers in REGS matches the loads from ascending memory |
9928 | locations, and the function verifies that the register numbers are | |
9929 | themselves ascending. If CHECK_REGS is false, the register numbers | |
9930 | are stored in the order they are found in the operands. */ | |
9931 | static int | |
9932 | load_multiple_sequence (rtx *operands, int nops, int *regs, int *saved_order, | |
9933 | int *base, HOST_WIDE_INT *load_offset, bool check_regs) | |
84ed5e79 | 9934 | { |
93b338c3 BS |
9935 | int unsorted_regs[MAX_LDM_STM_OPS]; |
9936 | HOST_WIDE_INT unsorted_offsets[MAX_LDM_STM_OPS]; | |
9937 | int order[MAX_LDM_STM_OPS]; | |
37119410 | 9938 | rtx base_reg_rtx = NULL; |
ad076f4e | 9939 | int base_reg = -1; |
93b338c3 | 9940 | int i, ldm_case; |
84ed5e79 | 9941 | |
93b338c3 BS |
9942 | /* Can only handle up to MAX_LDM_STM_OPS insns at present, though could be |
9943 | easily extended if required. */ | |
9944 | gcc_assert (nops >= 2 && nops <= MAX_LDM_STM_OPS); | |
84ed5e79 | 9945 | |
93b338c3 | 9946 | memset (order, 0, MAX_LDM_STM_OPS * sizeof (int)); |
f0b4bdd5 | 9947 | |
84ed5e79 | 9948 | /* Loop over the operands and check that the memory references are |
112cdef5 | 9949 | suitable (i.e. immediate offsets from the same base register). At |
84ed5e79 RE |
9950 | the same time, extract the target register, and the memory |
9951 | offsets. */ | |
9952 | for (i = 0; i < nops; i++) | |
9953 | { | |
9954 | rtx reg; | |
9955 | rtx offset; | |
9956 | ||
56636818 JL |
9957 | /* Convert a subreg of a mem into the mem itself. */ |
9958 | if (GET_CODE (operands[nops + i]) == SUBREG) | |
4e26a7af | 9959 | operands[nops + i] = alter_subreg (operands + (nops + i)); |
56636818 | 9960 | |
e6d29d15 | 9961 | gcc_assert (GET_CODE (operands[nops + i]) == MEM); |
84ed5e79 RE |
9962 | |
9963 | /* Don't reorder volatile memory references; it doesn't seem worth | |
9964 | looking for the case where the order is ok anyway. */ | |
9965 | if (MEM_VOLATILE_P (operands[nops + i])) | |
9966 | return 0; | |
9967 | ||
9968 | offset = const0_rtx; | |
9969 | ||
9970 | if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG | |
9971 | || (GET_CODE (reg) == SUBREG | |
9972 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
9973 | || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS | |
9974 | && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0)) | |
9975 | == REG) | |
9976 | || (GET_CODE (reg) == SUBREG | |
9977 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
9978 | && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1)) | |
9979 | == CONST_INT))) | |
9980 | { | |
9981 | if (i == 0) | |
84ed5e79 | 9982 | { |
37119410 BS |
9983 | base_reg = REGNO (reg); |
9984 | base_reg_rtx = reg; | |
9985 | if (TARGET_THUMB1 && base_reg > LAST_LO_REGNUM) | |
84ed5e79 | 9986 | return 0; |
84ed5e79 | 9987 | } |
37119410 BS |
9988 | else if (base_reg != (int) REGNO (reg)) |
9989 | /* Not addressed from the same base register. */ | |
9990 | return 0; | |
9991 | ||
93b338c3 BS |
9992 | unsorted_regs[i] = (GET_CODE (operands[i]) == REG |
9993 | ? REGNO (operands[i]) | |
9994 | : REGNO (SUBREG_REG (operands[i]))); | |
84ed5e79 RE |
9995 | |
9996 | /* If it isn't an integer register, or if it overwrites the | |
9997 | base register but isn't the last insn in the list, then | |
9998 | we can't do this. */ | |
37119410 BS |
9999 | if (unsorted_regs[i] < 0 |
10000 | || (TARGET_THUMB1 && unsorted_regs[i] > LAST_LO_REGNUM) | |
10001 | || unsorted_regs[i] > 14 | |
84ed5e79 RE |
10002 | || (i != nops - 1 && unsorted_regs[i] == base_reg)) |
10003 | return 0; | |
10004 | ||
10005 | unsorted_offsets[i] = INTVAL (offset); | |
93b338c3 BS |
10006 | if (i == 0 || unsorted_offsets[i] < unsorted_offsets[order[0]]) |
10007 | order[0] = i; | |
84ed5e79 RE |
10008 | } |
10009 | else | |
10010 | /* Not a suitable memory address. */ | |
10011 | return 0; | |
10012 | } | |
10013 | ||
10014 | /* All the useful information has now been extracted from the | |
10015 | operands into unsorted_regs and unsorted_offsets; additionally, | |
93b338c3 BS |
10016 | order[0] has been set to the lowest offset in the list. Sort |
10017 | the offsets into order, verifying that they are adjacent, and | |
10018 | check that the register numbers are ascending. */ | |
37119410 BS |
10019 | if (!compute_offset_order (nops, unsorted_offsets, order, |
10020 | check_regs ? unsorted_regs : NULL)) | |
93b338c3 | 10021 | return 0; |
84ed5e79 | 10022 | |
37119410 BS |
10023 | if (saved_order) |
10024 | memcpy (saved_order, order, sizeof order); | |
10025 | ||
84ed5e79 RE |
10026 | if (base) |
10027 | { | |
10028 | *base = base_reg; | |
10029 | ||
10030 | for (i = 0; i < nops; i++) | |
37119410 | 10031 | regs[i] = unsorted_regs[check_regs ? order[i] : i]; |
84ed5e79 RE |
10032 | |
10033 | *load_offset = unsorted_offsets[order[0]]; | |
10034 | } | |
10035 | ||
37119410 BS |
10036 | if (TARGET_THUMB1 |
10037 | && !peep2_reg_dead_p (nops, base_reg_rtx)) | |
10038 | return 0; | |
10039 | ||
84ed5e79 | 10040 | if (unsorted_offsets[order[0]] == 0) |
93b338c3 BS |
10041 | ldm_case = 1; /* ldmia */ |
10042 | else if (TARGET_ARM && unsorted_offsets[order[0]] == 4) | |
10043 | ldm_case = 2; /* ldmib */ | |
10044 | else if (TARGET_ARM && unsorted_offsets[order[nops - 1]] == 0) | |
10045 | ldm_case = 3; /* ldmda */ | |
37119410 | 10046 | else if (TARGET_32BIT && unsorted_offsets[order[nops - 1]] == -4) |
93b338c3 BS |
10047 | ldm_case = 4; /* ldmdb */ |
10048 | else if (const_ok_for_arm (unsorted_offsets[order[0]]) | |
10049 | || const_ok_for_arm (-unsorted_offsets[order[0]])) | |
10050 | ldm_case = 5; | |
10051 | else | |
10052 | return 0; | |
949d79eb | 10053 | |
93b338c3 BS |
10054 | if (!multiple_operation_profitable_p (false, nops, |
10055 | ldm_case == 5 | |
10056 | ? unsorted_offsets[order[0]] : 0)) | |
b36ba79f RE |
10057 | return 0; |
10058 | ||
93b338c3 | 10059 | return ldm_case; |
84ed5e79 RE |
10060 | } |
10061 | ||
37119410 BS |
10062 | /* Used to determine in a peephole whether a sequence of store instructions can |
10063 | be changed into a store-multiple instruction. | |
10064 | NOPS is the number of separate store instructions we are examining. | |
10065 | NOPS_TOTAL is the total number of instructions recognized by the peephole | |
10066 | pattern. | |
10067 | The first NOPS entries in OPERANDS are the source registers, the next | |
10068 | NOPS entries are memory operands. If this function is successful, *BASE is | |
10069 | set to the common base register of the memory accesses; *LOAD_OFFSET is set | |
10070 | to the first memory location's offset from that base register. REGS is an | |
10071 | array filled in with the source register numbers, REG_RTXS (if nonnull) is | |
10072 | likewise filled with the corresponding rtx's. | |
10073 | SAVED_ORDER (if nonnull), is an array filled in with an order that maps insn | |
dd5a833e | 10074 | numbers to an ascending order of stores. |
37119410 BS |
10075 | If CHECK_REGS is true, the sequence of registers in *REGS matches the stores |
10076 | from ascending memory locations, and the function verifies that the register | |
10077 | numbers are themselves ascending. If CHECK_REGS is false, the register | |
10078 | numbers are stored in the order they are found in the operands. */ | |
10079 | static int | |
10080 | store_multiple_sequence (rtx *operands, int nops, int nops_total, | |
10081 | int *regs, rtx *reg_rtxs, int *saved_order, int *base, | |
10082 | HOST_WIDE_INT *load_offset, bool check_regs) | |
84ed5e79 | 10083 | { |
93b338c3 | 10084 | int unsorted_regs[MAX_LDM_STM_OPS]; |
37119410 | 10085 | rtx unsorted_reg_rtxs[MAX_LDM_STM_OPS]; |
93b338c3 BS |
10086 | HOST_WIDE_INT unsorted_offsets[MAX_LDM_STM_OPS]; |
10087 | int order[MAX_LDM_STM_OPS]; | |
ad076f4e | 10088 | int base_reg = -1; |
37119410 | 10089 | rtx base_reg_rtx = NULL; |
93b338c3 | 10090 | int i, stm_case; |
84ed5e79 | 10091 | |
93b338c3 BS |
10092 | /* Can only handle up to MAX_LDM_STM_OPS insns at present, though could be |
10093 | easily extended if required. */ | |
10094 | gcc_assert (nops >= 2 && nops <= MAX_LDM_STM_OPS); | |
84ed5e79 | 10095 | |
93b338c3 | 10096 | memset (order, 0, MAX_LDM_STM_OPS * sizeof (int)); |
f0b4bdd5 | 10097 | |
84ed5e79 | 10098 | /* Loop over the operands and check that the memory references are |
112cdef5 | 10099 | suitable (i.e. immediate offsets from the same base register). At |
84ed5e79 RE |
10100 | the same time, extract the target register, and the memory |
10101 | offsets. */ | |
10102 | for (i = 0; i < nops; i++) | |
10103 | { | |
10104 | rtx reg; | |
10105 | rtx offset; | |
10106 | ||
56636818 JL |
10107 | /* Convert a subreg of a mem into the mem itself. */ |
10108 | if (GET_CODE (operands[nops + i]) == SUBREG) | |
4e26a7af | 10109 | operands[nops + i] = alter_subreg (operands + (nops + i)); |
56636818 | 10110 | |
e6d29d15 | 10111 | gcc_assert (GET_CODE (operands[nops + i]) == MEM); |
84ed5e79 RE |
10112 | |
10113 | /* Don't reorder volatile memory references; it doesn't seem worth | |
10114 | looking for the case where the order is ok anyway. */ | |
10115 | if (MEM_VOLATILE_P (operands[nops + i])) | |
10116 | return 0; | |
10117 | ||
10118 | offset = const0_rtx; | |
10119 | ||
10120 | if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG | |
10121 | || (GET_CODE (reg) == SUBREG | |
10122 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
10123 | || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS | |
10124 | && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0)) | |
10125 | == REG) | |
10126 | || (GET_CODE (reg) == SUBREG | |
10127 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
10128 | && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1)) | |
10129 | == CONST_INT))) | |
10130 | { | |
37119410 BS |
10131 | unsorted_reg_rtxs[i] = (GET_CODE (operands[i]) == REG |
10132 | ? operands[i] : SUBREG_REG (operands[i])); | |
10133 | unsorted_regs[i] = REGNO (unsorted_reg_rtxs[i]); | |
10134 | ||
84ed5e79 | 10135 | if (i == 0) |
37119410 BS |
10136 | { |
10137 | base_reg = REGNO (reg); | |
10138 | base_reg_rtx = reg; | |
10139 | if (TARGET_THUMB1 && base_reg > LAST_LO_REGNUM) | |
10140 | return 0; | |
10141 | } | |
93b338c3 BS |
10142 | else if (base_reg != (int) REGNO (reg)) |
10143 | /* Not addressed from the same base register. */ | |
10144 | return 0; | |
84ed5e79 RE |
10145 | |
10146 | /* If it isn't an integer register, then we can't do this. */ | |
37119410 BS |
10147 | if (unsorted_regs[i] < 0 |
10148 | || (TARGET_THUMB1 && unsorted_regs[i] > LAST_LO_REGNUM) | |
10149 | || (TARGET_THUMB2 && unsorted_regs[i] == base_reg) | |
10150 | || (TARGET_THUMB2 && unsorted_regs[i] == SP_REGNUM) | |
10151 | || unsorted_regs[i] > 14) | |
84ed5e79 RE |
10152 | return 0; |
10153 | ||
10154 | unsorted_offsets[i] = INTVAL (offset); | |
93b338c3 BS |
10155 | if (i == 0 || unsorted_offsets[i] < unsorted_offsets[order[0]]) |
10156 | order[0] = i; | |
84ed5e79 RE |
10157 | } |
10158 | else | |
10159 | /* Not a suitable memory address. */ | |
10160 | return 0; | |
10161 | } | |
10162 | ||
10163 | /* All the useful information has now been extracted from the | |
10164 | operands into unsorted_regs and unsorted_offsets; additionally, | |
93b338c3 BS |
10165 | order[0] has been set to the lowest offset in the list. Sort |
10166 | the offsets into order, verifying that they are adjacent, and | |
10167 | check that the register numbers are ascending. */ | |
37119410 BS |
10168 | if (!compute_offset_order (nops, unsorted_offsets, order, |
10169 | check_regs ? unsorted_regs : NULL)) | |
93b338c3 | 10170 | return 0; |
84ed5e79 | 10171 | |
37119410 BS |
10172 | if (saved_order) |
10173 | memcpy (saved_order, order, sizeof order); | |
10174 | ||
84ed5e79 RE |
10175 | if (base) |
10176 | { | |
10177 | *base = base_reg; | |
10178 | ||
10179 | for (i = 0; i < nops; i++) | |
37119410 BS |
10180 | { |
10181 | regs[i] = unsorted_regs[check_regs ? order[i] : i]; | |
10182 | if (reg_rtxs) | |
10183 | reg_rtxs[i] = unsorted_reg_rtxs[check_regs ? order[i] : i]; | |
10184 | } | |
84ed5e79 RE |
10185 | |
10186 | *load_offset = unsorted_offsets[order[0]]; | |
10187 | } | |
10188 | ||
37119410 BS |
10189 | if (TARGET_THUMB1 |
10190 | && !peep2_reg_dead_p (nops_total, base_reg_rtx)) | |
10191 | return 0; | |
10192 | ||
84ed5e79 | 10193 | if (unsorted_offsets[order[0]] == 0) |
93b338c3 BS |
10194 | stm_case = 1; /* stmia */ |
10195 | else if (TARGET_ARM && unsorted_offsets[order[0]] == 4) | |
10196 | stm_case = 2; /* stmib */ | |
10197 | else if (TARGET_ARM && unsorted_offsets[order[nops - 1]] == 0) | |
10198 | stm_case = 3; /* stmda */ | |
37119410 | 10199 | else if (TARGET_32BIT && unsorted_offsets[order[nops - 1]] == -4) |
93b338c3 BS |
10200 | stm_case = 4; /* stmdb */ |
10201 | else | |
10202 | return 0; | |
84ed5e79 | 10203 | |
93b338c3 BS |
10204 | if (!multiple_operation_profitable_p (false, nops, 0)) |
10205 | return 0; | |
84ed5e79 | 10206 | |
93b338c3 | 10207 | return stm_case; |
84ed5e79 | 10208 | } |
ff9940b0 | 10209 | \f |
6354dc9b | 10210 | /* Routines for use in generating RTL. */ |
1d6e90ac | 10211 | |
37119410 BS |
10212 | /* Generate a load-multiple instruction. COUNT is the number of loads in |
10213 | the instruction; REGS and MEMS are arrays containing the operands. | |
10214 | BASEREG is the base register to be used in addressing the memory operands. | |
10215 | WBACK_OFFSET is nonzero if the instruction should update the base | |
10216 | register. */ | |
10217 | ||
10218 | static rtx | |
10219 | arm_gen_load_multiple_1 (int count, int *regs, rtx *mems, rtx basereg, | |
10220 | HOST_WIDE_INT wback_offset) | |
ff9940b0 RE |
10221 | { |
10222 | int i = 0, j; | |
10223 | rtx result; | |
ff9940b0 | 10224 | |
8f4c6e28 | 10225 | if (!multiple_operation_profitable_p (false, count, 0)) |
d19fb8e3 NC |
10226 | { |
10227 | rtx seq; | |
f676971a | 10228 | |
d19fb8e3 | 10229 | start_sequence (); |
f676971a | 10230 | |
d19fb8e3 | 10231 | for (i = 0; i < count; i++) |
37119410 | 10232 | emit_move_insn (gen_rtx_REG (SImode, regs[i]), mems[i]); |
d19fb8e3 | 10233 | |
37119410 BS |
10234 | if (wback_offset != 0) |
10235 | emit_move_insn (basereg, plus_constant (basereg, wback_offset)); | |
d19fb8e3 | 10236 | |
2f937369 | 10237 | seq = get_insns (); |
d19fb8e3 | 10238 | end_sequence (); |
f676971a | 10239 | |
d19fb8e3 NC |
10240 | return seq; |
10241 | } | |
10242 | ||
43cffd11 | 10243 | result = gen_rtx_PARALLEL (VOIDmode, |
37119410 BS |
10244 | rtvec_alloc (count + (wback_offset != 0 ? 1 : 0))); |
10245 | if (wback_offset != 0) | |
f3bb6135 | 10246 | { |
ff9940b0 | 10247 | XVECEXP (result, 0, 0) |
37119410 BS |
10248 | = gen_rtx_SET (VOIDmode, basereg, |
10249 | plus_constant (basereg, wback_offset)); | |
ff9940b0 RE |
10250 | i = 1; |
10251 | count++; | |
f3bb6135 RE |
10252 | } |
10253 | ||
ff9940b0 | 10254 | for (j = 0; i < count; i++, j++) |
37119410 BS |
10255 | XVECEXP (result, 0, i) |
10256 | = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regs[j]), mems[j]); | |
50ed9cea | 10257 | |
ff9940b0 RE |
10258 | return result; |
10259 | } | |
10260 | ||
37119410 BS |
10261 | /* Generate a store-multiple instruction. COUNT is the number of stores in |
10262 | the instruction; REGS and MEMS are arrays containing the operands. | |
10263 | BASEREG is the base register to be used in addressing the memory operands. | |
10264 | WBACK_OFFSET is nonzero if the instruction should update the base | |
10265 | register. */ | |
10266 | ||
10267 | static rtx | |
10268 | arm_gen_store_multiple_1 (int count, int *regs, rtx *mems, rtx basereg, | |
10269 | HOST_WIDE_INT wback_offset) | |
ff9940b0 RE |
10270 | { |
10271 | int i = 0, j; | |
10272 | rtx result; | |
ff9940b0 | 10273 | |
37119410 BS |
10274 | if (GET_CODE (basereg) == PLUS) |
10275 | basereg = XEXP (basereg, 0); | |
10276 | ||
8f4c6e28 | 10277 | if (!multiple_operation_profitable_p (false, count, 0)) |
d19fb8e3 NC |
10278 | { |
10279 | rtx seq; | |
f676971a | 10280 | |
d19fb8e3 | 10281 | start_sequence (); |
f676971a | 10282 | |
d19fb8e3 | 10283 | for (i = 0; i < count; i++) |
37119410 | 10284 | emit_move_insn (mems[i], gen_rtx_REG (SImode, regs[i])); |
d19fb8e3 | 10285 | |
37119410 BS |
10286 | if (wback_offset != 0) |
10287 | emit_move_insn (basereg, plus_constant (basereg, wback_offset)); | |
d19fb8e3 | 10288 | |
2f937369 | 10289 | seq = get_insns (); |
d19fb8e3 | 10290 | end_sequence (); |
f676971a | 10291 | |
d19fb8e3 NC |
10292 | return seq; |
10293 | } | |
10294 | ||
43cffd11 | 10295 | result = gen_rtx_PARALLEL (VOIDmode, |
37119410 BS |
10296 | rtvec_alloc (count + (wback_offset != 0 ? 1 : 0))); |
10297 | if (wback_offset != 0) | |
f3bb6135 | 10298 | { |
ff9940b0 | 10299 | XVECEXP (result, 0, 0) |
37119410 BS |
10300 | = gen_rtx_SET (VOIDmode, basereg, |
10301 | plus_constant (basereg, wback_offset)); | |
ff9940b0 RE |
10302 | i = 1; |
10303 | count++; | |
f3bb6135 RE |
10304 | } |
10305 | ||
ff9940b0 | 10306 | for (j = 0; i < count; i++, j++) |
37119410 BS |
10307 | XVECEXP (result, 0, i) |
10308 | = gen_rtx_SET (VOIDmode, mems[j], gen_rtx_REG (SImode, regs[j])); | |
10309 | ||
10310 | return result; | |
10311 | } | |
10312 | ||
10313 | /* Generate either a load-multiple or a store-multiple instruction. This | |
10314 | function can be used in situations where we can start with a single MEM | |
10315 | rtx and adjust its address upwards. | |
10316 | COUNT is the number of operations in the instruction, not counting a | |
10317 | possible update of the base register. REGS is an array containing the | |
10318 | register operands. | |
10319 | BASEREG is the base register to be used in addressing the memory operands, | |
10320 | which are constructed from BASEMEM. | |
10321 | WRITE_BACK specifies whether the generated instruction should include an | |
10322 | update of the base register. | |
10323 | OFFSETP is used to pass an offset to and from this function; this offset | |
10324 | is not used when constructing the address (instead BASEMEM should have an | |
10325 | appropriate offset in its address), it is used only for setting | |
10326 | MEM_OFFSET. It is updated only if WRITE_BACK is true.*/ | |
10327 | ||
10328 | static rtx | |
10329 | arm_gen_multiple_op (bool is_load, int *regs, int count, rtx basereg, | |
10330 | bool write_back, rtx basemem, HOST_WIDE_INT *offsetp) | |
10331 | { | |
10332 | rtx mems[MAX_LDM_STM_OPS]; | |
10333 | HOST_WIDE_INT offset = *offsetp; | |
10334 | int i; | |
10335 | ||
10336 | gcc_assert (count <= MAX_LDM_STM_OPS); | |
10337 | ||
10338 | if (GET_CODE (basereg) == PLUS) | |
10339 | basereg = XEXP (basereg, 0); | |
10340 | ||
10341 | for (i = 0; i < count; i++) | |
f3bb6135 | 10342 | { |
37119410 BS |
10343 | rtx addr = plus_constant (basereg, i * 4); |
10344 | mems[i] = adjust_automodify_address_nv (basemem, SImode, addr, offset); | |
10345 | offset += 4; | |
f3bb6135 RE |
10346 | } |
10347 | ||
50ed9cea RH |
10348 | if (write_back) |
10349 | *offsetp = offset; | |
10350 | ||
37119410 BS |
10351 | if (is_load) |
10352 | return arm_gen_load_multiple_1 (count, regs, mems, basereg, | |
10353 | write_back ? 4 * count : 0); | |
10354 | else | |
10355 | return arm_gen_store_multiple_1 (count, regs, mems, basereg, | |
10356 | write_back ? 4 * count : 0); | |
10357 | } | |
10358 | ||
10359 | rtx | |
10360 | arm_gen_load_multiple (int *regs, int count, rtx basereg, int write_back, | |
10361 | rtx basemem, HOST_WIDE_INT *offsetp) | |
10362 | { | |
10363 | return arm_gen_multiple_op (TRUE, regs, count, basereg, write_back, basemem, | |
10364 | offsetp); | |
10365 | } | |
10366 | ||
10367 | rtx | |
10368 | arm_gen_store_multiple (int *regs, int count, rtx basereg, int write_back, | |
10369 | rtx basemem, HOST_WIDE_INT *offsetp) | |
10370 | { | |
10371 | return arm_gen_multiple_op (FALSE, regs, count, basereg, write_back, basemem, | |
10372 | offsetp); | |
10373 | } | |
10374 | ||
10375 | /* Called from a peephole2 expander to turn a sequence of loads into an | |
10376 | LDM instruction. OPERANDS are the operands found by the peephole matcher; | |
10377 | NOPS indicates how many separate loads we are trying to combine. SORT_REGS | |
10378 | is true if we can reorder the registers because they are used commutatively | |
10379 | subsequently. | |
10380 | Returns true iff we could generate a new instruction. */ | |
10381 | ||
10382 | bool | |
10383 | gen_ldm_seq (rtx *operands, int nops, bool sort_regs) | |
10384 | { | |
10385 | int regs[MAX_LDM_STM_OPS], mem_order[MAX_LDM_STM_OPS]; | |
10386 | rtx mems[MAX_LDM_STM_OPS]; | |
10387 | int i, j, base_reg; | |
10388 | rtx base_reg_rtx; | |
10389 | HOST_WIDE_INT offset; | |
10390 | int write_back = FALSE; | |
10391 | int ldm_case; | |
10392 | rtx addr; | |
10393 | ||
10394 | ldm_case = load_multiple_sequence (operands, nops, regs, mem_order, | |
10395 | &base_reg, &offset, !sort_regs); | |
10396 | ||
10397 | if (ldm_case == 0) | |
10398 | return false; | |
10399 | ||
10400 | if (sort_regs) | |
10401 | for (i = 0; i < nops - 1; i++) | |
10402 | for (j = i + 1; j < nops; j++) | |
10403 | if (regs[i] > regs[j]) | |
10404 | { | |
10405 | int t = regs[i]; | |
10406 | regs[i] = regs[j]; | |
10407 | regs[j] = t; | |
10408 | } | |
10409 | base_reg_rtx = gen_rtx_REG (Pmode, base_reg); | |
10410 | ||
10411 | if (TARGET_THUMB1) | |
10412 | { | |
10413 | gcc_assert (peep2_reg_dead_p (nops, base_reg_rtx)); | |
10414 | gcc_assert (ldm_case == 1 || ldm_case == 5); | |
10415 | write_back = TRUE; | |
10416 | } | |
10417 | ||
10418 | if (ldm_case == 5) | |
10419 | { | |
10420 | rtx newbase = TARGET_THUMB1 ? base_reg_rtx : gen_rtx_REG (SImode, regs[0]); | |
10421 | emit_insn (gen_addsi3 (newbase, base_reg_rtx, GEN_INT (offset))); | |
10422 | offset = 0; | |
10423 | if (!TARGET_THUMB1) | |
10424 | { | |
10425 | base_reg = regs[0]; | |
10426 | base_reg_rtx = newbase; | |
10427 | } | |
10428 | } | |
10429 | ||
10430 | for (i = 0; i < nops; i++) | |
10431 | { | |
10432 | addr = plus_constant (base_reg_rtx, offset + i * 4); | |
10433 | mems[i] = adjust_automodify_address_nv (operands[nops + mem_order[i]], | |
10434 | SImode, addr, 0); | |
10435 | } | |
10436 | emit_insn (arm_gen_load_multiple_1 (nops, regs, mems, base_reg_rtx, | |
10437 | write_back ? offset + i * 4 : 0)); | |
10438 | return true; | |
10439 | } | |
10440 | ||
10441 | /* Called from a peephole2 expander to turn a sequence of stores into an | |
10442 | STM instruction. OPERANDS are the operands found by the peephole matcher; | |
10443 | NOPS indicates how many separate stores we are trying to combine. | |
10444 | Returns true iff we could generate a new instruction. */ | |
10445 | ||
10446 | bool | |
10447 | gen_stm_seq (rtx *operands, int nops) | |
10448 | { | |
10449 | int i; | |
10450 | int regs[MAX_LDM_STM_OPS], mem_order[MAX_LDM_STM_OPS]; | |
10451 | rtx mems[MAX_LDM_STM_OPS]; | |
10452 | int base_reg; | |
10453 | rtx base_reg_rtx; | |
10454 | HOST_WIDE_INT offset; | |
10455 | int write_back = FALSE; | |
10456 | int stm_case; | |
10457 | rtx addr; | |
10458 | bool base_reg_dies; | |
10459 | ||
10460 | stm_case = store_multiple_sequence (operands, nops, nops, regs, NULL, | |
10461 | mem_order, &base_reg, &offset, true); | |
10462 | ||
10463 | if (stm_case == 0) | |
10464 | return false; | |
10465 | ||
10466 | base_reg_rtx = gen_rtx_REG (Pmode, base_reg); | |
10467 | ||
10468 | base_reg_dies = peep2_reg_dead_p (nops, base_reg_rtx); | |
10469 | if (TARGET_THUMB1) | |
10470 | { | |
10471 | gcc_assert (base_reg_dies); | |
10472 | write_back = TRUE; | |
10473 | } | |
10474 | ||
10475 | if (stm_case == 5) | |
10476 | { | |
10477 | gcc_assert (base_reg_dies); | |
10478 | emit_insn (gen_addsi3 (base_reg_rtx, base_reg_rtx, GEN_INT (offset))); | |
10479 | offset = 0; | |
10480 | } | |
10481 | ||
10482 | addr = plus_constant (base_reg_rtx, offset); | |
10483 | ||
10484 | for (i = 0; i < nops; i++) | |
10485 | { | |
10486 | addr = plus_constant (base_reg_rtx, offset + i * 4); | |
10487 | mems[i] = adjust_automodify_address_nv (operands[nops + mem_order[i]], | |
10488 | SImode, addr, 0); | |
10489 | } | |
10490 | emit_insn (arm_gen_store_multiple_1 (nops, regs, mems, base_reg_rtx, | |
10491 | write_back ? offset + i * 4 : 0)); | |
10492 | return true; | |
10493 | } | |
10494 | ||
10495 | /* Called from a peephole2 expander to turn a sequence of stores that are | |
10496 | preceded by constant loads into an STM instruction. OPERANDS are the | |
10497 | operands found by the peephole matcher; NOPS indicates how many | |
10498 | separate stores we are trying to combine; there are 2 * NOPS | |
10499 | instructions in the peephole. | |
10500 | Returns true iff we could generate a new instruction. */ | |
10501 | ||
10502 | bool | |
10503 | gen_const_stm_seq (rtx *operands, int nops) | |
10504 | { | |
10505 | int regs[MAX_LDM_STM_OPS], sorted_regs[MAX_LDM_STM_OPS]; | |
10506 | int reg_order[MAX_LDM_STM_OPS], mem_order[MAX_LDM_STM_OPS]; | |
10507 | rtx reg_rtxs[MAX_LDM_STM_OPS], orig_reg_rtxs[MAX_LDM_STM_OPS]; | |
10508 | rtx mems[MAX_LDM_STM_OPS]; | |
10509 | int base_reg; | |
10510 | rtx base_reg_rtx; | |
10511 | HOST_WIDE_INT offset; | |
10512 | int write_back = FALSE; | |
10513 | int stm_case; | |
10514 | rtx addr; | |
10515 | bool base_reg_dies; | |
10516 | int i, j; | |
10517 | HARD_REG_SET allocated; | |
10518 | ||
10519 | stm_case = store_multiple_sequence (operands, nops, 2 * nops, regs, reg_rtxs, | |
10520 | mem_order, &base_reg, &offset, false); | |
10521 | ||
10522 | if (stm_case == 0) | |
10523 | return false; | |
10524 | ||
10525 | memcpy (orig_reg_rtxs, reg_rtxs, sizeof orig_reg_rtxs); | |
10526 | ||
10527 | /* If the same register is used more than once, try to find a free | |
10528 | register. */ | |
10529 | CLEAR_HARD_REG_SET (allocated); | |
10530 | for (i = 0; i < nops; i++) | |
10531 | { | |
10532 | for (j = i + 1; j < nops; j++) | |
10533 | if (regs[i] == regs[j]) | |
10534 | { | |
10535 | rtx t = peep2_find_free_register (0, nops * 2, | |
10536 | TARGET_THUMB1 ? "l" : "r", | |
10537 | SImode, &allocated); | |
10538 | if (t == NULL_RTX) | |
10539 | return false; | |
10540 | reg_rtxs[i] = t; | |
10541 | regs[i] = REGNO (t); | |
10542 | } | |
10543 | } | |
10544 | ||
10545 | /* Compute an ordering that maps the register numbers to an ascending | |
10546 | sequence. */ | |
10547 | reg_order[0] = 0; | |
10548 | for (i = 0; i < nops; i++) | |
10549 | if (regs[i] < regs[reg_order[0]]) | |
10550 | reg_order[0] = i; | |
10551 | ||
10552 | for (i = 1; i < nops; i++) | |
10553 | { | |
10554 | int this_order = reg_order[i - 1]; | |
10555 | for (j = 0; j < nops; j++) | |
10556 | if (regs[j] > regs[reg_order[i - 1]] | |
10557 | && (this_order == reg_order[i - 1] | |
10558 | || regs[j] < regs[this_order])) | |
10559 | this_order = j; | |
10560 | reg_order[i] = this_order; | |
10561 | } | |
10562 | ||
10563 | /* Ensure that registers that must be live after the instruction end | |
10564 | up with the correct value. */ | |
10565 | for (i = 0; i < nops; i++) | |
10566 | { | |
10567 | int this_order = reg_order[i]; | |
10568 | if ((this_order != mem_order[i] | |
10569 | || orig_reg_rtxs[this_order] != reg_rtxs[this_order]) | |
10570 | && !peep2_reg_dead_p (nops * 2, orig_reg_rtxs[this_order])) | |
10571 | return false; | |
10572 | } | |
10573 | ||
10574 | /* Load the constants. */ | |
10575 | for (i = 0; i < nops; i++) | |
10576 | { | |
10577 | rtx op = operands[2 * nops + mem_order[i]]; | |
10578 | sorted_regs[i] = regs[reg_order[i]]; | |
10579 | emit_move_insn (reg_rtxs[reg_order[i]], op); | |
10580 | } | |
10581 | ||
10582 | base_reg_rtx = gen_rtx_REG (Pmode, base_reg); | |
10583 | ||
10584 | base_reg_dies = peep2_reg_dead_p (nops * 2, base_reg_rtx); | |
10585 | if (TARGET_THUMB1) | |
10586 | { | |
10587 | gcc_assert (base_reg_dies); | |
10588 | write_back = TRUE; | |
10589 | } | |
10590 | ||
10591 | if (stm_case == 5) | |
10592 | { | |
10593 | gcc_assert (base_reg_dies); | |
10594 | emit_insn (gen_addsi3 (base_reg_rtx, base_reg_rtx, GEN_INT (offset))); | |
10595 | offset = 0; | |
10596 | } | |
10597 | ||
10598 | addr = plus_constant (base_reg_rtx, offset); | |
10599 | ||
10600 | for (i = 0; i < nops; i++) | |
10601 | { | |
10602 | addr = plus_constant (base_reg_rtx, offset + i * 4); | |
10603 | mems[i] = adjust_automodify_address_nv (operands[nops + mem_order[i]], | |
10604 | SImode, addr, 0); | |
10605 | } | |
10606 | emit_insn (arm_gen_store_multiple_1 (nops, sorted_regs, mems, base_reg_rtx, | |
10607 | write_back ? offset + i * 4 : 0)); | |
10608 | return true; | |
ff9940b0 RE |
10609 | } |
10610 | ||
880e2516 | 10611 | int |
70128ad9 | 10612 | arm_gen_movmemqi (rtx *operands) |
880e2516 RE |
10613 | { |
10614 | HOST_WIDE_INT in_words_to_go, out_words_to_go, last_bytes; | |
50ed9cea | 10615 | HOST_WIDE_INT srcoffset, dstoffset; |
ad076f4e | 10616 | int i; |
50ed9cea | 10617 | rtx src, dst, srcbase, dstbase; |
880e2516 | 10618 | rtx part_bytes_reg = NULL; |
56636818 | 10619 | rtx mem; |
880e2516 RE |
10620 | |
10621 | if (GET_CODE (operands[2]) != CONST_INT | |
10622 | || GET_CODE (operands[3]) != CONST_INT | |
10623 | || INTVAL (operands[2]) > 64 | |
10624 | || INTVAL (operands[3]) & 3) | |
10625 | return 0; | |
10626 | ||
50ed9cea RH |
10627 | dstbase = operands[0]; |
10628 | srcbase = operands[1]; | |
56636818 | 10629 | |
50ed9cea RH |
10630 | dst = copy_to_mode_reg (SImode, XEXP (dstbase, 0)); |
10631 | src = copy_to_mode_reg (SImode, XEXP (srcbase, 0)); | |
880e2516 | 10632 | |
e9d7b180 | 10633 | in_words_to_go = ARM_NUM_INTS (INTVAL (operands[2])); |
880e2516 RE |
10634 | out_words_to_go = INTVAL (operands[2]) / 4; |
10635 | last_bytes = INTVAL (operands[2]) & 3; | |
50ed9cea | 10636 | dstoffset = srcoffset = 0; |
880e2516 RE |
10637 | |
10638 | if (out_words_to_go != in_words_to_go && ((in_words_to_go - 1) & 3) != 0) | |
43cffd11 | 10639 | part_bytes_reg = gen_rtx_REG (SImode, (in_words_to_go - 1) & 3); |
880e2516 RE |
10640 | |
10641 | for (i = 0; in_words_to_go >= 2; i+=4) | |
10642 | { | |
bd9c7e23 | 10643 | if (in_words_to_go > 4) |
37119410 BS |
10644 | emit_insn (arm_gen_load_multiple (arm_regs_in_sequence, 4, src, |
10645 | TRUE, srcbase, &srcoffset)); | |
bd9c7e23 | 10646 | else |
37119410 BS |
10647 | emit_insn (arm_gen_load_multiple (arm_regs_in_sequence, in_words_to_go, |
10648 | src, FALSE, srcbase, | |
10649 | &srcoffset)); | |
bd9c7e23 | 10650 | |
880e2516 RE |
10651 | if (out_words_to_go) |
10652 | { | |
bd9c7e23 | 10653 | if (out_words_to_go > 4) |
37119410 BS |
10654 | emit_insn (arm_gen_store_multiple (arm_regs_in_sequence, 4, dst, |
10655 | TRUE, dstbase, &dstoffset)); | |
bd9c7e23 | 10656 | else if (out_words_to_go != 1) |
37119410 BS |
10657 | emit_insn (arm_gen_store_multiple (arm_regs_in_sequence, |
10658 | out_words_to_go, dst, | |
bd9c7e23 | 10659 | (last_bytes == 0 |
56636818 | 10660 | ? FALSE : TRUE), |
50ed9cea | 10661 | dstbase, &dstoffset)); |
880e2516 RE |
10662 | else |
10663 | { | |
50ed9cea | 10664 | mem = adjust_automodify_address (dstbase, SImode, dst, dstoffset); |
43cffd11 | 10665 | emit_move_insn (mem, gen_rtx_REG (SImode, 0)); |
bd9c7e23 | 10666 | if (last_bytes != 0) |
50ed9cea RH |
10667 | { |
10668 | emit_insn (gen_addsi3 (dst, dst, GEN_INT (4))); | |
10669 | dstoffset += 4; | |
10670 | } | |
880e2516 RE |
10671 | } |
10672 | } | |
10673 | ||
10674 | in_words_to_go -= in_words_to_go < 4 ? in_words_to_go : 4; | |
10675 | out_words_to_go -= out_words_to_go < 4 ? out_words_to_go : 4; | |
10676 | } | |
10677 | ||
10678 | /* OUT_WORDS_TO_GO will be zero here if there are byte stores to do. */ | |
10679 | if (out_words_to_go) | |
62b10bbc NC |
10680 | { |
10681 | rtx sreg; | |
f676971a | 10682 | |
50ed9cea RH |
10683 | mem = adjust_automodify_address (srcbase, SImode, src, srcoffset); |
10684 | sreg = copy_to_reg (mem); | |
10685 | ||
10686 | mem = adjust_automodify_address (dstbase, SImode, dst, dstoffset); | |
62b10bbc | 10687 | emit_move_insn (mem, sreg); |
62b10bbc | 10688 | in_words_to_go--; |
f676971a | 10689 | |
e6d29d15 | 10690 | gcc_assert (!in_words_to_go); /* Sanity check */ |
62b10bbc | 10691 | } |
880e2516 RE |
10692 | |
10693 | if (in_words_to_go) | |
10694 | { | |
e6d29d15 | 10695 | gcc_assert (in_words_to_go > 0); |
880e2516 | 10696 | |
50ed9cea | 10697 | mem = adjust_automodify_address (srcbase, SImode, src, srcoffset); |
56636818 | 10698 | part_bytes_reg = copy_to_mode_reg (SImode, mem); |
880e2516 RE |
10699 | } |
10700 | ||
e6d29d15 | 10701 | gcc_assert (!last_bytes || part_bytes_reg); |
d5b7b3ae | 10702 | |
880e2516 RE |
10703 | if (BYTES_BIG_ENDIAN && last_bytes) |
10704 | { | |
10705 | rtx tmp = gen_reg_rtx (SImode); | |
10706 | ||
6354dc9b | 10707 | /* The bytes we want are in the top end of the word. */ |
bee06f3d RE |
10708 | emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, |
10709 | GEN_INT (8 * (4 - last_bytes)))); | |
880e2516 | 10710 | part_bytes_reg = tmp; |
f676971a | 10711 | |
880e2516 RE |
10712 | while (last_bytes) |
10713 | { | |
50ed9cea RH |
10714 | mem = adjust_automodify_address (dstbase, QImode, |
10715 | plus_constant (dst, last_bytes - 1), | |
10716 | dstoffset + last_bytes - 1); | |
5d5603e2 BS |
10717 | emit_move_insn (mem, gen_lowpart (QImode, part_bytes_reg)); |
10718 | ||
880e2516 RE |
10719 | if (--last_bytes) |
10720 | { | |
10721 | tmp = gen_reg_rtx (SImode); | |
10722 | emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8))); | |
10723 | part_bytes_reg = tmp; | |
10724 | } | |
10725 | } | |
f676971a | 10726 | |
880e2516 RE |
10727 | } |
10728 | else | |
10729 | { | |
d5b7b3ae | 10730 | if (last_bytes > 1) |
880e2516 | 10731 | { |
50ed9cea | 10732 | mem = adjust_automodify_address (dstbase, HImode, dst, dstoffset); |
5d5603e2 | 10733 | emit_move_insn (mem, gen_lowpart (HImode, part_bytes_reg)); |
d5b7b3ae RE |
10734 | last_bytes -= 2; |
10735 | if (last_bytes) | |
880e2516 RE |
10736 | { |
10737 | rtx tmp = gen_reg_rtx (SImode); | |
a556fd39 | 10738 | emit_insn (gen_addsi3 (dst, dst, const2_rtx)); |
d5b7b3ae | 10739 | emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (16))); |
880e2516 | 10740 | part_bytes_reg = tmp; |
50ed9cea | 10741 | dstoffset += 2; |
880e2516 RE |
10742 | } |
10743 | } | |
f676971a | 10744 | |
d5b7b3ae RE |
10745 | if (last_bytes) |
10746 | { | |
50ed9cea | 10747 | mem = adjust_automodify_address (dstbase, QImode, dst, dstoffset); |
5d5603e2 | 10748 | emit_move_insn (mem, gen_lowpart (QImode, part_bytes_reg)); |
d5b7b3ae | 10749 | } |
880e2516 RE |
10750 | } |
10751 | ||
10752 | return 1; | |
10753 | } | |
10754 | ||
03f1640c RE |
10755 | /* Select a dominance comparison mode if possible for a test of the general |
10756 | form (OP (COND_OR (X) (Y)) (const_int 0)). We support three forms. | |
f676971a | 10757 | COND_OR == DOM_CC_X_AND_Y => (X && Y) |
03f1640c | 10758 | COND_OR == DOM_CC_NX_OR_Y => ((! X) || Y) |
f676971a | 10759 | COND_OR == DOM_CC_X_OR_Y => (X || Y) |
03f1640c | 10760 | In all cases OP will be either EQ or NE, but we don't need to know which |
f676971a | 10761 | here. If we are unable to support a dominance comparison we return |
03f1640c RE |
10762 | CC mode. This will then fail to match for the RTL expressions that |
10763 | generate this call. */ | |
03f1640c | 10764 | enum machine_mode |
e32bac5b | 10765 | arm_select_dominance_cc_mode (rtx x, rtx y, HOST_WIDE_INT cond_or) |
84ed5e79 RE |
10766 | { |
10767 | enum rtx_code cond1, cond2; | |
10768 | int swapped = 0; | |
10769 | ||
10770 | /* Currently we will probably get the wrong result if the individual | |
10771 | comparisons are not simple. This also ensures that it is safe to | |
956d6950 | 10772 | reverse a comparison if necessary. */ |
84ed5e79 RE |
10773 | if ((arm_select_cc_mode (cond1 = GET_CODE (x), XEXP (x, 0), XEXP (x, 1)) |
10774 | != CCmode) | |
10775 | || (arm_select_cc_mode (cond2 = GET_CODE (y), XEXP (y, 0), XEXP (y, 1)) | |
10776 | != CCmode)) | |
10777 | return CCmode; | |
10778 | ||
1646cf41 RE |
10779 | /* The if_then_else variant of this tests the second condition if the |
10780 | first passes, but is true if the first fails. Reverse the first | |
10781 | condition to get a true "inclusive-or" expression. */ | |
03f1640c | 10782 | if (cond_or == DOM_CC_NX_OR_Y) |
84ed5e79 RE |
10783 | cond1 = reverse_condition (cond1); |
10784 | ||
10785 | /* If the comparisons are not equal, and one doesn't dominate the other, | |
10786 | then we can't do this. */ | |
f676971a | 10787 | if (cond1 != cond2 |
5895f793 RE |
10788 | && !comparison_dominates_p (cond1, cond2) |
10789 | && (swapped = 1, !comparison_dominates_p (cond2, cond1))) | |
84ed5e79 RE |
10790 | return CCmode; |
10791 | ||
10792 | if (swapped) | |
10793 | { | |
10794 | enum rtx_code temp = cond1; | |
10795 | cond1 = cond2; | |
10796 | cond2 = temp; | |
10797 | } | |
10798 | ||
10799 | switch (cond1) | |
10800 | { | |
10801 | case EQ: | |
e6d29d15 | 10802 | if (cond_or == DOM_CC_X_AND_Y) |
84ed5e79 RE |
10803 | return CC_DEQmode; |
10804 | ||
10805 | switch (cond2) | |
10806 | { | |
e6d29d15 | 10807 | case EQ: return CC_DEQmode; |
84ed5e79 RE |
10808 | case LE: return CC_DLEmode; |
10809 | case LEU: return CC_DLEUmode; | |
10810 | case GE: return CC_DGEmode; | |
10811 | case GEU: return CC_DGEUmode; | |
e6d29d15 | 10812 | default: gcc_unreachable (); |
84ed5e79 RE |
10813 | } |
10814 | ||
84ed5e79 | 10815 | case LT: |
e6d29d15 | 10816 | if (cond_or == DOM_CC_X_AND_Y) |
84ed5e79 | 10817 | return CC_DLTmode; |
e0b92319 | 10818 | |
e6d29d15 NS |
10819 | switch (cond2) |
10820 | { | |
10821 | case LT: | |
10822 | return CC_DLTmode; | |
10823 | case LE: | |
10824 | return CC_DLEmode; | |
10825 | case NE: | |
10826 | return CC_DNEmode; | |
10827 | default: | |
10828 | gcc_unreachable (); | |
10829 | } | |
84ed5e79 RE |
10830 | |
10831 | case GT: | |
e6d29d15 | 10832 | if (cond_or == DOM_CC_X_AND_Y) |
84ed5e79 | 10833 | return CC_DGTmode; |
e6d29d15 NS |
10834 | |
10835 | switch (cond2) | |
10836 | { | |
10837 | case GT: | |
10838 | return CC_DGTmode; | |
10839 | case GE: | |
10840 | return CC_DGEmode; | |
10841 | case NE: | |
10842 | return CC_DNEmode; | |
10843 | default: | |
10844 | gcc_unreachable (); | |
10845 | } | |
f676971a | 10846 | |
84ed5e79 | 10847 | case LTU: |
e6d29d15 | 10848 | if (cond_or == DOM_CC_X_AND_Y) |
84ed5e79 | 10849 | return CC_DLTUmode; |
e6d29d15 NS |
10850 | |
10851 | switch (cond2) | |
10852 | { | |
10853 | case LTU: | |
10854 | return CC_DLTUmode; | |
10855 | case LEU: | |
10856 | return CC_DLEUmode; | |
10857 | case NE: | |
10858 | return CC_DNEmode; | |
10859 | default: | |
10860 | gcc_unreachable (); | |
10861 | } | |
84ed5e79 RE |
10862 | |
10863 | case GTU: | |
e6d29d15 | 10864 | if (cond_or == DOM_CC_X_AND_Y) |
84ed5e79 | 10865 | return CC_DGTUmode; |
e0b92319 | 10866 | |
e6d29d15 NS |
10867 | switch (cond2) |
10868 | { | |
10869 | case GTU: | |
10870 | return CC_DGTUmode; | |
10871 | case GEU: | |
10872 | return CC_DGEUmode; | |
10873 | case NE: | |
10874 | return CC_DNEmode; | |
10875 | default: | |
10876 | gcc_unreachable (); | |
10877 | } | |
84ed5e79 RE |
10878 | |
10879 | /* The remaining cases only occur when both comparisons are the | |
10880 | same. */ | |
10881 | case NE: | |
e6d29d15 | 10882 | gcc_assert (cond1 == cond2); |
84ed5e79 RE |
10883 | return CC_DNEmode; |
10884 | ||
10885 | case LE: | |
e6d29d15 | 10886 | gcc_assert (cond1 == cond2); |
84ed5e79 RE |
10887 | return CC_DLEmode; |
10888 | ||
10889 | case GE: | |
e6d29d15 | 10890 | gcc_assert (cond1 == cond2); |
84ed5e79 RE |
10891 | return CC_DGEmode; |
10892 | ||
10893 | case LEU: | |
e6d29d15 | 10894 | gcc_assert (cond1 == cond2); |
84ed5e79 RE |
10895 | return CC_DLEUmode; |
10896 | ||
10897 | case GEU: | |
e6d29d15 | 10898 | gcc_assert (cond1 == cond2); |
84ed5e79 | 10899 | return CC_DGEUmode; |
ad076f4e RE |
10900 | |
10901 | default: | |
e6d29d15 | 10902 | gcc_unreachable (); |
84ed5e79 | 10903 | } |
84ed5e79 RE |
10904 | } |
10905 | ||
10906 | enum machine_mode | |
e32bac5b | 10907 | arm_select_cc_mode (enum rtx_code op, rtx x, rtx y) |
84ed5e79 RE |
10908 | { |
10909 | /* All floating point compares return CCFP if it is an equality | |
10910 | comparison, and CCFPE otherwise. */ | |
10911 | if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) | |
e45b72c4 RE |
10912 | { |
10913 | switch (op) | |
10914 | { | |
10915 | case EQ: | |
10916 | case NE: | |
10917 | case UNORDERED: | |
10918 | case ORDERED: | |
10919 | case UNLT: | |
10920 | case UNLE: | |
10921 | case UNGT: | |
10922 | case UNGE: | |
10923 | case UNEQ: | |
10924 | case LTGT: | |
10925 | return CCFPmode; | |
10926 | ||
10927 | case LT: | |
10928 | case LE: | |
10929 | case GT: | |
10930 | case GE: | |
9b66ebb1 | 10931 | if (TARGET_HARD_FLOAT && TARGET_MAVERICK) |
9b6b54e2 | 10932 | return CCFPmode; |
e45b72c4 RE |
10933 | return CCFPEmode; |
10934 | ||
10935 | default: | |
e6d29d15 | 10936 | gcc_unreachable (); |
e45b72c4 RE |
10937 | } |
10938 | } | |
f676971a | 10939 | |
84ed5e79 RE |
10940 | /* A compare with a shifted operand. Because of canonicalization, the |
10941 | comparison will have to be swapped when we emit the assembler. */ | |
3e2d9dcf RR |
10942 | if (GET_MODE (y) == SImode |
10943 | && (REG_P (y) || (GET_CODE (y) == SUBREG)) | |
84ed5e79 RE |
10944 | && (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT |
10945 | || GET_CODE (x) == LSHIFTRT || GET_CODE (x) == ROTATE | |
10946 | || GET_CODE (x) == ROTATERT)) | |
10947 | return CC_SWPmode; | |
10948 | ||
04d8b819 RE |
10949 | /* This operation is performed swapped, but since we only rely on the Z |
10950 | flag we don't need an additional mode. */ | |
3e2d9dcf RR |
10951 | if (GET_MODE (y) == SImode |
10952 | && (REG_P (y) || (GET_CODE (y) == SUBREG)) | |
04d8b819 RE |
10953 | && GET_CODE (x) == NEG |
10954 | && (op == EQ || op == NE)) | |
10955 | return CC_Zmode; | |
10956 | ||
f676971a | 10957 | /* This is a special case that is used by combine to allow a |
956d6950 | 10958 | comparison of a shifted byte load to be split into a zero-extend |
84ed5e79 | 10959 | followed by a comparison of the shifted integer (only valid for |
956d6950 | 10960 | equalities and unsigned inequalities). */ |
84ed5e79 RE |
10961 | if (GET_MODE (x) == SImode |
10962 | && GET_CODE (x) == ASHIFT | |
10963 | && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 24 | |
10964 | && GET_CODE (XEXP (x, 0)) == SUBREG | |
10965 | && GET_CODE (SUBREG_REG (XEXP (x, 0))) == MEM | |
10966 | && GET_MODE (SUBREG_REG (XEXP (x, 0))) == QImode | |
10967 | && (op == EQ || op == NE | |
10968 | || op == GEU || op == GTU || op == LTU || op == LEU) | |
10969 | && GET_CODE (y) == CONST_INT) | |
10970 | return CC_Zmode; | |
10971 | ||
1646cf41 RE |
10972 | /* A construct for a conditional compare, if the false arm contains |
10973 | 0, then both conditions must be true, otherwise either condition | |
10974 | must be true. Not all conditions are possible, so CCmode is | |
10975 | returned if it can't be done. */ | |
10976 | if (GET_CODE (x) == IF_THEN_ELSE | |
10977 | && (XEXP (x, 2) == const0_rtx | |
10978 | || XEXP (x, 2) == const1_rtx) | |
ec8e098d PB |
10979 | && COMPARISON_P (XEXP (x, 0)) |
10980 | && COMPARISON_P (XEXP (x, 1))) | |
f676971a | 10981 | return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), |
03f1640c | 10982 | INTVAL (XEXP (x, 2))); |
1646cf41 RE |
10983 | |
10984 | /* Alternate canonicalizations of the above. These are somewhat cleaner. */ | |
10985 | if (GET_CODE (x) == AND | |
4d5d6586 | 10986 | && (op == EQ || op == NE) |
ec8e098d PB |
10987 | && COMPARISON_P (XEXP (x, 0)) |
10988 | && COMPARISON_P (XEXP (x, 1))) | |
03f1640c RE |
10989 | return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), |
10990 | DOM_CC_X_AND_Y); | |
1646cf41 RE |
10991 | |
10992 | if (GET_CODE (x) == IOR | |
4d5d6586 | 10993 | && (op == EQ || op == NE) |
ec8e098d PB |
10994 | && COMPARISON_P (XEXP (x, 0)) |
10995 | && COMPARISON_P (XEXP (x, 1))) | |
03f1640c RE |
10996 | return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), |
10997 | DOM_CC_X_OR_Y); | |
1646cf41 | 10998 | |
defc0463 RE |
10999 | /* An operation (on Thumb) where we want to test for a single bit. |
11000 | This is done by shifting that bit up into the top bit of a | |
11001 | scratch register; we can then branch on the sign bit. */ | |
5b3e6663 | 11002 | if (TARGET_THUMB1 |
defc0463 RE |
11003 | && GET_MODE (x) == SImode |
11004 | && (op == EQ || op == NE) | |
f9fa4363 RE |
11005 | && GET_CODE (x) == ZERO_EXTRACT |
11006 | && XEXP (x, 1) == const1_rtx) | |
defc0463 RE |
11007 | return CC_Nmode; |
11008 | ||
84ed5e79 RE |
11009 | /* An operation that sets the condition codes as a side-effect, the |
11010 | V flag is not set correctly, so we can only use comparisons where | |
11011 | this doesn't matter. (For LT and GE we can use "mi" and "pl" | |
defc0463 | 11012 | instead.) */ |
5b3e6663 | 11013 | /* ??? Does the ZERO_EXTRACT case really apply to thumb2? */ |
84ed5e79 RE |
11014 | if (GET_MODE (x) == SImode |
11015 | && y == const0_rtx | |
11016 | && (op == EQ || op == NE || op == LT || op == GE) | |
11017 | && (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS | |
11018 | || GET_CODE (x) == AND || GET_CODE (x) == IOR | |
11019 | || GET_CODE (x) == XOR || GET_CODE (x) == MULT | |
11020 | || GET_CODE (x) == NOT || GET_CODE (x) == NEG | |
11021 | || GET_CODE (x) == LSHIFTRT | |
11022 | || GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT | |
defc0463 | 11023 | || GET_CODE (x) == ROTATERT |
5b3e6663 | 11024 | || (TARGET_32BIT && GET_CODE (x) == ZERO_EXTRACT))) |
84ed5e79 RE |
11025 | return CC_NOOVmode; |
11026 | ||
84ed5e79 RE |
11027 | if (GET_MODE (x) == QImode && (op == EQ || op == NE)) |
11028 | return CC_Zmode; | |
11029 | ||
bd9c7e23 RE |
11030 | if (GET_MODE (x) == SImode && (op == LTU || op == GEU) |
11031 | && GET_CODE (x) == PLUS | |
11032 | && (rtx_equal_p (XEXP (x, 0), y) || rtx_equal_p (XEXP (x, 1), y))) | |
11033 | return CC_Cmode; | |
11034 | ||
73160ba9 DJ |
11035 | if (GET_MODE (x) == DImode || GET_MODE (y) == DImode) |
11036 | { | |
11037 | /* To keep things simple, always use the Cirrus cfcmp64 if it is | |
11038 | available. */ | |
11039 | if (TARGET_ARM && TARGET_HARD_FLOAT && TARGET_MAVERICK) | |
11040 | return CCmode; | |
11041 | ||
11042 | switch (op) | |
11043 | { | |
11044 | case EQ: | |
11045 | case NE: | |
11046 | /* A DImode comparison against zero can be implemented by | |
11047 | or'ing the two halves together. */ | |
11048 | if (y == const0_rtx) | |
11049 | return CC_Zmode; | |
11050 | ||
11051 | /* We can do an equality test in three Thumb instructions. */ | |
11052 | if (!TARGET_ARM) | |
11053 | return CC_Zmode; | |
11054 | ||
11055 | /* FALLTHROUGH */ | |
11056 | ||
11057 | case LTU: | |
11058 | case LEU: | |
11059 | case GTU: | |
11060 | case GEU: | |
11061 | /* DImode unsigned comparisons can be implemented by cmp + | |
11062 | cmpeq without a scratch register. Not worth doing in | |
11063 | Thumb-2. */ | |
11064 | if (TARGET_ARM) | |
11065 | return CC_CZmode; | |
11066 | ||
11067 | /* FALLTHROUGH */ | |
11068 | ||
11069 | case LT: | |
11070 | case LE: | |
11071 | case GT: | |
11072 | case GE: | |
11073 | /* DImode signed and unsigned comparisons can be implemented | |
11074 | by cmp + sbcs with a scratch register, but that does not | |
11075 | set the Z flag - we must reverse GT/LE/GTU/LEU. */ | |
11076 | gcc_assert (op != EQ && op != NE); | |
11077 | return CC_NCVmode; | |
11078 | ||
11079 | default: | |
11080 | gcc_unreachable (); | |
11081 | } | |
11082 | } | |
11083 | ||
84ed5e79 RE |
11084 | return CCmode; |
11085 | } | |
11086 | ||
ff9940b0 RE |
11087 | /* X and Y are two things to compare using CODE. Emit the compare insn and |
11088 | return the rtx for register 0 in the proper mode. FP means this is a | |
11089 | floating point compare: I don't think that it is needed on the arm. */ | |
ff9940b0 | 11090 | rtx |
e32bac5b | 11091 | arm_gen_compare_reg (enum rtx_code code, rtx x, rtx y) |
ff9940b0 | 11092 | { |
73160ba9 DJ |
11093 | enum machine_mode mode; |
11094 | rtx cc_reg; | |
11095 | int dimode_comparison = GET_MODE (x) == DImode || GET_MODE (y) == DImode; | |
ff9940b0 | 11096 | |
73160ba9 DJ |
11097 | /* We might have X as a constant, Y as a register because of the predicates |
11098 | used for cmpdi. If so, force X to a register here. */ | |
11099 | if (dimode_comparison && !REG_P (x)) | |
11100 | x = force_reg (DImode, x); | |
11101 | ||
11102 | mode = SELECT_CC_MODE (code, x, y); | |
11103 | cc_reg = gen_rtx_REG (mode, CC_REGNUM); | |
11104 | ||
11105 | if (dimode_comparison | |
11106 | && !(TARGET_HARD_FLOAT && TARGET_MAVERICK) | |
11107 | && mode != CC_CZmode) | |
11108 | { | |
11109 | rtx clobber, set; | |
11110 | ||
11111 | /* To compare two non-zero values for equality, XOR them and | |
11112 | then compare against zero. Not used for ARM mode; there | |
11113 | CC_CZmode is cheaper. */ | |
11114 | if (mode == CC_Zmode && y != const0_rtx) | |
11115 | { | |
11116 | x = expand_binop (DImode, xor_optab, x, y, NULL_RTX, 0, OPTAB_WIDEN); | |
11117 | y = const0_rtx; | |
11118 | } | |
11119 | /* A scratch register is required. */ | |
11120 | clobber = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)); | |
11121 | set = gen_rtx_SET (VOIDmode, cc_reg, gen_rtx_COMPARE (mode, x, y)); | |
11122 | emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber))); | |
11123 | } | |
11124 | else | |
11125 | emit_set_insn (cc_reg, gen_rtx_COMPARE (mode, x, y)); | |
ff9940b0 RE |
11126 | |
11127 | return cc_reg; | |
11128 | } | |
11129 | ||
fcd53748 JT |
11130 | /* Generate a sequence of insns that will generate the correct return |
11131 | address mask depending on the physical architecture that the program | |
11132 | is running on. */ | |
fcd53748 | 11133 | rtx |
e32bac5b | 11134 | arm_gen_return_addr_mask (void) |
fcd53748 JT |
11135 | { |
11136 | rtx reg = gen_reg_rtx (Pmode); | |
11137 | ||
11138 | emit_insn (gen_return_addr_mask (reg)); | |
11139 | return reg; | |
11140 | } | |
11141 | ||
0a81f500 | 11142 | void |
e32bac5b | 11143 | arm_reload_in_hi (rtx *operands) |
0a81f500 | 11144 | { |
f9cc092a RE |
11145 | rtx ref = operands[1]; |
11146 | rtx base, scratch; | |
11147 | HOST_WIDE_INT offset = 0; | |
11148 | ||
11149 | if (GET_CODE (ref) == SUBREG) | |
11150 | { | |
ddef6bc7 | 11151 | offset = SUBREG_BYTE (ref); |
f9cc092a RE |
11152 | ref = SUBREG_REG (ref); |
11153 | } | |
11154 | ||
11155 | if (GET_CODE (ref) == REG) | |
11156 | { | |
11157 | /* We have a pseudo which has been spilt onto the stack; there | |
11158 | are two cases here: the first where there is a simple | |
11159 | stack-slot replacement and a second where the stack-slot is | |
11160 | out of range, or is used as a subreg. */ | |
f2034d06 | 11161 | if (reg_equiv_mem (REGNO (ref))) |
f9cc092a | 11162 | { |
f2034d06 | 11163 | ref = reg_equiv_mem (REGNO (ref)); |
f9cc092a RE |
11164 | base = find_replacement (&XEXP (ref, 0)); |
11165 | } | |
11166 | else | |
6354dc9b | 11167 | /* The slot is out of range, or was dressed up in a SUBREG. */ |
f2034d06 | 11168 | base = reg_equiv_address (REGNO (ref)); |
f9cc092a RE |
11169 | } |
11170 | else | |
11171 | base = find_replacement (&XEXP (ref, 0)); | |
0a81f500 | 11172 | |
e5e809f4 JL |
11173 | /* Handle the case where the address is too complex to be offset by 1. */ |
11174 | if (GET_CODE (base) == MINUS | |
11175 | || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT)) | |
11176 | { | |
f9cc092a | 11177 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); |
e5e809f4 | 11178 | |
d66437c5 | 11179 | emit_set_insn (base_plus, base); |
e5e809f4 JL |
11180 | base = base_plus; |
11181 | } | |
f9cc092a RE |
11182 | else if (GET_CODE (base) == PLUS) |
11183 | { | |
6354dc9b | 11184 | /* The addend must be CONST_INT, or we would have dealt with it above. */ |
f9cc092a RE |
11185 | HOST_WIDE_INT hi, lo; |
11186 | ||
11187 | offset += INTVAL (XEXP (base, 1)); | |
11188 | base = XEXP (base, 0); | |
11189 | ||
6354dc9b | 11190 | /* Rework the address into a legal sequence of insns. */ |
f9cc092a RE |
11191 | /* Valid range for lo is -4095 -> 4095 */ |
11192 | lo = (offset >= 0 | |
11193 | ? (offset & 0xfff) | |
11194 | : -((-offset) & 0xfff)); | |
11195 | ||
11196 | /* Corner case, if lo is the max offset then we would be out of range | |
11197 | once we have added the additional 1 below, so bump the msb into the | |
11198 | pre-loading insn(s). */ | |
11199 | if (lo == 4095) | |
11200 | lo &= 0x7ff; | |
11201 | ||
30cf4896 KG |
11202 | hi = ((((offset - lo) & (HOST_WIDE_INT) 0xffffffff) |
11203 | ^ (HOST_WIDE_INT) 0x80000000) | |
11204 | - (HOST_WIDE_INT) 0x80000000); | |
f9cc092a | 11205 | |
e6d29d15 | 11206 | gcc_assert (hi + lo == offset); |
f9cc092a RE |
11207 | |
11208 | if (hi != 0) | |
11209 | { | |
11210 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
11211 | ||
11212 | /* Get the base address; addsi3 knows how to handle constants | |
6354dc9b | 11213 | that require more than one insn. */ |
f9cc092a RE |
11214 | emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi))); |
11215 | base = base_plus; | |
11216 | offset = lo; | |
11217 | } | |
11218 | } | |
e5e809f4 | 11219 | |
3a1944a6 RE |
11220 | /* Operands[2] may overlap operands[0] (though it won't overlap |
11221 | operands[1]), that's why we asked for a DImode reg -- so we can | |
11222 | use the bit that does not overlap. */ | |
11223 | if (REGNO (operands[2]) == REGNO (operands[0])) | |
11224 | scratch = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
11225 | else | |
11226 | scratch = gen_rtx_REG (SImode, REGNO (operands[2])); | |
11227 | ||
f9cc092a RE |
11228 | emit_insn (gen_zero_extendqisi2 (scratch, |
11229 | gen_rtx_MEM (QImode, | |
11230 | plus_constant (base, | |
11231 | offset)))); | |
43cffd11 | 11232 | emit_insn (gen_zero_extendqisi2 (gen_rtx_SUBREG (SImode, operands[0], 0), |
f676971a | 11233 | gen_rtx_MEM (QImode, |
f9cc092a RE |
11234 | plus_constant (base, |
11235 | offset + 1)))); | |
5895f793 | 11236 | if (!BYTES_BIG_ENDIAN) |
d66437c5 RE |
11237 | emit_set_insn (gen_rtx_SUBREG (SImode, operands[0], 0), |
11238 | gen_rtx_IOR (SImode, | |
11239 | gen_rtx_ASHIFT | |
11240 | (SImode, | |
11241 | gen_rtx_SUBREG (SImode, operands[0], 0), | |
11242 | GEN_INT (8)), | |
11243 | scratch)); | |
0a81f500 | 11244 | else |
d66437c5 RE |
11245 | emit_set_insn (gen_rtx_SUBREG (SImode, operands[0], 0), |
11246 | gen_rtx_IOR (SImode, | |
11247 | gen_rtx_ASHIFT (SImode, scratch, | |
11248 | GEN_INT (8)), | |
11249 | gen_rtx_SUBREG (SImode, operands[0], 0))); | |
0a81f500 RE |
11250 | } |
11251 | ||
72ac76be | 11252 | /* Handle storing a half-word to memory during reload by synthesizing as two |
f9cc092a RE |
11253 | byte stores. Take care not to clobber the input values until after we |
11254 | have moved them somewhere safe. This code assumes that if the DImode | |
11255 | scratch in operands[2] overlaps either the input value or output address | |
11256 | in some way, then that value must die in this insn (we absolutely need | |
11257 | two scratch registers for some corner cases). */ | |
f3bb6135 | 11258 | void |
e32bac5b | 11259 | arm_reload_out_hi (rtx *operands) |
af48348a | 11260 | { |
f9cc092a RE |
11261 | rtx ref = operands[0]; |
11262 | rtx outval = operands[1]; | |
11263 | rtx base, scratch; | |
11264 | HOST_WIDE_INT offset = 0; | |
11265 | ||
11266 | if (GET_CODE (ref) == SUBREG) | |
11267 | { | |
ddef6bc7 | 11268 | offset = SUBREG_BYTE (ref); |
f9cc092a RE |
11269 | ref = SUBREG_REG (ref); |
11270 | } | |
11271 | ||
f9cc092a RE |
11272 | if (GET_CODE (ref) == REG) |
11273 | { | |
11274 | /* We have a pseudo which has been spilt onto the stack; there | |
11275 | are two cases here: the first where there is a simple | |
11276 | stack-slot replacement and a second where the stack-slot is | |
11277 | out of range, or is used as a subreg. */ | |
f2034d06 | 11278 | if (reg_equiv_mem (REGNO (ref))) |
f9cc092a | 11279 | { |
f2034d06 | 11280 | ref = reg_equiv_mem (REGNO (ref)); |
f9cc092a RE |
11281 | base = find_replacement (&XEXP (ref, 0)); |
11282 | } | |
11283 | else | |
6354dc9b | 11284 | /* The slot is out of range, or was dressed up in a SUBREG. */ |
f2034d06 | 11285 | base = reg_equiv_address (REGNO (ref)); |
f9cc092a RE |
11286 | } |
11287 | else | |
11288 | base = find_replacement (&XEXP (ref, 0)); | |
11289 | ||
11290 | scratch = gen_rtx_REG (SImode, REGNO (operands[2])); | |
11291 | ||
11292 | /* Handle the case where the address is too complex to be offset by 1. */ | |
11293 | if (GET_CODE (base) == MINUS | |
11294 | || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT)) | |
11295 | { | |
11296 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
11297 | ||
11298 | /* Be careful not to destroy OUTVAL. */ | |
11299 | if (reg_overlap_mentioned_p (base_plus, outval)) | |
11300 | { | |
11301 | /* Updating base_plus might destroy outval, see if we can | |
11302 | swap the scratch and base_plus. */ | |
5895f793 | 11303 | if (!reg_overlap_mentioned_p (scratch, outval)) |
f9cc092a RE |
11304 | { |
11305 | rtx tmp = scratch; | |
11306 | scratch = base_plus; | |
11307 | base_plus = tmp; | |
11308 | } | |
11309 | else | |
11310 | { | |
11311 | rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2])); | |
11312 | ||
11313 | /* Be conservative and copy OUTVAL into the scratch now, | |
11314 | this should only be necessary if outval is a subreg | |
11315 | of something larger than a word. */ | |
11316 | /* XXX Might this clobber base? I can't see how it can, | |
11317 | since scratch is known to overlap with OUTVAL, and | |
11318 | must be wider than a word. */ | |
11319 | emit_insn (gen_movhi (scratch_hi, outval)); | |
11320 | outval = scratch_hi; | |
11321 | } | |
11322 | } | |
11323 | ||
d66437c5 | 11324 | emit_set_insn (base_plus, base); |
f9cc092a RE |
11325 | base = base_plus; |
11326 | } | |
11327 | else if (GET_CODE (base) == PLUS) | |
11328 | { | |
6354dc9b | 11329 | /* The addend must be CONST_INT, or we would have dealt with it above. */ |
f9cc092a RE |
11330 | HOST_WIDE_INT hi, lo; |
11331 | ||
11332 | offset += INTVAL (XEXP (base, 1)); | |
11333 | base = XEXP (base, 0); | |
11334 | ||
6354dc9b | 11335 | /* Rework the address into a legal sequence of insns. */ |
f9cc092a RE |
11336 | /* Valid range for lo is -4095 -> 4095 */ |
11337 | lo = (offset >= 0 | |
11338 | ? (offset & 0xfff) | |
11339 | : -((-offset) & 0xfff)); | |
11340 | ||
11341 | /* Corner case, if lo is the max offset then we would be out of range | |
11342 | once we have added the additional 1 below, so bump the msb into the | |
11343 | pre-loading insn(s). */ | |
11344 | if (lo == 4095) | |
11345 | lo &= 0x7ff; | |
11346 | ||
30cf4896 KG |
11347 | hi = ((((offset - lo) & (HOST_WIDE_INT) 0xffffffff) |
11348 | ^ (HOST_WIDE_INT) 0x80000000) | |
11349 | - (HOST_WIDE_INT) 0x80000000); | |
f9cc092a | 11350 | |
e6d29d15 | 11351 | gcc_assert (hi + lo == offset); |
f9cc092a RE |
11352 | |
11353 | if (hi != 0) | |
11354 | { | |
11355 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
11356 | ||
11357 | /* Be careful not to destroy OUTVAL. */ | |
11358 | if (reg_overlap_mentioned_p (base_plus, outval)) | |
11359 | { | |
11360 | /* Updating base_plus might destroy outval, see if we | |
11361 | can swap the scratch and base_plus. */ | |
5895f793 | 11362 | if (!reg_overlap_mentioned_p (scratch, outval)) |
f9cc092a RE |
11363 | { |
11364 | rtx tmp = scratch; | |
11365 | scratch = base_plus; | |
11366 | base_plus = tmp; | |
11367 | } | |
11368 | else | |
11369 | { | |
11370 | rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2])); | |
11371 | ||
11372 | /* Be conservative and copy outval into scratch now, | |
11373 | this should only be necessary if outval is a | |
11374 | subreg of something larger than a word. */ | |
11375 | /* XXX Might this clobber base? I can't see how it | |
11376 | can, since scratch is known to overlap with | |
11377 | outval. */ | |
11378 | emit_insn (gen_movhi (scratch_hi, outval)); | |
11379 | outval = scratch_hi; | |
11380 | } | |
11381 | } | |
11382 | ||
11383 | /* Get the base address; addsi3 knows how to handle constants | |
6354dc9b | 11384 | that require more than one insn. */ |
f9cc092a RE |
11385 | emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi))); |
11386 | base = base_plus; | |
11387 | offset = lo; | |
11388 | } | |
11389 | } | |
af48348a | 11390 | |
b5cc037f RE |
11391 | if (BYTES_BIG_ENDIAN) |
11392 | { | |
f676971a | 11393 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, |
f9cc092a | 11394 | plus_constant (base, offset + 1)), |
5d5603e2 | 11395 | gen_lowpart (QImode, outval))); |
f9cc092a RE |
11396 | emit_insn (gen_lshrsi3 (scratch, |
11397 | gen_rtx_SUBREG (SImode, outval, 0), | |
b5cc037f | 11398 | GEN_INT (8))); |
f9cc092a | 11399 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, offset)), |
5d5603e2 | 11400 | gen_lowpart (QImode, scratch))); |
b5cc037f RE |
11401 | } |
11402 | else | |
11403 | { | |
f9cc092a | 11404 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, offset)), |
5d5603e2 | 11405 | gen_lowpart (QImode, outval))); |
f9cc092a RE |
11406 | emit_insn (gen_lshrsi3 (scratch, |
11407 | gen_rtx_SUBREG (SImode, outval, 0), | |
b5cc037f | 11408 | GEN_INT (8))); |
f9cc092a RE |
11409 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, |
11410 | plus_constant (base, offset + 1)), | |
5d5603e2 | 11411 | gen_lowpart (QImode, scratch))); |
b5cc037f | 11412 | } |
af48348a | 11413 | } |
866af8a9 JB |
11414 | |
11415 | /* Return true if a type must be passed in memory. For AAPCS, small aggregates | |
11416 | (padded to the size of a word) should be passed in a register. */ | |
11417 | ||
11418 | static bool | |
586de218 | 11419 | arm_must_pass_in_stack (enum machine_mode mode, const_tree type) |
866af8a9 JB |
11420 | { |
11421 | if (TARGET_AAPCS_BASED) | |
11422 | return must_pass_in_stack_var_size (mode, type); | |
11423 | else | |
11424 | return must_pass_in_stack_var_size_or_pad (mode, type); | |
11425 | } | |
11426 | ||
11427 | ||
11428 | /* For use by FUNCTION_ARG_PADDING (MODE, TYPE). | |
11429 | Return true if an argument passed on the stack should be padded upwards, | |
5a29b385 PB |
11430 | i.e. if the least-significant byte has useful data. |
11431 | For legacy APCS ABIs we use the default. For AAPCS based ABIs small | |
11432 | aggregate types are placed in the lowest memory address. */ | |
866af8a9 JB |
11433 | |
11434 | bool | |
586de218 | 11435 | arm_pad_arg_upward (enum machine_mode mode, const_tree type) |
866af8a9 JB |
11436 | { |
11437 | if (!TARGET_AAPCS_BASED) | |
5a29b385 | 11438 | return DEFAULT_FUNCTION_ARG_PADDING(mode, type) == upward; |
866af8a9 JB |
11439 | |
11440 | if (type && BYTES_BIG_ENDIAN && INTEGRAL_TYPE_P (type)) | |
11441 | return false; | |
11442 | ||
460b171d JB |
11443 | /* Half-float values are only passed to libcalls, not regular functions. |
11444 | They should be passed and returned as "short"s (see RTABI). To achieve | |
11445 | that effect in big-endian mode, pad downwards so the value is passed in | |
11446 | the least-significant end of the register. ??? This needs to be here | |
11447 | rather than in arm_pad_reg_upward due to peculiarity in the handling of | |
11448 | libcall arguments. */ | |
11449 | if (BYTES_BIG_ENDIAN && mode == HFmode) | |
11450 | return false; | |
11451 | ||
866af8a9 JB |
11452 | return true; |
11453 | } | |
11454 | ||
11455 | ||
11456 | /* Similarly, for use by BLOCK_REG_PADDING (MODE, TYPE, FIRST). | |
11457 | For non-AAPCS, return !BYTES_BIG_ENDIAN if the least significant | |
11458 | byte of the register has useful data, and return the opposite if the | |
11459 | most significant byte does. | |
11460 | For AAPCS, small aggregates and small complex types are always padded | |
11461 | upwards. */ | |
11462 | ||
11463 | bool | |
11464 | arm_pad_reg_upward (enum machine_mode mode ATTRIBUTE_UNUSED, | |
11465 | tree type, int first ATTRIBUTE_UNUSED) | |
11466 | { | |
11467 | if (TARGET_AAPCS_BASED | |
11468 | && BYTES_BIG_ENDIAN | |
655b30bf JB |
11469 | && (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE |
11470 | || FIXED_POINT_TYPE_P (type)) | |
866af8a9 JB |
11471 | && int_size_in_bytes (type) <= 4) |
11472 | return true; | |
11473 | ||
11474 | /* Otherwise, use default padding. */ | |
11475 | return !BYTES_BIG_ENDIAN; | |
11476 | } | |
11477 | ||
2b835d68 | 11478 | \f |
d5b7b3ae RE |
11479 | /* Print a symbolic form of X to the debug file, F. */ |
11480 | static void | |
e32bac5b | 11481 | arm_print_value (FILE *f, rtx x) |
d5b7b3ae RE |
11482 | { |
11483 | switch (GET_CODE (x)) | |
11484 | { | |
11485 | case CONST_INT: | |
11486 | fprintf (f, HOST_WIDE_INT_PRINT_HEX, INTVAL (x)); | |
11487 | return; | |
11488 | ||
11489 | case CONST_DOUBLE: | |
11490 | fprintf (f, "<0x%lx,0x%lx>", (long)XWINT (x, 2), (long)XWINT (x, 3)); | |
11491 | return; | |
11492 | ||
5a9335ef NC |
11493 | case CONST_VECTOR: |
11494 | { | |
11495 | int i; | |
11496 | ||
11497 | fprintf (f, "<"); | |
11498 | for (i = 0; i < CONST_VECTOR_NUNITS (x); i++) | |
11499 | { | |
11500 | fprintf (f, HOST_WIDE_INT_PRINT_HEX, INTVAL (CONST_VECTOR_ELT (x, i))); | |
11501 | if (i < (CONST_VECTOR_NUNITS (x) - 1)) | |
11502 | fputc (',', f); | |
11503 | } | |
11504 | fprintf (f, ">"); | |
11505 | } | |
11506 | return; | |
11507 | ||
d5b7b3ae RE |
11508 | case CONST_STRING: |
11509 | fprintf (f, "\"%s\"", XSTR (x, 0)); | |
11510 | return; | |
11511 | ||
11512 | case SYMBOL_REF: | |
11513 | fprintf (f, "`%s'", XSTR (x, 0)); | |
11514 | return; | |
11515 | ||
11516 | case LABEL_REF: | |
11517 | fprintf (f, "L%d", INSN_UID (XEXP (x, 0))); | |
11518 | return; | |
11519 | ||
11520 | case CONST: | |
11521 | arm_print_value (f, XEXP (x, 0)); | |
11522 | return; | |
11523 | ||
11524 | case PLUS: | |
11525 | arm_print_value (f, XEXP (x, 0)); | |
11526 | fprintf (f, "+"); | |
11527 | arm_print_value (f, XEXP (x, 1)); | |
11528 | return; | |
11529 | ||
11530 | case PC: | |
11531 | fprintf (f, "pc"); | |
11532 | return; | |
11533 | ||
11534 | default: | |
11535 | fprintf (f, "????"); | |
11536 | return; | |
11537 | } | |
11538 | } | |
11539 | \f | |
2b835d68 | 11540 | /* Routines for manipulation of the constant pool. */ |
2b835d68 | 11541 | |
949d79eb RE |
11542 | /* Arm instructions cannot load a large constant directly into a |
11543 | register; they have to come from a pc relative load. The constant | |
11544 | must therefore be placed in the addressable range of the pc | |
11545 | relative load. Depending on the precise pc relative load | |
11546 | instruction the range is somewhere between 256 bytes and 4k. This | |
11547 | means that we often have to dump a constant inside a function, and | |
2b835d68 RE |
11548 | generate code to branch around it. |
11549 | ||
949d79eb RE |
11550 | It is important to minimize this, since the branches will slow |
11551 | things down and make the code larger. | |
2b835d68 | 11552 | |
949d79eb RE |
11553 | Normally we can hide the table after an existing unconditional |
11554 | branch so that there is no interruption of the flow, but in the | |
11555 | worst case the code looks like this: | |
2b835d68 RE |
11556 | |
11557 | ldr rn, L1 | |
949d79eb | 11558 | ... |
2b835d68 RE |
11559 | b L2 |
11560 | align | |
11561 | L1: .long value | |
11562 | L2: | |
949d79eb | 11563 | ... |
2b835d68 | 11564 | |
2b835d68 | 11565 | ldr rn, L3 |
949d79eb | 11566 | ... |
2b835d68 RE |
11567 | b L4 |
11568 | align | |
2b835d68 RE |
11569 | L3: .long value |
11570 | L4: | |
949d79eb RE |
11571 | ... |
11572 | ||
11573 | We fix this by performing a scan after scheduling, which notices | |
11574 | which instructions need to have their operands fetched from the | |
11575 | constant table and builds the table. | |
11576 | ||
11577 | The algorithm starts by building a table of all the constants that | |
11578 | need fixing up and all the natural barriers in the function (places | |
11579 | where a constant table can be dropped without breaking the flow). | |
11580 | For each fixup we note how far the pc-relative replacement will be | |
11581 | able to reach and the offset of the instruction into the function. | |
11582 | ||
11583 | Having built the table we then group the fixes together to form | |
11584 | tables that are as large as possible (subject to addressing | |
11585 | constraints) and emit each table of constants after the last | |
11586 | barrier that is within range of all the instructions in the group. | |
11587 | If a group does not contain a barrier, then we forcibly create one | |
11588 | by inserting a jump instruction into the flow. Once the table has | |
11589 | been inserted, the insns are then modified to reference the | |
11590 | relevant entry in the pool. | |
11591 | ||
6354dc9b | 11592 | Possible enhancements to the algorithm (not implemented) are: |
949d79eb | 11593 | |
d5b7b3ae | 11594 | 1) For some processors and object formats, there may be benefit in |
949d79eb RE |
11595 | aligning the pools to the start of cache lines; this alignment |
11596 | would need to be taken into account when calculating addressability | |
6354dc9b | 11597 | of a pool. */ |
2b835d68 | 11598 | |
d5b7b3ae RE |
11599 | /* These typedefs are located at the start of this file, so that |
11600 | they can be used in the prototypes there. This comment is to | |
11601 | remind readers of that fact so that the following structures | |
11602 | can be understood more easily. | |
11603 | ||
11604 | typedef struct minipool_node Mnode; | |
11605 | typedef struct minipool_fixup Mfix; */ | |
11606 | ||
11607 | struct minipool_node | |
11608 | { | |
11609 | /* Doubly linked chain of entries. */ | |
11610 | Mnode * next; | |
11611 | Mnode * prev; | |
11612 | /* The maximum offset into the code that this entry can be placed. While | |
11613 | pushing fixes for forward references, all entries are sorted in order | |
11614 | of increasing max_address. */ | |
11615 | HOST_WIDE_INT max_address; | |
5519a4f9 | 11616 | /* Similarly for an entry inserted for a backwards ref. */ |
d5b7b3ae RE |
11617 | HOST_WIDE_INT min_address; |
11618 | /* The number of fixes referencing this entry. This can become zero | |
11619 | if we "unpush" an entry. In this case we ignore the entry when we | |
11620 | come to emit the code. */ | |
11621 | int refcount; | |
11622 | /* The offset from the start of the minipool. */ | |
11623 | HOST_WIDE_INT offset; | |
11624 | /* The value in table. */ | |
11625 | rtx value; | |
11626 | /* The mode of value. */ | |
11627 | enum machine_mode mode; | |
5a9335ef NC |
11628 | /* The size of the value. With iWMMXt enabled |
11629 | sizes > 4 also imply an alignment of 8-bytes. */ | |
d5b7b3ae RE |
11630 | int fix_size; |
11631 | }; | |
11632 | ||
11633 | struct minipool_fixup | |
2b835d68 | 11634 | { |
d5b7b3ae RE |
11635 | Mfix * next; |
11636 | rtx insn; | |
11637 | HOST_WIDE_INT address; | |
11638 | rtx * loc; | |
11639 | enum machine_mode mode; | |
11640 | int fix_size; | |
11641 | rtx value; | |
11642 | Mnode * minipool; | |
11643 | HOST_WIDE_INT forwards; | |
11644 | HOST_WIDE_INT backwards; | |
11645 | }; | |
2b835d68 | 11646 | |
d5b7b3ae RE |
11647 | /* Fixes less than a word need padding out to a word boundary. */ |
11648 | #define MINIPOOL_FIX_SIZE(mode) \ | |
11649 | (GET_MODE_SIZE ((mode)) >= 4 ? GET_MODE_SIZE ((mode)) : 4) | |
2b835d68 | 11650 | |
d5b7b3ae RE |
11651 | static Mnode * minipool_vector_head; |
11652 | static Mnode * minipool_vector_tail; | |
11653 | static rtx minipool_vector_label; | |
34a9f549 | 11654 | static int minipool_pad; |
332072db | 11655 | |
d5b7b3ae RE |
11656 | /* The linked list of all minipool fixes required for this function. */ |
11657 | Mfix * minipool_fix_head; | |
11658 | Mfix * minipool_fix_tail; | |
11659 | /* The fix entry for the current minipool, once it has been placed. */ | |
11660 | Mfix * minipool_barrier; | |
11661 | ||
11662 | /* Determines if INSN is the start of a jump table. Returns the end | |
11663 | of the TABLE or NULL_RTX. */ | |
11664 | static rtx | |
e32bac5b | 11665 | is_jump_table (rtx insn) |
2b835d68 | 11666 | { |
d5b7b3ae | 11667 | rtx table; |
f676971a | 11668 | |
dc0ff1c8 | 11669 | if (jump_to_label_p (insn) |
d5b7b3ae RE |
11670 | && ((table = next_real_insn (JUMP_LABEL (insn))) |
11671 | == next_real_insn (insn)) | |
11672 | && table != NULL | |
11673 | && GET_CODE (table) == JUMP_INSN | |
11674 | && (GET_CODE (PATTERN (table)) == ADDR_VEC | |
11675 | || GET_CODE (PATTERN (table)) == ADDR_DIFF_VEC)) | |
11676 | return table; | |
11677 | ||
11678 | return NULL_RTX; | |
2b835d68 RE |
11679 | } |
11680 | ||
657d9449 RE |
11681 | #ifndef JUMP_TABLES_IN_TEXT_SECTION |
11682 | #define JUMP_TABLES_IN_TEXT_SECTION 0 | |
11683 | #endif | |
11684 | ||
d5b7b3ae | 11685 | static HOST_WIDE_INT |
e32bac5b | 11686 | get_jump_table_size (rtx insn) |
2b835d68 | 11687 | { |
657d9449 RE |
11688 | /* ADDR_VECs only take room if read-only data does into the text |
11689 | section. */ | |
d6b5193b | 11690 | if (JUMP_TABLES_IN_TEXT_SECTION || readonly_data_section == text_section) |
657d9449 RE |
11691 | { |
11692 | rtx body = PATTERN (insn); | |
11693 | int elt = GET_CODE (body) == ADDR_DIFF_VEC ? 1 : 0; | |
5b3e6663 PB |
11694 | HOST_WIDE_INT size; |
11695 | HOST_WIDE_INT modesize; | |
2b835d68 | 11696 | |
5b3e6663 PB |
11697 | modesize = GET_MODE_SIZE (GET_MODE (body)); |
11698 | size = modesize * XVECLEN (body, elt); | |
11699 | switch (modesize) | |
11700 | { | |
11701 | case 1: | |
88512ba0 | 11702 | /* Round up size of TBB table to a halfword boundary. */ |
5b3e6663 PB |
11703 | size = (size + 1) & ~(HOST_WIDE_INT)1; |
11704 | break; | |
11705 | case 2: | |
7a085dce | 11706 | /* No padding necessary for TBH. */ |
5b3e6663 PB |
11707 | break; |
11708 | case 4: | |
11709 | /* Add two bytes for alignment on Thumb. */ | |
11710 | if (TARGET_THUMB) | |
11711 | size += 2; | |
11712 | break; | |
11713 | default: | |
11714 | gcc_unreachable (); | |
11715 | } | |
11716 | return size; | |
657d9449 RE |
11717 | } |
11718 | ||
11719 | return 0; | |
d5b7b3ae | 11720 | } |
2b835d68 | 11721 | |
20fe71c2 RS |
11722 | /* Return the maximum amount of padding that will be inserted before |
11723 | label LABEL. */ | |
11724 | ||
11725 | static HOST_WIDE_INT | |
11726 | get_label_padding (rtx label) | |
11727 | { | |
11728 | HOST_WIDE_INT align, min_insn_size; | |
11729 | ||
11730 | align = 1 << label_to_alignment (label); | |
11731 | min_insn_size = TARGET_THUMB ? 2 : 4; | |
11732 | return align > min_insn_size ? align - min_insn_size : 0; | |
11733 | } | |
11734 | ||
d5b7b3ae RE |
11735 | /* Move a minipool fix MP from its current location to before MAX_MP. |
11736 | If MAX_MP is NULL, then MP doesn't need moving, but the addressing | |
093354e0 | 11737 | constraints may need updating. */ |
d5b7b3ae | 11738 | static Mnode * |
e32bac5b RE |
11739 | move_minipool_fix_forward_ref (Mnode *mp, Mnode *max_mp, |
11740 | HOST_WIDE_INT max_address) | |
d5b7b3ae | 11741 | { |
e6d29d15 NS |
11742 | /* The code below assumes these are different. */ |
11743 | gcc_assert (mp != max_mp); | |
d5b7b3ae RE |
11744 | |
11745 | if (max_mp == NULL) | |
11746 | { | |
11747 | if (max_address < mp->max_address) | |
11748 | mp->max_address = max_address; | |
11749 | } | |
11750 | else | |
2b835d68 | 11751 | { |
d5b7b3ae RE |
11752 | if (max_address > max_mp->max_address - mp->fix_size) |
11753 | mp->max_address = max_mp->max_address - mp->fix_size; | |
11754 | else | |
11755 | mp->max_address = max_address; | |
2b835d68 | 11756 | |
d5b7b3ae RE |
11757 | /* Unlink MP from its current position. Since max_mp is non-null, |
11758 | mp->prev must be non-null. */ | |
11759 | mp->prev->next = mp->next; | |
11760 | if (mp->next != NULL) | |
11761 | mp->next->prev = mp->prev; | |
11762 | else | |
11763 | minipool_vector_tail = mp->prev; | |
2b835d68 | 11764 | |
d5b7b3ae RE |
11765 | /* Re-insert it before MAX_MP. */ |
11766 | mp->next = max_mp; | |
11767 | mp->prev = max_mp->prev; | |
11768 | max_mp->prev = mp; | |
f676971a | 11769 | |
d5b7b3ae RE |
11770 | if (mp->prev != NULL) |
11771 | mp->prev->next = mp; | |
11772 | else | |
11773 | minipool_vector_head = mp; | |
11774 | } | |
2b835d68 | 11775 | |
d5b7b3ae RE |
11776 | /* Save the new entry. */ |
11777 | max_mp = mp; | |
11778 | ||
d6a7951f | 11779 | /* Scan over the preceding entries and adjust their addresses as |
d5b7b3ae RE |
11780 | required. */ |
11781 | while (mp->prev != NULL | |
11782 | && mp->prev->max_address > mp->max_address - mp->prev->fix_size) | |
11783 | { | |
11784 | mp->prev->max_address = mp->max_address - mp->prev->fix_size; | |
11785 | mp = mp->prev; | |
2b835d68 RE |
11786 | } |
11787 | ||
d5b7b3ae | 11788 | return max_mp; |
2b835d68 RE |
11789 | } |
11790 | ||
d5b7b3ae RE |
11791 | /* Add a constant to the minipool for a forward reference. Returns the |
11792 | node added or NULL if the constant will not fit in this pool. */ | |
11793 | static Mnode * | |
e32bac5b | 11794 | add_minipool_forward_ref (Mfix *fix) |
d5b7b3ae RE |
11795 | { |
11796 | /* If set, max_mp is the first pool_entry that has a lower | |
11797 | constraint than the one we are trying to add. */ | |
11798 | Mnode * max_mp = NULL; | |
34a9f549 | 11799 | HOST_WIDE_INT max_address = fix->address + fix->forwards - minipool_pad; |
d5b7b3ae | 11800 | Mnode * mp; |
f676971a | 11801 | |
7a7017bc PB |
11802 | /* If the minipool starts before the end of FIX->INSN then this FIX |
11803 | can not be placed into the current pool. Furthermore, adding the | |
11804 | new constant pool entry may cause the pool to start FIX_SIZE bytes | |
11805 | earlier. */ | |
d5b7b3ae | 11806 | if (minipool_vector_head && |
7a7017bc PB |
11807 | (fix->address + get_attr_length (fix->insn) |
11808 | >= minipool_vector_head->max_address - fix->fix_size)) | |
d5b7b3ae | 11809 | return NULL; |
2b835d68 | 11810 | |
d5b7b3ae RE |
11811 | /* Scan the pool to see if a constant with the same value has |
11812 | already been added. While we are doing this, also note the | |
11813 | location where we must insert the constant if it doesn't already | |
11814 | exist. */ | |
11815 | for (mp = minipool_vector_head; mp != NULL; mp = mp->next) | |
11816 | { | |
11817 | if (GET_CODE (fix->value) == GET_CODE (mp->value) | |
11818 | && fix->mode == mp->mode | |
11819 | && (GET_CODE (fix->value) != CODE_LABEL | |
11820 | || (CODE_LABEL_NUMBER (fix->value) | |
11821 | == CODE_LABEL_NUMBER (mp->value))) | |
11822 | && rtx_equal_p (fix->value, mp->value)) | |
11823 | { | |
11824 | /* More than one fix references this entry. */ | |
11825 | mp->refcount++; | |
11826 | return move_minipool_fix_forward_ref (mp, max_mp, max_address); | |
11827 | } | |
11828 | ||
11829 | /* Note the insertion point if necessary. */ | |
11830 | if (max_mp == NULL | |
11831 | && mp->max_address > max_address) | |
11832 | max_mp = mp; | |
5a9335ef NC |
11833 | |
11834 | /* If we are inserting an 8-bytes aligned quantity and | |
11835 | we have not already found an insertion point, then | |
11836 | make sure that all such 8-byte aligned quantities are | |
11837 | placed at the start of the pool. */ | |
5848830f | 11838 | if (ARM_DOUBLEWORD_ALIGN |
5a9335ef | 11839 | && max_mp == NULL |
88f77cba JB |
11840 | && fix->fix_size >= 8 |
11841 | && mp->fix_size < 8) | |
5a9335ef NC |
11842 | { |
11843 | max_mp = mp; | |
11844 | max_address = mp->max_address; | |
11845 | } | |
d5b7b3ae RE |
11846 | } |
11847 | ||
11848 | /* The value is not currently in the minipool, so we need to create | |
11849 | a new entry for it. If MAX_MP is NULL, the entry will be put on | |
11850 | the end of the list since the placement is less constrained than | |
11851 | any existing entry. Otherwise, we insert the new fix before | |
6bc82793 | 11852 | MAX_MP and, if necessary, adjust the constraints on the other |
d5b7b3ae | 11853 | entries. */ |
5ed6ace5 | 11854 | mp = XNEW (Mnode); |
d5b7b3ae RE |
11855 | mp->fix_size = fix->fix_size; |
11856 | mp->mode = fix->mode; | |
11857 | mp->value = fix->value; | |
11858 | mp->refcount = 1; | |
11859 | /* Not yet required for a backwards ref. */ | |
11860 | mp->min_address = -65536; | |
11861 | ||
11862 | if (max_mp == NULL) | |
11863 | { | |
11864 | mp->max_address = max_address; | |
11865 | mp->next = NULL; | |
11866 | mp->prev = minipool_vector_tail; | |
11867 | ||
11868 | if (mp->prev == NULL) | |
11869 | { | |
11870 | minipool_vector_head = mp; | |
11871 | minipool_vector_label = gen_label_rtx (); | |
7551cbc7 | 11872 | } |
2b835d68 | 11873 | else |
d5b7b3ae | 11874 | mp->prev->next = mp; |
2b835d68 | 11875 | |
d5b7b3ae RE |
11876 | minipool_vector_tail = mp; |
11877 | } | |
11878 | else | |
11879 | { | |
11880 | if (max_address > max_mp->max_address - mp->fix_size) | |
11881 | mp->max_address = max_mp->max_address - mp->fix_size; | |
11882 | else | |
11883 | mp->max_address = max_address; | |
11884 | ||
11885 | mp->next = max_mp; | |
11886 | mp->prev = max_mp->prev; | |
11887 | max_mp->prev = mp; | |
11888 | if (mp->prev != NULL) | |
11889 | mp->prev->next = mp; | |
11890 | else | |
11891 | minipool_vector_head = mp; | |
11892 | } | |
11893 | ||
11894 | /* Save the new entry. */ | |
11895 | max_mp = mp; | |
11896 | ||
d6a7951f | 11897 | /* Scan over the preceding entries and adjust their addresses as |
d5b7b3ae RE |
11898 | required. */ |
11899 | while (mp->prev != NULL | |
11900 | && mp->prev->max_address > mp->max_address - mp->prev->fix_size) | |
11901 | { | |
11902 | mp->prev->max_address = mp->max_address - mp->prev->fix_size; | |
11903 | mp = mp->prev; | |
2b835d68 RE |
11904 | } |
11905 | ||
d5b7b3ae RE |
11906 | return max_mp; |
11907 | } | |
11908 | ||
11909 | static Mnode * | |
e32bac5b RE |
11910 | move_minipool_fix_backward_ref (Mnode *mp, Mnode *min_mp, |
11911 | HOST_WIDE_INT min_address) | |
d5b7b3ae RE |
11912 | { |
11913 | HOST_WIDE_INT offset; | |
11914 | ||
e6d29d15 NS |
11915 | /* The code below assumes these are different. */ |
11916 | gcc_assert (mp != min_mp); | |
d5b7b3ae RE |
11917 | |
11918 | if (min_mp == NULL) | |
2b835d68 | 11919 | { |
d5b7b3ae RE |
11920 | if (min_address > mp->min_address) |
11921 | mp->min_address = min_address; | |
11922 | } | |
11923 | else | |
11924 | { | |
11925 | /* We will adjust this below if it is too loose. */ | |
11926 | mp->min_address = min_address; | |
11927 | ||
11928 | /* Unlink MP from its current position. Since min_mp is non-null, | |
11929 | mp->next must be non-null. */ | |
11930 | mp->next->prev = mp->prev; | |
11931 | if (mp->prev != NULL) | |
11932 | mp->prev->next = mp->next; | |
11933 | else | |
11934 | minipool_vector_head = mp->next; | |
11935 | ||
11936 | /* Reinsert it after MIN_MP. */ | |
11937 | mp->prev = min_mp; | |
11938 | mp->next = min_mp->next; | |
11939 | min_mp->next = mp; | |
11940 | if (mp->next != NULL) | |
11941 | mp->next->prev = mp; | |
2b835d68 | 11942 | else |
d5b7b3ae RE |
11943 | minipool_vector_tail = mp; |
11944 | } | |
11945 | ||
11946 | min_mp = mp; | |
11947 | ||
11948 | offset = 0; | |
11949 | for (mp = minipool_vector_head; mp != NULL; mp = mp->next) | |
11950 | { | |
11951 | mp->offset = offset; | |
11952 | if (mp->refcount > 0) | |
11953 | offset += mp->fix_size; | |
11954 | ||
11955 | if (mp->next && mp->next->min_address < mp->min_address + mp->fix_size) | |
11956 | mp->next->min_address = mp->min_address + mp->fix_size; | |
11957 | } | |
11958 | ||
11959 | return min_mp; | |
f676971a | 11960 | } |
d5b7b3ae RE |
11961 | |
11962 | /* Add a constant to the minipool for a backward reference. Returns the | |
f676971a | 11963 | node added or NULL if the constant will not fit in this pool. |
d5b7b3ae RE |
11964 | |
11965 | Note that the code for insertion for a backwards reference can be | |
11966 | somewhat confusing because the calculated offsets for each fix do | |
11967 | not take into account the size of the pool (which is still under | |
11968 | construction. */ | |
11969 | static Mnode * | |
e32bac5b | 11970 | add_minipool_backward_ref (Mfix *fix) |
d5b7b3ae RE |
11971 | { |
11972 | /* If set, min_mp is the last pool_entry that has a lower constraint | |
11973 | than the one we are trying to add. */ | |
e32bac5b | 11974 | Mnode *min_mp = NULL; |
d5b7b3ae RE |
11975 | /* This can be negative, since it is only a constraint. */ |
11976 | HOST_WIDE_INT min_address = fix->address - fix->backwards; | |
e32bac5b | 11977 | Mnode *mp; |
d5b7b3ae RE |
11978 | |
11979 | /* If we can't reach the current pool from this insn, or if we can't | |
11980 | insert this entry at the end of the pool without pushing other | |
11981 | fixes out of range, then we don't try. This ensures that we | |
11982 | can't fail later on. */ | |
11983 | if (min_address >= minipool_barrier->address | |
11984 | || (minipool_vector_tail->min_address + fix->fix_size | |
11985 | >= minipool_barrier->address)) | |
11986 | return NULL; | |
11987 | ||
11988 | /* Scan the pool to see if a constant with the same value has | |
11989 | already been added. While we are doing this, also note the | |
11990 | location where we must insert the constant if it doesn't already | |
11991 | exist. */ | |
11992 | for (mp = minipool_vector_tail; mp != NULL; mp = mp->prev) | |
11993 | { | |
11994 | if (GET_CODE (fix->value) == GET_CODE (mp->value) | |
11995 | && fix->mode == mp->mode | |
11996 | && (GET_CODE (fix->value) != CODE_LABEL | |
11997 | || (CODE_LABEL_NUMBER (fix->value) | |
11998 | == CODE_LABEL_NUMBER (mp->value))) | |
11999 | && rtx_equal_p (fix->value, mp->value) | |
12000 | /* Check that there is enough slack to move this entry to the | |
12001 | end of the table (this is conservative). */ | |
f676971a EC |
12002 | && (mp->max_address |
12003 | > (minipool_barrier->address | |
d5b7b3ae RE |
12004 | + minipool_vector_tail->offset |
12005 | + minipool_vector_tail->fix_size))) | |
12006 | { | |
12007 | mp->refcount++; | |
12008 | return move_minipool_fix_backward_ref (mp, min_mp, min_address); | |
12009 | } | |
12010 | ||
12011 | if (min_mp != NULL) | |
12012 | mp->min_address += fix->fix_size; | |
12013 | else | |
12014 | { | |
12015 | /* Note the insertion point if necessary. */ | |
12016 | if (mp->min_address < min_address) | |
5a9335ef NC |
12017 | { |
12018 | /* For now, we do not allow the insertion of 8-byte alignment | |
12019 | requiring nodes anywhere but at the start of the pool. */ | |
5848830f | 12020 | if (ARM_DOUBLEWORD_ALIGN |
88f77cba | 12021 | && fix->fix_size >= 8 && mp->fix_size < 8) |
5a9335ef NC |
12022 | return NULL; |
12023 | else | |
12024 | min_mp = mp; | |
12025 | } | |
d5b7b3ae RE |
12026 | else if (mp->max_address |
12027 | < minipool_barrier->address + mp->offset + fix->fix_size) | |
12028 | { | |
12029 | /* Inserting before this entry would push the fix beyond | |
12030 | its maximum address (which can happen if we have | |
12031 | re-located a forwards fix); force the new fix to come | |
12032 | after it. */ | |
853ff9e2 JM |
12033 | if (ARM_DOUBLEWORD_ALIGN |
12034 | && fix->fix_size >= 8 && mp->fix_size < 8) | |
12035 | return NULL; | |
12036 | else | |
12037 | { | |
12038 | min_mp = mp; | |
12039 | min_address = mp->min_address + fix->fix_size; | |
12040 | } | |
d5b7b3ae | 12041 | } |
853ff9e2 JM |
12042 | /* Do not insert a non-8-byte aligned quantity before 8-byte |
12043 | aligned quantities. */ | |
5848830f | 12044 | else if (ARM_DOUBLEWORD_ALIGN |
853ff9e2 JM |
12045 | && fix->fix_size < 8 |
12046 | && mp->fix_size >= 8) | |
5a9335ef NC |
12047 | { |
12048 | min_mp = mp; | |
12049 | min_address = mp->min_address + fix->fix_size; | |
12050 | } | |
d5b7b3ae RE |
12051 | } |
12052 | } | |
12053 | ||
12054 | /* We need to create a new entry. */ | |
5ed6ace5 | 12055 | mp = XNEW (Mnode); |
d5b7b3ae RE |
12056 | mp->fix_size = fix->fix_size; |
12057 | mp->mode = fix->mode; | |
12058 | mp->value = fix->value; | |
12059 | mp->refcount = 1; | |
12060 | mp->max_address = minipool_barrier->address + 65536; | |
12061 | ||
12062 | mp->min_address = min_address; | |
12063 | ||
12064 | if (min_mp == NULL) | |
12065 | { | |
12066 | mp->prev = NULL; | |
12067 | mp->next = minipool_vector_head; | |
12068 | ||
12069 | if (mp->next == NULL) | |
12070 | { | |
12071 | minipool_vector_tail = mp; | |
12072 | minipool_vector_label = gen_label_rtx (); | |
12073 | } | |
12074 | else | |
12075 | mp->next->prev = mp; | |
12076 | ||
12077 | minipool_vector_head = mp; | |
12078 | } | |
12079 | else | |
12080 | { | |
12081 | mp->next = min_mp->next; | |
12082 | mp->prev = min_mp; | |
12083 | min_mp->next = mp; | |
f676971a | 12084 | |
d5b7b3ae RE |
12085 | if (mp->next != NULL) |
12086 | mp->next->prev = mp; | |
12087 | else | |
12088 | minipool_vector_tail = mp; | |
12089 | } | |
12090 | ||
12091 | /* Save the new entry. */ | |
12092 | min_mp = mp; | |
12093 | ||
12094 | if (mp->prev) | |
12095 | mp = mp->prev; | |
12096 | else | |
12097 | mp->offset = 0; | |
12098 | ||
12099 | /* Scan over the following entries and adjust their offsets. */ | |
12100 | while (mp->next != NULL) | |
12101 | { | |
12102 | if (mp->next->min_address < mp->min_address + mp->fix_size) | |
12103 | mp->next->min_address = mp->min_address + mp->fix_size; | |
12104 | ||
12105 | if (mp->refcount) | |
12106 | mp->next->offset = mp->offset + mp->fix_size; | |
12107 | else | |
12108 | mp->next->offset = mp->offset; | |
12109 | ||
12110 | mp = mp->next; | |
12111 | } | |
12112 | ||
12113 | return min_mp; | |
12114 | } | |
12115 | ||
12116 | static void | |
e32bac5b | 12117 | assign_minipool_offsets (Mfix *barrier) |
d5b7b3ae RE |
12118 | { |
12119 | HOST_WIDE_INT offset = 0; | |
e32bac5b | 12120 | Mnode *mp; |
d5b7b3ae RE |
12121 | |
12122 | minipool_barrier = barrier; | |
12123 | ||
12124 | for (mp = minipool_vector_head; mp != NULL; mp = mp->next) | |
12125 | { | |
12126 | mp->offset = offset; | |
f676971a | 12127 | |
d5b7b3ae RE |
12128 | if (mp->refcount > 0) |
12129 | offset += mp->fix_size; | |
12130 | } | |
12131 | } | |
12132 | ||
12133 | /* Output the literal table */ | |
12134 | static void | |
e32bac5b | 12135 | dump_minipool (rtx scan) |
d5b7b3ae | 12136 | { |
5a9335ef NC |
12137 | Mnode * mp; |
12138 | Mnode * nmp; | |
12139 | int align64 = 0; | |
12140 | ||
5848830f | 12141 | if (ARM_DOUBLEWORD_ALIGN) |
5a9335ef | 12142 | for (mp = minipool_vector_head; mp != NULL; mp = mp->next) |
88f77cba | 12143 | if (mp->refcount > 0 && mp->fix_size >= 8) |
5a9335ef NC |
12144 | { |
12145 | align64 = 1; | |
12146 | break; | |
12147 | } | |
d5b7b3ae | 12148 | |
c263766c RH |
12149 | if (dump_file) |
12150 | fprintf (dump_file, | |
5a9335ef NC |
12151 | ";; Emitting minipool after insn %u; address %ld; align %d (bytes)\n", |
12152 | INSN_UID (scan), (unsigned long) minipool_barrier->address, align64 ? 8 : 4); | |
d5b7b3ae RE |
12153 | |
12154 | scan = emit_label_after (gen_label_rtx (), scan); | |
5a9335ef | 12155 | scan = emit_insn_after (align64 ? gen_align_8 () : gen_align_4 (), scan); |
d5b7b3ae RE |
12156 | scan = emit_label_after (minipool_vector_label, scan); |
12157 | ||
12158 | for (mp = minipool_vector_head; mp != NULL; mp = nmp) | |
12159 | { | |
12160 | if (mp->refcount > 0) | |
12161 | { | |
c263766c | 12162 | if (dump_file) |
d5b7b3ae | 12163 | { |
f676971a | 12164 | fprintf (dump_file, |
d5b7b3ae RE |
12165 | ";; Offset %u, min %ld, max %ld ", |
12166 | (unsigned) mp->offset, (unsigned long) mp->min_address, | |
12167 | (unsigned long) mp->max_address); | |
c263766c RH |
12168 | arm_print_value (dump_file, mp->value); |
12169 | fputc ('\n', dump_file); | |
d5b7b3ae RE |
12170 | } |
12171 | ||
12172 | switch (mp->fix_size) | |
12173 | { | |
12174 | #ifdef HAVE_consttable_1 | |
12175 | case 1: | |
12176 | scan = emit_insn_after (gen_consttable_1 (mp->value), scan); | |
12177 | break; | |
12178 | ||
12179 | #endif | |
12180 | #ifdef HAVE_consttable_2 | |
12181 | case 2: | |
12182 | scan = emit_insn_after (gen_consttable_2 (mp->value), scan); | |
12183 | break; | |
12184 | ||
12185 | #endif | |
12186 | #ifdef HAVE_consttable_4 | |
12187 | case 4: | |
12188 | scan = emit_insn_after (gen_consttable_4 (mp->value), scan); | |
12189 | break; | |
12190 | ||
12191 | #endif | |
12192 | #ifdef HAVE_consttable_8 | |
12193 | case 8: | |
12194 | scan = emit_insn_after (gen_consttable_8 (mp->value), scan); | |
12195 | break; | |
12196 | ||
88f77cba JB |
12197 | #endif |
12198 | #ifdef HAVE_consttable_16 | |
12199 | case 16: | |
12200 | scan = emit_insn_after (gen_consttable_16 (mp->value), scan); | |
12201 | break; | |
12202 | ||
d5b7b3ae RE |
12203 | #endif |
12204 | default: | |
e6d29d15 | 12205 | gcc_unreachable (); |
d5b7b3ae RE |
12206 | } |
12207 | } | |
12208 | ||
12209 | nmp = mp->next; | |
12210 | free (mp); | |
2b835d68 RE |
12211 | } |
12212 | ||
d5b7b3ae RE |
12213 | minipool_vector_head = minipool_vector_tail = NULL; |
12214 | scan = emit_insn_after (gen_consttable_end (), scan); | |
12215 | scan = emit_barrier_after (scan); | |
2b835d68 RE |
12216 | } |
12217 | ||
d5b7b3ae RE |
12218 | /* Return the cost of forcibly inserting a barrier after INSN. */ |
12219 | static int | |
e32bac5b | 12220 | arm_barrier_cost (rtx insn) |
949d79eb | 12221 | { |
d5b7b3ae RE |
12222 | /* Basing the location of the pool on the loop depth is preferable, |
12223 | but at the moment, the basic block information seems to be | |
12224 | corrupt by this stage of the compilation. */ | |
12225 | int base_cost = 50; | |
12226 | rtx next = next_nonnote_insn (insn); | |
12227 | ||
12228 | if (next != NULL && GET_CODE (next) == CODE_LABEL) | |
12229 | base_cost -= 20; | |
12230 | ||
12231 | switch (GET_CODE (insn)) | |
12232 | { | |
12233 | case CODE_LABEL: | |
12234 | /* It will always be better to place the table before the label, rather | |
12235 | than after it. */ | |
f676971a | 12236 | return 50; |
949d79eb | 12237 | |
d5b7b3ae RE |
12238 | case INSN: |
12239 | case CALL_INSN: | |
12240 | return base_cost; | |
12241 | ||
12242 | case JUMP_INSN: | |
12243 | return base_cost - 10; | |
12244 | ||
12245 | default: | |
12246 | return base_cost + 10; | |
12247 | } | |
12248 | } | |
12249 | ||
12250 | /* Find the best place in the insn stream in the range | |
12251 | (FIX->address,MAX_ADDRESS) to forcibly insert a minipool barrier. | |
12252 | Create the barrier by inserting a jump and add a new fix entry for | |
12253 | it. */ | |
12254 | static Mfix * | |
e32bac5b | 12255 | create_fix_barrier (Mfix *fix, HOST_WIDE_INT max_address) |
d5b7b3ae RE |
12256 | { |
12257 | HOST_WIDE_INT count = 0; | |
12258 | rtx barrier; | |
12259 | rtx from = fix->insn; | |
7a7017bc PB |
12260 | /* The instruction after which we will insert the jump. */ |
12261 | rtx selected = NULL; | |
d5b7b3ae | 12262 | int selected_cost; |
7a7017bc | 12263 | /* The address at which the jump instruction will be placed. */ |
d5b7b3ae RE |
12264 | HOST_WIDE_INT selected_address; |
12265 | Mfix * new_fix; | |
12266 | HOST_WIDE_INT max_count = max_address - fix->address; | |
12267 | rtx label = gen_label_rtx (); | |
12268 | ||
12269 | selected_cost = arm_barrier_cost (from); | |
12270 | selected_address = fix->address; | |
12271 | ||
12272 | while (from && count < max_count) | |
12273 | { | |
12274 | rtx tmp; | |
12275 | int new_cost; | |
12276 | ||
12277 | /* This code shouldn't have been called if there was a natural barrier | |
12278 | within range. */ | |
e6d29d15 | 12279 | gcc_assert (GET_CODE (from) != BARRIER); |
d5b7b3ae | 12280 | |
20fe71c2 RS |
12281 | /* Count the length of this insn. This must stay in sync with the |
12282 | code that pushes minipool fixes. */ | |
12283 | if (LABEL_P (from)) | |
12284 | count += get_label_padding (from); | |
12285 | else | |
12286 | count += get_attr_length (from); | |
d5b7b3ae RE |
12287 | |
12288 | /* If there is a jump table, add its length. */ | |
12289 | tmp = is_jump_table (from); | |
12290 | if (tmp != NULL) | |
12291 | { | |
12292 | count += get_jump_table_size (tmp); | |
12293 | ||
12294 | /* Jump tables aren't in a basic block, so base the cost on | |
12295 | the dispatch insn. If we select this location, we will | |
12296 | still put the pool after the table. */ | |
12297 | new_cost = arm_barrier_cost (from); | |
12298 | ||
7a7017bc PB |
12299 | if (count < max_count |
12300 | && (!selected || new_cost <= selected_cost)) | |
d5b7b3ae RE |
12301 | { |
12302 | selected = tmp; | |
12303 | selected_cost = new_cost; | |
12304 | selected_address = fix->address + count; | |
12305 | } | |
12306 | ||
12307 | /* Continue after the dispatch table. */ | |
12308 | from = NEXT_INSN (tmp); | |
12309 | continue; | |
12310 | } | |
12311 | ||
12312 | new_cost = arm_barrier_cost (from); | |
f676971a | 12313 | |
7a7017bc PB |
12314 | if (count < max_count |
12315 | && (!selected || new_cost <= selected_cost)) | |
d5b7b3ae RE |
12316 | { |
12317 | selected = from; | |
12318 | selected_cost = new_cost; | |
12319 | selected_address = fix->address + count; | |
12320 | } | |
12321 | ||
12322 | from = NEXT_INSN (from); | |
12323 | } | |
12324 | ||
7a7017bc PB |
12325 | /* Make sure that we found a place to insert the jump. */ |
12326 | gcc_assert (selected); | |
12327 | ||
b6a75dda RR |
12328 | /* Make sure we do not split a call and its corresponding |
12329 | CALL_ARG_LOCATION note. */ | |
12330 | if (CALL_P (selected)) | |
12331 | { | |
12332 | rtx next = NEXT_INSN (selected); | |
12333 | if (next && NOTE_P (next) | |
12334 | && NOTE_KIND (next) == NOTE_INSN_CALL_ARG_LOCATION) | |
12335 | selected = next; | |
12336 | } | |
12337 | ||
d5b7b3ae RE |
12338 | /* Create a new JUMP_INSN that branches around a barrier. */ |
12339 | from = emit_jump_insn_after (gen_jump (label), selected); | |
12340 | JUMP_LABEL (from) = label; | |
12341 | barrier = emit_barrier_after (from); | |
12342 | emit_label_after (label, barrier); | |
12343 | ||
12344 | /* Create a minipool barrier entry for the new barrier. */ | |
c7319d87 | 12345 | new_fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* new_fix)); |
d5b7b3ae RE |
12346 | new_fix->insn = barrier; |
12347 | new_fix->address = selected_address; | |
12348 | new_fix->next = fix->next; | |
12349 | fix->next = new_fix; | |
12350 | ||
12351 | return new_fix; | |
12352 | } | |
12353 | ||
12354 | /* Record that there is a natural barrier in the insn stream at | |
12355 | ADDRESS. */ | |
949d79eb | 12356 | static void |
e32bac5b | 12357 | push_minipool_barrier (rtx insn, HOST_WIDE_INT address) |
2b835d68 | 12358 | { |
c7319d87 | 12359 | Mfix * fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* fix)); |
ad076f4e | 12360 | |
949d79eb RE |
12361 | fix->insn = insn; |
12362 | fix->address = address; | |
2b835d68 | 12363 | |
949d79eb RE |
12364 | fix->next = NULL; |
12365 | if (minipool_fix_head != NULL) | |
12366 | minipool_fix_tail->next = fix; | |
12367 | else | |
12368 | minipool_fix_head = fix; | |
12369 | ||
12370 | minipool_fix_tail = fix; | |
12371 | } | |
2b835d68 | 12372 | |
d5b7b3ae RE |
12373 | /* Record INSN, which will need fixing up to load a value from the |
12374 | minipool. ADDRESS is the offset of the insn since the start of the | |
12375 | function; LOC is a pointer to the part of the insn which requires | |
12376 | fixing; VALUE is the constant that must be loaded, which is of type | |
12377 | MODE. */ | |
949d79eb | 12378 | static void |
e32bac5b RE |
12379 | push_minipool_fix (rtx insn, HOST_WIDE_INT address, rtx *loc, |
12380 | enum machine_mode mode, rtx value) | |
949d79eb | 12381 | { |
c7319d87 | 12382 | Mfix * fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* fix)); |
949d79eb | 12383 | |
949d79eb RE |
12384 | fix->insn = insn; |
12385 | fix->address = address; | |
12386 | fix->loc = loc; | |
12387 | fix->mode = mode; | |
d5b7b3ae | 12388 | fix->fix_size = MINIPOOL_FIX_SIZE (mode); |
949d79eb | 12389 | fix->value = value; |
d5b7b3ae RE |
12390 | fix->forwards = get_attr_pool_range (insn); |
12391 | fix->backwards = get_attr_neg_pool_range (insn); | |
12392 | fix->minipool = NULL; | |
949d79eb RE |
12393 | |
12394 | /* If an insn doesn't have a range defined for it, then it isn't | |
e6d29d15 | 12395 | expecting to be reworked by this code. Better to stop now than |
949d79eb | 12396 | to generate duff assembly code. */ |
e6d29d15 | 12397 | gcc_assert (fix->forwards || fix->backwards); |
949d79eb | 12398 | |
34a9f549 PB |
12399 | /* If an entry requires 8-byte alignment then assume all constant pools |
12400 | require 4 bytes of padding. Trying to do this later on a per-pool | |
917f1b7e | 12401 | basis is awkward because existing pool entries have to be modified. */ |
88f77cba | 12402 | if (ARM_DOUBLEWORD_ALIGN && fix->fix_size >= 8) |
34a9f549 | 12403 | minipool_pad = 4; |
5a9335ef | 12404 | |
c263766c | 12405 | if (dump_file) |
d5b7b3ae | 12406 | { |
c263766c | 12407 | fprintf (dump_file, |
d5b7b3ae RE |
12408 | ";; %smode fixup for i%d; addr %lu, range (%ld,%ld): ", |
12409 | GET_MODE_NAME (mode), | |
f676971a | 12410 | INSN_UID (insn), (unsigned long) address, |
d5b7b3ae | 12411 | -1 * (long)fix->backwards, (long)fix->forwards); |
c263766c RH |
12412 | arm_print_value (dump_file, fix->value); |
12413 | fprintf (dump_file, "\n"); | |
d5b7b3ae RE |
12414 | } |
12415 | ||
6354dc9b | 12416 | /* Add it to the chain of fixes. */ |
949d79eb | 12417 | fix->next = NULL; |
f676971a | 12418 | |
949d79eb RE |
12419 | if (minipool_fix_head != NULL) |
12420 | minipool_fix_tail->next = fix; | |
12421 | else | |
12422 | minipool_fix_head = fix; | |
12423 | ||
12424 | minipool_fix_tail = fix; | |
12425 | } | |
12426 | ||
9b901d50 | 12427 | /* Return the cost of synthesizing a 64-bit constant VAL inline. |
2075b05d RE |
12428 | Returns the number of insns needed, or 99 if we don't know how to |
12429 | do it. */ | |
12430 | int | |
12431 | arm_const_double_inline_cost (rtx val) | |
b9e8bfda | 12432 | { |
9b901d50 RE |
12433 | rtx lowpart, highpart; |
12434 | enum machine_mode mode; | |
e0b92319 | 12435 | |
9b901d50 | 12436 | mode = GET_MODE (val); |
b9e8bfda | 12437 | |
9b901d50 RE |
12438 | if (mode == VOIDmode) |
12439 | mode = DImode; | |
12440 | ||
12441 | gcc_assert (GET_MODE_SIZE (mode) == 8); | |
e0b92319 | 12442 | |
9b901d50 RE |
12443 | lowpart = gen_lowpart (SImode, val); |
12444 | highpart = gen_highpart_mode (SImode, mode, val); | |
e0b92319 | 12445 | |
9b901d50 RE |
12446 | gcc_assert (GET_CODE (lowpart) == CONST_INT); |
12447 | gcc_assert (GET_CODE (highpart) == CONST_INT); | |
12448 | ||
12449 | return (arm_gen_constant (SET, SImode, NULL_RTX, INTVAL (lowpart), | |
2075b05d | 12450 | NULL_RTX, NULL_RTX, 0, 0) |
9b901d50 | 12451 | + arm_gen_constant (SET, SImode, NULL_RTX, INTVAL (highpart), |
2075b05d RE |
12452 | NULL_RTX, NULL_RTX, 0, 0)); |
12453 | } | |
12454 | ||
f3b569ca | 12455 | /* Return true if it is worthwhile to split a 64-bit constant into two |
b4a58f80 RE |
12456 | 32-bit operations. This is the case if optimizing for size, or |
12457 | if we have load delay slots, or if one 32-bit part can be done with | |
12458 | a single data operation. */ | |
12459 | bool | |
12460 | arm_const_double_by_parts (rtx val) | |
12461 | { | |
12462 | enum machine_mode mode = GET_MODE (val); | |
12463 | rtx part; | |
12464 | ||
12465 | if (optimize_size || arm_ld_sched) | |
12466 | return true; | |
12467 | ||
12468 | if (mode == VOIDmode) | |
12469 | mode = DImode; | |
e0b92319 | 12470 | |
b4a58f80 | 12471 | part = gen_highpart_mode (SImode, mode, val); |
e0b92319 | 12472 | |
b4a58f80 | 12473 | gcc_assert (GET_CODE (part) == CONST_INT); |
e0b92319 | 12474 | |
b4a58f80 RE |
12475 | if (const_ok_for_arm (INTVAL (part)) |
12476 | || const_ok_for_arm (~INTVAL (part))) | |
12477 | return true; | |
e0b92319 | 12478 | |
b4a58f80 | 12479 | part = gen_lowpart (SImode, val); |
e0b92319 | 12480 | |
b4a58f80 | 12481 | gcc_assert (GET_CODE (part) == CONST_INT); |
e0b92319 | 12482 | |
b4a58f80 RE |
12483 | if (const_ok_for_arm (INTVAL (part)) |
12484 | || const_ok_for_arm (~INTVAL (part))) | |
12485 | return true; | |
e0b92319 | 12486 | |
b4a58f80 RE |
12487 | return false; |
12488 | } | |
12489 | ||
73160ba9 DJ |
12490 | /* Return true if it is possible to inline both the high and low parts |
12491 | of a 64-bit constant into 32-bit data processing instructions. */ | |
12492 | bool | |
12493 | arm_const_double_by_immediates (rtx val) | |
12494 | { | |
12495 | enum machine_mode mode = GET_MODE (val); | |
12496 | rtx part; | |
12497 | ||
12498 | if (mode == VOIDmode) | |
12499 | mode = DImode; | |
12500 | ||
12501 | part = gen_highpart_mode (SImode, mode, val); | |
12502 | ||
12503 | gcc_assert (GET_CODE (part) == CONST_INT); | |
12504 | ||
12505 | if (!const_ok_for_arm (INTVAL (part))) | |
12506 | return false; | |
12507 | ||
12508 | part = gen_lowpart (SImode, val); | |
12509 | ||
12510 | gcc_assert (GET_CODE (part) == CONST_INT); | |
12511 | ||
12512 | if (!const_ok_for_arm (INTVAL (part))) | |
12513 | return false; | |
12514 | ||
12515 | return true; | |
12516 | } | |
12517 | ||
f0375c66 NC |
12518 | /* Scan INSN and note any of its operands that need fixing. |
12519 | If DO_PUSHES is false we do not actually push any of the fixups | |
9b901d50 | 12520 | needed. The function returns TRUE if any fixups were needed/pushed. |
f0375c66 NC |
12521 | This is used by arm_memory_load_p() which needs to know about loads |
12522 | of constants that will be converted into minipool loads. */ | |
f0375c66 | 12523 | static bool |
e32bac5b | 12524 | note_invalid_constants (rtx insn, HOST_WIDE_INT address, int do_pushes) |
949d79eb | 12525 | { |
f0375c66 | 12526 | bool result = false; |
949d79eb RE |
12527 | int opno; |
12528 | ||
d5b7b3ae | 12529 | extract_insn (insn); |
949d79eb | 12530 | |
5895f793 | 12531 | if (!constrain_operands (1)) |
949d79eb RE |
12532 | fatal_insn_not_found (insn); |
12533 | ||
8c2a5582 RE |
12534 | if (recog_data.n_alternatives == 0) |
12535 | return false; | |
12536 | ||
9b901d50 RE |
12537 | /* Fill in recog_op_alt with information about the constraints of |
12538 | this insn. */ | |
949d79eb RE |
12539 | preprocess_constraints (); |
12540 | ||
1ccbefce | 12541 | for (opno = 0; opno < recog_data.n_operands; opno++) |
949d79eb | 12542 | { |
6354dc9b | 12543 | /* Things we need to fix can only occur in inputs. */ |
36ab44c7 | 12544 | if (recog_data.operand_type[opno] != OP_IN) |
949d79eb RE |
12545 | continue; |
12546 | ||
12547 | /* If this alternative is a memory reference, then any mention | |
12548 | of constants in this alternative is really to fool reload | |
12549 | into allowing us to accept one there. We need to fix them up | |
12550 | now so that we output the right code. */ | |
12551 | if (recog_op_alt[opno][which_alternative].memory_ok) | |
12552 | { | |
1ccbefce | 12553 | rtx op = recog_data.operand[opno]; |
949d79eb | 12554 | |
9b901d50 | 12555 | if (CONSTANT_P (op)) |
f0375c66 NC |
12556 | { |
12557 | if (do_pushes) | |
12558 | push_minipool_fix (insn, address, recog_data.operand_loc[opno], | |
12559 | recog_data.operand_mode[opno], op); | |
12560 | result = true; | |
12561 | } | |
d5b7b3ae | 12562 | else if (GET_CODE (op) == MEM |
949d79eb RE |
12563 | && GET_CODE (XEXP (op, 0)) == SYMBOL_REF |
12564 | && CONSTANT_POOL_ADDRESS_P (XEXP (op, 0))) | |
f0375c66 NC |
12565 | { |
12566 | if (do_pushes) | |
244b1afb RE |
12567 | { |
12568 | rtx cop = avoid_constant_pool_reference (op); | |
12569 | ||
12570 | /* Casting the address of something to a mode narrower | |
12571 | than a word can cause avoid_constant_pool_reference() | |
12572 | to return the pool reference itself. That's no good to | |
f676971a | 12573 | us here. Lets just hope that we can use the |
244b1afb RE |
12574 | constant pool value directly. */ |
12575 | if (op == cop) | |
c769a35d | 12576 | cop = get_pool_constant (XEXP (op, 0)); |
244b1afb RE |
12577 | |
12578 | push_minipool_fix (insn, address, | |
12579 | recog_data.operand_loc[opno], | |
c769a35d | 12580 | recog_data.operand_mode[opno], cop); |
244b1afb | 12581 | } |
f0375c66 NC |
12582 | |
12583 | result = true; | |
12584 | } | |
949d79eb | 12585 | } |
2b835d68 | 12586 | } |
f0375c66 NC |
12587 | |
12588 | return result; | |
2b835d68 RE |
12589 | } |
12590 | ||
eef5973d BS |
12591 | /* Convert instructions to their cc-clobbering variant if possible, since |
12592 | that allows us to use smaller encodings. */ | |
12593 | ||
12594 | static void | |
12595 | thumb2_reorg (void) | |
12596 | { | |
12597 | basic_block bb; | |
12598 | regset_head live; | |
12599 | ||
12600 | INIT_REG_SET (&live); | |
12601 | ||
12602 | /* We are freeing block_for_insn in the toplev to keep compatibility | |
12603 | with old MDEP_REORGS that are not CFG based. Recompute it now. */ | |
12604 | compute_bb_for_insn (); | |
12605 | df_analyze (); | |
12606 | ||
12607 | FOR_EACH_BB (bb) | |
12608 | { | |
12609 | rtx insn; | |
c994a0ce | 12610 | |
eef5973d BS |
12611 | COPY_REG_SET (&live, DF_LR_OUT (bb)); |
12612 | df_simulate_initialize_backwards (bb, &live); | |
12613 | FOR_BB_INSNS_REVERSE (bb, insn) | |
12614 | { | |
12615 | if (NONJUMP_INSN_P (insn) | |
12616 | && !REGNO_REG_SET_P (&live, CC_REGNUM)) | |
12617 | { | |
12618 | rtx pat = PATTERN (insn); | |
12619 | if (GET_CODE (pat) == SET | |
12620 | && low_register_operand (XEXP (pat, 0), SImode) | |
12621 | && thumb_16bit_operator (XEXP (pat, 1), SImode) | |
12622 | && low_register_operand (XEXP (XEXP (pat, 1), 0), SImode) | |
12623 | && low_register_operand (XEXP (XEXP (pat, 1), 1), SImode)) | |
12624 | { | |
12625 | rtx dst = XEXP (pat, 0); | |
12626 | rtx src = XEXP (pat, 1); | |
12627 | rtx op0 = XEXP (src, 0); | |
c994a0ce RE |
12628 | rtx op1 = (GET_RTX_CLASS (GET_CODE (src)) == RTX_COMM_ARITH |
12629 | ? XEXP (src, 1) : NULL); | |
12630 | ||
eef5973d BS |
12631 | if (rtx_equal_p (dst, op0) |
12632 | || GET_CODE (src) == PLUS || GET_CODE (src) == MINUS) | |
12633 | { | |
12634 | rtx ccreg = gen_rtx_REG (CCmode, CC_REGNUM); | |
12635 | rtx clobber = gen_rtx_CLOBBER (VOIDmode, ccreg); | |
f63a6726 | 12636 | rtvec vec = gen_rtvec (2, pat, clobber); |
c994a0ce RE |
12637 | |
12638 | PATTERN (insn) = gen_rtx_PARALLEL (VOIDmode, vec); | |
12639 | INSN_CODE (insn) = -1; | |
12640 | } | |
12641 | /* We can also handle a commutative operation where the | |
12642 | second operand matches the destination. */ | |
12643 | else if (op1 && rtx_equal_p (dst, op1)) | |
12644 | { | |
12645 | rtx ccreg = gen_rtx_REG (CCmode, CC_REGNUM); | |
12646 | rtx clobber = gen_rtx_CLOBBER (VOIDmode, ccreg); | |
12647 | rtvec vec; | |
12648 | ||
12649 | src = copy_rtx (src); | |
12650 | XEXP (src, 0) = op1; | |
12651 | XEXP (src, 1) = op0; | |
12652 | pat = gen_rtx_SET (VOIDmode, dst, src); | |
12653 | vec = gen_rtvec (2, pat, clobber); | |
eef5973d BS |
12654 | PATTERN (insn) = gen_rtx_PARALLEL (VOIDmode, vec); |
12655 | INSN_CODE (insn) = -1; | |
12656 | } | |
12657 | } | |
12658 | } | |
c994a0ce | 12659 | |
eef5973d BS |
12660 | if (NONDEBUG_INSN_P (insn)) |
12661 | df_simulate_one_insn_backwards (bb, insn, &live); | |
12662 | } | |
12663 | } | |
c994a0ce | 12664 | |
eef5973d BS |
12665 | CLEAR_REG_SET (&live); |
12666 | } | |
12667 | ||
18dbd950 RS |
12668 | /* Gcc puts the pool in the wrong place for ARM, since we can only |
12669 | load addresses a limited distance around the pc. We do some | |
12670 | special munging to move the constant pool values to the correct | |
12671 | point in the code. */ | |
18dbd950 | 12672 | static void |
e32bac5b | 12673 | arm_reorg (void) |
2b835d68 RE |
12674 | { |
12675 | rtx insn; | |
d5b7b3ae RE |
12676 | HOST_WIDE_INT address = 0; |
12677 | Mfix * fix; | |
ad076f4e | 12678 | |
eef5973d BS |
12679 | if (TARGET_THUMB2) |
12680 | thumb2_reorg (); | |
12681 | ||
949d79eb | 12682 | minipool_fix_head = minipool_fix_tail = NULL; |
2b835d68 | 12683 | |
949d79eb RE |
12684 | /* The first insn must always be a note, or the code below won't |
12685 | scan it properly. */ | |
18dbd950 | 12686 | insn = get_insns (); |
e6d29d15 | 12687 | gcc_assert (GET_CODE (insn) == NOTE); |
34a9f549 | 12688 | minipool_pad = 0; |
949d79eb RE |
12689 | |
12690 | /* Scan all the insns and record the operands that will need fixing. */ | |
18dbd950 | 12691 | for (insn = next_nonnote_insn (insn); insn; insn = next_nonnote_insn (insn)) |
2b835d68 | 12692 | { |
9b6b54e2 | 12693 | if (TARGET_CIRRUS_FIX_INVALID_INSNS |
f0375c66 | 12694 | && (arm_cirrus_insn_p (insn) |
9b6b54e2 | 12695 | || GET_CODE (insn) == JUMP_INSN |
f0375c66 | 12696 | || arm_memory_load_p (insn))) |
9b6b54e2 NC |
12697 | cirrus_reorg (insn); |
12698 | ||
949d79eb | 12699 | if (GET_CODE (insn) == BARRIER) |
d5b7b3ae | 12700 | push_minipool_barrier (insn, address); |
f0375c66 | 12701 | else if (INSN_P (insn)) |
949d79eb RE |
12702 | { |
12703 | rtx table; | |
12704 | ||
f0375c66 | 12705 | note_invalid_constants (insn, address, true); |
949d79eb | 12706 | address += get_attr_length (insn); |
d5b7b3ae | 12707 | |
949d79eb RE |
12708 | /* If the insn is a vector jump, add the size of the table |
12709 | and skip the table. */ | |
d5b7b3ae | 12710 | if ((table = is_jump_table (insn)) != NULL) |
2b835d68 | 12711 | { |
d5b7b3ae | 12712 | address += get_jump_table_size (table); |
949d79eb RE |
12713 | insn = table; |
12714 | } | |
12715 | } | |
20fe71c2 RS |
12716 | else if (LABEL_P (insn)) |
12717 | /* Add the worst-case padding due to alignment. We don't add | |
12718 | the _current_ padding because the minipool insertions | |
12719 | themselves might change it. */ | |
12720 | address += get_label_padding (insn); | |
949d79eb | 12721 | } |
332072db | 12722 | |
d5b7b3ae | 12723 | fix = minipool_fix_head; |
f676971a | 12724 | |
949d79eb | 12725 | /* Now scan the fixups and perform the required changes. */ |
d5b7b3ae | 12726 | while (fix) |
949d79eb | 12727 | { |
d5b7b3ae RE |
12728 | Mfix * ftmp; |
12729 | Mfix * fdel; | |
12730 | Mfix * last_added_fix; | |
12731 | Mfix * last_barrier = NULL; | |
12732 | Mfix * this_fix; | |
949d79eb RE |
12733 | |
12734 | /* Skip any further barriers before the next fix. */ | |
12735 | while (fix && GET_CODE (fix->insn) == BARRIER) | |
12736 | fix = fix->next; | |
12737 | ||
d5b7b3ae | 12738 | /* No more fixes. */ |
949d79eb RE |
12739 | if (fix == NULL) |
12740 | break; | |
332072db | 12741 | |
d5b7b3ae | 12742 | last_added_fix = NULL; |
2b835d68 | 12743 | |
d5b7b3ae | 12744 | for (ftmp = fix; ftmp; ftmp = ftmp->next) |
949d79eb | 12745 | { |
949d79eb | 12746 | if (GET_CODE (ftmp->insn) == BARRIER) |
949d79eb | 12747 | { |
d5b7b3ae RE |
12748 | if (ftmp->address >= minipool_vector_head->max_address) |
12749 | break; | |
2b835d68 | 12750 | |
d5b7b3ae | 12751 | last_barrier = ftmp; |
2b835d68 | 12752 | } |
d5b7b3ae RE |
12753 | else if ((ftmp->minipool = add_minipool_forward_ref (ftmp)) == NULL) |
12754 | break; | |
12755 | ||
12756 | last_added_fix = ftmp; /* Keep track of the last fix added. */ | |
2b835d68 | 12757 | } |
949d79eb | 12758 | |
d5b7b3ae RE |
12759 | /* If we found a barrier, drop back to that; any fixes that we |
12760 | could have reached but come after the barrier will now go in | |
12761 | the next mini-pool. */ | |
949d79eb RE |
12762 | if (last_barrier != NULL) |
12763 | { | |
f676971a | 12764 | /* Reduce the refcount for those fixes that won't go into this |
d5b7b3ae RE |
12765 | pool after all. */ |
12766 | for (fdel = last_barrier->next; | |
12767 | fdel && fdel != ftmp; | |
12768 | fdel = fdel->next) | |
12769 | { | |
12770 | fdel->minipool->refcount--; | |
12771 | fdel->minipool = NULL; | |
12772 | } | |
12773 | ||
949d79eb RE |
12774 | ftmp = last_barrier; |
12775 | } | |
12776 | else | |
2bfa88dc | 12777 | { |
d5b7b3ae RE |
12778 | /* ftmp is first fix that we can't fit into this pool and |
12779 | there no natural barriers that we could use. Insert a | |
12780 | new barrier in the code somewhere between the previous | |
12781 | fix and this one, and arrange to jump around it. */ | |
12782 | HOST_WIDE_INT max_address; | |
12783 | ||
12784 | /* The last item on the list of fixes must be a barrier, so | |
12785 | we can never run off the end of the list of fixes without | |
12786 | last_barrier being set. */ | |
e6d29d15 | 12787 | gcc_assert (ftmp); |
d5b7b3ae RE |
12788 | |
12789 | max_address = minipool_vector_head->max_address; | |
2bfa88dc RE |
12790 | /* Check that there isn't another fix that is in range that |
12791 | we couldn't fit into this pool because the pool was | |
12792 | already too large: we need to put the pool before such an | |
7a7017bc PB |
12793 | instruction. The pool itself may come just after the |
12794 | fix because create_fix_barrier also allows space for a | |
12795 | jump instruction. */ | |
d5b7b3ae | 12796 | if (ftmp->address < max_address) |
7a7017bc | 12797 | max_address = ftmp->address + 1; |
d5b7b3ae RE |
12798 | |
12799 | last_barrier = create_fix_barrier (last_added_fix, max_address); | |
12800 | } | |
12801 | ||
12802 | assign_minipool_offsets (last_barrier); | |
12803 | ||
12804 | while (ftmp) | |
12805 | { | |
12806 | if (GET_CODE (ftmp->insn) != BARRIER | |
12807 | && ((ftmp->minipool = add_minipool_backward_ref (ftmp)) | |
12808 | == NULL)) | |
12809 | break; | |
2bfa88dc | 12810 | |
d5b7b3ae | 12811 | ftmp = ftmp->next; |
2bfa88dc | 12812 | } |
949d79eb RE |
12813 | |
12814 | /* Scan over the fixes we have identified for this pool, fixing them | |
12815 | up and adding the constants to the pool itself. */ | |
d5b7b3ae | 12816 | for (this_fix = fix; this_fix && ftmp != this_fix; |
949d79eb RE |
12817 | this_fix = this_fix->next) |
12818 | if (GET_CODE (this_fix->insn) != BARRIER) | |
12819 | { | |
949d79eb | 12820 | rtx addr |
f676971a | 12821 | = plus_constant (gen_rtx_LABEL_REF (VOIDmode, |
949d79eb | 12822 | minipool_vector_label), |
d5b7b3ae | 12823 | this_fix->minipool->offset); |
949d79eb RE |
12824 | *this_fix->loc = gen_rtx_MEM (this_fix->mode, addr); |
12825 | } | |
12826 | ||
d5b7b3ae | 12827 | dump_minipool (last_barrier->insn); |
949d79eb | 12828 | fix = ftmp; |
2b835d68 | 12829 | } |
4b632bf1 | 12830 | |
949d79eb RE |
12831 | /* From now on we must synthesize any constants that we can't handle |
12832 | directly. This can happen if the RTL gets split during final | |
12833 | instruction generation. */ | |
4b632bf1 | 12834 | after_arm_reorg = 1; |
c7319d87 RE |
12835 | |
12836 | /* Free the minipool memory. */ | |
12837 | obstack_free (&minipool_obstack, minipool_startobj); | |
2b835d68 | 12838 | } |
cce8749e CH |
12839 | \f |
12840 | /* Routines to output assembly language. */ | |
12841 | ||
f3bb6135 | 12842 | /* If the rtx is the correct value then return the string of the number. |
ff9940b0 | 12843 | In this way we can ensure that valid double constants are generated even |
6354dc9b | 12844 | when cross compiling. */ |
cd2b33d0 | 12845 | const char * |
e32bac5b | 12846 | fp_immediate_constant (rtx x) |
ff9940b0 RE |
12847 | { |
12848 | REAL_VALUE_TYPE r; | |
12849 | int i; | |
f676971a | 12850 | |
9b66ebb1 PB |
12851 | if (!fp_consts_inited) |
12852 | init_fp_table (); | |
f676971a | 12853 | |
ff9940b0 RE |
12854 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); |
12855 | for (i = 0; i < 8; i++) | |
9b66ebb1 PB |
12856 | if (REAL_VALUES_EQUAL (r, values_fp[i])) |
12857 | return strings_fp[i]; | |
f3bb6135 | 12858 | |
e6d29d15 | 12859 | gcc_unreachable (); |
ff9940b0 RE |
12860 | } |
12861 | ||
9997d19d | 12862 | /* As for fp_immediate_constant, but value is passed directly, not in rtx. */ |
cd2b33d0 | 12863 | static const char * |
e32bac5b | 12864 | fp_const_from_val (REAL_VALUE_TYPE *r) |
9997d19d RE |
12865 | { |
12866 | int i; | |
12867 | ||
9b66ebb1 PB |
12868 | if (!fp_consts_inited) |
12869 | init_fp_table (); | |
9997d19d RE |
12870 | |
12871 | for (i = 0; i < 8; i++) | |
9b66ebb1 PB |
12872 | if (REAL_VALUES_EQUAL (*r, values_fp[i])) |
12873 | return strings_fp[i]; | |
9997d19d | 12874 | |
e6d29d15 | 12875 | gcc_unreachable (); |
9997d19d | 12876 | } |
ff9940b0 | 12877 | |
cce8749e CH |
12878 | /* Output the operands of a LDM/STM instruction to STREAM. |
12879 | MASK is the ARM register set mask of which only bits 0-15 are important. | |
6d3d9133 | 12880 | REG is the base register, either the frame pointer or the stack pointer, |
a15908a4 PB |
12881 | INSTR is the possibly suffixed load or store instruction. |
12882 | RFE is nonzero if the instruction should also copy spsr to cpsr. */ | |
b279b20a | 12883 | |
d5b7b3ae | 12884 | static void |
b279b20a | 12885 | print_multi_reg (FILE *stream, const char *instr, unsigned reg, |
a15908a4 | 12886 | unsigned long mask, int rfe) |
cce8749e | 12887 | { |
b279b20a NC |
12888 | unsigned i; |
12889 | bool not_first = FALSE; | |
cce8749e | 12890 | |
a15908a4 | 12891 | gcc_assert (!rfe || (mask & (1 << PC_REGNUM))); |
1d5473cb | 12892 | fputc ('\t', stream); |
dd18ae56 | 12893 | asm_fprintf (stream, instr, reg); |
5b3e6663 | 12894 | fputc ('{', stream); |
f676971a | 12895 | |
d5b7b3ae | 12896 | for (i = 0; i <= LAST_ARM_REGNUM; i++) |
cce8749e CH |
12897 | if (mask & (1 << i)) |
12898 | { | |
12899 | if (not_first) | |
12900 | fprintf (stream, ", "); | |
f676971a | 12901 | |
dd18ae56 | 12902 | asm_fprintf (stream, "%r", i); |
cce8749e CH |
12903 | not_first = TRUE; |
12904 | } | |
f3bb6135 | 12905 | |
a15908a4 PB |
12906 | if (rfe) |
12907 | fprintf (stream, "}^\n"); | |
12908 | else | |
12909 | fprintf (stream, "}\n"); | |
f3bb6135 | 12910 | } |
cce8749e | 12911 | |
9b66ebb1 | 12912 | |
8edfc4cc | 12913 | /* Output a FLDMD instruction to STREAM. |
9728c9d1 PB |
12914 | BASE if the register containing the address. |
12915 | REG and COUNT specify the register range. | |
8edfc4cc MS |
12916 | Extra registers may be added to avoid hardware bugs. |
12917 | ||
12918 | We output FLDMD even for ARMv5 VFP implementations. Although | |
12919 | FLDMD is technically not supported until ARMv6, it is believed | |
12920 | that all VFP implementations support its use in this context. */ | |
9b66ebb1 PB |
12921 | |
12922 | static void | |
8edfc4cc | 12923 | vfp_output_fldmd (FILE * stream, unsigned int base, int reg, int count) |
9b66ebb1 PB |
12924 | { |
12925 | int i; | |
12926 | ||
9728c9d1 PB |
12927 | /* Workaround ARM10 VFPr1 bug. */ |
12928 | if (count == 2 && !arm_arch6) | |
12929 | { | |
12930 | if (reg == 15) | |
12931 | reg--; | |
12932 | count++; | |
12933 | } | |
12934 | ||
f1adb0a9 JB |
12935 | /* FLDMD may not load more than 16 doubleword registers at a time. Split the |
12936 | load into multiple parts if we have to handle more than 16 registers. */ | |
12937 | if (count > 16) | |
12938 | { | |
12939 | vfp_output_fldmd (stream, base, reg, 16); | |
12940 | vfp_output_fldmd (stream, base, reg + 16, count - 16); | |
12941 | return; | |
12942 | } | |
12943 | ||
9b66ebb1 | 12944 | fputc ('\t', stream); |
8edfc4cc | 12945 | asm_fprintf (stream, "fldmfdd\t%r!, {", base); |
9b66ebb1 | 12946 | |
9728c9d1 | 12947 | for (i = reg; i < reg + count; i++) |
9b66ebb1 | 12948 | { |
9728c9d1 | 12949 | if (i > reg) |
9b66ebb1 | 12950 | fputs (", ", stream); |
9728c9d1 | 12951 | asm_fprintf (stream, "d%d", i); |
9b66ebb1 PB |
12952 | } |
12953 | fputs ("}\n", stream); | |
9728c9d1 | 12954 | |
9b66ebb1 PB |
12955 | } |
12956 | ||
12957 | ||
12958 | /* Output the assembly for a store multiple. */ | |
12959 | ||
12960 | const char * | |
8edfc4cc | 12961 | vfp_output_fstmd (rtx * operands) |
9b66ebb1 PB |
12962 | { |
12963 | char pattern[100]; | |
12964 | int p; | |
12965 | int base; | |
12966 | int i; | |
12967 | ||
8edfc4cc | 12968 | strcpy (pattern, "fstmfdd\t%m0!, {%P1"); |
9b66ebb1 PB |
12969 | p = strlen (pattern); |
12970 | ||
e6d29d15 | 12971 | gcc_assert (GET_CODE (operands[1]) == REG); |
9b66ebb1 PB |
12972 | |
12973 | base = (REGNO (operands[1]) - FIRST_VFP_REGNUM) / 2; | |
12974 | for (i = 1; i < XVECLEN (operands[2], 0); i++) | |
12975 | { | |
12976 | p += sprintf (&pattern[p], ", d%d", base + i); | |
12977 | } | |
12978 | strcpy (&pattern[p], "}"); | |
12979 | ||
12980 | output_asm_insn (pattern, operands); | |
12981 | return ""; | |
12982 | } | |
12983 | ||
12984 | ||
9728c9d1 PB |
12985 | /* Emit RTL to save block of VFP register pairs to the stack. Returns the |
12986 | number of bytes pushed. */ | |
9b66ebb1 | 12987 | |
9728c9d1 | 12988 | static int |
8edfc4cc | 12989 | vfp_emit_fstmd (int base_reg, int count) |
9b66ebb1 PB |
12990 | { |
12991 | rtx par; | |
12992 | rtx dwarf; | |
12993 | rtx tmp, reg; | |
12994 | int i; | |
12995 | ||
9728c9d1 PB |
12996 | /* Workaround ARM10 VFPr1 bug. Data corruption can occur when exactly two |
12997 | register pairs are stored by a store multiple insn. We avoid this | |
12998 | by pushing an extra pair. */ | |
12999 | if (count == 2 && !arm_arch6) | |
13000 | { | |
13001 | if (base_reg == LAST_VFP_REGNUM - 3) | |
13002 | base_reg -= 2; | |
13003 | count++; | |
13004 | } | |
13005 | ||
f1adb0a9 JB |
13006 | /* FSTMD may not store more than 16 doubleword registers at once. Split |
13007 | larger stores into multiple parts (up to a maximum of two, in | |
13008 | practice). */ | |
13009 | if (count > 16) | |
13010 | { | |
13011 | int saved; | |
13012 | /* NOTE: base_reg is an internal register number, so each D register | |
13013 | counts as 2. */ | |
13014 | saved = vfp_emit_fstmd (base_reg + 32, count - 16); | |
13015 | saved += vfp_emit_fstmd (base_reg, 16); | |
13016 | return saved; | |
13017 | } | |
13018 | ||
9b66ebb1 PB |
13019 | par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count)); |
13020 | dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (count + 1)); | |
13021 | ||
13022 | reg = gen_rtx_REG (DFmode, base_reg); | |
13023 | base_reg += 2; | |
13024 | ||
13025 | XVECEXP (par, 0, 0) | |
13026 | = gen_rtx_SET (VOIDmode, | |
9abf5d7b RR |
13027 | gen_frame_mem |
13028 | (BLKmode, | |
13029 | gen_rtx_PRE_MODIFY (Pmode, | |
13030 | stack_pointer_rtx, | |
13031 | plus_constant | |
13032 | (stack_pointer_rtx, | |
13033 | - (count * 8))) | |
13034 | ), | |
9b66ebb1 PB |
13035 | gen_rtx_UNSPEC (BLKmode, |
13036 | gen_rtvec (1, reg), | |
13037 | UNSPEC_PUSH_MULT)); | |
13038 | ||
13039 | tmp = gen_rtx_SET (VOIDmode, stack_pointer_rtx, | |
8edfc4cc | 13040 | plus_constant (stack_pointer_rtx, -(count * 8))); |
9b66ebb1 PB |
13041 | RTX_FRAME_RELATED_P (tmp) = 1; |
13042 | XVECEXP (dwarf, 0, 0) = tmp; | |
13043 | ||
13044 | tmp = gen_rtx_SET (VOIDmode, | |
31fa16b6 | 13045 | gen_frame_mem (DFmode, stack_pointer_rtx), |
9b66ebb1 PB |
13046 | reg); |
13047 | RTX_FRAME_RELATED_P (tmp) = 1; | |
13048 | XVECEXP (dwarf, 0, 1) = tmp; | |
13049 | ||
13050 | for (i = 1; i < count; i++) | |
13051 | { | |
13052 | reg = gen_rtx_REG (DFmode, base_reg); | |
13053 | base_reg += 2; | |
13054 | XVECEXP (par, 0, i) = gen_rtx_USE (VOIDmode, reg); | |
13055 | ||
13056 | tmp = gen_rtx_SET (VOIDmode, | |
31fa16b6 | 13057 | gen_frame_mem (DFmode, |
d66437c5 RE |
13058 | plus_constant (stack_pointer_rtx, |
13059 | i * 8)), | |
9b66ebb1 PB |
13060 | reg); |
13061 | RTX_FRAME_RELATED_P (tmp) = 1; | |
13062 | XVECEXP (dwarf, 0, i + 1) = tmp; | |
13063 | } | |
13064 | ||
13065 | par = emit_insn (par); | |
bbbbb16a | 13066 | add_reg_note (par, REG_FRAME_RELATED_EXPR, dwarf); |
9728c9d1 PB |
13067 | RTX_FRAME_RELATED_P (par) = 1; |
13068 | ||
8edfc4cc | 13069 | return count * 8; |
9b66ebb1 PB |
13070 | } |
13071 | ||
9403b7f7 RS |
13072 | /* Emit a call instruction with pattern PAT. ADDR is the address of |
13073 | the call target. */ | |
13074 | ||
13075 | void | |
13076 | arm_emit_call_insn (rtx pat, rtx addr) | |
13077 | { | |
13078 | rtx insn; | |
13079 | ||
13080 | insn = emit_call_insn (pat); | |
13081 | ||
13082 | /* The PIC register is live on entry to VxWorks PIC PLT entries. | |
13083 | If the call might use such an entry, add a use of the PIC register | |
13084 | to the instruction's CALL_INSN_FUNCTION_USAGE. */ | |
13085 | if (TARGET_VXWORKS_RTP | |
13086 | && flag_pic | |
13087 | && GET_CODE (addr) == SYMBOL_REF | |
13088 | && (SYMBOL_REF_DECL (addr) | |
13089 | ? !targetm.binds_local_p (SYMBOL_REF_DECL (addr)) | |
13090 | : !SYMBOL_REF_LOCAL_P (addr))) | |
13091 | { | |
13092 | require_pic_register (); | |
13093 | use_reg (&CALL_INSN_FUNCTION_USAGE (insn), cfun->machine->pic_reg); | |
13094 | } | |
13095 | } | |
9b66ebb1 | 13096 | |
6354dc9b | 13097 | /* Output a 'call' insn. */ |
cd2b33d0 | 13098 | const char * |
e32bac5b | 13099 | output_call (rtx *operands) |
cce8749e | 13100 | { |
e6d29d15 | 13101 | gcc_assert (!arm_arch5); /* Patterns should call blx <reg> directly. */ |
cce8749e | 13102 | |
68d560d4 | 13103 | /* Handle calls to lr using ip (which may be clobbered in subr anyway). */ |
62b10bbc | 13104 | if (REGNO (operands[0]) == LR_REGNUM) |
cce8749e | 13105 | { |
62b10bbc | 13106 | operands[0] = gen_rtx_REG (SImode, IP_REGNUM); |
1d5473cb | 13107 | output_asm_insn ("mov%?\t%0, %|lr", operands); |
cce8749e | 13108 | } |
f676971a | 13109 | |
1d5473cb | 13110 | output_asm_insn ("mov%?\t%|lr, %|pc", operands); |
f676971a | 13111 | |
68d560d4 | 13112 | if (TARGET_INTERWORK || arm_arch4t) |
da6558fd NC |
13113 | output_asm_insn ("bx%?\t%0", operands); |
13114 | else | |
13115 | output_asm_insn ("mov%?\t%|pc, %0", operands); | |
f676971a | 13116 | |
f3bb6135 RE |
13117 | return ""; |
13118 | } | |
cce8749e | 13119 | |
0986ef45 JB |
13120 | /* Output a 'call' insn that is a reference in memory. This is |
13121 | disabled for ARMv5 and we prefer a blx instead because otherwise | |
13122 | there's a significant performance overhead. */ | |
cd2b33d0 | 13123 | const char * |
e32bac5b | 13124 | output_call_mem (rtx *operands) |
ff9940b0 | 13125 | { |
0986ef45 JB |
13126 | gcc_assert (!arm_arch5); |
13127 | if (TARGET_INTERWORK) | |
da6558fd NC |
13128 | { |
13129 | output_asm_insn ("ldr%?\t%|ip, %0", operands); | |
13130 | output_asm_insn ("mov%?\t%|lr, %|pc", operands); | |
13131 | output_asm_insn ("bx%?\t%|ip", operands); | |
13132 | } | |
6ab5da80 RE |
13133 | else if (regno_use_in (LR_REGNUM, operands[0])) |
13134 | { | |
13135 | /* LR is used in the memory address. We load the address in the | |
13136 | first instruction. It's safe to use IP as the target of the | |
13137 | load since the call will kill it anyway. */ | |
13138 | output_asm_insn ("ldr%?\t%|ip, %0", operands); | |
0986ef45 JB |
13139 | output_asm_insn ("mov%?\t%|lr, %|pc", operands); |
13140 | if (arm_arch4t) | |
13141 | output_asm_insn ("bx%?\t%|ip", operands); | |
68d560d4 | 13142 | else |
0986ef45 | 13143 | output_asm_insn ("mov%?\t%|pc, %|ip", operands); |
6ab5da80 | 13144 | } |
da6558fd NC |
13145 | else |
13146 | { | |
13147 | output_asm_insn ("mov%?\t%|lr, %|pc", operands); | |
13148 | output_asm_insn ("ldr%?\t%|pc, %0", operands); | |
13149 | } | |
13150 | ||
f3bb6135 RE |
13151 | return ""; |
13152 | } | |
ff9940b0 RE |
13153 | |
13154 | ||
3b684012 RE |
13155 | /* Output a move from arm registers to an fpa registers. |
13156 | OPERANDS[0] is an fpa register. | |
ff9940b0 | 13157 | OPERANDS[1] is the first registers of an arm register pair. */ |
cd2b33d0 | 13158 | const char * |
e32bac5b | 13159 | output_mov_long_double_fpa_from_arm (rtx *operands) |
ff9940b0 RE |
13160 | { |
13161 | int arm_reg0 = REGNO (operands[1]); | |
13162 | rtx ops[3]; | |
13163 | ||
e6d29d15 | 13164 | gcc_assert (arm_reg0 != IP_REGNUM); |
f3bb6135 | 13165 | |
43cffd11 RE |
13166 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
13167 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
13168 | ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0); | |
f676971a | 13169 | |
5b3e6663 | 13170 | output_asm_insn ("stm%(fd%)\t%|sp!, {%0, %1, %2}", ops); |
1d5473cb | 13171 | output_asm_insn ("ldf%?e\t%0, [%|sp], #12", operands); |
f676971a | 13172 | |
f3bb6135 RE |
13173 | return ""; |
13174 | } | |
ff9940b0 | 13175 | |
3b684012 | 13176 | /* Output a move from an fpa register to arm registers. |
ff9940b0 | 13177 | OPERANDS[0] is the first registers of an arm register pair. |
3b684012 | 13178 | OPERANDS[1] is an fpa register. */ |
cd2b33d0 | 13179 | const char * |
e32bac5b | 13180 | output_mov_long_double_arm_from_fpa (rtx *operands) |
ff9940b0 RE |
13181 | { |
13182 | int arm_reg0 = REGNO (operands[0]); | |
13183 | rtx ops[3]; | |
13184 | ||
e6d29d15 | 13185 | gcc_assert (arm_reg0 != IP_REGNUM); |
f3bb6135 | 13186 | |
43cffd11 RE |
13187 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
13188 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
13189 | ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0); | |
ff9940b0 | 13190 | |
1d5473cb | 13191 | output_asm_insn ("stf%?e\t%1, [%|sp, #-12]!", operands); |
5b3e6663 | 13192 | output_asm_insn ("ldm%(fd%)\t%|sp!, {%0, %1, %2}", ops); |
f3bb6135 RE |
13193 | return ""; |
13194 | } | |
ff9940b0 RE |
13195 | |
13196 | /* Output a move from arm registers to arm registers of a long double | |
13197 | OPERANDS[0] is the destination. | |
13198 | OPERANDS[1] is the source. */ | |
cd2b33d0 | 13199 | const char * |
e32bac5b | 13200 | output_mov_long_double_arm_from_arm (rtx *operands) |
ff9940b0 | 13201 | { |
6354dc9b | 13202 | /* We have to be careful here because the two might overlap. */ |
ff9940b0 RE |
13203 | int dest_start = REGNO (operands[0]); |
13204 | int src_start = REGNO (operands[1]); | |
13205 | rtx ops[2]; | |
13206 | int i; | |
13207 | ||
13208 | if (dest_start < src_start) | |
13209 | { | |
13210 | for (i = 0; i < 3; i++) | |
13211 | { | |
43cffd11 RE |
13212 | ops[0] = gen_rtx_REG (SImode, dest_start + i); |
13213 | ops[1] = gen_rtx_REG (SImode, src_start + i); | |
9997d19d | 13214 | output_asm_insn ("mov%?\t%0, %1", ops); |
ff9940b0 RE |
13215 | } |
13216 | } | |
13217 | else | |
13218 | { | |
13219 | for (i = 2; i >= 0; i--) | |
13220 | { | |
43cffd11 RE |
13221 | ops[0] = gen_rtx_REG (SImode, dest_start + i); |
13222 | ops[1] = gen_rtx_REG (SImode, src_start + i); | |
9997d19d | 13223 | output_asm_insn ("mov%?\t%0, %1", ops); |
ff9940b0 RE |
13224 | } |
13225 | } | |
f3bb6135 | 13226 | |
ff9940b0 RE |
13227 | return ""; |
13228 | } | |
13229 | ||
a552b644 RR |
13230 | void |
13231 | arm_emit_movpair (rtx dest, rtx src) | |
13232 | { | |
13233 | /* If the src is an immediate, simplify it. */ | |
13234 | if (CONST_INT_P (src)) | |
13235 | { | |
13236 | HOST_WIDE_INT val = INTVAL (src); | |
13237 | emit_set_insn (dest, GEN_INT (val & 0x0000ffff)); | |
13238 | if ((val >> 16) & 0x0000ffff) | |
13239 | emit_set_insn (gen_rtx_ZERO_EXTRACT (SImode, dest, GEN_INT (16), | |
13240 | GEN_INT (16)), | |
13241 | GEN_INT ((val >> 16) & 0x0000ffff)); | |
13242 | return; | |
13243 | } | |
13244 | emit_set_insn (dest, gen_rtx_HIGH (SImode, src)); | |
13245 | emit_set_insn (dest, gen_rtx_LO_SUM (SImode, dest, src)); | |
13246 | } | |
571191af | 13247 | |
3b684012 RE |
13248 | /* Output a move from arm registers to an fpa registers. |
13249 | OPERANDS[0] is an fpa register. | |
cce8749e | 13250 | OPERANDS[1] is the first registers of an arm register pair. */ |
cd2b33d0 | 13251 | const char * |
e32bac5b | 13252 | output_mov_double_fpa_from_arm (rtx *operands) |
cce8749e CH |
13253 | { |
13254 | int arm_reg0 = REGNO (operands[1]); | |
13255 | rtx ops[2]; | |
13256 | ||
e6d29d15 | 13257 | gcc_assert (arm_reg0 != IP_REGNUM); |
f676971a | 13258 | |
43cffd11 RE |
13259 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
13260 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
5b3e6663 | 13261 | output_asm_insn ("stm%(fd%)\t%|sp!, {%0, %1}", ops); |
1d5473cb | 13262 | output_asm_insn ("ldf%?d\t%0, [%|sp], #8", operands); |
f3bb6135 RE |
13263 | return ""; |
13264 | } | |
cce8749e | 13265 | |
3b684012 | 13266 | /* Output a move from an fpa register to arm registers. |
cce8749e | 13267 | OPERANDS[0] is the first registers of an arm register pair. |
3b684012 | 13268 | OPERANDS[1] is an fpa register. */ |
cd2b33d0 | 13269 | const char * |
e32bac5b | 13270 | output_mov_double_arm_from_fpa (rtx *operands) |
cce8749e CH |
13271 | { |
13272 | int arm_reg0 = REGNO (operands[0]); | |
13273 | rtx ops[2]; | |
13274 | ||
e6d29d15 | 13275 | gcc_assert (arm_reg0 != IP_REGNUM); |
f3bb6135 | 13276 | |
43cffd11 RE |
13277 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
13278 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
1d5473cb | 13279 | output_asm_insn ("stf%?d\t%1, [%|sp, #-8]!", operands); |
5b3e6663 | 13280 | output_asm_insn ("ldm%(fd%)\t%|sp!, {%0, %1}", ops); |
f3bb6135 RE |
13281 | return ""; |
13282 | } | |
cce8749e | 13283 | |
16a9afdc JZ |
13284 | /* Output a move between double words. It must be REG<-MEM |
13285 | or MEM<-REG. */ | |
cd2b33d0 | 13286 | const char * |
3598da80 | 13287 | output_move_double (rtx *operands, bool emit, int *count) |
cce8749e CH |
13288 | { |
13289 | enum rtx_code code0 = GET_CODE (operands[0]); | |
13290 | enum rtx_code code1 = GET_CODE (operands[1]); | |
56636818 | 13291 | rtx otherops[3]; |
3598da80 RR |
13292 | if (count) |
13293 | *count = 1; | |
13294 | ||
13295 | /* The only case when this might happen is when | |
13296 | you are looking at the length of a DImode instruction | |
13297 | that has an invalid constant in it. */ | |
13298 | if (code0 == REG && code1 != MEM) | |
13299 | { | |
13300 | gcc_assert (!emit); | |
13301 | *count = 2; | |
13302 | return ""; | |
13303 | } | |
13304 | ||
cce8749e CH |
13305 | |
13306 | if (code0 == REG) | |
13307 | { | |
f0b4bdd5 | 13308 | unsigned int reg0 = REGNO (operands[0]); |
cce8749e | 13309 | |
43cffd11 | 13310 | otherops[0] = gen_rtx_REG (SImode, 1 + reg0); |
f676971a | 13311 | |
e6d29d15 NS |
13312 | gcc_assert (code1 == MEM); /* Constraints should ensure this. */ |
13313 | ||
13314 | switch (GET_CODE (XEXP (operands[1], 0))) | |
cce8749e | 13315 | { |
e6d29d15 | 13316 | case REG: |
3598da80 RR |
13317 | |
13318 | if (emit) | |
13319 | { | |
13320 | if (TARGET_LDRD | |
13321 | && !(fix_cm3_ldrd && reg0 == REGNO(XEXP (operands[1], 0)))) | |
13322 | output_asm_insn ("ldr%(d%)\t%0, [%m1]", operands); | |
13323 | else | |
13324 | output_asm_insn ("ldm%(ia%)\t%m1, %M0", operands); | |
13325 | } | |
e6d29d15 | 13326 | break; |
e0b92319 | 13327 | |
e6d29d15 NS |
13328 | case PRE_INC: |
13329 | gcc_assert (TARGET_LDRD); | |
3598da80 RR |
13330 | if (emit) |
13331 | output_asm_insn ("ldr%(d%)\t%0, [%m1, #8]!", operands); | |
13332 | ||
e6d29d15 | 13333 | break; |
e0b92319 | 13334 | |
e6d29d15 | 13335 | case PRE_DEC: |
3598da80 RR |
13336 | if (emit) |
13337 | { | |
13338 | if (TARGET_LDRD) | |
13339 | output_asm_insn ("ldr%(d%)\t%0, [%m1, #-8]!", operands); | |
13340 | else | |
13341 | output_asm_insn ("ldm%(db%)\t%m1!, %M0", operands); | |
13342 | } | |
e6d29d15 | 13343 | break; |
e0b92319 | 13344 | |
e6d29d15 | 13345 | case POST_INC: |
3598da80 RR |
13346 | |
13347 | if (emit) | |
13348 | { | |
13349 | if (TARGET_LDRD) | |
13350 | output_asm_insn ("ldr%(d%)\t%0, [%m1], #8", operands); | |
13351 | else | |
13352 | output_asm_insn ("ldm%(ia%)\t%m1!, %M0", operands); | |
13353 | } | |
e6d29d15 | 13354 | break; |
e0b92319 | 13355 | |
e6d29d15 NS |
13356 | case POST_DEC: |
13357 | gcc_assert (TARGET_LDRD); | |
3598da80 RR |
13358 | if (emit) |
13359 | output_asm_insn ("ldr%(d%)\t%0, [%m1], #-8", operands); | |
e6d29d15 | 13360 | break; |
e0b92319 | 13361 | |
e6d29d15 NS |
13362 | case PRE_MODIFY: |
13363 | case POST_MODIFY: | |
5fd42423 PB |
13364 | /* Autoicrement addressing modes should never have overlapping |
13365 | base and destination registers, and overlapping index registers | |
13366 | are already prohibited, so this doesn't need to worry about | |
13367 | fix_cm3_ldrd. */ | |
e6d29d15 NS |
13368 | otherops[0] = operands[0]; |
13369 | otherops[1] = XEXP (XEXP (XEXP (operands[1], 0), 1), 0); | |
13370 | otherops[2] = XEXP (XEXP (XEXP (operands[1], 0), 1), 1); | |
e0b92319 | 13371 | |
e6d29d15 | 13372 | if (GET_CODE (XEXP (operands[1], 0)) == PRE_MODIFY) |
cce8749e | 13373 | { |
e6d29d15 | 13374 | if (reg_overlap_mentioned_p (otherops[0], otherops[2])) |
fdd695fd | 13375 | { |
e6d29d15 | 13376 | /* Registers overlap so split out the increment. */ |
3598da80 RR |
13377 | if (emit) |
13378 | { | |
13379 | output_asm_insn ("add%?\t%1, %1, %2", otherops); | |
13380 | output_asm_insn ("ldr%(d%)\t%0, [%1] @split", otherops); | |
13381 | } | |
13382 | if (count) | |
13383 | *count = 2; | |
fdd695fd PB |
13384 | } |
13385 | else | |
fe2d934b | 13386 | { |
ff128632 RE |
13387 | /* Use a single insn if we can. |
13388 | FIXME: IWMMXT allows offsets larger than ldrd can | |
13389 | handle, fix these up with a pair of ldr. */ | |
13390 | if (TARGET_THUMB2 | |
13391 | || GET_CODE (otherops[2]) != CONST_INT | |
13392 | || (INTVAL (otherops[2]) > -256 | |
13393 | && INTVAL (otherops[2]) < 256)) | |
3598da80 RR |
13394 | { |
13395 | if (emit) | |
13396 | output_asm_insn ("ldr%(d%)\t%0, [%1, %2]!", otherops); | |
13397 | } | |
ff128632 | 13398 | else |
fe2d934b | 13399 | { |
3598da80 RR |
13400 | if (emit) |
13401 | { | |
13402 | output_asm_insn ("ldr%?\t%0, [%1, %2]!", otherops); | |
13403 | output_asm_insn ("ldr%?\t%H0, [%1, #4]", otherops); | |
13404 | } | |
13405 | if (count) | |
13406 | *count = 2; | |
13407 | ||
fe2d934b | 13408 | } |
fe2d934b | 13409 | } |
e6d29d15 NS |
13410 | } |
13411 | else | |
13412 | { | |
ff128632 RE |
13413 | /* Use a single insn if we can. |
13414 | FIXME: IWMMXT allows offsets larger than ldrd can handle, | |
fe2d934b | 13415 | fix these up with a pair of ldr. */ |
ff128632 RE |
13416 | if (TARGET_THUMB2 |
13417 | || GET_CODE (otherops[2]) != CONST_INT | |
13418 | || (INTVAL (otherops[2]) > -256 | |
13419 | && INTVAL (otherops[2]) < 256)) | |
3598da80 RR |
13420 | { |
13421 | if (emit) | |
13422 | output_asm_insn ("ldr%(d%)\t%0, [%1], %2", otherops); | |
13423 | } | |
ff128632 | 13424 | else |
fe2d934b | 13425 | { |
3598da80 RR |
13426 | if (emit) |
13427 | { | |
13428 | output_asm_insn ("ldr%?\t%H0, [%1, #4]", otherops); | |
13429 | output_asm_insn ("ldr%?\t%0, [%1], %2", otherops); | |
13430 | } | |
13431 | if (count) | |
13432 | *count = 2; | |
fe2d934b | 13433 | } |
e6d29d15 NS |
13434 | } |
13435 | break; | |
e0b92319 | 13436 | |
e6d29d15 NS |
13437 | case LABEL_REF: |
13438 | case CONST: | |
5dea0c19 PB |
13439 | /* We might be able to use ldrd %0, %1 here. However the range is |
13440 | different to ldr/adr, and it is broken on some ARMv7-M | |
13441 | implementations. */ | |
5fd42423 PB |
13442 | /* Use the second register of the pair to avoid problematic |
13443 | overlap. */ | |
13444 | otherops[1] = operands[1]; | |
3598da80 RR |
13445 | if (emit) |
13446 | output_asm_insn ("adr%?\t%0, %1", otherops); | |
5fd42423 | 13447 | operands[1] = otherops[0]; |
3598da80 RR |
13448 | if (emit) |
13449 | { | |
13450 | if (TARGET_LDRD) | |
13451 | output_asm_insn ("ldr%(d%)\t%0, [%1]", operands); | |
13452 | else | |
13453 | output_asm_insn ("ldm%(ia%)\t%1, %M0", operands); | |
13454 | } | |
13455 | ||
13456 | if (count) | |
13457 | *count = 2; | |
e6d29d15 | 13458 | break; |
e0b92319 | 13459 | |
5b3e6663 | 13460 | /* ??? This needs checking for thumb2. */ |
e6d29d15 NS |
13461 | default: |
13462 | if (arm_add_operand (XEXP (XEXP (operands[1], 0), 1), | |
13463 | GET_MODE (XEXP (XEXP (operands[1], 0), 1)))) | |
13464 | { | |
13465 | otherops[0] = operands[0]; | |
13466 | otherops[1] = XEXP (XEXP (operands[1], 0), 0); | |
13467 | otherops[2] = XEXP (XEXP (operands[1], 0), 1); | |
e0b92319 | 13468 | |
e6d29d15 | 13469 | if (GET_CODE (XEXP (operands[1], 0)) == PLUS) |
fdd695fd | 13470 | { |
5dea0c19 | 13471 | if (GET_CODE (otherops[2]) == CONST_INT && !TARGET_LDRD) |
2b835d68 | 13472 | { |
e6d29d15 | 13473 | switch ((int) INTVAL (otherops[2])) |
2b835d68 | 13474 | { |
e6d29d15 | 13475 | case -8: |
3598da80 RR |
13476 | if (emit) |
13477 | output_asm_insn ("ldm%(db%)\t%1, %M0", otherops); | |
e6d29d15 NS |
13478 | return ""; |
13479 | case -4: | |
5b3e6663 PB |
13480 | if (TARGET_THUMB2) |
13481 | break; | |
3598da80 RR |
13482 | if (emit) |
13483 | output_asm_insn ("ldm%(da%)\t%1, %M0", otherops); | |
e6d29d15 NS |
13484 | return ""; |
13485 | case 4: | |
5b3e6663 PB |
13486 | if (TARGET_THUMB2) |
13487 | break; | |
3598da80 RR |
13488 | if (emit) |
13489 | output_asm_insn ("ldm%(ib%)\t%1, %M0", otherops); | |
e6d29d15 | 13490 | return ""; |
fdd695fd | 13491 | } |
e6d29d15 | 13492 | } |
5fd42423 PB |
13493 | otherops[0] = gen_rtx_REG(SImode, REGNO(operands[0]) + 1); |
13494 | operands[1] = otherops[0]; | |
e6d29d15 NS |
13495 | if (TARGET_LDRD |
13496 | && (GET_CODE (otherops[2]) == REG | |
ff128632 | 13497 | || TARGET_THUMB2 |
e6d29d15 NS |
13498 | || (GET_CODE (otherops[2]) == CONST_INT |
13499 | && INTVAL (otherops[2]) > -256 | |
13500 | && INTVAL (otherops[2]) < 256))) | |
13501 | { | |
5fd42423 | 13502 | if (reg_overlap_mentioned_p (operands[0], |
e6d29d15 | 13503 | otherops[2])) |
fdd695fd | 13504 | { |
5fd42423 | 13505 | rtx tmp; |
e6d29d15 NS |
13506 | /* Swap base and index registers over to |
13507 | avoid a conflict. */ | |
5fd42423 PB |
13508 | tmp = otherops[1]; |
13509 | otherops[1] = otherops[2]; | |
13510 | otherops[2] = tmp; | |
fdd695fd | 13511 | } |
e6d29d15 NS |
13512 | /* If both registers conflict, it will usually |
13513 | have been fixed by a splitter. */ | |
5fd42423 PB |
13514 | if (reg_overlap_mentioned_p (operands[0], otherops[2]) |
13515 | || (fix_cm3_ldrd && reg0 == REGNO (otherops[1]))) | |
fdd695fd | 13516 | { |
3598da80 RR |
13517 | if (emit) |
13518 | { | |
13519 | output_asm_insn ("add%?\t%0, %1, %2", otherops); | |
13520 | output_asm_insn ("ldr%(d%)\t%0, [%1]", operands); | |
13521 | } | |
13522 | if (count) | |
13523 | *count = 2; | |
2b835d68 RE |
13524 | } |
13525 | else | |
5fd42423 PB |
13526 | { |
13527 | otherops[0] = operands[0]; | |
3598da80 RR |
13528 | if (emit) |
13529 | output_asm_insn ("ldr%(d%)\t%0, [%1, %2]", otherops); | |
5fd42423 | 13530 | } |
e6d29d15 | 13531 | return ""; |
2b835d68 | 13532 | } |
e0b92319 | 13533 | |
e6d29d15 | 13534 | if (GET_CODE (otherops[2]) == CONST_INT) |
3598da80 RR |
13535 | { |
13536 | if (emit) | |
13537 | { | |
13538 | if (!(const_ok_for_arm (INTVAL (otherops[2])))) | |
13539 | output_asm_insn ("sub%?\t%0, %1, #%n2", otherops); | |
13540 | else | |
13541 | output_asm_insn ("add%?\t%0, %1, %2", otherops); | |
13542 | } | |
13543 | ||
13544 | } | |
13545 | else | |
2b835d68 | 13546 | { |
3598da80 | 13547 | if (emit) |
e6d29d15 | 13548 | output_asm_insn ("add%?\t%0, %1, %2", otherops); |
2b835d68 | 13549 | } |
e6d29d15 NS |
13550 | } |
13551 | else | |
3598da80 RR |
13552 | { |
13553 | if (emit) | |
13554 | output_asm_insn ("sub%?\t%0, %1, %2", otherops); | |
13555 | } | |
e6d29d15 | 13556 | |
5dea0c19 | 13557 | if (TARGET_LDRD) |
5fd42423 | 13558 | return "ldr%(d%)\t%0, [%1]"; |
3598da80 RR |
13559 | |
13560 | return "ldm%(ia%)\t%1, %M0"; | |
e6d29d15 NS |
13561 | } |
13562 | else | |
13563 | { | |
13564 | otherops[1] = adjust_address (operands[1], SImode, 4); | |
13565 | /* Take care of overlapping base/data reg. */ | |
13566 | if (reg_mentioned_p (operands[0], operands[1])) | |
13567 | { | |
3598da80 RR |
13568 | if (emit) |
13569 | { | |
13570 | output_asm_insn ("ldr%?\t%0, %1", otherops); | |
13571 | output_asm_insn ("ldr%?\t%0, %1", operands); | |
13572 | } | |
13573 | if (count) | |
13574 | *count = 2; | |
13575 | ||
e6d29d15 NS |
13576 | } |
13577 | else | |
13578 | { | |
3598da80 RR |
13579 | if (emit) |
13580 | { | |
13581 | output_asm_insn ("ldr%?\t%0, %1", operands); | |
13582 | output_asm_insn ("ldr%?\t%0, %1", otherops); | |
13583 | } | |
13584 | if (count) | |
13585 | *count = 2; | |
cce8749e CH |
13586 | } |
13587 | } | |
13588 | } | |
cce8749e | 13589 | } |
e6d29d15 | 13590 | else |
cce8749e | 13591 | { |
e6d29d15 NS |
13592 | /* Constraints should ensure this. */ |
13593 | gcc_assert (code0 == MEM && code1 == REG); | |
13594 | gcc_assert (REGNO (operands[1]) != IP_REGNUM); | |
2b835d68 | 13595 | |
ff9940b0 RE |
13596 | switch (GET_CODE (XEXP (operands[0], 0))) |
13597 | { | |
13598 | case REG: | |
3598da80 RR |
13599 | if (emit) |
13600 | { | |
13601 | if (TARGET_LDRD) | |
13602 | output_asm_insn ("str%(d%)\t%1, [%m0]", operands); | |
13603 | else | |
13604 | output_asm_insn ("stm%(ia%)\t%m0, %M1", operands); | |
13605 | } | |
ff9940b0 | 13606 | break; |
2b835d68 | 13607 | |
ff9940b0 | 13608 | case PRE_INC: |
e6d29d15 | 13609 | gcc_assert (TARGET_LDRD); |
3598da80 RR |
13610 | if (emit) |
13611 | output_asm_insn ("str%(d%)\t%1, [%m0, #8]!", operands); | |
ff9940b0 | 13612 | break; |
2b835d68 | 13613 | |
ff9940b0 | 13614 | case PRE_DEC: |
3598da80 RR |
13615 | if (emit) |
13616 | { | |
13617 | if (TARGET_LDRD) | |
13618 | output_asm_insn ("str%(d%)\t%1, [%m0, #-8]!", operands); | |
13619 | else | |
13620 | output_asm_insn ("stm%(db%)\t%m0!, %M1", operands); | |
13621 | } | |
ff9940b0 | 13622 | break; |
2b835d68 | 13623 | |
ff9940b0 | 13624 | case POST_INC: |
3598da80 RR |
13625 | if (emit) |
13626 | { | |
13627 | if (TARGET_LDRD) | |
13628 | output_asm_insn ("str%(d%)\t%1, [%m0], #8", operands); | |
13629 | else | |
13630 | output_asm_insn ("stm%(ia%)\t%m0!, %M1", operands); | |
13631 | } | |
ff9940b0 | 13632 | break; |
2b835d68 | 13633 | |
ff9940b0 | 13634 | case POST_DEC: |
e6d29d15 | 13635 | gcc_assert (TARGET_LDRD); |
3598da80 RR |
13636 | if (emit) |
13637 | output_asm_insn ("str%(d%)\t%1, [%m0], #-8", operands); | |
fdd695fd PB |
13638 | break; |
13639 | ||
13640 | case PRE_MODIFY: | |
13641 | case POST_MODIFY: | |
13642 | otherops[0] = operands[1]; | |
13643 | otherops[1] = XEXP (XEXP (XEXP (operands[0], 0), 1), 0); | |
13644 | otherops[2] = XEXP (XEXP (XEXP (operands[0], 0), 1), 1); | |
13645 | ||
fe2d934b PB |
13646 | /* IWMMXT allows offsets larger than ldrd can handle, |
13647 | fix these up with a pair of ldr. */ | |
ff128632 RE |
13648 | if (!TARGET_THUMB2 |
13649 | && GET_CODE (otherops[2]) == CONST_INT | |
fe2d934b PB |
13650 | && (INTVAL(otherops[2]) <= -256 |
13651 | || INTVAL(otherops[2]) >= 256)) | |
13652 | { | |
fe2d934b PB |
13653 | if (GET_CODE (XEXP (operands[0], 0)) == PRE_MODIFY) |
13654 | { | |
3598da80 RR |
13655 | if (emit) |
13656 | { | |
13657 | output_asm_insn ("str%?\t%0, [%1, %2]!", otherops); | |
13658 | output_asm_insn ("str%?\t%H0, [%1, #4]", otherops); | |
13659 | } | |
13660 | if (count) | |
13661 | *count = 2; | |
fe2d934b PB |
13662 | } |
13663 | else | |
13664 | { | |
3598da80 RR |
13665 | if (emit) |
13666 | { | |
13667 | output_asm_insn ("str%?\t%H0, [%1, #4]", otherops); | |
13668 | output_asm_insn ("str%?\t%0, [%1], %2", otherops); | |
13669 | } | |
13670 | if (count) | |
13671 | *count = 2; | |
fe2d934b PB |
13672 | } |
13673 | } | |
13674 | else if (GET_CODE (XEXP (operands[0], 0)) == PRE_MODIFY) | |
3598da80 RR |
13675 | { |
13676 | if (emit) | |
13677 | output_asm_insn ("str%(d%)\t%0, [%1, %2]!", otherops); | |
13678 | } | |
fdd695fd | 13679 | else |
3598da80 RR |
13680 | { |
13681 | if (emit) | |
13682 | output_asm_insn ("str%(d%)\t%0, [%1], %2", otherops); | |
13683 | } | |
ff9940b0 | 13684 | break; |
2b835d68 RE |
13685 | |
13686 | case PLUS: | |
fdd695fd | 13687 | otherops[2] = XEXP (XEXP (operands[0], 0), 1); |
5dea0c19 | 13688 | if (GET_CODE (otherops[2]) == CONST_INT && !TARGET_LDRD) |
2b835d68 | 13689 | { |
06bea5aa | 13690 | switch ((int) INTVAL (XEXP (XEXP (operands[0], 0), 1))) |
2b835d68 RE |
13691 | { |
13692 | case -8: | |
3598da80 RR |
13693 | if (emit) |
13694 | output_asm_insn ("stm%(db%)\t%m0, %M1", operands); | |
2b835d68 RE |
13695 | return ""; |
13696 | ||
13697 | case -4: | |
5b3e6663 PB |
13698 | if (TARGET_THUMB2) |
13699 | break; | |
3598da80 RR |
13700 | if (emit) |
13701 | output_asm_insn ("stm%(da%)\t%m0, %M1", operands); | |
2b835d68 RE |
13702 | return ""; |
13703 | ||
13704 | case 4: | |
5b3e6663 PB |
13705 | if (TARGET_THUMB2) |
13706 | break; | |
3598da80 RR |
13707 | if (emit) |
13708 | output_asm_insn ("stm%(ib%)\t%m0, %M1", operands); | |
2b835d68 RE |
13709 | return ""; |
13710 | } | |
13711 | } | |
fdd695fd PB |
13712 | if (TARGET_LDRD |
13713 | && (GET_CODE (otherops[2]) == REG | |
ff128632 | 13714 | || TARGET_THUMB2 |
fdd695fd PB |
13715 | || (GET_CODE (otherops[2]) == CONST_INT |
13716 | && INTVAL (otherops[2]) > -256 | |
13717 | && INTVAL (otherops[2]) < 256))) | |
13718 | { | |
13719 | otherops[0] = operands[1]; | |
13720 | otherops[1] = XEXP (XEXP (operands[0], 0), 0); | |
3598da80 RR |
13721 | if (emit) |
13722 | output_asm_insn ("str%(d%)\t%0, [%1, %2]", otherops); | |
fdd695fd PB |
13723 | return ""; |
13724 | } | |
2b835d68 RE |
13725 | /* Fall through */ |
13726 | ||
ff9940b0 | 13727 | default: |
a4a37b30 | 13728 | otherops[0] = adjust_address (operands[0], SImode, 4); |
ff128632 | 13729 | otherops[1] = operands[1]; |
3598da80 RR |
13730 | if (emit) |
13731 | { | |
13732 | output_asm_insn ("str%?\t%1, %0", operands); | |
13733 | output_asm_insn ("str%?\t%H1, %0", otherops); | |
13734 | } | |
13735 | if (count) | |
13736 | *count = 2; | |
13737 | ||
cce8749e CH |
13738 | } |
13739 | } | |
cce8749e | 13740 | |
9997d19d RE |
13741 | return ""; |
13742 | } | |
cce8749e | 13743 | |
88f77cba | 13744 | /* Output a move, load or store for quad-word vectors in ARM registers. Only |
dc34db56 | 13745 | handles MEMs accepted by neon_vector_mem_operand with TYPE=1. */ |
5b3e6663 PB |
13746 | |
13747 | const char * | |
88f77cba | 13748 | output_move_quad (rtx *operands) |
5b3e6663 | 13749 | { |
88f77cba JB |
13750 | if (REG_P (operands[0])) |
13751 | { | |
13752 | /* Load, or reg->reg move. */ | |
5b3e6663 | 13753 | |
88f77cba JB |
13754 | if (MEM_P (operands[1])) |
13755 | { | |
13756 | switch (GET_CODE (XEXP (operands[1], 0))) | |
13757 | { | |
13758 | case REG: | |
13759 | output_asm_insn ("ldm%(ia%)\t%m1, %M0", operands); | |
13760 | break; | |
13761 | ||
13762 | case LABEL_REF: | |
13763 | case CONST: | |
13764 | output_asm_insn ("adr%?\t%0, %1", operands); | |
13765 | output_asm_insn ("ldm%(ia%)\t%0, %M0", operands); | |
13766 | break; | |
13767 | ||
13768 | default: | |
13769 | gcc_unreachable (); | |
13770 | } | |
13771 | } | |
13772 | else | |
13773 | { | |
13774 | rtx ops[2]; | |
13775 | int dest, src, i; | |
5b3e6663 | 13776 | |
88f77cba | 13777 | gcc_assert (REG_P (operands[1])); |
5b3e6663 | 13778 | |
88f77cba JB |
13779 | dest = REGNO (operands[0]); |
13780 | src = REGNO (operands[1]); | |
5b3e6663 | 13781 | |
88f77cba JB |
13782 | /* This seems pretty dumb, but hopefully GCC won't try to do it |
13783 | very often. */ | |
13784 | if (dest < src) | |
13785 | for (i = 0; i < 4; i++) | |
13786 | { | |
13787 | ops[0] = gen_rtx_REG (SImode, dest + i); | |
13788 | ops[1] = gen_rtx_REG (SImode, src + i); | |
13789 | output_asm_insn ("mov%?\t%0, %1", ops); | |
13790 | } | |
13791 | else | |
13792 | for (i = 3; i >= 0; i--) | |
13793 | { | |
13794 | ops[0] = gen_rtx_REG (SImode, dest + i); | |
13795 | ops[1] = gen_rtx_REG (SImode, src + i); | |
13796 | output_asm_insn ("mov%?\t%0, %1", ops); | |
13797 | } | |
13798 | } | |
13799 | } | |
13800 | else | |
13801 | { | |
13802 | gcc_assert (MEM_P (operands[0])); | |
13803 | gcc_assert (REG_P (operands[1])); | |
13804 | gcc_assert (!reg_overlap_mentioned_p (operands[1], operands[0])); | |
13805 | ||
13806 | switch (GET_CODE (XEXP (operands[0], 0))) | |
13807 | { | |
13808 | case REG: | |
13809 | output_asm_insn ("stm%(ia%)\t%m0, %M1", operands); | |
13810 | break; | |
13811 | ||
13812 | default: | |
13813 | gcc_unreachable (); | |
13814 | } | |
13815 | } | |
13816 | ||
13817 | return ""; | |
13818 | } | |
13819 | ||
13820 | /* Output a VFP load or store instruction. */ | |
13821 | ||
13822 | const char * | |
13823 | output_move_vfp (rtx *operands) | |
13824 | { | |
13825 | rtx reg, mem, addr, ops[2]; | |
13826 | int load = REG_P (operands[0]); | |
13827 | int dp = GET_MODE_SIZE (GET_MODE (operands[0])) == 8; | |
13828 | int integer_p = GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT; | |
0a2aaacc | 13829 | const char *templ; |
88f77cba JB |
13830 | char buff[50]; |
13831 | enum machine_mode mode; | |
13832 | ||
13833 | reg = operands[!load]; | |
13834 | mem = operands[load]; | |
13835 | ||
13836 | mode = GET_MODE (reg); | |
13837 | ||
13838 | gcc_assert (REG_P (reg)); | |
13839 | gcc_assert (IS_VFP_REGNUM (REGNO (reg))); | |
13840 | gcc_assert (mode == SFmode | |
13841 | || mode == DFmode | |
13842 | || mode == SImode | |
13843 | || mode == DImode | |
13844 | || (TARGET_NEON && VALID_NEON_DREG_MODE (mode))); | |
13845 | gcc_assert (MEM_P (mem)); | |
13846 | ||
13847 | addr = XEXP (mem, 0); | |
13848 | ||
13849 | switch (GET_CODE (addr)) | |
13850 | { | |
13851 | case PRE_DEC: | |
0a2aaacc | 13852 | templ = "f%smdb%c%%?\t%%0!, {%%%s1}%s"; |
88f77cba JB |
13853 | ops[0] = XEXP (addr, 0); |
13854 | ops[1] = reg; | |
5b3e6663 PB |
13855 | break; |
13856 | ||
13857 | case POST_INC: | |
0a2aaacc | 13858 | templ = "f%smia%c%%?\t%%0!, {%%%s1}%s"; |
5b3e6663 PB |
13859 | ops[0] = XEXP (addr, 0); |
13860 | ops[1] = reg; | |
13861 | break; | |
13862 | ||
13863 | default: | |
0a2aaacc | 13864 | templ = "f%s%c%%?\t%%%s0, %%1%s"; |
5b3e6663 PB |
13865 | ops[0] = reg; |
13866 | ops[1] = mem; | |
13867 | break; | |
13868 | } | |
13869 | ||
0a2aaacc | 13870 | sprintf (buff, templ, |
5b3e6663 PB |
13871 | load ? "ld" : "st", |
13872 | dp ? 'd' : 's', | |
13873 | dp ? "P" : "", | |
13874 | integer_p ? "\t%@ int" : ""); | |
13875 | output_asm_insn (buff, ops); | |
13876 | ||
13877 | return ""; | |
13878 | } | |
13879 | ||
88f77cba | 13880 | /* Output a Neon quad-word load or store, or a load or store for |
874d42b9 | 13881 | larger structure modes. |
88f77cba | 13882 | |
874d42b9 JM |
13883 | WARNING: The ordering of elements is weird in big-endian mode, |
13884 | because we use VSTM, as required by the EABI. GCC RTL defines | |
13885 | element ordering based on in-memory order. This can be differ | |
13886 | from the architectural ordering of elements within a NEON register. | |
13887 | The intrinsics defined in arm_neon.h use the NEON register element | |
13888 | ordering, not the GCC RTL element ordering. | |
88f77cba | 13889 | |
874d42b9 JM |
13890 | For example, the in-memory ordering of a big-endian a quadword |
13891 | vector with 16-bit elements when stored from register pair {d0,d1} | |
13892 | will be (lowest address first, d0[N] is NEON register element N): | |
88f77cba | 13893 | |
874d42b9 | 13894 | [d0[3], d0[2], d0[1], d0[0], d1[7], d1[6], d1[5], d1[4]] |
88f77cba | 13895 | |
874d42b9 JM |
13896 | When necessary, quadword registers (dN, dN+1) are moved to ARM |
13897 | registers from rN in the order: | |
88f77cba JB |
13898 | |
13899 | dN -> (rN+1, rN), dN+1 -> (rN+3, rN+2) | |
13900 | ||
874d42b9 JM |
13901 | So that STM/LDM can be used on vectors in ARM registers, and the |
13902 | same memory layout will result as if VSTM/VLDM were used. */ | |
88f77cba JB |
13903 | |
13904 | const char * | |
13905 | output_move_neon (rtx *operands) | |
13906 | { | |
13907 | rtx reg, mem, addr, ops[2]; | |
13908 | int regno, load = REG_P (operands[0]); | |
0a2aaacc | 13909 | const char *templ; |
88f77cba JB |
13910 | char buff[50]; |
13911 | enum machine_mode mode; | |
13912 | ||
13913 | reg = operands[!load]; | |
13914 | mem = operands[load]; | |
13915 | ||
13916 | mode = GET_MODE (reg); | |
13917 | ||
13918 | gcc_assert (REG_P (reg)); | |
13919 | regno = REGNO (reg); | |
13920 | gcc_assert (VFP_REGNO_OK_FOR_DOUBLE (regno) | |
13921 | || NEON_REGNO_OK_FOR_QUAD (regno)); | |
13922 | gcc_assert (VALID_NEON_DREG_MODE (mode) | |
13923 | || VALID_NEON_QREG_MODE (mode) | |
13924 | || VALID_NEON_STRUCT_MODE (mode)); | |
13925 | gcc_assert (MEM_P (mem)); | |
13926 | ||
13927 | addr = XEXP (mem, 0); | |
13928 | ||
13929 | /* Strip off const from addresses like (const (plus (...))). */ | |
13930 | if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS) | |
13931 | addr = XEXP (addr, 0); | |
13932 | ||
13933 | switch (GET_CODE (addr)) | |
13934 | { | |
13935 | case POST_INC: | |
0a2aaacc | 13936 | templ = "v%smia%%?\t%%0!, %%h1"; |
88f77cba JB |
13937 | ops[0] = XEXP (addr, 0); |
13938 | ops[1] = reg; | |
13939 | break; | |
13940 | ||
dc34db56 PB |
13941 | case PRE_DEC: |
13942 | /* FIXME: We should be using vld1/vst1 here in BE mode? */ | |
13943 | templ = "v%smdb%%?\t%%0!, %%h1"; | |
13944 | ops[0] = XEXP (addr, 0); | |
13945 | ops[1] = reg; | |
13946 | break; | |
13947 | ||
88f77cba JB |
13948 | case POST_MODIFY: |
13949 | /* FIXME: Not currently enabled in neon_vector_mem_operand. */ | |
13950 | gcc_unreachable (); | |
13951 | ||
13952 | case LABEL_REF: | |
13953 | case PLUS: | |
13954 | { | |
13955 | int nregs = HARD_REGNO_NREGS (REGNO (reg), mode) / 2; | |
13956 | int i; | |
13957 | int overlap = -1; | |
13958 | for (i = 0; i < nregs; i++) | |
13959 | { | |
13960 | /* We're only using DImode here because it's a convenient size. */ | |
13961 | ops[0] = gen_rtx_REG (DImode, REGNO (reg) + 2 * i); | |
5728868b | 13962 | ops[1] = adjust_address (mem, DImode, 8 * i); |
88f77cba JB |
13963 | if (reg_overlap_mentioned_p (ops[0], mem)) |
13964 | { | |
13965 | gcc_assert (overlap == -1); | |
13966 | overlap = i; | |
13967 | } | |
13968 | else | |
13969 | { | |
13970 | sprintf (buff, "v%sr%%?\t%%P0, %%1", load ? "ld" : "st"); | |
13971 | output_asm_insn (buff, ops); | |
13972 | } | |
13973 | } | |
13974 | if (overlap != -1) | |
13975 | { | |
13976 | ops[0] = gen_rtx_REG (DImode, REGNO (reg) + 2 * overlap); | |
13977 | ops[1] = adjust_address (mem, SImode, 8 * overlap); | |
13978 | sprintf (buff, "v%sr%%?\t%%P0, %%1", load ? "ld" : "st"); | |
13979 | output_asm_insn (buff, ops); | |
13980 | } | |
13981 | ||
13982 | return ""; | |
13983 | } | |
13984 | ||
13985 | default: | |
0a2aaacc | 13986 | templ = "v%smia%%?\t%%m0, %%h1"; |
88f77cba JB |
13987 | ops[0] = mem; |
13988 | ops[1] = reg; | |
13989 | } | |
13990 | ||
0a2aaacc | 13991 | sprintf (buff, templ, load ? "ld" : "st"); |
88f77cba JB |
13992 | output_asm_insn (buff, ops); |
13993 | ||
13994 | return ""; | |
13995 | } | |
13996 | ||
7c4f0041 JZ |
13997 | /* Compute and return the length of neon_mov<mode>, where <mode> is |
13998 | one of VSTRUCT modes: EI, OI, CI or XI. */ | |
13999 | int | |
14000 | arm_attr_length_move_neon (rtx insn) | |
14001 | { | |
14002 | rtx reg, mem, addr; | |
e4dde839 | 14003 | int load; |
7c4f0041 JZ |
14004 | enum machine_mode mode; |
14005 | ||
14006 | extract_insn_cached (insn); | |
14007 | ||
14008 | if (REG_P (recog_data.operand[0]) && REG_P (recog_data.operand[1])) | |
14009 | { | |
14010 | mode = GET_MODE (recog_data.operand[0]); | |
14011 | switch (mode) | |
14012 | { | |
14013 | case EImode: | |
14014 | case OImode: | |
14015 | return 8; | |
14016 | case CImode: | |
14017 | return 12; | |
14018 | case XImode: | |
14019 | return 16; | |
14020 | default: | |
14021 | gcc_unreachable (); | |
14022 | } | |
14023 | } | |
14024 | ||
14025 | load = REG_P (recog_data.operand[0]); | |
14026 | reg = recog_data.operand[!load]; | |
14027 | mem = recog_data.operand[load]; | |
14028 | ||
14029 | gcc_assert (MEM_P (mem)); | |
14030 | ||
14031 | mode = GET_MODE (reg); | |
7c4f0041 JZ |
14032 | addr = XEXP (mem, 0); |
14033 | ||
14034 | /* Strip off const from addresses like (const (plus (...))). */ | |
14035 | if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS) | |
14036 | addr = XEXP (addr, 0); | |
14037 | ||
14038 | if (GET_CODE (addr) == LABEL_REF || GET_CODE (addr) == PLUS) | |
14039 | { | |
14040 | int insns = HARD_REGNO_NREGS (REGNO (reg), mode) / 2; | |
14041 | return insns * 4; | |
14042 | } | |
14043 | else | |
14044 | return 4; | |
14045 | } | |
14046 | ||
47d8f18d JZ |
14047 | /* Return nonzero if the offset in the address is an immediate. Otherwise, |
14048 | return zero. */ | |
14049 | ||
14050 | int | |
14051 | arm_address_offset_is_imm (rtx insn) | |
14052 | { | |
14053 | rtx mem, addr; | |
14054 | ||
14055 | extract_insn_cached (insn); | |
14056 | ||
14057 | if (REG_P (recog_data.operand[0])) | |
14058 | return 0; | |
14059 | ||
14060 | mem = recog_data.operand[0]; | |
14061 | ||
14062 | gcc_assert (MEM_P (mem)); | |
14063 | ||
14064 | addr = XEXP (mem, 0); | |
14065 | ||
14066 | if (GET_CODE (addr) == REG | |
14067 | || (GET_CODE (addr) == PLUS | |
14068 | && GET_CODE (XEXP (addr, 0)) == REG | |
14069 | && GET_CODE (XEXP (addr, 1)) == CONST_INT)) | |
14070 | return 1; | |
14071 | else | |
14072 | return 0; | |
14073 | } | |
14074 | ||
1d6e90ac NC |
14075 | /* Output an ADD r, s, #n where n may be too big for one instruction. |
14076 | If adding zero to one register, output nothing. */ | |
cd2b33d0 | 14077 | const char * |
e32bac5b | 14078 | output_add_immediate (rtx *operands) |
cce8749e | 14079 | { |
f3bb6135 | 14080 | HOST_WIDE_INT n = INTVAL (operands[2]); |
cce8749e CH |
14081 | |
14082 | if (n != 0 || REGNO (operands[0]) != REGNO (operands[1])) | |
14083 | { | |
14084 | if (n < 0) | |
14085 | output_multi_immediate (operands, | |
9997d19d RE |
14086 | "sub%?\t%0, %1, %2", "sub%?\t%0, %0, %2", 2, |
14087 | -n); | |
cce8749e CH |
14088 | else |
14089 | output_multi_immediate (operands, | |
9997d19d RE |
14090 | "add%?\t%0, %1, %2", "add%?\t%0, %0, %2", 2, |
14091 | n); | |
cce8749e | 14092 | } |
f3bb6135 RE |
14093 | |
14094 | return ""; | |
14095 | } | |
cce8749e | 14096 | |
cce8749e CH |
14097 | /* Output a multiple immediate operation. |
14098 | OPERANDS is the vector of operands referred to in the output patterns. | |
14099 | INSTR1 is the output pattern to use for the first constant. | |
14100 | INSTR2 is the output pattern to use for subsequent constants. | |
14101 | IMMED_OP is the index of the constant slot in OPERANDS. | |
14102 | N is the constant value. */ | |
cd2b33d0 | 14103 | static const char * |
e32bac5b RE |
14104 | output_multi_immediate (rtx *operands, const char *instr1, const char *instr2, |
14105 | int immed_op, HOST_WIDE_INT n) | |
cce8749e | 14106 | { |
f3bb6135 | 14107 | #if HOST_BITS_PER_WIDE_INT > 32 |
30cf4896 | 14108 | n &= 0xffffffff; |
f3bb6135 RE |
14109 | #endif |
14110 | ||
cce8749e CH |
14111 | if (n == 0) |
14112 | { | |
1d6e90ac | 14113 | /* Quick and easy output. */ |
cce8749e | 14114 | operands[immed_op] = const0_rtx; |
1d6e90ac | 14115 | output_asm_insn (instr1, operands); |
cce8749e CH |
14116 | } |
14117 | else | |
14118 | { | |
14119 | int i; | |
cd2b33d0 | 14120 | const char * instr = instr1; |
cce8749e | 14121 | |
6354dc9b | 14122 | /* Note that n is never zero here (which would give no output). */ |
cce8749e CH |
14123 | for (i = 0; i < 32; i += 2) |
14124 | { | |
14125 | if (n & (3 << i)) | |
14126 | { | |
f3bb6135 RE |
14127 | operands[immed_op] = GEN_INT (n & (255 << i)); |
14128 | output_asm_insn (instr, operands); | |
cce8749e CH |
14129 | instr = instr2; |
14130 | i += 6; | |
14131 | } | |
14132 | } | |
14133 | } | |
f676971a | 14134 | |
f3bb6135 | 14135 | return ""; |
9997d19d | 14136 | } |
cce8749e | 14137 | |
5b3e6663 PB |
14138 | /* Return the name of a shifter operation. */ |
14139 | static const char * | |
14140 | arm_shift_nmem(enum rtx_code code) | |
14141 | { | |
14142 | switch (code) | |
14143 | { | |
14144 | case ASHIFT: | |
14145 | return ARM_LSL_NAME; | |
14146 | ||
14147 | case ASHIFTRT: | |
14148 | return "asr"; | |
14149 | ||
14150 | case LSHIFTRT: | |
14151 | return "lsr"; | |
14152 | ||
14153 | case ROTATERT: | |
14154 | return "ror"; | |
14155 | ||
14156 | default: | |
14157 | abort(); | |
14158 | } | |
14159 | } | |
14160 | ||
cce8749e CH |
14161 | /* Return the appropriate ARM instruction for the operation code. |
14162 | The returned result should not be overwritten. OP is the rtx of the | |
14163 | operation. SHIFT_FIRST_ARG is TRUE if the first argument of the operator | |
14164 | was shifted. */ | |
cd2b33d0 | 14165 | const char * |
e32bac5b | 14166 | arithmetic_instr (rtx op, int shift_first_arg) |
cce8749e | 14167 | { |
9997d19d | 14168 | switch (GET_CODE (op)) |
cce8749e CH |
14169 | { |
14170 | case PLUS: | |
f3bb6135 RE |
14171 | return "add"; |
14172 | ||
cce8749e | 14173 | case MINUS: |
f3bb6135 RE |
14174 | return shift_first_arg ? "rsb" : "sub"; |
14175 | ||
cce8749e | 14176 | case IOR: |
f3bb6135 RE |
14177 | return "orr"; |
14178 | ||
cce8749e | 14179 | case XOR: |
f3bb6135 RE |
14180 | return "eor"; |
14181 | ||
cce8749e | 14182 | case AND: |
f3bb6135 RE |
14183 | return "and"; |
14184 | ||
5b3e6663 PB |
14185 | case ASHIFT: |
14186 | case ASHIFTRT: | |
14187 | case LSHIFTRT: | |
14188 | case ROTATERT: | |
14189 | return arm_shift_nmem(GET_CODE(op)); | |
14190 | ||
cce8749e | 14191 | default: |
e6d29d15 | 14192 | gcc_unreachable (); |
cce8749e | 14193 | } |
f3bb6135 | 14194 | } |
cce8749e | 14195 | |
cce8749e CH |
14196 | /* Ensure valid constant shifts and return the appropriate shift mnemonic |
14197 | for the operation code. The returned result should not be overwritten. | |
14198 | OP is the rtx code of the shift. | |
9997d19d | 14199 | On exit, *AMOUNTP will be -1 if the shift is by a register, or a constant |
6354dc9b | 14200 | shift. */ |
cd2b33d0 | 14201 | static const char * |
e32bac5b | 14202 | shift_op (rtx op, HOST_WIDE_INT *amountp) |
cce8749e | 14203 | { |
cd2b33d0 | 14204 | const char * mnem; |
e2c671ba | 14205 | enum rtx_code code = GET_CODE (op); |
cce8749e | 14206 | |
e6d29d15 NS |
14207 | switch (GET_CODE (XEXP (op, 1))) |
14208 | { | |
14209 | case REG: | |
14210 | case SUBREG: | |
14211 | *amountp = -1; | |
14212 | break; | |
14213 | ||
14214 | case CONST_INT: | |
14215 | *amountp = INTVAL (XEXP (op, 1)); | |
14216 | break; | |
14217 | ||
14218 | default: | |
14219 | gcc_unreachable (); | |
14220 | } | |
9997d19d | 14221 | |
e2c671ba | 14222 | switch (code) |
cce8749e | 14223 | { |
a657c98a | 14224 | case ROTATE: |
e6d29d15 | 14225 | gcc_assert (*amountp != -1); |
a657c98a | 14226 | *amountp = 32 - *amountp; |
5b3e6663 | 14227 | code = ROTATERT; |
a657c98a RE |
14228 | |
14229 | /* Fall through. */ | |
14230 | ||
5b3e6663 PB |
14231 | case ASHIFT: |
14232 | case ASHIFTRT: | |
14233 | case LSHIFTRT: | |
9997d19d | 14234 | case ROTATERT: |
5b3e6663 | 14235 | mnem = arm_shift_nmem(code); |
9997d19d RE |
14236 | break; |
14237 | ||
ff9940b0 | 14238 | case MULT: |
e2c671ba RE |
14239 | /* We never have to worry about the amount being other than a |
14240 | power of 2, since this case can never be reloaded from a reg. */ | |
e6d29d15 NS |
14241 | gcc_assert (*amountp != -1); |
14242 | *amountp = int_log2 (*amountp); | |
5b3e6663 | 14243 | return ARM_LSL_NAME; |
f3bb6135 | 14244 | |
cce8749e | 14245 | default: |
e6d29d15 | 14246 | gcc_unreachable (); |
cce8749e CH |
14247 | } |
14248 | ||
e2c671ba RE |
14249 | if (*amountp != -1) |
14250 | { | |
14251 | /* This is not 100% correct, but follows from the desire to merge | |
14252 | multiplication by a power of 2 with the recognizer for a | |
5b3e6663 | 14253 | shift. >=32 is not a valid shift for "lsl", so we must try and |
e2c671ba | 14254 | output a shift that produces the correct arithmetical result. |
ddd5a7c1 | 14255 | Using lsr #32 is identical except for the fact that the carry bit |
f676971a | 14256 | is not set correctly if we set the flags; but we never use the |
e2c671ba RE |
14257 | carry bit from such an operation, so we can ignore that. */ |
14258 | if (code == ROTATERT) | |
1d6e90ac NC |
14259 | /* Rotate is just modulo 32. */ |
14260 | *amountp &= 31; | |
e2c671ba RE |
14261 | else if (*amountp != (*amountp & 31)) |
14262 | { | |
14263 | if (code == ASHIFT) | |
14264 | mnem = "lsr"; | |
14265 | *amountp = 32; | |
14266 | } | |
14267 | ||
14268 | /* Shifts of 0 are no-ops. */ | |
14269 | if (*amountp == 0) | |
14270 | return NULL; | |
f676971a | 14271 | } |
e2c671ba | 14272 | |
9997d19d RE |
14273 | return mnem; |
14274 | } | |
cce8749e | 14275 | |
6354dc9b | 14276 | /* Obtain the shift from the POWER of two. */ |
1d6e90ac | 14277 | |
18af7313 | 14278 | static HOST_WIDE_INT |
e32bac5b | 14279 | int_log2 (HOST_WIDE_INT power) |
cce8749e | 14280 | { |
f3bb6135 | 14281 | HOST_WIDE_INT shift = 0; |
cce8749e | 14282 | |
30cf4896 | 14283 | while ((((HOST_WIDE_INT) 1 << shift) & power) == 0) |
cce8749e | 14284 | { |
e6d29d15 | 14285 | gcc_assert (shift <= 31); |
e32bac5b | 14286 | shift++; |
cce8749e | 14287 | } |
f3bb6135 RE |
14288 | |
14289 | return shift; | |
14290 | } | |
cce8749e | 14291 | |
c5ff069d ZW |
14292 | /* Output a .ascii pseudo-op, keeping track of lengths. This is |
14293 | because /bin/as is horribly restrictive. The judgement about | |
14294 | whether or not each character is 'printable' (and can be output as | |
14295 | is) or not (and must be printed with an octal escape) must be made | |
14296 | with reference to the *host* character set -- the situation is | |
14297 | similar to that discussed in the comments above pp_c_char in | |
14298 | c-pretty-print.c. */ | |
14299 | ||
6cfc7210 | 14300 | #define MAX_ASCII_LEN 51 |
cce8749e CH |
14301 | |
14302 | void | |
e32bac5b | 14303 | output_ascii_pseudo_op (FILE *stream, const unsigned char *p, int len) |
cce8749e CH |
14304 | { |
14305 | int i; | |
6cfc7210 | 14306 | int len_so_far = 0; |
cce8749e | 14307 | |
6cfc7210 | 14308 | fputs ("\t.ascii\t\"", stream); |
f676971a | 14309 | |
cce8749e CH |
14310 | for (i = 0; i < len; i++) |
14311 | { | |
1d6e90ac | 14312 | int c = p[i]; |
cce8749e | 14313 | |
6cfc7210 | 14314 | if (len_so_far >= MAX_ASCII_LEN) |
cce8749e | 14315 | { |
6cfc7210 | 14316 | fputs ("\"\n\t.ascii\t\"", stream); |
cce8749e | 14317 | len_so_far = 0; |
cce8749e CH |
14318 | } |
14319 | ||
c5ff069d | 14320 | if (ISPRINT (c)) |
cce8749e | 14321 | { |
c5ff069d | 14322 | if (c == '\\' || c == '\"') |
6cfc7210 | 14323 | { |
c5ff069d | 14324 | putc ('\\', stream); |
5895f793 | 14325 | len_so_far++; |
6cfc7210 | 14326 | } |
c5ff069d ZW |
14327 | putc (c, stream); |
14328 | len_so_far++; | |
14329 | } | |
14330 | else | |
14331 | { | |
14332 | fprintf (stream, "\\%03o", c); | |
14333 | len_so_far += 4; | |
cce8749e | 14334 | } |
cce8749e | 14335 | } |
f3bb6135 | 14336 | |
cce8749e | 14337 | fputs ("\"\n", stream); |
f3bb6135 | 14338 | } |
cce8749e | 14339 | \f |
c9ca9b88 | 14340 | /* Compute the register save mask for registers 0 through 12 |
5848830f | 14341 | inclusive. This code is used by arm_compute_save_reg_mask. */ |
b279b20a | 14342 | |
6d3d9133 | 14343 | static unsigned long |
e32bac5b | 14344 | arm_compute_save_reg0_reg12_mask (void) |
6d3d9133 | 14345 | { |
121308d4 | 14346 | unsigned long func_type = arm_current_func_type (); |
b279b20a | 14347 | unsigned long save_reg_mask = 0; |
6d3d9133 | 14348 | unsigned int reg; |
6d3d9133 | 14349 | |
7b8b8ade | 14350 | if (IS_INTERRUPT (func_type)) |
6d3d9133 | 14351 | { |
7b8b8ade | 14352 | unsigned int max_reg; |
7b8b8ade NC |
14353 | /* Interrupt functions must not corrupt any registers, |
14354 | even call clobbered ones. If this is a leaf function | |
14355 | we can just examine the registers used by the RTL, but | |
14356 | otherwise we have to assume that whatever function is | |
14357 | called might clobber anything, and so we have to save | |
14358 | all the call-clobbered registers as well. */ | |
14359 | if (ARM_FUNC_TYPE (func_type) == ARM_FT_FIQ) | |
14360 | /* FIQ handlers have registers r8 - r12 banked, so | |
14361 | we only need to check r0 - r7, Normal ISRs only | |
121308d4 | 14362 | bank r14 and r15, so we must check up to r12. |
7b8b8ade NC |
14363 | r13 is the stack pointer which is always preserved, |
14364 | so we do not need to consider it here. */ | |
14365 | max_reg = 7; | |
14366 | else | |
14367 | max_reg = 12; | |
f676971a | 14368 | |
7b8b8ade | 14369 | for (reg = 0; reg <= max_reg; reg++) |
6fb5fa3c DB |
14370 | if (df_regs_ever_live_p (reg) |
14371 | || (! current_function_is_leaf && call_used_regs[reg])) | |
6d3d9133 | 14372 | save_reg_mask |= (1 << reg); |
cfa01aab | 14373 | |
286d28c3 | 14374 | /* Also save the pic base register if necessary. */ |
cfa01aab PB |
14375 | if (flag_pic |
14376 | && !TARGET_SINGLE_PIC_BASE | |
020a4035 | 14377 | && arm_pic_register != INVALID_REGNUM |
e3b5732b | 14378 | && crtl->uses_pic_offset_table) |
cfa01aab | 14379 | save_reg_mask |= 1 << PIC_OFFSET_TABLE_REGNUM; |
6d3d9133 | 14380 | } |
1586899e PB |
14381 | else if (IS_VOLATILE(func_type)) |
14382 | { | |
14383 | /* For noreturn functions we historically omitted register saves | |
14384 | altogether. However this really messes up debugging. As a | |
3ed04dbd | 14385 | compromise save just the frame pointers. Combined with the link |
1586899e PB |
14386 | register saved elsewhere this should be sufficient to get |
14387 | a backtrace. */ | |
14388 | if (frame_pointer_needed) | |
14389 | save_reg_mask |= 1 << HARD_FRAME_POINTER_REGNUM; | |
14390 | if (df_regs_ever_live_p (ARM_HARD_FRAME_POINTER_REGNUM)) | |
14391 | save_reg_mask |= 1 << ARM_HARD_FRAME_POINTER_REGNUM; | |
14392 | if (df_regs_ever_live_p (THUMB_HARD_FRAME_POINTER_REGNUM)) | |
14393 | save_reg_mask |= 1 << THUMB_HARD_FRAME_POINTER_REGNUM; | |
14394 | } | |
6d3d9133 NC |
14395 | else |
14396 | { | |
14397 | /* In the normal case we only need to save those registers | |
14398 | which are call saved and which are used by this function. */ | |
ec6237e4 | 14399 | for (reg = 0; reg <= 11; reg++) |
6fb5fa3c | 14400 | if (df_regs_ever_live_p (reg) && ! call_used_regs[reg]) |
6d3d9133 NC |
14401 | save_reg_mask |= (1 << reg); |
14402 | ||
14403 | /* Handle the frame pointer as a special case. */ | |
ec6237e4 | 14404 | if (frame_pointer_needed) |
6d3d9133 NC |
14405 | save_reg_mask |= 1 << HARD_FRAME_POINTER_REGNUM; |
14406 | ||
14407 | /* If we aren't loading the PIC register, | |
14408 | don't stack it even though it may be live. */ | |
14409 | if (flag_pic | |
e0b92319 | 14410 | && !TARGET_SINGLE_PIC_BASE |
020a4035 | 14411 | && arm_pic_register != INVALID_REGNUM |
6fb5fa3c | 14412 | && (df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM) |
e3b5732b | 14413 | || crtl->uses_pic_offset_table)) |
6d3d9133 | 14414 | save_reg_mask |= 1 << PIC_OFFSET_TABLE_REGNUM; |
5b3e6663 PB |
14415 | |
14416 | /* The prologue will copy SP into R0, so save it. */ | |
14417 | if (IS_STACKALIGN (func_type)) | |
14418 | save_reg_mask |= 1; | |
6d3d9133 NC |
14419 | } |
14420 | ||
c9ca9b88 | 14421 | /* Save registers so the exception handler can modify them. */ |
e3b5732b | 14422 | if (crtl->calls_eh_return) |
c9ca9b88 PB |
14423 | { |
14424 | unsigned int i; | |
f676971a | 14425 | |
c9ca9b88 PB |
14426 | for (i = 0; ; i++) |
14427 | { | |
14428 | reg = EH_RETURN_DATA_REGNO (i); | |
14429 | if (reg == INVALID_REGNUM) | |
14430 | break; | |
14431 | save_reg_mask |= 1 << reg; | |
14432 | } | |
14433 | } | |
14434 | ||
121308d4 NC |
14435 | return save_reg_mask; |
14436 | } | |
14437 | ||
5b3e6663 | 14438 | |
35596784 AJ |
14439 | /* Compute the number of bytes used to store the static chain register on the |
14440 | stack, above the stack frame. We need to know this accurately to get the | |
14441 | alignment of the rest of the stack frame correct. */ | |
14442 | ||
14443 | static int arm_compute_static_chain_stack_bytes (void) | |
14444 | { | |
14445 | unsigned long func_type = arm_current_func_type (); | |
14446 | int static_chain_stack_bytes = 0; | |
14447 | ||
14448 | if (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM && | |
14449 | IS_NESTED (func_type) && | |
14450 | df_regs_ever_live_p (3) && crtl->args.pretend_args_size == 0) | |
14451 | static_chain_stack_bytes = 4; | |
14452 | ||
14453 | return static_chain_stack_bytes; | |
14454 | } | |
14455 | ||
14456 | ||
121308d4 | 14457 | /* Compute a bit mask of which registers need to be |
954954d1 PB |
14458 | saved on the stack for the current function. |
14459 | This is used by arm_get_frame_offsets, which may add extra registers. */ | |
121308d4 NC |
14460 | |
14461 | static unsigned long | |
e32bac5b | 14462 | arm_compute_save_reg_mask (void) |
121308d4 NC |
14463 | { |
14464 | unsigned int save_reg_mask = 0; | |
14465 | unsigned long func_type = arm_current_func_type (); | |
5b3e6663 | 14466 | unsigned int reg; |
121308d4 NC |
14467 | |
14468 | if (IS_NAKED (func_type)) | |
14469 | /* This should never really happen. */ | |
14470 | return 0; | |
14471 | ||
14472 | /* If we are creating a stack frame, then we must save the frame pointer, | |
14473 | IP (which will hold the old stack pointer), LR and the PC. */ | |
ec6237e4 | 14474 | if (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM) |
121308d4 NC |
14475 | save_reg_mask |= |
14476 | (1 << ARM_HARD_FRAME_POINTER_REGNUM) | |
14477 | | (1 << IP_REGNUM) | |
14478 | | (1 << LR_REGNUM) | |
14479 | | (1 << PC_REGNUM); | |
14480 | ||
121308d4 NC |
14481 | save_reg_mask |= arm_compute_save_reg0_reg12_mask (); |
14482 | ||
6d3d9133 NC |
14483 | /* Decide if we need to save the link register. |
14484 | Interrupt routines have their own banked link register, | |
14485 | so they never need to save it. | |
1768c26f | 14486 | Otherwise if we do not use the link register we do not need to save |
6d3d9133 NC |
14487 | it. If we are pushing other registers onto the stack however, we |
14488 | can save an instruction in the epilogue by pushing the link register | |
14489 | now and then popping it back into the PC. This incurs extra memory | |
72ac76be | 14490 | accesses though, so we only do it when optimizing for size, and only |
6d3d9133 | 14491 | if we know that we will not need a fancy return sequence. */ |
6fb5fa3c DB |
14492 | if (df_regs_ever_live_p (LR_REGNUM) |
14493 | || (save_reg_mask | |
14494 | && optimize_size | |
14495 | && ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL | |
e3b5732b | 14496 | && !crtl->calls_eh_return)) |
6d3d9133 NC |
14497 | save_reg_mask |= 1 << LR_REGNUM; |
14498 | ||
6f7ebcbb NC |
14499 | if (cfun->machine->lr_save_eliminated) |
14500 | save_reg_mask &= ~ (1 << LR_REGNUM); | |
14501 | ||
5a9335ef NC |
14502 | if (TARGET_REALLY_IWMMXT |
14503 | && ((bit_count (save_reg_mask) | |
35596784 AJ |
14504 | + ARM_NUM_INTS (crtl->args.pretend_args_size + |
14505 | arm_compute_static_chain_stack_bytes()) | |
14506 | ) % 2) != 0) | |
5a9335ef | 14507 | { |
5a9335ef NC |
14508 | /* The total number of registers that are going to be pushed |
14509 | onto the stack is odd. We need to ensure that the stack | |
14510 | is 64-bit aligned before we start to save iWMMXt registers, | |
14511 | and also before we start to create locals. (A local variable | |
14512 | might be a double or long long which we will load/store using | |
14513 | an iWMMXt instruction). Therefore we need to push another | |
14514 | ARM register, so that the stack will be 64-bit aligned. We | |
14515 | try to avoid using the arg registers (r0 -r3) as they might be | |
14516 | used to pass values in a tail call. */ | |
14517 | for (reg = 4; reg <= 12; reg++) | |
14518 | if ((save_reg_mask & (1 << reg)) == 0) | |
14519 | break; | |
14520 | ||
14521 | if (reg <= 12) | |
14522 | save_reg_mask |= (1 << reg); | |
14523 | else | |
14524 | { | |
14525 | cfun->machine->sibcall_blocked = 1; | |
14526 | save_reg_mask |= (1 << 3); | |
14527 | } | |
14528 | } | |
14529 | ||
5b3e6663 PB |
14530 | /* We may need to push an additional register for use initializing the |
14531 | PIC base register. */ | |
14532 | if (TARGET_THUMB2 && IS_NESTED (func_type) && flag_pic | |
14533 | && (save_reg_mask & THUMB2_WORK_REGS) == 0) | |
14534 | { | |
14535 | reg = thumb_find_work_register (1 << 4); | |
14536 | if (!call_used_regs[reg]) | |
14537 | save_reg_mask |= (1 << reg); | |
14538 | } | |
14539 | ||
6d3d9133 NC |
14540 | return save_reg_mask; |
14541 | } | |
14542 | ||
9728c9d1 | 14543 | |
57934c39 PB |
14544 | /* Compute a bit mask of which registers need to be |
14545 | saved on the stack for the current function. */ | |
14546 | static unsigned long | |
5b3e6663 | 14547 | thumb1_compute_save_reg_mask (void) |
57934c39 PB |
14548 | { |
14549 | unsigned long mask; | |
b279b20a | 14550 | unsigned reg; |
57934c39 PB |
14551 | |
14552 | mask = 0; | |
14553 | for (reg = 0; reg < 12; reg ++) | |
6fb5fa3c | 14554 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
b279b20a | 14555 | mask |= 1 << reg; |
57934c39 | 14556 | |
39c39be0 RE |
14557 | if (flag_pic |
14558 | && !TARGET_SINGLE_PIC_BASE | |
020a4035 | 14559 | && arm_pic_register != INVALID_REGNUM |
e3b5732b | 14560 | && crtl->uses_pic_offset_table) |
39c39be0 | 14561 | mask |= 1 << PIC_OFFSET_TABLE_REGNUM; |
b279b20a | 14562 | |
a2503645 RS |
14563 | /* See if we might need r11 for calls to _interwork_r11_call_via_rN(). */ |
14564 | if (!frame_pointer_needed && CALLER_INTERWORKING_SLOT_SIZE > 0) | |
14565 | mask |= 1 << ARM_HARD_FRAME_POINTER_REGNUM; | |
57934c39 | 14566 | |
b279b20a | 14567 | /* LR will also be pushed if any lo regs are pushed. */ |
57934c39 PB |
14568 | if (mask & 0xff || thumb_force_lr_save ()) |
14569 | mask |= (1 << LR_REGNUM); | |
14570 | ||
b279b20a NC |
14571 | /* Make sure we have a low work register if we need one. |
14572 | We will need one if we are going to push a high register, | |
14573 | but we are not currently intending to push a low register. */ | |
14574 | if ((mask & 0xff) == 0 | |
57934c39 | 14575 | && ((mask & 0x0f00) || TARGET_BACKTRACE)) |
b279b20a NC |
14576 | { |
14577 | /* Use thumb_find_work_register to choose which register | |
14578 | we will use. If the register is live then we will | |
14579 | have to push it. Use LAST_LO_REGNUM as our fallback | |
14580 | choice for the register to select. */ | |
14581 | reg = thumb_find_work_register (1 << LAST_LO_REGNUM); | |
19e723f4 PB |
14582 | /* Make sure the register returned by thumb_find_work_register is |
14583 | not part of the return value. */ | |
954954d1 | 14584 | if (reg * UNITS_PER_WORD <= (unsigned) arm_size_return_regs ()) |
19e723f4 | 14585 | reg = LAST_LO_REGNUM; |
b279b20a NC |
14586 | |
14587 | if (! call_used_regs[reg]) | |
14588 | mask |= 1 << reg; | |
14589 | } | |
57934c39 | 14590 | |
35596784 AJ |
14591 | /* The 504 below is 8 bytes less than 512 because there are two possible |
14592 | alignment words. We can't tell here if they will be present or not so we | |
14593 | have to play it safe and assume that they are. */ | |
14594 | if ((CALLER_INTERWORKING_SLOT_SIZE + | |
14595 | ROUND_UP_WORD (get_frame_size ()) + | |
14596 | crtl->outgoing_args_size) >= 504) | |
14597 | { | |
14598 | /* This is the same as the code in thumb1_expand_prologue() which | |
14599 | determines which register to use for stack decrement. */ | |
14600 | for (reg = LAST_ARG_REGNUM + 1; reg <= LAST_LO_REGNUM; reg++) | |
14601 | if (mask & (1 << reg)) | |
14602 | break; | |
14603 | ||
14604 | if (reg > LAST_LO_REGNUM) | |
14605 | { | |
14606 | /* Make sure we have a register available for stack decrement. */ | |
14607 | mask |= 1 << LAST_LO_REGNUM; | |
14608 | } | |
14609 | } | |
14610 | ||
57934c39 PB |
14611 | return mask; |
14612 | } | |
14613 | ||
14614 | ||
9728c9d1 PB |
14615 | /* Return the number of bytes required to save VFP registers. */ |
14616 | static int | |
14617 | arm_get_vfp_saved_size (void) | |
14618 | { | |
14619 | unsigned int regno; | |
14620 | int count; | |
14621 | int saved; | |
14622 | ||
14623 | saved = 0; | |
14624 | /* Space for saved VFP registers. */ | |
14625 | if (TARGET_HARD_FLOAT && TARGET_VFP) | |
14626 | { | |
14627 | count = 0; | |
14628 | for (regno = FIRST_VFP_REGNUM; | |
14629 | regno < LAST_VFP_REGNUM; | |
14630 | regno += 2) | |
14631 | { | |
6fb5fa3c DB |
14632 | if ((!df_regs_ever_live_p (regno) || call_used_regs[regno]) |
14633 | && (!df_regs_ever_live_p (regno + 1) || call_used_regs[regno + 1])) | |
9728c9d1 PB |
14634 | { |
14635 | if (count > 0) | |
14636 | { | |
14637 | /* Workaround ARM10 VFPr1 bug. */ | |
14638 | if (count == 2 && !arm_arch6) | |
14639 | count++; | |
8edfc4cc | 14640 | saved += count * 8; |
9728c9d1 PB |
14641 | } |
14642 | count = 0; | |
14643 | } | |
14644 | else | |
14645 | count++; | |
14646 | } | |
14647 | if (count > 0) | |
14648 | { | |
14649 | if (count == 2 && !arm_arch6) | |
14650 | count++; | |
8edfc4cc | 14651 | saved += count * 8; |
9728c9d1 PB |
14652 | } |
14653 | } | |
14654 | return saved; | |
14655 | } | |
14656 | ||
14657 | ||
699a4925 | 14658 | /* Generate a function exit sequence. If REALLY_RETURN is false, then do |
6d3d9133 | 14659 | everything bar the final return instruction. */ |
cd2b33d0 | 14660 | const char * |
e32bac5b | 14661 | output_return_instruction (rtx operand, int really_return, int reverse) |
ff9940b0 | 14662 | { |
6d3d9133 | 14663 | char conditional[10]; |
ff9940b0 | 14664 | char instr[100]; |
b279b20a | 14665 | unsigned reg; |
6d3d9133 NC |
14666 | unsigned long live_regs_mask; |
14667 | unsigned long func_type; | |
5848830f | 14668 | arm_stack_offsets *offsets; |
e26053d1 | 14669 | |
6d3d9133 | 14670 | func_type = arm_current_func_type (); |
e2c671ba | 14671 | |
6d3d9133 | 14672 | if (IS_NAKED (func_type)) |
d5b7b3ae | 14673 | return ""; |
6d3d9133 NC |
14674 | |
14675 | if (IS_VOLATILE (func_type) && TARGET_ABORT_NORETURN) | |
e2c671ba | 14676 | { |
699a4925 RE |
14677 | /* If this function was declared non-returning, and we have |
14678 | found a tail call, then we have to trust that the called | |
14679 | function won't return. */ | |
3a5a4282 PB |
14680 | if (really_return) |
14681 | { | |
14682 | rtx ops[2]; | |
f676971a | 14683 | |
3a5a4282 PB |
14684 | /* Otherwise, trap an attempted return by aborting. */ |
14685 | ops[0] = operand; | |
f676971a | 14686 | ops[1] = gen_rtx_SYMBOL_REF (Pmode, NEED_PLT_RELOC ? "abort(PLT)" |
3a5a4282 PB |
14687 | : "abort"); |
14688 | assemble_external_libcall (ops[1]); | |
14689 | output_asm_insn (reverse ? "bl%D0\t%a1" : "bl%d0\t%a1", ops); | |
14690 | } | |
f676971a | 14691 | |
e2c671ba RE |
14692 | return ""; |
14693 | } | |
6d3d9133 | 14694 | |
e3b5732b | 14695 | gcc_assert (!cfun->calls_alloca || really_return); |
ff9940b0 | 14696 | |
c414f8a9 | 14697 | sprintf (conditional, "%%?%%%c0", reverse ? 'D' : 'd'); |
d5b7b3ae | 14698 | |
934c2060 | 14699 | cfun->machine->return_used_this_function = 1; |
ff9940b0 | 14700 | |
954954d1 PB |
14701 | offsets = arm_get_frame_offsets (); |
14702 | live_regs_mask = offsets->saved_regs_mask; | |
ff9940b0 | 14703 | |
1768c26f | 14704 | if (live_regs_mask) |
6d3d9133 | 14705 | { |
1768c26f PB |
14706 | const char * return_reg; |
14707 | ||
f676971a | 14708 | /* If we do not have any special requirements for function exit |
a15908a4 | 14709 | (e.g. interworking) then we can load the return address |
1768c26f PB |
14710 | directly into the PC. Otherwise we must load it into LR. */ |
14711 | if (really_return | |
a15908a4 | 14712 | && (IS_INTERRUPT (func_type) || !TARGET_INTERWORK)) |
1768c26f | 14713 | return_reg = reg_names[PC_REGNUM]; |
6d3d9133 | 14714 | else |
1768c26f PB |
14715 | return_reg = reg_names[LR_REGNUM]; |
14716 | ||
6d3d9133 | 14717 | if ((live_regs_mask & (1 << IP_REGNUM)) == (1 << IP_REGNUM)) |
b034930f ILT |
14718 | { |
14719 | /* There are three possible reasons for the IP register | |
14720 | being saved. 1) a stack frame was created, in which case | |
14721 | IP contains the old stack pointer, or 2) an ISR routine | |
14722 | corrupted it, or 3) it was saved to align the stack on | |
14723 | iWMMXt. In case 1, restore IP into SP, otherwise just | |
14724 | restore IP. */ | |
14725 | if (frame_pointer_needed) | |
14726 | { | |
14727 | live_regs_mask &= ~ (1 << IP_REGNUM); | |
14728 | live_regs_mask |= (1 << SP_REGNUM); | |
14729 | } | |
14730 | else | |
e6d29d15 | 14731 | gcc_assert (IS_INTERRUPT (func_type) || TARGET_REALLY_IWMMXT); |
b034930f | 14732 | } |
f3bb6135 | 14733 | |
3a7731fd PB |
14734 | /* On some ARM architectures it is faster to use LDR rather than |
14735 | LDM to load a single register. On other architectures, the | |
14736 | cost is the same. In 26 bit mode, or for exception handlers, | |
14737 | we have to use LDM to load the PC so that the CPSR is also | |
14738 | restored. */ | |
14739 | for (reg = 0; reg <= LAST_ARM_REGNUM; reg++) | |
b279b20a NC |
14740 | if (live_regs_mask == (1U << reg)) |
14741 | break; | |
14742 | ||
3a7731fd PB |
14743 | if (reg <= LAST_ARM_REGNUM |
14744 | && (reg != LR_REGNUM | |
f676971a | 14745 | || ! really_return |
61f0ccff | 14746 | || ! IS_INTERRUPT (func_type))) |
3a7731fd | 14747 | { |
f676971a | 14748 | sprintf (instr, "ldr%s\t%%|%s, [%%|sp], #4", conditional, |
3a7731fd | 14749 | (reg == LR_REGNUM) ? return_reg : reg_names[reg]); |
6d3d9133 | 14750 | } |
ff9940b0 | 14751 | else |
1d5473cb | 14752 | { |
1768c26f PB |
14753 | char *p; |
14754 | int first = 1; | |
6d3d9133 | 14755 | |
699a4925 RE |
14756 | /* Generate the load multiple instruction to restore the |
14757 | registers. Note we can get here, even if | |
14758 | frame_pointer_needed is true, but only if sp already | |
14759 | points to the base of the saved core registers. */ | |
14760 | if (live_regs_mask & (1 << SP_REGNUM)) | |
a72d4945 | 14761 | { |
5848830f PB |
14762 | unsigned HOST_WIDE_INT stack_adjust; |
14763 | ||
5848830f | 14764 | stack_adjust = offsets->outgoing_args - offsets->saved_regs; |
e6d29d15 | 14765 | gcc_assert (stack_adjust == 0 || stack_adjust == 4); |
a72d4945 | 14766 | |
5b3e6663 | 14767 | if (stack_adjust && arm_arch5 && TARGET_ARM) |
c7e9ab97 RR |
14768 | if (TARGET_UNIFIED_ASM) |
14769 | sprintf (instr, "ldmib%s\t%%|sp, {", conditional); | |
14770 | else | |
14771 | sprintf (instr, "ldm%sib\t%%|sp, {", conditional); | |
a72d4945 RE |
14772 | else |
14773 | { | |
b279b20a NC |
14774 | /* If we can't use ldmib (SA110 bug), |
14775 | then try to pop r3 instead. */ | |
a72d4945 RE |
14776 | if (stack_adjust) |
14777 | live_regs_mask |= 1 << 3; | |
c7e9ab97 RR |
14778 | |
14779 | if (TARGET_UNIFIED_ASM) | |
14780 | sprintf (instr, "ldmfd%s\t%%|sp, {", conditional); | |
14781 | else | |
14782 | sprintf (instr, "ldm%sfd\t%%|sp, {", conditional); | |
a72d4945 RE |
14783 | } |
14784 | } | |
da6558fd | 14785 | else |
c7e9ab97 RR |
14786 | if (TARGET_UNIFIED_ASM) |
14787 | sprintf (instr, "pop%s\t{", conditional); | |
14788 | else | |
14789 | sprintf (instr, "ldm%sfd\t%%|sp!, {", conditional); | |
1768c26f PB |
14790 | |
14791 | p = instr + strlen (instr); | |
6d3d9133 | 14792 | |
1768c26f PB |
14793 | for (reg = 0; reg <= SP_REGNUM; reg++) |
14794 | if (live_regs_mask & (1 << reg)) | |
14795 | { | |
14796 | int l = strlen (reg_names[reg]); | |
14797 | ||
14798 | if (first) | |
14799 | first = 0; | |
14800 | else | |
14801 | { | |
14802 | memcpy (p, ", ", 2); | |
14803 | p += 2; | |
14804 | } | |
14805 | ||
14806 | memcpy (p, "%|", 2); | |
14807 | memcpy (p + 2, reg_names[reg], l); | |
14808 | p += l + 2; | |
14809 | } | |
f676971a | 14810 | |
1768c26f PB |
14811 | if (live_regs_mask & (1 << LR_REGNUM)) |
14812 | { | |
b17fe233 | 14813 | sprintf (p, "%s%%|%s}", first ? "" : ", ", return_reg); |
61f0ccff RE |
14814 | /* If returning from an interrupt, restore the CPSR. */ |
14815 | if (IS_INTERRUPT (func_type)) | |
b17fe233 | 14816 | strcat (p, "^"); |
1768c26f PB |
14817 | } |
14818 | else | |
14819 | strcpy (p, "}"); | |
1d5473cb | 14820 | } |
da6558fd | 14821 | |
1768c26f PB |
14822 | output_asm_insn (instr, & operand); |
14823 | ||
3a7731fd PB |
14824 | /* See if we need to generate an extra instruction to |
14825 | perform the actual function return. */ | |
14826 | if (really_return | |
14827 | && func_type != ARM_FT_INTERWORKED | |
14828 | && (live_regs_mask & (1 << LR_REGNUM)) != 0) | |
da6558fd | 14829 | { |
3a7731fd PB |
14830 | /* The return has already been handled |
14831 | by loading the LR into the PC. */ | |
14832 | really_return = 0; | |
da6558fd | 14833 | } |
ff9940b0 | 14834 | } |
e26053d1 | 14835 | |
1768c26f | 14836 | if (really_return) |
ff9940b0 | 14837 | { |
6d3d9133 NC |
14838 | switch ((int) ARM_FUNC_TYPE (func_type)) |
14839 | { | |
14840 | case ARM_FT_ISR: | |
14841 | case ARM_FT_FIQ: | |
5b3e6663 | 14842 | /* ??? This is wrong for unified assembly syntax. */ |
6d3d9133 NC |
14843 | sprintf (instr, "sub%ss\t%%|pc, %%|lr, #4", conditional); |
14844 | break; | |
14845 | ||
14846 | case ARM_FT_INTERWORKED: | |
14847 | sprintf (instr, "bx%s\t%%|lr", conditional); | |
14848 | break; | |
14849 | ||
14850 | case ARM_FT_EXCEPTION: | |
5b3e6663 | 14851 | /* ??? This is wrong for unified assembly syntax. */ |
6d3d9133 NC |
14852 | sprintf (instr, "mov%ss\t%%|pc, %%|lr", conditional); |
14853 | break; | |
14854 | ||
14855 | default: | |
68d560d4 RE |
14856 | /* Use bx if it's available. */ |
14857 | if (arm_arch5 || arm_arch4t) | |
f676971a | 14858 | sprintf (instr, "bx%s\t%%|lr", conditional); |
1768c26f | 14859 | else |
61f0ccff | 14860 | sprintf (instr, "mov%s\t%%|pc, %%|lr", conditional); |
6d3d9133 NC |
14861 | break; |
14862 | } | |
1768c26f PB |
14863 | |
14864 | output_asm_insn (instr, & operand); | |
ff9940b0 | 14865 | } |
f3bb6135 | 14866 | |
ff9940b0 RE |
14867 | return ""; |
14868 | } | |
14869 | ||
ef179a26 NC |
14870 | /* Write the function name into the code section, directly preceding |
14871 | the function prologue. | |
14872 | ||
14873 | Code will be output similar to this: | |
14874 | t0 | |
14875 | .ascii "arm_poke_function_name", 0 | |
14876 | .align | |
14877 | t1 | |
14878 | .word 0xff000000 + (t1 - t0) | |
14879 | arm_poke_function_name | |
14880 | mov ip, sp | |
14881 | stmfd sp!, {fp, ip, lr, pc} | |
14882 | sub fp, ip, #4 | |
14883 | ||
14884 | When performing a stack backtrace, code can inspect the value | |
14885 | of 'pc' stored at 'fp' + 0. If the trace function then looks | |
14886 | at location pc - 12 and the top 8 bits are set, then we know | |
14887 | that there is a function name embedded immediately preceding this | |
14888 | location and has length ((pc[-3]) & 0xff000000). | |
14889 | ||
14890 | We assume that pc is declared as a pointer to an unsigned long. | |
14891 | ||
14892 | It is of no benefit to output the function name if we are assembling | |
14893 | a leaf function. These function types will not contain a stack | |
14894 | backtrace structure, therefore it is not possible to determine the | |
14895 | function name. */ | |
ef179a26 | 14896 | void |
e32bac5b | 14897 | arm_poke_function_name (FILE *stream, const char *name) |
ef179a26 NC |
14898 | { |
14899 | unsigned long alignlength; | |
14900 | unsigned long length; | |
14901 | rtx x; | |
14902 | ||
d5b7b3ae | 14903 | length = strlen (name) + 1; |
0c2ca901 | 14904 | alignlength = ROUND_UP_WORD (length); |
f676971a | 14905 | |
949d79eb | 14906 | ASM_OUTPUT_ASCII (stream, name, length); |
ef179a26 | 14907 | ASM_OUTPUT_ALIGN (stream, 2); |
30cf4896 | 14908 | x = GEN_INT ((unsigned HOST_WIDE_INT) 0xff000000 + alignlength); |
301d03af | 14909 | assemble_aligned_integer (UNITS_PER_WORD, x); |
ef179a26 NC |
14910 | } |
14911 | ||
6d3d9133 NC |
14912 | /* Place some comments into the assembler stream |
14913 | describing the current function. */ | |
08c148a8 | 14914 | static void |
e32bac5b | 14915 | arm_output_function_prologue (FILE *f, HOST_WIDE_INT frame_size) |
cce8749e | 14916 | { |
6d3d9133 | 14917 | unsigned long func_type; |
08c148a8 | 14918 | |
d018b46e | 14919 | /* ??? Do we want to print some of the below anyway? */ |
5b3e6663 | 14920 | if (TARGET_THUMB1) |
d018b46e | 14921 | return; |
f676971a | 14922 | |
6d3d9133 | 14923 | /* Sanity check. */ |
e6d29d15 | 14924 | gcc_assert (!arm_ccfsm_state && !arm_target_insn); |
31fdb4d5 | 14925 | |
6d3d9133 | 14926 | func_type = arm_current_func_type (); |
f676971a | 14927 | |
6d3d9133 NC |
14928 | switch ((int) ARM_FUNC_TYPE (func_type)) |
14929 | { | |
14930 | default: | |
14931 | case ARM_FT_NORMAL: | |
14932 | break; | |
14933 | case ARM_FT_INTERWORKED: | |
14934 | asm_fprintf (f, "\t%@ Function supports interworking.\n"); | |
14935 | break; | |
6d3d9133 NC |
14936 | case ARM_FT_ISR: |
14937 | asm_fprintf (f, "\t%@ Interrupt Service Routine.\n"); | |
14938 | break; | |
14939 | case ARM_FT_FIQ: | |
14940 | asm_fprintf (f, "\t%@ Fast Interrupt Service Routine.\n"); | |
14941 | break; | |
14942 | case ARM_FT_EXCEPTION: | |
14943 | asm_fprintf (f, "\t%@ ARM Exception Handler.\n"); | |
14944 | break; | |
14945 | } | |
f676971a | 14946 | |
6d3d9133 NC |
14947 | if (IS_NAKED (func_type)) |
14948 | asm_fprintf (f, "\t%@ Naked Function: prologue and epilogue provided by programmer.\n"); | |
14949 | ||
14950 | if (IS_VOLATILE (func_type)) | |
14951 | asm_fprintf (f, "\t%@ Volatile: function does not return.\n"); | |
14952 | ||
14953 | if (IS_NESTED (func_type)) | |
14954 | asm_fprintf (f, "\t%@ Nested: function declared inside another function.\n"); | |
5b3e6663 PB |
14955 | if (IS_STACKALIGN (func_type)) |
14956 | asm_fprintf (f, "\t%@ Stack Align: May be called with mis-aligned SP.\n"); | |
f676971a | 14957 | |
c53dddc2 | 14958 | asm_fprintf (f, "\t%@ args = %d, pretend = %d, frame = %wd\n", |
38173d38 JH |
14959 | crtl->args.size, |
14960 | crtl->args.pretend_args_size, frame_size); | |
6d3d9133 | 14961 | |
3cb66fd7 | 14962 | asm_fprintf (f, "\t%@ frame_needed = %d, uses_anonymous_args = %d\n", |
dd18ae56 | 14963 | frame_pointer_needed, |
3cb66fd7 | 14964 | cfun->machine->uses_anonymous_args); |
cce8749e | 14965 | |
6f7ebcbb NC |
14966 | if (cfun->machine->lr_save_eliminated) |
14967 | asm_fprintf (f, "\t%@ link register save eliminated.\n"); | |
14968 | ||
e3b5732b | 14969 | if (crtl->calls_eh_return) |
c9ca9b88 PB |
14970 | asm_fprintf (f, "\t@ Calls __builtin_eh_return.\n"); |
14971 | ||
f3bb6135 | 14972 | } |
cce8749e | 14973 | |
cd2b33d0 | 14974 | const char * |
a72d4945 | 14975 | arm_output_epilogue (rtx sibling) |
cce8749e | 14976 | { |
949d79eb | 14977 | int reg; |
6f7ebcbb | 14978 | unsigned long saved_regs_mask; |
6d3d9133 | 14979 | unsigned long func_type; |
f676971a | 14980 | /* Floats_offset is the offset from the "virtual" frame. In an APCS |
c882c7ac RE |
14981 | frame that is $fp + 4 for a non-variadic function. */ |
14982 | int floats_offset = 0; | |
cce8749e | 14983 | rtx operands[3]; |
d5b7b3ae | 14984 | FILE * f = asm_out_file; |
5a9335ef | 14985 | unsigned int lrm_count = 0; |
a72d4945 | 14986 | int really_return = (sibling == NULL); |
9b66ebb1 | 14987 | int start_reg; |
5848830f | 14988 | arm_stack_offsets *offsets; |
cce8749e | 14989 | |
6d3d9133 NC |
14990 | /* If we have already generated the return instruction |
14991 | then it is futile to generate anything else. */ | |
934c2060 RR |
14992 | if (use_return_insn (FALSE, sibling) && |
14993 | (cfun->machine->return_used_this_function != 0)) | |
949d79eb | 14994 | return ""; |
cce8749e | 14995 | |
6d3d9133 | 14996 | func_type = arm_current_func_type (); |
d5b7b3ae | 14997 | |
6d3d9133 NC |
14998 | if (IS_NAKED (func_type)) |
14999 | /* Naked functions don't have epilogues. */ | |
15000 | return ""; | |
0616531f | 15001 | |
6d3d9133 | 15002 | if (IS_VOLATILE (func_type) && TARGET_ABORT_NORETURN) |
e2c671ba | 15003 | { |
86efdc8e | 15004 | rtx op; |
f676971a | 15005 | |
6d3d9133 | 15006 | /* A volatile function should never return. Call abort. */ |
ed0e6530 | 15007 | op = gen_rtx_SYMBOL_REF (Pmode, NEED_PLT_RELOC ? "abort(PLT)" : "abort"); |
2b835d68 | 15008 | assemble_external_libcall (op); |
e2c671ba | 15009 | output_asm_insn ("bl\t%a0", &op); |
f676971a | 15010 | |
949d79eb | 15011 | return ""; |
e2c671ba RE |
15012 | } |
15013 | ||
e6d29d15 NS |
15014 | /* If we are throwing an exception, then we really must be doing a |
15015 | return, so we can't tail-call. */ | |
e3b5732b | 15016 | gcc_assert (!crtl->calls_eh_return || really_return); |
f676971a | 15017 | |
5848830f | 15018 | offsets = arm_get_frame_offsets (); |
954954d1 | 15019 | saved_regs_mask = offsets->saved_regs_mask; |
5a9335ef NC |
15020 | |
15021 | if (TARGET_IWMMXT) | |
15022 | lrm_count = bit_count (saved_regs_mask); | |
15023 | ||
5848830f | 15024 | floats_offset = offsets->saved_args; |
6d3d9133 | 15025 | /* Compute how far away the floats will be. */ |
5a9335ef | 15026 | for (reg = 0; reg <= LAST_ARM_REGNUM; reg++) |
6f7ebcbb | 15027 | if (saved_regs_mask & (1 << reg)) |
6ed30148 | 15028 | floats_offset += 4; |
f676971a | 15029 | |
ec6237e4 | 15030 | if (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM) |
cce8749e | 15031 | { |
9b66ebb1 | 15032 | /* This variable is for the Virtual Frame Pointer, not VFP regs. */ |
5848830f | 15033 | int vfp_offset = offsets->frame; |
c882c7ac | 15034 | |
d79f3032 | 15035 | if (TARGET_FPA_EMU2) |
b111229a | 15036 | { |
9b66ebb1 | 15037 | for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--) |
6fb5fa3c | 15038 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
b111229a RE |
15039 | { |
15040 | floats_offset += 12; | |
f676971a | 15041 | asm_fprintf (f, "\tldfe\t%r, [%r, #-%d]\n", |
c882c7ac | 15042 | reg, FP_REGNUM, floats_offset - vfp_offset); |
b111229a RE |
15043 | } |
15044 | } | |
15045 | else | |
15046 | { | |
9b66ebb1 | 15047 | start_reg = LAST_FPA_REGNUM; |
b111229a | 15048 | |
9b66ebb1 | 15049 | for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--) |
b111229a | 15050 | { |
6fb5fa3c | 15051 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
b111229a RE |
15052 | { |
15053 | floats_offset += 12; | |
f676971a | 15054 | |
6354dc9b | 15055 | /* We can't unstack more than four registers at once. */ |
b111229a RE |
15056 | if (start_reg - reg == 3) |
15057 | { | |
dd18ae56 | 15058 | asm_fprintf (f, "\tlfm\t%r, 4, [%r, #-%d]\n", |
c882c7ac | 15059 | reg, FP_REGNUM, floats_offset - vfp_offset); |
b111229a RE |
15060 | start_reg = reg - 1; |
15061 | } | |
15062 | } | |
15063 | else | |
15064 | { | |
15065 | if (reg != start_reg) | |
dd18ae56 NC |
15066 | asm_fprintf (f, "\tlfm\t%r, %d, [%r, #-%d]\n", |
15067 | reg + 1, start_reg - reg, | |
c882c7ac | 15068 | FP_REGNUM, floats_offset - vfp_offset); |
b111229a RE |
15069 | start_reg = reg - 1; |
15070 | } | |
15071 | } | |
15072 | ||
15073 | /* Just in case the last register checked also needs unstacking. */ | |
15074 | if (reg != start_reg) | |
dd18ae56 NC |
15075 | asm_fprintf (f, "\tlfm\t%r, %d, [%r, #-%d]\n", |
15076 | reg + 1, start_reg - reg, | |
c882c7ac | 15077 | FP_REGNUM, floats_offset - vfp_offset); |
b111229a | 15078 | } |
6d3d9133 | 15079 | |
9b66ebb1 PB |
15080 | if (TARGET_HARD_FLOAT && TARGET_VFP) |
15081 | { | |
9728c9d1 | 15082 | int saved_size; |
9b66ebb1 | 15083 | |
8edfc4cc MS |
15084 | /* The fldmd insns do not have base+offset addressing |
15085 | modes, so we use IP to hold the address. */ | |
9728c9d1 | 15086 | saved_size = arm_get_vfp_saved_size (); |
9b66ebb1 | 15087 | |
9728c9d1 | 15088 | if (saved_size > 0) |
9b66ebb1 | 15089 | { |
9728c9d1 | 15090 | floats_offset += saved_size; |
9b66ebb1 PB |
15091 | asm_fprintf (f, "\tsub\t%r, %r, #%d\n", IP_REGNUM, |
15092 | FP_REGNUM, floats_offset - vfp_offset); | |
15093 | } | |
15094 | start_reg = FIRST_VFP_REGNUM; | |
15095 | for (reg = FIRST_VFP_REGNUM; reg < LAST_VFP_REGNUM; reg += 2) | |
15096 | { | |
6fb5fa3c DB |
15097 | if ((!df_regs_ever_live_p (reg) || call_used_regs[reg]) |
15098 | && (!df_regs_ever_live_p (reg + 1) || call_used_regs[reg + 1])) | |
9b66ebb1 PB |
15099 | { |
15100 | if (start_reg != reg) | |
8edfc4cc | 15101 | vfp_output_fldmd (f, IP_REGNUM, |
9728c9d1 PB |
15102 | (start_reg - FIRST_VFP_REGNUM) / 2, |
15103 | (reg - start_reg) / 2); | |
9b66ebb1 PB |
15104 | start_reg = reg + 2; |
15105 | } | |
15106 | } | |
15107 | if (start_reg != reg) | |
8edfc4cc | 15108 | vfp_output_fldmd (f, IP_REGNUM, |
9728c9d1 PB |
15109 | (start_reg - FIRST_VFP_REGNUM) / 2, |
15110 | (reg - start_reg) / 2); | |
9b66ebb1 PB |
15111 | } |
15112 | ||
5a9335ef NC |
15113 | if (TARGET_IWMMXT) |
15114 | { | |
15115 | /* The frame pointer is guaranteed to be non-double-word aligned. | |
15116 | This is because it is set to (old_stack_pointer - 4) and the | |
15117 | old_stack_pointer was double word aligned. Thus the offset to | |
15118 | the iWMMXt registers to be loaded must also be non-double-word | |
15119 | sized, so that the resultant address *is* double-word aligned. | |
15120 | We can ignore floats_offset since that was already included in | |
15121 | the live_regs_mask. */ | |
15122 | lrm_count += (lrm_count % 2 ? 2 : 1); | |
f676971a | 15123 | |
01d4c813 | 15124 | for (reg = LAST_IWMMXT_REGNUM; reg >= FIRST_IWMMXT_REGNUM; reg--) |
6fb5fa3c | 15125 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
5a9335ef | 15126 | { |
f676971a | 15127 | asm_fprintf (f, "\twldrd\t%r, [%r, #-%d]\n", |
5a9335ef | 15128 | reg, FP_REGNUM, lrm_count * 4); |
f676971a | 15129 | lrm_count += 2; |
5a9335ef NC |
15130 | } |
15131 | } | |
15132 | ||
6f7ebcbb | 15133 | /* saved_regs_mask should contain the IP, which at the time of stack |
6d3d9133 NC |
15134 | frame generation actually contains the old stack pointer. So a |
15135 | quick way to unwind the stack is just pop the IP register directly | |
15136 | into the stack pointer. */ | |
e6d29d15 | 15137 | gcc_assert (saved_regs_mask & (1 << IP_REGNUM)); |
6f7ebcbb NC |
15138 | saved_regs_mask &= ~ (1 << IP_REGNUM); |
15139 | saved_regs_mask |= (1 << SP_REGNUM); | |
6d3d9133 | 15140 | |
6f7ebcbb | 15141 | /* There are two registers left in saved_regs_mask - LR and PC. We |
6d3d9133 NC |
15142 | only need to restore the LR register (the return address), but to |
15143 | save time we can load it directly into the PC, unless we need a | |
15144 | special function exit sequence, or we are not really returning. */ | |
c9ca9b88 PB |
15145 | if (really_return |
15146 | && ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL | |
e3b5732b | 15147 | && !crtl->calls_eh_return) |
6d3d9133 NC |
15148 | /* Delete the LR from the register mask, so that the LR on |
15149 | the stack is loaded into the PC in the register mask. */ | |
6f7ebcbb | 15150 | saved_regs_mask &= ~ (1 << LR_REGNUM); |
b111229a | 15151 | else |
6f7ebcbb | 15152 | saved_regs_mask &= ~ (1 << PC_REGNUM); |
efc2515b RE |
15153 | |
15154 | /* We must use SP as the base register, because SP is one of the | |
15155 | registers being restored. If an interrupt or page fault | |
15156 | happens in the ldm instruction, the SP might or might not | |
15157 | have been restored. That would be bad, as then SP will no | |
15158 | longer indicate the safe area of stack, and we can get stack | |
15159 | corruption. Using SP as the base register means that it will | |
15160 | be reset correctly to the original value, should an interrupt | |
699a4925 RE |
15161 | occur. If the stack pointer already points at the right |
15162 | place, then omit the subtraction. */ | |
5848830f | 15163 | if (offsets->outgoing_args != (1 + (int) bit_count (saved_regs_mask)) |
e3b5732b | 15164 | || cfun->calls_alloca) |
699a4925 RE |
15165 | asm_fprintf (f, "\tsub\t%r, %r, #%d\n", SP_REGNUM, FP_REGNUM, |
15166 | 4 * bit_count (saved_regs_mask)); | |
a15908a4 | 15167 | print_multi_reg (f, "ldmfd\t%r, ", SP_REGNUM, saved_regs_mask, 0); |
7b8b8ade NC |
15168 | |
15169 | if (IS_INTERRUPT (func_type)) | |
15170 | /* Interrupt handlers will have pushed the | |
15171 | IP onto the stack, so restore it now. */ | |
a15908a4 | 15172 | print_multi_reg (f, "ldmfd\t%r!, ", SP_REGNUM, 1 << IP_REGNUM, 0); |
cce8749e CH |
15173 | } |
15174 | else | |
15175 | { | |
ec6237e4 PB |
15176 | /* This branch is executed for ARM mode (non-apcs frames) and |
15177 | Thumb-2 mode. Frame layout is essentially the same for those | |
15178 | cases, except that in ARM mode frame pointer points to the | |
15179 | first saved register, while in Thumb-2 mode the frame pointer points | |
15180 | to the last saved register. | |
15181 | ||
15182 | It is possible to make frame pointer point to last saved | |
15183 | register in both cases, and remove some conditionals below. | |
15184 | That means that fp setup in prologue would be just "mov fp, sp" | |
15185 | and sp restore in epilogue would be just "mov sp, fp", whereas | |
15186 | now we have to use add/sub in those cases. However, the value | |
15187 | of that would be marginal, as both mov and add/sub are 32-bit | |
15188 | in ARM mode, and it would require extra conditionals | |
15189 | in arm_expand_prologue to distingish ARM-apcs-frame case | |
15190 | (where frame pointer is required to point at first register) | |
15191 | and ARM-non-apcs-frame. Therefore, such change is postponed | |
15192 | until real need arise. */ | |
f0b4bdd5 | 15193 | unsigned HOST_WIDE_INT amount; |
a15908a4 | 15194 | int rfe; |
d2288d8d | 15195 | /* Restore stack pointer if necessary. */ |
ec6237e4 | 15196 | if (TARGET_ARM && frame_pointer_needed) |
5b3e6663 PB |
15197 | { |
15198 | operands[0] = stack_pointer_rtx; | |
ec6237e4 PB |
15199 | operands[1] = hard_frame_pointer_rtx; |
15200 | ||
15201 | operands[2] = GEN_INT (offsets->frame - offsets->saved_regs); | |
15202 | output_add_immediate (operands); | |
5b3e6663 | 15203 | } |
ec6237e4 | 15204 | else |
5b3e6663 | 15205 | { |
ec6237e4 PB |
15206 | if (frame_pointer_needed) |
15207 | { | |
15208 | /* For Thumb-2 restore sp from the frame pointer. | |
15209 | Operand restrictions mean we have to incrememnt FP, then copy | |
15210 | to SP. */ | |
15211 | amount = offsets->locals_base - offsets->saved_regs; | |
15212 | operands[0] = hard_frame_pointer_rtx; | |
15213 | } | |
15214 | else | |
15215 | { | |
954954d1 | 15216 | unsigned long count; |
ec6237e4 PB |
15217 | operands[0] = stack_pointer_rtx; |
15218 | amount = offsets->outgoing_args - offsets->saved_regs; | |
954954d1 PB |
15219 | /* pop call clobbered registers if it avoids a |
15220 | separate stack adjustment. */ | |
15221 | count = offsets->saved_regs - offsets->saved_args; | |
15222 | if (optimize_size | |
15223 | && count != 0 | |
e3b5732b | 15224 | && !crtl->calls_eh_return |
954954d1 PB |
15225 | && bit_count(saved_regs_mask) * 4 == count |
15226 | && !IS_INTERRUPT (func_type) | |
e3b5732b | 15227 | && !crtl->tail_call_emit) |
954954d1 PB |
15228 | { |
15229 | unsigned long mask; | |
c92f1823 IB |
15230 | /* Preserve return values, of any size. */ |
15231 | mask = (1 << ((arm_size_return_regs() + 3) / 4)) - 1; | |
954954d1 PB |
15232 | mask ^= 0xf; |
15233 | mask &= ~saved_regs_mask; | |
15234 | reg = 0; | |
15235 | while (bit_count (mask) * 4 > amount) | |
15236 | { | |
15237 | while ((mask & (1 << reg)) == 0) | |
15238 | reg++; | |
15239 | mask &= ~(1 << reg); | |
15240 | } | |
15241 | if (bit_count (mask) * 4 == amount) { | |
15242 | amount = 0; | |
15243 | saved_regs_mask |= mask; | |
15244 | } | |
15245 | } | |
ec6237e4 PB |
15246 | } |
15247 | ||
15248 | if (amount) | |
15249 | { | |
15250 | operands[1] = operands[0]; | |
15251 | operands[2] = GEN_INT (amount); | |
15252 | output_add_immediate (operands); | |
15253 | } | |
15254 | if (frame_pointer_needed) | |
15255 | asm_fprintf (f, "\tmov\t%r, %r\n", | |
15256 | SP_REGNUM, HARD_FRAME_POINTER_REGNUM); | |
d2288d8d TG |
15257 | } |
15258 | ||
d79f3032 | 15259 | if (TARGET_FPA_EMU2) |
b111229a | 15260 | { |
9b66ebb1 | 15261 | for (reg = FIRST_FPA_REGNUM; reg <= LAST_FPA_REGNUM; reg++) |
6fb5fa3c | 15262 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
dd18ae56 NC |
15263 | asm_fprintf (f, "\tldfe\t%r, [%r], #12\n", |
15264 | reg, SP_REGNUM); | |
b111229a RE |
15265 | } |
15266 | else | |
15267 | { | |
9b66ebb1 | 15268 | start_reg = FIRST_FPA_REGNUM; |
b111229a | 15269 | |
9b66ebb1 | 15270 | for (reg = FIRST_FPA_REGNUM; reg <= LAST_FPA_REGNUM; reg++) |
b111229a | 15271 | { |
6fb5fa3c | 15272 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
b111229a RE |
15273 | { |
15274 | if (reg - start_reg == 3) | |
15275 | { | |
dd18ae56 NC |
15276 | asm_fprintf (f, "\tlfmfd\t%r, 4, [%r]!\n", |
15277 | start_reg, SP_REGNUM); | |
b111229a RE |
15278 | start_reg = reg + 1; |
15279 | } | |
15280 | } | |
15281 | else | |
15282 | { | |
15283 | if (reg != start_reg) | |
dd18ae56 NC |
15284 | asm_fprintf (f, "\tlfmfd\t%r, %d, [%r]!\n", |
15285 | start_reg, reg - start_reg, | |
15286 | SP_REGNUM); | |
f676971a | 15287 | |
b111229a RE |
15288 | start_reg = reg + 1; |
15289 | } | |
15290 | } | |
15291 | ||
15292 | /* Just in case the last register checked also needs unstacking. */ | |
15293 | if (reg != start_reg) | |
dd18ae56 NC |
15294 | asm_fprintf (f, "\tlfmfd\t%r, %d, [%r]!\n", |
15295 | start_reg, reg - start_reg, SP_REGNUM); | |
b111229a RE |
15296 | } |
15297 | ||
9b66ebb1 PB |
15298 | if (TARGET_HARD_FLOAT && TARGET_VFP) |
15299 | { | |
f8b68ed3 RE |
15300 | int end_reg = LAST_VFP_REGNUM + 1; |
15301 | ||
15302 | /* Scan the registers in reverse order. We need to match | |
15303 | any groupings made in the prologue and generate matching | |
15304 | pop operations. */ | |
15305 | for (reg = LAST_VFP_REGNUM - 1; reg >= FIRST_VFP_REGNUM; reg -= 2) | |
9b66ebb1 | 15306 | { |
6fb5fa3c | 15307 | if ((!df_regs_ever_live_p (reg) || call_used_regs[reg]) |
f8b68ed3 RE |
15308 | && (!df_regs_ever_live_p (reg + 1) |
15309 | || call_used_regs[reg + 1])) | |
9b66ebb1 | 15310 | { |
f8b68ed3 | 15311 | if (end_reg > reg + 2) |
8edfc4cc | 15312 | vfp_output_fldmd (f, SP_REGNUM, |
f8b68ed3 RE |
15313 | (reg + 2 - FIRST_VFP_REGNUM) / 2, |
15314 | (end_reg - (reg + 2)) / 2); | |
15315 | end_reg = reg; | |
9b66ebb1 PB |
15316 | } |
15317 | } | |
f8b68ed3 RE |
15318 | if (end_reg > reg + 2) |
15319 | vfp_output_fldmd (f, SP_REGNUM, 0, | |
15320 | (end_reg - (reg + 2)) / 2); | |
9b66ebb1 | 15321 | } |
f8b68ed3 | 15322 | |
5a9335ef NC |
15323 | if (TARGET_IWMMXT) |
15324 | for (reg = FIRST_IWMMXT_REGNUM; reg <= LAST_IWMMXT_REGNUM; reg++) | |
6fb5fa3c | 15325 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
01d4c813 | 15326 | asm_fprintf (f, "\twldrd\t%r, [%r], #8\n", reg, SP_REGNUM); |
5a9335ef | 15327 | |
6d3d9133 | 15328 | /* If we can, restore the LR into the PC. */ |
a15908a4 PB |
15329 | if (ARM_FUNC_TYPE (func_type) != ARM_FT_INTERWORKED |
15330 | && (TARGET_ARM || ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL) | |
5b3e6663 | 15331 | && !IS_STACKALIGN (func_type) |
6d3d9133 | 15332 | && really_return |
38173d38 | 15333 | && crtl->args.pretend_args_size == 0 |
c9ca9b88 | 15334 | && saved_regs_mask & (1 << LR_REGNUM) |
e3b5732b | 15335 | && !crtl->calls_eh_return) |
cce8749e | 15336 | { |
6f7ebcbb NC |
15337 | saved_regs_mask &= ~ (1 << LR_REGNUM); |
15338 | saved_regs_mask |= (1 << PC_REGNUM); | |
a15908a4 | 15339 | rfe = IS_INTERRUPT (func_type); |
6d3d9133 | 15340 | } |
a15908a4 PB |
15341 | else |
15342 | rfe = 0; | |
d5b7b3ae | 15343 | |
6d3d9133 | 15344 | /* Load the registers off the stack. If we only have one register |
5b3e6663 PB |
15345 | to load use the LDR instruction - it is faster. For Thumb-2 |
15346 | always use pop and the assembler will pick the best instruction.*/ | |
a15908a4 PB |
15347 | if (TARGET_ARM && saved_regs_mask == (1 << LR_REGNUM) |
15348 | && !IS_INTERRUPT(func_type)) | |
6d3d9133 | 15349 | { |
c9ca9b88 | 15350 | asm_fprintf (f, "\tldr\t%r, [%r], #4\n", LR_REGNUM, SP_REGNUM); |
cce8749e | 15351 | } |
6f7ebcbb | 15352 | else if (saved_regs_mask) |
f1acdf8b NC |
15353 | { |
15354 | if (saved_regs_mask & (1 << SP_REGNUM)) | |
15355 | /* Note - write back to the stack register is not enabled | |
112cdef5 | 15356 | (i.e. "ldmfd sp!..."). We know that the stack pointer is |
f1acdf8b NC |
15357 | in the list of registers and if we add writeback the |
15358 | instruction becomes UNPREDICTABLE. */ | |
a15908a4 PB |
15359 | print_multi_reg (f, "ldmfd\t%r, ", SP_REGNUM, saved_regs_mask, |
15360 | rfe); | |
5b3e6663 | 15361 | else if (TARGET_ARM) |
a15908a4 PB |
15362 | print_multi_reg (f, "ldmfd\t%r!, ", SP_REGNUM, saved_regs_mask, |
15363 | rfe); | |
f1acdf8b | 15364 | else |
a15908a4 | 15365 | print_multi_reg (f, "pop\t", SP_REGNUM, saved_regs_mask, 0); |
f1acdf8b | 15366 | } |
6d3d9133 | 15367 | |
38173d38 | 15368 | if (crtl->args.pretend_args_size) |
cce8749e | 15369 | { |
6d3d9133 NC |
15370 | /* Unwind the pre-pushed regs. */ |
15371 | operands[0] = operands[1] = stack_pointer_rtx; | |
38173d38 | 15372 | operands[2] = GEN_INT (crtl->args.pretend_args_size); |
6d3d9133 NC |
15373 | output_add_immediate (operands); |
15374 | } | |
15375 | } | |
32de079a | 15376 | |
2966b00e | 15377 | /* We may have already restored PC directly from the stack. */ |
0cc3dda8 | 15378 | if (!really_return || saved_regs_mask & (1 << PC_REGNUM)) |
6d3d9133 | 15379 | return ""; |
d5b7b3ae | 15380 | |
c9ca9b88 | 15381 | /* Stack adjustment for exception handler. */ |
e3b5732b | 15382 | if (crtl->calls_eh_return) |
f676971a | 15383 | asm_fprintf (f, "\tadd\t%r, %r, %r\n", SP_REGNUM, SP_REGNUM, |
c9ca9b88 PB |
15384 | ARM_EH_STACKADJ_REGNUM); |
15385 | ||
6d3d9133 NC |
15386 | /* Generate the return instruction. */ |
15387 | switch ((int) ARM_FUNC_TYPE (func_type)) | |
15388 | { | |
6d3d9133 NC |
15389 | case ARM_FT_ISR: |
15390 | case ARM_FT_FIQ: | |
15391 | asm_fprintf (f, "\tsubs\t%r, %r, #4\n", PC_REGNUM, LR_REGNUM); | |
15392 | break; | |
15393 | ||
15394 | case ARM_FT_EXCEPTION: | |
15395 | asm_fprintf (f, "\tmovs\t%r, %r\n", PC_REGNUM, LR_REGNUM); | |
15396 | break; | |
15397 | ||
15398 | case ARM_FT_INTERWORKED: | |
15399 | asm_fprintf (f, "\tbx\t%r\n", LR_REGNUM); | |
15400 | break; | |
15401 | ||
15402 | default: | |
5b3e6663 PB |
15403 | if (IS_STACKALIGN (func_type)) |
15404 | { | |
15405 | /* See comment in arm_expand_prologue. */ | |
15406 | asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, 0); | |
15407 | } | |
68d560d4 RE |
15408 | if (arm_arch5 || arm_arch4t) |
15409 | asm_fprintf (f, "\tbx\t%r\n", LR_REGNUM); | |
15410 | else | |
15411 | asm_fprintf (f, "\tmov\t%r, %r\n", PC_REGNUM, LR_REGNUM); | |
6d3d9133 | 15412 | break; |
cce8749e | 15413 | } |
f3bb6135 | 15414 | |
949d79eb RE |
15415 | return ""; |
15416 | } | |
15417 | ||
08c148a8 | 15418 | static void |
e32bac5b | 15419 | arm_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED, |
5848830f | 15420 | HOST_WIDE_INT frame_size ATTRIBUTE_UNUSED) |
949d79eb | 15421 | { |
5848830f PB |
15422 | arm_stack_offsets *offsets; |
15423 | ||
5b3e6663 | 15424 | if (TARGET_THUMB1) |
d5b7b3ae | 15425 | { |
b12a00f1 RE |
15426 | int regno; |
15427 | ||
15428 | /* Emit any call-via-reg trampolines that are needed for v4t support | |
15429 | of call_reg and call_value_reg type insns. */ | |
57ecec57 | 15430 | for (regno = 0; regno < LR_REGNUM; regno++) |
b12a00f1 RE |
15431 | { |
15432 | rtx label = cfun->machine->call_via[regno]; | |
15433 | ||
15434 | if (label != NULL) | |
15435 | { | |
d6b5193b | 15436 | switch_to_section (function_section (current_function_decl)); |
b12a00f1 RE |
15437 | targetm.asm_out.internal_label (asm_out_file, "L", |
15438 | CODE_LABEL_NUMBER (label)); | |
15439 | asm_fprintf (asm_out_file, "\tbx\t%r\n", regno); | |
15440 | } | |
15441 | } | |
15442 | ||
d5b7b3ae RE |
15443 | /* ??? Probably not safe to set this here, since it assumes that a |
15444 | function will be emitted as assembly immediately after we generate | |
15445 | RTL for it. This does not happen for inline functions. */ | |
934c2060 | 15446 | cfun->machine->return_used_this_function = 0; |
d5b7b3ae | 15447 | } |
5b3e6663 | 15448 | else /* TARGET_32BIT */ |
d5b7b3ae | 15449 | { |
0977774b | 15450 | /* We need to take into account any stack-frame rounding. */ |
5848830f | 15451 | offsets = arm_get_frame_offsets (); |
0977774b | 15452 | |
e6d29d15 | 15453 | gcc_assert (!use_return_insn (FALSE, NULL) |
934c2060 | 15454 | || (cfun->machine->return_used_this_function != 0) |
e6d29d15 NS |
15455 | || offsets->saved_regs == offsets->outgoing_args |
15456 | || frame_pointer_needed); | |
f3bb6135 | 15457 | |
d5b7b3ae | 15458 | /* Reset the ARM-specific per-function variables. */ |
d5b7b3ae RE |
15459 | after_arm_reorg = 0; |
15460 | } | |
f3bb6135 | 15461 | } |
e2c671ba | 15462 | |
2c849145 JM |
15463 | /* Generate and emit an insn that we will recognize as a push_multi. |
15464 | Unfortunately, since this insn does not reflect very well the actual | |
15465 | semantics of the operation, we need to annotate the insn for the benefit | |
15466 | of DWARF2 frame unwind information. */ | |
2c849145 | 15467 | static rtx |
b279b20a | 15468 | emit_multi_reg_push (unsigned long mask) |
e2c671ba RE |
15469 | { |
15470 | int num_regs = 0; | |
9b598fa0 | 15471 | int num_dwarf_regs; |
e2c671ba RE |
15472 | int i, j; |
15473 | rtx par; | |
2c849145 | 15474 | rtx dwarf; |
87e27392 | 15475 | int dwarf_par_index; |
2c849145 | 15476 | rtx tmp, reg; |
e2c671ba | 15477 | |
d5b7b3ae | 15478 | for (i = 0; i <= LAST_ARM_REGNUM; i++) |
e2c671ba | 15479 | if (mask & (1 << i)) |
5895f793 | 15480 | num_regs++; |
e2c671ba | 15481 | |
e6d29d15 | 15482 | gcc_assert (num_regs && num_regs <= 16); |
e2c671ba | 15483 | |
9b598fa0 RE |
15484 | /* We don't record the PC in the dwarf frame information. */ |
15485 | num_dwarf_regs = num_regs; | |
15486 | if (mask & (1 << PC_REGNUM)) | |
15487 | num_dwarf_regs--; | |
15488 | ||
87e27392 | 15489 | /* For the body of the insn we are going to generate an UNSPEC in |
05713b80 | 15490 | parallel with several USEs. This allows the insn to be recognized |
9abf5d7b RR |
15491 | by the push_multi pattern in the arm.md file. |
15492 | ||
15493 | The body of the insn looks something like this: | |
87e27392 | 15494 | |
f676971a | 15495 | (parallel [ |
9abf5d7b RR |
15496 | (set (mem:BLK (pre_modify:SI (reg:SI sp) |
15497 | (const_int:SI <num>))) | |
b15bca31 | 15498 | (unspec:BLK [(reg:SI r4)] UNSPEC_PUSH_MULT)) |
9abf5d7b RR |
15499 | (use (reg:SI XX)) |
15500 | (use (reg:SI YY)) | |
15501 | ... | |
87e27392 NC |
15502 | ]) |
15503 | ||
15504 | For the frame note however, we try to be more explicit and actually | |
15505 | show each register being stored into the stack frame, plus a (single) | |
15506 | decrement of the stack pointer. We do it this way in order to be | |
15507 | friendly to the stack unwinding code, which only wants to see a single | |
15508 | stack decrement per instruction. The RTL we generate for the note looks | |
15509 | something like this: | |
15510 | ||
f676971a | 15511 | (sequence [ |
87e27392 NC |
15512 | (set (reg:SI sp) (plus:SI (reg:SI sp) (const_int -20))) |
15513 | (set (mem:SI (reg:SI sp)) (reg:SI r4)) | |
9abf5d7b RR |
15514 | (set (mem:SI (plus:SI (reg:SI sp) (const_int 4))) (reg:SI XX)) |
15515 | (set (mem:SI (plus:SI (reg:SI sp) (const_int 8))) (reg:SI YY)) | |
15516 | ... | |
87e27392 NC |
15517 | ]) |
15518 | ||
9abf5d7b RR |
15519 | FIXME:: In an ideal world the PRE_MODIFY would not exist and |
15520 | instead we'd have a parallel expression detailing all | |
15521 | the stores to the various memory addresses so that debug | |
15522 | information is more up-to-date. Remember however while writing | |
15523 | this to take care of the constraints with the push instruction. | |
15524 | ||
15525 | Note also that this has to be taken care of for the VFP registers. | |
15526 | ||
15527 | For more see PR43399. */ | |
f676971a | 15528 | |
43cffd11 | 15529 | par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_regs)); |
9b598fa0 | 15530 | dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (num_dwarf_regs + 1)); |
87e27392 | 15531 | dwarf_par_index = 1; |
e2c671ba | 15532 | |
d5b7b3ae | 15533 | for (i = 0; i <= LAST_ARM_REGNUM; i++) |
e2c671ba RE |
15534 | { |
15535 | if (mask & (1 << i)) | |
15536 | { | |
2c849145 JM |
15537 | reg = gen_rtx_REG (SImode, i); |
15538 | ||
e2c671ba | 15539 | XVECEXP (par, 0, 0) |
43cffd11 | 15540 | = gen_rtx_SET (VOIDmode, |
9abf5d7b RR |
15541 | gen_frame_mem |
15542 | (BLKmode, | |
15543 | gen_rtx_PRE_MODIFY (Pmode, | |
15544 | stack_pointer_rtx, | |
15545 | plus_constant | |
15546 | (stack_pointer_rtx, | |
15547 | -4 * num_regs)) | |
15548 | ), | |
43cffd11 | 15549 | gen_rtx_UNSPEC (BLKmode, |
2c849145 | 15550 | gen_rtvec (1, reg), |
9b598fa0 | 15551 | UNSPEC_PUSH_MULT)); |
2c849145 | 15552 | |
9b598fa0 RE |
15553 | if (i != PC_REGNUM) |
15554 | { | |
15555 | tmp = gen_rtx_SET (VOIDmode, | |
31fa16b6 | 15556 | gen_frame_mem (SImode, stack_pointer_rtx), |
9b598fa0 RE |
15557 | reg); |
15558 | RTX_FRAME_RELATED_P (tmp) = 1; | |
15559 | XVECEXP (dwarf, 0, dwarf_par_index) = tmp; | |
15560 | dwarf_par_index++; | |
15561 | } | |
2c849145 | 15562 | |
e2c671ba RE |
15563 | break; |
15564 | } | |
15565 | } | |
15566 | ||
15567 | for (j = 1, i++; j < num_regs; i++) | |
15568 | { | |
15569 | if (mask & (1 << i)) | |
15570 | { | |
2c849145 JM |
15571 | reg = gen_rtx_REG (SImode, i); |
15572 | ||
15573 | XVECEXP (par, 0, j) = gen_rtx_USE (VOIDmode, reg); | |
15574 | ||
9b598fa0 RE |
15575 | if (i != PC_REGNUM) |
15576 | { | |
31fa16b6 RE |
15577 | tmp |
15578 | = gen_rtx_SET (VOIDmode, | |
9abf5d7b RR |
15579 | gen_frame_mem |
15580 | (SImode, | |
15581 | plus_constant (stack_pointer_rtx, | |
15582 | 4 * j)), | |
31fa16b6 | 15583 | reg); |
9b598fa0 RE |
15584 | RTX_FRAME_RELATED_P (tmp) = 1; |
15585 | XVECEXP (dwarf, 0, dwarf_par_index++) = tmp; | |
15586 | } | |
15587 | ||
e2c671ba RE |
15588 | j++; |
15589 | } | |
15590 | } | |
b111229a | 15591 | |
2c849145 | 15592 | par = emit_insn (par); |
f676971a | 15593 | |
d66437c5 | 15594 | tmp = gen_rtx_SET (VOIDmode, |
87e27392 | 15595 | stack_pointer_rtx, |
d66437c5 | 15596 | plus_constant (stack_pointer_rtx, -4 * num_regs)); |
87e27392 NC |
15597 | RTX_FRAME_RELATED_P (tmp) = 1; |
15598 | XVECEXP (dwarf, 0, 0) = tmp; | |
f676971a | 15599 | |
bbbbb16a ILT |
15600 | add_reg_note (par, REG_FRAME_RELATED_EXPR, dwarf); |
15601 | ||
2c849145 | 15602 | return par; |
b111229a RE |
15603 | } |
15604 | ||
4f5dfed0 | 15605 | /* Calculate the size of the return value that is passed in registers. */ |
466e4b7a | 15606 | static unsigned |
4f5dfed0 JC |
15607 | arm_size_return_regs (void) |
15608 | { | |
15609 | enum machine_mode mode; | |
15610 | ||
38173d38 JH |
15611 | if (crtl->return_rtx != 0) |
15612 | mode = GET_MODE (crtl->return_rtx); | |
4f5dfed0 JC |
15613 | else |
15614 | mode = DECL_MODE (DECL_RESULT (current_function_decl)); | |
15615 | ||
15616 | return GET_MODE_SIZE (mode); | |
15617 | } | |
15618 | ||
2c849145 | 15619 | static rtx |
e32bac5b | 15620 | emit_sfm (int base_reg, int count) |
b111229a RE |
15621 | { |
15622 | rtx par; | |
2c849145 JM |
15623 | rtx dwarf; |
15624 | rtx tmp, reg; | |
b111229a RE |
15625 | int i; |
15626 | ||
43cffd11 | 15627 | par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count)); |
8ee6eb4e | 15628 | dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (count + 1)); |
2c849145 JM |
15629 | |
15630 | reg = gen_rtx_REG (XFmode, base_reg++); | |
43cffd11 RE |
15631 | |
15632 | XVECEXP (par, 0, 0) | |
f676971a | 15633 | = gen_rtx_SET (VOIDmode, |
9abf5d7b RR |
15634 | gen_frame_mem |
15635 | (BLKmode, | |
15636 | gen_rtx_PRE_MODIFY (Pmode, | |
15637 | stack_pointer_rtx, | |
15638 | plus_constant | |
15639 | (stack_pointer_rtx, | |
15640 | -12 * count)) | |
15641 | ), | |
43cffd11 | 15642 | gen_rtx_UNSPEC (BLKmode, |
2c849145 | 15643 | gen_rtvec (1, reg), |
b15bca31 | 15644 | UNSPEC_PUSH_MULT)); |
f676971a | 15645 | tmp = gen_rtx_SET (VOIDmode, |
31fa16b6 | 15646 | gen_frame_mem (XFmode, stack_pointer_rtx), reg); |
2c849145 | 15647 | RTX_FRAME_RELATED_P (tmp) = 1; |
f676971a EC |
15648 | XVECEXP (dwarf, 0, 1) = tmp; |
15649 | ||
b111229a | 15650 | for (i = 1; i < count; i++) |
2c849145 JM |
15651 | { |
15652 | reg = gen_rtx_REG (XFmode, base_reg++); | |
15653 | XVECEXP (par, 0, i) = gen_rtx_USE (VOIDmode, reg); | |
15654 | ||
f676971a | 15655 | tmp = gen_rtx_SET (VOIDmode, |
31fa16b6 RE |
15656 | gen_frame_mem (XFmode, |
15657 | plus_constant (stack_pointer_rtx, | |
15658 | i * 12)), | |
2c849145 JM |
15659 | reg); |
15660 | RTX_FRAME_RELATED_P (tmp) = 1; | |
f676971a | 15661 | XVECEXP (dwarf, 0, i + 1) = tmp; |
2c849145 | 15662 | } |
b111229a | 15663 | |
8ee6eb4e PB |
15664 | tmp = gen_rtx_SET (VOIDmode, |
15665 | stack_pointer_rtx, | |
d66437c5 RE |
15666 | plus_constant (stack_pointer_rtx, -12 * count)); |
15667 | ||
8ee6eb4e PB |
15668 | RTX_FRAME_RELATED_P (tmp) = 1; |
15669 | XVECEXP (dwarf, 0, 0) = tmp; | |
15670 | ||
2c849145 | 15671 | par = emit_insn (par); |
bbbbb16a ILT |
15672 | add_reg_note (par, REG_FRAME_RELATED_EXPR, dwarf); |
15673 | ||
2c849145 | 15674 | return par; |
e2c671ba RE |
15675 | } |
15676 | ||
9b66ebb1 | 15677 | |
3c7ad43e PB |
15678 | /* Return true if the current function needs to save/restore LR. */ |
15679 | ||
15680 | static bool | |
15681 | thumb_force_lr_save (void) | |
15682 | { | |
15683 | return !cfun->machine->lr_save_eliminated | |
15684 | && (!leaf_function_p () | |
15685 | || thumb_far_jump_used_p () | |
6fb5fa3c | 15686 | || df_regs_ever_live_p (LR_REGNUM)); |
3c7ad43e PB |
15687 | } |
15688 | ||
15689 | ||
147a0bcf JJ |
15690 | /* Return true if r3 is used by any of the tail call insns in the |
15691 | current function. */ | |
15692 | ||
15693 | static bool | |
15694 | any_sibcall_uses_r3 (void) | |
15695 | { | |
15696 | edge_iterator ei; | |
15697 | edge e; | |
15698 | ||
15699 | if (!crtl->tail_call_emit) | |
15700 | return false; | |
15701 | FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds) | |
15702 | if (e->flags & EDGE_SIBCALL) | |
15703 | { | |
15704 | rtx call = BB_END (e->src); | |
15705 | if (!CALL_P (call)) | |
15706 | call = prev_nonnote_nondebug_insn (call); | |
15707 | gcc_assert (CALL_P (call) && SIBLING_CALL_P (call)); | |
15708 | if (find_regno_fusage (call, USE, 3)) | |
15709 | return true; | |
15710 | } | |
15711 | return false; | |
15712 | } | |
15713 | ||
15714 | ||
095bb276 NC |
15715 | /* Compute the distance from register FROM to register TO. |
15716 | These can be the arg pointer (26), the soft frame pointer (25), | |
15717 | the stack pointer (13) or the hard frame pointer (11). | |
c9ca9b88 | 15718 | In thumb mode r7 is used as the soft frame pointer, if needed. |
095bb276 NC |
15719 | Typical stack layout looks like this: |
15720 | ||
15721 | old stack pointer -> | | | |
15722 | ---- | |
15723 | | | \ | |
15724 | | | saved arguments for | |
15725 | | | vararg functions | |
15726 | | | / | |
15727 | -- | |
15728 | hard FP & arg pointer -> | | \ | |
15729 | | | stack | |
15730 | | | frame | |
15731 | | | / | |
15732 | -- | |
15733 | | | \ | |
15734 | | | call saved | |
15735 | | | registers | |
15736 | soft frame pointer -> | | / | |
15737 | -- | |
15738 | | | \ | |
15739 | | | local | |
15740 | | | variables | |
2591db65 | 15741 | locals base pointer -> | | / |
095bb276 NC |
15742 | -- |
15743 | | | \ | |
15744 | | | outgoing | |
15745 | | | arguments | |
15746 | current stack pointer -> | | / | |
15747 | -- | |
15748 | ||
43aa4e05 | 15749 | For a given function some or all of these stack components |
095bb276 NC |
15750 | may not be needed, giving rise to the possibility of |
15751 | eliminating some of the registers. | |
15752 | ||
825dda42 | 15753 | The values returned by this function must reflect the behavior |
095bb276 NC |
15754 | of arm_expand_prologue() and arm_compute_save_reg_mask(). |
15755 | ||
15756 | The sign of the number returned reflects the direction of stack | |
15757 | growth, so the values are positive for all eliminations except | |
5848830f PB |
15758 | from the soft frame pointer to the hard frame pointer. |
15759 | ||
15760 | SFP may point just inside the local variables block to ensure correct | |
15761 | alignment. */ | |
15762 | ||
15763 | ||
15764 | /* Calculate stack offsets. These are used to calculate register elimination | |
954954d1 PB |
15765 | offsets and in prologue/epilogue code. Also calculates which registers |
15766 | should be saved. */ | |
5848830f PB |
15767 | |
15768 | static arm_stack_offsets * | |
15769 | arm_get_frame_offsets (void) | |
095bb276 | 15770 | { |
5848830f | 15771 | struct arm_stack_offsets *offsets; |
095bb276 | 15772 | unsigned long func_type; |
5848830f | 15773 | int leaf; |
5848830f | 15774 | int saved; |
954954d1 | 15775 | int core_saved; |
5848830f | 15776 | HOST_WIDE_INT frame_size; |
954954d1 | 15777 | int i; |
5848830f PB |
15778 | |
15779 | offsets = &cfun->machine->stack_offsets; | |
f676971a | 15780 | |
5848830f PB |
15781 | /* We need to know if we are a leaf function. Unfortunately, it |
15782 | is possible to be called after start_sequence has been called, | |
15783 | which causes get_insns to return the insns for the sequence, | |
15784 | not the function, which will cause leaf_function_p to return | |
15785 | the incorrect result. | |
095bb276 | 15786 | |
5848830f PB |
15787 | to know about leaf functions once reload has completed, and the |
15788 | frame size cannot be changed after that time, so we can safely | |
15789 | use the cached value. */ | |
15790 | ||
15791 | if (reload_completed) | |
15792 | return offsets; | |
15793 | ||
666c27b9 KH |
15794 | /* Initially this is the size of the local variables. It will translated |
15795 | into an offset once we have determined the size of preceding data. */ | |
5848830f PB |
15796 | frame_size = ROUND_UP_WORD (get_frame_size ()); |
15797 | ||
15798 | leaf = leaf_function_p (); | |
15799 | ||
15800 | /* Space for variadic functions. */ | |
38173d38 | 15801 | offsets->saved_args = crtl->args.pretend_args_size; |
5848830f | 15802 | |
5b3e6663 | 15803 | /* In Thumb mode this is incorrect, but never used. */ |
35596784 AJ |
15804 | offsets->frame = offsets->saved_args + (frame_pointer_needed ? 4 : 0) + |
15805 | arm_compute_static_chain_stack_bytes(); | |
5848830f | 15806 | |
5b3e6663 | 15807 | if (TARGET_32BIT) |
095bb276 | 15808 | { |
5848830f | 15809 | unsigned int regno; |
ef7112de | 15810 | |
954954d1 PB |
15811 | offsets->saved_regs_mask = arm_compute_save_reg_mask (); |
15812 | core_saved = bit_count (offsets->saved_regs_mask) * 4; | |
15813 | saved = core_saved; | |
5a9335ef | 15814 | |
5848830f PB |
15815 | /* We know that SP will be doubleword aligned on entry, and we must |
15816 | preserve that condition at any subroutine call. We also require the | |
15817 | soft frame pointer to be doubleword aligned. */ | |
15818 | ||
15819 | if (TARGET_REALLY_IWMMXT) | |
9b66ebb1 | 15820 | { |
5848830f PB |
15821 | /* Check for the call-saved iWMMXt registers. */ |
15822 | for (regno = FIRST_IWMMXT_REGNUM; | |
15823 | regno <= LAST_IWMMXT_REGNUM; | |
15824 | regno++) | |
6fb5fa3c | 15825 | if (df_regs_ever_live_p (regno) && ! call_used_regs[regno]) |
5848830f PB |
15826 | saved += 8; |
15827 | } | |
15828 | ||
15829 | func_type = arm_current_func_type (); | |
15830 | if (! IS_VOLATILE (func_type)) | |
15831 | { | |
15832 | /* Space for saved FPA registers. */ | |
15833 | for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++) | |
6fb5fa3c | 15834 | if (df_regs_ever_live_p (regno) && ! call_used_regs[regno]) |
5848830f PB |
15835 | saved += 12; |
15836 | ||
15837 | /* Space for saved VFP registers. */ | |
15838 | if (TARGET_HARD_FLOAT && TARGET_VFP) | |
9728c9d1 | 15839 | saved += arm_get_vfp_saved_size (); |
9b66ebb1 | 15840 | } |
5848830f | 15841 | } |
5b3e6663 | 15842 | else /* TARGET_THUMB1 */ |
5848830f | 15843 | { |
954954d1 PB |
15844 | offsets->saved_regs_mask = thumb1_compute_save_reg_mask (); |
15845 | core_saved = bit_count (offsets->saved_regs_mask) * 4; | |
15846 | saved = core_saved; | |
5848830f | 15847 | if (TARGET_BACKTRACE) |
57934c39 | 15848 | saved += 16; |
5848830f | 15849 | } |
9b66ebb1 | 15850 | |
5848830f | 15851 | /* Saved registers include the stack frame. */ |
35596784 AJ |
15852 | offsets->saved_regs = offsets->saved_args + saved + |
15853 | arm_compute_static_chain_stack_bytes(); | |
a2503645 | 15854 | offsets->soft_frame = offsets->saved_regs + CALLER_INTERWORKING_SLOT_SIZE; |
5848830f PB |
15855 | /* A leaf function does not need any stack alignment if it has nothing |
15856 | on the stack. */ | |
7c71147d CLT |
15857 | if (leaf && frame_size == 0 |
15858 | /* However if it calls alloca(), we have a dynamically allocated | |
15859 | block of BIGGEST_ALIGNMENT on stack, so still do stack alignment. */ | |
15860 | && ! cfun->calls_alloca) | |
5848830f PB |
15861 | { |
15862 | offsets->outgoing_args = offsets->soft_frame; | |
a3a531ec | 15863 | offsets->locals_base = offsets->soft_frame; |
5848830f PB |
15864 | return offsets; |
15865 | } | |
15866 | ||
15867 | /* Ensure SFP has the correct alignment. */ | |
15868 | if (ARM_DOUBLEWORD_ALIGN | |
15869 | && (offsets->soft_frame & 7)) | |
954954d1 PB |
15870 | { |
15871 | offsets->soft_frame += 4; | |
15872 | /* Try to align stack by pushing an extra reg. Don't bother doing this | |
15873 | when there is a stack frame as the alignment will be rolled into | |
15874 | the normal stack adjustment. */ | |
38173d38 | 15875 | if (frame_size + crtl->outgoing_args_size == 0) |
954954d1 PB |
15876 | { |
15877 | int reg = -1; | |
15878 | ||
55b2829b RE |
15879 | /* If it is safe to use r3, then do so. This sometimes |
15880 | generates better code on Thumb-2 by avoiding the need to | |
15881 | use 32-bit push/pop instructions. */ | |
147a0bcf | 15882 | if (! any_sibcall_uses_r3 () |
fb2f8cf8 JZ |
15883 | && arm_size_return_regs () <= 12 |
15884 | && (offsets->saved_regs_mask & (1 << 3)) == 0) | |
954954d1 | 15885 | { |
954954d1 PB |
15886 | reg = 3; |
15887 | } | |
55b2829b RE |
15888 | else |
15889 | for (i = 4; i <= (TARGET_THUMB1 ? LAST_LO_REGNUM : 11); i++) | |
15890 | { | |
15891 | if ((offsets->saved_regs_mask & (1 << i)) == 0) | |
15892 | { | |
15893 | reg = i; | |
15894 | break; | |
15895 | } | |
15896 | } | |
954954d1 PB |
15897 | |
15898 | if (reg != -1) | |
15899 | { | |
15900 | offsets->saved_regs += 4; | |
15901 | offsets->saved_regs_mask |= (1 << reg); | |
15902 | } | |
15903 | } | |
15904 | } | |
5848830f | 15905 | |
2591db65 RE |
15906 | offsets->locals_base = offsets->soft_frame + frame_size; |
15907 | offsets->outgoing_args = (offsets->locals_base | |
38173d38 | 15908 | + crtl->outgoing_args_size); |
5848830f PB |
15909 | |
15910 | if (ARM_DOUBLEWORD_ALIGN) | |
15911 | { | |
15912 | /* Ensure SP remains doubleword aligned. */ | |
15913 | if (offsets->outgoing_args & 7) | |
15914 | offsets->outgoing_args += 4; | |
e6d29d15 | 15915 | gcc_assert (!(offsets->outgoing_args & 7)); |
095bb276 NC |
15916 | } |
15917 | ||
5848830f PB |
15918 | return offsets; |
15919 | } | |
15920 | ||
15921 | ||
666c27b9 | 15922 | /* Calculate the relative offsets for the different stack pointers. Positive |
5848830f PB |
15923 | offsets are in the direction of stack growth. */ |
15924 | ||
b3f8d95d | 15925 | HOST_WIDE_INT |
5848830f PB |
15926 | arm_compute_initial_elimination_offset (unsigned int from, unsigned int to) |
15927 | { | |
15928 | arm_stack_offsets *offsets; | |
15929 | ||
15930 | offsets = arm_get_frame_offsets (); | |
095bb276 | 15931 | |
095bb276 NC |
15932 | /* OK, now we have enough information to compute the distances. |
15933 | There must be an entry in these switch tables for each pair | |
15934 | of registers in ELIMINABLE_REGS, even if some of the entries | |
15935 | seem to be redundant or useless. */ | |
15936 | switch (from) | |
15937 | { | |
15938 | case ARG_POINTER_REGNUM: | |
15939 | switch (to) | |
15940 | { | |
15941 | case THUMB_HARD_FRAME_POINTER_REGNUM: | |
15942 | return 0; | |
15943 | ||
15944 | case FRAME_POINTER_REGNUM: | |
15945 | /* This is the reverse of the soft frame pointer | |
15946 | to hard frame pointer elimination below. */ | |
5848830f | 15947 | return offsets->soft_frame - offsets->saved_args; |
095bb276 NC |
15948 | |
15949 | case ARM_HARD_FRAME_POINTER_REGNUM: | |
35596784 AJ |
15950 | /* This is only non-zero in the case where the static chain register |
15951 | is stored above the frame. */ | |
15952 | return offsets->frame - offsets->saved_args - 4; | |
095bb276 NC |
15953 | |
15954 | case STACK_POINTER_REGNUM: | |
15955 | /* If nothing has been pushed on the stack at all | |
15956 | then this will return -4. This *is* correct! */ | |
5848830f | 15957 | return offsets->outgoing_args - (offsets->saved_args + 4); |
095bb276 NC |
15958 | |
15959 | default: | |
e6d29d15 | 15960 | gcc_unreachable (); |
095bb276 | 15961 | } |
e6d29d15 | 15962 | gcc_unreachable (); |
095bb276 NC |
15963 | |
15964 | case FRAME_POINTER_REGNUM: | |
15965 | switch (to) | |
15966 | { | |
15967 | case THUMB_HARD_FRAME_POINTER_REGNUM: | |
15968 | return 0; | |
15969 | ||
15970 | case ARM_HARD_FRAME_POINTER_REGNUM: | |
15971 | /* The hard frame pointer points to the top entry in the | |
15972 | stack frame. The soft frame pointer to the bottom entry | |
15973 | in the stack frame. If there is no stack frame at all, | |
15974 | then they are identical. */ | |
5848830f PB |
15975 | |
15976 | return offsets->frame - offsets->soft_frame; | |
095bb276 NC |
15977 | |
15978 | case STACK_POINTER_REGNUM: | |
5848830f | 15979 | return offsets->outgoing_args - offsets->soft_frame; |
095bb276 NC |
15980 | |
15981 | default: | |
e6d29d15 | 15982 | gcc_unreachable (); |
095bb276 | 15983 | } |
e6d29d15 | 15984 | gcc_unreachable (); |
095bb276 NC |
15985 | |
15986 | default: | |
15987 | /* You cannot eliminate from the stack pointer. | |
15988 | In theory you could eliminate from the hard frame | |
15989 | pointer to the stack pointer, but this will never | |
15990 | happen, since if a stack frame is not needed the | |
15991 | hard frame pointer will never be used. */ | |
e6d29d15 | 15992 | gcc_unreachable (); |
095bb276 NC |
15993 | } |
15994 | } | |
15995 | ||
7b5cbb57 AS |
15996 | /* Given FROM and TO register numbers, say whether this elimination is |
15997 | allowed. Frame pointer elimination is automatically handled. | |
15998 | ||
15999 | All eliminations are permissible. Note that ARG_POINTER_REGNUM and | |
16000 | HARD_FRAME_POINTER_REGNUM are in fact the same thing. If we need a frame | |
16001 | pointer, we must eliminate FRAME_POINTER_REGNUM into | |
16002 | HARD_FRAME_POINTER_REGNUM and not into STACK_POINTER_REGNUM or | |
16003 | ARG_POINTER_REGNUM. */ | |
16004 | ||
16005 | bool | |
16006 | arm_can_eliminate (const int from, const int to) | |
16007 | { | |
16008 | return ((to == FRAME_POINTER_REGNUM && from == ARG_POINTER_REGNUM) ? false : | |
16009 | (to == STACK_POINTER_REGNUM && frame_pointer_needed) ? false : | |
16010 | (to == ARM_HARD_FRAME_POINTER_REGNUM && TARGET_THUMB) ? false : | |
16011 | (to == THUMB_HARD_FRAME_POINTER_REGNUM && TARGET_ARM) ? false : | |
16012 | true); | |
16013 | } | |
0977774b | 16014 | |
7a085dce | 16015 | /* Emit RTL to save coprocessor registers on function entry. Returns the |
5b3e6663 PB |
16016 | number of bytes pushed. */ |
16017 | ||
16018 | static int | |
16019 | arm_save_coproc_regs(void) | |
16020 | { | |
16021 | int saved_size = 0; | |
16022 | unsigned reg; | |
16023 | unsigned start_reg; | |
16024 | rtx insn; | |
16025 | ||
16026 | for (reg = LAST_IWMMXT_REGNUM; reg >= FIRST_IWMMXT_REGNUM; reg--) | |
6fb5fa3c | 16027 | if (df_regs_ever_live_p (reg) && ! call_used_regs[reg]) |
5b3e6663 | 16028 | { |
d8d55ac0 | 16029 | insn = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx); |
5b3e6663 PB |
16030 | insn = gen_rtx_MEM (V2SImode, insn); |
16031 | insn = emit_set_insn (insn, gen_rtx_REG (V2SImode, reg)); | |
16032 | RTX_FRAME_RELATED_P (insn) = 1; | |
16033 | saved_size += 8; | |
16034 | } | |
16035 | ||
16036 | /* Save any floating point call-saved registers used by this | |
16037 | function. */ | |
d79f3032 | 16038 | if (TARGET_FPA_EMU2) |
5b3e6663 PB |
16039 | { |
16040 | for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--) | |
6fb5fa3c | 16041 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
5b3e6663 | 16042 | { |
d8d55ac0 | 16043 | insn = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx); |
5b3e6663 PB |
16044 | insn = gen_rtx_MEM (XFmode, insn); |
16045 | insn = emit_set_insn (insn, gen_rtx_REG (XFmode, reg)); | |
16046 | RTX_FRAME_RELATED_P (insn) = 1; | |
16047 | saved_size += 12; | |
16048 | } | |
16049 | } | |
16050 | else | |
16051 | { | |
16052 | start_reg = LAST_FPA_REGNUM; | |
16053 | ||
16054 | for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--) | |
16055 | { | |
6fb5fa3c | 16056 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
5b3e6663 PB |
16057 | { |
16058 | if (start_reg - reg == 3) | |
16059 | { | |
16060 | insn = emit_sfm (reg, 4); | |
16061 | RTX_FRAME_RELATED_P (insn) = 1; | |
16062 | saved_size += 48; | |
16063 | start_reg = reg - 1; | |
16064 | } | |
16065 | } | |
16066 | else | |
16067 | { | |
16068 | if (start_reg != reg) | |
16069 | { | |
16070 | insn = emit_sfm (reg + 1, start_reg - reg); | |
16071 | RTX_FRAME_RELATED_P (insn) = 1; | |
16072 | saved_size += (start_reg - reg) * 12; | |
16073 | } | |
16074 | start_reg = reg - 1; | |
16075 | } | |
16076 | } | |
16077 | ||
16078 | if (start_reg != reg) | |
16079 | { | |
16080 | insn = emit_sfm (reg + 1, start_reg - reg); | |
16081 | saved_size += (start_reg - reg) * 12; | |
16082 | RTX_FRAME_RELATED_P (insn) = 1; | |
16083 | } | |
16084 | } | |
16085 | if (TARGET_HARD_FLOAT && TARGET_VFP) | |
16086 | { | |
16087 | start_reg = FIRST_VFP_REGNUM; | |
16088 | ||
16089 | for (reg = FIRST_VFP_REGNUM; reg < LAST_VFP_REGNUM; reg += 2) | |
16090 | { | |
6fb5fa3c DB |
16091 | if ((!df_regs_ever_live_p (reg) || call_used_regs[reg]) |
16092 | && (!df_regs_ever_live_p (reg + 1) || call_used_regs[reg + 1])) | |
5b3e6663 PB |
16093 | { |
16094 | if (start_reg != reg) | |
16095 | saved_size += vfp_emit_fstmd (start_reg, | |
16096 | (reg - start_reg) / 2); | |
16097 | start_reg = reg + 2; | |
16098 | } | |
16099 | } | |
16100 | if (start_reg != reg) | |
16101 | saved_size += vfp_emit_fstmd (start_reg, | |
16102 | (reg - start_reg) / 2); | |
16103 | } | |
16104 | return saved_size; | |
16105 | } | |
16106 | ||
16107 | ||
16108 | /* Set the Thumb frame pointer from the stack pointer. */ | |
16109 | ||
16110 | static void | |
16111 | thumb_set_frame_pointer (arm_stack_offsets *offsets) | |
16112 | { | |
16113 | HOST_WIDE_INT amount; | |
16114 | rtx insn, dwarf; | |
16115 | ||
16116 | amount = offsets->outgoing_args - offsets->locals_base; | |
16117 | if (amount < 1024) | |
16118 | insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, | |
16119 | stack_pointer_rtx, GEN_INT (amount))); | |
16120 | else | |
16121 | { | |
16122 | emit_insn (gen_movsi (hard_frame_pointer_rtx, GEN_INT (amount))); | |
f5c630c3 PB |
16123 | /* Thumb-2 RTL patterns expect sp as the first input. Thumb-1 |
16124 | expects the first two operands to be the same. */ | |
16125 | if (TARGET_THUMB2) | |
16126 | { | |
16127 | insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, | |
16128 | stack_pointer_rtx, | |
16129 | hard_frame_pointer_rtx)); | |
16130 | } | |
16131 | else | |
16132 | { | |
16133 | insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, | |
16134 | hard_frame_pointer_rtx, | |
16135 | stack_pointer_rtx)); | |
16136 | } | |
5b3e6663 PB |
16137 | dwarf = gen_rtx_SET (VOIDmode, hard_frame_pointer_rtx, |
16138 | plus_constant (stack_pointer_rtx, amount)); | |
16139 | RTX_FRAME_RELATED_P (dwarf) = 1; | |
bbbbb16a | 16140 | add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
5b3e6663 PB |
16141 | } |
16142 | ||
16143 | RTX_FRAME_RELATED_P (insn) = 1; | |
16144 | } | |
16145 | ||
16146 | /* Generate the prologue instructions for entry into an ARM or Thumb-2 | |
16147 | function. */ | |
e2c671ba | 16148 | void |
e32bac5b | 16149 | arm_expand_prologue (void) |
e2c671ba | 16150 | { |
6d3d9133 | 16151 | rtx amount; |
2c849145 | 16152 | rtx insn; |
68dfd979 | 16153 | rtx ip_rtx; |
6d3d9133 NC |
16154 | unsigned long live_regs_mask; |
16155 | unsigned long func_type; | |
68dfd979 | 16156 | int fp_offset = 0; |
095bb276 | 16157 | int saved_pretend_args = 0; |
5848830f | 16158 | int saved_regs = 0; |
b9705a21 | 16159 | unsigned HOST_WIDE_INT args_to_push; |
5848830f | 16160 | arm_stack_offsets *offsets; |
d3236b4d | 16161 | |
6d3d9133 | 16162 | func_type = arm_current_func_type (); |
e2c671ba | 16163 | |
31fdb4d5 | 16164 | /* Naked functions don't have prologues. */ |
6d3d9133 | 16165 | if (IS_NAKED (func_type)) |
31fdb4d5 DE |
16166 | return; |
16167 | ||
095bb276 | 16168 | /* Make a copy of c_f_p_a_s as we may need to modify it locally. */ |
38173d38 | 16169 | args_to_push = crtl->args.pretend_args_size; |
f676971a | 16170 | |
6d3d9133 | 16171 | /* Compute which register we will have to save onto the stack. */ |
954954d1 PB |
16172 | offsets = arm_get_frame_offsets (); |
16173 | live_regs_mask = offsets->saved_regs_mask; | |
e2c671ba | 16174 | |
68dfd979 | 16175 | ip_rtx = gen_rtx_REG (SImode, IP_REGNUM); |
d3236b4d | 16176 | |
5b3e6663 PB |
16177 | if (IS_STACKALIGN (func_type)) |
16178 | { | |
ddc6e7d6 RH |
16179 | rtx r0, r1; |
16180 | ||
5b3e6663 PB |
16181 | /* Handle a word-aligned stack pointer. We generate the following: |
16182 | ||
16183 | mov r0, sp | |
16184 | bic r1, r0, #7 | |
16185 | mov sp, r1 | |
16186 | <save and restore r0 in normal prologue/epilogue> | |
16187 | mov sp, r0 | |
16188 | bx lr | |
16189 | ||
16190 | The unwinder doesn't need to know about the stack realignment. | |
16191 | Just tell it we saved SP in r0. */ | |
16192 | gcc_assert (TARGET_THUMB2 && !arm_arch_notm && args_to_push == 0); | |
16193 | ||
16194 | r0 = gen_rtx_REG (SImode, 0); | |
16195 | r1 = gen_rtx_REG (SImode, 1); | |
ddc6e7d6 RH |
16196 | |
16197 | insn = emit_insn (gen_movsi (r0, stack_pointer_rtx)); | |
5b3e6663 | 16198 | RTX_FRAME_RELATED_P (insn) = 1; |
ddc6e7d6 RH |
16199 | add_reg_note (insn, REG_CFA_REGISTER, NULL); |
16200 | ||
5b3e6663 | 16201 | emit_insn (gen_andsi3 (r1, r0, GEN_INT (~(HOST_WIDE_INT)7))); |
ddc6e7d6 RH |
16202 | |
16203 | /* ??? The CFA changes here, which may cause GDB to conclude that it | |
16204 | has entered a different function. That said, the unwind info is | |
16205 | correct, individually, before and after this instruction because | |
16206 | we've described the save of SP, which will override the default | |
16207 | handling of SP as restoring from the CFA. */ | |
5b3e6663 PB |
16208 | emit_insn (gen_movsi (stack_pointer_rtx, r1)); |
16209 | } | |
16210 | ||
ec6237e4 PB |
16211 | /* For APCS frames, if IP register is clobbered |
16212 | when creating frame, save that register in a special | |
16213 | way. */ | |
16214 | if (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM) | |
e2c671ba | 16215 | { |
7b8b8ade NC |
16216 | if (IS_INTERRUPT (func_type)) |
16217 | { | |
16218 | /* Interrupt functions must not corrupt any registers. | |
16219 | Creating a frame pointer however, corrupts the IP | |
16220 | register, so we must push it first. */ | |
d018b46e | 16221 | emit_multi_reg_push (1 << IP_REGNUM); |
121308d4 NC |
16222 | |
16223 | /* Do not set RTX_FRAME_RELATED_P on this insn. | |
16224 | The dwarf stack unwinding code only wants to see one | |
16225 | stack decrement per function, and this is not it. If | |
16226 | this instruction is labeled as being part of the frame | |
16227 | creation sequence then dwarf2out_frame_debug_expr will | |
e6d29d15 | 16228 | die when it encounters the assignment of IP to FP |
121308d4 NC |
16229 | later on, since the use of SP here establishes SP as |
16230 | the CFA register and not IP. | |
16231 | ||
16232 | Anyway this instruction is not really part of the stack | |
16233 | frame creation although it is part of the prologue. */ | |
7b8b8ade NC |
16234 | } |
16235 | else if (IS_NESTED (func_type)) | |
68dfd979 NC |
16236 | { |
16237 | /* The Static chain register is the same as the IP register | |
16238 | used as a scratch register during stack frame creation. | |
16239 | To get around this need to find somewhere to store IP | |
16240 | whilst the frame is being created. We try the following | |
16241 | places in order: | |
f676971a | 16242 | |
6d3d9133 | 16243 | 1. The last argument register. |
68dfd979 NC |
16244 | 2. A slot on the stack above the frame. (This only |
16245 | works if the function is not a varargs function). | |
095bb276 NC |
16246 | 3. Register r3, after pushing the argument registers |
16247 | onto the stack. | |
6d3d9133 | 16248 | |
34ce3d7b JM |
16249 | Note - we only need to tell the dwarf2 backend about the SP |
16250 | adjustment in the second variant; the static chain register | |
16251 | doesn't need to be unwound, as it doesn't contain a value | |
16252 | inherited from the caller. */ | |
d3236b4d | 16253 | |
6fb5fa3c | 16254 | if (df_regs_ever_live_p (3) == false) |
d66437c5 | 16255 | insn = emit_set_insn (gen_rtx_REG (SImode, 3), ip_rtx); |
095bb276 | 16256 | else if (args_to_push == 0) |
68dfd979 | 16257 | { |
f0b4bdd5 RE |
16258 | rtx dwarf; |
16259 | ||
35596784 AJ |
16260 | gcc_assert(arm_compute_static_chain_stack_bytes() == 4); |
16261 | saved_regs += 4; | |
16262 | ||
d66437c5 RE |
16263 | insn = gen_rtx_PRE_DEC (SImode, stack_pointer_rtx); |
16264 | insn = emit_set_insn (gen_frame_mem (SImode, insn), ip_rtx); | |
68dfd979 | 16265 | fp_offset = 4; |
34ce3d7b JM |
16266 | |
16267 | /* Just tell the dwarf backend that we adjusted SP. */ | |
16268 | dwarf = gen_rtx_SET (VOIDmode, stack_pointer_rtx, | |
d66437c5 RE |
16269 | plus_constant (stack_pointer_rtx, |
16270 | -fp_offset)); | |
34ce3d7b | 16271 | RTX_FRAME_RELATED_P (insn) = 1; |
bbbbb16a | 16272 | add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
68dfd979 NC |
16273 | } |
16274 | else | |
095bb276 NC |
16275 | { |
16276 | /* Store the args on the stack. */ | |
3cb66fd7 | 16277 | if (cfun->machine->uses_anonymous_args) |
095bb276 NC |
16278 | insn = emit_multi_reg_push |
16279 | ((0xf0 >> (args_to_push / 4)) & 0xf); | |
16280 | else | |
16281 | insn = emit_insn | |
f676971a | 16282 | (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
095bb276 NC |
16283 | GEN_INT (- args_to_push))); |
16284 | ||
16285 | RTX_FRAME_RELATED_P (insn) = 1; | |
16286 | ||
16287 | saved_pretend_args = 1; | |
16288 | fp_offset = args_to_push; | |
16289 | args_to_push = 0; | |
16290 | ||
16291 | /* Now reuse r3 to preserve IP. */ | |
d66437c5 | 16292 | emit_set_insn (gen_rtx_REG (SImode, 3), ip_rtx); |
095bb276 | 16293 | } |
68dfd979 NC |
16294 | } |
16295 | ||
d66437c5 RE |
16296 | insn = emit_set_insn (ip_rtx, |
16297 | plus_constant (stack_pointer_rtx, fp_offset)); | |
8e56560e | 16298 | RTX_FRAME_RELATED_P (insn) = 1; |
e2c671ba RE |
16299 | } |
16300 | ||
095bb276 | 16301 | if (args_to_push) |
e2c671ba | 16302 | { |
6d3d9133 | 16303 | /* Push the argument registers, or reserve space for them. */ |
3cb66fd7 | 16304 | if (cfun->machine->uses_anonymous_args) |
2c849145 | 16305 | insn = emit_multi_reg_push |
095bb276 | 16306 | ((0xf0 >> (args_to_push / 4)) & 0xf); |
e2c671ba | 16307 | else |
2c849145 | 16308 | insn = emit_insn |
f676971a | 16309 | (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
095bb276 | 16310 | GEN_INT (- args_to_push))); |
2c849145 | 16311 | RTX_FRAME_RELATED_P (insn) = 1; |
e2c671ba RE |
16312 | } |
16313 | ||
06bea5aa | 16314 | /* If this is an interrupt service routine, and the link register |
ec6237e4 PB |
16315 | is going to be pushed, and we're not generating extra |
16316 | push of IP (needed when frame is needed and frame layout if apcs), | |
06bea5aa NC |
16317 | subtracting four from LR now will mean that the function return |
16318 | can be done with a single instruction. */ | |
3a7731fd | 16319 | if ((func_type == ARM_FT_ISR || func_type == ARM_FT_FIQ) |
06bea5aa | 16320 | && (live_regs_mask & (1 << LR_REGNUM)) != 0 |
ec6237e4 | 16321 | && !(frame_pointer_needed && TARGET_APCS_FRAME) |
a15908a4 | 16322 | && TARGET_ARM) |
d66437c5 RE |
16323 | { |
16324 | rtx lr = gen_rtx_REG (SImode, LR_REGNUM); | |
16325 | ||
16326 | emit_set_insn (lr, plus_constant (lr, -4)); | |
16327 | } | |
3a7731fd | 16328 | |
e2c671ba RE |
16329 | if (live_regs_mask) |
16330 | { | |
5848830f | 16331 | saved_regs += bit_count (live_regs_mask) * 4; |
954954d1 PB |
16332 | if (optimize_size && !frame_pointer_needed |
16333 | && saved_regs == offsets->saved_regs - offsets->saved_args) | |
16334 | { | |
16335 | /* If no coprocessor registers are being pushed and we don't have | |
16336 | to worry about a frame pointer then push extra registers to | |
16337 | create the stack frame. This is done is a way that does not | |
16338 | alter the frame layout, so is independent of the epilogue. */ | |
16339 | int n; | |
16340 | int frame; | |
16341 | n = 0; | |
16342 | while (n < 8 && (live_regs_mask & (1 << n)) == 0) | |
16343 | n++; | |
16344 | frame = offsets->outgoing_args - (offsets->saved_args + saved_regs); | |
16345 | if (frame && n * 4 >= frame) | |
16346 | { | |
16347 | n = frame / 4; | |
16348 | live_regs_mask |= (1 << n) - 1; | |
16349 | saved_regs += frame; | |
16350 | } | |
16351 | } | |
16352 | insn = emit_multi_reg_push (live_regs_mask); | |
2c849145 | 16353 | RTX_FRAME_RELATED_P (insn) = 1; |
e2c671ba | 16354 | } |
d5b7b3ae | 16355 | |
6d3d9133 | 16356 | if (! IS_VOLATILE (func_type)) |
5b3e6663 | 16357 | saved_regs += arm_save_coproc_regs (); |
b111229a | 16358 | |
5b3e6663 PB |
16359 | if (frame_pointer_needed && TARGET_ARM) |
16360 | { | |
16361 | /* Create the new frame pointer. */ | |
ec6237e4 | 16362 | if (TARGET_APCS_FRAME) |
9b66ebb1 | 16363 | { |
5b3e6663 PB |
16364 | insn = GEN_INT (-(4 + args_to_push + fp_offset)); |
16365 | insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, ip_rtx, insn)); | |
16366 | RTX_FRAME_RELATED_P (insn) = 1; | |
9b66ebb1 | 16367 | |
5b3e6663 | 16368 | if (IS_NESTED (func_type)) |
9b66ebb1 | 16369 | { |
5b3e6663 | 16370 | /* Recover the static chain register. */ |
6fb5fa3c | 16371 | if (!df_regs_ever_live_p (3) |
5b3e6663 PB |
16372 | || saved_pretend_args) |
16373 | insn = gen_rtx_REG (SImode, 3); | |
38173d38 | 16374 | else /* if (crtl->args.pretend_args_size == 0) */ |
9b66ebb1 | 16375 | { |
5b3e6663 PB |
16376 | insn = plus_constant (hard_frame_pointer_rtx, 4); |
16377 | insn = gen_frame_mem (SImode, insn); | |
9b66ebb1 | 16378 | } |
5b3e6663 PB |
16379 | emit_set_insn (ip_rtx, insn); |
16380 | /* Add a USE to stop propagate_one_insn() from barfing. */ | |
16381 | emit_insn (gen_prologue_use (ip_rtx)); | |
9b66ebb1 | 16382 | } |
68dfd979 | 16383 | } |
ec6237e4 PB |
16384 | else |
16385 | { | |
16386 | insn = GEN_INT (saved_regs - 4); | |
16387 | insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, | |
16388 | stack_pointer_rtx, insn)); | |
16389 | RTX_FRAME_RELATED_P (insn) = 1; | |
16390 | } | |
2c849145 | 16391 | } |
e2c671ba | 16392 | |
a11e0df4 | 16393 | if (flag_stack_usage_info) |
55256000 TK |
16394 | current_function_static_stack_size |
16395 | = offsets->outgoing_args - offsets->saved_args; | |
16396 | ||
5848830f | 16397 | if (offsets->outgoing_args != offsets->saved_args + saved_regs) |
e2c671ba | 16398 | { |
745b9093 JM |
16399 | /* This add can produce multiple insns for a large constant, so we |
16400 | need to get tricky. */ | |
16401 | rtx last = get_last_insn (); | |
5848830f PB |
16402 | |
16403 | amount = GEN_INT (offsets->saved_args + saved_regs | |
16404 | - offsets->outgoing_args); | |
16405 | ||
2c849145 JM |
16406 | insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
16407 | amount)); | |
745b9093 JM |
16408 | do |
16409 | { | |
16410 | last = last ? NEXT_INSN (last) : get_insns (); | |
16411 | RTX_FRAME_RELATED_P (last) = 1; | |
16412 | } | |
16413 | while (last != insn); | |
e04c2d6c RE |
16414 | |
16415 | /* If the frame pointer is needed, emit a special barrier that | |
16416 | will prevent the scheduler from moving stores to the frame | |
16417 | before the stack adjustment. */ | |
16418 | if (frame_pointer_needed) | |
3894f59e RE |
16419 | insn = emit_insn (gen_stack_tie (stack_pointer_rtx, |
16420 | hard_frame_pointer_rtx)); | |
e2c671ba RE |
16421 | } |
16422 | ||
876f13b0 | 16423 | |
5b3e6663 PB |
16424 | if (frame_pointer_needed && TARGET_THUMB2) |
16425 | thumb_set_frame_pointer (offsets); | |
16426 | ||
020a4035 | 16427 | if (flag_pic && arm_pic_register != INVALID_REGNUM) |
5b3e6663 PB |
16428 | { |
16429 | unsigned long mask; | |
16430 | ||
16431 | mask = live_regs_mask; | |
16432 | mask &= THUMB2_WORK_REGS; | |
16433 | if (!IS_NESTED (func_type)) | |
16434 | mask |= (1 << IP_REGNUM); | |
16435 | arm_load_pic_register (mask); | |
16436 | } | |
876f13b0 | 16437 | |
e2c671ba | 16438 | /* If we are profiling, make sure no instructions are scheduled before |
f5a1b0d2 | 16439 | the call to mcount. Similarly if the user has requested no |
74d9c39f DJ |
16440 | scheduling in the prolog. Similarly if we want non-call exceptions |
16441 | using the EABI unwinder, to prevent faulting instructions from being | |
16442 | swapped with a stack adjustment. */ | |
e3b5732b | 16443 | if (crtl->profile || !TARGET_SCHED_PROLOG |
d5fabb58 | 16444 | || (arm_except_unwind_info (&global_options) == UI_TARGET |
f0a0390e | 16445 | && cfun->can_throw_non_call_exceptions)) |
e2c671ba | 16446 | emit_insn (gen_blockage ()); |
6f7ebcbb NC |
16447 | |
16448 | /* If the link register is being kept alive, with the return address in it, | |
16449 | then make sure that it does not get reused by the ce2 pass. */ | |
16450 | if ((live_regs_mask & (1 << LR_REGNUM)) == 0) | |
6fb5fa3c | 16451 | cfun->machine->lr_save_eliminated = 1; |
e2c671ba | 16452 | } |
cce8749e | 16453 | \f |
5b3e6663 PB |
16454 | /* Print condition code to STREAM. Helper function for arm_print_operand. */ |
16455 | static void | |
16456 | arm_print_condition (FILE *stream) | |
16457 | { | |
16458 | if (arm_ccfsm_state == 3 || arm_ccfsm_state == 4) | |
16459 | { | |
16460 | /* Branch conversion is not implemented for Thumb-2. */ | |
16461 | if (TARGET_THUMB) | |
16462 | { | |
16463 | output_operand_lossage ("predicated Thumb instruction"); | |
16464 | return; | |
16465 | } | |
16466 | if (current_insn_predicate != NULL) | |
16467 | { | |
16468 | output_operand_lossage | |
16469 | ("predicated instruction in conditional sequence"); | |
16470 | return; | |
16471 | } | |
16472 | ||
16473 | fputs (arm_condition_codes[arm_current_cc], stream); | |
16474 | } | |
16475 | else if (current_insn_predicate) | |
16476 | { | |
16477 | enum arm_cond_code code; | |
16478 | ||
16479 | if (TARGET_THUMB1) | |
16480 | { | |
16481 | output_operand_lossage ("predicated Thumb instruction"); | |
16482 | return; | |
16483 | } | |
16484 | ||
16485 | code = get_arm_condition_code (current_insn_predicate); | |
16486 | fputs (arm_condition_codes[code], stream); | |
16487 | } | |
16488 | } | |
16489 | ||
16490 | ||
9997d19d RE |
16491 | /* If CODE is 'd', then the X is a condition operand and the instruction |
16492 | should only be executed if the condition is true. | |
ddd5a7c1 | 16493 | if CODE is 'D', then the X is a condition operand and the instruction |
9997d19d RE |
16494 | should only be executed if the condition is false: however, if the mode |
16495 | of the comparison is CCFPEmode, then always execute the instruction -- we | |
16496 | do this because in these circumstances !GE does not necessarily imply LT; | |
16497 | in these cases the instruction pattern will take care to make sure that | |
16498 | an instruction containing %d will follow, thereby undoing the effects of | |
ddd5a7c1 | 16499 | doing this instruction unconditionally. |
9997d19d RE |
16500 | If CODE is 'N' then X is a floating point operand that must be negated |
16501 | before output. | |
16502 | If CODE is 'B' then output a bitwise inverted value of X (a const int). | |
16503 | If X is a REG and CODE is `M', output a ldm/stm style multi-reg. */ | |
944442bb | 16504 | static void |
e32bac5b | 16505 | arm_print_operand (FILE *stream, rtx x, int code) |
9997d19d RE |
16506 | { |
16507 | switch (code) | |
16508 | { | |
16509 | case '@': | |
f3139301 | 16510 | fputs (ASM_COMMENT_START, stream); |
9997d19d RE |
16511 | return; |
16512 | ||
d5b7b3ae RE |
16513 | case '_': |
16514 | fputs (user_label_prefix, stream); | |
16515 | return; | |
f676971a | 16516 | |
9997d19d | 16517 | case '|': |
f3139301 | 16518 | fputs (REGISTER_PREFIX, stream); |
9997d19d RE |
16519 | return; |
16520 | ||
16521 | case '?': | |
5b3e6663 PB |
16522 | arm_print_condition (stream); |
16523 | return; | |
cca0a211 | 16524 | |
5b3e6663 PB |
16525 | case '(': |
16526 | /* Nothing in unified syntax, otherwise the current condition code. */ | |
16527 | if (!TARGET_UNIFIED_ASM) | |
16528 | arm_print_condition (stream); | |
16529 | break; | |
16530 | ||
16531 | case ')': | |
16532 | /* The current condition code in unified syntax, otherwise nothing. */ | |
16533 | if (TARGET_UNIFIED_ASM) | |
16534 | arm_print_condition (stream); | |
16535 | break; | |
16536 | ||
16537 | case '.': | |
16538 | /* The current condition code for a condition code setting instruction. | |
7a085dce | 16539 | Preceded by 's' in unified syntax, otherwise followed by 's'. */ |
5b3e6663 PB |
16540 | if (TARGET_UNIFIED_ASM) |
16541 | { | |
16542 | fputc('s', stream); | |
16543 | arm_print_condition (stream); | |
cca0a211 | 16544 | } |
5b3e6663 | 16545 | else |
cca0a211 | 16546 | { |
5b3e6663 PB |
16547 | arm_print_condition (stream); |
16548 | fputc('s', stream); | |
cca0a211 | 16549 | } |
9997d19d RE |
16550 | return; |
16551 | ||
5b3e6663 PB |
16552 | case '!': |
16553 | /* If the instruction is conditionally executed then print | |
16554 | the current condition code, otherwise print 's'. */ | |
16555 | gcc_assert (TARGET_THUMB2 && TARGET_UNIFIED_ASM); | |
16556 | if (current_insn_predicate) | |
16557 | arm_print_condition (stream); | |
16558 | else | |
16559 | fputc('s', stream); | |
16560 | break; | |
16561 | ||
88f77cba | 16562 | /* %# is a "break" sequence. It doesn't output anything, but is used to |
cea618ac | 16563 | separate e.g. operand numbers from following text, if that text consists |
88f77cba JB |
16564 | of further digits which we don't want to be part of the operand |
16565 | number. */ | |
16566 | case '#': | |
16567 | return; | |
16568 | ||
9997d19d RE |
16569 | case 'N': |
16570 | { | |
16571 | REAL_VALUE_TYPE r; | |
16572 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); | |
d49b6e1e | 16573 | r = real_value_negate (&r); |
9997d19d RE |
16574 | fprintf (stream, "%s", fp_const_from_val (&r)); |
16575 | } | |
16576 | return; | |
16577 | ||
571191af | 16578 | /* An integer or symbol address without a preceding # sign. */ |
88f77cba | 16579 | case 'c': |
571191af PB |
16580 | switch (GET_CODE (x)) |
16581 | { | |
16582 | case CONST_INT: | |
16583 | fprintf (stream, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); | |
16584 | break; | |
16585 | ||
16586 | case SYMBOL_REF: | |
16587 | output_addr_const (stream, x); | |
16588 | break; | |
16589 | ||
a1b5eb93 RE |
16590 | case CONST: |
16591 | if (GET_CODE (XEXP (x, 0)) == PLUS | |
16592 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF) | |
16593 | { | |
16594 | output_addr_const (stream, x); | |
16595 | break; | |
16596 | } | |
16597 | /* Fall through. */ | |
16598 | ||
571191af | 16599 | default: |
a1b5eb93 | 16600 | output_operand_lossage ("Unsupported operand for code '%c'", code); |
571191af | 16601 | } |
88f77cba JB |
16602 | return; |
16603 | ||
9997d19d RE |
16604 | case 'B': |
16605 | if (GET_CODE (x) == CONST_INT) | |
4bc74ece NC |
16606 | { |
16607 | HOST_WIDE_INT val; | |
5895f793 | 16608 | val = ARM_SIGN_EXTEND (~INTVAL (x)); |
36ba9cb8 | 16609 | fprintf (stream, HOST_WIDE_INT_PRINT_DEC, val); |
4bc74ece | 16610 | } |
9997d19d RE |
16611 | else |
16612 | { | |
16613 | putc ('~', stream); | |
16614 | output_addr_const (stream, x); | |
16615 | } | |
16616 | return; | |
16617 | ||
5b3e6663 PB |
16618 | case 'L': |
16619 | /* The low 16 bits of an immediate constant. */ | |
16620 | fprintf (stream, HOST_WIDE_INT_PRINT_DEC, INTVAL(x) & 0xffff); | |
16621 | return; | |
16622 | ||
9997d19d RE |
16623 | case 'i': |
16624 | fprintf (stream, "%s", arithmetic_instr (x, 1)); | |
16625 | return; | |
16626 | ||
9b6b54e2 NC |
16627 | /* Truncate Cirrus shift counts. */ |
16628 | case 's': | |
16629 | if (GET_CODE (x) == CONST_INT) | |
16630 | { | |
16631 | fprintf (stream, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x3f); | |
16632 | return; | |
16633 | } | |
16634 | arm_print_operand (stream, x, 0); | |
16635 | return; | |
16636 | ||
9997d19d RE |
16637 | case 'I': |
16638 | fprintf (stream, "%s", arithmetic_instr (x, 0)); | |
16639 | return; | |
16640 | ||
16641 | case 'S': | |
16642 | { | |
16643 | HOST_WIDE_INT val; | |
beed32b8 RE |
16644 | const char *shift; |
16645 | ||
16646 | if (!shift_operator (x, SImode)) | |
16647 | { | |
16648 | output_operand_lossage ("invalid shift operand"); | |
16649 | break; | |
16650 | } | |
16651 | ||
16652 | shift = shift_op (x, &val); | |
9997d19d | 16653 | |
e2c671ba RE |
16654 | if (shift) |
16655 | { | |
beed32b8 | 16656 | fprintf (stream, ", %s ", shift); |
e2c671ba RE |
16657 | if (val == -1) |
16658 | arm_print_operand (stream, XEXP (x, 1), 0); | |
16659 | else | |
4a0a75dd | 16660 | fprintf (stream, "#" HOST_WIDE_INT_PRINT_DEC, val); |
e2c671ba | 16661 | } |
9997d19d RE |
16662 | } |
16663 | return; | |
16664 | ||
d5b7b3ae | 16665 | /* An explanation of the 'Q', 'R' and 'H' register operands: |
f676971a | 16666 | |
d5b7b3ae RE |
16667 | In a pair of registers containing a DI or DF value the 'Q' |
16668 | operand returns the register number of the register containing | |
093354e0 | 16669 | the least significant part of the value. The 'R' operand returns |
d5b7b3ae RE |
16670 | the register number of the register containing the most |
16671 | significant part of the value. | |
f676971a | 16672 | |
d5b7b3ae RE |
16673 | The 'H' operand returns the higher of the two register numbers. |
16674 | On a run where WORDS_BIG_ENDIAN is true the 'H' operand is the | |
093354e0 | 16675 | same as the 'Q' operand, since the most significant part of the |
d5b7b3ae RE |
16676 | value is held in the lower number register. The reverse is true |
16677 | on systems where WORDS_BIG_ENDIAN is false. | |
f676971a | 16678 | |
d5b7b3ae RE |
16679 | The purpose of these operands is to distinguish between cases |
16680 | where the endian-ness of the values is important (for example | |
16681 | when they are added together), and cases where the endian-ness | |
16682 | is irrelevant, but the order of register operations is important. | |
16683 | For example when loading a value from memory into a register | |
16684 | pair, the endian-ness does not matter. Provided that the value | |
16685 | from the lower memory address is put into the lower numbered | |
16686 | register, and the value from the higher address is put into the | |
16687 | higher numbered register, the load will work regardless of whether | |
16688 | the value being loaded is big-wordian or little-wordian. The | |
16689 | order of the two register loads can matter however, if the address | |
16690 | of the memory location is actually held in one of the registers | |
73160ba9 DJ |
16691 | being overwritten by the load. |
16692 | ||
16693 | The 'Q' and 'R' constraints are also available for 64-bit | |
16694 | constants. */ | |
c1c2bc04 | 16695 | case 'Q': |
73160ba9 DJ |
16696 | if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) |
16697 | { | |
16698 | rtx part = gen_lowpart (SImode, x); | |
16699 | fprintf (stream, "#" HOST_WIDE_INT_PRINT_DEC, INTVAL (part)); | |
16700 | return; | |
16701 | } | |
16702 | ||
22de4c3d RE |
16703 | if (GET_CODE (x) != REG || REGNO (x) > LAST_ARM_REGNUM) |
16704 | { | |
16705 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16706 | return; | |
16707 | } | |
16708 | ||
d5b7b3ae | 16709 | asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 1 : 0)); |
c1c2bc04 RE |
16710 | return; |
16711 | ||
9997d19d | 16712 | case 'R': |
73160ba9 DJ |
16713 | if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) |
16714 | { | |
16715 | enum machine_mode mode = GET_MODE (x); | |
16716 | rtx part; | |
16717 | ||
16718 | if (mode == VOIDmode) | |
16719 | mode = DImode; | |
16720 | part = gen_highpart_mode (SImode, mode, x); | |
16721 | fprintf (stream, "#" HOST_WIDE_INT_PRINT_DEC, INTVAL (part)); | |
16722 | return; | |
16723 | } | |
16724 | ||
22de4c3d RE |
16725 | if (GET_CODE (x) != REG || REGNO (x) > LAST_ARM_REGNUM) |
16726 | { | |
16727 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16728 | return; | |
16729 | } | |
16730 | ||
d5b7b3ae RE |
16731 | asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 0 : 1)); |
16732 | return; | |
16733 | ||
16734 | case 'H': | |
22de4c3d RE |
16735 | if (GET_CODE (x) != REG || REGNO (x) > LAST_ARM_REGNUM) |
16736 | { | |
16737 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16738 | return; | |
16739 | } | |
16740 | ||
d5b7b3ae | 16741 | asm_fprintf (stream, "%r", REGNO (x) + 1); |
9997d19d RE |
16742 | return; |
16743 | ||
88f77cba JB |
16744 | case 'J': |
16745 | if (GET_CODE (x) != REG || REGNO (x) > LAST_ARM_REGNUM) | |
16746 | { | |
16747 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16748 | return; | |
16749 | } | |
16750 | ||
16751 | asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 3 : 2)); | |
16752 | return; | |
16753 | ||
16754 | case 'K': | |
16755 | if (GET_CODE (x) != REG || REGNO (x) > LAST_ARM_REGNUM) | |
16756 | { | |
16757 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16758 | return; | |
16759 | } | |
16760 | ||
16761 | asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 2 : 3)); | |
16762 | return; | |
16763 | ||
9997d19d | 16764 | case 'm': |
f676971a | 16765 | asm_fprintf (stream, "%r", |
d5b7b3ae RE |
16766 | GET_CODE (XEXP (x, 0)) == REG |
16767 | ? REGNO (XEXP (x, 0)) : REGNO (XEXP (XEXP (x, 0), 0))); | |
9997d19d RE |
16768 | return; |
16769 | ||
16770 | case 'M': | |
dd18ae56 | 16771 | asm_fprintf (stream, "{%r-%r}", |
d5b7b3ae | 16772 | REGNO (x), |
e9d7b180 | 16773 | REGNO (x) + ARM_NUM_REGS (GET_MODE (x)) - 1); |
9997d19d RE |
16774 | return; |
16775 | ||
88f77cba JB |
16776 | /* Like 'M', but writing doubleword vector registers, for use by Neon |
16777 | insns. */ | |
16778 | case 'h': | |
16779 | { | |
16780 | int regno = (REGNO (x) - FIRST_VFP_REGNUM) / 2; | |
16781 | int numregs = ARM_NUM_REGS (GET_MODE (x)) / 2; | |
16782 | if (numregs == 1) | |
16783 | asm_fprintf (stream, "{d%d}", regno); | |
16784 | else | |
16785 | asm_fprintf (stream, "{d%d-d%d}", regno, regno + numregs - 1); | |
16786 | } | |
16787 | return; | |
16788 | ||
9997d19d | 16789 | case 'd': |
64e92a26 RE |
16790 | /* CONST_TRUE_RTX means always -- that's the default. */ |
16791 | if (x == const_true_rtx) | |
d5b7b3ae | 16792 | return; |
f676971a | 16793 | |
22de4c3d RE |
16794 | if (!COMPARISON_P (x)) |
16795 | { | |
16796 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16797 | return; | |
16798 | } | |
16799 | ||
defc0463 RE |
16800 | fputs (arm_condition_codes[get_arm_condition_code (x)], |
16801 | stream); | |
9997d19d RE |
16802 | return; |
16803 | ||
16804 | case 'D': | |
112cdef5 | 16805 | /* CONST_TRUE_RTX means not always -- i.e. never. We shouldn't ever |
64e92a26 RE |
16806 | want to do that. */ |
16807 | if (x == const_true_rtx) | |
22de4c3d | 16808 | { |
4dad0aca | 16809 | output_operand_lossage ("instruction never executed"); |
22de4c3d RE |
16810 | return; |
16811 | } | |
16812 | if (!COMPARISON_P (x)) | |
16813 | { | |
16814 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16815 | return; | |
16816 | } | |
d5b7b3ae | 16817 | |
defc0463 RE |
16818 | fputs (arm_condition_codes[ARM_INVERSE_CONDITION_CODE |
16819 | (get_arm_condition_code (x))], | |
16820 | stream); | |
9997d19d RE |
16821 | return; |
16822 | ||
9b6b54e2 NC |
16823 | /* Cirrus registers can be accessed in a variety of ways: |
16824 | single floating point (f) | |
16825 | double floating point (d) | |
16826 | 32bit integer (fx) | |
16827 | 64bit integer (dx). */ | |
16828 | case 'W': /* Cirrus register in F mode. */ | |
16829 | case 'X': /* Cirrus register in D mode. */ | |
16830 | case 'Y': /* Cirrus register in FX mode. */ | |
16831 | case 'Z': /* Cirrus register in DX mode. */ | |
e6d29d15 NS |
16832 | gcc_assert (GET_CODE (x) == REG |
16833 | && REGNO_REG_CLASS (REGNO (x)) == CIRRUS_REGS); | |
9b6b54e2 NC |
16834 | |
16835 | fprintf (stream, "mv%s%s", | |
16836 | code == 'W' ? "f" | |
16837 | : code == 'X' ? "d" | |
16838 | : code == 'Y' ? "fx" : "dx", reg_names[REGNO (x)] + 2); | |
16839 | ||
16840 | return; | |
16841 | ||
16842 | /* Print cirrus register in the mode specified by the register's mode. */ | |
16843 | case 'V': | |
16844 | { | |
16845 | int mode = GET_MODE (x); | |
16846 | ||
16847 | if (GET_CODE (x) != REG || REGNO_REG_CLASS (REGNO (x)) != CIRRUS_REGS) | |
22de4c3d RE |
16848 | { |
16849 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16850 | return; | |
16851 | } | |
9b6b54e2 NC |
16852 | |
16853 | fprintf (stream, "mv%s%s", | |
16854 | mode == DFmode ? "d" | |
16855 | : mode == SImode ? "fx" | |
16856 | : mode == DImode ? "dx" | |
16857 | : "f", reg_names[REGNO (x)] + 2); | |
16858 | ||
16859 | return; | |
16860 | } | |
16861 | ||
5a9335ef NC |
16862 | case 'U': |
16863 | if (GET_CODE (x) != REG | |
16864 | || REGNO (x) < FIRST_IWMMXT_GR_REGNUM | |
16865 | || REGNO (x) > LAST_IWMMXT_GR_REGNUM) | |
16866 | /* Bad value for wCG register number. */ | |
22de4c3d RE |
16867 | { |
16868 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16869 | return; | |
16870 | } | |
16871 | ||
5a9335ef NC |
16872 | else |
16873 | fprintf (stream, "%d", REGNO (x) - FIRST_IWMMXT_GR_REGNUM); | |
16874 | return; | |
16875 | ||
16876 | /* Print an iWMMXt control register name. */ | |
16877 | case 'w': | |
16878 | if (GET_CODE (x) != CONST_INT | |
16879 | || INTVAL (x) < 0 | |
16880 | || INTVAL (x) >= 16) | |
16881 | /* Bad value for wC register number. */ | |
22de4c3d RE |
16882 | { |
16883 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16884 | return; | |
16885 | } | |
16886 | ||
5a9335ef NC |
16887 | else |
16888 | { | |
16889 | static const char * wc_reg_names [16] = | |
16890 | { | |
16891 | "wCID", "wCon", "wCSSF", "wCASF", | |
16892 | "wC4", "wC5", "wC6", "wC7", | |
16893 | "wCGR0", "wCGR1", "wCGR2", "wCGR3", | |
16894 | "wC12", "wC13", "wC14", "wC15" | |
16895 | }; | |
f676971a | 16896 | |
5a9335ef NC |
16897 | fprintf (stream, wc_reg_names [INTVAL (x)]); |
16898 | } | |
16899 | return; | |
16900 | ||
e0dc3601 PB |
16901 | /* Print the high single-precision register of a VFP double-precision |
16902 | register. */ | |
16903 | case 'p': | |
16904 | { | |
16905 | int mode = GET_MODE (x); | |
16906 | int regno; | |
16907 | ||
16908 | if (GET_MODE_SIZE (mode) != 8 || GET_CODE (x) != REG) | |
16909 | { | |
16910 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16911 | return; | |
16912 | } | |
16913 | ||
16914 | regno = REGNO (x); | |
16915 | if (!VFP_REGNO_OK_FOR_DOUBLE (regno)) | |
16916 | { | |
16917 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16918 | return; | |
16919 | } | |
16920 | ||
16921 | fprintf (stream, "s%d", regno - FIRST_VFP_REGNUM + 1); | |
16922 | } | |
16923 | return; | |
16924 | ||
88f77cba | 16925 | /* Print a VFP/Neon double precision or quad precision register name. */ |
9b66ebb1 | 16926 | case 'P': |
88f77cba | 16927 | case 'q': |
9b66ebb1 PB |
16928 | { |
16929 | int mode = GET_MODE (x); | |
88f77cba JB |
16930 | int is_quad = (code == 'q'); |
16931 | int regno; | |
9b66ebb1 | 16932 | |
88f77cba | 16933 | if (GET_MODE_SIZE (mode) != (is_quad ? 16 : 8)) |
22de4c3d RE |
16934 | { |
16935 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16936 | return; | |
16937 | } | |
9b66ebb1 PB |
16938 | |
16939 | if (GET_CODE (x) != REG | |
16940 | || !IS_VFP_REGNUM (REGNO (x))) | |
22de4c3d RE |
16941 | { |
16942 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16943 | return; | |
16944 | } | |
9b66ebb1 | 16945 | |
88f77cba JB |
16946 | regno = REGNO (x); |
16947 | if ((is_quad && !NEON_REGNO_OK_FOR_QUAD (regno)) | |
16948 | || (!is_quad && !VFP_REGNO_OK_FOR_DOUBLE (regno))) | |
22de4c3d RE |
16949 | { |
16950 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16951 | return; | |
16952 | } | |
9b66ebb1 | 16953 | |
88f77cba JB |
16954 | fprintf (stream, "%c%d", is_quad ? 'q' : 'd', |
16955 | (regno - FIRST_VFP_REGNUM) >> (is_quad ? 2 : 1)); | |
16956 | } | |
16957 | return; | |
16958 | ||
16959 | /* These two codes print the low/high doubleword register of a Neon quad | |
16960 | register, respectively. For pair-structure types, can also print | |
16961 | low/high quadword registers. */ | |
16962 | case 'e': | |
16963 | case 'f': | |
16964 | { | |
16965 | int mode = GET_MODE (x); | |
16966 | int regno; | |
16967 | ||
16968 | if ((GET_MODE_SIZE (mode) != 16 | |
16969 | && GET_MODE_SIZE (mode) != 32) || GET_CODE (x) != REG) | |
16970 | { | |
16971 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16972 | return; | |
16973 | } | |
16974 | ||
16975 | regno = REGNO (x); | |
16976 | if (!NEON_REGNO_OK_FOR_QUAD (regno)) | |
16977 | { | |
16978 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16979 | return; | |
16980 | } | |
16981 | ||
16982 | if (GET_MODE_SIZE (mode) == 16) | |
16983 | fprintf (stream, "d%d", ((regno - FIRST_VFP_REGNUM) >> 1) | |
16984 | + (code == 'f' ? 1 : 0)); | |
16985 | else | |
16986 | fprintf (stream, "q%d", ((regno - FIRST_VFP_REGNUM) >> 2) | |
16987 | + (code == 'f' ? 1 : 0)); | |
9b66ebb1 PB |
16988 | } |
16989 | return; | |
16990 | ||
f1adb0a9 JB |
16991 | /* Print a VFPv3 floating-point constant, represented as an integer |
16992 | index. */ | |
16993 | case 'G': | |
16994 | { | |
16995 | int index = vfp3_const_double_index (x); | |
16996 | gcc_assert (index != -1); | |
16997 | fprintf (stream, "%d", index); | |
16998 | } | |
16999 | return; | |
17000 | ||
88f77cba JB |
17001 | /* Print bits representing opcode features for Neon. |
17002 | ||
17003 | Bit 0 is 1 for signed, 0 for unsigned. Floats count as signed | |
17004 | and polynomials as unsigned. | |
17005 | ||
17006 | Bit 1 is 1 for floats and polynomials, 0 for ordinary integers. | |
17007 | ||
17008 | Bit 2 is 1 for rounding functions, 0 otherwise. */ | |
17009 | ||
17010 | /* Identify the type as 's', 'u', 'p' or 'f'. */ | |
17011 | case 'T': | |
17012 | { | |
17013 | HOST_WIDE_INT bits = INTVAL (x); | |
17014 | fputc ("uspf"[bits & 3], stream); | |
17015 | } | |
17016 | return; | |
17017 | ||
17018 | /* Likewise, but signed and unsigned integers are both 'i'. */ | |
17019 | case 'F': | |
17020 | { | |
17021 | HOST_WIDE_INT bits = INTVAL (x); | |
17022 | fputc ("iipf"[bits & 3], stream); | |
17023 | } | |
17024 | return; | |
17025 | ||
17026 | /* As for 'T', but emit 'u' instead of 'p'. */ | |
17027 | case 't': | |
17028 | { | |
17029 | HOST_WIDE_INT bits = INTVAL (x); | |
17030 | fputc ("usuf"[bits & 3], stream); | |
17031 | } | |
17032 | return; | |
17033 | ||
17034 | /* Bit 2: rounding (vs none). */ | |
17035 | case 'O': | |
17036 | { | |
17037 | HOST_WIDE_INT bits = INTVAL (x); | |
17038 | fputs ((bits & 4) != 0 ? "r" : "", stream); | |
17039 | } | |
17040 | return; | |
17041 | ||
dc34db56 PB |
17042 | /* Memory operand for vld1/vst1 instruction. */ |
17043 | case 'A': | |
17044 | { | |
17045 | rtx addr; | |
17046 | bool postinc = FALSE; | |
6308e208 | 17047 | unsigned align, memsize, align_bits; |
c452684d | 17048 | |
dc34db56 PB |
17049 | gcc_assert (GET_CODE (x) == MEM); |
17050 | addr = XEXP (x, 0); | |
17051 | if (GET_CODE (addr) == POST_INC) | |
17052 | { | |
17053 | postinc = 1; | |
17054 | addr = XEXP (addr, 0); | |
17055 | } | |
c452684d JB |
17056 | asm_fprintf (stream, "[%r", REGNO (addr)); |
17057 | ||
17058 | /* We know the alignment of this access, so we can emit a hint in the | |
17059 | instruction (for some alignments) as an aid to the memory subsystem | |
17060 | of the target. */ | |
17061 | align = MEM_ALIGN (x) >> 3; | |
f5541398 | 17062 | memsize = MEM_SIZE (x); |
c452684d JB |
17063 | |
17064 | /* Only certain alignment specifiers are supported by the hardware. */ | |
6308e208 | 17065 | if (memsize == 16 && (align % 32) == 0) |
c452684d | 17066 | align_bits = 256; |
6308e208 | 17067 | else if ((memsize == 8 || memsize == 16) && (align % 16) == 0) |
c452684d JB |
17068 | align_bits = 128; |
17069 | else if ((align % 8) == 0) | |
17070 | align_bits = 64; | |
17071 | else | |
17072 | align_bits = 0; | |
17073 | ||
17074 | if (align_bits != 0) | |
17075 | asm_fprintf (stream, ":%d", align_bits); | |
17076 | ||
17077 | asm_fprintf (stream, "]"); | |
17078 | ||
dc34db56 PB |
17079 | if (postinc) |
17080 | fputs("!", stream); | |
17081 | } | |
17082 | return; | |
17083 | ||
029e79eb MS |
17084 | case 'C': |
17085 | { | |
17086 | rtx addr; | |
17087 | ||
17088 | gcc_assert (GET_CODE (x) == MEM); | |
17089 | addr = XEXP (x, 0); | |
17090 | gcc_assert (GET_CODE (addr) == REG); | |
17091 | asm_fprintf (stream, "[%r]", REGNO (addr)); | |
17092 | } | |
17093 | return; | |
17094 | ||
814a4c3b DJ |
17095 | /* Translate an S register number into a D register number and element index. */ |
17096 | case 'y': | |
17097 | { | |
17098 | int mode = GET_MODE (x); | |
17099 | int regno; | |
17100 | ||
17101 | if (GET_MODE_SIZE (mode) != 4 || GET_CODE (x) != REG) | |
17102 | { | |
17103 | output_operand_lossage ("invalid operand for code '%c'", code); | |
17104 | return; | |
17105 | } | |
17106 | ||
17107 | regno = REGNO (x); | |
17108 | if (!VFP_REGNO_OK_FOR_SINGLE (regno)) | |
17109 | { | |
17110 | output_operand_lossage ("invalid operand for code '%c'", code); | |
17111 | return; | |
17112 | } | |
17113 | ||
17114 | regno = regno - FIRST_VFP_REGNUM; | |
17115 | fprintf (stream, "d%d[%d]", regno / 2, regno % 2); | |
17116 | } | |
17117 | return; | |
17118 | ||
0fd8c3ad SL |
17119 | /* Register specifier for vld1.16/vst1.16. Translate the S register |
17120 | number into a D register number and element index. */ | |
17121 | case 'z': | |
17122 | { | |
17123 | int mode = GET_MODE (x); | |
17124 | int regno; | |
17125 | ||
17126 | if (GET_MODE_SIZE (mode) != 2 || GET_CODE (x) != REG) | |
17127 | { | |
17128 | output_operand_lossage ("invalid operand for code '%c'", code); | |
17129 | return; | |
17130 | } | |
17131 | ||
17132 | regno = REGNO (x); | |
17133 | if (!VFP_REGNO_OK_FOR_SINGLE (regno)) | |
17134 | { | |
17135 | output_operand_lossage ("invalid operand for code '%c'", code); | |
17136 | return; | |
17137 | } | |
17138 | ||
17139 | regno = regno - FIRST_VFP_REGNUM; | |
17140 | fprintf (stream, "d%d[%d]", regno/2, ((regno % 2) ? 2 : 0)); | |
17141 | } | |
17142 | return; | |
17143 | ||
9997d19d RE |
17144 | default: |
17145 | if (x == 0) | |
22de4c3d RE |
17146 | { |
17147 | output_operand_lossage ("missing operand"); | |
17148 | return; | |
17149 | } | |
9997d19d | 17150 | |
e6d29d15 | 17151 | switch (GET_CODE (x)) |
9997d19d | 17152 | { |
e6d29d15 NS |
17153 | case REG: |
17154 | asm_fprintf (stream, "%r", REGNO (x)); | |
17155 | break; | |
17156 | ||
17157 | case MEM: | |
9997d19d RE |
17158 | output_memory_reference_mode = GET_MODE (x); |
17159 | output_address (XEXP (x, 0)); | |
e6d29d15 NS |
17160 | break; |
17161 | ||
17162 | case CONST_DOUBLE: | |
88f77cba JB |
17163 | if (TARGET_NEON) |
17164 | { | |
17165 | char fpstr[20]; | |
17166 | real_to_decimal (fpstr, CONST_DOUBLE_REAL_VALUE (x), | |
17167 | sizeof (fpstr), 0, 1); | |
17168 | fprintf (stream, "#%s", fpstr); | |
17169 | } | |
17170 | else | |
17171 | fprintf (stream, "#%s", fp_immediate_constant (x)); | |
e6d29d15 NS |
17172 | break; |
17173 | ||
17174 | default: | |
17175 | gcc_assert (GET_CODE (x) != NEG); | |
9997d19d | 17176 | fputc ('#', stream); |
d58bc084 NS |
17177 | if (GET_CODE (x) == HIGH) |
17178 | { | |
17179 | fputs (":lower16:", stream); | |
17180 | x = XEXP (x, 0); | |
17181 | } | |
17182 | ||
9997d19d | 17183 | output_addr_const (stream, x); |
e6d29d15 | 17184 | break; |
9997d19d RE |
17185 | } |
17186 | } | |
17187 | } | |
cce8749e | 17188 | \f |
944442bb NF |
17189 | /* Target hook for printing a memory address. */ |
17190 | static void | |
17191 | arm_print_operand_address (FILE *stream, rtx x) | |
17192 | { | |
17193 | if (TARGET_32BIT) | |
17194 | { | |
17195 | int is_minus = GET_CODE (x) == MINUS; | |
17196 | ||
17197 | if (GET_CODE (x) == REG) | |
17198 | asm_fprintf (stream, "[%r, #0]", REGNO (x)); | |
17199 | else if (GET_CODE (x) == PLUS || is_minus) | |
17200 | { | |
17201 | rtx base = XEXP (x, 0); | |
17202 | rtx index = XEXP (x, 1); | |
17203 | HOST_WIDE_INT offset = 0; | |
17204 | if (GET_CODE (base) != REG | |
17205 | || (GET_CODE (index) == REG && REGNO (index) == SP_REGNUM)) | |
17206 | { | |
17207 | /* Ensure that BASE is a register. */ | |
17208 | /* (one of them must be). */ | |
17209 | /* Also ensure the SP is not used as in index register. */ | |
17210 | rtx temp = base; | |
17211 | base = index; | |
17212 | index = temp; | |
17213 | } | |
17214 | switch (GET_CODE (index)) | |
17215 | { | |
17216 | case CONST_INT: | |
17217 | offset = INTVAL (index); | |
17218 | if (is_minus) | |
17219 | offset = -offset; | |
17220 | asm_fprintf (stream, "[%r, #%wd]", | |
17221 | REGNO (base), offset); | |
17222 | break; | |
17223 | ||
17224 | case REG: | |
17225 | asm_fprintf (stream, "[%r, %s%r]", | |
17226 | REGNO (base), is_minus ? "-" : "", | |
17227 | REGNO (index)); | |
17228 | break; | |
17229 | ||
17230 | case MULT: | |
17231 | case ASHIFTRT: | |
17232 | case LSHIFTRT: | |
17233 | case ASHIFT: | |
17234 | case ROTATERT: | |
17235 | { | |
17236 | asm_fprintf (stream, "[%r, %s%r", | |
17237 | REGNO (base), is_minus ? "-" : "", | |
17238 | REGNO (XEXP (index, 0))); | |
17239 | arm_print_operand (stream, index, 'S'); | |
17240 | fputs ("]", stream); | |
17241 | break; | |
17242 | } | |
17243 | ||
17244 | default: | |
17245 | gcc_unreachable (); | |
17246 | } | |
17247 | } | |
17248 | else if (GET_CODE (x) == PRE_INC || GET_CODE (x) == POST_INC | |
17249 | || GET_CODE (x) == PRE_DEC || GET_CODE (x) == POST_DEC) | |
17250 | { | |
17251 | extern enum machine_mode output_memory_reference_mode; | |
17252 | ||
17253 | gcc_assert (GET_CODE (XEXP (x, 0)) == REG); | |
17254 | ||
17255 | if (GET_CODE (x) == PRE_DEC || GET_CODE (x) == PRE_INC) | |
17256 | asm_fprintf (stream, "[%r, #%s%d]!", | |
17257 | REGNO (XEXP (x, 0)), | |
17258 | GET_CODE (x) == PRE_DEC ? "-" : "", | |
17259 | GET_MODE_SIZE (output_memory_reference_mode)); | |
17260 | else | |
17261 | asm_fprintf (stream, "[%r], #%s%d", | |
17262 | REGNO (XEXP (x, 0)), | |
17263 | GET_CODE (x) == POST_DEC ? "-" : "", | |
17264 | GET_MODE_SIZE (output_memory_reference_mode)); | |
17265 | } | |
17266 | else if (GET_CODE (x) == PRE_MODIFY) | |
17267 | { | |
17268 | asm_fprintf (stream, "[%r, ", REGNO (XEXP (x, 0))); | |
17269 | if (GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT) | |
17270 | asm_fprintf (stream, "#%wd]!", | |
17271 | INTVAL (XEXP (XEXP (x, 1), 1))); | |
17272 | else | |
17273 | asm_fprintf (stream, "%r]!", | |
17274 | REGNO (XEXP (XEXP (x, 1), 1))); | |
17275 | } | |
17276 | else if (GET_CODE (x) == POST_MODIFY) | |
17277 | { | |
17278 | asm_fprintf (stream, "[%r], ", REGNO (XEXP (x, 0))); | |
17279 | if (GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT) | |
17280 | asm_fprintf (stream, "#%wd", | |
17281 | INTVAL (XEXP (XEXP (x, 1), 1))); | |
17282 | else | |
17283 | asm_fprintf (stream, "%r", | |
17284 | REGNO (XEXP (XEXP (x, 1), 1))); | |
17285 | } | |
17286 | else output_addr_const (stream, x); | |
17287 | } | |
17288 | else | |
17289 | { | |
17290 | if (GET_CODE (x) == REG) | |
17291 | asm_fprintf (stream, "[%r]", REGNO (x)); | |
17292 | else if (GET_CODE (x) == POST_INC) | |
17293 | asm_fprintf (stream, "%r!", REGNO (XEXP (x, 0))); | |
17294 | else if (GET_CODE (x) == PLUS) | |
17295 | { | |
17296 | gcc_assert (GET_CODE (XEXP (x, 0)) == REG); | |
17297 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
17298 | asm_fprintf (stream, "[%r, #%wd]", | |
17299 | REGNO (XEXP (x, 0)), | |
17300 | INTVAL (XEXP (x, 1))); | |
17301 | else | |
17302 | asm_fprintf (stream, "[%r, %r]", | |
17303 | REGNO (XEXP (x, 0)), | |
17304 | REGNO (XEXP (x, 1))); | |
17305 | } | |
17306 | else | |
17307 | output_addr_const (stream, x); | |
17308 | } | |
17309 | } | |
17310 | \f | |
17311 | /* Target hook for indicating whether a punctuation character for | |
17312 | TARGET_PRINT_OPERAND is valid. */ | |
17313 | static bool | |
17314 | arm_print_operand_punct_valid_p (unsigned char code) | |
17315 | { | |
17316 | return (code == '@' || code == '|' || code == '.' | |
17317 | || code == '(' || code == ')' || code == '#' | |
17318 | || (TARGET_32BIT && (code == '?')) | |
17319 | || (TARGET_THUMB2 && (code == '!')) | |
17320 | || (TARGET_THUMB && (code == '_'))); | |
17321 | } | |
17322 | \f | |
301d03af RS |
17323 | /* Target hook for assembling integer objects. The ARM version needs to |
17324 | handle word-sized values specially. */ | |
301d03af | 17325 | static bool |
e32bac5b | 17326 | arm_assemble_integer (rtx x, unsigned int size, int aligned_p) |
301d03af | 17327 | { |
88f77cba JB |
17328 | enum machine_mode mode; |
17329 | ||
301d03af RS |
17330 | if (size == UNITS_PER_WORD && aligned_p) |
17331 | { | |
17332 | fputs ("\t.word\t", asm_out_file); | |
17333 | output_addr_const (asm_out_file, x); | |
17334 | ||
17335 | /* Mark symbols as position independent. We only do this in the | |
d6b4baa4 | 17336 | .text segment, not in the .data segment. */ |
301d03af RS |
17337 | if (NEED_GOT_RELOC && flag_pic && making_const_table && |
17338 | (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)) | |
17339 | { | |
9403b7f7 RS |
17340 | /* See legitimize_pic_address for an explanation of the |
17341 | TARGET_VXWORKS_RTP check. */ | |
17342 | if (TARGET_VXWORKS_RTP | |
17343 | || (GET_CODE (x) == SYMBOL_REF && !SYMBOL_REF_LOCAL_P (x))) | |
301d03af | 17344 | fputs ("(GOT)", asm_out_file); |
9403b7f7 RS |
17345 | else |
17346 | fputs ("(GOTOFF)", asm_out_file); | |
301d03af RS |
17347 | } |
17348 | fputc ('\n', asm_out_file); | |
17349 | return true; | |
17350 | } | |
1d6e90ac | 17351 | |
88f77cba JB |
17352 | mode = GET_MODE (x); |
17353 | ||
17354 | if (arm_vector_mode_supported_p (mode)) | |
5a9335ef NC |
17355 | { |
17356 | int i, units; | |
17357 | ||
e6d29d15 | 17358 | gcc_assert (GET_CODE (x) == CONST_VECTOR); |
5a9335ef NC |
17359 | |
17360 | units = CONST_VECTOR_NUNITS (x); | |
88f77cba | 17361 | size = GET_MODE_SIZE (GET_MODE_INNER (mode)); |
5a9335ef | 17362 | |
88f77cba JB |
17363 | if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) |
17364 | for (i = 0; i < units; i++) | |
17365 | { | |
874d42b9 | 17366 | rtx elt = CONST_VECTOR_ELT (x, i); |
88f77cba JB |
17367 | assemble_integer |
17368 | (elt, size, i == 0 ? BIGGEST_ALIGNMENT : size * BITS_PER_UNIT, 1); | |
17369 | } | |
17370 | else | |
17371 | for (i = 0; i < units; i++) | |
17372 | { | |
17373 | rtx elt = CONST_VECTOR_ELT (x, i); | |
17374 | REAL_VALUE_TYPE rval; | |
5a9335ef | 17375 | |
88f77cba JB |
17376 | REAL_VALUE_FROM_CONST_DOUBLE (rval, elt); |
17377 | ||
17378 | assemble_real | |
17379 | (rval, GET_MODE_INNER (mode), | |
17380 | i == 0 ? BIGGEST_ALIGNMENT : size * BITS_PER_UNIT); | |
17381 | } | |
5a9335ef NC |
17382 | |
17383 | return true; | |
17384 | } | |
17385 | ||
301d03af RS |
17386 | return default_assemble_integer (x, size, aligned_p); |
17387 | } | |
7abc66b1 | 17388 | |
7abc66b1 | 17389 | static void |
9f296620 | 17390 | arm_elf_asm_cdtor (rtx symbol, int priority, bool is_ctor) |
7abc66b1 | 17391 | { |
50603eed PB |
17392 | section *s; |
17393 | ||
7abc66b1 JB |
17394 | if (!TARGET_AAPCS_BASED) |
17395 | { | |
9f296620 MM |
17396 | (is_ctor ? |
17397 | default_named_section_asm_out_constructor | |
17398 | : default_named_section_asm_out_destructor) (symbol, priority); | |
7abc66b1 JB |
17399 | return; |
17400 | } | |
17401 | ||
17402 | /* Put these in the .init_array section, using a special relocation. */ | |
50603eed PB |
17403 | if (priority != DEFAULT_INIT_PRIORITY) |
17404 | { | |
17405 | char buf[18]; | |
9f296620 MM |
17406 | sprintf (buf, "%s.%.5u", |
17407 | is_ctor ? ".init_array" : ".fini_array", | |
17408 | priority); | |
50603eed PB |
17409 | s = get_section (buf, SECTION_WRITE, NULL_TREE); |
17410 | } | |
9f296620 | 17411 | else if (is_ctor) |
50603eed | 17412 | s = ctors_section; |
9f296620 MM |
17413 | else |
17414 | s = dtors_section; | |
50603eed PB |
17415 | |
17416 | switch_to_section (s); | |
7abc66b1 JB |
17417 | assemble_align (POINTER_SIZE); |
17418 | fputs ("\t.word\t", asm_out_file); | |
17419 | output_addr_const (asm_out_file, symbol); | |
17420 | fputs ("(target1)\n", asm_out_file); | |
17421 | } | |
9f296620 MM |
17422 | |
17423 | /* Add a function to the list of static constructors. */ | |
17424 | ||
17425 | static void | |
17426 | arm_elf_asm_constructor (rtx symbol, int priority) | |
17427 | { | |
17428 | arm_elf_asm_cdtor (symbol, priority, /*is_ctor=*/true); | |
17429 | } | |
17430 | ||
17431 | /* Add a function to the list of static destructors. */ | |
17432 | ||
17433 | static void | |
17434 | arm_elf_asm_destructor (rtx symbol, int priority) | |
17435 | { | |
17436 | arm_elf_asm_cdtor (symbol, priority, /*is_ctor=*/false); | |
17437 | } | |
301d03af | 17438 | \f |
cce8749e CH |
17439 | /* A finite state machine takes care of noticing whether or not instructions |
17440 | can be conditionally executed, and thus decrease execution time and code | |
17441 | size by deleting branch instructions. The fsm is controlled by | |
17442 | final_prescan_insn, and controls the actions of ASM_OUTPUT_OPCODE. */ | |
17443 | ||
17444 | /* The state of the fsm controlling condition codes are: | |
17445 | 0: normal, do nothing special | |
17446 | 1: make ASM_OUTPUT_OPCODE not output this instruction | |
17447 | 2: make ASM_OUTPUT_OPCODE not output this instruction | |
17448 | 3: make instructions conditional | |
17449 | 4: make instructions conditional | |
17450 | ||
17451 | State transitions (state->state by whom under condition): | |
17452 | 0 -> 1 final_prescan_insn if the `target' is a label | |
17453 | 0 -> 2 final_prescan_insn if the `target' is an unconditional branch | |
17454 | 1 -> 3 ASM_OUTPUT_OPCODE after not having output the conditional branch | |
17455 | 2 -> 4 ASM_OUTPUT_OPCODE after not having output the conditional branch | |
4977bab6 | 17456 | 3 -> 0 (*targetm.asm_out.internal_label) if the `target' label is reached |
cce8749e CH |
17457 | (the target label has CODE_LABEL_NUMBER equal to arm_target_label). |
17458 | 4 -> 0 final_prescan_insn if the `target' unconditional branch is reached | |
17459 | (the target insn is arm_target_insn). | |
17460 | ||
ff9940b0 RE |
17461 | If the jump clobbers the conditions then we use states 2 and 4. |
17462 | ||
17463 | A similar thing can be done with conditional return insns. | |
17464 | ||
cce8749e CH |
17465 | XXX In case the `target' is an unconditional branch, this conditionalising |
17466 | of the instructions always reduces code size, but not always execution | |
17467 | time. But then, I want to reduce the code size to somewhere near what | |
17468 | /bin/cc produces. */ | |
17469 | ||
5b3e6663 PB |
17470 | /* In addition to this, state is maintained for Thumb-2 COND_EXEC |
17471 | instructions. When a COND_EXEC instruction is seen the subsequent | |
17472 | instructions are scanned so that multiple conditional instructions can be | |
17473 | combined into a single IT block. arm_condexec_count and arm_condexec_mask | |
17474 | specify the length and true/false mask for the IT block. These will be | |
17475 | decremented/zeroed by arm_asm_output_opcode as the insns are output. */ | |
17476 | ||
cce8749e CH |
17477 | /* Returns the index of the ARM condition code string in |
17478 | `arm_condition_codes'. COMPARISON should be an rtx like | |
17479 | `(eq (...) (...))'. */ | |
84ed5e79 | 17480 | static enum arm_cond_code |
e32bac5b | 17481 | get_arm_condition_code (rtx comparison) |
cce8749e | 17482 | { |
5165176d | 17483 | enum machine_mode mode = GET_MODE (XEXP (comparison, 0)); |
81f40b79 | 17484 | enum arm_cond_code code; |
1d6e90ac | 17485 | enum rtx_code comp_code = GET_CODE (comparison); |
5165176d RE |
17486 | |
17487 | if (GET_MODE_CLASS (mode) != MODE_CC) | |
84ed5e79 | 17488 | mode = SELECT_CC_MODE (comp_code, XEXP (comparison, 0), |
5165176d RE |
17489 | XEXP (comparison, 1)); |
17490 | ||
17491 | switch (mode) | |
cce8749e | 17492 | { |
84ed5e79 RE |
17493 | case CC_DNEmode: code = ARM_NE; goto dominance; |
17494 | case CC_DEQmode: code = ARM_EQ; goto dominance; | |
17495 | case CC_DGEmode: code = ARM_GE; goto dominance; | |
17496 | case CC_DGTmode: code = ARM_GT; goto dominance; | |
17497 | case CC_DLEmode: code = ARM_LE; goto dominance; | |
17498 | case CC_DLTmode: code = ARM_LT; goto dominance; | |
17499 | case CC_DGEUmode: code = ARM_CS; goto dominance; | |
17500 | case CC_DGTUmode: code = ARM_HI; goto dominance; | |
17501 | case CC_DLEUmode: code = ARM_LS; goto dominance; | |
17502 | case CC_DLTUmode: code = ARM_CC; | |
17503 | ||
17504 | dominance: | |
e6d29d15 | 17505 | gcc_assert (comp_code == EQ || comp_code == NE); |
84ed5e79 RE |
17506 | |
17507 | if (comp_code == EQ) | |
17508 | return ARM_INVERSE_CONDITION_CODE (code); | |
17509 | return code; | |
17510 | ||
5165176d | 17511 | case CC_NOOVmode: |
84ed5e79 | 17512 | switch (comp_code) |
5165176d | 17513 | { |
84ed5e79 RE |
17514 | case NE: return ARM_NE; |
17515 | case EQ: return ARM_EQ; | |
17516 | case GE: return ARM_PL; | |
17517 | case LT: return ARM_MI; | |
e6d29d15 | 17518 | default: gcc_unreachable (); |
5165176d RE |
17519 | } |
17520 | ||
17521 | case CC_Zmode: | |
84ed5e79 | 17522 | switch (comp_code) |
5165176d | 17523 | { |
84ed5e79 RE |
17524 | case NE: return ARM_NE; |
17525 | case EQ: return ARM_EQ; | |
e6d29d15 | 17526 | default: gcc_unreachable (); |
5165176d RE |
17527 | } |
17528 | ||
defc0463 RE |
17529 | case CC_Nmode: |
17530 | switch (comp_code) | |
17531 | { | |
17532 | case NE: return ARM_MI; | |
17533 | case EQ: return ARM_PL; | |
e6d29d15 | 17534 | default: gcc_unreachable (); |
defc0463 RE |
17535 | } |
17536 | ||
5165176d | 17537 | case CCFPEmode: |
e45b72c4 RE |
17538 | case CCFPmode: |
17539 | /* These encodings assume that AC=1 in the FPA system control | |
17540 | byte. This allows us to handle all cases except UNEQ and | |
17541 | LTGT. */ | |
84ed5e79 RE |
17542 | switch (comp_code) |
17543 | { | |
17544 | case GE: return ARM_GE; | |
17545 | case GT: return ARM_GT; | |
17546 | case LE: return ARM_LS; | |
17547 | case LT: return ARM_MI; | |
e45b72c4 RE |
17548 | case NE: return ARM_NE; |
17549 | case EQ: return ARM_EQ; | |
17550 | case ORDERED: return ARM_VC; | |
17551 | case UNORDERED: return ARM_VS; | |
17552 | case UNLT: return ARM_LT; | |
17553 | case UNLE: return ARM_LE; | |
17554 | case UNGT: return ARM_HI; | |
17555 | case UNGE: return ARM_PL; | |
17556 | /* UNEQ and LTGT do not have a representation. */ | |
17557 | case UNEQ: /* Fall through. */ | |
17558 | case LTGT: /* Fall through. */ | |
e6d29d15 | 17559 | default: gcc_unreachable (); |
84ed5e79 RE |
17560 | } |
17561 | ||
17562 | case CC_SWPmode: | |
17563 | switch (comp_code) | |
17564 | { | |
17565 | case NE: return ARM_NE; | |
17566 | case EQ: return ARM_EQ; | |
17567 | case GE: return ARM_LE; | |
17568 | case GT: return ARM_LT; | |
17569 | case LE: return ARM_GE; | |
17570 | case LT: return ARM_GT; | |
17571 | case GEU: return ARM_LS; | |
17572 | case GTU: return ARM_CC; | |
17573 | case LEU: return ARM_CS; | |
17574 | case LTU: return ARM_HI; | |
e6d29d15 | 17575 | default: gcc_unreachable (); |
84ed5e79 RE |
17576 | } |
17577 | ||
bd9c7e23 RE |
17578 | case CC_Cmode: |
17579 | switch (comp_code) | |
18e8200f BS |
17580 | { |
17581 | case LTU: return ARM_CS; | |
17582 | case GEU: return ARM_CC; | |
17583 | default: gcc_unreachable (); | |
17584 | } | |
17585 | ||
73160ba9 DJ |
17586 | case CC_CZmode: |
17587 | switch (comp_code) | |
17588 | { | |
17589 | case NE: return ARM_NE; | |
17590 | case EQ: return ARM_EQ; | |
17591 | case GEU: return ARM_CS; | |
17592 | case GTU: return ARM_HI; | |
17593 | case LEU: return ARM_LS; | |
17594 | case LTU: return ARM_CC; | |
17595 | default: gcc_unreachable (); | |
17596 | } | |
17597 | ||
17598 | case CC_NCVmode: | |
17599 | switch (comp_code) | |
17600 | { | |
17601 | case GE: return ARM_GE; | |
17602 | case LT: return ARM_LT; | |
17603 | case GEU: return ARM_CS; | |
17604 | case LTU: return ARM_CC; | |
17605 | default: gcc_unreachable (); | |
17606 | } | |
17607 | ||
5165176d | 17608 | case CCmode: |
84ed5e79 | 17609 | switch (comp_code) |
5165176d | 17610 | { |
84ed5e79 RE |
17611 | case NE: return ARM_NE; |
17612 | case EQ: return ARM_EQ; | |
17613 | case GE: return ARM_GE; | |
17614 | case GT: return ARM_GT; | |
17615 | case LE: return ARM_LE; | |
17616 | case LT: return ARM_LT; | |
17617 | case GEU: return ARM_CS; | |
17618 | case GTU: return ARM_HI; | |
17619 | case LEU: return ARM_LS; | |
17620 | case LTU: return ARM_CC; | |
e6d29d15 | 17621 | default: gcc_unreachable (); |
5165176d RE |
17622 | } |
17623 | ||
e6d29d15 | 17624 | default: gcc_unreachable (); |
cce8749e | 17625 | } |
f3bb6135 | 17626 | } |
cce8749e | 17627 | |
44c7bd63 | 17628 | /* Tell arm_asm_output_opcode to output IT blocks for conditionally executed |
5b3e6663 PB |
17629 | instructions. */ |
17630 | void | |
17631 | thumb2_final_prescan_insn (rtx insn) | |
17632 | { | |
17633 | rtx first_insn = insn; | |
17634 | rtx body = PATTERN (insn); | |
17635 | rtx predicate; | |
17636 | enum arm_cond_code code; | |
17637 | int n; | |
17638 | int mask; | |
17639 | ||
17640 | /* Remove the previous insn from the count of insns to be output. */ | |
17641 | if (arm_condexec_count) | |
17642 | arm_condexec_count--; | |
17643 | ||
17644 | /* Nothing to do if we are already inside a conditional block. */ | |
17645 | if (arm_condexec_count) | |
17646 | return; | |
17647 | ||
17648 | if (GET_CODE (body) != COND_EXEC) | |
17649 | return; | |
17650 | ||
17651 | /* Conditional jumps are implemented directly. */ | |
17652 | if (GET_CODE (insn) == JUMP_INSN) | |
17653 | return; | |
17654 | ||
17655 | predicate = COND_EXEC_TEST (body); | |
17656 | arm_current_cc = get_arm_condition_code (predicate); | |
17657 | ||
17658 | n = get_attr_ce_count (insn); | |
17659 | arm_condexec_count = 1; | |
17660 | arm_condexec_mask = (1 << n) - 1; | |
17661 | arm_condexec_masklen = n; | |
17662 | /* See if subsequent instructions can be combined into the same block. */ | |
17663 | for (;;) | |
17664 | { | |
17665 | insn = next_nonnote_insn (insn); | |
17666 | ||
17667 | /* Jumping into the middle of an IT block is illegal, so a label or | |
17668 | barrier terminates the block. */ | |
17669 | if (GET_CODE (insn) != INSN && GET_CODE(insn) != JUMP_INSN) | |
17670 | break; | |
17671 | ||
17672 | body = PATTERN (insn); | |
17673 | /* USE and CLOBBER aren't really insns, so just skip them. */ | |
17674 | if (GET_CODE (body) == USE | |
17675 | || GET_CODE (body) == CLOBBER) | |
5b0202af | 17676 | continue; |
5b3e6663 | 17677 | |
7a085dce | 17678 | /* ??? Recognize conditional jumps, and combine them with IT blocks. */ |
5b3e6663 PB |
17679 | if (GET_CODE (body) != COND_EXEC) |
17680 | break; | |
17681 | /* Allow up to 4 conditionally executed instructions in a block. */ | |
17682 | n = get_attr_ce_count (insn); | |
17683 | if (arm_condexec_masklen + n > 4) | |
17684 | break; | |
17685 | ||
17686 | predicate = COND_EXEC_TEST (body); | |
17687 | code = get_arm_condition_code (predicate); | |
17688 | mask = (1 << n) - 1; | |
17689 | if (arm_current_cc == code) | |
17690 | arm_condexec_mask |= (mask << arm_condexec_masklen); | |
17691 | else if (arm_current_cc != ARM_INVERSE_CONDITION_CODE(code)) | |
17692 | break; | |
17693 | ||
17694 | arm_condexec_count++; | |
17695 | arm_condexec_masklen += n; | |
17696 | ||
17697 | /* A jump must be the last instruction in a conditional block. */ | |
17698 | if (GET_CODE(insn) == JUMP_INSN) | |
17699 | break; | |
17700 | } | |
17701 | /* Restore recog_data (getting the attributes of other insns can | |
17702 | destroy this array, but final.c assumes that it remains intact | |
17703 | across this call). */ | |
17704 | extract_constrain_insn_cached (first_insn); | |
17705 | } | |
17706 | ||
cce8749e | 17707 | void |
e32bac5b | 17708 | arm_final_prescan_insn (rtx insn) |
cce8749e CH |
17709 | { |
17710 | /* BODY will hold the body of INSN. */ | |
1d6e90ac | 17711 | rtx body = PATTERN (insn); |
cce8749e CH |
17712 | |
17713 | /* This will be 1 if trying to repeat the trick, and things need to be | |
17714 | reversed if it appears to fail. */ | |
17715 | int reverse = 0; | |
17716 | ||
6354dc9b | 17717 | /* If we start with a return insn, we only succeed if we find another one. */ |
ff9940b0 | 17718 | int seeking_return = 0; |
f676971a | 17719 | |
cce8749e CH |
17720 | /* START_INSN will hold the insn from where we start looking. This is the |
17721 | first insn after the following code_label if REVERSE is true. */ | |
17722 | rtx start_insn = insn; | |
17723 | ||
17724 | /* If in state 4, check if the target branch is reached, in order to | |
17725 | change back to state 0. */ | |
17726 | if (arm_ccfsm_state == 4) | |
17727 | { | |
17728 | if (insn == arm_target_insn) | |
f5a1b0d2 NC |
17729 | { |
17730 | arm_target_insn = NULL; | |
17731 | arm_ccfsm_state = 0; | |
17732 | } | |
cce8749e CH |
17733 | return; |
17734 | } | |
17735 | ||
17736 | /* If in state 3, it is possible to repeat the trick, if this insn is an | |
17737 | unconditional branch to a label, and immediately following this branch | |
17738 | is the previous target label which is only used once, and the label this | |
17739 | branch jumps to is not too far off. */ | |
17740 | if (arm_ccfsm_state == 3) | |
17741 | { | |
17742 | if (simplejump_p (insn)) | |
17743 | { | |
17744 | start_insn = next_nonnote_insn (start_insn); | |
17745 | if (GET_CODE (start_insn) == BARRIER) | |
17746 | { | |
17747 | /* XXX Isn't this always a barrier? */ | |
17748 | start_insn = next_nonnote_insn (start_insn); | |
17749 | } | |
17750 | if (GET_CODE (start_insn) == CODE_LABEL | |
17751 | && CODE_LABEL_NUMBER (start_insn) == arm_target_label | |
17752 | && LABEL_NUSES (start_insn) == 1) | |
17753 | reverse = TRUE; | |
17754 | else | |
17755 | return; | |
17756 | } | |
ff9940b0 RE |
17757 | else if (GET_CODE (body) == RETURN) |
17758 | { | |
17759 | start_insn = next_nonnote_insn (start_insn); | |
17760 | if (GET_CODE (start_insn) == BARRIER) | |
17761 | start_insn = next_nonnote_insn (start_insn); | |
17762 | if (GET_CODE (start_insn) == CODE_LABEL | |
17763 | && CODE_LABEL_NUMBER (start_insn) == arm_target_label | |
17764 | && LABEL_NUSES (start_insn) == 1) | |
17765 | { | |
17766 | reverse = TRUE; | |
17767 | seeking_return = 1; | |
17768 | } | |
17769 | else | |
17770 | return; | |
17771 | } | |
cce8749e CH |
17772 | else |
17773 | return; | |
17774 | } | |
17775 | ||
e6d29d15 | 17776 | gcc_assert (!arm_ccfsm_state || reverse); |
cce8749e CH |
17777 | if (GET_CODE (insn) != JUMP_INSN) |
17778 | return; | |
17779 | ||
f676971a | 17780 | /* This jump might be paralleled with a clobber of the condition codes |
ff9940b0 RE |
17781 | the jump should always come first */ |
17782 | if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0) | |
17783 | body = XVECEXP (body, 0, 0); | |
17784 | ||
cce8749e CH |
17785 | if (reverse |
17786 | || (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC | |
17787 | && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE)) | |
17788 | { | |
bd9c7e23 RE |
17789 | int insns_skipped; |
17790 | int fail = FALSE, succeed = FALSE; | |
cce8749e CH |
17791 | /* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */ |
17792 | int then_not_else = TRUE; | |
ff9940b0 | 17793 | rtx this_insn = start_insn, label = 0; |
cce8749e CH |
17794 | |
17795 | /* Register the insn jumped to. */ | |
17796 | if (reverse) | |
ff9940b0 RE |
17797 | { |
17798 | if (!seeking_return) | |
17799 | label = XEXP (SET_SRC (body), 0); | |
17800 | } | |
cce8749e CH |
17801 | else if (GET_CODE (XEXP (SET_SRC (body), 1)) == LABEL_REF) |
17802 | label = XEXP (XEXP (SET_SRC (body), 1), 0); | |
17803 | else if (GET_CODE (XEXP (SET_SRC (body), 2)) == LABEL_REF) | |
17804 | { | |
17805 | label = XEXP (XEXP (SET_SRC (body), 2), 0); | |
17806 | then_not_else = FALSE; | |
17807 | } | |
ff9940b0 RE |
17808 | else if (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN) |
17809 | seeking_return = 1; | |
17810 | else if (GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN) | |
17811 | { | |
17812 | seeking_return = 1; | |
17813 | then_not_else = FALSE; | |
17814 | } | |
cce8749e | 17815 | else |
e6d29d15 | 17816 | gcc_unreachable (); |
cce8749e CH |
17817 | |
17818 | /* See how many insns this branch skips, and what kind of insns. If all | |
17819 | insns are okay, and the label or unconditional branch to the same | |
17820 | label is not too far away, succeed. */ | |
17821 | for (insns_skipped = 0; | |
b36ba79f | 17822 | !fail && !succeed && insns_skipped++ < max_insns_skipped;) |
cce8749e CH |
17823 | { |
17824 | rtx scanbody; | |
17825 | ||
17826 | this_insn = next_nonnote_insn (this_insn); | |
17827 | if (!this_insn) | |
17828 | break; | |
17829 | ||
cce8749e CH |
17830 | switch (GET_CODE (this_insn)) |
17831 | { | |
17832 | case CODE_LABEL: | |
17833 | /* Succeed if it is the target label, otherwise fail since | |
17834 | control falls in from somewhere else. */ | |
17835 | if (this_insn == label) | |
17836 | { | |
accbd151 | 17837 | arm_ccfsm_state = 1; |
cce8749e CH |
17838 | succeed = TRUE; |
17839 | } | |
17840 | else | |
17841 | fail = TRUE; | |
17842 | break; | |
17843 | ||
ff9940b0 | 17844 | case BARRIER: |
cce8749e | 17845 | /* Succeed if the following insn is the target label. |
f676971a EC |
17846 | Otherwise fail. |
17847 | If return insns are used then the last insn in a function | |
6354dc9b | 17848 | will be a barrier. */ |
cce8749e | 17849 | this_insn = next_nonnote_insn (this_insn); |
ff9940b0 | 17850 | if (this_insn && this_insn == label) |
cce8749e | 17851 | { |
accbd151 | 17852 | arm_ccfsm_state = 1; |
cce8749e CH |
17853 | succeed = TRUE; |
17854 | } | |
17855 | else | |
17856 | fail = TRUE; | |
17857 | break; | |
17858 | ||
ff9940b0 | 17859 | case CALL_INSN: |
68d560d4 RE |
17860 | /* The AAPCS says that conditional calls should not be |
17861 | used since they make interworking inefficient (the | |
17862 | linker can't transform BL<cond> into BLX). That's | |
17863 | only a problem if the machine has BLX. */ | |
17864 | if (arm_arch5) | |
17865 | { | |
17866 | fail = TRUE; | |
17867 | break; | |
17868 | } | |
17869 | ||
61f0ccff RE |
17870 | /* Succeed if the following insn is the target label, or |
17871 | if the following two insns are a barrier and the | |
17872 | target label. */ | |
17873 | this_insn = next_nonnote_insn (this_insn); | |
17874 | if (this_insn && GET_CODE (this_insn) == BARRIER) | |
17875 | this_insn = next_nonnote_insn (this_insn); | |
bd9c7e23 | 17876 | |
61f0ccff RE |
17877 | if (this_insn && this_insn == label |
17878 | && insns_skipped < max_insns_skipped) | |
17879 | { | |
accbd151 | 17880 | arm_ccfsm_state = 1; |
61f0ccff | 17881 | succeed = TRUE; |
bd9c7e23 | 17882 | } |
61f0ccff RE |
17883 | else |
17884 | fail = TRUE; | |
ff9940b0 | 17885 | break; |
2b835d68 | 17886 | |
cce8749e CH |
17887 | case JUMP_INSN: |
17888 | /* If this is an unconditional branch to the same label, succeed. | |
17889 | If it is to another label, do nothing. If it is conditional, | |
17890 | fail. */ | |
e32bac5b RE |
17891 | /* XXX Probably, the tests for SET and the PC are |
17892 | unnecessary. */ | |
cce8749e | 17893 | |
ed4c4348 | 17894 | scanbody = PATTERN (this_insn); |
ff9940b0 RE |
17895 | if (GET_CODE (scanbody) == SET |
17896 | && GET_CODE (SET_DEST (scanbody)) == PC) | |
cce8749e CH |
17897 | { |
17898 | if (GET_CODE (SET_SRC (scanbody)) == LABEL_REF | |
17899 | && XEXP (SET_SRC (scanbody), 0) == label && !reverse) | |
17900 | { | |
17901 | arm_ccfsm_state = 2; | |
17902 | succeed = TRUE; | |
17903 | } | |
17904 | else if (GET_CODE (SET_SRC (scanbody)) == IF_THEN_ELSE) | |
17905 | fail = TRUE; | |
17906 | } | |
112cdef5 | 17907 | /* Fail if a conditional return is undesirable (e.g. on a |
b36ba79f RE |
17908 | StrongARM), but still allow this if optimizing for size. */ |
17909 | else if (GET_CODE (scanbody) == RETURN | |
a72d4945 | 17910 | && !use_return_insn (TRUE, NULL) |
5895f793 | 17911 | && !optimize_size) |
b36ba79f | 17912 | fail = TRUE; |
ff9940b0 RE |
17913 | else if (GET_CODE (scanbody) == RETURN |
17914 | && seeking_return) | |
17915 | { | |
17916 | arm_ccfsm_state = 2; | |
17917 | succeed = TRUE; | |
17918 | } | |
17919 | else if (GET_CODE (scanbody) == PARALLEL) | |
17920 | { | |
17921 | switch (get_attr_conds (this_insn)) | |
17922 | { | |
17923 | case CONDS_NOCOND: | |
17924 | break; | |
17925 | default: | |
17926 | fail = TRUE; | |
17927 | break; | |
17928 | } | |
17929 | } | |
4e67550b | 17930 | else |
112cdef5 | 17931 | fail = TRUE; /* Unrecognized jump (e.g. epilogue). */ |
4e67550b | 17932 | |
cce8749e CH |
17933 | break; |
17934 | ||
17935 | case INSN: | |
ff9940b0 RE |
17936 | /* Instructions using or affecting the condition codes make it |
17937 | fail. */ | |
ed4c4348 | 17938 | scanbody = PATTERN (this_insn); |
5895f793 RE |
17939 | if (!(GET_CODE (scanbody) == SET |
17940 | || GET_CODE (scanbody) == PARALLEL) | |
74641843 | 17941 | || get_attr_conds (this_insn) != CONDS_NOCOND) |
cce8749e | 17942 | fail = TRUE; |
9b6b54e2 NC |
17943 | |
17944 | /* A conditional cirrus instruction must be followed by | |
17945 | a non Cirrus instruction. However, since we | |
17946 | conditionalize instructions in this function and by | |
17947 | the time we get here we can't add instructions | |
17948 | (nops), because shorten_branches() has already been | |
17949 | called, we will disable conditionalizing Cirrus | |
17950 | instructions to be safe. */ | |
17951 | if (GET_CODE (scanbody) != USE | |
17952 | && GET_CODE (scanbody) != CLOBBER | |
f0375c66 | 17953 | && get_attr_cirrus (this_insn) != CIRRUS_NOT) |
9b6b54e2 | 17954 | fail = TRUE; |
cce8749e CH |
17955 | break; |
17956 | ||
17957 | default: | |
17958 | break; | |
17959 | } | |
17960 | } | |
17961 | if (succeed) | |
17962 | { | |
ff9940b0 | 17963 | if ((!seeking_return) && (arm_ccfsm_state == 1 || reverse)) |
cce8749e | 17964 | arm_target_label = CODE_LABEL_NUMBER (label); |
e6d29d15 | 17965 | else |
ff9940b0 | 17966 | { |
e6d29d15 | 17967 | gcc_assert (seeking_return || arm_ccfsm_state == 2); |
e0b92319 | 17968 | |
ff9940b0 RE |
17969 | while (this_insn && GET_CODE (PATTERN (this_insn)) == USE) |
17970 | { | |
17971 | this_insn = next_nonnote_insn (this_insn); | |
e6d29d15 NS |
17972 | gcc_assert (!this_insn |
17973 | || (GET_CODE (this_insn) != BARRIER | |
17974 | && GET_CODE (this_insn) != CODE_LABEL)); | |
ff9940b0 RE |
17975 | } |
17976 | if (!this_insn) | |
17977 | { | |
d6b4baa4 | 17978 | /* Oh, dear! we ran off the end.. give up. */ |
5b3e6663 | 17979 | extract_constrain_insn_cached (insn); |
ff9940b0 | 17980 | arm_ccfsm_state = 0; |
abaa26e5 | 17981 | arm_target_insn = NULL; |
ff9940b0 RE |
17982 | return; |
17983 | } | |
17984 | arm_target_insn = this_insn; | |
17985 | } | |
accbd151 PB |
17986 | |
17987 | /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from | |
17988 | what it was. */ | |
17989 | if (!reverse) | |
17990 | arm_current_cc = get_arm_condition_code (XEXP (SET_SRC (body), 0)); | |
cce8749e | 17991 | |
cce8749e CH |
17992 | if (reverse || then_not_else) |
17993 | arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc); | |
17994 | } | |
f676971a | 17995 | |
1ccbefce | 17996 | /* Restore recog_data (getting the attributes of other insns can |
ff9940b0 | 17997 | destroy this array, but final.c assumes that it remains intact |
5b3e6663 PB |
17998 | across this call. */ |
17999 | extract_constrain_insn_cached (insn); | |
18000 | } | |
18001 | } | |
18002 | ||
18003 | /* Output IT instructions. */ | |
18004 | void | |
18005 | thumb2_asm_output_opcode (FILE * stream) | |
18006 | { | |
18007 | char buff[5]; | |
18008 | int n; | |
18009 | ||
18010 | if (arm_condexec_mask) | |
18011 | { | |
18012 | for (n = 0; n < arm_condexec_masklen; n++) | |
18013 | buff[n] = (arm_condexec_mask & (1 << n)) ? 't' : 'e'; | |
18014 | buff[n] = 0; | |
18015 | asm_fprintf(stream, "i%s\t%s\n\t", buff, | |
18016 | arm_condition_codes[arm_current_cc]); | |
18017 | arm_condexec_mask = 0; | |
cce8749e | 18018 | } |
f3bb6135 | 18019 | } |
cce8749e | 18020 | |
4b02997f | 18021 | /* Returns true if REGNO is a valid register |
21b5653c | 18022 | for holding a quantity of type MODE. */ |
4b02997f | 18023 | int |
e32bac5b | 18024 | arm_hard_regno_mode_ok (unsigned int regno, enum machine_mode mode) |
4b02997f NC |
18025 | { |
18026 | if (GET_MODE_CLASS (mode) == MODE_CC) | |
a6a5de04 RE |
18027 | return (regno == CC_REGNUM |
18028 | || (TARGET_HARD_FLOAT && TARGET_VFP | |
18029 | && regno == VFPCC_REGNUM)); | |
f676971a | 18030 | |
5b3e6663 | 18031 | if (TARGET_THUMB1) |
4b02997f NC |
18032 | /* For the Thumb we only allow values bigger than SImode in |
18033 | registers 0 - 6, so that there is always a second low | |
18034 | register available to hold the upper part of the value. | |
18035 | We probably we ought to ensure that the register is the | |
18036 | start of an even numbered register pair. */ | |
e9d7b180 | 18037 | return (ARM_NUM_REGS (mode) < 2) || (regno < LAST_LO_REGNUM); |
4b02997f | 18038 | |
a6a5de04 RE |
18039 | if (TARGET_HARD_FLOAT && TARGET_MAVERICK |
18040 | && IS_CIRRUS_REGNUM (regno)) | |
9b6b54e2 NC |
18041 | /* We have outlawed SI values in Cirrus registers because they |
18042 | reside in the lower 32 bits, but SF values reside in the | |
18043 | upper 32 bits. This causes gcc all sorts of grief. We can't | |
18044 | even split the registers into pairs because Cirrus SI values | |
18045 | get sign extended to 64bits-- aldyh. */ | |
18046 | return (GET_MODE_CLASS (mode) == MODE_FLOAT) || (mode == DImode); | |
18047 | ||
a6a5de04 RE |
18048 | if (TARGET_HARD_FLOAT && TARGET_VFP |
18049 | && IS_VFP_REGNUM (regno)) | |
9b66ebb1 PB |
18050 | { |
18051 | if (mode == SFmode || mode == SImode) | |
f1adb0a9 | 18052 | return VFP_REGNO_OK_FOR_SINGLE (regno); |
9b66ebb1 | 18053 | |
9b66ebb1 | 18054 | if (mode == DFmode) |
f1adb0a9 | 18055 | return VFP_REGNO_OK_FOR_DOUBLE (regno); |
88f77cba | 18056 | |
0fd8c3ad | 18057 | /* VFP registers can hold HFmode values, but there is no point in |
e0dc3601 | 18058 | putting them there unless we have hardware conversion insns. */ |
0fd8c3ad | 18059 | if (mode == HFmode) |
e0dc3601 | 18060 | return TARGET_FP16 && VFP_REGNO_OK_FOR_SINGLE (regno); |
0fd8c3ad | 18061 | |
88f77cba JB |
18062 | if (TARGET_NEON) |
18063 | return (VALID_NEON_DREG_MODE (mode) && VFP_REGNO_OK_FOR_DOUBLE (regno)) | |
18064 | || (VALID_NEON_QREG_MODE (mode) | |
18065 | && NEON_REGNO_OK_FOR_QUAD (regno)) | |
18066 | || (mode == TImode && NEON_REGNO_OK_FOR_NREGS (regno, 2)) | |
18067 | || (mode == EImode && NEON_REGNO_OK_FOR_NREGS (regno, 3)) | |
18068 | || (mode == OImode && NEON_REGNO_OK_FOR_NREGS (regno, 4)) | |
18069 | || (mode == CImode && NEON_REGNO_OK_FOR_NREGS (regno, 6)) | |
18070 | || (mode == XImode && NEON_REGNO_OK_FOR_NREGS (regno, 8)); | |
18071 | ||
9b66ebb1 PB |
18072 | return FALSE; |
18073 | } | |
18074 | ||
a6a5de04 RE |
18075 | if (TARGET_REALLY_IWMMXT) |
18076 | { | |
18077 | if (IS_IWMMXT_GR_REGNUM (regno)) | |
18078 | return mode == SImode; | |
5a9335ef | 18079 | |
a6a5de04 RE |
18080 | if (IS_IWMMXT_REGNUM (regno)) |
18081 | return VALID_IWMMXT_REG_MODE (mode); | |
18082 | } | |
18083 | ||
2e94c12d | 18084 | /* We allow almost any value to be stored in the general registers. |
fdd695fd | 18085 | Restrict doubleword quantities to even register pairs so that we can |
2e94c12d JB |
18086 | use ldrd. Do not allow very large Neon structure opaque modes in |
18087 | general registers; they would use too many. */ | |
4b02997f | 18088 | if (regno <= LAST_ARM_REGNUM) |
88f77cba | 18089 | return !(TARGET_LDRD && GET_MODE_SIZE (mode) > 4 && (regno & 1) != 0) |
2e94c12d | 18090 | && ARM_NUM_REGS (mode) <= 4; |
4b02997f | 18091 | |
a6a5de04 | 18092 | if (regno == FRAME_POINTER_REGNUM |
4b02997f NC |
18093 | || regno == ARG_POINTER_REGNUM) |
18094 | /* We only allow integers in the fake hard registers. */ | |
18095 | return GET_MODE_CLASS (mode) == MODE_INT; | |
18096 | ||
3b684012 | 18097 | /* The only registers left are the FPA registers |
4b02997f | 18098 | which we only allow to hold FP values. */ |
a6a5de04 RE |
18099 | return (TARGET_HARD_FLOAT && TARGET_FPA |
18100 | && GET_MODE_CLASS (mode) == MODE_FLOAT | |
18101 | && regno >= FIRST_FPA_REGNUM | |
18102 | && regno <= LAST_FPA_REGNUM); | |
4b02997f NC |
18103 | } |
18104 | ||
5b3e6663 PB |
18105 | /* For efficiency and historical reasons LO_REGS, HI_REGS and CC_REGS are |
18106 | not used in arm mode. */ | |
bbbbb16a ILT |
18107 | |
18108 | enum reg_class | |
e32bac5b | 18109 | arm_regno_class (int regno) |
d5b7b3ae | 18110 | { |
5b3e6663 | 18111 | if (TARGET_THUMB1) |
d5b7b3ae RE |
18112 | { |
18113 | if (regno == STACK_POINTER_REGNUM) | |
18114 | return STACK_REG; | |
18115 | if (regno == CC_REGNUM) | |
18116 | return CC_REG; | |
18117 | if (regno < 8) | |
18118 | return LO_REGS; | |
18119 | return HI_REGS; | |
18120 | } | |
18121 | ||
5b3e6663 PB |
18122 | if (TARGET_THUMB2 && regno < 8) |
18123 | return LO_REGS; | |
18124 | ||
d5b7b3ae RE |
18125 | if ( regno <= LAST_ARM_REGNUM |
18126 | || regno == FRAME_POINTER_REGNUM | |
18127 | || regno == ARG_POINTER_REGNUM) | |
5b3e6663 | 18128 | return TARGET_THUMB2 ? HI_REGS : GENERAL_REGS; |
f676971a | 18129 | |
9b66ebb1 | 18130 | if (regno == CC_REGNUM || regno == VFPCC_REGNUM) |
5b3e6663 | 18131 | return TARGET_THUMB2 ? CC_REG : NO_REGS; |
d5b7b3ae | 18132 | |
9b6b54e2 NC |
18133 | if (IS_CIRRUS_REGNUM (regno)) |
18134 | return CIRRUS_REGS; | |
18135 | ||
9b66ebb1 | 18136 | if (IS_VFP_REGNUM (regno)) |
f1adb0a9 JB |
18137 | { |
18138 | if (regno <= D7_VFP_REGNUM) | |
18139 | return VFP_D0_D7_REGS; | |
18140 | else if (regno <= LAST_LO_VFP_REGNUM) | |
18141 | return VFP_LO_REGS; | |
18142 | else | |
18143 | return VFP_HI_REGS; | |
18144 | } | |
9b66ebb1 | 18145 | |
5a9335ef NC |
18146 | if (IS_IWMMXT_REGNUM (regno)) |
18147 | return IWMMXT_REGS; | |
18148 | ||
e99faaaa ILT |
18149 | if (IS_IWMMXT_GR_REGNUM (regno)) |
18150 | return IWMMXT_GR_REGS; | |
18151 | ||
3b684012 | 18152 | return FPA_REGS; |
d5b7b3ae RE |
18153 | } |
18154 | ||
18155 | /* Handle a special case when computing the offset | |
18156 | of an argument from the frame pointer. */ | |
18157 | int | |
e32bac5b | 18158 | arm_debugger_arg_offset (int value, rtx addr) |
d5b7b3ae RE |
18159 | { |
18160 | rtx insn; | |
18161 | ||
18162 | /* We are only interested if dbxout_parms() failed to compute the offset. */ | |
18163 | if (value != 0) | |
18164 | return 0; | |
18165 | ||
18166 | /* We can only cope with the case where the address is held in a register. */ | |
18167 | if (GET_CODE (addr) != REG) | |
18168 | return 0; | |
18169 | ||
18170 | /* If we are using the frame pointer to point at the argument, then | |
18171 | an offset of 0 is correct. */ | |
cd2b33d0 | 18172 | if (REGNO (addr) == (unsigned) HARD_FRAME_POINTER_REGNUM) |
d5b7b3ae | 18173 | return 0; |
f676971a | 18174 | |
d5b7b3ae RE |
18175 | /* If we are using the stack pointer to point at the |
18176 | argument, then an offset of 0 is correct. */ | |
5b3e6663 | 18177 | /* ??? Check this is consistent with thumb2 frame layout. */ |
5895f793 | 18178 | if ((TARGET_THUMB || !frame_pointer_needed) |
d5b7b3ae RE |
18179 | && REGNO (addr) == SP_REGNUM) |
18180 | return 0; | |
f676971a | 18181 | |
d5b7b3ae RE |
18182 | /* Oh dear. The argument is pointed to by a register rather |
18183 | than being held in a register, or being stored at a known | |
18184 | offset from the frame pointer. Since GDB only understands | |
18185 | those two kinds of argument we must translate the address | |
18186 | held in the register into an offset from the frame pointer. | |
18187 | We do this by searching through the insns for the function | |
18188 | looking to see where this register gets its value. If the | |
4912a07c | 18189 | register is initialized from the frame pointer plus an offset |
d5b7b3ae | 18190 | then we are in luck and we can continue, otherwise we give up. |
f676971a | 18191 | |
d5b7b3ae RE |
18192 | This code is exercised by producing debugging information |
18193 | for a function with arguments like this: | |
f676971a | 18194 | |
d5b7b3ae | 18195 | double func (double a, double b, int c, double d) {return d;} |
f676971a | 18196 | |
d5b7b3ae RE |
18197 | Without this code the stab for parameter 'd' will be set to |
18198 | an offset of 0 from the frame pointer, rather than 8. */ | |
18199 | ||
18200 | /* The if() statement says: | |
18201 | ||
18202 | If the insn is a normal instruction | |
18203 | and if the insn is setting the value in a register | |
18204 | and if the register being set is the register holding the address of the argument | |
18205 | and if the address is computing by an addition | |
18206 | that involves adding to a register | |
18207 | which is the frame pointer | |
18208 | a constant integer | |
18209 | ||
d6b4baa4 | 18210 | then... */ |
f676971a | 18211 | |
d5b7b3ae RE |
18212 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
18213 | { | |
f676971a | 18214 | if ( GET_CODE (insn) == INSN |
d5b7b3ae RE |
18215 | && GET_CODE (PATTERN (insn)) == SET |
18216 | && REGNO (XEXP (PATTERN (insn), 0)) == REGNO (addr) | |
18217 | && GET_CODE (XEXP (PATTERN (insn), 1)) == PLUS | |
18218 | && GET_CODE (XEXP (XEXP (PATTERN (insn), 1), 0)) == REG | |
cd2b33d0 | 18219 | && REGNO (XEXP (XEXP (PATTERN (insn), 1), 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM |
d5b7b3ae RE |
18220 | && GET_CODE (XEXP (XEXP (PATTERN (insn), 1), 1)) == CONST_INT |
18221 | ) | |
18222 | { | |
18223 | value = INTVAL (XEXP (XEXP (PATTERN (insn), 1), 1)); | |
f676971a | 18224 | |
d5b7b3ae RE |
18225 | break; |
18226 | } | |
18227 | } | |
f676971a | 18228 | |
d5b7b3ae RE |
18229 | if (value == 0) |
18230 | { | |
18231 | debug_rtx (addr); | |
d4ee4d25 | 18232 | warning (0, "unable to compute real location of stacked parameter"); |
d5b7b3ae RE |
18233 | value = 8; /* XXX magic hack */ |
18234 | } | |
18235 | ||
18236 | return value; | |
18237 | } | |
d5b7b3ae | 18238 | \f |
229a1c59 JZ |
18239 | typedef enum { |
18240 | T_V8QI, | |
18241 | T_V4HI, | |
18242 | T_V2SI, | |
18243 | T_V2SF, | |
18244 | T_DI, | |
18245 | T_V16QI, | |
18246 | T_V8HI, | |
18247 | T_V4SI, | |
18248 | T_V4SF, | |
18249 | T_V2DI, | |
18250 | T_TI, | |
18251 | T_EI, | |
18252 | T_OI, | |
18253 | T_MAX /* Size of enum. Keep last. */ | |
18254 | } neon_builtin_type_mode; | |
18255 | ||
18256 | #define TYPE_MODE_BIT(X) (1 << (X)) | |
18257 | ||
18258 | #define TB_DREG (TYPE_MODE_BIT (T_V8QI) | TYPE_MODE_BIT (T_V4HI) \ | |
18259 | | TYPE_MODE_BIT (T_V2SI) | TYPE_MODE_BIT (T_V2SF) \ | |
18260 | | TYPE_MODE_BIT (T_DI)) | |
18261 | #define TB_QREG (TYPE_MODE_BIT (T_V16QI) | TYPE_MODE_BIT (T_V8HI) \ | |
18262 | | TYPE_MODE_BIT (T_V4SI) | TYPE_MODE_BIT (T_V4SF) \ | |
18263 | | TYPE_MODE_BIT (T_V2DI) | TYPE_MODE_BIT (T_TI)) | |
5a9335ef | 18264 | |
229a1c59 JZ |
18265 | #define v8qi_UP T_V8QI |
18266 | #define v4hi_UP T_V4HI | |
18267 | #define v2si_UP T_V2SI | |
18268 | #define v2sf_UP T_V2SF | |
18269 | #define di_UP T_DI | |
18270 | #define v16qi_UP T_V16QI | |
18271 | #define v8hi_UP T_V8HI | |
18272 | #define v4si_UP T_V4SI | |
18273 | #define v4sf_UP T_V4SF | |
18274 | #define v2di_UP T_V2DI | |
18275 | #define ti_UP T_TI | |
18276 | #define ei_UP T_EI | |
18277 | #define oi_UP T_OI | |
5a9335ef | 18278 | |
229a1c59 | 18279 | #define UP(X) X##_UP |
5a9335ef | 18280 | |
229a1c59 JZ |
18281 | typedef enum { |
18282 | NEON_BINOP, | |
18283 | NEON_TERNOP, | |
18284 | NEON_UNOP, | |
18285 | NEON_GETLANE, | |
18286 | NEON_SETLANE, | |
18287 | NEON_CREATE, | |
18288 | NEON_DUP, | |
18289 | NEON_DUPLANE, | |
18290 | NEON_COMBINE, | |
18291 | NEON_SPLIT, | |
18292 | NEON_LANEMUL, | |
18293 | NEON_LANEMULL, | |
18294 | NEON_LANEMULH, | |
18295 | NEON_LANEMAC, | |
18296 | NEON_SCALARMUL, | |
18297 | NEON_SCALARMULL, | |
18298 | NEON_SCALARMULH, | |
18299 | NEON_SCALARMAC, | |
18300 | NEON_CONVERT, | |
18301 | NEON_FIXCONV, | |
18302 | NEON_SELECT, | |
18303 | NEON_RESULTPAIR, | |
18304 | NEON_REINTERP, | |
18305 | NEON_VTBL, | |
18306 | NEON_VTBX, | |
18307 | NEON_LOAD1, | |
18308 | NEON_LOAD1LANE, | |
18309 | NEON_STORE1, | |
18310 | NEON_STORE1LANE, | |
18311 | NEON_LOADSTRUCT, | |
18312 | NEON_LOADSTRUCTLANE, | |
18313 | NEON_STORESTRUCT, | |
18314 | NEON_STORESTRUCTLANE, | |
18315 | NEON_LOGICBINOP, | |
18316 | NEON_SHIFTINSERT, | |
18317 | NEON_SHIFTIMM, | |
18318 | NEON_SHIFTACC | |
18319 | } neon_itype; | |
5a9335ef | 18320 | |
229a1c59 JZ |
18321 | typedef struct { |
18322 | const char *name; | |
18323 | const neon_itype itype; | |
18324 | const neon_builtin_type_mode mode; | |
18325 | const enum insn_code code; | |
18326 | unsigned int fcode; | |
18327 | } neon_builtin_datum; | |
f676971a | 18328 | |
229a1c59 | 18329 | #define CF(N,X) CODE_FOR_neon_##N##X |
5a9335ef | 18330 | |
229a1c59 JZ |
18331 | #define VAR1(T, N, A) \ |
18332 | {#N, NEON_##T, UP (A), CF (N, A), 0} | |
18333 | #define VAR2(T, N, A, B) \ | |
18334 | VAR1 (T, N, A), \ | |
18335 | {#N, NEON_##T, UP (B), CF (N, B), 0} | |
18336 | #define VAR3(T, N, A, B, C) \ | |
18337 | VAR2 (T, N, A, B), \ | |
18338 | {#N, NEON_##T, UP (C), CF (N, C), 0} | |
18339 | #define VAR4(T, N, A, B, C, D) \ | |
18340 | VAR3 (T, N, A, B, C), \ | |
18341 | {#N, NEON_##T, UP (D), CF (N, D), 0} | |
18342 | #define VAR5(T, N, A, B, C, D, E) \ | |
18343 | VAR4 (T, N, A, B, C, D), \ | |
18344 | {#N, NEON_##T, UP (E), CF (N, E), 0} | |
18345 | #define VAR6(T, N, A, B, C, D, E, F) \ | |
18346 | VAR5 (T, N, A, B, C, D, E), \ | |
18347 | {#N, NEON_##T, UP (F), CF (N, F), 0} | |
18348 | #define VAR7(T, N, A, B, C, D, E, F, G) \ | |
18349 | VAR6 (T, N, A, B, C, D, E, F), \ | |
18350 | {#N, NEON_##T, UP (G), CF (N, G), 0} | |
18351 | #define VAR8(T, N, A, B, C, D, E, F, G, H) \ | |
18352 | VAR7 (T, N, A, B, C, D, E, F, G), \ | |
18353 | {#N, NEON_##T, UP (H), CF (N, H), 0} | |
18354 | #define VAR9(T, N, A, B, C, D, E, F, G, H, I) \ | |
18355 | VAR8 (T, N, A, B, C, D, E, F, G, H), \ | |
18356 | {#N, NEON_##T, UP (I), CF (N, I), 0} | |
18357 | #define VAR10(T, N, A, B, C, D, E, F, G, H, I, J) \ | |
18358 | VAR9 (T, N, A, B, C, D, E, F, G, H, I), \ | |
18359 | {#N, NEON_##T, UP (J), CF (N, J), 0} | |
18360 | ||
18361 | /* The mode entries in the following table correspond to the "key" type of the | |
18362 | instruction variant, i.e. equivalent to that which would be specified after | |
18363 | the assembler mnemonic, which usually refers to the last vector operand. | |
18364 | (Signed/unsigned/polynomial types are not differentiated between though, and | |
18365 | are all mapped onto the same mode for a given element size.) The modes | |
18366 | listed per instruction should be the same as those defined for that | |
18367 | instruction's pattern in neon.md. */ | |
18368 | ||
18369 | static neon_builtin_datum neon_builtin_data[] = | |
5a9335ef | 18370 | { |
229a1c59 JZ |
18371 | VAR10 (BINOP, vadd, |
18372 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18373 | VAR3 (BINOP, vaddl, v8qi, v4hi, v2si), | |
18374 | VAR3 (BINOP, vaddw, v8qi, v4hi, v2si), | |
18375 | VAR6 (BINOP, vhadd, v8qi, v4hi, v2si, v16qi, v8hi, v4si), | |
18376 | VAR8 (BINOP, vqadd, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di), | |
18377 | VAR3 (BINOP, vaddhn, v8hi, v4si, v2di), | |
18378 | VAR8 (BINOP, vmul, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18379 | VAR8 (TERNOP, vmla, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18380 | VAR3 (TERNOP, vmlal, v8qi, v4hi, v2si), | |
18381 | VAR8 (TERNOP, vmls, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18382 | VAR3 (TERNOP, vmlsl, v8qi, v4hi, v2si), | |
18383 | VAR4 (BINOP, vqdmulh, v4hi, v2si, v8hi, v4si), | |
18384 | VAR2 (TERNOP, vqdmlal, v4hi, v2si), | |
18385 | VAR2 (TERNOP, vqdmlsl, v4hi, v2si), | |
18386 | VAR3 (BINOP, vmull, v8qi, v4hi, v2si), | |
18387 | VAR2 (SCALARMULL, vmull_n, v4hi, v2si), | |
18388 | VAR2 (LANEMULL, vmull_lane, v4hi, v2si), | |
18389 | VAR2 (SCALARMULL, vqdmull_n, v4hi, v2si), | |
18390 | VAR2 (LANEMULL, vqdmull_lane, v4hi, v2si), | |
18391 | VAR4 (SCALARMULH, vqdmulh_n, v4hi, v2si, v8hi, v4si), | |
18392 | VAR4 (LANEMULH, vqdmulh_lane, v4hi, v2si, v8hi, v4si), | |
18393 | VAR2 (BINOP, vqdmull, v4hi, v2si), | |
18394 | VAR8 (BINOP, vshl, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di), | |
18395 | VAR8 (BINOP, vqshl, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di), | |
18396 | VAR8 (SHIFTIMM, vshr_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di), | |
18397 | VAR3 (SHIFTIMM, vshrn_n, v8hi, v4si, v2di), | |
18398 | VAR3 (SHIFTIMM, vqshrn_n, v8hi, v4si, v2di), | |
18399 | VAR3 (SHIFTIMM, vqshrun_n, v8hi, v4si, v2di), | |
18400 | VAR8 (SHIFTIMM, vshl_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di), | |
18401 | VAR8 (SHIFTIMM, vqshl_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di), | |
18402 | VAR8 (SHIFTIMM, vqshlu_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di), | |
18403 | VAR3 (SHIFTIMM, vshll_n, v8qi, v4hi, v2si), | |
18404 | VAR8 (SHIFTACC, vsra_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di), | |
18405 | VAR10 (BINOP, vsub, | |
18406 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18407 | VAR3 (BINOP, vsubl, v8qi, v4hi, v2si), | |
18408 | VAR3 (BINOP, vsubw, v8qi, v4hi, v2si), | |
18409 | VAR8 (BINOP, vqsub, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di), | |
18410 | VAR6 (BINOP, vhsub, v8qi, v4hi, v2si, v16qi, v8hi, v4si), | |
18411 | VAR3 (BINOP, vsubhn, v8hi, v4si, v2di), | |
18412 | VAR8 (BINOP, vceq, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18413 | VAR8 (BINOP, vcge, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18414 | VAR8 (BINOP, vcgt, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18415 | VAR2 (BINOP, vcage, v2sf, v4sf), | |
18416 | VAR2 (BINOP, vcagt, v2sf, v4sf), | |
18417 | VAR6 (BINOP, vtst, v8qi, v4hi, v2si, v16qi, v8hi, v4si), | |
18418 | VAR8 (BINOP, vabd, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18419 | VAR3 (BINOP, vabdl, v8qi, v4hi, v2si), | |
18420 | VAR6 (TERNOP, vaba, v8qi, v4hi, v2si, v16qi, v8hi, v4si), | |
18421 | VAR3 (TERNOP, vabal, v8qi, v4hi, v2si), | |
18422 | VAR8 (BINOP, vmax, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18423 | VAR8 (BINOP, vmin, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18424 | VAR4 (BINOP, vpadd, v8qi, v4hi, v2si, v2sf), | |
18425 | VAR6 (UNOP, vpaddl, v8qi, v4hi, v2si, v16qi, v8hi, v4si), | |
18426 | VAR6 (BINOP, vpadal, v8qi, v4hi, v2si, v16qi, v8hi, v4si), | |
18427 | VAR4 (BINOP, vpmax, v8qi, v4hi, v2si, v2sf), | |
18428 | VAR4 (BINOP, vpmin, v8qi, v4hi, v2si, v2sf), | |
18429 | VAR2 (BINOP, vrecps, v2sf, v4sf), | |
18430 | VAR2 (BINOP, vrsqrts, v2sf, v4sf), | |
18431 | VAR8 (SHIFTINSERT, vsri_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di), | |
18432 | VAR8 (SHIFTINSERT, vsli_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di), | |
18433 | VAR8 (UNOP, vabs, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18434 | VAR6 (UNOP, vqabs, v8qi, v4hi, v2si, v16qi, v8hi, v4si), | |
18435 | VAR8 (UNOP, vneg, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18436 | VAR6 (UNOP, vqneg, v8qi, v4hi, v2si, v16qi, v8hi, v4si), | |
18437 | VAR6 (UNOP, vcls, v8qi, v4hi, v2si, v16qi, v8hi, v4si), | |
18438 | VAR6 (UNOP, vclz, v8qi, v4hi, v2si, v16qi, v8hi, v4si), | |
18439 | VAR2 (UNOP, vcnt, v8qi, v16qi), | |
18440 | VAR4 (UNOP, vrecpe, v2si, v2sf, v4si, v4sf), | |
18441 | VAR4 (UNOP, vrsqrte, v2si, v2sf, v4si, v4sf), | |
18442 | VAR6 (UNOP, vmvn, v8qi, v4hi, v2si, v16qi, v8hi, v4si), | |
18443 | /* FIXME: vget_lane supports more variants than this! */ | |
18444 | VAR10 (GETLANE, vget_lane, | |
18445 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18446 | VAR10 (SETLANE, vset_lane, | |
18447 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18448 | VAR5 (CREATE, vcreate, v8qi, v4hi, v2si, v2sf, di), | |
18449 | VAR10 (DUP, vdup_n, | |
18450 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18451 | VAR10 (DUPLANE, vdup_lane, | |
18452 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18453 | VAR5 (COMBINE, vcombine, v8qi, v4hi, v2si, v2sf, di), | |
18454 | VAR5 (SPLIT, vget_high, v16qi, v8hi, v4si, v4sf, v2di), | |
18455 | VAR5 (SPLIT, vget_low, v16qi, v8hi, v4si, v4sf, v2di), | |
18456 | VAR3 (UNOP, vmovn, v8hi, v4si, v2di), | |
18457 | VAR3 (UNOP, vqmovn, v8hi, v4si, v2di), | |
18458 | VAR3 (UNOP, vqmovun, v8hi, v4si, v2di), | |
18459 | VAR3 (UNOP, vmovl, v8qi, v4hi, v2si), | |
18460 | VAR6 (LANEMUL, vmul_lane, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18461 | VAR6 (LANEMAC, vmla_lane, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18462 | VAR2 (LANEMAC, vmlal_lane, v4hi, v2si), | |
18463 | VAR2 (LANEMAC, vqdmlal_lane, v4hi, v2si), | |
18464 | VAR6 (LANEMAC, vmls_lane, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18465 | VAR2 (LANEMAC, vmlsl_lane, v4hi, v2si), | |
18466 | VAR2 (LANEMAC, vqdmlsl_lane, v4hi, v2si), | |
18467 | VAR6 (SCALARMUL, vmul_n, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18468 | VAR6 (SCALARMAC, vmla_n, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18469 | VAR2 (SCALARMAC, vmlal_n, v4hi, v2si), | |
18470 | VAR2 (SCALARMAC, vqdmlal_n, v4hi, v2si), | |
18471 | VAR6 (SCALARMAC, vmls_n, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18472 | VAR2 (SCALARMAC, vmlsl_n, v4hi, v2si), | |
18473 | VAR2 (SCALARMAC, vqdmlsl_n, v4hi, v2si), | |
18474 | VAR10 (BINOP, vext, | |
18475 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18476 | VAR8 (UNOP, vrev64, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18477 | VAR4 (UNOP, vrev32, v8qi, v4hi, v16qi, v8hi), | |
18478 | VAR2 (UNOP, vrev16, v8qi, v16qi), | |
18479 | VAR4 (CONVERT, vcvt, v2si, v2sf, v4si, v4sf), | |
18480 | VAR4 (FIXCONV, vcvt_n, v2si, v2sf, v4si, v4sf), | |
18481 | VAR10 (SELECT, vbsl, | |
18482 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18483 | VAR1 (VTBL, vtbl1, v8qi), | |
18484 | VAR1 (VTBL, vtbl2, v8qi), | |
18485 | VAR1 (VTBL, vtbl3, v8qi), | |
18486 | VAR1 (VTBL, vtbl4, v8qi), | |
18487 | VAR1 (VTBX, vtbx1, v8qi), | |
18488 | VAR1 (VTBX, vtbx2, v8qi), | |
18489 | VAR1 (VTBX, vtbx3, v8qi), | |
18490 | VAR1 (VTBX, vtbx4, v8qi), | |
18491 | VAR8 (RESULTPAIR, vtrn, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18492 | VAR8 (RESULTPAIR, vzip, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18493 | VAR8 (RESULTPAIR, vuzp, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf), | |
18494 | VAR5 (REINTERP, vreinterpretv8qi, v8qi, v4hi, v2si, v2sf, di), | |
18495 | VAR5 (REINTERP, vreinterpretv4hi, v8qi, v4hi, v2si, v2sf, di), | |
18496 | VAR5 (REINTERP, vreinterpretv2si, v8qi, v4hi, v2si, v2sf, di), | |
18497 | VAR5 (REINTERP, vreinterpretv2sf, v8qi, v4hi, v2si, v2sf, di), | |
18498 | VAR5 (REINTERP, vreinterpretdi, v8qi, v4hi, v2si, v2sf, di), | |
18499 | VAR5 (REINTERP, vreinterpretv16qi, v16qi, v8hi, v4si, v4sf, v2di), | |
18500 | VAR5 (REINTERP, vreinterpretv8hi, v16qi, v8hi, v4si, v4sf, v2di), | |
18501 | VAR5 (REINTERP, vreinterpretv4si, v16qi, v8hi, v4si, v4sf, v2di), | |
18502 | VAR5 (REINTERP, vreinterpretv4sf, v16qi, v8hi, v4si, v4sf, v2di), | |
18503 | VAR5 (REINTERP, vreinterpretv2di, v16qi, v8hi, v4si, v4sf, v2di), | |
18504 | VAR10 (LOAD1, vld1, | |
18505 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18506 | VAR10 (LOAD1LANE, vld1_lane, | |
18507 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18508 | VAR10 (LOAD1, vld1_dup, | |
18509 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18510 | VAR10 (STORE1, vst1, | |
18511 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18512 | VAR10 (STORE1LANE, vst1_lane, | |
18513 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18514 | VAR9 (LOADSTRUCT, | |
18515 | vld2, v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf), | |
18516 | VAR7 (LOADSTRUCTLANE, vld2_lane, | |
18517 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18518 | VAR5 (LOADSTRUCT, vld2_dup, v8qi, v4hi, v2si, v2sf, di), | |
18519 | VAR9 (STORESTRUCT, vst2, | |
18520 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf), | |
18521 | VAR7 (STORESTRUCTLANE, vst2_lane, | |
18522 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18523 | VAR9 (LOADSTRUCT, | |
18524 | vld3, v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf), | |
18525 | VAR7 (LOADSTRUCTLANE, vld3_lane, | |
18526 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18527 | VAR5 (LOADSTRUCT, vld3_dup, v8qi, v4hi, v2si, v2sf, di), | |
18528 | VAR9 (STORESTRUCT, vst3, | |
18529 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf), | |
18530 | VAR7 (STORESTRUCTLANE, vst3_lane, | |
18531 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18532 | VAR9 (LOADSTRUCT, vld4, | |
18533 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf), | |
18534 | VAR7 (LOADSTRUCTLANE, vld4_lane, | |
18535 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18536 | VAR5 (LOADSTRUCT, vld4_dup, v8qi, v4hi, v2si, v2sf, di), | |
18537 | VAR9 (STORESTRUCT, vst4, | |
18538 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf), | |
18539 | VAR7 (STORESTRUCTLANE, vst4_lane, | |
18540 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf), | |
18541 | VAR10 (LOGICBINOP, vand, | |
18542 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18543 | VAR10 (LOGICBINOP, vorr, | |
18544 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18545 | VAR10 (BINOP, veor, | |
18546 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18547 | VAR10 (LOGICBINOP, vbic, | |
18548 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di), | |
18549 | VAR10 (LOGICBINOP, vorn, | |
18550 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) | |
18551 | }; | |
18552 | ||
18553 | #undef CF | |
18554 | #undef VAR1 | |
18555 | #undef VAR2 | |
18556 | #undef VAR3 | |
18557 | #undef VAR4 | |
18558 | #undef VAR5 | |
18559 | #undef VAR6 | |
18560 | #undef VAR7 | |
18561 | #undef VAR8 | |
18562 | #undef VAR9 | |
18563 | #undef VAR10 | |
18564 | ||
18565 | /* Neon defines builtins from ARM_BUILTIN_MAX upwards, though they don't have | |
18566 | symbolic names defined here (which would require too much duplication). | |
18567 | FIXME? */ | |
18568 | enum arm_builtins | |
18569 | { | |
18570 | ARM_BUILTIN_GETWCX, | |
18571 | ARM_BUILTIN_SETWCX, | |
18572 | ||
18573 | ARM_BUILTIN_WZERO, | |
18574 | ||
18575 | ARM_BUILTIN_WAVG2BR, | |
18576 | ARM_BUILTIN_WAVG2HR, | |
18577 | ARM_BUILTIN_WAVG2B, | |
18578 | ARM_BUILTIN_WAVG2H, | |
18579 | ||
18580 | ARM_BUILTIN_WACCB, | |
18581 | ARM_BUILTIN_WACCH, | |
18582 | ARM_BUILTIN_WACCW, | |
18583 | ||
18584 | ARM_BUILTIN_WMACS, | |
18585 | ARM_BUILTIN_WMACSZ, | |
18586 | ARM_BUILTIN_WMACU, | |
18587 | ARM_BUILTIN_WMACUZ, | |
18588 | ||
18589 | ARM_BUILTIN_WSADB, | |
18590 | ARM_BUILTIN_WSADBZ, | |
18591 | ARM_BUILTIN_WSADH, | |
18592 | ARM_BUILTIN_WSADHZ, | |
18593 | ||
18594 | ARM_BUILTIN_WALIGN, | |
18595 | ||
18596 | ARM_BUILTIN_TMIA, | |
18597 | ARM_BUILTIN_TMIAPH, | |
18598 | ARM_BUILTIN_TMIABB, | |
18599 | ARM_BUILTIN_TMIABT, | |
18600 | ARM_BUILTIN_TMIATB, | |
18601 | ARM_BUILTIN_TMIATT, | |
18602 | ||
18603 | ARM_BUILTIN_TMOVMSKB, | |
18604 | ARM_BUILTIN_TMOVMSKH, | |
18605 | ARM_BUILTIN_TMOVMSKW, | |
18606 | ||
18607 | ARM_BUILTIN_TBCSTB, | |
18608 | ARM_BUILTIN_TBCSTH, | |
18609 | ARM_BUILTIN_TBCSTW, | |
18610 | ||
18611 | ARM_BUILTIN_WMADDS, | |
18612 | ARM_BUILTIN_WMADDU, | |
18613 | ||
18614 | ARM_BUILTIN_WPACKHSS, | |
18615 | ARM_BUILTIN_WPACKWSS, | |
18616 | ARM_BUILTIN_WPACKDSS, | |
18617 | ARM_BUILTIN_WPACKHUS, | |
18618 | ARM_BUILTIN_WPACKWUS, | |
18619 | ARM_BUILTIN_WPACKDUS, | |
18620 | ||
18621 | ARM_BUILTIN_WADDB, | |
18622 | ARM_BUILTIN_WADDH, | |
18623 | ARM_BUILTIN_WADDW, | |
18624 | ARM_BUILTIN_WADDSSB, | |
18625 | ARM_BUILTIN_WADDSSH, | |
18626 | ARM_BUILTIN_WADDSSW, | |
18627 | ARM_BUILTIN_WADDUSB, | |
18628 | ARM_BUILTIN_WADDUSH, | |
18629 | ARM_BUILTIN_WADDUSW, | |
18630 | ARM_BUILTIN_WSUBB, | |
18631 | ARM_BUILTIN_WSUBH, | |
18632 | ARM_BUILTIN_WSUBW, | |
18633 | ARM_BUILTIN_WSUBSSB, | |
18634 | ARM_BUILTIN_WSUBSSH, | |
18635 | ARM_BUILTIN_WSUBSSW, | |
18636 | ARM_BUILTIN_WSUBUSB, | |
18637 | ARM_BUILTIN_WSUBUSH, | |
18638 | ARM_BUILTIN_WSUBUSW, | |
18639 | ||
18640 | ARM_BUILTIN_WAND, | |
18641 | ARM_BUILTIN_WANDN, | |
18642 | ARM_BUILTIN_WOR, | |
18643 | ARM_BUILTIN_WXOR, | |
18644 | ||
18645 | ARM_BUILTIN_WCMPEQB, | |
18646 | ARM_BUILTIN_WCMPEQH, | |
18647 | ARM_BUILTIN_WCMPEQW, | |
18648 | ARM_BUILTIN_WCMPGTUB, | |
18649 | ARM_BUILTIN_WCMPGTUH, | |
18650 | ARM_BUILTIN_WCMPGTUW, | |
18651 | ARM_BUILTIN_WCMPGTSB, | |
18652 | ARM_BUILTIN_WCMPGTSH, | |
18653 | ARM_BUILTIN_WCMPGTSW, | |
18654 | ||
18655 | ARM_BUILTIN_TEXTRMSB, | |
18656 | ARM_BUILTIN_TEXTRMSH, | |
18657 | ARM_BUILTIN_TEXTRMSW, | |
18658 | ARM_BUILTIN_TEXTRMUB, | |
18659 | ARM_BUILTIN_TEXTRMUH, | |
18660 | ARM_BUILTIN_TEXTRMUW, | |
18661 | ARM_BUILTIN_TINSRB, | |
18662 | ARM_BUILTIN_TINSRH, | |
18663 | ARM_BUILTIN_TINSRW, | |
18664 | ||
18665 | ARM_BUILTIN_WMAXSW, | |
18666 | ARM_BUILTIN_WMAXSH, | |
18667 | ARM_BUILTIN_WMAXSB, | |
18668 | ARM_BUILTIN_WMAXUW, | |
18669 | ARM_BUILTIN_WMAXUH, | |
18670 | ARM_BUILTIN_WMAXUB, | |
18671 | ARM_BUILTIN_WMINSW, | |
18672 | ARM_BUILTIN_WMINSH, | |
18673 | ARM_BUILTIN_WMINSB, | |
18674 | ARM_BUILTIN_WMINUW, | |
18675 | ARM_BUILTIN_WMINUH, | |
18676 | ARM_BUILTIN_WMINUB, | |
18677 | ||
18678 | ARM_BUILTIN_WMULUM, | |
18679 | ARM_BUILTIN_WMULSM, | |
18680 | ARM_BUILTIN_WMULUL, | |
18681 | ||
18682 | ARM_BUILTIN_PSADBH, | |
18683 | ARM_BUILTIN_WSHUFH, | |
18684 | ||
18685 | ARM_BUILTIN_WSLLH, | |
18686 | ARM_BUILTIN_WSLLW, | |
18687 | ARM_BUILTIN_WSLLD, | |
18688 | ARM_BUILTIN_WSRAH, | |
18689 | ARM_BUILTIN_WSRAW, | |
18690 | ARM_BUILTIN_WSRAD, | |
18691 | ARM_BUILTIN_WSRLH, | |
18692 | ARM_BUILTIN_WSRLW, | |
18693 | ARM_BUILTIN_WSRLD, | |
18694 | ARM_BUILTIN_WRORH, | |
18695 | ARM_BUILTIN_WRORW, | |
18696 | ARM_BUILTIN_WRORD, | |
18697 | ARM_BUILTIN_WSLLHI, | |
18698 | ARM_BUILTIN_WSLLWI, | |
18699 | ARM_BUILTIN_WSLLDI, | |
18700 | ARM_BUILTIN_WSRAHI, | |
18701 | ARM_BUILTIN_WSRAWI, | |
18702 | ARM_BUILTIN_WSRADI, | |
18703 | ARM_BUILTIN_WSRLHI, | |
18704 | ARM_BUILTIN_WSRLWI, | |
18705 | ARM_BUILTIN_WSRLDI, | |
18706 | ARM_BUILTIN_WRORHI, | |
18707 | ARM_BUILTIN_WRORWI, | |
18708 | ARM_BUILTIN_WRORDI, | |
18709 | ||
18710 | ARM_BUILTIN_WUNPCKIHB, | |
18711 | ARM_BUILTIN_WUNPCKIHH, | |
18712 | ARM_BUILTIN_WUNPCKIHW, | |
18713 | ARM_BUILTIN_WUNPCKILB, | |
18714 | ARM_BUILTIN_WUNPCKILH, | |
18715 | ARM_BUILTIN_WUNPCKILW, | |
18716 | ||
18717 | ARM_BUILTIN_WUNPCKEHSB, | |
18718 | ARM_BUILTIN_WUNPCKEHSH, | |
18719 | ARM_BUILTIN_WUNPCKEHSW, | |
18720 | ARM_BUILTIN_WUNPCKEHUB, | |
18721 | ARM_BUILTIN_WUNPCKEHUH, | |
18722 | ARM_BUILTIN_WUNPCKEHUW, | |
18723 | ARM_BUILTIN_WUNPCKELSB, | |
18724 | ARM_BUILTIN_WUNPCKELSH, | |
18725 | ARM_BUILTIN_WUNPCKELSW, | |
18726 | ARM_BUILTIN_WUNPCKELUB, | |
18727 | ARM_BUILTIN_WUNPCKELUH, | |
18728 | ARM_BUILTIN_WUNPCKELUW, | |
18729 | ||
18730 | ARM_BUILTIN_THREAD_POINTER, | |
18731 | ||
18732 | ARM_BUILTIN_NEON_BASE, | |
18733 | ||
18734 | ARM_BUILTIN_MAX = ARM_BUILTIN_NEON_BASE + ARRAY_SIZE (neon_builtin_data) | |
5a9335ef NC |
18735 | }; |
18736 | ||
229a1c59 | 18737 | static GTY(()) tree arm_builtin_decls[ARM_BUILTIN_MAX]; |
5a9335ef NC |
18738 | |
18739 | static void | |
229a1c59 | 18740 | arm_init_neon_builtins (void) |
5a9335ef | 18741 | { |
229a1c59 JZ |
18742 | unsigned int i, fcode; |
18743 | tree decl; | |
5a9335ef | 18744 | |
229a1c59 JZ |
18745 | tree neon_intQI_type_node; |
18746 | tree neon_intHI_type_node; | |
18747 | tree neon_polyQI_type_node; | |
18748 | tree neon_polyHI_type_node; | |
18749 | tree neon_intSI_type_node; | |
18750 | tree neon_intDI_type_node; | |
18751 | tree neon_float_type_node; | |
4a5eab38 | 18752 | |
229a1c59 JZ |
18753 | tree intQI_pointer_node; |
18754 | tree intHI_pointer_node; | |
18755 | tree intSI_pointer_node; | |
18756 | tree intDI_pointer_node; | |
18757 | tree float_pointer_node; | |
5a9335ef | 18758 | |
229a1c59 JZ |
18759 | tree const_intQI_node; |
18760 | tree const_intHI_node; | |
18761 | tree const_intSI_node; | |
18762 | tree const_intDI_node; | |
18763 | tree const_float_node; | |
5a9335ef | 18764 | |
229a1c59 JZ |
18765 | tree const_intQI_pointer_node; |
18766 | tree const_intHI_pointer_node; | |
18767 | tree const_intSI_pointer_node; | |
18768 | tree const_intDI_pointer_node; | |
18769 | tree const_float_pointer_node; | |
5a9335ef | 18770 | |
229a1c59 JZ |
18771 | tree V8QI_type_node; |
18772 | tree V4HI_type_node; | |
18773 | tree V2SI_type_node; | |
18774 | tree V2SF_type_node; | |
18775 | tree V16QI_type_node; | |
18776 | tree V8HI_type_node; | |
18777 | tree V4SI_type_node; | |
18778 | tree V4SF_type_node; | |
18779 | tree V2DI_type_node; | |
5a9335ef | 18780 | |
229a1c59 JZ |
18781 | tree intUQI_type_node; |
18782 | tree intUHI_type_node; | |
18783 | tree intUSI_type_node; | |
18784 | tree intUDI_type_node; | |
5a9335ef | 18785 | |
229a1c59 JZ |
18786 | tree intEI_type_node; |
18787 | tree intOI_type_node; | |
18788 | tree intCI_type_node; | |
18789 | tree intXI_type_node; | |
5a9335ef | 18790 | |
229a1c59 JZ |
18791 | tree V8QI_pointer_node; |
18792 | tree V4HI_pointer_node; | |
18793 | tree V2SI_pointer_node; | |
18794 | tree V2SF_pointer_node; | |
18795 | tree V16QI_pointer_node; | |
18796 | tree V8HI_pointer_node; | |
18797 | tree V4SI_pointer_node; | |
18798 | tree V4SF_pointer_node; | |
18799 | tree V2DI_pointer_node; | |
5a9335ef | 18800 | |
229a1c59 JZ |
18801 | tree void_ftype_pv8qi_v8qi_v8qi; |
18802 | tree void_ftype_pv4hi_v4hi_v4hi; | |
18803 | tree void_ftype_pv2si_v2si_v2si; | |
18804 | tree void_ftype_pv2sf_v2sf_v2sf; | |
18805 | tree void_ftype_pdi_di_di; | |
18806 | tree void_ftype_pv16qi_v16qi_v16qi; | |
18807 | tree void_ftype_pv8hi_v8hi_v8hi; | |
18808 | tree void_ftype_pv4si_v4si_v4si; | |
18809 | tree void_ftype_pv4sf_v4sf_v4sf; | |
18810 | tree void_ftype_pv2di_v2di_v2di; | |
5a9335ef | 18811 | |
229a1c59 JZ |
18812 | tree reinterp_ftype_dreg[5][5]; |
18813 | tree reinterp_ftype_qreg[5][5]; | |
18814 | tree dreg_types[5], qreg_types[5]; | |
af06585a | 18815 | |
88f77cba JB |
18816 | /* Create distinguished type nodes for NEON vector element types, |
18817 | and pointers to values of such types, so we can detect them later. */ | |
af06585a JM |
18818 | neon_intQI_type_node = make_signed_type (GET_MODE_PRECISION (QImode)); |
18819 | neon_intHI_type_node = make_signed_type (GET_MODE_PRECISION (HImode)); | |
18820 | neon_polyQI_type_node = make_signed_type (GET_MODE_PRECISION (QImode)); | |
18821 | neon_polyHI_type_node = make_signed_type (GET_MODE_PRECISION (HImode)); | |
18822 | neon_intSI_type_node = make_signed_type (GET_MODE_PRECISION (SImode)); | |
18823 | neon_intDI_type_node = make_signed_type (GET_MODE_PRECISION (DImode)); | |
18824 | neon_float_type_node = make_node (REAL_TYPE); | |
18825 | TYPE_PRECISION (neon_float_type_node) = FLOAT_TYPE_SIZE; | |
18826 | layout_type (neon_float_type_node); | |
18827 | ||
bcbdbbb0 JM |
18828 | /* Define typedefs which exactly correspond to the modes we are basing vector |
18829 | types on. If you change these names you'll need to change | |
18830 | the table used by arm_mangle_type too. */ | |
18831 | (*lang_hooks.types.register_builtin_type) (neon_intQI_type_node, | |
18832 | "__builtin_neon_qi"); | |
18833 | (*lang_hooks.types.register_builtin_type) (neon_intHI_type_node, | |
18834 | "__builtin_neon_hi"); | |
18835 | (*lang_hooks.types.register_builtin_type) (neon_intSI_type_node, | |
18836 | "__builtin_neon_si"); | |
18837 | (*lang_hooks.types.register_builtin_type) (neon_float_type_node, | |
18838 | "__builtin_neon_sf"); | |
18839 | (*lang_hooks.types.register_builtin_type) (neon_intDI_type_node, | |
18840 | "__builtin_neon_di"); | |
18841 | (*lang_hooks.types.register_builtin_type) (neon_polyQI_type_node, | |
18842 | "__builtin_neon_poly8"); | |
18843 | (*lang_hooks.types.register_builtin_type) (neon_polyHI_type_node, | |
18844 | "__builtin_neon_poly16"); | |
18845 | ||
af06585a JM |
18846 | intQI_pointer_node = build_pointer_type (neon_intQI_type_node); |
18847 | intHI_pointer_node = build_pointer_type (neon_intHI_type_node); | |
18848 | intSI_pointer_node = build_pointer_type (neon_intSI_type_node); | |
18849 | intDI_pointer_node = build_pointer_type (neon_intDI_type_node); | |
18850 | float_pointer_node = build_pointer_type (neon_float_type_node); | |
88f77cba JB |
18851 | |
18852 | /* Next create constant-qualified versions of the above types. */ | |
af06585a JM |
18853 | const_intQI_node = build_qualified_type (neon_intQI_type_node, |
18854 | TYPE_QUAL_CONST); | |
18855 | const_intHI_node = build_qualified_type (neon_intHI_type_node, | |
18856 | TYPE_QUAL_CONST); | |
18857 | const_intSI_node = build_qualified_type (neon_intSI_type_node, | |
18858 | TYPE_QUAL_CONST); | |
18859 | const_intDI_node = build_qualified_type (neon_intDI_type_node, | |
18860 | TYPE_QUAL_CONST); | |
18861 | const_float_node = build_qualified_type (neon_float_type_node, | |
18862 | TYPE_QUAL_CONST); | |
18863 | ||
18864 | const_intQI_pointer_node = build_pointer_type (const_intQI_node); | |
18865 | const_intHI_pointer_node = build_pointer_type (const_intHI_node); | |
18866 | const_intSI_pointer_node = build_pointer_type (const_intSI_node); | |
18867 | const_intDI_pointer_node = build_pointer_type (const_intDI_node); | |
18868 | const_float_pointer_node = build_pointer_type (const_float_node); | |
88f77cba JB |
18869 | |
18870 | /* Now create vector types based on our NEON element types. */ | |
18871 | /* 64-bit vectors. */ | |
af06585a | 18872 | V8QI_type_node = |
88f77cba | 18873 | build_vector_type_for_mode (neon_intQI_type_node, V8QImode); |
af06585a | 18874 | V4HI_type_node = |
88f77cba | 18875 | build_vector_type_for_mode (neon_intHI_type_node, V4HImode); |
af06585a | 18876 | V2SI_type_node = |
88f77cba | 18877 | build_vector_type_for_mode (neon_intSI_type_node, V2SImode); |
af06585a | 18878 | V2SF_type_node = |
88f77cba JB |
18879 | build_vector_type_for_mode (neon_float_type_node, V2SFmode); |
18880 | /* 128-bit vectors. */ | |
af06585a | 18881 | V16QI_type_node = |
88f77cba | 18882 | build_vector_type_for_mode (neon_intQI_type_node, V16QImode); |
af06585a | 18883 | V8HI_type_node = |
88f77cba | 18884 | build_vector_type_for_mode (neon_intHI_type_node, V8HImode); |
af06585a | 18885 | V4SI_type_node = |
88f77cba | 18886 | build_vector_type_for_mode (neon_intSI_type_node, V4SImode); |
af06585a | 18887 | V4SF_type_node = |
88f77cba | 18888 | build_vector_type_for_mode (neon_float_type_node, V4SFmode); |
af06585a | 18889 | V2DI_type_node = |
88f77cba JB |
18890 | build_vector_type_for_mode (neon_intDI_type_node, V2DImode); |
18891 | ||
18892 | /* Unsigned integer types for various mode sizes. */ | |
af06585a JM |
18893 | intUQI_type_node = make_unsigned_type (GET_MODE_PRECISION (QImode)); |
18894 | intUHI_type_node = make_unsigned_type (GET_MODE_PRECISION (HImode)); | |
18895 | intUSI_type_node = make_unsigned_type (GET_MODE_PRECISION (SImode)); | |
18896 | intUDI_type_node = make_unsigned_type (GET_MODE_PRECISION (DImode)); | |
88f77cba | 18897 | |
bcbdbbb0 JM |
18898 | (*lang_hooks.types.register_builtin_type) (intUQI_type_node, |
18899 | "__builtin_neon_uqi"); | |
18900 | (*lang_hooks.types.register_builtin_type) (intUHI_type_node, | |
18901 | "__builtin_neon_uhi"); | |
18902 | (*lang_hooks.types.register_builtin_type) (intUSI_type_node, | |
18903 | "__builtin_neon_usi"); | |
18904 | (*lang_hooks.types.register_builtin_type) (intUDI_type_node, | |
18905 | "__builtin_neon_udi"); | |
18906 | ||
88f77cba | 18907 | /* Opaque integer types for structures of vectors. */ |
af06585a JM |
18908 | intEI_type_node = make_signed_type (GET_MODE_PRECISION (EImode)); |
18909 | intOI_type_node = make_signed_type (GET_MODE_PRECISION (OImode)); | |
18910 | intCI_type_node = make_signed_type (GET_MODE_PRECISION (CImode)); | |
18911 | intXI_type_node = make_signed_type (GET_MODE_PRECISION (XImode)); | |
88f77cba | 18912 | |
bcbdbbb0 JM |
18913 | (*lang_hooks.types.register_builtin_type) (intTI_type_node, |
18914 | "__builtin_neon_ti"); | |
18915 | (*lang_hooks.types.register_builtin_type) (intEI_type_node, | |
18916 | "__builtin_neon_ei"); | |
18917 | (*lang_hooks.types.register_builtin_type) (intOI_type_node, | |
18918 | "__builtin_neon_oi"); | |
18919 | (*lang_hooks.types.register_builtin_type) (intCI_type_node, | |
18920 | "__builtin_neon_ci"); | |
18921 | (*lang_hooks.types.register_builtin_type) (intXI_type_node, | |
18922 | "__builtin_neon_xi"); | |
18923 | ||
88f77cba | 18924 | /* Pointers to vector types. */ |
af06585a JM |
18925 | V8QI_pointer_node = build_pointer_type (V8QI_type_node); |
18926 | V4HI_pointer_node = build_pointer_type (V4HI_type_node); | |
18927 | V2SI_pointer_node = build_pointer_type (V2SI_type_node); | |
18928 | V2SF_pointer_node = build_pointer_type (V2SF_type_node); | |
18929 | V16QI_pointer_node = build_pointer_type (V16QI_type_node); | |
18930 | V8HI_pointer_node = build_pointer_type (V8HI_type_node); | |
18931 | V4SI_pointer_node = build_pointer_type (V4SI_type_node); | |
18932 | V4SF_pointer_node = build_pointer_type (V4SF_type_node); | |
18933 | V2DI_pointer_node = build_pointer_type (V2DI_type_node); | |
88f77cba JB |
18934 | |
18935 | /* Operations which return results as pairs. */ | |
af06585a | 18936 | void_ftype_pv8qi_v8qi_v8qi = |
88f77cba JB |
18937 | build_function_type_list (void_type_node, V8QI_pointer_node, V8QI_type_node, |
18938 | V8QI_type_node, NULL); | |
af06585a | 18939 | void_ftype_pv4hi_v4hi_v4hi = |
88f77cba JB |
18940 | build_function_type_list (void_type_node, V4HI_pointer_node, V4HI_type_node, |
18941 | V4HI_type_node, NULL); | |
af06585a | 18942 | void_ftype_pv2si_v2si_v2si = |
88f77cba JB |
18943 | build_function_type_list (void_type_node, V2SI_pointer_node, V2SI_type_node, |
18944 | V2SI_type_node, NULL); | |
af06585a | 18945 | void_ftype_pv2sf_v2sf_v2sf = |
88f77cba JB |
18946 | build_function_type_list (void_type_node, V2SF_pointer_node, V2SF_type_node, |
18947 | V2SF_type_node, NULL); | |
af06585a | 18948 | void_ftype_pdi_di_di = |
88f77cba JB |
18949 | build_function_type_list (void_type_node, intDI_pointer_node, |
18950 | neon_intDI_type_node, neon_intDI_type_node, NULL); | |
af06585a | 18951 | void_ftype_pv16qi_v16qi_v16qi = |
88f77cba JB |
18952 | build_function_type_list (void_type_node, V16QI_pointer_node, |
18953 | V16QI_type_node, V16QI_type_node, NULL); | |
af06585a | 18954 | void_ftype_pv8hi_v8hi_v8hi = |
88f77cba JB |
18955 | build_function_type_list (void_type_node, V8HI_pointer_node, V8HI_type_node, |
18956 | V8HI_type_node, NULL); | |
af06585a | 18957 | void_ftype_pv4si_v4si_v4si = |
88f77cba JB |
18958 | build_function_type_list (void_type_node, V4SI_pointer_node, V4SI_type_node, |
18959 | V4SI_type_node, NULL); | |
af06585a | 18960 | void_ftype_pv4sf_v4sf_v4sf = |
88f77cba JB |
18961 | build_function_type_list (void_type_node, V4SF_pointer_node, V4SF_type_node, |
18962 | V4SF_type_node, NULL); | |
af06585a | 18963 | void_ftype_pv2di_v2di_v2di = |
88f77cba JB |
18964 | build_function_type_list (void_type_node, V2DI_pointer_node, V2DI_type_node, |
18965 | V2DI_type_node, NULL); | |
18966 | ||
88f77cba JB |
18967 | dreg_types[0] = V8QI_type_node; |
18968 | dreg_types[1] = V4HI_type_node; | |
18969 | dreg_types[2] = V2SI_type_node; | |
18970 | dreg_types[3] = V2SF_type_node; | |
18971 | dreg_types[4] = neon_intDI_type_node; | |
18972 | ||
229a1c59 JZ |
18973 | qreg_types[0] = V16QI_type_node; |
18974 | qreg_types[1] = V8HI_type_node; | |
18975 | qreg_types[2] = V4SI_type_node; | |
18976 | qreg_types[3] = V4SF_type_node; | |
18977 | qreg_types[4] = V2DI_type_node; | |
18978 | ||
18979 | for (i = 0; i < 5; i++) | |
18980 | { | |
18981 | int j; | |
18982 | for (j = 0; j < 5; j++) | |
18983 | { | |
18984 | reinterp_ftype_dreg[i][j] | |
18985 | = build_function_type_list (dreg_types[i], dreg_types[j], NULL); | |
18986 | reinterp_ftype_qreg[i][j] | |
18987 | = build_function_type_list (qreg_types[i], qreg_types[j], NULL); | |
18988 | } | |
18989 | } | |
18990 | ||
18991 | for (i = 0, fcode = ARM_BUILTIN_NEON_BASE; | |
18992 | i < ARRAY_SIZE (neon_builtin_data); | |
18993 | i++, fcode++) | |
18994 | { | |
18995 | neon_builtin_datum *d = &neon_builtin_data[i]; | |
18996 | ||
18997 | const char* const modenames[] = { | |
18998 | "v8qi", "v4hi", "v2si", "v2sf", "di", | |
18999 | "v16qi", "v8hi", "v4si", "v4sf", "v2di", | |
19000 | "ti", "ei", "oi" | |
19001 | }; | |
19002 | char namebuf[60]; | |
19003 | tree ftype = NULL; | |
19004 | int is_load = 0, is_store = 0; | |
19005 | ||
19006 | gcc_assert (ARRAY_SIZE (modenames) == T_MAX); | |
19007 | ||
19008 | d->fcode = fcode; | |
19009 | ||
19010 | switch (d->itype) | |
19011 | { | |
19012 | case NEON_LOAD1: | |
19013 | case NEON_LOAD1LANE: | |
19014 | case NEON_LOADSTRUCT: | |
19015 | case NEON_LOADSTRUCTLANE: | |
19016 | is_load = 1; | |
19017 | /* Fall through. */ | |
19018 | case NEON_STORE1: | |
19019 | case NEON_STORE1LANE: | |
19020 | case NEON_STORESTRUCT: | |
19021 | case NEON_STORESTRUCTLANE: | |
19022 | if (!is_load) | |
19023 | is_store = 1; | |
19024 | /* Fall through. */ | |
19025 | case NEON_UNOP: | |
19026 | case NEON_BINOP: | |
19027 | case NEON_LOGICBINOP: | |
19028 | case NEON_SHIFTINSERT: | |
19029 | case NEON_TERNOP: | |
19030 | case NEON_GETLANE: | |
19031 | case NEON_SETLANE: | |
19032 | case NEON_CREATE: | |
19033 | case NEON_DUP: | |
19034 | case NEON_DUPLANE: | |
19035 | case NEON_SHIFTIMM: | |
19036 | case NEON_SHIFTACC: | |
19037 | case NEON_COMBINE: | |
19038 | case NEON_SPLIT: | |
19039 | case NEON_CONVERT: | |
19040 | case NEON_FIXCONV: | |
19041 | case NEON_LANEMUL: | |
19042 | case NEON_LANEMULL: | |
19043 | case NEON_LANEMULH: | |
19044 | case NEON_LANEMAC: | |
19045 | case NEON_SCALARMUL: | |
19046 | case NEON_SCALARMULL: | |
19047 | case NEON_SCALARMULH: | |
19048 | case NEON_SCALARMAC: | |
19049 | case NEON_SELECT: | |
19050 | case NEON_VTBL: | |
19051 | case NEON_VTBX: | |
19052 | { | |
19053 | int k; | |
19054 | tree return_type = void_type_node, args = void_list_node; | |
19055 | ||
19056 | /* Build a function type directly from the insn_data for | |
19057 | this builtin. The build_function_type() function takes | |
19058 | care of removing duplicates for us. */ | |
19059 | for (k = insn_data[d->code].n_generator_args - 1; k >= 0; k--) | |
19060 | { | |
19061 | tree eltype; | |
19062 | ||
19063 | if (is_load && k == 1) | |
19064 | { | |
19065 | /* Neon load patterns always have the memory | |
19066 | operand in the operand 1 position. */ | |
19067 | gcc_assert (insn_data[d->code].operand[k].predicate | |
19068 | == neon_struct_operand); | |
19069 | ||
19070 | switch (d->mode) | |
19071 | { | |
19072 | case T_V8QI: | |
19073 | case T_V16QI: | |
19074 | eltype = const_intQI_pointer_node; | |
19075 | break; | |
19076 | ||
19077 | case T_V4HI: | |
19078 | case T_V8HI: | |
19079 | eltype = const_intHI_pointer_node; | |
19080 | break; | |
19081 | ||
19082 | case T_V2SI: | |
19083 | case T_V4SI: | |
19084 | eltype = const_intSI_pointer_node; | |
19085 | break; | |
19086 | ||
19087 | case T_V2SF: | |
19088 | case T_V4SF: | |
19089 | eltype = const_float_pointer_node; | |
19090 | break; | |
19091 | ||
19092 | case T_DI: | |
19093 | case T_V2DI: | |
19094 | eltype = const_intDI_pointer_node; | |
19095 | break; | |
19096 | ||
19097 | default: gcc_unreachable (); | |
19098 | } | |
19099 | } | |
19100 | else if (is_store && k == 0) | |
19101 | { | |
19102 | /* Similarly, Neon store patterns use operand 0 as | |
19103 | the memory location to store to. */ | |
19104 | gcc_assert (insn_data[d->code].operand[k].predicate | |
19105 | == neon_struct_operand); | |
19106 | ||
19107 | switch (d->mode) | |
19108 | { | |
19109 | case T_V8QI: | |
19110 | case T_V16QI: | |
19111 | eltype = intQI_pointer_node; | |
19112 | break; | |
19113 | ||
19114 | case T_V4HI: | |
19115 | case T_V8HI: | |
19116 | eltype = intHI_pointer_node; | |
19117 | break; | |
19118 | ||
19119 | case T_V2SI: | |
19120 | case T_V4SI: | |
19121 | eltype = intSI_pointer_node; | |
19122 | break; | |
19123 | ||
19124 | case T_V2SF: | |
19125 | case T_V4SF: | |
19126 | eltype = float_pointer_node; | |
19127 | break; | |
19128 | ||
19129 | case T_DI: | |
19130 | case T_V2DI: | |
19131 | eltype = intDI_pointer_node; | |
19132 | break; | |
19133 | ||
19134 | default: gcc_unreachable (); | |
19135 | } | |
19136 | } | |
19137 | else | |
19138 | { | |
19139 | switch (insn_data[d->code].operand[k].mode) | |
19140 | { | |
19141 | case VOIDmode: eltype = void_type_node; break; | |
19142 | /* Scalars. */ | |
19143 | case QImode: eltype = neon_intQI_type_node; break; | |
19144 | case HImode: eltype = neon_intHI_type_node; break; | |
19145 | case SImode: eltype = neon_intSI_type_node; break; | |
19146 | case SFmode: eltype = neon_float_type_node; break; | |
19147 | case DImode: eltype = neon_intDI_type_node; break; | |
19148 | case TImode: eltype = intTI_type_node; break; | |
19149 | case EImode: eltype = intEI_type_node; break; | |
19150 | case OImode: eltype = intOI_type_node; break; | |
19151 | case CImode: eltype = intCI_type_node; break; | |
19152 | case XImode: eltype = intXI_type_node; break; | |
19153 | /* 64-bit vectors. */ | |
19154 | case V8QImode: eltype = V8QI_type_node; break; | |
19155 | case V4HImode: eltype = V4HI_type_node; break; | |
19156 | case V2SImode: eltype = V2SI_type_node; break; | |
19157 | case V2SFmode: eltype = V2SF_type_node; break; | |
19158 | /* 128-bit vectors. */ | |
19159 | case V16QImode: eltype = V16QI_type_node; break; | |
19160 | case V8HImode: eltype = V8HI_type_node; break; | |
19161 | case V4SImode: eltype = V4SI_type_node; break; | |
19162 | case V4SFmode: eltype = V4SF_type_node; break; | |
19163 | case V2DImode: eltype = V2DI_type_node; break; | |
19164 | default: gcc_unreachable (); | |
19165 | } | |
19166 | } | |
19167 | ||
19168 | if (k == 0 && !is_store) | |
19169 | return_type = eltype; | |
19170 | else | |
19171 | args = tree_cons (NULL_TREE, eltype, args); | |
19172 | } | |
19173 | ||
19174 | ftype = build_function_type (return_type, args); | |
19175 | } | |
19176 | break; | |
19177 | ||
19178 | case NEON_RESULTPAIR: | |
19179 | { | |
19180 | switch (insn_data[d->code].operand[1].mode) | |
19181 | { | |
19182 | case V8QImode: ftype = void_ftype_pv8qi_v8qi_v8qi; break; | |
19183 | case V4HImode: ftype = void_ftype_pv4hi_v4hi_v4hi; break; | |
19184 | case V2SImode: ftype = void_ftype_pv2si_v2si_v2si; break; | |
19185 | case V2SFmode: ftype = void_ftype_pv2sf_v2sf_v2sf; break; | |
19186 | case DImode: ftype = void_ftype_pdi_di_di; break; | |
19187 | case V16QImode: ftype = void_ftype_pv16qi_v16qi_v16qi; break; | |
19188 | case V8HImode: ftype = void_ftype_pv8hi_v8hi_v8hi; break; | |
19189 | case V4SImode: ftype = void_ftype_pv4si_v4si_v4si; break; | |
19190 | case V4SFmode: ftype = void_ftype_pv4sf_v4sf_v4sf; break; | |
19191 | case V2DImode: ftype = void_ftype_pv2di_v2di_v2di; break; | |
19192 | default: gcc_unreachable (); | |
19193 | } | |
19194 | } | |
19195 | break; | |
19196 | ||
19197 | case NEON_REINTERP: | |
19198 | { | |
19199 | /* We iterate over 5 doubleword types, then 5 quadword | |
19200 | types. */ | |
19201 | int rhs = d->mode % 5; | |
19202 | switch (insn_data[d->code].operand[0].mode) | |
19203 | { | |
19204 | case V8QImode: ftype = reinterp_ftype_dreg[0][rhs]; break; | |
19205 | case V4HImode: ftype = reinterp_ftype_dreg[1][rhs]; break; | |
19206 | case V2SImode: ftype = reinterp_ftype_dreg[2][rhs]; break; | |
19207 | case V2SFmode: ftype = reinterp_ftype_dreg[3][rhs]; break; | |
19208 | case DImode: ftype = reinterp_ftype_dreg[4][rhs]; break; | |
19209 | case V16QImode: ftype = reinterp_ftype_qreg[0][rhs]; break; | |
19210 | case V8HImode: ftype = reinterp_ftype_qreg[1][rhs]; break; | |
19211 | case V4SImode: ftype = reinterp_ftype_qreg[2][rhs]; break; | |
19212 | case V4SFmode: ftype = reinterp_ftype_qreg[3][rhs]; break; | |
19213 | case V2DImode: ftype = reinterp_ftype_qreg[4][rhs]; break; | |
19214 | default: gcc_unreachable (); | |
19215 | } | |
19216 | } | |
19217 | break; | |
19218 | ||
19219 | default: | |
19220 | gcc_unreachable (); | |
19221 | } | |
19222 | ||
19223 | gcc_assert (ftype != NULL); | |
19224 | ||
19225 | sprintf (namebuf, "__builtin_neon_%s%s", d->name, modenames[d->mode]); | |
19226 | ||
19227 | decl = add_builtin_function (namebuf, ftype, fcode, BUILT_IN_MD, NULL, | |
19228 | NULL_TREE); | |
19229 | arm_builtin_decls[fcode] = decl; | |
19230 | } | |
19231 | } | |
19232 | ||
19233 | #define def_mbuiltin(MASK, NAME, TYPE, CODE) \ | |
19234 | do \ | |
19235 | { \ | |
19236 | if ((MASK) & insn_flags) \ | |
19237 | { \ | |
19238 | tree bdecl; \ | |
19239 | bdecl = add_builtin_function ((NAME), (TYPE), (CODE), \ | |
19240 | BUILT_IN_MD, NULL, NULL_TREE); \ | |
19241 | arm_builtin_decls[CODE] = bdecl; \ | |
19242 | } \ | |
19243 | } \ | |
19244 | while (0) | |
19245 | ||
19246 | struct builtin_description | |
19247 | { | |
19248 | const unsigned int mask; | |
19249 | const enum insn_code icode; | |
19250 | const char * const name; | |
19251 | const enum arm_builtins code; | |
19252 | const enum rtx_code comparison; | |
19253 | const unsigned int flag; | |
19254 | }; | |
19255 | ||
19256 | static const struct builtin_description bdesc_2arg[] = | |
19257 | { | |
19258 | #define IWMMXT_BUILTIN(code, string, builtin) \ | |
19259 | { FL_IWMMXT, CODE_FOR_##code, "__builtin_arm_" string, \ | |
19260 | ARM_BUILTIN_##builtin, UNKNOWN, 0 }, | |
19261 | ||
19262 | IWMMXT_BUILTIN (addv8qi3, "waddb", WADDB) | |
19263 | IWMMXT_BUILTIN (addv4hi3, "waddh", WADDH) | |
19264 | IWMMXT_BUILTIN (addv2si3, "waddw", WADDW) | |
19265 | IWMMXT_BUILTIN (subv8qi3, "wsubb", WSUBB) | |
19266 | IWMMXT_BUILTIN (subv4hi3, "wsubh", WSUBH) | |
19267 | IWMMXT_BUILTIN (subv2si3, "wsubw", WSUBW) | |
19268 | IWMMXT_BUILTIN (ssaddv8qi3, "waddbss", WADDSSB) | |
19269 | IWMMXT_BUILTIN (ssaddv4hi3, "waddhss", WADDSSH) | |
19270 | IWMMXT_BUILTIN (ssaddv2si3, "waddwss", WADDSSW) | |
19271 | IWMMXT_BUILTIN (sssubv8qi3, "wsubbss", WSUBSSB) | |
19272 | IWMMXT_BUILTIN (sssubv4hi3, "wsubhss", WSUBSSH) | |
19273 | IWMMXT_BUILTIN (sssubv2si3, "wsubwss", WSUBSSW) | |
19274 | IWMMXT_BUILTIN (usaddv8qi3, "waddbus", WADDUSB) | |
19275 | IWMMXT_BUILTIN (usaddv4hi3, "waddhus", WADDUSH) | |
19276 | IWMMXT_BUILTIN (usaddv2si3, "waddwus", WADDUSW) | |
19277 | IWMMXT_BUILTIN (ussubv8qi3, "wsubbus", WSUBUSB) | |
19278 | IWMMXT_BUILTIN (ussubv4hi3, "wsubhus", WSUBUSH) | |
19279 | IWMMXT_BUILTIN (ussubv2si3, "wsubwus", WSUBUSW) | |
19280 | IWMMXT_BUILTIN (mulv4hi3, "wmulul", WMULUL) | |
19281 | IWMMXT_BUILTIN (smulv4hi3_highpart, "wmulsm", WMULSM) | |
19282 | IWMMXT_BUILTIN (umulv4hi3_highpart, "wmulum", WMULUM) | |
19283 | IWMMXT_BUILTIN (eqv8qi3, "wcmpeqb", WCMPEQB) | |
19284 | IWMMXT_BUILTIN (eqv4hi3, "wcmpeqh", WCMPEQH) | |
19285 | IWMMXT_BUILTIN (eqv2si3, "wcmpeqw", WCMPEQW) | |
19286 | IWMMXT_BUILTIN (gtuv8qi3, "wcmpgtub", WCMPGTUB) | |
19287 | IWMMXT_BUILTIN (gtuv4hi3, "wcmpgtuh", WCMPGTUH) | |
19288 | IWMMXT_BUILTIN (gtuv2si3, "wcmpgtuw", WCMPGTUW) | |
19289 | IWMMXT_BUILTIN (gtv8qi3, "wcmpgtsb", WCMPGTSB) | |
19290 | IWMMXT_BUILTIN (gtv4hi3, "wcmpgtsh", WCMPGTSH) | |
19291 | IWMMXT_BUILTIN (gtv2si3, "wcmpgtsw", WCMPGTSW) | |
19292 | IWMMXT_BUILTIN (umaxv8qi3, "wmaxub", WMAXUB) | |
19293 | IWMMXT_BUILTIN (smaxv8qi3, "wmaxsb", WMAXSB) | |
19294 | IWMMXT_BUILTIN (umaxv4hi3, "wmaxuh", WMAXUH) | |
19295 | IWMMXT_BUILTIN (smaxv4hi3, "wmaxsh", WMAXSH) | |
19296 | IWMMXT_BUILTIN (umaxv2si3, "wmaxuw", WMAXUW) | |
19297 | IWMMXT_BUILTIN (smaxv2si3, "wmaxsw", WMAXSW) | |
19298 | IWMMXT_BUILTIN (uminv8qi3, "wminub", WMINUB) | |
19299 | IWMMXT_BUILTIN (sminv8qi3, "wminsb", WMINSB) | |
19300 | IWMMXT_BUILTIN (uminv4hi3, "wminuh", WMINUH) | |
19301 | IWMMXT_BUILTIN (sminv4hi3, "wminsh", WMINSH) | |
19302 | IWMMXT_BUILTIN (uminv2si3, "wminuw", WMINUW) | |
19303 | IWMMXT_BUILTIN (sminv2si3, "wminsw", WMINSW) | |
19304 | IWMMXT_BUILTIN (iwmmxt_anddi3, "wand", WAND) | |
19305 | IWMMXT_BUILTIN (iwmmxt_nanddi3, "wandn", WANDN) | |
19306 | IWMMXT_BUILTIN (iwmmxt_iordi3, "wor", WOR) | |
19307 | IWMMXT_BUILTIN (iwmmxt_xordi3, "wxor", WXOR) | |
19308 | IWMMXT_BUILTIN (iwmmxt_uavgv8qi3, "wavg2b", WAVG2B) | |
19309 | IWMMXT_BUILTIN (iwmmxt_uavgv4hi3, "wavg2h", WAVG2H) | |
19310 | IWMMXT_BUILTIN (iwmmxt_uavgrndv8qi3, "wavg2br", WAVG2BR) | |
19311 | IWMMXT_BUILTIN (iwmmxt_uavgrndv4hi3, "wavg2hr", WAVG2HR) | |
19312 | IWMMXT_BUILTIN (iwmmxt_wunpckilb, "wunpckilb", WUNPCKILB) | |
19313 | IWMMXT_BUILTIN (iwmmxt_wunpckilh, "wunpckilh", WUNPCKILH) | |
19314 | IWMMXT_BUILTIN (iwmmxt_wunpckilw, "wunpckilw", WUNPCKILW) | |
19315 | IWMMXT_BUILTIN (iwmmxt_wunpckihb, "wunpckihb", WUNPCKIHB) | |
19316 | IWMMXT_BUILTIN (iwmmxt_wunpckihh, "wunpckihh", WUNPCKIHH) | |
19317 | IWMMXT_BUILTIN (iwmmxt_wunpckihw, "wunpckihw", WUNPCKIHW) | |
19318 | IWMMXT_BUILTIN (iwmmxt_wmadds, "wmadds", WMADDS) | |
19319 | IWMMXT_BUILTIN (iwmmxt_wmaddu, "wmaddu", WMADDU) | |
19320 | ||
19321 | #define IWMMXT_BUILTIN2(code, builtin) \ | |
19322 | { FL_IWMMXT, CODE_FOR_##code, NULL, ARM_BUILTIN_##builtin, UNKNOWN, 0 }, | |
19323 | ||
19324 | IWMMXT_BUILTIN2 (iwmmxt_wpackhss, WPACKHSS) | |
19325 | IWMMXT_BUILTIN2 (iwmmxt_wpackwss, WPACKWSS) | |
19326 | IWMMXT_BUILTIN2 (iwmmxt_wpackdss, WPACKDSS) | |
19327 | IWMMXT_BUILTIN2 (iwmmxt_wpackhus, WPACKHUS) | |
19328 | IWMMXT_BUILTIN2 (iwmmxt_wpackwus, WPACKWUS) | |
19329 | IWMMXT_BUILTIN2 (iwmmxt_wpackdus, WPACKDUS) | |
19330 | IWMMXT_BUILTIN2 (ashlv4hi3_di, WSLLH) | |
19331 | IWMMXT_BUILTIN2 (ashlv4hi3_iwmmxt, WSLLHI) | |
19332 | IWMMXT_BUILTIN2 (ashlv2si3_di, WSLLW) | |
19333 | IWMMXT_BUILTIN2 (ashlv2si3_iwmmxt, WSLLWI) | |
19334 | IWMMXT_BUILTIN2 (ashldi3_di, WSLLD) | |
19335 | IWMMXT_BUILTIN2 (ashldi3_iwmmxt, WSLLDI) | |
19336 | IWMMXT_BUILTIN2 (lshrv4hi3_di, WSRLH) | |
19337 | IWMMXT_BUILTIN2 (lshrv4hi3_iwmmxt, WSRLHI) | |
19338 | IWMMXT_BUILTIN2 (lshrv2si3_di, WSRLW) | |
19339 | IWMMXT_BUILTIN2 (lshrv2si3_iwmmxt, WSRLWI) | |
19340 | IWMMXT_BUILTIN2 (lshrdi3_di, WSRLD) | |
19341 | IWMMXT_BUILTIN2 (lshrdi3_iwmmxt, WSRLDI) | |
19342 | IWMMXT_BUILTIN2 (ashrv4hi3_di, WSRAH) | |
19343 | IWMMXT_BUILTIN2 (ashrv4hi3_iwmmxt, WSRAHI) | |
19344 | IWMMXT_BUILTIN2 (ashrv2si3_di, WSRAW) | |
19345 | IWMMXT_BUILTIN2 (ashrv2si3_iwmmxt, WSRAWI) | |
19346 | IWMMXT_BUILTIN2 (ashrdi3_di, WSRAD) | |
19347 | IWMMXT_BUILTIN2 (ashrdi3_iwmmxt, WSRADI) | |
19348 | IWMMXT_BUILTIN2 (rorv4hi3_di, WRORH) | |
19349 | IWMMXT_BUILTIN2 (rorv4hi3, WRORHI) | |
19350 | IWMMXT_BUILTIN2 (rorv2si3_di, WRORW) | |
19351 | IWMMXT_BUILTIN2 (rorv2si3, WRORWI) | |
19352 | IWMMXT_BUILTIN2 (rordi3_di, WRORD) | |
19353 | IWMMXT_BUILTIN2 (rordi3, WRORDI) | |
19354 | IWMMXT_BUILTIN2 (iwmmxt_wmacuz, WMACUZ) | |
19355 | IWMMXT_BUILTIN2 (iwmmxt_wmacsz, WMACSZ) | |
19356 | }; | |
19357 | ||
19358 | static const struct builtin_description bdesc_1arg[] = | |
19359 | { | |
19360 | IWMMXT_BUILTIN (iwmmxt_tmovmskb, "tmovmskb", TMOVMSKB) | |
19361 | IWMMXT_BUILTIN (iwmmxt_tmovmskh, "tmovmskh", TMOVMSKH) | |
19362 | IWMMXT_BUILTIN (iwmmxt_tmovmskw, "tmovmskw", TMOVMSKW) | |
19363 | IWMMXT_BUILTIN (iwmmxt_waccb, "waccb", WACCB) | |
19364 | IWMMXT_BUILTIN (iwmmxt_wacch, "wacch", WACCH) | |
19365 | IWMMXT_BUILTIN (iwmmxt_waccw, "waccw", WACCW) | |
19366 | IWMMXT_BUILTIN (iwmmxt_wunpckehub, "wunpckehub", WUNPCKEHUB) | |
19367 | IWMMXT_BUILTIN (iwmmxt_wunpckehuh, "wunpckehuh", WUNPCKEHUH) | |
19368 | IWMMXT_BUILTIN (iwmmxt_wunpckehuw, "wunpckehuw", WUNPCKEHUW) | |
19369 | IWMMXT_BUILTIN (iwmmxt_wunpckehsb, "wunpckehsb", WUNPCKEHSB) | |
19370 | IWMMXT_BUILTIN (iwmmxt_wunpckehsh, "wunpckehsh", WUNPCKEHSH) | |
19371 | IWMMXT_BUILTIN (iwmmxt_wunpckehsw, "wunpckehsw", WUNPCKEHSW) | |
19372 | IWMMXT_BUILTIN (iwmmxt_wunpckelub, "wunpckelub", WUNPCKELUB) | |
19373 | IWMMXT_BUILTIN (iwmmxt_wunpckeluh, "wunpckeluh", WUNPCKELUH) | |
19374 | IWMMXT_BUILTIN (iwmmxt_wunpckeluw, "wunpckeluw", WUNPCKELUW) | |
19375 | IWMMXT_BUILTIN (iwmmxt_wunpckelsb, "wunpckelsb", WUNPCKELSB) | |
19376 | IWMMXT_BUILTIN (iwmmxt_wunpckelsh, "wunpckelsh", WUNPCKELSH) | |
19377 | IWMMXT_BUILTIN (iwmmxt_wunpckelsw, "wunpckelsw", WUNPCKELSW) | |
19378 | }; | |
19379 | ||
19380 | /* Set up all the iWMMXt builtins. This is not called if | |
19381 | TARGET_IWMMXT is zero. */ | |
19382 | ||
19383 | static void | |
19384 | arm_init_iwmmxt_builtins (void) | |
19385 | { | |
19386 | const struct builtin_description * d; | |
19387 | size_t i; | |
229a1c59 JZ |
19388 | |
19389 | tree V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode); | |
19390 | tree V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode); | |
19391 | tree V8QI_type_node = build_vector_type_for_mode (intQI_type_node, V8QImode); | |
19392 | ||
19393 | tree int_ftype_int | |
4fe058e2 NF |
19394 | = build_function_type_list (integer_type_node, |
19395 | integer_type_node, NULL_TREE); | |
229a1c59 | 19396 | tree v8qi_ftype_v8qi_v8qi_int |
4fe058e2 NF |
19397 | = build_function_type_list (V8QI_type_node, |
19398 | V8QI_type_node, V8QI_type_node, | |
19399 | integer_type_node, NULL_TREE); | |
229a1c59 | 19400 | tree v4hi_ftype_v4hi_int |
4fe058e2 NF |
19401 | = build_function_type_list (V4HI_type_node, |
19402 | V4HI_type_node, integer_type_node, NULL_TREE); | |
229a1c59 | 19403 | tree v2si_ftype_v2si_int |
4fe058e2 NF |
19404 | = build_function_type_list (V2SI_type_node, |
19405 | V2SI_type_node, integer_type_node, NULL_TREE); | |
229a1c59 | 19406 | tree v2si_ftype_di_di |
4fe058e2 NF |
19407 | = build_function_type_list (V2SI_type_node, |
19408 | long_long_integer_type_node, | |
19409 | long_long_integer_type_node, | |
19410 | NULL_TREE); | |
229a1c59 | 19411 | tree di_ftype_di_int |
4fe058e2 NF |
19412 | = build_function_type_list (long_long_integer_type_node, |
19413 | long_long_integer_type_node, | |
19414 | integer_type_node, NULL_TREE); | |
229a1c59 | 19415 | tree di_ftype_di_int_int |
4fe058e2 NF |
19416 | = build_function_type_list (long_long_integer_type_node, |
19417 | long_long_integer_type_node, | |
19418 | integer_type_node, | |
19419 | integer_type_node, NULL_TREE); | |
229a1c59 | 19420 | tree int_ftype_v8qi |
4fe058e2 NF |
19421 | = build_function_type_list (integer_type_node, |
19422 | V8QI_type_node, NULL_TREE); | |
229a1c59 | 19423 | tree int_ftype_v4hi |
4fe058e2 NF |
19424 | = build_function_type_list (integer_type_node, |
19425 | V4HI_type_node, NULL_TREE); | |
229a1c59 | 19426 | tree int_ftype_v2si |
4fe058e2 NF |
19427 | = build_function_type_list (integer_type_node, |
19428 | V2SI_type_node, NULL_TREE); | |
229a1c59 | 19429 | tree int_ftype_v8qi_int |
4fe058e2 NF |
19430 | = build_function_type_list (integer_type_node, |
19431 | V8QI_type_node, integer_type_node, NULL_TREE); | |
229a1c59 | 19432 | tree int_ftype_v4hi_int |
4fe058e2 NF |
19433 | = build_function_type_list (integer_type_node, |
19434 | V4HI_type_node, integer_type_node, NULL_TREE); | |
229a1c59 | 19435 | tree int_ftype_v2si_int |
4fe058e2 NF |
19436 | = build_function_type_list (integer_type_node, |
19437 | V2SI_type_node, integer_type_node, NULL_TREE); | |
229a1c59 | 19438 | tree v8qi_ftype_v8qi_int_int |
4fe058e2 NF |
19439 | = build_function_type_list (V8QI_type_node, |
19440 | V8QI_type_node, integer_type_node, | |
19441 | integer_type_node, NULL_TREE); | |
229a1c59 | 19442 | tree v4hi_ftype_v4hi_int_int |
4fe058e2 NF |
19443 | = build_function_type_list (V4HI_type_node, |
19444 | V4HI_type_node, integer_type_node, | |
19445 | integer_type_node, NULL_TREE); | |
229a1c59 | 19446 | tree v2si_ftype_v2si_int_int |
4fe058e2 NF |
19447 | = build_function_type_list (V2SI_type_node, |
19448 | V2SI_type_node, integer_type_node, | |
19449 | integer_type_node, NULL_TREE); | |
229a1c59 JZ |
19450 | /* Miscellaneous. */ |
19451 | tree v8qi_ftype_v4hi_v4hi | |
4fe058e2 NF |
19452 | = build_function_type_list (V8QI_type_node, |
19453 | V4HI_type_node, V4HI_type_node, NULL_TREE); | |
229a1c59 | 19454 | tree v4hi_ftype_v2si_v2si |
4fe058e2 NF |
19455 | = build_function_type_list (V4HI_type_node, |
19456 | V2SI_type_node, V2SI_type_node, NULL_TREE); | |
229a1c59 | 19457 | tree v2si_ftype_v4hi_v4hi |
4fe058e2 NF |
19458 | = build_function_type_list (V2SI_type_node, |
19459 | V4HI_type_node, V4HI_type_node, NULL_TREE); | |
229a1c59 | 19460 | tree v2si_ftype_v8qi_v8qi |
4fe058e2 NF |
19461 | = build_function_type_list (V2SI_type_node, |
19462 | V8QI_type_node, V8QI_type_node, NULL_TREE); | |
229a1c59 | 19463 | tree v4hi_ftype_v4hi_di |
4fe058e2 NF |
19464 | = build_function_type_list (V4HI_type_node, |
19465 | V4HI_type_node, long_long_integer_type_node, | |
19466 | NULL_TREE); | |
229a1c59 | 19467 | tree v2si_ftype_v2si_di |
4fe058e2 NF |
19468 | = build_function_type_list (V2SI_type_node, |
19469 | V2SI_type_node, long_long_integer_type_node, | |
19470 | NULL_TREE); | |
229a1c59 | 19471 | tree void_ftype_int_int |
4fe058e2 NF |
19472 | = build_function_type_list (void_type_node, |
19473 | integer_type_node, integer_type_node, | |
19474 | NULL_TREE); | |
229a1c59 | 19475 | tree di_ftype_void |
4fe058e2 | 19476 | = build_function_type_list (long_long_unsigned_type_node, NULL_TREE); |
229a1c59 | 19477 | tree di_ftype_v8qi |
4fe058e2 NF |
19478 | = build_function_type_list (long_long_integer_type_node, |
19479 | V8QI_type_node, NULL_TREE); | |
229a1c59 | 19480 | tree di_ftype_v4hi |
4fe058e2 NF |
19481 | = build_function_type_list (long_long_integer_type_node, |
19482 | V4HI_type_node, NULL_TREE); | |
229a1c59 | 19483 | tree di_ftype_v2si |
4fe058e2 NF |
19484 | = build_function_type_list (long_long_integer_type_node, |
19485 | V2SI_type_node, NULL_TREE); | |
229a1c59 | 19486 | tree v2si_ftype_v4hi |
4fe058e2 NF |
19487 | = build_function_type_list (V2SI_type_node, |
19488 | V4HI_type_node, NULL_TREE); | |
229a1c59 | 19489 | tree v4hi_ftype_v8qi |
4fe058e2 NF |
19490 | = build_function_type_list (V4HI_type_node, |
19491 | V8QI_type_node, NULL_TREE); | |
229a1c59 JZ |
19492 | |
19493 | tree di_ftype_di_v4hi_v4hi | |
4fe058e2 NF |
19494 | = build_function_type_list (long_long_unsigned_type_node, |
19495 | long_long_unsigned_type_node, | |
19496 | V4HI_type_node, V4HI_type_node, | |
19497 | NULL_TREE); | |
88f77cba | 19498 | |
229a1c59 | 19499 | tree di_ftype_v4hi_v4hi |
4fe058e2 NF |
19500 | = build_function_type_list (long_long_unsigned_type_node, |
19501 | V4HI_type_node,V4HI_type_node, | |
19502 | NULL_TREE); | |
229a1c59 JZ |
19503 | |
19504 | /* Normal vector binops. */ | |
19505 | tree v8qi_ftype_v8qi_v8qi | |
4fe058e2 NF |
19506 | = build_function_type_list (V8QI_type_node, |
19507 | V8QI_type_node, V8QI_type_node, NULL_TREE); | |
229a1c59 | 19508 | tree v4hi_ftype_v4hi_v4hi |
4fe058e2 NF |
19509 | = build_function_type_list (V4HI_type_node, |
19510 | V4HI_type_node,V4HI_type_node, NULL_TREE); | |
229a1c59 | 19511 | tree v2si_ftype_v2si_v2si |
4fe058e2 NF |
19512 | = build_function_type_list (V2SI_type_node, |
19513 | V2SI_type_node, V2SI_type_node, NULL_TREE); | |
229a1c59 | 19514 | tree di_ftype_di_di |
4fe058e2 NF |
19515 | = build_function_type_list (long_long_unsigned_type_node, |
19516 | long_long_unsigned_type_node, | |
19517 | long_long_unsigned_type_node, | |
19518 | NULL_TREE); | |
229a1c59 JZ |
19519 | |
19520 | /* Add all builtins that are more or less simple operations on two | |
19521 | operands. */ | |
19522 | for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++) | |
88f77cba | 19523 | { |
229a1c59 JZ |
19524 | /* Use one of the operands; the target can have a different mode for |
19525 | mask-generating compares. */ | |
19526 | enum machine_mode mode; | |
19527 | tree type; | |
88f77cba | 19528 | |
229a1c59 JZ |
19529 | if (d->name == 0) |
19530 | continue; | |
88f77cba | 19531 | |
229a1c59 | 19532 | mode = insn_data[d->icode].operand[1].mode; |
88f77cba | 19533 | |
229a1c59 | 19534 | switch (mode) |
88f77cba | 19535 | { |
229a1c59 JZ |
19536 | case V8QImode: |
19537 | type = v8qi_ftype_v8qi_v8qi; | |
19538 | break; | |
19539 | case V4HImode: | |
19540 | type = v4hi_ftype_v4hi_v4hi; | |
19541 | break; | |
19542 | case V2SImode: | |
19543 | type = v2si_ftype_v2si_v2si; | |
19544 | break; | |
19545 | case DImode: | |
19546 | type = di_ftype_di_di; | |
19547 | break; | |
88f77cba | 19548 | |
229a1c59 JZ |
19549 | default: |
19550 | gcc_unreachable (); | |
19551 | } | |
88f77cba | 19552 | |
229a1c59 JZ |
19553 | def_mbuiltin (d->mask, d->name, type, d->code); |
19554 | } | |
88f77cba | 19555 | |
229a1c59 JZ |
19556 | /* Add the remaining MMX insns with somewhat more complicated types. */ |
19557 | #define iwmmx_mbuiltin(NAME, TYPE, CODE) \ | |
19558 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_" NAME, (TYPE), \ | |
19559 | ARM_BUILTIN_ ## CODE) | |
19560 | ||
19561 | iwmmx_mbuiltin ("wzero", di_ftype_void, WZERO); | |
19562 | iwmmx_mbuiltin ("setwcx", void_ftype_int_int, SETWCX); | |
19563 | iwmmx_mbuiltin ("getwcx", int_ftype_int, GETWCX); | |
19564 | ||
19565 | iwmmx_mbuiltin ("wsllh", v4hi_ftype_v4hi_di, WSLLH); | |
19566 | iwmmx_mbuiltin ("wsllw", v2si_ftype_v2si_di, WSLLW); | |
19567 | iwmmx_mbuiltin ("wslld", di_ftype_di_di, WSLLD); | |
19568 | iwmmx_mbuiltin ("wsllhi", v4hi_ftype_v4hi_int, WSLLHI); | |
19569 | iwmmx_mbuiltin ("wsllwi", v2si_ftype_v2si_int, WSLLWI); | |
19570 | iwmmx_mbuiltin ("wslldi", di_ftype_di_int, WSLLDI); | |
19571 | ||
19572 | iwmmx_mbuiltin ("wsrlh", v4hi_ftype_v4hi_di, WSRLH); | |
19573 | iwmmx_mbuiltin ("wsrlw", v2si_ftype_v2si_di, WSRLW); | |
19574 | iwmmx_mbuiltin ("wsrld", di_ftype_di_di, WSRLD); | |
19575 | iwmmx_mbuiltin ("wsrlhi", v4hi_ftype_v4hi_int, WSRLHI); | |
19576 | iwmmx_mbuiltin ("wsrlwi", v2si_ftype_v2si_int, WSRLWI); | |
19577 | iwmmx_mbuiltin ("wsrldi", di_ftype_di_int, WSRLDI); | |
19578 | ||
19579 | iwmmx_mbuiltin ("wsrah", v4hi_ftype_v4hi_di, WSRAH); | |
19580 | iwmmx_mbuiltin ("wsraw", v2si_ftype_v2si_di, WSRAW); | |
19581 | iwmmx_mbuiltin ("wsrad", di_ftype_di_di, WSRAD); | |
19582 | iwmmx_mbuiltin ("wsrahi", v4hi_ftype_v4hi_int, WSRAHI); | |
19583 | iwmmx_mbuiltin ("wsrawi", v2si_ftype_v2si_int, WSRAWI); | |
19584 | iwmmx_mbuiltin ("wsradi", di_ftype_di_int, WSRADI); | |
19585 | ||
19586 | iwmmx_mbuiltin ("wrorh", v4hi_ftype_v4hi_di, WRORH); | |
19587 | iwmmx_mbuiltin ("wrorw", v2si_ftype_v2si_di, WRORW); | |
19588 | iwmmx_mbuiltin ("wrord", di_ftype_di_di, WRORD); | |
19589 | iwmmx_mbuiltin ("wrorhi", v4hi_ftype_v4hi_int, WRORHI); | |
19590 | iwmmx_mbuiltin ("wrorwi", v2si_ftype_v2si_int, WRORWI); | |
19591 | iwmmx_mbuiltin ("wrordi", di_ftype_di_int, WRORDI); | |
19592 | ||
19593 | iwmmx_mbuiltin ("wshufh", v4hi_ftype_v4hi_int, WSHUFH); | |
19594 | ||
19595 | iwmmx_mbuiltin ("wsadb", v2si_ftype_v8qi_v8qi, WSADB); | |
19596 | iwmmx_mbuiltin ("wsadh", v2si_ftype_v4hi_v4hi, WSADH); | |
19597 | iwmmx_mbuiltin ("wsadbz", v2si_ftype_v8qi_v8qi, WSADBZ); | |
19598 | iwmmx_mbuiltin ("wsadhz", v2si_ftype_v4hi_v4hi, WSADHZ); | |
19599 | ||
19600 | iwmmx_mbuiltin ("textrmsb", int_ftype_v8qi_int, TEXTRMSB); | |
19601 | iwmmx_mbuiltin ("textrmsh", int_ftype_v4hi_int, TEXTRMSH); | |
19602 | iwmmx_mbuiltin ("textrmsw", int_ftype_v2si_int, TEXTRMSW); | |
19603 | iwmmx_mbuiltin ("textrmub", int_ftype_v8qi_int, TEXTRMUB); | |
19604 | iwmmx_mbuiltin ("textrmuh", int_ftype_v4hi_int, TEXTRMUH); | |
19605 | iwmmx_mbuiltin ("textrmuw", int_ftype_v2si_int, TEXTRMUW); | |
19606 | iwmmx_mbuiltin ("tinsrb", v8qi_ftype_v8qi_int_int, TINSRB); | |
19607 | iwmmx_mbuiltin ("tinsrh", v4hi_ftype_v4hi_int_int, TINSRH); | |
19608 | iwmmx_mbuiltin ("tinsrw", v2si_ftype_v2si_int_int, TINSRW); | |
19609 | ||
19610 | iwmmx_mbuiltin ("waccb", di_ftype_v8qi, WACCB); | |
19611 | iwmmx_mbuiltin ("wacch", di_ftype_v4hi, WACCH); | |
19612 | iwmmx_mbuiltin ("waccw", di_ftype_v2si, WACCW); | |
19613 | ||
19614 | iwmmx_mbuiltin ("tmovmskb", int_ftype_v8qi, TMOVMSKB); | |
19615 | iwmmx_mbuiltin ("tmovmskh", int_ftype_v4hi, TMOVMSKH); | |
19616 | iwmmx_mbuiltin ("tmovmskw", int_ftype_v2si, TMOVMSKW); | |
19617 | ||
19618 | iwmmx_mbuiltin ("wpackhss", v8qi_ftype_v4hi_v4hi, WPACKHSS); | |
19619 | iwmmx_mbuiltin ("wpackhus", v8qi_ftype_v4hi_v4hi, WPACKHUS); | |
19620 | iwmmx_mbuiltin ("wpackwus", v4hi_ftype_v2si_v2si, WPACKWUS); | |
19621 | iwmmx_mbuiltin ("wpackwss", v4hi_ftype_v2si_v2si, WPACKWSS); | |
19622 | iwmmx_mbuiltin ("wpackdus", v2si_ftype_di_di, WPACKDUS); | |
19623 | iwmmx_mbuiltin ("wpackdss", v2si_ftype_di_di, WPACKDSS); | |
19624 | ||
19625 | iwmmx_mbuiltin ("wunpckehub", v4hi_ftype_v8qi, WUNPCKEHUB); | |
19626 | iwmmx_mbuiltin ("wunpckehuh", v2si_ftype_v4hi, WUNPCKEHUH); | |
19627 | iwmmx_mbuiltin ("wunpckehuw", di_ftype_v2si, WUNPCKEHUW); | |
19628 | iwmmx_mbuiltin ("wunpckehsb", v4hi_ftype_v8qi, WUNPCKEHSB); | |
19629 | iwmmx_mbuiltin ("wunpckehsh", v2si_ftype_v4hi, WUNPCKEHSH); | |
19630 | iwmmx_mbuiltin ("wunpckehsw", di_ftype_v2si, WUNPCKEHSW); | |
19631 | iwmmx_mbuiltin ("wunpckelub", v4hi_ftype_v8qi, WUNPCKELUB); | |
19632 | iwmmx_mbuiltin ("wunpckeluh", v2si_ftype_v4hi, WUNPCKELUH); | |
19633 | iwmmx_mbuiltin ("wunpckeluw", di_ftype_v2si, WUNPCKELUW); | |
19634 | iwmmx_mbuiltin ("wunpckelsb", v4hi_ftype_v8qi, WUNPCKELSB); | |
19635 | iwmmx_mbuiltin ("wunpckelsh", v2si_ftype_v4hi, WUNPCKELSH); | |
19636 | iwmmx_mbuiltin ("wunpckelsw", di_ftype_v2si, WUNPCKELSW); | |
19637 | ||
19638 | iwmmx_mbuiltin ("wmacs", di_ftype_di_v4hi_v4hi, WMACS); | |
19639 | iwmmx_mbuiltin ("wmacsz", di_ftype_v4hi_v4hi, WMACSZ); | |
19640 | iwmmx_mbuiltin ("wmacu", di_ftype_di_v4hi_v4hi, WMACU); | |
19641 | iwmmx_mbuiltin ("wmacuz", di_ftype_v4hi_v4hi, WMACUZ); | |
19642 | ||
19643 | iwmmx_mbuiltin ("walign", v8qi_ftype_v8qi_v8qi_int, WALIGN); | |
19644 | iwmmx_mbuiltin ("tmia", di_ftype_di_int_int, TMIA); | |
19645 | iwmmx_mbuiltin ("tmiaph", di_ftype_di_int_int, TMIAPH); | |
19646 | iwmmx_mbuiltin ("tmiabb", di_ftype_di_int_int, TMIABB); | |
19647 | iwmmx_mbuiltin ("tmiabt", di_ftype_di_int_int, TMIABT); | |
19648 | iwmmx_mbuiltin ("tmiatb", di_ftype_di_int_int, TMIATB); | |
19649 | iwmmx_mbuiltin ("tmiatt", di_ftype_di_int_int, TMIATT); | |
19650 | ||
19651 | #undef iwmmx_mbuiltin | |
19652 | } | |
88f77cba | 19653 | |
229a1c59 JZ |
19654 | static void |
19655 | arm_init_tls_builtins (void) | |
19656 | { | |
19657 | tree ftype, decl; | |
88f77cba | 19658 | |
229a1c59 JZ |
19659 | ftype = build_function_type (ptr_type_node, void_list_node); |
19660 | decl = add_builtin_function ("__builtin_thread_pointer", ftype, | |
19661 | ARM_BUILTIN_THREAD_POINTER, BUILT_IN_MD, | |
19662 | NULL, NULL_TREE); | |
19663 | TREE_NOTHROW (decl) = 1; | |
19664 | TREE_READONLY (decl) = 1; | |
19665 | arm_builtin_decls[ARM_BUILTIN_THREAD_POINTER] = decl; | |
88f77cba JB |
19666 | } |
19667 | ||
0fd8c3ad SL |
19668 | static void |
19669 | arm_init_fp16_builtins (void) | |
19670 | { | |
19671 | tree fp16_type = make_node (REAL_TYPE); | |
19672 | TYPE_PRECISION (fp16_type) = 16; | |
19673 | layout_type (fp16_type); | |
19674 | (*lang_hooks.types.register_builtin_type) (fp16_type, "__fp16"); | |
19675 | } | |
19676 | ||
5a9335ef NC |
19677 | static void |
19678 | arm_init_builtins (void) | |
19679 | { | |
d3585b76 DJ |
19680 | arm_init_tls_builtins (); |
19681 | ||
5a9335ef NC |
19682 | if (TARGET_REALLY_IWMMXT) |
19683 | arm_init_iwmmxt_builtins (); | |
88f77cba JB |
19684 | |
19685 | if (TARGET_NEON) | |
19686 | arm_init_neon_builtins (); | |
0fd8c3ad SL |
19687 | |
19688 | if (arm_fp16_format) | |
19689 | arm_init_fp16_builtins (); | |
19690 | } | |
19691 | ||
229a1c59 JZ |
19692 | /* Return the ARM builtin for CODE. */ |
19693 | ||
19694 | static tree | |
19695 | arm_builtin_decl (unsigned code, bool initialize_p ATTRIBUTE_UNUSED) | |
19696 | { | |
19697 | if (code >= ARM_BUILTIN_MAX) | |
19698 | return error_mark_node; | |
19699 | ||
19700 | return arm_builtin_decls[code]; | |
19701 | } | |
19702 | ||
0fd8c3ad SL |
19703 | /* Implement TARGET_INVALID_PARAMETER_TYPE. */ |
19704 | ||
19705 | static const char * | |
19706 | arm_invalid_parameter_type (const_tree t) | |
19707 | { | |
19708 | if (SCALAR_FLOAT_TYPE_P (t) && TYPE_PRECISION (t) == 16) | |
19709 | return N_("function parameters cannot have __fp16 type"); | |
19710 | return NULL; | |
19711 | } | |
19712 | ||
19713 | /* Implement TARGET_INVALID_PARAMETER_TYPE. */ | |
19714 | ||
19715 | static const char * | |
19716 | arm_invalid_return_type (const_tree t) | |
19717 | { | |
19718 | if (SCALAR_FLOAT_TYPE_P (t) && TYPE_PRECISION (t) == 16) | |
19719 | return N_("functions cannot return __fp16 type"); | |
19720 | return NULL; | |
19721 | } | |
19722 | ||
19723 | /* Implement TARGET_PROMOTED_TYPE. */ | |
19724 | ||
19725 | static tree | |
19726 | arm_promoted_type (const_tree t) | |
19727 | { | |
19728 | if (SCALAR_FLOAT_TYPE_P (t) && TYPE_PRECISION (t) == 16) | |
19729 | return float_type_node; | |
19730 | return NULL_TREE; | |
19731 | } | |
19732 | ||
19733 | /* Implement TARGET_CONVERT_TO_TYPE. | |
19734 | Specifically, this hook implements the peculiarity of the ARM | |
19735 | half-precision floating-point C semantics that requires conversions between | |
19736 | __fp16 to or from double to do an intermediate conversion to float. */ | |
19737 | ||
19738 | static tree | |
19739 | arm_convert_to_type (tree type, tree expr) | |
19740 | { | |
19741 | tree fromtype = TREE_TYPE (expr); | |
19742 | if (!SCALAR_FLOAT_TYPE_P (fromtype) || !SCALAR_FLOAT_TYPE_P (type)) | |
19743 | return NULL_TREE; | |
19744 | if ((TYPE_PRECISION (fromtype) == 16 && TYPE_PRECISION (type) > 32) | |
19745 | || (TYPE_PRECISION (type) == 16 && TYPE_PRECISION (fromtype) > 32)) | |
19746 | return convert (type, convert (float_type_node, expr)); | |
19747 | return NULL_TREE; | |
5a9335ef NC |
19748 | } |
19749 | ||
bdc4827b SL |
19750 | /* Implement TARGET_SCALAR_MODE_SUPPORTED_P. |
19751 | This simply adds HFmode as a supported mode; even though we don't | |
19752 | implement arithmetic on this type directly, it's supported by | |
19753 | optabs conversions, much the way the double-word arithmetic is | |
19754 | special-cased in the default hook. */ | |
19755 | ||
19756 | static bool | |
19757 | arm_scalar_mode_supported_p (enum machine_mode mode) | |
19758 | { | |
19759 | if (mode == HFmode) | |
19760 | return (arm_fp16_format != ARM_FP16_FORMAT_NONE); | |
655b30bf JB |
19761 | else if (ALL_FIXED_POINT_MODE_P (mode)) |
19762 | return true; | |
bdc4827b SL |
19763 | else |
19764 | return default_scalar_mode_supported_p (mode); | |
19765 | } | |
19766 | ||
5a9335ef NC |
19767 | /* Errors in the source file can cause expand_expr to return const0_rtx |
19768 | where we expect a vector. To avoid crashing, use one of the vector | |
19769 | clear instructions. */ | |
19770 | ||
19771 | static rtx | |
19772 | safe_vector_operand (rtx x, enum machine_mode mode) | |
19773 | { | |
19774 | if (x != const0_rtx) | |
19775 | return x; | |
19776 | x = gen_reg_rtx (mode); | |
19777 | ||
19778 | emit_insn (gen_iwmmxt_clrdi (mode == DImode ? x | |
19779 | : gen_rtx_SUBREG (DImode, x, 0))); | |
19780 | return x; | |
19781 | } | |
19782 | ||
19783 | /* Subroutine of arm_expand_builtin to take care of binop insns. */ | |
19784 | ||
19785 | static rtx | |
19786 | arm_expand_binop_builtin (enum insn_code icode, | |
5039610b | 19787 | tree exp, rtx target) |
5a9335ef NC |
19788 | { |
19789 | rtx pat; | |
5039610b SL |
19790 | tree arg0 = CALL_EXPR_ARG (exp, 0); |
19791 | tree arg1 = CALL_EXPR_ARG (exp, 1); | |
84217346 MD |
19792 | rtx op0 = expand_normal (arg0); |
19793 | rtx op1 = expand_normal (arg1); | |
5a9335ef NC |
19794 | enum machine_mode tmode = insn_data[icode].operand[0].mode; |
19795 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
19796 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
19797 | ||
19798 | if (VECTOR_MODE_P (mode0)) | |
19799 | op0 = safe_vector_operand (op0, mode0); | |
19800 | if (VECTOR_MODE_P (mode1)) | |
19801 | op1 = safe_vector_operand (op1, mode1); | |
19802 | ||
19803 | if (! target | |
19804 | || GET_MODE (target) != tmode | |
19805 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
19806 | target = gen_reg_rtx (tmode); | |
19807 | ||
e6d29d15 | 19808 | gcc_assert (GET_MODE (op0) == mode0 && GET_MODE (op1) == mode1); |
5a9335ef NC |
19809 | |
19810 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
19811 | op0 = copy_to_mode_reg (mode0, op0); | |
19812 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
19813 | op1 = copy_to_mode_reg (mode1, op1); | |
19814 | ||
19815 | pat = GEN_FCN (icode) (target, op0, op1); | |
19816 | if (! pat) | |
19817 | return 0; | |
19818 | emit_insn (pat); | |
19819 | return target; | |
19820 | } | |
19821 | ||
19822 | /* Subroutine of arm_expand_builtin to take care of unop insns. */ | |
19823 | ||
19824 | static rtx | |
19825 | arm_expand_unop_builtin (enum insn_code icode, | |
5039610b | 19826 | tree exp, rtx target, int do_load) |
5a9335ef NC |
19827 | { |
19828 | rtx pat; | |
5039610b | 19829 | tree arg0 = CALL_EXPR_ARG (exp, 0); |
84217346 | 19830 | rtx op0 = expand_normal (arg0); |
5a9335ef NC |
19831 | enum machine_mode tmode = insn_data[icode].operand[0].mode; |
19832 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
19833 | ||
19834 | if (! target | |
19835 | || GET_MODE (target) != tmode | |
19836 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
19837 | target = gen_reg_rtx (tmode); | |
19838 | if (do_load) | |
19839 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
19840 | else | |
19841 | { | |
19842 | if (VECTOR_MODE_P (mode0)) | |
19843 | op0 = safe_vector_operand (op0, mode0); | |
19844 | ||
19845 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
19846 | op0 = copy_to_mode_reg (mode0, op0); | |
19847 | } | |
19848 | ||
19849 | pat = GEN_FCN (icode) (target, op0); | |
19850 | if (! pat) | |
19851 | return 0; | |
19852 | emit_insn (pat); | |
19853 | return target; | |
19854 | } | |
19855 | ||
88f77cba JB |
19856 | typedef enum { |
19857 | NEON_ARG_COPY_TO_REG, | |
19858 | NEON_ARG_CONSTANT, | |
6308e208 | 19859 | NEON_ARG_MEMORY, |
88f77cba JB |
19860 | NEON_ARG_STOP |
19861 | } builtin_arg; | |
19862 | ||
19863 | #define NEON_MAX_BUILTIN_ARGS 5 | |
19864 | ||
6308e208 RS |
19865 | /* EXP is a pointer argument to a Neon load or store intrinsic. Derive |
19866 | and return an expression for the accessed memory. | |
19867 | ||
19868 | The intrinsic function operates on a block of registers that has | |
229a1c59 | 19869 | mode REG_MODE. This block contains vectors of type TYPE_MODE. |
6308e208 RS |
19870 | The function references the memory at EXP in mode MEM_MODE; |
19871 | this mode may be BLKmode if no more suitable mode is available. */ | |
19872 | ||
19873 | static tree | |
19874 | neon_dereference_pointer (tree exp, enum machine_mode mem_mode, | |
19875 | enum machine_mode reg_mode, | |
229a1c59 | 19876 | neon_builtin_type_mode type_mode) |
6308e208 RS |
19877 | { |
19878 | HOST_WIDE_INT reg_size, vector_size, nvectors, nelems; | |
19879 | tree elem_type, upper_bound, array_type; | |
19880 | ||
19881 | /* Work out the size of the register block in bytes. */ | |
19882 | reg_size = GET_MODE_SIZE (reg_mode); | |
19883 | ||
19884 | /* Work out the size of each vector in bytes. */ | |
229a1c59 JZ |
19885 | gcc_assert (TYPE_MODE_BIT (type_mode) & (TB_DREG | TB_QREG)); |
19886 | vector_size = (TYPE_MODE_BIT (type_mode) & TB_QREG ? 16 : 8); | |
6308e208 RS |
19887 | |
19888 | /* Work out how many vectors there are. */ | |
19889 | gcc_assert (reg_size % vector_size == 0); | |
19890 | nvectors = reg_size / vector_size; | |
19891 | ||
19892 | /* Work out how many elements are being loaded or stored. | |
19893 | MEM_MODE == REG_MODE implies a one-to-one mapping between register | |
19894 | and memory elements; anything else implies a lane load or store. */ | |
19895 | if (mem_mode == reg_mode) | |
19896 | nelems = vector_size * nvectors; | |
19897 | else | |
19898 | nelems = nvectors; | |
19899 | ||
19900 | /* Work out the type of each element. */ | |
19901 | gcc_assert (POINTER_TYPE_P (TREE_TYPE (exp))); | |
19902 | elem_type = TREE_TYPE (TREE_TYPE (exp)); | |
19903 | ||
19904 | /* Create a type that describes the full access. */ | |
19905 | upper_bound = build_int_cst (size_type_node, nelems - 1); | |
19906 | array_type = build_array_type (elem_type, build_index_type (upper_bound)); | |
19907 | ||
19908 | /* Dereference EXP using that type. */ | |
19909 | exp = convert (build_pointer_type (array_type), exp); | |
19910 | return fold_build2 (MEM_REF, array_type, exp, | |
19911 | build_int_cst (TREE_TYPE (exp), 0)); | |
19912 | } | |
19913 | ||
88f77cba JB |
19914 | /* Expand a Neon builtin. */ |
19915 | static rtx | |
19916 | arm_expand_neon_args (rtx target, int icode, int have_retval, | |
229a1c59 | 19917 | neon_builtin_type_mode type_mode, |
88f77cba JB |
19918 | tree exp, ...) |
19919 | { | |
19920 | va_list ap; | |
19921 | rtx pat; | |
19922 | tree arg[NEON_MAX_BUILTIN_ARGS]; | |
19923 | rtx op[NEON_MAX_BUILTIN_ARGS]; | |
19924 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
19925 | enum machine_mode mode[NEON_MAX_BUILTIN_ARGS]; | |
6308e208 | 19926 | enum machine_mode other_mode; |
88f77cba | 19927 | int argc = 0; |
6308e208 | 19928 | int opno; |
88f77cba JB |
19929 | |
19930 | if (have_retval | |
19931 | && (!target | |
19932 | || GET_MODE (target) != tmode | |
19933 | || !(*insn_data[icode].operand[0].predicate) (target, tmode))) | |
19934 | target = gen_reg_rtx (tmode); | |
19935 | ||
19936 | va_start (ap, exp); | |
19937 | ||
19938 | for (;;) | |
19939 | { | |
81f40b79 | 19940 | builtin_arg thisarg = (builtin_arg) va_arg (ap, int); |
88f77cba JB |
19941 | |
19942 | if (thisarg == NEON_ARG_STOP) | |
19943 | break; | |
19944 | else | |
19945 | { | |
6308e208 RS |
19946 | opno = argc + have_retval; |
19947 | mode[argc] = insn_data[icode].operand[opno].mode; | |
88f77cba | 19948 | arg[argc] = CALL_EXPR_ARG (exp, argc); |
6308e208 RS |
19949 | if (thisarg == NEON_ARG_MEMORY) |
19950 | { | |
19951 | other_mode = insn_data[icode].operand[1 - opno].mode; | |
19952 | arg[argc] = neon_dereference_pointer (arg[argc], mode[argc], | |
229a1c59 | 19953 | other_mode, type_mode); |
6308e208 | 19954 | } |
88f77cba | 19955 | op[argc] = expand_normal (arg[argc]); |
88f77cba JB |
19956 | |
19957 | switch (thisarg) | |
19958 | { | |
19959 | case NEON_ARG_COPY_TO_REG: | |
19960 | /*gcc_assert (GET_MODE (op[argc]) == mode[argc]);*/ | |
6308e208 | 19961 | if (!(*insn_data[icode].operand[opno].predicate) |
88f77cba JB |
19962 | (op[argc], mode[argc])) |
19963 | op[argc] = copy_to_mode_reg (mode[argc], op[argc]); | |
19964 | break; | |
19965 | ||
19966 | case NEON_ARG_CONSTANT: | |
19967 | /* FIXME: This error message is somewhat unhelpful. */ | |
6308e208 | 19968 | if (!(*insn_data[icode].operand[opno].predicate) |
88f77cba JB |
19969 | (op[argc], mode[argc])) |
19970 | error ("argument must be a constant"); | |
19971 | break; | |
19972 | ||
6308e208 RS |
19973 | case NEON_ARG_MEMORY: |
19974 | gcc_assert (MEM_P (op[argc])); | |
19975 | PUT_MODE (op[argc], mode[argc]); | |
19976 | /* ??? arm_neon.h uses the same built-in functions for signed | |
19977 | and unsigned accesses, casting where necessary. This isn't | |
19978 | alias safe. */ | |
19979 | set_mem_alias_set (op[argc], 0); | |
19980 | if (!(*insn_data[icode].operand[opno].predicate) | |
19981 | (op[argc], mode[argc])) | |
19982 | op[argc] = (replace_equiv_address | |
19983 | (op[argc], force_reg (Pmode, XEXP (op[argc], 0)))); | |
19984 | break; | |
19985 | ||
88f77cba JB |
19986 | case NEON_ARG_STOP: |
19987 | gcc_unreachable (); | |
19988 | } | |
19989 | ||
19990 | argc++; | |
19991 | } | |
19992 | } | |
19993 | ||
19994 | va_end (ap); | |
19995 | ||
19996 | if (have_retval) | |
19997 | switch (argc) | |
19998 | { | |
19999 | case 1: | |
20000 | pat = GEN_FCN (icode) (target, op[0]); | |
20001 | break; | |
20002 | ||
20003 | case 2: | |
20004 | pat = GEN_FCN (icode) (target, op[0], op[1]); | |
20005 | break; | |
20006 | ||
20007 | case 3: | |
20008 | pat = GEN_FCN (icode) (target, op[0], op[1], op[2]); | |
20009 | break; | |
20010 | ||
20011 | case 4: | |
20012 | pat = GEN_FCN (icode) (target, op[0], op[1], op[2], op[3]); | |
20013 | break; | |
20014 | ||
20015 | case 5: | |
20016 | pat = GEN_FCN (icode) (target, op[0], op[1], op[2], op[3], op[4]); | |
20017 | break; | |
20018 | ||
20019 | default: | |
20020 | gcc_unreachable (); | |
20021 | } | |
20022 | else | |
20023 | switch (argc) | |
20024 | { | |
20025 | case 1: | |
20026 | pat = GEN_FCN (icode) (op[0]); | |
20027 | break; | |
20028 | ||
20029 | case 2: | |
20030 | pat = GEN_FCN (icode) (op[0], op[1]); | |
20031 | break; | |
20032 | ||
20033 | case 3: | |
20034 | pat = GEN_FCN (icode) (op[0], op[1], op[2]); | |
20035 | break; | |
20036 | ||
20037 | case 4: | |
20038 | pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3]); | |
20039 | break; | |
20040 | ||
20041 | case 5: | |
20042 | pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3], op[4]); | |
20043 | break; | |
20044 | ||
20045 | default: | |
20046 | gcc_unreachable (); | |
20047 | } | |
20048 | ||
20049 | if (!pat) | |
20050 | return 0; | |
20051 | ||
20052 | emit_insn (pat); | |
20053 | ||
20054 | return target; | |
20055 | } | |
20056 | ||
20057 | /* Expand a Neon builtin. These are "special" because they don't have symbolic | |
20058 | constants defined per-instruction or per instruction-variant. Instead, the | |
20059 | required info is looked up in the table neon_builtin_data. */ | |
20060 | static rtx | |
20061 | arm_expand_neon_builtin (int fcode, tree exp, rtx target) | |
20062 | { | |
229a1c59 JZ |
20063 | neon_builtin_datum *d = &neon_builtin_data[fcode - ARM_BUILTIN_NEON_BASE]; |
20064 | neon_itype itype = d->itype; | |
20065 | enum insn_code icode = d->code; | |
20066 | neon_builtin_type_mode type_mode = d->mode; | |
88f77cba JB |
20067 | |
20068 | switch (itype) | |
20069 | { | |
20070 | case NEON_UNOP: | |
20071 | case NEON_CONVERT: | |
20072 | case NEON_DUPLANE: | |
229a1c59 | 20073 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20074 | NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, NEON_ARG_STOP); |
20075 | ||
20076 | case NEON_BINOP: | |
20077 | case NEON_SETLANE: | |
20078 | case NEON_SCALARMUL: | |
20079 | case NEON_SCALARMULL: | |
20080 | case NEON_SCALARMULH: | |
20081 | case NEON_SHIFTINSERT: | |
20082 | case NEON_LOGICBINOP: | |
229a1c59 | 20083 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20084 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, |
20085 | NEON_ARG_STOP); | |
20086 | ||
20087 | case NEON_TERNOP: | |
229a1c59 | 20088 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20089 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, |
20090 | NEON_ARG_CONSTANT, NEON_ARG_STOP); | |
20091 | ||
20092 | case NEON_GETLANE: | |
20093 | case NEON_FIXCONV: | |
20094 | case NEON_SHIFTIMM: | |
229a1c59 | 20095 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20096 | NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, NEON_ARG_CONSTANT, |
20097 | NEON_ARG_STOP); | |
20098 | ||
20099 | case NEON_CREATE: | |
229a1c59 | 20100 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20101 | NEON_ARG_COPY_TO_REG, NEON_ARG_STOP); |
20102 | ||
20103 | case NEON_DUP: | |
20104 | case NEON_SPLIT: | |
20105 | case NEON_REINTERP: | |
229a1c59 | 20106 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20107 | NEON_ARG_COPY_TO_REG, NEON_ARG_STOP); |
20108 | ||
20109 | case NEON_COMBINE: | |
20110 | case NEON_VTBL: | |
229a1c59 | 20111 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20112 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_STOP); |
20113 | ||
20114 | case NEON_RESULTPAIR: | |
229a1c59 | 20115 | return arm_expand_neon_args (target, icode, 0, type_mode, exp, |
88f77cba JB |
20116 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, |
20117 | NEON_ARG_STOP); | |
20118 | ||
20119 | case NEON_LANEMUL: | |
20120 | case NEON_LANEMULL: | |
20121 | case NEON_LANEMULH: | |
229a1c59 | 20122 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20123 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, |
20124 | NEON_ARG_CONSTANT, NEON_ARG_STOP); | |
20125 | ||
20126 | case NEON_LANEMAC: | |
229a1c59 | 20127 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20128 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, |
20129 | NEON_ARG_CONSTANT, NEON_ARG_CONSTANT, NEON_ARG_STOP); | |
20130 | ||
20131 | case NEON_SHIFTACC: | |
229a1c59 | 20132 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20133 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, |
20134 | NEON_ARG_CONSTANT, NEON_ARG_STOP); | |
20135 | ||
20136 | case NEON_SCALARMAC: | |
229a1c59 | 20137 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20138 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, |
20139 | NEON_ARG_CONSTANT, NEON_ARG_STOP); | |
20140 | ||
20141 | case NEON_SELECT: | |
20142 | case NEON_VTBX: | |
229a1c59 | 20143 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
88f77cba JB |
20144 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, |
20145 | NEON_ARG_STOP); | |
20146 | ||
20147 | case NEON_LOAD1: | |
20148 | case NEON_LOADSTRUCT: | |
229a1c59 | 20149 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
6308e208 | 20150 | NEON_ARG_MEMORY, NEON_ARG_STOP); |
88f77cba JB |
20151 | |
20152 | case NEON_LOAD1LANE: | |
20153 | case NEON_LOADSTRUCTLANE: | |
229a1c59 | 20154 | return arm_expand_neon_args (target, icode, 1, type_mode, exp, |
6308e208 | 20155 | NEON_ARG_MEMORY, NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, |
88f77cba JB |
20156 | NEON_ARG_STOP); |
20157 | ||
20158 | case NEON_STORE1: | |
20159 | case NEON_STORESTRUCT: | |
229a1c59 | 20160 | return arm_expand_neon_args (target, icode, 0, type_mode, exp, |
6308e208 | 20161 | NEON_ARG_MEMORY, NEON_ARG_COPY_TO_REG, NEON_ARG_STOP); |
88f77cba JB |
20162 | |
20163 | case NEON_STORE1LANE: | |
20164 | case NEON_STORESTRUCTLANE: | |
229a1c59 | 20165 | return arm_expand_neon_args (target, icode, 0, type_mode, exp, |
6308e208 | 20166 | NEON_ARG_MEMORY, NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, |
88f77cba JB |
20167 | NEON_ARG_STOP); |
20168 | } | |
20169 | ||
20170 | gcc_unreachable (); | |
20171 | } | |
20172 | ||
20173 | /* Emit code to reinterpret one Neon type as another, without altering bits. */ | |
20174 | void | |
20175 | neon_reinterpret (rtx dest, rtx src) | |
20176 | { | |
20177 | emit_move_insn (dest, gen_lowpart (GET_MODE (dest), src)); | |
20178 | } | |
20179 | ||
20180 | /* Emit code to place a Neon pair result in memory locations (with equal | |
20181 | registers). */ | |
20182 | void | |
20183 | neon_emit_pair_result_insn (enum machine_mode mode, | |
20184 | rtx (*intfn) (rtx, rtx, rtx, rtx), rtx destaddr, | |
20185 | rtx op1, rtx op2) | |
20186 | { | |
20187 | rtx mem = gen_rtx_MEM (mode, destaddr); | |
20188 | rtx tmp1 = gen_reg_rtx (mode); | |
20189 | rtx tmp2 = gen_reg_rtx (mode); | |
20190 | ||
7e7cfcf6 | 20191 | emit_insn (intfn (tmp1, op1, op2, tmp2)); |
88f77cba JB |
20192 | |
20193 | emit_move_insn (mem, tmp1); | |
20194 | mem = adjust_address (mem, mode, GET_MODE_SIZE (mode)); | |
20195 | emit_move_insn (mem, tmp2); | |
20196 | } | |
20197 | ||
20198 | /* Set up operands for a register copy from src to dest, taking care not to | |
20199 | clobber registers in the process. | |
20200 | FIXME: This has rather high polynomial complexity (O(n^3)?) but shouldn't | |
20201 | be called with a large N, so that should be OK. */ | |
20202 | ||
20203 | void | |
20204 | neon_disambiguate_copy (rtx *operands, rtx *dest, rtx *src, unsigned int count) | |
20205 | { | |
20206 | unsigned int copied = 0, opctr = 0; | |
20207 | unsigned int done = (1 << count) - 1; | |
20208 | unsigned int i, j; | |
20209 | ||
20210 | while (copied != done) | |
20211 | { | |
20212 | for (i = 0; i < count; i++) | |
20213 | { | |
20214 | int good = 1; | |
20215 | ||
20216 | for (j = 0; good && j < count; j++) | |
20217 | if (i != j && (copied & (1 << j)) == 0 | |
20218 | && reg_overlap_mentioned_p (src[j], dest[i])) | |
20219 | good = 0; | |
20220 | ||
20221 | if (good) | |
20222 | { | |
20223 | operands[opctr++] = dest[i]; | |
20224 | operands[opctr++] = src[i]; | |
20225 | copied |= 1 << i; | |
20226 | } | |
20227 | } | |
20228 | } | |
20229 | ||
20230 | gcc_assert (opctr == count * 2); | |
20231 | } | |
20232 | ||
5a9335ef NC |
20233 | /* Expand an expression EXP that calls a built-in function, |
20234 | with result going to TARGET if that's convenient | |
20235 | (and in mode MODE if that's convenient). | |
20236 | SUBTARGET may be used as the target for computing one of EXP's operands. | |
20237 | IGNORE is nonzero if the value is to be ignored. */ | |
20238 | ||
20239 | static rtx | |
20240 | arm_expand_builtin (tree exp, | |
20241 | rtx target, | |
20242 | rtx subtarget ATTRIBUTE_UNUSED, | |
20243 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
20244 | int ignore ATTRIBUTE_UNUSED) | |
20245 | { | |
20246 | const struct builtin_description * d; | |
20247 | enum insn_code icode; | |
5039610b | 20248 | tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0); |
5a9335ef NC |
20249 | tree arg0; |
20250 | tree arg1; | |
20251 | tree arg2; | |
20252 | rtx op0; | |
20253 | rtx op1; | |
20254 | rtx op2; | |
20255 | rtx pat; | |
20256 | int fcode = DECL_FUNCTION_CODE (fndecl); | |
20257 | size_t i; | |
20258 | enum machine_mode tmode; | |
20259 | enum machine_mode mode0; | |
20260 | enum machine_mode mode1; | |
20261 | enum machine_mode mode2; | |
20262 | ||
88f77cba JB |
20263 | if (fcode >= ARM_BUILTIN_NEON_BASE) |
20264 | return arm_expand_neon_builtin (fcode, exp, target); | |
20265 | ||
5a9335ef NC |
20266 | switch (fcode) |
20267 | { | |
20268 | case ARM_BUILTIN_TEXTRMSB: | |
20269 | case ARM_BUILTIN_TEXTRMUB: | |
20270 | case ARM_BUILTIN_TEXTRMSH: | |
20271 | case ARM_BUILTIN_TEXTRMUH: | |
20272 | case ARM_BUILTIN_TEXTRMSW: | |
20273 | case ARM_BUILTIN_TEXTRMUW: | |
20274 | icode = (fcode == ARM_BUILTIN_TEXTRMSB ? CODE_FOR_iwmmxt_textrmsb | |
20275 | : fcode == ARM_BUILTIN_TEXTRMUB ? CODE_FOR_iwmmxt_textrmub | |
20276 | : fcode == ARM_BUILTIN_TEXTRMSH ? CODE_FOR_iwmmxt_textrmsh | |
20277 | : fcode == ARM_BUILTIN_TEXTRMUH ? CODE_FOR_iwmmxt_textrmuh | |
20278 | : CODE_FOR_iwmmxt_textrmw); | |
20279 | ||
5039610b SL |
20280 | arg0 = CALL_EXPR_ARG (exp, 0); |
20281 | arg1 = CALL_EXPR_ARG (exp, 1); | |
84217346 MD |
20282 | op0 = expand_normal (arg0); |
20283 | op1 = expand_normal (arg1); | |
5a9335ef NC |
20284 | tmode = insn_data[icode].operand[0].mode; |
20285 | mode0 = insn_data[icode].operand[1].mode; | |
20286 | mode1 = insn_data[icode].operand[2].mode; | |
20287 | ||
20288 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
20289 | op0 = copy_to_mode_reg (mode0, op0); | |
20290 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
20291 | { | |
20292 | /* @@@ better error message */ | |
20293 | error ("selector must be an immediate"); | |
20294 | return gen_reg_rtx (tmode); | |
20295 | } | |
20296 | if (target == 0 | |
20297 | || GET_MODE (target) != tmode | |
20298 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
20299 | target = gen_reg_rtx (tmode); | |
20300 | pat = GEN_FCN (icode) (target, op0, op1); | |
20301 | if (! pat) | |
20302 | return 0; | |
20303 | emit_insn (pat); | |
20304 | return target; | |
20305 | ||
20306 | case ARM_BUILTIN_TINSRB: | |
20307 | case ARM_BUILTIN_TINSRH: | |
20308 | case ARM_BUILTIN_TINSRW: | |
20309 | icode = (fcode == ARM_BUILTIN_TINSRB ? CODE_FOR_iwmmxt_tinsrb | |
20310 | : fcode == ARM_BUILTIN_TINSRH ? CODE_FOR_iwmmxt_tinsrh | |
20311 | : CODE_FOR_iwmmxt_tinsrw); | |
5039610b SL |
20312 | arg0 = CALL_EXPR_ARG (exp, 0); |
20313 | arg1 = CALL_EXPR_ARG (exp, 1); | |
20314 | arg2 = CALL_EXPR_ARG (exp, 2); | |
84217346 MD |
20315 | op0 = expand_normal (arg0); |
20316 | op1 = expand_normal (arg1); | |
20317 | op2 = expand_normal (arg2); | |
5a9335ef NC |
20318 | tmode = insn_data[icode].operand[0].mode; |
20319 | mode0 = insn_data[icode].operand[1].mode; | |
20320 | mode1 = insn_data[icode].operand[2].mode; | |
20321 | mode2 = insn_data[icode].operand[3].mode; | |
20322 | ||
20323 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
20324 | op0 = copy_to_mode_reg (mode0, op0); | |
20325 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
20326 | op1 = copy_to_mode_reg (mode1, op1); | |
20327 | if (! (*insn_data[icode].operand[3].predicate) (op2, mode2)) | |
20328 | { | |
20329 | /* @@@ better error message */ | |
20330 | error ("selector must be an immediate"); | |
20331 | return const0_rtx; | |
20332 | } | |
20333 | if (target == 0 | |
20334 | || GET_MODE (target) != tmode | |
20335 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
20336 | target = gen_reg_rtx (tmode); | |
20337 | pat = GEN_FCN (icode) (target, op0, op1, op2); | |
20338 | if (! pat) | |
20339 | return 0; | |
20340 | emit_insn (pat); | |
20341 | return target; | |
20342 | ||
20343 | case ARM_BUILTIN_SETWCX: | |
5039610b SL |
20344 | arg0 = CALL_EXPR_ARG (exp, 0); |
20345 | arg1 = CALL_EXPR_ARG (exp, 1); | |
84217346 MD |
20346 | op0 = force_reg (SImode, expand_normal (arg0)); |
20347 | op1 = expand_normal (arg1); | |
f07a6b21 | 20348 | emit_insn (gen_iwmmxt_tmcr (op1, op0)); |
5a9335ef NC |
20349 | return 0; |
20350 | ||
20351 | case ARM_BUILTIN_GETWCX: | |
5039610b | 20352 | arg0 = CALL_EXPR_ARG (exp, 0); |
84217346 | 20353 | op0 = expand_normal (arg0); |
5a9335ef NC |
20354 | target = gen_reg_rtx (SImode); |
20355 | emit_insn (gen_iwmmxt_tmrc (target, op0)); | |
20356 | return target; | |
20357 | ||
20358 | case ARM_BUILTIN_WSHUFH: | |
20359 | icode = CODE_FOR_iwmmxt_wshufh; | |
5039610b SL |
20360 | arg0 = CALL_EXPR_ARG (exp, 0); |
20361 | arg1 = CALL_EXPR_ARG (exp, 1); | |
84217346 MD |
20362 | op0 = expand_normal (arg0); |
20363 | op1 = expand_normal (arg1); | |
5a9335ef NC |
20364 | tmode = insn_data[icode].operand[0].mode; |
20365 | mode1 = insn_data[icode].operand[1].mode; | |
20366 | mode2 = insn_data[icode].operand[2].mode; | |
20367 | ||
20368 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode1)) | |
20369 | op0 = copy_to_mode_reg (mode1, op0); | |
20370 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode2)) | |
20371 | { | |
20372 | /* @@@ better error message */ | |
20373 | error ("mask must be an immediate"); | |
20374 | return const0_rtx; | |
20375 | } | |
20376 | if (target == 0 | |
20377 | || GET_MODE (target) != tmode | |
20378 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
20379 | target = gen_reg_rtx (tmode); | |
20380 | pat = GEN_FCN (icode) (target, op0, op1); | |
20381 | if (! pat) | |
20382 | return 0; | |
20383 | emit_insn (pat); | |
20384 | return target; | |
20385 | ||
20386 | case ARM_BUILTIN_WSADB: | |
5039610b | 20387 | return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadb, exp, target); |
5a9335ef | 20388 | case ARM_BUILTIN_WSADH: |
5039610b | 20389 | return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadh, exp, target); |
5a9335ef | 20390 | case ARM_BUILTIN_WSADBZ: |
5039610b | 20391 | return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadbz, exp, target); |
5a9335ef | 20392 | case ARM_BUILTIN_WSADHZ: |
5039610b | 20393 | return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadhz, exp, target); |
5a9335ef NC |
20394 | |
20395 | /* Several three-argument builtins. */ | |
20396 | case ARM_BUILTIN_WMACS: | |
20397 | case ARM_BUILTIN_WMACU: | |
20398 | case ARM_BUILTIN_WALIGN: | |
20399 | case ARM_BUILTIN_TMIA: | |
20400 | case ARM_BUILTIN_TMIAPH: | |
20401 | case ARM_BUILTIN_TMIATT: | |
20402 | case ARM_BUILTIN_TMIATB: | |
20403 | case ARM_BUILTIN_TMIABT: | |
20404 | case ARM_BUILTIN_TMIABB: | |
20405 | icode = (fcode == ARM_BUILTIN_WMACS ? CODE_FOR_iwmmxt_wmacs | |
20406 | : fcode == ARM_BUILTIN_WMACU ? CODE_FOR_iwmmxt_wmacu | |
20407 | : fcode == ARM_BUILTIN_TMIA ? CODE_FOR_iwmmxt_tmia | |
20408 | : fcode == ARM_BUILTIN_TMIAPH ? CODE_FOR_iwmmxt_tmiaph | |
20409 | : fcode == ARM_BUILTIN_TMIABB ? CODE_FOR_iwmmxt_tmiabb | |
20410 | : fcode == ARM_BUILTIN_TMIABT ? CODE_FOR_iwmmxt_tmiabt | |
20411 | : fcode == ARM_BUILTIN_TMIATB ? CODE_FOR_iwmmxt_tmiatb | |
20412 | : fcode == ARM_BUILTIN_TMIATT ? CODE_FOR_iwmmxt_tmiatt | |
20413 | : CODE_FOR_iwmmxt_walign); | |
5039610b SL |
20414 | arg0 = CALL_EXPR_ARG (exp, 0); |
20415 | arg1 = CALL_EXPR_ARG (exp, 1); | |
20416 | arg2 = CALL_EXPR_ARG (exp, 2); | |
84217346 MD |
20417 | op0 = expand_normal (arg0); |
20418 | op1 = expand_normal (arg1); | |
20419 | op2 = expand_normal (arg2); | |
5a9335ef NC |
20420 | tmode = insn_data[icode].operand[0].mode; |
20421 | mode0 = insn_data[icode].operand[1].mode; | |
20422 | mode1 = insn_data[icode].operand[2].mode; | |
20423 | mode2 = insn_data[icode].operand[3].mode; | |
20424 | ||
20425 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
20426 | op0 = copy_to_mode_reg (mode0, op0); | |
20427 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
20428 | op1 = copy_to_mode_reg (mode1, op1); | |
20429 | if (! (*insn_data[icode].operand[3].predicate) (op2, mode2)) | |
20430 | op2 = copy_to_mode_reg (mode2, op2); | |
20431 | if (target == 0 | |
20432 | || GET_MODE (target) != tmode | |
20433 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
20434 | target = gen_reg_rtx (tmode); | |
20435 | pat = GEN_FCN (icode) (target, op0, op1, op2); | |
20436 | if (! pat) | |
20437 | return 0; | |
20438 | emit_insn (pat); | |
20439 | return target; | |
f676971a | 20440 | |
5a9335ef NC |
20441 | case ARM_BUILTIN_WZERO: |
20442 | target = gen_reg_rtx (DImode); | |
20443 | emit_insn (gen_iwmmxt_clrdi (target)); | |
20444 | return target; | |
20445 | ||
d3585b76 DJ |
20446 | case ARM_BUILTIN_THREAD_POINTER: |
20447 | return arm_load_tp (target); | |
20448 | ||
5a9335ef NC |
20449 | default: |
20450 | break; | |
20451 | } | |
20452 | ||
e97a46ce | 20453 | for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++) |
5a9335ef | 20454 | if (d->code == (const enum arm_builtins) fcode) |
5039610b | 20455 | return arm_expand_binop_builtin (d->icode, exp, target); |
5a9335ef | 20456 | |
e97a46ce | 20457 | for (i = 0, d = bdesc_1arg; i < ARRAY_SIZE (bdesc_1arg); i++, d++) |
5a9335ef | 20458 | if (d->code == (const enum arm_builtins) fcode) |
5039610b | 20459 | return arm_expand_unop_builtin (d->icode, exp, target, 0); |
5a9335ef NC |
20460 | |
20461 | /* @@@ Should really do something sensible here. */ | |
20462 | return NULL_RTX; | |
20463 | } | |
20464 | \f | |
1d6e90ac NC |
20465 | /* Return the number (counting from 0) of |
20466 | the least significant set bit in MASK. */ | |
20467 | ||
e32bac5b | 20468 | inline static int |
b279b20a | 20469 | number_of_first_bit_set (unsigned mask) |
d5b7b3ae | 20470 | { |
d018b46e RH |
20471 | return ctz_hwi (mask); |
20472 | } | |
20473 | ||
20474 | /* Like emit_multi_reg_push, but allowing for a different set of | |
20475 | registers to be described as saved. MASK is the set of registers | |
20476 | to be saved; REAL_REGS is the set of registers to be described as | |
20477 | saved. If REAL_REGS is 0, only describe the stack adjustment. */ | |
d5b7b3ae | 20478 | |
d018b46e RH |
20479 | static rtx |
20480 | thumb1_emit_multi_reg_push (unsigned long mask, unsigned long real_regs) | |
20481 | { | |
20482 | unsigned long regno; | |
20483 | rtx par[10], tmp, reg, insn; | |
20484 | int i, j; | |
20485 | ||
20486 | /* Build the parallel of the registers actually being stored. */ | |
20487 | for (i = 0; mask; ++i, mask &= mask - 1) | |
20488 | { | |
20489 | regno = ctz_hwi (mask); | |
20490 | reg = gen_rtx_REG (SImode, regno); | |
d5b7b3ae | 20491 | |
d018b46e RH |
20492 | if (i == 0) |
20493 | tmp = gen_rtx_UNSPEC (BLKmode, gen_rtvec (1, reg), UNSPEC_PUSH_MULT); | |
20494 | else | |
20495 | tmp = gen_rtx_USE (VOIDmode, reg); | |
20496 | ||
20497 | par[i] = tmp; | |
20498 | } | |
20499 | ||
20500 | tmp = plus_constant (stack_pointer_rtx, -4 * i); | |
20501 | tmp = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, tmp); | |
20502 | tmp = gen_frame_mem (BLKmode, tmp); | |
20503 | tmp = gen_rtx_SET (VOIDmode, tmp, par[0]); | |
20504 | par[0] = tmp; | |
20505 | ||
20506 | tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (i, par)); | |
20507 | insn = emit_insn (tmp); | |
20508 | ||
20509 | /* Always build the stack adjustment note for unwind info. */ | |
20510 | tmp = plus_constant (stack_pointer_rtx, -4 * i); | |
20511 | tmp = gen_rtx_SET (VOIDmode, stack_pointer_rtx, tmp); | |
20512 | par[0] = tmp; | |
20513 | ||
20514 | /* Build the parallel of the registers recorded as saved for unwind. */ | |
20515 | for (j = 0; real_regs; ++j, real_regs &= real_regs - 1) | |
20516 | { | |
20517 | regno = ctz_hwi (real_regs); | |
20518 | reg = gen_rtx_REG (SImode, regno); | |
20519 | ||
20520 | tmp = plus_constant (stack_pointer_rtx, j * 4); | |
20521 | tmp = gen_frame_mem (SImode, tmp); | |
20522 | tmp = gen_rtx_SET (VOIDmode, tmp, reg); | |
20523 | RTX_FRAME_RELATED_P (tmp) = 1; | |
20524 | par[j + 1] = tmp; | |
20525 | } | |
20526 | ||
20527 | if (j == 0) | |
20528 | tmp = par[0]; | |
20529 | else | |
20530 | { | |
20531 | RTX_FRAME_RELATED_P (par[0]) = 1; | |
20532 | tmp = gen_rtx_SEQUENCE (VOIDmode, gen_rtvec_v (j + 1, par)); | |
20533 | } | |
20534 | ||
20535 | add_reg_note (insn, REG_FRAME_RELATED_EXPR, tmp); | |
20536 | ||
20537 | return insn; | |
d5b7b3ae RE |
20538 | } |
20539 | ||
b279b20a | 20540 | /* Emit code to push or pop registers to or from the stack. F is the |
94759030 | 20541 | assembly file. MASK is the registers to pop. */ |
b279b20a | 20542 | static void |
94759030 | 20543 | thumb_pop (FILE *f, unsigned long mask) |
b279b20a NC |
20544 | { |
20545 | int regno; | |
20546 | int lo_mask = mask & 0xFF; | |
20547 | int pushed_words = 0; | |
20548 | ||
e6d29d15 | 20549 | gcc_assert (mask); |
b279b20a | 20550 | |
94759030 | 20551 | if (lo_mask == 0 && (mask & (1 << PC_REGNUM))) |
b279b20a NC |
20552 | { |
20553 | /* Special case. Do not generate a POP PC statement here, do it in | |
20554 | thumb_exit() */ | |
20555 | thumb_exit (f, -1); | |
20556 | return; | |
20557 | } | |
20558 | ||
94759030 | 20559 | fprintf (f, "\tpop\t{"); |
b279b20a NC |
20560 | |
20561 | /* Look at the low registers first. */ | |
20562 | for (regno = 0; regno <= LAST_LO_REGNUM; regno++, lo_mask >>= 1) | |
20563 | { | |
20564 | if (lo_mask & 1) | |
20565 | { | |
20566 | asm_fprintf (f, "%r", regno); | |
20567 | ||
20568 | if ((lo_mask & ~1) != 0) | |
20569 | fprintf (f, ", "); | |
20570 | ||
20571 | pushed_words++; | |
20572 | } | |
20573 | } | |
20574 | ||
94759030 | 20575 | if (mask & (1 << PC_REGNUM)) |
b279b20a NC |
20576 | { |
20577 | /* Catch popping the PC. */ | |
20578 | if (TARGET_INTERWORK || TARGET_BACKTRACE | |
e3b5732b | 20579 | || crtl->calls_eh_return) |
b279b20a NC |
20580 | { |
20581 | /* The PC is never poped directly, instead | |
20582 | it is popped into r3 and then BX is used. */ | |
20583 | fprintf (f, "}\n"); | |
20584 | ||
20585 | thumb_exit (f, -1); | |
20586 | ||
20587 | return; | |
20588 | } | |
20589 | else | |
20590 | { | |
20591 | if (mask & 0xFF) | |
20592 | fprintf (f, ", "); | |
20593 | ||
20594 | asm_fprintf (f, "%r", PC_REGNUM); | |
20595 | } | |
20596 | } | |
20597 | ||
20598 | fprintf (f, "}\n"); | |
b279b20a NC |
20599 | } |
20600 | ||
d5b7b3ae RE |
20601 | /* Generate code to return from a thumb function. |
20602 | If 'reg_containing_return_addr' is -1, then the return address is | |
20603 | actually on the stack, at the stack pointer. */ | |
20604 | static void | |
c9ca9b88 | 20605 | thumb_exit (FILE *f, int reg_containing_return_addr) |
d5b7b3ae RE |
20606 | { |
20607 | unsigned regs_available_for_popping; | |
20608 | unsigned regs_to_pop; | |
20609 | int pops_needed; | |
20610 | unsigned available; | |
20611 | unsigned required; | |
20612 | int mode; | |
20613 | int size; | |
20614 | int restore_a4 = FALSE; | |
20615 | ||
20616 | /* Compute the registers we need to pop. */ | |
20617 | regs_to_pop = 0; | |
20618 | pops_needed = 0; | |
20619 | ||
c9ca9b88 | 20620 | if (reg_containing_return_addr == -1) |
d5b7b3ae | 20621 | { |
d5b7b3ae | 20622 | regs_to_pop |= 1 << LR_REGNUM; |
5895f793 | 20623 | ++pops_needed; |
d5b7b3ae RE |
20624 | } |
20625 | ||
20626 | if (TARGET_BACKTRACE) | |
20627 | { | |
20628 | /* Restore the (ARM) frame pointer and stack pointer. */ | |
20629 | regs_to_pop |= (1 << ARM_HARD_FRAME_POINTER_REGNUM) | (1 << SP_REGNUM); | |
20630 | pops_needed += 2; | |
20631 | } | |
20632 | ||
20633 | /* If there is nothing to pop then just emit the BX instruction and | |
20634 | return. */ | |
20635 | if (pops_needed == 0) | |
20636 | { | |
e3b5732b | 20637 | if (crtl->calls_eh_return) |
c9ca9b88 | 20638 | asm_fprintf (f, "\tadd\t%r, %r\n", SP_REGNUM, ARM_EH_STACKADJ_REGNUM); |
d5b7b3ae RE |
20639 | |
20640 | asm_fprintf (f, "\tbx\t%r\n", reg_containing_return_addr); | |
20641 | return; | |
20642 | } | |
20643 | /* Otherwise if we are not supporting interworking and we have not created | |
20644 | a backtrace structure and the function was not entered in ARM mode then | |
20645 | just pop the return address straight into the PC. */ | |
5895f793 RE |
20646 | else if (!TARGET_INTERWORK |
20647 | && !TARGET_BACKTRACE | |
c9ca9b88 | 20648 | && !is_called_in_ARM_mode (current_function_decl) |
e3b5732b | 20649 | && !crtl->calls_eh_return) |
d5b7b3ae | 20650 | { |
c9ca9b88 | 20651 | asm_fprintf (f, "\tpop\t{%r}\n", PC_REGNUM); |
d5b7b3ae RE |
20652 | return; |
20653 | } | |
20654 | ||
20655 | /* Find out how many of the (return) argument registers we can corrupt. */ | |
20656 | regs_available_for_popping = 0; | |
20657 | ||
20658 | /* If returning via __builtin_eh_return, the bottom three registers | |
20659 | all contain information needed for the return. */ | |
e3b5732b | 20660 | if (crtl->calls_eh_return) |
d5b7b3ae RE |
20661 | size = 12; |
20662 | else | |
20663 | { | |
d5b7b3ae RE |
20664 | /* If we can deduce the registers used from the function's |
20665 | return value. This is more reliable that examining | |
6fb5fa3c | 20666 | df_regs_ever_live_p () because that will be set if the register is |
d5b7b3ae RE |
20667 | ever used in the function, not just if the register is used |
20668 | to hold a return value. */ | |
20669 | ||
38173d38 JH |
20670 | if (crtl->return_rtx != 0) |
20671 | mode = GET_MODE (crtl->return_rtx); | |
d5b7b3ae | 20672 | else |
d5b7b3ae RE |
20673 | mode = DECL_MODE (DECL_RESULT (current_function_decl)); |
20674 | ||
20675 | size = GET_MODE_SIZE (mode); | |
20676 | ||
20677 | if (size == 0) | |
20678 | { | |
20679 | /* In a void function we can use any argument register. | |
20680 | In a function that returns a structure on the stack | |
20681 | we can use the second and third argument registers. */ | |
20682 | if (mode == VOIDmode) | |
20683 | regs_available_for_popping = | |
20684 | (1 << ARG_REGISTER (1)) | |
20685 | | (1 << ARG_REGISTER (2)) | |
20686 | | (1 << ARG_REGISTER (3)); | |
20687 | else | |
20688 | regs_available_for_popping = | |
20689 | (1 << ARG_REGISTER (2)) | |
20690 | | (1 << ARG_REGISTER (3)); | |
20691 | } | |
20692 | else if (size <= 4) | |
20693 | regs_available_for_popping = | |
20694 | (1 << ARG_REGISTER (2)) | |
20695 | | (1 << ARG_REGISTER (3)); | |
20696 | else if (size <= 8) | |
20697 | regs_available_for_popping = | |
20698 | (1 << ARG_REGISTER (3)); | |
20699 | } | |
20700 | ||
20701 | /* Match registers to be popped with registers into which we pop them. */ | |
20702 | for (available = regs_available_for_popping, | |
20703 | required = regs_to_pop; | |
20704 | required != 0 && available != 0; | |
20705 | available &= ~(available & - available), | |
20706 | required &= ~(required & - required)) | |
20707 | -- pops_needed; | |
20708 | ||
20709 | /* If we have any popping registers left over, remove them. */ | |
20710 | if (available > 0) | |
5895f793 | 20711 | regs_available_for_popping &= ~available; |
f676971a | 20712 | |
d5b7b3ae RE |
20713 | /* Otherwise if we need another popping register we can use |
20714 | the fourth argument register. */ | |
20715 | else if (pops_needed) | |
20716 | { | |
20717 | /* If we have not found any free argument registers and | |
20718 | reg a4 contains the return address, we must move it. */ | |
20719 | if (regs_available_for_popping == 0 | |
20720 | && reg_containing_return_addr == LAST_ARG_REGNUM) | |
20721 | { | |
20722 | asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, LAST_ARG_REGNUM); | |
20723 | reg_containing_return_addr = LR_REGNUM; | |
20724 | } | |
20725 | else if (size > 12) | |
20726 | { | |
20727 | /* Register a4 is being used to hold part of the return value, | |
20728 | but we have dire need of a free, low register. */ | |
20729 | restore_a4 = TRUE; | |
f676971a | 20730 | |
d5b7b3ae RE |
20731 | asm_fprintf (f, "\tmov\t%r, %r\n",IP_REGNUM, LAST_ARG_REGNUM); |
20732 | } | |
f676971a | 20733 | |
d5b7b3ae RE |
20734 | if (reg_containing_return_addr != LAST_ARG_REGNUM) |
20735 | { | |
20736 | /* The fourth argument register is available. */ | |
20737 | regs_available_for_popping |= 1 << LAST_ARG_REGNUM; | |
f676971a | 20738 | |
5895f793 | 20739 | --pops_needed; |
d5b7b3ae RE |
20740 | } |
20741 | } | |
20742 | ||
20743 | /* Pop as many registers as we can. */ | |
94759030 | 20744 | thumb_pop (f, regs_available_for_popping); |
d5b7b3ae RE |
20745 | |
20746 | /* Process the registers we popped. */ | |
20747 | if (reg_containing_return_addr == -1) | |
20748 | { | |
20749 | /* The return address was popped into the lowest numbered register. */ | |
5895f793 | 20750 | regs_to_pop &= ~(1 << LR_REGNUM); |
f676971a | 20751 | |
d5b7b3ae RE |
20752 | reg_containing_return_addr = |
20753 | number_of_first_bit_set (regs_available_for_popping); | |
20754 | ||
20755 | /* Remove this register for the mask of available registers, so that | |
6bc82793 | 20756 | the return address will not be corrupted by further pops. */ |
5895f793 | 20757 | regs_available_for_popping &= ~(1 << reg_containing_return_addr); |
d5b7b3ae RE |
20758 | } |
20759 | ||
20760 | /* If we popped other registers then handle them here. */ | |
20761 | if (regs_available_for_popping) | |
20762 | { | |
20763 | int frame_pointer; | |
f676971a | 20764 | |
d5b7b3ae RE |
20765 | /* Work out which register currently contains the frame pointer. */ |
20766 | frame_pointer = number_of_first_bit_set (regs_available_for_popping); | |
20767 | ||
20768 | /* Move it into the correct place. */ | |
20769 | asm_fprintf (f, "\tmov\t%r, %r\n", | |
20770 | ARM_HARD_FRAME_POINTER_REGNUM, frame_pointer); | |
20771 | ||
20772 | /* (Temporarily) remove it from the mask of popped registers. */ | |
5895f793 RE |
20773 | regs_available_for_popping &= ~(1 << frame_pointer); |
20774 | regs_to_pop &= ~(1 << ARM_HARD_FRAME_POINTER_REGNUM); | |
f676971a | 20775 | |
d5b7b3ae RE |
20776 | if (regs_available_for_popping) |
20777 | { | |
20778 | int stack_pointer; | |
f676971a | 20779 | |
d5b7b3ae RE |
20780 | /* We popped the stack pointer as well, |
20781 | find the register that contains it. */ | |
20782 | stack_pointer = number_of_first_bit_set (regs_available_for_popping); | |
20783 | ||
20784 | /* Move it into the stack register. */ | |
20785 | asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, stack_pointer); | |
f676971a | 20786 | |
d5b7b3ae RE |
20787 | /* At this point we have popped all necessary registers, so |
20788 | do not worry about restoring regs_available_for_popping | |
20789 | to its correct value: | |
20790 | ||
20791 | assert (pops_needed == 0) | |
20792 | assert (regs_available_for_popping == (1 << frame_pointer)) | |
20793 | assert (regs_to_pop == (1 << STACK_POINTER)) */ | |
20794 | } | |
20795 | else | |
20796 | { | |
20797 | /* Since we have just move the popped value into the frame | |
20798 | pointer, the popping register is available for reuse, and | |
20799 | we know that we still have the stack pointer left to pop. */ | |
20800 | regs_available_for_popping |= (1 << frame_pointer); | |
20801 | } | |
20802 | } | |
f676971a | 20803 | |
d5b7b3ae RE |
20804 | /* If we still have registers left on the stack, but we no longer have |
20805 | any registers into which we can pop them, then we must move the return | |
20806 | address into the link register and make available the register that | |
20807 | contained it. */ | |
20808 | if (regs_available_for_popping == 0 && pops_needed > 0) | |
20809 | { | |
20810 | regs_available_for_popping |= 1 << reg_containing_return_addr; | |
f676971a | 20811 | |
d5b7b3ae RE |
20812 | asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, |
20813 | reg_containing_return_addr); | |
f676971a | 20814 | |
d5b7b3ae RE |
20815 | reg_containing_return_addr = LR_REGNUM; |
20816 | } | |
20817 | ||
20818 | /* If we have registers left on the stack then pop some more. | |
20819 | We know that at most we will want to pop FP and SP. */ | |
20820 | if (pops_needed > 0) | |
20821 | { | |
20822 | int popped_into; | |
20823 | int move_to; | |
f676971a | 20824 | |
94759030 | 20825 | thumb_pop (f, regs_available_for_popping); |
d5b7b3ae RE |
20826 | |
20827 | /* We have popped either FP or SP. | |
20828 | Move whichever one it is into the correct register. */ | |
20829 | popped_into = number_of_first_bit_set (regs_available_for_popping); | |
20830 | move_to = number_of_first_bit_set (regs_to_pop); | |
20831 | ||
20832 | asm_fprintf (f, "\tmov\t%r, %r\n", move_to, popped_into); | |
20833 | ||
5895f793 | 20834 | regs_to_pop &= ~(1 << move_to); |
d5b7b3ae | 20835 | |
5895f793 | 20836 | --pops_needed; |
d5b7b3ae | 20837 | } |
f676971a | 20838 | |
d5b7b3ae RE |
20839 | /* If we still have not popped everything then we must have only |
20840 | had one register available to us and we are now popping the SP. */ | |
20841 | if (pops_needed > 0) | |
20842 | { | |
20843 | int popped_into; | |
f676971a | 20844 | |
94759030 | 20845 | thumb_pop (f, regs_available_for_popping); |
d5b7b3ae RE |
20846 | |
20847 | popped_into = number_of_first_bit_set (regs_available_for_popping); | |
20848 | ||
20849 | asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, popped_into); | |
20850 | /* | |
20851 | assert (regs_to_pop == (1 << STACK_POINTER)) | |
20852 | assert (pops_needed == 1) | |
20853 | */ | |
20854 | } | |
20855 | ||
20856 | /* If necessary restore the a4 register. */ | |
20857 | if (restore_a4) | |
20858 | { | |
20859 | if (reg_containing_return_addr != LR_REGNUM) | |
20860 | { | |
20861 | asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, LAST_ARG_REGNUM); | |
20862 | reg_containing_return_addr = LR_REGNUM; | |
20863 | } | |
f676971a | 20864 | |
d5b7b3ae RE |
20865 | asm_fprintf (f, "\tmov\t%r, %r\n", LAST_ARG_REGNUM, IP_REGNUM); |
20866 | } | |
20867 | ||
e3b5732b | 20868 | if (crtl->calls_eh_return) |
c9ca9b88 | 20869 | asm_fprintf (f, "\tadd\t%r, %r\n", SP_REGNUM, ARM_EH_STACKADJ_REGNUM); |
d5b7b3ae RE |
20870 | |
20871 | /* Return to caller. */ | |
20872 | asm_fprintf (f, "\tbx\t%r\n", reg_containing_return_addr); | |
20873 | } | |
d5b7b3ae | 20874 | \f |
906668bb BS |
20875 | /* Scan INSN just before assembler is output for it. |
20876 | For Thumb-1, we track the status of the condition codes; this | |
20877 | information is used in the cbranchsi4_insn pattern. */ | |
d5b7b3ae | 20878 | void |
5b3e6663 | 20879 | thumb1_final_prescan_insn (rtx insn) |
d5b7b3ae | 20880 | { |
d5b7b3ae | 20881 | if (flag_print_asm_name) |
9d98a694 AO |
20882 | asm_fprintf (asm_out_file, "%@ 0x%04x\n", |
20883 | INSN_ADDRESSES (INSN_UID (insn))); | |
906668bb BS |
20884 | /* Don't overwrite the previous setter when we get to a cbranch. */ |
20885 | if (INSN_CODE (insn) != CODE_FOR_cbranchsi4_insn) | |
20886 | { | |
20887 | enum attr_conds conds; | |
20888 | ||
20889 | if (cfun->machine->thumb1_cc_insn) | |
20890 | { | |
20891 | if (modified_in_p (cfun->machine->thumb1_cc_op0, insn) | |
20892 | || modified_in_p (cfun->machine->thumb1_cc_op1, insn)) | |
20893 | CC_STATUS_INIT; | |
20894 | } | |
20895 | conds = get_attr_conds (insn); | |
20896 | if (conds == CONDS_SET) | |
20897 | { | |
20898 | rtx set = single_set (insn); | |
20899 | cfun->machine->thumb1_cc_insn = insn; | |
20900 | cfun->machine->thumb1_cc_op0 = SET_DEST (set); | |
20901 | cfun->machine->thumb1_cc_op1 = const0_rtx; | |
20902 | cfun->machine->thumb1_cc_mode = CC_NOOVmode; | |
20903 | if (INSN_CODE (insn) == CODE_FOR_thumb1_subsi3_insn) | |
20904 | { | |
20905 | rtx src1 = XEXP (SET_SRC (set), 1); | |
20906 | if (src1 == const0_rtx) | |
20907 | cfun->machine->thumb1_cc_mode = CCmode; | |
20908 | } | |
20909 | } | |
20910 | else if (conds != CONDS_NOCOND) | |
20911 | cfun->machine->thumb1_cc_insn = NULL_RTX; | |
20912 | } | |
d5b7b3ae RE |
20913 | } |
20914 | ||
20915 | int | |
e32bac5b | 20916 | thumb_shiftable_const (unsigned HOST_WIDE_INT val) |
d5b7b3ae RE |
20917 | { |
20918 | unsigned HOST_WIDE_INT mask = 0xff; | |
20919 | int i; | |
20920 | ||
ce41c38b | 20921 | val = val & (unsigned HOST_WIDE_INT)0xffffffffu; |
d5b7b3ae RE |
20922 | if (val == 0) /* XXX */ |
20923 | return 0; | |
f676971a | 20924 | |
d5b7b3ae RE |
20925 | for (i = 0; i < 25; i++) |
20926 | if ((val & (mask << i)) == val) | |
20927 | return 1; | |
20928 | ||
20929 | return 0; | |
20930 | } | |
20931 | ||
825dda42 | 20932 | /* Returns nonzero if the current function contains, |
d5b7b3ae | 20933 | or might contain a far jump. */ |
5848830f PB |
20934 | static int |
20935 | thumb_far_jump_used_p (void) | |
d5b7b3ae RE |
20936 | { |
20937 | rtx insn; | |
20938 | ||
20939 | /* This test is only important for leaf functions. */ | |
5895f793 | 20940 | /* assert (!leaf_function_p ()); */ |
f676971a | 20941 | |
d5b7b3ae RE |
20942 | /* If we have already decided that far jumps may be used, |
20943 | do not bother checking again, and always return true even if | |
20944 | it turns out that they are not being used. Once we have made | |
20945 | the decision that far jumps are present (and that hence the link | |
20946 | register will be pushed onto the stack) we cannot go back on it. */ | |
20947 | if (cfun->machine->far_jump_used) | |
20948 | return 1; | |
20949 | ||
20950 | /* If this function is not being called from the prologue/epilogue | |
20951 | generation code then it must be being called from the | |
20952 | INITIAL_ELIMINATION_OFFSET macro. */ | |
5848830f | 20953 | if (!(ARM_DOUBLEWORD_ALIGN || reload_completed)) |
d5b7b3ae RE |
20954 | { |
20955 | /* In this case we know that we are being asked about the elimination | |
20956 | of the arg pointer register. If that register is not being used, | |
20957 | then there are no arguments on the stack, and we do not have to | |
20958 | worry that a far jump might force the prologue to push the link | |
20959 | register, changing the stack offsets. In this case we can just | |
20960 | return false, since the presence of far jumps in the function will | |
20961 | not affect stack offsets. | |
20962 | ||
20963 | If the arg pointer is live (or if it was live, but has now been | |
20964 | eliminated and so set to dead) then we do have to test to see if | |
20965 | the function might contain a far jump. This test can lead to some | |
20966 | false negatives, since before reload is completed, then length of | |
20967 | branch instructions is not known, so gcc defaults to returning their | |
20968 | longest length, which in turn sets the far jump attribute to true. | |
20969 | ||
20970 | A false negative will not result in bad code being generated, but it | |
20971 | will result in a needless push and pop of the link register. We | |
5848830f PB |
20972 | hope that this does not occur too often. |
20973 | ||
20974 | If we need doubleword stack alignment this could affect the other | |
20975 | elimination offsets so we can't risk getting it wrong. */ | |
6fb5fa3c | 20976 | if (df_regs_ever_live_p (ARG_POINTER_REGNUM)) |
d5b7b3ae | 20977 | cfun->machine->arg_pointer_live = 1; |
5895f793 | 20978 | else if (!cfun->machine->arg_pointer_live) |
d5b7b3ae RE |
20979 | return 0; |
20980 | } | |
20981 | ||
20982 | /* Check to see if the function contains a branch | |
20983 | insn with the far jump attribute set. */ | |
20984 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
20985 | { | |
20986 | if (GET_CODE (insn) == JUMP_INSN | |
20987 | /* Ignore tablejump patterns. */ | |
20988 | && GET_CODE (PATTERN (insn)) != ADDR_VEC | |
20989 | && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC | |
20990 | && get_attr_far_jump (insn) == FAR_JUMP_YES | |
20991 | ) | |
20992 | { | |
9a9f7594 | 20993 | /* Record the fact that we have decided that |
d5b7b3ae RE |
20994 | the function does use far jumps. */ |
20995 | cfun->machine->far_jump_used = 1; | |
20996 | return 1; | |
20997 | } | |
20998 | } | |
f676971a | 20999 | |
d5b7b3ae RE |
21000 | return 0; |
21001 | } | |
21002 | ||
825dda42 | 21003 | /* Return nonzero if FUNC must be entered in ARM mode. */ |
d5b7b3ae | 21004 | int |
e32bac5b | 21005 | is_called_in_ARM_mode (tree func) |
d5b7b3ae | 21006 | { |
e6d29d15 | 21007 | gcc_assert (TREE_CODE (func) == FUNCTION_DECL); |
d5b7b3ae | 21008 | |
696e78bf | 21009 | /* Ignore the problem about functions whose address is taken. */ |
d5b7b3ae RE |
21010 | if (TARGET_CALLEE_INTERWORKING && TREE_PUBLIC (func)) |
21011 | return TRUE; | |
21012 | ||
f676971a | 21013 | #ifdef ARM_PE |
91d231cb | 21014 | return lookup_attribute ("interfacearm", DECL_ATTRIBUTES (func)) != NULL_TREE; |
d5b7b3ae RE |
21015 | #else |
21016 | return FALSE; | |
21017 | #endif | |
21018 | } | |
21019 | ||
e784c52c BS |
21020 | /* Given the stack offsets and register mask in OFFSETS, decide how |
21021 | many additional registers to push instead of subtracting a constant | |
21022 | from SP. For epilogues the principle is the same except we use pop. | |
21023 | FOR_PROLOGUE indicates which we're generating. */ | |
21024 | static int | |
21025 | thumb1_extra_regs_pushed (arm_stack_offsets *offsets, bool for_prologue) | |
21026 | { | |
21027 | HOST_WIDE_INT amount; | |
21028 | unsigned long live_regs_mask = offsets->saved_regs_mask; | |
21029 | /* Extract a mask of the ones we can give to the Thumb's push/pop | |
21030 | instruction. */ | |
21031 | unsigned long l_mask = live_regs_mask & (for_prologue ? 0x40ff : 0xff); | |
21032 | /* Then count how many other high registers will need to be pushed. */ | |
21033 | unsigned long high_regs_pushed = bit_count (live_regs_mask & 0x0f00); | |
21034 | int n_free, reg_base; | |
21035 | ||
21036 | if (!for_prologue && frame_pointer_needed) | |
21037 | amount = offsets->locals_base - offsets->saved_regs; | |
21038 | else | |
21039 | amount = offsets->outgoing_args - offsets->saved_regs; | |
21040 | ||
21041 | /* If the stack frame size is 512 exactly, we can save one load | |
21042 | instruction, which should make this a win even when optimizing | |
21043 | for speed. */ | |
21044 | if (!optimize_size && amount != 512) | |
21045 | return 0; | |
21046 | ||
21047 | /* Can't do this if there are high registers to push. */ | |
21048 | if (high_regs_pushed != 0) | |
21049 | return 0; | |
21050 | ||
21051 | /* Shouldn't do it in the prologue if no registers would normally | |
21052 | be pushed at all. In the epilogue, also allow it if we'll have | |
21053 | a pop insn for the PC. */ | |
21054 | if (l_mask == 0 | |
21055 | && (for_prologue | |
21056 | || TARGET_BACKTRACE | |
21057 | || (live_regs_mask & 1 << LR_REGNUM) == 0 | |
21058 | || TARGET_INTERWORK | |
21059 | || crtl->args.pretend_args_size != 0)) | |
21060 | return 0; | |
21061 | ||
21062 | /* Don't do this if thumb_expand_prologue wants to emit instructions | |
21063 | between the push and the stack frame allocation. */ | |
21064 | if (for_prologue | |
21065 | && ((flag_pic && arm_pic_register != INVALID_REGNUM) | |
21066 | || (!frame_pointer_needed && CALLER_INTERWORKING_SLOT_SIZE > 0))) | |
21067 | return 0; | |
21068 | ||
21069 | reg_base = 0; | |
21070 | n_free = 0; | |
21071 | if (!for_prologue) | |
21072 | { | |
21073 | reg_base = arm_size_return_regs () / UNITS_PER_WORD; | |
21074 | live_regs_mask >>= reg_base; | |
21075 | } | |
21076 | ||
21077 | while (reg_base + n_free < 8 && !(live_regs_mask & 1) | |
21078 | && (for_prologue || call_used_regs[reg_base + n_free])) | |
21079 | { | |
21080 | live_regs_mask >>= 1; | |
21081 | n_free++; | |
21082 | } | |
21083 | ||
21084 | if (n_free == 0) | |
21085 | return 0; | |
21086 | gcc_assert (amount / 4 * 4 == amount); | |
21087 | ||
21088 | if (amount >= 512 && (amount - n_free * 4) < 512) | |
21089 | return (amount - 508) / 4; | |
21090 | if (amount <= n_free * 4) | |
21091 | return amount / 4; | |
21092 | return 0; | |
21093 | } | |
21094 | ||
d6b4baa4 | 21095 | /* The bits which aren't usefully expanded as rtl. */ |
cd2b33d0 | 21096 | const char * |
e32bac5b | 21097 | thumb_unexpanded_epilogue (void) |
d5b7b3ae | 21098 | { |
954954d1 | 21099 | arm_stack_offsets *offsets; |
d5b7b3ae | 21100 | int regno; |
b279b20a | 21101 | unsigned long live_regs_mask = 0; |
d5b7b3ae | 21102 | int high_regs_pushed = 0; |
e784c52c | 21103 | int extra_pop; |
d5b7b3ae | 21104 | int had_to_push_lr; |
57934c39 | 21105 | int size; |
d5b7b3ae | 21106 | |
934c2060 | 21107 | if (cfun->machine->return_used_this_function != 0) |
d5b7b3ae RE |
21108 | return ""; |
21109 | ||
58e60158 AN |
21110 | if (IS_NAKED (arm_current_func_type ())) |
21111 | return ""; | |
21112 | ||
954954d1 PB |
21113 | offsets = arm_get_frame_offsets (); |
21114 | live_regs_mask = offsets->saved_regs_mask; | |
57934c39 PB |
21115 | high_regs_pushed = bit_count (live_regs_mask & 0x0f00); |
21116 | ||
21117 | /* If we can deduce the registers used from the function's return value. | |
6fb5fa3c | 21118 | This is more reliable that examining df_regs_ever_live_p () because that |
57934c39 PB |
21119 | will be set if the register is ever used in the function, not just if |
21120 | the register is used to hold a return value. */ | |
4f5dfed0 | 21121 | size = arm_size_return_regs (); |
d5b7b3ae | 21122 | |
e784c52c BS |
21123 | extra_pop = thumb1_extra_regs_pushed (offsets, false); |
21124 | if (extra_pop > 0) | |
21125 | { | |
21126 | unsigned long extra_mask = (1 << extra_pop) - 1; | |
21127 | live_regs_mask |= extra_mask << (size / UNITS_PER_WORD); | |
21128 | } | |
21129 | ||
d5b7b3ae | 21130 | /* The prolog may have pushed some high registers to use as |
112cdef5 | 21131 | work registers. e.g. the testsuite file: |
d5b7b3ae RE |
21132 | gcc/testsuite/gcc/gcc.c-torture/execute/complex-2.c |
21133 | compiles to produce: | |
21134 | push {r4, r5, r6, r7, lr} | |
21135 | mov r7, r9 | |
21136 | mov r6, r8 | |
21137 | push {r6, r7} | |
21138 | as part of the prolog. We have to undo that pushing here. */ | |
f676971a | 21139 | |
d5b7b3ae RE |
21140 | if (high_regs_pushed) |
21141 | { | |
b279b20a | 21142 | unsigned long mask = live_regs_mask & 0xff; |
d5b7b3ae | 21143 | int next_hi_reg; |
d5b7b3ae | 21144 | |
57934c39 PB |
21145 | /* The available low registers depend on the size of the value we are |
21146 | returning. */ | |
21147 | if (size <= 12) | |
d5b7b3ae | 21148 | mask |= 1 << 3; |
57934c39 PB |
21149 | if (size <= 8) |
21150 | mask |= 1 << 2; | |
d5b7b3ae RE |
21151 | |
21152 | if (mask == 0) | |
21153 | /* Oh dear! We have no low registers into which we can pop | |
21154 | high registers! */ | |
400500c4 RK |
21155 | internal_error |
21156 | ("no low registers available for popping high registers"); | |
f676971a | 21157 | |
d5b7b3ae | 21158 | for (next_hi_reg = 8; next_hi_reg < 13; next_hi_reg++) |
57934c39 | 21159 | if (live_regs_mask & (1 << next_hi_reg)) |
d5b7b3ae RE |
21160 | break; |
21161 | ||
21162 | while (high_regs_pushed) | |
21163 | { | |
21164 | /* Find lo register(s) into which the high register(s) can | |
21165 | be popped. */ | |
21166 | for (regno = 0; regno <= LAST_LO_REGNUM; regno++) | |
21167 | { | |
21168 | if (mask & (1 << regno)) | |
21169 | high_regs_pushed--; | |
21170 | if (high_regs_pushed == 0) | |
21171 | break; | |
21172 | } | |
21173 | ||
21174 | mask &= (2 << regno) - 1; /* A noop if regno == 8 */ | |
21175 | ||
d6b4baa4 | 21176 | /* Pop the values into the low register(s). */ |
94759030 | 21177 | thumb_pop (asm_out_file, mask); |
d5b7b3ae RE |
21178 | |
21179 | /* Move the value(s) into the high registers. */ | |
21180 | for (regno = 0; regno <= LAST_LO_REGNUM; regno++) | |
21181 | { | |
21182 | if (mask & (1 << regno)) | |
21183 | { | |
21184 | asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", next_hi_reg, | |
21185 | regno); | |
f676971a | 21186 | |
d5b7b3ae | 21187 | for (next_hi_reg++; next_hi_reg < 13; next_hi_reg++) |
57934c39 | 21188 | if (live_regs_mask & (1 << next_hi_reg)) |
d5b7b3ae RE |
21189 | break; |
21190 | } | |
21191 | } | |
21192 | } | |
57934c39 | 21193 | live_regs_mask &= ~0x0f00; |
d5b7b3ae RE |
21194 | } |
21195 | ||
57934c39 PB |
21196 | had_to_push_lr = (live_regs_mask & (1 << LR_REGNUM)) != 0; |
21197 | live_regs_mask &= 0xff; | |
21198 | ||
38173d38 | 21199 | if (crtl->args.pretend_args_size == 0 || TARGET_BACKTRACE) |
d5b7b3ae | 21200 | { |
f676971a | 21201 | /* Pop the return address into the PC. */ |
57934c39 | 21202 | if (had_to_push_lr) |
d5b7b3ae RE |
21203 | live_regs_mask |= 1 << PC_REGNUM; |
21204 | ||
21205 | /* Either no argument registers were pushed or a backtrace | |
21206 | structure was created which includes an adjusted stack | |
21207 | pointer, so just pop everything. */ | |
21208 | if (live_regs_mask) | |
94759030 | 21209 | thumb_pop (asm_out_file, live_regs_mask); |
57934c39 | 21210 | |
d5b7b3ae | 21211 | /* We have either just popped the return address into the |
e784c52c | 21212 | PC or it is was kept in LR for the entire function. |
94759030 | 21213 | Note that thumb_pop has already called thumb_exit if the |
e784c52c | 21214 | PC was in the list. */ |
57934c39 PB |
21215 | if (!had_to_push_lr) |
21216 | thumb_exit (asm_out_file, LR_REGNUM); | |
d5b7b3ae RE |
21217 | } |
21218 | else | |
21219 | { | |
21220 | /* Pop everything but the return address. */ | |
d5b7b3ae | 21221 | if (live_regs_mask) |
94759030 | 21222 | thumb_pop (asm_out_file, live_regs_mask); |
d5b7b3ae RE |
21223 | |
21224 | if (had_to_push_lr) | |
57934c39 PB |
21225 | { |
21226 | if (size > 12) | |
21227 | { | |
21228 | /* We have no free low regs, so save one. */ | |
21229 | asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", IP_REGNUM, | |
21230 | LAST_ARG_REGNUM); | |
21231 | } | |
21232 | ||
21233 | /* Get the return address into a temporary register. */ | |
94759030 | 21234 | thumb_pop (asm_out_file, 1 << LAST_ARG_REGNUM); |
57934c39 PB |
21235 | |
21236 | if (size > 12) | |
21237 | { | |
21238 | /* Move the return address to lr. */ | |
21239 | asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", LR_REGNUM, | |
21240 | LAST_ARG_REGNUM); | |
21241 | /* Restore the low register. */ | |
21242 | asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", LAST_ARG_REGNUM, | |
21243 | IP_REGNUM); | |
21244 | regno = LR_REGNUM; | |
21245 | } | |
21246 | else | |
21247 | regno = LAST_ARG_REGNUM; | |
21248 | } | |
21249 | else | |
21250 | regno = LR_REGNUM; | |
f676971a | 21251 | |
d5b7b3ae RE |
21252 | /* Remove the argument registers that were pushed onto the stack. */ |
21253 | asm_fprintf (asm_out_file, "\tadd\t%r, %r, #%d\n", | |
21254 | SP_REGNUM, SP_REGNUM, | |
38173d38 | 21255 | crtl->args.pretend_args_size); |
f676971a | 21256 | |
57934c39 | 21257 | thumb_exit (asm_out_file, regno); |
d5b7b3ae RE |
21258 | } |
21259 | ||
21260 | return ""; | |
21261 | } | |
21262 | ||
21263 | /* Functions to save and restore machine-specific function data. */ | |
e2500fed | 21264 | static struct machine_function * |
e32bac5b | 21265 | arm_init_machine_status (void) |
d5b7b3ae | 21266 | { |
e2500fed | 21267 | struct machine_function *machine; |
a9429e29 | 21268 | machine = ggc_alloc_cleared_machine_function (); |
6d3d9133 | 21269 | |
f676971a | 21270 | #if ARM_FT_UNKNOWN != 0 |
e2500fed | 21271 | machine->func_type = ARM_FT_UNKNOWN; |
6d3d9133 | 21272 | #endif |
e2500fed | 21273 | return machine; |
f7a80099 NC |
21274 | } |
21275 | ||
d5b7b3ae RE |
21276 | /* Return an RTX indicating where the return address to the |
21277 | calling function can be found. */ | |
21278 | rtx | |
e32bac5b | 21279 | arm_return_addr (int count, rtx frame ATTRIBUTE_UNUSED) |
d5b7b3ae | 21280 | { |
d5b7b3ae RE |
21281 | if (count != 0) |
21282 | return NULL_RTX; | |
21283 | ||
61f0ccff | 21284 | return get_hard_reg_initial_val (Pmode, LR_REGNUM); |
d5b7b3ae RE |
21285 | } |
21286 | ||
21287 | /* Do anything needed before RTL is emitted for each function. */ | |
21288 | void | |
e32bac5b | 21289 | arm_init_expanders (void) |
d5b7b3ae RE |
21290 | { |
21291 | /* Arrange to initialize and mark the machine per-function status. */ | |
21292 | init_machine_status = arm_init_machine_status; | |
3ac5ea7c RH |
21293 | |
21294 | /* This is to stop the combine pass optimizing away the alignment | |
21295 | adjustment of va_arg. */ | |
21296 | /* ??? It is claimed that this should not be necessary. */ | |
21297 | if (cfun) | |
21298 | mark_reg_pointer (arg_pointer_rtx, PARM_BOUNDARY); | |
d5b7b3ae RE |
21299 | } |
21300 | ||
0977774b | 21301 | |
2591db65 RE |
21302 | /* Like arm_compute_initial_elimination offset. Simpler because there |
21303 | isn't an ABI specified frame pointer for Thumb. Instead, we set it | |
21304 | to point at the base of the local variables after static stack | |
21305 | space for a function has been allocated. */ | |
0977774b | 21306 | |
5848830f PB |
21307 | HOST_WIDE_INT |
21308 | thumb_compute_initial_elimination_offset (unsigned int from, unsigned int to) | |
21309 | { | |
21310 | arm_stack_offsets *offsets; | |
0977774b | 21311 | |
5848830f | 21312 | offsets = arm_get_frame_offsets (); |
0977774b | 21313 | |
5848830f | 21314 | switch (from) |
0977774b | 21315 | { |
5848830f PB |
21316 | case ARG_POINTER_REGNUM: |
21317 | switch (to) | |
21318 | { | |
21319 | case STACK_POINTER_REGNUM: | |
21320 | return offsets->outgoing_args - offsets->saved_args; | |
0977774b | 21321 | |
5848830f PB |
21322 | case FRAME_POINTER_REGNUM: |
21323 | return offsets->soft_frame - offsets->saved_args; | |
0977774b | 21324 | |
5848830f PB |
21325 | case ARM_HARD_FRAME_POINTER_REGNUM: |
21326 | return offsets->saved_regs - offsets->saved_args; | |
0977774b | 21327 | |
2591db65 RE |
21328 | case THUMB_HARD_FRAME_POINTER_REGNUM: |
21329 | return offsets->locals_base - offsets->saved_args; | |
21330 | ||
5848830f | 21331 | default: |
e6d29d15 | 21332 | gcc_unreachable (); |
5848830f PB |
21333 | } |
21334 | break; | |
0977774b | 21335 | |
5848830f PB |
21336 | case FRAME_POINTER_REGNUM: |
21337 | switch (to) | |
21338 | { | |
21339 | case STACK_POINTER_REGNUM: | |
21340 | return offsets->outgoing_args - offsets->soft_frame; | |
0977774b | 21341 | |
5848830f PB |
21342 | case ARM_HARD_FRAME_POINTER_REGNUM: |
21343 | return offsets->saved_regs - offsets->soft_frame; | |
0977774b | 21344 | |
2591db65 RE |
21345 | case THUMB_HARD_FRAME_POINTER_REGNUM: |
21346 | return offsets->locals_base - offsets->soft_frame; | |
21347 | ||
5848830f | 21348 | default: |
e6d29d15 | 21349 | gcc_unreachable (); |
5848830f PB |
21350 | } |
21351 | break; | |
0977774b | 21352 | |
5848830f | 21353 | default: |
e6d29d15 | 21354 | gcc_unreachable (); |
5848830f | 21355 | } |
0977774b JT |
21356 | } |
21357 | ||
d018b46e RH |
21358 | /* Generate the function's prologue. */ |
21359 | ||
d5b7b3ae | 21360 | void |
5b3e6663 | 21361 | thumb1_expand_prologue (void) |
d5b7b3ae | 21362 | { |
d018b46e | 21363 | rtx insn; |
980e61bb | 21364 | |
5848830f PB |
21365 | HOST_WIDE_INT amount; |
21366 | arm_stack_offsets *offsets; | |
6d3d9133 | 21367 | unsigned long func_type; |
3c7ad43e | 21368 | int regno; |
57934c39 | 21369 | unsigned long live_regs_mask; |
d018b46e RH |
21370 | unsigned long l_mask; |
21371 | unsigned high_regs_pushed = 0; | |
6d3d9133 NC |
21372 | |
21373 | func_type = arm_current_func_type (); | |
f676971a | 21374 | |
d5b7b3ae | 21375 | /* Naked functions don't have prologues. */ |
6d3d9133 | 21376 | if (IS_NAKED (func_type)) |
d5b7b3ae RE |
21377 | return; |
21378 | ||
6d3d9133 NC |
21379 | if (IS_INTERRUPT (func_type)) |
21380 | { | |
c725bd79 | 21381 | error ("interrupt Service Routines cannot be coded in Thumb mode"); |
6d3d9133 NC |
21382 | return; |
21383 | } | |
21384 | ||
d018b46e RH |
21385 | if (is_called_in_ARM_mode (current_function_decl)) |
21386 | emit_insn (gen_prologue_thumb1_interwork ()); | |
21387 | ||
954954d1 PB |
21388 | offsets = arm_get_frame_offsets (); |
21389 | live_regs_mask = offsets->saved_regs_mask; | |
d018b46e RH |
21390 | |
21391 | /* Extract a mask of the ones we can give to the Thumb's push instruction. */ | |
21392 | l_mask = live_regs_mask & 0x40ff; | |
21393 | /* Then count how many other high registers will need to be pushed. */ | |
21394 | high_regs_pushed = bit_count (live_regs_mask & 0x0f00); | |
21395 | ||
21396 | if (crtl->args.pretend_args_size) | |
21397 | { | |
21398 | rtx x = GEN_INT (-crtl->args.pretend_args_size); | |
21399 | ||
21400 | if (cfun->machine->uses_anonymous_args) | |
21401 | { | |
21402 | int num_pushes = ARM_NUM_INTS (crtl->args.pretend_args_size); | |
21403 | unsigned long mask; | |
21404 | ||
21405 | mask = 1ul << (LAST_ARG_REGNUM + 1); | |
21406 | mask -= 1ul << (LAST_ARG_REGNUM + 1 - num_pushes); | |
21407 | ||
21408 | insn = thumb1_emit_multi_reg_push (mask, 0); | |
21409 | } | |
21410 | else | |
21411 | { | |
21412 | insn = emit_insn (gen_addsi3 (stack_pointer_rtx, | |
21413 | stack_pointer_rtx, x)); | |
21414 | } | |
21415 | RTX_FRAME_RELATED_P (insn) = 1; | |
21416 | } | |
21417 | ||
21418 | if (TARGET_BACKTRACE) | |
21419 | { | |
21420 | HOST_WIDE_INT offset = 0; | |
21421 | unsigned work_register; | |
21422 | rtx work_reg, x, arm_hfp_rtx; | |
21423 | ||
21424 | /* We have been asked to create a stack backtrace structure. | |
21425 | The code looks like this: | |
21426 | ||
21427 | 0 .align 2 | |
21428 | 0 func: | |
21429 | 0 sub SP, #16 Reserve space for 4 registers. | |
21430 | 2 push {R7} Push low registers. | |
21431 | 4 add R7, SP, #20 Get the stack pointer before the push. | |
21432 | 6 str R7, [SP, #8] Store the stack pointer | |
21433 | (before reserving the space). | |
21434 | 8 mov R7, PC Get hold of the start of this code + 12. | |
21435 | 10 str R7, [SP, #16] Store it. | |
21436 | 12 mov R7, FP Get hold of the current frame pointer. | |
21437 | 14 str R7, [SP, #4] Store it. | |
21438 | 16 mov R7, LR Get hold of the current return address. | |
21439 | 18 str R7, [SP, #12] Store it. | |
21440 | 20 add R7, SP, #16 Point at the start of the | |
21441 | backtrace structure. | |
21442 | 22 mov FP, R7 Put this value into the frame pointer. */ | |
21443 | ||
21444 | work_register = thumb_find_work_register (live_regs_mask); | |
21445 | work_reg = gen_rtx_REG (SImode, work_register); | |
21446 | arm_hfp_rtx = gen_rtx_REG (SImode, ARM_HARD_FRAME_POINTER_REGNUM); | |
21447 | ||
21448 | insn = emit_insn (gen_addsi3 (stack_pointer_rtx, | |
21449 | stack_pointer_rtx, GEN_INT (-16))); | |
21450 | RTX_FRAME_RELATED_P (insn) = 1; | |
21451 | ||
21452 | if (l_mask) | |
21453 | { | |
21454 | insn = thumb1_emit_multi_reg_push (l_mask, l_mask); | |
21455 | RTX_FRAME_RELATED_P (insn) = 1; | |
21456 | ||
21457 | offset = bit_count (l_mask) * UNITS_PER_WORD; | |
21458 | } | |
21459 | ||
21460 | x = GEN_INT (offset + 16 + crtl->args.pretend_args_size); | |
21461 | emit_insn (gen_addsi3 (work_reg, stack_pointer_rtx, x)); | |
21462 | ||
21463 | x = plus_constant (stack_pointer_rtx, offset + 4); | |
21464 | x = gen_frame_mem (SImode, x); | |
21465 | emit_move_insn (x, work_reg); | |
21466 | ||
21467 | /* Make sure that the instruction fetching the PC is in the right place | |
21468 | to calculate "start of backtrace creation code + 12". */ | |
21469 | /* ??? The stores using the common WORK_REG ought to be enough to | |
21470 | prevent the scheduler from doing anything weird. Failing that | |
21471 | we could always move all of the following into an UNSPEC_VOLATILE. */ | |
21472 | if (l_mask) | |
21473 | { | |
21474 | x = gen_rtx_REG (SImode, PC_REGNUM); | |
21475 | emit_move_insn (work_reg, x); | |
21476 | ||
21477 | x = plus_constant (stack_pointer_rtx, offset + 12); | |
21478 | x = gen_frame_mem (SImode, x); | |
21479 | emit_move_insn (x, work_reg); | |
21480 | ||
21481 | emit_move_insn (work_reg, arm_hfp_rtx); | |
21482 | ||
21483 | x = plus_constant (stack_pointer_rtx, offset); | |
21484 | x = gen_frame_mem (SImode, x); | |
21485 | emit_move_insn (x, work_reg); | |
21486 | } | |
21487 | else | |
21488 | { | |
21489 | emit_move_insn (work_reg, arm_hfp_rtx); | |
21490 | ||
21491 | x = plus_constant (stack_pointer_rtx, offset); | |
21492 | x = gen_frame_mem (SImode, x); | |
21493 | emit_move_insn (x, work_reg); | |
21494 | ||
21495 | x = gen_rtx_REG (SImode, PC_REGNUM); | |
21496 | emit_move_insn (work_reg, x); | |
21497 | ||
21498 | x = plus_constant (stack_pointer_rtx, offset + 12); | |
21499 | x = gen_frame_mem (SImode, x); | |
21500 | emit_move_insn (x, work_reg); | |
21501 | } | |
21502 | ||
21503 | x = gen_rtx_REG (SImode, LR_REGNUM); | |
21504 | emit_move_insn (work_reg, x); | |
21505 | ||
21506 | x = plus_constant (stack_pointer_rtx, offset + 8); | |
21507 | x = gen_frame_mem (SImode, x); | |
21508 | emit_move_insn (x, work_reg); | |
21509 | ||
21510 | x = GEN_INT (offset + 12); | |
21511 | emit_insn (gen_addsi3 (work_reg, stack_pointer_rtx, x)); | |
21512 | ||
21513 | emit_move_insn (arm_hfp_rtx, work_reg); | |
21514 | } | |
21515 | /* Optimization: If we are not pushing any low registers but we are going | |
21516 | to push some high registers then delay our first push. This will just | |
21517 | be a push of LR and we can combine it with the push of the first high | |
21518 | register. */ | |
21519 | else if ((l_mask & 0xff) != 0 | |
21520 | || (high_regs_pushed == 0 && l_mask)) | |
21521 | { | |
21522 | unsigned long mask = l_mask; | |
21523 | mask |= (1 << thumb1_extra_regs_pushed (offsets, true)) - 1; | |
21524 | insn = thumb1_emit_multi_reg_push (mask, mask); | |
21525 | RTX_FRAME_RELATED_P (insn) = 1; | |
21526 | } | |
21527 | ||
21528 | if (high_regs_pushed) | |
21529 | { | |
21530 | unsigned pushable_regs; | |
21531 | unsigned next_hi_reg; | |
21532 | ||
21533 | for (next_hi_reg = 12; next_hi_reg > LAST_LO_REGNUM; next_hi_reg--) | |
21534 | if (live_regs_mask & (1 << next_hi_reg)) | |
21535 | break; | |
21536 | ||
21537 | pushable_regs = l_mask & 0xff; | |
21538 | ||
21539 | if (pushable_regs == 0) | |
21540 | pushable_regs = 1 << thumb_find_work_register (live_regs_mask); | |
21541 | ||
21542 | while (high_regs_pushed > 0) | |
21543 | { | |
21544 | unsigned long real_regs_mask = 0; | |
21545 | ||
21546 | for (regno = LAST_LO_REGNUM; regno >= 0; regno --) | |
21547 | { | |
21548 | if (pushable_regs & (1 << regno)) | |
21549 | { | |
21550 | emit_move_insn (gen_rtx_REG (SImode, regno), | |
21551 | gen_rtx_REG (SImode, next_hi_reg)); | |
21552 | ||
21553 | high_regs_pushed --; | |
21554 | real_regs_mask |= (1 << next_hi_reg); | |
21555 | ||
21556 | if (high_regs_pushed) | |
21557 | { | |
21558 | for (next_hi_reg --; next_hi_reg > LAST_LO_REGNUM; | |
21559 | next_hi_reg --) | |
21560 | if (live_regs_mask & (1 << next_hi_reg)) | |
21561 | break; | |
21562 | } | |
21563 | else | |
21564 | { | |
21565 | pushable_regs &= ~((1 << regno) - 1); | |
21566 | break; | |
21567 | } | |
21568 | } | |
21569 | } | |
21570 | ||
21571 | /* If we had to find a work register and we have not yet | |
21572 | saved the LR then add it to the list of regs to push. */ | |
21573 | if (l_mask == (1 << LR_REGNUM)) | |
21574 | { | |
21575 | pushable_regs |= l_mask; | |
21576 | real_regs_mask |= l_mask; | |
21577 | l_mask = 0; | |
21578 | } | |
21579 | ||
21580 | insn = thumb1_emit_multi_reg_push (pushable_regs, real_regs_mask); | |
21581 | RTX_FRAME_RELATED_P (insn) = 1; | |
21582 | } | |
21583 | } | |
21584 | ||
b279b20a NC |
21585 | /* Load the pic register before setting the frame pointer, |
21586 | so we can use r7 as a temporary work register. */ | |
020a4035 | 21587 | if (flag_pic && arm_pic_register != INVALID_REGNUM) |
e55ef7f4 | 21588 | arm_load_pic_register (live_regs_mask); |
876f13b0 | 21589 | |
2591db65 | 21590 | if (!frame_pointer_needed && CALLER_INTERWORKING_SLOT_SIZE > 0) |
a2503645 RS |
21591 | emit_move_insn (gen_rtx_REG (Pmode, ARM_HARD_FRAME_POINTER_REGNUM), |
21592 | stack_pointer_rtx); | |
d5b7b3ae | 21593 | |
a11e0df4 | 21594 | if (flag_stack_usage_info) |
55256000 TK |
21595 | current_function_static_stack_size |
21596 | = offsets->outgoing_args - offsets->saved_args; | |
21597 | ||
5848830f | 21598 | amount = offsets->outgoing_args - offsets->saved_regs; |
e784c52c | 21599 | amount -= 4 * thumb1_extra_regs_pushed (offsets, true); |
d5b7b3ae RE |
21600 | if (amount) |
21601 | { | |
d5b7b3ae | 21602 | if (amount < 512) |
980e61bb DJ |
21603 | { |
21604 | insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, | |
21605 | GEN_INT (- amount))); | |
21606 | RTX_FRAME_RELATED_P (insn) = 1; | |
21607 | } | |
d5b7b3ae RE |
21608 | else |
21609 | { | |
d018b46e | 21610 | rtx reg, dwarf; |
d5b7b3ae RE |
21611 | |
21612 | /* The stack decrement is too big for an immediate value in a single | |
21613 | insn. In theory we could issue multiple subtracts, but after | |
21614 | three of them it becomes more space efficient to place the full | |
21615 | value in the constant pool and load into a register. (Also the | |
21616 | ARM debugger really likes to see only one stack decrement per | |
21617 | function). So instead we look for a scratch register into which | |
21618 | we can load the decrement, and then we subtract this from the | |
21619 | stack pointer. Unfortunately on the thumb the only available | |
21620 | scratch registers are the argument registers, and we cannot use | |
21621 | these as they may hold arguments to the function. Instead we | |
21622 | attempt to locate a call preserved register which is used by this | |
21623 | function. If we can find one, then we know that it will have | |
21624 | been pushed at the start of the prologue and so we can corrupt | |
21625 | it now. */ | |
21626 | for (regno = LAST_ARG_REGNUM + 1; regno <= LAST_LO_REGNUM; regno++) | |
35596784 | 21627 | if (live_regs_mask & (1 << regno)) |
d5b7b3ae RE |
21628 | break; |
21629 | ||
35596784 | 21630 | gcc_assert(regno <= LAST_LO_REGNUM); |
d5b7b3ae | 21631 | |
35596784 | 21632 | reg = gen_rtx_REG (SImode, regno); |
d5b7b3ae | 21633 | |
35596784 | 21634 | emit_insn (gen_movsi (reg, GEN_INT (- amount))); |
980e61bb | 21635 | |
35596784 AJ |
21636 | insn = emit_insn (gen_addsi3 (stack_pointer_rtx, |
21637 | stack_pointer_rtx, reg)); | |
d018b46e | 21638 | |
35596784 AJ |
21639 | dwarf = gen_rtx_SET (VOIDmode, stack_pointer_rtx, |
21640 | plus_constant (stack_pointer_rtx, | |
21641 | -amount)); | |
bbbbb16a | 21642 | add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
d018b46e | 21643 | RTX_FRAME_RELATED_P (insn) = 1; |
d5b7b3ae | 21644 | } |
2591db65 RE |
21645 | } |
21646 | ||
21647 | if (frame_pointer_needed) | |
5b3e6663 | 21648 | thumb_set_frame_pointer (offsets); |
f676971a | 21649 | |
74d9c39f DJ |
21650 | /* If we are profiling, make sure no instructions are scheduled before |
21651 | the call to mcount. Similarly if the user has requested no | |
21652 | scheduling in the prolog. Similarly if we want non-call exceptions | |
21653 | using the EABI unwinder, to prevent faulting instructions from being | |
21654 | swapped with a stack adjustment. */ | |
e3b5732b | 21655 | if (crtl->profile || !TARGET_SCHED_PROLOG |
d5fabb58 | 21656 | || (arm_except_unwind_info (&global_options) == UI_TARGET |
f0a0390e | 21657 | && cfun->can_throw_non_call_exceptions)) |
d5b7b3ae | 21658 | emit_insn (gen_blockage ()); |
3c7ad43e PB |
21659 | |
21660 | cfun->machine->lr_save_eliminated = !thumb_force_lr_save (); | |
57934c39 PB |
21661 | if (live_regs_mask & 0xff) |
21662 | cfun->machine->lr_save_eliminated = 0; | |
d5b7b3ae RE |
21663 | } |
21664 | ||
57934c39 | 21665 | |
d5b7b3ae | 21666 | void |
5b3e6663 | 21667 | thumb1_expand_epilogue (void) |
d5b7b3ae | 21668 | { |
5848830f PB |
21669 | HOST_WIDE_INT amount; |
21670 | arm_stack_offsets *offsets; | |
defc0463 RE |
21671 | int regno; |
21672 | ||
6d3d9133 NC |
21673 | /* Naked functions don't have prologues. */ |
21674 | if (IS_NAKED (arm_current_func_type ())) | |
d5b7b3ae RE |
21675 | return; |
21676 | ||
5848830f PB |
21677 | offsets = arm_get_frame_offsets (); |
21678 | amount = offsets->outgoing_args - offsets->saved_regs; | |
21679 | ||
d5b7b3ae | 21680 | if (frame_pointer_needed) |
2591db65 RE |
21681 | { |
21682 | emit_insn (gen_movsi (stack_pointer_rtx, hard_frame_pointer_rtx)); | |
21683 | amount = offsets->locals_base - offsets->saved_regs; | |
21684 | } | |
e784c52c | 21685 | amount -= 4 * thumb1_extra_regs_pushed (offsets, false); |
e0b92319 | 21686 | |
a3a531ec | 21687 | gcc_assert (amount >= 0); |
2591db65 | 21688 | if (amount) |
d5b7b3ae | 21689 | { |
d5b7b3ae RE |
21690 | if (amount < 512) |
21691 | emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, | |
21692 | GEN_INT (amount))); | |
21693 | else | |
21694 | { | |
21695 | /* r3 is always free in the epilogue. */ | |
f1c25d3b | 21696 | rtx reg = gen_rtx_REG (SImode, LAST_ARG_REGNUM); |
d5b7b3ae RE |
21697 | |
21698 | emit_insn (gen_movsi (reg, GEN_INT (amount))); | |
21699 | emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg)); | |
21700 | } | |
21701 | } | |
f676971a | 21702 | |
d5b7b3ae RE |
21703 | /* Emit a USE (stack_pointer_rtx), so that |
21704 | the stack adjustment will not be deleted. */ | |
6bacc7b0 | 21705 | emit_insn (gen_prologue_use (stack_pointer_rtx)); |
d5b7b3ae | 21706 | |
e3b5732b | 21707 | if (crtl->profile || !TARGET_SCHED_PROLOG) |
d5b7b3ae | 21708 | emit_insn (gen_blockage ()); |
defc0463 RE |
21709 | |
21710 | /* Emit a clobber for each insn that will be restored in the epilogue, | |
21711 | so that flow2 will get register lifetimes correct. */ | |
21712 | for (regno = 0; regno < 13; regno++) | |
6fb5fa3c | 21713 | if (df_regs_ever_live_p (regno) && !call_used_regs[regno]) |
c41c1387 | 21714 | emit_clobber (gen_rtx_REG (SImode, regno)); |
defc0463 | 21715 | |
6fb5fa3c | 21716 | if (! df_regs_ever_live_p (LR_REGNUM)) |
c41c1387 | 21717 | emit_use (gen_rtx_REG (SImode, LR_REGNUM)); |
d5b7b3ae RE |
21718 | } |
21719 | ||
d018b46e RH |
21720 | /* Implementation of insn prologue_thumb1_interwork. This is the first |
21721 | "instruction" of a function called in ARM mode. Swap to thumb mode. */ | |
d5b7b3ae | 21722 | |
d018b46e RH |
21723 | const char * |
21724 | thumb1_output_interwork (void) | |
21725 | { | |
21726 | const char * name; | |
21727 | FILE *f = asm_out_file; | |
d5b7b3ae | 21728 | |
d018b46e RH |
21729 | gcc_assert (GET_CODE (DECL_RTL (current_function_decl)) == MEM); |
21730 | gcc_assert (GET_CODE (XEXP (DECL_RTL (current_function_decl), 0)) | |
21731 | == SYMBOL_REF); | |
21732 | name = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); | |
f676971a | 21733 | |
d018b46e RH |
21734 | /* Generate code sequence to switch us into Thumb mode. */ |
21735 | /* The .code 32 directive has already been emitted by | |
21736 | ASM_DECLARE_FUNCTION_NAME. */ | |
21737 | asm_fprintf (f, "\torr\t%r, %r, #1\n", IP_REGNUM, PC_REGNUM); | |
21738 | asm_fprintf (f, "\tbx\t%r\n", IP_REGNUM); | |
d5b7b3ae | 21739 | |
d018b46e RH |
21740 | /* Generate a label, so that the debugger will notice the |
21741 | change in instruction sets. This label is also used by | |
21742 | the assembler to bypass the ARM code when this function | |
21743 | is called from a Thumb encoded function elsewhere in the | |
21744 | same file. Hence the definition of STUB_NAME here must | |
21745 | agree with the definition in gas/config/tc-arm.c. */ | |
f676971a | 21746 | |
d5b7b3ae | 21747 | #define STUB_NAME ".real_start_of" |
f676971a | 21748 | |
d018b46e | 21749 | fprintf (f, "\t.code\t16\n"); |
d5b7b3ae | 21750 | #ifdef ARM_PE |
d018b46e RH |
21751 | if (arm_dllexport_name_p (name)) |
21752 | name = arm_strip_name_encoding (name); | |
f676971a | 21753 | #endif |
d018b46e RH |
21754 | asm_fprintf (f, "\t.globl %s%U%s\n", STUB_NAME, name); |
21755 | fprintf (f, "\t.thumb_func\n"); | |
21756 | asm_fprintf (f, "%s%U%s:\n", STUB_NAME, name); | |
d5b7b3ae | 21757 | |
d018b46e | 21758 | return ""; |
d5b7b3ae RE |
21759 | } |
21760 | ||
21761 | /* Handle the case of a double word load into a low register from | |
21762 | a computed memory address. The computed address may involve a | |
21763 | register which is overwritten by the load. */ | |
cd2b33d0 | 21764 | const char * |
e32bac5b | 21765 | thumb_load_double_from_address (rtx *operands) |
d5b7b3ae RE |
21766 | { |
21767 | rtx addr; | |
21768 | rtx base; | |
21769 | rtx offset; | |
21770 | rtx arg1; | |
21771 | rtx arg2; | |
f676971a | 21772 | |
e6d29d15 NS |
21773 | gcc_assert (GET_CODE (operands[0]) == REG); |
21774 | gcc_assert (GET_CODE (operands[1]) == MEM); | |
d5b7b3ae RE |
21775 | |
21776 | /* Get the memory address. */ | |
21777 | addr = XEXP (operands[1], 0); | |
f676971a | 21778 | |
d5b7b3ae RE |
21779 | /* Work out how the memory address is computed. */ |
21780 | switch (GET_CODE (addr)) | |
21781 | { | |
21782 | case REG: | |
31fa16b6 | 21783 | operands[2] = adjust_address (operands[1], SImode, 4); |
e0b92319 | 21784 | |
d5b7b3ae RE |
21785 | if (REGNO (operands[0]) == REGNO (addr)) |
21786 | { | |
21787 | output_asm_insn ("ldr\t%H0, %2", operands); | |
21788 | output_asm_insn ("ldr\t%0, %1", operands); | |
21789 | } | |
21790 | else | |
21791 | { | |
21792 | output_asm_insn ("ldr\t%0, %1", operands); | |
21793 | output_asm_insn ("ldr\t%H0, %2", operands); | |
21794 | } | |
21795 | break; | |
f676971a | 21796 | |
d5b7b3ae RE |
21797 | case CONST: |
21798 | /* Compute <address> + 4 for the high order load. */ | |
31fa16b6 | 21799 | operands[2] = adjust_address (operands[1], SImode, 4); |
e0b92319 | 21800 | |
d5b7b3ae RE |
21801 | output_asm_insn ("ldr\t%0, %1", operands); |
21802 | output_asm_insn ("ldr\t%H0, %2", operands); | |
21803 | break; | |
f676971a | 21804 | |
d5b7b3ae RE |
21805 | case PLUS: |
21806 | arg1 = XEXP (addr, 0); | |
21807 | arg2 = XEXP (addr, 1); | |
f676971a | 21808 | |
d5b7b3ae RE |
21809 | if (CONSTANT_P (arg1)) |
21810 | base = arg2, offset = arg1; | |
21811 | else | |
21812 | base = arg1, offset = arg2; | |
f676971a | 21813 | |
e6d29d15 | 21814 | gcc_assert (GET_CODE (base) == REG); |
d5b7b3ae RE |
21815 | |
21816 | /* Catch the case of <address> = <reg> + <reg> */ | |
21817 | if (GET_CODE (offset) == REG) | |
21818 | { | |
21819 | int reg_offset = REGNO (offset); | |
21820 | int reg_base = REGNO (base); | |
21821 | int reg_dest = REGNO (operands[0]); | |
f676971a | 21822 | |
d5b7b3ae RE |
21823 | /* Add the base and offset registers together into the |
21824 | higher destination register. */ | |
21825 | asm_fprintf (asm_out_file, "\tadd\t%r, %r, %r", | |
21826 | reg_dest + 1, reg_base, reg_offset); | |
f676971a | 21827 | |
d5b7b3ae RE |
21828 | /* Load the lower destination register from the address in |
21829 | the higher destination register. */ | |
21830 | asm_fprintf (asm_out_file, "\tldr\t%r, [%r, #0]", | |
21831 | reg_dest, reg_dest + 1); | |
f676971a | 21832 | |
d5b7b3ae RE |
21833 | /* Load the higher destination register from its own address |
21834 | plus 4. */ | |
21835 | asm_fprintf (asm_out_file, "\tldr\t%r, [%r, #4]", | |
21836 | reg_dest + 1, reg_dest + 1); | |
21837 | } | |
21838 | else | |
21839 | { | |
21840 | /* Compute <address> + 4 for the high order load. */ | |
31fa16b6 | 21841 | operands[2] = adjust_address (operands[1], SImode, 4); |
f676971a | 21842 | |
d5b7b3ae RE |
21843 | /* If the computed address is held in the low order register |
21844 | then load the high order register first, otherwise always | |
21845 | load the low order register first. */ | |
21846 | if (REGNO (operands[0]) == REGNO (base)) | |
21847 | { | |
21848 | output_asm_insn ("ldr\t%H0, %2", operands); | |
21849 | output_asm_insn ("ldr\t%0, %1", operands); | |
21850 | } | |
21851 | else | |
21852 | { | |
21853 | output_asm_insn ("ldr\t%0, %1", operands); | |
21854 | output_asm_insn ("ldr\t%H0, %2", operands); | |
21855 | } | |
21856 | } | |
21857 | break; | |
21858 | ||
21859 | case LABEL_REF: | |
21860 | /* With no registers to worry about we can just load the value | |
21861 | directly. */ | |
31fa16b6 | 21862 | operands[2] = adjust_address (operands[1], SImode, 4); |
f676971a | 21863 | |
d5b7b3ae RE |
21864 | output_asm_insn ("ldr\t%H0, %2", operands); |
21865 | output_asm_insn ("ldr\t%0, %1", operands); | |
21866 | break; | |
f676971a | 21867 | |
d5b7b3ae | 21868 | default: |
e6d29d15 | 21869 | gcc_unreachable (); |
d5b7b3ae | 21870 | } |
f676971a | 21871 | |
d5b7b3ae RE |
21872 | return ""; |
21873 | } | |
21874 | ||
cd2b33d0 | 21875 | const char * |
e32bac5b | 21876 | thumb_output_move_mem_multiple (int n, rtx *operands) |
d5b7b3ae RE |
21877 | { |
21878 | rtx tmp; | |
21879 | ||
21880 | switch (n) | |
21881 | { | |
21882 | case 2: | |
ca356f3a | 21883 | if (REGNO (operands[4]) > REGNO (operands[5])) |
d5b7b3ae | 21884 | { |
ca356f3a RE |
21885 | tmp = operands[4]; |
21886 | operands[4] = operands[5]; | |
21887 | operands[5] = tmp; | |
d5b7b3ae | 21888 | } |
ca356f3a RE |
21889 | output_asm_insn ("ldmia\t%1!, {%4, %5}", operands); |
21890 | output_asm_insn ("stmia\t%0!, {%4, %5}", operands); | |
d5b7b3ae RE |
21891 | break; |
21892 | ||
21893 | case 3: | |
ca356f3a | 21894 | if (REGNO (operands[4]) > REGNO (operands[5])) |
d5b7b3ae | 21895 | { |
ca356f3a RE |
21896 | tmp = operands[4]; |
21897 | operands[4] = operands[5]; | |
21898 | operands[5] = tmp; | |
d5b7b3ae | 21899 | } |
ca356f3a | 21900 | if (REGNO (operands[5]) > REGNO (operands[6])) |
d5b7b3ae | 21901 | { |
ca356f3a RE |
21902 | tmp = operands[5]; |
21903 | operands[5] = operands[6]; | |
21904 | operands[6] = tmp; | |
d5b7b3ae | 21905 | } |
ca356f3a | 21906 | if (REGNO (operands[4]) > REGNO (operands[5])) |
d5b7b3ae | 21907 | { |
ca356f3a RE |
21908 | tmp = operands[4]; |
21909 | operands[4] = operands[5]; | |
21910 | operands[5] = tmp; | |
d5b7b3ae | 21911 | } |
f676971a | 21912 | |
ca356f3a RE |
21913 | output_asm_insn ("ldmia\t%1!, {%4, %5, %6}", operands); |
21914 | output_asm_insn ("stmia\t%0!, {%4, %5, %6}", operands); | |
d5b7b3ae RE |
21915 | break; |
21916 | ||
21917 | default: | |
e6d29d15 | 21918 | gcc_unreachable (); |
d5b7b3ae RE |
21919 | } |
21920 | ||
21921 | return ""; | |
21922 | } | |
21923 | ||
b12a00f1 RE |
21924 | /* Output a call-via instruction for thumb state. */ |
21925 | const char * | |
21926 | thumb_call_via_reg (rtx reg) | |
21927 | { | |
21928 | int regno = REGNO (reg); | |
21929 | rtx *labelp; | |
21930 | ||
57ecec57 | 21931 | gcc_assert (regno < LR_REGNUM); |
b12a00f1 RE |
21932 | |
21933 | /* If we are in the normal text section we can use a single instance | |
21934 | per compilation unit. If we are doing function sections, then we need | |
21935 | an entry per section, since we can't rely on reachability. */ | |
d6b5193b | 21936 | if (in_section == text_section) |
b12a00f1 RE |
21937 | { |
21938 | thumb_call_reg_needed = 1; | |
21939 | ||
21940 | if (thumb_call_via_label[regno] == NULL) | |
21941 | thumb_call_via_label[regno] = gen_label_rtx (); | |
21942 | labelp = thumb_call_via_label + regno; | |
21943 | } | |
21944 | else | |
21945 | { | |
21946 | if (cfun->machine->call_via[regno] == NULL) | |
21947 | cfun->machine->call_via[regno] = gen_label_rtx (); | |
21948 | labelp = cfun->machine->call_via + regno; | |
21949 | } | |
21950 | ||
21951 | output_asm_insn ("bl\t%a0", labelp); | |
21952 | return ""; | |
21953 | } | |
21954 | ||
1d6e90ac | 21955 | /* Routines for generating rtl. */ |
d5b7b3ae | 21956 | void |
70128ad9 | 21957 | thumb_expand_movmemqi (rtx *operands) |
d5b7b3ae RE |
21958 | { |
21959 | rtx out = copy_to_mode_reg (SImode, XEXP (operands[0], 0)); | |
21960 | rtx in = copy_to_mode_reg (SImode, XEXP (operands[1], 0)); | |
21961 | HOST_WIDE_INT len = INTVAL (operands[2]); | |
21962 | HOST_WIDE_INT offset = 0; | |
21963 | ||
21964 | while (len >= 12) | |
21965 | { | |
ca356f3a | 21966 | emit_insn (gen_movmem12b (out, in, out, in)); |
d5b7b3ae RE |
21967 | len -= 12; |
21968 | } | |
f676971a | 21969 | |
d5b7b3ae RE |
21970 | if (len >= 8) |
21971 | { | |
ca356f3a | 21972 | emit_insn (gen_movmem8b (out, in, out, in)); |
d5b7b3ae RE |
21973 | len -= 8; |
21974 | } | |
f676971a | 21975 | |
d5b7b3ae RE |
21976 | if (len >= 4) |
21977 | { | |
21978 | rtx reg = gen_reg_rtx (SImode); | |
f1c25d3b KH |
21979 | emit_insn (gen_movsi (reg, gen_rtx_MEM (SImode, in))); |
21980 | emit_insn (gen_movsi (gen_rtx_MEM (SImode, out), reg)); | |
d5b7b3ae RE |
21981 | len -= 4; |
21982 | offset += 4; | |
21983 | } | |
f676971a | 21984 | |
d5b7b3ae RE |
21985 | if (len >= 2) |
21986 | { | |
21987 | rtx reg = gen_reg_rtx (HImode); | |
f676971a | 21988 | emit_insn (gen_movhi (reg, gen_rtx_MEM (HImode, |
f1c25d3b KH |
21989 | plus_constant (in, offset)))); |
21990 | emit_insn (gen_movhi (gen_rtx_MEM (HImode, plus_constant (out, offset)), | |
d5b7b3ae RE |
21991 | reg)); |
21992 | len -= 2; | |
21993 | offset += 2; | |
21994 | } | |
f676971a | 21995 | |
d5b7b3ae RE |
21996 | if (len) |
21997 | { | |
21998 | rtx reg = gen_reg_rtx (QImode); | |
f1c25d3b KH |
21999 | emit_insn (gen_movqi (reg, gen_rtx_MEM (QImode, |
22000 | plus_constant (in, offset)))); | |
22001 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (out, offset)), | |
d5b7b3ae RE |
22002 | reg)); |
22003 | } | |
22004 | } | |
22005 | ||
d5b7b3ae | 22006 | void |
e32bac5b | 22007 | thumb_reload_out_hi (rtx *operands) |
d5b7b3ae RE |
22008 | { |
22009 | emit_insn (gen_thumb_movhi_clobber (operands[0], operands[1], operands[2])); | |
22010 | } | |
22011 | ||
f676971a | 22012 | /* Handle reading a half-word from memory during reload. */ |
d5b7b3ae | 22013 | void |
e32bac5b | 22014 | thumb_reload_in_hi (rtx *operands ATTRIBUTE_UNUSED) |
d5b7b3ae | 22015 | { |
e6d29d15 | 22016 | gcc_unreachable (); |
d5b7b3ae RE |
22017 | } |
22018 | ||
c27ba912 DM |
22019 | /* Return the length of a function name prefix |
22020 | that starts with the character 'c'. */ | |
22021 | static int | |
e32bac5b | 22022 | arm_get_strip_length (int c) |
c27ba912 DM |
22023 | { |
22024 | switch (c) | |
22025 | { | |
22026 | ARM_NAME_ENCODING_LENGTHS | |
f676971a | 22027 | default: return 0; |
c27ba912 DM |
22028 | } |
22029 | } | |
22030 | ||
22031 | /* Return a pointer to a function's name with any | |
22032 | and all prefix encodings stripped from it. */ | |
22033 | const char * | |
e32bac5b | 22034 | arm_strip_name_encoding (const char *name) |
c27ba912 DM |
22035 | { |
22036 | int skip; | |
f676971a | 22037 | |
c27ba912 DM |
22038 | while ((skip = arm_get_strip_length (* name))) |
22039 | name += skip; | |
22040 | ||
22041 | return name; | |
22042 | } | |
22043 | ||
e1944073 KW |
22044 | /* If there is a '*' anywhere in the name's prefix, then |
22045 | emit the stripped name verbatim, otherwise prepend an | |
22046 | underscore if leading underscores are being used. */ | |
e1944073 | 22047 | void |
e32bac5b | 22048 | arm_asm_output_labelref (FILE *stream, const char *name) |
e1944073 KW |
22049 | { |
22050 | int skip; | |
22051 | int verbatim = 0; | |
22052 | ||
22053 | while ((skip = arm_get_strip_length (* name))) | |
22054 | { | |
22055 | verbatim |= (*name == '*'); | |
22056 | name += skip; | |
22057 | } | |
22058 | ||
22059 | if (verbatim) | |
22060 | fputs (name, stream); | |
22061 | else | |
22062 | asm_fprintf (stream, "%U%s", name); | |
22063 | } | |
22064 | ||
6c6aa1af PB |
22065 | static void |
22066 | arm_file_start (void) | |
22067 | { | |
22068 | int val; | |
22069 | ||
5b3e6663 PB |
22070 | if (TARGET_UNIFIED_ASM) |
22071 | asm_fprintf (asm_out_file, "\t.syntax unified\n"); | |
22072 | ||
6c6aa1af PB |
22073 | if (TARGET_BPABI) |
22074 | { | |
22075 | const char *fpu_name; | |
12a0a4d4 PB |
22076 | if (arm_selected_arch) |
22077 | asm_fprintf (asm_out_file, "\t.arch %s\n", arm_selected_arch->name); | |
6c6aa1af | 22078 | else |
12a0a4d4 | 22079 | asm_fprintf (asm_out_file, "\t.cpu %s\n", arm_selected_cpu->name); |
6c6aa1af PB |
22080 | |
22081 | if (TARGET_SOFT_FLOAT) | |
22082 | { | |
22083 | if (TARGET_VFP) | |
22084 | fpu_name = "softvfp"; | |
22085 | else | |
22086 | fpu_name = "softfpa"; | |
22087 | } | |
22088 | else | |
22089 | { | |
d79f3032 PB |
22090 | fpu_name = arm_fpu_desc->name; |
22091 | if (arm_fpu_desc->model == ARM_FP_MODEL_VFP) | |
f1adb0a9 JB |
22092 | { |
22093 | if (TARGET_HARD_FLOAT) | |
22094 | asm_fprintf (asm_out_file, "\t.eabi_attribute 27, 3\n"); | |
22095 | if (TARGET_HARD_FLOAT_ABI) | |
22096 | asm_fprintf (asm_out_file, "\t.eabi_attribute 28, 1\n"); | |
22097 | } | |
6c6aa1af PB |
22098 | } |
22099 | asm_fprintf (asm_out_file, "\t.fpu %s\n", fpu_name); | |
22100 | ||
22101 | /* Some of these attributes only apply when the corresponding features | |
22102 | are used. However we don't have any easy way of figuring this out. | |
22103 | Conservatively record the setting that would have been used. */ | |
22104 | ||
6c6aa1af PB |
22105 | /* Tag_ABI_FP_rounding. */ |
22106 | if (flag_rounding_math) | |
22107 | asm_fprintf (asm_out_file, "\t.eabi_attribute 19, 1\n"); | |
22108 | if (!flag_unsafe_math_optimizations) | |
22109 | { | |
22110 | /* Tag_ABI_FP_denomal. */ | |
22111 | asm_fprintf (asm_out_file, "\t.eabi_attribute 20, 1\n"); | |
22112 | /* Tag_ABI_FP_exceptions. */ | |
22113 | asm_fprintf (asm_out_file, "\t.eabi_attribute 21, 1\n"); | |
22114 | } | |
22115 | /* Tag_ABI_FP_user_exceptions. */ | |
22116 | if (flag_signaling_nans) | |
22117 | asm_fprintf (asm_out_file, "\t.eabi_attribute 22, 1\n"); | |
22118 | /* Tag_ABI_FP_number_model. */ | |
22119 | asm_fprintf (asm_out_file, "\t.eabi_attribute 23, %d\n", | |
22120 | flag_finite_math_only ? 1 : 3); | |
22121 | ||
22122 | /* Tag_ABI_align8_needed. */ | |
22123 | asm_fprintf (asm_out_file, "\t.eabi_attribute 24, 1\n"); | |
22124 | /* Tag_ABI_align8_preserved. */ | |
22125 | asm_fprintf (asm_out_file, "\t.eabi_attribute 25, 1\n"); | |
22126 | /* Tag_ABI_enum_size. */ | |
22127 | asm_fprintf (asm_out_file, "\t.eabi_attribute 26, %d\n", | |
22128 | flag_short_enums ? 1 : 2); | |
22129 | ||
22130 | /* Tag_ABI_optimization_goals. */ | |
22131 | if (optimize_size) | |
22132 | val = 4; | |
22133 | else if (optimize >= 2) | |
22134 | val = 2; | |
22135 | else if (optimize) | |
22136 | val = 1; | |
22137 | else | |
22138 | val = 6; | |
22139 | asm_fprintf (asm_out_file, "\t.eabi_attribute 30, %d\n", val); | |
b76c3c4b | 22140 | |
0fd8c3ad SL |
22141 | /* Tag_ABI_FP_16bit_format. */ |
22142 | if (arm_fp16_format) | |
22143 | asm_fprintf (asm_out_file, "\t.eabi_attribute 38, %d\n", | |
22144 | (int)arm_fp16_format); | |
22145 | ||
b76c3c4b PB |
22146 | if (arm_lang_output_object_attributes_hook) |
22147 | arm_lang_output_object_attributes_hook(); | |
6c6aa1af PB |
22148 | } |
22149 | default_file_start(); | |
22150 | } | |
22151 | ||
b12a00f1 RE |
22152 | static void |
22153 | arm_file_end (void) | |
22154 | { | |
22155 | int regno; | |
22156 | ||
978e411f CD |
22157 | if (NEED_INDICATE_EXEC_STACK) |
22158 | /* Add .note.GNU-stack. */ | |
22159 | file_end_indicate_exec_stack (); | |
22160 | ||
b12a00f1 RE |
22161 | if (! thumb_call_reg_needed) |
22162 | return; | |
22163 | ||
d6b5193b | 22164 | switch_to_section (text_section); |
b12a00f1 RE |
22165 | asm_fprintf (asm_out_file, "\t.code 16\n"); |
22166 | ASM_OUTPUT_ALIGN (asm_out_file, 1); | |
22167 | ||
57ecec57 | 22168 | for (regno = 0; regno < LR_REGNUM; regno++) |
b12a00f1 RE |
22169 | { |
22170 | rtx label = thumb_call_via_label[regno]; | |
22171 | ||
22172 | if (label != 0) | |
22173 | { | |
22174 | targetm.asm_out.internal_label (asm_out_file, "L", | |
22175 | CODE_LABEL_NUMBER (label)); | |
22176 | asm_fprintf (asm_out_file, "\tbx\t%r\n", regno); | |
22177 | } | |
22178 | } | |
22179 | } | |
22180 | ||
fb49053f RH |
22181 | #ifndef ARM_PE |
22182 | /* Symbols in the text segment can be accessed without indirecting via the | |
22183 | constant pool; it may take an extra binary operation, but this is still | |
22184 | faster than indirecting via memory. Don't do this when not optimizing, | |
22185 | since we won't be calculating al of the offsets necessary to do this | |
22186 | simplification. */ | |
22187 | ||
22188 | static void | |
e32bac5b | 22189 | arm_encode_section_info (tree decl, rtx rtl, int first) |
fb49053f | 22190 | { |
3521b33c | 22191 | if (optimize > 0 && TREE_CONSTANT (decl)) |
c6a2438a | 22192 | SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1; |
fb49053f | 22193 | |
d3585b76 | 22194 | default_encode_section_info (decl, rtl, first); |
fb49053f RH |
22195 | } |
22196 | #endif /* !ARM_PE */ | |
483ab821 | 22197 | |
4977bab6 | 22198 | static void |
e32bac5b | 22199 | arm_internal_label (FILE *stream, const char *prefix, unsigned long labelno) |
4977bab6 ZW |
22200 | { |
22201 | if (arm_ccfsm_state == 3 && (unsigned) arm_target_label == labelno | |
22202 | && !strcmp (prefix, "L")) | |
22203 | { | |
22204 | arm_ccfsm_state = 0; | |
22205 | arm_target_insn = NULL; | |
22206 | } | |
22207 | default_internal_label (stream, prefix, labelno); | |
22208 | } | |
22209 | ||
c590b625 RH |
22210 | /* Output code to add DELTA to the first argument, and then jump |
22211 | to FUNCTION. Used for C++ multiple inheritance. */ | |
c590b625 | 22212 | static void |
e32bac5b RE |
22213 | arm_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED, |
22214 | HOST_WIDE_INT delta, | |
22215 | HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED, | |
22216 | tree function) | |
483ab821 | 22217 | { |
9b66ebb1 PB |
22218 | static int thunk_label = 0; |
22219 | char label[256]; | |
54b9e939 | 22220 | char labelpc[256]; |
483ab821 MM |
22221 | int mi_delta = delta; |
22222 | const char *const mi_op = mi_delta < 0 ? "sub" : "add"; | |
22223 | int shift = 0; | |
61f71b34 | 22224 | int this_regno = (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function) |
483ab821 MM |
22225 | ? 1 : 0); |
22226 | if (mi_delta < 0) | |
22227 | mi_delta = - mi_delta; | |
bf98ec6c | 22228 | |
5b3e6663 | 22229 | if (TARGET_THUMB1) |
9b66ebb1 PB |
22230 | { |
22231 | int labelno = thunk_label++; | |
22232 | ASM_GENERATE_INTERNAL_LABEL (label, "LTHUMBFUNC", labelno); | |
bf98ec6c PB |
22233 | /* Thunks are entered in arm mode when avaiable. */ |
22234 | if (TARGET_THUMB1_ONLY) | |
22235 | { | |
22236 | /* push r3 so we can use it as a temporary. */ | |
22237 | /* TODO: Omit this save if r3 is not used. */ | |
22238 | fputs ("\tpush {r3}\n", file); | |
22239 | fputs ("\tldr\tr3, ", file); | |
22240 | } | |
22241 | else | |
22242 | { | |
22243 | fputs ("\tldr\tr12, ", file); | |
22244 | } | |
9b66ebb1 PB |
22245 | assemble_name (file, label); |
22246 | fputc ('\n', file); | |
54b9e939 KH |
22247 | if (flag_pic) |
22248 | { | |
22249 | /* If we are generating PIC, the ldr instruction below loads | |
22250 | "(target - 7) - .LTHUNKPCn" into r12. The pc reads as | |
22251 | the address of the add + 8, so we have: | |
22252 | ||
22253 | r12 = (target - 7) - .LTHUNKPCn + (.LTHUNKPCn + 8) | |
22254 | = target + 1. | |
22255 | ||
22256 | Note that we have "+ 1" because some versions of GNU ld | |
22257 | don't set the low bit of the result for R_ARM_REL32 | |
bf98ec6c PB |
22258 | relocations against thumb function symbols. |
22259 | On ARMv6M this is +4, not +8. */ | |
54b9e939 KH |
22260 | ASM_GENERATE_INTERNAL_LABEL (labelpc, "LTHUNKPC", labelno); |
22261 | assemble_name (file, labelpc); | |
22262 | fputs (":\n", file); | |
bf98ec6c PB |
22263 | if (TARGET_THUMB1_ONLY) |
22264 | { | |
22265 | /* This is 2 insns after the start of the thunk, so we know it | |
22266 | is 4-byte aligned. */ | |
22267 | fputs ("\tadd\tr3, pc, r3\n", file); | |
22268 | fputs ("\tmov r12, r3\n", file); | |
22269 | } | |
22270 | else | |
22271 | fputs ("\tadd\tr12, pc, r12\n", file); | |
54b9e939 | 22272 | } |
bf98ec6c PB |
22273 | else if (TARGET_THUMB1_ONLY) |
22274 | fputs ("\tmov r12, r3\n", file); | |
9b66ebb1 | 22275 | } |
bf98ec6c | 22276 | if (TARGET_THUMB1_ONLY) |
483ab821 | 22277 | { |
bf98ec6c PB |
22278 | if (mi_delta > 255) |
22279 | { | |
22280 | fputs ("\tldr\tr3, ", file); | |
22281 | assemble_name (file, label); | |
22282 | fputs ("+4\n", file); | |
22283 | asm_fprintf (file, "\t%s\t%r, %r, r3\n", | |
22284 | mi_op, this_regno, this_regno); | |
22285 | } | |
22286 | else if (mi_delta != 0) | |
22287 | { | |
22288 | asm_fprintf (file, "\t%s\t%r, %r, #%d\n", | |
22289 | mi_op, this_regno, this_regno, | |
22290 | mi_delta); | |
22291 | } | |
22292 | } | |
22293 | else | |
22294 | { | |
22295 | /* TODO: Use movw/movt for large constants when available. */ | |
22296 | while (mi_delta != 0) | |
22297 | { | |
22298 | if ((mi_delta & (3 << shift)) == 0) | |
22299 | shift += 2; | |
22300 | else | |
22301 | { | |
22302 | asm_fprintf (file, "\t%s\t%r, %r, #%d\n", | |
22303 | mi_op, this_regno, this_regno, | |
22304 | mi_delta & (0xff << shift)); | |
22305 | mi_delta &= ~(0xff << shift); | |
22306 | shift += 8; | |
22307 | } | |
22308 | } | |
483ab821 | 22309 | } |
5b3e6663 | 22310 | if (TARGET_THUMB1) |
9b66ebb1 | 22311 | { |
bf98ec6c PB |
22312 | if (TARGET_THUMB1_ONLY) |
22313 | fputs ("\tpop\t{r3}\n", file); | |
22314 | ||
9b66ebb1 PB |
22315 | fprintf (file, "\tbx\tr12\n"); |
22316 | ASM_OUTPUT_ALIGN (file, 2); | |
22317 | assemble_name (file, label); | |
22318 | fputs (":\n", file); | |
54b9e939 KH |
22319 | if (flag_pic) |
22320 | { | |
22321 | /* Output ".word .LTHUNKn-7-.LTHUNKPCn". */ | |
22322 | rtx tem = XEXP (DECL_RTL (function), 0); | |
22323 | tem = gen_rtx_PLUS (GET_MODE (tem), tem, GEN_INT (-7)); | |
22324 | tem = gen_rtx_MINUS (GET_MODE (tem), | |
22325 | tem, | |
22326 | gen_rtx_SYMBOL_REF (Pmode, | |
22327 | ggc_strdup (labelpc))); | |
22328 | assemble_integer (tem, 4, BITS_PER_WORD, 1); | |
22329 | } | |
22330 | else | |
22331 | /* Output ".word .LTHUNKn". */ | |
22332 | assemble_integer (XEXP (DECL_RTL (function), 0), 4, BITS_PER_WORD, 1); | |
bf98ec6c PB |
22333 | |
22334 | if (TARGET_THUMB1_ONLY && mi_delta > 255) | |
22335 | assemble_integer (GEN_INT(mi_delta), 4, BITS_PER_WORD, 1); | |
9b66ebb1 PB |
22336 | } |
22337 | else | |
22338 | { | |
22339 | fputs ("\tb\t", file); | |
22340 | assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0)); | |
22341 | if (NEED_PLT_RELOC) | |
22342 | fputs ("(PLT)", file); | |
22343 | fputc ('\n', file); | |
22344 | } | |
483ab821 | 22345 | } |
5a9335ef NC |
22346 | |
22347 | int | |
6f5f2481 | 22348 | arm_emit_vector_const (FILE *file, rtx x) |
5a9335ef NC |
22349 | { |
22350 | int i; | |
22351 | const char * pattern; | |
22352 | ||
e6d29d15 | 22353 | gcc_assert (GET_CODE (x) == CONST_VECTOR); |
5a9335ef NC |
22354 | |
22355 | switch (GET_MODE (x)) | |
22356 | { | |
22357 | case V2SImode: pattern = "%08x"; break; | |
22358 | case V4HImode: pattern = "%04x"; break; | |
22359 | case V8QImode: pattern = "%02x"; break; | |
e6d29d15 | 22360 | default: gcc_unreachable (); |
5a9335ef NC |
22361 | } |
22362 | ||
22363 | fprintf (file, "0x"); | |
22364 | for (i = CONST_VECTOR_NUNITS (x); i--;) | |
22365 | { | |
22366 | rtx element; | |
22367 | ||
22368 | element = CONST_VECTOR_ELT (x, i); | |
22369 | fprintf (file, pattern, INTVAL (element)); | |
22370 | } | |
22371 | ||
22372 | return 1; | |
22373 | } | |
22374 | ||
0fd8c3ad SL |
22375 | /* Emit a fp16 constant appropriately padded to occupy a 4-byte word. |
22376 | HFmode constant pool entries are actually loaded with ldr. */ | |
22377 | void | |
22378 | arm_emit_fp16_const (rtx c) | |
22379 | { | |
22380 | REAL_VALUE_TYPE r; | |
22381 | long bits; | |
22382 | ||
22383 | REAL_VALUE_FROM_CONST_DOUBLE (r, c); | |
22384 | bits = real_to_target (NULL, &r, HFmode); | |
22385 | if (WORDS_BIG_ENDIAN) | |
22386 | assemble_zeros (2); | |
22387 | assemble_integer (GEN_INT (bits), 2, BITS_PER_WORD, 1); | |
22388 | if (!WORDS_BIG_ENDIAN) | |
22389 | assemble_zeros (2); | |
22390 | } | |
22391 | ||
5a9335ef | 22392 | const char * |
6f5f2481 | 22393 | arm_output_load_gr (rtx *operands) |
5a9335ef NC |
22394 | { |
22395 | rtx reg; | |
22396 | rtx offset; | |
22397 | rtx wcgr; | |
22398 | rtx sum; | |
f676971a | 22399 | |
5a9335ef NC |
22400 | if (GET_CODE (operands [1]) != MEM |
22401 | || GET_CODE (sum = XEXP (operands [1], 0)) != PLUS | |
22402 | || GET_CODE (reg = XEXP (sum, 0)) != REG | |
22403 | || GET_CODE (offset = XEXP (sum, 1)) != CONST_INT | |
22404 | || ((INTVAL (offset) < 1024) && (INTVAL (offset) > -1024))) | |
22405 | return "wldrw%?\t%0, %1"; | |
f676971a EC |
22406 | |
22407 | /* Fix up an out-of-range load of a GR register. */ | |
5a9335ef NC |
22408 | output_asm_insn ("str%?\t%0, [sp, #-4]!\t@ Start of GR load expansion", & reg); |
22409 | wcgr = operands[0]; | |
22410 | operands[0] = reg; | |
22411 | output_asm_insn ("ldr%?\t%0, %1", operands); | |
22412 | ||
22413 | operands[0] = wcgr; | |
22414 | operands[1] = reg; | |
22415 | output_asm_insn ("tmcr%?\t%0, %1", operands); | |
22416 | output_asm_insn ("ldr%?\t%0, [sp], #4\t@ End of GR load expansion", & reg); | |
22417 | ||
22418 | return ""; | |
22419 | } | |
f9ba5949 | 22420 | |
1cc9f5f5 KH |
22421 | /* Worker function for TARGET_SETUP_INCOMING_VARARGS. |
22422 | ||
22423 | On the ARM, PRETEND_SIZE is set in order to have the prologue push the last | |
22424 | named arg and all anonymous args onto the stack. | |
22425 | XXX I know the prologue shouldn't be pushing registers, but it is faster | |
22426 | that way. */ | |
22427 | ||
22428 | static void | |
d5cc9181 | 22429 | arm_setup_incoming_varargs (cumulative_args_t pcum_v, |
22ccaaee JJ |
22430 | enum machine_mode mode, |
22431 | tree type, | |
1cc9f5f5 KH |
22432 | int *pretend_size, |
22433 | int second_time ATTRIBUTE_UNUSED) | |
22434 | { | |
d5cc9181 | 22435 | CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v); |
390b17c2 RE |
22436 | int nregs; |
22437 | ||
1cc9f5f5 | 22438 | cfun->machine->uses_anonymous_args = 1; |
390b17c2 RE |
22439 | if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) |
22440 | { | |
22441 | nregs = pcum->aapcs_ncrn; | |
22442 | if ((nregs & 1) && arm_needs_doubleword_align (mode, type)) | |
22443 | nregs++; | |
22444 | } | |
22445 | else | |
22446 | nregs = pcum->nregs; | |
22447 | ||
22ccaaee JJ |
22448 | if (nregs < NUM_ARG_REGS) |
22449 | *pretend_size = (NUM_ARG_REGS - nregs) * UNITS_PER_WORD; | |
1cc9f5f5 | 22450 | } |
9b66ebb1 | 22451 | |
59b9a953 | 22452 | /* Return nonzero if the CONSUMER instruction (a store) does not need |
9b66ebb1 PB |
22453 | PRODUCER's value to calculate the address. */ |
22454 | ||
22455 | int | |
22456 | arm_no_early_store_addr_dep (rtx producer, rtx consumer) | |
22457 | { | |
22458 | rtx value = PATTERN (producer); | |
22459 | rtx addr = PATTERN (consumer); | |
22460 | ||
22461 | if (GET_CODE (value) == COND_EXEC) | |
22462 | value = COND_EXEC_CODE (value); | |
22463 | if (GET_CODE (value) == PARALLEL) | |
22464 | value = XVECEXP (value, 0, 0); | |
22465 | value = XEXP (value, 0); | |
22466 | if (GET_CODE (addr) == COND_EXEC) | |
22467 | addr = COND_EXEC_CODE (addr); | |
22468 | if (GET_CODE (addr) == PARALLEL) | |
22469 | addr = XVECEXP (addr, 0, 0); | |
22470 | addr = XEXP (addr, 0); | |
f676971a | 22471 | |
9b66ebb1 PB |
22472 | return !reg_overlap_mentioned_p (value, addr); |
22473 | } | |
22474 | ||
47d8f18d JZ |
22475 | /* Return nonzero if the CONSUMER instruction (a store) does need |
22476 | PRODUCER's value to calculate the address. */ | |
22477 | ||
22478 | int | |
22479 | arm_early_store_addr_dep (rtx producer, rtx consumer) | |
22480 | { | |
22481 | return !arm_no_early_store_addr_dep (producer, consumer); | |
22482 | } | |
22483 | ||
22484 | /* Return nonzero if the CONSUMER instruction (a load) does need | |
22485 | PRODUCER's value to calculate the address. */ | |
22486 | ||
22487 | int | |
22488 | arm_early_load_addr_dep (rtx producer, rtx consumer) | |
22489 | { | |
22490 | rtx value = PATTERN (producer); | |
22491 | rtx addr = PATTERN (consumer); | |
22492 | ||
22493 | if (GET_CODE (value) == COND_EXEC) | |
22494 | value = COND_EXEC_CODE (value); | |
22495 | if (GET_CODE (value) == PARALLEL) | |
22496 | value = XVECEXP (value, 0, 0); | |
22497 | value = XEXP (value, 0); | |
22498 | if (GET_CODE (addr) == COND_EXEC) | |
22499 | addr = COND_EXEC_CODE (addr); | |
22500 | if (GET_CODE (addr) == PARALLEL) | |
22501 | addr = XVECEXP (addr, 0, 0); | |
22502 | addr = XEXP (addr, 1); | |
22503 | ||
22504 | return reg_overlap_mentioned_p (value, addr); | |
22505 | } | |
22506 | ||
59b9a953 | 22507 | /* Return nonzero if the CONSUMER instruction (an ALU op) does not |
9b66ebb1 PB |
22508 | have an early register shift value or amount dependency on the |
22509 | result of PRODUCER. */ | |
22510 | ||
22511 | int | |
22512 | arm_no_early_alu_shift_dep (rtx producer, rtx consumer) | |
22513 | { | |
22514 | rtx value = PATTERN (producer); | |
22515 | rtx op = PATTERN (consumer); | |
22516 | rtx early_op; | |
22517 | ||
22518 | if (GET_CODE (value) == COND_EXEC) | |
22519 | value = COND_EXEC_CODE (value); | |
22520 | if (GET_CODE (value) == PARALLEL) | |
22521 | value = XVECEXP (value, 0, 0); | |
22522 | value = XEXP (value, 0); | |
22523 | if (GET_CODE (op) == COND_EXEC) | |
22524 | op = COND_EXEC_CODE (op); | |
22525 | if (GET_CODE (op) == PARALLEL) | |
22526 | op = XVECEXP (op, 0, 0); | |
22527 | op = XEXP (op, 1); | |
f676971a | 22528 | |
9b66ebb1 PB |
22529 | early_op = XEXP (op, 0); |
22530 | /* This is either an actual independent shift, or a shift applied to | |
22531 | the first operand of another operation. We want the whole shift | |
22532 | operation. */ | |
22533 | if (GET_CODE (early_op) == REG) | |
22534 | early_op = op; | |
22535 | ||
22536 | return !reg_overlap_mentioned_p (value, early_op); | |
22537 | } | |
22538 | ||
59b9a953 | 22539 | /* Return nonzero if the CONSUMER instruction (an ALU op) does not |
9b66ebb1 PB |
22540 | have an early register shift value dependency on the result of |
22541 | PRODUCER. */ | |
22542 | ||
22543 | int | |
22544 | arm_no_early_alu_shift_value_dep (rtx producer, rtx consumer) | |
22545 | { | |
22546 | rtx value = PATTERN (producer); | |
22547 | rtx op = PATTERN (consumer); | |
22548 | rtx early_op; | |
22549 | ||
22550 | if (GET_CODE (value) == COND_EXEC) | |
22551 | value = COND_EXEC_CODE (value); | |
22552 | if (GET_CODE (value) == PARALLEL) | |
22553 | value = XVECEXP (value, 0, 0); | |
22554 | value = XEXP (value, 0); | |
22555 | if (GET_CODE (op) == COND_EXEC) | |
22556 | op = COND_EXEC_CODE (op); | |
22557 | if (GET_CODE (op) == PARALLEL) | |
22558 | op = XVECEXP (op, 0, 0); | |
22559 | op = XEXP (op, 1); | |
f676971a | 22560 | |
9b66ebb1 PB |
22561 | early_op = XEXP (op, 0); |
22562 | ||
22563 | /* This is either an actual independent shift, or a shift applied to | |
22564 | the first operand of another operation. We want the value being | |
22565 | shifted, in either case. */ | |
22566 | if (GET_CODE (early_op) != REG) | |
22567 | early_op = XEXP (early_op, 0); | |
f676971a | 22568 | |
9b66ebb1 PB |
22569 | return !reg_overlap_mentioned_p (value, early_op); |
22570 | } | |
22571 | ||
59b9a953 | 22572 | /* Return nonzero if the CONSUMER (a mul or mac op) does not |
9b66ebb1 PB |
22573 | have an early register mult dependency on the result of |
22574 | PRODUCER. */ | |
22575 | ||
22576 | int | |
22577 | arm_no_early_mul_dep (rtx producer, rtx consumer) | |
22578 | { | |
22579 | rtx value = PATTERN (producer); | |
22580 | rtx op = PATTERN (consumer); | |
22581 | ||
22582 | if (GET_CODE (value) == COND_EXEC) | |
22583 | value = COND_EXEC_CODE (value); | |
22584 | if (GET_CODE (value) == PARALLEL) | |
22585 | value = XVECEXP (value, 0, 0); | |
22586 | value = XEXP (value, 0); | |
22587 | if (GET_CODE (op) == COND_EXEC) | |
22588 | op = COND_EXEC_CODE (op); | |
22589 | if (GET_CODE (op) == PARALLEL) | |
22590 | op = XVECEXP (op, 0, 0); | |
22591 | op = XEXP (op, 1); | |
f676971a | 22592 | |
756f763b PB |
22593 | if (GET_CODE (op) == PLUS || GET_CODE (op) == MINUS) |
22594 | { | |
22595 | if (GET_CODE (XEXP (op, 0)) == MULT) | |
22596 | return !reg_overlap_mentioned_p (value, XEXP (op, 0)); | |
22597 | else | |
22598 | return !reg_overlap_mentioned_p (value, XEXP (op, 1)); | |
22599 | } | |
22600 | ||
22601 | return 0; | |
9b66ebb1 PB |
22602 | } |
22603 | ||
70301b45 PB |
22604 | /* We can't rely on the caller doing the proper promotion when |
22605 | using APCS or ATPCS. */ | |
22606 | ||
22607 | static bool | |
586de218 | 22608 | arm_promote_prototypes (const_tree t ATTRIBUTE_UNUSED) |
70301b45 | 22609 | { |
b6685939 | 22610 | return !TARGET_AAPCS_BASED; |
70301b45 PB |
22611 | } |
22612 | ||
cde0f3fd PB |
22613 | static enum machine_mode |
22614 | arm_promote_function_mode (const_tree type ATTRIBUTE_UNUSED, | |
22615 | enum machine_mode mode, | |
22616 | int *punsignedp ATTRIBUTE_UNUSED, | |
22617 | const_tree fntype ATTRIBUTE_UNUSED, | |
22618 | int for_return ATTRIBUTE_UNUSED) | |
22619 | { | |
22620 | if (GET_MODE_CLASS (mode) == MODE_INT | |
22621 | && GET_MODE_SIZE (mode) < 4) | |
22622 | return SImode; | |
22623 | ||
22624 | return mode; | |
22625 | } | |
6b045785 PB |
22626 | |
22627 | /* AAPCS based ABIs use short enums by default. */ | |
22628 | ||
22629 | static bool | |
22630 | arm_default_short_enums (void) | |
22631 | { | |
077fc835 | 22632 | return TARGET_AAPCS_BASED && arm_abi != ARM_ABI_AAPCS_LINUX; |
6b045785 | 22633 | } |
13c1cd82 PB |
22634 | |
22635 | ||
22636 | /* AAPCS requires that anonymous bitfields affect structure alignment. */ | |
22637 | ||
22638 | static bool | |
22639 | arm_align_anon_bitfield (void) | |
22640 | { | |
22641 | return TARGET_AAPCS_BASED; | |
22642 | } | |
4185ae53 PB |
22643 | |
22644 | ||
22645 | /* The generic C++ ABI says 64-bit (long long). The EABI says 32-bit. */ | |
22646 | ||
22647 | static tree | |
22648 | arm_cxx_guard_type (void) | |
22649 | { | |
22650 | return TARGET_AAPCS_BASED ? integer_type_node : long_long_integer_type_node; | |
22651 | } | |
22652 | ||
c956e102 MS |
22653 | /* Return non-zero if the consumer (a multiply-accumulate instruction) |
22654 | has an accumulator dependency on the result of the producer (a | |
22655 | multiplication instruction) and no other dependency on that result. */ | |
22656 | int | |
22657 | arm_mac_accumulator_is_mul_result (rtx producer, rtx consumer) | |
22658 | { | |
22659 | rtx mul = PATTERN (producer); | |
22660 | rtx mac = PATTERN (consumer); | |
22661 | rtx mul_result; | |
22662 | rtx mac_op0, mac_op1, mac_acc; | |
22663 | ||
22664 | if (GET_CODE (mul) == COND_EXEC) | |
22665 | mul = COND_EXEC_CODE (mul); | |
22666 | if (GET_CODE (mac) == COND_EXEC) | |
22667 | mac = COND_EXEC_CODE (mac); | |
22668 | ||
22669 | /* Check that mul is of the form (set (...) (mult ...)) | |
22670 | and mla is of the form (set (...) (plus (mult ...) (...))). */ | |
22671 | if ((GET_CODE (mul) != SET || GET_CODE (XEXP (mul, 1)) != MULT) | |
22672 | || (GET_CODE (mac) != SET || GET_CODE (XEXP (mac, 1)) != PLUS | |
22673 | || GET_CODE (XEXP (XEXP (mac, 1), 0)) != MULT)) | |
22674 | return 0; | |
22675 | ||
22676 | mul_result = XEXP (mul, 0); | |
22677 | mac_op0 = XEXP (XEXP (XEXP (mac, 1), 0), 0); | |
22678 | mac_op1 = XEXP (XEXP (XEXP (mac, 1), 0), 1); | |
22679 | mac_acc = XEXP (XEXP (mac, 1), 1); | |
22680 | ||
22681 | return (reg_overlap_mentioned_p (mul_result, mac_acc) | |
22682 | && !reg_overlap_mentioned_p (mul_result, mac_op0) | |
22683 | && !reg_overlap_mentioned_p (mul_result, mac_op1)); | |
22684 | } | |
22685 | ||
4185ae53 | 22686 | |
0fa2e4df | 22687 | /* The EABI says test the least significant bit of a guard variable. */ |
4185ae53 PB |
22688 | |
22689 | static bool | |
22690 | arm_cxx_guard_mask_bit (void) | |
22691 | { | |
22692 | return TARGET_AAPCS_BASED; | |
22693 | } | |
46e995e0 PB |
22694 | |
22695 | ||
22696 | /* The EABI specifies that all array cookies are 8 bytes long. */ | |
22697 | ||
22698 | static tree | |
22699 | arm_get_cookie_size (tree type) | |
22700 | { | |
22701 | tree size; | |
22702 | ||
22703 | if (!TARGET_AAPCS_BASED) | |
22704 | return default_cxx_get_cookie_size (type); | |
22705 | ||
7d60be94 | 22706 | size = build_int_cst (sizetype, 8); |
46e995e0 PB |
22707 | return size; |
22708 | } | |
22709 | ||
22710 | ||
22711 | /* The EABI says that array cookies should also contain the element size. */ | |
22712 | ||
22713 | static bool | |
22714 | arm_cookie_has_size (void) | |
22715 | { | |
22716 | return TARGET_AAPCS_BASED; | |
22717 | } | |
44d10c10 PB |
22718 | |
22719 | ||
22720 | /* The EABI says constructors and destructors should return a pointer to | |
22721 | the object constructed/destroyed. */ | |
22722 | ||
22723 | static bool | |
22724 | arm_cxx_cdtor_returns_this (void) | |
22725 | { | |
22726 | return TARGET_AAPCS_BASED; | |
22727 | } | |
c9ca9b88 | 22728 | |
505970fc MM |
22729 | /* The EABI says that an inline function may never be the key |
22730 | method. */ | |
22731 | ||
22732 | static bool | |
22733 | arm_cxx_key_method_may_be_inline (void) | |
22734 | { | |
22735 | return !TARGET_AAPCS_BASED; | |
22736 | } | |
22737 | ||
1e731102 MM |
22738 | static void |
22739 | arm_cxx_determine_class_data_visibility (tree decl) | |
22740 | { | |
711b2998 JB |
22741 | if (!TARGET_AAPCS_BASED |
22742 | || !TARGET_DLLIMPORT_DECL_ATTRIBUTES) | |
1e731102 | 22743 | return; |
505970fc | 22744 | |
1e731102 MM |
22745 | /* In general, \S 3.2.5.5 of the ARM EABI requires that class data |
22746 | is exported. However, on systems without dynamic vague linkage, | |
22747 | \S 3.2.5.6 says that COMDAT class data has hidden linkage. */ | |
22748 | if (!TARGET_ARM_DYNAMIC_VAGUE_LINKAGE_P && DECL_COMDAT (decl)) | |
22749 | DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; | |
22750 | else | |
22751 | DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; | |
22752 | DECL_VISIBILITY_SPECIFIED (decl) = 1; | |
22753 | } | |
e0b92319 | 22754 | |
505970fc | 22755 | static bool |
1e731102 | 22756 | arm_cxx_class_data_always_comdat (void) |
505970fc | 22757 | { |
1e731102 MM |
22758 | /* \S 3.2.5.4 of the ARM C++ ABI says that class data only have |
22759 | vague linkage if the class has no key function. */ | |
22760 | return !TARGET_AAPCS_BASED; | |
505970fc | 22761 | } |
c9ca9b88 | 22762 | |
9f62c3e3 PB |
22763 | |
22764 | /* The EABI says __aeabi_atexit should be used to register static | |
22765 | destructors. */ | |
22766 | ||
22767 | static bool | |
22768 | arm_cxx_use_aeabi_atexit (void) | |
22769 | { | |
22770 | return TARGET_AAPCS_BASED; | |
22771 | } | |
22772 | ||
22773 | ||
c9ca9b88 PB |
22774 | void |
22775 | arm_set_return_address (rtx source, rtx scratch) | |
22776 | { | |
22777 | arm_stack_offsets *offsets; | |
22778 | HOST_WIDE_INT delta; | |
22779 | rtx addr; | |
22780 | unsigned long saved_regs; | |
22781 | ||
954954d1 PB |
22782 | offsets = arm_get_frame_offsets (); |
22783 | saved_regs = offsets->saved_regs_mask; | |
c9ca9b88 PB |
22784 | |
22785 | if ((saved_regs & (1 << LR_REGNUM)) == 0) | |
22786 | emit_move_insn (gen_rtx_REG (Pmode, LR_REGNUM), source); | |
22787 | else | |
22788 | { | |
22789 | if (frame_pointer_needed) | |
22790 | addr = plus_constant(hard_frame_pointer_rtx, -4); | |
22791 | else | |
22792 | { | |
22793 | /* LR will be the first saved register. */ | |
c9ca9b88 PB |
22794 | delta = offsets->outgoing_args - (offsets->frame + 4); |
22795 | ||
f676971a | 22796 | |
c9ca9b88 PB |
22797 | if (delta >= 4096) |
22798 | { | |
22799 | emit_insn (gen_addsi3 (scratch, stack_pointer_rtx, | |
22800 | GEN_INT (delta & ~4095))); | |
22801 | addr = scratch; | |
22802 | delta &= 4095; | |
22803 | } | |
22804 | else | |
22805 | addr = stack_pointer_rtx; | |
22806 | ||
22807 | addr = plus_constant (addr, delta); | |
22808 | } | |
31fa16b6 | 22809 | emit_move_insn (gen_frame_mem (Pmode, addr), source); |
c9ca9b88 PB |
22810 | } |
22811 | } | |
22812 | ||
22813 | ||
22814 | void | |
22815 | thumb_set_return_address (rtx source, rtx scratch) | |
22816 | { | |
22817 | arm_stack_offsets *offsets; | |
c9ca9b88 | 22818 | HOST_WIDE_INT delta; |
5b3e6663 | 22819 | HOST_WIDE_INT limit; |
c9ca9b88 PB |
22820 | int reg; |
22821 | rtx addr; | |
57934c39 | 22822 | unsigned long mask; |
c9ca9b88 | 22823 | |
c41c1387 | 22824 | emit_use (source); |
c9ca9b88 | 22825 | |
954954d1 PB |
22826 | offsets = arm_get_frame_offsets (); |
22827 | mask = offsets->saved_regs_mask; | |
57934c39 | 22828 | if (mask & (1 << LR_REGNUM)) |
c9ca9b88 | 22829 | { |
5b3e6663 | 22830 | limit = 1024; |
c9ca9b88 PB |
22831 | /* Find the saved regs. */ |
22832 | if (frame_pointer_needed) | |
22833 | { | |
22834 | delta = offsets->soft_frame - offsets->saved_args; | |
22835 | reg = THUMB_HARD_FRAME_POINTER_REGNUM; | |
5b3e6663 PB |
22836 | if (TARGET_THUMB1) |
22837 | limit = 128; | |
c9ca9b88 PB |
22838 | } |
22839 | else | |
22840 | { | |
22841 | delta = offsets->outgoing_args - offsets->saved_args; | |
22842 | reg = SP_REGNUM; | |
22843 | } | |
22844 | /* Allow for the stack frame. */ | |
5b3e6663 | 22845 | if (TARGET_THUMB1 && TARGET_BACKTRACE) |
c9ca9b88 PB |
22846 | delta -= 16; |
22847 | /* The link register is always the first saved register. */ | |
22848 | delta -= 4; | |
f676971a | 22849 | |
c9ca9b88 PB |
22850 | /* Construct the address. */ |
22851 | addr = gen_rtx_REG (SImode, reg); | |
5b3e6663 | 22852 | if (delta > limit) |
c9ca9b88 PB |
22853 | { |
22854 | emit_insn (gen_movsi (scratch, GEN_INT (delta))); | |
22855 | emit_insn (gen_addsi3 (scratch, scratch, stack_pointer_rtx)); | |
22856 | addr = scratch; | |
22857 | } | |
22858 | else | |
22859 | addr = plus_constant (addr, delta); | |
22860 | ||
31fa16b6 | 22861 | emit_move_insn (gen_frame_mem (Pmode, addr), source); |
c9ca9b88 PB |
22862 | } |
22863 | else | |
22864 | emit_move_insn (gen_rtx_REG (Pmode, LR_REGNUM), source); | |
22865 | } | |
22866 | ||
f676971a EC |
22867 | /* Implements target hook vector_mode_supported_p. */ |
22868 | bool | |
22869 | arm_vector_mode_supported_p (enum machine_mode mode) | |
22870 | { | |
88f77cba JB |
22871 | /* Neon also supports V2SImode, etc. listed in the clause below. */ |
22872 | if (TARGET_NEON && (mode == V2SFmode || mode == V4SImode || mode == V8HImode | |
22873 | || mode == V16QImode || mode == V4SFmode || mode == V2DImode)) | |
22874 | return true; | |
22875 | ||
390b17c2 RE |
22876 | if ((TARGET_NEON || TARGET_IWMMXT) |
22877 | && ((mode == V2SImode) | |
22878 | || (mode == V4HImode) | |
22879 | || (mode == V8QImode))) | |
f676971a EC |
22880 | return true; |
22881 | ||
655b30bf JB |
22882 | if (TARGET_INT_SIMD && (mode == V4UQQmode || mode == V4QQmode |
22883 | || mode == V2UHQmode || mode == V2HQmode || mode == V2UHAmode | |
22884 | || mode == V2HAmode)) | |
22885 | return true; | |
22886 | ||
f676971a EC |
22887 | return false; |
22888 | } | |
273a2526 | 22889 | |
0f6d54f7 RS |
22890 | /* Implements target hook array_mode_supported_p. */ |
22891 | ||
22892 | static bool | |
22893 | arm_array_mode_supported_p (enum machine_mode mode, | |
22894 | unsigned HOST_WIDE_INT nelems) | |
22895 | { | |
22896 | if (TARGET_NEON | |
22897 | && (VALID_NEON_DREG_MODE (mode) || VALID_NEON_QREG_MODE (mode)) | |
22898 | && (nelems >= 2 && nelems <= 4)) | |
22899 | return true; | |
22900 | ||
22901 | return false; | |
22902 | } | |
22903 | ||
26983c22 L |
22904 | /* Use the option -mvectorize-with-neon-quad to override the use of doubleword |
22905 | registers when autovectorizing for Neon, at least until multiple vector | |
22906 | widths are supported properly by the middle-end. */ | |
22907 | ||
cc4b5170 RG |
22908 | static enum machine_mode |
22909 | arm_preferred_simd_mode (enum machine_mode mode) | |
26983c22 | 22910 | { |
cc4b5170 RG |
22911 | if (TARGET_NEON) |
22912 | switch (mode) | |
22913 | { | |
22914 | case SFmode: | |
22915 | return TARGET_NEON_VECTORIZE_QUAD ? V4SFmode : V2SFmode; | |
22916 | case SImode: | |
22917 | return TARGET_NEON_VECTORIZE_QUAD ? V4SImode : V2SImode; | |
22918 | case HImode: | |
22919 | return TARGET_NEON_VECTORIZE_QUAD ? V8HImode : V4HImode; | |
22920 | case QImode: | |
22921 | return TARGET_NEON_VECTORIZE_QUAD ? V16QImode : V8QImode; | |
22922 | case DImode: | |
22923 | if (TARGET_NEON_VECTORIZE_QUAD) | |
22924 | return V2DImode; | |
22925 | break; | |
22926 | ||
22927 | default:; | |
22928 | } | |
22929 | ||
22930 | if (TARGET_REALLY_IWMMXT) | |
22931 | switch (mode) | |
22932 | { | |
22933 | case SImode: | |
22934 | return V2SImode; | |
22935 | case HImode: | |
22936 | return V4HImode; | |
22937 | case QImode: | |
22938 | return V8QImode; | |
22939 | ||
22940 | default:; | |
22941 | } | |
22942 | ||
22943 | return word_mode; | |
26983c22 L |
22944 | } |
22945 | ||
d163e655 AS |
22946 | /* Implement TARGET_CLASS_LIKELY_SPILLED_P. |
22947 | ||
9adc580c AS |
22948 | We need to define this for LO_REGS on Thumb-1. Otherwise we can end up |
22949 | using r0-r4 for function arguments, r7 for the stack frame and don't have | |
22950 | enough left over to do doubleword arithmetic. For Thumb-2 all the | |
22951 | potentially problematic instructions accept high registers so this is not | |
22952 | necessary. Care needs to be taken to avoid adding new Thumb-2 patterns | |
22953 | that require many low registers. */ | |
d163e655 AS |
22954 | static bool |
22955 | arm_class_likely_spilled_p (reg_class_t rclass) | |
22956 | { | |
9adc580c | 22957 | if ((TARGET_THUMB1 && rclass == LO_REGS) |
d163e655 AS |
22958 | || rclass == CC_REG) |
22959 | return true; | |
22960 | ||
22961 | return false; | |
22962 | } | |
22963 | ||
42db504c SB |
22964 | /* Implements target hook small_register_classes_for_mode_p. */ |
22965 | bool | |
22966 | arm_small_register_classes_for_mode_p (enum machine_mode mode ATTRIBUTE_UNUSED) | |
22967 | { | |
22968 | return TARGET_THUMB1; | |
22969 | } | |
22970 | ||
273a2526 RS |
22971 | /* Implement TARGET_SHIFT_TRUNCATION_MASK. SImode shifts use normal |
22972 | ARM insns and therefore guarantee that the shift count is modulo 256. | |
22973 | DImode shifts (those implemented by lib1funcs.asm or by optabs.c) | |
22974 | guarantee no particular behavior for out-of-range counts. */ | |
22975 | ||
22976 | static unsigned HOST_WIDE_INT | |
22977 | arm_shift_truncation_mask (enum machine_mode mode) | |
22978 | { | |
22979 | return mode == SImode ? 255 : 0; | |
22980 | } | |
2fa330b2 PB |
22981 | |
22982 | ||
22983 | /* Map internal gcc register numbers to DWARF2 register numbers. */ | |
22984 | ||
22985 | unsigned int | |
22986 | arm_dbx_register_number (unsigned int regno) | |
22987 | { | |
22988 | if (regno < 16) | |
22989 | return regno; | |
22990 | ||
22991 | /* TODO: Legacy targets output FPA regs as registers 16-23 for backwards | |
22992 | compatibility. The EABI defines them as registers 96-103. */ | |
22993 | if (IS_FPA_REGNUM (regno)) | |
22994 | return (TARGET_AAPCS_BASED ? 96 : 16) + regno - FIRST_FPA_REGNUM; | |
22995 | ||
22996 | if (IS_VFP_REGNUM (regno)) | |
854b8a40 JB |
22997 | { |
22998 | /* See comment in arm_dwarf_register_span. */ | |
22999 | if (VFP_REGNO_OK_FOR_SINGLE (regno)) | |
23000 | return 64 + regno - FIRST_VFP_REGNUM; | |
23001 | else | |
23002 | return 256 + (regno - FIRST_VFP_REGNUM) / 2; | |
23003 | } | |
2fa330b2 PB |
23004 | |
23005 | if (IS_IWMMXT_GR_REGNUM (regno)) | |
23006 | return 104 + regno - FIRST_IWMMXT_GR_REGNUM; | |
23007 | ||
23008 | if (IS_IWMMXT_REGNUM (regno)) | |
23009 | return 112 + regno - FIRST_IWMMXT_REGNUM; | |
23010 | ||
e6d29d15 | 23011 | gcc_unreachable (); |
2fa330b2 PB |
23012 | } |
23013 | ||
854b8a40 JB |
23014 | /* Dwarf models VFPv3 registers as 32 64-bit registers. |
23015 | GCC models tham as 64 32-bit registers, so we need to describe this to | |
23016 | the DWARF generation code. Other registers can use the default. */ | |
23017 | static rtx | |
23018 | arm_dwarf_register_span (rtx rtl) | |
23019 | { | |
23020 | unsigned regno; | |
23021 | int nregs; | |
23022 | int i; | |
23023 | rtx p; | |
23024 | ||
23025 | regno = REGNO (rtl); | |
23026 | if (!IS_VFP_REGNUM (regno)) | |
23027 | return NULL_RTX; | |
23028 | ||
23029 | /* XXX FIXME: The EABI defines two VFP register ranges: | |
23030 | 64-95: Legacy VFPv2 numbering for S0-S31 (obsolescent) | |
23031 | 256-287: D0-D31 | |
23032 | The recommended encoding for S0-S31 is a DW_OP_bit_piece of the | |
23033 | corresponding D register. Until GDB supports this, we shall use the | |
23034 | legacy encodings. We also use these encodings for D0-D15 for | |
23035 | compatibility with older debuggers. */ | |
23036 | if (VFP_REGNO_OK_FOR_SINGLE (regno)) | |
23037 | return NULL_RTX; | |
23038 | ||
23039 | nregs = GET_MODE_SIZE (GET_MODE (rtl)) / 8; | |
23040 | p = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs)); | |
23041 | regno = (regno - FIRST_VFP_REGNUM) / 2; | |
23042 | for (i = 0; i < nregs; i++) | |
23043 | XVECEXP (p, 0, i) = gen_rtx_REG (DImode, 256 + regno + i); | |
23044 | ||
23045 | return p; | |
23046 | } | |
617a1b71 | 23047 | |
f0a0390e | 23048 | #if ARM_UNWIND_INFO |
5b3e6663 PB |
23049 | /* Emit unwind directives for a store-multiple instruction or stack pointer |
23050 | push during alignment. | |
23051 | These should only ever be generated by the function prologue code, so | |
23052 | expect them to have a particular form. */ | |
617a1b71 PB |
23053 | |
23054 | static void | |
5b3e6663 | 23055 | arm_unwind_emit_sequence (FILE * asm_out_file, rtx p) |
617a1b71 PB |
23056 | { |
23057 | int i; | |
23058 | HOST_WIDE_INT offset; | |
23059 | HOST_WIDE_INT nregs; | |
23060 | int reg_size; | |
23061 | unsigned reg; | |
23062 | unsigned lastreg; | |
23063 | rtx e; | |
23064 | ||
617a1b71 | 23065 | e = XVECEXP (p, 0, 0); |
5b3e6663 PB |
23066 | if (GET_CODE (e) != SET) |
23067 | abort (); | |
23068 | ||
23069 | /* First insn will adjust the stack pointer. */ | |
617a1b71 PB |
23070 | if (GET_CODE (e) != SET |
23071 | || GET_CODE (XEXP (e, 0)) != REG | |
23072 | || REGNO (XEXP (e, 0)) != SP_REGNUM | |
23073 | || GET_CODE (XEXP (e, 1)) != PLUS) | |
23074 | abort (); | |
23075 | ||
23076 | offset = -INTVAL (XEXP (XEXP (e, 1), 1)); | |
23077 | nregs = XVECLEN (p, 0) - 1; | |
23078 | ||
23079 | reg = REGNO (XEXP (XVECEXP (p, 0, 1), 1)); | |
23080 | if (reg < 16) | |
23081 | { | |
23082 | /* The function prologue may also push pc, but not annotate it as it is | |
569b7f6a | 23083 | never restored. We turn this into a stack pointer adjustment. */ |
617a1b71 PB |
23084 | if (nregs * 4 == offset - 4) |
23085 | { | |
23086 | fprintf (asm_out_file, "\t.pad #4\n"); | |
23087 | offset -= 4; | |
23088 | } | |
23089 | reg_size = 4; | |
8edfc4cc | 23090 | fprintf (asm_out_file, "\t.save {"); |
617a1b71 PB |
23091 | } |
23092 | else if (IS_VFP_REGNUM (reg)) | |
23093 | { | |
617a1b71 | 23094 | reg_size = 8; |
8edfc4cc | 23095 | fprintf (asm_out_file, "\t.vsave {"); |
617a1b71 PB |
23096 | } |
23097 | else if (reg >= FIRST_FPA_REGNUM && reg <= LAST_FPA_REGNUM) | |
23098 | { | |
23099 | /* FPA registers are done differently. */ | |
ea40ba9c | 23100 | asm_fprintf (asm_out_file, "\t.save %r, %wd\n", reg, nregs); |
617a1b71 PB |
23101 | return; |
23102 | } | |
23103 | else | |
23104 | /* Unknown register type. */ | |
23105 | abort (); | |
23106 | ||
23107 | /* If the stack increment doesn't match the size of the saved registers, | |
23108 | something has gone horribly wrong. */ | |
23109 | if (offset != nregs * reg_size) | |
23110 | abort (); | |
23111 | ||
617a1b71 PB |
23112 | offset = 0; |
23113 | lastreg = 0; | |
23114 | /* The remaining insns will describe the stores. */ | |
23115 | for (i = 1; i <= nregs; i++) | |
23116 | { | |
23117 | /* Expect (set (mem <addr>) (reg)). | |
23118 | Where <addr> is (reg:SP) or (plus (reg:SP) (const_int)). */ | |
23119 | e = XVECEXP (p, 0, i); | |
23120 | if (GET_CODE (e) != SET | |
23121 | || GET_CODE (XEXP (e, 0)) != MEM | |
23122 | || GET_CODE (XEXP (e, 1)) != REG) | |
23123 | abort (); | |
e0b92319 | 23124 | |
617a1b71 PB |
23125 | reg = REGNO (XEXP (e, 1)); |
23126 | if (reg < lastreg) | |
23127 | abort (); | |
e0b92319 | 23128 | |
617a1b71 PB |
23129 | if (i != 1) |
23130 | fprintf (asm_out_file, ", "); | |
23131 | /* We can't use %r for vfp because we need to use the | |
23132 | double precision register names. */ | |
23133 | if (IS_VFP_REGNUM (reg)) | |
23134 | asm_fprintf (asm_out_file, "d%d", (reg - FIRST_VFP_REGNUM) / 2); | |
23135 | else | |
23136 | asm_fprintf (asm_out_file, "%r", reg); | |
23137 | ||
23138 | #ifdef ENABLE_CHECKING | |
23139 | /* Check that the addresses are consecutive. */ | |
23140 | e = XEXP (XEXP (e, 0), 0); | |
23141 | if (GET_CODE (e) == PLUS) | |
23142 | { | |
23143 | offset += reg_size; | |
23144 | if (GET_CODE (XEXP (e, 0)) != REG | |
23145 | || REGNO (XEXP (e, 0)) != SP_REGNUM | |
23146 | || GET_CODE (XEXP (e, 1)) != CONST_INT | |
23147 | || offset != INTVAL (XEXP (e, 1))) | |
23148 | abort (); | |
23149 | } | |
23150 | else if (i != 1 | |
23151 | || GET_CODE (e) != REG | |
23152 | || REGNO (e) != SP_REGNUM) | |
23153 | abort (); | |
23154 | #endif | |
23155 | } | |
23156 | fprintf (asm_out_file, "}\n"); | |
23157 | } | |
23158 | ||
23159 | /* Emit unwind directives for a SET. */ | |
23160 | ||
23161 | static void | |
23162 | arm_unwind_emit_set (FILE * asm_out_file, rtx p) | |
23163 | { | |
23164 | rtx e0; | |
23165 | rtx e1; | |
5b3e6663 | 23166 | unsigned reg; |
617a1b71 PB |
23167 | |
23168 | e0 = XEXP (p, 0); | |
23169 | e1 = XEXP (p, 1); | |
23170 | switch (GET_CODE (e0)) | |
23171 | { | |
23172 | case MEM: | |
23173 | /* Pushing a single register. */ | |
23174 | if (GET_CODE (XEXP (e0, 0)) != PRE_DEC | |
23175 | || GET_CODE (XEXP (XEXP (e0, 0), 0)) != REG | |
23176 | || REGNO (XEXP (XEXP (e0, 0), 0)) != SP_REGNUM) | |
23177 | abort (); | |
23178 | ||
23179 | asm_fprintf (asm_out_file, "\t.save "); | |
23180 | if (IS_VFP_REGNUM (REGNO (e1))) | |
23181 | asm_fprintf(asm_out_file, "{d%d}\n", | |
23182 | (REGNO (e1) - FIRST_VFP_REGNUM) / 2); | |
23183 | else | |
23184 | asm_fprintf(asm_out_file, "{%r}\n", REGNO (e1)); | |
23185 | break; | |
23186 | ||
23187 | case REG: | |
23188 | if (REGNO (e0) == SP_REGNUM) | |
23189 | { | |
23190 | /* A stack increment. */ | |
23191 | if (GET_CODE (e1) != PLUS | |
23192 | || GET_CODE (XEXP (e1, 0)) != REG | |
23193 | || REGNO (XEXP (e1, 0)) != SP_REGNUM | |
23194 | || GET_CODE (XEXP (e1, 1)) != CONST_INT) | |
23195 | abort (); | |
23196 | ||
ea40ba9c | 23197 | asm_fprintf (asm_out_file, "\t.pad #%wd\n", |
617a1b71 PB |
23198 | -INTVAL (XEXP (e1, 1))); |
23199 | } | |
23200 | else if (REGNO (e0) == HARD_FRAME_POINTER_REGNUM) | |
23201 | { | |
23202 | HOST_WIDE_INT offset; | |
e0b92319 | 23203 | |
617a1b71 PB |
23204 | if (GET_CODE (e1) == PLUS) |
23205 | { | |
23206 | if (GET_CODE (XEXP (e1, 0)) != REG | |
23207 | || GET_CODE (XEXP (e1, 1)) != CONST_INT) | |
23208 | abort (); | |
23209 | reg = REGNO (XEXP (e1, 0)); | |
23210 | offset = INTVAL (XEXP (e1, 1)); | |
ea40ba9c | 23211 | asm_fprintf (asm_out_file, "\t.setfp %r, %r, #%wd\n", |
617a1b71 | 23212 | HARD_FRAME_POINTER_REGNUM, reg, |
80d56d04 | 23213 | offset); |
617a1b71 PB |
23214 | } |
23215 | else if (GET_CODE (e1) == REG) | |
23216 | { | |
23217 | reg = REGNO (e1); | |
23218 | asm_fprintf (asm_out_file, "\t.setfp %r, %r\n", | |
23219 | HARD_FRAME_POINTER_REGNUM, reg); | |
23220 | } | |
23221 | else | |
23222 | abort (); | |
23223 | } | |
23224 | else if (GET_CODE (e1) == REG && REGNO (e1) == SP_REGNUM) | |
23225 | { | |
23226 | /* Move from sp to reg. */ | |
23227 | asm_fprintf (asm_out_file, "\t.movsp %r\n", REGNO (e0)); | |
23228 | } | |
758ed9b2 PB |
23229 | else if (GET_CODE (e1) == PLUS |
23230 | && GET_CODE (XEXP (e1, 0)) == REG | |
23231 | && REGNO (XEXP (e1, 0)) == SP_REGNUM | |
23232 | && GET_CODE (XEXP (e1, 1)) == CONST_INT) | |
23233 | { | |
23234 | /* Set reg to offset from sp. */ | |
23235 | asm_fprintf (asm_out_file, "\t.movsp %r, #%d\n", | |
23236 | REGNO (e0), (int)INTVAL(XEXP (e1, 1))); | |
23237 | } | |
617a1b71 PB |
23238 | else |
23239 | abort (); | |
23240 | break; | |
23241 | ||
23242 | default: | |
23243 | abort (); | |
23244 | } | |
23245 | } | |
23246 | ||
23247 | ||
23248 | /* Emit unwind directives for the given insn. */ | |
23249 | ||
23250 | static void | |
23251 | arm_unwind_emit (FILE * asm_out_file, rtx insn) | |
23252 | { | |
ddc6e7d6 RH |
23253 | rtx note, pat; |
23254 | bool handled_one = false; | |
617a1b71 | 23255 | |
d5fabb58 | 23256 | if (arm_except_unwind_info (&global_options) != UI_TARGET) |
617a1b71 PB |
23257 | return; |
23258 | ||
e3b5732b | 23259 | if (!(flag_unwind_tables || crtl->uses_eh_lsda) |
80efdb6a | 23260 | && (TREE_NOTHROW (current_function_decl) |
ad516a74 | 23261 | || crtl->all_throwers_are_sibcalls)) |
80efdb6a PB |
23262 | return; |
23263 | ||
ddc6e7d6 | 23264 | if (NOTE_P (insn) || !RTX_FRAME_RELATED_P (insn)) |
617a1b71 PB |
23265 | return; |
23266 | ||
ddc6e7d6 RH |
23267 | for (note = REG_NOTES (insn); note ; note = XEXP (note, 1)) |
23268 | { | |
23269 | pat = XEXP (note, 0); | |
23270 | switch (REG_NOTE_KIND (note)) | |
23271 | { | |
23272 | case REG_FRAME_RELATED_EXPR: | |
23273 | goto found; | |
23274 | ||
23275 | case REG_CFA_REGISTER: | |
23276 | if (pat == NULL) | |
23277 | { | |
23278 | pat = PATTERN (insn); | |
23279 | if (GET_CODE (pat) == PARALLEL) | |
23280 | pat = XVECEXP (pat, 0, 0); | |
23281 | } | |
23282 | ||
23283 | /* Only emitted for IS_STACKALIGN re-alignment. */ | |
23284 | { | |
23285 | rtx dest, src; | |
23286 | unsigned reg; | |
23287 | ||
23288 | src = SET_SRC (pat); | |
23289 | dest = SET_DEST (pat); | |
23290 | ||
23291 | gcc_assert (src == stack_pointer_rtx); | |
23292 | reg = REGNO (dest); | |
23293 | asm_fprintf (asm_out_file, "\t.unwind_raw 0, 0x%x @ vsp = r%d\n", | |
23294 | reg + 0x90, reg); | |
23295 | } | |
23296 | handled_one = true; | |
23297 | break; | |
23298 | ||
23299 | case REG_CFA_DEF_CFA: | |
23300 | case REG_CFA_EXPRESSION: | |
23301 | case REG_CFA_ADJUST_CFA: | |
23302 | case REG_CFA_OFFSET: | |
23303 | /* ??? Only handling here what we actually emit. */ | |
23304 | gcc_unreachable (); | |
23305 | ||
23306 | default: | |
23307 | break; | |
23308 | } | |
23309 | } | |
23310 | if (handled_one) | |
23311 | return; | |
23312 | pat = PATTERN (insn); | |
23313 | found: | |
617a1b71 PB |
23314 | |
23315 | switch (GET_CODE (pat)) | |
23316 | { | |
23317 | case SET: | |
23318 | arm_unwind_emit_set (asm_out_file, pat); | |
23319 | break; | |
23320 | ||
23321 | case SEQUENCE: | |
23322 | /* Store multiple. */ | |
5b3e6663 | 23323 | arm_unwind_emit_sequence (asm_out_file, pat); |
617a1b71 PB |
23324 | break; |
23325 | ||
23326 | default: | |
23327 | abort(); | |
23328 | } | |
23329 | } | |
23330 | ||
23331 | ||
23332 | /* Output a reference from a function exception table to the type_info | |
23333 | object X. The EABI specifies that the symbol should be relocated by | |
23334 | an R_ARM_TARGET2 relocation. */ | |
23335 | ||
23336 | static bool | |
23337 | arm_output_ttype (rtx x) | |
23338 | { | |
23339 | fputs ("\t.word\t", asm_out_file); | |
23340 | output_addr_const (asm_out_file, x); | |
23341 | /* Use special relocations for symbol references. */ | |
23342 | if (GET_CODE (x) != CONST_INT) | |
23343 | fputs ("(TARGET2)", asm_out_file); | |
23344 | fputc ('\n', asm_out_file); | |
23345 | ||
23346 | return TRUE; | |
23347 | } | |
a68b5e52 RH |
23348 | |
23349 | /* Implement TARGET_ASM_EMIT_EXCEPT_PERSONALITY. */ | |
23350 | ||
23351 | static void | |
23352 | arm_asm_emit_except_personality (rtx personality) | |
23353 | { | |
23354 | fputs ("\t.personality\t", asm_out_file); | |
23355 | output_addr_const (asm_out_file, personality); | |
23356 | fputc ('\n', asm_out_file); | |
23357 | } | |
23358 | ||
23359 | /* Implement TARGET_ASM_INITIALIZE_SECTIONS. */ | |
23360 | ||
23361 | static void | |
23362 | arm_asm_init_sections (void) | |
23363 | { | |
23364 | exception_section = get_unnamed_section (0, output_section_asm_op, | |
23365 | "\t.handlerdata"); | |
23366 | } | |
f0a0390e RH |
23367 | #endif /* ARM_UNWIND_INFO */ |
23368 | ||
617a1b71 PB |
23369 | /* Output unwind directives for the start/end of a function. */ |
23370 | ||
23371 | void | |
23372 | arm_output_fn_unwind (FILE * f, bool prologue) | |
23373 | { | |
d5fabb58 | 23374 | if (arm_except_unwind_info (&global_options) != UI_TARGET) |
617a1b71 PB |
23375 | return; |
23376 | ||
23377 | if (prologue) | |
23378 | fputs ("\t.fnstart\n", f); | |
23379 | else | |
80efdb6a PB |
23380 | { |
23381 | /* If this function will never be unwound, then mark it as such. | |
23382 | The came condition is used in arm_unwind_emit to suppress | |
23383 | the frame annotations. */ | |
e3b5732b | 23384 | if (!(flag_unwind_tables || crtl->uses_eh_lsda) |
80efdb6a | 23385 | && (TREE_NOTHROW (current_function_decl) |
ad516a74 | 23386 | || crtl->all_throwers_are_sibcalls)) |
80efdb6a PB |
23387 | fputs("\t.cantunwind\n", f); |
23388 | ||
23389 | fputs ("\t.fnend\n", f); | |
23390 | } | |
617a1b71 | 23391 | } |
d3585b76 DJ |
23392 | |
23393 | static bool | |
23394 | arm_emit_tls_decoration (FILE *fp, rtx x) | |
23395 | { | |
23396 | enum tls_reloc reloc; | |
23397 | rtx val; | |
23398 | ||
23399 | val = XVECEXP (x, 0, 0); | |
32e8bb8e | 23400 | reloc = (enum tls_reloc) INTVAL (XVECEXP (x, 0, 1)); |
d3585b76 DJ |
23401 | |
23402 | output_addr_const (fp, val); | |
23403 | ||
23404 | switch (reloc) | |
23405 | { | |
23406 | case TLS_GD32: | |
23407 | fputs ("(tlsgd)", fp); | |
23408 | break; | |
23409 | case TLS_LDM32: | |
23410 | fputs ("(tlsldm)", fp); | |
23411 | break; | |
23412 | case TLS_LDO32: | |
23413 | fputs ("(tlsldo)", fp); | |
23414 | break; | |
23415 | case TLS_IE32: | |
23416 | fputs ("(gottpoff)", fp); | |
23417 | break; | |
23418 | case TLS_LE32: | |
23419 | fputs ("(tpoff)", fp); | |
23420 | break; | |
ccdc2164 NS |
23421 | case TLS_DESCSEQ: |
23422 | fputs ("(tlsdesc)", fp); | |
23423 | break; | |
d3585b76 DJ |
23424 | default: |
23425 | gcc_unreachable (); | |
23426 | } | |
23427 | ||
23428 | switch (reloc) | |
23429 | { | |
23430 | case TLS_GD32: | |
23431 | case TLS_LDM32: | |
23432 | case TLS_IE32: | |
ccdc2164 | 23433 | case TLS_DESCSEQ: |
d3585b76 DJ |
23434 | fputs (" + (. - ", fp); |
23435 | output_addr_const (fp, XVECEXP (x, 0, 2)); | |
ccdc2164 NS |
23436 | /* For DESCSEQ the 3rd operand encodes thumbness, and is added */ |
23437 | fputs (reloc == TLS_DESCSEQ ? " + " : " - ", fp); | |
d3585b76 DJ |
23438 | output_addr_const (fp, XVECEXP (x, 0, 3)); |
23439 | fputc (')', fp); | |
23440 | break; | |
23441 | default: | |
23442 | break; | |
23443 | } | |
23444 | ||
23445 | return TRUE; | |
23446 | } | |
23447 | ||
afcc986d JM |
23448 | /* ARM implementation of TARGET_ASM_OUTPUT_DWARF_DTPREL. */ |
23449 | ||
23450 | static void | |
23451 | arm_output_dwarf_dtprel (FILE *file, int size, rtx x) | |
23452 | { | |
23453 | gcc_assert (size == 4); | |
23454 | fputs ("\t.word\t", file); | |
23455 | output_addr_const (file, x); | |
23456 | fputs ("(tlsldo)", file); | |
23457 | } | |
23458 | ||
ffda8a0d AS |
23459 | /* Implement TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA. */ |
23460 | ||
23461 | static bool | |
d3585b76 DJ |
23462 | arm_output_addr_const_extra (FILE *fp, rtx x) |
23463 | { | |
23464 | if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS) | |
23465 | return arm_emit_tls_decoration (fp, x); | |
f16fe45f DJ |
23466 | else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_PIC_LABEL) |
23467 | { | |
23468 | char label[256]; | |
23469 | int labelno = INTVAL (XVECEXP (x, 0, 0)); | |
23470 | ||
23471 | ASM_GENERATE_INTERNAL_LABEL (label, "LPIC", labelno); | |
23472 | assemble_name_raw (fp, label); | |
23473 | ||
f9bd1a89 RS |
23474 | return TRUE; |
23475 | } | |
23476 | else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_GOTSYM_OFF) | |
23477 | { | |
23478 | assemble_name (fp, "_GLOBAL_OFFSET_TABLE_"); | |
23479 | if (GOT_PCREL) | |
23480 | fputs ("+.", fp); | |
23481 | fputs ("-(", fp); | |
23482 | output_addr_const (fp, XVECEXP (x, 0, 0)); | |
23483 | fputc (')', fp); | |
f16fe45f DJ |
23484 | return TRUE; |
23485 | } | |
85c9bcd4 WG |
23486 | else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SYMBOL_OFFSET) |
23487 | { | |
23488 | output_addr_const (fp, XVECEXP (x, 0, 0)); | |
23489 | if (GOT_PCREL) | |
23490 | fputs ("+.", fp); | |
23491 | fputs ("-(", fp); | |
23492 | output_addr_const (fp, XVECEXP (x, 0, 1)); | |
23493 | fputc (')', fp); | |
23494 | return TRUE; | |
23495 | } | |
d3585b76 DJ |
23496 | else if (GET_CODE (x) == CONST_VECTOR) |
23497 | return arm_emit_vector_const (fp, x); | |
23498 | ||
23499 | return FALSE; | |
23500 | } | |
23501 | ||
5b3e6663 PB |
23502 | /* Output assembly for a shift instruction. |
23503 | SET_FLAGS determines how the instruction modifies the condition codes. | |
7a085dce | 23504 | 0 - Do not set condition codes. |
5b3e6663 PB |
23505 | 1 - Set condition codes. |
23506 | 2 - Use smallest instruction. */ | |
23507 | const char * | |
23508 | arm_output_shift(rtx * operands, int set_flags) | |
23509 | { | |
23510 | char pattern[100]; | |
23511 | static const char flag_chars[3] = {'?', '.', '!'}; | |
23512 | const char *shift; | |
23513 | HOST_WIDE_INT val; | |
23514 | char c; | |
23515 | ||
23516 | c = flag_chars[set_flags]; | |
23517 | if (TARGET_UNIFIED_ASM) | |
23518 | { | |
23519 | shift = shift_op(operands[3], &val); | |
23520 | if (shift) | |
23521 | { | |
23522 | if (val != -1) | |
23523 | operands[2] = GEN_INT(val); | |
23524 | sprintf (pattern, "%s%%%c\t%%0, %%1, %%2", shift, c); | |
23525 | } | |
23526 | else | |
23527 | sprintf (pattern, "mov%%%c\t%%0, %%1", c); | |
23528 | } | |
23529 | else | |
23530 | sprintf (pattern, "mov%%%c\t%%0, %%1%%S3", c); | |
23531 | output_asm_insn (pattern, operands); | |
23532 | return ""; | |
23533 | } | |
23534 | ||
907dd0c7 RE |
23535 | /* Output a Thumb-1 casesi dispatch sequence. */ |
23536 | const char * | |
23537 | thumb1_output_casesi (rtx *operands) | |
23538 | { | |
23539 | rtx diff_vec = PATTERN (next_real_insn (operands[0])); | |
907dd0c7 RE |
23540 | |
23541 | gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC); | |
23542 | ||
907dd0c7 RE |
23543 | switch (GET_MODE(diff_vec)) |
23544 | { | |
23545 | case QImode: | |
23546 | return (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned ? | |
23547 | "bl\t%___gnu_thumb1_case_uqi" : "bl\t%___gnu_thumb1_case_sqi"); | |
23548 | case HImode: | |
23549 | return (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned ? | |
23550 | "bl\t%___gnu_thumb1_case_uhi" : "bl\t%___gnu_thumb1_case_shi"); | |
23551 | case SImode: | |
23552 | return "bl\t%___gnu_thumb1_case_si"; | |
23553 | default: | |
23554 | gcc_unreachable (); | |
23555 | } | |
23556 | } | |
23557 | ||
5b3e6663 PB |
23558 | /* Output a Thumb-2 casesi instruction. */ |
23559 | const char * | |
23560 | thumb2_output_casesi (rtx *operands) | |
23561 | { | |
23562 | rtx diff_vec = PATTERN (next_real_insn (operands[2])); | |
23563 | ||
23564 | gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC); | |
23565 | ||
23566 | output_asm_insn ("cmp\t%0, %1", operands); | |
23567 | output_asm_insn ("bhi\t%l3", operands); | |
23568 | switch (GET_MODE(diff_vec)) | |
23569 | { | |
23570 | case QImode: | |
23571 | return "tbb\t[%|pc, %0]"; | |
23572 | case HImode: | |
23573 | return "tbh\t[%|pc, %0, lsl #1]"; | |
23574 | case SImode: | |
23575 | if (flag_pic) | |
23576 | { | |
23577 | output_asm_insn ("adr\t%4, %l2", operands); | |
23578 | output_asm_insn ("ldr\t%5, [%4, %0, lsl #2]", operands); | |
23579 | output_asm_insn ("add\t%4, %4, %5", operands); | |
23580 | return "bx\t%4"; | |
23581 | } | |
23582 | else | |
23583 | { | |
23584 | output_asm_insn ("adr\t%4, %l2", operands); | |
23585 | return "ldr\t%|pc, [%4, %0, lsl #2]"; | |
23586 | } | |
23587 | default: | |
23588 | gcc_unreachable (); | |
23589 | } | |
23590 | } | |
23591 | ||
bd4dc3cd PB |
23592 | /* Most ARM cores are single issue, but some newer ones can dual issue. |
23593 | The scheduler descriptions rely on this being correct. */ | |
23594 | static int | |
23595 | arm_issue_rate (void) | |
23596 | { | |
23597 | switch (arm_tune) | |
23598 | { | |
23599 | case cortexr4: | |
51c69ddb | 23600 | case cortexr4f: |
572070ef | 23601 | case cortexr5: |
d8099dd8 | 23602 | case cortexa5: |
bd4dc3cd | 23603 | case cortexa8: |
7612f14d | 23604 | case cortexa9: |
c02a5ccb | 23605 | case fa726te: |
bd4dc3cd PB |
23606 | return 2; |
23607 | ||
23608 | default: | |
23609 | return 1; | |
23610 | } | |
23611 | } | |
23612 | ||
608063c3 JB |
23613 | /* A table and a function to perform ARM-specific name mangling for |
23614 | NEON vector types in order to conform to the AAPCS (see "Procedure | |
23615 | Call Standard for the ARM Architecture", Appendix A). To qualify | |
23616 | for emission with the mangled names defined in that document, a | |
23617 | vector type must not only be of the correct mode but also be | |
23618 | composed of NEON vector element types (e.g. __builtin_neon_qi). */ | |
23619 | typedef struct | |
23620 | { | |
23621 | enum machine_mode mode; | |
23622 | const char *element_type_name; | |
23623 | const char *aapcs_name; | |
23624 | } arm_mangle_map_entry; | |
23625 | ||
23626 | static arm_mangle_map_entry arm_mangle_map[] = { | |
23627 | /* 64-bit containerized types. */ | |
23628 | { V8QImode, "__builtin_neon_qi", "15__simd64_int8_t" }, | |
23629 | { V8QImode, "__builtin_neon_uqi", "16__simd64_uint8_t" }, | |
23630 | { V4HImode, "__builtin_neon_hi", "16__simd64_int16_t" }, | |
23631 | { V4HImode, "__builtin_neon_uhi", "17__simd64_uint16_t" }, | |
23632 | { V2SImode, "__builtin_neon_si", "16__simd64_int32_t" }, | |
23633 | { V2SImode, "__builtin_neon_usi", "17__simd64_uint32_t" }, | |
23634 | { V2SFmode, "__builtin_neon_sf", "18__simd64_float32_t" }, | |
23635 | { V8QImode, "__builtin_neon_poly8", "16__simd64_poly8_t" }, | |
23636 | { V4HImode, "__builtin_neon_poly16", "17__simd64_poly16_t" }, | |
23637 | /* 128-bit containerized types. */ | |
23638 | { V16QImode, "__builtin_neon_qi", "16__simd128_int8_t" }, | |
23639 | { V16QImode, "__builtin_neon_uqi", "17__simd128_uint8_t" }, | |
23640 | { V8HImode, "__builtin_neon_hi", "17__simd128_int16_t" }, | |
23641 | { V8HImode, "__builtin_neon_uhi", "18__simd128_uint16_t" }, | |
23642 | { V4SImode, "__builtin_neon_si", "17__simd128_int32_t" }, | |
23643 | { V4SImode, "__builtin_neon_usi", "18__simd128_uint32_t" }, | |
23644 | { V4SFmode, "__builtin_neon_sf", "19__simd128_float32_t" }, | |
23645 | { V16QImode, "__builtin_neon_poly8", "17__simd128_poly8_t" }, | |
23646 | { V8HImode, "__builtin_neon_poly16", "18__simd128_poly16_t" }, | |
23647 | { VOIDmode, NULL, NULL } | |
23648 | }; | |
23649 | ||
23650 | const char * | |
3101faab | 23651 | arm_mangle_type (const_tree type) |
608063c3 JB |
23652 | { |
23653 | arm_mangle_map_entry *pos = arm_mangle_map; | |
23654 | ||
07d8efe3 MM |
23655 | /* The ARM ABI documents (10th October 2008) say that "__va_list" |
23656 | has to be managled as if it is in the "std" namespace. */ | |
23657 | if (TARGET_AAPCS_BASED | |
ae46a823 | 23658 | && lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type)) |
07d8efe3 MM |
23659 | { |
23660 | static bool warned; | |
d147cbd9 | 23661 | if (!warned && warn_psabi && !in_system_header) |
07d8efe3 MM |
23662 | { |
23663 | warned = true; | |
23664 | inform (input_location, | |
23665 | "the mangling of %<va_list%> has changed in GCC 4.4"); | |
23666 | } | |
23667 | return "St9__va_list"; | |
23668 | } | |
23669 | ||
0fd8c3ad SL |
23670 | /* Half-precision float. */ |
23671 | if (TREE_CODE (type) == REAL_TYPE && TYPE_PRECISION (type) == 16) | |
23672 | return "Dh"; | |
23673 | ||
608063c3 JB |
23674 | if (TREE_CODE (type) != VECTOR_TYPE) |
23675 | return NULL; | |
23676 | ||
23677 | /* Check the mode of the vector type, and the name of the vector | |
23678 | element type, against the table. */ | |
23679 | while (pos->mode != VOIDmode) | |
23680 | { | |
23681 | tree elt_type = TREE_TYPE (type); | |
23682 | ||
23683 | if (pos->mode == TYPE_MODE (type) | |
23684 | && TREE_CODE (TYPE_NAME (elt_type)) == TYPE_DECL | |
23685 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (elt_type))), | |
23686 | pos->element_type_name)) | |
23687 | return pos->aapcs_name; | |
23688 | ||
23689 | pos++; | |
23690 | } | |
23691 | ||
23692 | /* Use the default mangling for unrecognized (possibly user-defined) | |
23693 | vector types. */ | |
23694 | return NULL; | |
23695 | } | |
23696 | ||
795dc4fc PB |
23697 | /* Order of allocation of core registers for Thumb: this allocation is |
23698 | written over the corresponding initial entries of the array | |
23699 | initialized with REG_ALLOC_ORDER. We allocate all low registers | |
23700 | first. Saving and restoring a low register is usually cheaper than | |
23701 | using a call-clobbered high register. */ | |
23702 | ||
23703 | static const int thumb_core_reg_alloc_order[] = | |
23704 | { | |
23705 | 3, 2, 1, 0, 4, 5, 6, 7, | |
23706 | 14, 12, 8, 9, 10, 11, 13, 15 | |
23707 | }; | |
23708 | ||
23709 | /* Adjust register allocation order when compiling for Thumb. */ | |
23710 | ||
23711 | void | |
23712 | arm_order_regs_for_local_alloc (void) | |
23713 | { | |
23714 | const int arm_reg_alloc_order[] = REG_ALLOC_ORDER; | |
23715 | memcpy(reg_alloc_order, arm_reg_alloc_order, sizeof (reg_alloc_order)); | |
23716 | if (TARGET_THUMB) | |
23717 | memcpy (reg_alloc_order, thumb_core_reg_alloc_order, | |
23718 | sizeof (thumb_core_reg_alloc_order)); | |
23719 | } | |
23720 | ||
b52b1749 AS |
23721 | /* Implement TARGET_FRAME_POINTER_REQUIRED. */ |
23722 | ||
23723 | bool | |
23724 | arm_frame_pointer_required (void) | |
23725 | { | |
23726 | return (cfun->has_nonlocal_label | |
23727 | || SUBTARGET_FRAME_POINTER_REQUIRED | |
23728 | || (TARGET_ARM && TARGET_APCS_FRAME && ! leaf_function_p ())); | |
23729 | } | |
23730 | ||
2929029c WG |
23731 | /* Only thumb1 can't support conditional execution, so return true if |
23732 | the target is not thumb1. */ | |
23733 | static bool | |
23734 | arm_have_conditional_execution (void) | |
23735 | { | |
23736 | return !TARGET_THUMB1; | |
23737 | } | |
23738 | ||
029e79eb MS |
23739 | /* Legitimize a memory reference for sync primitive implemented using |
23740 | ldrex / strex. We currently force the form of the reference to be | |
23741 | indirect without offset. We do not yet support the indirect offset | |
23742 | addressing supported by some ARM targets for these | |
23743 | instructions. */ | |
23744 | static rtx | |
23745 | arm_legitimize_sync_memory (rtx memory) | |
23746 | { | |
23747 | rtx addr = force_reg (Pmode, XEXP (memory, 0)); | |
23748 | rtx legitimate_memory = gen_rtx_MEM (GET_MODE (memory), addr); | |
23749 | ||
23750 | set_mem_alias_set (legitimate_memory, ALIAS_SET_MEMORY_BARRIER); | |
23751 | MEM_VOLATILE_P (legitimate_memory) = MEM_VOLATILE_P (memory); | |
23752 | return legitimate_memory; | |
23753 | } | |
23754 | ||
23755 | /* An instruction emitter. */ | |
23756 | typedef void (* emit_f) (int label, const char *, rtx *); | |
23757 | ||
23758 | /* An instruction emitter that emits via the conventional | |
23759 | output_asm_insn. */ | |
23760 | static void | |
23761 | arm_emit (int label ATTRIBUTE_UNUSED, const char *pattern, rtx *operands) | |
23762 | { | |
23763 | output_asm_insn (pattern, operands); | |
23764 | } | |
23765 | ||
23766 | /* Count the number of emitted synchronization instructions. */ | |
23767 | static unsigned arm_insn_count; | |
23768 | ||
23769 | /* An emitter that counts emitted instructions but does not actually | |
dd5a833e | 23770 | emit instruction into the instruction stream. */ |
029e79eb MS |
23771 | static void |
23772 | arm_count (int label, | |
23773 | const char *pattern ATTRIBUTE_UNUSED, | |
23774 | rtx *operands ATTRIBUTE_UNUSED) | |
23775 | { | |
23776 | if (! label) | |
23777 | ++ arm_insn_count; | |
23778 | } | |
23779 | ||
23780 | /* Construct a pattern using conventional output formatting and feed | |
23781 | it to output_asm_insn. Provides a mechanism to construct the | |
23782 | output pattern on the fly. Note the hard limit on the pattern | |
23783 | buffer size. */ | |
21272a45 | 23784 | static void ATTRIBUTE_PRINTF_4 |
029e79eb MS |
23785 | arm_output_asm_insn (emit_f emit, int label, rtx *operands, |
23786 | const char *pattern, ...) | |
23787 | { | |
23788 | va_list ap; | |
23789 | char buffer[256]; | |
23790 | ||
23791 | va_start (ap, pattern); | |
23792 | vsprintf (buffer, pattern, ap); | |
23793 | va_end (ap); | |
23794 | emit (label, buffer, operands); | |
23795 | } | |
23796 | ||
23797 | /* Emit the memory barrier instruction, if any, provided by this | |
23798 | target to a specified emitter. */ | |
23799 | static void | |
23800 | arm_process_output_memory_barrier (emit_f emit, rtx *operands) | |
23801 | { | |
23802 | if (TARGET_HAVE_DMB) | |
23803 | { | |
23804 | /* Note we issue a system level barrier. We should consider | |
23805 | issuing a inner shareabilty zone barrier here instead, ie. | |
23806 | "DMB ISH". */ | |
23807 | emit (0, "dmb\tsy", operands); | |
23808 | return; | |
23809 | } | |
23810 | ||
23811 | if (TARGET_HAVE_DMB_MCR) | |
23812 | { | |
23813 | emit (0, "mcr\tp15, 0, r0, c7, c10, 5", operands); | |
23814 | return; | |
23815 | } | |
23816 | ||
23817 | gcc_unreachable (); | |
23818 | } | |
23819 | ||
23820 | /* Emit the memory barrier instruction, if any, provided by this | |
23821 | target. */ | |
23822 | const char * | |
23823 | arm_output_memory_barrier (rtx *operands) | |
23824 | { | |
23825 | arm_process_output_memory_barrier (arm_emit, operands); | |
23826 | return ""; | |
23827 | } | |
23828 | ||
23829 | /* Helper to figure out the instruction suffix required on ldrex/strex | |
23830 | for operations on an object of the specified mode. */ | |
23831 | static const char * | |
23832 | arm_ldrex_suffix (enum machine_mode mode) | |
23833 | { | |
23834 | switch (mode) | |
23835 | { | |
23836 | case QImode: return "b"; | |
23837 | case HImode: return "h"; | |
23838 | case SImode: return ""; | |
23839 | case DImode: return "d"; | |
23840 | default: | |
23841 | gcc_unreachable (); | |
23842 | } | |
23843 | return ""; | |
23844 | } | |
23845 | ||
23846 | /* Emit an ldrex{b,h,d, } instruction appropriate for the specified | |
23847 | mode. */ | |
23848 | static void | |
23849 | arm_output_ldrex (emit_f emit, | |
23850 | enum machine_mode mode, | |
23851 | rtx target, | |
23852 | rtx memory) | |
23853 | { | |
23854 | const char *suffix = arm_ldrex_suffix (mode); | |
23855 | rtx operands[2]; | |
23856 | ||
23857 | operands[0] = target; | |
23858 | operands[1] = memory; | |
23859 | arm_output_asm_insn (emit, 0, operands, "ldrex%s\t%%0, %%C1", suffix); | |
23860 | } | |
23861 | ||
23862 | /* Emit a strex{b,h,d, } instruction appropriate for the specified | |
23863 | mode. */ | |
23864 | static void | |
23865 | arm_output_strex (emit_f emit, | |
23866 | enum machine_mode mode, | |
23867 | const char *cc, | |
23868 | rtx result, | |
23869 | rtx value, | |
23870 | rtx memory) | |
23871 | { | |
23872 | const char *suffix = arm_ldrex_suffix (mode); | |
23873 | rtx operands[3]; | |
23874 | ||
23875 | operands[0] = result; | |
23876 | operands[1] = value; | |
23877 | operands[2] = memory; | |
23878 | arm_output_asm_insn (emit, 0, operands, "strex%s%s\t%%0, %%1, %%C2", suffix, | |
23879 | cc); | |
23880 | } | |
23881 | ||
23882 | /* Helper to emit a two operand instruction. */ | |
23883 | static void | |
23884 | arm_output_op2 (emit_f emit, const char *mnemonic, rtx d, rtx s) | |
23885 | { | |
23886 | rtx operands[2]; | |
23887 | ||
23888 | operands[0] = d; | |
23889 | operands[1] = s; | |
23890 | arm_output_asm_insn (emit, 0, operands, "%s\t%%0, %%1", mnemonic); | |
23891 | } | |
23892 | ||
23893 | /* Helper to emit a three operand instruction. */ | |
23894 | static void | |
23895 | arm_output_op3 (emit_f emit, const char *mnemonic, rtx d, rtx a, rtx b) | |
23896 | { | |
23897 | rtx operands[3]; | |
23898 | ||
23899 | operands[0] = d; | |
23900 | operands[1] = a; | |
23901 | operands[2] = b; | |
23902 | arm_output_asm_insn (emit, 0, operands, "%s\t%%0, %%1, %%2", mnemonic); | |
23903 | } | |
23904 | ||
23905 | /* Emit a load store exclusive synchronization loop. | |
23906 | ||
23907 | do | |
23908 | old_value = [mem] | |
23909 | if old_value != required_value | |
23910 | break; | |
23911 | t1 = sync_op (old_value, new_value) | |
23912 | [mem] = t1, t2 = [0|1] | |
23913 | while ! t2 | |
23914 | ||
23915 | Note: | |
23916 | t1 == t2 is not permitted | |
23917 | t1 == old_value is permitted | |
23918 | ||
23919 | required_value: | |
23920 | ||
23921 | RTX register or const_int representing the required old_value for | |
23922 | the modify to continue, if NULL no comparsion is performed. */ | |
23923 | static void | |
23924 | arm_output_sync_loop (emit_f emit, | |
23925 | enum machine_mode mode, | |
23926 | rtx old_value, | |
23927 | rtx memory, | |
23928 | rtx required_value, | |
23929 | rtx new_value, | |
23930 | rtx t1, | |
23931 | rtx t2, | |
23932 | enum attr_sync_op sync_op, | |
23933 | int early_barrier_required) | |
23934 | { | |
23935 | rtx operands[1]; | |
23936 | ||
23937 | gcc_assert (t1 != t2); | |
23938 | ||
23939 | if (early_barrier_required) | |
23940 | arm_process_output_memory_barrier (emit, NULL); | |
23941 | ||
23942 | arm_output_asm_insn (emit, 1, operands, "%sLSYT%%=:", LOCAL_LABEL_PREFIX); | |
23943 | ||
23944 | arm_output_ldrex (emit, mode, old_value, memory); | |
23945 | ||
23946 | if (required_value) | |
23947 | { | |
23948 | rtx operands[2]; | |
23949 | ||
23950 | operands[0] = old_value; | |
23951 | operands[1] = required_value; | |
23952 | arm_output_asm_insn (emit, 0, operands, "cmp\t%%0, %%1"); | |
23953 | arm_output_asm_insn (emit, 0, operands, "bne\t%sLSYB%%=", LOCAL_LABEL_PREFIX); | |
23954 | } | |
23955 | ||
23956 | switch (sync_op) | |
23957 | { | |
23958 | case SYNC_OP_ADD: | |
23959 | arm_output_op3 (emit, "add", t1, old_value, new_value); | |
23960 | break; | |
23961 | ||
23962 | case SYNC_OP_SUB: | |
23963 | arm_output_op3 (emit, "sub", t1, old_value, new_value); | |
23964 | break; | |
23965 | ||
23966 | case SYNC_OP_IOR: | |
23967 | arm_output_op3 (emit, "orr", t1, old_value, new_value); | |
23968 | break; | |
23969 | ||
23970 | case SYNC_OP_XOR: | |
23971 | arm_output_op3 (emit, "eor", t1, old_value, new_value); | |
23972 | break; | |
23973 | ||
23974 | case SYNC_OP_AND: | |
23975 | arm_output_op3 (emit,"and", t1, old_value, new_value); | |
23976 | break; | |
23977 | ||
23978 | case SYNC_OP_NAND: | |
23979 | arm_output_op3 (emit, "and", t1, old_value, new_value); | |
23980 | arm_output_op2 (emit, "mvn", t1, t1); | |
23981 | break; | |
23982 | ||
23983 | case SYNC_OP_NONE: | |
23984 | t1 = new_value; | |
23985 | break; | |
23986 | } | |
23987 | ||
b7b79b54 KW |
23988 | if (t2) |
23989 | { | |
23990 | arm_output_strex (emit, mode, "", t2, t1, memory); | |
23991 | operands[0] = t2; | |
23992 | arm_output_asm_insn (emit, 0, operands, "teq\t%%0, #0"); | |
23993 | arm_output_asm_insn (emit, 0, operands, "bne\t%sLSYT%%=", | |
23994 | LOCAL_LABEL_PREFIX); | |
23995 | } | |
23996 | else | |
23997 | { | |
23998 | /* Use old_value for the return value because for some operations | |
23999 | the old_value can easily be restored. This saves one register. */ | |
24000 | arm_output_strex (emit, mode, "", old_value, t1, memory); | |
24001 | operands[0] = old_value; | |
24002 | arm_output_asm_insn (emit, 0, operands, "teq\t%%0, #0"); | |
24003 | arm_output_asm_insn (emit, 0, operands, "bne\t%sLSYT%%=", | |
24004 | LOCAL_LABEL_PREFIX); | |
24005 | ||
24006 | switch (sync_op) | |
24007 | { | |
24008 | case SYNC_OP_ADD: | |
24009 | arm_output_op3 (emit, "sub", old_value, t1, new_value); | |
24010 | break; | |
24011 | ||
24012 | case SYNC_OP_SUB: | |
24013 | arm_output_op3 (emit, "add", old_value, t1, new_value); | |
24014 | break; | |
24015 | ||
24016 | case SYNC_OP_XOR: | |
24017 | arm_output_op3 (emit, "eor", old_value, t1, new_value); | |
24018 | break; | |
24019 | ||
24020 | case SYNC_OP_NONE: | |
24021 | arm_output_op2 (emit, "mov", old_value, required_value); | |
24022 | break; | |
24023 | ||
24024 | default: | |
24025 | gcc_unreachable (); | |
24026 | } | |
24027 | } | |
029e79eb MS |
24028 | |
24029 | arm_process_output_memory_barrier (emit, NULL); | |
24030 | arm_output_asm_insn (emit, 1, operands, "%sLSYB%%=:", LOCAL_LABEL_PREFIX); | |
24031 | } | |
24032 | ||
24033 | static rtx | |
24034 | arm_get_sync_operand (rtx *operands, int index, rtx default_value) | |
24035 | { | |
24036 | if (index > 0) | |
24037 | default_value = operands[index - 1]; | |
24038 | ||
24039 | return default_value; | |
24040 | } | |
24041 | ||
24042 | #define FETCH_SYNC_OPERAND(NAME, DEFAULT) \ | |
24043 | arm_get_sync_operand (operands, (int) get_attr_sync_##NAME (insn), DEFAULT); | |
24044 | ||
24045 | /* Extract the operands for a synchroniztion instruction from the | |
24046 | instructions attributes and emit the instruction. */ | |
24047 | static void | |
24048 | arm_process_output_sync_insn (emit_f emit, rtx insn, rtx *operands) | |
24049 | { | |
24050 | rtx result, memory, required_value, new_value, t1, t2; | |
24051 | int early_barrier; | |
24052 | enum machine_mode mode; | |
24053 | enum attr_sync_op sync_op; | |
24054 | ||
24055 | result = FETCH_SYNC_OPERAND(result, 0); | |
24056 | memory = FETCH_SYNC_OPERAND(memory, 0); | |
24057 | required_value = FETCH_SYNC_OPERAND(required_value, 0); | |
24058 | new_value = FETCH_SYNC_OPERAND(new_value, 0); | |
24059 | t1 = FETCH_SYNC_OPERAND(t1, 0); | |
24060 | t2 = FETCH_SYNC_OPERAND(t2, 0); | |
24061 | early_barrier = | |
24062 | get_attr_sync_release_barrier (insn) == SYNC_RELEASE_BARRIER_YES; | |
24063 | sync_op = get_attr_sync_op (insn); | |
24064 | mode = GET_MODE (memory); | |
24065 | ||
24066 | arm_output_sync_loop (emit, mode, result, memory, required_value, | |
24067 | new_value, t1, t2, sync_op, early_barrier); | |
24068 | } | |
24069 | ||
24070 | /* Emit a synchronization instruction loop. */ | |
24071 | const char * | |
24072 | arm_output_sync_insn (rtx insn, rtx *operands) | |
24073 | { | |
24074 | arm_process_output_sync_insn (arm_emit, insn, operands); | |
24075 | return ""; | |
24076 | } | |
24077 | ||
24078 | /* Count the number of machine instruction that will be emitted for a | |
24079 | synchronization instruction. Note that the emitter used does not | |
24080 | emit instructions, it just counts instructions being carefull not | |
24081 | to count labels. */ | |
24082 | unsigned int | |
24083 | arm_sync_loop_insns (rtx insn, rtx *operands) | |
24084 | { | |
24085 | arm_insn_count = 0; | |
24086 | arm_process_output_sync_insn (arm_count, insn, operands); | |
24087 | return arm_insn_count; | |
24088 | } | |
24089 | ||
24090 | /* Helper to call a target sync instruction generator, dealing with | |
24091 | the variation in operands required by the different generators. */ | |
24092 | static rtx | |
24093 | arm_call_generator (struct arm_sync_generator *generator, rtx old_value, | |
24094 | rtx memory, rtx required_value, rtx new_value) | |
24095 | { | |
24096 | switch (generator->op) | |
24097 | { | |
24098 | case arm_sync_generator_omn: | |
24099 | gcc_assert (! required_value); | |
24100 | return generator->u.omn (old_value, memory, new_value); | |
24101 | ||
24102 | case arm_sync_generator_omrn: | |
24103 | gcc_assert (required_value); | |
24104 | return generator->u.omrn (old_value, memory, required_value, new_value); | |
24105 | } | |
24106 | ||
24107 | return NULL; | |
24108 | } | |
24109 | ||
24110 | /* Expand a synchronization loop. The synchronization loop is expanded | |
24111 | as an opaque block of instructions in order to ensure that we do | |
24112 | not subsequently get extraneous memory accesses inserted within the | |
24113 | critical region. The exclusive access property of ldrex/strex is | |
24114 | only guaranteed in there are no intervening memory accesses. */ | |
24115 | void | |
24116 | arm_expand_sync (enum machine_mode mode, | |
24117 | struct arm_sync_generator *generator, | |
24118 | rtx target, rtx memory, rtx required_value, rtx new_value) | |
24119 | { | |
24120 | if (target == NULL) | |
24121 | target = gen_reg_rtx (mode); | |
24122 | ||
24123 | memory = arm_legitimize_sync_memory (memory); | |
24124 | if (mode != SImode) | |
24125 | { | |
24126 | rtx load_temp = gen_reg_rtx (SImode); | |
24127 | ||
24128 | if (required_value) | |
24129 | required_value = convert_modes (SImode, mode, required_value, true); | |
24130 | ||
24131 | new_value = convert_modes (SImode, mode, new_value, true); | |
24132 | emit_insn (arm_call_generator (generator, load_temp, memory, | |
24133 | required_value, new_value)); | |
24134 | emit_move_insn (target, gen_lowpart (mode, load_temp)); | |
24135 | } | |
24136 | else | |
24137 | { | |
24138 | emit_insn (arm_call_generator (generator, target, memory, required_value, | |
24139 | new_value)); | |
24140 | } | |
24141 | } | |
24142 | ||
69d52339 IR |
24143 | static unsigned int |
24144 | arm_autovectorize_vector_sizes (void) | |
24145 | { | |
24146 | return TARGET_NEON_VECTORIZE_QUAD ? 16 | 8 : 0; | |
24147 | } | |
24148 | ||
c452684d JB |
24149 | static bool |
24150 | arm_vector_alignment_reachable (const_tree type, bool is_packed) | |
24151 | { | |
24152 | /* Vectors which aren't in packed structures will not be less aligned than | |
24153 | the natural alignment of their element type, so this is safe. */ | |
24154 | if (TARGET_NEON && !BYTES_BIG_ENDIAN) | |
24155 | return !is_packed; | |
24156 | ||
24157 | return default_builtin_vector_alignment_reachable (type, is_packed); | |
24158 | } | |
24159 | ||
24160 | static bool | |
24161 | arm_builtin_support_vector_misalignment (enum machine_mode mode, | |
24162 | const_tree type, int misalignment, | |
24163 | bool is_packed) | |
24164 | { | |
24165 | if (TARGET_NEON && !BYTES_BIG_ENDIAN) | |
24166 | { | |
24167 | HOST_WIDE_INT align = TYPE_ALIGN_UNIT (type); | |
24168 | ||
24169 | if (is_packed) | |
24170 | return align == 1; | |
24171 | ||
24172 | /* If the misalignment is unknown, we should be able to handle the access | |
24173 | so long as it is not to a member of a packed data structure. */ | |
24174 | if (misalignment == -1) | |
24175 | return true; | |
24176 | ||
24177 | /* Return true if the misalignment is a multiple of the natural alignment | |
24178 | of the vector's element type. This is probably always going to be | |
24179 | true in practice, since we've already established that this isn't a | |
24180 | packed access. */ | |
24181 | return ((misalignment % align) == 0); | |
24182 | } | |
24183 | ||
24184 | return default_builtin_support_vector_misalignment (mode, type, misalignment, | |
24185 | is_packed); | |
24186 | } | |
24187 | ||
5efd84c5 NF |
24188 | static void |
24189 | arm_conditional_register_usage (void) | |
24190 | { | |
24191 | int regno; | |
24192 | ||
24193 | if (TARGET_SOFT_FLOAT || TARGET_THUMB1 || !TARGET_FPA) | |
24194 | { | |
24195 | for (regno = FIRST_FPA_REGNUM; | |
24196 | regno <= LAST_FPA_REGNUM; ++regno) | |
24197 | fixed_regs[regno] = call_used_regs[regno] = 1; | |
24198 | } | |
24199 | ||
24200 | if (TARGET_THUMB1 && optimize_size) | |
24201 | { | |
24202 | /* When optimizing for size on Thumb-1, it's better not | |
24203 | to use the HI regs, because of the overhead of | |
24204 | stacking them. */ | |
24205 | for (regno = FIRST_HI_REGNUM; | |
24206 | regno <= LAST_HI_REGNUM; ++regno) | |
24207 | fixed_regs[regno] = call_used_regs[regno] = 1; | |
24208 | } | |
24209 | ||
24210 | /* The link register can be clobbered by any branch insn, | |
24211 | but we have no way to track that at present, so mark | |
24212 | it as unavailable. */ | |
24213 | if (TARGET_THUMB1) | |
24214 | fixed_regs[LR_REGNUM] = call_used_regs[LR_REGNUM] = 1; | |
24215 | ||
24216 | if (TARGET_32BIT && TARGET_HARD_FLOAT) | |
24217 | { | |
24218 | if (TARGET_MAVERICK) | |
24219 | { | |
24220 | for (regno = FIRST_FPA_REGNUM; | |
24221 | regno <= LAST_FPA_REGNUM; ++ regno) | |
24222 | fixed_regs[regno] = call_used_regs[regno] = 1; | |
24223 | for (regno = FIRST_CIRRUS_FP_REGNUM; | |
24224 | regno <= LAST_CIRRUS_FP_REGNUM; ++ regno) | |
24225 | { | |
24226 | fixed_regs[regno] = 0; | |
24227 | call_used_regs[regno] = regno < FIRST_CIRRUS_FP_REGNUM + 4; | |
24228 | } | |
24229 | } | |
24230 | if (TARGET_VFP) | |
24231 | { | |
24232 | /* VFPv3 registers are disabled when earlier VFP | |
24233 | versions are selected due to the definition of | |
24234 | LAST_VFP_REGNUM. */ | |
24235 | for (regno = FIRST_VFP_REGNUM; | |
24236 | regno <= LAST_VFP_REGNUM; ++ regno) | |
24237 | { | |
24238 | fixed_regs[regno] = 0; | |
24239 | call_used_regs[regno] = regno < FIRST_VFP_REGNUM + 16 | |
24240 | || regno >= FIRST_VFP_REGNUM + 32; | |
24241 | } | |
24242 | } | |
24243 | } | |
24244 | ||
24245 | if (TARGET_REALLY_IWMMXT) | |
24246 | { | |
24247 | regno = FIRST_IWMMXT_GR_REGNUM; | |
24248 | /* The 2002/10/09 revision of the XScale ABI has wCG0 | |
24249 | and wCG1 as call-preserved registers. The 2002/11/21 | |
24250 | revision changed this so that all wCG registers are | |
24251 | scratch registers. */ | |
24252 | for (regno = FIRST_IWMMXT_GR_REGNUM; | |
24253 | regno <= LAST_IWMMXT_GR_REGNUM; ++ regno) | |
24254 | fixed_regs[regno] = 0; | |
24255 | /* The XScale ABI has wR0 - wR9 as scratch registers, | |
24256 | the rest as call-preserved registers. */ | |
24257 | for (regno = FIRST_IWMMXT_REGNUM; | |
24258 | regno <= LAST_IWMMXT_REGNUM; ++ regno) | |
24259 | { | |
24260 | fixed_regs[regno] = 0; | |
24261 | call_used_regs[regno] = regno < FIRST_IWMMXT_REGNUM + 10; | |
24262 | } | |
24263 | } | |
24264 | ||
24265 | if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM) | |
24266 | { | |
24267 | fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1; | |
24268 | call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1; | |
24269 | } | |
24270 | else if (TARGET_APCS_STACK) | |
24271 | { | |
24272 | fixed_regs[10] = 1; | |
24273 | call_used_regs[10] = 1; | |
24274 | } | |
24275 | /* -mcaller-super-interworking reserves r11 for calls to | |
24276 | _interwork_r11_call_via_rN(). Making the register global | |
24277 | is an easy way of ensuring that it remains valid for all | |
24278 | calls. */ | |
24279 | if (TARGET_APCS_FRAME || TARGET_CALLER_INTERWORKING | |
24280 | || TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) | |
24281 | { | |
24282 | fixed_regs[ARM_HARD_FRAME_POINTER_REGNUM] = 1; | |
24283 | call_used_regs[ARM_HARD_FRAME_POINTER_REGNUM] = 1; | |
24284 | if (TARGET_CALLER_INTERWORKING) | |
24285 | global_regs[ARM_HARD_FRAME_POINTER_REGNUM] = 1; | |
24286 | } | |
24287 | SUBTARGET_CONDITIONAL_REGISTER_USAGE | |
24288 | } | |
24289 | ||
74e32076 | 24290 | static reg_class_t |
6d3fbe2f | 24291 | arm_preferred_rename_class (reg_class_t rclass) |
74e32076 YQ |
24292 | { |
24293 | /* Thumb-2 instructions using LO_REGS may be smaller than instructions | |
24294 | using GENERIC_REGS. During register rename pass, we prefer LO_REGS, | |
24295 | and code size can be reduced. */ | |
6d3fbe2f | 24296 | if (TARGET_THUMB2 && rclass == GENERAL_REGS) |
74e32076 YQ |
24297 | return LO_REGS; |
24298 | else | |
24299 | return NO_REGS; | |
24300 | } | |
24301 | ||
0c27e2d8 WG |
24302 | /* Compute the atrribute "length" of insn "*push_multi". |
24303 | So this function MUST be kept in sync with that insn pattern. */ | |
24304 | int | |
24305 | arm_attr_length_push_multi(rtx parallel_op, rtx first_op) | |
24306 | { | |
24307 | int i, regno, hi_reg; | |
24308 | int num_saves = XVECLEN (parallel_op, 0); | |
24309 | ||
24310 | /* ARM mode. */ | |
24311 | if (TARGET_ARM) | |
24312 | return 4; | |
d018b46e RH |
24313 | /* Thumb1 mode. */ |
24314 | if (TARGET_THUMB1) | |
24315 | return 2; | |
0c27e2d8 WG |
24316 | |
24317 | /* Thumb2 mode. */ | |
24318 | regno = REGNO (first_op); | |
24319 | hi_reg = (REGNO_REG_CLASS (regno) == HI_REGS) && (regno != LR_REGNUM); | |
24320 | for (i = 1; i < num_saves && !hi_reg; i++) | |
24321 | { | |
24322 | regno = REGNO (XEXP (XVECEXP (parallel_op, 0, i), 0)); | |
24323 | hi_reg |= (REGNO_REG_CLASS (regno) == HI_REGS) && (regno != LR_REGNUM); | |
24324 | } | |
24325 | ||
24326 | if (!hi_reg) | |
24327 | return 2; | |
24328 | return 4; | |
24329 | } | |
24330 | ||
3598da80 RR |
24331 | /* Compute the number of instructions emitted by output_move_double. */ |
24332 | int | |
24333 | arm_count_output_move_double_insns (rtx *operands) | |
24334 | { | |
24335 | int count; | |
24336 | output_move_double (operands, false, &count); | |
24337 | return count; | |
24338 | } | |
24339 | ||
d3585b76 | 24340 | #include "gt-arm.h" |