]>
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, |
d8d55ac0 | 3 | 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
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" |
ad076f4e | 44 | #include "toplev.h" |
aec3cfba | 45 | #include "recog.h" |
390b17c2 | 46 | #include "cgraph.h" |
92a432f4 | 47 | #include "ggc.h" |
d5b7b3ae | 48 | #include "except.h" |
39dabefd | 49 | #include "c-family/c-pragma.h" /* ??? */ |
7b8b8ade | 50 | #include "integrate.h" |
c27ba912 | 51 | #include "tm_p.h" |
672a6f42 NB |
52 | #include "target.h" |
53 | #include "target-def.h" | |
980e61bb | 54 | #include "debug.h" |
6e34d3a3 | 55 | #include "langhooks.h" |
6fb5fa3c | 56 | #include "df.h" |
0fd8c3ad | 57 | #include "intl.h" |
353a58f7 | 58 | #include "libfuncs.h" |
ec3728ad | 59 | #include "params.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. */ |
35596784 | 68 | static int arm_compute_static_chain_stack_bytes (void); |
5848830f | 69 | static arm_stack_offsets *arm_get_frame_offsets (void); |
e32bac5b | 70 | static void arm_add_gc_roots (void); |
a406f566 MM |
71 | static int arm_gen_constant (enum rtx_code, enum machine_mode, rtx, |
72 | HOST_WIDE_INT, rtx, rtx, int, int); | |
e32bac5b RE |
73 | static unsigned bit_count (unsigned long); |
74 | static int arm_address_register_rtx_p (rtx, int); | |
1e1ab407 | 75 | static int arm_legitimate_index_p (enum machine_mode, rtx, RTX_CODE, int); |
5b3e6663 PB |
76 | static int thumb2_legitimate_index_p (enum machine_mode, rtx, int); |
77 | static int thumb1_base_register_rtx_p (rtx, enum machine_mode, int); | |
506d7b68 PB |
78 | static rtx arm_legitimize_address (rtx, rtx, enum machine_mode); |
79 | static rtx thumb_legitimize_address (rtx, rtx, enum machine_mode); | |
5b3e6663 | 80 | inline static int thumb1_index_register_rtx_p (rtx, int); |
c6c3dba9 | 81 | static bool arm_legitimate_address_p (enum machine_mode, rtx, bool); |
5848830f | 82 | static int thumb_far_jump_used_p (void); |
57934c39 | 83 | static bool thumb_force_lr_save (void); |
e32bac5b | 84 | static int const_ok_for_op (HOST_WIDE_INT, enum rtx_code); |
e32bac5b | 85 | static rtx emit_sfm (int, int); |
466e4b7a | 86 | static unsigned arm_size_return_regs (void); |
e32bac5b | 87 | static bool arm_assemble_integer (rtx, unsigned int, int); |
944442bb NF |
88 | static void arm_print_operand (FILE *, rtx, int); |
89 | static void arm_print_operand_address (FILE *, rtx); | |
90 | static bool arm_print_operand_punct_valid_p (unsigned char code); | |
e32bac5b RE |
91 | static const char *fp_const_from_val (REAL_VALUE_TYPE *); |
92 | static arm_cc get_arm_condition_code (rtx); | |
e32bac5b RE |
93 | static HOST_WIDE_INT int_log2 (HOST_WIDE_INT); |
94 | static rtx is_jump_table (rtx); | |
95 | static const char *output_multi_immediate (rtx *, const char *, const char *, | |
96 | int, HOST_WIDE_INT); | |
e32bac5b RE |
97 | static const char *shift_op (rtx, HOST_WIDE_INT *); |
98 | static struct machine_function *arm_init_machine_status (void); | |
c9ca9b88 | 99 | static void thumb_exit (FILE *, int); |
e32bac5b RE |
100 | static rtx is_jump_table (rtx); |
101 | static HOST_WIDE_INT get_jump_table_size (rtx); | |
102 | static Mnode *move_minipool_fix_forward_ref (Mnode *, Mnode *, HOST_WIDE_INT); | |
103 | static Mnode *add_minipool_forward_ref (Mfix *); | |
104 | static Mnode *move_minipool_fix_backward_ref (Mnode *, Mnode *, HOST_WIDE_INT); | |
105 | static Mnode *add_minipool_backward_ref (Mfix *); | |
106 | static void assign_minipool_offsets (Mfix *); | |
107 | static void arm_print_value (FILE *, rtx); | |
108 | static void dump_minipool (rtx); | |
109 | static int arm_barrier_cost (rtx); | |
110 | static Mfix *create_fix_barrier (Mfix *, HOST_WIDE_INT); | |
111 | static void push_minipool_barrier (rtx, HOST_WIDE_INT); | |
112 | static void push_minipool_fix (rtx, HOST_WIDE_INT, rtx *, enum machine_mode, | |
113 | rtx); | |
114 | static void arm_reorg (void); | |
115 | static bool note_invalid_constants (rtx, HOST_WIDE_INT, int); | |
e32bac5b RE |
116 | static unsigned long arm_compute_save_reg0_reg12_mask (void); |
117 | static unsigned long arm_compute_save_reg_mask (void); | |
118 | static unsigned long arm_isr_value (tree); | |
119 | static unsigned long arm_compute_func_type (void); | |
120 | static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *); | |
390b17c2 | 121 | static tree arm_handle_pcs_attribute (tree *, tree, tree, int, bool *); |
e32bac5b | 122 | static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *); |
7bff66a7 | 123 | #if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
04fb56d5 | 124 | static tree arm_handle_notshared_attribute (tree *, tree, tree, int, bool *); |
7bff66a7 | 125 | #endif |
e32bac5b RE |
126 | static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT); |
127 | static void arm_output_function_prologue (FILE *, HOST_WIDE_INT); | |
5b3e6663 | 128 | static void thumb1_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); |
d5a0a47b RE |
146 | static bool arm_rtx_costs_1 (rtx, enum rtx_code, int*, bool); |
147 | static bool arm_size_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *); | |
148 | static bool arm_slowmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool); | |
149 | static bool arm_fastmul_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool); | |
150 | static bool arm_xscale_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool); | |
151 | static bool arm_9e_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool); | |
f40751dd JH |
152 | static bool arm_rtx_costs (rtx, int, int, int *, bool); |
153 | static int arm_address_cost (rtx, bool); | |
e32bac5b RE |
154 | static bool arm_memory_load_p (rtx); |
155 | static bool arm_cirrus_insn_p (rtx); | |
156 | static void cirrus_reorg (rtx); | |
5a9335ef | 157 | static void arm_init_builtins (void); |
5a9335ef NC |
158 | static void arm_init_iwmmxt_builtins (void); |
159 | static rtx safe_vector_operand (rtx, enum machine_mode); | |
160 | static rtx arm_expand_binop_builtin (enum insn_code, tree, rtx); | |
161 | static rtx arm_expand_unop_builtin (enum insn_code, tree, rtx, int); | |
162 | static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int); | |
a406f566 | 163 | static void emit_constant_insn (rtx cond, rtx pattern); |
d66437c5 | 164 | static rtx emit_set_insn (rtx, rtx); |
78a52f11 RH |
165 | static int arm_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode, |
166 | tree, bool); | |
9c6a2bee NF |
167 | static rtx arm_function_arg (CUMULATIVE_ARGS *, enum machine_mode, |
168 | const_tree, bool); | |
169 | static void arm_function_arg_advance (CUMULATIVE_ARGS *, enum machine_mode, | |
170 | const_tree, bool); | |
390b17c2 RE |
171 | static rtx aapcs_allocate_return_reg (enum machine_mode, const_tree, |
172 | const_tree); | |
173 | static int aapcs_select_return_coproc (const_tree, const_tree); | |
5a9335ef | 174 | |
7abc66b1 | 175 | #ifdef OBJECT_FORMAT_ELF |
9403b7f7 RS |
176 | static void arm_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED; |
177 | static void arm_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED; | |
7abc66b1 | 178 | #endif |
fb49053f | 179 | #ifndef ARM_PE |
e32bac5b | 180 | static void arm_encode_section_info (tree, rtx, int); |
fb49053f | 181 | #endif |
b12a00f1 RE |
182 | |
183 | static void arm_file_end (void); | |
6c6aa1af | 184 | static void arm_file_start (void); |
b12a00f1 | 185 | |
1cc9f5f5 KH |
186 | static void arm_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode, |
187 | tree, int *, int); | |
8cd5a4e0 | 188 | static bool arm_pass_by_reference (CUMULATIVE_ARGS *, |
586de218 KG |
189 | enum machine_mode, const_tree, bool); |
190 | static bool arm_promote_prototypes (const_tree); | |
6b045785 | 191 | static bool arm_default_short_enums (void); |
13c1cd82 | 192 | static bool arm_align_anon_bitfield (void); |
586de218 KG |
193 | static bool arm_return_in_msb (const_tree); |
194 | static bool arm_must_pass_in_stack (enum machine_mode, const_tree); | |
23668cf7 | 195 | static bool arm_return_in_memory (const_tree, const_tree); |
f0a0390e | 196 | #if ARM_UNWIND_INFO |
617a1b71 PB |
197 | static void arm_unwind_emit (FILE *, rtx); |
198 | static bool arm_output_ttype (rtx); | |
a68b5e52 RH |
199 | static void arm_asm_emit_except_personality (rtx); |
200 | static void arm_asm_init_sections (void); | |
617a1b71 | 201 | #endif |
f0a0390e | 202 | static enum unwind_info_type arm_except_unwind_info (void); |
5b3e6663 | 203 | static void arm_dwarf_handle_frame_unspec (const char *, rtx, int); |
854b8a40 | 204 | static rtx arm_dwarf_register_span (rtx); |
c237e94a | 205 | |
4185ae53 PB |
206 | static tree arm_cxx_guard_type (void); |
207 | static bool arm_cxx_guard_mask_bit (void); | |
46e995e0 PB |
208 | static tree arm_get_cookie_size (tree); |
209 | static bool arm_cookie_has_size (void); | |
44d10c10 | 210 | static bool arm_cxx_cdtor_returns_this (void); |
505970fc | 211 | static bool arm_cxx_key_method_may_be_inline (void); |
1e731102 MM |
212 | static void arm_cxx_determine_class_data_visibility (tree); |
213 | static bool arm_cxx_class_data_always_comdat (void); | |
9f62c3e3 | 214 | static bool arm_cxx_use_aeabi_atexit (void); |
b3f8d95d | 215 | static void arm_init_libfuncs (void); |
07d8efe3 MM |
216 | static tree arm_build_builtin_va_list (void); |
217 | static void arm_expand_builtin_va_start (tree, rtx); | |
ae46a823 | 218 | static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *); |
c5387660 | 219 | static void arm_option_override (void); |
c54c7322 | 220 | static bool arm_handle_option (size_t, const char *, int); |
67e6ba46 | 221 | static void arm_target_help (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 *); | |
cc4b5170 | 242 | static enum machine_mode arm_preferred_simd_mode (enum machine_mode); |
d163e655 | 243 | static bool arm_class_likely_spilled_p (reg_class_t); |
c452684d JB |
244 | static bool arm_vector_alignment_reachable (const_tree type, bool is_packed); |
245 | static bool arm_builtin_support_vector_misalignment (enum machine_mode mode, | |
246 | const_tree type, | |
247 | int misalignment, | |
248 | bool is_packed); | |
b52b1749 | 249 | |
5a82ecd9 ILT |
250 | \f |
251 | /* Table of machine attributes. */ | |
252 | static const struct attribute_spec arm_attribute_table[] = | |
253 | { | |
254 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ | |
255 | /* Function calls made to this symbol must be done indirectly, because | |
256 | it may lie outside of the 26 bit addressing range of a normal function | |
257 | call. */ | |
258 | { "long_call", 0, 0, false, true, true, NULL }, | |
259 | /* Whereas these functions are always known to reside within the 26 bit | |
260 | addressing range. */ | |
261 | { "short_call", 0, 0, false, true, true, NULL }, | |
390b17c2 RE |
262 | /* Specify the procedure call conventions for a function. */ |
263 | { "pcs", 1, 1, false, true, true, arm_handle_pcs_attribute }, | |
5a82ecd9 ILT |
264 | /* Interrupt Service Routines have special prologue and epilogue requirements. */ |
265 | { "isr", 0, 1, false, false, false, arm_handle_isr_attribute }, | |
266 | { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute }, | |
267 | { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute }, | |
268 | #ifdef ARM_PE | |
269 | /* ARM/PE has three new attributes: | |
270 | interfacearm - ? | |
271 | dllexport - for exporting a function/variable that will live in a dll | |
272 | dllimport - for importing a function/variable from a dll | |
d3585b76 | 273 | |
5a82ecd9 ILT |
274 | Microsoft allows multiple declspecs in one __declspec, separating |
275 | them with spaces. We do NOT support this. Instead, use __declspec | |
276 | multiple times. | |
277 | */ | |
278 | { "dllimport", 0, 0, true, false, false, NULL }, | |
279 | { "dllexport", 0, 0, true, false, false, NULL }, | |
280 | { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute }, | |
281 | #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES | |
282 | { "dllimport", 0, 0, false, false, false, handle_dll_attribute }, | |
283 | { "dllexport", 0, 0, false, false, false, handle_dll_attribute }, | |
284 | { "notshared", 0, 0, false, true, false, arm_handle_notshared_attribute }, | |
285 | #endif | |
286 | { NULL, 0, 0, false, false, false, NULL } | |
287 | }; | |
3020190e JM |
288 | |
289 | /* Set default optimization options. */ | |
290 | static const struct default_options arm_option_optimization_table[] = | |
291 | { | |
292 | /* Enable section anchors by default at -O1 or higher. */ | |
293 | { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 }, | |
294 | { OPT_LEVELS_1_PLUS, OPT_fomit_frame_pointer, NULL, 1 }, | |
295 | { OPT_LEVELS_NONE, 0, NULL, 0 } | |
296 | }; | |
672a6f42 NB |
297 | \f |
298 | /* Initialize the GCC target structure. */ | |
b2ca3702 | 299 | #if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
1d6e90ac | 300 | #undef TARGET_MERGE_DECL_ATTRIBUTES |
672a6f42 NB |
301 | #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes |
302 | #endif | |
f3bb6135 | 303 | |
506d7b68 PB |
304 | #undef TARGET_LEGITIMIZE_ADDRESS |
305 | #define TARGET_LEGITIMIZE_ADDRESS arm_legitimize_address | |
306 | ||
1d6e90ac | 307 | #undef TARGET_ATTRIBUTE_TABLE |
91d231cb | 308 | #define TARGET_ATTRIBUTE_TABLE arm_attribute_table |
672a6f42 | 309 | |
6c6aa1af PB |
310 | #undef TARGET_ASM_FILE_START |
311 | #define TARGET_ASM_FILE_START arm_file_start | |
b12a00f1 RE |
312 | #undef TARGET_ASM_FILE_END |
313 | #define TARGET_ASM_FILE_END arm_file_end | |
314 | ||
1d6e90ac | 315 | #undef TARGET_ASM_ALIGNED_SI_OP |
301d03af | 316 | #define TARGET_ASM_ALIGNED_SI_OP NULL |
1d6e90ac | 317 | #undef TARGET_ASM_INTEGER |
301d03af | 318 | #define TARGET_ASM_INTEGER arm_assemble_integer |
301d03af | 319 | |
944442bb NF |
320 | #undef TARGET_PRINT_OPERAND |
321 | #define TARGET_PRINT_OPERAND arm_print_operand | |
322 | #undef TARGET_PRINT_OPERAND_ADDRESS | |
323 | #define TARGET_PRINT_OPERAND_ADDRESS arm_print_operand_address | |
324 | #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P | |
325 | #define TARGET_PRINT_OPERAND_PUNCT_VALID_P arm_print_operand_punct_valid_p | |
326 | ||
ffda8a0d AS |
327 | #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA |
328 | #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA arm_output_addr_const_extra | |
329 | ||
1d6e90ac | 330 | #undef TARGET_ASM_FUNCTION_PROLOGUE |
08c148a8 NB |
331 | #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue |
332 | ||
1d6e90ac | 333 | #undef TARGET_ASM_FUNCTION_EPILOGUE |
08c148a8 NB |
334 | #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue |
335 | ||
c54c7322 RS |
336 | #undef TARGET_DEFAULT_TARGET_FLAGS |
337 | #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_SCHED_PROLOG) | |
338 | #undef TARGET_HANDLE_OPTION | |
339 | #define TARGET_HANDLE_OPTION arm_handle_option | |
67e6ba46 NC |
340 | #undef TARGET_HELP |
341 | #define TARGET_HELP arm_target_help | |
c5387660 JM |
342 | #undef TARGET_OPTION_OVERRIDE |
343 | #define TARGET_OPTION_OVERRIDE arm_option_override | |
3020190e JM |
344 | #undef TARGET_OPTION_OPTIMIZATION_TABLE |
345 | #define TARGET_OPTION_OPTIMIZATION_TABLE arm_option_optimization_table | |
c54c7322 | 346 | |
1d6e90ac | 347 | #undef TARGET_COMP_TYPE_ATTRIBUTES |
8d8e52be JM |
348 | #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes |
349 | ||
1d6e90ac | 350 | #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES |
8d8e52be JM |
351 | #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes |
352 | ||
1d6e90ac | 353 | #undef TARGET_SCHED_ADJUST_COST |
c237e94a ZW |
354 | #define TARGET_SCHED_ADJUST_COST arm_adjust_cost |
355 | ||
fb49053f RH |
356 | #undef TARGET_ENCODE_SECTION_INFO |
357 | #ifdef ARM_PE | |
358 | #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info | |
359 | #else | |
360 | #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info | |
361 | #endif | |
362 | ||
5a9335ef | 363 | #undef TARGET_STRIP_NAME_ENCODING |
772c5265 RH |
364 | #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding |
365 | ||
5a9335ef | 366 | #undef TARGET_ASM_INTERNAL_LABEL |
4977bab6 ZW |
367 | #define TARGET_ASM_INTERNAL_LABEL arm_internal_label |
368 | ||
5a9335ef | 369 | #undef TARGET_FUNCTION_OK_FOR_SIBCALL |
4977bab6 ZW |
370 | #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall |
371 | ||
390b17c2 RE |
372 | #undef TARGET_FUNCTION_VALUE |
373 | #define TARGET_FUNCTION_VALUE arm_function_value | |
374 | ||
375 | #undef TARGET_LIBCALL_VALUE | |
376 | #define TARGET_LIBCALL_VALUE arm_libcall_value | |
377 | ||
5a9335ef | 378 | #undef TARGET_ASM_OUTPUT_MI_THUNK |
c590b625 | 379 | #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk |
5a9335ef | 380 | #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK |
3961e8fe | 381 | #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall |
c590b625 | 382 | |
5a9335ef | 383 | #undef TARGET_RTX_COSTS |
f40751dd | 384 | #define TARGET_RTX_COSTS arm_rtx_costs |
5a9335ef | 385 | #undef TARGET_ADDRESS_COST |
dcefdf67 | 386 | #define TARGET_ADDRESS_COST arm_address_cost |
3c50106f | 387 | |
273a2526 RS |
388 | #undef TARGET_SHIFT_TRUNCATION_MASK |
389 | #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask | |
f676971a EC |
390 | #undef TARGET_VECTOR_MODE_SUPPORTED_P |
391 | #define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p | |
cc4b5170 RG |
392 | #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE |
393 | #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE arm_preferred_simd_mode | |
f676971a | 394 | |
5a9335ef | 395 | #undef TARGET_MACHINE_DEPENDENT_REORG |
18dbd950 RS |
396 | #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg |
397 | ||
5a9335ef NC |
398 | #undef TARGET_INIT_BUILTINS |
399 | #define TARGET_INIT_BUILTINS arm_init_builtins | |
400 | #undef TARGET_EXPAND_BUILTIN | |
401 | #define TARGET_EXPAND_BUILTIN arm_expand_builtin | |
402 | ||
b3f8d95d MM |
403 | #undef TARGET_INIT_LIBFUNCS |
404 | #define TARGET_INIT_LIBFUNCS arm_init_libfuncs | |
405 | ||
cde0f3fd PB |
406 | #undef TARGET_PROMOTE_FUNCTION_MODE |
407 | #define TARGET_PROMOTE_FUNCTION_MODE arm_promote_function_mode | |
f9ba5949 | 408 | #undef TARGET_PROMOTE_PROTOTYPES |
70301b45 | 409 | #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes |
8cd5a4e0 RH |
410 | #undef TARGET_PASS_BY_REFERENCE |
411 | #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference | |
78a52f11 RH |
412 | #undef TARGET_ARG_PARTIAL_BYTES |
413 | #define TARGET_ARG_PARTIAL_BYTES arm_arg_partial_bytes | |
9c6a2bee NF |
414 | #undef TARGET_FUNCTION_ARG |
415 | #define TARGET_FUNCTION_ARG arm_function_arg | |
416 | #undef TARGET_FUNCTION_ARG_ADVANCE | |
417 | #define TARGET_FUNCTION_ARG_ADVANCE arm_function_arg_advance | |
f9ba5949 | 418 | |
1cc9f5f5 KH |
419 | #undef TARGET_SETUP_INCOMING_VARARGS |
420 | #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs | |
421 | ||
007e61c2 PB |
422 | #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS |
423 | #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args | |
424 | ||
0ef9304b RH |
425 | #undef TARGET_ASM_TRAMPOLINE_TEMPLATE |
426 | #define TARGET_ASM_TRAMPOLINE_TEMPLATE arm_asm_trampoline_template | |
427 | #undef TARGET_TRAMPOLINE_INIT | |
428 | #define TARGET_TRAMPOLINE_INIT arm_trampoline_init | |
429 | #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS | |
430 | #define TARGET_TRAMPOLINE_ADJUST_ADDRESS arm_trampoline_adjust_address | |
431 | ||
6b045785 PB |
432 | #undef TARGET_DEFAULT_SHORT_ENUMS |
433 | #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums | |
434 | ||
13c1cd82 PB |
435 | #undef TARGET_ALIGN_ANON_BITFIELD |
436 | #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield | |
437 | ||
c2a64439 PB |
438 | #undef TARGET_NARROW_VOLATILE_BITFIELD |
439 | #define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false | |
440 | ||
4185ae53 PB |
441 | #undef TARGET_CXX_GUARD_TYPE |
442 | #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type | |
443 | ||
444 | #undef TARGET_CXX_GUARD_MASK_BIT | |
445 | #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit | |
446 | ||
46e995e0 PB |
447 | #undef TARGET_CXX_GET_COOKIE_SIZE |
448 | #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size | |
449 | ||
450 | #undef TARGET_CXX_COOKIE_HAS_SIZE | |
451 | #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size | |
452 | ||
44d10c10 PB |
453 | #undef TARGET_CXX_CDTOR_RETURNS_THIS |
454 | #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this | |
455 | ||
505970fc MM |
456 | #undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE |
457 | #define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline | |
458 | ||
9f62c3e3 PB |
459 | #undef TARGET_CXX_USE_AEABI_ATEXIT |
460 | #define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit | |
461 | ||
1e731102 MM |
462 | #undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY |
463 | #define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \ | |
464 | arm_cxx_determine_class_data_visibility | |
465 | ||
466 | #undef TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT | |
467 | #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT arm_cxx_class_data_always_comdat | |
505970fc | 468 | |
866af8a9 JB |
469 | #undef TARGET_RETURN_IN_MSB |
470 | #define TARGET_RETURN_IN_MSB arm_return_in_msb | |
471 | ||
23668cf7 CLT |
472 | #undef TARGET_RETURN_IN_MEMORY |
473 | #define TARGET_RETURN_IN_MEMORY arm_return_in_memory | |
474 | ||
866af8a9 JB |
475 | #undef TARGET_MUST_PASS_IN_STACK |
476 | #define TARGET_MUST_PASS_IN_STACK arm_must_pass_in_stack | |
477 | ||
f0a0390e | 478 | #if ARM_UNWIND_INFO |
38f8b050 JR |
479 | #undef TARGET_ASM_UNWIND_EMIT |
480 | #define TARGET_ASM_UNWIND_EMIT arm_unwind_emit | |
617a1b71 PB |
481 | |
482 | /* EABI unwinding tables use a different format for the typeinfo tables. */ | |
483 | #undef TARGET_ASM_TTYPE | |
484 | #define TARGET_ASM_TTYPE arm_output_ttype | |
485 | ||
486 | #undef TARGET_ARM_EABI_UNWINDER | |
487 | #define TARGET_ARM_EABI_UNWINDER true | |
a68b5e52 RH |
488 | |
489 | #undef TARGET_ASM_EMIT_EXCEPT_PERSONALITY | |
490 | #define TARGET_ASM_EMIT_EXCEPT_PERSONALITY arm_asm_emit_except_personality | |
491 | ||
492 | #undef TARGET_ASM_INIT_SECTIONS | |
493 | #define TARGET_ASM_INIT_SECTIONS arm_asm_init_sections | |
f0a0390e RH |
494 | #endif /* ARM_UNWIND_INFO */ |
495 | ||
496 | #undef TARGET_EXCEPT_UNWIND_INFO | |
497 | #define TARGET_EXCEPT_UNWIND_INFO arm_except_unwind_info | |
617a1b71 | 498 | |
5b3e6663 PB |
499 | #undef TARGET_DWARF_HANDLE_FRAME_UNSPEC |
500 | #define TARGET_DWARF_HANDLE_FRAME_UNSPEC arm_dwarf_handle_frame_unspec | |
501 | ||
854b8a40 JB |
502 | #undef TARGET_DWARF_REGISTER_SPAN |
503 | #define TARGET_DWARF_REGISTER_SPAN arm_dwarf_register_span | |
504 | ||
d3585b76 DJ |
505 | #undef TARGET_CANNOT_COPY_INSN_P |
506 | #define TARGET_CANNOT_COPY_INSN_P arm_cannot_copy_insn_p | |
507 | ||
508 | #ifdef HAVE_AS_TLS | |
509 | #undef TARGET_HAVE_TLS | |
510 | #define TARGET_HAVE_TLS true | |
511 | #endif | |
512 | ||
2929029c WG |
513 | #undef TARGET_HAVE_CONDITIONAL_EXECUTION |
514 | #define TARGET_HAVE_CONDITIONAL_EXECUTION arm_have_conditional_execution | |
515 | ||
d3585b76 | 516 | #undef TARGET_CANNOT_FORCE_CONST_MEM |
8426b956 | 517 | #define TARGET_CANNOT_FORCE_CONST_MEM arm_cannot_force_const_mem |
d3585b76 | 518 | |
f67358da PB |
519 | #undef TARGET_MAX_ANCHOR_OFFSET |
520 | #define TARGET_MAX_ANCHOR_OFFSET 4095 | |
521 | ||
522 | /* The minimum is set such that the total size of the block | |
523 | for a particular anchor is -4088 + 1 + 4095 bytes, which is | |
524 | divisible by eight, ensuring natural spacing of anchors. */ | |
525 | #undef TARGET_MIN_ANCHOR_OFFSET | |
526 | #define TARGET_MIN_ANCHOR_OFFSET -4088 | |
527 | ||
bd4dc3cd PB |
528 | #undef TARGET_SCHED_ISSUE_RATE |
529 | #define TARGET_SCHED_ISSUE_RATE arm_issue_rate | |
530 | ||
608063c3 JB |
531 | #undef TARGET_MANGLE_TYPE |
532 | #define TARGET_MANGLE_TYPE arm_mangle_type | |
533 | ||
07d8efe3 MM |
534 | #undef TARGET_BUILD_BUILTIN_VA_LIST |
535 | #define TARGET_BUILD_BUILTIN_VA_LIST arm_build_builtin_va_list | |
536 | #undef TARGET_EXPAND_BUILTIN_VA_START | |
537 | #define TARGET_EXPAND_BUILTIN_VA_START arm_expand_builtin_va_start | |
538 | #undef TARGET_GIMPLIFY_VA_ARG_EXPR | |
539 | #define TARGET_GIMPLIFY_VA_ARG_EXPR arm_gimplify_va_arg_expr | |
540 | ||
afcc986d JM |
541 | #ifdef HAVE_AS_TLS |
542 | #undef TARGET_ASM_OUTPUT_DWARF_DTPREL | |
543 | #define TARGET_ASM_OUTPUT_DWARF_DTPREL arm_output_dwarf_dtprel | |
544 | #endif | |
545 | ||
c6c3dba9 PB |
546 | #undef TARGET_LEGITIMATE_ADDRESS_P |
547 | #define TARGET_LEGITIMATE_ADDRESS_P arm_legitimate_address_p | |
548 | ||
0fd8c3ad SL |
549 | #undef TARGET_INVALID_PARAMETER_TYPE |
550 | #define TARGET_INVALID_PARAMETER_TYPE arm_invalid_parameter_type | |
551 | ||
552 | #undef TARGET_INVALID_RETURN_TYPE | |
553 | #define TARGET_INVALID_RETURN_TYPE arm_invalid_return_type | |
554 | ||
555 | #undef TARGET_PROMOTED_TYPE | |
556 | #define TARGET_PROMOTED_TYPE arm_promoted_type | |
557 | ||
558 | #undef TARGET_CONVERT_TO_TYPE | |
559 | #define TARGET_CONVERT_TO_TYPE arm_convert_to_type | |
560 | ||
bdc4827b SL |
561 | #undef TARGET_SCALAR_MODE_SUPPORTED_P |
562 | #define TARGET_SCALAR_MODE_SUPPORTED_P arm_scalar_mode_supported_p | |
563 | ||
b52b1749 AS |
564 | #undef TARGET_FRAME_POINTER_REQUIRED |
565 | #define TARGET_FRAME_POINTER_REQUIRED arm_frame_pointer_required | |
566 | ||
7b5cbb57 AS |
567 | #undef TARGET_CAN_ELIMINATE |
568 | #define TARGET_CAN_ELIMINATE arm_can_eliminate | |
569 | ||
d163e655 AS |
570 | #undef TARGET_CLASS_LIKELY_SPILLED_P |
571 | #define TARGET_CLASS_LIKELY_SPILLED_P arm_class_likely_spilled_p | |
572 | ||
c452684d JB |
573 | #undef TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE |
574 | #define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE \ | |
575 | arm_vector_alignment_reachable | |
576 | ||
577 | #undef TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT | |
578 | #define TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT \ | |
579 | arm_builtin_support_vector_misalignment | |
580 | ||
f6897b10 | 581 | struct gcc_target targetm = TARGET_INITIALIZER; |
672a6f42 | 582 | \f |
c7319d87 RE |
583 | /* Obstack for minipool constant handling. */ |
584 | static struct obstack minipool_obstack; | |
1d6e90ac | 585 | static char * minipool_startobj; |
c7319d87 | 586 | |
1d6e90ac NC |
587 | /* The maximum number of insns skipped which |
588 | will be conditionalised if possible. */ | |
c27ba912 DM |
589 | static int max_insns_skipped = 5; |
590 | ||
591 | extern FILE * asm_out_file; | |
592 | ||
6354dc9b | 593 | /* True if we are currently building a constant table. */ |
13bd191d PB |
594 | int making_const_table; |
595 | ||
9b66ebb1 PB |
596 | /* The processor for which instructions should be scheduled. */ |
597 | enum processor_type arm_tune = arm_none; | |
598 | ||
1b78f575 RE |
599 | /* The current tuning set. */ |
600 | const struct tune_params *current_tune; | |
601 | ||
9b66ebb1 | 602 | /* Which floating point hardware to schedule for. */ |
d79f3032 PB |
603 | int arm_fpu_attr; |
604 | ||
605 | /* Which floating popint hardware to use. */ | |
606 | const struct arm_fpu_desc *arm_fpu_desc; | |
9b66ebb1 PB |
607 | |
608 | /* Whether to use floating point hardware. */ | |
609 | enum float_abi_type arm_float_abi; | |
610 | ||
0fd8c3ad SL |
611 | /* Which __fp16 format to use. */ |
612 | enum arm_fp16_format_type arm_fp16_format; | |
613 | ||
5848830f PB |
614 | /* Which ABI to use. */ |
615 | enum arm_abi_type arm_abi; | |
616 | ||
d3585b76 DJ |
617 | /* Which thread pointer model to use. */ |
618 | enum arm_tp_type target_thread_pointer = TP_AUTO; | |
619 | ||
b355a481 | 620 | /* Used to parse -mstructure_size_boundary command line option. */ |
723ae7c1 | 621 | int arm_structure_size_boundary = DEFAULT_STRUCTURE_SIZE_BOUNDARY; |
b355a481 | 622 | |
b12a00f1 | 623 | /* Used for Thumb call_via trampolines. */ |
57ecec57 | 624 | rtx thumb_call_via_label[14]; |
b12a00f1 RE |
625 | static int thumb_call_reg_needed; |
626 | ||
aec3cfba | 627 | /* Bit values used to identify processor capabilities. */ |
62b10bbc | 628 | #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */ |
9b66ebb1 | 629 | #define FL_ARCH3M (1 << 1) /* Extended multiply */ |
62b10bbc NC |
630 | #define FL_MODE26 (1 << 2) /* 26-bit mode support */ |
631 | #define FL_MODE32 (1 << 3) /* 32-bit mode support */ | |
632 | #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */ | |
633 | #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */ | |
634 | #define FL_THUMB (1 << 6) /* Thumb aware */ | |
635 | #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */ | |
636 | #define FL_STRONG (1 << 8) /* StrongARM */ | |
6bc82793 | 637 | #define FL_ARCH5E (1 << 9) /* DSP extensions to v5 */ |
d19fb8e3 | 638 | #define FL_XSCALE (1 << 10) /* XScale */ |
9b6b54e2 | 639 | #define FL_CIRRUS (1 << 11) /* Cirrus/DSP. */ |
9b66ebb1 | 640 | #define FL_ARCH6 (1 << 12) /* Architecture rel 6. Adds |
81f9037c MM |
641 | media instructions. */ |
642 | #define FL_VFPV2 (1 << 13) /* Vector Floating Point V2. */ | |
abac3b49 RE |
643 | #define FL_WBUF (1 << 14) /* Schedule for write buffer ops. |
644 | Note: ARM6 & 7 derivatives only. */ | |
d3585b76 | 645 | #define FL_ARCH6K (1 << 15) /* Architecture rel 6 K extensions. */ |
5b3e6663 PB |
646 | #define FL_THUMB2 (1 << 16) /* Thumb-2. */ |
647 | #define FL_NOTM (1 << 17) /* Instructions not present in the 'M' | |
648 | profile. */ | |
7a085dce | 649 | #define FL_DIV (1 << 18) /* Hardware divide. */ |
f1adb0a9 | 650 | #define FL_VFPV3 (1 << 19) /* Vector Floating Point V3. */ |
88f77cba | 651 | #define FL_NEON (1 << 20) /* Neon instructions. */ |
60bd3528 PB |
652 | #define FL_ARCH7EM (1 << 21) /* Instructions present in the ARMv7E-M |
653 | architecture. */ | |
029e79eb | 654 | #define FL_ARCH7 (1 << 22) /* Architecture 7. */ |
aec3cfba | 655 | |
9b66ebb1 PB |
656 | #define FL_IWMMXT (1 << 29) /* XScale v2 or "Intel Wireless MMX technology". */ |
657 | ||
12a0a4d4 PB |
658 | /* Flags that only effect tuning, not available instructions. */ |
659 | #define FL_TUNE (FL_WBUF | FL_VFPV2 | FL_STRONG | FL_LDSCHED \ | |
660 | | FL_CO_PROC) | |
661 | ||
5b3e6663 PB |
662 | #define FL_FOR_ARCH2 FL_NOTM |
663 | #define FL_FOR_ARCH3 (FL_FOR_ARCH2 | FL_MODE32) | |
78011587 PB |
664 | #define FL_FOR_ARCH3M (FL_FOR_ARCH3 | FL_ARCH3M) |
665 | #define FL_FOR_ARCH4 (FL_FOR_ARCH3M | FL_ARCH4) | |
666 | #define FL_FOR_ARCH4T (FL_FOR_ARCH4 | FL_THUMB) | |
667 | #define FL_FOR_ARCH5 (FL_FOR_ARCH4 | FL_ARCH5) | |
668 | #define FL_FOR_ARCH5T (FL_FOR_ARCH5 | FL_THUMB) | |
669 | #define FL_FOR_ARCH5E (FL_FOR_ARCH5 | FL_ARCH5E) | |
670 | #define FL_FOR_ARCH5TE (FL_FOR_ARCH5E | FL_THUMB) | |
671 | #define FL_FOR_ARCH5TEJ FL_FOR_ARCH5TE | |
672 | #define FL_FOR_ARCH6 (FL_FOR_ARCH5TE | FL_ARCH6) | |
673 | #define FL_FOR_ARCH6J FL_FOR_ARCH6 | |
d3585b76 | 674 | #define FL_FOR_ARCH6K (FL_FOR_ARCH6 | FL_ARCH6K) |
fa91adc6 | 675 | #define FL_FOR_ARCH6Z FL_FOR_ARCH6 |
d3585b76 | 676 | #define FL_FOR_ARCH6ZK FL_FOR_ARCH6K |
5b3e6663 | 677 | #define FL_FOR_ARCH6T2 (FL_FOR_ARCH6 | FL_THUMB2) |
bf98ec6c | 678 | #define FL_FOR_ARCH6M (FL_FOR_ARCH6 & ~FL_NOTM) |
029e79eb | 679 | #define FL_FOR_ARCH7 ((FL_FOR_ARCH6T2 & ~FL_NOTM) | FL_ARCH7) |
87d05b44 | 680 | #define FL_FOR_ARCH7A (FL_FOR_ARCH7 | FL_NOTM | FL_ARCH6K) |
5b3e6663 PB |
681 | #define FL_FOR_ARCH7R (FL_FOR_ARCH7A | FL_DIV) |
682 | #define FL_FOR_ARCH7M (FL_FOR_ARCH7 | FL_DIV) | |
60bd3528 | 683 | #define FL_FOR_ARCH7EM (FL_FOR_ARCH7M | FL_ARCH7EM) |
78011587 | 684 | |
1d6e90ac NC |
685 | /* The bits in this mask specify which |
686 | instructions we are allowed to generate. */ | |
0977774b | 687 | static unsigned long insn_flags = 0; |
d5b7b3ae | 688 | |
aec3cfba | 689 | /* The bits in this mask specify which instruction scheduling options should |
9b66ebb1 | 690 | be used. */ |
0977774b | 691 | static unsigned long tune_flags = 0; |
aec3cfba NC |
692 | |
693 | /* The following are used in the arm.md file as equivalents to bits | |
694 | in the above two flag variables. */ | |
695 | ||
9b66ebb1 PB |
696 | /* Nonzero if this chip supports the ARM Architecture 3M extensions. */ |
697 | int arm_arch3m = 0; | |
2b835d68 | 698 | |
6354dc9b | 699 | /* Nonzero if this chip supports the ARM Architecture 4 extensions. */ |
2b835d68 RE |
700 | int arm_arch4 = 0; |
701 | ||
68d560d4 RE |
702 | /* Nonzero if this chip supports the ARM Architecture 4t extensions. */ |
703 | int arm_arch4t = 0; | |
704 | ||
6354dc9b | 705 | /* Nonzero if this chip supports the ARM Architecture 5 extensions. */ |
62b10bbc NC |
706 | int arm_arch5 = 0; |
707 | ||
b15bca31 RE |
708 | /* Nonzero if this chip supports the ARM Architecture 5E extensions. */ |
709 | int arm_arch5e = 0; | |
710 | ||
9b66ebb1 PB |
711 | /* Nonzero if this chip supports the ARM Architecture 6 extensions. */ |
712 | int arm_arch6 = 0; | |
713 | ||
d3585b76 DJ |
714 | /* Nonzero if this chip supports the ARM 6K extensions. */ |
715 | int arm_arch6k = 0; | |
716 | ||
029e79eb MS |
717 | /* Nonzero if this chip supports the ARM 7 extensions. */ |
718 | int arm_arch7 = 0; | |
719 | ||
5b3e6663 PB |
720 | /* Nonzero if instructions not present in the 'M' profile can be used. */ |
721 | int arm_arch_notm = 0; | |
722 | ||
60bd3528 PB |
723 | /* Nonzero if instructions present in ARMv7E-M can be used. */ |
724 | int arm_arch7em = 0; | |
725 | ||
aec3cfba | 726 | /* Nonzero if this chip can benefit from load scheduling. */ |
f5a1b0d2 NC |
727 | int arm_ld_sched = 0; |
728 | ||
729 | /* Nonzero if this chip is a StrongARM. */ | |
abac3b49 | 730 | int arm_tune_strongarm = 0; |
f5a1b0d2 | 731 | |
78011587 PB |
732 | /* Nonzero if this chip is a Cirrus variant. */ |
733 | int arm_arch_cirrus = 0; | |
734 | ||
5a9335ef NC |
735 | /* Nonzero if this chip supports Intel Wireless MMX technology. */ |
736 | int arm_arch_iwmmxt = 0; | |
737 | ||
d19fb8e3 | 738 | /* Nonzero if this chip is an XScale. */ |
4b3c2e48 PB |
739 | int arm_arch_xscale = 0; |
740 | ||
741 | /* Nonzero if tuning for XScale */ | |
742 | int arm_tune_xscale = 0; | |
d19fb8e3 | 743 | |
e0b92319 | 744 | /* Nonzero if we want to tune for stores that access the write-buffer. |
c5d34bb2 | 745 | This typically means an ARM6 or ARM7 with MMU or MPU. */ |
abac3b49 | 746 | int arm_tune_wbuf = 0; |
b111229a | 747 | |
7612f14d PB |
748 | /* Nonzero if tuning for Cortex-A9. */ |
749 | int arm_tune_cortex_a9 = 0; | |
750 | ||
0616531f RE |
751 | /* Nonzero if generating Thumb instructions. */ |
752 | int thumb_code = 0; | |
753 | ||
906668bb BS |
754 | /* Nonzero if generating Thumb-1 instructions. */ |
755 | int thumb1_code = 0; | |
756 | ||
2ad4dcf9 | 757 | /* Nonzero if we should define __THUMB_INTERWORK__ in the |
f676971a | 758 | preprocessor. |
2ad4dcf9 RE |
759 | XXX This is a bit of a hack, it's intended to help work around |
760 | problems in GLD which doesn't understand that armv5t code is | |
761 | interworking clean. */ | |
762 | int arm_cpp_interwork = 0; | |
763 | ||
5b3e6663 PB |
764 | /* Nonzero if chip supports Thumb 2. */ |
765 | int arm_arch_thumb2; | |
766 | ||
767 | /* Nonzero if chip supports integer division instruction. */ | |
768 | int arm_arch_hwdiv; | |
769 | ||
944442bb NF |
770 | /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, |
771 | we must report the mode of the memory reference from | |
772 | TARGET_PRINT_OPERAND to TARGET_PRINT_OPERAND_ADDRESS. */ | |
f3bb6135 | 773 | enum machine_mode output_memory_reference_mode; |
cce8749e | 774 | |
32de079a | 775 | /* The register number to be used for the PIC offset register. */ |
020a4035 | 776 | unsigned arm_pic_register = INVALID_REGNUM; |
32de079a | 777 | |
aec3cfba NC |
778 | /* Set to 1 after arm_reorg has started. Reset to start at the start of |
779 | the next function. */ | |
4b632bf1 RE |
780 | static int after_arm_reorg = 0; |
781 | ||
12ffc7d5 | 782 | enum arm_pcs arm_pcs_default; |
390b17c2 | 783 | |
cce8749e CH |
784 | /* For an explanation of these variables, see final_prescan_insn below. */ |
785 | int arm_ccfsm_state; | |
5b3e6663 | 786 | /* arm_current_cc is also used for Thumb-2 cond_exec blocks. */ |
84ed5e79 | 787 | enum arm_cond_code arm_current_cc; |
906668bb | 788 | |
cce8749e CH |
789 | rtx arm_target_insn; |
790 | int arm_target_label; | |
5b3e6663 PB |
791 | /* The number of conditionally executed insns, including the current insn. */ |
792 | int arm_condexec_count = 0; | |
793 | /* A bitmask specifying the patterns for the IT block. | |
794 | Zero means do not output an IT block before this insn. */ | |
795 | int arm_condexec_mask = 0; | |
796 | /* The number of bits used in arm_condexec_mask. */ | |
797 | int arm_condexec_masklen = 0; | |
9997d19d RE |
798 | |
799 | /* The condition codes of the ARM, and the inverse function. */ | |
1d6e90ac | 800 | static const char * const arm_condition_codes[] = |
9997d19d RE |
801 | { |
802 | "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc", | |
803 | "hi", "ls", "ge", "lt", "gt", "le", "al", "nv" | |
804 | }; | |
805 | ||
37119410 BS |
806 | /* The register numbers in sequence, for passing to arm_gen_load_multiple. */ |
807 | int arm_regs_in_sequence[] = | |
808 | { | |
809 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 | |
810 | }; | |
811 | ||
5b3e6663 | 812 | #define ARM_LSL_NAME (TARGET_UNIFIED_ASM ? "lsl" : "asl") |
f5a1b0d2 | 813 | #define streq(string1, string2) (strcmp (string1, string2) == 0) |
5b3e6663 PB |
814 | |
815 | #define THUMB2_WORK_REGS (0xff & ~( (1 << THUMB_HARD_FRAME_POINTER_REGNUM) \ | |
816 | | (1 << SP_REGNUM) | (1 << PC_REGNUM) \ | |
817 | | (1 << PIC_OFFSET_TABLE_REGNUM))) | |
2b835d68 | 818 | \f |
6354dc9b | 819 | /* Initialization code. */ |
2b835d68 | 820 | |
2b835d68 RE |
821 | struct processors |
822 | { | |
8b60264b | 823 | const char *const name; |
9b66ebb1 | 824 | enum processor_type core; |
78011587 | 825 | const char *arch; |
0977774b | 826 | const unsigned long flags; |
1b78f575 RE |
827 | const struct tune_params *const tune; |
828 | }; | |
829 | ||
830 | const struct tune_params arm_slowmul_tune = | |
831 | { | |
832 | arm_slowmul_rtx_costs, | |
b0c13111 | 833 | NULL, |
1b78f575 RE |
834 | 3 |
835 | }; | |
836 | ||
837 | const struct tune_params arm_fastmul_tune = | |
838 | { | |
839 | arm_fastmul_rtx_costs, | |
b0c13111 | 840 | NULL, |
1b78f575 RE |
841 | 1 |
842 | }; | |
843 | ||
844 | const struct tune_params arm_xscale_tune = | |
845 | { | |
846 | arm_xscale_rtx_costs, | |
b0c13111 | 847 | xscale_sched_adjust_cost, |
1b78f575 RE |
848 | 2 |
849 | }; | |
850 | ||
851 | const struct tune_params arm_9e_tune = | |
852 | { | |
853 | arm_9e_rtx_costs, | |
b0c13111 | 854 | NULL, |
1b78f575 | 855 | 1 |
2b835d68 RE |
856 | }; |
857 | ||
b0c13111 RR |
858 | const struct tune_params arm_cortex_a9_tune = |
859 | { | |
860 | arm_9e_rtx_costs, | |
861 | cortex_a9_sched_adjust_cost, | |
862 | 1 | |
863 | }; | |
864 | ||
865 | ||
2b835d68 RE |
866 | /* Not all of these give usefully different compilation alternatives, |
867 | but there is no simple way of generalizing them. */ | |
8b60264b | 868 | static const struct processors all_cores[] = |
f5a1b0d2 NC |
869 | { |
870 | /* ARM Cores */ | |
d98a72fd | 871 | #define ARM_CORE(NAME, IDENT, ARCH, FLAGS, COSTS) \ |
12a0a4d4 | 872 | {NAME, IDENT, #ARCH, FLAGS | FL_FOR_ARCH##ARCH, &arm_##COSTS##_tune}, |
9b66ebb1 PB |
873 | #include "arm-cores.def" |
874 | #undef ARM_CORE | |
78011587 | 875 | {NULL, arm_none, NULL, 0, NULL} |
f5a1b0d2 NC |
876 | }; |
877 | ||
8b60264b | 878 | static const struct processors all_architectures[] = |
2b835d68 | 879 | { |
f5a1b0d2 | 880 | /* ARM Architectures */ |
1b78f575 | 881 | /* We don't specify tuning costs here as it will be figured out |
9b66ebb1 | 882 | from the core. */ |
f676971a | 883 | |
78011587 PB |
884 | {"armv2", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL}, |
885 | {"armv2a", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL}, | |
886 | {"armv3", arm6, "3", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3, NULL}, | |
887 | {"armv3m", arm7m, "3M", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3M, NULL}, | |
888 | {"armv4", arm7tdmi, "4", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH4, NULL}, | |
b111229a RE |
889 | /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no |
890 | implementations that support it, so we will leave it out for now. */ | |
78011587 PB |
891 | {"armv4t", arm7tdmi, "4T", FL_CO_PROC | FL_FOR_ARCH4T, NULL}, |
892 | {"armv5", arm10tdmi, "5", FL_CO_PROC | FL_FOR_ARCH5, NULL}, | |
893 | {"armv5t", arm10tdmi, "5T", FL_CO_PROC | FL_FOR_ARCH5T, NULL}, | |
894 | {"armv5e", arm1026ejs, "5E", FL_CO_PROC | FL_FOR_ARCH5E, NULL}, | |
895 | {"armv5te", arm1026ejs, "5TE", FL_CO_PROC | FL_FOR_ARCH5TE, NULL}, | |
896 | {"armv6", arm1136js, "6", FL_CO_PROC | FL_FOR_ARCH6, NULL}, | |
897 | {"armv6j", arm1136js, "6J", FL_CO_PROC | FL_FOR_ARCH6J, NULL}, | |
fa91adc6 PB |
898 | {"armv6k", mpcore, "6K", FL_CO_PROC | FL_FOR_ARCH6K, NULL}, |
899 | {"armv6z", arm1176jzs, "6Z", FL_CO_PROC | FL_FOR_ARCH6Z, NULL}, | |
900 | {"armv6zk", arm1176jzs, "6ZK", FL_CO_PROC | FL_FOR_ARCH6ZK, NULL}, | |
5b3e6663 | 901 | {"armv6t2", arm1156t2s, "6T2", FL_CO_PROC | FL_FOR_ARCH6T2, NULL}, |
bf98ec6c | 902 | {"armv6-m", cortexm1, "6M", FL_FOR_ARCH6M, NULL}, |
5b3e6663 PB |
903 | {"armv7", cortexa8, "7", FL_CO_PROC | FL_FOR_ARCH7, NULL}, |
904 | {"armv7-a", cortexa8, "7A", FL_CO_PROC | FL_FOR_ARCH7A, NULL}, | |
905 | {"armv7-r", cortexr4, "7R", FL_CO_PROC | FL_FOR_ARCH7R, NULL}, | |
906 | {"armv7-m", cortexm3, "7M", FL_CO_PROC | FL_FOR_ARCH7M, NULL}, | |
f6e47b26 | 907 | {"armv7e-m", cortexm4, "7EM", FL_CO_PROC | FL_FOR_ARCH7EM, NULL}, |
78011587 PB |
908 | {"ep9312", ep9312, "4T", FL_LDSCHED | FL_CIRRUS | FL_FOR_ARCH4, NULL}, |
909 | {"iwmmxt", iwmmxt, "5TE", FL_LDSCHED | FL_STRONG | FL_FOR_ARCH5TE | FL_XSCALE | FL_IWMMXT , NULL}, | |
442dc742 | 910 | {"iwmmxt2", iwmmxt2, "5TE", FL_LDSCHED | FL_STRONG | FL_FOR_ARCH5TE | FL_XSCALE | FL_IWMMXT , NULL}, |
78011587 | 911 | {NULL, arm_none, NULL, 0 , NULL} |
f5a1b0d2 NC |
912 | }; |
913 | ||
f5a1b0d2 | 914 | |
12a0a4d4 PB |
915 | /* These are populated as commandline arguments are processed, or NULL |
916 | if not specified. */ | |
917 | static const struct processors *arm_selected_arch; | |
918 | static const struct processors *arm_selected_cpu; | |
919 | static const struct processors *arm_selected_tune; | |
78011587 | 920 | |
afc0a4ba | 921 | /* The name of the preprocessor macro to define for this architecture. */ |
78011587 PB |
922 | |
923 | char arm_arch_name[] = "__ARM_ARCH_0UNK__"; | |
924 | ||
56f42830 | 925 | /* Available values for -mfpu=. */ |
9b66ebb1 | 926 | |
d79f3032 PB |
927 | static const struct arm_fpu_desc all_fpus[] = |
928 | { | |
70dd156a RN |
929 | {"fpa", ARM_FP_MODEL_FPA, 0, VFP_NONE, false, false}, |
930 | {"fpe2", ARM_FP_MODEL_FPA, 2, VFP_NONE, false, false}, | |
931 | {"fpe3", ARM_FP_MODEL_FPA, 3, VFP_NONE, false, false}, | |
932 | {"maverick", ARM_FP_MODEL_MAVERICK, 0, VFP_NONE, false, false}, | |
d79f3032 PB |
933 | {"vfp", ARM_FP_MODEL_VFP, 2, VFP_REG_D16, false, false}, |
934 | {"vfpv3", ARM_FP_MODEL_VFP, 3, VFP_REG_D32, false, false}, | |
e0dc3601 | 935 | {"vfpv3-fp16", ARM_FP_MODEL_VFP, 3, VFP_REG_D32, false, true}, |
d79f3032 | 936 | {"vfpv3-d16", ARM_FP_MODEL_VFP, 3, VFP_REG_D16, false, false}, |
e0dc3601 PB |
937 | {"vfpv3-d16-fp16", ARM_FP_MODEL_VFP, 3, VFP_REG_D16, false, true}, |
938 | {"vfpv3xd", ARM_FP_MODEL_VFP, 3, VFP_REG_SINGLE, false, false}, | |
939 | {"vfpv3xd-fp16", ARM_FP_MODEL_VFP, 3, VFP_REG_SINGLE, false, true}, | |
d79f3032 PB |
940 | {"neon", ARM_FP_MODEL_VFP, 3, VFP_REG_D32, true , false}, |
941 | {"neon-fp16", ARM_FP_MODEL_VFP, 3, VFP_REG_D32, true , true }, | |
6ed126e6 PB |
942 | {"vfpv4", ARM_FP_MODEL_VFP, 4, VFP_REG_D32, false, true}, |
943 | {"vfpv4-d16", ARM_FP_MODEL_VFP, 4, VFP_REG_D16, false, true}, | |
1abed66b | 944 | {"fpv4-sp-d16", ARM_FP_MODEL_VFP, 4, VFP_REG_SINGLE, false, true}, |
6ed126e6 | 945 | {"neon-vfpv4", ARM_FP_MODEL_VFP, 4, VFP_REG_D32, true, true}, |
d79f3032 PB |
946 | /* Compatibility aliases. */ |
947 | {"vfp3", ARM_FP_MODEL_VFP, 3, VFP_REG_D32, false, false}, | |
9b66ebb1 PB |
948 | }; |
949 | ||
950 | ||
951 | struct float_abi | |
952 | { | |
953 | const char * name; | |
954 | enum float_abi_type abi_type; | |
955 | }; | |
956 | ||
957 | ||
958 | /* Available values for -mfloat-abi=. */ | |
959 | ||
960 | static const struct float_abi all_float_abis[] = | |
961 | { | |
962 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
963 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
964 | {"hard", ARM_FLOAT_ABI_HARD} | |
965 | }; | |
966 | ||
967 | ||
0fd8c3ad SL |
968 | struct fp16_format |
969 | { | |
970 | const char *name; | |
971 | enum arm_fp16_format_type fp16_format_type; | |
972 | }; | |
973 | ||
974 | ||
975 | /* Available values for -mfp16-format=. */ | |
976 | ||
977 | static const struct fp16_format all_fp16_formats[] = | |
978 | { | |
979 | {"none", ARM_FP16_FORMAT_NONE}, | |
980 | {"ieee", ARM_FP16_FORMAT_IEEE}, | |
981 | {"alternative", ARM_FP16_FORMAT_ALTERNATIVE} | |
982 | }; | |
983 | ||
984 | ||
5848830f PB |
985 | struct abi_name |
986 | { | |
987 | const char *name; | |
988 | enum arm_abi_type abi_type; | |
989 | }; | |
990 | ||
991 | ||
992 | /* Available values for -mabi=. */ | |
993 | ||
994 | static const struct abi_name arm_all_abis[] = | |
995 | { | |
996 | {"apcs-gnu", ARM_ABI_APCS}, | |
997 | {"atpcs", ARM_ABI_ATPCS}, | |
998 | {"aapcs", ARM_ABI_AAPCS}, | |
077fc835 KH |
999 | {"iwmmxt", ARM_ABI_IWMMXT}, |
1000 | {"aapcs-linux", ARM_ABI_AAPCS_LINUX} | |
5848830f PB |
1001 | }; |
1002 | ||
d3585b76 DJ |
1003 | /* Supported TLS relocations. */ |
1004 | ||
1005 | enum tls_reloc { | |
1006 | TLS_GD32, | |
1007 | TLS_LDM32, | |
1008 | TLS_LDO32, | |
1009 | TLS_IE32, | |
1010 | TLS_LE32 | |
1011 | }; | |
1012 | ||
1b78f575 RE |
1013 | /* The maximum number of insns to be used when loading a constant. */ |
1014 | inline static int | |
1015 | arm_constant_limit (bool size_p) | |
1016 | { | |
1017 | return size_p ? 1 : current_tune->constant_limit; | |
1018 | } | |
1019 | ||
d66437c5 RE |
1020 | /* Emit an insn that's a simple single-set. Both the operands must be known |
1021 | to be valid. */ | |
1022 | inline static rtx | |
1023 | emit_set_insn (rtx x, rtx y) | |
1024 | { | |
1025 | return emit_insn (gen_rtx_SET (VOIDmode, x, y)); | |
1026 | } | |
1027 | ||
0977774b JT |
1028 | /* Return the number of bits set in VALUE. */ |
1029 | static unsigned | |
e32bac5b | 1030 | bit_count (unsigned long value) |
aec3cfba | 1031 | { |
d5b7b3ae | 1032 | unsigned long count = 0; |
f676971a | 1033 | |
aec3cfba NC |
1034 | while (value) |
1035 | { | |
0977774b JT |
1036 | count++; |
1037 | value &= value - 1; /* Clear the least-significant set bit. */ | |
aec3cfba NC |
1038 | } |
1039 | ||
1040 | return count; | |
1041 | } | |
1042 | ||
c112cf2b | 1043 | /* Set up library functions unique to ARM. */ |
b3f8d95d MM |
1044 | |
1045 | static void | |
1046 | arm_init_libfuncs (void) | |
1047 | { | |
1048 | /* There are no special library functions unless we are using the | |
1049 | ARM BPABI. */ | |
1050 | if (!TARGET_BPABI) | |
1051 | return; | |
1052 | ||
1053 | /* The functions below are described in Section 4 of the "Run-Time | |
1054 | ABI for the ARM architecture", Version 1.0. */ | |
1055 | ||
1056 | /* Double-precision floating-point arithmetic. Table 2. */ | |
1057 | set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd"); | |
1058 | set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv"); | |
1059 | set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul"); | |
1060 | set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg"); | |
1061 | set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub"); | |
1062 | ||
c112cf2b | 1063 | /* Double-precision comparisons. Table 3. */ |
b3f8d95d MM |
1064 | set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq"); |
1065 | set_optab_libfunc (ne_optab, DFmode, NULL); | |
1066 | set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt"); | |
1067 | set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple"); | |
1068 | set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge"); | |
1069 | set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt"); | |
1070 | set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun"); | |
1071 | ||
1072 | /* Single-precision floating-point arithmetic. Table 4. */ | |
1073 | set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd"); | |
1074 | set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv"); | |
1075 | set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul"); | |
1076 | set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg"); | |
1077 | set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub"); | |
f676971a | 1078 | |
c112cf2b | 1079 | /* Single-precision comparisons. Table 5. */ |
b3f8d95d MM |
1080 | set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq"); |
1081 | set_optab_libfunc (ne_optab, SFmode, NULL); | |
1082 | set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt"); | |
1083 | set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple"); | |
1084 | set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge"); | |
1085 | set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt"); | |
1086 | set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun"); | |
1087 | ||
1088 | /* Floating-point to integer conversions. Table 6. */ | |
1089 | set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz"); | |
1090 | set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz"); | |
1091 | set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz"); | |
1092 | set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz"); | |
1093 | set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz"); | |
1094 | set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz"); | |
1095 | set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz"); | |
1096 | set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz"); | |
1097 | ||
1098 | /* Conversions between floating types. Table 7. */ | |
1099 | set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f"); | |
1100 | set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d"); | |
1101 | ||
c112cf2b | 1102 | /* Integer to floating-point conversions. Table 8. */ |
b3f8d95d MM |
1103 | set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d"); |
1104 | set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d"); | |
1105 | set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d"); | |
1106 | set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d"); | |
1107 | set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f"); | |
1108 | set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f"); | |
1109 | set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f"); | |
1110 | set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f"); | |
1111 | ||
1112 | /* Long long. Table 9. */ | |
1113 | set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul"); | |
1114 | set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod"); | |
1115 | set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod"); | |
1116 | set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl"); | |
1117 | set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr"); | |
1118 | set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr"); | |
1119 | set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp"); | |
1120 | set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp"); | |
1121 | ||
1122 | /* Integer (32/32->32) division. \S 4.3.1. */ | |
1123 | set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod"); | |
1124 | set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod"); | |
1125 | ||
1126 | /* The divmod functions are designed so that they can be used for | |
1127 | plain division, even though they return both the quotient and the | |
1128 | remainder. The quotient is returned in the usual location (i.e., | |
1129 | r0 for SImode, {r0, r1} for DImode), just as would be expected | |
1130 | for an ordinary division routine. Because the AAPCS calling | |
1131 | conventions specify that all of { r0, r1, r2, r3 } are | |
1132 | callee-saved registers, there is no need to tell the compiler | |
1133 | explicitly that those registers are clobbered by these | |
1134 | routines. */ | |
1135 | set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod"); | |
1136 | set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod"); | |
e993ba8f DJ |
1137 | |
1138 | /* For SImode division the ABI provides div-without-mod routines, | |
1139 | which are faster. */ | |
1140 | set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idiv"); | |
1141 | set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidiv"); | |
01c19d47 PB |
1142 | |
1143 | /* We don't have mod libcalls. Fortunately gcc knows how to use the | |
1144 | divmod libcalls instead. */ | |
1145 | set_optab_libfunc (smod_optab, DImode, NULL); | |
1146 | set_optab_libfunc (umod_optab, DImode, NULL); | |
1147 | set_optab_libfunc (smod_optab, SImode, NULL); | |
1148 | set_optab_libfunc (umod_optab, SImode, NULL); | |
0fd8c3ad SL |
1149 | |
1150 | /* Half-precision float operations. The compiler handles all operations | |
1151 | with NULL libfuncs by converting the SFmode. */ | |
1152 | switch (arm_fp16_format) | |
1153 | { | |
1154 | case ARM_FP16_FORMAT_IEEE: | |
1155 | case ARM_FP16_FORMAT_ALTERNATIVE: | |
1156 | ||
1157 | /* Conversions. */ | |
1158 | set_conv_libfunc (trunc_optab, HFmode, SFmode, | |
1159 | (arm_fp16_format == ARM_FP16_FORMAT_IEEE | |
1160 | ? "__gnu_f2h_ieee" | |
1161 | : "__gnu_f2h_alternative")); | |
1162 | set_conv_libfunc (sext_optab, SFmode, HFmode, | |
1163 | (arm_fp16_format == ARM_FP16_FORMAT_IEEE | |
1164 | ? "__gnu_h2f_ieee" | |
1165 | : "__gnu_h2f_alternative")); | |
1166 | ||
1167 | /* Arithmetic. */ | |
1168 | set_optab_libfunc (add_optab, HFmode, NULL); | |
1169 | set_optab_libfunc (sdiv_optab, HFmode, NULL); | |
1170 | set_optab_libfunc (smul_optab, HFmode, NULL); | |
1171 | set_optab_libfunc (neg_optab, HFmode, NULL); | |
1172 | set_optab_libfunc (sub_optab, HFmode, NULL); | |
1173 | ||
1174 | /* Comparisons. */ | |
1175 | set_optab_libfunc (eq_optab, HFmode, NULL); | |
1176 | set_optab_libfunc (ne_optab, HFmode, NULL); | |
1177 | set_optab_libfunc (lt_optab, HFmode, NULL); | |
1178 | set_optab_libfunc (le_optab, HFmode, NULL); | |
1179 | set_optab_libfunc (ge_optab, HFmode, NULL); | |
1180 | set_optab_libfunc (gt_optab, HFmode, NULL); | |
1181 | set_optab_libfunc (unord_optab, HFmode, NULL); | |
1182 | break; | |
1183 | ||
1184 | default: | |
1185 | break; | |
1186 | } | |
353a58f7 AH |
1187 | |
1188 | if (TARGET_AAPCS_BASED) | |
1189 | synchronize_libfunc = init_one_libfunc ("__sync_synchronize"); | |
b3f8d95d MM |
1190 | } |
1191 | ||
07d8efe3 MM |
1192 | /* On AAPCS systems, this is the "struct __va_list". */ |
1193 | static GTY(()) tree va_list_type; | |
1194 | ||
1195 | /* Return the type to use as __builtin_va_list. */ | |
1196 | static tree | |
1197 | arm_build_builtin_va_list (void) | |
1198 | { | |
1199 | tree va_list_name; | |
1200 | tree ap_field; | |
1201 | ||
1202 | if (!TARGET_AAPCS_BASED) | |
1203 | return std_build_builtin_va_list (); | |
1204 | ||
1205 | /* AAPCS \S 7.1.4 requires that va_list be a typedef for a type | |
1206 | defined as: | |
1207 | ||
1208 | struct __va_list | |
1209 | { | |
1210 | void *__ap; | |
1211 | }; | |
1212 | ||
1213 | The C Library ABI further reinforces this definition in \S | |
1214 | 4.1. | |
1215 | ||
1216 | We must follow this definition exactly. The structure tag | |
1217 | name is visible in C++ mangled names, and thus forms a part | |
1218 | of the ABI. The field name may be used by people who | |
1219 | #include <stdarg.h>. */ | |
1220 | /* Create the type. */ | |
1221 | va_list_type = lang_hooks.types.make_type (RECORD_TYPE); | |
1222 | /* Give it the required name. */ | |
4c4bde29 AH |
1223 | va_list_name = build_decl (BUILTINS_LOCATION, |
1224 | TYPE_DECL, | |
07d8efe3 MM |
1225 | get_identifier ("__va_list"), |
1226 | va_list_type); | |
1227 | DECL_ARTIFICIAL (va_list_name) = 1; | |
1228 | TYPE_NAME (va_list_type) = va_list_name; | |
56f01f0b | 1229 | TYPE_STUB_DECL (va_list_type) = va_list_name; |
07d8efe3 | 1230 | /* Create the __ap field. */ |
4c4bde29 AH |
1231 | ap_field = build_decl (BUILTINS_LOCATION, |
1232 | FIELD_DECL, | |
07d8efe3 MM |
1233 | get_identifier ("__ap"), |
1234 | ptr_type_node); | |
1235 | DECL_ARTIFICIAL (ap_field) = 1; | |
1236 | DECL_FIELD_CONTEXT (ap_field) = va_list_type; | |
1237 | TYPE_FIELDS (va_list_type) = ap_field; | |
1238 | /* Compute its layout. */ | |
1239 | layout_type (va_list_type); | |
1240 | ||
1241 | return va_list_type; | |
1242 | } | |
1243 | ||
1244 | /* Return an expression of type "void *" pointing to the next | |
1245 | available argument in a variable-argument list. VALIST is the | |
1246 | user-level va_list object, of type __builtin_va_list. */ | |
1247 | static tree | |
1248 | arm_extract_valist_ptr (tree valist) | |
1249 | { | |
1250 | if (TREE_TYPE (valist) == error_mark_node) | |
1251 | return error_mark_node; | |
1252 | ||
1253 | /* On an AAPCS target, the pointer is stored within "struct | |
1254 | va_list". */ | |
1255 | if (TARGET_AAPCS_BASED) | |
1256 | { | |
1257 | tree ap_field = TYPE_FIELDS (TREE_TYPE (valist)); | |
1258 | valist = build3 (COMPONENT_REF, TREE_TYPE (ap_field), | |
1259 | valist, ap_field, NULL_TREE); | |
1260 | } | |
1261 | ||
1262 | return valist; | |
1263 | } | |
1264 | ||
1265 | /* Implement TARGET_EXPAND_BUILTIN_VA_START. */ | |
1266 | static void | |
1267 | arm_expand_builtin_va_start (tree valist, rtx nextarg) | |
1268 | { | |
1269 | valist = arm_extract_valist_ptr (valist); | |
1270 | std_expand_builtin_va_start (valist, nextarg); | |
1271 | } | |
1272 | ||
1273 | /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */ | |
1274 | static tree | |
ae46a823 JM |
1275 | arm_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, |
1276 | gimple_seq *post_p) | |
07d8efe3 MM |
1277 | { |
1278 | valist = arm_extract_valist_ptr (valist); | |
1279 | return std_gimplify_va_arg_expr (valist, type, pre_p, post_p); | |
1280 | } | |
1281 | ||
12a0a4d4 PB |
1282 | /* Lookup NAME in SEL. */ |
1283 | ||
1284 | static const struct processors * | |
1285 | arm_find_cpu (const char *name, const struct processors *sel, const char *desc) | |
1286 | { | |
1287 | if (!(name && *name)) | |
1288 | return NULL; | |
1289 | ||
1290 | for (; sel->name != NULL; sel++) | |
1291 | { | |
1292 | if (streq (name, sel->name)) | |
1293 | return sel; | |
1294 | } | |
1295 | ||
1296 | error ("bad value (%s) for %s switch", name, desc); | |
1297 | return NULL; | |
1298 | } | |
1299 | ||
c54c7322 RS |
1300 | /* Implement TARGET_HANDLE_OPTION. */ |
1301 | ||
1302 | static bool | |
1303 | arm_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED) | |
1304 | { | |
1305 | switch (code) | |
1306 | { | |
c54c7322 | 1307 | case OPT_march_: |
12a0a4d4 | 1308 | arm_selected_arch = arm_find_cpu(arg, all_architectures, "-march"); |
c54c7322 RS |
1309 | return true; |
1310 | ||
1311 | case OPT_mcpu_: | |
12a0a4d4 | 1312 | arm_selected_cpu = arm_find_cpu(arg, all_cores, "-mcpu"); |
c54c7322 RS |
1313 | return true; |
1314 | ||
c54c7322 RS |
1315 | case OPT_mhard_float: |
1316 | target_float_abi_name = "hard"; | |
1317 | return true; | |
1318 | ||
c54c7322 RS |
1319 | case OPT_msoft_float: |
1320 | target_float_abi_name = "soft"; | |
1321 | return true; | |
1322 | ||
c54c7322 | 1323 | case OPT_mtune_: |
12a0a4d4 | 1324 | arm_selected_tune = arm_find_cpu(arg, all_cores, "-mtune"); |
c54c7322 RS |
1325 | return true; |
1326 | ||
1327 | default: | |
1328 | return true; | |
1329 | } | |
1330 | } | |
1331 | ||
67e6ba46 NC |
1332 | static void |
1333 | arm_target_help (void) | |
1334 | { | |
1335 | int i; | |
1336 | static int columns = 0; | |
1337 | int remaining; | |
1338 | ||
1339 | /* If we have not done so already, obtain the desired maximum width of | |
1340 | the output. Note - this is a duplication of the code at the start of | |
1341 | gcc/opts.c:print_specific_help() - the two copies should probably be | |
1342 | replaced by a single function. */ | |
1343 | if (columns == 0) | |
1344 | { | |
1345 | const char *p; | |
1346 | ||
1347 | GET_ENVIRONMENT (p, "COLUMNS"); | |
1348 | if (p != NULL) | |
1349 | { | |
1350 | int value = atoi (p); | |
1351 | ||
1352 | if (value > 0) | |
1353 | columns = value; | |
1354 | } | |
1355 | ||
1356 | if (columns == 0) | |
1357 | /* Use a reasonable default. */ | |
1358 | columns = 80; | |
1359 | } | |
1360 | ||
1361 | printf (" Known ARM CPUs (for use with the -mcpu= and -mtune= options):\n"); | |
1362 | ||
1363 | /* The - 2 is because we know that the last entry in the array is NULL. */ | |
1364 | i = ARRAY_SIZE (all_cores) - 2; | |
1365 | gcc_assert (i > 0); | |
1366 | printf (" %s", all_cores[i].name); | |
1367 | remaining = columns - (strlen (all_cores[i].name) + 4); | |
1368 | gcc_assert (remaining >= 0); | |
1369 | ||
1370 | while (i--) | |
1371 | { | |
1372 | int len = strlen (all_cores[i].name); | |
1373 | ||
1374 | if (remaining > len + 2) | |
1375 | { | |
1376 | printf (", %s", all_cores[i].name); | |
1377 | remaining -= len + 2; | |
1378 | } | |
1379 | else | |
1380 | { | |
1381 | if (remaining > 0) | |
1382 | printf (","); | |
1383 | printf ("\n %s", all_cores[i].name); | |
1384 | remaining = columns - (len + 4); | |
1385 | } | |
1386 | } | |
1387 | ||
1388 | printf ("\n\n Known ARM architectures (for use with the -march= option):\n"); | |
1389 | ||
1390 | i = ARRAY_SIZE (all_architectures) - 2; | |
1391 | gcc_assert (i > 0); | |
1392 | ||
1393 | printf (" %s", all_architectures[i].name); | |
1394 | remaining = columns - (strlen (all_architectures[i].name) + 4); | |
1395 | gcc_assert (remaining >= 0); | |
1396 | ||
1397 | while (i--) | |
1398 | { | |
1399 | int len = strlen (all_architectures[i].name); | |
1400 | ||
1401 | if (remaining > len + 2) | |
1402 | { | |
1403 | printf (", %s", all_architectures[i].name); | |
1404 | remaining -= len + 2; | |
1405 | } | |
1406 | else | |
1407 | { | |
1408 | if (remaining > 0) | |
1409 | printf (","); | |
1410 | printf ("\n %s", all_architectures[i].name); | |
1411 | remaining = columns - (len + 4); | |
1412 | } | |
1413 | } | |
1414 | printf ("\n"); | |
1415 | ||
1416 | } | |
1417 | ||
c5387660 JM |
1418 | /* Fix up any incompatible options that the user has specified. */ |
1419 | static void | |
1420 | arm_option_override (void) | |
2b835d68 | 1421 | { |
ed4c4348 | 1422 | unsigned i; |
9b66ebb1 | 1423 | |
c5387660 JM |
1424 | #ifdef SUBTARGET_OVERRIDE_OPTIONS |
1425 | SUBTARGET_OVERRIDE_OPTIONS; | |
1426 | #endif | |
1427 | ||
12a0a4d4 | 1428 | if (arm_selected_arch) |
bd9c7e23 | 1429 | { |
12a0a4d4 PB |
1430 | if (arm_selected_cpu) |
1431 | { | |
1432 | /* Check for conflict between mcpu and march. */ | |
1433 | if ((arm_selected_cpu->flags ^ arm_selected_arch->flags) & ~FL_TUNE) | |
1434 | { | |
1435 | warning (0, "switch -mcpu=%s conflicts with -march=%s switch", | |
1436 | arm_selected_cpu->name, arm_selected_arch->name); | |
1437 | /* -march wins for code generation. | |
1438 | -mcpu wins for default tuning. */ | |
1439 | if (!arm_selected_tune) | |
1440 | arm_selected_tune = arm_selected_cpu; | |
1441 | ||
1442 | arm_selected_cpu = arm_selected_arch; | |
1443 | } | |
1444 | else | |
1445 | /* -mcpu wins. */ | |
1446 | arm_selected_arch = NULL; | |
1447 | } | |
1448 | else | |
1449 | /* Pick a CPU based on the architecture. */ | |
1450 | arm_selected_cpu = arm_selected_arch; | |
bd9c7e23 | 1451 | } |
f676971a | 1452 | |
f5a1b0d2 | 1453 | /* If the user did not specify a processor, choose one for them. */ |
12a0a4d4 | 1454 | if (!arm_selected_cpu) |
f5a1b0d2 | 1455 | { |
8b60264b | 1456 | const struct processors * sel; |
aec3cfba | 1457 | unsigned int sought; |
aec3cfba | 1458 | |
12a0a4d4 PB |
1459 | arm_selected_cpu = &all_cores[TARGET_CPU_DEFAULT]; |
1460 | if (!arm_selected_cpu->name) | |
78011587 PB |
1461 | { |
1462 | #ifdef SUBTARGET_CPU_DEFAULT | |
1463 | /* Use the subtarget default CPU if none was specified by | |
1464 | configure. */ | |
12a0a4d4 | 1465 | arm_selected_cpu = &all_cores[SUBTARGET_CPU_DEFAULT]; |
78011587 PB |
1466 | #endif |
1467 | /* Default to ARM6. */ | |
fe7645b9 | 1468 | if (!arm_selected_cpu->name) |
12a0a4d4 | 1469 | arm_selected_cpu = &all_cores[arm6]; |
78011587 | 1470 | } |
aec3cfba | 1471 | |
12a0a4d4 | 1472 | sel = arm_selected_cpu; |
aec3cfba | 1473 | insn_flags = sel->flags; |
9b66ebb1 | 1474 | |
aec3cfba NC |
1475 | /* Now check to see if the user has specified some command line |
1476 | switch that require certain abilities from the cpu. */ | |
1477 | sought = 0; | |
f676971a | 1478 | |
d5b7b3ae | 1479 | if (TARGET_INTERWORK || TARGET_THUMB) |
f5a1b0d2 | 1480 | { |
aec3cfba | 1481 | sought |= (FL_THUMB | FL_MODE32); |
f676971a | 1482 | |
d5b7b3ae | 1483 | /* There are no ARM processors that support both APCS-26 and |
aec3cfba NC |
1484 | interworking. Therefore we force FL_MODE26 to be removed |
1485 | from insn_flags here (if it was set), so that the search | |
1486 | below will always be able to find a compatible processor. */ | |
5895f793 | 1487 | insn_flags &= ~FL_MODE26; |
f5a1b0d2 | 1488 | } |
f676971a | 1489 | |
aec3cfba | 1490 | if (sought != 0 && ((sought & insn_flags) != sought)) |
f5a1b0d2 | 1491 | { |
aec3cfba NC |
1492 | /* Try to locate a CPU type that supports all of the abilities |
1493 | of the default CPU, plus the extra abilities requested by | |
1494 | the user. */ | |
5895f793 | 1495 | for (sel = all_cores; sel->name != NULL; sel++) |
aec3cfba | 1496 | if ((sel->flags & sought) == (sought | insn_flags)) |
f5a1b0d2 NC |
1497 | break; |
1498 | ||
1499 | if (sel->name == NULL) | |
aec3cfba | 1500 | { |
0977774b | 1501 | unsigned current_bit_count = 0; |
8b60264b | 1502 | const struct processors * best_fit = NULL; |
f676971a | 1503 | |
aec3cfba NC |
1504 | /* Ideally we would like to issue an error message here |
1505 | saying that it was not possible to find a CPU compatible | |
1506 | with the default CPU, but which also supports the command | |
1507 | line options specified by the programmer, and so they | |
1508 | ought to use the -mcpu=<name> command line option to | |
1509 | override the default CPU type. | |
1510 | ||
61f0ccff RE |
1511 | If we cannot find a cpu that has both the |
1512 | characteristics of the default cpu and the given | |
1513 | command line options we scan the array again looking | |
1514 | for a best match. */ | |
5895f793 | 1515 | for (sel = all_cores; sel->name != NULL; sel++) |
aec3cfba NC |
1516 | if ((sel->flags & sought) == sought) |
1517 | { | |
0977774b | 1518 | unsigned count; |
aec3cfba NC |
1519 | |
1520 | count = bit_count (sel->flags & insn_flags); | |
1521 | ||
1522 | if (count >= current_bit_count) | |
1523 | { | |
1524 | best_fit = sel; | |
1525 | current_bit_count = count; | |
1526 | } | |
1527 | } | |
f5a1b0d2 | 1528 | |
e6d29d15 NS |
1529 | gcc_assert (best_fit); |
1530 | sel = best_fit; | |
aec3cfba NC |
1531 | } |
1532 | ||
12a0a4d4 | 1533 | arm_selected_cpu = sel; |
f5a1b0d2 NC |
1534 | } |
1535 | } | |
f676971a | 1536 | |
12a0a4d4 PB |
1537 | gcc_assert (arm_selected_cpu); |
1538 | /* The selected cpu may be an architecture, so lookup tuning by core ID. */ | |
1539 | if (!arm_selected_tune) | |
1540 | arm_selected_tune = &all_cores[arm_selected_cpu->core]; | |
1541 | ||
1542 | sprintf (arm_arch_name, "__ARM_ARCH_%s__", arm_selected_cpu->arch); | |
1543 | insn_flags = arm_selected_cpu->flags; | |
f676971a | 1544 | |
12a0a4d4 PB |
1545 | arm_tune = arm_selected_tune->core; |
1546 | tune_flags = arm_selected_tune->flags; | |
1547 | current_tune = arm_selected_tune->tune; | |
e26053d1 | 1548 | |
0fd8c3ad SL |
1549 | if (target_fp16_format_name) |
1550 | { | |
1551 | for (i = 0; i < ARRAY_SIZE (all_fp16_formats); i++) | |
1552 | { | |
1553 | if (streq (all_fp16_formats[i].name, target_fp16_format_name)) | |
1554 | { | |
1555 | arm_fp16_format = all_fp16_formats[i].fp16_format_type; | |
1556 | break; | |
1557 | } | |
1558 | } | |
1559 | if (i == ARRAY_SIZE (all_fp16_formats)) | |
1560 | error ("invalid __fp16 format option: -mfp16-format=%s", | |
1561 | target_fp16_format_name); | |
1562 | } | |
1563 | else | |
1564 | arm_fp16_format = ARM_FP16_FORMAT_NONE; | |
1565 | ||
26272ba2 PB |
1566 | if (target_abi_name) |
1567 | { | |
1568 | for (i = 0; i < ARRAY_SIZE (arm_all_abis); i++) | |
1569 | { | |
1570 | if (streq (arm_all_abis[i].name, target_abi_name)) | |
1571 | { | |
1572 | arm_abi = arm_all_abis[i].abi_type; | |
1573 | break; | |
1574 | } | |
1575 | } | |
1576 | if (i == ARRAY_SIZE (arm_all_abis)) | |
1577 | error ("invalid ABI option: -mabi=%s", target_abi_name); | |
1578 | } | |
1579 | else | |
1580 | arm_abi = ARM_DEFAULT_ABI; | |
1581 | ||
f5a1b0d2 NC |
1582 | /* Make sure that the processor choice does not conflict with any of the |
1583 | other command line choices. */ | |
5b3e6663 PB |
1584 | if (TARGET_ARM && !(insn_flags & FL_NOTM)) |
1585 | error ("target CPU does not support ARM mode"); | |
1586 | ||
26272ba2 PB |
1587 | /* BPABI targets use linker tricks to allow interworking on cores |
1588 | without thumb support. */ | |
1589 | if (TARGET_INTERWORK && !((insn_flags & FL_THUMB) || TARGET_BPABI)) | |
f5a1b0d2 | 1590 | { |
d4ee4d25 | 1591 | warning (0, "target CPU does not support interworking" ); |
c54c7322 | 1592 | target_flags &= ~MASK_INTERWORK; |
f5a1b0d2 | 1593 | } |
f676971a | 1594 | |
d5b7b3ae RE |
1595 | if (TARGET_THUMB && !(insn_flags & FL_THUMB)) |
1596 | { | |
d4ee4d25 | 1597 | warning (0, "target CPU does not support THUMB instructions"); |
c54c7322 | 1598 | target_flags &= ~MASK_THUMB; |
d5b7b3ae RE |
1599 | } |
1600 | ||
1601 | if (TARGET_APCS_FRAME && TARGET_THUMB) | |
1602 | { | |
d4ee4d25 | 1603 | /* warning (0, "ignoring -mapcs-frame because -mthumb was used"); */ |
c54c7322 | 1604 | target_flags &= ~MASK_APCS_FRAME; |
d5b7b3ae | 1605 | } |
d19fb8e3 | 1606 | |
da8ce8be RE |
1607 | /* Callee super interworking implies thumb interworking. Adding |
1608 | this to the flags here simplifies the logic elsewhere. */ | |
1609 | if (TARGET_THUMB && TARGET_CALLEE_INTERWORKING) | |
4546a2ef | 1610 | target_flags |= MASK_INTERWORK; |
da8ce8be | 1611 | |
d5b7b3ae RE |
1612 | /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done |
1613 | from here where no function is being compiled currently. */ | |
c54c7322 | 1614 | if ((TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) && TARGET_ARM) |
d4ee4d25 | 1615 | warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb"); |
d5b7b3ae RE |
1616 | |
1617 | if (TARGET_ARM && TARGET_CALLEE_INTERWORKING) | |
d4ee4d25 | 1618 | warning (0, "enabling callee interworking support is only meaningful when compiling for the Thumb"); |
d5b7b3ae | 1619 | |
5895f793 | 1620 | if (TARGET_APCS_STACK && !TARGET_APCS_FRAME) |
f5a1b0d2 | 1621 | { |
d4ee4d25 | 1622 | warning (0, "-mapcs-stack-check incompatible with -mno-apcs-frame"); |
c54c7322 | 1623 | target_flags |= MASK_APCS_FRAME; |
f5a1b0d2 | 1624 | } |
f676971a | 1625 | |
2b835d68 | 1626 | if (TARGET_POKE_FUNCTION_NAME) |
c54c7322 | 1627 | target_flags |= MASK_APCS_FRAME; |
f676971a | 1628 | |
2b835d68 | 1629 | if (TARGET_APCS_REENT && flag_pic) |
400500c4 | 1630 | error ("-fpic and -mapcs-reent are incompatible"); |
f676971a | 1631 | |
2b835d68 | 1632 | if (TARGET_APCS_REENT) |
d4ee4d25 | 1633 | warning (0, "APCS reentrant code not supported. Ignored"); |
f676971a | 1634 | |
d5b7b3ae RE |
1635 | /* If this target is normally configured to use APCS frames, warn if they |
1636 | are turned off and debugging is turned on. */ | |
1637 | if (TARGET_ARM | |
1638 | && write_symbols != NO_DEBUG | |
5895f793 | 1639 | && !TARGET_APCS_FRAME |
c54c7322 | 1640 | && (TARGET_DEFAULT & MASK_APCS_FRAME)) |
d4ee4d25 | 1641 | warning (0, "-g with -mno-apcs-frame may not give sensible debugging"); |
f676971a | 1642 | |
2b835d68 | 1643 | if (TARGET_APCS_FLOAT) |
d4ee4d25 | 1644 | warning (0, "passing floating point arguments in fp regs not yet supported"); |
f676971a | 1645 | |
4912a07c | 1646 | /* Initialize boolean versions of the flags, for use in the arm.md file. */ |
9b66ebb1 PB |
1647 | arm_arch3m = (insn_flags & FL_ARCH3M) != 0; |
1648 | arm_arch4 = (insn_flags & FL_ARCH4) != 0; | |
68d560d4 | 1649 | arm_arch4t = arm_arch4 & ((insn_flags & FL_THUMB) != 0); |
9b66ebb1 PB |
1650 | arm_arch5 = (insn_flags & FL_ARCH5) != 0; |
1651 | arm_arch5e = (insn_flags & FL_ARCH5E) != 0; | |
1652 | arm_arch6 = (insn_flags & FL_ARCH6) != 0; | |
d3585b76 | 1653 | arm_arch6k = (insn_flags & FL_ARCH6K) != 0; |
5b3e6663 | 1654 | arm_arch_notm = (insn_flags & FL_NOTM) != 0; |
029e79eb | 1655 | arm_arch7 = (insn_flags & FL_ARCH7) != 0; |
60bd3528 | 1656 | arm_arch7em = (insn_flags & FL_ARCH7EM) != 0; |
5b3e6663 | 1657 | arm_arch_thumb2 = (insn_flags & FL_THUMB2) != 0; |
9b66ebb1 | 1658 | arm_arch_xscale = (insn_flags & FL_XSCALE) != 0; |
78011587 | 1659 | arm_arch_cirrus = (insn_flags & FL_CIRRUS) != 0; |
9b66ebb1 PB |
1660 | |
1661 | arm_ld_sched = (tune_flags & FL_LDSCHED) != 0; | |
abac3b49 | 1662 | arm_tune_strongarm = (tune_flags & FL_STRONG) != 0; |
906668bb BS |
1663 | thumb_code = TARGET_ARM == 0; |
1664 | thumb1_code = TARGET_THUMB1 != 0; | |
abac3b49 | 1665 | arm_tune_wbuf = (tune_flags & FL_WBUF) != 0; |
9b66ebb1 PB |
1666 | arm_tune_xscale = (tune_flags & FL_XSCALE) != 0; |
1667 | arm_arch_iwmmxt = (insn_flags & FL_IWMMXT) != 0; | |
5b3e6663 | 1668 | arm_arch_hwdiv = (insn_flags & FL_DIV) != 0; |
7612f14d | 1669 | arm_tune_cortex_a9 = (arm_tune == cortexa9) != 0; |
5a9335ef | 1670 | |
f67358da PB |
1671 | /* If we are not using the default (ARM mode) section anchor offset |
1672 | ranges, then set the correct ranges now. */ | |
1673 | if (TARGET_THUMB1) | |
1674 | { | |
1675 | /* Thumb-1 LDR instructions cannot have negative offsets. | |
1676 | Permissible positive offset ranges are 5-bit (for byte loads), | |
1677 | 6-bit (for halfword loads), or 7-bit (for word loads). | |
1678 | Empirical results suggest a 7-bit anchor range gives the best | |
1679 | overall code size. */ | |
1680 | targetm.min_anchor_offset = 0; | |
1681 | targetm.max_anchor_offset = 127; | |
1682 | } | |
1683 | else if (TARGET_THUMB2) | |
1684 | { | |
1685 | /* The minimum is set such that the total size of the block | |
1686 | for a particular anchor is 248 + 1 + 4095 bytes, which is | |
1687 | divisible by eight, ensuring natural spacing of anchors. */ | |
1688 | targetm.min_anchor_offset = -248; | |
1689 | targetm.max_anchor_offset = 4095; | |
1690 | } | |
1691 | ||
68d560d4 RE |
1692 | /* V5 code we generate is completely interworking capable, so we turn off |
1693 | TARGET_INTERWORK here to avoid many tests later on. */ | |
2ad4dcf9 RE |
1694 | |
1695 | /* XXX However, we must pass the right pre-processor defines to CPP | |
1696 | or GLD can get confused. This is a hack. */ | |
1697 | if (TARGET_INTERWORK) | |
1698 | arm_cpp_interwork = 1; | |
1699 | ||
68d560d4 | 1700 | if (arm_arch5) |
c54c7322 | 1701 | target_flags &= ~MASK_INTERWORK; |
68d560d4 | 1702 | |
5848830f PB |
1703 | if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN) |
1704 | error ("iwmmxt requires an AAPCS compatible ABI for proper operation"); | |
1705 | ||
1706 | if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT) | |
1707 | error ("iwmmxt abi requires an iwmmxt capable cpu"); | |
6f7ebcbb | 1708 | |
9b66ebb1 | 1709 | if (target_fpu_name == NULL && target_fpe_name != NULL) |
9b6b54e2 | 1710 | { |
9b66ebb1 PB |
1711 | if (streq (target_fpe_name, "2")) |
1712 | target_fpu_name = "fpe2"; | |
1713 | else if (streq (target_fpe_name, "3")) | |
1714 | target_fpu_name = "fpe3"; | |
1715 | else | |
1716 | error ("invalid floating point emulation option: -mfpe=%s", | |
1717 | target_fpe_name); | |
1718 | } | |
d79f3032 PB |
1719 | |
1720 | if (target_fpu_name == NULL) | |
2b835d68 | 1721 | { |
9b66ebb1 | 1722 | #ifdef FPUTYPE_DEFAULT |
d79f3032 | 1723 | target_fpu_name = FPUTYPE_DEFAULT; |
9b66ebb1 | 1724 | #else |
78011587 | 1725 | if (arm_arch_cirrus) |
d79f3032 | 1726 | target_fpu_name = "maverick"; |
9b66ebb1 | 1727 | else |
d79f3032 | 1728 | target_fpu_name = "fpe2"; |
9b66ebb1 | 1729 | #endif |
d79f3032 PB |
1730 | } |
1731 | ||
1732 | arm_fpu_desc = NULL; | |
1733 | for (i = 0; i < ARRAY_SIZE (all_fpus); i++) | |
1734 | { | |
1735 | if (streq (all_fpus[i].name, target_fpu_name)) | |
1736 | { | |
1737 | arm_fpu_desc = &all_fpus[i]; | |
1738 | break; | |
1739 | } | |
1740 | } | |
b761dbe6 | 1741 | |
d79f3032 | 1742 | if (!arm_fpu_desc) |
b761dbe6 RE |
1743 | { |
1744 | error ("invalid floating point option: -mfpu=%s", target_fpu_name); | |
1745 | return; | |
1746 | } | |
d79f3032 PB |
1747 | |
1748 | switch (arm_fpu_desc->model) | |
1749 | { | |
1750 | case ARM_FP_MODEL_FPA: | |
1751 | if (arm_fpu_desc->rev == 2) | |
1752 | arm_fpu_attr = FPU_FPE2; | |
1753 | else if (arm_fpu_desc->rev == 3) | |
1754 | arm_fpu_attr = FPU_FPE3; | |
2b835d68 | 1755 | else |
d79f3032 PB |
1756 | arm_fpu_attr = FPU_FPA; |
1757 | break; | |
1758 | ||
1759 | case ARM_FP_MODEL_MAVERICK: | |
1760 | arm_fpu_attr = FPU_MAVERICK; | |
1761 | break; | |
1762 | ||
1763 | case ARM_FP_MODEL_VFP: | |
1764 | arm_fpu_attr = FPU_VFP; | |
1765 | break; | |
1766 | ||
1767 | default: | |
1768 | gcc_unreachable(); | |
9b66ebb1 PB |
1769 | } |
1770 | ||
1771 | if (target_float_abi_name != NULL) | |
1772 | { | |
1773 | /* The user specified a FP ABI. */ | |
1774 | for (i = 0; i < ARRAY_SIZE (all_float_abis); i++) | |
1775 | { | |
1776 | if (streq (all_float_abis[i].name, target_float_abi_name)) | |
1777 | { | |
1778 | arm_float_abi = all_float_abis[i].abi_type; | |
1779 | break; | |
1780 | } | |
1781 | } | |
1782 | if (i == ARRAY_SIZE (all_float_abis)) | |
1783 | error ("invalid floating point abi: -mfloat-abi=%s", | |
1784 | target_float_abi_name); | |
2b835d68 | 1785 | } |
3d8532aa PB |
1786 | else |
1787 | arm_float_abi = TARGET_DEFAULT_FLOAT_ABI; | |
9b66ebb1 | 1788 | |
0c48a567 | 1789 | if (TARGET_AAPCS_BASED |
d79f3032 | 1790 | && (arm_fpu_desc->model == ARM_FP_MODEL_FPA)) |
0c48a567 RR |
1791 | error ("FPA is unsupported in the AAPCS"); |
1792 | ||
3ce14752 | 1793 | if (TARGET_AAPCS_BASED) |
9df5bfe4 RR |
1794 | { |
1795 | if (TARGET_CALLER_INTERWORKING) | |
1796 | error ("AAPCS does not support -mcaller-super-interworking"); | |
1797 | else | |
1798 | if (TARGET_CALLEE_INTERWORKING) | |
1799 | error ("AAPCS does not support -mcallee-super-interworking"); | |
1800 | } | |
3ce14752 | 1801 | |
87b24aaf PB |
1802 | /* FPA and iWMMXt are incompatible because the insn encodings overlap. |
1803 | VFP and iWMMXt can theoretically coexist, but it's unlikely such silicon | |
1804 | will ever exist. GCC makes no attempt to support this combination. */ | |
1805 | if (TARGET_IWMMXT && !TARGET_SOFT_FLOAT) | |
1806 | sorry ("iWMMXt and hardware floating point"); | |
1807 | ||
5b3e6663 PB |
1808 | /* ??? iWMMXt insn patterns need auditing for Thumb-2. */ |
1809 | if (TARGET_THUMB2 && TARGET_IWMMXT) | |
1810 | sorry ("Thumb-2 iWMMXt"); | |
1811 | ||
0fd8c3ad SL |
1812 | /* __fp16 support currently assumes the core has ldrh. */ |
1813 | if (!arm_arch4 && arm_fp16_format != ARM_FP16_FORMAT_NONE) | |
1814 | sorry ("__fp16 and no ldrh"); | |
1815 | ||
9b66ebb1 PB |
1816 | /* If soft-float is specified then don't use FPU. */ |
1817 | if (TARGET_SOFT_FLOAT) | |
d79f3032 | 1818 | arm_fpu_attr = FPU_NONE; |
f676971a | 1819 | |
390b17c2 RE |
1820 | if (TARGET_AAPCS_BASED) |
1821 | { | |
1822 | if (arm_abi == ARM_ABI_IWMMXT) | |
1823 | arm_pcs_default = ARM_PCS_AAPCS_IWMMXT; | |
1824 | else if (arm_float_abi == ARM_FLOAT_ABI_HARD | |
1825 | && TARGET_HARD_FLOAT | |
1826 | && TARGET_VFP) | |
1827 | arm_pcs_default = ARM_PCS_AAPCS_VFP; | |
1828 | else | |
1829 | arm_pcs_default = ARM_PCS_AAPCS; | |
1830 | } | |
1831 | else | |
1832 | { | |
1833 | if (arm_float_abi == ARM_FLOAT_ABI_HARD && TARGET_VFP) | |
1834 | sorry ("-mfloat-abi=hard and VFP"); | |
1835 | ||
1836 | if (arm_abi == ARM_ABI_APCS) | |
1837 | arm_pcs_default = ARM_PCS_APCS; | |
1838 | else | |
1839 | arm_pcs_default = ARM_PCS_ATPCS; | |
1840 | } | |
1841 | ||
f5a1b0d2 NC |
1842 | /* For arm2/3 there is no need to do any scheduling if there is only |
1843 | a floating point emulator, or we are doing software floating-point. */ | |
9b66ebb1 | 1844 | if ((TARGET_SOFT_FLOAT |
d79f3032 | 1845 | || (TARGET_FPA && arm_fpu_desc->rev)) |
ed0e6530 | 1846 | && (tune_flags & FL_MODE32) == 0) |
f5a1b0d2 | 1847 | flag_schedule_insns = flag_schedule_insns_after_reload = 0; |
f676971a | 1848 | |
d3585b76 DJ |
1849 | if (target_thread_switch) |
1850 | { | |
1851 | if (strcmp (target_thread_switch, "soft") == 0) | |
1852 | target_thread_pointer = TP_SOFT; | |
1853 | else if (strcmp (target_thread_switch, "auto") == 0) | |
1854 | target_thread_pointer = TP_AUTO; | |
1855 | else if (strcmp (target_thread_switch, "cp15") == 0) | |
1856 | target_thread_pointer = TP_CP15; | |
1857 | else | |
1858 | error ("invalid thread pointer option: -mtp=%s", target_thread_switch); | |
1859 | } | |
1860 | ||
1861 | /* Use the cp15 method if it is available. */ | |
1862 | if (target_thread_pointer == TP_AUTO) | |
1863 | { | |
87d05b44 | 1864 | if (arm_arch6k && !TARGET_THUMB1) |
d3585b76 DJ |
1865 | target_thread_pointer = TP_CP15; |
1866 | else | |
1867 | target_thread_pointer = TP_SOFT; | |
1868 | } | |
1869 | ||
5b3e6663 PB |
1870 | if (TARGET_HARD_TP && TARGET_THUMB1) |
1871 | error ("can not use -mtp=cp15 with 16-bit Thumb"); | |
d3585b76 | 1872 | |
5848830f | 1873 | /* Override the default structure alignment for AAPCS ABI. */ |
077fc835 | 1874 | if (TARGET_AAPCS_BASED) |
5848830f PB |
1875 | arm_structure_size_boundary = 8; |
1876 | ||
b355a481 NC |
1877 | if (structure_size_string != NULL) |
1878 | { | |
1879 | int size = strtol (structure_size_string, NULL, 0); | |
5848830f PB |
1880 | |
1881 | if (size == 8 || size == 32 | |
1882 | || (ARM_DOUBLEWORD_ALIGN && size == 64)) | |
b355a481 NC |
1883 | arm_structure_size_boundary = size; |
1884 | else | |
d4ee4d25 | 1885 | warning (0, "structure size boundary can only be set to %s", |
5848830f | 1886 | ARM_DOUBLEWORD_ALIGN ? "8, 32 or 64": "8 or 32"); |
b355a481 | 1887 | } |
ed0e6530 | 1888 | |
9403b7f7 RS |
1889 | if (!TARGET_ARM && TARGET_VXWORKS_RTP && flag_pic) |
1890 | { | |
1891 | error ("RTP PIC is incompatible with Thumb"); | |
1892 | flag_pic = 0; | |
1893 | } | |
1894 | ||
c147eacb PB |
1895 | /* If stack checking is disabled, we can use r10 as the PIC register, |
1896 | which keeps r9 available. The EABI specifies r9 as the PIC register. */ | |
1897 | if (flag_pic && TARGET_SINGLE_PIC_BASE) | |
9403b7f7 RS |
1898 | { |
1899 | if (TARGET_VXWORKS_RTP) | |
1900 | warning (0, "RTP PIC is incompatible with -msingle-pic-base"); | |
1901 | arm_pic_register = (TARGET_APCS_STACK || TARGET_AAPCS_BASED) ? 9 : 10; | |
1902 | } | |
1903 | ||
1904 | if (flag_pic && TARGET_VXWORKS_RTP) | |
1905 | arm_pic_register = 9; | |
c147eacb | 1906 | |
ed0e6530 PB |
1907 | if (arm_pic_register_string != NULL) |
1908 | { | |
5b43fed1 | 1909 | int pic_register = decode_reg_name (arm_pic_register_string); |
e26053d1 | 1910 | |
5895f793 | 1911 | if (!flag_pic) |
d4ee4d25 | 1912 | warning (0, "-mpic-register= is useless without -fpic"); |
ed0e6530 | 1913 | |
ed0e6530 | 1914 | /* Prevent the user from choosing an obviously stupid PIC register. */ |
5b43fed1 RH |
1915 | else if (pic_register < 0 || call_used_regs[pic_register] |
1916 | || pic_register == HARD_FRAME_POINTER_REGNUM | |
1917 | || pic_register == STACK_POINTER_REGNUM | |
9403b7f7 RS |
1918 | || pic_register >= PC_REGNUM |
1919 | || (TARGET_VXWORKS_RTP | |
1920 | && (unsigned int) pic_register != arm_pic_register)) | |
c725bd79 | 1921 | error ("unable to use '%s' for PIC register", arm_pic_register_string); |
ed0e6530 PB |
1922 | else |
1923 | arm_pic_register = pic_register; | |
1924 | } | |
d5b7b3ae | 1925 | |
5fd42423 PB |
1926 | /* Enable -mfix-cortex-m3-ldrd by default for Cortex-M3 cores. */ |
1927 | if (fix_cm3_ldrd == 2) | |
1928 | { | |
12a0a4d4 | 1929 | if (arm_selected_cpu->core == cortexm3) |
5fd42423 PB |
1930 | fix_cm3_ldrd = 1; |
1931 | else | |
1932 | fix_cm3_ldrd = 0; | |
1933 | } | |
1934 | ||
4aef21c8 | 1935 | if (TARGET_THUMB1 && flag_schedule_insns) |
d5b7b3ae RE |
1936 | { |
1937 | /* Don't warn since it's on by default in -O2. */ | |
1938 | flag_schedule_insns = 0; | |
1939 | } | |
1940 | ||
f5a1b0d2 | 1941 | if (optimize_size) |
be03ccc9 | 1942 | { |
be03ccc9 | 1943 | /* If optimizing for size, bump the number of instructions that we |
d6b4baa4 | 1944 | are prepared to conditionally execute (even on a StrongARM). */ |
be03ccc9 NP |
1945 | max_insns_skipped = 6; |
1946 | } | |
1947 | else | |
1948 | { | |
be03ccc9 NP |
1949 | /* StrongARM has early execution of branches, so a sequence |
1950 | that is worth skipping is shorter. */ | |
abac3b49 | 1951 | if (arm_tune_strongarm) |
be03ccc9 NP |
1952 | max_insns_skipped = 3; |
1953 | } | |
92a432f4 | 1954 | |
70041f8a RE |
1955 | /* Hot/Cold partitioning is not currently supported, since we can't |
1956 | handle literal pool placement in that case. */ | |
1957 | if (flag_reorder_blocks_and_partition) | |
1958 | { | |
1959 | inform (input_location, | |
1960 | "-freorder-blocks-and-partition not supported on this architecture"); | |
1961 | flag_reorder_blocks_and_partition = 0; | |
1962 | flag_reorder_blocks = 1; | |
1963 | } | |
1964 | ||
128dc8e2 | 1965 | if (flag_pic) |
ec3728ad MK |
1966 | /* Hoisting PIC address calculations more aggressively provides a small, |
1967 | but measurable, size reduction for PIC code. Therefore, we decrease | |
1968 | the bar for unrestricted expression hoisting to the cost of PIC address | |
1969 | calculation, which is 2 instructions. */ | |
48476d13 JM |
1970 | maybe_set_param_value (PARAM_GCSE_UNRESTRICTED_COST, 2, |
1971 | global_options.x_param_values, | |
1972 | global_options_set.x_param_values); | |
ec3728ad | 1973 | |
f5c88dbf JZ |
1974 | /* ARM EABI defaults to strict volatile bitfields. */ |
1975 | if (TARGET_AAPCS_BASED && flag_strict_volatile_bitfields < 0) | |
1976 | flag_strict_volatile_bitfields = 1; | |
1977 | ||
92a432f4 RE |
1978 | /* Register global variables with the garbage collector. */ |
1979 | arm_add_gc_roots (); | |
1980 | } | |
1981 | ||
1982 | static void | |
e32bac5b | 1983 | arm_add_gc_roots (void) |
92a432f4 | 1984 | { |
c7319d87 RE |
1985 | gcc_obstack_init(&minipool_obstack); |
1986 | minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0); | |
2b835d68 | 1987 | } |
cce8749e | 1988 | \f |
6d3d9133 NC |
1989 | /* A table of known ARM exception types. |
1990 | For use with the interrupt function attribute. */ | |
1991 | ||
1992 | typedef struct | |
1993 | { | |
8b60264b KG |
1994 | const char *const arg; |
1995 | const unsigned long return_value; | |
6d3d9133 NC |
1996 | } |
1997 | isr_attribute_arg; | |
1998 | ||
8b60264b | 1999 | static const isr_attribute_arg isr_attribute_args [] = |
6d3d9133 NC |
2000 | { |
2001 | { "IRQ", ARM_FT_ISR }, | |
2002 | { "irq", ARM_FT_ISR }, | |
2003 | { "FIQ", ARM_FT_FIQ }, | |
2004 | { "fiq", ARM_FT_FIQ }, | |
2005 | { "ABORT", ARM_FT_ISR }, | |
2006 | { "abort", ARM_FT_ISR }, | |
2007 | { "ABORT", ARM_FT_ISR }, | |
2008 | { "abort", ARM_FT_ISR }, | |
2009 | { "UNDEF", ARM_FT_EXCEPTION }, | |
2010 | { "undef", ARM_FT_EXCEPTION }, | |
2011 | { "SWI", ARM_FT_EXCEPTION }, | |
2012 | { "swi", ARM_FT_EXCEPTION }, | |
2013 | { NULL, ARM_FT_NORMAL } | |
2014 | }; | |
2015 | ||
2016 | /* Returns the (interrupt) function type of the current | |
2017 | function, or ARM_FT_UNKNOWN if the type cannot be determined. */ | |
2018 | ||
2019 | static unsigned long | |
e32bac5b | 2020 | arm_isr_value (tree argument) |
6d3d9133 | 2021 | { |
8b60264b | 2022 | const isr_attribute_arg * ptr; |
1d6e90ac | 2023 | const char * arg; |
6d3d9133 | 2024 | |
5b3e6663 PB |
2025 | if (!arm_arch_notm) |
2026 | return ARM_FT_NORMAL | ARM_FT_STACKALIGN; | |
2027 | ||
6d3d9133 NC |
2028 | /* No argument - default to IRQ. */ |
2029 | if (argument == NULL_TREE) | |
2030 | return ARM_FT_ISR; | |
2031 | ||
2032 | /* Get the value of the argument. */ | |
2033 | if (TREE_VALUE (argument) == NULL_TREE | |
2034 | || TREE_CODE (TREE_VALUE (argument)) != STRING_CST) | |
2035 | return ARM_FT_UNKNOWN; | |
2036 | ||
2037 | arg = TREE_STRING_POINTER (TREE_VALUE (argument)); | |
2038 | ||
2039 | /* Check it against the list of known arguments. */ | |
5a9335ef | 2040 | for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++) |
1d6e90ac NC |
2041 | if (streq (arg, ptr->arg)) |
2042 | return ptr->return_value; | |
6d3d9133 | 2043 | |
05713b80 | 2044 | /* An unrecognized interrupt type. */ |
6d3d9133 NC |
2045 | return ARM_FT_UNKNOWN; |
2046 | } | |
2047 | ||
2048 | /* Computes the type of the current function. */ | |
2049 | ||
2050 | static unsigned long | |
e32bac5b | 2051 | arm_compute_func_type (void) |
6d3d9133 NC |
2052 | { |
2053 | unsigned long type = ARM_FT_UNKNOWN; | |
2054 | tree a; | |
2055 | tree attr; | |
f676971a | 2056 | |
e6d29d15 | 2057 | gcc_assert (TREE_CODE (current_function_decl) == FUNCTION_DECL); |
6d3d9133 NC |
2058 | |
2059 | /* Decide if the current function is volatile. Such functions | |
2060 | never return, and many memory cycles can be saved by not storing | |
2061 | register values that will never be needed again. This optimization | |
2062 | was added to speed up context switching in a kernel application. */ | |
2063 | if (optimize > 0 | |
cf1955dc PB |
2064 | && (TREE_NOTHROW (current_function_decl) |
2065 | || !(flag_unwind_tables | |
f0a0390e | 2066 | || (flag_exceptions && arm_except_unwind_info () != UI_SJLJ))) |
6d3d9133 NC |
2067 | && TREE_THIS_VOLATILE (current_function_decl)) |
2068 | type |= ARM_FT_VOLATILE; | |
f676971a | 2069 | |
6de9cd9a | 2070 | if (cfun->static_chain_decl != NULL) |
6d3d9133 NC |
2071 | type |= ARM_FT_NESTED; |
2072 | ||
91d231cb | 2073 | attr = DECL_ATTRIBUTES (current_function_decl); |
f676971a | 2074 | |
6d3d9133 NC |
2075 | a = lookup_attribute ("naked", attr); |
2076 | if (a != NULL_TREE) | |
2077 | type |= ARM_FT_NAKED; | |
2078 | ||
c9ca9b88 PB |
2079 | a = lookup_attribute ("isr", attr); |
2080 | if (a == NULL_TREE) | |
2081 | a = lookup_attribute ("interrupt", attr); | |
f676971a | 2082 | |
c9ca9b88 PB |
2083 | if (a == NULL_TREE) |
2084 | type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL; | |
6d3d9133 | 2085 | else |
c9ca9b88 | 2086 | type |= arm_isr_value (TREE_VALUE (a)); |
f676971a | 2087 | |
6d3d9133 NC |
2088 | return type; |
2089 | } | |
2090 | ||
2091 | /* Returns the type of the current function. */ | |
2092 | ||
2093 | unsigned long | |
e32bac5b | 2094 | arm_current_func_type (void) |
6d3d9133 NC |
2095 | { |
2096 | if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN) | |
2097 | cfun->machine->func_type = arm_compute_func_type (); | |
2098 | ||
2099 | return cfun->machine->func_type; | |
2100 | } | |
007e61c2 PB |
2101 | |
2102 | bool | |
2103 | arm_allocate_stack_slots_for_args (void) | |
2104 | { | |
2105 | /* Naked functions should not allocate stack slots for arguments. */ | |
2106 | return !IS_NAKED (arm_current_func_type ()); | |
2107 | } | |
2108 | ||
0ef9304b RH |
2109 | \f |
2110 | /* Output assembler code for a block containing the constant parts | |
2111 | of a trampoline, leaving space for the variable parts. | |
2112 | ||
2113 | On the ARM, (if r8 is the static chain regnum, and remembering that | |
2114 | referencing pc adds an offset of 8) the trampoline looks like: | |
2115 | ldr r8, [pc, #0] | |
2116 | ldr pc, [pc] | |
2117 | .word static chain value | |
2118 | .word function's address | |
2119 | XXX FIXME: When the trampoline returns, r8 will be clobbered. */ | |
2120 | ||
2121 | static void | |
2122 | arm_asm_trampoline_template (FILE *f) | |
2123 | { | |
2124 | if (TARGET_ARM) | |
2125 | { | |
2126 | asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", STATIC_CHAIN_REGNUM, PC_REGNUM); | |
2127 | asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", PC_REGNUM, PC_REGNUM); | |
2128 | } | |
2129 | else if (TARGET_THUMB2) | |
2130 | { | |
2131 | /* The Thumb-2 trampoline is similar to the arm implementation. | |
2132 | Unlike 16-bit Thumb, we enter the stub in thumb mode. */ | |
2133 | asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n", | |
2134 | STATIC_CHAIN_REGNUM, PC_REGNUM); | |
2135 | asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n", PC_REGNUM, PC_REGNUM); | |
2136 | } | |
2137 | else | |
2138 | { | |
2139 | ASM_OUTPUT_ALIGN (f, 2); | |
2140 | fprintf (f, "\t.code\t16\n"); | |
2141 | fprintf (f, ".Ltrampoline_start:\n"); | |
2142 | asm_fprintf (f, "\tpush\t{r0, r1}\n"); | |
2143 | asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM); | |
2144 | asm_fprintf (f, "\tmov\t%r, r0\n", STATIC_CHAIN_REGNUM); | |
2145 | asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM); | |
2146 | asm_fprintf (f, "\tstr\tr0, [%r, #4]\n", SP_REGNUM); | |
2147 | asm_fprintf (f, "\tpop\t{r0, %r}\n", PC_REGNUM); | |
2148 | } | |
2149 | assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); | |
2150 | assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); | |
2151 | } | |
2152 | ||
2153 | /* Emit RTL insns to initialize the variable parts of a trampoline. */ | |
2154 | ||
2155 | static void | |
2156 | arm_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) | |
2157 | { | |
2158 | rtx fnaddr, mem, a_tramp; | |
2159 | ||
2160 | emit_block_move (m_tramp, assemble_trampoline_template (), | |
2161 | GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL); | |
2162 | ||
2163 | mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 8 : 12); | |
2164 | emit_move_insn (mem, chain_value); | |
2165 | ||
2166 | mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 12 : 16); | |
2167 | fnaddr = XEXP (DECL_RTL (fndecl), 0); | |
2168 | emit_move_insn (mem, fnaddr); | |
2169 | ||
2170 | a_tramp = XEXP (m_tramp, 0); | |
2171 | emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"), | |
2172 | LCT_NORMAL, VOIDmode, 2, a_tramp, Pmode, | |
2173 | plus_constant (a_tramp, TRAMPOLINE_SIZE), Pmode); | |
2174 | } | |
2175 | ||
2176 | /* Thumb trampolines should be entered in thumb mode, so set | |
2177 | the bottom bit of the address. */ | |
2178 | ||
2179 | static rtx | |
2180 | arm_trampoline_adjust_address (rtx addr) | |
2181 | { | |
2182 | if (TARGET_THUMB) | |
2183 | addr = expand_simple_binop (Pmode, IOR, addr, const1_rtx, | |
2184 | NULL, 0, OPTAB_LIB_WIDEN); | |
2185 | return addr; | |
2186 | } | |
6d3d9133 | 2187 | \f |
f676971a | 2188 | /* Return 1 if it is possible to return using a single instruction. |
a72d4945 RE |
2189 | If SIBLING is non-null, this is a test for a return before a sibling |
2190 | call. SIBLING is the call insn, so we can examine its register usage. */ | |
6d3d9133 | 2191 | |
ff9940b0 | 2192 | int |
a72d4945 | 2193 | use_return_insn (int iscond, rtx sibling) |
ff9940b0 RE |
2194 | { |
2195 | int regno; | |
9b598fa0 | 2196 | unsigned int func_type; |
d5db54a1 | 2197 | unsigned long saved_int_regs; |
a72d4945 | 2198 | unsigned HOST_WIDE_INT stack_adjust; |
5848830f | 2199 | arm_stack_offsets *offsets; |
ff9940b0 | 2200 | |
d5b7b3ae | 2201 | /* Never use a return instruction before reload has run. */ |
6d3d9133 NC |
2202 | if (!reload_completed) |
2203 | return 0; | |
efc2515b | 2204 | |
9b598fa0 RE |
2205 | func_type = arm_current_func_type (); |
2206 | ||
5b3e6663 | 2207 | /* Naked, volatile and stack alignment functions need special |
3a7731fd | 2208 | consideration. */ |
5b3e6663 | 2209 | if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED | ARM_FT_STACKALIGN)) |
6d3d9133 | 2210 | return 0; |
06bea5aa | 2211 | |
a15908a4 PB |
2212 | /* So do interrupt functions that use the frame pointer and Thumb |
2213 | interrupt functions. */ | |
2214 | if (IS_INTERRUPT (func_type) && (frame_pointer_needed || TARGET_THUMB)) | |
06bea5aa | 2215 | return 0; |
a72d4945 | 2216 | |
5848830f PB |
2217 | offsets = arm_get_frame_offsets (); |
2218 | stack_adjust = offsets->outgoing_args - offsets->saved_regs; | |
a72d4945 | 2219 | |
6d3d9133 | 2220 | /* As do variadic functions. */ |
38173d38 | 2221 | if (crtl->args.pretend_args_size |
3cb66fd7 | 2222 | || cfun->machine->uses_anonymous_args |
699a4925 | 2223 | /* Or if the function calls __builtin_eh_return () */ |
e3b5732b | 2224 | || crtl->calls_eh_return |
699a4925 | 2225 | /* Or if the function calls alloca */ |
e3b5732b | 2226 | || cfun->calls_alloca |
a72d4945 RE |
2227 | /* Or if there is a stack adjustment. However, if the stack pointer |
2228 | is saved on the stack, we can use a pre-incrementing stack load. */ | |
ec6237e4 PB |
2229 | || !(stack_adjust == 0 || (TARGET_APCS_FRAME && frame_pointer_needed |
2230 | && stack_adjust == 4))) | |
ff9940b0 RE |
2231 | return 0; |
2232 | ||
954954d1 | 2233 | saved_int_regs = offsets->saved_regs_mask; |
d5db54a1 | 2234 | |
a72d4945 RE |
2235 | /* Unfortunately, the insn |
2236 | ||
2237 | ldmib sp, {..., sp, ...} | |
2238 | ||
2239 | triggers a bug on most SA-110 based devices, such that the stack | |
2240 | pointer won't be correctly restored if the instruction takes a | |
839a4992 | 2241 | page fault. We work around this problem by popping r3 along with |
a72d4945 | 2242 | the other registers, since that is never slower than executing |
f676971a | 2243 | another instruction. |
a72d4945 RE |
2244 | |
2245 | We test for !arm_arch5 here, because code for any architecture | |
2246 | less than this could potentially be run on one of the buggy | |
2247 | chips. */ | |
5b3e6663 | 2248 | if (stack_adjust == 4 && !arm_arch5 && TARGET_ARM) |
a72d4945 RE |
2249 | { |
2250 | /* Validate that r3 is a call-clobbered register (always true in | |
d6b4baa4 | 2251 | the default abi) ... */ |
a72d4945 RE |
2252 | if (!call_used_regs[3]) |
2253 | return 0; | |
2254 | ||
4f5dfed0 JC |
2255 | /* ... that it isn't being used for a return value ... */ |
2256 | if (arm_size_return_regs () >= (4 * UNITS_PER_WORD)) | |
2257 | return 0; | |
2258 | ||
2259 | /* ... or for a tail-call argument ... */ | |
a72d4945 RE |
2260 | if (sibling) |
2261 | { | |
e6d29d15 | 2262 | gcc_assert (GET_CODE (sibling) == CALL_INSN); |
a72d4945 RE |
2263 | |
2264 | if (find_regno_fusage (sibling, USE, 3)) | |
2265 | return 0; | |
2266 | } | |
2267 | ||
2268 | /* ... and that there are no call-saved registers in r0-r2 | |
2269 | (always true in the default ABI). */ | |
2270 | if (saved_int_regs & 0x7) | |
2271 | return 0; | |
2272 | } | |
2273 | ||
b111229a | 2274 | /* Can't be done if interworking with Thumb, and any registers have been |
d5db54a1 | 2275 | stacked. */ |
a15908a4 | 2276 | if (TARGET_INTERWORK && saved_int_regs != 0 && !IS_INTERRUPT(func_type)) |
b36ba79f | 2277 | return 0; |
d5db54a1 RE |
2278 | |
2279 | /* On StrongARM, conditional returns are expensive if they aren't | |
2280 | taken and multiple registers have been stacked. */ | |
abac3b49 | 2281 | if (iscond && arm_tune_strongarm) |
6ed30148 | 2282 | { |
f676971a | 2283 | /* Conditional return when just the LR is stored is a simple |
d5db54a1 RE |
2284 | conditional-load instruction, that's not expensive. */ |
2285 | if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM)) | |
2286 | return 0; | |
6ed30148 | 2287 | |
020a4035 RE |
2288 | if (flag_pic |
2289 | && arm_pic_register != INVALID_REGNUM | |
6fb5fa3c | 2290 | && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM)) |
b111229a | 2291 | return 0; |
6ed30148 | 2292 | } |
d5db54a1 RE |
2293 | |
2294 | /* If there are saved registers but the LR isn't saved, then we need | |
2295 | two instructions for the return. */ | |
2296 | if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM))) | |
2297 | return 0; | |
2298 | ||
3b684012 | 2299 | /* Can't be done if any of the FPA regs are pushed, |
6d3d9133 | 2300 | since this also requires an insn. */ |
9b66ebb1 PB |
2301 | if (TARGET_HARD_FLOAT && TARGET_FPA) |
2302 | for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++) | |
6fb5fa3c | 2303 | if (df_regs_ever_live_p (regno) && !call_used_regs[regno]) |
9b66ebb1 PB |
2304 | return 0; |
2305 | ||
2306 | /* Likewise VFP regs. */ | |
2307 | if (TARGET_HARD_FLOAT && TARGET_VFP) | |
2308 | for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++) | |
6fb5fa3c | 2309 | if (df_regs_ever_live_p (regno) && !call_used_regs[regno]) |
d5b7b3ae | 2310 | return 0; |
ff9940b0 | 2311 | |
5a9335ef NC |
2312 | if (TARGET_REALLY_IWMMXT) |
2313 | for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++) | |
6fb5fa3c | 2314 | if (df_regs_ever_live_p (regno) && ! call_used_regs[regno]) |
5a9335ef NC |
2315 | return 0; |
2316 | ||
ff9940b0 RE |
2317 | return 1; |
2318 | } | |
2319 | ||
cce8749e CH |
2320 | /* Return TRUE if int I is a valid immediate ARM constant. */ |
2321 | ||
2322 | int | |
e32bac5b | 2323 | const_ok_for_arm (HOST_WIDE_INT i) |
cce8749e | 2324 | { |
4642ccb1 | 2325 | int lowbit; |
e0b92319 | 2326 | |
f676971a | 2327 | /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must |
56636818 | 2328 | be all zero, or all one. */ |
30cf4896 KG |
2329 | if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0 |
2330 | && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) | |
2331 | != ((~(unsigned HOST_WIDE_INT) 0) | |
2332 | & ~(unsigned HOST_WIDE_INT) 0xffffffff))) | |
56636818 | 2333 | return FALSE; |
f676971a | 2334 | |
4642ccb1 | 2335 | i &= (unsigned HOST_WIDE_INT) 0xffffffff; |
e0b92319 | 2336 | |
4642ccb1 RE |
2337 | /* Fast return for 0 and small values. We must do this for zero, since |
2338 | the code below can't handle that one case. */ | |
2339 | if ((i & ~(unsigned HOST_WIDE_INT) 0xff) == 0) | |
e2c671ba RE |
2340 | return TRUE; |
2341 | ||
5b3e6663 PB |
2342 | /* Get the number of trailing zeros. */ |
2343 | lowbit = ffs((int) i) - 1; | |
2344 | ||
2345 | /* Only even shifts are allowed in ARM mode so round down to the | |
2346 | nearest even number. */ | |
2347 | if (TARGET_ARM) | |
2348 | lowbit &= ~1; | |
4642ccb1 RE |
2349 | |
2350 | if ((i & ~(((unsigned HOST_WIDE_INT) 0xff) << lowbit)) == 0) | |
2351 | return TRUE; | |
5b3e6663 PB |
2352 | |
2353 | if (TARGET_ARM) | |
2354 | { | |
2355 | /* Allow rotated constants in ARM mode. */ | |
2356 | if (lowbit <= 4 | |
4642ccb1 RE |
2357 | && ((i & ~0xc000003f) == 0 |
2358 | || (i & ~0xf000000f) == 0 | |
2359 | || (i & ~0xfc000003) == 0)) | |
5b3e6663 PB |
2360 | return TRUE; |
2361 | } | |
2362 | else | |
2363 | { | |
2364 | HOST_WIDE_INT v; | |
2365 | ||
d724c8f0 | 2366 | /* Allow repeated patterns 0x00XY00XY or 0xXYXYXYXY. */ |
5b3e6663 PB |
2367 | v = i & 0xff; |
2368 | v |= v << 16; | |
2369 | if (i == v || i == (v | (v << 8))) | |
2370 | return TRUE; | |
d724c8f0 AS |
2371 | |
2372 | /* Allow repeated pattern 0xXY00XY00. */ | |
2373 | v = i & 0xff00; | |
2374 | v |= v << 16; | |
2375 | if (i == v) | |
2376 | return TRUE; | |
5b3e6663 | 2377 | } |
cce8749e | 2378 | |
f3bb6135 RE |
2379 | return FALSE; |
2380 | } | |
cce8749e | 2381 | |
6354dc9b | 2382 | /* Return true if I is a valid constant for the operation CODE. */ |
74bbc178 | 2383 | static int |
e32bac5b | 2384 | const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code) |
e2c671ba RE |
2385 | { |
2386 | if (const_ok_for_arm (i)) | |
2387 | return 1; | |
2388 | ||
2389 | switch (code) | |
2390 | { | |
2391 | case PLUS: | |
d5a0a47b RE |
2392 | case COMPARE: |
2393 | case EQ: | |
2394 | case NE: | |
2395 | case GT: | |
2396 | case LE: | |
2397 | case LT: | |
2398 | case GE: | |
2399 | case GEU: | |
2400 | case LTU: | |
2401 | case GTU: | |
2402 | case LEU: | |
2403 | case UNORDERED: | |
2404 | case ORDERED: | |
2405 | case UNEQ: | |
2406 | case UNGE: | |
2407 | case UNLT: | |
2408 | case UNGT: | |
2409 | case UNLE: | |
e2c671ba RE |
2410 | return const_ok_for_arm (ARM_SIGN_EXTEND (-i)); |
2411 | ||
2412 | case MINUS: /* Should only occur with (MINUS I reg) => rsb */ | |
2413 | case XOR: | |
a7994a57 RR |
2414 | return 0; |
2415 | ||
e2c671ba | 2416 | case IOR: |
a7994a57 RR |
2417 | if (TARGET_THUMB2) |
2418 | return const_ok_for_arm (ARM_SIGN_EXTEND (~i)); | |
e2c671ba RE |
2419 | return 0; |
2420 | ||
2421 | case AND: | |
2422 | return const_ok_for_arm (ARM_SIGN_EXTEND (~i)); | |
2423 | ||
2424 | default: | |
e6d29d15 | 2425 | gcc_unreachable (); |
e2c671ba RE |
2426 | } |
2427 | } | |
2428 | ||
2429 | /* Emit a sequence of insns to handle a large constant. | |
2430 | CODE is the code of the operation required, it can be any of SET, PLUS, | |
2431 | IOR, AND, XOR, MINUS; | |
2432 | MODE is the mode in which the operation is being performed; | |
2433 | VAL is the integer to operate on; | |
2434 | SOURCE is the other operand (a register, or a null-pointer for SET); | |
2435 | SUBTARGETS means it is safe to create scratch registers if that will | |
2b835d68 RE |
2436 | either produce a simpler sequence, or we will want to cse the values. |
2437 | Return value is the number of insns emitted. */ | |
e2c671ba | 2438 | |
5b3e6663 | 2439 | /* ??? Tweak this for thumb2. */ |
e2c671ba | 2440 | int |
a406f566 | 2441 | arm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn, |
e32bac5b | 2442 | HOST_WIDE_INT val, rtx target, rtx source, int subtargets) |
2b835d68 | 2443 | { |
a406f566 MM |
2444 | rtx cond; |
2445 | ||
2446 | if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC) | |
2447 | cond = COND_EXEC_TEST (PATTERN (insn)); | |
2448 | else | |
2449 | cond = NULL_RTX; | |
2450 | ||
2b835d68 RE |
2451 | if (subtargets || code == SET |
2452 | || (GET_CODE (target) == REG && GET_CODE (source) == REG | |
2453 | && REGNO (target) != REGNO (source))) | |
2454 | { | |
4b632bf1 | 2455 | /* After arm_reorg has been called, we can't fix up expensive |
05713b80 | 2456 | constants by pushing them into memory so we must synthesize |
4b632bf1 RE |
2457 | them in-line, regardless of the cost. This is only likely to |
2458 | be more costly on chips that have load delay slots and we are | |
2459 | compiling without running the scheduler (so no splitting | |
aec3cfba NC |
2460 | occurred before the final instruction emission). |
2461 | ||
2462 | Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c | |
aec3cfba | 2463 | */ |
5895f793 | 2464 | if (!after_arm_reorg |
a406f566 | 2465 | && !cond |
f676971a | 2466 | && (arm_gen_constant (code, mode, NULL_RTX, val, target, source, |
a406f566 | 2467 | 1, 0) |
1b78f575 RE |
2468 | > (arm_constant_limit (optimize_function_for_size_p (cfun)) |
2469 | + (code != SET)))) | |
2b835d68 RE |
2470 | { |
2471 | if (code == SET) | |
2472 | { | |
2473 | /* Currently SET is the only monadic value for CODE, all | |
2474 | the rest are diadic. */ | |
571191af PB |
2475 | if (TARGET_USE_MOVT) |
2476 | arm_emit_movpair (target, GEN_INT (val)); | |
2477 | else | |
2478 | emit_set_insn (target, GEN_INT (val)); | |
2479 | ||
2b835d68 RE |
2480 | return 1; |
2481 | } | |
2482 | else | |
2483 | { | |
2484 | rtx temp = subtargets ? gen_reg_rtx (mode) : target; | |
2485 | ||
571191af PB |
2486 | if (TARGET_USE_MOVT) |
2487 | arm_emit_movpair (temp, GEN_INT (val)); | |
2488 | else | |
2489 | emit_set_insn (temp, GEN_INT (val)); | |
2490 | ||
2b835d68 RE |
2491 | /* For MINUS, the value is subtracted from, since we never |
2492 | have subtraction of a constant. */ | |
2493 | if (code == MINUS) | |
d66437c5 | 2494 | emit_set_insn (target, gen_rtx_MINUS (mode, temp, source)); |
2b835d68 | 2495 | else |
d66437c5 RE |
2496 | emit_set_insn (target, |
2497 | gen_rtx_fmt_ee (code, mode, source, temp)); | |
2b835d68 RE |
2498 | return 2; |
2499 | } | |
2500 | } | |
2501 | } | |
2502 | ||
f676971a | 2503 | return arm_gen_constant (code, mode, cond, val, target, source, subtargets, |
a406f566 | 2504 | 1); |
2b835d68 RE |
2505 | } |
2506 | ||
162e4591 RE |
2507 | /* Return the number of instructions required to synthesize the given |
2508 | constant, if we start emitting them from bit-position I. */ | |
ceebdb09 | 2509 | static int |
e32bac5b | 2510 | count_insns_for_constant (HOST_WIDE_INT remainder, int i) |
ceebdb09 PB |
2511 | { |
2512 | HOST_WIDE_INT temp1; | |
162e4591 | 2513 | int step_size = TARGET_ARM ? 2 : 1; |
ceebdb09 | 2514 | int num_insns = 0; |
162e4591 RE |
2515 | |
2516 | gcc_assert (TARGET_ARM || i == 0); | |
2517 | ||
ceebdb09 PB |
2518 | do |
2519 | { | |
2520 | int end; | |
f676971a | 2521 | |
ceebdb09 PB |
2522 | if (i <= 0) |
2523 | i += 32; | |
162e4591 | 2524 | if (remainder & (((1 << step_size) - 1) << (i - step_size))) |
ceebdb09 PB |
2525 | { |
2526 | end = i - 8; | |
2527 | if (end < 0) | |
2528 | end += 32; | |
2529 | temp1 = remainder & ((0x0ff << end) | |
2530 | | ((i < end) ? (0xff >> (32 - end)) : 0)); | |
2531 | remainder &= ~temp1; | |
2532 | num_insns++; | |
162e4591 | 2533 | i -= 8 - step_size; |
ceebdb09 | 2534 | } |
162e4591 | 2535 | i -= step_size; |
ceebdb09 PB |
2536 | } while (remainder); |
2537 | return num_insns; | |
2538 | } | |
2539 | ||
162e4591 | 2540 | static int |
90e77553 | 2541 | find_best_start (unsigned HOST_WIDE_INT remainder) |
162e4591 RE |
2542 | { |
2543 | int best_consecutive_zeros = 0; | |
2544 | int i; | |
2545 | int best_start = 0; | |
2546 | ||
2547 | /* If we aren't targetting ARM, the best place to start is always at | |
2548 | the bottom. */ | |
2549 | if (! TARGET_ARM) | |
2550 | return 0; | |
2551 | ||
2552 | for (i = 0; i < 32; i += 2) | |
2553 | { | |
2554 | int consecutive_zeros = 0; | |
2555 | ||
2556 | if (!(remainder & (3 << i))) | |
2557 | { | |
2558 | while ((i < 32) && !(remainder & (3 << i))) | |
2559 | { | |
2560 | consecutive_zeros += 2; | |
2561 | i += 2; | |
2562 | } | |
2563 | if (consecutive_zeros > best_consecutive_zeros) | |
2564 | { | |
2565 | best_consecutive_zeros = consecutive_zeros; | |
2566 | best_start = i - consecutive_zeros; | |
2567 | } | |
2568 | i -= 2; | |
2569 | } | |
2570 | } | |
2571 | ||
2572 | /* So long as it won't require any more insns to do so, it's | |
2573 | desirable to emit a small constant (in bits 0...9) in the last | |
2574 | insn. This way there is more chance that it can be combined with | |
2575 | a later addressing insn to form a pre-indexed load or store | |
2576 | operation. Consider: | |
2577 | ||
2578 | *((volatile int *)0xe0000100) = 1; | |
2579 | *((volatile int *)0xe0000110) = 2; | |
2580 | ||
2581 | We want this to wind up as: | |
2582 | ||
2583 | mov rA, #0xe0000000 | |
2584 | mov rB, #1 | |
2585 | str rB, [rA, #0x100] | |
2586 | mov rB, #2 | |
2587 | str rB, [rA, #0x110] | |
2588 | ||
2589 | rather than having to synthesize both large constants from scratch. | |
2590 | ||
2591 | Therefore, we calculate how many insns would be required to emit | |
2592 | the constant starting from `best_start', and also starting from | |
2593 | zero (i.e. with bit 31 first to be output). If `best_start' doesn't | |
2594 | yield a shorter sequence, we may as well use zero. */ | |
2595 | if (best_start != 0 | |
2596 | && ((((unsigned HOST_WIDE_INT) 1) << best_start) < remainder) | |
2597 | && (count_insns_for_constant (remainder, 0) <= | |
2598 | count_insns_for_constant (remainder, best_start))) | |
2599 | best_start = 0; | |
2600 | ||
2601 | return best_start; | |
2602 | } | |
2603 | ||
a406f566 MM |
2604 | /* Emit an instruction with the indicated PATTERN. If COND is |
2605 | non-NULL, conditionalize the execution of the instruction on COND | |
2606 | being true. */ | |
2607 | ||
2608 | static void | |
2609 | emit_constant_insn (rtx cond, rtx pattern) | |
2610 | { | |
2611 | if (cond) | |
2612 | pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern); | |
2613 | emit_insn (pattern); | |
2614 | } | |
2615 | ||
2b835d68 RE |
2616 | /* As above, but extra parameter GENERATE which, if clear, suppresses |
2617 | RTL generation. */ | |
5b3e6663 | 2618 | /* ??? This needs more work for thumb2. */ |
1d6e90ac | 2619 | |
d5b7b3ae | 2620 | static int |
a406f566 | 2621 | arm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond, |
e32bac5b RE |
2622 | HOST_WIDE_INT val, rtx target, rtx source, int subtargets, |
2623 | int generate) | |
e2c671ba | 2624 | { |
e2c671ba RE |
2625 | int can_invert = 0; |
2626 | int can_negate = 0; | |
162e4591 | 2627 | int final_invert = 0; |
e2c671ba | 2628 | int can_negate_initial = 0; |
e2c671ba RE |
2629 | int i; |
2630 | int num_bits_set = 0; | |
2631 | int set_sign_bit_copies = 0; | |
2632 | int clear_sign_bit_copies = 0; | |
2633 | int clear_zero_bit_copies = 0; | |
2634 | int set_zero_bit_copies = 0; | |
2635 | int insns = 0; | |
e2c671ba | 2636 | unsigned HOST_WIDE_INT temp1, temp2; |
30cf4896 | 2637 | unsigned HOST_WIDE_INT remainder = val & 0xffffffff; |
162e4591 | 2638 | int step_size = TARGET_ARM ? 2 : 1; |
e2c671ba | 2639 | |
d5b7b3ae | 2640 | /* Find out which operations are safe for a given CODE. Also do a quick |
e2c671ba RE |
2641 | check for degenerate cases; these can occur when DImode operations |
2642 | are split. */ | |
2643 | switch (code) | |
2644 | { | |
2645 | case SET: | |
2646 | can_invert = 1; | |
e2c671ba RE |
2647 | can_negate = 1; |
2648 | break; | |
2649 | ||
2650 | case PLUS: | |
2651 | can_negate = 1; | |
2652 | can_negate_initial = 1; | |
2653 | break; | |
2654 | ||
2655 | case IOR: | |
30cf4896 | 2656 | if (remainder == 0xffffffff) |
e2c671ba | 2657 | { |
2b835d68 | 2658 | if (generate) |
a406f566 MM |
2659 | emit_constant_insn (cond, |
2660 | gen_rtx_SET (VOIDmode, target, | |
2661 | GEN_INT (ARM_SIGN_EXTEND (val)))); | |
e2c671ba RE |
2662 | return 1; |
2663 | } | |
a7994a57 | 2664 | |
e2c671ba RE |
2665 | if (remainder == 0) |
2666 | { | |
2667 | if (reload_completed && rtx_equal_p (target, source)) | |
2668 | return 0; | |
a7994a57 | 2669 | |
2b835d68 | 2670 | if (generate) |
a406f566 MM |
2671 | emit_constant_insn (cond, |
2672 | gen_rtx_SET (VOIDmode, target, source)); | |
e2c671ba RE |
2673 | return 1; |
2674 | } | |
a7994a57 RR |
2675 | |
2676 | if (TARGET_THUMB2) | |
2677 | can_invert = 1; | |
e2c671ba RE |
2678 | break; |
2679 | ||
2680 | case AND: | |
2681 | if (remainder == 0) | |
2682 | { | |
2b835d68 | 2683 | if (generate) |
a406f566 MM |
2684 | emit_constant_insn (cond, |
2685 | gen_rtx_SET (VOIDmode, target, const0_rtx)); | |
e2c671ba RE |
2686 | return 1; |
2687 | } | |
30cf4896 | 2688 | if (remainder == 0xffffffff) |
e2c671ba RE |
2689 | { |
2690 | if (reload_completed && rtx_equal_p (target, source)) | |
2691 | return 0; | |
2b835d68 | 2692 | if (generate) |
a406f566 MM |
2693 | emit_constant_insn (cond, |
2694 | gen_rtx_SET (VOIDmode, target, source)); | |
e2c671ba RE |
2695 | return 1; |
2696 | } | |
2697 | can_invert = 1; | |
2698 | break; | |
2699 | ||
2700 | case XOR: | |
2701 | if (remainder == 0) | |
2702 | { | |
2703 | if (reload_completed && rtx_equal_p (target, source)) | |
2704 | return 0; | |
2b835d68 | 2705 | if (generate) |
a406f566 MM |
2706 | emit_constant_insn (cond, |
2707 | gen_rtx_SET (VOIDmode, target, source)); | |
e2c671ba RE |
2708 | return 1; |
2709 | } | |
e0b92319 | 2710 | |
162e4591 RE |
2711 | if (remainder == 0xffffffff) |
2712 | { | |
2713 | if (generate) | |
2714 | emit_constant_insn (cond, | |
2715 | gen_rtx_SET (VOIDmode, target, | |
2716 | gen_rtx_NOT (mode, source))); | |
2717 | return 1; | |
2718 | } | |
2719 | break; | |
e2c671ba RE |
2720 | |
2721 | case MINUS: | |
2722 | /* We treat MINUS as (val - source), since (source - val) is always | |
2723 | passed as (source + (-val)). */ | |
2724 | if (remainder == 0) | |
2725 | { | |
2b835d68 | 2726 | if (generate) |
a406f566 MM |
2727 | emit_constant_insn (cond, |
2728 | gen_rtx_SET (VOIDmode, target, | |
2729 | gen_rtx_NEG (mode, source))); | |
e2c671ba RE |
2730 | return 1; |
2731 | } | |
2732 | if (const_ok_for_arm (val)) | |
2733 | { | |
2b835d68 | 2734 | if (generate) |
a406f566 | 2735 | emit_constant_insn (cond, |
f676971a | 2736 | gen_rtx_SET (VOIDmode, target, |
a406f566 MM |
2737 | gen_rtx_MINUS (mode, GEN_INT (val), |
2738 | source))); | |
e2c671ba RE |
2739 | return 1; |
2740 | } | |
2741 | can_negate = 1; | |
2742 | ||
2743 | break; | |
2744 | ||
2745 | default: | |
e6d29d15 | 2746 | gcc_unreachable (); |
e2c671ba RE |
2747 | } |
2748 | ||
6354dc9b | 2749 | /* If we can do it in one insn get out quickly. */ |
e2c671ba RE |
2750 | if (const_ok_for_arm (val) |
2751 | || (can_negate_initial && const_ok_for_arm (-val)) | |
2752 | || (can_invert && const_ok_for_arm (~val))) | |
2753 | { | |
2b835d68 | 2754 | if (generate) |
a406f566 MM |
2755 | emit_constant_insn (cond, |
2756 | gen_rtx_SET (VOIDmode, target, | |
f676971a | 2757 | (source |
a406f566 MM |
2758 | ? gen_rtx_fmt_ee (code, mode, source, |
2759 | GEN_INT (val)) | |
2760 | : GEN_INT (val)))); | |
e2c671ba RE |
2761 | return 1; |
2762 | } | |
2763 | ||
e2c671ba | 2764 | /* Calculate a few attributes that may be useful for specific |
6354dc9b | 2765 | optimizations. */ |
a7994a57 | 2766 | /* Count number of leading zeros. */ |
e2c671ba RE |
2767 | for (i = 31; i >= 0; i--) |
2768 | { | |
2769 | if ((remainder & (1 << i)) == 0) | |
2770 | clear_sign_bit_copies++; | |
2771 | else | |
2772 | break; | |
2773 | } | |
2774 | ||
a7994a57 | 2775 | /* Count number of leading 1's. */ |
e2c671ba RE |
2776 | for (i = 31; i >= 0; i--) |
2777 | { | |
2778 | if ((remainder & (1 << i)) != 0) | |
2779 | set_sign_bit_copies++; | |
2780 | else | |
2781 | break; | |
2782 | } | |
2783 | ||
a7994a57 | 2784 | /* Count number of trailing zero's. */ |
e2c671ba RE |
2785 | for (i = 0; i <= 31; i++) |
2786 | { | |
2787 | if ((remainder & (1 << i)) == 0) | |
2788 | clear_zero_bit_copies++; | |
2789 | else | |
2790 | break; | |
2791 | } | |
2792 | ||
a7994a57 | 2793 | /* Count number of trailing 1's. */ |
e2c671ba RE |
2794 | for (i = 0; i <= 31; i++) |
2795 | { | |
2796 | if ((remainder & (1 << i)) != 0) | |
2797 | set_zero_bit_copies++; | |
2798 | else | |
2799 | break; | |
2800 | } | |
2801 | ||
2802 | switch (code) | |
2803 | { | |
2804 | case SET: | |
5b3e6663 PB |
2805 | /* See if we can use movw. */ |
2806 | if (arm_arch_thumb2 && (remainder & 0xffff0000) == 0) | |
2807 | { | |
2808 | if (generate) | |
2809 | emit_constant_insn (cond, gen_rtx_SET (VOIDmode, target, | |
2810 | GEN_INT (val))); | |
2811 | return 1; | |
2812 | } | |
2813 | ||
e2c671ba RE |
2814 | /* See if we can do this by sign_extending a constant that is known |
2815 | to be negative. This is a good, way of doing it, since the shift | |
2816 | may well merge into a subsequent insn. */ | |
2817 | if (set_sign_bit_copies > 1) | |
2818 | { | |
2819 | if (const_ok_for_arm | |
f676971a | 2820 | (temp1 = ARM_SIGN_EXTEND (remainder |
e2c671ba RE |
2821 | << (set_sign_bit_copies - 1)))) |
2822 | { | |
2b835d68 RE |
2823 | if (generate) |
2824 | { | |
d499463f | 2825 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
a406f566 | 2826 | emit_constant_insn (cond, |
f676971a | 2827 | gen_rtx_SET (VOIDmode, new_src, |
a406f566 MM |
2828 | GEN_INT (temp1))); |
2829 | emit_constant_insn (cond, | |
f676971a | 2830 | gen_ashrsi3 (target, new_src, |
a406f566 | 2831 | GEN_INT (set_sign_bit_copies - 1))); |
2b835d68 | 2832 | } |
e2c671ba RE |
2833 | return 2; |
2834 | } | |
2835 | /* For an inverted constant, we will need to set the low bits, | |
2836 | these will be shifted out of harm's way. */ | |
2837 | temp1 |= (1 << (set_sign_bit_copies - 1)) - 1; | |
2838 | if (const_ok_for_arm (~temp1)) | |
2839 | { | |
2b835d68 RE |
2840 | if (generate) |
2841 | { | |
d499463f | 2842 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
a406f566 MM |
2843 | emit_constant_insn (cond, |
2844 | gen_rtx_SET (VOIDmode, new_src, | |
2845 | GEN_INT (temp1))); | |
2846 | emit_constant_insn (cond, | |
f676971a | 2847 | gen_ashrsi3 (target, new_src, |
a406f566 | 2848 | GEN_INT (set_sign_bit_copies - 1))); |
2b835d68 | 2849 | } |
e2c671ba RE |
2850 | return 2; |
2851 | } | |
2852 | } | |
2853 | ||
c87e6352 RE |
2854 | /* See if we can calculate the value as the difference between two |
2855 | valid immediates. */ | |
2856 | if (clear_sign_bit_copies + clear_zero_bit_copies <= 16) | |
2857 | { | |
2858 | int topshift = clear_sign_bit_copies & ~1; | |
2859 | ||
fa2c88a0 RE |
2860 | temp1 = ARM_SIGN_EXTEND ((remainder + (0x00800000 >> topshift)) |
2861 | & (0xff000000 >> topshift)); | |
c87e6352 RE |
2862 | |
2863 | /* If temp1 is zero, then that means the 9 most significant | |
2864 | bits of remainder were 1 and we've caused it to overflow. | |
2865 | When topshift is 0 we don't need to do anything since we | |
2866 | can borrow from 'bit 32'. */ | |
2867 | if (temp1 == 0 && topshift != 0) | |
2868 | temp1 = 0x80000000 >> (topshift - 1); | |
2869 | ||
fa2c88a0 | 2870 | temp2 = ARM_SIGN_EXTEND (temp1 - remainder); |
e0b92319 | 2871 | |
c87e6352 RE |
2872 | if (const_ok_for_arm (temp2)) |
2873 | { | |
2874 | if (generate) | |
2875 | { | |
2876 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; | |
2877 | emit_constant_insn (cond, | |
2878 | gen_rtx_SET (VOIDmode, new_src, | |
2879 | GEN_INT (temp1))); | |
2880 | emit_constant_insn (cond, | |
2881 | gen_addsi3 (target, new_src, | |
2882 | GEN_INT (-temp2))); | |
2883 | } | |
2884 | ||
2885 | return 2; | |
2886 | } | |
2887 | } | |
2888 | ||
e2c671ba RE |
2889 | /* See if we can generate this by setting the bottom (or the top) |
2890 | 16 bits, and then shifting these into the other half of the | |
2891 | word. We only look for the simplest cases, to do more would cost | |
2892 | too much. Be careful, however, not to generate this when the | |
2893 | alternative would take fewer insns. */ | |
30cf4896 | 2894 | if (val & 0xffff0000) |
e2c671ba | 2895 | { |
30cf4896 | 2896 | temp1 = remainder & 0xffff0000; |
e2c671ba RE |
2897 | temp2 = remainder & 0x0000ffff; |
2898 | ||
6354dc9b | 2899 | /* Overlaps outside this range are best done using other methods. */ |
e2c671ba RE |
2900 | for (i = 9; i < 24; i++) |
2901 | { | |
30cf4896 | 2902 | if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder) |
5895f793 | 2903 | && !const_ok_for_arm (temp2)) |
e2c671ba | 2904 | { |
d499463f RE |
2905 | rtx new_src = (subtargets |
2906 | ? (generate ? gen_reg_rtx (mode) : NULL_RTX) | |
2907 | : target); | |
a406f566 | 2908 | insns = arm_gen_constant (code, mode, cond, temp2, new_src, |
2b835d68 | 2909 | source, subtargets, generate); |
e2c671ba | 2910 | source = new_src; |
2b835d68 | 2911 | if (generate) |
f676971a | 2912 | emit_constant_insn |
a406f566 MM |
2913 | (cond, |
2914 | gen_rtx_SET | |
2915 | (VOIDmode, target, | |
2916 | gen_rtx_IOR (mode, | |
2917 | gen_rtx_ASHIFT (mode, source, | |
2918 | GEN_INT (i)), | |
2919 | source))); | |
e2c671ba RE |
2920 | return insns + 1; |
2921 | } | |
2922 | } | |
2923 | ||
6354dc9b | 2924 | /* Don't duplicate cases already considered. */ |
e2c671ba RE |
2925 | for (i = 17; i < 24; i++) |
2926 | { | |
2927 | if (((temp1 | (temp1 >> i)) == remainder) | |
5895f793 | 2928 | && !const_ok_for_arm (temp1)) |
e2c671ba | 2929 | { |
d499463f RE |
2930 | rtx new_src = (subtargets |
2931 | ? (generate ? gen_reg_rtx (mode) : NULL_RTX) | |
2932 | : target); | |
a406f566 | 2933 | insns = arm_gen_constant (code, mode, cond, temp1, new_src, |
2b835d68 | 2934 | source, subtargets, generate); |
e2c671ba | 2935 | source = new_src; |
2b835d68 | 2936 | if (generate) |
a406f566 MM |
2937 | emit_constant_insn |
2938 | (cond, | |
2939 | gen_rtx_SET (VOIDmode, target, | |
43cffd11 RE |
2940 | gen_rtx_IOR |
2941 | (mode, | |
2942 | gen_rtx_LSHIFTRT (mode, source, | |
2943 | GEN_INT (i)), | |
2944 | source))); | |
e2c671ba RE |
2945 | return insns + 1; |
2946 | } | |
2947 | } | |
2948 | } | |
2949 | break; | |
2950 | ||
2951 | case IOR: | |
2952 | case XOR: | |
7b64da89 RE |
2953 | /* If we have IOR or XOR, and the constant can be loaded in a |
2954 | single instruction, and we can find a temporary to put it in, | |
e2c671ba RE |
2955 | then this can be done in two instructions instead of 3-4. */ |
2956 | if (subtargets | |
d499463f | 2957 | /* TARGET can't be NULL if SUBTARGETS is 0 */ |
5895f793 | 2958 | || (reload_completed && !reg_mentioned_p (target, source))) |
e2c671ba | 2959 | { |
5895f793 | 2960 | if (const_ok_for_arm (ARM_SIGN_EXTEND (~val))) |
e2c671ba | 2961 | { |
2b835d68 RE |
2962 | if (generate) |
2963 | { | |
2964 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
e2c671ba | 2965 | |
a406f566 | 2966 | emit_constant_insn (cond, |
f676971a | 2967 | gen_rtx_SET (VOIDmode, sub, |
a406f566 MM |
2968 | GEN_INT (val))); |
2969 | emit_constant_insn (cond, | |
f676971a | 2970 | gen_rtx_SET (VOIDmode, target, |
a406f566 MM |
2971 | gen_rtx_fmt_ee (code, mode, |
2972 | source, sub))); | |
2b835d68 | 2973 | } |
e2c671ba RE |
2974 | return 2; |
2975 | } | |
2976 | } | |
2977 | ||
2978 | if (code == XOR) | |
2979 | break; | |
2980 | ||
a7994a57 RR |
2981 | /* Convert. |
2982 | x = y | constant ( which is composed of set_sign_bit_copies of leading 1s | |
2983 | and the remainder 0s for e.g. 0xfff00000) | |
2984 | x = ~(~(y ashift set_sign_bit_copies) lshiftrt set_sign_bit_copies) | |
2985 | ||
2986 | This can be done in 2 instructions by using shifts with mov or mvn. | |
2987 | e.g. for | |
2988 | x = x | 0xfff00000; | |
2989 | we generate. | |
2990 | mvn r0, r0, asl #12 | |
2991 | mvn r0, r0, lsr #12 */ | |
e2c671ba RE |
2992 | if (set_sign_bit_copies > 8 |
2993 | && (val & (-1 << (32 - set_sign_bit_copies))) == val) | |
2994 | { | |
2b835d68 RE |
2995 | if (generate) |
2996 | { | |
2997 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
2998 | rtx shift = GEN_INT (set_sign_bit_copies); | |
2999 | ||
f676971a | 3000 | emit_constant_insn |
a406f566 MM |
3001 | (cond, |
3002 | gen_rtx_SET (VOIDmode, sub, | |
f676971a | 3003 | gen_rtx_NOT (mode, |
a406f566 | 3004 | gen_rtx_ASHIFT (mode, |
f676971a | 3005 | source, |
a406f566 | 3006 | shift)))); |
f676971a | 3007 | emit_constant_insn |
a406f566 MM |
3008 | (cond, |
3009 | gen_rtx_SET (VOIDmode, target, | |
3010 | gen_rtx_NOT (mode, | |
3011 | gen_rtx_LSHIFTRT (mode, sub, | |
3012 | shift)))); | |
2b835d68 | 3013 | } |
e2c671ba RE |
3014 | return 2; |
3015 | } | |
3016 | ||
a7994a57 RR |
3017 | /* Convert |
3018 | x = y | constant (which has set_zero_bit_copies number of trailing ones). | |
3019 | to | |
3020 | x = ~((~y lshiftrt set_zero_bit_copies) ashift set_zero_bit_copies). | |
3021 | ||
3022 | For eg. r0 = r0 | 0xfff | |
3023 | mvn r0, r0, lsr #12 | |
3024 | mvn r0, r0, asl #12 | |
3025 | ||
3026 | */ | |
e2c671ba RE |
3027 | if (set_zero_bit_copies > 8 |
3028 | && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder) | |
3029 | { | |
2b835d68 RE |
3030 | if (generate) |
3031 | { | |
3032 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
3033 | rtx shift = GEN_INT (set_zero_bit_copies); | |
3034 | ||
a406f566 MM |
3035 | emit_constant_insn |
3036 | (cond, | |
3037 | gen_rtx_SET (VOIDmode, sub, | |
3038 | gen_rtx_NOT (mode, | |
3039 | gen_rtx_LSHIFTRT (mode, | |
3040 | source, | |
3041 | shift)))); | |
f676971a | 3042 | emit_constant_insn |
a406f566 MM |
3043 | (cond, |
3044 | gen_rtx_SET (VOIDmode, target, | |
3045 | gen_rtx_NOT (mode, | |
3046 | gen_rtx_ASHIFT (mode, sub, | |
3047 | shift)))); | |
2b835d68 | 3048 | } |
e2c671ba RE |
3049 | return 2; |
3050 | } | |
3051 | ||
a7994a57 RR |
3052 | /* This will never be reached for Thumb2 because orn is a valid |
3053 | instruction. This is for Thumb1 and the ARM 32 bit cases. | |
3054 | ||
3055 | x = y | constant (such that ~constant is a valid constant) | |
3056 | Transform this to | |
3057 | x = ~(~y & ~constant). | |
3058 | */ | |
5895f793 | 3059 | if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val))) |
e2c671ba | 3060 | { |
2b835d68 RE |
3061 | if (generate) |
3062 | { | |
3063 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
a406f566 MM |
3064 | emit_constant_insn (cond, |
3065 | gen_rtx_SET (VOIDmode, sub, | |
3066 | gen_rtx_NOT (mode, source))); | |
2b835d68 RE |
3067 | source = sub; |
3068 | if (subtargets) | |
3069 | sub = gen_reg_rtx (mode); | |
a406f566 MM |
3070 | emit_constant_insn (cond, |
3071 | gen_rtx_SET (VOIDmode, sub, | |
f676971a | 3072 | gen_rtx_AND (mode, source, |
a406f566 MM |
3073 | GEN_INT (temp1)))); |
3074 | emit_constant_insn (cond, | |
3075 | gen_rtx_SET (VOIDmode, target, | |
3076 | gen_rtx_NOT (mode, sub))); | |
2b835d68 | 3077 | } |
e2c671ba RE |
3078 | return 3; |
3079 | } | |
3080 | break; | |
3081 | ||
3082 | case AND: | |
3083 | /* See if two shifts will do 2 or more insn's worth of work. */ | |
3084 | if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24) | |
3085 | { | |
30cf4896 | 3086 | HOST_WIDE_INT shift_mask = ((0xffffffff |
e2c671ba | 3087 | << (32 - clear_sign_bit_copies)) |
30cf4896 | 3088 | & 0xffffffff); |
e2c671ba | 3089 | |
30cf4896 | 3090 | if ((remainder | shift_mask) != 0xffffffff) |
e2c671ba | 3091 | { |
2b835d68 RE |
3092 | if (generate) |
3093 | { | |
d499463f | 3094 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
f676971a | 3095 | insns = arm_gen_constant (AND, mode, cond, |
a406f566 | 3096 | remainder | shift_mask, |
d499463f RE |
3097 | new_src, source, subtargets, 1); |
3098 | source = new_src; | |
2b835d68 RE |
3099 | } |
3100 | else | |
d499463f RE |
3101 | { |
3102 | rtx targ = subtargets ? NULL_RTX : target; | |
a406f566 MM |
3103 | insns = arm_gen_constant (AND, mode, cond, |
3104 | remainder | shift_mask, | |
d499463f RE |
3105 | targ, source, subtargets, 0); |
3106 | } | |
2b835d68 RE |
3107 | } |
3108 | ||
3109 | if (generate) | |
3110 | { | |
d499463f RE |
3111 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
3112 | rtx shift = GEN_INT (clear_sign_bit_copies); | |
3113 | ||
3114 | emit_insn (gen_ashlsi3 (new_src, source, shift)); | |
3115 | emit_insn (gen_lshrsi3 (target, new_src, shift)); | |
e2c671ba RE |
3116 | } |
3117 | ||
e2c671ba RE |
3118 | return insns + 2; |
3119 | } | |
3120 | ||
3121 | if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24) | |
3122 | { | |
3123 | HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1; | |
f676971a | 3124 | |
30cf4896 | 3125 | if ((remainder | shift_mask) != 0xffffffff) |
e2c671ba | 3126 | { |
2b835d68 RE |
3127 | if (generate) |
3128 | { | |
d499463f RE |
3129 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
3130 | ||
a406f566 MM |
3131 | insns = arm_gen_constant (AND, mode, cond, |
3132 | remainder | shift_mask, | |
d499463f RE |
3133 | new_src, source, subtargets, 1); |
3134 | source = new_src; | |
2b835d68 RE |
3135 | } |
3136 | else | |
d499463f RE |
3137 | { |
3138 | rtx targ = subtargets ? NULL_RTX : target; | |
3139 | ||
a406f566 MM |
3140 | insns = arm_gen_constant (AND, mode, cond, |
3141 | remainder | shift_mask, | |
d499463f RE |
3142 | targ, source, subtargets, 0); |
3143 | } | |
2b835d68 RE |
3144 | } |
3145 | ||
3146 | if (generate) | |
3147 | { | |
d499463f RE |
3148 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
3149 | rtx shift = GEN_INT (clear_zero_bit_copies); | |
3150 | ||
3151 | emit_insn (gen_lshrsi3 (new_src, source, shift)); | |
3152 | emit_insn (gen_ashlsi3 (target, new_src, shift)); | |
e2c671ba RE |
3153 | } |
3154 | ||
e2c671ba RE |
3155 | return insns + 2; |
3156 | } | |
3157 | ||
3158 | break; | |
3159 | ||
3160 | default: | |
3161 | break; | |
3162 | } | |
3163 | ||
3164 | for (i = 0; i < 32; i++) | |
3165 | if (remainder & (1 << i)) | |
3166 | num_bits_set++; | |
3167 | ||
a7994a57 RR |
3168 | if ((code == AND) |
3169 | || (code != IOR && can_invert && num_bits_set > 16)) | |
162e4591 | 3170 | remainder ^= 0xffffffff; |
e2c671ba | 3171 | else if (code == PLUS && num_bits_set > 16) |
30cf4896 | 3172 | remainder = (-remainder) & 0xffffffff; |
162e4591 RE |
3173 | |
3174 | /* For XOR, if more than half the bits are set and there's a sequence | |
3175 | of more than 8 consecutive ones in the pattern then we can XOR by the | |
3176 | inverted constant and then invert the final result; this may save an | |
3177 | instruction and might also lead to the final mvn being merged with | |
3178 | some other operation. */ | |
3179 | else if (code == XOR && num_bits_set > 16 | |
3180 | && (count_insns_for_constant (remainder ^ 0xffffffff, | |
3181 | find_best_start | |
3182 | (remainder ^ 0xffffffff)) | |
3183 | < count_insns_for_constant (remainder, | |
3184 | find_best_start (remainder)))) | |
3185 | { | |
3186 | remainder ^= 0xffffffff; | |
3187 | final_invert = 1; | |
3188 | } | |
e2c671ba RE |
3189 | else |
3190 | { | |
3191 | can_invert = 0; | |
3192 | can_negate = 0; | |
3193 | } | |
3194 | ||
3195 | /* Now try and find a way of doing the job in either two or three | |
3196 | instructions. | |
3197 | We start by looking for the largest block of zeros that are aligned on | |
3198 | a 2-bit boundary, we then fill up the temps, wrapping around to the | |
3199 | top of the word when we drop off the bottom. | |
5b3e6663 PB |
3200 | In the worst case this code should produce no more than four insns. |
3201 | Thumb-2 constants are shifted, not rotated, so the MSB is always the | |
3202 | best place to start. */ | |
3203 | ||
3204 | /* ??? Use thumb2 replicated constants when the high and low halfwords are | |
3205 | the same. */ | |
e2c671ba | 3206 | { |
ceebdb09 | 3207 | /* Now start emitting the insns. */ |
162e4591 | 3208 | i = find_best_start (remainder); |
e2c671ba RE |
3209 | do |
3210 | { | |
3211 | int end; | |
3212 | ||
3213 | if (i <= 0) | |
3214 | i += 32; | |
3215 | if (remainder & (3 << (i - 2))) | |
3216 | { | |
3217 | end = i - 8; | |
3218 | if (end < 0) | |
3219 | end += 32; | |
3220 | temp1 = remainder & ((0x0ff << end) | |
3221 | | ((i < end) ? (0xff >> (32 - end)) : 0)); | |
3222 | remainder &= ~temp1; | |
3223 | ||
d499463f | 3224 | if (generate) |
e2c671ba | 3225 | { |
9503f3d1 RH |
3226 | rtx new_src, temp1_rtx; |
3227 | ||
3228 | if (code == SET || code == MINUS) | |
3229 | { | |
3230 | new_src = (subtargets ? gen_reg_rtx (mode) : target); | |
96ae8197 | 3231 | if (can_invert && code != MINUS) |
9503f3d1 RH |
3232 | temp1 = ~temp1; |
3233 | } | |
3234 | else | |
3235 | { | |
162e4591 | 3236 | if ((final_invert || remainder) && subtargets) |
9503f3d1 | 3237 | new_src = gen_reg_rtx (mode); |
96ae8197 NC |
3238 | else |
3239 | new_src = target; | |
9503f3d1 RH |
3240 | if (can_invert) |
3241 | temp1 = ~temp1; | |
3242 | else if (can_negate) | |
3243 | temp1 = -temp1; | |
3244 | } | |
3245 | ||
3246 | temp1 = trunc_int_for_mode (temp1, mode); | |
3247 | temp1_rtx = GEN_INT (temp1); | |
d499463f RE |
3248 | |
3249 | if (code == SET) | |
9503f3d1 | 3250 | ; |
d499463f | 3251 | else if (code == MINUS) |
9503f3d1 | 3252 | temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source); |
d499463f | 3253 | else |
9503f3d1 RH |
3254 | temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx); |
3255 | ||
a406f566 | 3256 | emit_constant_insn (cond, |
f676971a | 3257 | gen_rtx_SET (VOIDmode, new_src, |
a406f566 | 3258 | temp1_rtx)); |
d499463f | 3259 | source = new_src; |
e2c671ba RE |
3260 | } |
3261 | ||
d499463f RE |
3262 | if (code == SET) |
3263 | { | |
3264 | can_invert = 0; | |
3265 | code = PLUS; | |
3266 | } | |
3267 | else if (code == MINUS) | |
3268 | code = PLUS; | |
3269 | ||
e2c671ba | 3270 | insns++; |
162e4591 | 3271 | i -= 8 - step_size; |
e2c671ba | 3272 | } |
7a085dce | 3273 | /* Arm allows rotates by a multiple of two. Thumb-2 allows arbitrary |
5b3e6663 | 3274 | shifts. */ |
162e4591 | 3275 | i -= step_size; |
1d6e90ac NC |
3276 | } |
3277 | while (remainder); | |
e2c671ba | 3278 | } |
1d6e90ac | 3279 | |
162e4591 RE |
3280 | if (final_invert) |
3281 | { | |
3282 | if (generate) | |
3283 | emit_constant_insn (cond, gen_rtx_SET (VOIDmode, target, | |
3284 | gen_rtx_NOT (mode, source))); | |
3285 | insns++; | |
3286 | } | |
3287 | ||
e2c671ba RE |
3288 | return insns; |
3289 | } | |
3290 | ||
bd9c7e23 RE |
3291 | /* Canonicalize a comparison so that we are more likely to recognize it. |
3292 | This can be done for a few constant compares, where we can make the | |
3293 | immediate value easier to load. */ | |
1d6e90ac | 3294 | |
bd9c7e23 | 3295 | enum rtx_code |
73160ba9 | 3296 | arm_canonicalize_comparison (enum rtx_code code, rtx *op0, rtx *op1) |
bd9c7e23 | 3297 | { |
73160ba9 DJ |
3298 | enum machine_mode mode; |
3299 | unsigned HOST_WIDE_INT i, maxval; | |
3300 | ||
3301 | mode = GET_MODE (*op0); | |
3302 | if (mode == VOIDmode) | |
3303 | mode = GET_MODE (*op1); | |
3304 | ||
a14b88bb | 3305 | maxval = (((unsigned HOST_WIDE_INT) 1) << (GET_MODE_BITSIZE(mode) - 1)) - 1; |
bd9c7e23 | 3306 | |
73160ba9 DJ |
3307 | /* For DImode, we have GE/LT/GEU/LTU comparisons. In ARM mode |
3308 | we can also use cmp/cmpeq for GTU/LEU. GT/LE must be either | |
3309 | reversed or (for constant OP1) adjusted to GE/LT. Similarly | |
3310 | for GTU/LEU in Thumb mode. */ | |
3311 | if (mode == DImode) | |
3312 | { | |
3313 | rtx tem; | |
3314 | ||
3315 | /* To keep things simple, always use the Cirrus cfcmp64 if it is | |
3316 | available. */ | |
3317 | if (TARGET_ARM && TARGET_HARD_FLOAT && TARGET_MAVERICK) | |
3318 | return code; | |
3319 | ||
3320 | if (code == GT || code == LE | |
3321 | || (!TARGET_ARM && (code == GTU || code == LEU))) | |
3322 | { | |
3323 | /* Missing comparison. First try to use an available | |
3324 | comparison. */ | |
3325 | if (GET_CODE (*op1) == CONST_INT) | |
3326 | { | |
3327 | i = INTVAL (*op1); | |
3328 | switch (code) | |
3329 | { | |
3330 | case GT: | |
3331 | case LE: | |
3332 | if (i != maxval | |
3333 | && arm_const_double_by_immediates (GEN_INT (i + 1))) | |
3334 | { | |
3335 | *op1 = GEN_INT (i + 1); | |
3336 | return code == GT ? GE : LT; | |
3337 | } | |
3338 | break; | |
3339 | case GTU: | |
3340 | case LEU: | |
3341 | if (i != ~((unsigned HOST_WIDE_INT) 0) | |
3342 | && arm_const_double_by_immediates (GEN_INT (i + 1))) | |
3343 | { | |
3344 | *op1 = GEN_INT (i + 1); | |
3345 | return code == GTU ? GEU : LTU; | |
3346 | } | |
3347 | break; | |
3348 | default: | |
3349 | gcc_unreachable (); | |
3350 | } | |
3351 | } | |
3352 | ||
3353 | /* If that did not work, reverse the condition. */ | |
3354 | tem = *op0; | |
3355 | *op0 = *op1; | |
3356 | *op1 = tem; | |
3357 | return swap_condition (code); | |
3358 | } | |
3359 | ||
3360 | return code; | |
3361 | } | |
3362 | ||
3363 | /* Comparisons smaller than DImode. Only adjust comparisons against | |
3364 | an out-of-range constant. */ | |
3365 | if (GET_CODE (*op1) != CONST_INT | |
3366 | || const_ok_for_arm (INTVAL (*op1)) | |
3367 | || const_ok_for_arm (- INTVAL (*op1))) | |
3368 | return code; | |
3369 | ||
3370 | i = INTVAL (*op1); | |
3371 | ||
bd9c7e23 RE |
3372 | switch (code) |
3373 | { | |
3374 | case EQ: | |
3375 | case NE: | |
3376 | return code; | |
3377 | ||
3378 | case GT: | |
3379 | case LE: | |
a14b88bb | 3380 | if (i != maxval |
5895f793 | 3381 | && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1)))) |
bd9c7e23 | 3382 | { |
5895f793 | 3383 | *op1 = GEN_INT (i + 1); |
bd9c7e23 RE |
3384 | return code == GT ? GE : LT; |
3385 | } | |
3386 | break; | |
3387 | ||
3388 | case GE: | |
3389 | case LT: | |
a14b88bb | 3390 | if (i != ~maxval |
5895f793 | 3391 | && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1)))) |
bd9c7e23 | 3392 | { |
5895f793 | 3393 | *op1 = GEN_INT (i - 1); |
bd9c7e23 RE |
3394 | return code == GE ? GT : LE; |
3395 | } | |
3396 | break; | |
3397 | ||
3398 | case GTU: | |
3399 | case LEU: | |
30cf4896 | 3400 | if (i != ~((unsigned HOST_WIDE_INT) 0) |
5895f793 | 3401 | && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1)))) |
bd9c7e23 RE |
3402 | { |
3403 | *op1 = GEN_INT (i + 1); | |
3404 | return code == GTU ? GEU : LTU; | |
3405 | } | |
3406 | break; | |
3407 | ||
3408 | case GEU: | |
3409 | case LTU: | |
3410 | if (i != 0 | |
5895f793 | 3411 | && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1)))) |
bd9c7e23 RE |
3412 | { |
3413 | *op1 = GEN_INT (i - 1); | |
3414 | return code == GEU ? GTU : LEU; | |
3415 | } | |
3416 | break; | |
3417 | ||
3418 | default: | |
e6d29d15 | 3419 | gcc_unreachable (); |
bd9c7e23 RE |
3420 | } |
3421 | ||
3422 | return code; | |
3423 | } | |
bd9c7e23 | 3424 | |
d4453b7a PB |
3425 | |
3426 | /* Define how to find the value returned by a function. */ | |
3427 | ||
390b17c2 RE |
3428 | static rtx |
3429 | arm_function_value(const_tree type, const_tree func, | |
3430 | bool outgoing ATTRIBUTE_UNUSED) | |
d4453b7a PB |
3431 | { |
3432 | enum machine_mode mode; | |
3433 | int unsignedp ATTRIBUTE_UNUSED; | |
3434 | rtx r ATTRIBUTE_UNUSED; | |
3435 | ||
d4453b7a | 3436 | mode = TYPE_MODE (type); |
390b17c2 RE |
3437 | |
3438 | if (TARGET_AAPCS_BASED) | |
3439 | return aapcs_allocate_return_reg (mode, type, func); | |
3440 | ||
d4453b7a PB |
3441 | /* Promote integer types. */ |
3442 | if (INTEGRAL_TYPE_P (type)) | |
cde0f3fd | 3443 | mode = arm_promote_function_mode (type, mode, &unsignedp, func, 1); |
866af8a9 JB |
3444 | |
3445 | /* Promotes small structs returned in a register to full-word size | |
3446 | for big-endian AAPCS. */ | |
3447 | if (arm_return_in_msb (type)) | |
3448 | { | |
3449 | HOST_WIDE_INT size = int_size_in_bytes (type); | |
3450 | if (size % UNITS_PER_WORD != 0) | |
3451 | { | |
3452 | size += UNITS_PER_WORD - size % UNITS_PER_WORD; | |
3453 | mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0); | |
3454 | } | |
3455 | } | |
e0b92319 | 3456 | |
390b17c2 RE |
3457 | return LIBCALL_VALUE (mode); |
3458 | } | |
3459 | ||
3460 | static int | |
3461 | libcall_eq (const void *p1, const void *p2) | |
3462 | { | |
3463 | return rtx_equal_p ((const_rtx) p1, (const_rtx) p2); | |
3464 | } | |
3465 | ||
3466 | static hashval_t | |
3467 | libcall_hash (const void *p1) | |
3468 | { | |
3469 | return hash_rtx ((const_rtx) p1, VOIDmode, NULL, NULL, FALSE); | |
3470 | } | |
3471 | ||
3472 | static void | |
3473 | add_libcall (htab_t htab, rtx libcall) | |
3474 | { | |
3475 | *htab_find_slot (htab, libcall, INSERT) = libcall; | |
3476 | } | |
3477 | ||
3478 | static bool | |
7fc6a96b | 3479 | arm_libcall_uses_aapcs_base (const_rtx libcall) |
390b17c2 RE |
3480 | { |
3481 | static bool init_done = false; | |
3482 | static htab_t libcall_htab; | |
3483 | ||
3484 | if (!init_done) | |
3485 | { | |
3486 | init_done = true; | |
3487 | ||
3488 | libcall_htab = htab_create (31, libcall_hash, libcall_eq, | |
3489 | NULL); | |
3490 | add_libcall (libcall_htab, | |
3491 | convert_optab_libfunc (sfloat_optab, SFmode, SImode)); | |
3492 | add_libcall (libcall_htab, | |
3493 | convert_optab_libfunc (sfloat_optab, DFmode, SImode)); | |
3494 | add_libcall (libcall_htab, | |
3495 | convert_optab_libfunc (sfloat_optab, SFmode, DImode)); | |
3496 | add_libcall (libcall_htab, | |
3497 | convert_optab_libfunc (sfloat_optab, DFmode, DImode)); | |
3498 | ||
3499 | add_libcall (libcall_htab, | |
3500 | convert_optab_libfunc (ufloat_optab, SFmode, SImode)); | |
3501 | add_libcall (libcall_htab, | |
3502 | convert_optab_libfunc (ufloat_optab, DFmode, SImode)); | |
3503 | add_libcall (libcall_htab, | |
3504 | convert_optab_libfunc (ufloat_optab, SFmode, DImode)); | |
3505 | add_libcall (libcall_htab, | |
3506 | convert_optab_libfunc (ufloat_optab, DFmode, DImode)); | |
3507 | ||
3508 | add_libcall (libcall_htab, | |
3509 | convert_optab_libfunc (sext_optab, SFmode, HFmode)); | |
3510 | add_libcall (libcall_htab, | |
3511 | convert_optab_libfunc (trunc_optab, HFmode, SFmode)); | |
3512 | add_libcall (libcall_htab, | |
3513 | convert_optab_libfunc (sfix_optab, DImode, DFmode)); | |
3514 | add_libcall (libcall_htab, | |
3515 | convert_optab_libfunc (ufix_optab, DImode, DFmode)); | |
3516 | add_libcall (libcall_htab, | |
3517 | convert_optab_libfunc (sfix_optab, DImode, SFmode)); | |
3518 | add_libcall (libcall_htab, | |
3519 | convert_optab_libfunc (ufix_optab, DImode, SFmode)); | |
3520 | } | |
3521 | ||
3522 | return libcall && htab_find (libcall_htab, libcall) != NULL; | |
3523 | } | |
3524 | ||
3525 | rtx | |
7fc6a96b | 3526 | arm_libcall_value (enum machine_mode mode, const_rtx libcall) |
390b17c2 RE |
3527 | { |
3528 | if (TARGET_AAPCS_BASED && arm_pcs_default != ARM_PCS_AAPCS | |
3529 | && GET_MODE_CLASS (mode) == MODE_FLOAT) | |
3530 | { | |
3531 | /* The following libcalls return their result in integer registers, | |
3532 | even though they return a floating point value. */ | |
3533 | if (arm_libcall_uses_aapcs_base (libcall)) | |
3534 | return gen_rtx_REG (mode, ARG_REGISTER(1)); | |
3535 | ||
3536 | } | |
3537 | ||
3538 | return LIBCALL_VALUE (mode); | |
d4453b7a PB |
3539 | } |
3540 | ||
e0b92319 | 3541 | /* Determine the amount of memory needed to store the possible return |
9f7bf991 RE |
3542 | registers of an untyped call. */ |
3543 | int | |
3544 | arm_apply_result_size (void) | |
3545 | { | |
3546 | int size = 16; | |
3547 | ||
390b17c2 | 3548 | if (TARGET_32BIT) |
9f7bf991 RE |
3549 | { |
3550 | if (TARGET_HARD_FLOAT_ABI) | |
3551 | { | |
390b17c2 RE |
3552 | if (TARGET_VFP) |
3553 | size += 32; | |
9f7bf991 RE |
3554 | if (TARGET_FPA) |
3555 | size += 12; | |
3556 | if (TARGET_MAVERICK) | |
3557 | size += 8; | |
3558 | } | |
3559 | if (TARGET_IWMMXT_ABI) | |
3560 | size += 8; | |
3561 | } | |
3562 | ||
3563 | return size; | |
3564 | } | |
d4453b7a | 3565 | |
390b17c2 RE |
3566 | /* Decide whether TYPE should be returned in memory (true) |
3567 | or in a register (false). FNTYPE is the type of the function making | |
3568 | the call. */ | |
23668cf7 | 3569 | static bool |
390b17c2 | 3570 | arm_return_in_memory (const_tree type, const_tree fntype) |
2b835d68 | 3571 | { |
dc0ba55a JT |
3572 | HOST_WIDE_INT size; |
3573 | ||
390b17c2 RE |
3574 | size = int_size_in_bytes (type); /* Negative if not fixed size. */ |
3575 | ||
3576 | if (TARGET_AAPCS_BASED) | |
3577 | { | |
3578 | /* Simple, non-aggregate types (ie not including vectors and | |
3579 | complex) are always returned in a register (or registers). | |
3580 | We don't care about which register here, so we can short-cut | |
3581 | some of the detail. */ | |
3582 | if (!AGGREGATE_TYPE_P (type) | |
3583 | && TREE_CODE (type) != VECTOR_TYPE | |
3584 | && TREE_CODE (type) != COMPLEX_TYPE) | |
3585 | return false; | |
3586 | ||
3587 | /* Any return value that is no larger than one word can be | |
3588 | returned in r0. */ | |
3589 | if (((unsigned HOST_WIDE_INT) size) <= UNITS_PER_WORD) | |
3590 | return false; | |
3591 | ||
3592 | /* Check any available co-processors to see if they accept the | |
3593 | type as a register candidate (VFP, for example, can return | |
3594 | some aggregates in consecutive registers). These aren't | |
3595 | available if the call is variadic. */ | |
3596 | if (aapcs_select_return_coproc (type, fntype) >= 0) | |
3597 | return false; | |
3598 | ||
3599 | /* Vector values should be returned using ARM registers, not | |
3600 | memory (unless they're over 16 bytes, which will break since | |
3601 | we only have four call-clobbered registers to play with). */ | |
3602 | if (TREE_CODE (type) == VECTOR_TYPE) | |
3603 | return (size < 0 || size > (4 * UNITS_PER_WORD)); | |
3604 | ||
3605 | /* The rest go in memory. */ | |
3606 | return true; | |
3607 | } | |
88f77cba | 3608 | |
88f77cba JB |
3609 | if (TREE_CODE (type) == VECTOR_TYPE) |
3610 | return (size < 0 || size > (4 * UNITS_PER_WORD)); | |
3611 | ||
3dd7ab65 | 3612 | if (!AGGREGATE_TYPE_P (type) && |
390b17c2 RE |
3613 | (TREE_CODE (type) != VECTOR_TYPE)) |
3614 | /* All simple types are returned in registers. */ | |
3615 | return false; | |
dc0ba55a | 3616 | |
5848830f | 3617 | if (arm_abi != ARM_ABI_APCS) |
dc0ba55a | 3618 | { |
5848830f | 3619 | /* ATPCS and later return aggregate types in memory only if they are |
dc0ba55a JT |
3620 | larger than a word (or are variable size). */ |
3621 | return (size < 0 || size > UNITS_PER_WORD); | |
3622 | } | |
f676971a | 3623 | |
6bc82793 | 3624 | /* For the arm-wince targets we choose to be compatible with Microsoft's |
d5b7b3ae RE |
3625 | ARM and Thumb compilers, which always return aggregates in memory. */ |
3626 | #ifndef ARM_WINCE | |
e529bd42 NC |
3627 | /* All structures/unions bigger than one word are returned in memory. |
3628 | Also catch the case where int_size_in_bytes returns -1. In this case | |
6bc82793 | 3629 | the aggregate is either huge or of variable size, and in either case |
e529bd42 | 3630 | we will want to return it via memory and not in a register. */ |
dc0ba55a | 3631 | if (size < 0 || size > UNITS_PER_WORD) |
390b17c2 | 3632 | return true; |
f676971a | 3633 | |
d7d01975 | 3634 | if (TREE_CODE (type) == RECORD_TYPE) |
2b835d68 RE |
3635 | { |
3636 | tree field; | |
3637 | ||
3a2ea258 RE |
3638 | /* For a struct the APCS says that we only return in a register |
3639 | if the type is 'integer like' and every addressable element | |
3640 | has an offset of zero. For practical purposes this means | |
3641 | that the structure can have at most one non bit-field element | |
3642 | and that this element must be the first one in the structure. */ | |
f676971a | 3643 | |
f5a1b0d2 NC |
3644 | /* Find the first field, ignoring non FIELD_DECL things which will |
3645 | have been created by C++. */ | |
3646 | for (field = TYPE_FIELDS (type); | |
3647 | field && TREE_CODE (field) != FIELD_DECL; | |
910ad8de | 3648 | field = DECL_CHAIN (field)) |
f5a1b0d2 | 3649 | continue; |
f676971a | 3650 | |
f5a1b0d2 | 3651 | if (field == NULL) |
390b17c2 | 3652 | return false; /* An empty structure. Allowed by an extension to ANSI C. */ |
f5a1b0d2 | 3653 | |
d5b7b3ae RE |
3654 | /* Check that the first field is valid for returning in a register. */ |
3655 | ||
3656 | /* ... Floats are not allowed */ | |
9e291dbe | 3657 | if (FLOAT_TYPE_P (TREE_TYPE (field))) |
390b17c2 | 3658 | return true; |
3a2ea258 | 3659 | |
d5b7b3ae RE |
3660 | /* ... Aggregates that are not themselves valid for returning in |
3661 | a register are not allowed. */ | |
81464b2c | 3662 | if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE)) |
390b17c2 | 3663 | return true; |
6f7ebcbb | 3664 | |
3a2ea258 RE |
3665 | /* Now check the remaining fields, if any. Only bitfields are allowed, |
3666 | since they are not addressable. */ | |
910ad8de | 3667 | for (field = DECL_CHAIN (field); |
f5a1b0d2 | 3668 | field; |
910ad8de | 3669 | field = DECL_CHAIN (field)) |
f5a1b0d2 NC |
3670 | { |
3671 | if (TREE_CODE (field) != FIELD_DECL) | |
3672 | continue; | |
f676971a | 3673 | |
5895f793 | 3674 | if (!DECL_BIT_FIELD_TYPE (field)) |
390b17c2 | 3675 | return true; |
f5a1b0d2 | 3676 | } |
2b835d68 | 3677 | |
390b17c2 | 3678 | return false; |
2b835d68 | 3679 | } |
f676971a | 3680 | |
d7d01975 | 3681 | if (TREE_CODE (type) == UNION_TYPE) |
2b835d68 RE |
3682 | { |
3683 | tree field; | |
3684 | ||
3685 | /* Unions can be returned in registers if every element is | |
3686 | integral, or can be returned in an integer register. */ | |
f5a1b0d2 NC |
3687 | for (field = TYPE_FIELDS (type); |
3688 | field; | |
910ad8de | 3689 | field = DECL_CHAIN (field)) |
2b835d68 | 3690 | { |
f5a1b0d2 NC |
3691 | if (TREE_CODE (field) != FIELD_DECL) |
3692 | continue; | |
3693 | ||
6cc8c0b3 | 3694 | if (FLOAT_TYPE_P (TREE_TYPE (field))) |
390b17c2 | 3695 | return true; |
f676971a | 3696 | |
81464b2c | 3697 | if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE)) |
390b17c2 | 3698 | return true; |
2b835d68 | 3699 | } |
f676971a | 3700 | |
390b17c2 | 3701 | return false; |
2b835d68 | 3702 | } |
f676971a EC |
3703 | #endif /* not ARM_WINCE */ |
3704 | ||
d5b7b3ae | 3705 | /* Return all other types in memory. */ |
390b17c2 | 3706 | return true; |
2b835d68 RE |
3707 | } |
3708 | ||
d6b4baa4 | 3709 | /* Indicate whether or not words of a double are in big-endian order. */ |
3717da94 JT |
3710 | |
3711 | int | |
e32bac5b | 3712 | arm_float_words_big_endian (void) |
3717da94 | 3713 | { |
9b66ebb1 | 3714 | if (TARGET_MAVERICK) |
9b6b54e2 | 3715 | return 0; |
3717da94 JT |
3716 | |
3717 | /* For FPA, float words are always big-endian. For VFP, floats words | |
3718 | follow the memory system mode. */ | |
3719 | ||
9b66ebb1 | 3720 | if (TARGET_FPA) |
3717da94 | 3721 | { |
3717da94 JT |
3722 | return 1; |
3723 | } | |
3724 | ||
3725 | if (TARGET_VFP) | |
3726 | return (TARGET_BIG_END ? 1 : 0); | |
3727 | ||
3728 | return 1; | |
3729 | } | |
3730 | ||
390b17c2 RE |
3731 | const struct pcs_attribute_arg |
3732 | { | |
3733 | const char *arg; | |
3734 | enum arm_pcs value; | |
3735 | } pcs_attribute_args[] = | |
3736 | { | |
3737 | {"aapcs", ARM_PCS_AAPCS}, | |
3738 | {"aapcs-vfp", ARM_PCS_AAPCS_VFP}, | |
0f1a24df RE |
3739 | #if 0 |
3740 | /* We could recognize these, but changes would be needed elsewhere | |
3741 | * to implement them. */ | |
390b17c2 RE |
3742 | {"aapcs-iwmmxt", ARM_PCS_AAPCS_IWMMXT}, |
3743 | {"atpcs", ARM_PCS_ATPCS}, | |
3744 | {"apcs", ARM_PCS_APCS}, | |
0f1a24df | 3745 | #endif |
390b17c2 RE |
3746 | {NULL, ARM_PCS_UNKNOWN} |
3747 | }; | |
3748 | ||
3749 | static enum arm_pcs | |
3750 | arm_pcs_from_attribute (tree attr) | |
3751 | { | |
3752 | const struct pcs_attribute_arg *ptr; | |
3753 | const char *arg; | |
3754 | ||
3755 | /* Get the value of the argument. */ | |
3756 | if (TREE_VALUE (attr) == NULL_TREE | |
3757 | || TREE_CODE (TREE_VALUE (attr)) != STRING_CST) | |
3758 | return ARM_PCS_UNKNOWN; | |
3759 | ||
3760 | arg = TREE_STRING_POINTER (TREE_VALUE (attr)); | |
3761 | ||
3762 | /* Check it against the list of known arguments. */ | |
3763 | for (ptr = pcs_attribute_args; ptr->arg != NULL; ptr++) | |
3764 | if (streq (arg, ptr->arg)) | |
3765 | return ptr->value; | |
3766 | ||
3767 | /* An unrecognized interrupt type. */ | |
3768 | return ARM_PCS_UNKNOWN; | |
3769 | } | |
3770 | ||
3771 | /* Get the PCS variant to use for this call. TYPE is the function's type | |
3772 | specification, DECL is the specific declartion. DECL may be null if | |
3773 | the call could be indirect or if this is a library call. */ | |
3774 | static enum arm_pcs | |
3775 | arm_get_pcs_model (const_tree type, const_tree decl) | |
3776 | { | |
3777 | bool user_convention = false; | |
3778 | enum arm_pcs user_pcs = arm_pcs_default; | |
3779 | tree attr; | |
3780 | ||
3781 | gcc_assert (type); | |
3782 | ||
3783 | attr = lookup_attribute ("pcs", TYPE_ATTRIBUTES (type)); | |
3784 | if (attr) | |
3785 | { | |
3786 | user_pcs = arm_pcs_from_attribute (TREE_VALUE (attr)); | |
3787 | user_convention = true; | |
3788 | } | |
3789 | ||
3790 | if (TARGET_AAPCS_BASED) | |
3791 | { | |
3792 | /* Detect varargs functions. These always use the base rules | |
3793 | (no argument is ever a candidate for a co-processor | |
3794 | register). */ | |
f38958e8 | 3795 | bool base_rules = stdarg_p (type); |
390b17c2 RE |
3796 | |
3797 | if (user_convention) | |
3798 | { | |
3799 | if (user_pcs > ARM_PCS_AAPCS_LOCAL) | |
d8a07487 | 3800 | sorry ("non-AAPCS derived PCS variant"); |
390b17c2 | 3801 | else if (base_rules && user_pcs != ARM_PCS_AAPCS) |
d8a07487 | 3802 | error ("variadic functions must use the base AAPCS variant"); |
390b17c2 RE |
3803 | } |
3804 | ||
3805 | if (base_rules) | |
3806 | return ARM_PCS_AAPCS; | |
3807 | else if (user_convention) | |
3808 | return user_pcs; | |
3809 | else if (decl && flag_unit_at_a_time) | |
3810 | { | |
3811 | /* Local functions never leak outside this compilation unit, | |
3812 | so we are free to use whatever conventions are | |
3813 | appropriate. */ | |
3814 | /* FIXME: remove CONST_CAST_TREE when cgraph is constified. */ | |
3815 | struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl)); | |
3816 | if (i && i->local) | |
3817 | return ARM_PCS_AAPCS_LOCAL; | |
3818 | } | |
3819 | } | |
3820 | else if (user_convention && user_pcs != arm_pcs_default) | |
3821 | sorry ("PCS variant"); | |
3822 | ||
3823 | /* For everything else we use the target's default. */ | |
3824 | return arm_pcs_default; | |
3825 | } | |
3826 | ||
3827 | ||
3828 | static void | |
3829 | aapcs_vfp_cum_init (CUMULATIVE_ARGS *pcum ATTRIBUTE_UNUSED, | |
3830 | const_tree fntype ATTRIBUTE_UNUSED, | |
3831 | rtx libcall ATTRIBUTE_UNUSED, | |
3832 | const_tree fndecl ATTRIBUTE_UNUSED) | |
3833 | { | |
3834 | /* Record the unallocated VFP registers. */ | |
3835 | pcum->aapcs_vfp_regs_free = (1 << NUM_VFP_ARG_REGS) - 1; | |
3836 | pcum->aapcs_vfp_reg_alloc = 0; | |
3837 | } | |
3838 | ||
3839 | /* Walk down the type tree of TYPE counting consecutive base elements. | |
3840 | If *MODEP is VOIDmode, then set it to the first valid floating point | |
3841 | type. If a non-floating point type is found, or if a floating point | |
3842 | type that doesn't match a non-VOIDmode *MODEP is found, then return -1, | |
3843 | otherwise return the count in the sub-tree. */ | |
3844 | static int | |
3845 | aapcs_vfp_sub_candidate (const_tree type, enum machine_mode *modep) | |
3846 | { | |
3847 | enum machine_mode mode; | |
3848 | HOST_WIDE_INT size; | |
3849 | ||
3850 | switch (TREE_CODE (type)) | |
3851 | { | |
3852 | case REAL_TYPE: | |
3853 | mode = TYPE_MODE (type); | |
3854 | if (mode != DFmode && mode != SFmode) | |
3855 | return -1; | |
3856 | ||
3857 | if (*modep == VOIDmode) | |
3858 | *modep = mode; | |
3859 | ||
3860 | if (*modep == mode) | |
3861 | return 1; | |
3862 | ||
3863 | break; | |
3864 | ||
3865 | case COMPLEX_TYPE: | |
3866 | mode = TYPE_MODE (TREE_TYPE (type)); | |
3867 | if (mode != DFmode && mode != SFmode) | |
3868 | return -1; | |
3869 | ||
3870 | if (*modep == VOIDmode) | |
3871 | *modep = mode; | |
3872 | ||
3873 | if (*modep == mode) | |
3874 | return 2; | |
3875 | ||
3876 | break; | |
3877 | ||
3878 | case VECTOR_TYPE: | |
3879 | /* Use V2SImode and V4SImode as representatives of all 64-bit | |
3880 | and 128-bit vector types, whether or not those modes are | |
3881 | supported with the present options. */ | |
3882 | size = int_size_in_bytes (type); | |
3883 | switch (size) | |
3884 | { | |
3885 | case 8: | |
3886 | mode = V2SImode; | |
3887 | break; | |
3888 | case 16: | |
3889 | mode = V4SImode; | |
3890 | break; | |
3891 | default: | |
3892 | return -1; | |
3893 | } | |
3894 | ||
3895 | if (*modep == VOIDmode) | |
3896 | *modep = mode; | |
3897 | ||
3898 | /* Vector modes are considered to be opaque: two vectors are | |
3899 | equivalent for the purposes of being homogeneous aggregates | |
3900 | if they are the same size. */ | |
3901 | if (*modep == mode) | |
3902 | return 1; | |
3903 | ||
3904 | break; | |
3905 | ||
3906 | case ARRAY_TYPE: | |
3907 | { | |
3908 | int count; | |
3909 | tree index = TYPE_DOMAIN (type); | |
3910 | ||
3911 | /* Can't handle incomplete types. */ | |
3912 | if (!COMPLETE_TYPE_P(type)) | |
3913 | return -1; | |
3914 | ||
3915 | count = aapcs_vfp_sub_candidate (TREE_TYPE (type), modep); | |
3916 | if (count == -1 | |
3917 | || !index | |
3918 | || !TYPE_MAX_VALUE (index) | |
3919 | || !host_integerp (TYPE_MAX_VALUE (index), 1) | |
3920 | || !TYPE_MIN_VALUE (index) | |
3921 | || !host_integerp (TYPE_MIN_VALUE (index), 1) | |
3922 | || count < 0) | |
3923 | return -1; | |
3924 | ||
3925 | count *= (1 + tree_low_cst (TYPE_MAX_VALUE (index), 1) | |
3926 | - tree_low_cst (TYPE_MIN_VALUE (index), 1)); | |
3927 | ||
3928 | /* There must be no padding. */ | |
3929 | if (!host_integerp (TYPE_SIZE (type), 1) | |
3930 | || (tree_low_cst (TYPE_SIZE (type), 1) | |
3931 | != count * GET_MODE_BITSIZE (*modep))) | |
3932 | return -1; | |
3933 | ||
3934 | return count; | |
3935 | } | |
3936 | ||
3937 | case RECORD_TYPE: | |
3938 | { | |
3939 | int count = 0; | |
3940 | int sub_count; | |
3941 | tree field; | |
3942 | ||
3943 | /* Can't handle incomplete types. */ | |
3944 | if (!COMPLETE_TYPE_P(type)) | |
3945 | return -1; | |
3946 | ||
910ad8de | 3947 | for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
390b17c2 RE |
3948 | { |
3949 | if (TREE_CODE (field) != FIELD_DECL) | |
3950 | continue; | |
3951 | ||
3952 | sub_count = aapcs_vfp_sub_candidate (TREE_TYPE (field), modep); | |
3953 | if (sub_count < 0) | |
3954 | return -1; | |
3955 | count += sub_count; | |
3956 | } | |
3957 | ||
3958 | /* There must be no padding. */ | |
3959 | if (!host_integerp (TYPE_SIZE (type), 1) | |
3960 | || (tree_low_cst (TYPE_SIZE (type), 1) | |
3961 | != count * GET_MODE_BITSIZE (*modep))) | |
3962 | return -1; | |
3963 | ||
3964 | return count; | |
3965 | } | |
3966 | ||
3967 | case UNION_TYPE: | |
3968 | case QUAL_UNION_TYPE: | |
3969 | { | |
3970 | /* These aren't very interesting except in a degenerate case. */ | |
3971 | int count = 0; | |
3972 | int sub_count; | |
3973 | tree field; | |
3974 | ||
3975 | /* Can't handle incomplete types. */ | |
3976 | if (!COMPLETE_TYPE_P(type)) | |
3977 | return -1; | |
3978 | ||
910ad8de | 3979 | for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
390b17c2 RE |
3980 | { |
3981 | if (TREE_CODE (field) != FIELD_DECL) | |
3982 | continue; | |
3983 | ||
3984 | sub_count = aapcs_vfp_sub_candidate (TREE_TYPE (field), modep); | |
3985 | if (sub_count < 0) | |
3986 | return -1; | |
3987 | count = count > sub_count ? count : sub_count; | |
3988 | } | |
3989 | ||
3990 | /* There must be no padding. */ | |
3991 | if (!host_integerp (TYPE_SIZE (type), 1) | |
3992 | || (tree_low_cst (TYPE_SIZE (type), 1) | |
3993 | != count * GET_MODE_BITSIZE (*modep))) | |
3994 | return -1; | |
3995 | ||
3996 | return count; | |
3997 | } | |
3998 | ||
3999 | default: | |
4000 | break; | |
4001 | } | |
4002 | ||
4003 | return -1; | |
4004 | } | |
4005 | ||
e0dc3601 | 4006 | /* Return true if PCS_VARIANT should use VFP registers. */ |
390b17c2 | 4007 | static bool |
e0dc3601 | 4008 | use_vfp_abi (enum arm_pcs pcs_variant, bool is_double) |
390b17c2 | 4009 | { |
e0dc3601 | 4010 | if (pcs_variant == ARM_PCS_AAPCS_VFP) |
50416c61 PB |
4011 | { |
4012 | static bool seen_thumb1_vfp = false; | |
4013 | ||
4014 | if (TARGET_THUMB1 && !seen_thumb1_vfp) | |
4015 | { | |
4016 | sorry ("Thumb-1 hard-float VFP ABI"); | |
4017 | /* sorry() is not immediately fatal, so only display this once. */ | |
4018 | seen_thumb1_vfp = true; | |
4019 | } | |
4020 | ||
4021 | return true; | |
4022 | } | |
e0dc3601 PB |
4023 | |
4024 | if (pcs_variant != ARM_PCS_AAPCS_LOCAL) | |
4025 | return false; | |
4026 | ||
4027 | return (TARGET_32BIT && TARGET_VFP && TARGET_HARD_FLOAT && | |
4028 | (TARGET_VFP_DOUBLE || !is_double)); | |
4029 | } | |
4030 | ||
4031 | static bool | |
4032 | aapcs_vfp_is_call_or_return_candidate (enum arm_pcs pcs_variant, | |
4033 | enum machine_mode mode, const_tree type, | |
70dd156a | 4034 | enum machine_mode *base_mode, int *count) |
e0dc3601 PB |
4035 | { |
4036 | enum machine_mode new_mode = VOIDmode; | |
4037 | ||
390b17c2 RE |
4038 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
4039 | || GET_MODE_CLASS (mode) == MODE_VECTOR_INT | |
4040 | || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT) | |
4041 | { | |
4042 | *count = 1; | |
e0dc3601 | 4043 | new_mode = mode; |
390b17c2 RE |
4044 | } |
4045 | else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT) | |
4046 | { | |
4047 | *count = 2; | |
e0dc3601 | 4048 | new_mode = (mode == DCmode ? DFmode : SFmode); |
390b17c2 RE |
4049 | } |
4050 | else if (type && (mode == BLKmode || TREE_CODE (type) == VECTOR_TYPE)) | |
4051 | { | |
e0dc3601 | 4052 | int ag_count = aapcs_vfp_sub_candidate (type, &new_mode); |
390b17c2 RE |
4053 | |
4054 | if (ag_count > 0 && ag_count <= 4) | |
e0dc3601 PB |
4055 | *count = ag_count; |
4056 | else | |
4057 | return false; | |
390b17c2 | 4058 | } |
e0dc3601 PB |
4059 | else |
4060 | return false; | |
4061 | ||
4062 | ||
4063 | if (!use_vfp_abi (pcs_variant, ARM_NUM_REGS (new_mode) > 1)) | |
4064 | return false; | |
4065 | ||
4066 | *base_mode = new_mode; | |
4067 | return true; | |
390b17c2 RE |
4068 | } |
4069 | ||
4070 | static bool | |
4071 | aapcs_vfp_is_return_candidate (enum arm_pcs pcs_variant, | |
4072 | enum machine_mode mode, const_tree type) | |
4073 | { | |
4074 | int count ATTRIBUTE_UNUSED; | |
46107b99 | 4075 | enum machine_mode ag_mode ATTRIBUTE_UNUSED; |
390b17c2 | 4076 | |
e0dc3601 | 4077 | if (!use_vfp_abi (pcs_variant, false)) |
390b17c2 | 4078 | return false; |
e0dc3601 PB |
4079 | return aapcs_vfp_is_call_or_return_candidate (pcs_variant, mode, type, |
4080 | &ag_mode, &count); | |
390b17c2 RE |
4081 | } |
4082 | ||
4083 | static bool | |
4084 | aapcs_vfp_is_call_candidate (CUMULATIVE_ARGS *pcum, enum machine_mode mode, | |
4085 | const_tree type) | |
4086 | { | |
e0dc3601 | 4087 | if (!use_vfp_abi (pcum->pcs_variant, false)) |
390b17c2 | 4088 | return false; |
e0dc3601 PB |
4089 | |
4090 | return aapcs_vfp_is_call_or_return_candidate (pcum->pcs_variant, mode, type, | |
390b17c2 RE |
4091 | &pcum->aapcs_vfp_rmode, |
4092 | &pcum->aapcs_vfp_rcount); | |
4093 | } | |
4094 | ||
4095 | static bool | |
4096 | aapcs_vfp_allocate (CUMULATIVE_ARGS *pcum, enum machine_mode mode, | |
4097 | const_tree type ATTRIBUTE_UNUSED) | |
4098 | { | |
4099 | int shift = GET_MODE_SIZE (pcum->aapcs_vfp_rmode) / GET_MODE_SIZE (SFmode); | |
4100 | unsigned mask = (1 << (shift * pcum->aapcs_vfp_rcount)) - 1; | |
4101 | int regno; | |
4102 | ||
4103 | for (regno = 0; regno < NUM_VFP_ARG_REGS; regno += shift) | |
4104 | if (((pcum->aapcs_vfp_regs_free >> regno) & mask) == mask) | |
4105 | { | |
4106 | pcum->aapcs_vfp_reg_alloc = mask << regno; | |
4107 | if (mode == BLKmode || (mode == TImode && !TARGET_NEON)) | |
4108 | { | |
4109 | int i; | |
4110 | int rcount = pcum->aapcs_vfp_rcount; | |
4111 | int rshift = shift; | |
4112 | enum machine_mode rmode = pcum->aapcs_vfp_rmode; | |
4113 | rtx par; | |
4114 | if (!TARGET_NEON) | |
4115 | { | |
4116 | /* Avoid using unsupported vector modes. */ | |
4117 | if (rmode == V2SImode) | |
4118 | rmode = DImode; | |
4119 | else if (rmode == V4SImode) | |
4120 | { | |
4121 | rmode = DImode; | |
4122 | rcount *= 2; | |
4123 | rshift /= 2; | |
4124 | } | |
4125 | } | |
4126 | par = gen_rtx_PARALLEL (mode, rtvec_alloc (rcount)); | |
4127 | for (i = 0; i < rcount; i++) | |
4128 | { | |
4129 | rtx tmp = gen_rtx_REG (rmode, | |
4130 | FIRST_VFP_REGNUM + regno + i * rshift); | |
4131 | tmp = gen_rtx_EXPR_LIST | |
4132 | (VOIDmode, tmp, | |
4133 | GEN_INT (i * GET_MODE_SIZE (rmode))); | |
4134 | XVECEXP (par, 0, i) = tmp; | |
4135 | } | |
4136 | ||
4137 | pcum->aapcs_reg = par; | |
4138 | } | |
4139 | else | |
4140 | pcum->aapcs_reg = gen_rtx_REG (mode, FIRST_VFP_REGNUM + regno); | |
4141 | return true; | |
4142 | } | |
4143 | return false; | |
4144 | } | |
4145 | ||
4146 | static rtx | |
4147 | aapcs_vfp_allocate_return_reg (enum arm_pcs pcs_variant ATTRIBUTE_UNUSED, | |
4148 | enum machine_mode mode, | |
4149 | const_tree type ATTRIBUTE_UNUSED) | |
4150 | { | |
e0dc3601 | 4151 | if (!use_vfp_abi (pcs_variant, false)) |
390b17c2 | 4152 | return false; |
e0dc3601 | 4153 | |
390b17c2 RE |
4154 | if (mode == BLKmode || (mode == TImode && !TARGET_NEON)) |
4155 | { | |
4156 | int count; | |
46107b99 | 4157 | enum machine_mode ag_mode; |
390b17c2 RE |
4158 | int i; |
4159 | rtx par; | |
4160 | int shift; | |
4161 | ||
e0dc3601 PB |
4162 | aapcs_vfp_is_call_or_return_candidate (pcs_variant, mode, type, |
4163 | &ag_mode, &count); | |
390b17c2 RE |
4164 | |
4165 | if (!TARGET_NEON) | |
4166 | { | |
4167 | if (ag_mode == V2SImode) | |
4168 | ag_mode = DImode; | |
4169 | else if (ag_mode == V4SImode) | |
4170 | { | |
4171 | ag_mode = DImode; | |
4172 | count *= 2; | |
4173 | } | |
4174 | } | |
4175 | shift = GET_MODE_SIZE(ag_mode) / GET_MODE_SIZE(SFmode); | |
4176 | par = gen_rtx_PARALLEL (mode, rtvec_alloc (count)); | |
4177 | for (i = 0; i < count; i++) | |
4178 | { | |
4179 | rtx tmp = gen_rtx_REG (ag_mode, FIRST_VFP_REGNUM + i * shift); | |
4180 | tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, | |
4181 | GEN_INT (i * GET_MODE_SIZE (ag_mode))); | |
4182 | XVECEXP (par, 0, i) = tmp; | |
4183 | } | |
4184 | ||
4185 | return par; | |
4186 | } | |
4187 | ||
4188 | return gen_rtx_REG (mode, FIRST_VFP_REGNUM); | |
4189 | } | |
4190 | ||
4191 | static void | |
4192 | aapcs_vfp_advance (CUMULATIVE_ARGS *pcum ATTRIBUTE_UNUSED, | |
4193 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
4194 | const_tree type ATTRIBUTE_UNUSED) | |
4195 | { | |
4196 | pcum->aapcs_vfp_regs_free &= ~pcum->aapcs_vfp_reg_alloc; | |
4197 | pcum->aapcs_vfp_reg_alloc = 0; | |
4198 | return; | |
4199 | } | |
4200 | ||
4201 | #define AAPCS_CP(X) \ | |
4202 | { \ | |
4203 | aapcs_ ## X ## _cum_init, \ | |
4204 | aapcs_ ## X ## _is_call_candidate, \ | |
4205 | aapcs_ ## X ## _allocate, \ | |
4206 | aapcs_ ## X ## _is_return_candidate, \ | |
4207 | aapcs_ ## X ## _allocate_return_reg, \ | |
4208 | aapcs_ ## X ## _advance \ | |
4209 | } | |
4210 | ||
4211 | /* Table of co-processors that can be used to pass arguments in | |
4212 | registers. Idealy no arugment should be a candidate for more than | |
4213 | one co-processor table entry, but the table is processed in order | |
4214 | and stops after the first match. If that entry then fails to put | |
4215 | the argument into a co-processor register, the argument will go on | |
4216 | the stack. */ | |
4217 | static struct | |
4218 | { | |
4219 | /* Initialize co-processor related state in CUMULATIVE_ARGS structure. */ | |
4220 | void (*cum_init) (CUMULATIVE_ARGS *, const_tree, rtx, const_tree); | |
4221 | ||
4222 | /* Return true if an argument of mode MODE (or type TYPE if MODE is | |
4223 | BLKmode) is a candidate for this co-processor's registers; this | |
4224 | function should ignore any position-dependent state in | |
4225 | CUMULATIVE_ARGS and only use call-type dependent information. */ | |
4226 | bool (*is_call_candidate) (CUMULATIVE_ARGS *, enum machine_mode, const_tree); | |
4227 | ||
4228 | /* Return true if the argument does get a co-processor register; it | |
4229 | should set aapcs_reg to an RTX of the register allocated as is | |
4230 | required for a return from FUNCTION_ARG. */ | |
4231 | bool (*allocate) (CUMULATIVE_ARGS *, enum machine_mode, const_tree); | |
4232 | ||
4233 | /* Return true if a result of mode MODE (or type TYPE if MODE is | |
4234 | BLKmode) is can be returned in this co-processor's registers. */ | |
4235 | bool (*is_return_candidate) (enum arm_pcs, enum machine_mode, const_tree); | |
4236 | ||
4237 | /* Allocate and return an RTX element to hold the return type of a | |
4238 | call, this routine must not fail and will only be called if | |
4239 | is_return_candidate returned true with the same parameters. */ | |
4240 | rtx (*allocate_return_reg) (enum arm_pcs, enum machine_mode, const_tree); | |
4241 | ||
4242 | /* Finish processing this argument and prepare to start processing | |
4243 | the next one. */ | |
4244 | void (*advance) (CUMULATIVE_ARGS *, enum machine_mode, const_tree); | |
4245 | } aapcs_cp_arg_layout[ARM_NUM_COPROC_SLOTS] = | |
4246 | { | |
4247 | AAPCS_CP(vfp) | |
4248 | }; | |
4249 | ||
4250 | #undef AAPCS_CP | |
4251 | ||
4252 | static int | |
4253 | aapcs_select_call_coproc (CUMULATIVE_ARGS *pcum, enum machine_mode mode, | |
9c6a2bee | 4254 | const_tree type) |
390b17c2 RE |
4255 | { |
4256 | int i; | |
4257 | ||
4258 | for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) | |
4259 | if (aapcs_cp_arg_layout[i].is_call_candidate (pcum, mode, type)) | |
4260 | return i; | |
4261 | ||
4262 | return -1; | |
4263 | } | |
4264 | ||
4265 | static int | |
4266 | aapcs_select_return_coproc (const_tree type, const_tree fntype) | |
4267 | { | |
4268 | /* We aren't passed a decl, so we can't check that a call is local. | |
4269 | However, it isn't clear that that would be a win anyway, since it | |
4270 | might limit some tail-calling opportunities. */ | |
4271 | enum arm_pcs pcs_variant; | |
4272 | ||
4273 | if (fntype) | |
4274 | { | |
4275 | const_tree fndecl = NULL_TREE; | |
4276 | ||
4277 | if (TREE_CODE (fntype) == FUNCTION_DECL) | |
4278 | { | |
4279 | fndecl = fntype; | |
4280 | fntype = TREE_TYPE (fntype); | |
4281 | } | |
4282 | ||
4283 | pcs_variant = arm_get_pcs_model (fntype, fndecl); | |
4284 | } | |
4285 | else | |
4286 | pcs_variant = arm_pcs_default; | |
4287 | ||
4288 | if (pcs_variant != ARM_PCS_AAPCS) | |
4289 | { | |
4290 | int i; | |
4291 | ||
4292 | for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) | |
4293 | if (aapcs_cp_arg_layout[i].is_return_candidate (pcs_variant, | |
4294 | TYPE_MODE (type), | |
4295 | type)) | |
4296 | return i; | |
4297 | } | |
4298 | return -1; | |
4299 | } | |
4300 | ||
4301 | static rtx | |
4302 | aapcs_allocate_return_reg (enum machine_mode mode, const_tree type, | |
4303 | const_tree fntype) | |
4304 | { | |
4305 | /* We aren't passed a decl, so we can't check that a call is local. | |
4306 | However, it isn't clear that that would be a win anyway, since it | |
4307 | might limit some tail-calling opportunities. */ | |
4308 | enum arm_pcs pcs_variant; | |
4309 | int unsignedp ATTRIBUTE_UNUSED; | |
4310 | ||
4311 | if (fntype) | |
4312 | { | |
4313 | const_tree fndecl = NULL_TREE; | |
4314 | ||
4315 | if (TREE_CODE (fntype) == FUNCTION_DECL) | |
4316 | { | |
4317 | fndecl = fntype; | |
4318 | fntype = TREE_TYPE (fntype); | |
4319 | } | |
4320 | ||
4321 | pcs_variant = arm_get_pcs_model (fntype, fndecl); | |
4322 | } | |
4323 | else | |
4324 | pcs_variant = arm_pcs_default; | |
4325 | ||
4326 | /* Promote integer types. */ | |
4327 | if (type && INTEGRAL_TYPE_P (type)) | |
4328 | mode = arm_promote_function_mode (type, mode, &unsignedp, fntype, 1); | |
4329 | ||
4330 | if (pcs_variant != ARM_PCS_AAPCS) | |
4331 | { | |
4332 | int i; | |
4333 | ||
4334 | for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) | |
4335 | if (aapcs_cp_arg_layout[i].is_return_candidate (pcs_variant, mode, | |
4336 | type)) | |
4337 | return aapcs_cp_arg_layout[i].allocate_return_reg (pcs_variant, | |
4338 | mode, type); | |
4339 | } | |
4340 | ||
4341 | /* Promotes small structs returned in a register to full-word size | |
4342 | for big-endian AAPCS. */ | |
4343 | if (type && arm_return_in_msb (type)) | |
4344 | { | |
4345 | HOST_WIDE_INT size = int_size_in_bytes (type); | |
4346 | if (size % UNITS_PER_WORD != 0) | |
4347 | { | |
4348 | size += UNITS_PER_WORD - size % UNITS_PER_WORD; | |
4349 | mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0); | |
4350 | } | |
4351 | } | |
4352 | ||
4353 | return gen_rtx_REG (mode, R0_REGNUM); | |
4354 | } | |
4355 | ||
4356 | rtx | |
4357 | aapcs_libcall_value (enum machine_mode mode) | |
4358 | { | |
4359 | return aapcs_allocate_return_reg (mode, NULL_TREE, NULL_TREE); | |
4360 | } | |
4361 | ||
4362 | /* Lay out a function argument using the AAPCS rules. The rule | |
4363 | numbers referred to here are those in the AAPCS. */ | |
4364 | static void | |
4365 | aapcs_layout_arg (CUMULATIVE_ARGS *pcum, enum machine_mode mode, | |
9c6a2bee | 4366 | const_tree type, bool named) |
390b17c2 RE |
4367 | { |
4368 | int nregs, nregs2; | |
4369 | int ncrn; | |
4370 | ||
4371 | /* We only need to do this once per argument. */ | |
4372 | if (pcum->aapcs_arg_processed) | |
4373 | return; | |
4374 | ||
4375 | pcum->aapcs_arg_processed = true; | |
4376 | ||
4377 | /* Special case: if named is false then we are handling an incoming | |
4378 | anonymous argument which is on the stack. */ | |
4379 | if (!named) | |
4380 | return; | |
4381 | ||
4382 | /* Is this a potential co-processor register candidate? */ | |
4383 | if (pcum->pcs_variant != ARM_PCS_AAPCS) | |
4384 | { | |
4385 | int slot = aapcs_select_call_coproc (pcum, mode, type); | |
4386 | pcum->aapcs_cprc_slot = slot; | |
4387 | ||
4388 | /* We don't have to apply any of the rules from part B of the | |
4389 | preparation phase, these are handled elsewhere in the | |
4390 | compiler. */ | |
4391 | ||
4392 | if (slot >= 0) | |
4393 | { | |
4394 | /* A Co-processor register candidate goes either in its own | |
4395 | class of registers or on the stack. */ | |
4396 | if (!pcum->aapcs_cprc_failed[slot]) | |
4397 | { | |
4398 | /* C1.cp - Try to allocate the argument to co-processor | |
4399 | registers. */ | |
4400 | if (aapcs_cp_arg_layout[slot].allocate (pcum, mode, type)) | |
4401 | return; | |
4402 | ||
4403 | /* C2.cp - Put the argument on the stack and note that we | |
4404 | can't assign any more candidates in this slot. We also | |
4405 | need to note that we have allocated stack space, so that | |
4406 | we won't later try to split a non-cprc candidate between | |
4407 | core registers and the stack. */ | |
4408 | pcum->aapcs_cprc_failed[slot] = true; | |
4409 | pcum->can_split = false; | |
4410 | } | |
4411 | ||
4412 | /* We didn't get a register, so this argument goes on the | |
4413 | stack. */ | |
4414 | gcc_assert (pcum->can_split == false); | |
4415 | return; | |
4416 | } | |
4417 | } | |
4418 | ||
4419 | /* C3 - For double-word aligned arguments, round the NCRN up to the | |
4420 | next even number. */ | |
4421 | ncrn = pcum->aapcs_ncrn; | |
4422 | if ((ncrn & 1) && arm_needs_doubleword_align (mode, type)) | |
4423 | ncrn++; | |
4424 | ||
4425 | nregs = ARM_NUM_REGS2(mode, type); | |
4426 | ||
4427 | /* Sigh, this test should really assert that nregs > 0, but a GCC | |
4428 | extension allows empty structs and then gives them empty size; it | |
4429 | then allows such a structure to be passed by value. For some of | |
4430 | the code below we have to pretend that such an argument has | |
4431 | non-zero size so that we 'locate' it correctly either in | |
4432 | registers or on the stack. */ | |
4433 | gcc_assert (nregs >= 0); | |
4434 | ||
4435 | nregs2 = nregs ? nregs : 1; | |
4436 | ||
4437 | /* C4 - Argument fits entirely in core registers. */ | |
4438 | if (ncrn + nregs2 <= NUM_ARG_REGS) | |
4439 | { | |
4440 | pcum->aapcs_reg = gen_rtx_REG (mode, ncrn); | |
4441 | pcum->aapcs_next_ncrn = ncrn + nregs; | |
4442 | return; | |
4443 | } | |
4444 | ||
4445 | /* C5 - Some core registers left and there are no arguments already | |
4446 | on the stack: split this argument between the remaining core | |
4447 | registers and the stack. */ | |
4448 | if (ncrn < NUM_ARG_REGS && pcum->can_split) | |
4449 | { | |
4450 | pcum->aapcs_reg = gen_rtx_REG (mode, ncrn); | |
4451 | pcum->aapcs_next_ncrn = NUM_ARG_REGS; | |
4452 | pcum->aapcs_partial = (NUM_ARG_REGS - ncrn) * UNITS_PER_WORD; | |
4453 | return; | |
4454 | } | |
4455 | ||
4456 | /* C6 - NCRN is set to 4. */ | |
4457 | pcum->aapcs_next_ncrn = NUM_ARG_REGS; | |
4458 | ||
4459 | /* C7,C8 - arugment goes on the stack. We have nothing to do here. */ | |
4460 | return; | |
4461 | } | |
4462 | ||
82e9d970 PB |
4463 | /* Initialize a variable CUM of type CUMULATIVE_ARGS |
4464 | for a call to a function whose data type is FNTYPE. | |
4465 | For a library call, FNTYPE is NULL. */ | |
4466 | void | |
f676971a | 4467 | arm_init_cumulative_args (CUMULATIVE_ARGS *pcum, tree fntype, |
390b17c2 | 4468 | rtx libname, |
e32bac5b | 4469 | tree fndecl ATTRIBUTE_UNUSED) |
82e9d970 | 4470 | { |
390b17c2 RE |
4471 | /* Long call handling. */ |
4472 | if (fntype) | |
4473 | pcum->pcs_variant = arm_get_pcs_model (fntype, fndecl); | |
4474 | else | |
4475 | pcum->pcs_variant = arm_pcs_default; | |
4476 | ||
4477 | if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) | |
4478 | { | |
4479 | if (arm_libcall_uses_aapcs_base (libname)) | |
4480 | pcum->pcs_variant = ARM_PCS_AAPCS; | |
4481 | ||
4482 | pcum->aapcs_ncrn = pcum->aapcs_next_ncrn = 0; | |
4483 | pcum->aapcs_reg = NULL_RTX; | |
4484 | pcum->aapcs_partial = 0; | |
4485 | pcum->aapcs_arg_processed = false; | |
4486 | pcum->aapcs_cprc_slot = -1; | |
4487 | pcum->can_split = true; | |
4488 | ||
4489 | if (pcum->pcs_variant != ARM_PCS_AAPCS) | |
4490 | { | |
4491 | int i; | |
4492 | ||
4493 | for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) | |
4494 | { | |
4495 | pcum->aapcs_cprc_failed[i] = false; | |
4496 | aapcs_cp_arg_layout[i].cum_init (pcum, fntype, libname, fndecl); | |
4497 | } | |
4498 | } | |
4499 | return; | |
4500 | } | |
4501 | ||
4502 | /* Legacy ABIs */ | |
4503 | ||
82e9d970 | 4504 | /* On the ARM, the offset starts at 0. */ |
29e339b9 | 4505 | pcum->nregs = 0; |
5a9335ef | 4506 | pcum->iwmmxt_nregs = 0; |
5848830f | 4507 | pcum->can_split = true; |
f676971a | 4508 | |
5a9335ef NC |
4509 | /* Varargs vectors are treated the same as long long. |
4510 | named_count avoids having to change the way arm handles 'named' */ | |
4511 | pcum->named_count = 0; | |
4512 | pcum->nargs = 0; | |
4513 | ||
4514 | if (TARGET_REALLY_IWMMXT && fntype) | |
4515 | { | |
4516 | tree fn_arg; | |
4517 | ||
4518 | for (fn_arg = TYPE_ARG_TYPES (fntype); | |
4519 | fn_arg; | |
4520 | fn_arg = TREE_CHAIN (fn_arg)) | |
4521 | pcum->named_count += 1; | |
4522 | ||
4523 | if (! pcum->named_count) | |
4524 | pcum->named_count = INT_MAX; | |
4525 | } | |
82e9d970 PB |
4526 | } |
4527 | ||
5848830f PB |
4528 | |
4529 | /* Return true if mode/type need doubleword alignment. */ | |
4530 | bool | |
9c6a2bee | 4531 | arm_needs_doubleword_align (enum machine_mode mode, const_tree type) |
5848830f | 4532 | { |
65a939f7 PB |
4533 | return (GET_MODE_ALIGNMENT (mode) > PARM_BOUNDARY |
4534 | || (type && TYPE_ALIGN (type) > PARM_BOUNDARY)); | |
5848830f PB |
4535 | } |
4536 | ||
4537 | ||
82e9d970 PB |
4538 | /* Determine where to put an argument to a function. |
4539 | Value is zero to push the argument on the stack, | |
4540 | or a hard register in which to store the argument. | |
4541 | ||
4542 | MODE is the argument's machine mode. | |
4543 | TYPE is the data type of the argument (as a tree). | |
4544 | This is null for libcalls where that information may | |
4545 | not be available. | |
4546 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
4547 | the preceding args and about the function being called. | |
4548 | NAMED is nonzero if this argument is a named parameter | |
9c6a2bee | 4549 | (otherwise it is an extra parameter matching an ellipsis). |
1d6e90ac | 4550 | |
9c6a2bee NF |
4551 | On the ARM, normally the first 16 bytes are passed in registers r0-r3; all |
4552 | other arguments are passed on the stack. If (NAMED == 0) (which happens | |
4553 | only in assign_parms, since TARGET_SETUP_INCOMING_VARARGS is | |
4554 | defined), say it is passed in the stack (function_prologue will | |
4555 | indeed make it pass in the stack if necessary). */ | |
4556 | ||
4557 | static rtx | |
e32bac5b | 4558 | arm_function_arg (CUMULATIVE_ARGS *pcum, enum machine_mode mode, |
9c6a2bee | 4559 | const_tree type, bool named) |
82e9d970 | 4560 | { |
5848830f PB |
4561 | int nregs; |
4562 | ||
390b17c2 RE |
4563 | /* Handle the special case quickly. Pick an arbitrary value for op2 of |
4564 | a call insn (op3 of a call_value insn). */ | |
4565 | if (mode == VOIDmode) | |
4566 | return const0_rtx; | |
4567 | ||
4568 | if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) | |
4569 | { | |
4570 | aapcs_layout_arg (pcum, mode, type, named); | |
4571 | return pcum->aapcs_reg; | |
4572 | } | |
4573 | ||
5848830f PB |
4574 | /* Varargs vectors are treated the same as long long. |
4575 | named_count avoids having to change the way arm handles 'named' */ | |
4576 | if (TARGET_IWMMXT_ABI | |
f676971a | 4577 | && arm_vector_mode_supported_p (mode) |
5848830f | 4578 | && pcum->named_count > pcum->nargs + 1) |
5a9335ef | 4579 | { |
5848830f PB |
4580 | if (pcum->iwmmxt_nregs <= 9) |
4581 | return gen_rtx_REG (mode, pcum->iwmmxt_nregs + FIRST_IWMMXT_REGNUM); | |
4582 | else | |
5a9335ef | 4583 | { |
5848830f PB |
4584 | pcum->can_split = false; |
4585 | return NULL_RTX; | |
5a9335ef | 4586 | } |
5a9335ef NC |
4587 | } |
4588 | ||
5848830f PB |
4589 | /* Put doubleword aligned quantities in even register pairs. */ |
4590 | if (pcum->nregs & 1 | |
4591 | && ARM_DOUBLEWORD_ALIGN | |
4592 | && arm_needs_doubleword_align (mode, type)) | |
4593 | pcum->nregs++; | |
4594 | ||
666c27b9 | 4595 | /* Only allow splitting an arg between regs and memory if all preceding |
5848830f PB |
4596 | args were allocated to regs. For args passed by reference we only count |
4597 | the reference pointer. */ | |
4598 | if (pcum->can_split) | |
4599 | nregs = 1; | |
4600 | else | |
4601 | nregs = ARM_NUM_REGS2 (mode, type); | |
4602 | ||
4603 | if (!named || pcum->nregs + nregs > NUM_ARG_REGS) | |
82e9d970 | 4604 | return NULL_RTX; |
f676971a | 4605 | |
82e9d970 PB |
4606 | return gen_rtx_REG (mode, pcum->nregs); |
4607 | } | |
1741620c | 4608 | |
78a52f11 RH |
4609 | static int |
4610 | arm_arg_partial_bytes (CUMULATIVE_ARGS *pcum, enum machine_mode mode, | |
390b17c2 | 4611 | tree type, bool named) |
78a52f11 RH |
4612 | { |
4613 | int nregs = pcum->nregs; | |
4614 | ||
390b17c2 RE |
4615 | if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) |
4616 | { | |
4617 | aapcs_layout_arg (pcum, mode, type, named); | |
4618 | return pcum->aapcs_partial; | |
4619 | } | |
4620 | ||
88f77cba | 4621 | if (TARGET_IWMMXT_ABI && arm_vector_mode_supported_p (mode)) |
78a52f11 RH |
4622 | return 0; |
4623 | ||
4624 | if (NUM_ARG_REGS > nregs | |
4625 | && (NUM_ARG_REGS < nregs + ARM_NUM_REGS2 (mode, type)) | |
4626 | && pcum->can_split) | |
4627 | return (NUM_ARG_REGS - nregs) * UNITS_PER_WORD; | |
4628 | ||
4629 | return 0; | |
4630 | } | |
4631 | ||
9c6a2bee NF |
4632 | /* Update the data in PCUM to advance over an argument |
4633 | of mode MODE and data type TYPE. | |
4634 | (TYPE is null for libcalls where that information may not be available.) */ | |
4635 | ||
4636 | static void | |
390b17c2 | 4637 | arm_function_arg_advance (CUMULATIVE_ARGS *pcum, enum machine_mode mode, |
9c6a2bee | 4638 | const_tree type, bool named) |
390b17c2 RE |
4639 | { |
4640 | if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) | |
4641 | { | |
4642 | aapcs_layout_arg (pcum, mode, type, named); | |
4643 | ||
4644 | if (pcum->aapcs_cprc_slot >= 0) | |
4645 | { | |
4646 | aapcs_cp_arg_layout[pcum->aapcs_cprc_slot].advance (pcum, mode, | |
4647 | type); | |
4648 | pcum->aapcs_cprc_slot = -1; | |
4649 | } | |
4650 | ||
4651 | /* Generic stuff. */ | |
4652 | pcum->aapcs_arg_processed = false; | |
4653 | pcum->aapcs_ncrn = pcum->aapcs_next_ncrn; | |
4654 | pcum->aapcs_reg = NULL_RTX; | |
4655 | pcum->aapcs_partial = 0; | |
4656 | } | |
4657 | else | |
4658 | { | |
4659 | pcum->nargs += 1; | |
4660 | if (arm_vector_mode_supported_p (mode) | |
4661 | && pcum->named_count > pcum->nargs | |
4662 | && TARGET_IWMMXT_ABI) | |
4663 | pcum->iwmmxt_nregs += 1; | |
4664 | else | |
4665 | pcum->nregs += ARM_NUM_REGS2 (mode, type); | |
4666 | } | |
4667 | } | |
4668 | ||
1741620c JD |
4669 | /* Variable sized types are passed by reference. This is a GCC |
4670 | extension to the ARM ABI. */ | |
4671 | ||
8cd5a4e0 RH |
4672 | static bool |
4673 | arm_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED, | |
4674 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
586de218 | 4675 | const_tree type, bool named ATTRIBUTE_UNUSED) |
1741620c JD |
4676 | { |
4677 | return type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST; | |
4678 | } | |
82e9d970 | 4679 | \f |
c27ba912 DM |
4680 | /* Encode the current state of the #pragma [no_]long_calls. */ |
4681 | typedef enum | |
82e9d970 | 4682 | { |
6fc0bb99 | 4683 | OFF, /* No #pragma [no_]long_calls is in effect. */ |
c27ba912 DM |
4684 | LONG, /* #pragma long_calls is in effect. */ |
4685 | SHORT /* #pragma no_long_calls is in effect. */ | |
4686 | } arm_pragma_enum; | |
82e9d970 | 4687 | |
c27ba912 | 4688 | static arm_pragma_enum arm_pragma_long_calls = OFF; |
82e9d970 | 4689 | |
8b97c5f8 | 4690 | void |
e32bac5b | 4691 | arm_pr_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED) |
82e9d970 | 4692 | { |
8b97c5f8 ZW |
4693 | arm_pragma_long_calls = LONG; |
4694 | } | |
4695 | ||
4696 | void | |
e32bac5b | 4697 | arm_pr_no_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED) |
8b97c5f8 ZW |
4698 | { |
4699 | arm_pragma_long_calls = SHORT; | |
4700 | } | |
4701 | ||
4702 | void | |
e32bac5b | 4703 | arm_pr_long_calls_off (struct cpp_reader * pfile ATTRIBUTE_UNUSED) |
8b97c5f8 ZW |
4704 | { |
4705 | arm_pragma_long_calls = OFF; | |
82e9d970 PB |
4706 | } |
4707 | \f | |
91d231cb JM |
4708 | /* Handle an attribute requiring a FUNCTION_DECL; |
4709 | arguments as in struct attribute_spec.handler. */ | |
4710 | static tree | |
e32bac5b RE |
4711 | arm_handle_fndecl_attribute (tree *node, tree name, tree args ATTRIBUTE_UNUSED, |
4712 | int flags ATTRIBUTE_UNUSED, bool *no_add_attrs) | |
91d231cb JM |
4713 | { |
4714 | if (TREE_CODE (*node) != FUNCTION_DECL) | |
4715 | { | |
29d08eba JM |
4716 | warning (OPT_Wattributes, "%qE attribute only applies to functions", |
4717 | name); | |
91d231cb JM |
4718 | *no_add_attrs = true; |
4719 | } | |
4720 | ||
4721 | return NULL_TREE; | |
4722 | } | |
4723 | ||
4724 | /* Handle an "interrupt" or "isr" attribute; | |
4725 | arguments as in struct attribute_spec.handler. */ | |
4726 | static tree | |
e32bac5b RE |
4727 | arm_handle_isr_attribute (tree *node, tree name, tree args, int flags, |
4728 | bool *no_add_attrs) | |
91d231cb JM |
4729 | { |
4730 | if (DECL_P (*node)) | |
4731 | { | |
4732 | if (TREE_CODE (*node) != FUNCTION_DECL) | |
4733 | { | |
29d08eba JM |
4734 | warning (OPT_Wattributes, "%qE attribute only applies to functions", |
4735 | name); | |
91d231cb JM |
4736 | *no_add_attrs = true; |
4737 | } | |
4738 | /* FIXME: the argument if any is checked for type attributes; | |
4739 | should it be checked for decl ones? */ | |
4740 | } | |
4741 | else | |
4742 | { | |
4743 | if (TREE_CODE (*node) == FUNCTION_TYPE | |
4744 | || TREE_CODE (*node) == METHOD_TYPE) | |
4745 | { | |
4746 | if (arm_isr_value (args) == ARM_FT_UNKNOWN) | |
4747 | { | |
29d08eba JM |
4748 | warning (OPT_Wattributes, "%qE attribute ignored", |
4749 | name); | |
91d231cb JM |
4750 | *no_add_attrs = true; |
4751 | } | |
4752 | } | |
4753 | else if (TREE_CODE (*node) == POINTER_TYPE | |
4754 | && (TREE_CODE (TREE_TYPE (*node)) == FUNCTION_TYPE | |
4755 | || TREE_CODE (TREE_TYPE (*node)) == METHOD_TYPE) | |
4756 | && arm_isr_value (args) != ARM_FT_UNKNOWN) | |
4757 | { | |
8dd16ecc | 4758 | *node = build_variant_type_copy (*node); |
1d6e90ac NC |
4759 | TREE_TYPE (*node) = build_type_attribute_variant |
4760 | (TREE_TYPE (*node), | |
4761 | tree_cons (name, args, TYPE_ATTRIBUTES (TREE_TYPE (*node)))); | |
91d231cb JM |
4762 | *no_add_attrs = true; |
4763 | } | |
4764 | else | |
4765 | { | |
4766 | /* Possibly pass this attribute on from the type to a decl. */ | |
4767 | if (flags & ((int) ATTR_FLAG_DECL_NEXT | |
4768 | | (int) ATTR_FLAG_FUNCTION_NEXT | |
4769 | | (int) ATTR_FLAG_ARRAY_NEXT)) | |
4770 | { | |
4771 | *no_add_attrs = true; | |
4772 | return tree_cons (name, args, NULL_TREE); | |
4773 | } | |
4774 | else | |
4775 | { | |
29d08eba JM |
4776 | warning (OPT_Wattributes, "%qE attribute ignored", |
4777 | name); | |
91d231cb JM |
4778 | } |
4779 | } | |
4780 | } | |
4781 | ||
4782 | return NULL_TREE; | |
82e9d970 PB |
4783 | } |
4784 | ||
390b17c2 RE |
4785 | /* Handle a "pcs" attribute; arguments as in struct |
4786 | attribute_spec.handler. */ | |
4787 | static tree | |
4788 | arm_handle_pcs_attribute (tree *node ATTRIBUTE_UNUSED, tree name, tree args, | |
4789 | int flags ATTRIBUTE_UNUSED, bool *no_add_attrs) | |
4790 | { | |
4791 | if (arm_pcs_from_attribute (args) == ARM_PCS_UNKNOWN) | |
4792 | { | |
a9717079 | 4793 | warning (OPT_Wattributes, "%qE attribute ignored", name); |
390b17c2 RE |
4794 | *no_add_attrs = true; |
4795 | } | |
4796 | return NULL_TREE; | |
4797 | } | |
4798 | ||
7bff66a7 | 4799 | #if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
04fb56d5 MM |
4800 | /* Handle the "notshared" attribute. This attribute is another way of |
4801 | requesting hidden visibility. ARM's compiler supports | |
4802 | "__declspec(notshared)"; we support the same thing via an | |
4803 | attribute. */ | |
4804 | ||
4805 | static tree | |
e0b92319 NC |
4806 | arm_handle_notshared_attribute (tree *node, |
4807 | tree name ATTRIBUTE_UNUSED, | |
4808 | tree args ATTRIBUTE_UNUSED, | |
4809 | int flags ATTRIBUTE_UNUSED, | |
04fb56d5 MM |
4810 | bool *no_add_attrs) |
4811 | { | |
4812 | tree decl = TYPE_NAME (*node); | |
4813 | ||
4814 | if (decl) | |
4815 | { | |
4816 | DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; | |
4817 | DECL_VISIBILITY_SPECIFIED (decl) = 1; | |
4818 | *no_add_attrs = false; | |
4819 | } | |
4820 | return NULL_TREE; | |
4821 | } | |
7bff66a7 | 4822 | #endif |
04fb56d5 | 4823 | |
82e9d970 PB |
4824 | /* Return 0 if the attributes for two types are incompatible, 1 if they |
4825 | are compatible, and 2 if they are nearly compatible (which causes a | |
4826 | warning to be generated). */ | |
8d8e52be | 4827 | static int |
3101faab | 4828 | arm_comp_type_attributes (const_tree type1, const_tree type2) |
82e9d970 | 4829 | { |
1cb8d58a | 4830 | int l1, l2, s1, s2; |
f676971a | 4831 | |
82e9d970 PB |
4832 | /* Check for mismatch of non-default calling convention. */ |
4833 | if (TREE_CODE (type1) != FUNCTION_TYPE) | |
4834 | return 1; | |
4835 | ||
4836 | /* Check for mismatched call attributes. */ | |
1cb8d58a NC |
4837 | l1 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type1)) != NULL; |
4838 | l2 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type2)) != NULL; | |
4839 | s1 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type1)) != NULL; | |
4840 | s2 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type2)) != NULL; | |
bd7fc26f NC |
4841 | |
4842 | /* Only bother to check if an attribute is defined. */ | |
4843 | if (l1 | l2 | s1 | s2) | |
4844 | { | |
4845 | /* If one type has an attribute, the other must have the same attribute. */ | |
1cb8d58a | 4846 | if ((l1 != l2) || (s1 != s2)) |
bd7fc26f | 4847 | return 0; |
82e9d970 | 4848 | |
bd7fc26f NC |
4849 | /* Disallow mixed attributes. */ |
4850 | if ((l1 & s2) || (l2 & s1)) | |
4851 | return 0; | |
4852 | } | |
f676971a | 4853 | |
6d3d9133 NC |
4854 | /* Check for mismatched ISR attribute. */ |
4855 | l1 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type1)) != NULL; | |
4856 | if (! l1) | |
4857 | l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1)) != NULL; | |
4858 | l2 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type2)) != NULL; | |
4859 | if (! l2) | |
4860 | l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2)) != NULL; | |
4861 | if (l1 != l2) | |
4862 | return 0; | |
4863 | ||
bd7fc26f | 4864 | return 1; |
82e9d970 PB |
4865 | } |
4866 | ||
c27ba912 DM |
4867 | /* Assigns default attributes to newly defined type. This is used to |
4868 | set short_call/long_call attributes for function types of | |
4869 | functions defined inside corresponding #pragma scopes. */ | |
8d8e52be | 4870 | static void |
e32bac5b | 4871 | arm_set_default_type_attributes (tree type) |
c27ba912 DM |
4872 | { |
4873 | /* Add __attribute__ ((long_call)) to all functions, when | |
4874 | inside #pragma long_calls or __attribute__ ((short_call)), | |
4875 | when inside #pragma no_long_calls. */ | |
4876 | if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) | |
4877 | { | |
4878 | tree type_attr_list, attr_name; | |
4879 | type_attr_list = TYPE_ATTRIBUTES (type); | |
4880 | ||
4881 | if (arm_pragma_long_calls == LONG) | |
4882 | attr_name = get_identifier ("long_call"); | |
4883 | else if (arm_pragma_long_calls == SHORT) | |
4884 | attr_name = get_identifier ("short_call"); | |
4885 | else | |
4886 | return; | |
4887 | ||
4888 | type_attr_list = tree_cons (attr_name, NULL_TREE, type_attr_list); | |
4889 | TYPE_ATTRIBUTES (type) = type_attr_list; | |
4890 | } | |
4891 | } | |
4892 | \f | |
25a65198 RS |
4893 | /* Return true if DECL is known to be linked into section SECTION. */ |
4894 | ||
4895 | static bool | |
4896 | arm_function_in_section_p (tree decl, section *section) | |
c27ba912 | 4897 | { |
25a65198 RS |
4898 | /* We can only be certain about functions defined in the same |
4899 | compilation unit. */ | |
4900 | if (!TREE_STATIC (decl)) | |
4901 | return false; | |
c27ba912 | 4902 | |
25a65198 RS |
4903 | /* Make sure that SYMBOL always binds to the definition in this |
4904 | compilation unit. */ | |
4905 | if (!targetm.binds_local_p (decl)) | |
4906 | return false; | |
c27ba912 | 4907 | |
25a65198 RS |
4908 | /* If DECL_SECTION_NAME is set, assume it is trustworthy. */ |
4909 | if (!DECL_SECTION_NAME (decl)) | |
4910 | { | |
25a65198 RS |
4911 | /* Make sure that we will not create a unique section for DECL. */ |
4912 | if (flag_function_sections || DECL_ONE_ONLY (decl)) | |
4913 | return false; | |
4914 | } | |
4915 | ||
4916 | return function_section (decl) == section; | |
c27ba912 DM |
4917 | } |
4918 | ||
a50aa827 | 4919 | /* Return nonzero if a 32-bit "long_call" should be generated for |
25a65198 RS |
4920 | a call from the current function to DECL. We generate a long_call |
4921 | if the function: | |
c27ba912 DM |
4922 | |
4923 | a. has an __attribute__((long call)) | |
4924 | or b. is within the scope of a #pragma long_calls | |
4925 | or c. the -mlong-calls command line switch has been specified | |
4926 | ||
4927 | However we do not generate a long call if the function: | |
f676971a | 4928 | |
c27ba912 DM |
4929 | d. has an __attribute__ ((short_call)) |
4930 | or e. is inside the scope of a #pragma no_long_calls | |
25a65198 | 4931 | or f. is defined in the same section as the current function. */ |
c27ba912 | 4932 | |
25a65198 RS |
4933 | bool |
4934 | arm_is_long_call_p (tree decl) | |
4935 | { | |
4936 | tree attrs; | |
c27ba912 | 4937 | |
25a65198 RS |
4938 | if (!decl) |
4939 | return TARGET_LONG_CALLS; | |
c27ba912 | 4940 | |
25a65198 RS |
4941 | attrs = TYPE_ATTRIBUTES (TREE_TYPE (decl)); |
4942 | if (lookup_attribute ("short_call", attrs)) | |
4943 | return false; | |
c27ba912 | 4944 | |
25a65198 RS |
4945 | /* For "f", be conservative, and only cater for cases in which the |
4946 | whole of the current function is placed in the same section. */ | |
4947 | if (!flag_reorder_blocks_and_partition | |
b3a796bc | 4948 | && TREE_CODE (decl) == FUNCTION_DECL |
25a65198 RS |
4949 | && arm_function_in_section_p (decl, current_function_section ())) |
4950 | return false; | |
a77655b1 | 4951 | |
25a65198 RS |
4952 | if (lookup_attribute ("long_call", attrs)) |
4953 | return true; | |
f676971a | 4954 | |
25a65198 | 4955 | return TARGET_LONG_CALLS; |
c27ba912 | 4956 | } |
f99fce0c | 4957 | |
825dda42 | 4958 | /* Return nonzero if it is ok to make a tail-call to DECL. */ |
4977bab6 | 4959 | static bool |
390b17c2 | 4960 | arm_function_ok_for_sibcall (tree decl, tree exp) |
f99fce0c | 4961 | { |
5b3e6663 | 4962 | unsigned long func_type; |
f99fce0c | 4963 | |
5a9335ef NC |
4964 | if (cfun->machine->sibcall_blocked) |
4965 | return false; | |
4966 | ||
f99fce0c | 4967 | /* Never tailcall something for which we have no decl, or if we |
7c19c715 JB |
4968 | are generating code for Thumb-1. */ |
4969 | if (decl == NULL || TARGET_THUMB1) | |
4977bab6 | 4970 | return false; |
f99fce0c | 4971 | |
9403b7f7 RS |
4972 | /* The PIC register is live on entry to VxWorks PLT entries, so we |
4973 | must make the call before restoring the PIC register. */ | |
4974 | if (TARGET_VXWORKS_RTP && flag_pic && !targetm.binds_local_p (decl)) | |
4975 | return false; | |
4976 | ||
f99fce0c | 4977 | /* Cannot tail-call to long calls, since these are out of range of |
25a65198 RS |
4978 | a branch instruction. */ |
4979 | if (arm_is_long_call_p (decl)) | |
4977bab6 | 4980 | return false; |
f99fce0c RE |
4981 | |
4982 | /* If we are interworking and the function is not declared static | |
f676971a | 4983 | then we can't tail-call it unless we know that it exists in this |
f99fce0c | 4984 | compilation unit (since it might be a Thumb routine). */ |
5895f793 | 4985 | if (TARGET_INTERWORK && TREE_PUBLIC (decl) && !TREE_ASM_WRITTEN (decl)) |
4977bab6 | 4986 | return false; |
f99fce0c | 4987 | |
5b3e6663 | 4988 | func_type = arm_current_func_type (); |
6d3d9133 | 4989 | /* Never tailcall from an ISR routine - it needs a special exit sequence. */ |
5b3e6663 PB |
4990 | if (IS_INTERRUPT (func_type)) |
4991 | return false; | |
4992 | ||
390b17c2 RE |
4993 | if (!VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl)))) |
4994 | { | |
4995 | /* Check that the return value locations are the same. For | |
4996 | example that we aren't returning a value from the sibling in | |
4997 | a VFP register but then need to transfer it to a core | |
4998 | register. */ | |
4999 | rtx a, b; | |
5000 | ||
5001 | a = arm_function_value (TREE_TYPE (exp), decl, false); | |
5002 | b = arm_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)), | |
5003 | cfun->decl, false); | |
5004 | if (!rtx_equal_p (a, b)) | |
5005 | return false; | |
5006 | } | |
5007 | ||
5b3e6663 PB |
5008 | /* Never tailcall if function may be called with a misaligned SP. */ |
5009 | if (IS_STACKALIGN (func_type)) | |
4977bab6 | 5010 | return false; |
6d3d9133 | 5011 | |
f99fce0c | 5012 | /* Everything else is ok. */ |
4977bab6 | 5013 | return true; |
f99fce0c RE |
5014 | } |
5015 | ||
82e9d970 | 5016 | \f |
6b990f6b RE |
5017 | /* Addressing mode support functions. */ |
5018 | ||
0b4be7de | 5019 | /* Return nonzero if X is a legitimate immediate operand when compiling |
020a4035 | 5020 | for PIC. We know that X satisfies CONSTANT_P and flag_pic is true. */ |
32de079a | 5021 | int |
e32bac5b | 5022 | legitimate_pic_operand_p (rtx x) |
32de079a | 5023 | { |
020a4035 RE |
5024 | if (GET_CODE (x) == SYMBOL_REF |
5025 | || (GET_CODE (x) == CONST | |
5026 | && GET_CODE (XEXP (x, 0)) == PLUS | |
5027 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)) | |
32de079a RE |
5028 | return 0; |
5029 | ||
5030 | return 1; | |
5031 | } | |
5032 | ||
9403b7f7 RS |
5033 | /* Record that the current function needs a PIC register. Initialize |
5034 | cfun->machine->pic_reg if we have not already done so. */ | |
5035 | ||
5036 | static void | |
5037 | require_pic_register (void) | |
5038 | { | |
5039 | /* A lot of the logic here is made obscure by the fact that this | |
5040 | routine gets called as part of the rtx cost estimation process. | |
5041 | We don't want those calls to affect any assumptions about the real | |
5042 | function; and further, we can't call entry_of_function() until we | |
5043 | start the real expansion process. */ | |
e3b5732b | 5044 | if (!crtl->uses_pic_offset_table) |
9403b7f7 | 5045 | { |
b3a13419 | 5046 | gcc_assert (can_create_pseudo_p ()); |
9403b7f7 RS |
5047 | if (arm_pic_register != INVALID_REGNUM) |
5048 | { | |
6d2538f5 JB |
5049 | if (!cfun->machine->pic_reg) |
5050 | cfun->machine->pic_reg = gen_rtx_REG (Pmode, arm_pic_register); | |
9403b7f7 RS |
5051 | |
5052 | /* Play games to avoid marking the function as needing pic | |
5053 | if we are being called as part of the cost-estimation | |
5054 | process. */ | |
04ef80ce | 5055 | if (current_ir_type () != IR_GIMPLE || currently_expanding_to_rtl) |
e3b5732b | 5056 | crtl->uses_pic_offset_table = 1; |
9403b7f7 RS |
5057 | } |
5058 | else | |
5059 | { | |
5060 | rtx seq; | |
5061 | ||
6d2538f5 JB |
5062 | if (!cfun->machine->pic_reg) |
5063 | cfun->machine->pic_reg = gen_reg_rtx (Pmode); | |
9403b7f7 RS |
5064 | |
5065 | /* Play games to avoid marking the function as needing pic | |
5066 | if we are being called as part of the cost-estimation | |
5067 | process. */ | |
04ef80ce | 5068 | if (current_ir_type () != IR_GIMPLE || currently_expanding_to_rtl) |
9403b7f7 | 5069 | { |
e3b5732b | 5070 | crtl->uses_pic_offset_table = 1; |
9403b7f7 RS |
5071 | start_sequence (); |
5072 | ||
5073 | arm_load_pic_register (0UL); | |
5074 | ||
5075 | seq = get_insns (); | |
5076 | end_sequence (); | |
af618949 MM |
5077 | /* We can be called during expansion of PHI nodes, where |
5078 | we can't yet emit instructions directly in the final | |
5079 | insn stream. Queue the insns on the entry edge, they will | |
5080 | be committed after everything else is expanded. */ | |
5081 | insert_insn_on_edge (seq, single_succ_edge (ENTRY_BLOCK_PTR)); | |
9403b7f7 RS |
5082 | } |
5083 | } | |
5084 | } | |
5085 | } | |
5086 | ||
32de079a | 5087 | rtx |
e32bac5b | 5088 | legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg) |
32de079a | 5089 | { |
a3c48721 RE |
5090 | if (GET_CODE (orig) == SYMBOL_REF |
5091 | || GET_CODE (orig) == LABEL_REF) | |
32de079a | 5092 | { |
32de079a | 5093 | rtx insn; |
020a4035 | 5094 | |
32de079a RE |
5095 | if (reg == 0) |
5096 | { | |
b3a13419 | 5097 | gcc_assert (can_create_pseudo_p ()); |
e6d29d15 | 5098 | reg = gen_reg_rtx (Pmode); |
32de079a | 5099 | } |
32de079a | 5100 | |
9403b7f7 RS |
5101 | /* VxWorks does not impose a fixed gap between segments; the run-time |
5102 | gap can be different from the object-file gap. We therefore can't | |
5103 | use GOTOFF unless we are absolutely sure that the symbol is in the | |
5104 | same segment as the GOT. Unfortunately, the flexibility of linker | |
5105 | scripts means that we can't be sure of that in general, so assume | |
5106 | that GOTOFF is never valid on VxWorks. */ | |
14f583b8 | 5107 | if ((GET_CODE (orig) == LABEL_REF |
f676971a | 5108 | || (GET_CODE (orig) == SYMBOL_REF && |
94428622 | 5109 | SYMBOL_REF_LOCAL_P (orig))) |
9403b7f7 RS |
5110 | && NEED_GOT_RELOC |
5111 | && !TARGET_VXWORKS_RTP) | |
85c9bcd4 | 5112 | insn = arm_pic_static_addr (orig, reg); |
a3c48721 RE |
5113 | else |
5114 | { | |
d37c3c62 MK |
5115 | rtx pat; |
5116 | rtx mem; | |
5117 | ||
85c9bcd4 WG |
5118 | /* If this function doesn't have a pic register, create one now. */ |
5119 | require_pic_register (); | |
5120 | ||
d37c3c62 | 5121 | pat = gen_calculate_pic_address (reg, cfun->machine->pic_reg, orig); |
85c9bcd4 | 5122 | |
d37c3c62 MK |
5123 | /* Make the MEM as close to a constant as possible. */ |
5124 | mem = SET_SRC (pat); | |
5125 | gcc_assert (MEM_P (mem) && !MEM_VOLATILE_P (mem)); | |
5126 | MEM_READONLY_P (mem) = 1; | |
5127 | MEM_NOTRAP_P (mem) = 1; | |
5128 | ||
5129 | insn = emit_insn (pat); | |
a3c48721 RE |
5130 | } |
5131 | ||
32de079a RE |
5132 | /* Put a REG_EQUAL note on this insn, so that it can be optimized |
5133 | by loop. */ | |
bd94cb6e SB |
5134 | set_unique_reg_note (insn, REG_EQUAL, orig); |
5135 | ||
32de079a RE |
5136 | return reg; |
5137 | } | |
5138 | else if (GET_CODE (orig) == CONST) | |
5139 | { | |
5140 | rtx base, offset; | |
5141 | ||
5142 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
020a4035 | 5143 | && XEXP (XEXP (orig, 0), 0) == cfun->machine->pic_reg) |
32de079a RE |
5144 | return orig; |
5145 | ||
f67358da | 5146 | /* Handle the case where we have: const (UNSPEC_TLS). */ |
d3585b76 DJ |
5147 | if (GET_CODE (XEXP (orig, 0)) == UNSPEC |
5148 | && XINT (XEXP (orig, 0), 1) == UNSPEC_TLS) | |
5149 | return orig; | |
5150 | ||
f67358da PB |
5151 | /* Handle the case where we have: |
5152 | const (plus (UNSPEC_TLS) (ADDEND)). The ADDEND must be a | |
5153 | CONST_INT. */ | |
5154 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
5155 | && GET_CODE (XEXP (XEXP (orig, 0), 0)) == UNSPEC | |
5156 | && XINT (XEXP (XEXP (orig, 0), 0), 1) == UNSPEC_TLS) | |
5157 | { | |
5158 | gcc_assert (GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT); | |
5159 | return orig; | |
5160 | } | |
5161 | ||
32de079a RE |
5162 | if (reg == 0) |
5163 | { | |
b3a13419 | 5164 | gcc_assert (can_create_pseudo_p ()); |
e6d29d15 | 5165 | reg = gen_reg_rtx (Pmode); |
32de079a RE |
5166 | } |
5167 | ||
e6d29d15 | 5168 | gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS); |
e0b92319 | 5169 | |
e6d29d15 NS |
5170 | base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg); |
5171 | offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode, | |
5172 | base == reg ? 0 : reg); | |
32de079a RE |
5173 | |
5174 | if (GET_CODE (offset) == CONST_INT) | |
5175 | { | |
5176 | /* The base register doesn't really matter, we only want to | |
5177 | test the index for the appropriate mode. */ | |
1e1ab407 | 5178 | if (!arm_legitimate_index_p (mode, offset, SET, 0)) |
6b990f6b | 5179 | { |
b3a13419 | 5180 | gcc_assert (can_create_pseudo_p ()); |
e6d29d15 | 5181 | offset = force_reg (Pmode, offset); |
6b990f6b | 5182 | } |
32de079a | 5183 | |
32de079a | 5184 | if (GET_CODE (offset) == CONST_INT) |
ed8908e7 | 5185 | return plus_constant (base, INTVAL (offset)); |
32de079a RE |
5186 | } |
5187 | ||
5188 | if (GET_MODE_SIZE (mode) > 4 | |
5189 | && (GET_MODE_CLASS (mode) == MODE_INT | |
5190 | || TARGET_SOFT_FLOAT)) | |
5191 | { | |
5192 | emit_insn (gen_addsi3 (reg, base, offset)); | |
5193 | return reg; | |
5194 | } | |
5195 | ||
43cffd11 | 5196 | return gen_rtx_PLUS (Pmode, base, offset); |
32de079a | 5197 | } |
32de079a RE |
5198 | |
5199 | return orig; | |
5200 | } | |
5201 | ||
57934c39 | 5202 | |
5b3e6663 | 5203 | /* Find a spare register to use during the prolog of a function. */ |
57934c39 PB |
5204 | |
5205 | static int | |
b279b20a | 5206 | thumb_find_work_register (unsigned long pushed_regs_mask) |
57934c39 PB |
5207 | { |
5208 | int reg; | |
5209 | ||
b279b20a NC |
5210 | /* Check the argument registers first as these are call-used. The |
5211 | register allocation order means that sometimes r3 might be used | |
5212 | but earlier argument registers might not, so check them all. */ | |
5213 | for (reg = LAST_ARG_REGNUM; reg >= 0; reg --) | |
6fb5fa3c | 5214 | if (!df_regs_ever_live_p (reg)) |
b279b20a NC |
5215 | return reg; |
5216 | ||
5217 | /* Before going on to check the call-saved registers we can try a couple | |
5218 | more ways of deducing that r3 is available. The first is when we are | |
5219 | pushing anonymous arguments onto the stack and we have less than 4 | |
5220 | registers worth of fixed arguments(*). In this case r3 will be part of | |
5221 | the variable argument list and so we can be sure that it will be | |
5222 | pushed right at the start of the function. Hence it will be available | |
5223 | for the rest of the prologue. | |
38173d38 | 5224 | (*): ie crtl->args.pretend_args_size is greater than 0. */ |
b279b20a | 5225 | if (cfun->machine->uses_anonymous_args |
38173d38 | 5226 | && crtl->args.pretend_args_size > 0) |
57934c39 PB |
5227 | return LAST_ARG_REGNUM; |
5228 | ||
b279b20a NC |
5229 | /* The other case is when we have fixed arguments but less than 4 registers |
5230 | worth. In this case r3 might be used in the body of the function, but | |
5231 | it is not being used to convey an argument into the function. In theory | |
38173d38 | 5232 | we could just check crtl->args.size to see how many bytes are |
b279b20a NC |
5233 | being passed in argument registers, but it seems that it is unreliable. |
5234 | Sometimes it will have the value 0 when in fact arguments are being | |
5235 | passed. (See testcase execute/20021111-1.c for an example). So we also | |
5236 | check the args_info.nregs field as well. The problem with this field is | |
5237 | that it makes no allowances for arguments that are passed to the | |
5238 | function but which are not used. Hence we could miss an opportunity | |
5239 | when a function has an unused argument in r3. But it is better to be | |
5240 | safe than to be sorry. */ | |
5241 | if (! cfun->machine->uses_anonymous_args | |
38173d38 JH |
5242 | && crtl->args.size >= 0 |
5243 | && crtl->args.size <= (LAST_ARG_REGNUM * UNITS_PER_WORD) | |
f6d2671e | 5244 | && crtl->args.info.nregs < 4) |
b279b20a | 5245 | return LAST_ARG_REGNUM; |
e0b92319 | 5246 | |
b279b20a NC |
5247 | /* Otherwise look for a call-saved register that is going to be pushed. */ |
5248 | for (reg = LAST_LO_REGNUM; reg > LAST_ARG_REGNUM; reg --) | |
5249 | if (pushed_regs_mask & (1 << reg)) | |
57934c39 PB |
5250 | return reg; |
5251 | ||
5b3e6663 PB |
5252 | if (TARGET_THUMB2) |
5253 | { | |
5254 | /* Thumb-2 can use high regs. */ | |
5255 | for (reg = FIRST_HI_REGNUM; reg < 15; reg ++) | |
5256 | if (pushed_regs_mask & (1 << reg)) | |
5257 | return reg; | |
5258 | } | |
b279b20a NC |
5259 | /* Something went wrong - thumb_compute_save_reg_mask() |
5260 | should have arranged for a suitable register to be pushed. */ | |
e6d29d15 | 5261 | gcc_unreachable (); |
57934c39 PB |
5262 | } |
5263 | ||
f16fe45f | 5264 | static GTY(()) int pic_labelno; |
876f13b0 | 5265 | |
fe013435 PB |
5266 | /* Generate code to load the PIC register. In thumb mode SCRATCH is a |
5267 | low register. */ | |
876f13b0 | 5268 | |
32de079a | 5269 | void |
e55ef7f4 | 5270 | arm_load_pic_register (unsigned long saved_regs ATTRIBUTE_UNUSED) |
32de079a | 5271 | { |
f9bd1a89 | 5272 | rtx l1, labelno, pic_tmp, pic_rtx, pic_reg; |
32de079a | 5273 | |
e3b5732b | 5274 | if (crtl->uses_pic_offset_table == 0 || TARGET_SINGLE_PIC_BASE) |
32de079a RE |
5275 | return; |
5276 | ||
e6d29d15 | 5277 | gcc_assert (flag_pic); |
32de079a | 5278 | |
9403b7f7 RS |
5279 | pic_reg = cfun->machine->pic_reg; |
5280 | if (TARGET_VXWORKS_RTP) | |
5281 | { | |
5282 | pic_rtx = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE); | |
5283 | pic_rtx = gen_rtx_CONST (Pmode, pic_rtx); | |
87d05b44 | 5284 | emit_insn (gen_pic_load_addr_32bit (pic_reg, pic_rtx)); |
43cffd11 | 5285 | |
9403b7f7 | 5286 | emit_insn (gen_rtx_SET (Pmode, pic_reg, gen_rtx_MEM (Pmode, pic_reg))); |
f676971a | 5287 | |
9403b7f7 RS |
5288 | pic_tmp = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX); |
5289 | emit_insn (gen_pic_offset_arm (pic_reg, pic_reg, pic_tmp)); | |
4bec9f7d | 5290 | } |
9403b7f7 | 5291 | else |
5b3e6663 | 5292 | { |
9403b7f7 RS |
5293 | /* We use an UNSPEC rather than a LABEL_REF because this label |
5294 | never appears in the code stream. */ | |
5295 | ||
5296 | labelno = GEN_INT (pic_labelno++); | |
5297 | l1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); | |
5298 | l1 = gen_rtx_CONST (VOIDmode, l1); | |
5299 | ||
9403b7f7 RS |
5300 | /* On the ARM the PC register contains 'dot + 8' at the time of the |
5301 | addition, on the Thumb it is 'dot + 4'. */ | |
f9bd1a89 RS |
5302 | pic_rtx = plus_constant (l1, TARGET_ARM ? 8 : 4); |
5303 | pic_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, pic_rtx), | |
5304 | UNSPEC_GOTSYM_OFF); | |
9403b7f7 RS |
5305 | pic_rtx = gen_rtx_CONST (Pmode, pic_rtx); |
5306 | ||
87d05b44 | 5307 | if (TARGET_32BIT) |
9403b7f7 | 5308 | { |
87d05b44 RE |
5309 | emit_insn (gen_pic_load_addr_32bit (pic_reg, pic_rtx)); |
5310 | if (TARGET_ARM) | |
5311 | emit_insn (gen_pic_add_dot_plus_eight (pic_reg, pic_reg, labelno)); | |
9403b7f7 | 5312 | else |
87d05b44 | 5313 | emit_insn (gen_pic_add_dot_plus_four (pic_reg, pic_reg, labelno)); |
9403b7f7 RS |
5314 | } |
5315 | else /* TARGET_THUMB1 */ | |
876f13b0 | 5316 | { |
9403b7f7 RS |
5317 | if (arm_pic_register != INVALID_REGNUM |
5318 | && REGNO (pic_reg) > LAST_LO_REGNUM) | |
5319 | { | |
5320 | /* We will have pushed the pic register, so we should always be | |
5321 | able to find a work register. */ | |
5322 | pic_tmp = gen_rtx_REG (SImode, | |
5323 | thumb_find_work_register (saved_regs)); | |
5324 | emit_insn (gen_pic_load_addr_thumb1 (pic_tmp, pic_rtx)); | |
5325 | emit_insn (gen_movsi (pic_offset_table_rtx, pic_tmp)); | |
5326 | } | |
5327 | else | |
5328 | emit_insn (gen_pic_load_addr_thumb1 (pic_reg, pic_rtx)); | |
5329 | emit_insn (gen_pic_add_dot_plus_four (pic_reg, pic_reg, labelno)); | |
876f13b0 | 5330 | } |
4bec9f7d | 5331 | } |
32de079a | 5332 | |
32de079a RE |
5333 | /* Need to emit this whether or not we obey regdecls, |
5334 | since setjmp/longjmp can cause life info to screw up. */ | |
c41c1387 | 5335 | emit_use (pic_reg); |
32de079a RE |
5336 | } |
5337 | ||
85c9bcd4 WG |
5338 | /* Generate code to load the address of a static var when flag_pic is set. */ |
5339 | static rtx | |
5340 | arm_pic_static_addr (rtx orig, rtx reg) | |
5341 | { | |
5342 | rtx l1, labelno, offset_rtx, insn; | |
5343 | ||
5344 | gcc_assert (flag_pic); | |
5345 | ||
5346 | /* We use an UNSPEC rather than a LABEL_REF because this label | |
5347 | never appears in the code stream. */ | |
5348 | labelno = GEN_INT (pic_labelno++); | |
5349 | l1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); | |
5350 | l1 = gen_rtx_CONST (VOIDmode, l1); | |
5351 | ||
5352 | /* On the ARM the PC register contains 'dot + 8' at the time of the | |
5353 | addition, on the Thumb it is 'dot + 4'. */ | |
5354 | offset_rtx = plus_constant (l1, TARGET_ARM ? 8 : 4); | |
5355 | offset_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, orig, offset_rtx), | |
5356 | UNSPEC_SYMBOL_OFFSET); | |
5357 | offset_rtx = gen_rtx_CONST (Pmode, offset_rtx); | |
5358 | ||
5359 | if (TARGET_32BIT) | |
5360 | { | |
5361 | emit_insn (gen_pic_load_addr_32bit (reg, offset_rtx)); | |
5362 | if (TARGET_ARM) | |
5363 | insn = emit_insn (gen_pic_add_dot_plus_eight (reg, reg, labelno)); | |
5364 | else | |
5365 | insn = emit_insn (gen_pic_add_dot_plus_four (reg, reg, labelno)); | |
5366 | } | |
5367 | else /* TARGET_THUMB1 */ | |
5368 | { | |
5369 | emit_insn (gen_pic_load_addr_thumb1 (reg, offset_rtx)); | |
5370 | insn = emit_insn (gen_pic_add_dot_plus_four (reg, reg, labelno)); | |
5371 | } | |
5372 | ||
5373 | return insn; | |
5374 | } | |
876f13b0 | 5375 | |
6b990f6b RE |
5376 | /* Return nonzero if X is valid as an ARM state addressing register. */ |
5377 | static int | |
e32bac5b | 5378 | arm_address_register_rtx_p (rtx x, int strict_p) |
6b990f6b RE |
5379 | { |
5380 | int regno; | |
5381 | ||
5382 | if (GET_CODE (x) != REG) | |
5383 | return 0; | |
5384 | ||
5385 | regno = REGNO (x); | |
5386 | ||
5387 | if (strict_p) | |
5388 | return ARM_REGNO_OK_FOR_BASE_P (regno); | |
5389 | ||
5390 | return (regno <= LAST_ARM_REGNUM | |
5391 | || regno >= FIRST_PSEUDO_REGISTER | |
5392 | || regno == FRAME_POINTER_REGNUM | |
5393 | || regno == ARG_POINTER_REGNUM); | |
5394 | } | |
5395 | ||
d3585b76 DJ |
5396 | /* Return TRUE if this rtx is the difference of a symbol and a label, |
5397 | and will reduce to a PC-relative relocation in the object file. | |
5398 | Expressions like this can be left alone when generating PIC, rather | |
5399 | than forced through the GOT. */ | |
5400 | static int | |
5401 | pcrel_constant_p (rtx x) | |
5402 | { | |
5403 | if (GET_CODE (x) == MINUS) | |
5404 | return symbol_mentioned_p (XEXP (x, 0)) && label_mentioned_p (XEXP (x, 1)); | |
5405 | ||
5406 | return FALSE; | |
5407 | } | |
5408 | ||
d37c3c62 MK |
5409 | /* Return true if X will surely end up in an index register after next |
5410 | splitting pass. */ | |
5411 | static bool | |
5412 | will_be_in_index_register (const_rtx x) | |
5413 | { | |
5414 | /* arm.md: calculate_pic_address will split this into a register. */ | |
5415 | return GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_PIC_SYM; | |
5416 | } | |
5417 | ||
6b990f6b RE |
5418 | /* Return nonzero if X is a valid ARM state address operand. */ |
5419 | int | |
c6c3dba9 PB |
5420 | arm_legitimate_address_outer_p (enum machine_mode mode, rtx x, RTX_CODE outer, |
5421 | int strict_p) | |
6b990f6b | 5422 | { |
fdd695fd PB |
5423 | bool use_ldrd; |
5424 | enum rtx_code code = GET_CODE (x); | |
f676971a | 5425 | |
6b990f6b RE |
5426 | if (arm_address_register_rtx_p (x, strict_p)) |
5427 | return 1; | |
5428 | ||
fdd695fd PB |
5429 | use_ldrd = (TARGET_LDRD |
5430 | && (mode == DImode | |
5431 | || (mode == DFmode && (TARGET_SOFT_FLOAT || TARGET_VFP)))); | |
5432 | ||
5433 | if (code == POST_INC || code == PRE_DEC | |
5434 | || ((code == PRE_INC || code == POST_DEC) | |
5435 | && (use_ldrd || GET_MODE_SIZE (mode) <= 4))) | |
6b990f6b RE |
5436 | return arm_address_register_rtx_p (XEXP (x, 0), strict_p); |
5437 | ||
fdd695fd | 5438 | else if ((code == POST_MODIFY || code == PRE_MODIFY) |
6b990f6b RE |
5439 | && arm_address_register_rtx_p (XEXP (x, 0), strict_p) |
5440 | && GET_CODE (XEXP (x, 1)) == PLUS | |
386d3a16 | 5441 | && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0))) |
fdd695fd PB |
5442 | { |
5443 | rtx addend = XEXP (XEXP (x, 1), 1); | |
5444 | ||
112cdef5 | 5445 | /* Don't allow ldrd post increment by register because it's hard |
fdd695fd PB |
5446 | to fixup invalid register choices. */ |
5447 | if (use_ldrd | |
5448 | && GET_CODE (x) == POST_MODIFY | |
5449 | && GET_CODE (addend) == REG) | |
5450 | return 0; | |
5451 | ||
5452 | return ((use_ldrd || GET_MODE_SIZE (mode) <= 4) | |
5453 | && arm_legitimate_index_p (mode, addend, outer, strict_p)); | |
5454 | } | |
6b990f6b RE |
5455 | |
5456 | /* After reload constants split into minipools will have addresses | |
5457 | from a LABEL_REF. */ | |
0bfb39ef | 5458 | else if (reload_completed |
fdd695fd PB |
5459 | && (code == LABEL_REF |
5460 | || (code == CONST | |
6b990f6b RE |
5461 | && GET_CODE (XEXP (x, 0)) == PLUS |
5462 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF | |
5463 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))) | |
5464 | return 1; | |
5465 | ||
88f77cba | 5466 | else if (mode == TImode || (TARGET_NEON && VALID_NEON_STRUCT_MODE (mode))) |
6b990f6b RE |
5467 | return 0; |
5468 | ||
fdd695fd | 5469 | else if (code == PLUS) |
6b990f6b RE |
5470 | { |
5471 | rtx xop0 = XEXP (x, 0); | |
5472 | rtx xop1 = XEXP (x, 1); | |
5473 | ||
5474 | return ((arm_address_register_rtx_p (xop0, strict_p) | |
d37c3c62 MK |
5475 | && ((GET_CODE(xop1) == CONST_INT |
5476 | && arm_legitimate_index_p (mode, xop1, outer, strict_p)) | |
5477 | || (!strict_p && will_be_in_index_register (xop1)))) | |
6b990f6b | 5478 | || (arm_address_register_rtx_p (xop1, strict_p) |
1e1ab407 | 5479 | && arm_legitimate_index_p (mode, xop0, outer, strict_p))); |
6b990f6b RE |
5480 | } |
5481 | ||
5482 | #if 0 | |
5483 | /* Reload currently can't handle MINUS, so disable this for now */ | |
5484 | else if (GET_CODE (x) == MINUS) | |
5485 | { | |
5486 | rtx xop0 = XEXP (x, 0); | |
5487 | rtx xop1 = XEXP (x, 1); | |
5488 | ||
5489 | return (arm_address_register_rtx_p (xop0, strict_p) | |
1e1ab407 | 5490 | && arm_legitimate_index_p (mode, xop1, outer, strict_p)); |
6b990f6b RE |
5491 | } |
5492 | #endif | |
5493 | ||
5494 | else if (GET_MODE_CLASS (mode) != MODE_FLOAT | |
fdd695fd | 5495 | && code == SYMBOL_REF |
6b990f6b RE |
5496 | && CONSTANT_POOL_ADDRESS_P (x) |
5497 | && ! (flag_pic | |
d3585b76 DJ |
5498 | && symbol_mentioned_p (get_pool_constant (x)) |
5499 | && ! pcrel_constant_p (get_pool_constant (x)))) | |
6b990f6b RE |
5500 | return 1; |
5501 | ||
6b990f6b RE |
5502 | return 0; |
5503 | } | |
5504 | ||
5b3e6663 | 5505 | /* Return nonzero if X is a valid Thumb-2 address operand. */ |
c6c3dba9 | 5506 | static int |
5b3e6663 PB |
5507 | thumb2_legitimate_address_p (enum machine_mode mode, rtx x, int strict_p) |
5508 | { | |
5509 | bool use_ldrd; | |
5510 | enum rtx_code code = GET_CODE (x); | |
5511 | ||
5512 | if (arm_address_register_rtx_p (x, strict_p)) | |
5513 | return 1; | |
5514 | ||
5515 | use_ldrd = (TARGET_LDRD | |
5516 | && (mode == DImode | |
5517 | || (mode == DFmode && (TARGET_SOFT_FLOAT || TARGET_VFP)))); | |
5518 | ||
5519 | if (code == POST_INC || code == PRE_DEC | |
5520 | || ((code == PRE_INC || code == POST_DEC) | |
5521 | && (use_ldrd || GET_MODE_SIZE (mode) <= 4))) | |
5522 | return arm_address_register_rtx_p (XEXP (x, 0), strict_p); | |
5523 | ||
5524 | else if ((code == POST_MODIFY || code == PRE_MODIFY) | |
5525 | && arm_address_register_rtx_p (XEXP (x, 0), strict_p) | |
5526 | && GET_CODE (XEXP (x, 1)) == PLUS | |
5527 | && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0))) | |
5528 | { | |
5529 | /* Thumb-2 only has autoincrement by constant. */ | |
5530 | rtx addend = XEXP (XEXP (x, 1), 1); | |
5531 | HOST_WIDE_INT offset; | |
5532 | ||
5533 | if (GET_CODE (addend) != CONST_INT) | |
5534 | return 0; | |
5535 | ||
5536 | offset = INTVAL(addend); | |
5537 | if (GET_MODE_SIZE (mode) <= 4) | |
5538 | return (offset > -256 && offset < 256); | |
5539 | ||
5540 | return (use_ldrd && offset > -1024 && offset < 1024 | |
5541 | && (offset & 3) == 0); | |
5542 | } | |
5543 | ||
5544 | /* After reload constants split into minipools will have addresses | |
5545 | from a LABEL_REF. */ | |
5546 | else if (reload_completed | |
5547 | && (code == LABEL_REF | |
5548 | || (code == CONST | |
5549 | && GET_CODE (XEXP (x, 0)) == PLUS | |
5550 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF | |
5551 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))) | |
5552 | return 1; | |
5553 | ||
88f77cba | 5554 | else if (mode == TImode || (TARGET_NEON && VALID_NEON_STRUCT_MODE (mode))) |
5b3e6663 PB |
5555 | return 0; |
5556 | ||
5557 | else if (code == PLUS) | |
5558 | { | |
5559 | rtx xop0 = XEXP (x, 0); | |
5560 | rtx xop1 = XEXP (x, 1); | |
5561 | ||
5562 | return ((arm_address_register_rtx_p (xop0, strict_p) | |
d37c3c62 MK |
5563 | && (thumb2_legitimate_index_p (mode, xop1, strict_p) |
5564 | || (!strict_p && will_be_in_index_register (xop1)))) | |
5b3e6663 PB |
5565 | || (arm_address_register_rtx_p (xop1, strict_p) |
5566 | && thumb2_legitimate_index_p (mode, xop0, strict_p))); | |
5567 | } | |
5568 | ||
5569 | else if (GET_MODE_CLASS (mode) != MODE_FLOAT | |
5570 | && code == SYMBOL_REF | |
5571 | && CONSTANT_POOL_ADDRESS_P (x) | |
5572 | && ! (flag_pic | |
5573 | && symbol_mentioned_p (get_pool_constant (x)) | |
5574 | && ! pcrel_constant_p (get_pool_constant (x)))) | |
5575 | return 1; | |
5576 | ||
5577 | return 0; | |
5578 | } | |
5579 | ||
6b990f6b RE |
5580 | /* Return nonzero if INDEX is valid for an address index operand in |
5581 | ARM state. */ | |
5582 | static int | |
1e1ab407 RE |
5583 | arm_legitimate_index_p (enum machine_mode mode, rtx index, RTX_CODE outer, |
5584 | int strict_p) | |
6b990f6b RE |
5585 | { |
5586 | HOST_WIDE_INT range; | |
5587 | enum rtx_code code = GET_CODE (index); | |
5588 | ||
778ebdd9 PB |
5589 | /* Standard coprocessor addressing modes. */ |
5590 | if (TARGET_HARD_FLOAT | |
5591 | && (TARGET_FPA || TARGET_MAVERICK) | |
5592 | && (GET_MODE_CLASS (mode) == MODE_FLOAT | |
5593 | || (TARGET_MAVERICK && mode == DImode))) | |
6b990f6b RE |
5594 | return (code == CONST_INT && INTVAL (index) < 1024 |
5595 | && INTVAL (index) > -1024 | |
5596 | && (INTVAL (index) & 3) == 0); | |
5597 | ||
88f77cba JB |
5598 | if (TARGET_NEON |
5599 | && (VALID_NEON_DREG_MODE (mode) || VALID_NEON_QREG_MODE (mode))) | |
5600 | return (code == CONST_INT | |
5601 | && INTVAL (index) < 1016 | |
5602 | && INTVAL (index) > -1024 | |
5603 | && (INTVAL (index) & 3) == 0); | |
5604 | ||
5a9335ef NC |
5605 | if (TARGET_REALLY_IWMMXT && VALID_IWMMXT_REG_MODE (mode)) |
5606 | return (code == CONST_INT | |
3657dc3e PB |
5607 | && INTVAL (index) < 1024 |
5608 | && INTVAL (index) > -1024 | |
5609 | && (INTVAL (index) & 3) == 0); | |
5a9335ef | 5610 | |
fdd695fd PB |
5611 | if (arm_address_register_rtx_p (index, strict_p) |
5612 | && (GET_MODE_SIZE (mode) <= 4)) | |
5613 | return 1; | |
5614 | ||
5615 | if (mode == DImode || mode == DFmode) | |
5616 | { | |
5617 | if (code == CONST_INT) | |
5618 | { | |
5619 | HOST_WIDE_INT val = INTVAL (index); | |
5620 | ||
5621 | if (TARGET_LDRD) | |
5622 | return val > -256 && val < 256; | |
5623 | else | |
f372c932 | 5624 | return val > -4096 && val < 4092; |
fdd695fd PB |
5625 | } |
5626 | ||
5627 | return TARGET_LDRD && arm_address_register_rtx_p (index, strict_p); | |
5628 | } | |
5629 | ||
6b990f6b | 5630 | if (GET_MODE_SIZE (mode) <= 4 |
1e1ab407 RE |
5631 | && ! (arm_arch4 |
5632 | && (mode == HImode | |
0fd8c3ad | 5633 | || mode == HFmode |
1e1ab407 | 5634 | || (mode == QImode && outer == SIGN_EXTEND)))) |
6b990f6b | 5635 | { |
1e1ab407 RE |
5636 | if (code == MULT) |
5637 | { | |
5638 | rtx xiop0 = XEXP (index, 0); | |
5639 | rtx xiop1 = XEXP (index, 1); | |
5640 | ||
5641 | return ((arm_address_register_rtx_p (xiop0, strict_p) | |
5642 | && power_of_two_operand (xiop1, SImode)) | |
5643 | || (arm_address_register_rtx_p (xiop1, strict_p) | |
5644 | && power_of_two_operand (xiop0, SImode))); | |
5645 | } | |
5646 | else if (code == LSHIFTRT || code == ASHIFTRT | |
5647 | || code == ASHIFT || code == ROTATERT) | |
5648 | { | |
5649 | rtx op = XEXP (index, 1); | |
6b990f6b | 5650 | |
1e1ab407 RE |
5651 | return (arm_address_register_rtx_p (XEXP (index, 0), strict_p) |
5652 | && GET_CODE (op) == CONST_INT | |
5653 | && INTVAL (op) > 0 | |
5654 | && INTVAL (op) <= 31); | |
5655 | } | |
6b990f6b RE |
5656 | } |
5657 | ||
1e1ab407 RE |
5658 | /* For ARM v4 we may be doing a sign-extend operation during the |
5659 | load. */ | |
e1471c91 | 5660 | if (arm_arch4) |
1e1ab407 | 5661 | { |
0fd8c3ad SL |
5662 | if (mode == HImode |
5663 | || mode == HFmode | |
5664 | || (outer == SIGN_EXTEND && mode == QImode)) | |
1e1ab407 RE |
5665 | range = 256; |
5666 | else | |
5667 | range = 4096; | |
5668 | } | |
e1471c91 | 5669 | else |
0fd8c3ad | 5670 | range = (mode == HImode || mode == HFmode) ? 4095 : 4096; |
6b990f6b RE |
5671 | |
5672 | return (code == CONST_INT | |
5673 | && INTVAL (index) < range | |
5674 | && INTVAL (index) > -range); | |
76a318e9 RE |
5675 | } |
5676 | ||
5b3e6663 PB |
5677 | /* Return true if OP is a valid index scaling factor for Thumb-2 address |
5678 | index operand. i.e. 1, 2, 4 or 8. */ | |
5679 | static bool | |
5680 | thumb2_index_mul_operand (rtx op) | |
5681 | { | |
5682 | HOST_WIDE_INT val; | |
5683 | ||
5684 | if (GET_CODE(op) != CONST_INT) | |
5685 | return false; | |
5686 | ||
5687 | val = INTVAL(op); | |
5688 | return (val == 1 || val == 2 || val == 4 || val == 8); | |
5689 | } | |
5690 | ||
5691 | /* Return nonzero if INDEX is a valid Thumb-2 address index operand. */ | |
5692 | static int | |
5693 | thumb2_legitimate_index_p (enum machine_mode mode, rtx index, int strict_p) | |
5694 | { | |
5695 | enum rtx_code code = GET_CODE (index); | |
5696 | ||
5697 | /* ??? Combine arm and thumb2 coprocessor addressing modes. */ | |
5698 | /* Standard coprocessor addressing modes. */ | |
5699 | if (TARGET_HARD_FLOAT | |
5700 | && (TARGET_FPA || TARGET_MAVERICK) | |
5701 | && (GET_MODE_CLASS (mode) == MODE_FLOAT | |
5702 | || (TARGET_MAVERICK && mode == DImode))) | |
5703 | return (code == CONST_INT && INTVAL (index) < 1024 | |
5704 | && INTVAL (index) > -1024 | |
5705 | && (INTVAL (index) & 3) == 0); | |
5706 | ||
5707 | if (TARGET_REALLY_IWMMXT && VALID_IWMMXT_REG_MODE (mode)) | |
fe2d934b PB |
5708 | { |
5709 | /* For DImode assume values will usually live in core regs | |
5710 | and only allow LDRD addressing modes. */ | |
5711 | if (!TARGET_LDRD || mode != DImode) | |
5712 | return (code == CONST_INT | |
5713 | && INTVAL (index) < 1024 | |
5714 | && INTVAL (index) > -1024 | |
5715 | && (INTVAL (index) & 3) == 0); | |
5716 | } | |
5b3e6663 | 5717 | |
88f77cba JB |
5718 | if (TARGET_NEON |
5719 | && (VALID_NEON_DREG_MODE (mode) || VALID_NEON_QREG_MODE (mode))) | |
5720 | return (code == CONST_INT | |
5721 | && INTVAL (index) < 1016 | |
5722 | && INTVAL (index) > -1024 | |
5723 | && (INTVAL (index) & 3) == 0); | |
5724 | ||
5b3e6663 PB |
5725 | if (arm_address_register_rtx_p (index, strict_p) |
5726 | && (GET_MODE_SIZE (mode) <= 4)) | |
5727 | return 1; | |
5728 | ||
5729 | if (mode == DImode || mode == DFmode) | |
5730 | { | |
e07e020b RR |
5731 | if (code == CONST_INT) |
5732 | { | |
5733 | HOST_WIDE_INT val = INTVAL (index); | |
5734 | /* ??? Can we assume ldrd for thumb2? */ | |
5735 | /* Thumb-2 ldrd only has reg+const addressing modes. */ | |
5736 | /* ldrd supports offsets of +-1020. | |
5737 | However the ldr fallback does not. */ | |
5738 | return val > -256 && val < 256 && (val & 3) == 0; | |
5739 | } | |
5740 | else | |
5b3e6663 | 5741 | return 0; |
5b3e6663 PB |
5742 | } |
5743 | ||
5744 | if (code == MULT) | |
5745 | { | |
5746 | rtx xiop0 = XEXP (index, 0); | |
5747 | rtx xiop1 = XEXP (index, 1); | |
5748 | ||
5749 | return ((arm_address_register_rtx_p (xiop0, strict_p) | |
5750 | && thumb2_index_mul_operand (xiop1)) | |
5751 | || (arm_address_register_rtx_p (xiop1, strict_p) | |
5752 | && thumb2_index_mul_operand (xiop0))); | |
5753 | } | |
5754 | else if (code == ASHIFT) | |
5755 | { | |
5756 | rtx op = XEXP (index, 1); | |
5757 | ||
5758 | return (arm_address_register_rtx_p (XEXP (index, 0), strict_p) | |
5759 | && GET_CODE (op) == CONST_INT | |
5760 | && INTVAL (op) > 0 | |
5761 | && INTVAL (op) <= 3); | |
5762 | } | |
5763 | ||
5764 | return (code == CONST_INT | |
5765 | && INTVAL (index) < 4096 | |
5766 | && INTVAL (index) > -256); | |
5767 | } | |
5768 | ||
5769 | /* Return nonzero if X is valid as a 16-bit Thumb state base register. */ | |
76a318e9 | 5770 | static int |
5b3e6663 | 5771 | thumb1_base_register_rtx_p (rtx x, enum machine_mode mode, int strict_p) |
76a318e9 RE |
5772 | { |
5773 | int regno; | |
5774 | ||
5775 | if (GET_CODE (x) != REG) | |
5776 | return 0; | |
5777 | ||
5778 | regno = REGNO (x); | |
5779 | ||
5780 | if (strict_p) | |
5b3e6663 | 5781 | return THUMB1_REGNO_MODE_OK_FOR_BASE_P (regno, mode); |
76a318e9 RE |
5782 | |
5783 | return (regno <= LAST_LO_REGNUM | |
07e58265 | 5784 | || regno > LAST_VIRTUAL_REGISTER |
76a318e9 RE |
5785 | || regno == FRAME_POINTER_REGNUM |
5786 | || (GET_MODE_SIZE (mode) >= 4 | |
5787 | && (regno == STACK_POINTER_REGNUM | |
edf7cee8 | 5788 | || regno >= FIRST_PSEUDO_REGISTER |
76a318e9 RE |
5789 | || x == hard_frame_pointer_rtx |
5790 | || x == arg_pointer_rtx))); | |
5791 | } | |
5792 | ||
5793 | /* Return nonzero if x is a legitimate index register. This is the case | |
5794 | for any base register that can access a QImode object. */ | |
5795 | inline static int | |
5b3e6663 | 5796 | thumb1_index_register_rtx_p (rtx x, int strict_p) |
76a318e9 | 5797 | { |
5b3e6663 | 5798 | return thumb1_base_register_rtx_p (x, QImode, strict_p); |
76a318e9 RE |
5799 | } |
5800 | ||
5b3e6663 | 5801 | /* Return nonzero if x is a legitimate 16-bit Thumb-state address. |
f676971a | 5802 | |
76a318e9 RE |
5803 | The AP may be eliminated to either the SP or the FP, so we use the |
5804 | least common denominator, e.g. SImode, and offsets from 0 to 64. | |
5805 | ||
5806 | ??? Verify whether the above is the right approach. | |
5807 | ||
5808 | ??? Also, the FP may be eliminated to the SP, so perhaps that | |
5809 | needs special handling also. | |
5810 | ||
5811 | ??? Look at how the mips16 port solves this problem. It probably uses | |
5812 | better ways to solve some of these problems. | |
5813 | ||
5814 | Although it is not incorrect, we don't accept QImode and HImode | |
5815 | addresses based on the frame pointer or arg pointer until the | |
5816 | reload pass starts. This is so that eliminating such addresses | |
5817 | into stack based ones won't produce impossible code. */ | |
c6c3dba9 | 5818 | static int |
5b3e6663 | 5819 | thumb1_legitimate_address_p (enum machine_mode mode, rtx x, int strict_p) |
76a318e9 RE |
5820 | { |
5821 | /* ??? Not clear if this is right. Experiment. */ | |
5822 | if (GET_MODE_SIZE (mode) < 4 | |
5823 | && !(reload_in_progress || reload_completed) | |
5824 | && (reg_mentioned_p (frame_pointer_rtx, x) | |
5825 | || reg_mentioned_p (arg_pointer_rtx, x) | |
5826 | || reg_mentioned_p (virtual_incoming_args_rtx, x) | |
5827 | || reg_mentioned_p (virtual_outgoing_args_rtx, x) | |
5828 | || reg_mentioned_p (virtual_stack_dynamic_rtx, x) | |
5829 | || reg_mentioned_p (virtual_stack_vars_rtx, x))) | |
5830 | return 0; | |
5831 | ||
5832 | /* Accept any base register. SP only in SImode or larger. */ | |
5b3e6663 | 5833 | else if (thumb1_base_register_rtx_p (x, mode, strict_p)) |
76a318e9 RE |
5834 | return 1; |
5835 | ||
18dbd950 | 5836 | /* This is PC relative data before arm_reorg runs. */ |
76a318e9 RE |
5837 | else if (GET_MODE_SIZE (mode) >= 4 && CONSTANT_P (x) |
5838 | && GET_CODE (x) == SYMBOL_REF | |
020a4035 | 5839 | && CONSTANT_POOL_ADDRESS_P (x) && !flag_pic) |
76a318e9 RE |
5840 | return 1; |
5841 | ||
18dbd950 | 5842 | /* This is PC relative data after arm_reorg runs. */ |
0fd8c3ad SL |
5843 | else if ((GET_MODE_SIZE (mode) >= 4 || mode == HFmode) |
5844 | && reload_completed | |
76a318e9 RE |
5845 | && (GET_CODE (x) == LABEL_REF |
5846 | || (GET_CODE (x) == CONST | |
5847 | && GET_CODE (XEXP (x, 0)) == PLUS | |
5848 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF | |
5849 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))) | |
5850 | return 1; | |
5851 | ||
5852 | /* Post-inc indexing only supported for SImode and larger. */ | |
5853 | else if (GET_CODE (x) == POST_INC && GET_MODE_SIZE (mode) >= 4 | |
5b3e6663 | 5854 | && thumb1_index_register_rtx_p (XEXP (x, 0), strict_p)) |
76a318e9 RE |
5855 | return 1; |
5856 | ||
5857 | else if (GET_CODE (x) == PLUS) | |
5858 | { | |
5859 | /* REG+REG address can be any two index registers. */ | |
5860 | /* We disallow FRAME+REG addressing since we know that FRAME | |
5861 | will be replaced with STACK, and SP relative addressing only | |
5862 | permits SP+OFFSET. */ | |
5863 | if (GET_MODE_SIZE (mode) <= 4 | |
5864 | && XEXP (x, 0) != frame_pointer_rtx | |
5865 | && XEXP (x, 1) != frame_pointer_rtx | |
5b3e6663 | 5866 | && thumb1_index_register_rtx_p (XEXP (x, 0), strict_p) |
d37c3c62 MK |
5867 | && (thumb1_index_register_rtx_p (XEXP (x, 1), strict_p) |
5868 | || (!strict_p && will_be_in_index_register (XEXP (x, 1))))) | |
76a318e9 RE |
5869 | return 1; |
5870 | ||
5871 | /* REG+const has 5-7 bit offset for non-SP registers. */ | |
5b3e6663 | 5872 | else if ((thumb1_index_register_rtx_p (XEXP (x, 0), strict_p) |
76a318e9 RE |
5873 | || XEXP (x, 0) == arg_pointer_rtx) |
5874 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
5875 | && thumb_legitimate_offset_p (mode, INTVAL (XEXP (x, 1)))) | |
5876 | return 1; | |
5877 | ||
a50aa827 | 5878 | /* REG+const has 10-bit offset for SP, but only SImode and |
76a318e9 RE |
5879 | larger is supported. */ |
5880 | /* ??? Should probably check for DI/DFmode overflow here | |
5881 | just like GO_IF_LEGITIMATE_OFFSET does. */ | |
5882 | else if (GET_CODE (XEXP (x, 0)) == REG | |
5883 | && REGNO (XEXP (x, 0)) == STACK_POINTER_REGNUM | |
5884 | && GET_MODE_SIZE (mode) >= 4 | |
5885 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
5886 | && INTVAL (XEXP (x, 1)) >= 0 | |
5887 | && INTVAL (XEXP (x, 1)) + GET_MODE_SIZE (mode) <= 1024 | |
5888 | && (INTVAL (XEXP (x, 1)) & 3) == 0) | |
5889 | return 1; | |
5890 | ||
5891 | else if (GET_CODE (XEXP (x, 0)) == REG | |
c5289e45 RE |
5892 | && (REGNO (XEXP (x, 0)) == FRAME_POINTER_REGNUM |
5893 | || REGNO (XEXP (x, 0)) == ARG_POINTER_REGNUM | |
5894 | || (REGNO (XEXP (x, 0)) >= FIRST_VIRTUAL_REGISTER | |
32990d5b JJ |
5895 | && REGNO (XEXP (x, 0)) |
5896 | <= LAST_VIRTUAL_POINTER_REGISTER)) | |
76a318e9 RE |
5897 | && GET_MODE_SIZE (mode) >= 4 |
5898 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
5899 | && (INTVAL (XEXP (x, 1)) & 3) == 0) | |
5900 | return 1; | |
5901 | } | |
5902 | ||
5903 | else if (GET_MODE_CLASS (mode) != MODE_FLOAT | |
f954388e | 5904 | && GET_MODE_SIZE (mode) == 4 |
76a318e9 RE |
5905 | && GET_CODE (x) == SYMBOL_REF |
5906 | && CONSTANT_POOL_ADDRESS_P (x) | |
d3585b76 DJ |
5907 | && ! (flag_pic |
5908 | && symbol_mentioned_p (get_pool_constant (x)) | |
5909 | && ! pcrel_constant_p (get_pool_constant (x)))) | |
76a318e9 RE |
5910 | return 1; |
5911 | ||
5912 | return 0; | |
5913 | } | |
5914 | ||
5915 | /* Return nonzero if VAL can be used as an offset in a Thumb-state address | |
5916 | instruction of mode MODE. */ | |
5917 | int | |
e32bac5b | 5918 | thumb_legitimate_offset_p (enum machine_mode mode, HOST_WIDE_INT val) |
76a318e9 RE |
5919 | { |
5920 | switch (GET_MODE_SIZE (mode)) | |
5921 | { | |
5922 | case 1: | |
5923 | return val >= 0 && val < 32; | |
5924 | ||
5925 | case 2: | |
5926 | return val >= 0 && val < 64 && (val & 1) == 0; | |
5927 | ||
5928 | default: | |
5929 | return (val >= 0 | |
5930 | && (val + GET_MODE_SIZE (mode)) <= 128 | |
5931 | && (val & 3) == 0); | |
5932 | } | |
5933 | } | |
5934 | ||
c6c3dba9 PB |
5935 | bool |
5936 | arm_legitimate_address_p (enum machine_mode mode, rtx x, bool strict_p) | |
5937 | { | |
5938 | if (TARGET_ARM) | |
5939 | return arm_legitimate_address_outer_p (mode, x, SET, strict_p); | |
5940 | else if (TARGET_THUMB2) | |
5941 | return thumb2_legitimate_address_p (mode, x, strict_p); | |
5942 | else /* if (TARGET_THUMB1) */ | |
5943 | return thumb1_legitimate_address_p (mode, x, strict_p); | |
5944 | } | |
5945 | ||
d3585b76 DJ |
5946 | /* Build the SYMBOL_REF for __tls_get_addr. */ |
5947 | ||
5948 | static GTY(()) rtx tls_get_addr_libfunc; | |
5949 | ||
5950 | static rtx | |
5951 | get_tls_get_addr (void) | |
5952 | { | |
5953 | if (!tls_get_addr_libfunc) | |
5954 | tls_get_addr_libfunc = init_one_libfunc ("__tls_get_addr"); | |
5955 | return tls_get_addr_libfunc; | |
5956 | } | |
5957 | ||
5958 | static rtx | |
5959 | arm_load_tp (rtx target) | |
5960 | { | |
5961 | if (!target) | |
5962 | target = gen_reg_rtx (SImode); | |
5963 | ||
5964 | if (TARGET_HARD_TP) | |
5965 | { | |
5966 | /* Can return in any reg. */ | |
5967 | emit_insn (gen_load_tp_hard (target)); | |
5968 | } | |
5969 | else | |
5970 | { | |
5971 | /* Always returned in r0. Immediately copy the result into a pseudo, | |
5972 | otherwise other uses of r0 (e.g. setting up function arguments) may | |
5973 | clobber the value. */ | |
5974 | ||
5975 | rtx tmp; | |
5976 | ||
5977 | emit_insn (gen_load_tp_soft ()); | |
5978 | ||
5979 | tmp = gen_rtx_REG (SImode, 0); | |
5980 | emit_move_insn (target, tmp); | |
5981 | } | |
5982 | return target; | |
5983 | } | |
5984 | ||
5985 | static rtx | |
5986 | load_tls_operand (rtx x, rtx reg) | |
5987 | { | |
5988 | rtx tmp; | |
5989 | ||
5990 | if (reg == NULL_RTX) | |
5991 | reg = gen_reg_rtx (SImode); | |
5992 | ||
5993 | tmp = gen_rtx_CONST (SImode, x); | |
5994 | ||
5995 | emit_move_insn (reg, tmp); | |
5996 | ||
5997 | return reg; | |
5998 | } | |
5999 | ||
6000 | static rtx | |
6001 | arm_call_tls_get_addr (rtx x, rtx reg, rtx *valuep, int reloc) | |
6002 | { | |
f16fe45f | 6003 | rtx insns, label, labelno, sum; |
d3585b76 DJ |
6004 | |
6005 | start_sequence (); | |
6006 | ||
f16fe45f DJ |
6007 | labelno = GEN_INT (pic_labelno++); |
6008 | label = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); | |
6009 | label = gen_rtx_CONST (VOIDmode, label); | |
6010 | ||
d3585b76 | 6011 | sum = gen_rtx_UNSPEC (Pmode, |
f16fe45f | 6012 | gen_rtvec (4, x, GEN_INT (reloc), label, |
d3585b76 DJ |
6013 | GEN_INT (TARGET_ARM ? 8 : 4)), |
6014 | UNSPEC_TLS); | |
6015 | reg = load_tls_operand (sum, reg); | |
6016 | ||
6017 | if (TARGET_ARM) | |
f16fe45f | 6018 | emit_insn (gen_pic_add_dot_plus_eight (reg, reg, labelno)); |
5b3e6663 | 6019 | else if (TARGET_THUMB2) |
87d05b44 | 6020 | emit_insn (gen_pic_add_dot_plus_four (reg, reg, labelno)); |
5b3e6663 | 6021 | else /* TARGET_THUMB1 */ |
f16fe45f | 6022 | emit_insn (gen_pic_add_dot_plus_four (reg, reg, labelno)); |
d3585b76 DJ |
6023 | |
6024 | *valuep = emit_library_call_value (get_tls_get_addr (), NULL_RTX, LCT_PURE, /* LCT_CONST? */ | |
6025 | Pmode, 1, reg, Pmode); | |
6026 | ||
6027 | insns = get_insns (); | |
6028 | end_sequence (); | |
6029 | ||
6030 | return insns; | |
6031 | } | |
6032 | ||
6033 | rtx | |
6034 | legitimize_tls_address (rtx x, rtx reg) | |
6035 | { | |
f16fe45f | 6036 | rtx dest, tp, label, labelno, sum, insns, ret, eqv, addend; |
d3585b76 DJ |
6037 | unsigned int model = SYMBOL_REF_TLS_MODEL (x); |
6038 | ||
6039 | switch (model) | |
6040 | { | |
6041 | case TLS_MODEL_GLOBAL_DYNAMIC: | |
6042 | insns = arm_call_tls_get_addr (x, reg, &ret, TLS_GD32); | |
6043 | dest = gen_reg_rtx (Pmode); | |
6044 | emit_libcall_block (insns, dest, ret, x); | |
6045 | return dest; | |
6046 | ||
6047 | case TLS_MODEL_LOCAL_DYNAMIC: | |
6048 | insns = arm_call_tls_get_addr (x, reg, &ret, TLS_LDM32); | |
6049 | ||
6050 | /* Attach a unique REG_EQUIV, to allow the RTL optimizers to | |
6051 | share the LDM result with other LD model accesses. */ | |
6052 | eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const1_rtx), | |
6053 | UNSPEC_TLS); | |
6054 | dest = gen_reg_rtx (Pmode); | |
e66e1c68 | 6055 | emit_libcall_block (insns, dest, ret, eqv); |
d3585b76 DJ |
6056 | |
6057 | /* Load the addend. */ | |
6058 | addend = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, x, GEN_INT (TLS_LDO32)), | |
6059 | UNSPEC_TLS); | |
6060 | addend = force_reg (SImode, gen_rtx_CONST (SImode, addend)); | |
6061 | return gen_rtx_PLUS (Pmode, dest, addend); | |
6062 | ||
6063 | case TLS_MODEL_INITIAL_EXEC: | |
f16fe45f DJ |
6064 | labelno = GEN_INT (pic_labelno++); |
6065 | label = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); | |
6066 | label = gen_rtx_CONST (VOIDmode, label); | |
d3585b76 | 6067 | sum = gen_rtx_UNSPEC (Pmode, |
f16fe45f | 6068 | gen_rtvec (4, x, GEN_INT (TLS_IE32), label, |
d3585b76 DJ |
6069 | GEN_INT (TARGET_ARM ? 8 : 4)), |
6070 | UNSPEC_TLS); | |
6071 | reg = load_tls_operand (sum, reg); | |
6072 | ||
6073 | if (TARGET_ARM) | |
f16fe45f | 6074 | emit_insn (gen_tls_load_dot_plus_eight (reg, reg, labelno)); |
5b3e6663 | 6075 | else if (TARGET_THUMB2) |
2e5505a4 | 6076 | emit_insn (gen_tls_load_dot_plus_four (reg, NULL, reg, labelno)); |
d3585b76 DJ |
6077 | else |
6078 | { | |
f16fe45f | 6079 | emit_insn (gen_pic_add_dot_plus_four (reg, reg, labelno)); |
d3585b76 DJ |
6080 | emit_move_insn (reg, gen_const_mem (SImode, reg)); |
6081 | } | |
6082 | ||
6083 | tp = arm_load_tp (NULL_RTX); | |
6084 | ||
6085 | return gen_rtx_PLUS (Pmode, tp, reg); | |
6086 | ||
6087 | case TLS_MODEL_LOCAL_EXEC: | |
6088 | tp = arm_load_tp (NULL_RTX); | |
6089 | ||
6090 | reg = gen_rtx_UNSPEC (Pmode, | |
6091 | gen_rtvec (2, x, GEN_INT (TLS_LE32)), | |
6092 | UNSPEC_TLS); | |
6093 | reg = force_reg (SImode, gen_rtx_CONST (SImode, reg)); | |
6094 | ||
6095 | return gen_rtx_PLUS (Pmode, tp, reg); | |
6096 | ||
6097 | default: | |
6098 | abort (); | |
6099 | } | |
6100 | } | |
6101 | ||
ccf4d512 RE |
6102 | /* Try machine-dependent ways of modifying an illegitimate address |
6103 | to be legitimate. If we find one, return the new, valid address. */ | |
ccf4d512 | 6104 | rtx |
e32bac5b | 6105 | arm_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode) |
ccf4d512 | 6106 | { |
506d7b68 PB |
6107 | if (!TARGET_ARM) |
6108 | { | |
6109 | /* TODO: legitimize_address for Thumb2. */ | |
6110 | if (TARGET_THUMB2) | |
6111 | return x; | |
6112 | return thumb_legitimize_address (x, orig_x, mode); | |
6113 | } | |
6114 | ||
d3585b76 DJ |
6115 | if (arm_tls_symbol_p (x)) |
6116 | return legitimize_tls_address (x, NULL_RTX); | |
6117 | ||
ccf4d512 RE |
6118 | if (GET_CODE (x) == PLUS) |
6119 | { | |
6120 | rtx xop0 = XEXP (x, 0); | |
6121 | rtx xop1 = XEXP (x, 1); | |
6122 | ||
6123 | if (CONSTANT_P (xop0) && !symbol_mentioned_p (xop0)) | |
6124 | xop0 = force_reg (SImode, xop0); | |
6125 | ||
6126 | if (CONSTANT_P (xop1) && !symbol_mentioned_p (xop1)) | |
6127 | xop1 = force_reg (SImode, xop1); | |
6128 | ||
6129 | if (ARM_BASE_REGISTER_RTX_P (xop0) | |
6130 | && GET_CODE (xop1) == CONST_INT) | |
6131 | { | |
6132 | HOST_WIDE_INT n, low_n; | |
6133 | rtx base_reg, val; | |
6134 | n = INTVAL (xop1); | |
6135 | ||
9b66ebb1 PB |
6136 | /* VFP addressing modes actually allow greater offsets, but for |
6137 | now we just stick with the lowest common denominator. */ | |
6138 | if (mode == DImode | |
6139 | || ((TARGET_SOFT_FLOAT || TARGET_VFP) && mode == DFmode)) | |
ccf4d512 RE |
6140 | { |
6141 | low_n = n & 0x0f; | |
6142 | n &= ~0x0f; | |
6143 | if (low_n > 4) | |
6144 | { | |
6145 | n += 16; | |
6146 | low_n -= 16; | |
6147 | } | |
6148 | } | |
6149 | else | |
6150 | { | |
6151 | low_n = ((mode) == TImode ? 0 | |
6152 | : n >= 0 ? (n & 0xfff) : -((-n) & 0xfff)); | |
6153 | n -= low_n; | |
6154 | } | |
6155 | ||
6156 | base_reg = gen_reg_rtx (SImode); | |
d66437c5 | 6157 | val = force_operand (plus_constant (xop0, n), NULL_RTX); |
ccf4d512 | 6158 | emit_move_insn (base_reg, val); |
d66437c5 | 6159 | x = plus_constant (base_reg, low_n); |
ccf4d512 RE |
6160 | } |
6161 | else if (xop0 != XEXP (x, 0) || xop1 != XEXP (x, 1)) | |
6162 | x = gen_rtx_PLUS (SImode, xop0, xop1); | |
6163 | } | |
6164 | ||
6165 | /* XXX We don't allow MINUS any more -- see comment in | |
c6c3dba9 | 6166 | arm_legitimate_address_outer_p (). */ |
ccf4d512 RE |
6167 | else if (GET_CODE (x) == MINUS) |
6168 | { | |
6169 | rtx xop0 = XEXP (x, 0); | |
6170 | rtx xop1 = XEXP (x, 1); | |
6171 | ||
6172 | if (CONSTANT_P (xop0)) | |
6173 | xop0 = force_reg (SImode, xop0); | |
6174 | ||
6175 | if (CONSTANT_P (xop1) && ! symbol_mentioned_p (xop1)) | |
6176 | xop1 = force_reg (SImode, xop1); | |
6177 | ||
6178 | if (xop0 != XEXP (x, 0) || xop1 != XEXP (x, 1)) | |
6179 | x = gen_rtx_MINUS (SImode, xop0, xop1); | |
6180 | } | |
6181 | ||
86805759 NP |
6182 | /* Make sure to take full advantage of the pre-indexed addressing mode |
6183 | with absolute addresses which often allows for the base register to | |
6184 | be factorized for multiple adjacent memory references, and it might | |
6185 | even allows for the mini pool to be avoided entirely. */ | |
6186 | else if (GET_CODE (x) == CONST_INT && optimize > 0) | |
6187 | { | |
6188 | unsigned int bits; | |
6189 | HOST_WIDE_INT mask, base, index; | |
6190 | rtx base_reg; | |
6191 | ||
a50aa827 KH |
6192 | /* ldr and ldrb can use a 12-bit index, ldrsb and the rest can only |
6193 | use a 8-bit index. So let's use a 12-bit index for SImode only and | |
86805759 NP |
6194 | hope that arm_gen_constant will enable ldrb to use more bits. */ |
6195 | bits = (mode == SImode) ? 12 : 8; | |
6196 | mask = (1 << bits) - 1; | |
6197 | base = INTVAL (x) & ~mask; | |
6198 | index = INTVAL (x) & mask; | |
b107d743 | 6199 | if (bit_count (base & 0xffffffff) > (32 - bits)/2) |
86805759 NP |
6200 | { |
6201 | /* It'll most probably be more efficient to generate the base | |
6202 | with more bits set and use a negative index instead. */ | |
6203 | base |= mask; | |
6204 | index -= mask; | |
6205 | } | |
6206 | base_reg = force_reg (SImode, GEN_INT (base)); | |
d66437c5 | 6207 | x = plus_constant (base_reg, index); |
86805759 NP |
6208 | } |
6209 | ||
ccf4d512 RE |
6210 | if (flag_pic) |
6211 | { | |
6212 | /* We need to find and carefully transform any SYMBOL and LABEL | |
6213 | references; so go back to the original address expression. */ | |
6214 | rtx new_x = legitimize_pic_address (orig_x, mode, NULL_RTX); | |
6215 | ||
6216 | if (new_x != orig_x) | |
6217 | x = new_x; | |
6218 | } | |
6219 | ||
6220 | return x; | |
6221 | } | |
6222 | ||
6f5b4f3e RE |
6223 | |
6224 | /* Try machine-dependent ways of modifying an illegitimate Thumb address | |
6225 | to be legitimate. If we find one, return the new, valid address. */ | |
6226 | rtx | |
6227 | thumb_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode) | |
6228 | { | |
d3585b76 DJ |
6229 | if (arm_tls_symbol_p (x)) |
6230 | return legitimize_tls_address (x, NULL_RTX); | |
6231 | ||
6f5b4f3e RE |
6232 | if (GET_CODE (x) == PLUS |
6233 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
6234 | && (INTVAL (XEXP (x, 1)) >= 32 * GET_MODE_SIZE (mode) | |
6235 | || INTVAL (XEXP (x, 1)) < 0)) | |
6236 | { | |
6237 | rtx xop0 = XEXP (x, 0); | |
6238 | rtx xop1 = XEXP (x, 1); | |
6239 | HOST_WIDE_INT offset = INTVAL (xop1); | |
6240 | ||
6241 | /* Try and fold the offset into a biasing of the base register and | |
6242 | then offsetting that. Don't do this when optimizing for space | |
6243 | since it can cause too many CSEs. */ | |
6244 | if (optimize_size && offset >= 0 | |
6245 | && offset < 256 + 31 * GET_MODE_SIZE (mode)) | |
6246 | { | |
6247 | HOST_WIDE_INT delta; | |
6248 | ||
6249 | if (offset >= 256) | |
6250 | delta = offset - (256 - GET_MODE_SIZE (mode)); | |
6251 | else if (offset < 32 * GET_MODE_SIZE (mode) + 8) | |
6252 | delta = 31 * GET_MODE_SIZE (mode); | |
6253 | else | |
6254 | delta = offset & (~31 * GET_MODE_SIZE (mode)); | |
6255 | ||
6256 | xop0 = force_operand (plus_constant (xop0, offset - delta), | |
6257 | NULL_RTX); | |
6258 | x = plus_constant (xop0, delta); | |
6259 | } | |
6260 | else if (offset < 0 && offset > -256) | |
6261 | /* Small negative offsets are best done with a subtract before the | |
6262 | dereference, forcing these into a register normally takes two | |
6263 | instructions. */ | |
6264 | x = force_operand (x, NULL_RTX); | |
6265 | else | |
6266 | { | |
6267 | /* For the remaining cases, force the constant into a register. */ | |
6268 | xop1 = force_reg (SImode, xop1); | |
6269 | x = gen_rtx_PLUS (SImode, xop0, xop1); | |
6270 | } | |
6271 | } | |
6272 | else if (GET_CODE (x) == PLUS | |
6273 | && s_register_operand (XEXP (x, 1), SImode) | |
6274 | && !s_register_operand (XEXP (x, 0), SImode)) | |
6275 | { | |
6276 | rtx xop0 = force_operand (XEXP (x, 0), NULL_RTX); | |
6277 | ||
6278 | x = gen_rtx_PLUS (SImode, xop0, XEXP (x, 1)); | |
6279 | } | |
6280 | ||
6281 | if (flag_pic) | |
6282 | { | |
6283 | /* We need to find and carefully transform any SYMBOL and LABEL | |
6284 | references; so go back to the original address expression. */ | |
6285 | rtx new_x = legitimize_pic_address (orig_x, mode, NULL_RTX); | |
6286 | ||
6287 | if (new_x != orig_x) | |
6288 | x = new_x; | |
6289 | } | |
6290 | ||
6291 | return x; | |
6292 | } | |
6293 | ||
a132dad6 | 6294 | rtx |
e0b92319 NC |
6295 | thumb_legitimize_reload_address (rtx *x_p, |
6296 | enum machine_mode mode, | |
6297 | int opnum, int type, | |
6298 | int ind_levels ATTRIBUTE_UNUSED) | |
a132dad6 RE |
6299 | { |
6300 | rtx x = *x_p; | |
e0b92319 | 6301 | |
a132dad6 RE |
6302 | if (GET_CODE (x) == PLUS |
6303 | && GET_MODE_SIZE (mode) < 4 | |
6304 | && REG_P (XEXP (x, 0)) | |
6305 | && XEXP (x, 0) == stack_pointer_rtx | |
6306 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
6307 | && !thumb_legitimate_offset_p (mode, INTVAL (XEXP (x, 1)))) | |
6308 | { | |
6309 | rtx orig_x = x; | |
6310 | ||
6311 | x = copy_rtx (x); | |
6312 | push_reload (orig_x, NULL_RTX, x_p, NULL, MODE_BASE_REG_CLASS (mode), | |
bbbbb16a | 6313 | Pmode, VOIDmode, 0, 0, opnum, (enum reload_type) type); |
a132dad6 RE |
6314 | return x; |
6315 | } | |
6316 | ||
6317 | /* If both registers are hi-regs, then it's better to reload the | |
6318 | entire expression rather than each register individually. That | |
6319 | only requires one reload register rather than two. */ | |
6320 | if (GET_CODE (x) == PLUS | |
6321 | && REG_P (XEXP (x, 0)) | |
6322 | && REG_P (XEXP (x, 1)) | |
6323 | && !REG_MODE_OK_FOR_REG_BASE_P (XEXP (x, 0), mode) | |
6324 | && !REG_MODE_OK_FOR_REG_BASE_P (XEXP (x, 1), mode)) | |
6325 | { | |
6326 | rtx orig_x = x; | |
6327 | ||
6328 | x = copy_rtx (x); | |
6329 | push_reload (orig_x, NULL_RTX, x_p, NULL, MODE_BASE_REG_CLASS (mode), | |
bbbbb16a | 6330 | Pmode, VOIDmode, 0, 0, opnum, (enum reload_type) type); |
a132dad6 RE |
6331 | return x; |
6332 | } | |
6333 | ||
6334 | return NULL; | |
6335 | } | |
d3585b76 DJ |
6336 | |
6337 | /* Test for various thread-local symbols. */ | |
6338 | ||
6339 | /* Return TRUE if X is a thread-local symbol. */ | |
6340 | ||
6341 | static bool | |
6342 | arm_tls_symbol_p (rtx x) | |
6343 | { | |
6344 | if (! TARGET_HAVE_TLS) | |
6345 | return false; | |
6346 | ||
6347 | if (GET_CODE (x) != SYMBOL_REF) | |
6348 | return false; | |
6349 | ||
6350 | return SYMBOL_REF_TLS_MODEL (x) != 0; | |
6351 | } | |
6352 | ||
6353 | /* Helper for arm_tls_referenced_p. */ | |
6354 | ||
6355 | static int | |
6356 | arm_tls_operand_p_1 (rtx *x, void *data ATTRIBUTE_UNUSED) | |
6357 | { | |
6358 | if (GET_CODE (*x) == SYMBOL_REF) | |
6359 | return SYMBOL_REF_TLS_MODEL (*x) != 0; | |
6360 | ||
6361 | /* Don't recurse into UNSPEC_TLS looking for TLS symbols; these are | |
6362 | TLS offsets, not real symbol references. */ | |
6363 | if (GET_CODE (*x) == UNSPEC | |
6364 | && XINT (*x, 1) == UNSPEC_TLS) | |
6365 | return -1; | |
6366 | ||
6367 | return 0; | |
6368 | } | |
6369 | ||
6370 | /* Return TRUE if X contains any TLS symbol references. */ | |
6371 | ||
6372 | bool | |
6373 | arm_tls_referenced_p (rtx x) | |
6374 | { | |
6375 | if (! TARGET_HAVE_TLS) | |
6376 | return false; | |
6377 | ||
6378 | return for_each_rtx (&x, arm_tls_operand_p_1, NULL); | |
6379 | } | |
8426b956 RS |
6380 | |
6381 | /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */ | |
6382 | ||
6383 | bool | |
6384 | arm_cannot_force_const_mem (rtx x) | |
6385 | { | |
6386 | rtx base, offset; | |
6387 | ||
6388 | if (ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P) | |
6389 | { | |
6390 | split_const (x, &base, &offset); | |
6391 | if (GET_CODE (base) == SYMBOL_REF | |
6392 | && !offset_within_block_p (base, INTVAL (offset))) | |
6393 | return true; | |
6394 | } | |
6395 | return arm_tls_referenced_p (x); | |
6396 | } | |
6b990f6b | 6397 | \f |
e2c671ba RE |
6398 | #define REG_OR_SUBREG_REG(X) \ |
6399 | (GET_CODE (X) == REG \ | |
6400 | || (GET_CODE (X) == SUBREG && GET_CODE (SUBREG_REG (X)) == REG)) | |
6401 | ||
6402 | #define REG_OR_SUBREG_RTX(X) \ | |
6403 | (GET_CODE (X) == REG ? (X) : SUBREG_REG (X)) | |
6404 | ||
3c50106f | 6405 | static inline int |
5b3e6663 | 6406 | thumb1_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer) |
e2c671ba RE |
6407 | { |
6408 | enum machine_mode mode = GET_MODE (x); | |
e4c6a07a | 6409 | int total; |
e2c671ba | 6410 | |
9b66ebb1 | 6411 | switch (code) |
d5b7b3ae | 6412 | { |
9b66ebb1 PB |
6413 | case ASHIFT: |
6414 | case ASHIFTRT: | |
6415 | case LSHIFTRT: | |
f676971a | 6416 | case ROTATERT: |
9b66ebb1 PB |
6417 | case PLUS: |
6418 | case MINUS: | |
6419 | case COMPARE: | |
6420 | case NEG: | |
f676971a | 6421 | case NOT: |
9b66ebb1 | 6422 | return COSTS_N_INSNS (1); |
f676971a EC |
6423 | |
6424 | case MULT: | |
6425 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
6426 | { | |
6427 | int cycles = 0; | |
9b66ebb1 | 6428 | unsigned HOST_WIDE_INT i = INTVAL (XEXP (x, 1)); |
f676971a EC |
6429 | |
6430 | while (i) | |
6431 | { | |
6432 | i >>= 2; | |
6433 | cycles++; | |
6434 | } | |
6435 | return COSTS_N_INSNS (2) + cycles; | |
9b66ebb1 PB |
6436 | } |
6437 | return COSTS_N_INSNS (1) + 16; | |
f676971a EC |
6438 | |
6439 | case SET: | |
6440 | return (COSTS_N_INSNS (1) | |
6441 | + 4 * ((GET_CODE (SET_SRC (x)) == MEM) | |
9b66ebb1 | 6442 | + GET_CODE (SET_DEST (x)) == MEM)); |
f676971a EC |
6443 | |
6444 | case CONST_INT: | |
6445 | if (outer == SET) | |
6446 | { | |
6447 | if ((unsigned HOST_WIDE_INT) INTVAL (x) < 256) | |
6448 | return 0; | |
6449 | if (thumb_shiftable_const (INTVAL (x))) | |
6450 | return COSTS_N_INSNS (2); | |
6451 | return COSTS_N_INSNS (3); | |
6452 | } | |
9b66ebb1 | 6453 | else if ((outer == PLUS || outer == COMPARE) |
f676971a | 6454 | && INTVAL (x) < 256 && INTVAL (x) > -256) |
9b66ebb1 | 6455 | return 0; |
582021ba | 6456 | else if ((outer == IOR || outer == XOR || outer == AND) |
9b66ebb1 PB |
6457 | && INTVAL (x) < 256 && INTVAL (x) >= -256) |
6458 | return COSTS_N_INSNS (1); | |
c99102b8 BS |
6459 | else if (outer == AND) |
6460 | { | |
6461 | int i; | |
6462 | /* This duplicates the tests in the andsi3 expander. */ | |
6463 | for (i = 9; i <= 31; i++) | |
6464 | if ((((HOST_WIDE_INT) 1) << i) - 1 == INTVAL (x) | |
6465 | || (((HOST_WIDE_INT) 1) << i) - 1 == ~INTVAL (x)) | |
6466 | return COSTS_N_INSNS (2); | |
6467 | } | |
f676971a EC |
6468 | else if (outer == ASHIFT || outer == ASHIFTRT |
6469 | || outer == LSHIFTRT) | |
6470 | return 0; | |
9b66ebb1 | 6471 | return COSTS_N_INSNS (2); |
f676971a EC |
6472 | |
6473 | case CONST: | |
6474 | case CONST_DOUBLE: | |
6475 | case LABEL_REF: | |
6476 | case SYMBOL_REF: | |
9b66ebb1 | 6477 | return COSTS_N_INSNS (3); |
f676971a | 6478 | |
9b66ebb1 PB |
6479 | case UDIV: |
6480 | case UMOD: | |
6481 | case DIV: | |
6482 | case MOD: | |
6483 | return 100; | |
d5b7b3ae | 6484 | |
9b66ebb1 PB |
6485 | case TRUNCATE: |
6486 | return 99; | |
d5b7b3ae | 6487 | |
9b66ebb1 PB |
6488 | case AND: |
6489 | case XOR: | |
f676971a | 6490 | case IOR: |
ff482c8d | 6491 | /* XXX guess. */ |
9b66ebb1 | 6492 | return 8; |
d5b7b3ae | 6493 | |
9b66ebb1 PB |
6494 | case MEM: |
6495 | /* XXX another guess. */ | |
6496 | /* Memory costs quite a lot for the first word, but subsequent words | |
6497 | load at the equivalent of a single insn each. */ | |
6498 | return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD) | |
6499 | + ((GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x)) | |
6500 | ? 4 : 0)); | |
6501 | ||
6502 | case IF_THEN_ELSE: | |
ff482c8d | 6503 | /* XXX a guess. */ |
9b66ebb1 PB |
6504 | if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC) |
6505 | return 14; | |
6506 | return 2; | |
6507 | ||
e4c6a07a | 6508 | case SIGN_EXTEND: |
9b66ebb1 | 6509 | case ZERO_EXTEND: |
e4c6a07a BS |
6510 | total = mode == DImode ? COSTS_N_INSNS (1) : 0; |
6511 | total += thumb1_rtx_costs (XEXP (x, 0), GET_CODE (XEXP (x, 0)), code); | |
f676971a | 6512 | |
e4c6a07a BS |
6513 | if (mode == SImode) |
6514 | return total; | |
f676971a | 6515 | |
e4c6a07a BS |
6516 | if (arm_arch6) |
6517 | return total + COSTS_N_INSNS (1); | |
f676971a | 6518 | |
e4c6a07a BS |
6519 | /* Assume a two-shift sequence. Increase the cost slightly so |
6520 | we prefer actual shifts over an extend operation. */ | |
6521 | return total + 1 + COSTS_N_INSNS (2); | |
f676971a | 6522 | |
9b66ebb1 PB |
6523 | default: |
6524 | return 99; | |
d5b7b3ae | 6525 | } |
9b66ebb1 PB |
6526 | } |
6527 | ||
d5a0a47b RE |
6528 | static inline bool |
6529 | arm_rtx_costs_1 (rtx x, enum rtx_code outer, int* total, bool speed) | |
9b66ebb1 PB |
6530 | { |
6531 | enum machine_mode mode = GET_MODE (x); | |
6532 | enum rtx_code subcode; | |
d5a0a47b RE |
6533 | rtx operand; |
6534 | enum rtx_code code = GET_CODE (x); | |
d5a0a47b | 6535 | *total = 0; |
9b66ebb1 | 6536 | |
e2c671ba RE |
6537 | switch (code) |
6538 | { | |
6539 | case MEM: | |
6540 | /* Memory costs quite a lot for the first word, but subsequent words | |
6541 | load at the equivalent of a single insn each. */ | |
d5a0a47b RE |
6542 | *total = COSTS_N_INSNS (2 + ARM_NUM_REGS (mode)); |
6543 | return true; | |
e2c671ba RE |
6544 | |
6545 | case DIV: | |
6546 | case MOD: | |
b9c53150 RS |
6547 | case UDIV: |
6548 | case UMOD: | |
d5a0a47b RE |
6549 | if (TARGET_HARD_FLOAT && mode == SFmode) |
6550 | *total = COSTS_N_INSNS (2); | |
e0dc3601 | 6551 | else if (TARGET_HARD_FLOAT && mode == DFmode && !TARGET_VFP_SINGLE) |
d5a0a47b RE |
6552 | *total = COSTS_N_INSNS (4); |
6553 | else | |
6554 | *total = COSTS_N_INSNS (20); | |
6555 | return false; | |
e2c671ba RE |
6556 | |
6557 | case ROTATE: | |
d5a0a47b RE |
6558 | if (GET_CODE (XEXP (x, 1)) == REG) |
6559 | *total = COSTS_N_INSNS (1); /* Need to subtract from 32 */ | |
6560 | else if (GET_CODE (XEXP (x, 1)) != CONST_INT) | |
6561 | *total = rtx_cost (XEXP (x, 1), code, speed); | |
6562 | ||
e2c671ba RE |
6563 | /* Fall through */ |
6564 | case ROTATERT: | |
6565 | if (mode != SImode) | |
d5a0a47b RE |
6566 | { |
6567 | *total += COSTS_N_INSNS (4); | |
6568 | return true; | |
6569 | } | |
6570 | ||
e2c671ba RE |
6571 | /* Fall through */ |
6572 | case ASHIFT: case LSHIFTRT: case ASHIFTRT: | |
d5a0a47b | 6573 | *total += rtx_cost (XEXP (x, 0), code, speed); |
e2c671ba | 6574 | if (mode == DImode) |
d5a0a47b RE |
6575 | { |
6576 | *total += COSTS_N_INSNS (3); | |
6577 | return true; | |
6578 | } | |
7612f14d | 6579 | |
d5a0a47b | 6580 | *total += COSTS_N_INSNS (1); |
7612f14d PB |
6581 | /* Increase the cost of complex shifts because they aren't any faster, |
6582 | and reduce dual issue opportunities. */ | |
6583 | if (arm_tune_cortex_a9 | |
6584 | && outer != SET && GET_CODE (XEXP (x, 1)) != CONST_INT) | |
d5a0a47b RE |
6585 | ++*total; |
6586 | ||
6587 | return true; | |
e2c671ba RE |
6588 | |
6589 | case MINUS: | |
6590 | if (mode == DImode) | |
d5a0a47b RE |
6591 | { |
6592 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
6593 | if (GET_CODE (XEXP (x, 0)) == CONST_INT | |
6594 | && const_ok_for_arm (INTVAL (XEXP (x, 0)))) | |
6595 | { | |
6596 | *total += rtx_cost (XEXP (x, 1), code, speed); | |
6597 | return true; | |
6598 | } | |
6599 | ||
6600 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
6601 | && const_ok_for_arm (INTVAL (XEXP (x, 1)))) | |
6602 | { | |
6603 | *total += rtx_cost (XEXP (x, 0), code, speed); | |
6604 | return true; | |
6605 | } | |
6606 | ||
6607 | return false; | |
6608 | } | |
e2c671ba RE |
6609 | |
6610 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
d5a0a47b | 6611 | { |
e0dc3601 PB |
6612 | if (TARGET_HARD_FLOAT |
6613 | && (mode == SFmode | |
6614 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
6615 | { |
6616 | *total = COSTS_N_INSNS (1); | |
6617 | if (GET_CODE (XEXP (x, 0)) == CONST_DOUBLE | |
6618 | && arm_const_double_rtx (XEXP (x, 0))) | |
6619 | { | |
6620 | *total += rtx_cost (XEXP (x, 1), code, speed); | |
6621 | return true; | |
6622 | } | |
6623 | ||
6624 | if (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE | |
6625 | && arm_const_double_rtx (XEXP (x, 1))) | |
6626 | { | |
6627 | *total += rtx_cost (XEXP (x, 0), code, speed); | |
6628 | return true; | |
6629 | } | |
6630 | ||
6631 | return false; | |
6632 | } | |
6633 | *total = COSTS_N_INSNS (20); | |
6634 | return false; | |
6635 | } | |
6636 | ||
6637 | *total = COSTS_N_INSNS (1); | |
6638 | if (GET_CODE (XEXP (x, 0)) == CONST_INT | |
6639 | && const_ok_for_arm (INTVAL (XEXP (x, 0)))) | |
6640 | { | |
6641 | *total += rtx_cost (XEXP (x, 1), code, speed); | |
6642 | return true; | |
6643 | } | |
6644 | ||
6645 | subcode = GET_CODE (XEXP (x, 1)); | |
6646 | if (subcode == ASHIFT || subcode == ASHIFTRT | |
6647 | || subcode == LSHIFTRT | |
6648 | || subcode == ROTATE || subcode == ROTATERT) | |
6649 | { | |
6650 | *total += rtx_cost (XEXP (x, 0), code, speed); | |
6651 | *total += rtx_cost (XEXP (XEXP (x, 1), 0), subcode, speed); | |
6652 | return true; | |
6653 | } | |
6654 | ||
b32f6fff KH |
6655 | /* A shift as a part of RSB costs no more than RSB itself. */ |
6656 | if (GET_CODE (XEXP (x, 0)) == MULT | |
4c7c486a | 6657 | && power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode)) |
b32f6fff KH |
6658 | { |
6659 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), code, speed); | |
6660 | *total += rtx_cost (XEXP (x, 1), code, speed); | |
6661 | return true; | |
6662 | } | |
6663 | ||
d5a0a47b | 6664 | if (subcode == MULT |
4c7c486a | 6665 | && power_of_two_operand (XEXP (XEXP (x, 1), 1), SImode)) |
d5a0a47b RE |
6666 | { |
6667 | *total += rtx_cost (XEXP (x, 0), code, speed); | |
6668 | *total += rtx_cost (XEXP (XEXP (x, 1), 0), subcode, speed); | |
6669 | return true; | |
6670 | } | |
6671 | ||
6672 | if (GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == RTX_COMPARE | |
6673 | || GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == RTX_COMM_COMPARE) | |
6674 | { | |
6675 | *total = COSTS_N_INSNS (1) + rtx_cost (XEXP (x, 0), code, speed); | |
6676 | if (GET_CODE (XEXP (XEXP (x, 1), 0)) == REG | |
6677 | && REGNO (XEXP (XEXP (x, 1), 0)) != CC_REGNUM) | |
6678 | *total += COSTS_N_INSNS (1); | |
6679 | ||
6680 | return true; | |
6681 | } | |
6682 | ||
e2c671ba RE |
6683 | /* Fall through */ |
6684 | ||
f676971a | 6685 | case PLUS: |
d5a0a47b | 6686 | if (code == PLUS && arm_arch6 && mode == SImode |
ff069900 PB |
6687 | && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND |
6688 | || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)) | |
d5a0a47b RE |
6689 | { |
6690 | *total = COSTS_N_INSNS (1); | |
6691 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), GET_CODE (XEXP (x, 0)), | |
6692 | speed); | |
6693 | *total += rtx_cost (XEXP (x, 1), code, speed); | |
6694 | return true; | |
6695 | } | |
ff069900 | 6696 | |
d5a0a47b RE |
6697 | /* MLA: All arguments must be registers. We filter out |
6698 | multiplication by a power of two, so that we fall down into | |
6699 | the code below. */ | |
6700 | if (GET_CODE (XEXP (x, 0)) == MULT | |
4c7c486a | 6701 | && !power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode)) |
26da58dd | 6702 | { |
d5a0a47b RE |
6703 | /* The cost comes from the cost of the multiply. */ |
6704 | return false; | |
26da58dd PB |
6705 | } |
6706 | ||
e2c671ba | 6707 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) |
d5a0a47b | 6708 | { |
e0dc3601 PB |
6709 | if (TARGET_HARD_FLOAT |
6710 | && (mode == SFmode | |
6711 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
6712 | { |
6713 | *total = COSTS_N_INSNS (1); | |
6714 | if (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE | |
6715 | && arm_const_double_rtx (XEXP (x, 1))) | |
6716 | { | |
6717 | *total += rtx_cost (XEXP (x, 0), code, speed); | |
6718 | return true; | |
6719 | } | |
6720 | ||
6721 | return false; | |
6722 | } | |
6723 | ||
6724 | *total = COSTS_N_INSNS (20); | |
6725 | return false; | |
6726 | } | |
6727 | ||
6728 | if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_COMPARE | |
6729 | || GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_COMM_COMPARE) | |
6730 | { | |
6731 | *total = COSTS_N_INSNS (1) + rtx_cost (XEXP (x, 1), code, speed); | |
6732 | if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG | |
6733 | && REGNO (XEXP (XEXP (x, 0), 0)) != CC_REGNUM) | |
6734 | *total += COSTS_N_INSNS (1); | |
6735 | return true; | |
6736 | } | |
e2c671ba RE |
6737 | |
6738 | /* Fall through */ | |
d5a0a47b | 6739 | |
f676971a | 6740 | case AND: case XOR: case IOR: |
e2c671ba RE |
6741 | |
6742 | /* Normally the frame registers will be spilt into reg+const during | |
6743 | reload, so it is a bad idea to combine them with other instructions, | |
6744 | since then they might not be moved outside of loops. As a compromise | |
6745 | we allow integration with ops that have a constant as their second | |
6746 | operand. */ | |
13cc4787 BS |
6747 | if (REG_OR_SUBREG_REG (XEXP (x, 0)) |
6748 | && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0))) | |
6749 | && GET_CODE (XEXP (x, 1)) != CONST_INT) | |
6750 | *total = COSTS_N_INSNS (1); | |
e2c671ba RE |
6751 | |
6752 | if (mode == DImode) | |
d5a0a47b RE |
6753 | { |
6754 | *total += COSTS_N_INSNS (2); | |
6755 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
6756 | && const_ok_for_op (INTVAL (XEXP (x, 1)), code)) | |
6757 | { | |
6758 | *total += rtx_cost (XEXP (x, 0), code, speed); | |
6759 | return true; | |
6760 | } | |
e2c671ba | 6761 | |
d5a0a47b RE |
6762 | return false; |
6763 | } | |
6764 | ||
6765 | *total += COSTS_N_INSNS (1); | |
6766 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
6767 | && const_ok_for_op (INTVAL (XEXP (x, 1)), code)) | |
6768 | { | |
6769 | *total += rtx_cost (XEXP (x, 0), code, speed); | |
6770 | return true; | |
6771 | } | |
6772 | subcode = GET_CODE (XEXP (x, 0)); | |
6773 | if (subcode == ASHIFT || subcode == ASHIFTRT | |
6774 | || subcode == LSHIFTRT | |
6775 | || subcode == ROTATE || subcode == ROTATERT) | |
6776 | { | |
6777 | *total += rtx_cost (XEXP (x, 1), code, speed); | |
6778 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), subcode, speed); | |
6779 | return true; | |
6780 | } | |
6781 | ||
6782 | if (subcode == MULT | |
4c7c486a | 6783 | && power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode)) |
d5a0a47b RE |
6784 | { |
6785 | *total += rtx_cost (XEXP (x, 1), code, speed); | |
6786 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), subcode, speed); | |
6787 | return true; | |
6788 | } | |
6789 | ||
6790 | if (subcode == UMIN || subcode == UMAX | |
6791 | || subcode == SMIN || subcode == SMAX) | |
6792 | { | |
6793 | *total = COSTS_N_INSNS (3); | |
6794 | return true; | |
6795 | } | |
6796 | ||
6797 | return false; | |
e2c671ba RE |
6798 | |
6799 | case MULT: | |
9b66ebb1 | 6800 | /* This should have been handled by the CPU specific routines. */ |
e6d29d15 | 6801 | gcc_unreachable (); |
e2c671ba | 6802 | |
56636818 | 6803 | case TRUNCATE: |
9b66ebb1 | 6804 | if (arm_arch3m && mode == SImode |
56636818 JL |
6805 | && GET_CODE (XEXP (x, 0)) == LSHIFTRT |
6806 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT | |
6807 | && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) | |
6808 | == GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1))) | |
6809 | && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND | |
6810 | || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND)) | |
d5a0a47b RE |
6811 | { |
6812 | *total = rtx_cost (XEXP (XEXP (x, 0), 0), LSHIFTRT, speed); | |
6813 | return true; | |
6814 | } | |
6815 | *total = COSTS_N_INSNS (2); /* Plus the cost of the MULT */ | |
6816 | return false; | |
56636818 | 6817 | |
e2c671ba RE |
6818 | case NEG: |
6819 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
d5a0a47b | 6820 | { |
e0dc3601 PB |
6821 | if (TARGET_HARD_FLOAT |
6822 | && (mode == SFmode | |
6823 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
6824 | { |
6825 | *total = COSTS_N_INSNS (1); | |
6826 | return false; | |
6827 | } | |
6828 | *total = COSTS_N_INSNS (2); | |
6829 | return false; | |
6830 | } | |
6831 | ||
e2c671ba RE |
6832 | /* Fall through */ |
6833 | case NOT: | |
d5a0a47b RE |
6834 | *total = COSTS_N_INSNS (ARM_NUM_REGS(mode)); |
6835 | if (mode == SImode && code == NOT) | |
6836 | { | |
6837 | subcode = GET_CODE (XEXP (x, 0)); | |
6838 | if (subcode == ASHIFT || subcode == ASHIFTRT | |
6839 | || subcode == LSHIFTRT | |
6840 | || subcode == ROTATE || subcode == ROTATERT | |
6841 | || (subcode == MULT | |
4c7c486a | 6842 | && power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode))) |
d5a0a47b RE |
6843 | { |
6844 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), subcode, speed); | |
6845 | /* Register shifts cost an extra cycle. */ | |
6846 | if (GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT) | |
6847 | *total += COSTS_N_INSNS (1) + rtx_cost (XEXP (XEXP (x, 0), 1), | |
6848 | subcode, speed); | |
6849 | return true; | |
6850 | } | |
6851 | } | |
e2c671ba | 6852 | |
d5a0a47b | 6853 | return false; |
e2c671ba RE |
6854 | |
6855 | case IF_THEN_ELSE: | |
6856 | if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC) | |
d5a0a47b RE |
6857 | { |
6858 | *total = COSTS_N_INSNS (4); | |
6859 | return true; | |
6860 | } | |
6861 | ||
6862 | operand = XEXP (x, 0); | |
6863 | ||
6864 | if (!((GET_RTX_CLASS (GET_CODE (operand)) == RTX_COMPARE | |
6865 | || GET_RTX_CLASS (GET_CODE (operand)) == RTX_COMM_COMPARE) | |
6866 | && GET_CODE (XEXP (operand, 0)) == REG | |
6867 | && REGNO (XEXP (operand, 0)) == CC_REGNUM)) | |
6868 | *total += COSTS_N_INSNS (1); | |
6869 | *total += (rtx_cost (XEXP (x, 1), code, speed) | |
6870 | + rtx_cost (XEXP (x, 2), code, speed)); | |
6871 | return true; | |
6872 | ||
6873 | case NE: | |
6874 | if (mode == SImode && XEXP (x, 1) == const0_rtx) | |
6875 | { | |
6876 | *total = COSTS_N_INSNS (2) + rtx_cost (XEXP (x, 0), code, speed); | |
6877 | return true; | |
6878 | } | |
6879 | goto scc_insn; | |
6880 | ||
6881 | case GE: | |
6882 | if ((GET_CODE (XEXP (x, 0)) != REG || REGNO (XEXP (x, 0)) != CC_REGNUM) | |
6883 | && mode == SImode && XEXP (x, 1) == const0_rtx) | |
6884 | { | |
6885 | *total = COSTS_N_INSNS (2) + rtx_cost (XEXP (x, 0), code, speed); | |
6886 | return true; | |
6887 | } | |
6888 | goto scc_insn; | |
6889 | ||
6890 | case LT: | |
6891 | if ((GET_CODE (XEXP (x, 0)) != REG || REGNO (XEXP (x, 0)) != CC_REGNUM) | |
6892 | && mode == SImode && XEXP (x, 1) == const0_rtx) | |
6893 | { | |
6894 | *total = COSTS_N_INSNS (1) + rtx_cost (XEXP (x, 0), code, speed); | |
6895 | return true; | |
6896 | } | |
6897 | goto scc_insn; | |
6898 | ||
6899 | case EQ: | |
6900 | case GT: | |
6901 | case LE: | |
6902 | case GEU: | |
6903 | case LTU: | |
6904 | case GTU: | |
6905 | case LEU: | |
6906 | case UNORDERED: | |
6907 | case ORDERED: | |
6908 | case UNEQ: | |
6909 | case UNGE: | |
6910 | case UNLT: | |
6911 | case UNGT: | |
6912 | case UNLE: | |
6913 | scc_insn: | |
6914 | /* SCC insns. In the case where the comparison has already been | |
6915 | performed, then they cost 2 instructions. Otherwise they need | |
6916 | an additional comparison before them. */ | |
6917 | *total = COSTS_N_INSNS (2); | |
6918 | if (GET_CODE (XEXP (x, 0)) == REG && REGNO (XEXP (x, 0)) == CC_REGNUM) | |
6919 | { | |
6920 | return true; | |
6921 | } | |
e2c671ba | 6922 | |
d5a0a47b | 6923 | /* Fall through */ |
e2c671ba | 6924 | case COMPARE: |
d5a0a47b RE |
6925 | if (GET_CODE (XEXP (x, 0)) == REG && REGNO (XEXP (x, 0)) == CC_REGNUM) |
6926 | { | |
6927 | *total = 0; | |
6928 | return true; | |
6929 | } | |
6930 | ||
6931 | *total += COSTS_N_INSNS (1); | |
6932 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
6933 | && const_ok_for_op (INTVAL (XEXP (x, 1)), code)) | |
6934 | { | |
6935 | *total += rtx_cost (XEXP (x, 0), code, speed); | |
6936 | return true; | |
6937 | } | |
6938 | ||
6939 | subcode = GET_CODE (XEXP (x, 0)); | |
6940 | if (subcode == ASHIFT || subcode == ASHIFTRT | |
6941 | || subcode == LSHIFTRT | |
6942 | || subcode == ROTATE || subcode == ROTATERT) | |
6943 | { | |
6944 | *total += rtx_cost (XEXP (x, 1), code, speed); | |
6945 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), subcode, speed); | |
6946 | return true; | |
6947 | } | |
6948 | ||
6949 | if (subcode == MULT | |
4c7c486a | 6950 | && power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode)) |
d5a0a47b RE |
6951 | { |
6952 | *total += rtx_cost (XEXP (x, 1), code, speed); | |
6953 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), subcode, speed); | |
6954 | return true; | |
6955 | } | |
6956 | ||
6957 | return false; | |
6958 | ||
6959 | case UMIN: | |
6960 | case UMAX: | |
6961 | case SMIN: | |
6962 | case SMAX: | |
6963 | *total = COSTS_N_INSNS (2) + rtx_cost (XEXP (x, 0), code, speed); | |
6964 | if (GET_CODE (XEXP (x, 1)) != CONST_INT | |
6965 | || !const_ok_for_arm (INTVAL (XEXP (x, 1)))) | |
6966 | *total += rtx_cost (XEXP (x, 1), code, speed); | |
6967 | return true; | |
e2c671ba RE |
6968 | |
6969 | case ABS: | |
bbbbb16a | 6970 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) |
d5a0a47b | 6971 | { |
e0dc3601 PB |
6972 | if (TARGET_HARD_FLOAT |
6973 | && (mode == SFmode | |
6974 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
6975 | { |
6976 | *total = COSTS_N_INSNS (1); | |
6977 | return false; | |
6978 | } | |
6979 | *total = COSTS_N_INSNS (20); | |
6980 | return false; | |
6981 | } | |
6982 | *total = COSTS_N_INSNS (1); | |
6983 | if (mode == DImode) | |
6984 | *total += COSTS_N_INSNS (3); | |
6985 | return false; | |
e2c671ba RE |
6986 | |
6987 | case SIGN_EXTEND: | |
e2c671ba | 6988 | case ZERO_EXTEND: |
d5a0a47b RE |
6989 | *total = 0; |
6990 | if (GET_MODE_CLASS (mode) == MODE_INT) | |
e2c671ba | 6991 | { |
e4c6a07a BS |
6992 | rtx op = XEXP (x, 0); |
6993 | enum machine_mode opmode = GET_MODE (op); | |
6994 | ||
d5a0a47b RE |
6995 | if (mode == DImode) |
6996 | *total += COSTS_N_INSNS (1); | |
e2c671ba | 6997 | |
e4c6a07a | 6998 | if (opmode != SImode) |
d5a0a47b | 6999 | { |
e4c6a07a | 7000 | if (MEM_P (op)) |
d5a0a47b | 7001 | { |
e4c6a07a BS |
7002 | /* If !arm_arch4, we use one of the extendhisi2_mem |
7003 | or movhi_bytes patterns for HImode. For a QImode | |
7004 | sign extension, we first zero-extend from memory | |
7005 | and then perform a shift sequence. */ | |
7006 | if (!arm_arch4 && (opmode != QImode || code == SIGN_EXTEND)) | |
7007 | *total += COSTS_N_INSNS (2); | |
d5a0a47b | 7008 | } |
e4c6a07a BS |
7009 | else if (arm_arch6) |
7010 | *total += COSTS_N_INSNS (1); | |
7011 | ||
7012 | /* We don't have the necessary insn, so we need to perform some | |
7013 | other operation. */ | |
7014 | else if (TARGET_ARM && code == ZERO_EXTEND && mode == QImode) | |
7015 | /* An and with constant 255. */ | |
7016 | *total += COSTS_N_INSNS (1); | |
7017 | else | |
7018 | /* A shift sequence. Increase costs slightly to avoid | |
7019 | combining two shifts into an extend operation. */ | |
7020 | *total += COSTS_N_INSNS (2) + 1; | |
d5a0a47b | 7021 | } |
e2c671ba | 7022 | |
d5a0a47b RE |
7023 | return false; |
7024 | } | |
ad076f4e | 7025 | |
d5a0a47b RE |
7026 | switch (GET_MODE (XEXP (x, 0))) |
7027 | { | |
5a9335ef NC |
7028 | case V8QImode: |
7029 | case V4HImode: | |
7030 | case V2SImode: | |
7031 | case V4QImode: | |
7032 | case V2HImode: | |
d5a0a47b RE |
7033 | *total = COSTS_N_INSNS (1); |
7034 | return false; | |
5a9335ef | 7035 | |
ad076f4e | 7036 | default: |
e6d29d15 | 7037 | gcc_unreachable (); |
e2c671ba | 7038 | } |
e6d29d15 | 7039 | gcc_unreachable (); |
e2c671ba | 7040 | |
d5a0a47b RE |
7041 | case ZERO_EXTRACT: |
7042 | case SIGN_EXTRACT: | |
7043 | *total = COSTS_N_INSNS (1) + rtx_cost (XEXP (x, 0), code, speed); | |
7044 | return true; | |
7045 | ||
f676971a | 7046 | case CONST_INT: |
d5a0a47b RE |
7047 | if (const_ok_for_arm (INTVAL (x)) |
7048 | || const_ok_for_arm (~INTVAL (x))) | |
7049 | *total = COSTS_N_INSNS (1); | |
f676971a | 7050 | else |
d5a0a47b RE |
7051 | *total = COSTS_N_INSNS (arm_gen_constant (SET, mode, NULL_RTX, |
7052 | INTVAL (x), NULL_RTX, | |
7053 | NULL_RTX, 0, 0)); | |
7054 | return true; | |
f676971a EC |
7055 | |
7056 | case CONST: | |
7057 | case LABEL_REF: | |
7058 | case SYMBOL_REF: | |
d5a0a47b RE |
7059 | *total = COSTS_N_INSNS (3); |
7060 | return true; | |
f676971a | 7061 | |
571191af | 7062 | case HIGH: |
d5a0a47b RE |
7063 | *total = COSTS_N_INSNS (1); |
7064 | return true; | |
7065 | ||
571191af | 7066 | case LO_SUM: |
d5a0a47b RE |
7067 | *total = COSTS_N_INSNS (1); |
7068 | *total += rtx_cost (XEXP (x, 0), code, speed); | |
7069 | return true; | |
571191af | 7070 | |
f676971a | 7071 | case CONST_DOUBLE: |
e0dc3601 PB |
7072 | if (TARGET_HARD_FLOAT && vfp3_const_double_rtx (x) |
7073 | && (mode == SFmode || !TARGET_VFP_SINGLE)) | |
d5a0a47b RE |
7074 | *total = COSTS_N_INSNS (1); |
7075 | else | |
7076 | *total = COSTS_N_INSNS (4); | |
7077 | return true; | |
f676971a | 7078 | |
e2c671ba | 7079 | default: |
d5a0a47b RE |
7080 | *total = COSTS_N_INSNS (4); |
7081 | return false; | |
e2c671ba RE |
7082 | } |
7083 | } | |
32de079a | 7084 | |
7548c1be WG |
7085 | /* Estimates the size cost of thumb1 instructions. |
7086 | For now most of the code is copied from thumb1_rtx_costs. We need more | |
7087 | fine grain tuning when we have more related test cases. */ | |
7088 | static inline int | |
7089 | thumb1_size_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer) | |
7090 | { | |
7091 | enum machine_mode mode = GET_MODE (x); | |
7092 | ||
7093 | switch (code) | |
7094 | { | |
7095 | case ASHIFT: | |
7096 | case ASHIFTRT: | |
7097 | case LSHIFTRT: | |
7098 | case ROTATERT: | |
7099 | case PLUS: | |
7100 | case MINUS: | |
7101 | case COMPARE: | |
7102 | case NEG: | |
7103 | case NOT: | |
7104 | return COSTS_N_INSNS (1); | |
7105 | ||
7106 | case MULT: | |
7107 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
7108 | { | |
7109 | /* Thumb1 mul instruction can't operate on const. We must Load it | |
7110 | into a register first. */ | |
7111 | int const_size = thumb1_size_rtx_costs (XEXP (x, 1), CONST_INT, SET); | |
7112 | return COSTS_N_INSNS (1) + const_size; | |
7113 | } | |
7114 | return COSTS_N_INSNS (1); | |
7115 | ||
7116 | case SET: | |
7117 | return (COSTS_N_INSNS (1) | |
7118 | + 4 * ((GET_CODE (SET_SRC (x)) == MEM) | |
7119 | + GET_CODE (SET_DEST (x)) == MEM)); | |
7120 | ||
7121 | case CONST_INT: | |
7122 | if (outer == SET) | |
7123 | { | |
7124 | if ((unsigned HOST_WIDE_INT) INTVAL (x) < 256) | |
9b9ee6d3 | 7125 | return COSTS_N_INSNS (1); |
3393e880 MK |
7126 | /* See split "TARGET_THUMB1 && satisfies_constraint_J". */ |
7127 | if (INTVAL (x) >= -255 && INTVAL (x) <= -1) | |
7128 | return COSTS_N_INSNS (2); | |
7129 | /* See split "TARGET_THUMB1 && satisfies_constraint_K". */ | |
7548c1be WG |
7130 | if (thumb_shiftable_const (INTVAL (x))) |
7131 | return COSTS_N_INSNS (2); | |
7132 | return COSTS_N_INSNS (3); | |
7133 | } | |
7134 | else if ((outer == PLUS || outer == COMPARE) | |
7135 | && INTVAL (x) < 256 && INTVAL (x) > -256) | |
7136 | return 0; | |
7137 | else if ((outer == IOR || outer == XOR || outer == AND) | |
7138 | && INTVAL (x) < 256 && INTVAL (x) >= -256) | |
7139 | return COSTS_N_INSNS (1); | |
7140 | else if (outer == AND) | |
7141 | { | |
7142 | int i; | |
7143 | /* This duplicates the tests in the andsi3 expander. */ | |
7144 | for (i = 9; i <= 31; i++) | |
7145 | if ((((HOST_WIDE_INT) 1) << i) - 1 == INTVAL (x) | |
7146 | || (((HOST_WIDE_INT) 1) << i) - 1 == ~INTVAL (x)) | |
7147 | return COSTS_N_INSNS (2); | |
7148 | } | |
7149 | else if (outer == ASHIFT || outer == ASHIFTRT | |
7150 | || outer == LSHIFTRT) | |
7151 | return 0; | |
7152 | return COSTS_N_INSNS (2); | |
7153 | ||
7154 | case CONST: | |
7155 | case CONST_DOUBLE: | |
7156 | case LABEL_REF: | |
7157 | case SYMBOL_REF: | |
7158 | return COSTS_N_INSNS (3); | |
7159 | ||
7160 | case UDIV: | |
7161 | case UMOD: | |
7162 | case DIV: | |
7163 | case MOD: | |
7164 | return 100; | |
7165 | ||
7166 | case TRUNCATE: | |
7167 | return 99; | |
7168 | ||
7169 | case AND: | |
7170 | case XOR: | |
7171 | case IOR: | |
7172 | /* XXX guess. */ | |
7173 | return 8; | |
7174 | ||
7175 | case MEM: | |
7176 | /* XXX another guess. */ | |
7177 | /* Memory costs quite a lot for the first word, but subsequent words | |
7178 | load at the equivalent of a single insn each. */ | |
7179 | return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD) | |
7180 | + ((GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x)) | |
7181 | ? 4 : 0)); | |
7182 | ||
7183 | case IF_THEN_ELSE: | |
7184 | /* XXX a guess. */ | |
7185 | if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC) | |
7186 | return 14; | |
7187 | return 2; | |
7188 | ||
7189 | case ZERO_EXTEND: | |
7190 | /* XXX still guessing. */ | |
7191 | switch (GET_MODE (XEXP (x, 0))) | |
7192 | { | |
7193 | case QImode: | |
7194 | return (1 + (mode == DImode ? 4 : 0) | |
7195 | + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
7196 | ||
7197 | case HImode: | |
7198 | return (4 + (mode == DImode ? 4 : 0) | |
7199 | + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
7200 | ||
7201 | case SImode: | |
7202 | return (1 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
7203 | ||
7204 | default: | |
7205 | return 99; | |
7206 | } | |
7207 | ||
7208 | default: | |
7209 | return 99; | |
7210 | } | |
7211 | } | |
7212 | ||
21b5653c RE |
7213 | /* RTX costs when optimizing for size. */ |
7214 | static bool | |
d5a0a47b RE |
7215 | arm_size_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer_code, |
7216 | int *total) | |
21b5653c RE |
7217 | { |
7218 | enum machine_mode mode = GET_MODE (x); | |
09754904 | 7219 | if (TARGET_THUMB1) |
21b5653c | 7220 | { |
7548c1be | 7221 | *total = thumb1_size_rtx_costs (x, code, outer_code); |
21b5653c RE |
7222 | return true; |
7223 | } | |
7224 | ||
09754904 | 7225 | /* FIXME: This makes no attempt to prefer narrow Thumb-2 instructions. */ |
21b5653c RE |
7226 | switch (code) |
7227 | { | |
7228 | case MEM: | |
f676971a | 7229 | /* A memory access costs 1 insn if the mode is small, or the address is |
21b5653c RE |
7230 | a single register, otherwise it costs one insn per word. */ |
7231 | if (REG_P (XEXP (x, 0))) | |
7232 | *total = COSTS_N_INSNS (1); | |
d37c3c62 MK |
7233 | else if (flag_pic |
7234 | && GET_CODE (XEXP (x, 0)) == PLUS | |
7235 | && will_be_in_index_register (XEXP (XEXP (x, 0), 1))) | |
7236 | /* This will be split into two instructions. | |
7237 | See arm.md:calculate_pic_address. */ | |
7238 | *total = COSTS_N_INSNS (2); | |
21b5653c RE |
7239 | else |
7240 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7241 | return true; | |
7242 | ||
7243 | case DIV: | |
7244 | case MOD: | |
7245 | case UDIV: | |
7246 | case UMOD: | |
7247 | /* Needs a libcall, so it costs about this. */ | |
7248 | *total = COSTS_N_INSNS (2); | |
7249 | return false; | |
7250 | ||
7251 | case ROTATE: | |
7252 | if (mode == SImode && GET_CODE (XEXP (x, 1)) == REG) | |
7253 | { | |
f40751dd | 7254 | *total = COSTS_N_INSNS (2) + rtx_cost (XEXP (x, 0), code, false); |
21b5653c RE |
7255 | return true; |
7256 | } | |
7257 | /* Fall through */ | |
7258 | case ROTATERT: | |
7259 | case ASHIFT: | |
7260 | case LSHIFTRT: | |
7261 | case ASHIFTRT: | |
7262 | if (mode == DImode && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
7263 | { | |
f40751dd | 7264 | *total = COSTS_N_INSNS (3) + rtx_cost (XEXP (x, 0), code, false); |
21b5653c RE |
7265 | return true; |
7266 | } | |
7267 | else if (mode == SImode) | |
7268 | { | |
f40751dd | 7269 | *total = COSTS_N_INSNS (1) + rtx_cost (XEXP (x, 0), code, false); |
21b5653c RE |
7270 | /* Slightly disparage register shifts, but not by much. */ |
7271 | if (GET_CODE (XEXP (x, 1)) != CONST_INT) | |
f40751dd | 7272 | *total += 1 + rtx_cost (XEXP (x, 1), code, false); |
21b5653c RE |
7273 | return true; |
7274 | } | |
7275 | ||
7276 | /* Needs a libcall. */ | |
7277 | *total = COSTS_N_INSNS (2); | |
7278 | return false; | |
7279 | ||
7280 | case MINUS: | |
e0dc3601 PB |
7281 | if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
7282 | && (mode == SFmode || !TARGET_VFP_SINGLE)) | |
21b5653c RE |
7283 | { |
7284 | *total = COSTS_N_INSNS (1); | |
7285 | return false; | |
7286 | } | |
7287 | ||
7288 | if (mode == SImode) | |
7289 | { | |
7290 | enum rtx_code subcode0 = GET_CODE (XEXP (x, 0)); | |
7291 | enum rtx_code subcode1 = GET_CODE (XEXP (x, 1)); | |
7292 | ||
7293 | if (subcode0 == ROTATE || subcode0 == ROTATERT || subcode0 == ASHIFT | |
7294 | || subcode0 == LSHIFTRT || subcode0 == ASHIFTRT | |
7295 | || subcode1 == ROTATE || subcode1 == ROTATERT | |
7296 | || subcode1 == ASHIFT || subcode1 == LSHIFTRT | |
7297 | || subcode1 == ASHIFTRT) | |
7298 | { | |
7299 | /* It's just the cost of the two operands. */ | |
7300 | *total = 0; | |
7301 | return false; | |
7302 | } | |
7303 | ||
7304 | *total = COSTS_N_INSNS (1); | |
7305 | return false; | |
7306 | } | |
7307 | ||
7308 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7309 | return false; | |
7310 | ||
f676971a | 7311 | case PLUS: |
e0dc3601 PB |
7312 | if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
7313 | && (mode == SFmode || !TARGET_VFP_SINGLE)) | |
21b5653c RE |
7314 | { |
7315 | *total = COSTS_N_INSNS (1); | |
7316 | return false; | |
7317 | } | |
7318 | ||
6e782a29 KH |
7319 | /* A shift as a part of ADD costs nothing. */ |
7320 | if (GET_CODE (XEXP (x, 0)) == MULT | |
7321 | && power_of_two_operand (XEXP (XEXP (x, 0), 1), SImode)) | |
7322 | { | |
7323 | *total = COSTS_N_INSNS (TARGET_THUMB2 ? 2 : 1); | |
7324 | *total += rtx_cost (XEXP (XEXP (x, 0), 0), code, false); | |
7325 | *total += rtx_cost (XEXP (x, 1), code, false); | |
7326 | return true; | |
7327 | } | |
7328 | ||
21b5653c RE |
7329 | /* Fall through */ |
7330 | case AND: case XOR: case IOR: | |
7331 | if (mode == SImode) | |
7332 | { | |
7333 | enum rtx_code subcode = GET_CODE (XEXP (x, 0)); | |
7334 | ||
7335 | if (subcode == ROTATE || subcode == ROTATERT || subcode == ASHIFT | |
7336 | || subcode == LSHIFTRT || subcode == ASHIFTRT | |
7337 | || (code == AND && subcode == NOT)) | |
7338 | { | |
7339 | /* It's just the cost of the two operands. */ | |
7340 | *total = 0; | |
7341 | return false; | |
7342 | } | |
7343 | } | |
7344 | ||
7345 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7346 | return false; | |
7347 | ||
7348 | case MULT: | |
7349 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7350 | return false; | |
7351 | ||
7352 | case NEG: | |
e0dc3601 PB |
7353 | if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
7354 | && (mode == SFmode || !TARGET_VFP_SINGLE)) | |
7ce8451d MG |
7355 | { |
7356 | *total = COSTS_N_INSNS (1); | |
7357 | return false; | |
7358 | } | |
7359 | ||
21b5653c RE |
7360 | /* Fall through */ |
7361 | case NOT: | |
7362 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7363 | ||
7364 | return false; | |
7365 | ||
7366 | case IF_THEN_ELSE: | |
7367 | *total = 0; | |
7368 | return false; | |
7369 | ||
7370 | case COMPARE: | |
7371 | if (cc_register (XEXP (x, 0), VOIDmode)) | |
7372 | * total = 0; | |
7373 | else | |
7374 | *total = COSTS_N_INSNS (1); | |
7375 | return false; | |
7376 | ||
7377 | case ABS: | |
e0dc3601 PB |
7378 | if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
7379 | && (mode == SFmode || !TARGET_VFP_SINGLE)) | |
21b5653c RE |
7380 | *total = COSTS_N_INSNS (1); |
7381 | else | |
7382 | *total = COSTS_N_INSNS (1 + ARM_NUM_REGS (mode)); | |
7383 | return false; | |
7384 | ||
7385 | case SIGN_EXTEND: | |
21b5653c | 7386 | case ZERO_EXTEND: |
e4c6a07a | 7387 | return arm_rtx_costs_1 (x, outer_code, total, 0); |
21b5653c | 7388 | |
f676971a EC |
7389 | case CONST_INT: |
7390 | if (const_ok_for_arm (INTVAL (x))) | |
6e782a29 KH |
7391 | /* A multiplication by a constant requires another instruction |
7392 | to load the constant to a register. */ | |
7393 | *total = COSTS_N_INSNS ((outer_code == SET || outer_code == MULT) | |
7394 | ? 1 : 0); | |
21b5653c RE |
7395 | else if (const_ok_for_arm (~INTVAL (x))) |
7396 | *total = COSTS_N_INSNS (outer_code == AND ? 0 : 1); | |
7397 | else if (const_ok_for_arm (-INTVAL (x))) | |
7398 | { | |
7399 | if (outer_code == COMPARE || outer_code == PLUS | |
7400 | || outer_code == MINUS) | |
7401 | *total = 0; | |
7402 | else | |
7403 | *total = COSTS_N_INSNS (1); | |
7404 | } | |
7405 | else | |
7406 | *total = COSTS_N_INSNS (2); | |
7407 | return true; | |
f676971a EC |
7408 | |
7409 | case CONST: | |
7410 | case LABEL_REF: | |
7411 | case SYMBOL_REF: | |
21b5653c RE |
7412 | *total = COSTS_N_INSNS (2); |
7413 | return true; | |
f676971a | 7414 | |
21b5653c RE |
7415 | case CONST_DOUBLE: |
7416 | *total = COSTS_N_INSNS (4); | |
7417 | return true; | |
7418 | ||
571191af PB |
7419 | case HIGH: |
7420 | case LO_SUM: | |
7421 | /* We prefer constant pool entries to MOVW/MOVT pairs, so bump the | |
7422 | cost of these slightly. */ | |
7423 | *total = COSTS_N_INSNS (1) + 1; | |
7424 | return true; | |
7425 | ||
21b5653c RE |
7426 | default: |
7427 | if (mode != VOIDmode) | |
7428 | *total = COSTS_N_INSNS (ARM_NUM_REGS (mode)); | |
7429 | else | |
7430 | *total = COSTS_N_INSNS (4); /* How knows? */ | |
7431 | return false; | |
7432 | } | |
7433 | } | |
7434 | ||
f40751dd JH |
7435 | /* RTX costs when optimizing for size. */ |
7436 | static bool | |
d5a0a47b RE |
7437 | arm_rtx_costs (rtx x, int code, int outer_code, int *total, |
7438 | bool speed) | |
f40751dd JH |
7439 | { |
7440 | if (!speed) | |
bbbbb16a ILT |
7441 | return arm_size_rtx_costs (x, (enum rtx_code) code, |
7442 | (enum rtx_code) outer_code, total); | |
f40751dd | 7443 | else |
1b78f575 RE |
7444 | return current_tune->rtx_costs (x, (enum rtx_code) code, |
7445 | (enum rtx_code) outer_code, | |
7446 | total, speed); | |
f40751dd JH |
7447 | } |
7448 | ||
5b3e6663 PB |
7449 | /* RTX costs for cores with a slow MUL implementation. Thumb-2 is not |
7450 | supported on any "slowmul" cores, so it can be ignored. */ | |
9b66ebb1 | 7451 | |
3c50106f | 7452 | static bool |
d5a0a47b RE |
7453 | arm_slowmul_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer_code, |
7454 | int *total, bool speed) | |
3c50106f | 7455 | { |
9b66ebb1 PB |
7456 | enum machine_mode mode = GET_MODE (x); |
7457 | ||
7458 | if (TARGET_THUMB) | |
7459 | { | |
5b3e6663 | 7460 | *total = thumb1_rtx_costs (x, code, outer_code); |
9b66ebb1 PB |
7461 | return true; |
7462 | } | |
f676971a | 7463 | |
9b66ebb1 PB |
7464 | switch (code) |
7465 | { | |
7466 | case MULT: | |
7467 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
7468 | || mode == DImode) | |
7469 | { | |
d5a0a47b RE |
7470 | *total = COSTS_N_INSNS (20); |
7471 | return false; | |
9b66ebb1 PB |
7472 | } |
7473 | ||
7474 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
7475 | { | |
7476 | unsigned HOST_WIDE_INT i = (INTVAL (XEXP (x, 1)) | |
7477 | & (unsigned HOST_WIDE_INT) 0xffffffff); | |
7478 | int cost, const_ok = const_ok_for_arm (i); | |
7479 | int j, booth_unit_size; | |
7480 | ||
f676971a | 7481 | /* Tune as appropriate. */ |
9b66ebb1 PB |
7482 | cost = const_ok ? 4 : 8; |
7483 | booth_unit_size = 2; | |
7484 | for (j = 0; i && j < 32; j += booth_unit_size) | |
7485 | { | |
7486 | i >>= booth_unit_size; | |
d5a0a47b | 7487 | cost++; |
9b66ebb1 PB |
7488 | } |
7489 | ||
d5a0a47b RE |
7490 | *total = COSTS_N_INSNS (cost); |
7491 | *total += rtx_cost (XEXP (x, 0), code, speed); | |
9b66ebb1 PB |
7492 | return true; |
7493 | } | |
7494 | ||
d5a0a47b RE |
7495 | *total = COSTS_N_INSNS (20); |
7496 | return false; | |
f676971a | 7497 | |
9b66ebb1 | 7498 | default: |
d5a0a47b | 7499 | return arm_rtx_costs_1 (x, outer_code, total, speed);; |
9b66ebb1 | 7500 | } |
3c50106f RH |
7501 | } |
7502 | ||
9b66ebb1 PB |
7503 | |
7504 | /* RTX cost for cores with a fast multiply unit (M variants). */ | |
7505 | ||
7506 | static bool | |
d5a0a47b RE |
7507 | arm_fastmul_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer_code, |
7508 | int *total, bool speed) | |
9b66ebb1 PB |
7509 | { |
7510 | enum machine_mode mode = GET_MODE (x); | |
7511 | ||
5b3e6663 | 7512 | if (TARGET_THUMB1) |
9b66ebb1 | 7513 | { |
5b3e6663 | 7514 | *total = thumb1_rtx_costs (x, code, outer_code); |
9b66ebb1 PB |
7515 | return true; |
7516 | } | |
f676971a | 7517 | |
5b3e6663 | 7518 | /* ??? should thumb2 use different costs? */ |
9b66ebb1 PB |
7519 | switch (code) |
7520 | { | |
7521 | case MULT: | |
7522 | /* There is no point basing this on the tuning, since it is always the | |
7523 | fast variant if it exists at all. */ | |
7524 | if (mode == DImode | |
7525 | && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1))) | |
7526 | && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND | |
7527 | || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)) | |
7528 | { | |
d5a0a47b RE |
7529 | *total = COSTS_N_INSNS(2); |
7530 | return false; | |
9b66ebb1 | 7531 | } |
f676971a | 7532 | |
9b66ebb1 | 7533 | |
d5a0a47b | 7534 | if (mode == DImode) |
9b66ebb1 | 7535 | { |
d5a0a47b RE |
7536 | *total = COSTS_N_INSNS (5); |
7537 | return false; | |
9b66ebb1 PB |
7538 | } |
7539 | ||
7540 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
7541 | { | |
7542 | unsigned HOST_WIDE_INT i = (INTVAL (XEXP (x, 1)) | |
7543 | & (unsigned HOST_WIDE_INT) 0xffffffff); | |
7544 | int cost, const_ok = const_ok_for_arm (i); | |
7545 | int j, booth_unit_size; | |
7546 | ||
f676971a | 7547 | /* Tune as appropriate. */ |
9b66ebb1 PB |
7548 | cost = const_ok ? 4 : 8; |
7549 | booth_unit_size = 8; | |
7550 | for (j = 0; i && j < 32; j += booth_unit_size) | |
7551 | { | |
7552 | i >>= booth_unit_size; | |
d5a0a47b | 7553 | cost++; |
9b66ebb1 PB |
7554 | } |
7555 | ||
d5a0a47b RE |
7556 | *total = COSTS_N_INSNS(cost); |
7557 | return false; | |
9b66ebb1 PB |
7558 | } |
7559 | ||
d5a0a47b RE |
7560 | if (mode == SImode) |
7561 | { | |
7562 | *total = COSTS_N_INSNS (4); | |
7563 | return false; | |
7564 | } | |
7565 | ||
7566 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
7567 | { | |
e0dc3601 PB |
7568 | if (TARGET_HARD_FLOAT |
7569 | && (mode == SFmode | |
7570 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
7571 | { |
7572 | *total = COSTS_N_INSNS (1); | |
7573 | return false; | |
7574 | } | |
7575 | } | |
7576 | ||
7577 | /* Requires a lib call */ | |
7578 | *total = COSTS_N_INSNS (20); | |
7579 | return false; | |
f676971a | 7580 | |
9b66ebb1 | 7581 | default: |
d5a0a47b | 7582 | return arm_rtx_costs_1 (x, outer_code, total, speed); |
9b66ebb1 PB |
7583 | } |
7584 | } | |
7585 | ||
7586 | ||
5b3e6663 PB |
7587 | /* RTX cost for XScale CPUs. Thumb-2 is not supported on any xscale cores, |
7588 | so it can be ignored. */ | |
9b66ebb1 PB |
7589 | |
7590 | static bool | |
1b78f575 RE |
7591 | arm_xscale_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer_code, |
7592 | int *total, bool speed) | |
9b66ebb1 PB |
7593 | { |
7594 | enum machine_mode mode = GET_MODE (x); | |
7595 | ||
7596 | if (TARGET_THUMB) | |
7597 | { | |
5b3e6663 | 7598 | *total = thumb1_rtx_costs (x, code, outer_code); |
9b66ebb1 PB |
7599 | return true; |
7600 | } | |
f676971a | 7601 | |
9b66ebb1 PB |
7602 | switch (code) |
7603 | { | |
d5a0a47b RE |
7604 | case COMPARE: |
7605 | if (GET_CODE (XEXP (x, 0)) != MULT) | |
7606 | return arm_rtx_costs_1 (x, outer_code, total, speed); | |
7607 | ||
7608 | /* A COMPARE of a MULT is slow on XScale; the muls instruction | |
7609 | will stall until the multiplication is complete. */ | |
7610 | *total = COSTS_N_INSNS (3); | |
7611 | return false; | |
7612 | ||
9b66ebb1 PB |
7613 | case MULT: |
7614 | /* There is no point basing this on the tuning, since it is always the | |
7615 | fast variant if it exists at all. */ | |
7616 | if (mode == DImode | |
7617 | && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1))) | |
7618 | && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND | |
7619 | || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)) | |
7620 | { | |
d5a0a47b RE |
7621 | *total = COSTS_N_INSNS (2); |
7622 | return false; | |
9b66ebb1 | 7623 | } |
f676971a | 7624 | |
9b66ebb1 | 7625 | |
d5a0a47b | 7626 | if (mode == DImode) |
9b66ebb1 | 7627 | { |
d5a0a47b RE |
7628 | *total = COSTS_N_INSNS (5); |
7629 | return false; | |
9b66ebb1 PB |
7630 | } |
7631 | ||
7632 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
7633 | { | |
d5a0a47b RE |
7634 | /* If operand 1 is a constant we can more accurately |
7635 | calculate the cost of the multiply. The multiplier can | |
7636 | retire 15 bits on the first cycle and a further 12 on the | |
7637 | second. We do, of course, have to load the constant into | |
7638 | a register first. */ | |
7639 | unsigned HOST_WIDE_INT i = INTVAL (XEXP (x, 1)); | |
7640 | /* There's a general overhead of one cycle. */ | |
7641 | int cost = 1; | |
9b66ebb1 PB |
7642 | unsigned HOST_WIDE_INT masked_const; |
7643 | ||
d5a0a47b RE |
7644 | if (i & 0x80000000) |
7645 | i = ~i; | |
7646 | ||
7647 | i &= (unsigned HOST_WIDE_INT) 0xffffffff; | |
7648 | ||
9b66ebb1 | 7649 | masked_const = i & 0xffff8000; |
d5a0a47b | 7650 | if (masked_const != 0) |
9b66ebb1 | 7651 | { |
d5a0a47b | 7652 | cost++; |
9b66ebb1 | 7653 | masked_const = i & 0xf8000000; |
d5a0a47b RE |
7654 | if (masked_const != 0) |
7655 | cost++; | |
9b66ebb1 | 7656 | } |
d5a0a47b RE |
7657 | *total = COSTS_N_INSNS (cost); |
7658 | return false; | |
9b66ebb1 PB |
7659 | } |
7660 | ||
d5a0a47b RE |
7661 | if (mode == SImode) |
7662 | { | |
7663 | *total = COSTS_N_INSNS (3); | |
7664 | return false; | |
7665 | } | |
f676971a | 7666 | |
d5a0a47b RE |
7667 | /* Requires a lib call */ |
7668 | *total = COSTS_N_INSNS (20); | |
7669 | return false; | |
06d5588c | 7670 | |
9b66ebb1 | 7671 | default: |
d5a0a47b | 7672 | return arm_rtx_costs_1 (x, outer_code, total, speed); |
9b66ebb1 PB |
7673 | } |
7674 | } | |
7675 | ||
7676 | ||
7677 | /* RTX costs for 9e (and later) cores. */ | |
7678 | ||
7679 | static bool | |
d5a0a47b RE |
7680 | arm_9e_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer_code, |
7681 | int *total, bool speed) | |
9b66ebb1 PB |
7682 | { |
7683 | enum machine_mode mode = GET_MODE (x); | |
f676971a | 7684 | |
5b3e6663 | 7685 | if (TARGET_THUMB1) |
9b66ebb1 PB |
7686 | { |
7687 | switch (code) | |
7688 | { | |
7689 | case MULT: | |
7690 | *total = COSTS_N_INSNS (3); | |
7691 | return true; | |
f676971a | 7692 | |
9b66ebb1 | 7693 | default: |
5b3e6663 | 7694 | *total = thumb1_rtx_costs (x, code, outer_code); |
9b66ebb1 PB |
7695 | return true; |
7696 | } | |
7697 | } | |
f676971a | 7698 | |
9b66ebb1 PB |
7699 | switch (code) |
7700 | { | |
7701 | case MULT: | |
7702 | /* There is no point basing this on the tuning, since it is always the | |
7703 | fast variant if it exists at all. */ | |
7704 | if (mode == DImode | |
7705 | && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1))) | |
7706 | && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND | |
7707 | || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)) | |
7708 | { | |
d5a0a47b RE |
7709 | *total = COSTS_N_INSNS (2); |
7710 | return false; | |
9b66ebb1 | 7711 | } |
f676971a | 7712 | |
9b66ebb1 | 7713 | |
9b66ebb1 PB |
7714 | if (mode == DImode) |
7715 | { | |
d5a0a47b RE |
7716 | *total = COSTS_N_INSNS (5); |
7717 | return false; | |
9b66ebb1 | 7718 | } |
d5a0a47b RE |
7719 | |
7720 | if (mode == SImode) | |
9b66ebb1 | 7721 | { |
d5a0a47b RE |
7722 | *total = COSTS_N_INSNS (2); |
7723 | return false; | |
9b66ebb1 PB |
7724 | } |
7725 | ||
d5a0a47b RE |
7726 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) |
7727 | { | |
e0dc3601 PB |
7728 | if (TARGET_HARD_FLOAT |
7729 | && (mode == SFmode | |
7730 | || (mode == DFmode && !TARGET_VFP_SINGLE))) | |
d5a0a47b RE |
7731 | { |
7732 | *total = COSTS_N_INSNS (1); | |
7733 | return false; | |
7734 | } | |
7735 | } | |
9b66ebb1 | 7736 | |
d5a0a47b RE |
7737 | *total = COSTS_N_INSNS (20); |
7738 | return false; | |
f676971a | 7739 | |
9b66ebb1 | 7740 | default: |
d5a0a47b | 7741 | return arm_rtx_costs_1 (x, outer_code, total, speed); |
9b66ebb1 PB |
7742 | } |
7743 | } | |
dcefdf67 RH |
7744 | /* All address computations that can be done are free, but rtx cost returns |
7745 | the same for practically all of them. So we weight the different types | |
7746 | of address here in the order (most pref first): | |
d6b4baa4 | 7747 | PRE/POST_INC/DEC, SHIFT or NON-INT sum, INT sum, REG, MEM or LABEL. */ |
d2b6eb76 ZW |
7748 | static inline int |
7749 | arm_arm_address_cost (rtx x) | |
7750 | { | |
7751 | enum rtx_code c = GET_CODE (x); | |
7752 | ||
7753 | if (c == PRE_INC || c == PRE_DEC || c == POST_INC || c == POST_DEC) | |
7754 | return 0; | |
7755 | if (c == MEM || c == LABEL_REF || c == SYMBOL_REF) | |
7756 | return 10; | |
7757 | ||
17eb4921 | 7758 | if (c == PLUS) |
d2b6eb76 | 7759 | { |
17eb4921 | 7760 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) |
d2b6eb76 ZW |
7761 | return 2; |
7762 | ||
ec8e098d | 7763 | if (ARITHMETIC_P (XEXP (x, 0)) || ARITHMETIC_P (XEXP (x, 1))) |
d2b6eb76 ZW |
7764 | return 3; |
7765 | ||
7766 | return 4; | |
7767 | } | |
7768 | ||
7769 | return 6; | |
7770 | } | |
7771 | ||
7772 | static inline int | |
7773 | arm_thumb_address_cost (rtx x) | |
7774 | { | |
7775 | enum rtx_code c = GET_CODE (x); | |
7776 | ||
7777 | if (c == REG) | |
7778 | return 1; | |
7779 | if (c == PLUS | |
7780 | && GET_CODE (XEXP (x, 0)) == REG | |
7781 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
7782 | return 1; | |
7783 | ||
7784 | return 2; | |
7785 | } | |
7786 | ||
dcefdf67 | 7787 | static int |
f40751dd | 7788 | arm_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED) |
dcefdf67 | 7789 | { |
5b3e6663 | 7790 | return TARGET_32BIT ? arm_arm_address_cost (x) : arm_thumb_address_cost (x); |
dcefdf67 | 7791 | } |
906668bb | 7792 | |
b0c13111 RR |
7793 | /* Adjust cost hook for XScale. */ |
7794 | static bool | |
7795 | xscale_sched_adjust_cost (rtx insn, rtx link, rtx dep, int * cost) | |
7796 | { | |
d19fb8e3 NC |
7797 | /* Some true dependencies can have a higher cost depending |
7798 | on precisely how certain input operands are used. */ | |
b0c13111 | 7799 | if (REG_NOTE_KIND(link) == 0 |
eda833e3 BE |
7800 | && recog_memoized (insn) >= 0 |
7801 | && recog_memoized (dep) >= 0) | |
d19fb8e3 NC |
7802 | { |
7803 | int shift_opnum = get_attr_shift (insn); | |
7804 | enum attr_type attr_type = get_attr_type (dep); | |
7805 | ||
7806 | /* If nonzero, SHIFT_OPNUM contains the operand number of a shifted | |
7807 | operand for INSN. If we have a shifted input operand and the | |
7808 | instruction we depend on is another ALU instruction, then we may | |
7809 | have to account for an additional stall. */ | |
9b66ebb1 PB |
7810 | if (shift_opnum != 0 |
7811 | && (attr_type == TYPE_ALU_SHIFT || attr_type == TYPE_ALU_SHIFT_REG)) | |
d19fb8e3 NC |
7812 | { |
7813 | rtx shifted_operand; | |
7814 | int opno; | |
f676971a | 7815 | |
d19fb8e3 NC |
7816 | /* Get the shifted operand. */ |
7817 | extract_insn (insn); | |
7818 | shifted_operand = recog_data.operand[shift_opnum]; | |
7819 | ||
7820 | /* Iterate over all the operands in DEP. If we write an operand | |
7821 | that overlaps with SHIFTED_OPERAND, then we have increase the | |
7822 | cost of this dependency. */ | |
7823 | extract_insn (dep); | |
7824 | preprocess_constraints (); | |
7825 | for (opno = 0; opno < recog_data.n_operands; opno++) | |
7826 | { | |
7827 | /* We can ignore strict inputs. */ | |
7828 | if (recog_data.operand_type[opno] == OP_IN) | |
7829 | continue; | |
7830 | ||
7831 | if (reg_overlap_mentioned_p (recog_data.operand[opno], | |
7832 | shifted_operand)) | |
b0c13111 RR |
7833 | { |
7834 | *cost = 2; | |
7835 | return false; | |
7836 | } | |
d19fb8e3 NC |
7837 | } |
7838 | } | |
7839 | } | |
b0c13111 RR |
7840 | return true; |
7841 | } | |
7842 | ||
7843 | /* Adjust cost hook for Cortex A9. */ | |
7844 | static bool | |
7845 | cortex_a9_sched_adjust_cost (rtx insn, rtx link, rtx dep, int * cost) | |
7846 | { | |
7847 | switch (REG_NOTE_KIND (link)) | |
7848 | { | |
7849 | case REG_DEP_ANTI: | |
7850 | *cost = 0; | |
7851 | return false; | |
7852 | ||
7853 | case REG_DEP_TRUE: | |
7854 | case REG_DEP_OUTPUT: | |
7855 | if (recog_memoized (insn) >= 0 | |
7856 | && recog_memoized (dep) >= 0) | |
7857 | { | |
7858 | if (GET_CODE (PATTERN (insn)) == SET) | |
7859 | { | |
7860 | if (GET_MODE_CLASS | |
7861 | (GET_MODE (SET_DEST (PATTERN (insn)))) == MODE_FLOAT | |
7862 | || GET_MODE_CLASS | |
7863 | (GET_MODE (SET_SRC (PATTERN (insn)))) == MODE_FLOAT) | |
7864 | { | |
7865 | enum attr_type attr_type_insn = get_attr_type (insn); | |
7866 | enum attr_type attr_type_dep = get_attr_type (dep); | |
7867 | ||
7868 | /* By default all dependencies of the form | |
7869 | s0 = s0 <op> s1 | |
7870 | s0 = s0 <op> s2 | |
7871 | have an extra latency of 1 cycle because | |
7872 | of the input and output dependency in this | |
7873 | case. However this gets modeled as an true | |
7874 | dependency and hence all these checks. */ | |
7875 | if (REG_P (SET_DEST (PATTERN (insn))) | |
7876 | && REG_P (SET_DEST (PATTERN (dep))) | |
7877 | && reg_overlap_mentioned_p (SET_DEST (PATTERN (insn)), | |
7878 | SET_DEST (PATTERN (dep)))) | |
7879 | { | |
7880 | /* FMACS is a special case where the dependant | |
7881 | instruction can be issued 3 cycles before | |
7882 | the normal latency in case of an output | |
7883 | dependency. */ | |
7884 | if ((attr_type_insn == TYPE_FMACS | |
7885 | || attr_type_insn == TYPE_FMACD) | |
7886 | && (attr_type_dep == TYPE_FMACS | |
7887 | || attr_type_dep == TYPE_FMACD)) | |
7888 | { | |
7889 | if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT) | |
7890 | *cost = insn_default_latency (dep) - 3; | |
7891 | else | |
7892 | *cost = insn_default_latency (dep); | |
7893 | return false; | |
7894 | } | |
7895 | else | |
7896 | { | |
7897 | if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT) | |
7898 | *cost = insn_default_latency (dep) + 1; | |
7899 | else | |
7900 | *cost = insn_default_latency (dep); | |
7901 | } | |
7902 | return false; | |
7903 | } | |
7904 | } | |
7905 | } | |
7906 | } | |
7907 | break; | |
7908 | ||
7909 | default: | |
7910 | gcc_unreachable (); | |
7911 | } | |
7912 | ||
7913 | return true; | |
7914 | } | |
7915 | ||
7916 | /* This function implements the target macro TARGET_SCHED_ADJUST_COST. | |
7917 | It corrects the value of COST based on the relationship between | |
7918 | INSN and DEP through the dependence LINK. It returns the new | |
7919 | value. There is a per-core adjust_cost hook to adjust scheduler costs | |
7920 | and the per-core hook can choose to completely override the generic | |
7921 | adjust_cost function. Only put bits of code into arm_adjust_cost that | |
7922 | are common across all cores. */ | |
7923 | static int | |
7924 | arm_adjust_cost (rtx insn, rtx link, rtx dep, int cost) | |
7925 | { | |
7926 | rtx i_pat, d_pat; | |
7927 | ||
7928 | /* When generating Thumb-1 code, we want to place flag-setting operations | |
7929 | close to a conditional branch which depends on them, so that we can | |
7930 | omit the comparison. */ | |
7931 | if (TARGET_THUMB1 | |
7932 | && REG_NOTE_KIND (link) == 0 | |
7933 | && recog_memoized (insn) == CODE_FOR_cbranchsi4_insn | |
7934 | && recog_memoized (dep) >= 0 | |
7935 | && get_attr_conds (dep) == CONDS_SET) | |
7936 | return 0; | |
7937 | ||
7938 | if (current_tune->sched_adjust_cost != NULL) | |
7939 | { | |
7940 | if (!current_tune->sched_adjust_cost (insn, link, dep, &cost)) | |
7941 | return cost; | |
7942 | } | |
d19fb8e3 | 7943 | |
6354dc9b | 7944 | /* XXX This is not strictly true for the FPA. */ |
d5b7b3ae RE |
7945 | if (REG_NOTE_KIND (link) == REG_DEP_ANTI |
7946 | || REG_NOTE_KIND (link) == REG_DEP_OUTPUT) | |
b36ba79f RE |
7947 | return 0; |
7948 | ||
d5b7b3ae RE |
7949 | /* Call insns don't incur a stall, even if they follow a load. */ |
7950 | if (REG_NOTE_KIND (link) == 0 | |
7951 | && GET_CODE (insn) == CALL_INSN) | |
7952 | return 1; | |
7953 | ||
32de079a RE |
7954 | if ((i_pat = single_set (insn)) != NULL |
7955 | && GET_CODE (SET_SRC (i_pat)) == MEM | |
7956 | && (d_pat = single_set (dep)) != NULL | |
7957 | && GET_CODE (SET_DEST (d_pat)) == MEM) | |
7958 | { | |
48f6efae | 7959 | rtx src_mem = XEXP (SET_SRC (i_pat), 0); |
32de079a RE |
7960 | /* This is a load after a store, there is no conflict if the load reads |
7961 | from a cached area. Assume that loads from the stack, and from the | |
f676971a | 7962 | constant pool are cached, and that others will miss. This is a |
6354dc9b | 7963 | hack. */ |
f676971a | 7964 | |
b0c13111 RR |
7965 | if ((GET_CODE (src_mem) == SYMBOL_REF |
7966 | && CONSTANT_POOL_ADDRESS_P (src_mem)) | |
48f6efae NC |
7967 | || reg_mentioned_p (stack_pointer_rtx, src_mem) |
7968 | || reg_mentioned_p (frame_pointer_rtx, src_mem) | |
7969 | || reg_mentioned_p (hard_frame_pointer_rtx, src_mem)) | |
949d79eb | 7970 | return 1; |
32de079a RE |
7971 | } |
7972 | ||
7973 | return cost; | |
7974 | } | |
7975 | ||
9b66ebb1 | 7976 | static int fp_consts_inited = 0; |
ff9940b0 | 7977 | |
9b66ebb1 PB |
7978 | /* Only zero is valid for VFP. Other values are also valid for FPA. */ |
7979 | static const char * const strings_fp[8] = | |
62b10bbc | 7980 | { |
2b835d68 RE |
7981 | "0", "1", "2", "3", |
7982 | "4", "5", "0.5", "10" | |
7983 | }; | |
ff9940b0 | 7984 | |
9b66ebb1 | 7985 | static REAL_VALUE_TYPE values_fp[8]; |
ff9940b0 RE |
7986 | |
7987 | static void | |
9b66ebb1 | 7988 | init_fp_table (void) |
ff9940b0 RE |
7989 | { |
7990 | int i; | |
7991 | REAL_VALUE_TYPE r; | |
7992 | ||
9b66ebb1 PB |
7993 | if (TARGET_VFP) |
7994 | fp_consts_inited = 1; | |
7995 | else | |
7996 | fp_consts_inited = 8; | |
7997 | ||
7998 | for (i = 0; i < fp_consts_inited; i++) | |
ff9940b0 | 7999 | { |
9b66ebb1 PB |
8000 | r = REAL_VALUE_ATOF (strings_fp[i], DFmode); |
8001 | values_fp[i] = r; | |
ff9940b0 | 8002 | } |
ff9940b0 RE |
8003 | } |
8004 | ||
9b66ebb1 | 8005 | /* Return TRUE if rtx X is a valid immediate FP constant. */ |
cce8749e | 8006 | int |
9b66ebb1 | 8007 | arm_const_double_rtx (rtx x) |
cce8749e | 8008 | { |
ff9940b0 RE |
8009 | REAL_VALUE_TYPE r; |
8010 | int i; | |
f676971a | 8011 | |
9b66ebb1 PB |
8012 | if (!fp_consts_inited) |
8013 | init_fp_table (); | |
f676971a | 8014 | |
ff9940b0 RE |
8015 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); |
8016 | if (REAL_VALUE_MINUS_ZERO (r)) | |
8017 | return 0; | |
f3bb6135 | 8018 | |
9b66ebb1 PB |
8019 | for (i = 0; i < fp_consts_inited; i++) |
8020 | if (REAL_VALUES_EQUAL (r, values_fp[i])) | |
ff9940b0 | 8021 | return 1; |
f3bb6135 | 8022 | |
ff9940b0 | 8023 | return 0; |
f3bb6135 | 8024 | } |
ff9940b0 | 8025 | |
3b684012 | 8026 | /* Return TRUE if rtx X is a valid immediate FPA constant. */ |
ff9940b0 | 8027 | int |
e32bac5b | 8028 | neg_const_double_rtx_ok_for_fpa (rtx x) |
ff9940b0 RE |
8029 | { |
8030 | REAL_VALUE_TYPE r; | |
8031 | int i; | |
f676971a | 8032 | |
9b66ebb1 PB |
8033 | if (!fp_consts_inited) |
8034 | init_fp_table (); | |
f676971a | 8035 | |
ff9940b0 | 8036 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); |
d49b6e1e | 8037 | r = real_value_negate (&r); |
ff9940b0 RE |
8038 | if (REAL_VALUE_MINUS_ZERO (r)) |
8039 | return 0; | |
f3bb6135 | 8040 | |
ff9940b0 | 8041 | for (i = 0; i < 8; i++) |
9b66ebb1 | 8042 | if (REAL_VALUES_EQUAL (r, values_fp[i])) |
ff9940b0 | 8043 | return 1; |
f3bb6135 | 8044 | |
ff9940b0 | 8045 | return 0; |
f3bb6135 | 8046 | } |
f1adb0a9 JB |
8047 | |
8048 | ||
8049 | /* VFPv3 has a fairly wide range of representable immediates, formed from | |
8050 | "quarter-precision" floating-point values. These can be evaluated using this | |
8051 | formula (with ^ for exponentiation): | |
8052 | ||
8053 | -1^s * n * 2^-r | |
8054 | ||
8055 | Where 's' is a sign bit (0/1), 'n' and 'r' are integers such that | |
8056 | 16 <= n <= 31 and 0 <= r <= 7. | |
8057 | ||
8058 | These values are mapped onto an 8-bit integer ABCDEFGH s.t. | |
8059 | ||
8060 | - A (most-significant) is the sign bit. | |
8061 | - BCD are the exponent (encoded as r XOR 3). | |
8062 | - EFGH are the mantissa (encoded as n - 16). | |
8063 | */ | |
8064 | ||
8065 | /* Return an integer index for a VFPv3 immediate operand X suitable for the | |
8066 | fconst[sd] instruction, or -1 if X isn't suitable. */ | |
8067 | static int | |
8068 | vfp3_const_double_index (rtx x) | |
8069 | { | |
8070 | REAL_VALUE_TYPE r, m; | |
8071 | int sign, exponent; | |
8072 | unsigned HOST_WIDE_INT mantissa, mant_hi; | |
8073 | unsigned HOST_WIDE_INT mask; | |
8e39e9af | 8074 | HOST_WIDE_INT m1, m2; |
f1adb0a9 JB |
8075 | int point_pos = 2 * HOST_BITS_PER_WIDE_INT - 1; |
8076 | ||
8077 | if (!TARGET_VFP3 || GET_CODE (x) != CONST_DOUBLE) | |
8078 | return -1; | |
8079 | ||
8080 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); | |
8081 | ||
8082 | /* We can't represent these things, so detect them first. */ | |
8083 | if (REAL_VALUE_ISINF (r) || REAL_VALUE_ISNAN (r) || REAL_VALUE_MINUS_ZERO (r)) | |
8084 | return -1; | |
8085 | ||
8086 | /* Extract sign, exponent and mantissa. */ | |
8087 | sign = REAL_VALUE_NEGATIVE (r) ? 1 : 0; | |
d49b6e1e | 8088 | r = real_value_abs (&r); |
f1adb0a9 JB |
8089 | exponent = REAL_EXP (&r); |
8090 | /* For the mantissa, we expand into two HOST_WIDE_INTS, apart from the | |
8091 | highest (sign) bit, with a fixed binary point at bit point_pos. | |
8092 | WARNING: If there's ever a VFP version which uses more than 2 * H_W_I - 1 | |
8093 | bits for the mantissa, this may fail (low bits would be lost). */ | |
8094 | real_ldexp (&m, &r, point_pos - exponent); | |
8e39e9af RE |
8095 | REAL_VALUE_TO_INT (&m1, &m2, m); |
8096 | mantissa = m1; | |
8097 | mant_hi = m2; | |
f1adb0a9 JB |
8098 | |
8099 | /* If there are bits set in the low part of the mantissa, we can't | |
8100 | represent this value. */ | |
8101 | if (mantissa != 0) | |
8102 | return -1; | |
8103 | ||
8104 | /* Now make it so that mantissa contains the most-significant bits, and move | |
8105 | the point_pos to indicate that the least-significant bits have been | |
8106 | discarded. */ | |
8107 | point_pos -= HOST_BITS_PER_WIDE_INT; | |
8108 | mantissa = mant_hi; | |
8109 | ||
8110 | /* We can permit four significant bits of mantissa only, plus a high bit | |
8111 | which is always 1. */ | |
8112 | mask = ((unsigned HOST_WIDE_INT)1 << (point_pos - 5)) - 1; | |
8113 | if ((mantissa & mask) != 0) | |
8114 | return -1; | |
8115 | ||
8116 | /* Now we know the mantissa is in range, chop off the unneeded bits. */ | |
8117 | mantissa >>= point_pos - 5; | |
8118 | ||
8119 | /* The mantissa may be zero. Disallow that case. (It's possible to load the | |
8120 | floating-point immediate zero with Neon using an integer-zero load, but | |
8121 | that case is handled elsewhere.) */ | |
8122 | if (mantissa == 0) | |
8123 | return -1; | |
8124 | ||
8125 | gcc_assert (mantissa >= 16 && mantissa <= 31); | |
8126 | ||
8127 | /* The value of 5 here would be 4 if GCC used IEEE754-like encoding (where | |
6ed3da00 KH |
8128 | normalized significands are in the range [1, 2). (Our mantissa is shifted |
8129 | left 4 places at this point relative to normalized IEEE754 values). GCC | |
f1adb0a9 JB |
8130 | internally uses [0.5, 1) (see real.c), so the exponent returned from |
8131 | REAL_EXP must be altered. */ | |
8132 | exponent = 5 - exponent; | |
8133 | ||
8134 | if (exponent < 0 || exponent > 7) | |
8135 | return -1; | |
8136 | ||
8137 | /* Sign, mantissa and exponent are now in the correct form to plug into the | |
15dc95cb | 8138 | formula described in the comment above. */ |
f1adb0a9 JB |
8139 | return (sign << 7) | ((exponent ^ 3) << 4) | (mantissa - 16); |
8140 | } | |
8141 | ||
8142 | /* Return TRUE if rtx X is a valid immediate VFPv3 constant. */ | |
8143 | int | |
8144 | vfp3_const_double_rtx (rtx x) | |
8145 | { | |
8146 | if (!TARGET_VFP3) | |
8147 | return 0; | |
8148 | ||
8149 | return vfp3_const_double_index (x) != -1; | |
8150 | } | |
8151 | ||
88f77cba JB |
8152 | /* Recognize immediates which can be used in various Neon instructions. Legal |
8153 | immediates are described by the following table (for VMVN variants, the | |
8154 | bitwise inverse of the constant shown is recognized. In either case, VMOV | |
8155 | is output and the correct instruction to use for a given constant is chosen | |
8156 | by the assembler). The constant shown is replicated across all elements of | |
8157 | the destination vector. | |
8158 | ||
8159 | insn elems variant constant (binary) | |
8160 | ---- ----- ------- ----------------- | |
8161 | vmov i32 0 00000000 00000000 00000000 abcdefgh | |
8162 | vmov i32 1 00000000 00000000 abcdefgh 00000000 | |
8163 | vmov i32 2 00000000 abcdefgh 00000000 00000000 | |
8164 | vmov i32 3 abcdefgh 00000000 00000000 00000000 | |
8165 | vmov i16 4 00000000 abcdefgh | |
8166 | vmov i16 5 abcdefgh 00000000 | |
8167 | vmvn i32 6 00000000 00000000 00000000 abcdefgh | |
8168 | vmvn i32 7 00000000 00000000 abcdefgh 00000000 | |
8169 | vmvn i32 8 00000000 abcdefgh 00000000 00000000 | |
8170 | vmvn i32 9 abcdefgh 00000000 00000000 00000000 | |
8171 | vmvn i16 10 00000000 abcdefgh | |
8172 | vmvn i16 11 abcdefgh 00000000 | |
8173 | vmov i32 12 00000000 00000000 abcdefgh 11111111 | |
8174 | vmvn i32 13 00000000 00000000 abcdefgh 11111111 | |
8175 | vmov i32 14 00000000 abcdefgh 11111111 11111111 | |
8176 | vmvn i32 15 00000000 abcdefgh 11111111 11111111 | |
8177 | vmov i8 16 abcdefgh | |
8178 | vmov i64 17 aaaaaaaa bbbbbbbb cccccccc dddddddd | |
8179 | eeeeeeee ffffffff gggggggg hhhhhhhh | |
8180 | vmov f32 18 aBbbbbbc defgh000 00000000 00000000 | |
8181 | ||
8182 | For case 18, B = !b. Representable values are exactly those accepted by | |
8183 | vfp3_const_double_index, but are output as floating-point numbers rather | |
8184 | than indices. | |
8185 | ||
8186 | Variants 0-5 (inclusive) may also be used as immediates for the second | |
8187 | operand of VORR/VBIC instructions. | |
8188 | ||
8189 | The INVERSE argument causes the bitwise inverse of the given operand to be | |
8190 | recognized instead (used for recognizing legal immediates for the VAND/VORN | |
8191 | pseudo-instructions). If INVERSE is true, the value placed in *MODCONST is | |
8192 | *not* inverted (i.e. the pseudo-instruction forms vand/vorn should still be | |
8193 | output, rather than the real insns vbic/vorr). | |
8194 | ||
8195 | INVERSE makes no difference to the recognition of float vectors. | |
8196 | ||
8197 | The return value is the variant of immediate as shown in the above table, or | |
8198 | -1 if the given value doesn't match any of the listed patterns. | |
8199 | */ | |
8200 | static int | |
8201 | neon_valid_immediate (rtx op, enum machine_mode mode, int inverse, | |
8202 | rtx *modconst, int *elementwidth) | |
8203 | { | |
8204 | #define CHECK(STRIDE, ELSIZE, CLASS, TEST) \ | |
8205 | matches = 1; \ | |
8206 | for (i = 0; i < idx; i += (STRIDE)) \ | |
8207 | if (!(TEST)) \ | |
8208 | matches = 0; \ | |
8209 | if (matches) \ | |
8210 | { \ | |
8211 | immtype = (CLASS); \ | |
8212 | elsize = (ELSIZE); \ | |
8213 | break; \ | |
8214 | } | |
8215 | ||
ff128632 | 8216 | unsigned int i, elsize = 0, idx = 0, n_elts = CONST_VECTOR_NUNITS (op); |
88f77cba JB |
8217 | unsigned int innersize = GET_MODE_SIZE (GET_MODE_INNER (mode)); |
8218 | unsigned char bytes[16]; | |
8219 | int immtype = -1, matches; | |
8220 | unsigned int invmask = inverse ? 0xff : 0; | |
8221 | ||
8222 | /* Vectors of float constants. */ | |
8223 | if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT) | |
8224 | { | |
8225 | rtx el0 = CONST_VECTOR_ELT (op, 0); | |
8226 | REAL_VALUE_TYPE r0; | |
8227 | ||
8228 | if (!vfp3_const_double_rtx (el0)) | |
8229 | return -1; | |
8230 | ||
8231 | REAL_VALUE_FROM_CONST_DOUBLE (r0, el0); | |
8232 | ||
8233 | for (i = 1; i < n_elts; i++) | |
8234 | { | |
8235 | rtx elt = CONST_VECTOR_ELT (op, i); | |
8236 | REAL_VALUE_TYPE re; | |
8237 | ||
8238 | REAL_VALUE_FROM_CONST_DOUBLE (re, elt); | |
8239 | ||
8240 | if (!REAL_VALUES_EQUAL (r0, re)) | |
8241 | return -1; | |
8242 | } | |
8243 | ||
8244 | if (modconst) | |
8245 | *modconst = CONST_VECTOR_ELT (op, 0); | |
8246 | ||
8247 | if (elementwidth) | |
8248 | *elementwidth = 0; | |
8249 | ||
8250 | return 18; | |
8251 | } | |
8252 | ||
8253 | /* Splat vector constant out into a byte vector. */ | |
8254 | for (i = 0; i < n_elts; i++) | |
8255 | { | |
8256 | rtx el = CONST_VECTOR_ELT (op, i); | |
8257 | unsigned HOST_WIDE_INT elpart; | |
8258 | unsigned int part, parts; | |
8259 | ||
8260 | if (GET_CODE (el) == CONST_INT) | |
8261 | { | |
8262 | elpart = INTVAL (el); | |
8263 | parts = 1; | |
8264 | } | |
8265 | else if (GET_CODE (el) == CONST_DOUBLE) | |
8266 | { | |
8267 | elpart = CONST_DOUBLE_LOW (el); | |
8268 | parts = 2; | |
8269 | } | |
8270 | else | |
8271 | gcc_unreachable (); | |
8272 | ||
8273 | for (part = 0; part < parts; part++) | |
8274 | { | |
8275 | unsigned int byte; | |
8276 | for (byte = 0; byte < innersize; byte++) | |
8277 | { | |
8278 | bytes[idx++] = (elpart & 0xff) ^ invmask; | |
8279 | elpart >>= BITS_PER_UNIT; | |
8280 | } | |
8281 | if (GET_CODE (el) == CONST_DOUBLE) | |
8282 | elpart = CONST_DOUBLE_HIGH (el); | |
8283 | } | |
8284 | } | |
8285 | ||
8286 | /* Sanity check. */ | |
8287 | gcc_assert (idx == GET_MODE_SIZE (mode)); | |
8288 | ||
8289 | do | |
8290 | { | |
8291 | CHECK (4, 32, 0, bytes[i] == bytes[0] && bytes[i + 1] == 0 | |
8292 | && bytes[i + 2] == 0 && bytes[i + 3] == 0); | |
8293 | ||
8294 | CHECK (4, 32, 1, bytes[i] == 0 && bytes[i + 1] == bytes[1] | |
8295 | && bytes[i + 2] == 0 && bytes[i + 3] == 0); | |
8296 | ||
8297 | CHECK (4, 32, 2, bytes[i] == 0 && bytes[i + 1] == 0 | |
8298 | && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0); | |
8299 | ||
8300 | CHECK (4, 32, 3, bytes[i] == 0 && bytes[i + 1] == 0 | |
8301 | && bytes[i + 2] == 0 && bytes[i + 3] == bytes[3]); | |
8302 | ||
8303 | CHECK (2, 16, 4, bytes[i] == bytes[0] && bytes[i + 1] == 0); | |
8304 | ||
8305 | CHECK (2, 16, 5, bytes[i] == 0 && bytes[i + 1] == bytes[1]); | |
8306 | ||
8307 | CHECK (4, 32, 6, bytes[i] == bytes[0] && bytes[i + 1] == 0xff | |
8308 | && bytes[i + 2] == 0xff && bytes[i + 3] == 0xff); | |
8309 | ||
8310 | CHECK (4, 32, 7, bytes[i] == 0xff && bytes[i + 1] == bytes[1] | |
8311 | && bytes[i + 2] == 0xff && bytes[i + 3] == 0xff); | |
8312 | ||
8313 | CHECK (4, 32, 8, bytes[i] == 0xff && bytes[i + 1] == 0xff | |
8314 | && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0xff); | |
8315 | ||
8316 | CHECK (4, 32, 9, bytes[i] == 0xff && bytes[i + 1] == 0xff | |
8317 | && bytes[i + 2] == 0xff && bytes[i + 3] == bytes[3]); | |
8318 | ||
8319 | CHECK (2, 16, 10, bytes[i] == bytes[0] && bytes[i + 1] == 0xff); | |
8320 | ||
8321 | CHECK (2, 16, 11, bytes[i] == 0xff && bytes[i + 1] == bytes[1]); | |
8322 | ||
8323 | CHECK (4, 32, 12, bytes[i] == 0xff && bytes[i + 1] == bytes[1] | |
8324 | && bytes[i + 2] == 0 && bytes[i + 3] == 0); | |
8325 | ||
8326 | CHECK (4, 32, 13, bytes[i] == 0 && bytes[i + 1] == bytes[1] | |
8327 | && bytes[i + 2] == 0xff && bytes[i + 3] == 0xff); | |
8328 | ||
8329 | CHECK (4, 32, 14, bytes[i] == 0xff && bytes[i + 1] == 0xff | |
8330 | && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0); | |
8331 | ||
8332 | CHECK (4, 32, 15, bytes[i] == 0 && bytes[i + 1] == 0 | |
8333 | && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0xff); | |
8334 | ||
8335 | CHECK (1, 8, 16, bytes[i] == bytes[0]); | |
8336 | ||
8337 | CHECK (1, 64, 17, (bytes[i] == 0 || bytes[i] == 0xff) | |
8338 | && bytes[i] == bytes[(i + 8) % idx]); | |
8339 | } | |
8340 | while (0); | |
8341 | ||
8342 | if (immtype == -1) | |
8343 | return -1; | |
8344 | ||
8345 | if (elementwidth) | |
8346 | *elementwidth = elsize; | |
8347 | ||
8348 | if (modconst) | |
8349 | { | |
8350 | unsigned HOST_WIDE_INT imm = 0; | |
8351 | ||
cea618ac | 8352 | /* Un-invert bytes of recognized vector, if necessary. */ |
88f77cba JB |
8353 | if (invmask != 0) |
8354 | for (i = 0; i < idx; i++) | |
8355 | bytes[i] ^= invmask; | |
8356 | ||
8357 | if (immtype == 17) | |
8358 | { | |
8359 | /* FIXME: Broken on 32-bit H_W_I hosts. */ | |
8360 | gcc_assert (sizeof (HOST_WIDE_INT) == 8); | |
8361 | ||
8362 | for (i = 0; i < 8; i++) | |
8363 | imm |= (unsigned HOST_WIDE_INT) (bytes[i] ? 0xff : 0) | |
8364 | << (i * BITS_PER_UNIT); | |
8365 | ||
8366 | *modconst = GEN_INT (imm); | |
8367 | } | |
8368 | else | |
8369 | { | |
8370 | unsigned HOST_WIDE_INT imm = 0; | |
8371 | ||
8372 | for (i = 0; i < elsize / BITS_PER_UNIT; i++) | |
8373 | imm |= (unsigned HOST_WIDE_INT) bytes[i] << (i * BITS_PER_UNIT); | |
8374 | ||
8375 | *modconst = GEN_INT (imm); | |
8376 | } | |
8377 | } | |
8378 | ||
8379 | return immtype; | |
8380 | #undef CHECK | |
8381 | } | |
8382 | ||
8383 | /* Return TRUE if rtx X is legal for use as either a Neon VMOV (or, implicitly, | |
8384 | VMVN) immediate. Write back width per element to *ELEMENTWIDTH (or zero for | |
8385 | float elements), and a modified constant (whatever should be output for a | |
8386 | VMOV) in *MODCONST. */ | |
8387 | ||
8388 | int | |
8389 | neon_immediate_valid_for_move (rtx op, enum machine_mode mode, | |
8390 | rtx *modconst, int *elementwidth) | |
8391 | { | |
8392 | rtx tmpconst; | |
8393 | int tmpwidth; | |
8394 | int retval = neon_valid_immediate (op, mode, 0, &tmpconst, &tmpwidth); | |
8395 | ||
8396 | if (retval == -1) | |
8397 | return 0; | |
8398 | ||
8399 | if (modconst) | |
8400 | *modconst = tmpconst; | |
8401 | ||
8402 | if (elementwidth) | |
8403 | *elementwidth = tmpwidth; | |
8404 | ||
8405 | return 1; | |
8406 | } | |
8407 | ||
8408 | /* Return TRUE if rtx X is legal for use in a VORR or VBIC instruction. If | |
8409 | the immediate is valid, write a constant suitable for using as an operand | |
8410 | to VORR/VBIC/VAND/VORN to *MODCONST and the corresponding element width to | |
8411 | *ELEMENTWIDTH. See neon_valid_immediate for description of INVERSE. */ | |
8412 | ||
8413 | int | |
8414 | neon_immediate_valid_for_logic (rtx op, enum machine_mode mode, int inverse, | |
8415 | rtx *modconst, int *elementwidth) | |
8416 | { | |
8417 | rtx tmpconst; | |
8418 | int tmpwidth; | |
8419 | int retval = neon_valid_immediate (op, mode, inverse, &tmpconst, &tmpwidth); | |
8420 | ||
8421 | if (retval < 0 || retval > 5) | |
8422 | return 0; | |
8423 | ||
8424 | if (modconst) | |
8425 | *modconst = tmpconst; | |
8426 | ||
8427 | if (elementwidth) | |
8428 | *elementwidth = tmpwidth; | |
8429 | ||
8430 | return 1; | |
8431 | } | |
8432 | ||
8433 | /* Return a string suitable for output of Neon immediate logic operation | |
8434 | MNEM. */ | |
8435 | ||
8436 | char * | |
8437 | neon_output_logic_immediate (const char *mnem, rtx *op2, enum machine_mode mode, | |
8438 | int inverse, int quad) | |
8439 | { | |
8440 | int width, is_valid; | |
8441 | static char templ[40]; | |
8442 | ||
8443 | is_valid = neon_immediate_valid_for_logic (*op2, mode, inverse, op2, &width); | |
8444 | ||
8445 | gcc_assert (is_valid != 0); | |
8446 | ||
8447 | if (quad) | |
8448 | sprintf (templ, "%s.i%d\t%%q0, %%2", mnem, width); | |
8449 | else | |
8450 | sprintf (templ, "%s.i%d\t%%P0, %%2", mnem, width); | |
8451 | ||
8452 | return templ; | |
8453 | } | |
8454 | ||
8455 | /* Output a sequence of pairwise operations to implement a reduction. | |
8456 | NOTE: We do "too much work" here, because pairwise operations work on two | |
8457 | registers-worth of operands in one go. Unfortunately we can't exploit those | |
8458 | extra calculations to do the full operation in fewer steps, I don't think. | |
8459 | Although all vector elements of the result but the first are ignored, we | |
8460 | actually calculate the same result in each of the elements. An alternative | |
8461 | such as initially loading a vector with zero to use as each of the second | |
8462 | operands would use up an additional register and take an extra instruction, | |
8463 | for no particular gain. */ | |
8464 | ||
8465 | void | |
8466 | neon_pairwise_reduce (rtx op0, rtx op1, enum machine_mode mode, | |
8467 | rtx (*reduc) (rtx, rtx, rtx)) | |
8468 | { | |
8469 | enum machine_mode inner = GET_MODE_INNER (mode); | |
8470 | unsigned int i, parts = GET_MODE_SIZE (mode) / GET_MODE_SIZE (inner); | |
8471 | rtx tmpsum = op1; | |
8472 | ||
8473 | for (i = parts / 2; i >= 1; i /= 2) | |
8474 | { | |
8475 | rtx dest = (i == 1) ? op0 : gen_reg_rtx (mode); | |
8476 | emit_insn (reduc (dest, tmpsum, tmpsum)); | |
8477 | tmpsum = dest; | |
8478 | } | |
8479 | } | |
8480 | ||
814a4c3b DJ |
8481 | /* If VALS is a vector constant that can be loaded into a register |
8482 | using VDUP, generate instructions to do so and return an RTX to | |
8483 | assign to the register. Otherwise return NULL_RTX. */ | |
8484 | ||
8485 | static rtx | |
8486 | neon_vdup_constant (rtx vals) | |
8487 | { | |
8488 | enum machine_mode mode = GET_MODE (vals); | |
8489 | enum machine_mode inner_mode = GET_MODE_INNER (mode); | |
8490 | int n_elts = GET_MODE_NUNITS (mode); | |
8491 | bool all_same = true; | |
8492 | rtx x; | |
8493 | int i; | |
8494 | ||
8495 | if (GET_CODE (vals) != CONST_VECTOR || GET_MODE_SIZE (inner_mode) > 4) | |
8496 | return NULL_RTX; | |
8497 | ||
8498 | for (i = 0; i < n_elts; ++i) | |
8499 | { | |
8500 | x = XVECEXP (vals, 0, i); | |
8501 | if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0))) | |
8502 | all_same = false; | |
8503 | } | |
8504 | ||
8505 | if (!all_same) | |
8506 | /* The elements are not all the same. We could handle repeating | |
8507 | patterns of a mode larger than INNER_MODE here (e.g. int8x8_t | |
8508 | {0, C, 0, C, 0, C, 0, C} which can be loaded using | |
8509 | vdup.i16). */ | |
8510 | return NULL_RTX; | |
8511 | ||
8512 | /* We can load this constant by using VDUP and a constant in a | |
8513 | single ARM register. This will be cheaper than a vector | |
8514 | load. */ | |
8515 | ||
8516 | x = copy_to_mode_reg (inner_mode, XVECEXP (vals, 0, 0)); | |
a277dd9b | 8517 | return gen_rtx_VEC_DUPLICATE (mode, x); |
814a4c3b DJ |
8518 | } |
8519 | ||
8520 | /* Generate code to load VALS, which is a PARALLEL containing only | |
8521 | constants (for vec_init) or CONST_VECTOR, efficiently into a | |
8522 | register. Returns an RTX to copy into the register, or NULL_RTX | |
8523 | for a PARALLEL that can not be converted into a CONST_VECTOR. */ | |
8524 | ||
8525 | rtx | |
8526 | neon_make_constant (rtx vals) | |
8527 | { | |
8528 | enum machine_mode mode = GET_MODE (vals); | |
8529 | rtx target; | |
8530 | rtx const_vec = NULL_RTX; | |
8531 | int n_elts = GET_MODE_NUNITS (mode); | |
8532 | int n_const = 0; | |
8533 | int i; | |
8534 | ||
8535 | if (GET_CODE (vals) == CONST_VECTOR) | |
8536 | const_vec = vals; | |
8537 | else if (GET_CODE (vals) == PARALLEL) | |
8538 | { | |
8539 | /* A CONST_VECTOR must contain only CONST_INTs and | |
8540 | CONST_DOUBLEs, but CONSTANT_P allows more (e.g. SYMBOL_REF). | |
8541 | Only store valid constants in a CONST_VECTOR. */ | |
8542 | for (i = 0; i < n_elts; ++i) | |
8543 | { | |
8544 | rtx x = XVECEXP (vals, 0, i); | |
8545 | if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) | |
8546 | n_const++; | |
8547 | } | |
8548 | if (n_const == n_elts) | |
8549 | const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)); | |
8550 | } | |
8551 | else | |
8552 | gcc_unreachable (); | |
8553 | ||
8554 | if (const_vec != NULL | |
8555 | && neon_immediate_valid_for_move (const_vec, mode, NULL, NULL)) | |
8556 | /* Load using VMOV. On Cortex-A8 this takes one cycle. */ | |
8557 | return const_vec; | |
8558 | else if ((target = neon_vdup_constant (vals)) != NULL_RTX) | |
8559 | /* Loaded using VDUP. On Cortex-A8 the VDUP takes one NEON | |
8560 | pipeline cycle; creating the constant takes one or two ARM | |
8561 | pipeline cycles. */ | |
8562 | return target; | |
8563 | else if (const_vec != NULL_RTX) | |
8564 | /* Load from constant pool. On Cortex-A8 this takes two cycles | |
8565 | (for either double or quad vectors). We can not take advantage | |
8566 | of single-cycle VLD1 because we need a PC-relative addressing | |
8567 | mode. */ | |
8568 | return const_vec; | |
8569 | else | |
8570 | /* A PARALLEL containing something not valid inside CONST_VECTOR. | |
8571 | We can not construct an initializer. */ | |
8572 | return NULL_RTX; | |
8573 | } | |
8574 | ||
8575 | /* Initialize vector TARGET to VALS. */ | |
88f77cba JB |
8576 | |
8577 | void | |
8578 | neon_expand_vector_init (rtx target, rtx vals) | |
8579 | { | |
8580 | enum machine_mode mode = GET_MODE (target); | |
814a4c3b DJ |
8581 | enum machine_mode inner_mode = GET_MODE_INNER (mode); |
8582 | int n_elts = GET_MODE_NUNITS (mode); | |
8583 | int n_var = 0, one_var = -1; | |
8584 | bool all_same = true; | |
8585 | rtx x, mem; | |
8586 | int i; | |
88f77cba | 8587 | |
814a4c3b DJ |
8588 | for (i = 0; i < n_elts; ++i) |
8589 | { | |
8590 | x = XVECEXP (vals, 0, i); | |
8591 | if (!CONSTANT_P (x)) | |
8592 | ++n_var, one_var = i; | |
8593 | ||
8594 | if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0))) | |
8595 | all_same = false; | |
8596 | } | |
88f77cba | 8597 | |
814a4c3b DJ |
8598 | if (n_var == 0) |
8599 | { | |
8600 | rtx constant = neon_make_constant (vals); | |
8601 | if (constant != NULL_RTX) | |
8602 | { | |
8603 | emit_move_insn (target, constant); | |
8604 | return; | |
8605 | } | |
8606 | } | |
8607 | ||
8608 | /* Splat a single non-constant element if we can. */ | |
8609 | if (all_same && GET_MODE_SIZE (inner_mode) <= 4) | |
8610 | { | |
8611 | x = copy_to_mode_reg (inner_mode, XVECEXP (vals, 0, 0)); | |
8612 | emit_insn (gen_rtx_SET (VOIDmode, target, | |
a277dd9b | 8613 | gen_rtx_VEC_DUPLICATE (mode, x))); |
814a4c3b DJ |
8614 | return; |
8615 | } | |
8616 | ||
8617 | /* One field is non-constant. Load constant then overwrite varying | |
8618 | field. This is more efficient than using the stack. */ | |
8619 | if (n_var == 1) | |
8620 | { | |
8621 | rtx copy = copy_rtx (vals); | |
a277dd9b | 8622 | rtx index = GEN_INT (one_var); |
814a4c3b DJ |
8623 | |
8624 | /* Load constant part of vector, substitute neighboring value for | |
8625 | varying element. */ | |
8626 | XVECEXP (copy, 0, one_var) = XVECEXP (vals, 0, (one_var + 1) % n_elts); | |
8627 | neon_expand_vector_init (target, copy); | |
8628 | ||
8629 | /* Insert variable. */ | |
8630 | x = copy_to_mode_reg (inner_mode, XVECEXP (vals, 0, one_var)); | |
a277dd9b SL |
8631 | switch (mode) |
8632 | { | |
8633 | case V8QImode: | |
8634 | emit_insn (gen_neon_vset_lanev8qi (target, x, target, index)); | |
8635 | break; | |
8636 | case V16QImode: | |
8637 | emit_insn (gen_neon_vset_lanev16qi (target, x, target, index)); | |
8638 | break; | |
8639 | case V4HImode: | |
8640 | emit_insn (gen_neon_vset_lanev4hi (target, x, target, index)); | |
8641 | break; | |
8642 | case V8HImode: | |
8643 | emit_insn (gen_neon_vset_lanev8hi (target, x, target, index)); | |
8644 | break; | |
8645 | case V2SImode: | |
8646 | emit_insn (gen_neon_vset_lanev2si (target, x, target, index)); | |
8647 | break; | |
8648 | case V4SImode: | |
8649 | emit_insn (gen_neon_vset_lanev4si (target, x, target, index)); | |
8650 | break; | |
8651 | case V2SFmode: | |
8652 | emit_insn (gen_neon_vset_lanev2sf (target, x, target, index)); | |
8653 | break; | |
8654 | case V4SFmode: | |
8655 | emit_insn (gen_neon_vset_lanev4sf (target, x, target, index)); | |
8656 | break; | |
8657 | case V2DImode: | |
8658 | emit_insn (gen_neon_vset_lanev2di (target, x, target, index)); | |
8659 | break; | |
8660 | default: | |
8661 | gcc_unreachable (); | |
8662 | } | |
814a4c3b DJ |
8663 | return; |
8664 | } | |
8665 | ||
8666 | /* Construct the vector in memory one field at a time | |
8667 | and load the whole vector. */ | |
88f77cba JB |
8668 | mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0); |
8669 | for (i = 0; i < n_elts; i++) | |
814a4c3b DJ |
8670 | emit_move_insn (adjust_address_nv (mem, inner_mode, |
8671 | i * GET_MODE_SIZE (inner_mode)), | |
8672 | XVECEXP (vals, 0, i)); | |
88f77cba JB |
8673 | emit_move_insn (target, mem); |
8674 | } | |
8675 | ||
b617fc71 JB |
8676 | /* Ensure OPERAND lies between LOW (inclusive) and HIGH (exclusive). Raise |
8677 | ERR if it doesn't. FIXME: NEON bounds checks occur late in compilation, so | |
8678 | reported source locations are bogus. */ | |
8679 | ||
8680 | static void | |
8681 | bounds_check (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high, | |
8682 | const char *err) | |
8683 | { | |
8684 | HOST_WIDE_INT lane; | |
8685 | ||
8686 | gcc_assert (GET_CODE (operand) == CONST_INT); | |
8687 | ||
8688 | lane = INTVAL (operand); | |
8689 | ||
8690 | if (lane < low || lane >= high) | |
8691 | error (err); | |
8692 | } | |
8693 | ||
8694 | /* Bounds-check lanes. */ | |
8695 | ||
8696 | void | |
8697 | neon_lane_bounds (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high) | |
8698 | { | |
8699 | bounds_check (operand, low, high, "lane out of range"); | |
8700 | } | |
8701 | ||
8702 | /* Bounds-check constants. */ | |
8703 | ||
8704 | void | |
8705 | neon_const_bounds (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high) | |
8706 | { | |
8707 | bounds_check (operand, low, high, "constant out of range"); | |
8708 | } | |
8709 | ||
8710 | HOST_WIDE_INT | |
8711 | neon_element_bits (enum machine_mode mode) | |
8712 | { | |
8713 | if (mode == DImode) | |
8714 | return GET_MODE_BITSIZE (mode); | |
8715 | else | |
8716 | return GET_MODE_BITSIZE (GET_MODE_INNER (mode)); | |
8717 | } | |
8718 | ||
cce8749e CH |
8719 | \f |
8720 | /* Predicates for `match_operand' and `match_operator'. */ | |
8721 | ||
9b6b54e2 | 8722 | /* Return nonzero if OP is a valid Cirrus memory address pattern. */ |
9b6b54e2 | 8723 | int |
e32bac5b | 8724 | cirrus_memory_offset (rtx op) |
9b6b54e2 NC |
8725 | { |
8726 | /* Reject eliminable registers. */ | |
8727 | if (! (reload_in_progress || reload_completed) | |
8728 | && ( reg_mentioned_p (frame_pointer_rtx, op) | |
8729 | || reg_mentioned_p (arg_pointer_rtx, op) | |
8730 | || reg_mentioned_p (virtual_incoming_args_rtx, op) | |
8731 | || reg_mentioned_p (virtual_outgoing_args_rtx, op) | |
8732 | || reg_mentioned_p (virtual_stack_dynamic_rtx, op) | |
8733 | || reg_mentioned_p (virtual_stack_vars_rtx, op))) | |
8734 | return 0; | |
8735 | ||
8736 | if (GET_CODE (op) == MEM) | |
8737 | { | |
8738 | rtx ind; | |
8739 | ||
8740 | ind = XEXP (op, 0); | |
8741 | ||
8742 | /* Match: (mem (reg)). */ | |
8743 | if (GET_CODE (ind) == REG) | |
8744 | return 1; | |
8745 | ||
8746 | /* Match: | |
8747 | (mem (plus (reg) | |
8748 | (const))). */ | |
8749 | if (GET_CODE (ind) == PLUS | |
8750 | && GET_CODE (XEXP (ind, 0)) == REG | |
8751 | && REG_MODE_OK_FOR_BASE_P (XEXP (ind, 0), VOIDmode) | |
8752 | && GET_CODE (XEXP (ind, 1)) == CONST_INT) | |
8753 | return 1; | |
8754 | } | |
8755 | ||
8756 | return 0; | |
8757 | } | |
8758 | ||
f26b8ec9 | 8759 | /* Return TRUE if OP is a valid coprocessor memory address pattern. |
5b3e6663 PB |
8760 | WB is true if full writeback address modes are allowed and is false |
8761 | if limited writeback address modes (POST_INC and PRE_DEC) are | |
8762 | allowed. */ | |
9b66ebb1 PB |
8763 | |
8764 | int | |
fdd695fd | 8765 | arm_coproc_mem_operand (rtx op, bool wb) |
9b66ebb1 | 8766 | { |
fdd695fd | 8767 | rtx ind; |
9b66ebb1 | 8768 | |
fdd695fd | 8769 | /* Reject eliminable registers. */ |
9b66ebb1 PB |
8770 | if (! (reload_in_progress || reload_completed) |
8771 | && ( reg_mentioned_p (frame_pointer_rtx, op) | |
8772 | || reg_mentioned_p (arg_pointer_rtx, op) | |
8773 | || reg_mentioned_p (virtual_incoming_args_rtx, op) | |
8774 | || reg_mentioned_p (virtual_outgoing_args_rtx, op) | |
8775 | || reg_mentioned_p (virtual_stack_dynamic_rtx, op) | |
8776 | || reg_mentioned_p (virtual_stack_vars_rtx, op))) | |
8777 | return FALSE; | |
8778 | ||
59b9a953 | 8779 | /* Constants are converted into offsets from labels. */ |
fdd695fd PB |
8780 | if (GET_CODE (op) != MEM) |
8781 | return FALSE; | |
9b66ebb1 | 8782 | |
fdd695fd | 8783 | ind = XEXP (op, 0); |
9b66ebb1 | 8784 | |
fdd695fd PB |
8785 | if (reload_completed |
8786 | && (GET_CODE (ind) == LABEL_REF | |
8787 | || (GET_CODE (ind) == CONST | |
8788 | && GET_CODE (XEXP (ind, 0)) == PLUS | |
8789 | && GET_CODE (XEXP (XEXP (ind, 0), 0)) == LABEL_REF | |
8790 | && GET_CODE (XEXP (XEXP (ind, 0), 1)) == CONST_INT))) | |
8791 | return TRUE; | |
9b66ebb1 | 8792 | |
fdd695fd PB |
8793 | /* Match: (mem (reg)). */ |
8794 | if (GET_CODE (ind) == REG) | |
8795 | return arm_address_register_rtx_p (ind, 0); | |
8796 | ||
5b3e6663 PB |
8797 | /* Autoincremment addressing modes. POST_INC and PRE_DEC are |
8798 | acceptable in any case (subject to verification by | |
8799 | arm_address_register_rtx_p). We need WB to be true to accept | |
8800 | PRE_INC and POST_DEC. */ | |
8801 | if (GET_CODE (ind) == POST_INC | |
8802 | || GET_CODE (ind) == PRE_DEC | |
8803 | || (wb | |
8804 | && (GET_CODE (ind) == PRE_INC | |
8805 | || GET_CODE (ind) == POST_DEC))) | |
fdd695fd PB |
8806 | return arm_address_register_rtx_p (XEXP (ind, 0), 0); |
8807 | ||
8808 | if (wb | |
8809 | && (GET_CODE (ind) == POST_MODIFY || GET_CODE (ind) == PRE_MODIFY) | |
8810 | && arm_address_register_rtx_p (XEXP (ind, 0), 0) | |
8811 | && GET_CODE (XEXP (ind, 1)) == PLUS | |
8812 | && rtx_equal_p (XEXP (XEXP (ind, 1), 0), XEXP (ind, 0))) | |
8813 | ind = XEXP (ind, 1); | |
8814 | ||
8815 | /* Match: | |
8816 | (plus (reg) | |
8817 | (const)). */ | |
8818 | if (GET_CODE (ind) == PLUS | |
8819 | && GET_CODE (XEXP (ind, 0)) == REG | |
8820 | && REG_MODE_OK_FOR_BASE_P (XEXP (ind, 0), VOIDmode) | |
8821 | && GET_CODE (XEXP (ind, 1)) == CONST_INT | |
8822 | && INTVAL (XEXP (ind, 1)) > -1024 | |
8823 | && INTVAL (XEXP (ind, 1)) < 1024 | |
8824 | && (INTVAL (XEXP (ind, 1)) & 3) == 0) | |
8825 | return TRUE; | |
9b66ebb1 PB |
8826 | |
8827 | return FALSE; | |
8828 | } | |
8829 | ||
88f77cba | 8830 | /* Return TRUE if OP is a memory operand which we can load or store a vector |
dc34db56 PB |
8831 | to/from. TYPE is one of the following values: |
8832 | 0 - Vector load/stor (vldr) | |
8833 | 1 - Core registers (ldm) | |
8834 | 2 - Element/structure loads (vld1) | |
8835 | */ | |
88f77cba | 8836 | int |
dc34db56 | 8837 | neon_vector_mem_operand (rtx op, int type) |
88f77cba JB |
8838 | { |
8839 | rtx ind; | |
8840 | ||
8841 | /* Reject eliminable registers. */ | |
8842 | if (! (reload_in_progress || reload_completed) | |
8843 | && ( reg_mentioned_p (frame_pointer_rtx, op) | |
8844 | || reg_mentioned_p (arg_pointer_rtx, op) | |
8845 | || reg_mentioned_p (virtual_incoming_args_rtx, op) | |
8846 | || reg_mentioned_p (virtual_outgoing_args_rtx, op) | |
8847 | || reg_mentioned_p (virtual_stack_dynamic_rtx, op) | |
8848 | || reg_mentioned_p (virtual_stack_vars_rtx, op))) | |
8849 | return FALSE; | |
8850 | ||
8851 | /* Constants are converted into offsets from labels. */ | |
8852 | if (GET_CODE (op) != MEM) | |
8853 | return FALSE; | |
8854 | ||
8855 | ind = XEXP (op, 0); | |
8856 | ||
8857 | if (reload_completed | |
8858 | && (GET_CODE (ind) == LABEL_REF | |
8859 | || (GET_CODE (ind) == CONST | |
8860 | && GET_CODE (XEXP (ind, 0)) == PLUS | |
8861 | && GET_CODE (XEXP (XEXP (ind, 0), 0)) == LABEL_REF | |
8862 | && GET_CODE (XEXP (XEXP (ind, 0), 1)) == CONST_INT))) | |
8863 | return TRUE; | |
8864 | ||
8865 | /* Match: (mem (reg)). */ | |
8866 | if (GET_CODE (ind) == REG) | |
8867 | return arm_address_register_rtx_p (ind, 0); | |
8868 | ||
8869 | /* Allow post-increment with Neon registers. */ | |
c452684d JB |
8870 | if ((type != 1 && GET_CODE (ind) == POST_INC) |
8871 | || (type == 0 && GET_CODE (ind) == PRE_DEC)) | |
88f77cba JB |
8872 | return arm_address_register_rtx_p (XEXP (ind, 0), 0); |
8873 | ||
dc34db56 | 8874 | /* FIXME: vld1 allows register post-modify. */ |
88f77cba JB |
8875 | |
8876 | /* Match: | |
8877 | (plus (reg) | |
8878 | (const)). */ | |
dc34db56 | 8879 | if (type == 0 |
88f77cba JB |
8880 | && GET_CODE (ind) == PLUS |
8881 | && GET_CODE (XEXP (ind, 0)) == REG | |
8882 | && REG_MODE_OK_FOR_BASE_P (XEXP (ind, 0), VOIDmode) | |
8883 | && GET_CODE (XEXP (ind, 1)) == CONST_INT | |
8884 | && INTVAL (XEXP (ind, 1)) > -1024 | |
8885 | && INTVAL (XEXP (ind, 1)) < 1016 | |
8886 | && (INTVAL (XEXP (ind, 1)) & 3) == 0) | |
8887 | return TRUE; | |
8888 | ||
8889 | return FALSE; | |
8890 | } | |
8891 | ||
8892 | /* Return TRUE if OP is a mem suitable for loading/storing a Neon struct | |
8893 | type. */ | |
8894 | int | |
8895 | neon_struct_mem_operand (rtx op) | |
8896 | { | |
8897 | rtx ind; | |
8898 | ||
8899 | /* Reject eliminable registers. */ | |
8900 | if (! (reload_in_progress || reload_completed) | |
8901 | && ( reg_mentioned_p (frame_pointer_rtx, op) | |
8902 | || reg_mentioned_p (arg_pointer_rtx, op) | |
8903 | || reg_mentioned_p (virtual_incoming_args_rtx, op) | |
8904 | || reg_mentioned_p (virtual_outgoing_args_rtx, op) | |
8905 | || reg_mentioned_p (virtual_stack_dynamic_rtx, op) | |
8906 | || reg_mentioned_p (virtual_stack_vars_rtx, op))) | |
8907 | return FALSE; | |
8908 | ||
8909 | /* Constants are converted into offsets from labels. */ | |
8910 | if (GET_CODE (op) != MEM) | |
8911 | return FALSE; | |
8912 | ||
8913 | ind = XEXP (op, 0); | |
8914 | ||
8915 | if (reload_completed | |
8916 | && (GET_CODE (ind) == LABEL_REF | |
8917 | || (GET_CODE (ind) == CONST | |
8918 | && GET_CODE (XEXP (ind, 0)) == PLUS | |
8919 | && GET_CODE (XEXP (XEXP (ind, 0), 0)) == LABEL_REF | |
8920 | && GET_CODE (XEXP (XEXP (ind, 0), 1)) == CONST_INT))) | |
8921 | return TRUE; | |
8922 | ||
8923 | /* Match: (mem (reg)). */ | |
8924 | if (GET_CODE (ind) == REG) | |
8925 | return arm_address_register_rtx_p (ind, 0); | |
8926 | ||
8927 | return FALSE; | |
8928 | } | |
8929 | ||
6555b6bd RE |
8930 | /* Return true if X is a register that will be eliminated later on. */ |
8931 | int | |
8932 | arm_eliminable_register (rtx x) | |
8933 | { | |
8934 | return REG_P (x) && (REGNO (x) == FRAME_POINTER_REGNUM | |
8935 | || REGNO (x) == ARG_POINTER_REGNUM | |
8936 | || (REGNO (x) >= FIRST_VIRTUAL_REGISTER | |
8937 | && REGNO (x) <= LAST_VIRTUAL_REGISTER)); | |
8938 | } | |
9b66ebb1 | 8939 | |
9b66ebb1 | 8940 | /* Return GENERAL_REGS if a scratch register required to reload x to/from |
fe2d934b | 8941 | coprocessor registers. Otherwise return NO_REGS. */ |
9b66ebb1 PB |
8942 | |
8943 | enum reg_class | |
fe2d934b | 8944 | coproc_secondary_reload_class (enum machine_mode mode, rtx x, bool wb) |
9b66ebb1 | 8945 | { |
0fd8c3ad SL |
8946 | if (mode == HFmode) |
8947 | { | |
e0dc3601 PB |
8948 | if (!TARGET_NEON_FP16) |
8949 | return GENERAL_REGS; | |
0fd8c3ad SL |
8950 | if (s_register_operand (x, mode) || neon_vector_mem_operand (x, 2)) |
8951 | return NO_REGS; | |
8952 | return GENERAL_REGS; | |
8953 | } | |
8954 | ||
88f77cba JB |
8955 | if (TARGET_NEON |
8956 | && (GET_MODE_CLASS (mode) == MODE_VECTOR_INT | |
8957 | || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT) | |
dc34db56 | 8958 | && neon_vector_mem_operand (x, 0)) |
88f77cba JB |
8959 | return NO_REGS; |
8960 | ||
fe2d934b | 8961 | if (arm_coproc_mem_operand (x, wb) || s_register_operand (x, mode)) |
9b66ebb1 PB |
8962 | return NO_REGS; |
8963 | ||
8964 | return GENERAL_REGS; | |
8965 | } | |
8966 | ||
866af8a9 JB |
8967 | /* Values which must be returned in the most-significant end of the return |
8968 | register. */ | |
8969 | ||
8970 | static bool | |
586de218 | 8971 | arm_return_in_msb (const_tree valtype) |
866af8a9 JB |
8972 | { |
8973 | return (TARGET_AAPCS_BASED | |
8974 | && BYTES_BIG_ENDIAN | |
8975 | && (AGGREGATE_TYPE_P (valtype) | |
8976 | || TREE_CODE (valtype) == COMPLEX_TYPE)); | |
8977 | } | |
9b66ebb1 | 8978 | |
f0375c66 NC |
8979 | /* Returns TRUE if INSN is an "LDR REG, ADDR" instruction. |
8980 | Use by the Cirrus Maverick code which has to workaround | |
8981 | a hardware bug triggered by such instructions. */ | |
f0375c66 | 8982 | static bool |
e32bac5b | 8983 | arm_memory_load_p (rtx insn) |
9b6b54e2 NC |
8984 | { |
8985 | rtx body, lhs, rhs;; | |
8986 | ||
f0375c66 NC |
8987 | if (insn == NULL_RTX || GET_CODE (insn) != INSN) |
8988 | return false; | |
9b6b54e2 NC |
8989 | |
8990 | body = PATTERN (insn); | |
8991 | ||
8992 | if (GET_CODE (body) != SET) | |
f0375c66 | 8993 | return false; |
9b6b54e2 NC |
8994 | |
8995 | lhs = XEXP (body, 0); | |
8996 | rhs = XEXP (body, 1); | |
8997 | ||
f0375c66 NC |
8998 | lhs = REG_OR_SUBREG_RTX (lhs); |
8999 | ||
9000 | /* If the destination is not a general purpose | |
9001 | register we do not have to worry. */ | |
9002 | if (GET_CODE (lhs) != REG | |
9003 | || REGNO_REG_CLASS (REGNO (lhs)) != GENERAL_REGS) | |
9004 | return false; | |
9005 | ||
9006 | /* As well as loads from memory we also have to react | |
9007 | to loads of invalid constants which will be turned | |
9008 | into loads from the minipool. */ | |
9009 | return (GET_CODE (rhs) == MEM | |
9010 | || GET_CODE (rhs) == SYMBOL_REF | |
9011 | || note_invalid_constants (insn, -1, false)); | |
9b6b54e2 NC |
9012 | } |
9013 | ||
f0375c66 | 9014 | /* Return TRUE if INSN is a Cirrus instruction. */ |
f0375c66 | 9015 | static bool |
e32bac5b | 9016 | arm_cirrus_insn_p (rtx insn) |
9b6b54e2 NC |
9017 | { |
9018 | enum attr_cirrus attr; | |
9019 | ||
e6d29d15 | 9020 | /* get_attr cannot accept USE or CLOBBER. */ |
9b6b54e2 NC |
9021 | if (!insn |
9022 | || GET_CODE (insn) != INSN | |
9023 | || GET_CODE (PATTERN (insn)) == USE | |
9024 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
9025 | return 0; | |
9026 | ||
9027 | attr = get_attr_cirrus (insn); | |
9028 | ||
f0375c66 | 9029 | return attr != CIRRUS_NOT; |
9b6b54e2 NC |
9030 | } |
9031 | ||
9032 | /* Cirrus reorg for invalid instruction combinations. */ | |
9b6b54e2 | 9033 | static void |
e32bac5b | 9034 | cirrus_reorg (rtx first) |
9b6b54e2 NC |
9035 | { |
9036 | enum attr_cirrus attr; | |
9037 | rtx body = PATTERN (first); | |
9038 | rtx t; | |
9039 | int nops; | |
9040 | ||
9041 | /* Any branch must be followed by 2 non Cirrus instructions. */ | |
9042 | if (GET_CODE (first) == JUMP_INSN && GET_CODE (body) != RETURN) | |
9043 | { | |
9044 | nops = 0; | |
9045 | t = next_nonnote_insn (first); | |
9046 | ||
f0375c66 | 9047 | if (arm_cirrus_insn_p (t)) |
9b6b54e2 NC |
9048 | ++ nops; |
9049 | ||
f0375c66 | 9050 | if (arm_cirrus_insn_p (next_nonnote_insn (t))) |
9b6b54e2 NC |
9051 | ++ nops; |
9052 | ||
9053 | while (nops --) | |
9054 | emit_insn_after (gen_nop (), first); | |
9055 | ||
9056 | return; | |
9057 | } | |
9058 | ||
9059 | /* (float (blah)) is in parallel with a clobber. */ | |
9060 | if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0) | |
9061 | body = XVECEXP (body, 0, 0); | |
9062 | ||
9063 | if (GET_CODE (body) == SET) | |
9064 | { | |
9065 | rtx lhs = XEXP (body, 0), rhs = XEXP (body, 1); | |
9066 | ||
9067 | /* cfldrd, cfldr64, cfstrd, cfstr64 must | |
9068 | be followed by a non Cirrus insn. */ | |
9069 | if (get_attr_cirrus (first) == CIRRUS_DOUBLE) | |
9070 | { | |
f0375c66 | 9071 | if (arm_cirrus_insn_p (next_nonnote_insn (first))) |
9b6b54e2 NC |
9072 | emit_insn_after (gen_nop (), first); |
9073 | ||
9074 | return; | |
9075 | } | |
f0375c66 | 9076 | else if (arm_memory_load_p (first)) |
9b6b54e2 NC |
9077 | { |
9078 | unsigned int arm_regno; | |
9079 | ||
9080 | /* Any ldr/cfmvdlr, ldr/cfmvdhr, ldr/cfmvsr, ldr/cfmv64lr, | |
9081 | ldr/cfmv64hr combination where the Rd field is the same | |
9082 | in both instructions must be split with a non Cirrus | |
9083 | insn. Example: | |
9084 | ||
9085 | ldr r0, blah | |
9086 | nop | |
9087 | cfmvsr mvf0, r0. */ | |
9088 | ||
9089 | /* Get Arm register number for ldr insn. */ | |
9090 | if (GET_CODE (lhs) == REG) | |
9091 | arm_regno = REGNO (lhs); | |
9b6b54e2 | 9092 | else |
e6d29d15 NS |
9093 | { |
9094 | gcc_assert (GET_CODE (rhs) == REG); | |
9095 | arm_regno = REGNO (rhs); | |
9096 | } | |
9b6b54e2 NC |
9097 | |
9098 | /* Next insn. */ | |
9099 | first = next_nonnote_insn (first); | |
9100 | ||
f0375c66 | 9101 | if (! arm_cirrus_insn_p (first)) |
9b6b54e2 NC |
9102 | return; |
9103 | ||
9104 | body = PATTERN (first); | |
9105 | ||
9106 | /* (float (blah)) is in parallel with a clobber. */ | |
9107 | if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0)) | |
9108 | body = XVECEXP (body, 0, 0); | |
9109 | ||
9110 | if (GET_CODE (body) == FLOAT) | |
9111 | body = XEXP (body, 0); | |
9112 | ||
9113 | if (get_attr_cirrus (first) == CIRRUS_MOVE | |
9114 | && GET_CODE (XEXP (body, 1)) == REG | |
9115 | && arm_regno == REGNO (XEXP (body, 1))) | |
9116 | emit_insn_after (gen_nop (), first); | |
9117 | ||
9118 | return; | |
9119 | } | |
9120 | } | |
9121 | ||
e6d29d15 | 9122 | /* get_attr cannot accept USE or CLOBBER. */ |
9b6b54e2 NC |
9123 | if (!first |
9124 | || GET_CODE (first) != INSN | |
9125 | || GET_CODE (PATTERN (first)) == USE | |
9126 | || GET_CODE (PATTERN (first)) == CLOBBER) | |
9127 | return; | |
9128 | ||
9129 | attr = get_attr_cirrus (first); | |
9130 | ||
9131 | /* Any coprocessor compare instruction (cfcmps, cfcmpd, ...) | |
9132 | must be followed by a non-coprocessor instruction. */ | |
9133 | if (attr == CIRRUS_COMPARE) | |
9134 | { | |
9135 | nops = 0; | |
9136 | ||
9137 | t = next_nonnote_insn (first); | |
9138 | ||
f0375c66 | 9139 | if (arm_cirrus_insn_p (t)) |
9b6b54e2 NC |
9140 | ++ nops; |
9141 | ||
f0375c66 | 9142 | if (arm_cirrus_insn_p (next_nonnote_insn (t))) |
9b6b54e2 NC |
9143 | ++ nops; |
9144 | ||
9145 | while (nops --) | |
9146 | emit_insn_after (gen_nop (), first); | |
9147 | ||
9148 | return; | |
9149 | } | |
9150 | } | |
9151 | ||
2b835d68 RE |
9152 | /* Return TRUE if X references a SYMBOL_REF. */ |
9153 | int | |
e32bac5b | 9154 | symbol_mentioned_p (rtx x) |
2b835d68 | 9155 | { |
1d6e90ac NC |
9156 | const char * fmt; |
9157 | int i; | |
2b835d68 RE |
9158 | |
9159 | if (GET_CODE (x) == SYMBOL_REF) | |
9160 | return 1; | |
9161 | ||
d3585b76 DJ |
9162 | /* UNSPEC_TLS entries for a symbol include the SYMBOL_REF, but they |
9163 | are constant offsets, not symbols. */ | |
9164 | if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS) | |
9165 | return 0; | |
9166 | ||
2b835d68 | 9167 | fmt = GET_RTX_FORMAT (GET_CODE (x)); |
f676971a | 9168 | |
2b835d68 RE |
9169 | for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) |
9170 | { | |
9171 | if (fmt[i] == 'E') | |
9172 | { | |
1d6e90ac | 9173 | int j; |
2b835d68 RE |
9174 | |
9175 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) | |
9176 | if (symbol_mentioned_p (XVECEXP (x, i, j))) | |
9177 | return 1; | |
9178 | } | |
9179 | else if (fmt[i] == 'e' && symbol_mentioned_p (XEXP (x, i))) | |
9180 | return 1; | |
9181 | } | |
9182 | ||
9183 | return 0; | |
9184 | } | |
9185 | ||
9186 | /* Return TRUE if X references a LABEL_REF. */ | |
9187 | int | |
e32bac5b | 9188 | label_mentioned_p (rtx x) |
2b835d68 | 9189 | { |
1d6e90ac NC |
9190 | const char * fmt; |
9191 | int i; | |
2b835d68 RE |
9192 | |
9193 | if (GET_CODE (x) == LABEL_REF) | |
9194 | return 1; | |
9195 | ||
d3585b76 DJ |
9196 | /* UNSPEC_TLS entries for a symbol include a LABEL_REF for the referencing |
9197 | instruction, but they are constant offsets, not symbols. */ | |
9198 | if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS) | |
9199 | return 0; | |
9200 | ||
2b835d68 RE |
9201 | fmt = GET_RTX_FORMAT (GET_CODE (x)); |
9202 | for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) | |
9203 | { | |
9204 | if (fmt[i] == 'E') | |
9205 | { | |
1d6e90ac | 9206 | int j; |
2b835d68 RE |
9207 | |
9208 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) | |
9209 | if (label_mentioned_p (XVECEXP (x, i, j))) | |
9210 | return 1; | |
9211 | } | |
9212 | else if (fmt[i] == 'e' && label_mentioned_p (XEXP (x, i))) | |
9213 | return 1; | |
9214 | } | |
9215 | ||
9216 | return 0; | |
9217 | } | |
9218 | ||
d3585b76 DJ |
9219 | int |
9220 | tls_mentioned_p (rtx x) | |
9221 | { | |
9222 | switch (GET_CODE (x)) | |
9223 | { | |
9224 | case CONST: | |
9225 | return tls_mentioned_p (XEXP (x, 0)); | |
9226 | ||
9227 | case UNSPEC: | |
9228 | if (XINT (x, 1) == UNSPEC_TLS) | |
9229 | return 1; | |
9230 | ||
9231 | default: | |
9232 | return 0; | |
9233 | } | |
9234 | } | |
9235 | ||
2e5505a4 RE |
9236 | /* Must not copy any rtx that uses a pc-relative address. */ |
9237 | ||
9238 | static int | |
9239 | arm_note_pic_base (rtx *x, void *date ATTRIBUTE_UNUSED) | |
9240 | { | |
9241 | if (GET_CODE (*x) == UNSPEC | |
9242 | && XINT (*x, 1) == UNSPEC_PIC_BASE) | |
9243 | return 1; | |
9244 | return 0; | |
9245 | } | |
d3585b76 DJ |
9246 | |
9247 | static bool | |
9248 | arm_cannot_copy_insn_p (rtx insn) | |
9249 | { | |
2e5505a4 | 9250 | return for_each_rtx (&PATTERN (insn), arm_note_pic_base, NULL); |
d3585b76 DJ |
9251 | } |
9252 | ||
ff9940b0 | 9253 | enum rtx_code |
e32bac5b | 9254 | minmax_code (rtx x) |
ff9940b0 RE |
9255 | { |
9256 | enum rtx_code code = GET_CODE (x); | |
9257 | ||
e6d29d15 NS |
9258 | switch (code) |
9259 | { | |
9260 | case SMAX: | |
9261 | return GE; | |
9262 | case SMIN: | |
9263 | return LE; | |
9264 | case UMIN: | |
9265 | return LEU; | |
9266 | case UMAX: | |
9267 | return GEU; | |
9268 | default: | |
9269 | gcc_unreachable (); | |
9270 | } | |
ff9940b0 RE |
9271 | } |
9272 | ||
6354dc9b | 9273 | /* Return 1 if memory locations are adjacent. */ |
f3bb6135 | 9274 | int |
e32bac5b | 9275 | adjacent_mem_locations (rtx a, rtx b) |
ff9940b0 | 9276 | { |
15b5c4c1 RE |
9277 | /* We don't guarantee to preserve the order of these memory refs. */ |
9278 | if (volatile_refs_p (a) || volatile_refs_p (b)) | |
9279 | return 0; | |
9280 | ||
ff9940b0 RE |
9281 | if ((GET_CODE (XEXP (a, 0)) == REG |
9282 | || (GET_CODE (XEXP (a, 0)) == PLUS | |
9283 | && GET_CODE (XEXP (XEXP (a, 0), 1)) == CONST_INT)) | |
9284 | && (GET_CODE (XEXP (b, 0)) == REG | |
9285 | || (GET_CODE (XEXP (b, 0)) == PLUS | |
9286 | && GET_CODE (XEXP (XEXP (b, 0), 1)) == CONST_INT))) | |
9287 | { | |
6555b6bd RE |
9288 | HOST_WIDE_INT val0 = 0, val1 = 0; |
9289 | rtx reg0, reg1; | |
9290 | int val_diff; | |
f676971a | 9291 | |
ff9940b0 RE |
9292 | if (GET_CODE (XEXP (a, 0)) == PLUS) |
9293 | { | |
6555b6bd | 9294 | reg0 = XEXP (XEXP (a, 0), 0); |
ff9940b0 RE |
9295 | val0 = INTVAL (XEXP (XEXP (a, 0), 1)); |
9296 | } | |
9297 | else | |
6555b6bd | 9298 | reg0 = XEXP (a, 0); |
1d6e90ac | 9299 | |
ff9940b0 RE |
9300 | if (GET_CODE (XEXP (b, 0)) == PLUS) |
9301 | { | |
6555b6bd | 9302 | reg1 = XEXP (XEXP (b, 0), 0); |
ff9940b0 RE |
9303 | val1 = INTVAL (XEXP (XEXP (b, 0), 1)); |
9304 | } | |
9305 | else | |
6555b6bd | 9306 | reg1 = XEXP (b, 0); |
1d6e90ac | 9307 | |
e32bac5b RE |
9308 | /* Don't accept any offset that will require multiple |
9309 | instructions to handle, since this would cause the | |
9310 | arith_adjacentmem pattern to output an overlong sequence. */ | |
bbbbb16a | 9311 | if (!const_ok_for_op (val0, PLUS) || !const_ok_for_op (val1, PLUS)) |
c75a3ddc | 9312 | return 0; |
f676971a | 9313 | |
6555b6bd RE |
9314 | /* Don't allow an eliminable register: register elimination can make |
9315 | the offset too large. */ | |
9316 | if (arm_eliminable_register (reg0)) | |
9317 | return 0; | |
9318 | ||
9319 | val_diff = val1 - val0; | |
15b5c4c1 RE |
9320 | |
9321 | if (arm_ld_sched) | |
9322 | { | |
9323 | /* If the target has load delay slots, then there's no benefit | |
9324 | to using an ldm instruction unless the offset is zero and | |
9325 | we are optimizing for size. */ | |
9326 | return (optimize_size && (REGNO (reg0) == REGNO (reg1)) | |
9327 | && (val0 == 0 || val1 == 0 || val0 == 4 || val1 == 4) | |
9328 | && (val_diff == 4 || val_diff == -4)); | |
9329 | } | |
9330 | ||
6555b6bd RE |
9331 | return ((REGNO (reg0) == REGNO (reg1)) |
9332 | && (val_diff == 4 || val_diff == -4)); | |
ff9940b0 | 9333 | } |
6555b6bd | 9334 | |
ff9940b0 RE |
9335 | return 0; |
9336 | } | |
9337 | ||
93b338c3 BS |
9338 | /* Return true iff it would be profitable to turn a sequence of NOPS loads |
9339 | or stores (depending on IS_STORE) into a load-multiple or store-multiple | |
9340 | instruction. ADD_OFFSET is nonzero if the base address register needs | |
9341 | to be modified with an add instruction before we can use it. */ | |
9342 | ||
9343 | static bool | |
9344 | multiple_operation_profitable_p (bool is_store ATTRIBUTE_UNUSED, | |
9345 | int nops, HOST_WIDE_INT add_offset) | |
9346 | { | |
9347 | /* For ARM8,9 & StrongARM, 2 ldr instructions are faster than an ldm | |
9348 | if the offset isn't small enough. The reason 2 ldrs are faster | |
9349 | is because these ARMs are able to do more than one cache access | |
9350 | in a single cycle. The ARM9 and StrongARM have Harvard caches, | |
9351 | whilst the ARM8 has a double bandwidth cache. This means that | |
9352 | these cores can do both an instruction fetch and a data fetch in | |
9353 | a single cycle, so the trick of calculating the address into a | |
9354 | scratch register (one of the result regs) and then doing a load | |
9355 | multiple actually becomes slower (and no smaller in code size). | |
9356 | That is the transformation | |
9357 | ||
9358 | ldr rd1, [rbase + offset] | |
9359 | ldr rd2, [rbase + offset + 4] | |
9360 | ||
9361 | to | |
9362 | ||
9363 | add rd1, rbase, offset | |
9364 | ldmia rd1, {rd1, rd2} | |
9365 | ||
9366 | produces worse code -- '3 cycles + any stalls on rd2' instead of | |
9367 | '2 cycles + any stalls on rd2'. On ARMs with only one cache | |
9368 | access per cycle, the first sequence could never complete in less | |
9369 | than 6 cycles, whereas the ldm sequence would only take 5 and | |
9370 | would make better use of sequential accesses if not hitting the | |
9371 | cache. | |
9372 | ||
9373 | We cheat here and test 'arm_ld_sched' which we currently know to | |
9374 | only be true for the ARM8, ARM9 and StrongARM. If this ever | |
9375 | changes, then the test below needs to be reworked. */ | |
9376 | if (nops == 2 && arm_ld_sched && add_offset != 0) | |
9377 | return false; | |
9378 | ||
8f4c6e28 BS |
9379 | /* XScale has load-store double instructions, but they have stricter |
9380 | alignment requirements than load-store multiple, so we cannot | |
9381 | use them. | |
9382 | ||
9383 | For XScale ldm requires 2 + NREGS cycles to complete and blocks | |
9384 | the pipeline until completion. | |
9385 | ||
9386 | NREGS CYCLES | |
9387 | 1 3 | |
9388 | 2 4 | |
9389 | 3 5 | |
9390 | 4 6 | |
9391 | ||
9392 | An ldr instruction takes 1-3 cycles, but does not block the | |
9393 | pipeline. | |
9394 | ||
9395 | NREGS CYCLES | |
9396 | 1 1-3 | |
9397 | 2 2-6 | |
9398 | 3 3-9 | |
9399 | 4 4-12 | |
9400 | ||
9401 | Best case ldr will always win. However, the more ldr instructions | |
9402 | we issue, the less likely we are to be able to schedule them well. | |
9403 | Using ldr instructions also increases code size. | |
9404 | ||
9405 | As a compromise, we use ldr for counts of 1 or 2 regs, and ldm | |
9406 | for counts of 3 or 4 regs. */ | |
9407 | if (nops <= 2 && arm_tune_xscale && !optimize_size) | |
9408 | return false; | |
93b338c3 BS |
9409 | return true; |
9410 | } | |
9411 | ||
9412 | /* Subroutine of load_multiple_sequence and store_multiple_sequence. | |
9413 | Given an array of UNSORTED_OFFSETS, of which there are NOPS, compute | |
9414 | an array ORDER which describes the sequence to use when accessing the | |
9415 | offsets that produces an ascending order. In this sequence, each | |
9416 | offset must be larger by exactly 4 than the previous one. ORDER[0] | |
9417 | must have been filled in with the lowest offset by the caller. | |
9418 | If UNSORTED_REGS is nonnull, it is an array of register numbers that | |
9419 | we use to verify that ORDER produces an ascending order of registers. | |
9420 | Return true if it was possible to construct such an order, false if | |
9421 | not. */ | |
9422 | ||
9423 | static bool | |
9424 | compute_offset_order (int nops, HOST_WIDE_INT *unsorted_offsets, int *order, | |
9425 | int *unsorted_regs) | |
9426 | { | |
9427 | int i; | |
9428 | for (i = 1; i < nops; i++) | |
9429 | { | |
9430 | int j; | |
9431 | ||
9432 | order[i] = order[i - 1]; | |
9433 | for (j = 0; j < nops; j++) | |
9434 | if (unsorted_offsets[j] == unsorted_offsets[order[i - 1]] + 4) | |
9435 | { | |
9436 | /* We must find exactly one offset that is higher than the | |
9437 | previous one by 4. */ | |
9438 | if (order[i] != order[i - 1]) | |
9439 | return false; | |
9440 | order[i] = j; | |
9441 | } | |
9442 | if (order[i] == order[i - 1]) | |
9443 | return false; | |
9444 | /* The register numbers must be ascending. */ | |
9445 | if (unsorted_regs != NULL | |
9446 | && unsorted_regs[order[i]] <= unsorted_regs[order[i - 1]]) | |
9447 | return false; | |
9448 | } | |
9449 | return true; | |
9450 | } | |
9451 | ||
37119410 BS |
9452 | /* Used to determine in a peephole whether a sequence of load |
9453 | instructions can be changed into a load-multiple instruction. | |
9454 | NOPS is the number of separate load instructions we are examining. The | |
9455 | first NOPS entries in OPERANDS are the destination registers, the | |
9456 | next NOPS entries are memory operands. If this function is | |
9457 | successful, *BASE is set to the common base register of the memory | |
9458 | accesses; *LOAD_OFFSET is set to the first memory location's offset | |
9459 | from that base register. | |
9460 | REGS is an array filled in with the destination register numbers. | |
9461 | SAVED_ORDER (if nonnull), is an array filled in with an order that maps | |
9462 | insn numbers to to an ascending order of stores. If CHECK_REGS is true, | |
9463 | the sequence of registers in REGS matches the loads from ascending memory | |
9464 | locations, and the function verifies that the register numbers are | |
9465 | themselves ascending. If CHECK_REGS is false, the register numbers | |
9466 | are stored in the order they are found in the operands. */ | |
9467 | static int | |
9468 | load_multiple_sequence (rtx *operands, int nops, int *regs, int *saved_order, | |
9469 | int *base, HOST_WIDE_INT *load_offset, bool check_regs) | |
84ed5e79 | 9470 | { |
93b338c3 BS |
9471 | int unsorted_regs[MAX_LDM_STM_OPS]; |
9472 | HOST_WIDE_INT unsorted_offsets[MAX_LDM_STM_OPS]; | |
9473 | int order[MAX_LDM_STM_OPS]; | |
37119410 | 9474 | rtx base_reg_rtx = NULL; |
ad076f4e | 9475 | int base_reg = -1; |
93b338c3 | 9476 | int i, ldm_case; |
84ed5e79 | 9477 | |
93b338c3 BS |
9478 | /* Can only handle up to MAX_LDM_STM_OPS insns at present, though could be |
9479 | easily extended if required. */ | |
9480 | gcc_assert (nops >= 2 && nops <= MAX_LDM_STM_OPS); | |
84ed5e79 | 9481 | |
93b338c3 | 9482 | memset (order, 0, MAX_LDM_STM_OPS * sizeof (int)); |
f0b4bdd5 | 9483 | |
84ed5e79 | 9484 | /* Loop over the operands and check that the memory references are |
112cdef5 | 9485 | suitable (i.e. immediate offsets from the same base register). At |
84ed5e79 RE |
9486 | the same time, extract the target register, and the memory |
9487 | offsets. */ | |
9488 | for (i = 0; i < nops; i++) | |
9489 | { | |
9490 | rtx reg; | |
9491 | rtx offset; | |
9492 | ||
56636818 JL |
9493 | /* Convert a subreg of a mem into the mem itself. */ |
9494 | if (GET_CODE (operands[nops + i]) == SUBREG) | |
4e26a7af | 9495 | operands[nops + i] = alter_subreg (operands + (nops + i)); |
56636818 | 9496 | |
e6d29d15 | 9497 | gcc_assert (GET_CODE (operands[nops + i]) == MEM); |
84ed5e79 RE |
9498 | |
9499 | /* Don't reorder volatile memory references; it doesn't seem worth | |
9500 | looking for the case where the order is ok anyway. */ | |
9501 | if (MEM_VOLATILE_P (operands[nops + i])) | |
9502 | return 0; | |
9503 | ||
9504 | offset = const0_rtx; | |
9505 | ||
9506 | if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG | |
9507 | || (GET_CODE (reg) == SUBREG | |
9508 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
9509 | || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS | |
9510 | && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0)) | |
9511 | == REG) | |
9512 | || (GET_CODE (reg) == SUBREG | |
9513 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
9514 | && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1)) | |
9515 | == CONST_INT))) | |
9516 | { | |
9517 | if (i == 0) | |
84ed5e79 | 9518 | { |
37119410 BS |
9519 | base_reg = REGNO (reg); |
9520 | base_reg_rtx = reg; | |
9521 | if (TARGET_THUMB1 && base_reg > LAST_LO_REGNUM) | |
84ed5e79 | 9522 | return 0; |
84ed5e79 | 9523 | } |
37119410 BS |
9524 | else if (base_reg != (int) REGNO (reg)) |
9525 | /* Not addressed from the same base register. */ | |
9526 | return 0; | |
9527 | ||
93b338c3 BS |
9528 | unsorted_regs[i] = (GET_CODE (operands[i]) == REG |
9529 | ? REGNO (operands[i]) | |
9530 | : REGNO (SUBREG_REG (operands[i]))); | |
84ed5e79 RE |
9531 | |
9532 | /* If it isn't an integer register, or if it overwrites the | |
9533 | base register but isn't the last insn in the list, then | |
9534 | we can't do this. */ | |
37119410 BS |
9535 | if (unsorted_regs[i] < 0 |
9536 | || (TARGET_THUMB1 && unsorted_regs[i] > LAST_LO_REGNUM) | |
9537 | || unsorted_regs[i] > 14 | |
84ed5e79 RE |
9538 | || (i != nops - 1 && unsorted_regs[i] == base_reg)) |
9539 | return 0; | |
9540 | ||
9541 | unsorted_offsets[i] = INTVAL (offset); | |
93b338c3 BS |
9542 | if (i == 0 || unsorted_offsets[i] < unsorted_offsets[order[0]]) |
9543 | order[0] = i; | |
84ed5e79 RE |
9544 | } |
9545 | else | |
9546 | /* Not a suitable memory address. */ | |
9547 | return 0; | |
9548 | } | |
9549 | ||
9550 | /* All the useful information has now been extracted from the | |
9551 | operands into unsorted_regs and unsorted_offsets; additionally, | |
93b338c3 BS |
9552 | order[0] has been set to the lowest offset in the list. Sort |
9553 | the offsets into order, verifying that they are adjacent, and | |
9554 | check that the register numbers are ascending. */ | |
37119410 BS |
9555 | if (!compute_offset_order (nops, unsorted_offsets, order, |
9556 | check_regs ? unsorted_regs : NULL)) | |
93b338c3 | 9557 | return 0; |
84ed5e79 | 9558 | |
37119410 BS |
9559 | if (saved_order) |
9560 | memcpy (saved_order, order, sizeof order); | |
9561 | ||
84ed5e79 RE |
9562 | if (base) |
9563 | { | |
9564 | *base = base_reg; | |
9565 | ||
9566 | for (i = 0; i < nops; i++) | |
37119410 | 9567 | regs[i] = unsorted_regs[check_regs ? order[i] : i]; |
84ed5e79 RE |
9568 | |
9569 | *load_offset = unsorted_offsets[order[0]]; | |
9570 | } | |
9571 | ||
37119410 BS |
9572 | if (TARGET_THUMB1 |
9573 | && !peep2_reg_dead_p (nops, base_reg_rtx)) | |
9574 | return 0; | |
9575 | ||
84ed5e79 | 9576 | if (unsorted_offsets[order[0]] == 0) |
93b338c3 BS |
9577 | ldm_case = 1; /* ldmia */ |
9578 | else if (TARGET_ARM && unsorted_offsets[order[0]] == 4) | |
9579 | ldm_case = 2; /* ldmib */ | |
9580 | else if (TARGET_ARM && unsorted_offsets[order[nops - 1]] == 0) | |
9581 | ldm_case = 3; /* ldmda */ | |
37119410 | 9582 | else if (TARGET_32BIT && unsorted_offsets[order[nops - 1]] == -4) |
93b338c3 BS |
9583 | ldm_case = 4; /* ldmdb */ |
9584 | else if (const_ok_for_arm (unsorted_offsets[order[0]]) | |
9585 | || const_ok_for_arm (-unsorted_offsets[order[0]])) | |
9586 | ldm_case = 5; | |
9587 | else | |
9588 | return 0; | |
949d79eb | 9589 | |
93b338c3 BS |
9590 | if (!multiple_operation_profitable_p (false, nops, |
9591 | ldm_case == 5 | |
9592 | ? unsorted_offsets[order[0]] : 0)) | |
b36ba79f RE |
9593 | return 0; |
9594 | ||
93b338c3 | 9595 | return ldm_case; |
84ed5e79 RE |
9596 | } |
9597 | ||
37119410 BS |
9598 | /* Used to determine in a peephole whether a sequence of store instructions can |
9599 | be changed into a store-multiple instruction. | |
9600 | NOPS is the number of separate store instructions we are examining. | |
9601 | NOPS_TOTAL is the total number of instructions recognized by the peephole | |
9602 | pattern. | |
9603 | The first NOPS entries in OPERANDS are the source registers, the next | |
9604 | NOPS entries are memory operands. If this function is successful, *BASE is | |
9605 | set to the common base register of the memory accesses; *LOAD_OFFSET is set | |
9606 | to the first memory location's offset from that base register. REGS is an | |
9607 | array filled in with the source register numbers, REG_RTXS (if nonnull) is | |
9608 | likewise filled with the corresponding rtx's. | |
9609 | SAVED_ORDER (if nonnull), is an array filled in with an order that maps insn | |
9610 | numbers to to an ascending order of stores. | |
9611 | If CHECK_REGS is true, the sequence of registers in *REGS matches the stores | |
9612 | from ascending memory locations, and the function verifies that the register | |
9613 | numbers are themselves ascending. If CHECK_REGS is false, the register | |
9614 | numbers are stored in the order they are found in the operands. */ | |
9615 | static int | |
9616 | store_multiple_sequence (rtx *operands, int nops, int nops_total, | |
9617 | int *regs, rtx *reg_rtxs, int *saved_order, int *base, | |
9618 | HOST_WIDE_INT *load_offset, bool check_regs) | |
84ed5e79 | 9619 | { |
93b338c3 | 9620 | int unsorted_regs[MAX_LDM_STM_OPS]; |
37119410 | 9621 | rtx unsorted_reg_rtxs[MAX_LDM_STM_OPS]; |
93b338c3 BS |
9622 | HOST_WIDE_INT unsorted_offsets[MAX_LDM_STM_OPS]; |
9623 | int order[MAX_LDM_STM_OPS]; | |
ad076f4e | 9624 | int base_reg = -1; |
37119410 | 9625 | rtx base_reg_rtx = NULL; |
93b338c3 | 9626 | int i, stm_case; |
84ed5e79 | 9627 | |
93b338c3 BS |
9628 | /* Can only handle up to MAX_LDM_STM_OPS insns at present, though could be |
9629 | easily extended if required. */ | |
9630 | gcc_assert (nops >= 2 && nops <= MAX_LDM_STM_OPS); | |
84ed5e79 | 9631 | |
93b338c3 | 9632 | memset (order, 0, MAX_LDM_STM_OPS * sizeof (int)); |
f0b4bdd5 | 9633 | |
84ed5e79 | 9634 | /* Loop over the operands and check that the memory references are |
112cdef5 | 9635 | suitable (i.e. immediate offsets from the same base register). At |
84ed5e79 RE |
9636 | the same time, extract the target register, and the memory |
9637 | offsets. */ | |
9638 | for (i = 0; i < nops; i++) | |
9639 | { | |
9640 | rtx reg; | |
9641 | rtx offset; | |
9642 | ||
56636818 JL |
9643 | /* Convert a subreg of a mem into the mem itself. */ |
9644 | if (GET_CODE (operands[nops + i]) == SUBREG) | |
4e26a7af | 9645 | operands[nops + i] = alter_subreg (operands + (nops + i)); |
56636818 | 9646 | |
e6d29d15 | 9647 | gcc_assert (GET_CODE (operands[nops + i]) == MEM); |
84ed5e79 RE |
9648 | |
9649 | /* Don't reorder volatile memory references; it doesn't seem worth | |
9650 | looking for the case where the order is ok anyway. */ | |
9651 | if (MEM_VOLATILE_P (operands[nops + i])) | |
9652 | return 0; | |
9653 | ||
9654 | offset = const0_rtx; | |
9655 | ||
9656 | if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG | |
9657 | || (GET_CODE (reg) == SUBREG | |
9658 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
9659 | || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS | |
9660 | && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0)) | |
9661 | == REG) | |
9662 | || (GET_CODE (reg) == SUBREG | |
9663 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
9664 | && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1)) | |
9665 | == CONST_INT))) | |
9666 | { | |
37119410 BS |
9667 | unsorted_reg_rtxs[i] = (GET_CODE (operands[i]) == REG |
9668 | ? operands[i] : SUBREG_REG (operands[i])); | |
9669 | unsorted_regs[i] = REGNO (unsorted_reg_rtxs[i]); | |
9670 | ||
84ed5e79 | 9671 | if (i == 0) |
37119410 BS |
9672 | { |
9673 | base_reg = REGNO (reg); | |
9674 | base_reg_rtx = reg; | |
9675 | if (TARGET_THUMB1 && base_reg > LAST_LO_REGNUM) | |
9676 | return 0; | |
9677 | } | |
93b338c3 BS |
9678 | else if (base_reg != (int) REGNO (reg)) |
9679 | /* Not addressed from the same base register. */ | |
9680 | return 0; | |
84ed5e79 RE |
9681 | |
9682 | /* If it isn't an integer register, then we can't do this. */ | |
37119410 BS |
9683 | if (unsorted_regs[i] < 0 |
9684 | || (TARGET_THUMB1 && unsorted_regs[i] > LAST_LO_REGNUM) | |
9685 | || (TARGET_THUMB2 && unsorted_regs[i] == base_reg) | |
9686 | || (TARGET_THUMB2 && unsorted_regs[i] == SP_REGNUM) | |
9687 | || unsorted_regs[i] > 14) | |
84ed5e79 RE |
9688 | return 0; |
9689 | ||
9690 | unsorted_offsets[i] = INTVAL (offset); | |
93b338c3 BS |
9691 | if (i == 0 || unsorted_offsets[i] < unsorted_offsets[order[0]]) |
9692 | order[0] = i; | |
84ed5e79 RE |
9693 | } |
9694 | else | |
9695 | /* Not a suitable memory address. */ | |
9696 | return 0; | |
9697 | } | |
9698 | ||
9699 | /* All the useful information has now been extracted from the | |
9700 | operands into unsorted_regs and unsorted_offsets; additionally, | |
93b338c3 BS |
9701 | order[0] has been set to the lowest offset in the list. Sort |
9702 | the offsets into order, verifying that they are adjacent, and | |
9703 | check that the register numbers are ascending. */ | |
37119410 BS |
9704 | if (!compute_offset_order (nops, unsorted_offsets, order, |
9705 | check_regs ? unsorted_regs : NULL)) | |
93b338c3 | 9706 | return 0; |
84ed5e79 | 9707 | |
37119410 BS |
9708 | if (saved_order) |
9709 | memcpy (saved_order, order, sizeof order); | |
9710 | ||
84ed5e79 RE |
9711 | if (base) |
9712 | { | |
9713 | *base = base_reg; | |
9714 | ||
9715 | for (i = 0; i < nops; i++) | |
37119410 BS |
9716 | { |
9717 | regs[i] = unsorted_regs[check_regs ? order[i] : i]; | |
9718 | if (reg_rtxs) | |
9719 | reg_rtxs[i] = unsorted_reg_rtxs[check_regs ? order[i] : i]; | |
9720 | } | |
84ed5e79 RE |
9721 | |
9722 | *load_offset = unsorted_offsets[order[0]]; | |
9723 | } | |
9724 | ||
37119410 BS |
9725 | if (TARGET_THUMB1 |
9726 | && !peep2_reg_dead_p (nops_total, base_reg_rtx)) | |
9727 | return 0; | |
9728 | ||
84ed5e79 | 9729 | if (unsorted_offsets[order[0]] == 0) |
93b338c3 BS |
9730 | stm_case = 1; /* stmia */ |
9731 | else if (TARGET_ARM && unsorted_offsets[order[0]] == 4) | |
9732 | stm_case = 2; /* stmib */ | |
9733 | else if (TARGET_ARM && unsorted_offsets[order[nops - 1]] == 0) | |
9734 | stm_case = 3; /* stmda */ | |
37119410 | 9735 | else if (TARGET_32BIT && unsorted_offsets[order[nops - 1]] == -4) |
93b338c3 BS |
9736 | stm_case = 4; /* stmdb */ |
9737 | else | |
9738 | return 0; | |
84ed5e79 | 9739 | |
93b338c3 BS |
9740 | if (!multiple_operation_profitable_p (false, nops, 0)) |
9741 | return 0; | |
84ed5e79 | 9742 | |
93b338c3 | 9743 | return stm_case; |
84ed5e79 | 9744 | } |
ff9940b0 | 9745 | \f |
6354dc9b | 9746 | /* Routines for use in generating RTL. */ |
1d6e90ac | 9747 | |
37119410 BS |
9748 | /* Generate a load-multiple instruction. COUNT is the number of loads in |
9749 | the instruction; REGS and MEMS are arrays containing the operands. | |
9750 | BASEREG is the base register to be used in addressing the memory operands. | |
9751 | WBACK_OFFSET is nonzero if the instruction should update the base | |
9752 | register. */ | |
9753 | ||
9754 | static rtx | |
9755 | arm_gen_load_multiple_1 (int count, int *regs, rtx *mems, rtx basereg, | |
9756 | HOST_WIDE_INT wback_offset) | |
ff9940b0 RE |
9757 | { |
9758 | int i = 0, j; | |
9759 | rtx result; | |
ff9940b0 | 9760 | |
8f4c6e28 | 9761 | if (!multiple_operation_profitable_p (false, count, 0)) |
d19fb8e3 NC |
9762 | { |
9763 | rtx seq; | |
f676971a | 9764 | |
d19fb8e3 | 9765 | start_sequence (); |
f676971a | 9766 | |
d19fb8e3 | 9767 | for (i = 0; i < count; i++) |
37119410 | 9768 | emit_move_insn (gen_rtx_REG (SImode, regs[i]), mems[i]); |
d19fb8e3 | 9769 | |
37119410 BS |
9770 | if (wback_offset != 0) |
9771 | emit_move_insn (basereg, plus_constant (basereg, wback_offset)); | |
d19fb8e3 | 9772 | |
2f937369 | 9773 | seq = get_insns (); |
d19fb8e3 | 9774 | end_sequence (); |
f676971a | 9775 | |
d19fb8e3 NC |
9776 | return seq; |
9777 | } | |
9778 | ||
43cffd11 | 9779 | result = gen_rtx_PARALLEL (VOIDmode, |
37119410 BS |
9780 | rtvec_alloc (count + (wback_offset != 0 ? 1 : 0))); |
9781 | if (wback_offset != 0) | |
f3bb6135 | 9782 | { |
ff9940b0 | 9783 | XVECEXP (result, 0, 0) |
37119410 BS |
9784 | = gen_rtx_SET (VOIDmode, basereg, |
9785 | plus_constant (basereg, wback_offset)); | |
ff9940b0 RE |
9786 | i = 1; |
9787 | count++; | |
f3bb6135 RE |
9788 | } |
9789 | ||
ff9940b0 | 9790 | for (j = 0; i < count; i++, j++) |
37119410 BS |
9791 | XVECEXP (result, 0, i) |
9792 | = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regs[j]), mems[j]); | |
50ed9cea | 9793 | |
ff9940b0 RE |
9794 | return result; |
9795 | } | |
9796 | ||
37119410 BS |
9797 | /* Generate a store-multiple instruction. COUNT is the number of stores in |
9798 | the instruction; REGS and MEMS are arrays containing the operands. | |
9799 | BASEREG is the base register to be used in addressing the memory operands. | |
9800 | WBACK_OFFSET is nonzero if the instruction should update the base | |
9801 | register. */ | |
9802 | ||
9803 | static rtx | |
9804 | arm_gen_store_multiple_1 (int count, int *regs, rtx *mems, rtx basereg, | |
9805 | HOST_WIDE_INT wback_offset) | |
ff9940b0 RE |
9806 | { |
9807 | int i = 0, j; | |
9808 | rtx result; | |
ff9940b0 | 9809 | |
37119410 BS |
9810 | if (GET_CODE (basereg) == PLUS) |
9811 | basereg = XEXP (basereg, 0); | |
9812 | ||
8f4c6e28 | 9813 | if (!multiple_operation_profitable_p (false, count, 0)) |
d19fb8e3 NC |
9814 | { |
9815 | rtx seq; | |
f676971a | 9816 | |
d19fb8e3 | 9817 | start_sequence (); |
f676971a | 9818 | |
d19fb8e3 | 9819 | for (i = 0; i < count; i++) |
37119410 | 9820 | emit_move_insn (mems[i], gen_rtx_REG (SImode, regs[i])); |
d19fb8e3 | 9821 | |
37119410 BS |
9822 | if (wback_offset != 0) |
9823 | emit_move_insn (basereg, plus_constant (basereg, wback_offset)); | |
d19fb8e3 | 9824 | |
2f937369 | 9825 | seq = get_insns (); |
d19fb8e3 | 9826 | end_sequence (); |
f676971a | 9827 | |
d19fb8e3 NC |
9828 | return seq; |
9829 | } | |
9830 | ||
43cffd11 | 9831 | result = gen_rtx_PARALLEL (VOIDmode, |
37119410 BS |
9832 | rtvec_alloc (count + (wback_offset != 0 ? 1 : 0))); |
9833 | if (wback_offset != 0) | |
f3bb6135 | 9834 | { |
ff9940b0 | 9835 | XVECEXP (result, 0, 0) |
37119410 BS |
9836 | = gen_rtx_SET (VOIDmode, basereg, |
9837 | plus_constant (basereg, wback_offset)); | |
ff9940b0 RE |
9838 | i = 1; |
9839 | count++; | |
f3bb6135 RE |
9840 | } |
9841 | ||
ff9940b0 | 9842 | for (j = 0; i < count; i++, j++) |
37119410 BS |
9843 | XVECEXP (result, 0, i) |
9844 | = gen_rtx_SET (VOIDmode, mems[j], gen_rtx_REG (SImode, regs[j])); | |
9845 | ||
9846 | return result; | |
9847 | } | |
9848 | ||
9849 | /* Generate either a load-multiple or a store-multiple instruction. This | |
9850 | function can be used in situations where we can start with a single MEM | |
9851 | rtx and adjust its address upwards. | |
9852 | COUNT is the number of operations in the instruction, not counting a | |
9853 | possible update of the base register. REGS is an array containing the | |
9854 | register operands. | |
9855 | BASEREG is the base register to be used in addressing the memory operands, | |
9856 | which are constructed from BASEMEM. | |
9857 | WRITE_BACK specifies whether the generated instruction should include an | |
9858 | update of the base register. | |
9859 | OFFSETP is used to pass an offset to and from this function; this offset | |
9860 | is not used when constructing the address (instead BASEMEM should have an | |
9861 | appropriate offset in its address), it is used only for setting | |
9862 | MEM_OFFSET. It is updated only if WRITE_BACK is true.*/ | |
9863 | ||
9864 | static rtx | |
9865 | arm_gen_multiple_op (bool is_load, int *regs, int count, rtx basereg, | |
9866 | bool write_back, rtx basemem, HOST_WIDE_INT *offsetp) | |
9867 | { | |
9868 | rtx mems[MAX_LDM_STM_OPS]; | |
9869 | HOST_WIDE_INT offset = *offsetp; | |
9870 | int i; | |
9871 | ||
9872 | gcc_assert (count <= MAX_LDM_STM_OPS); | |
9873 | ||
9874 | if (GET_CODE (basereg) == PLUS) | |
9875 | basereg = XEXP (basereg, 0); | |
9876 | ||
9877 | for (i = 0; i < count; i++) | |
f3bb6135 | 9878 | { |
37119410 BS |
9879 | rtx addr = plus_constant (basereg, i * 4); |
9880 | mems[i] = adjust_automodify_address_nv (basemem, SImode, addr, offset); | |
9881 | offset += 4; | |
f3bb6135 RE |
9882 | } |
9883 | ||
50ed9cea RH |
9884 | if (write_back) |
9885 | *offsetp = offset; | |
9886 | ||
37119410 BS |
9887 | if (is_load) |
9888 | return arm_gen_load_multiple_1 (count, regs, mems, basereg, | |
9889 | write_back ? 4 * count : 0); | |
9890 | else | |
9891 | return arm_gen_store_multiple_1 (count, regs, mems, basereg, | |
9892 | write_back ? 4 * count : 0); | |
9893 | } | |
9894 | ||
9895 | rtx | |
9896 | arm_gen_load_multiple (int *regs, int count, rtx basereg, int write_back, | |
9897 | rtx basemem, HOST_WIDE_INT *offsetp) | |
9898 | { | |
9899 | return arm_gen_multiple_op (TRUE, regs, count, basereg, write_back, basemem, | |
9900 | offsetp); | |
9901 | } | |
9902 | ||
9903 | rtx | |
9904 | arm_gen_store_multiple (int *regs, int count, rtx basereg, int write_back, | |
9905 | rtx basemem, HOST_WIDE_INT *offsetp) | |
9906 | { | |
9907 | return arm_gen_multiple_op (FALSE, regs, count, basereg, write_back, basemem, | |
9908 | offsetp); | |
9909 | } | |
9910 | ||
9911 | /* Called from a peephole2 expander to turn a sequence of loads into an | |
9912 | LDM instruction. OPERANDS are the operands found by the peephole matcher; | |
9913 | NOPS indicates how many separate loads we are trying to combine. SORT_REGS | |
9914 | is true if we can reorder the registers because they are used commutatively | |
9915 | subsequently. | |
9916 | Returns true iff we could generate a new instruction. */ | |
9917 | ||
9918 | bool | |
9919 | gen_ldm_seq (rtx *operands, int nops, bool sort_regs) | |
9920 | { | |
9921 | int regs[MAX_LDM_STM_OPS], mem_order[MAX_LDM_STM_OPS]; | |
9922 | rtx mems[MAX_LDM_STM_OPS]; | |
9923 | int i, j, base_reg; | |
9924 | rtx base_reg_rtx; | |
9925 | HOST_WIDE_INT offset; | |
9926 | int write_back = FALSE; | |
9927 | int ldm_case; | |
9928 | rtx addr; | |
9929 | ||
9930 | ldm_case = load_multiple_sequence (operands, nops, regs, mem_order, | |
9931 | &base_reg, &offset, !sort_regs); | |
9932 | ||
9933 | if (ldm_case == 0) | |
9934 | return false; | |
9935 | ||
9936 | if (sort_regs) | |
9937 | for (i = 0; i < nops - 1; i++) | |
9938 | for (j = i + 1; j < nops; j++) | |
9939 | if (regs[i] > regs[j]) | |
9940 | { | |
9941 | int t = regs[i]; | |
9942 | regs[i] = regs[j]; | |
9943 | regs[j] = t; | |
9944 | } | |
9945 | base_reg_rtx = gen_rtx_REG (Pmode, base_reg); | |
9946 | ||
9947 | if (TARGET_THUMB1) | |
9948 | { | |
9949 | gcc_assert (peep2_reg_dead_p (nops, base_reg_rtx)); | |
9950 | gcc_assert (ldm_case == 1 || ldm_case == 5); | |
9951 | write_back = TRUE; | |
9952 | } | |
9953 | ||
9954 | if (ldm_case == 5) | |
9955 | { | |
9956 | rtx newbase = TARGET_THUMB1 ? base_reg_rtx : gen_rtx_REG (SImode, regs[0]); | |
9957 | emit_insn (gen_addsi3 (newbase, base_reg_rtx, GEN_INT (offset))); | |
9958 | offset = 0; | |
9959 | if (!TARGET_THUMB1) | |
9960 | { | |
9961 | base_reg = regs[0]; | |
9962 | base_reg_rtx = newbase; | |
9963 | } | |
9964 | } | |
9965 | ||
9966 | for (i = 0; i < nops; i++) | |
9967 | { | |
9968 | addr = plus_constant (base_reg_rtx, offset + i * 4); | |
9969 | mems[i] = adjust_automodify_address_nv (operands[nops + mem_order[i]], | |
9970 | SImode, addr, 0); | |
9971 | } | |
9972 | emit_insn (arm_gen_load_multiple_1 (nops, regs, mems, base_reg_rtx, | |
9973 | write_back ? offset + i * 4 : 0)); | |
9974 | return true; | |
9975 | } | |
9976 | ||
9977 | /* Called from a peephole2 expander to turn a sequence of stores into an | |
9978 | STM instruction. OPERANDS are the operands found by the peephole matcher; | |
9979 | NOPS indicates how many separate stores we are trying to combine. | |
9980 | Returns true iff we could generate a new instruction. */ | |
9981 | ||
9982 | bool | |
9983 | gen_stm_seq (rtx *operands, int nops) | |
9984 | { | |
9985 | int i; | |
9986 | int regs[MAX_LDM_STM_OPS], mem_order[MAX_LDM_STM_OPS]; | |
9987 | rtx mems[MAX_LDM_STM_OPS]; | |
9988 | int base_reg; | |
9989 | rtx base_reg_rtx; | |
9990 | HOST_WIDE_INT offset; | |
9991 | int write_back = FALSE; | |
9992 | int stm_case; | |
9993 | rtx addr; | |
9994 | bool base_reg_dies; | |
9995 | ||
9996 | stm_case = store_multiple_sequence (operands, nops, nops, regs, NULL, | |
9997 | mem_order, &base_reg, &offset, true); | |
9998 | ||
9999 | if (stm_case == 0) | |
10000 | return false; | |
10001 | ||
10002 | base_reg_rtx = gen_rtx_REG (Pmode, base_reg); | |
10003 | ||
10004 | base_reg_dies = peep2_reg_dead_p (nops, base_reg_rtx); | |
10005 | if (TARGET_THUMB1) | |
10006 | { | |
10007 | gcc_assert (base_reg_dies); | |
10008 | write_back = TRUE; | |
10009 | } | |
10010 | ||
10011 | if (stm_case == 5) | |
10012 | { | |
10013 | gcc_assert (base_reg_dies); | |
10014 | emit_insn (gen_addsi3 (base_reg_rtx, base_reg_rtx, GEN_INT (offset))); | |
10015 | offset = 0; | |
10016 | } | |
10017 | ||
10018 | addr = plus_constant (base_reg_rtx, offset); | |
10019 | ||
10020 | for (i = 0; i < nops; i++) | |
10021 | { | |
10022 | addr = plus_constant (base_reg_rtx, offset + i * 4); | |
10023 | mems[i] = adjust_automodify_address_nv (operands[nops + mem_order[i]], | |
10024 | SImode, addr, 0); | |
10025 | } | |
10026 | emit_insn (arm_gen_store_multiple_1 (nops, regs, mems, base_reg_rtx, | |
10027 | write_back ? offset + i * 4 : 0)); | |
10028 | return true; | |
10029 | } | |
10030 | ||
10031 | /* Called from a peephole2 expander to turn a sequence of stores that are | |
10032 | preceded by constant loads into an STM instruction. OPERANDS are the | |
10033 | operands found by the peephole matcher; NOPS indicates how many | |
10034 | separate stores we are trying to combine; there are 2 * NOPS | |
10035 | instructions in the peephole. | |
10036 | Returns true iff we could generate a new instruction. */ | |
10037 | ||
10038 | bool | |
10039 | gen_const_stm_seq (rtx *operands, int nops) | |
10040 | { | |
10041 | int regs[MAX_LDM_STM_OPS], sorted_regs[MAX_LDM_STM_OPS]; | |
10042 | int reg_order[MAX_LDM_STM_OPS], mem_order[MAX_LDM_STM_OPS]; | |
10043 | rtx reg_rtxs[MAX_LDM_STM_OPS], orig_reg_rtxs[MAX_LDM_STM_OPS]; | |
10044 | rtx mems[MAX_LDM_STM_OPS]; | |
10045 | int base_reg; | |
10046 | rtx base_reg_rtx; | |
10047 | HOST_WIDE_INT offset; | |
10048 | int write_back = FALSE; | |
10049 | int stm_case; | |
10050 | rtx addr; | |
10051 | bool base_reg_dies; | |
10052 | int i, j; | |
10053 | HARD_REG_SET allocated; | |
10054 | ||
10055 | stm_case = store_multiple_sequence (operands, nops, 2 * nops, regs, reg_rtxs, | |
10056 | mem_order, &base_reg, &offset, false); | |
10057 | ||
10058 | if (stm_case == 0) | |
10059 | return false; | |
10060 | ||
10061 | memcpy (orig_reg_rtxs, reg_rtxs, sizeof orig_reg_rtxs); | |
10062 | ||
10063 | /* If the same register is used more than once, try to find a free | |
10064 | register. */ | |
10065 | CLEAR_HARD_REG_SET (allocated); | |
10066 | for (i = 0; i < nops; i++) | |
10067 | { | |
10068 | for (j = i + 1; j < nops; j++) | |
10069 | if (regs[i] == regs[j]) | |
10070 | { | |
10071 | rtx t = peep2_find_free_register (0, nops * 2, | |
10072 | TARGET_THUMB1 ? "l" : "r", | |
10073 | SImode, &allocated); | |
10074 | if (t == NULL_RTX) | |
10075 | return false; | |
10076 | reg_rtxs[i] = t; | |
10077 | regs[i] = REGNO (t); | |
10078 | } | |
10079 | } | |
10080 | ||
10081 | /* Compute an ordering that maps the register numbers to an ascending | |
10082 | sequence. */ | |
10083 | reg_order[0] = 0; | |
10084 | for (i = 0; i < nops; i++) | |
10085 | if (regs[i] < regs[reg_order[0]]) | |
10086 | reg_order[0] = i; | |
10087 | ||
10088 | for (i = 1; i < nops; i++) | |
10089 | { | |
10090 | int this_order = reg_order[i - 1]; | |
10091 | for (j = 0; j < nops; j++) | |
10092 | if (regs[j] > regs[reg_order[i - 1]] | |
10093 | && (this_order == reg_order[i - 1] | |
10094 | || regs[j] < regs[this_order])) | |
10095 | this_order = j; | |
10096 | reg_order[i] = this_order; | |
10097 | } | |
10098 | ||
10099 | /* Ensure that registers that must be live after the instruction end | |
10100 | up with the correct value. */ | |
10101 | for (i = 0; i < nops; i++) | |
10102 | { | |
10103 | int this_order = reg_order[i]; | |
10104 | if ((this_order != mem_order[i] | |
10105 | || orig_reg_rtxs[this_order] != reg_rtxs[this_order]) | |
10106 | && !peep2_reg_dead_p (nops * 2, orig_reg_rtxs[this_order])) | |
10107 | return false; | |
10108 | } | |
10109 | ||
10110 | /* Load the constants. */ | |
10111 | for (i = 0; i < nops; i++) | |
10112 | { | |
10113 | rtx op = operands[2 * nops + mem_order[i]]; | |
10114 | sorted_regs[i] = regs[reg_order[i]]; | |
10115 | emit_move_insn (reg_rtxs[reg_order[i]], op); | |
10116 | } | |
10117 | ||
10118 | base_reg_rtx = gen_rtx_REG (Pmode, base_reg); | |
10119 | ||
10120 | base_reg_dies = peep2_reg_dead_p (nops * 2, base_reg_rtx); | |
10121 | if (TARGET_THUMB1) | |
10122 | { | |
10123 | gcc_assert (base_reg_dies); | |
10124 | write_back = TRUE; | |
10125 | } | |
10126 | ||
10127 | if (stm_case == 5) | |
10128 | { | |
10129 | gcc_assert (base_reg_dies); | |
10130 | emit_insn (gen_addsi3 (base_reg_rtx, base_reg_rtx, GEN_INT (offset))); | |
10131 | offset = 0; | |
10132 | } | |
10133 | ||
10134 | addr = plus_constant (base_reg_rtx, offset); | |
10135 | ||
10136 | for (i = 0; i < nops; i++) | |
10137 | { | |
10138 | addr = plus_constant (base_reg_rtx, offset + i * 4); | |
10139 | mems[i] = adjust_automodify_address_nv (operands[nops + mem_order[i]], | |
10140 | SImode, addr, 0); | |
10141 | } | |
10142 | emit_insn (arm_gen_store_multiple_1 (nops, sorted_regs, mems, base_reg_rtx, | |
10143 | write_back ? offset + i * 4 : 0)); | |
10144 | return true; | |
ff9940b0 RE |
10145 | } |
10146 | ||
880e2516 | 10147 | int |
70128ad9 | 10148 | arm_gen_movmemqi (rtx *operands) |
880e2516 RE |
10149 | { |
10150 | HOST_WIDE_INT in_words_to_go, out_words_to_go, last_bytes; | |
50ed9cea | 10151 | HOST_WIDE_INT srcoffset, dstoffset; |
ad076f4e | 10152 | int i; |
50ed9cea | 10153 | rtx src, dst, srcbase, dstbase; |
880e2516 | 10154 | rtx part_bytes_reg = NULL; |
56636818 | 10155 | rtx mem; |
880e2516 RE |
10156 | |
10157 | if (GET_CODE (operands[2]) != CONST_INT | |
10158 | || GET_CODE (operands[3]) != CONST_INT | |
10159 | || INTVAL (operands[2]) > 64 | |
10160 | || INTVAL (operands[3]) & 3) | |
10161 | return 0; | |
10162 | ||
50ed9cea RH |
10163 | dstbase = operands[0]; |
10164 | srcbase = operands[1]; | |
56636818 | 10165 | |
50ed9cea RH |
10166 | dst = copy_to_mode_reg (SImode, XEXP (dstbase, 0)); |
10167 | src = copy_to_mode_reg (SImode, XEXP (srcbase, 0)); | |
880e2516 | 10168 | |
e9d7b180 | 10169 | in_words_to_go = ARM_NUM_INTS (INTVAL (operands[2])); |
880e2516 RE |
10170 | out_words_to_go = INTVAL (operands[2]) / 4; |
10171 | last_bytes = INTVAL (operands[2]) & 3; | |
50ed9cea | 10172 | dstoffset = srcoffset = 0; |
880e2516 RE |
10173 | |
10174 | if (out_words_to_go != in_words_to_go && ((in_words_to_go - 1) & 3) != 0) | |
43cffd11 | 10175 | part_bytes_reg = gen_rtx_REG (SImode, (in_words_to_go - 1) & 3); |
880e2516 RE |
10176 | |
10177 | for (i = 0; in_words_to_go >= 2; i+=4) | |
10178 | { | |
bd9c7e23 | 10179 | if (in_words_to_go > 4) |
37119410 BS |
10180 | emit_insn (arm_gen_load_multiple (arm_regs_in_sequence, 4, src, |
10181 | TRUE, srcbase, &srcoffset)); | |
bd9c7e23 | 10182 | else |
37119410 BS |
10183 | emit_insn (arm_gen_load_multiple (arm_regs_in_sequence, in_words_to_go, |
10184 | src, FALSE, srcbase, | |
10185 | &srcoffset)); | |
bd9c7e23 | 10186 | |
880e2516 RE |
10187 | if (out_words_to_go) |
10188 | { | |
bd9c7e23 | 10189 | if (out_words_to_go > 4) |
37119410 BS |
10190 | emit_insn (arm_gen_store_multiple (arm_regs_in_sequence, 4, dst, |
10191 | TRUE, dstbase, &dstoffset)); | |
bd9c7e23 | 10192 | else if (out_words_to_go != 1) |
37119410 BS |
10193 | emit_insn (arm_gen_store_multiple (arm_regs_in_sequence, |
10194 | out_words_to_go, dst, | |
bd9c7e23 | 10195 | (last_bytes == 0 |
56636818 | 10196 | ? FALSE : TRUE), |
50ed9cea | 10197 | dstbase, &dstoffset)); |
880e2516 RE |
10198 | else |
10199 | { | |
50ed9cea | 10200 | mem = adjust_automodify_address (dstbase, SImode, dst, dstoffset); |
43cffd11 | 10201 | emit_move_insn (mem, gen_rtx_REG (SImode, 0)); |
bd9c7e23 | 10202 | if (last_bytes != 0) |
50ed9cea RH |
10203 | { |
10204 | emit_insn (gen_addsi3 (dst, dst, GEN_INT (4))); | |
10205 | dstoffset += 4; | |
10206 | } | |
880e2516 RE |
10207 | } |
10208 | } | |
10209 | ||
10210 | in_words_to_go -= in_words_to_go < 4 ? in_words_to_go : 4; | |
10211 | out_words_to_go -= out_words_to_go < 4 ? out_words_to_go : 4; | |
10212 | } | |
10213 | ||
10214 | /* OUT_WORDS_TO_GO will be zero here if there are byte stores to do. */ | |
10215 | if (out_words_to_go) | |
62b10bbc NC |
10216 | { |
10217 | rtx sreg; | |
f676971a | 10218 | |
50ed9cea RH |
10219 | mem = adjust_automodify_address (srcbase, SImode, src, srcoffset); |
10220 | sreg = copy_to_reg (mem); | |
10221 | ||
10222 | mem = adjust_automodify_address (dstbase, SImode, dst, dstoffset); | |
62b10bbc | 10223 | emit_move_insn (mem, sreg); |
62b10bbc | 10224 | in_words_to_go--; |
f676971a | 10225 | |
e6d29d15 | 10226 | gcc_assert (!in_words_to_go); /* Sanity check */ |
62b10bbc | 10227 | } |
880e2516 RE |
10228 | |
10229 | if (in_words_to_go) | |
10230 | { | |
e6d29d15 | 10231 | gcc_assert (in_words_to_go > 0); |
880e2516 | 10232 | |
50ed9cea | 10233 | mem = adjust_automodify_address (srcbase, SImode, src, srcoffset); |
56636818 | 10234 | part_bytes_reg = copy_to_mode_reg (SImode, mem); |
880e2516 RE |
10235 | } |
10236 | ||
e6d29d15 | 10237 | gcc_assert (!last_bytes || part_bytes_reg); |
d5b7b3ae | 10238 | |
880e2516 RE |
10239 | if (BYTES_BIG_ENDIAN && last_bytes) |
10240 | { | |
10241 | rtx tmp = gen_reg_rtx (SImode); | |
10242 | ||
6354dc9b | 10243 | /* The bytes we want are in the top end of the word. */ |
bee06f3d RE |
10244 | emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, |
10245 | GEN_INT (8 * (4 - last_bytes)))); | |
880e2516 | 10246 | part_bytes_reg = tmp; |
f676971a | 10247 | |
880e2516 RE |
10248 | while (last_bytes) |
10249 | { | |
50ed9cea RH |
10250 | mem = adjust_automodify_address (dstbase, QImode, |
10251 | plus_constant (dst, last_bytes - 1), | |
10252 | dstoffset + last_bytes - 1); | |
5d5603e2 BS |
10253 | emit_move_insn (mem, gen_lowpart (QImode, part_bytes_reg)); |
10254 | ||
880e2516 RE |
10255 | if (--last_bytes) |
10256 | { | |
10257 | tmp = gen_reg_rtx (SImode); | |
10258 | emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8))); | |
10259 | part_bytes_reg = tmp; | |
10260 | } | |
10261 | } | |
f676971a | 10262 | |
880e2516 RE |
10263 | } |
10264 | else | |
10265 | { | |
d5b7b3ae | 10266 | if (last_bytes > 1) |
880e2516 | 10267 | { |
50ed9cea | 10268 | mem = adjust_automodify_address (dstbase, HImode, dst, dstoffset); |
5d5603e2 | 10269 | emit_move_insn (mem, gen_lowpart (HImode, part_bytes_reg)); |
d5b7b3ae RE |
10270 | last_bytes -= 2; |
10271 | if (last_bytes) | |
880e2516 RE |
10272 | { |
10273 | rtx tmp = gen_reg_rtx (SImode); | |
a556fd39 | 10274 | emit_insn (gen_addsi3 (dst, dst, const2_rtx)); |
d5b7b3ae | 10275 | emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (16))); |
880e2516 | 10276 | part_bytes_reg = tmp; |
50ed9cea | 10277 | dstoffset += 2; |
880e2516 RE |
10278 | } |
10279 | } | |
f676971a | 10280 | |
d5b7b3ae RE |
10281 | if (last_bytes) |
10282 | { | |
50ed9cea | 10283 | mem = adjust_automodify_address (dstbase, QImode, dst, dstoffset); |
5d5603e2 | 10284 | emit_move_insn (mem, gen_lowpart (QImode, part_bytes_reg)); |
d5b7b3ae | 10285 | } |
880e2516 RE |
10286 | } |
10287 | ||
10288 | return 1; | |
10289 | } | |
10290 | ||
03f1640c RE |
10291 | /* Select a dominance comparison mode if possible for a test of the general |
10292 | form (OP (COND_OR (X) (Y)) (const_int 0)). We support three forms. | |
f676971a | 10293 | COND_OR == DOM_CC_X_AND_Y => (X && Y) |
03f1640c | 10294 | COND_OR == DOM_CC_NX_OR_Y => ((! X) || Y) |
f676971a | 10295 | COND_OR == DOM_CC_X_OR_Y => (X || Y) |
03f1640c | 10296 | In all cases OP will be either EQ or NE, but we don't need to know which |
f676971a | 10297 | here. If we are unable to support a dominance comparison we return |
03f1640c RE |
10298 | CC mode. This will then fail to match for the RTL expressions that |
10299 | generate this call. */ | |
03f1640c | 10300 | enum machine_mode |
e32bac5b | 10301 | arm_select_dominance_cc_mode (rtx x, rtx y, HOST_WIDE_INT cond_or) |
84ed5e79 RE |
10302 | { |
10303 | enum rtx_code cond1, cond2; | |
10304 | int swapped = 0; | |
10305 | ||
10306 | /* Currently we will probably get the wrong result if the individual | |
10307 | comparisons are not simple. This also ensures that it is safe to | |
956d6950 | 10308 | reverse a comparison if necessary. */ |
84ed5e79 RE |
10309 | if ((arm_select_cc_mode (cond1 = GET_CODE (x), XEXP (x, 0), XEXP (x, 1)) |
10310 | != CCmode) | |
10311 | || (arm_select_cc_mode (cond2 = GET_CODE (y), XEXP (y, 0), XEXP (y, 1)) | |
10312 | != CCmode)) | |
10313 | return CCmode; | |
10314 | ||
1646cf41 RE |
10315 | /* The if_then_else variant of this tests the second condition if the |
10316 | first passes, but is true if the first fails. Reverse the first | |
10317 | condition to get a true "inclusive-or" expression. */ | |
03f1640c | 10318 | if (cond_or == DOM_CC_NX_OR_Y) |
84ed5e79 RE |
10319 | cond1 = reverse_condition (cond1); |
10320 | ||
10321 | /* If the comparisons are not equal, and one doesn't dominate the other, | |
10322 | then we can't do this. */ | |
f676971a | 10323 | if (cond1 != cond2 |
5895f793 RE |
10324 | && !comparison_dominates_p (cond1, cond2) |
10325 | && (swapped = 1, !comparison_dominates_p (cond2, cond1))) | |
84ed5e79 RE |
10326 | return CCmode; |
10327 | ||
10328 | if (swapped) | |
10329 | { | |
10330 | enum rtx_code temp = cond1; | |
10331 | cond1 = cond2; | |
10332 | cond2 = temp; | |
10333 | } | |
10334 | ||
10335 | switch (cond1) | |
10336 | { | |
10337 | case EQ: | |
e6d29d15 | 10338 | if (cond_or == DOM_CC_X_AND_Y) |
84ed5e79 RE |
10339 | return CC_DEQmode; |
10340 | ||
10341 | switch (cond2) | |
10342 | { | |
e6d29d15 | 10343 | case EQ: return CC_DEQmode; |
84ed5e79 RE |
10344 | case LE: return CC_DLEmode; |
10345 | case LEU: return CC_DLEUmode; | |
10346 | case GE: return CC_DGEmode; | |
10347 | case GEU: return CC_DGEUmode; | |
e6d29d15 | 10348 | default: gcc_unreachable (); |
84ed5e79 RE |
10349 | } |
10350 | ||
84ed5e79 | 10351 | case LT: |
e6d29d15 | 10352 | if (cond_or == DOM_CC_X_AND_Y) |
84ed5e79 | 10353 | return CC_DLTmode; |
e0b92319 | 10354 | |
e6d29d15 NS |
10355 | switch (cond2) |
10356 | { | |
10357 | case LT: | |
10358 | return CC_DLTmode; | |
10359 | case LE: | |
10360 | return CC_DLEmode; | |
10361 | case NE: | |
10362 | return CC_DNEmode; | |
10363 | default: | |
10364 | gcc_unreachable (); | |
10365 | } | |
84ed5e79 RE |
10366 | |
10367 | case GT: | |
e6d29d15 | 10368 | if (cond_or == DOM_CC_X_AND_Y) |
84ed5e79 | 10369 | return CC_DGTmode; |
e6d29d15 NS |
10370 | |
10371 | switch (cond2) | |
10372 | { | |
10373 | case GT: | |
10374 | return CC_DGTmode; | |
10375 | case GE: | |
10376 | return CC_DGEmode; | |
10377 | case NE: | |
10378 | return CC_DNEmode; | |
10379 | default: | |
10380 | gcc_unreachable (); | |
10381 | } | |
f676971a | 10382 | |
84ed5e79 | 10383 | case LTU: |
e6d29d15 | 10384 | if (cond_or == DOM_CC_X_AND_Y) |
84ed5e79 | 10385 | return CC_DLTUmode; |
e6d29d15 NS |
10386 | |
10387 | switch (cond2) | |
10388 | { | |
10389 | case LTU: | |
10390 | return CC_DLTUmode; | |
10391 | case LEU: | |
10392 | return CC_DLEUmode; | |
10393 | case NE: | |
10394 | return CC_DNEmode; | |
10395 | default: | |
10396 | gcc_unreachable (); | |
10397 | } | |
84ed5e79 RE |
10398 | |
10399 | case GTU: | |
e6d29d15 | 10400 | if (cond_or == DOM_CC_X_AND_Y) |
84ed5e79 | 10401 | return CC_DGTUmode; |
e0b92319 | 10402 | |
e6d29d15 NS |
10403 | switch (cond2) |
10404 | { | |
10405 | case GTU: | |
10406 | return CC_DGTUmode; | |
10407 | case GEU: | |
10408 | return CC_DGEUmode; | |
10409 | case NE: | |
10410 | return CC_DNEmode; | |
10411 | default: | |
10412 | gcc_unreachable (); | |
10413 | } | |
84ed5e79 RE |
10414 | |
10415 | /* The remaining cases only occur when both comparisons are the | |
10416 | same. */ | |
10417 | case NE: | |
e6d29d15 | 10418 | gcc_assert (cond1 == cond2); |
84ed5e79 RE |
10419 | return CC_DNEmode; |
10420 | ||
10421 | case LE: | |
e6d29d15 | 10422 | gcc_assert (cond1 == cond2); |
84ed5e79 RE |
10423 | return CC_DLEmode; |
10424 | ||
10425 | case GE: | |
e6d29d15 | 10426 | gcc_assert (cond1 == cond2); |
84ed5e79 RE |
10427 | return CC_DGEmode; |
10428 | ||
10429 | case LEU: | |
e6d29d15 | 10430 | gcc_assert (cond1 == cond2); |
84ed5e79 RE |
10431 | return CC_DLEUmode; |
10432 | ||
10433 | case GEU: | |
e6d29d15 | 10434 | gcc_assert (cond1 == cond2); |
84ed5e79 | 10435 | return CC_DGEUmode; |
ad076f4e RE |
10436 | |
10437 | default: | |
e6d29d15 | 10438 | gcc_unreachable (); |
84ed5e79 | 10439 | } |
84ed5e79 RE |
10440 | } |
10441 | ||
10442 | enum machine_mode | |
e32bac5b | 10443 | arm_select_cc_mode (enum rtx_code op, rtx x, rtx y) |
84ed5e79 RE |
10444 | { |
10445 | /* All floating point compares return CCFP if it is an equality | |
10446 | comparison, and CCFPE otherwise. */ | |
10447 | if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) | |
e45b72c4 RE |
10448 | { |
10449 | switch (op) | |
10450 | { | |
10451 | case EQ: | |
10452 | case NE: | |
10453 | case UNORDERED: | |
10454 | case ORDERED: | |
10455 | case UNLT: | |
10456 | case UNLE: | |
10457 | case UNGT: | |
10458 | case UNGE: | |
10459 | case UNEQ: | |
10460 | case LTGT: | |
10461 | return CCFPmode; | |
10462 | ||
10463 | case LT: | |
10464 | case LE: | |
10465 | case GT: | |
10466 | case GE: | |
9b66ebb1 | 10467 | if (TARGET_HARD_FLOAT && TARGET_MAVERICK) |
9b6b54e2 | 10468 | return CCFPmode; |
e45b72c4 RE |
10469 | return CCFPEmode; |
10470 | ||
10471 | default: | |
e6d29d15 | 10472 | gcc_unreachable (); |
e45b72c4 RE |
10473 | } |
10474 | } | |
f676971a | 10475 | |
84ed5e79 RE |
10476 | /* A compare with a shifted operand. Because of canonicalization, the |
10477 | comparison will have to be swapped when we emit the assembler. */ | |
3e2d9dcf RR |
10478 | if (GET_MODE (y) == SImode |
10479 | && (REG_P (y) || (GET_CODE (y) == SUBREG)) | |
84ed5e79 RE |
10480 | && (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT |
10481 | || GET_CODE (x) == LSHIFTRT || GET_CODE (x) == ROTATE | |
10482 | || GET_CODE (x) == ROTATERT)) | |
10483 | return CC_SWPmode; | |
10484 | ||
04d8b819 RE |
10485 | /* This operation is performed swapped, but since we only rely on the Z |
10486 | flag we don't need an additional mode. */ | |
3e2d9dcf RR |
10487 | if (GET_MODE (y) == SImode |
10488 | && (REG_P (y) || (GET_CODE (y) == SUBREG)) | |
04d8b819 RE |
10489 | && GET_CODE (x) == NEG |
10490 | && (op == EQ || op == NE)) | |
10491 | return CC_Zmode; | |
10492 | ||
f676971a | 10493 | /* This is a special case that is used by combine to allow a |
956d6950 | 10494 | comparison of a shifted byte load to be split into a zero-extend |
84ed5e79 | 10495 | followed by a comparison of the shifted integer (only valid for |
956d6950 | 10496 | equalities and unsigned inequalities). */ |
84ed5e79 RE |
10497 | if (GET_MODE (x) == SImode |
10498 | && GET_CODE (x) == ASHIFT | |
10499 | && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 24 | |
10500 | && GET_CODE (XEXP (x, 0)) == SUBREG | |
10501 | && GET_CODE (SUBREG_REG (XEXP (x, 0))) == MEM | |
10502 | && GET_MODE (SUBREG_REG (XEXP (x, 0))) == QImode | |
10503 | && (op == EQ || op == NE | |
10504 | || op == GEU || op == GTU || op == LTU || op == LEU) | |
10505 | && GET_CODE (y) == CONST_INT) | |
10506 | return CC_Zmode; | |
10507 | ||
1646cf41 RE |
10508 | /* A construct for a conditional compare, if the false arm contains |
10509 | 0, then both conditions must be true, otherwise either condition | |
10510 | must be true. Not all conditions are possible, so CCmode is | |
10511 | returned if it can't be done. */ | |
10512 | if (GET_CODE (x) == IF_THEN_ELSE | |
10513 | && (XEXP (x, 2) == const0_rtx | |
10514 | || XEXP (x, 2) == const1_rtx) | |
ec8e098d PB |
10515 | && COMPARISON_P (XEXP (x, 0)) |
10516 | && COMPARISON_P (XEXP (x, 1))) | |
f676971a | 10517 | return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), |
03f1640c | 10518 | INTVAL (XEXP (x, 2))); |
1646cf41 RE |
10519 | |
10520 | /* Alternate canonicalizations of the above. These are somewhat cleaner. */ | |
10521 | if (GET_CODE (x) == AND | |
ec8e098d PB |
10522 | && COMPARISON_P (XEXP (x, 0)) |
10523 | && COMPARISON_P (XEXP (x, 1))) | |
03f1640c RE |
10524 | return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), |
10525 | DOM_CC_X_AND_Y); | |
1646cf41 RE |
10526 | |
10527 | if (GET_CODE (x) == IOR | |
ec8e098d PB |
10528 | && COMPARISON_P (XEXP (x, 0)) |
10529 | && COMPARISON_P (XEXP (x, 1))) | |
03f1640c RE |
10530 | return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), |
10531 | DOM_CC_X_OR_Y); | |
1646cf41 | 10532 | |
defc0463 RE |
10533 | /* An operation (on Thumb) where we want to test for a single bit. |
10534 | This is done by shifting that bit up into the top bit of a | |
10535 | scratch register; we can then branch on the sign bit. */ | |
5b3e6663 | 10536 | if (TARGET_THUMB1 |
defc0463 RE |
10537 | && GET_MODE (x) == SImode |
10538 | && (op == EQ || op == NE) | |
f9fa4363 RE |
10539 | && GET_CODE (x) == ZERO_EXTRACT |
10540 | && XEXP (x, 1) == const1_rtx) | |
defc0463 RE |
10541 | return CC_Nmode; |
10542 | ||
84ed5e79 RE |
10543 | /* An operation that sets the condition codes as a side-effect, the |
10544 | V flag is not set correctly, so we can only use comparisons where | |
10545 | this doesn't matter. (For LT and GE we can use "mi" and "pl" | |
defc0463 | 10546 | instead.) */ |
5b3e6663 | 10547 | /* ??? Does the ZERO_EXTRACT case really apply to thumb2? */ |
84ed5e79 RE |
10548 | if (GET_MODE (x) == SImode |
10549 | && y == const0_rtx | |
10550 | && (op == EQ || op == NE || op == LT || op == GE) | |
10551 | && (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS | |
10552 | || GET_CODE (x) == AND || GET_CODE (x) == IOR | |
10553 | || GET_CODE (x) == XOR || GET_CODE (x) == MULT | |
10554 | || GET_CODE (x) == NOT || GET_CODE (x) == NEG | |
10555 | || GET_CODE (x) == LSHIFTRT | |
10556 | || GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT | |
defc0463 | 10557 | || GET_CODE (x) == ROTATERT |
5b3e6663 | 10558 | || (TARGET_32BIT && GET_CODE (x) == ZERO_EXTRACT))) |
84ed5e79 RE |
10559 | return CC_NOOVmode; |
10560 | ||
84ed5e79 RE |
10561 | if (GET_MODE (x) == QImode && (op == EQ || op == NE)) |
10562 | return CC_Zmode; | |
10563 | ||
bd9c7e23 RE |
10564 | if (GET_MODE (x) == SImode && (op == LTU || op == GEU) |
10565 | && GET_CODE (x) == PLUS | |
10566 | && (rtx_equal_p (XEXP (x, 0), y) || rtx_equal_p (XEXP (x, 1), y))) | |
10567 | return CC_Cmode; | |
10568 | ||
73160ba9 DJ |
10569 | if (GET_MODE (x) == DImode || GET_MODE (y) == DImode) |
10570 | { | |
10571 | /* To keep things simple, always use the Cirrus cfcmp64 if it is | |
10572 | available. */ | |
10573 | if (TARGET_ARM && TARGET_HARD_FLOAT && TARGET_MAVERICK) | |
10574 | return CCmode; | |
10575 | ||
10576 | switch (op) | |
10577 | { | |
10578 | case EQ: | |
10579 | case NE: | |
10580 | /* A DImode comparison against zero can be implemented by | |
10581 | or'ing the two halves together. */ | |
10582 | if (y == const0_rtx) | |
10583 | return CC_Zmode; | |
10584 | ||
10585 | /* We can do an equality test in three Thumb instructions. */ | |
10586 | if (!TARGET_ARM) | |
10587 | return CC_Zmode; | |
10588 | ||
10589 | /* FALLTHROUGH */ | |
10590 | ||
10591 | case LTU: | |
10592 | case LEU: | |
10593 | case GTU: | |
10594 | case GEU: | |
10595 | /* DImode unsigned comparisons can be implemented by cmp + | |
10596 | cmpeq without a scratch register. Not worth doing in | |
10597 | Thumb-2. */ | |
10598 | if (TARGET_ARM) | |
10599 | return CC_CZmode; | |
10600 | ||
10601 | /* FALLTHROUGH */ | |
10602 | ||
10603 | case LT: | |
10604 | case LE: | |
10605 | case GT: | |
10606 | case GE: | |
10607 | /* DImode signed and unsigned comparisons can be implemented | |
10608 | by cmp + sbcs with a scratch register, but that does not | |
10609 | set the Z flag - we must reverse GT/LE/GTU/LEU. */ | |
10610 | gcc_assert (op != EQ && op != NE); | |
10611 | return CC_NCVmode; | |
10612 | ||
10613 | default: | |
10614 | gcc_unreachable (); | |
10615 | } | |
10616 | } | |
10617 | ||
84ed5e79 RE |
10618 | return CCmode; |
10619 | } | |
10620 | ||
ff9940b0 RE |
10621 | /* X and Y are two things to compare using CODE. Emit the compare insn and |
10622 | return the rtx for register 0 in the proper mode. FP means this is a | |
10623 | floating point compare: I don't think that it is needed on the arm. */ | |
ff9940b0 | 10624 | rtx |
e32bac5b | 10625 | arm_gen_compare_reg (enum rtx_code code, rtx x, rtx y) |
ff9940b0 | 10626 | { |
73160ba9 DJ |
10627 | enum machine_mode mode; |
10628 | rtx cc_reg; | |
10629 | int dimode_comparison = GET_MODE (x) == DImode || GET_MODE (y) == DImode; | |
ff9940b0 | 10630 | |
73160ba9 DJ |
10631 | /* We might have X as a constant, Y as a register because of the predicates |
10632 | used for cmpdi. If so, force X to a register here. */ | |
10633 | if (dimode_comparison && !REG_P (x)) | |
10634 | x = force_reg (DImode, x); | |
10635 | ||
10636 | mode = SELECT_CC_MODE (code, x, y); | |
10637 | cc_reg = gen_rtx_REG (mode, CC_REGNUM); | |
10638 | ||
10639 | if (dimode_comparison | |
10640 | && !(TARGET_HARD_FLOAT && TARGET_MAVERICK) | |
10641 | && mode != CC_CZmode) | |
10642 | { | |
10643 | rtx clobber, set; | |
10644 | ||
10645 | /* To compare two non-zero values for equality, XOR them and | |
10646 | then compare against zero. Not used for ARM mode; there | |
10647 | CC_CZmode is cheaper. */ | |
10648 | if (mode == CC_Zmode && y != const0_rtx) | |
10649 | { | |
10650 | x = expand_binop (DImode, xor_optab, x, y, NULL_RTX, 0, OPTAB_WIDEN); | |
10651 | y = const0_rtx; | |
10652 | } | |
10653 | /* A scratch register is required. */ | |
10654 | clobber = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)); | |
10655 | set = gen_rtx_SET (VOIDmode, cc_reg, gen_rtx_COMPARE (mode, x, y)); | |
10656 | emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber))); | |
10657 | } | |
10658 | else | |
10659 | emit_set_insn (cc_reg, gen_rtx_COMPARE (mode, x, y)); | |
ff9940b0 RE |
10660 | |
10661 | return cc_reg; | |
10662 | } | |
10663 | ||
fcd53748 JT |
10664 | /* Generate a sequence of insns that will generate the correct return |
10665 | address mask depending on the physical architecture that the program | |
10666 | is running on. */ | |
fcd53748 | 10667 | rtx |
e32bac5b | 10668 | arm_gen_return_addr_mask (void) |
fcd53748 JT |
10669 | { |
10670 | rtx reg = gen_reg_rtx (Pmode); | |
10671 | ||
10672 | emit_insn (gen_return_addr_mask (reg)); | |
10673 | return reg; | |
10674 | } | |
10675 | ||
0a81f500 | 10676 | void |
e32bac5b | 10677 | arm_reload_in_hi (rtx *operands) |
0a81f500 | 10678 | { |
f9cc092a RE |
10679 | rtx ref = operands[1]; |
10680 | rtx base, scratch; | |
10681 | HOST_WIDE_INT offset = 0; | |
10682 | ||
10683 | if (GET_CODE (ref) == SUBREG) | |
10684 | { | |
ddef6bc7 | 10685 | offset = SUBREG_BYTE (ref); |
f9cc092a RE |
10686 | ref = SUBREG_REG (ref); |
10687 | } | |
10688 | ||
10689 | if (GET_CODE (ref) == REG) | |
10690 | { | |
10691 | /* We have a pseudo which has been spilt onto the stack; there | |
10692 | are two cases here: the first where there is a simple | |
10693 | stack-slot replacement and a second where the stack-slot is | |
10694 | out of range, or is used as a subreg. */ | |
10695 | if (reg_equiv_mem[REGNO (ref)]) | |
10696 | { | |
10697 | ref = reg_equiv_mem[REGNO (ref)]; | |
10698 | base = find_replacement (&XEXP (ref, 0)); | |
10699 | } | |
10700 | else | |
6354dc9b | 10701 | /* The slot is out of range, or was dressed up in a SUBREG. */ |
f9cc092a RE |
10702 | base = reg_equiv_address[REGNO (ref)]; |
10703 | } | |
10704 | else | |
10705 | base = find_replacement (&XEXP (ref, 0)); | |
0a81f500 | 10706 | |
e5e809f4 JL |
10707 | /* Handle the case where the address is too complex to be offset by 1. */ |
10708 | if (GET_CODE (base) == MINUS | |
10709 | || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT)) | |
10710 | { | |
f9cc092a | 10711 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); |
e5e809f4 | 10712 | |
d66437c5 | 10713 | emit_set_insn (base_plus, base); |
e5e809f4 JL |
10714 | base = base_plus; |
10715 | } | |
f9cc092a RE |
10716 | else if (GET_CODE (base) == PLUS) |
10717 | { | |
6354dc9b | 10718 | /* The addend must be CONST_INT, or we would have dealt with it above. */ |
f9cc092a RE |
10719 | HOST_WIDE_INT hi, lo; |
10720 | ||
10721 | offset += INTVAL (XEXP (base, 1)); | |
10722 | base = XEXP (base, 0); | |
10723 | ||
6354dc9b | 10724 | /* Rework the address into a legal sequence of insns. */ |
f9cc092a RE |
10725 | /* Valid range for lo is -4095 -> 4095 */ |
10726 | lo = (offset >= 0 | |
10727 | ? (offset & 0xfff) | |
10728 | : -((-offset) & 0xfff)); | |
10729 | ||
10730 | /* Corner case, if lo is the max offset then we would be out of range | |
10731 | once we have added the additional 1 below, so bump the msb into the | |
10732 | pre-loading insn(s). */ | |
10733 | if (lo == 4095) | |
10734 | lo &= 0x7ff; | |
10735 | ||
30cf4896 KG |
10736 | hi = ((((offset - lo) & (HOST_WIDE_INT) 0xffffffff) |
10737 | ^ (HOST_WIDE_INT) 0x80000000) | |
10738 | - (HOST_WIDE_INT) 0x80000000); | |
f9cc092a | 10739 | |
e6d29d15 | 10740 | gcc_assert (hi + lo == offset); |
f9cc092a RE |
10741 | |
10742 | if (hi != 0) | |
10743 | { | |
10744 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
10745 | ||
10746 | /* Get the base address; addsi3 knows how to handle constants | |
6354dc9b | 10747 | that require more than one insn. */ |
f9cc092a RE |
10748 | emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi))); |
10749 | base = base_plus; | |
10750 | offset = lo; | |
10751 | } | |
10752 | } | |
e5e809f4 | 10753 | |
3a1944a6 RE |
10754 | /* Operands[2] may overlap operands[0] (though it won't overlap |
10755 | operands[1]), that's why we asked for a DImode reg -- so we can | |
10756 | use the bit that does not overlap. */ | |
10757 | if (REGNO (operands[2]) == REGNO (operands[0])) | |
10758 | scratch = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
10759 | else | |
10760 | scratch = gen_rtx_REG (SImode, REGNO (operands[2])); | |
10761 | ||
f9cc092a RE |
10762 | emit_insn (gen_zero_extendqisi2 (scratch, |
10763 | gen_rtx_MEM (QImode, | |
10764 | plus_constant (base, | |
10765 | offset)))); | |
43cffd11 | 10766 | emit_insn (gen_zero_extendqisi2 (gen_rtx_SUBREG (SImode, operands[0], 0), |
f676971a | 10767 | gen_rtx_MEM (QImode, |
f9cc092a RE |
10768 | plus_constant (base, |
10769 | offset + 1)))); | |
5895f793 | 10770 | if (!BYTES_BIG_ENDIAN) |
d66437c5 RE |
10771 | emit_set_insn (gen_rtx_SUBREG (SImode, operands[0], 0), |
10772 | gen_rtx_IOR (SImode, | |
10773 | gen_rtx_ASHIFT | |
10774 | (SImode, | |
10775 | gen_rtx_SUBREG (SImode, operands[0], 0), | |
10776 | GEN_INT (8)), | |
10777 | scratch)); | |
0a81f500 | 10778 | else |
d66437c5 RE |
10779 | emit_set_insn (gen_rtx_SUBREG (SImode, operands[0], 0), |
10780 | gen_rtx_IOR (SImode, | |
10781 | gen_rtx_ASHIFT (SImode, scratch, | |
10782 | GEN_INT (8)), | |
10783 | gen_rtx_SUBREG (SImode, operands[0], 0))); | |
0a81f500 RE |
10784 | } |
10785 | ||
72ac76be | 10786 | /* Handle storing a half-word to memory during reload by synthesizing as two |
f9cc092a RE |
10787 | byte stores. Take care not to clobber the input values until after we |
10788 | have moved them somewhere safe. This code assumes that if the DImode | |
10789 | scratch in operands[2] overlaps either the input value or output address | |
10790 | in some way, then that value must die in this insn (we absolutely need | |
10791 | two scratch registers for some corner cases). */ | |
f3bb6135 | 10792 | void |
e32bac5b | 10793 | arm_reload_out_hi (rtx *operands) |
af48348a | 10794 | { |
f9cc092a RE |
10795 | rtx ref = operands[0]; |
10796 | rtx outval = operands[1]; | |
10797 | rtx base, scratch; | |
10798 | HOST_WIDE_INT offset = 0; | |
10799 | ||
10800 | if (GET_CODE (ref) == SUBREG) | |
10801 | { | |
ddef6bc7 | 10802 | offset = SUBREG_BYTE (ref); |
f9cc092a RE |
10803 | ref = SUBREG_REG (ref); |
10804 | } | |
10805 | ||
f9cc092a RE |
10806 | if (GET_CODE (ref) == REG) |
10807 | { | |
10808 | /* We have a pseudo which has been spilt onto the stack; there | |
10809 | are two cases here: the first where there is a simple | |
10810 | stack-slot replacement and a second where the stack-slot is | |
10811 | out of range, or is used as a subreg. */ | |
10812 | if (reg_equiv_mem[REGNO (ref)]) | |
10813 | { | |
10814 | ref = reg_equiv_mem[REGNO (ref)]; | |
10815 | base = find_replacement (&XEXP (ref, 0)); | |
10816 | } | |
10817 | else | |
6354dc9b | 10818 | /* The slot is out of range, or was dressed up in a SUBREG. */ |
f9cc092a RE |
10819 | base = reg_equiv_address[REGNO (ref)]; |
10820 | } | |
10821 | else | |
10822 | base = find_replacement (&XEXP (ref, 0)); | |
10823 | ||
10824 | scratch = gen_rtx_REG (SImode, REGNO (operands[2])); | |
10825 | ||
10826 | /* Handle the case where the address is too complex to be offset by 1. */ | |
10827 | if (GET_CODE (base) == MINUS | |
10828 | || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT)) | |
10829 | { | |
10830 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
10831 | ||
10832 | /* Be careful not to destroy OUTVAL. */ | |
10833 | if (reg_overlap_mentioned_p (base_plus, outval)) | |
10834 | { | |
10835 | /* Updating base_plus might destroy outval, see if we can | |
10836 | swap the scratch and base_plus. */ | |
5895f793 | 10837 | if (!reg_overlap_mentioned_p (scratch, outval)) |
f9cc092a RE |
10838 | { |
10839 | rtx tmp = scratch; | |
10840 | scratch = base_plus; | |
10841 | base_plus = tmp; | |
10842 | } | |
10843 | else | |
10844 | { | |
10845 | rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2])); | |
10846 | ||
10847 | /* Be conservative and copy OUTVAL into the scratch now, | |
10848 | this should only be necessary if outval is a subreg | |
10849 | of something larger than a word. */ | |
10850 | /* XXX Might this clobber base? I can't see how it can, | |
10851 | since scratch is known to overlap with OUTVAL, and | |
10852 | must be wider than a word. */ | |
10853 | emit_insn (gen_movhi (scratch_hi, outval)); | |
10854 | outval = scratch_hi; | |
10855 | } | |
10856 | } | |
10857 | ||
d66437c5 | 10858 | emit_set_insn (base_plus, base); |
f9cc092a RE |
10859 | base = base_plus; |
10860 | } | |
10861 | else if (GET_CODE (base) == PLUS) | |
10862 | { | |
6354dc9b | 10863 | /* The addend must be CONST_INT, or we would have dealt with it above. */ |
f9cc092a RE |
10864 | HOST_WIDE_INT hi, lo; |
10865 | ||
10866 | offset += INTVAL (XEXP (base, 1)); | |
10867 | base = XEXP (base, 0); | |
10868 | ||
6354dc9b | 10869 | /* Rework the address into a legal sequence of insns. */ |
f9cc092a RE |
10870 | /* Valid range for lo is -4095 -> 4095 */ |
10871 | lo = (offset >= 0 | |
10872 | ? (offset & 0xfff) | |
10873 | : -((-offset) & 0xfff)); | |
10874 | ||
10875 | /* Corner case, if lo is the max offset then we would be out of range | |
10876 | once we have added the additional 1 below, so bump the msb into the | |
10877 | pre-loading insn(s). */ | |
10878 | if (lo == 4095) | |
10879 | lo &= 0x7ff; | |
10880 | ||
30cf4896 KG |
10881 | hi = ((((offset - lo) & (HOST_WIDE_INT) 0xffffffff) |
10882 | ^ (HOST_WIDE_INT) 0x80000000) | |
10883 | - (HOST_WIDE_INT) 0x80000000); | |
f9cc092a | 10884 | |
e6d29d15 | 10885 | gcc_assert (hi + lo == offset); |
f9cc092a RE |
10886 | |
10887 | if (hi != 0) | |
10888 | { | |
10889 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
10890 | ||
10891 | /* Be careful not to destroy OUTVAL. */ | |
10892 | if (reg_overlap_mentioned_p (base_plus, outval)) | |
10893 | { | |
10894 | /* Updating base_plus might destroy outval, see if we | |
10895 | can swap the scratch and base_plus. */ | |
5895f793 | 10896 | if (!reg_overlap_mentioned_p (scratch, outval)) |
f9cc092a RE |
10897 | { |
10898 | rtx tmp = scratch; | |
10899 | scratch = base_plus; | |
10900 | base_plus = tmp; | |
10901 | } | |
10902 | else | |
10903 | { | |
10904 | rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2])); | |
10905 | ||
10906 | /* Be conservative and copy outval into scratch now, | |
10907 | this should only be necessary if outval is a | |
10908 | subreg of something larger than a word. */ | |
10909 | /* XXX Might this clobber base? I can't see how it | |
10910 | can, since scratch is known to overlap with | |
10911 | outval. */ | |
10912 | emit_insn (gen_movhi (scratch_hi, outval)); | |
10913 | outval = scratch_hi; | |
10914 | } | |
10915 | } | |
10916 | ||
10917 | /* Get the base address; addsi3 knows how to handle constants | |
6354dc9b | 10918 | that require more than one insn. */ |
f9cc092a RE |
10919 | emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi))); |
10920 | base = base_plus; | |
10921 | offset = lo; | |
10922 | } | |
10923 | } | |
af48348a | 10924 | |
b5cc037f RE |
10925 | if (BYTES_BIG_ENDIAN) |
10926 | { | |
f676971a | 10927 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, |
f9cc092a | 10928 | plus_constant (base, offset + 1)), |
5d5603e2 | 10929 | gen_lowpart (QImode, outval))); |
f9cc092a RE |
10930 | emit_insn (gen_lshrsi3 (scratch, |
10931 | gen_rtx_SUBREG (SImode, outval, 0), | |
b5cc037f | 10932 | GEN_INT (8))); |
f9cc092a | 10933 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, offset)), |
5d5603e2 | 10934 | gen_lowpart (QImode, scratch))); |
b5cc037f RE |
10935 | } |
10936 | else | |
10937 | { | |
f9cc092a | 10938 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, offset)), |
5d5603e2 | 10939 | gen_lowpart (QImode, outval))); |
f9cc092a RE |
10940 | emit_insn (gen_lshrsi3 (scratch, |
10941 | gen_rtx_SUBREG (SImode, outval, 0), | |
b5cc037f | 10942 | GEN_INT (8))); |
f9cc092a RE |
10943 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, |
10944 | plus_constant (base, offset + 1)), | |
5d5603e2 | 10945 | gen_lowpart (QImode, scratch))); |
b5cc037f | 10946 | } |
af48348a | 10947 | } |
866af8a9 JB |
10948 | |
10949 | /* Return true if a type must be passed in memory. For AAPCS, small aggregates | |
10950 | (padded to the size of a word) should be passed in a register. */ | |
10951 | ||
10952 | static bool | |
586de218 | 10953 | arm_must_pass_in_stack (enum machine_mode mode, const_tree type) |
866af8a9 JB |
10954 | { |
10955 | if (TARGET_AAPCS_BASED) | |
10956 | return must_pass_in_stack_var_size (mode, type); | |
10957 | else | |
10958 | return must_pass_in_stack_var_size_or_pad (mode, type); | |
10959 | } | |
10960 | ||
10961 | ||
10962 | /* For use by FUNCTION_ARG_PADDING (MODE, TYPE). | |
10963 | Return true if an argument passed on the stack should be padded upwards, | |
5a29b385 PB |
10964 | i.e. if the least-significant byte has useful data. |
10965 | For legacy APCS ABIs we use the default. For AAPCS based ABIs small | |
10966 | aggregate types are placed in the lowest memory address. */ | |
866af8a9 JB |
10967 | |
10968 | bool | |
586de218 | 10969 | arm_pad_arg_upward (enum machine_mode mode, const_tree type) |
866af8a9 JB |
10970 | { |
10971 | if (!TARGET_AAPCS_BASED) | |
5a29b385 | 10972 | return DEFAULT_FUNCTION_ARG_PADDING(mode, type) == upward; |
866af8a9 JB |
10973 | |
10974 | if (type && BYTES_BIG_ENDIAN && INTEGRAL_TYPE_P (type)) | |
10975 | return false; | |
10976 | ||
10977 | return true; | |
10978 | } | |
10979 | ||
10980 | ||
10981 | /* Similarly, for use by BLOCK_REG_PADDING (MODE, TYPE, FIRST). | |
10982 | For non-AAPCS, return !BYTES_BIG_ENDIAN if the least significant | |
10983 | byte of the register has useful data, and return the opposite if the | |
10984 | most significant byte does. | |
10985 | For AAPCS, small aggregates and small complex types are always padded | |
10986 | upwards. */ | |
10987 | ||
10988 | bool | |
10989 | arm_pad_reg_upward (enum machine_mode mode ATTRIBUTE_UNUSED, | |
10990 | tree type, int first ATTRIBUTE_UNUSED) | |
10991 | { | |
10992 | if (TARGET_AAPCS_BASED | |
10993 | && BYTES_BIG_ENDIAN | |
10994 | && (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE) | |
10995 | && int_size_in_bytes (type) <= 4) | |
10996 | return true; | |
10997 | ||
10998 | /* Otherwise, use default padding. */ | |
10999 | return !BYTES_BIG_ENDIAN; | |
11000 | } | |
11001 | ||
2b835d68 | 11002 | \f |
d5b7b3ae RE |
11003 | /* Print a symbolic form of X to the debug file, F. */ |
11004 | static void | |
e32bac5b | 11005 | arm_print_value (FILE *f, rtx x) |
d5b7b3ae RE |
11006 | { |
11007 | switch (GET_CODE (x)) | |
11008 | { | |
11009 | case CONST_INT: | |
11010 | fprintf (f, HOST_WIDE_INT_PRINT_HEX, INTVAL (x)); | |
11011 | return; | |
11012 | ||
11013 | case CONST_DOUBLE: | |
11014 | fprintf (f, "<0x%lx,0x%lx>", (long)XWINT (x, 2), (long)XWINT (x, 3)); | |
11015 | return; | |
11016 | ||
5a9335ef NC |
11017 | case CONST_VECTOR: |
11018 | { | |
11019 | int i; | |
11020 | ||
11021 | fprintf (f, "<"); | |
11022 | for (i = 0; i < CONST_VECTOR_NUNITS (x); i++) | |
11023 | { | |
11024 | fprintf (f, HOST_WIDE_INT_PRINT_HEX, INTVAL (CONST_VECTOR_ELT (x, i))); | |
11025 | if (i < (CONST_VECTOR_NUNITS (x) - 1)) | |
11026 | fputc (',', f); | |
11027 | } | |
11028 | fprintf (f, ">"); | |
11029 | } | |
11030 | return; | |
11031 | ||
d5b7b3ae RE |
11032 | case CONST_STRING: |
11033 | fprintf (f, "\"%s\"", XSTR (x, 0)); | |
11034 | return; | |
11035 | ||
11036 | case SYMBOL_REF: | |
11037 | fprintf (f, "`%s'", XSTR (x, 0)); | |
11038 | return; | |
11039 | ||
11040 | case LABEL_REF: | |
11041 | fprintf (f, "L%d", INSN_UID (XEXP (x, 0))); | |
11042 | return; | |
11043 | ||
11044 | case CONST: | |
11045 | arm_print_value (f, XEXP (x, 0)); | |
11046 | return; | |
11047 | ||
11048 | case PLUS: | |
11049 | arm_print_value (f, XEXP (x, 0)); | |
11050 | fprintf (f, "+"); | |
11051 | arm_print_value (f, XEXP (x, 1)); | |
11052 | return; | |
11053 | ||
11054 | case PC: | |
11055 | fprintf (f, "pc"); | |
11056 | return; | |
11057 | ||
11058 | default: | |
11059 | fprintf (f, "????"); | |
11060 | return; | |
11061 | } | |
11062 | } | |
11063 | \f | |
2b835d68 | 11064 | /* Routines for manipulation of the constant pool. */ |
2b835d68 | 11065 | |
949d79eb RE |
11066 | /* Arm instructions cannot load a large constant directly into a |
11067 | register; they have to come from a pc relative load. The constant | |
11068 | must therefore be placed in the addressable range of the pc | |
11069 | relative load. Depending on the precise pc relative load | |
11070 | instruction the range is somewhere between 256 bytes and 4k. This | |
11071 | means that we often have to dump a constant inside a function, and | |
2b835d68 RE |
11072 | generate code to branch around it. |
11073 | ||
949d79eb RE |
11074 | It is important to minimize this, since the branches will slow |
11075 | things down and make the code larger. | |
2b835d68 | 11076 | |
949d79eb RE |
11077 | Normally we can hide the table after an existing unconditional |
11078 | branch so that there is no interruption of the flow, but in the | |
11079 | worst case the code looks like this: | |
2b835d68 RE |
11080 | |
11081 | ldr rn, L1 | |
949d79eb | 11082 | ... |
2b835d68 RE |
11083 | b L2 |
11084 | align | |
11085 | L1: .long value | |
11086 | L2: | |
949d79eb | 11087 | ... |
2b835d68 | 11088 | |
2b835d68 | 11089 | ldr rn, L3 |
949d79eb | 11090 | ... |
2b835d68 RE |
11091 | b L4 |
11092 | align | |
2b835d68 RE |
11093 | L3: .long value |
11094 | L4: | |
949d79eb RE |
11095 | ... |
11096 | ||
11097 | We fix this by performing a scan after scheduling, which notices | |
11098 | which instructions need to have their operands fetched from the | |
11099 | constant table and builds the table. | |
11100 | ||
11101 | The algorithm starts by building a table of all the constants that | |
11102 | need fixing up and all the natural barriers in the function (places | |
11103 | where a constant table can be dropped without breaking the flow). | |
11104 | For each fixup we note how far the pc-relative replacement will be | |
11105 | able to reach and the offset of the instruction into the function. | |
11106 | ||
11107 | Having built the table we then group the fixes together to form | |
11108 | tables that are as large as possible (subject to addressing | |
11109 | constraints) and emit each table of constants after the last | |
11110 | barrier that is within range of all the instructions in the group. | |
11111 | If a group does not contain a barrier, then we forcibly create one | |
11112 | by inserting a jump instruction into the flow. Once the table has | |
11113 | been inserted, the insns are then modified to reference the | |
11114 | relevant entry in the pool. | |
11115 | ||
6354dc9b | 11116 | Possible enhancements to the algorithm (not implemented) are: |
949d79eb | 11117 | |
d5b7b3ae | 11118 | 1) For some processors and object formats, there may be benefit in |
949d79eb RE |
11119 | aligning the pools to the start of cache lines; this alignment |
11120 | would need to be taken into account when calculating addressability | |
6354dc9b | 11121 | of a pool. */ |
2b835d68 | 11122 | |
d5b7b3ae RE |
11123 | /* These typedefs are located at the start of this file, so that |
11124 | they can be used in the prototypes there. This comment is to | |
11125 | remind readers of that fact so that the following structures | |
11126 | can be understood more easily. | |
11127 | ||
11128 | typedef struct minipool_node Mnode; | |
11129 | typedef struct minipool_fixup Mfix; */ | |
11130 | ||
11131 | struct minipool_node | |
11132 | { | |
11133 | /* Doubly linked chain of entries. */ | |
11134 | Mnode * next; | |
11135 | Mnode * prev; | |
11136 | /* The maximum offset into the code that this entry can be placed. While | |
11137 | pushing fixes for forward references, all entries are sorted in order | |
11138 | of increasing max_address. */ | |
11139 | HOST_WIDE_INT max_address; | |
5519a4f9 | 11140 | /* Similarly for an entry inserted for a backwards ref. */ |
d5b7b3ae RE |
11141 | HOST_WIDE_INT min_address; |
11142 | /* The number of fixes referencing this entry. This can become zero | |
11143 | if we "unpush" an entry. In this case we ignore the entry when we | |
11144 | come to emit the code. */ | |
11145 | int refcount; | |
11146 | /* The offset from the start of the minipool. */ | |
11147 | HOST_WIDE_INT offset; | |
11148 | /* The value in table. */ | |
11149 | rtx value; | |
11150 | /* The mode of value. */ | |
11151 | enum machine_mode mode; | |
5a9335ef NC |
11152 | /* The size of the value. With iWMMXt enabled |
11153 | sizes > 4 also imply an alignment of 8-bytes. */ | |
d5b7b3ae RE |
11154 | int fix_size; |
11155 | }; | |
11156 | ||
11157 | struct minipool_fixup | |
2b835d68 | 11158 | { |
d5b7b3ae RE |
11159 | Mfix * next; |
11160 | rtx insn; | |
11161 | HOST_WIDE_INT address; | |
11162 | rtx * loc; | |
11163 | enum machine_mode mode; | |
11164 | int fix_size; | |
11165 | rtx value; | |
11166 | Mnode * minipool; | |
11167 | HOST_WIDE_INT forwards; | |
11168 | HOST_WIDE_INT backwards; | |
11169 | }; | |
2b835d68 | 11170 | |
d5b7b3ae RE |
11171 | /* Fixes less than a word need padding out to a word boundary. */ |
11172 | #define MINIPOOL_FIX_SIZE(mode) \ | |
11173 | (GET_MODE_SIZE ((mode)) >= 4 ? GET_MODE_SIZE ((mode)) : 4) | |
2b835d68 | 11174 | |
d5b7b3ae RE |
11175 | static Mnode * minipool_vector_head; |
11176 | static Mnode * minipool_vector_tail; | |
11177 | static rtx minipool_vector_label; | |
34a9f549 | 11178 | static int minipool_pad; |
332072db | 11179 | |
d5b7b3ae RE |
11180 | /* The linked list of all minipool fixes required for this function. */ |
11181 | Mfix * minipool_fix_head; | |
11182 | Mfix * minipool_fix_tail; | |
11183 | /* The fix entry for the current minipool, once it has been placed. */ | |
11184 | Mfix * minipool_barrier; | |
11185 | ||
11186 | /* Determines if INSN is the start of a jump table. Returns the end | |
11187 | of the TABLE or NULL_RTX. */ | |
11188 | static rtx | |
e32bac5b | 11189 | is_jump_table (rtx insn) |
2b835d68 | 11190 | { |
d5b7b3ae | 11191 | rtx table; |
f676971a | 11192 | |
d5b7b3ae RE |
11193 | if (GET_CODE (insn) == JUMP_INSN |
11194 | && JUMP_LABEL (insn) != NULL | |
11195 | && ((table = next_real_insn (JUMP_LABEL (insn))) | |
11196 | == next_real_insn (insn)) | |
11197 | && table != NULL | |
11198 | && GET_CODE (table) == JUMP_INSN | |
11199 | && (GET_CODE (PATTERN (table)) == ADDR_VEC | |
11200 | || GET_CODE (PATTERN (table)) == ADDR_DIFF_VEC)) | |
11201 | return table; | |
11202 | ||
11203 | return NULL_RTX; | |
2b835d68 RE |
11204 | } |
11205 | ||
657d9449 RE |
11206 | #ifndef JUMP_TABLES_IN_TEXT_SECTION |
11207 | #define JUMP_TABLES_IN_TEXT_SECTION 0 | |
11208 | #endif | |
11209 | ||
d5b7b3ae | 11210 | static HOST_WIDE_INT |
e32bac5b | 11211 | get_jump_table_size (rtx insn) |
2b835d68 | 11212 | { |
657d9449 RE |
11213 | /* ADDR_VECs only take room if read-only data does into the text |
11214 | section. */ | |
d6b5193b | 11215 | if (JUMP_TABLES_IN_TEXT_SECTION || readonly_data_section == text_section) |
657d9449 RE |
11216 | { |
11217 | rtx body = PATTERN (insn); | |
11218 | int elt = GET_CODE (body) == ADDR_DIFF_VEC ? 1 : 0; | |
5b3e6663 PB |
11219 | HOST_WIDE_INT size; |
11220 | HOST_WIDE_INT modesize; | |
2b835d68 | 11221 | |
5b3e6663 PB |
11222 | modesize = GET_MODE_SIZE (GET_MODE (body)); |
11223 | size = modesize * XVECLEN (body, elt); | |
11224 | switch (modesize) | |
11225 | { | |
11226 | case 1: | |
88512ba0 | 11227 | /* Round up size of TBB table to a halfword boundary. */ |
5b3e6663 PB |
11228 | size = (size + 1) & ~(HOST_WIDE_INT)1; |
11229 | break; | |
11230 | case 2: | |
7a085dce | 11231 | /* No padding necessary for TBH. */ |
5b3e6663 PB |
11232 | break; |
11233 | case 4: | |
11234 | /* Add two bytes for alignment on Thumb. */ | |
11235 | if (TARGET_THUMB) | |
11236 | size += 2; | |
11237 | break; | |
11238 | default: | |
11239 | gcc_unreachable (); | |
11240 | } | |
11241 | return size; | |
657d9449 RE |
11242 | } |
11243 | ||
11244 | return 0; | |
d5b7b3ae | 11245 | } |
2b835d68 | 11246 | |
d5b7b3ae RE |
11247 | /* Move a minipool fix MP from its current location to before MAX_MP. |
11248 | If MAX_MP is NULL, then MP doesn't need moving, but the addressing | |
093354e0 | 11249 | constraints may need updating. */ |
d5b7b3ae | 11250 | static Mnode * |
e32bac5b RE |
11251 | move_minipool_fix_forward_ref (Mnode *mp, Mnode *max_mp, |
11252 | HOST_WIDE_INT max_address) | |
d5b7b3ae | 11253 | { |
e6d29d15 NS |
11254 | /* The code below assumes these are different. */ |
11255 | gcc_assert (mp != max_mp); | |
d5b7b3ae RE |
11256 | |
11257 | if (max_mp == NULL) | |
11258 | { | |
11259 | if (max_address < mp->max_address) | |
11260 | mp->max_address = max_address; | |
11261 | } | |
11262 | else | |
2b835d68 | 11263 | { |
d5b7b3ae RE |
11264 | if (max_address > max_mp->max_address - mp->fix_size) |
11265 | mp->max_address = max_mp->max_address - mp->fix_size; | |
11266 | else | |
11267 | mp->max_address = max_address; | |
2b835d68 | 11268 | |
d5b7b3ae RE |
11269 | /* Unlink MP from its current position. Since max_mp is non-null, |
11270 | mp->prev must be non-null. */ | |
11271 | mp->prev->next = mp->next; | |
11272 | if (mp->next != NULL) | |
11273 | mp->next->prev = mp->prev; | |
11274 | else | |
11275 | minipool_vector_tail = mp->prev; | |
2b835d68 | 11276 | |
d5b7b3ae RE |
11277 | /* Re-insert it before MAX_MP. */ |
11278 | mp->next = max_mp; | |
11279 | mp->prev = max_mp->prev; | |
11280 | max_mp->prev = mp; | |
f676971a | 11281 | |
d5b7b3ae RE |
11282 | if (mp->prev != NULL) |
11283 | mp->prev->next = mp; | |
11284 | else | |
11285 | minipool_vector_head = mp; | |
11286 | } | |
2b835d68 | 11287 | |
d5b7b3ae RE |
11288 | /* Save the new entry. */ |
11289 | max_mp = mp; | |
11290 | ||
d6a7951f | 11291 | /* Scan over the preceding entries and adjust their addresses as |
d5b7b3ae RE |
11292 | required. */ |
11293 | while (mp->prev != NULL | |
11294 | && mp->prev->max_address > mp->max_address - mp->prev->fix_size) | |
11295 | { | |
11296 | mp->prev->max_address = mp->max_address - mp->prev->fix_size; | |
11297 | mp = mp->prev; | |
2b835d68 RE |
11298 | } |
11299 | ||
d5b7b3ae | 11300 | return max_mp; |
2b835d68 RE |
11301 | } |
11302 | ||
d5b7b3ae RE |
11303 | /* Add a constant to the minipool for a forward reference. Returns the |
11304 | node added or NULL if the constant will not fit in this pool. */ | |
11305 | static Mnode * | |
e32bac5b | 11306 | add_minipool_forward_ref (Mfix *fix) |
d5b7b3ae RE |
11307 | { |
11308 | /* If set, max_mp is the first pool_entry that has a lower | |
11309 | constraint than the one we are trying to add. */ | |
11310 | Mnode * max_mp = NULL; | |
34a9f549 | 11311 | HOST_WIDE_INT max_address = fix->address + fix->forwards - minipool_pad; |
d5b7b3ae | 11312 | Mnode * mp; |
f676971a | 11313 | |
7a7017bc PB |
11314 | /* If the minipool starts before the end of FIX->INSN then this FIX |
11315 | can not be placed into the current pool. Furthermore, adding the | |
11316 | new constant pool entry may cause the pool to start FIX_SIZE bytes | |
11317 | earlier. */ | |
d5b7b3ae | 11318 | if (minipool_vector_head && |
7a7017bc PB |
11319 | (fix->address + get_attr_length (fix->insn) |
11320 | >= minipool_vector_head->max_address - fix->fix_size)) | |
d5b7b3ae | 11321 | return NULL; |
2b835d68 | 11322 | |
d5b7b3ae RE |
11323 | /* Scan the pool to see if a constant with the same value has |
11324 | already been added. While we are doing this, also note the | |
11325 | location where we must insert the constant if it doesn't already | |
11326 | exist. */ | |
11327 | for (mp = minipool_vector_head; mp != NULL; mp = mp->next) | |
11328 | { | |
11329 | if (GET_CODE (fix->value) == GET_CODE (mp->value) | |
11330 | && fix->mode == mp->mode | |
11331 | && (GET_CODE (fix->value) != CODE_LABEL | |
11332 | || (CODE_LABEL_NUMBER (fix->value) | |
11333 | == CODE_LABEL_NUMBER (mp->value))) | |
11334 | && rtx_equal_p (fix->value, mp->value)) | |
11335 | { | |
11336 | /* More than one fix references this entry. */ | |
11337 | mp->refcount++; | |
11338 | return move_minipool_fix_forward_ref (mp, max_mp, max_address); | |
11339 | } | |
11340 | ||
11341 | /* Note the insertion point if necessary. */ | |
11342 | if (max_mp == NULL | |
11343 | && mp->max_address > max_address) | |
11344 | max_mp = mp; | |
5a9335ef NC |
11345 | |
11346 | /* If we are inserting an 8-bytes aligned quantity and | |
11347 | we have not already found an insertion point, then | |
11348 | make sure that all such 8-byte aligned quantities are | |
11349 | placed at the start of the pool. */ | |
5848830f | 11350 | if (ARM_DOUBLEWORD_ALIGN |
5a9335ef | 11351 | && max_mp == NULL |
88f77cba JB |
11352 | && fix->fix_size >= 8 |
11353 | && mp->fix_size < 8) | |
5a9335ef NC |
11354 | { |
11355 | max_mp = mp; | |
11356 | max_address = mp->max_address; | |
11357 | } | |
d5b7b3ae RE |
11358 | } |
11359 | ||
11360 | /* The value is not currently in the minipool, so we need to create | |
11361 | a new entry for it. If MAX_MP is NULL, the entry will be put on | |
11362 | the end of the list since the placement is less constrained than | |
11363 | any existing entry. Otherwise, we insert the new fix before | |
6bc82793 | 11364 | MAX_MP and, if necessary, adjust the constraints on the other |
d5b7b3ae | 11365 | entries. */ |
5ed6ace5 | 11366 | mp = XNEW (Mnode); |
d5b7b3ae RE |
11367 | mp->fix_size = fix->fix_size; |
11368 | mp->mode = fix->mode; | |
11369 | mp->value = fix->value; | |
11370 | mp->refcount = 1; | |
11371 | /* Not yet required for a backwards ref. */ | |
11372 | mp->min_address = -65536; | |
11373 | ||
11374 | if (max_mp == NULL) | |
11375 | { | |
11376 | mp->max_address = max_address; | |
11377 | mp->next = NULL; | |
11378 | mp->prev = minipool_vector_tail; | |
11379 | ||
11380 | if (mp->prev == NULL) | |
11381 | { | |
11382 | minipool_vector_head = mp; | |
11383 | minipool_vector_label = gen_label_rtx (); | |
7551cbc7 | 11384 | } |
2b835d68 | 11385 | else |
d5b7b3ae | 11386 | mp->prev->next = mp; |
2b835d68 | 11387 | |
d5b7b3ae RE |
11388 | minipool_vector_tail = mp; |
11389 | } | |
11390 | else | |
11391 | { | |
11392 | if (max_address > max_mp->max_address - mp->fix_size) | |
11393 | mp->max_address = max_mp->max_address - mp->fix_size; | |
11394 | else | |
11395 | mp->max_address = max_address; | |
11396 | ||
11397 | mp->next = max_mp; | |
11398 | mp->prev = max_mp->prev; | |
11399 | max_mp->prev = mp; | |
11400 | if (mp->prev != NULL) | |
11401 | mp->prev->next = mp; | |
11402 | else | |
11403 | minipool_vector_head = mp; | |
11404 | } | |
11405 | ||
11406 | /* Save the new entry. */ | |
11407 | max_mp = mp; | |
11408 | ||
d6a7951f | 11409 | /* Scan over the preceding entries and adjust their addresses as |
d5b7b3ae RE |
11410 | required. */ |
11411 | while (mp->prev != NULL | |
11412 | && mp->prev->max_address > mp->max_address - mp->prev->fix_size) | |
11413 | { | |
11414 | mp->prev->max_address = mp->max_address - mp->prev->fix_size; | |
11415 | mp = mp->prev; | |
2b835d68 RE |
11416 | } |
11417 | ||
d5b7b3ae RE |
11418 | return max_mp; |
11419 | } | |
11420 | ||
11421 | static Mnode * | |
e32bac5b RE |
11422 | move_minipool_fix_backward_ref (Mnode *mp, Mnode *min_mp, |
11423 | HOST_WIDE_INT min_address) | |
d5b7b3ae RE |
11424 | { |
11425 | HOST_WIDE_INT offset; | |
11426 | ||
e6d29d15 NS |
11427 | /* The code below assumes these are different. */ |
11428 | gcc_assert (mp != min_mp); | |
d5b7b3ae RE |
11429 | |
11430 | if (min_mp == NULL) | |
2b835d68 | 11431 | { |
d5b7b3ae RE |
11432 | if (min_address > mp->min_address) |
11433 | mp->min_address = min_address; | |
11434 | } | |
11435 | else | |
11436 | { | |
11437 | /* We will adjust this below if it is too loose. */ | |
11438 | mp->min_address = min_address; | |
11439 | ||
11440 | /* Unlink MP from its current position. Since min_mp is non-null, | |
11441 | mp->next must be non-null. */ | |
11442 | mp->next->prev = mp->prev; | |
11443 | if (mp->prev != NULL) | |
11444 | mp->prev->next = mp->next; | |
11445 | else | |
11446 | minipool_vector_head = mp->next; | |
11447 | ||
11448 | /* Reinsert it after MIN_MP. */ | |
11449 | mp->prev = min_mp; | |
11450 | mp->next = min_mp->next; | |
11451 | min_mp->next = mp; | |
11452 | if (mp->next != NULL) | |
11453 | mp->next->prev = mp; | |
2b835d68 | 11454 | else |
d5b7b3ae RE |
11455 | minipool_vector_tail = mp; |
11456 | } | |
11457 | ||
11458 | min_mp = mp; | |
11459 | ||
11460 | offset = 0; | |
11461 | for (mp = minipool_vector_head; mp != NULL; mp = mp->next) | |
11462 | { | |
11463 | mp->offset = offset; | |
11464 | if (mp->refcount > 0) | |
11465 | offset += mp->fix_size; | |
11466 | ||
11467 | if (mp->next && mp->next->min_address < mp->min_address + mp->fix_size) | |
11468 | mp->next->min_address = mp->min_address + mp->fix_size; | |
11469 | } | |
11470 | ||
11471 | return min_mp; | |
f676971a | 11472 | } |
d5b7b3ae RE |
11473 | |
11474 | /* Add a constant to the minipool for a backward reference. Returns the | |
f676971a | 11475 | node added or NULL if the constant will not fit in this pool. |
d5b7b3ae RE |
11476 | |
11477 | Note that the code for insertion for a backwards reference can be | |
11478 | somewhat confusing because the calculated offsets for each fix do | |
11479 | not take into account the size of the pool (which is still under | |
11480 | construction. */ | |
11481 | static Mnode * | |
e32bac5b | 11482 | add_minipool_backward_ref (Mfix *fix) |
d5b7b3ae RE |
11483 | { |
11484 | /* If set, min_mp is the last pool_entry that has a lower constraint | |
11485 | than the one we are trying to add. */ | |
e32bac5b | 11486 | Mnode *min_mp = NULL; |
d5b7b3ae RE |
11487 | /* This can be negative, since it is only a constraint. */ |
11488 | HOST_WIDE_INT min_address = fix->address - fix->backwards; | |
e32bac5b | 11489 | Mnode *mp; |
d5b7b3ae RE |
11490 | |
11491 | /* If we can't reach the current pool from this insn, or if we can't | |
11492 | insert this entry at the end of the pool without pushing other | |
11493 | fixes out of range, then we don't try. This ensures that we | |
11494 | can't fail later on. */ | |
11495 | if (min_address >= minipool_barrier->address | |
11496 | || (minipool_vector_tail->min_address + fix->fix_size | |
11497 | >= minipool_barrier->address)) | |
11498 | return NULL; | |
11499 | ||
11500 | /* Scan the pool to see if a constant with the same value has | |
11501 | already been added. While we are doing this, also note the | |
11502 | location where we must insert the constant if it doesn't already | |
11503 | exist. */ | |
11504 | for (mp = minipool_vector_tail; mp != NULL; mp = mp->prev) | |
11505 | { | |
11506 | if (GET_CODE (fix->value) == GET_CODE (mp->value) | |
11507 | && fix->mode == mp->mode | |
11508 | && (GET_CODE (fix->value) != CODE_LABEL | |
11509 | || (CODE_LABEL_NUMBER (fix->value) | |
11510 | == CODE_LABEL_NUMBER (mp->value))) | |
11511 | && rtx_equal_p (fix->value, mp->value) | |
11512 | /* Check that there is enough slack to move this entry to the | |
11513 | end of the table (this is conservative). */ | |
f676971a EC |
11514 | && (mp->max_address |
11515 | > (minipool_barrier->address | |
d5b7b3ae RE |
11516 | + minipool_vector_tail->offset |
11517 | + minipool_vector_tail->fix_size))) | |
11518 | { | |
11519 | mp->refcount++; | |
11520 | return move_minipool_fix_backward_ref (mp, min_mp, min_address); | |
11521 | } | |
11522 | ||
11523 | if (min_mp != NULL) | |
11524 | mp->min_address += fix->fix_size; | |
11525 | else | |
11526 | { | |
11527 | /* Note the insertion point if necessary. */ | |
11528 | if (mp->min_address < min_address) | |
5a9335ef NC |
11529 | { |
11530 | /* For now, we do not allow the insertion of 8-byte alignment | |
11531 | requiring nodes anywhere but at the start of the pool. */ | |
5848830f | 11532 | if (ARM_DOUBLEWORD_ALIGN |
88f77cba | 11533 | && fix->fix_size >= 8 && mp->fix_size < 8) |
5a9335ef NC |
11534 | return NULL; |
11535 | else | |
11536 | min_mp = mp; | |
11537 | } | |
d5b7b3ae RE |
11538 | else if (mp->max_address |
11539 | < minipool_barrier->address + mp->offset + fix->fix_size) | |
11540 | { | |
11541 | /* Inserting before this entry would push the fix beyond | |
11542 | its maximum address (which can happen if we have | |
11543 | re-located a forwards fix); force the new fix to come | |
11544 | after it. */ | |
853ff9e2 JM |
11545 | if (ARM_DOUBLEWORD_ALIGN |
11546 | && fix->fix_size >= 8 && mp->fix_size < 8) | |
11547 | return NULL; | |
11548 | else | |
11549 | { | |
11550 | min_mp = mp; | |
11551 | min_address = mp->min_address + fix->fix_size; | |
11552 | } | |
d5b7b3ae | 11553 | } |
853ff9e2 JM |
11554 | /* Do not insert a non-8-byte aligned quantity before 8-byte |
11555 | aligned quantities. */ | |
5848830f | 11556 | else if (ARM_DOUBLEWORD_ALIGN |
853ff9e2 JM |
11557 | && fix->fix_size < 8 |
11558 | && mp->fix_size >= 8) | |
5a9335ef NC |
11559 | { |
11560 | min_mp = mp; | |
11561 | min_address = mp->min_address + fix->fix_size; | |
11562 | } | |
d5b7b3ae RE |
11563 | } |
11564 | } | |
11565 | ||
11566 | /* We need to create a new entry. */ | |
5ed6ace5 | 11567 | mp = XNEW (Mnode); |
d5b7b3ae RE |
11568 | mp->fix_size = fix->fix_size; |
11569 | mp->mode = fix->mode; | |
11570 | mp->value = fix->value; | |
11571 | mp->refcount = 1; | |
11572 | mp->max_address = minipool_barrier->address + 65536; | |
11573 | ||
11574 | mp->min_address = min_address; | |
11575 | ||
11576 | if (min_mp == NULL) | |
11577 | { | |
11578 | mp->prev = NULL; | |
11579 | mp->next = minipool_vector_head; | |
11580 | ||
11581 | if (mp->next == NULL) | |
11582 | { | |
11583 | minipool_vector_tail = mp; | |
11584 | minipool_vector_label = gen_label_rtx (); | |
11585 | } | |
11586 | else | |
11587 | mp->next->prev = mp; | |
11588 | ||
11589 | minipool_vector_head = mp; | |
11590 | } | |
11591 | else | |
11592 | { | |
11593 | mp->next = min_mp->next; | |
11594 | mp->prev = min_mp; | |
11595 | min_mp->next = mp; | |
f676971a | 11596 | |
d5b7b3ae RE |
11597 | if (mp->next != NULL) |
11598 | mp->next->prev = mp; | |
11599 | else | |
11600 | minipool_vector_tail = mp; | |
11601 | } | |
11602 | ||
11603 | /* Save the new entry. */ | |
11604 | min_mp = mp; | |
11605 | ||
11606 | if (mp->prev) | |
11607 | mp = mp->prev; | |
11608 | else | |
11609 | mp->offset = 0; | |
11610 | ||
11611 | /* Scan over the following entries and adjust their offsets. */ | |
11612 | while (mp->next != NULL) | |
11613 | { | |
11614 | if (mp->next->min_address < mp->min_address + mp->fix_size) | |
11615 | mp->next->min_address = mp->min_address + mp->fix_size; | |
11616 | ||
11617 | if (mp->refcount) | |
11618 | mp->next->offset = mp->offset + mp->fix_size; | |
11619 | else | |
11620 | mp->next->offset = mp->offset; | |
11621 | ||
11622 | mp = mp->next; | |
11623 | } | |
11624 | ||
11625 | return min_mp; | |
11626 | } | |
11627 | ||
11628 | static void | |
e32bac5b | 11629 | assign_minipool_offsets (Mfix *barrier) |
d5b7b3ae RE |
11630 | { |
11631 | HOST_WIDE_INT offset = 0; | |
e32bac5b | 11632 | Mnode *mp; |
d5b7b3ae RE |
11633 | |
11634 | minipool_barrier = barrier; | |
11635 | ||
11636 | for (mp = minipool_vector_head; mp != NULL; mp = mp->next) | |
11637 | { | |
11638 | mp->offset = offset; | |
f676971a | 11639 | |
d5b7b3ae RE |
11640 | if (mp->refcount > 0) |
11641 | offset += mp->fix_size; | |
11642 | } | |
11643 | } | |
11644 | ||
11645 | /* Output the literal table */ | |
11646 | static void | |
e32bac5b | 11647 | dump_minipool (rtx scan) |
d5b7b3ae | 11648 | { |
5a9335ef NC |
11649 | Mnode * mp; |
11650 | Mnode * nmp; | |
11651 | int align64 = 0; | |
11652 | ||
5848830f | 11653 | if (ARM_DOUBLEWORD_ALIGN) |
5a9335ef | 11654 | for (mp = minipool_vector_head; mp != NULL; mp = mp->next) |
88f77cba | 11655 | if (mp->refcount > 0 && mp->fix_size >= 8) |
5a9335ef NC |
11656 | { |
11657 | align64 = 1; | |
11658 | break; | |
11659 | } | |
d5b7b3ae | 11660 | |
c263766c RH |
11661 | if (dump_file) |
11662 | fprintf (dump_file, | |
5a9335ef NC |
11663 | ";; Emitting minipool after insn %u; address %ld; align %d (bytes)\n", |
11664 | INSN_UID (scan), (unsigned long) minipool_barrier->address, align64 ? 8 : 4); | |
d5b7b3ae RE |
11665 | |
11666 | scan = emit_label_after (gen_label_rtx (), scan); | |
5a9335ef | 11667 | scan = emit_insn_after (align64 ? gen_align_8 () : gen_align_4 (), scan); |
d5b7b3ae RE |
11668 | scan = emit_label_after (minipool_vector_label, scan); |
11669 | ||
11670 | for (mp = minipool_vector_head; mp != NULL; mp = nmp) | |
11671 | { | |
11672 | if (mp->refcount > 0) | |
11673 | { | |
c263766c | 11674 | if (dump_file) |
d5b7b3ae | 11675 | { |
f676971a | 11676 | fprintf (dump_file, |
d5b7b3ae RE |
11677 | ";; Offset %u, min %ld, max %ld ", |
11678 | (unsigned) mp->offset, (unsigned long) mp->min_address, | |
11679 | (unsigned long) mp->max_address); | |
c263766c RH |
11680 | arm_print_value (dump_file, mp->value); |
11681 | fputc ('\n', dump_file); | |
d5b7b3ae RE |
11682 | } |
11683 | ||
11684 | switch (mp->fix_size) | |
11685 | { | |
11686 | #ifdef HAVE_consttable_1 | |
11687 | case 1: | |
11688 | scan = emit_insn_after (gen_consttable_1 (mp->value), scan); | |
11689 | break; | |
11690 | ||
11691 | #endif | |
11692 | #ifdef HAVE_consttable_2 | |
11693 | case 2: | |
11694 | scan = emit_insn_after (gen_consttable_2 (mp->value), scan); | |
11695 | break; | |
11696 | ||
11697 | #endif | |
11698 | #ifdef HAVE_consttable_4 | |
11699 | case 4: | |
11700 | scan = emit_insn_after (gen_consttable_4 (mp->value), scan); | |
11701 | break; | |
11702 | ||
11703 | #endif | |
11704 | #ifdef HAVE_consttable_8 | |
11705 | case 8: | |
11706 | scan = emit_insn_after (gen_consttable_8 (mp->value), scan); | |
11707 | break; | |
11708 | ||
88f77cba JB |
11709 | #endif |
11710 | #ifdef HAVE_consttable_16 | |
11711 | case 16: | |
11712 | scan = emit_insn_after (gen_consttable_16 (mp->value), scan); | |
11713 | break; | |
11714 | ||
d5b7b3ae RE |
11715 | #endif |
11716 | default: | |
e6d29d15 | 11717 | gcc_unreachable (); |
d5b7b3ae RE |
11718 | } |
11719 | } | |
11720 | ||
11721 | nmp = mp->next; | |
11722 | free (mp); | |
2b835d68 RE |
11723 | } |
11724 | ||
d5b7b3ae RE |
11725 | minipool_vector_head = minipool_vector_tail = NULL; |
11726 | scan = emit_insn_after (gen_consttable_end (), scan); | |
11727 | scan = emit_barrier_after (scan); | |
2b835d68 RE |
11728 | } |
11729 | ||
d5b7b3ae RE |
11730 | /* Return the cost of forcibly inserting a barrier after INSN. */ |
11731 | static int | |
e32bac5b | 11732 | arm_barrier_cost (rtx insn) |
949d79eb | 11733 | { |
d5b7b3ae RE |
11734 | /* Basing the location of the pool on the loop depth is preferable, |
11735 | but at the moment, the basic block information seems to be | |
11736 | corrupt by this stage of the compilation. */ | |
11737 | int base_cost = 50; | |
11738 | rtx next = next_nonnote_insn (insn); | |
11739 | ||
11740 | if (next != NULL && GET_CODE (next) == CODE_LABEL) | |
11741 | base_cost -= 20; | |
11742 | ||
11743 | switch (GET_CODE (insn)) | |
11744 | { | |
11745 | case CODE_LABEL: | |
11746 | /* It will always be better to place the table before the label, rather | |
11747 | than after it. */ | |
f676971a | 11748 | return 50; |
949d79eb | 11749 | |
d5b7b3ae RE |
11750 | case INSN: |
11751 | case CALL_INSN: | |
11752 | return base_cost; | |
11753 | ||
11754 | case JUMP_INSN: | |
11755 | return base_cost - 10; | |
11756 | ||
11757 | default: | |
11758 | return base_cost + 10; | |
11759 | } | |
11760 | } | |
11761 | ||
11762 | /* Find the best place in the insn stream in the range | |
11763 | (FIX->address,MAX_ADDRESS) to forcibly insert a minipool barrier. | |
11764 | Create the barrier by inserting a jump and add a new fix entry for | |
11765 | it. */ | |
11766 | static Mfix * | |
e32bac5b | 11767 | create_fix_barrier (Mfix *fix, HOST_WIDE_INT max_address) |
d5b7b3ae RE |
11768 | { |
11769 | HOST_WIDE_INT count = 0; | |
11770 | rtx barrier; | |
11771 | rtx from = fix->insn; | |
7a7017bc PB |
11772 | /* The instruction after which we will insert the jump. */ |
11773 | rtx selected = NULL; | |
d5b7b3ae | 11774 | int selected_cost; |
7a7017bc | 11775 | /* The address at which the jump instruction will be placed. */ |
d5b7b3ae RE |
11776 | HOST_WIDE_INT selected_address; |
11777 | Mfix * new_fix; | |
11778 | HOST_WIDE_INT max_count = max_address - fix->address; | |
11779 | rtx label = gen_label_rtx (); | |
11780 | ||
11781 | selected_cost = arm_barrier_cost (from); | |
11782 | selected_address = fix->address; | |
11783 | ||
11784 | while (from && count < max_count) | |
11785 | { | |
11786 | rtx tmp; | |
11787 | int new_cost; | |
11788 | ||
11789 | /* This code shouldn't have been called if there was a natural barrier | |
11790 | within range. */ | |
e6d29d15 | 11791 | gcc_assert (GET_CODE (from) != BARRIER); |
d5b7b3ae RE |
11792 | |
11793 | /* Count the length of this insn. */ | |
11794 | count += get_attr_length (from); | |
11795 | ||
11796 | /* If there is a jump table, add its length. */ | |
11797 | tmp = is_jump_table (from); | |
11798 | if (tmp != NULL) | |
11799 | { | |
11800 | count += get_jump_table_size (tmp); | |
11801 | ||
11802 | /* Jump tables aren't in a basic block, so base the cost on | |
11803 | the dispatch insn. If we select this location, we will | |
11804 | still put the pool after the table. */ | |
11805 | new_cost = arm_barrier_cost (from); | |
11806 | ||
7a7017bc PB |
11807 | if (count < max_count |
11808 | && (!selected || new_cost <= selected_cost)) | |
d5b7b3ae RE |
11809 | { |
11810 | selected = tmp; | |
11811 | selected_cost = new_cost; | |
11812 | selected_address = fix->address + count; | |
11813 | } | |
11814 | ||
11815 | /* Continue after the dispatch table. */ | |
11816 | from = NEXT_INSN (tmp); | |
11817 | continue; | |
11818 | } | |
11819 | ||
11820 | new_cost = arm_barrier_cost (from); | |
f676971a | 11821 | |
7a7017bc PB |
11822 | if (count < max_count |
11823 | && (!selected || new_cost <= selected_cost)) | |
d5b7b3ae RE |
11824 | { |
11825 | selected = from; | |
11826 | selected_cost = new_cost; | |
11827 | selected_address = fix->address + count; | |
11828 | } | |
11829 | ||
11830 | from = NEXT_INSN (from); | |
11831 | } | |
11832 | ||
7a7017bc PB |
11833 | /* Make sure that we found a place to insert the jump. */ |
11834 | gcc_assert (selected); | |
11835 | ||
d5b7b3ae RE |
11836 | /* Create a new JUMP_INSN that branches around a barrier. */ |
11837 | from = emit_jump_insn_after (gen_jump (label), selected); | |
11838 | JUMP_LABEL (from) = label; | |
11839 | barrier = emit_barrier_after (from); | |
11840 | emit_label_after (label, barrier); | |
11841 | ||
11842 | /* Create a minipool barrier entry for the new barrier. */ | |
c7319d87 | 11843 | new_fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* new_fix)); |
d5b7b3ae RE |
11844 | new_fix->insn = barrier; |
11845 | new_fix->address = selected_address; | |
11846 | new_fix->next = fix->next; | |
11847 | fix->next = new_fix; | |
11848 | ||
11849 | return new_fix; | |
11850 | } | |
11851 | ||
11852 | /* Record that there is a natural barrier in the insn stream at | |
11853 | ADDRESS. */ | |
949d79eb | 11854 | static void |
e32bac5b | 11855 | push_minipool_barrier (rtx insn, HOST_WIDE_INT address) |
2b835d68 | 11856 | { |
c7319d87 | 11857 | Mfix * fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* fix)); |
ad076f4e | 11858 | |
949d79eb RE |
11859 | fix->insn = insn; |
11860 | fix->address = address; | |
2b835d68 | 11861 | |
949d79eb RE |
11862 | fix->next = NULL; |
11863 | if (minipool_fix_head != NULL) | |
11864 | minipool_fix_tail->next = fix; | |
11865 | else | |
11866 | minipool_fix_head = fix; | |
11867 | ||
11868 | minipool_fix_tail = fix; | |
11869 | } | |
2b835d68 | 11870 | |
d5b7b3ae RE |
11871 | /* Record INSN, which will need fixing up to load a value from the |
11872 | minipool. ADDRESS is the offset of the insn since the start of the | |
11873 | function; LOC is a pointer to the part of the insn which requires | |
11874 | fixing; VALUE is the constant that must be loaded, which is of type | |
11875 | MODE. */ | |
949d79eb | 11876 | static void |
e32bac5b RE |
11877 | push_minipool_fix (rtx insn, HOST_WIDE_INT address, rtx *loc, |
11878 | enum machine_mode mode, rtx value) | |
949d79eb | 11879 | { |
c7319d87 | 11880 | Mfix * fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* fix)); |
949d79eb | 11881 | |
949d79eb RE |
11882 | fix->insn = insn; |
11883 | fix->address = address; | |
11884 | fix->loc = loc; | |
11885 | fix->mode = mode; | |
d5b7b3ae | 11886 | fix->fix_size = MINIPOOL_FIX_SIZE (mode); |
949d79eb | 11887 | fix->value = value; |
d5b7b3ae RE |
11888 | fix->forwards = get_attr_pool_range (insn); |
11889 | fix->backwards = get_attr_neg_pool_range (insn); | |
11890 | fix->minipool = NULL; | |
949d79eb RE |
11891 | |
11892 | /* If an insn doesn't have a range defined for it, then it isn't | |
e6d29d15 | 11893 | expecting to be reworked by this code. Better to stop now than |
949d79eb | 11894 | to generate duff assembly code. */ |
e6d29d15 | 11895 | gcc_assert (fix->forwards || fix->backwards); |
949d79eb | 11896 | |
34a9f549 PB |
11897 | /* If an entry requires 8-byte alignment then assume all constant pools |
11898 | require 4 bytes of padding. Trying to do this later on a per-pool | |
917f1b7e | 11899 | basis is awkward because existing pool entries have to be modified. */ |
88f77cba | 11900 | if (ARM_DOUBLEWORD_ALIGN && fix->fix_size >= 8) |
34a9f549 | 11901 | minipool_pad = 4; |
5a9335ef | 11902 | |
c263766c | 11903 | if (dump_file) |
d5b7b3ae | 11904 | { |
c263766c | 11905 | fprintf (dump_file, |
d5b7b3ae RE |
11906 | ";; %smode fixup for i%d; addr %lu, range (%ld,%ld): ", |
11907 | GET_MODE_NAME (mode), | |
f676971a | 11908 | INSN_UID (insn), (unsigned long) address, |
d5b7b3ae | 11909 | -1 * (long)fix->backwards, (long)fix->forwards); |
c263766c RH |
11910 | arm_print_value (dump_file, fix->value); |
11911 | fprintf (dump_file, "\n"); | |
d5b7b3ae RE |
11912 | } |
11913 | ||
6354dc9b | 11914 | /* Add it to the chain of fixes. */ |
949d79eb | 11915 | fix->next = NULL; |
f676971a | 11916 | |
949d79eb RE |
11917 | if (minipool_fix_head != NULL) |
11918 | minipool_fix_tail->next = fix; | |
11919 | else | |
11920 | minipool_fix_head = fix; | |
11921 | ||
11922 | minipool_fix_tail = fix; | |
11923 | } | |
11924 | ||
9b901d50 | 11925 | /* Return the cost of synthesizing a 64-bit constant VAL inline. |
2075b05d RE |
11926 | Returns the number of insns needed, or 99 if we don't know how to |
11927 | do it. */ | |
11928 | int | |
11929 | arm_const_double_inline_cost (rtx val) | |
b9e8bfda | 11930 | { |
9b901d50 RE |
11931 | rtx lowpart, highpart; |
11932 | enum machine_mode mode; | |
e0b92319 | 11933 | |
9b901d50 | 11934 | mode = GET_MODE (val); |
b9e8bfda | 11935 | |
9b901d50 RE |
11936 | if (mode == VOIDmode) |
11937 | mode = DImode; | |
11938 | ||
11939 | gcc_assert (GET_MODE_SIZE (mode) == 8); | |
e0b92319 | 11940 | |
9b901d50 RE |
11941 | lowpart = gen_lowpart (SImode, val); |
11942 | highpart = gen_highpart_mode (SImode, mode, val); | |
e0b92319 | 11943 | |
9b901d50 RE |
11944 | gcc_assert (GET_CODE (lowpart) == CONST_INT); |
11945 | gcc_assert (GET_CODE (highpart) == CONST_INT); | |
11946 | ||
11947 | return (arm_gen_constant (SET, SImode, NULL_RTX, INTVAL (lowpart), | |
2075b05d | 11948 | NULL_RTX, NULL_RTX, 0, 0) |
9b901d50 | 11949 | + arm_gen_constant (SET, SImode, NULL_RTX, INTVAL (highpart), |
2075b05d RE |
11950 | NULL_RTX, NULL_RTX, 0, 0)); |
11951 | } | |
11952 | ||
f3b569ca | 11953 | /* Return true if it is worthwhile to split a 64-bit constant into two |
b4a58f80 RE |
11954 | 32-bit operations. This is the case if optimizing for size, or |
11955 | if we have load delay slots, or if one 32-bit part can be done with | |
11956 | a single data operation. */ | |
11957 | bool | |
11958 | arm_const_double_by_parts (rtx val) | |
11959 | { | |
11960 | enum machine_mode mode = GET_MODE (val); | |
11961 | rtx part; | |
11962 | ||
11963 | if (optimize_size || arm_ld_sched) | |
11964 | return true; | |
11965 | ||
11966 | if (mode == VOIDmode) | |
11967 | mode = DImode; | |
e0b92319 | 11968 | |
b4a58f80 | 11969 | part = gen_highpart_mode (SImode, mode, val); |
e0b92319 | 11970 | |
b4a58f80 | 11971 | gcc_assert (GET_CODE (part) == CONST_INT); |
e0b92319 | 11972 | |
b4a58f80 RE |
11973 | if (const_ok_for_arm (INTVAL (part)) |
11974 | || const_ok_for_arm (~INTVAL (part))) | |
11975 | return true; | |
e0b92319 | 11976 | |
b4a58f80 | 11977 | part = gen_lowpart (SImode, val); |
e0b92319 | 11978 | |
b4a58f80 | 11979 | gcc_assert (GET_CODE (part) == CONST_INT); |
e0b92319 | 11980 | |
b4a58f80 RE |
11981 | if (const_ok_for_arm (INTVAL (part)) |
11982 | || const_ok_for_arm (~INTVAL (part))) | |
11983 | return true; | |
e0b92319 | 11984 | |
b4a58f80 RE |
11985 | return false; |
11986 | } | |
11987 | ||
73160ba9 DJ |
11988 | /* Return true if it is possible to inline both the high and low parts |
11989 | of a 64-bit constant into 32-bit data processing instructions. */ | |
11990 | bool | |
11991 | arm_const_double_by_immediates (rtx val) | |
11992 | { | |
11993 | enum machine_mode mode = GET_MODE (val); | |
11994 | rtx part; | |
11995 | ||
11996 | if (mode == VOIDmode) | |
11997 | mode = DImode; | |
11998 | ||
11999 | part = gen_highpart_mode (SImode, mode, val); | |
12000 | ||
12001 | gcc_assert (GET_CODE (part) == CONST_INT); | |
12002 | ||
12003 | if (!const_ok_for_arm (INTVAL (part))) | |
12004 | return false; | |
12005 | ||
12006 | part = gen_lowpart (SImode, val); | |
12007 | ||
12008 | gcc_assert (GET_CODE (part) == CONST_INT); | |
12009 | ||
12010 | if (!const_ok_for_arm (INTVAL (part))) | |
12011 | return false; | |
12012 | ||
12013 | return true; | |
12014 | } | |
12015 | ||
f0375c66 NC |
12016 | /* Scan INSN and note any of its operands that need fixing. |
12017 | If DO_PUSHES is false we do not actually push any of the fixups | |
9b901d50 | 12018 | needed. The function returns TRUE if any fixups were needed/pushed. |
f0375c66 NC |
12019 | This is used by arm_memory_load_p() which needs to know about loads |
12020 | of constants that will be converted into minipool loads. */ | |
f0375c66 | 12021 | static bool |
e32bac5b | 12022 | note_invalid_constants (rtx insn, HOST_WIDE_INT address, int do_pushes) |
949d79eb | 12023 | { |
f0375c66 | 12024 | bool result = false; |
949d79eb RE |
12025 | int opno; |
12026 | ||
d5b7b3ae | 12027 | extract_insn (insn); |
949d79eb | 12028 | |
5895f793 | 12029 | if (!constrain_operands (1)) |
949d79eb RE |
12030 | fatal_insn_not_found (insn); |
12031 | ||
8c2a5582 RE |
12032 | if (recog_data.n_alternatives == 0) |
12033 | return false; | |
12034 | ||
9b901d50 RE |
12035 | /* Fill in recog_op_alt with information about the constraints of |
12036 | this insn. */ | |
949d79eb RE |
12037 | preprocess_constraints (); |
12038 | ||
1ccbefce | 12039 | for (opno = 0; opno < recog_data.n_operands; opno++) |
949d79eb | 12040 | { |
6354dc9b | 12041 | /* Things we need to fix can only occur in inputs. */ |
36ab44c7 | 12042 | if (recog_data.operand_type[opno] != OP_IN) |
949d79eb RE |
12043 | continue; |
12044 | ||
12045 | /* If this alternative is a memory reference, then any mention | |
12046 | of constants in this alternative is really to fool reload | |
12047 | into allowing us to accept one there. We need to fix them up | |
12048 | now so that we output the right code. */ | |
12049 | if (recog_op_alt[opno][which_alternative].memory_ok) | |
12050 | { | |
1ccbefce | 12051 | rtx op = recog_data.operand[opno]; |
949d79eb | 12052 | |
9b901d50 | 12053 | if (CONSTANT_P (op)) |
f0375c66 NC |
12054 | { |
12055 | if (do_pushes) | |
12056 | push_minipool_fix (insn, address, recog_data.operand_loc[opno], | |
12057 | recog_data.operand_mode[opno], op); | |
12058 | result = true; | |
12059 | } | |
d5b7b3ae | 12060 | else if (GET_CODE (op) == MEM |
949d79eb RE |
12061 | && GET_CODE (XEXP (op, 0)) == SYMBOL_REF |
12062 | && CONSTANT_POOL_ADDRESS_P (XEXP (op, 0))) | |
f0375c66 NC |
12063 | { |
12064 | if (do_pushes) | |
244b1afb RE |
12065 | { |
12066 | rtx cop = avoid_constant_pool_reference (op); | |
12067 | ||
12068 | /* Casting the address of something to a mode narrower | |
12069 | than a word can cause avoid_constant_pool_reference() | |
12070 | to return the pool reference itself. That's no good to | |
f676971a | 12071 | us here. Lets just hope that we can use the |
244b1afb RE |
12072 | constant pool value directly. */ |
12073 | if (op == cop) | |
c769a35d | 12074 | cop = get_pool_constant (XEXP (op, 0)); |
244b1afb RE |
12075 | |
12076 | push_minipool_fix (insn, address, | |
12077 | recog_data.operand_loc[opno], | |
c769a35d | 12078 | recog_data.operand_mode[opno], cop); |
244b1afb | 12079 | } |
f0375c66 NC |
12080 | |
12081 | result = true; | |
12082 | } | |
949d79eb | 12083 | } |
2b835d68 | 12084 | } |
f0375c66 NC |
12085 | |
12086 | return result; | |
2b835d68 RE |
12087 | } |
12088 | ||
eef5973d BS |
12089 | /* Convert instructions to their cc-clobbering variant if possible, since |
12090 | that allows us to use smaller encodings. */ | |
12091 | ||
12092 | static void | |
12093 | thumb2_reorg (void) | |
12094 | { | |
12095 | basic_block bb; | |
12096 | regset_head live; | |
12097 | ||
12098 | INIT_REG_SET (&live); | |
12099 | ||
12100 | /* We are freeing block_for_insn in the toplev to keep compatibility | |
12101 | with old MDEP_REORGS that are not CFG based. Recompute it now. */ | |
12102 | compute_bb_for_insn (); | |
12103 | df_analyze (); | |
12104 | ||
12105 | FOR_EACH_BB (bb) | |
12106 | { | |
12107 | rtx insn; | |
12108 | COPY_REG_SET (&live, DF_LR_OUT (bb)); | |
12109 | df_simulate_initialize_backwards (bb, &live); | |
12110 | FOR_BB_INSNS_REVERSE (bb, insn) | |
12111 | { | |
12112 | if (NONJUMP_INSN_P (insn) | |
12113 | && !REGNO_REG_SET_P (&live, CC_REGNUM)) | |
12114 | { | |
12115 | rtx pat = PATTERN (insn); | |
12116 | if (GET_CODE (pat) == SET | |
12117 | && low_register_operand (XEXP (pat, 0), SImode) | |
12118 | && thumb_16bit_operator (XEXP (pat, 1), SImode) | |
12119 | && low_register_operand (XEXP (XEXP (pat, 1), 0), SImode) | |
12120 | && low_register_operand (XEXP (XEXP (pat, 1), 1), SImode)) | |
12121 | { | |
12122 | rtx dst = XEXP (pat, 0); | |
12123 | rtx src = XEXP (pat, 1); | |
12124 | rtx op0 = XEXP (src, 0); | |
eef5973d BS |
12125 | if (rtx_equal_p (dst, op0) |
12126 | || GET_CODE (src) == PLUS || GET_CODE (src) == MINUS) | |
12127 | { | |
12128 | rtx ccreg = gen_rtx_REG (CCmode, CC_REGNUM); | |
12129 | rtx clobber = gen_rtx_CLOBBER (VOIDmode, ccreg); | |
f63a6726 | 12130 | rtvec vec = gen_rtvec (2, pat, clobber); |
eef5973d BS |
12131 | PATTERN (insn) = gen_rtx_PARALLEL (VOIDmode, vec); |
12132 | INSN_CODE (insn) = -1; | |
12133 | } | |
12134 | } | |
12135 | } | |
12136 | if (NONDEBUG_INSN_P (insn)) | |
12137 | df_simulate_one_insn_backwards (bb, insn, &live); | |
12138 | } | |
12139 | } | |
12140 | CLEAR_REG_SET (&live); | |
12141 | } | |
12142 | ||
18dbd950 RS |
12143 | /* Gcc puts the pool in the wrong place for ARM, since we can only |
12144 | load addresses a limited distance around the pc. We do some | |
12145 | special munging to move the constant pool values to the correct | |
12146 | point in the code. */ | |
18dbd950 | 12147 | static void |
e32bac5b | 12148 | arm_reorg (void) |
2b835d68 RE |
12149 | { |
12150 | rtx insn; | |
d5b7b3ae RE |
12151 | HOST_WIDE_INT address = 0; |
12152 | Mfix * fix; | |
ad076f4e | 12153 | |
eef5973d BS |
12154 | if (TARGET_THUMB2) |
12155 | thumb2_reorg (); | |
12156 | ||
949d79eb | 12157 | minipool_fix_head = minipool_fix_tail = NULL; |
2b835d68 | 12158 | |
949d79eb RE |
12159 | /* The first insn must always be a note, or the code below won't |
12160 | scan it properly. */ | |
18dbd950 | 12161 | insn = get_insns (); |
e6d29d15 | 12162 | gcc_assert (GET_CODE (insn) == NOTE); |
34a9f549 | 12163 | minipool_pad = 0; |
949d79eb RE |
12164 | |
12165 | /* Scan all the insns and record the operands that will need fixing. */ | |
18dbd950 | 12166 | for (insn = next_nonnote_insn (insn); insn; insn = next_nonnote_insn (insn)) |
2b835d68 | 12167 | { |
9b6b54e2 | 12168 | if (TARGET_CIRRUS_FIX_INVALID_INSNS |
f0375c66 | 12169 | && (arm_cirrus_insn_p (insn) |
9b6b54e2 | 12170 | || GET_CODE (insn) == JUMP_INSN |
f0375c66 | 12171 | || arm_memory_load_p (insn))) |
9b6b54e2 NC |
12172 | cirrus_reorg (insn); |
12173 | ||
949d79eb | 12174 | if (GET_CODE (insn) == BARRIER) |
d5b7b3ae | 12175 | push_minipool_barrier (insn, address); |
f0375c66 | 12176 | else if (INSN_P (insn)) |
949d79eb RE |
12177 | { |
12178 | rtx table; | |
12179 | ||
f0375c66 | 12180 | note_invalid_constants (insn, address, true); |
949d79eb | 12181 | address += get_attr_length (insn); |
d5b7b3ae | 12182 | |
949d79eb RE |
12183 | /* If the insn is a vector jump, add the size of the table |
12184 | and skip the table. */ | |
d5b7b3ae | 12185 | if ((table = is_jump_table (insn)) != NULL) |
2b835d68 | 12186 | { |
d5b7b3ae | 12187 | address += get_jump_table_size (table); |
949d79eb RE |
12188 | insn = table; |
12189 | } | |
12190 | } | |
12191 | } | |
332072db | 12192 | |
d5b7b3ae | 12193 | fix = minipool_fix_head; |
f676971a | 12194 | |
949d79eb | 12195 | /* Now scan the fixups and perform the required changes. */ |
d5b7b3ae | 12196 | while (fix) |
949d79eb | 12197 | { |
d5b7b3ae RE |
12198 | Mfix * ftmp; |
12199 | Mfix * fdel; | |
12200 | Mfix * last_added_fix; | |
12201 | Mfix * last_barrier = NULL; | |
12202 | Mfix * this_fix; | |
949d79eb RE |
12203 | |
12204 | /* Skip any further barriers before the next fix. */ | |
12205 | while (fix && GET_CODE (fix->insn) == BARRIER) | |
12206 | fix = fix->next; | |
12207 | ||
d5b7b3ae | 12208 | /* No more fixes. */ |
949d79eb RE |
12209 | if (fix == NULL) |
12210 | break; | |
332072db | 12211 | |
d5b7b3ae | 12212 | last_added_fix = NULL; |
2b835d68 | 12213 | |
d5b7b3ae | 12214 | for (ftmp = fix; ftmp; ftmp = ftmp->next) |
949d79eb | 12215 | { |
949d79eb | 12216 | if (GET_CODE (ftmp->insn) == BARRIER) |
949d79eb | 12217 | { |
d5b7b3ae RE |
12218 | if (ftmp->address >= minipool_vector_head->max_address) |
12219 | break; | |
2b835d68 | 12220 | |
d5b7b3ae | 12221 | last_barrier = ftmp; |
2b835d68 | 12222 | } |
d5b7b3ae RE |
12223 | else if ((ftmp->minipool = add_minipool_forward_ref (ftmp)) == NULL) |
12224 | break; | |
12225 | ||
12226 | last_added_fix = ftmp; /* Keep track of the last fix added. */ | |
2b835d68 | 12227 | } |
949d79eb | 12228 | |
d5b7b3ae RE |
12229 | /* If we found a barrier, drop back to that; any fixes that we |
12230 | could have reached but come after the barrier will now go in | |
12231 | the next mini-pool. */ | |
949d79eb RE |
12232 | if (last_barrier != NULL) |
12233 | { | |
f676971a | 12234 | /* Reduce the refcount for those fixes that won't go into this |
d5b7b3ae RE |
12235 | pool after all. */ |
12236 | for (fdel = last_barrier->next; | |
12237 | fdel && fdel != ftmp; | |
12238 | fdel = fdel->next) | |
12239 | { | |
12240 | fdel->minipool->refcount--; | |
12241 | fdel->minipool = NULL; | |
12242 | } | |
12243 | ||
949d79eb RE |
12244 | ftmp = last_barrier; |
12245 | } | |
12246 | else | |
2bfa88dc | 12247 | { |
d5b7b3ae RE |
12248 | /* ftmp is first fix that we can't fit into this pool and |
12249 | there no natural barriers that we could use. Insert a | |
12250 | new barrier in the code somewhere between the previous | |
12251 | fix and this one, and arrange to jump around it. */ | |
12252 | HOST_WIDE_INT max_address; | |
12253 | ||
12254 | /* The last item on the list of fixes must be a barrier, so | |
12255 | we can never run off the end of the list of fixes without | |
12256 | last_barrier being set. */ | |
e6d29d15 | 12257 | gcc_assert (ftmp); |
d5b7b3ae RE |
12258 | |
12259 | max_address = minipool_vector_head->max_address; | |
2bfa88dc RE |
12260 | /* Check that there isn't another fix that is in range that |
12261 | we couldn't fit into this pool because the pool was | |
12262 | already too large: we need to put the pool before such an | |
7a7017bc PB |
12263 | instruction. The pool itself may come just after the |
12264 | fix because create_fix_barrier also allows space for a | |
12265 | jump instruction. */ | |
d5b7b3ae | 12266 | if (ftmp->address < max_address) |
7a7017bc | 12267 | max_address = ftmp->address + 1; |
d5b7b3ae RE |
12268 | |
12269 | last_barrier = create_fix_barrier (last_added_fix, max_address); | |
12270 | } | |
12271 | ||
12272 | assign_minipool_offsets (last_barrier); | |
12273 | ||
12274 | while (ftmp) | |
12275 | { | |
12276 | if (GET_CODE (ftmp->insn) != BARRIER | |
12277 | && ((ftmp->minipool = add_minipool_backward_ref (ftmp)) | |
12278 | == NULL)) | |
12279 | break; | |
2bfa88dc | 12280 | |
d5b7b3ae | 12281 | ftmp = ftmp->next; |
2bfa88dc | 12282 | } |
949d79eb RE |
12283 | |
12284 | /* Scan over the fixes we have identified for this pool, fixing them | |
12285 | up and adding the constants to the pool itself. */ | |
d5b7b3ae | 12286 | for (this_fix = fix; this_fix && ftmp != this_fix; |
949d79eb RE |
12287 | this_fix = this_fix->next) |
12288 | if (GET_CODE (this_fix->insn) != BARRIER) | |
12289 | { | |
949d79eb | 12290 | rtx addr |
f676971a | 12291 | = plus_constant (gen_rtx_LABEL_REF (VOIDmode, |
949d79eb | 12292 | minipool_vector_label), |
d5b7b3ae | 12293 | this_fix->minipool->offset); |
949d79eb RE |
12294 | *this_fix->loc = gen_rtx_MEM (this_fix->mode, addr); |
12295 | } | |
12296 | ||
d5b7b3ae | 12297 | dump_minipool (last_barrier->insn); |
949d79eb | 12298 | fix = ftmp; |
2b835d68 | 12299 | } |
4b632bf1 | 12300 | |
949d79eb RE |
12301 | /* From now on we must synthesize any constants that we can't handle |
12302 | directly. This can happen if the RTL gets split during final | |
12303 | instruction generation. */ | |
4b632bf1 | 12304 | after_arm_reorg = 1; |
c7319d87 RE |
12305 | |
12306 | /* Free the minipool memory. */ | |
12307 | obstack_free (&minipool_obstack, minipool_startobj); | |
2b835d68 | 12308 | } |
cce8749e CH |
12309 | \f |
12310 | /* Routines to output assembly language. */ | |
12311 | ||
f3bb6135 | 12312 | /* If the rtx is the correct value then return the string of the number. |
ff9940b0 | 12313 | In this way we can ensure that valid double constants are generated even |
6354dc9b | 12314 | when cross compiling. */ |
cd2b33d0 | 12315 | const char * |
e32bac5b | 12316 | fp_immediate_constant (rtx x) |
ff9940b0 RE |
12317 | { |
12318 | REAL_VALUE_TYPE r; | |
12319 | int i; | |
f676971a | 12320 | |
9b66ebb1 PB |
12321 | if (!fp_consts_inited) |
12322 | init_fp_table (); | |
f676971a | 12323 | |
ff9940b0 RE |
12324 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); |
12325 | for (i = 0; i < 8; i++) | |
9b66ebb1 PB |
12326 | if (REAL_VALUES_EQUAL (r, values_fp[i])) |
12327 | return strings_fp[i]; | |
f3bb6135 | 12328 | |
e6d29d15 | 12329 | gcc_unreachable (); |
ff9940b0 RE |
12330 | } |
12331 | ||
9997d19d | 12332 | /* As for fp_immediate_constant, but value is passed directly, not in rtx. */ |
cd2b33d0 | 12333 | static const char * |
e32bac5b | 12334 | fp_const_from_val (REAL_VALUE_TYPE *r) |
9997d19d RE |
12335 | { |
12336 | int i; | |
12337 | ||
9b66ebb1 PB |
12338 | if (!fp_consts_inited) |
12339 | init_fp_table (); | |
9997d19d RE |
12340 | |
12341 | for (i = 0; i < 8; i++) | |
9b66ebb1 PB |
12342 | if (REAL_VALUES_EQUAL (*r, values_fp[i])) |
12343 | return strings_fp[i]; | |
9997d19d | 12344 | |
e6d29d15 | 12345 | gcc_unreachable (); |
9997d19d | 12346 | } |
ff9940b0 | 12347 | |
cce8749e CH |
12348 | /* Output the operands of a LDM/STM instruction to STREAM. |
12349 | MASK is the ARM register set mask of which only bits 0-15 are important. | |
6d3d9133 | 12350 | REG is the base register, either the frame pointer or the stack pointer, |
a15908a4 PB |
12351 | INSTR is the possibly suffixed load or store instruction. |
12352 | RFE is nonzero if the instruction should also copy spsr to cpsr. */ | |
b279b20a | 12353 | |
d5b7b3ae | 12354 | static void |
b279b20a | 12355 | print_multi_reg (FILE *stream, const char *instr, unsigned reg, |
a15908a4 | 12356 | unsigned long mask, int rfe) |
cce8749e | 12357 | { |
b279b20a NC |
12358 | unsigned i; |
12359 | bool not_first = FALSE; | |
cce8749e | 12360 | |
a15908a4 | 12361 | gcc_assert (!rfe || (mask & (1 << PC_REGNUM))); |
1d5473cb | 12362 | fputc ('\t', stream); |
dd18ae56 | 12363 | asm_fprintf (stream, instr, reg); |
5b3e6663 | 12364 | fputc ('{', stream); |
f676971a | 12365 | |
d5b7b3ae | 12366 | for (i = 0; i <= LAST_ARM_REGNUM; i++) |
cce8749e CH |
12367 | if (mask & (1 << i)) |
12368 | { | |
12369 | if (not_first) | |
12370 | fprintf (stream, ", "); | |
f676971a | 12371 | |
dd18ae56 | 12372 | asm_fprintf (stream, "%r", i); |
cce8749e CH |
12373 | not_first = TRUE; |
12374 | } | |
f3bb6135 | 12375 | |
a15908a4 PB |
12376 | if (rfe) |
12377 | fprintf (stream, "}^\n"); | |
12378 | else | |
12379 | fprintf (stream, "}\n"); | |
f3bb6135 | 12380 | } |
cce8749e | 12381 | |
9b66ebb1 | 12382 | |
8edfc4cc | 12383 | /* Output a FLDMD instruction to STREAM. |
9728c9d1 PB |
12384 | BASE if the register containing the address. |
12385 | REG and COUNT specify the register range. | |
8edfc4cc MS |
12386 | Extra registers may be added to avoid hardware bugs. |
12387 | ||
12388 | We output FLDMD even for ARMv5 VFP implementations. Although | |
12389 | FLDMD is technically not supported until ARMv6, it is believed | |
12390 | that all VFP implementations support its use in this context. */ | |
9b66ebb1 PB |
12391 | |
12392 | static void | |
8edfc4cc | 12393 | vfp_output_fldmd (FILE * stream, unsigned int base, int reg, int count) |
9b66ebb1 PB |
12394 | { |
12395 | int i; | |
12396 | ||
9728c9d1 PB |
12397 | /* Workaround ARM10 VFPr1 bug. */ |
12398 | if (count == 2 && !arm_arch6) | |
12399 | { | |
12400 | if (reg == 15) | |
12401 | reg--; | |
12402 | count++; | |
12403 | } | |
12404 | ||
f1adb0a9 JB |
12405 | /* FLDMD may not load more than 16 doubleword registers at a time. Split the |
12406 | load into multiple parts if we have to handle more than 16 registers. */ | |
12407 | if (count > 16) | |
12408 | { | |
12409 | vfp_output_fldmd (stream, base, reg, 16); | |
12410 | vfp_output_fldmd (stream, base, reg + 16, count - 16); | |
12411 | return; | |
12412 | } | |
12413 | ||
9b66ebb1 | 12414 | fputc ('\t', stream); |
8edfc4cc | 12415 | asm_fprintf (stream, "fldmfdd\t%r!, {", base); |
9b66ebb1 | 12416 | |
9728c9d1 | 12417 | for (i = reg; i < reg + count; i++) |
9b66ebb1 | 12418 | { |
9728c9d1 | 12419 | if (i > reg) |
9b66ebb1 | 12420 | fputs (", ", stream); |
9728c9d1 | 12421 | asm_fprintf (stream, "d%d", i); |
9b66ebb1 PB |
12422 | } |
12423 | fputs ("}\n", stream); | |
9728c9d1 | 12424 | |
9b66ebb1 PB |
12425 | } |
12426 | ||
12427 | ||
12428 | /* Output the assembly for a store multiple. */ | |
12429 | ||
12430 | const char * | |
8edfc4cc | 12431 | vfp_output_fstmd (rtx * operands) |
9b66ebb1 PB |
12432 | { |
12433 | char pattern[100]; | |
12434 | int p; | |
12435 | int base; | |
12436 | int i; | |
12437 | ||
8edfc4cc | 12438 | strcpy (pattern, "fstmfdd\t%m0!, {%P1"); |
9b66ebb1 PB |
12439 | p = strlen (pattern); |
12440 | ||
e6d29d15 | 12441 | gcc_assert (GET_CODE (operands[1]) == REG); |
9b66ebb1 PB |
12442 | |
12443 | base = (REGNO (operands[1]) - FIRST_VFP_REGNUM) / 2; | |
12444 | for (i = 1; i < XVECLEN (operands[2], 0); i++) | |
12445 | { | |
12446 | p += sprintf (&pattern[p], ", d%d", base + i); | |
12447 | } | |
12448 | strcpy (&pattern[p], "}"); | |
12449 | ||
12450 | output_asm_insn (pattern, operands); | |
12451 | return ""; | |
12452 | } | |
12453 | ||
12454 | ||
9728c9d1 PB |
12455 | /* Emit RTL to save block of VFP register pairs to the stack. Returns the |
12456 | number of bytes pushed. */ | |
9b66ebb1 | 12457 | |
9728c9d1 | 12458 | static int |
8edfc4cc | 12459 | vfp_emit_fstmd (int base_reg, int count) |
9b66ebb1 PB |
12460 | { |
12461 | rtx par; | |
12462 | rtx dwarf; | |
12463 | rtx tmp, reg; | |
12464 | int i; | |
12465 | ||
9728c9d1 PB |
12466 | /* Workaround ARM10 VFPr1 bug. Data corruption can occur when exactly two |
12467 | register pairs are stored by a store multiple insn. We avoid this | |
12468 | by pushing an extra pair. */ | |
12469 | if (count == 2 && !arm_arch6) | |
12470 | { | |
12471 | if (base_reg == LAST_VFP_REGNUM - 3) | |
12472 | base_reg -= 2; | |
12473 | count++; | |
12474 | } | |
12475 | ||
f1adb0a9 JB |
12476 | /* FSTMD may not store more than 16 doubleword registers at once. Split |
12477 | larger stores into multiple parts (up to a maximum of two, in | |
12478 | practice). */ | |
12479 | if (count > 16) | |
12480 | { | |
12481 | int saved; | |
12482 | /* NOTE: base_reg is an internal register number, so each D register | |
12483 | counts as 2. */ | |
12484 | saved = vfp_emit_fstmd (base_reg + 32, count - 16); | |
12485 | saved += vfp_emit_fstmd (base_reg, 16); | |
12486 | return saved; | |
12487 | } | |
12488 | ||
9b66ebb1 PB |
12489 | par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count)); |
12490 | dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (count + 1)); | |
12491 | ||
12492 | reg = gen_rtx_REG (DFmode, base_reg); | |
12493 | base_reg += 2; | |
12494 | ||
12495 | XVECEXP (par, 0, 0) | |
12496 | = gen_rtx_SET (VOIDmode, | |
9abf5d7b RR |
12497 | gen_frame_mem |
12498 | (BLKmode, | |
12499 | gen_rtx_PRE_MODIFY (Pmode, | |
12500 | stack_pointer_rtx, | |
12501 | plus_constant | |
12502 | (stack_pointer_rtx, | |
12503 | - (count * 8))) | |
12504 | ), | |
9b66ebb1 PB |
12505 | gen_rtx_UNSPEC (BLKmode, |
12506 | gen_rtvec (1, reg), | |
12507 | UNSPEC_PUSH_MULT)); | |
12508 | ||
12509 | tmp = gen_rtx_SET (VOIDmode, stack_pointer_rtx, | |
8edfc4cc | 12510 | plus_constant (stack_pointer_rtx, -(count * 8))); |
9b66ebb1 PB |
12511 | RTX_FRAME_RELATED_P (tmp) = 1; |
12512 | XVECEXP (dwarf, 0, 0) = tmp; | |
12513 | ||
12514 | tmp = gen_rtx_SET (VOIDmode, | |
31fa16b6 | 12515 | gen_frame_mem (DFmode, stack_pointer_rtx), |
9b66ebb1 PB |
12516 | reg); |
12517 | RTX_FRAME_RELATED_P (tmp) = 1; | |
12518 | XVECEXP (dwarf, 0, 1) = tmp; | |
12519 | ||
12520 | for (i = 1; i < count; i++) | |
12521 | { | |
12522 | reg = gen_rtx_REG (DFmode, base_reg); | |
12523 | base_reg += 2; | |
12524 | XVECEXP (par, 0, i) = gen_rtx_USE (VOIDmode, reg); | |
12525 | ||
12526 | tmp = gen_rtx_SET (VOIDmode, | |
31fa16b6 | 12527 | gen_frame_mem (DFmode, |
d66437c5 RE |
12528 | plus_constant (stack_pointer_rtx, |
12529 | i * 8)), | |
9b66ebb1 PB |
12530 | reg); |
12531 | RTX_FRAME_RELATED_P (tmp) = 1; | |
12532 | XVECEXP (dwarf, 0, i + 1) = tmp; | |
12533 | } | |
12534 | ||
12535 | par = emit_insn (par); | |
bbbbb16a | 12536 | add_reg_note (par, REG_FRAME_RELATED_EXPR, dwarf); |
9728c9d1 PB |
12537 | RTX_FRAME_RELATED_P (par) = 1; |
12538 | ||
8edfc4cc | 12539 | return count * 8; |
9b66ebb1 PB |
12540 | } |
12541 | ||
9403b7f7 RS |
12542 | /* Emit a call instruction with pattern PAT. ADDR is the address of |
12543 | the call target. */ | |
12544 | ||
12545 | void | |
12546 | arm_emit_call_insn (rtx pat, rtx addr) | |
12547 | { | |
12548 | rtx insn; | |
12549 | ||
12550 | insn = emit_call_insn (pat); | |
12551 | ||
12552 | /* The PIC register is live on entry to VxWorks PIC PLT entries. | |
12553 | If the call might use such an entry, add a use of the PIC register | |
12554 | to the instruction's CALL_INSN_FUNCTION_USAGE. */ | |
12555 | if (TARGET_VXWORKS_RTP | |
12556 | && flag_pic | |
12557 | && GET_CODE (addr) == SYMBOL_REF | |
12558 | && (SYMBOL_REF_DECL (addr) | |
12559 | ? !targetm.binds_local_p (SYMBOL_REF_DECL (addr)) | |
12560 | : !SYMBOL_REF_LOCAL_P (addr))) | |
12561 | { | |
12562 | require_pic_register (); | |
12563 | use_reg (&CALL_INSN_FUNCTION_USAGE (insn), cfun->machine->pic_reg); | |
12564 | } | |
12565 | } | |
9b66ebb1 | 12566 | |
6354dc9b | 12567 | /* Output a 'call' insn. */ |
cd2b33d0 | 12568 | const char * |
e32bac5b | 12569 | output_call (rtx *operands) |
cce8749e | 12570 | { |
e6d29d15 | 12571 | gcc_assert (!arm_arch5); /* Patterns should call blx <reg> directly. */ |
cce8749e | 12572 | |
68d560d4 | 12573 | /* Handle calls to lr using ip (which may be clobbered in subr anyway). */ |
62b10bbc | 12574 | if (REGNO (operands[0]) == LR_REGNUM) |
cce8749e | 12575 | { |
62b10bbc | 12576 | operands[0] = gen_rtx_REG (SImode, IP_REGNUM); |
1d5473cb | 12577 | output_asm_insn ("mov%?\t%0, %|lr", operands); |
cce8749e | 12578 | } |
f676971a | 12579 | |
1d5473cb | 12580 | output_asm_insn ("mov%?\t%|lr, %|pc", operands); |
f676971a | 12581 | |
68d560d4 | 12582 | if (TARGET_INTERWORK || arm_arch4t) |
da6558fd NC |
12583 | output_asm_insn ("bx%?\t%0", operands); |
12584 | else | |
12585 | output_asm_insn ("mov%?\t%|pc, %0", operands); | |
f676971a | 12586 | |
f3bb6135 RE |
12587 | return ""; |
12588 | } | |
cce8749e | 12589 | |
0986ef45 JB |
12590 | /* Output a 'call' insn that is a reference in memory. This is |
12591 | disabled for ARMv5 and we prefer a blx instead because otherwise | |
12592 | there's a significant performance overhead. */ | |
cd2b33d0 | 12593 | const char * |
e32bac5b | 12594 | output_call_mem (rtx *operands) |
ff9940b0 | 12595 | { |
0986ef45 JB |
12596 | gcc_assert (!arm_arch5); |
12597 | if (TARGET_INTERWORK) | |
da6558fd NC |
12598 | { |
12599 | output_asm_insn ("ldr%?\t%|ip, %0", operands); | |
12600 | output_asm_insn ("mov%?\t%|lr, %|pc", operands); | |
12601 | output_asm_insn ("bx%?\t%|ip", operands); | |
12602 | } | |
6ab5da80 RE |
12603 | else if (regno_use_in (LR_REGNUM, operands[0])) |
12604 | { | |
12605 | /* LR is used in the memory address. We load the address in the | |
12606 | first instruction. It's safe to use IP as the target of the | |
12607 | load since the call will kill it anyway. */ | |
12608 | output_asm_insn ("ldr%?\t%|ip, %0", operands); | |
0986ef45 JB |
12609 | output_asm_insn ("mov%?\t%|lr, %|pc", operands); |
12610 | if (arm_arch4t) | |
12611 | output_asm_insn ("bx%?\t%|ip", operands); | |
68d560d4 | 12612 | else |
0986ef45 | 12613 | output_asm_insn ("mov%?\t%|pc, %|ip", operands); |
6ab5da80 | 12614 | } |
da6558fd NC |
12615 | else |
12616 | { | |
12617 | output_asm_insn ("mov%?\t%|lr, %|pc", operands); | |
12618 | output_asm_insn ("ldr%?\t%|pc, %0", operands); | |
12619 | } | |
12620 | ||
f3bb6135 RE |
12621 | return ""; |
12622 | } | |
ff9940b0 RE |
12623 | |
12624 | ||
3b684012 RE |
12625 | /* Output a move from arm registers to an fpa registers. |
12626 | OPERANDS[0] is an fpa register. | |
ff9940b0 | 12627 | OPERANDS[1] is the first registers of an arm register pair. */ |
cd2b33d0 | 12628 | const char * |
e32bac5b | 12629 | output_mov_long_double_fpa_from_arm (rtx *operands) |
ff9940b0 RE |
12630 | { |
12631 | int arm_reg0 = REGNO (operands[1]); | |
12632 | rtx ops[3]; | |
12633 | ||
e6d29d15 | 12634 | gcc_assert (arm_reg0 != IP_REGNUM); |
f3bb6135 | 12635 | |
43cffd11 RE |
12636 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
12637 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
12638 | ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0); | |
f676971a | 12639 | |
5b3e6663 | 12640 | output_asm_insn ("stm%(fd%)\t%|sp!, {%0, %1, %2}", ops); |
1d5473cb | 12641 | output_asm_insn ("ldf%?e\t%0, [%|sp], #12", operands); |
f676971a | 12642 | |
f3bb6135 RE |
12643 | return ""; |
12644 | } | |
ff9940b0 | 12645 | |
3b684012 | 12646 | /* Output a move from an fpa register to arm registers. |
ff9940b0 | 12647 | OPERANDS[0] is the first registers of an arm register pair. |
3b684012 | 12648 | OPERANDS[1] is an fpa register. */ |
cd2b33d0 | 12649 | const char * |
e32bac5b | 12650 | output_mov_long_double_arm_from_fpa (rtx *operands) |
ff9940b0 RE |
12651 | { |
12652 | int arm_reg0 = REGNO (operands[0]); | |
12653 | rtx ops[3]; | |
12654 | ||
e6d29d15 | 12655 | gcc_assert (arm_reg0 != IP_REGNUM); |
f3bb6135 | 12656 | |
43cffd11 RE |
12657 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
12658 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
12659 | ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0); | |
ff9940b0 | 12660 | |
1d5473cb | 12661 | output_asm_insn ("stf%?e\t%1, [%|sp, #-12]!", operands); |
5b3e6663 | 12662 | output_asm_insn ("ldm%(fd%)\t%|sp!, {%0, %1, %2}", ops); |
f3bb6135 RE |
12663 | return ""; |
12664 | } | |
ff9940b0 RE |
12665 | |
12666 | /* Output a move from arm registers to arm registers of a long double | |
12667 | OPERANDS[0] is the destination. | |
12668 | OPERANDS[1] is the source. */ | |
cd2b33d0 | 12669 | const char * |
e32bac5b | 12670 | output_mov_long_double_arm_from_arm (rtx *operands) |
ff9940b0 | 12671 | { |
6354dc9b | 12672 | /* We have to be careful here because the two might overlap. */ |
ff9940b0 RE |
12673 | int dest_start = REGNO (operands[0]); |
12674 | int src_start = REGNO (operands[1]); | |
12675 | rtx ops[2]; | |
12676 | int i; | |
12677 | ||
12678 | if (dest_start < src_start) | |
12679 | { | |
12680 | for (i = 0; i < 3; i++) | |
12681 | { | |
43cffd11 RE |
12682 | ops[0] = gen_rtx_REG (SImode, dest_start + i); |
12683 | ops[1] = gen_rtx_REG (SImode, src_start + i); | |
9997d19d | 12684 | output_asm_insn ("mov%?\t%0, %1", ops); |
ff9940b0 RE |
12685 | } |
12686 | } | |
12687 | else | |
12688 | { | |
12689 | for (i = 2; i >= 0; i--) | |
12690 | { | |
43cffd11 RE |
12691 | ops[0] = gen_rtx_REG (SImode, dest_start + i); |
12692 | ops[1] = gen_rtx_REG (SImode, src_start + i); | |
9997d19d | 12693 | output_asm_insn ("mov%?\t%0, %1", ops); |
ff9940b0 RE |
12694 | } |
12695 | } | |
f3bb6135 | 12696 | |
ff9940b0 RE |
12697 | return ""; |
12698 | } | |
12699 | ||
a552b644 RR |
12700 | void |
12701 | arm_emit_movpair (rtx dest, rtx src) | |
12702 | { | |
12703 | /* If the src is an immediate, simplify it. */ | |
12704 | if (CONST_INT_P (src)) | |
12705 | { | |
12706 | HOST_WIDE_INT val = INTVAL (src); | |
12707 | emit_set_insn (dest, GEN_INT (val & 0x0000ffff)); | |
12708 | if ((val >> 16) & 0x0000ffff) | |
12709 | emit_set_insn (gen_rtx_ZERO_EXTRACT (SImode, dest, GEN_INT (16), | |
12710 | GEN_INT (16)), | |
12711 | GEN_INT ((val >> 16) & 0x0000ffff)); | |
12712 | return; | |
12713 | } | |
12714 | emit_set_insn (dest, gen_rtx_HIGH (SImode, src)); | |
12715 | emit_set_insn (dest, gen_rtx_LO_SUM (SImode, dest, src)); | |
12716 | } | |
571191af | 12717 | |
3b684012 RE |
12718 | /* Output a move from arm registers to an fpa registers. |
12719 | OPERANDS[0] is an fpa register. | |
cce8749e | 12720 | OPERANDS[1] is the first registers of an arm register pair. */ |
cd2b33d0 | 12721 | const char * |
e32bac5b | 12722 | output_mov_double_fpa_from_arm (rtx *operands) |
cce8749e CH |
12723 | { |
12724 | int arm_reg0 = REGNO (operands[1]); | |
12725 | rtx ops[2]; | |
12726 | ||
e6d29d15 | 12727 | gcc_assert (arm_reg0 != IP_REGNUM); |
f676971a | 12728 | |
43cffd11 RE |
12729 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
12730 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
5b3e6663 | 12731 | output_asm_insn ("stm%(fd%)\t%|sp!, {%0, %1}", ops); |
1d5473cb | 12732 | output_asm_insn ("ldf%?d\t%0, [%|sp], #8", operands); |
f3bb6135 RE |
12733 | return ""; |
12734 | } | |
cce8749e | 12735 | |
3b684012 | 12736 | /* Output a move from an fpa register to arm registers. |
cce8749e | 12737 | OPERANDS[0] is the first registers of an arm register pair. |
3b684012 | 12738 | OPERANDS[1] is an fpa register. */ |
cd2b33d0 | 12739 | const char * |
e32bac5b | 12740 | output_mov_double_arm_from_fpa (rtx *operands) |
cce8749e CH |
12741 | { |
12742 | int arm_reg0 = REGNO (operands[0]); | |
12743 | rtx ops[2]; | |
12744 | ||
e6d29d15 | 12745 | gcc_assert (arm_reg0 != IP_REGNUM); |
f3bb6135 | 12746 | |
43cffd11 RE |
12747 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
12748 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
1d5473cb | 12749 | output_asm_insn ("stf%?d\t%1, [%|sp, #-8]!", operands); |
5b3e6663 | 12750 | output_asm_insn ("ldm%(fd%)\t%|sp!, {%0, %1}", ops); |
f3bb6135 RE |
12751 | return ""; |
12752 | } | |
cce8749e CH |
12753 | |
12754 | /* Output a move between double words. | |
12755 | It must be REG<-REG, REG<-CONST_DOUBLE, REG<-CONST_INT, REG<-MEM | |
12756 | or MEM<-REG and all MEMs must be offsettable addresses. */ | |
cd2b33d0 | 12757 | const char * |
e32bac5b | 12758 | output_move_double (rtx *operands) |
cce8749e CH |
12759 | { |
12760 | enum rtx_code code0 = GET_CODE (operands[0]); | |
12761 | enum rtx_code code1 = GET_CODE (operands[1]); | |
56636818 | 12762 | rtx otherops[3]; |
cce8749e CH |
12763 | |
12764 | if (code0 == REG) | |
12765 | { | |
f0b4bdd5 | 12766 | unsigned int reg0 = REGNO (operands[0]); |
cce8749e | 12767 | |
43cffd11 | 12768 | otherops[0] = gen_rtx_REG (SImode, 1 + reg0); |
f676971a | 12769 | |
e6d29d15 NS |
12770 | gcc_assert (code1 == MEM); /* Constraints should ensure this. */ |
12771 | ||
12772 | switch (GET_CODE (XEXP (operands[1], 0))) | |
cce8749e | 12773 | { |
e6d29d15 | 12774 | case REG: |
5fd42423 PB |
12775 | if (TARGET_LDRD |
12776 | && !(fix_cm3_ldrd && reg0 == REGNO(XEXP (operands[1], 0)))) | |
5dea0c19 PB |
12777 | output_asm_insn ("ldr%(d%)\t%0, [%m1]", operands); |
12778 | else | |
12779 | output_asm_insn ("ldm%(ia%)\t%m1, %M0", operands); | |
e6d29d15 | 12780 | break; |
e0b92319 | 12781 | |
e6d29d15 NS |
12782 | case PRE_INC: |
12783 | gcc_assert (TARGET_LDRD); | |
5b3e6663 | 12784 | output_asm_insn ("ldr%(d%)\t%0, [%m1, #8]!", operands); |
e6d29d15 | 12785 | break; |
e0b92319 | 12786 | |
e6d29d15 | 12787 | case PRE_DEC: |
5b3e6663 PB |
12788 | if (TARGET_LDRD) |
12789 | output_asm_insn ("ldr%(d%)\t%0, [%m1, #-8]!", operands); | |
12790 | else | |
12791 | output_asm_insn ("ldm%(db%)\t%m1!, %M0", operands); | |
e6d29d15 | 12792 | break; |
e0b92319 | 12793 | |
e6d29d15 | 12794 | case POST_INC: |
5dea0c19 PB |
12795 | if (TARGET_LDRD) |
12796 | output_asm_insn ("ldr%(d%)\t%0, [%m1], #8", operands); | |
12797 | else | |
12798 | output_asm_insn ("ldm%(ia%)\t%m1!, %M0", operands); | |
e6d29d15 | 12799 | break; |
e0b92319 | 12800 | |
e6d29d15 NS |
12801 | case POST_DEC: |
12802 | gcc_assert (TARGET_LDRD); | |
5b3e6663 | 12803 | output_asm_insn ("ldr%(d%)\t%0, [%m1], #-8", operands); |
e6d29d15 | 12804 | break; |
e0b92319 | 12805 | |
e6d29d15 NS |
12806 | case PRE_MODIFY: |
12807 | case POST_MODIFY: | |
5fd42423 PB |
12808 | /* Autoicrement addressing modes should never have overlapping |
12809 | base and destination registers, and overlapping index registers | |
12810 | are already prohibited, so this doesn't need to worry about | |
12811 | fix_cm3_ldrd. */ | |
e6d29d15 NS |
12812 | otherops[0] = operands[0]; |
12813 | otherops[1] = XEXP (XEXP (XEXP (operands[1], 0), 1), 0); | |
12814 | otherops[2] = XEXP (XEXP (XEXP (operands[1], 0), 1), 1); | |
e0b92319 | 12815 | |
e6d29d15 | 12816 | if (GET_CODE (XEXP (operands[1], 0)) == PRE_MODIFY) |
cce8749e | 12817 | { |
e6d29d15 | 12818 | if (reg_overlap_mentioned_p (otherops[0], otherops[2])) |
fdd695fd | 12819 | { |
e6d29d15 NS |
12820 | /* Registers overlap so split out the increment. */ |
12821 | output_asm_insn ("add%?\t%1, %1, %2", otherops); | |
5b3e6663 | 12822 | output_asm_insn ("ldr%(d%)\t%0, [%1] @split", otherops); |
fdd695fd PB |
12823 | } |
12824 | else | |
fe2d934b | 12825 | { |
ff128632 RE |
12826 | /* Use a single insn if we can. |
12827 | FIXME: IWMMXT allows offsets larger than ldrd can | |
12828 | handle, fix these up with a pair of ldr. */ | |
12829 | if (TARGET_THUMB2 | |
12830 | || GET_CODE (otherops[2]) != CONST_INT | |
12831 | || (INTVAL (otherops[2]) > -256 | |
12832 | && INTVAL (otherops[2]) < 256)) | |
12833 | output_asm_insn ("ldr%(d%)\t%0, [%1, %2]!", otherops); | |
12834 | else | |
fe2d934b PB |
12835 | { |
12836 | output_asm_insn ("ldr%?\t%0, [%1, %2]!", otherops); | |
ff128632 | 12837 | output_asm_insn ("ldr%?\t%H0, [%1, #4]", otherops); |
fe2d934b | 12838 | } |
fe2d934b | 12839 | } |
e6d29d15 NS |
12840 | } |
12841 | else | |
12842 | { | |
ff128632 RE |
12843 | /* Use a single insn if we can. |
12844 | FIXME: IWMMXT allows offsets larger than ldrd can handle, | |
fe2d934b | 12845 | fix these up with a pair of ldr. */ |
ff128632 RE |
12846 | if (TARGET_THUMB2 |
12847 | || GET_CODE (otherops[2]) != CONST_INT | |
12848 | || (INTVAL (otherops[2]) > -256 | |
12849 | && INTVAL (otherops[2]) < 256)) | |
12850 | output_asm_insn ("ldr%(d%)\t%0, [%1], %2", otherops); | |
12851 | else | |
fe2d934b | 12852 | { |
ff128632 | 12853 | output_asm_insn ("ldr%?\t%H0, [%1, #4]", otherops); |
fe2d934b PB |
12854 | output_asm_insn ("ldr%?\t%0, [%1], %2", otherops); |
12855 | } | |
e6d29d15 NS |
12856 | } |
12857 | break; | |
e0b92319 | 12858 | |
e6d29d15 NS |
12859 | case LABEL_REF: |
12860 | case CONST: | |
5dea0c19 PB |
12861 | /* We might be able to use ldrd %0, %1 here. However the range is |
12862 | different to ldr/adr, and it is broken on some ARMv7-M | |
12863 | implementations. */ | |
5fd42423 PB |
12864 | /* Use the second register of the pair to avoid problematic |
12865 | overlap. */ | |
12866 | otherops[1] = operands[1]; | |
12867 | output_asm_insn ("adr%?\t%0, %1", otherops); | |
12868 | operands[1] = otherops[0]; | |
5dea0c19 | 12869 | if (TARGET_LDRD) |
5fd42423 | 12870 | output_asm_insn ("ldr%(d%)\t%0, [%1]", operands); |
5dea0c19 | 12871 | else |
5fd42423 | 12872 | output_asm_insn ("ldm%(ia%)\t%1, %M0", operands); |
e6d29d15 | 12873 | break; |
e0b92319 | 12874 | |
5b3e6663 | 12875 | /* ??? This needs checking for thumb2. */ |
e6d29d15 NS |
12876 | default: |
12877 | if (arm_add_operand (XEXP (XEXP (operands[1], 0), 1), | |
12878 | GET_MODE (XEXP (XEXP (operands[1], 0), 1)))) | |
12879 | { | |
12880 | otherops[0] = operands[0]; | |
12881 | otherops[1] = XEXP (XEXP (operands[1], 0), 0); | |
12882 | otherops[2] = XEXP (XEXP (operands[1], 0), 1); | |
e0b92319 | 12883 | |
e6d29d15 | 12884 | if (GET_CODE (XEXP (operands[1], 0)) == PLUS) |
fdd695fd | 12885 | { |
5dea0c19 | 12886 | if (GET_CODE (otherops[2]) == CONST_INT && !TARGET_LDRD) |
2b835d68 | 12887 | { |
e6d29d15 | 12888 | switch ((int) INTVAL (otherops[2])) |
2b835d68 | 12889 | { |
e6d29d15 | 12890 | case -8: |
5b3e6663 | 12891 | output_asm_insn ("ldm%(db%)\t%1, %M0", otherops); |
e6d29d15 NS |
12892 | return ""; |
12893 | case -4: | |
5b3e6663 PB |
12894 | if (TARGET_THUMB2) |
12895 | break; | |
12896 | output_asm_insn ("ldm%(da%)\t%1, %M0", otherops); | |
e6d29d15 NS |
12897 | return ""; |
12898 | case 4: | |
5b3e6663 PB |
12899 | if (TARGET_THUMB2) |
12900 | break; | |
12901 | output_asm_insn ("ldm%(ib%)\t%1, %M0", otherops); | |
e6d29d15 | 12902 | return ""; |
fdd695fd | 12903 | } |
e6d29d15 | 12904 | } |
5fd42423 PB |
12905 | otherops[0] = gen_rtx_REG(SImode, REGNO(operands[0]) + 1); |
12906 | operands[1] = otherops[0]; | |
e6d29d15 NS |
12907 | if (TARGET_LDRD |
12908 | && (GET_CODE (otherops[2]) == REG | |
ff128632 | 12909 | || TARGET_THUMB2 |
e6d29d15 NS |
12910 | || (GET_CODE (otherops[2]) == CONST_INT |
12911 | && INTVAL (otherops[2]) > -256 | |
12912 | && INTVAL (otherops[2]) < 256))) | |
12913 | { | |
5fd42423 | 12914 | if (reg_overlap_mentioned_p (operands[0], |
e6d29d15 | 12915 | otherops[2])) |
fdd695fd | 12916 | { |
5fd42423 | 12917 | rtx tmp; |
e6d29d15 NS |
12918 | /* Swap base and index registers over to |
12919 | avoid a conflict. */ | |
5fd42423 PB |
12920 | tmp = otherops[1]; |
12921 | otherops[1] = otherops[2]; | |
12922 | otherops[2] = tmp; | |
fdd695fd | 12923 | } |
e6d29d15 NS |
12924 | /* If both registers conflict, it will usually |
12925 | have been fixed by a splitter. */ | |
5fd42423 PB |
12926 | if (reg_overlap_mentioned_p (operands[0], otherops[2]) |
12927 | || (fix_cm3_ldrd && reg0 == REGNO (otherops[1]))) | |
fdd695fd | 12928 | { |
5fd42423 PB |
12929 | output_asm_insn ("add%?\t%0, %1, %2", otherops); |
12930 | output_asm_insn ("ldr%(d%)\t%0, [%1]", operands); | |
2b835d68 RE |
12931 | } |
12932 | else | |
5fd42423 PB |
12933 | { |
12934 | otherops[0] = operands[0]; | |
12935 | output_asm_insn ("ldr%(d%)\t%0, [%1, %2]", otherops); | |
12936 | } | |
e6d29d15 | 12937 | return ""; |
2b835d68 | 12938 | } |
e0b92319 | 12939 | |
e6d29d15 | 12940 | if (GET_CODE (otherops[2]) == CONST_INT) |
2b835d68 | 12941 | { |
e6d29d15 NS |
12942 | if (!(const_ok_for_arm (INTVAL (otherops[2])))) |
12943 | output_asm_insn ("sub%?\t%0, %1, #%n2", otherops); | |
12944 | else | |
12945 | output_asm_insn ("add%?\t%0, %1, %2", otherops); | |
2b835d68 RE |
12946 | } |
12947 | else | |
e6d29d15 NS |
12948 | output_asm_insn ("add%?\t%0, %1, %2", otherops); |
12949 | } | |
12950 | else | |
12951 | output_asm_insn ("sub%?\t%0, %1, %2", otherops); | |
12952 | ||
5dea0c19 | 12953 | if (TARGET_LDRD) |
5fd42423 | 12954 | return "ldr%(d%)\t%0, [%1]"; |
5dea0c19 | 12955 | |
5fd42423 | 12956 | return "ldm%(ia%)\t%1, %M0"; |
e6d29d15 NS |
12957 | } |
12958 | else | |
12959 | { | |
12960 | otherops[1] = adjust_address (operands[1], SImode, 4); | |
12961 | /* Take care of overlapping base/data reg. */ | |
12962 | if (reg_mentioned_p (operands[0], operands[1])) | |
12963 | { | |
12964 | output_asm_insn ("ldr%?\t%0, %1", otherops); | |
12965 | output_asm_insn ("ldr%?\t%0, %1", operands); | |
12966 | } | |
12967 | else | |
12968 | { | |
12969 | output_asm_insn ("ldr%?\t%0, %1", operands); | |
12970 | output_asm_insn ("ldr%?\t%0, %1", otherops); | |
cce8749e CH |
12971 | } |
12972 | } | |
12973 | } | |
cce8749e | 12974 | } |
e6d29d15 | 12975 | else |
cce8749e | 12976 | { |
e6d29d15 NS |
12977 | /* Constraints should ensure this. */ |
12978 | gcc_assert (code0 == MEM && code1 == REG); | |
12979 | gcc_assert (REGNO (operands[1]) != IP_REGNUM); | |
2b835d68 | 12980 | |
ff9940b0 RE |
12981 | switch (GET_CODE (XEXP (operands[0], 0))) |
12982 | { | |
12983 | case REG: | |
5dea0c19 PB |
12984 | if (TARGET_LDRD) |
12985 | output_asm_insn ("str%(d%)\t%1, [%m0]", operands); | |
12986 | else | |
12987 | output_asm_insn ("stm%(ia%)\t%m0, %M1", operands); | |
ff9940b0 | 12988 | break; |
2b835d68 | 12989 | |
ff9940b0 | 12990 | case PRE_INC: |
e6d29d15 | 12991 | gcc_assert (TARGET_LDRD); |
5b3e6663 | 12992 | output_asm_insn ("str%(d%)\t%1, [%m0, #8]!", operands); |
ff9940b0 | 12993 | break; |
2b835d68 | 12994 | |
ff9940b0 | 12995 | case PRE_DEC: |
5b3e6663 PB |
12996 | if (TARGET_LDRD) |
12997 | output_asm_insn ("str%(d%)\t%1, [%m0, #-8]!", operands); | |
12998 | else | |
12999 | output_asm_insn ("stm%(db%)\t%m0!, %M1", operands); | |
ff9940b0 | 13000 | break; |
2b835d68 | 13001 | |
ff9940b0 | 13002 | case POST_INC: |
5dea0c19 PB |
13003 | if (TARGET_LDRD) |
13004 | output_asm_insn ("str%(d%)\t%1, [%m0], #8", operands); | |
13005 | else | |
13006 | output_asm_insn ("stm%(ia%)\t%m0!, %M1", operands); | |
ff9940b0 | 13007 | break; |
2b835d68 | 13008 | |
ff9940b0 | 13009 | case POST_DEC: |
e6d29d15 | 13010 | gcc_assert (TARGET_LDRD); |
5b3e6663 | 13011 | output_asm_insn ("str%(d%)\t%1, [%m0], #-8", operands); |
fdd695fd PB |
13012 | break; |
13013 | ||
13014 | case PRE_MODIFY: | |
13015 | case POST_MODIFY: | |
13016 | otherops[0] = operands[1]; | |
13017 | otherops[1] = XEXP (XEXP (XEXP (operands[0], 0), 1), 0); | |
13018 | otherops[2] = XEXP (XEXP (XEXP (operands[0], 0), 1), 1); | |
13019 | ||
fe2d934b PB |
13020 | /* IWMMXT allows offsets larger than ldrd can handle, |
13021 | fix these up with a pair of ldr. */ | |
ff128632 RE |
13022 | if (!TARGET_THUMB2 |
13023 | && GET_CODE (otherops[2]) == CONST_INT | |
fe2d934b PB |
13024 | && (INTVAL(otherops[2]) <= -256 |
13025 | || INTVAL(otherops[2]) >= 256)) | |
13026 | { | |
fe2d934b PB |
13027 | if (GET_CODE (XEXP (operands[0], 0)) == PRE_MODIFY) |
13028 | { | |
8019fcfb YQ |
13029 | output_asm_insn ("str%?\t%0, [%1, %2]!", otherops); |
13030 | output_asm_insn ("str%?\t%H0, [%1, #4]", otherops); | |
fe2d934b PB |
13031 | } |
13032 | else | |
13033 | { | |
8019fcfb YQ |
13034 | output_asm_insn ("str%?\t%H0, [%1, #4]", otherops); |
13035 | output_asm_insn ("str%?\t%0, [%1], %2", otherops); | |
fe2d934b PB |
13036 | } |
13037 | } | |
13038 | else if (GET_CODE (XEXP (operands[0], 0)) == PRE_MODIFY) | |
5b3e6663 | 13039 | output_asm_insn ("str%(d%)\t%0, [%1, %2]!", otherops); |
fdd695fd | 13040 | else |
5b3e6663 | 13041 | output_asm_insn ("str%(d%)\t%0, [%1], %2", otherops); |
ff9940b0 | 13042 | break; |
2b835d68 RE |
13043 | |
13044 | case PLUS: | |
fdd695fd | 13045 | otherops[2] = XEXP (XEXP (operands[0], 0), 1); |
5dea0c19 | 13046 | if (GET_CODE (otherops[2]) == CONST_INT && !TARGET_LDRD) |
2b835d68 | 13047 | { |
06bea5aa | 13048 | switch ((int) INTVAL (XEXP (XEXP (operands[0], 0), 1))) |
2b835d68 RE |
13049 | { |
13050 | case -8: | |
5b3e6663 | 13051 | output_asm_insn ("stm%(db%)\t%m0, %M1", operands); |
2b835d68 RE |
13052 | return ""; |
13053 | ||
13054 | case -4: | |
5b3e6663 PB |
13055 | if (TARGET_THUMB2) |
13056 | break; | |
13057 | output_asm_insn ("stm%(da%)\t%m0, %M1", operands); | |
2b835d68 RE |
13058 | return ""; |
13059 | ||
13060 | case 4: | |
5b3e6663 PB |
13061 | if (TARGET_THUMB2) |
13062 | break; | |
13063 | output_asm_insn ("stm%(ib%)\t%m0, %M1", operands); | |
2b835d68 RE |
13064 | return ""; |
13065 | } | |
13066 | } | |
fdd695fd PB |
13067 | if (TARGET_LDRD |
13068 | && (GET_CODE (otherops[2]) == REG | |
ff128632 | 13069 | || TARGET_THUMB2 |
fdd695fd PB |
13070 | || (GET_CODE (otherops[2]) == CONST_INT |
13071 | && INTVAL (otherops[2]) > -256 | |
13072 | && INTVAL (otherops[2]) < 256))) | |
13073 | { | |
13074 | otherops[0] = operands[1]; | |
13075 | otherops[1] = XEXP (XEXP (operands[0], 0), 0); | |
5b3e6663 | 13076 | output_asm_insn ("str%(d%)\t%0, [%1, %2]", otherops); |
fdd695fd PB |
13077 | return ""; |
13078 | } | |
2b835d68 RE |
13079 | /* Fall through */ |
13080 | ||
ff9940b0 | 13081 | default: |
a4a37b30 | 13082 | otherops[0] = adjust_address (operands[0], SImode, 4); |
ff128632 | 13083 | otherops[1] = operands[1]; |
9997d19d | 13084 | output_asm_insn ("str%?\t%1, %0", operands); |
ff128632 | 13085 | output_asm_insn ("str%?\t%H1, %0", otherops); |
cce8749e CH |
13086 | } |
13087 | } | |
cce8749e | 13088 | |
9997d19d RE |
13089 | return ""; |
13090 | } | |
cce8749e | 13091 | |
88f77cba | 13092 | /* Output a move, load or store for quad-word vectors in ARM registers. Only |
dc34db56 | 13093 | handles MEMs accepted by neon_vector_mem_operand with TYPE=1. */ |
5b3e6663 PB |
13094 | |
13095 | const char * | |
88f77cba | 13096 | output_move_quad (rtx *operands) |
5b3e6663 | 13097 | { |
88f77cba JB |
13098 | if (REG_P (operands[0])) |
13099 | { | |
13100 | /* Load, or reg->reg move. */ | |
5b3e6663 | 13101 | |
88f77cba JB |
13102 | if (MEM_P (operands[1])) |
13103 | { | |
13104 | switch (GET_CODE (XEXP (operands[1], 0))) | |
13105 | { | |
13106 | case REG: | |
13107 | output_asm_insn ("ldm%(ia%)\t%m1, %M0", operands); | |
13108 | break; | |
13109 | ||
13110 | case LABEL_REF: | |
13111 | case CONST: | |
13112 | output_asm_insn ("adr%?\t%0, %1", operands); | |
13113 | output_asm_insn ("ldm%(ia%)\t%0, %M0", operands); | |
13114 | break; | |
13115 | ||
13116 | default: | |
13117 | gcc_unreachable (); | |
13118 | } | |
13119 | } | |
13120 | else | |
13121 | { | |
13122 | rtx ops[2]; | |
13123 | int dest, src, i; | |
5b3e6663 | 13124 | |
88f77cba | 13125 | gcc_assert (REG_P (operands[1])); |
5b3e6663 | 13126 | |
88f77cba JB |
13127 | dest = REGNO (operands[0]); |
13128 | src = REGNO (operands[1]); | |
5b3e6663 | 13129 | |
88f77cba JB |
13130 | /* This seems pretty dumb, but hopefully GCC won't try to do it |
13131 | very often. */ | |
13132 | if (dest < src) | |
13133 | for (i = 0; i < 4; i++) | |
13134 | { | |
13135 | ops[0] = gen_rtx_REG (SImode, dest + i); | |
13136 | ops[1] = gen_rtx_REG (SImode, src + i); | |
13137 | output_asm_insn ("mov%?\t%0, %1", ops); | |
13138 | } | |
13139 | else | |
13140 | for (i = 3; i >= 0; i--) | |
13141 | { | |
13142 | ops[0] = gen_rtx_REG (SImode, dest + i); | |
13143 | ops[1] = gen_rtx_REG (SImode, src + i); | |
13144 | output_asm_insn ("mov%?\t%0, %1", ops); | |
13145 | } | |
13146 | } | |
13147 | } | |
13148 | else | |
13149 | { | |
13150 | gcc_assert (MEM_P (operands[0])); | |
13151 | gcc_assert (REG_P (operands[1])); | |
13152 | gcc_assert (!reg_overlap_mentioned_p (operands[1], operands[0])); | |
13153 | ||
13154 | switch (GET_CODE (XEXP (operands[0], 0))) | |
13155 | { | |
13156 | case REG: | |
13157 | output_asm_insn ("stm%(ia%)\t%m0, %M1", operands); | |
13158 | break; | |
13159 | ||
13160 | default: | |
13161 | gcc_unreachable (); | |
13162 | } | |
13163 | } | |
13164 | ||
13165 | return ""; | |
13166 | } | |
13167 | ||
13168 | /* Output a VFP load or store instruction. */ | |
13169 | ||
13170 | const char * | |
13171 | output_move_vfp (rtx *operands) | |
13172 | { | |
13173 | rtx reg, mem, addr, ops[2]; | |
13174 | int load = REG_P (operands[0]); | |
13175 | int dp = GET_MODE_SIZE (GET_MODE (operands[0])) == 8; | |
13176 | int integer_p = GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT; | |
0a2aaacc | 13177 | const char *templ; |
88f77cba JB |
13178 | char buff[50]; |
13179 | enum machine_mode mode; | |
13180 | ||
13181 | reg = operands[!load]; | |
13182 | mem = operands[load]; | |
13183 | ||
13184 | mode = GET_MODE (reg); | |
13185 | ||
13186 | gcc_assert (REG_P (reg)); | |
13187 | gcc_assert (IS_VFP_REGNUM (REGNO (reg))); | |
13188 | gcc_assert (mode == SFmode | |
13189 | || mode == DFmode | |
13190 | || mode == SImode | |
13191 | || mode == DImode | |
13192 | || (TARGET_NEON && VALID_NEON_DREG_MODE (mode))); | |
13193 | gcc_assert (MEM_P (mem)); | |
13194 | ||
13195 | addr = XEXP (mem, 0); | |
13196 | ||
13197 | switch (GET_CODE (addr)) | |
13198 | { | |
13199 | case PRE_DEC: | |
0a2aaacc | 13200 | templ = "f%smdb%c%%?\t%%0!, {%%%s1}%s"; |
88f77cba JB |
13201 | ops[0] = XEXP (addr, 0); |
13202 | ops[1] = reg; | |
5b3e6663 PB |
13203 | break; |
13204 | ||
13205 | case POST_INC: | |
0a2aaacc | 13206 | templ = "f%smia%c%%?\t%%0!, {%%%s1}%s"; |
5b3e6663 PB |
13207 | ops[0] = XEXP (addr, 0); |
13208 | ops[1] = reg; | |
13209 | break; | |
13210 | ||
13211 | default: | |
0a2aaacc | 13212 | templ = "f%s%c%%?\t%%%s0, %%1%s"; |
5b3e6663 PB |
13213 | ops[0] = reg; |
13214 | ops[1] = mem; | |
13215 | break; | |
13216 | } | |
13217 | ||
0a2aaacc | 13218 | sprintf (buff, templ, |
5b3e6663 PB |
13219 | load ? "ld" : "st", |
13220 | dp ? 'd' : 's', | |
13221 | dp ? "P" : "", | |
13222 | integer_p ? "\t%@ int" : ""); | |
13223 | output_asm_insn (buff, ops); | |
13224 | ||
13225 | return ""; | |
13226 | } | |
13227 | ||
88f77cba | 13228 | /* Output a Neon quad-word load or store, or a load or store for |
874d42b9 | 13229 | larger structure modes. |
88f77cba | 13230 | |
874d42b9 JM |
13231 | WARNING: The ordering of elements is weird in big-endian mode, |
13232 | because we use VSTM, as required by the EABI. GCC RTL defines | |
13233 | element ordering based on in-memory order. This can be differ | |
13234 | from the architectural ordering of elements within a NEON register. | |
13235 | The intrinsics defined in arm_neon.h use the NEON register element | |
13236 | ordering, not the GCC RTL element ordering. | |
88f77cba | 13237 | |
874d42b9 JM |
13238 | For example, the in-memory ordering of a big-endian a quadword |
13239 | vector with 16-bit elements when stored from register pair {d0,d1} | |
13240 | will be (lowest address first, d0[N] is NEON register element N): | |
88f77cba | 13241 | |
874d42b9 | 13242 | [d0[3], d0[2], d0[1], d0[0], d1[7], d1[6], d1[5], d1[4]] |
88f77cba | 13243 | |
874d42b9 JM |
13244 | When necessary, quadword registers (dN, dN+1) are moved to ARM |
13245 | registers from rN in the order: | |
88f77cba JB |
13246 | |
13247 | dN -> (rN+1, rN), dN+1 -> (rN+3, rN+2) | |
13248 | ||
874d42b9 JM |
13249 | So that STM/LDM can be used on vectors in ARM registers, and the |
13250 | same memory layout will result as if VSTM/VLDM were used. */ | |
88f77cba JB |
13251 | |
13252 | const char * | |
13253 | output_move_neon (rtx *operands) | |
13254 | { | |
13255 | rtx reg, mem, addr, ops[2]; | |
13256 | int regno, load = REG_P (operands[0]); | |
0a2aaacc | 13257 | const char *templ; |
88f77cba JB |
13258 | char buff[50]; |
13259 | enum machine_mode mode; | |
13260 | ||
13261 | reg = operands[!load]; | |
13262 | mem = operands[load]; | |
13263 | ||
13264 | mode = GET_MODE (reg); | |
13265 | ||
13266 | gcc_assert (REG_P (reg)); | |
13267 | regno = REGNO (reg); | |
13268 | gcc_assert (VFP_REGNO_OK_FOR_DOUBLE (regno) | |
13269 | || NEON_REGNO_OK_FOR_QUAD (regno)); | |
13270 | gcc_assert (VALID_NEON_DREG_MODE (mode) | |
13271 | || VALID_NEON_QREG_MODE (mode) | |
13272 | || VALID_NEON_STRUCT_MODE (mode)); | |
13273 | gcc_assert (MEM_P (mem)); | |
13274 | ||
13275 | addr = XEXP (mem, 0); | |
13276 | ||
13277 | /* Strip off const from addresses like (const (plus (...))). */ | |
13278 | if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS) | |
13279 | addr = XEXP (addr, 0); | |
13280 | ||
13281 | switch (GET_CODE (addr)) | |
13282 | { | |
13283 | case POST_INC: | |
0a2aaacc | 13284 | templ = "v%smia%%?\t%%0!, %%h1"; |
88f77cba JB |
13285 | ops[0] = XEXP (addr, 0); |
13286 | ops[1] = reg; | |
13287 | break; | |
13288 | ||
dc34db56 PB |
13289 | case PRE_DEC: |
13290 | /* FIXME: We should be using vld1/vst1 here in BE mode? */ | |
13291 | templ = "v%smdb%%?\t%%0!, %%h1"; | |
13292 | ops[0] = XEXP (addr, 0); | |
13293 | ops[1] = reg; | |
13294 | break; | |
13295 | ||
88f77cba JB |
13296 | case POST_MODIFY: |
13297 | /* FIXME: Not currently enabled in neon_vector_mem_operand. */ | |
13298 | gcc_unreachable (); | |
13299 | ||
13300 | case LABEL_REF: | |
13301 | case PLUS: | |
13302 | { | |
13303 | int nregs = HARD_REGNO_NREGS (REGNO (reg), mode) / 2; | |
13304 | int i; | |
13305 | int overlap = -1; | |
13306 | for (i = 0; i < nregs; i++) | |
13307 | { | |
13308 | /* We're only using DImode here because it's a convenient size. */ | |
13309 | ops[0] = gen_rtx_REG (DImode, REGNO (reg) + 2 * i); | |
5728868b | 13310 | ops[1] = adjust_address (mem, DImode, 8 * i); |
88f77cba JB |
13311 | if (reg_overlap_mentioned_p (ops[0], mem)) |
13312 | { | |
13313 | gcc_assert (overlap == -1); | |
13314 | overlap = i; | |
13315 | } | |
13316 | else | |
13317 | { | |
13318 | sprintf (buff, "v%sr%%?\t%%P0, %%1", load ? "ld" : "st"); | |
13319 | output_asm_insn (buff, ops); | |
13320 | } | |
13321 | } | |
13322 | if (overlap != -1) | |
13323 | { | |
13324 | ops[0] = gen_rtx_REG (DImode, REGNO (reg) + 2 * overlap); | |
13325 | ops[1] = adjust_address (mem, SImode, 8 * overlap); | |
13326 | sprintf (buff, "v%sr%%?\t%%P0, %%1", load ? "ld" : "st"); | |
13327 | output_asm_insn (buff, ops); | |
13328 | } | |
13329 | ||
13330 | return ""; | |
13331 | } | |
13332 | ||
13333 | default: | |
0a2aaacc | 13334 | templ = "v%smia%%?\t%%m0, %%h1"; |
88f77cba JB |
13335 | ops[0] = mem; |
13336 | ops[1] = reg; | |
13337 | } | |
13338 | ||
0a2aaacc | 13339 | sprintf (buff, templ, load ? "ld" : "st"); |
88f77cba JB |
13340 | output_asm_insn (buff, ops); |
13341 | ||
13342 | return ""; | |
13343 | } | |
13344 | ||
7c4f0041 JZ |
13345 | /* Compute and return the length of neon_mov<mode>, where <mode> is |
13346 | one of VSTRUCT modes: EI, OI, CI or XI. */ | |
13347 | int | |
13348 | arm_attr_length_move_neon (rtx insn) | |
13349 | { | |
13350 | rtx reg, mem, addr; | |
e4dde839 | 13351 | int load; |
7c4f0041 JZ |
13352 | enum machine_mode mode; |
13353 | ||
13354 | extract_insn_cached (insn); | |
13355 | ||
13356 | if (REG_P (recog_data.operand[0]) && REG_P (recog_data.operand[1])) | |
13357 | { | |
13358 | mode = GET_MODE (recog_data.operand[0]); | |
13359 | switch (mode) | |
13360 | { | |
13361 | case EImode: | |
13362 | case OImode: | |
13363 | return 8; | |
13364 | case CImode: | |
13365 | return 12; | |
13366 | case XImode: | |
13367 | return 16; | |
13368 | default: | |
13369 | gcc_unreachable (); | |
13370 | } | |
13371 | } | |
13372 | ||
13373 | load = REG_P (recog_data.operand[0]); | |
13374 | reg = recog_data.operand[!load]; | |
13375 | mem = recog_data.operand[load]; | |
13376 | ||
13377 | gcc_assert (MEM_P (mem)); | |
13378 | ||
13379 | mode = GET_MODE (reg); | |
7c4f0041 JZ |
13380 | addr = XEXP (mem, 0); |
13381 | ||
13382 | /* Strip off const from addresses like (const (plus (...))). */ | |
13383 | if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS) | |
13384 | addr = XEXP (addr, 0); | |
13385 | ||
13386 | if (GET_CODE (addr) == LABEL_REF || GET_CODE (addr) == PLUS) | |
13387 | { | |
13388 | int insns = HARD_REGNO_NREGS (REGNO (reg), mode) / 2; | |
13389 | return insns * 4; | |
13390 | } | |
13391 | else | |
13392 | return 4; | |
13393 | } | |
13394 | ||
47d8f18d JZ |
13395 | /* Return nonzero if the offset in the address is an immediate. Otherwise, |
13396 | return zero. */ | |
13397 | ||
13398 | int | |
13399 | arm_address_offset_is_imm (rtx insn) | |
13400 | { | |
13401 | rtx mem, addr; | |
13402 | ||
13403 | extract_insn_cached (insn); | |
13404 | ||
13405 | if (REG_P (recog_data.operand[0])) | |
13406 | return 0; | |
13407 | ||
13408 | mem = recog_data.operand[0]; | |
13409 | ||
13410 | gcc_assert (MEM_P (mem)); | |
13411 | ||
13412 | addr = XEXP (mem, 0); | |
13413 | ||
13414 | if (GET_CODE (addr) == REG | |
13415 | || (GET_CODE (addr) == PLUS | |
13416 | && GET_CODE (XEXP (addr, 0)) == REG | |
13417 | && GET_CODE (XEXP (addr, 1)) == CONST_INT)) | |
13418 | return 1; | |
13419 | else | |
13420 | return 0; | |
13421 | } | |
13422 | ||
1d6e90ac NC |
13423 | /* Output an ADD r, s, #n where n may be too big for one instruction. |
13424 | If adding zero to one register, output nothing. */ | |
cd2b33d0 | 13425 | const char * |
e32bac5b | 13426 | output_add_immediate (rtx *operands) |
cce8749e | 13427 | { |
f3bb6135 | 13428 | HOST_WIDE_INT n = INTVAL (operands[2]); |
cce8749e CH |
13429 | |
13430 | if (n != 0 || REGNO (operands[0]) != REGNO (operands[1])) | |
13431 | { | |
13432 | if (n < 0) | |
13433 | output_multi_immediate (operands, | |
9997d19d RE |
13434 | "sub%?\t%0, %1, %2", "sub%?\t%0, %0, %2", 2, |
13435 | -n); | |
cce8749e CH |
13436 | else |
13437 | output_multi_immediate (operands, | |
9997d19d RE |
13438 | "add%?\t%0, %1, %2", "add%?\t%0, %0, %2", 2, |
13439 | n); | |
cce8749e | 13440 | } |
f3bb6135 RE |
13441 | |
13442 | return ""; | |
13443 | } | |
cce8749e | 13444 | |
cce8749e CH |
13445 | /* Output a multiple immediate operation. |
13446 | OPERANDS is the vector of operands referred to in the output patterns. | |
13447 | INSTR1 is the output pattern to use for the first constant. | |
13448 | INSTR2 is the output pattern to use for subsequent constants. | |
13449 | IMMED_OP is the index of the constant slot in OPERANDS. | |
13450 | N is the constant value. */ | |
cd2b33d0 | 13451 | static const char * |
e32bac5b RE |
13452 | output_multi_immediate (rtx *operands, const char *instr1, const char *instr2, |
13453 | int immed_op, HOST_WIDE_INT n) | |
cce8749e | 13454 | { |
f3bb6135 | 13455 | #if HOST_BITS_PER_WIDE_INT > 32 |
30cf4896 | 13456 | n &= 0xffffffff; |
f3bb6135 RE |
13457 | #endif |
13458 | ||
cce8749e CH |
13459 | if (n == 0) |
13460 | { | |
1d6e90ac | 13461 | /* Quick and easy output. */ |
cce8749e | 13462 | operands[immed_op] = const0_rtx; |
1d6e90ac | 13463 | output_asm_insn (instr1, operands); |
cce8749e CH |
13464 | } |
13465 | else | |
13466 | { | |
13467 | int i; | |
cd2b33d0 | 13468 | const char * instr = instr1; |
cce8749e | 13469 | |
6354dc9b | 13470 | /* Note that n is never zero here (which would give no output). */ |
cce8749e CH |
13471 | for (i = 0; i < 32; i += 2) |
13472 | { | |
13473 | if (n & (3 << i)) | |
13474 | { | |
f3bb6135 RE |
13475 | operands[immed_op] = GEN_INT (n & (255 << i)); |
13476 | output_asm_insn (instr, operands); | |
cce8749e CH |
13477 | instr = instr2; |
13478 | i += 6; | |
13479 | } | |
13480 | } | |
13481 | } | |
f676971a | 13482 | |
f3bb6135 | 13483 | return ""; |
9997d19d | 13484 | } |
cce8749e | 13485 | |
5b3e6663 PB |
13486 | /* Return the name of a shifter operation. */ |
13487 | static const char * | |
13488 | arm_shift_nmem(enum rtx_code code) | |
13489 | { | |
13490 | switch (code) | |
13491 | { | |
13492 | case ASHIFT: | |
13493 | return ARM_LSL_NAME; | |
13494 | ||
13495 | case ASHIFTRT: | |
13496 | return "asr"; | |
13497 | ||
13498 | case LSHIFTRT: | |
13499 | return "lsr"; | |
13500 | ||
13501 | case ROTATERT: | |
13502 | return "ror"; | |
13503 | ||
13504 | default: | |
13505 | abort(); | |
13506 | } | |
13507 | } | |
13508 | ||
cce8749e CH |
13509 | /* Return the appropriate ARM instruction for the operation code. |
13510 | The returned result should not be overwritten. OP is the rtx of the | |
13511 | operation. SHIFT_FIRST_ARG is TRUE if the first argument of the operator | |
13512 | was shifted. */ | |
cd2b33d0 | 13513 | const char * |
e32bac5b | 13514 | arithmetic_instr (rtx op, int shift_first_arg) |
cce8749e | 13515 | { |
9997d19d | 13516 | switch (GET_CODE (op)) |
cce8749e CH |
13517 | { |
13518 | case PLUS: | |
f3bb6135 RE |
13519 | return "add"; |
13520 | ||
cce8749e | 13521 | case MINUS: |
f3bb6135 RE |
13522 | return shift_first_arg ? "rsb" : "sub"; |
13523 | ||
cce8749e | 13524 | case IOR: |
f3bb6135 RE |
13525 | return "orr"; |
13526 | ||
cce8749e | 13527 | case XOR: |
f3bb6135 RE |
13528 | return "eor"; |
13529 | ||
cce8749e | 13530 | case AND: |
f3bb6135 RE |
13531 | return "and"; |
13532 | ||
5b3e6663 PB |
13533 | case ASHIFT: |
13534 | case ASHIFTRT: | |
13535 | case LSHIFTRT: | |
13536 | case ROTATERT: | |
13537 | return arm_shift_nmem(GET_CODE(op)); | |
13538 | ||
cce8749e | 13539 | default: |
e6d29d15 | 13540 | gcc_unreachable (); |
cce8749e | 13541 | } |
f3bb6135 | 13542 | } |
cce8749e | 13543 | |
cce8749e CH |
13544 | /* Ensure valid constant shifts and return the appropriate shift mnemonic |
13545 | for the operation code. The returned result should not be overwritten. | |
13546 | OP is the rtx code of the shift. | |
9997d19d | 13547 | On exit, *AMOUNTP will be -1 if the shift is by a register, or a constant |
6354dc9b | 13548 | shift. */ |
cd2b33d0 | 13549 | static const char * |
e32bac5b | 13550 | shift_op (rtx op, HOST_WIDE_INT *amountp) |
cce8749e | 13551 | { |
cd2b33d0 | 13552 | const char * mnem; |
e2c671ba | 13553 | enum rtx_code code = GET_CODE (op); |
cce8749e | 13554 | |
e6d29d15 NS |
13555 | switch (GET_CODE (XEXP (op, 1))) |
13556 | { | |
13557 | case REG: | |
13558 | case SUBREG: | |
13559 | *amountp = -1; | |
13560 | break; | |
13561 | ||
13562 | case CONST_INT: | |
13563 | *amountp = INTVAL (XEXP (op, 1)); | |
13564 | break; | |
13565 | ||
13566 | default: | |
13567 | gcc_unreachable (); | |
13568 | } | |
9997d19d | 13569 | |
e2c671ba | 13570 | switch (code) |
cce8749e | 13571 | { |
a657c98a | 13572 | case ROTATE: |
e6d29d15 | 13573 | gcc_assert (*amountp != -1); |
a657c98a | 13574 | *amountp = 32 - *amountp; |
5b3e6663 | 13575 | code = ROTATERT; |
a657c98a RE |
13576 | |
13577 | /* Fall through. */ | |
13578 | ||
5b3e6663 PB |
13579 | case ASHIFT: |
13580 | case ASHIFTRT: | |
13581 | case LSHIFTRT: | |
9997d19d | 13582 | case ROTATERT: |
5b3e6663 | 13583 | mnem = arm_shift_nmem(code); |
9997d19d RE |
13584 | break; |
13585 | ||
ff9940b0 | 13586 | case MULT: |
e2c671ba RE |
13587 | /* We never have to worry about the amount being other than a |
13588 | power of 2, since this case can never be reloaded from a reg. */ | |
e6d29d15 NS |
13589 | gcc_assert (*amountp != -1); |
13590 | *amountp = int_log2 (*amountp); | |
5b3e6663 | 13591 | return ARM_LSL_NAME; |
f3bb6135 | 13592 | |
cce8749e | 13593 | default: |
e6d29d15 | 13594 | gcc_unreachable (); |
cce8749e CH |
13595 | } |
13596 | ||
e2c671ba RE |
13597 | if (*amountp != -1) |
13598 | { | |
13599 | /* This is not 100% correct, but follows from the desire to merge | |
13600 | multiplication by a power of 2 with the recognizer for a | |
5b3e6663 | 13601 | shift. >=32 is not a valid shift for "lsl", so we must try and |
e2c671ba | 13602 | output a shift that produces the correct arithmetical result. |
ddd5a7c1 | 13603 | Using lsr #32 is identical except for the fact that the carry bit |
f676971a | 13604 | is not set correctly if we set the flags; but we never use the |
e2c671ba RE |
13605 | carry bit from such an operation, so we can ignore that. */ |
13606 | if (code == ROTATERT) | |
1d6e90ac NC |
13607 | /* Rotate is just modulo 32. */ |
13608 | *amountp &= 31; | |
e2c671ba RE |
13609 | else if (*amountp != (*amountp & 31)) |
13610 | { | |
13611 | if (code == ASHIFT) | |
13612 | mnem = "lsr"; | |
13613 | *amountp = 32; | |
13614 | } | |
13615 | ||
13616 | /* Shifts of 0 are no-ops. */ | |
13617 | if (*amountp == 0) | |
13618 | return NULL; | |
f676971a | 13619 | } |
e2c671ba | 13620 | |
9997d19d RE |
13621 | return mnem; |
13622 | } | |
cce8749e | 13623 | |
6354dc9b | 13624 | /* Obtain the shift from the POWER of two. */ |
1d6e90ac | 13625 | |
18af7313 | 13626 | static HOST_WIDE_INT |
e32bac5b | 13627 | int_log2 (HOST_WIDE_INT power) |
cce8749e | 13628 | { |
f3bb6135 | 13629 | HOST_WIDE_INT shift = 0; |
cce8749e | 13630 | |
30cf4896 | 13631 | while ((((HOST_WIDE_INT) 1 << shift) & power) == 0) |
cce8749e | 13632 | { |
e6d29d15 | 13633 | gcc_assert (shift <= 31); |
e32bac5b | 13634 | shift++; |
cce8749e | 13635 | } |
f3bb6135 RE |
13636 | |
13637 | return shift; | |
13638 | } | |
cce8749e | 13639 | |
c5ff069d ZW |
13640 | /* Output a .ascii pseudo-op, keeping track of lengths. This is |
13641 | because /bin/as is horribly restrictive. The judgement about | |
13642 | whether or not each character is 'printable' (and can be output as | |
13643 | is) or not (and must be printed with an octal escape) must be made | |
13644 | with reference to the *host* character set -- the situation is | |
13645 | similar to that discussed in the comments above pp_c_char in | |
13646 | c-pretty-print.c. */ | |
13647 | ||
6cfc7210 | 13648 | #define MAX_ASCII_LEN 51 |
cce8749e CH |
13649 | |
13650 | void | |
e32bac5b | 13651 | output_ascii_pseudo_op (FILE *stream, const unsigned char *p, int len) |
cce8749e CH |
13652 | { |
13653 | int i; | |
6cfc7210 | 13654 | int len_so_far = 0; |
cce8749e | 13655 | |
6cfc7210 | 13656 | fputs ("\t.ascii\t\"", stream); |
f676971a | 13657 | |
cce8749e CH |
13658 | for (i = 0; i < len; i++) |
13659 | { | |
1d6e90ac | 13660 | int c = p[i]; |
cce8749e | 13661 | |
6cfc7210 | 13662 | if (len_so_far >= MAX_ASCII_LEN) |
cce8749e | 13663 | { |
6cfc7210 | 13664 | fputs ("\"\n\t.ascii\t\"", stream); |
cce8749e | 13665 | len_so_far = 0; |
cce8749e CH |
13666 | } |
13667 | ||
c5ff069d | 13668 | if (ISPRINT (c)) |
cce8749e | 13669 | { |
c5ff069d | 13670 | if (c == '\\' || c == '\"') |
6cfc7210 | 13671 | { |
c5ff069d | 13672 | putc ('\\', stream); |
5895f793 | 13673 | len_so_far++; |
6cfc7210 | 13674 | } |
c5ff069d ZW |
13675 | putc (c, stream); |
13676 | len_so_far++; | |
13677 | } | |
13678 | else | |
13679 | { | |
13680 | fprintf (stream, "\\%03o", c); | |
13681 | len_so_far += 4; | |
cce8749e | 13682 | } |
cce8749e | 13683 | } |
f3bb6135 | 13684 | |
cce8749e | 13685 | fputs ("\"\n", stream); |
f3bb6135 | 13686 | } |
cce8749e | 13687 | \f |
c9ca9b88 | 13688 | /* Compute the register save mask for registers 0 through 12 |
5848830f | 13689 | inclusive. This code is used by arm_compute_save_reg_mask. */ |
b279b20a | 13690 | |
6d3d9133 | 13691 | static unsigned long |
e32bac5b | 13692 | arm_compute_save_reg0_reg12_mask (void) |
6d3d9133 | 13693 | { |
121308d4 | 13694 | unsigned long func_type = arm_current_func_type (); |
b279b20a | 13695 | unsigned long save_reg_mask = 0; |
6d3d9133 | 13696 | unsigned int reg; |
6d3d9133 | 13697 | |
7b8b8ade | 13698 | if (IS_INTERRUPT (func_type)) |
6d3d9133 | 13699 | { |
7b8b8ade | 13700 | unsigned int max_reg; |
7b8b8ade NC |
13701 | /* Interrupt functions must not corrupt any registers, |
13702 | even call clobbered ones. If this is a leaf function | |
13703 | we can just examine the registers used by the RTL, but | |
13704 | otherwise we have to assume that whatever function is | |
13705 | called might clobber anything, and so we have to save | |
13706 | all the call-clobbered registers as well. */ | |
13707 | if (ARM_FUNC_TYPE (func_type) == ARM_FT_FIQ) | |
13708 | /* FIQ handlers have registers r8 - r12 banked, so | |
13709 | we only need to check r0 - r7, Normal ISRs only | |
121308d4 | 13710 | bank r14 and r15, so we must check up to r12. |
7b8b8ade NC |
13711 | r13 is the stack pointer which is always preserved, |
13712 | so we do not need to consider it here. */ | |
13713 | max_reg = 7; | |
13714 | else | |
13715 | max_reg = 12; | |
f676971a | 13716 | |
7b8b8ade | 13717 | for (reg = 0; reg <= max_reg; reg++) |
6fb5fa3c DB |
13718 | if (df_regs_ever_live_p (reg) |
13719 | || (! current_function_is_leaf && call_used_regs[reg])) | |
6d3d9133 | 13720 | save_reg_mask |= (1 << reg); |
cfa01aab | 13721 | |
286d28c3 | 13722 | /* Also save the pic base register if necessary. */ |
cfa01aab PB |
13723 | if (flag_pic |
13724 | && !TARGET_SINGLE_PIC_BASE | |
020a4035 | 13725 | && arm_pic_register != INVALID_REGNUM |
e3b5732b | 13726 | && crtl->uses_pic_offset_table) |
cfa01aab | 13727 | save_reg_mask |= 1 << PIC_OFFSET_TABLE_REGNUM; |
6d3d9133 | 13728 | } |
1586899e PB |
13729 | else if (IS_VOLATILE(func_type)) |
13730 | { | |
13731 | /* For noreturn functions we historically omitted register saves | |
13732 | altogether. However this really messes up debugging. As a | |
3ed04dbd | 13733 | compromise save just the frame pointers. Combined with the link |
1586899e PB |
13734 | register saved elsewhere this should be sufficient to get |
13735 | a backtrace. */ | |
13736 | if (frame_pointer_needed) | |
13737 | save_reg_mask |= 1 << HARD_FRAME_POINTER_REGNUM; | |
13738 | if (df_regs_ever_live_p (ARM_HARD_FRAME_POINTER_REGNUM)) | |
13739 | save_reg_mask |= 1 << ARM_HARD_FRAME_POINTER_REGNUM; | |
13740 | if (df_regs_ever_live_p (THUMB_HARD_FRAME_POINTER_REGNUM)) | |
13741 | save_reg_mask |= 1 << THUMB_HARD_FRAME_POINTER_REGNUM; | |
13742 | } | |
6d3d9133 NC |
13743 | else |
13744 | { | |
13745 | /* In the normal case we only need to save those registers | |
13746 | which are call saved and which are used by this function. */ | |
ec6237e4 | 13747 | for (reg = 0; reg <= 11; reg++) |
6fb5fa3c | 13748 | if (df_regs_ever_live_p (reg) && ! call_used_regs[reg]) |
6d3d9133 NC |
13749 | save_reg_mask |= (1 << reg); |
13750 | ||
13751 | /* Handle the frame pointer as a special case. */ | |
ec6237e4 | 13752 | if (frame_pointer_needed) |
6d3d9133 NC |
13753 | save_reg_mask |= 1 << HARD_FRAME_POINTER_REGNUM; |
13754 | ||
13755 | /* If we aren't loading the PIC register, | |
13756 | don't stack it even though it may be live. */ | |
13757 | if (flag_pic | |
e0b92319 | 13758 | && !TARGET_SINGLE_PIC_BASE |
020a4035 | 13759 | && arm_pic_register != INVALID_REGNUM |
6fb5fa3c | 13760 | && (df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM) |
e3b5732b | 13761 | || crtl->uses_pic_offset_table)) |
6d3d9133 | 13762 | save_reg_mask |= 1 << PIC_OFFSET_TABLE_REGNUM; |
5b3e6663 PB |
13763 | |
13764 | /* The prologue will copy SP into R0, so save it. */ | |
13765 | if (IS_STACKALIGN (func_type)) | |
13766 | save_reg_mask |= 1; | |
6d3d9133 NC |
13767 | } |
13768 | ||
c9ca9b88 | 13769 | /* Save registers so the exception handler can modify them. */ |
e3b5732b | 13770 | if (crtl->calls_eh_return) |
c9ca9b88 PB |
13771 | { |
13772 | unsigned int i; | |
f676971a | 13773 | |
c9ca9b88 PB |
13774 | for (i = 0; ; i++) |
13775 | { | |
13776 | reg = EH_RETURN_DATA_REGNO (i); | |
13777 | if (reg == INVALID_REGNUM) | |
13778 | break; | |
13779 | save_reg_mask |= 1 << reg; | |
13780 | } | |
13781 | } | |
13782 | ||
121308d4 NC |
13783 | return save_reg_mask; |
13784 | } | |
13785 | ||
5b3e6663 | 13786 | |
35596784 AJ |
13787 | /* Compute the number of bytes used to store the static chain register on the |
13788 | stack, above the stack frame. We need to know this accurately to get the | |
13789 | alignment of the rest of the stack frame correct. */ | |
13790 | ||
13791 | static int arm_compute_static_chain_stack_bytes (void) | |
13792 | { | |
13793 | unsigned long func_type = arm_current_func_type (); | |
13794 | int static_chain_stack_bytes = 0; | |
13795 | ||
13796 | if (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM && | |
13797 | IS_NESTED (func_type) && | |
13798 | df_regs_ever_live_p (3) && crtl->args.pretend_args_size == 0) | |
13799 | static_chain_stack_bytes = 4; | |
13800 | ||
13801 | return static_chain_stack_bytes; | |
13802 | } | |
13803 | ||
13804 | ||
121308d4 | 13805 | /* Compute a bit mask of which registers need to be |
954954d1 PB |
13806 | saved on the stack for the current function. |
13807 | This is used by arm_get_frame_offsets, which may add extra registers. */ | |
121308d4 NC |
13808 | |
13809 | static unsigned long | |
e32bac5b | 13810 | arm_compute_save_reg_mask (void) |
121308d4 NC |
13811 | { |
13812 | unsigned int save_reg_mask = 0; | |
13813 | unsigned long func_type = arm_current_func_type (); | |
5b3e6663 | 13814 | unsigned int reg; |
121308d4 NC |
13815 | |
13816 | if (IS_NAKED (func_type)) | |
13817 | /* This should never really happen. */ | |
13818 | return 0; | |
13819 | ||
13820 | /* If we are creating a stack frame, then we must save the frame pointer, | |
13821 | IP (which will hold the old stack pointer), LR and the PC. */ | |
ec6237e4 | 13822 | if (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM) |
121308d4 NC |
13823 | save_reg_mask |= |
13824 | (1 << ARM_HARD_FRAME_POINTER_REGNUM) | |
13825 | | (1 << IP_REGNUM) | |
13826 | | (1 << LR_REGNUM) | |
13827 | | (1 << PC_REGNUM); | |
13828 | ||
121308d4 NC |
13829 | save_reg_mask |= arm_compute_save_reg0_reg12_mask (); |
13830 | ||
6d3d9133 NC |
13831 | /* Decide if we need to save the link register. |
13832 | Interrupt routines have their own banked link register, | |
13833 | so they never need to save it. | |
1768c26f | 13834 | Otherwise if we do not use the link register we do not need to save |
6d3d9133 NC |
13835 | it. If we are pushing other registers onto the stack however, we |
13836 | can save an instruction in the epilogue by pushing the link register | |
13837 | now and then popping it back into the PC. This incurs extra memory | |
72ac76be | 13838 | accesses though, so we only do it when optimizing for size, and only |
6d3d9133 | 13839 | if we know that we will not need a fancy return sequence. */ |
6fb5fa3c DB |
13840 | if (df_regs_ever_live_p (LR_REGNUM) |
13841 | || (save_reg_mask | |
13842 | && optimize_size | |
13843 | && ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL | |
e3b5732b | 13844 | && !crtl->calls_eh_return)) |
6d3d9133 NC |
13845 | save_reg_mask |= 1 << LR_REGNUM; |
13846 | ||
6f7ebcbb NC |
13847 | if (cfun->machine->lr_save_eliminated) |
13848 | save_reg_mask &= ~ (1 << LR_REGNUM); | |
13849 | ||
5a9335ef NC |
13850 | if (TARGET_REALLY_IWMMXT |
13851 | && ((bit_count (save_reg_mask) | |
35596784 AJ |
13852 | + ARM_NUM_INTS (crtl->args.pretend_args_size + |
13853 | arm_compute_static_chain_stack_bytes()) | |
13854 | ) % 2) != 0) | |
5a9335ef | 13855 | { |
5a9335ef NC |
13856 | /* The total number of registers that are going to be pushed |
13857 | onto the stack is odd. We need to ensure that the stack | |
13858 | is 64-bit aligned before we start to save iWMMXt registers, | |
13859 | and also before we start to create locals. (A local variable | |
13860 | might be a double or long long which we will load/store using | |
13861 | an iWMMXt instruction). Therefore we need to push another | |
13862 | ARM register, so that the stack will be 64-bit aligned. We | |
13863 | try to avoid using the arg registers (r0 -r3) as they might be | |
13864 | used to pass values in a tail call. */ | |
13865 | for (reg = 4; reg <= 12; reg++) | |
13866 | if ((save_reg_mask & (1 << reg)) == 0) | |
13867 | break; | |
13868 | ||
13869 | if (reg <= 12) | |
13870 | save_reg_mask |= (1 << reg); | |
13871 | else | |
13872 | { | |
13873 | cfun->machine->sibcall_blocked = 1; | |
13874 | save_reg_mask |= (1 << 3); | |
13875 | } | |
13876 | } | |
13877 | ||
5b3e6663 PB |
13878 | /* We may need to push an additional register for use initializing the |
13879 | PIC base register. */ | |
13880 | if (TARGET_THUMB2 && IS_NESTED (func_type) && flag_pic | |
13881 | && (save_reg_mask & THUMB2_WORK_REGS) == 0) | |
13882 | { | |
13883 | reg = thumb_find_work_register (1 << 4); | |
13884 | if (!call_used_regs[reg]) | |
13885 | save_reg_mask |= (1 << reg); | |
13886 | } | |
13887 | ||
6d3d9133 NC |
13888 | return save_reg_mask; |
13889 | } | |
13890 | ||
9728c9d1 | 13891 | |
57934c39 PB |
13892 | /* Compute a bit mask of which registers need to be |
13893 | saved on the stack for the current function. */ | |
13894 | static unsigned long | |
5b3e6663 | 13895 | thumb1_compute_save_reg_mask (void) |
57934c39 PB |
13896 | { |
13897 | unsigned long mask; | |
b279b20a | 13898 | unsigned reg; |
57934c39 PB |
13899 | |
13900 | mask = 0; | |
13901 | for (reg = 0; reg < 12; reg ++) | |
6fb5fa3c | 13902 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
b279b20a | 13903 | mask |= 1 << reg; |
57934c39 | 13904 | |
39c39be0 RE |
13905 | if (flag_pic |
13906 | && !TARGET_SINGLE_PIC_BASE | |
020a4035 | 13907 | && arm_pic_register != INVALID_REGNUM |
e3b5732b | 13908 | && crtl->uses_pic_offset_table) |
39c39be0 | 13909 | mask |= 1 << PIC_OFFSET_TABLE_REGNUM; |
b279b20a | 13910 | |
a2503645 RS |
13911 | /* See if we might need r11 for calls to _interwork_r11_call_via_rN(). */ |
13912 | if (!frame_pointer_needed && CALLER_INTERWORKING_SLOT_SIZE > 0) | |
13913 | mask |= 1 << ARM_HARD_FRAME_POINTER_REGNUM; | |
57934c39 | 13914 | |
b279b20a | 13915 | /* LR will also be pushed if any lo regs are pushed. */ |
57934c39 PB |
13916 | if (mask & 0xff || thumb_force_lr_save ()) |
13917 | mask |= (1 << LR_REGNUM); | |
13918 | ||
b279b20a NC |
13919 | /* Make sure we have a low work register if we need one. |
13920 | We will need one if we are going to push a high register, | |
13921 | but we are not currently intending to push a low register. */ | |
13922 | if ((mask & 0xff) == 0 | |
57934c39 | 13923 | && ((mask & 0x0f00) || TARGET_BACKTRACE)) |
b279b20a NC |
13924 | { |
13925 | /* Use thumb_find_work_register to choose which register | |
13926 | we will use. If the register is live then we will | |
13927 | have to push it. Use LAST_LO_REGNUM as our fallback | |
13928 | choice for the register to select. */ | |
13929 | reg = thumb_find_work_register (1 << LAST_LO_REGNUM); | |
19e723f4 PB |
13930 | /* Make sure the register returned by thumb_find_work_register is |
13931 | not part of the return value. */ | |
954954d1 | 13932 | if (reg * UNITS_PER_WORD <= (unsigned) arm_size_return_regs ()) |
19e723f4 | 13933 | reg = LAST_LO_REGNUM; |
b279b20a NC |
13934 | |
13935 | if (! call_used_regs[reg]) | |
13936 | mask |= 1 << reg; | |
13937 | } | |
57934c39 | 13938 | |
35596784 AJ |
13939 | /* The 504 below is 8 bytes less than 512 because there are two possible |
13940 | alignment words. We can't tell here if they will be present or not so we | |
13941 | have to play it safe and assume that they are. */ | |
13942 | if ((CALLER_INTERWORKING_SLOT_SIZE + | |
13943 | ROUND_UP_WORD (get_frame_size ()) + | |
13944 | crtl->outgoing_args_size) >= 504) | |
13945 | { | |
13946 | /* This is the same as the code in thumb1_expand_prologue() which | |
13947 | determines which register to use for stack decrement. */ | |
13948 | for (reg = LAST_ARG_REGNUM + 1; reg <= LAST_LO_REGNUM; reg++) | |
13949 | if (mask & (1 << reg)) | |
13950 | break; | |
13951 | ||
13952 | if (reg > LAST_LO_REGNUM) | |
13953 | { | |
13954 | /* Make sure we have a register available for stack decrement. */ | |
13955 | mask |= 1 << LAST_LO_REGNUM; | |
13956 | } | |
13957 | } | |
13958 | ||
57934c39 PB |
13959 | return mask; |
13960 | } | |
13961 | ||
13962 | ||
9728c9d1 PB |
13963 | /* Return the number of bytes required to save VFP registers. */ |
13964 | static int | |
13965 | arm_get_vfp_saved_size (void) | |
13966 | { | |
13967 | unsigned int regno; | |
13968 | int count; | |
13969 | int saved; | |
13970 | ||
13971 | saved = 0; | |
13972 | /* Space for saved VFP registers. */ | |
13973 | if (TARGET_HARD_FLOAT && TARGET_VFP) | |
13974 | { | |
13975 | count = 0; | |
13976 | for (regno = FIRST_VFP_REGNUM; | |
13977 | regno < LAST_VFP_REGNUM; | |
13978 | regno += 2) | |
13979 | { | |
6fb5fa3c DB |
13980 | if ((!df_regs_ever_live_p (regno) || call_used_regs[regno]) |
13981 | && (!df_regs_ever_live_p (regno + 1) || call_used_regs[regno + 1])) | |
9728c9d1 PB |
13982 | { |
13983 | if (count > 0) | |
13984 | { | |
13985 | /* Workaround ARM10 VFPr1 bug. */ | |
13986 | if (count == 2 && !arm_arch6) | |
13987 | count++; | |
8edfc4cc | 13988 | saved += count * 8; |
9728c9d1 PB |
13989 | } |
13990 | count = 0; | |
13991 | } | |
13992 | else | |
13993 | count++; | |
13994 | } | |
13995 | if (count > 0) | |
13996 | { | |
13997 | if (count == 2 && !arm_arch6) | |
13998 | count++; | |
8edfc4cc | 13999 | saved += count * 8; |
9728c9d1 PB |
14000 | } |
14001 | } | |
14002 | return saved; | |
14003 | } | |
14004 | ||
14005 | ||
699a4925 | 14006 | /* Generate a function exit sequence. If REALLY_RETURN is false, then do |
6d3d9133 | 14007 | everything bar the final return instruction. */ |
cd2b33d0 | 14008 | const char * |
e32bac5b | 14009 | output_return_instruction (rtx operand, int really_return, int reverse) |
ff9940b0 | 14010 | { |
6d3d9133 | 14011 | char conditional[10]; |
ff9940b0 | 14012 | char instr[100]; |
b279b20a | 14013 | unsigned reg; |
6d3d9133 NC |
14014 | unsigned long live_regs_mask; |
14015 | unsigned long func_type; | |
5848830f | 14016 | arm_stack_offsets *offsets; |
e26053d1 | 14017 | |
6d3d9133 | 14018 | func_type = arm_current_func_type (); |
e2c671ba | 14019 | |
6d3d9133 | 14020 | if (IS_NAKED (func_type)) |
d5b7b3ae | 14021 | return ""; |
6d3d9133 NC |
14022 | |
14023 | if (IS_VOLATILE (func_type) && TARGET_ABORT_NORETURN) | |
e2c671ba | 14024 | { |
699a4925 RE |
14025 | /* If this function was declared non-returning, and we have |
14026 | found a tail call, then we have to trust that the called | |
14027 | function won't return. */ | |
3a5a4282 PB |
14028 | if (really_return) |
14029 | { | |
14030 | rtx ops[2]; | |
f676971a | 14031 | |
3a5a4282 PB |
14032 | /* Otherwise, trap an attempted return by aborting. */ |
14033 | ops[0] = operand; | |
f676971a | 14034 | ops[1] = gen_rtx_SYMBOL_REF (Pmode, NEED_PLT_RELOC ? "abort(PLT)" |
3a5a4282 PB |
14035 | : "abort"); |
14036 | assemble_external_libcall (ops[1]); | |
14037 | output_asm_insn (reverse ? "bl%D0\t%a1" : "bl%d0\t%a1", ops); | |
14038 | } | |
f676971a | 14039 | |
e2c671ba RE |
14040 | return ""; |
14041 | } | |
6d3d9133 | 14042 | |
e3b5732b | 14043 | gcc_assert (!cfun->calls_alloca || really_return); |
ff9940b0 | 14044 | |
c414f8a9 | 14045 | sprintf (conditional, "%%?%%%c0", reverse ? 'D' : 'd'); |
d5b7b3ae | 14046 | |
934c2060 | 14047 | cfun->machine->return_used_this_function = 1; |
ff9940b0 | 14048 | |
954954d1 PB |
14049 | offsets = arm_get_frame_offsets (); |
14050 | live_regs_mask = offsets->saved_regs_mask; | |
ff9940b0 | 14051 | |
1768c26f | 14052 | if (live_regs_mask) |
6d3d9133 | 14053 | { |
1768c26f PB |
14054 | const char * return_reg; |
14055 | ||
f676971a | 14056 | /* If we do not have any special requirements for function exit |
a15908a4 | 14057 | (e.g. interworking) then we can load the return address |
1768c26f PB |
14058 | directly into the PC. Otherwise we must load it into LR. */ |
14059 | if (really_return | |
a15908a4 | 14060 | && (IS_INTERRUPT (func_type) || !TARGET_INTERWORK)) |
1768c26f | 14061 | return_reg = reg_names[PC_REGNUM]; |
6d3d9133 | 14062 | else |
1768c26f PB |
14063 | return_reg = reg_names[LR_REGNUM]; |
14064 | ||
6d3d9133 | 14065 | if ((live_regs_mask & (1 << IP_REGNUM)) == (1 << IP_REGNUM)) |
b034930f ILT |
14066 | { |
14067 | /* There are three possible reasons for the IP register | |
14068 | being saved. 1) a stack frame was created, in which case | |
14069 | IP contains the old stack pointer, or 2) an ISR routine | |
14070 | corrupted it, or 3) it was saved to align the stack on | |
14071 | iWMMXt. In case 1, restore IP into SP, otherwise just | |
14072 | restore IP. */ | |
14073 | if (frame_pointer_needed) | |
14074 | { | |
14075 | live_regs_mask &= ~ (1 << IP_REGNUM); | |
14076 | live_regs_mask |= (1 << SP_REGNUM); | |
14077 | } | |
14078 | else | |
e6d29d15 | 14079 | gcc_assert (IS_INTERRUPT (func_type) || TARGET_REALLY_IWMMXT); |
b034930f | 14080 | } |
f3bb6135 | 14081 | |
3a7731fd PB |
14082 | /* On some ARM architectures it is faster to use LDR rather than |
14083 | LDM to load a single register. On other architectures, the | |
14084 | cost is the same. In 26 bit mode, or for exception handlers, | |
14085 | we have to use LDM to load the PC so that the CPSR is also | |
14086 | restored. */ | |
14087 | for (reg = 0; reg <= LAST_ARM_REGNUM; reg++) | |
b279b20a NC |
14088 | if (live_regs_mask == (1U << reg)) |
14089 | break; | |
14090 | ||
3a7731fd PB |
14091 | if (reg <= LAST_ARM_REGNUM |
14092 | && (reg != LR_REGNUM | |
f676971a | 14093 | || ! really_return |
61f0ccff | 14094 | || ! IS_INTERRUPT (func_type))) |
3a7731fd | 14095 | { |
f676971a | 14096 | sprintf (instr, "ldr%s\t%%|%s, [%%|sp], #4", conditional, |
3a7731fd | 14097 | (reg == LR_REGNUM) ? return_reg : reg_names[reg]); |
6d3d9133 | 14098 | } |
ff9940b0 | 14099 | else |
1d5473cb | 14100 | { |
1768c26f PB |
14101 | char *p; |
14102 | int first = 1; | |
6d3d9133 | 14103 | |
699a4925 RE |
14104 | /* Generate the load multiple instruction to restore the |
14105 | registers. Note we can get here, even if | |
14106 | frame_pointer_needed is true, but only if sp already | |
14107 | points to the base of the saved core registers. */ | |
14108 | if (live_regs_mask & (1 << SP_REGNUM)) | |
a72d4945 | 14109 | { |
5848830f PB |
14110 | unsigned HOST_WIDE_INT stack_adjust; |
14111 | ||
5848830f | 14112 | stack_adjust = offsets->outgoing_args - offsets->saved_regs; |
e6d29d15 | 14113 | gcc_assert (stack_adjust == 0 || stack_adjust == 4); |
a72d4945 | 14114 | |
5b3e6663 | 14115 | if (stack_adjust && arm_arch5 && TARGET_ARM) |
c7e9ab97 RR |
14116 | if (TARGET_UNIFIED_ASM) |
14117 | sprintf (instr, "ldmib%s\t%%|sp, {", conditional); | |
14118 | else | |
14119 | sprintf (instr, "ldm%sib\t%%|sp, {", conditional); | |
a72d4945 RE |
14120 | else |
14121 | { | |
b279b20a NC |
14122 | /* If we can't use ldmib (SA110 bug), |
14123 | then try to pop r3 instead. */ | |
a72d4945 RE |
14124 | if (stack_adjust) |
14125 | live_regs_mask |= 1 << 3; | |
c7e9ab97 RR |
14126 | |
14127 | if (TARGET_UNIFIED_ASM) | |
14128 | sprintf (instr, "ldmfd%s\t%%|sp, {", conditional); | |
14129 | else | |
14130 | sprintf (instr, "ldm%sfd\t%%|sp, {", conditional); | |
a72d4945 RE |
14131 | } |
14132 | } | |
da6558fd | 14133 | else |
c7e9ab97 RR |
14134 | if (TARGET_UNIFIED_ASM) |
14135 | sprintf (instr, "pop%s\t{", conditional); | |
14136 | else | |
14137 | sprintf (instr, "ldm%sfd\t%%|sp!, {", conditional); | |
1768c26f PB |
14138 | |
14139 | p = instr + strlen (instr); | |
6d3d9133 | 14140 | |
1768c26f PB |
14141 | for (reg = 0; reg <= SP_REGNUM; reg++) |
14142 | if (live_regs_mask & (1 << reg)) | |
14143 | { | |
14144 | int l = strlen (reg_names[reg]); | |
14145 | ||
14146 | if (first) | |
14147 | first = 0; | |
14148 | else | |
14149 | { | |
14150 | memcpy (p, ", ", 2); | |
14151 | p += 2; | |
14152 | } | |
14153 | ||
14154 | memcpy (p, "%|", 2); | |
14155 | memcpy (p + 2, reg_names[reg], l); | |
14156 | p += l + 2; | |
14157 | } | |
f676971a | 14158 | |
1768c26f PB |
14159 | if (live_regs_mask & (1 << LR_REGNUM)) |
14160 | { | |
b17fe233 | 14161 | sprintf (p, "%s%%|%s}", first ? "" : ", ", return_reg); |
61f0ccff RE |
14162 | /* If returning from an interrupt, restore the CPSR. */ |
14163 | if (IS_INTERRUPT (func_type)) | |
b17fe233 | 14164 | strcat (p, "^"); |
1768c26f PB |
14165 | } |
14166 | else | |
14167 | strcpy (p, "}"); | |
1d5473cb | 14168 | } |
da6558fd | 14169 | |
1768c26f PB |
14170 | output_asm_insn (instr, & operand); |
14171 | ||
3a7731fd PB |
14172 | /* See if we need to generate an extra instruction to |
14173 | perform the actual function return. */ | |
14174 | if (really_return | |
14175 | && func_type != ARM_FT_INTERWORKED | |
14176 | && (live_regs_mask & (1 << LR_REGNUM)) != 0) | |
da6558fd | 14177 | { |
3a7731fd PB |
14178 | /* The return has already been handled |
14179 | by loading the LR into the PC. */ | |
14180 | really_return = 0; | |
da6558fd | 14181 | } |
ff9940b0 | 14182 | } |
e26053d1 | 14183 | |
1768c26f | 14184 | if (really_return) |
ff9940b0 | 14185 | { |
6d3d9133 NC |
14186 | switch ((int) ARM_FUNC_TYPE (func_type)) |
14187 | { | |
14188 | case ARM_FT_ISR: | |
14189 | case ARM_FT_FIQ: | |
5b3e6663 | 14190 | /* ??? This is wrong for unified assembly syntax. */ |
6d3d9133 NC |
14191 | sprintf (instr, "sub%ss\t%%|pc, %%|lr, #4", conditional); |
14192 | break; | |
14193 | ||
14194 | case ARM_FT_INTERWORKED: | |
14195 | sprintf (instr, "bx%s\t%%|lr", conditional); | |
14196 | break; | |
14197 | ||
14198 | case ARM_FT_EXCEPTION: | |
5b3e6663 | 14199 | /* ??? This is wrong for unified assembly syntax. */ |
6d3d9133 NC |
14200 | sprintf (instr, "mov%ss\t%%|pc, %%|lr", conditional); |
14201 | break; | |
14202 | ||
14203 | default: | |
68d560d4 RE |
14204 | /* Use bx if it's available. */ |
14205 | if (arm_arch5 || arm_arch4t) | |
f676971a | 14206 | sprintf (instr, "bx%s\t%%|lr", conditional); |
1768c26f | 14207 | else |
61f0ccff | 14208 | sprintf (instr, "mov%s\t%%|pc, %%|lr", conditional); |
6d3d9133 NC |
14209 | break; |
14210 | } | |
1768c26f PB |
14211 | |
14212 | output_asm_insn (instr, & operand); | |
ff9940b0 | 14213 | } |
f3bb6135 | 14214 | |
ff9940b0 RE |
14215 | return ""; |
14216 | } | |
14217 | ||
ef179a26 NC |
14218 | /* Write the function name into the code section, directly preceding |
14219 | the function prologue. | |
14220 | ||
14221 | Code will be output similar to this: | |
14222 | t0 | |
14223 | .ascii "arm_poke_function_name", 0 | |
14224 | .align | |
14225 | t1 | |
14226 | .word 0xff000000 + (t1 - t0) | |
14227 | arm_poke_function_name | |
14228 | mov ip, sp | |
14229 | stmfd sp!, {fp, ip, lr, pc} | |
14230 | sub fp, ip, #4 | |
14231 | ||
14232 | When performing a stack backtrace, code can inspect the value | |
14233 | of 'pc' stored at 'fp' + 0. If the trace function then looks | |
14234 | at location pc - 12 and the top 8 bits are set, then we know | |
14235 | that there is a function name embedded immediately preceding this | |
14236 | location and has length ((pc[-3]) & 0xff000000). | |
14237 | ||
14238 | We assume that pc is declared as a pointer to an unsigned long. | |
14239 | ||
14240 | It is of no benefit to output the function name if we are assembling | |
14241 | a leaf function. These function types will not contain a stack | |
14242 | backtrace structure, therefore it is not possible to determine the | |
14243 | function name. */ | |
ef179a26 | 14244 | void |
e32bac5b | 14245 | arm_poke_function_name (FILE *stream, const char *name) |
ef179a26 NC |
14246 | { |
14247 | unsigned long alignlength; | |
14248 | unsigned long length; | |
14249 | rtx x; | |
14250 | ||
d5b7b3ae | 14251 | length = strlen (name) + 1; |
0c2ca901 | 14252 | alignlength = ROUND_UP_WORD (length); |
f676971a | 14253 | |
949d79eb | 14254 | ASM_OUTPUT_ASCII (stream, name, length); |
ef179a26 | 14255 | ASM_OUTPUT_ALIGN (stream, 2); |
30cf4896 | 14256 | x = GEN_INT ((unsigned HOST_WIDE_INT) 0xff000000 + alignlength); |
301d03af | 14257 | assemble_aligned_integer (UNITS_PER_WORD, x); |
ef179a26 NC |
14258 | } |
14259 | ||
6d3d9133 NC |
14260 | /* Place some comments into the assembler stream |
14261 | describing the current function. */ | |
08c148a8 | 14262 | static void |
e32bac5b | 14263 | arm_output_function_prologue (FILE *f, HOST_WIDE_INT frame_size) |
cce8749e | 14264 | { |
6d3d9133 | 14265 | unsigned long func_type; |
08c148a8 | 14266 | |
5b3e6663 | 14267 | if (TARGET_THUMB1) |
08c148a8 | 14268 | { |
5b3e6663 | 14269 | thumb1_output_function_prologue (f, frame_size); |
08c148a8 NB |
14270 | return; |
14271 | } | |
f676971a | 14272 | |
6d3d9133 | 14273 | /* Sanity check. */ |
e6d29d15 | 14274 | gcc_assert (!arm_ccfsm_state && !arm_target_insn); |
31fdb4d5 | 14275 | |
6d3d9133 | 14276 | func_type = arm_current_func_type (); |
f676971a | 14277 | |
6d3d9133 NC |
14278 | switch ((int) ARM_FUNC_TYPE (func_type)) |
14279 | { | |
14280 | default: | |
14281 | case ARM_FT_NORMAL: | |
14282 | break; | |
14283 | case ARM_FT_INTERWORKED: | |
14284 | asm_fprintf (f, "\t%@ Function supports interworking.\n"); | |
14285 | break; | |
6d3d9133 NC |
14286 | case ARM_FT_ISR: |
14287 | asm_fprintf (f, "\t%@ Interrupt Service Routine.\n"); | |
14288 | break; | |
14289 | case ARM_FT_FIQ: | |
14290 | asm_fprintf (f, "\t%@ Fast Interrupt Service Routine.\n"); | |
14291 | break; | |
14292 | case ARM_FT_EXCEPTION: | |
14293 | asm_fprintf (f, "\t%@ ARM Exception Handler.\n"); | |
14294 | break; | |
14295 | } | |
f676971a | 14296 | |
6d3d9133 NC |
14297 | if (IS_NAKED (func_type)) |
14298 | asm_fprintf (f, "\t%@ Naked Function: prologue and epilogue provided by programmer.\n"); | |
14299 | ||
14300 | if (IS_VOLATILE (func_type)) | |
14301 | asm_fprintf (f, "\t%@ Volatile: function does not return.\n"); | |
14302 | ||
14303 | if (IS_NESTED (func_type)) | |
14304 | asm_fprintf (f, "\t%@ Nested: function declared inside another function.\n"); | |
5b3e6663 PB |
14305 | if (IS_STACKALIGN (func_type)) |
14306 | asm_fprintf (f, "\t%@ Stack Align: May be called with mis-aligned SP.\n"); | |
f676971a | 14307 | |
c53dddc2 | 14308 | asm_fprintf (f, "\t%@ args = %d, pretend = %d, frame = %wd\n", |
38173d38 JH |
14309 | crtl->args.size, |
14310 | crtl->args.pretend_args_size, frame_size); | |
6d3d9133 | 14311 | |
3cb66fd7 | 14312 | asm_fprintf (f, "\t%@ frame_needed = %d, uses_anonymous_args = %d\n", |
dd18ae56 | 14313 | frame_pointer_needed, |
3cb66fd7 | 14314 | cfun->machine->uses_anonymous_args); |
cce8749e | 14315 | |
6f7ebcbb NC |
14316 | if (cfun->machine->lr_save_eliminated) |
14317 | asm_fprintf (f, "\t%@ link register save eliminated.\n"); | |
14318 | ||
e3b5732b | 14319 | if (crtl->calls_eh_return) |
c9ca9b88 PB |
14320 | asm_fprintf (f, "\t@ Calls __builtin_eh_return.\n"); |
14321 | ||
f3bb6135 | 14322 | } |
cce8749e | 14323 | |
cd2b33d0 | 14324 | const char * |
a72d4945 | 14325 | arm_output_epilogue (rtx sibling) |
cce8749e | 14326 | { |
949d79eb | 14327 | int reg; |
6f7ebcbb | 14328 | unsigned long saved_regs_mask; |
6d3d9133 | 14329 | unsigned long func_type; |
f676971a | 14330 | /* Floats_offset is the offset from the "virtual" frame. In an APCS |
c882c7ac RE |
14331 | frame that is $fp + 4 for a non-variadic function. */ |
14332 | int floats_offset = 0; | |
cce8749e | 14333 | rtx operands[3]; |
d5b7b3ae | 14334 | FILE * f = asm_out_file; |
5a9335ef | 14335 | unsigned int lrm_count = 0; |
a72d4945 | 14336 | int really_return = (sibling == NULL); |
9b66ebb1 | 14337 | int start_reg; |
5848830f | 14338 | arm_stack_offsets *offsets; |
cce8749e | 14339 | |
6d3d9133 NC |
14340 | /* If we have already generated the return instruction |
14341 | then it is futile to generate anything else. */ | |
934c2060 RR |
14342 | if (use_return_insn (FALSE, sibling) && |
14343 | (cfun->machine->return_used_this_function != 0)) | |
949d79eb | 14344 | return ""; |
cce8749e | 14345 | |
6d3d9133 | 14346 | func_type = arm_current_func_type (); |
d5b7b3ae | 14347 | |
6d3d9133 NC |
14348 | if (IS_NAKED (func_type)) |
14349 | /* Naked functions don't have epilogues. */ | |
14350 | return ""; | |
0616531f | 14351 | |
6d3d9133 | 14352 | if (IS_VOLATILE (func_type) && TARGET_ABORT_NORETURN) |
e2c671ba | 14353 | { |
86efdc8e | 14354 | rtx op; |
f676971a | 14355 | |
6d3d9133 | 14356 | /* A volatile function should never return. Call abort. */ |
ed0e6530 | 14357 | op = gen_rtx_SYMBOL_REF (Pmode, NEED_PLT_RELOC ? "abort(PLT)" : "abort"); |
2b835d68 | 14358 | assemble_external_libcall (op); |
e2c671ba | 14359 | output_asm_insn ("bl\t%a0", &op); |
f676971a | 14360 | |
949d79eb | 14361 | return ""; |
e2c671ba RE |
14362 | } |
14363 | ||
e6d29d15 NS |
14364 | /* If we are throwing an exception, then we really must be doing a |
14365 | return, so we can't tail-call. */ | |
e3b5732b | 14366 | gcc_assert (!crtl->calls_eh_return || really_return); |
f676971a | 14367 | |
5848830f | 14368 | offsets = arm_get_frame_offsets (); |
954954d1 | 14369 | saved_regs_mask = offsets->saved_regs_mask; |
5a9335ef NC |
14370 | |
14371 | if (TARGET_IWMMXT) | |
14372 | lrm_count = bit_count (saved_regs_mask); | |
14373 | ||
5848830f | 14374 | floats_offset = offsets->saved_args; |
6d3d9133 | 14375 | /* Compute how far away the floats will be. */ |
5a9335ef | 14376 | for (reg = 0; reg <= LAST_ARM_REGNUM; reg++) |
6f7ebcbb | 14377 | if (saved_regs_mask & (1 << reg)) |
6ed30148 | 14378 | floats_offset += 4; |
f676971a | 14379 | |
ec6237e4 | 14380 | if (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM) |
cce8749e | 14381 | { |
9b66ebb1 | 14382 | /* This variable is for the Virtual Frame Pointer, not VFP regs. */ |
5848830f | 14383 | int vfp_offset = offsets->frame; |
c882c7ac | 14384 | |
d79f3032 | 14385 | if (TARGET_FPA_EMU2) |
b111229a | 14386 | { |
9b66ebb1 | 14387 | for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--) |
6fb5fa3c | 14388 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
b111229a RE |
14389 | { |
14390 | floats_offset += 12; | |
f676971a | 14391 | asm_fprintf (f, "\tldfe\t%r, [%r, #-%d]\n", |
c882c7ac | 14392 | reg, FP_REGNUM, floats_offset - vfp_offset); |
b111229a RE |
14393 | } |
14394 | } | |
14395 | else | |
14396 | { | |
9b66ebb1 | 14397 | start_reg = LAST_FPA_REGNUM; |
b111229a | 14398 | |
9b66ebb1 | 14399 | for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--) |
b111229a | 14400 | { |
6fb5fa3c | 14401 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
b111229a RE |
14402 | { |
14403 | floats_offset += 12; | |
f676971a | 14404 | |
6354dc9b | 14405 | /* We can't unstack more than four registers at once. */ |
b111229a RE |
14406 | if (start_reg - reg == 3) |
14407 | { | |
dd18ae56 | 14408 | asm_fprintf (f, "\tlfm\t%r, 4, [%r, #-%d]\n", |
c882c7ac | 14409 | reg, FP_REGNUM, floats_offset - vfp_offset); |
b111229a RE |
14410 | start_reg = reg - 1; |
14411 | } | |
14412 | } | |
14413 | else | |
14414 | { | |
14415 | if (reg != start_reg) | |
dd18ae56 NC |
14416 | asm_fprintf (f, "\tlfm\t%r, %d, [%r, #-%d]\n", |
14417 | reg + 1, start_reg - reg, | |
c882c7ac | 14418 | FP_REGNUM, floats_offset - vfp_offset); |
b111229a RE |
14419 | start_reg = reg - 1; |
14420 | } | |
14421 | } | |
14422 | ||
14423 | /* Just in case the last register checked also needs unstacking. */ | |
14424 | if (reg != start_reg) | |
dd18ae56 NC |
14425 | asm_fprintf (f, "\tlfm\t%r, %d, [%r, #-%d]\n", |
14426 | reg + 1, start_reg - reg, | |
c882c7ac | 14427 | FP_REGNUM, floats_offset - vfp_offset); |
b111229a | 14428 | } |
6d3d9133 | 14429 | |
9b66ebb1 PB |
14430 | if (TARGET_HARD_FLOAT && TARGET_VFP) |
14431 | { | |
9728c9d1 | 14432 | int saved_size; |
9b66ebb1 | 14433 | |
8edfc4cc MS |
14434 | /* The fldmd insns do not have base+offset addressing |
14435 | modes, so we use IP to hold the address. */ | |
9728c9d1 | 14436 | saved_size = arm_get_vfp_saved_size (); |
9b66ebb1 | 14437 | |
9728c9d1 | 14438 | if (saved_size > 0) |
9b66ebb1 | 14439 | { |
9728c9d1 | 14440 | floats_offset += saved_size; |
9b66ebb1 PB |
14441 | asm_fprintf (f, "\tsub\t%r, %r, #%d\n", IP_REGNUM, |
14442 | FP_REGNUM, floats_offset - vfp_offset); | |
14443 | } | |
14444 | start_reg = FIRST_VFP_REGNUM; | |
14445 | for (reg = FIRST_VFP_REGNUM; reg < LAST_VFP_REGNUM; reg += 2) | |
14446 | { | |
6fb5fa3c DB |
14447 | if ((!df_regs_ever_live_p (reg) || call_used_regs[reg]) |
14448 | && (!df_regs_ever_live_p (reg + 1) || call_used_regs[reg + 1])) | |
9b66ebb1 PB |
14449 | { |
14450 | if (start_reg != reg) | |
8edfc4cc | 14451 | vfp_output_fldmd (f, IP_REGNUM, |
9728c9d1 PB |
14452 | (start_reg - FIRST_VFP_REGNUM) / 2, |
14453 | (reg - start_reg) / 2); | |
9b66ebb1 PB |
14454 | start_reg = reg + 2; |
14455 | } | |
14456 | } | |
14457 | if (start_reg != reg) | |
8edfc4cc | 14458 | vfp_output_fldmd (f, IP_REGNUM, |
9728c9d1 PB |
14459 | (start_reg - FIRST_VFP_REGNUM) / 2, |
14460 | (reg - start_reg) / 2); | |
9b66ebb1 PB |
14461 | } |
14462 | ||
5a9335ef NC |
14463 | if (TARGET_IWMMXT) |
14464 | { | |
14465 | /* The frame pointer is guaranteed to be non-double-word aligned. | |
14466 | This is because it is set to (old_stack_pointer - 4) and the | |
14467 | old_stack_pointer was double word aligned. Thus the offset to | |
14468 | the iWMMXt registers to be loaded must also be non-double-word | |
14469 | sized, so that the resultant address *is* double-word aligned. | |
14470 | We can ignore floats_offset since that was already included in | |
14471 | the live_regs_mask. */ | |
14472 | lrm_count += (lrm_count % 2 ? 2 : 1); | |
f676971a | 14473 | |
01d4c813 | 14474 | for (reg = LAST_IWMMXT_REGNUM; reg >= FIRST_IWMMXT_REGNUM; reg--) |
6fb5fa3c | 14475 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
5a9335ef | 14476 | { |
f676971a | 14477 | asm_fprintf (f, "\twldrd\t%r, [%r, #-%d]\n", |
5a9335ef | 14478 | reg, FP_REGNUM, lrm_count * 4); |
f676971a | 14479 | lrm_count += 2; |
5a9335ef NC |
14480 | } |
14481 | } | |
14482 | ||
6f7ebcbb | 14483 | /* saved_regs_mask should contain the IP, which at the time of stack |
6d3d9133 NC |
14484 | frame generation actually contains the old stack pointer. So a |
14485 | quick way to unwind the stack is just pop the IP register directly | |
14486 | into the stack pointer. */ | |
e6d29d15 | 14487 | gcc_assert (saved_regs_mask & (1 << IP_REGNUM)); |
6f7ebcbb NC |
14488 | saved_regs_mask &= ~ (1 << IP_REGNUM); |
14489 | saved_regs_mask |= (1 << SP_REGNUM); | |
6d3d9133 | 14490 | |
6f7ebcbb | 14491 | /* There are two registers left in saved_regs_mask - LR and PC. We |
6d3d9133 NC |
14492 | only need to restore the LR register (the return address), but to |
14493 | save time we can load it directly into the PC, unless we need a | |
14494 | special function exit sequence, or we are not really returning. */ | |
c9ca9b88 PB |
14495 | if (really_return |
14496 | && ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL | |
e3b5732b | 14497 | && !crtl->calls_eh_return) |
6d3d9133 NC |
14498 | /* Delete the LR from the register mask, so that the LR on |
14499 | the stack is loaded into the PC in the register mask. */ | |
6f7ebcbb | 14500 | saved_regs_mask &= ~ (1 << LR_REGNUM); |
b111229a | 14501 | else |
6f7ebcbb | 14502 | saved_regs_mask &= ~ (1 << PC_REGNUM); |
efc2515b RE |
14503 | |
14504 | /* We must use SP as the base register, because SP is one of the | |
14505 | registers being restored. If an interrupt or page fault | |
14506 | happens in the ldm instruction, the SP might or might not | |
14507 | have been restored. That would be bad, as then SP will no | |
14508 | longer indicate the safe area of stack, and we can get stack | |
14509 | corruption. Using SP as the base register means that it will | |
14510 | be reset correctly to the original value, should an interrupt | |
699a4925 RE |
14511 | occur. If the stack pointer already points at the right |
14512 | place, then omit the subtraction. */ | |
5848830f | 14513 | if (offsets->outgoing_args != (1 + (int) bit_count (saved_regs_mask)) |
e3b5732b | 14514 | || cfun->calls_alloca) |
699a4925 RE |
14515 | asm_fprintf (f, "\tsub\t%r, %r, #%d\n", SP_REGNUM, FP_REGNUM, |
14516 | 4 * bit_count (saved_regs_mask)); | |
a15908a4 | 14517 | print_multi_reg (f, "ldmfd\t%r, ", SP_REGNUM, saved_regs_mask, 0); |
7b8b8ade NC |
14518 | |
14519 | if (IS_INTERRUPT (func_type)) | |
14520 | /* Interrupt handlers will have pushed the | |
14521 | IP onto the stack, so restore it now. */ | |
a15908a4 | 14522 | print_multi_reg (f, "ldmfd\t%r!, ", SP_REGNUM, 1 << IP_REGNUM, 0); |
cce8749e CH |
14523 | } |
14524 | else | |
14525 | { | |
ec6237e4 PB |
14526 | /* This branch is executed for ARM mode (non-apcs frames) and |
14527 | Thumb-2 mode. Frame layout is essentially the same for those | |
14528 | cases, except that in ARM mode frame pointer points to the | |
14529 | first saved register, while in Thumb-2 mode the frame pointer points | |
14530 | to the last saved register. | |
14531 | ||
14532 | It is possible to make frame pointer point to last saved | |
14533 | register in both cases, and remove some conditionals below. | |
14534 | That means that fp setup in prologue would be just "mov fp, sp" | |
14535 | and sp restore in epilogue would be just "mov sp, fp", whereas | |
14536 | now we have to use add/sub in those cases. However, the value | |
14537 | of that would be marginal, as both mov and add/sub are 32-bit | |
14538 | in ARM mode, and it would require extra conditionals | |
14539 | in arm_expand_prologue to distingish ARM-apcs-frame case | |
14540 | (where frame pointer is required to point at first register) | |
14541 | and ARM-non-apcs-frame. Therefore, such change is postponed | |
14542 | until real need arise. */ | |
f0b4bdd5 | 14543 | unsigned HOST_WIDE_INT amount; |
a15908a4 | 14544 | int rfe; |
d2288d8d | 14545 | /* Restore stack pointer if necessary. */ |
ec6237e4 | 14546 | if (TARGET_ARM && frame_pointer_needed) |
5b3e6663 PB |
14547 | { |
14548 | operands[0] = stack_pointer_rtx; | |
ec6237e4 PB |
14549 | operands[1] = hard_frame_pointer_rtx; |
14550 | ||
14551 | operands[2] = GEN_INT (offsets->frame - offsets->saved_regs); | |
14552 | output_add_immediate (operands); | |
5b3e6663 | 14553 | } |
ec6237e4 | 14554 | else |
5b3e6663 | 14555 | { |
ec6237e4 PB |
14556 | if (frame_pointer_needed) |
14557 | { | |
14558 | /* For Thumb-2 restore sp from the frame pointer. | |
14559 | Operand restrictions mean we have to incrememnt FP, then copy | |
14560 | to SP. */ | |
14561 | amount = offsets->locals_base - offsets->saved_regs; | |
14562 | operands[0] = hard_frame_pointer_rtx; | |
14563 | } | |
14564 | else | |
14565 | { | |
954954d1 | 14566 | unsigned long count; |
ec6237e4 PB |
14567 | operands[0] = stack_pointer_rtx; |
14568 | amount = offsets->outgoing_args - offsets->saved_regs; | |
954954d1 PB |
14569 | /* pop call clobbered registers if it avoids a |
14570 | separate stack adjustment. */ | |
14571 | count = offsets->saved_regs - offsets->saved_args; | |
14572 | if (optimize_size | |
14573 | && count != 0 | |
e3b5732b | 14574 | && !crtl->calls_eh_return |
954954d1 PB |
14575 | && bit_count(saved_regs_mask) * 4 == count |
14576 | && !IS_INTERRUPT (func_type) | |
e3b5732b | 14577 | && !crtl->tail_call_emit) |
954954d1 PB |
14578 | { |
14579 | unsigned long mask; | |
c92f1823 IB |
14580 | /* Preserve return values, of any size. */ |
14581 | mask = (1 << ((arm_size_return_regs() + 3) / 4)) - 1; | |
954954d1 PB |
14582 | mask ^= 0xf; |
14583 | mask &= ~saved_regs_mask; | |
14584 | reg = 0; | |
14585 | while (bit_count (mask) * 4 > amount) | |
14586 | { | |
14587 | while ((mask & (1 << reg)) == 0) | |
14588 | reg++; | |
14589 | mask &= ~(1 << reg); | |
14590 | } | |
14591 | if (bit_count (mask) * 4 == amount) { | |
14592 | amount = 0; | |
14593 | saved_regs_mask |= mask; | |
14594 | } | |
14595 | } | |
ec6237e4 PB |
14596 | } |
14597 | ||
14598 | if (amount) | |
14599 | { | |
14600 | operands[1] = operands[0]; | |
14601 | operands[2] = GEN_INT (amount); | |
14602 | output_add_immediate (operands); | |
14603 | } | |
14604 | if (frame_pointer_needed) | |
14605 | asm_fprintf (f, "\tmov\t%r, %r\n", | |
14606 | SP_REGNUM, HARD_FRAME_POINTER_REGNUM); | |
d2288d8d TG |
14607 | } |
14608 | ||
d79f3032 | 14609 | if (TARGET_FPA_EMU2) |
b111229a | 14610 | { |
9b66ebb1 | 14611 | for (reg = FIRST_FPA_REGNUM; reg <= LAST_FPA_REGNUM; reg++) |
6fb5fa3c | 14612 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
dd18ae56 NC |
14613 | asm_fprintf (f, "\tldfe\t%r, [%r], #12\n", |
14614 | reg, SP_REGNUM); | |
b111229a RE |
14615 | } |
14616 | else | |
14617 | { | |
9b66ebb1 | 14618 | start_reg = FIRST_FPA_REGNUM; |
b111229a | 14619 | |
9b66ebb1 | 14620 | for (reg = FIRST_FPA_REGNUM; reg <= LAST_FPA_REGNUM; reg++) |
b111229a | 14621 | { |
6fb5fa3c | 14622 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
b111229a RE |
14623 | { |
14624 | if (reg - start_reg == 3) | |
14625 | { | |
dd18ae56 NC |
14626 | asm_fprintf (f, "\tlfmfd\t%r, 4, [%r]!\n", |
14627 | start_reg, SP_REGNUM); | |
b111229a RE |
14628 | start_reg = reg + 1; |
14629 | } | |
14630 | } | |
14631 | else | |
14632 | { | |
14633 | if (reg != start_reg) | |
dd18ae56 NC |
14634 | asm_fprintf (f, "\tlfmfd\t%r, %d, [%r]!\n", |
14635 | start_reg, reg - start_reg, | |
14636 | SP_REGNUM); | |
f676971a | 14637 | |
b111229a RE |
14638 | start_reg = reg + 1; |
14639 | } | |
14640 | } | |
14641 | ||
14642 | /* Just in case the last register checked also needs unstacking. */ | |
14643 | if (reg != start_reg) | |
dd18ae56 NC |
14644 | asm_fprintf (f, "\tlfmfd\t%r, %d, [%r]!\n", |
14645 | start_reg, reg - start_reg, SP_REGNUM); | |
b111229a RE |
14646 | } |
14647 | ||
9b66ebb1 PB |
14648 | if (TARGET_HARD_FLOAT && TARGET_VFP) |
14649 | { | |
f8b68ed3 RE |
14650 | int end_reg = LAST_VFP_REGNUM + 1; |
14651 | ||
14652 | /* Scan the registers in reverse order. We need to match | |
14653 | any groupings made in the prologue and generate matching | |
14654 | pop operations. */ | |
14655 | for (reg = LAST_VFP_REGNUM - 1; reg >= FIRST_VFP_REGNUM; reg -= 2) | |
9b66ebb1 | 14656 | { |
6fb5fa3c | 14657 | if ((!df_regs_ever_live_p (reg) || call_used_regs[reg]) |
f8b68ed3 RE |
14658 | && (!df_regs_ever_live_p (reg + 1) |
14659 | || call_used_regs[reg + 1])) | |
9b66ebb1 | 14660 | { |
f8b68ed3 | 14661 | if (end_reg > reg + 2) |
8edfc4cc | 14662 | vfp_output_fldmd (f, SP_REGNUM, |
f8b68ed3 RE |
14663 | (reg + 2 - FIRST_VFP_REGNUM) / 2, |
14664 | (end_reg - (reg + 2)) / 2); | |
14665 | end_reg = reg; | |
9b66ebb1 PB |
14666 | } |
14667 | } | |
f8b68ed3 RE |
14668 | if (end_reg > reg + 2) |
14669 | vfp_output_fldmd (f, SP_REGNUM, 0, | |
14670 | (end_reg - (reg + 2)) / 2); | |
9b66ebb1 | 14671 | } |
f8b68ed3 | 14672 | |
5a9335ef NC |
14673 | if (TARGET_IWMMXT) |
14674 | for (reg = FIRST_IWMMXT_REGNUM; reg <= LAST_IWMMXT_REGNUM; reg++) | |
6fb5fa3c | 14675 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
01d4c813 | 14676 | asm_fprintf (f, "\twldrd\t%r, [%r], #8\n", reg, SP_REGNUM); |
5a9335ef | 14677 | |
6d3d9133 | 14678 | /* If we can, restore the LR into the PC. */ |
a15908a4 PB |
14679 | if (ARM_FUNC_TYPE (func_type) != ARM_FT_INTERWORKED |
14680 | && (TARGET_ARM || ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL) | |
5b3e6663 | 14681 | && !IS_STACKALIGN (func_type) |
6d3d9133 | 14682 | && really_return |
38173d38 | 14683 | && crtl->args.pretend_args_size == 0 |
c9ca9b88 | 14684 | && saved_regs_mask & (1 << LR_REGNUM) |
e3b5732b | 14685 | && !crtl->calls_eh_return) |
cce8749e | 14686 | { |
6f7ebcbb NC |
14687 | saved_regs_mask &= ~ (1 << LR_REGNUM); |
14688 | saved_regs_mask |= (1 << PC_REGNUM); | |
a15908a4 | 14689 | rfe = IS_INTERRUPT (func_type); |
6d3d9133 | 14690 | } |
a15908a4 PB |
14691 | else |
14692 | rfe = 0; | |
d5b7b3ae | 14693 | |
6d3d9133 | 14694 | /* Load the registers off the stack. If we only have one register |
5b3e6663 PB |
14695 | to load use the LDR instruction - it is faster. For Thumb-2 |
14696 | always use pop and the assembler will pick the best instruction.*/ | |
a15908a4 PB |
14697 | if (TARGET_ARM && saved_regs_mask == (1 << LR_REGNUM) |
14698 | && !IS_INTERRUPT(func_type)) | |
6d3d9133 | 14699 | { |
c9ca9b88 | 14700 | asm_fprintf (f, "\tldr\t%r, [%r], #4\n", LR_REGNUM, SP_REGNUM); |
cce8749e | 14701 | } |
6f7ebcbb | 14702 | else if (saved_regs_mask) |
f1acdf8b NC |
14703 | { |
14704 | if (saved_regs_mask & (1 << SP_REGNUM)) | |
14705 | /* Note - write back to the stack register is not enabled | |
112cdef5 | 14706 | (i.e. "ldmfd sp!..."). We know that the stack pointer is |
f1acdf8b NC |
14707 | in the list of registers and if we add writeback the |
14708 | instruction becomes UNPREDICTABLE. */ | |
a15908a4 PB |
14709 | print_multi_reg (f, "ldmfd\t%r, ", SP_REGNUM, saved_regs_mask, |
14710 | rfe); | |
5b3e6663 | 14711 | else if (TARGET_ARM) |
a15908a4 PB |
14712 | print_multi_reg (f, "ldmfd\t%r!, ", SP_REGNUM, saved_regs_mask, |
14713 | rfe); | |
f1acdf8b | 14714 | else |
a15908a4 | 14715 | print_multi_reg (f, "pop\t", SP_REGNUM, saved_regs_mask, 0); |
f1acdf8b | 14716 | } |
6d3d9133 | 14717 | |
38173d38 | 14718 | if (crtl->args.pretend_args_size) |
cce8749e | 14719 | { |
6d3d9133 NC |
14720 | /* Unwind the pre-pushed regs. */ |
14721 | operands[0] = operands[1] = stack_pointer_rtx; | |
38173d38 | 14722 | operands[2] = GEN_INT (crtl->args.pretend_args_size); |
6d3d9133 NC |
14723 | output_add_immediate (operands); |
14724 | } | |
14725 | } | |
32de079a | 14726 | |
2966b00e | 14727 | /* We may have already restored PC directly from the stack. */ |
0cc3dda8 | 14728 | if (!really_return || saved_regs_mask & (1 << PC_REGNUM)) |
6d3d9133 | 14729 | return ""; |
d5b7b3ae | 14730 | |
c9ca9b88 | 14731 | /* Stack adjustment for exception handler. */ |
e3b5732b | 14732 | if (crtl->calls_eh_return) |
f676971a | 14733 | asm_fprintf (f, "\tadd\t%r, %r, %r\n", SP_REGNUM, SP_REGNUM, |
c9ca9b88 PB |
14734 | ARM_EH_STACKADJ_REGNUM); |
14735 | ||
6d3d9133 NC |
14736 | /* Generate the return instruction. */ |
14737 | switch ((int) ARM_FUNC_TYPE (func_type)) | |
14738 | { | |
6d3d9133 NC |
14739 | case ARM_FT_ISR: |
14740 | case ARM_FT_FIQ: | |
14741 | asm_fprintf (f, "\tsubs\t%r, %r, #4\n", PC_REGNUM, LR_REGNUM); | |
14742 | break; | |
14743 | ||
14744 | case ARM_FT_EXCEPTION: | |
14745 | asm_fprintf (f, "\tmovs\t%r, %r\n", PC_REGNUM, LR_REGNUM); | |
14746 | break; | |
14747 | ||
14748 | case ARM_FT_INTERWORKED: | |
14749 | asm_fprintf (f, "\tbx\t%r\n", LR_REGNUM); | |
14750 | break; | |
14751 | ||
14752 | default: | |
5b3e6663 PB |
14753 | if (IS_STACKALIGN (func_type)) |
14754 | { | |
14755 | /* See comment in arm_expand_prologue. */ | |
14756 | asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, 0); | |
14757 | } | |
68d560d4 RE |
14758 | if (arm_arch5 || arm_arch4t) |
14759 | asm_fprintf (f, "\tbx\t%r\n", LR_REGNUM); | |
14760 | else | |
14761 | asm_fprintf (f, "\tmov\t%r, %r\n", PC_REGNUM, LR_REGNUM); | |
6d3d9133 | 14762 | break; |
cce8749e | 14763 | } |
f3bb6135 | 14764 | |
949d79eb RE |
14765 | return ""; |
14766 | } | |
14767 | ||
08c148a8 | 14768 | static void |
e32bac5b | 14769 | arm_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED, |
5848830f | 14770 | HOST_WIDE_INT frame_size ATTRIBUTE_UNUSED) |
949d79eb | 14771 | { |
5848830f PB |
14772 | arm_stack_offsets *offsets; |
14773 | ||
5b3e6663 | 14774 | if (TARGET_THUMB1) |
d5b7b3ae | 14775 | { |
b12a00f1 RE |
14776 | int regno; |
14777 | ||
14778 | /* Emit any call-via-reg trampolines that are needed for v4t support | |
14779 | of call_reg and call_value_reg type insns. */ | |
57ecec57 | 14780 | for (regno = 0; regno < LR_REGNUM; regno++) |
b12a00f1 RE |
14781 | { |
14782 | rtx label = cfun->machine->call_via[regno]; | |
14783 | ||
14784 | if (label != NULL) | |
14785 | { | |
d6b5193b | 14786 | switch_to_section (function_section (current_function_decl)); |
b12a00f1 RE |
14787 | targetm.asm_out.internal_label (asm_out_file, "L", |
14788 | CODE_LABEL_NUMBER (label)); | |
14789 | asm_fprintf (asm_out_file, "\tbx\t%r\n", regno); | |
14790 | } | |
14791 | } | |
14792 | ||
d5b7b3ae RE |
14793 | /* ??? Probably not safe to set this here, since it assumes that a |
14794 | function will be emitted as assembly immediately after we generate | |
14795 | RTL for it. This does not happen for inline functions. */ | |
934c2060 | 14796 | cfun->machine->return_used_this_function = 0; |
d5b7b3ae | 14797 | } |
5b3e6663 | 14798 | else /* TARGET_32BIT */ |
d5b7b3ae | 14799 | { |
0977774b | 14800 | /* We need to take into account any stack-frame rounding. */ |
5848830f | 14801 | offsets = arm_get_frame_offsets (); |
0977774b | 14802 | |
e6d29d15 | 14803 | gcc_assert (!use_return_insn (FALSE, NULL) |
934c2060 | 14804 | || (cfun->machine->return_used_this_function != 0) |
e6d29d15 NS |
14805 | || offsets->saved_regs == offsets->outgoing_args |
14806 | || frame_pointer_needed); | |
f3bb6135 | 14807 | |
d5b7b3ae | 14808 | /* Reset the ARM-specific per-function variables. */ |
d5b7b3ae RE |
14809 | after_arm_reorg = 0; |
14810 | } | |
f3bb6135 | 14811 | } |
e2c671ba | 14812 | |
2c849145 JM |
14813 | /* Generate and emit an insn that we will recognize as a push_multi. |
14814 | Unfortunately, since this insn does not reflect very well the actual | |
14815 | semantics of the operation, we need to annotate the insn for the benefit | |
14816 | of DWARF2 frame unwind information. */ | |
2c849145 | 14817 | static rtx |
b279b20a | 14818 | emit_multi_reg_push (unsigned long mask) |
e2c671ba RE |
14819 | { |
14820 | int num_regs = 0; | |
9b598fa0 | 14821 | int num_dwarf_regs; |
e2c671ba RE |
14822 | int i, j; |
14823 | rtx par; | |
2c849145 | 14824 | rtx dwarf; |
87e27392 | 14825 | int dwarf_par_index; |
2c849145 | 14826 | rtx tmp, reg; |
e2c671ba | 14827 | |
d5b7b3ae | 14828 | for (i = 0; i <= LAST_ARM_REGNUM; i++) |
e2c671ba | 14829 | if (mask & (1 << i)) |
5895f793 | 14830 | num_regs++; |
e2c671ba | 14831 | |
e6d29d15 | 14832 | gcc_assert (num_regs && num_regs <= 16); |
e2c671ba | 14833 | |
9b598fa0 RE |
14834 | /* We don't record the PC in the dwarf frame information. */ |
14835 | num_dwarf_regs = num_regs; | |
14836 | if (mask & (1 << PC_REGNUM)) | |
14837 | num_dwarf_regs--; | |
14838 | ||
87e27392 | 14839 | /* For the body of the insn we are going to generate an UNSPEC in |
05713b80 | 14840 | parallel with several USEs. This allows the insn to be recognized |
9abf5d7b RR |
14841 | by the push_multi pattern in the arm.md file. |
14842 | ||
14843 | The body of the insn looks something like this: | |
87e27392 | 14844 | |
f676971a | 14845 | (parallel [ |
9abf5d7b RR |
14846 | (set (mem:BLK (pre_modify:SI (reg:SI sp) |
14847 | (const_int:SI <num>))) | |
b15bca31 | 14848 | (unspec:BLK [(reg:SI r4)] UNSPEC_PUSH_MULT)) |
9abf5d7b RR |
14849 | (use (reg:SI XX)) |
14850 | (use (reg:SI YY)) | |
14851 | ... | |
87e27392 NC |
14852 | ]) |
14853 | ||
14854 | For the frame note however, we try to be more explicit and actually | |
14855 | show each register being stored into the stack frame, plus a (single) | |
14856 | decrement of the stack pointer. We do it this way in order to be | |
14857 | friendly to the stack unwinding code, which only wants to see a single | |
14858 | stack decrement per instruction. The RTL we generate for the note looks | |
14859 | something like this: | |
14860 | ||
f676971a | 14861 | (sequence [ |
87e27392 NC |
14862 | (set (reg:SI sp) (plus:SI (reg:SI sp) (const_int -20))) |
14863 | (set (mem:SI (reg:SI sp)) (reg:SI r4)) | |
9abf5d7b RR |
14864 | (set (mem:SI (plus:SI (reg:SI sp) (const_int 4))) (reg:SI XX)) |
14865 | (set (mem:SI (plus:SI (reg:SI sp) (const_int 8))) (reg:SI YY)) | |
14866 | ... | |
87e27392 NC |
14867 | ]) |
14868 | ||
9abf5d7b RR |
14869 | FIXME:: In an ideal world the PRE_MODIFY would not exist and |
14870 | instead we'd have a parallel expression detailing all | |
14871 | the stores to the various memory addresses so that debug | |
14872 | information is more up-to-date. Remember however while writing | |
14873 | this to take care of the constraints with the push instruction. | |
14874 | ||
14875 | Note also that this has to be taken care of for the VFP registers. | |
14876 | ||
14877 | For more see PR43399. */ | |
f676971a | 14878 | |
43cffd11 | 14879 | par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_regs)); |
9b598fa0 | 14880 | dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (num_dwarf_regs + 1)); |
87e27392 | 14881 | dwarf_par_index = 1; |
e2c671ba | 14882 | |
d5b7b3ae | 14883 | for (i = 0; i <= LAST_ARM_REGNUM; i++) |
e2c671ba RE |
14884 | { |
14885 | if (mask & (1 << i)) | |
14886 | { | |
2c849145 JM |
14887 | reg = gen_rtx_REG (SImode, i); |
14888 | ||
e2c671ba | 14889 | XVECEXP (par, 0, 0) |
43cffd11 | 14890 | = gen_rtx_SET (VOIDmode, |
9abf5d7b RR |
14891 | gen_frame_mem |
14892 | (BLKmode, | |
14893 | gen_rtx_PRE_MODIFY (Pmode, | |
14894 | stack_pointer_rtx, | |
14895 | plus_constant | |
14896 | (stack_pointer_rtx, | |
14897 | -4 * num_regs)) | |
14898 | ), | |
43cffd11 | 14899 | gen_rtx_UNSPEC (BLKmode, |
2c849145 | 14900 | gen_rtvec (1, reg), |
9b598fa0 | 14901 | UNSPEC_PUSH_MULT)); |
2c849145 | 14902 | |
9b598fa0 RE |
14903 | if (i != PC_REGNUM) |
14904 | { | |
14905 | tmp = gen_rtx_SET (VOIDmode, | |
31fa16b6 | 14906 | gen_frame_mem (SImode, stack_pointer_rtx), |
9b598fa0 RE |
14907 | reg); |
14908 | RTX_FRAME_RELATED_P (tmp) = 1; | |
14909 | XVECEXP (dwarf, 0, dwarf_par_index) = tmp; | |
14910 | dwarf_par_index++; | |
14911 | } | |
2c849145 | 14912 | |
e2c671ba RE |
14913 | break; |
14914 | } | |
14915 | } | |
14916 | ||
14917 | for (j = 1, i++; j < num_regs; i++) | |
14918 | { | |
14919 | if (mask & (1 << i)) | |
14920 | { | |
2c849145 JM |
14921 | reg = gen_rtx_REG (SImode, i); |
14922 | ||
14923 | XVECEXP (par, 0, j) = gen_rtx_USE (VOIDmode, reg); | |
14924 | ||
9b598fa0 RE |
14925 | if (i != PC_REGNUM) |
14926 | { | |
31fa16b6 RE |
14927 | tmp |
14928 | = gen_rtx_SET (VOIDmode, | |
9abf5d7b RR |
14929 | gen_frame_mem |
14930 | (SImode, | |
14931 | plus_constant (stack_pointer_rtx, | |
14932 | 4 * j)), | |
31fa16b6 | 14933 | reg); |
9b598fa0 RE |
14934 | RTX_FRAME_RELATED_P (tmp) = 1; |
14935 | XVECEXP (dwarf, 0, dwarf_par_index++) = tmp; | |
14936 | } | |
14937 | ||
e2c671ba RE |
14938 | j++; |
14939 | } | |
14940 | } | |
b111229a | 14941 | |
2c849145 | 14942 | par = emit_insn (par); |
f676971a | 14943 | |
d66437c5 | 14944 | tmp = gen_rtx_SET (VOIDmode, |
87e27392 | 14945 | stack_pointer_rtx, |
d66437c5 | 14946 | plus_constant (stack_pointer_rtx, -4 * num_regs)); |
87e27392 NC |
14947 | RTX_FRAME_RELATED_P (tmp) = 1; |
14948 | XVECEXP (dwarf, 0, 0) = tmp; | |
f676971a | 14949 | |
bbbbb16a ILT |
14950 | add_reg_note (par, REG_FRAME_RELATED_EXPR, dwarf); |
14951 | ||
2c849145 | 14952 | return par; |
b111229a RE |
14953 | } |
14954 | ||
4f5dfed0 | 14955 | /* Calculate the size of the return value that is passed in registers. */ |
466e4b7a | 14956 | static unsigned |
4f5dfed0 JC |
14957 | arm_size_return_regs (void) |
14958 | { | |
14959 | enum machine_mode mode; | |
14960 | ||
38173d38 JH |
14961 | if (crtl->return_rtx != 0) |
14962 | mode = GET_MODE (crtl->return_rtx); | |
4f5dfed0 JC |
14963 | else |
14964 | mode = DECL_MODE (DECL_RESULT (current_function_decl)); | |
14965 | ||
14966 | return GET_MODE_SIZE (mode); | |
14967 | } | |
14968 | ||
2c849145 | 14969 | static rtx |
e32bac5b | 14970 | emit_sfm (int base_reg, int count) |
b111229a RE |
14971 | { |
14972 | rtx par; | |
2c849145 JM |
14973 | rtx dwarf; |
14974 | rtx tmp, reg; | |
b111229a RE |
14975 | int i; |
14976 | ||
43cffd11 | 14977 | par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count)); |
8ee6eb4e | 14978 | dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (count + 1)); |
2c849145 JM |
14979 | |
14980 | reg = gen_rtx_REG (XFmode, base_reg++); | |
43cffd11 RE |
14981 | |
14982 | XVECEXP (par, 0, 0) | |
f676971a | 14983 | = gen_rtx_SET (VOIDmode, |
9abf5d7b RR |
14984 | gen_frame_mem |
14985 | (BLKmode, | |
14986 | gen_rtx_PRE_MODIFY (Pmode, | |
14987 | stack_pointer_rtx, | |
14988 | plus_constant | |
14989 | (stack_pointer_rtx, | |
14990 | -12 * count)) | |
14991 | ), | |
43cffd11 | 14992 | gen_rtx_UNSPEC (BLKmode, |
2c849145 | 14993 | gen_rtvec (1, reg), |
b15bca31 | 14994 | UNSPEC_PUSH_MULT)); |
f676971a | 14995 | tmp = gen_rtx_SET (VOIDmode, |
31fa16b6 | 14996 | gen_frame_mem (XFmode, stack_pointer_rtx), reg); |
2c849145 | 14997 | RTX_FRAME_RELATED_P (tmp) = 1; |
f676971a EC |
14998 | XVECEXP (dwarf, 0, 1) = tmp; |
14999 | ||
b111229a | 15000 | for (i = 1; i < count; i++) |
2c849145 JM |
15001 | { |
15002 | reg = gen_rtx_REG (XFmode, base_reg++); | |
15003 | XVECEXP (par, 0, i) = gen_rtx_USE (VOIDmode, reg); | |
15004 | ||
f676971a | 15005 | tmp = gen_rtx_SET (VOIDmode, |
31fa16b6 RE |
15006 | gen_frame_mem (XFmode, |
15007 | plus_constant (stack_pointer_rtx, | |
15008 | i * 12)), | |
2c849145 JM |
15009 | reg); |
15010 | RTX_FRAME_RELATED_P (tmp) = 1; | |
f676971a | 15011 | XVECEXP (dwarf, 0, i + 1) = tmp; |
2c849145 | 15012 | } |
b111229a | 15013 | |
8ee6eb4e PB |
15014 | tmp = gen_rtx_SET (VOIDmode, |
15015 | stack_pointer_rtx, | |
d66437c5 RE |
15016 | plus_constant (stack_pointer_rtx, -12 * count)); |
15017 | ||
8ee6eb4e PB |
15018 | RTX_FRAME_RELATED_P (tmp) = 1; |
15019 | XVECEXP (dwarf, 0, 0) = tmp; | |
15020 | ||
2c849145 | 15021 | par = emit_insn (par); |
bbbbb16a ILT |
15022 | add_reg_note (par, REG_FRAME_RELATED_EXPR, dwarf); |
15023 | ||
2c849145 | 15024 | return par; |
e2c671ba RE |
15025 | } |
15026 | ||
9b66ebb1 | 15027 | |
3c7ad43e PB |
15028 | /* Return true if the current function needs to save/restore LR. */ |
15029 | ||
15030 | static bool | |
15031 | thumb_force_lr_save (void) | |
15032 | { | |
15033 | return !cfun->machine->lr_save_eliminated | |
15034 | && (!leaf_function_p () | |
15035 | || thumb_far_jump_used_p () | |
6fb5fa3c | 15036 | || df_regs_ever_live_p (LR_REGNUM)); |
3c7ad43e PB |
15037 | } |
15038 | ||
15039 | ||
095bb276 NC |
15040 | /* Compute the distance from register FROM to register TO. |
15041 | These can be the arg pointer (26), the soft frame pointer (25), | |
15042 | the stack pointer (13) or the hard frame pointer (11). | |
c9ca9b88 | 15043 | In thumb mode r7 is used as the soft frame pointer, if needed. |
095bb276 NC |
15044 | Typical stack layout looks like this: |
15045 | ||
15046 | old stack pointer -> | | | |
15047 | ---- | |
15048 | | | \ | |
15049 | | | saved arguments for | |
15050 | | | vararg functions | |
15051 | | | / | |
15052 | -- | |
15053 | hard FP & arg pointer -> | | \ | |
15054 | | | stack | |
15055 | | | frame | |
15056 | | | / | |
15057 | -- | |
15058 | | | \ | |
15059 | | | call saved | |
15060 | | | registers | |
15061 | soft frame pointer -> | | / | |
15062 | -- | |
15063 | | | \ | |
15064 | | | local | |
15065 | | | variables | |
2591db65 | 15066 | locals base pointer -> | | / |
095bb276 NC |
15067 | -- |
15068 | | | \ | |
15069 | | | outgoing | |
15070 | | | arguments | |
15071 | current stack pointer -> | | / | |
15072 | -- | |
15073 | ||
43aa4e05 | 15074 | For a given function some or all of these stack components |
095bb276 NC |
15075 | may not be needed, giving rise to the possibility of |
15076 | eliminating some of the registers. | |
15077 | ||
825dda42 | 15078 | The values returned by this function must reflect the behavior |
095bb276 NC |
15079 | of arm_expand_prologue() and arm_compute_save_reg_mask(). |
15080 | ||
15081 | The sign of the number returned reflects the direction of stack | |
15082 | growth, so the values are positive for all eliminations except | |
5848830f PB |
15083 | from the soft frame pointer to the hard frame pointer. |
15084 | ||
15085 | SFP may point just inside the local variables block to ensure correct | |
15086 | alignment. */ | |
15087 | ||
15088 | ||
15089 | /* Calculate stack offsets. These are used to calculate register elimination | |
954954d1 PB |
15090 | offsets and in prologue/epilogue code. Also calculates which registers |
15091 | should be saved. */ | |
5848830f PB |
15092 | |
15093 | static arm_stack_offsets * | |
15094 | arm_get_frame_offsets (void) | |
095bb276 | 15095 | { |
5848830f | 15096 | struct arm_stack_offsets *offsets; |
095bb276 | 15097 | unsigned long func_type; |
5848830f | 15098 | int leaf; |
5848830f | 15099 | int saved; |
954954d1 | 15100 | int core_saved; |
5848830f | 15101 | HOST_WIDE_INT frame_size; |
954954d1 | 15102 | int i; |
5848830f PB |
15103 | |
15104 | offsets = &cfun->machine->stack_offsets; | |
f676971a | 15105 | |
5848830f PB |
15106 | /* We need to know if we are a leaf function. Unfortunately, it |
15107 | is possible to be called after start_sequence has been called, | |
15108 | which causes get_insns to return the insns for the sequence, | |
15109 | not the function, which will cause leaf_function_p to return | |
15110 | the incorrect result. | |
095bb276 | 15111 | |
5848830f PB |
15112 | to know about leaf functions once reload has completed, and the |
15113 | frame size cannot be changed after that time, so we can safely | |
15114 | use the cached value. */ | |
15115 | ||
15116 | if (reload_completed) | |
15117 | return offsets; | |
15118 | ||
666c27b9 KH |
15119 | /* Initially this is the size of the local variables. It will translated |
15120 | into an offset once we have determined the size of preceding data. */ | |
5848830f PB |
15121 | frame_size = ROUND_UP_WORD (get_frame_size ()); |
15122 | ||
15123 | leaf = leaf_function_p (); | |
15124 | ||
15125 | /* Space for variadic functions. */ | |
38173d38 | 15126 | offsets->saved_args = crtl->args.pretend_args_size; |
5848830f | 15127 | |
5b3e6663 | 15128 | /* In Thumb mode this is incorrect, but never used. */ |
35596784 AJ |
15129 | offsets->frame = offsets->saved_args + (frame_pointer_needed ? 4 : 0) + |
15130 | arm_compute_static_chain_stack_bytes(); | |
5848830f | 15131 | |
5b3e6663 | 15132 | if (TARGET_32BIT) |
095bb276 | 15133 | { |
5848830f | 15134 | unsigned int regno; |
ef7112de | 15135 | |
954954d1 PB |
15136 | offsets->saved_regs_mask = arm_compute_save_reg_mask (); |
15137 | core_saved = bit_count (offsets->saved_regs_mask) * 4; | |
15138 | saved = core_saved; | |
5a9335ef | 15139 | |
5848830f PB |
15140 | /* We know that SP will be doubleword aligned on entry, and we must |
15141 | preserve that condition at any subroutine call. We also require the | |
15142 | soft frame pointer to be doubleword aligned. */ | |
15143 | ||
15144 | if (TARGET_REALLY_IWMMXT) | |
9b66ebb1 | 15145 | { |
5848830f PB |
15146 | /* Check for the call-saved iWMMXt registers. */ |
15147 | for (regno = FIRST_IWMMXT_REGNUM; | |
15148 | regno <= LAST_IWMMXT_REGNUM; | |
15149 | regno++) | |
6fb5fa3c | 15150 | if (df_regs_ever_live_p (regno) && ! call_used_regs[regno]) |
5848830f PB |
15151 | saved += 8; |
15152 | } | |
15153 | ||
15154 | func_type = arm_current_func_type (); | |
15155 | if (! IS_VOLATILE (func_type)) | |
15156 | { | |
15157 | /* Space for saved FPA registers. */ | |
15158 | for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++) | |
6fb5fa3c | 15159 | if (df_regs_ever_live_p (regno) && ! call_used_regs[regno]) |
5848830f PB |
15160 | saved += 12; |
15161 | ||
15162 | /* Space for saved VFP registers. */ | |
15163 | if (TARGET_HARD_FLOAT && TARGET_VFP) | |
9728c9d1 | 15164 | saved += arm_get_vfp_saved_size (); |
9b66ebb1 | 15165 | } |
5848830f | 15166 | } |
5b3e6663 | 15167 | else /* TARGET_THUMB1 */ |
5848830f | 15168 | { |
954954d1 PB |
15169 | offsets->saved_regs_mask = thumb1_compute_save_reg_mask (); |
15170 | core_saved = bit_count (offsets->saved_regs_mask) * 4; | |
15171 | saved = core_saved; | |
5848830f | 15172 | if (TARGET_BACKTRACE) |
57934c39 | 15173 | saved += 16; |
5848830f | 15174 | } |
9b66ebb1 | 15175 | |
5848830f | 15176 | /* Saved registers include the stack frame. */ |
35596784 AJ |
15177 | offsets->saved_regs = offsets->saved_args + saved + |
15178 | arm_compute_static_chain_stack_bytes(); | |
a2503645 | 15179 | offsets->soft_frame = offsets->saved_regs + CALLER_INTERWORKING_SLOT_SIZE; |
5848830f PB |
15180 | /* A leaf function does not need any stack alignment if it has nothing |
15181 | on the stack. */ | |
15182 | if (leaf && frame_size == 0) | |
15183 | { | |
15184 | offsets->outgoing_args = offsets->soft_frame; | |
a3a531ec | 15185 | offsets->locals_base = offsets->soft_frame; |
5848830f PB |
15186 | return offsets; |
15187 | } | |
15188 | ||
15189 | /* Ensure SFP has the correct alignment. */ | |
15190 | if (ARM_DOUBLEWORD_ALIGN | |
15191 | && (offsets->soft_frame & 7)) | |
954954d1 PB |
15192 | { |
15193 | offsets->soft_frame += 4; | |
15194 | /* Try to align stack by pushing an extra reg. Don't bother doing this | |
15195 | when there is a stack frame as the alignment will be rolled into | |
15196 | the normal stack adjustment. */ | |
38173d38 | 15197 | if (frame_size + crtl->outgoing_args_size == 0) |
954954d1 PB |
15198 | { |
15199 | int reg = -1; | |
15200 | ||
55b2829b RE |
15201 | /* If it is safe to use r3, then do so. This sometimes |
15202 | generates better code on Thumb-2 by avoiding the need to | |
15203 | use 32-bit push/pop instructions. */ | |
15204 | if (!crtl->tail_call_emit | |
fb2f8cf8 JZ |
15205 | && arm_size_return_regs () <= 12 |
15206 | && (offsets->saved_regs_mask & (1 << 3)) == 0) | |
954954d1 | 15207 | { |
954954d1 PB |
15208 | reg = 3; |
15209 | } | |
55b2829b RE |
15210 | else |
15211 | for (i = 4; i <= (TARGET_THUMB1 ? LAST_LO_REGNUM : 11); i++) | |
15212 | { | |
15213 | if ((offsets->saved_regs_mask & (1 << i)) == 0) | |
15214 | { | |
15215 | reg = i; | |
15216 | break; | |
15217 | } | |
15218 | } | |
954954d1 PB |
15219 | |
15220 | if (reg != -1) | |
15221 | { | |
15222 | offsets->saved_regs += 4; | |
15223 | offsets->saved_regs_mask |= (1 << reg); | |
15224 | } | |
15225 | } | |
15226 | } | |
5848830f | 15227 | |
2591db65 RE |
15228 | offsets->locals_base = offsets->soft_frame + frame_size; |
15229 | offsets->outgoing_args = (offsets->locals_base | |
38173d38 | 15230 | + crtl->outgoing_args_size); |
5848830f PB |
15231 | |
15232 | if (ARM_DOUBLEWORD_ALIGN) | |
15233 | { | |
15234 | /* Ensure SP remains doubleword aligned. */ | |
15235 | if (offsets->outgoing_args & 7) | |
15236 | offsets->outgoing_args += 4; | |
e6d29d15 | 15237 | gcc_assert (!(offsets->outgoing_args & 7)); |
095bb276 NC |
15238 | } |
15239 | ||
5848830f PB |
15240 | return offsets; |
15241 | } | |
15242 | ||
15243 | ||
666c27b9 | 15244 | /* Calculate the relative offsets for the different stack pointers. Positive |
5848830f PB |
15245 | offsets are in the direction of stack growth. */ |
15246 | ||
b3f8d95d | 15247 | HOST_WIDE_INT |
5848830f PB |
15248 | arm_compute_initial_elimination_offset (unsigned int from, unsigned int to) |
15249 | { | |
15250 | arm_stack_offsets *offsets; | |
15251 | ||
15252 | offsets = arm_get_frame_offsets (); | |
095bb276 | 15253 | |
095bb276 NC |
15254 | /* OK, now we have enough information to compute the distances. |
15255 | There must be an entry in these switch tables for each pair | |
15256 | of registers in ELIMINABLE_REGS, even if some of the entries | |
15257 | seem to be redundant or useless. */ | |
15258 | switch (from) | |
15259 | { | |
15260 | case ARG_POINTER_REGNUM: | |
15261 | switch (to) | |
15262 | { | |
15263 | case THUMB_HARD_FRAME_POINTER_REGNUM: | |
15264 | return 0; | |
15265 | ||
15266 | case FRAME_POINTER_REGNUM: | |
15267 | /* This is the reverse of the soft frame pointer | |
15268 | to hard frame pointer elimination below. */ | |
5848830f | 15269 | return offsets->soft_frame - offsets->saved_args; |
095bb276 NC |
15270 | |
15271 | case ARM_HARD_FRAME_POINTER_REGNUM: | |
35596784 AJ |
15272 | /* This is only non-zero in the case where the static chain register |
15273 | is stored above the frame. */ | |
15274 | return offsets->frame - offsets->saved_args - 4; | |
095bb276 NC |
15275 | |
15276 | case STACK_POINTER_REGNUM: | |
15277 | /* If nothing has been pushed on the stack at all | |
15278 | then this will return -4. This *is* correct! */ | |
5848830f | 15279 | return offsets->outgoing_args - (offsets->saved_args + 4); |
095bb276 NC |
15280 | |
15281 | default: | |
e6d29d15 | 15282 | gcc_unreachable (); |
095bb276 | 15283 | } |
e6d29d15 | 15284 | gcc_unreachable (); |
095bb276 NC |
15285 | |
15286 | case FRAME_POINTER_REGNUM: | |
15287 | switch (to) | |
15288 | { | |
15289 | case THUMB_HARD_FRAME_POINTER_REGNUM: | |
15290 | return 0; | |
15291 | ||
15292 | case ARM_HARD_FRAME_POINTER_REGNUM: | |
15293 | /* The hard frame pointer points to the top entry in the | |
15294 | stack frame. The soft frame pointer to the bottom entry | |
15295 | in the stack frame. If there is no stack frame at all, | |
15296 | then they are identical. */ | |
5848830f PB |
15297 | |
15298 | return offsets->frame - offsets->soft_frame; | |
095bb276 NC |
15299 | |
15300 | case STACK_POINTER_REGNUM: | |
5848830f | 15301 | return offsets->outgoing_args - offsets->soft_frame; |
095bb276 NC |
15302 | |
15303 | default: | |
e6d29d15 | 15304 | gcc_unreachable (); |
095bb276 | 15305 | } |
e6d29d15 | 15306 | gcc_unreachable (); |
095bb276 NC |
15307 | |
15308 | default: | |
15309 | /* You cannot eliminate from the stack pointer. | |
15310 | In theory you could eliminate from the hard frame | |
15311 | pointer to the stack pointer, but this will never | |
15312 | happen, since if a stack frame is not needed the | |
15313 | hard frame pointer will never be used. */ | |
e6d29d15 | 15314 | gcc_unreachable (); |
095bb276 NC |
15315 | } |
15316 | } | |
15317 | ||
7b5cbb57 AS |
15318 | /* Given FROM and TO register numbers, say whether this elimination is |
15319 | allowed. Frame pointer elimination is automatically handled. | |
15320 | ||
15321 | All eliminations are permissible. Note that ARG_POINTER_REGNUM and | |
15322 | HARD_FRAME_POINTER_REGNUM are in fact the same thing. If we need a frame | |
15323 | pointer, we must eliminate FRAME_POINTER_REGNUM into | |
15324 | HARD_FRAME_POINTER_REGNUM and not into STACK_POINTER_REGNUM or | |
15325 | ARG_POINTER_REGNUM. */ | |
15326 | ||
15327 | bool | |
15328 | arm_can_eliminate (const int from, const int to) | |
15329 | { | |
15330 | return ((to == FRAME_POINTER_REGNUM && from == ARG_POINTER_REGNUM) ? false : | |
15331 | (to == STACK_POINTER_REGNUM && frame_pointer_needed) ? false : | |
15332 | (to == ARM_HARD_FRAME_POINTER_REGNUM && TARGET_THUMB) ? false : | |
15333 | (to == THUMB_HARD_FRAME_POINTER_REGNUM && TARGET_ARM) ? false : | |
15334 | true); | |
15335 | } | |
0977774b | 15336 | |
7a085dce | 15337 | /* Emit RTL to save coprocessor registers on function entry. Returns the |
5b3e6663 PB |
15338 | number of bytes pushed. */ |
15339 | ||
15340 | static int | |
15341 | arm_save_coproc_regs(void) | |
15342 | { | |
15343 | int saved_size = 0; | |
15344 | unsigned reg; | |
15345 | unsigned start_reg; | |
15346 | rtx insn; | |
15347 | ||
15348 | for (reg = LAST_IWMMXT_REGNUM; reg >= FIRST_IWMMXT_REGNUM; reg--) | |
6fb5fa3c | 15349 | if (df_regs_ever_live_p (reg) && ! call_used_regs[reg]) |
5b3e6663 | 15350 | { |
d8d55ac0 | 15351 | insn = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx); |
5b3e6663 PB |
15352 | insn = gen_rtx_MEM (V2SImode, insn); |
15353 | insn = emit_set_insn (insn, gen_rtx_REG (V2SImode, reg)); | |
15354 | RTX_FRAME_RELATED_P (insn) = 1; | |
15355 | saved_size += 8; | |
15356 | } | |
15357 | ||
15358 | /* Save any floating point call-saved registers used by this | |
15359 | function. */ | |
d79f3032 | 15360 | if (TARGET_FPA_EMU2) |
5b3e6663 PB |
15361 | { |
15362 | for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--) | |
6fb5fa3c | 15363 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
5b3e6663 | 15364 | { |
d8d55ac0 | 15365 | insn = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx); |
5b3e6663 PB |
15366 | insn = gen_rtx_MEM (XFmode, insn); |
15367 | insn = emit_set_insn (insn, gen_rtx_REG (XFmode, reg)); | |
15368 | RTX_FRAME_RELATED_P (insn) = 1; | |
15369 | saved_size += 12; | |
15370 | } | |
15371 | } | |
15372 | else | |
15373 | { | |
15374 | start_reg = LAST_FPA_REGNUM; | |
15375 | ||
15376 | for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--) | |
15377 | { | |
6fb5fa3c | 15378 | if (df_regs_ever_live_p (reg) && !call_used_regs[reg]) |
5b3e6663 PB |
15379 | { |
15380 | if (start_reg - reg == 3) | |
15381 | { | |
15382 | insn = emit_sfm (reg, 4); | |
15383 | RTX_FRAME_RELATED_P (insn) = 1; | |
15384 | saved_size += 48; | |
15385 | start_reg = reg - 1; | |
15386 | } | |
15387 | } | |
15388 | else | |
15389 | { | |
15390 | if (start_reg != reg) | |
15391 | { | |
15392 | insn = emit_sfm (reg + 1, start_reg - reg); | |
15393 | RTX_FRAME_RELATED_P (insn) = 1; | |
15394 | saved_size += (start_reg - reg) * 12; | |
15395 | } | |
15396 | start_reg = reg - 1; | |
15397 | } | |
15398 | } | |
15399 | ||
15400 | if (start_reg != reg) | |
15401 | { | |
15402 | insn = emit_sfm (reg + 1, start_reg - reg); | |
15403 | saved_size += (start_reg - reg) * 12; | |
15404 | RTX_FRAME_RELATED_P (insn) = 1; | |
15405 | } | |
15406 | } | |
15407 | if (TARGET_HARD_FLOAT && TARGET_VFP) | |
15408 | { | |
15409 | start_reg = FIRST_VFP_REGNUM; | |
15410 | ||
15411 | for (reg = FIRST_VFP_REGNUM; reg < LAST_VFP_REGNUM; reg += 2) | |
15412 | { | |
6fb5fa3c DB |
15413 | if ((!df_regs_ever_live_p (reg) || call_used_regs[reg]) |
15414 | && (!df_regs_ever_live_p (reg + 1) || call_used_regs[reg + 1])) | |
5b3e6663 PB |
15415 | { |
15416 | if (start_reg != reg) | |
15417 | saved_size += vfp_emit_fstmd (start_reg, | |
15418 | (reg - start_reg) / 2); | |
15419 | start_reg = reg + 2; | |
15420 | } | |
15421 | } | |
15422 | if (start_reg != reg) | |
15423 | saved_size += vfp_emit_fstmd (start_reg, | |
15424 | (reg - start_reg) / 2); | |
15425 | } | |
15426 | return saved_size; | |
15427 | } | |
15428 | ||
15429 | ||
15430 | /* Set the Thumb frame pointer from the stack pointer. */ | |
15431 | ||
15432 | static void | |
15433 | thumb_set_frame_pointer (arm_stack_offsets *offsets) | |
15434 | { | |
15435 | HOST_WIDE_INT amount; | |
15436 | rtx insn, dwarf; | |
15437 | ||
15438 | amount = offsets->outgoing_args - offsets->locals_base; | |
15439 | if (amount < 1024) | |
15440 | insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, | |
15441 | stack_pointer_rtx, GEN_INT (amount))); | |
15442 | else | |
15443 | { | |
15444 | emit_insn (gen_movsi (hard_frame_pointer_rtx, GEN_INT (amount))); | |
f5c630c3 PB |
15445 | /* Thumb-2 RTL patterns expect sp as the first input. Thumb-1 |
15446 | expects the first two operands to be the same. */ | |
15447 | if (TARGET_THUMB2) | |
15448 | { | |
15449 | insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, | |
15450 | stack_pointer_rtx, | |
15451 | hard_frame_pointer_rtx)); | |
15452 | } | |
15453 | else | |
15454 | { | |
15455 | insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, | |
15456 | hard_frame_pointer_rtx, | |
15457 | stack_pointer_rtx)); | |
15458 | } | |
5b3e6663 PB |
15459 | dwarf = gen_rtx_SET (VOIDmode, hard_frame_pointer_rtx, |
15460 | plus_constant (stack_pointer_rtx, amount)); | |
15461 | RTX_FRAME_RELATED_P (dwarf) = 1; | |
bbbbb16a | 15462 | add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
5b3e6663 PB |
15463 | } |
15464 | ||
15465 | RTX_FRAME_RELATED_P (insn) = 1; | |
15466 | } | |
15467 | ||
15468 | /* Generate the prologue instructions for entry into an ARM or Thumb-2 | |
15469 | function. */ | |
e2c671ba | 15470 | void |
e32bac5b | 15471 | arm_expand_prologue (void) |
e2c671ba | 15472 | { |
6d3d9133 | 15473 | rtx amount; |
2c849145 | 15474 | rtx insn; |
68dfd979 | 15475 | rtx ip_rtx; |
6d3d9133 NC |
15476 | unsigned long live_regs_mask; |
15477 | unsigned long func_type; | |
68dfd979 | 15478 | int fp_offset = 0; |
095bb276 | 15479 | int saved_pretend_args = 0; |
5848830f | 15480 | int saved_regs = 0; |
b9705a21 | 15481 | unsigned HOST_WIDE_INT args_to_push; |
5848830f | 15482 | arm_stack_offsets *offsets; |
d3236b4d | 15483 | |
6d3d9133 | 15484 | func_type = arm_current_func_type (); |
e2c671ba | 15485 | |
31fdb4d5 | 15486 | /* Naked functions don't have prologues. */ |
6d3d9133 | 15487 | if (IS_NAKED (func_type)) |
31fdb4d5 DE |
15488 | return; |
15489 | ||
095bb276 | 15490 | /* Make a copy of c_f_p_a_s as we may need to modify it locally. */ |
38173d38 | 15491 | args_to_push = crtl->args.pretend_args_size; |
f676971a | 15492 | |
6d3d9133 | 15493 | /* Compute which register we will have to save onto the stack. */ |
954954d1 PB |
15494 | offsets = arm_get_frame_offsets (); |
15495 | live_regs_mask = offsets->saved_regs_mask; | |
e2c671ba | 15496 | |
68dfd979 | 15497 | ip_rtx = gen_rtx_REG (SImode, IP_REGNUM); |
d3236b4d | 15498 | |
5b3e6663 PB |
15499 | if (IS_STACKALIGN (func_type)) |
15500 | { | |
15501 | rtx dwarf; | |
15502 | rtx r0; | |
15503 | rtx r1; | |
15504 | /* Handle a word-aligned stack pointer. We generate the following: | |
15505 | ||
15506 | mov r0, sp | |
15507 | bic r1, r0, #7 | |
15508 | mov sp, r1 | |
15509 | <save and restore r0 in normal prologue/epilogue> | |
15510 | mov sp, r0 | |
15511 | bx lr | |
15512 | ||
15513 | The unwinder doesn't need to know about the stack realignment. | |
15514 | Just tell it we saved SP in r0. */ | |
15515 | gcc_assert (TARGET_THUMB2 && !arm_arch_notm && args_to_push == 0); | |
15516 | ||
15517 | r0 = gen_rtx_REG (SImode, 0); | |
15518 | r1 = gen_rtx_REG (SImode, 1); | |
44bfa35b NF |
15519 | /* Use a real rtvec rather than NULL_RTVEC so the rest of the |
15520 | compiler won't choke. */ | |
15521 | dwarf = gen_rtx_UNSPEC (SImode, rtvec_alloc (0), UNSPEC_STACK_ALIGN); | |
5b3e6663 PB |
15522 | dwarf = gen_rtx_SET (VOIDmode, r0, dwarf); |
15523 | insn = gen_movsi (r0, stack_pointer_rtx); | |
15524 | RTX_FRAME_RELATED_P (insn) = 1; | |
bbbbb16a | 15525 | add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
5b3e6663 PB |
15526 | emit_insn (insn); |
15527 | emit_insn (gen_andsi3 (r1, r0, GEN_INT (~(HOST_WIDE_INT)7))); | |
15528 | emit_insn (gen_movsi (stack_pointer_rtx, r1)); | |
15529 | } | |
15530 | ||
ec6237e4 PB |
15531 | /* For APCS frames, if IP register is clobbered |
15532 | when creating frame, save that register in a special | |
15533 | way. */ | |
15534 | if (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM) | |
e2c671ba | 15535 | { |
7b8b8ade NC |
15536 | if (IS_INTERRUPT (func_type)) |
15537 | { | |
15538 | /* Interrupt functions must not corrupt any registers. | |
15539 | Creating a frame pointer however, corrupts the IP | |
15540 | register, so we must push it first. */ | |
15541 | insn = emit_multi_reg_push (1 << IP_REGNUM); | |
121308d4 NC |
15542 | |
15543 | /* Do not set RTX_FRAME_RELATED_P on this insn. | |
15544 | The dwarf stack unwinding code only wants to see one | |
15545 | stack decrement per function, and this is not it. If | |
15546 | this instruction is labeled as being part of the frame | |
15547 | creation sequence then dwarf2out_frame_debug_expr will | |
e6d29d15 | 15548 | die when it encounters the assignment of IP to FP |
121308d4 NC |
15549 | later on, since the use of SP here establishes SP as |
15550 | the CFA register and not IP. | |
15551 | ||
15552 | Anyway this instruction is not really part of the stack | |
15553 | frame creation although it is part of the prologue. */ | |
7b8b8ade NC |
15554 | } |
15555 | else if (IS_NESTED (func_type)) | |
68dfd979 NC |
15556 | { |
15557 | /* The Static chain register is the same as the IP register | |
15558 | used as a scratch register during stack frame creation. | |
15559 | To get around this need to find somewhere to store IP | |
15560 | whilst the frame is being created. We try the following | |
15561 | places in order: | |
f676971a | 15562 | |
6d3d9133 | 15563 | 1. The last argument register. |
68dfd979 NC |
15564 | 2. A slot on the stack above the frame. (This only |
15565 | works if the function is not a varargs function). | |
095bb276 NC |
15566 | 3. Register r3, after pushing the argument registers |
15567 | onto the stack. | |
6d3d9133 | 15568 | |
34ce3d7b JM |
15569 | Note - we only need to tell the dwarf2 backend about the SP |
15570 | adjustment in the second variant; the static chain register | |
15571 | doesn't need to be unwound, as it doesn't contain a value | |
15572 | inherited from the caller. */ | |
d3236b4d | 15573 | |
6fb5fa3c | 15574 | if (df_regs_ever_live_p (3) == false) |
d66437c5 | 15575 | insn = emit_set_insn (gen_rtx_REG (SImode, 3), ip_rtx); |
095bb276 | 15576 | else if (args_to_push == 0) |
68dfd979 | 15577 | { |
f0b4bdd5 RE |
15578 | rtx dwarf; |
15579 | ||
35596784 AJ |
15580 | gcc_assert(arm_compute_static_chain_stack_bytes() == 4); |
15581 | saved_regs += 4; | |
15582 | ||
d66437c5 RE |
15583 | insn = gen_rtx_PRE_DEC (SImode, stack_pointer_rtx); |
15584 | insn = emit_set_insn (gen_frame_mem (SImode, insn), ip_rtx); | |
68dfd979 | 15585 | fp_offset = 4; |
34ce3d7b JM |
15586 | |
15587 | /* Just tell the dwarf backend that we adjusted SP. */ | |
15588 | dwarf = gen_rtx_SET (VOIDmode, stack_pointer_rtx, | |
d66437c5 RE |
15589 | plus_constant (stack_pointer_rtx, |
15590 | -fp_offset)); | |
34ce3d7b | 15591 | RTX_FRAME_RELATED_P (insn) = 1; |
bbbbb16a | 15592 | add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
68dfd979 NC |
15593 | } |
15594 | else | |
095bb276 NC |
15595 | { |
15596 | /* Store the args on the stack. */ | |
3cb66fd7 | 15597 | if (cfun->machine->uses_anonymous_args) |
095bb276 NC |
15598 | insn = emit_multi_reg_push |
15599 | ((0xf0 >> (args_to_push / 4)) & 0xf); | |
15600 | else | |
15601 | insn = emit_insn | |
f676971a | 15602 | (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
095bb276 NC |
15603 | GEN_INT (- args_to_push))); |
15604 | ||
15605 | RTX_FRAME_RELATED_P (insn) = 1; | |
15606 | ||
15607 | saved_pretend_args = 1; | |
15608 | fp_offset = args_to_push; | |
15609 | args_to_push = 0; | |
15610 | ||
15611 | /* Now reuse r3 to preserve IP. */ | |
d66437c5 | 15612 | emit_set_insn (gen_rtx_REG (SImode, 3), ip_rtx); |
095bb276 | 15613 | } |
68dfd979 NC |
15614 | } |
15615 | ||
d66437c5 RE |
15616 | insn = emit_set_insn (ip_rtx, |
15617 | plus_constant (stack_pointer_rtx, fp_offset)); | |
8e56560e | 15618 | RTX_FRAME_RELATED_P (insn) = 1; |
e2c671ba RE |
15619 | } |
15620 | ||
095bb276 | 15621 | if (args_to_push) |
e2c671ba | 15622 | { |
6d3d9133 | 15623 | /* Push the argument registers, or reserve space for them. */ |
3cb66fd7 | 15624 | if (cfun->machine->uses_anonymous_args) |
2c849145 | 15625 | insn = emit_multi_reg_push |
095bb276 | 15626 | ((0xf0 >> (args_to_push / 4)) & 0xf); |
e2c671ba | 15627 | else |
2c849145 | 15628 | insn = emit_insn |
f676971a | 15629 | (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
095bb276 | 15630 | GEN_INT (- args_to_push))); |
2c849145 | 15631 | RTX_FRAME_RELATED_P (insn) = 1; |
e2c671ba RE |
15632 | } |
15633 | ||
06bea5aa | 15634 | /* If this is an interrupt service routine, and the link register |
ec6237e4 PB |
15635 | is going to be pushed, and we're not generating extra |
15636 | push of IP (needed when frame is needed and frame layout if apcs), | |
06bea5aa NC |
15637 | subtracting four from LR now will mean that the function return |
15638 | can be done with a single instruction. */ | |
3a7731fd | 15639 | if ((func_type == ARM_FT_ISR || func_type == ARM_FT_FIQ) |
06bea5aa | 15640 | && (live_regs_mask & (1 << LR_REGNUM)) != 0 |
ec6237e4 | 15641 | && !(frame_pointer_needed && TARGET_APCS_FRAME) |
a15908a4 | 15642 | && TARGET_ARM) |
d66437c5 RE |
15643 | { |
15644 | rtx lr = gen_rtx_REG (SImode, LR_REGNUM); | |
15645 | ||
15646 | emit_set_insn (lr, plus_constant (lr, -4)); | |
15647 | } | |
3a7731fd | 15648 | |
e2c671ba RE |
15649 | if (live_regs_mask) |
15650 | { | |
5848830f | 15651 | saved_regs += bit_count (live_regs_mask) * 4; |
954954d1 PB |
15652 | if (optimize_size && !frame_pointer_needed |
15653 | && saved_regs == offsets->saved_regs - offsets->saved_args) | |
15654 | { | |
15655 | /* If no coprocessor registers are being pushed and we don't have | |
15656 | to worry about a frame pointer then push extra registers to | |
15657 | create the stack frame. This is done is a way that does not | |
15658 | alter the frame layout, so is independent of the epilogue. */ | |
15659 | int n; | |
15660 | int frame; | |
15661 | n = 0; | |
15662 | while (n < 8 && (live_regs_mask & (1 << n)) == 0) | |
15663 | n++; | |
15664 | frame = offsets->outgoing_args - (offsets->saved_args + saved_regs); | |
15665 | if (frame && n * 4 >= frame) | |
15666 | { | |
15667 | n = frame / 4; | |
15668 | live_regs_mask |= (1 << n) - 1; | |
15669 | saved_regs += frame; | |
15670 | } | |
15671 | } | |
15672 | insn = emit_multi_reg_push (live_regs_mask); | |
2c849145 | 15673 | RTX_FRAME_RELATED_P (insn) = 1; |
e2c671ba | 15674 | } |
d5b7b3ae | 15675 | |
6d3d9133 | 15676 | if (! IS_VOLATILE (func_type)) |
5b3e6663 | 15677 | saved_regs += arm_save_coproc_regs (); |
b111229a | 15678 | |
5b3e6663 PB |
15679 | if (frame_pointer_needed && TARGET_ARM) |
15680 | { | |
15681 | /* Create the new frame pointer. */ | |
ec6237e4 | 15682 | if (TARGET_APCS_FRAME) |
9b66ebb1 | 15683 | { |
5b3e6663 PB |
15684 | insn = GEN_INT (-(4 + args_to_push + fp_offset)); |
15685 | insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, ip_rtx, insn)); | |
15686 | RTX_FRAME_RELATED_P (insn) = 1; | |
9b66ebb1 | 15687 | |
5b3e6663 | 15688 | if (IS_NESTED (func_type)) |
9b66ebb1 | 15689 | { |
5b3e6663 | 15690 | /* Recover the static chain register. */ |
6fb5fa3c | 15691 | if (!df_regs_ever_live_p (3) |
5b3e6663 PB |
15692 | || saved_pretend_args) |
15693 | insn = gen_rtx_REG (SImode, 3); | |
38173d38 | 15694 | else /* if (crtl->args.pretend_args_size == 0) */ |
9b66ebb1 | 15695 | { |
5b3e6663 PB |
15696 | insn = plus_constant (hard_frame_pointer_rtx, 4); |
15697 | insn = gen_frame_mem (SImode, insn); | |
9b66ebb1 | 15698 | } |
5b3e6663 PB |
15699 | emit_set_insn (ip_rtx, insn); |
15700 | /* Add a USE to stop propagate_one_insn() from barfing. */ | |
15701 | emit_insn (gen_prologue_use (ip_rtx)); | |
9b66ebb1 | 15702 | } |
68dfd979 | 15703 | } |
ec6237e4 PB |
15704 | else |
15705 | { | |
15706 | insn = GEN_INT (saved_regs - 4); | |
15707 | insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, | |
15708 | stack_pointer_rtx, insn)); | |
15709 | RTX_FRAME_RELATED_P (insn) = 1; | |
15710 | } | |
2c849145 | 15711 | } |
e2c671ba | 15712 | |
5848830f | 15713 | if (offsets->outgoing_args != offsets->saved_args + saved_regs) |
e2c671ba | 15714 | { |
745b9093 JM |
15715 | /* This add can produce multiple insns for a large constant, so we |
15716 | need to get tricky. */ | |
15717 | rtx last = get_last_insn (); | |
5848830f PB |
15718 | |
15719 | amount = GEN_INT (offsets->saved_args + saved_regs | |
15720 | - offsets->outgoing_args); | |
15721 | ||
2c849145 JM |
15722 | insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
15723 | amount)); | |
745b9093 JM |
15724 | do |
15725 | { | |
15726 | last = last ? NEXT_INSN (last) : get_insns (); | |
15727 | RTX_FRAME_RELATED_P (last) = 1; | |
15728 | } | |
15729 | while (last != insn); | |
e04c2d6c RE |
15730 | |
15731 | /* If the frame pointer is needed, emit a special barrier that | |
15732 | will prevent the scheduler from moving stores to the frame | |
15733 | before the stack adjustment. */ | |
15734 | if (frame_pointer_needed) | |
3894f59e RE |
15735 | insn = emit_insn (gen_stack_tie (stack_pointer_rtx, |
15736 | hard_frame_pointer_rtx)); | |
e2c671ba RE |
15737 | } |
15738 | ||
876f13b0 | 15739 | |
5b3e6663 PB |
15740 | if (frame_pointer_needed && TARGET_THUMB2) |
15741 | thumb_set_frame_pointer (offsets); | |
15742 | ||
020a4035 | 15743 | if (flag_pic && arm_pic_register != INVALID_REGNUM) |
5b3e6663 PB |
15744 | { |
15745 | unsigned long mask; | |
15746 | ||
15747 | mask = live_regs_mask; | |
15748 | mask &= THUMB2_WORK_REGS; | |
15749 | if (!IS_NESTED (func_type)) | |
15750 | mask |= (1 << IP_REGNUM); | |
15751 | arm_load_pic_register (mask); | |
15752 | } | |
876f13b0 | 15753 | |
e2c671ba | 15754 | /* If we are profiling, make sure no instructions are scheduled before |
f5a1b0d2 | 15755 | the call to mcount. Similarly if the user has requested no |
74d9c39f DJ |
15756 | scheduling in the prolog. Similarly if we want non-call exceptions |
15757 | using the EABI unwinder, to prevent faulting instructions from being | |
15758 | swapped with a stack adjustment. */ | |
e3b5732b | 15759 | if (crtl->profile || !TARGET_SCHED_PROLOG |
f0a0390e RH |
15760 | || (arm_except_unwind_info () == UI_TARGET |
15761 | && cfun->can_throw_non_call_exceptions)) | |
e2c671ba | 15762 | emit_insn (gen_blockage ()); |
6f7ebcbb NC |
15763 | |
15764 | /* If the link register is being kept alive, with the return address in it, | |
15765 | then make sure that it does not get reused by the ce2 pass. */ | |
15766 | if ((live_regs_mask & (1 << LR_REGNUM)) == 0) | |
6fb5fa3c | 15767 | cfun->machine->lr_save_eliminated = 1; |
e2c671ba | 15768 | } |
cce8749e | 15769 | \f |
5b3e6663 PB |
15770 | /* Print condition code to STREAM. Helper function for arm_print_operand. */ |
15771 | static void | |
15772 | arm_print_condition (FILE *stream) | |
15773 | { | |
15774 | if (arm_ccfsm_state == 3 || arm_ccfsm_state == 4) | |
15775 | { | |
15776 | /* Branch conversion is not implemented for Thumb-2. */ | |
15777 | if (TARGET_THUMB) | |
15778 | { | |
15779 | output_operand_lossage ("predicated Thumb instruction"); | |
15780 | return; | |
15781 | } | |
15782 | if (current_insn_predicate != NULL) | |
15783 | { | |
15784 | output_operand_lossage | |
15785 | ("predicated instruction in conditional sequence"); | |
15786 | return; | |
15787 | } | |
15788 | ||
15789 | fputs (arm_condition_codes[arm_current_cc], stream); | |
15790 | } | |
15791 | else if (current_insn_predicate) | |
15792 | { | |
15793 | enum arm_cond_code code; | |
15794 | ||
15795 | if (TARGET_THUMB1) | |
15796 | { | |
15797 | output_operand_lossage ("predicated Thumb instruction"); | |
15798 | return; | |
15799 | } | |
15800 | ||
15801 | code = get_arm_condition_code (current_insn_predicate); | |
15802 | fputs (arm_condition_codes[code], stream); | |
15803 | } | |
15804 | } | |
15805 | ||
15806 | ||
9997d19d RE |
15807 | /* If CODE is 'd', then the X is a condition operand and the instruction |
15808 | should only be executed if the condition is true. | |
ddd5a7c1 | 15809 | if CODE is 'D', then the X is a condition operand and the instruction |
9997d19d RE |
15810 | should only be executed if the condition is false: however, if the mode |
15811 | of the comparison is CCFPEmode, then always execute the instruction -- we | |
15812 | do this because in these circumstances !GE does not necessarily imply LT; | |
15813 | in these cases the instruction pattern will take care to make sure that | |
15814 | an instruction containing %d will follow, thereby undoing the effects of | |
ddd5a7c1 | 15815 | doing this instruction unconditionally. |
9997d19d RE |
15816 | If CODE is 'N' then X is a floating point operand that must be negated |
15817 | before output. | |
15818 | If CODE is 'B' then output a bitwise inverted value of X (a const int). | |
15819 | If X is a REG and CODE is `M', output a ldm/stm style multi-reg. */ | |
944442bb | 15820 | static void |
e32bac5b | 15821 | arm_print_operand (FILE *stream, rtx x, int code) |
9997d19d RE |
15822 | { |
15823 | switch (code) | |
15824 | { | |
15825 | case '@': | |
f3139301 | 15826 | fputs (ASM_COMMENT_START, stream); |
9997d19d RE |
15827 | return; |
15828 | ||
d5b7b3ae RE |
15829 | case '_': |
15830 | fputs (user_label_prefix, stream); | |
15831 | return; | |
f676971a | 15832 | |
9997d19d | 15833 | case '|': |
f3139301 | 15834 | fputs (REGISTER_PREFIX, stream); |
9997d19d RE |
15835 | return; |
15836 | ||
15837 | case '?': | |
5b3e6663 PB |
15838 | arm_print_condition (stream); |
15839 | return; | |
cca0a211 | 15840 | |
5b3e6663 PB |
15841 | case '(': |
15842 | /* Nothing in unified syntax, otherwise the current condition code. */ | |
15843 | if (!TARGET_UNIFIED_ASM) | |
15844 | arm_print_condition (stream); | |
15845 | break; | |
15846 | ||
15847 | case ')': | |
15848 | /* The current condition code in unified syntax, otherwise nothing. */ | |
15849 | if (TARGET_UNIFIED_ASM) | |
15850 | arm_print_condition (stream); | |
15851 | break; | |
15852 | ||
15853 | case '.': | |
15854 | /* The current condition code for a condition code setting instruction. | |
7a085dce | 15855 | Preceded by 's' in unified syntax, otherwise followed by 's'. */ |
5b3e6663 PB |
15856 | if (TARGET_UNIFIED_ASM) |
15857 | { | |
15858 | fputc('s', stream); | |
15859 | arm_print_condition (stream); | |
cca0a211 | 15860 | } |
5b3e6663 | 15861 | else |
cca0a211 | 15862 | { |
5b3e6663 PB |
15863 | arm_print_condition (stream); |
15864 | fputc('s', stream); | |
cca0a211 | 15865 | } |
9997d19d RE |
15866 | return; |
15867 | ||
5b3e6663 PB |
15868 | case '!': |
15869 | /* If the instruction is conditionally executed then print | |
15870 | the current condition code, otherwise print 's'. */ | |
15871 | gcc_assert (TARGET_THUMB2 && TARGET_UNIFIED_ASM); | |
15872 | if (current_insn_predicate) | |
15873 | arm_print_condition (stream); | |
15874 | else | |
15875 | fputc('s', stream); | |
15876 | break; | |
15877 | ||
88f77cba | 15878 | /* %# is a "break" sequence. It doesn't output anything, but is used to |
cea618ac | 15879 | separate e.g. operand numbers from following text, if that text consists |
88f77cba JB |
15880 | of further digits which we don't want to be part of the operand |
15881 | number. */ | |
15882 | case '#': | |
15883 | return; | |
15884 | ||
9997d19d RE |
15885 | case 'N': |
15886 | { | |
15887 | REAL_VALUE_TYPE r; | |
15888 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); | |
d49b6e1e | 15889 | r = real_value_negate (&r); |
9997d19d RE |
15890 | fprintf (stream, "%s", fp_const_from_val (&r)); |
15891 | } | |
15892 | return; | |
15893 | ||
571191af | 15894 | /* An integer or symbol address without a preceding # sign. */ |
88f77cba | 15895 | case 'c': |
571191af PB |
15896 | switch (GET_CODE (x)) |
15897 | { | |
15898 | case CONST_INT: | |
15899 | fprintf (stream, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); | |
15900 | break; | |
15901 | ||
15902 | case SYMBOL_REF: | |
15903 | output_addr_const (stream, x); | |
15904 | break; | |
15905 | ||
15906 | default: | |
15907 | gcc_unreachable (); | |
15908 | } | |
88f77cba JB |
15909 | return; |
15910 | ||
9997d19d RE |
15911 | case 'B': |
15912 | if (GET_CODE (x) == CONST_INT) | |
4bc74ece NC |
15913 | { |
15914 | HOST_WIDE_INT val; | |
5895f793 | 15915 | val = ARM_SIGN_EXTEND (~INTVAL (x)); |
36ba9cb8 | 15916 | fprintf (stream, HOST_WIDE_INT_PRINT_DEC, val); |
4bc74ece | 15917 | } |
9997d19d RE |
15918 | else |
15919 | { | |
15920 | putc ('~', stream); | |
15921 | output_addr_const (stream, x); | |
15922 | } | |
15923 | return; | |
15924 | ||
5b3e6663 PB |
15925 | case 'L': |
15926 | /* The low 16 bits of an immediate constant. */ | |
15927 | fprintf (stream, HOST_WIDE_INT_PRINT_DEC, INTVAL(x) & 0xffff); | |
15928 | return; | |
15929 | ||
9997d19d RE |
15930 | case 'i': |
15931 | fprintf (stream, "%s", arithmetic_instr (x, 1)); | |
15932 | return; | |
15933 | ||
9b6b54e2 NC |
15934 | /* Truncate Cirrus shift counts. */ |
15935 | case 's': | |
15936 | if (GET_CODE (x) == CONST_INT) | |
15937 | { | |
15938 | fprintf (stream, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x3f); | |
15939 | return; | |
15940 | } | |
15941 | arm_print_operand (stream, x, 0); | |
15942 | return; | |
15943 | ||
9997d19d RE |
15944 | case 'I': |
15945 | fprintf (stream, "%s", arithmetic_instr (x, 0)); | |
15946 | return; | |
15947 | ||
15948 | case 'S': | |
15949 | { | |
15950 | HOST_WIDE_INT val; | |
beed32b8 RE |
15951 | const char *shift; |
15952 | ||
15953 | if (!shift_operator (x, SImode)) | |
15954 | { | |
15955 | output_operand_lossage ("invalid shift operand"); | |
15956 | break; | |
15957 | } | |
15958 | ||
15959 | shift = shift_op (x, &val); | |
9997d19d | 15960 | |
e2c671ba RE |
15961 | if (shift) |
15962 | { | |
beed32b8 | 15963 | fprintf (stream, ", %s ", shift); |
e2c671ba RE |
15964 | if (val == -1) |
15965 | arm_print_operand (stream, XEXP (x, 1), 0); | |
15966 | else | |
4a0a75dd | 15967 | fprintf (stream, "#" HOST_WIDE_INT_PRINT_DEC, val); |
e2c671ba | 15968 | } |
9997d19d RE |
15969 | } |
15970 | return; | |
15971 | ||
d5b7b3ae | 15972 | /* An explanation of the 'Q', 'R' and 'H' register operands: |
f676971a | 15973 | |
d5b7b3ae RE |
15974 | In a pair of registers containing a DI or DF value the 'Q' |
15975 | operand returns the register number of the register containing | |
093354e0 | 15976 | the least significant part of the value. The 'R' operand returns |
d5b7b3ae RE |
15977 | the register number of the register containing the most |
15978 | significant part of the value. | |
f676971a | 15979 | |
d5b7b3ae RE |
15980 | The 'H' operand returns the higher of the two register numbers. |
15981 | On a run where WORDS_BIG_ENDIAN is true the 'H' operand is the | |
093354e0 | 15982 | same as the 'Q' operand, since the most significant part of the |
d5b7b3ae RE |
15983 | value is held in the lower number register. The reverse is true |
15984 | on systems where WORDS_BIG_ENDIAN is false. | |
f676971a | 15985 | |
d5b7b3ae RE |
15986 | The purpose of these operands is to distinguish between cases |
15987 | where the endian-ness of the values is important (for example | |
15988 | when they are added together), and cases where the endian-ness | |
15989 | is irrelevant, but the order of register operations is important. | |
15990 | For example when loading a value from memory into a register | |
15991 | pair, the endian-ness does not matter. Provided that the value | |
15992 | from the lower memory address is put into the lower numbered | |
15993 | register, and the value from the higher address is put into the | |
15994 | higher numbered register, the load will work regardless of whether | |
15995 | the value being loaded is big-wordian or little-wordian. The | |
15996 | order of the two register loads can matter however, if the address | |
15997 | of the memory location is actually held in one of the registers | |
73160ba9 DJ |
15998 | being overwritten by the load. |
15999 | ||
16000 | The 'Q' and 'R' constraints are also available for 64-bit | |
16001 | constants. */ | |
c1c2bc04 | 16002 | case 'Q': |
73160ba9 DJ |
16003 | if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) |
16004 | { | |
16005 | rtx part = gen_lowpart (SImode, x); | |
16006 | fprintf (stream, "#" HOST_WIDE_INT_PRINT_DEC, INTVAL (part)); | |
16007 | return; | |
16008 | } | |
16009 | ||
22de4c3d RE |
16010 | if (GET_CODE (x) != REG || REGNO (x) > LAST_ARM_REGNUM) |
16011 | { | |
16012 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16013 | return; | |
16014 | } | |
16015 | ||
d5b7b3ae | 16016 | asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 1 : 0)); |
c1c2bc04 RE |
16017 | return; |
16018 | ||
9997d19d | 16019 | case 'R': |
73160ba9 DJ |
16020 | if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) |
16021 | { | |
16022 | enum machine_mode mode = GET_MODE (x); | |
16023 | rtx part; | |
16024 | ||
16025 | if (mode == VOIDmode) | |
16026 | mode = DImode; | |
16027 | part = gen_highpart_mode (SImode, mode, x); | |
16028 | fprintf (stream, "#" HOST_WIDE_INT_PRINT_DEC, INTVAL (part)); | |
16029 | return; | |
16030 | } | |
16031 | ||
22de4c3d RE |
16032 | if (GET_CODE (x) != REG || REGNO (x) > LAST_ARM_REGNUM) |
16033 | { | |
16034 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16035 | return; | |
16036 | } | |
16037 | ||
d5b7b3ae RE |
16038 | asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 0 : 1)); |
16039 | return; | |
16040 | ||
16041 | case 'H': | |
22de4c3d RE |
16042 | if (GET_CODE (x) != REG || REGNO (x) > LAST_ARM_REGNUM) |
16043 | { | |
16044 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16045 | return; | |
16046 | } | |
16047 | ||
d5b7b3ae | 16048 | asm_fprintf (stream, "%r", REGNO (x) + 1); |
9997d19d RE |
16049 | return; |
16050 | ||
88f77cba JB |
16051 | case 'J': |
16052 | if (GET_CODE (x) != REG || REGNO (x) > LAST_ARM_REGNUM) | |
16053 | { | |
16054 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16055 | return; | |
16056 | } | |
16057 | ||
16058 | asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 3 : 2)); | |
16059 | return; | |
16060 | ||
16061 | case 'K': | |
16062 | if (GET_CODE (x) != REG || REGNO (x) > LAST_ARM_REGNUM) | |
16063 | { | |
16064 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16065 | return; | |
16066 | } | |
16067 | ||
16068 | asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 2 : 3)); | |
16069 | return; | |
16070 | ||
9997d19d | 16071 | case 'm': |
f676971a | 16072 | asm_fprintf (stream, "%r", |
d5b7b3ae RE |
16073 | GET_CODE (XEXP (x, 0)) == REG |
16074 | ? REGNO (XEXP (x, 0)) : REGNO (XEXP (XEXP (x, 0), 0))); | |
9997d19d RE |
16075 | return; |
16076 | ||
16077 | case 'M': | |
dd18ae56 | 16078 | asm_fprintf (stream, "{%r-%r}", |
d5b7b3ae | 16079 | REGNO (x), |
e9d7b180 | 16080 | REGNO (x) + ARM_NUM_REGS (GET_MODE (x)) - 1); |
9997d19d RE |
16081 | return; |
16082 | ||
88f77cba JB |
16083 | /* Like 'M', but writing doubleword vector registers, for use by Neon |
16084 | insns. */ | |
16085 | case 'h': | |
16086 | { | |
16087 | int regno = (REGNO (x) - FIRST_VFP_REGNUM) / 2; | |
16088 | int numregs = ARM_NUM_REGS (GET_MODE (x)) / 2; | |
16089 | if (numregs == 1) | |
16090 | asm_fprintf (stream, "{d%d}", regno); | |
16091 | else | |
16092 | asm_fprintf (stream, "{d%d-d%d}", regno, regno + numregs - 1); | |
16093 | } | |
16094 | return; | |
16095 | ||
9997d19d | 16096 | case 'd': |
64e92a26 RE |
16097 | /* CONST_TRUE_RTX means always -- that's the default. */ |
16098 | if (x == const_true_rtx) | |
d5b7b3ae | 16099 | return; |
f676971a | 16100 | |
22de4c3d RE |
16101 | if (!COMPARISON_P (x)) |
16102 | { | |
16103 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16104 | return; | |
16105 | } | |
16106 | ||
defc0463 RE |
16107 | fputs (arm_condition_codes[get_arm_condition_code (x)], |
16108 | stream); | |
9997d19d RE |
16109 | return; |
16110 | ||
16111 | case 'D': | |
112cdef5 | 16112 | /* CONST_TRUE_RTX means not always -- i.e. never. We shouldn't ever |
64e92a26 RE |
16113 | want to do that. */ |
16114 | if (x == const_true_rtx) | |
22de4c3d | 16115 | { |
4dad0aca | 16116 | output_operand_lossage ("instruction never executed"); |
22de4c3d RE |
16117 | return; |
16118 | } | |
16119 | if (!COMPARISON_P (x)) | |
16120 | { | |
16121 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16122 | return; | |
16123 | } | |
d5b7b3ae | 16124 | |
defc0463 RE |
16125 | fputs (arm_condition_codes[ARM_INVERSE_CONDITION_CODE |
16126 | (get_arm_condition_code (x))], | |
16127 | stream); | |
9997d19d RE |
16128 | return; |
16129 | ||
9b6b54e2 NC |
16130 | /* Cirrus registers can be accessed in a variety of ways: |
16131 | single floating point (f) | |
16132 | double floating point (d) | |
16133 | 32bit integer (fx) | |
16134 | 64bit integer (dx). */ | |
16135 | case 'W': /* Cirrus register in F mode. */ | |
16136 | case 'X': /* Cirrus register in D mode. */ | |
16137 | case 'Y': /* Cirrus register in FX mode. */ | |
16138 | case 'Z': /* Cirrus register in DX mode. */ | |
e6d29d15 NS |
16139 | gcc_assert (GET_CODE (x) == REG |
16140 | && REGNO_REG_CLASS (REGNO (x)) == CIRRUS_REGS); | |
9b6b54e2 NC |
16141 | |
16142 | fprintf (stream, "mv%s%s", | |
16143 | code == 'W' ? "f" | |
16144 | : code == 'X' ? "d" | |
16145 | : code == 'Y' ? "fx" : "dx", reg_names[REGNO (x)] + 2); | |
16146 | ||
16147 | return; | |
16148 | ||
16149 | /* Print cirrus register in the mode specified by the register's mode. */ | |
16150 | case 'V': | |
16151 | { | |
16152 | int mode = GET_MODE (x); | |
16153 | ||
16154 | if (GET_CODE (x) != REG || REGNO_REG_CLASS (REGNO (x)) != CIRRUS_REGS) | |
22de4c3d RE |
16155 | { |
16156 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16157 | return; | |
16158 | } | |
9b6b54e2 NC |
16159 | |
16160 | fprintf (stream, "mv%s%s", | |
16161 | mode == DFmode ? "d" | |
16162 | : mode == SImode ? "fx" | |
16163 | : mode == DImode ? "dx" | |
16164 | : "f", reg_names[REGNO (x)] + 2); | |
16165 | ||
16166 | return; | |
16167 | } | |
16168 | ||
5a9335ef NC |
16169 | case 'U': |
16170 | if (GET_CODE (x) != REG | |
16171 | || REGNO (x) < FIRST_IWMMXT_GR_REGNUM | |
16172 | || REGNO (x) > LAST_IWMMXT_GR_REGNUM) | |
16173 | /* Bad value for wCG register number. */ | |
22de4c3d RE |
16174 | { |
16175 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16176 | return; | |
16177 | } | |
16178 | ||
5a9335ef NC |
16179 | else |
16180 | fprintf (stream, "%d", REGNO (x) - FIRST_IWMMXT_GR_REGNUM); | |
16181 | return; | |
16182 | ||
16183 | /* Print an iWMMXt control register name. */ | |
16184 | case 'w': | |
16185 | if (GET_CODE (x) != CONST_INT | |
16186 | || INTVAL (x) < 0 | |
16187 | || INTVAL (x) >= 16) | |
16188 | /* Bad value for wC register number. */ | |
22de4c3d RE |
16189 | { |
16190 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16191 | return; | |
16192 | } | |
16193 | ||
5a9335ef NC |
16194 | else |
16195 | { | |
16196 | static const char * wc_reg_names [16] = | |
16197 | { | |
16198 | "wCID", "wCon", "wCSSF", "wCASF", | |
16199 | "wC4", "wC5", "wC6", "wC7", | |
16200 | "wCGR0", "wCGR1", "wCGR2", "wCGR3", | |
16201 | "wC12", "wC13", "wC14", "wC15" | |
16202 | }; | |
f676971a | 16203 | |
5a9335ef NC |
16204 | fprintf (stream, wc_reg_names [INTVAL (x)]); |
16205 | } | |
16206 | return; | |
16207 | ||
e0dc3601 PB |
16208 | /* Print the high single-precision register of a VFP double-precision |
16209 | register. */ | |
16210 | case 'p': | |
16211 | { | |
16212 | int mode = GET_MODE (x); | |
16213 | int regno; | |
16214 | ||
16215 | if (GET_MODE_SIZE (mode) != 8 || GET_CODE (x) != REG) | |
16216 | { | |
16217 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16218 | return; | |
16219 | } | |
16220 | ||
16221 | regno = REGNO (x); | |
16222 | if (!VFP_REGNO_OK_FOR_DOUBLE (regno)) | |
16223 | { | |
16224 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16225 | return; | |
16226 | } | |
16227 | ||
16228 | fprintf (stream, "s%d", regno - FIRST_VFP_REGNUM + 1); | |
16229 | } | |
16230 | return; | |
16231 | ||
88f77cba | 16232 | /* Print a VFP/Neon double precision or quad precision register name. */ |
9b66ebb1 | 16233 | case 'P': |
88f77cba | 16234 | case 'q': |
9b66ebb1 PB |
16235 | { |
16236 | int mode = GET_MODE (x); | |
88f77cba JB |
16237 | int is_quad = (code == 'q'); |
16238 | int regno; | |
9b66ebb1 | 16239 | |
88f77cba | 16240 | if (GET_MODE_SIZE (mode) != (is_quad ? 16 : 8)) |
22de4c3d RE |
16241 | { |
16242 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16243 | return; | |
16244 | } | |
9b66ebb1 PB |
16245 | |
16246 | if (GET_CODE (x) != REG | |
16247 | || !IS_VFP_REGNUM (REGNO (x))) | |
22de4c3d RE |
16248 | { |
16249 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16250 | return; | |
16251 | } | |
9b66ebb1 | 16252 | |
88f77cba JB |
16253 | regno = REGNO (x); |
16254 | if ((is_quad && !NEON_REGNO_OK_FOR_QUAD (regno)) | |
16255 | || (!is_quad && !VFP_REGNO_OK_FOR_DOUBLE (regno))) | |
22de4c3d RE |
16256 | { |
16257 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16258 | return; | |
16259 | } | |
9b66ebb1 | 16260 | |
88f77cba JB |
16261 | fprintf (stream, "%c%d", is_quad ? 'q' : 'd', |
16262 | (regno - FIRST_VFP_REGNUM) >> (is_quad ? 2 : 1)); | |
16263 | } | |
16264 | return; | |
16265 | ||
16266 | /* These two codes print the low/high doubleword register of a Neon quad | |
16267 | register, respectively. For pair-structure types, can also print | |
16268 | low/high quadword registers. */ | |
16269 | case 'e': | |
16270 | case 'f': | |
16271 | { | |
16272 | int mode = GET_MODE (x); | |
16273 | int regno; | |
16274 | ||
16275 | if ((GET_MODE_SIZE (mode) != 16 | |
16276 | && GET_MODE_SIZE (mode) != 32) || GET_CODE (x) != REG) | |
16277 | { | |
16278 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16279 | return; | |
16280 | } | |
16281 | ||
16282 | regno = REGNO (x); | |
16283 | if (!NEON_REGNO_OK_FOR_QUAD (regno)) | |
16284 | { | |
16285 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16286 | return; | |
16287 | } | |
16288 | ||
16289 | if (GET_MODE_SIZE (mode) == 16) | |
16290 | fprintf (stream, "d%d", ((regno - FIRST_VFP_REGNUM) >> 1) | |
16291 | + (code == 'f' ? 1 : 0)); | |
16292 | else | |
16293 | fprintf (stream, "q%d", ((regno - FIRST_VFP_REGNUM) >> 2) | |
16294 | + (code == 'f' ? 1 : 0)); | |
9b66ebb1 PB |
16295 | } |
16296 | return; | |
16297 | ||
f1adb0a9 JB |
16298 | /* Print a VFPv3 floating-point constant, represented as an integer |
16299 | index. */ | |
16300 | case 'G': | |
16301 | { | |
16302 | int index = vfp3_const_double_index (x); | |
16303 | gcc_assert (index != -1); | |
16304 | fprintf (stream, "%d", index); | |
16305 | } | |
16306 | return; | |
16307 | ||
88f77cba JB |
16308 | /* Print bits representing opcode features for Neon. |
16309 | ||
16310 | Bit 0 is 1 for signed, 0 for unsigned. Floats count as signed | |
16311 | and polynomials as unsigned. | |
16312 | ||
16313 | Bit 1 is 1 for floats and polynomials, 0 for ordinary integers. | |
16314 | ||
16315 | Bit 2 is 1 for rounding functions, 0 otherwise. */ | |
16316 | ||
16317 | /* Identify the type as 's', 'u', 'p' or 'f'. */ | |
16318 | case 'T': | |
16319 | { | |
16320 | HOST_WIDE_INT bits = INTVAL (x); | |
16321 | fputc ("uspf"[bits & 3], stream); | |
16322 | } | |
16323 | return; | |
16324 | ||
16325 | /* Likewise, but signed and unsigned integers are both 'i'. */ | |
16326 | case 'F': | |
16327 | { | |
16328 | HOST_WIDE_INT bits = INTVAL (x); | |
16329 | fputc ("iipf"[bits & 3], stream); | |
16330 | } | |
16331 | return; | |
16332 | ||
16333 | /* As for 'T', but emit 'u' instead of 'p'. */ | |
16334 | case 't': | |
16335 | { | |
16336 | HOST_WIDE_INT bits = INTVAL (x); | |
16337 | fputc ("usuf"[bits & 3], stream); | |
16338 | } | |
16339 | return; | |
16340 | ||
16341 | /* Bit 2: rounding (vs none). */ | |
16342 | case 'O': | |
16343 | { | |
16344 | HOST_WIDE_INT bits = INTVAL (x); | |
16345 | fputs ((bits & 4) != 0 ? "r" : "", stream); | |
16346 | } | |
16347 | return; | |
16348 | ||
dc34db56 PB |
16349 | /* Memory operand for vld1/vst1 instruction. */ |
16350 | case 'A': | |
16351 | { | |
16352 | rtx addr; | |
16353 | bool postinc = FALSE; | |
c452684d JB |
16354 | unsigned align, modesize, align_bits; |
16355 | ||
dc34db56 PB |
16356 | gcc_assert (GET_CODE (x) == MEM); |
16357 | addr = XEXP (x, 0); | |
16358 | if (GET_CODE (addr) == POST_INC) | |
16359 | { | |
16360 | postinc = 1; | |
16361 | addr = XEXP (addr, 0); | |
16362 | } | |
c452684d JB |
16363 | asm_fprintf (stream, "[%r", REGNO (addr)); |
16364 | ||
16365 | /* We know the alignment of this access, so we can emit a hint in the | |
16366 | instruction (for some alignments) as an aid to the memory subsystem | |
16367 | of the target. */ | |
16368 | align = MEM_ALIGN (x) >> 3; | |
16369 | modesize = GET_MODE_SIZE (GET_MODE (x)); | |
16370 | ||
16371 | /* Only certain alignment specifiers are supported by the hardware. */ | |
16372 | if (modesize == 16 && (align % 32) == 0) | |
16373 | align_bits = 256; | |
16374 | else if ((modesize == 8 || modesize == 16) && (align % 16) == 0) | |
16375 | align_bits = 128; | |
16376 | else if ((align % 8) == 0) | |
16377 | align_bits = 64; | |
16378 | else | |
16379 | align_bits = 0; | |
16380 | ||
16381 | if (align_bits != 0) | |
16382 | asm_fprintf (stream, ":%d", align_bits); | |
16383 | ||
16384 | asm_fprintf (stream, "]"); | |
16385 | ||
dc34db56 PB |
16386 | if (postinc) |
16387 | fputs("!", stream); | |
16388 | } | |
16389 | return; | |
16390 | ||
029e79eb MS |
16391 | case 'C': |
16392 | { | |
16393 | rtx addr; | |
16394 | ||
16395 | gcc_assert (GET_CODE (x) == MEM); | |
16396 | addr = XEXP (x, 0); | |
16397 | gcc_assert (GET_CODE (addr) == REG); | |
16398 | asm_fprintf (stream, "[%r]", REGNO (addr)); | |
16399 | } | |
16400 | return; | |
16401 | ||
814a4c3b DJ |
16402 | /* Translate an S register number into a D register number and element index. */ |
16403 | case 'y': | |
16404 | { | |
16405 | int mode = GET_MODE (x); | |
16406 | int regno; | |
16407 | ||
16408 | if (GET_MODE_SIZE (mode) != 4 || GET_CODE (x) != REG) | |
16409 | { | |
16410 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16411 | return; | |
16412 | } | |
16413 | ||
16414 | regno = REGNO (x); | |
16415 | if (!VFP_REGNO_OK_FOR_SINGLE (regno)) | |
16416 | { | |
16417 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16418 | return; | |
16419 | } | |
16420 | ||
16421 | regno = regno - FIRST_VFP_REGNUM; | |
16422 | fprintf (stream, "d%d[%d]", regno / 2, regno % 2); | |
16423 | } | |
16424 | return; | |
16425 | ||
0fd8c3ad SL |
16426 | /* Register specifier for vld1.16/vst1.16. Translate the S register |
16427 | number into a D register number and element index. */ | |
16428 | case 'z': | |
16429 | { | |
16430 | int mode = GET_MODE (x); | |
16431 | int regno; | |
16432 | ||
16433 | if (GET_MODE_SIZE (mode) != 2 || GET_CODE (x) != REG) | |
16434 | { | |
16435 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16436 | return; | |
16437 | } | |
16438 | ||
16439 | regno = REGNO (x); | |
16440 | if (!VFP_REGNO_OK_FOR_SINGLE (regno)) | |
16441 | { | |
16442 | output_operand_lossage ("invalid operand for code '%c'", code); | |
16443 | return; | |
16444 | } | |
16445 | ||
16446 | regno = regno - FIRST_VFP_REGNUM; | |
16447 | fprintf (stream, "d%d[%d]", regno/2, ((regno % 2) ? 2 : 0)); | |
16448 | } | |
16449 | return; | |
16450 | ||
9997d19d RE |
16451 | default: |
16452 | if (x == 0) | |
22de4c3d RE |
16453 | { |
16454 | output_operand_lossage ("missing operand"); | |
16455 | return; | |
16456 | } | |
9997d19d | 16457 | |
e6d29d15 | 16458 | switch (GET_CODE (x)) |
9997d19d | 16459 | { |
e6d29d15 NS |
16460 | case REG: |
16461 | asm_fprintf (stream, "%r", REGNO (x)); | |
16462 | break; | |
16463 | ||
16464 | case MEM: | |
9997d19d RE |
16465 | output_memory_reference_mode = GET_MODE (x); |
16466 | output_address (XEXP (x, 0)); | |
e6d29d15 NS |
16467 | break; |
16468 | ||
16469 | case CONST_DOUBLE: | |
88f77cba JB |
16470 | if (TARGET_NEON) |
16471 | { | |
16472 | char fpstr[20]; | |
16473 | real_to_decimal (fpstr, CONST_DOUBLE_REAL_VALUE (x), | |
16474 | sizeof (fpstr), 0, 1); | |
16475 | fprintf (stream, "#%s", fpstr); | |
16476 | } | |
16477 | else | |
16478 | fprintf (stream, "#%s", fp_immediate_constant (x)); | |
e6d29d15 NS |
16479 | break; |
16480 | ||
16481 | default: | |
16482 | gcc_assert (GET_CODE (x) != NEG); | |
9997d19d | 16483 | fputc ('#', stream); |
d58bc084 NS |
16484 | if (GET_CODE (x) == HIGH) |
16485 | { | |
16486 | fputs (":lower16:", stream); | |
16487 | x = XEXP (x, 0); | |
16488 | } | |
16489 | ||
9997d19d | 16490 | output_addr_const (stream, x); |
e6d29d15 | 16491 | break; |
9997d19d RE |
16492 | } |
16493 | } | |
16494 | } | |
cce8749e | 16495 | \f |
944442bb NF |
16496 | /* Target hook for printing a memory address. */ |
16497 | static void | |
16498 | arm_print_operand_address (FILE *stream, rtx x) | |
16499 | { | |
16500 | if (TARGET_32BIT) | |
16501 | { | |
16502 | int is_minus = GET_CODE (x) == MINUS; | |
16503 | ||
16504 | if (GET_CODE (x) == REG) | |
16505 | asm_fprintf (stream, "[%r, #0]", REGNO (x)); | |
16506 | else if (GET_CODE (x) == PLUS || is_minus) | |
16507 | { | |
16508 | rtx base = XEXP (x, 0); | |
16509 | rtx index = XEXP (x, 1); | |
16510 | HOST_WIDE_INT offset = 0; | |
16511 | if (GET_CODE (base) != REG | |
16512 | || (GET_CODE (index) == REG && REGNO (index) == SP_REGNUM)) | |
16513 | { | |
16514 | /* Ensure that BASE is a register. */ | |
16515 | /* (one of them must be). */ | |
16516 | /* Also ensure the SP is not used as in index register. */ | |
16517 | rtx temp = base; | |
16518 | base = index; | |
16519 | index = temp; | |
16520 | } | |
16521 | switch (GET_CODE (index)) | |
16522 | { | |
16523 | case CONST_INT: | |
16524 | offset = INTVAL (index); | |
16525 | if (is_minus) | |
16526 | offset = -offset; | |
16527 | asm_fprintf (stream, "[%r, #%wd]", | |
16528 | REGNO (base), offset); | |
16529 | break; | |
16530 | ||
16531 | case REG: | |
16532 | asm_fprintf (stream, "[%r, %s%r]", | |
16533 | REGNO (base), is_minus ? "-" : "", | |
16534 | REGNO (index)); | |
16535 | break; | |
16536 | ||
16537 | case MULT: | |
16538 | case ASHIFTRT: | |
16539 | case LSHIFTRT: | |
16540 | case ASHIFT: | |
16541 | case ROTATERT: | |
16542 | { | |
16543 | asm_fprintf (stream, "[%r, %s%r", | |
16544 | REGNO (base), is_minus ? "-" : "", | |
16545 | REGNO (XEXP (index, 0))); | |
16546 | arm_print_operand (stream, index, 'S'); | |
16547 | fputs ("]", stream); | |
16548 | break; | |
16549 | } | |
16550 | ||
16551 | default: | |
16552 | gcc_unreachable (); | |
16553 | } | |
16554 | } | |
16555 | else if (GET_CODE (x) == PRE_INC || GET_CODE (x) == POST_INC | |
16556 | || GET_CODE (x) == PRE_DEC || GET_CODE (x) == POST_DEC) | |
16557 | { | |
16558 | extern enum machine_mode output_memory_reference_mode; | |
16559 | ||
16560 | gcc_assert (GET_CODE (XEXP (x, 0)) == REG); | |
16561 | ||
16562 | if (GET_CODE (x) == PRE_DEC || GET_CODE (x) == PRE_INC) | |
16563 | asm_fprintf (stream, "[%r, #%s%d]!", | |
16564 | REGNO (XEXP (x, 0)), | |
16565 | GET_CODE (x) == PRE_DEC ? "-" : "", | |
16566 | GET_MODE_SIZE (output_memory_reference_mode)); | |
16567 | else | |
16568 | asm_fprintf (stream, "[%r], #%s%d", | |
16569 | REGNO (XEXP (x, 0)), | |
16570 | GET_CODE (x) == POST_DEC ? "-" : "", | |
16571 | GET_MODE_SIZE (output_memory_reference_mode)); | |
16572 | } | |
16573 | else if (GET_CODE (x) == PRE_MODIFY) | |
16574 | { | |
16575 | asm_fprintf (stream, "[%r, ", REGNO (XEXP (x, 0))); | |
16576 | if (GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT) | |
16577 | asm_fprintf (stream, "#%wd]!", | |
16578 | INTVAL (XEXP (XEXP (x, 1), 1))); | |
16579 | else | |
16580 | asm_fprintf (stream, "%r]!", | |
16581 | REGNO (XEXP (XEXP (x, 1), 1))); | |
16582 | } | |
16583 | else if (GET_CODE (x) == POST_MODIFY) | |
16584 | { | |
16585 | asm_fprintf (stream, "[%r], ", REGNO (XEXP (x, 0))); | |
16586 | if (GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT) | |
16587 | asm_fprintf (stream, "#%wd", | |
16588 | INTVAL (XEXP (XEXP (x, 1), 1))); | |
16589 | else | |
16590 | asm_fprintf (stream, "%r", | |
16591 | REGNO (XEXP (XEXP (x, 1), 1))); | |
16592 | } | |
16593 | else output_addr_const (stream, x); | |
16594 | } | |
16595 | else | |
16596 | { | |
16597 | if (GET_CODE (x) == REG) | |
16598 | asm_fprintf (stream, "[%r]", REGNO (x)); | |
16599 | else if (GET_CODE (x) == POST_INC) | |
16600 | asm_fprintf (stream, "%r!", REGNO (XEXP (x, 0))); | |
16601 | else if (GET_CODE (x) == PLUS) | |
16602 | { | |
16603 | gcc_assert (GET_CODE (XEXP (x, 0)) == REG); | |
16604 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
16605 | asm_fprintf (stream, "[%r, #%wd]", | |
16606 | REGNO (XEXP (x, 0)), | |
16607 | INTVAL (XEXP (x, 1))); | |
16608 | else | |
16609 | asm_fprintf (stream, "[%r, %r]", | |
16610 | REGNO (XEXP (x, 0)), | |
16611 | REGNO (XEXP (x, 1))); | |
16612 | } | |
16613 | else | |
16614 | output_addr_const (stream, x); | |
16615 | } | |
16616 | } | |
16617 | \f | |
16618 | /* Target hook for indicating whether a punctuation character for | |
16619 | TARGET_PRINT_OPERAND is valid. */ | |
16620 | static bool | |
16621 | arm_print_operand_punct_valid_p (unsigned char code) | |
16622 | { | |
16623 | return (code == '@' || code == '|' || code == '.' | |
16624 | || code == '(' || code == ')' || code == '#' | |
16625 | || (TARGET_32BIT && (code == '?')) | |
16626 | || (TARGET_THUMB2 && (code == '!')) | |
16627 | || (TARGET_THUMB && (code == '_'))); | |
16628 | } | |
16629 | \f | |
301d03af RS |
16630 | /* Target hook for assembling integer objects. The ARM version needs to |
16631 | handle word-sized values specially. */ | |
301d03af | 16632 | static bool |
e32bac5b | 16633 | arm_assemble_integer (rtx x, unsigned int size, int aligned_p) |
301d03af | 16634 | { |
88f77cba JB |
16635 | enum machine_mode mode; |
16636 | ||
301d03af RS |
16637 | if (size == UNITS_PER_WORD && aligned_p) |
16638 | { | |
16639 | fputs ("\t.word\t", asm_out_file); | |
16640 | output_addr_const (asm_out_file, x); | |
16641 | ||
16642 | /* Mark symbols as position independent. We only do this in the | |
d6b4baa4 | 16643 | .text segment, not in the .data segment. */ |
301d03af RS |
16644 | if (NEED_GOT_RELOC && flag_pic && making_const_table && |
16645 | (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)) | |
16646 | { | |
9403b7f7 RS |
16647 | /* See legitimize_pic_address for an explanation of the |
16648 | TARGET_VXWORKS_RTP check. */ | |
16649 | if (TARGET_VXWORKS_RTP | |
16650 | || (GET_CODE (x) == SYMBOL_REF && !SYMBOL_REF_LOCAL_P (x))) | |
301d03af | 16651 | fputs ("(GOT)", asm_out_file); |
9403b7f7 RS |
16652 | else |
16653 | fputs ("(GOTOFF)", asm_out_file); | |
301d03af RS |
16654 | } |
16655 | fputc ('\n', asm_out_file); | |
16656 | return true; | |
16657 | } | |
1d6e90ac | 16658 | |
88f77cba JB |
16659 | mode = GET_MODE (x); |
16660 | ||
16661 | if (arm_vector_mode_supported_p (mode)) | |
5a9335ef NC |
16662 | { |
16663 | int i, units; | |
16664 | ||
e6d29d15 | 16665 | gcc_assert (GET_CODE (x) == CONST_VECTOR); |
5a9335ef NC |
16666 | |
16667 | units = CONST_VECTOR_NUNITS (x); | |
88f77cba | 16668 | size = GET_MODE_SIZE (GET_MODE_INNER (mode)); |
5a9335ef | 16669 | |
88f77cba JB |
16670 | if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) |
16671 | for (i = 0; i < units; i++) | |
16672 | { | |
874d42b9 | 16673 | rtx elt = CONST_VECTOR_ELT (x, i); |
88f77cba JB |
16674 | assemble_integer |
16675 | (elt, size, i == 0 ? BIGGEST_ALIGNMENT : size * BITS_PER_UNIT, 1); | |
16676 | } | |
16677 | else | |
16678 | for (i = 0; i < units; i++) | |
16679 | { | |
16680 | rtx elt = CONST_VECTOR_ELT (x, i); | |
16681 | REAL_VALUE_TYPE rval; | |
5a9335ef | 16682 | |
88f77cba JB |
16683 | REAL_VALUE_FROM_CONST_DOUBLE (rval, elt); |
16684 | ||
16685 | assemble_real | |
16686 | (rval, GET_MODE_INNER (mode), | |
16687 | i == 0 ? BIGGEST_ALIGNMENT : size * BITS_PER_UNIT); | |
16688 | } | |
5a9335ef NC |
16689 | |
16690 | return true; | |
16691 | } | |
16692 | ||
301d03af RS |
16693 | return default_assemble_integer (x, size, aligned_p); |
16694 | } | |
7abc66b1 | 16695 | |
7abc66b1 | 16696 | static void |
9f296620 | 16697 | arm_elf_asm_cdtor (rtx symbol, int priority, bool is_ctor) |
7abc66b1 | 16698 | { |
50603eed PB |
16699 | section *s; |
16700 | ||
7abc66b1 JB |
16701 | if (!TARGET_AAPCS_BASED) |
16702 | { | |
9f296620 MM |
16703 | (is_ctor ? |
16704 | default_named_section_asm_out_constructor | |
16705 | : default_named_section_asm_out_destructor) (symbol, priority); | |
7abc66b1 JB |
16706 | return; |
16707 | } | |
16708 | ||
16709 | /* Put these in the .init_array section, using a special relocation. */ | |
50603eed PB |
16710 | if (priority != DEFAULT_INIT_PRIORITY) |
16711 | { | |
16712 | char buf[18]; | |
9f296620 MM |
16713 | sprintf (buf, "%s.%.5u", |
16714 | is_ctor ? ".init_array" : ".fini_array", | |
16715 | priority); | |
50603eed PB |
16716 | s = get_section (buf, SECTION_WRITE, NULL_TREE); |
16717 | } | |
9f296620 | 16718 | else if (is_ctor) |
50603eed | 16719 | s = ctors_section; |
9f296620 MM |
16720 | else |
16721 | s = dtors_section; | |
50603eed PB |
16722 | |
16723 | switch_to_section (s); | |
7abc66b1 JB |
16724 | assemble_align (POINTER_SIZE); |
16725 | fputs ("\t.word\t", asm_out_file); | |
16726 | output_addr_const (asm_out_file, symbol); | |
16727 | fputs ("(target1)\n", asm_out_file); | |
16728 | } | |
9f296620 MM |
16729 | |
16730 | /* Add a function to the list of static constructors. */ | |
16731 | ||
16732 | static void | |
16733 | arm_elf_asm_constructor (rtx symbol, int priority) | |
16734 | { | |
16735 | arm_elf_asm_cdtor (symbol, priority, /*is_ctor=*/true); | |
16736 | } | |
16737 | ||
16738 | /* Add a function to the list of static destructors. */ | |
16739 | ||
16740 | static void | |
16741 | arm_elf_asm_destructor (rtx symbol, int priority) | |
16742 | { | |
16743 | arm_elf_asm_cdtor (symbol, priority, /*is_ctor=*/false); | |
16744 | } | |
301d03af | 16745 | \f |
cce8749e CH |
16746 | /* A finite state machine takes care of noticing whether or not instructions |
16747 | can be conditionally executed, and thus decrease execution time and code | |
16748 | size by deleting branch instructions. The fsm is controlled by | |
16749 | final_prescan_insn, and controls the actions of ASM_OUTPUT_OPCODE. */ | |
16750 | ||
16751 | /* The state of the fsm controlling condition codes are: | |
16752 | 0: normal, do nothing special | |
16753 | 1: make ASM_OUTPUT_OPCODE not output this instruction | |
16754 | 2: make ASM_OUTPUT_OPCODE not output this instruction | |
16755 | 3: make instructions conditional | |
16756 | 4: make instructions conditional | |
16757 | ||
16758 | State transitions (state->state by whom under condition): | |
16759 | 0 -> 1 final_prescan_insn if the `target' is a label | |
16760 | 0 -> 2 final_prescan_insn if the `target' is an unconditional branch | |
16761 | 1 -> 3 ASM_OUTPUT_OPCODE after not having output the conditional branch | |
16762 | 2 -> 4 ASM_OUTPUT_OPCODE after not having output the conditional branch | |
4977bab6 | 16763 | 3 -> 0 (*targetm.asm_out.internal_label) if the `target' label is reached |
cce8749e CH |
16764 | (the target label has CODE_LABEL_NUMBER equal to arm_target_label). |
16765 | 4 -> 0 final_prescan_insn if the `target' unconditional branch is reached | |
16766 | (the target insn is arm_target_insn). | |
16767 | ||
ff9940b0 RE |
16768 | If the jump clobbers the conditions then we use states 2 and 4. |
16769 | ||
16770 | A similar thing can be done with conditional return insns. | |
16771 | ||
cce8749e CH |
16772 | XXX In case the `target' is an unconditional branch, this conditionalising |
16773 | of the instructions always reduces code size, but not always execution | |
16774 | time. But then, I want to reduce the code size to somewhere near what | |
16775 | /bin/cc produces. */ | |
16776 | ||
5b3e6663 PB |
16777 | /* In addition to this, state is maintained for Thumb-2 COND_EXEC |
16778 | instructions. When a COND_EXEC instruction is seen the subsequent | |
16779 | instructions are scanned so that multiple conditional instructions can be | |
16780 | combined into a single IT block. arm_condexec_count and arm_condexec_mask | |
16781 | specify the length and true/false mask for the IT block. These will be | |
16782 | decremented/zeroed by arm_asm_output_opcode as the insns are output. */ | |
16783 | ||
cce8749e CH |
16784 | /* Returns the index of the ARM condition code string in |
16785 | `arm_condition_codes'. COMPARISON should be an rtx like | |
16786 | `(eq (...) (...))'. */ | |
84ed5e79 | 16787 | static enum arm_cond_code |
e32bac5b | 16788 | get_arm_condition_code (rtx comparison) |
cce8749e | 16789 | { |
5165176d | 16790 | enum machine_mode mode = GET_MODE (XEXP (comparison, 0)); |
81f40b79 | 16791 | enum arm_cond_code code; |
1d6e90ac | 16792 | enum rtx_code comp_code = GET_CODE (comparison); |
5165176d RE |
16793 | |
16794 | if (GET_MODE_CLASS (mode) != MODE_CC) | |
84ed5e79 | 16795 | mode = SELECT_CC_MODE (comp_code, XEXP (comparison, 0), |
5165176d RE |
16796 | XEXP (comparison, 1)); |
16797 | ||
16798 | switch (mode) | |
cce8749e | 16799 | { |
84ed5e79 RE |
16800 | case CC_DNEmode: code = ARM_NE; goto dominance; |
16801 | case CC_DEQmode: code = ARM_EQ; goto dominance; | |
16802 | case CC_DGEmode: code = ARM_GE; goto dominance; | |
16803 | case CC_DGTmode: code = ARM_GT; goto dominance; | |
16804 | case CC_DLEmode: code = ARM_LE; goto dominance; | |
16805 | case CC_DLTmode: code = ARM_LT; goto dominance; | |
16806 | case CC_DGEUmode: code = ARM_CS; goto dominance; | |
16807 | case CC_DGTUmode: code = ARM_HI; goto dominance; | |
16808 | case CC_DLEUmode: code = ARM_LS; goto dominance; | |
16809 | case CC_DLTUmode: code = ARM_CC; | |
16810 | ||
16811 | dominance: | |
e6d29d15 | 16812 | gcc_assert (comp_code == EQ || comp_code == NE); |
84ed5e79 RE |
16813 | |
16814 | if (comp_code == EQ) | |
16815 | return ARM_INVERSE_CONDITION_CODE (code); | |
16816 | return code; | |
16817 | ||
5165176d | 16818 | case CC_NOOVmode: |
84ed5e79 | 16819 | switch (comp_code) |
5165176d | 16820 | { |
84ed5e79 RE |
16821 | case NE: return ARM_NE; |
16822 | case EQ: return ARM_EQ; | |
16823 | case GE: return ARM_PL; | |
16824 | case LT: return ARM_MI; | |
e6d29d15 | 16825 | default: gcc_unreachable (); |
5165176d RE |
16826 | } |
16827 | ||
16828 | case CC_Zmode: | |
84ed5e79 | 16829 | switch (comp_code) |
5165176d | 16830 | { |
84ed5e79 RE |
16831 | case NE: return ARM_NE; |
16832 | case EQ: return ARM_EQ; | |
e6d29d15 | 16833 | default: gcc_unreachable (); |
5165176d RE |
16834 | } |
16835 | ||
defc0463 RE |
16836 | case CC_Nmode: |
16837 | switch (comp_code) | |
16838 | { | |
16839 | case NE: return ARM_MI; | |
16840 | case EQ: return ARM_PL; | |
e6d29d15 | 16841 | default: gcc_unreachable (); |
defc0463 RE |
16842 | } |
16843 | ||
5165176d | 16844 | case CCFPEmode: |
e45b72c4 RE |
16845 | case CCFPmode: |
16846 | /* These encodings assume that AC=1 in the FPA system control | |
16847 | byte. This allows us to handle all cases except UNEQ and | |
16848 | LTGT. */ | |
84ed5e79 RE |
16849 | switch (comp_code) |
16850 | { | |
16851 | case GE: return ARM_GE; | |
16852 | case GT: return ARM_GT; | |
16853 | case LE: return ARM_LS; | |
16854 | case LT: return ARM_MI; | |
e45b72c4 RE |
16855 | case NE: return ARM_NE; |
16856 | case EQ: return ARM_EQ; | |
16857 | case ORDERED: return ARM_VC; | |
16858 | case UNORDERED: return ARM_VS; | |
16859 | case UNLT: return ARM_LT; | |
16860 | case UNLE: return ARM_LE; | |
16861 | case UNGT: return ARM_HI; | |
16862 | case UNGE: return ARM_PL; | |
16863 | /* UNEQ and LTGT do not have a representation. */ | |
16864 | case UNEQ: /* Fall through. */ | |
16865 | case LTGT: /* Fall through. */ | |
e6d29d15 | 16866 | default: gcc_unreachable (); |
84ed5e79 RE |
16867 | } |
16868 | ||
16869 | case CC_SWPmode: | |
16870 | switch (comp_code) | |
16871 | { | |
16872 | case NE: return ARM_NE; | |
16873 | case EQ: return ARM_EQ; | |
16874 | case GE: return ARM_LE; | |
16875 | case GT: return ARM_LT; | |
16876 | case LE: return ARM_GE; | |
16877 | case LT: return ARM_GT; | |
16878 | case GEU: return ARM_LS; | |
16879 | case GTU: return ARM_CC; | |
16880 | case LEU: return ARM_CS; | |
16881 | case LTU: return ARM_HI; | |
e6d29d15 | 16882 | default: gcc_unreachable (); |
84ed5e79 RE |
16883 | } |
16884 | ||
bd9c7e23 RE |
16885 | case CC_Cmode: |
16886 | switch (comp_code) | |
18e8200f BS |
16887 | { |
16888 | case LTU: return ARM_CS; | |
16889 | case GEU: return ARM_CC; | |
16890 | default: gcc_unreachable (); | |
16891 | } | |
16892 | ||
73160ba9 DJ |
16893 | case CC_CZmode: |
16894 | switch (comp_code) | |
16895 | { | |
16896 | case NE: return ARM_NE; | |
16897 | case EQ: return ARM_EQ; | |
16898 | case GEU: return ARM_CS; | |
16899 | case GTU: return ARM_HI; | |
16900 | case LEU: return ARM_LS; | |
16901 | case LTU: return ARM_CC; | |
16902 | default: gcc_unreachable (); | |
16903 | } | |
16904 | ||
16905 | case CC_NCVmode: | |
16906 | switch (comp_code) | |
16907 | { | |
16908 | case GE: return ARM_GE; | |
16909 | case LT: return ARM_LT; | |
16910 | case GEU: return ARM_CS; | |
16911 | case LTU: return ARM_CC; | |
16912 | default: gcc_unreachable (); | |
16913 | } | |
16914 | ||
5165176d | 16915 | case CCmode: |
84ed5e79 | 16916 | switch (comp_code) |
5165176d | 16917 | { |
84ed5e79 RE |
16918 | case NE: return ARM_NE; |
16919 | case EQ: return ARM_EQ; | |
16920 | case GE: return ARM_GE; | |
16921 | case GT: return ARM_GT; | |
16922 | case LE: return ARM_LE; | |
16923 | case LT: return ARM_LT; | |
16924 | case GEU: return ARM_CS; | |
16925 | case GTU: return ARM_HI; | |
16926 | case LEU: return ARM_LS; | |
16927 | case LTU: return ARM_CC; | |
e6d29d15 | 16928 | default: gcc_unreachable (); |
5165176d RE |
16929 | } |
16930 | ||
e6d29d15 | 16931 | default: gcc_unreachable (); |
cce8749e | 16932 | } |
f3bb6135 | 16933 | } |
cce8749e | 16934 | |
44c7bd63 | 16935 | /* Tell arm_asm_output_opcode to output IT blocks for conditionally executed |
5b3e6663 PB |
16936 | instructions. */ |
16937 | void | |
16938 | thumb2_final_prescan_insn (rtx insn) | |
16939 | { | |
16940 | rtx first_insn = insn; | |
16941 | rtx body = PATTERN (insn); | |
16942 | rtx predicate; | |
16943 | enum arm_cond_code code; | |
16944 | int n; | |
16945 | int mask; | |
16946 | ||
16947 | /* Remove the previous insn from the count of insns to be output. */ | |
16948 | if (arm_condexec_count) | |
16949 | arm_condexec_count--; | |
16950 | ||
16951 | /* Nothing to do if we are already inside a conditional block. */ | |
16952 | if (arm_condexec_count) | |
16953 | return; | |
16954 | ||
16955 | if (GET_CODE (body) != COND_EXEC) | |
16956 | return; | |
16957 | ||
16958 | /* Conditional jumps are implemented directly. */ | |
16959 | if (GET_CODE (insn) == JUMP_INSN) | |
16960 | return; | |
16961 | ||
16962 | predicate = COND_EXEC_TEST (body); | |
16963 | arm_current_cc = get_arm_condition_code (predicate); | |
16964 | ||
16965 | n = get_attr_ce_count (insn); | |
16966 | arm_condexec_count = 1; | |
16967 | arm_condexec_mask = (1 << n) - 1; | |
16968 | arm_condexec_masklen = n; | |
16969 | /* See if subsequent instructions can be combined into the same block. */ | |
16970 | for (;;) | |
16971 | { | |
16972 | insn = next_nonnote_insn (insn); | |
16973 | ||
16974 | /* Jumping into the middle of an IT block is illegal, so a label or | |
16975 | barrier terminates the block. */ | |
16976 | if (GET_CODE (insn) != INSN && GET_CODE(insn) != JUMP_INSN) | |
16977 | break; | |
16978 | ||
16979 | body = PATTERN (insn); | |
16980 | /* USE and CLOBBER aren't really insns, so just skip them. */ | |
16981 | if (GET_CODE (body) == USE | |
16982 | || GET_CODE (body) == CLOBBER) | |
5b0202af | 16983 | continue; |
5b3e6663 | 16984 | |
7a085dce | 16985 | /* ??? Recognize conditional jumps, and combine them with IT blocks. */ |
5b3e6663 PB |
16986 | if (GET_CODE (body) != COND_EXEC) |
16987 | break; | |
16988 | /* Allow up to 4 conditionally executed instructions in a block. */ | |
16989 | n = get_attr_ce_count (insn); | |
16990 | if (arm_condexec_masklen + n > 4) | |
16991 | break; | |
16992 | ||
16993 | predicate = COND_EXEC_TEST (body); | |
16994 | code = get_arm_condition_code (predicate); | |
16995 | mask = (1 << n) - 1; | |
16996 | if (arm_current_cc == code) | |
16997 | arm_condexec_mask |= (mask << arm_condexec_masklen); | |
16998 | else if (arm_current_cc != ARM_INVERSE_CONDITION_CODE(code)) | |
16999 | break; | |
17000 | ||
17001 | arm_condexec_count++; | |
17002 | arm_condexec_masklen += n; | |
17003 | ||
17004 | /* A jump must be the last instruction in a conditional block. */ | |
17005 | if (GET_CODE(insn) == JUMP_INSN) | |
17006 | break; | |
17007 | } | |
17008 | /* Restore recog_data (getting the attributes of other insns can | |
17009 | destroy this array, but final.c assumes that it remains intact | |
17010 | across this call). */ | |
17011 | extract_constrain_insn_cached (first_insn); | |
17012 | } | |
17013 | ||
cce8749e | 17014 | void |
e32bac5b | 17015 | arm_final_prescan_insn (rtx insn) |
cce8749e CH |
17016 | { |
17017 | /* BODY will hold the body of INSN. */ | |
1d6e90ac | 17018 | rtx body = PATTERN (insn); |
cce8749e CH |
17019 | |
17020 | /* This will be 1 if trying to repeat the trick, and things need to be | |
17021 | reversed if it appears to fail. */ | |
17022 | int reverse = 0; | |
17023 | ||
6354dc9b | 17024 | /* If we start with a return insn, we only succeed if we find another one. */ |
ff9940b0 | 17025 | int seeking_return = 0; |
f676971a | 17026 | |
cce8749e CH |
17027 | /* START_INSN will hold the insn from where we start looking. This is the |
17028 | first insn after the following code_label if REVERSE is true. */ | |
17029 | rtx start_insn = insn; | |
17030 | ||
17031 | /* If in state 4, check if the target branch is reached, in order to | |
17032 | change back to state 0. */ | |
17033 | if (arm_ccfsm_state == 4) | |
17034 | { | |
17035 | if (insn == arm_target_insn) | |
f5a1b0d2 NC |
17036 | { |
17037 | arm_target_insn = NULL; | |
17038 | arm_ccfsm_state = 0; | |
17039 | } | |
cce8749e CH |
17040 | return; |
17041 | } | |
17042 | ||
17043 | /* If in state 3, it is possible to repeat the trick, if this insn is an | |
17044 | unconditional branch to a label, and immediately following this branch | |
17045 | is the previous target label which is only used once, and the label this | |
17046 | branch jumps to is not too far off. */ | |
17047 | if (arm_ccfsm_state == 3) | |
17048 | { | |
17049 | if (simplejump_p (insn)) | |
17050 | { | |
17051 | start_insn = next_nonnote_insn (start_insn); | |
17052 | if (GET_CODE (start_insn) == BARRIER) | |
17053 | { | |
17054 | /* XXX Isn't this always a barrier? */ | |
17055 | start_insn = next_nonnote_insn (start_insn); | |
17056 | } | |
17057 | if (GET_CODE (start_insn) == CODE_LABEL | |
17058 | && CODE_LABEL_NUMBER (start_insn) == arm_target_label | |
17059 | && LABEL_NUSES (start_insn) == 1) | |
17060 | reverse = TRUE; | |
17061 | else | |
17062 | return; | |
17063 | } | |
ff9940b0 RE |
17064 | else if (GET_CODE (body) == RETURN) |
17065 | { | |
17066 | start_insn = next_nonnote_insn (start_insn); | |
17067 | if (GET_CODE (start_insn) == BARRIER) | |
17068 | start_insn = next_nonnote_insn (start_insn); | |
17069 | if (GET_CODE (start_insn) == CODE_LABEL | |
17070 | && CODE_LABEL_NUMBER (start_insn) == arm_target_label | |
17071 | && LABEL_NUSES (start_insn) == 1) | |
17072 | { | |
17073 | reverse = TRUE; | |
17074 | seeking_return = 1; | |
17075 | } | |
17076 | else | |
17077 | return; | |
17078 | } | |
cce8749e CH |
17079 | else |
17080 | return; | |
17081 | } | |
17082 | ||
e6d29d15 | 17083 | gcc_assert (!arm_ccfsm_state || reverse); |
cce8749e CH |
17084 | if (GET_CODE (insn) != JUMP_INSN) |
17085 | return; | |
17086 | ||
f676971a | 17087 | /* This jump might be paralleled with a clobber of the condition codes |
ff9940b0 RE |
17088 | the jump should always come first */ |
17089 | if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0) | |
17090 | body = XVECEXP (body, 0, 0); | |
17091 | ||
cce8749e CH |
17092 | if (reverse |
17093 | || (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC | |
17094 | && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE)) | |
17095 | { | |
bd9c7e23 RE |
17096 | int insns_skipped; |
17097 | int fail = FALSE, succeed = FALSE; | |
cce8749e CH |
17098 | /* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */ |
17099 | int then_not_else = TRUE; | |
ff9940b0 | 17100 | rtx this_insn = start_insn, label = 0; |
cce8749e CH |
17101 | |
17102 | /* Register the insn jumped to. */ | |
17103 | if (reverse) | |
ff9940b0 RE |
17104 | { |
17105 | if (!seeking_return) | |
17106 | label = XEXP (SET_SRC (body), 0); | |
17107 | } | |
cce8749e CH |
17108 | else if (GET_CODE (XEXP (SET_SRC (body), 1)) == LABEL_REF) |
17109 | label = XEXP (XEXP (SET_SRC (body), 1), 0); | |
17110 | else if (GET_CODE (XEXP (SET_SRC (body), 2)) == LABEL_REF) | |
17111 | { | |
17112 | label = XEXP (XEXP (SET_SRC (body), 2), 0); | |
17113 | then_not_else = FALSE; | |
17114 | } | |
ff9940b0 RE |
17115 | else if (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN) |
17116 | seeking_return = 1; | |
17117 | else if (GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN) | |
17118 | { | |
17119 | seeking_return = 1; | |
17120 | then_not_else = FALSE; | |
17121 | } | |
cce8749e | 17122 | else |
e6d29d15 | 17123 | gcc_unreachable (); |
cce8749e CH |
17124 | |
17125 | /* See how many insns this branch skips, and what kind of insns. If all | |
17126 | insns are okay, and the label or unconditional branch to the same | |
17127 | label is not too far away, succeed. */ | |
17128 | for (insns_skipped = 0; | |
b36ba79f | 17129 | !fail && !succeed && insns_skipped++ < max_insns_skipped;) |
cce8749e CH |
17130 | { |
17131 | rtx scanbody; | |
17132 | ||
17133 | this_insn = next_nonnote_insn (this_insn); | |
17134 | if (!this_insn) | |
17135 | break; | |
17136 | ||
cce8749e CH |
17137 | switch (GET_CODE (this_insn)) |
17138 | { | |
17139 | case CODE_LABEL: | |
17140 | /* Succeed if it is the target label, otherwise fail since | |
17141 | control falls in from somewhere else. */ | |
17142 | if (this_insn == label) | |
17143 | { | |
accbd151 | 17144 | arm_ccfsm_state = 1; |
cce8749e CH |
17145 | succeed = TRUE; |
17146 | } | |
17147 | else | |
17148 | fail = TRUE; | |
17149 | break; | |
17150 | ||
ff9940b0 | 17151 | case BARRIER: |
cce8749e | 17152 | /* Succeed if the following insn is the target label. |
f676971a EC |
17153 | Otherwise fail. |
17154 | If return insns are used then the last insn in a function | |
6354dc9b | 17155 | will be a barrier. */ |
cce8749e | 17156 | this_insn = next_nonnote_insn (this_insn); |
ff9940b0 | 17157 | if (this_insn && this_insn == label) |
cce8749e | 17158 | { |
accbd151 | 17159 | arm_ccfsm_state = 1; |
cce8749e CH |
17160 | succeed = TRUE; |
17161 | } | |
17162 | else | |
17163 | fail = TRUE; | |
17164 | break; | |
17165 | ||
ff9940b0 | 17166 | case CALL_INSN: |
68d560d4 RE |
17167 | /* The AAPCS says that conditional calls should not be |
17168 | used since they make interworking inefficient (the | |
17169 | linker can't transform BL<cond> into BLX). That's | |
17170 | only a problem if the machine has BLX. */ | |
17171 | if (arm_arch5) | |
17172 | { | |
17173 | fail = TRUE; | |
17174 | break; | |
17175 | } | |
17176 | ||
61f0ccff RE |
17177 | /* Succeed if the following insn is the target label, or |
17178 | if the following two insns are a barrier and the | |
17179 | target label. */ | |
17180 | this_insn = next_nonnote_insn (this_insn); | |
17181 | if (this_insn && GET_CODE (this_insn) == BARRIER) | |
17182 | this_insn = next_nonnote_insn (this_insn); | |
bd9c7e23 | 17183 | |
61f0ccff RE |
17184 | if (this_insn && this_insn == label |
17185 | && insns_skipped < max_insns_skipped) | |
17186 | { | |
accbd151 | 17187 | arm_ccfsm_state = 1; |
61f0ccff | 17188 | succeed = TRUE; |
bd9c7e23 | 17189 | } |
61f0ccff RE |
17190 | else |
17191 | fail = TRUE; | |
ff9940b0 | 17192 | break; |
2b835d68 | 17193 | |
cce8749e CH |
17194 | case JUMP_INSN: |
17195 | /* If this is an unconditional branch to the same label, succeed. | |
17196 | If it is to another label, do nothing. If it is conditional, | |
17197 | fail. */ | |
e32bac5b RE |
17198 | /* XXX Probably, the tests for SET and the PC are |
17199 | unnecessary. */ | |
cce8749e | 17200 | |
ed4c4348 | 17201 | scanbody = PATTERN (this_insn); |
ff9940b0 RE |
17202 | if (GET_CODE (scanbody) == SET |
17203 | && GET_CODE (SET_DEST (scanbody)) == PC) | |
cce8749e CH |
17204 | { |
17205 | if (GET_CODE (SET_SRC (scanbody)) == LABEL_REF | |
17206 | && XEXP (SET_SRC (scanbody), 0) == label && !reverse) | |
17207 | { | |
17208 | arm_ccfsm_state = 2; | |
17209 | succeed = TRUE; | |
17210 | } | |
17211 | else if (GET_CODE (SET_SRC (scanbody)) == IF_THEN_ELSE) | |
17212 | fail = TRUE; | |
17213 | } | |
112cdef5 | 17214 | /* Fail if a conditional return is undesirable (e.g. on a |
b36ba79f RE |
17215 | StrongARM), but still allow this if optimizing for size. */ |
17216 | else if (GET_CODE (scanbody) == RETURN | |
a72d4945 | 17217 | && !use_return_insn (TRUE, NULL) |
5895f793 | 17218 | && !optimize_size) |
b36ba79f | 17219 | fail = TRUE; |
ff9940b0 RE |
17220 | else if (GET_CODE (scanbody) == RETURN |
17221 | && seeking_return) | |
17222 | { | |
17223 | arm_ccfsm_state = 2; | |
17224 | succeed = TRUE; | |
17225 | } | |
17226 | else if (GET_CODE (scanbody) == PARALLEL) | |
17227 | { | |
17228 | switch (get_attr_conds (this_insn)) | |
17229 | { | |
17230 | case CONDS_NOCOND: | |
17231 | break; | |
17232 | default: | |
17233 | fail = TRUE; | |
17234 | break; | |
17235 | } | |
17236 | } | |
4e67550b | 17237 | else |
112cdef5 | 17238 | fail = TRUE; /* Unrecognized jump (e.g. epilogue). */ |
4e67550b | 17239 | |
cce8749e CH |
17240 | break; |
17241 | ||
17242 | case INSN: | |
ff9940b0 RE |
17243 | /* Instructions using or affecting the condition codes make it |
17244 | fail. */ | |
ed4c4348 | 17245 | scanbody = PATTERN (this_insn); |
5895f793 RE |
17246 | if (!(GET_CODE (scanbody) == SET |
17247 | || GET_CODE (scanbody) == PARALLEL) | |
74641843 | 17248 | || get_attr_conds (this_insn) != CONDS_NOCOND) |
cce8749e | 17249 | fail = TRUE; |
9b6b54e2 NC |
17250 | |
17251 | /* A conditional cirrus instruction must be followed by | |
17252 | a non Cirrus instruction. However, since we | |
17253 | conditionalize instructions in this function and by | |
17254 | the time we get here we can't add instructions | |
17255 | (nops), because shorten_branches() has already been | |
17256 | called, we will disable conditionalizing Cirrus | |
17257 | instructions to be safe. */ | |
17258 | if (GET_CODE (scanbody) != USE | |
17259 | && GET_CODE (scanbody) != CLOBBER | |
f0375c66 | 17260 | && get_attr_cirrus (this_insn) != CIRRUS_NOT) |
9b6b54e2 | 17261 | fail = TRUE; |
cce8749e CH |
17262 | break; |
17263 | ||
17264 | default: | |
17265 | break; | |
17266 | } | |
17267 | } | |
17268 | if (succeed) | |
17269 | { | |
ff9940b0 | 17270 | if ((!seeking_return) && (arm_ccfsm_state == 1 || reverse)) |
cce8749e | 17271 | arm_target_label = CODE_LABEL_NUMBER (label); |
e6d29d15 | 17272 | else |
ff9940b0 | 17273 | { |
e6d29d15 | 17274 | gcc_assert (seeking_return || arm_ccfsm_state == 2); |
e0b92319 | 17275 | |
ff9940b0 RE |
17276 | while (this_insn && GET_CODE (PATTERN (this_insn)) == USE) |
17277 | { | |
17278 | this_insn = next_nonnote_insn (this_insn); | |
e6d29d15 NS |
17279 | gcc_assert (!this_insn |
17280 | || (GET_CODE (this_insn) != BARRIER | |
17281 | && GET_CODE (this_insn) != CODE_LABEL)); | |
ff9940b0 RE |
17282 | } |
17283 | if (!this_insn) | |
17284 | { | |
d6b4baa4 | 17285 | /* Oh, dear! we ran off the end.. give up. */ |
5b3e6663 | 17286 | extract_constrain_insn_cached (insn); |
ff9940b0 | 17287 | arm_ccfsm_state = 0; |
abaa26e5 | 17288 | arm_target_insn = NULL; |
ff9940b0 RE |
17289 | return; |
17290 | } | |
17291 | arm_target_insn = this_insn; | |
17292 | } | |
accbd151 PB |
17293 | |
17294 | /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from | |
17295 | what it was. */ | |
17296 | if (!reverse) | |
17297 | arm_current_cc = get_arm_condition_code (XEXP (SET_SRC (body), 0)); | |
cce8749e | 17298 | |
cce8749e CH |
17299 | if (reverse || then_not_else) |
17300 | arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc); | |
17301 | } | |
f676971a | 17302 | |
1ccbefce | 17303 | /* Restore recog_data (getting the attributes of other insns can |
ff9940b0 | 17304 | destroy this array, but final.c assumes that it remains intact |
5b3e6663 PB |
17305 | across this call. */ |
17306 | extract_constrain_insn_cached (insn); | |
17307 | } | |
17308 | } | |
17309 | ||
17310 | /* Output IT instructions. */ | |
17311 | void | |
17312 | thumb2_asm_output_opcode (FILE * stream) | |
17313 | { | |
17314 | char buff[5]; | |
17315 | int n; | |
17316 | ||
17317 | if (arm_condexec_mask) | |
17318 | { | |
17319 | for (n = 0; n < arm_condexec_masklen; n++) | |
17320 | buff[n] = (arm_condexec_mask & (1 << n)) ? 't' : 'e'; | |
17321 | buff[n] = 0; | |
17322 | asm_fprintf(stream, "i%s\t%s\n\t", buff, | |
17323 | arm_condition_codes[arm_current_cc]); | |
17324 | arm_condexec_mask = 0; | |
cce8749e | 17325 | } |
f3bb6135 | 17326 | } |
cce8749e | 17327 | |
4b02997f | 17328 | /* Returns true if REGNO is a valid register |
21b5653c | 17329 | for holding a quantity of type MODE. */ |
4b02997f | 17330 | int |
e32bac5b | 17331 | arm_hard_regno_mode_ok (unsigned int regno, enum machine_mode mode) |
4b02997f NC |
17332 | { |
17333 | if (GET_MODE_CLASS (mode) == MODE_CC) | |
a6a5de04 RE |
17334 | return (regno == CC_REGNUM |
17335 | || (TARGET_HARD_FLOAT && TARGET_VFP | |
17336 | && regno == VFPCC_REGNUM)); | |
f676971a | 17337 | |
5b3e6663 | 17338 | if (TARGET_THUMB1) |
4b02997f NC |
17339 | /* For the Thumb we only allow values bigger than SImode in |
17340 | registers 0 - 6, so that there is always a second low | |
17341 | register available to hold the upper part of the value. | |
17342 | We probably we ought to ensure that the register is the | |
17343 | start of an even numbered register pair. */ | |
e9d7b180 | 17344 | return (ARM_NUM_REGS (mode) < 2) || (regno < LAST_LO_REGNUM); |
4b02997f | 17345 | |
a6a5de04 RE |
17346 | if (TARGET_HARD_FLOAT && TARGET_MAVERICK |
17347 | && IS_CIRRUS_REGNUM (regno)) | |
9b6b54e2 NC |
17348 | /* We have outlawed SI values in Cirrus registers because they |
17349 | reside in the lower 32 bits, but SF values reside in the | |
17350 | upper 32 bits. This causes gcc all sorts of grief. We can't | |
17351 | even split the registers into pairs because Cirrus SI values | |
17352 | get sign extended to 64bits-- aldyh. */ | |
17353 | return (GET_MODE_CLASS (mode) == MODE_FLOAT) || (mode == DImode); | |
17354 | ||
a6a5de04 RE |
17355 | if (TARGET_HARD_FLOAT && TARGET_VFP |
17356 | && IS_VFP_REGNUM (regno)) | |
9b66ebb1 PB |
17357 | { |
17358 | if (mode == SFmode || mode == SImode) | |
f1adb0a9 | 17359 | return VFP_REGNO_OK_FOR_SINGLE (regno); |
9b66ebb1 | 17360 | |
9b66ebb1 | 17361 | if (mode == DFmode) |
f1adb0a9 | 17362 | return VFP_REGNO_OK_FOR_DOUBLE (regno); |
88f77cba | 17363 | |
0fd8c3ad | 17364 | /* VFP registers can hold HFmode values, but there is no point in |
e0dc3601 | 17365 | putting them there unless we have hardware conversion insns. */ |
0fd8c3ad | 17366 | if (mode == HFmode) |
e0dc3601 | 17367 | return TARGET_FP16 && VFP_REGNO_OK_FOR_SINGLE (regno); |
0fd8c3ad | 17368 | |
88f77cba JB |
17369 | if (TARGET_NEON) |
17370 | return (VALID_NEON_DREG_MODE (mode) && VFP_REGNO_OK_FOR_DOUBLE (regno)) | |
17371 | || (VALID_NEON_QREG_MODE (mode) | |
17372 | && NEON_REGNO_OK_FOR_QUAD (regno)) | |
17373 | || (mode == TImode && NEON_REGNO_OK_FOR_NREGS (regno, 2)) | |
17374 | || (mode == EImode && NEON_REGNO_OK_FOR_NREGS (regno, 3)) | |
17375 | || (mode == OImode && NEON_REGNO_OK_FOR_NREGS (regno, 4)) | |
17376 | || (mode == CImode && NEON_REGNO_OK_FOR_NREGS (regno, 6)) | |
17377 | || (mode == XImode && NEON_REGNO_OK_FOR_NREGS (regno, 8)); | |
17378 | ||
9b66ebb1 PB |
17379 | return FALSE; |
17380 | } | |
17381 | ||
a6a5de04 RE |
17382 | if (TARGET_REALLY_IWMMXT) |
17383 | { | |
17384 | if (IS_IWMMXT_GR_REGNUM (regno)) | |
17385 | return mode == SImode; | |
5a9335ef | 17386 | |
a6a5de04 RE |
17387 | if (IS_IWMMXT_REGNUM (regno)) |
17388 | return VALID_IWMMXT_REG_MODE (mode); | |
17389 | } | |
17390 | ||
2e94c12d | 17391 | /* We allow almost any value to be stored in the general registers. |
fdd695fd | 17392 | Restrict doubleword quantities to even register pairs so that we can |
2e94c12d JB |
17393 | use ldrd. Do not allow very large Neon structure opaque modes in |
17394 | general registers; they would use too many. */ | |
4b02997f | 17395 | if (regno <= LAST_ARM_REGNUM) |
88f77cba | 17396 | return !(TARGET_LDRD && GET_MODE_SIZE (mode) > 4 && (regno & 1) != 0) |
2e94c12d | 17397 | && ARM_NUM_REGS (mode) <= 4; |
4b02997f | 17398 | |
a6a5de04 | 17399 | if (regno == FRAME_POINTER_REGNUM |
4b02997f NC |
17400 | || regno == ARG_POINTER_REGNUM) |
17401 | /* We only allow integers in the fake hard registers. */ | |
17402 | return GET_MODE_CLASS (mode) == MODE_INT; | |
17403 | ||
3b684012 | 17404 | /* The only registers left are the FPA registers |
4b02997f | 17405 | which we only allow to hold FP values. */ |
a6a5de04 RE |
17406 | return (TARGET_HARD_FLOAT && TARGET_FPA |
17407 | && GET_MODE_CLASS (mode) == MODE_FLOAT | |
17408 | && regno >= FIRST_FPA_REGNUM | |
17409 | && regno <= LAST_FPA_REGNUM); | |
4b02997f NC |
17410 | } |
17411 | ||
5b3e6663 PB |
17412 | /* For efficiency and historical reasons LO_REGS, HI_REGS and CC_REGS are |
17413 | not used in arm mode. */ | |
bbbbb16a ILT |
17414 | |
17415 | enum reg_class | |
e32bac5b | 17416 | arm_regno_class (int regno) |
d5b7b3ae | 17417 | { |
5b3e6663 | 17418 | if (TARGET_THUMB1) |
d5b7b3ae RE |
17419 | { |
17420 | if (regno == STACK_POINTER_REGNUM) | |
17421 | return STACK_REG; | |
17422 | if (regno == CC_REGNUM) | |
17423 | return CC_REG; | |
17424 | if (regno < 8) | |
17425 | return LO_REGS; | |
17426 | return HI_REGS; | |
17427 | } | |
17428 | ||
5b3e6663 PB |
17429 | if (TARGET_THUMB2 && regno < 8) |
17430 | return LO_REGS; | |
17431 | ||
d5b7b3ae RE |
17432 | if ( regno <= LAST_ARM_REGNUM |
17433 | || regno == FRAME_POINTER_REGNUM | |
17434 | || regno == ARG_POINTER_REGNUM) | |
5b3e6663 | 17435 | return TARGET_THUMB2 ? HI_REGS : GENERAL_REGS; |
f676971a | 17436 | |
9b66ebb1 | 17437 | if (regno == CC_REGNUM || regno == VFPCC_REGNUM) |
5b3e6663 | 17438 | return TARGET_THUMB2 ? CC_REG : NO_REGS; |
d5b7b3ae | 17439 | |
9b6b54e2 NC |
17440 | if (IS_CIRRUS_REGNUM (regno)) |
17441 | return CIRRUS_REGS; | |
17442 | ||
9b66ebb1 | 17443 | if (IS_VFP_REGNUM (regno)) |
f1adb0a9 JB |
17444 | { |
17445 | if (regno <= D7_VFP_REGNUM) | |
17446 | return VFP_D0_D7_REGS; | |
17447 | else if (regno <= LAST_LO_VFP_REGNUM) | |
17448 | return VFP_LO_REGS; | |
17449 | else | |
17450 | return VFP_HI_REGS; | |
17451 | } | |
9b66ebb1 | 17452 | |
5a9335ef NC |
17453 | if (IS_IWMMXT_REGNUM (regno)) |
17454 | return IWMMXT_REGS; | |
17455 | ||
e99faaaa ILT |
17456 | if (IS_IWMMXT_GR_REGNUM (regno)) |
17457 | return IWMMXT_GR_REGS; | |
17458 | ||
3b684012 | 17459 | return FPA_REGS; |
d5b7b3ae RE |
17460 | } |
17461 | ||
17462 | /* Handle a special case when computing the offset | |
17463 | of an argument from the frame pointer. */ | |
17464 | int | |
e32bac5b | 17465 | arm_debugger_arg_offset (int value, rtx addr) |
d5b7b3ae RE |
17466 | { |
17467 | rtx insn; | |
17468 | ||
17469 | /* We are only interested if dbxout_parms() failed to compute the offset. */ | |
17470 | if (value != 0) | |
17471 | return 0; | |
17472 | ||
17473 | /* We can only cope with the case where the address is held in a register. */ | |
17474 | if (GET_CODE (addr) != REG) | |
17475 | return 0; | |
17476 | ||
17477 | /* If we are using the frame pointer to point at the argument, then | |
17478 | an offset of 0 is correct. */ | |
cd2b33d0 | 17479 | if (REGNO (addr) == (unsigned) HARD_FRAME_POINTER_REGNUM) |
d5b7b3ae | 17480 | return 0; |
f676971a | 17481 | |
d5b7b3ae RE |
17482 | /* If we are using the stack pointer to point at the |
17483 | argument, then an offset of 0 is correct. */ | |
5b3e6663 | 17484 | /* ??? Check this is consistent with thumb2 frame layout. */ |
5895f793 | 17485 | if ((TARGET_THUMB || !frame_pointer_needed) |
d5b7b3ae RE |
17486 | && REGNO (addr) == SP_REGNUM) |
17487 | return 0; | |
f676971a | 17488 | |
d5b7b3ae RE |
17489 | /* Oh dear. The argument is pointed to by a register rather |
17490 | than being held in a register, or being stored at a known | |
17491 | offset from the frame pointer. Since GDB only understands | |
17492 | those two kinds of argument we must translate the address | |
17493 | held in the register into an offset from the frame pointer. | |
17494 | We do this by searching through the insns for the function | |
17495 | looking to see where this register gets its value. If the | |
4912a07c | 17496 | register is initialized from the frame pointer plus an offset |
d5b7b3ae | 17497 | then we are in luck and we can continue, otherwise we give up. |
f676971a | 17498 | |
d5b7b3ae RE |
17499 | This code is exercised by producing debugging information |
17500 | for a function with arguments like this: | |
f676971a | 17501 | |
d5b7b3ae | 17502 | double func (double a, double b, int c, double d) {return d;} |
f676971a | 17503 | |
d5b7b3ae RE |
17504 | Without this code the stab for parameter 'd' will be set to |
17505 | an offset of 0 from the frame pointer, rather than 8. */ | |
17506 | ||
17507 | /* The if() statement says: | |
17508 | ||
17509 | If the insn is a normal instruction | |
17510 | and if the insn is setting the value in a register | |
17511 | and if the register being set is the register holding the address of the argument | |
17512 | and if the address is computing by an addition | |
17513 | that involves adding to a register | |
17514 | which is the frame pointer | |
17515 | a constant integer | |
17516 | ||
d6b4baa4 | 17517 | then... */ |
f676971a | 17518 | |
d5b7b3ae RE |
17519 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
17520 | { | |
f676971a | 17521 | if ( GET_CODE (insn) == INSN |
d5b7b3ae RE |
17522 | && GET_CODE (PATTERN (insn)) == SET |
17523 | && REGNO (XEXP (PATTERN (insn), 0)) == REGNO (addr) | |
17524 | && GET_CODE (XEXP (PATTERN (insn), 1)) == PLUS | |
17525 | && GET_CODE (XEXP (XEXP (PATTERN (insn), 1), 0)) == REG | |
cd2b33d0 | 17526 | && REGNO (XEXP (XEXP (PATTERN (insn), 1), 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM |
d5b7b3ae RE |
17527 | && GET_CODE (XEXP (XEXP (PATTERN (insn), 1), 1)) == CONST_INT |
17528 | ) | |
17529 | { | |
17530 | value = INTVAL (XEXP (XEXP (PATTERN (insn), 1), 1)); | |
f676971a | 17531 | |
d5b7b3ae RE |
17532 | break; |
17533 | } | |
17534 | } | |
f676971a | 17535 | |
d5b7b3ae RE |
17536 | if (value == 0) |
17537 | { | |
17538 | debug_rtx (addr); | |
d4ee4d25 | 17539 | warning (0, "unable to compute real location of stacked parameter"); |
d5b7b3ae RE |
17540 | value = 8; /* XXX magic hack */ |
17541 | } | |
17542 | ||
17543 | return value; | |
17544 | } | |
d5b7b3ae | 17545 | \f |
5a9335ef NC |
17546 | #define def_mbuiltin(MASK, NAME, TYPE, CODE) \ |
17547 | do \ | |
17548 | { \ | |
17549 | if ((MASK) & insn_flags) \ | |
c79efc4d RÁE |
17550 | add_builtin_function ((NAME), (TYPE), (CODE), \ |
17551 | BUILT_IN_MD, NULL, NULL_TREE); \ | |
5a9335ef NC |
17552 | } \ |
17553 | while (0) | |
17554 | ||
17555 | struct builtin_description | |
17556 | { | |
17557 | const unsigned int mask; | |
17558 | const enum insn_code icode; | |
17559 | const char * const name; | |
17560 | const enum arm_builtins code; | |
17561 | const enum rtx_code comparison; | |
17562 | const unsigned int flag; | |
17563 | }; | |
17564 | ||
17565 | static const struct builtin_description bdesc_2arg[] = | |
17566 | { | |
17567 | #define IWMMXT_BUILTIN(code, string, builtin) \ | |
17568 | { FL_IWMMXT, CODE_FOR_##code, "__builtin_arm_" string, \ | |
81f40b79 | 17569 | ARM_BUILTIN_##builtin, UNKNOWN, 0 }, |
5a9335ef NC |
17570 | |
17571 | IWMMXT_BUILTIN (addv8qi3, "waddb", WADDB) | |
17572 | IWMMXT_BUILTIN (addv4hi3, "waddh", WADDH) | |
17573 | IWMMXT_BUILTIN (addv2si3, "waddw", WADDW) | |
17574 | IWMMXT_BUILTIN (subv8qi3, "wsubb", WSUBB) | |
17575 | IWMMXT_BUILTIN (subv4hi3, "wsubh", WSUBH) | |
17576 | IWMMXT_BUILTIN (subv2si3, "wsubw", WSUBW) | |
17577 | IWMMXT_BUILTIN (ssaddv8qi3, "waddbss", WADDSSB) | |
17578 | IWMMXT_BUILTIN (ssaddv4hi3, "waddhss", WADDSSH) | |
17579 | IWMMXT_BUILTIN (ssaddv2si3, "waddwss", WADDSSW) | |
17580 | IWMMXT_BUILTIN (sssubv8qi3, "wsubbss", WSUBSSB) | |
17581 | IWMMXT_BUILTIN (sssubv4hi3, "wsubhss", WSUBSSH) | |
17582 | IWMMXT_BUILTIN (sssubv2si3, "wsubwss", WSUBSSW) | |
17583 | IWMMXT_BUILTIN (usaddv8qi3, "waddbus", WADDUSB) | |
17584 | IWMMXT_BUILTIN (usaddv4hi3, "waddhus", WADDUSH) | |
17585 | IWMMXT_BUILTIN (usaddv2si3, "waddwus", WADDUSW) | |
17586 | IWMMXT_BUILTIN (ussubv8qi3, "wsubbus", WSUBUSB) | |
17587 | IWMMXT_BUILTIN (ussubv4hi3, "wsubhus", WSUBUSH) | |
17588 | IWMMXT_BUILTIN (ussubv2si3, "wsubwus", WSUBUSW) | |
17589 | IWMMXT_BUILTIN (mulv4hi3, "wmulul", WMULUL) | |
f07a6b21 BE |
17590 | IWMMXT_BUILTIN (smulv4hi3_highpart, "wmulsm", WMULSM) |
17591 | IWMMXT_BUILTIN (umulv4hi3_highpart, "wmulum", WMULUM) | |
5a9335ef NC |
17592 | IWMMXT_BUILTIN (eqv8qi3, "wcmpeqb", WCMPEQB) |
17593 | IWMMXT_BUILTIN (eqv4hi3, "wcmpeqh", WCMPEQH) | |
17594 | IWMMXT_BUILTIN (eqv2si3, "wcmpeqw", WCMPEQW) | |
17595 | IWMMXT_BUILTIN (gtuv8qi3, "wcmpgtub", WCMPGTUB) | |
17596 | IWMMXT_BUILTIN (gtuv4hi3, "wcmpgtuh", WCMPGTUH) | |
17597 | IWMMXT_BUILTIN (gtuv2si3, "wcmpgtuw", WCMPGTUW) | |
17598 | IWMMXT_BUILTIN (gtv8qi3, "wcmpgtsb", WCMPGTSB) | |
17599 | IWMMXT_BUILTIN (gtv4hi3, "wcmpgtsh", WCMPGTSH) | |
17600 | IWMMXT_BUILTIN (gtv2si3, "wcmpgtsw", WCMPGTSW) | |
17601 | IWMMXT_BUILTIN (umaxv8qi3, "wmaxub", WMAXUB) | |
17602 | IWMMXT_BUILTIN (smaxv8qi3, "wmaxsb", WMAXSB) | |
17603 | IWMMXT_BUILTIN (umaxv4hi3, "wmaxuh", WMAXUH) | |
17604 | IWMMXT_BUILTIN (smaxv4hi3, "wmaxsh", WMAXSH) | |
17605 | IWMMXT_BUILTIN (umaxv2si3, "wmaxuw", WMAXUW) | |
17606 | IWMMXT_BUILTIN (smaxv2si3, "wmaxsw", WMAXSW) | |
17607 | IWMMXT_BUILTIN (uminv8qi3, "wminub", WMINUB) | |
17608 | IWMMXT_BUILTIN (sminv8qi3, "wminsb", WMINSB) | |
17609 | IWMMXT_BUILTIN (uminv4hi3, "wminuh", WMINUH) | |
17610 | IWMMXT_BUILTIN (sminv4hi3, "wminsh", WMINSH) | |
17611 | IWMMXT_BUILTIN (uminv2si3, "wminuw", WMINUW) | |
17612 | IWMMXT_BUILTIN (sminv2si3, "wminsw", WMINSW) | |
17613 | IWMMXT_BUILTIN (iwmmxt_anddi3, "wand", WAND) | |
17614 | IWMMXT_BUILTIN (iwmmxt_nanddi3, "wandn", WANDN) | |
17615 | IWMMXT_BUILTIN (iwmmxt_iordi3, "wor", WOR) | |
17616 | IWMMXT_BUILTIN (iwmmxt_xordi3, "wxor", WXOR) | |
17617 | IWMMXT_BUILTIN (iwmmxt_uavgv8qi3, "wavg2b", WAVG2B) | |
17618 | IWMMXT_BUILTIN (iwmmxt_uavgv4hi3, "wavg2h", WAVG2H) | |
17619 | IWMMXT_BUILTIN (iwmmxt_uavgrndv8qi3, "wavg2br", WAVG2BR) | |
17620 | IWMMXT_BUILTIN (iwmmxt_uavgrndv4hi3, "wavg2hr", WAVG2HR) | |
17621 | IWMMXT_BUILTIN (iwmmxt_wunpckilb, "wunpckilb", WUNPCKILB) | |
17622 | IWMMXT_BUILTIN (iwmmxt_wunpckilh, "wunpckilh", WUNPCKILH) | |
17623 | IWMMXT_BUILTIN (iwmmxt_wunpckilw, "wunpckilw", WUNPCKILW) | |
17624 | IWMMXT_BUILTIN (iwmmxt_wunpckihb, "wunpckihb", WUNPCKIHB) | |
17625 | IWMMXT_BUILTIN (iwmmxt_wunpckihh, "wunpckihh", WUNPCKIHH) | |
17626 | IWMMXT_BUILTIN (iwmmxt_wunpckihw, "wunpckihw", WUNPCKIHW) | |
17627 | IWMMXT_BUILTIN (iwmmxt_wmadds, "wmadds", WMADDS) | |
17628 | IWMMXT_BUILTIN (iwmmxt_wmaddu, "wmaddu", WMADDU) | |
17629 | ||
17630 | #define IWMMXT_BUILTIN2(code, builtin) \ | |
81f40b79 | 17631 | { FL_IWMMXT, CODE_FOR_##code, NULL, ARM_BUILTIN_##builtin, UNKNOWN, 0 }, |
f676971a | 17632 | |
5a9335ef NC |
17633 | IWMMXT_BUILTIN2 (iwmmxt_wpackhss, WPACKHSS) |
17634 | IWMMXT_BUILTIN2 (iwmmxt_wpackwss, WPACKWSS) | |
17635 | IWMMXT_BUILTIN2 (iwmmxt_wpackdss, WPACKDSS) | |
17636 | IWMMXT_BUILTIN2 (iwmmxt_wpackhus, WPACKHUS) | |
17637 | IWMMXT_BUILTIN2 (iwmmxt_wpackwus, WPACKWUS) | |
17638 | IWMMXT_BUILTIN2 (iwmmxt_wpackdus, WPACKDUS) | |
17639 | IWMMXT_BUILTIN2 (ashlv4hi3_di, WSLLH) | |
88f77cba | 17640 | IWMMXT_BUILTIN2 (ashlv4hi3_iwmmxt, WSLLHI) |
5a9335ef | 17641 | IWMMXT_BUILTIN2 (ashlv2si3_di, WSLLW) |
88f77cba | 17642 | IWMMXT_BUILTIN2 (ashlv2si3_iwmmxt, WSLLWI) |
5a9335ef NC |
17643 | IWMMXT_BUILTIN2 (ashldi3_di, WSLLD) |
17644 | IWMMXT_BUILTIN2 (ashldi3_iwmmxt, WSLLDI) | |
17645 | IWMMXT_BUILTIN2 (lshrv4hi3_di, WSRLH) | |
88f77cba | 17646 | IWMMXT_BUILTIN2 (lshrv4hi3_iwmmxt, WSRLHI) |
5a9335ef | 17647 | IWMMXT_BUILTIN2 (lshrv2si3_di, WSRLW) |
88f77cba | 17648 | IWMMXT_BUILTIN2 (lshrv2si3_iwmmxt, WSRLWI) |
5a9335ef | 17649 | IWMMXT_BUILTIN2 (lshrdi3_di, WSRLD) |
9b66ebb1 | 17650 | IWMMXT_BUILTIN2 (lshrdi3_iwmmxt, WSRLDI) |
5a9335ef | 17651 | IWMMXT_BUILTIN2 (ashrv4hi3_di, WSRAH) |
88f77cba | 17652 | IWMMXT_BUILTIN2 (ashrv4hi3_iwmmxt, WSRAHI) |
5a9335ef | 17653 | IWMMXT_BUILTIN2 (ashrv2si3_di, WSRAW) |
88f77cba | 17654 | IWMMXT_BUILTIN2 (ashrv2si3_iwmmxt, WSRAWI) |
5a9335ef | 17655 | IWMMXT_BUILTIN2 (ashrdi3_di, WSRAD) |
9b66ebb1 | 17656 | IWMMXT_BUILTIN2 (ashrdi3_iwmmxt, WSRADI) |
5a9335ef NC |
17657 | IWMMXT_BUILTIN2 (rorv4hi3_di, WRORH) |
17658 | IWMMXT_BUILTIN2 (rorv4hi3, WRORHI) | |
17659 | IWMMXT_BUILTIN2 (rorv2si3_di, WRORW) | |
17660 | IWMMXT_BUILTIN2 (rorv2si3, WRORWI) | |
17661 | IWMMXT_BUILTIN2 (rordi3_di, WRORD) | |
17662 | IWMMXT_BUILTIN2 (rordi3, WRORDI) | |
17663 | IWMMXT_BUILTIN2 (iwmmxt_wmacuz, WMACUZ) | |
17664 | IWMMXT_BUILTIN2 (iwmmxt_wmacsz, WMACSZ) | |
17665 | }; | |
17666 | ||
17667 | static const struct builtin_description bdesc_1arg[] = | |
17668 | { | |
17669 | IWMMXT_BUILTIN (iwmmxt_tmovmskb, "tmovmskb", TMOVMSKB) | |
17670 | IWMMXT_BUILTIN (iwmmxt_tmovmskh, "tmovmskh", TMOVMSKH) | |
17671 | IWMMXT_BUILTIN (iwmmxt_tmovmskw, "tmovmskw", TMOVMSKW) | |
17672 | IWMMXT_BUILTIN (iwmmxt_waccb, "waccb", WACCB) | |
17673 | IWMMXT_BUILTIN (iwmmxt_wacch, "wacch", WACCH) | |
17674 | IWMMXT_BUILTIN (iwmmxt_waccw, "waccw", WACCW) | |
17675 | IWMMXT_BUILTIN (iwmmxt_wunpckehub, "wunpckehub", WUNPCKEHUB) | |
17676 | IWMMXT_BUILTIN (iwmmxt_wunpckehuh, "wunpckehuh", WUNPCKEHUH) | |
17677 | IWMMXT_BUILTIN (iwmmxt_wunpckehuw, "wunpckehuw", WUNPCKEHUW) | |
17678 | IWMMXT_BUILTIN (iwmmxt_wunpckehsb, "wunpckehsb", WUNPCKEHSB) | |
17679 | IWMMXT_BUILTIN (iwmmxt_wunpckehsh, "wunpckehsh", WUNPCKEHSH) | |
17680 | IWMMXT_BUILTIN (iwmmxt_wunpckehsw, "wunpckehsw", WUNPCKEHSW) | |
17681 | IWMMXT_BUILTIN (iwmmxt_wunpckelub, "wunpckelub", WUNPCKELUB) | |
17682 | IWMMXT_BUILTIN (iwmmxt_wunpckeluh, "wunpckeluh", WUNPCKELUH) | |
17683 | IWMMXT_BUILTIN (iwmmxt_wunpckeluw, "wunpckeluw", WUNPCKELUW) | |
17684 | IWMMXT_BUILTIN (iwmmxt_wunpckelsb, "wunpckelsb", WUNPCKELSB) | |
17685 | IWMMXT_BUILTIN (iwmmxt_wunpckelsh, "wunpckelsh", WUNPCKELSH) | |
17686 | IWMMXT_BUILTIN (iwmmxt_wunpckelsw, "wunpckelsw", WUNPCKELSW) | |
17687 | }; | |
17688 | ||
17689 | /* Set up all the iWMMXt builtins. This is | |
17690 | not called if TARGET_IWMMXT is zero. */ | |
17691 | ||
17692 | static void | |
17693 | arm_init_iwmmxt_builtins (void) | |
17694 | { | |
17695 | const struct builtin_description * d; | |
17696 | size_t i; | |
17697 | tree endlink = void_list_node; | |
17698 | ||
4a5eab38 PB |
17699 | tree V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode); |
17700 | tree V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode); | |
17701 | tree V8QI_type_node = build_vector_type_for_mode (intQI_type_node, V8QImode); | |
17702 | ||
5a9335ef NC |
17703 | tree int_ftype_int |
17704 | = build_function_type (integer_type_node, | |
17705 | tree_cons (NULL_TREE, integer_type_node, endlink)); | |
17706 | tree v8qi_ftype_v8qi_v8qi_int | |
17707 | = build_function_type (V8QI_type_node, | |
17708 | tree_cons (NULL_TREE, V8QI_type_node, | |
17709 | tree_cons (NULL_TREE, V8QI_type_node, | |
17710 | tree_cons (NULL_TREE, | |
17711 | integer_type_node, | |
17712 | endlink)))); | |
17713 | tree v4hi_ftype_v4hi_int | |
17714 | = build_function_type (V4HI_type_node, | |
17715 | tree_cons (NULL_TREE, V4HI_type_node, | |
17716 | tree_cons (NULL_TREE, integer_type_node, | |
17717 | endlink))); | |
17718 | tree v2si_ftype_v2si_int | |
17719 | = build_function_type (V2SI_type_node, | |
17720 | tree_cons (NULL_TREE, V2SI_type_node, | |
17721 | tree_cons (NULL_TREE, integer_type_node, | |
17722 | endlink))); | |
17723 | tree v2si_ftype_di_di | |
17724 | = build_function_type (V2SI_type_node, | |
17725 | tree_cons (NULL_TREE, long_long_integer_type_node, | |
17726 | tree_cons (NULL_TREE, long_long_integer_type_node, | |
17727 | endlink))); | |
17728 | tree di_ftype_di_int | |
17729 | = build_function_type (long_long_integer_type_node, | |
17730 | tree_cons (NULL_TREE, long_long_integer_type_node, | |
17731 | tree_cons (NULL_TREE, integer_type_node, | |
17732 | endlink))); | |
17733 | tree di_ftype_di_int_int | |
17734 | = build_function_type (long_long_integer_type_node, | |
17735 | tree_cons (NULL_TREE, long_long_integer_type_node, | |
17736 | tree_cons (NULL_TREE, integer_type_node, | |
17737 | tree_cons (NULL_TREE, | |
17738 | integer_type_node, | |
17739 | endlink)))); | |
17740 | tree int_ftype_v8qi | |
17741 | = build_function_type (integer_type_node, | |
17742 | tree_cons (NULL_TREE, V8QI_type_node, | |
17743 | endlink)); | |
17744 | tree int_ftype_v4hi | |
17745 | = build_function_type (integer_type_node, | |
17746 | tree_cons (NULL_TREE, V4HI_type_node, | |
17747 | endlink)); | |
17748 | tree int_ftype_v2si | |
17749 | = build_function_type (integer_type_node, | |
17750 | tree_cons (NULL_TREE, V2SI_type_node, | |
17751 | endlink)); | |
17752 | tree int_ftype_v8qi_int | |
17753 | = build_function_type (integer_type_node, | |
17754 | tree_cons (NULL_TREE, V8QI_type_node, | |
17755 | tree_cons (NULL_TREE, integer_type_node, | |
17756 | endlink))); | |
17757 | tree int_ftype_v4hi_int | |
17758 | = build_function_type (integer_type_node, | |
17759 | tree_cons (NULL_TREE, V4HI_type_node, | |
17760 | tree_cons (NULL_TREE, integer_type_node, | |
17761 | endlink))); | |
17762 | tree int_ftype_v2si_int | |
17763 | = build_function_type (integer_type_node, | |
17764 | tree_cons (NULL_TREE, V2SI_type_node, | |
17765 | tree_cons (NULL_TREE, integer_type_node, | |
17766 | endlink))); | |
17767 | tree v8qi_ftype_v8qi_int_int | |
17768 | = build_function_type (V8QI_type_node, | |
17769 | tree_cons (NULL_TREE, V8QI_type_node, | |
17770 | tree_cons (NULL_TREE, integer_type_node, | |
17771 | tree_cons (NULL_TREE, | |
17772 | integer_type_node, | |
17773 | endlink)))); | |
17774 | tree v4hi_ftype_v4hi_int_int | |
17775 | = build_function_type (V4HI_type_node, | |
17776 | tree_cons (NULL_TREE, V4HI_type_node, | |
17777 | tree_cons (NULL_TREE, integer_type_node, | |
17778 | tree_cons (NULL_TREE, | |
17779 | integer_type_node, | |
17780 | endlink)))); | |
17781 | tree v2si_ftype_v2si_int_int | |
17782 | = build_function_type (V2SI_type_node, | |
17783 | tree_cons (NULL_TREE, V2SI_type_node, | |
17784 | tree_cons (NULL_TREE, integer_type_node, | |
17785 | tree_cons (NULL_TREE, | |
17786 | integer_type_node, | |
17787 | endlink)))); | |
17788 | /* Miscellaneous. */ | |
17789 | tree v8qi_ftype_v4hi_v4hi | |
17790 | = build_function_type (V8QI_type_node, | |
17791 | tree_cons (NULL_TREE, V4HI_type_node, | |
17792 | tree_cons (NULL_TREE, V4HI_type_node, | |
17793 | endlink))); | |
17794 | tree v4hi_ftype_v2si_v2si | |
17795 | = build_function_type (V4HI_type_node, | |
17796 | tree_cons (NULL_TREE, V2SI_type_node, | |
17797 | tree_cons (NULL_TREE, V2SI_type_node, | |
17798 | endlink))); | |
17799 | tree v2si_ftype_v4hi_v4hi | |
17800 | = build_function_type (V2SI_type_node, | |
17801 | tree_cons (NULL_TREE, V4HI_type_node, | |
17802 | tree_cons (NULL_TREE, V4HI_type_node, | |
17803 | endlink))); | |
17804 | tree v2si_ftype_v8qi_v8qi | |
17805 | = build_function_type (V2SI_type_node, | |
17806 | tree_cons (NULL_TREE, V8QI_type_node, | |
17807 | tree_cons (NULL_TREE, V8QI_type_node, | |
17808 | endlink))); | |
17809 | tree v4hi_ftype_v4hi_di | |
17810 | = build_function_type (V4HI_type_node, | |
17811 | tree_cons (NULL_TREE, V4HI_type_node, | |
17812 | tree_cons (NULL_TREE, | |
17813 | long_long_integer_type_node, | |
17814 | endlink))); | |
17815 | tree v2si_ftype_v2si_di | |
17816 | = build_function_type (V2SI_type_node, | |
17817 | tree_cons (NULL_TREE, V2SI_type_node, | |
17818 | tree_cons (NULL_TREE, | |
17819 | long_long_integer_type_node, | |
17820 | endlink))); | |
17821 | tree void_ftype_int_int | |
17822 | = build_function_type (void_type_node, | |
17823 | tree_cons (NULL_TREE, integer_type_node, | |
17824 | tree_cons (NULL_TREE, integer_type_node, | |
17825 | endlink))); | |
17826 | tree di_ftype_void | |
17827 | = build_function_type (long_long_unsigned_type_node, endlink); | |
17828 | tree di_ftype_v8qi | |
17829 | = build_function_type (long_long_integer_type_node, | |
17830 | tree_cons (NULL_TREE, V8QI_type_node, | |
17831 | endlink)); | |
17832 | tree di_ftype_v4hi | |
17833 | = build_function_type (long_long_integer_type_node, | |
17834 | tree_cons (NULL_TREE, V4HI_type_node, | |
17835 | endlink)); | |
17836 | tree di_ftype_v2si | |
17837 | = build_function_type (long_long_integer_type_node, | |
17838 | tree_cons (NULL_TREE, V2SI_type_node, | |
17839 | endlink)); | |
17840 | tree v2si_ftype_v4hi | |
17841 | = build_function_type (V2SI_type_node, | |
17842 | tree_cons (NULL_TREE, V4HI_type_node, | |
17843 | endlink)); | |
17844 | tree v4hi_ftype_v8qi | |
17845 | = build_function_type (V4HI_type_node, | |
17846 | tree_cons (NULL_TREE, V8QI_type_node, | |
17847 | endlink)); | |
17848 | ||
17849 | tree di_ftype_di_v4hi_v4hi | |
17850 | = build_function_type (long_long_unsigned_type_node, | |
17851 | tree_cons (NULL_TREE, | |
17852 | long_long_unsigned_type_node, | |
17853 | tree_cons (NULL_TREE, V4HI_type_node, | |
17854 | tree_cons (NULL_TREE, | |
17855 | V4HI_type_node, | |
17856 | endlink)))); | |
17857 | ||
17858 | tree di_ftype_v4hi_v4hi | |
17859 | = build_function_type (long_long_unsigned_type_node, | |
17860 | tree_cons (NULL_TREE, V4HI_type_node, | |
17861 | tree_cons (NULL_TREE, V4HI_type_node, | |
17862 | endlink))); | |
17863 | ||
17864 | /* Normal vector binops. */ | |
17865 | tree v8qi_ftype_v8qi_v8qi | |
17866 | = build_function_type (V8QI_type_node, | |
17867 | tree_cons (NULL_TREE, V8QI_type_node, | |
17868 | tree_cons (NULL_TREE, V8QI_type_node, | |
17869 | endlink))); | |
17870 | tree v4hi_ftype_v4hi_v4hi | |
17871 | = build_function_type (V4HI_type_node, | |
17872 | tree_cons (NULL_TREE, V4HI_type_node, | |
17873 | tree_cons (NULL_TREE, V4HI_type_node, | |
17874 | endlink))); | |
17875 | tree v2si_ftype_v2si_v2si | |
17876 | = build_function_type (V2SI_type_node, | |
17877 | tree_cons (NULL_TREE, V2SI_type_node, | |
17878 | tree_cons (NULL_TREE, V2SI_type_node, | |
17879 | endlink))); | |
17880 | tree di_ftype_di_di | |
17881 | = build_function_type (long_long_unsigned_type_node, | |
17882 | tree_cons (NULL_TREE, long_long_unsigned_type_node, | |
17883 | tree_cons (NULL_TREE, | |
17884 | long_long_unsigned_type_node, | |
17885 | endlink))); | |
17886 | ||
17887 | /* Add all builtins that are more or less simple operations on two | |
17888 | operands. */ | |
e97a46ce | 17889 | for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++) |
5a9335ef NC |
17890 | { |
17891 | /* Use one of the operands; the target can have a different mode for | |
17892 | mask-generating compares. */ | |
17893 | enum machine_mode mode; | |
17894 | tree type; | |
17895 | ||
17896 | if (d->name == 0) | |
17897 | continue; | |
17898 | ||
17899 | mode = insn_data[d->icode].operand[1].mode; | |
17900 | ||
17901 | switch (mode) | |
17902 | { | |
17903 | case V8QImode: | |
17904 | type = v8qi_ftype_v8qi_v8qi; | |
17905 | break; | |
17906 | case V4HImode: | |
17907 | type = v4hi_ftype_v4hi_v4hi; | |
17908 | break; | |
17909 | case V2SImode: | |
17910 | type = v2si_ftype_v2si_v2si; | |
17911 | break; | |
17912 | case DImode: | |
17913 | type = di_ftype_di_di; | |
17914 | break; | |
17915 | ||
17916 | default: | |
e6d29d15 | 17917 | gcc_unreachable (); |
5a9335ef NC |
17918 | } |
17919 | ||
17920 | def_mbuiltin (d->mask, d->name, type, d->code); | |
17921 | } | |
17922 | ||
17923 | /* Add the remaining MMX insns with somewhat more complicated types. */ | |
17924 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wzero", di_ftype_void, ARM_BUILTIN_WZERO); | |
17925 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_setwcx", void_ftype_int_int, ARM_BUILTIN_SETWCX); | |
17926 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_getwcx", int_ftype_int, ARM_BUILTIN_GETWCX); | |
17927 | ||
17928 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsllh", v4hi_ftype_v4hi_di, ARM_BUILTIN_WSLLH); | |
17929 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsllw", v2si_ftype_v2si_di, ARM_BUILTIN_WSLLW); | |
17930 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wslld", di_ftype_di_di, ARM_BUILTIN_WSLLD); | |
17931 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsllhi", v4hi_ftype_v4hi_int, ARM_BUILTIN_WSLLHI); | |
17932 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsllwi", v2si_ftype_v2si_int, ARM_BUILTIN_WSLLWI); | |
17933 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wslldi", di_ftype_di_int, ARM_BUILTIN_WSLLDI); | |
17934 | ||
17935 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrlh", v4hi_ftype_v4hi_di, ARM_BUILTIN_WSRLH); | |
17936 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrlw", v2si_ftype_v2si_di, ARM_BUILTIN_WSRLW); | |
17937 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrld", di_ftype_di_di, ARM_BUILTIN_WSRLD); | |
17938 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrlhi", v4hi_ftype_v4hi_int, ARM_BUILTIN_WSRLHI); | |
17939 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrlwi", v2si_ftype_v2si_int, ARM_BUILTIN_WSRLWI); | |
17940 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrldi", di_ftype_di_int, ARM_BUILTIN_WSRLDI); | |
17941 | ||
17942 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrah", v4hi_ftype_v4hi_di, ARM_BUILTIN_WSRAH); | |
17943 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsraw", v2si_ftype_v2si_di, ARM_BUILTIN_WSRAW); | |
17944 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrad", di_ftype_di_di, ARM_BUILTIN_WSRAD); | |
17945 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrahi", v4hi_ftype_v4hi_int, ARM_BUILTIN_WSRAHI); | |
17946 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrawi", v2si_ftype_v2si_int, ARM_BUILTIN_WSRAWI); | |
17947 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsradi", di_ftype_di_int, ARM_BUILTIN_WSRADI); | |
17948 | ||
17949 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrorh", v4hi_ftype_v4hi_di, ARM_BUILTIN_WRORH); | |
17950 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrorw", v2si_ftype_v2si_di, ARM_BUILTIN_WRORW); | |
17951 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrord", di_ftype_di_di, ARM_BUILTIN_WRORD); | |
17952 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrorhi", v4hi_ftype_v4hi_int, ARM_BUILTIN_WRORHI); | |
17953 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrorwi", v2si_ftype_v2si_int, ARM_BUILTIN_WRORWI); | |
17954 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrordi", di_ftype_di_int, ARM_BUILTIN_WRORDI); | |
17955 | ||
17956 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wshufh", v4hi_ftype_v4hi_int, ARM_BUILTIN_WSHUFH); | |
17957 | ||
17958 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsadb", v2si_ftype_v8qi_v8qi, ARM_BUILTIN_WSADB); | |
17959 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsadh", v2si_ftype_v4hi_v4hi, ARM_BUILTIN_WSADH); | |
17960 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsadbz", v2si_ftype_v8qi_v8qi, ARM_BUILTIN_WSADBZ); | |
17961 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsadhz", v2si_ftype_v4hi_v4hi, ARM_BUILTIN_WSADHZ); | |
17962 | ||
17963 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmsb", int_ftype_v8qi_int, ARM_BUILTIN_TEXTRMSB); | |
17964 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmsh", int_ftype_v4hi_int, ARM_BUILTIN_TEXTRMSH); | |
17965 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmsw", int_ftype_v2si_int, ARM_BUILTIN_TEXTRMSW); | |
17966 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmub", int_ftype_v8qi_int, ARM_BUILTIN_TEXTRMUB); | |
17967 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmuh", int_ftype_v4hi_int, ARM_BUILTIN_TEXTRMUH); | |
17968 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmuw", int_ftype_v2si_int, ARM_BUILTIN_TEXTRMUW); | |
17969 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tinsrb", v8qi_ftype_v8qi_int_int, ARM_BUILTIN_TINSRB); | |
17970 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tinsrh", v4hi_ftype_v4hi_int_int, ARM_BUILTIN_TINSRH); | |
17971 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tinsrw", v2si_ftype_v2si_int_int, ARM_BUILTIN_TINSRW); | |
17972 | ||
17973 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_waccb", di_ftype_v8qi, ARM_BUILTIN_WACCB); | |
17974 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wacch", di_ftype_v4hi, ARM_BUILTIN_WACCH); | |
17975 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_waccw", di_ftype_v2si, ARM_BUILTIN_WACCW); | |
17976 | ||
17977 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmovmskb", int_ftype_v8qi, ARM_BUILTIN_TMOVMSKB); | |
17978 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmovmskh", int_ftype_v4hi, ARM_BUILTIN_TMOVMSKH); | |
17979 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmovmskw", int_ftype_v2si, ARM_BUILTIN_TMOVMSKW); | |
17980 | ||
17981 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackhss", v8qi_ftype_v4hi_v4hi, ARM_BUILTIN_WPACKHSS); | |
17982 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackhus", v8qi_ftype_v4hi_v4hi, ARM_BUILTIN_WPACKHUS); | |
17983 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackwus", v4hi_ftype_v2si_v2si, ARM_BUILTIN_WPACKWUS); | |
17984 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackwss", v4hi_ftype_v2si_v2si, ARM_BUILTIN_WPACKWSS); | |
17985 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackdus", v2si_ftype_di_di, ARM_BUILTIN_WPACKDUS); | |
17986 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackdss", v2si_ftype_di_di, ARM_BUILTIN_WPACKDSS); | |
17987 | ||
17988 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehub", v4hi_ftype_v8qi, ARM_BUILTIN_WUNPCKEHUB); | |
17989 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehuh", v2si_ftype_v4hi, ARM_BUILTIN_WUNPCKEHUH); | |
17990 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehuw", di_ftype_v2si, ARM_BUILTIN_WUNPCKEHUW); | |
17991 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehsb", v4hi_ftype_v8qi, ARM_BUILTIN_WUNPCKEHSB); | |
17992 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehsh", v2si_ftype_v4hi, ARM_BUILTIN_WUNPCKEHSH); | |
17993 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehsw", di_ftype_v2si, ARM_BUILTIN_WUNPCKEHSW); | |
17994 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckelub", v4hi_ftype_v8qi, ARM_BUILTIN_WUNPCKELUB); | |
17995 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckeluh", v2si_ftype_v4hi, ARM_BUILTIN_WUNPCKELUH); | |
17996 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckeluw", di_ftype_v2si, ARM_BUILTIN_WUNPCKELUW); | |
17997 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckelsb", v4hi_ftype_v8qi, ARM_BUILTIN_WUNPCKELSB); | |
17998 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckelsh", v2si_ftype_v4hi, ARM_BUILTIN_WUNPCKELSH); | |
17999 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckelsw", di_ftype_v2si, ARM_BUILTIN_WUNPCKELSW); | |
18000 | ||
18001 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wmacs", di_ftype_di_v4hi_v4hi, ARM_BUILTIN_WMACS); | |
18002 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wmacsz", di_ftype_v4hi_v4hi, ARM_BUILTIN_WMACSZ); | |
18003 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wmacu", di_ftype_di_v4hi_v4hi, ARM_BUILTIN_WMACU); | |
18004 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_wmacuz", di_ftype_v4hi_v4hi, ARM_BUILTIN_WMACUZ); | |
18005 | ||
18006 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_walign", v8qi_ftype_v8qi_v8qi_int, ARM_BUILTIN_WALIGN); | |
18007 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmia", di_ftype_di_int_int, ARM_BUILTIN_TMIA); | |
18008 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmiaph", di_ftype_di_int_int, ARM_BUILTIN_TMIAPH); | |
18009 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmiabb", di_ftype_di_int_int, ARM_BUILTIN_TMIABB); | |
18010 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmiabt", di_ftype_di_int_int, ARM_BUILTIN_TMIABT); | |
18011 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmiatb", di_ftype_di_int_int, ARM_BUILTIN_TMIATB); | |
18012 | def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmiatt", di_ftype_di_int_int, ARM_BUILTIN_TMIATT); | |
18013 | } | |
18014 | ||
d3585b76 DJ |
18015 | static void |
18016 | arm_init_tls_builtins (void) | |
18017 | { | |
ebfe65a3 | 18018 | tree ftype, decl; |
d3585b76 DJ |
18019 | |
18020 | ftype = build_function_type (ptr_type_node, void_list_node); | |
ebfe65a3 JJ |
18021 | decl = add_builtin_function ("__builtin_thread_pointer", ftype, |
18022 | ARM_BUILTIN_THREAD_POINTER, BUILT_IN_MD, | |
18023 | NULL, NULL_TREE); | |
18024 | TREE_NOTHROW (decl) = 1; | |
18025 | TREE_READONLY (decl) = 1; | |
d3585b76 DJ |
18026 | } |
18027 | ||
81f40b79 | 18028 | enum neon_builtin_type_bits { |
88f77cba JB |
18029 | T_V8QI = 0x0001, |
18030 | T_V4HI = 0x0002, | |
18031 | T_V2SI = 0x0004, | |
18032 | T_V2SF = 0x0008, | |
18033 | T_DI = 0x0010, | |
18034 | T_V16QI = 0x0020, | |
18035 | T_V8HI = 0x0040, | |
18036 | T_V4SI = 0x0080, | |
18037 | T_V4SF = 0x0100, | |
18038 | T_V2DI = 0x0200, | |
18039 | T_TI = 0x0400, | |
18040 | T_EI = 0x0800, | |
18041 | T_OI = 0x1000 | |
81f40b79 | 18042 | }; |
88f77cba JB |
18043 | |
18044 | #define v8qi_UP T_V8QI | |
18045 | #define v4hi_UP T_V4HI | |
18046 | #define v2si_UP T_V2SI | |
18047 | #define v2sf_UP T_V2SF | |
18048 | #define di_UP T_DI | |
18049 | #define v16qi_UP T_V16QI | |
18050 | #define v8hi_UP T_V8HI | |
18051 | #define v4si_UP T_V4SI | |
18052 | #define v4sf_UP T_V4SF | |
18053 | #define v2di_UP T_V2DI | |
18054 | #define ti_UP T_TI | |
18055 | #define ei_UP T_EI | |
18056 | #define oi_UP T_OI | |
18057 | ||
18058 | #define UP(X) X##_UP | |
18059 | ||
18060 | #define T_MAX 13 | |
18061 | ||
18062 | typedef enum { | |
18063 | NEON_BINOP, | |
18064 | NEON_TERNOP, | |
18065 | NEON_UNOP, | |
18066 | NEON_GETLANE, | |
18067 | NEON_SETLANE, | |
18068 | NEON_CREATE, | |
18069 | NEON_DUP, | |
18070 | NEON_DUPLANE, | |
18071 | NEON_COMBINE, | |
18072 | NEON_SPLIT, | |
18073 | NEON_LANEMUL, | |
18074 | NEON_LANEMULL, | |
18075 | NEON_LANEMULH, | |
18076 | NEON_LANEMAC, | |
18077 | NEON_SCALARMUL, | |
18078 | NEON_SCALARMULL, | |
18079 | NEON_SCALARMULH, | |
18080 | NEON_SCALARMAC, | |
18081 | NEON_CONVERT, | |
18082 | NEON_FIXCONV, | |
18083 | NEON_SELECT, | |
18084 | NEON_RESULTPAIR, | |
18085 | NEON_REINTERP, | |
18086 | NEON_VTBL, | |
18087 | NEON_VTBX, | |
18088 | NEON_LOAD1, | |
18089 | NEON_LOAD1LANE, | |
18090 | NEON_STORE1, | |
18091 | NEON_STORE1LANE, | |
18092 | NEON_LOADSTRUCT, | |
18093 | NEON_LOADSTRUCTLANE, | |
18094 | NEON_STORESTRUCT, | |
18095 | NEON_STORESTRUCTLANE, | |
18096 | NEON_LOGICBINOP, | |
18097 | NEON_SHIFTINSERT, | |
18098 | NEON_SHIFTIMM, | |
18099 | NEON_SHIFTACC | |
18100 | } neon_itype; | |
18101 | ||
18102 | typedef struct { | |
18103 | const char *name; | |
18104 | const neon_itype itype; | |
81f40b79 | 18105 | const int bits; |
88f77cba JB |
18106 | const enum insn_code codes[T_MAX]; |
18107 | const unsigned int num_vars; | |
18108 | unsigned int base_fcode; | |
18109 | } neon_builtin_datum; | |
18110 | ||
18111 | #define CF(N,X) CODE_FOR_neon_##N##X | |
18112 | ||
18113 | #define VAR1(T, N, A) \ | |
18114 | #N, NEON_##T, UP (A), { CF (N, A) }, 1, 0 | |
18115 | #define VAR2(T, N, A, B) \ | |
18116 | #N, NEON_##T, UP (A) | UP (B), { CF (N, A), CF (N, B) }, 2, 0 | |
18117 | #define VAR3(T, N, A, B, C) \ | |
18118 | #N, NEON_##T, UP (A) | UP (B) | UP (C), \ | |
18119 | { CF (N, A), CF (N, B), CF (N, C) }, 3, 0 | |
18120 | #define VAR4(T, N, A, B, C, D) \ | |
18121 | #N, NEON_##T, UP (A) | UP (B) | UP (C) | UP (D), \ | |
18122 | { CF (N, A), CF (N, B), CF (N, C), CF (N, D) }, 4, 0 | |
18123 | #define VAR5(T, N, A, B, C, D, E) \ | |
18124 | #N, NEON_##T, UP (A) | UP (B) | UP (C) | UP (D) | UP (E), \ | |
18125 | { CF (N, A), CF (N, B), CF (N, C), CF (N, D), CF (N, E) }, 5, 0 | |
18126 | #define VAR6(T, N, A, B, C, D, E, F) \ | |
18127 | #N, NEON_##T, UP (A) | UP (B) | UP (C) | UP (D) | UP (E) | UP (F), \ | |
18128 | { CF (N, A), CF (N, B), CF (N, C), CF (N, D), CF (N, E), CF (N, F) }, 6, 0 | |
18129 | #define VAR7(T, N, A, B, C, D, E, F, G) \ | |
18130 | #N, NEON_##T, UP (A) | UP (B) | UP (C) | UP (D) | UP (E) | UP (F) | UP (G), \ | |
18131 | { CF (N, A), CF (N, B), CF (N, C), CF (N, D), CF (N, E), CF (N, F), \ | |
18132 | CF (N, G) }, 7, 0 | |
18133 | #define VAR8(T, N, A, B, C, D, E, F, G, H) \ | |
18134 | #N, NEON_##T, UP (A) | UP (B) | UP (C) | UP (D) | UP (E) | UP (F) | UP (G) \ | |
18135 | | UP (H), \ | |
18136 | { CF (N, A), CF (N, B), CF (N, C), CF (N, D), CF (N, E), CF (N, F), \ | |
18137 | CF (N, G), CF (N, H) }, 8, 0 | |
18138 | #define VAR9(T, N, A, B, C, D, E, F, G, H, I) \ | |
18139 | #N, NEON_##T, UP (A) | UP (B) | UP (C) | UP (D) | UP (E) | UP (F) | UP (G) \ | |
18140 | | UP (H) | UP (I), \ | |
18141 | { CF (N, A), CF (N, B), CF (N, C), CF (N, D), CF (N, E), CF (N, F), \ | |
18142 | CF (N, G), CF (N, H), CF (N, I) }, 9, 0 | |
18143 | #define VAR10(T, N, A, B, C, D, E, F, G, H, I, J) \ | |
18144 | #N, NEON_##T, UP (A) | UP (B) | UP (C) | UP (D) | UP (E) | UP (F) | UP (G) \ | |
18145 | | UP (H) | UP (I) | UP (J), \ | |
18146 | { CF (N, A), CF (N, B), CF (N, C), CF (N, D), CF (N, E), CF (N, F), \ | |
18147 | CF (N, G), CF (N, H), CF (N, I), CF (N, J) }, 10, 0 | |
18148 | ||
18149 | /* The mode entries in the following table correspond to the "key" type of the | |
18150 | instruction variant, i.e. equivalent to that which would be specified after | |
18151 | the assembler mnemonic, which usually refers to the last vector operand. | |
18152 | (Signed/unsigned/polynomial types are not differentiated between though, and | |
18153 | are all mapped onto the same mode for a given element size.) The modes | |
18154 | listed per instruction should be the same as those defined for that | |
18155 | instruction's pattern in neon.md. | |
18156 | WARNING: Variants should be listed in the same increasing order as | |
18157 | neon_builtin_type_bits. */ | |
18158 | ||
18159 | static neon_builtin_datum neon_builtin_data[] = | |
18160 | { | |
18161 | { VAR10 (BINOP, vadd, | |
18162 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18163 | { VAR3 (BINOP, vaddl, v8qi, v4hi, v2si) }, | |
18164 | { VAR3 (BINOP, vaddw, v8qi, v4hi, v2si) }, | |
18165 | { VAR6 (BINOP, vhadd, v8qi, v4hi, v2si, v16qi, v8hi, v4si) }, | |
18166 | { VAR8 (BINOP, vqadd, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di) }, | |
18167 | { VAR3 (BINOP, vaddhn, v8hi, v4si, v2di) }, | |
18168 | { VAR8 (BINOP, vmul, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18169 | { VAR8 (TERNOP, vmla, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18170 | { VAR3 (TERNOP, vmlal, v8qi, v4hi, v2si) }, | |
18171 | { VAR8 (TERNOP, vmls, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18172 | { VAR3 (TERNOP, vmlsl, v8qi, v4hi, v2si) }, | |
18173 | { VAR4 (BINOP, vqdmulh, v4hi, v2si, v8hi, v4si) }, | |
18174 | { VAR2 (TERNOP, vqdmlal, v4hi, v2si) }, | |
18175 | { VAR2 (TERNOP, vqdmlsl, v4hi, v2si) }, | |
18176 | { VAR3 (BINOP, vmull, v8qi, v4hi, v2si) }, | |
18177 | { VAR2 (SCALARMULL, vmull_n, v4hi, v2si) }, | |
18178 | { VAR2 (LANEMULL, vmull_lane, v4hi, v2si) }, | |
18179 | { VAR2 (SCALARMULL, vqdmull_n, v4hi, v2si) }, | |
18180 | { VAR2 (LANEMULL, vqdmull_lane, v4hi, v2si) }, | |
18181 | { VAR4 (SCALARMULH, vqdmulh_n, v4hi, v2si, v8hi, v4si) }, | |
18182 | { VAR4 (LANEMULH, vqdmulh_lane, v4hi, v2si, v8hi, v4si) }, | |
18183 | { VAR2 (BINOP, vqdmull, v4hi, v2si) }, | |
18184 | { VAR8 (BINOP, vshl, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di) }, | |
18185 | { VAR8 (BINOP, vqshl, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di) }, | |
18186 | { VAR8 (SHIFTIMM, vshr_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di) }, | |
18187 | { VAR3 (SHIFTIMM, vshrn_n, v8hi, v4si, v2di) }, | |
18188 | { VAR3 (SHIFTIMM, vqshrn_n, v8hi, v4si, v2di) }, | |
18189 | { VAR3 (SHIFTIMM, vqshrun_n, v8hi, v4si, v2di) }, | |
18190 | { VAR8 (SHIFTIMM, vshl_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di) }, | |
18191 | { VAR8 (SHIFTIMM, vqshl_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di) }, | |
18192 | { VAR8 (SHIFTIMM, vqshlu_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di) }, | |
18193 | { VAR3 (SHIFTIMM, vshll_n, v8qi, v4hi, v2si) }, | |
18194 | { VAR8 (SHIFTACC, vsra_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di) }, | |
18195 | { VAR10 (BINOP, vsub, | |
18196 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18197 | { VAR3 (BINOP, vsubl, v8qi, v4hi, v2si) }, | |
18198 | { VAR3 (BINOP, vsubw, v8qi, v4hi, v2si) }, | |
18199 | { VAR8 (BINOP, vqsub, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di) }, | |
18200 | { VAR6 (BINOP, vhsub, v8qi, v4hi, v2si, v16qi, v8hi, v4si) }, | |
18201 | { VAR3 (BINOP, vsubhn, v8hi, v4si, v2di) }, | |
18202 | { VAR8 (BINOP, vceq, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18203 | { VAR8 (BINOP, vcge, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18204 | { VAR8 (BINOP, vcgt, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18205 | { VAR2 (BINOP, vcage, v2sf, v4sf) }, | |
18206 | { VAR2 (BINOP, vcagt, v2sf, v4sf) }, | |
18207 | { VAR6 (BINOP, vtst, v8qi, v4hi, v2si, v16qi, v8hi, v4si) }, | |
18208 | { VAR8 (BINOP, vabd, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18209 | { VAR3 (BINOP, vabdl, v8qi, v4hi, v2si) }, | |
18210 | { VAR6 (TERNOP, vaba, v8qi, v4hi, v2si, v16qi, v8hi, v4si) }, | |
18211 | { VAR3 (TERNOP, vabal, v8qi, v4hi, v2si) }, | |
18212 | { VAR8 (BINOP, vmax, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18213 | { VAR8 (BINOP, vmin, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18214 | { VAR4 (BINOP, vpadd, v8qi, v4hi, v2si, v2sf) }, | |
18215 | { VAR6 (UNOP, vpaddl, v8qi, v4hi, v2si, v16qi, v8hi, v4si) }, | |
18216 | { VAR6 (BINOP, vpadal, v8qi, v4hi, v2si, v16qi, v8hi, v4si) }, | |
18217 | { VAR4 (BINOP, vpmax, v8qi, v4hi, v2si, v2sf) }, | |
18218 | { VAR4 (BINOP, vpmin, v8qi, v4hi, v2si, v2sf) }, | |
18219 | { VAR2 (BINOP, vrecps, v2sf, v4sf) }, | |
18220 | { VAR2 (BINOP, vrsqrts, v2sf, v4sf) }, | |
18221 | { VAR8 (SHIFTINSERT, vsri_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di) }, | |
18222 | { VAR8 (SHIFTINSERT, vsli_n, v8qi, v4hi, v2si, di, v16qi, v8hi, v4si, v2di) }, | |
18223 | { VAR8 (UNOP, vabs, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18224 | { VAR6 (UNOP, vqabs, v8qi, v4hi, v2si, v16qi, v8hi, v4si) }, | |
18225 | { VAR8 (UNOP, vneg, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18226 | { VAR6 (UNOP, vqneg, v8qi, v4hi, v2si, v16qi, v8hi, v4si) }, | |
18227 | { VAR6 (UNOP, vcls, v8qi, v4hi, v2si, v16qi, v8hi, v4si) }, | |
18228 | { VAR6 (UNOP, vclz, v8qi, v4hi, v2si, v16qi, v8hi, v4si) }, | |
18229 | { VAR2 (UNOP, vcnt, v8qi, v16qi) }, | |
18230 | { VAR4 (UNOP, vrecpe, v2si, v2sf, v4si, v4sf) }, | |
18231 | { VAR4 (UNOP, vrsqrte, v2si, v2sf, v4si, v4sf) }, | |
18232 | { VAR6 (UNOP, vmvn, v8qi, v4hi, v2si, v16qi, v8hi, v4si) }, | |
18233 | /* FIXME: vget_lane supports more variants than this! */ | |
18234 | { VAR10 (GETLANE, vget_lane, | |
18235 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18236 | { VAR10 (SETLANE, vset_lane, | |
18237 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18238 | { VAR5 (CREATE, vcreate, v8qi, v4hi, v2si, v2sf, di) }, | |
18239 | { VAR10 (DUP, vdup_n, | |
18240 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18241 | { VAR10 (DUPLANE, vdup_lane, | |
18242 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18243 | { VAR5 (COMBINE, vcombine, v8qi, v4hi, v2si, v2sf, di) }, | |
18244 | { VAR5 (SPLIT, vget_high, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18245 | { VAR5 (SPLIT, vget_low, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18246 | { VAR3 (UNOP, vmovn, v8hi, v4si, v2di) }, | |
18247 | { VAR3 (UNOP, vqmovn, v8hi, v4si, v2di) }, | |
18248 | { VAR3 (UNOP, vqmovun, v8hi, v4si, v2di) }, | |
18249 | { VAR3 (UNOP, vmovl, v8qi, v4hi, v2si) }, | |
18250 | { VAR6 (LANEMUL, vmul_lane, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18251 | { VAR6 (LANEMAC, vmla_lane, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18252 | { VAR2 (LANEMAC, vmlal_lane, v4hi, v2si) }, | |
18253 | { VAR2 (LANEMAC, vqdmlal_lane, v4hi, v2si) }, | |
18254 | { VAR6 (LANEMAC, vmls_lane, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18255 | { VAR2 (LANEMAC, vmlsl_lane, v4hi, v2si) }, | |
18256 | { VAR2 (LANEMAC, vqdmlsl_lane, v4hi, v2si) }, | |
18257 | { VAR6 (SCALARMUL, vmul_n, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18258 | { VAR6 (SCALARMAC, vmla_n, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18259 | { VAR2 (SCALARMAC, vmlal_n, v4hi, v2si) }, | |
18260 | { VAR2 (SCALARMAC, vqdmlal_n, v4hi, v2si) }, | |
18261 | { VAR6 (SCALARMAC, vmls_n, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18262 | { VAR2 (SCALARMAC, vmlsl_n, v4hi, v2si) }, | |
18263 | { VAR2 (SCALARMAC, vqdmlsl_n, v4hi, v2si) }, | |
18264 | { VAR10 (BINOP, vext, | |
18265 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18266 | { VAR8 (UNOP, vrev64, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18267 | { VAR4 (UNOP, vrev32, v8qi, v4hi, v16qi, v8hi) }, | |
18268 | { VAR2 (UNOP, vrev16, v8qi, v16qi) }, | |
18269 | { VAR4 (CONVERT, vcvt, v2si, v2sf, v4si, v4sf) }, | |
18270 | { VAR4 (FIXCONV, vcvt_n, v2si, v2sf, v4si, v4sf) }, | |
18271 | { VAR10 (SELECT, vbsl, | |
18272 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18273 | { VAR1 (VTBL, vtbl1, v8qi) }, | |
18274 | { VAR1 (VTBL, vtbl2, v8qi) }, | |
18275 | { VAR1 (VTBL, vtbl3, v8qi) }, | |
18276 | { VAR1 (VTBL, vtbl4, v8qi) }, | |
18277 | { VAR1 (VTBX, vtbx1, v8qi) }, | |
18278 | { VAR1 (VTBX, vtbx2, v8qi) }, | |
18279 | { VAR1 (VTBX, vtbx3, v8qi) }, | |
18280 | { VAR1 (VTBX, vtbx4, v8qi) }, | |
18281 | { VAR8 (RESULTPAIR, vtrn, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18282 | { VAR8 (RESULTPAIR, vzip, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18283 | { VAR8 (RESULTPAIR, vuzp, v8qi, v4hi, v2si, v2sf, v16qi, v8hi, v4si, v4sf) }, | |
18284 | { VAR5 (REINTERP, vreinterpretv8qi, v8qi, v4hi, v2si, v2sf, di) }, | |
18285 | { VAR5 (REINTERP, vreinterpretv4hi, v8qi, v4hi, v2si, v2sf, di) }, | |
18286 | { VAR5 (REINTERP, vreinterpretv2si, v8qi, v4hi, v2si, v2sf, di) }, | |
18287 | { VAR5 (REINTERP, vreinterpretv2sf, v8qi, v4hi, v2si, v2sf, di) }, | |
18288 | { VAR5 (REINTERP, vreinterpretdi, v8qi, v4hi, v2si, v2sf, di) }, | |
18289 | { VAR5 (REINTERP, vreinterpretv16qi, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18290 | { VAR5 (REINTERP, vreinterpretv8hi, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18291 | { VAR5 (REINTERP, vreinterpretv4si, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18292 | { VAR5 (REINTERP, vreinterpretv4sf, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18293 | { VAR5 (REINTERP, vreinterpretv2di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18294 | { VAR10 (LOAD1, vld1, | |
18295 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18296 | { VAR10 (LOAD1LANE, vld1_lane, | |
18297 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18298 | { VAR10 (LOAD1, vld1_dup, | |
18299 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18300 | { VAR10 (STORE1, vst1, | |
18301 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18302 | { VAR10 (STORE1LANE, vst1_lane, | |
18303 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18304 | { VAR9 (LOADSTRUCT, | |
18305 | vld2, v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf) }, | |
18306 | { VAR7 (LOADSTRUCTLANE, vld2_lane, | |
18307 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18308 | { VAR5 (LOADSTRUCT, vld2_dup, v8qi, v4hi, v2si, v2sf, di) }, | |
18309 | { VAR9 (STORESTRUCT, vst2, | |
18310 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf) }, | |
18311 | { VAR7 (STORESTRUCTLANE, vst2_lane, | |
18312 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18313 | { VAR9 (LOADSTRUCT, | |
18314 | vld3, v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf) }, | |
18315 | { VAR7 (LOADSTRUCTLANE, vld3_lane, | |
18316 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18317 | { VAR5 (LOADSTRUCT, vld3_dup, v8qi, v4hi, v2si, v2sf, di) }, | |
18318 | { VAR9 (STORESTRUCT, vst3, | |
18319 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf) }, | |
18320 | { VAR7 (STORESTRUCTLANE, vst3_lane, | |
18321 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18322 | { VAR9 (LOADSTRUCT, vld4, | |
18323 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf) }, | |
18324 | { VAR7 (LOADSTRUCTLANE, vld4_lane, | |
18325 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18326 | { VAR5 (LOADSTRUCT, vld4_dup, v8qi, v4hi, v2si, v2sf, di) }, | |
18327 | { VAR9 (STORESTRUCT, vst4, | |
18328 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf) }, | |
18329 | { VAR7 (STORESTRUCTLANE, vst4_lane, | |
18330 | v8qi, v4hi, v2si, v2sf, v8hi, v4si, v4sf) }, | |
18331 | { VAR10 (LOGICBINOP, vand, | |
18332 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18333 | { VAR10 (LOGICBINOP, vorr, | |
18334 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18335 | { VAR10 (BINOP, veor, | |
18336 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18337 | { VAR10 (LOGICBINOP, vbic, | |
18338 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) }, | |
18339 | { VAR10 (LOGICBINOP, vorn, | |
18340 | v8qi, v4hi, v2si, v2sf, di, v16qi, v8hi, v4si, v4sf, v2di) } | |
18341 | }; | |
18342 | ||
18343 | #undef CF | |
18344 | #undef VAR1 | |
18345 | #undef VAR2 | |
18346 | #undef VAR3 | |
18347 | #undef VAR4 | |
18348 | #undef VAR5 | |
18349 | #undef VAR6 | |
18350 | #undef VAR7 | |
18351 | #undef VAR8 | |
18352 | #undef VAR9 | |
18353 | #undef VAR10 | |
18354 | ||
18355 | static void | |
18356 | arm_init_neon_builtins (void) | |
18357 | { | |
18358 | unsigned int i, fcode = ARM_BUILTIN_NEON_BASE; | |
18359 | ||
af06585a JM |
18360 | tree neon_intQI_type_node; |
18361 | tree neon_intHI_type_node; | |
18362 | tree neon_polyQI_type_node; | |
18363 | tree neon_polyHI_type_node; | |
18364 | tree neon_intSI_type_node; | |
18365 | tree neon_intDI_type_node; | |
18366 | tree neon_float_type_node; | |
18367 | ||
18368 | tree intQI_pointer_node; | |
18369 | tree intHI_pointer_node; | |
18370 | tree intSI_pointer_node; | |
18371 | tree intDI_pointer_node; | |
18372 | tree float_pointer_node; | |
18373 | ||
18374 | tree const_intQI_node; | |
18375 | tree const_intHI_node; | |
18376 | tree const_intSI_node; | |
18377 | tree const_intDI_node; | |
18378 | tree const_float_node; | |
18379 | ||
18380 | tree const_intQI_pointer_node; | |
18381 | tree const_intHI_pointer_node; | |
18382 | tree const_intSI_pointer_node; | |
18383 | tree const_intDI_pointer_node; | |
18384 | tree const_float_pointer_node; | |
18385 | ||
18386 | tree V8QI_type_node; | |
18387 | tree V4HI_type_node; | |
18388 | tree V2SI_type_node; | |
18389 | tree V2SF_type_node; | |
18390 | tree V16QI_type_node; | |
18391 | tree V8HI_type_node; | |
18392 | tree V4SI_type_node; | |
18393 | tree V4SF_type_node; | |
18394 | tree V2DI_type_node; | |
18395 | ||
18396 | tree intUQI_type_node; | |
18397 | tree intUHI_type_node; | |
18398 | tree intUSI_type_node; | |
18399 | tree intUDI_type_node; | |
18400 | ||
18401 | tree intEI_type_node; | |
18402 | tree intOI_type_node; | |
18403 | tree intCI_type_node; | |
18404 | tree intXI_type_node; | |
18405 | ||
18406 | tree V8QI_pointer_node; | |
18407 | tree V4HI_pointer_node; | |
18408 | tree V2SI_pointer_node; | |
18409 | tree V2SF_pointer_node; | |
18410 | tree V16QI_pointer_node; | |
18411 | tree V8HI_pointer_node; | |
18412 | tree V4SI_pointer_node; | |
18413 | tree V4SF_pointer_node; | |
18414 | tree V2DI_pointer_node; | |
18415 | ||
18416 | tree void_ftype_pv8qi_v8qi_v8qi; | |
18417 | tree void_ftype_pv4hi_v4hi_v4hi; | |
18418 | tree void_ftype_pv2si_v2si_v2si; | |
18419 | tree void_ftype_pv2sf_v2sf_v2sf; | |
18420 | tree void_ftype_pdi_di_di; | |
18421 | tree void_ftype_pv16qi_v16qi_v16qi; | |
18422 | tree void_ftype_pv8hi_v8hi_v8hi; | |
18423 | tree void_ftype_pv4si_v4si_v4si; | |
18424 | tree void_ftype_pv4sf_v4sf_v4sf; | |
18425 | tree void_ftype_pv2di_v2di_v2di; | |
18426 | ||
18427 | tree reinterp_ftype_dreg[5][5]; | |
18428 | tree reinterp_ftype_qreg[5][5]; | |
18429 | tree dreg_types[5], qreg_types[5]; | |
18430 | ||
88f77cba JB |
18431 | /* Create distinguished type nodes for NEON vector element types, |
18432 | and pointers to values of such types, so we can detect them later. */ | |
af06585a JM |
18433 | neon_intQI_type_node = make_signed_type (GET_MODE_PRECISION (QImode)); |
18434 | neon_intHI_type_node = make_signed_type (GET_MODE_PRECISION (HImode)); | |
18435 | neon_polyQI_type_node = make_signed_type (GET_MODE_PRECISION (QImode)); | |
18436 | neon_polyHI_type_node = make_signed_type (GET_MODE_PRECISION (HImode)); | |
18437 | neon_intSI_type_node = make_signed_type (GET_MODE_PRECISION (SImode)); | |
18438 | neon_intDI_type_node = make_signed_type (GET_MODE_PRECISION (DImode)); | |
18439 | neon_float_type_node = make_node (REAL_TYPE); | |
18440 | TYPE_PRECISION (neon_float_type_node) = FLOAT_TYPE_SIZE; | |
18441 | layout_type (neon_float_type_node); | |
18442 | ||
bcbdbbb0 JM |
18443 | /* Define typedefs which exactly correspond to the modes we are basing vector |
18444 | types on. If you change these names you'll need to change | |
18445 | the table used by arm_mangle_type too. */ | |
18446 | (*lang_hooks.types.register_builtin_type) (neon_intQI_type_node, | |
18447 | "__builtin_neon_qi"); | |
18448 | (*lang_hooks.types.register_builtin_type) (neon_intHI_type_node, | |
18449 | "__builtin_neon_hi"); | |
18450 | (*lang_hooks.types.register_builtin_type) (neon_intSI_type_node, | |
18451 | "__builtin_neon_si"); | |
18452 | (*lang_hooks.types.register_builtin_type) (neon_float_type_node, | |
18453 | "__builtin_neon_sf"); | |
18454 | (*lang_hooks.types.register_builtin_type) (neon_intDI_type_node, | |
18455 | "__builtin_neon_di"); | |
18456 | (*lang_hooks.types.register_builtin_type) (neon_polyQI_type_node, | |
18457 | "__builtin_neon_poly8"); | |
18458 | (*lang_hooks.types.register_builtin_type) (neon_polyHI_type_node, | |
18459 | "__builtin_neon_poly16"); | |
18460 | ||
af06585a JM |
18461 | intQI_pointer_node = build_pointer_type (neon_intQI_type_node); |
18462 | intHI_pointer_node = build_pointer_type (neon_intHI_type_node); | |
18463 | intSI_pointer_node = build_pointer_type (neon_intSI_type_node); | |
18464 | intDI_pointer_node = build_pointer_type (neon_intDI_type_node); | |
18465 | float_pointer_node = build_pointer_type (neon_float_type_node); | |
88f77cba JB |
18466 | |
18467 | /* Next create constant-qualified versions of the above types. */ | |
af06585a JM |
18468 | const_intQI_node = build_qualified_type (neon_intQI_type_node, |
18469 | TYPE_QUAL_CONST); | |
18470 | const_intHI_node = build_qualified_type (neon_intHI_type_node, | |
18471 | TYPE_QUAL_CONST); | |
18472 | const_intSI_node = build_qualified_type (neon_intSI_type_node, | |
18473 | TYPE_QUAL_CONST); | |
18474 | const_intDI_node = build_qualified_type (neon_intDI_type_node, | |
18475 | TYPE_QUAL_CONST); | |
18476 | const_float_node = build_qualified_type (neon_float_type_node, | |
18477 | TYPE_QUAL_CONST); | |
18478 | ||
18479 | const_intQI_pointer_node = build_pointer_type (const_intQI_node); | |
18480 | const_intHI_pointer_node = build_pointer_type (const_intHI_node); | |
18481 | const_intSI_pointer_node = build_pointer_type (const_intSI_node); | |
18482 | const_intDI_pointer_node = build_pointer_type (const_intDI_node); | |
18483 | const_float_pointer_node = build_pointer_type (const_float_node); | |
88f77cba JB |
18484 | |
18485 | /* Now create vector types based on our NEON element types. */ | |
18486 | /* 64-bit vectors. */ | |
af06585a | 18487 | V8QI_type_node = |
88f77cba | 18488 | build_vector_type_for_mode (neon_intQI_type_node, V8QImode); |
af06585a | 18489 | V4HI_type_node = |
88f77cba | 18490 | build_vector_type_for_mode (neon_intHI_type_node, V4HImode); |
af06585a | 18491 | V2SI_type_node = |
88f77cba | 18492 | build_vector_type_for_mode (neon_intSI_type_node, V2SImode); |
af06585a | 18493 | V2SF_type_node = |
88f77cba JB |
18494 | build_vector_type_for_mode (neon_float_type_node, V2SFmode); |
18495 | /* 128-bit vectors. */ | |
af06585a | 18496 | V16QI_type_node = |
88f77cba | 18497 | build_vector_type_for_mode (neon_intQI_type_node, V16QImode); |
af06585a | 18498 | V8HI_type_node = |
88f77cba | 18499 | build_vector_type_for_mode (neon_intHI_type_node, V8HImode); |
af06585a | 18500 | V4SI_type_node = |
88f77cba | 18501 | build_vector_type_for_mode (neon_intSI_type_node, V4SImode); |
af06585a | 18502 | V4SF_type_node = |
88f77cba | 18503 | build_vector_type_for_mode (neon_float_type_node, V4SFmode); |
af06585a | 18504 | V2DI_type_node = |
88f77cba JB |
18505 | build_vector_type_for_mode (neon_intDI_type_node, V2DImode); |
18506 | ||
18507 | /* Unsigned integer types for various mode sizes. */ | |
af06585a JM |
18508 | intUQI_type_node = make_unsigned_type (GET_MODE_PRECISION (QImode)); |
18509 | intUHI_type_node = make_unsigned_type (GET_MODE_PRECISION (HImode)); | |
18510 | intUSI_type_node = make_unsigned_type (GET_MODE_PRECISION (SImode)); | |
18511 | intUDI_type_node = make_unsigned_type (GET_MODE_PRECISION (DImode)); | |
88f77cba | 18512 | |
bcbdbbb0 JM |
18513 | (*lang_hooks.types.register_builtin_type) (intUQI_type_node, |
18514 | "__builtin_neon_uqi"); | |
18515 | (*lang_hooks.types.register_builtin_type) (intUHI_type_node, | |
18516 | "__builtin_neon_uhi"); | |
18517 | (*lang_hooks.types.register_builtin_type) (intUSI_type_node, | |
18518 | "__builtin_neon_usi"); | |
18519 | (*lang_hooks.types.register_builtin_type) (intUDI_type_node, | |
18520 | "__builtin_neon_udi"); | |
18521 | ||
88f77cba | 18522 | /* Opaque integer types for structures of vectors. */ |
af06585a JM |
18523 | intEI_type_node = make_signed_type (GET_MODE_PRECISION (EImode)); |
18524 | intOI_type_node = make_signed_type (GET_MODE_PRECISION (OImode)); | |
18525 | intCI_type_node = make_signed_type (GET_MODE_PRECISION (CImode)); | |
18526 | intXI_type_node = make_signed_type (GET_MODE_PRECISION (XImode)); | |
88f77cba | 18527 | |
bcbdbbb0 JM |
18528 | (*lang_hooks.types.register_builtin_type) (intTI_type_node, |
18529 | "__builtin_neon_ti"); | |
18530 | (*lang_hooks.types.register_builtin_type) (intEI_type_node, | |
18531 | "__builtin_neon_ei"); | |
18532 | (*lang_hooks.types.register_builtin_type) (intOI_type_node, | |
18533 | "__builtin_neon_oi"); | |
18534 | (*lang_hooks.types.register_builtin_type) (intCI_type_node, | |
18535 | "__builtin_neon_ci"); | |
18536 | (*lang_hooks.types.register_builtin_type) (intXI_type_node, | |
18537 | "__builtin_neon_xi"); | |
18538 | ||
88f77cba | 18539 | /* Pointers to vector types. */ |
af06585a JM |
18540 | V8QI_pointer_node = build_pointer_type (V8QI_type_node); |
18541 | V4HI_pointer_node = build_pointer_type (V4HI_type_node); | |
18542 | V2SI_pointer_node = build_pointer_type (V2SI_type_node); | |
18543 | V2SF_pointer_node = build_pointer_type (V2SF_type_node); | |
18544 | V16QI_pointer_node = build_pointer_type (V16QI_type_node); | |
18545 | V8HI_pointer_node = build_pointer_type (V8HI_type_node); | |
18546 | V4SI_pointer_node = build_pointer_type (V4SI_type_node); | |
18547 | V4SF_pointer_node = build_pointer_type (V4SF_type_node); | |
18548 | V2DI_pointer_node = build_pointer_type (V2DI_type_node); | |
88f77cba JB |
18549 | |
18550 | /* Operations which return results as pairs. */ | |
af06585a | 18551 | void_ftype_pv8qi_v8qi_v8qi = |
88f77cba JB |
18552 | build_function_type_list (void_type_node, V8QI_pointer_node, V8QI_type_node, |
18553 | V8QI_type_node, NULL); | |
af06585a | 18554 | void_ftype_pv4hi_v4hi_v4hi = |
88f77cba JB |
18555 | build_function_type_list (void_type_node, V4HI_pointer_node, V4HI_type_node, |
18556 | V4HI_type_node, NULL); | |
af06585a | 18557 | void_ftype_pv2si_v2si_v2si = |
88f77cba JB |
18558 | build_function_type_list (void_type_node, V2SI_pointer_node, V2SI_type_node, |
18559 | V2SI_type_node, NULL); | |
af06585a | 18560 | void_ftype_pv2sf_v2sf_v2sf = |
88f77cba JB |
18561 | build_function_type_list (void_type_node, V2SF_pointer_node, V2SF_type_node, |
18562 | V2SF_type_node, NULL); | |
af06585a | 18563 | void_ftype_pdi_di_di = |
88f77cba JB |
18564 | build_function_type_list (void_type_node, intDI_pointer_node, |
18565 | neon_intDI_type_node, neon_intDI_type_node, NULL); | |
af06585a | 18566 | void_ftype_pv16qi_v16qi_v16qi = |
88f77cba JB |
18567 | build_function_type_list (void_type_node, V16QI_pointer_node, |
18568 | V16QI_type_node, V16QI_type_node, NULL); | |
af06585a | 18569 | void_ftype_pv8hi_v8hi_v8hi = |
88f77cba JB |
18570 | build_function_type_list (void_type_node, V8HI_pointer_node, V8HI_type_node, |
18571 | V8HI_type_node, NULL); | |
af06585a | 18572 | void_ftype_pv4si_v4si_v4si = |
88f77cba JB |
18573 | build_function_type_list (void_type_node, V4SI_pointer_node, V4SI_type_node, |
18574 | V4SI_type_node, NULL); | |
af06585a | 18575 | void_ftype_pv4sf_v4sf_v4sf = |
88f77cba JB |
18576 | build_function_type_list (void_type_node, V4SF_pointer_node, V4SF_type_node, |
18577 | V4SF_type_node, NULL); | |
af06585a | 18578 | void_ftype_pv2di_v2di_v2di = |
88f77cba JB |
18579 | build_function_type_list (void_type_node, V2DI_pointer_node, V2DI_type_node, |
18580 | V2DI_type_node, NULL); | |
18581 | ||
88f77cba JB |
18582 | dreg_types[0] = V8QI_type_node; |
18583 | dreg_types[1] = V4HI_type_node; | |
18584 | dreg_types[2] = V2SI_type_node; | |
18585 | dreg_types[3] = V2SF_type_node; | |
18586 | dreg_types[4] = neon_intDI_type_node; | |
18587 | ||
18588 | qreg_types[0] = V16QI_type_node; | |
18589 | qreg_types[1] = V8HI_type_node; | |
18590 | qreg_types[2] = V4SI_type_node; | |
18591 | qreg_types[3] = V4SF_type_node; | |
18592 | qreg_types[4] = V2DI_type_node; | |
18593 | ||
18594 | for (i = 0; i < 5; i++) | |
18595 | { | |
18596 | int j; | |
18597 | for (j = 0; j < 5; j++) | |
18598 | { | |
18599 | reinterp_ftype_dreg[i][j] | |
18600 | = build_function_type_list (dreg_types[i], dreg_types[j], NULL); | |
18601 | reinterp_ftype_qreg[i][j] | |
18602 | = build_function_type_list (qreg_types[i], qreg_types[j], NULL); | |
18603 | } | |
18604 | } | |
18605 | ||
18606 | for (i = 0; i < ARRAY_SIZE (neon_builtin_data); i++) | |
18607 | { | |
18608 | neon_builtin_datum *d = &neon_builtin_data[i]; | |
18609 | unsigned int j, codeidx = 0; | |
18610 | ||
18611 | d->base_fcode = fcode; | |
18612 | ||
18613 | for (j = 0; j < T_MAX; j++) | |
18614 | { | |
18615 | const char* const modenames[] = { | |
18616 | "v8qi", "v4hi", "v2si", "v2sf", "di", | |
18617 | "v16qi", "v8hi", "v4si", "v4sf", "v2di" | |
18618 | }; | |
18619 | char namebuf[60]; | |
18620 | tree ftype = NULL; | |
18621 | enum insn_code icode; | |
18622 | int is_load = 0, is_store = 0; | |
18623 | ||
18624 | if ((d->bits & (1 << j)) == 0) | |
18625 | continue; | |
18626 | ||
18627 | icode = d->codes[codeidx++]; | |
18628 | ||
18629 | switch (d->itype) | |
18630 | { | |
18631 | case NEON_LOAD1: | |
18632 | case NEON_LOAD1LANE: | |
18633 | case NEON_LOADSTRUCT: | |
18634 | case NEON_LOADSTRUCTLANE: | |
18635 | is_load = 1; | |
18636 | /* Fall through. */ | |
18637 | case NEON_STORE1: | |
18638 | case NEON_STORE1LANE: | |
18639 | case NEON_STORESTRUCT: | |
18640 | case NEON_STORESTRUCTLANE: | |
18641 | if (!is_load) | |
18642 | is_store = 1; | |
18643 | /* Fall through. */ | |
18644 | case NEON_UNOP: | |
18645 | case NEON_BINOP: | |
18646 | case NEON_LOGICBINOP: | |
18647 | case NEON_SHIFTINSERT: | |
18648 | case NEON_TERNOP: | |
18649 | case NEON_GETLANE: | |
18650 | case NEON_SETLANE: | |
18651 | case NEON_CREATE: | |
18652 | case NEON_DUP: | |
18653 | case NEON_DUPLANE: | |
18654 | case NEON_SHIFTIMM: | |
18655 | case NEON_SHIFTACC: | |
18656 | case NEON_COMBINE: | |
18657 | case NEON_SPLIT: | |
18658 | case NEON_CONVERT: | |
18659 | case NEON_FIXCONV: | |
18660 | case NEON_LANEMUL: | |
18661 | case NEON_LANEMULL: | |
18662 | case NEON_LANEMULH: | |
18663 | case NEON_LANEMAC: | |
18664 | case NEON_SCALARMUL: | |
18665 | case NEON_SCALARMULL: | |
18666 | case NEON_SCALARMULH: | |
18667 | case NEON_SCALARMAC: | |
18668 | case NEON_SELECT: | |
18669 | case NEON_VTBL: | |
18670 | case NEON_VTBX: | |
18671 | { | |
18672 | int k; | |
18673 | tree return_type = void_type_node, args = void_list_node; | |
18674 | ||
18675 | /* Build a function type directly from the insn_data for this | |
18676 | builtin. The build_function_type() function takes care of | |
18677 | removing duplicates for us. */ | |
18678 | for (k = insn_data[icode].n_operands - 1; k >= 0; k--) | |
18679 | { | |
18680 | tree eltype; | |
18681 | ||
18682 | if (is_load && k == 1) | |
18683 | { | |
18684 | /* Neon load patterns always have the memory operand | |
18685 | (a SImode pointer) in the operand 1 position. We | |
18686 | want a const pointer to the element type in that | |
18687 | position. */ | |
18688 | gcc_assert (insn_data[icode].operand[k].mode == SImode); | |
18689 | ||
18690 | switch (1 << j) | |
18691 | { | |
18692 | case T_V8QI: | |
18693 | case T_V16QI: | |
18694 | eltype = const_intQI_pointer_node; | |
18695 | break; | |
18696 | ||
18697 | case T_V4HI: | |
18698 | case T_V8HI: | |
18699 | eltype = const_intHI_pointer_node; | |
18700 | break; | |
18701 | ||
18702 | case T_V2SI: | |
18703 | case T_V4SI: | |
18704 | eltype = const_intSI_pointer_node; | |
18705 | break; | |
18706 | ||
18707 | case T_V2SF: | |
18708 | case T_V4SF: | |
18709 | eltype = const_float_pointer_node; | |
18710 | break; | |
18711 | ||
18712 | case T_DI: | |
18713 | case T_V2DI: | |
18714 | eltype = const_intDI_pointer_node; | |
18715 | break; | |
18716 | ||
18717 | default: gcc_unreachable (); | |
18718 | } | |
18719 | } | |
18720 | else if (is_store && k == 0) | |
18721 | { | |
18722 | /* Similarly, Neon store patterns use operand 0 as | |
18723 | the memory location to store to (a SImode pointer). | |
18724 | Use a pointer to the element type of the store in | |
18725 | that position. */ | |
18726 | gcc_assert (insn_data[icode].operand[k].mode == SImode); | |
18727 | ||
18728 | switch (1 << j) | |
18729 | { | |
18730 | case T_V8QI: | |
18731 | case T_V16QI: | |
18732 | eltype = intQI_pointer_node; | |
18733 | break; | |
18734 | ||
18735 | case T_V4HI: | |
18736 | case T_V8HI: | |
18737 | eltype = intHI_pointer_node; | |
18738 | break; | |
18739 | ||
18740 | case T_V2SI: | |
18741 | case T_V4SI: | |
18742 | eltype = intSI_pointer_node; | |
18743 | break; | |
18744 | ||
18745 | case T_V2SF: | |
18746 | case T_V4SF: | |
18747 | eltype = float_pointer_node; | |
18748 | break; | |
18749 | ||
18750 | case T_DI: | |
18751 | case T_V2DI: | |
18752 | eltype = intDI_pointer_node; | |
18753 | break; | |
18754 | ||
18755 | default: gcc_unreachable (); | |
18756 | } | |
18757 | } | |
18758 | else | |
18759 | { | |
18760 | switch (insn_data[icode].operand[k].mode) | |
18761 | { | |
18762 | case VOIDmode: eltype = void_type_node; break; | |
18763 | /* Scalars. */ | |
18764 | case QImode: eltype = neon_intQI_type_node; break; | |
18765 | case HImode: eltype = neon_intHI_type_node; break; | |
18766 | case SImode: eltype = neon_intSI_type_node; break; | |
18767 | case SFmode: eltype = neon_float_type_node; break; | |
18768 | case DImode: eltype = neon_intDI_type_node; break; | |
18769 | case TImode: eltype = intTI_type_node; break; | |
18770 | case EImode: eltype = intEI_type_node; break; | |
18771 | case OImode: eltype = intOI_type_node; break; | |
18772 | case CImode: eltype = intCI_type_node; break; | |
18773 | case XImode: eltype = intXI_type_node; break; | |
18774 | /* 64-bit vectors. */ | |
18775 | case V8QImode: eltype = V8QI_type_node; break; | |
18776 | case V4HImode: eltype = V4HI_type_node; break; | |
18777 | case V2SImode: eltype = V2SI_type_node; break; | |
18778 | case V2SFmode: eltype = V2SF_type_node; break; | |
18779 | /* 128-bit vectors. */ | |
18780 | case V16QImode: eltype = V16QI_type_node; break; | |
18781 | case V8HImode: eltype = V8HI_type_node; break; | |
18782 | case V4SImode: eltype = V4SI_type_node; break; | |
18783 | case V4SFmode: eltype = V4SF_type_node; break; | |
18784 | case V2DImode: eltype = V2DI_type_node; break; | |
18785 | default: gcc_unreachable (); | |
18786 | } | |
18787 | } | |
18788 | ||
18789 | if (k == 0 && !is_store) | |
18790 | return_type = eltype; | |
18791 | else | |
18792 | args = tree_cons (NULL_TREE, eltype, args); | |
18793 | } | |
18794 | ||
18795 | ftype = build_function_type (return_type, args); | |
18796 | } | |
18797 | break; | |
18798 | ||
18799 | case NEON_RESULTPAIR: | |
18800 | { | |
18801 | switch (insn_data[icode].operand[1].mode) | |
18802 | { | |
18803 | case V8QImode: ftype = void_ftype_pv8qi_v8qi_v8qi; break; | |
18804 | case V4HImode: ftype = void_ftype_pv4hi_v4hi_v4hi; break; | |
18805 | case V2SImode: ftype = void_ftype_pv2si_v2si_v2si; break; | |
18806 | case V2SFmode: ftype = void_ftype_pv2sf_v2sf_v2sf; break; | |
18807 | case DImode: ftype = void_ftype_pdi_di_di; break; | |
18808 | case V16QImode: ftype = void_ftype_pv16qi_v16qi_v16qi; break; | |
18809 | case V8HImode: ftype = void_ftype_pv8hi_v8hi_v8hi; break; | |
18810 | case V4SImode: ftype = void_ftype_pv4si_v4si_v4si; break; | |
18811 | case V4SFmode: ftype = void_ftype_pv4sf_v4sf_v4sf; break; | |
18812 | case V2DImode: ftype = void_ftype_pv2di_v2di_v2di; break; | |
18813 | default: gcc_unreachable (); | |
18814 | } | |
18815 | } | |
18816 | break; | |
18817 | ||
18818 | case NEON_REINTERP: | |
18819 | { | |
18820 | /* We iterate over 5 doubleword types, then 5 quadword | |
18821 | types. */ | |
18822 | int rhs = j % 5; | |
18823 | switch (insn_data[icode].operand[0].mode) | |
18824 | { | |
18825 | case V8QImode: ftype = reinterp_ftype_dreg[0][rhs]; break; | |
18826 | case V4HImode: ftype = reinterp_ftype_dreg[1][rhs]; break; | |
18827 | case V2SImode: ftype = reinterp_ftype_dreg[2][rhs]; break; | |
18828 | case V2SFmode: ftype = reinterp_ftype_dreg[3][rhs]; break; | |
18829 | case DImode: ftype = reinterp_ftype_dreg[4][rhs]; break; | |
18830 | case V16QImode: ftype = reinterp_ftype_qreg[0][rhs]; break; | |
18831 | case V8HImode: ftype = reinterp_ftype_qreg[1][rhs]; break; | |
18832 | case V4SImode: ftype = reinterp_ftype_qreg[2][rhs]; break; | |
18833 | case V4SFmode: ftype = reinterp_ftype_qreg[3][rhs]; break; | |
18834 | case V2DImode: ftype = reinterp_ftype_qreg[4][rhs]; break; | |
18835 | default: gcc_unreachable (); | |
18836 | } | |
18837 | } | |
18838 | break; | |
18839 | ||
18840 | default: | |
18841 | gcc_unreachable (); | |
18842 | } | |
18843 | ||
18844 | gcc_assert (ftype != NULL); | |
18845 | ||
18846 | sprintf (namebuf, "__builtin_neon_%s%s", d->name, modenames[j]); | |
18847 | ||
18848 | add_builtin_function (namebuf, ftype, fcode++, BUILT_IN_MD, NULL, | |
18849 | NULL_TREE); | |
18850 | } | |
18851 | } | |
18852 | } | |
18853 | ||
0fd8c3ad SL |
18854 | static void |
18855 | arm_init_fp16_builtins (void) | |
18856 | { | |
18857 | tree fp16_type = make_node (REAL_TYPE); | |
18858 | TYPE_PRECISION (fp16_type) = 16; | |
18859 | layout_type (fp16_type); | |
18860 | (*lang_hooks.types.register_builtin_type) (fp16_type, "__fp16"); | |
18861 | } | |
18862 | ||
5a9335ef NC |
18863 | static void |
18864 | arm_init_builtins (void) | |
18865 | { | |
d3585b76 DJ |
18866 | arm_init_tls_builtins (); |
18867 | ||
5a9335ef NC |
18868 | if (TARGET_REALLY_IWMMXT) |
18869 | arm_init_iwmmxt_builtins (); | |
88f77cba JB |
18870 | |
18871 | if (TARGET_NEON) | |
18872 | arm_init_neon_builtins (); | |
0fd8c3ad SL |
18873 | |
18874 | if (arm_fp16_format) | |
18875 | arm_init_fp16_builtins (); | |
18876 | } | |
18877 | ||
18878 | /* Implement TARGET_INVALID_PARAMETER_TYPE. */ | |
18879 | ||
18880 | static const char * | |
18881 | arm_invalid_parameter_type (const_tree t) | |
18882 | { | |
18883 | if (SCALAR_FLOAT_TYPE_P (t) && TYPE_PRECISION (t) == 16) | |
18884 | return N_("function parameters cannot have __fp16 type"); | |
18885 | return NULL; | |
18886 | } | |
18887 | ||
18888 | /* Implement TARGET_INVALID_PARAMETER_TYPE. */ | |
18889 | ||
18890 | static const char * | |
18891 | arm_invalid_return_type (const_tree t) | |
18892 | { | |
18893 | if (SCALAR_FLOAT_TYPE_P (t) && TYPE_PRECISION (t) == 16) | |
18894 | return N_("functions cannot return __fp16 type"); | |
18895 | return NULL; | |
18896 | } | |
18897 | ||
18898 | /* Implement TARGET_PROMOTED_TYPE. */ | |
18899 | ||
18900 | static tree | |
18901 | arm_promoted_type (const_tree t) | |
18902 | { | |
18903 | if (SCALAR_FLOAT_TYPE_P (t) && TYPE_PRECISION (t) == 16) | |
18904 | return float_type_node; | |
18905 | return NULL_TREE; | |
18906 | } | |
18907 | ||
18908 | /* Implement TARGET_CONVERT_TO_TYPE. | |
18909 | Specifically, this hook implements the peculiarity of the ARM | |
18910 | half-precision floating-point C semantics that requires conversions between | |
18911 | __fp16 to or from double to do an intermediate conversion to float. */ | |
18912 | ||
18913 | static tree | |
18914 | arm_convert_to_type (tree type, tree expr) | |
18915 | { | |
18916 | tree fromtype = TREE_TYPE (expr); | |
18917 | if (!SCALAR_FLOAT_TYPE_P (fromtype) || !SCALAR_FLOAT_TYPE_P (type)) | |
18918 | return NULL_TREE; | |
18919 | if ((TYPE_PRECISION (fromtype) == 16 && TYPE_PRECISION (type) > 32) | |
18920 | || (TYPE_PRECISION (type) == 16 && TYPE_PRECISION (fromtype) > 32)) | |
18921 | return convert (type, convert (float_type_node, expr)); | |
18922 | return NULL_TREE; | |
5a9335ef NC |
18923 | } |
18924 | ||
bdc4827b SL |
18925 | /* Implement TARGET_SCALAR_MODE_SUPPORTED_P. |
18926 | This simply adds HFmode as a supported mode; even though we don't | |
18927 | implement arithmetic on this type directly, it's supported by | |
18928 | optabs conversions, much the way the double-word arithmetic is | |
18929 | special-cased in the default hook. */ | |
18930 | ||
18931 | static bool | |
18932 | arm_scalar_mode_supported_p (enum machine_mode mode) | |
18933 | { | |
18934 | if (mode == HFmode) | |
18935 | return (arm_fp16_format != ARM_FP16_FORMAT_NONE); | |
18936 | else | |
18937 | return default_scalar_mode_supported_p (mode); | |
18938 | } | |
18939 | ||
5a9335ef NC |
18940 | /* Errors in the source file can cause expand_expr to return const0_rtx |
18941 | where we expect a vector. To avoid crashing, use one of the vector | |
18942 | clear instructions. */ | |
18943 | ||
18944 | static rtx | |
18945 | safe_vector_operand (rtx x, enum machine_mode mode) | |
18946 | { | |
18947 | if (x != const0_rtx) | |
18948 | return x; | |
18949 | x = gen_reg_rtx (mode); | |
18950 | ||
18951 | emit_insn (gen_iwmmxt_clrdi (mode == DImode ? x | |
18952 | : gen_rtx_SUBREG (DImode, x, 0))); | |
18953 | return x; | |
18954 | } | |
18955 | ||
18956 | /* Subroutine of arm_expand_builtin to take care of binop insns. */ | |
18957 | ||
18958 | static rtx | |
18959 | arm_expand_binop_builtin (enum insn_code icode, | |
5039610b | 18960 | tree exp, rtx target) |
5a9335ef NC |
18961 | { |
18962 | rtx pat; | |
5039610b SL |
18963 | tree arg0 = CALL_EXPR_ARG (exp, 0); |
18964 | tree arg1 = CALL_EXPR_ARG (exp, 1); | |
84217346 MD |
18965 | rtx op0 = expand_normal (arg0); |
18966 | rtx op1 = expand_normal (arg1); | |
5a9335ef NC |
18967 | enum machine_mode tmode = insn_data[icode].operand[0].mode; |
18968 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
18969 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
18970 | ||
18971 | if (VECTOR_MODE_P (mode0)) | |
18972 | op0 = safe_vector_operand (op0, mode0); | |
18973 | if (VECTOR_MODE_P (mode1)) | |
18974 | op1 = safe_vector_operand (op1, mode1); | |
18975 | ||
18976 | if (! target | |
18977 | || GET_MODE (target) != tmode | |
18978 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
18979 | target = gen_reg_rtx (tmode); | |
18980 | ||
e6d29d15 | 18981 | gcc_assert (GET_MODE (op0) == mode0 && GET_MODE (op1) == mode1); |
5a9335ef NC |
18982 | |
18983 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
18984 | op0 = copy_to_mode_reg (mode0, op0); | |
18985 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
18986 | op1 = copy_to_mode_reg (mode1, op1); | |
18987 | ||
18988 | pat = GEN_FCN (icode) (target, op0, op1); | |
18989 | if (! pat) | |
18990 | return 0; | |
18991 | emit_insn (pat); | |
18992 | return target; | |
18993 | } | |
18994 | ||
18995 | /* Subroutine of arm_expand_builtin to take care of unop insns. */ | |
18996 | ||
18997 | static rtx | |
18998 | arm_expand_unop_builtin (enum insn_code icode, | |
5039610b | 18999 | tree exp, rtx target, int do_load) |
5a9335ef NC |
19000 | { |
19001 | rtx pat; | |
5039610b | 19002 | tree arg0 = CALL_EXPR_ARG (exp, 0); |
84217346 | 19003 | rtx op0 = expand_normal (arg0); |
5a9335ef NC |
19004 | enum machine_mode tmode = insn_data[icode].operand[0].mode; |
19005 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
19006 | ||
19007 | if (! target | |
19008 | || GET_MODE (target) != tmode | |
19009 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
19010 | target = gen_reg_rtx (tmode); | |
19011 | if (do_load) | |
19012 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
19013 | else | |
19014 | { | |
19015 | if (VECTOR_MODE_P (mode0)) | |
19016 | op0 = safe_vector_operand (op0, mode0); | |
19017 | ||
19018 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
19019 | op0 = copy_to_mode_reg (mode0, op0); | |
19020 | } | |
19021 | ||
19022 | pat = GEN_FCN (icode) (target, op0); | |
19023 | if (! pat) | |
19024 | return 0; | |
19025 | emit_insn (pat); | |
19026 | return target; | |
19027 | } | |
19028 | ||
88f77cba JB |
19029 | static int |
19030 | neon_builtin_compare (const void *a, const void *b) | |
19031 | { | |
5ead67f6 KG |
19032 | const neon_builtin_datum *const key = (const neon_builtin_datum *) a; |
19033 | const neon_builtin_datum *const memb = (const neon_builtin_datum *) b; | |
88f77cba JB |
19034 | unsigned int soughtcode = key->base_fcode; |
19035 | ||
19036 | if (soughtcode >= memb->base_fcode | |
19037 | && soughtcode < memb->base_fcode + memb->num_vars) | |
19038 | return 0; | |
19039 | else if (soughtcode < memb->base_fcode) | |
19040 | return -1; | |
19041 | else | |
19042 | return 1; | |
19043 | } | |
19044 | ||
19045 | static enum insn_code | |
19046 | locate_neon_builtin_icode (int fcode, neon_itype *itype) | |
19047 | { | |
19048 | neon_builtin_datum key, *found; | |
19049 | int idx; | |
19050 | ||
19051 | key.base_fcode = fcode; | |
5ead67f6 KG |
19052 | found = (neon_builtin_datum *) |
19053 | bsearch (&key, &neon_builtin_data[0], ARRAY_SIZE (neon_builtin_data), | |
88f77cba JB |
19054 | sizeof (neon_builtin_data[0]), neon_builtin_compare); |
19055 | gcc_assert (found); | |
19056 | idx = fcode - (int) found->base_fcode; | |
19057 | gcc_assert (idx >= 0 && idx < T_MAX && idx < (int)found->num_vars); | |
19058 | ||
19059 | if (itype) | |
19060 | *itype = found->itype; | |
19061 | ||
19062 | return found->codes[idx]; | |
19063 | } | |
19064 | ||
19065 | typedef enum { | |
19066 | NEON_ARG_COPY_TO_REG, | |
19067 | NEON_ARG_CONSTANT, | |
19068 | NEON_ARG_STOP | |
19069 | } builtin_arg; | |
19070 | ||
19071 | #define NEON_MAX_BUILTIN_ARGS 5 | |
19072 | ||
19073 | /* Expand a Neon builtin. */ | |
19074 | static rtx | |
19075 | arm_expand_neon_args (rtx target, int icode, int have_retval, | |
19076 | tree exp, ...) | |
19077 | { | |
19078 | va_list ap; | |
19079 | rtx pat; | |
19080 | tree arg[NEON_MAX_BUILTIN_ARGS]; | |
19081 | rtx op[NEON_MAX_BUILTIN_ARGS]; | |
19082 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
19083 | enum machine_mode mode[NEON_MAX_BUILTIN_ARGS]; | |
19084 | int argc = 0; | |
19085 | ||
19086 | if (have_retval | |
19087 | && (!target | |
19088 | || GET_MODE (target) != tmode | |
19089 | || !(*insn_data[icode].operand[0].predicate) (target, tmode))) | |
19090 | target = gen_reg_rtx (tmode); | |
19091 | ||
19092 | va_start (ap, exp); | |
19093 | ||
19094 | for (;;) | |
19095 | { | |
81f40b79 | 19096 | builtin_arg thisarg = (builtin_arg) va_arg (ap, int); |
88f77cba JB |
19097 | |
19098 | if (thisarg == NEON_ARG_STOP) | |
19099 | break; | |
19100 | else | |
19101 | { | |
19102 | arg[argc] = CALL_EXPR_ARG (exp, argc); | |
19103 | op[argc] = expand_normal (arg[argc]); | |
19104 | mode[argc] = insn_data[icode].operand[argc + have_retval].mode; | |
19105 | ||
19106 | switch (thisarg) | |
19107 | { | |
19108 | case NEON_ARG_COPY_TO_REG: | |
19109 | /*gcc_assert (GET_MODE (op[argc]) == mode[argc]);*/ | |
19110 | if (!(*insn_data[icode].operand[argc + have_retval].predicate) | |
19111 | (op[argc], mode[argc])) | |
19112 | op[argc] = copy_to_mode_reg (mode[argc], op[argc]); | |
19113 | break; | |
19114 | ||
19115 | case NEON_ARG_CONSTANT: | |
19116 | /* FIXME: This error message is somewhat unhelpful. */ | |
19117 | if (!(*insn_data[icode].operand[argc + have_retval].predicate) | |
19118 | (op[argc], mode[argc])) | |
19119 | error ("argument must be a constant"); | |
19120 | break; | |
19121 | ||
19122 | case NEON_ARG_STOP: | |
19123 | gcc_unreachable (); | |
19124 | } | |
19125 | ||
19126 | argc++; | |
19127 | } | |
19128 | } | |
19129 | ||
19130 | va_end (ap); | |
19131 | ||
19132 | if (have_retval) | |
19133 | switch (argc) | |
19134 | { | |
19135 | case 1: | |
19136 | pat = GEN_FCN (icode) (target, op[0]); | |
19137 | break; | |
19138 | ||
19139 | case 2: | |
19140 | pat = GEN_FCN (icode) (target, op[0], op[1]); | |
19141 | break; | |
19142 | ||
19143 | case 3: | |
19144 | pat = GEN_FCN (icode) (target, op[0], op[1], op[2]); | |
19145 | break; | |
19146 | ||
19147 | case 4: | |
19148 | pat = GEN_FCN (icode) (target, op[0], op[1], op[2], op[3]); | |
19149 | break; | |
19150 | ||
19151 | case 5: | |
19152 | pat = GEN_FCN (icode) (target, op[0], op[1], op[2], op[3], op[4]); | |
19153 | break; | |
19154 | ||
19155 | default: | |
19156 | gcc_unreachable (); | |
19157 | } | |
19158 | else | |
19159 | switch (argc) | |
19160 | { | |
19161 | case 1: | |
19162 | pat = GEN_FCN (icode) (op[0]); | |
19163 | break; | |
19164 | ||
19165 | case 2: | |
19166 | pat = GEN_FCN (icode) (op[0], op[1]); | |
19167 | break; | |
19168 | ||
19169 | case 3: | |
19170 | pat = GEN_FCN (icode) (op[0], op[1], op[2]); | |
19171 | break; | |
19172 | ||
19173 | case 4: | |
19174 | pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3]); | |
19175 | break; | |
19176 | ||
19177 | case 5: | |
19178 | pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3], op[4]); | |
19179 | break; | |
19180 | ||
19181 | default: | |
19182 | gcc_unreachable (); | |
19183 | } | |
19184 | ||
19185 | if (!pat) | |
19186 | return 0; | |
19187 | ||
19188 | emit_insn (pat); | |
19189 | ||
19190 | return target; | |
19191 | } | |
19192 | ||
19193 | /* Expand a Neon builtin. These are "special" because they don't have symbolic | |
19194 | constants defined per-instruction or per instruction-variant. Instead, the | |
19195 | required info is looked up in the table neon_builtin_data. */ | |
19196 | static rtx | |
19197 | arm_expand_neon_builtin (int fcode, tree exp, rtx target) | |
19198 | { | |
19199 | neon_itype itype; | |
19200 | enum insn_code icode = locate_neon_builtin_icode (fcode, &itype); | |
19201 | ||
19202 | switch (itype) | |
19203 | { | |
19204 | case NEON_UNOP: | |
19205 | case NEON_CONVERT: | |
19206 | case NEON_DUPLANE: | |
19207 | return arm_expand_neon_args (target, icode, 1, exp, | |
19208 | NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, NEON_ARG_STOP); | |
19209 | ||
19210 | case NEON_BINOP: | |
19211 | case NEON_SETLANE: | |
19212 | case NEON_SCALARMUL: | |
19213 | case NEON_SCALARMULL: | |
19214 | case NEON_SCALARMULH: | |
19215 | case NEON_SHIFTINSERT: | |
19216 | case NEON_LOGICBINOP: | |
19217 | return arm_expand_neon_args (target, icode, 1, exp, | |
19218 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, | |
19219 | NEON_ARG_STOP); | |
19220 | ||
19221 | case NEON_TERNOP: | |
19222 | return arm_expand_neon_args (target, icode, 1, exp, | |
19223 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, | |
19224 | NEON_ARG_CONSTANT, NEON_ARG_STOP); | |
19225 | ||
19226 | case NEON_GETLANE: | |
19227 | case NEON_FIXCONV: | |
19228 | case NEON_SHIFTIMM: | |
19229 | return arm_expand_neon_args (target, icode, 1, exp, | |
19230 | NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, NEON_ARG_CONSTANT, | |
19231 | NEON_ARG_STOP); | |
19232 | ||
19233 | case NEON_CREATE: | |
19234 | return arm_expand_neon_args (target, icode, 1, exp, | |
19235 | NEON_ARG_COPY_TO_REG, NEON_ARG_STOP); | |
19236 | ||
19237 | case NEON_DUP: | |
19238 | case NEON_SPLIT: | |
19239 | case NEON_REINTERP: | |
19240 | return arm_expand_neon_args (target, icode, 1, exp, | |
19241 | NEON_ARG_COPY_TO_REG, NEON_ARG_STOP); | |
19242 | ||
19243 | case NEON_COMBINE: | |
19244 | case NEON_VTBL: | |
19245 | return arm_expand_neon_args (target, icode, 1, exp, | |
19246 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_STOP); | |
19247 | ||
19248 | case NEON_RESULTPAIR: | |
19249 | return arm_expand_neon_args (target, icode, 0, exp, | |
19250 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, | |
19251 | NEON_ARG_STOP); | |
19252 | ||
19253 | case NEON_LANEMUL: | |
19254 | case NEON_LANEMULL: | |
19255 | case NEON_LANEMULH: | |
19256 | return arm_expand_neon_args (target, icode, 1, exp, | |
19257 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, | |
19258 | NEON_ARG_CONSTANT, NEON_ARG_STOP); | |
19259 | ||
19260 | case NEON_LANEMAC: | |
19261 | return arm_expand_neon_args (target, icode, 1, exp, | |
19262 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, | |
19263 | NEON_ARG_CONSTANT, NEON_ARG_CONSTANT, NEON_ARG_STOP); | |
19264 | ||
19265 | case NEON_SHIFTACC: | |
19266 | return arm_expand_neon_args (target, icode, 1, exp, | |
19267 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, | |
19268 | NEON_ARG_CONSTANT, NEON_ARG_STOP); | |
19269 | ||
19270 | case NEON_SCALARMAC: | |
19271 | return arm_expand_neon_args (target, icode, 1, exp, | |
19272 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, | |
19273 | NEON_ARG_CONSTANT, NEON_ARG_STOP); | |
19274 | ||
19275 | case NEON_SELECT: | |
19276 | case NEON_VTBX: | |
19277 | return arm_expand_neon_args (target, icode, 1, exp, | |
19278 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, | |
19279 | NEON_ARG_STOP); | |
19280 | ||
19281 | case NEON_LOAD1: | |
19282 | case NEON_LOADSTRUCT: | |
19283 | return arm_expand_neon_args (target, icode, 1, exp, | |
19284 | NEON_ARG_COPY_TO_REG, NEON_ARG_STOP); | |
19285 | ||
19286 | case NEON_LOAD1LANE: | |
19287 | case NEON_LOADSTRUCTLANE: | |
19288 | return arm_expand_neon_args (target, icode, 1, exp, | |
19289 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, | |
19290 | NEON_ARG_STOP); | |
19291 | ||
19292 | case NEON_STORE1: | |
19293 | case NEON_STORESTRUCT: | |
19294 | return arm_expand_neon_args (target, icode, 0, exp, | |
19295 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_STOP); | |
19296 | ||
19297 | case NEON_STORE1LANE: | |
19298 | case NEON_STORESTRUCTLANE: | |
19299 | return arm_expand_neon_args (target, icode, 0, exp, | |
19300 | NEON_ARG_COPY_TO_REG, NEON_ARG_COPY_TO_REG, NEON_ARG_CONSTANT, | |
19301 | NEON_ARG_STOP); | |
19302 | } | |
19303 | ||
19304 | gcc_unreachable (); | |
19305 | } | |
19306 | ||
19307 | /* Emit code to reinterpret one Neon type as another, without altering bits. */ | |
19308 | void | |
19309 | neon_reinterpret (rtx dest, rtx src) | |
19310 | { | |
19311 | emit_move_insn (dest, gen_lowpart (GET_MODE (dest), src)); | |
19312 | } | |
19313 | ||
19314 | /* Emit code to place a Neon pair result in memory locations (with equal | |
19315 | registers). */ | |
19316 | void | |
19317 | neon_emit_pair_result_insn (enum machine_mode mode, | |
19318 | rtx (*intfn) (rtx, rtx, rtx, rtx), rtx destaddr, | |
19319 | rtx op1, rtx op2) | |
19320 | { | |
19321 | rtx mem = gen_rtx_MEM (mode, destaddr); | |
19322 | rtx tmp1 = gen_reg_rtx (mode); | |
19323 | rtx tmp2 = gen_reg_rtx (mode); | |
19324 | ||
19325 | emit_insn (intfn (tmp1, op1, tmp2, op2)); | |
19326 | ||
19327 | emit_move_insn (mem, tmp1); | |
19328 | mem = adjust_address (mem, mode, GET_MODE_SIZE (mode)); | |
19329 | emit_move_insn (mem, tmp2); | |
19330 | } | |
19331 | ||
19332 | /* Set up operands for a register copy from src to dest, taking care not to | |
19333 | clobber registers in the process. | |
19334 | FIXME: This has rather high polynomial complexity (O(n^3)?) but shouldn't | |
19335 | be called with a large N, so that should be OK. */ | |
19336 | ||
19337 | void | |
19338 | neon_disambiguate_copy (rtx *operands, rtx *dest, rtx *src, unsigned int count) | |
19339 | { | |
19340 | unsigned int copied = 0, opctr = 0; | |
19341 | unsigned int done = (1 << count) - 1; | |
19342 | unsigned int i, j; | |
19343 | ||
19344 | while (copied != done) | |
19345 | { | |
19346 | for (i = 0; i < count; i++) | |
19347 | { | |
19348 | int good = 1; | |
19349 | ||
19350 | for (j = 0; good && j < count; j++) | |
19351 | if (i != j && (copied & (1 << j)) == 0 | |
19352 | && reg_overlap_mentioned_p (src[j], dest[i])) | |
19353 | good = 0; | |
19354 | ||
19355 | if (good) | |
19356 | { | |
19357 | operands[opctr++] = dest[i]; | |
19358 | operands[opctr++] = src[i]; | |
19359 | copied |= 1 << i; | |
19360 | } | |
19361 | } | |
19362 | } | |
19363 | ||
19364 | gcc_assert (opctr == count * 2); | |
19365 | } | |
19366 | ||
5a9335ef NC |
19367 | /* Expand an expression EXP that calls a built-in function, |
19368 | with result going to TARGET if that's convenient | |
19369 | (and in mode MODE if that's convenient). | |
19370 | SUBTARGET may be used as the target for computing one of EXP's operands. | |
19371 | IGNORE is nonzero if the value is to be ignored. */ | |
19372 | ||
19373 | static rtx | |
19374 | arm_expand_builtin (tree exp, | |
19375 | rtx target, | |
19376 | rtx subtarget ATTRIBUTE_UNUSED, | |
19377 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
19378 | int ignore ATTRIBUTE_UNUSED) | |
19379 | { | |
19380 | const struct builtin_description * d; | |
19381 | enum insn_code icode; | |
5039610b | 19382 | tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0); |
5a9335ef NC |
19383 | tree arg0; |
19384 | tree arg1; | |
19385 | tree arg2; | |
19386 | rtx op0; | |
19387 | rtx op1; | |
19388 | rtx op2; | |
19389 | rtx pat; | |
19390 | int fcode = DECL_FUNCTION_CODE (fndecl); | |
19391 | size_t i; | |
19392 | enum machine_mode tmode; | |
19393 | enum machine_mode mode0; | |
19394 | enum machine_mode mode1; | |
19395 | enum machine_mode mode2; | |
19396 | ||
88f77cba JB |
19397 | if (fcode >= ARM_BUILTIN_NEON_BASE) |
19398 | return arm_expand_neon_builtin (fcode, exp, target); | |
19399 | ||
5a9335ef NC |
19400 | switch (fcode) |
19401 | { | |
19402 | case ARM_BUILTIN_TEXTRMSB: | |
19403 | case ARM_BUILTIN_TEXTRMUB: | |
19404 | case ARM_BUILTIN_TEXTRMSH: | |
19405 | case ARM_BUILTIN_TEXTRMUH: | |
19406 | case ARM_BUILTIN_TEXTRMSW: | |
19407 | case ARM_BUILTIN_TEXTRMUW: | |
19408 | icode = (fcode == ARM_BUILTIN_TEXTRMSB ? CODE_FOR_iwmmxt_textrmsb | |
19409 | : fcode == ARM_BUILTIN_TEXTRMUB ? CODE_FOR_iwmmxt_textrmub | |
19410 | : fcode == ARM_BUILTIN_TEXTRMSH ? CODE_FOR_iwmmxt_textrmsh | |
19411 | : fcode == ARM_BUILTIN_TEXTRMUH ? CODE_FOR_iwmmxt_textrmuh | |
19412 | : CODE_FOR_iwmmxt_textrmw); | |
19413 | ||
5039610b SL |
19414 | arg0 = CALL_EXPR_ARG (exp, 0); |
19415 | arg1 = CALL_EXPR_ARG (exp, 1); | |
84217346 MD |
19416 | op0 = expand_normal (arg0); |
19417 | op1 = expand_normal (arg1); | |
5a9335ef NC |
19418 | tmode = insn_data[icode].operand[0].mode; |
19419 | mode0 = insn_data[icode].operand[1].mode; | |
19420 | mode1 = insn_data[icode].operand[2].mode; | |
19421 | ||
19422 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
19423 | op0 = copy_to_mode_reg (mode0, op0); | |
19424 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
19425 | { | |
19426 | /* @@@ better error message */ | |
19427 | error ("selector must be an immediate"); | |
19428 | return gen_reg_rtx (tmode); | |
19429 | } | |
19430 | if (target == 0 | |
19431 | || GET_MODE (target) != tmode | |
19432 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
19433 | target = gen_reg_rtx (tmode); | |
19434 | pat = GEN_FCN (icode) (target, op0, op1); | |
19435 | if (! pat) | |
19436 | return 0; | |
19437 | emit_insn (pat); | |
19438 | return target; | |
19439 | ||
19440 | case ARM_BUILTIN_TINSRB: | |
19441 | case ARM_BUILTIN_TINSRH: | |
19442 | case ARM_BUILTIN_TINSRW: | |
19443 | icode = (fcode == ARM_BUILTIN_TINSRB ? CODE_FOR_iwmmxt_tinsrb | |
19444 | : fcode == ARM_BUILTIN_TINSRH ? CODE_FOR_iwmmxt_tinsrh | |
19445 | : CODE_FOR_iwmmxt_tinsrw); | |
5039610b SL |
19446 | arg0 = CALL_EXPR_ARG (exp, 0); |
19447 | arg1 = CALL_EXPR_ARG (exp, 1); | |
19448 | arg2 = CALL_EXPR_ARG (exp, 2); | |
84217346 MD |
19449 | op0 = expand_normal (arg0); |
19450 | op1 = expand_normal (arg1); | |
19451 | op2 = expand_normal (arg2); | |
5a9335ef NC |
19452 | tmode = insn_data[icode].operand[0].mode; |
19453 | mode0 = insn_data[icode].operand[1].mode; | |
19454 | mode1 = insn_data[icode].operand[2].mode; | |
19455 | mode2 = insn_data[icode].operand[3].mode; | |
19456 | ||
19457 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
19458 | op0 = copy_to_mode_reg (mode0, op0); | |
19459 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
19460 | op1 = copy_to_mode_reg (mode1, op1); | |
19461 | if (! (*insn_data[icode].operand[3].predicate) (op2, mode2)) | |
19462 | { | |
19463 | /* @@@ better error message */ | |
19464 | error ("selector must be an immediate"); | |
19465 | return const0_rtx; | |
19466 | } | |
19467 | if (target == 0 | |
19468 | || GET_MODE (target) != tmode | |
19469 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
19470 | target = gen_reg_rtx (tmode); | |
19471 | pat = GEN_FCN (icode) (target, op0, op1, op2); | |
19472 | if (! pat) | |
19473 | return 0; | |
19474 | emit_insn (pat); | |
19475 | return target; | |
19476 | ||
19477 | case ARM_BUILTIN_SETWCX: | |
5039610b SL |
19478 | arg0 = CALL_EXPR_ARG (exp, 0); |
19479 | arg1 = CALL_EXPR_ARG (exp, 1); | |
84217346 MD |
19480 | op0 = force_reg (SImode, expand_normal (arg0)); |
19481 | op1 = expand_normal (arg1); | |
f07a6b21 | 19482 | emit_insn (gen_iwmmxt_tmcr (op1, op0)); |
5a9335ef NC |
19483 | return 0; |
19484 | ||
19485 | case ARM_BUILTIN_GETWCX: | |
5039610b | 19486 | arg0 = CALL_EXPR_ARG (exp, 0); |
84217346 | 19487 | op0 = expand_normal (arg0); |
5a9335ef NC |
19488 | target = gen_reg_rtx (SImode); |
19489 | emit_insn (gen_iwmmxt_tmrc (target, op0)); | |
19490 | return target; | |
19491 | ||
19492 | case ARM_BUILTIN_WSHUFH: | |
19493 | icode = CODE_FOR_iwmmxt_wshufh; | |
5039610b SL |
19494 | arg0 = CALL_EXPR_ARG (exp, 0); |
19495 | arg1 = CALL_EXPR_ARG (exp, 1); | |
84217346 MD |
19496 | op0 = expand_normal (arg0); |
19497 | op1 = expand_normal (arg1); | |
5a9335ef NC |
19498 | tmode = insn_data[icode].operand[0].mode; |
19499 | mode1 = insn_data[icode].operand[1].mode; | |
19500 | mode2 = insn_data[icode].operand[2].mode; | |
19501 | ||
19502 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode1)) | |
19503 | op0 = copy_to_mode_reg (mode1, op0); | |
19504 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode2)) | |
19505 | { | |
19506 | /* @@@ better error message */ | |
19507 | error ("mask must be an immediate"); | |
19508 | return const0_rtx; | |
19509 | } | |
19510 | if (target == 0 | |
19511 | || GET_MODE (target) != tmode | |
19512 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
19513 | target = gen_reg_rtx (tmode); | |
19514 | pat = GEN_FCN (icode) (target, op0, op1); | |
19515 | if (! pat) | |
19516 | return 0; | |
19517 | emit_insn (pat); | |
19518 | return target; | |
19519 | ||
19520 | case ARM_BUILTIN_WSADB: | |
5039610b | 19521 | return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadb, exp, target); |
5a9335ef | 19522 | case ARM_BUILTIN_WSADH: |
5039610b | 19523 | return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadh, exp, target); |
5a9335ef | 19524 | case ARM_BUILTIN_WSADBZ: |
5039610b | 19525 | return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadbz, exp, target); |
5a9335ef | 19526 | case ARM_BUILTIN_WSADHZ: |
5039610b | 19527 | return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadhz, exp, target); |
5a9335ef NC |
19528 | |
19529 | /* Several three-argument builtins. */ | |
19530 | case ARM_BUILTIN_WMACS: | |
19531 | case ARM_BUILTIN_WMACU: | |
19532 | case ARM_BUILTIN_WALIGN: | |
19533 | case ARM_BUILTIN_TMIA: | |
19534 | case ARM_BUILTIN_TMIAPH: | |
19535 | case ARM_BUILTIN_TMIATT: | |
19536 | case ARM_BUILTIN_TMIATB: | |
19537 | case ARM_BUILTIN_TMIABT: | |
19538 | case ARM_BUILTIN_TMIABB: | |
19539 | icode = (fcode == ARM_BUILTIN_WMACS ? CODE_FOR_iwmmxt_wmacs | |
19540 | : fcode == ARM_BUILTIN_WMACU ? CODE_FOR_iwmmxt_wmacu | |
19541 | : fcode == ARM_BUILTIN_TMIA ? CODE_FOR_iwmmxt_tmia | |
19542 | : fcode == ARM_BUILTIN_TMIAPH ? CODE_FOR_iwmmxt_tmiaph | |
19543 | : fcode == ARM_BUILTIN_TMIABB ? CODE_FOR_iwmmxt_tmiabb | |
19544 | : fcode == ARM_BUILTIN_TMIABT ? CODE_FOR_iwmmxt_tmiabt | |
19545 | : fcode == ARM_BUILTIN_TMIATB ? CODE_FOR_iwmmxt_tmiatb | |
19546 | : fcode == ARM_BUILTIN_TMIATT ? CODE_FOR_iwmmxt_tmiatt | |
19547 | : CODE_FOR_iwmmxt_walign); | |
5039610b SL |
19548 | arg0 = CALL_EXPR_ARG (exp, 0); |
19549 | arg1 = CALL_EXPR_ARG (exp, 1); | |
19550 | arg2 = CALL_EXPR_ARG (exp, 2); | |
84217346 MD |
19551 | op0 = expand_normal (arg0); |
19552 | op1 = expand_normal (arg1); | |
19553 | op2 = expand_normal (arg2); | |
5a9335ef NC |
19554 | tmode = insn_data[icode].operand[0].mode; |
19555 | mode0 = insn_data[icode].operand[1].mode; | |
19556 | mode1 = insn_data[icode].operand[2].mode; | |
19557 | mode2 = insn_data[icode].operand[3].mode; | |
19558 | ||
19559 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
19560 | op0 = copy_to_mode_reg (mode0, op0); | |
19561 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
19562 | op1 = copy_to_mode_reg (mode1, op1); | |
19563 | if (! (*insn_data[icode].operand[3].predicate) (op2, mode2)) | |
19564 | op2 = copy_to_mode_reg (mode2, op2); | |
19565 | if (target == 0 | |
19566 | || GET_MODE (target) != tmode | |
19567 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
19568 | target = gen_reg_rtx (tmode); | |
19569 | pat = GEN_FCN (icode) (target, op0, op1, op2); | |
19570 | if (! pat) | |
19571 | return 0; | |
19572 | emit_insn (pat); | |
19573 | return target; | |
f676971a | 19574 | |
5a9335ef NC |
19575 | case ARM_BUILTIN_WZERO: |
19576 | target = gen_reg_rtx (DImode); | |
19577 | emit_insn (gen_iwmmxt_clrdi (target)); | |
19578 | return target; | |
19579 | ||
d3585b76 DJ |
19580 | case ARM_BUILTIN_THREAD_POINTER: |
19581 | return arm_load_tp (target); | |
19582 | ||
5a9335ef NC |
19583 | default: |
19584 | break; | |
19585 | } | |
19586 | ||
e97a46ce | 19587 | for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++) |
5a9335ef | 19588 | if (d->code == (const enum arm_builtins) fcode) |
5039610b | 19589 | return arm_expand_binop_builtin (d->icode, exp, target); |
5a9335ef | 19590 | |
e97a46ce | 19591 | for (i = 0, d = bdesc_1arg; i < ARRAY_SIZE (bdesc_1arg); i++, d++) |
5a9335ef | 19592 | if (d->code == (const enum arm_builtins) fcode) |
5039610b | 19593 | return arm_expand_unop_builtin (d->icode, exp, target, 0); |
5a9335ef NC |
19594 | |
19595 | /* @@@ Should really do something sensible here. */ | |
19596 | return NULL_RTX; | |
19597 | } | |
19598 | \f | |
1d6e90ac NC |
19599 | /* Return the number (counting from 0) of |
19600 | the least significant set bit in MASK. */ | |
19601 | ||
e32bac5b | 19602 | inline static int |
b279b20a | 19603 | number_of_first_bit_set (unsigned mask) |
d5b7b3ae RE |
19604 | { |
19605 | int bit; | |
19606 | ||
19607 | for (bit = 0; | |
19608 | (mask & (1 << bit)) == 0; | |
5895f793 | 19609 | ++bit) |
d5b7b3ae RE |
19610 | continue; |
19611 | ||
19612 | return bit; | |
19613 | } | |
19614 | ||
b279b20a NC |
19615 | /* Emit code to push or pop registers to or from the stack. F is the |
19616 | assembly file. MASK is the registers to push or pop. PUSH is | |
19617 | nonzero if we should push, and zero if we should pop. For debugging | |
19618 | output, if pushing, adjust CFA_OFFSET by the amount of space added | |
19619 | to the stack. REAL_REGS should have the same number of bits set as | |
19620 | MASK, and will be used instead (in the same order) to describe which | |
19621 | registers were saved - this is used to mark the save slots when we | |
19622 | push high registers after moving them to low registers. */ | |
19623 | static void | |
19624 | thumb_pushpop (FILE *f, unsigned long mask, int push, int *cfa_offset, | |
19625 | unsigned long real_regs) | |
19626 | { | |
19627 | int regno; | |
19628 | int lo_mask = mask & 0xFF; | |
19629 | int pushed_words = 0; | |
19630 | ||
e6d29d15 | 19631 | gcc_assert (mask); |
b279b20a NC |
19632 | |
19633 | if (lo_mask == 0 && !push && (mask & (1 << PC_REGNUM))) | |
19634 | { | |
19635 | /* Special case. Do not generate a POP PC statement here, do it in | |
19636 | thumb_exit() */ | |
19637 | thumb_exit (f, -1); | |
19638 | return; | |
19639 | } | |
19640 | ||
f0a0390e | 19641 | if (push && arm_except_unwind_info () == UI_TARGET) |
617a1b71 PB |
19642 | { |
19643 | fprintf (f, "\t.save\t{"); | |
19644 | for (regno = 0; regno < 15; regno++) | |
19645 | { | |
19646 | if (real_regs & (1 << regno)) | |
19647 | { | |
19648 | if (real_regs & ((1 << regno) -1)) | |
19649 | fprintf (f, ", "); | |
19650 | asm_fprintf (f, "%r", regno); | |
19651 | } | |
19652 | } | |
19653 | fprintf (f, "}\n"); | |
19654 | } | |
19655 | ||
b279b20a NC |
19656 | fprintf (f, "\t%s\t{", push ? "push" : "pop"); |
19657 | ||
19658 | /* Look at the low registers first. */ | |
19659 | for (regno = 0; regno <= LAST_LO_REGNUM; regno++, lo_mask >>= 1) | |
19660 | { | |
19661 | if (lo_mask & 1) | |
19662 | { | |
19663 | asm_fprintf (f, "%r", regno); | |
19664 | ||
19665 | if ((lo_mask & ~1) != 0) | |
19666 | fprintf (f, ", "); | |
19667 | ||
19668 | pushed_words++; | |
19669 | } | |
19670 | } | |
19671 | ||
19672 | if (push && (mask & (1 << LR_REGNUM))) | |
19673 | { | |
19674 | /* Catch pushing the LR. */ | |
19675 | if (mask & 0xFF) | |
19676 | fprintf (f, ", "); | |
19677 | ||
19678 | asm_fprintf (f, "%r", LR_REGNUM); | |
19679 | ||
19680 | pushed_words++; | |
19681 | } | |
19682 | else if (!push && (mask & (1 << PC_REGNUM))) | |
19683 | { | |
19684 | /* Catch popping the PC. */ | |
19685 | if (TARGET_INTERWORK || TARGET_BACKTRACE | |
e3b5732b | 19686 | || crtl->calls_eh_return) |
b279b20a NC |
19687 | { |
19688 | /* The PC is never poped directly, instead | |
19689 | it is popped into r3 and then BX is used. */ | |
19690 | fprintf (f, "}\n"); | |
19691 | ||
19692 | thumb_exit (f, -1); | |
19693 | ||
19694 | return; | |
19695 | } | |
19696 | else | |
19697 | { | |
19698 | if (mask & 0xFF) | |
19699 | fprintf (f, ", "); | |
19700 | ||
19701 | asm_fprintf (f, "%r", PC_REGNUM); | |
19702 | } | |
19703 | } | |
19704 | ||
19705 | fprintf (f, "}\n"); | |
19706 | ||
19707 | if (push && pushed_words && dwarf2out_do_frame ()) | |
19708 | { | |
d342c045 | 19709 | char *l = dwarf2out_cfi_label (false); |
b279b20a NC |
19710 | int pushed_mask = real_regs; |
19711 | ||
19712 | *cfa_offset += pushed_words * 4; | |
19713 | dwarf2out_def_cfa (l, SP_REGNUM, *cfa_offset); | |
19714 | ||
19715 | pushed_words = 0; | |
19716 | pushed_mask = real_regs; | |
19717 | for (regno = 0; regno <= 14; regno++, pushed_mask >>= 1) | |
19718 | { | |
19719 | if (pushed_mask & 1) | |
19720 | dwarf2out_reg_save (l, regno, 4 * pushed_words++ - *cfa_offset); | |
19721 | } | |
19722 | } | |
19723 | } | |
19724 | ||
d5b7b3ae RE |
19725 | /* Generate code to return from a thumb function. |
19726 | If 'reg_containing_return_addr' is -1, then the return address is | |
19727 | actually on the stack, at the stack pointer. */ | |
19728 | static void | |
c9ca9b88 | 19729 | thumb_exit (FILE *f, int reg_containing_return_addr) |
d5b7b3ae RE |
19730 | { |
19731 | unsigned regs_available_for_popping; | |
19732 | unsigned regs_to_pop; | |
19733 | int pops_needed; | |
19734 | unsigned available; | |
19735 | unsigned required; | |
19736 | int mode; | |
19737 | int size; | |
19738 | int restore_a4 = FALSE; | |
19739 | ||
19740 | /* Compute the registers we need to pop. */ | |
19741 | regs_to_pop = 0; | |
19742 | pops_needed = 0; | |
19743 | ||
c9ca9b88 | 19744 | if (reg_containing_return_addr == -1) |
d5b7b3ae | 19745 | { |
d5b7b3ae | 19746 | regs_to_pop |= 1 << LR_REGNUM; |
5895f793 | 19747 | ++pops_needed; |
d5b7b3ae RE |
19748 | } |
19749 | ||
19750 | if (TARGET_BACKTRACE) | |
19751 | { | |
19752 | /* Restore the (ARM) frame pointer and stack pointer. */ | |
19753 | regs_to_pop |= (1 << ARM_HARD_FRAME_POINTER_REGNUM) | (1 << SP_REGNUM); | |
19754 | pops_needed += 2; | |
19755 | } | |
19756 | ||
19757 | /* If there is nothing to pop then just emit the BX instruction and | |
19758 | return. */ | |
19759 | if (pops_needed == 0) | |
19760 | { | |
e3b5732b | 19761 | if (crtl->calls_eh_return) |
c9ca9b88 | 19762 | asm_fprintf (f, "\tadd\t%r, %r\n", SP_REGNUM, ARM_EH_STACKADJ_REGNUM); |
d5b7b3ae RE |
19763 | |
19764 | asm_fprintf (f, "\tbx\t%r\n", reg_containing_return_addr); | |
19765 | return; | |
19766 | } | |
19767 | /* Otherwise if we are not supporting interworking and we have not created | |
19768 | a backtrace structure and the function was not entered in ARM mode then | |
19769 | just pop the return address straight into the PC. */ | |
5895f793 RE |
19770 | else if (!TARGET_INTERWORK |
19771 | && !TARGET_BACKTRACE | |
c9ca9b88 | 19772 | && !is_called_in_ARM_mode (current_function_decl) |
e3b5732b | 19773 | && !crtl->calls_eh_return) |
d5b7b3ae | 19774 | { |
c9ca9b88 | 19775 | asm_fprintf (f, "\tpop\t{%r}\n", PC_REGNUM); |
d5b7b3ae RE |
19776 | return; |
19777 | } | |
19778 | ||
19779 | /* Find out how many of the (return) argument registers we can corrupt. */ | |
19780 | regs_available_for_popping = 0; | |
19781 | ||
19782 | /* If returning via __builtin_eh_return, the bottom three registers | |
19783 | all contain information needed for the return. */ | |
e3b5732b | 19784 | if (crtl->calls_eh_return) |
d5b7b3ae RE |
19785 | size = 12; |
19786 | else | |
19787 | { | |
d5b7b3ae RE |
19788 | /* If we can deduce the registers used from the function's |
19789 | return value. This is more reliable that examining | |
6fb5fa3c | 19790 | df_regs_ever_live_p () because that will be set if the register is |
d5b7b3ae RE |
19791 | ever used in the function, not just if the register is used |
19792 | to hold a return value. */ | |
19793 | ||
38173d38 JH |
19794 | if (crtl->return_rtx != 0) |
19795 | mode = GET_MODE (crtl->return_rtx); | |
d5b7b3ae | 19796 | else |
d5b7b3ae RE |
19797 | mode = DECL_MODE (DECL_RESULT (current_function_decl)); |
19798 | ||
19799 | size = GET_MODE_SIZE (mode); | |
19800 | ||
19801 | if (size == 0) | |
19802 | { | |
19803 | /* In a void function we can use any argument register. | |
19804 | In a function that returns a structure on the stack | |
19805 | we can use the second and third argument registers. */ | |
19806 | if (mode == VOIDmode) | |
19807 | regs_available_for_popping = | |
19808 | (1 << ARG_REGISTER (1)) | |
19809 | | (1 << ARG_REGISTER (2)) | |
19810 | | (1 << ARG_REGISTER (3)); | |
19811 | else | |
19812 | regs_available_for_popping = | |
19813 | (1 << ARG_REGISTER (2)) | |
19814 | | (1 << ARG_REGISTER (3)); | |
19815 | } | |
19816 | else if (size <= 4) | |
19817 | regs_available_for_popping = | |
19818 | (1 << ARG_REGISTER (2)) | |
19819 | | (1 << ARG_REGISTER (3)); | |
19820 | else if (size <= 8) | |
19821 | regs_available_for_popping = | |
19822 | (1 << ARG_REGISTER (3)); | |
19823 | } | |
19824 | ||
19825 | /* Match registers to be popped with registers into which we pop them. */ | |
19826 | for (available = regs_available_for_popping, | |
19827 | required = regs_to_pop; | |
19828 | required != 0 && available != 0; | |
19829 | available &= ~(available & - available), | |
19830 | required &= ~(required & - required)) | |
19831 | -- pops_needed; | |
19832 | ||
19833 | /* If we have any popping registers left over, remove them. */ | |
19834 | if (available > 0) | |
5895f793 | 19835 | regs_available_for_popping &= ~available; |
f676971a | 19836 | |
d5b7b3ae RE |
19837 | /* Otherwise if we need another popping register we can use |
19838 | the fourth argument register. */ | |
19839 | else if (pops_needed) | |
19840 | { | |
19841 | /* If we have not found any free argument registers and | |
19842 | reg a4 contains the return address, we must move it. */ | |
19843 | if (regs_available_for_popping == 0 | |
19844 | && reg_containing_return_addr == LAST_ARG_REGNUM) | |
19845 | { | |
19846 | asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, LAST_ARG_REGNUM); | |
19847 | reg_containing_return_addr = LR_REGNUM; | |
19848 | } | |
19849 | else if (size > 12) | |
19850 | { | |
19851 | /* Register a4 is being used to hold part of the return value, | |
19852 | but we have dire need of a free, low register. */ | |
19853 | restore_a4 = TRUE; | |
f676971a | 19854 | |
d5b7b3ae RE |
19855 | asm_fprintf (f, "\tmov\t%r, %r\n",IP_REGNUM, LAST_ARG_REGNUM); |
19856 | } | |
f676971a | 19857 | |
d5b7b3ae RE |
19858 | if (reg_containing_return_addr != LAST_ARG_REGNUM) |
19859 | { | |
19860 | /* The fourth argument register is available. */ | |
19861 | regs_available_for_popping |= 1 << LAST_ARG_REGNUM; | |
f676971a | 19862 | |
5895f793 | 19863 | --pops_needed; |
d5b7b3ae RE |
19864 | } |
19865 | } | |
19866 | ||
19867 | /* Pop as many registers as we can. */ | |
980e61bb DJ |
19868 | thumb_pushpop (f, regs_available_for_popping, FALSE, NULL, |
19869 | regs_available_for_popping); | |
d5b7b3ae RE |
19870 | |
19871 | /* Process the registers we popped. */ | |
19872 | if (reg_containing_return_addr == -1) | |
19873 | { | |
19874 | /* The return address was popped into the lowest numbered register. */ | |
5895f793 | 19875 | regs_to_pop &= ~(1 << LR_REGNUM); |
f676971a | 19876 | |
d5b7b3ae RE |
19877 | reg_containing_return_addr = |
19878 | number_of_first_bit_set (regs_available_for_popping); | |
19879 | ||
19880 | /* Remove this register for the mask of available registers, so that | |
6bc82793 | 19881 | the return address will not be corrupted by further pops. */ |
5895f793 | 19882 | regs_available_for_popping &= ~(1 << reg_containing_return_addr); |
d5b7b3ae RE |
19883 | } |
19884 | ||
19885 | /* If we popped other registers then handle them here. */ | |
19886 | if (regs_available_for_popping) | |
19887 | { | |
19888 | int frame_pointer; | |
f676971a | 19889 | |
d5b7b3ae RE |
19890 | /* Work out which register currently contains the frame pointer. */ |
19891 | frame_pointer = number_of_first_bit_set (regs_available_for_popping); | |
19892 | ||
19893 | /* Move it into the correct place. */ | |
19894 | asm_fprintf (f, "\tmov\t%r, %r\n", | |
19895 | ARM_HARD_FRAME_POINTER_REGNUM, frame_pointer); | |
19896 | ||
19897 | /* (Temporarily) remove it from the mask of popped registers. */ | |
5895f793 RE |
19898 | regs_available_for_popping &= ~(1 << frame_pointer); |
19899 | regs_to_pop &= ~(1 << ARM_HARD_FRAME_POINTER_REGNUM); | |
f676971a | 19900 | |
d5b7b3ae RE |
19901 | if (regs_available_for_popping) |
19902 | { | |
19903 | int stack_pointer; | |
f676971a | 19904 | |
d5b7b3ae RE |
19905 | /* We popped the stack pointer as well, |
19906 | find the register that contains it. */ | |
19907 | stack_pointer = number_of_first_bit_set (regs_available_for_popping); | |
19908 | ||
19909 | /* Move it into the stack register. */ | |
19910 | asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, stack_pointer); | |
f676971a | 19911 | |
d5b7b3ae RE |
19912 | /* At this point we have popped all necessary registers, so |
19913 | do not worry about restoring regs_available_for_popping | |
19914 | to its correct value: | |
19915 | ||
19916 | assert (pops_needed == 0) | |
19917 | assert (regs_available_for_popping == (1 << frame_pointer)) | |
19918 | assert (regs_to_pop == (1 << STACK_POINTER)) */ | |
19919 | } | |
19920 | else | |
19921 | { | |
19922 | /* Since we have just move the popped value into the frame | |
19923 | pointer, the popping register is available for reuse, and | |
19924 | we know that we still have the stack pointer left to pop. */ | |
19925 | regs_available_for_popping |= (1 << frame_pointer); | |
19926 | } | |
19927 | } | |
f676971a | 19928 | |
d5b7b3ae RE |
19929 | /* If we still have registers left on the stack, but we no longer have |
19930 | any registers into which we can pop them, then we must move the return | |
19931 | address into the link register and make available the register that | |
19932 | contained it. */ | |
19933 | if (regs_available_for_popping == 0 && pops_needed > 0) | |
19934 | { | |
19935 | regs_available_for_popping |= 1 << reg_containing_return_addr; | |
f676971a | 19936 | |
d5b7b3ae RE |
19937 | asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, |
19938 | reg_containing_return_addr); | |
f676971a | 19939 | |
d5b7b3ae RE |
19940 | reg_containing_return_addr = LR_REGNUM; |
19941 | } | |
19942 | ||
19943 | /* If we have registers left on the stack then pop some more. | |
19944 | We know that at most we will want to pop FP and SP. */ | |
19945 | if (pops_needed > 0) | |
19946 | { | |
19947 | int popped_into; | |
19948 | int move_to; | |
f676971a | 19949 | |
980e61bb DJ |
19950 | thumb_pushpop (f, regs_available_for_popping, FALSE, NULL, |
19951 | regs_available_for_popping); | |
d5b7b3ae RE |
19952 | |
19953 | /* We have popped either FP or SP. | |
19954 | Move whichever one it is into the correct register. */ | |
19955 | popped_into = number_of_first_bit_set (regs_available_for_popping); | |
19956 | move_to = number_of_first_bit_set (regs_to_pop); | |
19957 | ||
19958 | asm_fprintf (f, "\tmov\t%r, %r\n", move_to, popped_into); | |
19959 | ||
5895f793 | 19960 | regs_to_pop &= ~(1 << move_to); |
d5b7b3ae | 19961 | |
5895f793 | 19962 | --pops_needed; |
d5b7b3ae | 19963 | } |
f676971a | 19964 | |
d5b7b3ae RE |
19965 | /* If we still have not popped everything then we must have only |
19966 | had one register available to us and we are now popping the SP. */ | |
19967 | if (pops_needed > 0) | |
19968 | { | |
19969 | int popped_into; | |
f676971a | 19970 | |
980e61bb DJ |
19971 | thumb_pushpop (f, regs_available_for_popping, FALSE, NULL, |
19972 | regs_available_for_popping); | |
d5b7b3ae RE |
19973 | |
19974 | popped_into = number_of_first_bit_set (regs_available_for_popping); | |
19975 | ||
19976 | asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, popped_into); | |
19977 | /* | |
19978 | assert (regs_to_pop == (1 << STACK_POINTER)) | |
19979 | assert (pops_needed == 1) | |
19980 | */ | |
19981 | } | |
19982 | ||
19983 | /* If necessary restore the a4 register. */ | |
19984 | if (restore_a4) | |
19985 | { | |
19986 | if (reg_containing_return_addr != LR_REGNUM) | |
19987 | { | |
19988 | asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, LAST_ARG_REGNUM); | |
19989 | reg_containing_return_addr = LR_REGNUM; | |
19990 | } | |
f676971a | 19991 | |
d5b7b3ae RE |
19992 | asm_fprintf (f, "\tmov\t%r, %r\n", LAST_ARG_REGNUM, IP_REGNUM); |
19993 | } | |
19994 | ||
e3b5732b | 19995 | if (crtl->calls_eh_return) |
c9ca9b88 | 19996 | asm_fprintf (f, "\tadd\t%r, %r\n", SP_REGNUM, ARM_EH_STACKADJ_REGNUM); |
d5b7b3ae RE |
19997 | |
19998 | /* Return to caller. */ | |
19999 | asm_fprintf (f, "\tbx\t%r\n", reg_containing_return_addr); | |
20000 | } | |
d5b7b3ae | 20001 | \f |
906668bb BS |
20002 | /* Scan INSN just before assembler is output for it. |
20003 | For Thumb-1, we track the status of the condition codes; this | |
20004 | information is used in the cbranchsi4_insn pattern. */ | |
d5b7b3ae | 20005 | void |
5b3e6663 | 20006 | thumb1_final_prescan_insn (rtx insn) |
d5b7b3ae | 20007 | { |
d5b7b3ae | 20008 | if (flag_print_asm_name) |
9d98a694 AO |
20009 | asm_fprintf (asm_out_file, "%@ 0x%04x\n", |
20010 | INSN_ADDRESSES (INSN_UID (insn))); | |
906668bb BS |
20011 | /* Don't overwrite the previous setter when we get to a cbranch. */ |
20012 | if (INSN_CODE (insn) != CODE_FOR_cbranchsi4_insn) | |
20013 | { | |
20014 | enum attr_conds conds; | |
20015 | ||
20016 | if (cfun->machine->thumb1_cc_insn) | |
20017 | { | |
20018 | if (modified_in_p (cfun->machine->thumb1_cc_op0, insn) | |
20019 | || modified_in_p (cfun->machine->thumb1_cc_op1, insn)) | |
20020 | CC_STATUS_INIT; | |
20021 | } | |
20022 | conds = get_attr_conds (insn); | |
20023 | if (conds == CONDS_SET) | |
20024 | { | |
20025 | rtx set = single_set (insn); | |
20026 | cfun->machine->thumb1_cc_insn = insn; | |
20027 | cfun->machine->thumb1_cc_op0 = SET_DEST (set); | |
20028 | cfun->machine->thumb1_cc_op1 = const0_rtx; | |
20029 | cfun->machine->thumb1_cc_mode = CC_NOOVmode; | |
20030 | if (INSN_CODE (insn) == CODE_FOR_thumb1_subsi3_insn) | |
20031 | { | |
20032 | rtx src1 = XEXP (SET_SRC (set), 1); | |
20033 | if (src1 == const0_rtx) | |
20034 | cfun->machine->thumb1_cc_mode = CCmode; | |
20035 | } | |
20036 | } | |
20037 | else if (conds != CONDS_NOCOND) | |
20038 | cfun->machine->thumb1_cc_insn = NULL_RTX; | |
20039 | } | |
d5b7b3ae RE |
20040 | } |
20041 | ||
20042 | int | |
e32bac5b | 20043 | thumb_shiftable_const (unsigned HOST_WIDE_INT val) |
d5b7b3ae RE |
20044 | { |
20045 | unsigned HOST_WIDE_INT mask = 0xff; | |
20046 | int i; | |
20047 | ||
ce41c38b | 20048 | val = val & (unsigned HOST_WIDE_INT)0xffffffffu; |
d5b7b3ae RE |
20049 | if (val == 0) /* XXX */ |
20050 | return 0; | |
f676971a | 20051 | |
d5b7b3ae RE |
20052 | for (i = 0; i < 25; i++) |
20053 | if ((val & (mask << i)) == val) | |
20054 | return 1; | |
20055 | ||
20056 | return 0; | |
20057 | } | |
20058 | ||
825dda42 | 20059 | /* Returns nonzero if the current function contains, |
d5b7b3ae | 20060 | or might contain a far jump. */ |
5848830f PB |
20061 | static int |
20062 | thumb_far_jump_used_p (void) | |
d5b7b3ae RE |
20063 | { |
20064 | rtx insn; | |
20065 | ||
20066 | /* This test is only important for leaf functions. */ | |
5895f793 | 20067 | /* assert (!leaf_function_p ()); */ |
f676971a | 20068 | |
d5b7b3ae RE |
20069 | /* If we have already decided that far jumps may be used, |
20070 | do not bother checking again, and always return true even if | |
20071 | it turns out that they are not being used. Once we have made | |
20072 | the decision that far jumps are present (and that hence the link | |
20073 | register will be pushed onto the stack) we cannot go back on it. */ | |
20074 | if (cfun->machine->far_jump_used) | |
20075 | return 1; | |
20076 | ||
20077 | /* If this function is not being called from the prologue/epilogue | |
20078 | generation code then it must be being called from the | |
20079 | INITIAL_ELIMINATION_OFFSET macro. */ | |
5848830f | 20080 | if (!(ARM_DOUBLEWORD_ALIGN || reload_completed)) |
d5b7b3ae RE |
20081 | { |
20082 | /* In this case we know that we are being asked about the elimination | |
20083 | of the arg pointer register. If that register is not being used, | |
20084 | then there are no arguments on the stack, and we do not have to | |
20085 | worry that a far jump might force the prologue to push the link | |
20086 | register, changing the stack offsets. In this case we can just | |
20087 | return false, since the presence of far jumps in the function will | |
20088 | not affect stack offsets. | |
20089 | ||
20090 | If the arg pointer is live (or if it was live, but has now been | |
20091 | eliminated and so set to dead) then we do have to test to see if | |
20092 | the function might contain a far jump. This test can lead to some | |
20093 | false negatives, since before reload is completed, then length of | |
20094 | branch instructions is not known, so gcc defaults to returning their | |
20095 | longest length, which in turn sets the far jump attribute to true. | |
20096 | ||
20097 | A false negative will not result in bad code being generated, but it | |
20098 | will result in a needless push and pop of the link register. We | |
5848830f PB |
20099 | hope that this does not occur too often. |
20100 | ||
20101 | If we need doubleword stack alignment this could affect the other | |
20102 | elimination offsets so we can't risk getting it wrong. */ | |
6fb5fa3c | 20103 | if (df_regs_ever_live_p (ARG_POINTER_REGNUM)) |
d5b7b3ae | 20104 | cfun->machine->arg_pointer_live = 1; |
5895f793 | 20105 | else if (!cfun->machine->arg_pointer_live) |
d5b7b3ae RE |
20106 | return 0; |
20107 | } | |
20108 | ||
20109 | /* Check to see if the function contains a branch | |
20110 | insn with the far jump attribute set. */ | |
20111 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
20112 | { | |
20113 | if (GET_CODE (insn) == JUMP_INSN | |
20114 | /* Ignore tablejump patterns. */ | |
20115 | && GET_CODE (PATTERN (insn)) != ADDR_VEC | |
20116 | && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC | |
20117 | && get_attr_far_jump (insn) == FAR_JUMP_YES | |
20118 | ) | |
20119 | { | |
9a9f7594 | 20120 | /* Record the fact that we have decided that |
d5b7b3ae RE |
20121 | the function does use far jumps. */ |
20122 | cfun->machine->far_jump_used = 1; | |
20123 | return 1; | |
20124 | } | |
20125 | } | |
f676971a | 20126 | |
d5b7b3ae RE |
20127 | return 0; |
20128 | } | |
20129 | ||
825dda42 | 20130 | /* Return nonzero if FUNC must be entered in ARM mode. */ |
d5b7b3ae | 20131 | int |
e32bac5b | 20132 | is_called_in_ARM_mode (tree func) |
d5b7b3ae | 20133 | { |
e6d29d15 | 20134 | gcc_assert (TREE_CODE (func) == FUNCTION_DECL); |
d5b7b3ae | 20135 | |
696e78bf | 20136 | /* Ignore the problem about functions whose address is taken. */ |
d5b7b3ae RE |
20137 | if (TARGET_CALLEE_INTERWORKING && TREE_PUBLIC (func)) |
20138 | return TRUE; | |
20139 | ||
f676971a | 20140 | #ifdef ARM_PE |
91d231cb | 20141 | return lookup_attribute ("interfacearm", DECL_ATTRIBUTES (func)) != NULL_TREE; |
d5b7b3ae RE |
20142 | #else |
20143 | return FALSE; | |
20144 | #endif | |
20145 | } | |
20146 | ||
e784c52c BS |
20147 | /* Given the stack offsets and register mask in OFFSETS, decide how |
20148 | many additional registers to push instead of subtracting a constant | |
20149 | from SP. For epilogues the principle is the same except we use pop. | |
20150 | FOR_PROLOGUE indicates which we're generating. */ | |
20151 | static int | |
20152 | thumb1_extra_regs_pushed (arm_stack_offsets *offsets, bool for_prologue) | |
20153 | { | |
20154 | HOST_WIDE_INT amount; | |
20155 | unsigned long live_regs_mask = offsets->saved_regs_mask; | |
20156 | /* Extract a mask of the ones we can give to the Thumb's push/pop | |
20157 | instruction. */ | |
20158 | unsigned long l_mask = live_regs_mask & (for_prologue ? 0x40ff : 0xff); | |
20159 | /* Then count how many other high registers will need to be pushed. */ | |
20160 | unsigned long high_regs_pushed = bit_count (live_regs_mask & 0x0f00); | |
20161 | int n_free, reg_base; | |
20162 | ||
20163 | if (!for_prologue && frame_pointer_needed) | |
20164 | amount = offsets->locals_base - offsets->saved_regs; | |
20165 | else | |
20166 | amount = offsets->outgoing_args - offsets->saved_regs; | |
20167 | ||
20168 | /* If the stack frame size is 512 exactly, we can save one load | |
20169 | instruction, which should make this a win even when optimizing | |
20170 | for speed. */ | |
20171 | if (!optimize_size && amount != 512) | |
20172 | return 0; | |
20173 | ||
20174 | /* Can't do this if there are high registers to push. */ | |
20175 | if (high_regs_pushed != 0) | |
20176 | return 0; | |
20177 | ||
20178 | /* Shouldn't do it in the prologue if no registers would normally | |
20179 | be pushed at all. In the epilogue, also allow it if we'll have | |
20180 | a pop insn for the PC. */ | |
20181 | if (l_mask == 0 | |
20182 | && (for_prologue | |
20183 | || TARGET_BACKTRACE | |
20184 | || (live_regs_mask & 1 << LR_REGNUM) == 0 | |
20185 | || TARGET_INTERWORK | |
20186 | || crtl->args.pretend_args_size != 0)) | |
20187 | return 0; | |
20188 | ||
20189 | /* Don't do this if thumb_expand_prologue wants to emit instructions | |
20190 | between the push and the stack frame allocation. */ | |
20191 | if (for_prologue | |
20192 | && ((flag_pic && arm_pic_register != INVALID_REGNUM) | |
20193 | || (!frame_pointer_needed && CALLER_INTERWORKING_SLOT_SIZE > 0))) | |
20194 | return 0; | |
20195 | ||
20196 | reg_base = 0; | |
20197 | n_free = 0; | |
20198 | if (!for_prologue) | |
20199 | { | |
20200 | reg_base = arm_size_return_regs () / UNITS_PER_WORD; | |
20201 | live_regs_mask >>= reg_base; | |
20202 | } | |
20203 | ||
20204 | while (reg_base + n_free < 8 && !(live_regs_mask & 1) | |
20205 | && (for_prologue || call_used_regs[reg_base + n_free])) | |
20206 | { | |
20207 | live_regs_mask >>= 1; | |
20208 | n_free++; | |
20209 | } | |
20210 | ||
20211 | if (n_free == 0) | |
20212 | return 0; | |
20213 | gcc_assert (amount / 4 * 4 == amount); | |
20214 | ||
20215 | if (amount >= 512 && (amount - n_free * 4) < 512) | |
20216 | return (amount - 508) / 4; | |
20217 | if (amount <= n_free * 4) | |
20218 | return amount / 4; | |
20219 | return 0; | |
20220 | } | |
20221 | ||
d6b4baa4 | 20222 | /* The bits which aren't usefully expanded as rtl. */ |
cd2b33d0 | 20223 | const char * |
e32bac5b | 20224 | thumb_unexpanded_epilogue (void) |
d5b7b3ae | 20225 | { |
954954d1 | 20226 | arm_stack_offsets *offsets; |
d5b7b3ae | 20227 | int regno; |
b279b20a | 20228 | unsigned long live_regs_mask = 0; |
d5b7b3ae | 20229 | int high_regs_pushed = 0; |
e784c52c | 20230 | int extra_pop; |
d5b7b3ae | 20231 | int had_to_push_lr; |
57934c39 | 20232 | int size; |
d5b7b3ae | 20233 | |
934c2060 | 20234 | if (cfun->machine->return_used_this_function != 0) |
d5b7b3ae RE |
20235 | return ""; |
20236 | ||
58e60158 AN |
20237 | if (IS_NAKED (arm_current_func_type ())) |
20238 | return ""; | |
20239 | ||
954954d1 PB |
20240 | offsets = arm_get_frame_offsets (); |
20241 | live_regs_mask = offsets->saved_regs_mask; | |
57934c39 PB |
20242 | high_regs_pushed = bit_count (live_regs_mask & 0x0f00); |
20243 | ||
20244 | /* If we can deduce the registers used from the function's return value. | |
6fb5fa3c | 20245 | This is more reliable that examining df_regs_ever_live_p () because that |
57934c39 PB |
20246 | will be set if the register is ever used in the function, not just if |
20247 | the register is used to hold a return value. */ | |
4f5dfed0 | 20248 | size = arm_size_return_regs (); |
d5b7b3ae | 20249 | |
e784c52c BS |
20250 | extra_pop = thumb1_extra_regs_pushed (offsets, false); |
20251 | if (extra_pop > 0) | |
20252 | { | |
20253 | unsigned long extra_mask = (1 << extra_pop) - 1; | |
20254 | live_regs_mask |= extra_mask << (size / UNITS_PER_WORD); | |
20255 | } | |
20256 | ||
d5b7b3ae | 20257 | /* The prolog may have pushed some high registers to use as |
112cdef5 | 20258 | work registers. e.g. the testsuite file: |
d5b7b3ae RE |
20259 | gcc/testsuite/gcc/gcc.c-torture/execute/complex-2.c |
20260 | compiles to produce: | |
20261 | push {r4, r5, r6, r7, lr} | |
20262 | mov r7, r9 | |
20263 | mov r6, r8 | |
20264 | push {r6, r7} | |
20265 | as part of the prolog. We have to undo that pushing here. */ | |
f676971a | 20266 | |
d5b7b3ae RE |
20267 | if (high_regs_pushed) |
20268 | { | |
b279b20a | 20269 | unsigned long mask = live_regs_mask & 0xff; |
d5b7b3ae | 20270 | int next_hi_reg; |
d5b7b3ae | 20271 | |
57934c39 PB |
20272 | /* The available low registers depend on the size of the value we are |
20273 | returning. */ | |
20274 | if (size <= 12) | |
d5b7b3ae | 20275 | mask |= 1 << 3; |
57934c39 PB |
20276 | if (size <= 8) |
20277 | mask |= 1 << 2; | |
d5b7b3ae RE |
20278 | |
20279 | if (mask == 0) | |
20280 | /* Oh dear! We have no low registers into which we can pop | |
20281 | high registers! */ | |
400500c4 RK |
20282 | internal_error |
20283 | ("no low registers available for popping high registers"); | |
f676971a | 20284 | |
d5b7b3ae | 20285 | for (next_hi_reg = 8; next_hi_reg < 13; next_hi_reg++) |
57934c39 | 20286 | if (live_regs_mask & (1 << next_hi_reg)) |
d5b7b3ae RE |
20287 | break; |
20288 | ||
20289 | while (high_regs_pushed) | |
20290 | { | |
20291 | /* Find lo register(s) into which the high register(s) can | |
20292 | be popped. */ | |
20293 | for (regno = 0; regno <= LAST_LO_REGNUM; regno++) | |
20294 | { | |
20295 | if (mask & (1 << regno)) | |
20296 | high_regs_pushed--; | |
20297 | if (high_regs_pushed == 0) | |
20298 | break; | |
20299 | } | |
20300 | ||
20301 | mask &= (2 << regno) - 1; /* A noop if regno == 8 */ | |
20302 | ||
d6b4baa4 | 20303 | /* Pop the values into the low register(s). */ |
980e61bb | 20304 | thumb_pushpop (asm_out_file, mask, 0, NULL, mask); |
d5b7b3ae RE |
20305 | |
20306 | /* Move the value(s) into the high registers. */ | |
20307 | for (regno = 0; regno <= LAST_LO_REGNUM; regno++) | |
20308 | { | |
20309 | if (mask & (1 << regno)) | |
20310 | { | |
20311 | asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", next_hi_reg, | |
20312 | regno); | |
f676971a | 20313 | |
d5b7b3ae | 20314 | for (next_hi_reg++; next_hi_reg < 13; next_hi_reg++) |
57934c39 | 20315 | if (live_regs_mask & (1 << next_hi_reg)) |
d5b7b3ae RE |
20316 | break; |
20317 | } | |
20318 | } | |
20319 | } | |
57934c39 | 20320 | live_regs_mask &= ~0x0f00; |
d5b7b3ae RE |
20321 | } |
20322 | ||
57934c39 PB |
20323 | had_to_push_lr = (live_regs_mask & (1 << LR_REGNUM)) != 0; |
20324 | live_regs_mask &= 0xff; | |
20325 | ||
38173d38 | 20326 | if (crtl->args.pretend_args_size == 0 || TARGET_BACKTRACE) |
d5b7b3ae | 20327 | { |
f676971a | 20328 | /* Pop the return address into the PC. */ |
57934c39 | 20329 | if (had_to_push_lr) |
d5b7b3ae RE |
20330 | live_regs_mask |= 1 << PC_REGNUM; |
20331 | ||
20332 | /* Either no argument registers were pushed or a backtrace | |
20333 | structure was created which includes an adjusted stack | |
20334 | pointer, so just pop everything. */ | |
20335 | if (live_regs_mask) | |
980e61bb DJ |
20336 | thumb_pushpop (asm_out_file, live_regs_mask, FALSE, NULL, |
20337 | live_regs_mask); | |
57934c39 | 20338 | |
d5b7b3ae | 20339 | /* We have either just popped the return address into the |
e784c52c BS |
20340 | PC or it is was kept in LR for the entire function. |
20341 | Note that thumb_pushpop has already called thumb_exit if the | |
20342 | PC was in the list. */ | |
57934c39 PB |
20343 | if (!had_to_push_lr) |
20344 | thumb_exit (asm_out_file, LR_REGNUM); | |
d5b7b3ae RE |
20345 | } |
20346 | else | |
20347 | { | |
20348 | /* Pop everything but the return address. */ | |
d5b7b3ae | 20349 | if (live_regs_mask) |
980e61bb DJ |
20350 | thumb_pushpop (asm_out_file, live_regs_mask, FALSE, NULL, |
20351 | live_regs_mask); | |
d5b7b3ae RE |
20352 | |
20353 | if (had_to_push_lr) | |
57934c39 PB |
20354 | { |
20355 | if (size > 12) | |
20356 | { | |
20357 | /* We have no free low regs, so save one. */ | |
20358 | asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", IP_REGNUM, | |
20359 | LAST_ARG_REGNUM); | |
20360 | } | |
20361 | ||
20362 | /* Get the return address into a temporary register. */ | |
20363 | thumb_pushpop (asm_out_file, 1 << LAST_ARG_REGNUM, 0, NULL, | |
20364 | 1 << LAST_ARG_REGNUM); | |
20365 | ||
20366 | if (size > 12) | |
20367 | { | |
20368 | /* Move the return address to lr. */ | |
20369 | asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", LR_REGNUM, | |
20370 | LAST_ARG_REGNUM); | |
20371 | /* Restore the low register. */ | |
20372 | asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", LAST_ARG_REGNUM, | |
20373 | IP_REGNUM); | |
20374 | regno = LR_REGNUM; | |
20375 | } | |
20376 | else | |
20377 | regno = LAST_ARG_REGNUM; | |
20378 | } | |
20379 | else | |
20380 | regno = LR_REGNUM; | |
f676971a | 20381 | |
d5b7b3ae RE |
20382 | /* Remove the argument registers that were pushed onto the stack. */ |
20383 | asm_fprintf (asm_out_file, "\tadd\t%r, %r, #%d\n", | |
20384 | SP_REGNUM, SP_REGNUM, | |
38173d38 | 20385 | crtl->args.pretend_args_size); |
f676971a | 20386 | |
57934c39 | 20387 | thumb_exit (asm_out_file, regno); |
d5b7b3ae RE |
20388 | } |
20389 | ||
20390 | return ""; | |
20391 | } | |
20392 | ||
20393 | /* Functions to save and restore machine-specific function data. */ | |
e2500fed | 20394 | static struct machine_function * |
e32bac5b | 20395 | arm_init_machine_status (void) |
d5b7b3ae | 20396 | { |
e2500fed | 20397 | struct machine_function *machine; |
a9429e29 | 20398 | machine = ggc_alloc_cleared_machine_function (); |
6d3d9133 | 20399 | |
f676971a | 20400 | #if ARM_FT_UNKNOWN != 0 |
e2500fed | 20401 | machine->func_type = ARM_FT_UNKNOWN; |
6d3d9133 | 20402 | #endif |
e2500fed | 20403 | return machine; |
f7a80099 NC |
20404 | } |
20405 | ||
d5b7b3ae RE |
20406 | /* Return an RTX indicating where the return address to the |
20407 | calling function can be found. */ | |
20408 | rtx | |
e32bac5b | 20409 | arm_return_addr (int count, rtx frame ATTRIBUTE_UNUSED) |
d5b7b3ae | 20410 | { |
d5b7b3ae RE |
20411 | if (count != 0) |
20412 | return NULL_RTX; | |
20413 | ||
61f0ccff | 20414 | return get_hard_reg_initial_val (Pmode, LR_REGNUM); |
d5b7b3ae RE |
20415 | } |
20416 | ||
20417 | /* Do anything needed before RTL is emitted for each function. */ | |
20418 | void | |
e32bac5b | 20419 | arm_init_expanders (void) |
d5b7b3ae RE |
20420 | { |
20421 | /* Arrange to initialize and mark the machine per-function status. */ | |
20422 | init_machine_status = arm_init_machine_status; | |
3ac5ea7c RH |
20423 | |
20424 | /* This is to stop the combine pass optimizing away the alignment | |
20425 | adjustment of va_arg. */ | |
20426 | /* ??? It is claimed that this should not be necessary. */ | |
20427 | if (cfun) | |
20428 | mark_reg_pointer (arg_pointer_rtx, PARM_BOUNDARY); | |
d5b7b3ae RE |
20429 | } |
20430 | ||
0977774b | 20431 | |
2591db65 RE |
20432 | /* Like arm_compute_initial_elimination offset. Simpler because there |
20433 | isn't an ABI specified frame pointer for Thumb. Instead, we set it | |
20434 | to point at the base of the local variables after static stack | |
20435 | space for a function has been allocated. */ | |
0977774b | 20436 | |
5848830f PB |
20437 | HOST_WIDE_INT |
20438 | thumb_compute_initial_elimination_offset (unsigned int from, unsigned int to) | |
20439 | { | |
20440 | arm_stack_offsets *offsets; | |
0977774b | 20441 | |
5848830f | 20442 | offsets = arm_get_frame_offsets (); |
0977774b | 20443 | |
5848830f | 20444 | switch (from) |
0977774b | 20445 | { |
5848830f PB |
20446 | case ARG_POINTER_REGNUM: |
20447 | switch (to) | |
20448 | { | |
20449 | case STACK_POINTER_REGNUM: | |
20450 | return offsets->outgoing_args - offsets->saved_args; | |
0977774b | 20451 | |
5848830f PB |
20452 | case FRAME_POINTER_REGNUM: |
20453 | return offsets->soft_frame - offsets->saved_args; | |
0977774b | 20454 | |
5848830f PB |
20455 | case ARM_HARD_FRAME_POINTER_REGNUM: |
20456 | return offsets->saved_regs - offsets->saved_args; | |
0977774b | 20457 | |
2591db65 RE |
20458 | case THUMB_HARD_FRAME_POINTER_REGNUM: |
20459 | return offsets->locals_base - offsets->saved_args; | |
20460 | ||
5848830f | 20461 | default: |
e6d29d15 | 20462 | gcc_unreachable (); |
5848830f PB |
20463 | } |
20464 | break; | |
0977774b | 20465 | |
5848830f PB |
20466 | case FRAME_POINTER_REGNUM: |
20467 | switch (to) | |
20468 | { | |
20469 | case STACK_POINTER_REGNUM: | |
20470 | return offsets->outgoing_args - offsets->soft_frame; | |
0977774b | 20471 | |
5848830f PB |
20472 | case ARM_HARD_FRAME_POINTER_REGNUM: |
20473 | return offsets->saved_regs - offsets->soft_frame; | |
0977774b | 20474 | |
2591db65 RE |
20475 | case THUMB_HARD_FRAME_POINTER_REGNUM: |
20476 | return offsets->locals_base - offsets->soft_frame; | |
20477 | ||
5848830f | 20478 | default: |
e6d29d15 | 20479 | gcc_unreachable (); |
5848830f PB |
20480 | } |
20481 | break; | |
0977774b | 20482 | |
5848830f | 20483 | default: |
e6d29d15 | 20484 | gcc_unreachable (); |
5848830f | 20485 | } |
0977774b JT |
20486 | } |
20487 | ||
d5b7b3ae RE |
20488 | /* Generate the rest of a function's prologue. */ |
20489 | void | |
5b3e6663 | 20490 | thumb1_expand_prologue (void) |
d5b7b3ae | 20491 | { |
980e61bb DJ |
20492 | rtx insn, dwarf; |
20493 | ||
5848830f PB |
20494 | HOST_WIDE_INT amount; |
20495 | arm_stack_offsets *offsets; | |
6d3d9133 | 20496 | unsigned long func_type; |
3c7ad43e | 20497 | int regno; |
57934c39 | 20498 | unsigned long live_regs_mask; |
6d3d9133 NC |
20499 | |
20500 | func_type = arm_current_func_type (); | |
f676971a | 20501 | |
d5b7b3ae | 20502 | /* Naked functions don't have prologues. */ |
6d3d9133 | 20503 | if (IS_NAKED (func_type)) |
d5b7b3ae RE |
20504 | return; |
20505 | ||
6d3d9133 NC |
20506 | if (IS_INTERRUPT (func_type)) |
20507 | { | |
c725bd79 | 20508 | error ("interrupt Service Routines cannot be coded in Thumb mode"); |
6d3d9133 NC |
20509 | return; |
20510 | } | |
20511 | ||
954954d1 PB |
20512 | offsets = arm_get_frame_offsets (); |
20513 | live_regs_mask = offsets->saved_regs_mask; | |
b279b20a NC |
20514 | /* Load the pic register before setting the frame pointer, |
20515 | so we can use r7 as a temporary work register. */ | |
020a4035 | 20516 | if (flag_pic && arm_pic_register != INVALID_REGNUM) |
e55ef7f4 | 20517 | arm_load_pic_register (live_regs_mask); |
876f13b0 | 20518 | |
2591db65 | 20519 | if (!frame_pointer_needed && CALLER_INTERWORKING_SLOT_SIZE > 0) |
a2503645 RS |
20520 | emit_move_insn (gen_rtx_REG (Pmode, ARM_HARD_FRAME_POINTER_REGNUM), |
20521 | stack_pointer_rtx); | |
d5b7b3ae | 20522 | |
5848830f | 20523 | amount = offsets->outgoing_args - offsets->saved_regs; |
e784c52c | 20524 | amount -= 4 * thumb1_extra_regs_pushed (offsets, true); |
d5b7b3ae RE |
20525 | if (amount) |
20526 | { | |
d5b7b3ae | 20527 | if (amount < 512) |
980e61bb DJ |
20528 | { |
20529 | insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, | |
20530 | GEN_INT (- amount))); | |
20531 | RTX_FRAME_RELATED_P (insn) = 1; | |
20532 | } | |
d5b7b3ae RE |
20533 | else |
20534 | { | |
d5b7b3ae RE |
20535 | rtx reg; |
20536 | ||
20537 | /* The stack decrement is too big for an immediate value in a single | |
20538 | insn. In theory we could issue multiple subtracts, but after | |
20539 | three of them it becomes more space efficient to place the full | |
20540 | value in the constant pool and load into a register. (Also the | |
20541 | ARM debugger really likes to see only one stack decrement per | |
20542 | function). So instead we look for a scratch register into which | |
20543 | we can load the decrement, and then we subtract this from the | |
20544 | stack pointer. Unfortunately on the thumb the only available | |
20545 | scratch registers are the argument registers, and we cannot use | |
20546 | these as they may hold arguments to the function. Instead we | |
20547 | attempt to locate a call preserved register which is used by this | |
20548 | function. If we can find one, then we know that it will have | |
20549 | been pushed at the start of the prologue and so we can corrupt | |
20550 | it now. */ | |
20551 | for (regno = LAST_ARG_REGNUM + 1; regno <= LAST_LO_REGNUM; regno++) | |
35596784 | 20552 | if (live_regs_mask & (1 << regno)) |
d5b7b3ae RE |
20553 | break; |
20554 | ||
35596784 | 20555 | gcc_assert(regno <= LAST_LO_REGNUM); |
d5b7b3ae | 20556 | |
35596784 | 20557 | reg = gen_rtx_REG (SImode, regno); |
d5b7b3ae | 20558 | |
35596784 | 20559 | emit_insn (gen_movsi (reg, GEN_INT (- amount))); |
980e61bb | 20560 | |
35596784 AJ |
20561 | insn = emit_insn (gen_addsi3 (stack_pointer_rtx, |
20562 | stack_pointer_rtx, reg)); | |
20563 | RTX_FRAME_RELATED_P (insn) = 1; | |
20564 | dwarf = gen_rtx_SET (VOIDmode, stack_pointer_rtx, | |
20565 | plus_constant (stack_pointer_rtx, | |
20566 | -amount)); | |
20567 | RTX_FRAME_RELATED_P (dwarf) = 1; | |
bbbbb16a | 20568 | add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
d5b7b3ae | 20569 | } |
2591db65 RE |
20570 | } |
20571 | ||
20572 | if (frame_pointer_needed) | |
5b3e6663 | 20573 | thumb_set_frame_pointer (offsets); |
f676971a | 20574 | |
74d9c39f DJ |
20575 | /* If we are profiling, make sure no instructions are scheduled before |
20576 | the call to mcount. Similarly if the user has requested no | |
20577 | scheduling in the prolog. Similarly if we want non-call exceptions | |
20578 | using the EABI unwinder, to prevent faulting instructions from being | |
20579 | swapped with a stack adjustment. */ | |
e3b5732b | 20580 | if (crtl->profile || !TARGET_SCHED_PROLOG |
f0a0390e RH |
20581 | || (arm_except_unwind_info () == UI_TARGET |
20582 | && cfun->can_throw_non_call_exceptions)) | |
d5b7b3ae | 20583 | emit_insn (gen_blockage ()); |
3c7ad43e PB |
20584 | |
20585 | cfun->machine->lr_save_eliminated = !thumb_force_lr_save (); | |
57934c39 PB |
20586 | if (live_regs_mask & 0xff) |
20587 | cfun->machine->lr_save_eliminated = 0; | |
d5b7b3ae RE |
20588 | } |
20589 | ||
57934c39 | 20590 | |
d5b7b3ae | 20591 | void |
5b3e6663 | 20592 | thumb1_expand_epilogue (void) |
d5b7b3ae | 20593 | { |
5848830f PB |
20594 | HOST_WIDE_INT amount; |
20595 | arm_stack_offsets *offsets; | |
defc0463 RE |
20596 | int regno; |
20597 | ||
6d3d9133 NC |
20598 | /* Naked functions don't have prologues. */ |
20599 | if (IS_NAKED (arm_current_func_type ())) | |
d5b7b3ae RE |
20600 | return; |
20601 | ||
5848830f PB |
20602 | offsets = arm_get_frame_offsets (); |
20603 | amount = offsets->outgoing_args - offsets->saved_regs; | |
20604 | ||
d5b7b3ae | 20605 | if (frame_pointer_needed) |
2591db65 RE |
20606 | { |
20607 | emit_insn (gen_movsi (stack_pointer_rtx, hard_frame_pointer_rtx)); | |
20608 | amount = offsets->locals_base - offsets->saved_regs; | |
20609 | } | |
e784c52c | 20610 | amount -= 4 * thumb1_extra_regs_pushed (offsets, false); |
e0b92319 | 20611 | |
a3a531ec | 20612 | gcc_assert (amount >= 0); |
2591db65 | 20613 | if (amount) |
d5b7b3ae | 20614 | { |
d5b7b3ae RE |
20615 | if (amount < 512) |
20616 | emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, | |
20617 | GEN_INT (amount))); | |
20618 | else | |
20619 | { | |
20620 | /* r3 is always free in the epilogue. */ | |
f1c25d3b | 20621 | rtx reg = gen_rtx_REG (SImode, LAST_ARG_REGNUM); |
d5b7b3ae RE |
20622 | |
20623 | emit_insn (gen_movsi (reg, GEN_INT (amount))); | |
20624 | emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg)); | |
20625 | } | |
20626 | } | |
f676971a | 20627 | |
d5b7b3ae RE |
20628 | /* Emit a USE (stack_pointer_rtx), so that |
20629 | the stack adjustment will not be deleted. */ | |
6bacc7b0 | 20630 | emit_insn (gen_prologue_use (stack_pointer_rtx)); |
d5b7b3ae | 20631 | |
e3b5732b | 20632 | if (crtl->profile || !TARGET_SCHED_PROLOG) |
d5b7b3ae | 20633 | emit_insn (gen_blockage ()); |
defc0463 RE |
20634 | |
20635 | /* Emit a clobber for each insn that will be restored in the epilogue, | |
20636 | so that flow2 will get register lifetimes correct. */ | |
20637 | for (regno = 0; regno < 13; regno++) | |
6fb5fa3c | 20638 | if (df_regs_ever_live_p (regno) && !call_used_regs[regno]) |
c41c1387 | 20639 | emit_clobber (gen_rtx_REG (SImode, regno)); |
defc0463 | 20640 | |
6fb5fa3c | 20641 | if (! df_regs_ever_live_p (LR_REGNUM)) |
c41c1387 | 20642 | emit_use (gen_rtx_REG (SImode, LR_REGNUM)); |
d5b7b3ae RE |
20643 | } |
20644 | ||
08c148a8 | 20645 | static void |
5b3e6663 | 20646 | thumb1_output_function_prologue (FILE *f, HOST_WIDE_INT size ATTRIBUTE_UNUSED) |
d5b7b3ae | 20647 | { |
954954d1 | 20648 | arm_stack_offsets *offsets; |
b279b20a NC |
20649 | unsigned long live_regs_mask = 0; |
20650 | unsigned long l_mask; | |
20651 | unsigned high_regs_pushed = 0; | |
980e61bb | 20652 | int cfa_offset = 0; |
d5b7b3ae RE |
20653 | int regno; |
20654 | ||
6d3d9133 | 20655 | if (IS_NAKED (arm_current_func_type ())) |
d5b7b3ae RE |
20656 | return; |
20657 | ||
20658 | if (is_called_in_ARM_mode (current_function_decl)) | |
20659 | { | |
20660 | const char * name; | |
20661 | ||
e6d29d15 NS |
20662 | gcc_assert (GET_CODE (DECL_RTL (current_function_decl)) == MEM); |
20663 | gcc_assert (GET_CODE (XEXP (DECL_RTL (current_function_decl), 0)) | |
20664 | == SYMBOL_REF); | |
d5b7b3ae | 20665 | name = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); |
f676971a | 20666 | |
d5b7b3ae RE |
20667 | /* Generate code sequence to switch us into Thumb mode. */ |
20668 | /* The .code 32 directive has already been emitted by | |
6d77b53e | 20669 | ASM_DECLARE_FUNCTION_NAME. */ |
d5b7b3ae RE |
20670 | asm_fprintf (f, "\torr\t%r, %r, #1\n", IP_REGNUM, PC_REGNUM); |
20671 | asm_fprintf (f, "\tbx\t%r\n", IP_REGNUM); | |
20672 | ||
20673 | /* Generate a label, so that the debugger will notice the | |
20674 | change in instruction sets. This label is also used by | |
20675 | the assembler to bypass the ARM code when this function | |
20676 | is called from a Thumb encoded function elsewhere in the | |
20677 | same file. Hence the definition of STUB_NAME here must | |
d6b4baa4 | 20678 | agree with the definition in gas/config/tc-arm.c. */ |
f676971a | 20679 | |
d5b7b3ae | 20680 | #define STUB_NAME ".real_start_of" |
f676971a | 20681 | |
761c70aa | 20682 | fprintf (f, "\t.code\t16\n"); |
d5b7b3ae RE |
20683 | #ifdef ARM_PE |
20684 | if (arm_dllexport_name_p (name)) | |
e5951263 | 20685 | name = arm_strip_name_encoding (name); |
f676971a | 20686 | #endif |
d5b7b3ae | 20687 | asm_fprintf (f, "\t.globl %s%U%s\n", STUB_NAME, name); |
761c70aa | 20688 | fprintf (f, "\t.thumb_func\n"); |
d5b7b3ae RE |
20689 | asm_fprintf (f, "%s%U%s:\n", STUB_NAME, name); |
20690 | } | |
f676971a | 20691 | |
38173d38 | 20692 | if (crtl->args.pretend_args_size) |
d5b7b3ae | 20693 | { |
617a1b71 | 20694 | /* Output unwind directive for the stack adjustment. */ |
f0a0390e | 20695 | if (arm_except_unwind_info () == UI_TARGET) |
617a1b71 | 20696 | fprintf (f, "\t.pad #%d\n", |
38173d38 | 20697 | crtl->args.pretend_args_size); |
617a1b71 | 20698 | |
3cb66fd7 | 20699 | if (cfun->machine->uses_anonymous_args) |
d5b7b3ae RE |
20700 | { |
20701 | int num_pushes; | |
f676971a | 20702 | |
761c70aa | 20703 | fprintf (f, "\tpush\t{"); |
d5b7b3ae | 20704 | |
38173d38 | 20705 | num_pushes = ARM_NUM_INTS (crtl->args.pretend_args_size); |
f676971a | 20706 | |
d5b7b3ae RE |
20707 | for (regno = LAST_ARG_REGNUM + 1 - num_pushes; |
20708 | regno <= LAST_ARG_REGNUM; | |
5895f793 | 20709 | regno++) |
d5b7b3ae RE |
20710 | asm_fprintf (f, "%r%s", regno, |
20711 | regno == LAST_ARG_REGNUM ? "" : ", "); | |
20712 | ||
761c70aa | 20713 | fprintf (f, "}\n"); |
d5b7b3ae RE |
20714 | } |
20715 | else | |
f676971a | 20716 | asm_fprintf (f, "\tsub\t%r, %r, #%d\n", |
d5b7b3ae | 20717 | SP_REGNUM, SP_REGNUM, |
38173d38 | 20718 | crtl->args.pretend_args_size); |
980e61bb DJ |
20719 | |
20720 | /* We don't need to record the stores for unwinding (would it | |
20721 | help the debugger any if we did?), but record the change in | |
20722 | the stack pointer. */ | |
20723 | if (dwarf2out_do_frame ()) | |
20724 | { | |
d342c045 | 20725 | char *l = dwarf2out_cfi_label (false); |
b279b20a | 20726 | |
38173d38 | 20727 | cfa_offset = cfa_offset + crtl->args.pretend_args_size; |
980e61bb DJ |
20728 | dwarf2out_def_cfa (l, SP_REGNUM, cfa_offset); |
20729 | } | |
d5b7b3ae RE |
20730 | } |
20731 | ||
b279b20a | 20732 | /* Get the registers we are going to push. */ |
954954d1 PB |
20733 | offsets = arm_get_frame_offsets (); |
20734 | live_regs_mask = offsets->saved_regs_mask; | |
b279b20a | 20735 | /* Extract a mask of the ones we can give to the Thumb's push instruction. */ |
57934c39 | 20736 | l_mask = live_regs_mask & 0x40ff; |
b279b20a NC |
20737 | /* Then count how many other high registers will need to be pushed. */ |
20738 | high_regs_pushed = bit_count (live_regs_mask & 0x0f00); | |
d5b7b3ae RE |
20739 | |
20740 | if (TARGET_BACKTRACE) | |
20741 | { | |
b279b20a NC |
20742 | unsigned offset; |
20743 | unsigned work_register; | |
f676971a | 20744 | |
d5b7b3ae RE |
20745 | /* We have been asked to create a stack backtrace structure. |
20746 | The code looks like this: | |
f676971a | 20747 | |
d5b7b3ae RE |
20748 | 0 .align 2 |
20749 | 0 func: | |
20750 | 0 sub SP, #16 Reserve space for 4 registers. | |
57934c39 | 20751 | 2 push {R7} Push low registers. |
d5b7b3ae RE |
20752 | 4 add R7, SP, #20 Get the stack pointer before the push. |
20753 | 6 str R7, [SP, #8] Store the stack pointer (before reserving the space). | |
20754 | 8 mov R7, PC Get hold of the start of this code plus 12. | |
20755 | 10 str R7, [SP, #16] Store it. | |
20756 | 12 mov R7, FP Get hold of the current frame pointer. | |
20757 | 14 str R7, [SP, #4] Store it. | |
20758 | 16 mov R7, LR Get hold of the current return address. | |
20759 | 18 str R7, [SP, #12] Store it. | |
20760 | 20 add R7, SP, #16 Point at the start of the backtrace structure. | |
20761 | 22 mov FP, R7 Put this value into the frame pointer. */ | |
20762 | ||
57934c39 | 20763 | work_register = thumb_find_work_register (live_regs_mask); |
f676971a | 20764 | |
f0a0390e | 20765 | if (arm_except_unwind_info () == UI_TARGET) |
617a1b71 PB |
20766 | asm_fprintf (f, "\t.pad #16\n"); |
20767 | ||
d5b7b3ae RE |
20768 | asm_fprintf |
20769 | (f, "\tsub\t%r, %r, #16\t%@ Create stack backtrace structure\n", | |
20770 | SP_REGNUM, SP_REGNUM); | |
980e61bb DJ |
20771 | |
20772 | if (dwarf2out_do_frame ()) | |
20773 | { | |
d342c045 | 20774 | char *l = dwarf2out_cfi_label (false); |
b279b20a | 20775 | |
980e61bb DJ |
20776 | cfa_offset = cfa_offset + 16; |
20777 | dwarf2out_def_cfa (l, SP_REGNUM, cfa_offset); | |
20778 | } | |
20779 | ||
57934c39 PB |
20780 | if (l_mask) |
20781 | { | |
20782 | thumb_pushpop (f, l_mask, 1, &cfa_offset, l_mask); | |
1a59548b | 20783 | offset = bit_count (l_mask) * UNITS_PER_WORD; |
57934c39 PB |
20784 | } |
20785 | else | |
20786 | offset = 0; | |
f676971a | 20787 | |
d5b7b3ae | 20788 | asm_fprintf (f, "\tadd\t%r, %r, #%d\n", work_register, SP_REGNUM, |
38173d38 | 20789 | offset + 16 + crtl->args.pretend_args_size); |
f676971a | 20790 | |
d5b7b3ae RE |
20791 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, |
20792 | offset + 4); | |
20793 | ||
20794 | /* Make sure that the instruction fetching the PC is in the right place | |
20795 | to calculate "start of backtrace creation code + 12". */ | |
57934c39 | 20796 | if (l_mask) |
d5b7b3ae RE |
20797 | { |
20798 | asm_fprintf (f, "\tmov\t%r, %r\n", work_register, PC_REGNUM); | |
20799 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, | |
20800 | offset + 12); | |
20801 | asm_fprintf (f, "\tmov\t%r, %r\n", work_register, | |
20802 | ARM_HARD_FRAME_POINTER_REGNUM); | |
20803 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, | |
20804 | offset); | |
20805 | } | |
20806 | else | |
20807 | { | |
20808 | asm_fprintf (f, "\tmov\t%r, %r\n", work_register, | |
20809 | ARM_HARD_FRAME_POINTER_REGNUM); | |
20810 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, | |
20811 | offset); | |
20812 | asm_fprintf (f, "\tmov\t%r, %r\n", work_register, PC_REGNUM); | |
20813 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, | |
20814 | offset + 12); | |
20815 | } | |
f676971a | 20816 | |
d5b7b3ae RE |
20817 | asm_fprintf (f, "\tmov\t%r, %r\n", work_register, LR_REGNUM); |
20818 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, | |
20819 | offset + 8); | |
20820 | asm_fprintf (f, "\tadd\t%r, %r, #%d\n", work_register, SP_REGNUM, | |
20821 | offset + 12); | |
20822 | asm_fprintf (f, "\tmov\t%r, %r\t\t%@ Backtrace structure created\n", | |
20823 | ARM_HARD_FRAME_POINTER_REGNUM, work_register); | |
20824 | } | |
0fa2e4df | 20825 | /* Optimization: If we are not pushing any low registers but we are going |
b279b20a NC |
20826 | to push some high registers then delay our first push. This will just |
20827 | be a push of LR and we can combine it with the push of the first high | |
20828 | register. */ | |
20829 | else if ((l_mask & 0xff) != 0 | |
20830 | || (high_regs_pushed == 0 && l_mask)) | |
cb751cbd BS |
20831 | { |
20832 | unsigned long mask = l_mask; | |
e784c52c | 20833 | mask |= (1 << thumb1_extra_regs_pushed (offsets, true)) - 1; |
cb751cbd BS |
20834 | thumb_pushpop (f, mask, 1, &cfa_offset, mask); |
20835 | } | |
d5b7b3ae | 20836 | |
d5b7b3ae RE |
20837 | if (high_regs_pushed) |
20838 | { | |
b279b20a NC |
20839 | unsigned pushable_regs; |
20840 | unsigned next_hi_reg; | |
d5b7b3ae RE |
20841 | |
20842 | for (next_hi_reg = 12; next_hi_reg > LAST_LO_REGNUM; next_hi_reg--) | |
57934c39 | 20843 | if (live_regs_mask & (1 << next_hi_reg)) |
e26053d1 | 20844 | break; |
d5b7b3ae | 20845 | |
57934c39 | 20846 | pushable_regs = l_mask & 0xff; |
d5b7b3ae RE |
20847 | |
20848 | if (pushable_regs == 0) | |
57934c39 | 20849 | pushable_regs = 1 << thumb_find_work_register (live_regs_mask); |
d5b7b3ae RE |
20850 | |
20851 | while (high_regs_pushed > 0) | |
20852 | { | |
b279b20a | 20853 | unsigned long real_regs_mask = 0; |
980e61bb | 20854 | |
b279b20a | 20855 | for (regno = LAST_LO_REGNUM; regno >= 0; regno --) |
d5b7b3ae | 20856 | { |
57934c39 | 20857 | if (pushable_regs & (1 << regno)) |
d5b7b3ae RE |
20858 | { |
20859 | asm_fprintf (f, "\tmov\t%r, %r\n", regno, next_hi_reg); | |
f676971a | 20860 | |
b279b20a | 20861 | high_regs_pushed --; |
980e61bb | 20862 | real_regs_mask |= (1 << next_hi_reg); |
f676971a | 20863 | |
d5b7b3ae | 20864 | if (high_regs_pushed) |
aeaf4d25 | 20865 | { |
b279b20a NC |
20866 | for (next_hi_reg --; next_hi_reg > LAST_LO_REGNUM; |
20867 | next_hi_reg --) | |
57934c39 | 20868 | if (live_regs_mask & (1 << next_hi_reg)) |
d5b7b3ae | 20869 | break; |
aeaf4d25 | 20870 | } |
d5b7b3ae RE |
20871 | else |
20872 | { | |
57934c39 | 20873 | pushable_regs &= ~((1 << regno) - 1); |
d5b7b3ae RE |
20874 | break; |
20875 | } | |
20876 | } | |
20877 | } | |
980e61bb | 20878 | |
b279b20a NC |
20879 | /* If we had to find a work register and we have not yet |
20880 | saved the LR then add it to the list of regs to push. */ | |
20881 | if (l_mask == (1 << LR_REGNUM)) | |
20882 | { | |
20883 | thumb_pushpop (f, pushable_regs | (1 << LR_REGNUM), | |
20884 | 1, &cfa_offset, | |
20885 | real_regs_mask | (1 << LR_REGNUM)); | |
20886 | l_mask = 0; | |
20887 | } | |
20888 | else | |
20889 | thumb_pushpop (f, pushable_regs, 1, &cfa_offset, real_regs_mask); | |
d5b7b3ae | 20890 | } |
d5b7b3ae RE |
20891 | } |
20892 | } | |
20893 | ||
20894 | /* Handle the case of a double word load into a low register from | |
20895 | a computed memory address. The computed address may involve a | |
20896 | register which is overwritten by the load. */ | |
cd2b33d0 | 20897 | const char * |
e32bac5b | 20898 | thumb_load_double_from_address (rtx *operands) |
d5b7b3ae RE |
20899 | { |
20900 | rtx addr; | |
20901 | rtx base; | |
20902 | rtx offset; | |
20903 | rtx arg1; | |
20904 | rtx arg2; | |
f676971a | 20905 | |
e6d29d15 NS |
20906 | gcc_assert (GET_CODE (operands[0]) == REG); |
20907 | gcc_assert (GET_CODE (operands[1]) == MEM); | |
d5b7b3ae RE |
20908 | |
20909 | /* Get the memory address. */ | |
20910 | addr = XEXP (operands[1], 0); | |
f676971a | 20911 | |
d5b7b3ae RE |
20912 | /* Work out how the memory address is computed. */ |
20913 | switch (GET_CODE (addr)) | |
20914 | { | |
20915 | case REG: | |
31fa16b6 | 20916 | operands[2] = adjust_address (operands[1], SImode, 4); |
e0b92319 | 20917 | |
d5b7b3ae RE |
20918 | if (REGNO (operands[0]) == REGNO (addr)) |
20919 | { | |
20920 | output_asm_insn ("ldr\t%H0, %2", operands); | |
20921 | output_asm_insn ("ldr\t%0, %1", operands); | |
20922 | } | |
20923 | else | |
20924 | { | |
20925 | output_asm_insn ("ldr\t%0, %1", operands); | |
20926 | output_asm_insn ("ldr\t%H0, %2", operands); | |
20927 | } | |
20928 | break; | |
f676971a | 20929 | |
d5b7b3ae RE |
20930 | case CONST: |
20931 | /* Compute <address> + 4 for the high order load. */ | |
31fa16b6 | 20932 | operands[2] = adjust_address (operands[1], SImode, 4); |
e0b92319 | 20933 | |
d5b7b3ae RE |
20934 | output_asm_insn ("ldr\t%0, %1", operands); |
20935 | output_asm_insn ("ldr\t%H0, %2", operands); | |
20936 | break; | |
f676971a | 20937 | |
d5b7b3ae RE |
20938 | case PLUS: |
20939 | arg1 = XEXP (addr, 0); | |
20940 | arg2 = XEXP (addr, 1); | |
f676971a | 20941 | |
d5b7b3ae RE |
20942 | if (CONSTANT_P (arg1)) |
20943 | base = arg2, offset = arg1; | |
20944 | else | |
20945 | base = arg1, offset = arg2; | |
f676971a | 20946 | |
e6d29d15 | 20947 | gcc_assert (GET_CODE (base) == REG); |
d5b7b3ae RE |
20948 | |
20949 | /* Catch the case of <address> = <reg> + <reg> */ | |
20950 | if (GET_CODE (offset) == REG) | |
20951 | { | |
20952 | int reg_offset = REGNO (offset); | |
20953 | int reg_base = REGNO (base); | |
20954 | int reg_dest = REGNO (operands[0]); | |
f676971a | 20955 | |
d5b7b3ae RE |
20956 | /* Add the base and offset registers together into the |
20957 | higher destination register. */ | |
20958 | asm_fprintf (asm_out_file, "\tadd\t%r, %r, %r", | |
20959 | reg_dest + 1, reg_base, reg_offset); | |
f676971a | 20960 | |
d5b7b3ae RE |
20961 | /* Load the lower destination register from the address in |
20962 | the higher destination register. */ | |
20963 | asm_fprintf (asm_out_file, "\tldr\t%r, [%r, #0]", | |
20964 | reg_dest, reg_dest + 1); | |
f676971a | 20965 | |
d5b7b3ae RE |
20966 | /* Load the higher destination register from its own address |
20967 | plus 4. */ | |
20968 | asm_fprintf (asm_out_file, "\tldr\t%r, [%r, #4]", | |
20969 | reg_dest + 1, reg_dest + 1); | |
20970 | } | |
20971 | else | |
20972 | { | |
20973 | /* Compute <address> + 4 for the high order load. */ | |
31fa16b6 | 20974 | operands[2] = adjust_address (operands[1], SImode, 4); |
f676971a | 20975 | |
d5b7b3ae RE |
20976 | /* If the computed address is held in the low order register |
20977 | then load the high order register first, otherwise always | |
20978 | load the low order register first. */ | |
20979 | if (REGNO (operands[0]) == REGNO (base)) | |
20980 | { | |
20981 | output_asm_insn ("ldr\t%H0, %2", operands); | |
20982 | output_asm_insn ("ldr\t%0, %1", operands); | |
20983 | } | |
20984 | else | |
20985 | { | |
20986 | output_asm_insn ("ldr\t%0, %1", operands); | |
20987 | output_asm_insn ("ldr\t%H0, %2", operands); | |
20988 | } | |
20989 | } | |
20990 | break; | |
20991 | ||
20992 | case LABEL_REF: | |
20993 | /* With no registers to worry about we can just load the value | |
20994 | directly. */ | |
31fa16b6 | 20995 | operands[2] = adjust_address (operands[1], SImode, 4); |
f676971a | 20996 | |
d5b7b3ae RE |
20997 | output_asm_insn ("ldr\t%H0, %2", operands); |
20998 | output_asm_insn ("ldr\t%0, %1", operands); | |
20999 | break; | |
f676971a | 21000 | |
d5b7b3ae | 21001 | default: |
e6d29d15 | 21002 | gcc_unreachable (); |
d5b7b3ae | 21003 | } |
f676971a | 21004 | |
d5b7b3ae RE |
21005 | return ""; |
21006 | } | |
21007 | ||
cd2b33d0 | 21008 | const char * |
e32bac5b | 21009 | thumb_output_move_mem_multiple (int n, rtx *operands) |
d5b7b3ae RE |
21010 | { |
21011 | rtx tmp; | |
21012 | ||
21013 | switch (n) | |
21014 | { | |
21015 | case 2: | |
ca356f3a | 21016 | if (REGNO (operands[4]) > REGNO (operands[5])) |
d5b7b3ae | 21017 | { |
ca356f3a RE |
21018 | tmp = operands[4]; |
21019 | operands[4] = operands[5]; | |
21020 | operands[5] = tmp; | |
d5b7b3ae | 21021 | } |
ca356f3a RE |
21022 | output_asm_insn ("ldmia\t%1!, {%4, %5}", operands); |
21023 | output_asm_insn ("stmia\t%0!, {%4, %5}", operands); | |
d5b7b3ae RE |
21024 | break; |
21025 | ||
21026 | case 3: | |
ca356f3a | 21027 | if (REGNO (operands[4]) > REGNO (operands[5])) |
d5b7b3ae | 21028 | { |
ca356f3a RE |
21029 | tmp = operands[4]; |
21030 | operands[4] = operands[5]; | |
21031 | operands[5] = tmp; | |
d5b7b3ae | 21032 | } |
ca356f3a | 21033 | if (REGNO (operands[5]) > REGNO (operands[6])) |
d5b7b3ae | 21034 | { |
ca356f3a RE |
21035 | tmp = operands[5]; |
21036 | operands[5] = operands[6]; | |
21037 | operands[6] = tmp; | |
d5b7b3ae | 21038 | } |
ca356f3a | 21039 | if (REGNO (operands[4]) > REGNO (operands[5])) |
d5b7b3ae | 21040 | { |
ca356f3a RE |
21041 | tmp = operands[4]; |
21042 | operands[4] = operands[5]; | |
21043 | operands[5] = tmp; | |
d5b7b3ae | 21044 | } |
f676971a | 21045 | |
ca356f3a RE |
21046 | output_asm_insn ("ldmia\t%1!, {%4, %5, %6}", operands); |
21047 | output_asm_insn ("stmia\t%0!, {%4, %5, %6}", operands); | |
d5b7b3ae RE |
21048 | break; |
21049 | ||
21050 | default: | |
e6d29d15 | 21051 | gcc_unreachable (); |
d5b7b3ae RE |
21052 | } |
21053 | ||
21054 | return ""; | |
21055 | } | |
21056 | ||
b12a00f1 RE |
21057 | /* Output a call-via instruction for thumb state. */ |
21058 | const char * | |
21059 | thumb_call_via_reg (rtx reg) | |
21060 | { | |
21061 | int regno = REGNO (reg); | |
21062 | rtx *labelp; | |
21063 | ||
57ecec57 | 21064 | gcc_assert (regno < LR_REGNUM); |
b12a00f1 RE |
21065 | |
21066 | /* If we are in the normal text section we can use a single instance | |
21067 | per compilation unit. If we are doing function sections, then we need | |
21068 | an entry per section, since we can't rely on reachability. */ | |
d6b5193b | 21069 | if (in_section == text_section) |
b12a00f1 RE |
21070 | { |
21071 | thumb_call_reg_needed = 1; | |
21072 | ||
21073 | if (thumb_call_via_label[regno] == NULL) | |
21074 | thumb_call_via_label[regno] = gen_label_rtx (); | |
21075 | labelp = thumb_call_via_label + regno; | |
21076 | } | |
21077 | else | |
21078 | { | |
21079 | if (cfun->machine->call_via[regno] == NULL) | |
21080 | cfun->machine->call_via[regno] = gen_label_rtx (); | |
21081 | labelp = cfun->machine->call_via + regno; | |
21082 | } | |
21083 | ||
21084 | output_asm_insn ("bl\t%a0", labelp); | |
21085 | return ""; | |
21086 | } | |
21087 | ||
1d6e90ac | 21088 | /* Routines for generating rtl. */ |
d5b7b3ae | 21089 | void |
70128ad9 | 21090 | thumb_expand_movmemqi (rtx *operands) |
d5b7b3ae RE |
21091 | { |
21092 | rtx out = copy_to_mode_reg (SImode, XEXP (operands[0], 0)); | |
21093 | rtx in = copy_to_mode_reg (SImode, XEXP (operands[1], 0)); | |
21094 | HOST_WIDE_INT len = INTVAL (operands[2]); | |
21095 | HOST_WIDE_INT offset = 0; | |
21096 | ||
21097 | while (len >= 12) | |
21098 | { | |
ca356f3a | 21099 | emit_insn (gen_movmem12b (out, in, out, in)); |
d5b7b3ae RE |
21100 | len -= 12; |
21101 | } | |
f676971a | 21102 | |
d5b7b3ae RE |
21103 | if (len >= 8) |
21104 | { | |
ca356f3a | 21105 | emit_insn (gen_movmem8b (out, in, out, in)); |
d5b7b3ae RE |
21106 | len -= 8; |
21107 | } | |
f676971a | 21108 | |
d5b7b3ae RE |
21109 | if (len >= 4) |
21110 | { | |
21111 | rtx reg = gen_reg_rtx (SImode); | |
f1c25d3b KH |
21112 | emit_insn (gen_movsi (reg, gen_rtx_MEM (SImode, in))); |
21113 | emit_insn (gen_movsi (gen_rtx_MEM (SImode, out), reg)); | |
d5b7b3ae RE |
21114 | len -= 4; |
21115 | offset += 4; | |
21116 | } | |
f676971a | 21117 | |
d5b7b3ae RE |
21118 | if (len >= 2) |
21119 | { | |
21120 | rtx reg = gen_reg_rtx (HImode); | |
f676971a | 21121 | emit_insn (gen_movhi (reg, gen_rtx_MEM (HImode, |
f1c25d3b KH |
21122 | plus_constant (in, offset)))); |
21123 | emit_insn (gen_movhi (gen_rtx_MEM (HImode, plus_constant (out, offset)), | |
d5b7b3ae RE |
21124 | reg)); |
21125 | len -= 2; | |
21126 | offset += 2; | |
21127 | } | |
f676971a | 21128 | |
d5b7b3ae RE |
21129 | if (len) |
21130 | { | |
21131 | rtx reg = gen_reg_rtx (QImode); | |
f1c25d3b KH |
21132 | emit_insn (gen_movqi (reg, gen_rtx_MEM (QImode, |
21133 | plus_constant (in, offset)))); | |
21134 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (out, offset)), | |
d5b7b3ae RE |
21135 | reg)); |
21136 | } | |
21137 | } | |
21138 | ||
d5b7b3ae | 21139 | void |
e32bac5b | 21140 | thumb_reload_out_hi (rtx *operands) |
d5b7b3ae RE |
21141 | { |
21142 | emit_insn (gen_thumb_movhi_clobber (operands[0], operands[1], operands[2])); | |
21143 | } | |
21144 | ||
f676971a | 21145 | /* Handle reading a half-word from memory during reload. */ |
d5b7b3ae | 21146 | void |
e32bac5b | 21147 | thumb_reload_in_hi (rtx *operands ATTRIBUTE_UNUSED) |
d5b7b3ae | 21148 | { |
e6d29d15 | 21149 | gcc_unreachable (); |
d5b7b3ae RE |
21150 | } |
21151 | ||
c27ba912 DM |
21152 | /* Return the length of a function name prefix |
21153 | that starts with the character 'c'. */ | |
21154 | static int | |
e32bac5b | 21155 | arm_get_strip_length (int c) |
c27ba912 DM |
21156 | { |
21157 | switch (c) | |
21158 | { | |
21159 | ARM_NAME_ENCODING_LENGTHS | |
f676971a | 21160 | default: return 0; |
c27ba912 DM |
21161 | } |
21162 | } | |
21163 | ||
21164 | /* Return a pointer to a function's name with any | |
21165 | and all prefix encodings stripped from it. */ | |
21166 | const char * | |
e32bac5b | 21167 | arm_strip_name_encoding (const char *name) |
c27ba912 DM |
21168 | { |
21169 | int skip; | |
f676971a | 21170 | |
c27ba912 DM |
21171 | while ((skip = arm_get_strip_length (* name))) |
21172 | name += skip; | |
21173 | ||
21174 | return name; | |
21175 | } | |
21176 | ||
e1944073 KW |
21177 | /* If there is a '*' anywhere in the name's prefix, then |
21178 | emit the stripped name verbatim, otherwise prepend an | |
21179 | underscore if leading underscores are being used. */ | |
e1944073 | 21180 | void |
e32bac5b | 21181 | arm_asm_output_labelref (FILE *stream, const char *name) |
e1944073 KW |
21182 | { |
21183 | int skip; | |
21184 | int verbatim = 0; | |
21185 | ||
21186 | while ((skip = arm_get_strip_length (* name))) | |
21187 | { | |
21188 | verbatim |= (*name == '*'); | |
21189 | name += skip; | |
21190 | } | |
21191 | ||
21192 | if (verbatim) | |
21193 | fputs (name, stream); | |
21194 | else | |
21195 | asm_fprintf (stream, "%U%s", name); | |
21196 | } | |
21197 | ||
6c6aa1af PB |
21198 | static void |
21199 | arm_file_start (void) | |
21200 | { | |
21201 | int val; | |
21202 | ||
5b3e6663 PB |
21203 | if (TARGET_UNIFIED_ASM) |
21204 | asm_fprintf (asm_out_file, "\t.syntax unified\n"); | |
21205 | ||
6c6aa1af PB |
21206 | if (TARGET_BPABI) |
21207 | { | |
21208 | const char *fpu_name; | |
12a0a4d4 PB |
21209 | if (arm_selected_arch) |
21210 | asm_fprintf (asm_out_file, "\t.arch %s\n", arm_selected_arch->name); | |
6c6aa1af | 21211 | else |
12a0a4d4 | 21212 | asm_fprintf (asm_out_file, "\t.cpu %s\n", arm_selected_cpu->name); |
6c6aa1af PB |
21213 | |
21214 | if (TARGET_SOFT_FLOAT) | |
21215 | { | |
21216 | if (TARGET_VFP) | |
21217 | fpu_name = "softvfp"; | |
21218 | else | |
21219 | fpu_name = "softfpa"; | |
21220 | } | |
21221 | else | |
21222 | { | |
d79f3032 PB |
21223 | fpu_name = arm_fpu_desc->name; |
21224 | if (arm_fpu_desc->model == ARM_FP_MODEL_VFP) | |
f1adb0a9 JB |
21225 | { |
21226 | if (TARGET_HARD_FLOAT) | |
21227 | asm_fprintf (asm_out_file, "\t.eabi_attribute 27, 3\n"); | |
21228 | if (TARGET_HARD_FLOAT_ABI) | |
21229 | asm_fprintf (asm_out_file, "\t.eabi_attribute 28, 1\n"); | |
21230 | } | |
6c6aa1af PB |
21231 | } |
21232 | asm_fprintf (asm_out_file, "\t.fpu %s\n", fpu_name); | |
21233 | ||
21234 | /* Some of these attributes only apply when the corresponding features | |
21235 | are used. However we don't have any easy way of figuring this out. | |
21236 | Conservatively record the setting that would have been used. */ | |
21237 | ||
6c6aa1af PB |
21238 | /* Tag_ABI_FP_rounding. */ |
21239 | if (flag_rounding_math) | |
21240 | asm_fprintf (asm_out_file, "\t.eabi_attribute 19, 1\n"); | |
21241 | if (!flag_unsafe_math_optimizations) | |
21242 | { | |
21243 | /* Tag_ABI_FP_denomal. */ | |
21244 | asm_fprintf (asm_out_file, "\t.eabi_attribute 20, 1\n"); | |
21245 | /* Tag_ABI_FP_exceptions. */ | |
21246 | asm_fprintf (asm_out_file, "\t.eabi_attribute 21, 1\n"); | |
21247 | } | |
21248 | /* Tag_ABI_FP_user_exceptions. */ | |
21249 | if (flag_signaling_nans) | |
21250 | asm_fprintf (asm_out_file, "\t.eabi_attribute 22, 1\n"); | |
21251 | /* Tag_ABI_FP_number_model. */ | |
21252 | asm_fprintf (asm_out_file, "\t.eabi_attribute 23, %d\n", | |
21253 | flag_finite_math_only ? 1 : 3); | |
21254 | ||
21255 | /* Tag_ABI_align8_needed. */ | |
21256 | asm_fprintf (asm_out_file, "\t.eabi_attribute 24, 1\n"); | |
21257 | /* Tag_ABI_align8_preserved. */ | |
21258 | asm_fprintf (asm_out_file, "\t.eabi_attribute 25, 1\n"); | |
21259 | /* Tag_ABI_enum_size. */ | |
21260 | asm_fprintf (asm_out_file, "\t.eabi_attribute 26, %d\n", | |
21261 | flag_short_enums ? 1 : 2); | |
21262 | ||
21263 | /* Tag_ABI_optimization_goals. */ | |
21264 | if (optimize_size) | |
21265 | val = 4; | |
21266 | else if (optimize >= 2) | |
21267 | val = 2; | |
21268 | else if (optimize) | |
21269 | val = 1; | |
21270 | else | |
21271 | val = 6; | |
21272 | asm_fprintf (asm_out_file, "\t.eabi_attribute 30, %d\n", val); | |
b76c3c4b | 21273 | |
0fd8c3ad SL |
21274 | /* Tag_ABI_FP_16bit_format. */ |
21275 | if (arm_fp16_format) | |
21276 | asm_fprintf (asm_out_file, "\t.eabi_attribute 38, %d\n", | |
21277 | (int)arm_fp16_format); | |
21278 | ||
b76c3c4b PB |
21279 | if (arm_lang_output_object_attributes_hook) |
21280 | arm_lang_output_object_attributes_hook(); | |
6c6aa1af PB |
21281 | } |
21282 | default_file_start(); | |
21283 | } | |
21284 | ||
b12a00f1 RE |
21285 | static void |
21286 | arm_file_end (void) | |
21287 | { | |
21288 | int regno; | |
21289 | ||
978e411f CD |
21290 | if (NEED_INDICATE_EXEC_STACK) |
21291 | /* Add .note.GNU-stack. */ | |
21292 | file_end_indicate_exec_stack (); | |
21293 | ||
b12a00f1 RE |
21294 | if (! thumb_call_reg_needed) |
21295 | return; | |
21296 | ||
d6b5193b | 21297 | switch_to_section (text_section); |
b12a00f1 RE |
21298 | asm_fprintf (asm_out_file, "\t.code 16\n"); |
21299 | ASM_OUTPUT_ALIGN (asm_out_file, 1); | |
21300 | ||
57ecec57 | 21301 | for (regno = 0; regno < LR_REGNUM; regno++) |
b12a00f1 RE |
21302 | { |
21303 | rtx label = thumb_call_via_label[regno]; | |
21304 | ||
21305 | if (label != 0) | |
21306 | { | |
21307 | targetm.asm_out.internal_label (asm_out_file, "L", | |
21308 | CODE_LABEL_NUMBER (label)); | |
21309 | asm_fprintf (asm_out_file, "\tbx\t%r\n", regno); | |
21310 | } | |
21311 | } | |
21312 | } | |
21313 | ||
fb49053f RH |
21314 | #ifndef ARM_PE |
21315 | /* Symbols in the text segment can be accessed without indirecting via the | |
21316 | constant pool; it may take an extra binary operation, but this is still | |
21317 | faster than indirecting via memory. Don't do this when not optimizing, | |
21318 | since we won't be calculating al of the offsets necessary to do this | |
21319 | simplification. */ | |
21320 | ||
21321 | static void | |
e32bac5b | 21322 | arm_encode_section_info (tree decl, rtx rtl, int first) |
fb49053f | 21323 | { |
3521b33c | 21324 | if (optimize > 0 && TREE_CONSTANT (decl)) |
c6a2438a | 21325 | SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1; |
fb49053f | 21326 | |
d3585b76 | 21327 | default_encode_section_info (decl, rtl, first); |
fb49053f RH |
21328 | } |
21329 | #endif /* !ARM_PE */ | |
483ab821 | 21330 | |
4977bab6 | 21331 | static void |
e32bac5b | 21332 | arm_internal_label (FILE *stream, const char *prefix, unsigned long labelno) |
4977bab6 ZW |
21333 | { |
21334 | if (arm_ccfsm_state == 3 && (unsigned) arm_target_label == labelno | |
21335 | && !strcmp (prefix, "L")) | |
21336 | { | |
21337 | arm_ccfsm_state = 0; | |
21338 | arm_target_insn = NULL; | |
21339 | } | |
21340 | default_internal_label (stream, prefix, labelno); | |
21341 | } | |
21342 | ||
c590b625 RH |
21343 | /* Output code to add DELTA to the first argument, and then jump |
21344 | to FUNCTION. Used for C++ multiple inheritance. */ | |
c590b625 | 21345 | static void |
e32bac5b RE |
21346 | arm_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED, |
21347 | HOST_WIDE_INT delta, | |
21348 | HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED, | |
21349 | tree function) | |
483ab821 | 21350 | { |
9b66ebb1 PB |
21351 | static int thunk_label = 0; |
21352 | char label[256]; | |
54b9e939 | 21353 | char labelpc[256]; |
483ab821 MM |
21354 | int mi_delta = delta; |
21355 | const char *const mi_op = mi_delta < 0 ? "sub" : "add"; | |
21356 | int shift = 0; | |
61f71b34 | 21357 | int this_regno = (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function) |
483ab821 MM |
21358 | ? 1 : 0); |
21359 | if (mi_delta < 0) | |
21360 | mi_delta = - mi_delta; | |
bf98ec6c | 21361 | |
5b3e6663 | 21362 | if (TARGET_THUMB1) |
9b66ebb1 PB |
21363 | { |
21364 | int labelno = thunk_label++; | |
21365 | ASM_GENERATE_INTERNAL_LABEL (label, "LTHUMBFUNC", labelno); | |
bf98ec6c PB |
21366 | /* Thunks are entered in arm mode when avaiable. */ |
21367 | if (TARGET_THUMB1_ONLY) | |
21368 | { | |
21369 | /* push r3 so we can use it as a temporary. */ | |
21370 | /* TODO: Omit this save if r3 is not used. */ | |
21371 | fputs ("\tpush {r3}\n", file); | |
21372 | fputs ("\tldr\tr3, ", file); | |
21373 | } | |
21374 | else | |
21375 | { | |
21376 | fputs ("\tldr\tr12, ", file); | |
21377 | } | |
9b66ebb1 PB |
21378 | assemble_name (file, label); |
21379 | fputc ('\n', file); | |
54b9e939 KH |
21380 | if (flag_pic) |
21381 | { | |
21382 | /* If we are generating PIC, the ldr instruction below loads | |
21383 | "(target - 7) - .LTHUNKPCn" into r12. The pc reads as | |
21384 | the address of the add + 8, so we have: | |
21385 | ||
21386 | r12 = (target - 7) - .LTHUNKPCn + (.LTHUNKPCn + 8) | |
21387 | = target + 1. | |
21388 | ||
21389 | Note that we have "+ 1" because some versions of GNU ld | |
21390 | don't set the low bit of the result for R_ARM_REL32 | |
bf98ec6c PB |
21391 | relocations against thumb function symbols. |
21392 | On ARMv6M this is +4, not +8. */ | |
54b9e939 KH |
21393 | ASM_GENERATE_INTERNAL_LABEL (labelpc, "LTHUNKPC", labelno); |
21394 | assemble_name (file, labelpc); | |
21395 | fputs (":\n", file); | |
bf98ec6c PB |
21396 | if (TARGET_THUMB1_ONLY) |
21397 | { | |
21398 | /* This is 2 insns after the start of the thunk, so we know it | |
21399 | is 4-byte aligned. */ | |
21400 | fputs ("\tadd\tr3, pc, r3\n", file); | |
21401 | fputs ("\tmov r12, r3\n", file); | |
21402 | } | |
21403 | else | |
21404 | fputs ("\tadd\tr12, pc, r12\n", file); | |
54b9e939 | 21405 | } |
bf98ec6c PB |
21406 | else if (TARGET_THUMB1_ONLY) |
21407 | fputs ("\tmov r12, r3\n", file); | |
9b66ebb1 | 21408 | } |
bf98ec6c | 21409 | if (TARGET_THUMB1_ONLY) |
483ab821 | 21410 | { |
bf98ec6c PB |
21411 | if (mi_delta > 255) |
21412 | { | |
21413 | fputs ("\tldr\tr3, ", file); | |
21414 | assemble_name (file, label); | |
21415 | fputs ("+4\n", file); | |
21416 | asm_fprintf (file, "\t%s\t%r, %r, r3\n", | |
21417 | mi_op, this_regno, this_regno); | |
21418 | } | |
21419 | else if (mi_delta != 0) | |
21420 | { | |
21421 | asm_fprintf (file, "\t%s\t%r, %r, #%d\n", | |
21422 | mi_op, this_regno, this_regno, | |
21423 | mi_delta); | |
21424 | } | |
21425 | } | |
21426 | else | |
21427 | { | |
21428 | /* TODO: Use movw/movt for large constants when available. */ | |
21429 | while (mi_delta != 0) | |
21430 | { | |
21431 | if ((mi_delta & (3 << shift)) == 0) | |
21432 | shift += 2; | |
21433 | else | |
21434 | { | |
21435 | asm_fprintf (file, "\t%s\t%r, %r, #%d\n", | |
21436 | mi_op, this_regno, this_regno, | |
21437 | mi_delta & (0xff << shift)); | |
21438 | mi_delta &= ~(0xff << shift); | |
21439 | shift += 8; | |
21440 | } | |
21441 | } | |
483ab821 | 21442 | } |
5b3e6663 | 21443 | if (TARGET_THUMB1) |
9b66ebb1 | 21444 | { |
bf98ec6c PB |
21445 | if (TARGET_THUMB1_ONLY) |
21446 | fputs ("\tpop\t{r3}\n", file); | |
21447 | ||
9b66ebb1 PB |
21448 | fprintf (file, "\tbx\tr12\n"); |
21449 | ASM_OUTPUT_ALIGN (file, 2); | |
21450 | assemble_name (file, label); | |
21451 | fputs (":\n", file); | |
54b9e939 KH |
21452 | if (flag_pic) |
21453 | { | |
21454 | /* Output ".word .LTHUNKn-7-.LTHUNKPCn". */ | |
21455 | rtx tem = XEXP (DECL_RTL (function), 0); | |
21456 | tem = gen_rtx_PLUS (GET_MODE (tem), tem, GEN_INT (-7)); | |
21457 | tem = gen_rtx_MINUS (GET_MODE (tem), | |
21458 | tem, | |
21459 | gen_rtx_SYMBOL_REF (Pmode, | |
21460 | ggc_strdup (labelpc))); | |
21461 | assemble_integer (tem, 4, BITS_PER_WORD, 1); | |
21462 | } | |
21463 | else | |
21464 | /* Output ".word .LTHUNKn". */ | |
21465 | assemble_integer (XEXP (DECL_RTL (function), 0), 4, BITS_PER_WORD, 1); | |
bf98ec6c PB |
21466 | |
21467 | if (TARGET_THUMB1_ONLY && mi_delta > 255) | |
21468 | assemble_integer (GEN_INT(mi_delta), 4, BITS_PER_WORD, 1); | |
9b66ebb1 PB |
21469 | } |
21470 | else | |
21471 | { | |
21472 | fputs ("\tb\t", file); | |
21473 | assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0)); | |
21474 | if (NEED_PLT_RELOC) | |
21475 | fputs ("(PLT)", file); | |
21476 | fputc ('\n', file); | |
21477 | } | |
483ab821 | 21478 | } |
5a9335ef NC |
21479 | |
21480 | int | |
6f5f2481 | 21481 | arm_emit_vector_const (FILE *file, rtx x) |
5a9335ef NC |
21482 | { |
21483 | int i; | |
21484 | const char * pattern; | |
21485 | ||
e6d29d15 | 21486 | gcc_assert (GET_CODE (x) == CONST_VECTOR); |
5a9335ef NC |
21487 | |
21488 | switch (GET_MODE (x)) | |
21489 | { | |
21490 | case V2SImode: pattern = "%08x"; break; | |
21491 | case V4HImode: pattern = "%04x"; break; | |
21492 | case V8QImode: pattern = "%02x"; break; | |
e6d29d15 | 21493 | default: gcc_unreachable (); |
5a9335ef NC |
21494 | } |
21495 | ||
21496 | fprintf (file, "0x"); | |
21497 | for (i = CONST_VECTOR_NUNITS (x); i--;) | |
21498 | { | |
21499 | rtx element; | |
21500 | ||
21501 | element = CONST_VECTOR_ELT (x, i); | |
21502 | fprintf (file, pattern, INTVAL (element)); | |
21503 | } | |
21504 | ||
21505 | return 1; | |
21506 | } | |
21507 | ||
0fd8c3ad SL |
21508 | /* Emit a fp16 constant appropriately padded to occupy a 4-byte word. |
21509 | HFmode constant pool entries are actually loaded with ldr. */ | |
21510 | void | |
21511 | arm_emit_fp16_const (rtx c) | |
21512 | { | |
21513 | REAL_VALUE_TYPE r; | |
21514 | long bits; | |
21515 | ||
21516 | REAL_VALUE_FROM_CONST_DOUBLE (r, c); | |
21517 | bits = real_to_target (NULL, &r, HFmode); | |
21518 | if (WORDS_BIG_ENDIAN) | |
21519 | assemble_zeros (2); | |
21520 | assemble_integer (GEN_INT (bits), 2, BITS_PER_WORD, 1); | |
21521 | if (!WORDS_BIG_ENDIAN) | |
21522 | assemble_zeros (2); | |
21523 | } | |
21524 | ||
5a9335ef | 21525 | const char * |
6f5f2481 | 21526 | arm_output_load_gr (rtx *operands) |
5a9335ef NC |
21527 | { |
21528 | rtx reg; | |
21529 | rtx offset; | |
21530 | rtx wcgr; | |
21531 | rtx sum; | |
f676971a | 21532 | |
5a9335ef NC |
21533 | if (GET_CODE (operands [1]) != MEM |
21534 | || GET_CODE (sum = XEXP (operands [1], 0)) != PLUS | |
21535 | || GET_CODE (reg = XEXP (sum, 0)) != REG | |
21536 | || GET_CODE (offset = XEXP (sum, 1)) != CONST_INT | |
21537 | || ((INTVAL (offset) < 1024) && (INTVAL (offset) > -1024))) | |
21538 | return "wldrw%?\t%0, %1"; | |
f676971a EC |
21539 | |
21540 | /* Fix up an out-of-range load of a GR register. */ | |
5a9335ef NC |
21541 | output_asm_insn ("str%?\t%0, [sp, #-4]!\t@ Start of GR load expansion", & reg); |
21542 | wcgr = operands[0]; | |
21543 | operands[0] = reg; | |
21544 | output_asm_insn ("ldr%?\t%0, %1", operands); | |
21545 | ||
21546 | operands[0] = wcgr; | |
21547 | operands[1] = reg; | |
21548 | output_asm_insn ("tmcr%?\t%0, %1", operands); | |
21549 | output_asm_insn ("ldr%?\t%0, [sp], #4\t@ End of GR load expansion", & reg); | |
21550 | ||
21551 | return ""; | |
21552 | } | |
f9ba5949 | 21553 | |
1cc9f5f5 KH |
21554 | /* Worker function for TARGET_SETUP_INCOMING_VARARGS. |
21555 | ||
21556 | On the ARM, PRETEND_SIZE is set in order to have the prologue push the last | |
21557 | named arg and all anonymous args onto the stack. | |
21558 | XXX I know the prologue shouldn't be pushing registers, but it is faster | |
21559 | that way. */ | |
21560 | ||
21561 | static void | |
390b17c2 | 21562 | arm_setup_incoming_varargs (CUMULATIVE_ARGS *pcum, |
22ccaaee JJ |
21563 | enum machine_mode mode, |
21564 | tree type, | |
1cc9f5f5 KH |
21565 | int *pretend_size, |
21566 | int second_time ATTRIBUTE_UNUSED) | |
21567 | { | |
390b17c2 RE |
21568 | int nregs; |
21569 | ||
1cc9f5f5 | 21570 | cfun->machine->uses_anonymous_args = 1; |
390b17c2 RE |
21571 | if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) |
21572 | { | |
21573 | nregs = pcum->aapcs_ncrn; | |
21574 | if ((nregs & 1) && arm_needs_doubleword_align (mode, type)) | |
21575 | nregs++; | |
21576 | } | |
21577 | else | |
21578 | nregs = pcum->nregs; | |
21579 | ||
22ccaaee JJ |
21580 | if (nregs < NUM_ARG_REGS) |
21581 | *pretend_size = (NUM_ARG_REGS - nregs) * UNITS_PER_WORD; | |
1cc9f5f5 | 21582 | } |
9b66ebb1 | 21583 | |
59b9a953 | 21584 | /* Return nonzero if the CONSUMER instruction (a store) does not need |
9b66ebb1 PB |
21585 | PRODUCER's value to calculate the address. */ |
21586 | ||
21587 | int | |
21588 | arm_no_early_store_addr_dep (rtx producer, rtx consumer) | |
21589 | { | |
21590 | rtx value = PATTERN (producer); | |
21591 | rtx addr = PATTERN (consumer); | |
21592 | ||
21593 | if (GET_CODE (value) == COND_EXEC) | |
21594 | value = COND_EXEC_CODE (value); | |
21595 | if (GET_CODE (value) == PARALLEL) | |
21596 | value = XVECEXP (value, 0, 0); | |
21597 | value = XEXP (value, 0); | |
21598 | if (GET_CODE (addr) == COND_EXEC) | |
21599 | addr = COND_EXEC_CODE (addr); | |
21600 | if (GET_CODE (addr) == PARALLEL) | |
21601 | addr = XVECEXP (addr, 0, 0); | |
21602 | addr = XEXP (addr, 0); | |
f676971a | 21603 | |
9b66ebb1 PB |
21604 | return !reg_overlap_mentioned_p (value, addr); |
21605 | } | |
21606 | ||
47d8f18d JZ |
21607 | /* Return nonzero if the CONSUMER instruction (a store) does need |
21608 | PRODUCER's value to calculate the address. */ | |
21609 | ||
21610 | int | |
21611 | arm_early_store_addr_dep (rtx producer, rtx consumer) | |
21612 | { | |
21613 | return !arm_no_early_store_addr_dep (producer, consumer); | |
21614 | } | |
21615 | ||
21616 | /* Return nonzero if the CONSUMER instruction (a load) does need | |
21617 | PRODUCER's value to calculate the address. */ | |
21618 | ||
21619 | int | |
21620 | arm_early_load_addr_dep (rtx producer, rtx consumer) | |
21621 | { | |
21622 | rtx value = PATTERN (producer); | |
21623 | rtx addr = PATTERN (consumer); | |
21624 | ||
21625 | if (GET_CODE (value) == COND_EXEC) | |
21626 | value = COND_EXEC_CODE (value); | |
21627 | if (GET_CODE (value) == PARALLEL) | |
21628 | value = XVECEXP (value, 0, 0); | |
21629 | value = XEXP (value, 0); | |
21630 | if (GET_CODE (addr) == COND_EXEC) | |
21631 | addr = COND_EXEC_CODE (addr); | |
21632 | if (GET_CODE (addr) == PARALLEL) | |
21633 | addr = XVECEXP (addr, 0, 0); | |
21634 | addr = XEXP (addr, 1); | |
21635 | ||
21636 | return reg_overlap_mentioned_p (value, addr); | |
21637 | } | |
21638 | ||
59b9a953 | 21639 | /* Return nonzero if the CONSUMER instruction (an ALU op) does not |
9b66ebb1 PB |
21640 | have an early register shift value or amount dependency on the |
21641 | result of PRODUCER. */ | |
21642 | ||
21643 | int | |
21644 | arm_no_early_alu_shift_dep (rtx producer, rtx consumer) | |
21645 | { | |
21646 | rtx value = PATTERN (producer); | |
21647 | rtx op = PATTERN (consumer); | |
21648 | rtx early_op; | |
21649 | ||
21650 | if (GET_CODE (value) == COND_EXEC) | |
21651 | value = COND_EXEC_CODE (value); | |
21652 | if (GET_CODE (value) == PARALLEL) | |
21653 | value = XVECEXP (value, 0, 0); | |
21654 | value = XEXP (value, 0); | |
21655 | if (GET_CODE (op) == COND_EXEC) | |
21656 | op = COND_EXEC_CODE (op); | |
21657 | if (GET_CODE (op) == PARALLEL) | |
21658 | op = XVECEXP (op, 0, 0); | |
21659 | op = XEXP (op, 1); | |
f676971a | 21660 | |
9b66ebb1 PB |
21661 | early_op = XEXP (op, 0); |
21662 | /* This is either an actual independent shift, or a shift applied to | |
21663 | the first operand of another operation. We want the whole shift | |
21664 | operation. */ | |
21665 | if (GET_CODE (early_op) == REG) | |
21666 | early_op = op; | |
21667 | ||
21668 | return !reg_overlap_mentioned_p (value, early_op); | |
21669 | } | |
21670 | ||
59b9a953 | 21671 | /* Return nonzero if the CONSUMER instruction (an ALU op) does not |
9b66ebb1 PB |
21672 | have an early register shift value dependency on the result of |
21673 | PRODUCER. */ | |
21674 | ||
21675 | int | |
21676 | arm_no_early_alu_shift_value_dep (rtx producer, rtx consumer) | |
21677 | { | |
21678 | rtx value = PATTERN (producer); | |
21679 | rtx op = PATTERN (consumer); | |
21680 | rtx early_op; | |
21681 | ||
21682 | if (GET_CODE (value) == COND_EXEC) | |
21683 | value = COND_EXEC_CODE (value); | |
21684 | if (GET_CODE (value) == PARALLEL) | |
21685 | value = XVECEXP (value, 0, 0); | |
21686 | value = XEXP (value, 0); | |
21687 | if (GET_CODE (op) == COND_EXEC) | |
21688 | op = COND_EXEC_CODE (op); | |
21689 | if (GET_CODE (op) == PARALLEL) | |
21690 | op = XVECEXP (op, 0, 0); | |
21691 | op = XEXP (op, 1); | |
f676971a | 21692 | |
9b66ebb1 PB |
21693 | early_op = XEXP (op, 0); |
21694 | ||
21695 | /* This is either an actual independent shift, or a shift applied to | |
21696 | the first operand of another operation. We want the value being | |
21697 | shifted, in either case. */ | |
21698 | if (GET_CODE (early_op) != REG) | |
21699 | early_op = XEXP (early_op, 0); | |
f676971a | 21700 | |
9b66ebb1 PB |
21701 | return !reg_overlap_mentioned_p (value, early_op); |
21702 | } | |
21703 | ||
59b9a953 | 21704 | /* Return nonzero if the CONSUMER (a mul or mac op) does not |
9b66ebb1 PB |
21705 | have an early register mult dependency on the result of |
21706 | PRODUCER. */ | |
21707 | ||
21708 | int | |
21709 | arm_no_early_mul_dep (rtx producer, rtx consumer) | |
21710 | { | |
21711 | rtx value = PATTERN (producer); | |
21712 | rtx op = PATTERN (consumer); | |
21713 | ||
21714 | if (GET_CODE (value) == COND_EXEC) | |
21715 | value = COND_EXEC_CODE (value); | |
21716 | if (GET_CODE (value) == PARALLEL) | |
21717 | value = XVECEXP (value, 0, 0); | |
21718 | value = XEXP (value, 0); | |
21719 | if (GET_CODE (op) == COND_EXEC) | |
21720 | op = COND_EXEC_CODE (op); | |
21721 | if (GET_CODE (op) == PARALLEL) | |
21722 | op = XVECEXP (op, 0, 0); | |
21723 | op = XEXP (op, 1); | |
f676971a | 21724 | |
756f763b PB |
21725 | if (GET_CODE (op) == PLUS || GET_CODE (op) == MINUS) |
21726 | { | |
21727 | if (GET_CODE (XEXP (op, 0)) == MULT) | |
21728 | return !reg_overlap_mentioned_p (value, XEXP (op, 0)); | |
21729 | else | |
21730 | return !reg_overlap_mentioned_p (value, XEXP (op, 1)); | |
21731 | } | |
21732 | ||
21733 | return 0; | |
9b66ebb1 PB |
21734 | } |
21735 | ||
70301b45 PB |
21736 | /* We can't rely on the caller doing the proper promotion when |
21737 | using APCS or ATPCS. */ | |
21738 | ||
21739 | static bool | |
586de218 | 21740 | arm_promote_prototypes (const_tree t ATTRIBUTE_UNUSED) |
70301b45 | 21741 | { |
b6685939 | 21742 | return !TARGET_AAPCS_BASED; |
70301b45 PB |
21743 | } |
21744 | ||
cde0f3fd PB |
21745 | static enum machine_mode |
21746 | arm_promote_function_mode (const_tree type ATTRIBUTE_UNUSED, | |
21747 | enum machine_mode mode, | |
21748 | int *punsignedp ATTRIBUTE_UNUSED, | |
21749 | const_tree fntype ATTRIBUTE_UNUSED, | |
21750 | int for_return ATTRIBUTE_UNUSED) | |
21751 | { | |
21752 | if (GET_MODE_CLASS (mode) == MODE_INT | |
21753 | && GET_MODE_SIZE (mode) < 4) | |
21754 | return SImode; | |
21755 | ||
21756 | return mode; | |
21757 | } | |
6b045785 PB |
21758 | |
21759 | /* AAPCS based ABIs use short enums by default. */ | |
21760 | ||
21761 | static bool | |
21762 | arm_default_short_enums (void) | |
21763 | { | |
077fc835 | 21764 | return TARGET_AAPCS_BASED && arm_abi != ARM_ABI_AAPCS_LINUX; |
6b045785 | 21765 | } |
13c1cd82 PB |
21766 | |
21767 | ||
21768 | /* AAPCS requires that anonymous bitfields affect structure alignment. */ | |
21769 | ||
21770 | static bool | |
21771 | arm_align_anon_bitfield (void) | |
21772 | { | |
21773 | return TARGET_AAPCS_BASED; | |
21774 | } | |
4185ae53 PB |
21775 | |
21776 | ||
21777 | /* The generic C++ ABI says 64-bit (long long). The EABI says 32-bit. */ | |
21778 | ||
21779 | static tree | |
21780 | arm_cxx_guard_type (void) | |
21781 | { | |
21782 | return TARGET_AAPCS_BASED ? integer_type_node : long_long_integer_type_node; | |
21783 | } | |
21784 | ||
c956e102 MS |
21785 | /* Return non-zero if the consumer (a multiply-accumulate instruction) |
21786 | has an accumulator dependency on the result of the producer (a | |
21787 | multiplication instruction) and no other dependency on that result. */ | |
21788 | int | |
21789 | arm_mac_accumulator_is_mul_result (rtx producer, rtx consumer) | |
21790 | { | |
21791 | rtx mul = PATTERN (producer); | |
21792 | rtx mac = PATTERN (consumer); | |
21793 | rtx mul_result; | |
21794 | rtx mac_op0, mac_op1, mac_acc; | |
21795 | ||
21796 | if (GET_CODE (mul) == COND_EXEC) | |
21797 | mul = COND_EXEC_CODE (mul); | |
21798 | if (GET_CODE (mac) == COND_EXEC) | |
21799 | mac = COND_EXEC_CODE (mac); | |
21800 | ||
21801 | /* Check that mul is of the form (set (...) (mult ...)) | |
21802 | and mla is of the form (set (...) (plus (mult ...) (...))). */ | |
21803 | if ((GET_CODE (mul) != SET || GET_CODE (XEXP (mul, 1)) != MULT) | |
21804 | || (GET_CODE (mac) != SET || GET_CODE (XEXP (mac, 1)) != PLUS | |
21805 | || GET_CODE (XEXP (XEXP (mac, 1), 0)) != MULT)) | |
21806 | return 0; | |
21807 | ||
21808 | mul_result = XEXP (mul, 0); | |
21809 | mac_op0 = XEXP (XEXP (XEXP (mac, 1), 0), 0); | |
21810 | mac_op1 = XEXP (XEXP (XEXP (mac, 1), 0), 1); | |
21811 | mac_acc = XEXP (XEXP (mac, 1), 1); | |
21812 | ||
21813 | return (reg_overlap_mentioned_p (mul_result, mac_acc) | |
21814 | && !reg_overlap_mentioned_p (mul_result, mac_op0) | |
21815 | && !reg_overlap_mentioned_p (mul_result, mac_op1)); | |
21816 | } | |
21817 | ||
4185ae53 | 21818 | |
0fa2e4df | 21819 | /* The EABI says test the least significant bit of a guard variable. */ |
4185ae53 PB |
21820 | |
21821 | static bool | |
21822 | arm_cxx_guard_mask_bit (void) | |
21823 | { | |
21824 | return TARGET_AAPCS_BASED; | |
21825 | } | |
46e995e0 PB |
21826 | |
21827 | ||
21828 | /* The EABI specifies that all array cookies are 8 bytes long. */ | |
21829 | ||
21830 | static tree | |
21831 | arm_get_cookie_size (tree type) | |
21832 | { | |
21833 | tree size; | |
21834 | ||
21835 | if (!TARGET_AAPCS_BASED) | |
21836 | return default_cxx_get_cookie_size (type); | |
21837 | ||
7d60be94 | 21838 | size = build_int_cst (sizetype, 8); |
46e995e0 PB |
21839 | return size; |
21840 | } | |
21841 | ||
21842 | ||
21843 | /* The EABI says that array cookies should also contain the element size. */ | |
21844 | ||
21845 | static bool | |
21846 | arm_cookie_has_size (void) | |
21847 | { | |
21848 | return TARGET_AAPCS_BASED; | |
21849 | } | |
44d10c10 PB |
21850 | |
21851 | ||
21852 | /* The EABI says constructors and destructors should return a pointer to | |
21853 | the object constructed/destroyed. */ | |
21854 | ||
21855 | static bool | |
21856 | arm_cxx_cdtor_returns_this (void) | |
21857 | { | |
21858 | return TARGET_AAPCS_BASED; | |
21859 | } | |
c9ca9b88 | 21860 | |
505970fc MM |
21861 | /* The EABI says that an inline function may never be the key |
21862 | method. */ | |
21863 | ||
21864 | static bool | |
21865 | arm_cxx_key_method_may_be_inline (void) | |
21866 | { | |
21867 | return !TARGET_AAPCS_BASED; | |
21868 | } | |
21869 | ||
1e731102 MM |
21870 | static void |
21871 | arm_cxx_determine_class_data_visibility (tree decl) | |
21872 | { | |
711b2998 JB |
21873 | if (!TARGET_AAPCS_BASED |
21874 | || !TARGET_DLLIMPORT_DECL_ATTRIBUTES) | |
1e731102 | 21875 | return; |
505970fc | 21876 | |
1e731102 MM |
21877 | /* In general, \S 3.2.5.5 of the ARM EABI requires that class data |
21878 | is exported. However, on systems without dynamic vague linkage, | |
21879 | \S 3.2.5.6 says that COMDAT class data has hidden linkage. */ | |
21880 | if (!TARGET_ARM_DYNAMIC_VAGUE_LINKAGE_P && DECL_COMDAT (decl)) | |
21881 | DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; | |
21882 | else | |
21883 | DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; | |
21884 | DECL_VISIBILITY_SPECIFIED (decl) = 1; | |
21885 | } | |
e0b92319 | 21886 | |
505970fc | 21887 | static bool |
1e731102 | 21888 | arm_cxx_class_data_always_comdat (void) |
505970fc | 21889 | { |
1e731102 MM |
21890 | /* \S 3.2.5.4 of the ARM C++ ABI says that class data only have |
21891 | vague linkage if the class has no key function. */ | |
21892 | return !TARGET_AAPCS_BASED; | |
505970fc | 21893 | } |
c9ca9b88 | 21894 | |
9f62c3e3 PB |
21895 | |
21896 | /* The EABI says __aeabi_atexit should be used to register static | |
21897 | destructors. */ | |
21898 | ||
21899 | static bool | |
21900 | arm_cxx_use_aeabi_atexit (void) | |
21901 | { | |
21902 | return TARGET_AAPCS_BASED; | |
21903 | } | |
21904 | ||
21905 | ||
c9ca9b88 PB |
21906 | void |
21907 | arm_set_return_address (rtx source, rtx scratch) | |
21908 | { | |
21909 | arm_stack_offsets *offsets; | |
21910 | HOST_WIDE_INT delta; | |
21911 | rtx addr; | |
21912 | unsigned long saved_regs; | |
21913 | ||
954954d1 PB |
21914 | offsets = arm_get_frame_offsets (); |
21915 | saved_regs = offsets->saved_regs_mask; | |
c9ca9b88 PB |
21916 | |
21917 | if ((saved_regs & (1 << LR_REGNUM)) == 0) | |
21918 | emit_move_insn (gen_rtx_REG (Pmode, LR_REGNUM), source); | |
21919 | else | |
21920 | { | |
21921 | if (frame_pointer_needed) | |
21922 | addr = plus_constant(hard_frame_pointer_rtx, -4); | |
21923 | else | |
21924 | { | |
21925 | /* LR will be the first saved register. */ | |
c9ca9b88 PB |
21926 | delta = offsets->outgoing_args - (offsets->frame + 4); |
21927 | ||
f676971a | 21928 | |
c9ca9b88 PB |
21929 | if (delta >= 4096) |
21930 | { | |
21931 | emit_insn (gen_addsi3 (scratch, stack_pointer_rtx, | |
21932 | GEN_INT (delta & ~4095))); | |
21933 | addr = scratch; | |
21934 | delta &= 4095; | |
21935 | } | |
21936 | else | |
21937 | addr = stack_pointer_rtx; | |
21938 | ||
21939 | addr = plus_constant (addr, delta); | |
21940 | } | |
31fa16b6 | 21941 | emit_move_insn (gen_frame_mem (Pmode, addr), source); |
c9ca9b88 PB |
21942 | } |
21943 | } | |
21944 | ||
21945 | ||
21946 | void | |
21947 | thumb_set_return_address (rtx source, rtx scratch) | |
21948 | { | |
21949 | arm_stack_offsets *offsets; | |
c9ca9b88 | 21950 | HOST_WIDE_INT delta; |
5b3e6663 | 21951 | HOST_WIDE_INT limit; |
c9ca9b88 PB |
21952 | int reg; |
21953 | rtx addr; | |
57934c39 | 21954 | unsigned long mask; |
c9ca9b88 | 21955 | |
c41c1387 | 21956 | emit_use (source); |
c9ca9b88 | 21957 | |
954954d1 PB |
21958 | offsets = arm_get_frame_offsets (); |
21959 | mask = offsets->saved_regs_mask; | |
57934c39 | 21960 | if (mask & (1 << LR_REGNUM)) |
c9ca9b88 | 21961 | { |
5b3e6663 | 21962 | limit = 1024; |
c9ca9b88 PB |
21963 | /* Find the saved regs. */ |
21964 | if (frame_pointer_needed) | |
21965 | { | |
21966 | delta = offsets->soft_frame - offsets->saved_args; | |
21967 | reg = THUMB_HARD_FRAME_POINTER_REGNUM; | |
5b3e6663 PB |
21968 | if (TARGET_THUMB1) |
21969 | limit = 128; | |
c9ca9b88 PB |
21970 | } |
21971 | else | |
21972 | { | |
21973 | delta = offsets->outgoing_args - offsets->saved_args; | |
21974 | reg = SP_REGNUM; | |
21975 | } | |
21976 | /* Allow for the stack frame. */ | |
5b3e6663 | 21977 | if (TARGET_THUMB1 && TARGET_BACKTRACE) |
c9ca9b88 PB |
21978 | delta -= 16; |
21979 | /* The link register is always the first saved register. */ | |
21980 | delta -= 4; | |
f676971a | 21981 | |
c9ca9b88 PB |
21982 | /* Construct the address. */ |
21983 | addr = gen_rtx_REG (SImode, reg); | |
5b3e6663 | 21984 | if (delta > limit) |
c9ca9b88 PB |
21985 | { |
21986 | emit_insn (gen_movsi (scratch, GEN_INT (delta))); | |
21987 | emit_insn (gen_addsi3 (scratch, scratch, stack_pointer_rtx)); | |
21988 | addr = scratch; | |
21989 | } | |
21990 | else | |
21991 | addr = plus_constant (addr, delta); | |
21992 | ||
31fa16b6 | 21993 | emit_move_insn (gen_frame_mem (Pmode, addr), source); |
c9ca9b88 PB |
21994 | } |
21995 | else | |
21996 | emit_move_insn (gen_rtx_REG (Pmode, LR_REGNUM), source); | |
21997 | } | |
21998 | ||
f676971a EC |
21999 | /* Implements target hook vector_mode_supported_p. */ |
22000 | bool | |
22001 | arm_vector_mode_supported_p (enum machine_mode mode) | |
22002 | { | |
88f77cba JB |
22003 | /* Neon also supports V2SImode, etc. listed in the clause below. */ |
22004 | if (TARGET_NEON && (mode == V2SFmode || mode == V4SImode || mode == V8HImode | |
22005 | || mode == V16QImode || mode == V4SFmode || mode == V2DImode)) | |
22006 | return true; | |
22007 | ||
390b17c2 RE |
22008 | if ((TARGET_NEON || TARGET_IWMMXT) |
22009 | && ((mode == V2SImode) | |
22010 | || (mode == V4HImode) | |
22011 | || (mode == V8QImode))) | |
f676971a EC |
22012 | return true; |
22013 | ||
22014 | return false; | |
22015 | } | |
273a2526 | 22016 | |
26983c22 L |
22017 | /* Use the option -mvectorize-with-neon-quad to override the use of doubleword |
22018 | registers when autovectorizing for Neon, at least until multiple vector | |
22019 | widths are supported properly by the middle-end. */ | |
22020 | ||
cc4b5170 RG |
22021 | static enum machine_mode |
22022 | arm_preferred_simd_mode (enum machine_mode mode) | |
26983c22 | 22023 | { |
cc4b5170 RG |
22024 | if (TARGET_NEON) |
22025 | switch (mode) | |
22026 | { | |
22027 | case SFmode: | |
22028 | return TARGET_NEON_VECTORIZE_QUAD ? V4SFmode : V2SFmode; | |
22029 | case SImode: | |
22030 | return TARGET_NEON_VECTORIZE_QUAD ? V4SImode : V2SImode; | |
22031 | case HImode: | |
22032 | return TARGET_NEON_VECTORIZE_QUAD ? V8HImode : V4HImode; | |
22033 | case QImode: | |
22034 | return TARGET_NEON_VECTORIZE_QUAD ? V16QImode : V8QImode; | |
22035 | case DImode: | |
22036 | if (TARGET_NEON_VECTORIZE_QUAD) | |
22037 | return V2DImode; | |
22038 | break; | |
22039 | ||
22040 | default:; | |
22041 | } | |
22042 | ||
22043 | if (TARGET_REALLY_IWMMXT) | |
22044 | switch (mode) | |
22045 | { | |
22046 | case SImode: | |
22047 | return V2SImode; | |
22048 | case HImode: | |
22049 | return V4HImode; | |
22050 | case QImode: | |
22051 | return V8QImode; | |
22052 | ||
22053 | default:; | |
22054 | } | |
22055 | ||
22056 | return word_mode; | |
26983c22 L |
22057 | } |
22058 | ||
d163e655 AS |
22059 | /* Implement TARGET_CLASS_LIKELY_SPILLED_P. |
22060 | ||
22061 | We need to define this for LO_REGS on thumb. Otherwise we can end up | |
22062 | using r0-r4 for function arguments, r7 for the stack frame and don't | |
22063 | have enough left over to do doubleword arithmetic. */ | |
22064 | ||
22065 | static bool | |
22066 | arm_class_likely_spilled_p (reg_class_t rclass) | |
22067 | { | |
22068 | if ((TARGET_THUMB && rclass == LO_REGS) | |
22069 | || rclass == CC_REG) | |
22070 | return true; | |
22071 | ||
22072 | return false; | |
22073 | } | |
22074 | ||
42db504c SB |
22075 | /* Implements target hook small_register_classes_for_mode_p. */ |
22076 | bool | |
22077 | arm_small_register_classes_for_mode_p (enum machine_mode mode ATTRIBUTE_UNUSED) | |
22078 | { | |
22079 | return TARGET_THUMB1; | |
22080 | } | |
22081 | ||
273a2526 RS |
22082 | /* Implement TARGET_SHIFT_TRUNCATION_MASK. SImode shifts use normal |
22083 | ARM insns and therefore guarantee that the shift count is modulo 256. | |
22084 | DImode shifts (those implemented by lib1funcs.asm or by optabs.c) | |
22085 | guarantee no particular behavior for out-of-range counts. */ | |
22086 | ||
22087 | static unsigned HOST_WIDE_INT | |
22088 | arm_shift_truncation_mask (enum machine_mode mode) | |
22089 | { | |
22090 | return mode == SImode ? 255 : 0; | |
22091 | } | |
2fa330b2 PB |
22092 | |
22093 | ||
22094 | /* Map internal gcc register numbers to DWARF2 register numbers. */ | |
22095 | ||
22096 | unsigned int | |
22097 | arm_dbx_register_number (unsigned int regno) | |
22098 | { | |
22099 | if (regno < 16) | |
22100 | return regno; | |
22101 | ||
22102 | /* TODO: Legacy targets output FPA regs as registers 16-23 for backwards | |
22103 | compatibility. The EABI defines them as registers 96-103. */ | |
22104 | if (IS_FPA_REGNUM (regno)) | |
22105 | return (TARGET_AAPCS_BASED ? 96 : 16) + regno - FIRST_FPA_REGNUM; | |
22106 | ||
22107 | if (IS_VFP_REGNUM (regno)) | |
854b8a40 JB |
22108 | { |
22109 | /* See comment in arm_dwarf_register_span. */ | |
22110 | if (VFP_REGNO_OK_FOR_SINGLE (regno)) | |
22111 | return 64 + regno - FIRST_VFP_REGNUM; | |
22112 | else | |
22113 | return 256 + (regno - FIRST_VFP_REGNUM) / 2; | |
22114 | } | |
2fa330b2 PB |
22115 | |
22116 | if (IS_IWMMXT_GR_REGNUM (regno)) | |
22117 | return 104 + regno - FIRST_IWMMXT_GR_REGNUM; | |
22118 | ||
22119 | if (IS_IWMMXT_REGNUM (regno)) | |
22120 | return 112 + regno - FIRST_IWMMXT_REGNUM; | |
22121 | ||
e6d29d15 | 22122 | gcc_unreachable (); |
2fa330b2 PB |
22123 | } |
22124 | ||
854b8a40 JB |
22125 | /* Dwarf models VFPv3 registers as 32 64-bit registers. |
22126 | GCC models tham as 64 32-bit registers, so we need to describe this to | |
22127 | the DWARF generation code. Other registers can use the default. */ | |
22128 | static rtx | |
22129 | arm_dwarf_register_span (rtx rtl) | |
22130 | { | |
22131 | unsigned regno; | |
22132 | int nregs; | |
22133 | int i; | |
22134 | rtx p; | |
22135 | ||
22136 | regno = REGNO (rtl); | |
22137 | if (!IS_VFP_REGNUM (regno)) | |
22138 | return NULL_RTX; | |
22139 | ||
22140 | /* XXX FIXME: The EABI defines two VFP register ranges: | |
22141 | 64-95: Legacy VFPv2 numbering for S0-S31 (obsolescent) | |
22142 | 256-287: D0-D31 | |
22143 | The recommended encoding for S0-S31 is a DW_OP_bit_piece of the | |
22144 | corresponding D register. Until GDB supports this, we shall use the | |
22145 | legacy encodings. We also use these encodings for D0-D15 for | |
22146 | compatibility with older debuggers. */ | |
22147 | if (VFP_REGNO_OK_FOR_SINGLE (regno)) | |
22148 | return NULL_RTX; | |
22149 | ||
22150 | nregs = GET_MODE_SIZE (GET_MODE (rtl)) / 8; | |
22151 | p = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs)); | |
22152 | regno = (regno - FIRST_VFP_REGNUM) / 2; | |
22153 | for (i = 0; i < nregs; i++) | |
22154 | XVECEXP (p, 0, i) = gen_rtx_REG (DImode, 256 + regno + i); | |
22155 | ||
22156 | return p; | |
22157 | } | |
617a1b71 | 22158 | |
f0a0390e | 22159 | #if ARM_UNWIND_INFO |
5b3e6663 PB |
22160 | /* Emit unwind directives for a store-multiple instruction or stack pointer |
22161 | push during alignment. | |
22162 | These should only ever be generated by the function prologue code, so | |
22163 | expect them to have a particular form. */ | |
617a1b71 PB |
22164 | |
22165 | static void | |
5b3e6663 | 22166 | arm_unwind_emit_sequence (FILE * asm_out_file, rtx p) |
617a1b71 PB |
22167 | { |
22168 | int i; | |
22169 | HOST_WIDE_INT offset; | |
22170 | HOST_WIDE_INT nregs; | |
22171 | int reg_size; | |
22172 | unsigned reg; | |
22173 | unsigned lastreg; | |
22174 | rtx e; | |
22175 | ||
617a1b71 | 22176 | e = XVECEXP (p, 0, 0); |
5b3e6663 PB |
22177 | if (GET_CODE (e) != SET) |
22178 | abort (); | |
22179 | ||
22180 | /* First insn will adjust the stack pointer. */ | |
617a1b71 PB |
22181 | if (GET_CODE (e) != SET |
22182 | || GET_CODE (XEXP (e, 0)) != REG | |
22183 | || REGNO (XEXP (e, 0)) != SP_REGNUM | |
22184 | || GET_CODE (XEXP (e, 1)) != PLUS) | |
22185 | abort (); | |
22186 | ||
22187 | offset = -INTVAL (XEXP (XEXP (e, 1), 1)); | |
22188 | nregs = XVECLEN (p, 0) - 1; | |
22189 | ||
22190 | reg = REGNO (XEXP (XVECEXP (p, 0, 1), 1)); | |
22191 | if (reg < 16) | |
22192 | { | |
22193 | /* The function prologue may also push pc, but not annotate it as it is | |
569b7f6a | 22194 | never restored. We turn this into a stack pointer adjustment. */ |
617a1b71 PB |
22195 | if (nregs * 4 == offset - 4) |
22196 | { | |
22197 | fprintf (asm_out_file, "\t.pad #4\n"); | |
22198 | offset -= 4; | |
22199 | } | |
22200 | reg_size = 4; | |
8edfc4cc | 22201 | fprintf (asm_out_file, "\t.save {"); |
617a1b71 PB |
22202 | } |
22203 | else if (IS_VFP_REGNUM (reg)) | |
22204 | { | |
617a1b71 | 22205 | reg_size = 8; |
8edfc4cc | 22206 | fprintf (asm_out_file, "\t.vsave {"); |
617a1b71 PB |
22207 | } |
22208 | else if (reg >= FIRST_FPA_REGNUM && reg <= LAST_FPA_REGNUM) | |
22209 | { | |
22210 | /* FPA registers are done differently. */ | |
ea40ba9c | 22211 | asm_fprintf (asm_out_file, "\t.save %r, %wd\n", reg, nregs); |
617a1b71 PB |
22212 | return; |
22213 | } | |
22214 | else | |
22215 | /* Unknown register type. */ | |
22216 | abort (); | |
22217 | ||
22218 | /* If the stack increment doesn't match the size of the saved registers, | |
22219 | something has gone horribly wrong. */ | |
22220 | if (offset != nregs * reg_size) | |
22221 | abort (); | |
22222 | ||
617a1b71 PB |
22223 | offset = 0; |
22224 | lastreg = 0; | |
22225 | /* The remaining insns will describe the stores. */ | |
22226 | for (i = 1; i <= nregs; i++) | |
22227 | { | |
22228 | /* Expect (set (mem <addr>) (reg)). | |
22229 | Where <addr> is (reg:SP) or (plus (reg:SP) (const_int)). */ | |
22230 | e = XVECEXP (p, 0, i); | |
22231 | if (GET_CODE (e) != SET | |
22232 | || GET_CODE (XEXP (e, 0)) != MEM | |
22233 | || GET_CODE (XEXP (e, 1)) != REG) | |
22234 | abort (); | |
e0b92319 | 22235 | |
617a1b71 PB |
22236 | reg = REGNO (XEXP (e, 1)); |
22237 | if (reg < lastreg) | |
22238 | abort (); | |
e0b92319 | 22239 | |
617a1b71 PB |
22240 | if (i != 1) |
22241 | fprintf (asm_out_file, ", "); | |
22242 | /* We can't use %r for vfp because we need to use the | |
22243 | double precision register names. */ | |
22244 | if (IS_VFP_REGNUM (reg)) | |
22245 | asm_fprintf (asm_out_file, "d%d", (reg - FIRST_VFP_REGNUM) / 2); | |
22246 | else | |
22247 | asm_fprintf (asm_out_file, "%r", reg); | |
22248 | ||
22249 | #ifdef ENABLE_CHECKING | |
22250 | /* Check that the addresses are consecutive. */ | |
22251 | e = XEXP (XEXP (e, 0), 0); | |
22252 | if (GET_CODE (e) == PLUS) | |
22253 | { | |
22254 | offset += reg_size; | |
22255 | if (GET_CODE (XEXP (e, 0)) != REG | |
22256 | || REGNO (XEXP (e, 0)) != SP_REGNUM | |
22257 | || GET_CODE (XEXP (e, 1)) != CONST_INT | |
22258 | || offset != INTVAL (XEXP (e, 1))) | |
22259 | abort (); | |
22260 | } | |
22261 | else if (i != 1 | |
22262 | || GET_CODE (e) != REG | |
22263 | || REGNO (e) != SP_REGNUM) | |
22264 | abort (); | |
22265 | #endif | |
22266 | } | |
22267 | fprintf (asm_out_file, "}\n"); | |
22268 | } | |
22269 | ||
22270 | /* Emit unwind directives for a SET. */ | |
22271 | ||
22272 | static void | |
22273 | arm_unwind_emit_set (FILE * asm_out_file, rtx p) | |
22274 | { | |
22275 | rtx e0; | |
22276 | rtx e1; | |
5b3e6663 | 22277 | unsigned reg; |
617a1b71 PB |
22278 | |
22279 | e0 = XEXP (p, 0); | |
22280 | e1 = XEXP (p, 1); | |
22281 | switch (GET_CODE (e0)) | |
22282 | { | |
22283 | case MEM: | |
22284 | /* Pushing a single register. */ | |
22285 | if (GET_CODE (XEXP (e0, 0)) != PRE_DEC | |
22286 | || GET_CODE (XEXP (XEXP (e0, 0), 0)) != REG | |
22287 | || REGNO (XEXP (XEXP (e0, 0), 0)) != SP_REGNUM) | |
22288 | abort (); | |
22289 | ||
22290 | asm_fprintf (asm_out_file, "\t.save "); | |
22291 | if (IS_VFP_REGNUM (REGNO (e1))) | |
22292 | asm_fprintf(asm_out_file, "{d%d}\n", | |
22293 | (REGNO (e1) - FIRST_VFP_REGNUM) / 2); | |
22294 | else | |
22295 | asm_fprintf(asm_out_file, "{%r}\n", REGNO (e1)); | |
22296 | break; | |
22297 | ||
22298 | case REG: | |
22299 | if (REGNO (e0) == SP_REGNUM) | |
22300 | { | |
22301 | /* A stack increment. */ | |
22302 | if (GET_CODE (e1) != PLUS | |
22303 | || GET_CODE (XEXP (e1, 0)) != REG | |
22304 | || REGNO (XEXP (e1, 0)) != SP_REGNUM | |
22305 | || GET_CODE (XEXP (e1, 1)) != CONST_INT) | |
22306 | abort (); | |
22307 | ||
ea40ba9c | 22308 | asm_fprintf (asm_out_file, "\t.pad #%wd\n", |
617a1b71 PB |
22309 | -INTVAL (XEXP (e1, 1))); |
22310 | } | |
22311 | else if (REGNO (e0) == HARD_FRAME_POINTER_REGNUM) | |
22312 | { | |
22313 | HOST_WIDE_INT offset; | |
e0b92319 | 22314 | |
617a1b71 PB |
22315 | if (GET_CODE (e1) == PLUS) |
22316 | { | |
22317 | if (GET_CODE (XEXP (e1, 0)) != REG | |
22318 | || GET_CODE (XEXP (e1, 1)) != CONST_INT) | |
22319 | abort (); | |
22320 | reg = REGNO (XEXP (e1, 0)); | |
22321 | offset = INTVAL (XEXP (e1, 1)); | |
ea40ba9c | 22322 | asm_fprintf (asm_out_file, "\t.setfp %r, %r, #%wd\n", |
617a1b71 | 22323 | HARD_FRAME_POINTER_REGNUM, reg, |
80d56d04 | 22324 | offset); |
617a1b71 PB |
22325 | } |
22326 | else if (GET_CODE (e1) == REG) | |
22327 | { | |
22328 | reg = REGNO (e1); | |
22329 | asm_fprintf (asm_out_file, "\t.setfp %r, %r\n", | |
22330 | HARD_FRAME_POINTER_REGNUM, reg); | |
22331 | } | |
22332 | else | |
22333 | abort (); | |
22334 | } | |
22335 | else if (GET_CODE (e1) == REG && REGNO (e1) == SP_REGNUM) | |
22336 | { | |
22337 | /* Move from sp to reg. */ | |
22338 | asm_fprintf (asm_out_file, "\t.movsp %r\n", REGNO (e0)); | |
22339 | } | |
758ed9b2 PB |
22340 | else if (GET_CODE (e1) == PLUS |
22341 | && GET_CODE (XEXP (e1, 0)) == REG | |
22342 | && REGNO (XEXP (e1, 0)) == SP_REGNUM | |
22343 | && GET_CODE (XEXP (e1, 1)) == CONST_INT) | |
22344 | { | |
22345 | /* Set reg to offset from sp. */ | |
22346 | asm_fprintf (asm_out_file, "\t.movsp %r, #%d\n", | |
22347 | REGNO (e0), (int)INTVAL(XEXP (e1, 1))); | |
22348 | } | |
5b3e6663 PB |
22349 | else if (GET_CODE (e1) == UNSPEC && XINT (e1, 1) == UNSPEC_STACK_ALIGN) |
22350 | { | |
22351 | /* Stack pointer save before alignment. */ | |
22352 | reg = REGNO (e0); | |
22353 | asm_fprintf (asm_out_file, "\t.unwind_raw 0, 0x%x @ vsp = r%d\n", | |
22354 | reg + 0x90, reg); | |
22355 | } | |
617a1b71 PB |
22356 | else |
22357 | abort (); | |
22358 | break; | |
22359 | ||
22360 | default: | |
22361 | abort (); | |
22362 | } | |
22363 | } | |
22364 | ||
22365 | ||
22366 | /* Emit unwind directives for the given insn. */ | |
22367 | ||
22368 | static void | |
22369 | arm_unwind_emit (FILE * asm_out_file, rtx insn) | |
22370 | { | |
22371 | rtx pat; | |
22372 | ||
f0a0390e | 22373 | if (arm_except_unwind_info () != UI_TARGET) |
617a1b71 PB |
22374 | return; |
22375 | ||
e3b5732b | 22376 | if (!(flag_unwind_tables || crtl->uses_eh_lsda) |
80efdb6a | 22377 | && (TREE_NOTHROW (current_function_decl) |
ad516a74 | 22378 | || crtl->all_throwers_are_sibcalls)) |
80efdb6a PB |
22379 | return; |
22380 | ||
617a1b71 PB |
22381 | if (GET_CODE (insn) == NOTE || !RTX_FRAME_RELATED_P (insn)) |
22382 | return; | |
22383 | ||
22384 | pat = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); | |
22385 | if (pat) | |
22386 | pat = XEXP (pat, 0); | |
22387 | else | |
22388 | pat = PATTERN (insn); | |
22389 | ||
22390 | switch (GET_CODE (pat)) | |
22391 | { | |
22392 | case SET: | |
22393 | arm_unwind_emit_set (asm_out_file, pat); | |
22394 | break; | |
22395 | ||
22396 | case SEQUENCE: | |
22397 | /* Store multiple. */ | |
5b3e6663 | 22398 | arm_unwind_emit_sequence (asm_out_file, pat); |
617a1b71 PB |
22399 | break; |
22400 | ||
22401 | default: | |
22402 | abort(); | |
22403 | } | |
22404 | } | |
22405 | ||
22406 | ||
22407 | /* Output a reference from a function exception table to the type_info | |
22408 | object X. The EABI specifies that the symbol should be relocated by | |
22409 | an R_ARM_TARGET2 relocation. */ | |
22410 | ||
22411 | static bool | |
22412 | arm_output_ttype (rtx x) | |
22413 | { | |
22414 | fputs ("\t.word\t", asm_out_file); | |
22415 | output_addr_const (asm_out_file, x); | |
22416 | /* Use special relocations for symbol references. */ | |
22417 | if (GET_CODE (x) != CONST_INT) | |
22418 | fputs ("(TARGET2)", asm_out_file); | |
22419 | fputc ('\n', asm_out_file); | |
22420 | ||
22421 | return TRUE; | |
22422 | } | |
a68b5e52 RH |
22423 | |
22424 | /* Implement TARGET_ASM_EMIT_EXCEPT_PERSONALITY. */ | |
22425 | ||
22426 | static void | |
22427 | arm_asm_emit_except_personality (rtx personality) | |
22428 | { | |
22429 | fputs ("\t.personality\t", asm_out_file); | |
22430 | output_addr_const (asm_out_file, personality); | |
22431 | fputc ('\n', asm_out_file); | |
22432 | } | |
22433 | ||
22434 | /* Implement TARGET_ASM_INITIALIZE_SECTIONS. */ | |
22435 | ||
22436 | static void | |
22437 | arm_asm_init_sections (void) | |
22438 | { | |
22439 | exception_section = get_unnamed_section (0, output_section_asm_op, | |
22440 | "\t.handlerdata"); | |
22441 | } | |
f0a0390e RH |
22442 | #endif /* ARM_UNWIND_INFO */ |
22443 | ||
22444 | /* Implement TARGET_EXCEPT_UNWIND_INFO. */ | |
22445 | ||
22446 | static enum unwind_info_type | |
22447 | arm_except_unwind_info (void) | |
22448 | { | |
22449 | /* Honor the --enable-sjlj-exceptions configure switch. */ | |
22450 | #ifdef CONFIG_SJLJ_EXCEPTIONS | |
22451 | if (CONFIG_SJLJ_EXCEPTIONS) | |
22452 | return UI_SJLJ; | |
22453 | #endif | |
22454 | ||
22455 | /* If not using ARM EABI unwind tables... */ | |
22456 | if (ARM_UNWIND_INFO) | |
22457 | { | |
22458 | /* For simplicity elsewhere in this file, indicate that all unwind | |
22459 | info is disabled if we're not emitting unwind tables. */ | |
22460 | if (!flag_exceptions && !flag_unwind_tables) | |
22461 | return UI_NONE; | |
22462 | else | |
22463 | return UI_TARGET; | |
22464 | } | |
22465 | ||
22466 | /* ... we use sjlj exceptions for backwards compatibility. */ | |
22467 | return UI_SJLJ; | |
22468 | } | |
617a1b71 PB |
22469 | |
22470 | ||
5b3e6663 PB |
22471 | /* Handle UNSPEC DWARF call frame instructions. These are needed for dynamic |
22472 | stack alignment. */ | |
22473 | ||
22474 | static void | |
22475 | arm_dwarf_handle_frame_unspec (const char *label, rtx pattern, int index) | |
22476 | { | |
22477 | rtx unspec = SET_SRC (pattern); | |
22478 | gcc_assert (GET_CODE (unspec) == UNSPEC); | |
22479 | ||
22480 | switch (index) | |
22481 | { | |
22482 | case UNSPEC_STACK_ALIGN: | |
22483 | /* ??? We should set the CFA = (SP & ~7). At this point we haven't | |
22484 | put anything on the stack, so hopefully it won't matter. | |
22485 | CFA = SP will be correct after alignment. */ | |
22486 | dwarf2out_reg_save_reg (label, stack_pointer_rtx, | |
22487 | SET_DEST (pattern)); | |
22488 | break; | |
22489 | default: | |
22490 | gcc_unreachable (); | |
22491 | } | |
22492 | } | |
22493 | ||
22494 | ||
617a1b71 PB |
22495 | /* Output unwind directives for the start/end of a function. */ |
22496 | ||
22497 | void | |
22498 | arm_output_fn_unwind (FILE * f, bool prologue) | |
22499 | { | |
f0a0390e | 22500 | if (arm_except_unwind_info () != UI_TARGET) |
617a1b71 PB |
22501 | return; |
22502 | ||
22503 | if (prologue) | |
22504 | fputs ("\t.fnstart\n", f); | |
22505 | else | |
80efdb6a PB |
22506 | { |
22507 | /* If this function will never be unwound, then mark it as such. | |
22508 | The came condition is used in arm_unwind_emit to suppress | |
22509 | the frame annotations. */ | |
e3b5732b | 22510 | if (!(flag_unwind_tables || crtl->uses_eh_lsda) |
80efdb6a | 22511 | && (TREE_NOTHROW (current_function_decl) |
ad516a74 | 22512 | || crtl->all_throwers_are_sibcalls)) |
80efdb6a PB |
22513 | fputs("\t.cantunwind\n", f); |
22514 | ||
22515 | fputs ("\t.fnend\n", f); | |
22516 | } | |
617a1b71 | 22517 | } |
d3585b76 DJ |
22518 | |
22519 | static bool | |
22520 | arm_emit_tls_decoration (FILE *fp, rtx x) | |
22521 | { | |
22522 | enum tls_reloc reloc; | |
22523 | rtx val; | |
22524 | ||
22525 | val = XVECEXP (x, 0, 0); | |
32e8bb8e | 22526 | reloc = (enum tls_reloc) INTVAL (XVECEXP (x, 0, 1)); |
d3585b76 DJ |
22527 | |
22528 | output_addr_const (fp, val); | |
22529 | ||
22530 | switch (reloc) | |
22531 | { | |
22532 | case TLS_GD32: | |
22533 | fputs ("(tlsgd)", fp); | |
22534 | break; | |
22535 | case TLS_LDM32: | |
22536 | fputs ("(tlsldm)", fp); | |
22537 | break; | |
22538 | case TLS_LDO32: | |
22539 | fputs ("(tlsldo)", fp); | |
22540 | break; | |
22541 | case TLS_IE32: | |
22542 | fputs ("(gottpoff)", fp); | |
22543 | break; | |
22544 | case TLS_LE32: | |
22545 | fputs ("(tpoff)", fp); | |
22546 | break; | |
22547 | default: | |
22548 | gcc_unreachable (); | |
22549 | } | |
22550 | ||
22551 | switch (reloc) | |
22552 | { | |
22553 | case TLS_GD32: | |
22554 | case TLS_LDM32: | |
22555 | case TLS_IE32: | |
22556 | fputs (" + (. - ", fp); | |
22557 | output_addr_const (fp, XVECEXP (x, 0, 2)); | |
22558 | fputs (" - ", fp); | |
22559 | output_addr_const (fp, XVECEXP (x, 0, 3)); | |
22560 | fputc (')', fp); | |
22561 | break; | |
22562 | default: | |
22563 | break; | |
22564 | } | |
22565 | ||
22566 | return TRUE; | |
22567 | } | |
22568 | ||
afcc986d JM |
22569 | /* ARM implementation of TARGET_ASM_OUTPUT_DWARF_DTPREL. */ |
22570 | ||
22571 | static void | |
22572 | arm_output_dwarf_dtprel (FILE *file, int size, rtx x) | |
22573 | { | |
22574 | gcc_assert (size == 4); | |
22575 | fputs ("\t.word\t", file); | |
22576 | output_addr_const (file, x); | |
22577 | fputs ("(tlsldo)", file); | |
22578 | } | |
22579 | ||
ffda8a0d AS |
22580 | /* Implement TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA. */ |
22581 | ||
22582 | static bool | |
d3585b76 DJ |
22583 | arm_output_addr_const_extra (FILE *fp, rtx x) |
22584 | { | |
22585 | if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS) | |
22586 | return arm_emit_tls_decoration (fp, x); | |
f16fe45f DJ |
22587 | else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_PIC_LABEL) |
22588 | { | |
22589 | char label[256]; | |
22590 | int labelno = INTVAL (XVECEXP (x, 0, 0)); | |
22591 | ||
22592 | ASM_GENERATE_INTERNAL_LABEL (label, "LPIC", labelno); | |
22593 | assemble_name_raw (fp, label); | |
22594 | ||
f9bd1a89 RS |
22595 | return TRUE; |
22596 | } | |
22597 | else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_GOTSYM_OFF) | |
22598 | { | |
22599 | assemble_name (fp, "_GLOBAL_OFFSET_TABLE_"); | |
22600 | if (GOT_PCREL) | |
22601 | fputs ("+.", fp); | |
22602 | fputs ("-(", fp); | |
22603 | output_addr_const (fp, XVECEXP (x, 0, 0)); | |
22604 | fputc (')', fp); | |
f16fe45f DJ |
22605 | return TRUE; |
22606 | } | |
85c9bcd4 WG |
22607 | else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SYMBOL_OFFSET) |
22608 | { | |
22609 | output_addr_const (fp, XVECEXP (x, 0, 0)); | |
22610 | if (GOT_PCREL) | |
22611 | fputs ("+.", fp); | |
22612 | fputs ("-(", fp); | |
22613 | output_addr_const (fp, XVECEXP (x, 0, 1)); | |
22614 | fputc (')', fp); | |
22615 | return TRUE; | |
22616 | } | |
d3585b76 DJ |
22617 | else if (GET_CODE (x) == CONST_VECTOR) |
22618 | return arm_emit_vector_const (fp, x); | |
22619 | ||
22620 | return FALSE; | |
22621 | } | |
22622 | ||
5b3e6663 PB |
22623 | /* Output assembly for a shift instruction. |
22624 | SET_FLAGS determines how the instruction modifies the condition codes. | |
7a085dce | 22625 | 0 - Do not set condition codes. |
5b3e6663 PB |
22626 | 1 - Set condition codes. |
22627 | 2 - Use smallest instruction. */ | |
22628 | const char * | |
22629 | arm_output_shift(rtx * operands, int set_flags) | |
22630 | { | |
22631 | char pattern[100]; | |
22632 | static const char flag_chars[3] = {'?', '.', '!'}; | |
22633 | const char *shift; | |
22634 | HOST_WIDE_INT val; | |
22635 | char c; | |
22636 | ||
22637 | c = flag_chars[set_flags]; | |
22638 | if (TARGET_UNIFIED_ASM) | |
22639 | { | |
22640 | shift = shift_op(operands[3], &val); | |
22641 | if (shift) | |
22642 | { | |
22643 | if (val != -1) | |
22644 | operands[2] = GEN_INT(val); | |
22645 | sprintf (pattern, "%s%%%c\t%%0, %%1, %%2", shift, c); | |
22646 | } | |
22647 | else | |
22648 | sprintf (pattern, "mov%%%c\t%%0, %%1", c); | |
22649 | } | |
22650 | else | |
22651 | sprintf (pattern, "mov%%%c\t%%0, %%1%%S3", c); | |
22652 | output_asm_insn (pattern, operands); | |
22653 | return ""; | |
22654 | } | |
22655 | ||
907dd0c7 RE |
22656 | /* Output a Thumb-1 casesi dispatch sequence. */ |
22657 | const char * | |
22658 | thumb1_output_casesi (rtx *operands) | |
22659 | { | |
22660 | rtx diff_vec = PATTERN (next_real_insn (operands[0])); | |
907dd0c7 RE |
22661 | |
22662 | gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC); | |
22663 | ||
907dd0c7 RE |
22664 | switch (GET_MODE(diff_vec)) |
22665 | { | |
22666 | case QImode: | |
22667 | return (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned ? | |
22668 | "bl\t%___gnu_thumb1_case_uqi" : "bl\t%___gnu_thumb1_case_sqi"); | |
22669 | case HImode: | |
22670 | return (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned ? | |
22671 | "bl\t%___gnu_thumb1_case_uhi" : "bl\t%___gnu_thumb1_case_shi"); | |
22672 | case SImode: | |
22673 | return "bl\t%___gnu_thumb1_case_si"; | |
22674 | default: | |
22675 | gcc_unreachable (); | |
22676 | } | |
22677 | } | |
22678 | ||
5b3e6663 PB |
22679 | /* Output a Thumb-2 casesi instruction. */ |
22680 | const char * | |
22681 | thumb2_output_casesi (rtx *operands) | |
22682 | { | |
22683 | rtx diff_vec = PATTERN (next_real_insn (operands[2])); | |
22684 | ||
22685 | gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC); | |
22686 | ||
22687 | output_asm_insn ("cmp\t%0, %1", operands); | |
22688 | output_asm_insn ("bhi\t%l3", operands); | |
22689 | switch (GET_MODE(diff_vec)) | |
22690 | { | |
22691 | case QImode: | |
22692 | return "tbb\t[%|pc, %0]"; | |
22693 | case HImode: | |
22694 | return "tbh\t[%|pc, %0, lsl #1]"; | |
22695 | case SImode: | |
22696 | if (flag_pic) | |
22697 | { | |
22698 | output_asm_insn ("adr\t%4, %l2", operands); | |
22699 | output_asm_insn ("ldr\t%5, [%4, %0, lsl #2]", operands); | |
22700 | output_asm_insn ("add\t%4, %4, %5", operands); | |
22701 | return "bx\t%4"; | |
22702 | } | |
22703 | else | |
22704 | { | |
22705 | output_asm_insn ("adr\t%4, %l2", operands); | |
22706 | return "ldr\t%|pc, [%4, %0, lsl #2]"; | |
22707 | } | |
22708 | default: | |
22709 | gcc_unreachable (); | |
22710 | } | |
22711 | } | |
22712 | ||
bd4dc3cd PB |
22713 | /* Most ARM cores are single issue, but some newer ones can dual issue. |
22714 | The scheduler descriptions rely on this being correct. */ | |
22715 | static int | |
22716 | arm_issue_rate (void) | |
22717 | { | |
22718 | switch (arm_tune) | |
22719 | { | |
22720 | case cortexr4: | |
51c69ddb | 22721 | case cortexr4f: |
d8099dd8 | 22722 | case cortexa5: |
bd4dc3cd | 22723 | case cortexa8: |
7612f14d | 22724 | case cortexa9: |
bd4dc3cd PB |
22725 | return 2; |
22726 | ||
22727 | default: | |
22728 | return 1; | |
22729 | } | |
22730 | } | |
22731 | ||
608063c3 JB |
22732 | /* A table and a function to perform ARM-specific name mangling for |
22733 | NEON vector types in order to conform to the AAPCS (see "Procedure | |
22734 | Call Standard for the ARM Architecture", Appendix A). To qualify | |
22735 | for emission with the mangled names defined in that document, a | |
22736 | vector type must not only be of the correct mode but also be | |
22737 | composed of NEON vector element types (e.g. __builtin_neon_qi). */ | |
22738 | typedef struct | |
22739 | { | |
22740 | enum machine_mode mode; | |
22741 | const char *element_type_name; | |
22742 | const char *aapcs_name; | |
22743 | } arm_mangle_map_entry; | |
22744 | ||
22745 | static arm_mangle_map_entry arm_mangle_map[] = { | |
22746 | /* 64-bit containerized types. */ | |
22747 | { V8QImode, "__builtin_neon_qi", "15__simd64_int8_t" }, | |
22748 | { V8QImode, "__builtin_neon_uqi", "16__simd64_uint8_t" }, | |
22749 | { V4HImode, "__builtin_neon_hi", "16__simd64_int16_t" }, | |
22750 | { V4HImode, "__builtin_neon_uhi", "17__simd64_uint16_t" }, | |
22751 | { V2SImode, "__builtin_neon_si", "16__simd64_int32_t" }, | |
22752 | { V2SImode, "__builtin_neon_usi", "17__simd64_uint32_t" }, | |
22753 | { V2SFmode, "__builtin_neon_sf", "18__simd64_float32_t" }, | |
22754 | { V8QImode, "__builtin_neon_poly8", "16__simd64_poly8_t" }, | |
22755 | { V4HImode, "__builtin_neon_poly16", "17__simd64_poly16_t" }, | |
22756 | /* 128-bit containerized types. */ | |
22757 | { V16QImode, "__builtin_neon_qi", "16__simd128_int8_t" }, | |
22758 | { V16QImode, "__builtin_neon_uqi", "17__simd128_uint8_t" }, | |
22759 | { V8HImode, "__builtin_neon_hi", "17__simd128_int16_t" }, | |
22760 | { V8HImode, "__builtin_neon_uhi", "18__simd128_uint16_t" }, | |
22761 | { V4SImode, "__builtin_neon_si", "17__simd128_int32_t" }, | |
22762 | { V4SImode, "__builtin_neon_usi", "18__simd128_uint32_t" }, | |
22763 | { V4SFmode, "__builtin_neon_sf", "19__simd128_float32_t" }, | |
22764 | { V16QImode, "__builtin_neon_poly8", "17__simd128_poly8_t" }, | |
22765 | { V8HImode, "__builtin_neon_poly16", "18__simd128_poly16_t" }, | |
22766 | { VOIDmode, NULL, NULL } | |
22767 | }; | |
22768 | ||
22769 | const char * | |
3101faab | 22770 | arm_mangle_type (const_tree type) |
608063c3 JB |
22771 | { |
22772 | arm_mangle_map_entry *pos = arm_mangle_map; | |
22773 | ||
07d8efe3 MM |
22774 | /* The ARM ABI documents (10th October 2008) say that "__va_list" |
22775 | has to be managled as if it is in the "std" namespace. */ | |
22776 | if (TARGET_AAPCS_BASED | |
ae46a823 | 22777 | && lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type)) |
07d8efe3 MM |
22778 | { |
22779 | static bool warned; | |
d147cbd9 | 22780 | if (!warned && warn_psabi && !in_system_header) |
07d8efe3 MM |
22781 | { |
22782 | warned = true; | |
22783 | inform (input_location, | |
22784 | "the mangling of %<va_list%> has changed in GCC 4.4"); | |
22785 | } | |
22786 | return "St9__va_list"; | |
22787 | } | |
22788 | ||
0fd8c3ad SL |
22789 | /* Half-precision float. */ |
22790 | if (TREE_CODE (type) == REAL_TYPE && TYPE_PRECISION (type) == 16) | |
22791 | return "Dh"; | |
22792 | ||
608063c3 JB |
22793 | if (TREE_CODE (type) != VECTOR_TYPE) |
22794 | return NULL; | |
22795 | ||
22796 | /* Check the mode of the vector type, and the name of the vector | |
22797 | element type, against the table. */ | |
22798 | while (pos->mode != VOIDmode) | |
22799 | { | |
22800 | tree elt_type = TREE_TYPE (type); | |
22801 | ||
22802 | if (pos->mode == TYPE_MODE (type) | |
22803 | && TREE_CODE (TYPE_NAME (elt_type)) == TYPE_DECL | |
22804 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (elt_type))), | |
22805 | pos->element_type_name)) | |
22806 | return pos->aapcs_name; | |
22807 | ||
22808 | pos++; | |
22809 | } | |
22810 | ||
22811 | /* Use the default mangling for unrecognized (possibly user-defined) | |
22812 | vector types. */ | |
22813 | return NULL; | |
22814 | } | |
22815 | ||
795dc4fc PB |
22816 | /* Order of allocation of core registers for Thumb: this allocation is |
22817 | written over the corresponding initial entries of the array | |
22818 | initialized with REG_ALLOC_ORDER. We allocate all low registers | |
22819 | first. Saving and restoring a low register is usually cheaper than | |
22820 | using a call-clobbered high register. */ | |
22821 | ||
22822 | static const int thumb_core_reg_alloc_order[] = | |
22823 | { | |
22824 | 3, 2, 1, 0, 4, 5, 6, 7, | |
22825 | 14, 12, 8, 9, 10, 11, 13, 15 | |
22826 | }; | |
22827 | ||
22828 | /* Adjust register allocation order when compiling for Thumb. */ | |
22829 | ||
22830 | void | |
22831 | arm_order_regs_for_local_alloc (void) | |
22832 | { | |
22833 | const int arm_reg_alloc_order[] = REG_ALLOC_ORDER; | |
22834 | memcpy(reg_alloc_order, arm_reg_alloc_order, sizeof (reg_alloc_order)); | |
22835 | if (TARGET_THUMB) | |
22836 | memcpy (reg_alloc_order, thumb_core_reg_alloc_order, | |
22837 | sizeof (thumb_core_reg_alloc_order)); | |
22838 | } | |
22839 | ||
b52b1749 AS |
22840 | /* Implement TARGET_FRAME_POINTER_REQUIRED. */ |
22841 | ||
22842 | bool | |
22843 | arm_frame_pointer_required (void) | |
22844 | { | |
22845 | return (cfun->has_nonlocal_label | |
22846 | || SUBTARGET_FRAME_POINTER_REQUIRED | |
22847 | || (TARGET_ARM && TARGET_APCS_FRAME && ! leaf_function_p ())); | |
22848 | } | |
22849 | ||
2929029c WG |
22850 | /* Only thumb1 can't support conditional execution, so return true if |
22851 | the target is not thumb1. */ | |
22852 | static bool | |
22853 | arm_have_conditional_execution (void) | |
22854 | { | |
22855 | return !TARGET_THUMB1; | |
22856 | } | |
22857 | ||
029e79eb MS |
22858 | /* Legitimize a memory reference for sync primitive implemented using |
22859 | ldrex / strex. We currently force the form of the reference to be | |
22860 | indirect without offset. We do not yet support the indirect offset | |
22861 | addressing supported by some ARM targets for these | |
22862 | instructions. */ | |
22863 | static rtx | |
22864 | arm_legitimize_sync_memory (rtx memory) | |
22865 | { | |
22866 | rtx addr = force_reg (Pmode, XEXP (memory, 0)); | |
22867 | rtx legitimate_memory = gen_rtx_MEM (GET_MODE (memory), addr); | |
22868 | ||
22869 | set_mem_alias_set (legitimate_memory, ALIAS_SET_MEMORY_BARRIER); | |
22870 | MEM_VOLATILE_P (legitimate_memory) = MEM_VOLATILE_P (memory); | |
22871 | return legitimate_memory; | |
22872 | } | |
22873 | ||
22874 | /* An instruction emitter. */ | |
22875 | typedef void (* emit_f) (int label, const char *, rtx *); | |
22876 | ||
22877 | /* An instruction emitter that emits via the conventional | |
22878 | output_asm_insn. */ | |
22879 | static void | |
22880 | arm_emit (int label ATTRIBUTE_UNUSED, const char *pattern, rtx *operands) | |
22881 | { | |
22882 | output_asm_insn (pattern, operands); | |
22883 | } | |
22884 | ||
22885 | /* Count the number of emitted synchronization instructions. */ | |
22886 | static unsigned arm_insn_count; | |
22887 | ||
22888 | /* An emitter that counts emitted instructions but does not actually | |
22889 | emit instruction into the the instruction stream. */ | |
22890 | static void | |
22891 | arm_count (int label, | |
22892 | const char *pattern ATTRIBUTE_UNUSED, | |
22893 | rtx *operands ATTRIBUTE_UNUSED) | |
22894 | { | |
22895 | if (! label) | |
22896 | ++ arm_insn_count; | |
22897 | } | |
22898 | ||
22899 | /* Construct a pattern using conventional output formatting and feed | |
22900 | it to output_asm_insn. Provides a mechanism to construct the | |
22901 | output pattern on the fly. Note the hard limit on the pattern | |
22902 | buffer size. */ | |
22903 | static void | |
22904 | arm_output_asm_insn (emit_f emit, int label, rtx *operands, | |
22905 | const char *pattern, ...) | |
22906 | { | |
22907 | va_list ap; | |
22908 | char buffer[256]; | |
22909 | ||
22910 | va_start (ap, pattern); | |
22911 | vsprintf (buffer, pattern, ap); | |
22912 | va_end (ap); | |
22913 | emit (label, buffer, operands); | |
22914 | } | |
22915 | ||
22916 | /* Emit the memory barrier instruction, if any, provided by this | |
22917 | target to a specified emitter. */ | |
22918 | static void | |
22919 | arm_process_output_memory_barrier (emit_f emit, rtx *operands) | |
22920 | { | |
22921 | if (TARGET_HAVE_DMB) | |
22922 | { | |
22923 | /* Note we issue a system level barrier. We should consider | |
22924 | issuing a inner shareabilty zone barrier here instead, ie. | |
22925 | "DMB ISH". */ | |
22926 | emit (0, "dmb\tsy", operands); | |
22927 | return; | |
22928 | } | |
22929 | ||
22930 | if (TARGET_HAVE_DMB_MCR) | |
22931 | { | |
22932 | emit (0, "mcr\tp15, 0, r0, c7, c10, 5", operands); | |
22933 | return; | |
22934 | } | |
22935 | ||
22936 | gcc_unreachable (); | |
22937 | } | |
22938 | ||
22939 | /* Emit the memory barrier instruction, if any, provided by this | |
22940 | target. */ | |
22941 | const char * | |
22942 | arm_output_memory_barrier (rtx *operands) | |
22943 | { | |
22944 | arm_process_output_memory_barrier (arm_emit, operands); | |
22945 | return ""; | |
22946 | } | |
22947 | ||
22948 | /* Helper to figure out the instruction suffix required on ldrex/strex | |
22949 | for operations on an object of the specified mode. */ | |
22950 | static const char * | |
22951 | arm_ldrex_suffix (enum machine_mode mode) | |
22952 | { | |
22953 | switch (mode) | |
22954 | { | |
22955 | case QImode: return "b"; | |
22956 | case HImode: return "h"; | |
22957 | case SImode: return ""; | |
22958 | case DImode: return "d"; | |
22959 | default: | |
22960 | gcc_unreachable (); | |
22961 | } | |
22962 | return ""; | |
22963 | } | |
22964 | ||
22965 | /* Emit an ldrex{b,h,d, } instruction appropriate for the specified | |
22966 | mode. */ | |
22967 | static void | |
22968 | arm_output_ldrex (emit_f emit, | |
22969 | enum machine_mode mode, | |
22970 | rtx target, | |
22971 | rtx memory) | |
22972 | { | |
22973 | const char *suffix = arm_ldrex_suffix (mode); | |
22974 | rtx operands[2]; | |
22975 | ||
22976 | operands[0] = target; | |
22977 | operands[1] = memory; | |
22978 | arm_output_asm_insn (emit, 0, operands, "ldrex%s\t%%0, %%C1", suffix); | |
22979 | } | |
22980 | ||
22981 | /* Emit a strex{b,h,d, } instruction appropriate for the specified | |
22982 | mode. */ | |
22983 | static void | |
22984 | arm_output_strex (emit_f emit, | |
22985 | enum machine_mode mode, | |
22986 | const char *cc, | |
22987 | rtx result, | |
22988 | rtx value, | |
22989 | rtx memory) | |
22990 | { | |
22991 | const char *suffix = arm_ldrex_suffix (mode); | |
22992 | rtx operands[3]; | |
22993 | ||
22994 | operands[0] = result; | |
22995 | operands[1] = value; | |
22996 | operands[2] = memory; | |
22997 | arm_output_asm_insn (emit, 0, operands, "strex%s%s\t%%0, %%1, %%C2", suffix, | |
22998 | cc); | |
22999 | } | |
23000 | ||
23001 | /* Helper to emit a two operand instruction. */ | |
23002 | static void | |
23003 | arm_output_op2 (emit_f emit, const char *mnemonic, rtx d, rtx s) | |
23004 | { | |
23005 | rtx operands[2]; | |
23006 | ||
23007 | operands[0] = d; | |
23008 | operands[1] = s; | |
23009 | arm_output_asm_insn (emit, 0, operands, "%s\t%%0, %%1", mnemonic); | |
23010 | } | |
23011 | ||
23012 | /* Helper to emit a three operand instruction. */ | |
23013 | static void | |
23014 | arm_output_op3 (emit_f emit, const char *mnemonic, rtx d, rtx a, rtx b) | |
23015 | { | |
23016 | rtx operands[3]; | |
23017 | ||
23018 | operands[0] = d; | |
23019 | operands[1] = a; | |
23020 | operands[2] = b; | |
23021 | arm_output_asm_insn (emit, 0, operands, "%s\t%%0, %%1, %%2", mnemonic); | |
23022 | } | |
23023 | ||
23024 | /* Emit a load store exclusive synchronization loop. | |
23025 | ||
23026 | do | |
23027 | old_value = [mem] | |
23028 | if old_value != required_value | |
23029 | break; | |
23030 | t1 = sync_op (old_value, new_value) | |
23031 | [mem] = t1, t2 = [0|1] | |
23032 | while ! t2 | |
23033 | ||
23034 | Note: | |
23035 | t1 == t2 is not permitted | |
23036 | t1 == old_value is permitted | |
23037 | ||
23038 | required_value: | |
23039 | ||
23040 | RTX register or const_int representing the required old_value for | |
23041 | the modify to continue, if NULL no comparsion is performed. */ | |
23042 | static void | |
23043 | arm_output_sync_loop (emit_f emit, | |
23044 | enum machine_mode mode, | |
23045 | rtx old_value, | |
23046 | rtx memory, | |
23047 | rtx required_value, | |
23048 | rtx new_value, | |
23049 | rtx t1, | |
23050 | rtx t2, | |
23051 | enum attr_sync_op sync_op, | |
23052 | int early_barrier_required) | |
23053 | { | |
23054 | rtx operands[1]; | |
23055 | ||
23056 | gcc_assert (t1 != t2); | |
23057 | ||
23058 | if (early_barrier_required) | |
23059 | arm_process_output_memory_barrier (emit, NULL); | |
23060 | ||
23061 | arm_output_asm_insn (emit, 1, operands, "%sLSYT%%=:", LOCAL_LABEL_PREFIX); | |
23062 | ||
23063 | arm_output_ldrex (emit, mode, old_value, memory); | |
23064 | ||
23065 | if (required_value) | |
23066 | { | |
23067 | rtx operands[2]; | |
23068 | ||
23069 | operands[0] = old_value; | |
23070 | operands[1] = required_value; | |
23071 | arm_output_asm_insn (emit, 0, operands, "cmp\t%%0, %%1"); | |
23072 | arm_output_asm_insn (emit, 0, operands, "bne\t%sLSYB%%=", LOCAL_LABEL_PREFIX); | |
23073 | } | |
23074 | ||
23075 | switch (sync_op) | |
23076 | { | |
23077 | case SYNC_OP_ADD: | |
23078 | arm_output_op3 (emit, "add", t1, old_value, new_value); | |
23079 | break; | |
23080 | ||
23081 | case SYNC_OP_SUB: | |
23082 | arm_output_op3 (emit, "sub", t1, old_value, new_value); | |
23083 | break; | |
23084 | ||
23085 | case SYNC_OP_IOR: | |
23086 | arm_output_op3 (emit, "orr", t1, old_value, new_value); | |
23087 | break; | |
23088 | ||
23089 | case SYNC_OP_XOR: | |
23090 | arm_output_op3 (emit, "eor", t1, old_value, new_value); | |
23091 | break; | |
23092 | ||
23093 | case SYNC_OP_AND: | |
23094 | arm_output_op3 (emit,"and", t1, old_value, new_value); | |
23095 | break; | |
23096 | ||
23097 | case SYNC_OP_NAND: | |
23098 | arm_output_op3 (emit, "and", t1, old_value, new_value); | |
23099 | arm_output_op2 (emit, "mvn", t1, t1); | |
23100 | break; | |
23101 | ||
23102 | case SYNC_OP_NONE: | |
23103 | t1 = new_value; | |
23104 | break; | |
23105 | } | |
23106 | ||
23107 | arm_output_strex (emit, mode, "", t2, t1, memory); | |
23108 | operands[0] = t2; | |
23109 | arm_output_asm_insn (emit, 0, operands, "teq\t%%0, #0"); | |
23110 | arm_output_asm_insn (emit, 0, operands, "bne\t%sLSYT%%=", LOCAL_LABEL_PREFIX); | |
23111 | ||
23112 | arm_process_output_memory_barrier (emit, NULL); | |
23113 | arm_output_asm_insn (emit, 1, operands, "%sLSYB%%=:", LOCAL_LABEL_PREFIX); | |
23114 | } | |
23115 | ||
23116 | static rtx | |
23117 | arm_get_sync_operand (rtx *operands, int index, rtx default_value) | |
23118 | { | |
23119 | if (index > 0) | |
23120 | default_value = operands[index - 1]; | |
23121 | ||
23122 | return default_value; | |
23123 | } | |
23124 | ||
23125 | #define FETCH_SYNC_OPERAND(NAME, DEFAULT) \ | |
23126 | arm_get_sync_operand (operands, (int) get_attr_sync_##NAME (insn), DEFAULT); | |
23127 | ||
23128 | /* Extract the operands for a synchroniztion instruction from the | |
23129 | instructions attributes and emit the instruction. */ | |
23130 | static void | |
23131 | arm_process_output_sync_insn (emit_f emit, rtx insn, rtx *operands) | |
23132 | { | |
23133 | rtx result, memory, required_value, new_value, t1, t2; | |
23134 | int early_barrier; | |
23135 | enum machine_mode mode; | |
23136 | enum attr_sync_op sync_op; | |
23137 | ||
23138 | result = FETCH_SYNC_OPERAND(result, 0); | |
23139 | memory = FETCH_SYNC_OPERAND(memory, 0); | |
23140 | required_value = FETCH_SYNC_OPERAND(required_value, 0); | |
23141 | new_value = FETCH_SYNC_OPERAND(new_value, 0); | |
23142 | t1 = FETCH_SYNC_OPERAND(t1, 0); | |
23143 | t2 = FETCH_SYNC_OPERAND(t2, 0); | |
23144 | early_barrier = | |
23145 | get_attr_sync_release_barrier (insn) == SYNC_RELEASE_BARRIER_YES; | |
23146 | sync_op = get_attr_sync_op (insn); | |
23147 | mode = GET_MODE (memory); | |
23148 | ||
23149 | arm_output_sync_loop (emit, mode, result, memory, required_value, | |
23150 | new_value, t1, t2, sync_op, early_barrier); | |
23151 | } | |
23152 | ||
23153 | /* Emit a synchronization instruction loop. */ | |
23154 | const char * | |
23155 | arm_output_sync_insn (rtx insn, rtx *operands) | |
23156 | { | |
23157 | arm_process_output_sync_insn (arm_emit, insn, operands); | |
23158 | return ""; | |
23159 | } | |
23160 | ||
23161 | /* Count the number of machine instruction that will be emitted for a | |
23162 | synchronization instruction. Note that the emitter used does not | |
23163 | emit instructions, it just counts instructions being carefull not | |
23164 | to count labels. */ | |
23165 | unsigned int | |
23166 | arm_sync_loop_insns (rtx insn, rtx *operands) | |
23167 | { | |
23168 | arm_insn_count = 0; | |
23169 | arm_process_output_sync_insn (arm_count, insn, operands); | |
23170 | return arm_insn_count; | |
23171 | } | |
23172 | ||
23173 | /* Helper to call a target sync instruction generator, dealing with | |
23174 | the variation in operands required by the different generators. */ | |
23175 | static rtx | |
23176 | arm_call_generator (struct arm_sync_generator *generator, rtx old_value, | |
23177 | rtx memory, rtx required_value, rtx new_value) | |
23178 | { | |
23179 | switch (generator->op) | |
23180 | { | |
23181 | case arm_sync_generator_omn: | |
23182 | gcc_assert (! required_value); | |
23183 | return generator->u.omn (old_value, memory, new_value); | |
23184 | ||
23185 | case arm_sync_generator_omrn: | |
23186 | gcc_assert (required_value); | |
23187 | return generator->u.omrn (old_value, memory, required_value, new_value); | |
23188 | } | |
23189 | ||
23190 | return NULL; | |
23191 | } | |
23192 | ||
23193 | /* Expand a synchronization loop. The synchronization loop is expanded | |
23194 | as an opaque block of instructions in order to ensure that we do | |
23195 | not subsequently get extraneous memory accesses inserted within the | |
23196 | critical region. The exclusive access property of ldrex/strex is | |
23197 | only guaranteed in there are no intervening memory accesses. */ | |
23198 | void | |
23199 | arm_expand_sync (enum machine_mode mode, | |
23200 | struct arm_sync_generator *generator, | |
23201 | rtx target, rtx memory, rtx required_value, rtx new_value) | |
23202 | { | |
23203 | if (target == NULL) | |
23204 | target = gen_reg_rtx (mode); | |
23205 | ||
23206 | memory = arm_legitimize_sync_memory (memory); | |
23207 | if (mode != SImode) | |
23208 | { | |
23209 | rtx load_temp = gen_reg_rtx (SImode); | |
23210 | ||
23211 | if (required_value) | |
23212 | required_value = convert_modes (SImode, mode, required_value, true); | |
23213 | ||
23214 | new_value = convert_modes (SImode, mode, new_value, true); | |
23215 | emit_insn (arm_call_generator (generator, load_temp, memory, | |
23216 | required_value, new_value)); | |
23217 | emit_move_insn (target, gen_lowpart (mode, load_temp)); | |
23218 | } | |
23219 | else | |
23220 | { | |
23221 | emit_insn (arm_call_generator (generator, target, memory, required_value, | |
23222 | new_value)); | |
23223 | } | |
23224 | } | |
23225 | ||
c452684d JB |
23226 | static bool |
23227 | arm_vector_alignment_reachable (const_tree type, bool is_packed) | |
23228 | { | |
23229 | /* Vectors which aren't in packed structures will not be less aligned than | |
23230 | the natural alignment of their element type, so this is safe. */ | |
23231 | if (TARGET_NEON && !BYTES_BIG_ENDIAN) | |
23232 | return !is_packed; | |
23233 | ||
23234 | return default_builtin_vector_alignment_reachable (type, is_packed); | |
23235 | } | |
23236 | ||
23237 | static bool | |
23238 | arm_builtin_support_vector_misalignment (enum machine_mode mode, | |
23239 | const_tree type, int misalignment, | |
23240 | bool is_packed) | |
23241 | { | |
23242 | if (TARGET_NEON && !BYTES_BIG_ENDIAN) | |
23243 | { | |
23244 | HOST_WIDE_INT align = TYPE_ALIGN_UNIT (type); | |
23245 | ||
23246 | if (is_packed) | |
23247 | return align == 1; | |
23248 | ||
23249 | /* If the misalignment is unknown, we should be able to handle the access | |
23250 | so long as it is not to a member of a packed data structure. */ | |
23251 | if (misalignment == -1) | |
23252 | return true; | |
23253 | ||
23254 | /* Return true if the misalignment is a multiple of the natural alignment | |
23255 | of the vector's element type. This is probably always going to be | |
23256 | true in practice, since we've already established that this isn't a | |
23257 | packed access. */ | |
23258 | return ((misalignment % align) == 0); | |
23259 | } | |
23260 | ||
23261 | return default_builtin_support_vector_misalignment (mode, type, misalignment, | |
23262 | is_packed); | |
23263 | } | |
23264 | ||
d3585b76 | 23265 | #include "gt-arm.h" |