| 1 |
/* Output routines for GCC for ARM. |
| 2 |
Copyright (C) 1991-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Pieter `Tiggr' Schoenmakers ([email protected]) |
| 4 |
and Martin Simmons (@harleqn.co.uk). |
| 5 |
More major hacks by Richard Earnshaw ([email protected]). |
| 6 |
|
| 7 |
This file is part of GCC. |
| 8 |
|
| 9 |
GCC is free software; you can redistribute it and/or modify it |
| 10 |
under the terms of the GNU General Public License as published |
| 11 |
by the Free Software Foundation; either version 3, or (at your |
| 12 |
option) any later version. |
| 13 |
|
| 14 |
GCC is distributed in the hope that it will be useful, but WITHOUT |
| 15 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 16 |
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 17 |
License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License |
| 20 |
along with GCC; see the file COPYING3. If not see |
| 21 |
<http://www.gnu.org/licenses/>. */ |
| 22 |
|
| 23 |
#define IN_TARGET_CODE 1 |
| 24 |
|
| 25 |
#include "config.h" |
| 26 |
#define INCLUDE_STRING |
| 27 |
#include "system.h" |
| 28 |
#include "coretypes.h" |
| 29 |
#include "backend.h" |
| 30 |
#include "target.h" |
| 31 |
#include "rtl.h" |
| 32 |
#include "tree.h" |
| 33 |
#include "memmodel.h" |
| 34 |
#include "cfghooks.h" |
| 35 |
#include "cfgloop.h" |
| 36 |
#include "df.h" |
| 37 |
#include "tm_p.h" |
| 38 |
#include "stringpool.h" |
| 39 |
#include "attribs.h" |
| 40 |
#include "optabs.h" |
| 41 |
#include "regs.h" |
| 42 |
#include "emit-rtl.h" |
| 43 |
#include "recog.h" |
| 44 |
#include "cgraph.h" |
| 45 |
#include "diagnostic-core.h" |
| 46 |
#include "alias.h" |
| 47 |
#include "fold-const.h" |
| 48 |
#include "stor-layout.h" |
| 49 |
#include "calls.h" |
| 50 |
#include "varasm.h" |
| 51 |
#include "output.h" |
| 52 |
#include "insn-attr.h" |
| 53 |
#include "flags.h" |
| 54 |
#include "reload.h" |
| 55 |
#include "explow.h" |
| 56 |
#include "expr.h" |
| 57 |
#include "cfgrtl.h" |
| 58 |
#include "sched-int.h" |
| 59 |
#include "common/common-target.h" |
| 60 |
#include "langhooks.h" |
| 61 |
#include "intl.h" |
| 62 |
#include "libfuncs.h" |
| 63 |
#include "opts.h" |
| 64 |
#include "dumpfile.h" |
| 65 |
#include "target-globals.h" |
| 66 |
#include "builtins.h" |
| 67 |
#include "tm-constrs.h" |
| 68 |
#include "rtl-iter.h" |
| 69 |
#include "optabs-libfuncs.h" |
| 70 |
#include "gimplify.h" |
| 71 |
#include "gimple.h" |
| 72 |
#include "gimple-iterator.h" |
| 73 |
#include "selftest.h" |
| 74 |
#include "tree-vectorizer.h" |
| 75 |
#include "opts.h" |
| 76 |
#include "aarch-common.h" |
| 77 |
#include "aarch-common-protos.h" |
| 78 |
#include "machmode.h" |
| 79 |
#include "arm-builtins.h" |
| 80 |
|
| 81 |
/* This file should be included last. */ |
| 82 |
#include "target-def.h" |
| 83 |
|
| 84 |
/* Forward definitions of types. */ |
| 85 |
typedef struct minipool_node Mnode; |
| 86 |
typedef struct minipool_fixup Mfix; |
| 87 |
|
| 88 |
void (*arm_lang_output_object_attributes_hook)(void); |
| 89 |
|
| 90 |
struct four_ints |
| 91 |
{ |
| 92 |
int i[4]; |
| 93 |
}; |
| 94 |
|
| 95 |
/* Forward function declarations. */ |
| 96 |
static bool arm_const_not_ok_for_debug_p (rtx); |
| 97 |
static int arm_needs_doubleword_align (machine_mode, const_tree); |
| 98 |
static int arm_compute_static_chain_stack_bytes (void); |
| 99 |
static arm_stack_offsets *arm_get_frame_offsets (void); |
| 100 |
static void arm_compute_frame_layout (void); |
| 101 |
static void arm_add_gc_roots (void); |
| 102 |
static int arm_gen_constant (enum rtx_code, machine_mode, rtx, |
| 103 |
unsigned HOST_WIDE_INT, rtx, rtx, int, int); |
| 104 |
static unsigned bit_count (unsigned long); |
| 105 |
static unsigned bitmap_popcount (const sbitmap); |
| 106 |
static int arm_address_register_rtx_p (rtx, int); |
| 107 |
static int arm_legitimate_index_p (machine_mode, rtx, RTX_CODE, int); |
| 108 |
static bool is_called_in_ARM_mode (tree); |
| 109 |
static int thumb2_legitimate_index_p (machine_mode, rtx, int); |
| 110 |
static int thumb1_base_register_rtx_p (rtx, machine_mode, int); |
| 111 |
static rtx arm_legitimize_address (rtx, rtx, machine_mode); |
| 112 |
static reg_class_t arm_preferred_reload_class (rtx, reg_class_t); |
| 113 |
static rtx thumb_legitimize_address (rtx, rtx, machine_mode); |
| 114 |
inline static int thumb1_index_register_rtx_p (rtx, int); |
| 115 |
static int thumb_far_jump_used_p (void); |
| 116 |
static bool thumb_force_lr_save (void); |
| 117 |
static unsigned arm_size_return_regs (void); |
| 118 |
static bool arm_assemble_integer (rtx, unsigned int, int); |
| 119 |
static void arm_print_operand (FILE *, rtx, int); |
| 120 |
static void arm_print_operand_address (FILE *, machine_mode, rtx); |
| 121 |
static bool arm_print_operand_punct_valid_p (unsigned char code); |
| 122 |
static arm_cc get_arm_condition_code (rtx); |
| 123 |
static bool arm_fixed_condition_code_regs (unsigned int *, unsigned int *); |
| 124 |
static const char *output_multi_immediate (rtx *, const char *, const char *, |
| 125 |
int, HOST_WIDE_INT); |
| 126 |
static const char *shift_op (rtx, HOST_WIDE_INT *); |
| 127 |
static struct machine_function *arm_init_machine_status (void); |
| 128 |
static void thumb_exit (FILE *, int); |
| 129 |
static HOST_WIDE_INT get_jump_table_size (rtx_jump_table_data *); |
| 130 |
static Mnode *move_minipool_fix_forward_ref (Mnode *, Mnode *, HOST_WIDE_INT); |
| 131 |
static Mnode *add_minipool_forward_ref (Mfix *); |
| 132 |
static Mnode *move_minipool_fix_backward_ref (Mnode *, Mnode *, HOST_WIDE_INT); |
| 133 |
static Mnode *add_minipool_backward_ref (Mfix *); |
| 134 |
static void assign_minipool_offsets (Mfix *); |
| 135 |
static void arm_print_value (FILE *, rtx); |
| 136 |
static void dump_minipool (rtx_insn *); |
| 137 |
static int arm_barrier_cost (rtx_insn *); |
| 138 |
static Mfix *create_fix_barrier (Mfix *, HOST_WIDE_INT); |
| 139 |
static void push_minipool_barrier (rtx_insn *, HOST_WIDE_INT); |
| 140 |
static void push_minipool_fix (rtx_insn *, HOST_WIDE_INT, rtx *, |
| 141 |
machine_mode, rtx); |
| 142 |
static void arm_reorg (void); |
| 143 |
static void note_invalid_constants (rtx_insn *, HOST_WIDE_INT, int); |
| 144 |
static unsigned long arm_compute_save_reg0_reg12_mask (void); |
| 145 |
static unsigned long arm_compute_save_core_reg_mask (void); |
| 146 |
static unsigned long arm_isr_value (tree); |
| 147 |
static unsigned long arm_compute_func_type (void); |
| 148 |
static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *); |
| 149 |
static tree arm_handle_pcs_attribute (tree *, tree, tree, int, bool *); |
| 150 |
static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *); |
| 151 |
#if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
| 152 |
static tree arm_handle_notshared_attribute (tree *, tree, tree, int, bool *); |
| 153 |
#endif |
| 154 |
static tree arm_handle_cmse_nonsecure_entry (tree *, tree, tree, int, bool *); |
| 155 |
static tree arm_handle_cmse_nonsecure_call (tree *, tree, tree, int, bool *); |
| 156 |
static void arm_output_function_epilogue (FILE *); |
| 157 |
static void arm_output_function_prologue (FILE *); |
| 158 |
static int arm_comp_type_attributes (const_tree, const_tree); |
| 159 |
static void arm_set_default_type_attributes (tree); |
| 160 |
static int arm_adjust_cost (rtx_insn *, int, rtx_insn *, int, unsigned int); |
| 161 |
static int arm_sched_reorder (FILE *, int, rtx_insn **, int *, int); |
| 162 |
static int optimal_immediate_sequence (enum rtx_code code, |
| 163 |
unsigned HOST_WIDE_INT val, |
| 164 |
struct four_ints *return_sequence); |
| 165 |
static int optimal_immediate_sequence_1 (enum rtx_code code, |
| 166 |
unsigned HOST_WIDE_INT val, |
| 167 |
struct four_ints *return_sequence, |
| 168 |
int i); |
| 169 |
static int arm_get_strip_length (int); |
| 170 |
static bool arm_function_ok_for_sibcall (tree, tree); |
| 171 |
static machine_mode arm_promote_function_mode (const_tree, |
| 172 |
machine_mode, int *, |
| 173 |
const_tree, int); |
| 174 |
static bool arm_return_in_memory (const_tree, const_tree); |
| 175 |
static rtx arm_function_value (const_tree, const_tree, bool); |
| 176 |
static rtx arm_libcall_value_1 (machine_mode); |
| 177 |
static rtx arm_libcall_value (machine_mode, const_rtx); |
| 178 |
static bool arm_function_value_regno_p (const unsigned int); |
| 179 |
static void arm_internal_label (FILE *, const char *, unsigned long); |
| 180 |
static void arm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, |
| 181 |
tree); |
| 182 |
static bool arm_have_conditional_execution (void); |
| 183 |
static bool arm_cannot_force_const_mem (machine_mode, rtx); |
| 184 |
static bool arm_legitimate_constant_p (machine_mode, rtx); |
| 185 |
static bool arm_rtx_costs (rtx, machine_mode, int, int, int *, bool); |
| 186 |
static int arm_insn_cost (rtx_insn *, bool); |
| 187 |
static int arm_address_cost (rtx, machine_mode, addr_space_t, bool); |
| 188 |
static int arm_register_move_cost (machine_mode, reg_class_t, reg_class_t); |
| 189 |
static int arm_memory_move_cost (machine_mode, reg_class_t, bool); |
| 190 |
static void emit_constant_insn (rtx cond, rtx pattern); |
| 191 |
static rtx_insn *emit_set_insn (rtx, rtx); |
| 192 |
static void arm_add_cfa_adjust_cfa_note (rtx, int, rtx, rtx); |
| 193 |
static rtx emit_multi_reg_push (unsigned long, unsigned long); |
| 194 |
static void arm_emit_multi_reg_pop (unsigned long); |
| 195 |
static int vfp_emit_fstmd (int, int); |
| 196 |
static void arm_emit_vfp_multi_reg_pop (int, int, rtx); |
| 197 |
static int arm_arg_partial_bytes (cumulative_args_t, |
| 198 |
const function_arg_info &); |
| 199 |
static rtx arm_function_arg (cumulative_args_t, const function_arg_info &); |
| 200 |
static void arm_function_arg_advance (cumulative_args_t, |
| 201 |
const function_arg_info &); |
| 202 |
static pad_direction arm_function_arg_padding (machine_mode, const_tree); |
| 203 |
static unsigned int arm_function_arg_boundary (machine_mode, const_tree); |
| 204 |
static rtx aapcs_allocate_return_reg (machine_mode, const_tree, |
| 205 |
const_tree); |
| 206 |
static rtx aapcs_libcall_value (machine_mode); |
| 207 |
static int aapcs_select_return_coproc (const_tree, const_tree); |
| 208 |
|
| 209 |
#ifdef OBJECT_FORMAT_ELF |
| 210 |
static void arm_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED; |
| 211 |
static void arm_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED; |
| 212 |
#endif |
| 213 |
static void arm_encode_section_info (tree, rtx, int); |
| 214 |
|
| 215 |
static void arm_file_end (void); |
| 216 |
static void arm_file_start (void); |
| 217 |
static void arm_insert_attributes (tree, tree *); |
| 218 |
|
| 219 |
static void arm_setup_incoming_varargs (cumulative_args_t, |
| 220 |
const function_arg_info &, int *, int); |
| 221 |
static bool arm_pass_by_reference (cumulative_args_t, |
| 222 |
const function_arg_info &); |
| 223 |
static bool arm_promote_prototypes (const_tree); |
| 224 |
static bool arm_default_short_enums (void); |
| 225 |
static bool arm_align_anon_bitfield (void); |
| 226 |
static bool arm_return_in_msb (const_tree); |
| 227 |
static bool arm_must_pass_in_stack (const function_arg_info &); |
| 228 |
static bool arm_return_in_memory (const_tree, const_tree); |
| 229 |
#if ARM_UNWIND_INFO |
| 230 |
static void arm_unwind_emit (FILE *, rtx_insn *); |
| 231 |
static bool arm_output_ttype (rtx); |
| 232 |
static void arm_asm_emit_except_personality (rtx); |
| 233 |
#endif |
| 234 |
static void arm_asm_init_sections (void); |
| 235 |
static rtx arm_dwarf_register_span (rtx); |
| 236 |
|
| 237 |
static tree arm_cxx_guard_type (void); |
| 238 |
static bool arm_cxx_guard_mask_bit (void); |
| 239 |
static tree arm_get_cookie_size (tree); |
| 240 |
static bool arm_cookie_has_size (void); |
| 241 |
static bool arm_cxx_cdtor_returns_this (void); |
| 242 |
static bool arm_cxx_key_method_may_be_inline (void); |
| 243 |
static void arm_cxx_determine_class_data_visibility (tree); |
| 244 |
static bool arm_cxx_class_data_always_comdat (void); |
| 245 |
static bool arm_cxx_use_aeabi_atexit (void); |
| 246 |
static void arm_init_libfuncs (void); |
| 247 |
static tree arm_build_builtin_va_list (void); |
| 248 |
static void arm_expand_builtin_va_start (tree, rtx); |
| 249 |
static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *); |
| 250 |
static void arm_option_override (void); |
| 251 |
static void arm_option_restore (struct gcc_options *, struct gcc_options *, |
| 252 |
struct cl_target_option *); |
| 253 |
static void arm_override_options_after_change (void); |
| 254 |
static void arm_option_print (FILE *, int, struct cl_target_option *); |
| 255 |
static void arm_set_current_function (tree); |
| 256 |
static bool arm_can_inline_p (tree, tree); |
| 257 |
static void arm_relayout_function (tree); |
| 258 |
static bool arm_valid_target_attribute_p (tree, tree, tree, int); |
| 259 |
static unsigned HOST_WIDE_INT arm_shift_truncation_mask (machine_mode); |
| 260 |
static bool arm_sched_can_speculate_insn (rtx_insn *); |
| 261 |
static bool arm_macro_fusion_p (void); |
| 262 |
static bool arm_cannot_copy_insn_p (rtx_insn *); |
| 263 |
static int arm_issue_rate (void); |
| 264 |
static int arm_sched_variable_issue (FILE *, int, rtx_insn *, int); |
| 265 |
static int arm_first_cycle_multipass_dfa_lookahead (void); |
| 266 |
static int arm_first_cycle_multipass_dfa_lookahead_guard (rtx_insn *, int); |
| 267 |
static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED; |
| 268 |
static bool arm_output_addr_const_extra (FILE *, rtx); |
| 269 |
static bool arm_allocate_stack_slots_for_args (void); |
| 270 |
static bool arm_warn_func_return (tree); |
| 271 |
static tree arm_promoted_type (const_tree t); |
| 272 |
static bool arm_scalar_mode_supported_p (scalar_mode); |
| 273 |
static bool arm_frame_pointer_required (void); |
| 274 |
static bool arm_can_eliminate (const int, const int); |
| 275 |
static void arm_asm_trampoline_template (FILE *); |
| 276 |
static void arm_trampoline_init (rtx, tree, rtx); |
| 277 |
static rtx arm_trampoline_adjust_address (rtx); |
| 278 |
static rtx_insn *arm_pic_static_addr (rtx orig, rtx reg); |
| 279 |
static bool cortex_a9_sched_adjust_cost (rtx_insn *, int, rtx_insn *, int *); |
| 280 |
static bool xscale_sched_adjust_cost (rtx_insn *, int, rtx_insn *, int *); |
| 281 |
static bool fa726te_sched_adjust_cost (rtx_insn *, int, rtx_insn *, int *); |
| 282 |
static opt_machine_mode arm_array_mode (machine_mode, unsigned HOST_WIDE_INT); |
| 283 |
static bool arm_array_mode_supported_p (machine_mode, |
| 284 |
unsigned HOST_WIDE_INT); |
| 285 |
static machine_mode arm_preferred_simd_mode (scalar_mode); |
| 286 |
static bool arm_class_likely_spilled_p (reg_class_t); |
| 287 |
static HOST_WIDE_INT arm_vector_alignment (const_tree type); |
| 288 |
static bool arm_vector_alignment_reachable (const_tree type, bool is_packed); |
| 289 |
static bool arm_builtin_support_vector_misalignment (machine_mode mode, |
| 290 |
const_tree type, |
| 291 |
int misalignment, |
| 292 |
bool is_packed); |
| 293 |
static void arm_conditional_register_usage (void); |
| 294 |
static enum flt_eval_method arm_excess_precision (enum excess_precision_type); |
| 295 |
static reg_class_t arm_preferred_rename_class (reg_class_t rclass); |
| 296 |
static unsigned int arm_autovectorize_vector_modes (vector_modes *, bool); |
| 297 |
static int arm_default_branch_cost (bool, bool); |
| 298 |
static int arm_cortex_a5_branch_cost (bool, bool); |
| 299 |
static int arm_cortex_m_branch_cost (bool, bool); |
| 300 |
static int arm_cortex_m7_branch_cost (bool, bool); |
| 301 |
|
| 302 |
static bool arm_vectorize_vec_perm_const (machine_mode, machine_mode, rtx, rtx, |
| 303 |
rtx, const vec_perm_indices &); |
| 304 |
|
| 305 |
static bool aarch_macro_fusion_pair_p (rtx_insn*, rtx_insn*); |
| 306 |
|
| 307 |
static int arm_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost, |
| 308 |
tree vectype, |
| 309 |
int misalign ATTRIBUTE_UNUSED); |
| 310 |
|
| 311 |
static void arm_canonicalize_comparison (int *code, rtx *op0, rtx *op1, |
| 312 |
bool op0_preserve_value); |
| 313 |
static unsigned HOST_WIDE_INT arm_asan_shadow_offset (void); |
| 314 |
|
| 315 |
static void arm_sched_fusion_priority (rtx_insn *, int, int *, int*); |
| 316 |
static bool arm_can_output_mi_thunk (const_tree, HOST_WIDE_INT, HOST_WIDE_INT, |
| 317 |
const_tree); |
| 318 |
static section *arm_function_section (tree, enum node_frequency, bool, bool); |
| 319 |
static bool arm_asm_elf_flags_numeric (unsigned int flags, unsigned int *num); |
| 320 |
static unsigned int arm_elf_section_type_flags (tree decl, const char *name, |
| 321 |
int reloc); |
| 322 |
static void arm_expand_divmod_libfunc (rtx, machine_mode, rtx, rtx, rtx *, rtx *); |
| 323 |
static opt_scalar_float_mode arm_floatn_mode (int, bool); |
| 324 |
static unsigned int arm_hard_regno_nregs (unsigned int, machine_mode); |
| 325 |
static bool arm_hard_regno_mode_ok (unsigned int, machine_mode); |
| 326 |
static bool arm_modes_tieable_p (machine_mode, machine_mode); |
| 327 |
static HOST_WIDE_INT arm_constant_alignment (const_tree, HOST_WIDE_INT); |
| 328 |
static rtx_insn *thumb1_md_asm_adjust (vec<rtx> &, vec<rtx> &, |
| 329 |
vec<machine_mode> &, |
| 330 |
vec<const char *> &, vec<rtx> &, |
| 331 |
vec<rtx> &, HARD_REG_SET &, location_t); |
| 332 |
static const char *arm_identify_fpu_from_isa (sbitmap); |
| 333 |
|
| 334 |
/* Table of machine attributes. */ |
| 335 |
static const attribute_spec arm_gnu_attributes[] = |
| 336 |
{ |
| 337 |
/* { name, min_len, max_len, decl_req, type_req, fn_type_req, |
| 338 |
affects_type_identity, handler, exclude } */ |
| 339 |
/* Function calls made to this symbol must be done indirectly, because |
| 340 |
it may lie outside of the 26 bit addressing range of a normal function |
| 341 |
call. */ |
| 342 |
{ "long_call", 0, 0, false, true, true, false, NULL, NULL }, |
| 343 |
/* Whereas these functions are always known to reside within the 26 bit |
| 344 |
addressing range. */ |
| 345 |
{ "short_call", 0, 0, false, true, true, false, NULL, NULL }, |
| 346 |
/* Specify the procedure call conventions for a function. */ |
| 347 |
{ "pcs", 1, 1, false, true, true, false, arm_handle_pcs_attribute, |
| 348 |
NULL }, |
| 349 |
/* Interrupt Service Routines have special prologue and epilogue requirements. */ |
| 350 |
{ "isr", 0, 1, false, false, false, false, arm_handle_isr_attribute, |
| 351 |
NULL }, |
| 352 |
{ "interrupt", 0, 1, false, false, false, false, arm_handle_isr_attribute, |
| 353 |
NULL }, |
| 354 |
{ "naked", 0, 0, true, false, false, false, |
| 355 |
arm_handle_fndecl_attribute, NULL }, |
| 356 |
#if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
| 357 |
{ "dllimport", 0, 0, false, false, false, false, handle_dll_attribute, |
| 358 |
NULL }, |
| 359 |
{ "dllexport", 0, 0, false, false, false, false, handle_dll_attribute, |
| 360 |
NULL }, |
| 361 |
{ "notshared", 0, 0, false, true, false, false, |
| 362 |
arm_handle_notshared_attribute, NULL }, |
| 363 |
#endif |
| 364 |
/* ARMv8-M Security Extensions support. */ |
| 365 |
{ "cmse_nonsecure_entry", 0, 0, true, false, false, false, |
| 366 |
arm_handle_cmse_nonsecure_entry, NULL }, |
| 367 |
{ "cmse_nonsecure_call", 0, 0, false, false, false, true, |
| 368 |
arm_handle_cmse_nonsecure_call, NULL }, |
| 369 |
{ "Advanced SIMD type", 1, 1, false, true, false, true, NULL, NULL } |
| 370 |
}; |
| 371 |
|
| 372 |
static const scoped_attribute_specs arm_gnu_attribute_table = |
| 373 |
{ |
| 374 |
"gnu", { arm_gnu_attributes } |
| 375 |
}; |
| 376 |
|
| 377 |
static const scoped_attribute_specs *const arm_attribute_table[] = |
| 378 |
{ |
| 379 |
&arm_gnu_attribute_table |
| 380 |
}; |
| 381 |
|
| 382 |
/* Initialize the GCC target structure. */ |
| 383 |
#if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
| 384 |
#undef TARGET_MERGE_DECL_ATTRIBUTES |
| 385 |
#define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes |
| 386 |
#endif |
| 387 |
|
| 388 |
#undef TARGET_CHECK_BUILTIN_CALL |
| 389 |
#define TARGET_CHECK_BUILTIN_CALL arm_check_builtin_call |
| 390 |
|
| 391 |
#undef TARGET_LEGITIMIZE_ADDRESS |
| 392 |
#define TARGET_LEGITIMIZE_ADDRESS arm_legitimize_address |
| 393 |
|
| 394 |
#undef TARGET_ATTRIBUTE_TABLE |
| 395 |
#define TARGET_ATTRIBUTE_TABLE arm_attribute_table |
| 396 |
|
| 397 |
#undef TARGET_INSERT_ATTRIBUTES |
| 398 |
#define TARGET_INSERT_ATTRIBUTES arm_insert_attributes |
| 399 |
|
| 400 |
#undef TARGET_ASM_FILE_START |
| 401 |
#define TARGET_ASM_FILE_START arm_file_start |
| 402 |
#undef TARGET_ASM_FILE_END |
| 403 |
#define TARGET_ASM_FILE_END arm_file_end |
| 404 |
|
| 405 |
#undef TARGET_ASM_ALIGNED_SI_OP |
| 406 |
#define TARGET_ASM_ALIGNED_SI_OP NULL |
| 407 |
#undef TARGET_ASM_INTEGER |
| 408 |
#define TARGET_ASM_INTEGER arm_assemble_integer |
| 409 |
|
| 410 |
#undef TARGET_PRINT_OPERAND |
| 411 |
#define TARGET_PRINT_OPERAND arm_print_operand |
| 412 |
#undef TARGET_PRINT_OPERAND_ADDRESS |
| 413 |
#define TARGET_PRINT_OPERAND_ADDRESS arm_print_operand_address |
| 414 |
#undef TARGET_PRINT_OPERAND_PUNCT_VALID_P |
| 415 |
#define TARGET_PRINT_OPERAND_PUNCT_VALID_P arm_print_operand_punct_valid_p |
| 416 |
|
| 417 |
#undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA |
| 418 |
#define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA arm_output_addr_const_extra |
| 419 |
|
| 420 |
#undef TARGET_ASM_FUNCTION_PROLOGUE |
| 421 |
#define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue |
| 422 |
|
| 423 |
#undef TARGET_ASM_FUNCTION_EPILOGUE |
| 424 |
#define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue |
| 425 |
|
| 426 |
#undef TARGET_CAN_INLINE_P |
| 427 |
#define TARGET_CAN_INLINE_P arm_can_inline_p |
| 428 |
|
| 429 |
#undef TARGET_RELAYOUT_FUNCTION |
| 430 |
#define TARGET_RELAYOUT_FUNCTION arm_relayout_function |
| 431 |
|
| 432 |
#undef TARGET_OPTION_OVERRIDE |
| 433 |
#define TARGET_OPTION_OVERRIDE arm_option_override |
| 434 |
|
| 435 |
#undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE |
| 436 |
#define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE arm_override_options_after_change |
| 437 |
|
| 438 |
#undef TARGET_OPTION_RESTORE |
| 439 |
#define TARGET_OPTION_RESTORE arm_option_restore |
| 440 |
|
| 441 |
#undef TARGET_OPTION_PRINT |
| 442 |
#define TARGET_OPTION_PRINT arm_option_print |
| 443 |
|
| 444 |
#undef TARGET_COMP_TYPE_ATTRIBUTES |
| 445 |
#define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes |
| 446 |
|
| 447 |
#undef TARGET_SCHED_CAN_SPECULATE_INSN |
| 448 |
#define TARGET_SCHED_CAN_SPECULATE_INSN arm_sched_can_speculate_insn |
| 449 |
|
| 450 |
#undef TARGET_SCHED_MACRO_FUSION_P |
| 451 |
#define TARGET_SCHED_MACRO_FUSION_P arm_macro_fusion_p |
| 452 |
|
| 453 |
#undef TARGET_SCHED_MACRO_FUSION_PAIR_P |
| 454 |
#define TARGET_SCHED_MACRO_FUSION_PAIR_P aarch_macro_fusion_pair_p |
| 455 |
|
| 456 |
#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES |
| 457 |
#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes |
| 458 |
|
| 459 |
#undef TARGET_SCHED_ADJUST_COST |
| 460 |
#define TARGET_SCHED_ADJUST_COST arm_adjust_cost |
| 461 |
|
| 462 |
#undef TARGET_SET_CURRENT_FUNCTION |
| 463 |
#define TARGET_SET_CURRENT_FUNCTION arm_set_current_function |
| 464 |
|
| 465 |
#undef TARGET_OPTION_VALID_ATTRIBUTE_P |
| 466 |
#define TARGET_OPTION_VALID_ATTRIBUTE_P arm_valid_target_attribute_p |
| 467 |
|
| 468 |
#undef TARGET_SCHED_REORDER |
| 469 |
#define TARGET_SCHED_REORDER arm_sched_reorder |
| 470 |
|
| 471 |
#undef TARGET_REGISTER_MOVE_COST |
| 472 |
#define TARGET_REGISTER_MOVE_COST arm_register_move_cost |
| 473 |
|
| 474 |
#undef TARGET_MEMORY_MOVE_COST |
| 475 |
#define TARGET_MEMORY_MOVE_COST arm_memory_move_cost |
| 476 |
|
| 477 |
#undef TARGET_ENCODE_SECTION_INFO |
| 478 |
#define TARGET_ENCODE_SECTION_INFO arm_encode_section_info |
| 479 |
|
| 480 |
#undef TARGET_STRIP_NAME_ENCODING |
| 481 |
#define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding |
| 482 |
|
| 483 |
#undef TARGET_ASM_INTERNAL_LABEL |
| 484 |
#define TARGET_ASM_INTERNAL_LABEL arm_internal_label |
| 485 |
|
| 486 |
#undef TARGET_FLOATN_MODE |
| 487 |
#define TARGET_FLOATN_MODE arm_floatn_mode |
| 488 |
|
| 489 |
#undef TARGET_FUNCTION_OK_FOR_SIBCALL |
| 490 |
#define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall |
| 491 |
|
| 492 |
#undef TARGET_FUNCTION_VALUE |
| 493 |
#define TARGET_FUNCTION_VALUE arm_function_value |
| 494 |
|
| 495 |
#undef TARGET_LIBCALL_VALUE |
| 496 |
#define TARGET_LIBCALL_VALUE arm_libcall_value |
| 497 |
|
| 498 |
#undef TARGET_FUNCTION_VALUE_REGNO_P |
| 499 |
#define TARGET_FUNCTION_VALUE_REGNO_P arm_function_value_regno_p |
| 500 |
|
| 501 |
#undef TARGET_GIMPLE_FOLD_BUILTIN |
| 502 |
#define TARGET_GIMPLE_FOLD_BUILTIN arm_gimple_fold_builtin |
| 503 |
|
| 504 |
#undef TARGET_ASM_OUTPUT_MI_THUNK |
| 505 |
#define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk |
| 506 |
#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK |
| 507 |
#define TARGET_ASM_CAN_OUTPUT_MI_THUNK arm_can_output_mi_thunk |
| 508 |
|
| 509 |
#undef TARGET_RTX_COSTS |
| 510 |
#define TARGET_RTX_COSTS arm_rtx_costs |
| 511 |
#undef TARGET_ADDRESS_COST |
| 512 |
#define TARGET_ADDRESS_COST arm_address_cost |
| 513 |
#undef TARGET_INSN_COST |
| 514 |
#define TARGET_INSN_COST arm_insn_cost |
| 515 |
|
| 516 |
#undef TARGET_SHIFT_TRUNCATION_MASK |
| 517 |
#define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask |
| 518 |
#undef TARGET_VECTOR_MODE_SUPPORTED_P |
| 519 |
#define TARGET_VECTOR_MODE_SUPPORTED_P arm_vector_mode_supported_p |
| 520 |
#undef TARGET_ARRAY_MODE |
| 521 |
#define TARGET_ARRAY_MODE arm_array_mode |
| 522 |
#undef TARGET_ARRAY_MODE_SUPPORTED_P |
| 523 |
#define TARGET_ARRAY_MODE_SUPPORTED_P arm_array_mode_supported_p |
| 524 |
#undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE |
| 525 |
#define TARGET_VECTORIZE_PREFERRED_SIMD_MODE arm_preferred_simd_mode |
| 526 |
#undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES |
| 527 |
#define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES \ |
| 528 |
arm_autovectorize_vector_modes |
| 529 |
|
| 530 |
#undef TARGET_MACHINE_DEPENDENT_REORG |
| 531 |
#define TARGET_MACHINE_DEPENDENT_REORG arm_reorg |
| 532 |
|
| 533 |
#undef TARGET_INIT_BUILTINS |
| 534 |
#define TARGET_INIT_BUILTINS arm_init_builtins |
| 535 |
#undef TARGET_EXPAND_BUILTIN |
| 536 |
#define TARGET_EXPAND_BUILTIN arm_expand_builtin |
| 537 |
#undef TARGET_BUILTIN_DECL |
| 538 |
#define TARGET_BUILTIN_DECL arm_builtin_decl |
| 539 |
|
| 540 |
#undef TARGET_INIT_LIBFUNCS |
| 541 |
#define TARGET_INIT_LIBFUNCS arm_init_libfuncs |
| 542 |
|
| 543 |
#undef TARGET_PROMOTE_FUNCTION_MODE |
| 544 |
#define TARGET_PROMOTE_FUNCTION_MODE arm_promote_function_mode |
| 545 |
#undef TARGET_PROMOTE_PROTOTYPES |
| 546 |
#define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes |
| 547 |
#undef TARGET_PASS_BY_REFERENCE |
| 548 |
#define TARGET_PASS_BY_REFERENCE arm_pass_by_reference |
| 549 |
#undef TARGET_ARG_PARTIAL_BYTES |
| 550 |
#define TARGET_ARG_PARTIAL_BYTES arm_arg_partial_bytes |
| 551 |
#undef TARGET_FUNCTION_ARG |
| 552 |
#define TARGET_FUNCTION_ARG arm_function_arg |
| 553 |
#undef TARGET_FUNCTION_ARG_ADVANCE |
| 554 |
#define TARGET_FUNCTION_ARG_ADVANCE arm_function_arg_advance |
| 555 |
#undef TARGET_FUNCTION_ARG_PADDING |
| 556 |
#define TARGET_FUNCTION_ARG_PADDING arm_function_arg_padding |
| 557 |
#undef TARGET_FUNCTION_ARG_BOUNDARY |
| 558 |
#define TARGET_FUNCTION_ARG_BOUNDARY arm_function_arg_boundary |
| 559 |
|
| 560 |
#undef TARGET_SETUP_INCOMING_VARARGS |
| 561 |
#define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs |
| 562 |
|
| 563 |
#undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS |
| 564 |
#define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args |
| 565 |
|
| 566 |
#undef TARGET_ASM_TRAMPOLINE_TEMPLATE |
| 567 |
#define TARGET_ASM_TRAMPOLINE_TEMPLATE arm_asm_trampoline_template |
| 568 |
#undef TARGET_TRAMPOLINE_INIT |
| 569 |
#define TARGET_TRAMPOLINE_INIT arm_trampoline_init |
| 570 |
#undef TARGET_TRAMPOLINE_ADJUST_ADDRESS |
| 571 |
#define TARGET_TRAMPOLINE_ADJUST_ADDRESS arm_trampoline_adjust_address |
| 572 |
|
| 573 |
#undef TARGET_WARN_FUNC_RETURN |
| 574 |
#define TARGET_WARN_FUNC_RETURN arm_warn_func_return |
| 575 |
|
| 576 |
#undef TARGET_DEFAULT_SHORT_ENUMS |
| 577 |
#define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums |
| 578 |
|
| 579 |
#undef TARGET_ALIGN_ANON_BITFIELD |
| 580 |
#define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield |
| 581 |
|
| 582 |
#undef TARGET_NARROW_VOLATILE_BITFIELD |
| 583 |
#define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false |
| 584 |
|
| 585 |
#undef TARGET_CXX_GUARD_TYPE |
| 586 |
#define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type |
| 587 |
|
| 588 |
#undef TARGET_CXX_GUARD_MASK_BIT |
| 589 |
#define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit |
| 590 |
|
| 591 |
#undef TARGET_CXX_GET_COOKIE_SIZE |
| 592 |
#define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size |
| 593 |
|
| 594 |
#undef TARGET_CXX_COOKIE_HAS_SIZE |
| 595 |
#define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size |
| 596 |
|
| 597 |
#undef TARGET_CXX_CDTOR_RETURNS_THIS |
| 598 |
#define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this |
| 599 |
|
| 600 |
#undef TARGET_CXX_KEY_METHOD_MAY_BE_INLINE |
| 601 |
#define TARGET_CXX_KEY_METHOD_MAY_BE_INLINE arm_cxx_key_method_may_be_inline |
| 602 |
|
| 603 |
#undef TARGET_CXX_USE_AEABI_ATEXIT |
| 604 |
#define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit |
| 605 |
|
| 606 |
#undef TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY |
| 607 |
#define TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY \ |
| 608 |
arm_cxx_determine_class_data_visibility |
| 609 |
|
| 610 |
#undef TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT |
| 611 |
#define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT arm_cxx_class_data_always_comdat |
| 612 |
|
| 613 |
#undef TARGET_RETURN_IN_MSB |
| 614 |
#define TARGET_RETURN_IN_MSB arm_return_in_msb |
| 615 |
|
| 616 |
#undef TARGET_RETURN_IN_MEMORY |
| 617 |
#define TARGET_RETURN_IN_MEMORY arm_return_in_memory |
| 618 |
|
| 619 |
#undef TARGET_MUST_PASS_IN_STACK |
| 620 |
#define TARGET_MUST_PASS_IN_STACK arm_must_pass_in_stack |
| 621 |
|
| 622 |
#if ARM_UNWIND_INFO |
| 623 |
#undef TARGET_ASM_UNWIND_EMIT |
| 624 |
#define TARGET_ASM_UNWIND_EMIT arm_unwind_emit |
| 625 |
|
| 626 |
/* EABI unwinding tables use a different format for the typeinfo tables. */ |
| 627 |
#undef TARGET_ASM_TTYPE |
| 628 |
#define TARGET_ASM_TTYPE arm_output_ttype |
| 629 |
|
| 630 |
#undef TARGET_ARM_EABI_UNWINDER |
| 631 |
#define TARGET_ARM_EABI_UNWINDER true |
| 632 |
|
| 633 |
#undef TARGET_ASM_EMIT_EXCEPT_PERSONALITY |
| 634 |
#define TARGET_ASM_EMIT_EXCEPT_PERSONALITY arm_asm_emit_except_personality |
| 635 |
|
| 636 |
#endif /* ARM_UNWIND_INFO */ |
| 637 |
|
| 638 |
#undef TARGET_ASM_INIT_SECTIONS |
| 639 |
#define TARGET_ASM_INIT_SECTIONS arm_asm_init_sections |
| 640 |
|
| 641 |
#undef TARGET_DWARF_REGISTER_SPAN |
| 642 |
#define TARGET_DWARF_REGISTER_SPAN arm_dwarf_register_span |
| 643 |
|
| 644 |
#undef TARGET_CANNOT_COPY_INSN_P |
| 645 |
#define TARGET_CANNOT_COPY_INSN_P arm_cannot_copy_insn_p |
| 646 |
|
| 647 |
#ifdef HAVE_AS_TLS |
| 648 |
#undef TARGET_HAVE_TLS |
| 649 |
#define TARGET_HAVE_TLS true |
| 650 |
#endif |
| 651 |
|
| 652 |
#undef TARGET_HAVE_CONDITIONAL_EXECUTION |
| 653 |
#define TARGET_HAVE_CONDITIONAL_EXECUTION arm_have_conditional_execution |
| 654 |
|
| 655 |
#undef TARGET_LOOP_UNROLL_ADJUST |
| 656 |
#define TARGET_LOOP_UNROLL_ADJUST arm_loop_unroll_adjust |
| 657 |
|
| 658 |
#undef TARGET_PREDICT_DOLOOP_P |
| 659 |
#define TARGET_PREDICT_DOLOOP_P arm_predict_doloop_p |
| 660 |
|
| 661 |
#undef TARGET_LEGITIMATE_CONSTANT_P |
| 662 |
#define TARGET_LEGITIMATE_CONSTANT_P arm_legitimate_constant_p |
| 663 |
|
| 664 |
#undef TARGET_CANNOT_FORCE_CONST_MEM |
| 665 |
#define TARGET_CANNOT_FORCE_CONST_MEM arm_cannot_force_const_mem |
| 666 |
|
| 667 |
#undef TARGET_MAX_ANCHOR_OFFSET |
| 668 |
#define TARGET_MAX_ANCHOR_OFFSET 4095 |
| 669 |
|
| 670 |
/* The minimum is set such that the total size of the block |
| 671 |
for a particular anchor is -4088 + 1 + 4095 bytes, which is |
| 672 |
divisible by eight, ensuring natural spacing of anchors. */ |
| 673 |
#undef TARGET_MIN_ANCHOR_OFFSET |
| 674 |
#define TARGET_MIN_ANCHOR_OFFSET -4088 |
| 675 |
|
| 676 |
#undef TARGET_SCHED_ISSUE_RATE |
| 677 |
#define TARGET_SCHED_ISSUE_RATE arm_issue_rate |
| 678 |
|
| 679 |
#undef TARGET_SCHED_VARIABLE_ISSUE |
| 680 |
#define TARGET_SCHED_VARIABLE_ISSUE arm_sched_variable_issue |
| 681 |
|
| 682 |
#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD |
| 683 |
#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \ |
| 684 |
arm_first_cycle_multipass_dfa_lookahead |
| 685 |
|
| 686 |
#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD |
| 687 |
#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD \ |
| 688 |
arm_first_cycle_multipass_dfa_lookahead_guard |
| 689 |
|
| 690 |
#undef TARGET_MANGLE_TYPE |
| 691 |
#define TARGET_MANGLE_TYPE arm_mangle_type |
| 692 |
|
| 693 |
#undef TARGET_INVALID_CONVERSION |
| 694 |
#define TARGET_INVALID_CONVERSION arm_invalid_conversion |
| 695 |
|
| 696 |
#undef TARGET_INVALID_UNARY_OP |
| 697 |
#define TARGET_INVALID_UNARY_OP arm_invalid_unary_op |
| 698 |
|
| 699 |
#undef TARGET_INVALID_BINARY_OP |
| 700 |
#define TARGET_INVALID_BINARY_OP arm_invalid_binary_op |
| 701 |
|
| 702 |
#undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV |
| 703 |
#define TARGET_ATOMIC_ASSIGN_EXPAND_FENV arm_atomic_assign_expand_fenv |
| 704 |
|
| 705 |
#undef TARGET_BUILD_BUILTIN_VA_LIST |
| 706 |
#define TARGET_BUILD_BUILTIN_VA_LIST arm_build_builtin_va_list |
| 707 |
#undef TARGET_EXPAND_BUILTIN_VA_START |
| 708 |
#define TARGET_EXPAND_BUILTIN_VA_START arm_expand_builtin_va_start |
| 709 |
#undef TARGET_GIMPLIFY_VA_ARG_EXPR |
| 710 |
#define TARGET_GIMPLIFY_VA_ARG_EXPR arm_gimplify_va_arg_expr |
| 711 |
|
| 712 |
#ifdef HAVE_AS_TLS |
| 713 |
#undef TARGET_ASM_OUTPUT_DWARF_DTPREL |
| 714 |
#define TARGET_ASM_OUTPUT_DWARF_DTPREL arm_output_dwarf_dtprel |
| 715 |
#endif |
| 716 |
|
| 717 |
#undef TARGET_LEGITIMATE_ADDRESS_P |
| 718 |
#define TARGET_LEGITIMATE_ADDRESS_P arm_legitimate_address_p |
| 719 |
|
| 720 |
#undef TARGET_PREFERRED_RELOAD_CLASS |
| 721 |
#define TARGET_PREFERRED_RELOAD_CLASS arm_preferred_reload_class |
| 722 |
|
| 723 |
#undef TARGET_PROMOTED_TYPE |
| 724 |
#define TARGET_PROMOTED_TYPE arm_promoted_type |
| 725 |
|
| 726 |
#undef TARGET_SCALAR_MODE_SUPPORTED_P |
| 727 |
#define TARGET_SCALAR_MODE_SUPPORTED_P arm_scalar_mode_supported_p |
| 728 |
|
| 729 |
#undef TARGET_COMPUTE_FRAME_LAYOUT |
| 730 |
#define TARGET_COMPUTE_FRAME_LAYOUT arm_compute_frame_layout |
| 731 |
|
| 732 |
#undef TARGET_FRAME_POINTER_REQUIRED |
| 733 |
#define TARGET_FRAME_POINTER_REQUIRED arm_frame_pointer_required |
| 734 |
|
| 735 |
#undef TARGET_CAN_ELIMINATE |
| 736 |
#define TARGET_CAN_ELIMINATE arm_can_eliminate |
| 737 |
|
| 738 |
#undef TARGET_CONDITIONAL_REGISTER_USAGE |
| 739 |
#define TARGET_CONDITIONAL_REGISTER_USAGE arm_conditional_register_usage |
| 740 |
|
| 741 |
#undef TARGET_CLASS_LIKELY_SPILLED_P |
| 742 |
#define TARGET_CLASS_LIKELY_SPILLED_P arm_class_likely_spilled_p |
| 743 |
|
| 744 |
#undef TARGET_VECTORIZE_BUILTINS |
| 745 |
#define TARGET_VECTORIZE_BUILTINS |
| 746 |
|
| 747 |
#undef TARGET_VECTOR_ALIGNMENT |
| 748 |
#define TARGET_VECTOR_ALIGNMENT arm_vector_alignment |
| 749 |
|
| 750 |
#undef TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE |
| 751 |
#define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE \ |
| 752 |
arm_vector_alignment_reachable |
| 753 |
|
| 754 |
#undef TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT |
| 755 |
#define TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT \ |
| 756 |
arm_builtin_support_vector_misalignment |
| 757 |
|
| 758 |
#undef TARGET_PREFERRED_RENAME_CLASS |
| 759 |
#define TARGET_PREFERRED_RENAME_CLASS \ |
| 760 |
arm_preferred_rename_class |
| 761 |
|
| 762 |
#undef TARGET_VECTORIZE_VEC_PERM_CONST |
| 763 |
#define TARGET_VECTORIZE_VEC_PERM_CONST arm_vectorize_vec_perm_const |
| 764 |
|
| 765 |
#undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST |
| 766 |
#define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST \ |
| 767 |
arm_builtin_vectorization_cost |
| 768 |
|
| 769 |
#undef TARGET_CANONICALIZE_COMPARISON |
| 770 |
#define TARGET_CANONICALIZE_COMPARISON \ |
| 771 |
arm_canonicalize_comparison |
| 772 |
|
| 773 |
#undef TARGET_ASAN_SHADOW_OFFSET |
| 774 |
#define TARGET_ASAN_SHADOW_OFFSET arm_asan_shadow_offset |
| 775 |
|
| 776 |
#undef MAX_INSN_PER_IT_BLOCK |
| 777 |
#define MAX_INSN_PER_IT_BLOCK (arm_restrict_it ? 1 : 4) |
| 778 |
|
| 779 |
#undef TARGET_CAN_USE_DOLOOP_P |
| 780 |
#define TARGET_CAN_USE_DOLOOP_P can_use_doloop_if_innermost |
| 781 |
|
| 782 |
#undef TARGET_CONST_NOT_OK_FOR_DEBUG_P |
| 783 |
#define TARGET_CONST_NOT_OK_FOR_DEBUG_P arm_const_not_ok_for_debug_p |
| 784 |
|
| 785 |
#undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS |
| 786 |
#define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true |
| 787 |
|
| 788 |
#undef TARGET_SCHED_FUSION_PRIORITY |
| 789 |
#define TARGET_SCHED_FUSION_PRIORITY arm_sched_fusion_priority |
| 790 |
|
| 791 |
#undef TARGET_ASM_FUNCTION_SECTION |
| 792 |
#define TARGET_ASM_FUNCTION_SECTION arm_function_section |
| 793 |
|
| 794 |
#undef TARGET_ASM_ELF_FLAGS_NUMERIC |
| 795 |
#define TARGET_ASM_ELF_FLAGS_NUMERIC arm_asm_elf_flags_numeric |
| 796 |
|
| 797 |
#undef TARGET_SECTION_TYPE_FLAGS |
| 798 |
#define TARGET_SECTION_TYPE_FLAGS arm_elf_section_type_flags |
| 799 |
|
| 800 |
#undef TARGET_EXPAND_DIVMOD_LIBFUNC |
| 801 |
#define TARGET_EXPAND_DIVMOD_LIBFUNC arm_expand_divmod_libfunc |
| 802 |
|
| 803 |
#undef TARGET_C_EXCESS_PRECISION |
| 804 |
#define TARGET_C_EXCESS_PRECISION arm_excess_precision |
| 805 |
|
| 806 |
/* Although the architecture reserves bits 0 and 1, only the former is |
| 807 |
used for ARM/Thumb ISA selection in v7 and earlier versions. */ |
| 808 |
#undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS |
| 809 |
#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 2 |
| 810 |
|
| 811 |
#undef TARGET_FIXED_CONDITION_CODE_REGS |
| 812 |
#define TARGET_FIXED_CONDITION_CODE_REGS arm_fixed_condition_code_regs |
| 813 |
|
| 814 |
#undef TARGET_HARD_REGNO_NREGS |
| 815 |
#define TARGET_HARD_REGNO_NREGS arm_hard_regno_nregs |
| 816 |
#undef TARGET_HARD_REGNO_MODE_OK |
| 817 |
#define TARGET_HARD_REGNO_MODE_OK arm_hard_regno_mode_ok |
| 818 |
|
| 819 |
#undef TARGET_MODES_TIEABLE_P |
| 820 |
#define TARGET_MODES_TIEABLE_P arm_modes_tieable_p |
| 821 |
|
| 822 |
#undef TARGET_NOCE_CONVERSION_PROFITABLE_P |
| 823 |
#define TARGET_NOCE_CONVERSION_PROFITABLE_P arm_noce_conversion_profitable_p |
| 824 |
|
| 825 |
#undef TARGET_CAN_CHANGE_MODE_CLASS |
| 826 |
#define TARGET_CAN_CHANGE_MODE_CLASS arm_can_change_mode_class |
| 827 |
|
| 828 |
#undef TARGET_CONSTANT_ALIGNMENT |
| 829 |
#define TARGET_CONSTANT_ALIGNMENT arm_constant_alignment |
| 830 |
|
| 831 |
#undef TARGET_INVALID_WITHIN_DOLOOP |
| 832 |
#define TARGET_INVALID_WITHIN_DOLOOP arm_invalid_within_doloop |
| 833 |
|
| 834 |
#undef TARGET_MD_ASM_ADJUST |
| 835 |
#define TARGET_MD_ASM_ADJUST arm_md_asm_adjust |
| 836 |
|
| 837 |
#undef TARGET_STACK_PROTECT_GUARD |
| 838 |
#define TARGET_STACK_PROTECT_GUARD arm_stack_protect_guard |
| 839 |
|
| 840 |
#undef TARGET_VECTORIZE_GET_MASK_MODE |
| 841 |
#define TARGET_VECTORIZE_GET_MASK_MODE arm_get_mask_mode |
| 842 |
|
| 843 |
/* Obstack for minipool constant handling. */ |
| 844 |
static struct obstack minipool_obstack; |
| 845 |
static char * minipool_startobj; |
| 846 |
|
| 847 |
/* The maximum number of insns skipped which |
| 848 |
will be conditionalised if possible. */ |
| 849 |
static int max_insns_skipped = 5; |
| 850 |
|
| 851 |
/* True if we are currently building a constant table. */ |
| 852 |
int making_const_table; |
| 853 |
|
| 854 |
/* The processor for which instructions should be scheduled. */ |
| 855 |
enum processor_type arm_tune = TARGET_CPU_arm_none; |
| 856 |
|
| 857 |
/* The current tuning set. */ |
| 858 |
const struct tune_params *current_tune; |
| 859 |
|
| 860 |
/* Which floating point hardware to schedule for. */ |
| 861 |
int arm_fpu_attr; |
| 862 |
|
| 863 |
/* Used for Thumb call_via trampolines. */ |
| 864 |
rtx thumb_call_via_label[14]; |
| 865 |
static int thumb_call_reg_needed; |
| 866 |
|
| 867 |
/* The bits in this mask specify which instruction scheduling options should |
| 868 |
be used. */ |
| 869 |
unsigned int tune_flags = 0; |
| 870 |
|
| 871 |
/* The highest ARM architecture version supported by the |
| 872 |
target. */ |
| 873 |
enum base_architecture arm_base_arch = BASE_ARCH_0; |
| 874 |
|
| 875 |
/* Active target architecture and tuning. */ |
| 876 |
|
| 877 |
struct arm_build_target arm_active_target; |
| 878 |
|
| 879 |
/* The following are used in the arm.md file as equivalents to bits |
| 880 |
in the above two flag variables. */ |
| 881 |
|
| 882 |
/* Nonzero if this chip supports the ARM Architecture 4 extensions. */ |
| 883 |
int arm_arch4 = 0; |
| 884 |
|
| 885 |
/* Nonzero if this chip supports the ARM Architecture 4t extensions. */ |
| 886 |
int arm_arch4t = 0; |
| 887 |
|
| 888 |
/* Nonzero if this chip supports the ARM Architecture 5T extensions. */ |
| 889 |
int arm_arch5t = 0; |
| 890 |
|
| 891 |
/* Nonzero if this chip supports the ARM Architecture 5TE extensions. */ |
| 892 |
int arm_arch5te = 0; |
| 893 |
|
| 894 |
/* Nonzero if this chip supports the ARM Architecture 6 extensions. */ |
| 895 |
int arm_arch6 = 0; |
| 896 |
|
| 897 |
/* Nonzero if this chip supports the ARM 6K extensions. */ |
| 898 |
int arm_arch6k = 0; |
| 899 |
|
| 900 |
/* Nonzero if this chip supports the ARM 6KZ extensions. */ |
| 901 |
int arm_arch6kz = 0; |
| 902 |
|
| 903 |
/* Nonzero if instructions present in ARMv6-M can be used. */ |
| 904 |
int arm_arch6m = 0; |
| 905 |
|
| 906 |
/* Nonzero if this chip supports the ARM 7 extensions. */ |
| 907 |
int arm_arch7 = 0; |
| 908 |
|
| 909 |
/* Nonzero if this chip supports the Large Physical Address Extension. */ |
| 910 |
int arm_arch_lpae = 0; |
| 911 |
|
| 912 |
/* Nonzero if instructions not present in the 'M' profile can be used. */ |
| 913 |
int arm_arch_notm = 0; |
| 914 |
|
| 915 |
/* Nonzero if instructions present in ARMv7E-M can be used. */ |
| 916 |
int arm_arch7em = 0; |
| 917 |
|
| 918 |
/* Nonzero if instructions present in ARMv8 can be used. */ |
| 919 |
int arm_arch8 = 0; |
| 920 |
|
| 921 |
/* Nonzero if this chip supports the ARMv8.1 extensions. */ |
| 922 |
int arm_arch8_1 = 0; |
| 923 |
|
| 924 |
/* Nonzero if this chip supports the ARM Architecture 8.2 extensions. */ |
| 925 |
int arm_arch8_2 = 0; |
| 926 |
|
| 927 |
/* Nonzero if this chip supports the ARM Architecture 8.3 extensions. */ |
| 928 |
int arm_arch8_3 = 0; |
| 929 |
|
| 930 |
/* Nonzero if this chip supports the ARM Architecture 8.4 extensions. */ |
| 931 |
int arm_arch8_4 = 0; |
| 932 |
|
| 933 |
/* Nonzero if this chip supports the ARM Architecture 8-M Mainline |
| 934 |
extensions. */ |
| 935 |
int arm_arch8m_main = 0; |
| 936 |
|
| 937 |
/* Nonzero if this chip supports the ARM Architecture 8.1-M Mainline |
| 938 |
extensions. */ |
| 939 |
int arm_arch8_1m_main = 0; |
| 940 |
|
| 941 |
/* Nonzero if this chip supports the FP16 instructions extension of ARM |
| 942 |
Architecture 8.2. */ |
| 943 |
int arm_fp16_inst = 0; |
| 944 |
|
| 945 |
/* Nonzero if this chip can benefit from load scheduling. */ |
| 946 |
int arm_ld_sched = 0; |
| 947 |
|
| 948 |
/* Nonzero if this chip is a StrongARM. */ |
| 949 |
int arm_tune_strongarm = 0; |
| 950 |
|
| 951 |
/* Nonzero if this chip supports Intel Wireless MMX technology. */ |
| 952 |
int arm_arch_iwmmxt = 0; |
| 953 |
|
| 954 |
/* Nonzero if this chip supports Intel Wireless MMX2 technology. */ |
| 955 |
int arm_arch_iwmmxt2 = 0; |
| 956 |
|
| 957 |
/* Nonzero if this chip is an XScale. */ |
| 958 |
int arm_arch_xscale = 0; |
| 959 |
|
| 960 |
/* Nonzero if tuning for XScale */ |
| 961 |
int arm_tune_xscale = 0; |
| 962 |
|
| 963 |
/* Nonzero if we want to tune for stores that access the write-buffer. |
| 964 |
This typically means an ARM6 or ARM7 with MMU or MPU. */ |
| 965 |
int arm_tune_wbuf = 0; |
| 966 |
|
| 967 |
/* Nonzero if tuning for Cortex-A9. */ |
| 968 |
int arm_tune_cortex_a9 = 0; |
| 969 |
|
| 970 |
/* Nonzero if we should define __THUMB_INTERWORK__ in the |
| 971 |
preprocessor. |
| 972 |
XXX This is a bit of a hack, it's intended to help work around |
| 973 |
problems in GLD which doesn't understand that armv5t code is |
| 974 |
interworking clean. */ |
| 975 |
int arm_cpp_interwork = 0; |
| 976 |
|
| 977 |
/* Nonzero if chip supports Thumb 1. */ |
| 978 |
int arm_arch_thumb1; |
| 979 |
|
| 980 |
/* Nonzero if chip supports Thumb 2. */ |
| 981 |
int arm_arch_thumb2; |
| 982 |
|
| 983 |
/* Nonzero if chip supports integer division instruction. */ |
| 984 |
int arm_arch_arm_hwdiv; |
| 985 |
int arm_arch_thumb_hwdiv; |
| 986 |
|
| 987 |
/* Nonzero if chip disallows volatile memory access in IT block. */ |
| 988 |
int arm_arch_no_volatile_ce; |
| 989 |
|
| 990 |
/* Nonzero if we shouldn't use literal pools. */ |
| 991 |
bool arm_disable_literal_pool = false; |
| 992 |
|
| 993 |
/* The register number to be used for the PIC offset register. */ |
| 994 |
unsigned arm_pic_register = INVALID_REGNUM; |
| 995 |
|
| 996 |
enum arm_pcs arm_pcs_default; |
| 997 |
|
| 998 |
/* For an explanation of these variables, see final_prescan_insn below. */ |
| 999 |
int arm_ccfsm_state; |
| 1000 |
/* arm_current_cc is also used for Thumb-2 cond_exec blocks. */ |
| 1001 |
enum arm_cond_code arm_current_cc; |
| 1002 |
|
| 1003 |
rtx arm_target_insn; |
| 1004 |
int arm_target_label; |
| 1005 |
/* The number of conditionally executed insns, including the current insn. */ |
| 1006 |
int arm_condexec_count = 0; |
| 1007 |
/* A bitmask specifying the patterns for the IT block. |
| 1008 |
Zero means do not output an IT block before this insn. */ |
| 1009 |
int arm_condexec_mask = 0; |
| 1010 |
/* The number of bits used in arm_condexec_mask. */ |
| 1011 |
int arm_condexec_masklen = 0; |
| 1012 |
|
| 1013 |
/* Nonzero if chip supports the ARMv8 CRC instructions. */ |
| 1014 |
int arm_arch_crc = 0; |
| 1015 |
|
| 1016 |
/* Nonzero if chip supports the AdvSIMD Dot Product instructions. */ |
| 1017 |
int arm_arch_dotprod = 0; |
| 1018 |
|
| 1019 |
/* Nonzero if chip supports the ARMv8-M security extensions. */ |
| 1020 |
int arm_arch_cmse = 0; |
| 1021 |
|
| 1022 |
/* Nonzero if the core has a very small, high-latency, multiply unit. */ |
| 1023 |
int arm_m_profile_small_mul = 0; |
| 1024 |
|
| 1025 |
/* Nonzero if chip supports the AdvSIMD I8MM instructions. */ |
| 1026 |
int arm_arch_i8mm = 0; |
| 1027 |
|
| 1028 |
/* Nonzero if chip supports the BFloat16 instructions. */ |
| 1029 |
int arm_arch_bf16 = 0; |
| 1030 |
|
| 1031 |
/* Nonzero if chip supports the Custom Datapath Extension. */ |
| 1032 |
int arm_arch_cde = 0; |
| 1033 |
int arm_arch_cde_coproc = 0; |
| 1034 |
const int arm_arch_cde_coproc_bits[] = { |
| 1035 |
0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 |
| 1036 |
}; |
| 1037 |
|
| 1038 |
/* The condition codes of the ARM, and the inverse function. */ |
| 1039 |
static const char * const arm_condition_codes[] = |
| 1040 |
{ |
| 1041 |
"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc", |
| 1042 |
"hi", "ls", "ge", "lt", "gt", "le", "al", "nv" |
| 1043 |
}; |
| 1044 |
|
| 1045 |
/* The register numbers in sequence, for passing to arm_gen_load_multiple. */ |
| 1046 |
int arm_regs_in_sequence[] = |
| 1047 |
{ |
| 1048 |
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 |
| 1049 |
}; |
| 1050 |
|
| 1051 |
#define DEF_FP_SYSREG(reg) #reg, |
| 1052 |
const char *fp_sysreg_names[NB_FP_SYSREGS] = { |
| 1053 |
FP_SYSREGS |
| 1054 |
}; |
| 1055 |
#undef DEF_FP_SYSREG |
| 1056 |
|
| 1057 |
#define ARM_LSL_NAME "lsl" |
| 1058 |
#define streq(string1, string2) (strcmp (string1, string2) == 0) |
| 1059 |
|
| 1060 |
#define THUMB2_WORK_REGS \ |
| 1061 |
(0xff & ~((1 << THUMB_HARD_FRAME_POINTER_REGNUM) \ |
| 1062 |
| (1 << SP_REGNUM) \ |
| 1063 |
| (1 << PC_REGNUM) \ |
| 1064 |
| (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM \ |
| 1065 |
? (1 << PIC_OFFSET_TABLE_REGNUM) \ |
| 1066 |
: 0))) |
| 1067 |
|
| 1068 |
/* Initialization code. */ |
| 1069 |
|
| 1070 |
struct cpu_tune |
| 1071 |
{ |
| 1072 |
enum processor_type scheduler; |
| 1073 |
unsigned int tune_flags; |
| 1074 |
const struct tune_params *tune; |
| 1075 |
}; |
| 1076 |
|
| 1077 |
#define ARM_PREFETCH_NOT_BENEFICIAL { 0, -1, -1 } |
| 1078 |
#define ARM_PREFETCH_BENEFICIAL(num_slots,l1_size,l1_line_size) \ |
| 1079 |
{ \ |
| 1080 |
num_slots, \ |
| 1081 |
l1_size, \ |
| 1082 |
l1_line_size \ |
| 1083 |
} |
| 1084 |
|
| 1085 |
/* arm generic vectorizer costs. */ |
| 1086 |
static const |
| 1087 |
struct cpu_vec_costs arm_default_vec_cost = { |
| 1088 |
1, /* scalar_stmt_cost. */ |
| 1089 |
1, /* scalar load_cost. */ |
| 1090 |
1, /* scalar_store_cost. */ |
| 1091 |
1, /* vec_stmt_cost. */ |
| 1092 |
1, /* vec_to_scalar_cost. */ |
| 1093 |
1, /* scalar_to_vec_cost. */ |
| 1094 |
1, /* vec_align_load_cost. */ |
| 1095 |
1, /* vec_unalign_load_cost. */ |
| 1096 |
1, /* vec_unalign_store_cost. */ |
| 1097 |
1, /* vec_store_cost. */ |
| 1098 |
3, /* cond_taken_branch_cost. */ |
| 1099 |
1, /* cond_not_taken_branch_cost. */ |
| 1100 |
}; |
| 1101 |
|
| 1102 |
/* Cost tables for AArch32 + AArch64 cores should go in aarch-cost-tables.h */ |
| 1103 |
#include "aarch-cost-tables.h" |
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
const struct cpu_cost_table cortexa9_extra_costs = |
| 1108 |
{ |
| 1109 |
/* ALU */ |
| 1110 |
{ |
| 1111 |
0, /* arith. */ |
| 1112 |
0, /* logical. */ |
| 1113 |
0, /* shift. */ |
| 1114 |
COSTS_N_INSNS (1), /* shift_reg. */ |
| 1115 |
COSTS_N_INSNS (1), /* arith_shift. */ |
| 1116 |
COSTS_N_INSNS (2), /* arith_shift_reg. */ |
| 1117 |
0, /* log_shift. */ |
| 1118 |
COSTS_N_INSNS (1), /* log_shift_reg. */ |
| 1119 |
COSTS_N_INSNS (1), /* extend. */ |
| 1120 |
COSTS_N_INSNS (2), /* extend_arith. */ |
| 1121 |
COSTS_N_INSNS (1), /* bfi. */ |
| 1122 |
COSTS_N_INSNS (1), /* bfx. */ |
| 1123 |
0, /* clz. */ |
| 1124 |
0, /* rev. */ |
| 1125 |
0, /* non_exec. */ |
| 1126 |
true /* non_exec_costs_exec. */ |
| 1127 |
}, |
| 1128 |
{ |
| 1129 |
/* MULT SImode */ |
| 1130 |
{ |
| 1131 |
COSTS_N_INSNS (3), /* simple. */ |
| 1132 |
COSTS_N_INSNS (3), /* flag_setting. */ |
| 1133 |
COSTS_N_INSNS (2), /* extend. */ |
| 1134 |
COSTS_N_INSNS (3), /* add. */ |
| 1135 |
COSTS_N_INSNS (2), /* extend_add. */ |
| 1136 |
COSTS_N_INSNS (30) /* idiv. No HW div on Cortex A9. */ |
| 1137 |
}, |
| 1138 |
/* MULT DImode */ |
| 1139 |
{ |
| 1140 |
0, /* simple (N/A). */ |
| 1141 |
0, /* flag_setting (N/A). */ |
| 1142 |
COSTS_N_INSNS (4), /* extend. */ |
| 1143 |
0, /* add (N/A). */ |
| 1144 |
COSTS_N_INSNS (4), /* extend_add. */ |
| 1145 |
0 /* idiv (N/A). */ |
| 1146 |
} |
| 1147 |
}, |
| 1148 |
/* LD/ST */ |
| 1149 |
{ |
| 1150 |
COSTS_N_INSNS (2), /* load. */ |
| 1151 |
COSTS_N_INSNS (2), /* load_sign_extend. */ |
| 1152 |
COSTS_N_INSNS (2), /* ldrd. */ |
| 1153 |
COSTS_N_INSNS (2), /* ldm_1st. */ |
| 1154 |
1, /* ldm_regs_per_insn_1st. */ |
| 1155 |
2, /* ldm_regs_per_insn_subsequent. */ |
| 1156 |
COSTS_N_INSNS (5), /* loadf. */ |
| 1157 |
COSTS_N_INSNS (5), /* loadd. */ |
| 1158 |
COSTS_N_INSNS (1), /* load_unaligned. */ |
| 1159 |
COSTS_N_INSNS (2), /* store. */ |
| 1160 |
COSTS_N_INSNS (2), /* strd. */ |
| 1161 |
COSTS_N_INSNS (2), /* stm_1st. */ |
| 1162 |
1, /* stm_regs_per_insn_1st. */ |
| 1163 |
2, /* stm_regs_per_insn_subsequent. */ |
| 1164 |
COSTS_N_INSNS (1), /* storef. */ |
| 1165 |
COSTS_N_INSNS (1), /* stored. */ |
| 1166 |
COSTS_N_INSNS (1), /* store_unaligned. */ |
| 1167 |
COSTS_N_INSNS (1), /* loadv. */ |
| 1168 |
COSTS_N_INSNS (1) /* storev. */ |
| 1169 |
}, |
| 1170 |
{ |
| 1171 |
/* FP SFmode */ |
| 1172 |
{ |
| 1173 |
COSTS_N_INSNS (14), /* div. */ |
| 1174 |
COSTS_N_INSNS (4), /* mult. */ |
| 1175 |
COSTS_N_INSNS (7), /* mult_addsub. */ |
| 1176 |
COSTS_N_INSNS (30), /* fma. */ |
| 1177 |
COSTS_N_INSNS (3), /* addsub. */ |
| 1178 |
COSTS_N_INSNS (1), /* fpconst. */ |
| 1179 |
COSTS_N_INSNS (1), /* neg. */ |
| 1180 |
COSTS_N_INSNS (3), /* compare. */ |
| 1181 |
COSTS_N_INSNS (3), /* widen. */ |
| 1182 |
COSTS_N_INSNS (3), /* narrow. */ |
| 1183 |
COSTS_N_INSNS (3), /* toint. */ |
| 1184 |
COSTS_N_INSNS (3), /* fromint. */ |
| 1185 |
COSTS_N_INSNS (3) /* roundint. */ |
| 1186 |
}, |
| 1187 |
/* FP DFmode */ |
| 1188 |
{ |
| 1189 |
COSTS_N_INSNS (24), /* div. */ |
| 1190 |
COSTS_N_INSNS (5), /* mult. */ |
| 1191 |
COSTS_N_INSNS (8), /* mult_addsub. */ |
| 1192 |
COSTS_N_INSNS (30), /* fma. */ |
| 1193 |
COSTS_N_INSNS (3), /* addsub. */ |
| 1194 |
COSTS_N_INSNS (1), /* fpconst. */ |
| 1195 |
COSTS_N_INSNS (1), /* neg. */ |
| 1196 |
COSTS_N_INSNS (3), /* compare. */ |
| 1197 |
COSTS_N_INSNS (3), /* widen. */ |
| 1198 |
COSTS_N_INSNS (3), /* narrow. */ |
| 1199 |
COSTS_N_INSNS (3), /* toint. */ |
| 1200 |
COSTS_N_INSNS (3), /* fromint. */ |
| 1201 |
COSTS_N_INSNS (3) /* roundint. */ |
| 1202 |
} |
| 1203 |
}, |
| 1204 |
/* Vector */ |
| 1205 |
{ |
| 1206 |
COSTS_N_INSNS (1), /* alu. */ |
| 1207 |
COSTS_N_INSNS (4), /* mult. */ |
| 1208 |
COSTS_N_INSNS (1), /* movi. */ |
| 1209 |
COSTS_N_INSNS (2), /* dup. */ |
| 1210 |
COSTS_N_INSNS (2) /* extract. */ |
| 1211 |
} |
| 1212 |
}; |
| 1213 |
|
| 1214 |
const struct cpu_cost_table cortexa8_extra_costs = |
| 1215 |
{ |
| 1216 |
/* ALU */ |
| 1217 |
{ |
| 1218 |
0, /* arith. */ |
| 1219 |
0, /* logical. */ |
| 1220 |
COSTS_N_INSNS (1), /* shift. */ |
| 1221 |
0, /* shift_reg. */ |
| 1222 |
COSTS_N_INSNS (1), /* arith_shift. */ |
| 1223 |
0, /* arith_shift_reg. */ |
| 1224 |
COSTS_N_INSNS (1), /* log_shift. */ |
| 1225 |
0, /* log_shift_reg. */ |
| 1226 |
0, /* extend. */ |
| 1227 |
0, /* extend_arith. */ |
| 1228 |
0, /* bfi. */ |
| 1229 |
0, /* bfx. */ |
| 1230 |
0, /* clz. */ |
| 1231 |
0, /* rev. */ |
| 1232 |
0, /* non_exec. */ |
| 1233 |
true /* non_exec_costs_exec. */ |
| 1234 |
}, |
| 1235 |
{ |
| 1236 |
/* MULT SImode */ |
| 1237 |
{ |
| 1238 |
COSTS_N_INSNS (1), /* simple. */ |
| 1239 |
COSTS_N_INSNS (1), /* flag_setting. */ |
| 1240 |
COSTS_N_INSNS (1), /* extend. */ |
| 1241 |
COSTS_N_INSNS (1), /* add. */ |
| 1242 |
COSTS_N_INSNS (1), /* extend_add. */ |
| 1243 |
COSTS_N_INSNS (30) /* idiv. No HW div on Cortex A8. */ |
| 1244 |
}, |
| 1245 |
/* MULT DImode */ |
| 1246 |
{ |
| 1247 |
0, /* simple (N/A). */ |
| 1248 |
0, /* flag_setting (N/A). */ |
| 1249 |
COSTS_N_INSNS (2), /* extend. */ |
| 1250 |
0, /* add (N/A). */ |
| 1251 |
COSTS_N_INSNS (2), /* extend_add. */ |
| 1252 |
0 /* idiv (N/A). */ |
| 1253 |
} |
| 1254 |
}, |
| 1255 |
/* LD/ST */ |
| 1256 |
{ |
| 1257 |
COSTS_N_INSNS (1), /* load. */ |
| 1258 |
COSTS_N_INSNS (1), /* load_sign_extend. */ |
| 1259 |
COSTS_N_INSNS (1), /* ldrd. */ |
| 1260 |
COSTS_N_INSNS (1), /* ldm_1st. */ |
| 1261 |
1, /* ldm_regs_per_insn_1st. */ |
| 1262 |
2, /* ldm_regs_per_insn_subsequent. */ |
| 1263 |
COSTS_N_INSNS (1), /* loadf. */ |
| 1264 |
COSTS_N_INSNS (1), /* loadd. */ |
| 1265 |
COSTS_N_INSNS (1), /* load_unaligned. */ |
| 1266 |
COSTS_N_INSNS (1), /* store. */ |
| 1267 |
COSTS_N_INSNS (1), /* strd. */ |
| 1268 |
COSTS_N_INSNS (1), /* stm_1st. */ |
| 1269 |
1, /* stm_regs_per_insn_1st. */ |
| 1270 |
2, /* stm_regs_per_insn_subsequent. */ |
| 1271 |
COSTS_N_INSNS (1), /* storef. */ |
| 1272 |
COSTS_N_INSNS (1), /* stored. */ |
| 1273 |
COSTS_N_INSNS (1), /* store_unaligned. */ |
| 1274 |
COSTS_N_INSNS (1), /* loadv. */ |
| 1275 |
COSTS_N_INSNS (1) /* storev. */ |
| 1276 |
}, |
| 1277 |
{ |
| 1278 |
/* FP SFmode */ |
| 1279 |
{ |
| 1280 |
COSTS_N_INSNS (36), /* div. */ |
| 1281 |
COSTS_N_INSNS (11), /* mult. */ |
| 1282 |
COSTS_N_INSNS (20), /* mult_addsub. */ |
| 1283 |
COSTS_N_INSNS (30), /* fma. */ |
| 1284 |
COSTS_N_INSNS (9), /* addsub. */ |
| 1285 |
COSTS_N_INSNS (3), /* fpconst. */ |
| 1286 |
COSTS_N_INSNS (3), /* neg. */ |
| 1287 |
COSTS_N_INSNS (6), /* compare. */ |
| 1288 |
COSTS_N_INSNS (4), /* widen. */ |
| 1289 |
COSTS_N_INSNS (4), /* narrow. */ |
| 1290 |
COSTS_N_INSNS (8), /* toint. */ |
| 1291 |
COSTS_N_INSNS (8), /* fromint. */ |
| 1292 |
COSTS_N_INSNS (8) /* roundint. */ |
| 1293 |
}, |
| 1294 |
/* FP DFmode */ |
| 1295 |
{ |
| 1296 |
COSTS_N_INSNS (64), /* div. */ |
| 1297 |
COSTS_N_INSNS (16), /* mult. */ |
| 1298 |
COSTS_N_INSNS (25), /* mult_addsub. */ |
| 1299 |
COSTS_N_INSNS (30), /* fma. */ |
| 1300 |
COSTS_N_INSNS (9), /* addsub. */ |
| 1301 |
COSTS_N_INSNS (3), /* fpconst. */ |
| 1302 |
COSTS_N_INSNS (3), /* neg. */ |
| 1303 |
COSTS_N_INSNS (6), /* compare. */ |
| 1304 |
COSTS_N_INSNS (6), /* widen. */ |
| 1305 |
COSTS_N_INSNS (6), /* narrow. */ |
| 1306 |
COSTS_N_INSNS (8), /* toint. */ |
| 1307 |
COSTS_N_INSNS (8), /* fromint. */ |
| 1308 |
COSTS_N_INSNS (8) /* roundint. */ |
| 1309 |
} |
| 1310 |
}, |
| 1311 |
/* Vector */ |
| 1312 |
{ |
| 1313 |
COSTS_N_INSNS (1), /* alu. */ |
| 1314 |
COSTS_N_INSNS (4), /* mult. */ |
| 1315 |
COSTS_N_INSNS (1), /* movi. */ |
| 1316 |
COSTS_N_INSNS (2), /* dup. */ |
| 1317 |
COSTS_N_INSNS (2) /* extract. */ |
| 1318 |
} |
| 1319 |
}; |
| 1320 |
|
| 1321 |
const struct cpu_cost_table cortexa5_extra_costs = |
| 1322 |
{ |
| 1323 |
/* ALU */ |
| 1324 |
{ |
| 1325 |
0, /* arith. */ |
| 1326 |
0, /* logical. */ |
| 1327 |
COSTS_N_INSNS (1), /* shift. */ |
| 1328 |
COSTS_N_INSNS (1), /* shift_reg. */ |
| 1329 |
COSTS_N_INSNS (1), /* arith_shift. */ |
| 1330 |
COSTS_N_INSNS (1), /* arith_shift_reg. */ |
| 1331 |
COSTS_N_INSNS (1), /* log_shift. */ |
| 1332 |
COSTS_N_INSNS (1), /* log_shift_reg. */ |
| 1333 |
COSTS_N_INSNS (1), /* extend. */ |
| 1334 |
COSTS_N_INSNS (1), /* extend_arith. */ |
| 1335 |
COSTS_N_INSNS (1), /* bfi. */ |
| 1336 |
COSTS_N_INSNS (1), /* bfx. */ |
| 1337 |
COSTS_N_INSNS (1), /* clz. */ |
| 1338 |
COSTS_N_INSNS (1), /* rev. */ |
| 1339 |
0, /* non_exec. */ |
| 1340 |
true /* non_exec_costs_exec. */ |
| 1341 |
}, |
| 1342 |
|
| 1343 |
{ |
| 1344 |
/* MULT SImode */ |
| 1345 |
{ |
| 1346 |
0, /* simple. */ |
| 1347 |
COSTS_N_INSNS (1), /* flag_setting. */ |
| 1348 |
COSTS_N_INSNS (1), /* extend. */ |
| 1349 |
COSTS_N_INSNS (1), /* add. */ |
| 1350 |
COSTS_N_INSNS (1), /* extend_add. */ |
| 1351 |
COSTS_N_INSNS (7) /* idiv. */ |
| 1352 |
}, |
| 1353 |
/* MULT DImode */ |
| 1354 |
{ |
| 1355 |
0, /* simple (N/A). */ |
| 1356 |
0, /* flag_setting (N/A). */ |
| 1357 |
COSTS_N_INSNS (1), /* extend. */ |
| 1358 |
0, /* add. */ |
| 1359 |
COSTS_N_INSNS (2), /* extend_add. */ |
| 1360 |
0 /* idiv (N/A). */ |
| 1361 |
} |
| 1362 |
}, |
| 1363 |
/* LD/ST */ |
| 1364 |
{ |
| 1365 |
COSTS_N_INSNS (1), /* load. */ |
| 1366 |
COSTS_N_INSNS (1), /* load_sign_extend. */ |
| 1367 |
COSTS_N_INSNS (6), /* ldrd. */ |
| 1368 |
COSTS_N_INSNS (1), /* ldm_1st. */ |
| 1369 |
1, /* ldm_regs_per_insn_1st. */ |
| 1370 |
2, /* ldm_regs_per_insn_subsequent. */ |
| 1371 |
COSTS_N_INSNS (2), /* loadf. */ |
| 1372 |
COSTS_N_INSNS (4), /* loadd. */ |
| 1373 |
COSTS_N_INSNS (1), /* load_unaligned. */ |
| 1374 |
COSTS_N_INSNS (1), /* store. */ |
| 1375 |
COSTS_N_INSNS (3), /* strd. */ |
| 1376 |
COSTS_N_INSNS (1), /* stm_1st. */ |
| 1377 |
1, /* stm_regs_per_insn_1st. */ |
| 1378 |
2, /* stm_regs_per_insn_subsequent. */ |
| 1379 |
COSTS_N_INSNS (2), /* storef. */ |
| 1380 |
COSTS_N_INSNS (2), /* stored. */ |
| 1381 |
COSTS_N_INSNS (1), /* store_unaligned. */ |
| 1382 |
COSTS_N_INSNS (1), /* loadv. */ |
| 1383 |
COSTS_N_INSNS (1) /* storev. */ |
| 1384 |
}, |
| 1385 |
{ |
| 1386 |
/* FP SFmode */ |
| 1387 |
{ |
| 1388 |
COSTS_N_INSNS (15), /* div. */ |
| 1389 |
COSTS_N_INSNS (3), /* mult. */ |
| 1390 |
COSTS_N_INSNS (7), /* mult_addsub. */ |
| 1391 |
COSTS_N_INSNS (7), /* fma. */ |
| 1392 |
COSTS_N_INSNS (3), /* addsub. */ |
| 1393 |
COSTS_N_INSNS (3), /* fpconst. */ |
| 1394 |
COSTS_N_INSNS (3), /* neg. */ |
| 1395 |
COSTS_N_INSNS (3), /* compare. */ |
| 1396 |
COSTS_N_INSNS (3), /* widen. */ |
| 1397 |
COSTS_N_INSNS (3), /* narrow. */ |
| 1398 |
COSTS_N_INSNS (3), /* toint. */ |
| 1399 |
COSTS_N_INSNS (3), /* fromint. */ |
| 1400 |
COSTS_N_INSNS (3) /* roundint. */ |
| 1401 |
}, |
| 1402 |
/* FP DFmode */ |
| 1403 |
{ |
| 1404 |
COSTS_N_INSNS (30), /* div. */ |
| 1405 |
COSTS_N_INSNS (6), /* mult. */ |
| 1406 |
COSTS_N_INSNS (10), /* mult_addsub. */ |
| 1407 |
COSTS_N_INSNS (7), /* fma. */ |
| 1408 |
COSTS_N_INSNS (3), /* addsub. */ |
| 1409 |
COSTS_N_INSNS (3), /* fpconst. */ |
| 1410 |
COSTS_N_INSNS (3), /* neg. */ |
| 1411 |
COSTS_N_INSNS (3), /* compare. */ |
| 1412 |
COSTS_N_INSNS (3), /* widen. */ |
| 1413 |
COSTS_N_INSNS (3), /* narrow. */ |
| 1414 |
COSTS_N_INSNS (3), /* toint. */ |
| 1415 |
COSTS_N_INSNS (3), /* fromint. */ |
| 1416 |
COSTS_N_INSNS (3) /* roundint. */ |
| 1417 |
} |
| 1418 |
}, |
| 1419 |
/* Vector */ |
| 1420 |
{ |
| 1421 |
COSTS_N_INSNS (1), /* alu. */ |
| 1422 |
COSTS_N_INSNS (4), /* mult. */ |
| 1423 |
COSTS_N_INSNS (1), /* movi. */ |
| 1424 |
COSTS_N_INSNS (2), /* dup. */ |
| 1425 |
COSTS_N_INSNS (2) /* extract. */ |
| 1426 |
} |
| 1427 |
}; |
| 1428 |
|
| 1429 |
|
| 1430 |
const struct cpu_cost_table cortexa7_extra_costs = |
| 1431 |
{ |
| 1432 |
/* ALU */ |
| 1433 |
{ |
| 1434 |
0, /* arith. */ |
| 1435 |
0, /* logical. */ |
| 1436 |
COSTS_N_INSNS (1), /* shift. */ |
| 1437 |
COSTS_N_INSNS (1), /* shift_reg. */ |
| 1438 |
COSTS_N_INSNS (1), /* arith_shift. */ |
| 1439 |
COSTS_N_INSNS (1), /* arith_shift_reg. */ |
| 1440 |
COSTS_N_INSNS (1), /* log_shift. */ |
| 1441 |
COSTS_N_INSNS (1), /* log_shift_reg. */ |
| 1442 |
COSTS_N_INSNS (1), /* extend. */ |
| 1443 |
COSTS_N_INSNS (1), /* extend_arith. */ |
| 1444 |
COSTS_N_INSNS (1), /* bfi. */ |
| 1445 |
COSTS_N_INSNS (1), /* bfx. */ |
| 1446 |
COSTS_N_INSNS (1), /* clz. */ |
| 1447 |
COSTS_N_INSNS (1), /* rev. */ |
| 1448 |
0, /* non_exec. */ |
| 1449 |
true /* non_exec_costs_exec. */ |
| 1450 |
}, |
| 1451 |
|
| 1452 |
{ |
| 1453 |
/* MULT SImode */ |
| 1454 |
{ |
| 1455 |
0, /* simple. */ |
| 1456 |
COSTS_N_INSNS (1), /* flag_setting. */ |
| 1457 |
COSTS_N_INSNS (1), /* extend. */ |
| 1458 |
COSTS_N_INSNS (1), /* add. */ |
| 1459 |
COSTS_N_INSNS (1), /* extend_add. */ |
| 1460 |
COSTS_N_INSNS (7) /* idiv. */ |
| 1461 |
}, |
| 1462 |
/* MULT DImode */ |
| 1463 |
{ |
| 1464 |
0, /* simple (N/A). */ |
| 1465 |
0, /* flag_setting (N/A). */ |
| 1466 |
COSTS_N_INSNS (1), /* extend. */ |
| 1467 |
0, /* add. */ |
| 1468 |
COSTS_N_INSNS (2), /* extend_add. */ |
| 1469 |
0 /* idiv (N/A). */ |
| 1470 |
} |
| 1471 |
}, |
| 1472 |
/* LD/ST */ |
| 1473 |
{ |
| 1474 |
COSTS_N_INSNS (1), /* load. */ |
| 1475 |
COSTS_N_INSNS (1), /* load_sign_extend. */ |
| 1476 |
COSTS_N_INSNS (3), /* ldrd. */ |
| 1477 |
COSTS_N_INSNS (1), /* ldm_1st. */ |
| 1478 |
1, /* ldm_regs_per_insn_1st. */ |
| 1479 |
2, /* ldm_regs_per_insn_subsequent. */ |
| 1480 |
COSTS_N_INSNS (2), /* loadf. */ |
| 1481 |
COSTS_N_INSNS (2), /* loadd. */ |
| 1482 |
COSTS_N_INSNS (1), /* load_unaligned. */ |
| 1483 |
COSTS_N_INSNS (1), /* store. */ |
| 1484 |
COSTS_N_INSNS (3), /* strd. */ |
| 1485 |
COSTS_N_INSNS (1), /* stm_1st. */ |
| 1486 |
1, /* stm_regs_per_insn_1st. */ |
| 1487 |
2, /* stm_regs_per_insn_subsequent. */ |
| 1488 |
COSTS_N_INSNS (2), /* storef. */ |
| 1489 |
COSTS_N_INSNS (2), /* stored. */ |
| 1490 |
COSTS_N_INSNS (1), /* store_unaligned. */ |
| 1491 |
COSTS_N_INSNS (1), /* loadv. */ |
| 1492 |
COSTS_N_INSNS (1) /* storev. */ |
| 1493 |
}, |
| 1494 |
{ |
| 1495 |
/* FP SFmode */ |
| 1496 |
{ |
| 1497 |
COSTS_N_INSNS (15), /* div. */ |
| 1498 |
COSTS_N_INSNS (3), /* mult. */ |
| 1499 |
COSTS_N_INSNS (7), /* mult_addsub. */ |
| 1500 |
COSTS_N_INSNS (7), /* fma. */ |
| 1501 |
COSTS_N_INSNS (3), /* addsub. */ |
| 1502 |
COSTS_N_INSNS (3), /* fpconst. */ |
| 1503 |
COSTS_N_INSNS (3), /* neg. */ |
| 1504 |
COSTS_N_INSNS (3), /* compare. */ |
| 1505 |
COSTS_N_INSNS (3), /* widen. */ |
| 1506 |
COSTS_N_INSNS (3), /* narrow. */ |
| 1507 |
COSTS_N_INSNS (3), /* toint. */ |
| 1508 |
COSTS_N_INSNS (3), /* fromint. */ |
| 1509 |
COSTS_N_INSNS (3) /* roundint. */ |
| 1510 |
}, |
| 1511 |
/* FP DFmode */ |
| 1512 |
{ |
| 1513 |
COSTS_N_INSNS (30), /* div. */ |
| 1514 |
COSTS_N_INSNS (6), /* mult. */ |
| 1515 |
COSTS_N_INSNS (10), /* mult_addsub. */ |
| 1516 |
COSTS_N_INSNS (7), /* fma. */ |
| 1517 |
COSTS_N_INSNS (3), /* addsub. */ |
| 1518 |
COSTS_N_INSNS (3), /* fpconst. */ |
| 1519 |
COSTS_N_INSNS (3), /* neg. */ |
| 1520 |
COSTS_N_INSNS (3), /* compare. */ |
| 1521 |
COSTS_N_INSNS (3), /* widen. */ |
| 1522 |
COSTS_N_INSNS (3), /* narrow. */ |
| 1523 |
COSTS_N_INSNS (3), /* toint. */ |
| 1524 |
COSTS_N_INSNS (3), /* fromint. */ |
| 1525 |
COSTS_N_INSNS (3) /* roundint. */ |
| 1526 |
} |
| 1527 |
}, |
| 1528 |
/* Vector */ |
| 1529 |
{ |
| 1530 |
COSTS_N_INSNS (1), /* alu. */ |
| 1531 |
COSTS_N_INSNS (4), /* mult. */ |
| 1532 |
COSTS_N_INSNS (1), /* movi. */ |
| 1533 |
COSTS_N_INSNS (2), /* dup. */ |
| 1534 |
COSTS_N_INSNS (2) /* extract. */ |
| 1535 |
} |
| 1536 |
}; |
| 1537 |
|
| 1538 |
const struct cpu_cost_table cortexa12_extra_costs = |
| 1539 |
{ |
| 1540 |
/* ALU */ |
| 1541 |
{ |
| 1542 |
0, /* arith. */ |
| 1543 |
0, /* logical. */ |
| 1544 |
0, /* shift. */ |
| 1545 |
COSTS_N_INSNS (1), /* shift_reg. */ |
| 1546 |
COSTS_N_INSNS (1), /* arith_shift. */ |
| 1547 |
COSTS_N_INSNS (1), /* arith_shift_reg. */ |
| 1548 |
COSTS_N_INSNS (1), /* log_shift. */ |
| 1549 |
COSTS_N_INSNS (1), /* log_shift_reg. */ |
| 1550 |
0, /* extend. */ |
| 1551 |
COSTS_N_INSNS (1), /* extend_arith. */ |
| 1552 |
0, /* bfi. */ |
| 1553 |
COSTS_N_INSNS (1), /* bfx. */ |
| 1554 |
COSTS_N_INSNS (1), /* clz. */ |
| 1555 |
COSTS_N_INSNS (1), /* rev. */ |
| 1556 |
0, /* non_exec. */ |
| 1557 |
true /* non_exec_costs_exec. */ |
| 1558 |
}, |
| 1559 |
/* MULT SImode */ |
| 1560 |
{ |
| 1561 |
{ |
| 1562 |
COSTS_N_INSNS (2), /* simple. */ |
| 1563 |
COSTS_N_INSNS (3), /* flag_setting. */ |
| 1564 |
COSTS_N_INSNS (2), /* extend. */ |
| 1565 |
COSTS_N_INSNS (3), /* add. */ |
| 1566 |
COSTS_N_INSNS (2), /* extend_add. */ |
| 1567 |
COSTS_N_INSNS (18) /* idiv. */ |
| 1568 |
}, |
| 1569 |
/* MULT DImode */ |
| 1570 |
{ |
| 1571 |
0, /* simple (N/A). */ |
| 1572 |
0, /* flag_setting (N/A). */ |
| 1573 |
COSTS_N_INSNS (3), /* extend. */ |
| 1574 |
0, /* add (N/A). */ |
| 1575 |
COSTS_N_INSNS (3), /* extend_add. */ |
| 1576 |
0 /* idiv (N/A). */ |
| 1577 |
} |
| 1578 |
}, |
| 1579 |
/* LD/ST */ |
| 1580 |
{ |
| 1581 |
COSTS_N_INSNS (3), /* load. */ |
| 1582 |
COSTS_N_INSNS (3), /* load_sign_extend. */ |
| 1583 |
COSTS_N_INSNS (3), /* ldrd. */ |
| 1584 |
COSTS_N_INSNS (3), /* ldm_1st. */ |
| 1585 |
1, /* ldm_regs_per_insn_1st. */ |
| 1586 |
2, /* ldm_regs_per_insn_subsequent. */ |
| 1587 |
COSTS_N_INSNS (3), /* loadf. */ |
| 1588 |
COSTS_N_INSNS (3), /* loadd. */ |
| 1589 |
0, /* load_unaligned. */ |
| 1590 |
0, /* store. */ |
| 1591 |
0, /* strd. */ |
| 1592 |
0, /* stm_1st. */ |
| 1593 |
1, /* stm_regs_per_insn_1st. */ |
| 1594 |
2, /* stm_regs_per_insn_subsequent. */ |
| 1595 |
COSTS_N_INSNS (2), /* storef. */ |
| 1596 |
COSTS_N_INSNS (2), /* stored. */ |
| 1597 |
0, /* store_unaligned. */ |
| 1598 |
COSTS_N_INSNS (1), /* loadv. */ |
| 1599 |
COSTS_N_INSNS (1) /* storev. */ |
| 1600 |
}, |
| 1601 |
{ |
| 1602 |
/* FP SFmode */ |
| 1603 |
{ |
| 1604 |
COSTS_N_INSNS (17), /* div. */ |
| 1605 |
COSTS_N_INSNS (4), /* mult. */ |
| 1606 |
COSTS_N_INSNS (8), /* mult_addsub. */ |
| 1607 |
COSTS_N_INSNS (8), /* fma. */ |
| 1608 |
COSTS_N_INSNS (4), /* addsub. */ |
| 1609 |
COSTS_N_INSNS (2), /* fpconst. */ |
| 1610 |
COSTS_N_INSNS (2), /* neg. */ |
| 1611 |
COSTS_N_INSNS (2), /* compare. */ |
| 1612 |
COSTS_N_INSNS (4), /* widen. */ |
| 1613 |
COSTS_N_INSNS (4), /* narrow. */ |
| 1614 |
COSTS_N_INSNS (4), /* toint. */ |
| 1615 |
COSTS_N_INSNS (4), /* fromint. */ |
| 1616 |
COSTS_N_INSNS (4) /* roundint. */ |
| 1617 |
}, |
| 1618 |
/* FP DFmode */ |
| 1619 |
{ |
| 1620 |
COSTS_N_INSNS (31), /* div. */ |
| 1621 |
COSTS_N_INSNS (4), /* mult. */ |
| 1622 |
COSTS_N_INSNS (8), /* mult_addsub. */ |
| 1623 |
COSTS_N_INSNS (8), /* fma. */ |
| 1624 |
COSTS_N_INSNS (4), /* addsub. */ |
| 1625 |
COSTS_N_INSNS (2), /* fpconst. */ |
| 1626 |
COSTS_N_INSNS (2), /* neg. */ |
| 1627 |
COSTS_N_INSNS (2), /* compare. */ |
| 1628 |
COSTS_N_INSNS (4), /* widen. */ |
| 1629 |
COSTS_N_INSNS (4), /* narrow. */ |
| 1630 |
COSTS_N_INSNS (4), /* toint. */ |
| 1631 |
COSTS_N_INSNS (4), /* fromint. */ |
| 1632 |
COSTS_N_INSNS (4) /* roundint. */ |
| 1633 |
} |
| 1634 |
}, |
| 1635 |
/* Vector */ |
| 1636 |
{ |
| 1637 |
COSTS_N_INSNS (1), /* alu. */ |
| 1638 |
COSTS_N_INSNS (4), /* mult. */ |
| 1639 |
COSTS_N_INSNS (1), /* movi. */ |
| 1640 |
COSTS_N_INSNS (2), /* dup. */ |
| 1641 |
COSTS_N_INSNS (2) /* extract. */ |
| 1642 |
} |
| 1643 |
}; |
| 1644 |
|
| 1645 |
const struct cpu_cost_table cortexa15_extra_costs = |
| 1646 |
{ |
| 1647 |
/* ALU */ |
| 1648 |
{ |
| 1649 |
0, /* arith. */ |
| 1650 |
0, /* logical. */ |
| 1651 |
0, /* shift. */ |
| 1652 |
0, /* shift_reg. */ |
| 1653 |
COSTS_N_INSNS (1), /* arith_shift. */ |
| 1654 |
COSTS_N_INSNS (1), /* arith_shift_reg. */ |
| 1655 |
COSTS_N_INSNS (1), /* log_shift. */ |
| 1656 |
COSTS_N_INSNS (1), /* log_shift_reg. */ |
| 1657 |
0, /* extend. */ |
| 1658 |
COSTS_N_INSNS (1), /* extend_arith. */ |
| 1659 |
COSTS_N_INSNS (1), /* bfi. */ |
| 1660 |
0, /* bfx. */ |
| 1661 |
0, /* clz. */ |
| 1662 |
0, /* rev. */ |
| 1663 |
0, /* non_exec. */ |
| 1664 |
true /* non_exec_costs_exec. */ |
| 1665 |
}, |
| 1666 |
/* MULT SImode */ |
| 1667 |
{ |
| 1668 |
{ |
| 1669 |
COSTS_N_INSNS (2), /* simple. */ |
| 1670 |
COSTS_N_INSNS (3), /* flag_setting. */ |
| 1671 |
COSTS_N_INSNS (2), /* extend. */ |
| 1672 |
COSTS_N_INSNS (2), /* add. */ |
| 1673 |
COSTS_N_INSNS (2), /* extend_add. */ |
| 1674 |
COSTS_N_INSNS (18) /* idiv. */ |
| 1675 |
}, |
| 1676 |
/* MULT DImode */ |
| 1677 |
{ |
| 1678 |
0, /* simple (N/A). */ |
| 1679 |
0, /* flag_setting (N/A). */ |
| 1680 |
COSTS_N_INSNS (3), /* extend. */ |
| 1681 |
0, /* add (N/A). */ |
| 1682 |
COSTS_N_INSNS (3), /* extend_add. */ |
| 1683 |
0 /* idiv (N/A). */ |
| 1684 |
} |
| 1685 |
}, |
| 1686 |
/* LD/ST */ |
| 1687 |
{ |
| 1688 |
COSTS_N_INSNS (3), /* load. */ |
| 1689 |
COSTS_N_INSNS (3), /* load_sign_extend. */ |
| 1690 |
COSTS_N_INSNS (3), /* ldrd. */ |
| 1691 |
COSTS_N_INSNS (4), /* ldm_1st. */ |
| 1692 |
1, /* ldm_regs_per_insn_1st. */ |
| 1693 |
2, /* ldm_regs_per_insn_subsequent. */ |
| 1694 |
COSTS_N_INSNS (4), /* loadf. */ |
| 1695 |
COSTS_N_INSNS (4), /* loadd. */ |
| 1696 |
0, /* load_unaligned. */ |
| 1697 |
0, /* store. */ |
| 1698 |
0, /* strd. */ |
| 1699 |
COSTS_N_INSNS (1), /* stm_1st. */ |
| 1700 |
1, /* stm_regs_per_insn_1st. */ |
| 1701 |
2, /* stm_regs_per_insn_subsequent. */ |
| 1702 |
0, /* storef. */ |
| 1703 |
0, /* stored. */ |
| 1704 |
0, /* store_unaligned. */ |
| 1705 |
COSTS_N_INSNS (1), /* loadv. */ |
| 1706 |
COSTS_N_INSNS (1) /* storev. */ |
| 1707 |
}, |
| 1708 |
{ |
| 1709 |
/* FP SFmode */ |
| 1710 |
{ |
| 1711 |
COSTS_N_INSNS (17), /* div. */ |
| 1712 |
COSTS_N_INSNS (4), /* mult. */ |
| 1713 |
COSTS_N_INSNS (8), /* mult_addsub. */ |
| 1714 |
COSTS_N_INSNS (8), /* fma. */ |
| 1715 |
COSTS_N_INSNS (4), /* addsub. */ |
| 1716 |
COSTS_N_INSNS (2), /* fpconst. */ |
| 1717 |
COSTS_N_INSNS (2), /* neg. */ |
| 1718 |
COSTS_N_INSNS (5), /* compare. */ |
| 1719 |
COSTS_N_INSNS (4), /* widen. */ |
| 1720 |
COSTS_N_INSNS (4), /* narrow. */ |
| 1721 |
COSTS_N_INSNS (4), /* toint. */ |
| 1722 |
COSTS_N_INSNS (4), /* fromint. */ |
| 1723 |
COSTS_N_INSNS (4) /* roundint. */ |
| 1724 |
}, |
| 1725 |
/* FP DFmode */ |
| 1726 |
{ |
| 1727 |
COSTS_N_INSNS (31), /* div. */ |
| 1728 |
COSTS_N_INSNS (4), /* mult. */ |
| 1729 |
COSTS_N_INSNS (8), /* mult_addsub. */ |
| 1730 |
COSTS_N_INSNS (8), /* fma. */ |
| 1731 |
COSTS_N_INSNS (4), /* addsub. */ |
| 1732 |
COSTS_N_INSNS (2), /* fpconst. */ |
| 1733 |
COSTS_N_INSNS (2), /* neg. */ |
| 1734 |
COSTS_N_INSNS (2), /* compare. */ |
| 1735 |
COSTS_N_INSNS (4), /* widen. */ |
| 1736 |
COSTS_N_INSNS (4), /* narrow. */ |
| 1737 |
COSTS_N_INSNS (4), /* toint. */ |
| 1738 |
COSTS_N_INSNS (4), /* fromint. */ |
| 1739 |
COSTS_N_INSNS (4) /* roundint. */ |
| 1740 |
} |
| 1741 |
}, |
| 1742 |
/* Vector */ |
| 1743 |
{ |
| 1744 |
COSTS_N_INSNS (1), /* alu. */ |
| 1745 |
COSTS_N_INSNS (4), /* mult. */ |
| 1746 |
COSTS_N_INSNS (1), /* movi. */ |
| 1747 |
COSTS_N_INSNS (2), /* dup. */ |
| 1748 |
COSTS_N_INSNS (2) /* extract. */ |
| 1749 |
} |
| 1750 |
}; |
| 1751 |
|
| 1752 |
const struct cpu_cost_table v7m_extra_costs = |
| 1753 |
{ |
| 1754 |
/* ALU */ |
| 1755 |
{ |
| 1756 |
0, /* arith. */ |
| 1757 |
0, /* logical. */ |
| 1758 |
0, /* shift. */ |
| 1759 |
0, /* shift_reg. */ |
| 1760 |
0, /* arith_shift. */ |
| 1761 |
COSTS_N_INSNS (1), /* arith_shift_reg. */ |
| 1762 |
0, /* log_shift. */ |
| 1763 |
COSTS_N_INSNS (1), /* log_shift_reg. */ |
| 1764 |
0, /* extend. */ |
| 1765 |
COSTS_N_INSNS (1), /* extend_arith. */ |
| 1766 |
0, /* bfi. */ |
| 1767 |
0, /* bfx. */ |
| 1768 |
0, /* clz. */ |
| 1769 |
0, /* rev. */ |
| 1770 |
COSTS_N_INSNS (1), /* non_exec. */ |
| 1771 |
false /* non_exec_costs_exec. */ |
| 1772 |
}, |
| 1773 |
{ |
| 1774 |
/* MULT SImode */ |
| 1775 |
{ |
| 1776 |
COSTS_N_INSNS (1), /* simple. */ |
| 1777 |
COSTS_N_INSNS (1), /* flag_setting. */ |
| 1778 |
COSTS_N_INSNS (2), /* extend. */ |
| 1779 |
COSTS_N_INSNS (1), /* add. */ |
| 1780 |
COSTS_N_INSNS (3), /* extend_add. */ |
| 1781 |
COSTS_N_INSNS (8) /* idiv. */ |
| 1782 |
}, |
| 1783 |
/* MULT DImode */ |
| 1784 |
{ |
| 1785 |
0, /* simple (N/A). */ |
| 1786 |
0, /* flag_setting (N/A). */ |
| 1787 |
COSTS_N_INSNS (2), /* extend. */ |
| 1788 |
0, /* add (N/A). */ |
| 1789 |
COSTS_N_INSNS (3), /* extend_add. */ |
| 1790 |
0 /* idiv (N/A). */ |
| 1791 |
} |
| 1792 |
}, |
| 1793 |
/* LD/ST */ |
| 1794 |
{ |
| 1795 |
COSTS_N_INSNS (2), /* load. */ |
| 1796 |
0, /* load_sign_extend. */ |
| 1797 |
COSTS_N_INSNS (3), /* ldrd. */ |
| 1798 |
COSTS_N_INSNS (2), /* ldm_1st. */ |
| 1799 |
1, /* ldm_regs_per_insn_1st. */ |
| 1800 |
1, /* ldm_regs_per_insn_subsequent. */ |
| 1801 |
COSTS_N_INSNS (2), /* loadf. */ |
| 1802 |
COSTS_N_INSNS (3), /* loadd. */ |
| 1803 |
COSTS_N_INSNS (1), /* load_unaligned. */ |
| 1804 |
COSTS_N_INSNS (2), /* store. */ |
| 1805 |
COSTS_N_INSNS (3), /* strd. */ |
| 1806 |
COSTS_N_INSNS (2), /* stm_1st. */ |
| 1807 |
1, /* stm_regs_per_insn_1st. */ |
| 1808 |
1, /* stm_regs_per_insn_subsequent. */ |
| 1809 |
COSTS_N_INSNS (2), /* storef. */ |
| 1810 |
COSTS_N_INSNS (3), /* stored. */ |
| 1811 |
COSTS_N_INSNS (1), /* store_unaligned. */ |
| 1812 |
COSTS_N_INSNS (1), /* loadv. */ |
| 1813 |
COSTS_N_INSNS (1) /* storev. */ |
| 1814 |
}, |
| 1815 |
{ |
| 1816 |
/* FP SFmode */ |
| 1817 |
{ |
| 1818 |
COSTS_N_INSNS (7), /* div. */ |
| 1819 |
COSTS_N_INSNS (2), /* mult. */ |
| 1820 |
COSTS_N_INSNS (5), /* mult_addsub. */ |
| 1821 |
COSTS_N_INSNS (3), /* fma. */ |
| 1822 |
COSTS_N_INSNS (1), /* addsub. */ |
| 1823 |
0, /* fpconst. */ |
| 1824 |
0, /* neg. */ |
| 1825 |
0, /* compare. */ |
| 1826 |
0, /* widen. */ |
| 1827 |
0, /* narrow. */ |
| 1828 |
0, /* toint. */ |
| 1829 |
0, /* fromint. */ |
| 1830 |
0 /* roundint. */ |
| 1831 |
}, |
| 1832 |
/* FP DFmode */ |
| 1833 |
{ |
| 1834 |
COSTS_N_INSNS (15), /* div. */ |
| 1835 |
COSTS_N_INSNS (5), /* mult. */ |
| 1836 |
COSTS_N_INSNS (7), /* mult_addsub. */ |
| 1837 |
COSTS_N_INSNS (7), /* fma. */ |
| 1838 |
COSTS_N_INSNS (3), /* addsub. */ |
| 1839 |
0, /* fpconst. */ |
| 1840 |
0, /* neg. */ |
| 1841 |
0, /* compare. */ |
| 1842 |
0, /* widen. */ |
| 1843 |
0, /* narrow. */ |
| 1844 |
0, /* toint. */ |
| 1845 |
0, /* fromint. */ |
| 1846 |
0 /* roundint. */ |
| 1847 |
} |
| 1848 |
}, |
| 1849 |
/* Vector */ |
| 1850 |
{ |
| 1851 |
COSTS_N_INSNS (1), /* alu. */ |
| 1852 |
COSTS_N_INSNS (4), /* mult. */ |
| 1853 |
COSTS_N_INSNS (1), /* movi. */ |
| 1854 |
COSTS_N_INSNS (2), /* dup. */ |
| 1855 |
COSTS_N_INSNS (2) /* extract. */ |
| 1856 |
} |
| 1857 |
}; |
| 1858 |
|
| 1859 |
const struct addr_mode_cost_table generic_addr_mode_costs = |
| 1860 |
{ |
| 1861 |
/* int. */ |
| 1862 |
{ |
| 1863 |
COSTS_N_INSNS (0), /* AMO_DEFAULT. */ |
| 1864 |
COSTS_N_INSNS (0), /* AMO_NO_WB. */ |
| 1865 |
COSTS_N_INSNS (0) /* AMO_WB. */ |
| 1866 |
}, |
| 1867 |
/* float. */ |
| 1868 |
{ |
| 1869 |
COSTS_N_INSNS (0), /* AMO_DEFAULT. */ |
| 1870 |
COSTS_N_INSNS (0), /* AMO_NO_WB. */ |
| 1871 |
COSTS_N_INSNS (0) /* AMO_WB. */ |
| 1872 |
}, |
| 1873 |
/* vector. */ |
| 1874 |
{ |
| 1875 |
COSTS_N_INSNS (0), /* AMO_DEFAULT. */ |
| 1876 |
COSTS_N_INSNS (0), /* AMO_NO_WB. */ |
| 1877 |
COSTS_N_INSNS (0) /* AMO_WB. */ |
| 1878 |
} |
| 1879 |
}; |
| 1880 |
|
| 1881 |
const struct tune_params arm_slowmul_tune = |
| 1882 |
{ |
| 1883 |
&generic_extra_costs, /* Insn extra costs. */ |
| 1884 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 1885 |
NULL, /* Sched adj cost. */ |
| 1886 |
arm_default_branch_cost, |
| 1887 |
&arm_default_vec_cost, |
| 1888 |
3, /* Constant limit. */ |
| 1889 |
5, /* Max cond insns. */ |
| 1890 |
8, /* Memset max inline. */ |
| 1891 |
1, /* Issue rate. */ |
| 1892 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 1893 |
tune_params::PREF_CONST_POOL_TRUE, |
| 1894 |
tune_params::PREF_LDRD_FALSE, |
| 1895 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 1896 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 1897 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 1898 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 1899 |
tune_params::FUSE_NOTHING, |
| 1900 |
tune_params::SCHED_AUTOPREF_OFF |
| 1901 |
}; |
| 1902 |
|
| 1903 |
const struct tune_params arm_fastmul_tune = |
| 1904 |
{ |
| 1905 |
&generic_extra_costs, /* Insn extra costs. */ |
| 1906 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 1907 |
NULL, /* Sched adj cost. */ |
| 1908 |
arm_default_branch_cost, |
| 1909 |
&arm_default_vec_cost, |
| 1910 |
1, /* Constant limit. */ |
| 1911 |
5, /* Max cond insns. */ |
| 1912 |
8, /* Memset max inline. */ |
| 1913 |
1, /* Issue rate. */ |
| 1914 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 1915 |
tune_params::PREF_CONST_POOL_TRUE, |
| 1916 |
tune_params::PREF_LDRD_FALSE, |
| 1917 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 1918 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 1919 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 1920 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 1921 |
tune_params::FUSE_NOTHING, |
| 1922 |
tune_params::SCHED_AUTOPREF_OFF |
| 1923 |
}; |
| 1924 |
|
| 1925 |
/* StrongARM has early execution of branches, so a sequence that is worth |
| 1926 |
skipping is shorter. Set max_insns_skipped to a lower value. */ |
| 1927 |
|
| 1928 |
const struct tune_params arm_strongarm_tune = |
| 1929 |
{ |
| 1930 |
&generic_extra_costs, /* Insn extra costs. */ |
| 1931 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 1932 |
NULL, /* Sched adj cost. */ |
| 1933 |
arm_default_branch_cost, |
| 1934 |
&arm_default_vec_cost, |
| 1935 |
1, /* Constant limit. */ |
| 1936 |
3, /* Max cond insns. */ |
| 1937 |
8, /* Memset max inline. */ |
| 1938 |
1, /* Issue rate. */ |
| 1939 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 1940 |
tune_params::PREF_CONST_POOL_TRUE, |
| 1941 |
tune_params::PREF_LDRD_FALSE, |
| 1942 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 1943 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 1944 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 1945 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 1946 |
tune_params::FUSE_NOTHING, |
| 1947 |
tune_params::SCHED_AUTOPREF_OFF |
| 1948 |
}; |
| 1949 |
|
| 1950 |
const struct tune_params arm_xscale_tune = |
| 1951 |
{ |
| 1952 |
&generic_extra_costs, /* Insn extra costs. */ |
| 1953 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 1954 |
xscale_sched_adjust_cost, |
| 1955 |
arm_default_branch_cost, |
| 1956 |
&arm_default_vec_cost, |
| 1957 |
2, /* Constant limit. */ |
| 1958 |
3, /* Max cond insns. */ |
| 1959 |
8, /* Memset max inline. */ |
| 1960 |
1, /* Issue rate. */ |
| 1961 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 1962 |
tune_params::PREF_CONST_POOL_TRUE, |
| 1963 |
tune_params::PREF_LDRD_FALSE, |
| 1964 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 1965 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 1966 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 1967 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 1968 |
tune_params::FUSE_NOTHING, |
| 1969 |
tune_params::SCHED_AUTOPREF_OFF |
| 1970 |
}; |
| 1971 |
|
| 1972 |
const struct tune_params arm_9e_tune = |
| 1973 |
{ |
| 1974 |
&generic_extra_costs, /* Insn extra costs. */ |
| 1975 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 1976 |
NULL, /* Sched adj cost. */ |
| 1977 |
arm_default_branch_cost, |
| 1978 |
&arm_default_vec_cost, |
| 1979 |
1, /* Constant limit. */ |
| 1980 |
5, /* Max cond insns. */ |
| 1981 |
8, /* Memset max inline. */ |
| 1982 |
1, /* Issue rate. */ |
| 1983 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 1984 |
tune_params::PREF_CONST_POOL_TRUE, |
| 1985 |
tune_params::PREF_LDRD_FALSE, |
| 1986 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 1987 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 1988 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 1989 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 1990 |
tune_params::FUSE_NOTHING, |
| 1991 |
tune_params::SCHED_AUTOPREF_OFF |
| 1992 |
}; |
| 1993 |
|
| 1994 |
const struct tune_params arm_marvell_pj4_tune = |
| 1995 |
{ |
| 1996 |
&generic_extra_costs, /* Insn extra costs. */ |
| 1997 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 1998 |
NULL, /* Sched adj cost. */ |
| 1999 |
arm_default_branch_cost, |
| 2000 |
&arm_default_vec_cost, |
| 2001 |
1, /* Constant limit. */ |
| 2002 |
5, /* Max cond insns. */ |
| 2003 |
8, /* Memset max inline. */ |
| 2004 |
2, /* Issue rate. */ |
| 2005 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2006 |
tune_params::PREF_CONST_POOL_TRUE, |
| 2007 |
tune_params::PREF_LDRD_FALSE, |
| 2008 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2009 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2010 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2011 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 2012 |
tune_params::FUSE_NOTHING, |
| 2013 |
tune_params::SCHED_AUTOPREF_OFF |
| 2014 |
}; |
| 2015 |
|
| 2016 |
const struct tune_params arm_v6t2_tune = |
| 2017 |
{ |
| 2018 |
&generic_extra_costs, /* Insn extra costs. */ |
| 2019 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2020 |
NULL, /* Sched adj cost. */ |
| 2021 |
arm_default_branch_cost, |
| 2022 |
&arm_default_vec_cost, |
| 2023 |
1, /* Constant limit. */ |
| 2024 |
5, /* Max cond insns. */ |
| 2025 |
8, /* Memset max inline. */ |
| 2026 |
1, /* Issue rate. */ |
| 2027 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2028 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2029 |
tune_params::PREF_LDRD_FALSE, |
| 2030 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2031 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2032 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2033 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 2034 |
tune_params::FUSE_NOTHING, |
| 2035 |
tune_params::SCHED_AUTOPREF_OFF |
| 2036 |
}; |
| 2037 |
|
| 2038 |
|
| 2039 |
/* Generic Cortex tuning. Use more specific tunings if appropriate. */ |
| 2040 |
const struct tune_params arm_cortex_tune = |
| 2041 |
{ |
| 2042 |
&generic_extra_costs, |
| 2043 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2044 |
NULL, /* Sched adj cost. */ |
| 2045 |
arm_default_branch_cost, |
| 2046 |
&arm_default_vec_cost, |
| 2047 |
1, /* Constant limit. */ |
| 2048 |
5, /* Max cond insns. */ |
| 2049 |
8, /* Memset max inline. */ |
| 2050 |
2, /* Issue rate. */ |
| 2051 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2052 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2053 |
tune_params::PREF_LDRD_FALSE, |
| 2054 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2055 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2056 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2057 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 2058 |
tune_params::FUSE_NOTHING, |
| 2059 |
tune_params::SCHED_AUTOPREF_OFF |
| 2060 |
}; |
| 2061 |
|
| 2062 |
const struct tune_params arm_cortex_a8_tune = |
| 2063 |
{ |
| 2064 |
&cortexa8_extra_costs, |
| 2065 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2066 |
NULL, /* Sched adj cost. */ |
| 2067 |
arm_default_branch_cost, |
| 2068 |
&arm_default_vec_cost, |
| 2069 |
1, /* Constant limit. */ |
| 2070 |
5, /* Max cond insns. */ |
| 2071 |
8, /* Memset max inline. */ |
| 2072 |
2, /* Issue rate. */ |
| 2073 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2074 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2075 |
tune_params::PREF_LDRD_FALSE, |
| 2076 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2077 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2078 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2079 |
tune_params::PREF_NEON_STRINGOPS_TRUE, |
| 2080 |
tune_params::FUSE_NOTHING, |
| 2081 |
tune_params::SCHED_AUTOPREF_OFF |
| 2082 |
}; |
| 2083 |
|
| 2084 |
const struct tune_params arm_cortex_a7_tune = |
| 2085 |
{ |
| 2086 |
&cortexa7_extra_costs, |
| 2087 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2088 |
NULL, /* Sched adj cost. */ |
| 2089 |
arm_default_branch_cost, |
| 2090 |
&arm_default_vec_cost, |
| 2091 |
1, /* Constant limit. */ |
| 2092 |
5, /* Max cond insns. */ |
| 2093 |
8, /* Memset max inline. */ |
| 2094 |
2, /* Issue rate. */ |
| 2095 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2096 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2097 |
tune_params::PREF_LDRD_FALSE, |
| 2098 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2099 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2100 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2101 |
tune_params::PREF_NEON_STRINGOPS_TRUE, |
| 2102 |
tune_params::FUSE_NOTHING, |
| 2103 |
tune_params::SCHED_AUTOPREF_OFF |
| 2104 |
}; |
| 2105 |
|
| 2106 |
const struct tune_params arm_cortex_a15_tune = |
| 2107 |
{ |
| 2108 |
&cortexa15_extra_costs, |
| 2109 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2110 |
NULL, /* Sched adj cost. */ |
| 2111 |
arm_default_branch_cost, |
| 2112 |
&arm_default_vec_cost, |
| 2113 |
1, /* Constant limit. */ |
| 2114 |
2, /* Max cond insns. */ |
| 2115 |
8, /* Memset max inline. */ |
| 2116 |
3, /* Issue rate. */ |
| 2117 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2118 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2119 |
tune_params::PREF_LDRD_TRUE, |
| 2120 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2121 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2122 |
tune_params::DISPARAGE_FLAGS_ALL, |
| 2123 |
tune_params::PREF_NEON_STRINGOPS_TRUE, |
| 2124 |
tune_params::FUSE_NOTHING, |
| 2125 |
tune_params::SCHED_AUTOPREF_FULL |
| 2126 |
}; |
| 2127 |
|
| 2128 |
const struct tune_params arm_cortex_a35_tune = |
| 2129 |
{ |
| 2130 |
&cortexa53_extra_costs, |
| 2131 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2132 |
NULL, /* Sched adj cost. */ |
| 2133 |
arm_default_branch_cost, |
| 2134 |
&arm_default_vec_cost, |
| 2135 |
1, /* Constant limit. */ |
| 2136 |
5, /* Max cond insns. */ |
| 2137 |
8, /* Memset max inline. */ |
| 2138 |
1, /* Issue rate. */ |
| 2139 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2140 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2141 |
tune_params::PREF_LDRD_FALSE, |
| 2142 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2143 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2144 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2145 |
tune_params::PREF_NEON_STRINGOPS_TRUE, |
| 2146 |
FUSE_OPS (tune_params::FUSE_MOVW_MOVT), |
| 2147 |
tune_params::SCHED_AUTOPREF_OFF |
| 2148 |
}; |
| 2149 |
|
| 2150 |
const struct tune_params arm_cortex_a53_tune = |
| 2151 |
{ |
| 2152 |
&cortexa53_extra_costs, |
| 2153 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2154 |
NULL, /* Sched adj cost. */ |
| 2155 |
arm_default_branch_cost, |
| 2156 |
&arm_default_vec_cost, |
| 2157 |
1, /* Constant limit. */ |
| 2158 |
5, /* Max cond insns. */ |
| 2159 |
8, /* Memset max inline. */ |
| 2160 |
2, /* Issue rate. */ |
| 2161 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2162 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2163 |
tune_params::PREF_LDRD_FALSE, |
| 2164 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2165 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2166 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2167 |
tune_params::PREF_NEON_STRINGOPS_TRUE, |
| 2168 |
FUSE_OPS (tune_params::FUSE_MOVW_MOVT | tune_params::FUSE_AES_AESMC), |
| 2169 |
tune_params::SCHED_AUTOPREF_OFF |
| 2170 |
}; |
| 2171 |
|
| 2172 |
const struct tune_params arm_cortex_a57_tune = |
| 2173 |
{ |
| 2174 |
&cortexa57_extra_costs, |
| 2175 |
&generic_addr_mode_costs, /* addressing mode costs */ |
| 2176 |
NULL, /* Sched adj cost. */ |
| 2177 |
arm_default_branch_cost, |
| 2178 |
&arm_default_vec_cost, |
| 2179 |
1, /* Constant limit. */ |
| 2180 |
2, /* Max cond insns. */ |
| 2181 |
8, /* Memset max inline. */ |
| 2182 |
3, /* Issue rate. */ |
| 2183 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2184 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2185 |
tune_params::PREF_LDRD_TRUE, |
| 2186 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2187 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2188 |
tune_params::DISPARAGE_FLAGS_ALL, |
| 2189 |
tune_params::PREF_NEON_STRINGOPS_TRUE, |
| 2190 |
FUSE_OPS (tune_params::FUSE_MOVW_MOVT | tune_params::FUSE_AES_AESMC), |
| 2191 |
tune_params::SCHED_AUTOPREF_FULL |
| 2192 |
}; |
| 2193 |
|
| 2194 |
const struct tune_params arm_exynosm1_tune = |
| 2195 |
{ |
| 2196 |
&exynosm1_extra_costs, |
| 2197 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2198 |
NULL, /* Sched adj cost. */ |
| 2199 |
arm_default_branch_cost, |
| 2200 |
&arm_default_vec_cost, |
| 2201 |
1, /* Constant limit. */ |
| 2202 |
2, /* Max cond insns. */ |
| 2203 |
8, /* Memset max inline. */ |
| 2204 |
3, /* Issue rate. */ |
| 2205 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2206 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2207 |
tune_params::PREF_LDRD_TRUE, |
| 2208 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE, /* Thumb. */ |
| 2209 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE, /* ARM. */ |
| 2210 |
tune_params::DISPARAGE_FLAGS_ALL, |
| 2211 |
tune_params::PREF_NEON_STRINGOPS_TRUE, |
| 2212 |
tune_params::FUSE_NOTHING, |
| 2213 |
tune_params::SCHED_AUTOPREF_OFF |
| 2214 |
}; |
| 2215 |
|
| 2216 |
const struct tune_params arm_xgene1_tune = |
| 2217 |
{ |
| 2218 |
&xgene1_extra_costs, |
| 2219 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2220 |
NULL, /* Sched adj cost. */ |
| 2221 |
arm_default_branch_cost, |
| 2222 |
&arm_default_vec_cost, |
| 2223 |
1, /* Constant limit. */ |
| 2224 |
2, /* Max cond insns. */ |
| 2225 |
32, /* Memset max inline. */ |
| 2226 |
4, /* Issue rate. */ |
| 2227 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2228 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2229 |
tune_params::PREF_LDRD_TRUE, |
| 2230 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2231 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2232 |
tune_params::DISPARAGE_FLAGS_ALL, |
| 2233 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 2234 |
tune_params::FUSE_NOTHING, |
| 2235 |
tune_params::SCHED_AUTOPREF_OFF |
| 2236 |
}; |
| 2237 |
|
| 2238 |
/* Branches can be dual-issued on Cortex-A5, so conditional execution is |
| 2239 |
less appealing. Set max_insns_skipped to a low value. */ |
| 2240 |
|
| 2241 |
const struct tune_params arm_cortex_a5_tune = |
| 2242 |
{ |
| 2243 |
&cortexa5_extra_costs, |
| 2244 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2245 |
NULL, /* Sched adj cost. */ |
| 2246 |
arm_cortex_a5_branch_cost, |
| 2247 |
&arm_default_vec_cost, |
| 2248 |
1, /* Constant limit. */ |
| 2249 |
1, /* Max cond insns. */ |
| 2250 |
8, /* Memset max inline. */ |
| 2251 |
2, /* Issue rate. */ |
| 2252 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2253 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2254 |
tune_params::PREF_LDRD_FALSE, |
| 2255 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE, /* Thumb. */ |
| 2256 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE, /* ARM. */ |
| 2257 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2258 |
tune_params::PREF_NEON_STRINGOPS_TRUE, |
| 2259 |
tune_params::FUSE_NOTHING, |
| 2260 |
tune_params::SCHED_AUTOPREF_OFF |
| 2261 |
}; |
| 2262 |
|
| 2263 |
const struct tune_params arm_cortex_a9_tune = |
| 2264 |
{ |
| 2265 |
&cortexa9_extra_costs, |
| 2266 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2267 |
cortex_a9_sched_adjust_cost, |
| 2268 |
arm_default_branch_cost, |
| 2269 |
&arm_default_vec_cost, |
| 2270 |
1, /* Constant limit. */ |
| 2271 |
5, /* Max cond insns. */ |
| 2272 |
8, /* Memset max inline. */ |
| 2273 |
2, /* Issue rate. */ |
| 2274 |
ARM_PREFETCH_BENEFICIAL(4,32,32), |
| 2275 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2276 |
tune_params::PREF_LDRD_FALSE, |
| 2277 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2278 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2279 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2280 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 2281 |
tune_params::FUSE_NOTHING, |
| 2282 |
tune_params::SCHED_AUTOPREF_OFF |
| 2283 |
}; |
| 2284 |
|
| 2285 |
const struct tune_params arm_cortex_a12_tune = |
| 2286 |
{ |
| 2287 |
&cortexa12_extra_costs, |
| 2288 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2289 |
NULL, /* Sched adj cost. */ |
| 2290 |
arm_default_branch_cost, |
| 2291 |
&arm_default_vec_cost, /* Vectorizer costs. */ |
| 2292 |
1, /* Constant limit. */ |
| 2293 |
2, /* Max cond insns. */ |
| 2294 |
8, /* Memset max inline. */ |
| 2295 |
2, /* Issue rate. */ |
| 2296 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2297 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2298 |
tune_params::PREF_LDRD_TRUE, |
| 2299 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2300 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2301 |
tune_params::DISPARAGE_FLAGS_ALL, |
| 2302 |
tune_params::PREF_NEON_STRINGOPS_TRUE, |
| 2303 |
FUSE_OPS (tune_params::FUSE_MOVW_MOVT), |
| 2304 |
tune_params::SCHED_AUTOPREF_OFF |
| 2305 |
}; |
| 2306 |
|
| 2307 |
const struct tune_params arm_cortex_a73_tune = |
| 2308 |
{ |
| 2309 |
&cortexa57_extra_costs, |
| 2310 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2311 |
NULL, /* Sched adj cost. */ |
| 2312 |
arm_default_branch_cost, |
| 2313 |
&arm_default_vec_cost, /* Vectorizer costs. */ |
| 2314 |
1, /* Constant limit. */ |
| 2315 |
2, /* Max cond insns. */ |
| 2316 |
8, /* Memset max inline. */ |
| 2317 |
2, /* Issue rate. */ |
| 2318 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2319 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2320 |
tune_params::PREF_LDRD_TRUE, |
| 2321 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2322 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2323 |
tune_params::DISPARAGE_FLAGS_ALL, |
| 2324 |
tune_params::PREF_NEON_STRINGOPS_TRUE, |
| 2325 |
FUSE_OPS (tune_params::FUSE_AES_AESMC | tune_params::FUSE_MOVW_MOVT), |
| 2326 |
tune_params::SCHED_AUTOPREF_FULL |
| 2327 |
}; |
| 2328 |
|
| 2329 |
/* armv7m tuning. On Cortex-M4 cores for example, MOVW/MOVT take a single |
| 2330 |
cycle to execute each. An LDR from the constant pool also takes two cycles |
| 2331 |
to execute, but mildly increases pipelining opportunity (consecutive |
| 2332 |
loads/stores can be pipelined together, saving one cycle), and may also |
| 2333 |
improve icache utilisation. Hence we prefer the constant pool for such |
| 2334 |
processors. */ |
| 2335 |
|
| 2336 |
const struct tune_params arm_v7m_tune = |
| 2337 |
{ |
| 2338 |
&v7m_extra_costs, |
| 2339 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2340 |
NULL, /* Sched adj cost. */ |
| 2341 |
arm_cortex_m_branch_cost, |
| 2342 |
&arm_default_vec_cost, |
| 2343 |
1, /* Constant limit. */ |
| 2344 |
2, /* Max cond insns. */ |
| 2345 |
8, /* Memset max inline. */ |
| 2346 |
1, /* Issue rate. */ |
| 2347 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2348 |
tune_params::PREF_CONST_POOL_TRUE, |
| 2349 |
tune_params::PREF_LDRD_FALSE, |
| 2350 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE, /* Thumb. */ |
| 2351 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE, /* ARM. */ |
| 2352 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2353 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 2354 |
tune_params::FUSE_NOTHING, |
| 2355 |
tune_params::SCHED_AUTOPREF_OFF |
| 2356 |
}; |
| 2357 |
|
| 2358 |
/* Cortex-M7 tuning. */ |
| 2359 |
|
| 2360 |
const struct tune_params arm_cortex_m7_tune = |
| 2361 |
{ |
| 2362 |
&v7m_extra_costs, |
| 2363 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2364 |
NULL, /* Sched adj cost. */ |
| 2365 |
arm_cortex_m7_branch_cost, |
| 2366 |
&arm_default_vec_cost, |
| 2367 |
0, /* Constant limit. */ |
| 2368 |
1, /* Max cond insns. */ |
| 2369 |
8, /* Memset max inline. */ |
| 2370 |
2, /* Issue rate. */ |
| 2371 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2372 |
tune_params::PREF_CONST_POOL_TRUE, |
| 2373 |
tune_params::PREF_LDRD_FALSE, |
| 2374 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2375 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2376 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2377 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 2378 |
tune_params::FUSE_NOTHING, |
| 2379 |
tune_params::SCHED_AUTOPREF_OFF |
| 2380 |
}; |
| 2381 |
|
| 2382 |
/* The arm_v6m_tune is duplicated from arm_cortex_tune, rather than |
| 2383 |
arm_v6t2_tune. It is used for cortex-m0, cortex-m1, cortex-m0plus and |
| 2384 |
cortex-m23. */ |
| 2385 |
const struct tune_params arm_v6m_tune = |
| 2386 |
{ |
| 2387 |
&generic_extra_costs, /* Insn extra costs. */ |
| 2388 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2389 |
NULL, /* Sched adj cost. */ |
| 2390 |
arm_default_branch_cost, |
| 2391 |
&arm_default_vec_cost, /* Vectorizer costs. */ |
| 2392 |
1, /* Constant limit. */ |
| 2393 |
5, /* Max cond insns. */ |
| 2394 |
8, /* Memset max inline. */ |
| 2395 |
1, /* Issue rate. */ |
| 2396 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2397 |
tune_params::PREF_CONST_POOL_FALSE, |
| 2398 |
tune_params::PREF_LDRD_FALSE, |
| 2399 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE, /* Thumb. */ |
| 2400 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_FALSE, /* ARM. */ |
| 2401 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2402 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 2403 |
tune_params::FUSE_NOTHING, |
| 2404 |
tune_params::SCHED_AUTOPREF_OFF |
| 2405 |
}; |
| 2406 |
|
| 2407 |
const struct tune_params arm_fa726te_tune = |
| 2408 |
{ |
| 2409 |
&generic_extra_costs, /* Insn extra costs. */ |
| 2410 |
&generic_addr_mode_costs, /* Addressing mode costs. */ |
| 2411 |
fa726te_sched_adjust_cost, |
| 2412 |
arm_default_branch_cost, |
| 2413 |
&arm_default_vec_cost, |
| 2414 |
1, /* Constant limit. */ |
| 2415 |
5, /* Max cond insns. */ |
| 2416 |
8, /* Memset max inline. */ |
| 2417 |
2, /* Issue rate. */ |
| 2418 |
ARM_PREFETCH_NOT_BENEFICIAL, |
| 2419 |
tune_params::PREF_CONST_POOL_TRUE, |
| 2420 |
tune_params::PREF_LDRD_FALSE, |
| 2421 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* Thumb. */ |
| 2422 |
tune_params::LOG_OP_NON_SHORT_CIRCUIT_TRUE, /* ARM. */ |
| 2423 |
tune_params::DISPARAGE_FLAGS_NEITHER, |
| 2424 |
tune_params::PREF_NEON_STRINGOPS_FALSE, |
| 2425 |
tune_params::FUSE_NOTHING, |
| 2426 |
tune_params::SCHED_AUTOPREF_OFF |
| 2427 |
}; |
| 2428 |
|
| 2429 |
/* Auto-generated CPU, FPU and architecture tables. */ |
| 2430 |
#include "arm-cpu-data.h" |
| 2431 |
|
| 2432 |
/* The name of the preprocessor macro to define for this architecture. PROFILE |
| 2433 |
is replaced by the architecture name (eg. 8A) in arm_option_override () and |
| 2434 |
is thus chosen to be big enough to hold the longest architecture name. */ |
| 2435 |
|
| 2436 |
char arm_arch_name[] = "__ARM_ARCH_PROFILE__"; |
| 2437 |
|
| 2438 |
/* Supported TLS relocations. */ |
| 2439 |
|
| 2440 |
enum tls_reloc { |
| 2441 |
TLS_GD32, |
| 2442 |
TLS_GD32_FDPIC, |
| 2443 |
TLS_LDM32, |
| 2444 |
TLS_LDM32_FDPIC, |
| 2445 |
TLS_LDO32, |
| 2446 |
TLS_IE32, |
| 2447 |
TLS_IE32_FDPIC, |
| 2448 |
TLS_LE32, |
| 2449 |
TLS_DESCSEQ /* GNU scheme */ |
| 2450 |
}; |
| 2451 |
|
| 2452 |
/* The maximum number of insns to be used when loading a constant. */ |
| 2453 |
inline static int |
| 2454 |
arm_constant_limit (bool size_p) |
| 2455 |
{ |
| 2456 |
return size_p ? 1 : current_tune->constant_limit; |
| 2457 |
} |
| 2458 |
|
| 2459 |
/* Emit an insn that's a simple single-set. Both the operands must be known |
| 2460 |
to be valid. */ |
| 2461 |
inline static rtx_insn * |
| 2462 |
emit_set_insn (rtx x, rtx y) |
| 2463 |
{ |
| 2464 |
return emit_insn (gen_rtx_SET (x, y)); |
| 2465 |
} |
| 2466 |
|
| 2467 |
/* Return the number of bits set in VALUE. */ |
| 2468 |
static unsigned |
| 2469 |
bit_count (unsigned long value) |
| 2470 |
{ |
| 2471 |
unsigned long count = 0; |
| 2472 |
|
| 2473 |
while (value) |
| 2474 |
{ |
| 2475 |
count++; |
| 2476 |
value &= value - 1; /* Clear the least-significant set bit. */ |
| 2477 |
} |
| 2478 |
|
| 2479 |
return count; |
| 2480 |
} |
| 2481 |
|
| 2482 |
/* Return the number of bits set in BMAP. */ |
| 2483 |
static unsigned |
| 2484 |
bitmap_popcount (const sbitmap bmap) |
| 2485 |
{ |
| 2486 |
unsigned int count = 0; |
| 2487 |
unsigned int n = 0; |
| 2488 |
sbitmap_iterator sbi; |
| 2489 |
|
| 2490 |
EXECUTE_IF_SET_IN_BITMAP (bmap, 0, n, sbi) |
| 2491 |
count++; |
| 2492 |
return count; |
| 2493 |
} |
| 2494 |
|
| 2495 |
typedef struct |
| 2496 |
{ |
| 2497 |
machine_mode mode; |
| 2498 |
const char *name; |
| 2499 |
} arm_fixed_mode_set; |
| 2500 |
|
| 2501 |
/* A small helper for setting fixed-point library libfuncs. */ |
| 2502 |
|
| 2503 |
static void |
| 2504 |
arm_set_fixed_optab_libfunc (optab optable, machine_mode mode, |
| 2505 |
const char *funcname, const char *modename, |
| 2506 |
int num_suffix) |
| 2507 |
{ |
| 2508 |
char buffer[50]; |
| 2509 |
|
| 2510 |
if (num_suffix == 0) |
| 2511 |
sprintf (buffer, "__gnu_%s%s", funcname, modename); |
| 2512 |
else |
| 2513 |
sprintf (buffer, "__gnu_%s%s%d", funcname, modename, num_suffix); |
| 2514 |
|
| 2515 |
set_optab_libfunc (optable, mode, buffer); |
| 2516 |
} |
| 2517 |
|
| 2518 |
static void |
| 2519 |
arm_set_fixed_conv_libfunc (convert_optab optable, machine_mode to, |
| 2520 |
machine_mode from, const char *funcname, |
| 2521 |
const char *toname, const char *fromname) |
| 2522 |
{ |
| 2523 |
char buffer[50]; |
| 2524 |
const char *maybe_suffix_2 = ""; |
| 2525 |
|
| 2526 |
/* Follow the logic for selecting a "2" suffix in fixed-bit.h. */ |
| 2527 |
if (ALL_FIXED_POINT_MODE_P (from) && ALL_FIXED_POINT_MODE_P (to) |
| 2528 |
&& UNSIGNED_FIXED_POINT_MODE_P (from) == UNSIGNED_FIXED_POINT_MODE_P (to) |
| 2529 |
&& ALL_FRACT_MODE_P (from) == ALL_FRACT_MODE_P (to)) |
| 2530 |
maybe_suffix_2 = "2"; |
| 2531 |
|
| 2532 |
sprintf (buffer, "__gnu_%s%s%s%s", funcname, fromname, toname, |
| 2533 |
maybe_suffix_2); |
| 2534 |
|
| 2535 |
set_conv_libfunc (optable, to, from, buffer); |
| 2536 |
} |
| 2537 |
|
| 2538 |
static GTY(()) rtx speculation_barrier_libfunc; |
| 2539 |
|
| 2540 |
/* Record that we have no arithmetic or comparison libfuncs for |
| 2541 |
machine mode MODE. */ |
| 2542 |
|
| 2543 |
static void |
| 2544 |
arm_block_arith_comp_libfuncs_for_mode (machine_mode mode) |
| 2545 |
{ |
| 2546 |
/* Arithmetic. */ |
| 2547 |
set_optab_libfunc (add_optab, mode, NULL); |
| 2548 |
set_optab_libfunc (sdiv_optab, mode, NULL); |
| 2549 |
set_optab_libfunc (smul_optab, mode, NULL); |
| 2550 |
set_optab_libfunc (neg_optab, mode, NULL); |
| 2551 |
set_optab_libfunc (sub_optab, mode, NULL); |
| 2552 |
|
| 2553 |
/* Comparisons. */ |
| 2554 |
set_optab_libfunc (eq_optab, mode, NULL); |
| 2555 |
set_optab_libfunc (ne_optab, mode, NULL); |
| 2556 |
set_optab_libfunc (lt_optab, mode, NULL); |
| 2557 |
set_optab_libfunc (le_optab, mode, NULL); |
| 2558 |
set_optab_libfunc (ge_optab, mode, NULL); |
| 2559 |
set_optab_libfunc (gt_optab, mode, NULL); |
| 2560 |
set_optab_libfunc (unord_optab, mode, NULL); |
| 2561 |
} |
| 2562 |
|
| 2563 |
/* Set up library functions unique to ARM. */ |
| 2564 |
static void |
| 2565 |
arm_init_libfuncs (void) |
| 2566 |
{ |
| 2567 |
machine_mode mode_iter; |
| 2568 |
|
| 2569 |
/* For Linux, we have access to kernel support for atomic operations. */ |
| 2570 |
if (arm_abi == ARM_ABI_AAPCS_LINUX) |
| 2571 |
init_sync_libfuncs (MAX_SYNC_LIBFUNC_SIZE); |
| 2572 |
|
| 2573 |
/* There are no special library functions unless we are using the |
| 2574 |
ARM BPABI. */ |
| 2575 |
if (!TARGET_BPABI) |
| 2576 |
return; |
| 2577 |
|
| 2578 |
/* The functions below are described in Section 4 of the "Run-Time |
| 2579 |
ABI for the ARM architecture", Version 1.0. */ |
| 2580 |
|
| 2581 |
/* Double-precision floating-point arithmetic. Table 2. */ |
| 2582 |
set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd"); |
| 2583 |
set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv"); |
| 2584 |
set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul"); |
| 2585 |
set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg"); |
| 2586 |
set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub"); |
| 2587 |
|
| 2588 |
/* Double-precision comparisons. Table 3. */ |
| 2589 |
set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq"); |
| 2590 |
set_optab_libfunc (ne_optab, DFmode, NULL); |
| 2591 |
set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt"); |
| 2592 |
set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple"); |
| 2593 |
set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge"); |
| 2594 |
set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt"); |
| 2595 |
set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun"); |
| 2596 |
|
| 2597 |
/* Single-precision floating-point arithmetic. Table 4. */ |
| 2598 |
set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd"); |
| 2599 |
set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv"); |
| 2600 |
set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul"); |
| 2601 |
set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg"); |
| 2602 |
set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub"); |
| 2603 |
|
| 2604 |
/* Single-precision comparisons. Table 5. */ |
| 2605 |
set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq"); |
| 2606 |
set_optab_libfunc (ne_optab, SFmode, NULL); |
| 2607 |
set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt"); |
| 2608 |
set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple"); |
| 2609 |
set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge"); |
| 2610 |
set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt"); |
| 2611 |
set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun"); |
| 2612 |
|
| 2613 |
/* Floating-point to integer conversions. Table 6. */ |
| 2614 |
set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz"); |
| 2615 |
set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz"); |
| 2616 |
set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz"); |
| 2617 |
set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz"); |
| 2618 |
set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz"); |
| 2619 |
set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz"); |
| 2620 |
set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz"); |
| 2621 |
set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz"); |
| 2622 |
|
| 2623 |
/* Conversions between floating types. Table 7. */ |
| 2624 |
set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f"); |
| 2625 |
set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d"); |
| 2626 |
|
| 2627 |
/* Integer to floating-point conversions. Table 8. */ |
| 2628 |
set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d"); |
| 2629 |
set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d"); |
| 2630 |
set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d"); |
| 2631 |
set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d"); |
| 2632 |
set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f"); |
| 2633 |
set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f"); |
| 2634 |
set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f"); |
| 2635 |
set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f"); |
| 2636 |
|
| 2637 |
/* Long long. Table 9. */ |
| 2638 |
set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul"); |
| 2639 |
set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod"); |
| 2640 |
set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod"); |
| 2641 |
set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl"); |
| 2642 |
set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr"); |
| 2643 |
set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr"); |
| 2644 |
set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp"); |
| 2645 |
set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp"); |
| 2646 |
|
| 2647 |
/* Integer (32/32->32) division. \S 4.3.1. */ |
| 2648 |
set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod"); |
| 2649 |
set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod"); |
| 2650 |
|
| 2651 |
/* The divmod functions are designed so that they can be used for |
| 2652 |
plain division, even though they return both the quotient and the |
| 2653 |
remainder. The quotient is returned in the usual location (i.e., |
| 2654 |
r0 for SImode, {r0, r1} for DImode), just as would be expected |
| 2655 |
for an ordinary division routine. Because the AAPCS calling |
| 2656 |
conventions specify that all of { r0, r1, r2, r3 } are |
| 2657 |
callee-saved registers, there is no need to tell the compiler |
| 2658 |
explicitly that those registers are clobbered by these |
| 2659 |
routines. */ |
| 2660 |
set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod"); |
| 2661 |
set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod"); |
| 2662 |
|
| 2663 |
/* For SImode division the ABI provides div-without-mod routines, |
| 2664 |
which are faster. */ |
| 2665 |
set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idiv"); |
| 2666 |
set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidiv"); |
| 2667 |
|
| 2668 |
/* We don't have mod libcalls. Fortunately gcc knows how to use the |
| 2669 |
divmod libcalls instead. */ |
| 2670 |
set_optab_libfunc (smod_optab, DImode, NULL); |
| 2671 |
set_optab_libfunc (umod_optab, DImode, NULL); |
| 2672 |
set_optab_libfunc (smod_optab, SImode, NULL); |
| 2673 |
set_optab_libfunc (umod_optab, SImode, NULL); |
| 2674 |
|
| 2675 |
/* Half-precision float operations. The compiler handles all operations |
| 2676 |
with NULL libfuncs by converting the SFmode. */ |
| 2677 |
switch (arm_fp16_format) |
| 2678 |
{ |
| 2679 |
case ARM_FP16_FORMAT_IEEE: |
| 2680 |
case ARM_FP16_FORMAT_ALTERNATIVE: |
| 2681 |
|
| 2682 |
/* Conversions. */ |
| 2683 |
set_conv_libfunc (trunc_optab, HFmode, SFmode, |
| 2684 |
(arm_fp16_format == ARM_FP16_FORMAT_IEEE |
| 2685 |
? "__gnu_f2h_ieee" |
| 2686 |
: "__gnu_f2h_alternative")); |
| 2687 |
set_conv_libfunc (sext_optab, SFmode, HFmode, |
| 2688 |
(arm_fp16_format == ARM_FP16_FORMAT_IEEE |
| 2689 |
? "__gnu_h2f_ieee" |
| 2690 |
: "__gnu_h2f_alternative")); |
| 2691 |
|
| 2692 |
set_conv_libfunc (trunc_optab, HFmode, DFmode, |
| 2693 |
(arm_fp16_format == ARM_FP16_FORMAT_IEEE |
| 2694 |
? "__gnu_d2h_ieee" |
| 2695 |
: "__gnu_d2h_alternative")); |
| 2696 |
|
| 2697 |
arm_block_arith_comp_libfuncs_for_mode (HFmode); |
| 2698 |
break; |
| 2699 |
|
| 2700 |
default: |
| 2701 |
break; |
| 2702 |
} |
| 2703 |
|
| 2704 |
/* For all possible libcalls in BFmode, record NULL. */ |
| 2705 |
FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_FLOAT) |
| 2706 |
{ |
| 2707 |
set_conv_libfunc (trunc_optab, BFmode, mode_iter, NULL); |
| 2708 |
set_conv_libfunc (trunc_optab, mode_iter, BFmode, NULL); |
| 2709 |
set_conv_libfunc (sext_optab, mode_iter, BFmode, NULL); |
| 2710 |
set_conv_libfunc (sext_optab, BFmode, mode_iter, NULL); |
| 2711 |
} |
| 2712 |
arm_block_arith_comp_libfuncs_for_mode (BFmode); |
| 2713 |
|
| 2714 |
/* Use names prefixed with __gnu_ for fixed-point helper functions. */ |
| 2715 |
{ |
| 2716 |
const arm_fixed_mode_set fixed_arith_modes[] = |
| 2717 |
{ |
| 2718 |
{ E_QQmode, "qq" }, |
| 2719 |
{ E_UQQmode, "uqq" }, |
| 2720 |
{ E_HQmode, "hq" }, |
| 2721 |
{ E_UHQmode, "uhq" }, |
| 2722 |
{ E_SQmode, "sq" }, |
| 2723 |
{ E_USQmode, "usq" }, |
| 2724 |
{ E_DQmode, "dq" }, |
| 2725 |
{ E_UDQmode, "udq" }, |
| 2726 |
{ E_TQmode, "tq" }, |
| 2727 |
{ E_UTQmode, "utq" }, |
| 2728 |
{ E_HAmode, "ha" }, |
| 2729 |
{ E_UHAmode, "uha" }, |
| 2730 |
{ E_SAmode, "sa" }, |
| 2731 |
{ E_USAmode, "usa" }, |
| 2732 |
{ E_DAmode, "da" }, |
| 2733 |
{ E_UDAmode, "uda" }, |
| 2734 |
{ E_TAmode, "ta" }, |
| 2735 |
{ E_UTAmode, "uta" } |
| 2736 |
}; |
| 2737 |
const arm_fixed_mode_set fixed_conv_modes[] = |
| 2738 |
{ |
| 2739 |
{ E_QQmode, "qq" }, |
| 2740 |
{ E_UQQmode, "uqq" }, |
| 2741 |
{ E_HQmode, "hq" }, |
| 2742 |
{ E_UHQmode, "uhq" }, |
| 2743 |
{ E_SQmode, "sq" }, |
| 2744 |
{ E_USQmode, "usq" }, |
| 2745 |
{ E_DQmode, "dq" }, |
| 2746 |
{ E_UDQmode, "udq" }, |
| 2747 |
{ E_TQmode, "tq" }, |
| 2748 |
{ E_UTQmode, "utq" }, |
| 2749 |
{ E_HAmode, "ha" }, |
| 2750 |
{ E_UHAmode, "uha" }, |
| 2751 |
{ E_SAmode, "sa" }, |
| 2752 |
{ E_USAmode, "usa" }, |
| 2753 |
{ E_DAmode, "da" }, |
| 2754 |
{ E_UDAmode, "uda" }, |
| 2755 |
{ E_TAmode, "ta" }, |
| 2756 |
{ E_UTAmode, "uta" }, |
| 2757 |
{ E_QImode, "qi" }, |
| 2758 |
{ E_HImode, "hi" }, |
| 2759 |
{ E_SImode, "si" }, |
| 2760 |
{ E_DImode, "di" }, |
| 2761 |
{ E_TImode, "ti" }, |
| 2762 |
{ E_SFmode, "sf" }, |
| 2763 |
{ E_DFmode, "df" } |
| 2764 |
}; |
| 2765 |
unsigned int i, j; |
| 2766 |
|
| 2767 |
for (i = 0; i < ARRAY_SIZE (fixed_arith_modes); i++) |
| 2768 |
{ |
| 2769 |
arm_set_fixed_optab_libfunc (add_optab, fixed_arith_modes[i].mode, |
| 2770 |
"add", fixed_arith_modes[i].name, 3); |
| 2771 |
arm_set_fixed_optab_libfunc (ssadd_optab, fixed_arith_modes[i].mode, |
| 2772 |
"ssadd", fixed_arith_modes[i].name, 3); |
| 2773 |
arm_set_fixed_optab_libfunc (usadd_optab, fixed_arith_modes[i].mode, |
| 2774 |
"usadd", fixed_arith_modes[i].name, 3); |
| 2775 |
arm_set_fixed_optab_libfunc (sub_optab, fixed_arith_modes[i].mode, |
| 2776 |
"sub", fixed_arith_modes[i].name, 3); |
| 2777 |
arm_set_fixed_optab_libfunc (sssub_optab, fixed_arith_modes[i].mode, |
| 2778 |
"sssub", fixed_arith_modes[i].name, 3); |
| 2779 |
arm_set_fixed_optab_libfunc (ussub_optab, fixed_arith_modes[i].mode, |
| 2780 |
"ussub", fixed_arith_modes[i].name, 3); |
| 2781 |
arm_set_fixed_optab_libfunc (smul_optab, fixed_arith_modes[i].mode, |
| 2782 |
"mul", fixed_arith_modes[i].name, 3); |
| 2783 |
arm_set_fixed_optab_libfunc (ssmul_optab, fixed_arith_modes[i].mode, |
| 2784 |
"ssmul", fixed_arith_modes[i].name, 3); |
| 2785 |
arm_set_fixed_optab_libfunc (usmul_optab, fixed_arith_modes[i].mode, |
| 2786 |
"usmul", fixed_arith_modes[i].name, 3); |
| 2787 |
arm_set_fixed_optab_libfunc (sdiv_optab, fixed_arith_modes[i].mode, |
| 2788 |
"div", fixed_arith_modes[i].name, 3); |
| 2789 |
arm_set_fixed_optab_libfunc (udiv_optab, fixed_arith_modes[i].mode, |
| 2790 |
"udiv", fixed_arith_modes[i].name, 3); |
| 2791 |
arm_set_fixed_optab_libfunc (ssdiv_optab, fixed_arith_modes[i].mode, |
| 2792 |
"ssdiv", fixed_arith_modes[i].name, 3); |
| 2793 |
arm_set_fixed_optab_libfunc (usdiv_optab, fixed_arith_modes[i].mode, |
| 2794 |
"usdiv", fixed_arith_modes[i].name, 3); |
| 2795 |
arm_set_fixed_optab_libfunc (neg_optab, fixed_arith_modes[i].mode, |
| 2796 |
"neg", fixed_arith_modes[i].name, 2); |
| 2797 |
arm_set_fixed_optab_libfunc (ssneg_optab, fixed_arith_modes[i].mode, |
| 2798 |
"ssneg", fixed_arith_modes[i].name, 2); |
| 2799 |
arm_set_fixed_optab_libfunc (usneg_optab, fixed_arith_modes[i].mode, |
| 2800 |
"usneg", fixed_arith_modes[i].name, 2); |
| 2801 |
arm_set_fixed_optab_libfunc (ashl_optab, fixed_arith_modes[i].mode, |
| 2802 |
"ashl", fixed_arith_modes[i].name, 3); |
| 2803 |
arm_set_fixed_optab_libfunc (ashr_optab, fixed_arith_modes[i].mode, |
| 2804 |
"ashr", fixed_arith_modes[i].name, 3); |
| 2805 |
arm_set_fixed_optab_libfunc (lshr_optab, fixed_arith_modes[i].mode, |
| 2806 |
"lshr", fixed_arith_modes[i].name, 3); |
| 2807 |
arm_set_fixed_optab_libfunc (ssashl_optab, fixed_arith_modes[i].mode, |
| 2808 |
"ssashl", fixed_arith_modes[i].name, 3); |
| 2809 |
arm_set_fixed_optab_libfunc (usashl_optab, fixed_arith_modes[i].mode, |
| 2810 |
"usashl", fixed_arith_modes[i].name, 3); |
| 2811 |
arm_set_fixed_optab_libfunc (cmp_optab, fixed_arith_modes[i].mode, |
| 2812 |
"cmp", fixed_arith_modes[i].name, 2); |
| 2813 |
} |
| 2814 |
|
| 2815 |
for (i = 0; i < ARRAY_SIZE (fixed_conv_modes); i++) |
| 2816 |
for (j = 0; j < ARRAY_SIZE (fixed_conv_modes); j++) |
| 2817 |
{ |
| 2818 |
if (i == j |
| 2819 |
|| (!ALL_FIXED_POINT_MODE_P (fixed_conv_modes[i].mode) |
| 2820 |
&& !ALL_FIXED_POINT_MODE_P (fixed_conv_modes[j].mode))) |
| 2821 |
continue; |
| 2822 |
|
| 2823 |
arm_set_fixed_conv_libfunc (fract_optab, fixed_conv_modes[i].mode, |
| 2824 |
fixed_conv_modes[j].mode, "fract", |
| 2825 |
fixed_conv_modes[i].name, |
| 2826 |
fixed_conv_modes[j].name); |
| 2827 |
arm_set_fixed_conv_libfunc (satfract_optab, |
| 2828 |
fixed_conv_modes[i].mode, |
| 2829 |
fixed_conv_modes[j].mode, "satfract", |
| 2830 |
fixed_conv_modes[i].name, |
| 2831 |
fixed_conv_modes[j].name); |
| 2832 |
arm_set_fixed_conv_libfunc (fractuns_optab, |
| 2833 |
fixed_conv_modes[i].mode, |
| 2834 |
fixed_conv_modes[j].mode, "fractuns", |
| 2835 |
fixed_conv_modes[i].name, |
| 2836 |
fixed_conv_modes[j].name); |
| 2837 |
arm_set_fixed_conv_libfunc (satfractuns_optab, |
| 2838 |
fixed_conv_modes[i].mode, |
| 2839 |
fixed_conv_modes[j].mode, "satfractuns", |
| 2840 |
fixed_conv_modes[i].name, |
| 2841 |
fixed_conv_modes[j].name); |
| 2842 |
} |
| 2843 |
} |
| 2844 |
|
| 2845 |
if (TARGET_AAPCS_BASED) |
| 2846 |
synchronize_libfunc = init_one_libfunc ("__sync_synchronize"); |
| 2847 |
|
| 2848 |
speculation_barrier_libfunc = init_one_libfunc ("__speculation_barrier"); |
| 2849 |
} |
| 2850 |
|
| 2851 |
/* Implement TARGET_GIMPLE_FOLD_BUILTIN. */ |
| 2852 |
static bool |
| 2853 |
arm_gimple_fold_builtin (gimple_stmt_iterator *gsi) |
| 2854 |
{ |
| 2855 |
gcall *stmt = as_a <gcall *> (gsi_stmt (*gsi)); |
| 2856 |
tree fndecl = gimple_call_fndecl (stmt); |
| 2857 |
unsigned int code = DECL_MD_FUNCTION_CODE (fndecl); |
| 2858 |
unsigned int subcode = code >> ARM_BUILTIN_SHIFT; |
| 2859 |
gimple *new_stmt = NULL; |
| 2860 |
switch (code & ARM_BUILTIN_CLASS) |
| 2861 |
{ |
| 2862 |
case ARM_BUILTIN_GENERAL: |
| 2863 |
new_stmt = arm_general_gimple_fold_builtin (subcode, stmt); |
| 2864 |
break; |
| 2865 |
|
| 2866 |
case ARM_BUILTIN_MVE: |
| 2867 |
new_stmt = arm_mve::gimple_fold_builtin (subcode, stmt); |
| 2868 |
} |
| 2869 |
if (!new_stmt) |
| 2870 |
return false; |
| 2871 |
|
| 2872 |
gsi_replace (gsi, new_stmt, true); |
| 2873 |
return true; |
| 2874 |
} |
| 2875 |
|
| 2876 |
/* On AAPCS systems, this is the "struct __va_list". */ |
| 2877 |
static GTY(()) tree va_list_type; |
| 2878 |
|
| 2879 |
/* Return the type to use as __builtin_va_list. */ |
| 2880 |
static tree |
| 2881 |
arm_build_builtin_va_list (void) |
| 2882 |
{ |
| 2883 |
tree va_list_name; |
| 2884 |
tree ap_field; |
| 2885 |
|
| 2886 |
if (!TARGET_AAPCS_BASED) |
| 2887 |
return std_build_builtin_va_list (); |
| 2888 |
|
| 2889 |
/* AAPCS \S 7.1.4 requires that va_list be a typedef for a type |
| 2890 |
defined as: |
| 2891 |
|
| 2892 |
struct __va_list |
| 2893 |
{ |
| 2894 |
void *__ap; |
| 2895 |
}; |
| 2896 |
|
| 2897 |
The C Library ABI further reinforces this definition in \S |
| 2898 |
4.1. |
| 2899 |
|
| 2900 |
We must follow this definition exactly. The structure tag |
| 2901 |
name is visible in C++ mangled names, and thus forms a part |
| 2902 |
of the ABI. The field name may be used by people who |
| 2903 |
#include <stdarg.h>. */ |
| 2904 |
/* Create the type. */ |
| 2905 |
va_list_type = lang_hooks.types.make_type (RECORD_TYPE); |
| 2906 |
/* Give it the required name. */ |
| 2907 |
va_list_name = build_decl (BUILTINS_LOCATION, |
| 2908 |
TYPE_DECL, |
| 2909 |
get_identifier ("__va_list"), |
| 2910 |
va_list_type); |
| 2911 |
DECL_ARTIFICIAL (va_list_name) = 1; |
| 2912 |
TREE_PUBLIC (va_list_name) = 1; |
| 2913 |
TYPE_NAME (va_list_type) = va_list_name; |
| 2914 |
TYPE_STUB_DECL (va_list_type) = va_list_name; |
| 2915 |
/* Create the __ap field. */ |
| 2916 |
ap_field = build_decl (BUILTINS_LOCATION, |
| 2917 |
FIELD_DECL, |
| 2918 |
get_identifier ("__ap"), |
| 2919 |
ptr_type_node); |
| 2920 |
DECL_ARTIFICIAL (ap_field) = 1; |
| 2921 |
DECL_FIELD_CONTEXT (ap_field) = va_list_type; |
| 2922 |
TYPE_FIELDS (va_list_type) = ap_field; |
| 2923 |
/* Compute its layout. */ |
| 2924 |
layout_type (va_list_type); |
| 2925 |
|
| 2926 |
return va_list_type; |
| 2927 |
} |
| 2928 |
|
| 2929 |
/* Return an expression of type "void *" pointing to the next |
| 2930 |
available argument in a variable-argument list. VALIST is the |
| 2931 |
user-level va_list object, of type __builtin_va_list. */ |
| 2932 |
static tree |
| 2933 |
arm_extract_valist_ptr (tree valist) |
| 2934 |
{ |
| 2935 |
if (TREE_TYPE (valist) == error_mark_node) |
| 2936 |
return error_mark_node; |
| 2937 |
|
| 2938 |
/* On an AAPCS target, the pointer is stored within "struct |
| 2939 |
va_list". */ |
| 2940 |
if (TARGET_AAPCS_BASED) |
| 2941 |
{ |
| 2942 |
tree ap_field = TYPE_FIELDS (TREE_TYPE (valist)); |
| 2943 |
valist = build3 (COMPONENT_REF, TREE_TYPE (ap_field), |
| 2944 |
valist, ap_field, NULL_TREE); |
| 2945 |
} |
| 2946 |
|
| 2947 |
return valist; |
| 2948 |
} |
| 2949 |
|
| 2950 |
/* Implement TARGET_EXPAND_BUILTIN_VA_START. */ |
| 2951 |
static void |
| 2952 |
arm_expand_builtin_va_start (tree valist, rtx nextarg) |
| 2953 |
{ |
| 2954 |
valist = arm_extract_valist_ptr (valist); |
| 2955 |
std_expand_builtin_va_start (valist, nextarg); |
| 2956 |
} |
| 2957 |
|
| 2958 |
/* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */ |
| 2959 |
static tree |
| 2960 |
arm_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, |
| 2961 |
gimple_seq *post_p) |
| 2962 |
{ |
| 2963 |
valist = arm_extract_valist_ptr (valist); |
| 2964 |
return std_gimplify_va_arg_expr (valist, type, pre_p, post_p); |
| 2965 |
} |
| 2966 |
|
| 2967 |
/* Check any incompatible options that the user has specified. */ |
| 2968 |
static void |
| 2969 |
arm_option_check_internal (struct gcc_options *opts) |
| 2970 |
{ |
| 2971 |
int flags = opts->x_target_flags; |
| 2972 |
|
| 2973 |
/* iWMMXt and NEON are incompatible. */ |
| 2974 |
if (TARGET_IWMMXT |
| 2975 |
&& bitmap_bit_p (arm_active_target.isa, isa_bit_neon)) |
| 2976 |
error ("iWMMXt and NEON are incompatible"); |
| 2977 |
|
| 2978 |
/* Make sure that the processor choice does not conflict with any of the |
| 2979 |
other command line choices. */ |
| 2980 |
if (TARGET_ARM_P (flags) |
| 2981 |
&& !bitmap_bit_p (arm_active_target.isa, isa_bit_notm)) |
| 2982 |
error ("target CPU does not support ARM mode"); |
| 2983 |
|
| 2984 |
/* TARGET_BACKTRACE cannot be used here as crtl->is_leaf is not set yet. */ |
| 2985 |
if ((TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) && TARGET_ARM_P (flags)) |
| 2986 |
warning (0, "enabling backtrace support is only meaningful when compiling for the Thumb"); |
| 2987 |
|
| 2988 |
if (TARGET_ARM_P (flags) && TARGET_CALLEE_INTERWORKING) |
| 2989 |
warning (0, "enabling callee interworking support is only meaningful when compiling for the Thumb"); |
| 2990 |
|
| 2991 |
/* If this target is normally configured to use APCS frames, warn if they |
| 2992 |
are turned off and debugging is turned on. */ |
| 2993 |
if (TARGET_ARM_P (flags) |
| 2994 |
&& write_symbols != NO_DEBUG |
| 2995 |
&& !TARGET_APCS_FRAME |
| 2996 |
&& (TARGET_DEFAULT & MASK_APCS_FRAME)) |
| 2997 |
warning (0, "%<-g%> with %<-mno-apcs-frame%> may not give sensible " |
| 2998 |
"debugging"); |
| 2999 |
|
| 3000 |
/* iWMMXt unsupported under Thumb mode. */ |
| 3001 |
if (TARGET_THUMB_P (flags) && TARGET_IWMMXT) |
| 3002 |
error ("iWMMXt unsupported under Thumb mode"); |
| 3003 |
|
| 3004 |
if (TARGET_HARD_TP && TARGET_THUMB1_P (flags)) |
| 3005 |
error ("cannot use %<-mtp=cp15%> with 16-bit Thumb"); |
| 3006 |
|
| 3007 |
if (TARGET_THUMB_P (flags) && TARGET_VXWORKS_RTP && flag_pic) |
| 3008 |
{ |
| 3009 |
error ("RTP PIC is incompatible with Thumb"); |
| 3010 |
flag_pic = 0; |
| 3011 |
} |
| 3012 |
|
| 3013 |
if (target_pure_code || target_slow_flash_data) |
| 3014 |
{ |
| 3015 |
const char *flag = (target_pure_code ? "-mpure-code" : |
| 3016 |
"-mslow-flash-data"); |
| 3017 |
bool common_unsupported_modes = arm_arch_notm || flag_pic || TARGET_NEON; |
| 3018 |
|
| 3019 |
/* We only support -mslow-flash-data on M-profile targets with |
| 3020 |
MOVT. */ |
| 3021 |
if (target_slow_flash_data && (!TARGET_HAVE_MOVT || common_unsupported_modes)) |
| 3022 |
error ("%qs only supports non-pic code on M-profile targets with the " |
| 3023 |
"MOVT instruction", flag); |
| 3024 |
|
| 3025 |
/* We only support -mpure-code on M-profile targets. */ |
| 3026 |
if (target_pure_code && common_unsupported_modes) |
| 3027 |
error ("%qs only supports non-pic code on M-profile targets", flag); |
| 3028 |
|
| 3029 |
/* Cannot load addresses: -mslow-flash-data forbids literal pool and |
| 3030 |
-mword-relocations forbids relocation of MOVT/MOVW. */ |
| 3031 |
if (target_word_relocations) |
| 3032 |
error ("%qs is incompatible with %<-mword-relocations%>", flag); |
| 3033 |
} |
| 3034 |
} |
| 3035 |
|
| 3036 |
/* Recompute the global settings depending on target attribute options. */ |
| 3037 |
|
| 3038 |
static void |
| 3039 |
arm_option_params_internal (void) |
| 3040 |
{ |
| 3041 |
/* If we are not using the default (ARM mode) section anchor offset |
| 3042 |
ranges, then set the correct ranges now. */ |
| 3043 |
if (TARGET_THUMB1) |
| 3044 |
{ |
| 3045 |
/* Thumb-1 LDR instructions cannot have negative offsets. |
| 3046 |
Permissible positive offset ranges are 5-bit (for byte loads), |
| 3047 |
6-bit (for halfword loads), or 7-bit (for word loads). |
| 3048 |
Empirical results suggest a 7-bit anchor range gives the best |
| 3049 |
overall code size. */ |
| 3050 |
targetm.min_anchor_offset = 0; |
| 3051 |
targetm.max_anchor_offset = 127; |
| 3052 |
} |
| 3053 |
else if (TARGET_THUMB2) |
| 3054 |
{ |
| 3055 |
/* The minimum is set such that the total size of the block |
| 3056 |
for a particular anchor is 248 + 1 + 4095 bytes, which is |
| 3057 |
divisible by eight, ensuring natural spacing of anchors. */ |
| 3058 |
targetm.min_anchor_offset = -248; |
| 3059 |
targetm.max_anchor_offset = 4095; |
| 3060 |
} |
| 3061 |
else |
| 3062 |
{ |
| 3063 |
targetm.min_anchor_offset = TARGET_MIN_ANCHOR_OFFSET; |
| 3064 |
targetm.max_anchor_offset = TARGET_MAX_ANCHOR_OFFSET; |
| 3065 |
} |
| 3066 |
|
| 3067 |
/* Increase the number of conditional instructions with -Os. */ |
| 3068 |
max_insns_skipped = optimize_size ? 4 : current_tune->max_insns_skipped; |
| 3069 |
|
| 3070 |
/* For THUMB2, we limit the conditional sequence to one IT block. */ |
| 3071 |
if (TARGET_THUMB2) |
| 3072 |
max_insns_skipped = MIN (max_insns_skipped, MAX_INSN_PER_IT_BLOCK); |
| 3073 |
|
| 3074 |
if (TARGET_THUMB1) |
| 3075 |
targetm.md_asm_adjust = thumb1_md_asm_adjust; |
| 3076 |
else |
| 3077 |
targetm.md_asm_adjust = arm_md_asm_adjust; |
| 3078 |
} |
| 3079 |
|
| 3080 |
/* True if -mflip-thumb should next add an attribute for the default |
| 3081 |
mode, false if it should next add an attribute for the opposite mode. */ |
| 3082 |
static GTY(()) bool thumb_flipper; |
| 3083 |
|
| 3084 |
/* Options after initial target override. */ |
| 3085 |
static GTY(()) tree init_optimize; |
| 3086 |
|
| 3087 |
static void |
| 3088 |
arm_override_options_after_change_1 (struct gcc_options *opts, |
| 3089 |
struct gcc_options *opts_set) |
| 3090 |
{ |
| 3091 |
/* -falign-functions without argument: supply one. */ |
| 3092 |
if (opts->x_flag_align_functions && !opts_set->x_str_align_functions) |
| 3093 |
opts->x_str_align_functions = TARGET_THUMB_P (opts->x_target_flags) |
| 3094 |
&& opts->x_optimize_size ? "2" : "4"; |
| 3095 |
} |
| 3096 |
|
| 3097 |
/* Implement targetm.override_options_after_change. */ |
| 3098 |
|
| 3099 |
static void |
| 3100 |
arm_override_options_after_change (void) |
| 3101 |
{ |
| 3102 |
arm_override_options_after_change_1 (&global_options, &global_options_set); |
| 3103 |
} |
| 3104 |
|
| 3105 |
/* Implement TARGET_OPTION_RESTORE. */ |
| 3106 |
static void |
| 3107 |
arm_option_restore (struct gcc_options */* opts */, |
| 3108 |
struct gcc_options */* opts_set */, |
| 3109 |
struct cl_target_option *ptr) |
| 3110 |
{ |
| 3111 |
arm_configure_build_target (&arm_active_target, ptr, false); |
| 3112 |
arm_option_reconfigure_globals (); |
| 3113 |
} |
| 3114 |
|
| 3115 |
/* Reset options between modes that the user has specified. */ |
| 3116 |
static void |
| 3117 |
arm_option_override_internal (struct gcc_options *opts, |
| 3118 |
struct gcc_options *opts_set) |
| 3119 |
{ |
| 3120 |
arm_override_options_after_change_1 (opts, opts_set); |
| 3121 |
|
| 3122 |
if (TARGET_INTERWORK && !bitmap_bit_p (arm_active_target.isa, isa_bit_thumb)) |
| 3123 |
{ |
| 3124 |
/* The default is to enable interworking, so this warning message would |
| 3125 |
be confusing to users who have just compiled with |
| 3126 |
eg, -march=armv4. */ |
| 3127 |
/* warning (0, "ignoring -minterwork because target CPU does not support THUMB"); */ |
| 3128 |
opts->x_target_flags &= ~MASK_INTERWORK; |
| 3129 |
} |
| 3130 |
|
| 3131 |
if (TARGET_THUMB_P (opts->x_target_flags) |
| 3132 |
&& !bitmap_bit_p (arm_active_target.isa, isa_bit_thumb)) |
| 3133 |
{ |
| 3134 |
warning (0, "target CPU does not support THUMB instructions"); |
| 3135 |
opts->x_target_flags &= ~MASK_THUMB; |
| 3136 |
} |
| 3137 |
|
| 3138 |
if (TARGET_APCS_FRAME && TARGET_THUMB_P (opts->x_target_flags)) |
| 3139 |
{ |
| 3140 |
/* warning (0, "ignoring -mapcs-frame because -mthumb was used"); */ |
| 3141 |
opts->x_target_flags &= ~MASK_APCS_FRAME; |
| 3142 |
} |
| 3143 |
|
| 3144 |
/* Callee super interworking implies thumb interworking. Adding |
| 3145 |
this to the flags here simplifies the logic elsewhere. */ |
| 3146 |
if (TARGET_THUMB_P (opts->x_target_flags) && TARGET_CALLEE_INTERWORKING) |
| 3147 |
opts->x_target_flags |= MASK_INTERWORK; |
| 3148 |
|
| 3149 |
/* need to remember initial values so combinaisons of options like |
| 3150 |
-mflip-thumb -mthumb -fno-schedule-insns work for any attribute. */ |
| 3151 |
cl_optimization *to = TREE_OPTIMIZATION (init_optimize); |
| 3152 |
|
| 3153 |
if (! opts_set->x_arm_restrict_it) |
| 3154 |
opts->x_arm_restrict_it = arm_arch8; |
| 3155 |
|
| 3156 |
/* ARM execution state and M profile don't have [restrict] IT. */ |
| 3157 |
if (!TARGET_THUMB2_P (opts->x_target_flags) || !arm_arch_notm) |
| 3158 |
opts->x_arm_restrict_it = 0; |
| 3159 |
|
| 3160 |
/* Use the IT size from CPU specific tuning unless -mrestrict-it is used. */ |
| 3161 |
if (!opts_set->x_arm_restrict_it |
| 3162 |
&& (opts_set->x_arm_cpu_string || opts_set->x_arm_tune_string)) |
| 3163 |
opts->x_arm_restrict_it = 0; |
| 3164 |
|
| 3165 |
/* Enable -munaligned-access by default for |
| 3166 |
- all ARMv6 architecture-based processors when compiling for a 32-bit ISA |
| 3167 |
i.e. Thumb2 and ARM state only. |
| 3168 |
- ARMv7-A, ARMv7-R, and ARMv7-M architecture-based processors. |
| 3169 |
- ARMv8 architecture-base processors. |
| 3170 |
|
| 3171 |
Disable -munaligned-access by default for |
| 3172 |
- all pre-ARMv6 architecture-based processors |
| 3173 |
- ARMv6-M architecture-based processors |
| 3174 |
- ARMv8-M Baseline processors. */ |
| 3175 |
|
| 3176 |
if (! opts_set->x_unaligned_access) |
| 3177 |
{ |
| 3178 |
opts->x_unaligned_access = (TARGET_32BIT_P (opts->x_target_flags) |
| 3179 |
&& arm_arch6 && (arm_arch_notm || arm_arch7)); |
| 3180 |
} |
| 3181 |
else if (opts->x_unaligned_access == 1 |
| 3182 |
&& !(arm_arch6 && (arm_arch_notm || arm_arch7))) |
| 3183 |
{ |
| 3184 |
warning (0, "target CPU does not support unaligned accesses"); |
| 3185 |
opts->x_unaligned_access = 0; |
| 3186 |
} |
| 3187 |
|
| 3188 |
/* Don't warn since it's on by default in -O2. */ |
| 3189 |
if (TARGET_THUMB1_P (opts->x_target_flags)) |
| 3190 |
opts->x_flag_schedule_insns = 0; |
| 3191 |
else |
| 3192 |
opts->x_flag_schedule_insns = to->x_flag_schedule_insns; |
| 3193 |
|
| 3194 |
/* Disable shrink-wrap when optimizing function for size, since it tends to |
| 3195 |
generate additional returns. */ |
| 3196 |
if (optimize_function_for_size_p (cfun) |
| 3197 |
&& TARGET_THUMB2_P (opts->x_target_flags)) |
| 3198 |
opts->x_flag_shrink_wrap = false; |
| 3199 |
else |
| 3200 |
opts->x_flag_shrink_wrap = to->x_flag_shrink_wrap; |
| 3201 |
|
| 3202 |
/* In Thumb1 mode, we emit the epilogue in RTL, but the last insn |
| 3203 |
- epilogue_insns - does not accurately model the corresponding insns |
| 3204 |
emitted in the asm file. In particular, see the comment in thumb_exit |
| 3205 |
'Find out how many of the (return) argument registers we can corrupt'. |
| 3206 |
As a consequence, the epilogue may clobber registers without fipa-ra |
| 3207 |
finding out about it. Therefore, disable fipa-ra in Thumb1 mode. |
| 3208 |
TODO: Accurately model clobbers for epilogue_insns and reenable |
| 3209 |
fipa-ra. */ |
| 3210 |
if (TARGET_THUMB1_P (opts->x_target_flags)) |
| 3211 |
opts->x_flag_ipa_ra = 0; |
| 3212 |
else |
| 3213 |
opts->x_flag_ipa_ra = to->x_flag_ipa_ra; |
| 3214 |
|
| 3215 |
/* Thumb2 inline assembly code should always use unified syntax. |
| 3216 |
This will apply to ARM and Thumb1 eventually. */ |
| 3217 |
if (TARGET_THUMB2_P (opts->x_target_flags)) |
| 3218 |
opts->x_inline_asm_unified = true; |
| 3219 |
|
| 3220 |
if (arm_stack_protector_guard == SSP_GLOBAL |
| 3221 |
&& opts->x_arm_stack_protector_guard_offset_str) |
| 3222 |
{ |
| 3223 |
error ("incompatible options %<-mstack-protector-guard=global%> and " |
| 3224 |
"%<-mstack-protector-guard-offset=%s%>", |
| 3225 |
arm_stack_protector_guard_offset_str); |
| 3226 |
} |
| 3227 |
|
| 3228 |
if (opts->x_arm_stack_protector_guard_offset_str) |
| 3229 |
{ |
| 3230 |
char *end; |
| 3231 |
const char *str = arm_stack_protector_guard_offset_str; |
| 3232 |
errno = 0; |
| 3233 |
long offs = strtol (arm_stack_protector_guard_offset_str, &end, 0); |
| 3234 |
if (!*str || *end || errno) |
| 3235 |
error ("%qs is not a valid offset in %qs", str, |
| 3236 |
"-mstack-protector-guard-offset="); |
| 3237 |
arm_stack_protector_guard_offset = offs; |
| 3238 |
} |
| 3239 |
|
| 3240 |
if (arm_current_function_pac_enabled_p ()) |
| 3241 |
{ |
| 3242 |
if (!arm_arch8m_main) |
| 3243 |
error ("This architecture does not support branch protection " |
| 3244 |
"instructions"); |
| 3245 |
if (TARGET_TPCS_FRAME) |
| 3246 |
sorry ("Return address signing is not supported with %<-mtpcs-frame%>."); |
| 3247 |
} |
| 3248 |
|
| 3249 |
#ifdef SUBTARGET_OVERRIDE_INTERNAL_OPTIONS |
| 3250 |
SUBTARGET_OVERRIDE_INTERNAL_OPTIONS; |
| 3251 |
#endif |
| 3252 |
} |
| 3253 |
|
| 3254 |
static sbitmap isa_all_fpubits_internal; |
| 3255 |
static sbitmap isa_all_fpbits; |
| 3256 |
static sbitmap isa_quirkbits; |
| 3257 |
|
| 3258 |
static void |
| 3259 |
arm_handle_no_branch_protection (void) |
| 3260 |
{ |
| 3261 |
aarch_ra_sign_scope = AARCH_FUNCTION_NONE; |
| 3262 |
aarch_enable_bti = 0; |
| 3263 |
} |
| 3264 |
|
| 3265 |
static void |
| 3266 |
arm_handle_standard_branch_protection (void) |
| 3267 |
{ |
| 3268 |
aarch_ra_sign_scope = AARCH_FUNCTION_NON_LEAF; |
| 3269 |
aarch_enable_bti = 1; |
| 3270 |
} |
| 3271 |
|
| 3272 |
static void |
| 3273 |
arm_handle_pac_ret_protection (void) |
| 3274 |
{ |
| 3275 |
aarch_ra_sign_scope = AARCH_FUNCTION_NON_LEAF; |
| 3276 |
} |
| 3277 |
|
| 3278 |
static void |
| 3279 |
arm_handle_pac_ret_leaf (void) |
| 3280 |
{ |
| 3281 |
aarch_ra_sign_scope = AARCH_FUNCTION_ALL; |
| 3282 |
} |
| 3283 |
|
| 3284 |
static void |
| 3285 |
arm_handle_bti_protection (void) |
| 3286 |
{ |
| 3287 |
aarch_enable_bti = 1; |
| 3288 |
} |
| 3289 |
|
| 3290 |
static const struct aarch_branch_protect_type arm_pac_ret_subtypes[] = { |
| 3291 |
{ "leaf", false, arm_handle_pac_ret_leaf, NULL, 0 }, |
| 3292 |
{ NULL, false, NULL, NULL, 0 } |
| 3293 |
}; |
| 3294 |
|
| 3295 |
static const struct aarch_branch_protect_type arm_branch_protect_types[] = { |
| 3296 |
{ "none", true, arm_handle_no_branch_protection, NULL, 0 }, |
| 3297 |
{ "standard", true, arm_handle_standard_branch_protection, NULL, 0 }, |
| 3298 |
{ "pac-ret", false, arm_handle_pac_ret_protection, arm_pac_ret_subtypes, |
| 3299 |
ARRAY_SIZE (arm_pac_ret_subtypes) }, |
| 3300 |
{ "bti", false, arm_handle_bti_protection, NULL, 0 }, |
| 3301 |
{ NULL, false, NULL, NULL, 0 } |
| 3302 |
}; |
| 3303 |
|
| 3304 |
/* Configure a build target TARGET from the user-specified options OPTS and |
| 3305 |
OPTS_SET. If WARN_COMPATIBLE, emit a diagnostic if both the CPU and |
| 3306 |
architecture have been specified, but the two are not identical. */ |
| 3307 |
void |
| 3308 |
arm_configure_build_target (struct arm_build_target *target, |
| 3309 |
struct cl_target_option *opts, |
| 3310 |
bool warn_compatible) |
| 3311 |
{ |
| 3312 |
const cpu_option *arm_selected_tune = NULL; |
| 3313 |
const arch_option *arm_selected_arch = NULL; |
| 3314 |
const cpu_option *arm_selected_cpu = NULL; |
| 3315 |
const arm_fpu_desc *arm_selected_fpu = NULL; |
| 3316 |
const char *tune_opts = NULL; |
| 3317 |
const char *arch_opts = NULL; |
| 3318 |
const char *cpu_opts = NULL; |
| 3319 |
|
| 3320 |
bitmap_clear (target->isa); |
| 3321 |
target->core_name = NULL; |
| 3322 |
target->arch_name = NULL; |
| 3323 |
|
| 3324 |
if (opts->x_arm_arch_string) |
| 3325 |
{ |
| 3326 |
arm_selected_arch = arm_parse_arch_option_name (all_architectures, |
| 3327 |
"-march", |
| 3328 |
opts->x_arm_arch_string); |
| 3329 |
arch_opts = strchr (opts->x_arm_arch_string, '+'); |
| 3330 |
} |
| 3331 |
|
| 3332 |
if (opts->x_arm_cpu_string) |
| 3333 |
{ |
| 3334 |
arm_selected_cpu = arm_parse_cpu_option_name (all_cores, "-mcpu", |
| 3335 |
opts->x_arm_cpu_string); |
| 3336 |
cpu_opts = strchr (opts->x_arm_cpu_string, '+'); |
| 3337 |
arm_selected_tune = arm_selected_cpu; |
| 3338 |
/* If taking the tuning from -mcpu, we don't need to rescan the |
| 3339 |
options for tuning. */ |
| 3340 |
} |
| 3341 |
|
| 3342 |
if (opts->x_arm_tune_string) |
| 3343 |
{ |
| 3344 |
arm_selected_tune = arm_parse_cpu_option_name (all_cores, "-mtune", |
| 3345 |
opts->x_arm_tune_string); |
| 3346 |
tune_opts = strchr (opts->x_arm_tune_string, '+'); |
| 3347 |
} |
| 3348 |
|
| 3349 |
if (opts->x_arm_branch_protection_string) |
| 3350 |
{ |
| 3351 |
aarch_validate_mbranch_protection (arm_branch_protect_types, |
| 3352 |
opts->x_arm_branch_protection_string, |
| 3353 |
"-mbranch-protection="); |
| 3354 |
} |
| 3355 |
|
| 3356 |
if (arm_selected_arch) |
| 3357 |
{ |
| 3358 |
arm_initialize_isa (target->isa, arm_selected_arch->common.isa_bits); |
| 3359 |
arm_parse_option_features (target->isa, &arm_selected_arch->common, |
| 3360 |
arch_opts); |
| 3361 |
|
| 3362 |
if (arm_selected_cpu) |
| 3363 |
{ |
| 3364 |
auto_sbitmap cpu_isa (isa_num_bits); |
| 3365 |
auto_sbitmap isa_delta (isa_num_bits); |
| 3366 |
|
| 3367 |
arm_initialize_isa (cpu_isa, arm_selected_cpu->common.isa_bits); |
| 3368 |
arm_parse_option_features (cpu_isa, &arm_selected_cpu->common, |
| 3369 |
cpu_opts); |
| 3370 |
bitmap_xor (isa_delta, cpu_isa, target->isa); |
| 3371 |
/* Ignore any bits that are quirk bits. */ |
| 3372 |
bitmap_and_compl (isa_delta, isa_delta, isa_quirkbits); |
| 3373 |
/* If the user (or the default configuration) has specified a |
| 3374 |
specific FPU, then ignore any bits that depend on the FPU |
| 3375 |
configuration. Do similarly if using the soft-float |
| 3376 |
ABI. */ |
| 3377 |
if (opts->x_arm_fpu_index != TARGET_FPU_auto |
| 3378 |
|| arm_float_abi == ARM_FLOAT_ABI_SOFT) |
| 3379 |
bitmap_and_compl (isa_delta, isa_delta, isa_all_fpbits); |
| 3380 |
|
| 3381 |
if (!bitmap_empty_p (isa_delta)) |
| 3382 |
{ |
| 3383 |
if (warn_compatible) |
| 3384 |
warning (0, "switch %<-mcpu=%s%> conflicts " |
| 3385 |
"with switch %<-march=%s%>", |
| 3386 |
opts->x_arm_cpu_string, |
| 3387 |
opts->x_arm_arch_string); |
| 3388 |
|
| 3389 |
/* -march wins for code generation. |
| 3390 |
-mcpu wins for default tuning. */ |
| 3391 |
if (!arm_selected_tune) |
| 3392 |
arm_selected_tune = arm_selected_cpu; |
| 3393 |
|
| 3394 |
arm_selected_cpu = all_cores + arm_selected_arch->tune_id; |
| 3395 |
target->arch_name = arm_selected_arch->common.name; |
| 3396 |
} |
| 3397 |
else |
| 3398 |
{ |
| 3399 |
/* Architecture and CPU are essentially the same. |
| 3400 |
Prefer the CPU setting. */ |
| 3401 |
arm_selected_arch = all_architectures + arm_selected_cpu->arch; |
| 3402 |
target->core_name = arm_selected_cpu->common.name; |
| 3403 |
/* Copy the CPU's capabilities, so that we inherit the |
| 3404 |
appropriate extensions and quirks. */ |
| 3405 |
bitmap_copy (target->isa, cpu_isa); |
| 3406 |
} |
| 3407 |
} |
| 3408 |
else |
| 3409 |
{ |
| 3410 |
/* Pick a CPU based on the architecture. */ |
| 3411 |
arm_selected_cpu = all_cores + arm_selected_arch->tune_id; |
| 3412 |
target->arch_name = arm_selected_arch->common.name; |
| 3413 |
/* Note: target->core_name is left unset in this path. */ |
| 3414 |
} |
| 3415 |
} |
| 3416 |
else if (arm_selected_cpu) |
| 3417 |
{ |
| 3418 |
target->core_name = arm_selected_cpu->common.name; |
| 3419 |
arm_initialize_isa (target->isa, arm_selected_cpu->common.isa_bits); |
| 3420 |
arm_parse_option_features (target->isa, &arm_selected_cpu->common, |
| 3421 |
cpu_opts); |
| 3422 |
arm_selected_arch = all_architectures + arm_selected_cpu->arch; |
| 3423 |
} |
| 3424 |
/* If the user did not specify a processor or architecture, choose |
| 3425 |
one for them. */ |
| 3426 |
else |
| 3427 |
{ |
| 3428 |
const cpu_option *sel; |
| 3429 |
auto_sbitmap sought_isa (isa_num_bits); |
| 3430 |
bitmap_clear (sought_isa); |
| 3431 |
auto_sbitmap default_isa (isa_num_bits); |
| 3432 |
|
| 3433 |
arm_selected_cpu = arm_parse_cpu_option_name (all_cores, "default CPU", |
| 3434 |
TARGET_CPU_DEFAULT); |
| 3435 |
cpu_opts = strchr (TARGET_CPU_DEFAULT, '+'); |
| 3436 |
gcc_assert (arm_selected_cpu->common.name); |
| 3437 |
|
| 3438 |
/* RWE: All of the selection logic below (to the end of this |
| 3439 |
'if' clause) looks somewhat suspect. It appears to be mostly |
| 3440 |
there to support forcing thumb support when the default CPU |
| 3441 |
does not have thumb (somewhat dubious in terms of what the |
| 3442 |
user might be expecting). I think it should be removed once |
| 3443 |
support for the pre-thumb era cores is removed. */ |
| 3444 |
sel = arm_selected_cpu; |
| 3445 |
arm_initialize_isa (default_isa, sel->common.isa_bits); |
| 3446 |
arm_parse_option_features (default_isa, &arm_selected_cpu->common, |
| 3447 |
cpu_opts); |
| 3448 |
|
| 3449 |
/* Now check to see if the user has specified any command line |
| 3450 |
switches that require certain abilities from the cpu. */ |
| 3451 |
|
| 3452 |
if (TARGET_INTERWORK || TARGET_THUMB) |
| 3453 |
bitmap_set_bit (sought_isa, isa_bit_thumb); |
| 3454 |
|
| 3455 |
/* If there are such requirements and the default CPU does not |
| 3456 |
satisfy them, we need to run over the complete list of |
| 3457 |
cores looking for one that is satisfactory. */ |
| 3458 |
if (!bitmap_empty_p (sought_isa) |
| 3459 |
&& !bitmap_subset_p (sought_isa, default_isa)) |
| 3460 |
{ |
| 3461 |
auto_sbitmap candidate_isa (isa_num_bits); |
| 3462 |
/* We're only interested in a CPU with at least the |
| 3463 |
capabilities of the default CPU and the required |
| 3464 |
additional features. */ |
| 3465 |
bitmap_ior (default_isa, default_isa, sought_isa); |
| 3466 |
|
| 3467 |
/* Try to locate a CPU type that supports all of the abilities |
| 3468 |
of the default CPU, plus the extra abilities requested by |
| 3469 |
the user. */ |
| 3470 |
for (sel = all_cores; sel->common.name != NULL; sel++) |
| 3471 |
{ |
| 3472 |
arm_initialize_isa (candidate_isa, sel->common.isa_bits); |
| 3473 |
/* An exact match? */ |
| 3474 |
if (bitmap_equal_p (default_isa, candidate_isa)) |
| 3475 |
break; |
| 3476 |
} |
| 3477 |
|
| 3478 |
if (sel->common.name == NULL) |
| 3479 |
{ |
| 3480 |
unsigned current_bit_count = isa_num_bits; |
| 3481 |
const cpu_option *best_fit = NULL; |
| 3482 |
|
| 3483 |
/* Ideally we would like to issue an error message here |
| 3484 |
saying that it was not possible to find a CPU compatible |
| 3485 |
with the default CPU, but which also supports the command |
| 3486 |
line options specified by the programmer, and so they |
| 3487 |
ought to use the -mcpu=<name> command line option to |
| 3488 |
override the default CPU type. |
| 3489 |
|
| 3490 |
If we cannot find a CPU that has exactly the |
| 3491 |
characteristics of the default CPU and the given |
| 3492 |
command line options we scan the array again looking |
| 3493 |
for a best match. The best match must have at least |
| 3494 |
the capabilities of the perfect match. */ |
| 3495 |
for (sel = all_cores; sel->common.name != NULL; sel++) |
| 3496 |
{ |
| 3497 |
arm_initialize_isa (candidate_isa, sel->common.isa_bits); |
| 3498 |
|
| 3499 |
if (bitmap_subset_p (default_isa, candidate_isa)) |
| 3500 |
{ |
| 3501 |
unsigned count; |
| 3502 |
|
| 3503 |
bitmap_and_compl (candidate_isa, candidate_isa, |
| 3504 |
default_isa); |
| 3505 |
count = bitmap_popcount (candidate_isa); |
| 3506 |
|
| 3507 |
if (count < current_bit_count) |
| 3508 |
{ |
| 3509 |
best_fit = sel; |
| 3510 |
current_bit_count = count; |
| 3511 |
} |
| 3512 |
} |
| 3513 |
|
| 3514 |
gcc_assert (best_fit); |
| 3515 |
sel = best_fit; |
| 3516 |
} |
| 3517 |
} |
| 3518 |
arm_selected_cpu = sel; |
| 3519 |
} |
| 3520 |
|
| 3521 |
/* Now we know the CPU, we can finally initialize the target |
| 3522 |
structure. */ |
| 3523 |
target->core_name = arm_selected_cpu->common.name; |
| 3524 |
arm_initialize_isa (target->isa, arm_selected_cpu->common.isa_bits); |
| 3525 |
arm_parse_option_features (target->isa, &arm_selected_cpu->common, |
| 3526 |
cpu_opts); |
| 3527 |
arm_selected_arch = all_architectures + arm_selected_cpu->arch; |
| 3528 |
} |
| 3529 |
|
| 3530 |
gcc_assert (arm_selected_cpu); |
| 3531 |
gcc_assert (arm_selected_arch); |
| 3532 |
|
| 3533 |
if (opts->x_arm_fpu_index != TARGET_FPU_auto) |
| 3534 |
{ |
| 3535 |
arm_selected_fpu = &all_fpus[opts->x_arm_fpu_index]; |
| 3536 |
auto_sbitmap fpu_bits (isa_num_bits); |
| 3537 |
|
| 3538 |
arm_initialize_isa (fpu_bits, arm_selected_fpu->isa_bits); |
| 3539 |
/* This should clear out ALL bits relating to the FPU/simd |
| 3540 |
extensions, to avoid potentially invalid combinations later on |
| 3541 |
that we can't match. At present we only clear out those bits |
| 3542 |
that can be set by -mfpu. This should be fixed in GCC-12. */ |
| 3543 |
bitmap_and_compl (target->isa, target->isa, isa_all_fpubits_internal); |
| 3544 |
bitmap_ior (target->isa, target->isa, fpu_bits); |
| 3545 |
} |
| 3546 |
|
| 3547 |
/* If we have the soft-float ABI, clear any feature bits relating to use of |
| 3548 |
floating-point operations. They'll just confuse things later on. */ |
| 3549 |
if (arm_float_abi == ARM_FLOAT_ABI_SOFT) |
| 3550 |
bitmap_and_compl (target->isa, target->isa, isa_all_fpbits); |
| 3551 |
|
| 3552 |
/* There may be implied bits which we still need to enable. These are |
| 3553 |
non-named features which are needed to complete other sets of features, |
| 3554 |
but cannot be enabled from arm-cpus.in due to being shared between |
| 3555 |
multiple fgroups. Each entry in all_implied_fbits is of the form |
| 3556 |
ante -> cons, meaning that if the feature "ante" is enabled, we should |
| 3557 |
implicitly enable "cons". */ |
| 3558 |
const struct fbit_implication *impl = all_implied_fbits; |
| 3559 |
while (impl->ante) |
| 3560 |
{ |
| 3561 |
if (bitmap_bit_p (target->isa, impl->ante)) |
| 3562 |
bitmap_set_bit (target->isa, impl->cons); |
| 3563 |
impl++; |
| 3564 |
} |
| 3565 |
|
| 3566 |
if (!arm_selected_tune) |
| 3567 |
arm_selected_tune = arm_selected_cpu; |
| 3568 |
else /* Validate the features passed to -mtune. */ |
| 3569 |
arm_parse_option_features (NULL, &arm_selected_tune->common, tune_opts); |
| 3570 |
|
| 3571 |
const cpu_tune *tune_data = &all_tunes[arm_selected_tune - all_cores]; |
| 3572 |
|
| 3573 |
/* Finish initializing the target structure. */ |
| 3574 |
if (!target->arch_name) |
| 3575 |
target->arch_name = arm_selected_arch->common.name; |
| 3576 |
target->arch_pp_name = arm_selected_arch->arch; |
| 3577 |
target->base_arch = arm_selected_arch->base_arch; |
| 3578 |
target->profile = arm_selected_arch->profile; |
| 3579 |
|
| 3580 |
target->tune_flags = tune_data->tune_flags; |
| 3581 |
target->tune = tune_data->tune; |
| 3582 |
target->tune_core = tune_data->scheduler; |
| 3583 |
} |
| 3584 |
|
| 3585 |
/* Fix up any incompatible options that the user has specified. */ |
| 3586 |
static void |
| 3587 |
arm_option_override (void) |
| 3588 |
{ |
| 3589 |
static const enum isa_feature fpu_bitlist_internal[] |
| 3590 |
= { ISA_ALL_FPU_INTERNAL, isa_nobit }; |
| 3591 |
/* isa_bit_mve_float is also part of FP bit list for arch v8.1-m.main. */ |
| 3592 |
static const enum isa_feature fp_bitlist[] |
| 3593 |
= { ISA_ALL_FP, isa_bit_mve_float, isa_nobit }; |
| 3594 |
static const enum isa_feature quirk_bitlist[] = { ISA_ALL_QUIRKS, isa_nobit}; |
| 3595 |
cl_target_option opts; |
| 3596 |
|
| 3597 |
isa_quirkbits = sbitmap_alloc (isa_num_bits); |
| 3598 |
arm_initialize_isa (isa_quirkbits, quirk_bitlist); |
| 3599 |
|
| 3600 |
isa_all_fpubits_internal = sbitmap_alloc (isa_num_bits); |
| 3601 |
isa_all_fpbits = sbitmap_alloc (isa_num_bits); |
| 3602 |
arm_initialize_isa (isa_all_fpubits_internal, fpu_bitlist_internal); |
| 3603 |
arm_initialize_isa (isa_all_fpbits, fp_bitlist); |
| 3604 |
|
| 3605 |
arm_active_target.isa = sbitmap_alloc (isa_num_bits); |
| 3606 |
|
| 3607 |
if (!OPTION_SET_P (arm_fpu_index)) |
| 3608 |
{ |
| 3609 |
bool ok; |
| 3610 |
int fpu_index; |
| 3611 |
|
| 3612 |
ok = opt_enum_arg_to_value (OPT_mfpu_, FPUTYPE_AUTO, &fpu_index, |
| 3613 |
CL_TARGET); |
| 3614 |
gcc_assert (ok); |
| 3615 |
arm_fpu_index = (enum fpu_type) fpu_index; |
| 3616 |
} |
| 3617 |
|
| 3618 |
cl_target_option_save (&opts, &global_options, &global_options_set); |
| 3619 |
arm_configure_build_target (&arm_active_target, &opts, true); |
| 3620 |
|
| 3621 |
#ifdef SUBTARGET_OVERRIDE_OPTIONS |
| 3622 |
SUBTARGET_OVERRIDE_OPTIONS; |
| 3623 |
#endif |
| 3624 |
|
| 3625 |
/* Initialize boolean versions of the architectural flags, for use |
| 3626 |
in the arm.md file and for enabling feature flags. */ |
| 3627 |
arm_option_reconfigure_globals (); |
| 3628 |
|
| 3629 |
arm_tune = arm_active_target.tune_core; |
| 3630 |
tune_flags = arm_active_target.tune_flags; |
| 3631 |
current_tune = arm_active_target.tune; |
| 3632 |
|
| 3633 |
/* TBD: Dwarf info for apcs frame is not handled yet. */ |
| 3634 |
if (TARGET_APCS_FRAME) |
| 3635 |
flag_shrink_wrap = false; |
| 3636 |
|
| 3637 |
if (TARGET_APCS_STACK && !TARGET_APCS_FRAME) |
| 3638 |
{ |
| 3639 |
warning (0, "%<-mapcs-stack-check%> incompatible with " |
| 3640 |
"%<-mno-apcs-frame%>"); |
| 3641 |
target_flags |= MASK_APCS_FRAME; |
| 3642 |
} |
| 3643 |
|
| 3644 |
if (TARGET_POKE_FUNCTION_NAME) |
| 3645 |
target_flags |= MASK_APCS_FRAME; |
| 3646 |
|
| 3647 |
if (TARGET_APCS_REENT && flag_pic) |
| 3648 |
error ("%<-fpic%> and %<-mapcs-reent%> are incompatible"); |
| 3649 |
|
| 3650 |
if (TARGET_APCS_REENT) |
| 3651 |
warning (0, "APCS reentrant code not supported. Ignored"); |
| 3652 |
|
| 3653 |
/* Set up some tuning parameters. */ |
| 3654 |
arm_ld_sched = (tune_flags & TF_LDSCHED) != 0; |
| 3655 |
arm_tune_strongarm = (tune_flags & TF_STRONG) != 0; |
| 3656 |
arm_tune_wbuf = (tune_flags & TF_WBUF) != 0; |
| 3657 |
arm_tune_xscale = (tune_flags & TF_XSCALE) != 0; |
| 3658 |
arm_tune_cortex_a9 = (arm_tune == TARGET_CPU_cortexa9) != 0; |
| 3659 |
arm_m_profile_small_mul = (tune_flags & TF_SMALLMUL) != 0; |
| 3660 |
|
| 3661 |
/* For arm2/3 there is no need to do any scheduling if we are doing |
| 3662 |
software floating-point. */ |
| 3663 |
if (TARGET_SOFT_FLOAT && (tune_flags & TF_NO_MODE32)) |
| 3664 |
flag_schedule_insns = flag_schedule_insns_after_reload = 0; |
| 3665 |
|
| 3666 |
/* Override the default structure alignment for AAPCS ABI. */ |
| 3667 |
if (!OPTION_SET_P (arm_structure_size_boundary)) |
| 3668 |
{ |
| 3669 |
if (TARGET_AAPCS_BASED) |
| 3670 |
arm_structure_size_boundary = 8; |
| 3671 |
} |
| 3672 |
else |
| 3673 |
{ |
| 3674 |
warning (0, "option %<-mstructure-size-boundary%> is deprecated"); |
| 3675 |
|
| 3676 |
if (arm_structure_size_boundary != 8 |
| 3677 |
&& arm_structure_size_boundary != 32 |
| 3678 |
&& !(ARM_DOUBLEWORD_ALIGN && arm_structure_size_boundary == 64)) |
| 3679 |
{ |
| 3680 |
if (ARM_DOUBLEWORD_ALIGN) |
| 3681 |
warning (0, |
| 3682 |
"structure size boundary can only be set to 8, 32 or 64"); |
| 3683 |
else |
| 3684 |
warning (0, "structure size boundary can only be set to 8 or 32"); |
| 3685 |
arm_structure_size_boundary |
| 3686 |
= (TARGET_AAPCS_BASED ? 8 : DEFAULT_STRUCTURE_SIZE_BOUNDARY); |
| 3687 |
} |
| 3688 |
} |
| 3689 |
|
| 3690 |
if (TARGET_VXWORKS_RTP) |
| 3691 |
{ |
| 3692 |
if (!OPTION_SET_P (arm_pic_data_is_text_relative)) |
| 3693 |
arm_pic_data_is_text_relative = 0; |
| 3694 |
} |
| 3695 |
else if (flag_pic |
| 3696 |
&& !arm_pic_data_is_text_relative |
| 3697 |
&& !(OPTION_SET_P (target_flags) & MASK_SINGLE_PIC_BASE)) |
| 3698 |
/* When text & data segments don't have a fixed displacement, the |
| 3699 |
intended use is with a single, read only, pic base register. |
| 3700 |
Unless the user explicitly requested not to do that, set |
| 3701 |
it. */ |
| 3702 |
target_flags |= MASK_SINGLE_PIC_BASE; |
| 3703 |
|
| 3704 |
/* If stack checking is disabled, we can use r10 as the PIC register, |
| 3705 |
which keeps r9 available. The EABI specifies r9 as the PIC register. */ |
| 3706 |
if (flag_pic && TARGET_SINGLE_PIC_BASE) |
| 3707 |
{ |
| 3708 |
if (TARGET_VXWORKS_RTP) |
| 3709 |
warning (0, "RTP PIC is incompatible with %<-msingle-pic-base%>"); |
| 3710 |
arm_pic_register = (TARGET_APCS_STACK || TARGET_AAPCS_BASED) ? 9 : 10; |
| 3711 |
} |
| 3712 |
|
| 3713 |
if (flag_pic && TARGET_VXWORKS_RTP) |
| 3714 |
arm_pic_register = 9; |
| 3715 |
|
| 3716 |
/* If in FDPIC mode then force arm_pic_register to be r9. */ |
| 3717 |
if (TARGET_FDPIC) |
| 3718 |
{ |
| 3719 |
arm_pic_register = FDPIC_REGNUM; |
| 3720 |
if (TARGET_THUMB1) |
| 3721 |
sorry ("FDPIC mode is not supported in Thumb-1 mode"); |
| 3722 |
} |
| 3723 |
|
| 3724 |
if (arm_pic_register_string != NULL) |
| 3725 |
{ |
| 3726 |
int pic_register = decode_reg_name (arm_pic_register_string); |
| 3727 |
|
| 3728 |
if (!flag_pic) |
| 3729 |
warning (0, "%<-mpic-register=%> is useless without %<-fpic%>"); |
| 3730 |
|
| 3731 |
/* Prevent the user from choosing an obviously stupid PIC register. */ |
| 3732 |
else if (pic_register < 0 || call_used_or_fixed_reg_p (pic_register) |
| 3733 |
|| pic_register == HARD_FRAME_POINTER_REGNUM |
| 3734 |
|| pic_register == STACK_POINTER_REGNUM |
| 3735 |
|| pic_register >= PC_REGNUM |
| 3736 |
|| (TARGET_VXWORKS_RTP |
| 3737 |
&& (unsigned int) pic_register != arm_pic_register)) |
| 3738 |
error ("unable to use %qs for PIC register", arm_pic_register_string); |
| 3739 |
else |
| 3740 |
arm_pic_register = pic_register; |
| 3741 |
} |
| 3742 |
|
| 3743 |
if (flag_pic) |
| 3744 |
target_word_relocations = 1; |
| 3745 |
|
| 3746 |
/* Enable -mfix-cortex-m3-ldrd by default for Cortex-M3 cores. */ |
| 3747 |
if (fix_cm3_ldrd == 2) |
| 3748 |
{ |
| 3749 |
if (bitmap_bit_p (arm_active_target.isa, isa_bit_quirk_cm3_ldrd)) |
| 3750 |
fix_cm3_ldrd = 1; |
| 3751 |
else |
| 3752 |
fix_cm3_ldrd = 0; |
| 3753 |
} |
| 3754 |
|
| 3755 |
/* Enable fix_vlldm by default if required. */ |
| 3756 |
if (fix_vlldm == 2) |
| 3757 |
{ |
| 3758 |
if (bitmap_bit_p (arm_active_target.isa, isa_bit_quirk_vlldm)) |
| 3759 |
fix_vlldm = 1; |
| 3760 |
else |
| 3761 |
fix_vlldm = 0; |
| 3762 |
} |
| 3763 |
|
| 3764 |
/* Enable fix_aes by default if required. */ |
| 3765 |
if (fix_aes_erratum_1742098 == 2) |
| 3766 |
{ |
| 3767 |
if (bitmap_bit_p (arm_active_target.isa, isa_bit_quirk_aes_1742098)) |
| 3768 |
fix_aes_erratum_1742098 = 1; |
| 3769 |
else |
| 3770 |
fix_aes_erratum_1742098 = 0; |
| 3771 |
} |
| 3772 |
|
| 3773 |
/* Hot/Cold partitioning is not currently supported, since we can't |
| 3774 |
handle literal pool placement in that case. */ |
| 3775 |
if (flag_reorder_blocks_and_partition) |
| 3776 |
{ |
| 3777 |
inform (input_location, |
| 3778 |
"%<-freorder-blocks-and-partition%> not supported " |
| 3779 |
"on this architecture"); |
| 3780 |
flag_reorder_blocks_and_partition = 0; |
| 3781 |
flag_reorder_blocks = 1; |
| 3782 |
} |
| 3783 |
|
| 3784 |
if (flag_pic) |
| 3785 |
/* Hoisting PIC address calculations more aggressively provides a small, |
| 3786 |
but measurable, size reduction for PIC code. Therefore, we decrease |
| 3787 |
the bar for unrestricted expression hoisting to the cost of PIC address |
| 3788 |
calculation, which is 2 instructions. */ |
| 3789 |
SET_OPTION_IF_UNSET (&global_options, &global_options_set, |
| 3790 |
param_gcse_unrestricted_cost, 2); |
| 3791 |
|
| 3792 |
/* ARM EABI defaults to strict volatile bitfields. */ |
| 3793 |
if (TARGET_AAPCS_BASED && flag_strict_volatile_bitfields < 0 |
| 3794 |
&& abi_version_at_least(2)) |
| 3795 |
flag_strict_volatile_bitfields = 1; |
| 3796 |
|
| 3797 |
/* Enable sw prefetching at -O3 for CPUS that have prefetch, and we |
| 3798 |
have deemed it beneficial (signified by setting |
| 3799 |
prefetch.num_slots to 1 or more). */ |
| 3800 |
if (flag_prefetch_loop_arrays < 0 |
| 3801 |
&& HAVE_prefetch |
| 3802 |
&& optimize >= 3 |
| 3803 |
&& current_tune->prefetch.num_slots > 0) |
| 3804 |
flag_prefetch_loop_arrays = 1; |
| 3805 |
|
| 3806 |
/* Set up parameters to be used in prefetching algorithm. Do not |
| 3807 |
override the defaults unless we are tuning for a core we have |
| 3808 |
researched values for. */ |
| 3809 |
if (current_tune->prefetch.num_slots > 0) |
| 3810 |
SET_OPTION_IF_UNSET (&global_options, &global_options_set, |
| 3811 |
param_simultaneous_prefetches, |
| 3812 |
current_tune->prefetch.num_slots); |
| 3813 |
if (current_tune->prefetch.l1_cache_line_size >= 0) |
| 3814 |
SET_OPTION_IF_UNSET (&global_options, &global_options_set, |
| 3815 |
param_l1_cache_line_size, |
| 3816 |
current_tune->prefetch.l1_cache_line_size); |
| 3817 |
if (current_tune->prefetch.l1_cache_line_size >= 0) |
| 3818 |
{ |
| 3819 |
SET_OPTION_IF_UNSET (&global_options, &global_options_set, |
| 3820 |
param_destruct_interfere_size, |
| 3821 |
current_tune->prefetch.l1_cache_line_size); |
| 3822 |
SET_OPTION_IF_UNSET (&global_options, &global_options_set, |
| 3823 |
param_construct_interfere_size, |
| 3824 |
current_tune->prefetch.l1_cache_line_size); |
| 3825 |
} |
| 3826 |
else |
| 3827 |
{ |
| 3828 |
/* For a generic ARM target, JF Bastien proposed using 64 for both. */ |
| 3829 |
/* ??? Cortex A9 has a 32-byte cache line, so why not 32 for |
| 3830 |
constructive? */ |
| 3831 |
/* More recent Cortex chips have a 64-byte cache line, but are marked |
| 3832 |
ARM_PREFETCH_NOT_BENEFICIAL, so they get these defaults. */ |
| 3833 |
SET_OPTION_IF_UNSET (&global_options, &global_options_set, |
| 3834 |
param_destruct_interfere_size, 64); |
| 3835 |
SET_OPTION_IF_UNSET (&global_options, &global_options_set, |
| 3836 |
param_construct_interfere_size, 64); |
| 3837 |
} |
| 3838 |
|
| 3839 |
if (current_tune->prefetch.l1_cache_size >= 0) |
| 3840 |
SET_OPTION_IF_UNSET (&global_options, &global_options_set, |
| 3841 |
param_l1_cache_size, |
| 3842 |
current_tune->prefetch.l1_cache_size); |
| 3843 |
|
| 3844 |
/* Look through ready list and all of queue for instructions |
| 3845 |
relevant for L2 auto-prefetcher. */ |
| 3846 |
int sched_autopref_queue_depth; |
| 3847 |
|
| 3848 |
switch (current_tune->sched_autopref) |
| 3849 |
{ |
| 3850 |
case tune_params::SCHED_AUTOPREF_OFF: |
| 3851 |
sched_autopref_queue_depth = -1; |
| 3852 |
break; |
| 3853 |
|
| 3854 |
case tune_params::SCHED_AUTOPREF_RANK: |
| 3855 |
sched_autopref_queue_depth = 0; |
| 3856 |
break; |
| 3857 |
|
| 3858 |
case tune_params::SCHED_AUTOPREF_FULL: |
| 3859 |
sched_autopref_queue_depth = max_insn_queue_index + 1; |
| 3860 |
break; |
| 3861 |
|
| 3862 |
default: |
| 3863 |
gcc_unreachable (); |
| 3864 |
} |
| 3865 |
|
| 3866 |
SET_OPTION_IF_UNSET (&global_options, &global_options_set, |
| 3867 |
param_sched_autopref_queue_depth, |
| 3868 |
sched_autopref_queue_depth); |
| 3869 |
|
| 3870 |
/* Currently, for slow flash data, we just disable literal pools. We also |
| 3871 |
disable it for pure-code. */ |
| 3872 |
if (target_slow_flash_data || target_pure_code) |
| 3873 |
arm_disable_literal_pool = true; |
| 3874 |
|
| 3875 |
/* Disable scheduling fusion by default if it's not armv7 processor |
| 3876 |
or doesn't prefer ldrd/strd. */ |
| 3877 |
if (flag_schedule_fusion == 2 |
| 3878 |
&& (!arm_arch7 || !current_tune->prefer_ldrd_strd)) |
| 3879 |
flag_schedule_fusion = 0; |
| 3880 |
|
| 3881 |
/* Need to remember initial options before they are overriden. */ |
| 3882 |
init_optimize = build_optimization_node (&global_options, |
| 3883 |
&global_options_set); |
| 3884 |
|
| 3885 |
arm_options_perform_arch_sanity_checks (); |
| 3886 |
arm_option_override_internal (&global_options, &global_options_set); |
| 3887 |
arm_option_check_internal (&global_options); |
| 3888 |
arm_option_params_internal (); |
| 3889 |
|
| 3890 |
/* Create the default target_options structure. */ |
| 3891 |
target_option_default_node = target_option_current_node |
| 3892 |
= build_target_option_node (&global_options, &global_options_set); |
| 3893 |
|
| 3894 |
/* Register global variables with the garbage collector. */ |
| 3895 |
arm_add_gc_roots (); |
| 3896 |
|
| 3897 |
/* Init initial mode for testing. */ |
| 3898 |
thumb_flipper = TARGET_THUMB; |
| 3899 |
} |
| 3900 |
|
| 3901 |
|
| 3902 |
/* Reconfigure global status flags from the active_target.isa. */ |
| 3903 |
void |
| 3904 |
arm_option_reconfigure_globals (void) |
| 3905 |
{ |
| 3906 |
sprintf (arm_arch_name, "__ARM_ARCH_%s__", arm_active_target.arch_pp_name); |
| 3907 |
arm_base_arch = arm_active_target.base_arch; |
| 3908 |
|
| 3909 |
/* Initialize boolean versions of the architectural flags, for use |
| 3910 |
in the arm.md file. */ |
| 3911 |
arm_arch4 = bitmap_bit_p (arm_active_target.isa, isa_bit_armv4); |
| 3912 |
arm_arch4t = arm_arch4 && bitmap_bit_p (arm_active_target.isa, isa_bit_thumb); |
| 3913 |
arm_arch5t = bitmap_bit_p (arm_active_target.isa, isa_bit_armv5t); |
| 3914 |
arm_arch5te = bitmap_bit_p (arm_active_target.isa, isa_bit_armv5te); |
| 3915 |
arm_arch6 = bitmap_bit_p (arm_active_target.isa, isa_bit_armv6); |
| 3916 |
arm_arch6k = bitmap_bit_p (arm_active_target.isa, isa_bit_armv6k); |
| 3917 |
arm_arch_notm = bitmap_bit_p (arm_active_target.isa, isa_bit_notm); |
| 3918 |
arm_arch6m = arm_arch6 && !arm_arch_notm; |
| 3919 |
arm_arch7 = bitmap_bit_p (arm_active_target.isa, isa_bit_armv7); |
| 3920 |
arm_arch7em = bitmap_bit_p (arm_active_target.isa, isa_bit_armv7em); |
| 3921 |
arm_arch8 = bitmap_bit_p (arm_active_target.isa, isa_bit_armv8); |
| 3922 |
arm_arch8_1 = bitmap_bit_p (arm_active_target.isa, isa_bit_armv8_1); |
| 3923 |
arm_arch8_2 = bitmap_bit_p (arm_active_target.isa, isa_bit_armv8_2); |
| 3924 |
arm_arch8_3 = bitmap_bit_p (arm_active_target.isa, isa_bit_armv8_3); |
| 3925 |
arm_arch8_4 = bitmap_bit_p (arm_active_target.isa, isa_bit_armv8_4); |
| 3926 |
arm_arch8_1m_main = bitmap_bit_p (arm_active_target.isa, |
| 3927 |
isa_bit_armv8_1m_main); |
| 3928 |
arm_arch_thumb1 = bitmap_bit_p (arm_active_target.isa, isa_bit_thumb); |
| 3929 |
arm_arch_thumb2 = bitmap_bit_p (arm_active_target.isa, isa_bit_thumb2); |
| 3930 |
arm_arch_xscale = bitmap_bit_p (arm_active_target.isa, isa_bit_xscale); |
| 3931 |
arm_arch_iwmmxt = bitmap_bit_p (arm_active_target.isa, isa_bit_iwmmxt); |
| 3932 |
arm_arch_iwmmxt2 = bitmap_bit_p (arm_active_target.isa, isa_bit_iwmmxt2); |
| 3933 |
arm_arch_thumb_hwdiv = bitmap_bit_p (arm_active_target.isa, isa_bit_tdiv); |
| 3934 |
arm_arch_arm_hwdiv = bitmap_bit_p (arm_active_target.isa, isa_bit_adiv); |
| 3935 |
arm_arch_crc = bitmap_bit_p (arm_active_target.isa, isa_bit_crc32); |
| 3936 |
arm_arch_cmse = bitmap_bit_p (arm_active_target.isa, isa_bit_cmse); |
| 3937 |
arm_arch8m_main = arm_arch7 && arm_arch_cmse; |
| 3938 |
arm_arch_lpae = bitmap_bit_p (arm_active_target.isa, isa_bit_lpae); |
| 3939 |
arm_arch_i8mm = bitmap_bit_p (arm_active_target.isa, isa_bit_i8mm); |
| 3940 |
arm_arch_bf16 = bitmap_bit_p (arm_active_target.isa, isa_bit_bf16); |
| 3941 |
|
| 3942 |
arm_fp16_inst = bitmap_bit_p (arm_active_target.isa, isa_bit_fp16); |
| 3943 |
if (arm_fp16_inst) |
| 3944 |
{ |
| 3945 |
if (arm_fp16_format == ARM_FP16_FORMAT_ALTERNATIVE) |
| 3946 |
error ("selected fp16 options are incompatible"); |
| 3947 |
arm_fp16_format = ARM_FP16_FORMAT_IEEE; |
| 3948 |
} |
| 3949 |
|
| 3950 |
arm_arch_cde = 0; |
| 3951 |
arm_arch_cde_coproc = 0; |
| 3952 |
int cde_bits[] = {isa_bit_cdecp0, isa_bit_cdecp1, isa_bit_cdecp2, |
| 3953 |
isa_bit_cdecp3, isa_bit_cdecp4, isa_bit_cdecp5, |
| 3954 |
isa_bit_cdecp6, isa_bit_cdecp7}; |
| 3955 |
for (int i = 0, e = ARRAY_SIZE (cde_bits); i < e; i++) |
| 3956 |
{ |
| 3957 |
int cde_bit = bitmap_bit_p (arm_active_target.isa, cde_bits[i]); |
| 3958 |
if (cde_bit) |
| 3959 |
{ |
| 3960 |
arm_arch_cde |= cde_bit; |
| 3961 |
arm_arch_cde_coproc |= arm_arch_cde_coproc_bits[i]; |
| 3962 |
} |
| 3963 |
} |
| 3964 |
|
| 3965 |
/* And finally, set up some quirks. */ |
| 3966 |
arm_arch_no_volatile_ce |
| 3967 |
= bitmap_bit_p (arm_active_target.isa, isa_bit_quirk_no_volatile_ce); |
| 3968 |
arm_arch6kz = arm_arch6k && bitmap_bit_p (arm_active_target.isa, |
| 3969 |
isa_bit_quirk_armv6kz); |
| 3970 |
|
| 3971 |
/* Use the cp15 method if it is available. */ |
| 3972 |
if (target_thread_pointer == TP_AUTO) |
| 3973 |
{ |
| 3974 |
if (arm_arch6k && !TARGET_THUMB1) |
| 3975 |
target_thread_pointer = TP_TPIDRURO; |
| 3976 |
else |
| 3977 |
target_thread_pointer = TP_SOFT; |
| 3978 |
} |
| 3979 |
|
| 3980 |
if (!TARGET_HARD_TP && arm_stack_protector_guard == SSP_TLSREG) |
| 3981 |
error("%<-mstack-protector-guard=tls%> needs a hardware TLS register"); |
| 3982 |
} |
| 3983 |
|
| 3984 |
/* Perform some validation between the desired architecture and the rest of the |
| 3985 |
options. */ |
| 3986 |
void |
| 3987 |
arm_options_perform_arch_sanity_checks (void) |
| 3988 |
{ |
| 3989 |
/* V5T code we generate is completely interworking capable, so we turn off |
| 3990 |
TARGET_INTERWORK here to avoid many tests later on. */ |
| 3991 |
|
| 3992 |
/* XXX However, we must pass the right pre-processor defines to CPP |
| 3993 |
or GLD can get confused. This is a hack. */ |
| 3994 |
if (TARGET_INTERWORK) |
| 3995 |
arm_cpp_interwork = 1; |
| 3996 |
|
| 3997 |
if (arm_arch5t) |
| 3998 |
target_flags &= ~MASK_INTERWORK; |
| 3999 |
|
| 4000 |
if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN) |
| 4001 |
error ("iwmmxt requires an AAPCS compatible ABI for proper operation"); |
| 4002 |
|
| 4003 |
if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT) |
| 4004 |
error ("iwmmxt abi requires an iwmmxt capable cpu"); |
| 4005 |
|
| 4006 |
/* BPABI targets use linker tricks to allow interworking on cores |
| 4007 |
without thumb support. */ |
| 4008 |
if (TARGET_INTERWORK |
| 4009 |
&& !TARGET_BPABI |
| 4010 |
&& !bitmap_bit_p (arm_active_target.isa, isa_bit_thumb)) |
| 4011 |
{ |
| 4012 |
warning (0, "target CPU does not support interworking" ); |
| 4013 |
target_flags &= ~MASK_INTERWORK; |
| 4014 |
} |
| 4015 |
|
| 4016 |
/* If soft-float is specified then don't use FPU. */ |
| 4017 |
if (TARGET_SOFT_FLOAT) |
| 4018 |
arm_fpu_attr = FPU_NONE; |
| 4019 |
else |
| 4020 |
arm_fpu_attr = FPU_VFP; |
| 4021 |
|
| 4022 |
if (TARGET_AAPCS_BASED) |
| 4023 |
{ |
| 4024 |
if (TARGET_CALLER_INTERWORKING) |
| 4025 |
error ("AAPCS does not support %<-mcaller-super-interworking%>"); |
| 4026 |
else |
| 4027 |
if (TARGET_CALLEE_INTERWORKING) |
| 4028 |
error ("AAPCS does not support %<-mcallee-super-interworking%>"); |
| 4029 |
} |
| 4030 |
|
| 4031 |
/* __fp16 support currently assumes the core has ldrh. */ |
| 4032 |
if (!arm_arch4 && arm_fp16_format != ARM_FP16_FORMAT_NONE) |
| 4033 |
sorry ("%<__fp16%> and no ldrh"); |
| 4034 |
|
| 4035 |
if (use_cmse && !arm_arch_cmse) |
| 4036 |
error ("target CPU does not support ARMv8-M Security Extensions"); |
| 4037 |
|
| 4038 |
/* We don't clear D16-D31 VFP registers for cmse_nonsecure_call functions |
| 4039 |
and ARMv8-M Baseline and Mainline do not allow such configuration. */ |
| 4040 |
if (use_cmse && TARGET_HARD_FLOAT && LAST_VFP_REGNUM > LAST_LO_VFP_REGNUM) |
| 4041 |
error ("ARMv8-M Security Extensions incompatible with selected FPU"); |
| 4042 |
|
| 4043 |
|
| 4044 |
if (TARGET_AAPCS_BASED) |
| 4045 |
{ |
| 4046 |
if (arm_abi == ARM_ABI_IWMMXT) |
| 4047 |
arm_pcs_default = ARM_PCS_AAPCS_IWMMXT; |
| 4048 |
else if (TARGET_HARD_FLOAT_ABI) |
| 4049 |
{ |
| 4050 |
arm_pcs_default = ARM_PCS_AAPCS_VFP; |
| 4051 |
if (!bitmap_bit_p (arm_active_target.isa, isa_bit_vfpv2) |
| 4052 |
&& !bitmap_bit_p (arm_active_target.isa, isa_bit_mve)) |
| 4053 |
error ("%<-mfloat-abi=hard%>: selected architecture lacks an FPU"); |
| 4054 |
} |
| 4055 |
else |
| 4056 |
arm_pcs_default = ARM_PCS_AAPCS; |
| 4057 |
} |
| 4058 |
else |
| 4059 |
{ |
| 4060 |
if (arm_float_abi == ARM_FLOAT_ABI_HARD) |
| 4061 |
sorry ("%<-mfloat-abi=hard%> and VFP"); |
| 4062 |
|
| 4063 |
if (arm_abi == ARM_ABI_APCS) |
| 4064 |
arm_pcs_default = ARM_PCS_APCS; |
| 4065 |
else |
| 4066 |
arm_pcs_default = ARM_PCS_ATPCS; |
| 4067 |
} |
| 4068 |
} |
| 4069 |
|
| 4070 |
/* Test whether a local function descriptor is canonical, i.e., |
| 4071 |
whether we can use GOTOFFFUNCDESC to compute the address of the |
| 4072 |
function. */ |
| 4073 |
static bool |
| 4074 |
arm_fdpic_local_funcdesc_p (rtx fnx) |
| 4075 |
{ |
| 4076 |
tree fn; |
| 4077 |
enum symbol_visibility vis; |
| 4078 |
bool ret; |
| 4079 |
|
| 4080 |
if (!TARGET_FDPIC) |
| 4081 |
return true; |
| 4082 |
|
| 4083 |
if (! SYMBOL_REF_LOCAL_P (fnx)) |
| 4084 |
return false; |
| 4085 |
|
| 4086 |
fn = SYMBOL_REF_DECL (fnx); |
| 4087 |
|
| 4088 |
if (! fn) |
| 4089 |
return false; |
| 4090 |
|
| 4091 |
vis = DECL_VISIBILITY (fn); |
| 4092 |
|
| 4093 |
if (vis == VISIBILITY_PROTECTED) |
| 4094 |
/* Private function descriptors for protected functions are not |
| 4095 |
canonical. Temporarily change the visibility to global so that |
| 4096 |
we can ensure uniqueness of funcdesc pointers. */ |
| 4097 |
DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT; |
| 4098 |
|
| 4099 |
ret = default_binds_local_p_1 (fn, flag_pic); |
| 4100 |
|
| 4101 |
DECL_VISIBILITY (fn) = vis; |
| 4102 |
|
| 4103 |
return ret; |
| 4104 |
} |
| 4105 |
|
| 4106 |
static void |
| 4107 |
arm_add_gc_roots (void) |
| 4108 |
{ |
| 4109 |
gcc_obstack_init(&minipool_obstack); |
| 4110 |
minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0); |
| 4111 |
} |
| 4112 |
|
| 4113 |
/* A table of known ARM exception types. |
| 4114 |
For use with the interrupt function attribute. */ |
| 4115 |
|
| 4116 |
typedef struct |
| 4117 |
{ |
| 4118 |
const char *const arg; |
| 4119 |
const unsigned long return_value; |
| 4120 |
} |
| 4121 |
isr_attribute_arg; |
| 4122 |
|
| 4123 |
static const isr_attribute_arg isr_attribute_args [] = |
| 4124 |
{ |
| 4125 |
{ "IRQ", ARM_FT_ISR }, |
| 4126 |
{ "irq", ARM_FT_ISR }, |
| 4127 |
{ "FIQ", ARM_FT_FIQ }, |
| 4128 |
{ "fiq", ARM_FT_FIQ }, |
| 4129 |
{ "ABORT", ARM_FT_ISR }, |
| 4130 |
{ "abort", ARM_FT_ISR }, |
| 4131 |
{ "UNDEF", ARM_FT_EXCEPTION }, |
| 4132 |
{ "undef", ARM_FT_EXCEPTION }, |
| 4133 |
{ "SWI", ARM_FT_EXCEPTION }, |
| 4134 |
{ "swi", ARM_FT_EXCEPTION }, |
| 4135 |
{ NULL, ARM_FT_NORMAL } |
| 4136 |
}; |
| 4137 |
|
| 4138 |
/* Returns the (interrupt) function type of the current |
| 4139 |
function, or ARM_FT_UNKNOWN if the type cannot be determined. */ |
| 4140 |
|
| 4141 |
static unsigned long |
| 4142 |
arm_isr_value (tree argument) |
| 4143 |
{ |
| 4144 |
const isr_attribute_arg * ptr; |
| 4145 |
const char * arg; |
| 4146 |
|
| 4147 |
if (!arm_arch_notm) |
| 4148 |
return ARM_FT_NORMAL | ARM_FT_STACKALIGN; |
| 4149 |
|
| 4150 |
/* No argument - default to IRQ. */ |
| 4151 |
if (argument == NULL_TREE) |
| 4152 |
return ARM_FT_ISR; |
| 4153 |
|
| 4154 |
/* Get the value of the argument. */ |
| 4155 |
if (TREE_VALUE (argument) == NULL_TREE |
| 4156 |
|| TREE_CODE (TREE_VALUE (argument)) != STRING_CST) |
| 4157 |
return ARM_FT_UNKNOWN; |
| 4158 |
|
| 4159 |
arg = TREE_STRING_POINTER (TREE_VALUE (argument)); |
| 4160 |
|
| 4161 |
/* Check it against the list of known arguments. */ |
| 4162 |
for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++) |
| 4163 |
if (streq (arg, ptr->arg)) |
| 4164 |
return ptr->return_value; |
| 4165 |
|
| 4166 |
/* An unrecognized interrupt type. */ |
| 4167 |
return ARM_FT_UNKNOWN; |
| 4168 |
} |
| 4169 |
|
| 4170 |
/* Computes the type of the current function. */ |
| 4171 |
|
| 4172 |
static unsigned long |
| 4173 |
arm_compute_func_type (void) |
| 4174 |
{ |
| 4175 |
unsigned long type = ARM_FT_UNKNOWN; |
| 4176 |
tree a; |
| 4177 |
tree attr; |
| 4178 |
|
| 4179 |
gcc_assert (TREE_CODE (current_function_decl) == FUNCTION_DECL); |
| 4180 |
|
| 4181 |
/* Decide if the current function is volatile. Such functions |
| 4182 |
never return, and many memory cycles can be saved by not storing |
| 4183 |
register values that will never be needed again. This optimization |
| 4184 |
was added to speed up context switching in a kernel application. */ |
| 4185 |
if (optimize > 0 |
| 4186 |
&& (TREE_NOTHROW (current_function_decl) |
| 4187 |
|| !(flag_unwind_tables |
| 4188 |
|| (flag_exceptions |
| 4189 |
&& arm_except_unwind_info (&global_options) != UI_SJLJ))) |
| 4190 |
&& TREE_THIS_VOLATILE (current_function_decl)) |
| 4191 |
type |= ARM_FT_VOLATILE; |
| 4192 |
|
| 4193 |
if (cfun->static_chain_decl != NULL) |
| 4194 |
type |= ARM_FT_NESTED; |
| 4195 |
|
| 4196 |
attr = DECL_ATTRIBUTES (current_function_decl); |
| 4197 |
|
| 4198 |
a = lookup_attribute ("naked", attr); |
| 4199 |
if (a != NULL_TREE) |
| 4200 |
type |= ARM_FT_NAKED; |
| 4201 |
|
| 4202 |
a = lookup_attribute ("isr", attr); |
| 4203 |
if (a == NULL_TREE) |
| 4204 |
a = lookup_attribute ("interrupt", attr); |
| 4205 |
|
| 4206 |
if (a == NULL_TREE) |
| 4207 |
type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL; |
| 4208 |
else |
| 4209 |
type |= arm_isr_value (TREE_VALUE (a)); |
| 4210 |
|
| 4211 |
if (lookup_attribute ("cmse_nonsecure_entry", attr)) |
| 4212 |
type |= ARM_FT_CMSE_ENTRY; |
| 4213 |
|
| 4214 |
return type; |
| 4215 |
} |
| 4216 |
|
| 4217 |
/* Returns the type of the current function. */ |
| 4218 |
|
| 4219 |
unsigned long |
| 4220 |
arm_current_func_type (void) |
| 4221 |
{ |
| 4222 |
if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN) |
| 4223 |
cfun->machine->func_type = arm_compute_func_type (); |
| 4224 |
|
| 4225 |
return cfun->machine->func_type; |
| 4226 |
} |
| 4227 |
|
| 4228 |
bool |
| 4229 |
arm_allocate_stack_slots_for_args (void) |
| 4230 |
{ |
| 4231 |
/* Naked functions should not allocate stack slots for arguments. */ |
| 4232 |
return !IS_NAKED (arm_current_func_type ()); |
| 4233 |
} |
| 4234 |
|
| 4235 |
static bool |
| 4236 |
arm_warn_func_return (tree decl) |
| 4237 |
{ |
| 4238 |
/* Naked functions are implemented entirely in assembly, including the |
| 4239 |
return sequence, so suppress warnings about this. */ |
| 4240 |
return lookup_attribute ("naked", DECL_ATTRIBUTES (decl)) == NULL_TREE; |
| 4241 |
} |
| 4242 |
|
| 4243 |
|
| 4244 |
/* Output assembler code for a block containing the constant parts |
| 4245 |
of a trampoline, leaving space for the variable parts. |
| 4246 |
|
| 4247 |
On the ARM, (if r8 is the static chain regnum, and remembering that |
| 4248 |
referencing pc adds an offset of 8) the trampoline looks like: |
| 4249 |
ldr r8, [pc, #0] |
| 4250 |
ldr pc, [pc] |
| 4251 |
.word static chain value |
| 4252 |
.word function's address |
| 4253 |
XXX FIXME: When the trampoline returns, r8 will be clobbered. |
| 4254 |
|
| 4255 |
In FDPIC mode, the trampoline looks like: |
| 4256 |
.word trampoline address |
| 4257 |
.word trampoline GOT address |
| 4258 |
ldr r12, [pc, #8] ; #4 for Arm mode |
| 4259 |
ldr r9, [pc, #8] ; #4 for Arm mode |
| 4260 |
ldr pc, [pc, #8] ; #4 for Arm mode |
| 4261 |
.word static chain value |
| 4262 |
.word GOT address |
| 4263 |
.word function's address |
| 4264 |
*/ |
| 4265 |
|
| 4266 |
static void |
| 4267 |
arm_asm_trampoline_template (FILE *f) |
| 4268 |
{ |
| 4269 |
fprintf (f, "\t.syntax unified\n"); |
| 4270 |
|
| 4271 |
if (TARGET_FDPIC) |
| 4272 |
{ |
| 4273 |
/* The first two words are a function descriptor pointing to the |
| 4274 |
trampoline code just below. */ |
| 4275 |
if (TARGET_ARM) |
| 4276 |
fprintf (f, "\t.arm\n"); |
| 4277 |
else if (TARGET_THUMB2) |
| 4278 |
fprintf (f, "\t.thumb\n"); |
| 4279 |
else |
| 4280 |
/* Only ARM and Thumb-2 are supported. */ |
| 4281 |
gcc_unreachable (); |
| 4282 |
|
| 4283 |
assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); |
| 4284 |
assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); |
| 4285 |
/* Trampoline code which sets the static chain register but also |
| 4286 |
PIC register before jumping into real code. */ |
| 4287 |
asm_fprintf (f, "\tldr\t%r, [%r, #%d]\n", |
| 4288 |
STATIC_CHAIN_REGNUM, PC_REGNUM, |
| 4289 |
TARGET_THUMB2 ? 8 : 4); |
| 4290 |
asm_fprintf (f, "\tldr\t%r, [%r, #%d]\n", |
| 4291 |
PIC_OFFSET_TABLE_REGNUM, PC_REGNUM, |
| 4292 |
TARGET_THUMB2 ? 8 : 4); |
| 4293 |
asm_fprintf (f, "\tldr\t%r, [%r, #%d]\n", |
| 4294 |
PC_REGNUM, PC_REGNUM, |
| 4295 |
TARGET_THUMB2 ? 8 : 4); |
| 4296 |
assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); |
| 4297 |
} |
| 4298 |
else if (TARGET_ARM) |
| 4299 |
{ |
| 4300 |
fprintf (f, "\t.arm\n"); |
| 4301 |
asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", STATIC_CHAIN_REGNUM, PC_REGNUM); |
| 4302 |
asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", PC_REGNUM, PC_REGNUM); |
| 4303 |
} |
| 4304 |
else if (TARGET_THUMB2) |
| 4305 |
{ |
| 4306 |
fprintf (f, "\t.thumb\n"); |
| 4307 |
/* The Thumb-2 trampoline is similar to the arm implementation. |
| 4308 |
Unlike 16-bit Thumb, we enter the stub in thumb mode. */ |
| 4309 |
asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n", |
| 4310 |
STATIC_CHAIN_REGNUM, PC_REGNUM); |
| 4311 |
asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n", PC_REGNUM, PC_REGNUM); |
| 4312 |
} |
| 4313 |
else |
| 4314 |
{ |
| 4315 |
ASM_OUTPUT_ALIGN (f, 2); |
| 4316 |
fprintf (f, "\t.code\t16\n"); |
| 4317 |
fprintf (f, ".Ltrampoline_start:\n"); |
| 4318 |
asm_fprintf (f, "\tpush\t{r0, r1}\n"); |
| 4319 |
asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM); |
| 4320 |
asm_fprintf (f, "\tmov\t%r, r0\n", STATIC_CHAIN_REGNUM); |
| 4321 |
asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM); |
| 4322 |
asm_fprintf (f, "\tstr\tr0, [%r, #4]\n", SP_REGNUM); |
| 4323 |
asm_fprintf (f, "\tpop\t{r0, %r}\n", PC_REGNUM); |
| 4324 |
} |
| 4325 |
assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); |
| 4326 |
assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); |
| 4327 |
} |
| 4328 |
|
| 4329 |
/* Emit RTL insns to initialize the variable parts of a trampoline. */ |
| 4330 |
|
| 4331 |
static void |
| 4332 |
arm_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) |
| 4333 |
{ |
| 4334 |
rtx fnaddr, mem, a_tramp; |
| 4335 |
|
| 4336 |
emit_block_move (m_tramp, assemble_trampoline_template (), |
| 4337 |
GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL); |
| 4338 |
|
| 4339 |
if (TARGET_FDPIC) |
| 4340 |
{ |
| 4341 |
rtx funcdesc = XEXP (DECL_RTL (fndecl), 0); |
| 4342 |
rtx fnaddr = gen_rtx_MEM (Pmode, funcdesc); |
| 4343 |
rtx gotaddr = gen_rtx_MEM (Pmode, plus_constant (Pmode, funcdesc, 4)); |
| 4344 |
/* The function start address is at offset 8, but in Thumb mode |
| 4345 |
we want bit 0 set to 1 to indicate Thumb-ness, hence 9 |
| 4346 |
below. */ |
| 4347 |
rtx trampoline_code_start |
| 4348 |
= plus_constant (Pmode, XEXP (m_tramp, 0), TARGET_THUMB2 ? 9 : 8); |
| 4349 |
|
| 4350 |
/* Write initial funcdesc which points to the trampoline. */ |
| 4351 |
mem = adjust_address (m_tramp, SImode, 0); |
| 4352 |
emit_move_insn (mem, trampoline_code_start); |
| 4353 |
mem = adjust_address (m_tramp, SImode, 4); |
| 4354 |
emit_move_insn (mem, gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM)); |
| 4355 |
/* Setup static chain. */ |
| 4356 |
mem = adjust_address (m_tramp, SImode, 20); |
| 4357 |
emit_move_insn (mem, chain_value); |
| 4358 |
/* GOT + real function entry point. */ |
| 4359 |
mem = adjust_address (m_tramp, SImode, 24); |
| 4360 |
emit_move_insn (mem, gotaddr); |
| 4361 |
mem = adjust_address (m_tramp, SImode, 28); |
| 4362 |
emit_move_insn (mem, fnaddr); |
| 4363 |
} |
| 4364 |
else |
| 4365 |
{ |
| 4366 |
mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 8 : 12); |
| 4367 |
emit_move_insn (mem, chain_value); |
| 4368 |
|
| 4369 |
mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 12 : 16); |
| 4370 |
fnaddr = XEXP (DECL_RTL (fndecl), 0); |
| 4371 |
emit_move_insn (mem, fnaddr); |
| 4372 |
} |
| 4373 |
|
| 4374 |
a_tramp = XEXP (m_tramp, 0); |
| 4375 |
maybe_emit_call_builtin___clear_cache (a_tramp, |
| 4376 |
plus_constant (ptr_mode, |
| 4377 |
a_tramp, |
| 4378 |
TRAMPOLINE_SIZE)); |
| 4379 |
} |
| 4380 |
|
| 4381 |
/* Thumb trampolines should be entered in thumb mode, so set |
| 4382 |
the bottom bit of the address. */ |
| 4383 |
|
| 4384 |
static rtx |
| 4385 |
arm_trampoline_adjust_address (rtx addr) |
| 4386 |
{ |
| 4387 |
/* For FDPIC don't fix trampoline address since it's a function |
| 4388 |
descriptor and not a function address. */ |
| 4389 |
if (TARGET_THUMB && !TARGET_FDPIC) |
| 4390 |
addr = expand_simple_binop (Pmode, IOR, addr, const1_rtx, |
| 4391 |
NULL, 0, OPTAB_LIB_WIDEN); |
| 4392 |
return addr; |
| 4393 |
} |
| 4394 |
|
| 4395 |
/* Return 1 if REG needs to be saved. For interrupt handlers, this |
| 4396 |
includes call-clobbered registers too. If this is a leaf function |
| 4397 |
we can just examine the registers used by the RTL, but otherwise we |
| 4398 |
have to assume that whatever function is called might clobber |
| 4399 |
anything, and so we have to save all the call-clobbered registers |
| 4400 |
as well. */ |
| 4401 |
static inline bool reg_needs_saving_p (unsigned reg) |
| 4402 |
{ |
| 4403 |
unsigned long func_type = arm_current_func_type (); |
| 4404 |
|
| 4405 |
if (IS_INTERRUPT (func_type)) |
| 4406 |
if (df_regs_ever_live_p (reg) |
| 4407 |
/* Save call-clobbered core registers. */ |
| 4408 |
|| (! crtl->is_leaf && call_used_or_fixed_reg_p (reg) && reg < FIRST_VFP_REGNUM)) |
| 4409 |
return true; |
| 4410 |
else |
| 4411 |
return false; |
| 4412 |
else |
| 4413 |
if (!df_regs_ever_live_p (reg) |
| 4414 |
|| call_used_or_fixed_reg_p (reg)) |
| 4415 |
return false; |
| 4416 |
else |
| 4417 |
return true; |
| 4418 |
} |
| 4419 |
|
| 4420 |
/* Return 1 if it is possible to return using a single instruction. |
| 4421 |
If SIBLING is non-null, this is a test for a return before a sibling |
| 4422 |
call. SIBLING is the call insn, so we can examine its register usage. */ |
| 4423 |
|
| 4424 |
int |
| 4425 |
use_return_insn (int iscond, rtx sibling) |
| 4426 |
{ |
| 4427 |
int regno; |
| 4428 |
unsigned int func_type; |
| 4429 |
unsigned long saved_int_regs; |
| 4430 |
unsigned HOST_WIDE_INT stack_adjust; |
| 4431 |
arm_stack_offsets *offsets; |
| 4432 |
|
| 4433 |
/* Never use a return instruction before reload has run. */ |
| 4434 |
if (!reload_completed) |
| 4435 |
return 0; |
| 4436 |
|
| 4437 |
/* Never use a return instruction when return address signing |
| 4438 |
mechanism is enabled as it requires more than one |
| 4439 |
instruction. */ |
| 4440 |
if (arm_current_function_pac_enabled_p ()) |
| 4441 |
return 0; |
| 4442 |
|
| 4443 |
func_type = arm_current_func_type (); |
| 4444 |
|
| 4445 |
/* Naked, volatile and stack alignment functions need special |
| 4446 |
consideration. */ |
| 4447 |
if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED | ARM_FT_STACKALIGN)) |
| 4448 |
return 0; |
| 4449 |
|
| 4450 |
/* So do interrupt functions that use the frame pointer and Thumb |
| 4451 |
interrupt functions. */ |
| 4452 |
if (IS_INTERRUPT (func_type) && (frame_pointer_needed || TARGET_THUMB)) |
| 4453 |
return 0; |
| 4454 |
|
| 4455 |
if (TARGET_LDRD && current_tune->prefer_ldrd_strd |
| 4456 |
&& !optimize_function_for_size_p (cfun)) |
| 4457 |
return 0; |
| 4458 |
|
| 4459 |
offsets = arm_get_frame_offsets (); |
| 4460 |
stack_adjust = offsets->outgoing_args - offsets->saved_regs; |
| 4461 |
|
| 4462 |
/* As do variadic functions. */ |
| 4463 |
if (crtl->args.pretend_args_size |
| 4464 |
|| cfun->machine->uses_anonymous_args |
| 4465 |
/* Or if the function calls __builtin_eh_return () */ |
| 4466 |
|| crtl->calls_eh_return |
| 4467 |
/* Or if the function calls alloca */ |
| 4468 |
|| cfun->calls_alloca |
| 4469 |
/* Or if there is a stack adjustment. However, if the stack pointer |
| 4470 |
is saved on the stack, we can use a pre-incrementing stack load. */ |
| 4471 |
|| !(stack_adjust == 0 || (TARGET_APCS_FRAME && frame_pointer_needed |
| 4472 |
&& stack_adjust == 4)) |
| 4473 |
/* Or if the static chain register was saved above the frame, under the |
| 4474 |
assumption that the stack pointer isn't saved on the stack. */ |
| 4475 |
|| (!(TARGET_APCS_FRAME && frame_pointer_needed) |
| 4476 |
&& arm_compute_static_chain_stack_bytes() != 0)) |
| 4477 |
return 0; |
| 4478 |
|
| 4479 |
saved_int_regs = offsets->saved_regs_mask; |
| 4480 |
|
| 4481 |
/* Unfortunately, the insn |
| 4482 |
|
| 4483 |
ldmib sp, {..., sp, ...} |
| 4484 |
|
| 4485 |
triggers a bug on most SA-110 based devices, such that the stack |
| 4486 |
pointer won't be correctly restored if the instruction takes a |
| 4487 |
page fault. We work around this problem by popping r3 along with |
| 4488 |
the other registers, since that is never slower than executing |
| 4489 |
another instruction. |
| 4490 |
|
| 4491 |
We test for !arm_arch5t here, because code for any architecture |
| 4492 |
less than this could potentially be run on one of the buggy |
| 4493 |
chips. */ |
| 4494 |
if (stack_adjust == 4 && !arm_arch5t && TARGET_ARM) |
| 4495 |
{ |
| 4496 |
/* Validate that r3 is a call-clobbered register (always true in |
| 4497 |
the default abi) ... */ |
| 4498 |
if (!call_used_or_fixed_reg_p (3)) |
| 4499 |
return 0; |
| 4500 |
|
| 4501 |
/* ... that it isn't being used for a return value ... */ |
| 4502 |
if (arm_size_return_regs () >= (4 * UNITS_PER_WORD)) |
| 4503 |
return 0; |
| 4504 |
|
| 4505 |
/* ... or for a tail-call argument ... */ |
| 4506 |
if (sibling) |
| 4507 |
{ |
| 4508 |
gcc_assert (CALL_P (sibling)); |
| 4509 |
|
| 4510 |
if (find_regno_fusage (sibling, USE, 3)) |
| 4511 |
return 0; |
| 4512 |
} |
| 4513 |
|
| 4514 |
/* ... and that there are no call-saved registers in r0-r2 |
| 4515 |
(always true in the default ABI). */ |
| 4516 |
if (saved_int_regs & 0x7) |
| 4517 |
return 0; |
| 4518 |
} |
| 4519 |
|
| 4520 |
/* Can't be done if interworking with Thumb, and any registers have been |
| 4521 |
stacked. */ |
| 4522 |
if (TARGET_INTERWORK && saved_int_regs != 0 && !IS_INTERRUPT(func_type)) |
| 4523 |
return 0; |
| 4524 |
|
| 4525 |
/* On StrongARM, conditional returns are expensive if they aren't |
| 4526 |
taken and multiple registers have been stacked. */ |
| 4527 |
if (iscond && arm_tune_strongarm) |
| 4528 |
{ |
| 4529 |
/* Conditional return when just the LR is stored is a simple |
| 4530 |
conditional-load instruction, that's not expensive. */ |
| 4531 |
if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM)) |
| 4532 |
return 0; |
| 4533 |
|
| 4534 |
if (flag_pic |
| 4535 |
&& arm_pic_register != INVALID_REGNUM |
| 4536 |
&& df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM)) |
| 4537 |
return 0; |
| 4538 |
} |
| 4539 |
|
| 4540 |
/* ARMv8-M nonsecure entry function need to use bxns to return and thus need |
| 4541 |
several instructions if anything needs to be popped. Armv8.1-M Mainline |
| 4542 |
also needs several instructions to save and restore FP context. */ |
| 4543 |
if (IS_CMSE_ENTRY (func_type) && (saved_int_regs || TARGET_HAVE_FPCXT_CMSE)) |
| 4544 |
return 0; |
| 4545 |
|
| 4546 |
/* If there are saved registers but the LR isn't saved, then we need |
| 4547 |
two instructions for the return. */ |
| 4548 |
if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM))) |
| 4549 |
return 0; |
| 4550 |
|
| 4551 |
/* Can't be done if any of the VFP regs are pushed, |
| 4552 |
since this also requires an insn. */ |
| 4553 |
if (TARGET_VFP_BASE) |
| 4554 |
for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++) |
| 4555 |
if (reg_needs_saving_p (regno)) |
| 4556 |
return 0; |
| 4557 |
|
| 4558 |
if (TARGET_REALLY_IWMMXT) |
| 4559 |
for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++) |
| 4560 |
if (reg_needs_saving_p (regno)) |
| 4561 |
return 0; |
| 4562 |
|
| 4563 |
return 1; |
| 4564 |
} |
| 4565 |
|
| 4566 |
/* Return TRUE if we should try to use a simple_return insn, i.e. perform |
| 4567 |
shrink-wrapping if possible. This is the case if we need to emit a |
| 4568 |
prologue, which we can test by looking at the offsets. */ |
| 4569 |
bool |
| 4570 |
use_simple_return_p (void) |
| 4571 |
{ |
| 4572 |
arm_stack_offsets *offsets; |
| 4573 |
|
| 4574 |
/* Note this function can be called before or after reload. */ |
| 4575 |
if (!reload_completed) |
| 4576 |
arm_compute_frame_layout (); |
| 4577 |
|
| 4578 |
offsets = arm_get_frame_offsets (); |
| 4579 |
return offsets->outgoing_args != 0; |
| 4580 |
} |
| 4581 |
|
| 4582 |
/* Return TRUE if int I is a valid immediate ARM constant. */ |
| 4583 |
|
| 4584 |
int |
| 4585 |
const_ok_for_arm (HOST_WIDE_INT i) |
| 4586 |
{ |
| 4587 |
int lowbit; |
| 4588 |
|
| 4589 |
/* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must |
| 4590 |
be all zero, or all one. */ |
| 4591 |
if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0 |
| 4592 |
&& ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) |
| 4593 |
!= ((~(unsigned HOST_WIDE_INT) 0) |
| 4594 |
& ~(unsigned HOST_WIDE_INT) 0xffffffff))) |
| 4595 |
return FALSE; |
| 4596 |
|
| 4597 |
i &= (unsigned HOST_WIDE_INT) 0xffffffff; |
| 4598 |
|
| 4599 |
/* Fast return for 0 and small values. We must do this for zero, since |
| 4600 |
the code below can't handle that one case. */ |
| 4601 |
if ((i & ~(unsigned HOST_WIDE_INT) 0xff) == 0) |
| 4602 |
return TRUE; |
| 4603 |
|
| 4604 |
/* Get the number of trailing zeros. */ |
| 4605 |
lowbit = ffs((int) i) - 1; |
| 4606 |
|
| 4607 |
/* Only even shifts are allowed in ARM mode so round down to the |
| 4608 |
nearest even number. */ |
| 4609 |
if (TARGET_ARM) |
| 4610 |
lowbit &= ~1; |
| 4611 |
|
| 4612 |
if ((i & ~(((unsigned HOST_WIDE_INT) 0xff) << lowbit)) == 0) |
| 4613 |
return TRUE; |
| 4614 |
|
| 4615 |
if (TARGET_ARM) |
| 4616 |
{ |
| 4617 |
/* Allow rotated constants in ARM mode. */ |
| 4618 |
if (lowbit <= 4 |
| 4619 |
&& ((i & ~0xc000003f) == 0 |
| 4620 |
|| (i & ~0xf000000f) == 0 |
| 4621 |
|| (i & ~0xfc000003) == 0)) |
| 4622 |
return TRUE; |
| 4623 |
} |
| 4624 |
else if (TARGET_THUMB2) |
| 4625 |
{ |
| 4626 |
HOST_WIDE_INT v; |
| 4627 |
|
| 4628 |
/* Allow repeated patterns 0x00XY00XY or 0xXYXYXYXY. */ |
| 4629 |
v = i & 0xff; |
| 4630 |
v |= v << 16; |
| 4631 |
if (i == v || i == (v | (v << 8))) |
| 4632 |
return TRUE; |
| 4633 |
|
| 4634 |
/* Allow repeated pattern 0xXY00XY00. */ |
| 4635 |
v = i & 0xff00; |
| 4636 |
v |= v << 16; |
| 4637 |
if (i == v) |
| 4638 |
return TRUE; |
| 4639 |
} |
| 4640 |
else if (TARGET_HAVE_MOVT) |
| 4641 |
{ |
| 4642 |
/* Thumb-1 Targets with MOVT. */ |
| 4643 |
if (i > 0xffff) |
| 4644 |
return FALSE; |
| 4645 |
else |
| 4646 |
return TRUE; |
| 4647 |
} |
| 4648 |
|
| 4649 |
return FALSE; |
| 4650 |
} |
| 4651 |
|
| 4652 |
/* Return true if I is a valid constant for the operation CODE. */ |
| 4653 |
int |
| 4654 |
const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code) |
| 4655 |
{ |
| 4656 |
if (const_ok_for_arm (i)) |
| 4657 |
return 1; |
| 4658 |
|
| 4659 |
switch (code) |
| 4660 |
{ |
| 4661 |
case SET: |
| 4662 |
/* See if we can use movw. */ |
| 4663 |
if (TARGET_HAVE_MOVT && (i & 0xffff0000) == 0) |
| 4664 |
return 1; |
| 4665 |
else |
| 4666 |
/* Otherwise, try mvn. */ |
| 4667 |
return const_ok_for_arm (ARM_SIGN_EXTEND (~i)); |
| 4668 |
|
| 4669 |
case PLUS: |
| 4670 |
/* See if we can use addw or subw. */ |
| 4671 |
if (TARGET_THUMB2 |
| 4672 |
&& ((i & 0xfffff000) == 0 |
| 4673 |
|| ((-i) & 0xfffff000) == 0)) |
| 4674 |
return 1; |
| 4675 |
/* Fall through. */ |
| 4676 |
case COMPARE: |
| 4677 |
case EQ: |
| 4678 |
case NE: |
| 4679 |
case GT: |
| 4680 |
case LE: |
| 4681 |
case LT: |
| 4682 |
case GE: |
| 4683 |
case GEU: |
| 4684 |
case LTU: |
| 4685 |
case GTU: |
| 4686 |
case LEU: |
| 4687 |
case UNORDERED: |
| 4688 |
case ORDERED: |
| 4689 |
case UNEQ: |
| 4690 |
case UNGE: |
| 4691 |
case UNLT: |
| 4692 |
case UNGT: |
| 4693 |
case UNLE: |
| 4694 |
return const_ok_for_arm (ARM_SIGN_EXTEND (-i)); |
| 4695 |
|
| 4696 |
case MINUS: /* Should only occur with (MINUS I reg) => rsb */ |
| 4697 |
case XOR: |
| 4698 |
return 0; |
| 4699 |
|
| 4700 |
case IOR: |
| 4701 |
if (TARGET_THUMB2) |
| 4702 |
return const_ok_for_arm (ARM_SIGN_EXTEND (~i)); |
| 4703 |
return 0; |
| 4704 |
|
| 4705 |
case AND: |
| 4706 |
return const_ok_for_arm (ARM_SIGN_EXTEND (~i)); |
| 4707 |
|
| 4708 |
default: |
| 4709 |
gcc_unreachable (); |
| 4710 |
} |
| 4711 |
} |
| 4712 |
|
| 4713 |
/* Return true if I is a valid di mode constant for the operation CODE. */ |
| 4714 |
int |
| 4715 |
const_ok_for_dimode_op (HOST_WIDE_INT i, enum rtx_code code) |
| 4716 |
{ |
| 4717 |
HOST_WIDE_INT hi_val = (i >> 32) & 0xFFFFFFFF; |
| 4718 |
HOST_WIDE_INT lo_val = i & 0xFFFFFFFF; |
| 4719 |
rtx hi = GEN_INT (hi_val); |
| 4720 |
rtx lo = GEN_INT (lo_val); |
| 4721 |
|
| 4722 |
if (TARGET_THUMB1) |
| 4723 |
return 0; |
| 4724 |
|
| 4725 |
switch (code) |
| 4726 |
{ |
| 4727 |
case AND: |
| 4728 |
case IOR: |
| 4729 |
case XOR: |
| 4730 |
return const_ok_for_op (hi_val, code) || hi_val == 0xFFFFFFFF |
| 4731 |
|| const_ok_for_op (lo_val, code) || lo_val == 0xFFFFFFFF; |
| 4732 |
case PLUS: |
| 4733 |
return arm_not_operand (hi, SImode) && arm_add_operand (lo, SImode); |
| 4734 |
|
| 4735 |
default: |
| 4736 |
return 0; |
| 4737 |
} |
| 4738 |
} |
| 4739 |
|
| 4740 |
/* Emit a sequence of insns to handle a large constant. |
| 4741 |
CODE is the code of the operation required, it can be any of SET, PLUS, |
| 4742 |
IOR, AND, XOR, MINUS; |
| 4743 |
MODE is the mode in which the operation is being performed; |
| 4744 |
VAL is the integer to operate on; |
| 4745 |
SOURCE is the other operand (a register, or a null-pointer for SET); |
| 4746 |
SUBTARGETS means it is safe to create scratch registers if that will |
| 4747 |
either produce a simpler sequence, or we will want to cse the values. |
| 4748 |
Return value is the number of insns emitted. */ |
| 4749 |
|
| 4750 |
/* ??? Tweak this for thumb2. */ |
| 4751 |
int |
| 4752 |
arm_split_constant (enum rtx_code code, machine_mode mode, rtx insn, |
| 4753 |
HOST_WIDE_INT val, rtx target, rtx source, int subtargets) |
| 4754 |
{ |
| 4755 |
rtx cond; |
| 4756 |
|
| 4757 |
if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC) |
| 4758 |
cond = COND_EXEC_TEST (PATTERN (insn)); |
| 4759 |
else |
| 4760 |
cond = NULL_RTX; |
| 4761 |
|
| 4762 |
if (subtargets || code == SET |
| 4763 |
|| (REG_P (target) && REG_P (source) |
| 4764 |
&& REGNO (target) != REGNO (source))) |
| 4765 |
{ |
| 4766 |
/* After arm_reorg has been called, we can't fix up expensive |
| 4767 |
constants by pushing them into memory so we must synthesize |
| 4768 |
them in-line, regardless of the cost. This is only likely to |
| 4769 |
be more costly on chips that have load delay slots and we are |
| 4770 |
compiling without running the scheduler (so no splitting |
| 4771 |
occurred before the final instruction emission). |
| 4772 |
|
| 4773 |
Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c |
| 4774 |
*/ |
| 4775 |
if (!cfun->machine->after_arm_reorg |
| 4776 |
&& !cond |
| 4777 |
&& (arm_gen_constant (code, mode, NULL_RTX, val, target, source, |
| 4778 |
1, 0) |
| 4779 |
> (arm_constant_limit (optimize_function_for_size_p (cfun)) |
| 4780 |
+ (code != SET)))) |
| 4781 |
{ |
| 4782 |
if (code == SET) |
| 4783 |
{ |
| 4784 |
/* Currently SET is the only monadic value for CODE, all |
| 4785 |
the rest are diadic. */ |
| 4786 |
if (TARGET_USE_MOVT) |
| 4787 |
arm_emit_movpair (target, GEN_INT (val)); |
| 4788 |
else |
| 4789 |
emit_set_insn (target, GEN_INT (val)); |
| 4790 |
|
| 4791 |
return 1; |
| 4792 |
} |
| 4793 |
else |
| 4794 |
{ |
| 4795 |
rtx temp = subtargets ? gen_reg_rtx (mode) : target; |
| 4796 |
|
| 4797 |
if (TARGET_USE_MOVT) |
| 4798 |
arm_emit_movpair (temp, GEN_INT (val)); |
| 4799 |
else |
| 4800 |
emit_set_insn (temp, GEN_INT (val)); |
| 4801 |
|
| 4802 |
/* For MINUS, the value is subtracted from, since we never |
| 4803 |
have subtraction of a constant. */ |
| 4804 |
if (code == MINUS) |
| 4805 |
emit_set_insn (target, gen_rtx_MINUS (mode, temp, source)); |
| 4806 |
else |
| 4807 |
emit_set_insn (target, |
| 4808 |
gen_rtx_fmt_ee (code, mode, source, temp)); |
| 4809 |
return 2; |
| 4810 |
} |
| 4811 |
} |
| 4812 |
} |
| 4813 |
|
| 4814 |
return arm_gen_constant (code, mode, cond, val, target, source, subtargets, |
| 4815 |
1); |
| 4816 |
} |
| 4817 |
|
| 4818 |
/* Return a sequence of integers, in RETURN_SEQUENCE that fit into |
| 4819 |
ARM/THUMB2 immediates, and add up to VAL. |
| 4820 |
Thr function return value gives the number of insns required. */ |
| 4821 |
static int |
| 4822 |
optimal_immediate_sequence (enum rtx_code code, unsigned HOST_WIDE_INT val, |
| 4823 |
struct four_ints *return_sequence) |
| 4824 |
{ |
| 4825 |
int best_consecutive_zeros = 0; |
| 4826 |
int i; |
| 4827 |
int best_start = 0; |
| 4828 |
int insns1, insns2; |
| 4829 |
struct four_ints tmp_sequence; |
| 4830 |
|
| 4831 |
/* If we aren't targeting ARM, the best place to start is always at |
| 4832 |
the bottom, otherwise look more closely. */ |
| 4833 |
if (TARGET_ARM) |
| 4834 |
{ |
| 4835 |
for (i = 0; i < 32; i += 2) |
| 4836 |
{ |
| 4837 |
int consecutive_zeros = 0; |
| 4838 |
|
| 4839 |
if (!(val & (3 << i))) |
| 4840 |
{ |
| 4841 |
while ((i < 32) && !(val & (3 << i))) |
| 4842 |
{ |
| 4843 |
consecutive_zeros += 2; |
| 4844 |
i += 2; |
| 4845 |
} |
| 4846 |
if (consecutive_zeros > best_consecutive_zeros) |
| 4847 |
{ |
| 4848 |
best_consecutive_zeros = consecutive_zeros; |
| 4849 |
best_start = i - consecutive_zeros; |
| 4850 |
} |
| 4851 |
i -= 2; |
| 4852 |
} |
| 4853 |
} |
| 4854 |
} |
| 4855 |
|
| 4856 |
/* So long as it won't require any more insns to do so, it's |
| 4857 |
desirable to emit a small constant (in bits 0...9) in the last |
| 4858 |
insn. This way there is more chance that it can be combined with |
| 4859 |
a later addressing insn to form a pre-indexed load or store |
| 4860 |
operation. Consider: |
| 4861 |
|
| 4862 |
*((volatile int *)0xe0000100) = 1; |
| 4863 |
*((volatile int *)0xe0000110) = 2; |
| 4864 |
|
| 4865 |
We want this to wind up as: |
| 4866 |
|
| 4867 |
mov rA, #0xe0000000 |
| 4868 |
mov rB, #1 |
| 4869 |
str rB, [rA, #0x100] |
| 4870 |
mov rB, #2 |
| 4871 |
str rB, [rA, #0x110] |
| 4872 |
|
| 4873 |
rather than having to synthesize both large constants from scratch. |
| 4874 |
|
| 4875 |
Therefore, we calculate how many insns would be required to emit |
| 4876 |
the constant starting from `best_start', and also starting from |
| 4877 |
zero (i.e. with bit 31 first to be output). If `best_start' doesn't |
| 4878 |
yield a shorter sequence, we may as well use zero. */ |
| 4879 |
insns1 = optimal_immediate_sequence_1 (code, val, return_sequence, best_start); |
| 4880 |
if (best_start != 0 |
| 4881 |
&& ((HOST_WIDE_INT_1U << best_start) < val)) |
| 4882 |
{ |
| 4883 |
insns2 = optimal_immediate_sequence_1 (code, val, &tmp_sequence, 0); |
| 4884 |
if (insns2 <= insns1) |
| 4885 |
{ |
| 4886 |
*return_sequence = tmp_sequence; |
| 4887 |
insns1 = insns2; |
| 4888 |
} |
| 4889 |
} |
| 4890 |
|
| 4891 |
return insns1; |
| 4892 |
} |
| 4893 |
|
| 4894 |
/* As for optimal_immediate_sequence, but starting at bit-position I. */ |
| 4895 |
static int |
| 4896 |
optimal_immediate_sequence_1 (enum rtx_code code, unsigned HOST_WIDE_INT val, |
| 4897 |
struct four_ints *return_sequence, int i) |
| 4898 |
{ |
| 4899 |
int remainder = val & 0xffffffff; |
| 4900 |
int insns = 0; |
| 4901 |
|
| 4902 |
/* Try and find a way of doing the job in either two or three |
| 4903 |
instructions. |
| 4904 |
|
| 4905 |
In ARM mode we can use 8-bit constants, rotated to any 2-bit aligned |
| 4906 |
location. We start at position I. This may be the MSB, or |
| 4907 |
optimial_immediate_sequence may have positioned it at the largest block |
| 4908 |
of zeros that are aligned on a 2-bit boundary. We then fill up the temps, |
| 4909 |
wrapping around to the top of the word when we drop off the bottom. |
| 4910 |
In the worst case this code should produce no more than four insns. |
| 4911 |
|
| 4912 |
In Thumb2 mode, we can use 32/16-bit replicated constants, and 8-bit |
| 4913 |
constants, shifted to any arbitrary location. We should always start |
| 4914 |
at the MSB. */ |
| 4915 |
do |
| 4916 |
{ |
| 4917 |
int end; |
| 4918 |
unsigned int b1, b2, b3, b4; |
| 4919 |
unsigned HOST_WIDE_INT result; |
| 4920 |
int loc; |
| 4921 |
|
| 4922 |
gcc_assert (insns < 4); |
| 4923 |
|
| 4924 |
if (i <= 0) |
| 4925 |
i += 32; |
| 4926 |
|
| 4927 |
/* First, find the next normal 12/8-bit shifted/rotated immediate. */ |
| 4928 |
if (remainder & ((TARGET_ARM ? (3 << (i - 2)) : (1 << (i - 1))))) |
| 4929 |
{ |
| 4930 |
loc = i; |
| 4931 |
if (i <= 12 && TARGET_THUMB2 && code == PLUS) |
| 4932 |
/* We can use addw/subw for the last 12 bits. */ |
| 4933 |
result = remainder; |
| 4934 |
else |
| 4935 |
{ |
| 4936 |
/* Use an 8-bit shifted/rotated immediate. */ |
| 4937 |
end = i - 8; |
| 4938 |
if (end < 0) |
| 4939 |
end += 32; |
| 4940 |
result = remainder & ((0x0ff << end) |
| 4941 |
| ((i < end) ? (0xff >> (32 - end)) |
| 4942 |
: 0)); |
| 4943 |
i -= 8; |
| 4944 |
} |
| 4945 |
} |
| 4946 |
else |
| 4947 |
{ |
| 4948 |
/* Arm allows rotates by a multiple of two. Thumb-2 allows |
| 4949 |
arbitrary shifts. */ |
| 4950 |
i -= TARGET_ARM ? 2 : 1; |
| 4951 |
continue; |
| 4952 |
} |
| 4953 |
|
| 4954 |
/* Next, see if we can do a better job with a thumb2 replicated |
| 4955 |
constant. |
| 4956 |
|
| 4957 |
We do it this way around to catch the cases like 0x01F001E0 where |
| 4958 |
two 8-bit immediates would work, but a replicated constant would |
| 4959 |
make it worse. |
| 4960 |
|
| 4961 |
TODO: 16-bit constants that don't clear all the bits, but still win. |
| 4962 |
TODO: Arithmetic splitting for set/add/sub, rather than bitwise. */ |
| 4963 |
if (TARGET_THUMB2) |
| 4964 |
{ |
| 4965 |
b1 = (remainder & 0xff000000) >> 24; |
| 4966 |
b2 = (remainder & 0x00ff0000) >> 16; |
| 4967 |
b3 = (remainder & 0x0000ff00) >> 8; |
| 4968 |
b4 = remainder & 0xff; |
| 4969 |
|
| 4970 |
if (loc > 24) |
| 4971 |
{ |
| 4972 |
/* The 8-bit immediate already found clears b1 (and maybe b2), |
| 4973 |
but must leave b3 and b4 alone. */ |
| 4974 |
|
| 4975 |
/* First try to find a 32-bit replicated constant that clears |
| 4976 |
almost everything. We can assume that we can't do it in one, |
| 4977 |
or else we wouldn't be here. */ |
| 4978 |
unsigned int tmp = b1 & b2 & b3 & b4; |
| 4979 |
unsigned int tmp2 = tmp + (tmp << 8) + (tmp << 16) |
| 4980 |
+ (tmp << 24); |
| 4981 |
unsigned int matching_bytes = (tmp == b1) + (tmp == b2) |
| 4982 |
+ (tmp == b3) + (tmp == b4); |
| 4983 |
if (tmp |
| 4984 |
&& (matching_bytes >= 3 |
| 4985 |
|| (matching_bytes == 2 |
| 4986 |
&& const_ok_for_op (remainder & ~tmp2, code)))) |
| 4987 |
{ |
| 4988 |
/* At least 3 of the bytes match, and the fourth has at |
| 4989 |
least as many bits set, or two of the bytes match |
| 4990 |
and it will only require one more insn to finish. */ |
| 4991 |
result = tmp2; |
| 4992 |
i = tmp != b1 ? 32 |
| 4993 |
: tmp != b2 ? 24 |
| 4994 |
: tmp != b3 ? 16 |
| 4995 |
: 8; |
| 4996 |
} |
| 4997 |
|
| 4998 |
/* Second, try to find a 16-bit replicated constant that can |
| 4999 |
leave three of the bytes clear. If b2 or b4 is already |
| 5000 |
zero, then we can. If the 8-bit from above would not |
| 5001 |
clear b2 anyway, then we still win. */ |
| 5002 |
else if (b1 == b3 && (!b2 || !b4 |
| 5003 |
|| (remainder & 0x00ff0000 & ~result))) |
| 5004 |
{ |
| 5005 |
result = remainder & 0xff00ff00; |
| 5006 |
i = 24; |
| 5007 |
} |
| 5008 |
} |
| 5009 |
else if (loc > 16) |
| 5010 |
{ |
| 5011 |
/* The 8-bit immediate already found clears b2 (and maybe b3) |
| 5012 |
and we don't get here unless b1 is alredy clear, but it will |
| 5013 |
leave b4 unchanged. */ |
| 5014 |
|
| 5015 |
/* If we can clear b2 and b4 at once, then we win, since the |
| 5016 |
8-bits couldn't possibly reach that far. */ |
| 5017 |
if (b2 == b4) |
| 5018 |
{ |
| 5019 |
result = remainder & 0x00ff00ff; |
| 5020 |
i = 16; |
| 5021 |
} |
| 5022 |
} |
| 5023 |
} |
| 5024 |
|
| 5025 |
return_sequence->i[insns++] = result; |
| 5026 |
remainder &= ~result; |
| 5027 |
|
| 5028 |
if (code == SET || code == MINUS) |
| 5029 |
code = PLUS; |
| 5030 |
} |
| 5031 |
while (remainder); |
| 5032 |
|
| 5033 |
return insns; |
| 5034 |
} |
| 5035 |
|
| 5036 |
/* Emit an instruction with the indicated PATTERN. If COND is |
| 5037 |
non-NULL, conditionalize the execution of the instruction on COND |
| 5038 |
being true. */ |
| 5039 |
|
| 5040 |
static void |
| 5041 |
emit_constant_insn (rtx cond, rtx pattern) |
| 5042 |
{ |
| 5043 |
if (cond) |
| 5044 |
pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern); |
| 5045 |
emit_insn (pattern); |
| 5046 |
} |
| 5047 |
|
| 5048 |
/* As above, but extra parameter GENERATE which, if clear, suppresses |
| 5049 |
RTL generation. */ |
| 5050 |
|
| 5051 |
static int |
| 5052 |
arm_gen_constant (enum rtx_code code, machine_mode mode, rtx cond, |
| 5053 |
unsigned HOST_WIDE_INT val, rtx target, rtx source, |
| 5054 |
int subtargets, int generate) |
| 5055 |
{ |
| 5056 |
int can_invert = 0; |
| 5057 |
int can_negate = 0; |
| 5058 |
int final_invert = 0; |
| 5059 |
int i; |
| 5060 |
int set_sign_bit_copies = 0; |
| 5061 |
int clear_sign_bit_copies = 0; |
| 5062 |
int clear_zero_bit_copies = 0; |
| 5063 |
int set_zero_bit_copies = 0; |
| 5064 |
int insns = 0, neg_insns, inv_insns; |
| 5065 |
unsigned HOST_WIDE_INT temp1, temp2; |
| 5066 |
unsigned HOST_WIDE_INT remainder = val & 0xffffffff; |
| 5067 |
struct four_ints *immediates; |
| 5068 |
struct four_ints pos_immediates, neg_immediates, inv_immediates; |
| 5069 |
|
| 5070 |
/* Find out which operations are safe for a given CODE. Also do a quick |
| 5071 |
check for degenerate cases; these can occur when DImode operations |
| 5072 |
are split. */ |
| 5073 |
switch (code) |
| 5074 |
{ |
| 5075 |
case SET: |
| 5076 |
can_invert = 1; |
| 5077 |
break; |
| 5078 |
|
| 5079 |
case PLUS: |
| 5080 |
can_negate = 1; |
| 5081 |
break; |
| 5082 |
|
| 5083 |
case IOR: |
| 5084 |
if (remainder == 0xffffffff) |
| 5085 |
{ |
| 5086 |
if (generate) |
| 5087 |
emit_constant_insn (cond, |
| 5088 |
gen_rtx_SET (target, |
| 5089 |
GEN_INT (ARM_SIGN_EXTEND (val)))); |
| 5090 |
return 1; |
| 5091 |
} |
| 5092 |
|
| 5093 |
if (remainder == 0) |
| 5094 |
{ |
| 5095 |
if (reload_completed && rtx_equal_p (target, source)) |
| 5096 |
return 0; |
| 5097 |
|
| 5098 |
if (generate) |
| 5099 |
emit_constant_insn (cond, gen_rtx_SET (target, source)); |
| 5100 |
return 1; |
| 5101 |
} |
| 5102 |
break; |
| 5103 |
|
| 5104 |
case AND: |
| 5105 |
if (remainder == 0) |
| 5106 |
{ |
| 5107 |
if (generate) |
| 5108 |
emit_constant_insn (cond, gen_rtx_SET (target, const0_rtx)); |
| 5109 |
return 1; |
| 5110 |
} |
| 5111 |
if (remainder == 0xffffffff) |
| 5112 |
{ |
| 5113 |
if (reload_completed && rtx_equal_p (target, source)) |
| 5114 |
return 0; |
| 5115 |
if (generate) |
| 5116 |
emit_constant_insn (cond, gen_rtx_SET (target, source)); |
| 5117 |
return 1; |
| 5118 |
} |
| 5119 |
can_invert = 1; |
| 5120 |
break; |
| 5121 |
|
| 5122 |
case XOR: |
| 5123 |
if (remainder == 0) |
| 5124 |
{ |
| 5125 |
if (reload_completed && rtx_equal_p (target, source)) |
| 5126 |
return 0; |
| 5127 |
if (generate) |
| 5128 |
emit_constant_insn (cond, gen_rtx_SET (target, source)); |
| 5129 |
return 1; |
| 5130 |
} |
| 5131 |
|
| 5132 |
if (remainder == 0xffffffff) |
| 5133 |
{ |
| 5134 |
if (generate) |
| 5135 |
emit_constant_insn (cond, |
| 5136 |
gen_rtx_SET (target, |
| 5137 |
gen_rtx_NOT (mode, source))); |
| 5138 |
return 1; |
| 5139 |
} |
| 5140 |
final_invert = 1; |
| 5141 |
break; |
| 5142 |
|
| 5143 |
case MINUS: |
| 5144 |
/* We treat MINUS as (val - source), since (source - val) is always |
| 5145 |
passed as (source + (-val)). */ |
| 5146 |
if (remainder == 0) |
| 5147 |
{ |
| 5148 |
if (generate) |
| 5149 |
emit_constant_insn (cond, |
| 5150 |
gen_rtx_SET (target, |
| 5151 |
gen_rtx_NEG (mode, source))); |
| 5152 |
return 1; |
| 5153 |
} |
| 5154 |
if (const_ok_for_arm (val)) |
| 5155 |
{ |
| 5156 |
if (generate) |
| 5157 |
emit_constant_insn (cond, |
| 5158 |
gen_rtx_SET (target, |
| 5159 |
gen_rtx_MINUS (mode, GEN_INT (val), |
| 5160 |
source))); |
| 5161 |
return 1; |
| 5162 |
} |
| 5163 |
|
| 5164 |
break; |
| 5165 |
|
| 5166 |
default: |
| 5167 |
gcc_unreachable (); |
| 5168 |
} |
| 5169 |
|
| 5170 |
/* If we can do it in one insn get out quickly. */ |
| 5171 |
if (const_ok_for_op (val, code)) |
| 5172 |
{ |
| 5173 |
if (generate) |
| 5174 |
emit_constant_insn (cond, |
| 5175 |
gen_rtx_SET (target, |
| 5176 |
(source |
| 5177 |
? gen_rtx_fmt_ee (code, mode, source, |
| 5178 |
GEN_INT (val)) |
| 5179 |
: GEN_INT (val)))); |
| 5180 |
return 1; |
| 5181 |
} |
| 5182 |
|
| 5183 |
/* On targets with UXTH/UBFX, we can deal with AND (2^N)-1 in a single |
| 5184 |
insn. */ |
| 5185 |
if (code == AND && (i = exact_log2 (remainder + 1)) > 0 |
| 5186 |
&& (arm_arch_thumb2 || (i == 16 && arm_arch6 && mode == SImode))) |
| 5187 |
{ |
| 5188 |
if (generate) |
| 5189 |
{ |
| 5190 |
if (mode == SImode && i == 16) |
| 5191 |
/* Use UXTH in preference to UBFX, since on Thumb2 it's a |
| 5192 |
smaller insn. */ |
| 5193 |
emit_constant_insn (cond, |
| 5194 |
gen_zero_extendhisi2 |
| 5195 |
(target, gen_lowpart (HImode, source))); |
| 5196 |
else |
| 5197 |
/* Extz only supports SImode, but we can coerce the operands |
| 5198 |
into that mode. */ |
| 5199 |
emit_constant_insn (cond, |
| 5200 |
gen_extzv_t2 (gen_lowpart (SImode, target), |
| 5201 |
gen_lowpart (SImode, source), |
| 5202 |
GEN_INT (i), const0_rtx)); |
| 5203 |
} |
| 5204 |
|
| 5205 |
return 1; |
| 5206 |
} |
| 5207 |
|
| 5208 |
/* Calculate a few attributes that may be useful for specific |
| 5209 |
optimizations. */ |
| 5210 |
/* Count number of leading zeros. */ |
| 5211 |
for (i = 31; i >= 0; i--) |
| 5212 |
{ |
| 5213 |
if ((remainder & (1 << i)) == 0) |
| 5214 |
clear_sign_bit_copies++; |
| 5215 |
else |
| 5216 |
break; |
| 5217 |
} |
| 5218 |
|
| 5219 |
/* Count number of leading 1's. */ |
| 5220 |
for (i = 31; i >= 0; i--) |
| 5221 |
{ |
| 5222 |
if ((remainder & (1 << i)) != 0) |
| 5223 |
set_sign_bit_copies++; |
| 5224 |
else |
| 5225 |
break; |
| 5226 |
} |
| 5227 |
|
| 5228 |
/* Count number of trailing zero's. */ |
| 5229 |
for (i = 0; i <= 31; i++) |
| 5230 |
{ |
| 5231 |
if ((remainder & (1 << i)) == 0) |
| 5232 |
clear_zero_bit_copies++; |
| 5233 |
else |
| 5234 |
break; |
| 5235 |
} |
| 5236 |
|
| 5237 |
/* Count number of trailing 1's. */ |
| 5238 |
for (i = 0; i <= 31; i++) |
| 5239 |
{ |
| 5240 |
if ((remainder & (1 << i)) != 0) |
| 5241 |
set_zero_bit_copies++; |
| 5242 |
else |
| 5243 |
break; |
| 5244 |
} |
| 5245 |
|
| 5246 |
switch (code) |
| 5247 |
{ |
| 5248 |
case SET: |
| 5249 |
/* See if we can do this by sign_extending a constant that is known |
| 5250 |
to be negative. This is a good, way of doing it, since the shift |
| 5251 |
may well merge into a subsequent insn. */ |
| 5252 |
if (set_sign_bit_copies > 1) |
| 5253 |
{ |
| 5254 |
if (const_ok_for_arm |
| 5255 |
(temp1 = ARM_SIGN_EXTEND (remainder |
| 5256 |
<< (set_sign_bit_copies - 1)))) |
| 5257 |
{ |
| 5258 |
if (generate) |
| 5259 |
{ |
| 5260 |
rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
| 5261 |
emit_constant_insn (cond, |
| 5262 |
gen_rtx_SET (new_src, GEN_INT (temp1))); |
| 5263 |
emit_constant_insn (cond, |
| 5264 |
gen_ashrsi3 (target, new_src, |
| 5265 |
GEN_INT (set_sign_bit_copies - 1))); |
| 5266 |
} |
| 5267 |
return 2; |
| 5268 |
} |
| 5269 |
/* For an inverted constant, we will need to set the low bits, |
| 5270 |
these will be shifted out of harm's way. */ |
| 5271 |
temp1 |= (1 << (set_sign_bit_copies - 1)) - 1; |
| 5272 |
if (const_ok_for_arm (~temp1)) |
| 5273 |
{ |
| 5274 |
if (generate) |
| 5275 |
{ |
| 5276 |
rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
| 5277 |
emit_constant_insn (cond, |
| 5278 |
gen_rtx_SET (new_src, GEN_INT (temp1))); |
| 5279 |
emit_constant_insn (cond, |
| 5280 |
gen_ashrsi3 (target, new_src, |
| 5281 |
GEN_INT (set_sign_bit_copies - 1))); |
| 5282 |
} |
| 5283 |
return 2; |
| 5284 |
} |
| 5285 |
} |
| 5286 |
|
| 5287 |
/* See if we can calculate the value as the difference between two |
| 5288 |
valid immediates. */ |
| 5289 |
if (clear_sign_bit_copies + clear_zero_bit_copies <= 16) |
| 5290 |
{ |
| 5291 |
int topshift = clear_sign_bit_copies & ~1; |
| 5292 |
|
| 5293 |
temp1 = ARM_SIGN_EXTEND ((remainder + (0x00800000 >> topshift)) |
| 5294 |
& (0xff000000 >> topshift)); |
| 5295 |
|
| 5296 |
/* If temp1 is zero, then that means the 9 most significant |
| 5297 |
bits of remainder were 1 and we've caused it to overflow. |
| 5298 |
When topshift is 0 we don't need to do anything since we |
| 5299 |
can borrow from 'bit 32'. */ |
| 5300 |
if (temp1 == 0 && topshift != 0) |
| 5301 |
temp1 = 0x80000000 >> (topshift - 1); |
| 5302 |
|
| 5303 |
temp2 = ARM_SIGN_EXTEND (temp1 - remainder); |
| 5304 |
|
| 5305 |
if (const_ok_for_arm (temp2)) |
| 5306 |
{ |
| 5307 |
if (generate) |
| 5308 |
{ |
| 5309 |
rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
| 5310 |
emit_constant_insn (cond, |
| 5311 |
gen_rtx_SET (new_src, GEN_INT (temp1))); |
| 5312 |
emit_constant_insn (cond, |
| 5313 |
gen_addsi3 (target, new_src, |
| 5314 |
GEN_INT (-temp2))); |
| 5315 |
} |
| 5316 |
|
| 5317 |
return 2; |
| 5318 |
} |
| 5319 |
} |
| 5320 |
|
| 5321 |
/* See if we can generate this by setting the bottom (or the top) |
| 5322 |
16 bits, and then shifting these into the other half of the |
| 5323 |
word. We only look for the simplest cases, to do more would cost |
| 5324 |
too much. Be careful, however, not to generate this when the |
| 5325 |
alternative would take fewer insns. */ |
| 5326 |
if (val & 0xffff0000) |
| 5327 |
{ |
| 5328 |
temp1 = remainder & 0xffff0000; |
| 5329 |
temp2 = remainder & 0x0000ffff; |
| 5330 |
|
| 5331 |
/* Overlaps outside this range are best done using other methods. */ |
| 5332 |
for (i = 9; i < 24; i++) |
| 5333 |
{ |
| 5334 |
if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder) |
| 5335 |
&& !const_ok_for_arm (temp2)) |
| 5336 |
{ |
| 5337 |
rtx new_src = (subtargets |
| 5338 |
? (generate ? gen_reg_rtx (mode) : NULL_RTX) |
| 5339 |
: target); |
| 5340 |
insns = arm_gen_constant (code, mode, cond, temp2, new_src, |
| 5341 |
source, subtargets, generate); |
| 5342 |
source = new_src; |
| 5343 |
if (generate) |
| 5344 |
emit_constant_insn |
| 5345 |
(cond, |
| 5346 |
gen_rtx_SET |
| 5347 |
(target, |
| 5348 |
gen_rtx_IOR (mode, |
| 5349 |
gen_rtx_ASHIFT (mode, source, |
| 5350 |
GEN_INT (i)), |
| 5351 |
source))); |
| 5352 |
return insns + 1; |
| 5353 |
} |
| 5354 |
} |
| 5355 |
|
| 5356 |
/* Don't duplicate cases already considered. */ |
| 5357 |
for (i = 17; i < 24; i++) |
| 5358 |
{ |
| 5359 |
if (((temp1 | (temp1 >> i)) == remainder) |
| 5360 |
&& !const_ok_for_arm (temp1)) |
| 5361 |
{ |
| 5362 |
rtx new_src = (subtargets |
| 5363 |
? (generate ? gen_reg_rtx (mode) : NULL_RTX) |
| 5364 |
: target); |
| 5365 |
insns = arm_gen_constant (code, mode, cond, temp1, new_src, |
| 5366 |
source, subtargets, generate); |
| 5367 |
source = new_src; |
| 5368 |
if (generate) |
| 5369 |
emit_constant_insn |
| 5370 |
(cond, |
| 5371 |
gen_rtx_SET (target, |
| 5372 |
gen_rtx_IOR |
| 5373 |
(mode, |
| 5374 |
gen_rtx_LSHIFTRT (mode, source, |
| 5375 |
GEN_INT (i)), |
| 5376 |
source))); |
| 5377 |
return insns + 1; |
| 5378 |
} |
| 5379 |
} |
| 5380 |
} |
| 5381 |
break; |
| 5382 |
|
| 5383 |
case IOR: |
| 5384 |
case XOR: |
| 5385 |
/* If we have IOR or XOR, and the constant can be loaded in a |
| 5386 |
single instruction, and we can find a temporary to put it in, |
| 5387 |
then this can be done in two instructions instead of 3-4. */ |
| 5388 |
if (subtargets |
| 5389 |
/* TARGET can't be NULL if SUBTARGETS is 0 */ |
| 5390 |
|| (reload_completed && !reg_mentioned_p (target, source))) |
| 5391 |
{ |
| 5392 |
if (const_ok_for_arm (ARM_SIGN_EXTEND (~val))) |
| 5393 |
{ |
| 5394 |
if (generate) |
| 5395 |
{ |
| 5396 |
rtx sub = subtargets ? gen_reg_rtx (mode) : target; |
| 5397 |
|
| 5398 |
emit_constant_insn (cond, |
| 5399 |
gen_rtx_SET (sub, GEN_INT (val))); |
| 5400 |
emit_constant_insn (cond, |
| 5401 |
gen_rtx_SET (target, |
| 5402 |
gen_rtx_fmt_ee (code, mode, |
| 5403 |
source, sub))); |
| 5404 |
} |
| 5405 |
return 2; |
| 5406 |
} |
| 5407 |
} |
| 5408 |
|
| 5409 |
if (code == XOR) |
| 5410 |
break; |
| 5411 |
|
| 5412 |
/* Convert. |
| 5413 |
x = y | constant ( which is composed of set_sign_bit_copies of leading 1s |
| 5414 |
and the remainder 0s for e.g. 0xfff00000) |
| 5415 |
x = ~(~(y ashift set_sign_bit_copies) lshiftrt set_sign_bit_copies) |
| 5416 |
|
| 5417 |
This can be done in 2 instructions by using shifts with mov or mvn. |
| 5418 |
e.g. for |
| 5419 |
x = x | 0xfff00000; |
| 5420 |
we generate. |
| 5421 |
mvn r0, r0, asl #12 |
| 5422 |
mvn r0, r0, lsr #12 */ |
| 5423 |
if (set_sign_bit_copies > 8 |
| 5424 |
&& (val & (HOST_WIDE_INT_M1U << (32 - set_sign_bit_copies))) == val) |
| 5425 |
{ |
| 5426 |
if (generate) |
| 5427 |
{ |
| 5428 |
rtx sub = subtargets ? gen_reg_rtx (mode) : target; |
| 5429 |
rtx shift = GEN_INT (set_sign_bit_copies); |
| 5430 |
|
| 5431 |
emit_constant_insn |
| 5432 |
(cond, |
| 5433 |
gen_rtx_SET (sub, |
| 5434 |
gen_rtx_NOT (mode, |
| 5435 |
gen_rtx_ASHIFT (mode, |
| 5436 |
source, |
| 5437 |
shift)))); |
| 5438 |
emit_constant_insn |
| 5439 |
(cond, |
| 5440 |
gen_rtx_SET (target, |
| 5441 |
gen_rtx_NOT (mode, |
| 5442 |
gen_rtx_LSHIFTRT (mode, sub, |
| 5443 |
shift)))); |
| 5444 |
} |
| 5445 |
return 2; |
| 5446 |
} |
| 5447 |
|
| 5448 |
/* Convert |
| 5449 |
x = y | constant (which has set_zero_bit_copies number of trailing ones). |
| 5450 |
to |
| 5451 |
x = ~((~y lshiftrt set_zero_bit_copies) ashift set_zero_bit_copies). |
| 5452 |
|
| 5453 |
For eg. r0 = r0 | 0xfff |
| 5454 |
mvn r0, r0, lsr #12 |
| 5455 |
mvn r0, r0, asl #12 |
| 5456 |
|
| 5457 |
*/ |
| 5458 |
if (set_zero_bit_copies > 8 |
| 5459 |
&& (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder) |
| 5460 |
{ |
| 5461 |
if (generate) |
| 5462 |
{ |
| 5463 |
rtx sub = subtargets ? gen_reg_rtx (mode) : target; |
| 5464 |
rtx shift = GEN_INT (set_zero_bit_copies); |
| 5465 |
|
| 5466 |
emit_constant_insn |
| 5467 |
(cond, |
| 5468 |
gen_rtx_SET (sub, |
| 5469 |
gen_rtx_NOT (mode, |
| 5470 |
gen_rtx_LSHIFTRT (mode, |
| 5471 |
source, |
| 5472 |
shift)))); |
| 5473 |
emit_constant_insn |
| 5474 |
(cond, |
| 5475 |
gen_rtx_SET (target, |
| 5476 |
gen_rtx_NOT (mode, |
| 5477 |
gen_rtx_ASHIFT (mode, sub, |
| 5478 |
shift)))); |
| 5479 |
} |
| 5480 |
return 2; |
| 5481 |
} |
| 5482 |
|
| 5483 |
/* This will never be reached for Thumb2 because orn is a valid |
| 5484 |
instruction. This is for Thumb1 and the ARM 32 bit cases. |
| 5485 |
|
| 5486 |
x = y | constant (such that ~constant is a valid constant) |
| 5487 |
Transform this to |
| 5488 |
x = ~(~y & ~constant). |
| 5489 |
*/ |
| 5490 |
if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val))) |
| 5491 |
{ |
| 5492 |
if (generate) |
| 5493 |
{ |
| 5494 |
rtx sub = subtargets ? gen_reg_rtx (mode) : target; |
| 5495 |
emit_constant_insn (cond, |
| 5496 |
gen_rtx_SET (sub, |
| 5497 |
gen_rtx_NOT (mode, source))); |
| 5498 |
source = sub; |
| 5499 |
if (subtargets) |
| 5500 |
sub = gen_reg_rtx (mode); |
| 5501 |
emit_constant_insn (cond, |
| 5502 |
gen_rtx_SET (sub, |
| 5503 |
gen_rtx_AND (mode, source, |
| 5504 |
GEN_INT (temp1)))); |
| 5505 |
emit_constant_insn (cond, |
| 5506 |
gen_rtx_SET (target, |
| 5507 |
gen_rtx_NOT (mode, sub))); |
| 5508 |
} |
| 5509 |
return 3; |
| 5510 |
} |
| 5511 |
break; |
| 5512 |
|
| 5513 |
case AND: |
| 5514 |
/* See if two shifts will do 2 or more insn's worth of work. */ |
| 5515 |
if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24) |
| 5516 |
{ |
| 5517 |
HOST_WIDE_INT shift_mask = ((0xffffffff |
| 5518 |
<< (32 - clear_sign_bit_copies)) |
| 5519 |
& 0xffffffff); |
| 5520 |
|
| 5521 |
if ((remainder | shift_mask) != 0xffffffff) |
| 5522 |
{ |
| 5523 |
HOST_WIDE_INT new_val |
| 5524 |
= ARM_SIGN_EXTEND (remainder | shift_mask); |
| 5525 |
|
| 5526 |
if (generate) |
| 5527 |
{ |
| 5528 |
rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
| 5529 |
insns = arm_gen_constant (AND, SImode, cond, new_val, |
| 5530 |
new_src, source, subtargets, 1); |
| 5531 |
source = new_src; |
| 5532 |
} |
| 5533 |
else |
| 5534 |
{ |
| 5535 |
rtx targ = subtargets ? NULL_RTX : target; |
| 5536 |
insns = arm_gen_constant (AND, mode, cond, new_val, |
| 5537 |
targ, source, subtargets, 0); |
| 5538 |
} |
| 5539 |
} |
| 5540 |
|
| 5541 |
if (generate) |
| 5542 |
{ |
| 5543 |
rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
| 5544 |
rtx shift = GEN_INT (clear_sign_bit_copies); |
| 5545 |
|
| 5546 |
emit_insn (gen_ashlsi3 (new_src, source, shift)); |
| 5547 |
emit_insn (gen_lshrsi3 (target, new_src, shift)); |
| 5548 |
} |
| 5549 |
|
| 5550 |
return insns + 2; |
| 5551 |
} |
| 5552 |
|
| 5553 |
if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24) |
| 5554 |
{ |
| 5555 |
HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1; |
| 5556 |
|
| 5557 |
if ((remainder | shift_mask) != 0xffffffff) |
| 5558 |
{ |
| 5559 |
HOST_WIDE_INT new_val |
| 5560 |
= ARM_SIGN_EXTEND (remainder | shift_mask); |
| 5561 |
if (generate) |
| 5562 |
{ |
| 5563 |
rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
| 5564 |
|
| 5565 |
insns = arm_gen_constant (AND, mode, cond, new_val, |
| 5566 |
new_src, source, subtargets, 1); |
| 5567 |
source = new_src; |
| 5568 |
} |
| 5569 |
else |
| 5570 |
{ |
| 5571 |
rtx targ = subtargets ? NULL_RTX : target; |
| 5572 |
|
| 5573 |
insns = arm_gen_constant (AND, mode, cond, new_val, |
| 5574 |
targ, source, subtargets, 0); |
| 5575 |
} |
| 5576 |
} |
| 5577 |
|
| 5578 |
if (generate) |
| 5579 |
{ |
| 5580 |
rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
| 5581 |
rtx shift = GEN_INT (clear_zero_bit_copies); |
| 5582 |
|
| 5583 |
emit_insn (gen_lshrsi3 (new_src, source, shift)); |
| 5584 |
emit_insn (gen_ashlsi3 (target, new_src, shift)); |
| 5585 |
} |
| 5586 |
|
| 5587 |
return insns + 2; |
| 5588 |
} |
| 5589 |
|
| 5590 |
break; |
| 5591 |
|
| 5592 |
default: |
| 5593 |
break; |
| 5594 |
} |
| 5595 |
|
| 5596 |
/* Calculate what the instruction sequences would be if we generated it |
| 5597 |
normally, negated, or inverted. */ |
| 5598 |
if (code == AND) |
| 5599 |
/* AND cannot be split into multiple insns, so invert and use BIC. */ |
| 5600 |
insns = 99; |
| 5601 |
else |
| 5602 |
insns = optimal_immediate_sequence (code, remainder, &pos_immediates); |
| 5603 |
|
| 5604 |
if (can_negate) |
| 5605 |
neg_insns = optimal_immediate_sequence (code, (-remainder) & 0xffffffff, |
| 5606 |
&neg_immediates); |
| 5607 |
else |
| 5608 |
neg_insns = 99; |
| 5609 |
|
| 5610 |
if (can_invert || final_invert) |
| 5611 |
inv_insns = optimal_immediate_sequence (code, remainder ^ 0xffffffff, |
| 5612 |
&inv_immediates); |
| 5613 |
else |
| 5614 |
inv_insns = 99; |
| 5615 |
|
| 5616 |
immediates = &pos_immediates; |
| 5617 |
|
| 5618 |
/* Is the negated immediate sequence more efficient? */ |
| 5619 |
if (neg_insns < insns && neg_insns <= inv_insns) |
| 5620 |
{ |
| 5621 |
insns = neg_insns; |
| 5622 |
immediates = &neg_immediates; |
| 5623 |
} |
| 5624 |
else |
| 5625 |
can_negate = 0; |
| 5626 |
|
| 5627 |
/* Is the inverted immediate sequence more efficient? |
| 5628 |
We must allow for an extra NOT instruction for XOR operations, although |
| 5629 |
there is some chance that the final 'mvn' will get optimized later. */ |
| 5630 |
if ((inv_insns + 1) < insns || (!final_invert && inv_insns < insns)) |
| 5631 |
{ |
| 5632 |
insns = inv_insns; |
| 5633 |
immediates = &inv_immediates; |
| 5634 |
} |
| 5635 |
else |
| 5636 |
{ |
| 5637 |
can_invert = 0; |
| 5638 |
final_invert = 0; |
| 5639 |
} |
| 5640 |
|
| 5641 |
/* Now output the chosen sequence as instructions. */ |
| 5642 |
if (generate) |
| 5643 |
{ |
| 5644 |
for (i = 0; i < insns; i++) |
| 5645 |
{ |
| 5646 |
rtx new_src, temp1_rtx; |
| 5647 |
|
| 5648 |
temp1 = immediates->i[i]; |
| 5649 |
|
| 5650 |
if (code == SET || code == MINUS) |
| 5651 |
new_src = (subtargets ? gen_reg_rtx (mode) : target); |
| 5652 |
else if ((final_invert || i < (insns - 1)) && subtargets) |
| 5653 |
new_src = gen_reg_rtx (mode); |
| 5654 |
else |
| 5655 |
new_src = target; |
| 5656 |
|
| 5657 |
if (can_invert) |
| 5658 |
temp1 = ~temp1; |
| 5659 |
else if (can_negate) |
| 5660 |
temp1 = -temp1; |
| 5661 |
|
| 5662 |
temp1 = trunc_int_for_mode (temp1, mode); |
| 5663 |
temp1_rtx = GEN_INT (temp1); |
| 5664 |
|
| 5665 |
if (code == SET) |
| 5666 |
; |
| 5667 |
else if (code == MINUS) |
| 5668 |
temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source); |
| 5669 |
else |
| 5670 |
temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx); |
| 5671 |
|
| 5672 |
emit_constant_insn (cond, gen_rtx_SET (new_src, temp1_rtx)); |
| 5673 |
source = new_src; |
| 5674 |
|
| 5675 |
if (code == SET) |
| 5676 |
{ |
| 5677 |
can_negate = can_invert; |
| 5678 |
can_invert = 0; |
| 5679 |
code = PLUS; |
| 5680 |
} |
| 5681 |
else if (code == MINUS) |
| 5682 |
code = PLUS; |
| 5683 |
} |
| 5684 |
} |
| 5685 |
|
| 5686 |
if (final_invert) |
| 5687 |
{ |
| 5688 |
if (generate) |
| 5689 |
emit_constant_insn (cond, gen_rtx_SET (target, |
| 5690 |
gen_rtx_NOT (mode, source))); |
| 5691 |
insns++; |
| 5692 |
} |
| 5693 |
|
| 5694 |
return insns; |
| 5695 |
} |
| 5696 |
|
| 5697 |
/* Return TRUE if op is a constant where both the low and top words are |
| 5698 |
suitable for RSB/RSC instructions. This is never true for Thumb, since |
| 5699 |
we do not have RSC in that case. */ |
| 5700 |
static bool |
| 5701 |
arm_const_double_prefer_rsbs_rsc (rtx op) |
| 5702 |
{ |
| 5703 |
/* Thumb lacks RSC, so we never prefer that sequence. */ |
| 5704 |
if (TARGET_THUMB || !CONST_INT_P (op)) |
| 5705 |
return false; |
| 5706 |
HOST_WIDE_INT hi, lo; |
| 5707 |
lo = UINTVAL (op) & 0xffffffffULL; |
| 5708 |
hi = UINTVAL (op) >> 32; |
| 5709 |
return const_ok_for_arm (lo) && const_ok_for_arm (hi); |
| 5710 |
} |
| 5711 |
|
| 5712 |
/* Canonicalize a comparison so that we are more likely to recognize it. |
| 5713 |
This can be done for a few constant compares, where we can make the |
| 5714 |
immediate value easier to load. */ |
| 5715 |
|
| 5716 |
static void |
| 5717 |
arm_canonicalize_comparison (int *code, rtx *op0, rtx *op1, |
| 5718 |
bool op0_preserve_value) |
| 5719 |
{ |
| 5720 |
machine_mode mode; |
| 5721 |
unsigned HOST_WIDE_INT i, maxval; |
| 5722 |
|
| 5723 |
mode = GET_MODE (*op0); |
| 5724 |
if (mode == VOIDmode) |
| 5725 |
mode = GET_MODE (*op1); |
| 5726 |
|
| 5727 |
maxval = (HOST_WIDE_INT_1U << (GET_MODE_BITSIZE (mode) - 1)) - 1; |
| 5728 |
|
| 5729 |
/* For floating-point comparisons, prefer >= and > over <= and < since |
| 5730 |
the former are supported by VSEL on some architectures. Only do this |
| 5731 |
if both operands are registers. */ |
| 5732 |
if (GET_MODE_CLASS (mode) == MODE_FLOAT |
| 5733 |
&& (*code == LE |
| 5734 |
|| *code == LT |
| 5735 |
|| *code == UNGT |
| 5736 |
|| *code == UNGE) |
| 5737 |
&& register_operand (*op0, mode) |
| 5738 |
&& register_operand (*op1, mode)) |
| 5739 |
{ |
| 5740 |
std::swap (*op0, *op1); |
| 5741 |
*code = (int) swap_condition ((rtx_code)*code); |
| 5742 |
return; |
| 5743 |
} |
| 5744 |
|
| 5745 |
/* For DImode, we have GE/LT/GEU/LTU comparisons (with cmp/sbc). In |
| 5746 |
ARM mode we can also use cmp/cmpeq for GTU/LEU. GT/LE must be |
| 5747 |
either reversed or (for constant OP1) adjusted to GE/LT. |
| 5748 |
Similarly for GTU/LEU in Thumb mode. */ |
| 5749 |
if (mode == DImode) |
| 5750 |
{ |
| 5751 |
|
| 5752 |
if (*code == GT || *code == LE |
| 5753 |
|| *code == GTU || *code == LEU) |
| 5754 |
{ |
| 5755 |
/* Missing comparison. First try to use an available |
| 5756 |
comparison. */ |
| 5757 |
if (CONST_INT_P (*op1)) |
| 5758 |
{ |
| 5759 |
i = INTVAL (*op1); |
| 5760 |
switch (*code) |
| 5761 |
{ |
| 5762 |
case GT: |
| 5763 |
case LE: |
| 5764 |
if (i != maxval) |
| 5765 |
{ |
| 5766 |
/* Try to convert to GE/LT, unless that would be more |
| 5767 |
expensive. */ |
| 5768 |
if (!arm_const_double_by_immediates (GEN_INT (i + 1)) |
| 5769 |
&& arm_const_double_prefer_rsbs_rsc (*op1)) |
| 5770 |
return; |
| 5771 |
*op1 = GEN_INT (i + 1); |
| 5772 |
*code = *code == GT ? GE : LT; |
| 5773 |
} |
| 5774 |
else |
| 5775 |
{ |
| 5776 |
/* GT maxval is always false, LE maxval is always true. |
| 5777 |
We can't fold that away here as we must make a |
| 5778 |
comparison, but we can fold them to comparisons |
| 5779 |
with the same result that can be handled: |
| 5780 |
op0 GT maxval -> op0 LT minval |
| 5781 |
op0 LE maxval -> op0 GE minval |
| 5782 |
where minval = (-maxval - 1). */ |
| 5783 |
*op1 = GEN_INT (-maxval - 1); |
| 5784 |
*code = *code == GT ? LT : GE; |
| 5785 |
} |
| 5786 |
return; |
| 5787 |
|
| 5788 |
case GTU: |
| 5789 |
case LEU: |
| 5790 |
if (i != ~((unsigned HOST_WIDE_INT) 0)) |
| 5791 |
{ |
| 5792 |
/* Try to convert to GEU/LTU, unless that would |
| 5793 |
be more expensive. */ |
| 5794 |
if (!arm_const_double_by_immediates (GEN_INT (i + 1)) |
| 5795 |
&& arm_const_double_prefer_rsbs_rsc (*op1)) |
| 5796 |
return; |
| 5797 |
*op1 = GEN_INT (i + 1); |
| 5798 |
*code = *code == GTU ? GEU : LTU; |
| 5799 |
} |
| 5800 |
else |
| 5801 |
{ |
| 5802 |
/* GTU ~0 is always false, LEU ~0 is always true. |
| 5803 |
We can't fold that away here as we must make a |
| 5804 |
comparison, but we can fold them to comparisons |
| 5805 |
with the same result that can be handled: |
| 5806 |
op0 GTU ~0 -> op0 LTU 0 |
| 5807 |
op0 LEU ~0 -> op0 GEU 0. */ |
| 5808 |
*op1 = const0_rtx; |
| 5809 |
*code = *code == GTU ? LTU : GEU; |
| 5810 |
} |
| 5811 |
return; |
| 5812 |
|
| 5813 |
default: |
| 5814 |
gcc_unreachable (); |
| 5815 |
} |
| 5816 |
} |
| 5817 |
|
| 5818 |
if (!op0_preserve_value) |
| 5819 |
{ |
| 5820 |
std::swap (*op0, *op1); |
| 5821 |
*code = (int)swap_condition ((enum rtx_code)*code); |
| 5822 |
} |
| 5823 |
} |
| 5824 |
return; |
| 5825 |
} |
| 5826 |
|
| 5827 |
/* If *op0 is (zero_extend:SI (subreg:QI (reg:SI) 0)) and comparing |
| 5828 |
with const0_rtx, change it to (and:SI (reg:SI) (const_int 255)), |
| 5829 |
to facilitate possible combining with a cmp into 'ands'. */ |
| 5830 |
if (mode == SImode |
| 5831 |
&& GET_CODE (*op0) == ZERO_EXTEND |
| 5832 |
&& GET_CODE (XEXP (*op0, 0)) == SUBREG |
| 5833 |
&& GET_MODE (XEXP (*op0, 0)) == QImode |
| 5834 |
&& GET_MODE (SUBREG_REG (XEXP (*op0, 0))) == SImode |
| 5835 |
&& subreg_lowpart_p (XEXP (*op0, 0)) |
| 5836 |
&& *op1 == const0_rtx) |
| 5837 |
*op0 = gen_rtx_AND (SImode, SUBREG_REG (XEXP (*op0, 0)), |
| 5838 |
GEN_INT (255)); |
| 5839 |
|
| 5840 |
/* Comparisons smaller than DImode. Only adjust comparisons against |
| 5841 |
an out-of-range constant. */ |
| 5842 |
if (!CONST_INT_P (*op1) |
| 5843 |
|| const_ok_for_arm (INTVAL (*op1)) |
| 5844 |
|| const_ok_for_arm (- INTVAL (*op1))) |
| 5845 |
return; |
| 5846 |
|
| 5847 |
i = INTVAL (*op1); |
| 5848 |
|
| 5849 |
switch (*code) |
| 5850 |
{ |
| 5851 |
case EQ: |
| 5852 |
case NE: |
| 5853 |
return; |
| 5854 |
|
| 5855 |
case GT: |
| 5856 |
case LE: |
| 5857 |
if (i != maxval |
| 5858 |
&& (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1)))) |
| 5859 |
{ |
| 5860 |
*op1 = GEN_INT (ARM_SIGN_EXTEND (i + 1)); |
| 5861 |
*code = *code == GT ? GE : LT; |
| 5862 |
return; |
| 5863 |
} |
| 5864 |
break; |
| 5865 |
|
| 5866 |
case GE: |
| 5867 |
case LT: |
| 5868 |
if (i != ~maxval |
| 5869 |
&& (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1)))) |
| 5870 |
{ |
| 5871 |
*op1 = GEN_INT (i - 1); |
| 5872 |
*code = *code == GE ? GT : LE; |
| 5873 |
return; |
| 5874 |
} |
| 5875 |
break; |
| 5876 |
|
| 5877 |
case GTU: |
| 5878 |
case LEU: |
| 5879 |
if (i != ~((unsigned HOST_WIDE_INT) 0) |
| 5880 |
&& (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1)))) |
| 5881 |
{ |
| 5882 |
*op1 = GEN_INT (ARM_SIGN_EXTEND (i + 1)); |
| 5883 |
*code = *code == GTU ? GEU : LTU; |
| 5884 |
return; |
| 5885 |
} |
| 5886 |
break; |
| 5887 |
|
| 5888 |
case GEU: |
| 5889 |
case LTU: |
| 5890 |
if (i != 0 |
| 5891 |
&& (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1)))) |
| 5892 |
{ |
| 5893 |
*op1 = GEN_INT (i - 1); |
| 5894 |
*code = *code == GEU ? GTU : LEU; |
| 5895 |
return; |
| 5896 |
} |
| 5897 |
break; |
| 5898 |
|
| 5899 |
default: |
| 5900 |
gcc_unreachable (); |
| 5901 |
} |
| 5902 |
} |
| 5903 |
|
| 5904 |
|
| 5905 |
/* Define how to find the value returned by a function. */ |
| 5906 |
|
| 5907 |
static rtx |
| 5908 |
arm_function_value(const_tree type, const_tree func, |
| 5909 |
bool outgoing ATTRIBUTE_UNUSED) |
| 5910 |
{ |
| 5911 |
machine_mode mode; |
| 5912 |
int unsignedp ATTRIBUTE_UNUSED; |
| 5913 |
rtx r ATTRIBUTE_UNUSED; |
| 5914 |
|
| 5915 |
mode = TYPE_MODE (type); |
| 5916 |
|
| 5917 |
if (TARGET_AAPCS_BASED) |
| 5918 |
return aapcs_allocate_return_reg (mode, type, func); |
| 5919 |
|
| 5920 |
/* Promote integer types. */ |
| 5921 |
if (INTEGRAL_TYPE_P (type)) |
| 5922 |
mode = arm_promote_function_mode (type, mode, &unsignedp, func, 1); |
| 5923 |
|
| 5924 |
/* Promotes small structs returned in a register to full-word size |
| 5925 |
for big-endian AAPCS. */ |
| 5926 |
if (arm_return_in_msb (type)) |
| 5927 |
{ |
| 5928 |
HOST_WIDE_INT size = int_size_in_bytes (type); |
| 5929 |
if (size % UNITS_PER_WORD != 0) |
| 5930 |
{ |
| 5931 |
size += UNITS_PER_WORD - size % UNITS_PER_WORD; |
| 5932 |
mode = int_mode_for_size (size * BITS_PER_UNIT, 0).require (); |
| 5933 |
} |
| 5934 |
} |
| 5935 |
|
| 5936 |
return arm_libcall_value_1 (mode); |
| 5937 |
} |
| 5938 |
|
| 5939 |
/* libcall hashtable helpers. */ |
| 5940 |
|
| 5941 |
struct libcall_hasher : nofree_ptr_hash <const rtx_def> |
| 5942 |
{ |
| 5943 |
static inline hashval_t hash (const rtx_def *); |
| 5944 |
static inline bool equal (const rtx_def *, const rtx_def *); |
| 5945 |
static inline void remove (rtx_def *); |
| 5946 |
}; |
| 5947 |
|
| 5948 |
inline bool |
| 5949 |
libcall_hasher::equal (const rtx_def *p1, const rtx_def *p2) |
| 5950 |
{ |
| 5951 |
return rtx_equal_p (p1, p2); |
| 5952 |
} |
| 5953 |
|
| 5954 |
inline hashval_t |
| 5955 |
libcall_hasher::hash (const rtx_def *p1) |
| 5956 |
{ |
| 5957 |
return hash_rtx (p1, VOIDmode, NULL, NULL, FALSE); |
| 5958 |
} |
| 5959 |
|
| 5960 |
typedef hash_table<libcall_hasher> libcall_table_type; |
| 5961 |
|
| 5962 |
static void |
| 5963 |
add_libcall (libcall_table_type *htab, rtx libcall) |
| 5964 |
{ |
| 5965 |
*htab->find_slot (libcall, INSERT) = libcall; |
| 5966 |
} |
| 5967 |
|
| 5968 |
static bool |
| 5969 |
arm_libcall_uses_aapcs_base (const_rtx libcall) |
| 5970 |
{ |
| 5971 |
static bool init_done = false; |
| 5972 |
static libcall_table_type *libcall_htab = NULL; |
| 5973 |
|
| 5974 |
if (!init_done) |
| 5975 |
{ |
| 5976 |
init_done = true; |
| 5977 |
|
| 5978 |
libcall_htab = new libcall_table_type (31); |
| 5979 |
add_libcall (libcall_htab, |
| 5980 |
convert_optab_libfunc (sfloat_optab, SFmode, SImode)); |
| 5981 |
add_libcall (libcall_htab, |
| 5982 |
convert_optab_libfunc (sfloat_optab, DFmode, SImode)); |
| 5983 |
add_libcall (libcall_htab, |
| 5984 |
convert_optab_libfunc (sfloat_optab, SFmode, DImode)); |
| 5985 |
add_libcall (libcall_htab, |
| 5986 |
convert_optab_libfunc (sfloat_optab, DFmode, DImode)); |
| 5987 |
|
| 5988 |
add_libcall (libcall_htab, |
| 5989 |
convert_optab_libfunc (ufloat_optab, SFmode, SImode)); |
| 5990 |
add_libcall (libcall_htab, |
| 5991 |
convert_optab_libfunc (ufloat_optab, DFmode, SImode)); |
| 5992 |
add_libcall (libcall_htab, |
| 5993 |
convert_optab_libfunc (ufloat_optab, SFmode, DImode)); |
| 5994 |
add_libcall (libcall_htab, |
| 5995 |
convert_optab_libfunc (ufloat_optab, DFmode, DImode)); |
| 5996 |
|
| 5997 |
add_libcall (libcall_htab, |
| 5998 |
convert_optab_libfunc (sext_optab, SFmode, HFmode)); |
| 5999 |
add_libcall (libcall_htab, |
| 6000 |
convert_optab_libfunc (trunc_optab, HFmode, SFmode)); |
| 6001 |
add_libcall (libcall_htab, |
| 6002 |
convert_optab_libfunc (sfix_optab, SImode, DFmode)); |
| 6003 |
add_libcall (libcall_htab, |
| 6004 |
convert_optab_libfunc (ufix_optab, SImode, DFmode)); |
| 6005 |
add_libcall (libcall_htab, |
| 6006 |
convert_optab_libfunc (sfix_optab, DImode, DFmode)); |
| 6007 |
add_libcall (libcall_htab, |
| 6008 |
convert_optab_libfunc (ufix_optab, DImode, DFmode)); |
| 6009 |
add_libcall (libcall_htab, |
| 6010 |
convert_optab_libfunc (sfix_optab, DImode, SFmode)); |
| 6011 |
add_libcall (libcall_htab, |
| 6012 |
convert_optab_libfunc (ufix_optab, DImode, SFmode)); |
| 6013 |
add_libcall (libcall_htab, |
| 6014 |
convert_optab_libfunc (sfix_optab, SImode, SFmode)); |
| 6015 |
add_libcall (libcall_htab, |
| 6016 |
convert_optab_libfunc (ufix_optab, SImode, SFmode)); |
| 6017 |
|
| 6018 |
/* Values from double-precision helper functions are returned in core |
| 6019 |
registers if the selected core only supports single-precision |
| 6020 |
arithmetic, even if we are using the hard-float ABI. The same is |
| 6021 |
true for single-precision helpers except in case of MVE, because in |
| 6022 |
MVE we will be using the hard-float ABI on a CPU which doesn't support |
| 6023 |
single-precision operations in hardware. In MVE the following check |
| 6024 |
enables use of emulation for the single-precision arithmetic |
| 6025 |
operations. */ |
| 6026 |
if (TARGET_HAVE_MVE) |
| 6027 |
{ |
| 6028 |
add_libcall (libcall_htab, optab_libfunc (add_optab, SFmode)); |
| 6029 |
add_libcall (libcall_htab, optab_libfunc (sdiv_optab, SFmode)); |
| 6030 |
add_libcall (libcall_htab, optab_libfunc (smul_optab, SFmode)); |
| 6031 |
add_libcall (libcall_htab, optab_libfunc (neg_optab, SFmode)); |
| 6032 |
add_libcall (libcall_htab, optab_libfunc (sub_optab, SFmode)); |
| 6033 |
add_libcall (libcall_htab, optab_libfunc (eq_optab, SFmode)); |
| 6034 |
add_libcall (libcall_htab, optab_libfunc (lt_optab, SFmode)); |
| 6035 |
add_libcall (libcall_htab, optab_libfunc (le_optab, SFmode)); |
| 6036 |
add_libcall (libcall_htab, optab_libfunc (ge_optab, SFmode)); |
| 6037 |
add_libcall (libcall_htab, optab_libfunc (gt_optab, SFmode)); |
| 6038 |
add_libcall (libcall_htab, optab_libfunc (unord_optab, SFmode)); |
| 6039 |
} |
| 6040 |
add_libcall (libcall_htab, optab_libfunc (add_optab, DFmode)); |
| 6041 |
add_libcall (libcall_htab, optab_libfunc (sdiv_optab, DFmode)); |
| 6042 |
add_libcall (libcall_htab, optab_libfunc (smul_optab, DFmode)); |
| 6043 |
add_libcall (libcall_htab, optab_libfunc (neg_optab, DFmode)); |
| 6044 |
add_libcall (libcall_htab, optab_libfunc (sub_optab, DFmode)); |
| 6045 |
add_libcall (libcall_htab, optab_libfunc (eq_optab, DFmode)); |
| 6046 |
add_libcall (libcall_htab, optab_libfunc (lt_optab, DFmode)); |
| 6047 |
add_libcall (libcall_htab, optab_libfunc (le_optab, DFmode)); |
| 6048 |
add_libcall (libcall_htab, optab_libfunc (ge_optab, DFmode)); |
| 6049 |
add_libcall (libcall_htab, optab_libfunc (gt_optab, DFmode)); |
| 6050 |
add_libcall (libcall_htab, optab_libfunc (unord_optab, DFmode)); |
| 6051 |
add_libcall (libcall_htab, convert_optab_libfunc (sext_optab, DFmode, |
| 6052 |
SFmode)); |
| 6053 |
add_libcall (libcall_htab, convert_optab_libfunc (trunc_optab, SFmode, |
| 6054 |
DFmode)); |
| 6055 |
add_libcall (libcall_htab, |
| 6056 |
convert_optab_libfunc (trunc_optab, HFmode, DFmode)); |
| 6057 |
} |
| 6058 |
|
| 6059 |
return libcall && libcall_htab->find (libcall) != NULL; |
| 6060 |
} |
| 6061 |
|
| 6062 |
static rtx |
| 6063 |
arm_libcall_value_1 (machine_mode mode) |
| 6064 |
{ |
| 6065 |
if (TARGET_AAPCS_BASED) |
| 6066 |
return aapcs_libcall_value (mode); |
| 6067 |
else if (TARGET_IWMMXT_ABI |
| 6068 |
&& arm_vector_mode_supported_p (mode)) |
| 6069 |
return gen_rtx_REG (mode, FIRST_IWMMXT_REGNUM); |
| 6070 |
else |
| 6071 |
return gen_rtx_REG (mode, ARG_REGISTER (1)); |
| 6072 |
} |
| 6073 |
|
| 6074 |
/* Define how to find the value returned by a library function |
| 6075 |
assuming the value has mode MODE. */ |
| 6076 |
|
| 6077 |
static rtx |
| 6078 |
arm_libcall_value (machine_mode mode, const_rtx libcall) |
| 6079 |
{ |
| 6080 |
if (TARGET_AAPCS_BASED && arm_pcs_default != ARM_PCS_AAPCS |
| 6081 |
&& GET_MODE_CLASS (mode) == MODE_FLOAT) |
| 6082 |
{ |
| 6083 |
/* The following libcalls return their result in integer registers, |
| 6084 |
even though they return a floating point value. */ |
| 6085 |
if (arm_libcall_uses_aapcs_base (libcall)) |
| 6086 |
return gen_rtx_REG (mode, ARG_REGISTER(1)); |
| 6087 |
|
| 6088 |
} |
| 6089 |
|
| 6090 |
return arm_libcall_value_1 (mode); |
| 6091 |
} |
| 6092 |
|
| 6093 |
/* Implement TARGET_FUNCTION_VALUE_REGNO_P. */ |
| 6094 |
|
| 6095 |
static bool |
| 6096 |
arm_function_value_regno_p (const unsigned int regno) |
| 6097 |
{ |
| 6098 |
if (regno == ARG_REGISTER (1) |
| 6099 |
|| (TARGET_32BIT |
| 6100 |
&& TARGET_AAPCS_BASED |
| 6101 |
&& TARGET_HARD_FLOAT |
| 6102 |
&& regno == FIRST_VFP_REGNUM) |
| 6103 |
|| (TARGET_IWMMXT_ABI |
| 6104 |
&& regno == FIRST_IWMMXT_REGNUM)) |
| 6105 |
return true; |
| 6106 |
|
| 6107 |
return false; |
| 6108 |
} |
| 6109 |
|
| 6110 |
/* Determine the amount of memory needed to store the possible return |
| 6111 |
registers of an untyped call. */ |
| 6112 |
int |
| 6113 |
arm_apply_result_size (void) |
| 6114 |
{ |
| 6115 |
int size = 16; |
| 6116 |
|
| 6117 |
if (TARGET_32BIT) |
| 6118 |
{ |
| 6119 |
if (TARGET_HARD_FLOAT_ABI) |
| 6120 |
size += 32; |
| 6121 |
if (TARGET_IWMMXT_ABI) |
| 6122 |
size += 8; |
| 6123 |
} |
| 6124 |
|
| 6125 |
return size; |
| 6126 |
} |
| 6127 |
|
| 6128 |
/* Decide whether TYPE should be returned in memory (true) |
| 6129 |
or in a register (false). FNTYPE is the type of the function making |
| 6130 |
the call. */ |
| 6131 |
static bool |
| 6132 |
arm_return_in_memory (const_tree type, const_tree fntype) |
| 6133 |
{ |
| 6134 |
HOST_WIDE_INT size; |
| 6135 |
|
| 6136 |
size = int_size_in_bytes (type); /* Negative if not fixed size. */ |
| 6137 |
|
| 6138 |
if (TARGET_AAPCS_BASED) |
| 6139 |
{ |
| 6140 |
/* Simple, non-aggregate types (ie not including vectors and |
| 6141 |
complex) are always returned in a register (or registers). |
| 6142 |
We don't care about which register here, so we can short-cut |
| 6143 |
some of the detail. */ |
| 6144 |
if (!AGGREGATE_TYPE_P (type) |
| 6145 |
&& TREE_CODE (type) != VECTOR_TYPE |
| 6146 |
&& TREE_CODE (type) != COMPLEX_TYPE) |
| 6147 |
return false; |
| 6148 |
|
| 6149 |
/* Any return value that is no larger than one word can be |
| 6150 |
returned in r0. */ |
| 6151 |
if (((unsigned HOST_WIDE_INT) size) <= UNITS_PER_WORD) |
| 6152 |
return false; |
| 6153 |
|
| 6154 |
/* Check any available co-processors to see if they accept the |
| 6155 |
type as a register candidate (VFP, for example, can return |
| 6156 |
some aggregates in consecutive registers). These aren't |
| 6157 |
available if the call is variadic. */ |
| 6158 |
if (aapcs_select_return_coproc (type, fntype) >= 0) |
| 6159 |
return false; |
| 6160 |
|
| 6161 |
/* Vector values should be returned using ARM registers, not |
| 6162 |
memory (unless they're over 16 bytes, which will break since |
| 6163 |
we only have four call-clobbered registers to play with). */ |
| 6164 |
if (TREE_CODE (type) == VECTOR_TYPE) |
| 6165 |
return (size < 0 || size > (4 * UNITS_PER_WORD)); |
| 6166 |
|
| 6167 |
/* The rest go in memory. */ |
| 6168 |
return true; |
| 6169 |
} |
| 6170 |
|
| 6171 |
if (TREE_CODE (type) == VECTOR_TYPE) |
| 6172 |
return (size < 0 || size > (4 * UNITS_PER_WORD)); |
| 6173 |
|
| 6174 |
if (!AGGREGATE_TYPE_P (type) && |
| 6175 |
(TREE_CODE (type) != VECTOR_TYPE)) |
| 6176 |
/* All simple types are returned in registers. */ |
| 6177 |
return false; |
| 6178 |
|
| 6179 |
if (arm_abi != ARM_ABI_APCS) |
| 6180 |
{ |
| 6181 |
/* ATPCS and later return aggregate types in memory only if they are |
| 6182 |
larger than a word (or are variable size). */ |
| 6183 |
return (size < 0 || size > UNITS_PER_WORD); |
| 6184 |
} |
| 6185 |
|
| 6186 |
/* For the arm-wince targets we choose to be compatible with Microsoft's |
| 6187 |
ARM and Thumb compilers, which always return aggregates in memory. */ |
| 6188 |
#ifndef ARM_WINCE |
| 6189 |
/* All structures/unions bigger than one word are returned in memory. |
| 6190 |
Also catch the case where int_size_in_bytes returns -1. In this case |
| 6191 |
the aggregate is either huge or of variable size, and in either case |
| 6192 |
we will want to return it via memory and not in a register. */ |
| 6193 |
if (size < 0 || size > UNITS_PER_WORD) |
| 6194 |
return true; |
| 6195 |
|
| 6196 |
if (TREE_CODE (type) == RECORD_TYPE) |
| 6197 |
{ |
| 6198 |
tree field; |
| 6199 |
|
| 6200 |
/* For a struct the APCS says that we only return in a register |
| 6201 |
if the type is 'integer like' and every addressable element |
| 6202 |
has an offset of zero. For practical purposes this means |
| 6203 |
that the structure can have at most one non bit-field element |
| 6204 |
and that this element must be the first one in the structure. */ |
| 6205 |
|
| 6206 |
/* Find the first field, ignoring non FIELD_DECL things which will |
| 6207 |
have been created by C++. */ |
| 6208 |
/* NOTE: This code is deprecated and has not been updated to handle |
| 6209 |
DECL_FIELD_ABI_IGNORED. */ |
| 6210 |
for (field = TYPE_FIELDS (type); |
| 6211 |
field && TREE_CODE (field) != FIELD_DECL; |
| 6212 |
field = DECL_CHAIN (field)) |
| 6213 |
continue; |
| 6214 |
|
| 6215 |
if (field == NULL) |
| 6216 |
return false; /* An empty structure. Allowed by an extension to ANSI C. */ |
| 6217 |
|
| 6218 |
/* Check that the first field is valid for returning in a register. */ |
| 6219 |
|
| 6220 |
/* ... Floats are not allowed */ |
| 6221 |
if (FLOAT_TYPE_P (TREE_TYPE (field))) |
| 6222 |
return true; |
| 6223 |
|
| 6224 |
/* ... Aggregates that are not themselves valid for returning in |
| 6225 |
a register are not allowed. */ |
| 6226 |
if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE)) |
| 6227 |
return true; |
| 6228 |
|
| 6229 |
/* Now check the remaining fields, if any. Only bitfields are allowed, |
| 6230 |
since they are not addressable. */ |
| 6231 |
for (field = DECL_CHAIN (field); |
| 6232 |
field; |
| 6233 |
field = DECL_CHAIN (field)) |
| 6234 |
{ |
| 6235 |
if (TREE_CODE (field) != FIELD_DECL) |
| 6236 |
continue; |
| 6237 |
|
| 6238 |
if (!DECL_BIT_FIELD_TYPE (field)) |
| 6239 |
return true; |
| 6240 |
} |
| 6241 |
|
| 6242 |
return false; |
| 6243 |
} |
| 6244 |
|
| 6245 |
if (TREE_CODE (type) == UNION_TYPE) |
| 6246 |
{ |
| 6247 |
tree field; |
| 6248 |
|
| 6249 |
/* Unions can be returned in registers if every element is |
| 6250 |
integral, or can be returned in an integer register. */ |
| 6251 |
for (field = TYPE_FIELDS (type); |
| 6252 |
field; |
| 6253 |
field = DECL_CHAIN (field)) |
| 6254 |
{ |
| 6255 |
if (TREE_CODE (field) != FIELD_DECL) |
| 6256 |
continue; |
| 6257 |
|
| 6258 |
if (FLOAT_TYPE_P (TREE_TYPE (field))) |
| 6259 |
return true; |
| 6260 |
|
| 6261 |
if (arm_return_in_memory (TREE_TYPE (field), NULL_TREE)) |
| 6262 |
return true; |
| 6263 |
} |
| 6264 |
|
| 6265 |
return false; |
| 6266 |
} |
| 6267 |
#endif /* not ARM_WINCE */ |
| 6268 |
|
| 6269 |
/* Return all other types in memory. */ |
| 6270 |
return true; |
| 6271 |
} |
| 6272 |
|
| 6273 |
const struct pcs_attribute_arg |
| 6274 |
{ |
| 6275 |
const char *arg; |
| 6276 |
enum arm_pcs value; |
| 6277 |
} pcs_attribute_args[] = |
| 6278 |
{ |
| 6279 |
{"aapcs", ARM_PCS_AAPCS}, |
| 6280 |
{"aapcs-vfp", ARM_PCS_AAPCS_VFP}, |
| 6281 |
#if 0 |
| 6282 |
/* We could recognize these, but changes would be needed elsewhere |
| 6283 |
* to implement them. */ |
| 6284 |
{"aapcs-iwmmxt", ARM_PCS_AAPCS_IWMMXT}, |
| 6285 |
{"atpcs", ARM_PCS_ATPCS}, |
| 6286 |
{"apcs", ARM_PCS_APCS}, |
| 6287 |
#endif |
| 6288 |
{NULL, ARM_PCS_UNKNOWN} |
| 6289 |
}; |
| 6290 |
|
| 6291 |
static enum arm_pcs |
| 6292 |
arm_pcs_from_attribute (tree attr) |
| 6293 |
{ |
| 6294 |
const struct pcs_attribute_arg *ptr; |
| 6295 |
const char *arg; |
| 6296 |
|
| 6297 |
/* Get the value of the argument. */ |
| 6298 |
if (TREE_VALUE (attr) == NULL_TREE |
| 6299 |
|| TREE_CODE (TREE_VALUE (attr)) != STRING_CST) |
| 6300 |
return ARM_PCS_UNKNOWN; |
| 6301 |
|
| 6302 |
arg = TREE_STRING_POINTER (TREE_VALUE (attr)); |
| 6303 |
|
| 6304 |
/* Check it against the list of known arguments. */ |
| 6305 |
for (ptr = pcs_attribute_args; ptr->arg != NULL; ptr++) |
| 6306 |
if (streq (arg, ptr->arg)) |
| 6307 |
return ptr->value; |
| 6308 |
|
| 6309 |
/* An unrecognized interrupt type. */ |
| 6310 |
return ARM_PCS_UNKNOWN; |
| 6311 |
} |
| 6312 |
|
| 6313 |
/* Get the PCS variant to use for this call. TYPE is the function's type |
| 6314 |
specification, DECL is the specific declartion. DECL may be null if |
| 6315 |
the call could be indirect or if this is a library call. */ |
| 6316 |
static enum arm_pcs |
| 6317 |
arm_get_pcs_model (const_tree type, const_tree decl ATTRIBUTE_UNUSED) |
| 6318 |
{ |
| 6319 |
bool user_convention = false; |
| 6320 |
enum arm_pcs user_pcs = arm_pcs_default; |
| 6321 |
tree attr; |
| 6322 |
|
| 6323 |
gcc_assert (type); |
| 6324 |
|
| 6325 |
attr = lookup_attribute ("pcs", TYPE_ATTRIBUTES (type)); |
| 6326 |
if (attr) |
| 6327 |
{ |
| 6328 |
user_pcs = arm_pcs_from_attribute (TREE_VALUE (attr)); |
| 6329 |
user_convention = true; |
| 6330 |
} |
| 6331 |
|
| 6332 |
if (TARGET_AAPCS_BASED) |
| 6333 |
{ |
| 6334 |
/* Detect varargs functions. These always use the base rules |
| 6335 |
(no argument is ever a candidate for a co-processor |
| 6336 |
register). */ |
| 6337 |
bool base_rules = stdarg_p (type); |
| 6338 |
|
| 6339 |
if (user_convention) |
| 6340 |
{ |
| 6341 |
if (user_pcs > ARM_PCS_AAPCS_LOCAL) |
| 6342 |
sorry ("non-AAPCS derived PCS variant"); |
| 6343 |
else if (base_rules && user_pcs != ARM_PCS_AAPCS) |
| 6344 |
error ("variadic functions must use the base AAPCS variant"); |
| 6345 |
} |
| 6346 |
|
| 6347 |
if (base_rules) |
| 6348 |
return ARM_PCS_AAPCS; |
| 6349 |
else if (user_convention) |
| 6350 |
return user_pcs; |
| 6351 |
#if 0 |
| 6352 |
/* Unfortunately, this is not safe and can lead to wrong code |
| 6353 |
being generated (PR96882). Not all calls into the back-end |
| 6354 |
pass the DECL, so it is unsafe to make any PCS-changing |
| 6355 |
decisions based on it. In particular the RETURN_IN_MEMORY |
| 6356 |
hook is only ever passed a TYPE. This needs revisiting to |
| 6357 |
see if there are any partial improvements that can be |
| 6358 |
re-enabled. */ |
| 6359 |
else if (decl && flag_unit_at_a_time) |
| 6360 |
{ |
| 6361 |
/* Local functions never leak outside this compilation unit, |
| 6362 |
so we are free to use whatever conventions are |
| 6363 |
appropriate. */ |
| 6364 |
/* FIXME: remove CONST_CAST_TREE when cgraph is constified. */ |
| 6365 |
cgraph_node *local_info_node |
| 6366 |
= cgraph_node::local_info_node (CONST_CAST_TREE (decl)); |
| 6367 |
if (local_info_node && local_info_node->local) |
| 6368 |
return ARM_PCS_AAPCS_LOCAL; |
| 6369 |
} |
| 6370 |
#endif |
| 6371 |
} |
| 6372 |
else if (user_convention && user_pcs != arm_pcs_default) |
| 6373 |
sorry ("PCS variant"); |
| 6374 |
|
| 6375 |
/* For everything else we use the target's default. */ |
| 6376 |
return arm_pcs_default; |
| 6377 |
} |
| 6378 |
|
| 6379 |
|
| 6380 |
static void |
| 6381 |
aapcs_vfp_cum_init (CUMULATIVE_ARGS *pcum ATTRIBUTE_UNUSED, |
| 6382 |
const_tree fntype ATTRIBUTE_UNUSED, |
| 6383 |
rtx libcall ATTRIBUTE_UNUSED, |
| 6384 |
const_tree fndecl ATTRIBUTE_UNUSED) |
| 6385 |
{ |
| 6386 |
/* Record the unallocated VFP registers. */ |
| 6387 |
pcum->aapcs_vfp_regs_free = (1 << NUM_VFP_ARG_REGS) - 1; |
| 6388 |
pcum->aapcs_vfp_reg_alloc = 0; |
| 6389 |
} |
| 6390 |
|
| 6391 |
/* Bitmasks that indicate whether earlier versions of GCC would have |
| 6392 |
taken a different path through the ABI logic. This should result in |
| 6393 |
a -Wpsabi warning if the earlier path led to a different ABI decision. |
| 6394 |
|
| 6395 |
WARN_PSABI_EMPTY_CXX17_BASE |
| 6396 |
Indicates that the type includes an artificial empty C++17 base field |
| 6397 |
that, prior to GCC 10.1, would prevent the type from being treated as |
| 6398 |
a HFA or HVA. See PR94711 for details. |
| 6399 |
|
| 6400 |
WARN_PSABI_NO_UNIQUE_ADDRESS |
| 6401 |
Indicates that the type includes an empty [[no_unique_address]] field |
| 6402 |
that, prior to GCC 10.1, would prevent the type from being treated as |
| 6403 |
a HFA or HVA. */ |
| 6404 |
const unsigned int WARN_PSABI_EMPTY_CXX17_BASE = 1U << 0; |
| 6405 |
const unsigned int WARN_PSABI_NO_UNIQUE_ADDRESS = 1U << 1; |
| 6406 |
const unsigned int WARN_PSABI_ZERO_WIDTH_BITFIELD = 1U << 2; |
| 6407 |
|
| 6408 |
/* Walk down the type tree of TYPE counting consecutive base elements. |
| 6409 |
If *MODEP is VOIDmode, then set it to the first valid floating point |
| 6410 |
type. If a non-floating point type is found, or if a floating point |
| 6411 |
type that doesn't match a non-VOIDmode *MODEP is found, then return -1, |
| 6412 |
otherwise return the count in the sub-tree. |
| 6413 |
|
| 6414 |
The WARN_PSABI_FLAGS argument allows the caller to check whether this |
| 6415 |
function has changed its behavior relative to earlier versions of GCC. |
| 6416 |
Normally the argument should be nonnull and point to a zero-initialized |
| 6417 |
variable. The function then records whether the ABI decision might |
| 6418 |
be affected by a known fix to the ABI logic, setting the associated |
| 6419 |
WARN_PSABI_* bits if so. |
| 6420 |
|
| 6421 |
When the argument is instead a null pointer, the function tries to |
| 6422 |
simulate the behavior of GCC before all such ABI fixes were made. |
| 6423 |
This is useful to check whether the function returns something |
| 6424 |
different after the ABI fixes. */ |
| 6425 |
static int |
| 6426 |
aapcs_vfp_sub_candidate (const_tree type, machine_mode *modep, |
| 6427 |
unsigned int *warn_psabi_flags) |
| 6428 |
{ |
| 6429 |
machine_mode mode; |
| 6430 |
HOST_WIDE_INT size; |
| 6431 |
|
| 6432 |
switch (TREE_CODE (type)) |
| 6433 |
{ |
| 6434 |
case REAL_TYPE: |
| 6435 |
mode = TYPE_MODE (type); |
| 6436 |
if (mode != DFmode && mode != SFmode && mode != HFmode && mode != BFmode) |
| 6437 |
return -1; |
| 6438 |
|
| 6439 |
if (*modep == VOIDmode) |
| 6440 |
*modep = mode; |
| 6441 |
|
| 6442 |
if (*modep == mode) |
| 6443 |
return 1; |
| 6444 |
|
| 6445 |
break; |
| 6446 |
|
| 6447 |
case COMPLEX_TYPE: |
| 6448 |
mode = TYPE_MODE (TREE_TYPE (type)); |
| 6449 |
if (mode != DFmode && mode != SFmode) |
| 6450 |
return -1; |
| 6451 |
|
| 6452 |
if (*modep == VOIDmode) |
| 6453 |
*modep = mode; |
| 6454 |
|
| 6455 |
if (*modep == mode) |
| 6456 |
return 2; |
| 6457 |
|
| 6458 |
break; |
| 6459 |
|
| 6460 |
case VECTOR_TYPE: |
| 6461 |
/* Use V2SImode and V4SImode as representatives of all 64-bit |
| 6462 |
and 128-bit vector types, whether or not those modes are |
| 6463 |
supported with the present options. */ |
| 6464 |
size = int_size_in_bytes (type); |
| 6465 |
switch (size) |
| 6466 |
{ |
| 6467 |
case 8: |
| 6468 |
mode = V2SImode; |
| 6469 |
break; |
| 6470 |
case 16: |
| 6471 |
mode = V4SImode; |
| 6472 |
break; |
| 6473 |
default: |
| 6474 |
return -1; |
| 6475 |
} |
| 6476 |
|
| 6477 |
if (*modep == VOIDmode) |
| 6478 |
*modep = mode; |
| 6479 |
|
| 6480 |
/* Vector modes are considered to be opaque: two vectors are |
| 6481 |
equivalent for the purposes of being homogeneous aggregates |
| 6482 |
if they are the same size. */ |
| 6483 |
if (*modep == mode) |
| 6484 |
return 1; |
| 6485 |
|
| 6486 |
break; |
| 6487 |
|
| 6488 |
case ARRAY_TYPE: |
| 6489 |
{ |
| 6490 |
int count; |
| 6491 |
tree index = TYPE_DOMAIN (type); |
| 6492 |
|
| 6493 |
/* Can't handle incomplete types nor sizes that are not |
| 6494 |
fixed. */ |
| 6495 |
if (!COMPLETE_TYPE_P (type) |
| 6496 |
|| TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) |
| 6497 |
return -1; |
| 6498 |
|
| 6499 |
count = aapcs_vfp_sub_candidate (TREE_TYPE (type), modep, |
| 6500 |
warn_psabi_flags); |
| 6501 |
if (count == -1 |
| 6502 |
|| !index |
| 6503 |
|| !TYPE_MAX_VALUE (index) |
| 6504 |
|| !tree_fits_uhwi_p (TYPE_MAX_VALUE (index)) |
| 6505 |
|| !TYPE_MIN_VALUE (index) |
| 6506 |
|| !tree_fits_uhwi_p (TYPE_MIN_VALUE (index)) |
| 6507 |
|| count < 0) |
| 6508 |
return -1; |
| 6509 |
|
| 6510 |
count *= (1 + tree_to_uhwi (TYPE_MAX_VALUE (index)) |
| 6511 |
- tree_to_uhwi (TYPE_MIN_VALUE (index))); |
| 6512 |
|
| 6513 |
/* There must be no padding. */ |
| 6514 |
if (wi::to_wide (TYPE_SIZE (type)) |
| 6515 |
!= count * GET_MODE_BITSIZE (*modep)) |
| 6516 |
return -1; |
| 6517 |
|
| 6518 |
return count; |
| 6519 |
} |
| 6520 |
|
| 6521 |
case RECORD_TYPE: |
| 6522 |
{ |
| 6523 |
int count = 0; |
| 6524 |
int sub_count; |
| 6525 |
tree field; |
| 6526 |
|
| 6527 |
/* Can't handle incomplete types nor sizes that are not |
| 6528 |
fixed. */ |
| 6529 |
if (!COMPLETE_TYPE_P (type) |
| 6530 |
|| TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) |
| 6531 |
return -1; |
| 6532 |
|
| 6533 |
for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
| 6534 |
{ |
| 6535 |
if (TREE_CODE (field) != FIELD_DECL) |
| 6536 |
continue; |
| 6537 |
|
| 6538 |
if (DECL_FIELD_ABI_IGNORED (field)) |
| 6539 |
{ |
| 6540 |
/* See whether this is something that earlier versions of |
| 6541 |
GCC failed to ignore. */ |
| 6542 |
unsigned int flag; |
| 6543 |
if (lookup_attribute ("no_unique_address", |
| 6544 |
DECL_ATTRIBUTES (field))) |
| 6545 |
flag = WARN_PSABI_NO_UNIQUE_ADDRESS; |
| 6546 |
else if (cxx17_empty_base_field_p (field)) |
| 6547 |
flag = WARN_PSABI_EMPTY_CXX17_BASE; |
| 6548 |
else |
| 6549 |
/* No compatibility problem. */ |
| 6550 |
continue; |
| 6551 |
|
| 6552 |
/* Simulate the old behavior when WARN_PSABI_FLAGS is null. */ |
| 6553 |
if (warn_psabi_flags) |
| 6554 |
{ |
| 6555 |
*warn_psabi_flags |= flag; |
| 6556 |
continue; |
| 6557 |
} |
| 6558 |
} |
| 6559 |
/* A zero-width bitfield may affect layout in some |
| 6560 |
circumstances, but adds no members. The determination |
| 6561 |
of whether or not a type is an HFA is performed after |
| 6562 |
layout is complete, so if the type still looks like an |
| 6563 |
HFA afterwards, it is still classed as one. This is |
| 6564 |
potentially an ABI break for the hard-float ABI. */ |
| 6565 |
else if (DECL_BIT_FIELD (field) |
| 6566 |
&& integer_zerop (DECL_SIZE (field))) |
| 6567 |
{ |
| 6568 |
/* Prior to GCC-12 these fields were striped early, |
| 6569 |
hiding them from the back-end entirely and |
| 6570 |
resulting in the correct behaviour for argument |
| 6571 |
passing. Simulate that old behaviour without |
| 6572 |
generating a warning. */ |
| 6573 |
if (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field)) |
| 6574 |
continue; |
| 6575 |
if (warn_psabi_flags) |
| 6576 |
{ |
| 6577 |
*warn_psabi_flags |= WARN_PSABI_ZERO_WIDTH_BITFIELD; |
| 6578 |
continue; |
| 6579 |
} |
| 6580 |
} |
| 6581 |
|
| 6582 |
sub_count = aapcs_vfp_sub_candidate (TREE_TYPE (field), modep, |
| 6583 |
warn_psabi_flags); |
| 6584 |
if (sub_count < 0) |
| 6585 |
return -1; |
| 6586 |
count += sub_count; |
| 6587 |
} |
| 6588 |
|
| 6589 |
/* There must be no padding. */ |
| 6590 |
if (wi::to_wide (TYPE_SIZE (type)) |
| 6591 |
!= count * GET_MODE_BITSIZE (*modep)) |
| 6592 |
return -1; |
| 6593 |
|
| 6594 |
return count; |
| 6595 |
} |
| 6596 |
|
| 6597 |
case UNION_TYPE: |
| 6598 |
case QUAL_UNION_TYPE: |
| 6599 |
{ |
| 6600 |
/* These aren't very interesting except in a degenerate case. */ |
| 6601 |
int count = 0; |
| 6602 |
int sub_count; |
| 6603 |
tree field; |
| 6604 |
|
| 6605 |
/* Can't handle incomplete types nor sizes that are not |
| 6606 |
fixed. */ |
| 6607 |
if (!COMPLETE_TYPE_P (type) |
| 6608 |
|| TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) |
| 6609 |
return -1; |
| 6610 |
|
| 6611 |
for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
| 6612 |
{ |
| 6613 |
if (TREE_CODE (field) != FIELD_DECL) |
| 6614 |
continue; |
| 6615 |
|
| 6616 |
sub_count = aapcs_vfp_sub_candidate (TREE_TYPE (field), modep, |
| 6617 |
warn_psabi_flags); |
| 6618 |
if (sub_count < 0) |
| 6619 |
return -1; |
| 6620 |
count = count > sub_count ? count : sub_count; |
| 6621 |
} |
| 6622 |
|
| 6623 |
/* There must be no padding. */ |
| 6624 |
if (wi::to_wide (TYPE_SIZE (type)) |
| 6625 |
!= count * GET_MODE_BITSIZE (*modep)) |
| 6626 |
return -1; |
| 6627 |
|
| 6628 |
return count; |
| 6629 |
} |
| 6630 |
|
| 6631 |
default: |
| 6632 |
break; |
| 6633 |
} |
| 6634 |
|
| 6635 |
return -1; |
| 6636 |
} |
| 6637 |
|
| 6638 |
/* Return true if PCS_VARIANT should use VFP registers. */ |
| 6639 |
static bool |
| 6640 |
use_vfp_abi (enum arm_pcs pcs_variant, bool is_double) |
| 6641 |
{ |
| 6642 |
if (pcs_variant == ARM_PCS_AAPCS_VFP) |
| 6643 |
{ |
| 6644 |
static bool seen_thumb1_vfp = false; |
| 6645 |
|
| 6646 |
if (TARGET_THUMB1 && !seen_thumb1_vfp) |
| 6647 |
{ |
| 6648 |
sorry ("Thumb-1 %<hard-float%> VFP ABI"); |
| 6649 |
/* sorry() is not immediately fatal, so only display this once. */ |
| 6650 |
seen_thumb1_vfp = true; |
| 6651 |
} |
| 6652 |
|
| 6653 |
return true; |
| 6654 |
} |
| 6655 |
|
| 6656 |
if (pcs_variant != ARM_PCS_AAPCS_LOCAL) |
| 6657 |
return false; |
| 6658 |
|
| 6659 |
return (TARGET_32BIT && TARGET_HARD_FLOAT && |
| 6660 |
(TARGET_VFP_DOUBLE || !is_double)); |
| 6661 |
} |
| 6662 |
|
| 6663 |
/* Return true if an argument whose type is TYPE, or mode is MODE, is |
| 6664 |
suitable for passing or returning in VFP registers for the PCS |
| 6665 |
variant selected. If it is, then *BASE_MODE is updated to contain |
| 6666 |
a machine mode describing each element of the argument's type and |
| 6667 |
*COUNT to hold the number of such elements. */ |
| 6668 |
static bool |
| 6669 |
aapcs_vfp_is_call_or_return_candidate (enum arm_pcs pcs_variant, |
| 6670 |
machine_mode mode, const_tree type, |
| 6671 |
machine_mode *base_mode, int *count) |
| 6672 |
{ |
| 6673 |
machine_mode new_mode = VOIDmode; |
| 6674 |
|
| 6675 |
/* If we have the type information, prefer that to working things |
| 6676 |
out from the mode. */ |
| 6677 |
if (type) |
| 6678 |
{ |
| 6679 |
unsigned int warn_psabi_flags = 0; |
| 6680 |
int ag_count = aapcs_vfp_sub_candidate (type, &new_mode, |
| 6681 |
&warn_psabi_flags); |
| 6682 |
if (ag_count > 0 && ag_count <= 4) |
| 6683 |
{ |
| 6684 |
static unsigned last_reported_type_uid; |
| 6685 |
unsigned uid = TYPE_UID (TYPE_MAIN_VARIANT (type)); |
| 6686 |
int alt; |
| 6687 |
if (warn_psabi |
| 6688 |
&& warn_psabi_flags |
| 6689 |
&& uid != last_reported_type_uid |
| 6690 |
&& ((alt = aapcs_vfp_sub_candidate (type, &new_mode, NULL)) |
| 6691 |
!= ag_count)) |
| 6692 |
{ |
| 6693 |
const char *url10 |
| 6694 |
= CHANGES_ROOT_URL "gcc-10/changes.html#empty_base"; |
| 6695 |
const char *url12 |
| 6696 |
= CHANGES_ROOT_URL "gcc-12/changes.html#zero_width_bitfields"; |
| 6697 |
gcc_assert (alt == -1); |
| 6698 |
last_reported_type_uid = uid; |
| 6699 |
/* Use TYPE_MAIN_VARIANT to strip any redundant const |
| 6700 |
qualification. */ |
| 6701 |
if (warn_psabi_flags & WARN_PSABI_NO_UNIQUE_ADDRESS) |
| 6702 |
inform (input_location, "parameter passing for argument of " |
| 6703 |
"type %qT with %<[[no_unique_address]]%> members " |
| 6704 |
"changed %{in GCC 10.1%}", |
| 6705 |
TYPE_MAIN_VARIANT (type), url10); |
| 6706 |
else if (warn_psabi_flags & WARN_PSABI_EMPTY_CXX17_BASE) |
| 6707 |
inform (input_location, "parameter passing for argument of " |
| 6708 |
"type %qT when C++17 is enabled changed to match " |
| 6709 |
"C++14 %{in GCC 10.1%}", |
| 6710 |
TYPE_MAIN_VARIANT (type), url10); |
| 6711 |
else if (warn_psabi_flags & WARN_PSABI_ZERO_WIDTH_BITFIELD) |
| 6712 |
inform (input_location, "parameter passing for argument of " |
| 6713 |
"type %qT changed %{in GCC 12.1%}", |
| 6714 |
TYPE_MAIN_VARIANT (type), url12); |
| 6715 |
} |
| 6716 |
*count = ag_count; |
| 6717 |
} |
| 6718 |
else |
| 6719 |
return false; |
| 6720 |
} |
| 6721 |
else if (GET_MODE_CLASS (mode) == MODE_FLOAT |
| 6722 |
|| GET_MODE_CLASS (mode) == MODE_VECTOR_INT |
| 6723 |
|| GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT) |
| 6724 |
{ |
| 6725 |
*count = 1; |
| 6726 |
new_mode = mode; |
| 6727 |
} |
| 6728 |
else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT) |
| 6729 |
{ |
| 6730 |
*count = 2; |
| 6731 |
new_mode = (mode == DCmode ? DFmode : SFmode); |
| 6732 |
} |
| 6733 |
else |
| 6734 |
return false; |
| 6735 |
|
| 6736 |
|
| 6737 |
if (!use_vfp_abi (pcs_variant, ARM_NUM_REGS (new_mode) > 1)) |
| 6738 |
return false; |
| 6739 |
|
| 6740 |
*base_mode = new_mode; |
| 6741 |
|
| 6742 |
if (TARGET_GENERAL_REGS_ONLY) |
| 6743 |
error ("argument of type %qT not permitted with %<-mgeneral-regs-only%>", |
| 6744 |
type); |
| 6745 |
|
| 6746 |
return true; |
| 6747 |
} |
| 6748 |
|
| 6749 |
static bool |
| 6750 |
aapcs_vfp_is_return_candidate (enum arm_pcs pcs_variant, |
| 6751 |
machine_mode mode, const_tree type) |
| 6752 |
{ |
| 6753 |
int count ATTRIBUTE_UNUSED; |
| 6754 |
machine_mode ag_mode ATTRIBUTE_UNUSED; |
| 6755 |
|
| 6756 |
if (!use_vfp_abi (pcs_variant, false)) |
| 6757 |
return false; |
| 6758 |
return aapcs_vfp_is_call_or_return_candidate (pcs_variant, mode, type, |
| 6759 |
&ag_mode, &count); |
| 6760 |
} |
| 6761 |
|
| 6762 |
static bool |
| 6763 |
aapcs_vfp_is_call_candidate (CUMULATIVE_ARGS *pcum, machine_mode mode, |
| 6764 |
const_tree type) |
| 6765 |
{ |
| 6766 |
if (!use_vfp_abi (pcum->pcs_variant, false)) |
| 6767 |
return false; |
| 6768 |
|
| 6769 |
return aapcs_vfp_is_call_or_return_candidate (pcum->pcs_variant, mode, type, |
| 6770 |
&pcum->aapcs_vfp_rmode, |
| 6771 |
&pcum->aapcs_vfp_rcount); |
| 6772 |
} |
| 6773 |
|
| 6774 |
/* Implement the allocate field in aapcs_cp_arg_layout. See the comment there |
| 6775 |
for the behaviour of this function. */ |
| 6776 |
|
| 6777 |
static bool |
| 6778 |
aapcs_vfp_allocate (CUMULATIVE_ARGS *pcum, machine_mode mode, |
| 6779 |
const_tree type ATTRIBUTE_UNUSED) |
| 6780 |
{ |
| 6781 |
int rmode_size |
| 6782 |
= MAX (GET_MODE_SIZE (pcum->aapcs_vfp_rmode), GET_MODE_SIZE (SFmode)); |
| 6783 |
int shift = rmode_size / GET_MODE_SIZE (SFmode); |
| 6784 |
unsigned mask = (1 << (shift * pcum->aapcs_vfp_rcount)) - 1; |
| 6785 |
int regno; |
| 6786 |
|
| 6787 |
for (regno = 0; regno < NUM_VFP_ARG_REGS; regno += shift) |
| 6788 |
if (((pcum->aapcs_vfp_regs_free >> regno) & mask) == mask) |
| 6789 |
{ |
| 6790 |
pcum->aapcs_vfp_reg_alloc = mask << regno; |
| 6791 |
if (mode == BLKmode |
| 6792 |
|| (mode == TImode && ! (TARGET_NEON || TARGET_HAVE_MVE)) |
| 6793 |
|| ! arm_hard_regno_mode_ok (FIRST_VFP_REGNUM + regno, mode)) |
| 6794 |
{ |
| 6795 |
int i; |
| 6796 |
int rcount = pcum->aapcs_vfp_rcount; |
| 6797 |
int rshift = shift; |
| 6798 |
machine_mode rmode = pcum->aapcs_vfp_rmode; |
| 6799 |
rtx par; |
| 6800 |
if (!(TARGET_NEON || TARGET_HAVE_MVE)) |
| 6801 |
{ |
| 6802 |
/* Avoid using unsupported vector modes. */ |
| 6803 |
if (rmode == V2SImode) |
| 6804 |
rmode = DImode; |
| 6805 |
else if (rmode == V4SImode) |
| 6806 |
{ |
| 6807 |
rmode = DImode; |
| 6808 |
rcount *= 2; |
| 6809 |
rshift /= 2; |
| 6810 |
} |
| 6811 |
} |
| 6812 |
par = gen_rtx_PARALLEL (mode, rtvec_alloc (rcount)); |
| 6813 |
for (i = 0; i < rcount; i++) |
| 6814 |
{ |
| 6815 |
rtx tmp = gen_rtx_REG (rmode, |
| 6816 |
FIRST_VFP_REGNUM + regno + i * rshift); |
| 6817 |
tmp = gen_rtx_EXPR_LIST |
| 6818 |
(VOIDmode, tmp, |
| 6819 |
GEN_INT (i * GET_MODE_SIZE (rmode))); |
| 6820 |
XVECEXP (par, 0, i) = tmp; |
| 6821 |
} |
| 6822 |
|
| 6823 |
pcum->aapcs_reg = par; |
| 6824 |
} |
| 6825 |
else |
| 6826 |
pcum->aapcs_reg = gen_rtx_REG (mode, FIRST_VFP_REGNUM + regno); |
| 6827 |
return true; |
| 6828 |
} |
| 6829 |
return false; |
| 6830 |
} |
| 6831 |
|
| 6832 |
/* Implement the allocate_return_reg field in aapcs_cp_arg_layout. See the |
| 6833 |
comment there for the behaviour of this function. */ |
| 6834 |
|
| 6835 |
static rtx |
| 6836 |
aapcs_vfp_allocate_return_reg (enum arm_pcs pcs_variant ATTRIBUTE_UNUSED, |
| 6837 |
machine_mode mode, |
| 6838 |
const_tree type ATTRIBUTE_UNUSED) |
| 6839 |
{ |
| 6840 |
if (!use_vfp_abi (pcs_variant, false)) |
| 6841 |
return NULL; |
| 6842 |
|
| 6843 |
if (mode == BLKmode |
| 6844 |
|| (GET_MODE_CLASS (mode) == MODE_INT |
| 6845 |
&& GET_MODE_SIZE (mode) >= GET_MODE_SIZE (TImode) |
| 6846 |
&& !(TARGET_NEON || TARGET_HAVE_MVE))) |
| 6847 |
{ |
| 6848 |
int count; |
| 6849 |
machine_mode ag_mode; |
| 6850 |
int i; |
| 6851 |
rtx par; |
| 6852 |
int shift; |
| 6853 |
|
| 6854 |
aapcs_vfp_is_call_or_return_candidate (pcs_variant, mode, type, |
| 6855 |
&ag_mode, &count); |
| 6856 |
|
| 6857 |
if (!(TARGET_NEON || TARGET_HAVE_MVE)) |
| 6858 |
{ |
| 6859 |
if (ag_mode == V2SImode) |
| 6860 |
ag_mode = DImode; |
| 6861 |
else if (ag_mode == V4SImode) |
| 6862 |
{ |
| 6863 |
ag_mode = DImode; |
| 6864 |
count *= 2; |
| 6865 |
} |
| 6866 |
} |
| 6867 |
shift = GET_MODE_SIZE(ag_mode) / GET_MODE_SIZE(SFmode); |
| 6868 |
par = gen_rtx_PARALLEL (mode, rtvec_alloc (count)); |
| 6869 |
for (i = 0; i < count; i++) |
| 6870 |
{ |
| 6871 |
rtx tmp = gen_rtx_REG (ag_mode, FIRST_VFP_REGNUM + i * shift); |
| 6872 |
tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, |
| 6873 |
GEN_INT (i * GET_MODE_SIZE (ag_mode))); |
| 6874 |
XVECEXP (par, 0, i) = tmp; |
| 6875 |
} |
| 6876 |
|
| 6877 |
return par; |
| 6878 |
} |
| 6879 |
|
| 6880 |
return gen_rtx_REG (mode, FIRST_VFP_REGNUM); |
| 6881 |
} |
| 6882 |
|
| 6883 |
static void |
| 6884 |
aapcs_vfp_advance (CUMULATIVE_ARGS *pcum ATTRIBUTE_UNUSED, |
| 6885 |
machine_mode mode ATTRIBUTE_UNUSED, |
| 6886 |
const_tree type ATTRIBUTE_UNUSED) |
| 6887 |
{ |
| 6888 |
pcum->aapcs_vfp_regs_free &= ~pcum->aapcs_vfp_reg_alloc; |
| 6889 |
pcum->aapcs_vfp_reg_alloc = 0; |
| 6890 |
return; |
| 6891 |
} |
| 6892 |
|
| 6893 |
#define AAPCS_CP(X) \ |
| 6894 |
{ \ |
| 6895 |
aapcs_ ## X ## _cum_init, \ |
| 6896 |
aapcs_ ## X ## _is_call_candidate, \ |
| 6897 |
aapcs_ ## X ## _allocate, \ |
| 6898 |
aapcs_ ## X ## _is_return_candidate, \ |
| 6899 |
aapcs_ ## X ## _allocate_return_reg, \ |
| 6900 |
aapcs_ ## X ## _advance \ |
| 6901 |
} |
| 6902 |
|
| 6903 |
/* Table of co-processors that can be used to pass arguments in |
| 6904 |
registers. Idealy no arugment should be a candidate for more than |
| 6905 |
one co-processor table entry, but the table is processed in order |
| 6906 |
and stops after the first match. If that entry then fails to put |
| 6907 |
the argument into a co-processor register, the argument will go on |
| 6908 |
the stack. */ |
| 6909 |
static struct |
| 6910 |
{ |
| 6911 |
/* Initialize co-processor related state in CUMULATIVE_ARGS structure. */ |
| 6912 |
void (*cum_init) (CUMULATIVE_ARGS *, const_tree, rtx, const_tree); |
| 6913 |
|
| 6914 |
/* Return true if an argument of mode MODE (or type TYPE if MODE is |
| 6915 |
BLKmode) is a candidate for this co-processor's registers; this |
| 6916 |
function should ignore any position-dependent state in |
| 6917 |
CUMULATIVE_ARGS and only use call-type dependent information. */ |
| 6918 |
bool (*is_call_candidate) (CUMULATIVE_ARGS *, machine_mode, const_tree); |
| 6919 |
|
| 6920 |
/* Return true if the argument does get a co-processor register; it |
| 6921 |
should set aapcs_reg to an RTX of the register allocated as is |
| 6922 |
required for a return from FUNCTION_ARG. */ |
| 6923 |
bool (*allocate) (CUMULATIVE_ARGS *, machine_mode, const_tree); |
| 6924 |
|
| 6925 |
/* Return true if a result of mode MODE (or type TYPE if MODE is BLKmode) can |
| 6926 |
be returned in this co-processor's registers. */ |
| 6927 |
bool (*is_return_candidate) (enum arm_pcs, machine_mode, const_tree); |
| 6928 |
|
| 6929 |
/* Allocate and return an RTX element to hold the return type of a call. This |
| 6930 |
routine must not fail and will only be called if is_return_candidate |
| 6931 |
returned true with the same parameters. */ |
| 6932 |
rtx (*allocate_return_reg) (enum arm_pcs, machine_mode, const_tree); |
| 6933 |
|
| 6934 |
/* Finish processing this argument and prepare to start processing |
| 6935 |
the next one. */ |
| 6936 |
void (*advance) (CUMULATIVE_ARGS *, machine_mode, const_tree); |
| 6937 |
} aapcs_cp_arg_layout[ARM_NUM_COPROC_SLOTS] = |
| 6938 |
{ |
| 6939 |
AAPCS_CP(vfp) |
| 6940 |
}; |
| 6941 |
|
| 6942 |
#undef AAPCS_CP |
| 6943 |
|
| 6944 |
static int |
| 6945 |
aapcs_select_call_coproc (CUMULATIVE_ARGS *pcum, machine_mode mode, |
| 6946 |
const_tree type) |
| 6947 |
{ |
| 6948 |
int i; |
| 6949 |
|
| 6950 |
for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) |
| 6951 |
if (aapcs_cp_arg_layout[i].is_call_candidate (pcum, mode, type)) |
| 6952 |
return i; |
| 6953 |
|
| 6954 |
return -1; |
| 6955 |
} |
| 6956 |
|
| 6957 |
static int |
| 6958 |
aapcs_select_return_coproc (const_tree type, const_tree fntype) |
| 6959 |
{ |
| 6960 |
/* We aren't passed a decl, so we can't check that a call is local. |
| 6961 |
However, it isn't clear that that would be a win anyway, since it |
| 6962 |
might limit some tail-calling opportunities. */ |
| 6963 |
enum arm_pcs pcs_variant; |
| 6964 |
|
| 6965 |
if (fntype) |
| 6966 |
{ |
| 6967 |
const_tree fndecl = NULL_TREE; |
| 6968 |
|
| 6969 |
if (TREE_CODE (fntype) == FUNCTION_DECL) |
| 6970 |
{ |
| 6971 |
fndecl = fntype; |
| 6972 |
fntype = TREE_TYPE (fntype); |
| 6973 |
} |
| 6974 |
|
| 6975 |
pcs_variant = arm_get_pcs_model (fntype, fndecl); |
| 6976 |
} |
| 6977 |
else |
| 6978 |
pcs_variant = arm_pcs_default; |
| 6979 |
|
| 6980 |
if (pcs_variant != ARM_PCS_AAPCS) |
| 6981 |
{ |
| 6982 |
int i; |
| 6983 |
|
| 6984 |
for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) |
| 6985 |
if (aapcs_cp_arg_layout[i].is_return_candidate (pcs_variant, |
| 6986 |
TYPE_MODE (type), |
| 6987 |
type)) |
| 6988 |
return i; |
| 6989 |
} |
| 6990 |
return -1; |
| 6991 |
} |
| 6992 |
|
| 6993 |
static rtx |
| 6994 |
aapcs_allocate_return_reg (machine_mode mode, const_tree type, |
| 6995 |
const_tree fntype) |
| 6996 |
{ |
| 6997 |
/* We aren't passed a decl, so we can't check that a call is local. |
| 6998 |
However, it isn't clear that that would be a win anyway, since it |
| 6999 |
might limit some tail-calling opportunities. */ |
| 7000 |
enum arm_pcs pcs_variant; |
| 7001 |
int unsignedp ATTRIBUTE_UNUSED; |
| 7002 |
|
| 7003 |
if (fntype) |
| 7004 |
{ |
| 7005 |
const_tree fndecl = NULL_TREE; |
| 7006 |
|
| 7007 |
if (TREE_CODE (fntype) == FUNCTION_DECL) |
| 7008 |
{ |
| 7009 |
fndecl = fntype; |
| 7010 |
fntype = TREE_TYPE (fntype); |
| 7011 |
} |
| 7012 |
|
| 7013 |
pcs_variant = arm_get_pcs_model (fntype, fndecl); |
| 7014 |
} |
| 7015 |
else |
| 7016 |
pcs_variant = arm_pcs_default; |
| 7017 |
|
| 7018 |
/* Promote integer types. */ |
| 7019 |
if (type && INTEGRAL_TYPE_P (type)) |
| 7020 |
mode = arm_promote_function_mode (type, mode, &unsignedp, fntype, 1); |
| 7021 |
|
| 7022 |
if (pcs_variant != ARM_PCS_AAPCS) |
| 7023 |
{ |
| 7024 |
int i; |
| 7025 |
|
| 7026 |
for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) |
| 7027 |
if (aapcs_cp_arg_layout[i].is_return_candidate (pcs_variant, mode, |
| 7028 |
type)) |
| 7029 |
return aapcs_cp_arg_layout[i].allocate_return_reg (pcs_variant, |
| 7030 |
mode, type); |
| 7031 |
} |
| 7032 |
|
| 7033 |
/* Promotes small structs returned in a register to full-word size |
| 7034 |
for big-endian AAPCS. */ |
| 7035 |
if (type && arm_return_in_msb (type)) |
| 7036 |
{ |
| 7037 |
HOST_WIDE_INT size = int_size_in_bytes (type); |
| 7038 |
if (size % UNITS_PER_WORD != 0) |
| 7039 |
{ |
| 7040 |
size += UNITS_PER_WORD - size % UNITS_PER_WORD; |
| 7041 |
mode = int_mode_for_size (size * BITS_PER_UNIT, 0).require (); |
| 7042 |
} |
| 7043 |
} |
| 7044 |
|
| 7045 |
return gen_rtx_REG (mode, R0_REGNUM); |
| 7046 |
} |
| 7047 |
|
| 7048 |
static rtx |
| 7049 |
aapcs_libcall_value (machine_mode mode) |
| 7050 |
{ |
| 7051 |
if (BYTES_BIG_ENDIAN && ALL_FIXED_POINT_MODE_P (mode) |
| 7052 |
&& GET_MODE_SIZE (mode) <= 4) |
| 7053 |
mode = SImode; |
| 7054 |
|
| 7055 |
return aapcs_allocate_return_reg (mode, NULL_TREE, NULL_TREE); |
| 7056 |
} |
| 7057 |
|
| 7058 |
/* Lay out a function argument using the AAPCS rules. The rule |
| 7059 |
numbers referred to here are those in the AAPCS. */ |
| 7060 |
static void |
| 7061 |
aapcs_layout_arg (CUMULATIVE_ARGS *pcum, machine_mode mode, |
| 7062 |
const_tree type, bool named) |
| 7063 |
{ |
| 7064 |
int nregs, nregs2; |
| 7065 |
int ncrn; |
| 7066 |
|
| 7067 |
/* We only need to do this once per argument. */ |
| 7068 |
if (pcum->aapcs_arg_processed) |
| 7069 |
return; |
| 7070 |
|
| 7071 |
pcum->aapcs_arg_processed = true; |
| 7072 |
|
| 7073 |
/* Special case: if named is false then we are handling an incoming |
| 7074 |
anonymous argument which is on the stack. */ |
| 7075 |
if (!named) |
| 7076 |
return; |
| 7077 |
|
| 7078 |
/* Is this a potential co-processor register candidate? */ |
| 7079 |
if (pcum->pcs_variant != ARM_PCS_AAPCS) |
| 7080 |
{ |
| 7081 |
int slot = aapcs_select_call_coproc (pcum, mode, type); |
| 7082 |
pcum->aapcs_cprc_slot = slot; |
| 7083 |
|
| 7084 |
/* We don't have to apply any of the rules from part B of the |
| 7085 |
preparation phase, these are handled elsewhere in the |
| 7086 |
compiler. */ |
| 7087 |
|
| 7088 |
if (slot >= 0) |
| 7089 |
{ |
| 7090 |
/* A Co-processor register candidate goes either in its own |
| 7091 |
class of registers or on the stack. */ |
| 7092 |
if (!pcum->aapcs_cprc_failed[slot]) |
| 7093 |
{ |
| 7094 |
/* C1.cp - Try to allocate the argument to co-processor |
| 7095 |
registers. */ |
| 7096 |
if (aapcs_cp_arg_layout[slot].allocate (pcum, mode, type)) |
| 7097 |
return; |
| 7098 |
|
| 7099 |
/* C2.cp - Put the argument on the stack and note that we |
| 7100 |
can't assign any more candidates in this slot. We also |
| 7101 |
need to note that we have allocated stack space, so that |
| 7102 |
we won't later try to split a non-cprc candidate between |
| 7103 |
core registers and the stack. */ |
| 7104 |
pcum->aapcs_cprc_failed[slot] = true; |
| 7105 |
pcum->can_split = false; |
| 7106 |
} |
| 7107 |
|
| 7108 |
/* We didn't get a register, so this argument goes on the |
| 7109 |
stack. */ |
| 7110 |
gcc_assert (pcum->can_split == false); |
| 7111 |
return; |
| 7112 |
} |
| 7113 |
} |
| 7114 |
|
| 7115 |
/* C3 - For double-word aligned arguments, round the NCRN up to the |
| 7116 |
next even number. */ |
| 7117 |
ncrn = pcum->aapcs_ncrn; |
| 7118 |
if (ncrn & 1) |
| 7119 |
{ |
| 7120 |
int res = arm_needs_doubleword_align (mode, type); |
| 7121 |
/* Only warn during RTL expansion of call stmts, otherwise we would |
| 7122 |
warn e.g. during gimplification even on functions that will be |
| 7123 |
always inlined, and we'd warn multiple times. Don't warn when |
| 7124 |
called in expand_function_start either, as we warn instead in |
| 7125 |
arm_function_arg_boundary in that case. */ |
| 7126 |
if (res < 0 && warn_psabi && currently_expanding_gimple_stmt) |
| 7127 |
inform (input_location, "parameter passing for argument of type " |
| 7128 |
"%qT changed in GCC 7.1", type); |
| 7129 |
else if (res > 0) |
| 7130 |
ncrn++; |
| 7131 |
} |
| 7132 |
|
| 7133 |
nregs = ARM_NUM_REGS2(mode, type); |
| 7134 |
|
| 7135 |
/* Sigh, this test should really assert that nregs > 0, but a GCC |
| 7136 |
extension allows empty structs and then gives them empty size; it |
| 7137 |
then allows such a structure to be passed by value. For some of |
| 7138 |
the code below we have to pretend that such an argument has |
| 7139 |
non-zero size so that we 'locate' it correctly either in |
| 7140 |
registers or on the stack. */ |
| 7141 |
gcc_assert (nregs >= 0); |
| 7142 |
|
| 7143 |
nregs2 = nregs ? nregs : 1; |
| 7144 |
|
| 7145 |
/* C4 - Argument fits entirely in core registers. */ |
| 7146 |
if (ncrn + nregs2 <= NUM_ARG_REGS) |
| 7147 |
{ |
| 7148 |
pcum->aapcs_reg = gen_rtx_REG (mode, ncrn); |
| 7149 |
pcum->aapcs_next_ncrn = ncrn + nregs; |
| 7150 |
return; |
| 7151 |
} |
| 7152 |
|
| 7153 |
/* C5 - Some core registers left and there are no arguments already |
| 7154 |
on the stack: split this argument between the remaining core |
| 7155 |
registers and the stack. */ |
| 7156 |
if (ncrn < NUM_ARG_REGS && pcum->can_split) |
| 7157 |
{ |
| 7158 |
pcum->aapcs_reg = gen_rtx_REG (mode, ncrn); |
| 7159 |
pcum->aapcs_next_ncrn = NUM_ARG_REGS; |
| 7160 |
pcum->aapcs_partial = (NUM_ARG_REGS - ncrn) * UNITS_PER_WORD; |
| 7161 |
return; |
| 7162 |
} |
| 7163 |
|
| 7164 |
/* C6 - NCRN is set to 4. */ |
| 7165 |
pcum->aapcs_next_ncrn = NUM_ARG_REGS; |
| 7166 |
|
| 7167 |
/* C7,C8 - arugment goes on the stack. We have nothing to do here. */ |
| 7168 |
return; |
| 7169 |
} |
| 7170 |
|
| 7171 |
/* Initialize a variable CUM of type CUMULATIVE_ARGS |
| 7172 |
for a call to a function whose data type is FNTYPE. |
| 7173 |
For a library call, FNTYPE is NULL. */ |
| 7174 |
void |
| 7175 |
arm_init_cumulative_args (CUMULATIVE_ARGS *pcum, tree fntype, |
| 7176 |
rtx libname, |
| 7177 |
tree fndecl ATTRIBUTE_UNUSED) |
| 7178 |
{ |
| 7179 |
/* Long call handling. */ |
| 7180 |
if (fntype) |
| 7181 |
pcum->pcs_variant = arm_get_pcs_model (fntype, fndecl); |
| 7182 |
else |
| 7183 |
pcum->pcs_variant = arm_pcs_default; |
| 7184 |
|
| 7185 |
if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) |
| 7186 |
{ |
| 7187 |
if (arm_libcall_uses_aapcs_base (libname)) |
| 7188 |
pcum->pcs_variant = ARM_PCS_AAPCS; |
| 7189 |
|
| 7190 |
pcum->aapcs_ncrn = pcum->aapcs_next_ncrn = 0; |
| 7191 |
pcum->aapcs_reg = NULL_RTX; |
| 7192 |
pcum->aapcs_partial = 0; |
| 7193 |
pcum->aapcs_arg_processed = false; |
| 7194 |
pcum->aapcs_cprc_slot = -1; |
| 7195 |
pcum->can_split = true; |
| 7196 |
|
| 7197 |
if (pcum->pcs_variant != ARM_PCS_AAPCS) |
| 7198 |
{ |
| 7199 |
int i; |
| 7200 |
|
| 7201 |
for (i = 0; i < ARM_NUM_COPROC_SLOTS; i++) |
| 7202 |
{ |
| 7203 |
pcum->aapcs_cprc_failed[i] = false; |
| 7204 |
aapcs_cp_arg_layout[i].cum_init (pcum, fntype, libname, fndecl); |
| 7205 |
} |
| 7206 |
} |
| 7207 |
return; |
| 7208 |
} |
| 7209 |
|
| 7210 |
/* Legacy ABIs */ |
| 7211 |
|
| 7212 |
/* On the ARM, the offset starts at 0. */ |
| 7213 |
pcum->nregs = 0; |
| 7214 |
pcum->iwmmxt_nregs = 0; |
| 7215 |
pcum->can_split = true; |
| 7216 |
|
| 7217 |
/* Varargs vectors are treated the same as long long. |
| 7218 |
named_count avoids having to change the way arm handles 'named' */ |
| 7219 |
pcum->named_count = 0; |
| 7220 |
pcum->nargs = 0; |
| 7221 |
|
| 7222 |
if (TARGET_REALLY_IWMMXT && fntype) |
| 7223 |
{ |
| 7224 |
tree fn_arg; |
| 7225 |
|
| 7226 |
for (fn_arg = TYPE_ARG_TYPES (fntype); |
| 7227 |
fn_arg; |
| 7228 |
fn_arg = TREE_CHAIN (fn_arg)) |
| 7229 |
pcum->named_count += 1; |
| 7230 |
|
| 7231 |
if (! pcum->named_count) |
| 7232 |
pcum->named_count = INT_MAX; |
| 7233 |
} |
| 7234 |
} |
| 7235 |
|
| 7236 |
/* Return 2 if double word alignment is required for argument passing, |
| 7237 |
but wasn't required before the fix for PR88469. |
| 7238 |
Return 1 if double word alignment is required for argument passing. |
| 7239 |
Return -1 if double word alignment used to be required for argument |
| 7240 |
passing before PR77728 ABI fix, but is not required anymore. |
| 7241 |
Return 0 if double word alignment is not required and wasn't requried |
| 7242 |
before either. */ |
| 7243 |
static int |
| 7244 |
arm_needs_doubleword_align (machine_mode mode, const_tree type) |
| 7245 |
{ |
| 7246 |
if (!type) |
| 7247 |
return GET_MODE_ALIGNMENT (mode) > PARM_BOUNDARY; |
| 7248 |
|
| 7249 |
/* Scalar and vector types: Use natural alignment, i.e. of base type. */ |
| 7250 |
if (!AGGREGATE_TYPE_P (type)) |
| 7251 |
return TYPE_ALIGN (TYPE_MAIN_VARIANT (type)) > PARM_BOUNDARY; |
| 7252 |
|
| 7253 |
/* Array types: Use member alignment of element type. */ |
| 7254 |
if (TREE_CODE (type) == ARRAY_TYPE) |
| 7255 |
return TYPE_ALIGN (TREE_TYPE (type)) > PARM_BOUNDARY; |
| 7256 |
|
| 7257 |
int ret = 0; |
| 7258 |
int ret2 = 0; |
| 7259 |
/* Record/aggregate types: Use greatest member alignment of any member. |
| 7260 |
|
| 7261 |
Note that we explicitly consider zero-sized fields here, even though |
| 7262 |
they don't map to AAPCS machine types. For example, in: |
| 7263 |
|
| 7264 |
struct __attribute__((aligned(8))) empty {}; |
| 7265 |
|
| 7266 |
struct s { |
| 7267 |
[[no_unique_address]] empty e; |
| 7268 |
int x; |
| 7269 |
}; |
| 7270 |
|
| 7271 |
"s" contains only one Fundamental Data Type (the int field) |
| 7272 |
but gains 8-byte alignment and size thanks to "e". */ |
| 7273 |
for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
| 7274 |
if (DECL_ALIGN (field) > PARM_BOUNDARY) |
| 7275 |
{ |
| 7276 |
if (TREE_CODE (field) == FIELD_DECL) |
| 7277 |
return 1; |
| 7278 |
else |
| 7279 |
/* Before PR77728 fix, we were incorrectly considering also |
| 7280 |
other aggregate fields, like VAR_DECLs, TYPE_DECLs etc. |
| 7281 |
Make sure we can warn about that with -Wpsabi. */ |
| 7282 |
ret = -1; |
| 7283 |
} |
| 7284 |
else if (TREE_CODE (field) == FIELD_DECL |
| 7285 |
&& DECL_BIT_FIELD_TYPE (field) |
| 7286 |
&& TYPE_ALIGN (DECL_BIT_FIELD_TYPE (field)) > PARM_BOUNDARY) |
| 7287 |
ret2 = 1; |
| 7288 |
|
| 7289 |
if (ret2) |
| 7290 |
return 2; |
| 7291 |
|
| 7292 |
return ret; |
| 7293 |
} |
| 7294 |
|
| 7295 |
|
| 7296 |
/* Determine where to put an argument to a function. |
| 7297 |
Value is zero to push the argument on the stack, |
| 7298 |
or a hard register in which to store the argument. |
| 7299 |
|
| 7300 |
CUM is a variable of type CUMULATIVE_ARGS which gives info about |
| 7301 |
the preceding args and about the function being called. |
| 7302 |
ARG is a description of the argument. |
| 7303 |
|
| 7304 |
On the ARM, normally the first 16 bytes are passed in registers r0-r3; all |
| 7305 |
other arguments are passed on the stack. If (NAMED == 0) (which happens |
| 7306 |
only in assign_parms, since TARGET_SETUP_INCOMING_VARARGS is |
| 7307 |
defined), say it is passed in the stack (function_prologue will |
| 7308 |
indeed make it pass in the stack if necessary). */ |
| 7309 |
|
| 7310 |
static rtx |
| 7311 |
arm_function_arg (cumulative_args_t pcum_v, const function_arg_info &arg) |
| 7312 |
{ |
| 7313 |
CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v); |
| 7314 |
int nregs; |
| 7315 |
|
| 7316 |
/* Handle the special case quickly. Pick an arbitrary value for op2 of |
| 7317 |
a call insn (op3 of a call_value insn). */ |
| 7318 |
if (arg.end_marker_p ()) |
| 7319 |
return const0_rtx; |
| 7320 |
|
| 7321 |
if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) |
| 7322 |
{ |
| 7323 |
aapcs_layout_arg (pcum, arg.mode, arg.type, arg.named); |
| 7324 |
return pcum->aapcs_reg; |
| 7325 |
} |
| 7326 |
|
| 7327 |
/* Varargs vectors are treated the same as long long. |
| 7328 |
named_count avoids having to change the way arm handles 'named' */ |
| 7329 |
if (TARGET_IWMMXT_ABI |
| 7330 |
&& arm_vector_mode_supported_p (arg.mode) |
| 7331 |
&& pcum->named_count > pcum->nargs + 1) |
| 7332 |
{ |
| 7333 |
if (pcum->iwmmxt_nregs <= 9) |
| 7334 |
return gen_rtx_REG (arg.mode, |
| 7335 |
pcum->iwmmxt_nregs + FIRST_IWMMXT_REGNUM); |
| 7336 |
else |
| 7337 |
{ |
| 7338 |
pcum->can_split = false; |
| 7339 |
return NULL_RTX; |
| 7340 |
} |
| 7341 |
} |
| 7342 |
|
| 7343 |
/* Put doubleword aligned quantities in even register pairs. */ |
| 7344 |
if ((pcum->nregs & 1) && ARM_DOUBLEWORD_ALIGN) |
| 7345 |
{ |
| 7346 |
int res = arm_needs_doubleword_align (arg.mode, arg.type); |
| 7347 |
if (res < 0 && warn_psabi) |
| 7348 |
inform (input_location, "parameter passing for argument of type " |
| 7349 |
"%qT changed in GCC 7.1", arg.type); |
| 7350 |
else if (res > 0) |
| 7351 |
{ |
| 7352 |
pcum->nregs++; |
| 7353 |
if (res > 1 && warn_psabi) |
| 7354 |
inform (input_location, "parameter passing for argument of type " |
| 7355 |
"%qT changed in GCC 9.1", arg.type); |
| 7356 |
} |
| 7357 |
} |
| 7358 |
|
| 7359 |
/* Only allow splitting an arg between regs and memory if all preceding |
| 7360 |
args were allocated to regs. For args passed by reference we only count |
| 7361 |
the reference pointer. */ |
| 7362 |
if (pcum->can_split) |
| 7363 |
nregs = 1; |
| 7364 |
else |
| 7365 |
nregs = ARM_NUM_REGS2 (arg.mode, arg.type); |
| 7366 |
|
| 7367 |
if (!arg.named || pcum->nregs + nregs > NUM_ARG_REGS) |
| 7368 |
return NULL_RTX; |
| 7369 |
|
| 7370 |
return gen_rtx_REG (arg.mode, pcum->nregs); |
| 7371 |
} |
| 7372 |
|
| 7373 |
static unsigned int |
| 7374 |
arm_function_arg_boundary (machine_mode mode, const_tree type) |
| 7375 |
{ |
| 7376 |
if (!ARM_DOUBLEWORD_ALIGN) |
| 7377 |
return PARM_BOUNDARY; |
| 7378 |
|
| 7379 |
int res = arm_needs_doubleword_align (mode, type); |
| 7380 |
if (res < 0 && warn_psabi) |
| 7381 |
inform (input_location, "parameter passing for argument of type %qT " |
| 7382 |
"changed in GCC 7.1", type); |
| 7383 |
if (res > 1 && warn_psabi) |
| 7384 |
inform (input_location, "parameter passing for argument of type " |
| 7385 |
"%qT changed in GCC 9.1", type); |
| 7386 |
|
| 7387 |
return res > 0 ? DOUBLEWORD_ALIGNMENT : PARM_BOUNDARY; |
| 7388 |
} |
| 7389 |
|
| 7390 |
static int |
| 7391 |
arm_arg_partial_bytes (cumulative_args_t pcum_v, const function_arg_info &arg) |
| 7392 |
{ |
| 7393 |
CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v); |
| 7394 |
int nregs = pcum->nregs; |
| 7395 |
|
| 7396 |
if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) |
| 7397 |
{ |
| 7398 |
aapcs_layout_arg (pcum, arg.mode, arg.type, arg.named); |
| 7399 |
return pcum->aapcs_partial; |
| 7400 |
} |
| 7401 |
|
| 7402 |
if (TARGET_IWMMXT_ABI && arm_vector_mode_supported_p (arg.mode)) |
| 7403 |
return 0; |
| 7404 |
|
| 7405 |
if (NUM_ARG_REGS > nregs |
| 7406 |
&& (NUM_ARG_REGS < nregs + ARM_NUM_REGS2 (arg.mode, arg.type)) |
| 7407 |
&& pcum->can_split) |
| 7408 |
return (NUM_ARG_REGS - nregs) * UNITS_PER_WORD; |
| 7409 |
|
| 7410 |
return 0; |
| 7411 |
} |
| 7412 |
|
| 7413 |
/* Update the data in PCUM to advance over argument ARG. */ |
| 7414 |
|
| 7415 |
static void |
| 7416 |
arm_function_arg_advance (cumulative_args_t pcum_v, |
| 7417 |
const function_arg_info &arg) |
| 7418 |
{ |
| 7419 |
CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v); |
| 7420 |
|
| 7421 |
if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) |
| 7422 |
{ |
| 7423 |
aapcs_layout_arg (pcum, arg.mode, arg.type, arg.named); |
| 7424 |
|
| 7425 |
if (pcum->aapcs_cprc_slot >= 0) |
| 7426 |
{ |
| 7427 |
aapcs_cp_arg_layout[pcum->aapcs_cprc_slot].advance (pcum, arg.mode, |
| 7428 |
arg.type); |
| 7429 |
pcum->aapcs_cprc_slot = -1; |
| 7430 |
} |
| 7431 |
|
| 7432 |
/* Generic stuff. */ |
| 7433 |
pcum->aapcs_arg_processed = false; |
| 7434 |
pcum->aapcs_ncrn = pcum->aapcs_next_ncrn; |
| 7435 |
pcum->aapcs_reg = NULL_RTX; |
| 7436 |
pcum->aapcs_partial = 0; |
| 7437 |
} |
| 7438 |
else |
| 7439 |
{ |
| 7440 |
pcum->nargs += 1; |
| 7441 |
if (arm_vector_mode_supported_p (arg.mode) |
| 7442 |
&& pcum->named_count > pcum->nargs |
| 7443 |
&& TARGET_IWMMXT_ABI) |
| 7444 |
pcum->iwmmxt_nregs += 1; |
| 7445 |
else |
| 7446 |
pcum->nregs += ARM_NUM_REGS2 (arg.mode, arg.type); |
| 7447 |
} |
| 7448 |
} |
| 7449 |
|
| 7450 |
/* Variable sized types are passed by reference. This is a GCC |
| 7451 |
extension to the ARM ABI. */ |
| 7452 |
|
| 7453 |
static bool |
| 7454 |
arm_pass_by_reference (cumulative_args_t, const function_arg_info &arg) |
| 7455 |
{ |
| 7456 |
return arg.type && TREE_CODE (TYPE_SIZE (arg.type)) != INTEGER_CST; |
| 7457 |
} |
| 7458 |
|
| 7459 |
/* Encode the current state of the #pragma [no_]long_calls. */ |
| 7460 |
typedef enum |
| 7461 |
{ |
| 7462 |
OFF, /* No #pragma [no_]long_calls is in effect. */ |
| 7463 |
LONG, /* #pragma long_calls is in effect. */ |
| 7464 |
SHORT /* #pragma no_long_calls is in effect. */ |
| 7465 |
} arm_pragma_enum; |
| 7466 |
|
| 7467 |
static arm_pragma_enum arm_pragma_long_calls = OFF; |
| 7468 |
|
| 7469 |
void |
| 7470 |
arm_pr_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED) |
| 7471 |
{ |
| 7472 |
arm_pragma_long_calls = LONG; |
| 7473 |
} |
| 7474 |
|
| 7475 |
void |
| 7476 |
arm_pr_no_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED) |
| 7477 |
{ |
| 7478 |
arm_pragma_long_calls = SHORT; |
| 7479 |
} |
| 7480 |
|
| 7481 |
void |
| 7482 |
arm_pr_long_calls_off (struct cpp_reader * pfile ATTRIBUTE_UNUSED) |
| 7483 |
{ |
| 7484 |
arm_pragma_long_calls = OFF; |
| 7485 |
} |
| 7486 |
|
| 7487 |
/* Handle an attribute requiring a FUNCTION_DECL; |
| 7488 |
arguments as in struct attribute_spec.handler. */ |
| 7489 |
static tree |
| 7490 |
arm_handle_fndecl_attribute (tree *node, tree name, tree args ATTRIBUTE_UNUSED, |
| 7491 |
int flags ATTRIBUTE_UNUSED, bool *no_add_attrs) |
| 7492 |
{ |
| 7493 |
if (TREE_CODE (*node) != FUNCTION_DECL) |
| 7494 |
{ |
| 7495 |
warning (OPT_Wattributes, "%qE attribute only applies to functions", |
| 7496 |
name); |
| 7497 |
*no_add_attrs = true; |
| 7498 |
} |
| 7499 |
|
| 7500 |
return NULL_TREE; |
| 7501 |
} |
| 7502 |
|
| 7503 |
/* Handle an "interrupt" or "isr" attribute; |
| 7504 |
arguments as in struct attribute_spec.handler. */ |
| 7505 |
static tree |
| 7506 |
arm_handle_isr_attribute (tree *node, tree name, tree args, int flags, |
| 7507 |
bool *no_add_attrs) |
| 7508 |
{ |
| 7509 |
if (DECL_P (*node)) |
| 7510 |
{ |
| 7511 |
if (TREE_CODE (*node) != FUNCTION_DECL) |
| 7512 |
{ |
| 7513 |
warning (OPT_Wattributes, "%qE attribute only applies to functions", |
| 7514 |
name); |
| 7515 |
*no_add_attrs = true; |
| 7516 |
} |
| 7517 |
else if (TARGET_VFP_BASE) |
| 7518 |
{ |
| 7519 |
warning (OPT_Wattributes, "FP registers might be clobbered despite %qE attribute: compile with %<-mgeneral-regs-only%>", |
| 7520 |
name); |
| 7521 |
} |
| 7522 |
/* FIXME: the argument if any is checked for type attributes; |
| 7523 |
should it be checked for decl ones? */ |
| 7524 |
} |
| 7525 |
else |
| 7526 |
{ |
| 7527 |
if (FUNC_OR_METHOD_TYPE_P (*node)) |
| 7528 |
{ |
| 7529 |
if (arm_isr_value (args) == ARM_FT_UNKNOWN) |
| 7530 |
{ |
| 7531 |
warning (OPT_Wattributes, "%qE attribute ignored", |
| 7532 |
name); |
| 7533 |
*no_add_attrs = true; |
| 7534 |
} |
| 7535 |
} |
| 7536 |
else if (TREE_CODE (*node) == POINTER_TYPE |
| 7537 |
&& FUNC_OR_METHOD_TYPE_P (TREE_TYPE (*node)) |
| 7538 |
&& arm_isr_value (args) != ARM_FT_UNKNOWN) |
| 7539 |
{ |
| 7540 |
*node = build_variant_type_copy (*node); |
| 7541 |
TREE_TYPE (*node) = build_type_attribute_variant |
| 7542 |
(TREE_TYPE (*node), |
| 7543 |
tree_cons (name, args, TYPE_ATTRIBUTES (TREE_TYPE (*node)))); |
| 7544 |
*no_add_attrs = true; |
| 7545 |
} |
| 7546 |
else |
| 7547 |
{ |
| 7548 |
/* Possibly pass this attribute on from the type to a decl. */ |
| 7549 |
if (flags & ((int) ATTR_FLAG_DECL_NEXT |
| 7550 |
| (int) ATTR_FLAG_FUNCTION_NEXT |
| 7551 |
| (int) ATTR_FLAG_ARRAY_NEXT)) |
| 7552 |
{ |
| 7553 |
*no_add_attrs = true; |
| 7554 |
return tree_cons (name, args, NULL_TREE); |
| 7555 |
} |
| 7556 |
else |
| 7557 |
{ |
| 7558 |
warning (OPT_Wattributes, "%qE attribute ignored", |
| 7559 |
name); |
| 7560 |
} |
| 7561 |
} |
| 7562 |
} |
| 7563 |
|
| 7564 |
return NULL_TREE; |
| 7565 |
} |
| 7566 |
|
| 7567 |
/* Handle a "pcs" attribute; arguments as in struct |
| 7568 |
attribute_spec.handler. */ |
| 7569 |
static tree |
| 7570 |
arm_handle_pcs_attribute (tree *node ATTRIBUTE_UNUSED, tree name, tree args, |
| 7571 |
int flags ATTRIBUTE_UNUSED, bool *no_add_attrs) |
| 7572 |
{ |
| 7573 |
if (arm_pcs_from_attribute (args) == ARM_PCS_UNKNOWN) |
| 7574 |
{ |
| 7575 |
warning (OPT_Wattributes, "%qE attribute ignored", name); |
| 7576 |
*no_add_attrs = true; |
| 7577 |
} |
| 7578 |
return NULL_TREE; |
| 7579 |
} |
| 7580 |
|
| 7581 |
#if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
| 7582 |
/* Handle the "notshared" attribute. This attribute is another way of |
| 7583 |
requesting hidden visibility. ARM's compiler supports |
| 7584 |
"__declspec(notshared)"; we support the same thing via an |
| 7585 |
attribute. */ |
| 7586 |
|
| 7587 |
static tree |
| 7588 |
arm_handle_notshared_attribute (tree *node, |
| 7589 |
tree name ATTRIBUTE_UNUSED, |
| 7590 |
tree args ATTRIBUTE_UNUSED, |
| 7591 |
int flags ATTRIBUTE_UNUSED, |
| 7592 |
bool *no_add_attrs) |
| 7593 |
{ |
| 7594 |
tree decl = TYPE_NAME (*node); |
| 7595 |
|
| 7596 |
if (decl) |
| 7597 |
{ |
| 7598 |
DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; |
| 7599 |
DECL_VISIBILITY_SPECIFIED (decl) = 1; |
| 7600 |
*no_add_attrs = false; |
| 7601 |
} |
| 7602 |
return NULL_TREE; |
| 7603 |
} |
| 7604 |
#endif |
| 7605 |
|
| 7606 |
/* This function returns true if a function with declaration FNDECL and type |
| 7607 |
FNTYPE uses the stack to pass arguments or return variables and false |
| 7608 |
otherwise. This is used for functions with the attributes |
| 7609 |
'cmse_nonsecure_call' or 'cmse_nonsecure_entry' and this function will issue |
| 7610 |
diagnostic messages if the stack is used. NAME is the name of the attribute |
| 7611 |
used. */ |
| 7612 |
|
| 7613 |
static bool |
| 7614 |
cmse_func_args_or_return_in_stack (tree fndecl, tree name, tree fntype) |
| 7615 |
{ |
| 7616 |
function_args_iterator args_iter; |
| 7617 |
CUMULATIVE_ARGS args_so_far_v; |
| 7618 |
cumulative_args_t args_so_far; |
| 7619 |
bool first_param = true; |
| 7620 |
tree arg_type, prev_arg_type = NULL_TREE, ret_type; |
| 7621 |
|
| 7622 |
/* Error out if any argument is passed on the stack. */ |
| 7623 |
arm_init_cumulative_args (&args_so_far_v, fntype, NULL_RTX, fndecl); |
| 7624 |
args_so_far = pack_cumulative_args (&args_so_far_v); |
| 7625 |
FOREACH_FUNCTION_ARGS (fntype, arg_type, args_iter) |
| 7626 |
{ |
| 7627 |
rtx arg_rtx; |
| 7628 |
|
| 7629 |
prev_arg_type = arg_type; |
| 7630 |
if (VOID_TYPE_P (arg_type)) |
| 7631 |
continue; |
| 7632 |
|
| 7633 |
function_arg_info arg (arg_type, /*named=*/true); |
| 7634 |
if (!first_param) |
| 7635 |
/* ??? We should advance after processing the argument and pass |
| 7636 |
the argument we're advancing past. */ |
| 7637 |
arm_function_arg_advance (args_so_far, arg); |
| 7638 |
arg_rtx = arm_function_arg (args_so_far, arg); |
| 7639 |
if (!arg_rtx || arm_arg_partial_bytes (args_so_far, arg)) |
| 7640 |
{ |
| 7641 |
error ("%qE attribute not available to functions with arguments " |
| 7642 |
"passed on the stack", name); |
| 7643 |
return true; |
| 7644 |
} |
| 7645 |
first_param = false; |
| 7646 |
} |
| 7647 |
|
| 7648 |
/* Error out for variadic functions since we cannot control how many |
| 7649 |
arguments will be passed and thus stack could be used. stdarg_p () is not |
| 7650 |
used for the checking to avoid browsing arguments twice. */ |
| 7651 |
if (prev_arg_type != NULL_TREE && !VOID_TYPE_P (prev_arg_type)) |
| 7652 |
{ |
| 7653 |
error ("%qE attribute not available to functions with variable number " |
| 7654 |
"of arguments", name); |
| 7655 |
return true; |
| 7656 |
} |
| 7657 |
|
| 7658 |
/* Error out if return value is passed on the stack. */ |
| 7659 |
ret_type = TREE_TYPE (fntype); |
| 7660 |
if (arm_return_in_memory (ret_type, fntype)) |
| 7661 |
{ |
| 7662 |
error ("%qE attribute not available to functions that return value on " |
| 7663 |
"the stack", name); |
| 7664 |
return true; |
| 7665 |
} |
| 7666 |
return false; |
| 7667 |
} |
| 7668 |
|
| 7669 |
/* Called upon detection of the use of the cmse_nonsecure_entry attribute, this |
| 7670 |
function will check whether the attribute is allowed here and will add the |
| 7671 |
attribute to the function declaration tree or otherwise issue a warning. */ |
| 7672 |
|
| 7673 |
static tree |
| 7674 |
arm_handle_cmse_nonsecure_entry (tree *node, tree name, |
| 7675 |
tree /* args */, |
| 7676 |
int /* flags */, |
| 7677 |
bool *no_add_attrs) |
| 7678 |
{ |
| 7679 |
tree fndecl; |
| 7680 |
|
| 7681 |
if (!use_cmse) |
| 7682 |
{ |
| 7683 |
*no_add_attrs = true; |
| 7684 |
warning (OPT_Wattributes, "%qE attribute ignored without %<-mcmse%> " |
| 7685 |
"option", name); |
| 7686 |
return NULL_TREE; |
| 7687 |
} |
| 7688 |
|
| 7689 |
/* Ignore attribute for function types. */ |
| 7690 |
if (TREE_CODE (*node) != FUNCTION_DECL) |
| 7691 |
{ |
| 7692 |
warning (OPT_Wattributes, "%qE attribute only applies to functions", |
| 7693 |
name); |
| 7694 |
*no_add_attrs = true; |
| 7695 |
return NULL_TREE; |
| 7696 |
} |
| 7697 |
|
| 7698 |
fndecl = *node; |
| 7699 |
|
| 7700 |
/* Warn for static linkage functions. */ |
| 7701 |
if (!TREE_PUBLIC (fndecl)) |
| 7702 |
{ |
| 7703 |
warning (OPT_Wattributes, "%qE attribute has no effect on functions " |
| 7704 |
"with static linkage", name); |
| 7705 |
*no_add_attrs = true; |
| 7706 |
return NULL_TREE; |
| 7707 |
} |
| 7708 |
|
| 7709 |
*no_add_attrs |= cmse_func_args_or_return_in_stack (fndecl, name, |
| 7710 |
TREE_TYPE (fndecl)); |
| 7711 |
return NULL_TREE; |
| 7712 |
} |
| 7713 |
|
| 7714 |
|
| 7715 |
/* Called upon detection of the use of the cmse_nonsecure_call attribute, this |
| 7716 |
function will check whether the attribute is allowed here and will add the |
| 7717 |
attribute to the function type tree or otherwise issue a diagnostic. The |
| 7718 |
reason we check this at declaration time is to only allow the use of the |
| 7719 |
attribute with declarations of function pointers and not function |
| 7720 |
declarations. This function checks NODE is of the expected type and issues |
| 7721 |
diagnostics otherwise using NAME. If it is not of the expected type |
| 7722 |
*NO_ADD_ATTRS will be set to true. */ |
| 7723 |
|
| 7724 |
static tree |
| 7725 |
arm_handle_cmse_nonsecure_call (tree *node, tree name, |
| 7726 |
tree /* args */, |
| 7727 |
int /* flags */, |
| 7728 |
bool *no_add_attrs) |
| 7729 |
{ |
| 7730 |
tree decl = NULL_TREE; |
| 7731 |
tree fntype, type; |
| 7732 |
|
| 7733 |
if (!use_cmse) |
| 7734 |
{ |
| 7735 |
*no_add_attrs = true; |
| 7736 |
warning (OPT_Wattributes, "%qE attribute ignored without %<-mcmse%> " |
| 7737 |
"option", name); |
| 7738 |
return NULL_TREE; |
| 7739 |
} |
| 7740 |
|
| 7741 |
if (DECL_P (*node)) |
| 7742 |
{ |
| 7743 |
fntype = TREE_TYPE (*node); |
| 7744 |
|
| 7745 |
if (VAR_P (*node) || TREE_CODE (*node) == TYPE_DECL) |
| 7746 |
decl = *node; |
| 7747 |
} |
| 7748 |
else |
| 7749 |
fntype = *node; |
| 7750 |
|
| 7751 |
while (fntype && TREE_CODE (fntype) == POINTER_TYPE) |
| 7752 |
fntype = TREE_TYPE (fntype); |
| 7753 |
|
| 7754 |
if ((DECL_P (*node) && !decl) || TREE_CODE (fntype) != FUNCTION_TYPE) |
| 7755 |
{ |
| 7756 |
warning (OPT_Wattributes, "%qE attribute only applies to base type of a " |
| 7757 |
"function pointer", name); |
| 7758 |
*no_add_attrs = true; |
| 7759 |
return NULL_TREE; |
| 7760 |
} |
| 7761 |
|
| 7762 |
*no_add_attrs |= cmse_func_args_or_return_in_stack (NULL, name, fntype); |
| 7763 |
|
| 7764 |
if (*no_add_attrs) |
| 7765 |
return NULL_TREE; |
| 7766 |
|
| 7767 |
/* Prevent trees being shared among function types with and without |
| 7768 |
cmse_nonsecure_call attribute. */ |
| 7769 |
if (decl) |
| 7770 |
{ |
| 7771 |
type = build_distinct_type_copy (TREE_TYPE (decl)); |
| 7772 |
TREE_TYPE (decl) = type; |
| 7773 |
} |
| 7774 |
else |
| 7775 |
{ |
| 7776 |
type = build_distinct_type_copy (*node); |
| 7777 |
*node = type; |
| 7778 |
} |
| 7779 |
|
| 7780 |
fntype = type; |
| 7781 |
|
| 7782 |
while (TREE_CODE (fntype) != FUNCTION_TYPE) |
| 7783 |
{ |
| 7784 |
type = fntype; |
| 7785 |
fntype = TREE_TYPE (fntype); |
| 7786 |
fntype = build_distinct_type_copy (fntype); |
| 7787 |
TREE_TYPE (type) = fntype; |
| 7788 |
} |
| 7789 |
|
| 7790 |
/* Construct a type attribute and add it to the function type. */ |
| 7791 |
tree attrs = tree_cons (get_identifier ("cmse_nonsecure_call"), NULL_TREE, |
| 7792 |
TYPE_ATTRIBUTES (fntype)); |
| 7793 |
TYPE_ATTRIBUTES (fntype) = attrs; |
| 7794 |
return NULL_TREE; |
| 7795 |
} |
| 7796 |
|
| 7797 |
/* Return 0 if the attributes for two types are incompatible, 1 if they |
| 7798 |
are compatible, and 2 if they are nearly compatible (which causes a |
| 7799 |
warning to be generated). */ |
| 7800 |
static int |
| 7801 |
arm_comp_type_attributes (const_tree type1, const_tree type2) |
| 7802 |
{ |
| 7803 |
int l1, l2, s1, s2; |
| 7804 |
|
| 7805 |
tree attrs1 = lookup_attribute ("Advanced SIMD type", |
| 7806 |
TYPE_ATTRIBUTES (type1)); |
| 7807 |
tree attrs2 = lookup_attribute ("Advanced SIMD type", |
| 7808 |
TYPE_ATTRIBUTES (type2)); |
| 7809 |
if (bool (attrs1) != bool (attrs2)) |
| 7810 |
return 0; |
| 7811 |
if (attrs1 && !attribute_value_equal (attrs1, attrs2)) |
| 7812 |
return 0; |
| 7813 |
|
| 7814 |
/* Check for mismatch of non-default calling convention. */ |
| 7815 |
if (TREE_CODE (type1) != FUNCTION_TYPE) |
| 7816 |
return 1; |
| 7817 |
|
| 7818 |
/* Check for mismatched call attributes. */ |
| 7819 |
l1 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type1)) != NULL; |
| 7820 |
l2 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type2)) != NULL; |
| 7821 |
s1 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type1)) != NULL; |
| 7822 |
s2 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type2)) != NULL; |
| 7823 |
|
| 7824 |
/* Only bother to check if an attribute is defined. */ |
| 7825 |
if (l1 | l2 | s1 | s2) |
| 7826 |
{ |
| 7827 |
/* If one type has an attribute, the other must have the same attribute. */ |
| 7828 |
if ((l1 != l2) || (s1 != s2)) |
| 7829 |
return 0; |
| 7830 |
|
| 7831 |
/* Disallow mixed attributes. */ |
| 7832 |
if ((l1 & s2) || (l2 & s1)) |
| 7833 |
return 0; |
| 7834 |
} |
| 7835 |
|
| 7836 |
/* Check for mismatched ISR attribute. */ |
| 7837 |
l1 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type1)) != NULL; |
| 7838 |
if (! l1) |
| 7839 |
l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1)) != NULL; |
| 7840 |
l2 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type2)) != NULL; |
| 7841 |
if (! l2) |
| 7842 |
l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2)) != NULL; |
| 7843 |
if (l1 != l2) |
| 7844 |
return 0; |
| 7845 |
|
| 7846 |
l1 = lookup_attribute ("cmse_nonsecure_call", |
| 7847 |
TYPE_ATTRIBUTES (type1)) != NULL; |
| 7848 |
l2 = lookup_attribute ("cmse_nonsecure_call", |
| 7849 |
TYPE_ATTRIBUTES (type2)) != NULL; |
| 7850 |
|
| 7851 |
if (l1 != l2) |
| 7852 |
return 0; |
| 7853 |
|
| 7854 |
return 1; |
| 7855 |
} |
| 7856 |
|
| 7857 |
/* Assigns default attributes to newly defined type. This is used to |
| 7858 |
set short_call/long_call attributes for function types of |
| 7859 |
functions defined inside corresponding #pragma scopes. */ |
| 7860 |
static void |
| 7861 |
arm_set_default_type_attributes (tree type) |
| 7862 |
{ |
| 7863 |
/* Add __attribute__ ((long_call)) to all functions, when |
| 7864 |
inside #pragma long_calls or __attribute__ ((short_call)), |
| 7865 |
when inside #pragma no_long_calls. */ |
| 7866 |
if (FUNC_OR_METHOD_TYPE_P (type)) |
| 7867 |
{ |
| 7868 |
tree type_attr_list, attr_name; |
| 7869 |
type_attr_list = TYPE_ATTRIBUTES (type); |
| 7870 |
|
| 7871 |
if (arm_pragma_long_calls == LONG) |
| 7872 |
attr_name = get_identifier ("long_call"); |
| 7873 |
else if (arm_pragma_long_calls == SHORT) |
| 7874 |
attr_name = get_identifier ("short_call"); |
| 7875 |
else |
| 7876 |
return; |
| 7877 |
|
| 7878 |
type_attr_list = tree_cons (attr_name, NULL_TREE, type_attr_list); |
| 7879 |
TYPE_ATTRIBUTES (type) = type_attr_list; |
| 7880 |
} |
| 7881 |
} |
| 7882 |
|
| 7883 |
/* Return true if DECL is known to be linked into section SECTION. */ |
| 7884 |
|
| 7885 |
static bool |
| 7886 |
arm_function_in_section_p (tree decl, section *section) |
| 7887 |
{ |
| 7888 |
/* We can only be certain about the prevailing symbol definition. */ |
| 7889 |
if (!decl_binds_to_current_def_p (decl)) |
| 7890 |
return false; |
| 7891 |
|
| 7892 |
/* If DECL_SECTION_NAME is set, assume it is trustworthy. */ |
| 7893 |
if (!DECL_SECTION_NAME (decl)) |
| 7894 |
{ |
| 7895 |
/* Make sure that we will not create a unique section for DECL. */ |
| 7896 |
if (flag_function_sections || DECL_COMDAT_GROUP (decl)) |
| 7897 |
return false; |
| 7898 |
} |
| 7899 |
|
| 7900 |
return function_section (decl) == section; |
| 7901 |
} |
| 7902 |
|
| 7903 |
/* Return nonzero if a 32-bit "long_call" should be generated for |
| 7904 |
a call from the current function to DECL. We generate a long_call |
| 7905 |
if the function: |
| 7906 |
|
| 7907 |
a. has an __attribute__((long call)) |
| 7908 |
or b. is within the scope of a #pragma long_calls |
| 7909 |
or c. the -mlong-calls command line switch has been specified |
| 7910 |
|
| 7911 |
However we do not generate a long call if the function: |
| 7912 |
|
| 7913 |
d. has an __attribute__ ((short_call)) |
| 7914 |
or e. is inside the scope of a #pragma no_long_calls |
| 7915 |
or f. is defined in the same section as the current function. */ |
| 7916 |
|
| 7917 |
bool |
| 7918 |
arm_is_long_call_p (tree decl) |
| 7919 |
{ |
| 7920 |
tree attrs; |
| 7921 |
|
| 7922 |
if (!decl) |
| 7923 |
return TARGET_LONG_CALLS; |
| 7924 |
|
| 7925 |
attrs = TYPE_ATTRIBUTES (TREE_TYPE (decl)); |
| 7926 |
if (lookup_attribute ("short_call", attrs)) |
| 7927 |
return false; |
| 7928 |
|
| 7929 |
/* For "f", be conservative, and only cater for cases in which the |
| 7930 |
whole of the current function is placed in the same section. */ |
| 7931 |
if (!flag_reorder_blocks_and_partition |
| 7932 |
&& TREE_CODE (decl) == FUNCTION_DECL |
| 7933 |
&& arm_function_in_section_p (decl, current_function_section ())) |
| 7934 |
return false; |
| 7935 |
|
| 7936 |
if (lookup_attribute ("long_call", attrs)) |
| 7937 |
return true; |
| 7938 |
|
| 7939 |
return TARGET_LONG_CALLS; |
| 7940 |
} |
| 7941 |
|
| 7942 |
/* Return nonzero if it is ok to make a tail-call to DECL. */ |
| 7943 |
static bool |
| 7944 |
arm_function_ok_for_sibcall (tree decl, tree exp) |
| 7945 |
{ |
| 7946 |
unsigned long func_type; |
| 7947 |
|
| 7948 |
if (cfun->machine->sibcall_blocked) |
| 7949 |
return false; |
| 7950 |
|
| 7951 |
if (TARGET_FDPIC) |
| 7952 |
{ |
| 7953 |
/* In FDPIC, never tailcall something for which we have no decl: |
| 7954 |
the target function could be in a different module, requiring |
| 7955 |
a different FDPIC register value. */ |
| 7956 |
if (decl == NULL) |
| 7957 |
return false; |
| 7958 |
} |
| 7959 |
|
| 7960 |
/* Never tailcall something if we are generating code for Thumb-1. */ |
| 7961 |
if (TARGET_THUMB1) |
| 7962 |
return false; |
| 7963 |
|
| 7964 |
/* The PIC register is live on entry to VxWorks PLT entries, so we |
| 7965 |
must make the call before restoring the PIC register. */ |
| 7966 |
if (TARGET_VXWORKS_RTP && flag_pic && decl && !targetm.binds_local_p (decl)) |
| 7967 |
return false; |
| 7968 |
|
| 7969 |
/* ??? Cannot tail-call to long calls with APCS frame and VFP, because IP |
| 7970 |
may be used both as target of the call and base register for restoring |
| 7971 |
the VFP registers */ |
| 7972 |
if (TARGET_APCS_FRAME && TARGET_ARM |
| 7973 |
&& TARGET_HARD_FLOAT |
| 7974 |
&& decl && arm_is_long_call_p (decl)) |
| 7975 |
return false; |
| 7976 |
|
| 7977 |
/* If we are interworking and the function is not declared static |
| 7978 |
then we can't tail-call it unless we know that it exists in this |
| 7979 |
compilation unit (since it might be a Thumb routine). */ |
| 7980 |
if (TARGET_INTERWORK && decl && TREE_PUBLIC (decl) |
| 7981 |
&& !TREE_ASM_WRITTEN (decl)) |
| 7982 |
return false; |
| 7983 |
|
| 7984 |
func_type = arm_current_func_type (); |
| 7985 |
/* Never tailcall from an ISR routine - it needs a special exit sequence. */ |
| 7986 |
if (IS_INTERRUPT (func_type)) |
| 7987 |
return false; |
| 7988 |
|
| 7989 |
/* ARMv8-M non-secure entry functions need to return with bxns which is only |
| 7990 |
generated for entry functions themselves. */ |
| 7991 |
if (IS_CMSE_ENTRY (arm_current_func_type ())) |
| 7992 |
return false; |
| 7993 |
|
| 7994 |
/* We do not allow ARMv8-M non-secure calls to be turned into sibling calls, |
| 7995 |
this would complicate matters for later code generation. */ |
| 7996 |
if (TREE_CODE (exp) == CALL_EXPR) |
| 7997 |
{ |
| 7998 |
tree fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp))); |
| 7999 |
if (lookup_attribute ("cmse_nonsecure_call", TYPE_ATTRIBUTES (fntype))) |
| 8000 |
return false; |
| 8001 |
} |
| 8002 |
|
| 8003 |
if (!VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl)))) |
| 8004 |
{ |
| 8005 |
/* Check that the return value locations are the same. For |
| 8006 |
example that we aren't returning a value from the sibling in |
| 8007 |
a VFP register but then need to transfer it to a core |
| 8008 |
register. */ |
| 8009 |
rtx a, b; |
| 8010 |
tree decl_or_type = decl; |
| 8011 |
|
| 8012 |
/* If it is an indirect function pointer, get the function type. */ |
| 8013 |
if (!decl) |
| 8014 |
decl_or_type = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp))); |
| 8015 |
|
| 8016 |
a = arm_function_value (TREE_TYPE (exp), decl_or_type, false); |
| 8017 |
b = arm_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)), |
| 8018 |
cfun->decl, false); |
| 8019 |
if (!rtx_equal_p (a, b)) |
| 8020 |
return false; |
| 8021 |
} |
| 8022 |
|
| 8023 |
/* Never tailcall if function may be called with a misaligned SP. */ |
| 8024 |
if (IS_STACKALIGN (func_type)) |
| 8025 |
return false; |
| 8026 |
|
| 8027 |
/* The AAPCS says that, on bare-metal, calls to unresolved weak |
| 8028 |
references should become a NOP. Don't convert such calls into |
| 8029 |
sibling calls. */ |
| 8030 |
if (TARGET_AAPCS_BASED |
| 8031 |
&& arm_abi == ARM_ABI_AAPCS |
| 8032 |
&& decl |
| 8033 |
&& DECL_WEAK (decl)) |
| 8034 |
return false; |
| 8035 |
|
| 8036 |
/* Indirect tailcalls need a call-clobbered register to hold the function |
| 8037 |
address. But we only have r0-r3 and ip in that class. If r0-r3 all hold |
| 8038 |
function arguments, then we can only use IP. But IP may be needed in the |
| 8039 |
epilogue (for PAC validation), or for passing the static chain. We have |
| 8040 |
to disable the tail call if nothing is available. */ |
| 8041 |
if (!decl |
| 8042 |
&& ((CALL_EXPR_BY_DESCRIPTOR (exp) && !flag_trampolines) |
| 8043 |
|| arm_current_function_pac_enabled_p())) |
| 8044 |
{ |
| 8045 |
tree fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp))); |
| 8046 |
CUMULATIVE_ARGS cum; |
| 8047 |
cumulative_args_t cum_v; |
| 8048 |
|
| 8049 |
arm_init_cumulative_args (&cum, fntype, NULL_RTX, NULL_TREE); |
| 8050 |
cum_v = pack_cumulative_args (&cum); |
| 8051 |
|
| 8052 |
tree arg; |
| 8053 |
call_expr_arg_iterator iter; |
| 8054 |
unsigned used_regs = 0; |
| 8055 |
|
| 8056 |
/* Layout each actual argument in turn. If it is allocated to |
| 8057 |
core regs, note which regs have been allocated. */ |
| 8058 |
FOR_EACH_CALL_EXPR_ARG (arg, iter, exp) |
| 8059 |
{ |
| 8060 |
tree type = TREE_TYPE (arg); |
| 8061 |
function_arg_info arg_info (type, /*named=*/true); |
| 8062 |
rtx reg = arm_function_arg (cum_v, arg_info); |
| 8063 |
if (reg && REG_P (reg) |
| 8064 |
&& REGNO (reg) <= LAST_ARG_REGNUM) |
| 8065 |
{ |
| 8066 |
/* Avoid any chance of UB here. We don't care if TYPE |
| 8067 |
is very large since it will use up all the argument regs. */ |
| 8068 |
unsigned nregs = MIN (ARM_NUM_REGS2 (GET_MODE (reg), type), |
| 8069 |
LAST_ARG_REGNUM + 1); |
| 8070 |
used_regs |= ((1 << nregs) - 1) << REGNO (reg); |
| 8071 |
} |
| 8072 |
arm_function_arg_advance (cum_v, arg_info); |
| 8073 |
} |
| 8074 |
|
| 8075 |
/* We've used all the argument regs, and we know IP is live during the |
| 8076 |
epilogue for some reason, so we can't tailcall. */ |
| 8077 |
if ((used_regs & ((1 << (LAST_ARG_REGNUM + 1)) - 1)) |
| 8078 |
== ((1 << (LAST_ARG_REGNUM + 1)) - 1)) |
| 8079 |
return false; |
| 8080 |
} |
| 8081 |
|
| 8082 |
/* Everything else is ok. */ |
| 8083 |
return true; |
| 8084 |
} |
| 8085 |
|
| 8086 |
|
| 8087 |
/* Addressing mode support functions. */ |
| 8088 |
|
| 8089 |
/* Return nonzero if X is a legitimate immediate operand when compiling |
| 8090 |
for PIC. We know that X satisfies CONSTANT_P and flag_pic is true. */ |
| 8091 |
int |
| 8092 |
legitimate_pic_operand_p (rtx x) |
| 8093 |
{ |
| 8094 |
if (SYMBOL_REF_P (x) |
| 8095 |
|| (GET_CODE (x) == CONST |
| 8096 |
&& GET_CODE (XEXP (x, 0)) == PLUS |
| 8097 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)) |
| 8098 |
return 0; |
| 8099 |
|
| 8100 |
return 1; |
| 8101 |
} |
| 8102 |
|
| 8103 |
/* Record that the current function needs a PIC register. If PIC_REG is null, |
| 8104 |
a new pseudo is allocated as PIC register, otherwise PIC_REG is used. In |
| 8105 |
both cases cfun->machine->pic_reg is initialized if we have not already done |
| 8106 |
so. COMPUTE_NOW decides whether and where to set the PIC register. If true, |
| 8107 |
PIC register is reloaded in the current position of the instruction stream |
| 8108 |
irregardless of whether it was loaded before. Otherwise, it is only loaded |
| 8109 |
if not already done so (crtl->uses_pic_offset_table is null). Note that |
| 8110 |
nonnull PIC_REG is only supported iff COMPUTE_NOW is true and null PIC_REG |
| 8111 |
is only supported iff COMPUTE_NOW is false. */ |
| 8112 |
|
| 8113 |
static void |
| 8114 |
require_pic_register (rtx pic_reg, bool compute_now) |
| 8115 |
{ |
| 8116 |
gcc_assert (compute_now == (pic_reg != NULL_RTX)); |
| 8117 |
|
| 8118 |
/* A lot of the logic here is made obscure by the fact that this |
| 8119 |
routine gets called as part of the rtx cost estimation process. |
| 8120 |
We don't want those calls to affect any assumptions about the real |
| 8121 |
function; and further, we can't call entry_of_function() until we |
| 8122 |
start the real expansion process. */ |
| 8123 |
if (!crtl->uses_pic_offset_table || compute_now) |
| 8124 |
{ |
| 8125 |
gcc_assert (can_create_pseudo_p () |
| 8126 |
|| (arm_pic_register != INVALID_REGNUM) |
| 8127 |
|| (pic_reg != NULL_RTX |
| 8128 |
&& REG_P (pic_reg) |
| 8129 |
&& GET_MODE (pic_reg) == Pmode)); |
| 8130 |
if (arm_pic_register != INVALID_REGNUM |
| 8131 |
&& !compute_now |
| 8132 |
&& !(TARGET_THUMB1 && arm_pic_register > LAST_LO_REGNUM)) |
| 8133 |
{ |
| 8134 |
if (!cfun->machine->pic_reg) |
| 8135 |
cfun->machine->pic_reg = gen_rtx_REG (Pmode, arm_pic_register); |
| 8136 |
|
| 8137 |
/* Play games to avoid marking the function as needing pic |
| 8138 |
if we are being called as part of the cost-estimation |
| 8139 |
process. */ |
| 8140 |
if (current_ir_type () != IR_GIMPLE || currently_expanding_to_rtl) |
| 8141 |
crtl->uses_pic_offset_table = 1; |
| 8142 |
} |
| 8143 |
else |
| 8144 |
{ |
| 8145 |
rtx_insn *seq, *insn; |
| 8146 |
|
| 8147 |
if (pic_reg == NULL_RTX) |
| 8148 |
pic_reg = gen_reg_rtx (Pmode); |
| 8149 |
if (!cfun->machine->pic_reg) |
| 8150 |
cfun->machine->pic_reg = pic_reg; |
| 8151 |
|
| 8152 |
/* Play games to avoid marking the function as needing pic |
| 8153 |
if we are being called as part of the cost-estimation |
| 8154 |
process. */ |
| 8155 |
if (current_ir_type () != IR_GIMPLE || currently_expanding_to_rtl) |
| 8156 |
{ |
| 8157 |
crtl->uses_pic_offset_table = 1; |
| 8158 |
start_sequence (); |
| 8159 |
|
| 8160 |
if (TARGET_THUMB1 && arm_pic_register != INVALID_REGNUM |
| 8161 |
&& arm_pic_register > LAST_LO_REGNUM |
| 8162 |
&& !compute_now) |
| 8163 |
emit_move_insn (cfun->machine->pic_reg, |
| 8164 |
gen_rtx_REG (Pmode, arm_pic_register)); |
| 8165 |
else |
| 8166 |
arm_load_pic_register (0UL, pic_reg); |
| 8167 |
|
| 8168 |
seq = get_insns (); |
| 8169 |
end_sequence (); |
| 8170 |
|
| 8171 |
for (insn = seq; insn; insn = NEXT_INSN (insn)) |
| 8172 |
if (INSN_P (insn)) |
| 8173 |
INSN_LOCATION (insn) = prologue_location; |
| 8174 |
|
| 8175 |
/* We can be called during expansion of PHI nodes, where |
| 8176 |
we can't yet emit instructions directly in the final |
| 8177 |
insn stream. Queue the insns on the entry edge, they will |
| 8178 |
be committed after everything else is expanded. */ |
| 8179 |
if (currently_expanding_to_rtl) |
| 8180 |
insert_insn_on_edge (seq, |
| 8181 |
single_succ_edge |
| 8182 |
(ENTRY_BLOCK_PTR_FOR_FN (cfun))); |
| 8183 |
else |
| 8184 |
emit_insn (seq); |
| 8185 |
} |
| 8186 |
} |
| 8187 |
} |
| 8188 |
} |
| 8189 |
|
| 8190 |
/* Generate insns to calculate the address of ORIG in pic mode. */ |
| 8191 |
static rtx_insn * |
| 8192 |
calculate_pic_address_constant (rtx reg, rtx pic_reg, rtx orig) |
| 8193 |
{ |
| 8194 |
rtx pat; |
| 8195 |
rtx mem; |
| 8196 |
|
| 8197 |
pat = gen_calculate_pic_address (reg, pic_reg, orig); |
| 8198 |
|
| 8199 |
/* Make the MEM as close to a constant as possible. */ |
| 8200 |
mem = SET_SRC (pat); |
| 8201 |
gcc_assert (MEM_P (mem) && !MEM_VOLATILE_P (mem)); |
| 8202 |
MEM_READONLY_P (mem) = 1; |
| 8203 |
MEM_NOTRAP_P (mem) = 1; |
| 8204 |
|
| 8205 |
return emit_insn (pat); |
| 8206 |
} |
| 8207 |
|
| 8208 |
/* Legitimize PIC load to ORIG into REG. If REG is NULL, a new pseudo is |
| 8209 |
created to hold the result of the load. If not NULL, PIC_REG indicates |
| 8210 |
which register to use as PIC register, otherwise it is decided by register |
| 8211 |
allocator. COMPUTE_NOW forces the PIC register to be loaded at the current |
| 8212 |
location in the instruction stream, irregardless of whether it was loaded |
| 8213 |
previously. Note that nonnull PIC_REG is only supported iff COMPUTE_NOW is |
| 8214 |
true and null PIC_REG is only supported iff COMPUTE_NOW is false. |
| 8215 |
|
| 8216 |
Returns the register REG into which the PIC load is performed. */ |
| 8217 |
|
| 8218 |
rtx |
| 8219 |
legitimize_pic_address (rtx orig, machine_mode mode, rtx reg, rtx pic_reg, |
| 8220 |
bool compute_now) |
| 8221 |
{ |
| 8222 |
gcc_assert (compute_now == (pic_reg != NULL_RTX)); |
| 8223 |
|
| 8224 |
if (SYMBOL_REF_P (orig) |
| 8225 |
|| LABEL_REF_P (orig)) |
| 8226 |
{ |
| 8227 |
if (reg == 0) |
| 8228 |
{ |
| 8229 |
gcc_assert (can_create_pseudo_p ()); |
| 8230 |
reg = gen_reg_rtx (Pmode); |
| 8231 |
} |
| 8232 |
|
| 8233 |
/* VxWorks does not impose a fixed gap between segments; the run-time |
| 8234 |
gap can be different from the object-file gap. We therefore can't |
| 8235 |
use GOTOFF unless we are absolutely sure that the symbol is in the |
| 8236 |
same segment as the GOT. Unfortunately, the flexibility of linker |
| 8237 |
scripts means that we can't be sure of that in general, so assume |
| 8238 |
that GOTOFF is never valid on VxWorks. */ |
| 8239 |
/* References to weak symbols cannot be resolved locally: they |
| 8240 |
may be overridden by a non-weak definition at link time. */ |
| 8241 |
rtx_insn *insn; |
| 8242 |
if ((LABEL_REF_P (orig) |
| 8243 |
|| (SYMBOL_REF_P (orig) |
| 8244 |
&& SYMBOL_REF_LOCAL_P (orig) |
| 8245 |
&& (SYMBOL_REF_DECL (orig) |
| 8246 |
? !DECL_WEAK (SYMBOL_REF_DECL (orig)) : 1) |
| 8247 |
&& (!SYMBOL_REF_FUNCTION_P (orig) |
| 8248 |
|| arm_fdpic_local_funcdesc_p (orig)))) |
| 8249 |
&& NEED_GOT_RELOC |
| 8250 |
&& arm_pic_data_is_text_relative) |
| 8251 |
insn = arm_pic_static_addr (orig, reg); |
| 8252 |
else |
| 8253 |
{ |
| 8254 |
/* If this function doesn't have a pic register, create one now. */ |
| 8255 |
require_pic_register (pic_reg, compute_now); |
| 8256 |
|
| 8257 |
if (pic_reg == NULL_RTX) |
| 8258 |
pic_reg = cfun->machine->pic_reg; |
| 8259 |
|
| 8260 |
insn = calculate_pic_address_constant (reg, pic_reg, orig); |
| 8261 |
} |
| 8262 |
|
| 8263 |
/* Put a REG_EQUAL note on this insn, so that it can be optimized |
| 8264 |
by loop. */ |
| 8265 |
set_unique_reg_note (insn, REG_EQUAL, orig); |
| 8266 |
|
| 8267 |
return reg; |
| 8268 |
} |
| 8269 |
else if (GET_CODE (orig) == CONST) |
| 8270 |
{ |
| 8271 |
rtx base, offset; |
| 8272 |
|
| 8273 |
if (GET_CODE (XEXP (orig, 0)) == PLUS |
| 8274 |
&& XEXP (XEXP (orig, 0), 0) == cfun->machine->pic_reg) |
| 8275 |
return orig; |
| 8276 |
|
| 8277 |
/* Handle the case where we have: const (UNSPEC_TLS). */ |
| 8278 |
if (GET_CODE (XEXP (orig, 0)) == UNSPEC |
| 8279 |
&& XINT (XEXP (orig, 0), 1) == UNSPEC_TLS) |
| 8280 |
return orig; |
| 8281 |
|
| 8282 |
/* Handle the case where we have: |
| 8283 |
const (plus (UNSPEC_TLS) (ADDEND)). The ADDEND must be a |
| 8284 |
CONST_INT. */ |
| 8285 |
if (GET_CODE (XEXP (orig, 0)) == PLUS |
| 8286 |
&& GET_CODE (XEXP (XEXP (orig, 0), 0)) == UNSPEC |
| 8287 |
&& XINT (XEXP (XEXP (orig, 0), 0), 1) == UNSPEC_TLS) |
| 8288 |
{ |
| 8289 |
gcc_assert (CONST_INT_P (XEXP (XEXP (orig, 0), 1))); |
| 8290 |
return orig; |
| 8291 |
} |
| 8292 |
|
| 8293 |
if (reg == 0) |
| 8294 |
{ |
| 8295 |
gcc_assert (can_create_pseudo_p ()); |
| 8296 |
reg = gen_reg_rtx (Pmode); |
| 8297 |
} |
| 8298 |
|
| 8299 |
gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS); |
| 8300 |
|
| 8301 |
base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg, |
| 8302 |
pic_reg, compute_now); |
| 8303 |
offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode, |
| 8304 |
base == reg ? 0 : reg, pic_reg, |
| 8305 |
compute_now); |
| 8306 |
|
| 8307 |
if (CONST_INT_P (offset)) |
| 8308 |
{ |
| 8309 |
/* The base register doesn't really matter, we only want to |
| 8310 |
test the index for the appropriate mode. */ |
| 8311 |
if (!arm_legitimate_index_p (mode, offset, SET, 0)) |
| 8312 |
{ |
| 8313 |
gcc_assert (can_create_pseudo_p ()); |
| 8314 |
offset = force_reg (Pmode, offset); |
| 8315 |
} |
| 8316 |
|
| 8317 |
if (CONST_INT_P (offset)) |
| 8318 |
return plus_constant (Pmode, base, INTVAL (offset)); |
| 8319 |
} |
| 8320 |
|
| 8321 |
if (GET_MODE_SIZE (mode) > 4 |
| 8322 |
&& (GET_MODE_CLASS (mode) == MODE_INT |
| 8323 |
|| TARGET_SOFT_FLOAT)) |
| 8324 |
{ |
| 8325 |
emit_insn (gen_addsi3 (reg, base, offset)); |
| 8326 |
return reg; |
| 8327 |
} |
| 8328 |
|
| 8329 |
return gen_rtx_PLUS (Pmode, base, offset); |
| 8330 |
} |
| 8331 |
|
| 8332 |
return orig; |
| 8333 |
} |
| 8334 |
|
| 8335 |
|
| 8336 |
/* Generate insns that produce the address of the stack canary */ |
| 8337 |
rtx |
| 8338 |
arm_stack_protect_tls_canary_mem (bool reload) |
| 8339 |
{ |
| 8340 |
rtx tp = gen_reg_rtx (SImode); |
| 8341 |
if (reload) |
| 8342 |
emit_insn (gen_reload_tp_hard (tp)); |
| 8343 |
else |
| 8344 |
emit_insn (gen_load_tp_hard (tp)); |
| 8345 |
|
| 8346 |
rtx reg = gen_reg_rtx (SImode); |
| 8347 |
rtx offset = GEN_INT (arm_stack_protector_guard_offset); |
| 8348 |
emit_set_insn (reg, gen_rtx_PLUS (SImode, tp, offset)); |
| 8349 |
return gen_rtx_MEM (SImode, reg); |
| 8350 |
} |
| 8351 |
|
| 8352 |
|
| 8353 |
/* Whether a register is callee saved or not. This is necessary because high |
| 8354 |
registers are marked as caller saved when optimizing for size on Thumb-1 |
| 8355 |
targets despite being callee saved in order to avoid using them. */ |
| 8356 |
#define callee_saved_reg_p(reg) \ |
| 8357 |
(!call_used_or_fixed_reg_p (reg) \ |
| 8358 |
|| (TARGET_THUMB1 && optimize_size \ |
| 8359 |
&& reg >= FIRST_HI_REGNUM && reg <= LAST_HI_REGNUM)) |
| 8360 |
|
| 8361 |
/* Return a mask for the call-clobbered low registers that are unused |
| 8362 |
at the end of the prologue. */ |
| 8363 |
static unsigned long |
| 8364 |
thumb1_prologue_unused_call_clobbered_lo_regs (void) |
| 8365 |
{ |
| 8366 |
unsigned long mask = 0; |
| 8367 |
bitmap prologue_live_out = df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)); |
| 8368 |
|
| 8369 |
for (int reg = FIRST_LO_REGNUM; reg <= LAST_LO_REGNUM; reg++) |
| 8370 |
if (!callee_saved_reg_p (reg) && !REGNO_REG_SET_P (prologue_live_out, reg)) |
| 8371 |
mask |= 1 << (reg - FIRST_LO_REGNUM); |
| 8372 |
return mask; |
| 8373 |
} |
| 8374 |
|
| 8375 |
/* Similarly for the start of the epilogue. */ |
| 8376 |
static unsigned long |
| 8377 |
thumb1_epilogue_unused_call_clobbered_lo_regs (void) |
| 8378 |
{ |
| 8379 |
unsigned long mask = 0; |
| 8380 |
bitmap epilogue_live_in = df_get_live_in (EXIT_BLOCK_PTR_FOR_FN (cfun)); |
| 8381 |
|
| 8382 |
for (int reg = FIRST_LO_REGNUM; reg <= LAST_LO_REGNUM; reg++) |
| 8383 |
if (!callee_saved_reg_p (reg) && !REGNO_REG_SET_P (epilogue_live_in, reg)) |
| 8384 |
mask |= 1 << (reg - FIRST_LO_REGNUM); |
| 8385 |
return mask; |
| 8386 |
} |
| 8387 |
|
| 8388 |
/* Find a spare register to use during the prolog of a function. */ |
| 8389 |
|
| 8390 |
static int |
| 8391 |
thumb_find_work_register (unsigned long pushed_regs_mask) |
| 8392 |
{ |
| 8393 |
int reg; |
| 8394 |
|
| 8395 |
unsigned long unused_regs |
| 8396 |
= thumb1_prologue_unused_call_clobbered_lo_regs (); |
| 8397 |
|
| 8398 |
/* Check the argument registers first as these are call-used. The |
| 8399 |
register allocation order means that sometimes r3 might be used |
| 8400 |
but earlier argument registers might not, so check them all. */ |
| 8401 |
for (reg = LAST_LO_REGNUM; reg >= FIRST_LO_REGNUM; reg--) |
| 8402 |
if (unused_regs & (1 << (reg - FIRST_LO_REGNUM))) |
| 8403 |
return reg; |
| 8404 |
|
| 8405 |
/* Otherwise look for a call-saved register that is going to be pushed. */ |
| 8406 |
for (reg = LAST_LO_REGNUM; reg > LAST_ARG_REGNUM; reg --) |
| 8407 |
if (pushed_regs_mask & (1 << reg)) |
| 8408 |
return reg; |
| 8409 |
|
| 8410 |
if (TARGET_THUMB2) |
| 8411 |
{ |
| 8412 |
/* Thumb-2 can use high regs. */ |
| 8413 |
for (reg = FIRST_HI_REGNUM; reg < 15; reg ++) |
| 8414 |
if (pushed_regs_mask & (1 << reg)) |
| 8415 |
return reg; |
| 8416 |
} |
| 8417 |
/* Something went wrong - thumb_compute_save_reg_mask() |
| 8418 |
should have arranged for a suitable register to be pushed. */ |
| 8419 |
gcc_unreachable (); |
| 8420 |
} |
| 8421 |
|
| 8422 |
static GTY(()) int pic_labelno; |
| 8423 |
|
| 8424 |
/* Generate code to load the PIC register. In thumb mode SCRATCH is a |
| 8425 |
low register. */ |
| 8426 |
|
| 8427 |
void |
| 8428 |
arm_load_pic_register (unsigned long saved_regs ATTRIBUTE_UNUSED, rtx pic_reg) |
| 8429 |
{ |
| 8430 |
rtx l1, labelno, pic_tmp, pic_rtx; |
| 8431 |
|
| 8432 |
if (crtl->uses_pic_offset_table == 0 |
| 8433 |
|| TARGET_SINGLE_PIC_BASE |
| 8434 |
|| TARGET_FDPIC) |
| 8435 |
return; |
| 8436 |
|
| 8437 |
gcc_assert (flag_pic); |
| 8438 |
|
| 8439 |
if (pic_reg == NULL_RTX) |
| 8440 |
pic_reg = cfun->machine->pic_reg; |
| 8441 |
if (TARGET_VXWORKS_RTP) |
| 8442 |
{ |
| 8443 |
pic_rtx = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE); |
| 8444 |
pic_rtx = gen_rtx_CONST (Pmode, pic_rtx); |
| 8445 |
emit_insn (gen_pic_load_addr_32bit (pic_reg, pic_rtx)); |
| 8446 |
|
| 8447 |
emit_insn (gen_rtx_SET (pic_reg, gen_rtx_MEM (Pmode, pic_reg))); |
| 8448 |
|
| 8449 |
pic_tmp = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX); |
| 8450 |
emit_insn (gen_pic_offset_arm (pic_reg, pic_reg, pic_tmp)); |
| 8451 |
} |
| 8452 |
else |
| 8453 |
{ |
| 8454 |
/* We use an UNSPEC rather than a LABEL_REF because this label |
| 8455 |
never appears in the code stream. */ |
| 8456 |
|
| 8457 |
labelno = GEN_INT (pic_labelno++); |
| 8458 |
l1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); |
| 8459 |
l1 = gen_rtx_CONST (VOIDmode, l1); |
| 8460 |
|
| 8461 |
/* On the ARM the PC register contains 'dot + 8' at the time of the |
| 8462 |
addition, on the Thumb it is 'dot + 4'. */ |
| 8463 |
pic_rtx = plus_constant (Pmode, l1, TARGET_ARM ? 8 : 4); |
| 8464 |
pic_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, pic_rtx), |
| 8465 |
UNSPEC_GOTSYM_OFF); |
| 8466 |
pic_rtx = gen_rtx_CONST (Pmode, pic_rtx); |
| 8467 |
|
| 8468 |
if (TARGET_32BIT) |
| 8469 |
{ |
| 8470 |
emit_insn (gen_pic_load_addr_unified (pic_reg, pic_rtx, labelno)); |
| 8471 |
} |
| 8472 |
else /* TARGET_THUMB1 */ |
| 8473 |
{ |
| 8474 |
if (arm_pic_register != INVALID_REGNUM |
| 8475 |
&& REGNO (pic_reg) > LAST_LO_REGNUM) |
| 8476 |
{ |
| 8477 |
/* We will have pushed the pic register, so we should always be |
| 8478 |
able to find a work register. */ |
| 8479 |
pic_tmp = gen_rtx_REG (SImode, |
| 8480 |
thumb_find_work_register (saved_regs)); |
| 8481 |
emit_insn (gen_pic_load_addr_thumb1 (pic_tmp, pic_rtx)); |
| 8482 |
emit_insn (gen_movsi (pic_offset_table_rtx, pic_tmp)); |
| 8483 |
emit_insn (gen_pic_add_dot_plus_four (pic_reg, pic_reg, labelno)); |
| 8484 |
} |
| 8485 |
else if (arm_pic_register != INVALID_REGNUM |
| 8486 |
&& arm_pic_register > LAST_LO_REGNUM |
| 8487 |
&& REGNO (pic_reg) <= LAST_LO_REGNUM) |
| 8488 |
{ |
| 8489 |
emit_insn (gen_pic_load_addr_unified (pic_reg, pic_rtx, labelno)); |
| 8490 |
emit_move_insn (gen_rtx_REG (Pmode, arm_pic_register), pic_reg); |
| 8491 |
emit_use (gen_rtx_REG (Pmode, arm_pic_register)); |
| 8492 |
} |
| 8493 |
else |
| 8494 |
emit_insn (gen_pic_load_addr_unified (pic_reg, pic_rtx, labelno)); |
| 8495 |
} |
| 8496 |
} |
| 8497 |
|
| 8498 |
/* Need to emit this whether or not we obey regdecls, |
| 8499 |
since setjmp/longjmp can cause life info to screw up. */ |
| 8500 |
emit_use (pic_reg); |
| 8501 |
} |
| 8502 |
|
| 8503 |
/* Try to determine whether an object, referenced via ORIG, will be |
| 8504 |
placed in the text or data segment. This is used in FDPIC mode, to |
| 8505 |
decide which relocations to use when accessing ORIG. *IS_READONLY |
| 8506 |
is set to true if ORIG is a read-only location, false otherwise. |
| 8507 |
Return true if we could determine the location of ORIG, false |
| 8508 |
otherwise. *IS_READONLY is valid only when we return true. */ |
| 8509 |
static bool |
| 8510 |
arm_is_segment_info_known (rtx orig, bool *is_readonly) |
| 8511 |
{ |
| 8512 |
*is_readonly = false; |
| 8513 |
|
| 8514 |
if (LABEL_REF_P (orig)) |
| 8515 |
{ |
| 8516 |
*is_readonly = true; |
| 8517 |
return true; |
| 8518 |
} |
| 8519 |
|
| 8520 |
if (SYMBOL_REF_P (orig)) |
| 8521 |
{ |
| 8522 |
if (CONSTANT_POOL_ADDRESS_P (orig)) |
| 8523 |
{ |
| 8524 |
*is_readonly = true; |
| 8525 |
return true; |
| 8526 |
} |
| 8527 |
if (SYMBOL_REF_LOCAL_P (orig) |
| 8528 |
&& !SYMBOL_REF_EXTERNAL_P (orig) |
| 8529 |
&& SYMBOL_REF_DECL (orig) |
| 8530 |
&& (!DECL_P (SYMBOL_REF_DECL (orig)) |
| 8531 |
|| !DECL_COMMON (SYMBOL_REF_DECL (orig)))) |
| 8532 |
{ |
| 8533 |
tree decl = SYMBOL_REF_DECL (orig); |
| 8534 |
tree init = VAR_P (decl) |
| 8535 |
? DECL_INITIAL (decl) : (TREE_CODE (decl) == CONSTRUCTOR) |
| 8536 |
? decl : 0; |
| 8537 |
int reloc = 0; |
| 8538 |
bool named_section, readonly; |
| 8539 |
|
| 8540 |
if (init && init != error_mark_node) |
| 8541 |
reloc = compute_reloc_for_constant (init); |
| 8542 |
|
| 8543 |
named_section = VAR_P (decl) |
| 8544 |
&& lookup_attribute ("section", DECL_ATTRIBUTES (decl)); |
| 8545 |
readonly = decl_readonly_section (decl, reloc); |
| 8546 |
|
| 8547 |
/* We don't know where the link script will put a named |
| 8548 |
section, so return false in such a case. */ |
| 8549 |
if (named_section) |
| 8550 |
return false; |
| 8551 |
|
| 8552 |
*is_readonly = readonly; |
| 8553 |
return true; |
| 8554 |
} |
| 8555 |
|
| 8556 |
/* We don't know. */ |
| 8557 |
return false; |
| 8558 |
} |
| 8559 |
|
| 8560 |
gcc_unreachable (); |
| 8561 |
} |
| 8562 |
|
| 8563 |
/* Generate code to load the address of a static var when flag_pic is set. */ |
| 8564 |
static rtx_insn * |
| 8565 |
arm_pic_static_addr (rtx orig, rtx reg) |
| 8566 |
{ |
| 8567 |
rtx l1, labelno, offset_rtx; |
| 8568 |
rtx_insn *insn; |
| 8569 |
|
| 8570 |
gcc_assert (flag_pic); |
| 8571 |
|
| 8572 |
bool is_readonly = false; |
| 8573 |
bool info_known = false; |
| 8574 |
|
| 8575 |
if (TARGET_FDPIC |
| 8576 |
&& SYMBOL_REF_P (orig) |
| 8577 |
&& !SYMBOL_REF_FUNCTION_P (orig)) |
| 8578 |
info_known = arm_is_segment_info_known (orig, &is_readonly); |
| 8579 |
|
| 8580 |
if (TARGET_FDPIC |
| 8581 |
&& SYMBOL_REF_P (orig) |
| 8582 |
&& !SYMBOL_REF_FUNCTION_P (orig) |
| 8583 |
&& !info_known) |
| 8584 |
{ |
| 8585 |
/* We don't know where orig is stored, so we have be |
| 8586 |
pessimistic and use a GOT relocation. */ |
| 8587 |
rtx pic_reg = gen_rtx_REG (Pmode, FDPIC_REGNUM); |
| 8588 |
|
| 8589 |
insn = calculate_pic_address_constant (reg, pic_reg, orig); |
| 8590 |
} |
| 8591 |
else if (TARGET_FDPIC |
| 8592 |
&& SYMBOL_REF_P (orig) |
| 8593 |
&& (SYMBOL_REF_FUNCTION_P (orig) |
| 8594 |
|| !is_readonly)) |
| 8595 |
{ |
| 8596 |
/* We use the GOTOFF relocation. */ |
| 8597 |
rtx pic_reg = gen_rtx_REG (Pmode, FDPIC_REGNUM); |
| 8598 |
|
| 8599 |
rtx l1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, orig), UNSPEC_PIC_SYM); |
| 8600 |
emit_insn (gen_movsi (reg, l1)); |
| 8601 |
insn = emit_insn (gen_addsi3 (reg, reg, pic_reg)); |
| 8602 |
} |
| 8603 |
else |
| 8604 |
{ |
| 8605 |
/* Not FDPIC, not SYMBOL_REF_P or readonly: we can use |
| 8606 |
PC-relative access. */ |
| 8607 |
/* We use an UNSPEC rather than a LABEL_REF because this label |
| 8608 |
never appears in the code stream. */ |
| 8609 |
labelno = GEN_INT (pic_labelno++); |
| 8610 |
l1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); |
| 8611 |
l1 = gen_rtx_CONST (VOIDmode, l1); |
| 8612 |
|
| 8613 |
/* On the ARM the PC register contains 'dot + 8' at the time of the |
| 8614 |
addition, on the Thumb it is 'dot + 4'. */ |
| 8615 |
offset_rtx = plus_constant (Pmode, l1, TARGET_ARM ? 8 : 4); |
| 8616 |
offset_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, orig, offset_rtx), |
| 8617 |
UNSPEC_SYMBOL_OFFSET); |
| 8618 |
offset_rtx = gen_rtx_CONST (Pmode, offset_rtx); |
| 8619 |
|
| 8620 |
insn = emit_insn (gen_pic_load_addr_unified (reg, offset_rtx, |
| 8621 |
labelno)); |
| 8622 |
} |
| 8623 |
|
| 8624 |
return insn; |
| 8625 |
} |
| 8626 |
|
| 8627 |
/* Return nonzero if X is valid as an ARM state addressing register. */ |
| 8628 |
static int |
| 8629 |
arm_address_register_rtx_p (rtx x, int strict_p) |
| 8630 |
{ |
| 8631 |
int regno; |
| 8632 |
|
| 8633 |
if (!REG_P (x)) |
| 8634 |
return 0; |
| 8635 |
|
| 8636 |
regno = REGNO (x); |
| 8637 |
|
| 8638 |
if (strict_p) |
| 8639 |
return ARM_REGNO_OK_FOR_BASE_P (regno); |
| 8640 |
|
| 8641 |
return (regno <= LAST_ARM_REGNUM |
| 8642 |
|| regno >= FIRST_PSEUDO_REGISTER |
| 8643 |
|| regno == FRAME_POINTER_REGNUM |
| 8644 |
|| regno == ARG_POINTER_REGNUM); |
| 8645 |
} |
| 8646 |
|
| 8647 |
/* Return TRUE if this rtx is the difference of a symbol and a label, |
| 8648 |
and will reduce to a PC-relative relocation in the object file. |
| 8649 |
Expressions like this can be left alone when generating PIC, rather |
| 8650 |
than forced through the GOT. */ |
| 8651 |
static int |
| 8652 |
pcrel_constant_p (rtx x) |
| 8653 |
{ |
| 8654 |
if (GET_CODE (x) == MINUS) |
| 8655 |
return symbol_mentioned_p (XEXP (x, 0)) && label_mentioned_p (XEXP (x, 1)); |
| 8656 |
|
| 8657 |
return FALSE; |
| 8658 |
} |
| 8659 |
|
| 8660 |
/* Return true if X will surely end up in an index register after next |
| 8661 |
splitting pass. */ |
| 8662 |
static bool |
| 8663 |
will_be_in_index_register (const_rtx x) |
| 8664 |
{ |
| 8665 |
/* arm.md: calculate_pic_address will split this into a register. */ |
| 8666 |
return GET_CODE (x) == UNSPEC && (XINT (x, 1) == UNSPEC_PIC_SYM); |
| 8667 |
} |
| 8668 |
|
| 8669 |
/* Return nonzero if X is a valid ARM state address operand. */ |
| 8670 |
int |
| 8671 |
arm_legitimate_address_outer_p (machine_mode mode, rtx x, RTX_CODE outer, |
| 8672 |
int strict_p) |
| 8673 |
{ |
| 8674 |
bool use_ldrd; |
| 8675 |
enum rtx_code code = GET_CODE (x); |
| 8676 |
|
| 8677 |
if (arm_address_register_rtx_p (x, strict_p)) |
| 8678 |
return 1; |
| 8679 |
|
| 8680 |
use_ldrd = (TARGET_LDRD |
| 8681 |
&& (mode == DImode || mode == DFmode)); |
| 8682 |
|
| 8683 |
if (code == POST_INC || code == PRE_DEC |
| 8684 |
|| ((code == PRE_INC || code == POST_DEC) |
| 8685 |
&& (use_ldrd || GET_MODE_SIZE (mode) <= 4))) |
| 8686 |
return arm_address_register_rtx_p (XEXP (x, 0), strict_p); |
| 8687 |
|
| 8688 |
else if ((code == POST_MODIFY || code == PRE_MODIFY) |
| 8689 |
&& arm_address_register_rtx_p (XEXP (x, 0), strict_p) |
| 8690 |
&& GET_CODE (XEXP (x, 1)) == PLUS |
| 8691 |
&& rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0))) |
| 8692 |
{ |
| 8693 |
rtx addend = XEXP (XEXP (x, 1), 1); |
| 8694 |
|
| 8695 |
/* Don't allow ldrd post increment by register because it's hard |
| 8696 |
to fixup invalid register choices. */ |
| 8697 |
if (use_ldrd |
| 8698 |
&& GET_CODE (x) == POST_MODIFY |
| 8699 |
&& REG_P (addend)) |
| 8700 |
return 0; |
| 8701 |
|
| 8702 |
return ((use_ldrd || GET_MODE_SIZE (mode) <= 4) |
| 8703 |
&& arm_legitimate_index_p (mode, addend, outer, strict_p)); |
| 8704 |
} |
| 8705 |
|
| 8706 |
/* After reload constants split into minipools will have addresses |
| 8707 |
from a LABEL_REF. */ |
| 8708 |
else if (reload_completed |
| 8709 |
&& (code == LABEL_REF |
| 8710 |
|| (code == CONST |
| 8711 |
&& GET_CODE (XEXP (x, 0)) == PLUS |
| 8712 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF |
| 8713 |
&& CONST_INT_P (XEXP (XEXP (x, 0), 1))))) |
| 8714 |
return 1; |
| 8715 |
|
| 8716 |
else if (mode == TImode || (TARGET_NEON && VALID_NEON_STRUCT_MODE (mode))) |
| 8717 |
return 0; |
| 8718 |
|
| 8719 |
else if (code == PLUS) |
| 8720 |
{ |
| 8721 |
rtx xop0 = XEXP (x, 0); |
| 8722 |
rtx xop1 = XEXP (x, 1); |
| 8723 |
|
| 8724 |
return ((arm_address_register_rtx_p (xop0, strict_p) |
| 8725 |
&& ((CONST_INT_P (xop1) |
| 8726 |
&& arm_legitimate_index_p (mode, xop1, outer, strict_p)) |
| 8727 |
|| (!strict_p && will_be_in_index_register (xop1)))) |
| 8728 |
|| (arm_address_register_rtx_p (xop1, strict_p) |
| 8729 |
&& arm_legitimate_index_p (mode, xop0, outer, strict_p))); |
| 8730 |
} |
| 8731 |
|
| 8732 |
#if 0 |
| 8733 |
/* Reload currently can't handle MINUS, so disable this for now */ |
| 8734 |
else if (GET_CODE (x) == MINUS) |
| 8735 |
{ |
| 8736 |
rtx xop0 = XEXP (x, 0); |
| 8737 |
rtx xop1 = XEXP (x, 1); |
| 8738 |
|
| 8739 |
return (arm_address_register_rtx_p (xop0, strict_p) |
| 8740 |
&& arm_legitimate_index_p (mode, xop1, outer, strict_p)); |
| 8741 |
} |
| 8742 |
#endif |
| 8743 |
|
| 8744 |
else if (GET_MODE_CLASS (mode) != MODE_FLOAT |
| 8745 |
&& code == SYMBOL_REF |
| 8746 |
&& CONSTANT_POOL_ADDRESS_P (x) |
| 8747 |
&& ! (flag_pic |
| 8748 |
&& symbol_mentioned_p (get_pool_constant (x)) |
| 8749 |
&& ! pcrel_constant_p (get_pool_constant (x)))) |
| 8750 |
return 1; |
| 8751 |
|
| 8752 |
return 0; |
| 8753 |
} |
| 8754 |
|
| 8755 |
/* Return true if we can avoid creating a constant pool entry for x. */ |
| 8756 |
static bool |
| 8757 |
can_avoid_literal_pool_for_label_p (rtx x) |
| 8758 |
{ |
| 8759 |
/* Normally we can assign constant values to target registers without |
| 8760 |
the help of constant pool. But there are cases we have to use constant |
| 8761 |
pool like: |
| 8762 |
1) assign a label to register. |
| 8763 |
2) sign-extend a 8bit value to 32bit and then assign to register. |
| 8764 |
|
| 8765 |
Constant pool access in format: |
| 8766 |
(set (reg r0) (mem (symbol_ref (".LC0")))) |
| 8767 |
will cause the use of literal pool (later in function arm_reorg). |
| 8768 |
So here we mark such format as an invalid format, then the compiler |
| 8769 |
will adjust it into: |
| 8770 |
(set (reg r0) (symbol_ref (".LC0"))) |
| 8771 |
(set (reg r0) (mem (reg r0))). |
| 8772 |
No extra register is required, and (mem (reg r0)) won't cause the use |
| 8773 |
of literal pools. */ |
| 8774 |
if (arm_disable_literal_pool && SYMBOL_REF_P (x) |
| 8775 |
&& CONSTANT_POOL_ADDRESS_P (x)) |
| 8776 |
return 1; |
| 8777 |
return 0; |
| 8778 |
} |
| 8779 |
|
| 8780 |
|
| 8781 |
/* Return nonzero if X is a valid Thumb-2 address operand. */ |
| 8782 |
static int |
| 8783 |
thumb2_legitimate_address_p (machine_mode mode, rtx x, int strict_p) |
| 8784 |
{ |
| 8785 |
bool use_ldrd; |
| 8786 |
enum rtx_code code = GET_CODE (x); |
| 8787 |
|
| 8788 |
/* If we are dealing with a MVE predicate mode, then treat it as a HImode as |
| 8789 |
can store and load it like any other 16-bit value. */ |
| 8790 |
if (TARGET_HAVE_MVE && VALID_MVE_PRED_MODE (mode)) |
| 8791 |
mode = HImode; |
| 8792 |
|
| 8793 |
if (TARGET_HAVE_MVE && VALID_MVE_MODE (mode)) |
| 8794 |
return mve_vector_mem_operand (mode, x, strict_p); |
| 8795 |
|
| 8796 |
if (arm_address_register_rtx_p (x, strict_p)) |
| 8797 |
return 1; |
| 8798 |
|
| 8799 |
use_ldrd = (TARGET_LDRD |
| 8800 |
&& (mode == DImode || mode == DFmode)); |
| 8801 |
|
| 8802 |
if (code == POST_INC || code == PRE_DEC |
| 8803 |
|| ((code == PRE_INC || code == POST_DEC) |
| 8804 |
&& (use_ldrd || GET_MODE_SIZE (mode) <= 4))) |
| 8805 |
return arm_address_register_rtx_p (XEXP (x, 0), strict_p); |
| 8806 |
|
| 8807 |
else if ((code == POST_MODIFY || code == PRE_MODIFY) |
| 8808 |
&& arm_address_register_rtx_p (XEXP (x, 0), strict_p) |
| 8809 |
&& GET_CODE (XEXP (x, 1)) == PLUS |
| 8810 |
&& rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0))) |
| 8811 |
{ |
| 8812 |
/* Thumb-2 only has autoincrement by constant. */ |
| 8813 |
rtx addend = XEXP (XEXP (x, 1), 1); |
| 8814 |
HOST_WIDE_INT offset; |
| 8815 |
|
| 8816 |
if (!CONST_INT_P (addend)) |
| 8817 |
return 0; |
| 8818 |
|
| 8819 |
offset = INTVAL(addend); |
| 8820 |
if (GET_MODE_SIZE (mode) <= 4) |
| 8821 |
return (offset > -256 && offset < 256); |
| 8822 |
|
| 8823 |
return (use_ldrd && offset > -1024 && offset < 1024 |
| 8824 |
&& (offset & 3) == 0); |
| 8825 |
} |
| 8826 |
|
| 8827 |
/* After reload constants split into minipools will have addresses |
| 8828 |
from a LABEL_REF. */ |
| 8829 |
else if (reload_completed |
| 8830 |
&& (code == LABEL_REF |
| 8831 |
|| (code == CONST |
| 8832 |
&& GET_CODE (XEXP (x, 0)) == PLUS |
| 8833 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF |
| 8834 |
&& CONST_INT_P (XEXP (XEXP (x, 0), 1))))) |
| 8835 |
return 1; |
| 8836 |
|
| 8837 |
else if (mode == TImode |
| 8838 |
|| (TARGET_NEON && VALID_NEON_STRUCT_MODE (mode)) |
| 8839 |
|| (TARGET_HAVE_MVE && VALID_MVE_STRUCT_MODE (mode))) |
| 8840 |
return 0; |
| 8841 |
|
| 8842 |
else if (code == PLUS) |
| 8843 |
{ |
| 8844 |
rtx xop0 = XEXP (x, 0); |
| 8845 |
rtx xop1 = XEXP (x, 1); |
| 8846 |
|
| 8847 |
return ((arm_address_register_rtx_p (xop0, strict_p) |
| 8848 |
&& (thumb2_legitimate_index_p (mode, xop1, strict_p) |
| 8849 |
|| (!strict_p && will_be_in_index_register (xop1)))) |
| 8850 |
|| (arm_address_register_rtx_p (xop1, strict_p) |
| 8851 |
&& thumb2_legitimate_index_p (mode, xop0, strict_p))); |
| 8852 |
} |
| 8853 |
|
| 8854 |
else if (can_avoid_literal_pool_for_label_p (x)) |
| 8855 |
return 0; |
| 8856 |
|
| 8857 |
else if (GET_MODE_CLASS (mode) != MODE_FLOAT |
| 8858 |
&& code == SYMBOL_REF |
| 8859 |
&& CONSTANT_POOL_ADDRESS_P (x) |
| 8860 |
&& ! (flag_pic |
| 8861 |
&& symbol_mentioned_p (get_pool_constant (x)) |
| 8862 |
&& ! pcrel_constant_p (get_pool_constant (x)))) |
| 8863 |
return 1; |
| 8864 |
|
| 8865 |
return 0; |
| 8866 |
} |
| 8867 |
|
| 8868 |
/* Return nonzero if INDEX is valid for an address index operand in |
| 8869 |
ARM state. */ |
| 8870 |
static int |
| 8871 |
arm_legitimate_index_p (machine_mode mode, rtx index, RTX_CODE outer, |
| 8872 |
int strict_p) |
| 8873 |
{ |
| 8874 |
HOST_WIDE_INT range; |
| 8875 |
enum rtx_code code = GET_CODE (index); |
| 8876 |
|
| 8877 |
/* Standard coprocessor addressing modes. */ |
| 8878 |
if (TARGET_HARD_FLOAT |
| 8879 |
&& (mode == SFmode || mode == DFmode)) |
| 8880 |
return (code == CONST_INT && INTVAL (index) < 1024 |
| 8881 |
&& INTVAL (index) > -1024 |
| 8882 |
&& (INTVAL (index) & 3) == 0); |
| 8883 |
|
| 8884 |
if (arm_address_register_rtx_p (index, strict_p) |
| 8885 |
&& (GET_MODE_SIZE (mode) <= 4)) |
| 8886 |
return 1; |
| 8887 |
|
| 8888 |
/* This handles DFmode only if !TARGET_HARD_FLOAT. */ |
| 8889 |
if (mode == DImode || mode == DFmode) |
| 8890 |
{ |
| 8891 |
if (code == CONST_INT) |
| 8892 |
{ |
| 8893 |
HOST_WIDE_INT val = INTVAL (index); |
| 8894 |
|
| 8895 |
/* Assume we emit ldrd or 2x ldr if !TARGET_LDRD. |
| 8896 |
If vldr is selected it uses arm_coproc_mem_operand. */ |
| 8897 |
if (TARGET_LDRD) |
| 8898 |
return val > -256 && val < 256; |
| 8899 |
else |
| 8900 |
return val > -4096 && val < 4092; |
| 8901 |
} |
| 8902 |
|
| 8903 |
return TARGET_LDRD && arm_address_register_rtx_p (index, strict_p); |
| 8904 |
} |
| 8905 |
|
| 8906 |
/* For quad modes, we restrict the constant offset to be slightly less |
| 8907 |
than what the instruction format permits. We do this because for |
| 8908 |
quad mode moves, we will actually decompose them into two separate |
| 8909 |
double-mode reads or writes. INDEX must therefore be a valid |
| 8910 |
(double-mode) offset and so should INDEX+8. */ |
| 8911 |
if (TARGET_NEON && VALID_NEON_QREG_MODE (mode)) |
| 8912 |
return (code == CONST_INT |
| 8913 |
&& INTVAL (index) < 1016 |
| 8914 |
&& INTVAL (index) > -1024 |
| 8915 |
&& (INTVAL (index) & 3) == 0); |
| 8916 |
|
| 8917 |
/* We have no such constraint on double mode offsets, so we permit the |
| 8918 |
full range of the instruction format. Note DImode is included here. */ |
| 8919 |
if (TARGET_NEON && VALID_NEON_DREG_MODE (mode)) |
| 8920 |
return (code == CONST_INT |
| 8921 |
&& INTVAL (index) < 1024 |
| 8922 |
&& INTVAL (index) > -1024 |
| 8923 |
&& (INTVAL (index) & 3) == 0); |
| 8924 |
|
| 8925 |
if (TARGET_REALLY_IWMMXT && VALID_IWMMXT_REG_MODE (mode)) |
| 8926 |
return (code == CONST_INT |
| 8927 |
&& INTVAL (index) < 1024 |
| 8928 |
&& INTVAL (index) > -1024 |
| 8929 |
&& (INTVAL (index) & 3) == 0); |
| 8930 |
|
| 8931 |
if (GET_MODE_SIZE (mode) <= 4 |
| 8932 |
&& ! (arm_arch4 |
| 8933 |
&& (mode == HImode |
| 8934 |
|| mode == HFmode |
| 8935 |
|| (mode == QImode && outer == SIGN_EXTEND)))) |
| 8936 |
{ |
| 8937 |
if (code == MULT) |
| 8938 |
{ |
| 8939 |
rtx xiop0 = XEXP (index, 0); |
| 8940 |
rtx xiop1 = XEXP (index, 1); |
| 8941 |
|
| 8942 |
return ((arm_address_register_rtx_p (xiop0, strict_p) |
| 8943 |
&& power_of_two_operand (xiop1, SImode)) |
| 8944 |
|| (arm_address_register_rtx_p (xiop1, strict_p) |
| 8945 |
&& power_of_two_operand (xiop0, SImode))); |
| 8946 |
} |
| 8947 |
else if (code == LSHIFTRT || code == ASHIFTRT |
| 8948 |
|| code == ASHIFT || code == ROTATERT) |
| 8949 |
{ |
| 8950 |
rtx op = XEXP (index, 1); |
| 8951 |
|
| 8952 |
return (arm_address_register_rtx_p (XEXP (index, 0), strict_p) |
| 8953 |
&& CONST_INT_P (op) |
| 8954 |
&& INTVAL (op) > 0 |
| 8955 |
&& INTVAL (op) <= 31); |
| 8956 |
} |
| 8957 |
} |
| 8958 |
|
| 8959 |
/* For ARM v4 we may be doing a sign-extend operation during the |
| 8960 |
load. */ |
| 8961 |
if (arm_arch4) |
| 8962 |
{ |
| 8963 |
if (mode == HImode |
| 8964 |
|| mode == HFmode |
| 8965 |
|| (outer == SIGN_EXTEND && mode == QImode)) |
| 8966 |
range = 256; |
| 8967 |
else |
| 8968 |
range = 4096; |
| 8969 |
} |
| 8970 |
else |
| 8971 |
range = (mode == HImode || mode == HFmode) ? 4095 : 4096; |
| 8972 |
|
| 8973 |
return (code == CONST_INT |
| 8974 |
&& INTVAL (index) < range |
| 8975 |
&& INTVAL (index) > -range); |
| 8976 |
} |
| 8977 |
|
| 8978 |
/* Return true if OP is a valid index scaling factor for Thumb-2 address |
| 8979 |
index operand. i.e. 1, 2, 4 or 8. */ |
| 8980 |
static bool |
| 8981 |
thumb2_index_mul_operand (rtx op) |
| 8982 |
{ |
| 8983 |
HOST_WIDE_INT val; |
| 8984 |
|
| 8985 |
if (!CONST_INT_P (op)) |
| 8986 |
return false; |
| 8987 |
|
| 8988 |
val = INTVAL(op); |
| 8989 |
return (val == 1 || val == 2 || val == 4 || val == 8); |
| 8990 |
} |
| 8991 |
|
| 8992 |
/* Return nonzero if INDEX is a valid Thumb-2 address index operand. */ |
| 8993 |
static int |
| 8994 |
thumb2_legitimate_index_p (machine_mode mode, rtx index, int strict_p) |
| 8995 |
{ |
| 8996 |
enum rtx_code code = GET_CODE (index); |
| 8997 |
|
| 8998 |
/* ??? Combine arm and thumb2 coprocessor addressing modes. */ |
| 8999 |
/* Standard coprocessor addressing modes. */ |
| 9000 |
if (TARGET_VFP_BASE |
| 9001 |
&& (mode == SFmode || mode == DFmode)) |
| 9002 |
return (code == CONST_INT && INTVAL (index) < 1024 |
| 9003 |
/* Thumb-2 allows only > -256 index range for it's core register |
| 9004 |
load/stores. Since we allow SF/DF in core registers, we have |
| 9005 |
to use the intersection between -256~4096 (core) and -1024~1024 |
| 9006 |
(coprocessor). */ |
| 9007 |
&& INTVAL (index) > -256 |
| 9008 |
&& (INTVAL (index) & 3) == 0); |
| 9009 |
|
| 9010 |
if (TARGET_REALLY_IWMMXT && VALID_IWMMXT_REG_MODE (mode)) |
| 9011 |
{ |
| 9012 |
/* For DImode assume values will usually live in core regs |
| 9013 |
and only allow LDRD addressing modes. */ |
| 9014 |
if (!TARGET_LDRD || mode != DImode) |
| 9015 |
return (code == CONST_INT |
| 9016 |
&& INTVAL (index) < 1024 |
| 9017 |
&& INTVAL (index) > -1024 |
| 9018 |
&& (INTVAL (index) & 3) == 0); |
| 9019 |
} |
| 9020 |
|
| 9021 |
/* For quad modes, we restrict the constant offset to be slightly less |
| 9022 |
than what the instruction format permits. We do this because for |
| 9023 |
quad mode moves, we will actually decompose them into two separate |
| 9024 |
double-mode reads or writes. INDEX must therefore be a valid |
| 9025 |
(double-mode) offset and so should INDEX+8. */ |
| 9026 |
if (TARGET_NEON && VALID_NEON_QREG_MODE (mode)) |
| 9027 |
return (code == CONST_INT |
| 9028 |
&& INTVAL (index) < 1016 |
| 9029 |
&& INTVAL (index) > -1024 |
| 9030 |
&& (INTVAL (index) & 3) == 0); |
| 9031 |
|
| 9032 |
/* We have no such constraint on double mode offsets, so we permit the |
| 9033 |
full range of the instruction format. Note DImode is included here. */ |
| 9034 |
if (TARGET_NEON && VALID_NEON_DREG_MODE (mode)) |
| 9035 |
return (code == CONST_INT |
| 9036 |
&& INTVAL (index) < 1024 |
| 9037 |
&& INTVAL (index) > -1024 |
| 9038 |
&& (INTVAL (index) & 3) == 0); |
| 9039 |
|
| 9040 |
if (arm_address_register_rtx_p (index, strict_p) |
| 9041 |
&& (GET_MODE_SIZE (mode) <= 4)) |
| 9042 |
return 1; |
| 9043 |
|
| 9044 |
/* This handles DImode if !TARGET_NEON, and DFmode if !TARGET_VFP_BASE. */ |
| 9045 |
if (mode == DImode || mode == DFmode) |
| 9046 |
{ |
| 9047 |
if (code == CONST_INT) |
| 9048 |
{ |
| 9049 |
HOST_WIDE_INT val = INTVAL (index); |
| 9050 |
/* Thumb-2 ldrd only has reg+const addressing modes. |
| 9051 |
Assume we emit ldrd or 2x ldr if !TARGET_LDRD. |
| 9052 |
If vldr is selected it uses arm_coproc_mem_operand. */ |
| 9053 |
if (TARGET_LDRD) |
| 9054 |
return IN_RANGE (val, -1020, 1020) && (val & 3) == 0; |
| 9055 |
else |
| 9056 |
return IN_RANGE (val, -255, 4095 - 4); |
| 9057 |
} |
| 9058 |
else |
| 9059 |
return 0; |
| 9060 |
} |
| 9061 |
|
| 9062 |
if (code == MULT) |
| 9063 |
{ |
| 9064 |
rtx xiop0 = XEXP (index, 0); |
| 9065 |
rtx xiop1 = XEXP (index, 1); |
| 9066 |
|
| 9067 |
return ((arm_address_register_rtx_p (xiop0, strict_p) |
| 9068 |
&& thumb2_index_mul_operand (xiop1)) |
| 9069 |
|| (arm_address_register_rtx_p (xiop1, strict_p) |
| 9070 |
&& thumb2_index_mul_operand (xiop0))); |
| 9071 |
} |
| 9072 |
else if (code == ASHIFT) |
| 9073 |
{ |
| 9074 |
rtx op = XEXP (index, 1); |
| 9075 |
|
| 9076 |
return (arm_address_register_rtx_p (XEXP (index, 0), strict_p) |
| 9077 |
&& CONST_INT_P (op) |
| 9078 |
&& INTVAL (op) > 0 |
| 9079 |
&& INTVAL (op) <= 3); |
| 9080 |
} |
| 9081 |
|
| 9082 |
return (code == CONST_INT |
| 9083 |
&& INTVAL (index) < 4096 |
| 9084 |
&& INTVAL (index) > -256); |
| 9085 |
} |
| 9086 |
|
| 9087 |
/* Return nonzero if X is valid as a 16-bit Thumb state base register. */ |
| 9088 |
static int |
| 9089 |
thumb1_base_register_rtx_p (rtx x, machine_mode mode, int strict_p) |
| 9090 |
{ |
| 9091 |
int regno; |
| 9092 |
|
| 9093 |
if (!REG_P (x)) |
| 9094 |
return 0; |
| 9095 |
|
| 9096 |
regno = REGNO (x); |
| 9097 |
|
| 9098 |
if (strict_p) |
| 9099 |
return THUMB1_REGNO_MODE_OK_FOR_BASE_P (regno, mode); |
| 9100 |
|
| 9101 |
return (regno <= LAST_LO_REGNUM |
| 9102 |
|| regno > LAST_VIRTUAL_REGISTER |
| 9103 |
|| regno == FRAME_POINTER_REGNUM |
| 9104 |
|| (GET_MODE_SIZE (mode) >= 4 |
| 9105 |
&& (regno == STACK_POINTER_REGNUM |
| 9106 |
|| regno >= FIRST_PSEUDO_REGISTER |
| 9107 |
|| x == hard_frame_pointer_rtx |
| 9108 |
|| x == arg_pointer_rtx))); |
| 9109 |
} |
| 9110 |
|
| 9111 |
/* Return nonzero if x is a legitimate index register. This is the case |
| 9112 |
for any base register that can access a QImode object. */ |
| 9113 |
inline static int |
| 9114 |
thumb1_index_register_rtx_p (rtx x, int strict_p) |
| 9115 |
{ |
| 9116 |
return thumb1_base_register_rtx_p (x, QImode, strict_p); |
| 9117 |
} |
| 9118 |
|
| 9119 |
/* Return nonzero if x is a legitimate 16-bit Thumb-state address. |
| 9120 |
|
| 9121 |
The AP may be eliminated to either the SP or the FP, so we use the |
| 9122 |
least common denominator, e.g. SImode, and offsets from 0 to 64. |
| 9123 |
|
| 9124 |
??? Verify whether the above is the right approach. |
| 9125 |
|
| 9126 |
??? Also, the FP may be eliminated to the SP, so perhaps that |
| 9127 |
needs special handling also. |
| 9128 |
|
| 9129 |
??? Look at how the mips16 port solves this problem. It probably uses |
| 9130 |
better ways to solve some of these problems. |
| 9131 |
|
| 9132 |
Although it is not incorrect, we don't accept QImode and HImode |
| 9133 |
addresses based on the frame pointer or arg pointer until the |
| 9134 |
reload pass starts. This is so that eliminating such addresses |
| 9135 |
into stack based ones won't produce impossible code. */ |
| 9136 |
int |
| 9137 |
thumb1_legitimate_address_p (machine_mode mode, rtx x, int strict_p) |
| 9138 |
{ |
| 9139 |
if (TARGET_HAVE_MOVT && can_avoid_literal_pool_for_label_p (x)) |
| 9140 |
return 0; |
| 9141 |
|
| 9142 |
/* ??? Not clear if this is right. Experiment. */ |
| 9143 |
if (GET_MODE_SIZE (mode) < 4 |
| 9144 |
&& !(reload_in_progress || reload_completed) |
| 9145 |
&& (reg_mentioned_p (frame_pointer_rtx, x) |
| 9146 |
|| reg_mentioned_p (arg_pointer_rtx, x) |
| 9147 |
|| reg_mentioned_p (virtual_incoming_args_rtx, x) |
| 9148 |
|| reg_mentioned_p (virtual_outgoing_args_rtx, x) |
| 9149 |
|| reg_mentioned_p (virtual_stack_dynamic_rtx, x) |
| 9150 |
|| reg_mentioned_p (virtual_stack_vars_rtx, x))) |
| 9151 |
return 0; |
| 9152 |
|
| 9153 |
/* Accept any base register. SP only in SImode or larger. */ |
| 9154 |
else if (thumb1_base_register_rtx_p (x, mode, strict_p)) |
| 9155 |
return 1; |
| 9156 |
|
| 9157 |
/* This is PC relative data before arm_reorg runs. */ |
| 9158 |
else if (GET_MODE_SIZE (mode) >= 4 && CONSTANT_P (x) |
| 9159 |
&& SYMBOL_REF_P (x) |
| 9160 |
&& CONSTANT_POOL_ADDRESS_P (x) && !flag_pic |
| 9161 |
&& !arm_disable_literal_pool) |
| 9162 |
return 1; |
| 9163 |
|
| 9164 |
/* This is PC relative data after arm_reorg runs. */ |
| 9165 |
else if ((GET_MODE_SIZE (mode) >= 4 || mode == HFmode) |
| 9166 |
&& reload_completed |
| 9167 |
&& (LABEL_REF_P (x) |
| 9168 |
|| (GET_CODE (x) == CONST |
| 9169 |
&& GET_CODE (XEXP (x, 0)) == PLUS |
| 9170 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF |
| 9171 |
&& CONST_INT_P (XEXP (XEXP (x, 0), 1))))) |
| 9172 |
return 1; |
| 9173 |
|
| 9174 |
/* Post-inc indexing only supported for SImode and larger. */ |
| 9175 |
else if (GET_CODE (x) == POST_INC && GET_MODE_SIZE (mode) >= 4 |
| 9176 |
&& thumb1_index_register_rtx_p (XEXP (x, 0), strict_p)) |
| 9177 |
return 1; |
| 9178 |
|
| 9179 |
else if (GET_CODE (x) == PLUS) |
| 9180 |
{ |
| 9181 |
/* REG+REG address can be any two index registers. */ |
| 9182 |
/* We disallow FRAME+REG addressing since we know that FRAME |
| 9183 |
will be replaced with STACK, and SP relative addressing only |
| 9184 |
permits SP+OFFSET. */ |
| 9185 |
if (GET_MODE_SIZE (mode) <= 4 |
| 9186 |
&& XEXP (x, 0) != frame_pointer_rtx |
| 9187 |
&& XEXP (x, 1) != frame_pointer_rtx |
| 9188 |
&& thumb1_index_register_rtx_p (XEXP (x, 0), strict_p) |
| 9189 |
&& (thumb1_index_register_rtx_p (XEXP (x, 1), strict_p) |
| 9190 |
|| (!strict_p && will_be_in_index_register (XEXP (x, 1))))) |
| 9191 |
return 1; |
| 9192 |
|
| 9193 |
/* REG+const has 5-7 bit offset for non-SP registers. */ |
| 9194 |
else if ((thumb1_index_register_rtx_p (XEXP (x, 0), strict_p) |
| 9195 |
|| XEXP (x, 0) == arg_pointer_rtx) |
| 9196 |
&& CONST_INT_P (XEXP (x, 1)) |
| 9197 |
&& thumb_legitimate_offset_p (mode, INTVAL (XEXP (x, 1)))) |
| 9198 |
return 1; |
| 9199 |
|
| 9200 |
/* REG+const has 10-bit offset for SP, but only SImode and |
| 9201 |
larger is supported. */ |
| 9202 |
/* ??? Should probably check for DI/DFmode overflow here |
| 9203 |
just like GO_IF_LEGITIMATE_OFFSET does. */ |
| 9204 |
else if (REG_P (XEXP (x, 0)) |
| 9205 |
&& REGNO (XEXP (x, 0)) == STACK_POINTER_REGNUM |
| 9206 |
&& GET_MODE_SIZE (mode) >= 4 |
| 9207 |
&& CONST_INT_P (XEXP (x, 1)) |
| 9208 |
&& INTVAL (XEXP (x, 1)) >= 0 |
| 9209 |
&& INTVAL (XEXP (x, 1)) + GET_MODE_SIZE (mode) <= 1024 |
| 9210 |
&& (INTVAL (XEXP (x, 1)) & 3) == 0) |
| 9211 |
return 1; |
| 9212 |
|
| 9213 |
else if (REG_P (XEXP (x, 0)) |
| 9214 |
&& (REGNO (XEXP (x, 0)) == FRAME_POINTER_REGNUM |
| 9215 |
|| REGNO (XEXP (x, 0)) == ARG_POINTER_REGNUM |
| 9216 |
|| VIRTUAL_REGISTER_P (XEXP (x, 0))) |
| 9217 |
&& GET_MODE_SIZE (mode) >= 4 |
| 9218 |
&& CONST_INT_P (XEXP (x, 1)) |
| 9219 |
&& (INTVAL (XEXP (x, 1)) & 3) == 0) |
| 9220 |
return 1; |
| 9221 |
} |
| 9222 |
|
| 9223 |
else if (GET_MODE_CLASS (mode) != MODE_FLOAT |
| 9224 |
&& GET_MODE_SIZE (mode) == 4 |
| 9225 |
&& SYMBOL_REF_P (x) |
| 9226 |
&& CONSTANT_POOL_ADDRESS_P (x) |
| 9227 |
&& !arm_disable_literal_pool |
| 9228 |
&& ! (flag_pic |
| 9229 |
&& symbol_mentioned_p (get_pool_constant (x)) |
| 9230 |
&& ! pcrel_constant_p (get_pool_constant (x)))) |
| 9231 |
return 1; |
| 9232 |
|
| 9233 |
return 0; |
| 9234 |
} |
| 9235 |
|
| 9236 |
/* Return nonzero if VAL can be used as an offset in a Thumb-state address |
| 9237 |
instruction of mode MODE. */ |
| 9238 |
int |
| 9239 |
thumb_legitimate_offset_p (machine_mode mode, HOST_WIDE_INT val) |
| 9240 |
{ |
| 9241 |
switch (GET_MODE_SIZE (mode)) |
| 9242 |
{ |
| 9243 |
case 1: |
| 9244 |
return val >= 0 && val < 32; |
| 9245 |
|
| 9246 |
case 2: |
| 9247 |
return val >= 0 && val < 64 && (val & 1) == 0; |
| 9248 |
|
| 9249 |
default: |
| 9250 |
return (val >= 0 |
| 9251 |
&& (val + GET_MODE_SIZE (mode)) <= 128 |
| 9252 |
&& (val & 3) == 0); |
| 9253 |
} |
| 9254 |
} |
| 9255 |
|
| 9256 |
bool |
| 9257 |
arm_legitimate_address_p (machine_mode mode, rtx x, bool strict_p, code_helper) |
| 9258 |
{ |
| 9259 |
if (TARGET_ARM) |
| 9260 |
return arm_legitimate_address_outer_p (mode, x, SET, strict_p); |
| 9261 |
else if (TARGET_THUMB2) |
| 9262 |
return thumb2_legitimate_address_p (mode, x, strict_p); |
| 9263 |
else /* if (TARGET_THUMB1) */ |
| 9264 |
return thumb1_legitimate_address_p (mode, x, strict_p); |
| 9265 |
} |
| 9266 |
|
| 9267 |
/* Worker function for TARGET_PREFERRED_RELOAD_CLASS. |
| 9268 |
|
| 9269 |
Given an rtx X being reloaded into a reg required to be |
| 9270 |
in class CLASS, return the class of reg to actually use. |
| 9271 |
In general this is just CLASS, but for the Thumb core registers and |
| 9272 |
immediate constants we prefer a LO_REGS class or a subset. */ |
| 9273 |
|
| 9274 |
static reg_class_t |
| 9275 |
arm_preferred_reload_class (rtx x ATTRIBUTE_UNUSED, reg_class_t rclass) |
| 9276 |
{ |
| 9277 |
if (TARGET_32BIT) |
| 9278 |
return rclass; |
| 9279 |
else |
| 9280 |
{ |
| 9281 |
if (rclass == GENERAL_REGS) |
| 9282 |
return LO_REGS; |
| 9283 |
else |
| 9284 |
return rclass; |
| 9285 |
} |
| 9286 |
} |
| 9287 |
|
| 9288 |
/* Build the SYMBOL_REF for __tls_get_addr. */ |
| 9289 |
|
| 9290 |
static GTY(()) rtx tls_get_addr_libfunc; |
| 9291 |
|
| 9292 |
static rtx |
| 9293 |
get_tls_get_addr (void) |
| 9294 |
{ |
| 9295 |
if (!tls_get_addr_libfunc) |
| 9296 |
tls_get_addr_libfunc = init_one_libfunc ("__tls_get_addr"); |
| 9297 |
return tls_get_addr_libfunc; |
| 9298 |
} |
| 9299 |
|
| 9300 |
rtx |
| 9301 |
arm_load_tp (rtx target) |
| 9302 |
{ |
| 9303 |
if (!target) |
| 9304 |
target = gen_reg_rtx (SImode); |
| 9305 |
|
| 9306 |
if (TARGET_HARD_TP) |
| 9307 |
{ |
| 9308 |
/* Can return in any reg. */ |
| 9309 |
emit_insn (gen_load_tp_hard (target)); |
| 9310 |
} |
| 9311 |
else |
| 9312 |
{ |
| 9313 |
/* Always returned in r0. Immediately copy the result into a pseudo, |
| 9314 |
otherwise other uses of r0 (e.g. setting up function arguments) may |
| 9315 |
clobber the value. */ |
| 9316 |
|
| 9317 |
rtx tmp; |
| 9318 |
|
| 9319 |
if (TARGET_FDPIC) |
| 9320 |
{ |
| 9321 |
rtx fdpic_reg = gen_rtx_REG (Pmode, FDPIC_REGNUM); |
| 9322 |
rtx initial_fdpic_reg = get_hard_reg_initial_val (Pmode, FDPIC_REGNUM); |
| 9323 |
|
| 9324 |
emit_insn (gen_load_tp_soft_fdpic ()); |
| 9325 |
|
| 9326 |
/* Restore r9. */ |
| 9327 |
emit_insn (gen_restore_pic_register_after_call(fdpic_reg, initial_fdpic_reg)); |
| 9328 |
} |
| 9329 |
else |
| 9330 |
emit_insn (gen_load_tp_soft ()); |
| 9331 |
|
| 9332 |
tmp = gen_rtx_REG (SImode, R0_REGNUM); |
| 9333 |
emit_move_insn (target, tmp); |
| 9334 |
} |
| 9335 |
return target; |
| 9336 |
} |
| 9337 |
|
| 9338 |
static rtx |
| 9339 |
load_tls_operand (rtx x, rtx reg) |
| 9340 |
{ |
| 9341 |
rtx tmp; |
| 9342 |
|
| 9343 |
if (reg == NULL_RTX) |
| 9344 |
reg = gen_reg_rtx (SImode); |
| 9345 |
|
| 9346 |
tmp = gen_rtx_CONST (SImode, x); |
| 9347 |
|
| 9348 |
emit_move_insn (reg, tmp); |
| 9349 |
|
| 9350 |
return reg; |
| 9351 |
} |
| 9352 |
|
| 9353 |
static rtx_insn * |
| 9354 |
arm_call_tls_get_addr (rtx x, rtx reg, rtx *valuep, int reloc) |
| 9355 |
{ |
| 9356 |
rtx label, labelno = NULL_RTX, sum; |
| 9357 |
|
| 9358 |
gcc_assert (reloc != TLS_DESCSEQ); |
| 9359 |
start_sequence (); |
| 9360 |
|
| 9361 |
if (TARGET_FDPIC) |
| 9362 |
{ |
| 9363 |
sum = gen_rtx_UNSPEC (Pmode, |
| 9364 |
gen_rtvec (2, x, GEN_INT (reloc)), |
| 9365 |
UNSPEC_TLS); |
| 9366 |
} |
| 9367 |
else |
| 9368 |
{ |
| 9369 |
labelno = GEN_INT (pic_labelno++); |
| 9370 |
label = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); |
| 9371 |
label = gen_rtx_CONST (VOIDmode, label); |
| 9372 |
|
| 9373 |
sum = gen_rtx_UNSPEC (Pmode, |
| 9374 |
gen_rtvec (4, x, GEN_INT (reloc), label, |
| 9375 |
GEN_INT (TARGET_ARM ? 8 : 4)), |
| 9376 |
UNSPEC_TLS); |
| 9377 |
} |
| 9378 |
reg = load_tls_operand (sum, reg); |
| 9379 |
|
| 9380 |
if (TARGET_FDPIC) |
| 9381 |
emit_insn (gen_addsi3 (reg, reg, gen_rtx_REG (Pmode, FDPIC_REGNUM))); |
| 9382 |
else if (TARGET_ARM) |
| 9383 |
emit_insn (gen_pic_add_dot_plus_eight (reg, reg, labelno)); |
| 9384 |
else |
| 9385 |
emit_insn (gen_pic_add_dot_plus_four (reg, reg, labelno)); |
| 9386 |
|
| 9387 |
*valuep = emit_library_call_value (get_tls_get_addr (), NULL_RTX, |
| 9388 |
LCT_PURE, /* LCT_CONST? */ |
| 9389 |
Pmode, reg, Pmode); |
| 9390 |
|
| 9391 |
rtx_insn *insns = get_insns (); |
| 9392 |
end_sequence (); |
| 9393 |
|
| 9394 |
return insns; |
| 9395 |
} |
| 9396 |
|
| 9397 |
static rtx |
| 9398 |
arm_tls_descseq_addr (rtx x, rtx reg) |
| 9399 |
{ |
| 9400 |
rtx labelno = GEN_INT (pic_labelno++); |
| 9401 |
rtx label = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); |
| 9402 |
rtx sum = gen_rtx_UNSPEC (Pmode, |
| 9403 |
gen_rtvec (4, x, GEN_INT (TLS_DESCSEQ), |
| 9404 |
gen_rtx_CONST (VOIDmode, label), |
| 9405 |
GEN_INT (!TARGET_ARM)), |
| 9406 |
UNSPEC_TLS); |
| 9407 |
rtx reg0 = load_tls_operand (sum, gen_rtx_REG (SImode, R0_REGNUM)); |
| 9408 |
|
| 9409 |
emit_insn (gen_tlscall (x, labelno)); |
| 9410 |
if (!reg) |
| 9411 |
reg = gen_reg_rtx (SImode); |
| 9412 |
else |
| 9413 |
gcc_assert (REGNO (reg) != R0_REGNUM); |
| 9414 |
|
| 9415 |
emit_move_insn (reg, reg0); |
| 9416 |
|
| 9417 |
return reg; |
| 9418 |
} |
| 9419 |
|
| 9420 |
|
| 9421 |
rtx |
| 9422 |
legitimize_tls_address (rtx x, rtx reg) |
| 9423 |
{ |
| 9424 |
rtx dest, tp, label, labelno, sum, ret, eqv, addend; |
| 9425 |
rtx_insn *insns; |
| 9426 |
unsigned int model = SYMBOL_REF_TLS_MODEL (x); |
| 9427 |
|
| 9428 |
switch (model) |
| 9429 |
{ |
| 9430 |
case TLS_MODEL_GLOBAL_DYNAMIC: |
| 9431 |
if (TARGET_GNU2_TLS) |
| 9432 |
{ |
| 9433 |
gcc_assert (!TARGET_FDPIC); |
| 9434 |
|
| 9435 |
reg = arm_tls_descseq_addr (x, reg); |
| 9436 |
|
| 9437 |
tp = arm_load_tp (NULL_RTX); |
| 9438 |
|
| 9439 |
dest = gen_rtx_PLUS (Pmode, tp, reg); |
| 9440 |
} |
| 9441 |
else |
| 9442 |
{ |
| 9443 |
/* Original scheme */ |
| 9444 |
if (TARGET_FDPIC) |
| 9445 |
insns = arm_call_tls_get_addr (x, reg, &ret, TLS_GD32_FDPIC); |
| 9446 |
else |
| 9447 |
insns = arm_call_tls_get_addr (x, reg, &ret, TLS_GD32); |
| 9448 |
dest = gen_reg_rtx (Pmode); |
| 9449 |
emit_libcall_block (insns, dest, ret, x); |
| 9450 |
} |
| 9451 |
return dest; |
| 9452 |
|
| 9453 |
case TLS_MODEL_LOCAL_DYNAMIC: |
| 9454 |
if (TARGET_GNU2_TLS) |
| 9455 |
{ |
| 9456 |
gcc_assert (!TARGET_FDPIC); |
| 9457 |
|
| 9458 |
reg = arm_tls_descseq_addr (x, reg); |
| 9459 |
|
| 9460 |
tp = arm_load_tp (NULL_RTX); |
| 9461 |
|
| 9462 |
dest = gen_rtx_PLUS (Pmode, tp, reg); |
| 9463 |
} |
| 9464 |
else |
| 9465 |
{ |
| 9466 |
if (TARGET_FDPIC) |
| 9467 |
insns = arm_call_tls_get_addr (x, reg, &ret, TLS_LDM32_FDPIC); |
| 9468 |
else |
| 9469 |
insns = arm_call_tls_get_addr (x, reg, &ret, TLS_LDM32); |
| 9470 |
|
| 9471 |
/* Attach a unique REG_EQUIV, to allow the RTL optimizers to |
| 9472 |
share the LDM result with other LD model accesses. */ |
| 9473 |
eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const1_rtx), |
| 9474 |
UNSPEC_TLS); |
| 9475 |
dest = gen_reg_rtx (Pmode); |
| 9476 |
emit_libcall_block (insns, dest, ret, eqv); |
| 9477 |
|
| 9478 |
/* Load the addend. */ |
| 9479 |
addend = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, x, |
| 9480 |
GEN_INT (TLS_LDO32)), |
| 9481 |
UNSPEC_TLS); |
| 9482 |
addend = force_reg (SImode, gen_rtx_CONST (SImode, addend)); |
| 9483 |
dest = gen_rtx_PLUS (Pmode, dest, addend); |
| 9484 |
} |
| 9485 |
return dest; |
| 9486 |
|
| 9487 |
case TLS_MODEL_INITIAL_EXEC: |
| 9488 |
if (TARGET_FDPIC) |
| 9489 |
{ |
| 9490 |
sum = gen_rtx_UNSPEC (Pmode, |
| 9491 |
gen_rtvec (2, x, GEN_INT (TLS_IE32_FDPIC)), |
| 9492 |
UNSPEC_TLS); |
| 9493 |
reg = load_tls_operand (sum, reg); |
| 9494 |
emit_insn (gen_addsi3 (reg, reg, gen_rtx_REG (Pmode, FDPIC_REGNUM))); |
| 9495 |
emit_move_insn (reg, gen_rtx_MEM (Pmode, reg)); |
| 9496 |
} |
| 9497 |
else |
| 9498 |
{ |
| 9499 |
labelno = GEN_INT (pic_labelno++); |
| 9500 |
label = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, labelno), UNSPEC_PIC_LABEL); |
| 9501 |
label = gen_rtx_CONST (VOIDmode, label); |
| 9502 |
sum = gen_rtx_UNSPEC (Pmode, |
| 9503 |
gen_rtvec (4, x, GEN_INT (TLS_IE32), label, |
| 9504 |
GEN_INT (TARGET_ARM ? 8 : 4)), |
| 9505 |
UNSPEC_TLS); |
| 9506 |
reg = load_tls_operand (sum, reg); |
| 9507 |
|
| 9508 |
if (TARGET_ARM) |
| 9509 |
emit_insn (gen_tls_load_dot_plus_eight (reg, reg, labelno)); |
| 9510 |
else if (TARGET_THUMB2) |
| 9511 |
emit_insn (gen_tls_load_dot_plus_four (reg, NULL, reg, labelno)); |
| 9512 |
else |
| 9513 |
{ |
| 9514 |
emit_insn (gen_pic_add_dot_plus_four (reg, reg, labelno)); |
| 9515 |
emit_move_insn (reg, gen_const_mem (SImode, reg)); |
| 9516 |
} |
| 9517 |
} |
| 9518 |
|
| 9519 |
tp = arm_load_tp (NULL_RTX); |
| 9520 |
|
| 9521 |
return gen_rtx_PLUS (Pmode, tp, reg); |
| 9522 |
|
| 9523 |
case TLS_MODEL_LOCAL_EXEC: |
| 9524 |
tp = arm_load_tp (NULL_RTX); |
| 9525 |
|
| 9526 |
reg = gen_rtx_UNSPEC (Pmode, |
| 9527 |
gen_rtvec (2, x, GEN_INT (TLS_LE32)), |
| 9528 |
UNSPEC_TLS); |
| 9529 |
reg = force_reg (SImode, gen_rtx_CONST (SImode, reg)); |
| 9530 |
|
| 9531 |
return gen_rtx_PLUS (Pmode, tp, reg); |
| 9532 |
|
| 9533 |
default: |
| 9534 |
abort (); |
| 9535 |
} |
| 9536 |
} |
| 9537 |
|
| 9538 |
/* Try machine-dependent ways of modifying an illegitimate address |
| 9539 |
to be legitimate. If we find one, return the new, valid address. */ |
| 9540 |
rtx |
| 9541 |
arm_legitimize_address (rtx x, rtx orig_x, machine_mode mode) |
| 9542 |
{ |
| 9543 |
if (arm_tls_referenced_p (x)) |
| 9544 |
{ |
| 9545 |
rtx addend = NULL; |
| 9546 |
|
| 9547 |
if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS) |
| 9548 |
{ |
| 9549 |
addend = XEXP (XEXP (x, 0), 1); |
| 9550 |
x = XEXP (XEXP (x, 0), 0); |
| 9551 |
} |
| 9552 |
|
| 9553 |
if (!SYMBOL_REF_P (x)) |
| 9554 |
return x; |
| 9555 |
|
| 9556 |
gcc_assert (SYMBOL_REF_TLS_MODEL (x) != 0); |
| 9557 |
|
| 9558 |
x = legitimize_tls_address (x, NULL_RTX); |
| 9559 |
|
| 9560 |
if (addend) |
| 9561 |
{ |
| 9562 |
x = gen_rtx_PLUS (SImode, x, addend); |
| 9563 |
orig_x = x; |
| 9564 |
} |
| 9565 |
else |
| 9566 |
return x; |
| 9567 |
} |
| 9568 |
|
| 9569 |
if (TARGET_THUMB1) |
| 9570 |
return thumb_legitimize_address (x, orig_x, mode); |
| 9571 |
|
| 9572 |
if (GET_CODE (x) == PLUS) |
| 9573 |
{ |
| 9574 |
rtx xop0 = XEXP (x, 0); |
| 9575 |
rtx xop1 = XEXP (x, 1); |
| 9576 |
|
| 9577 |
if (CONSTANT_P (xop0) && !symbol_mentioned_p (xop0)) |
| 9578 |
xop0 = force_reg (SImode, xop0); |
| 9579 |
|
| 9580 |
if (CONSTANT_P (xop1) && !CONST_INT_P (xop1) |
| 9581 |
&& !symbol_mentioned_p (xop1)) |
| 9582 |
xop1 = force_reg (SImode, xop1); |
| 9583 |
|
| 9584 |
if (ARM_BASE_REGISTER_RTX_P (xop0) |
| 9585 |
&& CONST_INT_P (xop1)) |
| 9586 |
{ |
| 9587 |
HOST_WIDE_INT n, low_n; |
| 9588 |
rtx base_reg, val; |
| 9589 |
n = INTVAL (xop1); |
| 9590 |
|
| 9591 |
/* VFP addressing modes actually allow greater offsets, but for |
| 9592 |
now we just stick with the lowest common denominator. */ |
| 9593 |
if (mode == DImode || mode == DFmode) |
| 9594 |
{ |
| 9595 |
low_n = n & 0x0f; |
| 9596 |
n &= ~0x0f; |
| 9597 |
if (low_n > 4) |
| 9598 |
{ |
| 9599 |
n += 16; |
| 9600 |
low_n -= 16; |
| 9601 |
} |
| 9602 |
} |
| 9603 |
else |
| 9604 |
{ |
| 9605 |
low_n = ((mode) == TImode ? 0 |
| 9606 |
: n >= 0 ? (n & 0xfff) : -((-n) & 0xfff)); |
| 9607 |
n -= low_n; |
| 9608 |
} |
| 9609 |
|
| 9610 |
base_reg = gen_reg_rtx (SImode); |
| 9611 |
val = force_operand (plus_constant (Pmode, xop0, n), NULL_RTX); |
| 9612 |
emit_move_insn (base_reg, val); |
| 9613 |
x = plus_constant (Pmode, base_reg, low_n); |
| 9614 |
} |
| 9615 |
else if (xop0 != XEXP (x, 0) || xop1 != XEXP (x, 1)) |
| 9616 |
x = gen_rtx_PLUS (SImode, xop0, xop1); |
| 9617 |
} |
| 9618 |
|
| 9619 |
/* XXX We don't allow MINUS any more -- see comment in |
| 9620 |
arm_legitimate_address_outer_p (). */ |
| 9621 |
else if (GET_CODE (x) == MINUS) |
| 9622 |
{ |
| 9623 |
rtx xop0 = XEXP (x, 0); |
| 9624 |
rtx xop1 = XEXP (x, 1); |
| 9625 |
|
| 9626 |
if (CONSTANT_P (xop0)) |
| 9627 |
xop0 = force_reg (SImode, xop0); |
| 9628 |
|
| 9629 |
if (CONSTANT_P (xop1) && ! symbol_mentioned_p (xop1)) |
| 9630 |
xop1 = force_reg (SImode, xop1); |
| 9631 |
|
| 9632 |
if (xop0 != XEXP (x, 0) || xop1 != XEXP (x, 1)) |
| 9633 |
x = gen_rtx_MINUS (SImode, xop0, xop1); |
| 9634 |
} |
| 9635 |
|
| 9636 |
/* Make sure to take full advantage of the pre-indexed addressing mode |
| 9637 |
with absolute addresses which often allows for the base register to |
| 9638 |
be factorized for multiple adjacent memory references, and it might |
| 9639 |
even allows for the mini pool to be avoided entirely. */ |
| 9640 |
else if (CONST_INT_P (x) && optimize > 0) |
| 9641 |
{ |
| 9642 |
unsigned int bits; |
| 9643 |
HOST_WIDE_INT mask, base, index; |
| 9644 |
rtx base_reg; |
| 9645 |
|
| 9646 |
/* LDR and LDRB can use a 12-bit index, ldrsb and the rest can |
| 9647 |
only use a 8-bit index. So let's use a 12-bit index for |
| 9648 |
SImode only and hope that arm_gen_constant will enable LDRB |
| 9649 |
to use more bits. */ |
| 9650 |
bits = (mode == SImode) ? 12 : 8; |
| 9651 |
mask = (1 << bits) - 1; |
| 9652 |
base = INTVAL (x) & ~mask; |
| 9653 |
index = INTVAL (x) & mask; |
| 9654 |
if (TARGET_ARM && bit_count (base & 0xffffffff) > (32 - bits)/2) |
| 9655 |
{ |
| 9656 |
/* It'll most probably be more efficient to generate the |
| 9657 |
base with more bits set and use a negative index instead. |
| 9658 |
Don't do this for Thumb as negative offsets are much more |
| 9659 |
limited. */ |
| 9660 |
base |= mask; |
| 9661 |
index -= mask; |
| 9662 |
} |
| 9663 |
base_reg = force_reg (SImode, GEN_INT (base)); |
| 9664 |
x = plus_constant (Pmode, base_reg, index); |
| 9665 |
} |
| 9666 |
|
| 9667 |
if (flag_pic) |
| 9668 |
{ |
| 9669 |
/* We need to find and carefully transform any SYMBOL and LABEL |
| 9670 |
references; so go back to the original address expression. */ |
| 9671 |
rtx new_x = legitimize_pic_address (orig_x, mode, NULL_RTX, NULL_RTX, |
| 9672 |
false /*compute_now*/); |
| 9673 |
|
| 9674 |
if (new_x != orig_x) |
| 9675 |
x = new_x; |
| 9676 |
} |
| 9677 |
|
| 9678 |
return x; |
| 9679 |
} |
| 9680 |
|
| 9681 |
|
| 9682 |
/* Try machine-dependent ways of modifying an illegitimate Thumb address |
| 9683 |
to be legitimate. If we find one, return the new, valid address. */ |
| 9684 |
rtx |
| 9685 |
thumb_legitimize_address (rtx x, rtx orig_x, machine_mode mode) |
| 9686 |
{ |
| 9687 |
if (GET_CODE (x) == PLUS |
| 9688 |
&& CONST_INT_P (XEXP (x, 1)) |
| 9689 |
&& (INTVAL (XEXP (x, 1)) >= 32 * GET_MODE_SIZE (mode) |
| 9690 |
|| INTVAL (XEXP (x, 1)) < 0)) |
| 9691 |
{ |
| 9692 |
rtx xop0 = XEXP (x, 0); |
| 9693 |
rtx xop1 = XEXP (x, 1); |
| 9694 |
HOST_WIDE_INT offset = INTVAL (xop1); |
| 9695 |
|
| 9696 |
/* Try and fold the offset into a biasing of the base register and |
| 9697 |
then offsetting that. Don't do this when optimizing for space |
| 9698 |
since it can cause too many CSEs. */ |
| 9699 |
if (optimize_size && offset >= 0 |
| 9700 |
&& offset < 256 + 31 * GET_MODE_SIZE (mode)) |
| 9701 |
{ |
| 9702 |
HOST_WIDE_INT delta; |
| 9703 |
|
| 9704 |
if (offset >= 256) |
| 9705 |
delta = offset - (256 - GET_MODE_SIZE (mode)); |
| 9706 |
else if (offset < 32 * GET_MODE_SIZE (mode) + 8) |
| 9707 |
delta = 31 * GET_MODE_SIZE (mode); |
| 9708 |
else |
| 9709 |
delta = offset & (~31 * GET_MODE_SIZE (mode)); |
| 9710 |
|
| 9711 |
xop0 = force_operand (plus_constant (Pmode, xop0, offset - delta), |
| 9712 |
NULL_RTX); |
| 9713 |
x = plus_constant (Pmode, xop0, delta); |
| 9714 |
} |
| 9715 |
else if (offset < 0 && offset > -256) |
| 9716 |
/* Small negative offsets are best done with a subtract before the |
| 9717 |
dereference, forcing these into a register normally takes two |
| 9718 |
instructions. */ |
| 9719 |
x = force_operand (x, NULL_RTX); |
| 9720 |
else |
| 9721 |
{ |
| 9722 |
/* For the remaining cases, force the constant into a register. */ |
| 9723 |
xop1 = force_reg (SImode, xop1); |
| 9724 |
x = gen_rtx_PLUS (SImode, xop0, xop1); |
| 9725 |
} |
| 9726 |
} |
| 9727 |
else if (GET_CODE (x) == PLUS |
| 9728 |
&& s_register_operand (XEXP (x, 1), SImode) |
| 9729 |
&& !s_register_operand (XEXP (x, 0), SImode)) |
| 9730 |
{ |
| 9731 |
rtx xop0 = force_operand (XEXP (x, 0), NULL_RTX); |
| 9732 |
|
| 9733 |
x = gen_rtx_PLUS (SImode, xop0, XEXP (x, 1)); |
| 9734 |
} |
| 9735 |
|
| 9736 |
if (flag_pic) |
| 9737 |
{ |
| 9738 |
/* We need to find and carefully transform any SYMBOL and LABEL |
| 9739 |
references; so go back to the original address expression. */ |
| 9740 |
rtx new_x = legitimize_pic_address (orig_x, mode, NULL_RTX, NULL_RTX, |
| 9741 |
false /*compute_now*/); |
| 9742 |
|
| 9743 |
if (new_x != orig_x) |
| 9744 |
x = new_x; |
| 9745 |
} |
| 9746 |
|
| 9747 |
return x; |
| 9748 |
} |
| 9749 |
|
| 9750 |
/* Return TRUE if X contains any TLS symbol references. */ |
| 9751 |
|
| 9752 |
bool |
| 9753 |
arm_tls_referenced_p (rtx x) |
| 9754 |
{ |
| 9755 |
if (! TARGET_HAVE_TLS) |
| 9756 |
return false; |
| 9757 |
|
| 9758 |
subrtx_iterator::array_type array; |
| 9759 |
FOR_EACH_SUBRTX (iter, array, x, ALL) |
| 9760 |
{ |
| 9761 |
const_rtx x = *iter; |
| 9762 |
if (SYMBOL_REF_P (x) && SYMBOL_REF_TLS_MODEL (x) != 0) |
| 9763 |
{ |
| 9764 |
/* ARM currently does not provide relocations to encode TLS variables |
| 9765 |
into AArch32 instructions, only data, so there is no way to |
| 9766 |
currently implement these if a literal pool is disabled. */ |
| 9767 |
if (arm_disable_literal_pool) |
| 9768 |
sorry ("accessing thread-local storage is not currently supported " |
| 9769 |
"with %<-mpure-code%> or %<-mslow-flash-data%>"); |
| 9770 |
|
| 9771 |
return true; |
| 9772 |
} |
| 9773 |
|
| 9774 |
/* Don't recurse into UNSPEC_TLS looking for TLS symbols; these are |
| 9775 |
TLS offsets, not real symbol references. */ |
| 9776 |
if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS) |
| 9777 |
iter.skip_subrtxes (); |
| 9778 |
} |
| 9779 |
return false; |
| 9780 |
} |
| 9781 |
|
| 9782 |
/* Implement TARGET_LEGITIMATE_CONSTANT_P. |
| 9783 |
|
| 9784 |
On the ARM, allow any integer (invalid ones are removed later by insn |
| 9785 |
patterns), nice doubles and symbol_refs which refer to the function's |
| 9786 |
constant pool XXX. |
| 9787 |
|
| 9788 |
When generating pic allow anything. */ |
| 9789 |
|
| 9790 |
static bool |
| 9791 |
arm_legitimate_constant_p_1 (machine_mode, rtx x) |
| 9792 |
{ |
| 9793 |
if (GET_CODE (x) == CONST_VECTOR && !neon_make_constant (x, false)) |
| 9794 |
return false; |
| 9795 |
|
| 9796 |
return flag_pic || !label_mentioned_p (x); |
| 9797 |
} |
| 9798 |
|
| 9799 |
static bool |
| 9800 |
thumb_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x) |
| 9801 |
{ |
| 9802 |
/* Splitters for TARGET_USE_MOVT call arm_emit_movpair which creates high |
| 9803 |
RTX. These RTX must therefore be allowed for Thumb-1 so that when run |
| 9804 |
for ARMv8-M Baseline or later the result is valid. */ |
| 9805 |
if (TARGET_HAVE_MOVT && GET_CODE (x) == HIGH) |
| 9806 |
x = XEXP (x, 0); |
| 9807 |
|
| 9808 |
return (CONST_INT_P (x) |
| 9809 |
|| CONST_DOUBLE_P (x) |
| 9810 |
|| CONSTANT_ADDRESS_P (x) |
| 9811 |
|| (TARGET_HAVE_MOVT && SYMBOL_REF_P (x)) |
| 9812 |
/* On Thumb-1 without MOVT/MOVW and literal pool disabled, |
| 9813 |
we build the symbol address with upper/lower |
| 9814 |
relocations. */ |
| 9815 |
|| (TARGET_THUMB1 |
| 9816 |
&& !label_mentioned_p (x) |
| 9817 |
&& arm_valid_symbolic_address_p (x) |
| 9818 |
&& arm_disable_literal_pool) |
| 9819 |
|| flag_pic); |
| 9820 |
} |
| 9821 |
|
| 9822 |
static bool |
| 9823 |
arm_legitimate_constant_p (machine_mode mode, rtx x) |
| 9824 |
{ |
| 9825 |
return (!arm_cannot_force_const_mem (mode, x) |
| 9826 |
&& (TARGET_32BIT |
| 9827 |
? arm_legitimate_constant_p_1 (mode, x) |
| 9828 |
: thumb_legitimate_constant_p (mode, x))); |
| 9829 |
} |
| 9830 |
|
| 9831 |
/* Implement TARGET_CANNOT_FORCE_CONST_MEM. */ |
| 9832 |
|
| 9833 |
static bool |
| 9834 |
arm_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x) |
| 9835 |
{ |
| 9836 |
rtx base, offset; |
| 9837 |
split_const (x, &base, &offset); |
| 9838 |
|
| 9839 |
if (SYMBOL_REF_P (base)) |
| 9840 |
{ |
| 9841 |
/* Function symbols cannot have an offset due to the Thumb bit. */ |
| 9842 |
if ((SYMBOL_REF_FLAGS (base) & SYMBOL_FLAG_FUNCTION) |
| 9843 |
&& INTVAL (offset) != 0) |
| 9844 |
return true; |
| 9845 |
|
| 9846 |
if (ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P |
| 9847 |
&& !offset_within_block_p (base, INTVAL (offset))) |
| 9848 |
return true; |
| 9849 |
} |
| 9850 |
return arm_tls_referenced_p (x); |
| 9851 |
} |
| 9852 |
|
| 9853 |
#define REG_OR_SUBREG_REG(X) \ |
| 9854 |
(REG_P (X) \ |
| 9855 |
|| (SUBREG_P (X) && REG_P (SUBREG_REG (X)))) |
| 9856 |
|
| 9857 |
#define REG_OR_SUBREG_RTX(X) \ |
| 9858 |
(REG_P (X) ? (X) : SUBREG_REG (X)) |
| 9859 |
|
| 9860 |
static inline int |
| 9861 |
thumb1_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer) |
| 9862 |
{ |
| 9863 |
machine_mode mode = GET_MODE (x); |
| 9864 |
int total, words; |
| 9865 |
|
| 9866 |
switch (code) |
| 9867 |
{ |
| 9868 |
case ASHIFT: |
| 9869 |
case ASHIFTRT: |
| 9870 |
case LSHIFTRT: |
| 9871 |
case ROTATERT: |
| 9872 |
return (mode == SImode) ? COSTS_N_INSNS (1) : COSTS_N_INSNS (2); |
| 9873 |
|
| 9874 |
case PLUS: |
| 9875 |
case MINUS: |
| 9876 |
case COMPARE: |
| 9877 |
case NEG: |
| 9878 |
case NOT: |
| 9879 |
return COSTS_N_INSNS (1); |
| 9880 |
|
| 9881 |
case MULT: |
| 9882 |
if (arm_arch6m && arm_m_profile_small_mul) |
| 9883 |
return COSTS_N_INSNS (32); |
| 9884 |
|
| 9885 |
if (CONST_INT_P (XEXP (x, 1))) |
| 9886 |
{ |
| 9887 |
int cycles = 0; |
| 9888 |
unsigned HOST_WIDE_INT i = INTVAL (XEXP (x, 1)); |
| 9889 |
|
| 9890 |
while (i) |
| 9891 |
{ |
| 9892 |
i >>= 2; |
| 9893 |
cycles++; |
| 9894 |
} |
| 9895 |
return COSTS_N_INSNS (2) + cycles; |
| 9896 |
} |
| 9897 |
return COSTS_N_INSNS (1) + 16; |
| 9898 |
|
| 9899 |
case SET: |
| 9900 |
/* A SET doesn't have a mode, so let's look at the SET_DEST to get |
| 9901 |
the mode. */ |
| 9902 |
words = ARM_NUM_INTS (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))); |
| 9903 |
return (COSTS_N_INSNS (words) |
| 9904 |
+ 4 * ((MEM_P (SET_SRC (x))) |
| 9905 |
+ MEM_P (SET_DEST (x)))); |
| 9906 |
|
| 9907 |
case CONST_INT: |
| 9908 |
if (outer == SET) |
| 9909 |
{ |
| 9910 |
if (UINTVAL (x) < 256 |
| 9911 |
/* 16-bit constant. */ |
| 9912 |
|| (TARGET_HAVE_MOVT && !(INTVAL (x) & 0xffff0000))) |
| 9913 |
return 0; |
| 9914 |
if (thumb_shiftable_const (INTVAL (x))) |
| 9915 |
return COSTS_N_INSNS (2); |
| 9916 |
return arm_disable_literal_pool |
| 9917 |
? COSTS_N_INSNS (8) |
| 9918 |
: COSTS_N_INSNS (3); |
| 9919 |
} |
| 9920 |
else if ((outer == PLUS || outer == COMPARE) |
| 9921 |
&& INTVAL (x) < 256 && INTVAL (x) > -256) |
| 9922 |
return 0; |
| 9923 |
else if ((outer == IOR || outer == XOR || outer == AND) |
| 9924 |
&& INTVAL (x) < 256 && INTVAL (x) >= -256) |
| 9925 |
return COSTS_N_INSNS (1); |
| 9926 |
else if (outer == AND) |
| 9927 |
{ |
| 9928 |
int i; |
| 9929 |
/* This duplicates the tests in the andsi3 expander. */ |
| 9930 |
for (i = 9; i <= 31; i++) |
| 9931 |
if ((HOST_WIDE_INT_1 << i) - 1 == INTVAL (x) |
| 9932 |
|| (HOST_WIDE_INT_1 << i) - 1 == ~INTVAL (x)) |
| 9933 |
return COSTS_N_INSNS (2); |
| 9934 |
} |
| 9935 |
else if (outer == ASHIFT || outer == ASHIFTRT |
| 9936 |
|| outer == LSHIFTRT) |
| 9937 |
return 0; |
| 9938 |
return COSTS_N_INSNS (2); |
| 9939 |
|
| 9940 |
case CONST: |
| 9941 |
case CONST_DOUBLE: |
| 9942 |
case LABEL_REF: |
| 9943 |
case SYMBOL_REF: |
| 9944 |
return COSTS_N_INSNS (3); |
| 9945 |
|
| 9946 |
case UDIV: |
| 9947 |
case UMOD: |
| 9948 |
case DIV: |
| 9949 |
case MOD: |
| 9950 |
return 100; |
| 9951 |
|
| 9952 |
case TRUNCATE: |
| 9953 |
return 99; |
| 9954 |
|
| 9955 |
case AND: |
| 9956 |
case XOR: |
| 9957 |
case IOR: |
| 9958 |
/* XXX guess. */ |
| 9959 |
return 8; |
| 9960 |
|
| 9961 |
case MEM: |
| 9962 |
/* XXX another guess. */ |
| 9963 |
/* Memory costs quite a lot for the first word, but subsequent words |
| 9964 |
load at the equivalent of a single insn each. */ |
| 9965 |
return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD) |
| 9966 |
+ ((SYMBOL_REF_P (x) && CONSTANT_POOL_ADDRESS_P (x)) |
| 9967 |
? 4 : 0)); |
| 9968 |
|
| 9969 |
case IF_THEN_ELSE: |
| 9970 |
/* XXX a guess. */ |
| 9971 |
if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC) |
| 9972 |
return 14; |
| 9973 |
return 2; |
| 9974 |
|
| 9975 |
case SIGN_EXTEND: |
| 9976 |
case ZERO_EXTEND: |
| 9977 |
total = mode == DImode ? COSTS_N_INSNS (1) : 0; |
| 9978 |
total += thumb1_rtx_costs (XEXP (x, 0), GET_CODE (XEXP (x, 0)), code); |
| 9979 |
|
| 9980 |
if (mode == SImode) |
| 9981 |
return total; |
| 9982 |
|
| 9983 |
if (arm_arch6) |
| 9984 |
return total + COSTS_N_INSNS (1); |
| 9985 |
|
| 9986 |
/* Assume a two-shift sequence. Increase the cost slightly so |
| 9987 |
we prefer actual shifts over an extend operation. */ |
| 9988 |
return total + 1 + COSTS_N_INSNS (2); |
| 9989 |
|
| 9990 |
default: |
| 9991 |
return 99; |
| 9992 |
} |
| 9993 |
} |
| 9994 |
|
| 9995 |
/* Estimates the size cost of thumb1 instructions. |
| 9996 |
For now most of the code is copied from thumb1_rtx_costs. We need more |
| 9997 |
fine grain tuning when we have more related test cases. */ |
| 9998 |
static inline int |
| 9999 |
thumb1_size_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer) |
| 10000 |
{ |
| 10001 |
machine_mode mode = GET_MODE (x); |
| 10002 |
int words, cost; |
| 10003 |
|
| 10004 |
switch (code) |
| 10005 |
{ |
| 10006 |
case ASHIFT: |
| 10007 |
case ASHIFTRT: |
| 10008 |
case LSHIFTRT: |
| 10009 |
case ROTATERT: |
| 10010 |
return (mode == SImode) ? COSTS_N_INSNS (1) : COSTS_N_INSNS (2); |
| 10011 |
|
| 10012 |
case PLUS: |
| 10013 |
case MINUS: |
| 10014 |
/* Thumb-1 needs two instructions to fulfill shiftadd/shiftsub0/shiftsub1 |
| 10015 |
defined by RTL expansion, especially for the expansion of |
| 10016 |
multiplication. */ |
| 10017 |
if ((GET_CODE (XEXP (x, 0)) == MULT |
| 10018 |
&& power_of_two_operand (XEXP (XEXP (x,0),1), SImode)) |
| 10019 |
|| (GET_CODE (XEXP (x, 1)) == MULT |
| 10020 |
&& power_of_two_operand (XEXP (XEXP (x, 1), 1), SImode))) |
| 10021 |
return COSTS_N_INSNS (2); |
| 10022 |
/* Fall through. */ |
| 10023 |
case COMPARE: |
| 10024 |
case NEG: |
| 10025 |
case NOT: |
| 10026 |
return COSTS_N_INSNS (1); |
| 10027 |
|
| 10028 |
case MULT: |
| 10029 |
if (CONST_INT_P (XEXP (x, 1))) |
| 10030 |
{ |
| 10031 |
/* Thumb1 mul instruction can't operate on const. We must Load it |
| 10032 |
into a register first. */ |
| 10033 |
int const_size = thumb1_size_rtx_costs (XEXP (x, 1), CONST_INT, SET); |
| 10034 |
/* For the targets which have a very small and high-latency multiply |
| 10035 |
unit, we prefer to synthesize the mult with up to 5 instructions, |
| 10036 |
giving a good balance between size and performance. */ |
| 10037 |
if (arm_arch6m && arm_m_profile_small_mul) |
| 10038 |
return COSTS_N_INSNS (5); |
| 10039 |
else |
| 10040 |
return COSTS_N_INSNS (1) + const_size; |
| 10041 |
} |
| 10042 |
return COSTS_N_INSNS (1); |
| 10043 |
|
| 10044 |
case SET: |
| 10045 |
/* A SET doesn't have a mode, so let's look at the SET_DEST to get |
| 10046 |
the mode. */ |
| 10047 |
words = ARM_NUM_INTS (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))); |
| 10048 |
cost = COSTS_N_INSNS (words); |
| 10049 |
if (satisfies_constraint_J (SET_SRC (x)) |
| 10050 |
|| satisfies_constraint_K (SET_SRC (x)) |
| 10051 |
/* Too big an immediate for a 2-byte mov, using MOVT. */ |
| 10052 |
|| (CONST_INT_P (SET_SRC (x)) |
| 10053 |
&& UINTVAL (SET_SRC (x)) >= 256 |
| 10054 |
&& TARGET_HAVE_MOVT |
| 10055 |
&& satisfies_constraint_j (SET_SRC (x))) |
| 10056 |
/* thumb1_movdi_insn. */ |
| 10057 |
|| ((words > 1) && MEM_P (SET_SRC (x)))) |
| 10058 |
cost += COSTS_N_INSNS (1); |
| 10059 |
return cost; |
| 10060 |
|
| 10061 |
case CONST_INT: |
| 10062 |
if (outer == SET) |
| 10063 |
{ |
| 10064 |
if (UINTVAL (x) < 256) |
| 10065 |
return COSTS_N_INSNS (1); |
| 10066 |
/* movw is 4byte long. */ |
| 10067 |
if (TARGET_HAVE_MOVT && !(INTVAL (x) & 0xffff0000)) |
| 10068 |
return COSTS_N_INSNS (2); |
| 10069 |
/* See split "TARGET_THUMB1 && satisfies_constraint_J". */ |
| 10070 |
if (INTVAL (x) >= -255 && INTVAL (x) <= -1) |
| 10071 |
return COSTS_N_INSNS (2); |
| 10072 |
/* See split "TARGET_THUMB1 && satisfies_constraint_K". */ |
| 10073 |
if (thumb_shiftable_const (INTVAL (x))) |
| 10074 |
return COSTS_N_INSNS (2); |
| 10075 |
return arm_disable_literal_pool |
| 10076 |
? COSTS_N_INSNS (8) |
| 10077 |
: COSTS_N_INSNS (3); |
| 10078 |
} |
| 10079 |
else if ((outer == PLUS || outer == COMPARE) |
| 10080 |
&& INTVAL (x) < 256 && INTVAL (x) > -256) |
| 10081 |
return 0; |
| 10082 |
else if ((outer == IOR || outer == XOR || outer == AND) |
| 10083 |
&& INTVAL (x) < 256 && INTVAL (x) >= -256) |
| 10084 |
return COSTS_N_INSNS (1); |
| 10085 |
else if (outer == AND) |
| 10086 |
{ |
| 10087 |
int i; |
| 10088 |
/* This duplicates the tests in the andsi3 expander. */ |
| 10089 |
for (i = 9; i <= 31; i++) |
| 10090 |
if ((HOST_WIDE_INT_1 << i) - 1 == INTVAL (x) |
| 10091 |
|| (HOST_WIDE_INT_1 << i) - 1 == ~INTVAL (x)) |
| 10092 |
return COSTS_N_INSNS (2); |
| 10093 |
} |
| 10094 |
else if (outer == ASHIFT || outer == ASHIFTRT |
| 10095 |
|| outer == LSHIFTRT) |
| 10096 |
return 0; |
| 10097 |
return COSTS_N_INSNS (2); |
| 10098 |
|
| 10099 |
case CONST: |
| 10100 |
case CONST_DOUBLE: |
| 10101 |
case LABEL_REF: |
| 10102 |
case SYMBOL_REF: |
| 10103 |
return COSTS_N_INSNS (3); |
| 10104 |
|
| 10105 |
case UDIV: |
| 10106 |
case UMOD: |
| 10107 |
case DIV: |
| 10108 |
case MOD: |
| 10109 |
return 100; |
| 10110 |
|
| 10111 |
case TRUNCATE: |
| 10112 |
return 99; |
| 10113 |
|
| 10114 |
case AND: |
| 10115 |
case XOR: |
| 10116 |
case IOR: |
| 10117 |
return COSTS_N_INSNS (1); |
| 10118 |
|
| 10119 |
case MEM: |
| 10120 |
return (COSTS_N_INSNS (1) |
| 10121 |
+ COSTS_N_INSNS (1) |
| 10122 |
* ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD) |
| 10123 |
+ ((SYMBOL_REF_P (x) && CONSTANT_POOL_ADDRESS_P (x)) |
| 10124 |
? COSTS_N_INSNS (1) : 0)); |
| 10125 |
|
| 10126 |
case IF_THEN_ELSE: |
| 10127 |
/* XXX a guess. */ |
| 10128 |
if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC) |
| 10129 |
return 14; |
| 10130 |
return 2; |
| 10131 |
|
| 10132 |
case ZERO_EXTEND: |
| 10133 |
/* XXX still guessing. */ |
| 10134 |
switch (GET_MODE (XEXP (x, 0))) |
| 10135 |
{ |
| 10136 |
case E_QImode: |
| 10137 |
return (1 + (mode == DImode ? 4 : 0) |
| 10138 |
+ (MEM_P (XEXP (x, 0)) ? 10 : 0)); |
| 10139 |
|
| 10140 |
case E_HImode: |
| 10141 |
return (4 + (mode == DImode ? 4 : 0) |
| 10142 |
+ (MEM_P (XEXP (x, 0)) ? 10 : 0)); |
| 10143 |
|
| 10144 |
case E_SImode: |
| 10145 |
return (1 + (MEM_P (XEXP (x, 0)) ? 10 : 0)); |
| 10146 |
|
| 10147 |
default: |
| 10148 |
return 99; |
| 10149 |
} |
| 10150 |
|
| 10151 |
default: |
| 10152 |
return 99; |
| 10153 |
} |
| 10154 |
} |
| 10155 |
|
| 10156 |
/* Helper function for arm_rtx_costs. If one operand of the OP, a |
| 10157 |
PLUS, adds the carry flag, then return the other operand. If |
| 10158 |
neither is a carry, return OP unchanged. */ |
| 10159 |
static rtx |
| 10160 |
strip_carry_operation (rtx op) |
| 10161 |
{ |
| 10162 |
gcc_assert (GET_CODE (op) == PLUS); |
| 10163 |
if (arm_carry_operation (XEXP (op, 0), GET_MODE (op))) |
| 10164 |
return XEXP (op, 1); |
| 10165 |
else if (arm_carry_operation (XEXP (op, 1), GET_MODE (op))) |
| 10166 |
return XEXP (op, 0); |
| 10167 |
return op; |
| 10168 |
} |
| 10169 |
|
| 10170 |
/* Helper function for arm_rtx_costs. If the operand is a valid shift |
| 10171 |
operand, then return the operand that is being shifted. If the shift |
| 10172 |
is not by a constant, then set SHIFT_REG to point to the operand. |
| 10173 |
Return NULL if OP is not a shifter operand. */ |
| 10174 |
static rtx |
| 10175 |
shifter_op_p (rtx op, rtx *shift_reg) |
| 10176 |
{ |
| 10177 |
enum rtx_code code = GET_CODE (op); |
| 10178 |
|
| 10179 |
if (code == MULT && CONST_INT_P (XEXP (op, 1)) |
| 10180 |
&& exact_log2 (INTVAL (XEXP (op, 1))) > 0) |
| 10181 |
return XEXP (op, 0); |
| 10182 |
else if (code == ROTATE && CONST_INT_P (XEXP (op, 1))) |
| 10183 |
return XEXP (op, 0); |
| 10184 |
else if (code == ROTATERT || code == ASHIFT || code == LSHIFTRT |
| 10185 |
|| code == ASHIFTRT) |
| 10186 |
{ |
| 10187 |
if (!CONST_INT_P (XEXP (op, 1))) |
| 10188 |
*shift_reg = XEXP (op, 1); |
| 10189 |
return XEXP (op, 0); |
| 10190 |
} |
| 10191 |
|
| 10192 |
return NULL; |
| 10193 |
} |
| 10194 |
|
| 10195 |
static bool |
| 10196 |
arm_unspec_cost (rtx x, enum rtx_code /* outer_code */, bool speed_p, int *cost) |
| 10197 |
{ |
| 10198 |
const struct cpu_cost_table *extra_cost = current_tune->insn_extra_cost; |
| 10199 |
rtx_code code = GET_CODE (x); |
| 10200 |
gcc_assert (code == UNSPEC || code == UNSPEC_VOLATILE); |
| 10201 |
|
| 10202 |
switch (XINT (x, 1)) |
| 10203 |
{ |
| 10204 |
case UNSPEC_UNALIGNED_LOAD: |
| 10205 |
/* We can only do unaligned loads into the integer unit, and we can't |
| 10206 |
use LDM or LDRD. */ |
| 10207 |
*cost = COSTS_N_INSNS (ARM_NUM_REGS (GET_MODE (x))); |
| 10208 |
if (speed_p) |
| 10209 |
*cost += (ARM_NUM_REGS (GET_MODE (x)) * extra_cost->ldst.load |
| 10210 |
+ extra_cost->ldst.load_unaligned); |
| 10211 |
|
| 10212 |
#ifdef NOT_YET |
| 10213 |
*cost += arm_address_cost (XEXP (XVECEXP (x, 0, 0), 0), GET_MODE (x), |
| 10214 |
ADDR_SPACE_GENERIC, speed_p); |
| 10215 |
#endif |
| 10216 |
return true; |
| 10217 |
|
| 10218 |
case UNSPEC_UNALIGNED_STORE: |
| 10219 |
*cost = COSTS_N_INSNS (ARM_NUM_REGS (GET_MODE (x))); |
| 10220 |
if (speed_p) |
| 10221 |
*cost += (ARM_NUM_REGS (GET_MODE (x)) * extra_cost->ldst.store |
| 10222 |
+ extra_cost->ldst.store_unaligned); |
| 10223 |
|
| 10224 |
*cost += rtx_cost (XVECEXP (x, 0, 0), VOIDmode, UNSPEC, 0, speed_p); |
| 10225 |
#ifdef NOT_YET |
| 10226 |
*cost += arm_address_cost (XEXP (XVECEXP (x, 0, 0), 0), GET_MODE (x), |
| 10227 |
ADDR_SPACE_GENERIC, speed_p); |
| 10228 |
#endif |
| 10229 |
return true; |
| 10230 |
|
| 10231 |
case UNSPEC_VRINTZ: |
| 10232 |
case UNSPEC_VRINTP: |
| 10233 |
case UNSPEC_VRINTM: |
| 10234 |
case UNSPEC_VRINTR: |
| 10235 |
case UNSPEC_VRINTX: |
| 10236 |
case UNSPEC_VRINTA: |
| 10237 |
if (speed_p) |
| 10238 |
*cost += extra_cost->fp[GET_MODE (x) == DFmode].roundint; |
| 10239 |
|
| 10240 |
return true; |
| 10241 |
default: |
| 10242 |
*cost = COSTS_N_INSNS (2); |
| 10243 |
break; |
| 10244 |
} |
| 10245 |
return true; |
| 10246 |
} |
| 10247 |
|
| 10248 |
/* Cost of a libcall. We assume one insn per argument, an amount for the |
| 10249 |
call (one insn for -Os) and then one for processing the result. */ |
| 10250 |
#define LIBCALL_COST(N) COSTS_N_INSNS (N + (speed_p ? 18 : 2)) |
| 10251 |
|
| 10252 |
#define HANDLE_NARROW_SHIFT_ARITH(OP, IDX) \ |
| 10253 |
do \ |
| 10254 |
{ \ |
| 10255 |
shift_op = shifter_op_p (XEXP (x, IDX), &shift_reg); \ |
| 10256 |
if (shift_op != NULL \ |
| 10257 |
&& arm_rtx_shift_left_p (XEXP (x, IDX))) \ |
| 10258 |
{ \ |
| 10259 |
if (shift_reg) \ |
| 10260 |
{ \ |
| 10261 |
if (speed_p) \ |
| 10262 |
*cost += extra_cost->alu.arith_shift_reg; \ |
| 10263 |
*cost += rtx_cost (shift_reg, GET_MODE (shift_reg), \ |
| 10264 |
ASHIFT, 1, speed_p); \ |
| 10265 |
} \ |
| 10266 |
else if (speed_p) \ |
| 10267 |
*cost += extra_cost->alu.arith_shift; \ |
| 10268 |
\ |
| 10269 |
*cost += (rtx_cost (shift_op, GET_MODE (shift_op), \ |
| 10270 |
ASHIFT, 0, speed_p) \ |
| 10271 |
+ rtx_cost (XEXP (x, 1 - IDX), \ |
| 10272 |
GET_MODE (shift_op), \ |
| 10273 |
OP, 1, speed_p)); \ |
| 10274 |
return true; \ |
| 10275 |
} \ |
| 10276 |
} \ |
| 10277 |
while (0) |
| 10278 |
|
| 10279 |
/* Helper function for arm_rtx_costs_internal. Calculates the cost of a MEM, |
| 10280 |
considering the costs of the addressing mode and memory access |
| 10281 |
separately. */ |
| 10282 |
static bool |
| 10283 |
arm_mem_costs (rtx x, const struct cpu_cost_table *extra_cost, |
| 10284 |
int *cost, bool speed_p) |
| 10285 |
{ |
| 10286 |
machine_mode mode = GET_MODE (x); |
| 10287 |
|
| 10288 |
*cost = COSTS_N_INSNS (1); |
| 10289 |
|
| 10290 |
if (flag_pic |
| 10291 |
&& GET_CODE (XEXP (x, 0)) == PLUS |
| 10292 |
&& will_be_in_index_register (XEXP (XEXP (x, 0), 1))) |
| 10293 |
/* This will be split into two instructions. Add the cost of the |
| 10294 |
additional instruction here. The cost of the memory access is computed |
| 10295 |
below. See arm.md:calculate_pic_address. */ |
| 10296 |
*cost += COSTS_N_INSNS (1); |
| 10297 |
|
| 10298 |
/* Calculate cost of the addressing mode. */ |
| 10299 |
if (speed_p) |
| 10300 |
{ |
| 10301 |
arm_addr_mode_op op_type; |
| 10302 |
switch (GET_CODE (XEXP (x, 0))) |
| 10303 |
{ |
| 10304 |
default: |
| 10305 |
case REG: |
| 10306 |
op_type = AMO_DEFAULT; |
| 10307 |
break; |
| 10308 |
case MINUS: |
| 10309 |
/* MINUS does not appear in RTL, but the architecture supports it, |
| 10310 |
so handle this case defensively. */ |
| 10311 |
/* fall through */ |
| 10312 |
case PLUS: |
| 10313 |
op_type = AMO_NO_WB; |
| 10314 |
break; |
| 10315 |
case PRE_INC: |
| 10316 |
case PRE_DEC: |
| 10317 |
case POST_INC: |
| 10318 |
case POST_DEC: |
| 10319 |
case PRE_MODIFY: |
| 10320 |
case POST_MODIFY: |
| 10321 |
op_type = AMO_WB; |
| 10322 |
break; |
| 10323 |
} |
| 10324 |
|
| 10325 |
if (VECTOR_MODE_P (mode)) |
| 10326 |
*cost += current_tune->addr_mode_costs->vector[op_type]; |
| 10327 |
else if (FLOAT_MODE_P (mode)) |
| 10328 |
*cost += current_tune->addr_mode_costs->fp[op_type]; |
| 10329 |
else |
| 10330 |
*cost += current_tune->addr_mode_costs->integer[op_type]; |
| 10331 |
} |
| 10332 |
|
| 10333 |
/* Calculate cost of memory access. */ |
| 10334 |
if (speed_p) |
| 10335 |
{ |
| 10336 |
if (FLOAT_MODE_P (mode)) |
| 10337 |
{ |
| 10338 |
if (GET_MODE_SIZE (mode) == 8) |
| 10339 |
*cost += extra_cost->ldst.loadd; |
| 10340 |
else |
| 10341 |
*cost += extra_cost->ldst.loadf; |
| 10342 |
} |
| 10343 |
else if (VECTOR_MODE_P (mode)) |
| 10344 |
*cost += extra_cost->ldst.loadv; |
| 10345 |
else |
| 10346 |
{ |
| 10347 |
/* Integer modes */ |
| 10348 |
if (GET_MODE_SIZE (mode) == 8) |
| 10349 |
*cost += extra_cost->ldst.ldrd; |
| 10350 |
else |
| 10351 |
*cost += extra_cost->ldst.load; |
| 10352 |
} |
| 10353 |
} |
| 10354 |
|
| 10355 |
return true; |
| 10356 |
} |
| 10357 |
|
| 10358 |
/* Helper for arm_bfi_p. */ |
| 10359 |
static bool |
| 10360 |
arm_bfi_1_p (rtx op0, rtx op1, rtx *sub0, rtx *sub1) |
| 10361 |
{ |
| 10362 |
unsigned HOST_WIDE_INT const1; |
| 10363 |
unsigned HOST_WIDE_INT const2 = 0; |
| 10364 |
|
| 10365 |
if (!CONST_INT_P (XEXP (op0, 1))) |
| 10366 |
return false; |
| 10367 |
|
| 10368 |
const1 = UINTVAL (XEXP (op0, 1)); |
| 10369 |
if (!CONST_INT_P (XEXP (op1, 1)) |
| 10370 |
|| ~UINTVAL (XEXP (op1, 1)) != const1) |
| 10371 |
return false; |
| 10372 |
|
| 10373 |
if (GET_CODE (XEXP (op0, 0)) == ASHIFT |
| 10374 |
&& CONST_INT_P (XEXP (XEXP (op0, 0), 1))) |
| 10375 |
{ |
| 10376 |
const2 = UINTVAL (XEXP (XEXP (op0, 0), 1)); |
| 10377 |
*sub0 = XEXP (XEXP (op0, 0), 0); |
| 10378 |
} |
| 10379 |
else |
| 10380 |
*sub0 = XEXP (op0, 0); |
| 10381 |
|
| 10382 |
if (const2 >= GET_MODE_BITSIZE (GET_MODE (op0))) |
| 10383 |
return false; |
| 10384 |
|
| 10385 |
*sub1 = XEXP (op1, 0); |
| 10386 |
return exact_log2 (const1 + (HOST_WIDE_INT_1U << const2)) >= 0; |
| 10387 |
} |
| 10388 |
|
| 10389 |
/* Recognize a BFI idiom. Helper for arm_rtx_costs_internal. The |
| 10390 |
format looks something like: |
| 10391 |
|
| 10392 |
(IOR (AND (reg1) (~const1)) |
| 10393 |
(AND (ASHIFT (reg2) (const2)) |
| 10394 |
(const1))) |
| 10395 |
|
| 10396 |
where const1 is a consecutive sequence of 1-bits with the |
| 10397 |
least-significant non-zero bit starting at bit position const2. If |
| 10398 |
const2 is zero, then the shift will not appear at all, due to |
| 10399 |
canonicalization. The two arms of the IOR expression may be |
| 10400 |
flipped. */ |
| 10401 |
static bool |
| 10402 |
arm_bfi_p (rtx x, rtx *sub0, rtx *sub1) |
| 10403 |
{ |
| 10404 |
if (GET_CODE (x) != IOR) |
| 10405 |
return false; |
| 10406 |
if (GET_CODE (XEXP (x, 0)) != AND |
| 10407 |
|| GET_CODE (XEXP (x, 1)) != AND) |
| 10408 |
return false; |
| 10409 |
return (arm_bfi_1_p (XEXP (x, 0), XEXP (x, 1), sub0, sub1) |
| 10410 |
|| arm_bfi_1_p (XEXP (x, 1), XEXP (x, 0), sub1, sub0)); |
| 10411 |
} |
| 10412 |
|
| 10413 |
/* RTX costs. Make an estimate of the cost of executing the operation |
| 10414 |
X, which is contained within an operation with code OUTER_CODE. |
| 10415 |
SPEED_P indicates whether the cost desired is the performance cost, |
| 10416 |
or the size cost. The estimate is stored in COST and the return |
| 10417 |
value is TRUE if the cost calculation is final, or FALSE if the |
| 10418 |
caller should recurse through the operands of X to add additional |
| 10419 |
costs. |
| 10420 |
|
| 10421 |
We currently make no attempt to model the size savings of Thumb-2 |
| 10422 |
16-bit instructions. At the normal points in compilation where |
| 10423 |
this code is called we have no measure of whether the condition |
| 10424 |
flags are live or not, and thus no realistic way to determine what |
| 10425 |
the size will eventually be. */ |
| 10426 |
static bool |
| 10427 |
arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code, |
| 10428 |
const struct cpu_cost_table *extra_cost, |
| 10429 |
int *cost, bool speed_p) |
| 10430 |
{ |
| 10431 |
machine_mode mode = GET_MODE (x); |
| 10432 |
|
| 10433 |
*cost = COSTS_N_INSNS (1); |
| 10434 |
|
| 10435 |
if (TARGET_THUMB1) |
| 10436 |
{ |
| 10437 |
if (speed_p) |
| 10438 |
*cost = thumb1_rtx_costs (x, code, outer_code); |
| 10439 |
else |
| 10440 |
*cost = thumb1_size_rtx_costs (x, code, outer_code); |
| 10441 |
return true; |
| 10442 |
} |
| 10443 |
|
| 10444 |
switch (code) |
| 10445 |
{ |
| 10446 |
case SET: |
| 10447 |
*cost = 0; |
| 10448 |
/* SET RTXs don't have a mode so we get it from the destination. */ |
| 10449 |
mode = GET_MODE (SET_DEST (x)); |
| 10450 |
|
| 10451 |
if (REG_P (SET_SRC (x)) |
| 10452 |
&& REG_P (SET_DEST (x))) |
| 10453 |
{ |
| 10454 |
/* Assume that most copies can be done with a single insn, |
| 10455 |
unless we don't have HW FP, in which case everything |
| 10456 |
larger than word mode will require two insns. */ |
| 10457 |
*cost = COSTS_N_INSNS (((!TARGET_VFP_BASE |
| 10458 |
&& GET_MODE_SIZE (mode) > 4) |
| 10459 |
|| mode == DImode) |
| 10460 |
? 2 : 1); |
| 10461 |
/* Conditional register moves can be encoded |
| 10462 |
in 16 bits in Thumb mode. */ |
| 10463 |
if (!speed_p && TARGET_THUMB && outer_code == COND_EXEC) |
| 10464 |
*cost >>= 1; |
| 10465 |
|
| 10466 |
return true; |
| 10467 |
} |
| 10468 |
|
| 10469 |
if (CONST_INT_P (SET_SRC (x))) |
| 10470 |
{ |
| 10471 |
/* Handle CONST_INT here, since the value doesn't have a mode |
| 10472 |
and we would otherwise be unable to work out the true cost. */ |
| 10473 |
*cost = rtx_cost (SET_DEST (x), GET_MODE (SET_DEST (x)), SET, |
| 10474 |
0, speed_p); |
| 10475 |
outer_code = SET; |
| 10476 |
/* Slightly lower the cost of setting a core reg to a constant. |
| 10477 |
This helps break up chains and allows for better scheduling. */ |
| 10478 |
if (REG_P (SET_DEST (x)) |
| 10479 |
&& REGNO (SET_DEST (x)) <= LR_REGNUM) |
| 10480 |
*cost -= 1; |
| 10481 |
x = SET_SRC (x); |
| 10482 |
/* Immediate moves with an immediate in the range [0, 255] can be |
| 10483 |
encoded in 16 bits in Thumb mode. */ |
| 10484 |
if (!speed_p && TARGET_THUMB && GET_MODE (x) == SImode |
| 10485 |
&& INTVAL (x) >= 0 && INTVAL (x) <=255) |
| 10486 |
*cost >>= 1; |
| 10487 |
goto const_int_cost; |
| 10488 |
} |
| 10489 |
|
| 10490 |
return false; |
| 10491 |
|
| 10492 |
case MEM: |
| 10493 |
return arm_mem_costs (x, extra_cost, cost, speed_p); |
| 10494 |
|
| 10495 |
case PARALLEL: |
| 10496 |
{ |
| 10497 |
/* Calculations of LDM costs are complex. We assume an initial cost |
| 10498 |
(ldm_1st) which will load the number of registers mentioned in |
| 10499 |
ldm_regs_per_insn_1st registers; then each additional |
| 10500 |
ldm_regs_per_insn_subsequent registers cost one more insn. The |
| 10501 |
formula for N regs is thus: |
| 10502 |
|
| 10503 |
ldm_1st + COSTS_N_INSNS ((max (N - ldm_regs_per_insn_1st, 0) |
| 10504 |
+ ldm_regs_per_insn_subsequent - 1) |
| 10505 |
/ ldm_regs_per_insn_subsequent). |
| 10506 |
|
| 10507 |
Additional costs may also be added for addressing. A similar |
| 10508 |
formula is used for STM. */ |
| 10509 |
|
| 10510 |
bool is_ldm = load_multiple_operation (x, SImode); |
| 10511 |
bool is_stm = store_multiple_operation (x, SImode); |
| 10512 |
|
| 10513 |
if (is_ldm || is_stm) |
| 10514 |
{ |
| 10515 |
if (speed_p) |
| 10516 |
{ |
| 10517 |
HOST_WIDE_INT nregs = XVECLEN (x, 0); |
| 10518 |
HOST_WIDE_INT regs_per_insn_1st = is_ldm |
| 10519 |
? extra_cost->ldst.ldm_regs_per_insn_1st |
| 10520 |
: extra_cost->ldst.stm_regs_per_insn_1st; |
| 10521 |
HOST_WIDE_INT regs_per_insn_sub = is_ldm |
| 10522 |
? extra_cost->ldst.ldm_regs_per_insn_subsequent |
| 10523 |
: extra_cost->ldst.stm_regs_per_insn_subsequent; |
| 10524 |
|
| 10525 |
*cost += regs_per_insn_1st |
| 10526 |
+ COSTS_N_INSNS (((MAX (nregs - regs_per_insn_1st, 0)) |
| 10527 |
+ regs_per_insn_sub - 1) |
| 10528 |
/ regs_per_insn_sub); |
| 10529 |
return true; |
| 10530 |
} |
| 10531 |
|
| 10532 |
} |
| 10533 |
return false; |
| 10534 |
} |
| 10535 |
case DIV: |
| 10536 |
case UDIV: |
| 10537 |
if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
| 10538 |
&& (mode == SFmode || !TARGET_VFP_SINGLE)) |
| 10539 |
*cost += COSTS_N_INSNS (speed_p |
| 10540 |
? extra_cost->fp[mode != SFmode].div : 0); |
| 10541 |
else if (mode == SImode && TARGET_IDIV) |
| 10542 |
*cost += COSTS_N_INSNS (speed_p ? extra_cost->mult[0].idiv : 0); |
| 10543 |
else |
| 10544 |
*cost = LIBCALL_COST (2); |
| 10545 |
|
| 10546 |
/* Make the cost of sdiv more expensive so when both sdiv and udiv are |
| 10547 |
possible udiv is prefered. */ |
| 10548 |
*cost += (code == DIV ? COSTS_N_INSNS (1) : 0); |
| 10549 |
return false; /* All arguments must be in registers. */ |
| 10550 |
|
| 10551 |
case MOD: |
| 10552 |
/* MOD by a power of 2 can be expanded as: |
| 10553 |
rsbs r1, r0, #0 |
| 10554 |
and r0, r0, #(n - 1) |
| 10555 |
and r1, r1, #(n - 1) |
| 10556 |
rsbpl r0, r1, #0. */ |
| 10557 |
if (CONST_INT_P (XEXP (x, 1)) |
| 10558 |
&& exact_log2 (INTVAL (XEXP (x, 1))) > 0 |
| 10559 |
&& mode == SImode) |
| 10560 |
{ |
| 10561 |
*cost += COSTS_N_INSNS (3); |
| 10562 |
|
| 10563 |
if (speed_p) |
| 10564 |
*cost += 2 * extra_cost->alu.logical |
| 10565 |
+ extra_cost->alu.arith; |
| 10566 |
return true; |
| 10567 |
} |
| 10568 |
|
| 10569 |
/* Fall-through. */ |
| 10570 |
case UMOD: |
| 10571 |
/* Make the cost of sdiv more expensive so when both sdiv and udiv are |
| 10572 |
possible udiv is prefered. */ |
| 10573 |
*cost = LIBCALL_COST (2) + (code == MOD ? COSTS_N_INSNS (1) : 0); |
| 10574 |
return false; /* All arguments must be in registers. */ |
| 10575 |
|
| 10576 |
case ROTATE: |
| 10577 |
if (mode == SImode && REG_P (XEXP (x, 1))) |
| 10578 |
{ |
| 10579 |
*cost += (COSTS_N_INSNS (1) |
| 10580 |
+ rtx_cost (XEXP (x, 0), mode, code, 0, speed_p)); |
| 10581 |
if (speed_p) |
| 10582 |
*cost += extra_cost->alu.shift_reg; |
| 10583 |
return true; |
| 10584 |
} |
| 10585 |
/* Fall through */ |
| 10586 |
case ROTATERT: |
| 10587 |
case ASHIFT: |
| 10588 |
case LSHIFTRT: |
| 10589 |
case ASHIFTRT: |
| 10590 |
if (mode == DImode && CONST_INT_P (XEXP (x, 1))) |
| 10591 |
{ |
| 10592 |
*cost += (COSTS_N_INSNS (2) |
| 10593 |
+ rtx_cost (XEXP (x, 0), mode, code, 0, speed_p)); |
| 10594 |
if (speed_p) |
| 10595 |
*cost += 2 * extra_cost->alu.shift; |
| 10596 |
/* Slightly disparage left shift by 1 at so we prefer adddi3. */ |
| 10597 |
if (code == ASHIFT && XEXP (x, 1) == CONST1_RTX (SImode)) |
| 10598 |
*cost += 1; |
| 10599 |
return true; |
| 10600 |
} |
| 10601 |
else if (mode == SImode) |
| 10602 |
{ |
| 10603 |
*cost += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); |
| 10604 |
/* Slightly disparage register shifts at -Os, but not by much. */ |
| 10605 |
if (!CONST_INT_P (XEXP (x, 1))) |
| 10606 |
*cost += (speed_p ? extra_cost->alu.shift_reg : 1 |
| 10607 |
+ rtx_cost (XEXP (x, 1), mode, code, 1, speed_p)); |
| 10608 |
return true; |
| 10609 |
} |
| 10610 |
else if (GET_MODE_CLASS (mode) == MODE_INT |
| 10611 |
&& GET_MODE_SIZE (mode) < 4) |
| 10612 |
{ |
| 10613 |
if (code == ASHIFT) |
| 10614 |
{ |
| 10615 |
*cost += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); |
| 10616 |
/* Slightly disparage register shifts at -Os, but not by |
| 10617 |
much. */ |
| 10618 |
if (!CONST_INT_P (XEXP (x, 1))) |
| 10619 |
*cost += (speed_p ? extra_cost->alu.shift_reg : 1 |
| 10620 |
+ rtx_cost (XEXP (x, 1), mode, code, 1, speed_p)); |
| 10621 |
} |
| 10622 |
else if (code == LSHIFTRT || code == ASHIFTRT) |
| 10623 |
{ |
| 10624 |
if (arm_arch_thumb2 && CONST_INT_P (XEXP (x, 1))) |
| 10625 |
{ |
| 10626 |
/* Can use SBFX/UBFX. */ |
| 10627 |
if (speed_p) |
| 10628 |
*cost += extra_cost->alu.bfx; |
| 10629 |
*cost += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); |
| 10630 |
} |
| 10631 |
else |
| 10632 |
{ |
| 10633 |
*cost += COSTS_N_INSNS (1); |
| 10634 |
*cost += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); |
| 10635 |
if (speed_p) |
| 10636 |
{ |
| 10637 |
if (CONST_INT_P (XEXP (x, 1))) |
| 10638 |
*cost += 2 * extra_cost->alu.shift; |
| 10639 |
else |
| 10640 |
*cost += (extra_cost->alu.shift |
| 10641 |
+ extra_cost->alu.shift_reg); |
| 10642 |
} |
| 10643 |
else |
| 10644 |
/* Slightly disparage register shifts. */ |
| 10645 |
*cost += !CONST_INT_P (XEXP (x, 1)); |
| 10646 |
} |
| 10647 |
} |
| 10648 |
else /* Rotates. */ |
| 10649 |
{ |
| 10650 |
*cost = COSTS_N_INSNS (2 + !CONST_INT_P (XEXP (x, 1))); |
| 10651 |
*cost += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); |
| 10652 |
if (speed_p) |
| 10653 |
{ |
| 10654 |
if (CONST_INT_P (XEXP (x, 1))) |
| 10655 |
*cost += (2 * extra_cost->alu.shift |
| 10656 |
+ extra_cost->alu.log_shift); |
| 10657 |
else |
| 10658 |
*cost += (extra_cost->alu.shift |
| 10659 |
+ extra_cost->alu.shift_reg |
| 10660 |
+ extra_cost->alu.log_shift_reg); |
| 10661 |
} |
| 10662 |
} |
| 10663 |
return true; |
| 10664 |
} |
| 10665 |
|
| 10666 |
*cost = LIBCALL_COST (2); |
| 10667 |
return false; |
| 10668 |
|
| 10669 |
case BSWAP: |
| 10670 |
if (arm_arch6) |
| 10671 |
{ |
| 10672 |
if (mode == SImode) |
| 10673 |
{ |
| 10674 |
if (speed_p) |
| 10675 |
*cost += extra_cost->alu.rev; |
| 10676 |
|
| 10677 |
return false; |
| 10678 |
} |
| 10679 |
} |
| 10680 |
else |
| 10681 |
{ |
| 10682 |
/* No rev instruction available. Look at arm_legacy_rev |
| 10683 |
and thumb_legacy_rev for the form of RTL used then. */ |
| 10684 |
if (TARGET_THUMB) |
| 10685 |
{ |
| 10686 |
*cost += COSTS_N_INSNS (9); |
| 10687 |
|
| 10688 |
if (speed_p) |
| 10689 |
{ |
| 10690 |
*cost += 6 * extra_cost->alu.shift; |
| 10691 |
*cost += 3 * extra_cost->alu.logical; |
| 10692 |
} |
| 10693 |
} |
| 10694 |
else |
| 10695 |
{ |
| 10696 |
*cost += COSTS_N_INSNS (4); |
| 10697 |
|
| 10698 |
if (speed_p) |
| 10699 |
{ |
| 10700 |
*cost += 2 * extra_cost->alu.shift; |
| 10701 |
*cost += extra_cost->alu.arith_shift; |
| 10702 |
*cost += 2 * extra_cost->alu.logical; |
| 10703 |
} |
| 10704 |
} |
| 10705 |
return true; |
| 10706 |
} |
| 10707 |
return false; |
| 10708 |
|
| 10709 |
case MINUS: |
| 10710 |
if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
| 10711 |
&& (mode == SFmode || !TARGET_VFP_SINGLE)) |
| 10712 |
{ |
| 10713 |
if (GET_CODE (XEXP (x, 0)) == MULT |
| 10714 |
|| GET_CODE (XEXP (x, 1)) == MULT) |
| 10715 |
{ |
| 10716 |
rtx mul_op0, mul_op1, sub_op; |
| 10717 |
|
| 10718 |
if (speed_p) |
| 10719 |
*cost += extra_cost->fp[mode != SFmode].mult_addsub; |
| 10720 |
|
| 10721 |
if (GET_CODE (XEXP (x, 0)) == MULT) |
| 10722 |
{ |
| 10723 |
mul_op0 = XEXP (XEXP (x, 0), 0); |
| 10724 |
mul_op1 = XEXP (XEXP (x, 0), 1); |
| 10725 |
sub_op = XEXP (x, 1); |
| 10726 |
} |
| 10727 |
else |
| 10728 |
{ |
| 10729 |
mul_op0 = XEXP (XEXP (x, 1), 0); |
| 10730 |
mul_op1 = XEXP (XEXP (x, 1), 1); |
| 10731 |
sub_op = XEXP (x, 0); |
| 10732 |
} |
| 10733 |
|
| 10734 |
/* The first operand of the multiply may be optionally |
| 10735 |
negated. */ |
| 10736 |
if (GET_CODE (mul_op0) == NEG) |
| 10737 |
mul_op0 = XEXP (mul_op0, 0); |
| 10738 |
|
| 10739 |
*cost += (rtx_cost (mul_op0, mode, code, 0, speed_p) |
| 10740 |
+ rtx_cost (mul_op1, mode, code, 0, speed_p) |
| 10741 |
+ rtx_cost (sub_op, mode, code, 0, speed_p)); |
| 10742 |
|
| 10743 |
return true; |
| 10744 |
} |
| 10745 |
|
| 10746 |
if (speed_p) |
| 10747 |
*cost += extra_cost->fp[mode != SFmode].addsub; |
| 10748 |
return false; |
| 10749 |
} |
| 10750 |
|
| 10751 |
if (mode == SImode) |
| 10752 |
{ |
| 10753 |
rtx shift_by_reg = NULL; |
| 10754 |
rtx shift_op; |
| 10755 |
rtx non_shift_op; |
| 10756 |
rtx op0 = XEXP (x, 0); |
| 10757 |
rtx op1 = XEXP (x, 1); |
| 10758 |
|
| 10759 |
/* Factor out any borrow operation. There's more than one way |
| 10760 |
of expressing this; try to recognize them all. */ |
| 10761 |
if (GET_CODE (op0) == MINUS) |
| 10762 |
{ |
| 10763 |
if (arm_borrow_operation (op1, SImode)) |
| 10764 |
{ |
| 10765 |
op1 = XEXP (op0, 1); |
| 10766 |
op0 = XEXP (op0, 0); |
| 10767 |
} |
| 10768 |
else if (arm_borrow_operation (XEXP (op0, 1), SImode)) |
| 10769 |
op0 = XEXP (op0, 0); |
| 10770 |
} |
| 10771 |
else if (GET_CODE (op1) == PLUS |
| 10772 |
&& arm_borrow_operation (XEXP (op1, 0), SImode)) |
| 10773 |
op1 = XEXP (op1, 0); |
| 10774 |
else if (GET_CODE (op0) == NEG |
| 10775 |
&& arm_borrow_operation (op1, SImode)) |
| 10776 |
{ |
| 10777 |
/* Negate with carry-in. For Thumb2 this is done with |
| 10778 |
SBC R, X, X lsl #1 (ie X - 2X - C) as Thumb lacks the |
| 10779 |
RSC instruction that exists in Arm mode. */ |
| 10780 |
if (speed_p) |
| 10781 |
*cost += (TARGET_THUMB2 |
| 10782 |
? extra_cost->alu.arith_shift |
| 10783 |
: extra_cost->alu.arith); |
| 10784 |
*cost += rtx_cost (XEXP (op0, 0), mode, MINUS, 0, speed_p); |
| 10785 |
return true; |
| 10786 |
} |
| 10787 |
/* (Carry_op - reg) can be done as RSC Rd, Rn, #1 on Arm. |
| 10788 |
Note we do mean ~borrow here. */ |
| 10789 |
else if (TARGET_ARM && arm_carry_operation (op0, SImode)) |
| 10790 |
{ |
| 10791 |
*cost += rtx_cost (op1, mode, code, 1, speed_p); |
| 10792 |
return true; |
| 10793 |
} |
| 10794 |
|
| 10795 |
shift_op = shifter_op_p (op0, &shift_by_reg); |
| 10796 |
if (shift_op == NULL) |
| 10797 |
{ |
| 10798 |
shift_op = shifter_op_p (op1, &shift_by_reg); |
| 10799 |
non_shift_op = op0; |
| 10800 |
} |
| 10801 |
else |
| 10802 |
non_shift_op = op1; |
| 10803 |
|
| 10804 |
if (shift_op != NULL) |
| 10805 |
{ |
| 10806 |
if (shift_by_reg != NULL) |
| 10807 |
{ |
| 10808 |
if (speed_p) |
| 10809 |
*cost += extra_cost->alu.arith_shift_reg; |
| 10810 |
*cost += rtx_cost (shift_by_reg, mode, code, 0, speed_p); |
| 10811 |
} |
| 10812 |
else if (speed_p) |
| 10813 |
*cost += extra_cost->alu.arith_shift; |
| 10814 |
|
| 10815 |
*cost += rtx_cost (shift_op, mode, code, 0, speed_p); |
| 10816 |
*cost += rtx_cost (non_shift_op, mode, code, 0, speed_p); |
| 10817 |
return true; |
| 10818 |
} |
| 10819 |
|
| 10820 |
if (arm_arch_thumb2 |
| 10821 |
&& GET_CODE (XEXP (x, 1)) == MULT) |
| 10822 |
{ |
| 10823 |
/* MLS. */ |
| 10824 |
if (speed_p) |
| 10825 |
*cost += extra_cost->mult[0].add; |
| 10826 |
*cost += rtx_cost (XEXP (x, 0), mode, MINUS, 0, speed_p); |
| 10827 |
*cost += rtx_cost (XEXP (XEXP (x, 1), 0), mode, MULT, 0, speed_p); |
| 10828 |
*cost += rtx_cost (XEXP (XEXP (x, 1), 1), mode, MULT, 1, speed_p); |
| 10829 |
return true; |
| 10830 |
} |
| 10831 |
|
| 10832 |
if (CONST_INT_P (op0)) |
| 10833 |
{ |
| 10834 |
int insns = arm_gen_constant (MINUS, SImode, NULL_RTX, |
| 10835 |
INTVAL (op0), NULL_RTX, |
| 10836 |
NULL_RTX, 1, 0); |
| 10837 |
*cost = COSTS_N_INSNS (insns); |
| 10838 |
if (speed_p) |
| 10839 |
*cost += insns * extra_cost->alu.arith; |
| 10840 |
*cost += rtx_cost (XEXP (x, 1), mode, code, 1, speed_p); |
| 10841 |
return true; |
| 10842 |
} |
| 10843 |
else if (speed_p) |
| 10844 |
*cost += extra_cost->alu.arith; |
| 10845 |
|
| 10846 |
/* Don't recurse as we don't want to cost any borrow that |
| 10847 |
we've stripped. */ |
| 10848 |
*cost += rtx_cost (op0, mode, MINUS, 0, speed_p); |
| 10849 |
*cost += rtx_cost (op1, mode, MINUS, 1, speed_p); |
| 10850 |
return true; |
| 10851 |
} |
| 10852 |
|
| 10853 |
if (GET_MODE_CLASS (mode) == MODE_INT |
| 10854 |
&& GET_MODE_SIZE (mode) < 4) |
| 10855 |
{ |
| 10856 |
rtx shift_op, shift_reg; |
| 10857 |
shift_reg = NULL; |
| 10858 |
|
| 10859 |
/* We check both sides of the MINUS for shifter operands since, |
| 10860 |
unlike PLUS, it's not commutative. */ |
| 10861 |
|
| 10862 |
HANDLE_NARROW_SHIFT_ARITH (MINUS, 0); |
| 10863 |
HANDLE_NARROW_SHIFT_ARITH (MINUS, 1); |
| 10864 |
|
| 10865 |
/* Slightly disparage, as we might need to widen the result. */ |
| 10866 |
*cost += 1; |
| 10867 |
if (speed_p) |
| 10868 |
*cost += extra_cost->alu.arith; |
| 10869 |
|
| 10870 |
if (CONST_INT_P (XEXP (x, 0))) |
| 10871 |
{ |
| 10872 |
*cost += rtx_cost (XEXP (x, 1), mode, code, 1, speed_p); |
| 10873 |
return true; |
| 10874 |
} |
| 10875 |
|
| 10876 |
return false; |
| 10877 |
} |
| 10878 |
|
| 10879 |
if (mode == DImode) |
| 10880 |
{ |
| 10881 |
*cost += COSTS_N_INSNS (1); |
| 10882 |
|
| 10883 |
if (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND) |
| 10884 |
{ |
| 10885 |
rtx op1 = XEXP (x, 1); |
| 10886 |
|
| 10887 |
if (speed_p) |
| 10888 |
*cost += 2 * extra_cost->alu.arith; |
| 10889 |
|
| 10890 |
if (GET_CODE (op1) == ZERO_EXTEND) |
| 10891 |
*cost += rtx_cost (XEXP (op1, 0), VOIDmode, ZERO_EXTEND, |
| 10892 |
0, speed_p); |
| 10893 |
else |
| 10894 |
*cost += rtx_cost (op1, mode, MINUS, 1, speed_p); |
| 10895 |
*cost += rtx_cost (XEXP (XEXP (x, 0), 0), VOIDmode, ZERO_EXTEND, |
| 10896 |
0, speed_p); |
| 10897 |
return true; |
| 10898 |
} |
| 10899 |
else if (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND) |
| 10900 |
{ |
| 10901 |
if (speed_p) |
| 10902 |
*cost += extra_cost->alu.arith + extra_cost->alu.arith_shift; |
| 10903 |
*cost += (rtx_cost (XEXP (XEXP (x, 0), 0), VOIDmode, SIGN_EXTEND, |
| 10904 |
0, speed_p) |
| 10905 |
+ rtx_cost (XEXP (x, 1), mode, MINUS, 1, speed_p)); |
| 10906 |
return true; |
| 10907 |
} |
| 10908 |
else if (GET_CODE (XEXP (x, 1)) == ZERO_EXTEND |
| 10909 |
|| GET_CODE (XEXP (x, 1)) == SIGN_EXTEND) |
| 10910 |
{ |
| 10911 |
if (speed_p) |
| 10912 |
*cost += (extra_cost->alu.arith |
| 10913 |
+ (GET_CODE (XEXP (x, 1)) == ZERO_EXTEND |
| 10914 |
? extra_cost->alu.arith |
| 10915 |
: extra_cost->alu.arith_shift)); |
| 10916 |
*cost += (rtx_cost (XEXP (x, 0), mode, MINUS, 0, speed_p) |
| 10917 |
+ rtx_cost (XEXP (XEXP (x, 1), 0), VOIDmode, |
| 10918 |
GET_CODE (XEXP (x, 1)), 0, speed_p)); |
| 10919 |
return true; |
| 10920 |
} |
| 10921 |
|
| 10922 |
if (speed_p) |
| 10923 |
*cost += 2 * extra_cost->alu.arith; |
| 10924 |
return false; |
| 10925 |
} |
| 10926 |
|
| 10927 |
/* Vector mode? */ |
| 10928 |
|
| 10929 |
*cost = LIBCALL_COST (2); |
| 10930 |
return false; |
| 10931 |
|
| 10932 |
case PLUS: |
| 10933 |
if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
| 10934 |
&& (mode == SFmode || !TARGET_VFP_SINGLE)) |
| 10935 |
{ |
| 10936 |
if (GET_CODE (XEXP (x, 0)) == MULT) |
| 10937 |
{ |
| 10938 |
rtx mul_op0, mul_op1, add_op; |
| 10939 |
|
| 10940 |
if (speed_p) |
| 10941 |
*cost += extra_cost->fp[mode != SFmode].mult_addsub; |
| 10942 |
|
| 10943 |
mul_op0 = XEXP (XEXP (x, 0), 0); |
| 10944 |
mul_op1 = XEXP (XEXP (x, 0), 1); |
| 10945 |
add_op = XEXP (x, 1); |
| 10946 |
|
| 10947 |
*cost += (rtx_cost (mul_op0, mode, code, 0, speed_p) |
| 10948 |
+ rtx_cost (mul_op1, mode, code, 0, speed_p) |
| 10949 |
+ rtx_cost (add_op, mode, code, 0, speed_p)); |
| 10950 |
|
| 10951 |
return true; |
| 10952 |
} |
| 10953 |
|
| 10954 |
if (speed_p) |
| 10955 |
*cost += extra_cost->fp[mode != SFmode].addsub; |
| 10956 |
return false; |
| 10957 |
} |
| 10958 |
else if (GET_MODE_CLASS (mode) == MODE_FLOAT) |
| 10959 |
{ |
| 10960 |
*cost = LIBCALL_COST (2); |
| 10961 |
return false; |
| 10962 |
} |
| 10963 |
|
| 10964 |
/* Narrow modes can be synthesized in SImode, but the range |
| 10965 |
of useful sub-operations is limited. Check for shift operations |
| 10966 |
on one of the operands. Only left shifts can be used in the |
| 10967 |
narrow modes. */ |
| 10968 |
if (GET_MODE_CLASS (mode) == MODE_INT |
| 10969 |
&& GET_MODE_SIZE (mode) < 4) |
| 10970 |
{ |
| 10971 |
rtx shift_op, shift_reg; |
| 10972 |
shift_reg = NULL; |
| 10973 |
|
| 10974 |
HANDLE_NARROW_SHIFT_ARITH (PLUS, 0); |
| 10975 |
|
| 10976 |
if (CONST_INT_P (XEXP (x, 1))) |
| 10977 |
{ |
| 10978 |
int insns = arm_gen_constant (PLUS, SImode, NULL_RTX, |
| 10979 |
INTVAL (XEXP (x, 1)), NULL_RTX, |
| 10980 |
NULL_RTX, 1, 0); |
| 10981 |
*cost = COSTS_N_INSNS (insns); |
| 10982 |
if (speed_p) |
| 10983 |
*cost += insns * extra_cost->alu.arith; |
| 10984 |
/* Slightly penalize a narrow operation as the result may |
| 10985 |
need widening. */ |
| 10986 |
*cost += 1 + rtx_cost (XEXP (x, 0), mode, PLUS, 0, speed_p); |
| 10987 |
return true; |
| 10988 |
} |
| 10989 |
|
| 10990 |
/* Slightly penalize a narrow operation as the result may |
| 10991 |
need widening. */ |
| 10992 |
*cost += 1; |
| 10993 |
if (speed_p) |
| 10994 |
*cost += extra_cost->alu.arith; |
| 10995 |
|
| 10996 |
return false; |
| 10997 |
} |
| 10998 |
|
| 10999 |
if (mode == SImode) |
| 11000 |
{ |
| 11001 |
rtx shift_op, shift_reg; |
| 11002 |
|
| 11003 |
if (TARGET_INT_SIMD |
| 11004 |
&& (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND |
| 11005 |
|| GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)) |
| 11006 |
{ |
| 11007 |
/* UXTA[BH] or SXTA[BH]. */ |
| 11008 |
if (speed_p) |
| 11009 |
*cost += extra_cost->alu.extend_arith; |
| 11010 |
*cost += (rtx_cost (XEXP (XEXP (x, 0), 0), VOIDmode, ZERO_EXTEND, |
| 11011 |
0, speed_p) |
| 11012 |
+ rtx_cost (XEXP (x, 1), mode, PLUS, 0, speed_p)); |
| 11013 |
return true; |
| 11014 |
} |
| 11015 |
|
| 11016 |
rtx op0 = XEXP (x, 0); |
| 11017 |
rtx op1 = XEXP (x, 1); |
| 11018 |
|
| 11019 |
/* Handle a side effect of adding in the carry to an addition. */ |
| 11020 |
if (GET_CODE (op0) == PLUS |
| 11021 |
&& arm_carry_operation (op1, mode)) |
| 11022 |
{ |
| 11023 |
op1 = XEXP (op0, 1); |
| 11024 |
op0 = XEXP (op0, 0); |
| 11025 |
} |
| 11026 |
else if (GET_CODE (op1) == PLUS |
| 11027 |
&& arm_carry_operation (op0, mode)) |
| 11028 |
{ |
| 11029 |
op0 = XEXP (op1, 0); |
| 11030 |
op1 = XEXP (op1, 1); |
| 11031 |
} |
| 11032 |
else if (GET_CODE (op0) == PLUS) |
| 11033 |
{ |
| 11034 |
op0 = strip_carry_operation (op0); |
| 11035 |
if (swap_commutative_operands_p (op0, op1)) |
| 11036 |
std::swap (op0, op1); |
| 11037 |
} |
| 11038 |
|
| 11039 |
if (arm_carry_operation (op0, mode)) |
| 11040 |
{ |
| 11041 |
/* Adding the carry to a register is a canonicalization of |
| 11042 |
adding 0 to the register plus the carry. */ |
| 11043 |
if (speed_p) |
| 11044 |
*cost += extra_cost->alu.arith; |
| 11045 |
*cost += rtx_cost (op1, mode, PLUS, 1, speed_p); |
| 11046 |
return true; |
| 11047 |
} |
| 11048 |
|
| 11049 |
shift_reg = NULL; |
| 11050 |
shift_op = shifter_op_p (op0, &shift_reg); |
| 11051 |
if (shift_op != NULL) |
| 11052 |
{ |
| 11053 |
if (shift_reg) |
| 11054 |
{ |
| 11055 |
if (speed_p) |
| 11056 |
*cost += extra_cost->alu.arith_shift_reg; |
| 11057 |
*cost += rtx_cost (shift_reg, mode, ASHIFT, 1, speed_p); |
| 11058 |
} |
| 11059 |
else if (speed_p) |
| 11060 |
*cost += extra_cost->alu.arith_shift; |
| 11061 |
|
| 11062 |
*cost += (rtx_cost (shift_op, mode, ASHIFT, 0, speed_p) |
| 11063 |
+ rtx_cost (op1, mode, PLUS, 1, speed_p)); |
| 11064 |
return true; |
| 11065 |
} |
| 11066 |
|
| 11067 |
if (GET_CODE (op0) == MULT) |
| 11068 |
{ |
| 11069 |
rtx mul_op = op0; |
| 11070 |
|
| 11071 |
if (TARGET_DSP_MULTIPLY |
| 11072 |
&& ((GET_CODE (XEXP (mul_op, 0)) == SIGN_EXTEND |
| 11073 |
&& (GET_CODE (XEXP (mul_op, 1)) == SIGN_EXTEND |
| 11074 |
|| (GET_CODE (XEXP (mul_op, 1)) == ASHIFTRT |
| 11075 |
&& CONST_INT_P (XEXP (XEXP (mul_op, 1), 1)) |
| 11076 |
&& INTVAL (XEXP (XEXP (mul_op, 1), 1)) == 16))) |
| 11077 |
|| (GET_CODE (XEXP (mul_op, 0)) == ASHIFTRT |
| 11078 |
&& CONST_INT_P (XEXP (XEXP (mul_op, 0), 1)) |
| 11079 |
&& INTVAL (XEXP (XEXP (mul_op, 0), 1)) == 16 |
| 11080 |
&& (GET_CODE (XEXP (mul_op, 1)) == SIGN_EXTEND |
| 11081 |
|| (GET_CODE (XEXP (mul_op, 1)) == ASHIFTRT |
| 11082 |
&& CONST_INT_P (XEXP (XEXP (mul_op, 1), 1)) |
| 11083 |
&& (INTVAL (XEXP (XEXP (mul_op, 1), 1)) |
| 11084 |
== 16)))))) |
| 11085 |
{ |
| 11086 |
/* SMLA[BT][BT]. */ |
| 11087 |
if (speed_p) |
| 11088 |
*cost += extra_cost->mult[0].extend_add; |
| 11089 |
*cost += (rtx_cost (XEXP (XEXP (mul_op, 0), 0), mode, |
| 11090 |
SIGN_EXTEND, 0, speed_p) |
| 11091 |
+ rtx_cost (XEXP (XEXP (mul_op, 1), 0), mode, |
| 11092 |
SIGN_EXTEND, 0, speed_p) |
| 11093 |
+ rtx_cost (op1, mode, PLUS, 1, speed_p)); |
| 11094 |
return true; |
| 11095 |
} |
| 11096 |
|
| 11097 |
if (speed_p) |
| 11098 |
*cost += extra_cost->mult[0].add; |
| 11099 |
*cost += (rtx_cost (XEXP (mul_op, 0), mode, MULT, 0, speed_p) |
| 11100 |
+ rtx_cost (XEXP (mul_op, 1), mode, MULT, 1, speed_p) |
| 11101 |
+ rtx_cost (op1, mode, PLUS, 1, speed_p)); |
| 11102 |
return true; |
| 11103 |
} |
| 11104 |
|
| 11105 |
if (CONST_INT_P (op1)) |
| 11106 |
{ |
| 11107 |
int insns = arm_gen_constant (PLUS, SImode, NULL_RTX, |
| 11108 |
INTVAL (op1), NULL_RTX, |
| 11109 |
NULL_RTX, 1, 0); |
| 11110 |
*cost = COSTS_N_INSNS (insns); |
| 11111 |
if (speed_p) |
| 11112 |
*cost += insns * extra_cost->alu.arith; |
| 11113 |
*cost += rtx_cost (op0, mode, PLUS, 0, speed_p); |
| 11114 |
return true; |
| 11115 |
} |
| 11116 |
|
| 11117 |
if (speed_p) |
| 11118 |
*cost += extra_cost->alu.arith; |
| 11119 |
|
| 11120 |
/* Don't recurse here because we want to test the operands |
| 11121 |
without any carry operation. */ |
| 11122 |
*cost += rtx_cost (op0, mode, PLUS, 0, speed_p); |
| 11123 |
*cost += rtx_cost (op1, mode, PLUS, 1, speed_p); |
| 11124 |
return true; |
| 11125 |
} |
| 11126 |
|
| 11127 |
if (mode == DImode) |
| 11128 |
{ |
| 11129 |
if (GET_CODE (XEXP (x, 0)) == MULT |
| 11130 |
&& ((GET_CODE (XEXP (XEXP (x, 0), 0)) == ZERO_EXTEND |
| 11131 |
&& GET_CODE (XEXP (XEXP (x, 0), 1)) == ZERO_EXTEND) |
| 11132 |
|| (GET_CODE (XEXP (XEXP (x, 0), 0)) == SIGN_EXTEND |
| 11133 |
&& GET_CODE (XEXP (XEXP (x, 0), 1)) == SIGN_EXTEND))) |
| 11134 |
{ |
| 11135 |
if (speed_p) |
| 11136 |
*cost += extra_cost->mult[1].extend_add; |
| 11137 |
*cost += (rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0), mode, |
| 11138 |
ZERO_EXTEND, 0, speed_p) |
| 11139 |
+ rtx_cost (XEXP (XEXP (XEXP (x, 0), 1), 0), mode, |
| 11140 |
ZERO_EXTEND, 0, speed_p) |
| 11141 |
+ rtx_cost (XEXP (x, 1), mode, PLUS, 1, speed_p)); |
| 11142 |
return true; |
| 11143 |
} |
| 11144 |
|
| 11145 |
*cost += COSTS_N_INSNS (1); |
| 11146 |
|
| 11147 |
if (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND |
| 11148 |
|| GET_CODE (XEXP (x, 0)) == SIGN_EXTEND) |
| 11149 |
{ |
| 11150 |
if (speed_p) |
| 11151 |
*cost += (extra_cost->alu.arith |
| 11152 |
+ (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND |
| 11153 |
? extra_cost->alu.arith |
| 11154 |
: extra_cost->alu.arith_shift)); |
| 11155 |
|
| 11156 |
*cost += (rtx_cost (XEXP (XEXP (x, 0), 0), VOIDmode, ZERO_EXTEND, |
| 11157 |
0, speed_p) |
| 11158 |
+ rtx_cost (XEXP (x, 1), mode, PLUS, 1, speed_p)); |
| 11159 |
return true; |
| 11160 |
} |
| 11161 |
|
| 11162 |
if (speed_p) |
| 11163 |
*cost += 2 * extra_cost->alu.arith; |
| 11164 |
return false; |
| 11165 |
} |
| 11166 |
|
| 11167 |
/* Vector mode? */ |
| 11168 |
*cost = LIBCALL_COST (2); |
| 11169 |
return false; |
| 11170 |
case IOR: |
| 11171 |
{ |
| 11172 |
rtx sub0, sub1; |
| 11173 |
if (mode == SImode && arm_arch6 && aarch_rev16_p (x)) |
| 11174 |
{ |
| 11175 |
if (speed_p) |
| 11176 |
*cost += extra_cost->alu.rev; |
| 11177 |
|
| 11178 |
return true; |
| 11179 |
} |
| 11180 |
else if (mode == SImode && arm_arch_thumb2 |
| 11181 |
&& arm_bfi_p (x, &sub0, &sub1)) |
| 11182 |
{ |
| 11183 |
*cost += rtx_cost (sub0, mode, ZERO_EXTRACT, 1, speed_p); |
| 11184 |
*cost += rtx_cost (sub1, mode, ZERO_EXTRACT, 0, speed_p); |
| 11185 |
if (speed_p) |
| 11186 |
*cost += extra_cost->alu.bfi; |
| 11187 |
|
| 11188 |
return true; |
| 11189 |
} |
| 11190 |
} |
| 11191 |
|
| 11192 |
/* Fall through. */ |
| 11193 |
case AND: case XOR: |
| 11194 |
if (mode == SImode) |
| 11195 |
{ |
| 11196 |
enum rtx_code subcode = GET_CODE (XEXP (x, 0)); |
| 11197 |
rtx op0 = XEXP (x, 0); |
| 11198 |
rtx shift_op, shift_reg; |
| 11199 |
|
| 11200 |
if (subcode == NOT |
| 11201 |
&& (code == AND |
| 11202 |
|| (code == IOR && TARGET_THUMB2))) |
| 11203 |
op0 = XEXP (op0, 0); |
| 11204 |
|
| 11205 |
shift_reg = NULL; |
| 11206 |
shift_op = shifter_op_p (op0, &shift_reg); |
| 11207 |
if (shift_op != NULL) |
| 11208 |
{ |
| 11209 |
if (shift_reg) |
| 11210 |
{ |
| 11211 |
if (speed_p) |
| 11212 |
*cost += extra_cost->alu.log_shift_reg; |
| 11213 |
*cost += rtx_cost (shift_reg, mode, ASHIFT, 1, speed_p); |
| 11214 |
} |
| 11215 |
else if (speed_p) |
| 11216 |
*cost += extra_cost->alu.log_shift; |
| 11217 |
|
| 11218 |
*cost += (rtx_cost (shift_op, mode, ASHIFT, 0, speed_p) |
| 11219 |
+ rtx_cost (XEXP (x, 1), mode, code, 1, speed_p)); |
| 11220 |
return true; |
| 11221 |
} |
| 11222 |
|
| 11223 |
if (CONST_INT_P (XEXP (x, 1))) |
| 11224 |
{ |
| 11225 |
int insns = arm_gen_constant (code, SImode, NULL_RTX, |
| 11226 |
INTVAL (XEXP (x, 1)), NULL_RTX, |
| 11227 |
NULL_RTX, 1, 0); |
| 11228 |
|
| 11229 |
*cost = COSTS_N_INSNS (insns); |
| 11230 |
if (speed_p) |
| 11231 |
*cost += insns * extra_cost->alu.logical; |
| 11232 |
*cost += rtx_cost (op0, mode, code, 0, speed_p); |
| 11233 |
return true; |
| 11234 |
} |
| 11235 |
|
| 11236 |
if (speed_p) |
| 11237 |
*cost += extra_cost->alu.logical; |
| 11238 |
*cost += (rtx_cost (op0, mode, code, 0, speed_p) |
| 11239 |
+ rtx_cost (XEXP (x, 1), mode, code, 1, speed_p)); |
| 11240 |
return true; |
| 11241 |
} |
| 11242 |
|
| 11243 |
if (mode == DImode) |
| 11244 |
{ |
| 11245 |
rtx op0 = XEXP (x, 0); |
| 11246 |
enum rtx_code subcode = GET_CODE (op0); |
| 11247 |
|
| 11248 |
*cost += COSTS_N_INSNS (1); |
| 11249 |
|
| 11250 |
if (subcode == NOT |
| 11251 |
&& (code == AND |
| 11252 |
|| (code == IOR && TARGET_THUMB2))) |
| 11253 |
op0 = XEXP (op0, 0); |
| 11254 |
|
| 11255 |
if (GET_CODE (op0) == ZERO_EXTEND) |
| 11256 |
{ |
| 11257 |
if (speed_p) |
| 11258 |
*cost += 2 * extra_cost->alu.logical; |
| 11259 |
|
| 11260 |
*cost += (rtx_cost (XEXP (op0, 0), VOIDmode, ZERO_EXTEND, |
| 11261 |
0, speed_p) |
| 11262 |
+ rtx_cost (XEXP (x, 1), mode, code, 0, speed_p)); |
| 11263 |
return true; |
| 11264 |
} |
| 11265 |
else if (GET_CODE (op0) == SIGN_EXTEND) |
| 11266 |
{ |
| 11267 |
if (speed_p) |
| 11268 |
*cost += extra_cost->alu.logical + extra_cost->alu.log_shift; |
| 11269 |
|
| 11270 |
*cost += (rtx_cost (XEXP (op0, 0), VOIDmode, SIGN_EXTEND, |
| 11271 |
0, speed_p) |
| 11272 |
+ rtx_cost (XEXP (x, 1), mode, code, 0, speed_p)); |
| 11273 |
return true; |
| 11274 |
} |
| 11275 |
|
| 11276 |
if (speed_p) |
| 11277 |
*cost += 2 * extra_cost->alu.logical; |
| 11278 |
|
| 11279 |
return true; |
| 11280 |
} |
| 11281 |
/* Vector mode? */ |
| 11282 |
|
| 11283 |
*cost = LIBCALL_COST (2); |
| 11284 |
return false; |
| 11285 |
|
| 11286 |
case MULT: |
| 11287 |
if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
| 11288 |
&& (mode == SFmode || !TARGET_VFP_SINGLE)) |
| 11289 |
{ |
| 11290 |
rtx op0 = XEXP (x, 0); |
| 11291 |
|
| 11292 |
if (GET_CODE (op0) == NEG && !flag_rounding_math) |
| 11293 |
op0 = XEXP (op0, 0); |
| 11294 |
|
| 11295 |
if (speed_p) |
| 11296 |
*cost += extra_cost->fp[mode != SFmode].mult; |
| 11297 |
|
| 11298 |
*cost += (rtx_cost (op0, mode, MULT, 0, speed_p) |
| 11299 |
+ rtx_cost (XEXP (x, 1), mode, MULT, 1, speed_p)); |
| 11300 |
return true; |
| 11301 |
} |
| 11302 |
else if (GET_MODE_CLASS (mode) == MODE_FLOAT) |
| 11303 |
{ |
| 11304 |
*cost = LIBCALL_COST (2); |
| 11305 |
return false; |
| 11306 |
} |
| 11307 |
|
| 11308 |
if (mode == SImode) |
| 11309 |
{ |
| 11310 |
if (TARGET_DSP_MULTIPLY |
| 11311 |
&& ((GET_CODE (XEXP (x, 0)) == SIGN_EXTEND |
| 11312 |
&& (GET_CODE (XEXP (x, 1)) == SIGN_EXTEND |
| 11313 |
|| (GET_CODE (XEXP (x, 1)) == ASHIFTRT |
| 11314 |
&& CONST_INT_P (XEXP (XEXP (x, 1), 1)) |
| 11315 |
&& INTVAL (XEXP (XEXP (x, 1), 1)) == 16))) |
| 11316 |
|| (GET_CODE (XEXP (x, 0)) == ASHIFTRT |
| 11317 |
&& CONST_INT_P (XEXP (XEXP (x, 0), 1)) |
| 11318 |
&& INTVAL (XEXP (XEXP (x, 0), 1)) == 16 |
| 11319 |
&& (GET_CODE (XEXP (x, 1)) == SIGN_EXTEND |
| 11320 |
|| (GET_CODE (XEXP (x, 1)) == ASHIFTRT |
| 11321 |
&& CONST_INT_P (XEXP (XEXP (x, 1), 1)) |
| 11322 |
&& (INTVAL (XEXP (XEXP (x, 1), 1)) |
| 11323 |
== 16)))))) |
| 11324 |
{ |
| 11325 |
/* SMUL[TB][TB]. */ |
| 11326 |
if (speed_p) |
| 11327 |
*cost += extra_cost->mult[0].extend; |
| 11328 |
*cost += rtx_cost (XEXP (XEXP (x, 0), 0), mode, |
| 11329 |
SIGN_EXTEND, 0, speed_p); |
| 11330 |
*cost += rtx_cost (XEXP (XEXP (x, 1), 0), mode, |
| 11331 |
SIGN_EXTEND, 1, speed_p); |
| 11332 |
return true; |
| 11333 |
} |
| 11334 |
if (speed_p) |
| 11335 |
*cost += extra_cost->mult[0].simple; |
| 11336 |
return false; |
| 11337 |
} |
| 11338 |
|
| 11339 |
if (mode == DImode) |
| 11340 |
{ |
| 11341 |
if ((GET_CODE (XEXP (x, 0)) == ZERO_EXTEND |
| 11342 |
&& GET_CODE (XEXP (x, 1)) == ZERO_EXTEND) |
| 11343 |
|| (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND |
| 11344 |
&& GET_CODE (XEXP (x, 1)) == SIGN_EXTEND)) |
| 11345 |
{ |
| 11346 |
if (speed_p) |
| 11347 |
*cost += extra_cost->mult[1].extend; |
| 11348 |
*cost += (rtx_cost (XEXP (XEXP (x, 0), 0), VOIDmode, |
| 11349 |
ZERO_EXTEND, 0, speed_p) |
| 11350 |
+ rtx_cost (XEXP (XEXP (x, 1), 0), VOIDmode, |
| 11351 |
ZERO_EXTEND, 0, speed_p)); |
| 11352 |
return true; |
| 11353 |
} |
| 11354 |
|
| 11355 |
*cost = LIBCALL_COST (2); |
| 11356 |
return false; |
| 11357 |
} |
| 11358 |
|
| 11359 |
/* Vector mode? */ |
| 11360 |
*cost = LIBCALL_COST (2); |
| 11361 |
return false; |
| 11362 |
|
| 11363 |
case NEG: |
| 11364 |
if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
| 11365 |
&& (mode == SFmode || !TARGET_VFP_SINGLE)) |
| 11366 |
{ |
| 11367 |
if (GET_CODE (XEXP (x, 0)) == MULT) |
| 11368 |
{ |
| 11369 |
/* VNMUL. */ |
| 11370 |
*cost = rtx_cost (XEXP (x, 0), mode, NEG, 0, speed_p); |
| 11371 |
return true; |
| 11372 |
} |
| 11373 |
|
| 11374 |
if (speed_p) |
| 11375 |
*cost += extra_cost->fp[mode != SFmode].neg; |
| 11376 |
|
| 11377 |
return false; |
| 11378 |
} |
| 11379 |
else if (GET_MODE_CLASS (mode) == MODE_FLOAT) |
| 11380 |
{ |
| 11381 |
*cost = LIBCALL_COST (1); |
| 11382 |
return false; |
| 11383 |
} |
| 11384 |
|
| 11385 |
if (mode == SImode) |
| 11386 |
{ |
| 11387 |
if (GET_CODE (XEXP (x, 0)) == ABS) |
| 11388 |
{ |
| 11389 |
*cost += COSTS_N_INSNS (1); |
| 11390 |
/* Assume the non-flag-changing variant. */ |
| 11391 |
if (speed_p) |
| 11392 |
*cost += (extra_cost->alu.log_shift |
| 11393 |
+ extra_cost->alu.arith_shift); |
| 11394 |
*cost += rtx_cost (XEXP (XEXP (x, 0), 0), mode, ABS, 0, speed_p); |
| 11395 |
return true; |
| 11396 |
} |
| 11397 |
|
| 11398 |
if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_COMPARE |
| 11399 |
|| GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_COMM_COMPARE) |
| 11400 |
{ |
| 11401 |
*cost += COSTS_N_INSNS (1); |
| 11402 |
/* No extra cost for MOV imm and MVN imm. */ |
| 11403 |
/* If the comparison op is using the flags, there's no further |
| 11404 |
cost, otherwise we need to add the cost of the comparison. */ |
| 11405 |
if (!(REG_P (XEXP (XEXP (x, 0), 0)) |
| 11406 |
&& REGNO (XEXP (XEXP (x, 0), 0)) == CC_REGNUM |
| 11407 |
&& XEXP (XEXP (x, 0), 1) == const0_rtx)) |
| 11408 |
{ |
| 11409 |
mode = GET_MODE (XEXP (XEXP (x, 0), 0)); |
| 11410 |
*cost += (COSTS_N_INSNS (1) |
| 11411 |
+ rtx_cost (XEXP (XEXP (x, 0), 0), mode, COMPARE, |
| 11412 |
0, speed_p) |
| 11413 |
+ rtx_cost (XEXP (XEXP (x, 0), 1), mode, COMPARE, |
| 11414 |
1, speed_p)); |
| 11415 |
if (speed_p) |
| 11416 |
*cost += extra_cost->alu.arith; |
| 11417 |
} |
| 11418 |
return true; |
| 11419 |
} |
| 11420 |
|
| 11421 |
if (speed_p) |
| 11422 |
*cost += extra_cost->alu.arith; |
| 11423 |
return false; |
| 11424 |
} |
| 11425 |
|
| 11426 |
if (GET_MODE_CLASS (mode) == MODE_INT |
| 11427 |
&& GET_MODE_SIZE (mode) < 4) |
| 11428 |
{ |
| 11429 |
/* Slightly disparage, as we might need an extend operation. */ |
| 11430 |
*cost += 1; |
| 11431 |
if (speed_p) |
| 11432 |
*cost += extra_cost->alu.arith; |
| 11433 |
return false; |
| 11434 |
} |
| 11435 |
|
| 11436 |
if (mode == DImode) |
| 11437 |
{ |
| 11438 |
*cost += COSTS_N_INSNS (1); |
| 11439 |
if (speed_p) |
| 11440 |
*cost += 2 * extra_cost->alu.arith; |
| 11441 |
return false; |
| 11442 |
} |
| 11443 |
|
| 11444 |
/* Vector mode? */ |
| 11445 |
*cost = LIBCALL_COST (1); |
| 11446 |
return false; |
| 11447 |
|
| 11448 |
case NOT: |
| 11449 |
if (mode == SImode) |
| 11450 |
{ |
| 11451 |
rtx shift_op; |
| 11452 |
rtx shift_reg = NULL; |
| 11453 |
|
| 11454 |
shift_op = shifter_op_p (XEXP (x, 0), &shift_reg); |
| 11455 |
|
| 11456 |
if (shift_op) |
| 11457 |
{ |
| 11458 |
if (shift_reg != NULL) |
| 11459 |
{ |
| 11460 |
if (speed_p) |
| 11461 |
*cost += extra_cost->alu.log_shift_reg; |
| 11462 |
*cost += rtx_cost (shift_reg, mode, ASHIFT, 1, speed_p); |
| 11463 |
} |
| 11464 |
else if (speed_p) |
| 11465 |
*cost += extra_cost->alu.log_shift; |
| 11466 |
*cost += rtx_cost (shift_op, mode, ASHIFT, 0, speed_p); |
| 11467 |
return true; |
| 11468 |
} |
| 11469 |
|
| 11470 |
if (speed_p) |
| 11471 |
*cost += extra_cost->alu.logical; |
| 11472 |
return false; |
| 11473 |
} |
| 11474 |
if (mode == DImode) |
| 11475 |
{ |
| 11476 |
*cost += COSTS_N_INSNS (1); |
| 11477 |
return false; |
| 11478 |
} |
| 11479 |
|
| 11480 |
/* Vector mode? */ |
| 11481 |
|
| 11482 |
*cost += LIBCALL_COST (1); |
| 11483 |
return false; |
| 11484 |
|
| 11485 |
case IF_THEN_ELSE: |
| 11486 |
{ |
| 11487 |
if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC) |
| 11488 |
{ |
| 11489 |
*cost += COSTS_N_INSNS (3); |
| 11490 |
return true; |
| 11491 |
} |
| 11492 |
int op1cost = rtx_cost (XEXP (x, 1), mode, SET, 1, speed_p); |
| 11493 |
int op2cost = rtx_cost (XEXP (x, 2), mode, SET, 1, speed_p); |
| 11494 |
|
| 11495 |
*cost = rtx_cost (XEXP (x, 0), mode, IF_THEN_ELSE, 0, speed_p); |
| 11496 |
/* Assume that if one arm of the if_then_else is a register, |
| 11497 |
that it will be tied with the result and eliminate the |
| 11498 |
conditional insn. */ |
| 11499 |
if (REG_P (XEXP (x, 1))) |
| 11500 |
*cost += op2cost; |
| 11501 |
else if (REG_P (XEXP (x, 2))) |
| 11502 |
*cost += op1cost; |
| 11503 |
else |
| 11504 |
{ |
| 11505 |
if (speed_p) |
| 11506 |
{ |
| 11507 |
if (extra_cost->alu.non_exec_costs_exec) |
| 11508 |
*cost += op1cost + op2cost + extra_cost->alu.non_exec; |
| 11509 |
else |
| 11510 |
*cost += MAX (op1cost, op2cost) + extra_cost->alu.non_exec; |
| 11511 |
} |
| 11512 |
else |
| 11513 |
*cost += op1cost + op2cost; |
| 11514 |
} |
| 11515 |
} |
| 11516 |
return true; |
| 11517 |
|
| 11518 |
case COMPARE: |
| 11519 |
if (cc_register (XEXP (x, 0), VOIDmode) && XEXP (x, 1) == const0_rtx) |
| 11520 |
*cost = 0; |
| 11521 |
else |
| 11522 |
{ |
| 11523 |
machine_mode op0mode; |
| 11524 |
/* We'll mostly assume that the cost of a compare is the cost of the |
| 11525 |
LHS. However, there are some notable exceptions. */ |
| 11526 |
|
| 11527 |
/* Floating point compares are never done as side-effects. */ |
| 11528 |
op0mode = GET_MODE (XEXP (x, 0)); |
| 11529 |
if (TARGET_HARD_FLOAT && GET_MODE_CLASS (op0mode) == MODE_FLOAT |
| 11530 |
&& (op0mode == SFmode || !TARGET_VFP_SINGLE)) |
| 11531 |
{ |
| 11532 |
if (speed_p) |
| 11533 |
*cost += extra_cost->fp[op0mode != SFmode].compare; |
| 11534 |
|
| 11535 |
if (XEXP (x, 1) == CONST0_RTX (op0mode)) |
| 11536 |
{ |
| 11537 |
*cost += rtx_cost (XEXP (x, 0), op0mode, code, 0, speed_p); |
| 11538 |
return true; |
| 11539 |
} |
| 11540 |
|
| 11541 |
return false; |
| 11542 |
} |
| 11543 |
else if (GET_MODE_CLASS (op0mode) == MODE_FLOAT) |
| 11544 |
{ |
| 11545 |
*cost = LIBCALL_COST (2); |
| 11546 |
return false; |
| 11547 |
} |
| 11548 |
|
| 11549 |
/* DImode compares normally take two insns. */ |
| 11550 |
if (op0mode == DImode) |
| 11551 |
{ |
| 11552 |
*cost += COSTS_N_INSNS (1); |
| 11553 |
if (speed_p) |
| 11554 |
*cost += 2 * extra_cost->alu.arith; |
| 11555 |
return false; |
| 11556 |
} |
| 11557 |
|
| 11558 |
if (op0mode == SImode) |
| 11559 |
{ |
| 11560 |
rtx shift_op; |
| 11561 |
rtx shift_reg; |
| 11562 |
|
| 11563 |
if (XEXP (x, 1) == const0_rtx |
| 11564 |
&& !(REG_P (XEXP (x, 0)) |
| 11565 |
|| (GET_CODE (XEXP (x, 0)) == SUBREG |
| 11566 |
&& REG_P (SUBREG_REG (XEXP (x, 0)))))) |
| 11567 |
{ |
| 11568 |
*cost = rtx_cost (XEXP (x, 0), op0mode, COMPARE, 0, speed_p); |
| 11569 |
|
| 11570 |
/* Multiply operations that set the flags are often |
| 11571 |
significantly more expensive. */ |
| 11572 |
if (speed_p |
| 11573 |
&& GET_CODE (XEXP (x, 0)) == MULT |
| 11574 |
&& !power_of_two_operand (XEXP (XEXP (x, 0), 1), mode)) |
| 11575 |
*cost += extra_cost->mult[0].flag_setting; |
| 11576 |
|
| 11577 |
if (speed_p |
| 11578 |
&& GET_CODE (XEXP (x, 0)) == PLUS |
| 11579 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT |
| 11580 |
&& !power_of_two_operand (XEXP (XEXP (XEXP (x, 0), |
| 11581 |
0), 1), mode)) |
| 11582 |
*cost += extra_cost->mult[0].flag_setting; |
| 11583 |
return true; |
| 11584 |
} |
| 11585 |
|
| 11586 |
shift_reg = NULL; |
| 11587 |
shift_op = shifter_op_p (XEXP (x, 0), &shift_reg); |
| 11588 |
if (shift_op != NULL) |
| 11589 |
{ |
| 11590 |
if (shift_reg != NULL) |
| 11591 |
{ |
| 11592 |
*cost += rtx_cost (shift_reg, op0mode, ASHIFT, |
| 11593 |
1, speed_p); |
| 11594 |
if (speed_p) |
| 11595 |
*cost += extra_cost->alu.arith_shift_reg; |
| 11596 |
} |
| 11597 |
else if (speed_p) |
| 11598 |
*cost += extra_cost->alu.arith_shift; |
| 11599 |
*cost += rtx_cost (shift_op, op0mode, ASHIFT, 0, speed_p); |
| 11600 |
*cost += rtx_cost (XEXP (x, 1), op0mode, COMPARE, 1, speed_p); |
| 11601 |
return true; |
| 11602 |
} |
| 11603 |
|
| 11604 |
if (speed_p) |
| 11605 |
*cost += extra_cost->alu.arith; |
| 11606 |
if (CONST_INT_P (XEXP (x, 1)) |
| 11607 |
&& const_ok_for_op (INTVAL (XEXP (x, 1)), COMPARE)) |
| 11608 |
{ |
| 11609 |
*cost += rtx_cost (XEXP (x, 0), op0mode, COMPARE, 0, speed_p); |
| 11610 |
return true; |
| 11611 |
} |
| 11612 |
return false; |
| 11613 |
} |
| 11614 |
|
| 11615 |
/* Vector mode? */ |
| 11616 |
|
| 11617 |
*cost = LIBCALL_COST (2); |
| 11618 |
return false; |
| 11619 |
} |
| 11620 |
return true; |
| 11621 |
|
| 11622 |
case EQ: |
| 11623 |
case GE: |
| 11624 |
case GT: |
| 11625 |
case LE: |
| 11626 |
case LT: |
| 11627 |
/* Neon has special instructions when comparing with 0 (vceq, vcge, vcgt, |
| 11628 |
vcle and vclt). */ |
| 11629 |
if (TARGET_NEON |
| 11630 |
&& TARGET_HARD_FLOAT |
| 11631 |
&& (VALID_NEON_DREG_MODE (mode) || VALID_NEON_QREG_MODE (mode)) |
| 11632 |
&& (XEXP (x, 1) == CONST0_RTX (mode))) |
| 11633 |
{ |
| 11634 |
*cost = 0; |
| 11635 |
return true; |
| 11636 |
} |
| 11637 |
|
| 11638 |
/* Fall through. */ |
| 11639 |
case NE: |
| 11640 |
case LTU: |
| 11641 |
case LEU: |
| 11642 |
case GEU: |
| 11643 |
case GTU: |
| 11644 |
case ORDERED: |
| 11645 |
case UNORDERED: |
| 11646 |
case UNEQ: |
| 11647 |
case UNLE: |
| 11648 |
case UNLT: |
| 11649 |
case UNGE: |
| 11650 |
case UNGT: |
| 11651 |
case LTGT: |
| 11652 |
if (outer_code == SET) |
| 11653 |
{ |
| 11654 |
/* Is it a store-flag operation? */ |
| 11655 |
if (REG_P (XEXP (x, 0)) && REGNO (XEXP (x, 0)) == CC_REGNUM |
| 11656 |
&& XEXP (x, 1) == const0_rtx) |
| 11657 |
{ |
| 11658 |
/* Thumb also needs an IT insn. */ |
| 11659 |
*cost += COSTS_N_INSNS (TARGET_THUMB ? 2 : 1); |
| 11660 |
return true; |
| 11661 |
} |
| 11662 |
if (XEXP (x, 1) == const0_rtx) |
| 11663 |
{ |
| 11664 |
switch (code) |
| 11665 |
{ |
| 11666 |
case LT: |
| 11667 |
/* LSR Rd, Rn, #31. */ |
| 11668 |
if (speed_p) |
| 11669 |
*cost += extra_cost->alu.shift; |
| 11670 |
break; |
| 11671 |
|
| 11672 |
case EQ: |
| 11673 |
/* RSBS T1, Rn, #0 |
| 11674 |
ADC Rd, Rn, T1. */ |
| 11675 |
|
| 11676 |
case NE: |
| 11677 |
/* SUBS T1, Rn, #1 |
| 11678 |
SBC Rd, Rn, T1. */ |
| 11679 |
*cost += COSTS_N_INSNS (1); |
| 11680 |
break; |
| 11681 |
|
| 11682 |
case LE: |
| 11683 |
/* RSBS T1, Rn, Rn, LSR #31 |
| 11684 |
ADC Rd, Rn, T1. */ |
| 11685 |
*cost += COSTS_N_INSNS (1); |
| 11686 |
if (speed_p) |
| 11687 |
*cost += extra_cost->alu.arith_shift; |
| 11688 |
break; |
| 11689 |
|
| 11690 |
case GT: |
| 11691 |
/* RSB Rd, Rn, Rn, ASR #1 |
| 11692 |
LSR Rd, Rd, #31. */ |
| 11693 |
*cost += COSTS_N_INSNS (1); |
| 11694 |
if (speed_p) |
| 11695 |
*cost += (extra_cost->alu.arith_shift |
| 11696 |
+ extra_cost->alu.shift); |
| 11697 |
break; |
| 11698 |
|
| 11699 |
case GE: |
| 11700 |
/* ASR Rd, Rn, #31 |
| 11701 |
ADD Rd, Rn, #1. */ |
| 11702 |
*cost += COSTS_N_INSNS (1); |
| 11703 |
if (speed_p) |
| 11704 |
*cost += extra_cost->alu.shift; |
| 11705 |
break; |
| 11706 |
|
| 11707 |
default: |
| 11708 |
/* Remaining cases are either meaningless or would take |
| 11709 |
three insns anyway. */ |
| 11710 |
*cost = COSTS_N_INSNS (3); |
| 11711 |
break; |
| 11712 |
} |
| 11713 |
*cost += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); |
| 11714 |
return true; |
| 11715 |
} |
| 11716 |
else |
| 11717 |
{ |
| 11718 |
*cost += COSTS_N_INSNS (TARGET_THUMB ? 3 : 2); |
| 11719 |
if (CONST_INT_P (XEXP (x, 1)) |
| 11720 |
&& const_ok_for_op (INTVAL (XEXP (x, 1)), COMPARE)) |
| 11721 |
{ |
| 11722 |
*cost += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); |
| 11723 |
return true; |
| 11724 |
} |
| 11725 |
|
| 11726 |
return false; |
| 11727 |
} |
| 11728 |
} |
| 11729 |
/* Not directly inside a set. If it involves the condition code |
| 11730 |
register it must be the condition for a branch, cond_exec or |
| 11731 |
I_T_E operation. Since the comparison is performed elsewhere |
| 11732 |
this is just the control part which has no additional |
| 11733 |
cost. */ |
| 11734 |
else if (REG_P (XEXP (x, 0)) && REGNO (XEXP (x, 0)) == CC_REGNUM |
| 11735 |
&& XEXP (x, 1) == const0_rtx) |
| 11736 |
{ |
| 11737 |
*cost = 0; |
| 11738 |
return true; |
| 11739 |
} |
| 11740 |
return false; |
| 11741 |
|
| 11742 |
case ABS: |
| 11743 |
if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
| 11744 |
&& (mode == SFmode || !TARGET_VFP_SINGLE)) |
| 11745 |
{ |
| 11746 |
if (speed_p) |
| 11747 |
*cost += extra_cost->fp[mode != SFmode].neg; |
| 11748 |
|
| 11749 |
return false; |
| 11750 |
} |
| 11751 |
else if (GET_MODE_CLASS (mode) == MODE_FLOAT) |
| 11752 |
{ |
| 11753 |
*cost = LIBCALL_COST (1); |
| 11754 |
return false; |
| 11755 |
} |
| 11756 |
|
| 11757 |
if (mode == SImode) |
| 11758 |
{ |
| 11759 |
if (speed_p) |
| 11760 |
*cost += extra_cost->alu.log_shift + extra_cost->alu.arith_shift; |
| 11761 |
return false; |
| 11762 |
} |
| 11763 |
/* Vector mode? */ |
| 11764 |
*cost = LIBCALL_COST (1); |
| 11765 |
return false; |
| 11766 |
|
| 11767 |
case SIGN_EXTEND: |
| 11768 |
if ((arm_arch4 || GET_MODE (XEXP (x, 0)) == SImode) |
| 11769 |
&& MEM_P (XEXP (x, 0))) |
| 11770 |
{ |
| 11771 |
if (mode == DImode) |
| 11772 |
*cost += COSTS_N_INSNS (1); |
| 11773 |
|
| 11774 |
if (!speed_p) |
| 11775 |
return true; |
| 11776 |
|
| 11777 |
if (GET_MODE (XEXP (x, 0)) == SImode) |
| 11778 |
*cost += extra_cost->ldst.load; |
| 11779 |
else |
| 11780 |
*cost += extra_cost->ldst.load_sign_extend; |
| 11781 |
|
| 11782 |
if (mode == DImode) |
| 11783 |
*cost += extra_cost->alu.shift; |
| 11784 |
|
| 11785 |
return true; |
| 11786 |
} |
| 11787 |
|
| 11788 |
/* Widening from less than 32-bits requires an extend operation. */ |
| 11789 |
if (GET_MODE (XEXP (x, 0)) != SImode && arm_arch6) |
| 11790 |
{ |
| 11791 |
/* We have SXTB/SXTH. */ |
| 11792 |
*cost += rtx_cost (XEXP (x, 0), VOIDmode, code, 0, speed_p); |
| 11793 |
if (speed_p) |
| 11794 |
*cost += extra_cost->alu.extend; |
| 11795 |
} |
| 11796 |
else if (GET_MODE (XEXP (x, 0)) != SImode) |
| 11797 |
{ |
| 11798 |
/* Needs two shifts. */ |
| 11799 |
*cost += COSTS_N_INSNS (1); |
| 11800 |
*cost += rtx_cost (XEXP (x, 0), VOIDmode, code, 0, speed_p); |
| 11801 |
if (speed_p) |
| 11802 |
*cost += 2 * extra_cost->alu.shift; |
| 11803 |
} |
| 11804 |
|
| 11805 |
/* Widening beyond 32-bits requires one more insn. */ |
| 11806 |
if (mode == DImode) |
| 11807 |
{ |
| 11808 |
*cost += COSTS_N_INSNS (1); |
| 11809 |
if (speed_p) |
| 11810 |
*cost += extra_cost->alu.shift; |
| 11811 |
} |
| 11812 |
|
| 11813 |
return true; |
| 11814 |
|
| 11815 |
case ZERO_EXTEND: |
| 11816 |
if ((arm_arch4 |
| 11817 |
|| GET_MODE (XEXP (x, 0)) == SImode |
| 11818 |
|| GET_MODE (XEXP (x, 0)) == QImode) |
| 11819 |
&& MEM_P (XEXP (x, 0))) |
| 11820 |
{ |
| 11821 |
*cost = rtx_cost (XEXP (x, 0), VOIDmode, code, 0, speed_p); |
| 11822 |
|
| 11823 |
if (mode == DImode) |
| 11824 |
*cost += COSTS_N_INSNS (1); /* No speed penalty. */ |
| 11825 |
|
| 11826 |
return true; |
| 11827 |
} |
| 11828 |
|
| 11829 |
/* Widening from less than 32-bits requires an extend operation. */ |
| 11830 |
if (GET_MODE (XEXP (x, 0)) == QImode) |
| 11831 |
{ |
| 11832 |
/* UXTB can be a shorter instruction in Thumb2, but it might |
| 11833 |
be slower than the AND Rd, Rn, #255 alternative. When |
| 11834 |
optimizing for speed it should never be slower to use |
| 11835 |
AND, and we don't really model 16-bit vs 32-bit insns |
| 11836 |
here. */ |
| 11837 |
if (speed_p) |
| 11838 |
*cost += extra_cost->alu.logical; |
| 11839 |
} |
| 11840 |
else if (GET_MODE (XEXP (x, 0)) != SImode && arm_arch6) |
| 11841 |
{ |
| 11842 |
/* We have UXTB/UXTH. */ |
| 11843 |
*cost += rtx_cost (XEXP (x, 0), VOIDmode, code, 0, speed_p); |
| 11844 |
if (speed_p) |
| 11845 |
*cost += extra_cost->alu.extend; |
| 11846 |
} |
| 11847 |
else if (GET_MODE (XEXP (x, 0)) != SImode) |
| 11848 |
{ |
| 11849 |
/* Needs two shifts. It's marginally preferable to use |
| 11850 |
shifts rather than two BIC instructions as the second |
| 11851 |
shift may merge with a subsequent insn as a shifter |
| 11852 |
op. */ |
| 11853 |
*cost = COSTS_N_INSNS (2); |
| 11854 |
*cost += rtx_cost (XEXP (x, 0), VOIDmode, code, 0, speed_p); |
| 11855 |
if (speed_p) |
| 11856 |
*cost += 2 * extra_cost->alu.shift; |
| 11857 |
} |
| 11858 |
|
| 11859 |
/* Widening beyond 32-bits requires one more insn. */ |
| 11860 |
if (mode == DImode) |
| 11861 |
{ |
| 11862 |
*cost += COSTS_N_INSNS (1); /* No speed penalty. */ |
| 11863 |
} |
| 11864 |
|
| 11865 |
return true; |
| 11866 |
|
| 11867 |
case CONST_INT: |
| 11868 |
*cost = 0; |
| 11869 |
/* CONST_INT has no mode, so we cannot tell for sure how many |
| 11870 |
insns are really going to be needed. The best we can do is |
| 11871 |
look at the value passed. If it fits in SImode, then assume |
| 11872 |
that's the mode it will be used for. Otherwise assume it |
| 11873 |
will be used in DImode. */ |
| 11874 |
if (INTVAL (x) == trunc_int_for_mode (INTVAL (x), SImode)) |
| 11875 |
mode = SImode; |
| 11876 |
else |
| 11877 |
mode = DImode; |
| 11878 |
|
| 11879 |
/* Avoid blowing up in arm_gen_constant (). */ |
| 11880 |
if (!(outer_code == PLUS |
| 11881 |
|| outer_code == AND |
| 11882 |
|| outer_code == IOR |
| 11883 |
|| outer_code == XOR |
| 11884 |
|| outer_code == MINUS)) |
| 11885 |
outer_code = SET; |
| 11886 |
|
| 11887 |
const_int_cost: |
| 11888 |
if (mode == SImode) |
| 11889 |
{ |
| 11890 |
*cost += COSTS_N_INSNS (arm_gen_constant (outer_code, SImode, NULL, |
| 11891 |
INTVAL (x), NULL, NULL, |
| 11892 |
0, 0)); |
| 11893 |
/* Extra costs? */ |
| 11894 |
} |
| 11895 |
else |
| 11896 |
{ |
| 11897 |
*cost += COSTS_N_INSNS (arm_gen_constant |
| 11898 |
(outer_code, SImode, NULL, |
| 11899 |
trunc_int_for_mode (INTVAL (x), SImode), |
| 11900 |
NULL, NULL, 0, 0) |
| 11901 |
+ arm_gen_constant (outer_code, SImode, NULL, |
| 11902 |
INTVAL (x) >> 32, NULL, |
| 11903 |
NULL, 0, 0)); |
| 11904 |
/* Extra costs? */ |
| 11905 |
} |
| 11906 |
|
| 11907 |
return true; |
| 11908 |
|
| 11909 |
case CONST: |
| 11910 |
case LABEL_REF: |
| 11911 |
case SYMBOL_REF: |
| 11912 |
if (speed_p) |
| 11913 |
{ |
| 11914 |
if (arm_arch_thumb2 && !flag_pic) |
| 11915 |
*cost += COSTS_N_INSNS (1); |
| 11916 |
else |
| 11917 |
*cost += extra_cost->ldst.load; |
| 11918 |
} |
| 11919 |
else |
| 11920 |
*cost += COSTS_N_INSNS (1); |
| 11921 |
|
| 11922 |
if (flag_pic) |
| 11923 |
{ |
| 11924 |
*cost += COSTS_N_INSNS (1); |
| 11925 |
if (speed_p) |
| 11926 |
*cost += extra_cost->alu.arith; |
| 11927 |
} |
| 11928 |
|
| 11929 |
return true; |
| 11930 |
|
| 11931 |
case CONST_FIXED: |
| 11932 |
*cost = COSTS_N_INSNS (4); |
| 11933 |
/* Fixme. */ |
| 11934 |
return true; |
| 11935 |
|
| 11936 |
case CONST_DOUBLE: |
| 11937 |
if (TARGET_HARD_FLOAT && GET_MODE_CLASS (mode) == MODE_FLOAT |
| 11938 |
&& (mode == SFmode || mode == HFmode || !TARGET_VFP_SINGLE)) |
| 11939 |
{ |
| 11940 |
if (vfp3_const_double_rtx (x)) |
| 11941 |
{ |
| 11942 |
if (speed_p) |
| 11943 |
*cost += extra_cost->fp[mode == DFmode].fpconst; |
| 11944 |
return true; |
| 11945 |
} |
| 11946 |
|
| 11947 |
if (speed_p) |
| 11948 |
{ |
| 11949 |
if (mode == DFmode) |
| 11950 |
*cost += extra_cost->ldst.loadd; |
| 11951 |
else |
| 11952 |
*cost += extra_cost->ldst.loadf; |
| 11953 |
} |
| 11954 |
else |
| 11955 |
*cost += COSTS_N_INSNS (1 + (mode == DFmode)); |
| 11956 |
|
| 11957 |
return true; |
| 11958 |
} |
| 11959 |
*cost = COSTS_N_INSNS (4); |
| 11960 |
return true; |
| 11961 |
|
| 11962 |
case CONST_VECTOR: |
| 11963 |
if (((TARGET_NEON && TARGET_HARD_FLOAT |
| 11964 |
&& (VALID_NEON_DREG_MODE (mode) || VALID_NEON_QREG_MODE (mode))) |
| 11965 |
|| TARGET_HAVE_MVE) |
| 11966 |
&& simd_immediate_valid_for_move (x, mode, NULL, NULL)) |
| 11967 |
*cost = COSTS_N_INSNS (1); |
| 11968 |
else if (TARGET_HAVE_MVE) |
| 11969 |
{ |
| 11970 |
/* 128-bit vector requires two vldr.64 on MVE. */ |
| 11971 |
*cost = COSTS_N_INSNS (2); |
| 11972 |
if (speed_p) |
| 11973 |
*cost += extra_cost->ldst.loadd * 2; |
| 11974 |
} |
| 11975 |
else |
| 11976 |
*cost = COSTS_N_INSNS (4); |
| 11977 |
return true; |
| 11978 |
|
| 11979 |
case HIGH: |
| 11980 |
case LO_SUM: |
| 11981 |
/* When optimizing for size, we prefer constant pool entries to |
| 11982 |
MOVW/MOVT pairs, so bump the cost of these slightly. */ |
| 11983 |
if (!speed_p) |
| 11984 |
*cost += 1; |
| 11985 |
return true; |
| 11986 |
|
| 11987 |
case CLZ: |
| 11988 |
if (speed_p) |
| 11989 |
*cost += extra_cost->alu.clz; |
| 11990 |
return false; |
| 11991 |
|
| 11992 |
case SMIN: |
| 11993 |
if (XEXP (x, 1) == const0_rtx) |
| 11994 |
{ |
| 11995 |
if (speed_p) |
| 11996 |
*cost += extra_cost->alu.log_shift; |
| 11997 |
*cost += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); |
| 11998 |
return true; |
| 11999 |
} |
| 12000 |
/* Fall through. */ |
| 12001 |
case SMAX: |
| 12002 |
case UMIN: |
| 12003 |
case UMAX: |
| 12004 |
*cost += COSTS_N_INSNS (1); |
| 12005 |
return false; |
| 12006 |
|
| 12007 |
case TRUNCATE: |
| 12008 |
if (GET_CODE (XEXP (x, 0)) == ASHIFTRT |
| 12009 |
&& CONST_INT_P (XEXP (XEXP (x, 0), 1)) |
| 12010 |
&& INTVAL (XEXP (XEXP (x, 0), 1)) == 32 |
| 12011 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT |
| 12012 |
&& ((GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND |
| 12013 |
&& GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == SIGN_EXTEND) |
| 12014 |
|| (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND |
| 12015 |
&& (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) |
| 12016 |
== ZERO_EXTEND)))) |
| 12017 |
{ |
| 12018 |
if (speed_p) |
| 12019 |
*cost += extra_cost->mult[1].extend; |
| 12020 |
*cost += (rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0), VOIDmode, |
| 12021 |
ZERO_EXTEND, 0, speed_p) |
| 12022 |
+ rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 1), VOIDmode, |
| 12023 |
ZERO_EXTEND, 0, speed_p)); |
| 12024 |
return true; |
| 12025 |
} |
| 12026 |
*cost = LIBCALL_COST (1); |
| 12027 |
return false; |
| 12028 |
|
| 12029 |
case UNSPEC_VOLATILE: |
| 12030 |
case UNSPEC: |
| 12031 |
return arm_unspec_cost (x, outer_code, speed_p, cost); |
| 12032 |
|
| 12033 |
case PC: |
| 12034 |
/* Reading the PC is like reading any other register. Writing it |
| 12035 |
is more expensive, but we take that into account elsewhere. */ |
| 12036 |
*cost = 0; |
| 12037 |
return true; |
| 12038 |
|
| 12039 |
case ZERO_EXTRACT: |
| 12040 |
/* TODO: Simple zero_extract of bottom bits using AND. */ |
| 12041 |
/* Fall through. */ |
| 12042 |
case SIGN_EXTRACT: |
| 12043 |
if (arm_arch6 |
| 12044 |
&& mode == SImode |
| 12045 |
&& CONST_INT_P (XEXP (x, 1)) |
| 12046 |
&& CONST_INT_P (XEXP (x, 2))) |
| 12047 |
{ |
| 12048 |
if (speed_p) |
| 12049 |
*cost += extra_cost->alu.bfx; |
| 12050 |
*cost += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); |
| 12051 |
return true; |
| 12052 |
} |
| 12053 |
/* Without UBFX/SBFX, need to resort to shift operations. */ |
| 12054 |
*cost += COSTS_N_INSNS (1); |
| 12055 |
if (speed_p) |
| 12056 |
*cost += 2 * extra_cost->alu.shift; |
| 12057 |
*cost += rtx_cost (XEXP (x, 0), mode, ASHIFT, 0, speed_p); |
| 12058 |
return true; |
| 12059 |
|
| 12060 |
case FLOAT_EXTEND: |
| 12061 |
if (TARGET_HARD_FLOAT) |
| 12062 |
{ |
| 12063 |
if (speed_p) |
| 12064 |
*cost += extra_cost->fp[mode == DFmode].widen; |
| 12065 |
if (!TARGET_VFP5 |
| 12066 |
&& GET_MODE (XEXP (x, 0)) == HFmode) |
| 12067 |
{ |
| 12068 |
/* Pre v8, widening HF->DF is a two-step process, first |
| 12069 |
widening to SFmode. */ |
| 12070 |
*cost += COSTS_N_INSNS (1); |
| 12071 |
if (speed_p) |
| 12072 |
*cost += extra_cost->fp[0].widen; |
| 12073 |
} |
| 12074 |
*cost += rtx_cost (XEXP (x, 0), VOIDmode, code, 0, speed_p); |
| 12075 |
return true; |
| 12076 |
} |
| 12077 |
|
| 12078 |
*cost = LIBCALL_COST (1); |
| 12079 |
return false; |
| 12080 |
|
| 12081 |
case FLOAT_TRUNCATE: |
| 12082 |
if (TARGET_HARD_FLOAT) |
| 12083 |
{ |
| 12084 |
if (speed_p) |
| 12085 |
*cost += extra_cost->fp[mode == DFmode].narrow; |
| 12086 |
*cost += rtx_cost (XEXP (x, 0), VOIDmode, code, 0, speed_p); |
| 12087 |
return true; |
| 12088 |
/* Vector modes? */ |
| 12089 |
} |
| 12090 |
*cost = LIBCALL_COST (1); |
| 12091 |
return false; |
| 12092 |
|
| 12093 |
case FMA: |
| 12094 |
if (TARGET_32BIT && TARGET_HARD_FLOAT && TARGET_FMA) |
| 12095 |
{ |
| 12096 |
rtx op0 = XEXP (x, 0); |
| 12097 |
rtx op1 = XEXP (x, 1); |
| 12098 |
rtx op2 = XEXP (x, 2); |
| 12099 |
|
| 12100 |
|
| 12101 |
/* vfms or vfnma. */ |
| 12102 |
if (GET_CODE (op0) == NEG) |
| 12103 |
op0 = XEXP (op0, 0); |
| 12104 |
|
| 12105 |
/* vfnms or vfnma. */ |
| 12106 |
if (GET_CODE (op2) == NEG) |
| 12107 |
op2 = XEXP (op2, 0); |
| 12108 |
|
| 12109 |
*cost += rtx_cost (op0, mode, FMA, 0, speed_p); |
| 12110 |
*cost += rtx_cost (op1, mode, FMA, 1, speed_p); |
| 12111 |
*cost += rtx_cost (op2, mode, FMA, 2, speed_p); |
| 12112 |
|
| 12113 |
if (speed_p) |
| 12114 |
*cost += extra_cost->fp[mode ==DFmode].fma; |
| 12115 |
|
| 12116 |
return true; |
| 12117 |
} |
| 12118 |
|
| 12119 |
*cost = LIBCALL_COST (3); |
| 12120 |
return false; |
| 12121 |
|
| 12122 |
case FIX: |
| 12123 |
case UNSIGNED_FIX: |
| 12124 |
if (TARGET_HARD_FLOAT) |
| 12125 |
{ |
| 12126 |
/* The *combine_vcvtf2i reduces a vmul+vcvt into |
| 12127 |
a vcvt fixed-point conversion. */ |
| 12128 |
if (code == FIX && mode == SImode |
| 12129 |
&& GET_CODE (XEXP (x, 0)) == FIX |
| 12130 |
&& GET_MODE (XEXP (x, 0)) == SFmode |
| 12131 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT |
| 12132 |
&& vfp3_const_double_for_bits (XEXP (XEXP (XEXP (x, 0), 0), 1)) |
| 12133 |
> 0) |
| 12134 |
{ |
| 12135 |
if (speed_p) |
| 12136 |
*cost += extra_cost->fp[0].toint; |
| 12137 |
|
| 12138 |
*cost += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0), mode, |
| 12139 |
code, 0, speed_p); |
| 12140 |
return true; |
| 12141 |
} |
| 12142 |
|
| 12143 |
if (GET_MODE_CLASS (mode) == MODE_INT) |
| 12144 |
{ |
| 12145 |
mode = GET_MODE (XEXP (x, 0)); |
| 12146 |
if (speed_p) |
| 12147 |
*cost += extra_cost->fp[mode == DFmode].toint; |
| 12148 |
/* Strip of the 'cost' of rounding towards zero. */ |
| 12149 |
if (GET_CODE (XEXP (x, 0)) == FIX) |
| 12150 |
*cost += rtx_cost (XEXP (XEXP (x, 0), 0), mode, code, |
| 12151 |
0, speed_p); |
| 12152 |
else |
| 12153 |
*cost += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); |
| 12154 |
/* ??? Increase the cost to deal with transferring from |
| 12155 |
FP -> CORE registers? */ |
| 12156 |
return true; |
| 12157 |
} |
| 12158 |
else if (GET_MODE_CLASS (mode) == MODE_FLOAT |
| 12159 |
&& TARGET_VFP5) |
| 12160 |
{ |
| 12161 |
if (speed_p) |
| 12162 |
*cost += extra_cost->fp[mode == DFmode].roundint; |
| 12163 |
return false; |
| 12164 |
} |
| 12165 |
/* Vector costs? */ |
| 12166 |
} |
| 12167 |
*cost = LIBCALL_COST (1); |
| 12168 |
return false; |
| 12169 |
|
| 12170 |
case FLOAT: |
| 12171 |
case UNSIGNED_FLOAT: |
| 12172 |
if (TARGET_HARD_FLOAT) |
| 12173 |
{ |
| 12174 |
/* ??? Increase the cost to deal with transferring from CORE |
| 12175 |
-> FP registers? */ |
| 12176 |
if (speed_p) |
| 12177 |
*cost += extra_cost->fp[mode == DFmode].fromint; |
| 12178 |
return false; |
| 12179 |
} |
| 12180 |
*cost = LIBCALL_COST (1); |
| 12181 |
return false; |
| 12182 |
|
| 12183 |
case CALL: |
| 12184 |
return true; |
| 12185 |
|
| 12186 |
case ASM_OPERANDS: |
| 12187 |
{ |
| 12188 |
/* Just a guess. Guess number of instructions in the asm |
| 12189 |
plus one insn per input. Always a minimum of COSTS_N_INSNS (1) |
| 12190 |
though (see PR60663). */ |
| 12191 |
int asm_length = MAX (1, asm_str_count (ASM_OPERANDS_TEMPLATE (x))); |
| 12192 |
int num_operands = ASM_OPERANDS_INPUT_LENGTH (x); |
| 12193 |
|
| 12194 |
*cost = COSTS_N_INSNS (asm_length + num_operands); |
| 12195 |
return true; |
| 12196 |
} |
| 12197 |
default: |
| 12198 |
if (mode != VOIDmode) |
| 12199 |
*cost = COSTS_N_INSNS (ARM_NUM_REGS (mode)); |
| 12200 |
else |
| 12201 |
*cost = COSTS_N_INSNS (4); /* Who knows? */ |
| 12202 |
return false; |
| 12203 |
} |
| 12204 |
} |
| 12205 |
|
| 12206 |
#undef HANDLE_NARROW_SHIFT_ARITH |
| 12207 |
|
| 12208 |
/* RTX costs entry point. */ |
| 12209 |
|
| 12210 |
static bool |
| 12211 |
arm_rtx_costs (rtx x, machine_mode mode ATTRIBUTE_UNUSED, int outer_code, |
| 12212 |
int opno ATTRIBUTE_UNUSED, int *total, bool speed) |
| 12213 |
{ |
| 12214 |
bool result; |
| 12215 |
int code = GET_CODE (x); |
| 12216 |
gcc_assert (current_tune->insn_extra_cost); |
| 12217 |
|
| 12218 |
result = arm_rtx_costs_internal (x, (enum rtx_code) code, |
| 12219 |
(enum rtx_code) outer_code, |
| 12220 |
current_tune->insn_extra_cost, |
| 12221 |
total, speed); |
| 12222 |
|
| 12223 |
if (dump_file && arm_verbose_cost) |
| 12224 |
{ |
| 12225 |
print_rtl_single (dump_file, x); |
| 12226 |
fprintf (dump_file, "\n%s cost: %d (%s)\n", speed ? "Hot" : "Cold", |
| 12227 |
*total, result ? "final" : "partial"); |
| 12228 |
} |
| 12229 |
return result; |
| 12230 |
} |
| 12231 |
|
| 12232 |
static int |
| 12233 |
arm_insn_cost (rtx_insn *insn, bool speed) |
| 12234 |
{ |
| 12235 |
int cost; |
| 12236 |
|
| 12237 |
/* Don't cost a simple reg-reg move at a full insn cost: such moves |
| 12238 |
will likely disappear during register allocation. */ |
| 12239 |
if (!reload_completed |
| 12240 |
&& GET_CODE (PATTERN (insn)) == SET |
| 12241 |
&& REG_P (SET_DEST (PATTERN (insn))) |
| 12242 |
&& REG_P (SET_SRC (PATTERN (insn)))) |
| 12243 |
return 2; |
| 12244 |
cost = pattern_cost (PATTERN (insn), speed); |
| 12245 |
/* If the cost is zero, then it's likely a complex insn. We don't want the |
| 12246 |
cost of these to be less than something we know about. */ |
| 12247 |
return cost ? cost : COSTS_N_INSNS (2); |
| 12248 |
} |
| 12249 |
|
| 12250 |
/* All address computations that can be done are free, but rtx cost returns |
| 12251 |
the same for practically all of them. So we weight the different types |
| 12252 |
of address here in the order (most pref first): |
| 12253 |
PRE/POST_INC/DEC, SHIFT or NON-INT sum, INT sum, REG, MEM or LABEL. */ |
| 12254 |
static inline int |
| 12255 |
arm_arm_address_cost (rtx x) |
| 12256 |
{ |
| 12257 |
enum rtx_code c = GET_CODE (x); |
| 12258 |
|
| 12259 |
if (c == PRE_INC || c == PRE_DEC || c == POST_INC || c == POST_DEC) |
| 12260 |
return 0; |
| 12261 |
if (c == MEM || c == LABEL_REF || c == SYMBOL_REF) |
| 12262 |
return 10; |
| 12263 |
|
| 12264 |
if (c == PLUS) |
| 12265 |
{ |
| 12266 |
if (CONST_INT_P (XEXP (x, 1))) |
| 12267 |
return 2; |
| 12268 |
|
| 12269 |
if (ARITHMETIC_P (XEXP (x, 0)) || ARITHMETIC_P (XEXP (x, 1))) |
| 12270 |
return 3; |
| 12271 |
|
| 12272 |
return 4; |
| 12273 |
} |
| 12274 |
|
| 12275 |
return 6; |
| 12276 |
} |
| 12277 |
|
| 12278 |
static inline int |
| 12279 |
arm_thumb_address_cost (rtx x) |
| 12280 |
{ |
| 12281 |
enum rtx_code c = GET_CODE (x); |
| 12282 |
|
| 12283 |
if (c == REG) |
| 12284 |
return 1; |
| 12285 |
if (c == PLUS |
| 12286 |
&& REG_P (XEXP (x, 0)) |
| 12287 |
&& CONST_INT_P (XEXP (x, 1))) |
| 12288 |
return 1; |
| 12289 |
|
| 12290 |
return 2; |
| 12291 |
} |
| 12292 |
|
| 12293 |
static int |
| 12294 |
arm_address_cost (rtx x, machine_mode mode ATTRIBUTE_UNUSED, |
| 12295 |
addr_space_t as ATTRIBUTE_UNUSED, bool speed ATTRIBUTE_UNUSED) |
| 12296 |
{ |
| 12297 |
return TARGET_32BIT ? arm_arm_address_cost (x) : arm_thumb_address_cost (x); |
| 12298 |
} |
| 12299 |
|
| 12300 |
/* Adjust cost hook for XScale. */ |
| 12301 |
static bool |
| 12302 |
xscale_sched_adjust_cost (rtx_insn *insn, int dep_type, rtx_insn *dep, |
| 12303 |
int * cost) |
| 12304 |
{ |
| 12305 |
/* Some true dependencies can have a higher cost depending |
| 12306 |
on precisely how certain input operands are used. */ |
| 12307 |
if (dep_type == 0 |
| 12308 |
&& recog_memoized (insn) >= 0 |
| 12309 |
&& recog_memoized (dep) >= 0) |
| 12310 |
{ |
| 12311 |
int shift_opnum = get_attr_shift (insn); |
| 12312 |
enum attr_type attr_type = get_attr_type (dep); |
| 12313 |
|
| 12314 |
/* If nonzero, SHIFT_OPNUM contains the operand number of a shifted |
| 12315 |
operand for INSN. If we have a shifted input operand and the |
| 12316 |
instruction we depend on is another ALU instruction, then we may |
| 12317 |
have to account for an additional stall. */ |
| 12318 |
if (shift_opnum != 0 |
| 12319 |
&& (attr_type == TYPE_ALU_SHIFT_IMM_LSL_1TO4 |
| 12320 |
|| attr_type == TYPE_ALU_SHIFT_IMM_OTHER |
| 12321 |
|| attr_type == TYPE_ALUS_SHIFT_IMM |
| 12322 |
|| attr_type == TYPE_LOGIC_SHIFT_IMM |
| 12323 |
|| attr_type == TYPE_LOGICS_SHIFT_IMM |
| 12324 |
|| attr_type == TYPE_ALU_SHIFT_REG |
| 12325 |
|| attr_type == TYPE_ALUS_SHIFT_REG |
| 12326 |
|| attr_type == TYPE_LOGIC_SHIFT_REG |
| 12327 |
|| attr_type == TYPE_LOGICS_SHIFT_REG |
| 12328 |
|| attr_type == TYPE_MOV_SHIFT |
| 12329 |
|| attr_type == TYPE_MVN_SHIFT |
| 12330 |
|| attr_type == TYPE_MOV_SHIFT_REG |
| 12331 |
|| attr_type == TYPE_MVN_SHIFT_REG)) |
| 12332 |
{ |
| 12333 |
rtx shifted_operand; |
| 12334 |
int opno; |
| 12335 |
|
| 12336 |
/* Get the shifted operand. */ |
| 12337 |
extract_insn (insn); |
| 12338 |
shifted_operand = recog_data.operand[shift_opnum]; |
| 12339 |
|
| 12340 |
/* Iterate over all the operands in DEP. If we write an operand |
| 12341 |
that overlaps with SHIFTED_OPERAND, then we have increase the |
| 12342 |
cost of this dependency. */ |
| 12343 |
extract_insn (dep); |
| 12344 |
preprocess_constraints (dep); |
| 12345 |
for (opno = 0; opno < recog_data.n_operands; opno++) |
| 12346 |
{ |
| 12347 |
/* We can ignore strict inputs. */ |
| 12348 |
if (recog_data.operand_type[opno] == OP_IN) |
| 12349 |
continue; |
| 12350 |
|
| 12351 |
if (reg_overlap_mentioned_p (recog_data.operand[opno], |
| 12352 |
shifted_operand)) |
| 12353 |
{ |
| 12354 |
*cost = 2; |
| 12355 |
return false; |
| 12356 |
} |
| 12357 |
} |
| 12358 |
} |
| 12359 |
} |
| 12360 |
return true; |
| 12361 |
} |
| 12362 |
|
| 12363 |
/* Adjust cost hook for Cortex A9. */ |
| 12364 |
static bool |
| 12365 |
cortex_a9_sched_adjust_cost (rtx_insn *insn, int dep_type, rtx_insn *dep, |
| 12366 |
int * cost) |
| 12367 |
{ |
| 12368 |
switch (dep_type) |
| 12369 |
{ |
| 12370 |
case REG_DEP_ANTI: |
| 12371 |
*cost = 0; |
| 12372 |
return false; |
| 12373 |
|
| 12374 |
case REG_DEP_TRUE: |
| 12375 |
case REG_DEP_OUTPUT: |
| 12376 |
if (recog_memoized (insn) >= 0 |
| 12377 |
&& recog_memoized (dep) >= 0) |
| 12378 |
{ |
| 12379 |
if (GET_CODE (PATTERN (insn)) == SET) |
| 12380 |
{ |
| 12381 |
if (GET_MODE_CLASS |
| 12382 |
(GET_MODE (SET_DEST (PATTERN (insn)))) == MODE_FLOAT |
| 12383 |
|| GET_MODE_CLASS |
| 12384 |
(GET_MODE (SET_SRC (PATTERN (insn)))) == MODE_FLOAT) |
| 12385 |
{ |
| 12386 |
enum attr_type attr_type_insn = get_attr_type (insn); |
| 12387 |
enum attr_type attr_type_dep = get_attr_type (dep); |
| 12388 |
|
| 12389 |
/* By default all dependencies of the form |
| 12390 |
s0 = s0 <op> s1 |
| 12391 |
s0 = s0 <op> s2 |
| 12392 |
have an extra latency of 1 cycle because |
| 12393 |
of the input and output dependency in this |
| 12394 |
case. However this gets modeled as an true |
| 12395 |
dependency and hence all these checks. */ |
| 12396 |
if (REG_P (SET_DEST (PATTERN (insn))) |
| 12397 |
&& reg_set_p (SET_DEST (PATTERN (insn)), dep)) |
| 12398 |
{ |
| 12399 |
/* FMACS is a special case where the dependent |
| 12400 |
instruction can be issued 3 cycles before |
| 12401 |
the normal latency in case of an output |
| 12402 |
dependency. */ |
| 12403 |
if ((attr_type_insn == TYPE_FMACS |
| 12404 |
|| attr_type_insn == TYPE_FMACD) |
| 12405 |
&& (attr_type_dep == TYPE_FMACS |
| 12406 |
|| attr_type_dep == TYPE_FMACD)) |
| 12407 |
{ |
| 12408 |
if (dep_type == REG_DEP_OUTPUT) |
| 12409 |
*cost = insn_default_latency (dep) - 3; |
| 12410 |
else |
| 12411 |
*cost = insn_default_latency (dep); |
| 12412 |
return false; |
| 12413 |
} |
| 12414 |
else |
| 12415 |
{ |
| 12416 |
if (dep_type == REG_DEP_OUTPUT) |
| 12417 |
*cost = insn_default_latency (dep) + 1; |
| 12418 |
else |
| 12419 |
*cost = insn_default_latency (dep); |
| 12420 |
} |
| 12421 |
return false; |
| 12422 |
} |
| 12423 |
} |
| 12424 |
} |
| 12425 |
} |
| 12426 |
break; |
| 12427 |
|
| 12428 |
default: |
| 12429 |
gcc_unreachable (); |
| 12430 |
} |
| 12431 |
|
| 12432 |
return true; |
| 12433 |
} |
| 12434 |
|
| 12435 |
/* Adjust cost hook for FA726TE. */ |
| 12436 |
static bool |
| 12437 |
fa726te_sched_adjust_cost (rtx_insn *insn, int dep_type, rtx_insn *dep, |
| 12438 |
int * cost) |
| 12439 |
{ |
| 12440 |
/* For FA726TE, true dependency on CPSR (i.e. set cond followed by predicated) |
| 12441 |
have penalty of 3. */ |
| 12442 |
if (dep_type == REG_DEP_TRUE |
| 12443 |
&& recog_memoized (insn) >= 0 |
| 12444 |
&& recog_memoized (dep) >= 0 |
| 12445 |
&& get_attr_conds (dep) == CONDS_SET) |
| 12446 |
{ |
| 12447 |
/* Use of carry (e.g. 64-bit arithmetic) in ALU: 3-cycle latency. */ |
| 12448 |
if (get_attr_conds (insn) == CONDS_USE |
| 12449 |
&& get_attr_type (insn) != TYPE_BRANCH) |
| 12450 |
{ |
| 12451 |
*cost = 3; |
| 12452 |
return false; |
| 12453 |
} |
| 12454 |
|
| 12455 |
if (GET_CODE (PATTERN (insn)) == COND_EXEC |
| 12456 |
|| get_attr_conds (insn) == CONDS_USE) |
| 12457 |
{ |
| 12458 |
*cost = 0; |
| 12459 |
return false; |
| 12460 |
} |
| 12461 |
} |
| 12462 |
|
| 12463 |
return true; |
| 12464 |
} |
| 12465 |
|
| 12466 |
/* Implement TARGET_REGISTER_MOVE_COST. |
| 12467 |
|
| 12468 |
Moves between VFP_REGS and GENERAL_REGS are a single insn, but |
| 12469 |
it is typically more expensive than a single memory access. We set |
| 12470 |
the cost to less than two memory accesses so that floating |
| 12471 |
point to integer conversion does not go through memory. */ |
| 12472 |
|
| 12473 |
int |
| 12474 |
arm_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED, |
| 12475 |
reg_class_t from, reg_class_t to) |
| 12476 |
{ |
| 12477 |
if (TARGET_32BIT) |
| 12478 |
{ |
| 12479 |
if ((IS_VFP_CLASS (from) && !IS_VFP_CLASS (to)) |
| 12480 |
|| (!IS_VFP_CLASS (from) && IS_VFP_CLASS (to))) |
| 12481 |
return 15; |
| 12482 |
else if ((from == IWMMXT_REGS && to != IWMMXT_REGS) |
| 12483 |
|| (from != IWMMXT_REGS && to == IWMMXT_REGS)) |
| 12484 |
return 4; |
| 12485 |
else if (from == IWMMXT_GR_REGS || to == IWMMXT_GR_REGS) |
| 12486 |
return 20; |
| 12487 |
else |
| 12488 |
return 2; |
| 12489 |
} |
| 12490 |
else |
| 12491 |
{ |
| 12492 |
if (from == HI_REGS || to == HI_REGS) |
| 12493 |
return 4; |
| 12494 |
else |
| 12495 |
return 2; |
| 12496 |
} |
| 12497 |
} |
| 12498 |
|
| 12499 |
/* Implement TARGET_MEMORY_MOVE_COST. */ |
| 12500 |
|
| 12501 |
int |
| 12502 |
arm_memory_move_cost (machine_mode mode, reg_class_t rclass, |
| 12503 |
bool in ATTRIBUTE_UNUSED) |
| 12504 |
{ |
| 12505 |
if (TARGET_32BIT) |
| 12506 |
return 10; |
| 12507 |
else |
| 12508 |
{ |
| 12509 |
if (GET_MODE_SIZE (mode) < 4) |
| 12510 |
return 8; |
| 12511 |
else |
| 12512 |
return ((2 * GET_MODE_SIZE (mode)) * (rclass == LO_REGS ? 1 : 2)); |
| 12513 |
} |
| 12514 |
} |
| 12515 |
|
| 12516 |
/* Vectorizer cost model implementation. */ |
| 12517 |
|
| 12518 |
/* Implement targetm.vectorize.builtin_vectorization_cost. */ |
| 12519 |
static int |
| 12520 |
arm_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost, |
| 12521 |
tree vectype, |
| 12522 |
int misalign ATTRIBUTE_UNUSED) |
| 12523 |
{ |
| 12524 |
unsigned elements; |
| 12525 |
|
| 12526 |
switch (type_of_cost) |
| 12527 |
{ |
| 12528 |
case scalar_stmt: |
| 12529 |
return current_tune->vec_costs->scalar_stmt_cost; |
| 12530 |
|
| 12531 |
case scalar_load: |
| 12532 |
return current_tune->vec_costs->scalar_load_cost; |
| 12533 |
|
| 12534 |
case scalar_store: |
| 12535 |
return current_tune->vec_costs->scalar_store_cost; |
| 12536 |
|
| 12537 |
case vector_stmt: |
| 12538 |
return current_tune->vec_costs->vec_stmt_cost; |
| 12539 |
|
| 12540 |
case vector_load: |
| 12541 |
return current_tune->vec_costs->vec_align_load_cost; |
| 12542 |
|
| 12543 |
case vector_store: |
| 12544 |
return current_tune->vec_costs->vec_store_cost; |
| 12545 |
|
| 12546 |
case vec_to_scalar: |
| 12547 |
return current_tune->vec_costs->vec_to_scalar_cost; |
| 12548 |
|
| 12549 |
case scalar_to_vec: |
| 12550 |
return current_tune->vec_costs->scalar_to_vec_cost; |
| 12551 |
|
| 12552 |
case unaligned_load: |
| 12553 |
case vector_gather_load: |
| 12554 |
return current_tune->vec_costs->vec_unalign_load_cost; |
| 12555 |
|
| 12556 |
case unaligned_store: |
| 12557 |
case vector_scatter_store: |
| 12558 |
return current_tune->vec_costs->vec_unalign_store_cost; |
| 12559 |
|
| 12560 |
case cond_branch_taken: |
| 12561 |
return current_tune->vec_costs->cond_taken_branch_cost; |
| 12562 |
|
| 12563 |
case cond_branch_not_taken: |
| 12564 |
return current_tune->vec_costs->cond_not_taken_branch_cost; |
| 12565 |
|
| 12566 |
case vec_perm: |
| 12567 |
case vec_promote_demote: |
| 12568 |
return current_tune->vec_costs->vec_stmt_cost; |
| 12569 |
|
| 12570 |
case vec_construct: |
| 12571 |
elements = TYPE_VECTOR_SUBPARTS (vectype); |
| 12572 |
return elements / 2 + 1; |
| 12573 |
|
| 12574 |
default: |
| 12575 |
gcc_unreachable (); |
| 12576 |
} |
| 12577 |
} |
| 12578 |
|
| 12579 |
/* Return true if and only if this insn can dual-issue only as older. */ |
| 12580 |
static bool |
| 12581 |
cortexa7_older_only (rtx_insn *insn) |
| 12582 |
{ |
| 12583 |
if (recog_memoized (insn) < 0) |
| 12584 |
return false; |
| 12585 |
|
| 12586 |
switch (get_attr_type (insn)) |
| 12587 |
{ |
| 12588 |
case TYPE_ALU_DSP_REG: |
| 12589 |
case TYPE_ALU_SREG: |
| 12590 |
case TYPE_ALUS_SREG: |
| 12591 |
case TYPE_LOGIC_REG: |
| 12592 |
case TYPE_LOGICS_REG: |
| 12593 |
case TYPE_ADC_REG: |
| 12594 |
case TYPE_ADCS_REG: |
| 12595 |
case TYPE_ADR: |
| 12596 |
case TYPE_BFM: |
| 12597 |
case TYPE_REV: |
| 12598 |
case TYPE_MVN_REG: |
| 12599 |
case TYPE_SHIFT_IMM: |
| 12600 |
case TYPE_SHIFT_REG: |
| 12601 |
case TYPE_LOAD_BYTE: |
| 12602 |
case TYPE_LOAD_4: |
| 12603 |
case TYPE_STORE_4: |
| 12604 |
case TYPE_FFARITHS: |
| 12605 |
case TYPE_FADDS: |
| 12606 |
case TYPE_FFARITHD: |
| 12607 |
case TYPE_FADDD: |
| 12608 |
case TYPE_FMOV: |
| 12609 |
case TYPE_F_CVT: |
| 12610 |
case TYPE_FCMPS: |
| 12611 |
case TYPE_FCMPD: |
| 12612 |
case TYPE_FCONSTS: |
| 12613 |
case TYPE_FCONSTD: |
| 12614 |
case TYPE_FMULS: |
| 12615 |
case TYPE_FMACS: |
| 12616 |
case TYPE_FMULD: |
| 12617 |
case TYPE_FMACD: |
| 12618 |
case TYPE_FDIVS: |
| 12619 |
case TYPE_FDIVD: |
| 12620 |
case TYPE_F_MRC: |
| 12621 |
case TYPE_F_MRRC: |
| 12622 |
case TYPE_F_FLAG: |
| 12623 |
case TYPE_F_LOADS: |
| 12624 |
case TYPE_F_STORES: |
| 12625 |
return true; |
| 12626 |
default: |
| 12627 |
return false; |
| 12628 |
} |
| 12629 |
} |
| 12630 |
|
| 12631 |
/* Return true if and only if this insn can dual-issue as younger. */ |
| 12632 |
static bool |
| 12633 |
cortexa7_younger (FILE *file, int verbose, rtx_insn *insn) |
| 12634 |
{ |
| 12635 |
if (recog_memoized (insn) < 0) |
| 12636 |
{ |
| 12637 |
if (verbose > 5) |
| 12638 |
fprintf (file, ";; not cortexa7_younger %d\n", INSN_UID (insn)); |
| 12639 |
return false; |
| 12640 |
} |
| 12641 |
|
| 12642 |
switch (get_attr_type (insn)) |
| 12643 |
{ |
| 12644 |
case TYPE_ALU_IMM: |
| 12645 |
case TYPE_ALUS_IMM: |
| 12646 |
case TYPE_LOGIC_IMM: |
| 12647 |
case TYPE_LOGICS_IMM: |
| 12648 |
case TYPE_EXTEND: |
| 12649 |
case TYPE_MVN_IMM: |
| 12650 |
case TYPE_MOV_IMM: |
| 12651 |
case TYPE_MOV_REG: |
| 12652 |
case TYPE_MOV_SHIFT: |
| 12653 |
case TYPE_MOV_SHIFT_REG: |
| 12654 |
case TYPE_BRANCH: |
| 12655 |
case TYPE_CALL: |
| 12656 |
return true; |
| 12657 |
default: |
| 12658 |
return false; |
| 12659 |
} |
| 12660 |
} |
| 12661 |
|
| 12662 |
|
| 12663 |
/* Look for an instruction that can dual issue only as an older |
| 12664 |
instruction, and move it in front of any instructions that can |
| 12665 |
dual-issue as younger, while preserving the relative order of all |
| 12666 |
other instructions in the ready list. This is a hueuristic to help |
| 12667 |
dual-issue in later cycles, by postponing issue of more flexible |
| 12668 |
instructions. This heuristic may affect dual issue opportunities |
| 12669 |
in the current cycle. */ |
| 12670 |
static void |
| 12671 |
cortexa7_sched_reorder (FILE *file, int verbose, rtx_insn **ready, |
| 12672 |
int *n_readyp, int clock) |
| 12673 |
{ |
| 12674 |
int i; |
| 12675 |
int first_older_only = -1, first_younger = -1; |
| 12676 |
|
| 12677 |
if (verbose > 5) |
| 12678 |
fprintf (file, |
| 12679 |
";; sched_reorder for cycle %d with %d insns in ready list\n", |
| 12680 |
clock, |
| 12681 |
*n_readyp); |
| 12682 |
|
| 12683 |
/* Traverse the ready list from the head (the instruction to issue |
| 12684 |
first), and looking for the first instruction that can issue as |
| 12685 |
younger and the first instruction that can dual-issue only as |
| 12686 |
older. */ |
| 12687 |
for (i = *n_readyp - 1; i >= 0; i--) |
| 12688 |
{ |
| 12689 |
rtx_insn *insn = ready[i]; |
| 12690 |
if (cortexa7_older_only (insn)) |
| 12691 |
{ |
| 12692 |
first_older_only = i; |
| 12693 |
if (verbose > 5) |
| 12694 |
fprintf (file, ";; reorder older found %d\n", INSN_UID (insn)); |
| 12695 |
break; |
| 12696 |
} |
| 12697 |
else if (cortexa7_younger (file, verbose, insn) && first_younger == -1) |
| 12698 |
first_younger = i; |
| 12699 |
} |
| 12700 |
|
| 12701 |
/* Nothing to reorder because either no younger insn found or insn |
| 12702 |
that can dual-issue only as older appears before any insn that |
| 12703 |
can dual-issue as younger. */ |
| 12704 |
if (first_younger == -1) |
| 12705 |
{ |
| 12706 |
if (verbose > 5) |
| 12707 |
fprintf (file, ";; sched_reorder nothing to reorder as no younger\n"); |
| 12708 |
return; |
| 12709 |
} |
| 12710 |
|
| 12711 |
/* Nothing to reorder because no older-only insn in the ready list. */ |
| 12712 |
if (first_older_only == -1) |
| 12713 |
{ |
| 12714 |
if (verbose > 5) |
| 12715 |
fprintf (file, ";; sched_reorder nothing to reorder as no older_only\n"); |
| 12716 |
return; |
| 12717 |
} |
| 12718 |
|
| 12719 |
/* Move first_older_only insn before first_younger. */ |
| 12720 |
if (verbose > 5) |
| 12721 |
fprintf (file, ";; cortexa7_sched_reorder insn %d before %d\n", |
| 12722 |
INSN_UID(ready [first_older_only]), |
| 12723 |
INSN_UID(ready [first_younger])); |
| 12724 |
rtx_insn *first_older_only_insn = ready [first_older_only]; |
| 12725 |
for (i = first_older_only; i < first_younger; i++) |
| 12726 |
{ |
| 12727 |
ready[i] = ready[i+1]; |
| 12728 |
} |
| 12729 |
|
| 12730 |
ready[i] = first_older_only_insn; |
| 12731 |
return; |
| 12732 |
} |
| 12733 |
|
| 12734 |
/* Implement TARGET_SCHED_REORDER. */ |
| 12735 |
static int |
| 12736 |
arm_sched_reorder (FILE *file, int verbose, rtx_insn **ready, int *n_readyp, |
| 12737 |
int clock) |
| 12738 |
{ |
| 12739 |
switch (arm_tune) |
| 12740 |
{ |
| 12741 |
case TARGET_CPU_cortexa7: |
| 12742 |
cortexa7_sched_reorder (file, verbose, ready, n_readyp, clock); |
| 12743 |
break; |
| 12744 |
default: |
| 12745 |
/* Do nothing for other cores. */ |
| 12746 |
break; |
| 12747 |
} |
| 12748 |
|
| 12749 |
return arm_issue_rate (); |
| 12750 |
} |
| 12751 |
|
| 12752 |
/* This function implements the target macro TARGET_SCHED_ADJUST_COST. |
| 12753 |
It corrects the value of COST based on the relationship between |
| 12754 |
INSN and DEP through the dependence LINK. It returns the new |
| 12755 |
value. There is a per-core adjust_cost hook to adjust scheduler costs |
| 12756 |
and the per-core hook can choose to completely override the generic |
| 12757 |
adjust_cost function. Only put bits of code into arm_adjust_cost that |
| 12758 |
are common across all cores. */ |
| 12759 |
static int |
| 12760 |
arm_adjust_cost (rtx_insn *insn, int dep_type, rtx_insn *dep, int cost, |
| 12761 |
unsigned int) |
| 12762 |
{ |
| 12763 |
rtx i_pat, d_pat; |
| 12764 |
|
| 12765 |
/* When generating Thumb-1 code, we want to place flag-setting operations |
| 12766 |
close to a conditional branch which depends on them, so that we can |
| 12767 |
omit the comparison. */ |
| 12768 |
if (TARGET_THUMB1 |
| 12769 |
&& dep_type == 0 |
| 12770 |
&& recog_memoized (insn) == CODE_FOR_cbranchsi4_insn |
| 12771 |
&& recog_memoized (dep) >= 0 |
| 12772 |
&& get_attr_conds (dep) == CONDS_SET) |
| 12773 |
return 0; |
| 12774 |
|
| 12775 |
if (current_tune->sched_adjust_cost != NULL) |
| 12776 |
{ |
| 12777 |
if (!current_tune->sched_adjust_cost (insn, dep_type, dep, &cost)) |
| 12778 |
return cost; |
| 12779 |
} |
| 12780 |
|
| 12781 |
/* XXX Is this strictly true? */ |
| 12782 |
if (dep_type == REG_DEP_ANTI |
| 12783 |
|| dep_type == REG_DEP_OUTPUT) |
| 12784 |
return 0; |
| 12785 |
|
| 12786 |
/* Call insns don't incur a stall, even if they follow a load. */ |
| 12787 |
if (dep_type == 0 |
| 12788 |
&& CALL_P (insn)) |
| 12789 |
return 1; |
| 12790 |
|
| 12791 |
if ((i_pat = single_set (insn)) != NULL |
| 12792 |
&& MEM_P (SET_SRC (i_pat)) |
| 12793 |
&& (d_pat = single_set (dep)) != NULL |
| 12794 |
&& MEM_P (SET_DEST (d_pat))) |
| 12795 |
{ |
| 12796 |
rtx src_mem = XEXP (SET_SRC (i_pat), 0); |
| 12797 |
/* This is a load after a store, there is no conflict if the load reads |
| 12798 |
from a cached area. Assume that loads from the stack, and from the |
| 12799 |
constant pool are cached, and that others will miss. This is a |
| 12800 |
hack. */ |
| 12801 |
|
| 12802 |
if ((SYMBOL_REF_P (src_mem) |
| 12803 |
&& CONSTANT_POOL_ADDRESS_P (src_mem)) |
| 12804 |
|| reg_mentioned_p (stack_pointer_rtx, src_mem) |
| 12805 |
|| reg_mentioned_p (frame_pointer_rtx, src_mem) |
| 12806 |
|| reg_mentioned_p (hard_frame_pointer_rtx, src_mem)) |
| 12807 |
return 1; |
| 12808 |
} |
| 12809 |
|
| 12810 |
return cost; |
| 12811 |
} |
| 12812 |
|
| 12813 |
int |
| 12814 |
arm_max_conditional_execute (void) |
| 12815 |
{ |
| 12816 |
return max_insns_skipped; |
| 12817 |
} |
| 12818 |
|
| 12819 |
static int |
| 12820 |
arm_default_branch_cost (bool speed_p, bool predictable_p ATTRIBUTE_UNUSED) |
| 12821 |
{ |
| 12822 |
if (TARGET_32BIT) |
| 12823 |
return (TARGET_THUMB2 && !speed_p) ? 1 : 4; |
| 12824 |
else |
| 12825 |
return (optimize > 0) ? 2 : 0; |
| 12826 |
} |
| 12827 |
|
| 12828 |
static int |
| 12829 |
arm_cortex_a5_branch_cost (bool speed_p, bool predictable_p) |
| 12830 |
{ |
| 12831 |
return speed_p ? 0 : arm_default_branch_cost (speed_p, predictable_p); |
| 12832 |
} |
| 12833 |
|
| 12834 |
/* Thumb-2 branches are relatively cheap on Cortex-M processors ("1 + P cycles" |
| 12835 |
on Cortex-M4, where P varies from 1 to 3 according to some criteria), since |
| 12836 |
sequences of non-executed instructions in IT blocks probably take the same |
| 12837 |
amount of time as executed instructions (and the IT instruction itself takes |
| 12838 |
space in icache). This function was experimentally determined to give good |
| 12839 |
results on a popular embedded benchmark. */ |
| 12840 |
|
| 12841 |
static int |
| 12842 |
arm_cortex_m_branch_cost (bool speed_p, bool predictable_p) |
| 12843 |
{ |
| 12844 |
return (TARGET_32BIT && speed_p) ? 1 |
| 12845 |
: arm_default_branch_cost (speed_p, predictable_p); |
| 12846 |
} |
| 12847 |
|
| 12848 |
static int |
| 12849 |
arm_cortex_m7_branch_cost (bool speed_p, bool predictable_p) |
| 12850 |
{ |
| 12851 |
return speed_p ? 0 : arm_default_branch_cost (speed_p, predictable_p); |
| 12852 |
} |
| 12853 |
|
| 12854 |
/* Return TRUE if rtx X is a valid immediate FP constant. */ |
| 12855 |
int |
| 12856 |
arm_const_double_rtx (rtx x) |
| 12857 |
{ |
| 12858 |
return (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT |
| 12859 |
&& x == CONST0_RTX (GET_MODE (x))); |
| 12860 |
} |
| 12861 |
|
| 12862 |
/* VFPv3 has a fairly wide range of representable immediates, formed from |
| 12863 |
"quarter-precision" floating-point values. These can be evaluated using this |
| 12864 |
formula (with ^ for exponentiation): |
| 12865 |
|
| 12866 |
-1^s * n * 2^-r |
| 12867 |
|
| 12868 |
Where 's' is a sign bit (0/1), 'n' and 'r' are integers such that |
| 12869 |
16 <= n <= 31 and 0 <= r <= 7. |
| 12870 |
|
| 12871 |
These values are mapped onto an 8-bit integer ABCDEFGH s.t. |
| 12872 |
|
| 12873 |
- A (most-significant) is the sign bit. |
| 12874 |
- BCD are the exponent (encoded as r XOR 3). |
| 12875 |
- EFGH are the mantissa (encoded as n - 16). |
| 12876 |
*/ |
| 12877 |
|
| 12878 |
/* Return an integer index for a VFPv3 immediate operand X suitable for the |
| 12879 |
fconst[sd] instruction, or -1 if X isn't suitable. */ |
| 12880 |
static int |
| 12881 |
vfp3_const_double_index (rtx x) |
| 12882 |
{ |
| 12883 |
REAL_VALUE_TYPE r, m; |
| 12884 |
int sign, exponent; |
| 12885 |
unsigned HOST_WIDE_INT mantissa, mant_hi; |
| 12886 |
unsigned HOST_WIDE_INT mask; |
| 12887 |
int point_pos = 2 * HOST_BITS_PER_WIDE_INT - 1; |
| 12888 |
bool fail; |
| 12889 |
|
| 12890 |
if (!TARGET_VFP3 || !CONST_DOUBLE_P (x)) |
| 12891 |
return -1; |
| 12892 |
|
| 12893 |
r = *CONST_DOUBLE_REAL_VALUE (x); |
| 12894 |
|
| 12895 |
/* We can't represent these things, so detect them first. */ |
| 12896 |
if (REAL_VALUE_ISINF (r) || REAL_VALUE_ISNAN (r) || REAL_VALUE_MINUS_ZERO (r)) |
| 12897 |
return -1; |
| 12898 |
|
| 12899 |
/* Extract sign, exponent and mantissa. */ |
| 12900 |
sign = REAL_VALUE_NEGATIVE (r) ? 1 : 0; |
| 12901 |
r = real_value_abs (&r); |
| 12902 |
exponent = REAL_EXP (&r); |
| 12903 |
/* For the mantissa, we expand into two HOST_WIDE_INTS, apart from the |
| 12904 |
highest (sign) bit, with a fixed binary point at bit point_pos. |
| 12905 |
WARNING: If there's ever a VFP version which uses more than 2 * H_W_I - 1 |
| 12906 |
bits for the mantissa, this may fail (low bits would be lost). */ |
| 12907 |
real_ldexp (&m, &r, point_pos - exponent); |
| 12908 |
wide_int w = real_to_integer (&m, &fail, HOST_BITS_PER_WIDE_INT * 2); |
| 12909 |
mantissa = w.elt (0); |
| 12910 |
mant_hi = w.elt (1); |
| 12911 |
|
| 12912 |
/* If there are bits set in the low part of the mantissa, we can't |
| 12913 |
represent this value. */ |
| 12914 |
if (mantissa != 0) |
| 12915 |
return -1; |
| 12916 |
|
| 12917 |
/* Now make it so that mantissa contains the most-significant bits, and move |
| 12918 |
the point_pos to indicate that the least-significant bits have been |
| 12919 |
discarded. */ |
| 12920 |
point_pos -= HOST_BITS_PER_WIDE_INT; |
| 12921 |
mantissa = mant_hi; |
| 12922 |
|
| 12923 |
/* We can permit four significant bits of mantissa only, plus a high bit |
| 12924 |
which is always 1. */ |
| 12925 |
mask = (HOST_WIDE_INT_1U << (point_pos - 5)) - 1; |
| 12926 |
if ((mantissa & mask) != 0) |
| 12927 |
return -1; |
| 12928 |
|
| 12929 |
/* Now we know the mantissa is in range, chop off the unneeded bits. */ |
| 12930 |
mantissa >>= point_pos - 5; |
| 12931 |
|
| 12932 |
/* The mantissa may be zero. Disallow that case. (It's possible to load the |
| 12933 |
floating-point immediate zero with Neon using an integer-zero load, but |
| 12934 |
that case is handled elsewhere.) */ |
| 12935 |
if (mantissa == 0) |
| 12936 |
return -1; |
| 12937 |
|
| 12938 |
gcc_assert (mantissa >= 16 && mantissa <= 31); |
| 12939 |
|
| 12940 |
/* The value of 5 here would be 4 if GCC used IEEE754-like encoding (where |
| 12941 |
normalized significands are in the range [1, 2). (Our mantissa is shifted |
| 12942 |
left 4 places at this point relative to normalized IEEE754 values). GCC |
| 12943 |
internally uses [0.5, 1) (see real.cc), so the exponent returned from |
| 12944 |
REAL_EXP must be altered. */ |
| 12945 |
exponent = 5 - exponent; |
| 12946 |
|
| 12947 |
if (exponent < 0 || exponent > 7) |
| 12948 |
return -1; |
| 12949 |
|
| 12950 |
/* Sign, mantissa and exponent are now in the correct form to plug into the |
| 12951 |
formula described in the comment above. */ |
| 12952 |
return (sign << 7) | ((exponent ^ 3) << 4) | (mantissa - 16); |
| 12953 |
} |
| 12954 |
|
| 12955 |
/* Return TRUE if rtx X is a valid immediate VFPv3 constant. */ |
| 12956 |
int |
| 12957 |
vfp3_const_double_rtx (rtx x) |
| 12958 |
{ |
| 12959 |
if (!TARGET_VFP3) |
| 12960 |
return 0; |
| 12961 |
|
| 12962 |
return vfp3_const_double_index (x) != -1; |
| 12963 |
} |
| 12964 |
|
| 12965 |
/* Recognize immediates which can be used in various Neon and MVE instructions. |
| 12966 |
Legal immediates are described by the following table (for VMVN variants, the |
| 12967 |
bitwise inverse of the constant shown is recognized. In either case, VMOV |
| 12968 |
is output and the correct instruction to use for a given constant is chosen |
| 12969 |
by the assembler). The constant shown is replicated across all elements of |
| 12970 |
the destination vector. |
| 12971 |
|
| 12972 |
insn elems variant constant (binary) |
| 12973 |
---- ----- ------- ----------------- |
| 12974 |
vmov i32 0 00000000 00000000 00000000 abcdefgh |
| 12975 |
vmov i32 1 00000000 00000000 abcdefgh 00000000 |
| 12976 |
vmov i32 2 00000000 abcdefgh 00000000 00000000 |
| 12977 |
vmov i32 3 abcdefgh 00000000 00000000 00000000 |
| 12978 |
vmov i16 4 00000000 abcdefgh |
| 12979 |
vmov i16 5 abcdefgh 00000000 |
| 12980 |
vmvn i32 6 00000000 00000000 00000000 abcdefgh |
| 12981 |
vmvn i32 7 00000000 00000000 abcdefgh 00000000 |
| 12982 |
vmvn i32 8 00000000 abcdefgh 00000000 00000000 |
| 12983 |
vmvn i32 9 abcdefgh 00000000 00000000 00000000 |
| 12984 |
vmvn i16 10 00000000 abcdefgh |
| 12985 |
vmvn i16 11 abcdefgh 00000000 |
| 12986 |
vmov i32 12 00000000 00000000 abcdefgh 11111111 |
| 12987 |
vmvn i32 13 00000000 00000000 abcdefgh 11111111 |
| 12988 |
vmov i32 14 00000000 abcdefgh 11111111 11111111 |
| 12989 |
vmvn i32 15 00000000 abcdefgh 11111111 11111111 |
| 12990 |
vmov i8 16 abcdefgh |
| 12991 |
vmov i64 17 aaaaaaaa bbbbbbbb cccccccc dddddddd |
| 12992 |
eeeeeeee ffffffff gggggggg hhhhhhhh |
| 12993 |
vmov f32 18 aBbbbbbc defgh000 00000000 00000000 |
| 12994 |
vmov f32 19 00000000 00000000 00000000 00000000 |
| 12995 |
|
| 12996 |
For case 18, B = !b. Representable values are exactly those accepted by |
| 12997 |
vfp3_const_double_index, but are output as floating-point numbers rather |
| 12998 |
than indices. |
| 12999 |
|
| 13000 |
For case 19, we will change it to vmov.i32 when assembling. |
| 13001 |
|
| 13002 |
Variants 0-5 (inclusive) may also be used as immediates for the second |
| 13003 |
operand of VORR/VBIC instructions. |
| 13004 |
|
| 13005 |
The INVERSE argument causes the bitwise inverse of the given operand to be |
| 13006 |
recognized instead (used for recognizing legal immediates for the VAND/VORN |
| 13007 |
pseudo-instructions). If INVERSE is true, the value placed in *MODCONST is |
| 13008 |
*not* inverted (i.e. the pseudo-instruction forms vand/vorn should still be |
| 13009 |
output, rather than the real insns vbic/vorr). |
| 13010 |
|
| 13011 |
INVERSE makes no difference to the recognition of float vectors. |
| 13012 |
|
| 13013 |
The return value is the variant of immediate as shown in the above table, or |
| 13014 |
-1 if the given value doesn't match any of the listed patterns. |
| 13015 |
*/ |
| 13016 |
static int |
| 13017 |
simd_valid_immediate (rtx op, machine_mode mode, int inverse, |
| 13018 |
rtx *modconst, int *elementwidth) |
| 13019 |
{ |
| 13020 |
#define CHECK(STRIDE, ELSIZE, CLASS, TEST) \ |
| 13021 |
matches = 1; \ |
| 13022 |
for (i = 0; i < idx; i += (STRIDE)) \ |
| 13023 |
if (!(TEST)) \ |
| 13024 |
matches = 0; \ |
| 13025 |
if (matches) \ |
| 13026 |
{ \ |
| 13027 |
immtype = (CLASS); \ |
| 13028 |
elsize = (ELSIZE); \ |
| 13029 |
break; \ |
| 13030 |
} |
| 13031 |
|
| 13032 |
unsigned int i, elsize = 0, idx = 0, n_elts; |
| 13033 |
unsigned int innersize; |
| 13034 |
unsigned char bytes[16] = {}; |
| 13035 |
int immtype = -1, matches; |
| 13036 |
unsigned int invmask = inverse ? 0xff : 0; |
| 13037 |
bool vector = GET_CODE (op) == CONST_VECTOR; |
| 13038 |
|
| 13039 |
if (vector) |
| 13040 |
n_elts = CONST_VECTOR_NUNITS (op); |
| 13041 |
else |
| 13042 |
{ |
| 13043 |
n_elts = 1; |
| 13044 |
gcc_assert (mode != VOIDmode); |
| 13045 |
} |
| 13046 |
|
| 13047 |
innersize = GET_MODE_UNIT_SIZE (mode); |
| 13048 |
|
| 13049 |
/* Only support 128-bit vectors for MVE. */ |
| 13050 |
if (TARGET_HAVE_MVE |
| 13051 |
&& (!vector |
| 13052 |
|| VALID_MVE_PRED_MODE (mode) |
| 13053 |
|| n_elts * innersize != 16)) |
| 13054 |
return -1; |
| 13055 |
|
| 13056 |
if (!TARGET_HAVE_MVE && GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL) |
| 13057 |
return -1; |
| 13058 |
|
| 13059 |
/* Vectors of float constants. */ |
| 13060 |
if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT) |
| 13061 |
{ |
| 13062 |
rtx el0 = CONST_VECTOR_ELT (op, 0); |
| 13063 |
|
| 13064 |
if (!vfp3_const_double_rtx (el0) && el0 != CONST0_RTX (GET_MODE (el0))) |
| 13065 |
return -1; |
| 13066 |
|
| 13067 |
/* FP16 vectors cannot be represented. */ |
| 13068 |
if (GET_MODE_INNER (mode) == HFmode) |
| 13069 |
return -1; |
| 13070 |
|
| 13071 |
/* All elements in the vector must be the same. Note that 0.0 and -0.0 |
| 13072 |
are distinct in this context. */ |
| 13073 |
if (!const_vec_duplicate_p (op)) |
| 13074 |
return -1; |
| 13075 |
|
| 13076 |
if (modconst) |
| 13077 |
*modconst = CONST_VECTOR_ELT (op, 0); |
| 13078 |
|
| 13079 |
if (elementwidth) |
| 13080 |
*elementwidth = 0; |
| 13081 |
|
| 13082 |
if (el0 == CONST0_RTX (GET_MODE (el0))) |
| 13083 |
return 19; |
| 13084 |
else |
| 13085 |
return 18; |
| 13086 |
} |
| 13087 |
|
| 13088 |
/* The tricks done in the code below apply for little-endian vector layout. |
| 13089 |
For big-endian vectors only allow vectors of the form { a, a, a..., a }. |
| 13090 |
FIXME: Implement logic for big-endian vectors. */ |
| 13091 |
if (BYTES_BIG_ENDIAN && vector && !const_vec_duplicate_p (op)) |
| 13092 |
return -1; |
| 13093 |
|
| 13094 |
/* Splat vector constant out into a byte vector. */ |
| 13095 |
for (i = 0; i < n_elts; i++) |
| 13096 |
{ |
| 13097 |
rtx el = vector ? CONST_VECTOR_ELT (op, i) : op; |
| 13098 |
unsigned HOST_WIDE_INT elpart; |
| 13099 |
|
| 13100 |
gcc_assert (CONST_INT_P (el)); |
| 13101 |
elpart = INTVAL (el); |
| 13102 |
|
| 13103 |
for (unsigned int byte = 0; byte < innersize; byte++) |
| 13104 |
{ |
| 13105 |
bytes[idx++] = (elpart & 0xff) ^ invmask; |
| 13106 |
elpart >>= BITS_PER_UNIT; |
| 13107 |
} |
| 13108 |
} |
| 13109 |
|
| 13110 |
/* Sanity check. */ |
| 13111 |
gcc_assert (idx == GET_MODE_SIZE (mode)); |
| 13112 |
|
| 13113 |
do |
| 13114 |
{ |
| 13115 |
CHECK (4, 32, 0, bytes[i] == bytes[0] && bytes[i + 1] == 0 |
| 13116 |
&& bytes[i + 2] == 0 && bytes[i + 3] == 0); |
| 13117 |
|
| 13118 |
CHECK (4, 32, 1, bytes[i] == 0 && bytes[i + 1] == bytes[1] |
| 13119 |
&& bytes[i + 2] == 0 && bytes[i + 3] == 0); |
| 13120 |
|
| 13121 |
CHECK (4, 32, 2, bytes[i] == 0 && bytes[i + 1] == 0 |
| 13122 |
&& bytes[i + 2] == bytes[2] && bytes[i + 3] == 0); |
| 13123 |
|
| 13124 |
CHECK (4, 32, 3, bytes[i] == 0 && bytes[i + 1] == 0 |
| 13125 |
&& bytes[i + 2] == 0 && bytes[i + 3] == bytes[3]); |
| 13126 |
|
| 13127 |
CHECK (2, 16, 4, bytes[i] == bytes[0] && bytes[i + 1] == 0); |
| 13128 |
|
| 13129 |
CHECK (2, 16, 5, bytes[i] == 0 && bytes[i + 1] == bytes[1]); |
| 13130 |
|
| 13131 |
CHECK (4, 32, 6, bytes[i] == bytes[0] && bytes[i + 1] == 0xff |
| 13132 |
&& bytes[i + 2] == 0xff && bytes[i + 3] == 0xff); |
| 13133 |
|
| 13134 |
CHECK (4, 32, 7, bytes[i] == 0xff && bytes[i + 1] == bytes[1] |
| 13135 |
&& bytes[i + 2] == 0xff && bytes[i + 3] == 0xff); |
| 13136 |
|
| 13137 |
CHECK (4, 32, 8, bytes[i] == 0xff && bytes[i + 1] == 0xff |
| 13138 |
&& bytes[i + 2] == bytes[2] && bytes[i + 3] == 0xff); |
| 13139 |
|
| 13140 |
CHECK (4, 32, 9, bytes[i] == 0xff && bytes[i + 1] == 0xff |
| 13141 |
&& bytes[i + 2] == 0xff && bytes[i + 3] == bytes[3]); |
| 13142 |
|
| 13143 |
CHECK (2, 16, 10, bytes[i] == bytes[0] && bytes[i + 1] == 0xff); |
| 13144 |
|
| 13145 |
CHECK (2, 16, 11, bytes[i] == 0xff && bytes[i + 1] == bytes[1]); |
| 13146 |
|
| 13147 |
CHECK (4, 32, 12, bytes[i] == 0xff && bytes[i + 1] == bytes[1] |
| 13148 |
&& bytes[i + 2] == 0 && bytes[i + 3] == 0); |
| 13149 |
|
| 13150 |
CHECK (4, 32, 13, bytes[i] == 0 && bytes[i + 1] == bytes[1] |
| 13151 |
&& bytes[i + 2] == 0xff && bytes[i + 3] == 0xff); |
| 13152 |
|
| 13153 |
CHECK (4, 32, 14, bytes[i] == 0xff && bytes[i + 1] == 0xff |
| 13154 |
&& bytes[i + 2] == bytes[2] && bytes[i + 3] == 0); |
| 13155 |
|
| 13156 |
CHECK (4, 32, 15, bytes[i] == 0 && bytes[i + 1] == 0 |
| 13157 |
&& bytes[i + 2] == bytes[2] && bytes[i + 3] == 0xff); |
| 13158 |
|
| 13159 |
CHECK (1, 8, 16, bytes[i] == bytes[0]); |
| 13160 |
|
| 13161 |
CHECK (1, 64, 17, (bytes[i] == 0 || bytes[i] == 0xff) |
| 13162 |
&& bytes[i] == bytes[(i + 8) % idx]); |
| 13163 |
} |
| 13164 |
while (0); |
| 13165 |
|
| 13166 |
if (immtype == -1) |
| 13167 |
return -1; |
| 13168 |
|
| 13169 |
if (elementwidth) |
| 13170 |
*elementwidth = elsize; |
| 13171 |
|
| 13172 |
if (modconst) |
| 13173 |
{ |
| 13174 |
unsigned HOST_WIDE_INT imm = 0; |
| 13175 |
|
| 13176 |
/* Un-invert bytes of recognized vector, if necessary. */ |
| 13177 |
if (invmask != 0) |
| 13178 |
for (i = 0; i < idx; i++) |
| 13179 |
bytes[i] ^= invmask; |
| 13180 |
|
| 13181 |
if (immtype == 17) |
| 13182 |
{ |
| 13183 |
/* FIXME: Broken on 32-bit H_W_I hosts. */ |
| 13184 |
gcc_assert (sizeof (HOST_WIDE_INT) == 8); |
| 13185 |
|
| 13186 |
for (i = 0; i < 8; i++) |
| 13187 |
imm |= (unsigned HOST_WIDE_INT) (bytes[i] ? 0xff : 0) |
| 13188 |
<< (i * BITS_PER_UNIT); |
| 13189 |
|
| 13190 |
*modconst = GEN_INT (imm); |
| 13191 |
} |
| 13192 |
else |
| 13193 |
{ |
| 13194 |
unsigned HOST_WIDE_INT imm = 0; |
| 13195 |
|
| 13196 |
for (i = 0; i < elsize / BITS_PER_UNIT; i++) |
| 13197 |
imm |= (unsigned HOST_WIDE_INT) bytes[i] << (i * BITS_PER_UNIT); |
| 13198 |
|
| 13199 |
*modconst = GEN_INT (imm); |
| 13200 |
} |
| 13201 |
} |
| 13202 |
|
| 13203 |
return immtype; |
| 13204 |
#undef CHECK |
| 13205 |
} |
| 13206 |
|
| 13207 |
/* Return TRUE if rtx X is legal for use as either a Neon or MVE VMOV (or, |
| 13208 |
implicitly, VMVN) immediate. Write back width per element to *ELEMENTWIDTH |
| 13209 |
(or zero for float elements), and a modified constant (whatever should be |
| 13210 |
output for a VMOV) in *MODCONST. "neon_immediate_valid_for_move" function is |
| 13211 |
modified to "simd_immediate_valid_for_move" as this function will be used |
| 13212 |
both by neon and mve. */ |
| 13213 |
int |
| 13214 |
simd_immediate_valid_for_move (rtx op, machine_mode mode, |
| 13215 |
rtx *modconst, int *elementwidth) |
| 13216 |
{ |
| 13217 |
rtx tmpconst; |
| 13218 |
int tmpwidth; |
| 13219 |
int retval = simd_valid_immediate (op, mode, 0, &tmpconst, &tmpwidth); |
| 13220 |
|
| 13221 |
if (retval == -1) |
| 13222 |
return 0; |
| 13223 |
|
| 13224 |
if (modconst) |
| 13225 |
*modconst = tmpconst; |
| 13226 |
|
| 13227 |
if (elementwidth) |
| 13228 |
*elementwidth = tmpwidth; |
| 13229 |
|
| 13230 |
return 1; |
| 13231 |
} |
| 13232 |
|
| 13233 |
/* Return TRUE if rtx X is legal for use in a VORR or VBIC instruction. If |
| 13234 |
the immediate is valid, write a constant suitable for using as an operand |
| 13235 |
to VORR/VBIC/VAND/VORN to *MODCONST and the corresponding element width to |
| 13236 |
*ELEMENTWIDTH. See simd_valid_immediate for description of INVERSE. */ |
| 13237 |
|
| 13238 |
int |
| 13239 |
neon_immediate_valid_for_logic (rtx op, machine_mode mode, int inverse, |
| 13240 |
rtx *modconst, int *elementwidth) |
| 13241 |
{ |
| 13242 |
rtx tmpconst; |
| 13243 |
int tmpwidth; |
| 13244 |
int retval = simd_valid_immediate (op, mode, inverse, &tmpconst, &tmpwidth); |
| 13245 |
|
| 13246 |
if (retval < 0 || retval > 5) |
| 13247 |
return 0; |
| 13248 |
|
| 13249 |
if (modconst) |
| 13250 |
*modconst = tmpconst; |
| 13251 |
|
| 13252 |
if (elementwidth) |
| 13253 |
*elementwidth = tmpwidth; |
| 13254 |
|
| 13255 |
return 1; |
| 13256 |
} |
| 13257 |
|
| 13258 |
/* Return TRUE if rtx OP is legal for use in a VSHR or VSHL instruction. If |
| 13259 |
the immediate is valid, write a constant suitable for using as an operand |
| 13260 |
to VSHR/VSHL to *MODCONST and the corresponding element width to |
| 13261 |
*ELEMENTWIDTH. ISLEFTSHIFT is for determine left or right shift, |
| 13262 |
because they have different limitations. */ |
| 13263 |
|
| 13264 |
int |
| 13265 |
neon_immediate_valid_for_shift (rtx op, machine_mode mode, |
| 13266 |
rtx *modconst, int *elementwidth, |
| 13267 |
bool isleftshift) |
| 13268 |
{ |
| 13269 |
unsigned int innersize = GET_MODE_UNIT_SIZE (mode); |
| 13270 |
unsigned int n_elts = CONST_VECTOR_NUNITS (op), i; |
| 13271 |
unsigned HOST_WIDE_INT last_elt = 0; |
| 13272 |
unsigned HOST_WIDE_INT maxshift; |
| 13273 |
|
| 13274 |
/* Split vector constant out into a byte vector. */ |
| 13275 |
for (i = 0; i < n_elts; i++) |
| 13276 |
{ |
| 13277 |
rtx el = CONST_VECTOR_ELT (op, i); |
| 13278 |
unsigned HOST_WIDE_INT elpart; |
| 13279 |
|
| 13280 |
if (CONST_INT_P (el)) |
| 13281 |
elpart = INTVAL (el); |
| 13282 |
else if (CONST_DOUBLE_P (el)) |
| 13283 |
return 0; |
| 13284 |
else |
| 13285 |
gcc_unreachable (); |
| 13286 |
|
| 13287 |
if (i != 0 && elpart != last_elt) |
| 13288 |
return 0; |
| 13289 |
|
| 13290 |
last_elt = elpart; |
| 13291 |
} |
| 13292 |
|
| 13293 |
/* Shift less than element size. */ |
| 13294 |
maxshift = innersize * 8; |
| 13295 |
|
| 13296 |
if (isleftshift) |
| 13297 |
{ |
| 13298 |
/* Left shift immediate value can be from 0 to <size>-1. */ |
| 13299 |
if (last_elt >= maxshift) |
| 13300 |
return 0; |
| 13301 |
} |
| 13302 |
else |
| 13303 |
{ |
| 13304 |
/* Right shift immediate value can be from 1 to <size>. */ |
| 13305 |
if (last_elt == 0 || last_elt > maxshift) |
| 13306 |
return 0; |
| 13307 |
} |
| 13308 |
|
| 13309 |
if (elementwidth) |
| 13310 |
*elementwidth = innersize * 8; |
| 13311 |
|
| 13312 |
if (modconst) |
| 13313 |
*modconst = CONST_VECTOR_ELT (op, 0); |
| 13314 |
|
| 13315 |
return 1; |
| 13316 |
} |
| 13317 |
|
| 13318 |
/* Return a string suitable for output of Neon immediate logic operation |
| 13319 |
MNEM. */ |
| 13320 |
|
| 13321 |
char * |
| 13322 |
neon_output_logic_immediate (const char *mnem, rtx *op2, machine_mode mode, |
| 13323 |
int inverse, int quad) |
| 13324 |
{ |
| 13325 |
int width, is_valid; |
| 13326 |
static char templ[40]; |
| 13327 |
|
| 13328 |
is_valid = neon_immediate_valid_for_logic (*op2, mode, inverse, op2, &width); |
| 13329 |
|
| 13330 |
gcc_assert (is_valid != 0); |
| 13331 |
|
| 13332 |
if (quad) |
| 13333 |
sprintf (templ, "%s.i%d\t%%q0, %%2", mnem, width); |
| 13334 |
else |
| 13335 |
sprintf (templ, "%s.i%d\t%%P0, %%2", mnem, width); |
| 13336 |
|
| 13337 |
return templ; |
| 13338 |
} |
| 13339 |
|
| 13340 |
/* Return a string suitable for output of Neon immediate shift operation |
| 13341 |
(VSHR or VSHL) MNEM. */ |
| 13342 |
|
| 13343 |
char * |
| 13344 |
neon_output_shift_immediate (const char *mnem, char sign, rtx *op2, |
| 13345 |
machine_mode mode, int quad, |
| 13346 |
bool isleftshift) |
| 13347 |
{ |
| 13348 |
int width, is_valid; |
| 13349 |
static char templ[40]; |
| 13350 |
|
| 13351 |
is_valid = neon_immediate_valid_for_shift (*op2, mode, op2, &width, isleftshift); |
| 13352 |
gcc_assert (is_valid != 0); |
| 13353 |
|
| 13354 |
if (quad) |
| 13355 |
sprintf (templ, "%s.%c%d\t%%q0, %%q1, %%2", mnem, sign, width); |
| 13356 |
else |
| 13357 |
sprintf (templ, "%s.%c%d\t%%P0, %%P1, %%2", mnem, sign, width); |
| 13358 |
|
| 13359 |
return templ; |
| 13360 |
} |
| 13361 |
|
| 13362 |
/* Output a sequence of pairwise operations to implement a reduction. |
| 13363 |
NOTE: We do "too much work" here, because pairwise operations work on two |
| 13364 |
registers-worth of operands in one go. Unfortunately we can't exploit those |
| 13365 |
extra calculations to do the full operation in fewer steps, I don't think. |
| 13366 |
Although all vector elements of the result but the first are ignored, we |
| 13367 |
actually calculate the same result in each of the elements. An alternative |
| 13368 |
such as initially loading a vector with zero to use as each of the second |
| 13369 |
operands would use up an additional register and take an extra instruction, |
| 13370 |
for no particular gain. */ |
| 13371 |
|
| 13372 |
void |
| 13373 |
neon_pairwise_reduce (rtx op0, rtx op1, machine_mode mode, |
| 13374 |
rtx (*reduc) (rtx, rtx, rtx)) |
| 13375 |
{ |
| 13376 |
unsigned int i, parts = GET_MODE_SIZE (mode) / GET_MODE_UNIT_SIZE (mode); |
| 13377 |
rtx tmpsum = op1; |
| 13378 |
|
| 13379 |
for (i = parts / 2; i >= 1; i /= 2) |
| 13380 |
{ |
| 13381 |
rtx dest = (i == 1) ? op0 : gen_reg_rtx (mode); |
| 13382 |
emit_insn (reduc (dest, tmpsum, tmpsum)); |
| 13383 |
tmpsum = dest; |
| 13384 |
} |
| 13385 |
} |
| 13386 |
|
| 13387 |
/* Return a non-NULL RTX iff VALS is a vector constant that can be |
| 13388 |
loaded into a register using VDUP. |
| 13389 |
|
| 13390 |
If this is the case, and GENERATE is set, we also generate |
| 13391 |
instructions to do this and return an RTX to assign to the register. */ |
| 13392 |
|
| 13393 |
static rtx |
| 13394 |
neon_vdup_constant (rtx vals, bool generate) |
| 13395 |
{ |
| 13396 |
machine_mode mode = GET_MODE (vals); |
| 13397 |
machine_mode inner_mode = GET_MODE_INNER (mode); |
| 13398 |
rtx x; |
| 13399 |
|
| 13400 |
if (GET_CODE (vals) != CONST_VECTOR || GET_MODE_SIZE (inner_mode) > 4) |
| 13401 |
return NULL_RTX; |
| 13402 |
|
| 13403 |
if (!const_vec_duplicate_p (vals, &x)) |
| 13404 |
/* The elements are not all the same. We could handle repeating |
| 13405 |
patterns of a mode larger than INNER_MODE here (e.g. int8x8_t |
| 13406 |
{0, C, 0, C, 0, C, 0, C} which can be loaded using |
| 13407 |
vdup.i16). */ |
| 13408 |
return NULL_RTX; |
| 13409 |
|
| 13410 |
if (!generate) |
| 13411 |
return x; |
| 13412 |
|
| 13413 |
/* We can load this constant by using VDUP and a constant in a |
| 13414 |
single ARM register. This will be cheaper than a vector |
| 13415 |
load. */ |
| 13416 |
|
| 13417 |
x = copy_to_mode_reg (inner_mode, x); |
| 13418 |
return gen_vec_duplicate (mode, x); |
| 13419 |
} |
| 13420 |
|
| 13421 |
/* Return a HI representation of CONST_VEC suitable for MVE predicates. */ |
| 13422 |
rtx |
| 13423 |
mve_bool_vec_to_const (rtx const_vec) |
| 13424 |
{ |
| 13425 |
machine_mode mode = GET_MODE (const_vec); |
| 13426 |
|
| 13427 |
if (!VECTOR_MODE_P (mode)) |
| 13428 |
return const_vec; |
| 13429 |
|
| 13430 |
unsigned n_elts = GET_MODE_NUNITS (mode); |
| 13431 |
unsigned el_prec = GET_MODE_PRECISION (GET_MODE_INNER (mode)); |
| 13432 |
unsigned shift_c = 16 / n_elts; |
| 13433 |
unsigned i; |
| 13434 |
int hi_val = 0; |
| 13435 |
|
| 13436 |
for (i = 0; i < n_elts; i++) |
| 13437 |
{ |
| 13438 |
rtx el = CONST_VECTOR_ELT (const_vec, i); |
| 13439 |
unsigned HOST_WIDE_INT elpart; |
| 13440 |
|
| 13441 |
gcc_assert (CONST_INT_P (el)); |
| 13442 |
elpart = INTVAL (el) & ((1U << el_prec) - 1); |
| 13443 |
|
| 13444 |
unsigned index = BYTES_BIG_ENDIAN ? n_elts - i - 1 : i; |
| 13445 |
|
| 13446 |
hi_val |= elpart << (index * shift_c); |
| 13447 |
} |
| 13448 |
/* We are using mov immediate to encode this constant which writes 32-bits |
| 13449 |
so we need to make sure the top 16-bits are all 0, otherwise we can't |
| 13450 |
guarantee we can actually write this immediate. */ |
| 13451 |
return gen_int_mode (hi_val, SImode); |
| 13452 |
} |
| 13453 |
|
| 13454 |
/* Return a non-NULL RTX iff VALS, which is a PARALLEL containing only |
| 13455 |
constants (for vec_init) or CONST_VECTOR, can be effeciently loaded |
| 13456 |
into a register. |
| 13457 |
|
| 13458 |
If this is the case, and GENERATE is set, we also generate code to do |
| 13459 |
this and return an RTX to copy into the register. */ |
| 13460 |
|
| 13461 |
rtx |
| 13462 |
neon_make_constant (rtx vals, bool generate) |
| 13463 |
{ |
| 13464 |
machine_mode mode = GET_MODE (vals); |
| 13465 |
rtx target; |
| 13466 |
rtx const_vec = NULL_RTX; |
| 13467 |
int n_elts = GET_MODE_NUNITS (mode); |
| 13468 |
int n_const = 0; |
| 13469 |
int i; |
| 13470 |
|
| 13471 |
if (GET_CODE (vals) == CONST_VECTOR) |
| 13472 |
const_vec = vals; |
| 13473 |
else if (GET_CODE (vals) == PARALLEL) |
| 13474 |
{ |
| 13475 |
/* A CONST_VECTOR must contain only CONST_INTs and |
| 13476 |
CONST_DOUBLEs, but CONSTANT_P allows more (e.g. SYMBOL_REF). |
| 13477 |
Only store valid constants in a CONST_VECTOR. */ |
| 13478 |
for (i = 0; i < n_elts; ++i) |
| 13479 |
{ |
| 13480 |
rtx x = XVECEXP (vals, 0, i); |
| 13481 |
if (CONST_INT_P (x) || CONST_DOUBLE_P (x)) |
| 13482 |
n_const++; |
| 13483 |
} |
| 13484 |
if (n_const == n_elts) |
| 13485 |
const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)); |
| 13486 |
} |
| 13487 |
else |
| 13488 |
gcc_unreachable (); |
| 13489 |
|
| 13490 |
if (const_vec != NULL |
| 13491 |
&& simd_immediate_valid_for_move (const_vec, mode, NULL, NULL)) |
| 13492 |
/* Load using VMOV. On Cortex-A8 this takes one cycle. */ |
| 13493 |
return const_vec; |
| 13494 |
else if (TARGET_HAVE_MVE && VALID_MVE_PRED_MODE(mode)) |
| 13495 |
return mve_bool_vec_to_const (const_vec); |
| 13496 |
else if ((target = neon_vdup_constant (vals, generate)) != NULL_RTX) |
| 13497 |
/* Loaded using VDUP. On Cortex-A8 the VDUP takes one NEON |
| 13498 |
pipeline cycle; creating the constant takes one or two ARM |
| 13499 |
pipeline cycles. */ |
| 13500 |
return target; |
| 13501 |
else if (const_vec != NULL_RTX) |
| 13502 |
/* Load from constant pool. On Cortex-A8 this takes two cycles |
| 13503 |
(for either double or quad vectors). We cannot take advantage |
| 13504 |
of single-cycle VLD1 because we need a PC-relative addressing |
| 13505 |
mode. */ |
| 13506 |
return arm_disable_literal_pool ? NULL_RTX : const_vec; |
| 13507 |
else |
| 13508 |
/* A PARALLEL containing something not valid inside CONST_VECTOR. |
| 13509 |
We cannot construct an initializer. */ |
| 13510 |
return NULL_RTX; |
| 13511 |
} |
| 13512 |
|
| 13513 |
/* Initialize vector TARGET to VALS. */ |
| 13514 |
|
| 13515 |
void |
| 13516 |
neon_expand_vector_init (rtx target, rtx vals) |
| 13517 |
{ |
| 13518 |
machine_mode mode = GET_MODE (target); |
| 13519 |
machine_mode inner_mode = GET_MODE_INNER (mode); |
| 13520 |
int n_elts = GET_MODE_NUNITS (mode); |
| 13521 |
int n_var = 0, one_var = -1; |
| 13522 |
bool all_same = true; |
| 13523 |
rtx x, mem; |
| 13524 |
int i; |
| 13525 |
|
| 13526 |
for (i = 0; i < n_elts; ++i) |
| 13527 |
{ |
| 13528 |
x = XVECEXP (vals, 0, i); |
| 13529 |
if (!CONSTANT_P (x)) |
| 13530 |
++n_var, one_var = i; |
| 13531 |
|
| 13532 |
if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0))) |
| 13533 |
all_same = false; |
| 13534 |
} |
| 13535 |
|
| 13536 |
if (n_var == 0) |
| 13537 |
{ |
| 13538 |
rtx constant = neon_make_constant (vals); |
| 13539 |
if (constant != NULL_RTX) |
| 13540 |
{ |
| 13541 |
emit_move_insn (target, constant); |
| 13542 |
return; |
| 13543 |
} |
| 13544 |
} |
| 13545 |
|
| 13546 |
/* Splat a single non-constant element if we can. */ |
| 13547 |
if (all_same && GET_MODE_SIZE (inner_mode) <= 4) |
| 13548 |
{ |
| 13549 |
x = copy_to_mode_reg (inner_mode, XVECEXP (vals, 0, 0)); |
| 13550 |
emit_insn (gen_rtx_SET (target, gen_vec_duplicate (mode, x))); |
| 13551 |
return; |
| 13552 |
} |
| 13553 |
|
| 13554 |
/* One field is non-constant. Load constant then overwrite varying |
| 13555 |
field. This is more efficient than using the stack. */ |
| 13556 |
if (n_var == 1) |
| 13557 |
{ |
| 13558 |
rtx copy = copy_rtx (vals); |
| 13559 |
rtx merge_mask = GEN_INT (1 << one_var); |
| 13560 |
|
| 13561 |
/* Load constant part of vector, substitute neighboring value for |
| 13562 |
varying element. */ |
| 13563 |
XVECEXP (copy, 0, one_var) = XVECEXP (vals, 0, (one_var + 1) % n_elts); |
| 13564 |
neon_expand_vector_init (target, copy); |
| 13565 |
|
| 13566 |
/* Insert variable. */ |
| 13567 |
x = copy_to_mode_reg (inner_mode, XVECEXP (vals, 0, one_var)); |
| 13568 |
emit_insn (gen_vec_set_internal (mode, target, x, merge_mask, target)); |
| 13569 |
return; |
| 13570 |
} |
| 13571 |
|
| 13572 |
/* Construct the vector in memory one field at a time |
| 13573 |
and load the whole vector. */ |
| 13574 |
mem = assign_stack_temp (mode, GET_MODE_SIZE (mode)); |
| 13575 |
for (i = 0; i < n_elts; i++) |
| 13576 |
emit_move_insn (adjust_address_nv (mem, inner_mode, |
| 13577 |
i * GET_MODE_SIZE (inner_mode)), |
| 13578 |
XVECEXP (vals, 0, i)); |
| 13579 |
emit_move_insn (target, mem); |
| 13580 |
} |
| 13581 |
|
| 13582 |
/* Ensure OPERAND lies between LOW (inclusive) and HIGH (exclusive). Raise |
| 13583 |
ERR if it doesn't. EXP indicates the source location, which includes the |
| 13584 |
inlining history for intrinsics. */ |
| 13585 |
|
| 13586 |
static void |
| 13587 |
bounds_check (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high, |
| 13588 |
const_tree exp, const char *desc) |
| 13589 |
{ |
| 13590 |
HOST_WIDE_INT lane; |
| 13591 |
|
| 13592 |
gcc_assert (CONST_INT_P (operand)); |
| 13593 |
|
| 13594 |
lane = INTVAL (operand); |
| 13595 |
|
| 13596 |
if (lane < low || lane >= high) |
| 13597 |
{ |
| 13598 |
if (exp) |
| 13599 |
error_at (EXPR_LOCATION (exp), |
| 13600 |
"%s %wd out of range %wd - %wd", desc, lane, low, high - 1); |
| 13601 |
else |
| 13602 |
error ("%s %wd out of range %wd - %wd", desc, lane, low, high - 1); |
| 13603 |
} |
| 13604 |
} |
| 13605 |
|
| 13606 |
/* Bounds-check lanes. */ |
| 13607 |
|
| 13608 |
void |
| 13609 |
neon_lane_bounds (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high, |
| 13610 |
const_tree exp) |
| 13611 |
{ |
| 13612 |
bounds_check (operand, low, high, exp, "lane"); |
| 13613 |
} |
| 13614 |
|
| 13615 |
/* Bounds-check constants. */ |
| 13616 |
|
| 13617 |
void |
| 13618 |
arm_const_bounds (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high) |
| 13619 |
{ |
| 13620 |
bounds_check (operand, low, high, NULL_TREE, "constant"); |
| 13621 |
} |
| 13622 |
|
| 13623 |
HOST_WIDE_INT |
| 13624 |
neon_element_bits (machine_mode mode) |
| 13625 |
{ |
| 13626 |
return GET_MODE_UNIT_BITSIZE (mode); |
| 13627 |
} |
| 13628 |
|
| 13629 |
|
| 13630 |
/* Predicates for `match_operand' and `match_operator'. */ |
| 13631 |
|
| 13632 |
/* Return TRUE if OP is a valid coprocessor memory address pattern. |
| 13633 |
WB level is 2 if full writeback address modes are allowed, 1 |
| 13634 |
if limited writeback address modes (POST_INC and PRE_DEC) are |
| 13635 |
allowed and 0 if no writeback at all is supported. */ |
| 13636 |
|
| 13637 |
int |
| 13638 |
arm_coproc_mem_operand_wb (rtx op, int wb_level) |
| 13639 |
{ |
| 13640 |
gcc_assert (wb_level == 0 || wb_level == 1 || wb_level == 2); |
| 13641 |
rtx ind; |
| 13642 |
|
| 13643 |
/* Reject eliminable registers. */ |
| 13644 |
if (! (reload_in_progress || reload_completed || lra_in_progress) |
| 13645 |
&& ( reg_mentioned_p (frame_pointer_rtx, op) |
| 13646 |
|| reg_mentioned_p (arg_pointer_rtx, op) |
| 13647 |
|| reg_mentioned_p (virtual_incoming_args_rtx, op) |
| 13648 |
|| reg_mentioned_p (virtual_outgoing_args_rtx, op) |
| 13649 |
|| reg_mentioned_p (virtual_stack_dynamic_rtx, op) |
| 13650 |
|| reg_mentioned_p (virtual_stack_vars_rtx, op))) |
| 13651 |
return FALSE; |
| 13652 |
|
| 13653 |
/* Constants are converted into offsets from labels. */ |
| 13654 |
if (!MEM_P (op)) |
| 13655 |
return FALSE; |
| 13656 |
|
| 13657 |
ind = XEXP (op, 0); |
| 13658 |
|
| 13659 |
if (reload_completed |
| 13660 |
&& (LABEL_REF_P (ind) |
| 13661 |
|| (GET_CODE (ind) == CONST |
| 13662 |
&& GET_CODE (XEXP (ind, 0)) == PLUS |
| 13663 |
&& GET_CODE (XEXP (XEXP (ind, 0), 0)) == LABEL_REF |
| 13664 |
&& CONST_INT_P (XEXP (XEXP (ind, 0), 1))))) |
| 13665 |
return TRUE; |
| 13666 |
|
| 13667 |
/* Match: (mem (reg)). */ |
| 13668 |
if (REG_P (ind)) |
| 13669 |
return arm_address_register_rtx_p (ind, 0); |
| 13670 |
|
| 13671 |
/* Autoincremment addressing modes. POST_INC and PRE_DEC are |
| 13672 |
acceptable in any case (subject to verification by |
| 13673 |
arm_address_register_rtx_p). We need full writeback to accept |
| 13674 |
PRE_INC and POST_DEC, and at least restricted writeback for |
| 13675 |
PRE_INC and POST_DEC. */ |
| 13676 |
if (wb_level > 0 |
| 13677 |
&& (GET_CODE (ind) == POST_INC |
| 13678 |
|| GET_CODE (ind) == PRE_DEC |
| 13679 |
|| (wb_level > 1 |
| 13680 |
&& (GET_CODE (ind) == PRE_INC |
| 13681 |
|| GET_CODE (ind) == POST_DEC)))) |
| 13682 |
return arm_address_register_rtx_p (XEXP (ind, 0), 0); |
| 13683 |
|
| 13684 |
if (wb_level > 1 |
| 13685 |
&& (GET_CODE (ind) == POST_MODIFY || GET_CODE (ind) == PRE_MODIFY) |
| 13686 |
&& arm_address_register_rtx_p (XEXP (ind, 0), 0) |
| 13687 |
&& GET_CODE (XEXP (ind, 1)) == PLUS |
| 13688 |
&& rtx_equal_p (XEXP (XEXP (ind, 1), 0), XEXP (ind, 0))) |
| 13689 |
ind = XEXP (ind, 1); |
| 13690 |
|
| 13691 |
/* Match: |
| 13692 |
(plus (reg) |
| 13693 |
(const)) |
| 13694 |
|
| 13695 |
The encoded immediate for 16-bit modes is multiplied by 2, |
| 13696 |
while the encoded immediate for 32-bit and 64-bit modes is |
| 13697 |
multiplied by 4. */ |
| 13698 |
int factor = MIN (GET_MODE_SIZE (GET_MODE (op)), 4); |
| 13699 |
if (GET_CODE (ind) == PLUS |
| 13700 |
&& REG_P (XEXP (ind, 0)) |
| 13701 |
&& REG_MODE_OK_FOR_BASE_P (XEXP (ind, 0), VOIDmode) |
| 13702 |
&& CONST_INT_P (XEXP (ind, 1)) |
| 13703 |
&& IN_RANGE (INTVAL (XEXP (ind, 1)), -255 * factor, 255 * factor) |
| 13704 |
&& (INTVAL (XEXP (ind, 1)) & (factor - 1)) == 0) |
| 13705 |
return TRUE; |
| 13706 |
|
| 13707 |
return FALSE; |
| 13708 |
} |
| 13709 |
|
| 13710 |
/* Return TRUE if OP is a valid coprocessor memory address pattern. |
| 13711 |
WB is true if full writeback address modes are allowed and is false |
| 13712 |
if limited writeback address modes (POST_INC and PRE_DEC) are |
| 13713 |
allowed. */ |
| 13714 |
|
| 13715 |
int arm_coproc_mem_operand (rtx op, bool wb) |
| 13716 |
{ |
| 13717 |
return arm_coproc_mem_operand_wb (op, wb ? 2 : 1); |
| 13718 |
} |
| 13719 |
|
| 13720 |
/* Return TRUE if OP is a valid coprocessor memory address pattern in a |
| 13721 |
context in which no writeback address modes are allowed. */ |
| 13722 |
|
| 13723 |
int |
| 13724 |
arm_coproc_mem_operand_no_writeback (rtx op) |
| 13725 |
{ |
| 13726 |
return arm_coproc_mem_operand_wb (op, 0); |
| 13727 |
} |
| 13728 |
|
| 13729 |
/* In non-STRICT mode, return the register number; in STRICT mode return |
| 13730 |
the hard regno or the replacement if it won't be a mem. Otherwise, return |
| 13731 |
the original pseudo number. */ |
| 13732 |
static int |
| 13733 |
arm_effective_regno (rtx op, bool strict) |
| 13734 |
{ |
| 13735 |
gcc_assert (REG_P (op)); |
| 13736 |
if (!strict || REGNO (op) < FIRST_PSEUDO_REGISTER |
| 13737 |
|| !reg_renumber || reg_renumber[REGNO (op)] < 0) |
| 13738 |
return REGNO (op); |
| 13739 |
return reg_renumber[REGNO (op)]; |
| 13740 |
} |
| 13741 |
|
| 13742 |
/* This function returns TRUE on matching mode and op. |
| 13743 |
1. For given modes, check for [Rn], return TRUE for Rn <= LO_REGS. |
| 13744 |
2. For other modes, check for [Rn], return TRUE for Rn < R15 (expect R13). */ |
| 13745 |
int |
| 13746 |
mve_vector_mem_operand (machine_mode mode, rtx op, bool strict) |
| 13747 |
{ |
| 13748 |
enum rtx_code code; |
| 13749 |
int val, reg_no; |
| 13750 |
|
| 13751 |
/* Match: (mem (reg)). */ |
| 13752 |
if (REG_P (op)) |
| 13753 |
{ |
| 13754 |
reg_no = arm_effective_regno (op, strict); |
| 13755 |
return (((mode == E_V8QImode || mode == E_V4QImode || mode == E_V4HImode) |
| 13756 |
? reg_no <= LAST_LO_REGNUM |
| 13757 |
: reg_no < LAST_ARM_REGNUM) |
| 13758 |
|| (!strict && reg_no >= FIRST_PSEUDO_REGISTER)); |
| 13759 |
} |
| 13760 |
code = GET_CODE (op); |
| 13761 |
|
| 13762 |
if ((code == POST_INC |
| 13763 |
|| code == PRE_DEC |
| 13764 |
|| code == PRE_INC |
| 13765 |
|| code == POST_DEC) |
| 13766 |
&& REG_P (XEXP (op, 0))) |
| 13767 |
{ |
| 13768 |
reg_no = arm_effective_regno (XEXP (op, 0), strict); |
| 13769 |
return (((mode == E_V8QImode || mode == E_V4QImode || mode == E_V4HImode) |
| 13770 |
? reg_no <= LAST_LO_REGNUM |
| 13771 |
:(reg_no < LAST_ARM_REGNUM && reg_no != SP_REGNUM)) |
| 13772 |
|| (!strict && reg_no >= FIRST_PSEUDO_REGISTER)); |
| 13773 |
} |
| 13774 |
else if (((code == POST_MODIFY || code == PRE_MODIFY) |
| 13775 |
&& GET_CODE (XEXP (op, 1)) == PLUS |
| 13776 |
&& XEXP (op, 0) == XEXP (XEXP (op, 1), 0) |
| 13777 |
&& REG_P (XEXP (op, 0)) |
| 13778 |
&& GET_CODE (XEXP (XEXP (op, 1), 1)) == CONST_INT) |
| 13779 |
/* Make sure to only accept PLUS after reload_completed, otherwise |
| 13780 |
this will interfere with auto_inc's pattern detection. */ |
| 13781 |
|| (reload_completed && code == PLUS && REG_P (XEXP (op, 0)) |
| 13782 |
&& GET_CODE (XEXP (op, 1)) == CONST_INT)) |
| 13783 |
{ |
| 13784 |
reg_no = arm_effective_regno (XEXP (op, 0), strict); |
| 13785 |
if (code == PLUS) |
| 13786 |
val = INTVAL (XEXP (op, 1)); |
| 13787 |
else |
| 13788 |
val = INTVAL (XEXP(XEXP (op, 1), 1)); |
| 13789 |
|
| 13790 |
switch (mode) |
| 13791 |
{ |
| 13792 |
case E_V16QImode: |
| 13793 |
case E_V8QImode: |
| 13794 |
case E_V4QImode: |
| 13795 |
if (abs (val) > 127) |
| 13796 |
return FALSE; |
| 13797 |
break; |
| 13798 |
case E_V8HImode: |
| 13799 |
case E_V8HFmode: |
| 13800 |
case E_V4HImode: |
| 13801 |
case E_V4HFmode: |
| 13802 |
if (val % 2 != 0 || abs (val) > 254) |
| 13803 |
return FALSE; |
| 13804 |
break; |
| 13805 |
case E_V4SImode: |
| 13806 |
case E_V4SFmode: |
| 13807 |
if (val % 4 != 0 || abs (val) > 508) |
| 13808 |
return FALSE; |
| 13809 |
break; |
| 13810 |
default: |
| 13811 |
return FALSE; |
| 13812 |
} |
| 13813 |
return ((!strict && reg_no >= FIRST_PSEUDO_REGISTER) |
| 13814 |
|| (MVE_STN_LDW_MODE (mode) |
| 13815 |
? reg_no <= LAST_LO_REGNUM |
| 13816 |
: (reg_no < LAST_ARM_REGNUM |
| 13817 |
&& (code == PLUS || reg_no != SP_REGNUM)))); |
| 13818 |
} |
| 13819 |
return FALSE; |
| 13820 |
} |
| 13821 |
|
| 13822 |
/* Return TRUE if OP is a memory operand which we can load or store a vector |
| 13823 |
to/from. TYPE is one of the following values: |
| 13824 |
0 - Vector load/stor (vldr) |
| 13825 |
1 - Core registers (ldm) |
| 13826 |
2 - Element/structure loads (vld1) |
| 13827 |
*/ |
| 13828 |
int |
| 13829 |
neon_vector_mem_operand (rtx op, int type, bool strict) |
| 13830 |
{ |
| 13831 |
rtx ind; |
| 13832 |
|
| 13833 |
/* Reject eliminable registers. */ |
| 13834 |
if (strict && ! (reload_in_progress || reload_completed) |
| 13835 |
&& (reg_mentioned_p (frame_pointer_rtx, op) |
| 13836 |
|| reg_mentioned_p (arg_pointer_rtx, op) |
| 13837 |
|| reg_mentioned_p (virtual_incoming_args_rtx, op) |
| 13838 |
|| reg_mentioned_p (virtual_outgoing_args_rtx, op) |
| 13839 |
|| reg_mentioned_p (virtual_stack_dynamic_rtx, op) |
| 13840 |
|| reg_mentioned_p (virtual_stack_vars_rtx, op))) |
| 13841 |
return FALSE; |
| 13842 |
|
| 13843 |
/* Constants are converted into offsets from labels. */ |
| 13844 |
if (!MEM_P (op)) |
| 13845 |
return FALSE; |
| 13846 |
|
| 13847 |
ind = XEXP (op, 0); |
| 13848 |
|
| 13849 |
if (reload_completed |
| 13850 |
&& (LABEL_REF_P (ind) |
| 13851 |
|| (GET_CODE (ind) == CONST |
| 13852 |
&& GET_CODE (XEXP (ind, 0)) == PLUS |
| 13853 |
&& GET_CODE (XEXP (XEXP (ind, 0), 0)) == LABEL_REF |
| 13854 |
&& CONST_INT_P (XEXP (XEXP (ind, 0), 1))))) |
| 13855 |
return TRUE; |
| 13856 |
|
| 13857 |
/* Match: (mem (reg)). */ |
| 13858 |
if (REG_P (ind)) |
| 13859 |
return arm_address_register_rtx_p (ind, 0); |
| 13860 |
|
| 13861 |
/* Allow post-increment with Neon registers. */ |
| 13862 |
if ((type != 1 && GET_CODE (ind) == POST_INC) |
| 13863 |
|| (type == 0 && GET_CODE (ind) == PRE_DEC)) |
| 13864 |
return arm_address_register_rtx_p (XEXP (ind, 0), 0); |
| 13865 |
|
| 13866 |
/* Allow post-increment by register for VLDn */ |
| 13867 |
if (type == 2 && GET_CODE (ind) == POST_MODIFY |
| 13868 |
&& GET_CODE (XEXP (ind, 1)) == PLUS |
| 13869 |
&& REG_P (XEXP (XEXP (ind, 1), 1)) |
| 13870 |
&& REG_P (XEXP (ind, 0)) |
| 13871 |
&& rtx_equal_p (XEXP (ind, 0), XEXP (XEXP (ind, 1), 0))) |
| 13872 |
return true; |
| 13873 |
|
| 13874 |
/* Match: |
| 13875 |
(plus (reg) |
| 13876 |
(const)). */ |
| 13877 |
if (type == 0 |
| 13878 |
&& GET_CODE (ind) == PLUS |
| 13879 |
&& REG_P (XEXP (ind, 0)) |
| 13880 |
&& REG_MODE_OK_FOR_BASE_P (XEXP (ind, 0), VOIDmode) |
| 13881 |
&& CONST_INT_P (XEXP (ind, 1)) |
| 13882 |
&& INTVAL (XEXP (ind, 1)) > -1024 |
| 13883 |
/* For quad modes, we restrict the constant offset to be slightly less |
| 13884 |
than what the instruction format permits. We have no such constraint |
| 13885 |
on double mode offsets. (This must match arm_legitimate_index_p.) */ |
| 13886 |
&& (INTVAL (XEXP (ind, 1)) |
| 13887 |
< (VALID_NEON_QREG_MODE (GET_MODE (op))? 1016 : 1024)) |
| 13888 |
&& (INTVAL (XEXP (ind, 1)) & 3) == 0) |
| 13889 |
return TRUE; |
| 13890 |
|
| 13891 |
return FALSE; |
| 13892 |
} |
| 13893 |
|
| 13894 |
/* Return TRUE if OP is a mem suitable for loading/storing an MVE struct |
| 13895 |
type. */ |
| 13896 |
int |
| 13897 |
mve_struct_mem_operand (rtx op) |
| 13898 |
{ |
| 13899 |
rtx ind = XEXP (op, 0); |
| 13900 |
|
| 13901 |
/* Match: (mem (reg)). */ |
| 13902 |
if (REG_P (ind)) |
| 13903 |
return arm_address_register_rtx_p (ind, 0); |
| 13904 |
|
| 13905 |
/* Allow only post-increment by the mode size. */ |
| 13906 |
if (GET_CODE (ind) == POST_INC) |
| 13907 |
return arm_address_register_rtx_p (XEXP (ind, 0), 0); |
| 13908 |
|
| 13909 |
return FALSE; |
| 13910 |
} |
| 13911 |
|
| 13912 |
/* Return TRUE if OP is a mem suitable for loading/storing a Neon struct |
| 13913 |
type. */ |
| 13914 |
int |
| 13915 |
neon_struct_mem_operand (rtx op) |
| 13916 |
{ |
| 13917 |
rtx ind; |
| 13918 |
|
| 13919 |
/* Reject eliminable registers. */ |
| 13920 |
if (! (reload_in_progress || reload_completed) |
| 13921 |
&& ( reg_mentioned_p (frame_pointer_rtx, op) |
| 13922 |
|| reg_mentioned_p (arg_pointer_rtx, op) |
| 13923 |
|| reg_mentioned_p (virtual_incoming_args_rtx, op) |
| 13924 |
|| reg_mentioned_p (virtual_outgoing_args_rtx, op) |
| 13925 |
|| reg_mentioned_p (virtual_stack_dynamic_rtx, op) |
| 13926 |
|| reg_mentioned_p (virtual_stack_vars_rtx, op))) |
| 13927 |
return FALSE; |
| 13928 |
|
| 13929 |
/* Constants are converted into offsets from labels. */ |
| 13930 |
if (!MEM_P (op)) |
| 13931 |
return FALSE; |
| 13932 |
|
| 13933 |
ind = XEXP (op, 0); |
| 13934 |
|
| 13935 |
if (reload_completed |
| 13936 |
&& (LABEL_REF_P (ind) |
| 13937 |
|| (GET_CODE (ind) == CONST |
| 13938 |
&& GET_CODE (XEXP (ind, 0)) == PLUS |
| 13939 |
&& GET_CODE (XEXP (XEXP (ind, 0), 0)) == LABEL_REF |
| 13940 |
&& CONST_INT_P (XEXP (XEXP (ind, 0), 1))))) |
| 13941 |
return TRUE; |
| 13942 |
|
| 13943 |
/* Match: (mem (reg)). */ |
| 13944 |
if (REG_P (ind)) |
| 13945 |
return arm_address_register_rtx_p (ind, 0); |
| 13946 |
|
| 13947 |
/* vldm/vstm allows POST_INC (ia) and PRE_DEC (db). */ |
| 13948 |
if (GET_CODE (ind) == POST_INC |
| 13949 |
|| GET_CODE (ind) == PRE_DEC) |
| 13950 |
return arm_address_register_rtx_p (XEXP (ind, 0), 0); |
| 13951 |
|
| 13952 |
return FALSE; |
| 13953 |
} |
| 13954 |
|
| 13955 |
/* Prepares the operands for the VCMLA by lane instruction such that the right |
| 13956 |
register number is selected. This instruction is special in that it always |
| 13957 |
requires a D register, however there is a choice to be made between Dn[0], |
| 13958 |
Dn[1], D(n+1)[0], and D(n+1)[1] depending on the mode of the registers. |
| 13959 |
|
| 13960 |
The VCMLA by lane function always selects two values. For instance given D0 |
| 13961 |
and a V2SF, the only valid index is 0 as the values in S0 and S1 will be |
| 13962 |
used by the instruction. However given V4SF then index 0 and 1 are valid as |
| 13963 |
D0[0] or D1[0] are both valid. |
| 13964 |
|
| 13965 |
This function centralizes that information based on OPERANDS, OPERANDS[3] |
| 13966 |
will be changed from a REG into a CONST_INT RTX and OPERANDS[4] will be |
| 13967 |
updated to contain the right index. */ |
| 13968 |
|
| 13969 |
rtx * |
| 13970 |
neon_vcmla_lane_prepare_operands (rtx *operands) |
| 13971 |
{ |
| 13972 |
int lane = INTVAL (operands[4]); |
| 13973 |
machine_mode constmode = SImode; |
| 13974 |
machine_mode mode = GET_MODE (operands[3]); |
| 13975 |
int regno = REGNO (operands[3]); |
| 13976 |
regno = ((regno - FIRST_VFP_REGNUM) >> 1); |
| 13977 |
if (lane > 0 && lane >= GET_MODE_NUNITS (mode) / 4) |
| 13978 |
{ |
| 13979 |
operands[3] = gen_int_mode (regno + 1, constmode); |
| 13980 |
operands[4] |
| 13981 |
= gen_int_mode (lane - GET_MODE_NUNITS (mode) / 4, constmode); |
| 13982 |
} |
| 13983 |
else |
| 13984 |
{ |
| 13985 |
operands[3] = gen_int_mode (regno, constmode); |
| 13986 |
operands[4] = gen_int_mode (lane, constmode); |
| 13987 |
} |
| 13988 |
return operands; |
| 13989 |
} |
| 13990 |
|
| 13991 |
|
| 13992 |
/* Return true if X is a register that will be eliminated later on. */ |
| 13993 |
int |
| 13994 |
arm_eliminable_register (rtx x) |
| 13995 |
{ |
| 13996 |
return REG_P (x) && (REGNO (x) == FRAME_POINTER_REGNUM |
| 13997 |
|| REGNO (x) == ARG_POINTER_REGNUM |
| 13998 |
|| VIRTUAL_REGISTER_P (x)); |
| 13999 |
} |
| 14000 |
|
| 14001 |
/* Return GENERAL_REGS if a scratch register required to reload x to/from |
| 14002 |
coprocessor registers. Otherwise return NO_REGS. */ |
| 14003 |
|
| 14004 |
enum reg_class |
| 14005 |
coproc_secondary_reload_class (machine_mode mode, rtx x, bool wb) |
| 14006 |
{ |
| 14007 |
if (mode == HFmode) |
| 14008 |
{ |
| 14009 |
if (!TARGET_NEON_FP16 && !TARGET_VFP_FP16INST) |
| 14010 |
return GENERAL_REGS; |
| 14011 |
if (s_register_operand (x, mode) || neon_vector_mem_operand (x, 2, true)) |
| 14012 |
return NO_REGS; |
| 14013 |
return GENERAL_REGS; |
| 14014 |
} |
| 14015 |
|
| 14016 |
/* The neon move patterns handle all legitimate vector and struct |
| 14017 |
addresses. */ |
| 14018 |
if (TARGET_NEON |
| 14019 |
&& (MEM_P (x) || GET_CODE (x) == CONST_VECTOR) |
| 14020 |
&& (GET_MODE_CLASS (mode) == MODE_VECTOR_INT |
| 14021 |
|| GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT |
| 14022 |
|| VALID_NEON_STRUCT_MODE (mode))) |
| 14023 |
return NO_REGS; |
| 14024 |
|
| 14025 |
if (arm_coproc_mem_operand (x, wb) || s_register_operand (x, mode)) |
| 14026 |
return NO_REGS; |
| 14027 |
|
| 14028 |
return GENERAL_REGS; |
| 14029 |
} |
| 14030 |
|
| 14031 |
/* Values which must be returned in the most-significant end of the return |
| 14032 |
register. */ |
| 14033 |
|
| 14034 |
static bool |
| 14035 |
arm_return_in_msb (const_tree valtype) |
| 14036 |
{ |
| 14037 |
return (TARGET_AAPCS_BASED |
| 14038 |
&& BYTES_BIG_ENDIAN |
| 14039 |
&& (AGGREGATE_TYPE_P (valtype) |
| 14040 |
|| TREE_CODE (valtype) == COMPLEX_TYPE |
| 14041 |
|| FIXED_POINT_TYPE_P (valtype))); |
| 14042 |
} |
| 14043 |
|
| 14044 |
/* Return TRUE if X references a SYMBOL_REF. */ |
| 14045 |
int |
| 14046 |
symbol_mentioned_p (rtx x) |
| 14047 |
{ |
| 14048 |
const char * fmt; |
| 14049 |
int i; |
| 14050 |
|
| 14051 |
if (SYMBOL_REF_P (x)) |
| 14052 |
return 1; |
| 14053 |
|
| 14054 |
/* UNSPEC_TLS entries for a symbol include the SYMBOL_REF, but they |
| 14055 |
are constant offsets, not symbols. */ |
| 14056 |
if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS) |
| 14057 |
return 0; |
| 14058 |
|
| 14059 |
fmt = GET_RTX_FORMAT (GET_CODE (x)); |
| 14060 |
|
| 14061 |
for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) |
| 14062 |
{ |
| 14063 |
if (fmt[i] == 'E') |
| 14064 |
{ |
| 14065 |
int j; |
| 14066 |
|
| 14067 |
for (j = XVECLEN (x, i) - 1; j >= 0; j--) |
| 14068 |
if (symbol_mentioned_p (XVECEXP (x, i, j))) |
| 14069 |
return 1; |
| 14070 |
} |
| 14071 |
else if (fmt[i] == 'e' && symbol_mentioned_p (XEXP (x, i))) |
| 14072 |
return 1; |
| 14073 |
} |
| 14074 |
|
| 14075 |
return 0; |
| 14076 |
} |
| 14077 |
|
| 14078 |
/* Return TRUE if X references a LABEL_REF. */ |
| 14079 |
int |
| 14080 |
label_mentioned_p (rtx x) |
| 14081 |
{ |
| 14082 |
const char * fmt; |
| 14083 |
int i; |
| 14084 |
|
| 14085 |
if (LABEL_REF_P (x)) |
| 14086 |
return 1; |
| 14087 |
|
| 14088 |
/* UNSPEC_TLS entries for a symbol include a LABEL_REF for the referencing |
| 14089 |
instruction, but they are constant offsets, not symbols. */ |
| 14090 |
if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS) |
| 14091 |
return 0; |
| 14092 |
|
| 14093 |
fmt = GET_RTX_FORMAT (GET_CODE (x)); |
| 14094 |
for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) |
| 14095 |
{ |
| 14096 |
if (fmt[i] == 'E') |
| 14097 |
{ |
| 14098 |
int j; |
| 14099 |
|
| 14100 |
for (j = XVECLEN (x, i) - 1; j >= 0; j--) |
| 14101 |
if (label_mentioned_p (XVECEXP (x, i, j))) |
| 14102 |
return 1; |
| 14103 |
} |
| 14104 |
else if (fmt[i] == 'e' && label_mentioned_p (XEXP (x, i))) |
| 14105 |
return 1; |
| 14106 |
} |
| 14107 |
|
| 14108 |
return 0; |
| 14109 |
} |
| 14110 |
|
| 14111 |
int |
| 14112 |
tls_mentioned_p (rtx x) |
| 14113 |
{ |
| 14114 |
switch (GET_CODE (x)) |
| 14115 |
{ |
| 14116 |
case CONST: |
| 14117 |
return tls_mentioned_p (XEXP (x, 0)); |
| 14118 |
|
| 14119 |
case UNSPEC: |
| 14120 |
if (XINT (x, 1) == UNSPEC_TLS) |
| 14121 |
return 1; |
| 14122 |
|
| 14123 |
/* Fall through. */ |
| 14124 |
default: |
| 14125 |
return 0; |
| 14126 |
} |
| 14127 |
} |
| 14128 |
|
| 14129 |
/* Must not copy any rtx that uses a pc-relative address. |
| 14130 |
Also, disallow copying of load-exclusive instructions that |
| 14131 |
may appear after splitting of compare-and-swap-style operations |
| 14132 |
so as to prevent those loops from being transformed away from their |
| 14133 |
canonical forms (see PR 69904). */ |
| 14134 |
|
| 14135 |
static bool |
| 14136 |
arm_cannot_copy_insn_p (rtx_insn *insn) |
| 14137 |
{ |
| 14138 |
/* The tls call insn cannot be copied, as it is paired with a data |
| 14139 |
word. */ |
| 14140 |
if (recog_memoized (insn) == CODE_FOR_tlscall) |
| 14141 |
return true; |
| 14142 |
|
| 14143 |
subrtx_iterator::array_type array; |
| 14144 |
FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL) |
| 14145 |
{ |
| 14146 |
const_rtx x = *iter; |
| 14147 |
if (GET_CODE (x) == UNSPEC |
| 14148 |
&& (XINT (x, 1) == UNSPEC_PIC_BASE |
| 14149 |
|| XINT (x, 1) == UNSPEC_PIC_UNIFIED)) |
| 14150 |
return true; |
| 14151 |
} |
| 14152 |
|
| 14153 |
rtx set = single_set (insn); |
| 14154 |
if (set) |
| 14155 |
{ |
| 14156 |
rtx src = SET_SRC (set); |
| 14157 |
if (GET_CODE (src) == ZERO_EXTEND) |
| 14158 |
src = XEXP (src, 0); |
| 14159 |
|
| 14160 |
/* Catch the load-exclusive and load-acquire operations. */ |
| 14161 |
if (GET_CODE (src) == UNSPEC_VOLATILE |
| 14162 |
&& (XINT (src, 1) == VUNSPEC_LL |
| 14163 |
|| XINT (src, 1) == VUNSPEC_LAX)) |
| 14164 |
return true; |
| 14165 |
} |
| 14166 |
return false; |
| 14167 |
} |
| 14168 |
|
| 14169 |
enum rtx_code |
| 14170 |
minmax_code (rtx x) |
| 14171 |
{ |
| 14172 |
enum rtx_code code = GET_CODE (x); |
| 14173 |
|
| 14174 |
switch (code) |
| 14175 |
{ |
| 14176 |
case SMAX: |
| 14177 |
return GE; |
| 14178 |
case SMIN: |
| 14179 |
return LE; |
| 14180 |
case UMIN: |
| 14181 |
return LEU; |
| 14182 |
case UMAX: |
| 14183 |
return GEU; |
| 14184 |
default: |
| 14185 |
gcc_unreachable (); |
| 14186 |
} |
| 14187 |
} |
| 14188 |
|
| 14189 |
/* Match pair of min/max operators that can be implemented via usat/ssat. */ |
| 14190 |
|
| 14191 |
bool |
| 14192 |
arm_sat_operator_match (rtx lo_bound, rtx hi_bound, |
| 14193 |
int *mask, bool *signed_sat) |
| 14194 |
{ |
| 14195 |
/* The high bound must be a power of two minus one. */ |
| 14196 |
int log = exact_log2 (INTVAL (hi_bound) + 1); |
| 14197 |
if (log == -1) |
| 14198 |
return false; |
| 14199 |
|
| 14200 |
/* The low bound is either zero (for usat) or one less than the |
| 14201 |
negation of the high bound (for ssat). */ |
| 14202 |
if (INTVAL (lo_bound) == 0) |
| 14203 |
{ |
| 14204 |
if (mask) |
| 14205 |
*mask = log; |
| 14206 |
if (signed_sat) |
| 14207 |
*signed_sat = false; |
| 14208 |
|
| 14209 |
return true; |
| 14210 |
} |
| 14211 |
|
| 14212 |
if (INTVAL (lo_bound) == -INTVAL (hi_bound) - 1) |
| 14213 |
{ |
| 14214 |
if (mask) |
| 14215 |
*mask = log + 1; |
| 14216 |
if (signed_sat) |
| 14217 |
*signed_sat = true; |
| 14218 |
|
| 14219 |
return true; |
| 14220 |
} |
| 14221 |
|
| 14222 |
return false; |
| 14223 |
} |
| 14224 |
|
| 14225 |
/* Return 1 if memory locations are adjacent. */ |
| 14226 |
int |
| 14227 |
adjacent_mem_locations (rtx a, rtx b) |
| 14228 |
{ |
| 14229 |
/* We don't guarantee to preserve the order of these memory refs. */ |
| 14230 |
if (volatile_refs_p (a) || volatile_refs_p (b)) |
| 14231 |
return 0; |
| 14232 |
|
| 14233 |
if ((REG_P (XEXP (a, 0)) |
| 14234 |
|| (GET_CODE (XEXP (a, 0)) == PLUS |
| 14235 |
&& CONST_INT_P (XEXP (XEXP (a, 0), 1)))) |
| 14236 |
&& (REG_P (XEXP (b, 0)) |
| 14237 |
|| (GET_CODE (XEXP (b, 0)) == PLUS |
| 14238 |
&& CONST_INT_P (XEXP (XEXP (b, 0), 1))))) |
| 14239 |
{ |
| 14240 |
HOST_WIDE_INT val0 = 0, val1 = 0; |
| 14241 |
rtx reg0, reg1; |
| 14242 |
int val_diff; |
| 14243 |
|
| 14244 |
if (GET_CODE (XEXP (a, 0)) == PLUS) |
| 14245 |
{ |
| 14246 |
reg0 = XEXP (XEXP (a, 0), 0); |
| 14247 |
val0 = INTVAL (XEXP (XEXP (a, 0), 1)); |
| 14248 |
} |
| 14249 |
else |
| 14250 |
reg0 = XEXP (a, 0); |
| 14251 |
|
| 14252 |
if (GET_CODE (XEXP (b, 0)) == PLUS) |
| 14253 |
{ |
| 14254 |
reg1 = XEXP (XEXP (b, 0), 0); |
| 14255 |
val1 = INTVAL (XEXP (XEXP (b, 0), 1)); |
| 14256 |
} |
| 14257 |
else |
| 14258 |
reg1 = XEXP (b, 0); |
| 14259 |
|
| 14260 |
/* Don't accept any offset that will require multiple |
| 14261 |
instructions to handle, since this would cause the |
| 14262 |
arith_adjacentmem pattern to output an overlong sequence. */ |
| 14263 |
if (!const_ok_for_op (val0, PLUS) || !const_ok_for_op (val1, PLUS)) |
| 14264 |
return 0; |
| 14265 |
|
| 14266 |
/* Don't allow an eliminable register: register elimination can make |
| 14267 |
the offset too large. */ |
| 14268 |
if (arm_eliminable_register (reg0)) |
| 14269 |
return 0; |
| 14270 |
|
| 14271 |
val_diff = val1 - val0; |
| 14272 |
|
| 14273 |
if (arm_ld_sched) |
| 14274 |
{ |
| 14275 |
/* If the target has load delay slots, then there's no benefit |
| 14276 |
to using an ldm instruction unless the offset is zero and |
| 14277 |
we are optimizing for size. */ |
| 14278 |
return (optimize_size && (REGNO (reg0) == REGNO (reg1)) |
| 14279 |
&& (val0 == 0 || val1 == 0 || val0 == 4 || val1 == 4) |
| 14280 |
&& (val_diff == 4 || val_diff == -4)); |
| 14281 |
} |
| 14282 |
|
| 14283 |
return ((REGNO (reg0) == REGNO (reg1)) |
| 14284 |
&& (val_diff == 4 || val_diff == -4)); |
| 14285 |
} |
| 14286 |
|
| 14287 |
return 0; |
| 14288 |
} |
| 14289 |
|
| 14290 |
/* Helper routine for ldm_stm_operation_p. Decompose a simple offset |
| 14291 |
address into the base register and the offset. Return false iff |
| 14292 |
it is more complex than this. */ |
| 14293 |
static inline bool |
| 14294 |
decompose_addr_for_ldm_stm (rtx addr, rtx *base, HOST_WIDE_INT *offset) |
| 14295 |
{ |
| 14296 |
if (REG_P (addr)) |
| 14297 |
{ |
| 14298 |
*base = addr; |
| 14299 |
*offset = 0; |
| 14300 |
return true; |
| 14301 |
} |
| 14302 |
else if (GET_CODE (addr) == PLUS |
| 14303 |
&& REG_P (XEXP (addr, 0)) |
| 14304 |
&& CONST_INT_P (XEXP (addr, 1))) |
| 14305 |
{ |
| 14306 |
*base = XEXP (addr, 0); |
| 14307 |
*offset = INTVAL (XEXP (addr, 1)); |
| 14308 |
return true; |
| 14309 |
} |
| 14310 |
|
| 14311 |
return false; |
| 14312 |
} |
| 14313 |
|
| 14314 |
/* Return true if OP is a valid load or store multiple operation. LOAD is true |
| 14315 |
for load operations, false for store operations. CONSECUTIVE is true |
| 14316 |
if the register numbers in the operation must be consecutive in the register |
| 14317 |
bank. RETURN_PC is true if value is to be loaded in PC. |
| 14318 |
The pattern we are trying to match for load is: |
| 14319 |
[(SET (R_d0) (MEM (PLUS (addr) (offset)))) |
| 14320 |
(SET (R_d1) (MEM (PLUS (addr) (offset + <reg_increment>)))) |
| 14321 |
: |
| 14322 |
: |
| 14323 |
(SET (R_dn) (MEM (PLUS (addr) (offset + n * <reg_increment>)))) |
| 14324 |
] |
| 14325 |
where |
| 14326 |
1. If offset is 0, first insn should be (SET (R_d0) (MEM (src_addr))). |
| 14327 |
2. REGNO (R_d0) < REGNO (R_d1) < ... < REGNO (R_dn). |
| 14328 |
3. If consecutive is TRUE, then for kth register being loaded, |
| 14329 |
REGNO (R_dk) = REGNO (R_d0) + k. |
| 14330 |
The pattern for store is similar. */ |
| 14331 |
bool |
| 14332 |
ldm_stm_operation_p (rtx op, bool load, machine_mode mode, |
| 14333 |
bool consecutive, bool return_pc) |
| 14334 |
{ |
| 14335 |
int count = XVECLEN (op, 0); |
| 14336 |
rtx reg, mem; |
| 14337 |
rtx addr_base; |
| 14338 |
int reg_loc, mem_loc; |
| 14339 |
unsigned prev_regno; |
| 14340 |
HOST_WIDE_INT addr_offset; |
| 14341 |
rtx elt; |
| 14342 |
bool addr_reg_in_reglist = false; |
| 14343 |
bool update = false; |
| 14344 |
int reg_bytes; |
| 14345 |
int words_per_reg; /* How many words in memory a register takes. */ |
| 14346 |
int elt_num = 0; |
| 14347 |
int base_elt_num; /* Element number of the first transfer operation. */ |
| 14348 |
|
| 14349 |
/* If not in SImode, then registers must be consecutive |
| 14350 |
(e.g., VLDM instructions for DFmode). */ |
| 14351 |
gcc_assert ((mode == SImode) || consecutive); |
| 14352 |
/* Setting return_pc for stores is illegal. */ |
| 14353 |
gcc_assert (!return_pc || load); |
| 14354 |
|
| 14355 |
/* Set up the increments and sizes for the mode. */ |
| 14356 |
reg_bytes = GET_MODE_SIZE (mode); |
| 14357 |
words_per_reg = ARM_NUM_REGS (mode); |
| 14358 |
|
| 14359 |
/* If this is a return, then the first element in the par must be |
| 14360 |
(return). */ |
| 14361 |
if (return_pc) |
| 14362 |
{ |
| 14363 |
if (GET_CODE (XVECEXP (op, 0, 0)) != RETURN) |
| 14364 |
return false; |
| 14365 |
elt_num++; |
| 14366 |
} |
| 14367 |
|
| 14368 |
if (elt_num >= count) |
| 14369 |
return false; |
| 14370 |
|
| 14371 |
/* Check if this is a write-back. */ |
| 14372 |
elt = XVECEXP (op, 0, elt_num); |
| 14373 |
if (GET_CODE (elt) != SET) |
| 14374 |
return false; |
| 14375 |
if (GET_CODE (SET_SRC (elt)) == PLUS) |
| 14376 |
{ |
| 14377 |
elt_num++; |
| 14378 |
update = true; |
| 14379 |
|
| 14380 |
/* The offset adjustment must be the number of registers being |
| 14381 |
popped times the size of a single register. */ |
| 14382 |
if (!REG_P (SET_DEST (elt)) |
| 14383 |
|| !REG_P (XEXP (SET_SRC (elt), 0)) |
| 14384 |
|| (REGNO (SET_DEST (elt)) != REGNO (XEXP (SET_SRC (elt), 0))) |
| 14385 |
|| !CONST_INT_P (XEXP (SET_SRC (elt), 1)) |
| 14386 |
/* ??? Can't this be negative for a PUSH? */ |
| 14387 |
|| (INTVAL (XEXP (SET_SRC (elt), 1)) != |
| 14388 |
((count - elt_num) * reg_bytes))) |
| 14389 |
return false; |
| 14390 |
} |
| 14391 |
|
| 14392 |
base_elt_num = elt_num; |
| 14393 |
/* There must be at least one register to transfer. */ |
| 14394 |
if (base_elt_num >= count) |
| 14395 |
return false; |
| 14396 |
|
| 14397 |
elt = XVECEXP (op, 0, elt_num); |
| 14398 |
if (GET_CODE (elt) != SET) |
| 14399 |
return false; |
| 14400 |
|
| 14401 |
/* Where to look for the register and memory elements. These save us |
| 14402 |
needing to check LOAD multiple times in the loop. */ |
| 14403 |
if (load) |
| 14404 |
{ |
| 14405 |
reg_loc = 0; /* SET_DEST. */ |
| 14406 |
mem_loc = 1; /* SET_SRC. */ |
| 14407 |
} |
| 14408 |
else |
| 14409 |
{ |
| 14410 |
mem_loc = 0; /* SET_DEST. */ |
| 14411 |
reg_loc = 1; /* SET_SRC. */ |
| 14412 |
} |
| 14413 |
|
| 14414 |
reg = XEXP (elt, reg_loc); |
| 14415 |
mem = XEXP (elt, mem_loc); |
| 14416 |
|
| 14417 |
if (!REG_P (reg) || !MEM_P (mem)) |
| 14418 |
return false; |
| 14419 |
|
| 14420 |
prev_regno = REGNO (reg); |
| 14421 |
if (!decompose_addr_for_ldm_stm (XEXP (mem, 0), &addr_base, &addr_offset)) |
| 14422 |
return false; |
| 14423 |
|
| 14424 |
/* Don't allow SP to be loaded unless it is also the base register. |
| 14425 |
Otherwise SP will not be correctly restored if an LDM instruction is |
| 14426 |
interrupted (low latency interrupt or address fault), which can result in |
| 14427 |
stack corruption. */ |
| 14428 |
if (load && (REGNO (reg) == SP_REGNUM) && (REGNO (addr_base) != SP_REGNUM)) |
| 14429 |
return false; |
| 14430 |
|
| 14431 |
addr_reg_in_reglist = (prev_regno == REGNO (addr_base)); |
| 14432 |
|
| 14433 |
for (elt_num++; elt_num < count; elt_num++) |
| 14434 |
{ |
| 14435 |
rtx elt_base; |
| 14436 |
HOST_WIDE_INT elt_offset; |
| 14437 |
|
| 14438 |
elt = XVECEXP (op, 0, elt_num); |
| 14439 |
if (GET_CODE (elt) != SET) |
| 14440 |
return false; |
| 14441 |
|
| 14442 |
reg = XEXP (elt, reg_loc); |
| 14443 |
mem = XEXP (elt, mem_loc); |
| 14444 |
|
| 14445 |
if (!REG_P (reg) |
| 14446 |
|| GET_MODE (reg) != mode |
| 14447 |
|| REGNO (reg) <= prev_regno |
| 14448 |
|| (consecutive |
| 14449 |
&& REGNO (reg) != prev_regno + words_per_reg) |
| 14450 |
/* Don't allow SP to be loaded unless it is also the base register |
| 14451 |
(see similar comment above). */ |
| 14452 |
|| (load |
| 14453 |
&& (REGNO (reg) == SP_REGNUM) |
| 14454 |
&& (REGNO (addr_base) != SP_REGNUM)) |
| 14455 |
|| !MEM_P (mem) |
| 14456 |
|| GET_MODE (mem) != mode |
| 14457 |
|| !decompose_addr_for_ldm_stm (XEXP (mem, 0), &elt_base, |
| 14458 |
&elt_offset) |
| 14459 |
|| REGNO (addr_base) != REGNO (elt_base) |
| 14460 |
|| addr_offset + (elt_num - base_elt_num) * reg_bytes != elt_offset) |
| 14461 |
return false; |
| 14462 |
|
| 14463 |
prev_regno = REGNO (reg); |
| 14464 |
if (prev_regno == REGNO (addr_base)) |
| 14465 |
{ |
| 14466 |
/* Storing the base register is unpredictable if it is not the first |
| 14467 |
transfer register and the base register is being modified. */ |
| 14468 |
if (update && !load) |
| 14469 |
return false; |
| 14470 |
addr_reg_in_reglist = true; |
| 14471 |
} |
| 14472 |
} |
| 14473 |
|
| 14474 |
if (load) |
| 14475 |
{ |
| 14476 |
if (update && addr_reg_in_reglist) |
| 14477 |
return false; |
| 14478 |
|
| 14479 |
/* A return instruction must load PC last. */ |
| 14480 |
if (return_pc && prev_regno != PC_REGNUM) |
| 14481 |
return false; |
| 14482 |
|
| 14483 |
/* For Thumb-1, address register is always modified - either by |
| 14484 |
write-back or by explicit load. If the pattern does not describe an |
| 14485 |
update, then the address register must be in the list of loaded |
| 14486 |
registers. */ |
| 14487 |
if (TARGET_THUMB1) |
| 14488 |
return update || addr_reg_in_reglist; |
| 14489 |
} |
| 14490 |
|
| 14491 |
return true; |
| 14492 |
} |
| 14493 |
|
| 14494 |
/* Checks whether OP is a valid parallel pattern for a CLRM (if VFP is false) |
| 14495 |
or VSCCLRM (otherwise) insn. To be a valid CLRM pattern, OP must have the |
| 14496 |
following form: |
| 14497 |
|
| 14498 |
[(set (reg:SI <N>) (const_int 0)) |
| 14499 |
(set (reg:SI <M>) (const_int 0)) |
| 14500 |
... |
| 14501 |
(unspec_volatile [(const_int 0)] |
| 14502 |
VUNSPEC_CLRM_APSR) |
| 14503 |
(clobber (reg:CC CC_REGNUM)) |
| 14504 |
] |
| 14505 |
|
| 14506 |
Any number (including 0) of set expressions is valid, the volatile unspec is |
| 14507 |
optional. All registers but SP and PC are allowed and registers must be in |
| 14508 |
strict increasing order. |
| 14509 |
|
| 14510 |
To be a valid VSCCLRM pattern, OP must have the following form: |
| 14511 |
|
| 14512 |
[(unspec_volatile [(const_int 0)] |
| 14513 |
VUNSPEC_VSCCLRM_VPR) |
| 14514 |
(set (reg:SF <N>) (const_int 0)) |
| 14515 |
(set (reg:SF <M>) (const_int 0)) |
| 14516 |
... |
| 14517 |
] |
| 14518 |
|
| 14519 |
As with CLRM, any number (including 0) of set expressions is valid, however |
| 14520 |
the volatile unspec is mandatory here. Any VFP single-precision register is |
| 14521 |
accepted but all registers must be consecutive and in increasing order. */ |
| 14522 |
|
| 14523 |
bool |
| 14524 |
clear_operation_p (rtx op, bool vfp) |
| 14525 |
{ |
| 14526 |
unsigned regno; |
| 14527 |
unsigned last_regno = INVALID_REGNUM; |
| 14528 |
rtx elt, reg, zero; |
| 14529 |
int count = XVECLEN (op, 0); |
| 14530 |
int first_set = vfp ? 1 : 0; |
| 14531 |
machine_mode expected_mode = vfp ? E_SFmode : E_SImode; |
| 14532 |
|
| 14533 |
for (int i = first_set; i < count; i++) |
| 14534 |
{ |
| 14535 |
elt = XVECEXP (op, 0, i); |
| 14536 |
|
| 14537 |
if (!vfp && GET_CODE (elt) == UNSPEC_VOLATILE) |
| 14538 |
{ |
| 14539 |
if (XINT (elt, 1) != VUNSPEC_CLRM_APSR |
| 14540 |
|| XVECLEN (elt, 0) != 1 |
| 14541 |
|| XVECEXP (elt, 0, 0) != CONST0_RTX (SImode) |
| 14542 |
|| i != count - 2) |
| 14543 |
return false; |
| 14544 |
|
| 14545 |
continue; |
| 14546 |
} |
| 14547 |
|
| 14548 |
if (GET_CODE (elt) == CLOBBER) |
| 14549 |
continue; |
| 14550 |
|
| 14551 |
if (GET_CODE (elt) != SET) |
| 14552 |
return false; |
| 14553 |
|
| 14554 |
reg = SET_DEST (elt); |
| 14555 |
zero = SET_SRC (elt); |
| 14556 |
|
| 14557 |
if (!REG_P (reg) |
| 14558 |
|| GET_MODE (reg) != expected_mode |
| 14559 |
|| zero != CONST0_RTX (SImode)) |
| 14560 |
return false; |
| 14561 |
|
| 14562 |
regno = REGNO (reg); |
| 14563 |
|
| 14564 |
if (vfp) |
| 14565 |
{ |
| 14566 |
if (i != first_set && regno != last_regno + 1) |
| 14567 |
return false; |
| 14568 |
} |
| 14569 |
else |
| 14570 |
{ |
| 14571 |
if (regno == SP_REGNUM || regno == PC_REGNUM) |
| 14572 |
return false; |
| 14573 |
if (i != first_set && regno <= last_regno) |
| 14574 |
return false; |
| 14575 |
} |
| 14576 |
|
| 14577 |
last_regno = regno; |
| 14578 |
} |
| 14579 |
|
| 14580 |
return true; |
| 14581 |
} |
| 14582 |
|
| 14583 |
/* Return true iff it would be profitable to turn a sequence of NOPS loads |
| 14584 |
or stores (depending on IS_STORE) into a load-multiple or store-multiple |
| 14585 |
instruction. ADD_OFFSET is nonzero if the base address register needs |
| 14586 |
to be modified with an add instruction before we can use it. */ |
| 14587 |
|
| 14588 |
static bool |
| 14589 |
multiple_operation_profitable_p (bool is_store ATTRIBUTE_UNUSED, |
| 14590 |
int nops, HOST_WIDE_INT add_offset) |
| 14591 |
{ |
| 14592 |
/* For ARM8,9 & StrongARM, 2 ldr instructions are faster than an ldm |
| 14593 |
if the offset isn't small enough. The reason 2 ldrs are faster |
| 14594 |
is because these ARMs are able to do more than one cache access |
| 14595 |
in a single cycle. The ARM9 and StrongARM have Harvard caches, |
| 14596 |
whilst the ARM8 has a double bandwidth cache. This means that |
| 14597 |
these cores can do both an instruction fetch and a data fetch in |
| 14598 |
a single cycle, so the trick of calculating the address into a |
| 14599 |
scratch register (one of the result regs) and then doing a load |
| 14600 |
multiple actually becomes slower (and no smaller in code size). |
| 14601 |
That is the transformation |
| 14602 |
|
| 14603 |
ldr rd1, [rbase + offset] |
| 14604 |
ldr rd2, [rbase + offset + 4] |
| 14605 |
|
| 14606 |
to |
| 14607 |
|
| 14608 |
add rd1, rbase, offset |
| 14609 |
ldmia rd1, {rd1, rd2} |
| 14610 |
|
| 14611 |
produces worse code -- '3 cycles + any stalls on rd2' instead of |
| 14612 |
'2 cycles + any stalls on rd2'. On ARMs with only one cache |
| 14613 |
access per cycle, the first sequence could never complete in less |
| 14614 |
than 6 cycles, whereas the ldm sequence would only take 5 and |
| 14615 |
would make better use of sequential accesses if not hitting the |
| 14616 |
cache. |
| 14617 |
|
| 14618 |
We cheat here and test 'arm_ld_sched' which we currently know to |
| 14619 |
only be true for the ARM8, ARM9 and StrongARM. If this ever |
| 14620 |
changes, then the test below needs to be reworked. */ |
| 14621 |
if (nops == 2 && arm_ld_sched && add_offset != 0) |
| 14622 |
return false; |
| 14623 |
|
| 14624 |
/* XScale has load-store double instructions, but they have stricter |
| 14625 |
alignment requirements than load-store multiple, so we cannot |
| 14626 |
use them. |
| 14627 |
|
| 14628 |
For XScale ldm requires 2 + NREGS cycles to complete and blocks |
| 14629 |
the pipeline until completion. |
| 14630 |
|
| 14631 |
NREGS CYCLES |
| 14632 |
1 3 |
| 14633 |
2 4 |
| 14634 |
3 5 |
| 14635 |
4 6 |
| 14636 |
|
| 14637 |
An ldr instruction takes 1-3 cycles, but does not block the |
| 14638 |
pipeline. |
| 14639 |
|
| 14640 |
NREGS CYCLES |
| 14641 |
1 1-3 |
| 14642 |
2 2-6 |
| 14643 |
3 3-9 |
| 14644 |
4 4-12 |
| 14645 |
|
| 14646 |
Best case ldr will always win. However, the more ldr instructions |
| 14647 |
we issue, the less likely we are to be able to schedule them well. |
| 14648 |
Using ldr instructions also increases code size. |
| 14649 |
|
| 14650 |
As a compromise, we use ldr for counts of 1 or 2 regs, and ldm |
| 14651 |
for counts of 3 or 4 regs. */ |
| 14652 |
if (nops <= 2 && arm_tune_xscale && !optimize_size) |
| 14653 |
return false; |
| 14654 |
return true; |
| 14655 |
} |
| 14656 |
|
| 14657 |
/* Subroutine of load_multiple_sequence and store_multiple_sequence. |
| 14658 |
Given an array of UNSORTED_OFFSETS, of which there are NOPS, compute |
| 14659 |
an array ORDER which describes the sequence to use when accessing the |
| 14660 |
offsets that produces an ascending order. In this sequence, each |
| 14661 |
offset must be larger by exactly 4 than the previous one. ORDER[0] |
| 14662 |
must have been filled in with the lowest offset by the caller. |
| 14663 |
If UNSORTED_REGS is nonnull, it is an array of register numbers that |
| 14664 |
we use to verify that ORDER produces an ascending order of registers. |
| 14665 |
Return true if it was possible to construct such an order, false if |
| 14666 |
not. */ |
| 14667 |
|
| 14668 |
static bool |
| 14669 |
compute_offset_order (int nops, HOST_WIDE_INT *unsorted_offsets, int *order, |
| 14670 |
int *unsorted_regs) |
| 14671 |
{ |
| 14672 |
int i; |
| 14673 |
for (i = 1; i < nops; i++) |
| 14674 |
{ |
| 14675 |
int j; |
| 14676 |
|
| 14677 |
order[i] = order[i - 1]; |
| 14678 |
for (j = 0; j < nops; j++) |
| 14679 |
if (unsorted_offsets[j] == unsorted_offsets[order[i - 1]] + 4) |
| 14680 |
{ |
| 14681 |
/* We must find exactly one offset that is higher than the |
| 14682 |
previous one by 4. */ |
| 14683 |
if (order[i] != order[i - 1]) |
| 14684 |
return false; |
| 14685 |
order[i] = j; |
| 14686 |
} |
| 14687 |
if (order[i] == order[i - 1]) |
| 14688 |
return false; |
| 14689 |
/* The register numbers must be ascending. */ |
| 14690 |
if (unsorted_regs != NULL |
| 14691 |
&& unsorted_regs[order[i]] <= unsorted_regs[order[i - 1]]) |
| 14692 |
return false; |
| 14693 |
} |
| 14694 |
return true; |
| 14695 |
} |
| 14696 |
|
| 14697 |
/* Used to determine in a peephole whether a sequence of load |
| 14698 |
instructions can be changed into a load-multiple instruction. |
| 14699 |
NOPS is the number of separate load instructions we are examining. The |
| 14700 |
first NOPS entries in OPERANDS are the destination registers, the |
| 14701 |
next NOPS entries are memory operands. If this function is |
| 14702 |
successful, *BASE is set to the common base register of the memory |
| 14703 |
accesses; *LOAD_OFFSET is set to the first memory location's offset |
| 14704 |
from that base register. |
| 14705 |
REGS is an array filled in with the destination register numbers. |
| 14706 |
SAVED_ORDER (if nonnull), is an array filled in with an order that maps |
| 14707 |
insn numbers to an ascending order of stores. If CHECK_REGS is true, |
| 14708 |
the sequence of registers in REGS matches the loads from ascending memory |
| 14709 |
locations, and the function verifies that the register numbers are |
| 14710 |
themselves ascending. If CHECK_REGS is false, the register numbers |
| 14711 |
are stored in the order they are found in the operands. */ |
| 14712 |
static int |
| 14713 |
load_multiple_sequence (rtx *operands, int nops, int *regs, int *saved_order, |
| 14714 |
int *base, HOST_WIDE_INT *load_offset, bool check_regs) |
| 14715 |
{ |
| 14716 |
int unsorted_regs[MAX_LDM_STM_OPS]; |
| 14717 |
HOST_WIDE_INT unsorted_offsets[MAX_LDM_STM_OPS]; |
| 14718 |
int order[MAX_LDM_STM_OPS]; |
| 14719 |
int base_reg = -1; |
| 14720 |
int i, ldm_case; |
| 14721 |
|
| 14722 |
/* Can only handle up to MAX_LDM_STM_OPS insns at present, though could be |
| 14723 |
easily extended if required. */ |
| 14724 |
gcc_assert (nops >= 2 && nops <= MAX_LDM_STM_OPS); |
| 14725 |
|
| 14726 |
memset (order, 0, MAX_LDM_STM_OPS * sizeof (int)); |
| 14727 |
|
| 14728 |
/* Loop over the operands and check that the memory references are |
| 14729 |
suitable (i.e. immediate offsets from the same base register). At |
| 14730 |
the same time, extract the target register, and the memory |
| 14731 |
offsets. */ |
| 14732 |
for (i = 0; i < nops; i++) |
| 14733 |
{ |
| 14734 |
rtx reg; |
| 14735 |
rtx offset; |
| 14736 |
|
| 14737 |
/* Convert a subreg of a mem into the mem itself. */ |
| 14738 |
if (GET_CODE (operands[nops + i]) == SUBREG) |
| 14739 |
operands[nops + i] = alter_subreg (operands + (nops + i), true); |
| 14740 |
|
| 14741 |
gcc_assert (MEM_P (operands[nops + i])); |
| 14742 |
|
| 14743 |
/* Don't reorder volatile memory references; it doesn't seem worth |
| 14744 |
looking for the case where the order is ok anyway. */ |
| 14745 |
if (MEM_VOLATILE_P (operands[nops + i])) |
| 14746 |
return 0; |
| 14747 |
|
| 14748 |
offset = const0_rtx; |
| 14749 |
|
| 14750 |
if ((REG_P (reg = XEXP (operands[nops + i], 0)) |
| 14751 |
|| (SUBREG_P (reg) |
| 14752 |
&& REG_P (reg = SUBREG_REG (reg)))) |
| 14753 |
|| (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS |
| 14754 |
&& ((REG_P (reg = XEXP (XEXP (operands[nops + i], 0), 0))) |
| 14755 |
|| (SUBREG_P (reg) |
| 14756 |
&& REG_P (reg = SUBREG_REG (reg)))) |
| 14757 |
&& (CONST_INT_P (offset |
| 14758 |
= XEXP (XEXP (operands[nops + i], 0), 1))))) |
| 14759 |
{ |
| 14760 |
if (i == 0) |
| 14761 |
{ |
| 14762 |
base_reg = REGNO (reg); |
| 14763 |
if (TARGET_THUMB1 && base_reg > LAST_LO_REGNUM) |
| 14764 |
return 0; |
| 14765 |
} |
| 14766 |
else if (base_reg != (int) REGNO (reg)) |
| 14767 |
/* Not addressed from the same base register. */ |
| 14768 |
return 0; |
| 14769 |
|
| 14770 |
unsorted_regs[i] = (REG_P (operands[i]) |
| 14771 |
? REGNO (operands[i]) |
| 14772 |
: REGNO (SUBREG_REG (operands[i]))); |
| 14773 |
|
| 14774 |
/* If it isn't an integer register, or if it overwrites the |
| 14775 |
base register but isn't the last insn in the list, then |
| 14776 |
we can't do this. */ |
| 14777 |
if (unsorted_regs[i] < 0 |
| 14778 |
|| (TARGET_THUMB1 && unsorted_regs[i] > LAST_LO_REGNUM) |
| 14779 |
|| unsorted_regs[i] > 14 |
| 14780 |
|| (i != nops - 1 && unsorted_regs[i] == base_reg)) |
| 14781 |
return 0; |
| 14782 |
|
| 14783 |
/* Don't allow SP to be loaded unless it is also the base |
| 14784 |
register. It guarantees that SP is reset correctly when |
| 14785 |
an LDM instruction is interrupted. Otherwise, we might |
| 14786 |
end up with a corrupt stack. */ |
| 14787 |
if (unsorted_regs[i] == SP_REGNUM && base_reg != SP_REGNUM) |
| 14788 |
return 0; |
| 14789 |
|
| 14790 |
unsorted_offsets[i] = INTVAL (offset); |
| 14791 |
if (i == 0 || unsorted_offsets[i] < unsorted_offsets[order[0]]) |
| 14792 |
order[0] = i; |
| 14793 |
} |
| 14794 |
else |
| 14795 |
/* Not a suitable memory address. */ |
| 14796 |
return 0; |
| 14797 |
} |
| 14798 |
|
| 14799 |
/* All the useful information has now been extracted from the |
| 14800 |
operands into unsorted_regs and unsorted_offsets; additionally, |
| 14801 |
order[0] has been set to the lowest offset in the list. Sort |
| 14802 |
the offsets into order, verifying that they are adjacent, and |
| 14803 |
check that the register numbers are ascending. */ |
| 14804 |
if (!compute_offset_order (nops, unsorted_offsets, order, |
| 14805 |
check_regs ? unsorted_regs : NULL)) |
| 14806 |
return 0; |
| 14807 |
|
| 14808 |
if (saved_order) |
| 14809 |
memcpy (saved_order, order, sizeof order); |
| 14810 |
|
| 14811 |
if (base) |
| 14812 |
{ |
| 14813 |
*base = base_reg; |
| 14814 |
|
| 14815 |
for (i = 0; i < nops; i++) |
| 14816 |
regs[i] = unsorted_regs[check_regs ? order[i] : i]; |
| 14817 |
|
| 14818 |
*load_offset = unsorted_offsets[order[0]]; |
| 14819 |
} |
| 14820 |
|
| 14821 |
if (unsorted_offsets[order[0]] == 0) |
| 14822 |
ldm_case = 1; /* ldmia */ |
| 14823 |
else if (TARGET_ARM && unsorted_offsets[order[0]] == 4) |
| 14824 |
ldm_case = 2; /* ldmib */ |
| 14825 |
else if (TARGET_ARM && unsorted_offsets[order[nops - 1]] == 0) |
| 14826 |
ldm_case = 3; /* ldmda */ |
| 14827 |
else if (TARGET_32BIT && unsorted_offsets[order[nops - 1]] == -4) |
| 14828 |
ldm_case = 4; /* ldmdb */ |
| 14829 |
else if (const_ok_for_arm (unsorted_offsets[order[0]]) |
| 14830 |
|| const_ok_for_arm (-unsorted_offsets[order[0]])) |
| 14831 |
ldm_case = 5; |
| 14832 |
else |
| 14833 |
return 0; |
| 14834 |
|
| 14835 |
if (!multiple_operation_profitable_p (false, nops, |
| 14836 |
ldm_case == 5 |
| 14837 |
? unsorted_offsets[order[0]] : 0)) |
| 14838 |
return 0; |
| 14839 |
|
| 14840 |
return ldm_case; |
| 14841 |
} |
| 14842 |
|
| 14843 |
/* Used to determine in a peephole whether a sequence of store instructions can |
| 14844 |
be changed into a store-multiple instruction. |
| 14845 |
NOPS is the number of separate store instructions we are examining. |
| 14846 |
NOPS_TOTAL is the total number of instructions recognized by the peephole |
| 14847 |
pattern. |
| 14848 |
The first NOPS entries in OPERANDS are the source registers, the next |
| 14849 |
NOPS entries are memory operands. If this function is successful, *BASE is |
| 14850 |
set to the common base register of the memory accesses; *LOAD_OFFSET is set |
| 14851 |
to the first memory location's offset from that base register. REGS is an |
| 14852 |
array filled in with the source register numbers, REG_RTXS (if nonnull) is |
| 14853 |
likewise filled with the corresponding rtx's. |
| 14854 |
SAVED_ORDER (if nonnull), is an array filled in with an order that maps insn |
| 14855 |
numbers to an ascending order of stores. |
| 14856 |
If CHECK_REGS is true, the sequence of registers in *REGS matches the stores |
| 14857 |
from ascending memory locations, and the function verifies that the register |
| 14858 |
numbers are themselves ascending. If CHECK_REGS is false, the register |
| 14859 |
numbers are stored in the order they are found in the operands. */ |
| 14860 |
static int |
| 14861 |
store_multiple_sequence (rtx *operands, int nops, int nops_total, |
| 14862 |
int *regs, rtx *reg_rtxs, int *saved_order, int *base, |
| 14863 |
HOST_WIDE_INT *load_offset, bool check_regs) |
| 14864 |
{ |
| 14865 |
int unsorted_regs[MAX_LDM_STM_OPS]; |
| 14866 |
rtx unsorted_reg_rtxs[MAX_LDM_STM_OPS]; |
| 14867 |
HOST_WIDE_INT unsorted_offsets[MAX_LDM_STM_OPS]; |
| 14868 |
int order[MAX_LDM_STM_OPS]; |
| 14869 |
int base_reg = -1; |
| 14870 |
rtx base_reg_rtx = NULL; |
| 14871 |
int i, stm_case; |
| 14872 |
|
| 14873 |
/* Write back of base register is currently only supported for Thumb 1. */ |
| 14874 |
int base_writeback = TARGET_THUMB1; |
| 14875 |
|
| 14876 |
/* Can only handle up to MAX_LDM_STM_OPS insns at present, though could be |
| 14877 |
easily extended if required. */ |
| 14878 |
gcc_assert (nops >= 2 && nops <= MAX_LDM_STM_OPS); |
| 14879 |
|
| 14880 |
memset (order, 0, MAX_LDM_STM_OPS * sizeof (int)); |
| 14881 |
|
| 14882 |
/* Loop over the operands and check that the memory references are |
| 14883 |
suitable (i.e. immediate offsets from the same base register). At |
| 14884 |
the same time, extract the target register, and the memory |
| 14885 |
offsets. */ |
| 14886 |
for (i = 0; i < nops; i++) |
| 14887 |
{ |
| 14888 |
rtx reg; |
| 14889 |
rtx offset; |
| 14890 |
|
| 14891 |
/* Convert a subreg of a mem into the mem itself. */ |
| 14892 |
if (GET_CODE (operands[nops + i]) == SUBREG) |
| 14893 |
operands[nops + i] = alter_subreg (operands + (nops + i), true); |
| 14894 |
|
| 14895 |
gcc_assert (MEM_P (operands[nops + i])); |
| 14896 |
|
| 14897 |
/* Don't reorder volatile memory references; it doesn't seem worth |
| 14898 |
looking for the case where the order is ok anyway. */ |
| 14899 |
if (MEM_VOLATILE_P (operands[nops + i])) |
| 14900 |
return 0; |
| 14901 |
|
| 14902 |
offset = const0_rtx; |
| 14903 |
|
| 14904 |
if ((REG_P (reg = XEXP (operands[nops + i], 0)) |
| 14905 |
|| (SUBREG_P (reg) |
| 14906 |
&& REG_P (reg = SUBREG_REG (reg)))) |
| 14907 |
|| (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS |
| 14908 |
&& ((REG_P (reg = XEXP (XEXP (operands[nops + i], 0), 0))) |
| 14909 |
|| (SUBREG_P (reg) |
| 14910 |
&& REG_P (reg = SUBREG_REG (reg)))) |
| 14911 |
&& (CONST_INT_P (offset |
| 14912 |
= XEXP (XEXP (operands[nops + i], 0), 1))))) |
| 14913 |
{ |
| 14914 |
unsorted_reg_rtxs[i] = (REG_P (operands[i]) |
| 14915 |
? operands[i] : SUBREG_REG (operands[i])); |
| 14916 |
unsorted_regs[i] = REGNO (unsorted_reg_rtxs[i]); |
| 14917 |
|
| 14918 |
if (i == 0) |
| 14919 |
{ |
| 14920 |
base_reg = REGNO (reg); |
| 14921 |
base_reg_rtx = reg; |
| 14922 |
if (TARGET_THUMB1 && base_reg > LAST_LO_REGNUM) |
| 14923 |
return 0; |
| 14924 |
} |
| 14925 |
else if (base_reg != (int) REGNO (reg)) |
| 14926 |
/* Not addressed from the same base register. */ |
| 14927 |
return 0; |
| 14928 |
|
| 14929 |
/* If it isn't an integer register, then we can't do this. */ |
| 14930 |
if (unsorted_regs[i] < 0 |
| 14931 |
|| (TARGET_THUMB1 && unsorted_regs[i] > LAST_LO_REGNUM) |
| 14932 |
/* The effects are unpredictable if the base register is |
| 14933 |
both updated and stored. */ |
| 14934 |
|| (base_writeback && unsorted_regs[i] == base_reg) |
| 14935 |
|| (TARGET_THUMB2 && unsorted_regs[i] == SP_REGNUM) |
| 14936 |
|| unsorted_regs[i] > 14) |
| 14937 |
return 0; |
| 14938 |
|
| 14939 |
unsorted_offsets[i] = INTVAL (offset); |
| 14940 |
if (i == 0 || unsorted_offsets[i] < unsorted_offsets[order[0]]) |
| 14941 |
order[0] = i; |
| 14942 |
} |
| 14943 |
else |
| 14944 |
/* Not a suitable memory address. */ |
| 14945 |
return 0; |
| 14946 |
} |
| 14947 |
|
| 14948 |
/* All the useful information has now been extracted from the |
| 14949 |
operands into unsorted_regs and unsorted_offsets; additionally, |
| 14950 |
order[0] has been set to the lowest offset in the list. Sort |
| 14951 |
the offsets into order, verifying that they are adjacent, and |
| 14952 |
check that the register numbers are ascending. */ |
| 14953 |
if (!compute_offset_order (nops, unsorted_offsets, order, |
| 14954 |
check_regs ? unsorted_regs : NULL)) |
| 14955 |
return 0; |
| 14956 |
|
| 14957 |
if (saved_order) |
| 14958 |
memcpy (saved_order, order, sizeof order); |
| 14959 |
|
| 14960 |
if (base) |
| 14961 |
{ |
| 14962 |
*base = base_reg; |
| 14963 |
|
| 14964 |
for (i = 0; i < nops; i++) |
| 14965 |
{ |
| 14966 |
regs[i] = unsorted_regs[check_regs ? order[i] : i]; |
| 14967 |
if (reg_rtxs) |
| 14968 |
reg_rtxs[i] = unsorted_reg_rtxs[check_regs ? order[i] : i]; |
| 14969 |
} |
| 14970 |
|
| 14971 |
*load_offset = unsorted_offsets[order[0]]; |
| 14972 |
} |
| 14973 |
|
| 14974 |
if (TARGET_THUMB1 |
| 14975 |
&& !peep2_reg_dead_p (nops_total, base_reg_rtx)) |
| 14976 |
return 0; |
| 14977 |
|
| 14978 |
if (unsorted_offsets[order[0]] == 0) |
| 14979 |
stm_case = 1; /* stmia */ |
| 14980 |
else if (TARGET_ARM && unsorted_offsets[order[0]] == 4) |
| 14981 |
stm_case = 2; /* stmib */ |
| 14982 |
else if (TARGET_ARM && unsorted_offsets[order[nops - 1]] == 0) |
| 14983 |
stm_case = 3; /* stmda */ |
| 14984 |
else if (TARGET_32BIT && unsorted_offsets[order[nops - 1]] == -4) |
| 14985 |
stm_case = 4; /* stmdb */ |
| 14986 |
else |
| 14987 |
return 0; |
| 14988 |
|
| 14989 |
if (!multiple_operation_profitable_p (false, nops, 0)) |
| 14990 |
return 0; |
| 14991 |
|
| 14992 |
return stm_case; |
| 14993 |
} |
| 14994 |
|
| 14995 |
/* Routines for use in generating RTL. */ |
| 14996 |
|
| 14997 |
/* Generate a load-multiple instruction. COUNT is the number of loads in |
| 14998 |
the instruction; REGS and MEMS are arrays containing the operands. |
| 14999 |
BASEREG is the base register to be used in addressing the memory operands. |
| 15000 |
WBACK_OFFSET is nonzero if the instruction should update the base |
| 15001 |
register. */ |
| 15002 |
|
| 15003 |
static rtx |
| 15004 |
arm_gen_load_multiple_1 (int count, int *regs, rtx *mems, rtx basereg, |
| 15005 |
HOST_WIDE_INT wback_offset) |
| 15006 |
{ |
| 15007 |
int i = 0, j; |
| 15008 |
rtx result; |
| 15009 |
|
| 15010 |
if (!multiple_operation_profitable_p (false, count, 0)) |
| 15011 |
{ |
| 15012 |
rtx seq; |
| 15013 |
|
| 15014 |
start_sequence (); |
| 15015 |
|
| 15016 |
for (i = 0; i < count; i++) |
| 15017 |
emit_move_insn (gen_rtx_REG (SImode, regs[i]), mems[i]); |
| 15018 |
|
| 15019 |
if (wback_offset != 0) |
| 15020 |
emit_move_insn (basereg, plus_constant (Pmode, basereg, wback_offset)); |
| 15021 |
|
| 15022 |
seq = get_insns (); |
| 15023 |
end_sequence (); |
| 15024 |
|
| 15025 |
return seq; |
| 15026 |
} |
| 15027 |
|
| 15028 |
result = gen_rtx_PARALLEL (VOIDmode, |
| 15029 |
rtvec_alloc (count + (wback_offset != 0 ? 1 : 0))); |
| 15030 |
if (wback_offset != 0) |
| 15031 |
{ |
| 15032 |
XVECEXP (result, 0, 0) |
| 15033 |
= gen_rtx_SET (basereg, plus_constant (Pmode, basereg, wback_offset)); |
| 15034 |
i = 1; |
| 15035 |
count++; |
| 15036 |
} |
| 15037 |
|
| 15038 |
for (j = 0; i < count; i++, j++) |
| 15039 |
XVECEXP (result, 0, i) |
| 15040 |
= gen_rtx_SET (gen_rtx_REG (SImode, regs[j]), mems[j]); |
| 15041 |
|
| 15042 |
return result; |
| 15043 |
} |
| 15044 |
|
| 15045 |
/* Generate a store-multiple instruction. COUNT is the number of stores in |
| 15046 |
the instruction; REGS and MEMS are arrays containing the operands. |
| 15047 |
BASEREG is the base register to be used in addressing the memory operands. |
| 15048 |
WBACK_OFFSET is nonzero if the instruction should update the base |
| 15049 |
register. */ |
| 15050 |
|
| 15051 |
static rtx |
| 15052 |
arm_gen_store_multiple_1 (int count, int *regs, rtx *mems, rtx basereg, |
| 15053 |
HOST_WIDE_INT wback_offset) |
| 15054 |
{ |
| 15055 |
int i = 0, j; |
| 15056 |
rtx result; |
| 15057 |
|
| 15058 |
if (GET_CODE (basereg) == PLUS) |
| 15059 |
basereg = XEXP (basereg, 0); |
| 15060 |
|
| 15061 |
if (!multiple_operation_profitable_p (false, count, 0)) |
| 15062 |
{ |
| 15063 |
rtx seq; |
| 15064 |
|
| 15065 |
start_sequence (); |
| 15066 |
|
| 15067 |
for (i = 0; i < count; i++) |
| 15068 |
emit_move_insn (mems[i], gen_rtx_REG (SImode, regs[i])); |
| 15069 |
|
| 15070 |
if (wback_offset != 0) |
| 15071 |
emit_move_insn (basereg, plus_constant (Pmode, basereg, wback_offset)); |
| 15072 |
|
| 15073 |
seq = get_insns (); |
| 15074 |
end_sequence (); |
| 15075 |
|
| 15076 |
return seq; |
| 15077 |
} |
| 15078 |
|
| 15079 |
result = gen_rtx_PARALLEL (VOIDmode, |
| 15080 |
rtvec_alloc (count + (wback_offset != 0 ? 1 : 0))); |
| 15081 |
if (wback_offset != 0) |
| 15082 |
{ |
| 15083 |
XVECEXP (result, 0, 0) |
| 15084 |
= gen_rtx_SET (basereg, plus_constant (Pmode, basereg, wback_offset)); |
| 15085 |
i = 1; |
| 15086 |
count++; |
| 15087 |
} |
| 15088 |
|
| 15089 |
for (j = 0; i < count; i++, j++) |
| 15090 |
XVECEXP (result, 0, i) |
| 15091 |
= gen_rtx_SET (mems[j], gen_rtx_REG (SImode, regs[j])); |
| 15092 |
|
| 15093 |
return result; |
| 15094 |
} |
| 15095 |
|
| 15096 |
/* Generate either a load-multiple or a store-multiple instruction. This |
| 15097 |
function can be used in situations where we can start with a single MEM |
| 15098 |
rtx and adjust its address upwards. |
| 15099 |
COUNT is the number of operations in the instruction, not counting a |
| 15100 |
possible update of the base register. REGS is an array containing the |
| 15101 |
register operands. |
| 15102 |
BASEREG is the base register to be used in addressing the memory operands, |
| 15103 |
which are constructed from BASEMEM. |
| 15104 |
WRITE_BACK specifies whether the generated instruction should include an |
| 15105 |
update of the base register. |
| 15106 |
OFFSETP is used to pass an offset to and from this function; this offset |
| 15107 |
is not used when constructing the address (instead BASEMEM should have an |
| 15108 |
appropriate offset in its address), it is used only for setting |
| 15109 |
MEM_OFFSET. It is updated only if WRITE_BACK is true.*/ |
| 15110 |
|
| 15111 |
static rtx |
| 15112 |
arm_gen_multiple_op (bool is_load, int *regs, int count, rtx basereg, |
| 15113 |
bool write_back, rtx basemem, HOST_WIDE_INT *offsetp) |
| 15114 |
{ |
| 15115 |
rtx mems[MAX_LDM_STM_OPS]; |
| 15116 |
HOST_WIDE_INT offset = *offsetp; |
| 15117 |
int i; |
| 15118 |
|
| 15119 |
gcc_assert (count <= MAX_LDM_STM_OPS); |
| 15120 |
|
| 15121 |
if (GET_CODE (basereg) == PLUS) |
| 15122 |
basereg = XEXP (basereg, 0); |
| 15123 |
|
| 15124 |
for (i = 0; i < count; i++) |
| 15125 |
{ |
| 15126 |
rtx addr = plus_constant (Pmode, basereg, i * 4); |
| 15127 |
mems[i] = adjust_automodify_address_nv (basemem, SImode, addr, offset); |
| 15128 |
offset += 4; |
| 15129 |
} |
| 15130 |
|
| 15131 |
if (write_back) |
| 15132 |
*offsetp = offset; |
| 15133 |
|
| 15134 |
if (is_load) |
| 15135 |
return arm_gen_load_multiple_1 (count, regs, mems, basereg, |
| 15136 |
write_back ? 4 * count : 0); |
| 15137 |
else |
| 15138 |
return arm_gen_store_multiple_1 (count, regs, mems, basereg, |
| 15139 |
write_back ? 4 * count : 0); |
| 15140 |
} |
| 15141 |
|
| 15142 |
rtx |
| 15143 |
arm_gen_load_multiple (int *regs, int count, rtx basereg, int write_back, |
| 15144 |
rtx basemem, HOST_WIDE_INT *offsetp) |
| 15145 |
{ |
| 15146 |
return arm_gen_multiple_op (TRUE, regs, count, basereg, write_back, basemem, |
| 15147 |
offsetp); |
| 15148 |
} |
| 15149 |
|
| 15150 |
rtx |
| 15151 |
arm_gen_store_multiple (int *regs, int count, rtx basereg, int write_back, |
| 15152 |
rtx basemem, HOST_WIDE_INT *offsetp) |
| 15153 |
{ |
| 15154 |
return arm_gen_multiple_op (FALSE, regs, count, basereg, write_back, basemem, |
| 15155 |
offsetp); |
| 15156 |
} |
| 15157 |
|
| 15158 |
/* Called from a peephole2 expander to turn a sequence of loads into an |
| 15159 |
LDM instruction. OPERANDS are the operands found by the peephole matcher; |
| 15160 |
NOPS indicates how many separate loads we are trying to combine. SORT_REGS |
| 15161 |
is true if we can reorder the registers because they are used commutatively |
| 15162 |
subsequently. |
| 15163 |
Returns true iff we could generate a new instruction. */ |
| 15164 |
|
| 15165 |
bool |
| 15166 |
gen_ldm_seq (rtx *operands, int nops, bool sort_regs) |
| 15167 |
{ |
| 15168 |
int regs[MAX_LDM_STM_OPS], mem_order[MAX_LDM_STM_OPS]; |
| 15169 |
rtx mems[MAX_LDM_STM_OPS]; |
| 15170 |
int i, j, base_reg; |
| 15171 |
rtx base_reg_rtx; |
| 15172 |
HOST_WIDE_INT offset; |
| 15173 |
int write_back = FALSE; |
| 15174 |
int ldm_case; |
| 15175 |
rtx addr; |
| 15176 |
|
| 15177 |
ldm_case = load_multiple_sequence (operands, nops, regs, mem_order, |
| 15178 |
&base_reg, &offset, !sort_regs); |
| 15179 |
|
| 15180 |
if (ldm_case == 0) |
| 15181 |
return false; |
| 15182 |
|
| 15183 |
if (sort_regs) |
| 15184 |
for (i = 0; i < nops - 1; i++) |
| 15185 |
for (j = i + 1; j < nops; j++) |
| 15186 |
if (regs[i] > regs[j]) |
| 15187 |
{ |
| 15188 |
int t = regs[i]; |
| 15189 |
regs[i] = regs[j]; |
| 15190 |
regs[j] = t; |
| 15191 |
} |
| 15192 |
base_reg_rtx = gen_rtx_REG (Pmode, base_reg); |
| 15193 |
|
| 15194 |
if (TARGET_THUMB1) |
| 15195 |
{ |
| 15196 |
gcc_assert (ldm_case == 1 || ldm_case == 5); |
| 15197 |
|
| 15198 |
/* Thumb-1 ldm uses writeback except if the base is loaded. */ |
| 15199 |
write_back = true; |
| 15200 |
for (i = 0; i < nops; i++) |
| 15201 |
if (base_reg == regs[i]) |
| 15202 |
write_back = false; |
| 15203 |
|
| 15204 |
/* Ensure the base is dead if it is updated. */ |
| 15205 |
if (write_back && !peep2_reg_dead_p (nops, base_reg_rtx)) |
| 15206 |
return false; |
| 15207 |
} |
| 15208 |
|
| 15209 |
if (ldm_case == 5) |
| 15210 |
{ |
| 15211 |
rtx newbase = TARGET_THUMB1 ? base_reg_rtx : gen_rtx_REG (SImode, regs[0]); |
| 15212 |
emit_insn (gen_addsi3 (newbase, base_reg_rtx, GEN_INT (offset))); |
| 15213 |
offset = 0; |
| 15214 |
base_reg_rtx = newbase; |
| 15215 |
} |
| 15216 |
|
| 15217 |
for (i = 0; i < nops; i++) |
| 15218 |
{ |
| 15219 |
addr = plus_constant (Pmode, base_reg_rtx, offset + i * 4); |
| 15220 |
mems[i] = adjust_automodify_address_nv (operands[nops + mem_order[i]], |
| 15221 |
SImode, addr, 0); |
| 15222 |
} |
| 15223 |
emit_insn (arm_gen_load_multiple_1 (nops, regs, mems, base_reg_rtx, |
| 15224 |
write_back ? offset + i * 4 : 0)); |
| 15225 |
return true; |
| 15226 |
} |
| 15227 |
|
| 15228 |
/* Called from a peephole2 expander to turn a sequence of stores into an |
| 15229 |
STM instruction. OPERANDS are the operands found by the peephole matcher; |
| 15230 |
NOPS indicates how many separate stores we are trying to combine. |
| 15231 |
Returns true iff we could generate a new instruction. */ |
| 15232 |
|
| 15233 |
bool |
| 15234 |
gen_stm_seq (rtx *operands, int nops) |
| 15235 |
{ |
| 15236 |
int i; |
| 15237 |
int regs[MAX_LDM_STM_OPS], mem_order[MAX_LDM_STM_OPS]; |
| 15238 |
rtx mems[MAX_LDM_STM_OPS]; |
| 15239 |
int base_reg; |
| 15240 |
rtx base_reg_rtx; |
| 15241 |
HOST_WIDE_INT offset; |
| 15242 |
int write_back = FALSE; |
| 15243 |
int stm_case; |
| 15244 |
rtx addr; |
| 15245 |
bool base_reg_dies; |
| 15246 |
|
| 15247 |
stm_case = store_multiple_sequence (operands, nops, nops, regs, NULL, |
| 15248 |
mem_order, &base_reg, &offset, true); |
| 15249 |
|
| 15250 |
if (stm_case == 0) |
| 15251 |
return false; |
| 15252 |
|
| 15253 |
base_reg_rtx = gen_rtx_REG (Pmode, base_reg); |
| 15254 |
|
| 15255 |
base_reg_dies = peep2_reg_dead_p (nops, base_reg_rtx); |
| 15256 |
if (TARGET_THUMB1) |
| 15257 |
{ |
| 15258 |
gcc_assert (base_reg_dies); |
| 15259 |
write_back = TRUE; |
| 15260 |
} |
| 15261 |
|
| 15262 |
if (stm_case == 5) |
| 15263 |
{ |
| 15264 |
gcc_assert (base_reg_dies); |
| 15265 |
emit_insn (gen_addsi3 (base_reg_rtx, base_reg_rtx, GEN_INT (offset))); |
| 15266 |
offset = 0; |
| 15267 |
} |
| 15268 |
|
| 15269 |
addr = plus_constant (Pmode, base_reg_rtx, offset); |
| 15270 |
|
| 15271 |
for (i = 0; i < nops; i++) |
| 15272 |
{ |
| 15273 |
addr = plus_constant (Pmode, base_reg_rtx, offset + i * 4); |
| 15274 |
mems[i] = adjust_automodify_address_nv (operands[nops + mem_order[i]], |
| 15275 |
SImode, addr, 0); |
| 15276 |
} |
| 15277 |
emit_insn (arm_gen_store_multiple_1 (nops, regs, mems, base_reg_rtx, |
| 15278 |
write_back ? offset + i * 4 : 0)); |
| 15279 |
return true; |
| 15280 |
} |
| 15281 |
|
| 15282 |
/* Called from a peephole2 expander to turn a sequence of stores that are |
| 15283 |
preceded by constant loads into an STM instruction. OPERANDS are the |
| 15284 |
operands found by the peephole matcher; NOPS indicates how many |
| 15285 |
separate stores we are trying to combine; there are 2 * NOPS |
| 15286 |
instructions in the peephole. |
| 15287 |
Returns true iff we could generate a new instruction. */ |
| 15288 |
|
| 15289 |
bool |
| 15290 |
gen_const_stm_seq (rtx *operands, int nops) |
| 15291 |
{ |
| 15292 |
int regs[MAX_LDM_STM_OPS], sorted_regs[MAX_LDM_STM_OPS]; |
| 15293 |
int reg_order[MAX_LDM_STM_OPS], mem_order[MAX_LDM_STM_OPS]; |
| 15294 |
rtx reg_rtxs[MAX_LDM_STM_OPS], orig_reg_rtxs[MAX_LDM_STM_OPS]; |
| 15295 |
rtx mems[MAX_LDM_STM_OPS]; |
| 15296 |
int base_reg; |
| 15297 |
rtx base_reg_rtx; |
| 15298 |
HOST_WIDE_INT offset; |
| 15299 |
int write_back = FALSE; |
| 15300 |
int stm_case; |
| 15301 |
rtx addr; |
| 15302 |
bool base_reg_dies; |
| 15303 |
int i, j; |
| 15304 |
HARD_REG_SET allocated; |
| 15305 |
|
| 15306 |
stm_case = store_multiple_sequence (operands, nops, 2 * nops, regs, reg_rtxs, |
| 15307 |
mem_order, &base_reg, &offset, false); |
| 15308 |
|
| 15309 |
if (stm_case == 0) |
| 15310 |
return false; |
| 15311 |
|
| 15312 |
memcpy (orig_reg_rtxs, reg_rtxs, sizeof orig_reg_rtxs); |
| 15313 |
|
| 15314 |
/* If the same register is used more than once, try to find a free |
| 15315 |
register. */ |
| 15316 |
CLEAR_HARD_REG_SET (allocated); |
| 15317 |
for (i = 0; i < nops; i++) |
| 15318 |
{ |
| 15319 |
for (j = i + 1; j < nops; j++) |
| 15320 |
if (regs[i] == regs[j]) |
| 15321 |
{ |
| 15322 |
rtx t = peep2_find_free_register (0, nops * 2, |
| 15323 |
TARGET_THUMB1 ? "l" : "r", |
| 15324 |
SImode, &allocated); |
| 15325 |
if (t == NULL_RTX) |
| 15326 |
return false; |
| 15327 |
reg_rtxs[i] = t; |
| 15328 |
regs[i] = REGNO (t); |
| 15329 |
} |
| 15330 |
} |
| 15331 |
|
| 15332 |
/* Compute an ordering that maps the register numbers to an ascending |
| 15333 |
sequence. */ |
| 15334 |
reg_order[0] = 0; |
| 15335 |
for (i = 0; i < nops; i++) |
| 15336 |
if (regs[i] < regs[reg_order[0]]) |
| 15337 |
reg_order[0] = i; |
| 15338 |
|
| 15339 |
for (i = 1; i < nops; i++) |
| 15340 |
{ |
| 15341 |
int this_order = reg_order[i - 1]; |
| 15342 |
for (j = 0; j < nops; j++) |
| 15343 |
if (regs[j] > regs[reg_order[i - 1]] |
| 15344 |
&& (this_order == reg_order[i - 1] |
| 15345 |
|| regs[j] < regs[this_order])) |
| 15346 |
this_order = j; |
| 15347 |
reg_order[i] = this_order; |
| 15348 |
} |
| 15349 |
|
| 15350 |
/* Ensure that registers that must be live after the instruction end |
| 15351 |
up with the correct value. */ |
| 15352 |
for (i = 0; i < nops; i++) |
| 15353 |
{ |
| 15354 |
int this_order = reg_order[i]; |
| 15355 |
if ((this_order != mem_order[i] |
| 15356 |
|| orig_reg_rtxs[this_order] != reg_rtxs[this_order]) |
| 15357 |
&& !peep2_reg_dead_p (nops * 2, orig_reg_rtxs[this_order])) |
| 15358 |
return false; |
| 15359 |
} |
| 15360 |
|
| 15361 |
/* Load the constants. */ |
| 15362 |
for (i = 0; i < nops; i++) |
| 15363 |
{ |
| 15364 |
rtx op = operands[2 * nops + mem_order[i]]; |
| 15365 |
sorted_regs[i] = regs[reg_order[i]]; |
| 15366 |
emit_move_insn (reg_rtxs[reg_order[i]], op); |
| 15367 |
} |
| 15368 |
|
| 15369 |
base_reg_rtx = gen_rtx_REG (Pmode, base_reg); |
| 15370 |
|
| 15371 |
base_reg_dies = peep2_reg_dead_p (nops * 2, base_reg_rtx); |
| 15372 |
if (TARGET_THUMB1) |
| 15373 |
{ |
| 15374 |
gcc_assert (base_reg_dies); |
| 15375 |
write_back = TRUE; |
| 15376 |
} |
| 15377 |
|
| 15378 |
if (stm_case == 5) |
| 15379 |
{ |
| 15380 |
gcc_assert (base_reg_dies); |
| 15381 |
emit_insn (gen_addsi3 (base_reg_rtx, base_reg_rtx, GEN_INT (offset))); |
| 15382 |
offset = 0; |
| 15383 |
} |
| 15384 |
|
| 15385 |
addr = plus_constant (Pmode, base_reg_rtx, offset); |
| 15386 |
|
| 15387 |
for (i = 0; i < nops; i++) |
| 15388 |
{ |
| 15389 |
addr = plus_constant (Pmode, base_reg_rtx, offset + i * 4); |
| 15390 |
mems[i] = adjust_automodify_address_nv (operands[nops + mem_order[i]], |
| 15391 |
SImode, addr, 0); |
| 15392 |
} |
| 15393 |
emit_insn (arm_gen_store_multiple_1 (nops, sorted_regs, mems, base_reg_rtx, |
| 15394 |
write_back ? offset + i * 4 : 0)); |
| 15395 |
return true; |
| 15396 |
} |
| 15397 |
|
| 15398 |
/* Copy a block of memory using plain ldr/str/ldrh/strh instructions, to permit |
| 15399 |
unaligned copies on processors which support unaligned semantics for those |
| 15400 |
instructions. INTERLEAVE_FACTOR can be used to attempt to hide load latency |
| 15401 |
(using more registers) by doing e.g. load/load/store/store for a factor of 2. |
| 15402 |
An interleave factor of 1 (the minimum) will perform no interleaving. |
| 15403 |
Load/store multiple are used for aligned addresses where possible. */ |
| 15404 |
|
| 15405 |
static void |
| 15406 |
arm_block_move_unaligned_straight (rtx dstbase, rtx srcbase, |
| 15407 |
HOST_WIDE_INT length, |
| 15408 |
unsigned int interleave_factor) |
| 15409 |
{ |
| 15410 |
rtx *regs = XALLOCAVEC (rtx, interleave_factor); |
| 15411 |
int *regnos = XALLOCAVEC (int, interleave_factor); |
| 15412 |
HOST_WIDE_INT block_size_bytes = interleave_factor * UNITS_PER_WORD; |
| 15413 |
HOST_WIDE_INT i, j; |
| 15414 |
HOST_WIDE_INT remaining = length, words; |
| 15415 |
rtx halfword_tmp = NULL, byte_tmp = NULL; |
| 15416 |
rtx dst, src; |
| 15417 |
bool src_aligned = MEM_ALIGN (srcbase) >= BITS_PER_WORD; |
| 15418 |
bool dst_aligned = MEM_ALIGN (dstbase) >= BITS_PER_WORD; |
| 15419 |
HOST_WIDE_INT srcoffset, dstoffset; |
| 15420 |
HOST_WIDE_INT src_autoinc, dst_autoinc; |
| 15421 |
rtx mem, addr; |
| 15422 |
|
| 15423 |
gcc_assert (interleave_factor >= 1 && interleave_factor <= 4); |
| 15424 |
|
| 15425 |
/* Use hard registers if we have aligned source or destination so we can use |
| 15426 |
load/store multiple with contiguous registers. */ |
| 15427 |
if (dst_aligned || src_aligned) |
| 15428 |
for (i = 0; i < interleave_factor; i++) |
| 15429 |
regs[i] = gen_rtx_REG (SImode, i); |
| 15430 |
else |
| 15431 |
for (i = 0; i < interleave_factor; i++) |
| 15432 |
regs[i] = gen_reg_rtx (SImode); |
| 15433 |
|
| 15434 |
dst = copy_addr_to_reg (XEXP (dstbase, 0)); |
| 15435 |
src = copy_addr_to_reg (XEXP (srcbase, 0)); |
| 15436 |
|
| 15437 |
srcoffset = dstoffset = 0; |
| 15438 |
|
| 15439 |
/* Calls to arm_gen_load_multiple and arm_gen_store_multiple update SRC/DST. |
| 15440 |
For copying the last bytes we want to subtract this offset again. */ |
| 15441 |
src_autoinc = dst_autoinc = 0; |
| 15442 |
|
| 15443 |
for (i = 0; i < interleave_factor; i++) |
| 15444 |
regnos[i] = i; |
| 15445 |
|
| 15446 |
/* Copy BLOCK_SIZE_BYTES chunks. */ |
| 15447 |
|
| 15448 |
for (i = 0; i + block_size_bytes <= length; i += block_size_bytes) |
| 15449 |
{ |
| 15450 |
/* Load words. */ |
| 15451 |
if (src_aligned && interleave_factor > 1) |
| 15452 |
{ |
| 15453 |
emit_insn (arm_gen_load_multiple (regnos, interleave_factor, src, |
| 15454 |
TRUE, srcbase, &srcoffset)); |
| 15455 |
src_autoinc += UNITS_PER_WORD * interleave_factor; |
| 15456 |
} |
| 15457 |
else |
| 15458 |
{ |
| 15459 |
for (j = 0; j < interleave_factor; j++) |
| 15460 |
{ |
| 15461 |
addr = plus_constant (Pmode, src, (srcoffset + j * UNITS_PER_WORD |
| 15462 |
- src_autoinc)); |
| 15463 |
mem = adjust_automodify_address (srcbase, SImode, addr, |
| 15464 |
srcoffset + j * UNITS_PER_WORD); |
| 15465 |
emit_insn (gen_unaligned_loadsi (regs[j], mem)); |
| 15466 |
} |
| 15467 |
srcoffset += block_size_bytes; |
| 15468 |
} |
| 15469 |
|
| 15470 |
/* Store words. */ |
| 15471 |
if (dst_aligned && interleave_factor > 1) |
| 15472 |
{ |
| 15473 |
emit_insn (arm_gen_store_multiple (regnos, interleave_factor, dst, |
| 15474 |
TRUE, dstbase, &dstoffset)); |
| 15475 |
dst_autoinc += UNITS_PER_WORD * interleave_factor; |
| 15476 |
} |
| 15477 |
else |
| 15478 |
{ |
| 15479 |
for (j = 0; j < interleave_factor; j++) |
| 15480 |
{ |
| 15481 |
addr = plus_constant (Pmode, dst, (dstoffset + j * UNITS_PER_WORD |
| 15482 |
- dst_autoinc)); |
| 15483 |
mem = adjust_automodify_address (dstbase, SImode, addr, |
| 15484 |
dstoffset + j * UNITS_PER_WORD); |
| 15485 |
emit_insn (gen_unaligned_storesi (mem, regs[j])); |
| 15486 |
} |
| 15487 |
dstoffset += block_size_bytes; |
| 15488 |
} |
| 15489 |
|
| 15490 |
remaining -= block_size_bytes; |
| 15491 |
} |
| 15492 |
|
| 15493 |
/* Copy any whole words left (note these aren't interleaved with any |
| 15494 |
subsequent halfword/byte load/stores in the interests of simplicity). */ |
| 15495 |
|
| 15496 |
words = remaining / UNITS_PER_WORD; |
| 15497 |
|
| 15498 |
gcc_assert (words < interleave_factor); |
| 15499 |
|
| 15500 |
if (src_aligned && words > 1) |
| 15501 |
{ |
| 15502 |
emit_insn (arm_gen_load_multiple (regnos, words, src, TRUE, srcbase, |
| 15503 |
&srcoffset)); |
| 15504 |
src_autoinc += UNITS_PER_WORD * words; |
| 15505 |
} |
| 15506 |
else |
| 15507 |
{ |
| 15508 |
for (j = 0; j < words; j++) |
| 15509 |
{ |
| 15510 |
addr = plus_constant (Pmode, src, |
| 15511 |
srcoffset + j * UNITS_PER_WORD - src_autoinc); |
| 15512 |
mem = adjust_automodify_address (srcbase, SImode, addr, |
| 15513 |
srcoffset + j * UNITS_PER_WORD); |
| 15514 |
if (src_aligned) |
| 15515 |
emit_move_insn (regs[j], mem); |
| 15516 |
else |
| 15517 |
emit_insn (gen_unaligned_loadsi (regs[j], mem)); |
| 15518 |
} |
| 15519 |
srcoffset += words * UNITS_PER_WORD; |
| 15520 |
} |
| 15521 |
|
| 15522 |
if (dst_aligned && words > 1) |
| 15523 |
{ |
| 15524 |
emit_insn (arm_gen_store_multiple (regnos, words, dst, TRUE, dstbase, |
| 15525 |
&dstoffset)); |
| 15526 |
dst_autoinc += words * UNITS_PER_WORD; |
| 15527 |
} |
| 15528 |
else |
| 15529 |
{ |
| 15530 |
for (j = 0; j < words; j++) |
| 15531 |
{ |
| 15532 |
addr = plus_constant (Pmode, dst, |
| 15533 |
dstoffset + j * UNITS_PER_WORD - dst_autoinc); |
| 15534 |
mem = adjust_automodify_address (dstbase, SImode, addr, |
| 15535 |
dstoffset + j * UNITS_PER_WORD); |
| 15536 |
if (dst_aligned) |
| 15537 |
emit_move_insn (mem, regs[j]); |
| 15538 |
else |
| 15539 |
emit_insn (gen_unaligned_storesi (mem, regs[j])); |
| 15540 |
} |
| 15541 |
dstoffset += words * UNITS_PER_WORD; |
| 15542 |
} |
| 15543 |
|
| 15544 |
remaining -= words * UNITS_PER_WORD; |
| 15545 |
|
| 15546 |
gcc_assert (remaining < 4); |
| 15547 |
|
| 15548 |
/* Copy a halfword if necessary. */ |
| 15549 |
|
| 15550 |
if (remaining >= 2) |
| 15551 |
{ |
| 15552 |
halfword_tmp = gen_reg_rtx (SImode); |
| 15553 |
|
| 15554 |
addr = plus_constant (Pmode, src, srcoffset - src_autoinc); |
| 15555 |
mem = adjust_automodify_address (srcbase, HImode, addr, srcoffset); |
| 15556 |
emit_insn (gen_unaligned_loadhiu (halfword_tmp, mem)); |
| 15557 |
|
| 15558 |
/* Either write out immediately, or delay until we've loaded the last |
| 15559 |
byte, depending on interleave factor. */ |
| 15560 |
if (interleave_factor == 1) |
| 15561 |
{ |
| 15562 |
addr = plus_constant (Pmode, dst, dstoffset - dst_autoinc); |
| 15563 |
mem = adjust_automodify_address (dstbase, HImode, addr, dstoffset); |
| 15564 |
emit_insn (gen_unaligned_storehi (mem, |
| 15565 |
gen_lowpart (HImode, halfword_tmp))); |
| 15566 |
halfword_tmp = NULL; |
| 15567 |
dstoffset += 2; |
| 15568 |
} |
| 15569 |
|
| 15570 |
remaining -= 2; |
| 15571 |
srcoffset += 2; |
| 15572 |
} |
| 15573 |
|
| 15574 |
gcc_assert (remaining < 2); |
| 15575 |
|
| 15576 |
/* Copy last byte. */ |
| 15577 |
|
| 15578 |
if ((remaining & 1) != 0) |
| 15579 |
{ |
| 15580 |
byte_tmp = gen_reg_rtx (SImode); |
| 15581 |
|
| 15582 |
addr = plus_constant (Pmode, src, srcoffset - src_autoinc); |
| 15583 |
mem = adjust_automodify_address (srcbase, QImode, addr, srcoffset); |
| 15584 |
emit_move_insn (gen_lowpart (QImode, byte_tmp), mem); |
| 15585 |
|
| 15586 |
if (interleave_factor == 1) |
| 15587 |
{ |
| 15588 |
addr = plus_constant (Pmode, dst, dstoffset - dst_autoinc); |
| 15589 |
mem = adjust_automodify_address (dstbase, QImode, addr, dstoffset); |
| 15590 |
emit_move_insn (mem, gen_lowpart (QImode, byte_tmp)); |
| 15591 |
byte_tmp = NULL; |
| 15592 |
dstoffset++; |
| 15593 |
} |
| 15594 |
|
| 15595 |
remaining--; |
| 15596 |
srcoffset++; |
| 15597 |
} |
| 15598 |
|
| 15599 |
/* Store last halfword if we haven't done so already. */ |
| 15600 |
|
| 15601 |
if (halfword_tmp) |
| 15602 |
{ |
| 15603 |
addr = plus_constant (Pmode, dst, dstoffset - dst_autoinc); |
| 15604 |
mem = adjust_automodify_address (dstbase, HImode, addr, dstoffset); |
| 15605 |
emit_insn (gen_unaligned_storehi (mem, |
| 15606 |
gen_lowpart (HImode, halfword_tmp))); |
| 15607 |
dstoffset += 2; |
| 15608 |
} |
| 15609 |
|
| 15610 |
/* Likewise for last byte. */ |
| 15611 |
|
| 15612 |
if (byte_tmp) |
| 15613 |
{ |
| 15614 |
addr = plus_constant (Pmode, dst, dstoffset - dst_autoinc); |
| 15615 |
mem = adjust_automodify_address (dstbase, QImode, addr, dstoffset); |
| 15616 |
emit_move_insn (mem, gen_lowpart (QImode, byte_tmp)); |
| 15617 |
dstoffset++; |
| 15618 |
} |
| 15619 |
|
| 15620 |
gcc_assert (remaining == 0 && srcoffset == dstoffset); |
| 15621 |
} |
| 15622 |
|
| 15623 |
/* From mips_adjust_block_mem: |
| 15624 |
|
| 15625 |
Helper function for doing a loop-based block operation on memory |
| 15626 |
reference MEM. Each iteration of the loop will operate on LENGTH |
| 15627 |
bytes of MEM. |
| 15628 |
|
| 15629 |
Create a new base register for use within the loop and point it to |
| 15630 |
the start of MEM. Create a new memory reference that uses this |
| 15631 |
register. Store them in *LOOP_REG and *LOOP_MEM respectively. */ |
| 15632 |
|
| 15633 |
static void |
| 15634 |
arm_adjust_block_mem (rtx mem, HOST_WIDE_INT length, rtx *loop_reg, |
| 15635 |
rtx *loop_mem) |
| 15636 |
{ |
| 15637 |
*loop_reg = copy_addr_to_reg (XEXP (mem, 0)); |
| 15638 |
|
| 15639 |
/* Although the new mem does not refer to a known location, |
| 15640 |
it does keep up to LENGTH bytes of alignment. */ |
| 15641 |
*loop_mem = change_address (mem, BLKmode, *loop_reg); |
| 15642 |
set_mem_align (*loop_mem, MIN (MEM_ALIGN (mem), length * BITS_PER_UNIT)); |
| 15643 |
} |
| 15644 |
|
| 15645 |
/* From mips_block_move_loop: |
| 15646 |
|
| 15647 |
Move LENGTH bytes from SRC to DEST using a loop that moves BYTES_PER_ITER |
| 15648 |
bytes at a time. LENGTH must be at least BYTES_PER_ITER. Assume that |
| 15649 |
the memory regions do not overlap. */ |
| 15650 |
|
| 15651 |
static void |
| 15652 |
arm_block_move_unaligned_loop (rtx dest, rtx src, HOST_WIDE_INT length, |
| 15653 |
unsigned int interleave_factor, |
| 15654 |
HOST_WIDE_INT bytes_per_iter) |
| 15655 |
{ |
| 15656 |
rtx src_reg, dest_reg, final_src, test; |
| 15657 |
HOST_WIDE_INT leftover; |
| 15658 |
|
| 15659 |
leftover = length % bytes_per_iter; |
| 15660 |
length -= leftover; |
| 15661 |
|
| 15662 |
/* Create registers and memory references for use within the loop. */ |
| 15663 |
arm_adjust_block_mem (src, bytes_per_iter, &src_reg, &src); |
| 15664 |
arm_adjust_block_mem (dest, bytes_per_iter, &dest_reg, &dest); |
| 15665 |
|
| 15666 |
/* Calculate the value that SRC_REG should have after the last iteration of |
| 15667 |
the loop. */ |
| 15668 |
final_src = expand_simple_binop (Pmode, PLUS, src_reg, GEN_INT (length), |
| 15669 |
0, 0, OPTAB_WIDEN); |
| 15670 |
|
| 15671 |
/* Emit the start of the loop. */ |
| 15672 |
rtx_code_label *label = gen_label_rtx (); |
| 15673 |
emit_label (label); |
| 15674 |
|
| 15675 |
/* Emit the loop body. */ |
| 15676 |
arm_block_move_unaligned_straight (dest, src, bytes_per_iter, |
| 15677 |
interleave_factor); |
| 15678 |
|
| 15679 |
/* Move on to the next block. */ |
| 15680 |
emit_move_insn (src_reg, plus_constant (Pmode, src_reg, bytes_per_iter)); |
| 15681 |
emit_move_insn (dest_reg, plus_constant (Pmode, dest_reg, bytes_per_iter)); |
| 15682 |
|
| 15683 |
/* Emit the loop condition. */ |
| 15684 |
test = gen_rtx_NE (VOIDmode, src_reg, final_src); |
| 15685 |
emit_jump_insn (gen_cbranchsi4 (test, src_reg, final_src, label)); |
| 15686 |
|
| 15687 |
/* Mop up any left-over bytes. */ |
| 15688 |
if (leftover) |
| 15689 |
arm_block_move_unaligned_straight (dest, src, leftover, interleave_factor); |
| 15690 |
} |
| 15691 |
|
| 15692 |
/* Emit a block move when either the source or destination is unaligned (not |
| 15693 |
aligned to a four-byte boundary). This may need further tuning depending on |
| 15694 |
core type, optimize_size setting, etc. */ |
| 15695 |
|
| 15696 |
static int |
| 15697 |
arm_cpymemqi_unaligned (rtx *operands) |
| 15698 |
{ |
| 15699 |
HOST_WIDE_INT length = INTVAL (operands[2]); |
| 15700 |
|
| 15701 |
if (optimize_size) |
| 15702 |
{ |
| 15703 |
bool src_aligned = MEM_ALIGN (operands[1]) >= BITS_PER_WORD; |
| 15704 |
bool dst_aligned = MEM_ALIGN (operands[0]) >= BITS_PER_WORD; |
| 15705 |
/* Inlined memcpy using ldr/str/ldrh/strh can be quite big: try to limit |
| 15706 |
size of code if optimizing for size. We'll use ldm/stm if src_aligned |
| 15707 |
or dst_aligned though: allow more interleaving in those cases since the |
| 15708 |
resulting code can be smaller. */ |
| 15709 |
unsigned int interleave_factor = (src_aligned || dst_aligned) ? 2 : 1; |
| 15710 |
HOST_WIDE_INT bytes_per_iter = (src_aligned || dst_aligned) ? 8 : 4; |
| 15711 |
|
| 15712 |
if (length > 12) |
| 15713 |
arm_block_move_unaligned_loop (operands[0], operands[1], length, |
| 15714 |
interleave_factor, bytes_per_iter); |
| 15715 |
else |
| 15716 |
arm_block_move_unaligned_straight (operands[0], operands[1], length, |
| 15717 |
interleave_factor); |
| 15718 |
} |
| 15719 |
else |
| 15720 |
{ |
| 15721 |
/* Note that the loop created by arm_block_move_unaligned_loop may be |
| 15722 |
subject to loop unrolling, which makes tuning this condition a little |
| 15723 |
redundant. */ |
| 15724 |
if (length > 32) |
| 15725 |
arm_block_move_unaligned_loop (operands[0], operands[1], length, 4, 16); |
| 15726 |
else |
| 15727 |
arm_block_move_unaligned_straight (operands[0], operands[1], length, 4); |
| 15728 |
} |
| 15729 |
|
| 15730 |
return 1; |
| 15731 |
} |
| 15732 |
|
| 15733 |
int |
| 15734 |
arm_gen_cpymemqi (rtx *operands) |
| 15735 |
{ |
| 15736 |
HOST_WIDE_INT in_words_to_go, out_words_to_go, last_bytes; |
| 15737 |
HOST_WIDE_INT srcoffset, dstoffset; |
| 15738 |
rtx src, dst, srcbase, dstbase; |
| 15739 |
rtx part_bytes_reg = NULL; |
| 15740 |
rtx mem; |
| 15741 |
|
| 15742 |
if (!CONST_INT_P (operands[2]) |
| 15743 |
|| !CONST_INT_P (operands[3]) |
| 15744 |
|| INTVAL (operands[2]) > 64) |
| 15745 |
return 0; |
| 15746 |
|
| 15747 |
if (unaligned_access && (INTVAL (operands[3]) & 3) != 0) |
| 15748 |
return arm_cpymemqi_unaligned (operands); |
| 15749 |
|
| 15750 |
if (INTVAL (operands[3]) & 3) |
| 15751 |
return 0; |
| 15752 |
|
| 15753 |
dstbase = operands[0]; |
| 15754 |
srcbase = operands[1]; |
| 15755 |
|
| 15756 |
dst = copy_to_mode_reg (SImode, XEXP (dstbase, 0)); |
| 15757 |
src = copy_to_mode_reg (SImode, XEXP (srcbase, 0)); |
| 15758 |
|
| 15759 |
in_words_to_go = ARM_NUM_INTS (INTVAL (operands[2])); |
| 15760 |
out_words_to_go = INTVAL (operands[2]) / 4; |
| 15761 |
last_bytes = INTVAL (operands[2]) & 3; |
| 15762 |
dstoffset = srcoffset = 0; |
| 15763 |
|
| 15764 |
if (out_words_to_go != in_words_to_go && ((in_words_to_go - 1) & 3) != 0) |
| 15765 |
part_bytes_reg = gen_rtx_REG (SImode, (in_words_to_go - 1) & 3); |
| 15766 |
|
| 15767 |
while (in_words_to_go >= 2) |
| 15768 |
{ |
| 15769 |
if (in_words_to_go > 4) |
| 15770 |
emit_insn (arm_gen_load_multiple (arm_regs_in_sequence, 4, src, |
| 15771 |
TRUE, srcbase, &srcoffset)); |
| 15772 |
else |
| 15773 |
emit_insn (arm_gen_load_multiple (arm_regs_in_sequence, in_words_to_go, |
| 15774 |
src, FALSE, srcbase, |
| 15775 |
&srcoffset)); |
| 15776 |
|
| 15777 |
if (out_words_to_go) |
| 15778 |
{ |
| 15779 |
if (out_words_to_go > 4) |
| 15780 |
emit_insn (arm_gen_store_multiple (arm_regs_in_sequence, 4, dst, |
| 15781 |
TRUE, dstbase, &dstoffset)); |
| 15782 |
else if (out_words_to_go != 1) |
| 15783 |
emit_insn (arm_gen_store_multiple (arm_regs_in_sequence, |
| 15784 |
out_words_to_go, dst, |
| 15785 |
(last_bytes == 0 |
| 15786 |
? FALSE : TRUE), |
| 15787 |
dstbase, &dstoffset)); |
| 15788 |
else |
| 15789 |
{ |
| 15790 |
mem = adjust_automodify_address (dstbase, SImode, dst, dstoffset); |
| 15791 |
emit_move_insn (mem, gen_rtx_REG (SImode, R0_REGNUM)); |
| 15792 |
if (last_bytes != 0) |
| 15793 |
{ |
| 15794 |
emit_insn (gen_addsi3 (dst, dst, GEN_INT (4))); |
| 15795 |
dstoffset += 4; |
| 15796 |
} |
| 15797 |
} |
| 15798 |
} |
| 15799 |
|
| 15800 |
in_words_to_go -= in_words_to_go < 4 ? in_words_to_go : 4; |
| 15801 |
out_words_to_go -= out_words_to_go < 4 ? out_words_to_go : 4; |
| 15802 |
} |
| 15803 |
|
| 15804 |
/* OUT_WORDS_TO_GO will be zero here if there are byte stores to do. */ |
| 15805 |
if (out_words_to_go) |
| 15806 |
{ |
| 15807 |
rtx sreg; |
| 15808 |
|
| 15809 |
mem = adjust_automodify_address (srcbase, SImode, src, srcoffset); |
| 15810 |
sreg = copy_to_reg (mem); |
| 15811 |
|
| 15812 |
mem = adjust_automodify_address (dstbase, SImode, dst, dstoffset); |
| 15813 |
emit_move_insn (mem, sreg); |
| 15814 |
in_words_to_go--; |
| 15815 |
|
| 15816 |
gcc_assert (!in_words_to_go); /* Sanity check */ |
| 15817 |
} |
| 15818 |
|
| 15819 |
if (in_words_to_go) |
| 15820 |
{ |
| 15821 |
gcc_assert (in_words_to_go > 0); |
| 15822 |
|
| 15823 |
mem = adjust_automodify_address (srcbase, SImode, src, srcoffset); |
| 15824 |
part_bytes_reg = copy_to_mode_reg (SImode, mem); |
| 15825 |
} |
| 15826 |
|
| 15827 |
gcc_assert (!last_bytes || part_bytes_reg); |
| 15828 |
|
| 15829 |
if (BYTES_BIG_ENDIAN && last_bytes) |
| 15830 |
{ |
| 15831 |
rtx tmp = gen_reg_rtx (SImode); |
| 15832 |
|
| 15833 |
/* The bytes we want are in the top end of the word. */ |
| 15834 |
emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, |
| 15835 |
GEN_INT (8 * (4 - last_bytes)))); |
| 15836 |
part_bytes_reg = tmp; |
| 15837 |
|
| 15838 |
while (last_bytes) |
| 15839 |
{ |
| 15840 |
mem = adjust_automodify_address (dstbase, QImode, |
| 15841 |
plus_constant (Pmode, dst, |
| 15842 |
last_bytes - 1), |
| 15843 |
dstoffset + last_bytes - 1); |
| 15844 |
emit_move_insn (mem, gen_lowpart (QImode, part_bytes_reg)); |
| 15845 |
|
| 15846 |
if (--last_bytes) |
| 15847 |
{ |
| 15848 |
tmp = gen_reg_rtx (SImode); |
| 15849 |
emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8))); |
| 15850 |
part_bytes_reg = tmp; |
| 15851 |
} |
| 15852 |
} |
| 15853 |
|
| 15854 |
} |
| 15855 |
else |
| 15856 |
{ |
| 15857 |
if (last_bytes > 1) |
| 15858 |
{ |
| 15859 |
mem = adjust_automodify_address (dstbase, HImode, dst, dstoffset); |
| 15860 |
emit_move_insn (mem, gen_lowpart (HImode, part_bytes_reg)); |
| 15861 |
last_bytes -= 2; |
| 15862 |
if (last_bytes) |
| 15863 |
{ |
| 15864 |
rtx tmp = gen_reg_rtx (SImode); |
| 15865 |
emit_insn (gen_addsi3 (dst, dst, const2_rtx)); |
| 15866 |
emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (16))); |
| 15867 |
part_bytes_reg = tmp; |
| 15868 |
dstoffset += 2; |
| 15869 |
} |
| 15870 |
} |
| 15871 |
|
| 15872 |
if (last_bytes) |
| 15873 |
{ |
| 15874 |
mem = adjust_automodify_address (dstbase, QImode, dst, dstoffset); |
| 15875 |
emit_move_insn (mem, gen_lowpart (QImode, part_bytes_reg)); |
| 15876 |
} |
| 15877 |
} |
| 15878 |
|
| 15879 |
return 1; |
| 15880 |
} |
| 15881 |
|
| 15882 |
/* Helper for gen_cpymem_ldrd_strd. Increase the address of memory rtx |
| 15883 |
by mode size. */ |
| 15884 |
inline static rtx |
| 15885 |
next_consecutive_mem (rtx mem) |
| 15886 |
{ |
| 15887 |
machine_mode mode = GET_MODE (mem); |
| 15888 |
HOST_WIDE_INT offset = GET_MODE_SIZE (mode); |
| 15889 |
rtx addr = plus_constant (Pmode, XEXP (mem, 0), offset); |
| 15890 |
|
| 15891 |
return adjust_automodify_address (mem, mode, addr, offset); |
| 15892 |
} |
| 15893 |
|
| 15894 |
/* Copy using LDRD/STRD instructions whenever possible. |
| 15895 |
Returns true upon success. */ |
| 15896 |
bool |
| 15897 |
gen_cpymem_ldrd_strd (rtx *operands) |
| 15898 |
{ |
| 15899 |
unsigned HOST_WIDE_INT len; |
| 15900 |
HOST_WIDE_INT align; |
| 15901 |
rtx src, dst, base; |
| 15902 |
rtx reg0; |
| 15903 |
bool src_aligned, dst_aligned; |
| 15904 |
bool src_volatile, dst_volatile; |
| 15905 |
|
| 15906 |
gcc_assert (CONST_INT_P (operands[2])); |
| 15907 |
gcc_assert (CONST_INT_P (operands[3])); |
| 15908 |
|
| 15909 |
len = UINTVAL (operands[2]); |
| 15910 |
if (len > 64) |
| 15911 |
return false; |
| 15912 |
|
| 15913 |
/* Maximum alignment we can assume for both src and dst buffers. */ |
| 15914 |
align = INTVAL (operands[3]); |
| 15915 |
|
| 15916 |
if ((!unaligned_access) && (len >= 4) && ((align & 3) != 0)) |
| 15917 |
return false; |
| 15918 |
|
| 15919 |
/* Place src and dst addresses in registers |
| 15920 |
and update the corresponding mem rtx. */ |
| 15921 |
dst = operands[0]; |
| 15922 |
dst_volatile = MEM_VOLATILE_P (dst); |
| 15923 |
dst_aligned = MEM_ALIGN (dst) >= BITS_PER_WORD; |
| 15924 |
base = copy_to_mode_reg (SImode, XEXP (dst, 0)); |
| 15925 |
dst = adjust_automodify_address (dst, VOIDmode, base, 0); |
| 15926 |
|
| 15927 |
src = operands[1]; |
| 15928 |
src_volatile = MEM_VOLATILE_P (src); |
| 15929 |
src_aligned = MEM_ALIGN (src) >= BITS_PER_WORD; |
| 15930 |
base = copy_to_mode_reg (SImode, XEXP (src, 0)); |
| 15931 |
src = adjust_automodify_address (src, VOIDmode, base, 0); |
| 15932 |
|
| 15933 |
if (!unaligned_access && !(src_aligned && dst_aligned)) |
| 15934 |
return false; |
| 15935 |
|
| 15936 |
if (src_volatile || dst_volatile) |
| 15937 |
return false; |
| 15938 |
|
| 15939 |
/* If we cannot generate any LDRD/STRD, try to generate LDM/STM. */ |
| 15940 |
if (!(dst_aligned || src_aligned)) |
| 15941 |
return arm_gen_cpymemqi (operands); |
| 15942 |
|
| 15943 |
/* If the either src or dst is unaligned we'll be accessing it as pairs |
| 15944 |
of unaligned SImode accesses. Otherwise we can generate DImode |
| 15945 |
ldrd/strd instructions. */ |
| 15946 |
src = adjust_address (src, src_aligned ? DImode : SImode, 0); |
| 15947 |
dst = adjust_address (dst, dst_aligned ? DImode : SImode, 0); |
| 15948 |
|
| 15949 |
while (len >= 8) |
| 15950 |
{ |
| 15951 |
len -= 8; |
| 15952 |
reg0 = gen_reg_rtx (DImode); |
| 15953 |
rtx first_reg = NULL_RTX; |
| 15954 |
rtx second_reg = NULL_RTX; |
| 15955 |
|
| 15956 |
if (!src_aligned || !dst_aligned) |
| 15957 |
{ |
| 15958 |
if (BYTES_BIG_ENDIAN) |
| 15959 |
{ |
| 15960 |
second_reg = gen_lowpart (SImode, reg0); |
| 15961 |
first_reg = gen_highpart_mode (SImode, DImode, reg0); |
| 15962 |
} |
| 15963 |
else |
| 15964 |
{ |
| 15965 |
first_reg = gen_lowpart (SImode, reg0); |
| 15966 |
second_reg = gen_highpart_mode (SImode, DImode, reg0); |
| 15967 |
} |
| 15968 |
} |
| 15969 |
if (MEM_ALIGN (src) >= 2 * BITS_PER_WORD) |
| 15970 |
emit_move_insn (reg0, src); |
| 15971 |
else if (src_aligned) |
| 15972 |
emit_insn (gen_unaligned_loaddi (reg0, src)); |
| 15973 |
else |
| 15974 |
{ |
| 15975 |
emit_insn (gen_unaligned_loadsi (first_reg, src)); |
| 15976 |
src = next_consecutive_mem (src); |
| 15977 |
emit_insn (gen_unaligned_loadsi (second_reg, src)); |
| 15978 |
} |
| 15979 |
|
| 15980 |
if (MEM_ALIGN (dst) >= 2 * BITS_PER_WORD) |
| 15981 |
emit_move_insn (dst, reg0); |
| 15982 |
else if (dst_aligned) |
| 15983 |
emit_insn (gen_unaligned_storedi (dst, reg0)); |
| 15984 |
else |
| 15985 |
{ |
| 15986 |
emit_insn (gen_unaligned_storesi (dst, first_reg)); |
| 15987 |
dst = next_consecutive_mem (dst); |
| 15988 |
emit_insn (gen_unaligned_storesi (dst, second_reg)); |
| 15989 |
} |
| 15990 |
|
| 15991 |
src = next_consecutive_mem (src); |
| 15992 |
dst = next_consecutive_mem (dst); |
| 15993 |
} |
| 15994 |
|
| 15995 |
gcc_assert (len < 8); |
| 15996 |
if (len >= 4) |
| 15997 |
{ |
| 15998 |
/* More than a word but less than a double-word to copy. Copy a word. */ |
| 15999 |
reg0 = gen_reg_rtx (SImode); |
| 16000 |
src = adjust_address (src, SImode, 0); |
| 16001 |
dst = adjust_address (dst, SImode, 0); |
| 16002 |
if (src_aligned) |
| 16003 |
emit_move_insn (reg0, src); |
| 16004 |
else |
| 16005 |
emit_insn (gen_unaligned_loadsi (reg0, src)); |
| 16006 |
|
| 16007 |
if (dst_aligned) |
| 16008 |
emit_move_insn (dst, reg0); |
| 16009 |
else |
| 16010 |
emit_insn (gen_unaligned_storesi (dst, reg0)); |
| 16011 |
|
| 16012 |
src = next_consecutive_mem (src); |
| 16013 |
dst = next_consecutive_mem (dst); |
| 16014 |
len -= 4; |
| 16015 |
} |
| 16016 |
|
| 16017 |
if (len == 0) |
| 16018 |
return true; |
| 16019 |
|
| 16020 |
/* Copy the remaining bytes. */ |
| 16021 |
if (len >= 2) |
| 16022 |
{ |
| 16023 |
dst = adjust_address (dst, HImode, 0); |
| 16024 |
src = adjust_address (src, HImode, 0); |
| 16025 |
reg0 = gen_reg_rtx (SImode); |
| 16026 |
if (src_aligned) |
| 16027 |
emit_insn (gen_zero_extendhisi2 (reg0, src)); |
| 16028 |
else |
| 16029 |
emit_insn (gen_unaligned_loadhiu (reg0, src)); |
| 16030 |
|
| 16031 |
if (dst_aligned) |
| 16032 |
emit_insn (gen_movhi (dst, gen_lowpart(HImode, reg0))); |
| 16033 |
else |
| 16034 |
emit_insn (gen_unaligned_storehi (dst, gen_lowpart (HImode, reg0))); |
| 16035 |
|
| 16036 |
src = next_consecutive_mem (src); |
| 16037 |
dst = next_consecutive_mem (dst); |
| 16038 |
if (len == 2) |
| 16039 |
return true; |
| 16040 |
} |
| 16041 |
|
| 16042 |
dst = adjust_address (dst, QImode, 0); |
| 16043 |
src = adjust_address (src, QImode, 0); |
| 16044 |
reg0 = gen_reg_rtx (QImode); |
| 16045 |
emit_move_insn (reg0, src); |
| 16046 |
emit_move_insn (dst, reg0); |
| 16047 |
return true; |
| 16048 |
} |
| 16049 |
|
| 16050 |
/* Decompose operands for a 64-bit binary operation in OP1 and OP2 |
| 16051 |
into its component 32-bit subregs. OP2 may be an immediate |
| 16052 |
constant and we want to simplify it in that case. */ |
| 16053 |
void |
| 16054 |
arm_decompose_di_binop (rtx op1, rtx op2, rtx *lo_op1, rtx *hi_op1, |
| 16055 |
rtx *lo_op2, rtx *hi_op2) |
| 16056 |
{ |
| 16057 |
*lo_op1 = gen_lowpart (SImode, op1); |
| 16058 |
*hi_op1 = gen_highpart (SImode, op1); |
| 16059 |
*lo_op2 = simplify_gen_subreg (SImode, op2, DImode, |
| 16060 |
subreg_lowpart_offset (SImode, DImode)); |
| 16061 |
*hi_op2 = simplify_gen_subreg (SImode, op2, DImode, |
| 16062 |
subreg_highpart_offset (SImode, DImode)); |
| 16063 |
} |
| 16064 |
|
| 16065 |
/* Select a dominance comparison mode if possible for a test of the general |
| 16066 |
form (OP (COND_OR (X) (Y)) (const_int 0)). We support three forms. |
| 16067 |
COND_OR == DOM_CC_X_AND_Y => (X && Y) |
| 16068 |
COND_OR == DOM_CC_NX_OR_Y => ((! X) || Y) |
| 16069 |
COND_OR == DOM_CC_X_OR_Y => (X || Y) |
| 16070 |
In all cases OP will be either EQ or NE, but we don't need to know which |
| 16071 |
here. If we are unable to support a dominance comparison we return |
| 16072 |
CC mode. This will then fail to match for the RTL expressions that |
| 16073 |
generate this call. */ |
| 16074 |
machine_mode |
| 16075 |
arm_select_dominance_cc_mode (rtx x, rtx y, HOST_WIDE_INT cond_or) |
| 16076 |
{ |
| 16077 |
enum rtx_code cond1, cond2; |
| 16078 |
int swapped = 0; |
| 16079 |
|
| 16080 |
/* Currently we will probably get the wrong result if the individual |
| 16081 |
comparisons are not simple. This also ensures that it is safe to |
| 16082 |
reverse a comparison if necessary. */ |
| 16083 |
if ((arm_select_cc_mode (cond1 = GET_CODE (x), XEXP (x, 0), XEXP (x, 1)) |
| 16084 |
!= CCmode) |
| 16085 |
|| (arm_select_cc_mode (cond2 = GET_CODE (y), XEXP (y, 0), XEXP (y, 1)) |
| 16086 |
!= CCmode)) |
| 16087 |
return CCmode; |
| 16088 |
|
| 16089 |
/* The if_then_else variant of this tests the second condition if the |
| 16090 |
first passes, but is true if the first fails. Reverse the first |
| 16091 |
condition to get a true "inclusive-or" expression. */ |
| 16092 |
if (cond_or == DOM_CC_NX_OR_Y) |
| 16093 |
cond1 = reverse_condition (cond1); |
| 16094 |
|
| 16095 |
/* If the comparisons are not equal, and one doesn't dominate the other, |
| 16096 |
then we can't do this. */ |
| 16097 |
if (cond1 != cond2 |
| 16098 |
&& !comparison_dominates_p (cond1, cond2) |
| 16099 |
&& (swapped = 1, !comparison_dominates_p (cond2, cond1))) |
| 16100 |
return CCmode; |
| 16101 |
|
| 16102 |
if (swapped) |
| 16103 |
std::swap (cond1, cond2); |
| 16104 |
|
| 16105 |
switch (cond1) |
| 16106 |
{ |
| 16107 |
case EQ: |
| 16108 |
if (cond_or == DOM_CC_X_AND_Y) |
| 16109 |
return CC_DEQmode; |
| 16110 |
|
| 16111 |
switch (cond2) |
| 16112 |
{ |
| 16113 |
case EQ: return CC_DEQmode; |
| 16114 |
case LE: return CC_DLEmode; |
| 16115 |
case LEU: return CC_DLEUmode; |
| 16116 |
case GE: return CC_DGEmode; |
| 16117 |
case GEU: return CC_DGEUmode; |
| 16118 |
default: gcc_unreachable (); |
| 16119 |
} |
| 16120 |
|
| 16121 |
case LT: |
| 16122 |
if (cond_or == DOM_CC_X_AND_Y) |
| 16123 |
return CC_DLTmode; |
| 16124 |
|
| 16125 |
switch (cond2) |
| 16126 |
{ |
| 16127 |
case LT: |
| 16128 |
return CC_DLTmode; |
| 16129 |
case LE: |
| 16130 |
return CC_DLEmode; |
| 16131 |
case NE: |
| 16132 |
return CC_DNEmode; |
| 16133 |
default: |
| 16134 |
gcc_unreachable (); |
| 16135 |
} |
| 16136 |
|
| 16137 |
case GT: |
| 16138 |
if (cond_or == DOM_CC_X_AND_Y) |
| 16139 |
return CC_DGTmode; |
| 16140 |
|
| 16141 |
switch (cond2) |
| 16142 |
{ |
| 16143 |
case GT: |
| 16144 |
return CC_DGTmode; |
| 16145 |
case GE: |
| 16146 |
return CC_DGEmode; |
| 16147 |
case NE: |
| 16148 |
return CC_DNEmode; |
| 16149 |
default: |
| 16150 |
gcc_unreachable (); |
| 16151 |
} |
| 16152 |
|
| 16153 |
case LTU: |
| 16154 |
if (cond_or == DOM_CC_X_AND_Y) |
| 16155 |
return CC_DLTUmode; |
| 16156 |
|
| 16157 |
switch (cond2) |
| 16158 |
{ |
| 16159 |
case LTU: |
| 16160 |
return CC_DLTUmode; |
| 16161 |
case LEU: |
| 16162 |
return CC_DLEUmode; |
| 16163 |
case NE: |
| 16164 |
return CC_DNEmode; |
| 16165 |
default: |
| 16166 |
gcc_unreachable (); |
| 16167 |
} |
| 16168 |
|
| 16169 |
case GTU: |
| 16170 |
if (cond_or == DOM_CC_X_AND_Y) |
| 16171 |
return CC_DGTUmode; |
| 16172 |
|
| 16173 |
switch (cond2) |
| 16174 |
{ |
| 16175 |
case GTU: |
| 16176 |
return CC_DGTUmode; |
| 16177 |
case GEU: |
| 16178 |
return CC_DGEUmode; |
| 16179 |
case NE: |
| 16180 |
return CC_DNEmode; |
| 16181 |
default: |
| 16182 |
gcc_unreachable (); |
| 16183 |
} |
| 16184 |
|
| 16185 |
/* The remaining cases only occur when both comparisons are the |
| 16186 |
same. */ |
| 16187 |
case NE: |
| 16188 |
gcc_assert (cond1 == cond2); |
| 16189 |
return CC_DNEmode; |
| 16190 |
|
| 16191 |
case LE: |
| 16192 |
gcc_assert (cond1 == cond2); |
| 16193 |
return CC_DLEmode; |
| 16194 |
|
| 16195 |
case GE: |
| 16196 |
gcc_assert (cond1 == cond2); |
| 16197 |
return CC_DGEmode; |
| 16198 |
|
| 16199 |
case LEU: |
| 16200 |
gcc_assert (cond1 == cond2); |
| 16201 |
return CC_DLEUmode; |
| 16202 |
|
| 16203 |
case GEU: |
| 16204 |
gcc_assert (cond1 == cond2); |
| 16205 |
return CC_DGEUmode; |
| 16206 |
|
| 16207 |
default: |
| 16208 |
gcc_unreachable (); |
| 16209 |
} |
| 16210 |
} |
| 16211 |
|
| 16212 |
machine_mode |
| 16213 |
arm_select_cc_mode (enum rtx_code op, rtx x, rtx y) |
| 16214 |
{ |
| 16215 |
/* All floating point compares return CCFP if it is an equality |
| 16216 |
comparison, and CCFPE otherwise. */ |
| 16217 |
if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) |
| 16218 |
{ |
| 16219 |
switch (op) |
| 16220 |
{ |
| 16221 |
case EQ: |
| 16222 |
case NE: |
| 16223 |
case UNORDERED: |
| 16224 |
case ORDERED: |
| 16225 |
case UNLT: |
| 16226 |
case UNLE: |
| 16227 |
case UNGT: |
| 16228 |
case UNGE: |
| 16229 |
case UNEQ: |
| 16230 |
case LTGT: |
| 16231 |
return CCFPmode; |
| 16232 |
|
| 16233 |
case LT: |
| 16234 |
case LE: |
| 16235 |
case GT: |
| 16236 |
case GE: |
| 16237 |
return (flag_finite_math_only |
| 16238 |
? CCFPmode |
| 16239 |
: CCFPEmode); |
| 16240 |
|
| 16241 |
default: |
| 16242 |
gcc_unreachable (); |
| 16243 |
} |
| 16244 |
} |
| 16245 |
|
| 16246 |
/* A compare with a shifted operand. Because of canonicalization, the |
| 16247 |
comparison will have to be swapped when we emit the assembler. */ |
| 16248 |
if (GET_MODE (y) == SImode |
| 16249 |
&& (REG_P (y) || (SUBREG_P (y))) |
| 16250 |
&& (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT |
| 16251 |
|| GET_CODE (x) == LSHIFTRT || GET_CODE (x) == ROTATE |
| 16252 |
|| GET_CODE (x) == ROTATERT)) |
| 16253 |
return CC_SWPmode; |
| 16254 |
|
| 16255 |
/* A widened compare of the sum of a value plus a carry against a |
| 16256 |
constant. This is a representation of RSC. We want to swap the |
| 16257 |
result of the comparison at output. Not valid if the Z bit is |
| 16258 |
needed. */ |
| 16259 |
if (GET_MODE (x) == DImode |
| 16260 |
&& GET_CODE (x) == PLUS |
| 16261 |
&& arm_borrow_operation (XEXP (x, 1), DImode) |
| 16262 |
&& CONST_INT_P (y) |
| 16263 |
&& ((GET_CODE (XEXP (x, 0)) == SIGN_EXTEND |
| 16264 |
&& (op == LE || op == GT)) |
| 16265 |
|| (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND |
| 16266 |
&& (op == LEU || op == GTU)))) |
| 16267 |
return CC_SWPmode; |
| 16268 |
|
| 16269 |
/* If X is a constant we want to use CC_RSBmode. This is |
| 16270 |
non-canonical, but arm_gen_compare_reg uses this to generate the |
| 16271 |
correct canonical form. */ |
| 16272 |
if (GET_MODE (y) == SImode |
| 16273 |
&& (REG_P (y) || SUBREG_P (y)) |
| 16274 |
&& CONST_INT_P (x)) |
| 16275 |
return CC_RSBmode; |
| 16276 |
|
| 16277 |
/* This operation is performed swapped, but since we only rely on the Z |
| 16278 |
flag we don't need an additional mode. */ |
| 16279 |
if (GET_MODE (y) == SImode |
| 16280 |
&& (REG_P (y) || (SUBREG_P (y))) |
| 16281 |
&& GET_CODE (x) == NEG |
| 16282 |
&& (op == EQ || op == NE)) |
| 16283 |
return CC_Zmode; |
| 16284 |
|
| 16285 |
/* This is a special case that is used by combine to allow a |
| 16286 |
comparison of a shifted byte load to be split into a zero-extend |
| 16287 |
followed by a comparison of the shifted integer (only valid for |
| 16288 |
equalities and unsigned inequalities). */ |
| 16289 |
if (GET_MODE (x) == SImode |
| 16290 |
&& GET_CODE (x) == ASHIFT |
| 16291 |
&& CONST_INT_P (XEXP (x, 1)) && INTVAL (XEXP (x, 1)) == 24 |
| 16292 |
&& GET_CODE (XEXP (x, 0)) == SUBREG |
| 16293 |
&& MEM_P (SUBREG_REG (XEXP (x, 0))) |
| 16294 |
&& GET_MODE (SUBREG_REG (XEXP (x, 0))) == QImode |
| 16295 |
&& (op == EQ || op == NE |
| 16296 |
|| op == GEU || op == GTU || op == LTU || op == LEU) |
| 16297 |
&& CONST_INT_P (y)) |
| 16298 |
return CC_Zmode; |
| 16299 |
|
| 16300 |
/* A construct for a conditional compare, if the false arm contains |
| 16301 |
0, then both conditions must be true, otherwise either condition |
| 16302 |
must be true. Not all conditions are possible, so CCmode is |
| 16303 |
returned if it can't be done. */ |
| 16304 |
if (GET_CODE (x) == IF_THEN_ELSE |
| 16305 |
&& (XEXP (x, 2) == const0_rtx |
| 16306 |
|| XEXP (x, 2) == const1_rtx) |
| 16307 |
&& COMPARISON_P (XEXP (x, 0)) |
| 16308 |
&& COMPARISON_P (XEXP (x, 1))) |
| 16309 |
return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), |
| 16310 |
INTVAL (XEXP (x, 2))); |
| 16311 |
|
| 16312 |
/* Alternate canonicalizations of the above. These are somewhat cleaner. */ |
| 16313 |
if (GET_CODE (x) == AND |
| 16314 |
&& (op == EQ || op == NE) |
| 16315 |
&& COMPARISON_P (XEXP (x, 0)) |
| 16316 |
&& COMPARISON_P (XEXP (x, 1))) |
| 16317 |
return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), |
| 16318 |
DOM_CC_X_AND_Y); |
| 16319 |
|
| 16320 |
if (GET_CODE (x) == IOR |
| 16321 |
&& (op == EQ || op == NE) |
| 16322 |
&& COMPARISON_P (XEXP (x, 0)) |
| 16323 |
&& COMPARISON_P (XEXP (x, 1))) |
| 16324 |
return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), |
| 16325 |
DOM_CC_X_OR_Y); |
| 16326 |
|
| 16327 |
/* An operation (on Thumb) where we want to test for a single bit. |
| 16328 |
This is done by shifting that bit up into the top bit of a |
| 16329 |
scratch register; we can then branch on the sign bit. */ |
| 16330 |
if (TARGET_THUMB1 |
| 16331 |
&& GET_MODE (x) == SImode |
| 16332 |
&& (op == EQ || op == NE) |
| 16333 |
&& GET_CODE (x) == ZERO_EXTRACT |
| 16334 |
&& XEXP (x, 1) == const1_rtx) |
| 16335 |
return CC_Nmode; |
| 16336 |
|
| 16337 |
/* An operation that sets the condition codes as a side-effect, the |
| 16338 |
V flag is not set correctly, so we can only use comparisons where |
| 16339 |
this doesn't matter. (For LT and GE we can use "mi" and "pl" |
| 16340 |
instead.) */ |
| 16341 |
/* ??? Does the ZERO_EXTRACT case really apply to thumb2? */ |
| 16342 |
if (GET_MODE (x) == SImode |
| 16343 |
&& y == const0_rtx |
| 16344 |
&& (op == EQ || op == NE || op == LT || op == GE) |
| 16345 |
&& (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS |
| 16346 |
|| GET_CODE (x) == AND || GET_CODE (x) == IOR |
| 16347 |
|| GET_CODE (x) == XOR || GET_CODE (x) == MULT |
| 16348 |
|| GET_CODE (x) == NOT || GET_CODE (x) == NEG |
| 16349 |
|| GET_CODE (x) == LSHIFTRT |
| 16350 |
|| GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT |
| 16351 |
|| GET_CODE (x) == ROTATERT |
| 16352 |
|| (TARGET_32BIT && GET_CODE (x) == ZERO_EXTRACT))) |
| 16353 |
return CC_NZmode; |
| 16354 |
|
| 16355 |
/* A comparison of ~reg with a const is really a special |
| 16356 |
canoncialization of compare (~const, reg), which is a reverse |
| 16357 |
subtract operation. We may not get here if CONST is 0, but that |
| 16358 |
doesn't matter because ~0 isn't a valid immediate for RSB. */ |
| 16359 |
if (GET_MODE (x) == SImode |
| 16360 |
&& GET_CODE (x) == NOT |
| 16361 |
&& CONST_INT_P (y)) |
| 16362 |
return CC_RSBmode; |
| 16363 |
|
| 16364 |
if (GET_MODE (x) == QImode && (op == EQ || op == NE)) |
| 16365 |
return CC_Zmode; |
| 16366 |
|
| 16367 |
if (GET_MODE (x) == SImode && (op == LTU || op == GEU) |
| 16368 |
&& GET_CODE (x) == PLUS |
| 16369 |
&& (rtx_equal_p (XEXP (x, 0), y) || rtx_equal_p (XEXP (x, 1), y))) |
| 16370 |
return CC_Cmode; |
| 16371 |
|
| 16372 |
if (GET_MODE (x) == DImode |
| 16373 |
&& GET_CODE (x) == PLUS |
| 16374 |
&& GET_CODE (XEXP (x, 1)) == ZERO_EXTEND |
| 16375 |
&& CONST_INT_P (y) |
| 16376 |
&& UINTVAL (y) == 0x800000000 |
| 16377 |
&& (op == GEU || op == LTU)) |
| 16378 |
return CC_ADCmode; |
| 16379 |
|
| 16380 |
if (GET_MODE (x) == DImode |
| 16381 |
&& (op == GE || op == LT) |
| 16382 |
&& GET_CODE (x) == SIGN_EXTEND |
| 16383 |
&& ((GET_CODE (y) == PLUS |
| 16384 |
&& arm_borrow_operation (XEXP (y, 0), DImode)) |
| 16385 |
|| arm_borrow_operation (y, DImode))) |
| 16386 |
return CC_NVmode; |
| 16387 |
|
| 16388 |
if (GET_MODE (x) == DImode |
| 16389 |
&& (op == GEU || op == LTU) |
| 16390 |
&& GET_CODE (x) == ZERO_EXTEND |
| 16391 |
&& ((GET_CODE (y) == PLUS |
| 16392 |
&& arm_borrow_operation (XEXP (y, 0), DImode)) |
| 16393 |
|| arm_borrow_operation (y, DImode))) |
| 16394 |
return CC_Bmode; |
| 16395 |
|
| 16396 |
if (GET_MODE (x) == DImode |
| 16397 |
&& (op == EQ || op == NE) |
| 16398 |
&& (GET_CODE (x) == PLUS |
| 16399 |
|| GET_CODE (x) == MINUS) |
| 16400 |
&& (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND |
| 16401 |
|| GET_CODE (XEXP (x, 1)) == SIGN_EXTEND) |
| 16402 |
&& GET_CODE (y) == SIGN_EXTEND |
| 16403 |
&& GET_CODE (XEXP (y, 0)) == GET_CODE (x)) |
| 16404 |
return CC_Vmode; |
| 16405 |
|
| 16406 |
if (GET_MODE_CLASS (GET_MODE (x)) == MODE_CC) |
| 16407 |
return GET_MODE (x); |
| 16408 |
|
| 16409 |
return CCmode; |
| 16410 |
} |
| 16411 |
|
| 16412 |
/* X and Y are two (DImode) things to compare for the condition CODE. Emit |
| 16413 |
the sequence of instructions needed to generate a suitable condition |
| 16414 |
code register. Return the CC register result. */ |
| 16415 |
static rtx |
| 16416 |
arm_gen_dicompare_reg (rtx_code code, rtx x, rtx y, rtx scratch) |
| 16417 |
{ |
| 16418 |
machine_mode mode; |
| 16419 |
rtx cc_reg; |
| 16420 |
|
| 16421 |
/* We don't currently handle DImode in thumb1, but rely on libgcc. */ |
| 16422 |
gcc_assert (TARGET_32BIT); |
| 16423 |
gcc_assert (!CONST_INT_P (x)); |
| 16424 |
|
| 16425 |
rtx x_lo = simplify_gen_subreg (SImode, x, DImode, |
| 16426 |
subreg_lowpart_offset (SImode, DImode)); |
| 16427 |
rtx x_hi = simplify_gen_subreg (SImode, x, DImode, |
| 16428 |
subreg_highpart_offset (SImode, DImode)); |
| 16429 |
rtx y_lo = simplify_gen_subreg (SImode, y, DImode, |
| 16430 |
subreg_lowpart_offset (SImode, DImode)); |
| 16431 |
rtx y_hi = simplify_gen_subreg (SImode, y, DImode, |
| 16432 |
subreg_highpart_offset (SImode, DImode)); |
| 16433 |
switch (code) |
| 16434 |
{ |
| 16435 |
case EQ: |
| 16436 |
case NE: |
| 16437 |
{ |
| 16438 |
if (y_lo == const0_rtx || y_hi == const0_rtx) |
| 16439 |
{ |
| 16440 |
if (y_lo != const0_rtx) |
| 16441 |
{ |
| 16442 |
rtx scratch2 = scratch ? scratch : gen_reg_rtx (SImode); |
| 16443 |
|
| 16444 |
gcc_assert (y_hi == const0_rtx); |
| 16445 |
y_lo = gen_int_mode (-INTVAL (y_lo), SImode); |
| 16446 |
if (!arm_add_operand (y_lo, SImode)) |
| 16447 |
y_lo = force_reg (SImode, y_lo); |
| 16448 |
emit_insn (gen_addsi3 (scratch2, x_lo, y_lo)); |
| 16449 |
x_lo = scratch2; |
| 16450 |
} |
| 16451 |
else if (y_hi != const0_rtx) |
| 16452 |
{ |
| 16453 |
rtx scratch2 = scratch ? scratch : gen_reg_rtx (SImode); |
| 16454 |
|
| 16455 |
y_hi = gen_int_mode (-INTVAL (y_hi), SImode); |
| 16456 |
if (!arm_add_operand (y_hi, SImode)) |
| 16457 |
y_hi = force_reg (SImode, y_hi); |
| 16458 |
emit_insn (gen_addsi3 (scratch2, x_hi, y_hi)); |
| 16459 |
x_hi = scratch2; |
| 16460 |
} |
| 16461 |
|
| 16462 |
if (!scratch) |
| 16463 |
{ |
| 16464 |
gcc_assert (!reload_completed); |
| 16465 |
scratch = gen_rtx_SCRATCH (SImode); |
| 16466 |
} |
| 16467 |
|
| 16468 |
rtx clobber = gen_rtx_CLOBBER (VOIDmode, scratch); |
| 16469 |
cc_reg = gen_rtx_REG (CC_NZmode, CC_REGNUM); |
| 16470 |
|
| 16471 |
rtx set |
| 16472 |
= gen_rtx_SET (cc_reg, |
| 16473 |
gen_rtx_COMPARE (CC_NZmode, |
| 16474 |
gen_rtx_IOR (SImode, x_lo, x_hi), |
| 16475 |
const0_rtx)); |
| 16476 |
emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, |
| 16477 |
clobber))); |
| 16478 |
return cc_reg; |
| 16479 |
} |
| 16480 |
|
| 16481 |
if (!arm_add_operand (y_lo, SImode)) |
| 16482 |
y_lo = force_reg (SImode, y_lo); |
| 16483 |
|
| 16484 |
if (!arm_add_operand (y_hi, SImode)) |
| 16485 |
y_hi = force_reg (SImode, y_hi); |
| 16486 |
|
| 16487 |
rtx cmp1 = gen_rtx_NE (SImode, x_lo, y_lo); |
| 16488 |
rtx cmp2 = gen_rtx_NE (SImode, x_hi, y_hi); |
| 16489 |
rtx conjunction = gen_rtx_IOR (SImode, cmp1, cmp2); |
| 16490 |
mode = SELECT_CC_MODE (code, conjunction, const0_rtx); |
| 16491 |
cc_reg = gen_rtx_REG (mode, CC_REGNUM); |
| 16492 |
|
| 16493 |
emit_insn (gen_rtx_SET (cc_reg, |
| 16494 |
gen_rtx_COMPARE (mode, conjunction, |
| 16495 |
const0_rtx))); |
| 16496 |
return cc_reg; |
| 16497 |
} |
| 16498 |
|
| 16499 |
case LT: |
| 16500 |
case GE: |
| 16501 |
{ |
| 16502 |
if (y_lo == const0_rtx) |
| 16503 |
{ |
| 16504 |
/* If the low word of y is 0, then this is simply a normal |
| 16505 |
compare of the upper words. */ |
| 16506 |
if (!arm_add_operand (y_hi, SImode)) |
| 16507 |
y_hi = force_reg (SImode, y_hi); |
| 16508 |
|
| 16509 |
return arm_gen_compare_reg (code, x_hi, y_hi, NULL_RTX); |
| 16510 |
} |
| 16511 |
|
| 16512 |
if (!arm_add_operand (y_lo, SImode)) |
| 16513 |
y_lo = force_reg (SImode, y_lo); |
| 16514 |
|
| 16515 |
rtx cmp1 |
| 16516 |
= gen_rtx_LTU (DImode, |
| 16517 |
arm_gen_compare_reg (LTU, x_lo, y_lo, NULL_RTX), |
| 16518 |
const0_rtx); |
| 16519 |
|
| 16520 |
if (!scratch) |
| 16521 |
scratch = gen_rtx_SCRATCH (SImode); |
| 16522 |
|
| 16523 |
if (!arm_not_operand (y_hi, SImode)) |
| 16524 |
y_hi = force_reg (SImode, y_hi); |
| 16525 |
|
| 16526 |
rtx_insn *insn; |
| 16527 |
if (y_hi == const0_rtx) |
| 16528 |
insn = emit_insn (gen_cmpsi3_0_carryin_CC_NVout (scratch, x_hi, |
| 16529 |
cmp1)); |
| 16530 |
else if (CONST_INT_P (y_hi)) |
| 16531 |
insn = emit_insn (gen_cmpsi3_imm_carryin_CC_NVout (scratch, x_hi, |
| 16532 |
y_hi, cmp1)); |
| 16533 |
else |
| 16534 |
insn = emit_insn (gen_cmpsi3_carryin_CC_NVout (scratch, x_hi, y_hi, |
| 16535 |
cmp1)); |
| 16536 |
return SET_DEST (single_set (insn)); |
| 16537 |
} |
| 16538 |
|
| 16539 |
case LE: |
| 16540 |
case GT: |
| 16541 |
{ |
| 16542 |
/* During expansion, we only expect to get here if y is a |
| 16543 |
constant that we want to handle, otherwise we should have |
| 16544 |
swapped the operands already. */ |
| 16545 |
gcc_assert (arm_const_double_prefer_rsbs_rsc (y)); |
| 16546 |
|
| 16547 |
if (!const_ok_for_arm (INTVAL (y_lo))) |
| 16548 |
y_lo = force_reg (SImode, y_lo); |
| 16549 |
|
| 16550 |
/* Perform a reverse subtract and compare. */ |
| 16551 |
rtx cmp1 |
| 16552 |
= gen_rtx_LTU (DImode, |
| 16553 |
arm_gen_compare_reg (LTU, y_lo, x_lo, scratch), |
| 16554 |
const0_rtx); |
| 16555 |
rtx_insn *insn = emit_insn (gen_rscsi3_CC_NVout_scratch (scratch, y_hi, |
| 16556 |
x_hi, cmp1)); |
| 16557 |
return SET_DEST (single_set (insn)); |
| 16558 |
} |
| 16559 |
|
| 16560 |
case LTU: |
| 16561 |
case GEU: |
| 16562 |
{ |
| 16563 |
if (y_lo == const0_rtx) |
| 16564 |
{ |
| 16565 |
/* If the low word of y is 0, then this is simply a normal |
| 16566 |
compare of the upper words. */ |
| 16567 |
if (!arm_add_operand (y_hi, SImode)) |
| 16568 |
y_hi = force_reg (SImode, y_hi); |
| 16569 |
|
| 16570 |
return arm_gen_compare_reg (code, x_hi, y_hi, NULL_RTX); |
| 16571 |
} |
| 16572 |
|
| 16573 |
if (!arm_add_operand (y_lo, SImode)) |
| 16574 |
y_lo = force_reg (SImode, y_lo); |
| 16575 |
|
| 16576 |
rtx cmp1 |
| 16577 |
= gen_rtx_LTU (DImode, |
| 16578 |
arm_gen_compare_reg (LTU, x_lo, y_lo, NULL_RTX), |
| 16579 |
const0_rtx); |
| 16580 |
|
| 16581 |
if (!scratch) |
| 16582 |
scratch = gen_rtx_SCRATCH (SImode); |
| 16583 |
if (!arm_not_operand (y_hi, SImode)) |
| 16584 |
y_hi = force_reg (SImode, y_hi); |
| 16585 |
|
| 16586 |
rtx_insn *insn; |
| 16587 |
if (y_hi == const0_rtx) |
| 16588 |
insn = emit_insn (gen_cmpsi3_0_carryin_CC_Bout (scratch, x_hi, |
| 16589 |
cmp1)); |
| 16590 |
else if (CONST_INT_P (y_hi)) |
| 16591 |
{ |
| 16592 |
/* Constant is viewed as unsigned when zero-extended. */ |
| 16593 |
y_hi = GEN_INT (UINTVAL (y_hi) & 0xffffffffULL); |
| 16594 |
insn = emit_insn (gen_cmpsi3_imm_carryin_CC_Bout (scratch, x_hi, |
| 16595 |
y_hi, cmp1)); |
| 16596 |
} |
| 16597 |
else |
| 16598 |
insn = emit_insn (gen_cmpsi3_carryin_CC_Bout (scratch, x_hi, y_hi, |
| 16599 |
cmp1)); |
| 16600 |
return SET_DEST (single_set (insn)); |
| 16601 |
} |
| 16602 |
|
| 16603 |
case LEU: |
| 16604 |
case GTU: |
| 16605 |
{ |
| 16606 |
/* During expansion, we only expect to get here if y is a |
| 16607 |
constant that we want to handle, otherwise we should have |
| 16608 |
swapped the operands already. */ |
| 16609 |
gcc_assert (arm_const_double_prefer_rsbs_rsc (y)); |
| 16610 |
|
| 16611 |
if (!const_ok_for_arm (INTVAL (y_lo))) |
| 16612 |
y_lo = force_reg (SImode, y_lo); |
| 16613 |
|
| 16614 |
/* Perform a reverse subtract and compare. */ |
| 16615 |
rtx cmp1 |
| 16616 |
= gen_rtx_LTU (DImode, |
| 16617 |
arm_gen_compare_reg (LTU, y_lo, x_lo, scratch), |
| 16618 |
const0_rtx); |
| 16619 |
y_hi = GEN_INT (0xffffffff & UINTVAL (y_hi)); |
| 16620 |
rtx_insn *insn = emit_insn (gen_rscsi3_CC_Bout_scratch (scratch, y_hi, |
| 16621 |
x_hi, cmp1)); |
| 16622 |
return SET_DEST (single_set (insn)); |
| 16623 |
} |
| 16624 |
|
| 16625 |
default: |
| 16626 |
gcc_unreachable (); |
| 16627 |
} |
| 16628 |
} |
| 16629 |
|
| 16630 |
/* X and Y are two things to compare using CODE. Emit the compare insn and |
| 16631 |
return the rtx for register 0 in the proper mode. */ |
| 16632 |
rtx |
| 16633 |
arm_gen_compare_reg (rtx_code code, rtx x, rtx y, rtx scratch) |
| 16634 |
{ |
| 16635 |
if (GET_MODE (x) == DImode || GET_MODE (y) == DImode) |
| 16636 |
return arm_gen_dicompare_reg (code, x, y, scratch); |
| 16637 |
|
| 16638 |
machine_mode mode = SELECT_CC_MODE (code, x, y); |
| 16639 |
rtx cc_reg = gen_rtx_REG (mode, CC_REGNUM); |
| 16640 |
if (mode == CC_RSBmode) |
| 16641 |
{ |
| 16642 |
if (!scratch) |
| 16643 |
scratch = gen_rtx_SCRATCH (SImode); |
| 16644 |
emit_insn (gen_rsb_imm_compare_scratch (scratch, |
| 16645 |
GEN_INT (~UINTVAL (x)), y)); |
| 16646 |
} |
| 16647 |
else |
| 16648 |
emit_set_insn (cc_reg, gen_rtx_COMPARE (mode, x, y)); |
| 16649 |
|
| 16650 |
return cc_reg; |
| 16651 |
} |
| 16652 |
|
| 16653 |
/* Generate a sequence of insns that will generate the correct return |
| 16654 |
address mask depending on the physical architecture that the program |
| 16655 |
is running on. */ |
| 16656 |
rtx |
| 16657 |
arm_gen_return_addr_mask (void) |
| 16658 |
{ |
| 16659 |
rtx reg = gen_reg_rtx (Pmode); |
| 16660 |
|
| 16661 |
emit_insn (gen_return_addr_mask (reg)); |
| 16662 |
return reg; |
| 16663 |
} |
| 16664 |
|
| 16665 |
void |
| 16666 |
arm_reload_in_hi (rtx *operands) |
| 16667 |
{ |
| 16668 |
rtx ref = operands[1]; |
| 16669 |
rtx base, scratch; |
| 16670 |
HOST_WIDE_INT offset = 0; |
| 16671 |
|
| 16672 |
if (SUBREG_P (ref)) |
| 16673 |
{ |
| 16674 |
offset = SUBREG_BYTE (ref); |
| 16675 |
ref = SUBREG_REG (ref); |
| 16676 |
} |
| 16677 |
|
| 16678 |
if (REG_P (ref)) |
| 16679 |
{ |
| 16680 |
/* We have a pseudo which has been spilt onto the stack; there |
| 16681 |
are two cases here: the first where there is a simple |
| 16682 |
stack-slot replacement and a second where the stack-slot is |
| 16683 |
out of range, or is used as a subreg. */ |
| 16684 |
if (reg_equiv_mem (REGNO (ref))) |
| 16685 |
{ |
| 16686 |
ref = reg_equiv_mem (REGNO (ref)); |
| 16687 |
base = find_replacement (&XEXP (ref, 0)); |
| 16688 |
} |
| 16689 |
else |
| 16690 |
/* The slot is out of range, or was dressed up in a SUBREG. */ |
| 16691 |
base = reg_equiv_address (REGNO (ref)); |
| 16692 |
|
| 16693 |
/* PR 62554: If there is no equivalent memory location then just move |
| 16694 |
the value as an SImode register move. This happens when the target |
| 16695 |
architecture variant does not have an HImode register move. */ |
| 16696 |
if (base == NULL) |
| 16697 |
{ |
| 16698 |
gcc_assert (REG_P (operands[0])); |
| 16699 |
emit_insn (gen_movsi (gen_rtx_SUBREG (SImode, operands[0], 0), |
| 16700 |
gen_rtx_SUBREG (SImode, ref, 0))); |
| 16701 |
return; |
| 16702 |
} |
| 16703 |
} |
| 16704 |
else |
| 16705 |
base = find_replacement (&XEXP (ref, 0)); |
| 16706 |
|
| 16707 |
/* Handle the case where the address is too complex to be offset by 1. */ |
| 16708 |
if (GET_CODE (base) == MINUS |
| 16709 |
|| (GET_CODE (base) == PLUS && !CONST_INT_P (XEXP (base, 1)))) |
| 16710 |
{ |
| 16711 |
rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); |
| 16712 |
|
| 16713 |
emit_set_insn (base_plus, base); |
| 16714 |
base = base_plus; |
| 16715 |
} |
| 16716 |
else if (GET_CODE (base) == PLUS) |
| 16717 |
{ |
| 16718 |
/* The addend must be CONST_INT, or we would have dealt with it above. */ |
| 16719 |
HOST_WIDE_INT hi, lo; |
| 16720 |
|
| 16721 |
offset += INTVAL (XEXP (base, 1)); |
| 16722 |
base = XEXP (base, 0); |
| 16723 |
|
| 16724 |
/* Rework the address into a legal sequence of insns. */ |
| 16725 |
/* Valid range for lo is -4095 -> 4095 */ |
| 16726 |
lo = (offset >= 0 |
| 16727 |
? (offset & 0xfff) |
| 16728 |
: -((-offset) & 0xfff)); |
| 16729 |
|
| 16730 |
/* Corner case, if lo is the max offset then we would be out of range |
| 16731 |
once we have added the additional 1 below, so bump the msb into the |
| 16732 |
pre-loading insn(s). */ |
| 16733 |
if (lo == 4095) |
| 16734 |
lo &= 0x7ff; |
| 16735 |
|
| 16736 |
hi = ((((offset - lo) & (HOST_WIDE_INT) 0xffffffff) |
| 16737 |
^ (HOST_WIDE_INT) 0x80000000) |
| 16738 |
- (HOST_WIDE_INT) 0x80000000); |
| 16739 |
|
| 16740 |
gcc_assert (hi + lo == offset); |
| 16741 |
|
| 16742 |
if (hi != 0) |
| 16743 |
{ |
| 16744 |
rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); |
| 16745 |
|
| 16746 |
/* Get the base address; addsi3 knows how to handle constants |
| 16747 |
that require more than one insn. */ |
| 16748 |
emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi))); |
| 16749 |
base = base_plus; |
| 16750 |
offset = lo; |
| 16751 |
} |
| 16752 |
} |
| 16753 |
|
| 16754 |
/* Operands[2] may overlap operands[0] (though it won't overlap |
| 16755 |
operands[1]), that's why we asked for a DImode reg -- so we can |
| 16756 |
use the bit that does not overlap. */ |
| 16757 |
if (REGNO (operands[2]) == REGNO (operands[0])) |
| 16758 |
scratch = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); |
| 16759 |
else |
| 16760 |
scratch = gen_rtx_REG (SImode, REGNO (operands[2])); |
| 16761 |
|
| 16762 |
emit_insn (gen_zero_extendqisi2 (scratch, |
| 16763 |
gen_rtx_MEM (QImode, |
| 16764 |
plus_constant (Pmode, base, |
| 16765 |
offset)))); |
| 16766 |
emit_insn (gen_zero_extendqisi2 (gen_rtx_SUBREG (SImode, operands[0], 0), |
| 16767 |
gen_rtx_MEM (QImode, |
| 16768 |
plus_constant (Pmode, base, |
| 16769 |
offset + 1)))); |
| 16770 |
if (!BYTES_BIG_ENDIAN) |
| 16771 |
emit_set_insn (gen_rtx_SUBREG (SImode, operands[0], 0), |
| 16772 |
gen_rtx_IOR (SImode, |
| 16773 |
gen_rtx_ASHIFT |
| 16774 |
(SImode, |
| 16775 |
gen_rtx_SUBREG (SImode, operands[0], 0), |
| 16776 |
GEN_INT (8)), |
| 16777 |
scratch)); |
| 16778 |
else |
| 16779 |
emit_set_insn (gen_rtx_SUBREG (SImode, operands[0], 0), |
| 16780 |
gen_rtx_IOR (SImode, |
| 16781 |
gen_rtx_ASHIFT (SImode, scratch, |
| 16782 |
GEN_INT (8)), |
| 16783 |
gen_rtx_SUBREG (SImode, operands[0], 0))); |
| 16784 |
} |
| 16785 |
|
| 16786 |
/* Handle storing a half-word to memory during reload by synthesizing as two |
| 16787 |
byte stores. Take care not to clobber the input values until after we |
| 16788 |
have moved them somewhere safe. This code assumes that if the DImode |
| 16789 |
scratch in operands[2] overlaps either the input value or output address |
| 16790 |
in some way, then that value must die in this insn (we absolutely need |
| 16791 |
two scratch registers for some corner cases). */ |
| 16792 |
void |
| 16793 |
arm_reload_out_hi (rtx *operands) |
| 16794 |
{ |
| 16795 |
rtx ref = operands[0]; |
| 16796 |
rtx outval = operands[1]; |
| 16797 |
rtx base, scratch; |
| 16798 |
HOST_WIDE_INT offset = 0; |
| 16799 |
|
| 16800 |
if (SUBREG_P (ref)) |
| 16801 |
{ |
| 16802 |
offset = SUBREG_BYTE (ref); |
| 16803 |
ref = SUBREG_REG (ref); |
| 16804 |
} |
| 16805 |
|
| 16806 |
if (REG_P (ref)) |
| 16807 |
{ |
| 16808 |
/* We have a pseudo which has been spilt onto the stack; there |
| 16809 |
are two cases here: the first where there is a simple |
| 16810 |
stack-slot replacement and a second where the stack-slot is |
| 16811 |
out of range, or is used as a subreg. */ |
| 16812 |
if (reg_equiv_mem (REGNO (ref))) |
| 16813 |
{ |
| 16814 |
ref = reg_equiv_mem (REGNO (ref)); |
| 16815 |
base = find_replacement (&XEXP (ref, 0)); |
| 16816 |
} |
| 16817 |
else |
| 16818 |
/* The slot is out of range, or was dressed up in a SUBREG. */ |
| 16819 |
base = reg_equiv_address (REGNO (ref)); |
| 16820 |
|
| 16821 |
/* PR 62254: If there is no equivalent memory location then just move |
| 16822 |
the value as an SImode register move. This happens when the target |
| 16823 |
architecture variant does not have an HImode register move. */ |
| 16824 |
if (base == NULL) |
| 16825 |
{ |
| 16826 |
gcc_assert (REG_P (outval) || SUBREG_P (outval)); |
| 16827 |
|
| 16828 |
if (REG_P (outval)) |
| 16829 |
{ |
| 16830 |
emit_insn (gen_movsi (gen_rtx_SUBREG (SImode, ref, 0), |
| 16831 |
gen_rtx_SUBREG (SImode, outval, 0))); |
| 16832 |
} |
| 16833 |
else /* SUBREG_P (outval) */ |
| 16834 |
{ |
| 16835 |
if (GET_MODE (SUBREG_REG (outval)) == SImode) |
| 16836 |
emit_insn (gen_movsi (gen_rtx_SUBREG (SImode, ref, 0), |
| 16837 |
SUBREG_REG (outval))); |
| 16838 |
else |
| 16839 |
/* FIXME: Handle other cases ? */ |
| 16840 |
gcc_unreachable (); |
| 16841 |
} |
| 16842 |
return; |
| 16843 |
} |
| 16844 |
} |
| 16845 |
else |
| 16846 |
base = find_replacement (&XEXP (ref, 0)); |
| 16847 |
|
| 16848 |
scratch = gen_rtx_REG (SImode, REGNO (operands[2])); |
| 16849 |
|
| 16850 |
/* Handle the case where the address is too complex to be offset by 1. */ |
| 16851 |
if (GET_CODE (base) == MINUS |
| 16852 |
|| (GET_CODE (base) == PLUS && !CONST_INT_P (XEXP (base, 1)))) |
| 16853 |
{ |
| 16854 |
rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); |
| 16855 |
|
| 16856 |
/* Be careful not to destroy OUTVAL. */ |
| 16857 |
if (reg_overlap_mentioned_p (base_plus, outval)) |
| 16858 |
{ |
| 16859 |
/* Updating base_plus might destroy outval, see if we can |
| 16860 |
swap the scratch and base_plus. */ |
| 16861 |
if (!reg_overlap_mentioned_p (scratch, outval)) |
| 16862 |
std::swap (scratch, base_plus); |
| 16863 |
else |
| 16864 |
{ |
| 16865 |
rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2])); |
| 16866 |
|
| 16867 |
/* Be conservative and copy OUTVAL into the scratch now, |
| 16868 |
this should only be necessary if outval is a subreg |
| 16869 |
of something larger than a word. */ |
| 16870 |
/* XXX Might this clobber base? I can't see how it can, |
| 16871 |
since scratch is known to overlap with OUTVAL, and |
| 16872 |
must be wider than a word. */ |
| 16873 |
emit_insn (gen_movhi (scratch_hi, outval)); |
| 16874 |
outval = scratch_hi; |
| 16875 |
} |
| 16876 |
} |
| 16877 |
|
| 16878 |
emit_set_insn (base_plus, base); |
| 16879 |
base = base_plus; |
| 16880 |
} |
| 16881 |
else if (GET_CODE (base) == PLUS) |
| 16882 |
{ |
| 16883 |
/* The addend must be CONST_INT, or we would have dealt with it above. */ |
| 16884 |
HOST_WIDE_INT hi, lo; |
| 16885 |
|
| 16886 |
offset += INTVAL (XEXP (base, 1)); |
| 16887 |
base = XEXP (base, 0); |
| 16888 |
|
| 16889 |
/* Rework the address into a legal sequence of insns. */ |
| 16890 |
/* Valid range for lo is -4095 -> 4095 */ |
| 16891 |
lo = (offset >= 0 |
| 16892 |
? (offset & 0xfff) |
| 16893 |
: -((-offset) & 0xfff)); |
| 16894 |
|
| 16895 |
/* Corner case, if lo is the max offset then we would be out of range |
| 16896 |
once we have added the additional 1 below, so bump the msb into the |
| 16897 |
pre-loading insn(s). */ |
| 16898 |
if (lo == 4095) |
| 16899 |
lo &= 0x7ff; |
| 16900 |
|
| 16901 |
hi = ((((offset - lo) & (HOST_WIDE_INT) 0xffffffff) |
| 16902 |
^ (HOST_WIDE_INT) 0x80000000) |
| 16903 |
- (HOST_WIDE_INT) 0x80000000); |
| 16904 |
|
| 16905 |
gcc_assert (hi + lo == offset); |
| 16906 |
|
| 16907 |
if (hi != 0) |
| 16908 |
{ |
| 16909 |
rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); |
| 16910 |
|
| 16911 |
/* Be careful not to destroy OUTVAL. */ |
| 16912 |
if (reg_overlap_mentioned_p (base_plus, outval)) |
| 16913 |
{ |
| 16914 |
/* Updating base_plus might destroy outval, see if we |
| 16915 |
can swap the scratch and base_plus. */ |
| 16916 |
if (!reg_overlap_mentioned_p (scratch, outval)) |
| 16917 |
std::swap (scratch, base_plus); |
| 16918 |
else |
| 16919 |
{ |
| 16920 |
rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2])); |
| 16921 |
|
| 16922 |
/* Be conservative and copy outval into scratch now, |
| 16923 |
this should only be necessary if outval is a |
| 16924 |
subreg of something larger than a word. */ |
| 16925 |
/* XXX Might this clobber base? I can't see how it |
| 16926 |
can, since scratch is known to overlap with |
| 16927 |
outval. */ |
| 16928 |
emit_insn (gen_movhi (scratch_hi, outval)); |
| 16929 |
outval = scratch_hi; |
| 16930 |
} |
| 16931 |
} |
| 16932 |
|
| 16933 |
/* Get the base address; addsi3 knows how to handle constants |
| 16934 |
that require more than one insn. */ |
| 16935 |
emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi))); |
| 16936 |
base = base_plus; |
| 16937 |
offset = lo; |
| 16938 |
} |
| 16939 |
} |
| 16940 |
|
| 16941 |
if (BYTES_BIG_ENDIAN) |
| 16942 |
{ |
| 16943 |
emit_insn (gen_movqi (gen_rtx_MEM (QImode, |
| 16944 |
plus_constant (Pmode, base, |
| 16945 |
offset + 1)), |
| 16946 |
gen_lowpart (QImode, outval))); |
| 16947 |
emit_insn (gen_lshrsi3 (scratch, |
| 16948 |
gen_rtx_SUBREG (SImode, outval, 0), |
| 16949 |
GEN_INT (8))); |
| 16950 |
emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (Pmode, base, |
| 16951 |
offset)), |
| 16952 |
gen_lowpart (QImode, scratch))); |
| 16953 |
} |
| 16954 |
else |
| 16955 |
{ |
| 16956 |
emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (Pmode, base, |
| 16957 |
offset)), |
| 16958 |
gen_lowpart (QImode, outval))); |
| 16959 |
emit_insn (gen_lshrsi3 (scratch, |
| 16960 |
gen_rtx_SUBREG (SImode, outval, 0), |
| 16961 |
GEN_INT (8))); |
| 16962 |
emit_insn (gen_movqi (gen_rtx_MEM (QImode, |
| 16963 |
plus_constant (Pmode, base, |
| 16964 |
offset + 1)), |
| 16965 |
gen_lowpart (QImode, scratch))); |
| 16966 |
} |
| 16967 |
} |
| 16968 |
|
| 16969 |
/* Return true if a type must be passed in memory. For AAPCS, small aggregates |
| 16970 |
(padded to the size of a word) should be passed in a register. */ |
| 16971 |
|
| 16972 |
static bool |
| 16973 |
arm_must_pass_in_stack (const function_arg_info &arg) |
| 16974 |
{ |
| 16975 |
if (TARGET_AAPCS_BASED) |
| 16976 |
return must_pass_in_stack_var_size (arg); |
| 16977 |
else |
| 16978 |
return must_pass_in_stack_var_size_or_pad (arg); |
| 16979 |
} |
| 16980 |
|
| 16981 |
|
| 16982 |
/* Implement TARGET_FUNCTION_ARG_PADDING; return PAD_UPWARD if the lowest |
| 16983 |
byte of a stack argument has useful data. For legacy APCS ABIs we use |
| 16984 |
the default. For AAPCS based ABIs small aggregate types are placed |
| 16985 |
in the lowest memory address. */ |
| 16986 |
|
| 16987 |
static pad_direction |
| 16988 |
arm_function_arg_padding (machine_mode mode, const_tree type) |
| 16989 |
{ |
| 16990 |
if (!TARGET_AAPCS_BASED) |
| 16991 |
return default_function_arg_padding (mode, type); |
| 16992 |
|
| 16993 |
if (type && BYTES_BIG_ENDIAN && INTEGRAL_TYPE_P (type)) |
| 16994 |
return PAD_DOWNWARD; |
| 16995 |
|
| 16996 |
return PAD_UPWARD; |
| 16997 |
} |
| 16998 |
|
| 16999 |
|
| 17000 |
/* Similarly, for use by BLOCK_REG_PADDING (MODE, TYPE, FIRST). |
| 17001 |
Return !BYTES_BIG_ENDIAN if the least significant byte of the |
| 17002 |
register has useful data, and return the opposite if the most |
| 17003 |
significant byte does. */ |
| 17004 |
|
| 17005 |
bool |
| 17006 |
arm_pad_reg_upward (machine_mode mode, |
| 17007 |
tree type, int first ATTRIBUTE_UNUSED) |
| 17008 |
{ |
| 17009 |
if (TARGET_AAPCS_BASED && BYTES_BIG_ENDIAN) |
| 17010 |
{ |
| 17011 |
/* For AAPCS, small aggregates, small fixed-point types, |
| 17012 |
and small complex types are always padded upwards. */ |
| 17013 |
if (type) |
| 17014 |
{ |
| 17015 |
if ((AGGREGATE_TYPE_P (type) |
| 17016 |
|| TREE_CODE (type) == COMPLEX_TYPE |
| 17017 |
|| FIXED_POINT_TYPE_P (type)) |
| 17018 |
&& int_size_in_bytes (type) <= 4) |
| 17019 |
return true; |
| 17020 |
} |
| 17021 |
else |
| 17022 |
{ |
| 17023 |
if ((COMPLEX_MODE_P (mode) || ALL_FIXED_POINT_MODE_P (mode)) |
| 17024 |
&& GET_MODE_SIZE (mode) <= 4) |
| 17025 |
return true; |
| 17026 |
} |
| 17027 |
} |
| 17028 |
|
| 17029 |
/* Otherwise, use default padding. */ |
| 17030 |
return !BYTES_BIG_ENDIAN; |
| 17031 |
} |
| 17032 |
|
| 17033 |
/* Returns true iff OFFSET is valid for use in an LDRD/STRD instruction, |
| 17034 |
assuming that the address in the base register is word aligned. */ |
| 17035 |
bool |
| 17036 |
offset_ok_for_ldrd_strd (HOST_WIDE_INT offset) |
| 17037 |
{ |
| 17038 |
HOST_WIDE_INT max_offset; |
| 17039 |
|
| 17040 |
/* Offset must be a multiple of 4 in Thumb mode. */ |
| 17041 |
if (TARGET_THUMB2 && ((offset & 3) != 0)) |
| 17042 |
return false; |
| 17043 |
|
| 17044 |
if (TARGET_THUMB2) |
| 17045 |
max_offset = 1020; |
| 17046 |
else if (TARGET_ARM) |
| 17047 |
max_offset = 255; |
| 17048 |
else |
| 17049 |
return false; |
| 17050 |
|
| 17051 |
return ((offset <= max_offset) && (offset >= -max_offset)); |
| 17052 |
} |
| 17053 |
|
| 17054 |
/* Checks whether the operands are valid for use in an LDRD/STRD instruction. |
| 17055 |
Assumes that RT, RT2, and RN are REG. This is guaranteed by the patterns. |
| 17056 |
Assumes that the address in the base register RN is word aligned. Pattern |
| 17057 |
guarantees that both memory accesses use the same base register, |
| 17058 |
the offsets are constants within the range, and the gap between the offsets is 4. |
| 17059 |
If preload complete then check that registers are legal. WBACK indicates whether |
| 17060 |
address is updated. LOAD indicates whether memory access is load or store. */ |
| 17061 |
bool |
| 17062 |
operands_ok_ldrd_strd (rtx rt, rtx rt2, rtx rn, HOST_WIDE_INT offset, |
| 17063 |
bool wback, bool load) |
| 17064 |
{ |
| 17065 |
unsigned int t, t2, n; |
| 17066 |
|
| 17067 |
if (!reload_completed) |
| 17068 |
return true; |
| 17069 |
|
| 17070 |
if (!offset_ok_for_ldrd_strd (offset)) |
| 17071 |
return false; |
| 17072 |
|
| 17073 |
t = REGNO (rt); |
| 17074 |
t2 = REGNO (rt2); |
| 17075 |
n = REGNO (rn); |
| 17076 |
|
| 17077 |
if ((TARGET_THUMB2) |
| 17078 |
&& ((wback && (n == t || n == t2)) |
| 17079 |
|| (t == SP_REGNUM) |
| 17080 |
|| (t == PC_REGNUM) |
| 17081 |
|| (t2 == SP_REGNUM) |
| 17082 |
|| (t2 == PC_REGNUM) |
| 17083 |
|| (!load && (n == PC_REGNUM)) |
| 17084 |
|| (load && (t == t2)) |
| 17085 |
/* Triggers Cortex-M3 LDRD errata. */ |
| 17086 |
|| (!wback && load && fix_cm3_ldrd && (n == t)))) |
| 17087 |
return false; |
| 17088 |
|
| 17089 |
if ((TARGET_ARM) |
| 17090 |
&& ((wback && (n == t || n == t2)) |
| 17091 |
|| (t2 == PC_REGNUM) |
| 17092 |
|| (t % 2 != 0) /* First destination register is not even. */ |
| 17093 |
|| (t2 != t + 1) |
| 17094 |
/* PC can be used as base register (for offset addressing only), |
| 17095 |
but it is depricated. */ |
| 17096 |
|| (n == PC_REGNUM))) |
| 17097 |
return false; |
| 17098 |
|
| 17099 |
return true; |
| 17100 |
} |
| 17101 |
|
| 17102 |
/* Return true if a 64-bit access with alignment ALIGN and with a |
| 17103 |
constant offset OFFSET from the base pointer is permitted on this |
| 17104 |
architecture. */ |
| 17105 |
static bool |
| 17106 |
align_ok_ldrd_strd (HOST_WIDE_INT align, HOST_WIDE_INT offset) |
| 17107 |
{ |
| 17108 |
return (unaligned_access |
| 17109 |
? (align >= BITS_PER_WORD && (offset & 3) == 0) |
| 17110 |
: (align >= 2 * BITS_PER_WORD && (offset & 7) == 0)); |
| 17111 |
} |
| 17112 |
|
| 17113 |
/* Helper for gen_operands_ldrd_strd. Returns true iff the memory |
| 17114 |
operand MEM's address contains an immediate offset from the base |
| 17115 |
register and has no side effects, in which case it sets BASE, |
| 17116 |
OFFSET and ALIGN accordingly. */ |
| 17117 |
static bool |
| 17118 |
mem_ok_for_ldrd_strd (rtx mem, rtx *base, rtx *offset, HOST_WIDE_INT *align) |
| 17119 |
{ |
| 17120 |
rtx addr; |
| 17121 |
|
| 17122 |
gcc_assert (base != NULL && offset != NULL); |
| 17123 |
|
| 17124 |
/* TODO: Handle more general memory operand patterns, such as |
| 17125 |
PRE_DEC and PRE_INC. */ |
| 17126 |
|
| 17127 |
if (side_effects_p (mem)) |
| 17128 |
return false; |
| 17129 |
|
| 17130 |
/* Can't deal with subregs. */ |
| 17131 |
if (SUBREG_P (mem)) |
| 17132 |
return false; |
| 17133 |
|
| 17134 |
gcc_assert (MEM_P (mem)); |
| 17135 |
|
| 17136 |
*offset = const0_rtx; |
| 17137 |
*align = MEM_ALIGN (mem); |
| 17138 |
|
| 17139 |
addr = XEXP (mem, 0); |
| 17140 |
|
| 17141 |
/* If addr isn't valid for DImode, then we can't handle it. */ |
| 17142 |
if (!arm_legitimate_address_p (DImode, addr, |
| 17143 |
reload_in_progress || reload_completed)) |
| 17144 |
return false; |
| 17145 |
|
| 17146 |
if (REG_P (addr)) |
| 17147 |
{ |
| 17148 |
*base = addr; |
| 17149 |
return true; |
| 17150 |
} |
| 17151 |
else if (GET_CODE (addr) == PLUS) |
| 17152 |
{ |
| 17153 |
*base = XEXP (addr, 0); |
| 17154 |
*offset = XEXP (addr, 1); |
| 17155 |
return (REG_P (*base) && CONST_INT_P (*offset)); |
| 17156 |
} |
| 17157 |
|
| 17158 |
return false; |
| 17159 |
} |
| 17160 |
|
| 17161 |
/* Called from a peephole2 to replace two word-size accesses with a |
| 17162 |
single LDRD/STRD instruction. Returns true iff we can generate a |
| 17163 |
new instruction sequence. That is, both accesses use the same base |
| 17164 |
register and the gap between constant offsets is 4. This function |
| 17165 |
may reorder its operands to match ldrd/strd RTL templates. |
| 17166 |
OPERANDS are the operands found by the peephole matcher; |
| 17167 |
OPERANDS[0,1] are register operands, and OPERANDS[2,3] are the |
| 17168 |
corresponding memory operands. LOAD indicaates whether the access |
| 17169 |
is load or store. CONST_STORE indicates a store of constant |
| 17170 |
integer values held in OPERANDS[4,5] and assumes that the pattern |
| 17171 |
is of length 4 insn, for the purpose of checking dead registers. |
| 17172 |
COMMUTE indicates that register operands may be reordered. */ |
| 17173 |
bool |
| 17174 |
gen_operands_ldrd_strd (rtx *operands, bool load, |
| 17175 |
bool const_store, bool commute) |
| 17176 |
{ |
| 17177 |
int nops = 2; |
| 17178 |
HOST_WIDE_INT offsets[2], offset, align[2]; |
| 17179 |
rtx base = NULL_RTX; |
| 17180 |
rtx cur_base, cur_offset, tmp; |
| 17181 |
int i, gap; |
| 17182 |
HARD_REG_SET regset; |
| 17183 |
|
| 17184 |
gcc_assert (!const_store || !load); |
| 17185 |
/* Check that the memory references are immediate offsets from the |
| 17186 |
same base register. Extract the base register, the destination |
| 17187 |
registers, and the corresponding memory offsets. */ |
| 17188 |
for (i = 0; i < nops; i++) |
| 17189 |
{ |
| 17190 |
if (!mem_ok_for_ldrd_strd (operands[nops+i], &cur_base, &cur_offset, |
| 17191 |
&align[i])) |
| 17192 |
return false; |
| 17193 |
|
| 17194 |
if (i == 0) |
| 17195 |
base = cur_base; |
| 17196 |
else if (REGNO (base) != REGNO (cur_base)) |
| 17197 |
return false; |
| 17198 |
|
| 17199 |
offsets[i] = INTVAL (cur_offset); |
| 17200 |
if (GET_CODE (operands[i]) == SUBREG) |
| 17201 |
{ |
| 17202 |
tmp = SUBREG_REG (operands[i]); |
| 17203 |
gcc_assert (GET_MODE (operands[i]) == GET_MODE (tmp)); |
| 17204 |
operands[i] = tmp; |
| 17205 |
} |
| 17206 |
} |
| 17207 |
|
| 17208 |
/* Make sure there is no dependency between the individual loads. */ |
| 17209 |
if (load && REGNO (operands[0]) == REGNO (base)) |
| 17210 |
return false; /* RAW */ |
| 17211 |
|
| 17212 |
if (load && REGNO (operands[0]) == REGNO (operands[1])) |
| 17213 |
return false; /* WAW */ |
| 17214 |
|
| 17215 |
/* If the same input register is used in both stores |
| 17216 |
when storing different constants, try to find a free register. |
| 17217 |
For example, the code |
| 17218 |
mov r0, 0 |
| 17219 |
str r0, [r2] |
| 17220 |
mov r0, 1 |
| 17221 |
str r0, [r2, #4] |
| 17222 |
can be transformed into |
| 17223 |
mov r1, 0 |
| 17224 |
mov r0, 1 |
| 17225 |
strd r1, r0, [r2] |
| 17226 |
in Thumb mode assuming that r1 is free. |
| 17227 |
For ARM mode do the same but only if the starting register |
| 17228 |
can be made to be even. */ |
| 17229 |
if (const_store |
| 17230 |
&& REGNO (operands[0]) == REGNO (operands[1]) |
| 17231 |
&& INTVAL (operands[4]) != INTVAL (operands[5])) |
| 17232 |
{ |
| 17233 |
if (TARGET_THUMB2) |
| 17234 |
{ |
| 17235 |
CLEAR_HARD_REG_SET (regset); |
| 17236 |
tmp = peep2_find_free_register (0, 4, "r", SImode, ®set); |
| 17237 |
if (tmp == NULL_RTX) |
| 17238 |
return false; |
| 17239 |
|
| 17240 |
/* Use the new register in the first load to ensure that |
| 17241 |
if the original input register is not dead after peephole, |
| 17242 |
then it will have the correct constant value. */ |
| 17243 |
operands[0] = tmp; |
| 17244 |
} |
| 17245 |
else if (TARGET_ARM) |
| 17246 |
{ |
| 17247 |
int regno = REGNO (operands[0]); |
| 17248 |
if (!peep2_reg_dead_p (4, operands[0])) |
| 17249 |
{ |
| 17250 |
/* When the input register is even and is not dead after the |
| 17251 |
pattern, it has to hold the second constant but we cannot |
| 17252 |
form a legal STRD in ARM mode with this register as the second |
| 17253 |
register. */ |
| 17254 |
if (regno % 2 == 0) |
| 17255 |
return false; |
| 17256 |
|
| 17257 |
/* Is regno-1 free? */ |
| 17258 |
SET_HARD_REG_SET (regset); |
| 17259 |
CLEAR_HARD_REG_BIT(regset, regno - 1); |
| 17260 |
tmp = peep2_find_free_register (0, 4, "r", SImode, ®set); |
| 17261 |
if (tmp == NULL_RTX) |
| 17262 |
return false; |
| 17263 |
|
| 17264 |
operands[0] = tmp; |
| 17265 |
} |
| 17266 |
else |
| 17267 |
{ |
| 17268 |
/* Find a DImode register. */ |
| 17269 |
CLEAR_HARD_REG_SET (regset); |
| 17270 |
tmp = peep2_find_free_register (0, 4, "r", DImode, ®set); |
| 17271 |
if (tmp != NULL_RTX) |
| 17272 |
{ |
| 17273 |
operands[0] = simplify_gen_subreg (SImode, tmp, DImode, 0); |
| 17274 |
operands[1] = simplify_gen_subreg (SImode, tmp, DImode, 4); |
| 17275 |
} |
| 17276 |
else |
| 17277 |
{ |
| 17278 |
/* Can we use the input register to form a DI register? */ |
| 17279 |
SET_HARD_REG_SET (regset); |
| 17280 |
CLEAR_HARD_REG_BIT(regset, |
| 17281 |
regno % 2 == 0 ? regno + 1 : regno - 1); |
| 17282 |
tmp = peep2_find_free_register (0, 4, "r", SImode, ®set); |
| 17283 |
if (tmp == NULL_RTX) |
| 17284 |
return false; |
| 17285 |
operands[regno % 2 == 1 ? 0 : 1] = tmp; |
| 17286 |
} |
| 17287 |
} |
| 17288 |
|
| 17289 |
gcc_assert (operands[0] != NULL_RTX); |
| 17290 |
gcc_assert (operands[1] != NULL_RTX); |
| 17291 |
gcc_assert (REGNO (operands[0]) % 2 == 0); |
| 17292 |
gcc_assert (REGNO (operands[1]) == REGNO (operands[0]) + 1); |
| 17293 |
} |
| 17294 |
} |
| 17295 |
|
| 17296 |
/* Make sure the instructions are ordered with lower memory access first. */ |
| 17297 |
if (offsets[0] > offsets[1]) |
| 17298 |
{ |
| 17299 |
gap = offsets[0] - offsets[1]; |
| 17300 |
offset = offsets[1]; |
| 17301 |
|
| 17302 |
/* Swap the instructions such that lower memory is accessed first. */ |
| 17303 |
std::swap (operands[0], operands[1]); |
| 17304 |
std::swap (operands[2], operands[3]); |
| 17305 |
std::swap (align[0], align[1]); |
| 17306 |
if (const_store) |
| 17307 |
std::swap (operands[4], operands[5]); |
| 17308 |
} |
| 17309 |
else |
| 17310 |
{ |
| 17311 |
gap = offsets[1] - offsets[0]; |
| 17312 |
offset = offsets[0]; |
| 17313 |
} |
| 17314 |
|
| 17315 |
/* Make sure accesses are to consecutive memory locations. */ |
| 17316 |
if (gap != GET_MODE_SIZE (SImode)) |
| 17317 |
return false; |
| 17318 |
|
| 17319 |
if (!align_ok_ldrd_strd (align[0], offset)) |
| 17320 |
return false; |
| 17321 |
|
| 17322 |
/* Make sure we generate legal instructions. */ |
| 17323 |
if (operands_ok_ldrd_strd (operands[0], operands[1], base, offset, |
| 17324 |
false, load)) |
| 17325 |
return true; |
| 17326 |
|
| 17327 |
/* In Thumb state, where registers are almost unconstrained, there |
| 17328 |
is little hope to fix it. */ |
| 17329 |
if (TARGET_THUMB2) |
| 17330 |
return false; |
| 17331 |
|
| 17332 |
if (load && commute) |
| 17333 |
{ |
| 17334 |
/* Try reordering registers. */ |
| 17335 |
std::swap (operands[0], operands[1]); |
| 17336 |
if (operands_ok_ldrd_strd (operands[0], operands[1], base, offset, |
| 17337 |
false, load)) |
| 17338 |
return true; |
| 17339 |
} |
| 17340 |
|
| 17341 |
if (const_store) |
| 17342 |
{ |
| 17343 |
/* If input registers are dead after this pattern, they can be |
| 17344 |
reordered or replaced by other registers that are free in the |
| 17345 |
current pattern. */ |
| 17346 |
if (!peep2_reg_dead_p (4, operands[0]) |
| 17347 |
|| !peep2_reg_dead_p (4, operands[1])) |
| 17348 |
return false; |
| 17349 |
|
| 17350 |
/* Try to reorder the input registers. */ |
| 17351 |
/* For example, the code |
| 17352 |
mov r0, 0 |
| 17353 |
mov r1, 1 |
| 17354 |
str r1, [r2] |
| 17355 |
str r0, [r2, #4] |
| 17356 |
can be transformed into |
| 17357 |
mov r1, 0 |
| 17358 |
mov r0, 1 |
| 17359 |
strd r0, [r2] |
| 17360 |
*/ |
| 17361 |
if (operands_ok_ldrd_strd (operands[1], operands[0], base, offset, |
| 17362 |
false, false)) |
| 17363 |
{ |
| 17364 |
std::swap (operands[0], operands[1]); |
| 17365 |
return true; |
| 17366 |
} |
| 17367 |
|
| 17368 |
/* Try to find a free DI register. */ |
| 17369 |
CLEAR_HARD_REG_SET (regset); |
| 17370 |
add_to_hard_reg_set (®set, SImode, REGNO (operands[0])); |
| 17371 |
add_to_hard_reg_set (®set, SImode, REGNO (operands[1])); |
| 17372 |
while (true) |
| 17373 |
{ |
| 17374 |
tmp = peep2_find_free_register (0, 4, "r", DImode, ®set); |
| 17375 |
if (tmp == NULL_RTX) |
| 17376 |
return false; |
| 17377 |
|
| 17378 |
/* DREG must be an even-numbered register in DImode. |
| 17379 |
Split it into SI registers. */ |
| 17380 |
operands[0] = simplify_gen_subreg (SImode, tmp, DImode, 0); |
| 17381 |
operands[1] = simplify_gen_subreg (SImode, tmp, DImode, 4); |
| 17382 |
gcc_assert (operands[0] != NULL_RTX); |
| 17383 |
gcc_assert (operands[1] != NULL_RTX); |
| 17384 |
gcc_assert (REGNO (operands[0]) % 2 == 0); |
| 17385 |
gcc_assert (REGNO (operands[0]) + 1 == REGNO (operands[1])); |
| 17386 |
|
| 17387 |
return (operands_ok_ldrd_strd (operands[0], operands[1], |
| 17388 |
base, offset, |
| 17389 |
false, load)); |
| 17390 |
} |
| 17391 |
} |
| 17392 |
|
| 17393 |
return false; |
| 17394 |
} |
| 17395 |
|
| 17396 |
|
| 17397 |
/* Return true if parallel execution of the two word-size accesses provided |
| 17398 |
could be satisfied with a single LDRD/STRD instruction. Two word-size |
| 17399 |
accesses are represented by the OPERANDS array, where OPERANDS[0,1] are |
| 17400 |
register operands and OPERANDS[2,3] are the corresponding memory operands. |
| 17401 |
*/ |
| 17402 |
bool |
| 17403 |
valid_operands_ldrd_strd (rtx *operands, bool load) |
| 17404 |
{ |
| 17405 |
int nops = 2; |
| 17406 |
HOST_WIDE_INT offsets[2], offset, align[2]; |
| 17407 |
rtx base = NULL_RTX; |
| 17408 |
rtx cur_base, cur_offset; |
| 17409 |
int i, gap; |
| 17410 |
|
| 17411 |
/* Check that the memory references are immediate offsets from the |
| 17412 |
same base register. Extract the base register, the destination |
| 17413 |
registers, and the corresponding memory offsets. */ |
| 17414 |
for (i = 0; i < nops; i++) |
| 17415 |
{ |
| 17416 |
if (!mem_ok_for_ldrd_strd (operands[nops+i], &cur_base, &cur_offset, |
| 17417 |
&align[i])) |
| 17418 |
return false; |
| 17419 |
|
| 17420 |
if (i == 0) |
| 17421 |
base = cur_base; |
| 17422 |
else if (REGNO (base) != REGNO (cur_base)) |
| 17423 |
return false; |
| 17424 |
|
| 17425 |
offsets[i] = INTVAL (cur_offset); |
| 17426 |
if (GET_CODE (operands[i]) == SUBREG) |
| 17427 |
return false; |
| 17428 |
} |
| 17429 |
|
| 17430 |
if (offsets[0] > offsets[1]) |
| 17431 |
return false; |
| 17432 |
|
| 17433 |
gap = offsets[1] - offsets[0]; |
| 17434 |
offset = offsets[0]; |
| 17435 |
|
| 17436 |
/* Make sure accesses are to consecutive memory locations. */ |
| 17437 |
if (gap != GET_MODE_SIZE (SImode)) |
| 17438 |
return false; |
| 17439 |
|
| 17440 |
if (!align_ok_ldrd_strd (align[0], offset)) |
| 17441 |
return false; |
| 17442 |
|
| 17443 |
return operands_ok_ldrd_strd (operands[0], operands[1], base, offset, |
| 17444 |
false, load); |
| 17445 |
} |
| 17446 |
|
| 17447 |
|
| 17448 |
/* Print a symbolic form of X to the debug file, F. */ |
| 17449 |
static void |
| 17450 |
arm_print_value (FILE *f, rtx x) |
| 17451 |
{ |
| 17452 |
switch (GET_CODE (x)) |
| 17453 |
{ |
| 17454 |
case CONST_INT: |
| 17455 |
fprintf (f, HOST_WIDE_INT_PRINT_HEX, INTVAL (x)); |
| 17456 |
return; |
| 17457 |
|
| 17458 |
case CONST_DOUBLE: |
| 17459 |
{ |
| 17460 |
char fpstr[20]; |
| 17461 |
real_to_decimal (fpstr, CONST_DOUBLE_REAL_VALUE (x), |
| 17462 |
sizeof (fpstr), 0, 1); |
| 17463 |
fputs (fpstr, f); |
| 17464 |
} |
| 17465 |
return; |
| 17466 |
|
| 17467 |
case CONST_VECTOR: |
| 17468 |
{ |
| 17469 |
int i; |
| 17470 |
|
| 17471 |
fprintf (f, "<"); |
| 17472 |
for (i = 0; i < CONST_VECTOR_NUNITS (x); i++) |
| 17473 |
{ |
| 17474 |
fprintf (f, HOST_WIDE_INT_PRINT_HEX, INTVAL (CONST_VECTOR_ELT (x, i))); |
| 17475 |
if (i < (CONST_VECTOR_NUNITS (x) - 1)) |
| 17476 |
fputc (',', f); |
| 17477 |
} |
| 17478 |
fprintf (f, ">"); |
| 17479 |
} |
| 17480 |
return; |
| 17481 |
|
| 17482 |
case CONST_STRING: |
| 17483 |
fprintf (f, "\"%s\"", XSTR (x, 0)); |
| 17484 |
return; |
| 17485 |
|
| 17486 |
case SYMBOL_REF: |
| 17487 |
fprintf (f, "`%s'", XSTR (x, 0)); |
| 17488 |
return; |
| 17489 |
|
| 17490 |
case LABEL_REF: |
| 17491 |
fprintf (f, "L%d", INSN_UID (XEXP (x, 0))); |
| 17492 |
return; |
| 17493 |
|
| 17494 |
case CONST: |
| 17495 |
arm_print_value (f, XEXP (x, 0)); |
| 17496 |
return; |
| 17497 |
|
| 17498 |
case PLUS: |
| 17499 |
arm_print_value (f, XEXP (x, 0)); |
| 17500 |
fprintf (f, "+"); |
| 17501 |
arm_print_value (f, XEXP (x, 1)); |
| 17502 |
return; |
| 17503 |
|
| 17504 |
case PC: |
| 17505 |
fprintf (f, "pc"); |
| 17506 |
return; |
| 17507 |
|
| 17508 |
default: |
| 17509 |
fprintf (f, "????"); |
| 17510 |
return; |
| 17511 |
} |
| 17512 |
} |
| 17513 |
|
| 17514 |
/* Routines for manipulation of the constant pool. */ |
| 17515 |
|
| 17516 |
/* Arm instructions cannot load a large constant directly into a |
| 17517 |
register; they have to come from a pc relative load. The constant |
| 17518 |
must therefore be placed in the addressable range of the pc |
| 17519 |
relative load. Depending on the precise pc relative load |
| 17520 |
instruction the range is somewhere between 256 bytes and 4k. This |
| 17521 |
means that we often have to dump a constant inside a function, and |
| 17522 |
generate code to branch around it. |
| 17523 |
|
| 17524 |
It is important to minimize this, since the branches will slow |
| 17525 |
things down and make the code larger. |
| 17526 |
|
| 17527 |
Normally we can hide the table after an existing unconditional |
| 17528 |
branch so that there is no interruption of the flow, but in the |
| 17529 |
worst case the code looks like this: |
| 17530 |
|
| 17531 |
ldr rn, L1 |
| 17532 |
... |
| 17533 |
b L2 |
| 17534 |
align |
| 17535 |
L1: .long value |
| 17536 |
L2: |
| 17537 |
... |
| 17538 |
|
| 17539 |
ldr rn, L3 |
| 17540 |
... |
| 17541 |
b L4 |
| 17542 |
align |
| 17543 |
L3: .long value |
| 17544 |
L4: |
| 17545 |
... |
| 17546 |
|
| 17547 |
We fix this by performing a scan after scheduling, which notices |
| 17548 |
which instructions need to have their operands fetched from the |
| 17549 |
constant table and builds the table. |
| 17550 |
|
| 17551 |
The algorithm starts by building a table of all the constants that |
| 17552 |
need fixing up and all the natural barriers in the function (places |
| 17553 |
where a constant table can be dropped without breaking the flow). |
| 17554 |
For each fixup we note how far the pc-relative replacement will be |
| 17555 |
able to reach and the offset of the instruction into the function. |
| 17556 |
|
| 17557 |
Having built the table we then group the fixes together to form |
| 17558 |
tables that are as large as possible (subject to addressing |
| 17559 |
constraints) and emit each table of constants after the last |
| 17560 |
barrier that is within range of all the instructions in the group. |
| 17561 |
If a group does not contain a barrier, then we forcibly create one |
| 17562 |
by inserting a jump instruction into the flow. Once the table has |
| 17563 |
been inserted, the insns are then modified to reference the |
| 17564 |
relevant entry in the pool. |
| 17565 |
|
| 17566 |
Possible enhancements to the algorithm (not implemented) are: |
| 17567 |
|
| 17568 |
1) For some processors and object formats, there may be benefit in |
| 17569 |
aligning the pools to the start of cache lines; this alignment |
| 17570 |
would need to be taken into account when calculating addressability |
| 17571 |
of a pool. */ |
| 17572 |
|
| 17573 |
/* These typedefs are located at the start of this file, so that |
| 17574 |
they can be used in the prototypes there. This comment is to |
| 17575 |
remind readers of that fact so that the following structures |
| 17576 |
can be understood more easily. |
| 17577 |
|
| 17578 |
typedef struct minipool_node Mnode; |
| 17579 |
typedef struct minipool_fixup Mfix; */ |
| 17580 |
|
| 17581 |
struct minipool_node |
| 17582 |
{ |
| 17583 |
/* Doubly linked chain of entries. */ |
| 17584 |
Mnode * next; |
| 17585 |
Mnode * prev; |
| 17586 |
/* The maximum offset into the code that this entry can be placed. While |
| 17587 |
pushing fixes for forward references, all entries are sorted in order |
| 17588 |
of increasing max_address. */ |
| 17589 |
HOST_WIDE_INT max_address; |
| 17590 |
/* Similarly for an entry inserted for a backwards ref. */ |
| 17591 |
HOST_WIDE_INT min_address; |
| 17592 |
/* The number of fixes referencing this entry. This can become zero |
| 17593 |
if we "unpush" an entry. In this case we ignore the entry when we |
| 17594 |
come to emit the code. */ |
| 17595 |
int refcount; |
| 17596 |
/* The offset from the start of the minipool. */ |
| 17597 |
HOST_WIDE_INT offset; |
| 17598 |
/* The value in table. */ |
| 17599 |
rtx value; |
| 17600 |
/* The mode of value. */ |
| 17601 |
machine_mode mode; |
| 17602 |
/* The size of the value. With iWMMXt enabled |
| 17603 |
sizes > 4 also imply an alignment of 8-bytes. */ |
| 17604 |
int fix_size; |
| 17605 |
}; |
| 17606 |
|
| 17607 |
struct minipool_fixup |
| 17608 |
{ |
| 17609 |
Mfix * next; |
| 17610 |
rtx_insn * insn; |
| 17611 |
HOST_WIDE_INT address; |
| 17612 |
rtx * loc; |
| 17613 |
machine_mode mode; |
| 17614 |
int fix_size; |
| 17615 |
rtx value; |
| 17616 |
Mnode * minipool; |
| 17617 |
HOST_WIDE_INT forwards; |
| 17618 |
HOST_WIDE_INT backwards; |
| 17619 |
}; |
| 17620 |
|
| 17621 |
/* Fixes less than a word need padding out to a word boundary. */ |
| 17622 |
#define MINIPOOL_FIX_SIZE(mode) \ |
| 17623 |
(GET_MODE_SIZE ((mode)) >= 4 ? GET_MODE_SIZE ((mode)) : 4) |
| 17624 |
|
| 17625 |
static Mnode * minipool_vector_head; |
| 17626 |
static Mnode * minipool_vector_tail; |
| 17627 |
static rtx_code_label *minipool_vector_label; |
| 17628 |
static int minipool_pad; |
| 17629 |
|
| 17630 |
/* The linked list of all minipool fixes required for this function. */ |
| 17631 |
Mfix * minipool_fix_head; |
| 17632 |
Mfix * minipool_fix_tail; |
| 17633 |
/* The fix entry for the current minipool, once it has been placed. */ |
| 17634 |
Mfix * minipool_barrier; |
| 17635 |
|
| 17636 |
#ifndef JUMP_TABLES_IN_TEXT_SECTION |
| 17637 |
#define JUMP_TABLES_IN_TEXT_SECTION 0 |
| 17638 |
#endif |
| 17639 |
|
| 17640 |
static HOST_WIDE_INT |
| 17641 |
get_jump_table_size (rtx_jump_table_data *insn) |
| 17642 |
{ |
| 17643 |
/* ADDR_VECs only take room if read-only data does into the text |
| 17644 |
section. */ |
| 17645 |
if (JUMP_TABLES_IN_TEXT_SECTION || readonly_data_section == text_section) |
| 17646 |
{ |
| 17647 |
rtx body = PATTERN (insn); |
| 17648 |
int elt = GET_CODE (body) == ADDR_DIFF_VEC ? 1 : 0; |
| 17649 |
HOST_WIDE_INT size; |
| 17650 |
HOST_WIDE_INT modesize; |
| 17651 |
|
| 17652 |
modesize = GET_MODE_SIZE (GET_MODE (body)); |
| 17653 |
size = modesize * XVECLEN (body, elt); |
| 17654 |
switch (modesize) |
| 17655 |
{ |
| 17656 |
case 1: |
| 17657 |
/* Round up size of TBB table to a halfword boundary. */ |
| 17658 |
size = (size + 1) & ~HOST_WIDE_INT_1; |
| 17659 |
break; |
| 17660 |
case 2: |
| 17661 |
/* No padding necessary for TBH. */ |
| 17662 |
break; |
| 17663 |
case 4: |
| 17664 |
/* Add two bytes for alignment on Thumb. */ |
| 17665 |
if (TARGET_THUMB) |
| 17666 |
size += 2; |
| 17667 |
break; |
| 17668 |
default: |
| 17669 |
gcc_unreachable (); |
| 17670 |
} |
| 17671 |
return size; |
| 17672 |
} |
| 17673 |
|
| 17674 |
return 0; |
| 17675 |
} |
| 17676 |
|
| 17677 |
/* Emit insns to load the function address from FUNCDESC (an FDPIC |
| 17678 |
function descriptor) into a register and the GOT address into the |
| 17679 |
FDPIC register, returning an rtx for the register holding the |
| 17680 |
function address. */ |
| 17681 |
|
| 17682 |
rtx |
| 17683 |
arm_load_function_descriptor (rtx funcdesc) |
| 17684 |
{ |
| 17685 |
rtx fnaddr_reg = gen_reg_rtx (Pmode); |
| 17686 |
rtx pic_reg = gen_rtx_REG (Pmode, FDPIC_REGNUM); |
| 17687 |
rtx fnaddr = gen_rtx_MEM (Pmode, funcdesc); |
| 17688 |
rtx gotaddr = gen_rtx_MEM (Pmode, plus_constant (Pmode, funcdesc, 4)); |
| 17689 |
|
| 17690 |
emit_move_insn (fnaddr_reg, fnaddr); |
| 17691 |
|
| 17692 |
/* The ABI requires the entry point address to be loaded first, but |
| 17693 |
since we cannot support lazy binding for lack of atomic load of |
| 17694 |
two 32-bits values, we do not need to bother to prevent the |
| 17695 |
previous load from being moved after that of the GOT address. */ |
| 17696 |
emit_insn (gen_restore_pic_register_after_call (pic_reg, gotaddr)); |
| 17697 |
|
| 17698 |
return fnaddr_reg; |
| 17699 |
} |
| 17700 |
|
| 17701 |
/* Return the maximum amount of padding that will be inserted before |
| 17702 |
label LABEL. */ |
| 17703 |
static HOST_WIDE_INT |
| 17704 |
get_label_padding (rtx label) |
| 17705 |
{ |
| 17706 |
HOST_WIDE_INT align, min_insn_size; |
| 17707 |
|
| 17708 |
align = 1 << label_to_alignment (label).levels[0].log; |
| 17709 |
min_insn_size = TARGET_THUMB ? 2 : 4; |
| 17710 |
return align > min_insn_size ? align - min_insn_size : 0; |
| 17711 |
} |
| 17712 |
|
| 17713 |
/* Move a minipool fix MP from its current location to before MAX_MP. |
| 17714 |
If MAX_MP is NULL, then MP doesn't need moving, but the addressing |
| 17715 |
constraints may need updating. */ |
| 17716 |
static Mnode * |
| 17717 |
move_minipool_fix_forward_ref (Mnode *mp, Mnode *max_mp, |
| 17718 |
HOST_WIDE_INT max_address) |
| 17719 |
{ |
| 17720 |
/* The code below assumes these are different. */ |
| 17721 |
gcc_assert (mp != max_mp); |
| 17722 |
|
| 17723 |
if (max_mp == NULL) |
| 17724 |
{ |
| 17725 |
if (max_address < mp->max_address) |
| 17726 |
mp->max_address = max_address; |
| 17727 |
} |
| 17728 |
else |
| 17729 |
{ |
| 17730 |
if (max_address > max_mp->max_address - mp->fix_size) |
| 17731 |
mp->max_address = max_mp->max_address - mp->fix_size; |
| 17732 |
else |
| 17733 |
mp->max_address = max_address; |
| 17734 |
|
| 17735 |
/* Unlink MP from its current position. Since max_mp is non-null, |
| 17736 |
mp->prev must be non-null. */ |
| 17737 |
mp->prev->next = mp->next; |
| 17738 |
if (mp->next != NULL) |
| 17739 |
mp->next->prev = mp->prev; |
| 17740 |
else |
| 17741 |
minipool_vector_tail = mp->prev; |
| 17742 |
|
| 17743 |
/* Re-insert it before MAX_MP. */ |
| 17744 |
mp->next = max_mp; |
| 17745 |
mp->prev = max_mp->prev; |
| 17746 |
max_mp->prev = mp; |
| 17747 |
|
| 17748 |
if (mp->prev != NULL) |
| 17749 |
mp->prev->next = mp; |
| 17750 |
else |
| 17751 |
minipool_vector_head = mp; |
| 17752 |
} |
| 17753 |
|
| 17754 |
/* Save the new entry. */ |
| 17755 |
max_mp = mp; |
| 17756 |
|
| 17757 |
/* Scan over the preceding entries and adjust their addresses as |
| 17758 |
required. */ |
| 17759 |
while (mp->prev != NULL |
| 17760 |
&& mp->prev->max_address > mp->max_address - mp->prev->fix_size) |
| 17761 |
{ |
| 17762 |
mp->prev->max_address = mp->max_address - mp->prev->fix_size; |
| 17763 |
mp = mp->prev; |
| 17764 |
} |
| 17765 |
|
| 17766 |
return max_mp; |
| 17767 |
} |
| 17768 |
|
| 17769 |
/* Add a constant to the minipool for a forward reference. Returns the |
| 17770 |
node added or NULL if the constant will not fit in this pool. */ |
| 17771 |
static Mnode * |
| 17772 |
add_minipool_forward_ref (Mfix *fix) |
| 17773 |
{ |
| 17774 |
/* If set, max_mp is the first pool_entry that has a lower |
| 17775 |
constraint than the one we are trying to add. */ |
| 17776 |
Mnode * max_mp = NULL; |
| 17777 |
HOST_WIDE_INT max_address = fix->address + fix->forwards - minipool_pad; |
| 17778 |
Mnode * mp; |
| 17779 |
|
| 17780 |
/* If the minipool starts before the end of FIX->INSN then this FIX |
| 17781 |
cannot be placed into the current pool. Furthermore, adding the |
| 17782 |
new constant pool entry may cause the pool to start FIX_SIZE bytes |
| 17783 |
earlier. */ |
| 17784 |
if (minipool_vector_head && |
| 17785 |
(fix->address + get_attr_length (fix->insn) |
| 17786 |
>= minipool_vector_head->max_address - fix->fix_size)) |
| 17787 |
return NULL; |
| 17788 |
|
| 17789 |
/* Scan the pool to see if a constant with the same value has |
| 17790 |
already been added. While we are doing this, also note the |
| 17791 |
location where we must insert the constant if it doesn't already |
| 17792 |
exist. */ |
| 17793 |
for (mp = minipool_vector_head; mp != NULL; mp = mp->next) |
| 17794 |
{ |
| 17795 |
if (GET_CODE (fix->value) == GET_CODE (mp->value) |
| 17796 |
&& fix->mode == mp->mode |
| 17797 |
&& (!LABEL_P (fix->value) |
| 17798 |
|| (CODE_LABEL_NUMBER (fix->value) |
| 17799 |
== CODE_LABEL_NUMBER (mp->value))) |
| 17800 |
&& rtx_equal_p (fix->value, mp->value)) |
| 17801 |
{ |
| 17802 |
/* More than one fix references this entry. */ |
| 17803 |
mp->refcount++; |
| 17804 |
return move_minipool_fix_forward_ref (mp, max_mp, max_address); |
| 17805 |
} |
| 17806 |
|
| 17807 |
/* Note the insertion point if necessary. */ |
| 17808 |
if (max_mp == NULL |
| 17809 |
&& mp->max_address > max_address) |
| 17810 |
max_mp = mp; |
| 17811 |
|
| 17812 |
/* If we are inserting an 8-bytes aligned quantity and |
| 17813 |
we have not already found an insertion point, then |
| 17814 |
make sure that all such 8-byte aligned quantities are |
| 17815 |
placed at the start of the pool. */ |
| 17816 |
if (ARM_DOUBLEWORD_ALIGN |
| 17817 |
&& max_mp == NULL |
| 17818 |
&& fix->fix_size >= 8 |
| 17819 |
&& mp->fix_size < 8) |
| 17820 |
{ |
| 17821 |
max_mp = mp; |
| 17822 |
max_address = mp->max_address; |
| 17823 |
} |
| 17824 |
} |
| 17825 |
|
| 17826 |
/* The value is not currently in the minipool, so we need to create |
| 17827 |
a new entry for it. If MAX_MP is NULL, the entry will be put on |
| 17828 |
the end of the list since the placement is less constrained than |
| 17829 |
any existing entry. Otherwise, we insert the new fix before |
| 17830 |
MAX_MP and, if necessary, adjust the constraints on the other |
| 17831 |
entries. */ |
| 17832 |
mp = XNEW (Mnode); |
| 17833 |
mp->fix_size = fix->fix_size; |
| 17834 |
mp->mode = fix->mode; |
| 17835 |
mp->value = fix->value; |
| 17836 |
mp->refcount = 1; |
| 17837 |
/* Not yet required for a backwards ref. */ |
| 17838 |
mp->min_address = -65536; |
| 17839 |
|
| 17840 |
if (max_mp == NULL) |
| 17841 |
{ |
| 17842 |
mp->max_address = max_address; |
| 17843 |
mp->next = NULL; |
| 17844 |
mp->prev = minipool_vector_tail; |
| 17845 |
|
| 17846 |
if (mp->prev == NULL) |
| 17847 |
{ |
| 17848 |
minipool_vector_head = mp; |
| 17849 |
minipool_vector_label = gen_label_rtx (); |
| 17850 |
} |
| 17851 |
else |
| 17852 |
mp->prev->next = mp; |
| 17853 |
|
| 17854 |
minipool_vector_tail = mp; |
| 17855 |
} |
| 17856 |
else |
| 17857 |
{ |
| 17858 |
if (max_address > max_mp->max_address - mp->fix_size) |
| 17859 |
mp->max_address = max_mp->max_address - mp->fix_size; |
| 17860 |
else |
| 17861 |
mp->max_address = max_address; |
| 17862 |
|
| 17863 |
mp->next = max_mp; |
| 17864 |
mp->prev = max_mp->prev; |
| 17865 |
max_mp->prev = mp; |
| 17866 |
if (mp->prev != NULL) |
| 17867 |
mp->prev->next = mp; |
| 17868 |
else |
| 17869 |
minipool_vector_head = mp; |
| 17870 |
} |
| 17871 |
|
| 17872 |
/* Save the new entry. */ |
| 17873 |
max_mp = mp; |
| 17874 |
|
| 17875 |
/* Scan over the preceding entries and adjust their addresses as |
| 17876 |
required. */ |
| 17877 |
while (mp->prev != NULL |
| 17878 |
&& mp->prev->max_address > mp->max_address - mp->prev->fix_size) |
| 17879 |
{ |
| 17880 |
mp->prev->max_address = mp->max_address - mp->prev->fix_size; |
| 17881 |
mp = mp->prev; |
| 17882 |
} |
| 17883 |
|
| 17884 |
return max_mp; |
| 17885 |
} |
| 17886 |
|
| 17887 |
static Mnode * |
| 17888 |
move_minipool_fix_backward_ref (Mnode *mp, Mnode *min_mp, |
| 17889 |
HOST_WIDE_INT min_address) |
| 17890 |
{ |
| 17891 |
HOST_WIDE_INT offset; |
| 17892 |
|
| 17893 |
/* The code below assumes these are different. */ |
| 17894 |
gcc_assert (mp != min_mp); |
| 17895 |
|
| 17896 |
if (min_mp == NULL) |
| 17897 |
{ |
| 17898 |
if (min_address > mp->min_address) |
| 17899 |
mp->min_address = min_address; |
| 17900 |
} |
| 17901 |
else |
| 17902 |
{ |
| 17903 |
/* We will adjust this below if it is too loose. */ |
| 17904 |
mp->min_address = min_address; |
| 17905 |
|
| 17906 |
/* Unlink MP from its current position. Since min_mp is non-null, |
| 17907 |
mp->next must be non-null. */ |
| 17908 |
mp->next->prev = mp->prev; |
| 17909 |
if (mp->prev != NULL) |
| 17910 |
mp->prev->next = mp->next; |
| 17911 |
else |
| 17912 |
minipool_vector_head = mp->next; |
| 17913 |
|
| 17914 |
/* Reinsert it after MIN_MP. */ |
| 17915 |
mp->prev = min_mp; |
| 17916 |
mp->next = min_mp->next; |
| 17917 |
min_mp->next = mp; |
| 17918 |
if (mp->next != NULL) |
| 17919 |
mp->next->prev = mp; |
| 17920 |
else |
| 17921 |
minipool_vector_tail = mp; |
| 17922 |
} |
| 17923 |
|
| 17924 |
min_mp = mp; |
| 17925 |
|
| 17926 |
offset = 0; |
| 17927 |
for (mp = minipool_vector_head; mp != NULL; mp = mp->next) |
| 17928 |
{ |
| 17929 |
mp->offset = offset; |
| 17930 |
if (mp->refcount > 0) |
| 17931 |
offset += mp->fix_size; |
| 17932 |
|
| 17933 |
if (mp->next && mp->next->min_address < mp->min_address + mp->fix_size) |
| 17934 |
mp->next->min_address = mp->min_address + mp->fix_size; |
| 17935 |
} |
| 17936 |
|
| 17937 |
return min_mp; |
| 17938 |
} |
| 17939 |
|
| 17940 |
/* Add a constant to the minipool for a backward reference. Returns the |
| 17941 |
node added or NULL if the constant will not fit in this pool. |
| 17942 |
|
| 17943 |
Note that the code for insertion for a backwards reference can be |
| 17944 |
somewhat confusing because the calculated offsets for each fix do |
| 17945 |
not take into account the size of the pool (which is still under |
| 17946 |
construction. */ |
| 17947 |
static Mnode * |
| 17948 |
add_minipool_backward_ref (Mfix *fix) |
| 17949 |
{ |
| 17950 |
/* If set, min_mp is the last pool_entry that has a lower constraint |
| 17951 |
than the one we are trying to add. */ |
| 17952 |
Mnode *min_mp = NULL; |
| 17953 |
/* This can be negative, since it is only a constraint. */ |
| 17954 |
HOST_WIDE_INT min_address = fix->address - fix->backwards; |
| 17955 |
Mnode *mp; |
| 17956 |
|
| 17957 |
/* If we can't reach the current pool from this insn, or if we can't |
| 17958 |
insert this entry at the end of the pool without pushing other |
| 17959 |
fixes out of range, then we don't try. This ensures that we |
| 17960 |
can't fail later on. */ |
| 17961 |
if (min_address >= minipool_barrier->address |
| 17962 |
|| (minipool_vector_tail->min_address + fix->fix_size |
| 17963 |
>= minipool_barrier->address)) |
| 17964 |
return NULL; |
| 17965 |
|
| 17966 |
/* Scan the pool to see if a constant with the same value has |
| 17967 |
already been added. While we are doing this, also note the |
| 17968 |
location where we must insert the constant if it doesn't already |
| 17969 |
exist. */ |
| 17970 |
for (mp = minipool_vector_tail; mp != NULL; mp = mp->prev) |
| 17971 |
{ |
| 17972 |
if (GET_CODE (fix->value) == GET_CODE (mp->value) |
| 17973 |
&& fix->mode == mp->mode |
| 17974 |
&& (!LABEL_P (fix->value) |
| 17975 |
|| (CODE_LABEL_NUMBER (fix->value) |
| 17976 |
== CODE_LABEL_NUMBER (mp->value))) |
| 17977 |
&& rtx_equal_p (fix->value, mp->value) |
| 17978 |
/* Check that there is enough slack to move this entry to the |
| 17979 |
end of the table (this is conservative). */ |
| 17980 |
&& (mp->max_address |
| 17981 |
> (minipool_barrier->address |
| 17982 |
+ minipool_vector_tail->offset |
| 17983 |
+ minipool_vector_tail->fix_size))) |
| 17984 |
{ |
| 17985 |
mp->refcount++; |
| 17986 |
return move_minipool_fix_backward_ref (mp, min_mp, min_address); |
| 17987 |
} |
| 17988 |
|
| 17989 |
if (min_mp != NULL) |
| 17990 |
mp->min_address += fix->fix_size; |
| 17991 |
else |
| 17992 |
{ |
| 17993 |
/* Note the insertion point if necessary. */ |
| 17994 |
if (mp->min_address < min_address) |
| 17995 |
{ |
| 17996 |
/* For now, we do not allow the insertion of 8-byte alignment |
| 17997 |
requiring nodes anywhere but at the start of the pool. */ |
| 17998 |
if (ARM_DOUBLEWORD_ALIGN |
| 17999 |
&& fix->fix_size >= 8 && mp->fix_size < 8) |
| 18000 |
return NULL; |
| 18001 |
else |
| 18002 |
min_mp = mp; |
| 18003 |
} |
| 18004 |
else if (mp->max_address |
| 18005 |
< minipool_barrier->address + mp->offset + fix->fix_size) |
| 18006 |
{ |
| 18007 |
/* Inserting before this entry would push the fix beyond |
| 18008 |
its maximum address (which can happen if we have |
| 18009 |
re-located a forwards fix); force the new fix to come |
| 18010 |
after it. */ |
| 18011 |
if (ARM_DOUBLEWORD_ALIGN |
| 18012 |
&& fix->fix_size >= 8 && mp->fix_size < 8) |
| 18013 |
return NULL; |
| 18014 |
else |
| 18015 |
{ |
| 18016 |
min_mp = mp; |
| 18017 |
min_address = mp->min_address + fix->fix_size; |
| 18018 |
} |
| 18019 |
} |
| 18020 |
/* Do not insert a non-8-byte aligned quantity before 8-byte |
| 18021 |
aligned quantities. */ |
| 18022 |
else if (ARM_DOUBLEWORD_ALIGN |
| 18023 |
&& fix->fix_size < 8 |
| 18024 |
&& mp->fix_size >= 8) |
| 18025 |
{ |
| 18026 |
min_mp = mp; |
| 18027 |
min_address = mp->min_address + fix->fix_size; |
| 18028 |
} |
| 18029 |
} |
| 18030 |
} |
| 18031 |
|
| 18032 |
/* We need to create a new entry. */ |
| 18033 |
mp = XNEW (Mnode); |
| 18034 |
mp->fix_size = fix->fix_size; |
| 18035 |
mp->mode = fix->mode; |
| 18036 |
mp->value = fix->value; |
| 18037 |
mp->refcount = 1; |
| 18038 |
mp->max_address = minipool_barrier->address + 65536; |
| 18039 |
|
| 18040 |
mp->min_address = min_address; |
| 18041 |
|
| 18042 |
if (min_mp == NULL) |
| 18043 |
{ |
| 18044 |
mp->prev = NULL; |
| 18045 |
mp->next = minipool_vector_head; |
| 18046 |
|
| 18047 |
if (mp->next == NULL) |
| 18048 |
{ |
| 18049 |
minipool_vector_tail = mp; |
| 18050 |
minipool_vector_label = gen_label_rtx (); |
| 18051 |
} |
| 18052 |
else |
| 18053 |
mp->next->prev = mp; |
| 18054 |
|
| 18055 |
minipool_vector_head = mp; |
| 18056 |
} |
| 18057 |
else |
| 18058 |
{ |
| 18059 |
mp->next = min_mp->next; |
| 18060 |
mp->prev = min_mp; |
| 18061 |
min_mp->next = mp; |
| 18062 |
|
| 18063 |
if (mp->next != NULL) |
| 18064 |
mp->next->prev = mp; |
| 18065 |
else |
| 18066 |
minipool_vector_tail = mp; |
| 18067 |
} |
| 18068 |
|
| 18069 |
/* Save the new entry. */ |
| 18070 |
min_mp = mp; |
| 18071 |
|
| 18072 |
if (mp->prev) |
| 18073 |
mp = mp->prev; |
| 18074 |
else |
| 18075 |
mp->offset = 0; |
| 18076 |
|
| 18077 |
/* Scan over the following entries and adjust their offsets. */ |
| 18078 |
while (mp->next != NULL) |
| 18079 |
{ |
| 18080 |
if (mp->next->min_address < mp->min_address + mp->fix_size) |
| 18081 |
mp->next->min_address = mp->min_address + mp->fix_size; |
| 18082 |
|
| 18083 |
if (mp->refcount) |
| 18084 |
mp->next->offset = mp->offset + mp->fix_size; |
| 18085 |
else |
| 18086 |
mp->next->offset = mp->offset; |
| 18087 |
|
| 18088 |
mp = mp->next; |
| 18089 |
} |
| 18090 |
|
| 18091 |
return min_mp; |
| 18092 |
} |
| 18093 |
|
| 18094 |
static void |
| 18095 |
assign_minipool_offsets (Mfix *barrier) |
| 18096 |
{ |
| 18097 |
HOST_WIDE_INT offset = 0; |
| 18098 |
Mnode *mp; |
| 18099 |
|
| 18100 |
minipool_barrier = barrier; |
| 18101 |
|
| 18102 |
for (mp = minipool_vector_head; mp != NULL; mp = mp->next) |
| 18103 |
{ |
| 18104 |
mp->offset = offset; |
| 18105 |
|
| 18106 |
if (mp->refcount > 0) |
| 18107 |
offset += mp->fix_size; |
| 18108 |
} |
| 18109 |
} |
| 18110 |
|
| 18111 |
/* Output the literal table */ |
| 18112 |
static void |
| 18113 |
dump_minipool (rtx_insn *scan) |
| 18114 |
{ |
| 18115 |
Mnode * mp; |
| 18116 |
Mnode * nmp; |
| 18117 |
int align64 = 0; |
| 18118 |
|
| 18119 |
if (ARM_DOUBLEWORD_ALIGN) |
| 18120 |
for (mp = minipool_vector_head; mp != NULL; mp = mp->next) |
| 18121 |
if (mp->refcount > 0 && mp->fix_size >= 8) |
| 18122 |
{ |
| 18123 |
align64 = 1; |
| 18124 |
break; |
| 18125 |
} |
| 18126 |
|
| 18127 |
if (dump_file) |
| 18128 |
fprintf (dump_file, |
| 18129 |
";; Emitting minipool after insn %u; address %ld; align %d (bytes)\n", |
| 18130 |
INSN_UID (scan), (unsigned long) minipool_barrier->address, align64 ? 8 : 4); |
| 18131 |
|
| 18132 |
scan = emit_label_after (gen_label_rtx (), scan); |
| 18133 |
scan = emit_insn_after (align64 ? gen_align_8 () : gen_align_4 (), scan); |
| 18134 |
scan = emit_label_after (minipool_vector_label, scan); |
| 18135 |
|
| 18136 |
for (mp = minipool_vector_head; mp != NULL; mp = nmp) |
| 18137 |
{ |
| 18138 |
if (mp->refcount > 0) |
| 18139 |
{ |
| 18140 |
if (dump_file) |
| 18141 |
{ |
| 18142 |
fprintf (dump_file, |
| 18143 |
";; Offset %u, min %ld, max %ld ", |
| 18144 |
(unsigned) mp->offset, (unsigned long) mp->min_address, |
| 18145 |
(unsigned long) mp->max_address); |
| 18146 |
arm_print_value (dump_file, mp->value); |
| 18147 |
fputc ('\n', dump_file); |
| 18148 |
} |
| 18149 |
|
| 18150 |
rtx val = copy_rtx (mp->value); |
| 18151 |
|
| 18152 |
switch (GET_MODE_SIZE (mp->mode)) |
| 18153 |
{ |
| 18154 |
#ifdef HAVE_consttable_1 |
| 18155 |
case 1: |
| 18156 |
scan = emit_insn_after (gen_consttable_1 (val), scan); |
| 18157 |
break; |
| 18158 |
|
| 18159 |
#endif |
| 18160 |
#ifdef HAVE_consttable_2 |
| 18161 |
case 2: |
| 18162 |
scan = emit_insn_after (gen_consttable_2 (val), scan); |
| 18163 |
break; |
| 18164 |
|
| 18165 |
#endif |
| 18166 |
#ifdef HAVE_consttable_4 |
| 18167 |
case 4: |
| 18168 |
scan = emit_insn_after (gen_consttable_4 (val), scan); |
| 18169 |
break; |
| 18170 |
|
| 18171 |
#endif |
| 18172 |
#ifdef HAVE_consttable_8 |
| 18173 |
case 8: |
| 18174 |
scan = emit_insn_after (gen_consttable_8 (val), scan); |
| 18175 |
break; |
| 18176 |
|
| 18177 |
#endif |
| 18178 |
#ifdef HAVE_consttable_16 |
| 18179 |
case 16: |
| 18180 |
scan = emit_insn_after (gen_consttable_16 (val), scan); |
| 18181 |
break; |
| 18182 |
|
| 18183 |
#endif |
| 18184 |
default: |
| 18185 |
gcc_unreachable (); |
| 18186 |
} |
| 18187 |
} |
| 18188 |
|
| 18189 |
nmp = mp->next; |
| 18190 |
free (mp); |
| 18191 |
} |
| 18192 |
|
| 18193 |
minipool_vector_head = minipool_vector_tail = NULL; |
| 18194 |
scan = emit_insn_after (gen_consttable_end (), scan); |
| 18195 |
scan = emit_barrier_after (scan); |
| 18196 |
} |
| 18197 |
|
| 18198 |
/* Return the cost of forcibly inserting a barrier after INSN. */ |
| 18199 |
static int |
| 18200 |
arm_barrier_cost (rtx_insn *insn) |
| 18201 |
{ |
| 18202 |
/* Basing the location of the pool on the loop depth is preferable, |
| 18203 |
but at the moment, the basic block information seems to be |
| 18204 |
corrupt by this stage of the compilation. */ |
| 18205 |
int base_cost = 50; |
| 18206 |
rtx_insn *next = next_nonnote_insn (insn); |
| 18207 |
|
| 18208 |
if (next != NULL && LABEL_P (next)) |
| 18209 |
base_cost -= 20; |
| 18210 |
|
| 18211 |
switch (GET_CODE (insn)) |
| 18212 |
{ |
| 18213 |
case CODE_LABEL: |
| 18214 |
/* It will always be better to place the table before the label, rather |
| 18215 |
than after it. */ |
| 18216 |
return 50; |
| 18217 |
|
| 18218 |
case INSN: |
| 18219 |
case CALL_INSN: |
| 18220 |
return base_cost; |
| 18221 |
|
| 18222 |
case JUMP_INSN: |
| 18223 |
return base_cost - 10; |
| 18224 |
|
| 18225 |
default: |
| 18226 |
return base_cost + 10; |
| 18227 |
} |
| 18228 |
} |
| 18229 |
|
| 18230 |
/* Find the best place in the insn stream in the range |
| 18231 |
(FIX->address,MAX_ADDRESS) to forcibly insert a minipool barrier. |
| 18232 |
Create the barrier by inserting a jump and add a new fix entry for |
| 18233 |
it. */ |
| 18234 |
static Mfix * |
| 18235 |
create_fix_barrier (Mfix *fix, HOST_WIDE_INT max_address) |
| 18236 |
{ |
| 18237 |
HOST_WIDE_INT count = 0; |
| 18238 |
rtx_barrier *barrier; |
| 18239 |
rtx_insn *from = fix->insn; |
| 18240 |
/* The instruction after which we will insert the jump. */ |
| 18241 |
rtx_insn *selected = NULL; |
| 18242 |
int selected_cost; |
| 18243 |
/* The address at which the jump instruction will be placed. */ |
| 18244 |
HOST_WIDE_INT selected_address; |
| 18245 |
Mfix * new_fix; |
| 18246 |
HOST_WIDE_INT max_count = max_address - fix->address; |
| 18247 |
rtx_code_label *label = gen_label_rtx (); |
| 18248 |
|
| 18249 |
selected_cost = arm_barrier_cost (from); |
| 18250 |
selected_address = fix->address; |
| 18251 |
|
| 18252 |
while (from && count < max_count) |
| 18253 |
{ |
| 18254 |
rtx_jump_table_data *tmp; |
| 18255 |
int new_cost; |
| 18256 |
|
| 18257 |
/* This code shouldn't have been called if there was a natural barrier |
| 18258 |
within range. */ |
| 18259 |
gcc_assert (!BARRIER_P (from)); |
| 18260 |
|
| 18261 |
/* Count the length of this insn. This must stay in sync with the |
| 18262 |
code that pushes minipool fixes. */ |
| 18263 |
if (LABEL_P (from)) |
| 18264 |
count += get_label_padding (from); |
| 18265 |
else |
| 18266 |
count += get_attr_length (from); |
| 18267 |
|
| 18268 |
/* If there is a jump table, add its length. */ |
| 18269 |
if (tablejump_p (from, NULL, &tmp)) |
| 18270 |
{ |
| 18271 |
count += get_jump_table_size (tmp); |
| 18272 |
|
| 18273 |
/* Jump tables aren't in a basic block, so base the cost on |
| 18274 |
the dispatch insn. If we select this location, we will |
| 18275 |
still put the pool after the table. */ |
| 18276 |
new_cost = arm_barrier_cost (from); |
| 18277 |
|
| 18278 |
if (count < max_count |
| 18279 |
&& (!selected || new_cost <= selected_cost)) |
| 18280 |
{ |
| 18281 |
selected = tmp; |
| 18282 |
selected_cost = new_cost; |
| 18283 |
selected_address = fix->address + count; |
| 18284 |
} |
| 18285 |
|
| 18286 |
/* Continue after the dispatch table. */ |
| 18287 |
from = NEXT_INSN (tmp); |
| 18288 |
continue; |
| 18289 |
} |
| 18290 |
|
| 18291 |
new_cost = arm_barrier_cost (from); |
| 18292 |
|
| 18293 |
if (count < max_count |
| 18294 |
&& (!selected || new_cost <= selected_cost)) |
| 18295 |
{ |
| 18296 |
selected = from; |
| 18297 |
selected_cost = new_cost; |
| 18298 |
selected_address = fix->address + count; |
| 18299 |
} |
| 18300 |
|
| 18301 |
from = NEXT_INSN (from); |
| 18302 |
} |
| 18303 |
|
| 18304 |
/* Make sure that we found a place to insert the jump. */ |
| 18305 |
gcc_assert (selected); |
| 18306 |
|
| 18307 |
/* Create a new JUMP_INSN that branches around a barrier. */ |
| 18308 |
from = emit_jump_insn_after (gen_jump (label), selected); |
| 18309 |
JUMP_LABEL (from) = label; |
| 18310 |
barrier = emit_barrier_after (from); |
| 18311 |
emit_label_after (label, barrier); |
| 18312 |
|
| 18313 |
/* Create a minipool barrier entry for the new barrier. */ |
| 18314 |
new_fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* new_fix)); |
| 18315 |
new_fix->insn = barrier; |
| 18316 |
new_fix->address = selected_address; |
| 18317 |
new_fix->next = fix->next; |
| 18318 |
fix->next = new_fix; |
| 18319 |
|
| 18320 |
return new_fix; |
| 18321 |
} |
| 18322 |
|
| 18323 |
/* Record that there is a natural barrier in the insn stream at |
| 18324 |
ADDRESS. */ |
| 18325 |
static void |
| 18326 |
push_minipool_barrier (rtx_insn *insn, HOST_WIDE_INT address) |
| 18327 |
{ |
| 18328 |
Mfix * fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* fix)); |
| 18329 |
|
| 18330 |
fix->insn = insn; |
| 18331 |
fix->address = address; |
| 18332 |
|
| 18333 |
fix->next = NULL; |
| 18334 |
if (minipool_fix_head != NULL) |
| 18335 |
minipool_fix_tail->next = fix; |
| 18336 |
else |
| 18337 |
minipool_fix_head = fix; |
| 18338 |
|
| 18339 |
minipool_fix_tail = fix; |
| 18340 |
} |
| 18341 |
|
| 18342 |
/* Record INSN, which will need fixing up to load a value from the |
| 18343 |
minipool. ADDRESS is the offset of the insn since the start of the |
| 18344 |
function; LOC is a pointer to the part of the insn which requires |
| 18345 |
fixing; VALUE is the constant that must be loaded, which is of type |
| 18346 |
MODE. */ |
| 18347 |
static void |
| 18348 |
push_minipool_fix (rtx_insn *insn, HOST_WIDE_INT address, rtx *loc, |
| 18349 |
machine_mode mode, rtx value) |
| 18350 |
{ |
| 18351 |
gcc_assert (!arm_disable_literal_pool); |
| 18352 |
Mfix * fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* fix)); |
| 18353 |
|
| 18354 |
fix->insn = insn; |
| 18355 |
fix->address = address; |
| 18356 |
fix->loc = loc; |
| 18357 |
fix->mode = mode; |
| 18358 |
fix->fix_size = MINIPOOL_FIX_SIZE (mode); |
| 18359 |
fix->value = value; |
| 18360 |
fix->forwards = get_attr_pool_range (insn); |
| 18361 |
fix->backwards = get_attr_neg_pool_range (insn); |
| 18362 |
fix->minipool = NULL; |
| 18363 |
|
| 18364 |
/* If an insn doesn't have a range defined for it, then it isn't |
| 18365 |
expecting to be reworked by this code. Better to stop now than |
| 18366 |
to generate duff assembly code. */ |
| 18367 |
gcc_assert (fix->forwards || fix->backwards); |
| 18368 |
|
| 18369 |
/* If an entry requires 8-byte alignment then assume all constant pools |
| 18370 |
require 4 bytes of padding. Trying to do this later on a per-pool |
| 18371 |
basis is awkward because existing pool entries have to be modified. */ |
| 18372 |
if (ARM_DOUBLEWORD_ALIGN && fix->fix_size >= 8) |
| 18373 |
minipool_pad = 4; |
| 18374 |
|
| 18375 |
if (dump_file) |
| 18376 |
{ |
| 18377 |
fprintf (dump_file, |
| 18378 |
";; %smode fixup for i%d; addr %lu, range (%ld,%ld): ", |
| 18379 |
GET_MODE_NAME (mode), |
| 18380 |
INSN_UID (insn), (unsigned long) address, |
| 18381 |
-1 * (long)fix->backwards, (long)fix->forwards); |
| 18382 |
arm_print_value (dump_file, fix->value); |
| 18383 |
fprintf (dump_file, "\n"); |
| 18384 |
} |
| 18385 |
|
| 18386 |
/* Add it to the chain of fixes. */ |
| 18387 |
fix->next = NULL; |
| 18388 |
|
| 18389 |
if (minipool_fix_head != NULL) |
| 18390 |
minipool_fix_tail->next = fix; |
| 18391 |
else |
| 18392 |
minipool_fix_head = fix; |
| 18393 |
|
| 18394 |
minipool_fix_tail = fix; |
| 18395 |
} |
| 18396 |
|
| 18397 |
/* Return maximum allowed cost of synthesizing a 64-bit constant VAL inline. |
| 18398 |
Returns the number of insns needed, or 99 if we always want to synthesize |
| 18399 |
the value. */ |
| 18400 |
int |
| 18401 |
arm_max_const_double_inline_cost () |
| 18402 |
{ |
| 18403 |
return ((optimize_size || arm_ld_sched) ? 3 : 4); |
| 18404 |
} |
| 18405 |
|
| 18406 |
/* Return the cost of synthesizing a 64-bit constant VAL inline. |
| 18407 |
Returns the number of insns needed, or 99 if we don't know how to |
| 18408 |
do it. */ |
| 18409 |
int |
| 18410 |
arm_const_double_inline_cost (rtx val) |
| 18411 |
{ |
| 18412 |
rtx lowpart, highpart; |
| 18413 |
machine_mode mode; |
| 18414 |
|
| 18415 |
mode = GET_MODE (val); |
| 18416 |
|
| 18417 |
if (mode == VOIDmode) |
| 18418 |
mode = DImode; |
| 18419 |
|
| 18420 |
gcc_assert (GET_MODE_SIZE (mode) == 8); |
| 18421 |
|
| 18422 |
lowpart = gen_lowpart (SImode, val); |
| 18423 |
highpart = gen_highpart_mode (SImode, mode, val); |
| 18424 |
|
| 18425 |
gcc_assert (CONST_INT_P (lowpart)); |
| 18426 |
gcc_assert (CONST_INT_P (highpart)); |
| 18427 |
|
| 18428 |
return (arm_gen_constant (SET, SImode, NULL_RTX, INTVAL (lowpart), |
| 18429 |
NULL_RTX, NULL_RTX, 0, 0) |
| 18430 |
+ arm_gen_constant (SET, SImode, NULL_RTX, INTVAL (highpart), |
| 18431 |
NULL_RTX, NULL_RTX, 0, 0)); |
| 18432 |
} |
| 18433 |
|
| 18434 |
/* Cost of loading a SImode constant. */ |
| 18435 |
static inline int |
| 18436 |
arm_const_inline_cost (enum rtx_code code, rtx val) |
| 18437 |
{ |
| 18438 |
return arm_gen_constant (code, SImode, NULL_RTX, INTVAL (val), |
| 18439 |
NULL_RTX, NULL_RTX, 1, 0); |
| 18440 |
} |
| 18441 |
|
| 18442 |
/* Return true if it is worthwhile to split a 64-bit constant into two |
| 18443 |
32-bit operations. This is the case if optimizing for size, or |
| 18444 |
if we have load delay slots, or if one 32-bit part can be done with |
| 18445 |
a single data operation. */ |
| 18446 |
bool |
| 18447 |
arm_const_double_by_parts (rtx val) |
| 18448 |
{ |
| 18449 |
machine_mode mode = GET_MODE (val); |
| 18450 |
rtx part; |
| 18451 |
|
| 18452 |
if (optimize_size || arm_ld_sched) |
| 18453 |
return true; |
| 18454 |
|
| 18455 |
if (mode == VOIDmode) |
| 18456 |
mode = DImode; |
| 18457 |
|
| 18458 |
part = gen_highpart_mode (SImode, mode, val); |
| 18459 |
|
| 18460 |
gcc_assert (CONST_INT_P (part)); |
| 18461 |
|
| 18462 |
if (const_ok_for_arm (INTVAL (part)) |
| 18463 |
|| const_ok_for_arm (~INTVAL (part))) |
| 18464 |
return true; |
| 18465 |
|
| 18466 |
part = gen_lowpart (SImode, val); |
| 18467 |
|
| 18468 |
gcc_assert (CONST_INT_P (part)); |
| 18469 |
|
| 18470 |
if (const_ok_for_arm (INTVAL (part)) |
| 18471 |
|| const_ok_for_arm (~INTVAL (part))) |
| 18472 |
return true; |
| 18473 |
|
| 18474 |
return false; |
| 18475 |
} |
| 18476 |
|
| 18477 |
/* Return true if it is possible to inline both the high and low parts |
| 18478 |
of a 64-bit constant into 32-bit data processing instructions. */ |
| 18479 |
bool |
| 18480 |
arm_const_double_by_immediates (rtx val) |
| 18481 |
{ |
| 18482 |
machine_mode mode = GET_MODE (val); |
| 18483 |
rtx part; |
| 18484 |
|
| 18485 |
if (mode == VOIDmode) |
| 18486 |
mode = DImode; |
| 18487 |
|
| 18488 |
part = gen_highpart_mode (SImode, mode, val); |
| 18489 |
|
| 18490 |
gcc_assert (CONST_INT_P (part)); |
| 18491 |
|
| 18492 |
if (!const_ok_for_arm (INTVAL (part))) |
| 18493 |
return false; |
| 18494 |
|
| 18495 |
part = gen_lowpart (SImode, val); |
| 18496 |
|
| 18497 |
gcc_assert (CONST_INT_P (part)); |
| 18498 |
|
| 18499 |
if (!const_ok_for_arm (INTVAL (part))) |
| 18500 |
return false; |
| 18501 |
|
| 18502 |
return true; |
| 18503 |
} |
| 18504 |
|
| 18505 |
/* Scan INSN and note any of its operands that need fixing. |
| 18506 |
If DO_PUSHES is false we do not actually push any of the fixups |
| 18507 |
needed. */ |
| 18508 |
static void |
| 18509 |
note_invalid_constants (rtx_insn *insn, HOST_WIDE_INT address, int do_pushes) |
| 18510 |
{ |
| 18511 |
int opno; |
| 18512 |
|
| 18513 |
extract_constrain_insn (insn); |
| 18514 |
|
| 18515 |
if (recog_data.n_alternatives == 0) |
| 18516 |
return; |
| 18517 |
|
| 18518 |
/* Fill in recog_op_alt with information about the constraints of |
| 18519 |
this insn. */ |
| 18520 |
preprocess_constraints (insn); |
| 18521 |
|
| 18522 |
const operand_alternative *op_alt = which_op_alt (); |
| 18523 |
for (opno = 0; opno < recog_data.n_operands; opno++) |
| 18524 |
{ |
| 18525 |
/* Things we need to fix can only occur in inputs. */ |
| 18526 |
if (recog_data.operand_type[opno] != OP_IN) |
| 18527 |
continue; |
| 18528 |
|
| 18529 |
/* If this alternative is a memory reference, then any mention |
| 18530 |
of constants in this alternative is really to fool reload |
| 18531 |
into allowing us to accept one there. We need to fix them up |
| 18532 |
now so that we output the right code. */ |
| 18533 |
if (op_alt[opno].memory_ok) |
| 18534 |
{ |
| 18535 |
rtx op = recog_data.operand[opno]; |
| 18536 |
|
| 18537 |
if (CONSTANT_P (op)) |
| 18538 |
{ |
| 18539 |
if (do_pushes) |
| 18540 |
push_minipool_fix (insn, address, recog_data.operand_loc[opno], |
| 18541 |
recog_data.operand_mode[opno], op); |
| 18542 |
} |
| 18543 |
else if (MEM_P (op) |
| 18544 |
&& GET_CODE (XEXP (op, 0)) == SYMBOL_REF |
| 18545 |
&& CONSTANT_POOL_ADDRESS_P (XEXP (op, 0))) |
| 18546 |
{ |
| 18547 |
if (do_pushes) |
| 18548 |
{ |
| 18549 |
rtx cop = avoid_constant_pool_reference (op); |
| 18550 |
|
| 18551 |
/* Casting the address of something to a mode narrower |
| 18552 |
than a word can cause avoid_constant_pool_reference() |
| 18553 |
to return the pool reference itself. That's no good to |
| 18554 |
us here. Lets just hope that we can use the |
| 18555 |
constant pool value directly. */ |
| 18556 |
if (op == cop) |
| 18557 |
cop = get_pool_constant (XEXP (op, 0)); |
| 18558 |
|
| 18559 |
push_minipool_fix (insn, address, |
| 18560 |
recog_data.operand_loc[opno], |
| 18561 |
recog_data.operand_mode[opno], cop); |
| 18562 |
} |
| 18563 |
|
| 18564 |
} |
| 18565 |
} |
| 18566 |
} |
| 18567 |
|
| 18568 |
return; |
| 18569 |
} |
| 18570 |
|
| 18571 |
/* This function computes the clear mask and PADDING_BITS_TO_CLEAR for structs |
| 18572 |
and unions in the context of ARMv8-M Security Extensions. It is used as a |
| 18573 |
helper function for both 'cmse_nonsecure_call' and 'cmse_nonsecure_entry' |
| 18574 |
functions. The PADDING_BITS_TO_CLEAR pointer can be the base to either one |
| 18575 |
or four masks, depending on whether it is being computed for a |
| 18576 |
'cmse_nonsecure_entry' return value or a 'cmse_nonsecure_call' argument |
| 18577 |
respectively. The tree for the type of the argument or a field within an |
| 18578 |
argument is passed in ARG_TYPE, the current register this argument or field |
| 18579 |
starts in is kept in the pointer REGNO and updated accordingly, the bit this |
| 18580 |
argument or field starts at is passed in STARTING_BIT and the last used bit |
| 18581 |
is kept in LAST_USED_BIT which is also updated accordingly. */ |
| 18582 |
|
| 18583 |
static unsigned HOST_WIDE_INT |
| 18584 |
comp_not_to_clear_mask_str_un (tree arg_type, int * regno, |
| 18585 |
uint32_t * padding_bits_to_clear, |
| 18586 |
unsigned starting_bit, int * last_used_bit) |
| 18587 |
|
| 18588 |
{ |
| 18589 |
unsigned HOST_WIDE_INT not_to_clear_reg_mask = 0; |
| 18590 |
|
| 18591 |
if (TREE_CODE (arg_type) == RECORD_TYPE) |
| 18592 |
{ |
| 18593 |
unsigned current_bit = starting_bit; |
| 18594 |
tree field; |
| 18595 |
long int offset, size; |
| 18596 |
|
| 18597 |
|
| 18598 |
field = TYPE_FIELDS (arg_type); |
| 18599 |
while (field) |
| 18600 |
{ |
| 18601 |
/* The offset within a structure is always an offset from |
| 18602 |
the start of that structure. Make sure we take that into the |
| 18603 |
calculation of the register based offset that we use here. */ |
| 18604 |
offset = starting_bit; |
| 18605 |
offset += TREE_INT_CST_ELT (DECL_FIELD_BIT_OFFSET (field), 0); |
| 18606 |
offset %= 32; |
| 18607 |
|
| 18608 |
/* This is the actual size of the field, for bitfields this is the |
| 18609 |
bitfield width and not the container size. */ |
| 18610 |
size = TREE_INT_CST_ELT (DECL_SIZE (field), 0); |
| 18611 |
|
| 18612 |
if (*last_used_bit != offset) |
| 18613 |
{ |
| 18614 |
/* We never clear padding bits in any other registers than the |
| 18615 |
first 4 GPRs. */ |
| 18616 |
gcc_assert (*regno < 4); |
| 18617 |
if (offset < *last_used_bit) |
| 18618 |
{ |
| 18619 |
/* This field's offset is before the 'last_used_bit', that |
| 18620 |
means this field goes on the next register. So we need to |
| 18621 |
pad the rest of the current register and increase the |
| 18622 |
register number. */ |
| 18623 |
uint32_t mask; |
| 18624 |
mask = ((uint32_t)-1) - ((uint32_t) 1 << *last_used_bit); |
| 18625 |
mask++; |
| 18626 |
|
| 18627 |
padding_bits_to_clear[*regno] |= mask; |
| 18628 |
not_to_clear_reg_mask |= HOST_WIDE_INT_1U << *regno; |
| 18629 |
(*regno)++; |
| 18630 |
} |
| 18631 |
else |
| 18632 |
{ |
| 18633 |
/* Otherwise we pad the bits between the last field's end and |
| 18634 |
the start of the new field. */ |
| 18635 |
uint32_t mask; |
| 18636 |
|
| 18637 |
mask = ((uint32_t)-1) >> (32 - offset); |
| 18638 |
mask -= ((uint32_t) 1 << *last_used_bit) - 1; |
| 18639 |
padding_bits_to_clear[*regno] |= mask; |
| 18640 |
} |
| 18641 |
current_bit = offset; |
| 18642 |
} |
| 18643 |
|
| 18644 |
/* Calculate further padding bits for inner structs/unions too. */ |
| 18645 |
if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))) |
| 18646 |
{ |
| 18647 |
*last_used_bit = current_bit; |
| 18648 |
not_to_clear_reg_mask |
| 18649 |
|= comp_not_to_clear_mask_str_un (TREE_TYPE (field), regno, |
| 18650 |
padding_bits_to_clear, offset, |
| 18651 |
last_used_bit); |
| 18652 |
} |
| 18653 |
else |
| 18654 |
{ |
| 18655 |
/* Update 'current_bit' with this field's size. If the |
| 18656 |
'current_bit' lies in a subsequent register, update 'regno' and |
| 18657 |
reset 'current_bit' to point to the current bit in that new |
| 18658 |
register. */ |
| 18659 |
current_bit += size; |
| 18660 |
while (current_bit >= 32) |
| 18661 |
{ |
| 18662 |
current_bit-=32; |
| 18663 |
not_to_clear_reg_mask |= HOST_WIDE_INT_1U << *regno; |
| 18664 |
(*regno)++; |
| 18665 |
} |
| 18666 |
*last_used_bit = current_bit; |
| 18667 |
} |
| 18668 |
|
| 18669 |
field = TREE_CHAIN (field); |
| 18670 |
} |
| 18671 |
not_to_clear_reg_mask |= HOST_WIDE_INT_1U << *regno; |
| 18672 |
} |
| 18673 |
else if (TREE_CODE (arg_type) == UNION_TYPE) |
| 18674 |
{ |
| 18675 |
tree field, field_t; |
| 18676 |
int i, regno_t, field_size; |
| 18677 |
int max_reg = -1; |
| 18678 |
int max_bit = -1; |
| 18679 |
uint32_t mask; |
| 18680 |
uint32_t padding_bits_to_clear_res[NUM_ARG_REGS] |
| 18681 |
= {-1, -1, -1, -1}; |
| 18682 |
|
| 18683 |
/* To compute the padding bits in a union we only consider bits as |
| 18684 |
padding bits if they are always either a padding bit or fall outside a |
| 18685 |
fields size for all fields in the union. */ |
| 18686 |
field = TYPE_FIELDS (arg_type); |
| 18687 |
while (field) |
| 18688 |
{ |
| 18689 |
uint32_t padding_bits_to_clear_t[NUM_ARG_REGS] |
| 18690 |
= {0U, 0U, 0U, 0U}; |
| 18691 |
int last_used_bit_t = *last_used_bit; |
| 18692 |
regno_t = *regno; |
| 18693 |
field_t = TREE_TYPE (field); |
| 18694 |
|
| 18695 |
/* If the field's type is either a record or a union make sure to |
| 18696 |
compute their padding bits too. */ |
| 18697 |
if (RECORD_OR_UNION_TYPE_P (field_t)) |
| 18698 |
not_to_clear_reg_mask |
| 18699 |
|= comp_not_to_clear_mask_str_un (field_t, ®no_t, |
| 18700 |
&padding_bits_to_clear_t[0], |
| 18701 |
starting_bit, &last_used_bit_t); |
| 18702 |
else |
| 18703 |
{ |
| 18704 |
field_size = TREE_INT_CST_ELT (DECL_SIZE (field), 0); |
| 18705 |
regno_t = (field_size / 32) + *regno; |
| 18706 |
last_used_bit_t = (starting_bit + field_size) % 32; |
| 18707 |
} |
| 18708 |
|
| 18709 |
/* We only clear padding bits in the first 4 GPRs. No need to check |
| 18710 |
regno_t, since there is no way where this field would have been |
| 18711 |
put into part GPR part FP reg. */ |
| 18712 |
if (*regno < 4) |
| 18713 |
{ |
| 18714 |
for (i = *regno; i < regno_t; i++) |
| 18715 |
{ |
| 18716 |
/* For all but the last register used by this field only keep |
| 18717 |
the padding bits that were padding bits in this field. */ |
| 18718 |
padding_bits_to_clear_res[i] &= padding_bits_to_clear_t[i]; |
| 18719 |
} |
| 18720 |
|
| 18721 |
/* For the last register, keep all padding bits that were padding |
| 18722 |
bits in this field and any padding bits that are still valid |
| 18723 |
as padding bits but fall outside of this field's size. */ |
| 18724 |
mask = (((uint32_t) -1) - ((uint32_t) 1 << last_used_bit_t)) + 1; |
| 18725 |
padding_bits_to_clear_res[regno_t] |
| 18726 |
&= padding_bits_to_clear_t[regno_t] | mask; |
| 18727 |
} |
| 18728 |
|
| 18729 |
/* Update the maximum size of the fields in terms of registers used |
| 18730 |
('max_reg') and the 'last_used_bit' in said register. */ |
| 18731 |
if (max_reg < regno_t) |
| 18732 |
{ |
| 18733 |
max_reg = regno_t; |
| 18734 |
max_bit = last_used_bit_t; |
| 18735 |
} |
| 18736 |
else if (max_reg == regno_t && max_bit < last_used_bit_t) |
| 18737 |
max_bit = last_used_bit_t; |
| 18738 |
|
| 18739 |
field = TREE_CHAIN (field); |
| 18740 |
} |
| 18741 |
|
| 18742 |
/* We only clear padding bits in the first 4 GPRs. No need to check |
| 18743 |
regno_t, since there is no way where this field would have been |
| 18744 |
put into part GPR part FP reg. */ |
| 18745 |
if (*regno < 4) |
| 18746 |
{ |
| 18747 |
/* Update the current padding_bits_to_clear using the intersection of the |
| 18748 |
padding bits of all the fields. */ |
| 18749 |
for (i=*regno; i < max_reg; i++) |
| 18750 |
padding_bits_to_clear[i] |= padding_bits_to_clear_res[i]; |
| 18751 |
|
| 18752 |
/* Do not keep trailing padding bits, we do not know yet whether this |
| 18753 |
is the end of the argument. */ |
| 18754 |
mask = ((uint32_t) 1 << max_bit) - 1; |
| 18755 |
padding_bits_to_clear[max_reg] |
| 18756 |
|= padding_bits_to_clear_res[max_reg] & mask; |
| 18757 |
} |
| 18758 |
|
| 18759 |
for (int i = *regno; i < max_reg; ++i) |
| 18760 |
not_to_clear_reg_mask |= HOST_WIDE_INT_1U << i; |
| 18761 |
|
| 18762 |
*regno = max_reg; |
| 18763 |
*last_used_bit = max_bit; |
| 18764 |
} |
| 18765 |
else |
| 18766 |
/* This function should only be used for structs and unions. */ |
| 18767 |
gcc_unreachable (); |
| 18768 |
|
| 18769 |
return not_to_clear_reg_mask; |
| 18770 |
} |
| 18771 |
|
| 18772 |
/* In the context of ARMv8-M Security Extensions, this function is used for both |
| 18773 |
'cmse_nonsecure_call' and 'cmse_nonsecure_entry' functions to compute what |
| 18774 |
registers are used when returning or passing arguments, which is then |
| 18775 |
returned as a mask. It will also compute a mask to indicate padding/unused |
| 18776 |
bits for each of these registers, and passes this through the |
| 18777 |
PADDING_BITS_TO_CLEAR pointer. The tree of the argument type is passed in |
| 18778 |
ARG_TYPE, the rtl representation of the argument is passed in ARG_RTX and |
| 18779 |
the starting register used to pass this argument or return value is passed |
| 18780 |
in REGNO. It makes use of 'comp_not_to_clear_mask_str_un' to compute these |
| 18781 |
for struct and union types. */ |
| 18782 |
|
| 18783 |
static unsigned HOST_WIDE_INT |
| 18784 |
compute_not_to_clear_mask (tree arg_type, rtx arg_rtx, int regno, |
| 18785 |
uint32_t * padding_bits_to_clear) |
| 18786 |
|
| 18787 |
{ |
| 18788 |
int last_used_bit = 0; |
| 18789 |
unsigned HOST_WIDE_INT not_to_clear_mask; |
| 18790 |
|
| 18791 |
if (RECORD_OR_UNION_TYPE_P (arg_type)) |
| 18792 |
{ |
| 18793 |
not_to_clear_mask |
| 18794 |
= comp_not_to_clear_mask_str_un (arg_type, ®no, |
| 18795 |
padding_bits_to_clear, 0, |
| 18796 |
&last_used_bit); |
| 18797 |
|
| 18798 |
|
| 18799 |
/* If the 'last_used_bit' is not zero, that means we are still using a |
| 18800 |
part of the last 'regno'. In such cases we must clear the trailing |
| 18801 |
bits. Otherwise we are not using regno and we should mark it as to |
| 18802 |
clear. We only clear padding bits for scalar values that are passed |
| 18803 |
in registers, so regno is never 4 or higher. */ |
| 18804 |
if (regno < 4 && last_used_bit != 0) |
| 18805 |
padding_bits_to_clear[regno] |
| 18806 |
|= ((uint32_t)-1) - ((uint32_t) 1 << last_used_bit) + 1; |
| 18807 |
else |
| 18808 |
not_to_clear_mask &= ~(HOST_WIDE_INT_1U << regno); |
| 18809 |
} |
| 18810 |
else |
| 18811 |
{ |
| 18812 |
not_to_clear_mask = 0; |
| 18813 |
/* We are not dealing with structs nor unions. So these arguments may be |
| 18814 |
passed in floating point registers too. In some cases a BLKmode is |
| 18815 |
used when returning or passing arguments in multiple VFP registers. */ |
| 18816 |
if (GET_MODE (arg_rtx) == BLKmode) |
| 18817 |
{ |
| 18818 |
int i, arg_regs; |
| 18819 |
rtx reg; |
| 18820 |
|
| 18821 |
/* This should really only occur when dealing with the hard-float |
| 18822 |
ABI. */ |
| 18823 |
gcc_assert (TARGET_HARD_FLOAT_ABI); |
| 18824 |
|
| 18825 |
for (i = 0; i < XVECLEN (arg_rtx, 0); i++) |
| 18826 |
{ |
| 18827 |
reg = XEXP (XVECEXP (arg_rtx, 0, i), 0); |
| 18828 |
gcc_assert (REG_P (reg)); |
| 18829 |
|
| 18830 |
not_to_clear_mask |= HOST_WIDE_INT_1U << REGNO (reg); |
| 18831 |
|
| 18832 |
/* If we are dealing with DF mode, make sure we don't |
| 18833 |
clear either of the registers it addresses. */ |
| 18834 |
arg_regs = ARM_NUM_REGS (GET_MODE (reg)); |
| 18835 |
if (arg_regs > 1) |
| 18836 |
{ |
| 18837 |
unsigned HOST_WIDE_INT mask; |
| 18838 |
mask = HOST_WIDE_INT_1U << (REGNO (reg) + arg_regs); |
| 18839 |
mask -= HOST_WIDE_INT_1U << REGNO (reg); |
| 18840 |
not_to_clear_mask |= mask; |
| 18841 |
} |
| 18842 |
} |
| 18843 |
} |
| 18844 |
else |
| 18845 |
{ |
| 18846 |
/* Otherwise we can rely on the MODE to determine how many registers |
| 18847 |
are being used by this argument. */ |
| 18848 |
int arg_regs = ARM_NUM_REGS (GET_MODE (arg_rtx)); |
| 18849 |
not_to_clear_mask |= HOST_WIDE_INT_1U << REGNO (arg_rtx); |
| 18850 |
if (arg_regs > 1) |
| 18851 |
{ |
| 18852 |
unsigned HOST_WIDE_INT |
| 18853 |
mask = HOST_WIDE_INT_1U << (REGNO (arg_rtx) + arg_regs); |
| 18854 |
mask -= HOST_WIDE_INT_1U << REGNO (arg_rtx); |
| 18855 |
not_to_clear_mask |= mask; |
| 18856 |
} |
| 18857 |
} |
| 18858 |
} |
| 18859 |
|
| 18860 |
return not_to_clear_mask; |
| 18861 |
} |
| 18862 |
|
| 18863 |
/* Clear registers secret before doing a cmse_nonsecure_call or returning from |
| 18864 |
a cmse_nonsecure_entry function. TO_CLEAR_BITMAP indicates which registers |
| 18865 |
are to be fully cleared, using the value in register CLEARING_REG if more |
| 18866 |
efficient. The PADDING_BITS_LEN entries array PADDING_BITS_TO_CLEAR gives |
| 18867 |
the bits that needs to be cleared in caller-saved core registers, with |
| 18868 |
SCRATCH_REG used as a scratch register for that clearing. |
| 18869 |
|
| 18870 |
NOTE: one of three following assertions must hold: |
| 18871 |
- SCRATCH_REG is a low register |
| 18872 |
- CLEARING_REG is in the set of registers fully cleared (ie. its bit is set |
| 18873 |
in TO_CLEAR_BITMAP) |
| 18874 |
- CLEARING_REG is a low register. */ |
| 18875 |
|
| 18876 |
static void |
| 18877 |
cmse_clear_registers (sbitmap to_clear_bitmap, uint32_t *padding_bits_to_clear, |
| 18878 |
int padding_bits_len, rtx scratch_reg, rtx clearing_reg) |
| 18879 |
{ |
| 18880 |
bool saved_clearing = false; |
| 18881 |
rtx saved_clearing_reg = NULL_RTX; |
| 18882 |
int i, regno, clearing_regno, minregno = R0_REGNUM, maxregno = minregno - 1; |
| 18883 |
|
| 18884 |
gcc_assert (arm_arch_cmse); |
| 18885 |
|
| 18886 |
if (!bitmap_empty_p (to_clear_bitmap)) |
| 18887 |
{ |
| 18888 |
minregno = bitmap_first_set_bit (to_clear_bitmap); |
| 18889 |
maxregno = bitmap_last_set_bit (to_clear_bitmap); |
| 18890 |
} |
| 18891 |
clearing_regno = REGNO (clearing_reg); |
| 18892 |
|
| 18893 |
/* Clear padding bits. */ |
| 18894 |
gcc_assert (padding_bits_len <= NUM_ARG_REGS); |
| 18895 |
for (i = 0, regno = R0_REGNUM; i < padding_bits_len; i++, regno++) |
| 18896 |
{ |
| 18897 |
uint64_t mask; |
| 18898 |
rtx rtx16, dest, cleared_reg = gen_rtx_REG (SImode, regno); |
| 18899 |
|
| 18900 |
if (padding_bits_to_clear[i] == 0) |
| 18901 |
continue; |
| 18902 |
|
| 18903 |
/* If this is a Thumb-1 target and SCRATCH_REG is not a low register, use |
| 18904 |
CLEARING_REG as scratch. */ |
| 18905 |
if (TARGET_THUMB1 |
| 18906 |
&& REGNO (scratch_reg) > LAST_LO_REGNUM) |
| 18907 |
{ |
| 18908 |
/* clearing_reg is not to be cleared, copy its value into scratch_reg |
| 18909 |
such that we can use clearing_reg to clear the unused bits in the |
| 18910 |
arguments. */ |
| 18911 |
if ((clearing_regno > maxregno |
| 18912 |
|| !bitmap_bit_p (to_clear_bitmap, clearing_regno)) |
| 18913 |
&& !saved_clearing) |
| 18914 |
{ |
| 18915 |
gcc_assert (clearing_regno <= LAST_LO_REGNUM); |
| 18916 |
emit_move_insn (scratch_reg, clearing_reg); |
| 18917 |
saved_clearing = true; |
| 18918 |
saved_clearing_reg = scratch_reg; |
| 18919 |
} |
| 18920 |
scratch_reg = clearing_reg; |
| 18921 |
} |
| 18922 |
|
| 18923 |
/* Fill the lower half of the negated padding_bits_to_clear[i]. */ |
| 18924 |
mask = (~padding_bits_to_clear[i]) & 0xFFFF; |
| 18925 |
emit_move_insn (scratch_reg, gen_int_mode (mask, SImode)); |
| 18926 |
|
| 18927 |
/* Fill the top half of the negated padding_bits_to_clear[i]. */ |
| 18928 |
mask = (~padding_bits_to_clear[i]) >> 16; |
| 18929 |
rtx16 = gen_int_mode (16, SImode); |
| 18930 |
dest = gen_rtx_ZERO_EXTRACT (SImode, scratch_reg, rtx16, rtx16); |
| 18931 |
if (mask) |
| 18932 |
emit_insn (gen_rtx_SET (dest, gen_int_mode (mask, SImode))); |
| 18933 |
|
| 18934 |
emit_insn (gen_andsi3 (cleared_reg, cleared_reg, scratch_reg)); |
| 18935 |
} |
| 18936 |
if (saved_clearing) |
| 18937 |
emit_move_insn (clearing_reg, saved_clearing_reg); |
| 18938 |
|
| 18939 |
|
| 18940 |
/* Clear full registers. */ |
| 18941 |
|
| 18942 |
if (TARGET_HAVE_FPCXT_CMSE) |
| 18943 |
{ |
| 18944 |
rtvec vunspec_vec; |
| 18945 |
int i, j, k, nb_regs; |
| 18946 |
rtx use_seq, par, reg, set, vunspec; |
| 18947 |
int to_clear_bitmap_size = SBITMAP_SIZE (to_clear_bitmap); |
| 18948 |
auto_sbitmap core_regs_bitmap (to_clear_bitmap_size); |
| 18949 |
auto_sbitmap to_clear_core_bitmap (to_clear_bitmap_size); |
| 18950 |
|
| 18951 |
for (i = FIRST_VFP_REGNUM; i <= maxregno; i += nb_regs) |
| 18952 |
{ |
| 18953 |
/* Find next register to clear and exit if none. */ |
| 18954 |
for (; i <= maxregno && !bitmap_bit_p (to_clear_bitmap, i); i++); |
| 18955 |
if (i > maxregno) |
| 18956 |
break; |
| 18957 |
|
| 18958 |
/* Compute number of consecutive registers to clear. */ |
| 18959 |
for (j = i; j <= maxregno && bitmap_bit_p (to_clear_bitmap, j); |
| 18960 |
j++); |
| 18961 |
nb_regs = j - i; |
| 18962 |
|
| 18963 |
/* Create VSCCLRM RTX pattern. */ |
| 18964 |
par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nb_regs + 1)); |
| 18965 |
vunspec_vec = gen_rtvec (1, gen_int_mode (0, SImode)); |
| 18966 |
vunspec = gen_rtx_UNSPEC_VOLATILE (SImode, vunspec_vec, |
| 18967 |
VUNSPEC_VSCCLRM_VPR); |
| 18968 |
XVECEXP (par, 0, 0) = vunspec; |
| 18969 |
|
| 18970 |
/* Insert VFP register clearing RTX in the pattern. */ |
| 18971 |
start_sequence (); |
| 18972 |
for (k = 1, j = i; j <= maxregno && k < nb_regs + 1; j++) |
| 18973 |
{ |
| 18974 |
if (!bitmap_bit_p (to_clear_bitmap, j)) |
| 18975 |
continue; |
| 18976 |
|
| 18977 |
reg = gen_rtx_REG (SFmode, j); |
| 18978 |
set = gen_rtx_SET (reg, const0_rtx); |
| 18979 |
XVECEXP (par, 0, k++) = set; |
| 18980 |
emit_use (reg); |
| 18981 |
} |
| 18982 |
use_seq = get_insns (); |
| 18983 |
end_sequence (); |
| 18984 |
|
| 18985 |
emit_insn_after (use_seq, emit_insn (par)); |
| 18986 |
} |
| 18987 |
|
| 18988 |
/* Get set of core registers to clear. */ |
| 18989 |
bitmap_clear (core_regs_bitmap); |
| 18990 |
bitmap_set_range (core_regs_bitmap, R0_REGNUM, |
| 18991 |
IP_REGNUM - R0_REGNUM + 1); |
| 18992 |
bitmap_and (to_clear_core_bitmap, to_clear_bitmap, |
| 18993 |
core_regs_bitmap); |
| 18994 |
gcc_assert (!bitmap_empty_p (to_clear_core_bitmap)); |
| 18995 |
|
| 18996 |
if (bitmap_empty_p (to_clear_core_bitmap)) |
| 18997 |
return; |
| 18998 |
|
| 18999 |
/* Create clrm RTX pattern. */ |
| 19000 |
nb_regs = bitmap_count_bits (to_clear_core_bitmap); |
| 19001 |
par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nb_regs + 2)); |
| 19002 |
|
| 19003 |
/* Insert core register clearing RTX in the pattern. */ |
| 19004 |
start_sequence (); |
| 19005 |
for (j = 0, i = minregno; j < nb_regs; i++) |
| 19006 |
{ |
| 19007 |
if (!bitmap_bit_p (to_clear_core_bitmap, i)) |
| 19008 |
continue; |
| 19009 |
|
| 19010 |
reg = gen_rtx_REG (SImode, i); |
| 19011 |
set = gen_rtx_SET (reg, const0_rtx); |
| 19012 |
XVECEXP (par, 0, j++) = set; |
| 19013 |
emit_use (reg); |
| 19014 |
} |
| 19015 |
|
| 19016 |
/* Insert APSR register clearing RTX in the pattern |
| 19017 |
* along with clobbering CC. */ |
| 19018 |
vunspec_vec = gen_rtvec (1, gen_int_mode (0, SImode)); |
| 19019 |
vunspec = gen_rtx_UNSPEC_VOLATILE (SImode, vunspec_vec, |
| 19020 |
VUNSPEC_CLRM_APSR); |
| 19021 |
|
| 19022 |
XVECEXP (par, 0, j++) = vunspec; |
| 19023 |
|
| 19024 |
rtx ccreg = gen_rtx_REG (CCmode, CC_REGNUM); |
| 19025 |
rtx clobber = gen_rtx_CLOBBER (VOIDmode, ccreg); |
| 19026 |
XVECEXP (par, 0, j) = clobber; |
| 19027 |
|
| 19028 |
use_seq = get_insns (); |
| 19029 |
end_sequence (); |
| 19030 |
|
| 19031 |
emit_insn_after (use_seq, emit_insn (par)); |
| 19032 |
} |
| 19033 |
else |
| 19034 |
{ |
| 19035 |
/* If not marked for clearing, clearing_reg already does not contain |
| 19036 |
any secret. */ |
| 19037 |
if (clearing_regno <= maxregno |
| 19038 |
&& bitmap_bit_p (to_clear_bitmap, clearing_regno)) |
| 19039 |
{ |
| 19040 |
emit_move_insn (clearing_reg, const0_rtx); |
| 19041 |
emit_use (clearing_reg); |
| 19042 |
bitmap_clear_bit (to_clear_bitmap, clearing_regno); |
| 19043 |
} |
| 19044 |
|
| 19045 |
for (regno = minregno; regno <= maxregno; regno++) |
| 19046 |
{ |
| 19047 |
if (!bitmap_bit_p (to_clear_bitmap, regno)) |
| 19048 |
continue; |
| 19049 |
|
| 19050 |
if (IS_VFP_REGNUM (regno)) |
| 19051 |
{ |
| 19052 |
/* If regno is an even vfp register and its successor is also to |
| 19053 |
be cleared, use vmov. */ |
| 19054 |
if (TARGET_VFP_DOUBLE |
| 19055 |
&& VFP_REGNO_OK_FOR_DOUBLE (regno) |
| 19056 |
&& bitmap_bit_p (to_clear_bitmap, regno + 1)) |
| 19057 |
{ |
| 19058 |
emit_move_insn (gen_rtx_REG (DFmode, regno), |
| 19059 |
CONST1_RTX (DFmode)); |
| 19060 |
emit_use (gen_rtx_REG (DFmode, regno)); |
| 19061 |
regno++; |
| 19062 |
} |
| 19063 |
else |
| 19064 |
{ |
| 19065 |
emit_move_insn (gen_rtx_REG (SFmode, regno), |
| 19066 |
CONST1_RTX (SFmode)); |
| 19067 |
emit_use (gen_rtx_REG (SFmode, regno)); |
| 19068 |
} |
| 19069 |
} |
| 19070 |
else |
| 19071 |
{ |
| 19072 |
emit_move_insn (gen_rtx_REG (SImode, regno), clearing_reg); |
| 19073 |
emit_use (gen_rtx_REG (SImode, regno)); |
| 19074 |
} |
| 19075 |
} |
| 19076 |
} |
| 19077 |
} |
| 19078 |
|
| 19079 |
/* Clear core and caller-saved VFP registers not used to pass arguments before |
| 19080 |
a cmse_nonsecure_call. Saving, clearing and restoring of VFP callee-saved |
| 19081 |
registers is done in the __gnu_cmse_nonsecure_call libcall. See |
| 19082 |
libgcc/config/arm/cmse_nonsecure_call.S. */ |
| 19083 |
|
| 19084 |
static void |
| 19085 |
cmse_nonsecure_call_inline_register_clear (void) |
| 19086 |
{ |
| 19087 |
basic_block bb; |
| 19088 |
|
| 19089 |
FOR_EACH_BB_FN (bb, cfun) |
| 19090 |
{ |
| 19091 |
rtx_insn *insn; |
| 19092 |
|
| 19093 |
FOR_BB_INSNS (bb, insn) |
| 19094 |
{ |
| 19095 |
bool clear_callee_saved = TARGET_HAVE_FPCXT_CMSE; |
| 19096 |
/* frame = VFP regs + FPSCR + VPR. */ |
| 19097 |
unsigned lazy_store_stack_frame_size |
| 19098 |
= (LAST_VFP_REGNUM - FIRST_VFP_REGNUM + 1 + 2) * UNITS_PER_WORD; |
| 19099 |
unsigned long callee_saved_mask |
| 19100 |
= ((1 << (LAST_HI_REGNUM + 1)) - 1) |
| 19101 |
& ~((1 << (LAST_ARG_REGNUM + 1)) - 1); |
| 19102 |
unsigned address_regnum, regno; |
| 19103 |
unsigned max_int_regno |
| 19104 |
= clear_callee_saved ? IP_REGNUM : LAST_ARG_REGNUM; |
| 19105 |
unsigned max_fp_regno |
| 19106 |
= TARGET_HAVE_FPCXT_CMSE ? LAST_VFP_REGNUM : D7_VFP_REGNUM; |
| 19107 |
unsigned maxregno |
| 19108 |
= TARGET_HARD_FLOAT_ABI ? max_fp_regno : max_int_regno; |
| 19109 |
auto_sbitmap to_clear_bitmap (maxregno + 1); |
| 19110 |
rtx_insn *seq; |
| 19111 |
rtx pat, call, unspec, clearing_reg, ip_reg, shift; |
| 19112 |
rtx address; |
| 19113 |
CUMULATIVE_ARGS args_so_far_v; |
| 19114 |
cumulative_args_t args_so_far; |
| 19115 |
tree arg_type, fntype; |
| 19116 |
bool first_param = true, lazy_fpclear = !TARGET_HARD_FLOAT_ABI; |
| 19117 |
function_args_iterator args_iter; |
| 19118 |
uint32_t padding_bits_to_clear[4] = {0U, 0U, 0U, 0U}; |
| 19119 |
|
| 19120 |
if (!NONDEBUG_INSN_P (insn)) |
| 19121 |
continue; |
| 19122 |
|
| 19123 |
if (!CALL_P (insn)) |
| 19124 |
continue; |
| 19125 |
|
| 19126 |
pat = PATTERN (insn); |
| 19127 |
gcc_assert (GET_CODE (pat) == PARALLEL && XVECLEN (pat, 0) > 0); |
| 19128 |
call = XVECEXP (pat, 0, 0); |
| 19129 |
|
| 19130 |
/* Get the real call RTX if the insn sets a value, ie. returns. */ |
| 19131 |
if (GET_CODE (call) == SET) |
| 19132 |
call = SET_SRC (call); |
| 19133 |
|
| 19134 |
/* Check if it is a cmse_nonsecure_call. */ |
| 19135 |
unspec = XEXP (call, 0); |
| 19136 |
if (GET_CODE (unspec) != UNSPEC |
| 19137 |
|| XINT (unspec, 1) != UNSPEC_NONSECURE_MEM) |
| 19138 |
continue; |
| 19139 |
|
| 19140 |
/* Mark registers that needs to be cleared. Those that holds a |
| 19141 |
parameter are removed from the set further below. */ |
| 19142 |
bitmap_clear (to_clear_bitmap); |
| 19143 |
bitmap_set_range (to_clear_bitmap, R0_REGNUM, |
| 19144 |
max_int_regno - R0_REGNUM + 1); |
| 19145 |
|
| 19146 |
/* Only look at the caller-saved floating point registers in case of |
| 19147 |
-mfloat-abi=hard. For -mfloat-abi=softfp we will be using the |
| 19148 |
lazy store and loads which clear both caller- and callee-saved |
| 19149 |
registers. */ |
| 19150 |
if (!lazy_fpclear) |
| 19151 |
{ |
| 19152 |
auto_sbitmap float_bitmap (maxregno + 1); |
| 19153 |
|
| 19154 |
bitmap_clear (float_bitmap); |
| 19155 |
bitmap_set_range (float_bitmap, FIRST_VFP_REGNUM, |
| 19156 |
max_fp_regno - FIRST_VFP_REGNUM + 1); |
| 19157 |
bitmap_ior (to_clear_bitmap, to_clear_bitmap, float_bitmap); |
| 19158 |
} |
| 19159 |
|
| 19160 |
/* Make sure the register used to hold the function address is not |
| 19161 |
cleared. */ |
| 19162 |
address = RTVEC_ELT (XVEC (unspec, 0), 0); |
| 19163 |
gcc_assert (MEM_P (address)); |
| 19164 |
gcc_assert (REG_P (XEXP (address, 0))); |
| 19165 |
address_regnum = REGNO (XEXP (address, 0)); |
| 19166 |
if (address_regnum <= max_int_regno) |
| 19167 |
bitmap_clear_bit (to_clear_bitmap, address_regnum); |
| 19168 |
|
| 19169 |
/* Set basic block of call insn so that df rescan is performed on |
| 19170 |
insns inserted here. */ |
| 19171 |
set_block_for_insn (insn, bb); |
| 19172 |
df_set_flags (DF_DEFER_INSN_RESCAN); |
| 19173 |
start_sequence (); |
| 19174 |
|
| 19175 |
/* Make sure the scheduler doesn't schedule other insns beyond |
| 19176 |
here. */ |
| 19177 |
emit_insn (gen_blockage ()); |
| 19178 |
|
| 19179 |
/* Walk through all arguments and clear registers appropriately. |
| 19180 |
*/ |
| 19181 |
fntype = TREE_TYPE (MEM_EXPR (address)); |
| 19182 |
arm_init_cumulative_args (&args_so_far_v, fntype, NULL_RTX, |
| 19183 |
NULL_TREE); |
| 19184 |
args_so_far = pack_cumulative_args (&args_so_far_v); |
| 19185 |
FOREACH_FUNCTION_ARGS (fntype, arg_type, args_iter) |
| 19186 |
{ |
| 19187 |
rtx arg_rtx; |
| 19188 |
uint64_t to_clear_args_mask; |
| 19189 |
|
| 19190 |
if (VOID_TYPE_P (arg_type)) |
| 19191 |
continue; |
| 19192 |
|
| 19193 |
function_arg_info arg (arg_type, /*named=*/true); |
| 19194 |
if (!first_param) |
| 19195 |
/* ??? We should advance after processing the argument and pass |
| 19196 |
the argument we're advancing past. */ |
| 19197 |
arm_function_arg_advance (args_so_far, arg); |
| 19198 |
|
| 19199 |
arg_rtx = arm_function_arg (args_so_far, arg); |
| 19200 |
gcc_assert (REG_P (arg_rtx)); |
| 19201 |
to_clear_args_mask |
| 19202 |
= compute_not_to_clear_mask (arg_type, arg_rtx, |
| 19203 |
REGNO (arg_rtx), |
| 19204 |
&padding_bits_to_clear[0]); |
| 19205 |
if (to_clear_args_mask) |
| 19206 |
{ |
| 19207 |
for (regno = R0_REGNUM; regno <= maxregno; regno++) |
| 19208 |
{ |
| 19209 |
if (to_clear_args_mask & (1ULL << regno)) |
| 19210 |
bitmap_clear_bit (to_clear_bitmap, regno); |
| 19211 |
} |
| 19212 |
} |
| 19213 |
|
| 19214 |
first_param = false; |
| 19215 |
} |
| 19216 |
|
| 19217 |
/* We use right shift and left shift to clear the LSB of the address |
| 19218 |
we jump to instead of using bic, to avoid having to use an extra |
| 19219 |
register on Thumb-1. */ |
| 19220 |
clearing_reg = XEXP (address, 0); |
| 19221 |
shift = gen_rtx_LSHIFTRT (SImode, clearing_reg, const1_rtx); |
| 19222 |
emit_insn (gen_rtx_SET (clearing_reg, shift)); |
| 19223 |
shift = gen_rtx_ASHIFT (SImode, clearing_reg, const1_rtx); |
| 19224 |
emit_insn (gen_rtx_SET (clearing_reg, shift)); |
| 19225 |
|
| 19226 |
if (clear_callee_saved) |
| 19227 |
{ |
| 19228 |
rtx push_insn = |
| 19229 |
emit_multi_reg_push (callee_saved_mask, callee_saved_mask); |
| 19230 |
/* Disable frame debug info in push because it needs to be |
| 19231 |
disabled for pop (see below). */ |
| 19232 |
RTX_FRAME_RELATED_P (push_insn) = 0; |
| 19233 |
|
| 19234 |
/* Lazy store multiple. */ |
| 19235 |
if (lazy_fpclear) |
| 19236 |
{ |
| 19237 |
rtx imm; |
| 19238 |
rtx_insn *add_insn; |
| 19239 |
|
| 19240 |
imm = gen_int_mode (- lazy_store_stack_frame_size, SImode); |
| 19241 |
add_insn = emit_insn (gen_addsi3 (stack_pointer_rtx, |
| 19242 |
stack_pointer_rtx, imm)); |
| 19243 |
/* If we have the frame pointer, then it will be the |
| 19244 |
CFA reg. Otherwise, the stack pointer is the CFA |
| 19245 |
reg, so we need to emit a CFA adjust. */ |
| 19246 |
if (!frame_pointer_needed) |
| 19247 |
arm_add_cfa_adjust_cfa_note (add_insn, |
| 19248 |
- lazy_store_stack_frame_size, |
| 19249 |
stack_pointer_rtx, |
| 19250 |
stack_pointer_rtx); |
| 19251 |
emit_insn (gen_lazy_store_multiple_insn (stack_pointer_rtx)); |
| 19252 |
} |
| 19253 |
/* Save VFP callee-saved registers. */ |
| 19254 |
else |
| 19255 |
{ |
| 19256 |
vfp_emit_fstmd (D7_VFP_REGNUM + 1, |
| 19257 |
(max_fp_regno - D7_VFP_REGNUM) / 2); |
| 19258 |
/* Disable frame debug info in push because it needs to be |
| 19259 |
disabled for vpop (see below). */ |
| 19260 |
RTX_FRAME_RELATED_P (get_last_insn ()) = 0; |
| 19261 |
} |
| 19262 |
} |
| 19263 |
|
| 19264 |
/* Clear caller-saved registers that leak before doing a non-secure |
| 19265 |
call. */ |
| 19266 |
ip_reg = gen_rtx_REG (SImode, IP_REGNUM); |
| 19267 |
cmse_clear_registers (to_clear_bitmap, padding_bits_to_clear, |
| 19268 |
NUM_ARG_REGS, ip_reg, clearing_reg); |
| 19269 |
|
| 19270 |
seq = get_insns (); |
| 19271 |
end_sequence (); |
| 19272 |
emit_insn_before (seq, insn); |
| 19273 |
|
| 19274 |
/* The AAPCS requires the callee to widen integral types narrower |
| 19275 |
than 32 bits to the full width of the register; but when handling |
| 19276 |
calls to non-secure space, we cannot trust the callee to have |
| 19277 |
correctly done so. So forcibly re-widen the result here. */ |
| 19278 |
tree ret_type = TREE_TYPE (fntype); |
| 19279 |
if ((TREE_CODE (ret_type) == INTEGER_TYPE |
| 19280 |
|| TREE_CODE (ret_type) == ENUMERAL_TYPE |
| 19281 |
|| TREE_CODE (ret_type) == BOOLEAN_TYPE) |
| 19282 |
&& known_lt (GET_MODE_SIZE (TYPE_MODE (ret_type)), 4)) |
| 19283 |
{ |
| 19284 |
rtx ret_reg = gen_rtx_REG (TYPE_MODE (ret_type), R0_REGNUM); |
| 19285 |
rtx si_reg = gen_rtx_REG (SImode, R0_REGNUM); |
| 19286 |
rtx extend; |
| 19287 |
if (TYPE_UNSIGNED (ret_type)) |
| 19288 |
extend = gen_rtx_SET (si_reg, gen_rtx_ZERO_EXTEND (SImode, |
| 19289 |
ret_reg)); |
| 19290 |
else |
| 19291 |
{ |
| 19292 |
/* Signed-extension is a special case because of |
| 19293 |
thumb1_extendhisi2. */ |
| 19294 |
if (TARGET_THUMB1 |
| 19295 |
&& known_eq (GET_MODE_SIZE (TYPE_MODE (ret_type)), 2)) |
| 19296 |
extend = gen_thumb1_extendhisi2 (si_reg, ret_reg); |
| 19297 |
else |
| 19298 |
extend = gen_rtx_SET (si_reg, |
| 19299 |
gen_rtx_SIGN_EXTEND (SImode, |
| 19300 |
ret_reg)); |
| 19301 |
} |
| 19302 |
emit_insn_after (extend, insn); |
| 19303 |
} |
| 19304 |
|
| 19305 |
|
| 19306 |
if (TARGET_HAVE_FPCXT_CMSE) |
| 19307 |
{ |
| 19308 |
rtx_insn *last, *pop_insn, *after = insn; |
| 19309 |
|
| 19310 |
start_sequence (); |
| 19311 |
|
| 19312 |
/* Lazy load multiple done as part of libcall in Armv8-M. */ |
| 19313 |
if (lazy_fpclear) |
| 19314 |
{ |
| 19315 |
rtx imm = gen_int_mode (lazy_store_stack_frame_size, SImode); |
| 19316 |
emit_insn (gen_lazy_load_multiple_insn (stack_pointer_rtx)); |
| 19317 |
rtx_insn *add_insn = |
| 19318 |
emit_insn (gen_addsi3 (stack_pointer_rtx, |
| 19319 |
stack_pointer_rtx, imm)); |
| 19320 |
if (!frame_pointer_needed) |
| 19321 |
arm_add_cfa_adjust_cfa_note (add_insn, |
| 19322 |
lazy_store_stack_frame_size, |
| 19323 |
stack_pointer_rtx, |
| 19324 |
stack_pointer_rtx); |
| 19325 |
} |
| 19326 |
/* Restore VFP callee-saved registers. */ |
| 19327 |
else |
| 19328 |
{ |
| 19329 |
int nb_callee_saved_vfp_regs = |
| 19330 |
(max_fp_regno - D7_VFP_REGNUM) / 2; |
| 19331 |
arm_emit_vfp_multi_reg_pop (D7_VFP_REGNUM + 1, |
| 19332 |
nb_callee_saved_vfp_regs, |
| 19333 |
stack_pointer_rtx); |
| 19334 |
/* Disable frame debug info in vpop because the SP adjustment |
| 19335 |
is made using a CFA adjustment note while CFA used is |
| 19336 |
sometimes R7. This then causes an assert failure in the |
| 19337 |
CFI note creation code. */ |
| 19338 |
RTX_FRAME_RELATED_P (get_last_insn ()) = 0; |
| 19339 |
} |
| 19340 |
|
| 19341 |
arm_emit_multi_reg_pop (callee_saved_mask); |
| 19342 |
pop_insn = get_last_insn (); |
| 19343 |
|
| 19344 |
/* Disable frame debug info in pop because they reset the state |
| 19345 |
of popped registers to what it was at the beginning of the |
| 19346 |
function, before the prologue. This leads to incorrect state |
| 19347 |
when doing the pop after the nonsecure call for registers that |
| 19348 |
are pushed both in prologue and before the nonsecure call. |
| 19349 |
|
| 19350 |
It also occasionally triggers an assert failure in CFI note |
| 19351 |
creation code when there are two codepaths to the epilogue, |
| 19352 |
one of which does not go through the nonsecure call. |
| 19353 |
Obviously this mean that debugging between the push and pop is |
| 19354 |
not reliable. */ |
| 19355 |
RTX_FRAME_RELATED_P (pop_insn) = 0; |
| 19356 |
|
| 19357 |
seq = get_insns (); |
| 19358 |
last = get_last_insn (); |
| 19359 |
end_sequence (); |
| 19360 |
|
| 19361 |
emit_insn_after (seq, after); |
| 19362 |
|
| 19363 |
/* Skip pop we have just inserted after nonsecure call, we know |
| 19364 |
it does not contain a nonsecure call. */ |
| 19365 |
insn = last; |
| 19366 |
} |
| 19367 |
} |
| 19368 |
} |
| 19369 |
} |
| 19370 |
|
| 19371 |
/* Rewrite move insn into subtract of 0 if the condition codes will |
| 19372 |
be useful in next conditional jump insn. */ |
| 19373 |
|
| 19374 |
static void |
| 19375 |
thumb1_reorg (void) |
| 19376 |
{ |
| 19377 |
basic_block bb; |
| 19378 |
|
| 19379 |
FOR_EACH_BB_FN (bb, cfun) |
| 19380 |
{ |
| 19381 |
rtx dest, src; |
| 19382 |
rtx cmp, op0, op1, set = NULL; |
| 19383 |
rtx_insn *prev, *insn = BB_END (bb); |
| 19384 |
bool insn_clobbered = false; |
| 19385 |
|
| 19386 |
while (insn != BB_HEAD (bb) && !NONDEBUG_INSN_P (insn)) |
| 19387 |
insn = PREV_INSN (insn); |
| 19388 |
|
| 19389 |
/* Find the last cbranchsi4_insn in basic block BB. */ |
| 19390 |
if (insn == BB_HEAD (bb) |
| 19391 |
|| INSN_CODE (insn) != CODE_FOR_cbranchsi4_insn) |
| 19392 |
continue; |
| 19393 |
|
| 19394 |
/* Get the register with which we are comparing. */ |
| 19395 |
cmp = XEXP (SET_SRC (PATTERN (insn)), 0); |
| 19396 |
op0 = XEXP (cmp, 0); |
| 19397 |
op1 = XEXP (cmp, 1); |
| 19398 |
|
| 19399 |
/* Check that comparison is against ZERO. */ |
| 19400 |
if (!CONST_INT_P (op1) || INTVAL (op1) != 0) |
| 19401 |
continue; |
| 19402 |
|
| 19403 |
/* Find the first flag setting insn before INSN in basic block BB. */ |
| 19404 |
gcc_assert (insn != BB_HEAD (bb)); |
| 19405 |
for (prev = PREV_INSN (insn); |
| 19406 |
(!insn_clobbered |
| 19407 |
&& prev != BB_HEAD (bb) |
| 19408 |
&& (NOTE_P (prev) |
| 19409 |
|| DEBUG_INSN_P (prev) |
| 19410 |
|| ((set = single_set (prev)) != NULL |
| 19411 |
&& get_attr_conds (prev) == CONDS_NOCOND))); |
| 19412 |
prev = PREV_INSN (prev)) |
| 19413 |
{ |
| 19414 |
if (reg_set_p (op0, prev)) |
| 19415 |
insn_clobbered = true; |
| 19416 |
} |
| 19417 |
|
| 19418 |
/* Skip if op0 is clobbered by insn other than prev. */ |
| 19419 |
if (insn_clobbered) |
| 19420 |
continue; |
| 19421 |
|
| 19422 |
if (!set) |
| 19423 |
continue; |
| 19424 |
|
| 19425 |
dest = SET_DEST (set); |
| 19426 |
src = SET_SRC (set); |
| 19427 |
if (!low_register_operand (dest, SImode) |
| 19428 |
|| !low_register_operand (src, SImode)) |
| 19429 |
continue; |
| 19430 |
|
| 19431 |
/* Rewrite move into subtract of 0 if its operand is compared with ZERO |
| 19432 |
in INSN. Both src and dest of the move insn are checked. */ |
| 19433 |
if (REGNO (op0) == REGNO (src) || REGNO (op0) == REGNO (dest)) |
| 19434 |
{ |
| 19435 |
dest = copy_rtx (dest); |
| 19436 |
src = copy_rtx (src); |
| 19437 |
src = gen_rtx_MINUS (SImode, src, const0_rtx); |
| 19438 |
PATTERN (prev) = gen_rtx_SET (dest, src); |
| 19439 |
INSN_CODE (prev) = -1; |
| 19440 |
/* Set test register in INSN to dest. */ |
| 19441 |
XEXP (cmp, 0) = copy_rtx (dest); |
| 19442 |
INSN_CODE (insn) = -1; |
| 19443 |
} |
| 19444 |
} |
| 19445 |
} |
| 19446 |
|
| 19447 |
/* Convert instructions to their cc-clobbering variant if possible, since |
| 19448 |
that allows us to use smaller encodings. */ |
| 19449 |
|
| 19450 |
static void |
| 19451 |
thumb2_reorg (void) |
| 19452 |
{ |
| 19453 |
basic_block bb; |
| 19454 |
regset_head live; |
| 19455 |
|
| 19456 |
INIT_REG_SET (&live); |
| 19457 |
|
| 19458 |
/* We are freeing block_for_insn in the toplev to keep compatibility |
| 19459 |
with old MDEP_REORGS that are not CFG based. Recompute it now. */ |
| 19460 |
compute_bb_for_insn (); |
| 19461 |
df_analyze (); |
| 19462 |
|
| 19463 |
enum Convert_Action {SKIP, CONV, SWAP_CONV}; |
| 19464 |
|
| 19465 |
FOR_EACH_BB_FN (bb, cfun) |
| 19466 |
{ |
| 19467 |
if ((current_tune->disparage_flag_setting_t16_encodings |
| 19468 |
== tune_params::DISPARAGE_FLAGS_ALL) |
| 19469 |
&& optimize_bb_for_speed_p (bb)) |
| 19470 |
continue; |
| 19471 |
|
| 19472 |
rtx_insn *insn; |
| 19473 |
Convert_Action action = SKIP; |
| 19474 |
Convert_Action action_for_partial_flag_setting |
| 19475 |
= ((current_tune->disparage_flag_setting_t16_encodings |
| 19476 |
!= tune_params::DISPARAGE_FLAGS_NEITHER) |
| 19477 |
&& optimize_bb_for_speed_p (bb)) |
| 19478 |
? SKIP : CONV; |
| 19479 |
|
| 19480 |
COPY_REG_SET (&live, DF_LR_OUT (bb)); |
| 19481 |
df_simulate_initialize_backwards (bb, &live); |
| 19482 |
FOR_BB_INSNS_REVERSE (bb, insn) |
| 19483 |
{ |
| 19484 |
if (NONJUMP_INSN_P (insn) |
| 19485 |
&& !REGNO_REG_SET_P (&live, CC_REGNUM) |
| 19486 |
&& GET_CODE (PATTERN (insn)) == SET) |
| 19487 |
{ |
| 19488 |
action = SKIP; |
| 19489 |
rtx pat = PATTERN (insn); |
| 19490 |
rtx dst = XEXP (pat, 0); |
| 19491 |
rtx src = XEXP (pat, 1); |
| 19492 |
rtx op0 = NULL_RTX, op1 = NULL_RTX; |
| 19493 |
|
| 19494 |
if (UNARY_P (src) || BINARY_P (src)) |
| 19495 |
op0 = XEXP (src, 0); |
| 19496 |
|
| 19497 |
if (BINARY_P (src)) |
| 19498 |
op1 = XEXP (src, 1); |
| 19499 |
|
| 19500 |
if (low_register_operand (dst, SImode)) |
| 19501 |
{ |
| 19502 |
switch (GET_CODE (src)) |
| 19503 |
{ |
| 19504 |
case PLUS: |
| 19505 |
/* Adding two registers and storing the result |
| 19506 |
in the first source is already a 16-bit |
| 19507 |
operation. */ |
| 19508 |
if (rtx_equal_p (dst, op0) |
| 19509 |
&& register_operand (op1, SImode)) |
| 19510 |
break; |
| 19511 |
|
| 19512 |
if (low_register_operand (op0, SImode)) |
| 19513 |
{ |
| 19514 |
/* ADDS <Rd>,<Rn>,<Rm> */ |
| 19515 |
if (low_register_operand (op1, SImode)) |
| 19516 |
action = CONV; |
| 19517 |
/* ADDS <Rdn>,#<imm8> */ |
| 19518 |
/* SUBS <Rdn>,#<imm8> */ |
| 19519 |
else if (rtx_equal_p (dst, op0) |
| 19520 |
&& CONST_INT_P (op1) |
| 19521 |
&& IN_RANGE (INTVAL (op1), -255, 255)) |
| 19522 |
action = CONV; |
| 19523 |
/* ADDS <Rd>,<Rn>,#<imm3> */ |
| 19524 |
/* SUBS <Rd>,<Rn>,#<imm3> */ |
| 19525 |
else if (CONST_INT_P (op1) |
| 19526 |
&& IN_RANGE (INTVAL (op1), -7, 7)) |
| 19527 |
action = CONV; |
| 19528 |
} |
| 19529 |
/* ADCS <Rd>, <Rn> */ |
| 19530 |
else if (GET_CODE (XEXP (src, 0)) == PLUS |
| 19531 |
&& rtx_equal_p (XEXP (XEXP (src, 0), 0), dst) |
| 19532 |
&& low_register_operand (XEXP (XEXP (src, 0), 1), |
| 19533 |
SImode) |
| 19534 |
&& COMPARISON_P (op1) |
| 19535 |
&& cc_register (XEXP (op1, 0), VOIDmode) |
| 19536 |
&& maybe_get_arm_condition_code (op1) == ARM_CS |
| 19537 |
&& XEXP (op1, 1) == const0_rtx) |
| 19538 |
action = CONV; |
| 19539 |
break; |
| 19540 |
|
| 19541 |
case MINUS: |
| 19542 |
/* RSBS <Rd>,<Rn>,#0 |
| 19543 |
Not handled here: see NEG below. */ |
| 19544 |
/* SUBS <Rd>,<Rn>,#<imm3> |
| 19545 |
SUBS <Rdn>,#<imm8> |
| 19546 |
Not handled here: see PLUS above. */ |
| 19547 |
/* SUBS <Rd>,<Rn>,<Rm> */ |
| 19548 |
if (low_register_operand (op0, SImode) |
| 19549 |
&& low_register_operand (op1, SImode)) |
| 19550 |
action = CONV; |
| 19551 |
break; |
| 19552 |
|
| 19553 |
case MULT: |
| 19554 |
/* MULS <Rdm>,<Rn>,<Rdm> |
| 19555 |
As an exception to the rule, this is only used |
| 19556 |
when optimizing for size since MULS is slow on all |
| 19557 |
known implementations. We do not even want to use |
| 19558 |
MULS in cold code, if optimizing for speed, so we |
| 19559 |
test the global flag here. */ |
| 19560 |
if (!optimize_size) |
| 19561 |
break; |
| 19562 |
/* Fall through. */ |
| 19563 |
case AND: |
| 19564 |
case IOR: |
| 19565 |
case XOR: |
| 19566 |
/* ANDS <Rdn>,<Rm> */ |
| 19567 |
if (rtx_equal_p (dst, op0) |
| 19568 |
&& low_register_operand (op1, SImode)) |
| 19569 |
action = action_for_partial_flag_setting; |
| 19570 |
else if (rtx_equal_p (dst, op1) |
| 19571 |
&& low_register_operand (op0, SImode)) |
| 19572 |
action = action_for_partial_flag_setting == SKIP |
| 19573 |
? SKIP : SWAP_CONV; |
| 19574 |
break; |
| 19575 |
|
| 19576 |
case ASHIFTRT: |
| 19577 |
case ASHIFT: |
| 19578 |
case LSHIFTRT: |
| 19579 |
/* ASRS <Rdn>,<Rm> */ |
| 19580 |
/* LSRS <Rdn>,<Rm> */ |
| 19581 |
/* LSLS <Rdn>,<Rm> */ |
| 19582 |
if (rtx_equal_p (dst, op0) |
| 19583 |
&& low_register_operand (op1, SImode)) |
| 19584 |
action = action_for_partial_flag_setting; |
| 19585 |
/* ASRS <Rd>,<Rm>,#<imm5> */ |
| 19586 |
/* LSRS <Rd>,<Rm>,#<imm5> */ |
| 19587 |
/* LSLS <Rd>,<Rm>,#<imm5> */ |
| 19588 |
else if (low_register_operand (op0, SImode) |
| 19589 |
&& CONST_INT_P (op1) |
| 19590 |
&& IN_RANGE (INTVAL (op1), 0, 31)) |
| 19591 |
action = action_for_partial_flag_setting; |
| 19592 |
break; |
| 19593 |
|
| 19594 |
case ROTATERT: |
| 19595 |
/* RORS <Rdn>,<Rm> */ |
| 19596 |
if (rtx_equal_p (dst, op0) |
| 19597 |
&& low_register_operand (op1, SImode)) |
| 19598 |
action = action_for_partial_flag_setting; |
| 19599 |
break; |
| 19600 |
|
| 19601 |
case NOT: |
| 19602 |
/* MVNS <Rd>,<Rm> */ |
| 19603 |
if (low_register_operand (op0, SImode)) |
| 19604 |
action = action_for_partial_flag_setting; |
| 19605 |
break; |
| 19606 |
|
| 19607 |
case NEG: |
| 19608 |
/* NEGS <Rd>,<Rm> (a.k.a RSBS) */ |
| 19609 |
if (low_register_operand (op0, SImode)) |
| 19610 |
action = CONV; |
| 19611 |
break; |
| 19612 |
|
| 19613 |
case CONST_INT: |
| 19614 |
/* MOVS <Rd>,#<imm8> */ |
| 19615 |
if (CONST_INT_P (src) |
| 19616 |
&& IN_RANGE (INTVAL (src), 0, 255)) |
| 19617 |
action = action_for_partial_flag_setting; |
| 19618 |
break; |
| 19619 |
|
| 19620 |
case REG: |
| 19621 |
/* MOVS and MOV<c> with registers have different |
| 19622 |
encodings, so are not relevant here. */ |
| 19623 |
break; |
| 19624 |
|
| 19625 |
default: |
| 19626 |
break; |
| 19627 |
} |
| 19628 |
} |
| 19629 |
|
| 19630 |
if (action != SKIP) |
| 19631 |
{ |
| 19632 |
rtx ccreg = gen_rtx_REG (CCmode, CC_REGNUM); |
| 19633 |
rtx clobber = gen_rtx_CLOBBER (VOIDmode, ccreg); |
| 19634 |
rtvec vec; |
| 19635 |
|
| 19636 |
if (action == SWAP_CONV) |
| 19637 |
{ |
| 19638 |
src = copy_rtx (src); |
| 19639 |
XEXP (src, 0) = op1; |
| 19640 |
XEXP (src, 1) = op0; |
| 19641 |
pat = gen_rtx_SET (dst, src); |
| 19642 |
vec = gen_rtvec (2, pat, clobber); |
| 19643 |
} |
| 19644 |
else /* action == CONV */ |
| 19645 |
vec = gen_rtvec (2, pat, clobber); |
| 19646 |
|
| 19647 |
PATTERN (insn) = gen_rtx_PARALLEL (VOIDmode, vec); |
| 19648 |
INSN_CODE (insn) = -1; |
| 19649 |
} |
| 19650 |
} |
| 19651 |
|
| 19652 |
if (NONDEBUG_INSN_P (insn)) |
| 19653 |
df_simulate_one_insn_backwards (bb, insn, &live); |
| 19654 |
} |
| 19655 |
} |
| 19656 |
|
| 19657 |
CLEAR_REG_SET (&live); |
| 19658 |
} |
| 19659 |
|
| 19660 |
/* Gcc puts the pool in the wrong place for ARM, since we can only |
| 19661 |
load addresses a limited distance around the pc. We do some |
| 19662 |
special munging to move the constant pool values to the correct |
| 19663 |
point in the code. */ |
| 19664 |
static void |
| 19665 |
arm_reorg (void) |
| 19666 |
{ |
| 19667 |
rtx_insn *insn; |
| 19668 |
HOST_WIDE_INT address = 0; |
| 19669 |
Mfix * fix; |
| 19670 |
|
| 19671 |
if (use_cmse) |
| 19672 |
cmse_nonsecure_call_inline_register_clear (); |
| 19673 |
|
| 19674 |
/* We cannot run the Thumb passes for thunks because there is no CFG. */ |
| 19675 |
if (cfun->is_thunk) |
| 19676 |
; |
| 19677 |
else if (TARGET_THUMB1) |
| 19678 |
thumb1_reorg (); |
| 19679 |
else if (TARGET_THUMB2) |
| 19680 |
thumb2_reorg (); |
| 19681 |
|
| 19682 |
/* Ensure all insns that must be split have been split at this point. |
| 19683 |
Otherwise, the pool placement code below may compute incorrect |
| 19684 |
insn lengths. Note that when optimizing, all insns have already |
| 19685 |
been split at this point. */ |
| 19686 |
if (!optimize) |
| 19687 |
split_all_insns_noflow (); |
| 19688 |
|
| 19689 |
/* Make sure we do not attempt to create a literal pool even though it should |
| 19690 |
no longer be necessary to create any. */ |
| 19691 |
if (arm_disable_literal_pool) |
| 19692 |
return ; |
| 19693 |
|
| 19694 |
minipool_fix_head = minipool_fix_tail = NULL; |
| 19695 |
|
| 19696 |
/* The first insn must always be a note, or the code below won't |
| 19697 |
scan it properly. */ |
| 19698 |
insn = get_insns (); |
| 19699 |
gcc_assert (NOTE_P (insn)); |
| 19700 |
minipool_pad = 0; |
| 19701 |
|
| 19702 |
/* Scan all the insns and record the operands that will need fixing. */ |
| 19703 |
for (insn = next_nonnote_insn (insn); insn; insn = next_nonnote_insn (insn)) |
| 19704 |
{ |
| 19705 |
if (BARRIER_P (insn)) |
| 19706 |
push_minipool_barrier (insn, address); |
| 19707 |
else if (INSN_P (insn)) |
| 19708 |
{ |
| 19709 |
rtx_jump_table_data *table; |
| 19710 |
|
| 19711 |
note_invalid_constants (insn, address, true); |
| 19712 |
address += get_attr_length (insn); |
| 19713 |
|
| 19714 |
/* If the insn is a vector jump, add the size of the table |
| 19715 |
and skip the table. */ |
| 19716 |
if (tablejump_p (insn, NULL, &table)) |
| 19717 |
{ |
| 19718 |
address += get_jump_table_size (table); |
| 19719 |
insn = table; |
| 19720 |
} |
| 19721 |
} |
| 19722 |
else if (LABEL_P (insn)) |
| 19723 |
/* Add the worst-case padding due to alignment. We don't add |
| 19724 |
the _current_ padding because the minipool insertions |
| 19725 |
themselves might change it. */ |
| 19726 |
address += get_label_padding (insn); |
| 19727 |
} |
| 19728 |
|
| 19729 |
fix = minipool_fix_head; |
| 19730 |
|
| 19731 |
/* Now scan the fixups and perform the required changes. */ |
| 19732 |
while (fix) |
| 19733 |
{ |
| 19734 |
Mfix * ftmp; |
| 19735 |
Mfix * fdel; |
| 19736 |
Mfix * last_added_fix; |
| 19737 |
Mfix * last_barrier = NULL; |
| 19738 |
Mfix * this_fix; |
| 19739 |
|
| 19740 |
/* Skip any further barriers before the next fix. */ |
| 19741 |
while (fix && BARRIER_P (fix->insn)) |
| 19742 |
fix = fix->next; |
| 19743 |
|
| 19744 |
/* No more fixes. */ |
| 19745 |
if (fix == NULL) |
| 19746 |
break; |
| 19747 |
|
| 19748 |
last_added_fix = NULL; |
| 19749 |
|
| 19750 |
for (ftmp = fix; ftmp; ftmp = ftmp->next) |
| 19751 |
{ |
| 19752 |
if (BARRIER_P (ftmp->insn)) |
| 19753 |
{ |
| 19754 |
if (ftmp->address >= minipool_vector_head->max_address) |
| 19755 |
break; |
| 19756 |
|
| 19757 |
last_barrier = ftmp; |
| 19758 |
} |
| 19759 |
else if ((ftmp->minipool = add_minipool_forward_ref (ftmp)) == NULL) |
| 19760 |
break; |
| 19761 |
|
| 19762 |
last_added_fix = ftmp; /* Keep track of the last fix added. */ |
| 19763 |
} |
| 19764 |
|
| 19765 |
/* If we found a barrier, drop back to that; any fixes that we |
| 19766 |
could have reached but come after the barrier will now go in |
| 19767 |
the next mini-pool. */ |
| 19768 |
if (last_barrier != NULL) |
| 19769 |
{ |
| 19770 |
/* Reduce the refcount for those fixes that won't go into this |
| 19771 |
pool after all. */ |
| 19772 |
for (fdel = last_barrier->next; |
| 19773 |
fdel && fdel != ftmp; |
| 19774 |
fdel = fdel->next) |
| 19775 |
{ |
| 19776 |
fdel->minipool->refcount--; |
| 19777 |
fdel->minipool = NULL; |
| 19778 |
} |
| 19779 |
|
| 19780 |
ftmp = last_barrier; |
| 19781 |
} |
| 19782 |
else |
| 19783 |
{ |
| 19784 |
/* ftmp is first fix that we can't fit into this pool and |
| 19785 |
there no natural barriers that we could use. Insert a |
| 19786 |
new barrier in the code somewhere between the previous |
| 19787 |
fix and this one, and arrange to jump around it. */ |
| 19788 |
HOST_WIDE_INT max_address; |
| 19789 |
|
| 19790 |
/* The last item on the list of fixes must be a barrier, so |
| 19791 |
we can never run off the end of the list of fixes without |
| 19792 |
last_barrier being set. */ |
| 19793 |
gcc_assert (ftmp); |
| 19794 |
|
| 19795 |
max_address = minipool_vector_head->max_address; |
| 19796 |
/* Check that there isn't another fix that is in range that |
| 19797 |
we couldn't fit into this pool because the pool was |
| 19798 |
already too large: we need to put the pool before such an |
| 19799 |
instruction. The pool itself may come just after the |
| 19800 |
fix because create_fix_barrier also allows space for a |
| 19801 |
jump instruction. */ |
| 19802 |
if (ftmp->address < max_address) |
| 19803 |
max_address = ftmp->address + 1; |
| 19804 |
|
| 19805 |
last_barrier = create_fix_barrier (last_added_fix, max_address); |
| 19806 |
} |
| 19807 |
|
| 19808 |
assign_minipool_offsets (last_barrier); |
| 19809 |
|
| 19810 |
while (ftmp) |
| 19811 |
{ |
| 19812 |
if (!BARRIER_P (ftmp->insn) |
| 19813 |
&& ((ftmp->minipool = add_minipool_backward_ref (ftmp)) |
| 19814 |
== NULL)) |
| 19815 |
break; |
| 19816 |
|
| 19817 |
ftmp = ftmp->next; |
| 19818 |
} |
| 19819 |
|
| 19820 |
/* Scan over the fixes we have identified for this pool, fixing them |
| 19821 |
up and adding the constants to the pool itself. */ |
| 19822 |
for (this_fix = fix; this_fix && ftmp != this_fix; |
| 19823 |
this_fix = this_fix->next) |
| 19824 |
if (!BARRIER_P (this_fix->insn)) |
| 19825 |
{ |
| 19826 |
rtx addr |
| 19827 |
= plus_constant (Pmode, |
| 19828 |
gen_rtx_LABEL_REF (VOIDmode, |
| 19829 |
minipool_vector_label), |
| 19830 |
this_fix->minipool->offset); |
| 19831 |
*this_fix->loc = gen_rtx_MEM (this_fix->mode, addr); |
| 19832 |
} |
| 19833 |
|
| 19834 |
dump_minipool (last_barrier->insn); |
| 19835 |
fix = ftmp; |
| 19836 |
} |
| 19837 |
|
| 19838 |
/* From now on we must synthesize any constants that we can't handle |
| 19839 |
directly. This can happen if the RTL gets split during final |
| 19840 |
instruction generation. */ |
| 19841 |
cfun->machine->after_arm_reorg = 1; |
| 19842 |
|
| 19843 |
/* Free the minipool memory. */ |
| 19844 |
obstack_free (&minipool_obstack, minipool_startobj); |
| 19845 |
} |
| 19846 |
|
| 19847 |
/* Routines to output assembly language. */ |
| 19848 |
|
| 19849 |
/* OPERANDS[0] is the entire list of insns that constitute pop, |
| 19850 |
OPERANDS[1] is the base register, RETURN_PC is true iff return insn |
| 19851 |
is in the list, UPDATE is true iff the list contains explicit |
| 19852 |
update of base register. */ |
| 19853 |
void |
| 19854 |
arm_output_multireg_pop (rtx *operands, bool return_pc, rtx cond, bool reverse, |
| 19855 |
bool update) |
| 19856 |
{ |
| 19857 |
int i; |
| 19858 |
char pattern[100]; |
| 19859 |
int offset; |
| 19860 |
const char *conditional; |
| 19861 |
int num_saves = XVECLEN (operands[0], 0); |
| 19862 |
unsigned int regno; |
| 19863 |
unsigned int regno_base = REGNO (operands[1]); |
| 19864 |
bool interrupt_p = IS_INTERRUPT (arm_current_func_type ()); |
| 19865 |
|
| 19866 |
offset = 0; |
| 19867 |
offset += update ? 1 : 0; |
| 19868 |
offset += return_pc ? 1 : 0; |
| 19869 |
|
| 19870 |
/* Is the base register in the list? */ |
| 19871 |
for (i = offset; i < num_saves; i++) |
| 19872 |
{ |
| 19873 |
regno = REGNO (XEXP (XVECEXP (operands[0], 0, i), 0)); |
| 19874 |
/* If SP is in the list, then the base register must be SP. */ |
| 19875 |
gcc_assert ((regno != SP_REGNUM) || (regno_base == SP_REGNUM)); |
| 19876 |
/* If base register is in the list, there must be no explicit update. */ |
| 19877 |
if (regno == regno_base) |
| 19878 |
gcc_assert (!update); |
| 19879 |
} |
| 19880 |
|
| 19881 |
conditional = reverse ? "%?%D0" : "%?%d0"; |
| 19882 |
/* Can't use POP if returning from an interrupt. */ |
| 19883 |
if ((regno_base == SP_REGNUM) && update && !(interrupt_p && return_pc)) |
| 19884 |
sprintf (pattern, "pop%s\t{", conditional); |
| 19885 |
else |
| 19886 |
{ |
| 19887 |
/* Output ldmfd when the base register is SP, otherwise output ldmia. |
| 19888 |
It's just a convention, their semantics are identical. */ |
| 19889 |
if (regno_base == SP_REGNUM) |
| 19890 |
sprintf (pattern, "ldmfd%s\t", conditional); |
| 19891 |
else if (update) |
| 19892 |
sprintf (pattern, "ldmia%s\t", conditional); |
| 19893 |
else |
| 19894 |
sprintf (pattern, "ldm%s\t", conditional); |
| 19895 |
|
| 19896 |
strcat (pattern, reg_names[regno_base]); |
| 19897 |
if (update) |
| 19898 |
strcat (pattern, "!, {"); |
| 19899 |
else |
| 19900 |
strcat (pattern, ", {"); |
| 19901 |
} |
| 19902 |
|
| 19903 |
/* Output the first destination register. */ |
| 19904 |
strcat (pattern, |
| 19905 |
reg_names[REGNO (XEXP (XVECEXP (operands[0], 0, offset), 0))]); |
| 19906 |
|
| 19907 |
/* Output the rest of the destination registers. */ |
| 19908 |
for (i = offset + 1; i < num_saves; i++) |
| 19909 |
{ |
| 19910 |
strcat (pattern, ", "); |
| 19911 |
strcat (pattern, |
| 19912 |
reg_names[REGNO (XEXP (XVECEXP (operands[0], 0, i), 0))]); |
| 19913 |
} |
| 19914 |
|
| 19915 |
strcat (pattern, "}"); |
| 19916 |
|
| 19917 |
if (interrupt_p && return_pc) |
| 19918 |
strcat (pattern, "^"); |
| 19919 |
|
| 19920 |
output_asm_insn (pattern, &cond); |
| 19921 |
} |
| 19922 |
|
| 19923 |
|
| 19924 |
/* Output the assembly for a store multiple. */ |
| 19925 |
|
| 19926 |
const char * |
| 19927 |
vfp_output_vstmd (rtx * operands) |
| 19928 |
{ |
| 19929 |
char pattern[100]; |
| 19930 |
int p; |
| 19931 |
int base; |
| 19932 |
int i; |
| 19933 |
rtx addr_reg = REG_P (XEXP (operands[0], 0)) |
| 19934 |
? XEXP (operands[0], 0) |
| 19935 |
: XEXP (XEXP (operands[0], 0), 0); |
| 19936 |
bool push_p = REGNO (addr_reg) == SP_REGNUM; |
| 19937 |
|
| 19938 |
if (push_p) |
| 19939 |
strcpy (pattern, "vpush%?.64\t{%P1"); |
| 19940 |
else |
| 19941 |
strcpy (pattern, "vstmdb%?.64\t%m0!, {%P1"); |
| 19942 |
|
| 19943 |
p = strlen (pattern); |
| 19944 |
|
| 19945 |
gcc_assert (REG_P (operands[1])); |
| 19946 |
|
| 19947 |
base = (REGNO (operands[1]) - FIRST_VFP_REGNUM) / 2; |
| 19948 |
for (i = 1; i < XVECLEN (operands[2], 0); i++) |
| 19949 |
{ |
| 19950 |
p += sprintf (&pattern[p], ", d%d", base + i); |
| 19951 |
} |
| 19952 |
strcpy (&pattern[p], "}"); |
| 19953 |
|
| 19954 |
output_asm_insn (pattern, operands); |
| 19955 |
return ""; |
| 19956 |
} |
| 19957 |
|
| 19958 |
|
| 19959 |
/* Emit RTL to save block of VFP register pairs to the stack. Returns the |
| 19960 |
number of bytes pushed. */ |
| 19961 |
|
| 19962 |
static int |
| 19963 |
vfp_emit_fstmd (int base_reg, int count) |
| 19964 |
{ |
| 19965 |
rtx par; |
| 19966 |
rtx dwarf; |
| 19967 |
rtx tmp, reg; |
| 19968 |
int i; |
| 19969 |
|
| 19970 |
/* Workaround ARM10 VFPr1 bug. Data corruption can occur when exactly two |
| 19971 |
register pairs are stored by a store multiple insn. We avoid this |
| 19972 |
by pushing an extra pair. */ |
| 19973 |
if (count == 2 && !arm_arch6) |
| 19974 |
{ |
| 19975 |
if (base_reg == LAST_VFP_REGNUM - 3) |
| 19976 |
base_reg -= 2; |
| 19977 |
count++; |
| 19978 |
} |
| 19979 |
|
| 19980 |
/* FSTMD may not store more than 16 doubleword registers at once. Split |
| 19981 |
larger stores into multiple parts (up to a maximum of two, in |
| 19982 |
practice). */ |
| 19983 |
if (count > 16) |
| 19984 |
{ |
| 19985 |
int saved; |
| 19986 |
/* NOTE: base_reg is an internal register number, so each D register |
| 19987 |
counts as 2. */ |
| 19988 |
saved = vfp_emit_fstmd (base_reg + 32, count - 16); |
| 19989 |
saved += vfp_emit_fstmd (base_reg, 16); |
| 19990 |
return saved; |
| 19991 |
} |
| 19992 |
|
| 19993 |
par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count)); |
| 19994 |
dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (count + 1)); |
| 19995 |
|
| 19996 |
reg = gen_rtx_REG (DFmode, base_reg); |
| 19997 |
base_reg += 2; |
| 19998 |
|
| 19999 |
XVECEXP (par, 0, 0) |
| 20000 |
= gen_rtx_SET (gen_frame_mem |
| 20001 |
(BLKmode, |
| 20002 |
gen_rtx_PRE_MODIFY (Pmode, |
| 20003 |
stack_pointer_rtx, |
| 20004 |
plus_constant |
| 20005 |
(Pmode, stack_pointer_rtx, |
| 20006 |
- (count * 8))) |
| 20007 |
), |
| 20008 |
gen_rtx_UNSPEC (BLKmode, |
| 20009 |
gen_rtvec (1, reg), |
| 20010 |
UNSPEC_PUSH_MULT)); |
| 20011 |
|
| 20012 |
tmp = gen_rtx_SET (stack_pointer_rtx, |
| 20013 |
plus_constant (Pmode, stack_pointer_rtx, -(count * 8))); |
| 20014 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 20015 |
XVECEXP (dwarf, 0, 0) = tmp; |
| 20016 |
|
| 20017 |
tmp = gen_rtx_SET (gen_frame_mem (DFmode, stack_pointer_rtx), reg); |
| 20018 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 20019 |
XVECEXP (dwarf, 0, 1) = tmp; |
| 20020 |
|
| 20021 |
for (i = 1; i < count; i++) |
| 20022 |
{ |
| 20023 |
reg = gen_rtx_REG (DFmode, base_reg); |
| 20024 |
base_reg += 2; |
| 20025 |
XVECEXP (par, 0, i) = gen_rtx_USE (VOIDmode, reg); |
| 20026 |
|
| 20027 |
tmp = gen_rtx_SET (gen_frame_mem (DFmode, |
| 20028 |
plus_constant (Pmode, |
| 20029 |
stack_pointer_rtx, |
| 20030 |
i * 8)), |
| 20031 |
reg); |
| 20032 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 20033 |
XVECEXP (dwarf, 0, i + 1) = tmp; |
| 20034 |
} |
| 20035 |
|
| 20036 |
par = emit_insn (par); |
| 20037 |
add_reg_note (par, REG_FRAME_RELATED_EXPR, dwarf); |
| 20038 |
RTX_FRAME_RELATED_P (par) = 1; |
| 20039 |
|
| 20040 |
return count * 8; |
| 20041 |
} |
| 20042 |
|
| 20043 |
/* Returns true if -mcmse has been passed and the function pointed to by 'addr' |
| 20044 |
has the cmse_nonsecure_call attribute and returns false otherwise. */ |
| 20045 |
|
| 20046 |
bool |
| 20047 |
detect_cmse_nonsecure_call (tree addr) |
| 20048 |
{ |
| 20049 |
if (!addr) |
| 20050 |
return FALSE; |
| 20051 |
|
| 20052 |
tree fntype = TREE_TYPE (addr); |
| 20053 |
if (use_cmse && lookup_attribute ("cmse_nonsecure_call", |
| 20054 |
TYPE_ATTRIBUTES (fntype))) |
| 20055 |
return TRUE; |
| 20056 |
return FALSE; |
| 20057 |
} |
| 20058 |
|
| 20059 |
|
| 20060 |
/* Emit a call instruction with pattern PAT. ADDR is the address of |
| 20061 |
the call target. */ |
| 20062 |
|
| 20063 |
void |
| 20064 |
arm_emit_call_insn (rtx pat, rtx addr, bool sibcall) |
| 20065 |
{ |
| 20066 |
rtx insn; |
| 20067 |
|
| 20068 |
insn = emit_call_insn (pat); |
| 20069 |
|
| 20070 |
/* The PIC register is live on entry to VxWorks PIC PLT entries. |
| 20071 |
If the call might use such an entry, add a use of the PIC register |
| 20072 |
to the instruction's CALL_INSN_FUNCTION_USAGE. */ |
| 20073 |
if (TARGET_VXWORKS_RTP |
| 20074 |
&& flag_pic |
| 20075 |
&& !sibcall |
| 20076 |
&& SYMBOL_REF_P (addr) |
| 20077 |
&& (SYMBOL_REF_DECL (addr) |
| 20078 |
? !targetm.binds_local_p (SYMBOL_REF_DECL (addr)) |
| 20079 |
: !SYMBOL_REF_LOCAL_P (addr))) |
| 20080 |
{ |
| 20081 |
require_pic_register (NULL_RTX, false /*compute_now*/); |
| 20082 |
use_reg (&CALL_INSN_FUNCTION_USAGE (insn), cfun->machine->pic_reg); |
| 20083 |
} |
| 20084 |
|
| 20085 |
if (TARGET_FDPIC) |
| 20086 |
{ |
| 20087 |
rtx fdpic_reg = gen_rtx_REG (Pmode, FDPIC_REGNUM); |
| 20088 |
use_reg (&CALL_INSN_FUNCTION_USAGE (insn), fdpic_reg); |
| 20089 |
} |
| 20090 |
|
| 20091 |
if (TARGET_AAPCS_BASED) |
| 20092 |
{ |
| 20093 |
/* For AAPCS, IP and CC can be clobbered by veneers inserted by the |
| 20094 |
linker. We need to add an IP clobber to allow setting |
| 20095 |
TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS to true. A CC clobber |
| 20096 |
is not needed since it's a fixed register. */ |
| 20097 |
rtx *fusage = &CALL_INSN_FUNCTION_USAGE (insn); |
| 20098 |
clobber_reg (fusage, gen_rtx_REG (word_mode, IP_REGNUM)); |
| 20099 |
} |
| 20100 |
} |
| 20101 |
|
| 20102 |
/* Output a 'call' insn. */ |
| 20103 |
const char * |
| 20104 |
output_call (rtx *operands) |
| 20105 |
{ |
| 20106 |
gcc_assert (!arm_arch5t); /* Patterns should call blx <reg> directly. */ |
| 20107 |
|
| 20108 |
/* Handle calls to lr using ip (which may be clobbered in subr anyway). */ |
| 20109 |
if (REGNO (operands[0]) == LR_REGNUM) |
| 20110 |
{ |
| 20111 |
operands[0] = gen_rtx_REG (SImode, IP_REGNUM); |
| 20112 |
output_asm_insn ("mov%?\t%0, %|lr", operands); |
| 20113 |
} |
| 20114 |
|
| 20115 |
output_asm_insn ("mov%?\t%|lr, %|pc", operands); |
| 20116 |
|
| 20117 |
if (TARGET_INTERWORK || arm_arch4t) |
| 20118 |
output_asm_insn ("bx%?\t%0", operands); |
| 20119 |
else |
| 20120 |
output_asm_insn ("mov%?\t%|pc, %0", operands); |
| 20121 |
|
| 20122 |
return ""; |
| 20123 |
} |
| 20124 |
|
| 20125 |
/* Output a move from arm registers to arm registers of a long double |
| 20126 |
OPERANDS[0] is the destination. |
| 20127 |
OPERANDS[1] is the source. */ |
| 20128 |
const char * |
| 20129 |
output_mov_long_double_arm_from_arm (rtx *operands) |
| 20130 |
{ |
| 20131 |
/* We have to be careful here because the two might overlap. */ |
| 20132 |
int dest_start = REGNO (operands[0]); |
| 20133 |
int src_start = REGNO (operands[1]); |
| 20134 |
rtx ops[2]; |
| 20135 |
int i; |
| 20136 |
|
| 20137 |
if (dest_start < src_start) |
| 20138 |
{ |
| 20139 |
for (i = 0; i < 3; i++) |
| 20140 |
{ |
| 20141 |
ops[0] = gen_rtx_REG (SImode, dest_start + i); |
| 20142 |
ops[1] = gen_rtx_REG (SImode, src_start + i); |
| 20143 |
output_asm_insn ("mov%?\t%0, %1", ops); |
| 20144 |
} |
| 20145 |
} |
| 20146 |
else |
| 20147 |
{ |
| 20148 |
for (i = 2; i >= 0; i--) |
| 20149 |
{ |
| 20150 |
ops[0] = gen_rtx_REG (SImode, dest_start + i); |
| 20151 |
ops[1] = gen_rtx_REG (SImode, src_start + i); |
| 20152 |
output_asm_insn ("mov%?\t%0, %1", ops); |
| 20153 |
} |
| 20154 |
} |
| 20155 |
|
| 20156 |
return ""; |
| 20157 |
} |
| 20158 |
|
| 20159 |
void |
| 20160 |
arm_emit_movpair (rtx dest, rtx src) |
| 20161 |
{ |
| 20162 |
/* If the src is an immediate, simplify it. */ |
| 20163 |
if (CONST_INT_P (src)) |
| 20164 |
{ |
| 20165 |
HOST_WIDE_INT val = INTVAL (src); |
| 20166 |
emit_set_insn (dest, GEN_INT (val & 0x0000ffff)); |
| 20167 |
if ((val >> 16) & 0x0000ffff) |
| 20168 |
{ |
| 20169 |
emit_set_insn (gen_rtx_ZERO_EXTRACT (SImode, dest, GEN_INT (16), |
| 20170 |
GEN_INT (16)), |
| 20171 |
GEN_INT ((val >> 16) & 0x0000ffff)); |
| 20172 |
rtx_insn *insn = get_last_insn (); |
| 20173 |
set_unique_reg_note (insn, REG_EQUAL, copy_rtx (src)); |
| 20174 |
} |
| 20175 |
return; |
| 20176 |
} |
| 20177 |
emit_set_insn (dest, gen_rtx_HIGH (SImode, src)); |
| 20178 |
emit_set_insn (dest, gen_rtx_LO_SUM (SImode, dest, src)); |
| 20179 |
rtx_insn *insn = get_last_insn (); |
| 20180 |
set_unique_reg_note (insn, REG_EQUAL, copy_rtx (src)); |
| 20181 |
} |
| 20182 |
|
| 20183 |
/* Output a move between double words. It must be REG<-MEM |
| 20184 |
or MEM<-REG. */ |
| 20185 |
const char * |
| 20186 |
output_move_double (rtx *operands, bool emit, int *count) |
| 20187 |
{ |
| 20188 |
enum rtx_code code0 = GET_CODE (operands[0]); |
| 20189 |
enum rtx_code code1 = GET_CODE (operands[1]); |
| 20190 |
rtx otherops[3]; |
| 20191 |
if (count) |
| 20192 |
*count = 1; |
| 20193 |
|
| 20194 |
/* The only case when this might happen is when |
| 20195 |
you are looking at the length of a DImode instruction |
| 20196 |
that has an invalid constant in it. */ |
| 20197 |
if (code0 == REG && code1 != MEM) |
| 20198 |
{ |
| 20199 |
gcc_assert (!emit); |
| 20200 |
*count = 2; |
| 20201 |
return ""; |
| 20202 |
} |
| 20203 |
|
| 20204 |
if (code0 == REG) |
| 20205 |
{ |
| 20206 |
unsigned int reg0 = REGNO (operands[0]); |
| 20207 |
const bool can_ldrd = TARGET_LDRD && (TARGET_THUMB2 || (reg0 % 2 == 0)); |
| 20208 |
|
| 20209 |
otherops[0] = gen_rtx_REG (SImode, 1 + reg0); |
| 20210 |
|
| 20211 |
gcc_assert (code1 == MEM); /* Constraints should ensure this. */ |
| 20212 |
|
| 20213 |
switch (GET_CODE (XEXP (operands[1], 0))) |
| 20214 |
{ |
| 20215 |
case REG: |
| 20216 |
|
| 20217 |
if (emit) |
| 20218 |
{ |
| 20219 |
if (can_ldrd |
| 20220 |
&& !(fix_cm3_ldrd && reg0 == REGNO(XEXP (operands[1], 0)))) |
| 20221 |
output_asm_insn ("ldrd%?\t%0, [%m1]", operands); |
| 20222 |
else |
| 20223 |
output_asm_insn ("ldmia%?\t%m1, %M0", operands); |
| 20224 |
} |
| 20225 |
break; |
| 20226 |
|
| 20227 |
case PRE_INC: |
| 20228 |
gcc_assert (can_ldrd); |
| 20229 |
if (emit) |
| 20230 |
output_asm_insn ("ldrd%?\t%0, [%m1, #8]!", operands); |
| 20231 |
break; |
| 20232 |
|
| 20233 |
case PRE_DEC: |
| 20234 |
if (emit) |
| 20235 |
{ |
| 20236 |
if (can_ldrd) |
| 20237 |
output_asm_insn ("ldrd%?\t%0, [%m1, #-8]!", operands); |
| 20238 |
else |
| 20239 |
output_asm_insn ("ldmdb%?\t%m1!, %M0", operands); |
| 20240 |
} |
| 20241 |
break; |
| 20242 |
|
| 20243 |
case POST_INC: |
| 20244 |
if (emit) |
| 20245 |
{ |
| 20246 |
if (can_ldrd) |
| 20247 |
output_asm_insn ("ldrd%?\t%0, [%m1], #8", operands); |
| 20248 |
else |
| 20249 |
output_asm_insn ("ldmia%?\t%m1!, %M0", operands); |
| 20250 |
} |
| 20251 |
break; |
| 20252 |
|
| 20253 |
case POST_DEC: |
| 20254 |
gcc_assert (can_ldrd); |
| 20255 |
if (emit) |
| 20256 |
output_asm_insn ("ldrd%?\t%0, [%m1], #-8", operands); |
| 20257 |
break; |
| 20258 |
|
| 20259 |
case PRE_MODIFY: |
| 20260 |
case POST_MODIFY: |
| 20261 |
/* Autoicrement addressing modes should never have overlapping |
| 20262 |
base and destination registers, and overlapping index registers |
| 20263 |
are already prohibited, so this doesn't need to worry about |
| 20264 |
fix_cm3_ldrd. */ |
| 20265 |
otherops[0] = operands[0]; |
| 20266 |
otherops[1] = XEXP (XEXP (XEXP (operands[1], 0), 1), 0); |
| 20267 |
otherops[2] = XEXP (XEXP (XEXP (operands[1], 0), 1), 1); |
| 20268 |
|
| 20269 |
if (GET_CODE (XEXP (operands[1], 0)) == PRE_MODIFY) |
| 20270 |
{ |
| 20271 |
if (reg_overlap_mentioned_p (otherops[0], otherops[2])) |
| 20272 |
{ |
| 20273 |
/* Registers overlap so split out the increment. */ |
| 20274 |
if (emit) |
| 20275 |
{ |
| 20276 |
gcc_assert (can_ldrd); |
| 20277 |
output_asm_insn ("add%?\t%1, %1, %2", otherops); |
| 20278 |
output_asm_insn ("ldrd%?\t%0, [%1] @split", otherops); |
| 20279 |
} |
| 20280 |
if (count) |
| 20281 |
*count = 2; |
| 20282 |
} |
| 20283 |
else |
| 20284 |
{ |
| 20285 |
/* Use a single insn if we can. |
| 20286 |
FIXME: IWMMXT allows offsets larger than ldrd can |
| 20287 |
handle, fix these up with a pair of ldr. */ |
| 20288 |
if (can_ldrd |
| 20289 |
&& (TARGET_THUMB2 |
| 20290 |
|| !CONST_INT_P (otherops[2]) |
| 20291 |
|| (INTVAL (otherops[2]) > -256 |
| 20292 |
&& INTVAL (otherops[2]) < 256))) |
| 20293 |
{ |
| 20294 |
if (emit) |
| 20295 |
output_asm_insn ("ldrd%?\t%0, [%1, %2]!", otherops); |
| 20296 |
} |
| 20297 |
else |
| 20298 |
{ |
| 20299 |
if (emit) |
| 20300 |
{ |
| 20301 |
output_asm_insn ("ldr%?\t%0, [%1, %2]!", otherops); |
| 20302 |
output_asm_insn ("ldr%?\t%H0, [%1, #4]", otherops); |
| 20303 |
} |
| 20304 |
if (count) |
| 20305 |
*count = 2; |
| 20306 |
|
| 20307 |
} |
| 20308 |
} |
| 20309 |
} |
| 20310 |
else |
| 20311 |
{ |
| 20312 |
/* Use a single insn if we can. |
| 20313 |
FIXME: IWMMXT allows offsets larger than ldrd can handle, |
| 20314 |
fix these up with a pair of ldr. */ |
| 20315 |
if (can_ldrd |
| 20316 |
&& (TARGET_THUMB2 |
| 20317 |
|| !CONST_INT_P (otherops[2]) |
| 20318 |
|| (INTVAL (otherops[2]) > -256 |
| 20319 |
&& INTVAL (otherops[2]) < 256))) |
| 20320 |
{ |
| 20321 |
if (emit) |
| 20322 |
output_asm_insn ("ldrd%?\t%0, [%1], %2", otherops); |
| 20323 |
} |
| 20324 |
else |
| 20325 |
{ |
| 20326 |
if (emit) |
| 20327 |
{ |
| 20328 |
output_asm_insn ("ldr%?\t%H0, [%1, #4]", otherops); |
| 20329 |
output_asm_insn ("ldr%?\t%0, [%1], %2", otherops); |
| 20330 |
} |
| 20331 |
if (count) |
| 20332 |
*count = 2; |
| 20333 |
} |
| 20334 |
} |
| 20335 |
break; |
| 20336 |
|
| 20337 |
case LABEL_REF: |
| 20338 |
case CONST: |
| 20339 |
/* We might be able to use ldrd %0, %1 here. However the range is |
| 20340 |
different to ldr/adr, and it is broken on some ARMv7-M |
| 20341 |
implementations. */ |
| 20342 |
/* Use the second register of the pair to avoid problematic |
| 20343 |
overlap. */ |
| 20344 |
otherops[1] = operands[1]; |
| 20345 |
if (emit) |
| 20346 |
output_asm_insn ("adr%?\t%0, %1", otherops); |
| 20347 |
operands[1] = otherops[0]; |
| 20348 |
if (emit) |
| 20349 |
{ |
| 20350 |
if (can_ldrd) |
| 20351 |
output_asm_insn ("ldrd%?\t%0, [%1]", operands); |
| 20352 |
else |
| 20353 |
output_asm_insn ("ldmia%?\t%1, %M0", operands); |
| 20354 |
} |
| 20355 |
|
| 20356 |
if (count) |
| 20357 |
*count = 2; |
| 20358 |
break; |
| 20359 |
|
| 20360 |
/* ??? This needs checking for thumb2. */ |
| 20361 |
default: |
| 20362 |
if (arm_add_operand (XEXP (XEXP (operands[1], 0), 1), |
| 20363 |
GET_MODE (XEXP (XEXP (operands[1], 0), 1)))) |
| 20364 |
{ |
| 20365 |
otherops[0] = operands[0]; |
| 20366 |
otherops[1] = XEXP (XEXP (operands[1], 0), 0); |
| 20367 |
otherops[2] = XEXP (XEXP (operands[1], 0), 1); |
| 20368 |
|
| 20369 |
if (GET_CODE (XEXP (operands[1], 0)) == PLUS) |
| 20370 |
{ |
| 20371 |
if (CONST_INT_P (otherops[2]) && !TARGET_LDRD) |
| 20372 |
{ |
| 20373 |
switch ((int) INTVAL (otherops[2])) |
| 20374 |
{ |
| 20375 |
case -8: |
| 20376 |
if (emit) |
| 20377 |
output_asm_insn ("ldmdb%?\t%1, %M0", otherops); |
| 20378 |
return ""; |
| 20379 |
case -4: |
| 20380 |
if (TARGET_THUMB2) |
| 20381 |
break; |
| 20382 |
if (emit) |
| 20383 |
output_asm_insn ("ldmda%?\t%1, %M0", otherops); |
| 20384 |
return ""; |
| 20385 |
case 4: |
| 20386 |
if (TARGET_THUMB2) |
| 20387 |
break; |
| 20388 |
if (emit) |
| 20389 |
output_asm_insn ("ldmib%?\t%1, %M0", otherops); |
| 20390 |
return ""; |
| 20391 |
} |
| 20392 |
} |
| 20393 |
otherops[0] = gen_rtx_REG(SImode, REGNO(operands[0]) + 1); |
| 20394 |
operands[1] = otherops[0]; |
| 20395 |
if (can_ldrd |
| 20396 |
&& (REG_P (otherops[2]) |
| 20397 |
|| TARGET_THUMB2 |
| 20398 |
|| (CONST_INT_P (otherops[2]) |
| 20399 |
&& INTVAL (otherops[2]) > -256 |
| 20400 |
&& INTVAL (otherops[2]) < 256))) |
| 20401 |
{ |
| 20402 |
if (reg_overlap_mentioned_p (operands[0], |
| 20403 |
otherops[2])) |
| 20404 |
{ |
| 20405 |
/* Swap base and index registers over to |
| 20406 |
avoid a conflict. */ |
| 20407 |
std::swap (otherops[1], otherops[2]); |
| 20408 |
} |
| 20409 |
/* If both registers conflict, it will usually |
| 20410 |
have been fixed by a splitter. */ |
| 20411 |
if (reg_overlap_mentioned_p (operands[0], otherops[2]) |
| 20412 |
|| (fix_cm3_ldrd && reg0 == REGNO (otherops[1]))) |
| 20413 |
{ |
| 20414 |
if (emit) |
| 20415 |
{ |
| 20416 |
output_asm_insn ("add%?\t%0, %1, %2", otherops); |
| 20417 |
output_asm_insn ("ldrd%?\t%0, [%1]", operands); |
| 20418 |
} |
| 20419 |
if (count) |
| 20420 |
*count = 2; |
| 20421 |
} |
| 20422 |
else |
| 20423 |
{ |
| 20424 |
otherops[0] = operands[0]; |
| 20425 |
if (emit) |
| 20426 |
output_asm_insn ("ldrd%?\t%0, [%1, %2]", otherops); |
| 20427 |
} |
| 20428 |
return ""; |
| 20429 |
} |
| 20430 |
|
| 20431 |
if (CONST_INT_P (otherops[2])) |
| 20432 |
{ |
| 20433 |
if (emit) |
| 20434 |
{ |
| 20435 |
if (!(const_ok_for_arm (INTVAL (otherops[2])))) |
| 20436 |
output_asm_insn ("sub%?\t%0, %1, #%n2", otherops); |
| 20437 |
else |
| 20438 |
output_asm_insn ("add%?\t%0, %1, %2", otherops); |
| 20439 |
} |
| 20440 |
} |
| 20441 |
else |
| 20442 |
{ |
| 20443 |
if (emit) |
| 20444 |
output_asm_insn ("add%?\t%0, %1, %2", otherops); |
| 20445 |
} |
| 20446 |
} |
| 20447 |
else |
| 20448 |
{ |
| 20449 |
if (emit) |
| 20450 |
output_asm_insn ("sub%?\t%0, %1, %2", otherops); |
| 20451 |
} |
| 20452 |
|
| 20453 |
if (count) |
| 20454 |
*count = 2; |
| 20455 |
|
| 20456 |
if (can_ldrd) |
| 20457 |
return "ldrd%?\t%0, [%1]"; |
| 20458 |
|
| 20459 |
return "ldmia%?\t%1, %M0"; |
| 20460 |
} |
| 20461 |
else |
| 20462 |
{ |
| 20463 |
otherops[1] = adjust_address (operands[1], SImode, 4); |
| 20464 |
/* Take care of overlapping base/data reg. */ |
| 20465 |
if (reg_mentioned_p (operands[0], operands[1])) |
| 20466 |
{ |
| 20467 |
if (emit) |
| 20468 |
{ |
| 20469 |
output_asm_insn ("ldr%?\t%0, %1", otherops); |
| 20470 |
output_asm_insn ("ldr%?\t%0, %1", operands); |
| 20471 |
} |
| 20472 |
if (count) |
| 20473 |
*count = 2; |
| 20474 |
|
| 20475 |
} |
| 20476 |
else |
| 20477 |
{ |
| 20478 |
if (emit) |
| 20479 |
{ |
| 20480 |
output_asm_insn ("ldr%?\t%0, %1", operands); |
| 20481 |
output_asm_insn ("ldr%?\t%0, %1", otherops); |
| 20482 |
} |
| 20483 |
if (count) |
| 20484 |
*count = 2; |
| 20485 |
} |
| 20486 |
} |
| 20487 |
} |
| 20488 |
} |
| 20489 |
else |
| 20490 |
{ |
| 20491 |
/* Constraints should ensure this. */ |
| 20492 |
gcc_assert (code0 == MEM && code1 == REG); |
| 20493 |
gcc_assert ((REGNO (operands[1]) != IP_REGNUM) |
| 20494 |
|| (TARGET_ARM && TARGET_LDRD)); |
| 20495 |
|
| 20496 |
/* For TARGET_ARM the first source register of an STRD |
| 20497 |
must be even. This is usually the case for double-word |
| 20498 |
values but user assembly constraints can force an odd |
| 20499 |
starting register. */ |
| 20500 |
bool allow_strd = TARGET_LDRD |
| 20501 |
&& !(TARGET_ARM && (REGNO (operands[1]) & 1) == 1); |
| 20502 |
switch (GET_CODE (XEXP (operands[0], 0))) |
| 20503 |
{ |
| 20504 |
case REG: |
| 20505 |
if (emit) |
| 20506 |
{ |
| 20507 |
if (allow_strd) |
| 20508 |
output_asm_insn ("strd%?\t%1, [%m0]", operands); |
| 20509 |
else |
| 20510 |
output_asm_insn ("stm%?\t%m0, %M1", operands); |
| 20511 |
} |
| 20512 |
break; |
| 20513 |
|
| 20514 |
case PRE_INC: |
| 20515 |
gcc_assert (allow_strd); |
| 20516 |
if (emit) |
| 20517 |
output_asm_insn ("strd%?\t%1, [%m0, #8]!", operands); |
| 20518 |
break; |
| 20519 |
|
| 20520 |
case PRE_DEC: |
| 20521 |
if (emit) |
| 20522 |
{ |
| 20523 |
if (allow_strd) |
| 20524 |
output_asm_insn ("strd%?\t%1, [%m0, #-8]!", operands); |
| 20525 |
else |
| 20526 |
output_asm_insn ("stmdb%?\t%m0!, %M1", operands); |
| 20527 |
} |
| 20528 |
break; |
| 20529 |
|
| 20530 |
case POST_INC: |
| 20531 |
if (emit) |
| 20532 |
{ |
| 20533 |
if (allow_strd) |
| 20534 |
output_asm_insn ("strd%?\t%1, [%m0], #8", operands); |
| 20535 |
else |
| 20536 |
output_asm_insn ("stm%?\t%m0!, %M1", operands); |
| 20537 |
} |
| 20538 |
break; |
| 20539 |
|
| 20540 |
case POST_DEC: |
| 20541 |
gcc_assert (allow_strd); |
| 20542 |
if (emit) |
| 20543 |
output_asm_insn ("strd%?\t%1, [%m0], #-8", operands); |
| 20544 |
break; |
| 20545 |
|
| 20546 |
case PRE_MODIFY: |
| 20547 |
case POST_MODIFY: |
| 20548 |
otherops[0] = operands[1]; |
| 20549 |
otherops[1] = XEXP (XEXP (XEXP (operands[0], 0), 1), 0); |
| 20550 |
otherops[2] = XEXP (XEXP (XEXP (operands[0], 0), 1), 1); |
| 20551 |
|
| 20552 |
/* IWMMXT allows offsets larger than strd can handle, |
| 20553 |
fix these up with a pair of str. */ |
| 20554 |
if (!TARGET_THUMB2 |
| 20555 |
&& CONST_INT_P (otherops[2]) |
| 20556 |
&& (INTVAL(otherops[2]) <= -256 |
| 20557 |
|| INTVAL(otherops[2]) >= 256)) |
| 20558 |
{ |
| 20559 |
if (GET_CODE (XEXP (operands[0], 0)) == PRE_MODIFY) |
| 20560 |
{ |
| 20561 |
if (emit) |
| 20562 |
{ |
| 20563 |
output_asm_insn ("str%?\t%0, [%1, %2]!", otherops); |
| 20564 |
output_asm_insn ("str%?\t%H0, [%1, #4]", otherops); |
| 20565 |
} |
| 20566 |
if (count) |
| 20567 |
*count = 2; |
| 20568 |
} |
| 20569 |
else |
| 20570 |
{ |
| 20571 |
if (emit) |
| 20572 |
{ |
| 20573 |
output_asm_insn ("str%?\t%H0, [%1, #4]", otherops); |
| 20574 |
output_asm_insn ("str%?\t%0, [%1], %2", otherops); |
| 20575 |
} |
| 20576 |
if (count) |
| 20577 |
*count = 2; |
| 20578 |
} |
| 20579 |
} |
| 20580 |
else if (GET_CODE (XEXP (operands[0], 0)) == PRE_MODIFY) |
| 20581 |
{ |
| 20582 |
if (emit) |
| 20583 |
output_asm_insn ("strd%?\t%0, [%1, %2]!", otherops); |
| 20584 |
} |
| 20585 |
else |
| 20586 |
{ |
| 20587 |
if (emit) |
| 20588 |
output_asm_insn ("strd%?\t%0, [%1], %2", otherops); |
| 20589 |
} |
| 20590 |
break; |
| 20591 |
|
| 20592 |
case PLUS: |
| 20593 |
otherops[2] = XEXP (XEXP (operands[0], 0), 1); |
| 20594 |
if (CONST_INT_P (otherops[2]) && !TARGET_LDRD) |
| 20595 |
{ |
| 20596 |
switch ((int) INTVAL (XEXP (XEXP (operands[0], 0), 1))) |
| 20597 |
{ |
| 20598 |
case -8: |
| 20599 |
if (emit) |
| 20600 |
output_asm_insn ("stmdb%?\t%m0, %M1", operands); |
| 20601 |
return ""; |
| 20602 |
|
| 20603 |
case -4: |
| 20604 |
if (TARGET_THUMB2) |
| 20605 |
break; |
| 20606 |
if (emit) |
| 20607 |
output_asm_insn ("stmda%?\t%m0, %M1", operands); |
| 20608 |
return ""; |
| 20609 |
|
| 20610 |
case 4: |
| 20611 |
if (TARGET_THUMB2) |
| 20612 |
break; |
| 20613 |
if (emit) |
| 20614 |
output_asm_insn ("stmib%?\t%m0, %M1", operands); |
| 20615 |
return ""; |
| 20616 |
} |
| 20617 |
} |
| 20618 |
if (allow_strd |
| 20619 |
&& (REG_P (otherops[2]) |
| 20620 |
|| TARGET_THUMB2 |
| 20621 |
|| (CONST_INT_P (otherops[2]) |
| 20622 |
&& INTVAL (otherops[2]) > -256 |
| 20623 |
&& INTVAL (otherops[2]) < 256))) |
| 20624 |
{ |
| 20625 |
otherops[0] = operands[1]; |
| 20626 |
otherops[1] = XEXP (XEXP (operands[0], 0), 0); |
| 20627 |
if (emit) |
| 20628 |
output_asm_insn ("strd%?\t%0, [%1, %2]", otherops); |
| 20629 |
return ""; |
| 20630 |
} |
| 20631 |
/* Fall through */ |
| 20632 |
|
| 20633 |
default: |
| 20634 |
otherops[0] = adjust_address (operands[0], SImode, 4); |
| 20635 |
otherops[1] = operands[1]; |
| 20636 |
if (emit) |
| 20637 |
{ |
| 20638 |
output_asm_insn ("str%?\t%1, %0", operands); |
| 20639 |
output_asm_insn ("str%?\t%H1, %0", otherops); |
| 20640 |
} |
| 20641 |
if (count) |
| 20642 |
*count = 2; |
| 20643 |
} |
| 20644 |
} |
| 20645 |
|
| 20646 |
return ""; |
| 20647 |
} |
| 20648 |
|
| 20649 |
/* Output a move, load or store for quad-word vectors in ARM registers. Only |
| 20650 |
handles MEMs accepted by neon_vector_mem_operand with TYPE=1. */ |
| 20651 |
|
| 20652 |
const char * |
| 20653 |
output_move_quad (rtx *operands) |
| 20654 |
{ |
| 20655 |
if (REG_P (operands[0])) |
| 20656 |
{ |
| 20657 |
/* Load, or reg->reg move. */ |
| 20658 |
|
| 20659 |
if (MEM_P (operands[1])) |
| 20660 |
{ |
| 20661 |
switch (GET_CODE (XEXP (operands[1], 0))) |
| 20662 |
{ |
| 20663 |
case REG: |
| 20664 |
output_asm_insn ("ldmia%?\t%m1, %M0", operands); |
| 20665 |
break; |
| 20666 |
|
| 20667 |
case LABEL_REF: |
| 20668 |
case CONST: |
| 20669 |
output_asm_insn ("adr%?\t%0, %1", operands); |
| 20670 |
output_asm_insn ("ldmia%?\t%0, %M0", operands); |
| 20671 |
break; |
| 20672 |
|
| 20673 |
default: |
| 20674 |
gcc_unreachable (); |
| 20675 |
} |
| 20676 |
} |
| 20677 |
else |
| 20678 |
{ |
| 20679 |
rtx ops[2]; |
| 20680 |
int dest, src, i; |
| 20681 |
|
| 20682 |
gcc_assert (REG_P (operands[1])); |
| 20683 |
|
| 20684 |
dest = REGNO (operands[0]); |
| 20685 |
src = REGNO (operands[1]); |
| 20686 |
|
| 20687 |
/* This seems pretty dumb, but hopefully GCC won't try to do it |
| 20688 |
very often. */ |
| 20689 |
if (dest < src) |
| 20690 |
for (i = 0; i < 4; i++) |
| 20691 |
{ |
| 20692 |
ops[0] = gen_rtx_REG (SImode, dest + i); |
| 20693 |
ops[1] = gen_rtx_REG (SImode, src + i); |
| 20694 |
output_asm_insn ("mov%?\t%0, %1", ops); |
| 20695 |
} |
| 20696 |
else |
| 20697 |
for (i = 3; i >= 0; i--) |
| 20698 |
{ |
| 20699 |
ops[0] = gen_rtx_REG (SImode, dest + i); |
| 20700 |
ops[1] = gen_rtx_REG (SImode, src + i); |
| 20701 |
output_asm_insn ("mov%?\t%0, %1", ops); |
| 20702 |
} |
| 20703 |
} |
| 20704 |
} |
| 20705 |
else |
| 20706 |
{ |
| 20707 |
gcc_assert (MEM_P (operands[0])); |
| 20708 |
gcc_assert (REG_P (operands[1])); |
| 20709 |
gcc_assert (!reg_overlap_mentioned_p (operands[1], operands[0])); |
| 20710 |
|
| 20711 |
switch (GET_CODE (XEXP (operands[0], 0))) |
| 20712 |
{ |
| 20713 |
case REG: |
| 20714 |
output_asm_insn ("stm%?\t%m0, %M1", operands); |
| 20715 |
break; |
| 20716 |
|
| 20717 |
default: |
| 20718 |
gcc_unreachable (); |
| 20719 |
} |
| 20720 |
} |
| 20721 |
|
| 20722 |
return ""; |
| 20723 |
} |
| 20724 |
|
| 20725 |
/* Output a VFP load or store instruction. */ |
| 20726 |
|
| 20727 |
const char * |
| 20728 |
output_move_vfp (rtx *operands) |
| 20729 |
{ |
| 20730 |
rtx reg, mem, addr, ops[2]; |
| 20731 |
int load = REG_P (operands[0]); |
| 20732 |
int dp = GET_MODE_SIZE (GET_MODE (operands[0])) == 8; |
| 20733 |
int sp = (!TARGET_VFP_FP16INST |
| 20734 |
|| GET_MODE_SIZE (GET_MODE (operands[0])) == 4); |
| 20735 |
int integer_p = GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT; |
| 20736 |
const char *templ; |
| 20737 |
char buff[50]; |
| 20738 |
machine_mode mode; |
| 20739 |
|
| 20740 |
reg = operands[!load]; |
| 20741 |
mem = operands[load]; |
| 20742 |
|
| 20743 |
mode = GET_MODE (reg); |
| 20744 |
|
| 20745 |
gcc_assert (REG_P (reg)); |
| 20746 |
gcc_assert (IS_VFP_REGNUM (REGNO (reg))); |
| 20747 |
gcc_assert ((mode == HFmode && TARGET_HARD_FLOAT) |
| 20748 |
|| mode == SFmode |
| 20749 |
|| mode == DFmode |
| 20750 |
|| mode == HImode |
| 20751 |
|| mode == SImode |
| 20752 |
|| mode == DImode |
| 20753 |
|| (TARGET_NEON && VALID_NEON_DREG_MODE (mode))); |
| 20754 |
gcc_assert (MEM_P (mem)); |
| 20755 |
|
| 20756 |
addr = XEXP (mem, 0); |
| 20757 |
|
| 20758 |
switch (GET_CODE (addr)) |
| 20759 |
{ |
| 20760 |
case PRE_DEC: |
| 20761 |
templ = "v%smdb%%?.%s\t%%0!, {%%%s1}%s"; |
| 20762 |
ops[0] = XEXP (addr, 0); |
| 20763 |
ops[1] = reg; |
| 20764 |
break; |
| 20765 |
|
| 20766 |
case POST_INC: |
| 20767 |
templ = "v%smia%%?.%s\t%%0!, {%%%s1}%s"; |
| 20768 |
ops[0] = XEXP (addr, 0); |
| 20769 |
ops[1] = reg; |
| 20770 |
break; |
| 20771 |
|
| 20772 |
default: |
| 20773 |
templ = "v%sr%%?.%s\t%%%s0, %%1%s"; |
| 20774 |
ops[0] = reg; |
| 20775 |
ops[1] = mem; |
| 20776 |
break; |
| 20777 |
} |
| 20778 |
|
| 20779 |
sprintf (buff, templ, |
| 20780 |
load ? "ld" : "st", |
| 20781 |
dp ? "64" : sp ? "32" : "16", |
| 20782 |
dp ? "P" : "", |
| 20783 |
integer_p ? "\t%@ int" : ""); |
| 20784 |
output_asm_insn (buff, ops); |
| 20785 |
|
| 20786 |
return ""; |
| 20787 |
} |
| 20788 |
|
| 20789 |
/* Output a Neon double-word or quad-word load or store, or a load |
| 20790 |
or store for larger structure modes. |
| 20791 |
|
| 20792 |
WARNING: The ordering of elements is weird in big-endian mode, |
| 20793 |
because the EABI requires that vectors stored in memory appear |
| 20794 |
as though they were stored by a VSTM, as required by the EABI. |
| 20795 |
GCC RTL defines element ordering based on in-memory order. |
| 20796 |
This can be different from the architectural ordering of elements |
| 20797 |
within a NEON register. The intrinsics defined in arm_neon.h use the |
| 20798 |
NEON register element ordering, not the GCC RTL element ordering. |
| 20799 |
|
| 20800 |
For example, the in-memory ordering of a big-endian a quadword |
| 20801 |
vector with 16-bit elements when stored from register pair {d0,d1} |
| 20802 |
will be (lowest address first, d0[N] is NEON register element N): |
| 20803 |
|
| 20804 |
[d0[3], d0[2], d0[1], d0[0], d1[7], d1[6], d1[5], d1[4]] |
| 20805 |
|
| 20806 |
When necessary, quadword registers (dN, dN+1) are moved to ARM |
| 20807 |
registers from rN in the order: |
| 20808 |
|
| 20809 |
dN -> (rN+1, rN), dN+1 -> (rN+3, rN+2) |
| 20810 |
|
| 20811 |
So that STM/LDM can be used on vectors in ARM registers, and the |
| 20812 |
same memory layout will result as if VSTM/VLDM were used. |
| 20813 |
|
| 20814 |
Instead of VSTM/VLDM we prefer to use VST1.64/VLD1.64 where |
| 20815 |
possible, which allows use of appropriate alignment tags. |
| 20816 |
Note that the choice of "64" is independent of the actual vector |
| 20817 |
element size; this size simply ensures that the behavior is |
| 20818 |
equivalent to VSTM/VLDM in both little-endian and big-endian mode. |
| 20819 |
|
| 20820 |
Due to limitations of those instructions, use of VST1.64/VLD1.64 |
| 20821 |
is not possible if: |
| 20822 |
- the address contains PRE_DEC, or |
| 20823 |
- the mode refers to more than 4 double-word registers |
| 20824 |
|
| 20825 |
In those cases, it would be possible to replace VSTM/VLDM by a |
| 20826 |
sequence of instructions; this is not currently implemented since |
| 20827 |
this is not certain to actually improve performance. */ |
| 20828 |
|
| 20829 |
const char * |
| 20830 |
output_move_neon (rtx *operands) |
| 20831 |
{ |
| 20832 |
rtx reg, mem, addr, ops[2]; |
| 20833 |
int regno, nregs, load = REG_P (operands[0]); |
| 20834 |
const char *templ; |
| 20835 |
char buff[50]; |
| 20836 |
machine_mode mode; |
| 20837 |
|
| 20838 |
reg = operands[!load]; |
| 20839 |
mem = operands[load]; |
| 20840 |
|
| 20841 |
mode = GET_MODE (reg); |
| 20842 |
|
| 20843 |
gcc_assert (REG_P (reg)); |
| 20844 |
regno = REGNO (reg); |
| 20845 |
nregs = REG_NREGS (reg) / 2; |
| 20846 |
gcc_assert (VFP_REGNO_OK_FOR_DOUBLE (regno) |
| 20847 |
|| NEON_REGNO_OK_FOR_QUAD (regno)); |
| 20848 |
gcc_assert ((TARGET_NEON |
| 20849 |
&& (VALID_NEON_DREG_MODE (mode) |
| 20850 |
|| VALID_NEON_QREG_MODE (mode) |
| 20851 |
|| VALID_NEON_STRUCT_MODE (mode))) |
| 20852 |
|| (TARGET_HAVE_MVE |
| 20853 |
&& (VALID_MVE_MODE (mode) |
| 20854 |
|| VALID_MVE_STRUCT_MODE (mode)))); |
| 20855 |
gcc_assert (MEM_P (mem)); |
| 20856 |
|
| 20857 |
addr = XEXP (mem, 0); |
| 20858 |
|
| 20859 |
/* Strip off const from addresses like (const (plus (...))). */ |
| 20860 |
if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS) |
| 20861 |
addr = XEXP (addr, 0); |
| 20862 |
|
| 20863 |
switch (GET_CODE (addr)) |
| 20864 |
{ |
| 20865 |
case POST_INC: |
| 20866 |
/* We have to use vldm / vstm for too-large modes. */ |
| 20867 |
if (nregs > 4 || (TARGET_HAVE_MVE && nregs >= 2)) |
| 20868 |
{ |
| 20869 |
templ = "v%smia%%?\t%%0!, %%h1"; |
| 20870 |
ops[0] = XEXP (addr, 0); |
| 20871 |
} |
| 20872 |
else |
| 20873 |
{ |
| 20874 |
templ = "v%s1.64\t%%h1, %%A0"; |
| 20875 |
ops[0] = mem; |
| 20876 |
} |
| 20877 |
ops[1] = reg; |
| 20878 |
break; |
| 20879 |
|
| 20880 |
case PRE_DEC: |
| 20881 |
/* We have to use vldm / vstm in this case, since there is no |
| 20882 |
pre-decrement form of the vld1 / vst1 instructions. */ |
| 20883 |
templ = "v%smdb%%?\t%%0!, %%h1"; |
| 20884 |
ops[0] = XEXP (addr, 0); |
| 20885 |
ops[1] = reg; |
| 20886 |
break; |
| 20887 |
|
| 20888 |
case POST_MODIFY: |
| 20889 |
/* FIXME: Not currently enabled in neon_vector_mem_operand. */ |
| 20890 |
gcc_unreachable (); |
| 20891 |
|
| 20892 |
case REG: |
| 20893 |
/* We have to use vldm / vstm for too-large modes. */ |
| 20894 |
if (nregs > 1) |
| 20895 |
{ |
| 20896 |
if (nregs > 4 || (TARGET_HAVE_MVE && nregs >= 2)) |
| 20897 |
templ = "v%smia%%?\t%%m0, %%h1"; |
| 20898 |
else |
| 20899 |
templ = "v%s1.64\t%%h1, %%A0"; |
| 20900 |
|
| 20901 |
ops[0] = mem; |
| 20902 |
ops[1] = reg; |
| 20903 |
break; |
| 20904 |
} |
| 20905 |
/* Fall through. */ |
| 20906 |
case PLUS: |
| 20907 |
if (GET_CODE (addr) == PLUS) |
| 20908 |
addr = XEXP (addr, 0); |
| 20909 |
/* Fall through. */ |
| 20910 |
case LABEL_REF: |
| 20911 |
{ |
| 20912 |
int i; |
| 20913 |
int overlap = -1; |
| 20914 |
for (i = 0; i < nregs; i++) |
| 20915 |
{ |
| 20916 |
/* Use DFmode for vldr/vstr. */ |
| 20917 |
ops[0] = gen_rtx_REG (DFmode, REGNO (reg) + 2 * i); |
| 20918 |
ops[1] = adjust_address_nv (mem, DFmode, 8 * i); |
| 20919 |
if (reg_overlap_mentioned_p (ops[0], mem)) |
| 20920 |
{ |
| 20921 |
gcc_assert (overlap == -1); |
| 20922 |
overlap = i; |
| 20923 |
} |
| 20924 |
else |
| 20925 |
{ |
| 20926 |
if (TARGET_HAVE_MVE && LABEL_REF_P (addr)) |
| 20927 |
sprintf (buff, "v%sr.64\t%%P0, %%1", load ? "ld" : "st"); |
| 20928 |
else |
| 20929 |
sprintf (buff, "v%sr%%?\t%%P0, %%1", load ? "ld" : "st"); |
| 20930 |
output_asm_insn (buff, ops); |
| 20931 |
} |
| 20932 |
} |
| 20933 |
if (overlap != -1) |
| 20934 |
{ |
| 20935 |
ops[0] = gen_rtx_REG (DFmode, REGNO (reg) + 2 * overlap); |
| 20936 |
ops[1] = adjust_address_nv (mem, DFmode, 8 * overlap); |
| 20937 |
if (TARGET_HAVE_MVE && LABEL_REF_P (addr)) |
| 20938 |
sprintf (buff, "v%sr.32\t%%P0, %%1", load ? "ld" : "st"); |
| 20939 |
else |
| 20940 |
sprintf (buff, "v%sr%%?\t%%P0, %%1", load ? "ld" : "st"); |
| 20941 |
output_asm_insn (buff, ops); |
| 20942 |
} |
| 20943 |
|
| 20944 |
return ""; |
| 20945 |
} |
| 20946 |
|
| 20947 |
default: |
| 20948 |
gcc_unreachable (); |
| 20949 |
} |
| 20950 |
|
| 20951 |
sprintf (buff, templ, load ? "ld" : "st"); |
| 20952 |
output_asm_insn (buff, ops); |
| 20953 |
|
| 20954 |
return ""; |
| 20955 |
} |
| 20956 |
|
| 20957 |
/* Compute and return the length of neon_mov<mode>, where <mode> is one of |
| 20958 |
VSTRUCT modes: EI, OI, CI or XI for Neon, and V2x16QI, V2x8HI, V2x4SI, |
| 20959 |
V2x8HF, V2x4SF, V2x16QI, V2x8HI, V2x4SI, V2x8HF, V2x4SF for MVE. */ |
| 20960 |
int |
| 20961 |
arm_attr_length_move_neon (rtx_insn *insn) |
| 20962 |
{ |
| 20963 |
rtx reg, mem, addr; |
| 20964 |
int load; |
| 20965 |
machine_mode mode; |
| 20966 |
|
| 20967 |
extract_insn_cached (insn); |
| 20968 |
|
| 20969 |
if (REG_P (recog_data.operand[0]) && REG_P (recog_data.operand[1])) |
| 20970 |
{ |
| 20971 |
mode = GET_MODE (recog_data.operand[0]); |
| 20972 |
switch (mode) |
| 20973 |
{ |
| 20974 |
case E_EImode: |
| 20975 |
case E_OImode: |
| 20976 |
case E_V2x16QImode: |
| 20977 |
case E_V2x8HImode: |
| 20978 |
case E_V2x4SImode: |
| 20979 |
case E_V2x8HFmode: |
| 20980 |
case E_V2x4SFmode: |
| 20981 |
return 8; |
| 20982 |
case E_CImode: |
| 20983 |
return 12; |
| 20984 |
case E_XImode: |
| 20985 |
case E_V4x16QImode: |
| 20986 |
case E_V4x8HImode: |
| 20987 |
case E_V4x4SImode: |
| 20988 |
case E_V4x8HFmode: |
| 20989 |
case E_V4x4SFmode: |
| 20990 |
return 16; |
| 20991 |
default: |
| 20992 |
gcc_unreachable (); |
| 20993 |
} |
| 20994 |
} |
| 20995 |
|
| 20996 |
load = REG_P (recog_data.operand[0]); |
| 20997 |
reg = recog_data.operand[!load]; |
| 20998 |
mem = recog_data.operand[load]; |
| 20999 |
|
| 21000 |
gcc_assert (MEM_P (mem)); |
| 21001 |
|
| 21002 |
addr = XEXP (mem, 0); |
| 21003 |
|
| 21004 |
/* Strip off const from addresses like (const (plus (...))). */ |
| 21005 |
if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS) |
| 21006 |
addr = XEXP (addr, 0); |
| 21007 |
|
| 21008 |
if (LABEL_REF_P (addr) || GET_CODE (addr) == PLUS) |
| 21009 |
{ |
| 21010 |
int insns = REG_NREGS (reg) / 2; |
| 21011 |
return insns * 4; |
| 21012 |
} |
| 21013 |
else |
| 21014 |
return 4; |
| 21015 |
} |
| 21016 |
|
| 21017 |
/* Return nonzero if the offset in the address is an immediate. Otherwise, |
| 21018 |
return zero. */ |
| 21019 |
|
| 21020 |
int |
| 21021 |
arm_address_offset_is_imm (rtx_insn *insn) |
| 21022 |
{ |
| 21023 |
rtx mem, addr; |
| 21024 |
|
| 21025 |
extract_insn_cached (insn); |
| 21026 |
|
| 21027 |
if (REG_P (recog_data.operand[0])) |
| 21028 |
return 0; |
| 21029 |
|
| 21030 |
mem = recog_data.operand[0]; |
| 21031 |
|
| 21032 |
gcc_assert (MEM_P (mem)); |
| 21033 |
|
| 21034 |
addr = XEXP (mem, 0); |
| 21035 |
|
| 21036 |
if (REG_P (addr) |
| 21037 |
|| (GET_CODE (addr) == PLUS |
| 21038 |
&& REG_P (XEXP (addr, 0)) |
| 21039 |
&& CONST_INT_P (XEXP (addr, 1)))) |
| 21040 |
return 1; |
| 21041 |
else |
| 21042 |
return 0; |
| 21043 |
} |
| 21044 |
|
| 21045 |
/* Output an ADD r, s, #n where n may be too big for one instruction. |
| 21046 |
If adding zero to one register, output nothing. */ |
| 21047 |
const char * |
| 21048 |
output_add_immediate (rtx *operands) |
| 21049 |
{ |
| 21050 |
HOST_WIDE_INT n = INTVAL (operands[2]); |
| 21051 |
|
| 21052 |
if (n != 0 || REGNO (operands[0]) != REGNO (operands[1])) |
| 21053 |
{ |
| 21054 |
if (n < 0) |
| 21055 |
output_multi_immediate (operands, |
| 21056 |
"sub%?\t%0, %1, %2", "sub%?\t%0, %0, %2", 2, |
| 21057 |
-n); |
| 21058 |
else |
| 21059 |
output_multi_immediate (operands, |
| 21060 |
"add%?\t%0, %1, %2", "add%?\t%0, %0, %2", 2, |
| 21061 |
n); |
| 21062 |
} |
| 21063 |
|
| 21064 |
return ""; |
| 21065 |
} |
| 21066 |
|
| 21067 |
/* Output a multiple immediate operation. |
| 21068 |
OPERANDS is the vector of operands referred to in the output patterns. |
| 21069 |
INSTR1 is the output pattern to use for the first constant. |
| 21070 |
INSTR2 is the output pattern to use for subsequent constants. |
| 21071 |
IMMED_OP is the index of the constant slot in OPERANDS. |
| 21072 |
N is the constant value. */ |
| 21073 |
static const char * |
| 21074 |
output_multi_immediate (rtx *operands, const char *instr1, const char *instr2, |
| 21075 |
int immed_op, HOST_WIDE_INT n) |
| 21076 |
{ |
| 21077 |
#if HOST_BITS_PER_WIDE_INT > 32 |
| 21078 |
n &= 0xffffffff; |
| 21079 |
#endif |
| 21080 |
|
| 21081 |
if (n == 0) |
| 21082 |
{ |
| 21083 |
/* Quick and easy output. */ |
| 21084 |
operands[immed_op] = const0_rtx; |
| 21085 |
output_asm_insn (instr1, operands); |
| 21086 |
} |
| 21087 |
else |
| 21088 |
{ |
| 21089 |
int i; |
| 21090 |
const char * instr = instr1; |
| 21091 |
|
| 21092 |
/* Note that n is never zero here (which would give no output). */ |
| 21093 |
for (i = 0; i < 32; i += 2) |
| 21094 |
{ |
| 21095 |
if (n & (3 << i)) |
| 21096 |
{ |
| 21097 |
operands[immed_op] = GEN_INT (n & (255 << i)); |
| 21098 |
output_asm_insn (instr, operands); |
| 21099 |
instr = instr2; |
| 21100 |
i += 6; |
| 21101 |
} |
| 21102 |
} |
| 21103 |
} |
| 21104 |
|
| 21105 |
return ""; |
| 21106 |
} |
| 21107 |
|
| 21108 |
/* Return the name of a shifter operation. */ |
| 21109 |
static const char * |
| 21110 |
arm_shift_nmem(enum rtx_code code) |
| 21111 |
{ |
| 21112 |
switch (code) |
| 21113 |
{ |
| 21114 |
case ASHIFT: |
| 21115 |
return ARM_LSL_NAME; |
| 21116 |
|
| 21117 |
case ASHIFTRT: |
| 21118 |
return "asr"; |
| 21119 |
|
| 21120 |
case LSHIFTRT: |
| 21121 |
return "lsr"; |
| 21122 |
|
| 21123 |
case ROTATERT: |
| 21124 |
return "ror"; |
| 21125 |
|
| 21126 |
default: |
| 21127 |
abort(); |
| 21128 |
} |
| 21129 |
} |
| 21130 |
|
| 21131 |
/* Return the appropriate ARM instruction for the operation code. |
| 21132 |
The returned result should not be overwritten. OP is the rtx of the |
| 21133 |
operation. SHIFT_FIRST_ARG is TRUE if the first argument of the operator |
| 21134 |
was shifted. */ |
| 21135 |
const char * |
| 21136 |
arithmetic_instr (rtx op, int shift_first_arg) |
| 21137 |
{ |
| 21138 |
switch (GET_CODE (op)) |
| 21139 |
{ |
| 21140 |
case PLUS: |
| 21141 |
return "add"; |
| 21142 |
|
| 21143 |
case MINUS: |
| 21144 |
return shift_first_arg ? "rsb" : "sub"; |
| 21145 |
|
| 21146 |
case IOR: |
| 21147 |
return "orr"; |
| 21148 |
|
| 21149 |
case XOR: |
| 21150 |
return "eor"; |
| 21151 |
|
| 21152 |
case AND: |
| 21153 |
return "and"; |
| 21154 |
|
| 21155 |
case ASHIFT: |
| 21156 |
case ASHIFTRT: |
| 21157 |
case LSHIFTRT: |
| 21158 |
case ROTATERT: |
| 21159 |
return arm_shift_nmem(GET_CODE(op)); |
| 21160 |
|
| 21161 |
default: |
| 21162 |
gcc_unreachable (); |
| 21163 |
} |
| 21164 |
} |
| 21165 |
|
| 21166 |
/* Ensure valid constant shifts and return the appropriate shift mnemonic |
| 21167 |
for the operation code. The returned result should not be overwritten. |
| 21168 |
OP is the rtx code of the shift. |
| 21169 |
On exit, *AMOUNTP will be -1 if the shift is by a register, or a constant |
| 21170 |
shift. */ |
| 21171 |
static const char * |
| 21172 |
shift_op (rtx op, HOST_WIDE_INT *amountp) |
| 21173 |
{ |
| 21174 |
const char * mnem; |
| 21175 |
enum rtx_code code = GET_CODE (op); |
| 21176 |
|
| 21177 |
switch (code) |
| 21178 |
{ |
| 21179 |
case ROTATE: |
| 21180 |
if (!CONST_INT_P (XEXP (op, 1))) |
| 21181 |
{ |
| 21182 |
output_operand_lossage ("invalid shift operand"); |
| 21183 |
return NULL; |
| 21184 |
} |
| 21185 |
|
| 21186 |
code = ROTATERT; |
| 21187 |
*amountp = 32 - INTVAL (XEXP (op, 1)); |
| 21188 |
mnem = "ror"; |
| 21189 |
break; |
| 21190 |
|
| 21191 |
case ASHIFT: |
| 21192 |
case ASHIFTRT: |
| 21193 |
case LSHIFTRT: |
| 21194 |
case ROTATERT: |
| 21195 |
mnem = arm_shift_nmem(code); |
| 21196 |
if (CONST_INT_P (XEXP (op, 1))) |
| 21197 |
{ |
| 21198 |
*amountp = INTVAL (XEXP (op, 1)); |
| 21199 |
} |
| 21200 |
else if (REG_P (XEXP (op, 1))) |
| 21201 |
{ |
| 21202 |
*amountp = -1; |
| 21203 |
return mnem; |
| 21204 |
} |
| 21205 |
else |
| 21206 |
{ |
| 21207 |
output_operand_lossage ("invalid shift operand"); |
| 21208 |
return NULL; |
| 21209 |
} |
| 21210 |
break; |
| 21211 |
|
| 21212 |
case MULT: |
| 21213 |
/* We never have to worry about the amount being other than a |
| 21214 |
power of 2, since this case can never be reloaded from a reg. */ |
| 21215 |
if (!CONST_INT_P (XEXP (op, 1))) |
| 21216 |
{ |
| 21217 |
output_operand_lossage ("invalid shift operand"); |
| 21218 |
return NULL; |
| 21219 |
} |
| 21220 |
|
| 21221 |
*amountp = INTVAL (XEXP (op, 1)) & 0xFFFFFFFF; |
| 21222 |
|
| 21223 |
/* Amount must be a power of two. */ |
| 21224 |
if (*amountp & (*amountp - 1)) |
| 21225 |
{ |
| 21226 |
output_operand_lossage ("invalid shift operand"); |
| 21227 |
return NULL; |
| 21228 |
} |
| 21229 |
|
| 21230 |
*amountp = exact_log2 (*amountp); |
| 21231 |
gcc_assert (IN_RANGE (*amountp, 0, 31)); |
| 21232 |
return ARM_LSL_NAME; |
| 21233 |
|
| 21234 |
default: |
| 21235 |
output_operand_lossage ("invalid shift operand"); |
| 21236 |
return NULL; |
| 21237 |
} |
| 21238 |
|
| 21239 |
/* This is not 100% correct, but follows from the desire to merge |
| 21240 |
multiplication by a power of 2 with the recognizer for a |
| 21241 |
shift. >=32 is not a valid shift for "lsl", so we must try and |
| 21242 |
output a shift that produces the correct arithmetical result. |
| 21243 |
Using lsr #32 is identical except for the fact that the carry bit |
| 21244 |
is not set correctly if we set the flags; but we never use the |
| 21245 |
carry bit from such an operation, so we can ignore that. */ |
| 21246 |
if (code == ROTATERT) |
| 21247 |
/* Rotate is just modulo 32. */ |
| 21248 |
*amountp &= 31; |
| 21249 |
else if (*amountp != (*amountp & 31)) |
| 21250 |
{ |
| 21251 |
if (code == ASHIFT) |
| 21252 |
mnem = "lsr"; |
| 21253 |
*amountp = 32; |
| 21254 |
} |
| 21255 |
|
| 21256 |
/* Shifts of 0 are no-ops. */ |
| 21257 |
if (*amountp == 0) |
| 21258 |
return NULL; |
| 21259 |
|
| 21260 |
return mnem; |
| 21261 |
} |
| 21262 |
|
| 21263 |
/* Output a .ascii pseudo-op, keeping track of lengths. This is |
| 21264 |
because /bin/as is horribly restrictive. The judgement about |
| 21265 |
whether or not each character is 'printable' (and can be output as |
| 21266 |
is) or not (and must be printed with an octal escape) must be made |
| 21267 |
with reference to the *host* character set -- the situation is |
| 21268 |
similar to that discussed in the comments above pp_c_char in |
| 21269 |
c-pretty-print.cc. */ |
| 21270 |
|
| 21271 |
#define MAX_ASCII_LEN 51 |
| 21272 |
|
| 21273 |
void |
| 21274 |
output_ascii_pseudo_op (FILE *stream, const unsigned char *p, int len) |
| 21275 |
{ |
| 21276 |
int i; |
| 21277 |
int len_so_far = 0; |
| 21278 |
|
| 21279 |
fputs ("\t.ascii\t\"", stream); |
| 21280 |
|
| 21281 |
for (i = 0; i < len; i++) |
| 21282 |
{ |
| 21283 |
int c = p[i]; |
| 21284 |
|
| 21285 |
if (len_so_far >= MAX_ASCII_LEN) |
| 21286 |
{ |
| 21287 |
fputs ("\"\n\t.ascii\t\"", stream); |
| 21288 |
len_so_far = 0; |
| 21289 |
} |
| 21290 |
|
| 21291 |
if (ISPRINT (c)) |
| 21292 |
{ |
| 21293 |
if (c == '\\' || c == '\"') |
| 21294 |
{ |
| 21295 |
putc ('\\', stream); |
| 21296 |
len_so_far++; |
| 21297 |
} |
| 21298 |
putc (c, stream); |
| 21299 |
len_so_far++; |
| 21300 |
} |
| 21301 |
else |
| 21302 |
{ |
| 21303 |
fprintf (stream, "\\%03o", c); |
| 21304 |
len_so_far += 4; |
| 21305 |
} |
| 21306 |
} |
| 21307 |
|
| 21308 |
fputs ("\"\n", stream); |
| 21309 |
} |
| 21310 |
|
| 21311 |
|
| 21312 |
/* Compute the register save mask for registers 0 through 12 |
| 21313 |
inclusive. This code is used by arm_compute_save_core_reg_mask (). */ |
| 21314 |
|
| 21315 |
static unsigned long |
| 21316 |
arm_compute_save_reg0_reg12_mask (void) |
| 21317 |
{ |
| 21318 |
unsigned long func_type = arm_current_func_type (); |
| 21319 |
unsigned long save_reg_mask = 0; |
| 21320 |
unsigned int reg; |
| 21321 |
|
| 21322 |
if (IS_INTERRUPT (func_type)) |
| 21323 |
{ |
| 21324 |
unsigned int max_reg; |
| 21325 |
/* Interrupt functions must not corrupt any registers, |
| 21326 |
even call clobbered ones. If this is a leaf function |
| 21327 |
we can just examine the registers used by the RTL, but |
| 21328 |
otherwise we have to assume that whatever function is |
| 21329 |
called might clobber anything, and so we have to save |
| 21330 |
all the call-clobbered registers as well. */ |
| 21331 |
if (ARM_FUNC_TYPE (func_type) == ARM_FT_FIQ) |
| 21332 |
/* FIQ handlers have registers r8 - r12 banked, so |
| 21333 |
we only need to check r0 - r7, Normal ISRs only |
| 21334 |
bank r14 and r15, so we must check up to r12. |
| 21335 |
r13 is the stack pointer which is always preserved, |
| 21336 |
so we do not need to consider it here. */ |
| 21337 |
max_reg = 7; |
| 21338 |
else |
| 21339 |
max_reg = 12; |
| 21340 |
|
| 21341 |
for (reg = 0; reg <= max_reg; reg++) |
| 21342 |
if (reg_needs_saving_p (reg)) |
| 21343 |
save_reg_mask |= (1 << reg); |
| 21344 |
|
| 21345 |
/* Also save the pic base register if necessary. */ |
| 21346 |
if (PIC_REGISTER_MAY_NEED_SAVING |
| 21347 |
&& crtl->uses_pic_offset_table) |
| 21348 |
save_reg_mask |= 1 << PIC_OFFSET_TABLE_REGNUM; |
| 21349 |
} |
| 21350 |
else if (IS_VOLATILE(func_type)) |
| 21351 |
{ |
| 21352 |
/* For noreturn functions we historically omitted register saves |
| 21353 |
altogether. However this really messes up debugging. As a |
| 21354 |
compromise save just the frame pointers. Combined with the link |
| 21355 |
register saved elsewhere this should be sufficient to get |
| 21356 |
a backtrace. */ |
| 21357 |
if (frame_pointer_needed) |
| 21358 |
save_reg_mask |= 1 << HARD_FRAME_POINTER_REGNUM; |
| 21359 |
if (df_regs_ever_live_p (ARM_HARD_FRAME_POINTER_REGNUM)) |
| 21360 |
save_reg_mask |= 1 << ARM_HARD_FRAME_POINTER_REGNUM; |
| 21361 |
if (df_regs_ever_live_p (THUMB_HARD_FRAME_POINTER_REGNUM)) |
| 21362 |
save_reg_mask |= 1 << THUMB_HARD_FRAME_POINTER_REGNUM; |
| 21363 |
} |
| 21364 |
else |
| 21365 |
{ |
| 21366 |
/* In the normal case we only need to save those registers |
| 21367 |
which are call saved and which are used by this function. */ |
| 21368 |
for (reg = 0; reg <= 11; reg++) |
| 21369 |
if (df_regs_ever_live_p (reg) && callee_saved_reg_p (reg)) |
| 21370 |
save_reg_mask |= (1 << reg); |
| 21371 |
|
| 21372 |
/* Handle the frame pointer as a special case. */ |
| 21373 |
if (frame_pointer_needed) |
| 21374 |
save_reg_mask |= 1 << HARD_FRAME_POINTER_REGNUM; |
| 21375 |
|
| 21376 |
/* If we aren't loading the PIC register, |
| 21377 |
don't stack it even though it may be live. */ |
| 21378 |
if (PIC_REGISTER_MAY_NEED_SAVING |
| 21379 |
&& (df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM) |
| 21380 |
|| crtl->uses_pic_offset_table)) |
| 21381 |
save_reg_mask |= 1 << PIC_OFFSET_TABLE_REGNUM; |
| 21382 |
|
| 21383 |
/* The prologue will copy SP into R0, so save it. */ |
| 21384 |
if (IS_STACKALIGN (func_type)) |
| 21385 |
save_reg_mask |= 1; |
| 21386 |
} |
| 21387 |
|
| 21388 |
/* Save registers so the exception handler can modify them. */ |
| 21389 |
if (crtl->calls_eh_return) |
| 21390 |
{ |
| 21391 |
unsigned int i; |
| 21392 |
|
| 21393 |
for (i = 0; ; i++) |
| 21394 |
{ |
| 21395 |
reg = EH_RETURN_DATA_REGNO (i); |
| 21396 |
if (reg == INVALID_REGNUM) |
| 21397 |
break; |
| 21398 |
save_reg_mask |= 1 << reg; |
| 21399 |
} |
| 21400 |
} |
| 21401 |
|
| 21402 |
return save_reg_mask; |
| 21403 |
} |
| 21404 |
|
| 21405 |
/* Return true if r3 is live at the start of the function. */ |
| 21406 |
|
| 21407 |
static bool |
| 21408 |
arm_r3_live_at_start_p (void) |
| 21409 |
{ |
| 21410 |
/* Just look at cfg info, which is still close enough to correct at this |
| 21411 |
point. This gives false positives for broken functions that might use |
| 21412 |
uninitialized data that happens to be allocated in r3, but who cares? */ |
| 21413 |
return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)), 3); |
| 21414 |
} |
| 21415 |
|
| 21416 |
/* Compute the number of bytes used to store the static chain register on the |
| 21417 |
stack, above the stack frame. We need to know this accurately to get the |
| 21418 |
alignment of the rest of the stack frame correct. */ |
| 21419 |
|
| 21420 |
static int |
| 21421 |
arm_compute_static_chain_stack_bytes (void) |
| 21422 |
{ |
| 21423 |
/* Once the value is updated from the init value of -1, do not |
| 21424 |
re-compute. */ |
| 21425 |
if (cfun->machine->static_chain_stack_bytes != -1) |
| 21426 |
return cfun->machine->static_chain_stack_bytes; |
| 21427 |
|
| 21428 |
/* See the defining assertion in arm_expand_prologue. */ |
| 21429 |
if (IS_NESTED (arm_current_func_type ()) |
| 21430 |
&& ((TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM) |
| 21431 |
|| ((flag_stack_check == STATIC_BUILTIN_STACK_CHECK |
| 21432 |
|| flag_stack_clash_protection) |
| 21433 |
&& !df_regs_ever_live_p (LR_REGNUM))) |
| 21434 |
&& arm_r3_live_at_start_p () |
| 21435 |
&& crtl->args.pretend_args_size == 0) |
| 21436 |
return 4; |
| 21437 |
|
| 21438 |
return 0; |
| 21439 |
} |
| 21440 |
|
| 21441 |
/* Compute a bit mask of which core registers need to be |
| 21442 |
saved on the stack for the current function. |
| 21443 |
This is used by arm_compute_frame_layout, which may add extra registers. */ |
| 21444 |
|
| 21445 |
static unsigned long |
| 21446 |
arm_compute_save_core_reg_mask (void) |
| 21447 |
{ |
| 21448 |
unsigned int save_reg_mask = 0; |
| 21449 |
unsigned long func_type = arm_current_func_type (); |
| 21450 |
unsigned int reg; |
| 21451 |
|
| 21452 |
if (IS_NAKED (func_type)) |
| 21453 |
/* This should never really happen. */ |
| 21454 |
return 0; |
| 21455 |
|
| 21456 |
/* If we are creating a stack frame, then we must save the frame pointer, |
| 21457 |
IP (which will hold the old stack pointer), LR and the PC. */ |
| 21458 |
if (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM) |
| 21459 |
save_reg_mask |= |
| 21460 |
(1 << ARM_HARD_FRAME_POINTER_REGNUM) |
| 21461 |
| (1 << IP_REGNUM) |
| 21462 |
| (1 << LR_REGNUM) |
| 21463 |
| (1 << PC_REGNUM); |
| 21464 |
|
| 21465 |
save_reg_mask |= arm_compute_save_reg0_reg12_mask (); |
| 21466 |
|
| 21467 |
if (arm_current_function_pac_enabled_p ()) |
| 21468 |
save_reg_mask |= 1 << IP_REGNUM; |
| 21469 |
|
| 21470 |
/* Decide if we need to save the link register. |
| 21471 |
Interrupt routines have their own banked link register, |
| 21472 |
so they never need to save it. |
| 21473 |
Otherwise if we do not use the link register we do not need to save |
| 21474 |
it. If we are pushing other registers onto the stack however, we |
| 21475 |
can save an instruction in the epilogue by pushing the link register |
| 21476 |
now and then popping it back into the PC. This incurs extra memory |
| 21477 |
accesses though, so we only do it when optimizing for size, and only |
| 21478 |
if we know that we will not need a fancy return sequence. */ |
| 21479 |
if (df_regs_ever_live_p (LR_REGNUM) |
| 21480 |
|| (save_reg_mask |
| 21481 |
&& optimize_size |
| 21482 |
&& ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL |
| 21483 |
&& !crtl->tail_call_emit |
| 21484 |
&& !crtl->calls_eh_return)) |
| 21485 |
save_reg_mask |= 1 << LR_REGNUM; |
| 21486 |
|
| 21487 |
if (cfun->machine->lr_save_eliminated) |
| 21488 |
save_reg_mask &= ~ (1 << LR_REGNUM); |
| 21489 |
|
| 21490 |
if (TARGET_REALLY_IWMMXT |
| 21491 |
&& ((bit_count (save_reg_mask) |
| 21492 |
+ ARM_NUM_INTS (crtl->args.pretend_args_size + |
| 21493 |
arm_compute_static_chain_stack_bytes()) |
| 21494 |
) % 2) != 0) |
| 21495 |
{ |
| 21496 |
/* The total number of registers that are going to be pushed |
| 21497 |
onto the stack is odd. We need to ensure that the stack |
| 21498 |
is 64-bit aligned before we start to save iWMMXt registers, |
| 21499 |
and also before we start to create locals. (A local variable |
| 21500 |
might be a double or long long which we will load/store using |
| 21501 |
an iWMMXt instruction). Therefore we need to push another |
| 21502 |
ARM register, so that the stack will be 64-bit aligned. We |
| 21503 |
try to avoid using the arg registers (r0 -r3) as they might be |
| 21504 |
used to pass values in a tail call. */ |
| 21505 |
for (reg = 4; reg <= 12; reg++) |
| 21506 |
if ((save_reg_mask & (1 << reg)) == 0) |
| 21507 |
break; |
| 21508 |
|
| 21509 |
if (reg <= 12) |
| 21510 |
save_reg_mask |= (1 << reg); |
| 21511 |
else |
| 21512 |
{ |
| 21513 |
cfun->machine->sibcall_blocked = 1; |
| 21514 |
save_reg_mask |= (1 << 3); |
| 21515 |
} |
| 21516 |
} |
| 21517 |
|
| 21518 |
/* We may need to push an additional register for use initializing the |
| 21519 |
PIC base register. */ |
| 21520 |
if (TARGET_THUMB2 && IS_NESTED (func_type) && flag_pic |
| 21521 |
&& (save_reg_mask & THUMB2_WORK_REGS) == 0) |
| 21522 |
{ |
| 21523 |
reg = thumb_find_work_register (1 << 4); |
| 21524 |
if (!call_used_or_fixed_reg_p (reg)) |
| 21525 |
save_reg_mask |= (1 << reg); |
| 21526 |
} |
| 21527 |
|
| 21528 |
return save_reg_mask; |
| 21529 |
} |
| 21530 |
|
| 21531 |
/* Compute a bit mask of which core registers need to be |
| 21532 |
saved on the stack for the current function. */ |
| 21533 |
static unsigned long |
| 21534 |
thumb1_compute_save_core_reg_mask (void) |
| 21535 |
{ |
| 21536 |
unsigned long mask; |
| 21537 |
unsigned reg; |
| 21538 |
|
| 21539 |
mask = 0; |
| 21540 |
for (reg = 0; reg < 12; reg ++) |
| 21541 |
if (df_regs_ever_live_p (reg) && callee_saved_reg_p (reg)) |
| 21542 |
mask |= 1 << reg; |
| 21543 |
|
| 21544 |
/* Handle the frame pointer as a special case. */ |
| 21545 |
if (frame_pointer_needed) |
| 21546 |
mask |= 1 << HARD_FRAME_POINTER_REGNUM; |
| 21547 |
|
| 21548 |
if (flag_pic |
| 21549 |
&& !TARGET_SINGLE_PIC_BASE |
| 21550 |
&& arm_pic_register != INVALID_REGNUM |
| 21551 |
&& crtl->uses_pic_offset_table) |
| 21552 |
mask |= 1 << PIC_OFFSET_TABLE_REGNUM; |
| 21553 |
|
| 21554 |
/* See if we might need r11 for calls to _interwork_r11_call_via_rN(). */ |
| 21555 |
if (!frame_pointer_needed && CALLER_INTERWORKING_SLOT_SIZE > 0) |
| 21556 |
mask |= 1 << ARM_HARD_FRAME_POINTER_REGNUM; |
| 21557 |
|
| 21558 |
/* LR will also be pushed if any lo regs are pushed. */ |
| 21559 |
if (mask & 0xff || thumb_force_lr_save ()) |
| 21560 |
mask |= (1 << LR_REGNUM); |
| 21561 |
|
| 21562 |
bool call_clobbered_scratch |
| 21563 |
= (thumb1_prologue_unused_call_clobbered_lo_regs () |
| 21564 |
&& thumb1_epilogue_unused_call_clobbered_lo_regs ()); |
| 21565 |
|
| 21566 |
/* Make sure we have a low work register if we need one. We will |
| 21567 |
need one if we are going to push a high register, but we are not |
| 21568 |
currently intending to push a low register. However if both the |
| 21569 |
prologue and epilogue have a spare call-clobbered low register, |
| 21570 |
then we won't need to find an additional work register. It does |
| 21571 |
not need to be the same register in the prologue and |
| 21572 |
epilogue. */ |
| 21573 |
if ((mask & 0xff) == 0 |
| 21574 |
&& !call_clobbered_scratch |
| 21575 |
&& ((mask & 0x0f00) || TARGET_BACKTRACE)) |
| 21576 |
{ |
| 21577 |
/* Use thumb_find_work_register to choose which register |
| 21578 |
we will use. If the register is live then we will |
| 21579 |
have to push it. Use LAST_LO_REGNUM as our fallback |
| 21580 |
choice for the register to select. */ |
| 21581 |
reg = thumb_find_work_register (1 << LAST_LO_REGNUM); |
| 21582 |
/* Make sure the register returned by thumb_find_work_register is |
| 21583 |
not part of the return value. */ |
| 21584 |
if (reg * UNITS_PER_WORD <= (unsigned) arm_size_return_regs ()) |
| 21585 |
reg = LAST_LO_REGNUM; |
| 21586 |
|
| 21587 |
if (callee_saved_reg_p (reg)) |
| 21588 |
mask |= 1 << reg; |
| 21589 |
} |
| 21590 |
|
| 21591 |
/* The 504 below is 8 bytes less than 512 because there are two possible |
| 21592 |
alignment words. We can't tell here if they will be present or not so we |
| 21593 |
have to play it safe and assume that they are. */ |
| 21594 |
if ((CALLER_INTERWORKING_SLOT_SIZE + |
| 21595 |
ROUND_UP_WORD (get_frame_size ()) + |
| 21596 |
crtl->outgoing_args_size) >= 504) |
| 21597 |
{ |
| 21598 |
/* This is the same as the code in thumb1_expand_prologue() which |
| 21599 |
determines which register to use for stack decrement. */ |
| 21600 |
for (reg = LAST_ARG_REGNUM + 1; reg <= LAST_LO_REGNUM; reg++) |
| 21601 |
if (mask & (1 << reg)) |
| 21602 |
break; |
| 21603 |
|
| 21604 |
if (reg > LAST_LO_REGNUM) |
| 21605 |
{ |
| 21606 |
/* Make sure we have a register available for stack decrement. */ |
| 21607 |
mask |= 1 << LAST_LO_REGNUM; |
| 21608 |
} |
| 21609 |
} |
| 21610 |
|
| 21611 |
return mask; |
| 21612 |
} |
| 21613 |
|
| 21614 |
/* Return the number of bytes required to save VFP registers. */ |
| 21615 |
static int |
| 21616 |
arm_get_vfp_saved_size (void) |
| 21617 |
{ |
| 21618 |
unsigned int regno; |
| 21619 |
int count; |
| 21620 |
int saved; |
| 21621 |
|
| 21622 |
saved = 0; |
| 21623 |
/* Space for saved VFP registers. */ |
| 21624 |
if (TARGET_VFP_BASE) |
| 21625 |
{ |
| 21626 |
count = 0; |
| 21627 |
for (regno = FIRST_VFP_REGNUM; |
| 21628 |
regno < LAST_VFP_REGNUM; |
| 21629 |
regno += 2) |
| 21630 |
{ |
| 21631 |
if (!reg_needs_saving_p (regno) && !reg_needs_saving_p (regno + 1)) |
| 21632 |
{ |
| 21633 |
if (count > 0) |
| 21634 |
{ |
| 21635 |
/* Workaround ARM10 VFPr1 bug. */ |
| 21636 |
if (count == 2 && !arm_arch6) |
| 21637 |
count++; |
| 21638 |
saved += count * 8; |
| 21639 |
} |
| 21640 |
count = 0; |
| 21641 |
} |
| 21642 |
else |
| 21643 |
count++; |
| 21644 |
} |
| 21645 |
if (count > 0) |
| 21646 |
{ |
| 21647 |
if (count == 2 && !arm_arch6) |
| 21648 |
count++; |
| 21649 |
saved += count * 8; |
| 21650 |
} |
| 21651 |
} |
| 21652 |
return saved; |
| 21653 |
} |
| 21654 |
|
| 21655 |
|
| 21656 |
/* Generate a function exit sequence. If REALLY_RETURN is false, then do |
| 21657 |
everything bar the final return instruction. If simple_return is true, |
| 21658 |
then do not output epilogue, because it has already been emitted in RTL. |
| 21659 |
|
| 21660 |
Note: do not forget to update length attribute of corresponding insn pattern |
| 21661 |
when changing assembly output (eg. length attribute of |
| 21662 |
thumb2_cmse_entry_return when updating Armv8-M Mainline Security Extensions |
| 21663 |
register clearing sequences). */ |
| 21664 |
const char * |
| 21665 |
output_return_instruction (rtx operand, bool really_return, bool reverse, |
| 21666 |
bool simple_return) |
| 21667 |
{ |
| 21668 |
char conditional[10]; |
| 21669 |
char instr[100]; |
| 21670 |
unsigned reg; |
| 21671 |
unsigned long live_regs_mask; |
| 21672 |
unsigned long func_type; |
| 21673 |
arm_stack_offsets *offsets; |
| 21674 |
|
| 21675 |
func_type = arm_current_func_type (); |
| 21676 |
|
| 21677 |
if (IS_NAKED (func_type)) |
| 21678 |
return ""; |
| 21679 |
|
| 21680 |
if (IS_VOLATILE (func_type) && TARGET_ABORT_NORETURN) |
| 21681 |
{ |
| 21682 |
/* If this function was declared non-returning, and we have |
| 21683 |
found a tail call, then we have to trust that the called |
| 21684 |
function won't return. */ |
| 21685 |
if (really_return) |
| 21686 |
{ |
| 21687 |
rtx ops[2]; |
| 21688 |
|
| 21689 |
/* Otherwise, trap an attempted return by aborting. */ |
| 21690 |
ops[0] = operand; |
| 21691 |
ops[1] = gen_rtx_SYMBOL_REF (Pmode, NEED_PLT_RELOC ? "abort(PLT)" |
| 21692 |
: "abort"); |
| 21693 |
assemble_external_libcall (ops[1]); |
| 21694 |
output_asm_insn (reverse ? "bl%D0\t%a1" : "bl%d0\t%a1", ops); |
| 21695 |
} |
| 21696 |
|
| 21697 |
return ""; |
| 21698 |
} |
| 21699 |
|
| 21700 |
gcc_assert (!cfun->calls_alloca || really_return); |
| 21701 |
|
| 21702 |
sprintf (conditional, "%%?%%%c0", reverse ? 'D' : 'd'); |
| 21703 |
|
| 21704 |
cfun->machine->return_used_this_function = 1; |
| 21705 |
|
| 21706 |
offsets = arm_get_frame_offsets (); |
| 21707 |
live_regs_mask = offsets->saved_regs_mask; |
| 21708 |
|
| 21709 |
if (!simple_return && live_regs_mask) |
| 21710 |
{ |
| 21711 |
const char * return_reg; |
| 21712 |
|
| 21713 |
/* If we do not have any special requirements for function exit |
| 21714 |
(e.g. interworking) then we can load the return address |
| 21715 |
directly into the PC. Otherwise we must load it into LR. */ |
| 21716 |
if (really_return |
| 21717 |
&& !IS_CMSE_ENTRY (func_type) |
| 21718 |
&& (IS_INTERRUPT (func_type) || !TARGET_INTERWORK)) |
| 21719 |
return_reg = reg_names[PC_REGNUM]; |
| 21720 |
else |
| 21721 |
return_reg = reg_names[LR_REGNUM]; |
| 21722 |
|
| 21723 |
if ((live_regs_mask & (1 << IP_REGNUM)) == (1 << IP_REGNUM)) |
| 21724 |
{ |
| 21725 |
/* There are three possible reasons for the IP register |
| 21726 |
being saved. 1) a stack frame was created, in which case |
| 21727 |
IP contains the old stack pointer, or 2) an ISR routine |
| 21728 |
corrupted it, or 3) it was saved to align the stack on |
| 21729 |
iWMMXt. In case 1, restore IP into SP, otherwise just |
| 21730 |
restore IP. */ |
| 21731 |
if (frame_pointer_needed) |
| 21732 |
{ |
| 21733 |
live_regs_mask &= ~ (1 << IP_REGNUM); |
| 21734 |
live_regs_mask |= (1 << SP_REGNUM); |
| 21735 |
} |
| 21736 |
else |
| 21737 |
gcc_assert (IS_INTERRUPT (func_type) || TARGET_REALLY_IWMMXT); |
| 21738 |
} |
| 21739 |
|
| 21740 |
/* On some ARM architectures it is faster to use LDR rather than |
| 21741 |
LDM to load a single register. On other architectures, the |
| 21742 |
cost is the same. In 26 bit mode, or for exception handlers, |
| 21743 |
we have to use LDM to load the PC so that the CPSR is also |
| 21744 |
restored. */ |
| 21745 |
for (reg = 0; reg <= LAST_ARM_REGNUM; reg++) |
| 21746 |
if (live_regs_mask == (1U << reg)) |
| 21747 |
break; |
| 21748 |
|
| 21749 |
if (reg <= LAST_ARM_REGNUM |
| 21750 |
&& (reg != LR_REGNUM |
| 21751 |
|| ! really_return |
| 21752 |
|| ! IS_INTERRUPT (func_type))) |
| 21753 |
{ |
| 21754 |
sprintf (instr, "ldr%s\t%%|%s, [%%|sp], #4", conditional, |
| 21755 |
(reg == LR_REGNUM) ? return_reg : reg_names[reg]); |
| 21756 |
} |
| 21757 |
else |
| 21758 |
{ |
| 21759 |
char *p; |
| 21760 |
int first = 1; |
| 21761 |
|
| 21762 |
/* Generate the load multiple instruction to restore the |
| 21763 |
registers. Note we can get here, even if |
| 21764 |
frame_pointer_needed is true, but only if sp already |
| 21765 |
points to the base of the saved core registers. */ |
| 21766 |
if (live_regs_mask & (1 << SP_REGNUM)) |
| 21767 |
{ |
| 21768 |
unsigned HOST_WIDE_INT stack_adjust; |
| 21769 |
|
| 21770 |
stack_adjust = offsets->outgoing_args - offsets->saved_regs; |
| 21771 |
gcc_assert (stack_adjust == 0 || stack_adjust == 4); |
| 21772 |
|
| 21773 |
if (stack_adjust && arm_arch5t && TARGET_ARM) |
| 21774 |
sprintf (instr, "ldmib%s\t%%|sp, {", conditional); |
| 21775 |
else |
| 21776 |
{ |
| 21777 |
/* If we can't use ldmib (SA110 bug), |
| 21778 |
then try to pop r3 instead. */ |
| 21779 |
if (stack_adjust) |
| 21780 |
live_regs_mask |= 1 << 3; |
| 21781 |
|
| 21782 |
sprintf (instr, "ldmfd%s\t%%|sp, {", conditional); |
| 21783 |
} |
| 21784 |
} |
| 21785 |
/* For interrupt returns we have to use an LDM rather than |
| 21786 |
a POP so that we can use the exception return variant. */ |
| 21787 |
else if (IS_INTERRUPT (func_type)) |
| 21788 |
sprintf (instr, "ldmfd%s\t%%|sp!, {", conditional); |
| 21789 |
else |
| 21790 |
sprintf (instr, "pop%s\t{", conditional); |
| 21791 |
|
| 21792 |
p = instr + strlen (instr); |
| 21793 |
|
| 21794 |
for (reg = 0; reg <= SP_REGNUM; reg++) |
| 21795 |
if (live_regs_mask & (1 << reg)) |
| 21796 |
{ |
| 21797 |
int l = strlen (reg_names[reg]); |
| 21798 |
|
| 21799 |
if (first) |
| 21800 |
first = 0; |
| 21801 |
else |
| 21802 |
{ |
| 21803 |
memcpy (p, ", ", 2); |
| 21804 |
p += 2; |
| 21805 |
} |
| 21806 |
|
| 21807 |
memcpy (p, "%|", 2); |
| 21808 |
memcpy (p + 2, reg_names[reg], l); |
| 21809 |
p += l + 2; |
| 21810 |
} |
| 21811 |
|
| 21812 |
if (live_regs_mask & (1 << LR_REGNUM)) |
| 21813 |
{ |
| 21814 |
sprintf (p, "%s%%|%s}", first ? "" : ", ", return_reg); |
| 21815 |
/* If returning from an interrupt, restore the CPSR. */ |
| 21816 |
if (IS_INTERRUPT (func_type)) |
| 21817 |
strcat (p, "^"); |
| 21818 |
} |
| 21819 |
else |
| 21820 |
strcpy (p, "}"); |
| 21821 |
} |
| 21822 |
|
| 21823 |
output_asm_insn (instr, & operand); |
| 21824 |
|
| 21825 |
/* See if we need to generate an extra instruction to |
| 21826 |
perform the actual function return. */ |
| 21827 |
if (really_return |
| 21828 |
&& func_type != ARM_FT_INTERWORKED |
| 21829 |
&& (live_regs_mask & (1 << LR_REGNUM)) != 0) |
| 21830 |
{ |
| 21831 |
/* The return has already been handled |
| 21832 |
by loading the LR into the PC. */ |
| 21833 |
return ""; |
| 21834 |
} |
| 21835 |
} |
| 21836 |
|
| 21837 |
if (really_return) |
| 21838 |
{ |
| 21839 |
switch ((int) ARM_FUNC_TYPE (func_type)) |
| 21840 |
{ |
| 21841 |
case ARM_FT_ISR: |
| 21842 |
case ARM_FT_FIQ: |
| 21843 |
/* ??? This is wrong for unified assembly syntax. */ |
| 21844 |
sprintf (instr, "sub%ss\t%%|pc, %%|lr, #4", conditional); |
| 21845 |
break; |
| 21846 |
|
| 21847 |
case ARM_FT_INTERWORKED: |
| 21848 |
gcc_assert (arm_arch5t || arm_arch4t); |
| 21849 |
sprintf (instr, "bx%s\t%%|lr", conditional); |
| 21850 |
break; |
| 21851 |
|
| 21852 |
case ARM_FT_EXCEPTION: |
| 21853 |
/* ??? This is wrong for unified assembly syntax. */ |
| 21854 |
sprintf (instr, "mov%ss\t%%|pc, %%|lr", conditional); |
| 21855 |
break; |
| 21856 |
|
| 21857 |
default: |
| 21858 |
if (IS_CMSE_ENTRY (func_type)) |
| 21859 |
{ |
| 21860 |
/* For Armv8.1-M, this is cleared as part of the CLRM instruction |
| 21861 |
emitted by cmse_nonsecure_entry_clear_before_return () and the |
| 21862 |
VSTR/VLDR instructions in the prologue and epilogue. */ |
| 21863 |
if (!TARGET_HAVE_FPCXT_CMSE) |
| 21864 |
{ |
| 21865 |
/* Check if we have to clear the 'GE bits' which is only used if |
| 21866 |
parallel add and subtraction instructions are available. */ |
| 21867 |
if (TARGET_INT_SIMD) |
| 21868 |
snprintf (instr, sizeof (instr), |
| 21869 |
"msr%s\tAPSR_nzcvqg, %%|lr", conditional); |
| 21870 |
else |
| 21871 |
snprintf (instr, sizeof (instr), |
| 21872 |
"msr%s\tAPSR_nzcvq, %%|lr", conditional); |
| 21873 |
|
| 21874 |
output_asm_insn (instr, & operand); |
| 21875 |
/* Do not clear FPSCR if targeting Armv8.1-M Mainline, VLDR takes |
| 21876 |
care of it. */ |
| 21877 |
if (TARGET_HARD_FLOAT) |
| 21878 |
{ |
| 21879 |
/* Clear the cumulative exception-status bits (0-4,7) and |
| 21880 |
the condition code bits (28-31) of the FPSCR. We need |
| 21881 |
to remember to clear the first scratch register used |
| 21882 |
(IP) and save and restore the second (r4). |
| 21883 |
|
| 21884 |
Important note: the length of the |
| 21885 |
thumb2_cmse_entry_return insn pattern must account for |
| 21886 |
the size of the below instructions. */ |
| 21887 |
output_asm_insn ("push\t{%|r4}", & operand); |
| 21888 |
output_asm_insn ("vmrs\t%|ip, fpscr", & operand); |
| 21889 |
output_asm_insn ("movw\t%|r4, #65376", & operand); |
| 21890 |
output_asm_insn ("movt\t%|r4, #4095", & operand); |
| 21891 |
output_asm_insn ("and\t%|ip, %|r4", & operand); |
| 21892 |
output_asm_insn ("vmsr\tfpscr, %|ip", & operand); |
| 21893 |
output_asm_insn ("pop\t{%|r4}", & operand); |
| 21894 |
output_asm_insn ("mov\t%|ip, %|lr", & operand); |
| 21895 |
} |
| 21896 |
} |
| 21897 |
snprintf (instr, sizeof (instr), "bxns\t%%|lr"); |
| 21898 |
} |
| 21899 |
/* Use bx if it's available. */ |
| 21900 |
else if (arm_arch5t || arm_arch4t) |
| 21901 |
sprintf (instr, "bx%s\t%%|lr", conditional); |
| 21902 |
else |
| 21903 |
sprintf (instr, "mov%s\t%%|pc, %%|lr", conditional); |
| 21904 |
break; |
| 21905 |
} |
| 21906 |
|
| 21907 |
output_asm_insn (instr, & operand); |
| 21908 |
} |
| 21909 |
|
| 21910 |
return ""; |
| 21911 |
} |
| 21912 |
|
| 21913 |
/* Output in FILE asm statements needed to declare the NAME of the function |
| 21914 |
defined by its DECL node. */ |
| 21915 |
|
| 21916 |
void |
| 21917 |
arm_asm_declare_function_name (FILE *file, const char *name, tree decl) |
| 21918 |
{ |
| 21919 |
size_t cmse_name_len; |
| 21920 |
char *cmse_name = 0; |
| 21921 |
char cmse_prefix[] = "__acle_se_"; |
| 21922 |
|
| 21923 |
/* When compiling with ARMv8-M Security Extensions enabled, we should print an |
| 21924 |
extra function label for each function with the 'cmse_nonsecure_entry' |
| 21925 |
attribute. This extra function label should be prepended with |
| 21926 |
'__acle_se_', telling the linker that it needs to create secure gateway |
| 21927 |
veneers for this function. */ |
| 21928 |
if (use_cmse && lookup_attribute ("cmse_nonsecure_entry", |
| 21929 |
DECL_ATTRIBUTES (decl))) |
| 21930 |
{ |
| 21931 |
cmse_name_len = sizeof (cmse_prefix) + strlen (name); |
| 21932 |
cmse_name = XALLOCAVEC (char, cmse_name_len); |
| 21933 |
snprintf (cmse_name, cmse_name_len, "%s%s", cmse_prefix, name); |
| 21934 |
targetm.asm_out.globalize_label (file, cmse_name); |
| 21935 |
|
| 21936 |
ARM_DECLARE_FUNCTION_NAME (file, cmse_name, decl); |
| 21937 |
ASM_OUTPUT_TYPE_DIRECTIVE (file, cmse_name, "function"); |
| 21938 |
} |
| 21939 |
|
| 21940 |
ARM_DECLARE_FUNCTION_NAME (file, name, decl); |
| 21941 |
ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function"); |
| 21942 |
ASM_DECLARE_RESULT (file, DECL_RESULT (decl)); |
| 21943 |
ASM_OUTPUT_FUNCTION_LABEL (file, name, decl); |
| 21944 |
|
| 21945 |
if (cmse_name) |
| 21946 |
ASM_OUTPUT_LABEL (file, cmse_name); |
| 21947 |
|
| 21948 |
ARM_OUTPUT_FN_UNWIND (file, TRUE); |
| 21949 |
} |
| 21950 |
|
| 21951 |
/* Write the function name into the code section, directly preceding |
| 21952 |
the function prologue. |
| 21953 |
|
| 21954 |
Code will be output similar to this: |
| 21955 |
t0 |
| 21956 |
.ascii "arm_poke_function_name", 0 |
| 21957 |
.align |
| 21958 |
t1 |
| 21959 |
.word 0xff000000 + (t1 - t0) |
| 21960 |
arm_poke_function_name |
| 21961 |
mov ip, sp |
| 21962 |
stmfd sp!, {fp, ip, lr, pc} |
| 21963 |
sub fp, ip, #4 |
| 21964 |
|
| 21965 |
When performing a stack backtrace, code can inspect the value |
| 21966 |
of 'pc' stored at 'fp' + 0. If the trace function then looks |
| 21967 |
at location pc - 12 and the top 8 bits are set, then we know |
| 21968 |
that there is a function name embedded immediately preceding this |
| 21969 |
location and has length ((pc[-3]) & 0xff000000). |
| 21970 |
|
| 21971 |
We assume that pc is declared as a pointer to an unsigned long. |
| 21972 |
|
| 21973 |
It is of no benefit to output the function name if we are assembling |
| 21974 |
a leaf function. These function types will not contain a stack |
| 21975 |
backtrace structure, therefore it is not possible to determine the |
| 21976 |
function name. */ |
| 21977 |
void |
| 21978 |
arm_poke_function_name (FILE *stream, const char *name) |
| 21979 |
{ |
| 21980 |
unsigned long alignlength; |
| 21981 |
unsigned long length; |
| 21982 |
rtx x; |
| 21983 |
|
| 21984 |
length = strlen (name) + 1; |
| 21985 |
alignlength = ROUND_UP_WORD (length); |
| 21986 |
|
| 21987 |
ASM_OUTPUT_ASCII (stream, name, length); |
| 21988 |
ASM_OUTPUT_ALIGN (stream, 2); |
| 21989 |
x = GEN_INT ((unsigned HOST_WIDE_INT) 0xff000000 + alignlength); |
| 21990 |
assemble_aligned_integer (UNITS_PER_WORD, x); |
| 21991 |
} |
| 21992 |
|
| 21993 |
/* Place some comments into the assembler stream |
| 21994 |
describing the current function. */ |
| 21995 |
static void |
| 21996 |
arm_output_function_prologue (FILE *f) |
| 21997 |
{ |
| 21998 |
unsigned long func_type; |
| 21999 |
|
| 22000 |
/* Sanity check. */ |
| 22001 |
gcc_assert (!arm_ccfsm_state && !arm_target_insn); |
| 22002 |
|
| 22003 |
func_type = arm_current_func_type (); |
| 22004 |
|
| 22005 |
switch ((int) ARM_FUNC_TYPE (func_type)) |
| 22006 |
{ |
| 22007 |
default: |
| 22008 |
case ARM_FT_NORMAL: |
| 22009 |
break; |
| 22010 |
case ARM_FT_INTERWORKED: |
| 22011 |
asm_fprintf (f, "\t%@ Function supports interworking.\n"); |
| 22012 |
break; |
| 22013 |
case ARM_FT_ISR: |
| 22014 |
asm_fprintf (f, "\t%@ Interrupt Service Routine.\n"); |
| 22015 |
break; |
| 22016 |
case ARM_FT_FIQ: |
| 22017 |
asm_fprintf (f, "\t%@ Fast Interrupt Service Routine.\n"); |
| 22018 |
break; |
| 22019 |
case ARM_FT_EXCEPTION: |
| 22020 |
asm_fprintf (f, "\t%@ ARM Exception Handler.\n"); |
| 22021 |
break; |
| 22022 |
} |
| 22023 |
|
| 22024 |
if (IS_NAKED (func_type)) |
| 22025 |
asm_fprintf (f, "\t%@ Naked Function: prologue and epilogue provided by programmer.\n"); |
| 22026 |
|
| 22027 |
if (IS_VOLATILE (func_type)) |
| 22028 |
asm_fprintf (f, "\t%@ Volatile: function does not return.\n"); |
| 22029 |
|
| 22030 |
if (IS_NESTED (func_type)) |
| 22031 |
asm_fprintf (f, "\t%@ Nested: function declared inside another function.\n"); |
| 22032 |
if (IS_STACKALIGN (func_type)) |
| 22033 |
asm_fprintf (f, "\t%@ Stack Align: May be called with mis-aligned SP.\n"); |
| 22034 |
if (IS_CMSE_ENTRY (func_type)) |
| 22035 |
asm_fprintf (f, "\t%@ Non-secure entry function: called from non-secure code.\n"); |
| 22036 |
|
| 22037 |
asm_fprintf (f, "\t%@ args = %wd, pretend = %d, frame = %wd\n", |
| 22038 |
(HOST_WIDE_INT) crtl->args.size, |
| 22039 |
crtl->args.pretend_args_size, |
| 22040 |
(HOST_WIDE_INT) get_frame_size ()); |
| 22041 |
|
| 22042 |
asm_fprintf (f, "\t%@ frame_needed = %d, uses_anonymous_args = %d\n", |
| 22043 |
frame_pointer_needed, |
| 22044 |
cfun->machine->uses_anonymous_args); |
| 22045 |
|
| 22046 |
if (cfun->machine->lr_save_eliminated) |
| 22047 |
asm_fprintf (f, "\t%@ link register save eliminated.\n"); |
| 22048 |
|
| 22049 |
if (crtl->calls_eh_return) |
| 22050 |
asm_fprintf (f, "\t@ Calls __builtin_eh_return.\n"); |
| 22051 |
|
| 22052 |
} |
| 22053 |
|
| 22054 |
static void |
| 22055 |
arm_output_function_epilogue (FILE *) |
| 22056 |
{ |
| 22057 |
arm_stack_offsets *offsets; |
| 22058 |
|
| 22059 |
if (TARGET_THUMB1) |
| 22060 |
{ |
| 22061 |
int regno; |
| 22062 |
|
| 22063 |
/* Emit any call-via-reg trampolines that are needed for v4t support |
| 22064 |
of call_reg and call_value_reg type insns. */ |
| 22065 |
for (regno = 0; regno < LR_REGNUM; regno++) |
| 22066 |
{ |
| 22067 |
rtx label = cfun->machine->call_via[regno]; |
| 22068 |
|
| 22069 |
if (label != NULL) |
| 22070 |
{ |
| 22071 |
switch_to_section (function_section (current_function_decl)); |
| 22072 |
targetm.asm_out.internal_label (asm_out_file, "L", |
| 22073 |
CODE_LABEL_NUMBER (label)); |
| 22074 |
asm_fprintf (asm_out_file, "\tbx\t%r\n", regno); |
| 22075 |
} |
| 22076 |
} |
| 22077 |
|
| 22078 |
/* ??? Probably not safe to set this here, since it assumes that a |
| 22079 |
function will be emitted as assembly immediately after we generate |
| 22080 |
RTL for it. This does not happen for inline functions. */ |
| 22081 |
cfun->machine->return_used_this_function = 0; |
| 22082 |
} |
| 22083 |
else /* TARGET_32BIT */ |
| 22084 |
{ |
| 22085 |
/* We need to take into account any stack-frame rounding. */ |
| 22086 |
offsets = arm_get_frame_offsets (); |
| 22087 |
|
| 22088 |
gcc_assert (!use_return_insn (FALSE, NULL) |
| 22089 |
|| (cfun->machine->return_used_this_function != 0) |
| 22090 |
|| offsets->saved_regs == offsets->outgoing_args |
| 22091 |
|| frame_pointer_needed); |
| 22092 |
} |
| 22093 |
} |
| 22094 |
|
| 22095 |
/* Generate and emit a sequence of insns equivalent to PUSH, but using |
| 22096 |
STR and STRD. If an even number of registers are being pushed, one |
| 22097 |
or more STRD patterns are created for each register pair. If an |
| 22098 |
odd number of registers are pushed, emit an initial STR followed by |
| 22099 |
as many STRD instructions as are needed. This works best when the |
| 22100 |
stack is initially 64-bit aligned (the normal case), since it |
| 22101 |
ensures that each STRD is also 64-bit aligned. */ |
| 22102 |
static void |
| 22103 |
thumb2_emit_strd_push (unsigned long saved_regs_mask) |
| 22104 |
{ |
| 22105 |
int num_regs = 0; |
| 22106 |
int i; |
| 22107 |
int regno; |
| 22108 |
rtx par = NULL_RTX; |
| 22109 |
rtx dwarf = NULL_RTX; |
| 22110 |
rtx tmp; |
| 22111 |
bool first = true; |
| 22112 |
|
| 22113 |
num_regs = bit_count (saved_regs_mask); |
| 22114 |
|
| 22115 |
/* Must be at least one register to save, and can't save SP or PC. */ |
| 22116 |
gcc_assert (num_regs > 0 && num_regs <= 14); |
| 22117 |
gcc_assert (!(saved_regs_mask & (1 << SP_REGNUM))); |
| 22118 |
gcc_assert (!(saved_regs_mask & (1 << PC_REGNUM))); |
| 22119 |
|
| 22120 |
/* Create sequence for DWARF info. All the frame-related data for |
| 22121 |
debugging is held in this wrapper. */ |
| 22122 |
dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (num_regs + 1)); |
| 22123 |
|
| 22124 |
/* Describe the stack adjustment. */ |
| 22125 |
tmp = gen_rtx_SET (stack_pointer_rtx, |
| 22126 |
plus_constant (Pmode, stack_pointer_rtx, -4 * num_regs)); |
| 22127 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22128 |
XVECEXP (dwarf, 0, 0) = tmp; |
| 22129 |
|
| 22130 |
/* Find the first register. */ |
| 22131 |
for (regno = 0; (saved_regs_mask & (1 << regno)) == 0; regno++) |
| 22132 |
; |
| 22133 |
|
| 22134 |
i = 0; |
| 22135 |
|
| 22136 |
/* If there's an odd number of registers to push. Start off by |
| 22137 |
pushing a single register. This ensures that subsequent strd |
| 22138 |
operations are dword aligned (assuming that SP was originally |
| 22139 |
64-bit aligned). */ |
| 22140 |
if ((num_regs & 1) != 0) |
| 22141 |
{ |
| 22142 |
rtx reg, mem, insn; |
| 22143 |
|
| 22144 |
reg = gen_rtx_REG (SImode, regno); |
| 22145 |
if (num_regs == 1) |
| 22146 |
mem = gen_frame_mem (Pmode, gen_rtx_PRE_DEC (Pmode, |
| 22147 |
stack_pointer_rtx)); |
| 22148 |
else |
| 22149 |
mem = gen_frame_mem (Pmode, |
| 22150 |
gen_rtx_PRE_MODIFY |
| 22151 |
(Pmode, stack_pointer_rtx, |
| 22152 |
plus_constant (Pmode, stack_pointer_rtx, |
| 22153 |
-4 * num_regs))); |
| 22154 |
|
| 22155 |
tmp = gen_rtx_SET (mem, reg); |
| 22156 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22157 |
insn = emit_insn (tmp); |
| 22158 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 22159 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
| 22160 |
tmp = gen_rtx_SET (gen_frame_mem (Pmode, stack_pointer_rtx), reg); |
| 22161 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22162 |
i++; |
| 22163 |
regno++; |
| 22164 |
XVECEXP (dwarf, 0, i) = tmp; |
| 22165 |
first = false; |
| 22166 |
} |
| 22167 |
|
| 22168 |
while (i < num_regs) |
| 22169 |
if (saved_regs_mask & (1 << regno)) |
| 22170 |
{ |
| 22171 |
rtx reg1, reg2, mem1, mem2; |
| 22172 |
rtx tmp0, tmp1, tmp2; |
| 22173 |
int regno2; |
| 22174 |
|
| 22175 |
/* Find the register to pair with this one. */ |
| 22176 |
for (regno2 = regno + 1; (saved_regs_mask & (1 << regno2)) == 0; |
| 22177 |
regno2++) |
| 22178 |
; |
| 22179 |
|
| 22180 |
reg1 = gen_rtx_REG (SImode, regno); |
| 22181 |
reg2 = gen_rtx_REG (SImode, regno2); |
| 22182 |
|
| 22183 |
if (first) |
| 22184 |
{ |
| 22185 |
rtx insn; |
| 22186 |
|
| 22187 |
first = false; |
| 22188 |
mem1 = gen_frame_mem (Pmode, plus_constant (Pmode, |
| 22189 |
stack_pointer_rtx, |
| 22190 |
-4 * num_regs)); |
| 22191 |
mem2 = gen_frame_mem (Pmode, plus_constant (Pmode, |
| 22192 |
stack_pointer_rtx, |
| 22193 |
-4 * (num_regs - 1))); |
| 22194 |
tmp0 = gen_rtx_SET (stack_pointer_rtx, |
| 22195 |
plus_constant (Pmode, stack_pointer_rtx, |
| 22196 |
-4 * (num_regs))); |
| 22197 |
tmp1 = gen_rtx_SET (mem1, reg1); |
| 22198 |
tmp2 = gen_rtx_SET (mem2, reg2); |
| 22199 |
RTX_FRAME_RELATED_P (tmp0) = 1; |
| 22200 |
RTX_FRAME_RELATED_P (tmp1) = 1; |
| 22201 |
RTX_FRAME_RELATED_P (tmp2) = 1; |
| 22202 |
par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (3)); |
| 22203 |
XVECEXP (par, 0, 0) = tmp0; |
| 22204 |
XVECEXP (par, 0, 1) = tmp1; |
| 22205 |
XVECEXP (par, 0, 2) = tmp2; |
| 22206 |
insn = emit_insn (par); |
| 22207 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 22208 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
| 22209 |
} |
| 22210 |
else |
| 22211 |
{ |
| 22212 |
mem1 = gen_frame_mem (Pmode, plus_constant (Pmode, |
| 22213 |
stack_pointer_rtx, |
| 22214 |
4 * i)); |
| 22215 |
mem2 = gen_frame_mem (Pmode, plus_constant (Pmode, |
| 22216 |
stack_pointer_rtx, |
| 22217 |
4 * (i + 1))); |
| 22218 |
tmp1 = gen_rtx_SET (mem1, reg1); |
| 22219 |
tmp2 = gen_rtx_SET (mem2, reg2); |
| 22220 |
RTX_FRAME_RELATED_P (tmp1) = 1; |
| 22221 |
RTX_FRAME_RELATED_P (tmp2) = 1; |
| 22222 |
par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2)); |
| 22223 |
XVECEXP (par, 0, 0) = tmp1; |
| 22224 |
XVECEXP (par, 0, 1) = tmp2; |
| 22225 |
emit_insn (par); |
| 22226 |
} |
| 22227 |
|
| 22228 |
/* Create unwind information. This is an approximation. */ |
| 22229 |
tmp1 = gen_rtx_SET (gen_frame_mem (Pmode, |
| 22230 |
plus_constant (Pmode, |
| 22231 |
stack_pointer_rtx, |
| 22232 |
4 * i)), |
| 22233 |
reg1); |
| 22234 |
tmp2 = gen_rtx_SET (gen_frame_mem (Pmode, |
| 22235 |
plus_constant (Pmode, |
| 22236 |
stack_pointer_rtx, |
| 22237 |
4 * (i + 1))), |
| 22238 |
reg2); |
| 22239 |
|
| 22240 |
RTX_FRAME_RELATED_P (tmp1) = 1; |
| 22241 |
RTX_FRAME_RELATED_P (tmp2) = 1; |
| 22242 |
XVECEXP (dwarf, 0, i + 1) = tmp1; |
| 22243 |
XVECEXP (dwarf, 0, i + 2) = tmp2; |
| 22244 |
i += 2; |
| 22245 |
regno = regno2 + 1; |
| 22246 |
} |
| 22247 |
else |
| 22248 |
regno++; |
| 22249 |
|
| 22250 |
return; |
| 22251 |
} |
| 22252 |
|
| 22253 |
/* STRD in ARM mode requires consecutive registers. This function emits STRD |
| 22254 |
whenever possible, otherwise it emits single-word stores. The first store |
| 22255 |
also allocates stack space for all saved registers, using writeback with |
| 22256 |
post-addressing mode. All other stores use offset addressing. If no STRD |
| 22257 |
can be emitted, this function emits a sequence of single-word stores, |
| 22258 |
and not an STM as before, because single-word stores provide more freedom |
| 22259 |
scheduling and can be turned into an STM by peephole optimizations. */ |
| 22260 |
static void |
| 22261 |
arm_emit_strd_push (unsigned long saved_regs_mask) |
| 22262 |
{ |
| 22263 |
int num_regs = 0; |
| 22264 |
int i, j, dwarf_index = 0; |
| 22265 |
int offset = 0; |
| 22266 |
rtx dwarf = NULL_RTX; |
| 22267 |
rtx insn = NULL_RTX; |
| 22268 |
rtx tmp, mem; |
| 22269 |
|
| 22270 |
/* TODO: A more efficient code can be emitted by changing the |
| 22271 |
layout, e.g., first push all pairs that can use STRD to keep the |
| 22272 |
stack aligned, and then push all other registers. */ |
| 22273 |
for (i = 0; i <= LAST_ARM_REGNUM; i++) |
| 22274 |
if (saved_regs_mask & (1 << i)) |
| 22275 |
num_regs++; |
| 22276 |
|
| 22277 |
gcc_assert (!(saved_regs_mask & (1 << SP_REGNUM))); |
| 22278 |
gcc_assert (!(saved_regs_mask & (1 << PC_REGNUM))); |
| 22279 |
gcc_assert (num_regs > 0); |
| 22280 |
|
| 22281 |
/* Create sequence for DWARF info. */ |
| 22282 |
dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (num_regs + 1)); |
| 22283 |
|
| 22284 |
/* For dwarf info, we generate explicit stack update. */ |
| 22285 |
tmp = gen_rtx_SET (stack_pointer_rtx, |
| 22286 |
plus_constant (Pmode, stack_pointer_rtx, -4 * num_regs)); |
| 22287 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22288 |
XVECEXP (dwarf, 0, dwarf_index++) = tmp; |
| 22289 |
|
| 22290 |
/* Save registers. */ |
| 22291 |
offset = - 4 * num_regs; |
| 22292 |
j = 0; |
| 22293 |
while (j <= LAST_ARM_REGNUM) |
| 22294 |
if (saved_regs_mask & (1 << j)) |
| 22295 |
{ |
| 22296 |
if ((j % 2 == 0) |
| 22297 |
&& (saved_regs_mask & (1 << (j + 1)))) |
| 22298 |
{ |
| 22299 |
/* Current register and previous register form register pair for |
| 22300 |
which STRD can be generated. */ |
| 22301 |
if (offset < 0) |
| 22302 |
{ |
| 22303 |
/* Allocate stack space for all saved registers. */ |
| 22304 |
tmp = plus_constant (Pmode, stack_pointer_rtx, offset); |
| 22305 |
tmp = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, tmp); |
| 22306 |
mem = gen_frame_mem (DImode, tmp); |
| 22307 |
offset = 0; |
| 22308 |
} |
| 22309 |
else if (offset > 0) |
| 22310 |
mem = gen_frame_mem (DImode, |
| 22311 |
plus_constant (Pmode, |
| 22312 |
stack_pointer_rtx, |
| 22313 |
offset)); |
| 22314 |
else |
| 22315 |
mem = gen_frame_mem (DImode, stack_pointer_rtx); |
| 22316 |
|
| 22317 |
tmp = gen_rtx_SET (mem, gen_rtx_REG (DImode, j)); |
| 22318 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22319 |
tmp = emit_insn (tmp); |
| 22320 |
|
| 22321 |
/* Record the first store insn. */ |
| 22322 |
if (dwarf_index == 1) |
| 22323 |
insn = tmp; |
| 22324 |
|
| 22325 |
/* Generate dwarf info. */ |
| 22326 |
mem = gen_frame_mem (SImode, |
| 22327 |
plus_constant (Pmode, |
| 22328 |
stack_pointer_rtx, |
| 22329 |
offset)); |
| 22330 |
tmp = gen_rtx_SET (mem, gen_rtx_REG (SImode, j)); |
| 22331 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22332 |
XVECEXP (dwarf, 0, dwarf_index++) = tmp; |
| 22333 |
|
| 22334 |
mem = gen_frame_mem (SImode, |
| 22335 |
plus_constant (Pmode, |
| 22336 |
stack_pointer_rtx, |
| 22337 |
offset + 4)); |
| 22338 |
tmp = gen_rtx_SET (mem, gen_rtx_REG (SImode, j + 1)); |
| 22339 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22340 |
XVECEXP (dwarf, 0, dwarf_index++) = tmp; |
| 22341 |
|
| 22342 |
offset += 8; |
| 22343 |
j += 2; |
| 22344 |
} |
| 22345 |
else |
| 22346 |
{ |
| 22347 |
/* Emit a single word store. */ |
| 22348 |
if (offset < 0) |
| 22349 |
{ |
| 22350 |
/* Allocate stack space for all saved registers. */ |
| 22351 |
tmp = plus_constant (Pmode, stack_pointer_rtx, offset); |
| 22352 |
tmp = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, tmp); |
| 22353 |
mem = gen_frame_mem (SImode, tmp); |
| 22354 |
offset = 0; |
| 22355 |
} |
| 22356 |
else if (offset > 0) |
| 22357 |
mem = gen_frame_mem (SImode, |
| 22358 |
plus_constant (Pmode, |
| 22359 |
stack_pointer_rtx, |
| 22360 |
offset)); |
| 22361 |
else |
| 22362 |
mem = gen_frame_mem (SImode, stack_pointer_rtx); |
| 22363 |
|
| 22364 |
tmp = gen_rtx_SET (mem, gen_rtx_REG (SImode, j)); |
| 22365 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22366 |
tmp = emit_insn (tmp); |
| 22367 |
|
| 22368 |
/* Record the first store insn. */ |
| 22369 |
if (dwarf_index == 1) |
| 22370 |
insn = tmp; |
| 22371 |
|
| 22372 |
/* Generate dwarf info. */ |
| 22373 |
mem = gen_frame_mem (SImode, |
| 22374 |
plus_constant(Pmode, |
| 22375 |
stack_pointer_rtx, |
| 22376 |
offset)); |
| 22377 |
tmp = gen_rtx_SET (mem, gen_rtx_REG (SImode, j)); |
| 22378 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22379 |
XVECEXP (dwarf, 0, dwarf_index++) = tmp; |
| 22380 |
|
| 22381 |
offset += 4; |
| 22382 |
j += 1; |
| 22383 |
} |
| 22384 |
} |
| 22385 |
else |
| 22386 |
j++; |
| 22387 |
|
| 22388 |
/* Attach dwarf info to the first insn we generate. */ |
| 22389 |
gcc_assert (insn != NULL_RTX); |
| 22390 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
| 22391 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 22392 |
} |
| 22393 |
|
| 22394 |
/* Generate and emit an insn that we will recognize as a push_multi. |
| 22395 |
Unfortunately, since this insn does not reflect very well the actual |
| 22396 |
semantics of the operation, we need to annotate the insn for the benefit |
| 22397 |
of DWARF2 frame unwind information. DWARF_REGS_MASK is a subset of |
| 22398 |
MASK for registers that should be annotated for DWARF2 frame unwind |
| 22399 |
information. */ |
| 22400 |
static rtx |
| 22401 |
emit_multi_reg_push (unsigned long mask, unsigned long dwarf_regs_mask) |
| 22402 |
{ |
| 22403 |
int num_regs = 0; |
| 22404 |
int num_dwarf_regs = 0; |
| 22405 |
int i, j; |
| 22406 |
rtx par; |
| 22407 |
rtx dwarf; |
| 22408 |
int dwarf_par_index; |
| 22409 |
rtx tmp, reg; |
| 22410 |
|
| 22411 |
/* We don't record the PC in the dwarf frame information. */ |
| 22412 |
dwarf_regs_mask &= ~(1 << PC_REGNUM); |
| 22413 |
|
| 22414 |
for (i = 0; i <= LAST_ARM_REGNUM; i++) |
| 22415 |
{ |
| 22416 |
if (mask & (1 << i)) |
| 22417 |
num_regs++; |
| 22418 |
if (dwarf_regs_mask & (1 << i)) |
| 22419 |
num_dwarf_regs++; |
| 22420 |
} |
| 22421 |
|
| 22422 |
gcc_assert (num_regs && num_regs <= 16); |
| 22423 |
gcc_assert ((dwarf_regs_mask & ~mask) == 0); |
| 22424 |
|
| 22425 |
/* For the body of the insn we are going to generate an UNSPEC in |
| 22426 |
parallel with several USEs. This allows the insn to be recognized |
| 22427 |
by the push_multi pattern in the arm.md file. |
| 22428 |
|
| 22429 |
The body of the insn looks something like this: |
| 22430 |
|
| 22431 |
(parallel [ |
| 22432 |
(set (mem:BLK (pre_modify:SI (reg:SI sp) |
| 22433 |
(const_int:SI <num>))) |
| 22434 |
(unspec:BLK [(reg:SI r4)] UNSPEC_PUSH_MULT)) |
| 22435 |
(use (reg:SI XX)) |
| 22436 |
(use (reg:SI YY)) |
| 22437 |
... |
| 22438 |
]) |
| 22439 |
|
| 22440 |
For the frame note however, we try to be more explicit and actually |
| 22441 |
show each register being stored into the stack frame, plus a (single) |
| 22442 |
decrement of the stack pointer. We do it this way in order to be |
| 22443 |
friendly to the stack unwinding code, which only wants to see a single |
| 22444 |
stack decrement per instruction. The RTL we generate for the note looks |
| 22445 |
something like this: |
| 22446 |
|
| 22447 |
(sequence [ |
| 22448 |
(set (reg:SI sp) (plus:SI (reg:SI sp) (const_int -20))) |
| 22449 |
(set (mem:SI (reg:SI sp)) (reg:SI r4)) |
| 22450 |
(set (mem:SI (plus:SI (reg:SI sp) (const_int 4))) (reg:SI XX)) |
| 22451 |
(set (mem:SI (plus:SI (reg:SI sp) (const_int 8))) (reg:SI YY)) |
| 22452 |
... |
| 22453 |
]) |
| 22454 |
|
| 22455 |
FIXME:: In an ideal world the PRE_MODIFY would not exist and |
| 22456 |
instead we'd have a parallel expression detailing all |
| 22457 |
the stores to the various memory addresses so that debug |
| 22458 |
information is more up-to-date. Remember however while writing |
| 22459 |
this to take care of the constraints with the push instruction. |
| 22460 |
|
| 22461 |
Note also that this has to be taken care of for the VFP registers. |
| 22462 |
|
| 22463 |
For more see PR43399. */ |
| 22464 |
|
| 22465 |
par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_regs)); |
| 22466 |
dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (num_dwarf_regs + 1)); |
| 22467 |
dwarf_par_index = 1; |
| 22468 |
|
| 22469 |
for (i = 0; i <= LAST_ARM_REGNUM; i++) |
| 22470 |
{ |
| 22471 |
if (mask & (1 << i)) |
| 22472 |
{ |
| 22473 |
/* NOTE: Dwarf code emitter handle reg-reg copies correctly and in the |
| 22474 |
following example reg-reg copy of SP to IP register is handled |
| 22475 |
through .cfi_def_cfa_register directive and the .cfi_offset |
| 22476 |
directive for IP register is skipped by dwarf code emitter. |
| 22477 |
Example: |
| 22478 |
mov ip, sp |
| 22479 |
.cfi_def_cfa_register 12 |
| 22480 |
push {fp, ip, lr, pc} |
| 22481 |
.cfi_offset 11, -16 |
| 22482 |
.cfi_offset 13, -12 |
| 22483 |
.cfi_offset 14, -8 |
| 22484 |
|
| 22485 |
Where as Arm-specific .save directive handling is different to that |
| 22486 |
of dwarf code emitter and it doesn't consider reg-reg copies while |
| 22487 |
updating the register list. When PACBTI is enabled we manually |
| 22488 |
updated the .save directive register list to use "ra_auth_code" |
| 22489 |
(pseduo register 143) instead of IP register as shown in following |
| 22490 |
pseduo code. |
| 22491 |
Example: |
| 22492 |
pacbti ip, lr, sp |
| 22493 |
.cfi_register 143, 12 |
| 22494 |
push {r3, r7, ip, lr} |
| 22495 |
.save {r3, r7, ra_auth_code, lr} |
| 22496 |
*/ |
| 22497 |
rtx dwarf_reg = reg = gen_rtx_REG (SImode, i); |
| 22498 |
if (arm_current_function_pac_enabled_p () && i == IP_REGNUM) |
| 22499 |
dwarf_reg = gen_rtx_REG (SImode, RA_AUTH_CODE); |
| 22500 |
|
| 22501 |
XVECEXP (par, 0, 0) |
| 22502 |
= gen_rtx_SET (gen_frame_mem |
| 22503 |
(BLKmode, |
| 22504 |
gen_rtx_PRE_MODIFY (Pmode, |
| 22505 |
stack_pointer_rtx, |
| 22506 |
plus_constant |
| 22507 |
(Pmode, stack_pointer_rtx, |
| 22508 |
-4 * num_regs)) |
| 22509 |
), |
| 22510 |
gen_rtx_UNSPEC (BLKmode, |
| 22511 |
gen_rtvec (1, reg), |
| 22512 |
UNSPEC_PUSH_MULT)); |
| 22513 |
|
| 22514 |
if (dwarf_regs_mask & (1 << i)) |
| 22515 |
{ |
| 22516 |
tmp = gen_rtx_SET (gen_frame_mem (SImode, stack_pointer_rtx), |
| 22517 |
dwarf_reg); |
| 22518 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22519 |
XVECEXP (dwarf, 0, dwarf_par_index++) = tmp; |
| 22520 |
} |
| 22521 |
|
| 22522 |
break; |
| 22523 |
} |
| 22524 |
} |
| 22525 |
|
| 22526 |
for (j = 1, i++; j < num_regs; i++) |
| 22527 |
{ |
| 22528 |
if (mask & (1 << i)) |
| 22529 |
{ |
| 22530 |
rtx dwarf_reg = reg = gen_rtx_REG (SImode, i); |
| 22531 |
if (arm_current_function_pac_enabled_p () && i == IP_REGNUM) |
| 22532 |
dwarf_reg = gen_rtx_REG (SImode, RA_AUTH_CODE); |
| 22533 |
|
| 22534 |
XVECEXP (par, 0, j) = gen_rtx_USE (VOIDmode, reg); |
| 22535 |
|
| 22536 |
if (dwarf_regs_mask & (1 << i)) |
| 22537 |
{ |
| 22538 |
tmp |
| 22539 |
= gen_rtx_SET (gen_frame_mem |
| 22540 |
(SImode, |
| 22541 |
plus_constant (Pmode, stack_pointer_rtx, |
| 22542 |
4 * j)), |
| 22543 |
dwarf_reg); |
| 22544 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22545 |
XVECEXP (dwarf, 0, dwarf_par_index++) = tmp; |
| 22546 |
} |
| 22547 |
|
| 22548 |
j++; |
| 22549 |
} |
| 22550 |
} |
| 22551 |
|
| 22552 |
par = emit_insn (par); |
| 22553 |
|
| 22554 |
tmp = gen_rtx_SET (stack_pointer_rtx, |
| 22555 |
plus_constant (Pmode, stack_pointer_rtx, -4 * num_regs)); |
| 22556 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22557 |
XVECEXP (dwarf, 0, 0) = tmp; |
| 22558 |
|
| 22559 |
add_reg_note (par, REG_FRAME_RELATED_EXPR, dwarf); |
| 22560 |
|
| 22561 |
return par; |
| 22562 |
} |
| 22563 |
|
| 22564 |
/* Add a REG_CFA_ADJUST_CFA REG note to INSN. |
| 22565 |
SIZE is the offset to be adjusted. |
| 22566 |
DEST and SRC might be stack_pointer_rtx or hard_frame_pointer_rtx. */ |
| 22567 |
static void |
| 22568 |
arm_add_cfa_adjust_cfa_note (rtx insn, int size, rtx dest, rtx src) |
| 22569 |
{ |
| 22570 |
rtx dwarf; |
| 22571 |
|
| 22572 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 22573 |
dwarf = gen_rtx_SET (dest, plus_constant (Pmode, src, size)); |
| 22574 |
add_reg_note (insn, REG_CFA_ADJUST_CFA, dwarf); |
| 22575 |
} |
| 22576 |
|
| 22577 |
/* Generate and emit an insn pattern that we will recognize as a pop_multi. |
| 22578 |
SAVED_REGS_MASK shows which registers need to be restored. |
| 22579 |
|
| 22580 |
Unfortunately, since this insn does not reflect very well the actual |
| 22581 |
semantics of the operation, we need to annotate the insn for the benefit |
| 22582 |
of DWARF2 frame unwind information. */ |
| 22583 |
static void |
| 22584 |
arm_emit_multi_reg_pop (unsigned long saved_regs_mask) |
| 22585 |
{ |
| 22586 |
int num_regs = 0; |
| 22587 |
rtx par; |
| 22588 |
rtx dwarf = NULL_RTX; |
| 22589 |
rtx tmp, reg; |
| 22590 |
bool return_in_pc = saved_regs_mask & (1 << PC_REGNUM); |
| 22591 |
int offset_adj; |
| 22592 |
int emit_update; |
| 22593 |
unsigned long reg_bits; |
| 22594 |
|
| 22595 |
offset_adj = return_in_pc ? 1 : 0; |
| 22596 |
for (reg_bits = saved_regs_mask; reg_bits; |
| 22597 |
reg_bits &= ~(reg_bits & -reg_bits)) |
| 22598 |
num_regs++; |
| 22599 |
|
| 22600 |
gcc_assert (num_regs && num_regs <= 16); |
| 22601 |
|
| 22602 |
/* If SP is in reglist, then we don't emit SP update insn. */ |
| 22603 |
emit_update = (saved_regs_mask & (1 << SP_REGNUM)) ? 0 : 1; |
| 22604 |
|
| 22605 |
/* If popping just one register, use LDR reg, [SP], #4, unless |
| 22606 |
we're generating Thumb code and reg is a low reg. */ |
| 22607 |
if (num_regs == 1 |
| 22608 |
&& emit_update |
| 22609 |
&& !return_in_pc |
| 22610 |
&& (TARGET_ARM |
| 22611 |
/* For Thumb we want to use POP for a single low register. */ |
| 22612 |
|| (saved_regs_mask & ~0xff))) |
| 22613 |
{ |
| 22614 |
int i = exact_log2 (saved_regs_mask); |
| 22615 |
|
| 22616 |
rtx dwarf_reg = reg = gen_rtx_REG (SImode, i); |
| 22617 |
if (arm_current_function_pac_enabled_p () && i == IP_REGNUM) |
| 22618 |
dwarf_reg = gen_rtx_REG (SImode, RA_AUTH_CODE); |
| 22619 |
/* Emit single load with writeback. */ |
| 22620 |
tmp = gen_frame_mem (SImode, |
| 22621 |
gen_rtx_POST_INC (Pmode, |
| 22622 |
stack_pointer_rtx)); |
| 22623 |
tmp = emit_insn (gen_rtx_SET (reg, tmp)); |
| 22624 |
REG_NOTES (tmp) = alloc_reg_note (REG_CFA_RESTORE, dwarf_reg, |
| 22625 |
dwarf); |
| 22626 |
arm_add_cfa_adjust_cfa_note (tmp, UNITS_PER_WORD, |
| 22627 |
stack_pointer_rtx, stack_pointer_rtx); |
| 22628 |
return; |
| 22629 |
} |
| 22630 |
|
| 22631 |
/* The parallel needs to hold num_regs SETs |
| 22632 |
and one SET for the stack update. */ |
| 22633 |
par = gen_rtx_PARALLEL (VOIDmode, |
| 22634 |
rtvec_alloc (num_regs + emit_update + offset_adj)); |
| 22635 |
|
| 22636 |
if (return_in_pc) |
| 22637 |
XVECEXP (par, 0, 0) = ret_rtx; |
| 22638 |
|
| 22639 |
if (emit_update) |
| 22640 |
{ |
| 22641 |
/* Increment the stack pointer, based on there being |
| 22642 |
num_regs 4-byte registers to restore. */ |
| 22643 |
tmp = gen_rtx_SET (stack_pointer_rtx, |
| 22644 |
plus_constant (Pmode, |
| 22645 |
stack_pointer_rtx, |
| 22646 |
4 * num_regs)); |
| 22647 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22648 |
XVECEXP (par, 0, offset_adj) = tmp; |
| 22649 |
} |
| 22650 |
|
| 22651 |
/* Now restore every reg, which may include PC. */ |
| 22652 |
int j = 0; |
| 22653 |
int elt = emit_update + offset_adj; |
| 22654 |
for (reg_bits = saved_regs_mask; reg_bits; |
| 22655 |
reg_bits &= ~(reg_bits & -reg_bits)) |
| 22656 |
{ |
| 22657 |
int i = exact_log2 (reg_bits & -reg_bits); |
| 22658 |
rtx dwarf_reg = reg = gen_rtx_REG (SImode, i); |
| 22659 |
|
| 22660 |
if (i == IP_REGNUM && arm_current_function_pac_enabled_p ()) |
| 22661 |
dwarf_reg = gen_rtx_REG (SImode, RA_AUTH_CODE); |
| 22662 |
tmp = gen_rtx_SET (reg, |
| 22663 |
gen_frame_mem |
| 22664 |
(SImode, |
| 22665 |
plus_constant (Pmode, stack_pointer_rtx, 4 * j))); |
| 22666 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22667 |
XVECEXP (par, 0, elt) = tmp; |
| 22668 |
|
| 22669 |
/* We need to maintain a sequence for DWARF info too. As dwarf info |
| 22670 |
should not have PC, skip PC. */ |
| 22671 |
if (i != PC_REGNUM) |
| 22672 |
dwarf = alloc_reg_note (REG_CFA_RESTORE, dwarf_reg, dwarf); |
| 22673 |
j++; |
| 22674 |
elt++; |
| 22675 |
} |
| 22676 |
|
| 22677 |
par = return_in_pc ? emit_jump_insn (par) : emit_insn (par); |
| 22678 |
REG_NOTES (par) = dwarf; |
| 22679 |
|
| 22680 |
if (!return_in_pc && emit_update) |
| 22681 |
arm_add_cfa_adjust_cfa_note (par, UNITS_PER_WORD * num_regs, |
| 22682 |
stack_pointer_rtx, stack_pointer_rtx); |
| 22683 |
else if (!return_in_pc) |
| 22684 |
RTX_FRAME_RELATED_P (par) = 1; |
| 22685 |
} |
| 22686 |
|
| 22687 |
/* Generate and emit an insn pattern that we will recognize as a pop_multi |
| 22688 |
of NUM_REGS consecutive VFP regs, starting at FIRST_REG. |
| 22689 |
|
| 22690 |
Unfortunately, since this insn does not reflect very well the actual |
| 22691 |
semantics of the operation, we need to annotate the insn for the benefit |
| 22692 |
of DWARF2 frame unwind information. */ |
| 22693 |
static void |
| 22694 |
arm_emit_vfp_multi_reg_pop (int first_reg, int num_regs, rtx base_reg) |
| 22695 |
{ |
| 22696 |
int i, j; |
| 22697 |
rtx par; |
| 22698 |
rtx dwarf = NULL_RTX; |
| 22699 |
rtx tmp, reg; |
| 22700 |
|
| 22701 |
gcc_assert (num_regs && num_regs <= 32); |
| 22702 |
|
| 22703 |
/* Workaround ARM10 VFPr1 bug. */ |
| 22704 |
if (num_regs == 2 && !arm_arch6) |
| 22705 |
{ |
| 22706 |
if (first_reg == 15) |
| 22707 |
first_reg--; |
| 22708 |
|
| 22709 |
num_regs++; |
| 22710 |
} |
| 22711 |
|
| 22712 |
/* We can emit at most 16 D-registers in a single pop_multi instruction, and |
| 22713 |
there could be up to 32 D-registers to restore. |
| 22714 |
If there are more than 16 D-registers, make two recursive calls, |
| 22715 |
each of which emits one pop_multi instruction. */ |
| 22716 |
if (num_regs > 16) |
| 22717 |
{ |
| 22718 |
arm_emit_vfp_multi_reg_pop (first_reg, 16, base_reg); |
| 22719 |
arm_emit_vfp_multi_reg_pop (first_reg + 16, num_regs - 16, base_reg); |
| 22720 |
return; |
| 22721 |
} |
| 22722 |
|
| 22723 |
/* The parallel needs to hold num_regs SETs |
| 22724 |
and one SET for the stack update. */ |
| 22725 |
par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_regs + 1)); |
| 22726 |
|
| 22727 |
/* Increment the stack pointer, based on there being |
| 22728 |
num_regs 8-byte registers to restore. */ |
| 22729 |
tmp = gen_rtx_SET (base_reg, plus_constant (Pmode, base_reg, 8 * num_regs)); |
| 22730 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22731 |
XVECEXP (par, 0, 0) = tmp; |
| 22732 |
|
| 22733 |
/* Now show every reg that will be restored, using a SET for each. */ |
| 22734 |
for (j = 0, i=first_reg; j < num_regs; i += 2) |
| 22735 |
{ |
| 22736 |
reg = gen_rtx_REG (DFmode, i); |
| 22737 |
|
| 22738 |
tmp = gen_rtx_SET (reg, |
| 22739 |
gen_frame_mem |
| 22740 |
(DFmode, |
| 22741 |
plus_constant (Pmode, base_reg, 8 * j))); |
| 22742 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22743 |
XVECEXP (par, 0, j + 1) = tmp; |
| 22744 |
|
| 22745 |
dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); |
| 22746 |
|
| 22747 |
j++; |
| 22748 |
} |
| 22749 |
|
| 22750 |
par = emit_insn (par); |
| 22751 |
REG_NOTES (par) = dwarf; |
| 22752 |
|
| 22753 |
/* Make sure cfa doesn't leave with IP_REGNUM to allow unwinding fron FP. */ |
| 22754 |
if (REGNO (base_reg) == IP_REGNUM) |
| 22755 |
{ |
| 22756 |
RTX_FRAME_RELATED_P (par) = 1; |
| 22757 |
add_reg_note (par, REG_CFA_DEF_CFA, hard_frame_pointer_rtx); |
| 22758 |
} |
| 22759 |
else |
| 22760 |
arm_add_cfa_adjust_cfa_note (par, 2 * UNITS_PER_WORD * num_regs, |
| 22761 |
base_reg, base_reg); |
| 22762 |
} |
| 22763 |
|
| 22764 |
/* Generate and emit a pattern that will be recognized as LDRD pattern. If even |
| 22765 |
number of registers are being popped, multiple LDRD patterns are created for |
| 22766 |
all register pairs. If odd number of registers are popped, last register is |
| 22767 |
loaded by using LDR pattern. */ |
| 22768 |
static void |
| 22769 |
thumb2_emit_ldrd_pop (unsigned long saved_regs_mask) |
| 22770 |
{ |
| 22771 |
int num_regs = 0; |
| 22772 |
int i, j; |
| 22773 |
rtx par = NULL_RTX; |
| 22774 |
rtx dwarf = NULL_RTX; |
| 22775 |
rtx tmp, reg, tmp1; |
| 22776 |
bool return_in_pc = saved_regs_mask & (1 << PC_REGNUM); |
| 22777 |
|
| 22778 |
for (i = 0; i <= LAST_ARM_REGNUM; i++) |
| 22779 |
if (saved_regs_mask & (1 << i)) |
| 22780 |
num_regs++; |
| 22781 |
|
| 22782 |
gcc_assert (num_regs && num_regs <= 16); |
| 22783 |
|
| 22784 |
/* We cannot generate ldrd for PC. Hence, reduce the count if PC is |
| 22785 |
to be popped. So, if num_regs is even, now it will become odd, |
| 22786 |
and we can generate pop with PC. If num_regs is odd, it will be |
| 22787 |
even now, and ldr with return can be generated for PC. */ |
| 22788 |
if (return_in_pc) |
| 22789 |
num_regs--; |
| 22790 |
|
| 22791 |
gcc_assert (!(saved_regs_mask & (1 << SP_REGNUM))); |
| 22792 |
|
| 22793 |
/* Var j iterates over all the registers to gather all the registers in |
| 22794 |
saved_regs_mask. Var i gives index of saved registers in stack frame. |
| 22795 |
A PARALLEL RTX of register-pair is created here, so that pattern for |
| 22796 |
LDRD can be matched. As PC is always last register to be popped, and |
| 22797 |
we have already decremented num_regs if PC, we don't have to worry |
| 22798 |
about PC in this loop. */ |
| 22799 |
for (i = 0, j = 0; i < (num_regs - (num_regs % 2)); j++) |
| 22800 |
if (saved_regs_mask & (1 << j)) |
| 22801 |
{ |
| 22802 |
/* Create RTX for memory load. */ |
| 22803 |
reg = gen_rtx_REG (SImode, j); |
| 22804 |
tmp = gen_rtx_SET (reg, |
| 22805 |
gen_frame_mem (SImode, |
| 22806 |
plus_constant (Pmode, |
| 22807 |
stack_pointer_rtx, 4 * i))); |
| 22808 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22809 |
|
| 22810 |
if (i % 2 == 0) |
| 22811 |
{ |
| 22812 |
/* When saved-register index (i) is even, the RTX to be emitted is |
| 22813 |
yet to be created. Hence create it first. The LDRD pattern we |
| 22814 |
are generating is : |
| 22815 |
[ (SET (reg_t0) (MEM (PLUS (SP) (NUM)))) |
| 22816 |
(SET (reg_t1) (MEM (PLUS (SP) (NUM + 4)))) ] |
| 22817 |
where target registers need not be consecutive. */ |
| 22818 |
par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2)); |
| 22819 |
dwarf = NULL_RTX; |
| 22820 |
} |
| 22821 |
|
| 22822 |
/* ith register is added in PARALLEL RTX. If i is even, the reg_i is |
| 22823 |
added as 0th element and if i is odd, reg_i is added as 1st element |
| 22824 |
of LDRD pattern shown above. */ |
| 22825 |
XVECEXP (par, 0, (i % 2)) = tmp; |
| 22826 |
dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); |
| 22827 |
|
| 22828 |
if ((i % 2) == 1) |
| 22829 |
{ |
| 22830 |
/* When saved-register index (i) is odd, RTXs for both the registers |
| 22831 |
to be loaded are generated in above given LDRD pattern, and the |
| 22832 |
pattern can be emitted now. */ |
| 22833 |
par = emit_insn (par); |
| 22834 |
REG_NOTES (par) = dwarf; |
| 22835 |
RTX_FRAME_RELATED_P (par) = 1; |
| 22836 |
} |
| 22837 |
|
| 22838 |
i++; |
| 22839 |
} |
| 22840 |
|
| 22841 |
/* If the number of registers pushed is odd AND return_in_pc is false OR |
| 22842 |
number of registers are even AND return_in_pc is true, last register is |
| 22843 |
popped using LDR. It can be PC as well. Hence, adjust the stack first and |
| 22844 |
then LDR with post increment. */ |
| 22845 |
|
| 22846 |
/* Increment the stack pointer, based on there being |
| 22847 |
num_regs 4-byte registers to restore. */ |
| 22848 |
tmp = gen_rtx_SET (stack_pointer_rtx, |
| 22849 |
plus_constant (Pmode, stack_pointer_rtx, 4 * i)); |
| 22850 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22851 |
tmp = emit_insn (tmp); |
| 22852 |
if (!return_in_pc) |
| 22853 |
{ |
| 22854 |
arm_add_cfa_adjust_cfa_note (tmp, UNITS_PER_WORD * i, |
| 22855 |
stack_pointer_rtx, stack_pointer_rtx); |
| 22856 |
} |
| 22857 |
|
| 22858 |
dwarf = NULL_RTX; |
| 22859 |
|
| 22860 |
if (((num_regs % 2) == 1 && !return_in_pc) |
| 22861 |
|| ((num_regs % 2) == 0 && return_in_pc)) |
| 22862 |
{ |
| 22863 |
/* Scan for the single register to be popped. Skip until the saved |
| 22864 |
register is found. */ |
| 22865 |
for (; (saved_regs_mask & (1 << j)) == 0; j++); |
| 22866 |
|
| 22867 |
/* Gen LDR with post increment here. */ |
| 22868 |
tmp1 = gen_rtx_MEM (SImode, |
| 22869 |
gen_rtx_POST_INC (SImode, |
| 22870 |
stack_pointer_rtx)); |
| 22871 |
set_mem_alias_set (tmp1, get_frame_alias_set ()); |
| 22872 |
|
| 22873 |
reg = gen_rtx_REG (SImode, j); |
| 22874 |
tmp = gen_rtx_SET (reg, tmp1); |
| 22875 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22876 |
dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); |
| 22877 |
|
| 22878 |
if (return_in_pc) |
| 22879 |
{ |
| 22880 |
/* If return_in_pc, j must be PC_REGNUM. */ |
| 22881 |
gcc_assert (j == PC_REGNUM); |
| 22882 |
par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2)); |
| 22883 |
XVECEXP (par, 0, 0) = ret_rtx; |
| 22884 |
XVECEXP (par, 0, 1) = tmp; |
| 22885 |
par = emit_jump_insn (par); |
| 22886 |
} |
| 22887 |
else |
| 22888 |
{ |
| 22889 |
par = emit_insn (tmp); |
| 22890 |
REG_NOTES (par) = dwarf; |
| 22891 |
arm_add_cfa_adjust_cfa_note (par, UNITS_PER_WORD, |
| 22892 |
stack_pointer_rtx, stack_pointer_rtx); |
| 22893 |
} |
| 22894 |
|
| 22895 |
} |
| 22896 |
else if ((num_regs % 2) == 1 && return_in_pc) |
| 22897 |
{ |
| 22898 |
/* There are 2 registers to be popped. So, generate the pattern |
| 22899 |
pop_multiple_with_stack_update_and_return to pop in PC. */ |
| 22900 |
arm_emit_multi_reg_pop (saved_regs_mask & (~((1 << j) - 1))); |
| 22901 |
} |
| 22902 |
|
| 22903 |
return; |
| 22904 |
} |
| 22905 |
|
| 22906 |
/* LDRD in ARM mode needs consecutive registers as operands. This function |
| 22907 |
emits LDRD whenever possible, otherwise it emits single-word loads. It uses |
| 22908 |
offset addressing and then generates one separate stack udpate. This provides |
| 22909 |
more scheduling freedom, compared to writeback on every load. However, |
| 22910 |
if the function returns using load into PC directly |
| 22911 |
(i.e., if PC is in SAVED_REGS_MASK), the stack needs to be updated |
| 22912 |
before the last load. TODO: Add a peephole optimization to recognize |
| 22913 |
the new epilogue sequence as an LDM instruction whenever possible. TODO: Add |
| 22914 |
peephole optimization to merge the load at stack-offset zero |
| 22915 |
with the stack update instruction using load with writeback |
| 22916 |
in post-index addressing mode. */ |
| 22917 |
static void |
| 22918 |
arm_emit_ldrd_pop (unsigned long saved_regs_mask) |
| 22919 |
{ |
| 22920 |
int j = 0; |
| 22921 |
int offset = 0; |
| 22922 |
rtx par = NULL_RTX; |
| 22923 |
rtx dwarf = NULL_RTX; |
| 22924 |
rtx tmp, mem; |
| 22925 |
|
| 22926 |
/* Restore saved registers. */ |
| 22927 |
gcc_assert (!((saved_regs_mask & (1 << SP_REGNUM)))); |
| 22928 |
j = 0; |
| 22929 |
while (j <= LAST_ARM_REGNUM) |
| 22930 |
if (saved_regs_mask & (1 << j)) |
| 22931 |
{ |
| 22932 |
if ((j % 2) == 0 |
| 22933 |
&& (saved_regs_mask & (1 << (j + 1))) |
| 22934 |
&& (j + 1) != PC_REGNUM) |
| 22935 |
{ |
| 22936 |
/* Current register and next register form register pair for which |
| 22937 |
LDRD can be generated. PC is always the last register popped, and |
| 22938 |
we handle it separately. */ |
| 22939 |
if (offset > 0) |
| 22940 |
mem = gen_frame_mem (DImode, |
| 22941 |
plus_constant (Pmode, |
| 22942 |
stack_pointer_rtx, |
| 22943 |
offset)); |
| 22944 |
else |
| 22945 |
mem = gen_frame_mem (DImode, stack_pointer_rtx); |
| 22946 |
|
| 22947 |
tmp = gen_rtx_SET (gen_rtx_REG (DImode, j), mem); |
| 22948 |
tmp = emit_insn (tmp); |
| 22949 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22950 |
|
| 22951 |
/* Generate dwarf info. */ |
| 22952 |
|
| 22953 |
dwarf = alloc_reg_note (REG_CFA_RESTORE, |
| 22954 |
gen_rtx_REG (SImode, j), |
| 22955 |
NULL_RTX); |
| 22956 |
dwarf = alloc_reg_note (REG_CFA_RESTORE, |
| 22957 |
gen_rtx_REG (SImode, j + 1), |
| 22958 |
dwarf); |
| 22959 |
|
| 22960 |
REG_NOTES (tmp) = dwarf; |
| 22961 |
|
| 22962 |
offset += 8; |
| 22963 |
j += 2; |
| 22964 |
} |
| 22965 |
else if (j != PC_REGNUM) |
| 22966 |
{ |
| 22967 |
/* Emit a single word load. */ |
| 22968 |
if (offset > 0) |
| 22969 |
mem = gen_frame_mem (SImode, |
| 22970 |
plus_constant (Pmode, |
| 22971 |
stack_pointer_rtx, |
| 22972 |
offset)); |
| 22973 |
else |
| 22974 |
mem = gen_frame_mem (SImode, stack_pointer_rtx); |
| 22975 |
|
| 22976 |
tmp = gen_rtx_SET (gen_rtx_REG (SImode, j), mem); |
| 22977 |
tmp = emit_insn (tmp); |
| 22978 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 22979 |
|
| 22980 |
/* Generate dwarf info. */ |
| 22981 |
REG_NOTES (tmp) = alloc_reg_note (REG_CFA_RESTORE, |
| 22982 |
gen_rtx_REG (SImode, j), |
| 22983 |
NULL_RTX); |
| 22984 |
|
| 22985 |
offset += 4; |
| 22986 |
j += 1; |
| 22987 |
} |
| 22988 |
else /* j == PC_REGNUM */ |
| 22989 |
j++; |
| 22990 |
} |
| 22991 |
else |
| 22992 |
j++; |
| 22993 |
|
| 22994 |
/* Update the stack. */ |
| 22995 |
if (offset > 0) |
| 22996 |
{ |
| 22997 |
tmp = gen_rtx_SET (stack_pointer_rtx, |
| 22998 |
plus_constant (Pmode, |
| 22999 |
stack_pointer_rtx, |
| 23000 |
offset)); |
| 23001 |
tmp = emit_insn (tmp); |
| 23002 |
arm_add_cfa_adjust_cfa_note (tmp, offset, |
| 23003 |
stack_pointer_rtx, stack_pointer_rtx); |
| 23004 |
offset = 0; |
| 23005 |
} |
| 23006 |
|
| 23007 |
if (saved_regs_mask & (1 << PC_REGNUM)) |
| 23008 |
{ |
| 23009 |
/* Only PC is to be popped. */ |
| 23010 |
par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2)); |
| 23011 |
XVECEXP (par, 0, 0) = ret_rtx; |
| 23012 |
tmp = gen_rtx_SET (gen_rtx_REG (SImode, PC_REGNUM), |
| 23013 |
gen_frame_mem (SImode, |
| 23014 |
gen_rtx_POST_INC (SImode, |
| 23015 |
stack_pointer_rtx))); |
| 23016 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 23017 |
XVECEXP (par, 0, 1) = tmp; |
| 23018 |
par = emit_jump_insn (par); |
| 23019 |
|
| 23020 |
/* Generate dwarf info. */ |
| 23021 |
dwarf = alloc_reg_note (REG_CFA_RESTORE, |
| 23022 |
gen_rtx_REG (SImode, PC_REGNUM), |
| 23023 |
NULL_RTX); |
| 23024 |
REG_NOTES (par) = dwarf; |
| 23025 |
arm_add_cfa_adjust_cfa_note (par, UNITS_PER_WORD, |
| 23026 |
stack_pointer_rtx, stack_pointer_rtx); |
| 23027 |
} |
| 23028 |
} |
| 23029 |
|
| 23030 |
/* Calculate the size of the return value that is passed in registers. */ |
| 23031 |
static unsigned |
| 23032 |
arm_size_return_regs (void) |
| 23033 |
{ |
| 23034 |
machine_mode mode; |
| 23035 |
|
| 23036 |
if (crtl->return_rtx != 0) |
| 23037 |
mode = GET_MODE (crtl->return_rtx); |
| 23038 |
else |
| 23039 |
mode = DECL_MODE (DECL_RESULT (current_function_decl)); |
| 23040 |
|
| 23041 |
return GET_MODE_SIZE (mode); |
| 23042 |
} |
| 23043 |
|
| 23044 |
/* Return true if the current function needs to save/restore LR. */ |
| 23045 |
static bool |
| 23046 |
thumb_force_lr_save (void) |
| 23047 |
{ |
| 23048 |
return !cfun->machine->lr_save_eliminated |
| 23049 |
&& (!crtl->is_leaf |
| 23050 |
|| thumb_far_jump_used_p () |
| 23051 |
|| df_regs_ever_live_p (LR_REGNUM)); |
| 23052 |
} |
| 23053 |
|
| 23054 |
/* We do not know if r3 will be available because |
| 23055 |
we do have an indirect tailcall happening in this |
| 23056 |
particular case. */ |
| 23057 |
static bool |
| 23058 |
is_indirect_tailcall_p (rtx call) |
| 23059 |
{ |
| 23060 |
rtx pat = PATTERN (call); |
| 23061 |
|
| 23062 |
/* Indirect tail call. */ |
| 23063 |
pat = XVECEXP (pat, 0, 0); |
| 23064 |
if (GET_CODE (pat) == SET) |
| 23065 |
pat = SET_SRC (pat); |
| 23066 |
|
| 23067 |
pat = XEXP (XEXP (pat, 0), 0); |
| 23068 |
return REG_P (pat); |
| 23069 |
} |
| 23070 |
|
| 23071 |
/* Return true if r3 is used by any of the tail call insns in the |
| 23072 |
current function. */ |
| 23073 |
static bool |
| 23074 |
any_sibcall_could_use_r3 (void) |
| 23075 |
{ |
| 23076 |
edge_iterator ei; |
| 23077 |
edge e; |
| 23078 |
|
| 23079 |
if (!crtl->tail_call_emit) |
| 23080 |
return false; |
| 23081 |
FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds) |
| 23082 |
if (e->flags & EDGE_SIBCALL) |
| 23083 |
{ |
| 23084 |
rtx_insn *call = BB_END (e->src); |
| 23085 |
if (!CALL_P (call)) |
| 23086 |
call = prev_nonnote_nondebug_insn (call); |
| 23087 |
gcc_assert (CALL_P (call) && SIBLING_CALL_P (call)); |
| 23088 |
if (find_regno_fusage (call, USE, 3) |
| 23089 |
|| is_indirect_tailcall_p (call)) |
| 23090 |
return true; |
| 23091 |
} |
| 23092 |
return false; |
| 23093 |
} |
| 23094 |
|
| 23095 |
|
| 23096 |
/* Compute the distance from register FROM to register TO. |
| 23097 |
These can be the arg pointer (26), the soft frame pointer (25), |
| 23098 |
the stack pointer (13) or the hard frame pointer (11). |
| 23099 |
In thumb mode r7 is used as the soft frame pointer, if needed. |
| 23100 |
Typical stack layout looks like this: |
| 23101 |
|
| 23102 |
old stack pointer -> | | |
| 23103 |
---- |
| 23104 |
| | \ |
| 23105 |
| | saved arguments for |
| 23106 |
| | vararg functions |
| 23107 |
| | / |
| 23108 |
-- |
| 23109 |
hard FP & arg pointer -> | | \ |
| 23110 |
| | stack |
| 23111 |
| | frame |
| 23112 |
| | / |
| 23113 |
-- |
| 23114 |
| | \ |
| 23115 |
| | call saved |
| 23116 |
| | registers |
| 23117 |
soft frame pointer -> | | / |
| 23118 |
-- |
| 23119 |
| | \ |
| 23120 |
| | local |
| 23121 |
| | variables |
| 23122 |
locals base pointer -> | | / |
| 23123 |
-- |
| 23124 |
| | \ |
| 23125 |
| | outgoing |
| 23126 |
| | arguments |
| 23127 |
current stack pointer -> | | / |
| 23128 |
-- |
| 23129 |
|
| 23130 |
For a given function some or all of these stack components |
| 23131 |
may not be needed, giving rise to the possibility of |
| 23132 |
eliminating some of the registers. |
| 23133 |
|
| 23134 |
The values returned by this function must reflect the behavior |
| 23135 |
of arm_expand_prologue () and arm_compute_save_core_reg_mask (). |
| 23136 |
|
| 23137 |
The sign of the number returned reflects the direction of stack |
| 23138 |
growth, so the values are positive for all eliminations except |
| 23139 |
from the soft frame pointer to the hard frame pointer. |
| 23140 |
|
| 23141 |
SFP may point just inside the local variables block to ensure correct |
| 23142 |
alignment. */ |
| 23143 |
|
| 23144 |
|
| 23145 |
/* Return cached stack offsets. */ |
| 23146 |
|
| 23147 |
static arm_stack_offsets * |
| 23148 |
arm_get_frame_offsets (void) |
| 23149 |
{ |
| 23150 |
struct arm_stack_offsets *offsets; |
| 23151 |
|
| 23152 |
offsets = &cfun->machine->stack_offsets; |
| 23153 |
|
| 23154 |
return offsets; |
| 23155 |
} |
| 23156 |
|
| 23157 |
|
| 23158 |
/* Calculate stack offsets. These are used to calculate register elimination |
| 23159 |
offsets and in prologue/epilogue code. Also calculates which registers |
| 23160 |
should be saved. */ |
| 23161 |
|
| 23162 |
static void |
| 23163 |
arm_compute_frame_layout (void) |
| 23164 |
{ |
| 23165 |
struct arm_stack_offsets *offsets; |
| 23166 |
unsigned long func_type; |
| 23167 |
int saved; |
| 23168 |
int core_saved; |
| 23169 |
HOST_WIDE_INT frame_size; |
| 23170 |
int i; |
| 23171 |
|
| 23172 |
offsets = &cfun->machine->stack_offsets; |
| 23173 |
|
| 23174 |
/* Initially this is the size of the local variables. It will translated |
| 23175 |
into an offset once we have determined the size of preceding data. */ |
| 23176 |
frame_size = ROUND_UP_WORD (get_frame_size ()); |
| 23177 |
|
| 23178 |
/* Space for variadic functions. */ |
| 23179 |
offsets->saved_args = crtl->args.pretend_args_size; |
| 23180 |
|
| 23181 |
/* In Thumb mode this is incorrect, but never used. */ |
| 23182 |
offsets->frame |
| 23183 |
= (offsets->saved_args |
| 23184 |
+ arm_compute_static_chain_stack_bytes () |
| 23185 |
+ (frame_pointer_needed ? 4 : 0)); |
| 23186 |
|
| 23187 |
if (TARGET_32BIT) |
| 23188 |
{ |
| 23189 |
unsigned int regno; |
| 23190 |
|
| 23191 |
offsets->saved_regs_mask = arm_compute_save_core_reg_mask (); |
| 23192 |
core_saved = bit_count (offsets->saved_regs_mask) * 4; |
| 23193 |
saved = core_saved; |
| 23194 |
|
| 23195 |
/* We know that SP will be doubleword aligned on entry, and we must |
| 23196 |
preserve that condition at any subroutine call. We also require the |
| 23197 |
soft frame pointer to be doubleword aligned. */ |
| 23198 |
|
| 23199 |
if (TARGET_REALLY_IWMMXT) |
| 23200 |
{ |
| 23201 |
/* Check for the call-saved iWMMXt registers. */ |
| 23202 |
for (regno = FIRST_IWMMXT_REGNUM; |
| 23203 |
regno <= LAST_IWMMXT_REGNUM; |
| 23204 |
regno++) |
| 23205 |
if (reg_needs_saving_p (regno)) |
| 23206 |
saved += 8; |
| 23207 |
} |
| 23208 |
|
| 23209 |
func_type = arm_current_func_type (); |
| 23210 |
/* Space for saved VFP registers. */ |
| 23211 |
if (! IS_VOLATILE (func_type) |
| 23212 |
&& TARGET_VFP_BASE) |
| 23213 |
saved += arm_get_vfp_saved_size (); |
| 23214 |
|
| 23215 |
/* Allocate space for saving/restoring FPCXTNS in Armv8.1-M Mainline |
| 23216 |
nonecure entry functions with VSTR/VLDR. */ |
| 23217 |
if (TARGET_HAVE_FPCXT_CMSE && IS_CMSE_ENTRY (func_type)) |
| 23218 |
saved += 4; |
| 23219 |
} |
| 23220 |
else /* TARGET_THUMB1 */ |
| 23221 |
{ |
| 23222 |
offsets->saved_regs_mask = thumb1_compute_save_core_reg_mask (); |
| 23223 |
core_saved = bit_count (offsets->saved_regs_mask) * 4; |
| 23224 |
saved = core_saved; |
| 23225 |
if (TARGET_BACKTRACE) |
| 23226 |
saved += 16; |
| 23227 |
} |
| 23228 |
|
| 23229 |
/* Saved registers include the stack frame. */ |
| 23230 |
offsets->saved_regs |
| 23231 |
= offsets->saved_args + arm_compute_static_chain_stack_bytes () + saved; |
| 23232 |
offsets->soft_frame = offsets->saved_regs + CALLER_INTERWORKING_SLOT_SIZE; |
| 23233 |
|
| 23234 |
/* A leaf function does not need any stack alignment if it has nothing |
| 23235 |
on the stack. */ |
| 23236 |
if (crtl->is_leaf && frame_size == 0 |
| 23237 |
/* However if it calls alloca(), we have a dynamically allocated |
| 23238 |
block of BIGGEST_ALIGNMENT on stack, so still do stack alignment. */ |
| 23239 |
&& ! cfun->calls_alloca) |
| 23240 |
{ |
| 23241 |
offsets->outgoing_args = offsets->soft_frame; |
| 23242 |
offsets->locals_base = offsets->soft_frame; |
| 23243 |
return; |
| 23244 |
} |
| 23245 |
|
| 23246 |
/* Ensure SFP has the correct alignment. */ |
| 23247 |
if (ARM_DOUBLEWORD_ALIGN |
| 23248 |
&& (offsets->soft_frame & 7)) |
| 23249 |
{ |
| 23250 |
offsets->soft_frame += 4; |
| 23251 |
/* Try to align stack by pushing an extra reg. Don't bother doing this |
| 23252 |
when there is a stack frame as the alignment will be rolled into |
| 23253 |
the normal stack adjustment. */ |
| 23254 |
if (frame_size + crtl->outgoing_args_size == 0) |
| 23255 |
{ |
| 23256 |
int reg = -1; |
| 23257 |
|
| 23258 |
/* Register r3 is caller-saved. Normally it does not need to be |
| 23259 |
saved on entry by the prologue. However if we choose to save |
| 23260 |
it for padding then we may confuse the compiler into thinking |
| 23261 |
a prologue sequence is required when in fact it is not. This |
| 23262 |
will occur when shrink-wrapping if r3 is used as a scratch |
| 23263 |
register and there are no other callee-saved writes. |
| 23264 |
|
| 23265 |
This situation can be avoided when other callee-saved registers |
| 23266 |
are available and r3 is not mandatory if we choose a callee-saved |
| 23267 |
register for padding. */ |
| 23268 |
bool prefer_callee_reg_p = false; |
| 23269 |
|
| 23270 |
/* If it is safe to use r3, then do so. This sometimes |
| 23271 |
generates better code on Thumb-2 by avoiding the need to |
| 23272 |
use 32-bit push/pop instructions. */ |
| 23273 |
if (! any_sibcall_could_use_r3 () |
| 23274 |
&& arm_size_return_regs () <= 12 |
| 23275 |
&& (offsets->saved_regs_mask & (1 << 3)) == 0 |
| 23276 |
&& (TARGET_THUMB2 |
| 23277 |
|| !(TARGET_LDRD && current_tune->prefer_ldrd_strd))) |
| 23278 |
{ |
| 23279 |
reg = 3; |
| 23280 |
if (!TARGET_THUMB2) |
| 23281 |
prefer_callee_reg_p = true; |
| 23282 |
} |
| 23283 |
if (reg == -1 |
| 23284 |
|| prefer_callee_reg_p) |
| 23285 |
{ |
| 23286 |
for (i = 4; i <= (TARGET_THUMB1 ? LAST_LO_REGNUM : 11); i++) |
| 23287 |
{ |
| 23288 |
/* Avoid fixed registers; they may be changed at |
| 23289 |
arbitrary times so it's unsafe to restore them |
| 23290 |
during the epilogue. */ |
| 23291 |
if (!fixed_regs[i] |
| 23292 |
&& (offsets->saved_regs_mask & (1 << i)) == 0) |
| 23293 |
{ |
| 23294 |
reg = i; |
| 23295 |
break; |
| 23296 |
} |
| 23297 |
} |
| 23298 |
} |
| 23299 |
|
| 23300 |
if (reg != -1) |
| 23301 |
{ |
| 23302 |
offsets->saved_regs += 4; |
| 23303 |
offsets->saved_regs_mask |= (1 << reg); |
| 23304 |
} |
| 23305 |
} |
| 23306 |
} |
| 23307 |
|
| 23308 |
offsets->locals_base = offsets->soft_frame + frame_size; |
| 23309 |
offsets->outgoing_args = (offsets->locals_base |
| 23310 |
+ crtl->outgoing_args_size); |
| 23311 |
|
| 23312 |
if (ARM_DOUBLEWORD_ALIGN) |
| 23313 |
{ |
| 23314 |
/* Ensure SP remains doubleword aligned. */ |
| 23315 |
if (offsets->outgoing_args & 7) |
| 23316 |
offsets->outgoing_args += 4; |
| 23317 |
gcc_assert (!(offsets->outgoing_args & 7)); |
| 23318 |
} |
| 23319 |
} |
| 23320 |
|
| 23321 |
|
| 23322 |
/* Calculate the relative offsets for the different stack pointers. Positive |
| 23323 |
offsets are in the direction of stack growth. */ |
| 23324 |
|
| 23325 |
HOST_WIDE_INT |
| 23326 |
arm_compute_initial_elimination_offset (unsigned int from, unsigned int to) |
| 23327 |
{ |
| 23328 |
arm_stack_offsets *offsets; |
| 23329 |
|
| 23330 |
offsets = arm_get_frame_offsets (); |
| 23331 |
|
| 23332 |
/* OK, now we have enough information to compute the distances. |
| 23333 |
There must be an entry in these switch tables for each pair |
| 23334 |
of registers in ELIMINABLE_REGS, even if some of the entries |
| 23335 |
seem to be redundant or useless. */ |
| 23336 |
switch (from) |
| 23337 |
{ |
| 23338 |
case ARG_POINTER_REGNUM: |
| 23339 |
switch (to) |
| 23340 |
{ |
| 23341 |
case THUMB_HARD_FRAME_POINTER_REGNUM: |
| 23342 |
return 0; |
| 23343 |
|
| 23344 |
case FRAME_POINTER_REGNUM: |
| 23345 |
/* This is the reverse of the soft frame pointer |
| 23346 |
to hard frame pointer elimination below. */ |
| 23347 |
return offsets->soft_frame - offsets->saved_args; |
| 23348 |
|
| 23349 |
case ARM_HARD_FRAME_POINTER_REGNUM: |
| 23350 |
/* This is only non-zero in the case where the static chain register |
| 23351 |
is stored above the frame. */ |
| 23352 |
return offsets->frame - offsets->saved_args - 4; |
| 23353 |
|
| 23354 |
case STACK_POINTER_REGNUM: |
| 23355 |
/* If nothing has been pushed on the stack at all |
| 23356 |
then this will return -4. This *is* correct! */ |
| 23357 |
return offsets->outgoing_args - (offsets->saved_args + 4); |
| 23358 |
|
| 23359 |
default: |
| 23360 |
gcc_unreachable (); |
| 23361 |
} |
| 23362 |
gcc_unreachable (); |
| 23363 |
|
| 23364 |
case FRAME_POINTER_REGNUM: |
| 23365 |
switch (to) |
| 23366 |
{ |
| 23367 |
case THUMB_HARD_FRAME_POINTER_REGNUM: |
| 23368 |
return 0; |
| 23369 |
|
| 23370 |
case ARM_HARD_FRAME_POINTER_REGNUM: |
| 23371 |
/* The hard frame pointer points to the top entry in the |
| 23372 |
stack frame. The soft frame pointer to the bottom entry |
| 23373 |
in the stack frame. If there is no stack frame at all, |
| 23374 |
then they are identical. */ |
| 23375 |
|
| 23376 |
return offsets->frame - offsets->soft_frame; |
| 23377 |
|
| 23378 |
case STACK_POINTER_REGNUM: |
| 23379 |
return offsets->outgoing_args - offsets->soft_frame; |
| 23380 |
|
| 23381 |
default: |
| 23382 |
gcc_unreachable (); |
| 23383 |
} |
| 23384 |
gcc_unreachable (); |
| 23385 |
|
| 23386 |
default: |
| 23387 |
/* You cannot eliminate from the stack pointer. |
| 23388 |
In theory you could eliminate from the hard frame |
| 23389 |
pointer to the stack pointer, but this will never |
| 23390 |
happen, since if a stack frame is not needed the |
| 23391 |
hard frame pointer will never be used. */ |
| 23392 |
gcc_unreachable (); |
| 23393 |
} |
| 23394 |
} |
| 23395 |
|
| 23396 |
/* Given FROM and TO register numbers, say whether this elimination is |
| 23397 |
allowed. Frame pointer elimination is automatically handled. |
| 23398 |
|
| 23399 |
All eliminations are permissible. Note that ARG_POINTER_REGNUM and |
| 23400 |
HARD_FRAME_POINTER_REGNUM are in fact the same thing. If we need a frame |
| 23401 |
pointer, we must eliminate FRAME_POINTER_REGNUM into |
| 23402 |
HARD_FRAME_POINTER_REGNUM and not into STACK_POINTER_REGNUM or |
| 23403 |
ARG_POINTER_REGNUM. */ |
| 23404 |
|
| 23405 |
bool |
| 23406 |
arm_can_eliminate (const int from, const int to) |
| 23407 |
{ |
| 23408 |
return ((to == FRAME_POINTER_REGNUM && from == ARG_POINTER_REGNUM) ? false : |
| 23409 |
(to == STACK_POINTER_REGNUM && frame_pointer_needed) ? false : |
| 23410 |
(to == ARM_HARD_FRAME_POINTER_REGNUM && TARGET_THUMB) ? false : |
| 23411 |
(to == THUMB_HARD_FRAME_POINTER_REGNUM && TARGET_ARM) ? false : |
| 23412 |
true); |
| 23413 |
} |
| 23414 |
|
| 23415 |
/* Emit RTL to save coprocessor registers on function entry. Returns the |
| 23416 |
number of bytes pushed. */ |
| 23417 |
|
| 23418 |
static int |
| 23419 |
arm_save_coproc_regs(void) |
| 23420 |
{ |
| 23421 |
int saved_size = 0; |
| 23422 |
unsigned reg; |
| 23423 |
unsigned start_reg; |
| 23424 |
rtx insn; |
| 23425 |
|
| 23426 |
if (TARGET_REALLY_IWMMXT) |
| 23427 |
for (reg = LAST_IWMMXT_REGNUM; reg >= FIRST_IWMMXT_REGNUM; reg--) |
| 23428 |
if (reg_needs_saving_p (reg)) |
| 23429 |
{ |
| 23430 |
insn = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx); |
| 23431 |
insn = gen_rtx_MEM (V2SImode, insn); |
| 23432 |
insn = emit_set_insn (insn, gen_rtx_REG (V2SImode, reg)); |
| 23433 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 23434 |
saved_size += 8; |
| 23435 |
} |
| 23436 |
|
| 23437 |
if (TARGET_VFP_BASE) |
| 23438 |
{ |
| 23439 |
start_reg = FIRST_VFP_REGNUM; |
| 23440 |
|
| 23441 |
for (reg = FIRST_VFP_REGNUM; reg < LAST_VFP_REGNUM; reg += 2) |
| 23442 |
{ |
| 23443 |
if (!reg_needs_saving_p (reg) && !reg_needs_saving_p (reg + 1)) |
| 23444 |
{ |
| 23445 |
if (start_reg != reg) |
| 23446 |
saved_size += vfp_emit_fstmd (start_reg, |
| 23447 |
(reg - start_reg) / 2); |
| 23448 |
start_reg = reg + 2; |
| 23449 |
} |
| 23450 |
} |
| 23451 |
if (start_reg != reg) |
| 23452 |
saved_size += vfp_emit_fstmd (start_reg, |
| 23453 |
(reg - start_reg) / 2); |
| 23454 |
} |
| 23455 |
return saved_size; |
| 23456 |
} |
| 23457 |
|
| 23458 |
|
| 23459 |
/* Set the Thumb frame pointer from the stack pointer. */ |
| 23460 |
|
| 23461 |
static void |
| 23462 |
thumb_set_frame_pointer (arm_stack_offsets *offsets) |
| 23463 |
{ |
| 23464 |
HOST_WIDE_INT amount; |
| 23465 |
rtx insn, dwarf; |
| 23466 |
|
| 23467 |
amount = offsets->outgoing_args - offsets->locals_base; |
| 23468 |
if (amount < 1024) |
| 23469 |
insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, |
| 23470 |
stack_pointer_rtx, GEN_INT (amount))); |
| 23471 |
else |
| 23472 |
{ |
| 23473 |
emit_insn (gen_movsi (hard_frame_pointer_rtx, GEN_INT (amount))); |
| 23474 |
/* Thumb-2 RTL patterns expect sp as the first input. Thumb-1 |
| 23475 |
expects the first two operands to be the same. */ |
| 23476 |
if (TARGET_THUMB2) |
| 23477 |
{ |
| 23478 |
insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, |
| 23479 |
stack_pointer_rtx, |
| 23480 |
hard_frame_pointer_rtx)); |
| 23481 |
} |
| 23482 |
else |
| 23483 |
{ |
| 23484 |
insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, |
| 23485 |
hard_frame_pointer_rtx, |
| 23486 |
stack_pointer_rtx)); |
| 23487 |
} |
| 23488 |
dwarf = gen_rtx_SET (hard_frame_pointer_rtx, |
| 23489 |
plus_constant (Pmode, stack_pointer_rtx, amount)); |
| 23490 |
RTX_FRAME_RELATED_P (dwarf) = 1; |
| 23491 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
| 23492 |
} |
| 23493 |
|
| 23494 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 23495 |
} |
| 23496 |
|
| 23497 |
struct scratch_reg { |
| 23498 |
rtx reg; |
| 23499 |
bool saved; |
| 23500 |
}; |
| 23501 |
|
| 23502 |
/* Return a short-lived scratch register for use as a 2nd scratch register on |
| 23503 |
function entry after the registers are saved in the prologue. This register |
| 23504 |
must be released by means of release_scratch_register_on_entry. IP is not |
| 23505 |
considered since it is always used as the 1st scratch register if available. |
| 23506 |
|
| 23507 |
REGNO1 is the index number of the 1st scratch register and LIVE_REGS is the |
| 23508 |
mask of live registers. */ |
| 23509 |
|
| 23510 |
static void |
| 23511 |
get_scratch_register_on_entry (struct scratch_reg *sr, unsigned int regno1, |
| 23512 |
unsigned long live_regs) |
| 23513 |
{ |
| 23514 |
int regno = -1; |
| 23515 |
|
| 23516 |
sr->saved = false; |
| 23517 |
|
| 23518 |
if (regno1 != LR_REGNUM && (live_regs & (1 << LR_REGNUM)) != 0) |
| 23519 |
regno = LR_REGNUM; |
| 23520 |
else |
| 23521 |
{ |
| 23522 |
unsigned int i; |
| 23523 |
|
| 23524 |
for (i = 4; i < 11; i++) |
| 23525 |
if (regno1 != i && (live_regs & (1 << i)) != 0) |
| 23526 |
{ |
| 23527 |
regno = i; |
| 23528 |
break; |
| 23529 |
} |
| 23530 |
|
| 23531 |
if (regno < 0) |
| 23532 |
{ |
| 23533 |
/* If IP is used as the 1st scratch register for a nested function, |
| 23534 |
then either r3 wasn't available or is used to preserve IP. */ |
| 23535 |
if (regno1 == IP_REGNUM && IS_NESTED (arm_current_func_type ())) |
| 23536 |
regno1 = 3; |
| 23537 |
regno = (regno1 == 3 ? 2 : 3); |
| 23538 |
sr->saved |
| 23539 |
= REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)), |
| 23540 |
regno); |
| 23541 |
} |
| 23542 |
} |
| 23543 |
|
| 23544 |
sr->reg = gen_rtx_REG (SImode, regno); |
| 23545 |
if (sr->saved) |
| 23546 |
{ |
| 23547 |
rtx addr = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx); |
| 23548 |
rtx insn = emit_set_insn (gen_frame_mem (SImode, addr), sr->reg); |
| 23549 |
rtx x = gen_rtx_SET (stack_pointer_rtx, |
| 23550 |
plus_constant (Pmode, stack_pointer_rtx, -4)); |
| 23551 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 23552 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, x); |
| 23553 |
} |
| 23554 |
} |
| 23555 |
|
| 23556 |
/* Release a scratch register obtained from the preceding function. */ |
| 23557 |
|
| 23558 |
static void |
| 23559 |
release_scratch_register_on_entry (struct scratch_reg *sr) |
| 23560 |
{ |
| 23561 |
if (sr->saved) |
| 23562 |
{ |
| 23563 |
rtx addr = gen_rtx_POST_INC (Pmode, stack_pointer_rtx); |
| 23564 |
rtx insn = emit_set_insn (sr->reg, gen_frame_mem (SImode, addr)); |
| 23565 |
rtx x = gen_rtx_SET (stack_pointer_rtx, |
| 23566 |
plus_constant (Pmode, stack_pointer_rtx, 4)); |
| 23567 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 23568 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, x); |
| 23569 |
} |
| 23570 |
} |
| 23571 |
|
| 23572 |
#define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP) |
| 23573 |
|
| 23574 |
#if PROBE_INTERVAL > 4096 |
| 23575 |
#error Cannot use indexed addressing mode for stack probing |
| 23576 |
#endif |
| 23577 |
|
| 23578 |
/* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE, |
| 23579 |
inclusive. These are offsets from the current stack pointer. REGNO1 |
| 23580 |
is the index number of the 1st scratch register and LIVE_REGS is the |
| 23581 |
mask of live registers. */ |
| 23582 |
|
| 23583 |
static void |
| 23584 |
arm_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size, |
| 23585 |
unsigned int regno1, unsigned long live_regs) |
| 23586 |
{ |
| 23587 |
rtx reg1 = gen_rtx_REG (Pmode, regno1); |
| 23588 |
|
| 23589 |
/* See if we have a constant small number of probes to generate. If so, |
| 23590 |
that's the easy case. */ |
| 23591 |
if (size <= PROBE_INTERVAL) |
| 23592 |
{ |
| 23593 |
emit_move_insn (reg1, GEN_INT (first + PROBE_INTERVAL)); |
| 23594 |
emit_set_insn (reg1, gen_rtx_MINUS (Pmode, stack_pointer_rtx, reg1)); |
| 23595 |
emit_stack_probe (plus_constant (Pmode, reg1, PROBE_INTERVAL - size)); |
| 23596 |
} |
| 23597 |
|
| 23598 |
/* The run-time loop is made up of 10 insns in the generic case while the |
| 23599 |
compile-time loop is made up of 4+2*(n-2) insns for n # of intervals. */ |
| 23600 |
else if (size <= 5 * PROBE_INTERVAL) |
| 23601 |
{ |
| 23602 |
HOST_WIDE_INT i, rem; |
| 23603 |
|
| 23604 |
emit_move_insn (reg1, GEN_INT (first + PROBE_INTERVAL)); |
| 23605 |
emit_set_insn (reg1, gen_rtx_MINUS (Pmode, stack_pointer_rtx, reg1)); |
| 23606 |
emit_stack_probe (reg1); |
| 23607 |
|
| 23608 |
/* Probe at FIRST + N * PROBE_INTERVAL for values of N from 2 until |
| 23609 |
it exceeds SIZE. If only two probes are needed, this will not |
| 23610 |
generate any code. Then probe at FIRST + SIZE. */ |
| 23611 |
for (i = 2 * PROBE_INTERVAL; i < size; i += PROBE_INTERVAL) |
| 23612 |
{ |
| 23613 |
emit_set_insn (reg1, plus_constant (Pmode, reg1, -PROBE_INTERVAL)); |
| 23614 |
emit_stack_probe (reg1); |
| 23615 |
} |
| 23616 |
|
| 23617 |
rem = size - (i - PROBE_INTERVAL); |
| 23618 |
if (rem > 4095 || (TARGET_THUMB2 && rem > 255)) |
| 23619 |
{ |
| 23620 |
emit_set_insn (reg1, plus_constant (Pmode, reg1, -PROBE_INTERVAL)); |
| 23621 |
emit_stack_probe (plus_constant (Pmode, reg1, PROBE_INTERVAL - rem)); |
| 23622 |
} |
| 23623 |
else |
| 23624 |
emit_stack_probe (plus_constant (Pmode, reg1, -rem)); |
| 23625 |
} |
| 23626 |
|
| 23627 |
/* Otherwise, do the same as above, but in a loop. Note that we must be |
| 23628 |
extra careful with variables wrapping around because we might be at |
| 23629 |
the very top (or the very bottom) of the address space and we have |
| 23630 |
to be able to handle this case properly; in particular, we use an |
| 23631 |
equality test for the loop condition. */ |
| 23632 |
else |
| 23633 |
{ |
| 23634 |
HOST_WIDE_INT rounded_size; |
| 23635 |
struct scratch_reg sr; |
| 23636 |
|
| 23637 |
get_scratch_register_on_entry (&sr, regno1, live_regs); |
| 23638 |
|
| 23639 |
emit_move_insn (reg1, GEN_INT (first)); |
| 23640 |
|
| 23641 |
|
| 23642 |
/* Step 1: round SIZE to the previous multiple of the interval. */ |
| 23643 |
|
| 23644 |
rounded_size = size & -PROBE_INTERVAL; |
| 23645 |
emit_move_insn (sr.reg, GEN_INT (rounded_size)); |
| 23646 |
|
| 23647 |
|
| 23648 |
/* Step 2: compute initial and final value of the loop counter. */ |
| 23649 |
|
| 23650 |
/* TEST_ADDR = SP + FIRST. */ |
| 23651 |
emit_set_insn (reg1, gen_rtx_MINUS (Pmode, stack_pointer_rtx, reg1)); |
| 23652 |
|
| 23653 |
/* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */ |
| 23654 |
emit_set_insn (sr.reg, gen_rtx_MINUS (Pmode, reg1, sr.reg)); |
| 23655 |
|
| 23656 |
|
| 23657 |
/* Step 3: the loop |
| 23658 |
|
| 23659 |
do |
| 23660 |
{ |
| 23661 |
TEST_ADDR = TEST_ADDR + PROBE_INTERVAL |
| 23662 |
probe at TEST_ADDR |
| 23663 |
} |
| 23664 |
while (TEST_ADDR != LAST_ADDR) |
| 23665 |
|
| 23666 |
probes at FIRST + N * PROBE_INTERVAL for values of N from 1 |
| 23667 |
until it is equal to ROUNDED_SIZE. */ |
| 23668 |
|
| 23669 |
emit_insn (gen_probe_stack_range (reg1, reg1, sr.reg)); |
| 23670 |
|
| 23671 |
|
| 23672 |
/* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time |
| 23673 |
that SIZE is equal to ROUNDED_SIZE. */ |
| 23674 |
|
| 23675 |
if (size != rounded_size) |
| 23676 |
{ |
| 23677 |
HOST_WIDE_INT rem = size - rounded_size; |
| 23678 |
|
| 23679 |
if (rem > 4095 || (TARGET_THUMB2 && rem > 255)) |
| 23680 |
{ |
| 23681 |
emit_set_insn (sr.reg, |
| 23682 |
plus_constant (Pmode, sr.reg, -PROBE_INTERVAL)); |
| 23683 |
emit_stack_probe (plus_constant (Pmode, sr.reg, |
| 23684 |
PROBE_INTERVAL - rem)); |
| 23685 |
} |
| 23686 |
else |
| 23687 |
emit_stack_probe (plus_constant (Pmode, sr.reg, -rem)); |
| 23688 |
} |
| 23689 |
|
| 23690 |
release_scratch_register_on_entry (&sr); |
| 23691 |
} |
| 23692 |
|
| 23693 |
/* Make sure nothing is scheduled before we are done. */ |
| 23694 |
emit_insn (gen_blockage ()); |
| 23695 |
} |
| 23696 |
|
| 23697 |
/* Probe a range of stack addresses from REG1 to REG2 inclusive. These are |
| 23698 |
absolute addresses. */ |
| 23699 |
|
| 23700 |
const char * |
| 23701 |
output_probe_stack_range (rtx reg1, rtx reg2) |
| 23702 |
{ |
| 23703 |
static int labelno = 0; |
| 23704 |
char loop_lab[32]; |
| 23705 |
rtx xops[2]; |
| 23706 |
|
| 23707 |
ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++); |
| 23708 |
|
| 23709 |
/* Loop. */ |
| 23710 |
ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab); |
| 23711 |
|
| 23712 |
/* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */ |
| 23713 |
xops[0] = reg1; |
| 23714 |
xops[1] = GEN_INT (PROBE_INTERVAL); |
| 23715 |
output_asm_insn ("sub\t%0, %0, %1", xops); |
| 23716 |
|
| 23717 |
/* Probe at TEST_ADDR. */ |
| 23718 |
output_asm_insn ("str\tr0, [%0, #0]", xops); |
| 23719 |
|
| 23720 |
/* Test if TEST_ADDR == LAST_ADDR. */ |
| 23721 |
xops[1] = reg2; |
| 23722 |
output_asm_insn ("cmp\t%0, %1", xops); |
| 23723 |
|
| 23724 |
/* Branch. */ |
| 23725 |
fputs ("\tbne\t", asm_out_file); |
| 23726 |
assemble_name_raw (asm_out_file, loop_lab); |
| 23727 |
fputc ('\n', asm_out_file); |
| 23728 |
|
| 23729 |
return ""; |
| 23730 |
} |
| 23731 |
|
| 23732 |
/* Generate the prologue instructions for entry into an ARM or Thumb-2 |
| 23733 |
function. */ |
| 23734 |
void |
| 23735 |
arm_expand_prologue (void) |
| 23736 |
{ |
| 23737 |
rtx amount; |
| 23738 |
rtx insn; |
| 23739 |
rtx ip_rtx; |
| 23740 |
unsigned long live_regs_mask; |
| 23741 |
unsigned long func_type; |
| 23742 |
int fp_offset = 0; |
| 23743 |
int saved_pretend_args = 0; |
| 23744 |
int saved_regs = 0; |
| 23745 |
unsigned HOST_WIDE_INT args_to_push; |
| 23746 |
HOST_WIDE_INT size; |
| 23747 |
arm_stack_offsets *offsets; |
| 23748 |
bool clobber_ip; |
| 23749 |
|
| 23750 |
func_type = arm_current_func_type (); |
| 23751 |
|
| 23752 |
/* Naked functions don't have prologues. */ |
| 23753 |
if (IS_NAKED (func_type)) |
| 23754 |
{ |
| 23755 |
if (flag_stack_usage_info) |
| 23756 |
current_function_static_stack_size = 0; |
| 23757 |
return; |
| 23758 |
} |
| 23759 |
|
| 23760 |
/* Make a copy of c_f_p_a_s as we may need to modify it locally. */ |
| 23761 |
args_to_push = crtl->args.pretend_args_size; |
| 23762 |
|
| 23763 |
/* Compute which register we will have to save onto the stack. */ |
| 23764 |
offsets = arm_get_frame_offsets (); |
| 23765 |
live_regs_mask = offsets->saved_regs_mask; |
| 23766 |
|
| 23767 |
ip_rtx = gen_rtx_REG (SImode, IP_REGNUM); |
| 23768 |
|
| 23769 |
/* The AAPCS requires the callee to widen integral types narrower |
| 23770 |
than 32 bits to the full width of the register; but when handling |
| 23771 |
calls to non-secure space, we cannot trust the callee to have |
| 23772 |
correctly done so. So forcibly re-widen the result here. */ |
| 23773 |
if (IS_CMSE_ENTRY (func_type)) |
| 23774 |
{ |
| 23775 |
function_args_iterator args_iter; |
| 23776 |
CUMULATIVE_ARGS args_so_far_v; |
| 23777 |
cumulative_args_t args_so_far; |
| 23778 |
bool first_param = true; |
| 23779 |
tree arg_type; |
| 23780 |
tree fndecl = current_function_decl; |
| 23781 |
tree fntype = TREE_TYPE (fndecl); |
| 23782 |
arm_init_cumulative_args (&args_so_far_v, fntype, NULL_RTX, fndecl); |
| 23783 |
args_so_far = pack_cumulative_args (&args_so_far_v); |
| 23784 |
FOREACH_FUNCTION_ARGS (fntype, arg_type, args_iter) |
| 23785 |
{ |
| 23786 |
rtx arg_rtx; |
| 23787 |
|
| 23788 |
if (VOID_TYPE_P (arg_type)) |
| 23789 |
break; |
| 23790 |
|
| 23791 |
function_arg_info arg (arg_type, /*named=*/true); |
| 23792 |
if (!first_param) |
| 23793 |
/* We should advance after processing the argument and pass |
| 23794 |
the argument we're advancing past. */ |
| 23795 |
arm_function_arg_advance (args_so_far, arg); |
| 23796 |
first_param = false; |
| 23797 |
arg_rtx = arm_function_arg (args_so_far, arg); |
| 23798 |
gcc_assert (REG_P (arg_rtx)); |
| 23799 |
if ((TREE_CODE (arg_type) == INTEGER_TYPE |
| 23800 |
|| TREE_CODE (arg_type) == ENUMERAL_TYPE |
| 23801 |
|| TREE_CODE (arg_type) == BOOLEAN_TYPE) |
| 23802 |
&& known_lt (GET_MODE_SIZE (GET_MODE (arg_rtx)), 4)) |
| 23803 |
{ |
| 23804 |
if (TYPE_UNSIGNED (arg_type)) |
| 23805 |
emit_set_insn (gen_rtx_REG (SImode, REGNO (arg_rtx)), |
| 23806 |
gen_rtx_ZERO_EXTEND (SImode, arg_rtx)); |
| 23807 |
else |
| 23808 |
emit_set_insn (gen_rtx_REG (SImode, REGNO (arg_rtx)), |
| 23809 |
gen_rtx_SIGN_EXTEND (SImode, arg_rtx)); |
| 23810 |
} |
| 23811 |
} |
| 23812 |
} |
| 23813 |
|
| 23814 |
if (IS_STACKALIGN (func_type)) |
| 23815 |
{ |
| 23816 |
rtx r0, r1; |
| 23817 |
|
| 23818 |
/* Handle a word-aligned stack pointer. We generate the following: |
| 23819 |
|
| 23820 |
mov r0, sp |
| 23821 |
bic r1, r0, #7 |
| 23822 |
mov sp, r1 |
| 23823 |
<save and restore r0 in normal prologue/epilogue> |
| 23824 |
mov sp, r0 |
| 23825 |
bx lr |
| 23826 |
|
| 23827 |
The unwinder doesn't need to know about the stack realignment. |
| 23828 |
Just tell it we saved SP in r0. */ |
| 23829 |
gcc_assert (TARGET_THUMB2 && !arm_arch_notm && args_to_push == 0); |
| 23830 |
|
| 23831 |
r0 = gen_rtx_REG (SImode, R0_REGNUM); |
| 23832 |
r1 = gen_rtx_REG (SImode, R1_REGNUM); |
| 23833 |
|
| 23834 |
insn = emit_insn (gen_movsi (r0, stack_pointer_rtx)); |
| 23835 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 23836 |
add_reg_note (insn, REG_CFA_REGISTER, NULL); |
| 23837 |
|
| 23838 |
emit_insn (gen_andsi3 (r1, r0, GEN_INT (~(HOST_WIDE_INT)7))); |
| 23839 |
|
| 23840 |
/* ??? The CFA changes here, which may cause GDB to conclude that it |
| 23841 |
has entered a different function. That said, the unwind info is |
| 23842 |
correct, individually, before and after this instruction because |
| 23843 |
we've described the save of SP, which will override the default |
| 23844 |
handling of SP as restoring from the CFA. */ |
| 23845 |
emit_insn (gen_movsi (stack_pointer_rtx, r1)); |
| 23846 |
} |
| 23847 |
|
| 23848 |
/* Let's compute the static_chain_stack_bytes required and store it. Right |
| 23849 |
now the value must be -1 as stored by arm_init_machine_status (). */ |
| 23850 |
cfun->machine->static_chain_stack_bytes |
| 23851 |
= arm_compute_static_chain_stack_bytes (); |
| 23852 |
|
| 23853 |
/* The static chain register is the same as the IP register. If it is |
| 23854 |
clobbered when creating the frame, we need to save and restore it. */ |
| 23855 |
clobber_ip = (IS_NESTED (func_type) |
| 23856 |
&& (((TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM) |
| 23857 |
|| ((flag_stack_check == STATIC_BUILTIN_STACK_CHECK |
| 23858 |
|| flag_stack_clash_protection) |
| 23859 |
&& !df_regs_ever_live_p (LR_REGNUM) |
| 23860 |
&& arm_r3_live_at_start_p ())) |
| 23861 |
|| arm_current_function_pac_enabled_p ())); |
| 23862 |
|
| 23863 |
/* Find somewhere to store IP whilst the frame is being created. |
| 23864 |
We try the following places in order: |
| 23865 |
|
| 23866 |
1. The last argument register r3 if it is available. |
| 23867 |
2. A slot on the stack above the frame if there are no |
| 23868 |
arguments to push onto the stack. |
| 23869 |
3. Register r3 again, after pushing the argument registers |
| 23870 |
onto the stack, if this is a varargs function. |
| 23871 |
4. The last slot on the stack created for the arguments to |
| 23872 |
push, if this isn't a varargs function. |
| 23873 |
|
| 23874 |
Note - we only need to tell the dwarf2 backend about the SP |
| 23875 |
adjustment in the second variant; the static chain register |
| 23876 |
doesn't need to be unwound, as it doesn't contain a value |
| 23877 |
inherited from the caller. */ |
| 23878 |
if (clobber_ip) |
| 23879 |
{ |
| 23880 |
if (!arm_r3_live_at_start_p ()) |
| 23881 |
insn = emit_set_insn (gen_rtx_REG (SImode, 3), ip_rtx); |
| 23882 |
else if (args_to_push == 0) |
| 23883 |
{ |
| 23884 |
rtx addr, dwarf; |
| 23885 |
|
| 23886 |
saved_regs += 4; |
| 23887 |
|
| 23888 |
addr = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx); |
| 23889 |
insn = emit_set_insn (gen_frame_mem (SImode, addr), ip_rtx); |
| 23890 |
fp_offset = 4; |
| 23891 |
|
| 23892 |
/* Just tell the dwarf backend that we adjusted SP. */ |
| 23893 |
dwarf = gen_rtx_SET (stack_pointer_rtx, |
| 23894 |
plus_constant (Pmode, stack_pointer_rtx, |
| 23895 |
-fp_offset)); |
| 23896 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 23897 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
| 23898 |
if (arm_current_function_pac_enabled_p ()) |
| 23899 |
cfun->machine->pacspval_needed = 1; |
| 23900 |
} |
| 23901 |
else |
| 23902 |
{ |
| 23903 |
/* Store the args on the stack. */ |
| 23904 |
if (cfun->machine->uses_anonymous_args) |
| 23905 |
{ |
| 23906 |
insn = emit_multi_reg_push ((0xf0 >> (args_to_push / 4)) & 0xf, |
| 23907 |
(0xf0 >> (args_to_push / 4)) & 0xf); |
| 23908 |
emit_set_insn (gen_rtx_REG (SImode, 3), ip_rtx); |
| 23909 |
saved_pretend_args = 1; |
| 23910 |
} |
| 23911 |
else |
| 23912 |
{ |
| 23913 |
rtx addr, dwarf; |
| 23914 |
|
| 23915 |
if (args_to_push == 4) |
| 23916 |
addr = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx); |
| 23917 |
else |
| 23918 |
addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, |
| 23919 |
plus_constant (Pmode, |
| 23920 |
stack_pointer_rtx, |
| 23921 |
-args_to_push)); |
| 23922 |
|
| 23923 |
insn = emit_set_insn (gen_frame_mem (SImode, addr), ip_rtx); |
| 23924 |
|
| 23925 |
/* Just tell the dwarf backend that we adjusted SP. */ |
| 23926 |
dwarf = gen_rtx_SET (stack_pointer_rtx, |
| 23927 |
plus_constant (Pmode, stack_pointer_rtx, |
| 23928 |
-args_to_push)); |
| 23929 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
| 23930 |
} |
| 23931 |
|
| 23932 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 23933 |
fp_offset = args_to_push; |
| 23934 |
args_to_push = 0; |
| 23935 |
if (arm_current_function_pac_enabled_p ()) |
| 23936 |
cfun->machine->pacspval_needed = 1; |
| 23937 |
} |
| 23938 |
} |
| 23939 |
|
| 23940 |
if (arm_current_function_pac_enabled_p ()) |
| 23941 |
{ |
| 23942 |
/* If IP was clobbered we only emit a PAC instruction as the BTI |
| 23943 |
one will be added before the push of the clobbered IP (if |
| 23944 |
necessary) by the bti pass. */ |
| 23945 |
if (aarch_bti_enabled () && !clobber_ip) |
| 23946 |
insn = emit_insn (gen_pacbti_nop ()); |
| 23947 |
else |
| 23948 |
insn = emit_insn (gen_pac_nop ()); |
| 23949 |
|
| 23950 |
rtx dwarf = gen_rtx_SET (ip_rtx, gen_rtx_REG (SImode, RA_AUTH_CODE)); |
| 23951 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 23952 |
add_reg_note (insn, REG_CFA_REGISTER, dwarf); |
| 23953 |
} |
| 23954 |
|
| 23955 |
if (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM) |
| 23956 |
{ |
| 23957 |
if (IS_INTERRUPT (func_type)) |
| 23958 |
{ |
| 23959 |
/* Interrupt functions must not corrupt any registers. |
| 23960 |
Creating a frame pointer however, corrupts the IP |
| 23961 |
register, so we must push it first. */ |
| 23962 |
emit_multi_reg_push (1 << IP_REGNUM, 1 << IP_REGNUM); |
| 23963 |
|
| 23964 |
/* Do not set RTX_FRAME_RELATED_P on this insn. |
| 23965 |
The dwarf stack unwinding code only wants to see one |
| 23966 |
stack decrement per function, and this is not it. If |
| 23967 |
this instruction is labeled as being part of the frame |
| 23968 |
creation sequence then dwarf2out_frame_debug_expr will |
| 23969 |
die when it encounters the assignment of IP to FP |
| 23970 |
later on, since the use of SP here establishes SP as |
| 23971 |
the CFA register and not IP. |
| 23972 |
|
| 23973 |
Anyway this instruction is not really part of the stack |
| 23974 |
frame creation although it is part of the prologue. */ |
| 23975 |
} |
| 23976 |
|
| 23977 |
insn = emit_set_insn (ip_rtx, |
| 23978 |
plus_constant (Pmode, stack_pointer_rtx, |
| 23979 |
fp_offset)); |
| 23980 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 23981 |
} |
| 23982 |
|
| 23983 |
/* Armv8.1-M Mainline nonsecure entry: save FPCXTNS on stack using VSTR. */ |
| 23984 |
if (TARGET_HAVE_FPCXT_CMSE && IS_CMSE_ENTRY (func_type)) |
| 23985 |
{ |
| 23986 |
saved_regs += 4; |
| 23987 |
insn = emit_insn (gen_push_fpsysreg_insn (stack_pointer_rtx, |
| 23988 |
GEN_INT (FPCXTNS_ENUM))); |
| 23989 |
rtx dwarf = gen_rtx_SET (stack_pointer_rtx, |
| 23990 |
plus_constant (Pmode, stack_pointer_rtx, -4)); |
| 23991 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
| 23992 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 23993 |
} |
| 23994 |
|
| 23995 |
if (args_to_push) |
| 23996 |
{ |
| 23997 |
/* Push the argument registers, or reserve space for them. */ |
| 23998 |
if (cfun->machine->uses_anonymous_args) |
| 23999 |
insn = emit_multi_reg_push |
| 24000 |
((0xf0 >> (args_to_push / 4)) & 0xf, |
| 24001 |
(0xf0 >> (args_to_push / 4)) & 0xf); |
| 24002 |
else |
| 24003 |
insn = emit_insn |
| 24004 |
(gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
| 24005 |
GEN_INT (- args_to_push))); |
| 24006 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 24007 |
} |
| 24008 |
|
| 24009 |
/* If this is an interrupt service routine, and the link register |
| 24010 |
is going to be pushed, and we're not generating extra |
| 24011 |
push of IP (needed when frame is needed and frame layout if apcs), |
| 24012 |
subtracting four from LR now will mean that the function return |
| 24013 |
can be done with a single instruction. */ |
| 24014 |
if ((func_type == ARM_FT_ISR || func_type == ARM_FT_FIQ) |
| 24015 |
&& (live_regs_mask & (1 << LR_REGNUM)) != 0 |
| 24016 |
&& !(frame_pointer_needed && TARGET_APCS_FRAME) |
| 24017 |
&& TARGET_ARM) |
| 24018 |
{ |
| 24019 |
rtx lr = gen_rtx_REG (SImode, LR_REGNUM); |
| 24020 |
|
| 24021 |
emit_set_insn (lr, plus_constant (SImode, lr, -4)); |
| 24022 |
} |
| 24023 |
|
| 24024 |
if (live_regs_mask) |
| 24025 |
{ |
| 24026 |
unsigned long dwarf_regs_mask = live_regs_mask; |
| 24027 |
|
| 24028 |
saved_regs += bit_count (live_regs_mask) * 4; |
| 24029 |
if (optimize_size && !frame_pointer_needed |
| 24030 |
&& saved_regs == offsets->saved_regs - offsets->saved_args) |
| 24031 |
{ |
| 24032 |
/* If no coprocessor registers are being pushed and we don't have |
| 24033 |
to worry about a frame pointer then push extra registers to |
| 24034 |
create the stack frame. This is done in a way that does not |
| 24035 |
alter the frame layout, so is independent of the epilogue. */ |
| 24036 |
int n; |
| 24037 |
int frame; |
| 24038 |
n = 0; |
| 24039 |
while (n < 8 && (live_regs_mask & (1 << n)) == 0) |
| 24040 |
n++; |
| 24041 |
frame = offsets->outgoing_args - (offsets->saved_args + saved_regs); |
| 24042 |
if (frame && n * 4 >= frame) |
| 24043 |
{ |
| 24044 |
n = frame / 4; |
| 24045 |
live_regs_mask |= (1 << n) - 1; |
| 24046 |
saved_regs += frame; |
| 24047 |
} |
| 24048 |
} |
| 24049 |
|
| 24050 |
if (TARGET_LDRD |
| 24051 |
&& current_tune->prefer_ldrd_strd |
| 24052 |
&& !optimize_function_for_size_p (cfun)) |
| 24053 |
{ |
| 24054 |
gcc_checking_assert (live_regs_mask == dwarf_regs_mask); |
| 24055 |
if (TARGET_THUMB2) |
| 24056 |
thumb2_emit_strd_push (live_regs_mask); |
| 24057 |
else if (TARGET_ARM |
| 24058 |
&& !TARGET_APCS_FRAME |
| 24059 |
&& !IS_INTERRUPT (func_type)) |
| 24060 |
arm_emit_strd_push (live_regs_mask); |
| 24061 |
else |
| 24062 |
{ |
| 24063 |
insn = emit_multi_reg_push (live_regs_mask, live_regs_mask); |
| 24064 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 24065 |
} |
| 24066 |
} |
| 24067 |
else |
| 24068 |
{ |
| 24069 |
insn = emit_multi_reg_push (live_regs_mask, dwarf_regs_mask); |
| 24070 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 24071 |
} |
| 24072 |
} |
| 24073 |
|
| 24074 |
if (! IS_VOLATILE (func_type)) |
| 24075 |
saved_regs += arm_save_coproc_regs (); |
| 24076 |
|
| 24077 |
if (frame_pointer_needed && TARGET_ARM) |
| 24078 |
{ |
| 24079 |
/* Create the new frame pointer. */ |
| 24080 |
if (TARGET_APCS_FRAME) |
| 24081 |
{ |
| 24082 |
insn = GEN_INT (-(4 + args_to_push + fp_offset)); |
| 24083 |
insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, ip_rtx, insn)); |
| 24084 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 24085 |
} |
| 24086 |
else |
| 24087 |
{ |
| 24088 |
insn = GEN_INT (saved_regs - (4 + fp_offset)); |
| 24089 |
insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, |
| 24090 |
stack_pointer_rtx, insn)); |
| 24091 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 24092 |
} |
| 24093 |
} |
| 24094 |
|
| 24095 |
size = offsets->outgoing_args - offsets->saved_args; |
| 24096 |
if (flag_stack_usage_info) |
| 24097 |
current_function_static_stack_size = size; |
| 24098 |
|
| 24099 |
/* If this isn't an interrupt service routine and we have a frame, then do |
| 24100 |
stack checking. We use IP as the first scratch register, except for the |
| 24101 |
non-APCS nested functions if LR or r3 are available (see clobber_ip). */ |
| 24102 |
if (!IS_INTERRUPT (func_type) |
| 24103 |
&& (flag_stack_check == STATIC_BUILTIN_STACK_CHECK |
| 24104 |
|| flag_stack_clash_protection)) |
| 24105 |
{ |
| 24106 |
unsigned int regno; |
| 24107 |
|
| 24108 |
if (!IS_NESTED (func_type) || clobber_ip) |
| 24109 |
regno = IP_REGNUM; |
| 24110 |
else if (df_regs_ever_live_p (LR_REGNUM)) |
| 24111 |
regno = LR_REGNUM; |
| 24112 |
else |
| 24113 |
regno = 3; |
| 24114 |
|
| 24115 |
if (crtl->is_leaf && !cfun->calls_alloca) |
| 24116 |
{ |
| 24117 |
if (size > PROBE_INTERVAL && size > get_stack_check_protect ()) |
| 24118 |
arm_emit_probe_stack_range (get_stack_check_protect (), |
| 24119 |
size - get_stack_check_protect (), |
| 24120 |
regno, live_regs_mask); |
| 24121 |
} |
| 24122 |
else if (size > 0) |
| 24123 |
arm_emit_probe_stack_range (get_stack_check_protect (), size, |
| 24124 |
regno, live_regs_mask); |
| 24125 |
} |
| 24126 |
|
| 24127 |
/* Recover the static chain register. */ |
| 24128 |
if (clobber_ip) |
| 24129 |
{ |
| 24130 |
if (!arm_r3_live_at_start_p () || saved_pretend_args) |
| 24131 |
insn = gen_rtx_REG (SImode, 3); |
| 24132 |
else |
| 24133 |
{ |
| 24134 |
insn = plus_constant (Pmode, hard_frame_pointer_rtx, 4); |
| 24135 |
insn = gen_frame_mem (SImode, insn); |
| 24136 |
} |
| 24137 |
emit_set_insn (ip_rtx, insn); |
| 24138 |
emit_insn (gen_force_register_use (ip_rtx)); |
| 24139 |
} |
| 24140 |
|
| 24141 |
if (offsets->outgoing_args != offsets->saved_args + saved_regs) |
| 24142 |
{ |
| 24143 |
/* This add can produce multiple insns for a large constant, so we |
| 24144 |
need to get tricky. */ |
| 24145 |
rtx_insn *last = get_last_insn (); |
| 24146 |
|
| 24147 |
amount = GEN_INT (offsets->saved_args + saved_regs |
| 24148 |
- offsets->outgoing_args); |
| 24149 |
|
| 24150 |
insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
| 24151 |
amount)); |
| 24152 |
do |
| 24153 |
{ |
| 24154 |
last = last ? NEXT_INSN (last) : get_insns (); |
| 24155 |
RTX_FRAME_RELATED_P (last) = 1; |
| 24156 |
} |
| 24157 |
while (last != insn); |
| 24158 |
|
| 24159 |
/* If the frame pointer is needed, emit a special barrier that |
| 24160 |
will prevent the scheduler from moving stores to the frame |
| 24161 |
before the stack adjustment. */ |
| 24162 |
if (frame_pointer_needed) |
| 24163 |
emit_insn (gen_stack_tie (stack_pointer_rtx, |
| 24164 |
hard_frame_pointer_rtx)); |
| 24165 |
} |
| 24166 |
|
| 24167 |
|
| 24168 |
if (frame_pointer_needed && TARGET_THUMB2) |
| 24169 |
thumb_set_frame_pointer (offsets); |
| 24170 |
|
| 24171 |
if (flag_pic && arm_pic_register != INVALID_REGNUM) |
| 24172 |
{ |
| 24173 |
unsigned long mask; |
| 24174 |
|
| 24175 |
mask = live_regs_mask; |
| 24176 |
mask &= THUMB2_WORK_REGS; |
| 24177 |
if (!IS_NESTED (func_type)) |
| 24178 |
mask |= (1 << IP_REGNUM); |
| 24179 |
arm_load_pic_register (mask, NULL_RTX); |
| 24180 |
} |
| 24181 |
|
| 24182 |
/* If we are profiling, make sure no instructions are scheduled before |
| 24183 |
the call to mcount. Similarly if the user has requested no |
| 24184 |
scheduling in the prolog. Similarly if we want non-call exceptions |
| 24185 |
using the EABI unwinder, to prevent faulting instructions from being |
| 24186 |
swapped with a stack adjustment. */ |
| 24187 |
if (crtl->profile || !TARGET_SCHED_PROLOG |
| 24188 |
|| (arm_except_unwind_info (&global_options) == UI_TARGET |
| 24189 |
&& cfun->can_throw_non_call_exceptions)) |
| 24190 |
emit_insn (gen_blockage ()); |
| 24191 |
|
| 24192 |
/* If the link register is being kept alive, with the return address in it, |
| 24193 |
then make sure that it does not get reused by the ce2 pass. */ |
| 24194 |
if ((live_regs_mask & (1 << LR_REGNUM)) == 0) |
| 24195 |
cfun->machine->lr_save_eliminated = 1; |
| 24196 |
} |
| 24197 |
|
| 24198 |
/* Print condition code to STREAM. Helper function for arm_print_operand. */ |
| 24199 |
static void |
| 24200 |
arm_print_condition (FILE *stream) |
| 24201 |
{ |
| 24202 |
if (arm_ccfsm_state == 3 || arm_ccfsm_state == 4) |
| 24203 |
{ |
| 24204 |
/* Branch conversion is not implemented for Thumb-2. */ |
| 24205 |
if (TARGET_THUMB) |
| 24206 |
{ |
| 24207 |
output_operand_lossage ("predicated Thumb instruction"); |
| 24208 |
return; |
| 24209 |
} |
| 24210 |
if (current_insn_predicate != NULL) |
| 24211 |
{ |
| 24212 |
output_operand_lossage |
| 24213 |
("predicated instruction in conditional sequence"); |
| 24214 |
return; |
| 24215 |
} |
| 24216 |
|
| 24217 |
fputs (arm_condition_codes[arm_current_cc], stream); |
| 24218 |
} |
| 24219 |
else if (current_insn_predicate) |
| 24220 |
{ |
| 24221 |
enum arm_cond_code code; |
| 24222 |
|
| 24223 |
if (TARGET_THUMB1) |
| 24224 |
{ |
| 24225 |
output_operand_lossage ("predicated Thumb instruction"); |
| 24226 |
return; |
| 24227 |
} |
| 24228 |
|
| 24229 |
code = get_arm_condition_code (current_insn_predicate); |
| 24230 |
fputs (arm_condition_codes[code], stream); |
| 24231 |
} |
| 24232 |
} |
| 24233 |
|
| 24234 |
|
| 24235 |
/* Globally reserved letters: acln |
| 24236 |
Puncutation letters currently used: @_-|?().!# |
| 24237 |
Lower case letters currently used: bcdefhimpqtvwxyz |
| 24238 |
Upper case letters currently used: ABCDEFGHIJKLMOPQRSTUV |
| 24239 |
Letters previously used, but now deprecated/obsolete: sNWXYZ. |
| 24240 |
|
| 24241 |
Note that the global reservation for 'c' is only for CONSTANT_ADDRESS_P. |
| 24242 |
|
| 24243 |
If CODE is 'd', then the X is a condition operand and the instruction |
| 24244 |
should only be executed if the condition is true. |
| 24245 |
if CODE is 'D', then the X is a condition operand and the instruction |
| 24246 |
should only be executed if the condition is false: however, if the mode |
| 24247 |
of the comparison is CCFPEmode, then always execute the instruction -- we |
| 24248 |
do this because in these circumstances !GE does not necessarily imply LT; |
| 24249 |
in these cases the instruction pattern will take care to make sure that |
| 24250 |
an instruction containing %d will follow, thereby undoing the effects of |
| 24251 |
doing this instruction unconditionally. |
| 24252 |
If CODE is 'B' then output a bitwise inverted value of X (a const int). |
| 24253 |
If X is a REG and CODE is `M', output a ldm/stm style multi-reg. |
| 24254 |
If CODE is 'V', then the operand must be a CONST_INT representing |
| 24255 |
the bits to preserve in the modified register (Rd) of a BFI or BFC |
| 24256 |
instruction: print out both the width and lsb (shift) fields. */ |
| 24257 |
static void |
| 24258 |
arm_print_operand (FILE *stream, rtx x, int code) |
| 24259 |
{ |
| 24260 |
switch (code) |
| 24261 |
{ |
| 24262 |
case '@': |
| 24263 |
fputs (ASM_COMMENT_START, stream); |
| 24264 |
return; |
| 24265 |
|
| 24266 |
case '_': |
| 24267 |
fputs (user_label_prefix, stream); |
| 24268 |
return; |
| 24269 |
case '-': |
| 24270 |
#ifdef LOCAL_LABEL_PREFIX |
| 24271 |
fputs (LOCAL_LABEL_PREFIX, stream); |
| 24272 |
#endif |
| 24273 |
return; |
| 24274 |
|
| 24275 |
case '|': |
| 24276 |
fputs (REGISTER_PREFIX, stream); |
| 24277 |
return; |
| 24278 |
|
| 24279 |
case '?': |
| 24280 |
arm_print_condition (stream); |
| 24281 |
return; |
| 24282 |
|
| 24283 |
case '.': |
| 24284 |
/* The current condition code for a condition code setting instruction. |
| 24285 |
Preceded by 's' in unified syntax, otherwise followed by 's'. */ |
| 24286 |
fputc('s', stream); |
| 24287 |
arm_print_condition (stream); |
| 24288 |
return; |
| 24289 |
|
| 24290 |
case '!': |
| 24291 |
/* If the instruction is conditionally executed then print |
| 24292 |
the current condition code, otherwise print 's'. */ |
| 24293 |
gcc_assert (TARGET_THUMB2); |
| 24294 |
if (current_insn_predicate) |
| 24295 |
arm_print_condition (stream); |
| 24296 |
else |
| 24297 |
fputc('s', stream); |
| 24298 |
break; |
| 24299 |
|
| 24300 |
/* %# is a "break" sequence. It doesn't output anything, but is used to |
| 24301 |
separate e.g. operand numbers from following text, if that text consists |
| 24302 |
of further digits which we don't want to be part of the operand |
| 24303 |
number. */ |
| 24304 |
case '#': |
| 24305 |
return; |
| 24306 |
|
| 24307 |
/* An integer or symbol address without a preceding # sign. */ |
| 24308 |
case 'c': |
| 24309 |
switch (GET_CODE (x)) |
| 24310 |
{ |
| 24311 |
case CONST_INT: |
| 24312 |
fprintf (stream, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); |
| 24313 |
break; |
| 24314 |
|
| 24315 |
case SYMBOL_REF: |
| 24316 |
output_addr_const (stream, x); |
| 24317 |
break; |
| 24318 |
|
| 24319 |
case CONST: |
| 24320 |
if (GET_CODE (XEXP (x, 0)) == PLUS |
| 24321 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF) |
| 24322 |
{ |
| 24323 |
output_addr_const (stream, x); |
| 24324 |
break; |
| 24325 |
} |
| 24326 |
/* Fall through. */ |
| 24327 |
|
| 24328 |
default: |
| 24329 |
output_operand_lossage ("Unsupported operand for code '%c'", code); |
| 24330 |
} |
| 24331 |
return; |
| 24332 |
|
| 24333 |
/* An integer that we want to print in HEX. */ |
| 24334 |
case 'x': |
| 24335 |
switch (GET_CODE (x)) |
| 24336 |
{ |
| 24337 |
case CONST_INT: |
| 24338 |
fprintf (stream, "#" HOST_WIDE_INT_PRINT_HEX, INTVAL (x)); |
| 24339 |
break; |
| 24340 |
|
| 24341 |
default: |
| 24342 |
output_operand_lossage ("Unsupported operand for code '%c'", code); |
| 24343 |
} |
| 24344 |
return; |
| 24345 |
|
| 24346 |
case 'B': |
| 24347 |
if (CONST_INT_P (x)) |
| 24348 |
{ |
| 24349 |
HOST_WIDE_INT val; |
| 24350 |
val = ARM_SIGN_EXTEND (~INTVAL (x)); |
| 24351 |
fprintf (stream, HOST_WIDE_INT_PRINT_DEC, val); |
| 24352 |
} |
| 24353 |
else |
| 24354 |
{ |
| 24355 |
putc ('~', stream); |
| 24356 |
output_addr_const (stream, x); |
| 24357 |
} |
| 24358 |
return; |
| 24359 |
|
| 24360 |
case 'b': |
| 24361 |
/* Print the log2 of a CONST_INT. */ |
| 24362 |
{ |
| 24363 |
HOST_WIDE_INT val; |
| 24364 |
|
| 24365 |
if (!CONST_INT_P (x) |
| 24366 |
|| (val = exact_log2 (INTVAL (x) & 0xffffffff)) < 0) |
| 24367 |
output_operand_lossage ("Unsupported operand for code '%c'", code); |
| 24368 |
else |
| 24369 |
fprintf (stream, "#" HOST_WIDE_INT_PRINT_DEC, val); |
| 24370 |
} |
| 24371 |
return; |
| 24372 |
|
| 24373 |
case 'L': |
| 24374 |
/* The low 16 bits of an immediate constant. */ |
| 24375 |
fprintf (stream, HOST_WIDE_INT_PRINT_DEC, INTVAL(x) & 0xffff); |
| 24376 |
return; |
| 24377 |
|
| 24378 |
case 'i': |
| 24379 |
fprintf (stream, "%s", arithmetic_instr (x, 1)); |
| 24380 |
return; |
| 24381 |
|
| 24382 |
case 'I': |
| 24383 |
fprintf (stream, "%s", arithmetic_instr (x, 0)); |
| 24384 |
return; |
| 24385 |
|
| 24386 |
case 'S': |
| 24387 |
{ |
| 24388 |
HOST_WIDE_INT val; |
| 24389 |
const char *shift; |
| 24390 |
|
| 24391 |
shift = shift_op (x, &val); |
| 24392 |
|
| 24393 |
if (shift) |
| 24394 |
{ |
| 24395 |
fprintf (stream, ", %s ", shift); |
| 24396 |
if (val == -1) |
| 24397 |
arm_print_operand (stream, XEXP (x, 1), 0); |
| 24398 |
else |
| 24399 |
fprintf (stream, "#" HOST_WIDE_INT_PRINT_DEC, val); |
| 24400 |
} |
| 24401 |
} |
| 24402 |
return; |
| 24403 |
|
| 24404 |
/* An explanation of the 'Q', 'R' and 'H' register operands: |
| 24405 |
|
| 24406 |
In a pair of registers containing a DI or DF value the 'Q' |
| 24407 |
operand returns the register number of the register containing |
| 24408 |
the least significant part of the value. The 'R' operand returns |
| 24409 |
the register number of the register containing the most |
| 24410 |
significant part of the value. |
| 24411 |
|
| 24412 |
The 'H' operand returns the higher of the two register numbers. |
| 24413 |
On a run where WORDS_BIG_ENDIAN is true the 'H' operand is the |
| 24414 |
same as the 'Q' operand, since the most significant part of the |
| 24415 |
value is held in the lower number register. The reverse is true |
| 24416 |
on systems where WORDS_BIG_ENDIAN is false. |
| 24417 |
|
| 24418 |
The purpose of these operands is to distinguish between cases |
| 24419 |
where the endian-ness of the values is important (for example |
| 24420 |
when they are added together), and cases where the endian-ness |
| 24421 |
is irrelevant, but the order of register operations is important. |
| 24422 |
For example when loading a value from memory into a register |
| 24423 |
pair, the endian-ness does not matter. Provided that the value |
| 24424 |
from the lower memory address is put into the lower numbered |
| 24425 |
register, and the value from the higher address is put into the |
| 24426 |
higher numbered register, the load will work regardless of whether |
| 24427 |
the value being loaded is big-wordian or little-wordian. The |
| 24428 |
order of the two register loads can matter however, if the address |
| 24429 |
of the memory location is actually held in one of the registers |
| 24430 |
being overwritten by the load. |
| 24431 |
|
| 24432 |
The 'Q' and 'R' constraints are also available for 64-bit |
| 24433 |
constants. */ |
| 24434 |
case 'Q': |
| 24435 |
if (CONST_INT_P (x) || CONST_DOUBLE_P (x)) |
| 24436 |
{ |
| 24437 |
rtx part = gen_lowpart (SImode, x); |
| 24438 |
fprintf (stream, "#" HOST_WIDE_INT_PRINT_DEC, INTVAL (part)); |
| 24439 |
return; |
| 24440 |
} |
| 24441 |
|
| 24442 |
if (!REG_P (x) || REGNO (x) > LAST_ARM_REGNUM) |
| 24443 |
{ |
| 24444 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24445 |
return; |
| 24446 |
} |
| 24447 |
|
| 24448 |
asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 1 : 0)); |
| 24449 |
return; |
| 24450 |
|
| 24451 |
case 'R': |
| 24452 |
if (CONST_INT_P (x) || CONST_DOUBLE_P (x)) |
| 24453 |
{ |
| 24454 |
machine_mode mode = GET_MODE (x); |
| 24455 |
rtx part; |
| 24456 |
|
| 24457 |
if (mode == VOIDmode) |
| 24458 |
mode = DImode; |
| 24459 |
part = gen_highpart_mode (SImode, mode, x); |
| 24460 |
fprintf (stream, "#" HOST_WIDE_INT_PRINT_DEC, INTVAL (part)); |
| 24461 |
return; |
| 24462 |
} |
| 24463 |
|
| 24464 |
if (!REG_P (x) || REGNO (x) > LAST_ARM_REGNUM) |
| 24465 |
{ |
| 24466 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24467 |
return; |
| 24468 |
} |
| 24469 |
|
| 24470 |
asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 0 : 1)); |
| 24471 |
return; |
| 24472 |
|
| 24473 |
case 'H': |
| 24474 |
if (!REG_P (x) || REGNO (x) > LAST_ARM_REGNUM) |
| 24475 |
{ |
| 24476 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24477 |
return; |
| 24478 |
} |
| 24479 |
|
| 24480 |
asm_fprintf (stream, "%r", REGNO (x) + 1); |
| 24481 |
return; |
| 24482 |
|
| 24483 |
case 'J': |
| 24484 |
if (!REG_P (x) || REGNO (x) > LAST_ARM_REGNUM) |
| 24485 |
{ |
| 24486 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24487 |
return; |
| 24488 |
} |
| 24489 |
|
| 24490 |
asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 3 : 2)); |
| 24491 |
return; |
| 24492 |
|
| 24493 |
case 'K': |
| 24494 |
if (!REG_P (x) || REGNO (x) > LAST_ARM_REGNUM) |
| 24495 |
{ |
| 24496 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24497 |
return; |
| 24498 |
} |
| 24499 |
|
| 24500 |
asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 2 : 3)); |
| 24501 |
return; |
| 24502 |
|
| 24503 |
case 'm': |
| 24504 |
asm_fprintf (stream, "%r", |
| 24505 |
REG_P (XEXP (x, 0)) |
| 24506 |
? REGNO (XEXP (x, 0)) : REGNO (XEXP (XEXP (x, 0), 0))); |
| 24507 |
return; |
| 24508 |
|
| 24509 |
case 'M': |
| 24510 |
asm_fprintf (stream, "{%r-%r}", |
| 24511 |
REGNO (x), |
| 24512 |
REGNO (x) + ARM_NUM_REGS (GET_MODE (x)) - 1); |
| 24513 |
return; |
| 24514 |
|
| 24515 |
/* Like 'M', but writing doubleword vector registers, for use by Neon |
| 24516 |
insns. */ |
| 24517 |
case 'h': |
| 24518 |
{ |
| 24519 |
int regno = (REGNO (x) - FIRST_VFP_REGNUM) / 2; |
| 24520 |
int numregs = ARM_NUM_REGS (GET_MODE (x)) / 2; |
| 24521 |
if (numregs == 1) |
| 24522 |
asm_fprintf (stream, "{d%d}", regno); |
| 24523 |
else |
| 24524 |
asm_fprintf (stream, "{d%d-d%d}", regno, regno + numregs - 1); |
| 24525 |
} |
| 24526 |
return; |
| 24527 |
|
| 24528 |
case 'd': |
| 24529 |
/* CONST_TRUE_RTX means always -- that's the default. */ |
| 24530 |
if (x == const_true_rtx) |
| 24531 |
return; |
| 24532 |
|
| 24533 |
if (!COMPARISON_P (x)) |
| 24534 |
{ |
| 24535 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24536 |
return; |
| 24537 |
} |
| 24538 |
|
| 24539 |
fputs (arm_condition_codes[get_arm_condition_code (x)], |
| 24540 |
stream); |
| 24541 |
return; |
| 24542 |
|
| 24543 |
case 'D': |
| 24544 |
/* CONST_TRUE_RTX means not always -- i.e. never. We shouldn't ever |
| 24545 |
want to do that. */ |
| 24546 |
if (x == const_true_rtx) |
| 24547 |
{ |
| 24548 |
output_operand_lossage ("instruction never executed"); |
| 24549 |
return; |
| 24550 |
} |
| 24551 |
if (!COMPARISON_P (x)) |
| 24552 |
{ |
| 24553 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24554 |
return; |
| 24555 |
} |
| 24556 |
|
| 24557 |
fputs (arm_condition_codes[ARM_INVERSE_CONDITION_CODE |
| 24558 |
(get_arm_condition_code (x))], |
| 24559 |
stream); |
| 24560 |
return; |
| 24561 |
|
| 24562 |
case 'V': |
| 24563 |
{ |
| 24564 |
/* Output the LSB (shift) and width for a bitmask instruction |
| 24565 |
based on a literal mask. The LSB is printed first, |
| 24566 |
followed by the width. |
| 24567 |
|
| 24568 |
Eg. For 0b1...1110001, the result is #1, #3. */ |
| 24569 |
if (!CONST_INT_P (x)) |
| 24570 |
{ |
| 24571 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24572 |
return; |
| 24573 |
} |
| 24574 |
|
| 24575 |
unsigned HOST_WIDE_INT val |
| 24576 |
= ~UINTVAL (x) & HOST_WIDE_INT_UC (0xffffffff); |
| 24577 |
int lsb = exact_log2 (val & -val); |
| 24578 |
asm_fprintf (stream, "#%d, #%d", lsb, |
| 24579 |
(exact_log2 (val + (val & -val)) - lsb)); |
| 24580 |
} |
| 24581 |
return; |
| 24582 |
|
| 24583 |
case 'N': |
| 24584 |
/* Former FPA support, effectively unused after GCC-4.7, but not |
| 24585 |
removed until gcc-15. */ |
| 24586 |
output_operand_lossage ("obsolete FPA format code '%c'", code); |
| 24587 |
return; |
| 24588 |
|
| 24589 |
case 's': |
| 24590 |
case 'W': |
| 24591 |
case 'X': |
| 24592 |
case 'Y': |
| 24593 |
case 'Z': |
| 24594 |
/* Former Maverick support, removed after GCC-4.7. */ |
| 24595 |
output_operand_lossage ("obsolete Maverick format code '%c'", code); |
| 24596 |
return; |
| 24597 |
|
| 24598 |
case 'U': |
| 24599 |
if (!REG_P (x) |
| 24600 |
|| REGNO (x) < FIRST_IWMMXT_GR_REGNUM |
| 24601 |
|| REGNO (x) > LAST_IWMMXT_GR_REGNUM) |
| 24602 |
/* Bad value for wCG register number. */ |
| 24603 |
{ |
| 24604 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24605 |
return; |
| 24606 |
} |
| 24607 |
|
| 24608 |
else |
| 24609 |
fprintf (stream, "%d", REGNO (x) - FIRST_IWMMXT_GR_REGNUM); |
| 24610 |
return; |
| 24611 |
|
| 24612 |
/* Print an iWMMXt control register name. */ |
| 24613 |
case 'w': |
| 24614 |
if (!CONST_INT_P (x) |
| 24615 |
|| INTVAL (x) < 0 |
| 24616 |
|| INTVAL (x) >= 16) |
| 24617 |
/* Bad value for wC register number. */ |
| 24618 |
{ |
| 24619 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24620 |
return; |
| 24621 |
} |
| 24622 |
|
| 24623 |
else |
| 24624 |
{ |
| 24625 |
static const char * wc_reg_names [16] = |
| 24626 |
{ |
| 24627 |
"wCID", "wCon", "wCSSF", "wCASF", |
| 24628 |
"wC4", "wC5", "wC6", "wC7", |
| 24629 |
"wCGR0", "wCGR1", "wCGR2", "wCGR3", |
| 24630 |
"wC12", "wC13", "wC14", "wC15" |
| 24631 |
}; |
| 24632 |
|
| 24633 |
fputs (wc_reg_names [INTVAL (x)], stream); |
| 24634 |
} |
| 24635 |
return; |
| 24636 |
|
| 24637 |
/* Print the high single-precision register of a VFP double-precision |
| 24638 |
register. */ |
| 24639 |
case 'p': |
| 24640 |
{ |
| 24641 |
machine_mode mode = GET_MODE (x); |
| 24642 |
int regno; |
| 24643 |
|
| 24644 |
if (GET_MODE_SIZE (mode) != 8 || !REG_P (x)) |
| 24645 |
{ |
| 24646 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24647 |
return; |
| 24648 |
} |
| 24649 |
|
| 24650 |
regno = REGNO (x); |
| 24651 |
if (!VFP_REGNO_OK_FOR_DOUBLE (regno)) |
| 24652 |
{ |
| 24653 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24654 |
return; |
| 24655 |
} |
| 24656 |
|
| 24657 |
fprintf (stream, "s%d", regno - FIRST_VFP_REGNUM + 1); |
| 24658 |
} |
| 24659 |
return; |
| 24660 |
|
| 24661 |
/* Print a VFP/Neon double precision or quad precision register name. */ |
| 24662 |
case 'P': |
| 24663 |
case 'q': |
| 24664 |
{ |
| 24665 |
machine_mode mode = GET_MODE (x); |
| 24666 |
int is_quad = (code == 'q'); |
| 24667 |
int regno; |
| 24668 |
|
| 24669 |
if (GET_MODE_SIZE (mode) != (is_quad ? 16 : 8)) |
| 24670 |
{ |
| 24671 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24672 |
return; |
| 24673 |
} |
| 24674 |
|
| 24675 |
if (!REG_P (x) |
| 24676 |
|| !IS_VFP_REGNUM (REGNO (x))) |
| 24677 |
{ |
| 24678 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24679 |
return; |
| 24680 |
} |
| 24681 |
|
| 24682 |
regno = REGNO (x); |
| 24683 |
if ((is_quad && !NEON_REGNO_OK_FOR_QUAD (regno)) |
| 24684 |
|| (!is_quad && !VFP_REGNO_OK_FOR_DOUBLE (regno))) |
| 24685 |
{ |
| 24686 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24687 |
return; |
| 24688 |
} |
| 24689 |
|
| 24690 |
fprintf (stream, "%c%d", is_quad ? 'q' : 'd', |
| 24691 |
(regno - FIRST_VFP_REGNUM) >> (is_quad ? 2 : 1)); |
| 24692 |
} |
| 24693 |
return; |
| 24694 |
|
| 24695 |
/* These two codes print the low/high doubleword register of a Neon quad |
| 24696 |
register, respectively. For pair-structure types, can also print |
| 24697 |
low/high quadword registers. */ |
| 24698 |
case 'e': |
| 24699 |
case 'f': |
| 24700 |
{ |
| 24701 |
machine_mode mode = GET_MODE (x); |
| 24702 |
int regno; |
| 24703 |
|
| 24704 |
if ((GET_MODE_SIZE (mode) != 16 |
| 24705 |
&& GET_MODE_SIZE (mode) != 32) || !REG_P (x)) |
| 24706 |
{ |
| 24707 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24708 |
return; |
| 24709 |
} |
| 24710 |
|
| 24711 |
regno = REGNO (x); |
| 24712 |
if (!NEON_REGNO_OK_FOR_QUAD (regno)) |
| 24713 |
{ |
| 24714 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24715 |
return; |
| 24716 |
} |
| 24717 |
|
| 24718 |
if (GET_MODE_SIZE (mode) == 16) |
| 24719 |
fprintf (stream, "d%d", ((regno - FIRST_VFP_REGNUM) >> 1) |
| 24720 |
+ (code == 'f' ? 1 : 0)); |
| 24721 |
else |
| 24722 |
fprintf (stream, "q%d", ((regno - FIRST_VFP_REGNUM) >> 2) |
| 24723 |
+ (code == 'f' ? 1 : 0)); |
| 24724 |
} |
| 24725 |
return; |
| 24726 |
|
| 24727 |
/* Print a VFPv3 floating-point constant, represented as an integer |
| 24728 |
index. */ |
| 24729 |
case 'G': |
| 24730 |
{ |
| 24731 |
int index = vfp3_const_double_index (x); |
| 24732 |
gcc_assert (index != -1); |
| 24733 |
fprintf (stream, "%d", index); |
| 24734 |
} |
| 24735 |
return; |
| 24736 |
|
| 24737 |
/* Print bits representing opcode features for Neon. |
| 24738 |
|
| 24739 |
Bit 0 is 1 for signed, 0 for unsigned. Floats count as signed |
| 24740 |
and polynomials as unsigned. |
| 24741 |
|
| 24742 |
Bit 1 is 1 for floats and polynomials, 0 for ordinary integers. |
| 24743 |
|
| 24744 |
Bit 2 is 1 for rounding functions, 0 otherwise. */ |
| 24745 |
|
| 24746 |
/* Identify the type as 's', 'u', 'p' or 'f'. */ |
| 24747 |
case 'T': |
| 24748 |
{ |
| 24749 |
HOST_WIDE_INT bits = INTVAL (x); |
| 24750 |
fputc ("uspf"[bits & 3], stream); |
| 24751 |
} |
| 24752 |
return; |
| 24753 |
|
| 24754 |
/* Likewise, but signed and unsigned integers are both 'i'. */ |
| 24755 |
case 'F': |
| 24756 |
{ |
| 24757 |
HOST_WIDE_INT bits = INTVAL (x); |
| 24758 |
fputc ("iipf"[bits & 3], stream); |
| 24759 |
} |
| 24760 |
return; |
| 24761 |
|
| 24762 |
/* As for 'T', but emit 'u' instead of 'p'. */ |
| 24763 |
case 't': |
| 24764 |
{ |
| 24765 |
HOST_WIDE_INT bits = INTVAL (x); |
| 24766 |
fputc ("usuf"[bits & 3], stream); |
| 24767 |
} |
| 24768 |
return; |
| 24769 |
|
| 24770 |
/* Bit 2: rounding (vs none). */ |
| 24771 |
case 'O': |
| 24772 |
{ |
| 24773 |
HOST_WIDE_INT bits = INTVAL (x); |
| 24774 |
fputs ((bits & 4) != 0 ? "r" : "", stream); |
| 24775 |
} |
| 24776 |
return; |
| 24777 |
|
| 24778 |
/* Memory operand for vld1/vst1 instruction. */ |
| 24779 |
case 'A': |
| 24780 |
{ |
| 24781 |
rtx addr; |
| 24782 |
bool postinc = FALSE; |
| 24783 |
rtx postinc_reg = NULL; |
| 24784 |
unsigned align, memsize, align_bits; |
| 24785 |
|
| 24786 |
gcc_assert (MEM_P (x)); |
| 24787 |
addr = XEXP (x, 0); |
| 24788 |
if (GET_CODE (addr) == POST_INC) |
| 24789 |
{ |
| 24790 |
postinc = 1; |
| 24791 |
addr = XEXP (addr, 0); |
| 24792 |
} |
| 24793 |
if (GET_CODE (addr) == POST_MODIFY) |
| 24794 |
{ |
| 24795 |
postinc_reg = XEXP( XEXP (addr, 1), 1); |
| 24796 |
addr = XEXP (addr, 0); |
| 24797 |
} |
| 24798 |
asm_fprintf (stream, "[%r", REGNO (addr)); |
| 24799 |
|
| 24800 |
/* We know the alignment of this access, so we can emit a hint in the |
| 24801 |
instruction (for some alignments) as an aid to the memory subsystem |
| 24802 |
of the target. */ |
| 24803 |
align = MEM_ALIGN (x) >> 3; |
| 24804 |
memsize = MEM_SIZE (x); |
| 24805 |
|
| 24806 |
/* Only certain alignment specifiers are supported by the hardware. */ |
| 24807 |
if (memsize == 32 && (align % 32) == 0) |
| 24808 |
align_bits = 256; |
| 24809 |
else if ((memsize == 16 || memsize == 32) && (align % 16) == 0) |
| 24810 |
align_bits = 128; |
| 24811 |
else if (memsize >= 8 && (align % 8) == 0) |
| 24812 |
align_bits = 64; |
| 24813 |
else |
| 24814 |
align_bits = 0; |
| 24815 |
|
| 24816 |
if (align_bits != 0) |
| 24817 |
asm_fprintf (stream, ":%d", align_bits); |
| 24818 |
|
| 24819 |
asm_fprintf (stream, "]"); |
| 24820 |
|
| 24821 |
if (postinc) |
| 24822 |
fputs("!", stream); |
| 24823 |
if (postinc_reg) |
| 24824 |
asm_fprintf (stream, ", %r", REGNO (postinc_reg)); |
| 24825 |
} |
| 24826 |
return; |
| 24827 |
|
| 24828 |
/* To print the memory operand with "Ux" or "Uj" constraint. Based on the |
| 24829 |
rtx_code the memory operands output looks like following. |
| 24830 |
1. [Rn], #+/-<imm> |
| 24831 |
2. [Rn, #+/-<imm>]! |
| 24832 |
3. [Rn, #+/-<imm>] |
| 24833 |
4. [Rn]. */ |
| 24834 |
case 'E': |
| 24835 |
{ |
| 24836 |
rtx addr; |
| 24837 |
rtx postinc_reg = NULL; |
| 24838 |
unsigned inc_val = 0; |
| 24839 |
enum rtx_code code; |
| 24840 |
|
| 24841 |
gcc_assert (MEM_P (x)); |
| 24842 |
addr = XEXP (x, 0); |
| 24843 |
code = GET_CODE (addr); |
| 24844 |
if (code == POST_INC || code == POST_DEC || code == PRE_INC |
| 24845 |
|| code == PRE_DEC) |
| 24846 |
{ |
| 24847 |
asm_fprintf (stream, "[%r", REGNO (XEXP (addr, 0))); |
| 24848 |
inc_val = GET_MODE_SIZE (GET_MODE (x)); |
| 24849 |
if (code == POST_INC || code == POST_DEC) |
| 24850 |
asm_fprintf (stream, "], #%s%d", (code == POST_INC) |
| 24851 |
? "" : "-", inc_val); |
| 24852 |
else |
| 24853 |
asm_fprintf (stream, ", #%s%d]!", (code == PRE_INC) |
| 24854 |
? "" : "-", inc_val); |
| 24855 |
} |
| 24856 |
else if (code == POST_MODIFY || code == PRE_MODIFY) |
| 24857 |
{ |
| 24858 |
asm_fprintf (stream, "[%r", REGNO (XEXP (addr, 0))); |
| 24859 |
postinc_reg = XEXP (XEXP (addr, 1), 1); |
| 24860 |
if (postinc_reg && CONST_INT_P (postinc_reg)) |
| 24861 |
{ |
| 24862 |
if (code == POST_MODIFY) |
| 24863 |
asm_fprintf (stream, "], #%wd", INTVAL (postinc_reg)); |
| 24864 |
else |
| 24865 |
asm_fprintf (stream, ", #%wd]!", INTVAL (postinc_reg)); |
| 24866 |
} |
| 24867 |
} |
| 24868 |
else if (code == PLUS) |
| 24869 |
{ |
| 24870 |
rtx base = XEXP (addr, 0); |
| 24871 |
rtx index = XEXP (addr, 1); |
| 24872 |
|
| 24873 |
gcc_assert (REG_P (base) && CONST_INT_P (index)); |
| 24874 |
|
| 24875 |
HOST_WIDE_INT offset = INTVAL (index); |
| 24876 |
asm_fprintf (stream, "[%r, #%wd]", REGNO (base), offset); |
| 24877 |
} |
| 24878 |
else |
| 24879 |
{ |
| 24880 |
gcc_assert (REG_P (addr)); |
| 24881 |
asm_fprintf (stream, "[%r]",REGNO (addr)); |
| 24882 |
} |
| 24883 |
} |
| 24884 |
return; |
| 24885 |
|
| 24886 |
case 'C': |
| 24887 |
{ |
| 24888 |
rtx addr; |
| 24889 |
|
| 24890 |
gcc_assert (MEM_P (x)); |
| 24891 |
addr = XEXP (x, 0); |
| 24892 |
gcc_assert (REG_P (addr)); |
| 24893 |
asm_fprintf (stream, "[%r]", REGNO (addr)); |
| 24894 |
} |
| 24895 |
return; |
| 24896 |
|
| 24897 |
/* Translate an S register number into a D register number and element index. */ |
| 24898 |
case 'y': |
| 24899 |
{ |
| 24900 |
machine_mode mode = GET_MODE (x); |
| 24901 |
int regno; |
| 24902 |
|
| 24903 |
if (GET_MODE_SIZE (mode) != 4 || !REG_P (x)) |
| 24904 |
{ |
| 24905 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24906 |
return; |
| 24907 |
} |
| 24908 |
|
| 24909 |
regno = REGNO (x); |
| 24910 |
if (!VFP_REGNO_OK_FOR_SINGLE (regno)) |
| 24911 |
{ |
| 24912 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24913 |
return; |
| 24914 |
} |
| 24915 |
|
| 24916 |
regno = regno - FIRST_VFP_REGNUM; |
| 24917 |
fprintf (stream, "d%d[%d]", regno / 2, regno % 2); |
| 24918 |
} |
| 24919 |
return; |
| 24920 |
|
| 24921 |
case 'v': |
| 24922 |
gcc_assert (CONST_DOUBLE_P (x)); |
| 24923 |
int result; |
| 24924 |
result = vfp3_const_double_for_fract_bits (x); |
| 24925 |
if (result == 0) |
| 24926 |
result = vfp3_const_double_for_bits (x); |
| 24927 |
fprintf (stream, "#%d", result); |
| 24928 |
return; |
| 24929 |
|
| 24930 |
/* Register specifier for vld1.16/vst1.16. Translate the S register |
| 24931 |
number into a D register number and element index. */ |
| 24932 |
case 'z': |
| 24933 |
{ |
| 24934 |
machine_mode mode = GET_MODE (x); |
| 24935 |
int regno; |
| 24936 |
|
| 24937 |
if (GET_MODE_SIZE (mode) != 2 || !REG_P (x)) |
| 24938 |
{ |
| 24939 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24940 |
return; |
| 24941 |
} |
| 24942 |
|
| 24943 |
regno = REGNO (x); |
| 24944 |
if (!VFP_REGNO_OK_FOR_SINGLE (regno)) |
| 24945 |
{ |
| 24946 |
output_operand_lossage ("invalid operand for code '%c'", code); |
| 24947 |
return; |
| 24948 |
} |
| 24949 |
|
| 24950 |
regno = regno - FIRST_VFP_REGNUM; |
| 24951 |
fprintf (stream, "d%d[%d]", regno/2, ((regno % 2) ? 2 : 0)); |
| 24952 |
} |
| 24953 |
return; |
| 24954 |
|
| 24955 |
default: |
| 24956 |
if (x == 0) |
| 24957 |
{ |
| 24958 |
output_operand_lossage ("missing operand"); |
| 24959 |
return; |
| 24960 |
} |
| 24961 |
|
| 24962 |
switch (GET_CODE (x)) |
| 24963 |
{ |
| 24964 |
case REG: |
| 24965 |
asm_fprintf (stream, "%r", REGNO (x)); |
| 24966 |
break; |
| 24967 |
|
| 24968 |
case MEM: |
| 24969 |
output_address (GET_MODE (x), XEXP (x, 0)); |
| 24970 |
break; |
| 24971 |
|
| 24972 |
case CONST_DOUBLE: |
| 24973 |
{ |
| 24974 |
char fpstr[20]; |
| 24975 |
real_to_decimal (fpstr, CONST_DOUBLE_REAL_VALUE (x), |
| 24976 |
sizeof (fpstr), 0, 1); |
| 24977 |
fprintf (stream, "#%s", fpstr); |
| 24978 |
} |
| 24979 |
break; |
| 24980 |
|
| 24981 |
default: |
| 24982 |
gcc_assert (GET_CODE (x) != NEG); |
| 24983 |
fputc ('#', stream); |
| 24984 |
if (GET_CODE (x) == HIGH) |
| 24985 |
{ |
| 24986 |
fputs (":lower16:", stream); |
| 24987 |
x = XEXP (x, 0); |
| 24988 |
} |
| 24989 |
|
| 24990 |
output_addr_const (stream, x); |
| 24991 |
break; |
| 24992 |
} |
| 24993 |
} |
| 24994 |
} |
| 24995 |
|
| 24996 |
/* Target hook for printing a memory address. */ |
| 24997 |
static void |
| 24998 |
arm_print_operand_address (FILE *stream, machine_mode mode, rtx x) |
| 24999 |
{ |
| 25000 |
if (TARGET_32BIT) |
| 25001 |
{ |
| 25002 |
int is_minus = GET_CODE (x) == MINUS; |
| 25003 |
|
| 25004 |
if (REG_P (x)) |
| 25005 |
asm_fprintf (stream, "[%r]", REGNO (x)); |
| 25006 |
else if (GET_CODE (x) == PLUS || is_minus) |
| 25007 |
{ |
| 25008 |
rtx base = XEXP (x, 0); |
| 25009 |
rtx index = XEXP (x, 1); |
| 25010 |
HOST_WIDE_INT offset = 0; |
| 25011 |
if (!REG_P (base) |
| 25012 |
|| (REG_P (index) && REGNO (index) == SP_REGNUM)) |
| 25013 |
{ |
| 25014 |
/* Ensure that BASE is a register. */ |
| 25015 |
/* (one of them must be). */ |
| 25016 |
/* Also ensure the SP is not used as in index register. */ |
| 25017 |
std::swap (base, index); |
| 25018 |
} |
| 25019 |
switch (GET_CODE (index)) |
| 25020 |
{ |
| 25021 |
case CONST_INT: |
| 25022 |
offset = INTVAL (index); |
| 25023 |
if (is_minus) |
| 25024 |
offset = -offset; |
| 25025 |
asm_fprintf (stream, "[%r, #%wd]", |
| 25026 |
REGNO (base), offset); |
| 25027 |
break; |
| 25028 |
|
| 25029 |
case REG: |
| 25030 |
asm_fprintf (stream, "[%r, %s%r]", |
| 25031 |
REGNO (base), is_minus ? "-" : "", |
| 25032 |
REGNO (index)); |
| 25033 |
break; |
| 25034 |
|
| 25035 |
case MULT: |
| 25036 |
case ASHIFTRT: |
| 25037 |
case LSHIFTRT: |
| 25038 |
case ASHIFT: |
| 25039 |
case ROTATERT: |
| 25040 |
{ |
| 25041 |
asm_fprintf (stream, "[%r, %s%r", |
| 25042 |
REGNO (base), is_minus ? "-" : "", |
| 25043 |
REGNO (XEXP (index, 0))); |
| 25044 |
arm_print_operand (stream, index, 'S'); |
| 25045 |
fputs ("]", stream); |
| 25046 |
break; |
| 25047 |
} |
| 25048 |
|
| 25049 |
default: |
| 25050 |
gcc_unreachable (); |
| 25051 |
} |
| 25052 |
} |
| 25053 |
else if (GET_CODE (x) == PRE_INC || GET_CODE (x) == POST_INC |
| 25054 |
|| GET_CODE (x) == PRE_DEC || GET_CODE (x) == POST_DEC) |
| 25055 |
{ |
| 25056 |
gcc_assert (REG_P (XEXP (x, 0))); |
| 25057 |
|
| 25058 |
if (GET_CODE (x) == PRE_DEC || GET_CODE (x) == PRE_INC) |
| 25059 |
asm_fprintf (stream, "[%r, #%s%d]!", |
| 25060 |
REGNO (XEXP (x, 0)), |
| 25061 |
GET_CODE (x) == PRE_DEC ? "-" : "", |
| 25062 |
GET_MODE_SIZE (mode)); |
| 25063 |
else if (TARGET_HAVE_MVE |
| 25064 |
&& VALID_MVE_STRUCT_MODE (mode)) |
| 25065 |
asm_fprintf (stream, "[%r]!", REGNO (XEXP (x,0))); |
| 25066 |
else |
| 25067 |
asm_fprintf (stream, "[%r], #%s%d", REGNO (XEXP (x, 0)), |
| 25068 |
GET_CODE (x) == POST_DEC ? "-" : "", |
| 25069 |
GET_MODE_SIZE (mode)); |
| 25070 |
} |
| 25071 |
else if (GET_CODE (x) == PRE_MODIFY) |
| 25072 |
{ |
| 25073 |
asm_fprintf (stream, "[%r, ", REGNO (XEXP (x, 0))); |
| 25074 |
if (CONST_INT_P (XEXP (XEXP (x, 1), 1))) |
| 25075 |
asm_fprintf (stream, "#%wd]!", |
| 25076 |
INTVAL (XEXP (XEXP (x, 1), 1))); |
| 25077 |
else |
| 25078 |
asm_fprintf (stream, "%r]!", |
| 25079 |
REGNO (XEXP (XEXP (x, 1), 1))); |
| 25080 |
} |
| 25081 |
else if (GET_CODE (x) == POST_MODIFY) |
| 25082 |
{ |
| 25083 |
asm_fprintf (stream, "[%r], ", REGNO (XEXP (x, 0))); |
| 25084 |
if (CONST_INT_P (XEXP (XEXP (x, 1), 1))) |
| 25085 |
asm_fprintf (stream, "#%wd", |
| 25086 |
INTVAL (XEXP (XEXP (x, 1), 1))); |
| 25087 |
else |
| 25088 |
asm_fprintf (stream, "%r", |
| 25089 |
REGNO (XEXP (XEXP (x, 1), 1))); |
| 25090 |
} |
| 25091 |
else output_addr_const (stream, x); |
| 25092 |
} |
| 25093 |
else |
| 25094 |
{ |
| 25095 |
if (REG_P (x)) |
| 25096 |
asm_fprintf (stream, "[%r]", REGNO (x)); |
| 25097 |
else if (GET_CODE (x) == POST_INC) |
| 25098 |
asm_fprintf (stream, "%r!", REGNO (XEXP (x, 0))); |
| 25099 |
else if (GET_CODE (x) == PLUS) |
| 25100 |
{ |
| 25101 |
gcc_assert (REG_P (XEXP (x, 0))); |
| 25102 |
if (CONST_INT_P (XEXP (x, 1))) |
| 25103 |
asm_fprintf (stream, "[%r, #%wd]", |
| 25104 |
REGNO (XEXP (x, 0)), |
| 25105 |
INTVAL (XEXP (x, 1))); |
| 25106 |
else |
| 25107 |
asm_fprintf (stream, "[%r, %r]", |
| 25108 |
REGNO (XEXP (x, 0)), |
| 25109 |
REGNO (XEXP (x, 1))); |
| 25110 |
} |
| 25111 |
else |
| 25112 |
output_addr_const (stream, x); |
| 25113 |
} |
| 25114 |
} |
| 25115 |
|
| 25116 |
/* Target hook for indicating whether a punctuation character for |
| 25117 |
TARGET_PRINT_OPERAND is valid. */ |
| 25118 |
static bool |
| 25119 |
arm_print_operand_punct_valid_p (unsigned char code) |
| 25120 |
{ |
| 25121 |
return (code == '@' || code == '|' || code == '.' |
| 25122 |
|| code == '(' || code == ')' || code == '#' |
| 25123 |
|| code == '-' || code == '_' |
| 25124 |
|| (TARGET_32BIT && (code == '?')) |
| 25125 |
|| (TARGET_THUMB2 && (code == '!'))); |
| 25126 |
} |
| 25127 |
|
| 25128 |
/* Target hook for assembling integer objects. The ARM version needs to |
| 25129 |
handle word-sized values specially. */ |
| 25130 |
static bool |
| 25131 |
arm_assemble_integer (rtx x, unsigned int size, int aligned_p) |
| 25132 |
{ |
| 25133 |
machine_mode mode; |
| 25134 |
|
| 25135 |
if (size == UNITS_PER_WORD && aligned_p) |
| 25136 |
{ |
| 25137 |
fputs ("\t.word\t", asm_out_file); |
| 25138 |
output_addr_const (asm_out_file, x); |
| 25139 |
|
| 25140 |
/* Mark symbols as position independent. We only do this in the |
| 25141 |
.text segment, not in the .data segment. */ |
| 25142 |
if (NEED_GOT_RELOC && flag_pic && making_const_table && |
| 25143 |
(SYMBOL_REF_P (x) || LABEL_REF_P (x))) |
| 25144 |
{ |
| 25145 |
/* See legitimize_pic_address for an explanation of the |
| 25146 |
TARGET_VXWORKS_RTP check. */ |
| 25147 |
/* References to weak symbols cannot be resolved locally: |
| 25148 |
they may be overridden by a non-weak definition at link |
| 25149 |
time. */ |
| 25150 |
if (!arm_pic_data_is_text_relative |
| 25151 |
|| (SYMBOL_REF_P (x) |
| 25152 |
&& (!SYMBOL_REF_LOCAL_P (x) |
| 25153 |
|| (SYMBOL_REF_DECL (x) |
| 25154 |
? DECL_WEAK (SYMBOL_REF_DECL (x)) : 0) |
| 25155 |
|| (SYMBOL_REF_FUNCTION_P (x) |
| 25156 |
&& !arm_fdpic_local_funcdesc_p (x))))) |
| 25157 |
{ |
| 25158 |
if (TARGET_FDPIC && SYMBOL_REF_FUNCTION_P (x)) |
| 25159 |
fputs ("(GOTFUNCDESC)", asm_out_file); |
| 25160 |
else |
| 25161 |
fputs ("(GOT)", asm_out_file); |
| 25162 |
} |
| 25163 |
else |
| 25164 |
{ |
| 25165 |
if (TARGET_FDPIC && SYMBOL_REF_FUNCTION_P (x)) |
| 25166 |
fputs ("(GOTOFFFUNCDESC)", asm_out_file); |
| 25167 |
else |
| 25168 |
{ |
| 25169 |
bool is_readonly; |
| 25170 |
|
| 25171 |
if (!TARGET_FDPIC |
| 25172 |
|| arm_is_segment_info_known (x, &is_readonly)) |
| 25173 |
fputs ("(GOTOFF)", asm_out_file); |
| 25174 |
else |
| 25175 |
fputs ("(GOT)", asm_out_file); |
| 25176 |
} |
| 25177 |
} |
| 25178 |
} |
| 25179 |
|
| 25180 |
/* For FDPIC we also have to mark symbol for .data section. */ |
| 25181 |
if (TARGET_FDPIC |
| 25182 |
&& !making_const_table |
| 25183 |
&& SYMBOL_REF_P (x) |
| 25184 |
&& SYMBOL_REF_FUNCTION_P (x)) |
| 25185 |
fputs ("(FUNCDESC)", asm_out_file); |
| 25186 |
|
| 25187 |
fputc ('\n', asm_out_file); |
| 25188 |
return true; |
| 25189 |
} |
| 25190 |
|
| 25191 |
mode = GET_MODE (x); |
| 25192 |
|
| 25193 |
if (arm_vector_mode_supported_p (mode)) |
| 25194 |
{ |
| 25195 |
int i, units; |
| 25196 |
|
| 25197 |
gcc_assert (GET_CODE (x) == CONST_VECTOR); |
| 25198 |
|
| 25199 |
units = CONST_VECTOR_NUNITS (x); |
| 25200 |
size = GET_MODE_UNIT_SIZE (mode); |
| 25201 |
|
| 25202 |
if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) |
| 25203 |
for (i = 0; i < units; i++) |
| 25204 |
{ |
| 25205 |
rtx elt = CONST_VECTOR_ELT (x, i); |
| 25206 |
assemble_integer |
| 25207 |
(elt, size, i == 0 ? BIGGEST_ALIGNMENT : size * BITS_PER_UNIT, 1); |
| 25208 |
} |
| 25209 |
else |
| 25210 |
for (i = 0; i < units; i++) |
| 25211 |
{ |
| 25212 |
rtx elt = CONST_VECTOR_ELT (x, i); |
| 25213 |
assemble_real |
| 25214 |
(*CONST_DOUBLE_REAL_VALUE (elt), |
| 25215 |
as_a <scalar_float_mode> (GET_MODE_INNER (mode)), |
| 25216 |
i == 0 ? BIGGEST_ALIGNMENT : size * BITS_PER_UNIT); |
| 25217 |
} |
| 25218 |
|
| 25219 |
return true; |
| 25220 |
} |
| 25221 |
|
| 25222 |
return default_assemble_integer (x, size, aligned_p); |
| 25223 |
} |
| 25224 |
|
| 25225 |
static void |
| 25226 |
arm_elf_asm_cdtor (rtx symbol, int priority, bool is_ctor) |
| 25227 |
{ |
| 25228 |
section *s; |
| 25229 |
|
| 25230 |
if (!TARGET_AAPCS_BASED) |
| 25231 |
{ |
| 25232 |
(is_ctor ? |
| 25233 |
default_named_section_asm_out_constructor |
| 25234 |
: default_named_section_asm_out_destructor) (symbol, priority); |
| 25235 |
return; |
| 25236 |
} |
| 25237 |
|
| 25238 |
/* Put these in the .init_array section, using a special relocation. */ |
| 25239 |
if (priority != DEFAULT_INIT_PRIORITY) |
| 25240 |
{ |
| 25241 |
char buf[18]; |
| 25242 |
sprintf (buf, "%s.%.5u", |
| 25243 |
is_ctor ? ".init_array" : ".fini_array", |
| 25244 |
priority); |
| 25245 |
s = get_section (buf, SECTION_WRITE | SECTION_NOTYPE, NULL_TREE); |
| 25246 |
} |
| 25247 |
else if (is_ctor) |
| 25248 |
s = ctors_section; |
| 25249 |
else |
| 25250 |
s = dtors_section; |
| 25251 |
|
| 25252 |
switch_to_section (s); |
| 25253 |
assemble_align (POINTER_SIZE); |
| 25254 |
fputs ("\t.word\t", asm_out_file); |
| 25255 |
output_addr_const (asm_out_file, symbol); |
| 25256 |
fputs ("(target1)\n", asm_out_file); |
| 25257 |
} |
| 25258 |
|
| 25259 |
/* Add a function to the list of static constructors. */ |
| 25260 |
|
| 25261 |
static void |
| 25262 |
arm_elf_asm_constructor (rtx symbol, int priority) |
| 25263 |
{ |
| 25264 |
arm_elf_asm_cdtor (symbol, priority, /*is_ctor=*/true); |
| 25265 |
} |
| 25266 |
|
| 25267 |
/* Add a function to the list of static destructors. */ |
| 25268 |
|
| 25269 |
static void |
| 25270 |
arm_elf_asm_destructor (rtx symbol, int priority) |
| 25271 |
{ |
| 25272 |
arm_elf_asm_cdtor (symbol, priority, /*is_ctor=*/false); |
| 25273 |
} |
| 25274 |
|
| 25275 |
/* A finite state machine takes care of noticing whether or not instructions |
| 25276 |
can be conditionally executed, and thus decrease execution time and code |
| 25277 |
size by deleting branch instructions. The fsm is controlled by |
| 25278 |
final_prescan_insn, and controls the actions of ASM_OUTPUT_OPCODE. */ |
| 25279 |
|
| 25280 |
/* The state of the fsm controlling condition codes are: |
| 25281 |
0: normal, do nothing special |
| 25282 |
1: make ASM_OUTPUT_OPCODE not output this instruction |
| 25283 |
2: make ASM_OUTPUT_OPCODE not output this instruction |
| 25284 |
3: make instructions conditional |
| 25285 |
4: make instructions conditional |
| 25286 |
|
| 25287 |
State transitions (state->state by whom under condition): |
| 25288 |
0 -> 1 final_prescan_insn if the `target' is a label |
| 25289 |
0 -> 2 final_prescan_insn if the `target' is an unconditional branch |
| 25290 |
1 -> 3 ASM_OUTPUT_OPCODE after not having output the conditional branch |
| 25291 |
2 -> 4 ASM_OUTPUT_OPCODE after not having output the conditional branch |
| 25292 |
3 -> 0 (*targetm.asm_out.internal_label) if the `target' label is reached |
| 25293 |
(the target label has CODE_LABEL_NUMBER equal to arm_target_label). |
| 25294 |
4 -> 0 final_prescan_insn if the `target' unconditional branch is reached |
| 25295 |
(the target insn is arm_target_insn). |
| 25296 |
|
| 25297 |
If the jump clobbers the conditions then we use states 2 and 4. |
| 25298 |
|
| 25299 |
A similar thing can be done with conditional return insns. |
| 25300 |
|
| 25301 |
XXX In case the `target' is an unconditional branch, this conditionalising |
| 25302 |
of the instructions always reduces code size, but not always execution |
| 25303 |
time. But then, I want to reduce the code size to somewhere near what |
| 25304 |
/bin/cc produces. */ |
| 25305 |
|
| 25306 |
/* In addition to this, state is maintained for Thumb-2 COND_EXEC |
| 25307 |
instructions. When a COND_EXEC instruction is seen the subsequent |
| 25308 |
instructions are scanned so that multiple conditional instructions can be |
| 25309 |
combined into a single IT block. arm_condexec_count and arm_condexec_mask |
| 25310 |
specify the length and true/false mask for the IT block. These will be |
| 25311 |
decremented/zeroed by arm_asm_output_opcode as the insns are output. */ |
| 25312 |
|
| 25313 |
/* Returns the index of the ARM condition code string in |
| 25314 |
`arm_condition_codes', or ARM_NV if the comparison is invalid. |
| 25315 |
COMPARISON should be an rtx like `(eq (...) (...))'. */ |
| 25316 |
|
| 25317 |
enum arm_cond_code |
| 25318 |
maybe_get_arm_condition_code (rtx comparison) |
| 25319 |
{ |
| 25320 |
machine_mode mode = GET_MODE (XEXP (comparison, 0)); |
| 25321 |
enum arm_cond_code code; |
| 25322 |
enum rtx_code comp_code = GET_CODE (comparison); |
| 25323 |
|
| 25324 |
if (GET_MODE_CLASS (mode) != MODE_CC) |
| 25325 |
mode = SELECT_CC_MODE (comp_code, XEXP (comparison, 0), |
| 25326 |
XEXP (comparison, 1)); |
| 25327 |
|
| 25328 |
switch (mode) |
| 25329 |
{ |
| 25330 |
case E_CC_DNEmode: code = ARM_NE; goto dominance; |
| 25331 |
case E_CC_DEQmode: code = ARM_EQ; goto dominance; |
| 25332 |
case E_CC_DGEmode: code = ARM_GE; goto dominance; |
| 25333 |
case E_CC_DGTmode: code = ARM_GT; goto dominance; |
| 25334 |
case E_CC_DLEmode: code = ARM_LE; goto dominance; |
| 25335 |
case E_CC_DLTmode: code = ARM_LT; goto dominance; |
| 25336 |
case E_CC_DGEUmode: code = ARM_CS; goto dominance; |
| 25337 |
case E_CC_DGTUmode: code = ARM_HI; goto dominance; |
| 25338 |
case E_CC_DLEUmode: code = ARM_LS; goto dominance; |
| 25339 |
case E_CC_DLTUmode: code = ARM_CC; |
| 25340 |
|
| 25341 |
dominance: |
| 25342 |
if (comp_code == EQ) |
| 25343 |
return ARM_INVERSE_CONDITION_CODE (code); |
| 25344 |
if (comp_code == NE) |
| 25345 |
return code; |
| 25346 |
return ARM_NV; |
| 25347 |
|
| 25348 |
case E_CC_NZmode: |
| 25349 |
switch (comp_code) |
| 25350 |
{ |
| 25351 |
case NE: return ARM_NE; |
| 25352 |
case EQ: return ARM_EQ; |
| 25353 |
case GE: return ARM_PL; |
| 25354 |
case LT: return ARM_MI; |
| 25355 |
default: return ARM_NV; |
| 25356 |
} |
| 25357 |
|
| 25358 |
case E_CC_Zmode: |
| 25359 |
switch (comp_code) |
| 25360 |
{ |
| 25361 |
case NE: return ARM_NE; |
| 25362 |
case EQ: return ARM_EQ; |
| 25363 |
default: return ARM_NV; |
| 25364 |
} |
| 25365 |
|
| 25366 |
case E_CC_Nmode: |
| 25367 |
switch (comp_code) |
| 25368 |
{ |
| 25369 |
case NE: return ARM_MI; |
| 25370 |
case EQ: return ARM_PL; |
| 25371 |
default: return ARM_NV; |
| 25372 |
} |
| 25373 |
|
| 25374 |
case E_CCFPEmode: |
| 25375 |
case E_CCFPmode: |
| 25376 |
/* We can handle all cases except UNEQ and LTGT. */ |
| 25377 |
switch (comp_code) |
| 25378 |
{ |
| 25379 |
case GE: return ARM_GE; |
| 25380 |
case GT: return ARM_GT; |
| 25381 |
case LE: return ARM_LS; |
| 25382 |
case LT: return ARM_MI; |
| 25383 |
case NE: return ARM_NE; |
| 25384 |
case EQ: return ARM_EQ; |
| 25385 |
case ORDERED: return ARM_VC; |
| 25386 |
case UNORDERED: return ARM_VS; |
| 25387 |
case UNLT: return ARM_LT; |
| 25388 |
case UNLE: return ARM_LE; |
| 25389 |
case UNGT: return ARM_HI; |
| 25390 |
case UNGE: return ARM_PL; |
| 25391 |
/* UNEQ and LTGT do not have a representation. */ |
| 25392 |
case UNEQ: /* Fall through. */ |
| 25393 |
case LTGT: /* Fall through. */ |
| 25394 |
default: return ARM_NV; |
| 25395 |
} |
| 25396 |
|
| 25397 |
case E_CC_SWPmode: |
| 25398 |
switch (comp_code) |
| 25399 |
{ |
| 25400 |
case NE: return ARM_NE; |
| 25401 |
case EQ: return ARM_EQ; |
| 25402 |
case GE: return ARM_LE; |
| 25403 |
case GT: return ARM_LT; |
| 25404 |
case LE: return ARM_GE; |
| 25405 |
case LT: return ARM_GT; |
| 25406 |
case GEU: return ARM_LS; |
| 25407 |
case GTU: return ARM_CC; |
| 25408 |
case LEU: return ARM_CS; |
| 25409 |
case LTU: return ARM_HI; |
| 25410 |
default: return ARM_NV; |
| 25411 |
} |
| 25412 |
|
| 25413 |
case E_CC_Cmode: |
| 25414 |
switch (comp_code) |
| 25415 |
{ |
| 25416 |
case LTU: return ARM_CS; |
| 25417 |
case GEU: return ARM_CC; |
| 25418 |
default: return ARM_NV; |
| 25419 |
} |
| 25420 |
|
| 25421 |
case E_CC_NVmode: |
| 25422 |
switch (comp_code) |
| 25423 |
{ |
| 25424 |
case GE: return ARM_GE; |
| 25425 |
case LT: return ARM_LT; |
| 25426 |
default: return ARM_NV; |
| 25427 |
} |
| 25428 |
|
| 25429 |
case E_CC_Bmode: |
| 25430 |
switch (comp_code) |
| 25431 |
{ |
| 25432 |
case GEU: return ARM_CS; |
| 25433 |
case LTU: return ARM_CC; |
| 25434 |
default: return ARM_NV; |
| 25435 |
} |
| 25436 |
|
| 25437 |
case E_CC_Vmode: |
| 25438 |
switch (comp_code) |
| 25439 |
{ |
| 25440 |
case NE: return ARM_VS; |
| 25441 |
case EQ: return ARM_VC; |
| 25442 |
default: return ARM_NV; |
| 25443 |
} |
| 25444 |
|
| 25445 |
case E_CC_ADCmode: |
| 25446 |
switch (comp_code) |
| 25447 |
{ |
| 25448 |
case GEU: return ARM_CS; |
| 25449 |
case LTU: return ARM_CC; |
| 25450 |
default: return ARM_NV; |
| 25451 |
} |
| 25452 |
|
| 25453 |
case E_CCmode: |
| 25454 |
case E_CC_RSBmode: |
| 25455 |
switch (comp_code) |
| 25456 |
{ |
| 25457 |
case NE: return ARM_NE; |
| 25458 |
case EQ: return ARM_EQ; |
| 25459 |
case GE: return ARM_GE; |
| 25460 |
case GT: return ARM_GT; |
| 25461 |
case LE: return ARM_LE; |
| 25462 |
case LT: return ARM_LT; |
| 25463 |
case GEU: return ARM_CS; |
| 25464 |
case GTU: return ARM_HI; |
| 25465 |
case LEU: return ARM_LS; |
| 25466 |
case LTU: return ARM_CC; |
| 25467 |
default: return ARM_NV; |
| 25468 |
} |
| 25469 |
|
| 25470 |
default: gcc_unreachable (); |
| 25471 |
} |
| 25472 |
} |
| 25473 |
|
| 25474 |
/* Like maybe_get_arm_condition_code, but never return ARM_NV. */ |
| 25475 |
static enum arm_cond_code |
| 25476 |
get_arm_condition_code (rtx comparison) |
| 25477 |
{ |
| 25478 |
enum arm_cond_code code = maybe_get_arm_condition_code (comparison); |
| 25479 |
gcc_assert (code != ARM_NV); |
| 25480 |
return code; |
| 25481 |
} |
| 25482 |
|
| 25483 |
/* Implement TARGET_FIXED_CONDITION_CODE_REGS. We only have condition |
| 25484 |
code registers when not targetting Thumb1. The VFP condition register |
| 25485 |
only exists when generating hard-float code. */ |
| 25486 |
static bool |
| 25487 |
arm_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2) |
| 25488 |
{ |
| 25489 |
if (!TARGET_32BIT) |
| 25490 |
return false; |
| 25491 |
|
| 25492 |
*p1 = CC_REGNUM; |
| 25493 |
*p2 = TARGET_VFP_BASE ? VFPCC_REGNUM : INVALID_REGNUM; |
| 25494 |
return true; |
| 25495 |
} |
| 25496 |
|
| 25497 |
/* Tell arm_asm_output_opcode to output IT blocks for conditionally executed |
| 25498 |
instructions. */ |
| 25499 |
void |
| 25500 |
thumb2_final_prescan_insn (rtx_insn *insn) |
| 25501 |
{ |
| 25502 |
rtx_insn *first_insn = insn; |
| 25503 |
rtx body = PATTERN (insn); |
| 25504 |
rtx predicate; |
| 25505 |
enum arm_cond_code code; |
| 25506 |
int n; |
| 25507 |
int mask; |
| 25508 |
int max; |
| 25509 |
|
| 25510 |
/* max_insns_skipped in the tune was already taken into account in the |
| 25511 |
cost model of ifcvt pass when generating COND_EXEC insns. At this stage |
| 25512 |
just emit the IT blocks as we can. It does not make sense to split |
| 25513 |
the IT blocks. */ |
| 25514 |
max = MAX_INSN_PER_IT_BLOCK; |
| 25515 |
|
| 25516 |
/* Remove the previous insn from the count of insns to be output. */ |
| 25517 |
if (arm_condexec_count) |
| 25518 |
arm_condexec_count--; |
| 25519 |
|
| 25520 |
/* Nothing to do if we are already inside a conditional block. */ |
| 25521 |
if (arm_condexec_count) |
| 25522 |
return; |
| 25523 |
|
| 25524 |
if (GET_CODE (body) != COND_EXEC) |
| 25525 |
return; |
| 25526 |
|
| 25527 |
/* Conditional jumps are implemented directly. */ |
| 25528 |
if (JUMP_P (insn)) |
| 25529 |
return; |
| 25530 |
|
| 25531 |
predicate = COND_EXEC_TEST (body); |
| 25532 |
arm_current_cc = get_arm_condition_code (predicate); |
| 25533 |
|
| 25534 |
n = get_attr_ce_count (insn); |
| 25535 |
arm_condexec_count = 1; |
| 25536 |
arm_condexec_mask = (1 << n) - 1; |
| 25537 |
arm_condexec_masklen = n; |
| 25538 |
/* See if subsequent instructions can be combined into the same block. */ |
| 25539 |
for (;;) |
| 25540 |
{ |
| 25541 |
insn = next_nonnote_insn (insn); |
| 25542 |
|
| 25543 |
/* Jumping into the middle of an IT block is illegal, so a label or |
| 25544 |
barrier terminates the block. */ |
| 25545 |
if (!NONJUMP_INSN_P (insn) && !JUMP_P (insn)) |
| 25546 |
break; |
| 25547 |
|
| 25548 |
body = PATTERN (insn); |
| 25549 |
/* USE and CLOBBER aren't really insns, so just skip them. */ |
| 25550 |
if (GET_CODE (body) == USE |
| 25551 |
|| GET_CODE (body) == CLOBBER) |
| 25552 |
continue; |
| 25553 |
|
| 25554 |
/* ??? Recognize conditional jumps, and combine them with IT blocks. */ |
| 25555 |
if (GET_CODE (body) != COND_EXEC) |
| 25556 |
break; |
| 25557 |
/* Maximum number of conditionally executed instructions in a block. */ |
| 25558 |
n = get_attr_ce_count (insn); |
| 25559 |
if (arm_condexec_masklen + n > max) |
| 25560 |
break; |
| 25561 |
|
| 25562 |
predicate = COND_EXEC_TEST (body); |
| 25563 |
code = get_arm_condition_code (predicate); |
| 25564 |
mask = (1 << n) - 1; |
| 25565 |
if (arm_current_cc == code) |
| 25566 |
arm_condexec_mask |= (mask << arm_condexec_masklen); |
| 25567 |
else if (arm_current_cc != ARM_INVERSE_CONDITION_CODE(code)) |
| 25568 |
break; |
| 25569 |
|
| 25570 |
arm_condexec_count++; |
| 25571 |
arm_condexec_masklen += n; |
| 25572 |
|
| 25573 |
/* A jump must be the last instruction in a conditional block. */ |
| 25574 |
if (JUMP_P (insn)) |
| 25575 |
break; |
| 25576 |
} |
| 25577 |
/* Restore recog_data (getting the attributes of other insns can |
| 25578 |
destroy this array, but final.cc assumes that it remains intact |
| 25579 |
across this call). */ |
| 25580 |
extract_constrain_insn_cached (first_insn); |
| 25581 |
} |
| 25582 |
|
| 25583 |
void |
| 25584 |
arm_final_prescan_insn (rtx_insn *insn) |
| 25585 |
{ |
| 25586 |
/* BODY will hold the body of INSN. */ |
| 25587 |
rtx body = PATTERN (insn); |
| 25588 |
|
| 25589 |
/* This will be 1 if trying to repeat the trick, and things need to be |
| 25590 |
reversed if it appears to fail. */ |
| 25591 |
int reverse = 0; |
| 25592 |
|
| 25593 |
/* If we start with a return insn, we only succeed if we find another one. */ |
| 25594 |
int seeking_return = 0; |
| 25595 |
enum rtx_code return_code = UNKNOWN; |
| 25596 |
|
| 25597 |
/* START_INSN will hold the insn from where we start looking. This is the |
| 25598 |
first insn after the following code_label if REVERSE is true. */ |
| 25599 |
rtx_insn *start_insn = insn; |
| 25600 |
|
| 25601 |
/* If in state 4, check if the target branch is reached, in order to |
| 25602 |
change back to state 0. */ |
| 25603 |
if (arm_ccfsm_state == 4) |
| 25604 |
{ |
| 25605 |
if (insn == arm_target_insn) |
| 25606 |
{ |
| 25607 |
arm_target_insn = NULL; |
| 25608 |
arm_ccfsm_state = 0; |
| 25609 |
} |
| 25610 |
return; |
| 25611 |
} |
| 25612 |
|
| 25613 |
/* If in state 3, it is possible to repeat the trick, if this insn is an |
| 25614 |
unconditional branch to a label, and immediately following this branch |
| 25615 |
is the previous target label which is only used once, and the label this |
| 25616 |
branch jumps to is not too far off. */ |
| 25617 |
if (arm_ccfsm_state == 3) |
| 25618 |
{ |
| 25619 |
if (simplejump_p (insn)) |
| 25620 |
{ |
| 25621 |
start_insn = next_nonnote_insn (start_insn); |
| 25622 |
if (BARRIER_P (start_insn)) |
| 25623 |
{ |
| 25624 |
/* XXX Isn't this always a barrier? */ |
| 25625 |
start_insn = next_nonnote_insn (start_insn); |
| 25626 |
} |
| 25627 |
if (LABEL_P (start_insn) |
| 25628 |
&& CODE_LABEL_NUMBER (start_insn) == arm_target_label |
| 25629 |
&& LABEL_NUSES (start_insn) == 1) |
| 25630 |
reverse = TRUE; |
| 25631 |
else |
| 25632 |
return; |
| 25633 |
} |
| 25634 |
else if (ANY_RETURN_P (body)) |
| 25635 |
{ |
| 25636 |
start_insn = next_nonnote_insn (start_insn); |
| 25637 |
if (BARRIER_P (start_insn)) |
| 25638 |
start_insn = next_nonnote_insn (start_insn); |
| 25639 |
if (LABEL_P (start_insn) |
| 25640 |
&& CODE_LABEL_NUMBER (start_insn) == arm_target_label |
| 25641 |
&& LABEL_NUSES (start_insn) == 1) |
| 25642 |
{ |
| 25643 |
reverse = TRUE; |
| 25644 |
seeking_return = 1; |
| 25645 |
return_code = GET_CODE (body); |
| 25646 |
} |
| 25647 |
else |
| 25648 |
return; |
| 25649 |
} |
| 25650 |
else |
| 25651 |
return; |
| 25652 |
} |
| 25653 |
|
| 25654 |
gcc_assert (!arm_ccfsm_state || reverse); |
| 25655 |
if (!JUMP_P (insn)) |
| 25656 |
return; |
| 25657 |
|
| 25658 |
/* This jump might be paralleled with a clobber of the condition codes |
| 25659 |
the jump should always come first */ |
| 25660 |
if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0) |
| 25661 |
body = XVECEXP (body, 0, 0); |
| 25662 |
|
| 25663 |
if (reverse |
| 25664 |
|| (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC |
| 25665 |
&& GET_CODE (SET_SRC (body)) == IF_THEN_ELSE)) |
| 25666 |
{ |
| 25667 |
int insns_skipped; |
| 25668 |
int fail = FALSE, succeed = FALSE; |
| 25669 |
/* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */ |
| 25670 |
int then_not_else = TRUE; |
| 25671 |
rtx_insn *this_insn = start_insn; |
| 25672 |
rtx label = 0; |
| 25673 |
|
| 25674 |
/* Register the insn jumped to. */ |
| 25675 |
if (reverse) |
| 25676 |
{ |
| 25677 |
if (!seeking_return) |
| 25678 |
label = XEXP (SET_SRC (body), 0); |
| 25679 |
} |
| 25680 |
else if (GET_CODE (XEXP (SET_SRC (body), 1)) == LABEL_REF) |
| 25681 |
label = XEXP (XEXP (SET_SRC (body), 1), 0); |
| 25682 |
else if (GET_CODE (XEXP (SET_SRC (body), 2)) == LABEL_REF) |
| 25683 |
{ |
| 25684 |
label = XEXP (XEXP (SET_SRC (body), 2), 0); |
| 25685 |
then_not_else = FALSE; |
| 25686 |
} |
| 25687 |
else if (ANY_RETURN_P (XEXP (SET_SRC (body), 1))) |
| 25688 |
{ |
| 25689 |
seeking_return = 1; |
| 25690 |
return_code = GET_CODE (XEXP (SET_SRC (body), 1)); |
| 25691 |
} |
| 25692 |
else if (ANY_RETURN_P (XEXP (SET_SRC (body), 2))) |
| 25693 |
{ |
| 25694 |
seeking_return = 1; |
| 25695 |
return_code = GET_CODE (XEXP (SET_SRC (body), 2)); |
| 25696 |
then_not_else = FALSE; |
| 25697 |
} |
| 25698 |
else |
| 25699 |
gcc_unreachable (); |
| 25700 |
|
| 25701 |
/* See how many insns this branch skips, and what kind of insns. If all |
| 25702 |
insns are okay, and the label or unconditional branch to the same |
| 25703 |
label is not too far away, succeed. */ |
| 25704 |
for (insns_skipped = 0; |
| 25705 |
!fail && !succeed && insns_skipped++ < max_insns_skipped;) |
| 25706 |
{ |
| 25707 |
rtx scanbody; |
| 25708 |
|
| 25709 |
this_insn = next_nonnote_insn (this_insn); |
| 25710 |
if (!this_insn) |
| 25711 |
break; |
| 25712 |
|
| 25713 |
switch (GET_CODE (this_insn)) |
| 25714 |
{ |
| 25715 |
case CODE_LABEL: |
| 25716 |
/* Succeed if it is the target label, otherwise fail since |
| 25717 |
control falls in from somewhere else. */ |
| 25718 |
if (this_insn == label) |
| 25719 |
{ |
| 25720 |
arm_ccfsm_state = 1; |
| 25721 |
succeed = TRUE; |
| 25722 |
} |
| 25723 |
else |
| 25724 |
fail = TRUE; |
| 25725 |
break; |
| 25726 |
|
| 25727 |
case BARRIER: |
| 25728 |
/* Succeed if the following insn is the target label. |
| 25729 |
Otherwise fail. |
| 25730 |
If return insns are used then the last insn in a function |
| 25731 |
will be a barrier. */ |
| 25732 |
this_insn = next_nonnote_insn (this_insn); |
| 25733 |
if (this_insn && this_insn == label) |
| 25734 |
{ |
| 25735 |
arm_ccfsm_state = 1; |
| 25736 |
succeed = TRUE; |
| 25737 |
} |
| 25738 |
else |
| 25739 |
fail = TRUE; |
| 25740 |
break; |
| 25741 |
|
| 25742 |
case CALL_INSN: |
| 25743 |
/* The AAPCS says that conditional calls should not be |
| 25744 |
used since they make interworking inefficient (the |
| 25745 |
linker can't transform BL<cond> into BLX). That's |
| 25746 |
only a problem if the machine has BLX. */ |
| 25747 |
if (arm_arch5t) |
| 25748 |
{ |
| 25749 |
fail = TRUE; |
| 25750 |
break; |
| 25751 |
} |
| 25752 |
|
| 25753 |
/* Succeed if the following insn is the target label, or |
| 25754 |
if the following two insns are a barrier and the |
| 25755 |
target label. */ |
| 25756 |
this_insn = next_nonnote_insn (this_insn); |
| 25757 |
if (this_insn && BARRIER_P (this_insn)) |
| 25758 |
this_insn = next_nonnote_insn (this_insn); |
| 25759 |
|
| 25760 |
if (this_insn && this_insn == label |
| 25761 |
&& insns_skipped < max_insns_skipped) |
| 25762 |
{ |
| 25763 |
arm_ccfsm_state = 1; |
| 25764 |
succeed = TRUE; |
| 25765 |
} |
| 25766 |
else |
| 25767 |
fail = TRUE; |
| 25768 |
break; |
| 25769 |
|
| 25770 |
case JUMP_INSN: |
| 25771 |
/* If this is an unconditional branch to the same label, succeed. |
| 25772 |
If it is to another label, do nothing. If it is conditional, |
| 25773 |
fail. */ |
| 25774 |
/* XXX Probably, the tests for SET and the PC are |
| 25775 |
unnecessary. */ |
| 25776 |
|
| 25777 |
scanbody = PATTERN (this_insn); |
| 25778 |
if (GET_CODE (scanbody) == SET |
| 25779 |
&& GET_CODE (SET_DEST (scanbody)) == PC) |
| 25780 |
{ |
| 25781 |
if (GET_CODE (SET_SRC (scanbody)) == LABEL_REF |
| 25782 |
&& XEXP (SET_SRC (scanbody), 0) == label && !reverse) |
| 25783 |
{ |
| 25784 |
arm_ccfsm_state = 2; |
| 25785 |
succeed = TRUE; |
| 25786 |
} |
| 25787 |
else if (GET_CODE (SET_SRC (scanbody)) == IF_THEN_ELSE) |
| 25788 |
fail = TRUE; |
| 25789 |
} |
| 25790 |
/* Fail if a conditional return is undesirable (e.g. on a |
| 25791 |
StrongARM), but still allow this if optimizing for size. */ |
| 25792 |
else if (GET_CODE (scanbody) == return_code |
| 25793 |
&& !use_return_insn (TRUE, NULL) |
| 25794 |
&& !optimize_size) |
| 25795 |
fail = TRUE; |
| 25796 |
else if (GET_CODE (scanbody) == return_code) |
| 25797 |
{ |
| 25798 |
arm_ccfsm_state = 2; |
| 25799 |
succeed = TRUE; |
| 25800 |
} |
| 25801 |
else if (GET_CODE (scanbody) == PARALLEL) |
| 25802 |
{ |
| 25803 |
switch (get_attr_conds (this_insn)) |
| 25804 |
{ |
| 25805 |
case CONDS_NOCOND: |
| 25806 |
break; |
| 25807 |
default: |
| 25808 |
fail = TRUE; |
| 25809 |
break; |
| 25810 |
} |
| 25811 |
} |
| 25812 |
else |
| 25813 |
fail = TRUE; /* Unrecognized jump (e.g. epilogue). */ |
| 25814 |
|
| 25815 |
break; |
| 25816 |
|
| 25817 |
case INSN: |
| 25818 |
/* Check the instruction is explicitly marked as predicable. |
| 25819 |
Instructions using or affecting the condition codes are not. */ |
| 25820 |
scanbody = PATTERN (this_insn); |
| 25821 |
if (!(GET_CODE (scanbody) == SET |
| 25822 |
|| GET_CODE (scanbody) == PARALLEL) |
| 25823 |
|| get_attr_predicable (this_insn) != PREDICABLE_YES |
| 25824 |
|| get_attr_conds (this_insn) != CONDS_NOCOND) |
| 25825 |
fail = TRUE; |
| 25826 |
break; |
| 25827 |
|
| 25828 |
default: |
| 25829 |
break; |
| 25830 |
} |
| 25831 |
} |
| 25832 |
if (succeed) |
| 25833 |
{ |
| 25834 |
if ((!seeking_return) && (arm_ccfsm_state == 1 || reverse)) |
| 25835 |
arm_target_label = CODE_LABEL_NUMBER (label); |
| 25836 |
else |
| 25837 |
{ |
| 25838 |
gcc_assert (seeking_return || arm_ccfsm_state == 2); |
| 25839 |
|
| 25840 |
while (this_insn && GET_CODE (PATTERN (this_insn)) == USE) |
| 25841 |
{ |
| 25842 |
this_insn = next_nonnote_insn (this_insn); |
| 25843 |
gcc_assert (!this_insn |
| 25844 |
|| (!BARRIER_P (this_insn) |
| 25845 |
&& !LABEL_P (this_insn))); |
| 25846 |
} |
| 25847 |
if (!this_insn) |
| 25848 |
{ |
| 25849 |
/* Oh, dear! we ran off the end.. give up. */ |
| 25850 |
extract_constrain_insn_cached (insn); |
| 25851 |
arm_ccfsm_state = 0; |
| 25852 |
arm_target_insn = NULL; |
| 25853 |
return; |
| 25854 |
} |
| 25855 |
arm_target_insn = this_insn; |
| 25856 |
} |
| 25857 |
|
| 25858 |
/* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from |
| 25859 |
what it was. */ |
| 25860 |
if (!reverse) |
| 25861 |
arm_current_cc = get_arm_condition_code (XEXP (SET_SRC (body), 0)); |
| 25862 |
|
| 25863 |
if (reverse || then_not_else) |
| 25864 |
arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc); |
| 25865 |
} |
| 25866 |
|
| 25867 |
/* Restore recog_data (getting the attributes of other insns can |
| 25868 |
destroy this array, but final.cc assumes that it remains intact |
| 25869 |
across this call. */ |
| 25870 |
extract_constrain_insn_cached (insn); |
| 25871 |
} |
| 25872 |
} |
| 25873 |
|
| 25874 |
/* Output IT instructions. */ |
| 25875 |
void |
| 25876 |
thumb2_asm_output_opcode (FILE * stream) |
| 25877 |
{ |
| 25878 |
char buff[5]; |
| 25879 |
int n; |
| 25880 |
|
| 25881 |
if (arm_condexec_mask) |
| 25882 |
{ |
| 25883 |
for (n = 0; n < arm_condexec_masklen; n++) |
| 25884 |
buff[n] = (arm_condexec_mask & (1 << n)) ? 't' : 'e'; |
| 25885 |
buff[n] = 0; |
| 25886 |
asm_fprintf(stream, "i%s\t%s\n\t", buff, |
| 25887 |
arm_condition_codes[arm_current_cc]); |
| 25888 |
arm_condexec_mask = 0; |
| 25889 |
} |
| 25890 |
} |
| 25891 |
|
| 25892 |
/* Implement TARGET_HARD_REGNO_NREGS. On the ARM core regs are |
| 25893 |
UNITS_PER_WORD bytes wide. */ |
| 25894 |
static unsigned int |
| 25895 |
arm_hard_regno_nregs (unsigned int regno, machine_mode mode) |
| 25896 |
{ |
| 25897 |
if (IS_VPR_REGNUM (regno)) |
| 25898 |
return CEIL (GET_MODE_SIZE (mode), 2); |
| 25899 |
|
| 25900 |
if (TARGET_32BIT |
| 25901 |
&& regno > PC_REGNUM |
| 25902 |
&& regno != FRAME_POINTER_REGNUM |
| 25903 |
&& regno != ARG_POINTER_REGNUM |
| 25904 |
&& !IS_VFP_REGNUM (regno)) |
| 25905 |
return 1; |
| 25906 |
|
| 25907 |
return ARM_NUM_REGS (mode); |
| 25908 |
} |
| 25909 |
|
| 25910 |
/* Implement TARGET_HARD_REGNO_MODE_OK. */ |
| 25911 |
static bool |
| 25912 |
arm_hard_regno_mode_ok (unsigned int regno, machine_mode mode) |
| 25913 |
{ |
| 25914 |
if (GET_MODE_CLASS (mode) == MODE_CC) |
| 25915 |
return (regno == CC_REGNUM |
| 25916 |
|| (TARGET_VFP_BASE |
| 25917 |
&& regno == VFPCC_REGNUM)); |
| 25918 |
|
| 25919 |
if (regno == CC_REGNUM && GET_MODE_CLASS (mode) != MODE_CC) |
| 25920 |
return false; |
| 25921 |
|
| 25922 |
if (IS_VPR_REGNUM (regno)) |
| 25923 |
return VALID_MVE_PRED_MODE (mode); |
| 25924 |
|
| 25925 |
if (TARGET_THUMB1) |
| 25926 |
/* For the Thumb we only allow values bigger than SImode in |
| 25927 |
registers 0 - 6, so that there is always a second low |
| 25928 |
register available to hold the upper part of the value. |
| 25929 |
We probably we ought to ensure that the register is the |
| 25930 |
start of an even numbered register pair. */ |
| 25931 |
return (ARM_NUM_REGS (mode) < 2) || (regno < LAST_LO_REGNUM); |
| 25932 |
|
| 25933 |
if (TARGET_VFP_BASE && IS_VFP_REGNUM (regno)) |
| 25934 |
{ |
| 25935 |
if (mode == DFmode || mode == DImode) |
| 25936 |
return VFP_REGNO_OK_FOR_DOUBLE (regno); |
| 25937 |
|
| 25938 |
if (mode == HFmode || mode == BFmode || mode == HImode |
| 25939 |
|| mode == SFmode || mode == SImode) |
| 25940 |
return VFP_REGNO_OK_FOR_SINGLE (regno); |
| 25941 |
|
| 25942 |
if (TARGET_NEON) |
| 25943 |
return (VALID_NEON_DREG_MODE (mode) && VFP_REGNO_OK_FOR_DOUBLE (regno)) |
| 25944 |
|| (VALID_NEON_QREG_MODE (mode) |
| 25945 |
&& NEON_REGNO_OK_FOR_QUAD (regno)) |
| 25946 |
|| (mode == TImode && NEON_REGNO_OK_FOR_NREGS (regno, 2)) |
| 25947 |
|| (mode == EImode && NEON_REGNO_OK_FOR_NREGS (regno, 3)) |
| 25948 |
|| (mode == OImode && NEON_REGNO_OK_FOR_NREGS (regno, 4)) |
| 25949 |
|| (mode == CImode && NEON_REGNO_OK_FOR_NREGS (regno, 6)) |
| 25950 |
|| (mode == XImode && NEON_REGNO_OK_FOR_NREGS (regno, 8)); |
| 25951 |
if (TARGET_HAVE_MVE) |
| 25952 |
return ((VALID_MVE_MODE (mode) && NEON_REGNO_OK_FOR_QUAD (regno)) |
| 25953 |
|| (mode == OImode && NEON_REGNO_OK_FOR_NREGS (regno, 4)) |
| 25954 |
|| (mode == V2x16QImode && NEON_REGNO_OK_FOR_NREGS (regno, 4)) |
| 25955 |
|| (mode == V2x8HImode && NEON_REGNO_OK_FOR_NREGS (regno, 4)) |
| 25956 |
|| (mode == V2x4SImode && NEON_REGNO_OK_FOR_NREGS (regno, 4)) |
| 25957 |
|| (mode == V2x8HFmode && NEON_REGNO_OK_FOR_NREGS (regno, 4)) |
| 25958 |
|| (mode == V2x4SFmode && NEON_REGNO_OK_FOR_NREGS (regno, 4)) |
| 25959 |
|| (mode == XImode && NEON_REGNO_OK_FOR_NREGS (regno, 8)) |
| 25960 |
|| (mode == V4x16QImode && NEON_REGNO_OK_FOR_NREGS (regno, 8)) |
| 25961 |
|| (mode == V4x8HImode && NEON_REGNO_OK_FOR_NREGS (regno, 8)) |
| 25962 |
|| (mode == V4x4SImode && NEON_REGNO_OK_FOR_NREGS (regno, 8)) |
| 25963 |
|| (mode == V4x8HFmode && NEON_REGNO_OK_FOR_NREGS (regno, 8)) |
| 25964 |
|| (mode == V4x4SFmode && NEON_REGNO_OK_FOR_NREGS (regno, 8))); |
| 25965 |
|
| 25966 |
return false; |
| 25967 |
} |
| 25968 |
|
| 25969 |
if (TARGET_REALLY_IWMMXT) |
| 25970 |
{ |
| 25971 |
if (IS_IWMMXT_GR_REGNUM (regno)) |
| 25972 |
return mode == SImode; |
| 25973 |
|
| 25974 |
if (IS_IWMMXT_REGNUM (regno)) |
| 25975 |
return VALID_IWMMXT_REG_MODE (mode); |
| 25976 |
} |
| 25977 |
|
| 25978 |
/* We allow almost any value to be stored in the general registers. |
| 25979 |
Restrict doubleword quantities to even register pairs in ARM state |
| 25980 |
so that we can use ldrd. The same restriction applies for MVE |
| 25981 |
in order to support Armv8.1-M Mainline instructions. |
| 25982 |
Do not allow very large Neon structure opaque modes in general |
| 25983 |
registers; they would use too many. */ |
| 25984 |
if (regno <= LAST_ARM_REGNUM) |
| 25985 |
{ |
| 25986 |
if (ARM_NUM_REGS (mode) > 4) |
| 25987 |
return false; |
| 25988 |
|
| 25989 |
if (TARGET_THUMB2 && !(TARGET_HAVE_MVE || TARGET_CDE)) |
| 25990 |
return true; |
| 25991 |
|
| 25992 |
return !((TARGET_LDRD || TARGET_CDE) |
| 25993 |
&& GET_MODE_SIZE (mode) > 4 && (regno & 1) != 0); |
| 25994 |
} |
| 25995 |
|
| 25996 |
if (regno == FRAME_POINTER_REGNUM |
| 25997 |
|| regno == ARG_POINTER_REGNUM) |
| 25998 |
/* We only allow integers in the fake hard registers. */ |
| 25999 |
return GET_MODE_CLASS (mode) == MODE_INT; |
| 26000 |
|
| 26001 |
return false; |
| 26002 |
} |
| 26003 |
|
| 26004 |
/* Implement TARGET_MODES_TIEABLE_P. */ |
| 26005 |
|
| 26006 |
static bool |
| 26007 |
arm_modes_tieable_p (machine_mode mode1, machine_mode mode2) |
| 26008 |
{ |
| 26009 |
if (GET_MODE_CLASS (mode1) == GET_MODE_CLASS (mode2)) |
| 26010 |
return true; |
| 26011 |
|
| 26012 |
if (TARGET_HAVE_MVE |
| 26013 |
&& (VALID_MVE_PRED_MODE (mode1) && VALID_MVE_PRED_MODE (mode2))) |
| 26014 |
return true; |
| 26015 |
|
| 26016 |
/* We specifically want to allow elements of "structure" modes to |
| 26017 |
be tieable to the structure. This more general condition allows |
| 26018 |
other rarer situations too. */ |
| 26019 |
if ((TARGET_NEON |
| 26020 |
&& (VALID_NEON_DREG_MODE (mode1) |
| 26021 |
|| VALID_NEON_QREG_MODE (mode1) |
| 26022 |
|| VALID_NEON_STRUCT_MODE (mode1)) |
| 26023 |
&& (VALID_NEON_DREG_MODE (mode2) |
| 26024 |
|| VALID_NEON_QREG_MODE (mode2) |
| 26025 |
|| VALID_NEON_STRUCT_MODE (mode2))) |
| 26026 |
|| (TARGET_HAVE_MVE |
| 26027 |
&& (VALID_MVE_MODE (mode1) |
| 26028 |
|| VALID_MVE_STRUCT_MODE (mode1)) |
| 26029 |
&& (VALID_MVE_MODE (mode2) |
| 26030 |
|| VALID_MVE_STRUCT_MODE (mode2)))) |
| 26031 |
return true; |
| 26032 |
|
| 26033 |
return false; |
| 26034 |
} |
| 26035 |
|
| 26036 |
/* For efficiency and historical reasons LO_REGS, HI_REGS and CC_REGS are |
| 26037 |
not used in arm mode. */ |
| 26038 |
|
| 26039 |
enum reg_class |
| 26040 |
arm_regno_class (int regno) |
| 26041 |
{ |
| 26042 |
if (regno == PC_REGNUM) |
| 26043 |
return NO_REGS; |
| 26044 |
|
| 26045 |
if (IS_VPR_REGNUM (regno)) |
| 26046 |
return VPR_REG; |
| 26047 |
|
| 26048 |
if (IS_PAC_REGNUM (regno)) |
| 26049 |
return PAC_REG; |
| 26050 |
|
| 26051 |
if (TARGET_THUMB1) |
| 26052 |
{ |
| 26053 |
if (regno == STACK_POINTER_REGNUM) |
| 26054 |
return STACK_REG; |
| 26055 |
if (regno == CC_REGNUM) |
| 26056 |
return CC_REG; |
| 26057 |
if (regno < 8) |
| 26058 |
return LO_REGS; |
| 26059 |
return HI_REGS; |
| 26060 |
} |
| 26061 |
|
| 26062 |
if (TARGET_THUMB2 && regno < 8) |
| 26063 |
return LO_REGS; |
| 26064 |
|
| 26065 |
if ( regno <= LAST_ARM_REGNUM |
| 26066 |
|| regno == FRAME_POINTER_REGNUM |
| 26067 |
|| regno == ARG_POINTER_REGNUM) |
| 26068 |
return TARGET_THUMB2 ? HI_REGS : GENERAL_REGS; |
| 26069 |
|
| 26070 |
if (regno == CC_REGNUM || regno == VFPCC_REGNUM) |
| 26071 |
return TARGET_THUMB2 ? CC_REG : NO_REGS; |
| 26072 |
|
| 26073 |
if (IS_VFP_REGNUM (regno)) |
| 26074 |
{ |
| 26075 |
if (regno <= D7_VFP_REGNUM) |
| 26076 |
return VFP_D0_D7_REGS; |
| 26077 |
else if (regno <= LAST_LO_VFP_REGNUM) |
| 26078 |
return VFP_LO_REGS; |
| 26079 |
else |
| 26080 |
return VFP_HI_REGS; |
| 26081 |
} |
| 26082 |
|
| 26083 |
if (IS_IWMMXT_REGNUM (regno)) |
| 26084 |
return IWMMXT_REGS; |
| 26085 |
|
| 26086 |
if (IS_IWMMXT_GR_REGNUM (regno)) |
| 26087 |
return IWMMXT_GR_REGS; |
| 26088 |
|
| 26089 |
return NO_REGS; |
| 26090 |
} |
| 26091 |
|
| 26092 |
/* Handle a special case when computing the offset |
| 26093 |
of an argument from the frame pointer. */ |
| 26094 |
int |
| 26095 |
arm_debugger_arg_offset (int value, rtx addr) |
| 26096 |
{ |
| 26097 |
rtx_insn *insn; |
| 26098 |
|
| 26099 |
/* We are only interested if dbxout_parms() failed to compute the offset. */ |
| 26100 |
if (value != 0) |
| 26101 |
return 0; |
| 26102 |
|
| 26103 |
/* We can only cope with the case where the address is held in a register. */ |
| 26104 |
if (!REG_P (addr)) |
| 26105 |
return 0; |
| 26106 |
|
| 26107 |
/* If we are using the frame pointer to point at the argument, then |
| 26108 |
an offset of 0 is correct. */ |
| 26109 |
if (REGNO (addr) == (unsigned) HARD_FRAME_POINTER_REGNUM) |
| 26110 |
return 0; |
| 26111 |
|
| 26112 |
/* If we are using the stack pointer to point at the |
| 26113 |
argument, then an offset of 0 is correct. */ |
| 26114 |
/* ??? Check this is consistent with thumb2 frame layout. */ |
| 26115 |
if ((TARGET_THUMB || !frame_pointer_needed) |
| 26116 |
&& REGNO (addr) == SP_REGNUM) |
| 26117 |
return 0; |
| 26118 |
|
| 26119 |
/* Oh dear. The argument is pointed to by a register rather |
| 26120 |
than being held in a register, or being stored at a known |
| 26121 |
offset from the frame pointer. Since GDB only understands |
| 26122 |
those two kinds of argument we must translate the address |
| 26123 |
held in the register into an offset from the frame pointer. |
| 26124 |
We do this by searching through the insns for the function |
| 26125 |
looking to see where this register gets its value. If the |
| 26126 |
register is initialized from the frame pointer plus an offset |
| 26127 |
then we are in luck and we can continue, otherwise we give up. |
| 26128 |
|
| 26129 |
This code is exercised by producing debugging information |
| 26130 |
for a function with arguments like this: |
| 26131 |
|
| 26132 |
double func (double a, double b, int c, double d) {return d;} |
| 26133 |
|
| 26134 |
Without this code the stab for parameter 'd' will be set to |
| 26135 |
an offset of 0 from the frame pointer, rather than 8. */ |
| 26136 |
|
| 26137 |
/* The if() statement says: |
| 26138 |
|
| 26139 |
If the insn is a normal instruction |
| 26140 |
and if the insn is setting the value in a register |
| 26141 |
and if the register being set is the register holding the address of the argument |
| 26142 |
and if the address is computing by an addition |
| 26143 |
that involves adding to a register |
| 26144 |
which is the frame pointer |
| 26145 |
a constant integer |
| 26146 |
|
| 26147 |
then... */ |
| 26148 |
|
| 26149 |
for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
| 26150 |
{ |
| 26151 |
if ( NONJUMP_INSN_P (insn) |
| 26152 |
&& GET_CODE (PATTERN (insn)) == SET |
| 26153 |
&& REGNO (XEXP (PATTERN (insn), 0)) == REGNO (addr) |
| 26154 |
&& GET_CODE (XEXP (PATTERN (insn), 1)) == PLUS |
| 26155 |
&& REG_P (XEXP (XEXP (PATTERN (insn), 1), 0)) |
| 26156 |
&& REGNO (XEXP (XEXP (PATTERN (insn), 1), 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM |
| 26157 |
&& CONST_INT_P (XEXP (XEXP (PATTERN (insn), 1), 1)) |
| 26158 |
) |
| 26159 |
{ |
| 26160 |
value = INTVAL (XEXP (XEXP (PATTERN (insn), 1), 1)); |
| 26161 |
|
| 26162 |
break; |
| 26163 |
} |
| 26164 |
} |
| 26165 |
|
| 26166 |
if (value == 0) |
| 26167 |
{ |
| 26168 |
debug_rtx (addr); |
| 26169 |
warning (0, "unable to compute real location of stacked parameter"); |
| 26170 |
value = 8; /* XXX magic hack */ |
| 26171 |
} |
| 26172 |
|
| 26173 |
return value; |
| 26174 |
} |
| 26175 |
|
| 26176 |
/* Implement TARGET_PROMOTED_TYPE. */ |
| 26177 |
|
| 26178 |
static tree |
| 26179 |
arm_promoted_type (const_tree t) |
| 26180 |
{ |
| 26181 |
if (SCALAR_FLOAT_TYPE_P (t) |
| 26182 |
&& TYPE_PRECISION (t) == 16 |
| 26183 |
&& TYPE_MAIN_VARIANT (t) == arm_fp16_type_node) |
| 26184 |
return float_type_node; |
| 26185 |
return NULL_TREE; |
| 26186 |
} |
| 26187 |
|
| 26188 |
/* Implement TARGET_SCALAR_MODE_SUPPORTED_P. |
| 26189 |
This simply adds HFmode as a supported mode; even though we don't |
| 26190 |
implement arithmetic on this type directly, it's supported by |
| 26191 |
optabs conversions, much the way the double-word arithmetic is |
| 26192 |
special-cased in the default hook. */ |
| 26193 |
|
| 26194 |
static bool |
| 26195 |
arm_scalar_mode_supported_p (scalar_mode mode) |
| 26196 |
{ |
| 26197 |
if (mode == HFmode) |
| 26198 |
return (arm_fp16_format != ARM_FP16_FORMAT_NONE); |
| 26199 |
else if (ALL_FIXED_POINT_MODE_P (mode)) |
| 26200 |
return true; |
| 26201 |
else |
| 26202 |
return default_scalar_mode_supported_p (mode); |
| 26203 |
} |
| 26204 |
|
| 26205 |
/* Set the value of FLT_EVAL_METHOD. |
| 26206 |
ISO/IEC TS 18661-3 defines two values that we'd like to make use of: |
| 26207 |
|
| 26208 |
0: evaluate all operations and constants, whose semantic type has at |
| 26209 |
most the range and precision of type float, to the range and |
| 26210 |
precision of float; evaluate all other operations and constants to |
| 26211 |
the range and precision of the semantic type; |
| 26212 |
|
| 26213 |
N, where _FloatN is a supported interchange floating type |
| 26214 |
evaluate all operations and constants, whose semantic type has at |
| 26215 |
most the range and precision of _FloatN type, to the range and |
| 26216 |
precision of the _FloatN type; evaluate all other operations and |
| 26217 |
constants to the range and precision of the semantic type; |
| 26218 |
|
| 26219 |
If we have the ARMv8.2-A extensions then we support _Float16 in native |
| 26220 |
precision, so we should set this to 16. Otherwise, we support the type, |
| 26221 |
but want to evaluate expressions in float precision, so set this to |
| 26222 |
0. */ |
| 26223 |
|
| 26224 |
static enum flt_eval_method |
| 26225 |
arm_excess_precision (enum excess_precision_type type) |
| 26226 |
{ |
| 26227 |
switch (type) |
| 26228 |
{ |
| 26229 |
case EXCESS_PRECISION_TYPE_FAST: |
| 26230 |
case EXCESS_PRECISION_TYPE_STANDARD: |
| 26231 |
/* We can calculate either in 16-bit range and precision or |
| 26232 |
32-bit range and precision. Make that decision based on whether |
| 26233 |
we have native support for the ARMv8.2-A 16-bit floating-point |
| 26234 |
instructions or not. */ |
| 26235 |
return (TARGET_VFP_FP16INST |
| 26236 |
? FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 |
| 26237 |
: FLT_EVAL_METHOD_PROMOTE_TO_FLOAT); |
| 26238 |
case EXCESS_PRECISION_TYPE_IMPLICIT: |
| 26239 |
case EXCESS_PRECISION_TYPE_FLOAT16: |
| 26240 |
return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16; |
| 26241 |
default: |
| 26242 |
gcc_unreachable (); |
| 26243 |
} |
| 26244 |
return FLT_EVAL_METHOD_UNPREDICTABLE; |
| 26245 |
} |
| 26246 |
|
| 26247 |
|
| 26248 |
/* Implement TARGET_FLOATN_MODE. Make very sure that we don't provide |
| 26249 |
_Float16 if we are using anything other than ieee format for 16-bit |
| 26250 |
floating point. Otherwise, punt to the default implementation. */ |
| 26251 |
static opt_scalar_float_mode |
| 26252 |
arm_floatn_mode (int n, bool extended) |
| 26253 |
{ |
| 26254 |
if (!extended && n == 16) |
| 26255 |
{ |
| 26256 |
if (arm_fp16_format == ARM_FP16_FORMAT_IEEE) |
| 26257 |
return HFmode; |
| 26258 |
return opt_scalar_float_mode (); |
| 26259 |
} |
| 26260 |
|
| 26261 |
return default_floatn_mode (n, extended); |
| 26262 |
} |
| 26263 |
|
| 26264 |
|
| 26265 |
/* Set up OPERANDS for a register copy from SRC to DEST, taking care |
| 26266 |
not to early-clobber SRC registers in the process. |
| 26267 |
|
| 26268 |
We assume that the operands described by SRC and DEST represent a |
| 26269 |
decomposed copy of OPERANDS[1] into OPERANDS[0]. COUNT is the |
| 26270 |
number of components into which the copy has been decomposed. */ |
| 26271 |
void |
| 26272 |
neon_disambiguate_copy (rtx *operands, rtx *dest, rtx *src, unsigned int count) |
| 26273 |
{ |
| 26274 |
unsigned int i; |
| 26275 |
|
| 26276 |
if (!reg_overlap_mentioned_p (operands[0], operands[1]) |
| 26277 |
|| REGNO (operands[0]) < REGNO (operands[1])) |
| 26278 |
{ |
| 26279 |
for (i = 0; i < count; i++) |
| 26280 |
{ |
| 26281 |
operands[2 * i] = dest[i]; |
| 26282 |
operands[2 * i + 1] = src[i]; |
| 26283 |
} |
| 26284 |
} |
| 26285 |
else |
| 26286 |
{ |
| 26287 |
for (i = 0; i < count; i++) |
| 26288 |
{ |
| 26289 |
operands[2 * i] = dest[count - i - 1]; |
| 26290 |
operands[2 * i + 1] = src[count - i - 1]; |
| 26291 |
} |
| 26292 |
} |
| 26293 |
} |
| 26294 |
|
| 26295 |
/* Split operands into moves from op[1] + op[2] into op[0]. */ |
| 26296 |
|
| 26297 |
void |
| 26298 |
neon_split_vcombine (rtx operands[3]) |
| 26299 |
{ |
| 26300 |
unsigned int dest = REGNO (operands[0]); |
| 26301 |
unsigned int src1 = REGNO (operands[1]); |
| 26302 |
unsigned int src2 = REGNO (operands[2]); |
| 26303 |
machine_mode halfmode = GET_MODE (operands[1]); |
| 26304 |
unsigned int halfregs = REG_NREGS (operands[1]); |
| 26305 |
rtx destlo, desthi; |
| 26306 |
|
| 26307 |
if (src1 == dest && src2 == dest + halfregs) |
| 26308 |
{ |
| 26309 |
/* No-op move. Can't split to nothing; emit something. */ |
| 26310 |
emit_note (NOTE_INSN_DELETED); |
| 26311 |
return; |
| 26312 |
} |
| 26313 |
|
| 26314 |
/* Preserve register attributes for variable tracking. */ |
| 26315 |
destlo = gen_rtx_REG_offset (operands[0], halfmode, dest, 0); |
| 26316 |
desthi = gen_rtx_REG_offset (operands[0], halfmode, dest + halfregs, |
| 26317 |
GET_MODE_SIZE (halfmode)); |
| 26318 |
|
| 26319 |
/* Special case of reversed high/low parts. Use VSWP. */ |
| 26320 |
if (src2 == dest && src1 == dest + halfregs) |
| 26321 |
{ |
| 26322 |
rtx x = gen_rtx_SET (destlo, operands[1]); |
| 26323 |
rtx y = gen_rtx_SET (desthi, operands[2]); |
| 26324 |
emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, x, y))); |
| 26325 |
return; |
| 26326 |
} |
| 26327 |
|
| 26328 |
if (!reg_overlap_mentioned_p (operands[2], destlo)) |
| 26329 |
{ |
| 26330 |
/* Try to avoid unnecessary moves if part of the result |
| 26331 |
is in the right place already. */ |
| 26332 |
if (src1 != dest) |
| 26333 |
emit_move_insn (destlo, operands[1]); |
| 26334 |
if (src2 != dest + halfregs) |
| 26335 |
emit_move_insn (desthi, operands[2]); |
| 26336 |
} |
| 26337 |
else |
| 26338 |
{ |
| 26339 |
if (src2 != dest + halfregs) |
| 26340 |
emit_move_insn (desthi, operands[2]); |
| 26341 |
if (src1 != dest) |
| 26342 |
emit_move_insn (destlo, operands[1]); |
| 26343 |
} |
| 26344 |
} |
| 26345 |
|
| 26346 |
/* Return the number (counting from 0) of |
| 26347 |
the least significant set bit in MASK. */ |
| 26348 |
|
| 26349 |
inline static int |
| 26350 |
number_of_first_bit_set (unsigned mask) |
| 26351 |
{ |
| 26352 |
return ctz_hwi (mask); |
| 26353 |
} |
| 26354 |
|
| 26355 |
/* Like emit_multi_reg_push, but allowing for a different set of |
| 26356 |
registers to be described as saved. MASK is the set of registers |
| 26357 |
to be saved; REAL_REGS is the set of registers to be described as |
| 26358 |
saved. If REAL_REGS is 0, only describe the stack adjustment. */ |
| 26359 |
|
| 26360 |
static rtx_insn * |
| 26361 |
thumb1_emit_multi_reg_push (unsigned long mask, unsigned long real_regs) |
| 26362 |
{ |
| 26363 |
unsigned long regno; |
| 26364 |
rtx par[10], tmp, reg; |
| 26365 |
rtx_insn *insn; |
| 26366 |
int i, j; |
| 26367 |
|
| 26368 |
/* Build the parallel of the registers actually being stored. */ |
| 26369 |
for (i = 0; mask; ++i, mask &= mask - 1) |
| 26370 |
{ |
| 26371 |
regno = ctz_hwi (mask); |
| 26372 |
reg = gen_rtx_REG (SImode, regno); |
| 26373 |
|
| 26374 |
if (i == 0) |
| 26375 |
tmp = gen_rtx_UNSPEC (BLKmode, gen_rtvec (1, reg), UNSPEC_PUSH_MULT); |
| 26376 |
else |
| 26377 |
tmp = gen_rtx_USE (VOIDmode, reg); |
| 26378 |
|
| 26379 |
par[i] = tmp; |
| 26380 |
} |
| 26381 |
|
| 26382 |
tmp = plus_constant (Pmode, stack_pointer_rtx, -4 * i); |
| 26383 |
tmp = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, tmp); |
| 26384 |
tmp = gen_frame_mem (BLKmode, tmp); |
| 26385 |
tmp = gen_rtx_SET (tmp, par[0]); |
| 26386 |
par[0] = tmp; |
| 26387 |
|
| 26388 |
tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (i, par)); |
| 26389 |
insn = emit_insn (tmp); |
| 26390 |
|
| 26391 |
/* Always build the stack adjustment note for unwind info. */ |
| 26392 |
tmp = plus_constant (Pmode, stack_pointer_rtx, -4 * i); |
| 26393 |
tmp = gen_rtx_SET (stack_pointer_rtx, tmp); |
| 26394 |
par[0] = tmp; |
| 26395 |
|
| 26396 |
/* Build the parallel of the registers recorded as saved for unwind. */ |
| 26397 |
for (j = 0; real_regs; ++j, real_regs &= real_regs - 1) |
| 26398 |
{ |
| 26399 |
regno = ctz_hwi (real_regs); |
| 26400 |
reg = gen_rtx_REG (SImode, regno); |
| 26401 |
|
| 26402 |
tmp = plus_constant (Pmode, stack_pointer_rtx, j * 4); |
| 26403 |
tmp = gen_frame_mem (SImode, tmp); |
| 26404 |
tmp = gen_rtx_SET (tmp, reg); |
| 26405 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 26406 |
par[j + 1] = tmp; |
| 26407 |
} |
| 26408 |
|
| 26409 |
if (j == 0) |
| 26410 |
tmp = par[0]; |
| 26411 |
else |
| 26412 |
{ |
| 26413 |
RTX_FRAME_RELATED_P (par[0]) = 1; |
| 26414 |
tmp = gen_rtx_SEQUENCE (VOIDmode, gen_rtvec_v (j + 1, par)); |
| 26415 |
} |
| 26416 |
|
| 26417 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, tmp); |
| 26418 |
|
| 26419 |
return insn; |
| 26420 |
} |
| 26421 |
|
| 26422 |
/* Emit code to push or pop registers to or from the stack. F is the |
| 26423 |
assembly file. MASK is the registers to pop. */ |
| 26424 |
static void |
| 26425 |
thumb_pop (FILE *f, unsigned long mask) |
| 26426 |
{ |
| 26427 |
int regno; |
| 26428 |
int lo_mask = mask & 0xFF; |
| 26429 |
|
| 26430 |
gcc_assert (mask); |
| 26431 |
|
| 26432 |
if (lo_mask == 0 && (mask & (1 << PC_REGNUM))) |
| 26433 |
{ |
| 26434 |
/* Special case. Do not generate a POP PC statement here, do it in |
| 26435 |
thumb_exit() */ |
| 26436 |
thumb_exit (f, -1); |
| 26437 |
return; |
| 26438 |
} |
| 26439 |
|
| 26440 |
fprintf (f, "\tpop\t{"); |
| 26441 |
|
| 26442 |
/* Look at the low registers first. */ |
| 26443 |
for (regno = 0; regno <= LAST_LO_REGNUM; regno++, lo_mask >>= 1) |
| 26444 |
{ |
| 26445 |
if (lo_mask & 1) |
| 26446 |
{ |
| 26447 |
asm_fprintf (f, "%r", regno); |
| 26448 |
|
| 26449 |
if ((lo_mask & ~1) != 0) |
| 26450 |
fprintf (f, ", "); |
| 26451 |
} |
| 26452 |
} |
| 26453 |
|
| 26454 |
if (mask & (1 << PC_REGNUM)) |
| 26455 |
{ |
| 26456 |
/* Catch popping the PC. */ |
| 26457 |
if (TARGET_INTERWORK || TARGET_BACKTRACE || crtl->calls_eh_return |
| 26458 |
|| IS_CMSE_ENTRY (arm_current_func_type ())) |
| 26459 |
{ |
| 26460 |
/* The PC is never poped directly, instead |
| 26461 |
it is popped into r3 and then BX is used. */ |
| 26462 |
fprintf (f, "}\n"); |
| 26463 |
|
| 26464 |
thumb_exit (f, -1); |
| 26465 |
|
| 26466 |
return; |
| 26467 |
} |
| 26468 |
else |
| 26469 |
{ |
| 26470 |
if (mask & 0xFF) |
| 26471 |
fprintf (f, ", "); |
| 26472 |
|
| 26473 |
asm_fprintf (f, "%r", PC_REGNUM); |
| 26474 |
} |
| 26475 |
} |
| 26476 |
|
| 26477 |
fprintf (f, "}\n"); |
| 26478 |
} |
| 26479 |
|
| 26480 |
/* Generate code to return from a thumb function. |
| 26481 |
If 'reg_containing_return_addr' is -1, then the return address is |
| 26482 |
actually on the stack, at the stack pointer. |
| 26483 |
|
| 26484 |
Note: do not forget to update length attribute of corresponding insn pattern |
| 26485 |
when changing assembly output (eg. length attribute of epilogue_insns when |
| 26486 |
updating Armv8-M Baseline Security Extensions register clearing |
| 26487 |
sequences). */ |
| 26488 |
static void |
| 26489 |
thumb_exit (FILE *f, int reg_containing_return_addr) |
| 26490 |
{ |
| 26491 |
unsigned regs_available_for_popping; |
| 26492 |
unsigned regs_to_pop; |
| 26493 |
int pops_needed; |
| 26494 |
unsigned available; |
| 26495 |
unsigned required; |
| 26496 |
machine_mode mode; |
| 26497 |
int size; |
| 26498 |
int restore_a4 = FALSE; |
| 26499 |
|
| 26500 |
/* Compute the registers we need to pop. */ |
| 26501 |
regs_to_pop = 0; |
| 26502 |
pops_needed = 0; |
| 26503 |
|
| 26504 |
if (reg_containing_return_addr == -1) |
| 26505 |
{ |
| 26506 |
regs_to_pop |= 1 << LR_REGNUM; |
| 26507 |
++pops_needed; |
| 26508 |
} |
| 26509 |
|
| 26510 |
if (TARGET_BACKTRACE) |
| 26511 |
{ |
| 26512 |
/* Restore the (ARM) frame pointer and stack pointer. */ |
| 26513 |
regs_to_pop |= (1 << ARM_HARD_FRAME_POINTER_REGNUM) | (1 << SP_REGNUM); |
| 26514 |
pops_needed += 2; |
| 26515 |
} |
| 26516 |
|
| 26517 |
/* If there is nothing to pop then just emit the BX instruction and |
| 26518 |
return. */ |
| 26519 |
if (pops_needed == 0) |
| 26520 |
{ |
| 26521 |
if (crtl->calls_eh_return) |
| 26522 |
asm_fprintf (f, "\tadd\t%r, %r\n", SP_REGNUM, ARM_EH_STACKADJ_REGNUM); |
| 26523 |
|
| 26524 |
if (IS_CMSE_ENTRY (arm_current_func_type ())) |
| 26525 |
{ |
| 26526 |
/* For Armv8.1-M, this is cleared as part of the CLRM instruction |
| 26527 |
emitted by cmse_nonsecure_entry_clear_before_return (). */ |
| 26528 |
if (!TARGET_HAVE_FPCXT_CMSE) |
| 26529 |
asm_fprintf (f, "\tmsr\tAPSR_nzcvq, %r\n", |
| 26530 |
reg_containing_return_addr); |
| 26531 |
asm_fprintf (f, "\tbxns\t%r\n", reg_containing_return_addr); |
| 26532 |
} |
| 26533 |
else |
| 26534 |
asm_fprintf (f, "\tbx\t%r\n", reg_containing_return_addr); |
| 26535 |
return; |
| 26536 |
} |
| 26537 |
/* Otherwise if we are not supporting interworking and we have not created |
| 26538 |
a backtrace structure and the function was not entered in ARM mode then |
| 26539 |
just pop the return address straight into the PC. */ |
| 26540 |
else if (!TARGET_INTERWORK |
| 26541 |
&& !TARGET_BACKTRACE |
| 26542 |
&& !is_called_in_ARM_mode (current_function_decl) |
| 26543 |
&& !crtl->calls_eh_return |
| 26544 |
&& !IS_CMSE_ENTRY (arm_current_func_type ())) |
| 26545 |
{ |
| 26546 |
asm_fprintf (f, "\tpop\t{%r}\n", PC_REGNUM); |
| 26547 |
return; |
| 26548 |
} |
| 26549 |
|
| 26550 |
/* Find out how many of the (return) argument registers we can corrupt. */ |
| 26551 |
regs_available_for_popping = 0; |
| 26552 |
|
| 26553 |
/* If returning via __builtin_eh_return, the bottom three registers |
| 26554 |
all contain information needed for the return. */ |
| 26555 |
if (crtl->calls_eh_return) |
| 26556 |
size = 12; |
| 26557 |
else |
| 26558 |
{ |
| 26559 |
/* If we can deduce the registers used from the function's |
| 26560 |
return value. This is more reliable that examining |
| 26561 |
df_regs_ever_live_p () because that will be set if the register is |
| 26562 |
ever used in the function, not just if the register is used |
| 26563 |
to hold a return value. */ |
| 26564 |
|
| 26565 |
if (crtl->return_rtx != 0) |
| 26566 |
mode = GET_MODE (crtl->return_rtx); |
| 26567 |
else |
| 26568 |
mode = DECL_MODE (DECL_RESULT (current_function_decl)); |
| 26569 |
|
| 26570 |
size = GET_MODE_SIZE (mode); |
| 26571 |
|
| 26572 |
if (size == 0) |
| 26573 |
{ |
| 26574 |
/* In a void function we can use any argument register. |
| 26575 |
In a function that returns a structure on the stack |
| 26576 |
we can use the second and third argument registers. */ |
| 26577 |
if (mode == VOIDmode) |
| 26578 |
regs_available_for_popping = |
| 26579 |
(1 << ARG_REGISTER (1)) |
| 26580 |
| (1 << ARG_REGISTER (2)) |
| 26581 |
| (1 << ARG_REGISTER (3)); |
| 26582 |
else |
| 26583 |
regs_available_for_popping = |
| 26584 |
(1 << ARG_REGISTER (2)) |
| 26585 |
| (1 << ARG_REGISTER (3)); |
| 26586 |
} |
| 26587 |
else if (size <= 4) |
| 26588 |
regs_available_for_popping = |
| 26589 |
(1 << ARG_REGISTER (2)) |
| 26590 |
| (1 << ARG_REGISTER (3)); |
| 26591 |
else if (size <= 8) |
| 26592 |
regs_available_for_popping = |
| 26593 |
(1 << ARG_REGISTER (3)); |
| 26594 |
} |
| 26595 |
|
| 26596 |
/* Match registers to be popped with registers into which we pop them. */ |
| 26597 |
for (available = regs_available_for_popping, |
| 26598 |
required = regs_to_pop; |
| 26599 |
required != 0 && available != 0; |
| 26600 |
available &= ~(available & - available), |
| 26601 |
required &= ~(required & - required)) |
| 26602 |
-- pops_needed; |
| 26603 |
|
| 26604 |
/* If we have any popping registers left over, remove them. */ |
| 26605 |
if (available > 0) |
| 26606 |
regs_available_for_popping &= ~available; |
| 26607 |
|
| 26608 |
/* Otherwise if we need another popping register we can use |
| 26609 |
the fourth argument register. */ |
| 26610 |
else if (pops_needed) |
| 26611 |
{ |
| 26612 |
/* If we have not found any free argument registers and |
| 26613 |
reg a4 contains the return address, we must move it. */ |
| 26614 |
if (regs_available_for_popping == 0 |
| 26615 |
&& reg_containing_return_addr == LAST_ARG_REGNUM) |
| 26616 |
{ |
| 26617 |
asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, LAST_ARG_REGNUM); |
| 26618 |
reg_containing_return_addr = LR_REGNUM; |
| 26619 |
} |
| 26620 |
else if (size > 12) |
| 26621 |
{ |
| 26622 |
/* Register a4 is being used to hold part of the return value, |
| 26623 |
but we have dire need of a free, low register. */ |
| 26624 |
restore_a4 = TRUE; |
| 26625 |
|
| 26626 |
asm_fprintf (f, "\tmov\t%r, %r\n",IP_REGNUM, LAST_ARG_REGNUM); |
| 26627 |
} |
| 26628 |
|
| 26629 |
if (reg_containing_return_addr != LAST_ARG_REGNUM) |
| 26630 |
{ |
| 26631 |
/* The fourth argument register is available. */ |
| 26632 |
regs_available_for_popping |= 1 << LAST_ARG_REGNUM; |
| 26633 |
|
| 26634 |
--pops_needed; |
| 26635 |
} |
| 26636 |
} |
| 26637 |
|
| 26638 |
/* Pop as many registers as we can. */ |
| 26639 |
thumb_pop (f, regs_available_for_popping); |
| 26640 |
|
| 26641 |
/* Process the registers we popped. */ |
| 26642 |
if (reg_containing_return_addr == -1) |
| 26643 |
{ |
| 26644 |
/* The return address was popped into the lowest numbered register. */ |
| 26645 |
regs_to_pop &= ~(1 << LR_REGNUM); |
| 26646 |
|
| 26647 |
reg_containing_return_addr = |
| 26648 |
number_of_first_bit_set (regs_available_for_popping); |
| 26649 |
|
| 26650 |
/* Remove this register for the mask of available registers, so that |
| 26651 |
the return address will not be corrupted by further pops. */ |
| 26652 |
regs_available_for_popping &= ~(1 << reg_containing_return_addr); |
| 26653 |
} |
| 26654 |
|
| 26655 |
/* If we popped other registers then handle them here. */ |
| 26656 |
if (regs_available_for_popping) |
| 26657 |
{ |
| 26658 |
int frame_pointer; |
| 26659 |
|
| 26660 |
/* Work out which register currently contains the frame pointer. */ |
| 26661 |
frame_pointer = number_of_first_bit_set (regs_available_for_popping); |
| 26662 |
|
| 26663 |
/* Move it into the correct place. */ |
| 26664 |
asm_fprintf (f, "\tmov\t%r, %r\n", |
| 26665 |
ARM_HARD_FRAME_POINTER_REGNUM, frame_pointer); |
| 26666 |
|
| 26667 |
/* (Temporarily) remove it from the mask of popped registers. */ |
| 26668 |
regs_available_for_popping &= ~(1 << frame_pointer); |
| 26669 |
regs_to_pop &= ~(1 << ARM_HARD_FRAME_POINTER_REGNUM); |
| 26670 |
|
| 26671 |
if (regs_available_for_popping) |
| 26672 |
{ |
| 26673 |
int stack_pointer; |
| 26674 |
|
| 26675 |
/* We popped the stack pointer as well, |
| 26676 |
find the register that contains it. */ |
| 26677 |
stack_pointer = number_of_first_bit_set (regs_available_for_popping); |
| 26678 |
|
| 26679 |
/* Move it into the stack register. */ |
| 26680 |
asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, stack_pointer); |
| 26681 |
|
| 26682 |
/* At this point we have popped all necessary registers, so |
| 26683 |
do not worry about restoring regs_available_for_popping |
| 26684 |
to its correct value: |
| 26685 |
|
| 26686 |
assert (pops_needed == 0) |
| 26687 |
assert (regs_available_for_popping == (1 << frame_pointer)) |
| 26688 |
assert (regs_to_pop == (1 << STACK_POINTER)) */ |
| 26689 |
} |
| 26690 |
else |
| 26691 |
{ |
| 26692 |
/* Since we have just move the popped value into the frame |
| 26693 |
pointer, the popping register is available for reuse, and |
| 26694 |
we know that we still have the stack pointer left to pop. */ |
| 26695 |
regs_available_for_popping |= (1 << frame_pointer); |
| 26696 |
} |
| 26697 |
} |
| 26698 |
|
| 26699 |
/* If we still have registers left on the stack, but we no longer have |
| 26700 |
any registers into which we can pop them, then we must move the return |
| 26701 |
address into the link register and make available the register that |
| 26702 |
contained it. */ |
| 26703 |
if (regs_available_for_popping == 0 && pops_needed > 0) |
| 26704 |
{ |
| 26705 |
regs_available_for_popping |= 1 << reg_containing_return_addr; |
| 26706 |
|
| 26707 |
asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, |
| 26708 |
reg_containing_return_addr); |
| 26709 |
|
| 26710 |
reg_containing_return_addr = LR_REGNUM; |
| 26711 |
} |
| 26712 |
|
| 26713 |
/* If we have registers left on the stack then pop some more. |
| 26714 |
We know that at most we will want to pop FP and SP. */ |
| 26715 |
if (pops_needed > 0) |
| 26716 |
{ |
| 26717 |
int popped_into; |
| 26718 |
int move_to; |
| 26719 |
|
| 26720 |
thumb_pop (f, regs_available_for_popping); |
| 26721 |
|
| 26722 |
/* We have popped either FP or SP. |
| 26723 |
Move whichever one it is into the correct register. */ |
| 26724 |
popped_into = number_of_first_bit_set (regs_available_for_popping); |
| 26725 |
move_to = number_of_first_bit_set (regs_to_pop); |
| 26726 |
|
| 26727 |
asm_fprintf (f, "\tmov\t%r, %r\n", move_to, popped_into); |
| 26728 |
--pops_needed; |
| 26729 |
} |
| 26730 |
|
| 26731 |
/* If we still have not popped everything then we must have only |
| 26732 |
had one register available to us and we are now popping the SP. */ |
| 26733 |
if (pops_needed > 0) |
| 26734 |
{ |
| 26735 |
int popped_into; |
| 26736 |
|
| 26737 |
thumb_pop (f, regs_available_for_popping); |
| 26738 |
|
| 26739 |
popped_into = number_of_first_bit_set (regs_available_for_popping); |
| 26740 |
|
| 26741 |
asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, popped_into); |
| 26742 |
/* |
| 26743 |
assert (regs_to_pop == (1 << STACK_POINTER)) |
| 26744 |
assert (pops_needed == 1) |
| 26745 |
*/ |
| 26746 |
} |
| 26747 |
|
| 26748 |
/* If necessary restore the a4 register. */ |
| 26749 |
if (restore_a4) |
| 26750 |
{ |
| 26751 |
if (reg_containing_return_addr != LR_REGNUM) |
| 26752 |
{ |
| 26753 |
asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, LAST_ARG_REGNUM); |
| 26754 |
reg_containing_return_addr = LR_REGNUM; |
| 26755 |
} |
| 26756 |
|
| 26757 |
asm_fprintf (f, "\tmov\t%r, %r\n", LAST_ARG_REGNUM, IP_REGNUM); |
| 26758 |
} |
| 26759 |
|
| 26760 |
if (crtl->calls_eh_return) |
| 26761 |
asm_fprintf (f, "\tadd\t%r, %r\n", SP_REGNUM, ARM_EH_STACKADJ_REGNUM); |
| 26762 |
|
| 26763 |
/* Return to caller. */ |
| 26764 |
if (IS_CMSE_ENTRY (arm_current_func_type ())) |
| 26765 |
{ |
| 26766 |
/* This is for the cases where LR is not being used to contain the return |
| 26767 |
address. It may therefore contain information that we might not want |
| 26768 |
to leak, hence it must be cleared. The value in R0 will never be a |
| 26769 |
secret at this point, so it is safe to use it, see the clearing code |
| 26770 |
in cmse_nonsecure_entry_clear_before_return (). */ |
| 26771 |
if (reg_containing_return_addr != LR_REGNUM) |
| 26772 |
asm_fprintf (f, "\tmov\tlr, r0\n"); |
| 26773 |
|
| 26774 |
/* For Armv8.1-M, this is cleared as part of the CLRM instruction emitted |
| 26775 |
by cmse_nonsecure_entry_clear_before_return (). */ |
| 26776 |
if (!TARGET_HAVE_FPCXT_CMSE) |
| 26777 |
asm_fprintf (f, "\tmsr\tAPSR_nzcvq, %r\n", reg_containing_return_addr); |
| 26778 |
asm_fprintf (f, "\tbxns\t%r\n", reg_containing_return_addr); |
| 26779 |
} |
| 26780 |
else |
| 26781 |
asm_fprintf (f, "\tbx\t%r\n", reg_containing_return_addr); |
| 26782 |
} |
| 26783 |
|
| 26784 |
/* Scan INSN just before assembler is output for it. |
| 26785 |
For Thumb-1, we track the status of the condition codes; this |
| 26786 |
information is used in the cbranchsi4_insn pattern. */ |
| 26787 |
void |
| 26788 |
thumb1_final_prescan_insn (rtx_insn *insn) |
| 26789 |
{ |
| 26790 |
if (flag_print_asm_name) |
| 26791 |
asm_fprintf (asm_out_file, "%@ 0x%04x\n", |
| 26792 |
INSN_ADDRESSES (INSN_UID (insn))); |
| 26793 |
/* Don't overwrite the previous setter when we get to a cbranch. */ |
| 26794 |
if (INSN_CODE (insn) != CODE_FOR_cbranchsi4_insn) |
| 26795 |
{ |
| 26796 |
enum attr_conds conds; |
| 26797 |
|
| 26798 |
if (cfun->machine->thumb1_cc_insn) |
| 26799 |
{ |
| 26800 |
if (modified_in_p (cfun->machine->thumb1_cc_op0, insn) |
| 26801 |
|| modified_in_p (cfun->machine->thumb1_cc_op1, insn)) |
| 26802 |
CC_STATUS_INIT; |
| 26803 |
} |
| 26804 |
conds = get_attr_conds (insn); |
| 26805 |
if (conds == CONDS_SET) |
| 26806 |
{ |
| 26807 |
rtx set = single_set (insn); |
| 26808 |
cfun->machine->thumb1_cc_insn = insn; |
| 26809 |
cfun->machine->thumb1_cc_op0 = SET_DEST (set); |
| 26810 |
cfun->machine->thumb1_cc_op1 = const0_rtx; |
| 26811 |
cfun->machine->thumb1_cc_mode = CC_NZmode; |
| 26812 |
if (INSN_CODE (insn) == CODE_FOR_thumb1_subsi3_insn) |
| 26813 |
{ |
| 26814 |
rtx src1 = XEXP (SET_SRC (set), 1); |
| 26815 |
if (src1 == const0_rtx) |
| 26816 |
cfun->machine->thumb1_cc_mode = CCmode; |
| 26817 |
} |
| 26818 |
else if (REG_P (SET_DEST (set)) && REG_P (SET_SRC (set))) |
| 26819 |
{ |
| 26820 |
/* Record the src register operand instead of dest because |
| 26821 |
cprop_hardreg pass propagates src. */ |
| 26822 |
cfun->machine->thumb1_cc_op0 = SET_SRC (set); |
| 26823 |
} |
| 26824 |
} |
| 26825 |
else if (conds != CONDS_NOCOND) |
| 26826 |
cfun->machine->thumb1_cc_insn = NULL_RTX; |
| 26827 |
} |
| 26828 |
|
| 26829 |
/* Check if unexpected far jump is used. */ |
| 26830 |
if (cfun->machine->lr_save_eliminated |
| 26831 |
&& get_attr_far_jump (insn) == FAR_JUMP_YES) |
| 26832 |
internal_error("Unexpected thumb1 far jump"); |
| 26833 |
} |
| 26834 |
|
| 26835 |
int |
| 26836 |
thumb_shiftable_const (unsigned HOST_WIDE_INT val) |
| 26837 |
{ |
| 26838 |
unsigned HOST_WIDE_INT mask = 0xff; |
| 26839 |
int i; |
| 26840 |
|
| 26841 |
val = val & (unsigned HOST_WIDE_INT)0xffffffffu; |
| 26842 |
if (val == 0) /* XXX */ |
| 26843 |
return 0; |
| 26844 |
|
| 26845 |
for (i = 0; i < 25; i++) |
| 26846 |
if ((val & (mask << i)) == val) |
| 26847 |
return 1; |
| 26848 |
|
| 26849 |
return 0; |
| 26850 |
} |
| 26851 |
|
| 26852 |
/* Returns nonzero if the current function contains, |
| 26853 |
or might contain a far jump. */ |
| 26854 |
static int |
| 26855 |
thumb_far_jump_used_p (void) |
| 26856 |
{ |
| 26857 |
rtx_insn *insn; |
| 26858 |
bool far_jump = false; |
| 26859 |
unsigned int func_size = 0; |
| 26860 |
|
| 26861 |
/* If we have already decided that far jumps may be used, |
| 26862 |
do not bother checking again, and always return true even if |
| 26863 |
it turns out that they are not being used. Once we have made |
| 26864 |
the decision that far jumps are present (and that hence the link |
| 26865 |
register will be pushed onto the stack) we cannot go back on it. */ |
| 26866 |
if (cfun->machine->far_jump_used) |
| 26867 |
return 1; |
| 26868 |
|
| 26869 |
/* If this function is not being called from the prologue/epilogue |
| 26870 |
generation code then it must be being called from the |
| 26871 |
INITIAL_ELIMINATION_OFFSET macro. */ |
| 26872 |
if (!(ARM_DOUBLEWORD_ALIGN || reload_completed)) |
| 26873 |
{ |
| 26874 |
/* In this case we know that we are being asked about the elimination |
| 26875 |
of the arg pointer register. If that register is not being used, |
| 26876 |
then there are no arguments on the stack, and we do not have to |
| 26877 |
worry that a far jump might force the prologue to push the link |
| 26878 |
register, changing the stack offsets. In this case we can just |
| 26879 |
return false, since the presence of far jumps in the function will |
| 26880 |
not affect stack offsets. |
| 26881 |
|
| 26882 |
If the arg pointer is live (or if it was live, but has now been |
| 26883 |
eliminated and so set to dead) then we do have to test to see if |
| 26884 |
the function might contain a far jump. This test can lead to some |
| 26885 |
false negatives, since before reload is completed, then length of |
| 26886 |
branch instructions is not known, so gcc defaults to returning their |
| 26887 |
longest length, which in turn sets the far jump attribute to true. |
| 26888 |
|
| 26889 |
A false negative will not result in bad code being generated, but it |
| 26890 |
will result in a needless push and pop of the link register. We |
| 26891 |
hope that this does not occur too often. |
| 26892 |
|
| 26893 |
If we need doubleword stack alignment this could affect the other |
| 26894 |
elimination offsets so we can't risk getting it wrong. */ |
| 26895 |
if (df_regs_ever_live_p (ARG_POINTER_REGNUM)) |
| 26896 |
cfun->machine->arg_pointer_live = 1; |
| 26897 |
else if (!cfun->machine->arg_pointer_live) |
| 26898 |
return 0; |
| 26899 |
} |
| 26900 |
|
| 26901 |
/* We should not change far_jump_used during or after reload, as there is |
| 26902 |
no chance to change stack frame layout. */ |
| 26903 |
if (reload_in_progress || reload_completed) |
| 26904 |
return 0; |
| 26905 |
|
| 26906 |
/* Check to see if the function contains a branch |
| 26907 |
insn with the far jump attribute set. */ |
| 26908 |
for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
| 26909 |
{ |
| 26910 |
if (JUMP_P (insn) && get_attr_far_jump (insn) == FAR_JUMP_YES) |
| 26911 |
{ |
| 26912 |
far_jump = true; |
| 26913 |
} |
| 26914 |
func_size += get_attr_length (insn); |
| 26915 |
} |
| 26916 |
|
| 26917 |
/* Attribute far_jump will always be true for thumb1 before |
| 26918 |
shorten_branch pass. So checking far_jump attribute before |
| 26919 |
shorten_branch isn't much useful. |
| 26920 |
|
| 26921 |
Following heuristic tries to estimate more accurately if a far jump |
| 26922 |
may finally be used. The heuristic is very conservative as there is |
| 26923 |
no chance to roll-back the decision of not to use far jump. |
| 26924 |
|
| 26925 |
Thumb1 long branch offset is -2048 to 2046. The worst case is each |
| 26926 |
2-byte insn is associated with a 4 byte constant pool. Using |
| 26927 |
function size 2048/3 as the threshold is conservative enough. */ |
| 26928 |
if (far_jump) |
| 26929 |
{ |
| 26930 |
if ((func_size * 3) >= 2048) |
| 26931 |
{ |
| 26932 |
/* Record the fact that we have decided that |
| 26933 |
the function does use far jumps. */ |
| 26934 |
cfun->machine->far_jump_used = 1; |
| 26935 |
return 1; |
| 26936 |
} |
| 26937 |
} |
| 26938 |
|
| 26939 |
return 0; |
| 26940 |
} |
| 26941 |
|
| 26942 |
/* Return nonzero if FUNC must be entered in ARM mode. */ |
| 26943 |
static bool |
| 26944 |
is_called_in_ARM_mode (tree func) |
| 26945 |
{ |
| 26946 |
gcc_assert (TREE_CODE (func) == FUNCTION_DECL); |
| 26947 |
|
| 26948 |
/* Ignore the problem about functions whose address is taken. */ |
| 26949 |
if (TARGET_CALLEE_INTERWORKING && TREE_PUBLIC (func)) |
| 26950 |
return true; |
| 26951 |
|
| 26952 |
return false; |
| 26953 |
} |
| 26954 |
|
| 26955 |
/* Given the stack offsets and register mask in OFFSETS, decide how |
| 26956 |
many additional registers to push instead of subtracting a constant |
| 26957 |
from SP. For epilogues the principle is the same except we use pop. |
| 26958 |
FOR_PROLOGUE indicates which we're generating. */ |
| 26959 |
static int |
| 26960 |
thumb1_extra_regs_pushed (arm_stack_offsets *offsets, bool for_prologue) |
| 26961 |
{ |
| 26962 |
HOST_WIDE_INT amount; |
| 26963 |
unsigned long live_regs_mask = offsets->saved_regs_mask; |
| 26964 |
/* Extract a mask of the ones we can give to the Thumb's push/pop |
| 26965 |
instruction. */ |
| 26966 |
unsigned long l_mask = live_regs_mask & (for_prologue ? 0x40ff : 0xff); |
| 26967 |
/* Then count how many other high registers will need to be pushed. */ |
| 26968 |
unsigned long high_regs_pushed = bit_count (live_regs_mask & 0x0f00); |
| 26969 |
int n_free, reg_base, size; |
| 26970 |
|
| 26971 |
if (!for_prologue && frame_pointer_needed) |
| 26972 |
amount = offsets->locals_base - offsets->saved_regs; |
| 26973 |
else |
| 26974 |
amount = offsets->outgoing_args - offsets->saved_regs; |
| 26975 |
|
| 26976 |
/* If the stack frame size is 512 exactly, we can save one load |
| 26977 |
instruction, which should make this a win even when optimizing |
| 26978 |
for speed. */ |
| 26979 |
if (!optimize_size && amount != 512) |
| 26980 |
return 0; |
| 26981 |
|
| 26982 |
/* Can't do this if there are high registers to push. */ |
| 26983 |
if (high_regs_pushed != 0) |
| 26984 |
return 0; |
| 26985 |
|
| 26986 |
/* Shouldn't do it in the prologue if no registers would normally |
| 26987 |
be pushed at all. In the epilogue, also allow it if we'll have |
| 26988 |
a pop insn for the PC. */ |
| 26989 |
if (l_mask == 0 |
| 26990 |
&& (for_prologue |
| 26991 |
|| TARGET_BACKTRACE |
| 26992 |
|| (live_regs_mask & 1 << LR_REGNUM) == 0 |
| 26993 |
|| TARGET_INTERWORK |
| 26994 |
|| crtl->args.pretend_args_size != 0)) |
| 26995 |
return 0; |
| 26996 |
|
| 26997 |
/* Don't do this if thumb_expand_prologue wants to emit instructions |
| 26998 |
between the push and the stack frame allocation. */ |
| 26999 |
if (for_prologue |
| 27000 |
&& ((flag_pic && arm_pic_register != INVALID_REGNUM) |
| 27001 |
|| (!frame_pointer_needed && CALLER_INTERWORKING_SLOT_SIZE > 0))) |
| 27002 |
return 0; |
| 27003 |
|
| 27004 |
reg_base = 0; |
| 27005 |
n_free = 0; |
| 27006 |
if (!for_prologue) |
| 27007 |
{ |
| 27008 |
size = arm_size_return_regs (); |
| 27009 |
reg_base = ARM_NUM_INTS (size); |
| 27010 |
live_regs_mask >>= reg_base; |
| 27011 |
} |
| 27012 |
|
| 27013 |
while (reg_base + n_free < 8 && !(live_regs_mask & 1) |
| 27014 |
&& (for_prologue || call_used_or_fixed_reg_p (reg_base + n_free))) |
| 27015 |
{ |
| 27016 |
live_regs_mask >>= 1; |
| 27017 |
n_free++; |
| 27018 |
} |
| 27019 |
|
| 27020 |
if (n_free == 0) |
| 27021 |
return 0; |
| 27022 |
gcc_assert (amount / 4 * 4 == amount); |
| 27023 |
|
| 27024 |
if (amount >= 512 && (amount - n_free * 4) < 512) |
| 27025 |
return (amount - 508) / 4; |
| 27026 |
if (amount <= n_free * 4) |
| 27027 |
return amount / 4; |
| 27028 |
return 0; |
| 27029 |
} |
| 27030 |
|
| 27031 |
/* The bits which aren't usefully expanded as rtl. */ |
| 27032 |
const char * |
| 27033 |
thumb1_unexpanded_epilogue (void) |
| 27034 |
{ |
| 27035 |
arm_stack_offsets *offsets; |
| 27036 |
int regno; |
| 27037 |
unsigned long live_regs_mask = 0; |
| 27038 |
int high_regs_pushed = 0; |
| 27039 |
int extra_pop; |
| 27040 |
int had_to_push_lr; |
| 27041 |
int size; |
| 27042 |
|
| 27043 |
if (cfun->machine->return_used_this_function != 0) |
| 27044 |
return ""; |
| 27045 |
|
| 27046 |
if (IS_NAKED (arm_current_func_type ())) |
| 27047 |
return ""; |
| 27048 |
|
| 27049 |
offsets = arm_get_frame_offsets (); |
| 27050 |
live_regs_mask = offsets->saved_regs_mask; |
| 27051 |
high_regs_pushed = bit_count (live_regs_mask & 0x0f00); |
| 27052 |
|
| 27053 |
/* If we can deduce the registers used from the function's return value. |
| 27054 |
This is more reliable that examining df_regs_ever_live_p () because that |
| 27055 |
will be set if the register is ever used in the function, not just if |
| 27056 |
the register is used to hold a return value. */ |
| 27057 |
size = arm_size_return_regs (); |
| 27058 |
|
| 27059 |
extra_pop = thumb1_extra_regs_pushed (offsets, false); |
| 27060 |
if (extra_pop > 0) |
| 27061 |
{ |
| 27062 |
unsigned long extra_mask = (1 << extra_pop) - 1; |
| 27063 |
live_regs_mask |= extra_mask << ARM_NUM_INTS (size); |
| 27064 |
} |
| 27065 |
|
| 27066 |
/* The prolog may have pushed some high registers to use as |
| 27067 |
work registers. e.g. the testsuite file: |
| 27068 |
gcc/testsuite/gcc/gcc.c-torture/execute/complex-2.c |
| 27069 |
compiles to produce: |
| 27070 |
push {r4, r5, r6, r7, lr} |
| 27071 |
mov r7, r9 |
| 27072 |
mov r6, r8 |
| 27073 |
push {r6, r7} |
| 27074 |
as part of the prolog. We have to undo that pushing here. */ |
| 27075 |
|
| 27076 |
if (high_regs_pushed) |
| 27077 |
{ |
| 27078 |
unsigned long mask = live_regs_mask & 0xff; |
| 27079 |
int next_hi_reg; |
| 27080 |
|
| 27081 |
mask |= thumb1_epilogue_unused_call_clobbered_lo_regs (); |
| 27082 |
|
| 27083 |
if (mask == 0) |
| 27084 |
/* Oh dear! We have no low registers into which we can pop |
| 27085 |
high registers! */ |
| 27086 |
internal_error |
| 27087 |
("no low registers available for popping high registers"); |
| 27088 |
|
| 27089 |
for (next_hi_reg = 12; next_hi_reg > LAST_LO_REGNUM; next_hi_reg--) |
| 27090 |
if (live_regs_mask & (1 << next_hi_reg)) |
| 27091 |
break; |
| 27092 |
|
| 27093 |
while (high_regs_pushed) |
| 27094 |
{ |
| 27095 |
/* Find lo register(s) into which the high register(s) can |
| 27096 |
be popped. */ |
| 27097 |
for (regno = LAST_LO_REGNUM; regno >= 0; regno--) |
| 27098 |
{ |
| 27099 |
if (mask & (1 << regno)) |
| 27100 |
high_regs_pushed--; |
| 27101 |
if (high_regs_pushed == 0) |
| 27102 |
break; |
| 27103 |
} |
| 27104 |
|
| 27105 |
if (high_regs_pushed == 0 && regno >= 0) |
| 27106 |
mask &= ~((1 << regno) - 1); |
| 27107 |
|
| 27108 |
/* Pop the values into the low register(s). */ |
| 27109 |
thumb_pop (asm_out_file, mask); |
| 27110 |
|
| 27111 |
/* Move the value(s) into the high registers. */ |
| 27112 |
for (regno = LAST_LO_REGNUM; regno >= 0; regno--) |
| 27113 |
{ |
| 27114 |
if (mask & (1 << regno)) |
| 27115 |
{ |
| 27116 |
asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", next_hi_reg, |
| 27117 |
regno); |
| 27118 |
|
| 27119 |
for (next_hi_reg--; next_hi_reg > LAST_LO_REGNUM; |
| 27120 |
next_hi_reg--) |
| 27121 |
if (live_regs_mask & (1 << next_hi_reg)) |
| 27122 |
break; |
| 27123 |
} |
| 27124 |
} |
| 27125 |
} |
| 27126 |
live_regs_mask &= ~0x0f00; |
| 27127 |
} |
| 27128 |
|
| 27129 |
had_to_push_lr = (live_regs_mask & (1 << LR_REGNUM)) != 0; |
| 27130 |
live_regs_mask &= 0xff; |
| 27131 |
|
| 27132 |
if (crtl->args.pretend_args_size == 0 || TARGET_BACKTRACE) |
| 27133 |
{ |
| 27134 |
/* Pop the return address into the PC. */ |
| 27135 |
if (had_to_push_lr) |
| 27136 |
live_regs_mask |= 1 << PC_REGNUM; |
| 27137 |
|
| 27138 |
/* Either no argument registers were pushed or a backtrace |
| 27139 |
structure was created which includes an adjusted stack |
| 27140 |
pointer, so just pop everything. */ |
| 27141 |
if (live_regs_mask) |
| 27142 |
thumb_pop (asm_out_file, live_regs_mask); |
| 27143 |
|
| 27144 |
/* We have either just popped the return address into the |
| 27145 |
PC or it is was kept in LR for the entire function. |
| 27146 |
Note that thumb_pop has already called thumb_exit if the |
| 27147 |
PC was in the list. */ |
| 27148 |
if (!had_to_push_lr) |
| 27149 |
thumb_exit (asm_out_file, LR_REGNUM); |
| 27150 |
} |
| 27151 |
else |
| 27152 |
{ |
| 27153 |
/* Pop everything but the return address. */ |
| 27154 |
if (live_regs_mask) |
| 27155 |
thumb_pop (asm_out_file, live_regs_mask); |
| 27156 |
|
| 27157 |
if (had_to_push_lr) |
| 27158 |
{ |
| 27159 |
if (size > 12) |
| 27160 |
{ |
| 27161 |
/* We have no free low regs, so save one. */ |
| 27162 |
asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", IP_REGNUM, |
| 27163 |
LAST_ARG_REGNUM); |
| 27164 |
} |
| 27165 |
|
| 27166 |
/* Get the return address into a temporary register. */ |
| 27167 |
thumb_pop (asm_out_file, 1 << LAST_ARG_REGNUM); |
| 27168 |
|
| 27169 |
if (size > 12) |
| 27170 |
{ |
| 27171 |
/* Move the return address to lr. */ |
| 27172 |
asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", LR_REGNUM, |
| 27173 |
LAST_ARG_REGNUM); |
| 27174 |
/* Restore the low register. */ |
| 27175 |
asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", LAST_ARG_REGNUM, |
| 27176 |
IP_REGNUM); |
| 27177 |
regno = LR_REGNUM; |
| 27178 |
} |
| 27179 |
else |
| 27180 |
regno = LAST_ARG_REGNUM; |
| 27181 |
} |
| 27182 |
else |
| 27183 |
regno = LR_REGNUM; |
| 27184 |
|
| 27185 |
/* Remove the argument registers that were pushed onto the stack. */ |
| 27186 |
asm_fprintf (asm_out_file, "\tadd\t%r, %r, #%d\n", |
| 27187 |
SP_REGNUM, SP_REGNUM, |
| 27188 |
crtl->args.pretend_args_size); |
| 27189 |
|
| 27190 |
thumb_exit (asm_out_file, regno); |
| 27191 |
} |
| 27192 |
|
| 27193 |
return ""; |
| 27194 |
} |
| 27195 |
|
| 27196 |
/* Functions to save and restore machine-specific function data. */ |
| 27197 |
static struct machine_function * |
| 27198 |
arm_init_machine_status (void) |
| 27199 |
{ |
| 27200 |
struct machine_function *machine; |
| 27201 |
machine = ggc_cleared_alloc<machine_function> (); |
| 27202 |
|
| 27203 |
#if ARM_FT_UNKNOWN != 0 |
| 27204 |
machine->func_type = ARM_FT_UNKNOWN; |
| 27205 |
#endif |
| 27206 |
machine->static_chain_stack_bytes = -1; |
| 27207 |
machine->pacspval_needed = 0; |
| 27208 |
return machine; |
| 27209 |
} |
| 27210 |
|
| 27211 |
/* Return an RTX indicating where the return address to the |
| 27212 |
calling function can be found. */ |
| 27213 |
rtx |
| 27214 |
arm_return_addr (int count, rtx frame ATTRIBUTE_UNUSED) |
| 27215 |
{ |
| 27216 |
if (count != 0) |
| 27217 |
return NULL_RTX; |
| 27218 |
|
| 27219 |
return get_hard_reg_initial_val (Pmode, LR_REGNUM); |
| 27220 |
} |
| 27221 |
|
| 27222 |
/* Do anything needed before RTL is emitted for each function. */ |
| 27223 |
void |
| 27224 |
arm_init_expanders (void) |
| 27225 |
{ |
| 27226 |
/* Arrange to initialize and mark the machine per-function status. */ |
| 27227 |
init_machine_status = arm_init_machine_status; |
| 27228 |
|
| 27229 |
/* This is to stop the combine pass optimizing away the alignment |
| 27230 |
adjustment of va_arg. */ |
| 27231 |
/* ??? It is claimed that this should not be necessary. */ |
| 27232 |
if (cfun) |
| 27233 |
mark_reg_pointer (arg_pointer_rtx, PARM_BOUNDARY); |
| 27234 |
} |
| 27235 |
|
| 27236 |
/* Check that FUNC is called with a different mode. */ |
| 27237 |
|
| 27238 |
bool |
| 27239 |
arm_change_mode_p (tree func) |
| 27240 |
{ |
| 27241 |
if (TREE_CODE (func) != FUNCTION_DECL) |
| 27242 |
return false; |
| 27243 |
|
| 27244 |
tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (func); |
| 27245 |
|
| 27246 |
if (!callee_tree) |
| 27247 |
callee_tree = target_option_default_node; |
| 27248 |
|
| 27249 |
struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree); |
| 27250 |
int flags = callee_opts->x_target_flags; |
| 27251 |
|
| 27252 |
return (TARGET_THUMB_P (flags) != TARGET_THUMB); |
| 27253 |
} |
| 27254 |
|
| 27255 |
/* Like arm_compute_initial_elimination offset. Simpler because there |
| 27256 |
isn't an ABI specified frame pointer for Thumb. Instead, we set it |
| 27257 |
to point at the base of the local variables after static stack |
| 27258 |
space for a function has been allocated. */ |
| 27259 |
|
| 27260 |
HOST_WIDE_INT |
| 27261 |
thumb_compute_initial_elimination_offset (unsigned int from, unsigned int to) |
| 27262 |
{ |
| 27263 |
arm_stack_offsets *offsets; |
| 27264 |
|
| 27265 |
offsets = arm_get_frame_offsets (); |
| 27266 |
|
| 27267 |
switch (from) |
| 27268 |
{ |
| 27269 |
case ARG_POINTER_REGNUM: |
| 27270 |
switch (to) |
| 27271 |
{ |
| 27272 |
case STACK_POINTER_REGNUM: |
| 27273 |
return offsets->outgoing_args - offsets->saved_args; |
| 27274 |
|
| 27275 |
case FRAME_POINTER_REGNUM: |
| 27276 |
return offsets->soft_frame - offsets->saved_args; |
| 27277 |
|
| 27278 |
case ARM_HARD_FRAME_POINTER_REGNUM: |
| 27279 |
return offsets->saved_regs - offsets->saved_args; |
| 27280 |
|
| 27281 |
case THUMB_HARD_FRAME_POINTER_REGNUM: |
| 27282 |
return offsets->locals_base - offsets->saved_args; |
| 27283 |
|
| 27284 |
default: |
| 27285 |
gcc_unreachable (); |
| 27286 |
} |
| 27287 |
break; |
| 27288 |
|
| 27289 |
case FRAME_POINTER_REGNUM: |
| 27290 |
switch (to) |
| 27291 |
{ |
| 27292 |
case STACK_POINTER_REGNUM: |
| 27293 |
return offsets->outgoing_args - offsets->soft_frame; |
| 27294 |
|
| 27295 |
case ARM_HARD_FRAME_POINTER_REGNUM: |
| 27296 |
return offsets->saved_regs - offsets->soft_frame; |
| 27297 |
|
| 27298 |
case THUMB_HARD_FRAME_POINTER_REGNUM: |
| 27299 |
return offsets->locals_base - offsets->soft_frame; |
| 27300 |
|
| 27301 |
default: |
| 27302 |
gcc_unreachable (); |
| 27303 |
} |
| 27304 |
break; |
| 27305 |
|
| 27306 |
default: |
| 27307 |
gcc_unreachable (); |
| 27308 |
} |
| 27309 |
} |
| 27310 |
|
| 27311 |
/* Generate the function's prologue. */ |
| 27312 |
|
| 27313 |
void |
| 27314 |
thumb1_expand_prologue (void) |
| 27315 |
{ |
| 27316 |
rtx_insn *insn; |
| 27317 |
|
| 27318 |
HOST_WIDE_INT amount; |
| 27319 |
HOST_WIDE_INT size; |
| 27320 |
arm_stack_offsets *offsets; |
| 27321 |
unsigned long func_type; |
| 27322 |
int regno; |
| 27323 |
unsigned long live_regs_mask; |
| 27324 |
unsigned long l_mask; |
| 27325 |
unsigned high_regs_pushed = 0; |
| 27326 |
bool lr_needs_saving; |
| 27327 |
|
| 27328 |
func_type = arm_current_func_type (); |
| 27329 |
|
| 27330 |
/* Naked functions don't have prologues. */ |
| 27331 |
if (IS_NAKED (func_type)) |
| 27332 |
{ |
| 27333 |
if (flag_stack_usage_info) |
| 27334 |
current_function_static_stack_size = 0; |
| 27335 |
return; |
| 27336 |
} |
| 27337 |
|
| 27338 |
if (IS_INTERRUPT (func_type)) |
| 27339 |
{ |
| 27340 |
error ("Interrupt Service Routines cannot be coded in Thumb-1 mode"); |
| 27341 |
return; |
| 27342 |
} |
| 27343 |
|
| 27344 |
if (is_called_in_ARM_mode (current_function_decl)) |
| 27345 |
emit_insn (gen_prologue_thumb1_interwork ()); |
| 27346 |
|
| 27347 |
offsets = arm_get_frame_offsets (); |
| 27348 |
live_regs_mask = offsets->saved_regs_mask; |
| 27349 |
lr_needs_saving = live_regs_mask & (1 << LR_REGNUM); |
| 27350 |
|
| 27351 |
/* The AAPCS requires the callee to widen integral types narrower |
| 27352 |
than 32 bits to the full width of the register; but when handling |
| 27353 |
calls to non-secure space, we cannot trust the callee to have |
| 27354 |
correctly done so. So forcibly re-widen the result here. */ |
| 27355 |
if (IS_CMSE_ENTRY (func_type)) |
| 27356 |
{ |
| 27357 |
function_args_iterator args_iter; |
| 27358 |
CUMULATIVE_ARGS args_so_far_v; |
| 27359 |
cumulative_args_t args_so_far; |
| 27360 |
bool first_param = true; |
| 27361 |
tree arg_type; |
| 27362 |
tree fndecl = current_function_decl; |
| 27363 |
tree fntype = TREE_TYPE (fndecl); |
| 27364 |
arm_init_cumulative_args (&args_so_far_v, fntype, NULL_RTX, fndecl); |
| 27365 |
args_so_far = pack_cumulative_args (&args_so_far_v); |
| 27366 |
FOREACH_FUNCTION_ARGS (fntype, arg_type, args_iter) |
| 27367 |
{ |
| 27368 |
rtx arg_rtx; |
| 27369 |
|
| 27370 |
if (VOID_TYPE_P (arg_type)) |
| 27371 |
break; |
| 27372 |
|
| 27373 |
function_arg_info arg (arg_type, /*named=*/true); |
| 27374 |
if (!first_param) |
| 27375 |
/* We should advance after processing the argument and pass |
| 27376 |
the argument we're advancing past. */ |
| 27377 |
arm_function_arg_advance (args_so_far, arg); |
| 27378 |
first_param = false; |
| 27379 |
arg_rtx = arm_function_arg (args_so_far, arg); |
| 27380 |
gcc_assert (REG_P (arg_rtx)); |
| 27381 |
if ((TREE_CODE (arg_type) == INTEGER_TYPE |
| 27382 |
|| TREE_CODE (arg_type) == ENUMERAL_TYPE |
| 27383 |
|| TREE_CODE (arg_type) == BOOLEAN_TYPE) |
| 27384 |
&& known_lt (GET_MODE_SIZE (GET_MODE (arg_rtx)), 4)) |
| 27385 |
{ |
| 27386 |
rtx res_reg = gen_rtx_REG (SImode, REGNO (arg_rtx)); |
| 27387 |
if (TYPE_UNSIGNED (arg_type)) |
| 27388 |
emit_set_insn (res_reg, gen_rtx_ZERO_EXTEND (SImode, arg_rtx)); |
| 27389 |
else |
| 27390 |
{ |
| 27391 |
/* Signed-extension is a special case because of |
| 27392 |
thumb1_extendhisi2. */ |
| 27393 |
if (known_eq (GET_MODE_SIZE (GET_MODE (arg_rtx)), 2)) |
| 27394 |
emit_insn (gen_thumb1_extendhisi2 (res_reg, arg_rtx)); |
| 27395 |
else |
| 27396 |
emit_set_insn (res_reg, |
| 27397 |
gen_rtx_SIGN_EXTEND (SImode, arg_rtx)); |
| 27398 |
} |
| 27399 |
} |
| 27400 |
} |
| 27401 |
} |
| 27402 |
|
| 27403 |
/* Extract a mask of the ones we can give to the Thumb's push instruction. */ |
| 27404 |
l_mask = live_regs_mask & 0x40ff; |
| 27405 |
/* Then count how many other high registers will need to be pushed. */ |
| 27406 |
high_regs_pushed = bit_count (live_regs_mask & 0x0f00); |
| 27407 |
|
| 27408 |
if (crtl->args.pretend_args_size) |
| 27409 |
{ |
| 27410 |
rtx x = GEN_INT (-crtl->args.pretend_args_size); |
| 27411 |
|
| 27412 |
if (cfun->machine->uses_anonymous_args) |
| 27413 |
{ |
| 27414 |
int num_pushes = ARM_NUM_INTS (crtl->args.pretend_args_size); |
| 27415 |
unsigned long mask; |
| 27416 |
|
| 27417 |
mask = 1ul << (LAST_ARG_REGNUM + 1); |
| 27418 |
mask -= 1ul << (LAST_ARG_REGNUM + 1 - num_pushes); |
| 27419 |
|
| 27420 |
insn = thumb1_emit_multi_reg_push (mask, 0); |
| 27421 |
} |
| 27422 |
else |
| 27423 |
{ |
| 27424 |
insn = emit_insn (gen_addsi3 (stack_pointer_rtx, |
| 27425 |
stack_pointer_rtx, x)); |
| 27426 |
} |
| 27427 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 27428 |
} |
| 27429 |
|
| 27430 |
if (TARGET_BACKTRACE) |
| 27431 |
{ |
| 27432 |
HOST_WIDE_INT offset = 0; |
| 27433 |
unsigned work_register; |
| 27434 |
rtx work_reg, x, arm_hfp_rtx; |
| 27435 |
|
| 27436 |
/* We have been asked to create a stack backtrace structure. |
| 27437 |
The code looks like this: |
| 27438 |
|
| 27439 |
0 .align 2 |
| 27440 |
0 func: |
| 27441 |
0 sub SP, #16 Reserve space for 4 registers. |
| 27442 |
2 push {R7} Push low registers. |
| 27443 |
4 add R7, SP, #20 Get the stack pointer before the push. |
| 27444 |
6 str R7, [SP, #8] Store the stack pointer |
| 27445 |
(before reserving the space). |
| 27446 |
8 mov R7, PC Get hold of the start of this code + 12. |
| 27447 |
10 str R7, [SP, #16] Store it. |
| 27448 |
12 mov R7, FP Get hold of the current frame pointer. |
| 27449 |
14 str R7, [SP, #4] Store it. |
| 27450 |
16 mov R7, LR Get hold of the current return address. |
| 27451 |
18 str R7, [SP, #12] Store it. |
| 27452 |
20 add R7, SP, #16 Point at the start of the |
| 27453 |
backtrace structure. |
| 27454 |
22 mov FP, R7 Put this value into the frame pointer. */ |
| 27455 |
|
| 27456 |
work_register = thumb_find_work_register (live_regs_mask); |
| 27457 |
work_reg = gen_rtx_REG (SImode, work_register); |
| 27458 |
arm_hfp_rtx = gen_rtx_REG (SImode, ARM_HARD_FRAME_POINTER_REGNUM); |
| 27459 |
|
| 27460 |
insn = emit_insn (gen_addsi3 (stack_pointer_rtx, |
| 27461 |
stack_pointer_rtx, GEN_INT (-16))); |
| 27462 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 27463 |
|
| 27464 |
if (l_mask) |
| 27465 |
{ |
| 27466 |
insn = thumb1_emit_multi_reg_push (l_mask, l_mask); |
| 27467 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 27468 |
lr_needs_saving = false; |
| 27469 |
|
| 27470 |
offset = bit_count (l_mask) * UNITS_PER_WORD; |
| 27471 |
} |
| 27472 |
|
| 27473 |
x = GEN_INT (offset + 16 + crtl->args.pretend_args_size); |
| 27474 |
emit_insn (gen_addsi3 (work_reg, stack_pointer_rtx, x)); |
| 27475 |
|
| 27476 |
x = plus_constant (Pmode, stack_pointer_rtx, offset + 4); |
| 27477 |
x = gen_frame_mem (SImode, x); |
| 27478 |
emit_move_insn (x, work_reg); |
| 27479 |
|
| 27480 |
/* Make sure that the instruction fetching the PC is in the right place |
| 27481 |
to calculate "start of backtrace creation code + 12". */ |
| 27482 |
/* ??? The stores using the common WORK_REG ought to be enough to |
| 27483 |
prevent the scheduler from doing anything weird. Failing that |
| 27484 |
we could always move all of the following into an UNSPEC_VOLATILE. */ |
| 27485 |
if (l_mask) |
| 27486 |
{ |
| 27487 |
x = gen_rtx_REG (SImode, PC_REGNUM); |
| 27488 |
emit_move_insn (work_reg, x); |
| 27489 |
|
| 27490 |
x = plus_constant (Pmode, stack_pointer_rtx, offset + 12); |
| 27491 |
x = gen_frame_mem (SImode, x); |
| 27492 |
emit_move_insn (x, work_reg); |
| 27493 |
|
| 27494 |
emit_move_insn (work_reg, arm_hfp_rtx); |
| 27495 |
|
| 27496 |
x = plus_constant (Pmode, stack_pointer_rtx, offset); |
| 27497 |
x = gen_frame_mem (SImode, x); |
| 27498 |
emit_move_insn (x, work_reg); |
| 27499 |
} |
| 27500 |
else |
| 27501 |
{ |
| 27502 |
emit_move_insn (work_reg, arm_hfp_rtx); |
| 27503 |
|
| 27504 |
x = plus_constant (Pmode, stack_pointer_rtx, offset); |
| 27505 |
x = gen_frame_mem (SImode, x); |
| 27506 |
emit_move_insn (x, work_reg); |
| 27507 |
|
| 27508 |
x = gen_rtx_REG (SImode, PC_REGNUM); |
| 27509 |
emit_move_insn (work_reg, x); |
| 27510 |
|
| 27511 |
x = plus_constant (Pmode, stack_pointer_rtx, offset + 12); |
| 27512 |
x = gen_frame_mem (SImode, x); |
| 27513 |
emit_move_insn (x, work_reg); |
| 27514 |
} |
| 27515 |
|
| 27516 |
x = gen_rtx_REG (SImode, LR_REGNUM); |
| 27517 |
emit_move_insn (work_reg, x); |
| 27518 |
|
| 27519 |
x = plus_constant (Pmode, stack_pointer_rtx, offset + 8); |
| 27520 |
x = gen_frame_mem (SImode, x); |
| 27521 |
emit_move_insn (x, work_reg); |
| 27522 |
|
| 27523 |
x = GEN_INT (offset + 12); |
| 27524 |
emit_insn (gen_addsi3 (work_reg, stack_pointer_rtx, x)); |
| 27525 |
|
| 27526 |
emit_move_insn (arm_hfp_rtx, work_reg); |
| 27527 |
} |
| 27528 |
/* Optimization: If we are not pushing any low registers but we are going |
| 27529 |
to push some high registers then delay our first push. This will just |
| 27530 |
be a push of LR and we can combine it with the push of the first high |
| 27531 |
register. */ |
| 27532 |
else if ((l_mask & 0xff) != 0 |
| 27533 |
|| (high_regs_pushed == 0 && lr_needs_saving)) |
| 27534 |
{ |
| 27535 |
unsigned long mask = l_mask; |
| 27536 |
mask |= (1 << thumb1_extra_regs_pushed (offsets, true)) - 1; |
| 27537 |
insn = thumb1_emit_multi_reg_push (mask, mask); |
| 27538 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 27539 |
lr_needs_saving = false; |
| 27540 |
} |
| 27541 |
|
| 27542 |
if (high_regs_pushed) |
| 27543 |
{ |
| 27544 |
unsigned pushable_regs; |
| 27545 |
unsigned next_hi_reg; |
| 27546 |
unsigned arg_regs_num = TARGET_AAPCS_BASED ? crtl->args.info.aapcs_ncrn |
| 27547 |
: crtl->args.info.nregs; |
| 27548 |
unsigned arg_regs_mask = (1 << arg_regs_num) - 1; |
| 27549 |
|
| 27550 |
for (next_hi_reg = 12; next_hi_reg > LAST_LO_REGNUM; next_hi_reg--) |
| 27551 |
if (live_regs_mask & (1 << next_hi_reg)) |
| 27552 |
break; |
| 27553 |
|
| 27554 |
/* Here we need to mask out registers used for passing arguments |
| 27555 |
even if they can be pushed. This is to avoid using them to |
| 27556 |
stash the high registers. Such kind of stash may clobber the |
| 27557 |
use of arguments. */ |
| 27558 |
pushable_regs = l_mask & (~arg_regs_mask); |
| 27559 |
pushable_regs |= thumb1_prologue_unused_call_clobbered_lo_regs (); |
| 27560 |
|
| 27561 |
/* Normally, LR can be used as a scratch register once it has been |
| 27562 |
saved; but if the function examines its own return address then |
| 27563 |
the value is still live and we need to avoid using it. */ |
| 27564 |
bool return_addr_live |
| 27565 |
= REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)), |
| 27566 |
LR_REGNUM); |
| 27567 |
|
| 27568 |
if (lr_needs_saving || return_addr_live) |
| 27569 |
pushable_regs &= ~(1 << LR_REGNUM); |
| 27570 |
|
| 27571 |
if (pushable_regs == 0) |
| 27572 |
pushable_regs = 1 << thumb_find_work_register (live_regs_mask); |
| 27573 |
|
| 27574 |
while (high_regs_pushed > 0) |
| 27575 |
{ |
| 27576 |
unsigned long real_regs_mask = 0; |
| 27577 |
unsigned long push_mask = 0; |
| 27578 |
|
| 27579 |
for (regno = LR_REGNUM; regno >= 0; regno --) |
| 27580 |
{ |
| 27581 |
if (pushable_regs & (1 << regno)) |
| 27582 |
{ |
| 27583 |
emit_move_insn (gen_rtx_REG (SImode, regno), |
| 27584 |
gen_rtx_REG (SImode, next_hi_reg)); |
| 27585 |
|
| 27586 |
high_regs_pushed --; |
| 27587 |
real_regs_mask |= (1 << next_hi_reg); |
| 27588 |
push_mask |= (1 << regno); |
| 27589 |
|
| 27590 |
if (high_regs_pushed) |
| 27591 |
{ |
| 27592 |
for (next_hi_reg --; next_hi_reg > LAST_LO_REGNUM; |
| 27593 |
next_hi_reg --) |
| 27594 |
if (live_regs_mask & (1 << next_hi_reg)) |
| 27595 |
break; |
| 27596 |
} |
| 27597 |
else |
| 27598 |
break; |
| 27599 |
} |
| 27600 |
} |
| 27601 |
|
| 27602 |
/* If we had to find a work register and we have not yet |
| 27603 |
saved the LR then add it to the list of regs to push. */ |
| 27604 |
if (lr_needs_saving) |
| 27605 |
{ |
| 27606 |
push_mask |= 1 << LR_REGNUM; |
| 27607 |
real_regs_mask |= 1 << LR_REGNUM; |
| 27608 |
lr_needs_saving = false; |
| 27609 |
/* If the return address is not live at this point, we |
| 27610 |
can add LR to the list of registers that we can use |
| 27611 |
for pushes. */ |
| 27612 |
if (!return_addr_live) |
| 27613 |
pushable_regs |= 1 << LR_REGNUM; |
| 27614 |
} |
| 27615 |
|
| 27616 |
insn = thumb1_emit_multi_reg_push (push_mask, real_regs_mask); |
| 27617 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 27618 |
} |
| 27619 |
} |
| 27620 |
|
| 27621 |
/* Load the pic register before setting the frame pointer, |
| 27622 |
so we can use r7 as a temporary work register. */ |
| 27623 |
if (flag_pic && arm_pic_register != INVALID_REGNUM) |
| 27624 |
arm_load_pic_register (live_regs_mask, NULL_RTX); |
| 27625 |
|
| 27626 |
if (!frame_pointer_needed && CALLER_INTERWORKING_SLOT_SIZE > 0) |
| 27627 |
emit_move_insn (gen_rtx_REG (Pmode, ARM_HARD_FRAME_POINTER_REGNUM), |
| 27628 |
stack_pointer_rtx); |
| 27629 |
|
| 27630 |
size = offsets->outgoing_args - offsets->saved_args; |
| 27631 |
if (flag_stack_usage_info) |
| 27632 |
current_function_static_stack_size = size; |
| 27633 |
|
| 27634 |
/* If we have a frame, then do stack checking. FIXME: not implemented. */ |
| 27635 |
if ((flag_stack_check == STATIC_BUILTIN_STACK_CHECK |
| 27636 |
|| flag_stack_clash_protection) |
| 27637 |
&& size) |
| 27638 |
sorry ("%<-fstack-check=specific%> for Thumb-1"); |
| 27639 |
|
| 27640 |
amount = offsets->outgoing_args - offsets->saved_regs; |
| 27641 |
amount -= 4 * thumb1_extra_regs_pushed (offsets, true); |
| 27642 |
if (amount) |
| 27643 |
{ |
| 27644 |
if (amount < 512) |
| 27645 |
{ |
| 27646 |
insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
| 27647 |
GEN_INT (- amount))); |
| 27648 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 27649 |
} |
| 27650 |
else |
| 27651 |
{ |
| 27652 |
rtx reg, dwarf; |
| 27653 |
|
| 27654 |
/* The stack decrement is too big for an immediate value in a single |
| 27655 |
insn. In theory we could issue multiple subtracts, but after |
| 27656 |
three of them it becomes more space efficient to place the full |
| 27657 |
value in the constant pool and load into a register. (Also the |
| 27658 |
ARM debugger really likes to see only one stack decrement per |
| 27659 |
function). So instead we look for a scratch register into which |
| 27660 |
we can load the decrement, and then we subtract this from the |
| 27661 |
stack pointer. Unfortunately on the thumb the only available |
| 27662 |
scratch registers are the argument registers, and we cannot use |
| 27663 |
these as they may hold arguments to the function. Instead we |
| 27664 |
attempt to locate a call preserved register which is used by this |
| 27665 |
function. If we can find one, then we know that it will have |
| 27666 |
been pushed at the start of the prologue and so we can corrupt |
| 27667 |
it now. */ |
| 27668 |
for (regno = LAST_ARG_REGNUM + 1; regno <= LAST_LO_REGNUM; regno++) |
| 27669 |
if (live_regs_mask & (1 << regno)) |
| 27670 |
break; |
| 27671 |
|
| 27672 |
gcc_assert(regno <= LAST_LO_REGNUM); |
| 27673 |
|
| 27674 |
reg = gen_rtx_REG (SImode, regno); |
| 27675 |
|
| 27676 |
emit_insn (gen_movsi (reg, GEN_INT (- amount))); |
| 27677 |
|
| 27678 |
insn = emit_insn (gen_addsi3 (stack_pointer_rtx, |
| 27679 |
stack_pointer_rtx, reg)); |
| 27680 |
|
| 27681 |
dwarf = gen_rtx_SET (stack_pointer_rtx, |
| 27682 |
plus_constant (Pmode, stack_pointer_rtx, |
| 27683 |
-amount)); |
| 27684 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
| 27685 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 27686 |
} |
| 27687 |
} |
| 27688 |
|
| 27689 |
if (frame_pointer_needed) |
| 27690 |
thumb_set_frame_pointer (offsets); |
| 27691 |
|
| 27692 |
/* If we are profiling, make sure no instructions are scheduled before |
| 27693 |
the call to mcount. Similarly if the user has requested no |
| 27694 |
scheduling in the prolog. Similarly if we want non-call exceptions |
| 27695 |
using the EABI unwinder, to prevent faulting instructions from being |
| 27696 |
swapped with a stack adjustment. */ |
| 27697 |
if (crtl->profile || !TARGET_SCHED_PROLOG |
| 27698 |
|| (arm_except_unwind_info (&global_options) == UI_TARGET |
| 27699 |
&& cfun->can_throw_non_call_exceptions)) |
| 27700 |
emit_insn (gen_blockage ()); |
| 27701 |
|
| 27702 |
cfun->machine->lr_save_eliminated = !thumb_force_lr_save (); |
| 27703 |
if (live_regs_mask & 0xff) |
| 27704 |
cfun->machine->lr_save_eliminated = 0; |
| 27705 |
} |
| 27706 |
|
| 27707 |
/* Clear caller saved registers not used to pass return values and leaked |
| 27708 |
condition flags before exiting a cmse_nonsecure_entry function. */ |
| 27709 |
|
| 27710 |
void |
| 27711 |
cmse_nonsecure_entry_clear_before_return (void) |
| 27712 |
{ |
| 27713 |
bool clear_vfpregs = TARGET_HARD_FLOAT || TARGET_HAVE_FPCXT_CMSE; |
| 27714 |
int regno, maxregno = clear_vfpregs ? LAST_VFP_REGNUM : IP_REGNUM; |
| 27715 |
uint32_t padding_bits_to_clear = 0; |
| 27716 |
auto_sbitmap to_clear_bitmap (maxregno + 1); |
| 27717 |
rtx r1_reg, result_rtl, clearing_reg = NULL_RTX; |
| 27718 |
tree result_type; |
| 27719 |
|
| 27720 |
bitmap_clear (to_clear_bitmap); |
| 27721 |
bitmap_set_range (to_clear_bitmap, R0_REGNUM, NUM_ARG_REGS); |
| 27722 |
bitmap_set_bit (to_clear_bitmap, IP_REGNUM); |
| 27723 |
|
| 27724 |
/* If we are not dealing with -mfloat-abi=soft we will need to clear VFP |
| 27725 |
registers. */ |
| 27726 |
if (clear_vfpregs) |
| 27727 |
{ |
| 27728 |
int float_bits = D7_VFP_REGNUM - FIRST_VFP_REGNUM + 1; |
| 27729 |
|
| 27730 |
bitmap_set_range (to_clear_bitmap, FIRST_VFP_REGNUM, float_bits); |
| 27731 |
|
| 27732 |
if (!TARGET_HAVE_FPCXT_CMSE) |
| 27733 |
{ |
| 27734 |
/* Make sure we don't clear the two scratch registers used to clear |
| 27735 |
the relevant FPSCR bits in output_return_instruction. */ |
| 27736 |
emit_use (gen_rtx_REG (SImode, IP_REGNUM)); |
| 27737 |
bitmap_clear_bit (to_clear_bitmap, IP_REGNUM); |
| 27738 |
emit_use (gen_rtx_REG (SImode, 4)); |
| 27739 |
bitmap_clear_bit (to_clear_bitmap, 4); |
| 27740 |
} |
| 27741 |
} |
| 27742 |
|
| 27743 |
/* If the user has defined registers to be caller saved, these are no longer |
| 27744 |
restored by the function before returning and must thus be cleared for |
| 27745 |
security purposes. */ |
| 27746 |
for (regno = NUM_ARG_REGS; regno <= maxregno; regno++) |
| 27747 |
{ |
| 27748 |
/* We do not touch registers that can be used to pass arguments as per |
| 27749 |
the AAPCS, since these should never be made callee-saved by user |
| 27750 |
options. */ |
| 27751 |
if (IN_RANGE (regno, FIRST_VFP_REGNUM, D7_VFP_REGNUM)) |
| 27752 |
continue; |
| 27753 |
if (IN_RANGE (regno, IP_REGNUM, PC_REGNUM)) |
| 27754 |
continue; |
| 27755 |
if (!callee_saved_reg_p (regno) |
| 27756 |
&& (!IN_RANGE (regno, FIRST_VFP_REGNUM, LAST_VFP_REGNUM) |
| 27757 |
|| TARGET_HARD_FLOAT)) |
| 27758 |
bitmap_set_bit (to_clear_bitmap, regno); |
| 27759 |
} |
| 27760 |
|
| 27761 |
/* Make sure we do not clear the registers used to return the result in. */ |
| 27762 |
result_type = TREE_TYPE (DECL_RESULT (current_function_decl)); |
| 27763 |
if (!VOID_TYPE_P (result_type)) |
| 27764 |
{ |
| 27765 |
uint64_t to_clear_return_mask; |
| 27766 |
result_rtl = arm_function_value (result_type, current_function_decl, 0); |
| 27767 |
|
| 27768 |
/* No need to check that we return in registers, because we don't |
| 27769 |
support returning on stack yet. */ |
| 27770 |
gcc_assert (REG_P (result_rtl)); |
| 27771 |
to_clear_return_mask |
| 27772 |
= compute_not_to_clear_mask (result_type, result_rtl, 0, |
| 27773 |
&padding_bits_to_clear); |
| 27774 |
if (to_clear_return_mask) |
| 27775 |
{ |
| 27776 |
gcc_assert ((unsigned) maxregno < sizeof (long long) * __CHAR_BIT__); |
| 27777 |
for (regno = R0_REGNUM; regno <= maxregno; regno++) |
| 27778 |
{ |
| 27779 |
if (to_clear_return_mask & (1ULL << regno)) |
| 27780 |
bitmap_clear_bit (to_clear_bitmap, regno); |
| 27781 |
} |
| 27782 |
} |
| 27783 |
} |
| 27784 |
|
| 27785 |
if (padding_bits_to_clear != 0) |
| 27786 |
{ |
| 27787 |
int to_clear_bitmap_size = SBITMAP_SIZE ((sbitmap) to_clear_bitmap); |
| 27788 |
auto_sbitmap to_clear_arg_regs_bitmap (to_clear_bitmap_size); |
| 27789 |
|
| 27790 |
/* Padding_bits_to_clear is not 0 so we know we are dealing with |
| 27791 |
returning a composite type, which only uses r0. Let's make sure that |
| 27792 |
r1-r3 is cleared too. */ |
| 27793 |
bitmap_clear (to_clear_arg_regs_bitmap); |
| 27794 |
bitmap_set_range (to_clear_arg_regs_bitmap, R1_REGNUM, NUM_ARG_REGS - 1); |
| 27795 |
gcc_assert (bitmap_subset_p (to_clear_arg_regs_bitmap, to_clear_bitmap)); |
| 27796 |
} |
| 27797 |
|
| 27798 |
/* Clear full registers that leak before returning. */ |
| 27799 |
clearing_reg = gen_rtx_REG (SImode, TARGET_THUMB1 ? R0_REGNUM : LR_REGNUM); |
| 27800 |
r1_reg = gen_rtx_REG (SImode, R0_REGNUM + 1); |
| 27801 |
cmse_clear_registers (to_clear_bitmap, &padding_bits_to_clear, 1, r1_reg, |
| 27802 |
clearing_reg); |
| 27803 |
} |
| 27804 |
|
| 27805 |
/* Generate pattern *pop_multiple_with_stack_update_and_return if single |
| 27806 |
POP instruction can be generated. LR should be replaced by PC. All |
| 27807 |
the checks required are already done by USE_RETURN_INSN (). Hence, |
| 27808 |
all we really need to check here is if single register is to be |
| 27809 |
returned, or multiple register return. */ |
| 27810 |
void |
| 27811 |
thumb2_expand_return (bool simple_return) |
| 27812 |
{ |
| 27813 |
int i, num_regs; |
| 27814 |
unsigned long saved_regs_mask; |
| 27815 |
arm_stack_offsets *offsets; |
| 27816 |
|
| 27817 |
offsets = arm_get_frame_offsets (); |
| 27818 |
saved_regs_mask = offsets->saved_regs_mask; |
| 27819 |
|
| 27820 |
for (i = 0, num_regs = 0; i <= LAST_ARM_REGNUM; i++) |
| 27821 |
if (saved_regs_mask & (1 << i)) |
| 27822 |
num_regs++; |
| 27823 |
|
| 27824 |
if (!simple_return && saved_regs_mask) |
| 27825 |
{ |
| 27826 |
/* TODO: Verify that this path is never taken for cmse_nonsecure_entry |
| 27827 |
functions or adapt code to handle according to ACLE. This path should |
| 27828 |
not be reachable for cmse_nonsecure_entry functions though we prefer |
| 27829 |
to assert it for now to ensure that future code changes do not |
| 27830 |
silently change this behavior. */ |
| 27831 |
gcc_assert (!IS_CMSE_ENTRY (arm_current_func_type ())); |
| 27832 |
if (arm_current_function_pac_enabled_p ()) |
| 27833 |
{ |
| 27834 |
gcc_assert (!(saved_regs_mask & (1 << PC_REGNUM))); |
| 27835 |
arm_emit_multi_reg_pop (saved_regs_mask); |
| 27836 |
emit_insn (gen_aut_nop ()); |
| 27837 |
emit_jump_insn (simple_return_rtx); |
| 27838 |
} |
| 27839 |
/* Use LDR PC, [sp], #4. Only do this if not optimizing for size and |
| 27840 |
there's a known performance benefit (we don't know this exactly, but |
| 27841 |
preferring LDRD/STRD over LDM/STM is a reasonable proxy). */ |
| 27842 |
else if (num_regs == 1 |
| 27843 |
&& !optimize_size |
| 27844 |
&& current_tune->prefer_ldrd_strd) |
| 27845 |
{ |
| 27846 |
rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2)); |
| 27847 |
rtx reg = gen_rtx_REG (SImode, PC_REGNUM); |
| 27848 |
rtx addr = gen_rtx_MEM (SImode, |
| 27849 |
gen_rtx_POST_INC (SImode, |
| 27850 |
stack_pointer_rtx)); |
| 27851 |
set_mem_alias_set (addr, get_frame_alias_set ()); |
| 27852 |
XVECEXP (par, 0, 0) = ret_rtx; |
| 27853 |
XVECEXP (par, 0, 1) = gen_rtx_SET (reg, addr); |
| 27854 |
RTX_FRAME_RELATED_P (XVECEXP (par, 0, 1)) = 1; |
| 27855 |
emit_jump_insn (par); |
| 27856 |
} |
| 27857 |
else |
| 27858 |
{ |
| 27859 |
saved_regs_mask &= ~ (1 << LR_REGNUM); |
| 27860 |
saved_regs_mask |= (1 << PC_REGNUM); |
| 27861 |
arm_emit_multi_reg_pop (saved_regs_mask); |
| 27862 |
} |
| 27863 |
} |
| 27864 |
else |
| 27865 |
{ |
| 27866 |
if (IS_CMSE_ENTRY (arm_current_func_type ())) |
| 27867 |
cmse_nonsecure_entry_clear_before_return (); |
| 27868 |
emit_jump_insn (simple_return_rtx); |
| 27869 |
} |
| 27870 |
} |
| 27871 |
|
| 27872 |
void |
| 27873 |
thumb1_expand_epilogue (void) |
| 27874 |
{ |
| 27875 |
HOST_WIDE_INT amount; |
| 27876 |
arm_stack_offsets *offsets; |
| 27877 |
int regno; |
| 27878 |
|
| 27879 |
/* Naked functions don't have prologues. */ |
| 27880 |
if (IS_NAKED (arm_current_func_type ())) |
| 27881 |
return; |
| 27882 |
|
| 27883 |
offsets = arm_get_frame_offsets (); |
| 27884 |
amount = offsets->outgoing_args - offsets->saved_regs; |
| 27885 |
|
| 27886 |
if (frame_pointer_needed) |
| 27887 |
{ |
| 27888 |
emit_insn (gen_movsi (stack_pointer_rtx, hard_frame_pointer_rtx)); |
| 27889 |
amount = offsets->locals_base - offsets->saved_regs; |
| 27890 |
} |
| 27891 |
amount -= 4 * thumb1_extra_regs_pushed (offsets, false); |
| 27892 |
|
| 27893 |
gcc_assert (amount >= 0); |
| 27894 |
if (amount) |
| 27895 |
{ |
| 27896 |
emit_insn (gen_blockage ()); |
| 27897 |
|
| 27898 |
if (amount < 512) |
| 27899 |
emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
| 27900 |
GEN_INT (amount))); |
| 27901 |
else |
| 27902 |
{ |
| 27903 |
/* r3 is always free in the epilogue. */ |
| 27904 |
rtx reg = gen_rtx_REG (SImode, LAST_ARG_REGNUM); |
| 27905 |
|
| 27906 |
emit_insn (gen_movsi (reg, GEN_INT (amount))); |
| 27907 |
emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg)); |
| 27908 |
} |
| 27909 |
} |
| 27910 |
|
| 27911 |
/* Emit a USE (stack_pointer_rtx), so that |
| 27912 |
the stack adjustment will not be deleted. */ |
| 27913 |
emit_insn (gen_force_register_use (stack_pointer_rtx)); |
| 27914 |
|
| 27915 |
if (crtl->profile || !TARGET_SCHED_PROLOG) |
| 27916 |
emit_insn (gen_blockage ()); |
| 27917 |
|
| 27918 |
/* Emit a clobber for each insn that will be restored in the epilogue, |
| 27919 |
so that flow2 will get register lifetimes correct. */ |
| 27920 |
for (regno = 0; regno < 13; regno++) |
| 27921 |
if (reg_needs_saving_p (regno)) |
| 27922 |
emit_clobber (gen_rtx_REG (SImode, regno)); |
| 27923 |
|
| 27924 |
if (! df_regs_ever_live_p (LR_REGNUM)) |
| 27925 |
emit_use (gen_rtx_REG (SImode, LR_REGNUM)); |
| 27926 |
|
| 27927 |
/* Clear all caller-saved regs that are not used to return. */ |
| 27928 |
if (IS_CMSE_ENTRY (arm_current_func_type ())) |
| 27929 |
cmse_nonsecure_entry_clear_before_return (); |
| 27930 |
} |
| 27931 |
|
| 27932 |
/* Epilogue code for APCS frame. */ |
| 27933 |
static void |
| 27934 |
arm_expand_epilogue_apcs_frame (bool really_return) |
| 27935 |
{ |
| 27936 |
unsigned long func_type; |
| 27937 |
unsigned long saved_regs_mask; |
| 27938 |
int num_regs = 0; |
| 27939 |
int i; |
| 27940 |
int floats_from_frame = 0; |
| 27941 |
arm_stack_offsets *offsets; |
| 27942 |
|
| 27943 |
gcc_assert (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM); |
| 27944 |
func_type = arm_current_func_type (); |
| 27945 |
|
| 27946 |
/* Get frame offsets for ARM. */ |
| 27947 |
offsets = arm_get_frame_offsets (); |
| 27948 |
saved_regs_mask = offsets->saved_regs_mask; |
| 27949 |
|
| 27950 |
/* Find the offset of the floating-point save area in the frame. */ |
| 27951 |
floats_from_frame |
| 27952 |
= (offsets->saved_args |
| 27953 |
+ arm_compute_static_chain_stack_bytes () |
| 27954 |
- offsets->frame); |
| 27955 |
|
| 27956 |
/* Compute how many core registers saved and how far away the floats are. */ |
| 27957 |
for (i = 0; i <= LAST_ARM_REGNUM; i++) |
| 27958 |
if (saved_regs_mask & (1 << i)) |
| 27959 |
{ |
| 27960 |
num_regs++; |
| 27961 |
floats_from_frame += 4; |
| 27962 |
} |
| 27963 |
|
| 27964 |
if (TARGET_VFP_BASE) |
| 27965 |
{ |
| 27966 |
int start_reg; |
| 27967 |
rtx ip_rtx = gen_rtx_REG (SImode, IP_REGNUM); |
| 27968 |
|
| 27969 |
/* The offset is from IP_REGNUM. */ |
| 27970 |
int saved_size = arm_get_vfp_saved_size (); |
| 27971 |
if (saved_size > 0) |
| 27972 |
{ |
| 27973 |
rtx_insn *insn; |
| 27974 |
floats_from_frame += saved_size; |
| 27975 |
insn = emit_insn (gen_addsi3 (ip_rtx, |
| 27976 |
hard_frame_pointer_rtx, |
| 27977 |
GEN_INT (-floats_from_frame))); |
| 27978 |
arm_add_cfa_adjust_cfa_note (insn, -floats_from_frame, |
| 27979 |
ip_rtx, hard_frame_pointer_rtx); |
| 27980 |
} |
| 27981 |
|
| 27982 |
/* Generate VFP register multi-pop. */ |
| 27983 |
start_reg = FIRST_VFP_REGNUM; |
| 27984 |
|
| 27985 |
for (i = FIRST_VFP_REGNUM; i < LAST_VFP_REGNUM; i += 2) |
| 27986 |
/* Look for a case where a reg does not need restoring. */ |
| 27987 |
if (!reg_needs_saving_p (i) && !reg_needs_saving_p (i + 1)) |
| 27988 |
{ |
| 27989 |
if (start_reg != i) |
| 27990 |
arm_emit_vfp_multi_reg_pop (start_reg, |
| 27991 |
(i - start_reg) / 2, |
| 27992 |
gen_rtx_REG (SImode, |
| 27993 |
IP_REGNUM)); |
| 27994 |
start_reg = i + 2; |
| 27995 |
} |
| 27996 |
|
| 27997 |
/* Restore the remaining regs that we have discovered (or possibly |
| 27998 |
even all of them, if the conditional in the for loop never |
| 27999 |
fired). */ |
| 28000 |
if (start_reg != i) |
| 28001 |
arm_emit_vfp_multi_reg_pop (start_reg, |
| 28002 |
(i - start_reg) / 2, |
| 28003 |
gen_rtx_REG (SImode, IP_REGNUM)); |
| 28004 |
} |
| 28005 |
|
| 28006 |
if (TARGET_IWMMXT) |
| 28007 |
{ |
| 28008 |
/* The frame pointer is guaranteed to be non-double-word aligned, as |
| 28009 |
it is set to double-word-aligned old_stack_pointer - 4. */ |
| 28010 |
rtx_insn *insn; |
| 28011 |
int lrm_count = (num_regs % 2) ? (num_regs + 2) : (num_regs + 1); |
| 28012 |
|
| 28013 |
for (i = LAST_IWMMXT_REGNUM; i >= FIRST_IWMMXT_REGNUM; i--) |
| 28014 |
if (reg_needs_saving_p (i)) |
| 28015 |
{ |
| 28016 |
rtx addr = gen_frame_mem (V2SImode, |
| 28017 |
plus_constant (Pmode, hard_frame_pointer_rtx, |
| 28018 |
- lrm_count * 4)); |
| 28019 |
insn = emit_insn (gen_movsi (gen_rtx_REG (V2SImode, i), addr)); |
| 28020 |
REG_NOTES (insn) = alloc_reg_note (REG_CFA_RESTORE, |
| 28021 |
gen_rtx_REG (V2SImode, i), |
| 28022 |
NULL_RTX); |
| 28023 |
lrm_count += 2; |
| 28024 |
} |
| 28025 |
} |
| 28026 |
|
| 28027 |
/* saved_regs_mask should contain IP which contains old stack pointer |
| 28028 |
at the time of activation creation. Since SP and IP are adjacent registers, |
| 28029 |
we can restore the value directly into SP. */ |
| 28030 |
gcc_assert (saved_regs_mask & (1 << IP_REGNUM)); |
| 28031 |
saved_regs_mask &= ~(1 << IP_REGNUM); |
| 28032 |
saved_regs_mask |= (1 << SP_REGNUM); |
| 28033 |
|
| 28034 |
/* There are two registers left in saved_regs_mask - LR and PC. We |
| 28035 |
only need to restore LR (the return address), but to |
| 28036 |
save time we can load it directly into PC, unless we need a |
| 28037 |
special function exit sequence, or we are not really returning. */ |
| 28038 |
if (really_return |
| 28039 |
&& ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL |
| 28040 |
&& !crtl->calls_eh_return) |
| 28041 |
/* Delete LR from the register mask, so that LR on |
| 28042 |
the stack is loaded into the PC in the register mask. */ |
| 28043 |
saved_regs_mask &= ~(1 << LR_REGNUM); |
| 28044 |
else |
| 28045 |
saved_regs_mask &= ~(1 << PC_REGNUM); |
| 28046 |
|
| 28047 |
num_regs = bit_count (saved_regs_mask); |
| 28048 |
if ((offsets->outgoing_args != (1 + num_regs)) || cfun->calls_alloca) |
| 28049 |
{ |
| 28050 |
rtx_insn *insn; |
| 28051 |
emit_insn (gen_blockage ()); |
| 28052 |
/* Unwind the stack to just below the saved registers. */ |
| 28053 |
insn = emit_insn (gen_addsi3 (stack_pointer_rtx, |
| 28054 |
hard_frame_pointer_rtx, |
| 28055 |
GEN_INT (- 4 * num_regs))); |
| 28056 |
|
| 28057 |
arm_add_cfa_adjust_cfa_note (insn, - 4 * num_regs, |
| 28058 |
stack_pointer_rtx, hard_frame_pointer_rtx); |
| 28059 |
} |
| 28060 |
|
| 28061 |
arm_emit_multi_reg_pop (saved_regs_mask); |
| 28062 |
|
| 28063 |
if (IS_INTERRUPT (func_type)) |
| 28064 |
{ |
| 28065 |
/* Interrupt handlers will have pushed the |
| 28066 |
IP onto the stack, so restore it now. */ |
| 28067 |
rtx_insn *insn; |
| 28068 |
rtx addr = gen_rtx_MEM (SImode, |
| 28069 |
gen_rtx_POST_INC (SImode, |
| 28070 |
stack_pointer_rtx)); |
| 28071 |
set_mem_alias_set (addr, get_frame_alias_set ()); |
| 28072 |
insn = emit_insn (gen_movsi (gen_rtx_REG (SImode, IP_REGNUM), addr)); |
| 28073 |
REG_NOTES (insn) = alloc_reg_note (REG_CFA_RESTORE, |
| 28074 |
gen_rtx_REG (SImode, IP_REGNUM), |
| 28075 |
NULL_RTX); |
| 28076 |
} |
| 28077 |
|
| 28078 |
if (!really_return || (saved_regs_mask & (1 << PC_REGNUM))) |
| 28079 |
return; |
| 28080 |
|
| 28081 |
if (crtl->calls_eh_return) |
| 28082 |
emit_insn (gen_addsi3 (stack_pointer_rtx, |
| 28083 |
stack_pointer_rtx, |
| 28084 |
gen_rtx_REG (SImode, ARM_EH_STACKADJ_REGNUM))); |
| 28085 |
|
| 28086 |
if (IS_STACKALIGN (func_type)) |
| 28087 |
/* Restore the original stack pointer. Before prologue, the stack was |
| 28088 |
realigned and the original stack pointer saved in r0. For details, |
| 28089 |
see comment in arm_expand_prologue. */ |
| 28090 |
emit_insn (gen_movsi (stack_pointer_rtx, gen_rtx_REG (SImode, R0_REGNUM))); |
| 28091 |
|
| 28092 |
emit_jump_insn (simple_return_rtx); |
| 28093 |
} |
| 28094 |
|
| 28095 |
/* Generate RTL to represent ARM epilogue. Really_return is true if the |
| 28096 |
function is not a sibcall. */ |
| 28097 |
void |
| 28098 |
arm_expand_epilogue (bool really_return) |
| 28099 |
{ |
| 28100 |
unsigned long func_type; |
| 28101 |
unsigned long saved_regs_mask; |
| 28102 |
int num_regs = 0; |
| 28103 |
int i; |
| 28104 |
int amount; |
| 28105 |
arm_stack_offsets *offsets; |
| 28106 |
|
| 28107 |
func_type = arm_current_func_type (); |
| 28108 |
|
| 28109 |
/* Naked functions don't have epilogue. Hence, generate return pattern, and |
| 28110 |
let output_return_instruction take care of instruction emission if any. */ |
| 28111 |
if (IS_NAKED (func_type) |
| 28112 |
|| (IS_VOLATILE (func_type) && TARGET_ABORT_NORETURN)) |
| 28113 |
{ |
| 28114 |
if (really_return) |
| 28115 |
emit_jump_insn (simple_return_rtx); |
| 28116 |
return; |
| 28117 |
} |
| 28118 |
|
| 28119 |
/* If we are throwing an exception, then we really must be doing a |
| 28120 |
return, so we can't tail-call. */ |
| 28121 |
gcc_assert (!crtl->calls_eh_return || really_return); |
| 28122 |
|
| 28123 |
if (TARGET_APCS_FRAME && frame_pointer_needed && TARGET_ARM) |
| 28124 |
{ |
| 28125 |
arm_expand_epilogue_apcs_frame (really_return); |
| 28126 |
return; |
| 28127 |
} |
| 28128 |
|
| 28129 |
/* Get frame offsets for ARM. */ |
| 28130 |
offsets = arm_get_frame_offsets (); |
| 28131 |
saved_regs_mask = offsets->saved_regs_mask; |
| 28132 |
num_regs = bit_count (saved_regs_mask); |
| 28133 |
|
| 28134 |
if (frame_pointer_needed) |
| 28135 |
{ |
| 28136 |
rtx_insn *insn; |
| 28137 |
/* Restore stack pointer if necessary. */ |
| 28138 |
if (TARGET_ARM) |
| 28139 |
{ |
| 28140 |
/* In ARM mode, frame pointer points to first saved register. |
| 28141 |
Restore stack pointer to last saved register. */ |
| 28142 |
amount = offsets->frame - offsets->saved_regs; |
| 28143 |
|
| 28144 |
/* Force out any pending memory operations that reference stacked data |
| 28145 |
before stack de-allocation occurs. */ |
| 28146 |
emit_insn (gen_blockage ()); |
| 28147 |
insn = emit_insn (gen_addsi3 (stack_pointer_rtx, |
| 28148 |
hard_frame_pointer_rtx, |
| 28149 |
GEN_INT (amount))); |
| 28150 |
arm_add_cfa_adjust_cfa_note (insn, amount, |
| 28151 |
stack_pointer_rtx, |
| 28152 |
hard_frame_pointer_rtx); |
| 28153 |
|
| 28154 |
/* Emit USE(stack_pointer_rtx) to ensure that stack adjustment is not |
| 28155 |
deleted. */ |
| 28156 |
emit_insn (gen_force_register_use (stack_pointer_rtx)); |
| 28157 |
} |
| 28158 |
else |
| 28159 |
{ |
| 28160 |
/* In Thumb-2 mode, the frame pointer points to the last saved |
| 28161 |
register. */ |
| 28162 |
amount = offsets->locals_base - offsets->saved_regs; |
| 28163 |
if (amount) |
| 28164 |
{ |
| 28165 |
insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, |
| 28166 |
hard_frame_pointer_rtx, |
| 28167 |
GEN_INT (amount))); |
| 28168 |
arm_add_cfa_adjust_cfa_note (insn, amount, |
| 28169 |
hard_frame_pointer_rtx, |
| 28170 |
hard_frame_pointer_rtx); |
| 28171 |
} |
| 28172 |
|
| 28173 |
/* Force out any pending memory operations that reference stacked data |
| 28174 |
before stack de-allocation occurs. */ |
| 28175 |
emit_insn (gen_blockage ()); |
| 28176 |
insn = emit_insn (gen_movsi (stack_pointer_rtx, |
| 28177 |
hard_frame_pointer_rtx)); |
| 28178 |
arm_add_cfa_adjust_cfa_note (insn, 0, |
| 28179 |
stack_pointer_rtx, |
| 28180 |
hard_frame_pointer_rtx); |
| 28181 |
/* Emit USE(stack_pointer_rtx) to ensure that stack adjustment is not |
| 28182 |
deleted. */ |
| 28183 |
emit_insn (gen_force_register_use (stack_pointer_rtx)); |
| 28184 |
} |
| 28185 |
} |
| 28186 |
else |
| 28187 |
{ |
| 28188 |
/* Pop off outgoing args and local frame to adjust stack pointer to |
| 28189 |
last saved register. */ |
| 28190 |
amount = offsets->outgoing_args - offsets->saved_regs; |
| 28191 |
if (amount) |
| 28192 |
{ |
| 28193 |
rtx_insn *tmp; |
| 28194 |
/* Force out any pending memory operations that reference stacked data |
| 28195 |
before stack de-allocation occurs. */ |
| 28196 |
emit_insn (gen_blockage ()); |
| 28197 |
tmp = emit_insn (gen_addsi3 (stack_pointer_rtx, |
| 28198 |
stack_pointer_rtx, |
| 28199 |
GEN_INT (amount))); |
| 28200 |
arm_add_cfa_adjust_cfa_note (tmp, amount, |
| 28201 |
stack_pointer_rtx, stack_pointer_rtx); |
| 28202 |
/* Emit USE(stack_pointer_rtx) to ensure that stack adjustment is |
| 28203 |
not deleted. */ |
| 28204 |
emit_insn (gen_force_register_use (stack_pointer_rtx)); |
| 28205 |
} |
| 28206 |
} |
| 28207 |
|
| 28208 |
if (TARGET_VFP_BASE) |
| 28209 |
{ |
| 28210 |
/* Generate VFP register multi-pop. */ |
| 28211 |
int end_reg = LAST_VFP_REGNUM + 1; |
| 28212 |
|
| 28213 |
/* Scan the registers in reverse order. We need to match |
| 28214 |
any groupings made in the prologue and generate matching |
| 28215 |
vldm operations. The need to match groups is because, |
| 28216 |
unlike pop, vldm can only do consecutive regs. */ |
| 28217 |
for (i = LAST_VFP_REGNUM - 1; i >= FIRST_VFP_REGNUM; i -= 2) |
| 28218 |
/* Look for a case where a reg does not need restoring. */ |
| 28219 |
if (!reg_needs_saving_p (i) && !reg_needs_saving_p (i + 1)) |
| 28220 |
{ |
| 28221 |
/* Restore the regs discovered so far (from reg+2 to |
| 28222 |
end_reg). */ |
| 28223 |
if (end_reg > i + 2) |
| 28224 |
arm_emit_vfp_multi_reg_pop (i + 2, |
| 28225 |
(end_reg - (i + 2)) / 2, |
| 28226 |
stack_pointer_rtx); |
| 28227 |
end_reg = i; |
| 28228 |
} |
| 28229 |
|
| 28230 |
/* Restore the remaining regs that we have discovered (or possibly |
| 28231 |
even all of them, if the conditional in the for loop never |
| 28232 |
fired). */ |
| 28233 |
if (end_reg > i + 2) |
| 28234 |
arm_emit_vfp_multi_reg_pop (i + 2, |
| 28235 |
(end_reg - (i + 2)) / 2, |
| 28236 |
stack_pointer_rtx); |
| 28237 |
} |
| 28238 |
|
| 28239 |
if (TARGET_IWMMXT) |
| 28240 |
for (i = FIRST_IWMMXT_REGNUM; i <= LAST_IWMMXT_REGNUM; i++) |
| 28241 |
if (reg_needs_saving_p (i)) |
| 28242 |
{ |
| 28243 |
rtx_insn *insn; |
| 28244 |
rtx addr = gen_rtx_MEM (V2SImode, |
| 28245 |
gen_rtx_POST_INC (SImode, |
| 28246 |
stack_pointer_rtx)); |
| 28247 |
set_mem_alias_set (addr, get_frame_alias_set ()); |
| 28248 |
insn = emit_insn (gen_movsi (gen_rtx_REG (V2SImode, i), addr)); |
| 28249 |
REG_NOTES (insn) = alloc_reg_note (REG_CFA_RESTORE, |
| 28250 |
gen_rtx_REG (V2SImode, i), |
| 28251 |
NULL_RTX); |
| 28252 |
arm_add_cfa_adjust_cfa_note (insn, UNITS_PER_WORD, |
| 28253 |
stack_pointer_rtx, stack_pointer_rtx); |
| 28254 |
} |
| 28255 |
|
| 28256 |
if (saved_regs_mask) |
| 28257 |
{ |
| 28258 |
rtx insn; |
| 28259 |
bool return_in_pc = false; |
| 28260 |
|
| 28261 |
if (ARM_FUNC_TYPE (func_type) != ARM_FT_INTERWORKED |
| 28262 |
&& (TARGET_ARM || ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL) |
| 28263 |
&& !IS_CMSE_ENTRY (func_type) |
| 28264 |
&& !IS_STACKALIGN (func_type) |
| 28265 |
&& really_return |
| 28266 |
&& crtl->args.pretend_args_size == 0 |
| 28267 |
&& saved_regs_mask & (1 << LR_REGNUM) |
| 28268 |
&& !crtl->calls_eh_return |
| 28269 |
&& !arm_current_function_pac_enabled_p ()) |
| 28270 |
{ |
| 28271 |
saved_regs_mask &= ~(1 << LR_REGNUM); |
| 28272 |
saved_regs_mask |= (1 << PC_REGNUM); |
| 28273 |
return_in_pc = true; |
| 28274 |
} |
| 28275 |
|
| 28276 |
if (num_regs == 1 |
| 28277 |
&& !optimize_size |
| 28278 |
&& current_tune->prefer_ldrd_strd |
| 28279 |
&& !(IS_INTERRUPT (func_type) && return_in_pc)) |
| 28280 |
{ |
| 28281 |
for (i = 0; i <= LAST_ARM_REGNUM; i++) |
| 28282 |
if (saved_regs_mask & (1 << i)) |
| 28283 |
{ |
| 28284 |
rtx addr = gen_rtx_MEM (SImode, |
| 28285 |
gen_rtx_POST_INC (SImode, |
| 28286 |
stack_pointer_rtx)); |
| 28287 |
set_mem_alias_set (addr, get_frame_alias_set ()); |
| 28288 |
|
| 28289 |
if (i == PC_REGNUM) |
| 28290 |
{ |
| 28291 |
insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2)); |
| 28292 |
XVECEXP (insn, 0, 0) = ret_rtx; |
| 28293 |
XVECEXP (insn, 0, 1) = gen_rtx_SET (gen_rtx_REG (SImode, i), |
| 28294 |
addr); |
| 28295 |
RTX_FRAME_RELATED_P (XVECEXP (insn, 0, 1)) = 1; |
| 28296 |
insn = emit_jump_insn (insn); |
| 28297 |
} |
| 28298 |
else |
| 28299 |
{ |
| 28300 |
insn = emit_insn (gen_movsi (gen_rtx_REG (SImode, i), |
| 28301 |
addr)); |
| 28302 |
REG_NOTES (insn) = alloc_reg_note (REG_CFA_RESTORE, |
| 28303 |
gen_rtx_REG (SImode, i), |
| 28304 |
NULL_RTX); |
| 28305 |
arm_add_cfa_adjust_cfa_note (insn, UNITS_PER_WORD, |
| 28306 |
stack_pointer_rtx, |
| 28307 |
stack_pointer_rtx); |
| 28308 |
} |
| 28309 |
} |
| 28310 |
} |
| 28311 |
else |
| 28312 |
{ |
| 28313 |
if (TARGET_LDRD |
| 28314 |
&& current_tune->prefer_ldrd_strd |
| 28315 |
&& !optimize_function_for_size_p (cfun)) |
| 28316 |
{ |
| 28317 |
if (TARGET_THUMB2) |
| 28318 |
thumb2_emit_ldrd_pop (saved_regs_mask); |
| 28319 |
else if (TARGET_ARM && !IS_INTERRUPT (func_type)) |
| 28320 |
arm_emit_ldrd_pop (saved_regs_mask); |
| 28321 |
else |
| 28322 |
arm_emit_multi_reg_pop (saved_regs_mask); |
| 28323 |
} |
| 28324 |
else |
| 28325 |
arm_emit_multi_reg_pop (saved_regs_mask); |
| 28326 |
} |
| 28327 |
|
| 28328 |
if (return_in_pc) |
| 28329 |
return; |
| 28330 |
} |
| 28331 |
|
| 28332 |
amount |
| 28333 |
= crtl->args.pretend_args_size + arm_compute_static_chain_stack_bytes(); |
| 28334 |
if (amount) |
| 28335 |
{ |
| 28336 |
int i, j; |
| 28337 |
rtx dwarf = NULL_RTX; |
| 28338 |
rtx_insn *tmp = |
| 28339 |
emit_insn (gen_addsi3 (stack_pointer_rtx, |
| 28340 |
stack_pointer_rtx, |
| 28341 |
GEN_INT (amount))); |
| 28342 |
|
| 28343 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 28344 |
|
| 28345 |
if (cfun->machine->uses_anonymous_args) |
| 28346 |
{ |
| 28347 |
/* Restore pretend args. Refer arm_expand_prologue on how to save |
| 28348 |
pretend_args in stack. */ |
| 28349 |
int num_regs = crtl->args.pretend_args_size / 4; |
| 28350 |
saved_regs_mask = (0xf0 >> num_regs) & 0xf; |
| 28351 |
for (j = 0, i = 0; j < num_regs; i++) |
| 28352 |
if (saved_regs_mask & (1 << i)) |
| 28353 |
{ |
| 28354 |
rtx reg = gen_rtx_REG (SImode, i); |
| 28355 |
dwarf = alloc_reg_note (REG_CFA_RESTORE, reg, dwarf); |
| 28356 |
j++; |
| 28357 |
} |
| 28358 |
REG_NOTES (tmp) = dwarf; |
| 28359 |
} |
| 28360 |
arm_add_cfa_adjust_cfa_note (tmp, amount, |
| 28361 |
stack_pointer_rtx, stack_pointer_rtx); |
| 28362 |
} |
| 28363 |
|
| 28364 |
if (IS_CMSE_ENTRY (func_type)) |
| 28365 |
{ |
| 28366 |
/* CMSE_ENTRY always returns. */ |
| 28367 |
gcc_assert (really_return); |
| 28368 |
/* Clear all caller-saved regs that are not used to return. */ |
| 28369 |
cmse_nonsecure_entry_clear_before_return (); |
| 28370 |
|
| 28371 |
/* Armv8.1-M Mainline nonsecure entry: restore FPCXTNS from stack using |
| 28372 |
VLDR. */ |
| 28373 |
if (TARGET_HAVE_FPCXT_CMSE) |
| 28374 |
{ |
| 28375 |
rtx_insn *insn; |
| 28376 |
|
| 28377 |
insn = emit_insn (gen_pop_fpsysreg_insn (stack_pointer_rtx, |
| 28378 |
GEN_INT (FPCXTNS_ENUM))); |
| 28379 |
rtx dwarf = gen_rtx_SET (stack_pointer_rtx, |
| 28380 |
plus_constant (Pmode, stack_pointer_rtx, 4)); |
| 28381 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
| 28382 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 28383 |
} |
| 28384 |
} |
| 28385 |
|
| 28386 |
if (arm_current_function_pac_enabled_p ()) |
| 28387 |
emit_insn (gen_aut_nop ()); |
| 28388 |
|
| 28389 |
if (!really_return) |
| 28390 |
return; |
| 28391 |
|
| 28392 |
if (crtl->calls_eh_return) |
| 28393 |
emit_insn (gen_addsi3 (stack_pointer_rtx, |
| 28394 |
stack_pointer_rtx, |
| 28395 |
gen_rtx_REG (SImode, ARM_EH_STACKADJ_REGNUM))); |
| 28396 |
|
| 28397 |
if (IS_STACKALIGN (func_type)) |
| 28398 |
/* Restore the original stack pointer. Before prologue, the stack was |
| 28399 |
realigned and the original stack pointer saved in r0. For details, |
| 28400 |
see comment in arm_expand_prologue. */ |
| 28401 |
emit_insn (gen_movsi (stack_pointer_rtx, gen_rtx_REG (SImode, R0_REGNUM))); |
| 28402 |
|
| 28403 |
emit_jump_insn (simple_return_rtx); |
| 28404 |
} |
| 28405 |
|
| 28406 |
/* Implementation of insn prologue_thumb1_interwork. This is the first |
| 28407 |
"instruction" of a function called in ARM mode. Swap to thumb mode. */ |
| 28408 |
|
| 28409 |
const char * |
| 28410 |
thumb1_output_interwork (void) |
| 28411 |
{ |
| 28412 |
const char * name; |
| 28413 |
FILE *f = asm_out_file; |
| 28414 |
|
| 28415 |
gcc_assert (MEM_P (DECL_RTL (current_function_decl))); |
| 28416 |
gcc_assert (GET_CODE (XEXP (DECL_RTL (current_function_decl), 0)) |
| 28417 |
== SYMBOL_REF); |
| 28418 |
name = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); |
| 28419 |
|
| 28420 |
/* Generate code sequence to switch us into Thumb mode. */ |
| 28421 |
/* The .code 32 directive has already been emitted by |
| 28422 |
ASM_DECLARE_FUNCTION_NAME. */ |
| 28423 |
asm_fprintf (f, "\torr\t%r, %r, #1\n", IP_REGNUM, PC_REGNUM); |
| 28424 |
asm_fprintf (f, "\tbx\t%r\n", IP_REGNUM); |
| 28425 |
|
| 28426 |
/* Generate a label, so that the debugger will notice the |
| 28427 |
change in instruction sets. This label is also used by |
| 28428 |
the assembler to bypass the ARM code when this function |
| 28429 |
is called from a Thumb encoded function elsewhere in the |
| 28430 |
same file. Hence the definition of STUB_NAME here must |
| 28431 |
agree with the definition in gas/config/tc-arm.c. */ |
| 28432 |
|
| 28433 |
#define STUB_NAME ".real_start_of" |
| 28434 |
|
| 28435 |
fprintf (f, "\t.code\t16\n"); |
| 28436 |
asm_fprintf (f, "\t.globl %s%U%s\n", STUB_NAME, name); |
| 28437 |
fprintf (f, "\t.thumb_func\n"); |
| 28438 |
asm_fprintf (f, "%s%U%s:\n", STUB_NAME, name); |
| 28439 |
|
| 28440 |
return ""; |
| 28441 |
} |
| 28442 |
|
| 28443 |
/* Handle the case of a double word load into a low register from |
| 28444 |
a computed memory address. The computed address may involve a |
| 28445 |
register which is overwritten by the load. */ |
| 28446 |
const char * |
| 28447 |
thumb_load_double_from_address (rtx *operands) |
| 28448 |
{ |
| 28449 |
rtx addr; |
| 28450 |
rtx base; |
| 28451 |
rtx offset; |
| 28452 |
rtx arg1; |
| 28453 |
rtx arg2; |
| 28454 |
|
| 28455 |
gcc_assert (REG_P (operands[0])); |
| 28456 |
gcc_assert (MEM_P (operands[1])); |
| 28457 |
|
| 28458 |
/* Get the memory address. */ |
| 28459 |
addr = XEXP (operands[1], 0); |
| 28460 |
|
| 28461 |
/* Work out how the memory address is computed. */ |
| 28462 |
switch (GET_CODE (addr)) |
| 28463 |
{ |
| 28464 |
case REG: |
| 28465 |
if (reg_overlap_mentioned_p (addr, operands[0])) |
| 28466 |
output_asm_insn ("ldmia\t%m1, {%0, %H0}", operands); |
| 28467 |
else |
| 28468 |
{ |
| 28469 |
operands[2] = adjust_address (operands[1], SImode, 4); |
| 28470 |
output_asm_insn ("ldr\t%0, %1", operands); |
| 28471 |
output_asm_insn ("ldr\t%H0, %2", operands); |
| 28472 |
} |
| 28473 |
break; |
| 28474 |
|
| 28475 |
case CONST: |
| 28476 |
/* Compute <address> + 4 for the high order load. */ |
| 28477 |
operands[2] = adjust_address (operands[1], SImode, 4); |
| 28478 |
|
| 28479 |
output_asm_insn ("ldr\t%0, %1", operands); |
| 28480 |
output_asm_insn ("ldr\t%H0, %2", operands); |
| 28481 |
break; |
| 28482 |
|
| 28483 |
case PLUS: |
| 28484 |
arg1 = XEXP (addr, 0); |
| 28485 |
arg2 = XEXP (addr, 1); |
| 28486 |
|
| 28487 |
if (CONSTANT_P (arg1)) |
| 28488 |
base = arg2, offset = arg1; |
| 28489 |
else |
| 28490 |
base = arg1, offset = arg2; |
| 28491 |
|
| 28492 |
gcc_assert (REG_P (base)); |
| 28493 |
|
| 28494 |
/* Catch the case of <address> = <reg> + <reg> */ |
| 28495 |
if (REG_P (offset)) |
| 28496 |
{ |
| 28497 |
int reg_offset = REGNO (offset); |
| 28498 |
int reg_base = REGNO (base); |
| 28499 |
int reg_dest = REGNO (operands[0]); |
| 28500 |
|
| 28501 |
/* Add the base and offset registers together into the |
| 28502 |
higher destination register. */ |
| 28503 |
asm_fprintf (asm_out_file, "\tadd\t%r, %r, %r", |
| 28504 |
reg_dest + 1, reg_base, reg_offset); |
| 28505 |
|
| 28506 |
/* Load the lower destination register from the address in |
| 28507 |
the higher destination register. */ |
| 28508 |
asm_fprintf (asm_out_file, "\tldr\t%r, [%r, #0]", |
| 28509 |
reg_dest, reg_dest + 1); |
| 28510 |
|
| 28511 |
/* Load the higher destination register from its own address |
| 28512 |
plus 4. */ |
| 28513 |
asm_fprintf (asm_out_file, "\tldr\t%r, [%r, #4]", |
| 28514 |
reg_dest + 1, reg_dest + 1); |
| 28515 |
} |
| 28516 |
else |
| 28517 |
{ |
| 28518 |
/* Compute <address> + 4 for the high order load. */ |
| 28519 |
operands[2] = adjust_address (operands[1], SImode, 4); |
| 28520 |
|
| 28521 |
/* If the computed address is held in the low order register |
| 28522 |
then load the high order register first, otherwise always |
| 28523 |
load the low order register first. */ |
| 28524 |
if (REGNO (operands[0]) == REGNO (base)) |
| 28525 |
{ |
| 28526 |
output_asm_insn ("ldr\t%H0, %2", operands); |
| 28527 |
output_asm_insn ("ldr\t%0, %1", operands); |
| 28528 |
} |
| 28529 |
else |
| 28530 |
{ |
| 28531 |
output_asm_insn ("ldr\t%0, %1", operands); |
| 28532 |
output_asm_insn ("ldr\t%H0, %2", operands); |
| 28533 |
} |
| 28534 |
} |
| 28535 |
break; |
| 28536 |
|
| 28537 |
case LABEL_REF: |
| 28538 |
/* With no registers to worry about we can just load the value |
| 28539 |
directly. */ |
| 28540 |
operands[2] = adjust_address (operands[1], SImode, 4); |
| 28541 |
|
| 28542 |
output_asm_insn ("ldr\t%H0, %2", operands); |
| 28543 |
output_asm_insn ("ldr\t%0, %1", operands); |
| 28544 |
break; |
| 28545 |
|
| 28546 |
default: |
| 28547 |
gcc_unreachable (); |
| 28548 |
} |
| 28549 |
|
| 28550 |
return ""; |
| 28551 |
} |
| 28552 |
|
| 28553 |
const char * |
| 28554 |
thumb_output_move_mem_multiple (int n, rtx *operands) |
| 28555 |
{ |
| 28556 |
switch (n) |
| 28557 |
{ |
| 28558 |
case 2: |
| 28559 |
if (REGNO (operands[4]) > REGNO (operands[5])) |
| 28560 |
std::swap (operands[4], operands[5]); |
| 28561 |
|
| 28562 |
output_asm_insn ("ldmia\t%1!, {%4, %5}", operands); |
| 28563 |
output_asm_insn ("stmia\t%0!, {%4, %5}", operands); |
| 28564 |
break; |
| 28565 |
|
| 28566 |
case 3: |
| 28567 |
if (REGNO (operands[4]) > REGNO (operands[5])) |
| 28568 |
std::swap (operands[4], operands[5]); |
| 28569 |
if (REGNO (operands[5]) > REGNO (operands[6])) |
| 28570 |
std::swap (operands[5], operands[6]); |
| 28571 |
if (REGNO (operands[4]) > REGNO (operands[5])) |
| 28572 |
std::swap (operands[4], operands[5]); |
| 28573 |
|
| 28574 |
output_asm_insn ("ldmia\t%1!, {%4, %5, %6}", operands); |
| 28575 |
output_asm_insn ("stmia\t%0!, {%4, %5, %6}", operands); |
| 28576 |
break; |
| 28577 |
|
| 28578 |
default: |
| 28579 |
gcc_unreachable (); |
| 28580 |
} |
| 28581 |
|
| 28582 |
return ""; |
| 28583 |
} |
| 28584 |
|
| 28585 |
/* Output a call-via instruction for thumb state. */ |
| 28586 |
const char * |
| 28587 |
thumb_call_via_reg (rtx reg) |
| 28588 |
{ |
| 28589 |
int regno = REGNO (reg); |
| 28590 |
rtx *labelp; |
| 28591 |
|
| 28592 |
gcc_assert (regno < LR_REGNUM); |
| 28593 |
|
| 28594 |
/* If we are in the normal text section we can use a single instance |
| 28595 |
per compilation unit. If we are doing function sections, then we need |
| 28596 |
an entry per section, since we can't rely on reachability. */ |
| 28597 |
if (in_section == text_section) |
| 28598 |
{ |
| 28599 |
thumb_call_reg_needed = 1; |
| 28600 |
|
| 28601 |
if (thumb_call_via_label[regno] == NULL) |
| 28602 |
thumb_call_via_label[regno] = gen_label_rtx (); |
| 28603 |
labelp = thumb_call_via_label + regno; |
| 28604 |
} |
| 28605 |
else |
| 28606 |
{ |
| 28607 |
if (cfun->machine->call_via[regno] == NULL) |
| 28608 |
cfun->machine->call_via[regno] = gen_label_rtx (); |
| 28609 |
labelp = cfun->machine->call_via + regno; |
| 28610 |
} |
| 28611 |
|
| 28612 |
output_asm_insn ("bl\t%a0", labelp); |
| 28613 |
return ""; |
| 28614 |
} |
| 28615 |
|
| 28616 |
/* Routines for generating rtl. */ |
| 28617 |
void |
| 28618 |
thumb_expand_cpymemqi (rtx *operands) |
| 28619 |
{ |
| 28620 |
rtx out = copy_to_mode_reg (SImode, XEXP (operands[0], 0)); |
| 28621 |
rtx in = copy_to_mode_reg (SImode, XEXP (operands[1], 0)); |
| 28622 |
HOST_WIDE_INT len = INTVAL (operands[2]); |
| 28623 |
HOST_WIDE_INT offset = 0; |
| 28624 |
|
| 28625 |
while (len >= 12) |
| 28626 |
{ |
| 28627 |
emit_insn (gen_cpymem12b (out, in, out, in)); |
| 28628 |
len -= 12; |
| 28629 |
} |
| 28630 |
|
| 28631 |
if (len >= 8) |
| 28632 |
{ |
| 28633 |
emit_insn (gen_cpymem8b (out, in, out, in)); |
| 28634 |
len -= 8; |
| 28635 |
} |
| 28636 |
|
| 28637 |
if (len >= 4) |
| 28638 |
{ |
| 28639 |
rtx reg = gen_reg_rtx (SImode); |
| 28640 |
emit_insn (gen_movsi (reg, gen_rtx_MEM (SImode, in))); |
| 28641 |
emit_insn (gen_movsi (gen_rtx_MEM (SImode, out), reg)); |
| 28642 |
len -= 4; |
| 28643 |
offset += 4; |
| 28644 |
} |
| 28645 |
|
| 28646 |
if (len >= 2) |
| 28647 |
{ |
| 28648 |
rtx reg = gen_reg_rtx (HImode); |
| 28649 |
emit_insn (gen_movhi (reg, gen_rtx_MEM (HImode, |
| 28650 |
plus_constant (Pmode, in, |
| 28651 |
offset)))); |
| 28652 |
emit_insn (gen_movhi (gen_rtx_MEM (HImode, plus_constant (Pmode, out, |
| 28653 |
offset)), |
| 28654 |
reg)); |
| 28655 |
len -= 2; |
| 28656 |
offset += 2; |
| 28657 |
} |
| 28658 |
|
| 28659 |
if (len) |
| 28660 |
{ |
| 28661 |
rtx reg = gen_reg_rtx (QImode); |
| 28662 |
emit_insn (gen_movqi (reg, gen_rtx_MEM (QImode, |
| 28663 |
plus_constant (Pmode, in, |
| 28664 |
offset)))); |
| 28665 |
emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (Pmode, out, |
| 28666 |
offset)), |
| 28667 |
reg)); |
| 28668 |
} |
| 28669 |
} |
| 28670 |
|
| 28671 |
void |
| 28672 |
thumb_reload_out_hi (rtx *operands) |
| 28673 |
{ |
| 28674 |
emit_insn (gen_thumb_movhi_clobber (operands[0], operands[1], operands[2])); |
| 28675 |
} |
| 28676 |
|
| 28677 |
/* Return the length of a function name prefix |
| 28678 |
that starts with the character 'c'. */ |
| 28679 |
static int |
| 28680 |
arm_get_strip_length (int c) |
| 28681 |
{ |
| 28682 |
switch (c) |
| 28683 |
{ |
| 28684 |
ARM_NAME_ENCODING_LENGTHS |
| 28685 |
default: return 0; |
| 28686 |
} |
| 28687 |
} |
| 28688 |
|
| 28689 |
/* Return a pointer to a function's name with any |
| 28690 |
and all prefix encodings stripped from it. */ |
| 28691 |
const char * |
| 28692 |
arm_strip_name_encoding (const char *name) |
| 28693 |
{ |
| 28694 |
int skip; |
| 28695 |
|
| 28696 |
while ((skip = arm_get_strip_length (* name))) |
| 28697 |
name += skip; |
| 28698 |
|
| 28699 |
return name; |
| 28700 |
} |
| 28701 |
|
| 28702 |
/* If there is a '*' anywhere in the name's prefix, then |
| 28703 |
emit the stripped name verbatim, otherwise prepend an |
| 28704 |
underscore if leading underscores are being used. */ |
| 28705 |
void |
| 28706 |
arm_asm_output_labelref (FILE *stream, const char *name) |
| 28707 |
{ |
| 28708 |
int skip; |
| 28709 |
int verbatim = 0; |
| 28710 |
|
| 28711 |
while ((skip = arm_get_strip_length (* name))) |
| 28712 |
{ |
| 28713 |
verbatim |= (*name == '*'); |
| 28714 |
name += skip; |
| 28715 |
} |
| 28716 |
|
| 28717 |
if (verbatim) |
| 28718 |
fputs (name, stream); |
| 28719 |
else |
| 28720 |
asm_fprintf (stream, "%U%s", name); |
| 28721 |
} |
| 28722 |
|
| 28723 |
/* This function is used to emit an EABI tag and its associated value. |
| 28724 |
We emit the numerical value of the tag in case the assembler does not |
| 28725 |
support textual tags. (Eg gas prior to 2.20). If requested we include |
| 28726 |
the tag name in a comment so that anyone reading the assembler output |
| 28727 |
will know which tag is being set. |
| 28728 |
|
| 28729 |
This function is not static because arm-c.cc needs it too. */ |
| 28730 |
|
| 28731 |
void |
| 28732 |
arm_emit_eabi_attribute (const char *name, int num, int val) |
| 28733 |
{ |
| 28734 |
asm_fprintf (asm_out_file, "\t.eabi_attribute %d, %d", num, val); |
| 28735 |
if (flag_verbose_asm || flag_debug_asm) |
| 28736 |
asm_fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, name); |
| 28737 |
asm_fprintf (asm_out_file, "\n"); |
| 28738 |
} |
| 28739 |
|
| 28740 |
/* This function is used to print CPU tuning information as comment |
| 28741 |
in assembler file. Pointers are not printed for now. */ |
| 28742 |
|
| 28743 |
void |
| 28744 |
arm_print_tune_info (void) |
| 28745 |
{ |
| 28746 |
asm_fprintf (asm_out_file, "\t" ASM_COMMENT_START ".tune parameters\n"); |
| 28747 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START "constant_limit:\t%d\n", |
| 28748 |
current_tune->constant_limit); |
| 28749 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START |
| 28750 |
"max_insns_skipped:\t%d\n", current_tune->max_insns_skipped); |
| 28751 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START |
| 28752 |
"prefetch.num_slots:\t%d\n", current_tune->prefetch.num_slots); |
| 28753 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START |
| 28754 |
"prefetch.l1_cache_size:\t%d\n", |
| 28755 |
current_tune->prefetch.l1_cache_size); |
| 28756 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START |
| 28757 |
"prefetch.l1_cache_line_size:\t%d\n", |
| 28758 |
current_tune->prefetch.l1_cache_line_size); |
| 28759 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START |
| 28760 |
"prefer_constant_pool:\t%d\n", |
| 28761 |
(int) current_tune->prefer_constant_pool); |
| 28762 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START |
| 28763 |
"branch_cost:\t(s:speed, p:predictable)\n"); |
| 28764 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START "\t\ts&p\tcost\n"); |
| 28765 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START "\t\t00\t%d\n", |
| 28766 |
current_tune->branch_cost (false, false)); |
| 28767 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START "\t\t01\t%d\n", |
| 28768 |
current_tune->branch_cost (false, true)); |
| 28769 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START "\t\t10\t%d\n", |
| 28770 |
current_tune->branch_cost (true, false)); |
| 28771 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START "\t\t11\t%d\n", |
| 28772 |
current_tune->branch_cost (true, true)); |
| 28773 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START |
| 28774 |
"prefer_ldrd_strd:\t%d\n", |
| 28775 |
(int) current_tune->prefer_ldrd_strd); |
| 28776 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START |
| 28777 |
"logical_op_non_short_circuit:\t[%d,%d]\n", |
| 28778 |
(int) current_tune->logical_op_non_short_circuit_thumb, |
| 28779 |
(int) current_tune->logical_op_non_short_circuit_arm); |
| 28780 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START |
| 28781 |
"disparage_flag_setting_t16_encodings:\t%d\n", |
| 28782 |
(int) current_tune->disparage_flag_setting_t16_encodings); |
| 28783 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START |
| 28784 |
"string_ops_prefer_neon:\t%d\n", |
| 28785 |
(int) current_tune->string_ops_prefer_neon); |
| 28786 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START |
| 28787 |
"max_insns_inline_memset:\t%d\n", |
| 28788 |
current_tune->max_insns_inline_memset); |
| 28789 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START "fusible_ops:\t%u\n", |
| 28790 |
current_tune->fusible_ops); |
| 28791 |
asm_fprintf (asm_out_file, "\t\t" ASM_COMMENT_START "sched_autopref:\t%d\n", |
| 28792 |
(int) current_tune->sched_autopref); |
| 28793 |
} |
| 28794 |
|
| 28795 |
/* The last set of target options used to emit .arch directives, etc. This |
| 28796 |
could be a function-local static if it were not required to expose it as a |
| 28797 |
root to the garbage collector. */ |
| 28798 |
static GTY(()) cl_target_option *last_asm_targ_options = NULL; |
| 28799 |
|
| 28800 |
/* Print .arch and .arch_extension directives corresponding to the |
| 28801 |
current architecture configuration. */ |
| 28802 |
static void |
| 28803 |
arm_print_asm_arch_directives (FILE *stream, cl_target_option *targ_options) |
| 28804 |
{ |
| 28805 |
arm_build_target build_target; |
| 28806 |
/* If the target options haven't changed since the last time we were called |
| 28807 |
there is nothing to do. This should be sufficient to suppress the |
| 28808 |
majority of redundant work. */ |
| 28809 |
if (last_asm_targ_options == targ_options) |
| 28810 |
return; |
| 28811 |
|
| 28812 |
last_asm_targ_options = targ_options; |
| 28813 |
|
| 28814 |
build_target.isa = sbitmap_alloc (isa_num_bits); |
| 28815 |
arm_configure_build_target (&build_target, targ_options, false); |
| 28816 |
|
| 28817 |
if (build_target.core_name |
| 28818 |
&& !bitmap_bit_p (build_target.isa, isa_bit_quirk_no_asmcpu)) |
| 28819 |
{ |
| 28820 |
const char* truncated_name |
| 28821 |
= arm_rewrite_selected_cpu (build_target.core_name); |
| 28822 |
asm_fprintf (stream, "\t.cpu %s\n", truncated_name); |
| 28823 |
} |
| 28824 |
|
| 28825 |
const arch_option *arch |
| 28826 |
= arm_parse_arch_option_name (all_architectures, "-march", |
| 28827 |
build_target.arch_name); |
| 28828 |
auto_sbitmap opt_bits (isa_num_bits); |
| 28829 |
|
| 28830 |
gcc_assert (arch); |
| 28831 |
|
| 28832 |
if (strcmp (build_target.arch_name, "armv7ve") == 0) |
| 28833 |
{ |
| 28834 |
/* Keep backward compatability for assemblers which don't support |
| 28835 |
armv7ve. Fortunately, none of the following extensions are reset |
| 28836 |
by a .fpu directive. */ |
| 28837 |
asm_fprintf (stream, "\t.arch armv7-a\n"); |
| 28838 |
asm_fprintf (stream, "\t.arch_extension virt\n"); |
| 28839 |
asm_fprintf (stream, "\t.arch_extension idiv\n"); |
| 28840 |
asm_fprintf (stream, "\t.arch_extension sec\n"); |
| 28841 |
asm_fprintf (stream, "\t.arch_extension mp\n"); |
| 28842 |
} |
| 28843 |
else |
| 28844 |
asm_fprintf (stream, "\t.arch %s\n", build_target.arch_name); |
| 28845 |
|
| 28846 |
/* The .fpu directive will reset any architecture extensions from the |
| 28847 |
assembler that relate to the fp/vector extensions. So put this out before |
| 28848 |
any .arch_extension directives. */ |
| 28849 |
const char *fpu_name = (TARGET_SOFT_FLOAT |
| 28850 |
? "softvfp" |
| 28851 |
: arm_identify_fpu_from_isa (build_target.isa)); |
| 28852 |
asm_fprintf (stream, "\t.fpu %s\n", fpu_name); |
| 28853 |
|
| 28854 |
if (!arch->common.extensions) |
| 28855 |
return; |
| 28856 |
|
| 28857 |
for (const struct cpu_arch_extension *opt = arch->common.extensions; |
| 28858 |
opt->name != NULL; |
| 28859 |
opt++) |
| 28860 |
{ |
| 28861 |
if (!opt->remove) |
| 28862 |
{ |
| 28863 |
arm_initialize_isa (opt_bits, opt->isa_bits); |
| 28864 |
|
| 28865 |
/* For the cases "-march=armv8.1-m.main+mve -mfloat-abi=soft" and |
| 28866 |
"-march=armv8.1-m.main+mve.fp -mfloat-abi=soft" MVE and MVE with |
| 28867 |
floating point instructions is disabled. So the following check |
| 28868 |
restricts the printing of ".arch_extension mve" and |
| 28869 |
".arch_extension fp" (for mve.fp) in the assembly file. MVE needs |
| 28870 |
this special behaviour because the feature bit "mve" and |
| 28871 |
"mve_float" are not part of "fpu bits", so they are not cleared |
| 28872 |
when -mfloat-abi=soft (i.e nofp) but the marco TARGET_HAVE_MVE and |
| 28873 |
TARGET_HAVE_MVE_FLOAT are disabled. */ |
| 28874 |
if ((bitmap_bit_p (opt_bits, isa_bit_mve) && !TARGET_HAVE_MVE) |
| 28875 |
|| (bitmap_bit_p (opt_bits, isa_bit_mve_float) |
| 28876 |
&& !TARGET_HAVE_MVE_FLOAT)) |
| 28877 |
continue; |
| 28878 |
|
| 28879 |
/* If every feature bit of this option is set in the target ISA |
| 28880 |
specification, print out the option name. However, don't print |
| 28881 |
anything if all the bits are part of the FPU specification. */ |
| 28882 |
if (bitmap_subset_p (opt_bits, build_target.isa) |
| 28883 |
&& !bitmap_subset_p (opt_bits, isa_all_fpubits_internal)) |
| 28884 |
asm_fprintf (stream, "\t.arch_extension %s\n", opt->name); |
| 28885 |
} |
| 28886 |
} |
| 28887 |
} |
| 28888 |
|
| 28889 |
static void |
| 28890 |
arm_file_start (void) |
| 28891 |
{ |
| 28892 |
int val; |
| 28893 |
bool pac = (aarch_ra_sign_scope != AARCH_FUNCTION_NONE); |
| 28894 |
bool bti = (aarch_enable_bti == 1); |
| 28895 |
|
| 28896 |
arm_print_asm_arch_directives |
| 28897 |
(asm_out_file, TREE_TARGET_OPTION (target_option_default_node)); |
| 28898 |
|
| 28899 |
if (TARGET_BPABI) |
| 28900 |
{ |
| 28901 |
/* If we have a named cpu, but we the assembler does not support that |
| 28902 |
name via .cpu, put out a cpu name attribute; but don't do this if the |
| 28903 |
name starts with the fictitious prefix, 'generic'. */ |
| 28904 |
if (arm_active_target.core_name |
| 28905 |
&& bitmap_bit_p (arm_active_target.isa, isa_bit_quirk_no_asmcpu) |
| 28906 |
&& !startswith (arm_active_target.core_name, "generic")) |
| 28907 |
{ |
| 28908 |
const char* truncated_name |
| 28909 |
= arm_rewrite_selected_cpu (arm_active_target.core_name); |
| 28910 |
if (bitmap_bit_p (arm_active_target.isa, isa_bit_quirk_no_asmcpu)) |
| 28911 |
asm_fprintf (asm_out_file, "\t.eabi_attribute 5, \"%s\"\n", |
| 28912 |
truncated_name); |
| 28913 |
} |
| 28914 |
|
| 28915 |
if (print_tune_info) |
| 28916 |
arm_print_tune_info (); |
| 28917 |
|
| 28918 |
if (TARGET_HARD_FLOAT && TARGET_VFP_SINGLE) |
| 28919 |
arm_emit_eabi_attribute ("Tag_ABI_HardFP_use", 27, 1); |
| 28920 |
|
| 28921 |
if (TARGET_HARD_FLOAT_ABI) |
| 28922 |
arm_emit_eabi_attribute ("Tag_ABI_VFP_args", 28, 1); |
| 28923 |
|
| 28924 |
/* Some of these attributes only apply when the corresponding features |
| 28925 |
are used. However we don't have any easy way of figuring this out. |
| 28926 |
Conservatively record the setting that would have been used. */ |
| 28927 |
|
| 28928 |
if (flag_rounding_math) |
| 28929 |
arm_emit_eabi_attribute ("Tag_ABI_FP_rounding", 19, 1); |
| 28930 |
|
| 28931 |
if (!flag_unsafe_math_optimizations) |
| 28932 |
{ |
| 28933 |
arm_emit_eabi_attribute ("Tag_ABI_FP_denormal", 20, 1); |
| 28934 |
arm_emit_eabi_attribute ("Tag_ABI_FP_exceptions", 21, 1); |
| 28935 |
} |
| 28936 |
if (flag_signaling_nans) |
| 28937 |
arm_emit_eabi_attribute ("Tag_ABI_FP_user_exceptions", 22, 1); |
| 28938 |
|
| 28939 |
arm_emit_eabi_attribute ("Tag_ABI_FP_number_model", 23, |
| 28940 |
flag_finite_math_only ? 1 : 3); |
| 28941 |
|
| 28942 |
arm_emit_eabi_attribute ("Tag_ABI_align8_needed", 24, 1); |
| 28943 |
arm_emit_eabi_attribute ("Tag_ABI_align8_preserved", 25, 1); |
| 28944 |
arm_emit_eabi_attribute ("Tag_ABI_enum_size", 26, |
| 28945 |
flag_short_enums ? 1 : 2); |
| 28946 |
|
| 28947 |
/* Tag_ABI_optimization_goals. */ |
| 28948 |
if (optimize_size) |
| 28949 |
val = 4; |
| 28950 |
else if (optimize >= 2) |
| 28951 |
val = 2; |
| 28952 |
else if (optimize) |
| 28953 |
val = 1; |
| 28954 |
else |
| 28955 |
val = 6; |
| 28956 |
arm_emit_eabi_attribute ("Tag_ABI_optimization_goals", 30, val); |
| 28957 |
|
| 28958 |
arm_emit_eabi_attribute ("Tag_CPU_unaligned_access", 34, |
| 28959 |
unaligned_access); |
| 28960 |
|
| 28961 |
if (arm_fp16_format) |
| 28962 |
arm_emit_eabi_attribute ("Tag_ABI_FP_16bit_format", 38, |
| 28963 |
(int) arm_fp16_format); |
| 28964 |
|
| 28965 |
if (TARGET_HAVE_PACBTI) |
| 28966 |
{ |
| 28967 |
arm_emit_eabi_attribute ("Tag_PAC_extension", 50, 2); |
| 28968 |
arm_emit_eabi_attribute ("Tag_BTI_extension", 52, 2); |
| 28969 |
} |
| 28970 |
else if (pac || bti) |
| 28971 |
{ |
| 28972 |
arm_emit_eabi_attribute ("Tag_PAC_extension", 50, 1); |
| 28973 |
arm_emit_eabi_attribute ("Tag_BTI_extension", 52, 1); |
| 28974 |
} |
| 28975 |
|
| 28976 |
if (bti) |
| 28977 |
arm_emit_eabi_attribute ("TAG_BTI_use", 74, 1); |
| 28978 |
if (pac) |
| 28979 |
arm_emit_eabi_attribute ("TAG_PACRET_use", 76, 1); |
| 28980 |
|
| 28981 |
if (arm_lang_output_object_attributes_hook) |
| 28982 |
arm_lang_output_object_attributes_hook(); |
| 28983 |
} |
| 28984 |
|
| 28985 |
default_file_start (); |
| 28986 |
} |
| 28987 |
|
| 28988 |
static void |
| 28989 |
arm_file_end (void) |
| 28990 |
{ |
| 28991 |
int regno; |
| 28992 |
|
| 28993 |
/* Just in case the last function output in the assembler had non-default |
| 28994 |
architecture directives, we force the assembler state back to the default |
| 28995 |
set, so that any 'calculated' build attributes are based on the default |
| 28996 |
options rather than the special options for that function. */ |
| 28997 |
arm_print_asm_arch_directives |
| 28998 |
(asm_out_file, TREE_TARGET_OPTION (target_option_default_node)); |
| 28999 |
|
| 29000 |
if (NEED_INDICATE_EXEC_STACK) |
| 29001 |
/* Add .note.GNU-stack. */ |
| 29002 |
file_end_indicate_exec_stack (); |
| 29003 |
|
| 29004 |
if (! thumb_call_reg_needed) |
| 29005 |
return; |
| 29006 |
|
| 29007 |
switch_to_section (text_section); |
| 29008 |
asm_fprintf (asm_out_file, "\t.code 16\n"); |
| 29009 |
ASM_OUTPUT_ALIGN (asm_out_file, 1); |
| 29010 |
|
| 29011 |
for (regno = 0; regno < LR_REGNUM; regno++) |
| 29012 |
{ |
| 29013 |
rtx label = thumb_call_via_label[regno]; |
| 29014 |
|
| 29015 |
if (label != 0) |
| 29016 |
{ |
| 29017 |
targetm.asm_out.internal_label (asm_out_file, "L", |
| 29018 |
CODE_LABEL_NUMBER (label)); |
| 29019 |
asm_fprintf (asm_out_file, "\tbx\t%r\n", regno); |
| 29020 |
} |
| 29021 |
} |
| 29022 |
} |
| 29023 |
|
| 29024 |
/* Symbols in the text segment can be accessed without indirecting via the |
| 29025 |
constant pool; it may take an extra binary operation, but this is still |
| 29026 |
faster than indirecting via memory. Don't do this when not optimizing, |
| 29027 |
since we won't be calculating al of the offsets necessary to do this |
| 29028 |
simplification. */ |
| 29029 |
|
| 29030 |
static void |
| 29031 |
arm_encode_section_info (tree decl, rtx rtl, int first) |
| 29032 |
{ |
| 29033 |
if (optimize > 0 && TREE_CONSTANT (decl)) |
| 29034 |
SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1; |
| 29035 |
|
| 29036 |
default_encode_section_info (decl, rtl, first); |
| 29037 |
} |
| 29038 |
|
| 29039 |
static void |
| 29040 |
arm_internal_label (FILE *stream, const char *prefix, unsigned long labelno) |
| 29041 |
{ |
| 29042 |
if (arm_ccfsm_state == 3 && (unsigned) arm_target_label == labelno |
| 29043 |
&& !strcmp (prefix, "L")) |
| 29044 |
{ |
| 29045 |
arm_ccfsm_state = 0; |
| 29046 |
arm_target_insn = NULL; |
| 29047 |
} |
| 29048 |
default_internal_label (stream, prefix, labelno); |
| 29049 |
} |
| 29050 |
|
| 29051 |
/* Define classes to generate code as RTL or output asm to a file. |
| 29052 |
Using templates then allows to use the same code to output code |
| 29053 |
sequences in the two formats. */ |
| 29054 |
class thumb1_const_rtl |
| 29055 |
{ |
| 29056 |
public: |
| 29057 |
thumb1_const_rtl (rtx dst) : dst (dst) {} |
| 29058 |
|
| 29059 |
void mov (HOST_WIDE_INT val) |
| 29060 |
{ |
| 29061 |
emit_set_insn (dst, GEN_INT (val)); |
| 29062 |
} |
| 29063 |
|
| 29064 |
void add (HOST_WIDE_INT val) |
| 29065 |
{ |
| 29066 |
emit_set_insn (dst, gen_rtx_PLUS (SImode, dst, GEN_INT (val))); |
| 29067 |
} |
| 29068 |
|
| 29069 |
void ashift (HOST_WIDE_INT shift) |
| 29070 |
{ |
| 29071 |
emit_set_insn (dst, gen_rtx_ASHIFT (SImode, dst, GEN_INT (shift))); |
| 29072 |
} |
| 29073 |
|
| 29074 |
void neg () |
| 29075 |
{ |
| 29076 |
emit_set_insn (dst, gen_rtx_NEG (SImode, dst)); |
| 29077 |
} |
| 29078 |
|
| 29079 |
private: |
| 29080 |
rtx dst; |
| 29081 |
}; |
| 29082 |
|
| 29083 |
class thumb1_const_print |
| 29084 |
{ |
| 29085 |
public: |
| 29086 |
thumb1_const_print (FILE *f, int regno) |
| 29087 |
{ |
| 29088 |
t_file = f; |
| 29089 |
dst_regname = reg_names[regno]; |
| 29090 |
} |
| 29091 |
|
| 29092 |
void mov (HOST_WIDE_INT val) |
| 29093 |
{ |
| 29094 |
asm_fprintf (t_file, "\tmovs\t%s, #" HOST_WIDE_INT_PRINT_DEC "\n", |
| 29095 |
dst_regname, val); |
| 29096 |
} |
| 29097 |
|
| 29098 |
void add (HOST_WIDE_INT val) |
| 29099 |
{ |
| 29100 |
asm_fprintf (t_file, "\tadds\t%s, #" HOST_WIDE_INT_PRINT_DEC "\n", |
| 29101 |
dst_regname, val); |
| 29102 |
} |
| 29103 |
|
| 29104 |
void ashift (HOST_WIDE_INT shift) |
| 29105 |
{ |
| 29106 |
asm_fprintf (t_file, "\tlsls\t%s, #" HOST_WIDE_INT_PRINT_DEC "\n", |
| 29107 |
dst_regname, shift); |
| 29108 |
} |
| 29109 |
|
| 29110 |
void neg () |
| 29111 |
{ |
| 29112 |
asm_fprintf (t_file, "\trsbs\t%s, #0\n", dst_regname); |
| 29113 |
} |
| 29114 |
|
| 29115 |
private: |
| 29116 |
FILE *t_file; |
| 29117 |
const char *dst_regname; |
| 29118 |
}; |
| 29119 |
|
| 29120 |
/* Emit a sequence of movs/adds/shift to produce a 32-bit constant. |
| 29121 |
Avoid generating useless code when one of the bytes is zero. */ |
| 29122 |
template <class T> |
| 29123 |
void |
| 29124 |
thumb1_gen_const_int_1 (T dst, HOST_WIDE_INT op1) |
| 29125 |
{ |
| 29126 |
bool mov_done_p = false; |
| 29127 |
unsigned HOST_WIDE_INT val = op1; |
| 29128 |
int shift = 0; |
| 29129 |
int i; |
| 29130 |
|
| 29131 |
gcc_assert (op1 == trunc_int_for_mode (op1, SImode)); |
| 29132 |
|
| 29133 |
if (val <= 255) |
| 29134 |
{ |
| 29135 |
dst.mov (val); |
| 29136 |
return; |
| 29137 |
} |
| 29138 |
|
| 29139 |
/* For negative numbers with the first nine bits set, build the |
| 29140 |
opposite of OP1, then negate it, it's generally shorter and not |
| 29141 |
longer. */ |
| 29142 |
if ((val & 0xFF800000) == 0xFF800000) |
| 29143 |
{ |
| 29144 |
thumb1_gen_const_int_1 (dst, -op1); |
| 29145 |
dst.neg (); |
| 29146 |
return; |
| 29147 |
} |
| 29148 |
|
| 29149 |
/* In the general case, we need 7 instructions to build |
| 29150 |
a 32 bits constant (1 movs, 3 lsls, 3 adds). We can |
| 29151 |
do better if VAL is small enough, or |
| 29152 |
right-shiftable by a suitable amount. If the |
| 29153 |
right-shift enables to encode at least one less byte, |
| 29154 |
it's worth it: we save a adds and a lsls at the |
| 29155 |
expense of a final lsls. */ |
| 29156 |
int final_shift = number_of_first_bit_set (val); |
| 29157 |
|
| 29158 |
int leading_zeroes = clz_hwi (val); |
| 29159 |
int number_of_bytes_needed |
| 29160 |
= ((HOST_BITS_PER_WIDE_INT - 1 - leading_zeroes) |
| 29161 |
/ BITS_PER_UNIT) + 1; |
| 29162 |
int number_of_bytes_needed2 |
| 29163 |
= ((HOST_BITS_PER_WIDE_INT - 1 - leading_zeroes - final_shift) |
| 29164 |
/ BITS_PER_UNIT) + 1; |
| 29165 |
|
| 29166 |
if (number_of_bytes_needed2 < number_of_bytes_needed) |
| 29167 |
val >>= final_shift; |
| 29168 |
else |
| 29169 |
final_shift = 0; |
| 29170 |
|
| 29171 |
/* If we are in a very small range, we can use either a single movs |
| 29172 |
or movs+adds. */ |
| 29173 |
if (val <= 510) |
| 29174 |
{ |
| 29175 |
if (val > 255) |
| 29176 |
{ |
| 29177 |
unsigned HOST_WIDE_INT high = val - 255; |
| 29178 |
|
| 29179 |
dst.mov (high); |
| 29180 |
dst.add (255); |
| 29181 |
} |
| 29182 |
else |
| 29183 |
dst.mov (val); |
| 29184 |
|
| 29185 |
if (final_shift > 0) |
| 29186 |
dst.ashift (final_shift); |
| 29187 |
} |
| 29188 |
else |
| 29189 |
{ |
| 29190 |
/* General case, emit upper 3 bytes as needed. */ |
| 29191 |
for (i = 0; i < 3; i++) |
| 29192 |
{ |
| 29193 |
unsigned HOST_WIDE_INT byte = (val >> (8 * (3 - i))) & 0xff; |
| 29194 |
|
| 29195 |
if (byte) |
| 29196 |
{ |
| 29197 |
/* We are about to emit new bits, stop accumulating a |
| 29198 |
shift amount, and left-shift only if we have already |
| 29199 |
emitted some upper bits. */ |
| 29200 |
if (mov_done_p) |
| 29201 |
{ |
| 29202 |
dst.ashift (shift); |
| 29203 |
dst.add (byte); |
| 29204 |
} |
| 29205 |
else |
| 29206 |
dst.mov (byte); |
| 29207 |
|
| 29208 |
/* Stop accumulating shift amount since we've just |
| 29209 |
emitted some bits. */ |
| 29210 |
shift = 0; |
| 29211 |
|
| 29212 |
mov_done_p = true; |
| 29213 |
} |
| 29214 |
|
| 29215 |
if (mov_done_p) |
| 29216 |
shift += 8; |
| 29217 |
} |
| 29218 |
|
| 29219 |
/* Emit lower byte. */ |
| 29220 |
if (!mov_done_p) |
| 29221 |
dst.mov (val & 0xff); |
| 29222 |
else |
| 29223 |
{ |
| 29224 |
dst.ashift (shift); |
| 29225 |
if (val & 0xff) |
| 29226 |
dst.add (val & 0xff); |
| 29227 |
} |
| 29228 |
|
| 29229 |
if (final_shift > 0) |
| 29230 |
dst.ashift (final_shift); |
| 29231 |
} |
| 29232 |
} |
| 29233 |
|
| 29234 |
/* Proxies for thumb1.md, since the thumb1_const_print and |
| 29235 |
thumb1_const_rtl classes are not exported. */ |
| 29236 |
void |
| 29237 |
thumb1_gen_const_int_rtl (rtx dst, HOST_WIDE_INT op1) |
| 29238 |
{ |
| 29239 |
thumb1_const_rtl t (dst); |
| 29240 |
thumb1_gen_const_int_1 (t, op1); |
| 29241 |
} |
| 29242 |
|
| 29243 |
void |
| 29244 |
thumb1_gen_const_int_print (rtx dst, HOST_WIDE_INT op1) |
| 29245 |
{ |
| 29246 |
thumb1_const_print t (asm_out_file, REGNO (dst)); |
| 29247 |
thumb1_gen_const_int_1 (t, op1); |
| 29248 |
} |
| 29249 |
|
| 29250 |
/* Output code to add DELTA to the first argument, and then jump |
| 29251 |
to FUNCTION. Used for C++ multiple inheritance. */ |
| 29252 |
|
| 29253 |
static void |
| 29254 |
arm_thumb1_mi_thunk (FILE *file, tree, HOST_WIDE_INT delta, |
| 29255 |
HOST_WIDE_INT, tree function) |
| 29256 |
{ |
| 29257 |
static int thunk_label = 0; |
| 29258 |
char label[256]; |
| 29259 |
char labelpc[256]; |
| 29260 |
int mi_delta = delta; |
| 29261 |
const char *const mi_op = mi_delta < 0 ? "sub" : "add"; |
| 29262 |
int shift = 0; |
| 29263 |
int this_regno = (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function) |
| 29264 |
? 1 : 0); |
| 29265 |
if (mi_delta < 0) |
| 29266 |
mi_delta = - mi_delta; |
| 29267 |
|
| 29268 |
final_start_function (emit_barrier (), file, 1); |
| 29269 |
|
| 29270 |
if (TARGET_THUMB1) |
| 29271 |
{ |
| 29272 |
int labelno = thunk_label++; |
| 29273 |
ASM_GENERATE_INTERNAL_LABEL (label, "LTHUMBFUNC", labelno); |
| 29274 |
/* Thunks are entered in arm mode when available. */ |
| 29275 |
if (TARGET_THUMB1_ONLY) |
| 29276 |
{ |
| 29277 |
/* push r3 so we can use it as a temporary. */ |
| 29278 |
/* TODO: Omit this save if r3 is not used. */ |
| 29279 |
fputs ("\tpush {r3}\n", file); |
| 29280 |
|
| 29281 |
/* With -mpure-code, we cannot load the address from the |
| 29282 |
constant pool: we build it explicitly. */ |
| 29283 |
if (target_pure_code) |
| 29284 |
{ |
| 29285 |
fputs ("\tmovs\tr3, #:upper8_15:#", file); |
| 29286 |
assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0)); |
| 29287 |
fputc ('\n', file); |
| 29288 |
fputs ("\tlsls r3, #8\n", file); |
| 29289 |
fputs ("\tadds\tr3, #:upper0_7:#", file); |
| 29290 |
assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0)); |
| 29291 |
fputc ('\n', file); |
| 29292 |
fputs ("\tlsls r3, #8\n", file); |
| 29293 |
fputs ("\tadds\tr3, #:lower8_15:#", file); |
| 29294 |
assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0)); |
| 29295 |
fputc ('\n', file); |
| 29296 |
fputs ("\tlsls r3, #8\n", file); |
| 29297 |
fputs ("\tadds\tr3, #:lower0_7:#", file); |
| 29298 |
assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0)); |
| 29299 |
fputc ('\n', file); |
| 29300 |
} |
| 29301 |
else |
| 29302 |
fputs ("\tldr\tr3, ", file); |
| 29303 |
} |
| 29304 |
else |
| 29305 |
{ |
| 29306 |
fputs ("\tldr\tr12, ", file); |
| 29307 |
} |
| 29308 |
|
| 29309 |
if (!target_pure_code) |
| 29310 |
{ |
| 29311 |
assemble_name (file, label); |
| 29312 |
fputc ('\n', file); |
| 29313 |
} |
| 29314 |
|
| 29315 |
if (flag_pic) |
| 29316 |
{ |
| 29317 |
/* If we are generating PIC, the ldr instruction below loads |
| 29318 |
"(target - 7) - .LTHUNKPCn" into r12. The pc reads as |
| 29319 |
the address of the add + 8, so we have: |
| 29320 |
|
| 29321 |
r12 = (target - 7) - .LTHUNKPCn + (.LTHUNKPCn + 8) |
| 29322 |
= target + 1. |
| 29323 |
|
| 29324 |
Note that we have "+ 1" because some versions of GNU ld |
| 29325 |
don't set the low bit of the result for R_ARM_REL32 |
| 29326 |
relocations against thumb function symbols. |
| 29327 |
On ARMv6M this is +4, not +8. */ |
| 29328 |
ASM_GENERATE_INTERNAL_LABEL (labelpc, "LTHUNKPC", labelno); |
| 29329 |
assemble_name (file, labelpc); |
| 29330 |
fputs (":\n", file); |
| 29331 |
if (TARGET_THUMB1_ONLY) |
| 29332 |
{ |
| 29333 |
/* This is 2 insns after the start of the thunk, so we know it |
| 29334 |
is 4-byte aligned. */ |
| 29335 |
fputs ("\tadd\tr3, pc, r3\n", file); |
| 29336 |
fputs ("\tmov r12, r3\n", file); |
| 29337 |
} |
| 29338 |
else |
| 29339 |
fputs ("\tadd\tr12, pc, r12\n", file); |
| 29340 |
} |
| 29341 |
else if (TARGET_THUMB1_ONLY) |
| 29342 |
fputs ("\tmov r12, r3\n", file); |
| 29343 |
} |
| 29344 |
if (TARGET_THUMB1_ONLY) |
| 29345 |
{ |
| 29346 |
if (mi_delta > 255) |
| 29347 |
{ |
| 29348 |
/* With -mpure-code, we cannot load MI_DELTA from the |
| 29349 |
constant pool: we build it explicitly. */ |
| 29350 |
if (target_pure_code) |
| 29351 |
{ |
| 29352 |
thumb1_const_print r3 (file, 3); |
| 29353 |
thumb1_gen_const_int_1 (r3, mi_delta); |
| 29354 |
} |
| 29355 |
else |
| 29356 |
{ |
| 29357 |
fputs ("\tldr\tr3, ", file); |
| 29358 |
assemble_name (file, label); |
| 29359 |
fputs ("+4\n", file); |
| 29360 |
} |
| 29361 |
asm_fprintf (file, "\t%ss\t%r, %r, r3\n", |
| 29362 |
mi_op, this_regno, this_regno); |
| 29363 |
} |
| 29364 |
else if (mi_delta != 0) |
| 29365 |
{ |
| 29366 |
/* Thumb1 unified syntax requires s suffix in instruction name when |
| 29367 |
one of the operands is immediate. */ |
| 29368 |
asm_fprintf (file, "\t%ss\t%r, %r, #%d\n", |
| 29369 |
mi_op, this_regno, this_regno, |
| 29370 |
mi_delta); |
| 29371 |
} |
| 29372 |
} |
| 29373 |
else |
| 29374 |
{ |
| 29375 |
/* TODO: Use movw/movt for large constants when available. */ |
| 29376 |
while (mi_delta != 0) |
| 29377 |
{ |
| 29378 |
if ((mi_delta & (3 << shift)) == 0) |
| 29379 |
shift += 2; |
| 29380 |
else |
| 29381 |
{ |
| 29382 |
asm_fprintf (file, "\t%s\t%r, %r, #%d\n", |
| 29383 |
mi_op, this_regno, this_regno, |
| 29384 |
mi_delta & (0xff << shift)); |
| 29385 |
mi_delta &= ~(0xff << shift); |
| 29386 |
shift += 8; |
| 29387 |
} |
| 29388 |
} |
| 29389 |
} |
| 29390 |
if (TARGET_THUMB1) |
| 29391 |
{ |
| 29392 |
if (TARGET_THUMB1_ONLY) |
| 29393 |
fputs ("\tpop\t{r3}\n", file); |
| 29394 |
|
| 29395 |
fprintf (file, "\tbx\tr12\n"); |
| 29396 |
|
| 29397 |
/* With -mpure-code, we don't need to emit literals for the |
| 29398 |
function address and delta since we emitted code to build |
| 29399 |
them. */ |
| 29400 |
if (!target_pure_code) |
| 29401 |
{ |
| 29402 |
ASM_OUTPUT_ALIGN (file, 2); |
| 29403 |
assemble_name (file, label); |
| 29404 |
fputs (":\n", file); |
| 29405 |
if (flag_pic) |
| 29406 |
{ |
| 29407 |
/* Output ".word .LTHUNKn-[3,7]-.LTHUNKPCn". */ |
| 29408 |
rtx tem = XEXP (DECL_RTL (function), 0); |
| 29409 |
/* For TARGET_THUMB1_ONLY the thunk is in Thumb mode, so the PC |
| 29410 |
pipeline offset is four rather than eight. Adjust the offset |
| 29411 |
accordingly. */ |
| 29412 |
tem = plus_constant (GET_MODE (tem), tem, |
| 29413 |
TARGET_THUMB1_ONLY ? -3 : -7); |
| 29414 |
tem = gen_rtx_MINUS (GET_MODE (tem), |
| 29415 |
tem, |
| 29416 |
gen_rtx_SYMBOL_REF (Pmode, |
| 29417 |
ggc_strdup (labelpc))); |
| 29418 |
assemble_integer (tem, 4, BITS_PER_WORD, 1); |
| 29419 |
} |
| 29420 |
else |
| 29421 |
/* Output ".word .LTHUNKn". */ |
| 29422 |
assemble_integer (XEXP (DECL_RTL (function), 0), 4, BITS_PER_WORD, 1); |
| 29423 |
|
| 29424 |
if (TARGET_THUMB1_ONLY && mi_delta > 255) |
| 29425 |
assemble_integer (GEN_INT (mi_delta), 4, BITS_PER_WORD, 1); |
| 29426 |
} |
| 29427 |
} |
| 29428 |
else |
| 29429 |
{ |
| 29430 |
fputs ("\tb\t", file); |
| 29431 |
assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0)); |
| 29432 |
if (NEED_PLT_RELOC) |
| 29433 |
fputs ("(PLT)", file); |
| 29434 |
fputc ('\n', file); |
| 29435 |
} |
| 29436 |
|
| 29437 |
final_end_function (); |
| 29438 |
} |
| 29439 |
|
| 29440 |
/* MI thunk handling for TARGET_32BIT. */ |
| 29441 |
|
| 29442 |
static void |
| 29443 |
arm32_output_mi_thunk (FILE *file, tree, HOST_WIDE_INT delta, |
| 29444 |
HOST_WIDE_INT vcall_offset, tree function) |
| 29445 |
{ |
| 29446 |
const bool long_call_p = arm_is_long_call_p (function); |
| 29447 |
|
| 29448 |
/* On ARM, this_regno is R0 or R1 depending on |
| 29449 |
whether the function returns an aggregate or not. |
| 29450 |
*/ |
| 29451 |
int this_regno = (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), |
| 29452 |
function) |
| 29453 |
? R1_REGNUM : R0_REGNUM); |
| 29454 |
|
| 29455 |
rtx temp = gen_rtx_REG (Pmode, IP_REGNUM); |
| 29456 |
rtx this_rtx = gen_rtx_REG (Pmode, this_regno); |
| 29457 |
reload_completed = 1; |
| 29458 |
emit_note (NOTE_INSN_PROLOGUE_END); |
| 29459 |
|
| 29460 |
/* Add DELTA to THIS_RTX. */ |
| 29461 |
if (delta != 0) |
| 29462 |
arm_split_constant (PLUS, Pmode, NULL_RTX, |
| 29463 |
delta, this_rtx, this_rtx, false); |
| 29464 |
|
| 29465 |
/* Add *(*THIS_RTX + VCALL_OFFSET) to THIS_RTX. */ |
| 29466 |
if (vcall_offset != 0) |
| 29467 |
{ |
| 29468 |
/* Load *THIS_RTX. */ |
| 29469 |
emit_move_insn (temp, gen_rtx_MEM (Pmode, this_rtx)); |
| 29470 |
/* Compute *THIS_RTX + VCALL_OFFSET. */ |
| 29471 |
arm_split_constant (PLUS, Pmode, NULL_RTX, vcall_offset, temp, temp, |
| 29472 |
false); |
| 29473 |
/* Compute *(*THIS_RTX + VCALL_OFFSET). */ |
| 29474 |
emit_move_insn (temp, gen_rtx_MEM (Pmode, temp)); |
| 29475 |
emit_insn (gen_add3_insn (this_rtx, this_rtx, temp)); |
| 29476 |
} |
| 29477 |
|
| 29478 |
/* Generate a tail call to the target function. */ |
| 29479 |
if (!TREE_USED (function)) |
| 29480 |
{ |
| 29481 |
assemble_external (function); |
| 29482 |
TREE_USED (function) = 1; |
| 29483 |
} |
| 29484 |
rtx funexp = XEXP (DECL_RTL (function), 0); |
| 29485 |
if (long_call_p) |
| 29486 |
{ |
| 29487 |
emit_move_insn (temp, funexp); |
| 29488 |
funexp = temp; |
| 29489 |
} |
| 29490 |
funexp = gen_rtx_MEM (FUNCTION_MODE, funexp); |
| 29491 |
rtx_insn *insn = emit_call_insn (gen_sibcall (funexp, const0_rtx, NULL_RTX)); |
| 29492 |
SIBLING_CALL_P (insn) = 1; |
| 29493 |
emit_barrier (); |
| 29494 |
|
| 29495 |
/* Indirect calls require a bit of fixup in PIC mode. */ |
| 29496 |
if (long_call_p) |
| 29497 |
{ |
| 29498 |
split_all_insns_noflow (); |
| 29499 |
arm_reorg (); |
| 29500 |
} |
| 29501 |
|
| 29502 |
insn = get_insns (); |
| 29503 |
shorten_branches (insn); |
| 29504 |
final_start_function (insn, file, 1); |
| 29505 |
final (insn, file, 1); |
| 29506 |
final_end_function (); |
| 29507 |
|
| 29508 |
/* Stop pretending this is a post-reload pass. */ |
| 29509 |
reload_completed = 0; |
| 29510 |
} |
| 29511 |
|
| 29512 |
/* Output code to add DELTA to the first argument, and then jump |
| 29513 |
to FUNCTION. Used for C++ multiple inheritance. */ |
| 29514 |
|
| 29515 |
static void |
| 29516 |
arm_output_mi_thunk (FILE *file, tree thunk, HOST_WIDE_INT delta, |
| 29517 |
HOST_WIDE_INT vcall_offset, tree function) |
| 29518 |
{ |
| 29519 |
const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk)); |
| 29520 |
|
| 29521 |
assemble_start_function (thunk, fnname); |
| 29522 |
if (aarch_bti_enabled ()) |
| 29523 |
emit_insn (aarch_gen_bti_c ()); |
| 29524 |
if (TARGET_32BIT) |
| 29525 |
arm32_output_mi_thunk (file, thunk, delta, vcall_offset, function); |
| 29526 |
else |
| 29527 |
arm_thumb1_mi_thunk (file, thunk, delta, vcall_offset, function); |
| 29528 |
assemble_end_function (thunk, fnname); |
| 29529 |
} |
| 29530 |
|
| 29531 |
int |
| 29532 |
arm_emit_vector_const (FILE *file, rtx x) |
| 29533 |
{ |
| 29534 |
int i; |
| 29535 |
const char * pattern; |
| 29536 |
|
| 29537 |
gcc_assert (GET_CODE (x) == CONST_VECTOR); |
| 29538 |
|
| 29539 |
switch (GET_MODE (x)) |
| 29540 |
{ |
| 29541 |
case E_V2SImode: pattern = "%08x"; break; |
| 29542 |
case E_V4HImode: pattern = "%04x"; break; |
| 29543 |
case E_V8QImode: pattern = "%02x"; break; |
| 29544 |
default: gcc_unreachable (); |
| 29545 |
} |
| 29546 |
|
| 29547 |
fprintf (file, "0x"); |
| 29548 |
for (i = CONST_VECTOR_NUNITS (x); i--;) |
| 29549 |
{ |
| 29550 |
rtx element; |
| 29551 |
|
| 29552 |
element = CONST_VECTOR_ELT (x, i); |
| 29553 |
fprintf (file, pattern, INTVAL (element)); |
| 29554 |
} |
| 29555 |
|
| 29556 |
return 1; |
| 29557 |
} |
| 29558 |
|
| 29559 |
/* Emit a fp16 constant appropriately padded to occupy a 4-byte word. |
| 29560 |
HFmode constant pool entries are actually loaded with ldr. */ |
| 29561 |
void |
| 29562 |
arm_emit_fp16_const (rtx c) |
| 29563 |
{ |
| 29564 |
long bits; |
| 29565 |
|
| 29566 |
bits = real_to_target (NULL, CONST_DOUBLE_REAL_VALUE (c), HFmode); |
| 29567 |
if (WORDS_BIG_ENDIAN) |
| 29568 |
assemble_zeros (2); |
| 29569 |
assemble_integer (GEN_INT (bits), 2, BITS_PER_WORD, 1); |
| 29570 |
if (!WORDS_BIG_ENDIAN) |
| 29571 |
assemble_zeros (2); |
| 29572 |
} |
| 29573 |
|
| 29574 |
const char * |
| 29575 |
arm_output_load_gr (rtx *operands) |
| 29576 |
{ |
| 29577 |
rtx reg; |
| 29578 |
rtx offset; |
| 29579 |
rtx wcgr; |
| 29580 |
rtx sum; |
| 29581 |
|
| 29582 |
if (!MEM_P (operands [1]) |
| 29583 |
|| GET_CODE (sum = XEXP (operands [1], 0)) != PLUS |
| 29584 |
|| !REG_P (reg = XEXP (sum, 0)) |
| 29585 |
|| !CONST_INT_P (offset = XEXP (sum, 1)) |
| 29586 |
|| ((INTVAL (offset) < 1024) && (INTVAL (offset) > -1024))) |
| 29587 |
return "wldrw%?\t%0, %1"; |
| 29588 |
|
| 29589 |
/* Fix up an out-of-range load of a GR register. */ |
| 29590 |
output_asm_insn ("str%?\t%0, [sp, #-4]!\t@ Start of GR load expansion", & reg); |
| 29591 |
wcgr = operands[0]; |
| 29592 |
operands[0] = reg; |
| 29593 |
output_asm_insn ("ldr%?\t%0, %1", operands); |
| 29594 |
|
| 29595 |
operands[0] = wcgr; |
| 29596 |
operands[1] = reg; |
| 29597 |
output_asm_insn ("tmcr%?\t%0, %1", operands); |
| 29598 |
output_asm_insn ("ldr%?\t%0, [sp], #4\t@ End of GR load expansion", & reg); |
| 29599 |
|
| 29600 |
return ""; |
| 29601 |
} |
| 29602 |
|
| 29603 |
/* Worker function for TARGET_SETUP_INCOMING_VARARGS. |
| 29604 |
|
| 29605 |
On the ARM, PRETEND_SIZE is set in order to have the prologue push the last |
| 29606 |
named arg and all anonymous args onto the stack. |
| 29607 |
XXX I know the prologue shouldn't be pushing registers, but it is faster |
| 29608 |
that way. */ |
| 29609 |
|
| 29610 |
static void |
| 29611 |
arm_setup_incoming_varargs (cumulative_args_t pcum_v, |
| 29612 |
const function_arg_info &arg, |
| 29613 |
int *pretend_size, |
| 29614 |
int second_time ATTRIBUTE_UNUSED) |
| 29615 |
{ |
| 29616 |
CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v); |
| 29617 |
int nregs; |
| 29618 |
|
| 29619 |
cfun->machine->uses_anonymous_args = 1; |
| 29620 |
if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) |
| 29621 |
{ |
| 29622 |
nregs = pcum->aapcs_ncrn; |
| 29623 |
if (!TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (current_function_decl)) |
| 29624 |
&& (nregs & 1)) |
| 29625 |
{ |
| 29626 |
int res = arm_needs_doubleword_align (arg.mode, arg.type); |
| 29627 |
if (res < 0 && warn_psabi) |
| 29628 |
inform (input_location, "parameter passing for argument of " |
| 29629 |
"type %qT changed in GCC 7.1", arg.type); |
| 29630 |
else if (res > 0) |
| 29631 |
{ |
| 29632 |
nregs++; |
| 29633 |
if (res > 1 && warn_psabi) |
| 29634 |
inform (input_location, |
| 29635 |
"parameter passing for argument of type " |
| 29636 |
"%qT changed in GCC 9.1", arg.type); |
| 29637 |
} |
| 29638 |
} |
| 29639 |
} |
| 29640 |
else |
| 29641 |
nregs = pcum->nregs; |
| 29642 |
|
| 29643 |
if (nregs < NUM_ARG_REGS) |
| 29644 |
*pretend_size = (NUM_ARG_REGS - nregs) * UNITS_PER_WORD; |
| 29645 |
} |
| 29646 |
|
| 29647 |
/* We can't rely on the caller doing the proper promotion when |
| 29648 |
using APCS or ATPCS. */ |
| 29649 |
|
| 29650 |
static bool |
| 29651 |
arm_promote_prototypes (const_tree t ATTRIBUTE_UNUSED) |
| 29652 |
{ |
| 29653 |
return !TARGET_AAPCS_BASED; |
| 29654 |
} |
| 29655 |
|
| 29656 |
static machine_mode |
| 29657 |
arm_promote_function_mode (const_tree type ATTRIBUTE_UNUSED, |
| 29658 |
machine_mode mode, |
| 29659 |
int *punsignedp ATTRIBUTE_UNUSED, |
| 29660 |
const_tree fntype ATTRIBUTE_UNUSED, |
| 29661 |
int for_return ATTRIBUTE_UNUSED) |
| 29662 |
{ |
| 29663 |
if (GET_MODE_CLASS (mode) == MODE_INT |
| 29664 |
&& GET_MODE_SIZE (mode) < 4) |
| 29665 |
return SImode; |
| 29666 |
|
| 29667 |
return mode; |
| 29668 |
} |
| 29669 |
|
| 29670 |
|
| 29671 |
static bool |
| 29672 |
arm_default_short_enums (void) |
| 29673 |
{ |
| 29674 |
return ARM_DEFAULT_SHORT_ENUMS; |
| 29675 |
} |
| 29676 |
|
| 29677 |
|
| 29678 |
/* AAPCS requires that anonymous bitfields affect structure alignment. */ |
| 29679 |
|
| 29680 |
static bool |
| 29681 |
arm_align_anon_bitfield (void) |
| 29682 |
{ |
| 29683 |
return TARGET_AAPCS_BASED; |
| 29684 |
} |
| 29685 |
|
| 29686 |
|
| 29687 |
/* The generic C++ ABI says 64-bit (long long). The EABI says 32-bit. */ |
| 29688 |
|
| 29689 |
static tree |
| 29690 |
arm_cxx_guard_type (void) |
| 29691 |
{ |
| 29692 |
return TARGET_AAPCS_BASED ? integer_type_node : long_long_integer_type_node; |
| 29693 |
} |
| 29694 |
|
| 29695 |
|
| 29696 |
/* The EABI says test the least significant bit of a guard variable. */ |
| 29697 |
|
| 29698 |
static bool |
| 29699 |
arm_cxx_guard_mask_bit (void) |
| 29700 |
{ |
| 29701 |
return TARGET_AAPCS_BASED; |
| 29702 |
} |
| 29703 |
|
| 29704 |
|
| 29705 |
/* The EABI specifies that all array cookies are 8 bytes long. */ |
| 29706 |
|
| 29707 |
static tree |
| 29708 |
arm_get_cookie_size (tree type) |
| 29709 |
{ |
| 29710 |
tree size; |
| 29711 |
|
| 29712 |
if (!TARGET_AAPCS_BASED) |
| 29713 |
return default_cxx_get_cookie_size (type); |
| 29714 |
|
| 29715 |
size = build_int_cst (sizetype, 8); |
| 29716 |
return size; |
| 29717 |
} |
| 29718 |
|
| 29719 |
|
| 29720 |
/* The EABI says that array cookies should also contain the element size. */ |
| 29721 |
|
| 29722 |
static bool |
| 29723 |
arm_cookie_has_size (void) |
| 29724 |
{ |
| 29725 |
return TARGET_AAPCS_BASED; |
| 29726 |
} |
| 29727 |
|
| 29728 |
|
| 29729 |
/* The EABI says constructors and destructors should return a pointer to |
| 29730 |
the object constructed/destroyed. */ |
| 29731 |
|
| 29732 |
static bool |
| 29733 |
arm_cxx_cdtor_returns_this (void) |
| 29734 |
{ |
| 29735 |
return TARGET_AAPCS_BASED; |
| 29736 |
} |
| 29737 |
|
| 29738 |
/* The EABI says that an inline function may never be the key |
| 29739 |
method. */ |
| 29740 |
|
| 29741 |
static bool |
| 29742 |
arm_cxx_key_method_may_be_inline (void) |
| 29743 |
{ |
| 29744 |
return !TARGET_AAPCS_BASED; |
| 29745 |
} |
| 29746 |
|
| 29747 |
static void |
| 29748 |
arm_cxx_determine_class_data_visibility (tree decl) |
| 29749 |
{ |
| 29750 |
if (!TARGET_AAPCS_BASED |
| 29751 |
|| !TARGET_DLLIMPORT_DECL_ATTRIBUTES) |
| 29752 |
return; |
| 29753 |
|
| 29754 |
/* In general, \S 3.2.5.5 of the ARM EABI requires that class data |
| 29755 |
is exported. However, on systems without dynamic vague linkage, |
| 29756 |
\S 3.2.5.6 says that COMDAT class data has hidden linkage. */ |
| 29757 |
if (!TARGET_ARM_DYNAMIC_VAGUE_LINKAGE_P && DECL_COMDAT (decl)) |
| 29758 |
DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; |
| 29759 |
else |
| 29760 |
DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; |
| 29761 |
DECL_VISIBILITY_SPECIFIED (decl) = 1; |
| 29762 |
} |
| 29763 |
|
| 29764 |
static bool |
| 29765 |
arm_cxx_class_data_always_comdat (void) |
| 29766 |
{ |
| 29767 |
/* \S 3.2.5.4 of the ARM C++ ABI says that class data only have |
| 29768 |
vague linkage if the class has no key function. */ |
| 29769 |
return !TARGET_AAPCS_BASED; |
| 29770 |
} |
| 29771 |
|
| 29772 |
|
| 29773 |
/* The EABI says __aeabi_atexit should be used to register static |
| 29774 |
destructors. */ |
| 29775 |
|
| 29776 |
static bool |
| 29777 |
arm_cxx_use_aeabi_atexit (void) |
| 29778 |
{ |
| 29779 |
return TARGET_AAPCS_BASED; |
| 29780 |
} |
| 29781 |
|
| 29782 |
|
| 29783 |
void |
| 29784 |
arm_set_return_address (rtx source, rtx scratch) |
| 29785 |
{ |
| 29786 |
arm_stack_offsets *offsets; |
| 29787 |
HOST_WIDE_INT delta; |
| 29788 |
rtx addr, mem; |
| 29789 |
unsigned long saved_regs; |
| 29790 |
|
| 29791 |
offsets = arm_get_frame_offsets (); |
| 29792 |
saved_regs = offsets->saved_regs_mask; |
| 29793 |
|
| 29794 |
if ((saved_regs & (1 << LR_REGNUM)) == 0) |
| 29795 |
emit_move_insn (gen_rtx_REG (Pmode, LR_REGNUM), source); |
| 29796 |
else |
| 29797 |
{ |
| 29798 |
if (frame_pointer_needed) |
| 29799 |
addr = plus_constant (Pmode, hard_frame_pointer_rtx, -4); |
| 29800 |
else |
| 29801 |
{ |
| 29802 |
/* LR will be the first saved register. */ |
| 29803 |
delta = offsets->outgoing_args - (offsets->frame + 4); |
| 29804 |
|
| 29805 |
|
| 29806 |
if (delta >= 4096) |
| 29807 |
{ |
| 29808 |
emit_insn (gen_addsi3 (scratch, stack_pointer_rtx, |
| 29809 |
GEN_INT (delta & ~4095))); |
| 29810 |
addr = scratch; |
| 29811 |
delta &= 4095; |
| 29812 |
} |
| 29813 |
else |
| 29814 |
addr = stack_pointer_rtx; |
| 29815 |
|
| 29816 |
addr = plus_constant (Pmode, addr, delta); |
| 29817 |
} |
| 29818 |
|
| 29819 |
/* The store needs to be marked to prevent DSE from deleting |
| 29820 |
it as dead if it is based on fp. */ |
| 29821 |
mem = gen_frame_mem (Pmode, addr); |
| 29822 |
MEM_VOLATILE_P (mem) = true; |
| 29823 |
emit_move_insn (mem, source); |
| 29824 |
} |
| 29825 |
} |
| 29826 |
|
| 29827 |
|
| 29828 |
void |
| 29829 |
thumb_set_return_address (rtx source, rtx scratch) |
| 29830 |
{ |
| 29831 |
arm_stack_offsets *offsets; |
| 29832 |
HOST_WIDE_INT delta; |
| 29833 |
HOST_WIDE_INT limit; |
| 29834 |
int reg; |
| 29835 |
rtx addr, mem; |
| 29836 |
unsigned long mask; |
| 29837 |
|
| 29838 |
emit_use (source); |
| 29839 |
|
| 29840 |
offsets = arm_get_frame_offsets (); |
| 29841 |
mask = offsets->saved_regs_mask; |
| 29842 |
if (mask & (1 << LR_REGNUM)) |
| 29843 |
{ |
| 29844 |
limit = 1024; |
| 29845 |
/* Find the saved regs. */ |
| 29846 |
if (frame_pointer_needed) |
| 29847 |
{ |
| 29848 |
delta = offsets->soft_frame - offsets->saved_args; |
| 29849 |
reg = THUMB_HARD_FRAME_POINTER_REGNUM; |
| 29850 |
if (TARGET_THUMB1) |
| 29851 |
limit = 128; |
| 29852 |
} |
| 29853 |
else |
| 29854 |
{ |
| 29855 |
delta = offsets->outgoing_args - offsets->saved_args; |
| 29856 |
reg = SP_REGNUM; |
| 29857 |
} |
| 29858 |
/* Allow for the stack frame. */ |
| 29859 |
if (TARGET_THUMB1 && TARGET_BACKTRACE) |
| 29860 |
delta -= 16; |
| 29861 |
/* The link register is always the first saved register. */ |
| 29862 |
delta -= 4; |
| 29863 |
|
| 29864 |
/* Construct the address. */ |
| 29865 |
addr = gen_rtx_REG (SImode, reg); |
| 29866 |
if (delta > limit) |
| 29867 |
{ |
| 29868 |
emit_insn (gen_movsi (scratch, GEN_INT (delta))); |
| 29869 |
emit_insn (gen_addsi3 (scratch, scratch, stack_pointer_rtx)); |
| 29870 |
addr = scratch; |
| 29871 |
} |
| 29872 |
else |
| 29873 |
addr = plus_constant (Pmode, addr, delta); |
| 29874 |
|
| 29875 |
/* The store needs to be marked to prevent DSE from deleting |
| 29876 |
it as dead if it is based on fp. */ |
| 29877 |
mem = gen_frame_mem (Pmode, addr); |
| 29878 |
MEM_VOLATILE_P (mem) = true; |
| 29879 |
emit_move_insn (mem, source); |
| 29880 |
} |
| 29881 |
else |
| 29882 |
emit_move_insn (gen_rtx_REG (Pmode, LR_REGNUM), source); |
| 29883 |
} |
| 29884 |
|
| 29885 |
/* Implements target hook vector_mode_supported_p. */ |
| 29886 |
bool |
| 29887 |
arm_vector_mode_supported_p (machine_mode mode) |
| 29888 |
{ |
| 29889 |
/* Neon also supports V2SImode, etc. listed in the clause below. */ |
| 29890 |
if (TARGET_NEON && (mode == V2SFmode || mode == V4SImode || mode == V8HImode |
| 29891 |
|| mode == V4HFmode || mode == V16QImode || mode == V4SFmode |
| 29892 |
|| mode == V2DImode || mode == V8HFmode || mode == V4BFmode |
| 29893 |
|| mode == V8BFmode)) |
| 29894 |
return true; |
| 29895 |
|
| 29896 |
if ((TARGET_NEON || TARGET_IWMMXT) |
| 29897 |
&& ((mode == V2SImode) |
| 29898 |
|| (mode == V4HImode) |
| 29899 |
|| (mode == V8QImode))) |
| 29900 |
return true; |
| 29901 |
|
| 29902 |
if (TARGET_INT_SIMD && (mode == V4UQQmode || mode == V4QQmode |
| 29903 |
|| mode == V2UHQmode || mode == V2HQmode || mode == V2UHAmode |
| 29904 |
|| mode == V2HAmode)) |
| 29905 |
return true; |
| 29906 |
|
| 29907 |
if (TARGET_HAVE_MVE |
| 29908 |
&& (VALID_MVE_SI_MODE (mode) || VALID_MVE_PRED_MODE (mode))) |
| 29909 |
return true; |
| 29910 |
|
| 29911 |
if (TARGET_HAVE_MVE_FLOAT |
| 29912 |
&& (mode == V2DFmode || mode == V4SFmode || mode == V8HFmode)) |
| 29913 |
return true; |
| 29914 |
|
| 29915 |
return false; |
| 29916 |
} |
| 29917 |
|
| 29918 |
/* Implements target hook array_mode. */ |
| 29919 |
static opt_machine_mode |
| 29920 |
arm_array_mode (machine_mode mode, unsigned HOST_WIDE_INT nelems) |
| 29921 |
{ |
| 29922 |
if (TARGET_HAVE_MVE |
| 29923 |
/* MVE accepts only tuples of 2 or 4 vectors. */ |
| 29924 |
&& (nelems == 2 |
| 29925 |
|| nelems == 4)) |
| 29926 |
{ |
| 29927 |
machine_mode struct_mode; |
| 29928 |
FOR_EACH_MODE_IN_CLASS (struct_mode, GET_MODE_CLASS (mode)) |
| 29929 |
{ |
| 29930 |
if (GET_MODE_INNER (struct_mode) == GET_MODE_INNER (mode) |
| 29931 |
&& known_eq (GET_MODE_NUNITS (struct_mode), |
| 29932 |
GET_MODE_NUNITS (mode) * nelems)) |
| 29933 |
return struct_mode; |
| 29934 |
} |
| 29935 |
} |
| 29936 |
return opt_machine_mode (); |
| 29937 |
} |
| 29938 |
|
| 29939 |
/* Implements target hook array_mode_supported_p. */ |
| 29940 |
|
| 29941 |
static bool |
| 29942 |
arm_array_mode_supported_p (machine_mode mode, |
| 29943 |
unsigned HOST_WIDE_INT nelems) |
| 29944 |
{ |
| 29945 |
/* We don't want to enable interleaved loads and stores for BYTES_BIG_ENDIAN |
| 29946 |
for now, as the lane-swapping logic needs to be extended in the expanders. |
| 29947 |
See PR target/82518. */ |
| 29948 |
if (TARGET_NEON && !BYTES_BIG_ENDIAN |
| 29949 |
&& (VALID_NEON_DREG_MODE (mode) || VALID_NEON_QREG_MODE (mode)) |
| 29950 |
&& (nelems >= 2 && nelems <= 4)) |
| 29951 |
return true; |
| 29952 |
|
| 29953 |
if (TARGET_HAVE_MVE && !BYTES_BIG_ENDIAN |
| 29954 |
&& VALID_MVE_MODE (mode) && (nelems == 2 || nelems == 4)) |
| 29955 |
return true; |
| 29956 |
|
| 29957 |
return false; |
| 29958 |
} |
| 29959 |
|
| 29960 |
/* Use the option -mvectorize-with-neon-double to override the use of quardword |
| 29961 |
registers when autovectorizing for Neon, at least until multiple vector |
| 29962 |
widths are supported properly by the middle-end. */ |
| 29963 |
|
| 29964 |
static machine_mode |
| 29965 |
arm_preferred_simd_mode (scalar_mode mode) |
| 29966 |
{ |
| 29967 |
if (TARGET_NEON) |
| 29968 |
switch (mode) |
| 29969 |
{ |
| 29970 |
case E_HFmode: |
| 29971 |
return TARGET_NEON_VECTORIZE_DOUBLE ? V4HFmode : V8HFmode; |
| 29972 |
case E_SFmode: |
| 29973 |
return TARGET_NEON_VECTORIZE_DOUBLE ? V2SFmode : V4SFmode; |
| 29974 |
case E_SImode: |
| 29975 |
return TARGET_NEON_VECTORIZE_DOUBLE ? V2SImode : V4SImode; |
| 29976 |
case E_HImode: |
| 29977 |
return TARGET_NEON_VECTORIZE_DOUBLE ? V4HImode : V8HImode; |
| 29978 |
case E_QImode: |
| 29979 |
return TARGET_NEON_VECTORIZE_DOUBLE ? V8QImode : V16QImode; |
| 29980 |
case E_DImode: |
| 29981 |
if (!TARGET_NEON_VECTORIZE_DOUBLE) |
| 29982 |
return V2DImode; |
| 29983 |
break; |
| 29984 |
|
| 29985 |
default:; |
| 29986 |
} |
| 29987 |
|
| 29988 |
if (TARGET_REALLY_IWMMXT) |
| 29989 |
switch (mode) |
| 29990 |
{ |
| 29991 |
case E_SImode: |
| 29992 |
return V2SImode; |
| 29993 |
case E_HImode: |
| 29994 |
return V4HImode; |
| 29995 |
case E_QImode: |
| 29996 |
return V8QImode; |
| 29997 |
|
| 29998 |
default:; |
| 29999 |
} |
| 30000 |
|
| 30001 |
if (TARGET_HAVE_MVE) |
| 30002 |
switch (mode) |
| 30003 |
{ |
| 30004 |
case E_QImode: |
| 30005 |
return V16QImode; |
| 30006 |
case E_HImode: |
| 30007 |
return V8HImode; |
| 30008 |
case E_SImode: |
| 30009 |
return V4SImode; |
| 30010 |
|
| 30011 |
default:; |
| 30012 |
} |
| 30013 |
|
| 30014 |
if (TARGET_HAVE_MVE_FLOAT) |
| 30015 |
switch (mode) |
| 30016 |
{ |
| 30017 |
case E_HFmode: |
| 30018 |
return V8HFmode; |
| 30019 |
case E_SFmode: |
| 30020 |
return V4SFmode; |
| 30021 |
|
| 30022 |
default:; |
| 30023 |
} |
| 30024 |
|
| 30025 |
return word_mode; |
| 30026 |
} |
| 30027 |
|
| 30028 |
/* Implement TARGET_CLASS_LIKELY_SPILLED_P. |
| 30029 |
|
| 30030 |
We need to define this for LO_REGS on Thumb-1. Otherwise we can end up |
| 30031 |
using r0-r4 for function arguments, r7 for the stack frame and don't have |
| 30032 |
enough left over to do doubleword arithmetic. For Thumb-2 all the |
| 30033 |
potentially problematic instructions accept high registers so this is not |
| 30034 |
necessary. Care needs to be taken to avoid adding new Thumb-2 patterns |
| 30035 |
that require many low registers. */ |
| 30036 |
static bool |
| 30037 |
arm_class_likely_spilled_p (reg_class_t rclass) |
| 30038 |
{ |
| 30039 |
if ((TARGET_THUMB1 && rclass == LO_REGS) |
| 30040 |
|| rclass == CC_REG) |
| 30041 |
return true; |
| 30042 |
|
| 30043 |
return default_class_likely_spilled_p (rclass); |
| 30044 |
} |
| 30045 |
|
| 30046 |
/* Implements target hook small_register_classes_for_mode_p. */ |
| 30047 |
bool |
| 30048 |
arm_small_register_classes_for_mode_p (machine_mode mode ATTRIBUTE_UNUSED) |
| 30049 |
{ |
| 30050 |
return TARGET_THUMB1; |
| 30051 |
} |
| 30052 |
|
| 30053 |
/* Implement TARGET_SHIFT_TRUNCATION_MASK. SImode shifts use normal |
| 30054 |
ARM insns and therefore guarantee that the shift count is modulo 256. |
| 30055 |
DImode shifts (those implemented by lib1funcs.S or by optabs.cc) |
| 30056 |
guarantee no particular behavior for out-of-range counts. */ |
| 30057 |
|
| 30058 |
static unsigned HOST_WIDE_INT |
| 30059 |
arm_shift_truncation_mask (machine_mode mode) |
| 30060 |
{ |
| 30061 |
return mode == SImode ? 255 : 0; |
| 30062 |
} |
| 30063 |
|
| 30064 |
|
| 30065 |
/* Map internal gcc register numbers to DWARF2 register numbers. */ |
| 30066 |
|
| 30067 |
unsigned int |
| 30068 |
arm_debugger_regno (unsigned int regno) |
| 30069 |
{ |
| 30070 |
if (regno < 16) |
| 30071 |
return regno; |
| 30072 |
|
| 30073 |
if (IS_VFP_REGNUM (regno)) |
| 30074 |
{ |
| 30075 |
/* See comment in arm_dwarf_register_span. */ |
| 30076 |
if (VFP_REGNO_OK_FOR_SINGLE (regno)) |
| 30077 |
return 64 + regno - FIRST_VFP_REGNUM; |
| 30078 |
else |
| 30079 |
return 256 + (regno - FIRST_VFP_REGNUM) / 2; |
| 30080 |
} |
| 30081 |
|
| 30082 |
if (IS_IWMMXT_GR_REGNUM (regno)) |
| 30083 |
return 104 + regno - FIRST_IWMMXT_GR_REGNUM; |
| 30084 |
|
| 30085 |
if (IS_IWMMXT_REGNUM (regno)) |
| 30086 |
return 112 + regno - FIRST_IWMMXT_REGNUM; |
| 30087 |
|
| 30088 |
if (IS_PAC_REGNUM (regno)) |
| 30089 |
return DWARF_PAC_REGNUM; |
| 30090 |
|
| 30091 |
return DWARF_FRAME_REGISTERS; |
| 30092 |
} |
| 30093 |
|
| 30094 |
/* Dwarf models VFPv3 registers as 32 64-bit registers. |
| 30095 |
GCC models tham as 64 32-bit registers, so we need to describe this to |
| 30096 |
the DWARF generation code. Other registers can use the default. */ |
| 30097 |
static rtx |
| 30098 |
arm_dwarf_register_span (rtx rtl) |
| 30099 |
{ |
| 30100 |
machine_mode mode; |
| 30101 |
unsigned regno; |
| 30102 |
rtx parts[16]; |
| 30103 |
int nregs; |
| 30104 |
int i; |
| 30105 |
|
| 30106 |
regno = REGNO (rtl); |
| 30107 |
if (!IS_VFP_REGNUM (regno)) |
| 30108 |
return NULL_RTX; |
| 30109 |
|
| 30110 |
/* XXX FIXME: The EABI defines two VFP register ranges: |
| 30111 |
64-95: Legacy VFPv2 numbering for S0-S31 (obsolescent) |
| 30112 |
256-287: D0-D31 |
| 30113 |
The recommended encoding for S0-S31 is a DW_OP_bit_piece of the |
| 30114 |
corresponding D register. Until GDB supports this, we shall use the |
| 30115 |
legacy encodings. We also use these encodings for D0-D15 for |
| 30116 |
compatibility with older debuggers. */ |
| 30117 |
mode = GET_MODE (rtl); |
| 30118 |
if (GET_MODE_SIZE (mode) < 8) |
| 30119 |
return NULL_RTX; |
| 30120 |
|
| 30121 |
if (VFP_REGNO_OK_FOR_SINGLE (regno)) |
| 30122 |
{ |
| 30123 |
nregs = GET_MODE_SIZE (mode) / 4; |
| 30124 |
for (i = 0; i < nregs; i += 2) |
| 30125 |
if (TARGET_BIG_END) |
| 30126 |
{ |
| 30127 |
parts[i] = gen_rtx_REG (SImode, regno + i + 1); |
| 30128 |
parts[i + 1] = gen_rtx_REG (SImode, regno + i); |
| 30129 |
} |
| 30130 |
else |
| 30131 |
{ |
| 30132 |
parts[i] = gen_rtx_REG (SImode, regno + i); |
| 30133 |
parts[i + 1] = gen_rtx_REG (SImode, regno + i + 1); |
| 30134 |
} |
| 30135 |
} |
| 30136 |
else |
| 30137 |
{ |
| 30138 |
nregs = GET_MODE_SIZE (mode) / 8; |
| 30139 |
for (i = 0; i < nregs; i++) |
| 30140 |
parts[i] = gen_rtx_REG (DImode, regno + i); |
| 30141 |
} |
| 30142 |
|
| 30143 |
return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs , parts)); |
| 30144 |
} |
| 30145 |
|
| 30146 |
#if ARM_UNWIND_INFO |
| 30147 |
/* Emit unwind directives for a store-multiple instruction or stack pointer |
| 30148 |
push during alignment. |
| 30149 |
These should only ever be generated by the function prologue code, so |
| 30150 |
expect them to have a particular form. |
| 30151 |
The store-multiple instruction sometimes pushes pc as the last register, |
| 30152 |
although it should not be tracked into unwind information, or for -Os |
| 30153 |
sometimes pushes some dummy registers before first register that needs |
| 30154 |
to be tracked in unwind information; such dummy registers are there just |
| 30155 |
to avoid separate stack adjustment, and will not be restored in the |
| 30156 |
epilogue. */ |
| 30157 |
|
| 30158 |
static void |
| 30159 |
arm_unwind_emit_sequence (FILE * out_file, rtx p) |
| 30160 |
{ |
| 30161 |
int i; |
| 30162 |
HOST_WIDE_INT offset; |
| 30163 |
HOST_WIDE_INT nregs; |
| 30164 |
int reg_size; |
| 30165 |
unsigned reg; |
| 30166 |
unsigned lastreg; |
| 30167 |
unsigned padfirst = 0, padlast = 0; |
| 30168 |
rtx e; |
| 30169 |
|
| 30170 |
e = XVECEXP (p, 0, 0); |
| 30171 |
gcc_assert (GET_CODE (e) == SET); |
| 30172 |
|
| 30173 |
/* First insn will adjust the stack pointer. */ |
| 30174 |
gcc_assert (GET_CODE (e) == SET |
| 30175 |
&& REG_P (SET_DEST (e)) |
| 30176 |
&& REGNO (SET_DEST (e)) == SP_REGNUM |
| 30177 |
&& GET_CODE (SET_SRC (e)) == PLUS); |
| 30178 |
|
| 30179 |
offset = -INTVAL (XEXP (SET_SRC (e), 1)); |
| 30180 |
nregs = XVECLEN (p, 0) - 1; |
| 30181 |
gcc_assert (nregs); |
| 30182 |
|
| 30183 |
reg = REGNO (SET_SRC (XVECEXP (p, 0, 1))); |
| 30184 |
if (reg < 16 || IS_PAC_REGNUM (reg)) |
| 30185 |
{ |
| 30186 |
/* For -Os dummy registers can be pushed at the beginning to |
| 30187 |
avoid separate stack pointer adjustment. */ |
| 30188 |
e = XVECEXP (p, 0, 1); |
| 30189 |
e = XEXP (SET_DEST (e), 0); |
| 30190 |
if (GET_CODE (e) == PLUS) |
| 30191 |
padfirst = INTVAL (XEXP (e, 1)); |
| 30192 |
gcc_assert (padfirst == 0 || optimize_size); |
| 30193 |
/* The function prologue may also push pc, but not annotate it as it is |
| 30194 |
never restored. We turn this into a stack pointer adjustment. */ |
| 30195 |
e = XVECEXP (p, 0, nregs); |
| 30196 |
e = XEXP (SET_DEST (e), 0); |
| 30197 |
if (GET_CODE (e) == PLUS) |
| 30198 |
padlast = offset - INTVAL (XEXP (e, 1)) - 4; |
| 30199 |
else |
| 30200 |
padlast = offset - 4; |
| 30201 |
gcc_assert (padlast == 0 || padlast == 4); |
| 30202 |
if (padlast == 4) |
| 30203 |
fprintf (out_file, "\t.pad #4\n"); |
| 30204 |
reg_size = 4; |
| 30205 |
fprintf (out_file, "\t.save {"); |
| 30206 |
} |
| 30207 |
else if (IS_VFP_REGNUM (reg)) |
| 30208 |
{ |
| 30209 |
reg_size = 8; |
| 30210 |
fprintf (out_file, "\t.vsave {"); |
| 30211 |
} |
| 30212 |
else |
| 30213 |
/* Unknown register type. */ |
| 30214 |
gcc_unreachable (); |
| 30215 |
|
| 30216 |
/* If the stack increment doesn't match the size of the saved registers, |
| 30217 |
something has gone horribly wrong. */ |
| 30218 |
gcc_assert (offset == padfirst + nregs * reg_size + padlast); |
| 30219 |
|
| 30220 |
offset = padfirst; |
| 30221 |
lastreg = 0; |
| 30222 |
/* The remaining insns will describe the stores. */ |
| 30223 |
for (i = 1; i <= nregs; i++) |
| 30224 |
{ |
| 30225 |
/* Expect (set (mem <addr>) (reg)). |
| 30226 |
Where <addr> is (reg:SP) or (plus (reg:SP) (const_int)). */ |
| 30227 |
e = XVECEXP (p, 0, i); |
| 30228 |
gcc_assert (GET_CODE (e) == SET |
| 30229 |
&& MEM_P (SET_DEST (e)) |
| 30230 |
&& REG_P (SET_SRC (e))); |
| 30231 |
|
| 30232 |
reg = REGNO (SET_SRC (e)); |
| 30233 |
gcc_assert (reg >= lastreg); |
| 30234 |
|
| 30235 |
if (i != 1) |
| 30236 |
fprintf (out_file, ", "); |
| 30237 |
/* We can't use %r for vfp because we need to use the |
| 30238 |
double precision register names. */ |
| 30239 |
if (IS_VFP_REGNUM (reg)) |
| 30240 |
asm_fprintf (out_file, "d%d", (reg - FIRST_VFP_REGNUM) / 2); |
| 30241 |
else if (IS_PAC_REGNUM (reg)) |
| 30242 |
asm_fprintf (asm_out_file, "ra_auth_code"); |
| 30243 |
else |
| 30244 |
asm_fprintf (out_file, "%r", reg); |
| 30245 |
|
| 30246 |
if (flag_checking) |
| 30247 |
{ |
| 30248 |
/* Check that the addresses are consecutive. */ |
| 30249 |
e = XEXP (SET_DEST (e), 0); |
| 30250 |
if (GET_CODE (e) == PLUS) |
| 30251 |
gcc_assert (REG_P (XEXP (e, 0)) |
| 30252 |
&& REGNO (XEXP (e, 0)) == SP_REGNUM |
| 30253 |
&& CONST_INT_P (XEXP (e, 1)) |
| 30254 |
&& offset == INTVAL (XEXP (e, 1))); |
| 30255 |
else |
| 30256 |
gcc_assert (i == 1 |
| 30257 |
&& REG_P (e) |
| 30258 |
&& REGNO (e) == SP_REGNUM); |
| 30259 |
offset += reg_size; |
| 30260 |
} |
| 30261 |
} |
| 30262 |
fprintf (out_file, "}\n"); |
| 30263 |
if (padfirst) |
| 30264 |
fprintf (out_file, "\t.pad #%d\n", padfirst); |
| 30265 |
} |
| 30266 |
|
| 30267 |
/* Emit unwind directives for a SET. */ |
| 30268 |
|
| 30269 |
static void |
| 30270 |
arm_unwind_emit_set (FILE * out_file, rtx p) |
| 30271 |
{ |
| 30272 |
rtx e0; |
| 30273 |
rtx e1; |
| 30274 |
unsigned reg; |
| 30275 |
|
| 30276 |
e0 = XEXP (p, 0); |
| 30277 |
e1 = XEXP (p, 1); |
| 30278 |
switch (GET_CODE (e0)) |
| 30279 |
{ |
| 30280 |
case MEM: |
| 30281 |
/* Pushing a single register. */ |
| 30282 |
if (GET_CODE (XEXP (e0, 0)) != PRE_DEC |
| 30283 |
|| !REG_P (XEXP (XEXP (e0, 0), 0)) |
| 30284 |
|| REGNO (XEXP (XEXP (e0, 0), 0)) != SP_REGNUM) |
| 30285 |
abort (); |
| 30286 |
|
| 30287 |
asm_fprintf (out_file, "\t.save "); |
| 30288 |
if (IS_VFP_REGNUM (REGNO (e1))) |
| 30289 |
asm_fprintf(out_file, "{d%d}\n", |
| 30290 |
(REGNO (e1) - FIRST_VFP_REGNUM) / 2); |
| 30291 |
else |
| 30292 |
asm_fprintf(out_file, "{%r}\n", REGNO (e1)); |
| 30293 |
break; |
| 30294 |
|
| 30295 |
case REG: |
| 30296 |
if (REGNO (e0) == SP_REGNUM) |
| 30297 |
{ |
| 30298 |
/* A stack increment. */ |
| 30299 |
if (GET_CODE (e1) != PLUS |
| 30300 |
|| !REG_P (XEXP (e1, 0)) |
| 30301 |
|| REGNO (XEXP (e1, 0)) != SP_REGNUM |
| 30302 |
|| !CONST_INT_P (XEXP (e1, 1))) |
| 30303 |
abort (); |
| 30304 |
|
| 30305 |
asm_fprintf (out_file, "\t.pad #%wd\n", |
| 30306 |
-INTVAL (XEXP (e1, 1))); |
| 30307 |
} |
| 30308 |
else if (REGNO (e0) == HARD_FRAME_POINTER_REGNUM) |
| 30309 |
{ |
| 30310 |
HOST_WIDE_INT offset; |
| 30311 |
|
| 30312 |
if (GET_CODE (e1) == PLUS) |
| 30313 |
{ |
| 30314 |
if (!REG_P (XEXP (e1, 0)) |
| 30315 |
|| !CONST_INT_P (XEXP (e1, 1))) |
| 30316 |
abort (); |
| 30317 |
reg = REGNO (XEXP (e1, 0)); |
| 30318 |
offset = INTVAL (XEXP (e1, 1)); |
| 30319 |
asm_fprintf (out_file, "\t.setfp %r, %r, #%wd\n", |
| 30320 |
HARD_FRAME_POINTER_REGNUM, reg, |
| 30321 |
offset); |
| 30322 |
} |
| 30323 |
else if (REG_P (e1)) |
| 30324 |
{ |
| 30325 |
reg = REGNO (e1); |
| 30326 |
asm_fprintf (out_file, "\t.setfp %r, %r\n", |
| 30327 |
HARD_FRAME_POINTER_REGNUM, reg); |
| 30328 |
} |
| 30329 |
else |
| 30330 |
abort (); |
| 30331 |
} |
| 30332 |
else if (REG_P (e1) && REGNO (e1) == SP_REGNUM) |
| 30333 |
{ |
| 30334 |
/* Move from sp to reg. */ |
| 30335 |
asm_fprintf (out_file, "\t.movsp %r\n", REGNO (e0)); |
| 30336 |
} |
| 30337 |
else if (GET_CODE (e1) == PLUS |
| 30338 |
&& REG_P (XEXP (e1, 0)) |
| 30339 |
&& REGNO (XEXP (e1, 0)) == SP_REGNUM |
| 30340 |
&& CONST_INT_P (XEXP (e1, 1))) |
| 30341 |
{ |
| 30342 |
/* Set reg to offset from sp. */ |
| 30343 |
asm_fprintf (out_file, "\t.movsp %r, #%d\n", |
| 30344 |
REGNO (e0), (int)INTVAL(XEXP (e1, 1))); |
| 30345 |
} |
| 30346 |
else if (REGNO (e0) == IP_REGNUM && arm_current_function_pac_enabled_p ()) |
| 30347 |
{ |
| 30348 |
if (cfun->machine->pacspval_needed) |
| 30349 |
asm_fprintf (out_file, "\t.pacspval\n"); |
| 30350 |
} |
| 30351 |
else |
| 30352 |
abort (); |
| 30353 |
break; |
| 30354 |
|
| 30355 |
default: |
| 30356 |
abort (); |
| 30357 |
} |
| 30358 |
} |
| 30359 |
|
| 30360 |
|
| 30361 |
/* Emit unwind directives for the given insn. */ |
| 30362 |
|
| 30363 |
static void |
| 30364 |
arm_unwind_emit (FILE * out_file, rtx_insn *insn) |
| 30365 |
{ |
| 30366 |
rtx note, pat; |
| 30367 |
bool handled_one = false; |
| 30368 |
|
| 30369 |
if (arm_except_unwind_info (&global_options) != UI_TARGET) |
| 30370 |
return; |
| 30371 |
|
| 30372 |
if (!(flag_unwind_tables || crtl->uses_eh_lsda) |
| 30373 |
&& (TREE_NOTHROW (current_function_decl) |
| 30374 |
|| crtl->all_throwers_are_sibcalls)) |
| 30375 |
return; |
| 30376 |
|
| 30377 |
if (NOTE_P (insn) || !RTX_FRAME_RELATED_P (insn)) |
| 30378 |
return; |
| 30379 |
|
| 30380 |
for (note = REG_NOTES (insn); note ; note = XEXP (note, 1)) |
| 30381 |
{ |
| 30382 |
switch (REG_NOTE_KIND (note)) |
| 30383 |
{ |
| 30384 |
case REG_FRAME_RELATED_EXPR: |
| 30385 |
pat = XEXP (note, 0); |
| 30386 |
goto found; |
| 30387 |
|
| 30388 |
case REG_CFA_REGISTER: |
| 30389 |
pat = XEXP (note, 0); |
| 30390 |
if (pat == NULL) |
| 30391 |
{ |
| 30392 |
pat = PATTERN (insn); |
| 30393 |
if (GET_CODE (pat) == PARALLEL) |
| 30394 |
pat = XVECEXP (pat, 0, 0); |
| 30395 |
} |
| 30396 |
|
| 30397 |
/* Only emitted for IS_STACKALIGN re-alignment. */ |
| 30398 |
{ |
| 30399 |
rtx dest, src; |
| 30400 |
unsigned reg; |
| 30401 |
|
| 30402 |
src = SET_SRC (pat); |
| 30403 |
dest = SET_DEST (pat); |
| 30404 |
|
| 30405 |
gcc_assert (src == stack_pointer_rtx |
| 30406 |
|| IS_PAC_REGNUM (REGNO (src))); |
| 30407 |
reg = REGNO (dest); |
| 30408 |
|
| 30409 |
if (IS_PAC_REGNUM (REGNO (src))) |
| 30410 |
arm_unwind_emit_set (out_file, PATTERN (insn)); |
| 30411 |
else |
| 30412 |
asm_fprintf (out_file, "\t.unwind_raw 0, 0x%x @ vsp = r%d\n", |
| 30413 |
reg + 0x90, reg); |
| 30414 |
} |
| 30415 |
handled_one = true; |
| 30416 |
break; |
| 30417 |
|
| 30418 |
/* The INSN is generated in epilogue. It is set as RTX_FRAME_RELATED_P |
| 30419 |
to get correct dwarf information for shrink-wrap. We should not |
| 30420 |
emit unwind information for it because these are used either for |
| 30421 |
pretend arguments or notes to adjust sp and restore registers from |
| 30422 |
stack. */ |
| 30423 |
case REG_CFA_DEF_CFA: |
| 30424 |
case REG_CFA_ADJUST_CFA: |
| 30425 |
case REG_CFA_RESTORE: |
| 30426 |
return; |
| 30427 |
|
| 30428 |
case REG_CFA_EXPRESSION: |
| 30429 |
case REG_CFA_OFFSET: |
| 30430 |
/* ??? Only handling here what we actually emit. */ |
| 30431 |
gcc_unreachable (); |
| 30432 |
|
| 30433 |
default: |
| 30434 |
break; |
| 30435 |
} |
| 30436 |
} |
| 30437 |
if (handled_one) |
| 30438 |
return; |
| 30439 |
pat = PATTERN (insn); |
| 30440 |
found: |
| 30441 |
|
| 30442 |
switch (GET_CODE (pat)) |
| 30443 |
{ |
| 30444 |
case SET: |
| 30445 |
arm_unwind_emit_set (out_file, pat); |
| 30446 |
break; |
| 30447 |
|
| 30448 |
case SEQUENCE: |
| 30449 |
/* Store multiple. */ |
| 30450 |
arm_unwind_emit_sequence (out_file, pat); |
| 30451 |
break; |
| 30452 |
|
| 30453 |
default: |
| 30454 |
abort(); |
| 30455 |
} |
| 30456 |
} |
| 30457 |
|
| 30458 |
|
| 30459 |
/* Output a reference from a function exception table to the type_info |
| 30460 |
object X. The EABI specifies that the symbol should be relocated by |
| 30461 |
an R_ARM_TARGET2 relocation. */ |
| 30462 |
|
| 30463 |
static bool |
| 30464 |
arm_output_ttype (rtx x) |
| 30465 |
{ |
| 30466 |
fputs ("\t.word\t", asm_out_file); |
| 30467 |
output_addr_const (asm_out_file, x); |
| 30468 |
/* Use special relocations for symbol references. */ |
| 30469 |
if (!CONST_INT_P (x)) |
| 30470 |
fputs ("(TARGET2)", asm_out_file); |
| 30471 |
fputc ('\n', asm_out_file); |
| 30472 |
|
| 30473 |
return TRUE; |
| 30474 |
} |
| 30475 |
|
| 30476 |
/* Implement TARGET_ASM_EMIT_EXCEPT_PERSONALITY. */ |
| 30477 |
|
| 30478 |
static void |
| 30479 |
arm_asm_emit_except_personality (rtx personality) |
| 30480 |
{ |
| 30481 |
fputs ("\t.personality\t", asm_out_file); |
| 30482 |
output_addr_const (asm_out_file, personality); |
| 30483 |
fputc ('\n', asm_out_file); |
| 30484 |
} |
| 30485 |
#endif /* ARM_UNWIND_INFO */ |
| 30486 |
|
| 30487 |
/* Implement TARGET_ASM_INITIALIZE_SECTIONS. */ |
| 30488 |
|
| 30489 |
static void |
| 30490 |
arm_asm_init_sections (void) |
| 30491 |
{ |
| 30492 |
#if ARM_UNWIND_INFO |
| 30493 |
exception_section = get_unnamed_section (0, output_section_asm_op, |
| 30494 |
"\t.handlerdata"); |
| 30495 |
#endif /* ARM_UNWIND_INFO */ |
| 30496 |
|
| 30497 |
#ifdef OBJECT_FORMAT_ELF |
| 30498 |
if (target_pure_code) |
| 30499 |
text_section->unnamed.data = "\t.section .text,\"0x20000006\",%progbits"; |
| 30500 |
#endif |
| 30501 |
} |
| 30502 |
|
| 30503 |
/* Output unwind directives for the start/end of a function. */ |
| 30504 |
|
| 30505 |
void |
| 30506 |
arm_output_fn_unwind (FILE * f, bool prologue) |
| 30507 |
{ |
| 30508 |
if (arm_except_unwind_info (&global_options) != UI_TARGET) |
| 30509 |
return; |
| 30510 |
|
| 30511 |
if (prologue) |
| 30512 |
fputs ("\t.fnstart\n", f); |
| 30513 |
else |
| 30514 |
{ |
| 30515 |
/* If this function will never be unwound, then mark it as such. |
| 30516 |
The came condition is used in arm_unwind_emit to suppress |
| 30517 |
the frame annotations. */ |
| 30518 |
if (!(flag_unwind_tables || crtl->uses_eh_lsda) |
| 30519 |
&& (TREE_NOTHROW (current_function_decl) |
| 30520 |
|| crtl->all_throwers_are_sibcalls)) |
| 30521 |
fputs("\t.cantunwind\n", f); |
| 30522 |
|
| 30523 |
fputs ("\t.fnend\n", f); |
| 30524 |
} |
| 30525 |
} |
| 30526 |
|
| 30527 |
static bool |
| 30528 |
arm_emit_tls_decoration (FILE *fp, rtx x) |
| 30529 |
{ |
| 30530 |
enum tls_reloc reloc; |
| 30531 |
rtx val; |
| 30532 |
|
| 30533 |
val = XVECEXP (x, 0, 0); |
| 30534 |
reloc = (enum tls_reloc) INTVAL (XVECEXP (x, 0, 1)); |
| 30535 |
|
| 30536 |
output_addr_const (fp, val); |
| 30537 |
|
| 30538 |
switch (reloc) |
| 30539 |
{ |
| 30540 |
case TLS_GD32: |
| 30541 |
fputs ("(tlsgd)", fp); |
| 30542 |
break; |
| 30543 |
case TLS_GD32_FDPIC: |
| 30544 |
fputs ("(tlsgd_fdpic)", fp); |
| 30545 |
break; |
| 30546 |
case TLS_LDM32: |
| 30547 |
fputs ("(tlsldm)", fp); |
| 30548 |
break; |
| 30549 |
case TLS_LDM32_FDPIC: |
| 30550 |
fputs ("(tlsldm_fdpic)", fp); |
| 30551 |
break; |
| 30552 |
case TLS_LDO32: |
| 30553 |
fputs ("(tlsldo)", fp); |
| 30554 |
break; |
| 30555 |
case TLS_IE32: |
| 30556 |
fputs ("(gottpoff)", fp); |
| 30557 |
break; |
| 30558 |
case TLS_IE32_FDPIC: |
| 30559 |
fputs ("(gottpoff_fdpic)", fp); |
| 30560 |
break; |
| 30561 |
case TLS_LE32: |
| 30562 |
fputs ("(tpoff)", fp); |
| 30563 |
break; |
| 30564 |
case TLS_DESCSEQ: |
| 30565 |
fputs ("(tlsdesc)", fp); |
| 30566 |
break; |
| 30567 |
default: |
| 30568 |
gcc_unreachable (); |
| 30569 |
} |
| 30570 |
|
| 30571 |
switch (reloc) |
| 30572 |
{ |
| 30573 |
case TLS_GD32: |
| 30574 |
case TLS_LDM32: |
| 30575 |
case TLS_IE32: |
| 30576 |
case TLS_DESCSEQ: |
| 30577 |
fputs (" + (. - ", fp); |
| 30578 |
output_addr_const (fp, XVECEXP (x, 0, 2)); |
| 30579 |
/* For DESCSEQ the 3rd operand encodes thumbness, and is added */ |
| 30580 |
fputs (reloc == TLS_DESCSEQ ? " + " : " - ", fp); |
| 30581 |
output_addr_const (fp, XVECEXP (x, 0, 3)); |
| 30582 |
fputc (')', fp); |
| 30583 |
break; |
| 30584 |
default: |
| 30585 |
break; |
| 30586 |
} |
| 30587 |
|
| 30588 |
return TRUE; |
| 30589 |
} |
| 30590 |
|
| 30591 |
/* ARM implementation of TARGET_ASM_OUTPUT_DWARF_DTPREL. */ |
| 30592 |
|
| 30593 |
static void |
| 30594 |
arm_output_dwarf_dtprel (FILE *file, int size, rtx x) |
| 30595 |
{ |
| 30596 |
gcc_assert (size == 4); |
| 30597 |
fputs ("\t.word\t", file); |
| 30598 |
output_addr_const (file, x); |
| 30599 |
fputs ("(tlsldo)", file); |
| 30600 |
} |
| 30601 |
|
| 30602 |
/* Implement TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA. */ |
| 30603 |
|
| 30604 |
static bool |
| 30605 |
arm_output_addr_const_extra (FILE *fp, rtx x) |
| 30606 |
{ |
| 30607 |
if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS) |
| 30608 |
return arm_emit_tls_decoration (fp, x); |
| 30609 |
else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_PIC_LABEL) |
| 30610 |
{ |
| 30611 |
char label[256]; |
| 30612 |
int labelno = INTVAL (XVECEXP (x, 0, 0)); |
| 30613 |
|
| 30614 |
ASM_GENERATE_INTERNAL_LABEL (label, "LPIC", labelno); |
| 30615 |
assemble_name_raw (fp, label); |
| 30616 |
|
| 30617 |
return TRUE; |
| 30618 |
} |
| 30619 |
else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_GOTSYM_OFF) |
| 30620 |
{ |
| 30621 |
assemble_name (fp, "_GLOBAL_OFFSET_TABLE_"); |
| 30622 |
if (GOT_PCREL) |
| 30623 |
fputs ("+.", fp); |
| 30624 |
fputs ("-(", fp); |
| 30625 |
output_addr_const (fp, XVECEXP (x, 0, 0)); |
| 30626 |
fputc (')', fp); |
| 30627 |
return TRUE; |
| 30628 |
} |
| 30629 |
else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SYMBOL_OFFSET) |
| 30630 |
{ |
| 30631 |
output_addr_const (fp, XVECEXP (x, 0, 0)); |
| 30632 |
if (GOT_PCREL) |
| 30633 |
fputs ("+.", fp); |
| 30634 |
fputs ("-(", fp); |
| 30635 |
output_addr_const (fp, XVECEXP (x, 0, 1)); |
| 30636 |
fputc (')', fp); |
| 30637 |
return TRUE; |
| 30638 |
} |
| 30639 |
else if (GET_CODE (x) == CONST_VECTOR) |
| 30640 |
return arm_emit_vector_const (fp, x); |
| 30641 |
|
| 30642 |
return FALSE; |
| 30643 |
} |
| 30644 |
|
| 30645 |
/* Output assembly for a shift instruction. |
| 30646 |
SET_FLAGS determines how the instruction modifies the condition codes. |
| 30647 |
0 - Do not set condition codes. |
| 30648 |
1 - Set condition codes. |
| 30649 |
2 - Use smallest instruction. */ |
| 30650 |
const char * |
| 30651 |
arm_output_shift(rtx * operands, int set_flags) |
| 30652 |
{ |
| 30653 |
char pattern[100]; |
| 30654 |
static const char flag_chars[3] = {'?', '.', '!'}; |
| 30655 |
const char *shift; |
| 30656 |
HOST_WIDE_INT val; |
| 30657 |
char c; |
| 30658 |
|
| 30659 |
c = flag_chars[set_flags]; |
| 30660 |
shift = shift_op(operands[3], &val); |
| 30661 |
if (shift) |
| 30662 |
{ |
| 30663 |
if (val != -1) |
| 30664 |
operands[2] = GEN_INT(val); |
| 30665 |
sprintf (pattern, "%s%%%c\t%%0, %%1, %%2", shift, c); |
| 30666 |
} |
| 30667 |
else |
| 30668 |
sprintf (pattern, "mov%%%c\t%%0, %%1", c); |
| 30669 |
|
| 30670 |
output_asm_insn (pattern, operands); |
| 30671 |
return ""; |
| 30672 |
} |
| 30673 |
|
| 30674 |
/* Output assembly for a WMMX immediate shift instruction. */ |
| 30675 |
const char * |
| 30676 |
arm_output_iwmmxt_shift_immediate (const char *insn_name, rtx *operands, bool wror_or_wsra) |
| 30677 |
{ |
| 30678 |
int shift = INTVAL (operands[2]); |
| 30679 |
char templ[50]; |
| 30680 |
machine_mode opmode = GET_MODE (operands[0]); |
| 30681 |
|
| 30682 |
gcc_assert (shift >= 0); |
| 30683 |
|
| 30684 |
/* If the shift value in the register versions is > 63 (for D qualifier), |
| 30685 |
31 (for W qualifier) or 15 (for H qualifier). */ |
| 30686 |
if (((opmode == V4HImode) && (shift > 15)) |
| 30687 |
|| ((opmode == V2SImode) && (shift > 31)) |
| 30688 |
|| ((opmode == DImode) && (shift > 63))) |
| 30689 |
{ |
| 30690 |
if (wror_or_wsra) |
| 30691 |
{ |
| 30692 |
sprintf (templ, "%s\t%%0, %%1, #%d", insn_name, 32); |
| 30693 |
output_asm_insn (templ, operands); |
| 30694 |
if (opmode == DImode) |
| 30695 |
{ |
| 30696 |
sprintf (templ, "%s\t%%0, %%0, #%d", insn_name, 32); |
| 30697 |
output_asm_insn (templ, operands); |
| 30698 |
} |
| 30699 |
} |
| 30700 |
else |
| 30701 |
{ |
| 30702 |
/* The destination register will contain all zeros. */ |
| 30703 |
sprintf (templ, "wzero\t%%0"); |
| 30704 |
output_asm_insn (templ, operands); |
| 30705 |
} |
| 30706 |
return ""; |
| 30707 |
} |
| 30708 |
|
| 30709 |
if ((opmode == DImode) && (shift > 32)) |
| 30710 |
{ |
| 30711 |
sprintf (templ, "%s\t%%0, %%1, #%d", insn_name, 32); |
| 30712 |
output_asm_insn (templ, operands); |
| 30713 |
sprintf (templ, "%s\t%%0, %%0, #%d", insn_name, shift - 32); |
| 30714 |
output_asm_insn (templ, operands); |
| 30715 |
} |
| 30716 |
else |
| 30717 |
{ |
| 30718 |
sprintf (templ, "%s\t%%0, %%1, #%d", insn_name, shift); |
| 30719 |
output_asm_insn (templ, operands); |
| 30720 |
} |
| 30721 |
return ""; |
| 30722 |
} |
| 30723 |
|
| 30724 |
/* Output assembly for a WMMX tinsr instruction. */ |
| 30725 |
const char * |
| 30726 |
arm_output_iwmmxt_tinsr (rtx *operands) |
| 30727 |
{ |
| 30728 |
int mask = INTVAL (operands[3]); |
| 30729 |
int i; |
| 30730 |
char templ[50]; |
| 30731 |
int units = mode_nunits[GET_MODE (operands[0])]; |
| 30732 |
gcc_assert ((mask & (mask - 1)) == 0); |
| 30733 |
for (i = 0; i < units; ++i) |
| 30734 |
{ |
| 30735 |
if ((mask & 0x01) == 1) |
| 30736 |
{ |
| 30737 |
break; |
| 30738 |
} |
| 30739 |
mask >>= 1; |
| 30740 |
} |
| 30741 |
gcc_assert (i < units); |
| 30742 |
{ |
| 30743 |
switch (GET_MODE (operands[0])) |
| 30744 |
{ |
| 30745 |
case E_V8QImode: |
| 30746 |
sprintf (templ, "tinsrb%%?\t%%0, %%2, #%d", i); |
| 30747 |
break; |
| 30748 |
case E_V4HImode: |
| 30749 |
sprintf (templ, "tinsrh%%?\t%%0, %%2, #%d", i); |
| 30750 |
break; |
| 30751 |
case E_V2SImode: |
| 30752 |
sprintf (templ, "tinsrw%%?\t%%0, %%2, #%d", i); |
| 30753 |
break; |
| 30754 |
default: |
| 30755 |
gcc_unreachable (); |
| 30756 |
break; |
| 30757 |
} |
| 30758 |
output_asm_insn (templ, operands); |
| 30759 |
} |
| 30760 |
return ""; |
| 30761 |
} |
| 30762 |
|
| 30763 |
/* Output an arm casesi dispatch sequence. Used by arm_casesi_internal insn. |
| 30764 |
Responsible for the handling of switch statements in arm. */ |
| 30765 |
const char * |
| 30766 |
arm_output_casesi (rtx *operands) |
| 30767 |
{ |
| 30768 |
char label[100]; |
| 30769 |
rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2]))); |
| 30770 |
gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC); |
| 30771 |
output_asm_insn ("cmp\t%0, %1", operands); |
| 30772 |
output_asm_insn ("bhi\t%l3", operands); |
| 30773 |
ASM_GENERATE_INTERNAL_LABEL (label, "Lrtx", CODE_LABEL_NUMBER (operands[2])); |
| 30774 |
switch (GET_MODE (diff_vec)) |
| 30775 |
{ |
| 30776 |
case E_QImode: |
| 30777 |
if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned) |
| 30778 |
output_asm_insn ("ldrb\t%4, [%5, %0]", operands); |
| 30779 |
else |
| 30780 |
output_asm_insn ("ldrsb\t%4, [%5, %0]", operands); |
| 30781 |
output_asm_insn ("add\t%|pc, %|pc, %4, lsl #2", operands); |
| 30782 |
break; |
| 30783 |
case E_HImode: |
| 30784 |
if (REGNO (operands[4]) != REGNO (operands[5])) |
| 30785 |
{ |
| 30786 |
output_asm_insn ("add\t%4, %0, %0", operands); |
| 30787 |
if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned) |
| 30788 |
output_asm_insn ("ldrh\t%4, [%5, %4]", operands); |
| 30789 |
else |
| 30790 |
output_asm_insn ("ldrsh\t%4, [%5, %4]", operands); |
| 30791 |
} |
| 30792 |
else |
| 30793 |
{ |
| 30794 |
output_asm_insn ("add\t%4, %5, %0", operands); |
| 30795 |
if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned) |
| 30796 |
output_asm_insn ("ldrh\t%4, [%4, %0]", operands); |
| 30797 |
else |
| 30798 |
output_asm_insn ("ldrsh\t%4, [%4, %0]", operands); |
| 30799 |
} |
| 30800 |
output_asm_insn ("add\t%|pc, %|pc, %4, lsl #2", operands); |
| 30801 |
break; |
| 30802 |
case E_SImode: |
| 30803 |
if (flag_pic) |
| 30804 |
{ |
| 30805 |
output_asm_insn ("ldr\t%4, [%5, %0, lsl #2]", operands); |
| 30806 |
output_asm_insn ("add\t%|pc, %|pc, %4", operands); |
| 30807 |
} |
| 30808 |
else |
| 30809 |
output_asm_insn ("ldr\t%|pc, [%5, %0, lsl #2]", operands); |
| 30810 |
break; |
| 30811 |
default: |
| 30812 |
gcc_unreachable (); |
| 30813 |
} |
| 30814 |
assemble_label (asm_out_file, label); |
| 30815 |
output_asm_insn ("nop", operands); |
| 30816 |
return ""; |
| 30817 |
} |
| 30818 |
|
| 30819 |
/* Output a Thumb-1 casesi dispatch sequence. */ |
| 30820 |
const char * |
| 30821 |
thumb1_output_casesi (rtx *operands) |
| 30822 |
{ |
| 30823 |
rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[0]))); |
| 30824 |
|
| 30825 |
gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC); |
| 30826 |
|
| 30827 |
switch (GET_MODE(diff_vec)) |
| 30828 |
{ |
| 30829 |
case E_QImode: |
| 30830 |
return (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned ? |
| 30831 |
"bl\t%___gnu_thumb1_case_uqi" : "bl\t%___gnu_thumb1_case_sqi"); |
| 30832 |
case E_HImode: |
| 30833 |
return (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned ? |
| 30834 |
"bl\t%___gnu_thumb1_case_uhi" : "bl\t%___gnu_thumb1_case_shi"); |
| 30835 |
case E_SImode: |
| 30836 |
return "bl\t%___gnu_thumb1_case_si"; |
| 30837 |
default: |
| 30838 |
gcc_unreachable (); |
| 30839 |
} |
| 30840 |
} |
| 30841 |
|
| 30842 |
/* Output a Thumb-2 casesi instruction. */ |
| 30843 |
const char * |
| 30844 |
thumb2_output_casesi (rtx *operands) |
| 30845 |
{ |
| 30846 |
rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2]))); |
| 30847 |
|
| 30848 |
gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC); |
| 30849 |
|
| 30850 |
output_asm_insn ("cmp\t%0, %1", operands); |
| 30851 |
output_asm_insn ("bhi\t%l3", operands); |
| 30852 |
switch (GET_MODE(diff_vec)) |
| 30853 |
{ |
| 30854 |
case E_QImode: |
| 30855 |
return "tbb\t[%|pc, %0]"; |
| 30856 |
case E_HImode: |
| 30857 |
return "tbh\t[%|pc, %0, lsl #1]"; |
| 30858 |
case E_SImode: |
| 30859 |
if (flag_pic) |
| 30860 |
{ |
| 30861 |
output_asm_insn ("adr\t%4, %l2", operands); |
| 30862 |
output_asm_insn ("ldr\t%5, [%4, %0, lsl #2]", operands); |
| 30863 |
output_asm_insn ("add\t%4, %4, %5", operands); |
| 30864 |
return "bx\t%4"; |
| 30865 |
} |
| 30866 |
else |
| 30867 |
{ |
| 30868 |
output_asm_insn ("adr\t%4, %l2", operands); |
| 30869 |
return "ldr\t%|pc, [%4, %0, lsl #2]"; |
| 30870 |
} |
| 30871 |
default: |
| 30872 |
gcc_unreachable (); |
| 30873 |
} |
| 30874 |
} |
| 30875 |
|
| 30876 |
/* Implement TARGET_SCHED_ISSUE_RATE. Lookup the issue rate in the |
| 30877 |
per-core tuning structs. */ |
| 30878 |
static int |
| 30879 |
arm_issue_rate (void) |
| 30880 |
{ |
| 30881 |
return current_tune->issue_rate; |
| 30882 |
} |
| 30883 |
|
| 30884 |
/* Implement TARGET_SCHED_VARIABLE_ISSUE. */ |
| 30885 |
static int |
| 30886 |
arm_sched_variable_issue (FILE *, int, rtx_insn *insn, int more) |
| 30887 |
{ |
| 30888 |
if (DEBUG_INSN_P (insn)) |
| 30889 |
return more; |
| 30890 |
|
| 30891 |
rtx_code code = GET_CODE (PATTERN (insn)); |
| 30892 |
if (code == USE || code == CLOBBER) |
| 30893 |
return more; |
| 30894 |
|
| 30895 |
if (get_attr_type (insn) == TYPE_NO_INSN) |
| 30896 |
return more; |
| 30897 |
|
| 30898 |
return more - 1; |
| 30899 |
} |
| 30900 |
|
| 30901 |
/* Return how many instructions should scheduler lookahead to choose the |
| 30902 |
best one. */ |
| 30903 |
static int |
| 30904 |
arm_first_cycle_multipass_dfa_lookahead (void) |
| 30905 |
{ |
| 30906 |
int issue_rate = arm_issue_rate (); |
| 30907 |
|
| 30908 |
return issue_rate > 1 && !sched_fusion ? issue_rate : 0; |
| 30909 |
} |
| 30910 |
|
| 30911 |
/* Enable modeling of L2 auto-prefetcher. */ |
| 30912 |
static int |
| 30913 |
arm_first_cycle_multipass_dfa_lookahead_guard (rtx_insn *insn, int ready_index) |
| 30914 |
{ |
| 30915 |
return autopref_multipass_dfa_lookahead_guard (insn, ready_index); |
| 30916 |
} |
| 30917 |
|
| 30918 |
const char * |
| 30919 |
arm_mangle_type (const_tree type) |
| 30920 |
{ |
| 30921 |
/* The ARM ABI documents (10th October 2008) say that "__va_list" |
| 30922 |
has to be managled as if it is in the "std" namespace. */ |
| 30923 |
if (TARGET_AAPCS_BASED |
| 30924 |
&& lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type)) |
| 30925 |
return "St9__va_list"; |
| 30926 |
|
| 30927 |
/* Half-precision floating point types. */ |
| 30928 |
if (SCALAR_FLOAT_TYPE_P (type) && TYPE_PRECISION (type) == 16) |
| 30929 |
{ |
| 30930 |
if (TYPE_MAIN_VARIANT (type) == float16_type_node) |
| 30931 |
return NULL; |
| 30932 |
if (TYPE_MODE (type) == BFmode) |
| 30933 |
return "u6__bf16"; |
| 30934 |
else |
| 30935 |
return "Dh"; |
| 30936 |
} |
| 30937 |
|
| 30938 |
/* Try mangling as a Neon type, TYPE_NAME is non-NULL if this is a |
| 30939 |
builtin type. */ |
| 30940 |
if (TYPE_NAME (type) != NULL) |
| 30941 |
return arm_mangle_builtin_type (type); |
| 30942 |
|
| 30943 |
/* Use the default mangling. */ |
| 30944 |
return NULL; |
| 30945 |
} |
| 30946 |
|
| 30947 |
/* Order of allocation of core registers for Thumb: this allocation is |
| 30948 |
written over the corresponding initial entries of the array |
| 30949 |
initialized with REG_ALLOC_ORDER. We allocate all low registers |
| 30950 |
first. Saving and restoring a low register is usually cheaper than |
| 30951 |
using a call-clobbered high register. */ |
| 30952 |
|
| 30953 |
static const int thumb_core_reg_alloc_order[] = |
| 30954 |
{ |
| 30955 |
3, 2, 1, 0, 4, 5, 6, 7, |
| 30956 |
12, 14, 8, 9, 10, 11 |
| 30957 |
}; |
| 30958 |
|
| 30959 |
/* Adjust register allocation order when compiling for Thumb. */ |
| 30960 |
|
| 30961 |
void |
| 30962 |
arm_order_regs_for_local_alloc (void) |
| 30963 |
{ |
| 30964 |
const int arm_reg_alloc_order[] = REG_ALLOC_ORDER; |
| 30965 |
memcpy(reg_alloc_order, arm_reg_alloc_order, sizeof (reg_alloc_order)); |
| 30966 |
if (TARGET_THUMB) |
| 30967 |
memcpy (reg_alloc_order, thumb_core_reg_alloc_order, |
| 30968 |
sizeof (thumb_core_reg_alloc_order)); |
| 30969 |
} |
| 30970 |
|
| 30971 |
/* Implement TARGET_FRAME_POINTER_REQUIRED. */ |
| 30972 |
|
| 30973 |
bool |
| 30974 |
arm_frame_pointer_required (void) |
| 30975 |
{ |
| 30976 |
if (SUBTARGET_FRAME_POINTER_REQUIRED) |
| 30977 |
return true; |
| 30978 |
|
| 30979 |
/* If the function receives nonlocal gotos, it needs to save the frame |
| 30980 |
pointer in the nonlocal_goto_save_area object. */ |
| 30981 |
if (cfun->has_nonlocal_label) |
| 30982 |
return true; |
| 30983 |
|
| 30984 |
/* The frame pointer is required for non-leaf APCS frames. */ |
| 30985 |
if (TARGET_ARM && TARGET_APCS_FRAME && !crtl->is_leaf) |
| 30986 |
return true; |
| 30987 |
|
| 30988 |
/* If we are probing the stack in the prologue, we will have a faulting |
| 30989 |
instruction prior to the stack adjustment and this requires a frame |
| 30990 |
pointer if we want to catch the exception using the EABI unwinder. */ |
| 30991 |
if (!IS_INTERRUPT (arm_current_func_type ()) |
| 30992 |
&& (flag_stack_check == STATIC_BUILTIN_STACK_CHECK |
| 30993 |
|| flag_stack_clash_protection) |
| 30994 |
&& arm_except_unwind_info (&global_options) == UI_TARGET |
| 30995 |
&& cfun->can_throw_non_call_exceptions) |
| 30996 |
{ |
| 30997 |
HOST_WIDE_INT size = get_frame_size (); |
| 30998 |
|
| 30999 |
/* That's irrelevant if there is no stack adjustment. */ |
| 31000 |
if (size <= 0) |
| 31001 |
return false; |
| 31002 |
|
| 31003 |
/* That's relevant only if there is a stack probe. */ |
| 31004 |
if (crtl->is_leaf && !cfun->calls_alloca) |
| 31005 |
{ |
| 31006 |
/* We don't have the final size of the frame so adjust. */ |
| 31007 |
size += 32 * UNITS_PER_WORD; |
| 31008 |
if (size > PROBE_INTERVAL && size > get_stack_check_protect ()) |
| 31009 |
return true; |
| 31010 |
} |
| 31011 |
else |
| 31012 |
return true; |
| 31013 |
} |
| 31014 |
|
| 31015 |
return false; |
| 31016 |
} |
| 31017 |
|
| 31018 |
/* Implement the TARGET_HAVE_CONDITIONAL_EXECUTION hook. |
| 31019 |
All modes except THUMB1 have conditional execution. |
| 31020 |
If we have conditional arithmetic, return false before reload to |
| 31021 |
enable some ifcvt transformations. */ |
| 31022 |
static bool |
| 31023 |
arm_have_conditional_execution (void) |
| 31024 |
{ |
| 31025 |
bool has_cond_exec, enable_ifcvt_trans; |
| 31026 |
|
| 31027 |
/* Only THUMB1 cannot support conditional execution. */ |
| 31028 |
has_cond_exec = !TARGET_THUMB1; |
| 31029 |
|
| 31030 |
/* Enable ifcvt transformations if we have conditional arithmetic, but only |
| 31031 |
before reload. */ |
| 31032 |
enable_ifcvt_trans = TARGET_COND_ARITH && !reload_completed; |
| 31033 |
|
| 31034 |
return has_cond_exec && !enable_ifcvt_trans; |
| 31035 |
} |
| 31036 |
|
| 31037 |
/* The AAPCS sets the maximum alignment of a vector to 64 bits. */ |
| 31038 |
static HOST_WIDE_INT |
| 31039 |
arm_vector_alignment (const_tree type) |
| 31040 |
{ |
| 31041 |
HOST_WIDE_INT align = tree_to_shwi (TYPE_SIZE (type)); |
| 31042 |
|
| 31043 |
if (TARGET_AAPCS_BASED) |
| 31044 |
align = MIN (align, 64); |
| 31045 |
|
| 31046 |
return align; |
| 31047 |
} |
| 31048 |
|
| 31049 |
static unsigned int |
| 31050 |
arm_autovectorize_vector_modes (vector_modes *modes, bool) |
| 31051 |
{ |
| 31052 |
if (!TARGET_NEON_VECTORIZE_DOUBLE) |
| 31053 |
{ |
| 31054 |
modes->safe_push (V16QImode); |
| 31055 |
modes->safe_push (V8QImode); |
| 31056 |
} |
| 31057 |
return 0; |
| 31058 |
} |
| 31059 |
|
| 31060 |
static bool |
| 31061 |
arm_vector_alignment_reachable (const_tree type, bool is_packed) |
| 31062 |
{ |
| 31063 |
/* Vectors which aren't in packed structures will not be less aligned than |
| 31064 |
the natural alignment of their element type, so this is safe. */ |
| 31065 |
if (TARGET_NEON && !BYTES_BIG_ENDIAN && unaligned_access) |
| 31066 |
return !is_packed; |
| 31067 |
|
| 31068 |
return default_builtin_vector_alignment_reachable (type, is_packed); |
| 31069 |
} |
| 31070 |
|
| 31071 |
static bool |
| 31072 |
arm_builtin_support_vector_misalignment (machine_mode mode, |
| 31073 |
const_tree type, int misalignment, |
| 31074 |
bool is_packed) |
| 31075 |
{ |
| 31076 |
if (TARGET_NEON && !BYTES_BIG_ENDIAN && unaligned_access) |
| 31077 |
{ |
| 31078 |
HOST_WIDE_INT align = TYPE_ALIGN_UNIT (type); |
| 31079 |
|
| 31080 |
if (is_packed) |
| 31081 |
return align == 1; |
| 31082 |
|
| 31083 |
/* If the misalignment is unknown, we should be able to handle the access |
| 31084 |
so long as it is not to a member of a packed data structure. */ |
| 31085 |
if (misalignment == -1) |
| 31086 |
return true; |
| 31087 |
|
| 31088 |
/* Return true if the misalignment is a multiple of the natural alignment |
| 31089 |
of the vector's element type. This is probably always going to be |
| 31090 |
true in practice, since we've already established that this isn't a |
| 31091 |
packed access. */ |
| 31092 |
return ((misalignment % align) == 0); |
| 31093 |
} |
| 31094 |
|
| 31095 |
return default_builtin_support_vector_misalignment (mode, type, misalignment, |
| 31096 |
is_packed); |
| 31097 |
} |
| 31098 |
|
| 31099 |
static void |
| 31100 |
arm_conditional_register_usage (void) |
| 31101 |
{ |
| 31102 |
int regno; |
| 31103 |
|
| 31104 |
if (TARGET_THUMB1 && optimize_size) |
| 31105 |
{ |
| 31106 |
/* When optimizing for size on Thumb-1, it's better not |
| 31107 |
to use the HI regs, because of the overhead of |
| 31108 |
stacking them. */ |
| 31109 |
for (regno = FIRST_HI_REGNUM; regno <= LAST_HI_REGNUM; ++regno) |
| 31110 |
fixed_regs[regno] = call_used_regs[regno] = 1; |
| 31111 |
} |
| 31112 |
|
| 31113 |
/* The link register can be clobbered by any branch insn, |
| 31114 |
but we have no way to track that at present, so mark |
| 31115 |
it as unavailable. */ |
| 31116 |
if (TARGET_THUMB1) |
| 31117 |
fixed_regs[LR_REGNUM] = call_used_regs[LR_REGNUM] = 1; |
| 31118 |
|
| 31119 |
if (TARGET_32BIT && TARGET_VFP_BASE) |
| 31120 |
{ |
| 31121 |
/* VFPv3 registers are disabled when earlier VFP |
| 31122 |
versions are selected due to the definition of |
| 31123 |
LAST_VFP_REGNUM. */ |
| 31124 |
for (regno = FIRST_VFP_REGNUM; |
| 31125 |
regno <= LAST_VFP_REGNUM; ++ regno) |
| 31126 |
{ |
| 31127 |
fixed_regs[regno] = 0; |
| 31128 |
call_used_regs[regno] = regno < FIRST_VFP_REGNUM + 16 |
| 31129 |
|| regno >= FIRST_VFP_REGNUM + 32; |
| 31130 |
} |
| 31131 |
if (TARGET_HAVE_MVE) |
| 31132 |
fixed_regs[VPR_REGNUM] = 0; |
| 31133 |
} |
| 31134 |
|
| 31135 |
if (TARGET_REALLY_IWMMXT && !TARGET_GENERAL_REGS_ONLY) |
| 31136 |
{ |
| 31137 |
regno = FIRST_IWMMXT_GR_REGNUM; |
| 31138 |
/* The 2002/10/09 revision of the XScale ABI has wCG0 |
| 31139 |
and wCG1 as call-preserved registers. The 2002/11/21 |
| 31140 |
revision changed this so that all wCG registers are |
| 31141 |
scratch registers. */ |
| 31142 |
for (regno = FIRST_IWMMXT_GR_REGNUM; |
| 31143 |
regno <= LAST_IWMMXT_GR_REGNUM; ++ regno) |
| 31144 |
fixed_regs[regno] = 0; |
| 31145 |
/* The XScale ABI has wR0 - wR9 as scratch registers, |
| 31146 |
the rest as call-preserved registers. */ |
| 31147 |
for (regno = FIRST_IWMMXT_REGNUM; |
| 31148 |
regno <= LAST_IWMMXT_REGNUM; ++ regno) |
| 31149 |
{ |
| 31150 |
fixed_regs[regno] = 0; |
| 31151 |
call_used_regs[regno] = regno < FIRST_IWMMXT_REGNUM + 10; |
| 31152 |
} |
| 31153 |
} |
| 31154 |
|
| 31155 |
if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM) |
| 31156 |
{ |
| 31157 |
fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1; |
| 31158 |
call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1; |
| 31159 |
} |
| 31160 |
else if (TARGET_APCS_STACK) |
| 31161 |
{ |
| 31162 |
fixed_regs[10] = 1; |
| 31163 |
call_used_regs[10] = 1; |
| 31164 |
} |
| 31165 |
/* -mcaller-super-interworking reserves r11 for calls to |
| 31166 |
_interwork_r11_call_via_rN(). Making the register global |
| 31167 |
is an easy way of ensuring that it remains valid for all |
| 31168 |
calls. */ |
| 31169 |
if (TARGET_APCS_FRAME || TARGET_CALLER_INTERWORKING |
| 31170 |
|| TARGET_TPCS_FRAME || TARGET_TPCS_LEAF_FRAME) |
| 31171 |
{ |
| 31172 |
fixed_regs[ARM_HARD_FRAME_POINTER_REGNUM] = 1; |
| 31173 |
call_used_regs[ARM_HARD_FRAME_POINTER_REGNUM] = 1; |
| 31174 |
if (TARGET_CALLER_INTERWORKING) |
| 31175 |
global_regs[ARM_HARD_FRAME_POINTER_REGNUM] = 1; |
| 31176 |
} |
| 31177 |
|
| 31178 |
/* The Q and GE bits are only accessed via special ACLE patterns. */ |
| 31179 |
CLEAR_HARD_REG_BIT (operand_reg_set, APSRQ_REGNUM); |
| 31180 |
CLEAR_HARD_REG_BIT (operand_reg_set, APSRGE_REGNUM); |
| 31181 |
|
| 31182 |
SUBTARGET_CONDITIONAL_REGISTER_USAGE |
| 31183 |
} |
| 31184 |
|
| 31185 |
static reg_class_t |
| 31186 |
arm_preferred_rename_class (reg_class_t rclass) |
| 31187 |
{ |
| 31188 |
/* Thumb-2 instructions using LO_REGS may be smaller than instructions |
| 31189 |
using GENERIC_REGS. During register rename pass, we prefer LO_REGS, |
| 31190 |
and code size can be reduced. */ |
| 31191 |
if (TARGET_THUMB2 && rclass == GENERAL_REGS) |
| 31192 |
return LO_REGS; |
| 31193 |
else |
| 31194 |
return NO_REGS; |
| 31195 |
} |
| 31196 |
|
| 31197 |
/* Compute the attribute "length" of insn "*push_multi". |
| 31198 |
So this function MUST be kept in sync with that insn pattern. */ |
| 31199 |
int |
| 31200 |
arm_attr_length_push_multi(rtx parallel_op, rtx first_op) |
| 31201 |
{ |
| 31202 |
int i, regno, hi_reg; |
| 31203 |
int num_saves = XVECLEN (parallel_op, 0); |
| 31204 |
|
| 31205 |
/* ARM mode. */ |
| 31206 |
if (TARGET_ARM) |
| 31207 |
return 4; |
| 31208 |
/* Thumb1 mode. */ |
| 31209 |
if (TARGET_THUMB1) |
| 31210 |
return 2; |
| 31211 |
|
| 31212 |
/* Thumb2 mode. */ |
| 31213 |
regno = REGNO (first_op); |
| 31214 |
/* For PUSH/STM under Thumb2 mode, we can use 16-bit encodings if the register |
| 31215 |
list is 8-bit. Normally this means all registers in the list must be |
| 31216 |
LO_REGS, that is (R0 -R7). If any HI_REGS used, then we must use 32-bit |
| 31217 |
encodings. There is one exception for PUSH that LR in HI_REGS can be used |
| 31218 |
with 16-bit encoding. */ |
| 31219 |
hi_reg = (REGNO_REG_CLASS (regno) == HI_REGS) && (regno != LR_REGNUM); |
| 31220 |
for (i = 1; i < num_saves && !hi_reg; i++) |
| 31221 |
{ |
| 31222 |
regno = REGNO (XEXP (XVECEXP (parallel_op, 0, i), 0)); |
| 31223 |
hi_reg |= (REGNO_REG_CLASS (regno) == HI_REGS) && (regno != LR_REGNUM); |
| 31224 |
} |
| 31225 |
|
| 31226 |
if (!hi_reg) |
| 31227 |
return 2; |
| 31228 |
return 4; |
| 31229 |
} |
| 31230 |
|
| 31231 |
/* Compute the attribute "length" of insn. Currently, this function is used |
| 31232 |
for "*load_multiple_with_writeback", "*pop_multiple_with_return" and |
| 31233 |
"*pop_multiple_with_writeback_and_return". OPERANDS is the toplevel PARALLEL |
| 31234 |
rtx, RETURN_PC is true if OPERANDS contains return insn. WRITE_BACK_P is |
| 31235 |
true if OPERANDS contains insn which explicit updates base register. */ |
| 31236 |
|
| 31237 |
int |
| 31238 |
arm_attr_length_pop_multi (rtx *operands, bool return_pc, bool write_back_p) |
| 31239 |
{ |
| 31240 |
/* ARM mode. */ |
| 31241 |
if (TARGET_ARM) |
| 31242 |
return 4; |
| 31243 |
/* Thumb1 mode. */ |
| 31244 |
if (TARGET_THUMB1) |
| 31245 |
return 2; |
| 31246 |
|
| 31247 |
rtx parallel_op = operands[0]; |
| 31248 |
/* Initialize to elements number of PARALLEL. */ |
| 31249 |
unsigned indx = XVECLEN (parallel_op, 0) - 1; |
| 31250 |
/* Initialize the value to base register. */ |
| 31251 |
unsigned regno = REGNO (operands[1]); |
| 31252 |
/* Skip return and write back pattern. |
| 31253 |
We only need register pop pattern for later analysis. */ |
| 31254 |
unsigned first_indx = 0; |
| 31255 |
first_indx += return_pc ? 1 : 0; |
| 31256 |
first_indx += write_back_p ? 1 : 0; |
| 31257 |
|
| 31258 |
/* A pop operation can be done through LDM or POP. If the base register is SP |
| 31259 |
and if it's with write back, then a LDM will be alias of POP. */ |
| 31260 |
bool pop_p = (regno == SP_REGNUM && write_back_p); |
| 31261 |
bool ldm_p = !pop_p; |
| 31262 |
|
| 31263 |
/* Check base register for LDM. */ |
| 31264 |
if (ldm_p && REGNO_REG_CLASS (regno) == HI_REGS) |
| 31265 |
return 4; |
| 31266 |
|
| 31267 |
/* Check each register in the list. */ |
| 31268 |
for (; indx >= first_indx; indx--) |
| 31269 |
{ |
| 31270 |
regno = REGNO (XEXP (XVECEXP (parallel_op, 0, indx), 0)); |
| 31271 |
/* For POP, PC in HI_REGS can be used with 16-bit encoding. See similar |
| 31272 |
comment in arm_attr_length_push_multi. */ |
| 31273 |
if (REGNO_REG_CLASS (regno) == HI_REGS |
| 31274 |
&& (regno != PC_REGNUM || ldm_p)) |
| 31275 |
return 4; |
| 31276 |
} |
| 31277 |
|
| 31278 |
return 2; |
| 31279 |
} |
| 31280 |
|
| 31281 |
/* Compute the number of instructions emitted by output_move_double. */ |
| 31282 |
int |
| 31283 |
arm_count_output_move_double_insns (rtx *operands) |
| 31284 |
{ |
| 31285 |
int count; |
| 31286 |
rtx ops[2]; |
| 31287 |
/* output_move_double may modify the operands array, so call it |
| 31288 |
here on a copy of the array. */ |
| 31289 |
ops[0] = operands[0]; |
| 31290 |
ops[1] = operands[1]; |
| 31291 |
output_move_double (ops, false, &count); |
| 31292 |
return count; |
| 31293 |
} |
| 31294 |
|
| 31295 |
/* Same as above, but operands are a register/memory pair in SImode. |
| 31296 |
Assumes operands has the base register in position 0 and memory in position |
| 31297 |
2 (which is the order provided by the arm_{ldrd,strd} patterns). */ |
| 31298 |
int |
| 31299 |
arm_count_ldrdstrd_insns (rtx *operands, bool load) |
| 31300 |
{ |
| 31301 |
int count; |
| 31302 |
rtx ops[2]; |
| 31303 |
int regnum, memnum; |
| 31304 |
if (load) |
| 31305 |
regnum = 0, memnum = 1; |
| 31306 |
else |
| 31307 |
regnum = 1, memnum = 0; |
| 31308 |
ops[regnum] = gen_rtx_REG (DImode, REGNO (operands[0])); |
| 31309 |
ops[memnum] = adjust_address (operands[2], DImode, 0); |
| 31310 |
output_move_double (ops, false, &count); |
| 31311 |
return count; |
| 31312 |
} |
| 31313 |
|
| 31314 |
|
| 31315 |
int |
| 31316 |
vfp3_const_double_for_fract_bits (rtx operand) |
| 31317 |
{ |
| 31318 |
REAL_VALUE_TYPE r0; |
| 31319 |
|
| 31320 |
if (!CONST_DOUBLE_P (operand)) |
| 31321 |
return 0; |
| 31322 |
|
| 31323 |
r0 = *CONST_DOUBLE_REAL_VALUE (operand); |
| 31324 |
if (exact_real_inverse (DFmode, &r0) |
| 31325 |
&& !REAL_VALUE_NEGATIVE (r0)) |
| 31326 |
{ |
| 31327 |
if (exact_real_truncate (DFmode, &r0)) |
| 31328 |
{ |
| 31329 |
HOST_WIDE_INT value = real_to_integer (&r0); |
| 31330 |
value = value & 0xffffffff; |
| 31331 |
if ((value != 0) && ( (value & (value - 1)) == 0)) |
| 31332 |
{ |
| 31333 |
int ret = exact_log2 (value); |
| 31334 |
gcc_assert (IN_RANGE (ret, 0, 31)); |
| 31335 |
return ret; |
| 31336 |
} |
| 31337 |
} |
| 31338 |
} |
| 31339 |
return 0; |
| 31340 |
} |
| 31341 |
|
| 31342 |
/* If X is a CONST_DOUBLE with a value that is a power of 2 whose |
| 31343 |
log2 is in [1, 32], return that log2. Otherwise return -1. |
| 31344 |
This is used in the patterns for vcvt.s32.f32 floating-point to |
| 31345 |
fixed-point conversions. */ |
| 31346 |
|
| 31347 |
int |
| 31348 |
vfp3_const_double_for_bits (rtx x) |
| 31349 |
{ |
| 31350 |
const REAL_VALUE_TYPE *r; |
| 31351 |
|
| 31352 |
if (!CONST_DOUBLE_P (x)) |
| 31353 |
return -1; |
| 31354 |
|
| 31355 |
r = CONST_DOUBLE_REAL_VALUE (x); |
| 31356 |
|
| 31357 |
if (REAL_VALUE_NEGATIVE (*r) |
| 31358 |
|| REAL_VALUE_ISNAN (*r) |
| 31359 |
|| REAL_VALUE_ISINF (*r) |
| 31360 |
|| !real_isinteger (r, SFmode)) |
| 31361 |
return -1; |
| 31362 |
|
| 31363 |
HOST_WIDE_INT hwint = exact_log2 (real_to_integer (r)); |
| 31364 |
|
| 31365 |
/* The exact_log2 above will have returned -1 if this is |
| 31366 |
not an exact log2. */ |
| 31367 |
if (!IN_RANGE (hwint, 1, 32)) |
| 31368 |
return -1; |
| 31369 |
|
| 31370 |
return hwint; |
| 31371 |
} |
| 31372 |
|
| 31373 |
|
| 31374 |
/* Emit a memory barrier around an atomic sequence according to MODEL. */ |
| 31375 |
|
| 31376 |
static void |
| 31377 |
arm_pre_atomic_barrier (enum memmodel model) |
| 31378 |
{ |
| 31379 |
if (need_atomic_barrier_p (model, true)) |
| 31380 |
emit_insn (gen_memory_barrier ()); |
| 31381 |
} |
| 31382 |
|
| 31383 |
static void |
| 31384 |
arm_post_atomic_barrier (enum memmodel model) |
| 31385 |
{ |
| 31386 |
if (need_atomic_barrier_p (model, false)) |
| 31387 |
emit_insn (gen_memory_barrier ()); |
| 31388 |
} |
| 31389 |
|
| 31390 |
/* Emit the load-exclusive and store-exclusive instructions. |
| 31391 |
Use acquire and release versions if necessary. */ |
| 31392 |
|
| 31393 |
static void |
| 31394 |
arm_emit_load_exclusive (machine_mode mode, rtx rval, rtx mem, bool acq) |
| 31395 |
{ |
| 31396 |
rtx (*gen) (rtx, rtx); |
| 31397 |
|
| 31398 |
if (acq) |
| 31399 |
{ |
| 31400 |
switch (mode) |
| 31401 |
{ |
| 31402 |
case E_QImode: gen = gen_arm_load_acquire_exclusiveqi; break; |
| 31403 |
case E_HImode: gen = gen_arm_load_acquire_exclusivehi; break; |
| 31404 |
case E_SImode: gen = gen_arm_load_acquire_exclusivesi; break; |
| 31405 |
case E_DImode: gen = gen_arm_load_acquire_exclusivedi; break; |
| 31406 |
default: |
| 31407 |
gcc_unreachable (); |
| 31408 |
} |
| 31409 |
} |
| 31410 |
else |
| 31411 |
{ |
| 31412 |
switch (mode) |
| 31413 |
{ |
| 31414 |
case E_QImode: gen = gen_arm_load_exclusiveqi; break; |
| 31415 |
case E_HImode: gen = gen_arm_load_exclusivehi; break; |
| 31416 |
case E_SImode: gen = gen_arm_load_exclusivesi; break; |
| 31417 |
case E_DImode: gen = gen_arm_load_exclusivedi; break; |
| 31418 |
default: |
| 31419 |
gcc_unreachable (); |
| 31420 |
} |
| 31421 |
} |
| 31422 |
|
| 31423 |
emit_insn (gen (rval, mem)); |
| 31424 |
} |
| 31425 |
|
| 31426 |
static void |
| 31427 |
arm_emit_store_exclusive (machine_mode mode, rtx bval, rtx rval, |
| 31428 |
rtx mem, bool rel) |
| 31429 |
{ |
| 31430 |
rtx (*gen) (rtx, rtx, rtx); |
| 31431 |
|
| 31432 |
if (rel) |
| 31433 |
{ |
| 31434 |
switch (mode) |
| 31435 |
{ |
| 31436 |
case E_QImode: gen = gen_arm_store_release_exclusiveqi; break; |
| 31437 |
case E_HImode: gen = gen_arm_store_release_exclusivehi; break; |
| 31438 |
case E_SImode: gen = gen_arm_store_release_exclusivesi; break; |
| 31439 |
case E_DImode: gen = gen_arm_store_release_exclusivedi; break; |
| 31440 |
default: |
| 31441 |
gcc_unreachable (); |
| 31442 |
} |
| 31443 |
} |
| 31444 |
else |
| 31445 |
{ |
| 31446 |
switch (mode) |
| 31447 |
{ |
| 31448 |
case E_QImode: gen = gen_arm_store_exclusiveqi; break; |
| 31449 |
case E_HImode: gen = gen_arm_store_exclusivehi; break; |
| 31450 |
case E_SImode: gen = gen_arm_store_exclusivesi; break; |
| 31451 |
case E_DImode: gen = gen_arm_store_exclusivedi; break; |
| 31452 |
default: |
| 31453 |
gcc_unreachable (); |
| 31454 |
} |
| 31455 |
} |
| 31456 |
|
| 31457 |
emit_insn (gen (bval, rval, mem)); |
| 31458 |
} |
| 31459 |
|
| 31460 |
/* Mark the previous jump instruction as unlikely. */ |
| 31461 |
|
| 31462 |
static void |
| 31463 |
emit_unlikely_jump (rtx insn) |
| 31464 |
{ |
| 31465 |
rtx_insn *jump = emit_jump_insn (insn); |
| 31466 |
add_reg_br_prob_note (jump, profile_probability::very_unlikely ()); |
| 31467 |
} |
| 31468 |
|
| 31469 |
/* Expand a compare and swap pattern. */ |
| 31470 |
|
| 31471 |
void |
| 31472 |
arm_expand_compare_and_swap (rtx operands[]) |
| 31473 |
{ |
| 31474 |
rtx bval, bdst, rval, mem, oldval, newval, is_weak, mod_s, mod_f, x; |
| 31475 |
machine_mode mode, cmp_mode; |
| 31476 |
|
| 31477 |
bval = operands[0]; |
| 31478 |
rval = operands[1]; |
| 31479 |
mem = operands[2]; |
| 31480 |
oldval = operands[3]; |
| 31481 |
newval = operands[4]; |
| 31482 |
is_weak = operands[5]; |
| 31483 |
mod_s = operands[6]; |
| 31484 |
mod_f = operands[7]; |
| 31485 |
mode = GET_MODE (mem); |
| 31486 |
|
| 31487 |
/* Normally the succ memory model must be stronger than fail, but in the |
| 31488 |
unlikely event of fail being ACQUIRE and succ being RELEASE we need to |
| 31489 |
promote succ to ACQ_REL so that we don't lose the acquire semantics. */ |
| 31490 |
|
| 31491 |
if (TARGET_HAVE_LDACQ |
| 31492 |
&& is_mm_acquire (memmodel_from_int (INTVAL (mod_f))) |
| 31493 |
&& is_mm_release (memmodel_from_int (INTVAL (mod_s)))) |
| 31494 |
mod_s = GEN_INT (MEMMODEL_ACQ_REL); |
| 31495 |
|
| 31496 |
switch (mode) |
| 31497 |
{ |
| 31498 |
case E_QImode: |
| 31499 |
case E_HImode: |
| 31500 |
/* For narrow modes, we're going to perform the comparison in SImode, |
| 31501 |
so do the zero-extension now. */ |
| 31502 |
rval = gen_reg_rtx (SImode); |
| 31503 |
oldval = convert_modes (SImode, mode, oldval, true); |
| 31504 |
/* FALLTHRU */ |
| 31505 |
|
| 31506 |
case E_SImode: |
| 31507 |
/* Force the value into a register if needed. We waited until after |
| 31508 |
the zero-extension above to do this properly. */ |
| 31509 |
if (!arm_add_operand (oldval, SImode)) |
| 31510 |
oldval = force_reg (SImode, oldval); |
| 31511 |
break; |
| 31512 |
|
| 31513 |
case E_DImode: |
| 31514 |
if (!cmpdi_operand (oldval, mode)) |
| 31515 |
oldval = force_reg (mode, oldval); |
| 31516 |
break; |
| 31517 |
|
| 31518 |
default: |
| 31519 |
gcc_unreachable (); |
| 31520 |
} |
| 31521 |
|
| 31522 |
if (TARGET_THUMB1) |
| 31523 |
cmp_mode = E_SImode; |
| 31524 |
else |
| 31525 |
cmp_mode = CC_Zmode; |
| 31526 |
|
| 31527 |
bdst = TARGET_THUMB1 ? bval : gen_rtx_REG (CC_Zmode, CC_REGNUM); |
| 31528 |
emit_insn (gen_atomic_compare_and_swap_1 (cmp_mode, mode, bdst, rval, mem, |
| 31529 |
oldval, newval, is_weak, mod_s, mod_f)); |
| 31530 |
|
| 31531 |
if (mode == QImode || mode == HImode) |
| 31532 |
emit_move_insn (operands[1], gen_lowpart (mode, rval)); |
| 31533 |
|
| 31534 |
/* In all cases, we arrange for success to be signaled by Z set. |
| 31535 |
This arrangement allows for the boolean result to be used directly |
| 31536 |
in a subsequent branch, post optimization. For Thumb-1 targets, the |
| 31537 |
boolean negation of the result is also stored in bval because Thumb-1 |
| 31538 |
backend lacks dependency tracking for CC flag due to flag-setting not |
| 31539 |
being represented at RTL level. */ |
| 31540 |
if (TARGET_THUMB1) |
| 31541 |
emit_insn (gen_cstoresi_eq0_thumb1 (bval, bdst)); |
| 31542 |
else |
| 31543 |
{ |
| 31544 |
x = gen_rtx_EQ (SImode, bdst, const0_rtx); |
| 31545 |
emit_insn (gen_rtx_SET (bval, x)); |
| 31546 |
} |
| 31547 |
} |
| 31548 |
|
| 31549 |
/* Split a compare and swap pattern. It is IMPLEMENTATION DEFINED whether |
| 31550 |
another memory store between the load-exclusive and store-exclusive can |
| 31551 |
reset the monitor from Exclusive to Open state. This means we must wait |
| 31552 |
until after reload to split the pattern, lest we get a register spill in |
| 31553 |
the middle of the atomic sequence. Success of the compare and swap is |
| 31554 |
indicated by the Z flag set for 32bit targets and by neg_bval being zero |
| 31555 |
for Thumb-1 targets (ie. negation of the boolean value returned by |
| 31556 |
atomic_compare_and_swapmode standard pattern in operand 0). */ |
| 31557 |
|
| 31558 |
void |
| 31559 |
arm_split_compare_and_swap (rtx operands[]) |
| 31560 |
{ |
| 31561 |
rtx rval, mem, oldval, newval, neg_bval, mod_s_rtx; |
| 31562 |
machine_mode mode; |
| 31563 |
enum memmodel mod_s, mod_f; |
| 31564 |
bool is_weak; |
| 31565 |
rtx_code_label *label1, *label2; |
| 31566 |
rtx x, cond; |
| 31567 |
|
| 31568 |
rval = operands[1]; |
| 31569 |
mem = operands[2]; |
| 31570 |
oldval = operands[3]; |
| 31571 |
newval = operands[4]; |
| 31572 |
is_weak = (operands[5] != const0_rtx); |
| 31573 |
mod_s_rtx = operands[6]; |
| 31574 |
mod_s = memmodel_from_int (INTVAL (mod_s_rtx)); |
| 31575 |
mod_f = memmodel_from_int (INTVAL (operands[7])); |
| 31576 |
neg_bval = TARGET_THUMB1 ? operands[0] : operands[8]; |
| 31577 |
mode = GET_MODE (mem); |
| 31578 |
|
| 31579 |
bool is_armv8_sync = arm_arch8 && is_mm_sync (mod_s); |
| 31580 |
|
| 31581 |
bool use_acquire = TARGET_HAVE_LDACQ && aarch_mm_needs_acquire (mod_s_rtx); |
| 31582 |
bool use_release = TARGET_HAVE_LDACQ && aarch_mm_needs_release (mod_s_rtx); |
| 31583 |
|
| 31584 |
/* For ARMv8, the load-acquire is too weak for __sync memory orders. Instead, |
| 31585 |
a full barrier is emitted after the store-release. */ |
| 31586 |
if (is_armv8_sync) |
| 31587 |
use_acquire = false; |
| 31588 |
|
| 31589 |
/* Checks whether a barrier is needed and emits one accordingly. */ |
| 31590 |
if (!(use_acquire || use_release)) |
| 31591 |
arm_pre_atomic_barrier (mod_s); |
| 31592 |
|
| 31593 |
label1 = NULL; |
| 31594 |
if (!is_weak) |
| 31595 |
{ |
| 31596 |
label1 = gen_label_rtx (); |
| 31597 |
emit_label (label1); |
| 31598 |
} |
| 31599 |
label2 = gen_label_rtx (); |
| 31600 |
|
| 31601 |
arm_emit_load_exclusive (mode, rval, mem, use_acquire); |
| 31602 |
|
| 31603 |
/* Z is set to 0 for 32bit targets (resp. rval set to 1) if oldval != rval, |
| 31604 |
as required to communicate with arm_expand_compare_and_swap. */ |
| 31605 |
if (TARGET_32BIT) |
| 31606 |
{ |
| 31607 |
cond = arm_gen_compare_reg (NE, rval, oldval, neg_bval); |
| 31608 |
x = gen_rtx_NE (VOIDmode, cond, const0_rtx); |
| 31609 |
x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, |
| 31610 |
gen_rtx_LABEL_REF (Pmode, label2), pc_rtx); |
| 31611 |
emit_unlikely_jump (gen_rtx_SET (pc_rtx, x)); |
| 31612 |
} |
| 31613 |
else |
| 31614 |
{ |
| 31615 |
cond = gen_rtx_NE (VOIDmode, rval, oldval); |
| 31616 |
if (thumb1_cmpneg_operand (oldval, SImode)) |
| 31617 |
{ |
| 31618 |
rtx src = rval; |
| 31619 |
if (!satisfies_constraint_L (oldval)) |
| 31620 |
{ |
| 31621 |
gcc_assert (satisfies_constraint_J (oldval)); |
| 31622 |
|
| 31623 |
/* For such immediates, ADDS needs the source and destination regs |
| 31624 |
to be the same. |
| 31625 |
|
| 31626 |
Normally this would be handled by RA, but this is all happening |
| 31627 |
after RA. */ |
| 31628 |
emit_move_insn (neg_bval, rval); |
| 31629 |
src = neg_bval; |
| 31630 |
} |
| 31631 |
|
| 31632 |
emit_unlikely_jump (gen_cbranchsi4_neg_late (neg_bval, src, oldval, |
| 31633 |
label2, cond)); |
| 31634 |
} |
| 31635 |
else |
| 31636 |
{ |
| 31637 |
emit_move_insn (neg_bval, const1_rtx); |
| 31638 |
emit_unlikely_jump (gen_cbranchsi4_insn (cond, rval, oldval, label2)); |
| 31639 |
} |
| 31640 |
} |
| 31641 |
|
| 31642 |
arm_emit_store_exclusive (mode, neg_bval, mem, newval, use_release); |
| 31643 |
|
| 31644 |
/* Weak or strong, we want EQ to be true for success, so that we |
| 31645 |
match the flags that we got from the compare above. */ |
| 31646 |
if (TARGET_32BIT) |
| 31647 |
{ |
| 31648 |
cond = gen_rtx_REG (CCmode, CC_REGNUM); |
| 31649 |
x = gen_rtx_COMPARE (CCmode, neg_bval, const0_rtx); |
| 31650 |
emit_insn (gen_rtx_SET (cond, x)); |
| 31651 |
} |
| 31652 |
|
| 31653 |
if (!is_weak) |
| 31654 |
{ |
| 31655 |
/* Z is set to boolean value of !neg_bval, as required to communicate |
| 31656 |
with arm_expand_compare_and_swap. */ |
| 31657 |
x = gen_rtx_NE (VOIDmode, neg_bval, const0_rtx); |
| 31658 |
emit_unlikely_jump (gen_cbranchsi4 (x, neg_bval, const0_rtx, label1)); |
| 31659 |
} |
| 31660 |
|
| 31661 |
if (!is_mm_relaxed (mod_f)) |
| 31662 |
emit_label (label2); |
| 31663 |
|
| 31664 |
/* Checks whether a barrier is needed and emits one accordingly. */ |
| 31665 |
if (is_armv8_sync |
| 31666 |
|| !(use_acquire || use_release)) |
| 31667 |
arm_post_atomic_barrier (mod_s); |
| 31668 |
|
| 31669 |
if (is_mm_relaxed (mod_f)) |
| 31670 |
emit_label (label2); |
| 31671 |
} |
| 31672 |
|
| 31673 |
/* Split an atomic operation pattern. Operation is given by CODE and is one |
| 31674 |
of PLUS, MINUS, IOR, XOR, SET (for an exchange operation) or NOT (for a nand |
| 31675 |
operation). Operation is performed on the content at MEM and on VALUE |
| 31676 |
following the memory model MODEL_RTX. The content at MEM before and after |
| 31677 |
the operation is returned in OLD_OUT and NEW_OUT respectively while the |
| 31678 |
success of the operation is returned in COND. Using a scratch register or |
| 31679 |
an operand register for these determines what result is returned for that |
| 31680 |
pattern. */ |
| 31681 |
|
| 31682 |
void |
| 31683 |
arm_split_atomic_op (enum rtx_code code, rtx old_out, rtx new_out, rtx mem, |
| 31684 |
rtx value, rtx model_rtx, rtx cond) |
| 31685 |
{ |
| 31686 |
enum memmodel model = memmodel_from_int (INTVAL (model_rtx)); |
| 31687 |
machine_mode mode = GET_MODE (mem); |
| 31688 |
machine_mode wmode = (mode == DImode ? DImode : SImode); |
| 31689 |
rtx_code_label *label; |
| 31690 |
bool all_low_regs, bind_old_new; |
| 31691 |
rtx x; |
| 31692 |
|
| 31693 |
bool is_armv8_sync = arm_arch8 && is_mm_sync (model); |
| 31694 |
|
| 31695 |
bool use_acquire = TARGET_HAVE_LDACQ && aarch_mm_needs_acquire (model_rtx); |
| 31696 |
bool use_release = TARGET_HAVE_LDACQ && aarch_mm_needs_release (model_rtx); |
| 31697 |
|
| 31698 |
/* For ARMv8, a load-acquire is too weak for __sync memory orders. Instead, |
| 31699 |
a full barrier is emitted after the store-release. */ |
| 31700 |
if (is_armv8_sync) |
| 31701 |
use_acquire = false; |
| 31702 |
|
| 31703 |
/* Checks whether a barrier is needed and emits one accordingly. */ |
| 31704 |
if (!(use_acquire || use_release)) |
| 31705 |
arm_pre_atomic_barrier (model); |
| 31706 |
|
| 31707 |
label = gen_label_rtx (); |
| 31708 |
emit_label (label); |
| 31709 |
|
| 31710 |
if (new_out) |
| 31711 |
new_out = gen_lowpart (wmode, new_out); |
| 31712 |
if (old_out) |
| 31713 |
old_out = gen_lowpart (wmode, old_out); |
| 31714 |
else |
| 31715 |
old_out = new_out; |
| 31716 |
value = simplify_gen_subreg (wmode, value, mode, 0); |
| 31717 |
|
| 31718 |
arm_emit_load_exclusive (mode, old_out, mem, use_acquire); |
| 31719 |
|
| 31720 |
/* Does the operation require destination and first operand to use the same |
| 31721 |
register? This is decided by register constraints of relevant insn |
| 31722 |
patterns in thumb1.md. */ |
| 31723 |
gcc_assert (!new_out || REG_P (new_out)); |
| 31724 |
all_low_regs = REG_P (value) && REGNO_REG_CLASS (REGNO (value)) == LO_REGS |
| 31725 |
&& new_out && REGNO_REG_CLASS (REGNO (new_out)) == LO_REGS |
| 31726 |
&& REGNO_REG_CLASS (REGNO (old_out)) == LO_REGS; |
| 31727 |
bind_old_new = |
| 31728 |
(TARGET_THUMB1 |
| 31729 |
&& code != SET |
| 31730 |
&& code != MINUS |
| 31731 |
&& (code != PLUS || (!all_low_regs && !satisfies_constraint_L (value)))); |
| 31732 |
|
| 31733 |
/* We want to return the old value while putting the result of the operation |
| 31734 |
in the same register as the old value so copy the old value over to the |
| 31735 |
destination register and use that register for the operation. */ |
| 31736 |
if (old_out && bind_old_new) |
| 31737 |
{ |
| 31738 |
emit_move_insn (new_out, old_out); |
| 31739 |
old_out = new_out; |
| 31740 |
} |
| 31741 |
|
| 31742 |
switch (code) |
| 31743 |
{ |
| 31744 |
case SET: |
| 31745 |
new_out = value; |
| 31746 |
break; |
| 31747 |
|
| 31748 |
case NOT: |
| 31749 |
x = gen_rtx_AND (wmode, old_out, value); |
| 31750 |
emit_insn (gen_rtx_SET (new_out, x)); |
| 31751 |
x = gen_rtx_NOT (wmode, new_out); |
| 31752 |
emit_insn (gen_rtx_SET (new_out, x)); |
| 31753 |
break; |
| 31754 |
|
| 31755 |
case MINUS: |
| 31756 |
if (CONST_INT_P (value)) |
| 31757 |
{ |
| 31758 |
value = gen_int_mode (-INTVAL (value), wmode); |
| 31759 |
code = PLUS; |
| 31760 |
} |
| 31761 |
/* FALLTHRU */ |
| 31762 |
|
| 31763 |
case PLUS: |
| 31764 |
if (mode == DImode) |
| 31765 |
{ |
| 31766 |
/* DImode plus/minus need to clobber flags. */ |
| 31767 |
/* The adddi3 and subdi3 patterns are incorrectly written so that |
| 31768 |
they require matching operands, even when we could easily support |
| 31769 |
three operands. Thankfully, this can be fixed up post-splitting, |
| 31770 |
as the individual add+adc patterns do accept three operands and |
| 31771 |
post-reload cprop can make these moves go away. */ |
| 31772 |
emit_move_insn (new_out, old_out); |
| 31773 |
if (code == PLUS) |
| 31774 |
x = gen_adddi3 (new_out, new_out, value); |
| 31775 |
else |
| 31776 |
x = gen_subdi3 (new_out, new_out, value); |
| 31777 |
emit_insn (x); |
| 31778 |
break; |
| 31779 |
} |
| 31780 |
/* FALLTHRU */ |
| 31781 |
|
| 31782 |
default: |
| 31783 |
x = gen_rtx_fmt_ee (code, wmode, old_out, value); |
| 31784 |
emit_insn (gen_rtx_SET (new_out, x)); |
| 31785 |
break; |
| 31786 |
} |
| 31787 |
|
| 31788 |
arm_emit_store_exclusive (mode, cond, mem, gen_lowpart (mode, new_out), |
| 31789 |
use_release); |
| 31790 |
|
| 31791 |
x = gen_rtx_NE (VOIDmode, cond, const0_rtx); |
| 31792 |
emit_unlikely_jump (gen_cbranchsi4 (x, cond, const0_rtx, label)); |
| 31793 |
|
| 31794 |
/* Checks whether a barrier is needed and emits one accordingly. */ |
| 31795 |
if (is_armv8_sync |
| 31796 |
|| !(use_acquire || use_release)) |
| 31797 |
arm_post_atomic_barrier (model); |
| 31798 |
} |
| 31799 |
|
| 31800 |
/* Return the mode for the MVE vector of predicates corresponding to MODE. */ |
| 31801 |
opt_machine_mode |
| 31802 |
arm_mode_to_pred_mode (machine_mode mode) |
| 31803 |
{ |
| 31804 |
switch (GET_MODE_NUNITS (mode)) |
| 31805 |
{ |
| 31806 |
case 16: return V16BImode; |
| 31807 |
case 8: return V8BImode; |
| 31808 |
case 4: return V4BImode; |
| 31809 |
case 2: return V2QImode; |
| 31810 |
} |
| 31811 |
return opt_machine_mode (); |
| 31812 |
} |
| 31813 |
|
| 31814 |
/* Expand code to compare vectors OP0 and OP1 using condition CODE. |
| 31815 |
If CAN_INVERT, store either the result or its inverse in TARGET |
| 31816 |
and return true if TARGET contains the inverse. If !CAN_INVERT, |
| 31817 |
always store the result in TARGET, never its inverse. |
| 31818 |
|
| 31819 |
Note that the handling of floating-point comparisons is not |
| 31820 |
IEEE compliant. */ |
| 31821 |
|
| 31822 |
bool |
| 31823 |
arm_expand_vector_compare (rtx target, rtx_code code, rtx op0, rtx op1, |
| 31824 |
bool can_invert) |
| 31825 |
{ |
| 31826 |
machine_mode cmp_result_mode = GET_MODE (target); |
| 31827 |
machine_mode cmp_mode = GET_MODE (op0); |
| 31828 |
|
| 31829 |
bool inverted; |
| 31830 |
|
| 31831 |
/* MVE supports more comparisons than Neon. */ |
| 31832 |
if (TARGET_HAVE_MVE) |
| 31833 |
inverted = false; |
| 31834 |
else |
| 31835 |
switch (code) |
| 31836 |
{ |
| 31837 |
/* For these we need to compute the inverse of the requested |
| 31838 |
comparison. */ |
| 31839 |
case UNORDERED: |
| 31840 |
case UNLT: |
| 31841 |
case UNLE: |
| 31842 |
case UNGT: |
| 31843 |
case UNGE: |
| 31844 |
case UNEQ: |
| 31845 |
case NE: |
| 31846 |
code = reverse_condition_maybe_unordered (code); |
| 31847 |
if (!can_invert) |
| 31848 |
{ |
| 31849 |
/* Recursively emit the inverted comparison into a temporary |
| 31850 |
and then store its inverse in TARGET. This avoids reusing |
| 31851 |
TARGET (which for integer NE could be one of the inputs). */ |
| 31852 |
rtx tmp = gen_reg_rtx (cmp_result_mode); |
| 31853 |
if (arm_expand_vector_compare (tmp, code, op0, op1, true)) |
| 31854 |
gcc_unreachable (); |
| 31855 |
emit_insn (gen_rtx_SET (target, gen_rtx_NOT (cmp_result_mode, tmp))); |
| 31856 |
return false; |
| 31857 |
} |
| 31858 |
inverted = true; |
| 31859 |
break; |
| 31860 |
|
| 31861 |
default: |
| 31862 |
inverted = false; |
| 31863 |
break; |
| 31864 |
} |
| 31865 |
|
| 31866 |
switch (code) |
| 31867 |
{ |
| 31868 |
/* These are natively supported by Neon for zero comparisons, but otherwise |
| 31869 |
require the operands to be swapped. For MVE, we can only compare |
| 31870 |
registers. */ |
| 31871 |
case LE: |
| 31872 |
case LT: |
| 31873 |
if (!TARGET_HAVE_MVE) |
| 31874 |
if (op1 != CONST0_RTX (cmp_mode)) |
| 31875 |
{ |
| 31876 |
code = swap_condition (code); |
| 31877 |
std::swap (op0, op1); |
| 31878 |
} |
| 31879 |
/* Fall through. */ |
| 31880 |
|
| 31881 |
/* These are natively supported by Neon for both register and zero |
| 31882 |
operands. MVE supports registers only. */ |
| 31883 |
case EQ: |
| 31884 |
case GE: |
| 31885 |
case GT: |
| 31886 |
case NE: |
| 31887 |
if (TARGET_HAVE_MVE) |
| 31888 |
{ |
| 31889 |
switch (GET_MODE_CLASS (cmp_mode)) |
| 31890 |
{ |
| 31891 |
case MODE_VECTOR_INT: |
| 31892 |
emit_insn (gen_mve_vcmpq (code, cmp_mode, target, |
| 31893 |
op0, force_reg (cmp_mode, op1))); |
| 31894 |
break; |
| 31895 |
case MODE_VECTOR_FLOAT: |
| 31896 |
if (TARGET_HAVE_MVE_FLOAT) |
| 31897 |
emit_insn (gen_mve_vcmpq_f (code, cmp_mode, target, |
| 31898 |
op0, force_reg (cmp_mode, op1))); |
| 31899 |
else |
| 31900 |
gcc_unreachable (); |
| 31901 |
break; |
| 31902 |
default: |
| 31903 |
gcc_unreachable (); |
| 31904 |
} |
| 31905 |
} |
| 31906 |
else |
| 31907 |
emit_insn (gen_neon_vc (code, cmp_mode, target, op0, op1)); |
| 31908 |
return inverted; |
| 31909 |
|
| 31910 |
/* These are natively supported for register operands only. |
| 31911 |
Comparisons with zero aren't useful and should be folded |
| 31912 |
or canonicalized by target-independent code. */ |
| 31913 |
case GEU: |
| 31914 |
case GTU: |
| 31915 |
if (TARGET_HAVE_MVE) |
| 31916 |
emit_insn (gen_mve_vcmpq (code, cmp_mode, target, |
| 31917 |
op0, force_reg (cmp_mode, op1))); |
| 31918 |
else |
| 31919 |
emit_insn (gen_neon_vc (code, cmp_mode, target, |
| 31920 |
op0, force_reg (cmp_mode, op1))); |
| 31921 |
return inverted; |
| 31922 |
|
| 31923 |
/* These require the operands to be swapped and likewise do not |
| 31924 |
support comparisons with zero. */ |
| 31925 |
case LEU: |
| 31926 |
case LTU: |
| 31927 |
if (TARGET_HAVE_MVE) |
| 31928 |
emit_insn (gen_mve_vcmpq (swap_condition (code), cmp_mode, target, |
| 31929 |
force_reg (cmp_mode, op1), op0)); |
| 31930 |
else |
| 31931 |
emit_insn (gen_neon_vc (swap_condition (code), cmp_mode, |
| 31932 |
target, force_reg (cmp_mode, op1), op0)); |
| 31933 |
return inverted; |
| 31934 |
|
| 31935 |
/* These need a combination of two comparisons. */ |
| 31936 |
case LTGT: |
| 31937 |
case ORDERED: |
| 31938 |
{ |
| 31939 |
/* Operands are LTGT iff (a > b || a > b). |
| 31940 |
Operands are ORDERED iff (a > b || a <= b). */ |
| 31941 |
rtx gt_res = gen_reg_rtx (cmp_result_mode); |
| 31942 |
rtx alt_res = gen_reg_rtx (cmp_result_mode); |
| 31943 |
rtx_code alt_code = (code == LTGT ? LT : LE); |
| 31944 |
if (arm_expand_vector_compare (gt_res, GT, op0, op1, true) |
| 31945 |
|| arm_expand_vector_compare (alt_res, alt_code, op0, op1, true)) |
| 31946 |
gcc_unreachable (); |
| 31947 |
emit_insn (gen_rtx_SET (target, gen_rtx_IOR (cmp_result_mode, |
| 31948 |
gt_res, alt_res))); |
| 31949 |
return inverted; |
| 31950 |
} |
| 31951 |
|
| 31952 |
default: |
| 31953 |
gcc_unreachable (); |
| 31954 |
} |
| 31955 |
} |
| 31956 |
|
| 31957 |
|
| 31958 |
#define MAX_VECT_LEN 16 |
| 31959 |
|
| 31960 |
struct expand_vec_perm_d |
| 31961 |
{ |
| 31962 |
rtx target, op0, op1; |
| 31963 |
vec_perm_indices perm; |
| 31964 |
machine_mode vmode; |
| 31965 |
bool one_vector_p; |
| 31966 |
bool testing_p; |
| 31967 |
}; |
| 31968 |
|
| 31969 |
/* Generate a variable permutation. */ |
| 31970 |
|
| 31971 |
static void |
| 31972 |
arm_expand_vec_perm_1 (rtx target, rtx op0, rtx op1, rtx sel) |
| 31973 |
{ |
| 31974 |
machine_mode vmode = GET_MODE (target); |
| 31975 |
bool one_vector_p = rtx_equal_p (op0, op1); |
| 31976 |
|
| 31977 |
gcc_checking_assert (vmode == V8QImode || vmode == V16QImode); |
| 31978 |
gcc_checking_assert (GET_MODE (op0) == vmode); |
| 31979 |
gcc_checking_assert (GET_MODE (op1) == vmode); |
| 31980 |
gcc_checking_assert (GET_MODE (sel) == vmode); |
| 31981 |
gcc_checking_assert (TARGET_NEON); |
| 31982 |
|
| 31983 |
if (one_vector_p) |
| 31984 |
{ |
| 31985 |
if (vmode == V8QImode) |
| 31986 |
emit_insn (gen_neon_vtbl1v8qi (target, op0, sel)); |
| 31987 |
else |
| 31988 |
emit_insn (gen_neon_vtbl1v16qi (target, op0, sel)); |
| 31989 |
} |
| 31990 |
else |
| 31991 |
{ |
| 31992 |
rtx pair; |
| 31993 |
|
| 31994 |
if (vmode == V8QImode) |
| 31995 |
{ |
| 31996 |
pair = gen_reg_rtx (V16QImode); |
| 31997 |
emit_insn (gen_neon_vcombinev8qi (pair, op0, op1)); |
| 31998 |
pair = gen_lowpart (TImode, pair); |
| 31999 |
emit_insn (gen_neon_vtbl2v8qi (target, pair, sel)); |
| 32000 |
} |
| 32001 |
else |
| 32002 |
{ |
| 32003 |
pair = gen_reg_rtx (OImode); |
| 32004 |
emit_insn (gen_neon_vcombinev16qi (pair, op0, op1)); |
| 32005 |
emit_insn (gen_neon_vtbl2v16qi (target, pair, sel)); |
| 32006 |
} |
| 32007 |
} |
| 32008 |
} |
| 32009 |
|
| 32010 |
void |
| 32011 |
arm_expand_vec_perm (rtx target, rtx op0, rtx op1, rtx sel) |
| 32012 |
{ |
| 32013 |
machine_mode vmode = GET_MODE (target); |
| 32014 |
unsigned int nelt = GET_MODE_NUNITS (vmode); |
| 32015 |
bool one_vector_p = rtx_equal_p (op0, op1); |
| 32016 |
rtx mask; |
| 32017 |
|
| 32018 |
/* TODO: ARM's VTBL indexing is little-endian. In order to handle GCC's |
| 32019 |
numbering of elements for big-endian, we must reverse the order. */ |
| 32020 |
gcc_checking_assert (!BYTES_BIG_ENDIAN); |
| 32021 |
|
| 32022 |
/* The VTBL instruction does not use a modulo index, so we must take care |
| 32023 |
of that ourselves. */ |
| 32024 |
mask = GEN_INT (one_vector_p ? nelt - 1 : 2 * nelt - 1); |
| 32025 |
mask = gen_const_vec_duplicate (vmode, mask); |
| 32026 |
sel = expand_simple_binop (vmode, AND, sel, mask, NULL, 0, OPTAB_LIB_WIDEN); |
| 32027 |
|
| 32028 |
arm_expand_vec_perm_1 (target, op0, op1, sel); |
| 32029 |
} |
| 32030 |
|
| 32031 |
/* Map lane ordering between architectural lane order, and GCC lane order, |
| 32032 |
taking into account ABI. See comment above output_move_neon for details. */ |
| 32033 |
|
| 32034 |
static int |
| 32035 |
neon_endian_lane_map (machine_mode mode, int lane) |
| 32036 |
{ |
| 32037 |
if (BYTES_BIG_ENDIAN) |
| 32038 |
{ |
| 32039 |
int nelems = GET_MODE_NUNITS (mode); |
| 32040 |
/* Reverse lane order. */ |
| 32041 |
lane = (nelems - 1 - lane); |
| 32042 |
/* Reverse D register order, to match ABI. */ |
| 32043 |
if (GET_MODE_SIZE (mode) == 16) |
| 32044 |
lane = lane ^ (nelems / 2); |
| 32045 |
} |
| 32046 |
return lane; |
| 32047 |
} |
| 32048 |
|
| 32049 |
/* Some permutations index into pairs of vectors, this is a helper function |
| 32050 |
to map indexes into those pairs of vectors. */ |
| 32051 |
|
| 32052 |
static int |
| 32053 |
neon_pair_endian_lane_map (machine_mode mode, int lane) |
| 32054 |
{ |
| 32055 |
int nelem = GET_MODE_NUNITS (mode); |
| 32056 |
if (BYTES_BIG_ENDIAN) |
| 32057 |
lane = |
| 32058 |
neon_endian_lane_map (mode, lane & (nelem - 1)) + (lane & nelem); |
| 32059 |
return lane; |
| 32060 |
} |
| 32061 |
|
| 32062 |
/* Generate or test for an insn that supports a constant permutation. */ |
| 32063 |
|
| 32064 |
/* Recognize patterns for the VUZP insns. */ |
| 32065 |
|
| 32066 |
static bool |
| 32067 |
arm_evpc_neon_vuzp (struct expand_vec_perm_d *d) |
| 32068 |
{ |
| 32069 |
unsigned int i, odd, mask, nelt = d->perm.length (); |
| 32070 |
rtx out0, out1, in0, in1; |
| 32071 |
int first_elem; |
| 32072 |
int swap_nelt; |
| 32073 |
|
| 32074 |
if (GET_MODE_UNIT_SIZE (d->vmode) >= 8) |
| 32075 |
return false; |
| 32076 |
|
| 32077 |
/* arm_expand_vec_perm_const_1 () helpfully swaps the operands for the |
| 32078 |
big endian pattern on 64 bit vectors, so we correct for that. */ |
| 32079 |
swap_nelt = BYTES_BIG_ENDIAN && !d->one_vector_p |
| 32080 |
&& GET_MODE_SIZE (d->vmode) == 8 ? nelt : 0; |
| 32081 |
|
| 32082 |
first_elem = d->perm[neon_endian_lane_map (d->vmode, 0)] ^ swap_nelt; |
| 32083 |
|
| 32084 |
if (first_elem == neon_endian_lane_map (d->vmode, 0)) |
| 32085 |
odd = 0; |
| 32086 |
else if (first_elem == neon_endian_lane_map (d->vmode, 1)) |
| 32087 |
odd = 1; |
| 32088 |
else |
| 32089 |
return false; |
| 32090 |
mask = (d->one_vector_p ? nelt - 1 : 2 * nelt - 1); |
| 32091 |
|
| 32092 |
for (i = 0; i < nelt; i++) |
| 32093 |
{ |
| 32094 |
unsigned elt = |
| 32095 |
(neon_pair_endian_lane_map (d->vmode, i) * 2 + odd) & mask; |
| 32096 |
if ((d->perm[i] ^ swap_nelt) != neon_pair_endian_lane_map (d->vmode, elt)) |
| 32097 |
return false; |
| 32098 |
} |
| 32099 |
|
| 32100 |
/* Success! */ |
| 32101 |
if (d->testing_p) |
| 32102 |
return true; |
| 32103 |
|
| 32104 |
in0 = d->op0; |
| 32105 |
in1 = d->op1; |
| 32106 |
if (swap_nelt != 0) |
| 32107 |
std::swap (in0, in1); |
| 32108 |
|
| 32109 |
out0 = d->target; |
| 32110 |
out1 = gen_reg_rtx (d->vmode); |
| 32111 |
if (odd) |
| 32112 |
std::swap (out0, out1); |
| 32113 |
|
| 32114 |
emit_insn (gen_neon_vuzp_internal (d->vmode, out0, in0, in1, out1)); |
| 32115 |
return true; |
| 32116 |
} |
| 32117 |
|
| 32118 |
/* Recognize patterns for the VZIP insns. */ |
| 32119 |
|
| 32120 |
static bool |
| 32121 |
arm_evpc_neon_vzip (struct expand_vec_perm_d *d) |
| 32122 |
{ |
| 32123 |
unsigned int i, high, mask, nelt = d->perm.length (); |
| 32124 |
rtx out0, out1, in0, in1; |
| 32125 |
int first_elem; |
| 32126 |
bool is_swapped; |
| 32127 |
|
| 32128 |
if (GET_MODE_UNIT_SIZE (d->vmode) >= 8) |
| 32129 |
return false; |
| 32130 |
|
| 32131 |
is_swapped = BYTES_BIG_ENDIAN; |
| 32132 |
|
| 32133 |
first_elem = d->perm[neon_endian_lane_map (d->vmode, 0) ^ is_swapped]; |
| 32134 |
|
| 32135 |
high = nelt / 2; |
| 32136 |
if (first_elem == neon_endian_lane_map (d->vmode, high)) |
| 32137 |
; |
| 32138 |
else if (first_elem == neon_endian_lane_map (d->vmode, 0)) |
| 32139 |
high = 0; |
| 32140 |
else |
| 32141 |
return false; |
| 32142 |
mask = (d->one_vector_p ? nelt - 1 : 2 * nelt - 1); |
| 32143 |
|
| 32144 |
for (i = 0; i < nelt / 2; i++) |
| 32145 |
{ |
| 32146 |
unsigned elt = |
| 32147 |
neon_pair_endian_lane_map (d->vmode, i + high) & mask; |
| 32148 |
if (d->perm[neon_pair_endian_lane_map (d->vmode, 2 * i + is_swapped)] |
| 32149 |
!= elt) |
| 32150 |
return false; |
| 32151 |
elt = |
| 32152 |
neon_pair_endian_lane_map (d->vmode, i + nelt + high) & mask; |
| 32153 |
if (d->perm[neon_pair_endian_lane_map (d->vmode, 2 * i + !is_swapped)] |
| 32154 |
!= elt) |
| 32155 |
return false; |
| 32156 |
} |
| 32157 |
|
| 32158 |
/* Success! */ |
| 32159 |
if (d->testing_p) |
| 32160 |
return true; |
| 32161 |
|
| 32162 |
in0 = d->op0; |
| 32163 |
in1 = d->op1; |
| 32164 |
if (is_swapped) |
| 32165 |
std::swap (in0, in1); |
| 32166 |
|
| 32167 |
out0 = d->target; |
| 32168 |
out1 = gen_reg_rtx (d->vmode); |
| 32169 |
if (high) |
| 32170 |
std::swap (out0, out1); |
| 32171 |
|
| 32172 |
emit_insn (gen_neon_vzip_internal (d->vmode, out0, in0, in1, out1)); |
| 32173 |
return true; |
| 32174 |
} |
| 32175 |
|
| 32176 |
/* Recognize patterns for the VREV insns. */ |
| 32177 |
static bool |
| 32178 |
arm_evpc_neon_vrev (struct expand_vec_perm_d *d) |
| 32179 |
{ |
| 32180 |
unsigned int i, j, diff, nelt = d->perm.length (); |
| 32181 |
rtx (*gen) (machine_mode, rtx, rtx); |
| 32182 |
|
| 32183 |
if (!d->one_vector_p) |
| 32184 |
return false; |
| 32185 |
|
| 32186 |
diff = d->perm[0]; |
| 32187 |
switch (diff) |
| 32188 |
{ |
| 32189 |
case 7: |
| 32190 |
switch (d->vmode) |
| 32191 |
{ |
| 32192 |
case E_V16QImode: |
| 32193 |
case E_V8QImode: |
| 32194 |
gen = gen_neon_vrev64; |
| 32195 |
break; |
| 32196 |
default: |
| 32197 |
return false; |
| 32198 |
} |
| 32199 |
break; |
| 32200 |
case 3: |
| 32201 |
switch (d->vmode) |
| 32202 |
{ |
| 32203 |
case E_V16QImode: |
| 32204 |
case E_V8QImode: |
| 32205 |
gen = gen_neon_vrev32; |
| 32206 |
break; |
| 32207 |
case E_V8HImode: |
| 32208 |
case E_V4HImode: |
| 32209 |
case E_V8HFmode: |
| 32210 |
case E_V4HFmode: |
| 32211 |
gen = gen_neon_vrev64; |
| 32212 |
break; |
| 32213 |
default: |
| 32214 |
return false; |
| 32215 |
} |
| 32216 |
break; |
| 32217 |
case 1: |
| 32218 |
switch (d->vmode) |
| 32219 |
{ |
| 32220 |
case E_V16QImode: |
| 32221 |
case E_V8QImode: |
| 32222 |
gen = gen_neon_vrev16; |
| 32223 |
break; |
| 32224 |
case E_V8HImode: |
| 32225 |
case E_V4HImode: |
| 32226 |
gen = gen_neon_vrev32; |
| 32227 |
break; |
| 32228 |
case E_V4SImode: |
| 32229 |
case E_V2SImode: |
| 32230 |
case E_V4SFmode: |
| 32231 |
case E_V2SFmode: |
| 32232 |
gen = gen_neon_vrev64; |
| 32233 |
break; |
| 32234 |
default: |
| 32235 |
return false; |
| 32236 |
} |
| 32237 |
break; |
| 32238 |
default: |
| 32239 |
return false; |
| 32240 |
} |
| 32241 |
|
| 32242 |
for (i = 0; i < nelt ; i += diff + 1) |
| 32243 |
for (j = 0; j <= diff; j += 1) |
| 32244 |
{ |
| 32245 |
/* This is guaranteed to be true as the value of diff |
| 32246 |
is 7, 3, 1 and we should have enough elements in the |
| 32247 |
queue to generate this. Getting a vector mask with a |
| 32248 |
value of diff other than these values implies that |
| 32249 |
something is wrong by the time we get here. */ |
| 32250 |
gcc_assert (i + j < nelt); |
| 32251 |
if (d->perm[i + j] != i + diff - j) |
| 32252 |
return false; |
| 32253 |
} |
| 32254 |
|
| 32255 |
/* Success! */ |
| 32256 |
if (d->testing_p) |
| 32257 |
return true; |
| 32258 |
|
| 32259 |
emit_insn (gen (d->vmode, d->target, d->op0)); |
| 32260 |
return true; |
| 32261 |
} |
| 32262 |
|
| 32263 |
/* Recognize patterns for the VTRN insns. */ |
| 32264 |
|
| 32265 |
static bool |
| 32266 |
arm_evpc_neon_vtrn (struct expand_vec_perm_d *d) |
| 32267 |
{ |
| 32268 |
unsigned int i, odd, mask, nelt = d->perm.length (); |
| 32269 |
rtx out0, out1, in0, in1; |
| 32270 |
|
| 32271 |
if (GET_MODE_UNIT_SIZE (d->vmode) >= 8) |
| 32272 |
return false; |
| 32273 |
|
| 32274 |
/* Note that these are little-endian tests. Adjust for big-endian later. */ |
| 32275 |
if (d->perm[0] == 0) |
| 32276 |
odd = 0; |
| 32277 |
else if (d->perm[0] == 1) |
| 32278 |
odd = 1; |
| 32279 |
else |
| 32280 |
return false; |
| 32281 |
mask = (d->one_vector_p ? nelt - 1 : 2 * nelt - 1); |
| 32282 |
|
| 32283 |
for (i = 0; i < nelt; i += 2) |
| 32284 |
{ |
| 32285 |
if (d->perm[i] != i + odd) |
| 32286 |
return false; |
| 32287 |
if (d->perm[i + 1] != ((i + nelt + odd) & mask)) |
| 32288 |
return false; |
| 32289 |
} |
| 32290 |
|
| 32291 |
/* Success! */ |
| 32292 |
if (d->testing_p) |
| 32293 |
return true; |
| 32294 |
|
| 32295 |
in0 = d->op0; |
| 32296 |
in1 = d->op1; |
| 32297 |
if (BYTES_BIG_ENDIAN) |
| 32298 |
{ |
| 32299 |
std::swap (in0, in1); |
| 32300 |
odd = !odd; |
| 32301 |
} |
| 32302 |
|
| 32303 |
out0 = d->target; |
| 32304 |
out1 = gen_reg_rtx (d->vmode); |
| 32305 |
if (odd) |
| 32306 |
std::swap (out0, out1); |
| 32307 |
|
| 32308 |
emit_insn (gen_neon_vtrn_internal (d->vmode, out0, in0, in1, out1)); |
| 32309 |
return true; |
| 32310 |
} |
| 32311 |
|
| 32312 |
/* Recognize patterns for the VEXT insns. */ |
| 32313 |
|
| 32314 |
static bool |
| 32315 |
arm_evpc_neon_vext (struct expand_vec_perm_d *d) |
| 32316 |
{ |
| 32317 |
unsigned int i, nelt = d->perm.length (); |
| 32318 |
rtx offset; |
| 32319 |
|
| 32320 |
unsigned int location; |
| 32321 |
|
| 32322 |
unsigned int next = d->perm[0] + 1; |
| 32323 |
|
| 32324 |
/* TODO: Handle GCC's numbering of elements for big-endian. */ |
| 32325 |
if (BYTES_BIG_ENDIAN) |
| 32326 |
return false; |
| 32327 |
|
| 32328 |
/* Check if the extracted indexes are increasing by one. */ |
| 32329 |
for (i = 1; i < nelt; next++, i++) |
| 32330 |
{ |
| 32331 |
/* If we hit the most significant element of the 2nd vector in |
| 32332 |
the previous iteration, no need to test further. */ |
| 32333 |
if (next == 2 * nelt) |
| 32334 |
return false; |
| 32335 |
|
| 32336 |
/* If we are operating on only one vector: it could be a |
| 32337 |
rotation. If there are only two elements of size < 64, let |
| 32338 |
arm_evpc_neon_vrev catch it. */ |
| 32339 |
if (d->one_vector_p && (next == nelt)) |
| 32340 |
{ |
| 32341 |
if ((nelt == 2) && (d->vmode != V2DImode)) |
| 32342 |
return false; |
| 32343 |
else |
| 32344 |
next = 0; |
| 32345 |
} |
| 32346 |
|
| 32347 |
if (d->perm[i] != next) |
| 32348 |
return false; |
| 32349 |
} |
| 32350 |
|
| 32351 |
location = d->perm[0]; |
| 32352 |
|
| 32353 |
/* Success! */ |
| 32354 |
if (d->testing_p) |
| 32355 |
return true; |
| 32356 |
|
| 32357 |
offset = GEN_INT (location); |
| 32358 |
|
| 32359 |
if(d->vmode == E_DImode) |
| 32360 |
return false; |
| 32361 |
|
| 32362 |
emit_insn (gen_neon_vext (d->vmode, d->target, d->op0, d->op1, offset)); |
| 32363 |
return true; |
| 32364 |
} |
| 32365 |
|
| 32366 |
/* The NEON VTBL instruction is a fully variable permuation that's even |
| 32367 |
stronger than what we expose via VEC_PERM_EXPR. What it doesn't do |
| 32368 |
is mask the index operand as VEC_PERM_EXPR requires. Therefore we |
| 32369 |
can do slightly better by expanding this as a constant where we don't |
| 32370 |
have to apply a mask. */ |
| 32371 |
|
| 32372 |
static bool |
| 32373 |
arm_evpc_neon_vtbl (struct expand_vec_perm_d *d) |
| 32374 |
{ |
| 32375 |
rtx rperm[MAX_VECT_LEN], sel; |
| 32376 |
machine_mode vmode = d->vmode; |
| 32377 |
unsigned int i, nelt = d->perm.length (); |
| 32378 |
|
| 32379 |
/* TODO: ARM's VTBL indexing is little-endian. In order to handle GCC's |
| 32380 |
numbering of elements for big-endian, we must reverse the order. */ |
| 32381 |
if (BYTES_BIG_ENDIAN) |
| 32382 |
return false; |
| 32383 |
|
| 32384 |
if (d->testing_p) |
| 32385 |
return true; |
| 32386 |
|
| 32387 |
/* Generic code will try constant permutation twice. Once with the |
| 32388 |
original mode and again with the elements lowered to QImode. |
| 32389 |
So wait and don't do the selector expansion ourselves. */ |
| 32390 |
if (vmode != V8QImode && vmode != V16QImode) |
| 32391 |
return false; |
| 32392 |
|
| 32393 |
for (i = 0; i < nelt; ++i) |
| 32394 |
rperm[i] = GEN_INT (d->perm[i]); |
| 32395 |
sel = gen_rtx_CONST_VECTOR (vmode, gen_rtvec_v (nelt, rperm)); |
| 32396 |
sel = force_reg (vmode, sel); |
| 32397 |
|
| 32398 |
arm_expand_vec_perm_1 (d->target, d->op0, d->op1, sel); |
| 32399 |
return true; |
| 32400 |
} |
| 32401 |
|
| 32402 |
static bool |
| 32403 |
arm_expand_vec_perm_const_1 (struct expand_vec_perm_d *d) |
| 32404 |
{ |
| 32405 |
/* Check if the input mask matches vext before reordering the |
| 32406 |
operands. */ |
| 32407 |
if (TARGET_NEON) |
| 32408 |
if (arm_evpc_neon_vext (d)) |
| 32409 |
return true; |
| 32410 |
|
| 32411 |
/* The pattern matching functions above are written to look for a small |
| 32412 |
number to begin the sequence (0, 1, N/2). If we begin with an index |
| 32413 |
from the second operand, we can swap the operands. */ |
| 32414 |
unsigned int nelt = d->perm.length (); |
| 32415 |
if (d->perm[0] >= nelt) |
| 32416 |
{ |
| 32417 |
d->perm.rotate_inputs (1); |
| 32418 |
std::swap (d->op0, d->op1); |
| 32419 |
} |
| 32420 |
|
| 32421 |
if (TARGET_NEON) |
| 32422 |
{ |
| 32423 |
if (arm_evpc_neon_vuzp (d)) |
| 32424 |
return true; |
| 32425 |
if (arm_evpc_neon_vzip (d)) |
| 32426 |
return true; |
| 32427 |
if (arm_evpc_neon_vrev (d)) |
| 32428 |
return true; |
| 32429 |
if (arm_evpc_neon_vtrn (d)) |
| 32430 |
return true; |
| 32431 |
return arm_evpc_neon_vtbl (d); |
| 32432 |
} |
| 32433 |
return false; |
| 32434 |
} |
| 32435 |
|
| 32436 |
/* Implement TARGET_VECTORIZE_VEC_PERM_CONST. */ |
| 32437 |
|
| 32438 |
static bool |
| 32439 |
arm_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode, |
| 32440 |
rtx target, rtx op0, rtx op1, |
| 32441 |
const vec_perm_indices &sel) |
| 32442 |
{ |
| 32443 |
if (vmode != op_mode) |
| 32444 |
return false; |
| 32445 |
|
| 32446 |
struct expand_vec_perm_d d; |
| 32447 |
int i, nelt, which; |
| 32448 |
|
| 32449 |
if (!VALID_NEON_DREG_MODE (vmode) && !VALID_NEON_QREG_MODE (vmode)) |
| 32450 |
return false; |
| 32451 |
|
| 32452 |
d.target = target; |
| 32453 |
if (op0) |
| 32454 |
{ |
| 32455 |
rtx nop0 = force_reg (vmode, op0); |
| 32456 |
if (op0 == op1) |
| 32457 |
op1 = nop0; |
| 32458 |
op0 = nop0; |
| 32459 |
} |
| 32460 |
if (op1) |
| 32461 |
op1 = force_reg (vmode, op1); |
| 32462 |
d.op0 = op0; |
| 32463 |
d.op1 = op1; |
| 32464 |
|
| 32465 |
d.vmode = vmode; |
| 32466 |
gcc_assert (VECTOR_MODE_P (d.vmode)); |
| 32467 |
d.testing_p = !target; |
| 32468 |
|
| 32469 |
nelt = GET_MODE_NUNITS (d.vmode); |
| 32470 |
for (i = which = 0; i < nelt; ++i) |
| 32471 |
{ |
| 32472 |
int ei = sel[i] & (2 * nelt - 1); |
| 32473 |
which |= (ei < nelt ? 1 : 2); |
| 32474 |
} |
| 32475 |
|
| 32476 |
switch (which) |
| 32477 |
{ |
| 32478 |
default: |
| 32479 |
gcc_unreachable(); |
| 32480 |
|
| 32481 |
case 3: |
| 32482 |
d.one_vector_p = false; |
| 32483 |
if (d.testing_p || !rtx_equal_p (op0, op1)) |
| 32484 |
break; |
| 32485 |
|
| 32486 |
/* The elements of PERM do not suggest that only the first operand |
| 32487 |
is used, but both operands are identical. Allow easier matching |
| 32488 |
of the permutation by folding the permutation into the single |
| 32489 |
input vector. */ |
| 32490 |
/* FALLTHRU */ |
| 32491 |
case 2: |
| 32492 |
d.op0 = op1; |
| 32493 |
d.one_vector_p = true; |
| 32494 |
break; |
| 32495 |
|
| 32496 |
case 1: |
| 32497 |
d.op1 = op0; |
| 32498 |
d.one_vector_p = true; |
| 32499 |
break; |
| 32500 |
} |
| 32501 |
|
| 32502 |
d.perm.new_vector (sel.encoding (), d.one_vector_p ? 1 : 2, nelt); |
| 32503 |
|
| 32504 |
if (!d.testing_p) |
| 32505 |
return arm_expand_vec_perm_const_1 (&d); |
| 32506 |
|
| 32507 |
d.target = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 1); |
| 32508 |
d.op1 = d.op0 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 2); |
| 32509 |
if (!d.one_vector_p) |
| 32510 |
d.op1 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 3); |
| 32511 |
|
| 32512 |
start_sequence (); |
| 32513 |
bool ret = arm_expand_vec_perm_const_1 (&d); |
| 32514 |
end_sequence (); |
| 32515 |
|
| 32516 |
return ret; |
| 32517 |
} |
| 32518 |
|
| 32519 |
bool |
| 32520 |
arm_autoinc_modes_ok_p (machine_mode mode, enum arm_auto_incmodes code) |
| 32521 |
{ |
| 32522 |
/* If we are soft float and we do not have ldrd |
| 32523 |
then all auto increment forms are ok. */ |
| 32524 |
if (TARGET_SOFT_FLOAT && (TARGET_LDRD || GET_MODE_SIZE (mode) <= 4)) |
| 32525 |
return true; |
| 32526 |
|
| 32527 |
switch (code) |
| 32528 |
{ |
| 32529 |
/* Post increment and Pre Decrement are supported for all |
| 32530 |
instruction forms except for vector forms. */ |
| 32531 |
case ARM_POST_INC: |
| 32532 |
case ARM_PRE_DEC: |
| 32533 |
if (VECTOR_MODE_P (mode)) |
| 32534 |
{ |
| 32535 |
if (code != ARM_PRE_DEC) |
| 32536 |
return true; |
| 32537 |
else |
| 32538 |
return false; |
| 32539 |
} |
| 32540 |
|
| 32541 |
return true; |
| 32542 |
|
| 32543 |
case ARM_POST_DEC: |
| 32544 |
case ARM_PRE_INC: |
| 32545 |
/* Without LDRD and mode size greater than |
| 32546 |
word size, there is no point in auto-incrementing |
| 32547 |
because ldm and stm will not have these forms. */ |
| 32548 |
if (!TARGET_LDRD && GET_MODE_SIZE (mode) > 4) |
| 32549 |
return false; |
| 32550 |
|
| 32551 |
/* Vector and floating point modes do not support |
| 32552 |
these auto increment forms. */ |
| 32553 |
if (FLOAT_MODE_P (mode) || VECTOR_MODE_P (mode)) |
| 32554 |
return false; |
| 32555 |
|
| 32556 |
return true; |
| 32557 |
|
| 32558 |
default: |
| 32559 |
return false; |
| 32560 |
|
| 32561 |
} |
| 32562 |
|
| 32563 |
return false; |
| 32564 |
} |
| 32565 |
|
| 32566 |
/* The default expansion of general 64-bit shifts in core-regs is suboptimal, |
| 32567 |
on ARM, since we know that shifts by negative amounts are no-ops. |
| 32568 |
Additionally, the default expansion code is not available or suitable |
| 32569 |
for post-reload insn splits (this can occur when the register allocator |
| 32570 |
chooses not to do a shift in NEON). |
| 32571 |
|
| 32572 |
This function is used in both initial expand and post-reload splits, and |
| 32573 |
handles all kinds of 64-bit shifts. |
| 32574 |
|
| 32575 |
Input requirements: |
| 32576 |
- It is safe for the input and output to be the same register, but |
| 32577 |
early-clobber rules apply for the shift amount and scratch registers. |
| 32578 |
- Shift by register requires both scratch registers. In all other cases |
| 32579 |
the scratch registers may be NULL. |
| 32580 |
- Ashiftrt by a register also clobbers the CC register. */ |
| 32581 |
void |
| 32582 |
arm_emit_coreregs_64bit_shift (enum rtx_code code, rtx out, rtx in, |
| 32583 |
rtx amount, rtx scratch1, rtx scratch2) |
| 32584 |
{ |
| 32585 |
rtx out_high = gen_highpart (SImode, out); |
| 32586 |
rtx out_low = gen_lowpart (SImode, out); |
| 32587 |
rtx in_high = gen_highpart (SImode, in); |
| 32588 |
rtx in_low = gen_lowpart (SImode, in); |
| 32589 |
|
| 32590 |
/* Terminology: |
| 32591 |
in = the register pair containing the input value. |
| 32592 |
out = the destination register pair. |
| 32593 |
up = the high- or low-part of each pair. |
| 32594 |
down = the opposite part to "up". |
| 32595 |
In a shift, we can consider bits to shift from "up"-stream to |
| 32596 |
"down"-stream, so in a left-shift "up" is the low-part and "down" |
| 32597 |
is the high-part of each register pair. */ |
| 32598 |
|
| 32599 |
rtx out_up = code == ASHIFT ? out_low : out_high; |
| 32600 |
rtx out_down = code == ASHIFT ? out_high : out_low; |
| 32601 |
rtx in_up = code == ASHIFT ? in_low : in_high; |
| 32602 |
rtx in_down = code == ASHIFT ? in_high : in_low; |
| 32603 |
|
| 32604 |
gcc_assert (code == ASHIFT || code == ASHIFTRT || code == LSHIFTRT); |
| 32605 |
gcc_assert (out |
| 32606 |
&& (REG_P (out) || SUBREG_P (out)) |
| 32607 |
&& GET_MODE (out) == DImode); |
| 32608 |
gcc_assert (in |
| 32609 |
&& (REG_P (in) || SUBREG_P (in)) |
| 32610 |
&& GET_MODE (in) == DImode); |
| 32611 |
gcc_assert (amount |
| 32612 |
&& (((REG_P (amount) || SUBREG_P (amount)) |
| 32613 |
&& GET_MODE (amount) == SImode) |
| 32614 |
|| CONST_INT_P (amount))); |
| 32615 |
gcc_assert (scratch1 == NULL |
| 32616 |
|| (GET_CODE (scratch1) == SCRATCH) |
| 32617 |
|| (GET_MODE (scratch1) == SImode |
| 32618 |
&& REG_P (scratch1))); |
| 32619 |
gcc_assert (scratch2 == NULL |
| 32620 |
|| (GET_CODE (scratch2) == SCRATCH) |
| 32621 |
|| (GET_MODE (scratch2) == SImode |
| 32622 |
&& REG_P (scratch2))); |
| 32623 |
gcc_assert (!REG_P (out) || !REG_P (amount) |
| 32624 |
|| !HARD_REGISTER_P (out) |
| 32625 |
|| (REGNO (out) != REGNO (amount) |
| 32626 |
&& REGNO (out) + 1 != REGNO (amount))); |
| 32627 |
|
| 32628 |
/* Macros to make following code more readable. */ |
| 32629 |
#define SUB_32(DEST,SRC) \ |
| 32630 |
gen_addsi3 ((DEST), (SRC), GEN_INT (-32)) |
| 32631 |
#define RSB_32(DEST,SRC) \ |
| 32632 |
gen_subsi3 ((DEST), GEN_INT (32), (SRC)) |
| 32633 |
#define SUB_S_32(DEST,SRC) \ |
| 32634 |
gen_addsi3_compare0 ((DEST), (SRC), \ |
| 32635 |
GEN_INT (-32)) |
| 32636 |
#define SET(DEST,SRC) \ |
| 32637 |
gen_rtx_SET ((DEST), (SRC)) |
| 32638 |
#define SHIFT(CODE,SRC,AMOUNT) \ |
| 32639 |
gen_rtx_fmt_ee ((CODE), SImode, (SRC), (AMOUNT)) |
| 32640 |
#define LSHIFT(CODE,SRC,AMOUNT) \ |
| 32641 |
gen_rtx_fmt_ee ((CODE) == ASHIFT ? ASHIFT : LSHIFTRT, \ |
| 32642 |
SImode, (SRC), (AMOUNT)) |
| 32643 |
#define REV_LSHIFT(CODE,SRC,AMOUNT) \ |
| 32644 |
gen_rtx_fmt_ee ((CODE) == ASHIFT ? LSHIFTRT : ASHIFT, \ |
| 32645 |
SImode, (SRC), (AMOUNT)) |
| 32646 |
#define ORR(A,B) \ |
| 32647 |
gen_rtx_IOR (SImode, (A), (B)) |
| 32648 |
#define BRANCH(COND,LABEL) \ |
| 32649 |
gen_arm_cond_branch ((LABEL), \ |
| 32650 |
gen_rtx_ ## COND (CCmode, cc_reg, \ |
| 32651 |
const0_rtx), \ |
| 32652 |
cc_reg) |
| 32653 |
|
| 32654 |
/* Shifts by register and shifts by constant are handled separately. */ |
| 32655 |
if (CONST_INT_P (amount)) |
| 32656 |
{ |
| 32657 |
/* We have a shift-by-constant. */ |
| 32658 |
|
| 32659 |
/* First, handle out-of-range shift amounts. |
| 32660 |
In both cases we try to match the result an ARM instruction in a |
| 32661 |
shift-by-register would give. This helps reduce execution |
| 32662 |
differences between optimization levels, but it won't stop other |
| 32663 |
parts of the compiler doing different things. This is "undefined |
| 32664 |
behavior, in any case. */ |
| 32665 |
if (INTVAL (amount) <= 0) |
| 32666 |
emit_insn (gen_movdi (out, in)); |
| 32667 |
else if (INTVAL (amount) >= 64) |
| 32668 |
{ |
| 32669 |
if (code == ASHIFTRT) |
| 32670 |
{ |
| 32671 |
rtx const31_rtx = GEN_INT (31); |
| 32672 |
emit_insn (SET (out_down, SHIFT (code, in_up, const31_rtx))); |
| 32673 |
emit_insn (SET (out_up, SHIFT (code, in_up, const31_rtx))); |
| 32674 |
} |
| 32675 |
else |
| 32676 |
emit_insn (gen_movdi (out, const0_rtx)); |
| 32677 |
} |
| 32678 |
|
| 32679 |
/* Now handle valid shifts. */ |
| 32680 |
else if (INTVAL (amount) < 32) |
| 32681 |
{ |
| 32682 |
/* Shifts by a constant less than 32. */ |
| 32683 |
rtx reverse_amount = GEN_INT (32 - INTVAL (amount)); |
| 32684 |
|
| 32685 |
/* Clearing the out register in DImode first avoids lots |
| 32686 |
of spilling and results in less stack usage. |
| 32687 |
Later this redundant insn is completely removed. |
| 32688 |
Do that only if "in" and "out" are different registers. */ |
| 32689 |
if (REG_P (out) && REG_P (in) && REGNO (out) != REGNO (in)) |
| 32690 |
emit_insn (SET (out, const0_rtx)); |
| 32691 |
emit_insn (SET (out_down, LSHIFT (code, in_down, amount))); |
| 32692 |
emit_insn (SET (out_down, |
| 32693 |
ORR (REV_LSHIFT (code, in_up, reverse_amount), |
| 32694 |
out_down))); |
| 32695 |
emit_insn (SET (out_up, SHIFT (code, in_up, amount))); |
| 32696 |
} |
| 32697 |
else |
| 32698 |
{ |
| 32699 |
/* Shifts by a constant greater than 31. */ |
| 32700 |
rtx adj_amount = GEN_INT (INTVAL (amount) - 32); |
| 32701 |
|
| 32702 |
if (REG_P (out) && REG_P (in) && REGNO (out) != REGNO (in)) |
| 32703 |
emit_insn (SET (out, const0_rtx)); |
| 32704 |
emit_insn (SET (out_down, SHIFT (code, in_up, adj_amount))); |
| 32705 |
if (code == ASHIFTRT) |
| 32706 |
emit_insn (gen_ashrsi3 (out_up, in_up, |
| 32707 |
GEN_INT (31))); |
| 32708 |
else |
| 32709 |
emit_insn (SET (out_up, const0_rtx)); |
| 32710 |
} |
| 32711 |
} |
| 32712 |
else |
| 32713 |
{ |
| 32714 |
/* We have a shift-by-register. */ |
| 32715 |
rtx cc_reg = gen_rtx_REG (CC_NZmode, CC_REGNUM); |
| 32716 |
|
| 32717 |
/* This alternative requires the scratch registers. */ |
| 32718 |
gcc_assert (scratch1 && REG_P (scratch1)); |
| 32719 |
gcc_assert (scratch2 && REG_P (scratch2)); |
| 32720 |
|
| 32721 |
/* We will need the values "amount-32" and "32-amount" later. |
| 32722 |
Swapping them around now allows the later code to be more general. */ |
| 32723 |
switch (code) |
| 32724 |
{ |
| 32725 |
case ASHIFT: |
| 32726 |
emit_insn (SUB_32 (scratch1, amount)); |
| 32727 |
emit_insn (RSB_32 (scratch2, amount)); |
| 32728 |
break; |
| 32729 |
case ASHIFTRT: |
| 32730 |
emit_insn (RSB_32 (scratch1, amount)); |
| 32731 |
/* Also set CC = amount > 32. */ |
| 32732 |
emit_insn (SUB_S_32 (scratch2, amount)); |
| 32733 |
break; |
| 32734 |
case LSHIFTRT: |
| 32735 |
emit_insn (RSB_32 (scratch1, amount)); |
| 32736 |
emit_insn (SUB_32 (scratch2, amount)); |
| 32737 |
break; |
| 32738 |
default: |
| 32739 |
gcc_unreachable (); |
| 32740 |
} |
| 32741 |
|
| 32742 |
/* Emit code like this: |
| 32743 |
|
| 32744 |
arithmetic-left: |
| 32745 |
out_down = in_down << amount; |
| 32746 |
out_down = (in_up << (amount - 32)) | out_down; |
| 32747 |
out_down = ((unsigned)in_up >> (32 - amount)) | out_down; |
| 32748 |
out_up = in_up << amount; |
| 32749 |
|
| 32750 |
arithmetic-right: |
| 32751 |
out_down = in_down >> amount; |
| 32752 |
out_down = (in_up << (32 - amount)) | out_down; |
| 32753 |
if (amount < 32) |
| 32754 |
out_down = ((signed)in_up >> (amount - 32)) | out_down; |
| 32755 |
out_up = in_up << amount; |
| 32756 |
|
| 32757 |
logical-right: |
| 32758 |
out_down = in_down >> amount; |
| 32759 |
out_down = (in_up << (32 - amount)) | out_down; |
| 32760 |
if (amount < 32) |
| 32761 |
out_down = ((unsigned)in_up >> (amount - 32)) | out_down; |
| 32762 |
out_up = in_up << amount; |
| 32763 |
|
| 32764 |
The ARM and Thumb2 variants are the same but implemented slightly |
| 32765 |
differently. If this were only called during expand we could just |
| 32766 |
use the Thumb2 case and let combine do the right thing, but this |
| 32767 |
can also be called from post-reload splitters. */ |
| 32768 |
|
| 32769 |
emit_insn (SET (out_down, LSHIFT (code, in_down, amount))); |
| 32770 |
|
| 32771 |
if (!TARGET_THUMB2) |
| 32772 |
{ |
| 32773 |
/* Emit code for ARM mode. */ |
| 32774 |
emit_insn (SET (out_down, |
| 32775 |
ORR (SHIFT (ASHIFT, in_up, scratch1), out_down))); |
| 32776 |
if (code == ASHIFTRT) |
| 32777 |
{ |
| 32778 |
rtx_code_label *done_label = gen_label_rtx (); |
| 32779 |
emit_jump_insn (BRANCH (LT, done_label)); |
| 32780 |
emit_insn (SET (out_down, ORR (SHIFT (ASHIFTRT, in_up, scratch2), |
| 32781 |
out_down))); |
| 32782 |
emit_label (done_label); |
| 32783 |
} |
| 32784 |
else |
| 32785 |
emit_insn (SET (out_down, ORR (SHIFT (LSHIFTRT, in_up, scratch2), |
| 32786 |
out_down))); |
| 32787 |
} |
| 32788 |
else |
| 32789 |
{ |
| 32790 |
/* Emit code for Thumb2 mode. |
| 32791 |
Thumb2 can't do shift and or in one insn. */ |
| 32792 |
emit_insn (SET (scratch1, SHIFT (ASHIFT, in_up, scratch1))); |
| 32793 |
emit_insn (gen_iorsi3 (out_down, out_down, scratch1)); |
| 32794 |
|
| 32795 |
if (code == ASHIFTRT) |
| 32796 |
{ |
| 32797 |
rtx_code_label *done_label = gen_label_rtx (); |
| 32798 |
emit_jump_insn (BRANCH (LT, done_label)); |
| 32799 |
emit_insn (SET (scratch2, SHIFT (ASHIFTRT, in_up, scratch2))); |
| 32800 |
emit_insn (SET (out_down, ORR (out_down, scratch2))); |
| 32801 |
emit_label (done_label); |
| 32802 |
} |
| 32803 |
else |
| 32804 |
{ |
| 32805 |
emit_insn (SET (scratch2, SHIFT (LSHIFTRT, in_up, scratch2))); |
| 32806 |
emit_insn (gen_iorsi3 (out_down, out_down, scratch2)); |
| 32807 |
} |
| 32808 |
} |
| 32809 |
|
| 32810 |
emit_insn (SET (out_up, SHIFT (code, in_up, amount))); |
| 32811 |
} |
| 32812 |
|
| 32813 |
#undef SUB_32 |
| 32814 |
#undef RSB_32 |
| 32815 |
#undef SUB_S_32 |
| 32816 |
#undef SET |
| 32817 |
#undef SHIFT |
| 32818 |
#undef LSHIFT |
| 32819 |
#undef REV_LSHIFT |
| 32820 |
#undef ORR |
| 32821 |
#undef BRANCH |
| 32822 |
} |
| 32823 |
|
| 32824 |
/* Returns true if the pattern is a valid symbolic address, which is either a |
| 32825 |
symbol_ref or (symbol_ref + addend). |
| 32826 |
|
| 32827 |
According to the ARM ELF ABI, the initial addend of REL-type relocations |
| 32828 |
processing MOVW and MOVT instructions is formed by interpreting the 16-bit |
| 32829 |
literal field of the instruction as a 16-bit signed value in the range |
| 32830 |
-32768 <= A < 32768. |
| 32831 |
|
| 32832 |
In Thumb-1 mode, we use upper/lower relocations which have an 8-bit |
| 32833 |
unsigned range of 0 <= A < 256 as described in the AAELF32 |
| 32834 |
relocation handling documentation: REL-type relocations are encoded |
| 32835 |
as unsigned in this case. */ |
| 32836 |
|
| 32837 |
bool |
| 32838 |
arm_valid_symbolic_address_p (rtx addr) |
| 32839 |
{ |
| 32840 |
rtx xop0, xop1 = NULL_RTX; |
| 32841 |
rtx tmp = addr; |
| 32842 |
|
| 32843 |
if (target_word_relocations) |
| 32844 |
return false; |
| 32845 |
|
| 32846 |
if (SYMBOL_REF_P (tmp) || LABEL_REF_P (tmp)) |
| 32847 |
return true; |
| 32848 |
|
| 32849 |
/* (const (plus: symbol_ref const_int)) */ |
| 32850 |
if (GET_CODE (addr) == CONST) |
| 32851 |
tmp = XEXP (addr, 0); |
| 32852 |
|
| 32853 |
if (GET_CODE (tmp) == PLUS) |
| 32854 |
{ |
| 32855 |
xop0 = XEXP (tmp, 0); |
| 32856 |
xop1 = XEXP (tmp, 1); |
| 32857 |
|
| 32858 |
if (GET_CODE (xop0) == SYMBOL_REF && CONST_INT_P (xop1)) |
| 32859 |
{ |
| 32860 |
if (TARGET_THUMB1 && !TARGET_HAVE_MOVT) |
| 32861 |
return IN_RANGE (INTVAL (xop1), 0, 0xff); |
| 32862 |
else |
| 32863 |
return IN_RANGE (INTVAL (xop1), -0x8000, 0x7fff); |
| 32864 |
} |
| 32865 |
} |
| 32866 |
|
| 32867 |
return false; |
| 32868 |
} |
| 32869 |
|
| 32870 |
/* Returns true if a valid comparison operation and makes |
| 32871 |
the operands in a form that is valid. */ |
| 32872 |
bool |
| 32873 |
arm_validize_comparison (rtx *comparison, rtx * op1, rtx * op2) |
| 32874 |
{ |
| 32875 |
enum rtx_code code = GET_CODE (*comparison); |
| 32876 |
int code_int; |
| 32877 |
machine_mode mode = (GET_MODE (*op1) == VOIDmode) |
| 32878 |
? GET_MODE (*op2) : GET_MODE (*op1); |
| 32879 |
|
| 32880 |
gcc_assert (GET_MODE (*op1) != VOIDmode || GET_MODE (*op2) != VOIDmode); |
| 32881 |
|
| 32882 |
if (code == UNEQ || code == LTGT) |
| 32883 |
return false; |
| 32884 |
|
| 32885 |
code_int = (int)code; |
| 32886 |
arm_canonicalize_comparison (&code_int, op1, op2, 0); |
| 32887 |
PUT_CODE (*comparison, (enum rtx_code)code_int); |
| 32888 |
|
| 32889 |
switch (mode) |
| 32890 |
{ |
| 32891 |
case E_SImode: |
| 32892 |
if (!arm_add_operand (*op1, mode)) |
| 32893 |
*op1 = force_reg (mode, *op1); |
| 32894 |
if (!arm_add_operand (*op2, mode)) |
| 32895 |
*op2 = force_reg (mode, *op2); |
| 32896 |
return true; |
| 32897 |
|
| 32898 |
case E_DImode: |
| 32899 |
/* gen_compare_reg() will sort out any invalid operands. */ |
| 32900 |
return true; |
| 32901 |
|
| 32902 |
case E_HFmode: |
| 32903 |
if (!TARGET_VFP_FP16INST) |
| 32904 |
break; |
| 32905 |
if (!arm_vsel_comparison_operator (*comparison, mode)) |
| 32906 |
return false; |
| 32907 |
|
| 32908 |
/* FP16 comparisons are done in SF mode. */ |
| 32909 |
mode = SFmode; |
| 32910 |
*op1 = convert_to_mode (mode, *op1, 1); |
| 32911 |
*op2 = convert_to_mode (mode, *op2, 1); |
| 32912 |
/* Fall through. */ |
| 32913 |
case E_SFmode: |
| 32914 |
case E_DFmode: |
| 32915 |
if (!vfp_compare_operand (*op1, mode)) |
| 32916 |
*op1 = force_reg (mode, *op1); |
| 32917 |
if (!vfp_compare_operand (*op2, mode)) |
| 32918 |
*op2 = force_reg (mode, *op2); |
| 32919 |
return true; |
| 32920 |
default: |
| 32921 |
break; |
| 32922 |
} |
| 32923 |
|
| 32924 |
return false; |
| 32925 |
|
| 32926 |
} |
| 32927 |
|
| 32928 |
/* Maximum number of instructions to set block of memory. */ |
| 32929 |
static int |
| 32930 |
arm_block_set_max_insns (void) |
| 32931 |
{ |
| 32932 |
if (optimize_function_for_size_p (cfun)) |
| 32933 |
return 4; |
| 32934 |
else |
| 32935 |
return current_tune->max_insns_inline_memset; |
| 32936 |
} |
| 32937 |
|
| 32938 |
/* Return TRUE if it's profitable to set block of memory for |
| 32939 |
non-vectorized case. VAL is the value to set the memory |
| 32940 |
with. LENGTH is the number of bytes to set. ALIGN is the |
| 32941 |
alignment of the destination memory in bytes. UNALIGNED_P |
| 32942 |
is TRUE if we can only set the memory with instructions |
| 32943 |
meeting alignment requirements. USE_STRD_P is TRUE if we |
| 32944 |
can use strd to set the memory. */ |
| 32945 |
static bool |
| 32946 |
arm_block_set_non_vect_profit_p (rtx val, |
| 32947 |
unsigned HOST_WIDE_INT length, |
| 32948 |
unsigned HOST_WIDE_INT align, |
| 32949 |
bool unaligned_p, bool use_strd_p) |
| 32950 |
{ |
| 32951 |
int num = 0; |
| 32952 |
/* For leftovers in bytes of 0-7, we can set the memory block using |
| 32953 |
strb/strh/str with minimum instruction number. */ |
| 32954 |
const int leftover[8] = {0, 1, 1, 2, 1, 2, 2, 3}; |
| 32955 |
|
| 32956 |
if (unaligned_p) |
| 32957 |
{ |
| 32958 |
num = arm_const_inline_cost (SET, val); |
| 32959 |
num += length / align + length % align; |
| 32960 |
} |
| 32961 |
else if (use_strd_p) |
| 32962 |
{ |
| 32963 |
num = arm_const_double_inline_cost (val); |
| 32964 |
num += (length >> 3) + leftover[length & 7]; |
| 32965 |
} |
| 32966 |
else |
| 32967 |
{ |
| 32968 |
num = arm_const_inline_cost (SET, val); |
| 32969 |
num += (length >> 2) + leftover[length & 3]; |
| 32970 |
} |
| 32971 |
|
| 32972 |
/* We may be able to combine last pair STRH/STRB into a single STR |
| 32973 |
by shifting one byte back. */ |
| 32974 |
if (unaligned_access && length > 3 && (length & 3) == 3) |
| 32975 |
num--; |
| 32976 |
|
| 32977 |
return (num <= arm_block_set_max_insns ()); |
| 32978 |
} |
| 32979 |
|
| 32980 |
/* Return TRUE if it's profitable to set block of memory for |
| 32981 |
vectorized case. LENGTH is the number of bytes to set. |
| 32982 |
ALIGN is the alignment of destination memory in bytes. |
| 32983 |
MODE is the vector mode used to set the memory. */ |
| 32984 |
static bool |
| 32985 |
arm_block_set_vect_profit_p (unsigned HOST_WIDE_INT length, |
| 32986 |
unsigned HOST_WIDE_INT align, |
| 32987 |
machine_mode mode) |
| 32988 |
{ |
| 32989 |
int num; |
| 32990 |
bool unaligned_p = ((align & 3) != 0); |
| 32991 |
unsigned int nelt = GET_MODE_NUNITS (mode); |
| 32992 |
|
| 32993 |
/* Instruction loading constant value. */ |
| 32994 |
num = 1; |
| 32995 |
/* Instructions storing the memory. */ |
| 32996 |
num += (length + nelt - 1) / nelt; |
| 32997 |
/* Instructions adjusting the address expression. Only need to |
| 32998 |
adjust address expression if it's 4 bytes aligned and bytes |
| 32999 |
leftover can only be stored by mis-aligned store instruction. */ |
| 33000 |
if (!unaligned_p && (length & 3) != 0) |
| 33001 |
num++; |
| 33002 |
|
| 33003 |
/* Store the first 16 bytes using vst1:v16qi for the aligned case. */ |
| 33004 |
if (!unaligned_p && mode == V16QImode) |
| 33005 |
num--; |
| 33006 |
|
| 33007 |
return (num <= arm_block_set_max_insns ()); |
| 33008 |
} |
| 33009 |
|
| 33010 |
/* Set a block of memory using vectorization instructions for the |
| 33011 |
unaligned case. We fill the first LENGTH bytes of the memory |
| 33012 |
area starting from DSTBASE with byte constant VALUE. ALIGN is |
| 33013 |
the alignment requirement of memory. Return TRUE if succeeded. */ |
| 33014 |
static bool |
| 33015 |
arm_block_set_unaligned_vect (rtx dstbase, |
| 33016 |
unsigned HOST_WIDE_INT length, |
| 33017 |
unsigned HOST_WIDE_INT value, |
| 33018 |
unsigned HOST_WIDE_INT align) |
| 33019 |
{ |
| 33020 |
unsigned int i, nelt_v16, nelt_v8, nelt_mode; |
| 33021 |
rtx dst, mem; |
| 33022 |
rtx val_vec, reg; |
| 33023 |
rtx (*gen_func) (rtx, rtx); |
| 33024 |
machine_mode mode; |
| 33025 |
unsigned HOST_WIDE_INT v = value; |
| 33026 |
unsigned int offset = 0; |
| 33027 |
gcc_assert ((align & 0x3) != 0); |
| 33028 |
nelt_v8 = GET_MODE_NUNITS (V8QImode); |
| 33029 |
nelt_v16 = GET_MODE_NUNITS (V16QImode); |
| 33030 |
if (length >= nelt_v16) |
| 33031 |
{ |
| 33032 |
mode = V16QImode; |
| 33033 |
gen_func = gen_movmisalignv16qi; |
| 33034 |
} |
| 33035 |
else |
| 33036 |
{ |
| 33037 |
mode = V8QImode; |
| 33038 |
gen_func = gen_movmisalignv8qi; |
| 33039 |
} |
| 33040 |
nelt_mode = GET_MODE_NUNITS (mode); |
| 33041 |
gcc_assert (length >= nelt_mode); |
| 33042 |
/* Skip if it isn't profitable. */ |
| 33043 |
if (!arm_block_set_vect_profit_p (length, align, mode)) |
| 33044 |
return false; |
| 33045 |
|
| 33046 |
dst = copy_addr_to_reg (XEXP (dstbase, 0)); |
| 33047 |
mem = adjust_automodify_address (dstbase, mode, dst, offset); |
| 33048 |
|
| 33049 |
v = sext_hwi (v, BITS_PER_WORD); |
| 33050 |
|
| 33051 |
reg = gen_reg_rtx (mode); |
| 33052 |
val_vec = gen_const_vec_duplicate (mode, GEN_INT (v)); |
| 33053 |
/* Emit instruction loading the constant value. */ |
| 33054 |
emit_move_insn (reg, val_vec); |
| 33055 |
|
| 33056 |
/* Handle nelt_mode bytes in a vector. */ |
| 33057 |
for (i = 0; (i + nelt_mode <= length); i += nelt_mode) |
| 33058 |
{ |
| 33059 |
emit_insn ((*gen_func) (mem, reg)); |
| 33060 |
if (i + 2 * nelt_mode <= length) |
| 33061 |
{ |
| 33062 |
emit_insn (gen_add2_insn (dst, GEN_INT (nelt_mode))); |
| 33063 |
offset += nelt_mode; |
| 33064 |
mem = adjust_automodify_address (dstbase, mode, dst, offset); |
| 33065 |
} |
| 33066 |
} |
| 33067 |
|
| 33068 |
/* If there are not less than nelt_v8 bytes leftover, we must be in |
| 33069 |
V16QI mode. */ |
| 33070 |
gcc_assert ((i + nelt_v8) > length || mode == V16QImode); |
| 33071 |
|
| 33072 |
/* Handle (8, 16) bytes leftover. */ |
| 33073 |
if (i + nelt_v8 < length) |
| 33074 |
{ |
| 33075 |
emit_insn (gen_add2_insn (dst, GEN_INT (length - i))); |
| 33076 |
offset += length - i; |
| 33077 |
mem = adjust_automodify_address (dstbase, mode, dst, offset); |
| 33078 |
|
| 33079 |
/* We are shifting bytes back, set the alignment accordingly. */ |
| 33080 |
if ((length & 1) != 0 && align >= 2) |
| 33081 |
set_mem_align (mem, BITS_PER_UNIT); |
| 33082 |
|
| 33083 |
emit_insn (gen_movmisalignv16qi (mem, reg)); |
| 33084 |
} |
| 33085 |
/* Handle (0, 8] bytes leftover. */ |
| 33086 |
else if (i < length && i + nelt_v8 >= length) |
| 33087 |
{ |
| 33088 |
if (mode == V16QImode) |
| 33089 |
reg = gen_lowpart (V8QImode, reg); |
| 33090 |
|
| 33091 |
emit_insn (gen_add2_insn (dst, GEN_INT ((length - i) |
| 33092 |
+ (nelt_mode - nelt_v8)))); |
| 33093 |
offset += (length - i) + (nelt_mode - nelt_v8); |
| 33094 |
mem = adjust_automodify_address (dstbase, V8QImode, dst, offset); |
| 33095 |
|
| 33096 |
/* We are shifting bytes back, set the alignment accordingly. */ |
| 33097 |
if ((length & 1) != 0 && align >= 2) |
| 33098 |
set_mem_align (mem, BITS_PER_UNIT); |
| 33099 |
|
| 33100 |
emit_insn (gen_movmisalignv8qi (mem, reg)); |
| 33101 |
} |
| 33102 |
|
| 33103 |
return true; |
| 33104 |
} |
| 33105 |
|
| 33106 |
/* Set a block of memory using vectorization instructions for the |
| 33107 |
aligned case. We fill the first LENGTH bytes of the memory area |
| 33108 |
starting from DSTBASE with byte constant VALUE. ALIGN is the |
| 33109 |
alignment requirement of memory. Return TRUE if succeeded. */ |
| 33110 |
static bool |
| 33111 |
arm_block_set_aligned_vect (rtx dstbase, |
| 33112 |
unsigned HOST_WIDE_INT length, |
| 33113 |
unsigned HOST_WIDE_INT value, |
| 33114 |
unsigned HOST_WIDE_INT align) |
| 33115 |
{ |
| 33116 |
unsigned int i, nelt_v8, nelt_v16, nelt_mode; |
| 33117 |
rtx dst, addr, mem; |
| 33118 |
rtx val_vec, reg; |
| 33119 |
machine_mode mode; |
| 33120 |
unsigned int offset = 0; |
| 33121 |
|
| 33122 |
gcc_assert ((align & 0x3) == 0); |
| 33123 |
nelt_v8 = GET_MODE_NUNITS (V8QImode); |
| 33124 |
nelt_v16 = GET_MODE_NUNITS (V16QImode); |
| 33125 |
if (length >= nelt_v16 && unaligned_access && !BYTES_BIG_ENDIAN) |
| 33126 |
mode = V16QImode; |
| 33127 |
else |
| 33128 |
mode = V8QImode; |
| 33129 |
|
| 33130 |
nelt_mode = GET_MODE_NUNITS (mode); |
| 33131 |
gcc_assert (length >= nelt_mode); |
| 33132 |
/* Skip if it isn't profitable. */ |
| 33133 |
if (!arm_block_set_vect_profit_p (length, align, mode)) |
| 33134 |
return false; |
| 33135 |
|
| 33136 |
dst = copy_addr_to_reg (XEXP (dstbase, 0)); |
| 33137 |
|
| 33138 |
reg = gen_reg_rtx (mode); |
| 33139 |
val_vec = gen_const_vec_duplicate (mode, gen_int_mode (value, QImode)); |
| 33140 |
/* Emit instruction loading the constant value. */ |
| 33141 |
emit_move_insn (reg, val_vec); |
| 33142 |
|
| 33143 |
i = 0; |
| 33144 |
/* Handle first 16 bytes specially using vst1:v16qi instruction. */ |
| 33145 |
if (mode == V16QImode) |
| 33146 |
{ |
| 33147 |
mem = adjust_automodify_address (dstbase, mode, dst, offset); |
| 33148 |
emit_insn (gen_movmisalignv16qi (mem, reg)); |
| 33149 |
i += nelt_mode; |
| 33150 |
/* Handle (8, 16) bytes leftover using vst1:v16qi again. */ |
| 33151 |
if (i + nelt_v8 < length && i + nelt_v16 > length) |
| 33152 |
{ |
| 33153 |
emit_insn (gen_add2_insn (dst, GEN_INT (length - nelt_mode))); |
| 33154 |
offset += length - nelt_mode; |
| 33155 |
mem = adjust_automodify_address (dstbase, mode, dst, offset); |
| 33156 |
/* We are shifting bytes back, set the alignment accordingly. */ |
| 33157 |
if ((length & 0x3) == 0) |
| 33158 |
set_mem_align (mem, BITS_PER_UNIT * 4); |
| 33159 |
else if ((length & 0x1) == 0) |
| 33160 |
set_mem_align (mem, BITS_PER_UNIT * 2); |
| 33161 |
else |
| 33162 |
set_mem_align (mem, BITS_PER_UNIT); |
| 33163 |
|
| 33164 |
emit_insn (gen_movmisalignv16qi (mem, reg)); |
| 33165 |
return true; |
| 33166 |
} |
| 33167 |
/* Fall through for bytes leftover. */ |
| 33168 |
mode = V8QImode; |
| 33169 |
nelt_mode = GET_MODE_NUNITS (mode); |
| 33170 |
reg = gen_lowpart (V8QImode, reg); |
| 33171 |
} |
| 33172 |
|
| 33173 |
/* Handle 8 bytes in a vector. */ |
| 33174 |
for (; (i + nelt_mode <= length); i += nelt_mode) |
| 33175 |
{ |
| 33176 |
addr = plus_constant (Pmode, dst, i); |
| 33177 |
mem = adjust_automodify_address (dstbase, mode, addr, offset + i); |
| 33178 |
if (MEM_ALIGN (mem) >= 2 * BITS_PER_WORD) |
| 33179 |
emit_move_insn (mem, reg); |
| 33180 |
else |
| 33181 |
emit_insn (gen_unaligned_storev8qi (mem, reg)); |
| 33182 |
} |
| 33183 |
|
| 33184 |
/* Handle single word leftover by shifting 4 bytes back. We can |
| 33185 |
use aligned access for this case. */ |
| 33186 |
if (i + UNITS_PER_WORD == length) |
| 33187 |
{ |
| 33188 |
addr = plus_constant (Pmode, dst, i - UNITS_PER_WORD); |
| 33189 |
offset += i - UNITS_PER_WORD; |
| 33190 |
mem = adjust_automodify_address (dstbase, mode, addr, offset); |
| 33191 |
/* We are shifting 4 bytes back, set the alignment accordingly. */ |
| 33192 |
if (align > UNITS_PER_WORD) |
| 33193 |
set_mem_align (mem, BITS_PER_UNIT * UNITS_PER_WORD); |
| 33194 |
|
| 33195 |
emit_insn (gen_unaligned_storev8qi (mem, reg)); |
| 33196 |
} |
| 33197 |
/* Handle (0, 4), (4, 8) bytes leftover by shifting bytes back. |
| 33198 |
We have to use unaligned access for this case. */ |
| 33199 |
else if (i < length) |
| 33200 |
{ |
| 33201 |
emit_insn (gen_add2_insn (dst, GEN_INT (length - nelt_mode))); |
| 33202 |
offset += length - nelt_mode; |
| 33203 |
mem = adjust_automodify_address (dstbase, mode, dst, offset); |
| 33204 |
/* We are shifting bytes back, set the alignment accordingly. */ |
| 33205 |
if ((length & 1) == 0) |
| 33206 |
set_mem_align (mem, BITS_PER_UNIT * 2); |
| 33207 |
else |
| 33208 |
set_mem_align (mem, BITS_PER_UNIT); |
| 33209 |
|
| 33210 |
emit_insn (gen_movmisalignv8qi (mem, reg)); |
| 33211 |
} |
| 33212 |
|
| 33213 |
return true; |
| 33214 |
} |
| 33215 |
|
| 33216 |
/* Set a block of memory using plain strh/strb instructions, only |
| 33217 |
using instructions allowed by ALIGN on processor. We fill the |
| 33218 |
first LENGTH bytes of the memory area starting from DSTBASE |
| 33219 |
with byte constant VALUE. ALIGN is the alignment requirement |
| 33220 |
of memory. */ |
| 33221 |
static bool |
| 33222 |
arm_block_set_unaligned_non_vect (rtx dstbase, |
| 33223 |
unsigned HOST_WIDE_INT length, |
| 33224 |
unsigned HOST_WIDE_INT value, |
| 33225 |
unsigned HOST_WIDE_INT align) |
| 33226 |
{ |
| 33227 |
unsigned int i; |
| 33228 |
rtx dst, addr, mem; |
| 33229 |
rtx val_exp, val_reg, reg; |
| 33230 |
machine_mode mode; |
| 33231 |
HOST_WIDE_INT v = value; |
| 33232 |
|
| 33233 |
gcc_assert (align == 1 || align == 2); |
| 33234 |
|
| 33235 |
if (align == 2) |
| 33236 |
v |= (value << BITS_PER_UNIT); |
| 33237 |
|
| 33238 |
v = sext_hwi (v, BITS_PER_WORD); |
| 33239 |
val_exp = GEN_INT (v); |
| 33240 |
/* Skip if it isn't profitable. */ |
| 33241 |
if (!arm_block_set_non_vect_profit_p (val_exp, length, |
| 33242 |
align, true, false)) |
| 33243 |
return false; |
| 33244 |
|
| 33245 |
dst = copy_addr_to_reg (XEXP (dstbase, 0)); |
| 33246 |
mode = (align == 2 ? HImode : QImode); |
| 33247 |
val_reg = force_reg (SImode, val_exp); |
| 33248 |
reg = gen_lowpart (mode, val_reg); |
| 33249 |
|
| 33250 |
for (i = 0; (i + GET_MODE_SIZE (mode) <= length); i += GET_MODE_SIZE (mode)) |
| 33251 |
{ |
| 33252 |
addr = plus_constant (Pmode, dst, i); |
| 33253 |
mem = adjust_automodify_address (dstbase, mode, addr, i); |
| 33254 |
emit_move_insn (mem, reg); |
| 33255 |
} |
| 33256 |
|
| 33257 |
/* Handle single byte leftover. */ |
| 33258 |
if (i + 1 == length) |
| 33259 |
{ |
| 33260 |
reg = gen_lowpart (QImode, val_reg); |
| 33261 |
addr = plus_constant (Pmode, dst, i); |
| 33262 |
mem = adjust_automodify_address (dstbase, QImode, addr, i); |
| 33263 |
emit_move_insn (mem, reg); |
| 33264 |
i++; |
| 33265 |
} |
| 33266 |
|
| 33267 |
gcc_assert (i == length); |
| 33268 |
return true; |
| 33269 |
} |
| 33270 |
|
| 33271 |
/* Set a block of memory using plain strd/str/strh/strb instructions, |
| 33272 |
to permit unaligned copies on processors which support unaligned |
| 33273 |
semantics for those instructions. We fill the first LENGTH bytes |
| 33274 |
of the memory area starting from DSTBASE with byte constant VALUE. |
| 33275 |
ALIGN is the alignment requirement of memory. */ |
| 33276 |
static bool |
| 33277 |
arm_block_set_aligned_non_vect (rtx dstbase, |
| 33278 |
unsigned HOST_WIDE_INT length, |
| 33279 |
unsigned HOST_WIDE_INT value, |
| 33280 |
unsigned HOST_WIDE_INT align) |
| 33281 |
{ |
| 33282 |
unsigned int i; |
| 33283 |
rtx dst, addr, mem; |
| 33284 |
rtx val_exp, val_reg, reg; |
| 33285 |
unsigned HOST_WIDE_INT v; |
| 33286 |
bool use_strd_p; |
| 33287 |
|
| 33288 |
use_strd_p = (length >= 2 * UNITS_PER_WORD && (align & 3) == 0 |
| 33289 |
&& TARGET_LDRD && current_tune->prefer_ldrd_strd); |
| 33290 |
|
| 33291 |
v = (value | (value << 8) | (value << 16) | (value << 24)); |
| 33292 |
if (length < UNITS_PER_WORD) |
| 33293 |
v &= (0xFFFFFFFF >> (UNITS_PER_WORD - length) * BITS_PER_UNIT); |
| 33294 |
|
| 33295 |
if (use_strd_p) |
| 33296 |
v |= (v << BITS_PER_WORD); |
| 33297 |
else |
| 33298 |
v = sext_hwi (v, BITS_PER_WORD); |
| 33299 |
|
| 33300 |
val_exp = GEN_INT (v); |
| 33301 |
/* Skip if it isn't profitable. */ |
| 33302 |
if (!arm_block_set_non_vect_profit_p (val_exp, length, |
| 33303 |
align, false, use_strd_p)) |
| 33304 |
{ |
| 33305 |
if (!use_strd_p) |
| 33306 |
return false; |
| 33307 |
|
| 33308 |
/* Try without strd. */ |
| 33309 |
v = (v >> BITS_PER_WORD); |
| 33310 |
v = sext_hwi (v, BITS_PER_WORD); |
| 33311 |
val_exp = GEN_INT (v); |
| 33312 |
use_strd_p = false; |
| 33313 |
if (!arm_block_set_non_vect_profit_p (val_exp, length, |
| 33314 |
align, false, use_strd_p)) |
| 33315 |
return false; |
| 33316 |
} |
| 33317 |
|
| 33318 |
i = 0; |
| 33319 |
dst = copy_addr_to_reg (XEXP (dstbase, 0)); |
| 33320 |
/* Handle double words using strd if possible. */ |
| 33321 |
if (use_strd_p) |
| 33322 |
{ |
| 33323 |
val_reg = force_reg (DImode, val_exp); |
| 33324 |
reg = val_reg; |
| 33325 |
for (; (i + 8 <= length); i += 8) |
| 33326 |
{ |
| 33327 |
addr = plus_constant (Pmode, dst, i); |
| 33328 |
mem = adjust_automodify_address (dstbase, DImode, addr, i); |
| 33329 |
if (MEM_ALIGN (mem) >= 2 * BITS_PER_WORD) |
| 33330 |
emit_move_insn (mem, reg); |
| 33331 |
else |
| 33332 |
emit_insn (gen_unaligned_storedi (mem, reg)); |
| 33333 |
} |
| 33334 |
} |
| 33335 |
else |
| 33336 |
val_reg = force_reg (SImode, val_exp); |
| 33337 |
|
| 33338 |
/* Handle words. */ |
| 33339 |
reg = (use_strd_p ? gen_lowpart (SImode, val_reg) : val_reg); |
| 33340 |
for (; (i + 4 <= length); i += 4) |
| 33341 |
{ |
| 33342 |
addr = plus_constant (Pmode, dst, i); |
| 33343 |
mem = adjust_automodify_address (dstbase, SImode, addr, i); |
| 33344 |
if ((align & 3) == 0) |
| 33345 |
emit_move_insn (mem, reg); |
| 33346 |
else |
| 33347 |
emit_insn (gen_unaligned_storesi (mem, reg)); |
| 33348 |
} |
| 33349 |
|
| 33350 |
/* Merge last pair of STRH and STRB into a STR if possible. */ |
| 33351 |
if (unaligned_access && i > 0 && (i + 3) == length) |
| 33352 |
{ |
| 33353 |
addr = plus_constant (Pmode, dst, i - 1); |
| 33354 |
mem = adjust_automodify_address (dstbase, SImode, addr, i - 1); |
| 33355 |
/* We are shifting one byte back, set the alignment accordingly. */ |
| 33356 |
if ((align & 1) == 0) |
| 33357 |
set_mem_align (mem, BITS_PER_UNIT); |
| 33358 |
|
| 33359 |
/* Most likely this is an unaligned access, and we can't tell at |
| 33360 |
compilation time. */ |
| 33361 |
emit_insn (gen_unaligned_storesi (mem, reg)); |
| 33362 |
return true; |
| 33363 |
} |
| 33364 |
|
| 33365 |
/* Handle half word leftover. */ |
| 33366 |
if (i + 2 <= length) |
| 33367 |
{ |
| 33368 |
reg = gen_lowpart (HImode, val_reg); |
| 33369 |
addr = plus_constant (Pmode, dst, i); |
| 33370 |
mem = adjust_automodify_address (dstbase, HImode, addr, i); |
| 33371 |
if ((align & 1) == 0) |
| 33372 |
emit_move_insn (mem, reg); |
| 33373 |
else |
| 33374 |
emit_insn (gen_unaligned_storehi (mem, reg)); |
| 33375 |
|
| 33376 |
i += 2; |
| 33377 |
} |
| 33378 |
|
| 33379 |
/* Handle single byte leftover. */ |
| 33380 |
if (i + 1 == length) |
| 33381 |
{ |
| 33382 |
reg = gen_lowpart (QImode, val_reg); |
| 33383 |
addr = plus_constant (Pmode, dst, i); |
| 33384 |
mem = adjust_automodify_address (dstbase, QImode, addr, i); |
| 33385 |
emit_move_insn (mem, reg); |
| 33386 |
} |
| 33387 |
|
| 33388 |
return true; |
| 33389 |
} |
| 33390 |
|
| 33391 |
/* Set a block of memory using vectorization instructions for both |
| 33392 |
aligned and unaligned cases. We fill the first LENGTH bytes of |
| 33393 |
the memory area starting from DSTBASE with byte constant VALUE. |
| 33394 |
ALIGN is the alignment requirement of memory. */ |
| 33395 |
static bool |
| 33396 |
arm_block_set_vect (rtx dstbase, |
| 33397 |
unsigned HOST_WIDE_INT length, |
| 33398 |
unsigned HOST_WIDE_INT value, |
| 33399 |
unsigned HOST_WIDE_INT align) |
| 33400 |
{ |
| 33401 |
/* Check whether we need to use unaligned store instruction. */ |
| 33402 |
if (((align & 3) != 0 || (length & 3) != 0) |
| 33403 |
/* Check whether unaligned store instruction is available. */ |
| 33404 |
&& (!unaligned_access || BYTES_BIG_ENDIAN)) |
| 33405 |
return false; |
| 33406 |
|
| 33407 |
if ((align & 3) == 0) |
| 33408 |
return arm_block_set_aligned_vect (dstbase, length, value, align); |
| 33409 |
else |
| 33410 |
return arm_block_set_unaligned_vect (dstbase, length, value, align); |
| 33411 |
} |
| 33412 |
|
| 33413 |
/* Expand string store operation. Firstly we try to do that by using |
| 33414 |
vectorization instructions, then try with ARM unaligned access and |
| 33415 |
double-word store if profitable. OPERANDS[0] is the destination, |
| 33416 |
OPERANDS[1] is the number of bytes, operands[2] is the value to |
| 33417 |
initialize the memory, OPERANDS[3] is the known alignment of the |
| 33418 |
destination. */ |
| 33419 |
bool |
| 33420 |
arm_gen_setmem (rtx *operands) |
| 33421 |
{ |
| 33422 |
rtx dstbase = operands[0]; |
| 33423 |
unsigned HOST_WIDE_INT length; |
| 33424 |
unsigned HOST_WIDE_INT value; |
| 33425 |
unsigned HOST_WIDE_INT align; |
| 33426 |
|
| 33427 |
if (!CONST_INT_P (operands[2]) || !CONST_INT_P (operands[1])) |
| 33428 |
return false; |
| 33429 |
|
| 33430 |
length = UINTVAL (operands[1]); |
| 33431 |
if (length > 64) |
| 33432 |
return false; |
| 33433 |
|
| 33434 |
value = (UINTVAL (operands[2]) & 0xFF); |
| 33435 |
align = UINTVAL (operands[3]); |
| 33436 |
if (TARGET_NEON && length >= 8 |
| 33437 |
&& current_tune->string_ops_prefer_neon |
| 33438 |
&& arm_block_set_vect (dstbase, length, value, align)) |
| 33439 |
return true; |
| 33440 |
|
| 33441 |
if (!unaligned_access && (align & 3) != 0) |
| 33442 |
return arm_block_set_unaligned_non_vect (dstbase, length, value, align); |
| 33443 |
|
| 33444 |
return arm_block_set_aligned_non_vect (dstbase, length, value, align); |
| 33445 |
} |
| 33446 |
|
| 33447 |
|
| 33448 |
static bool |
| 33449 |
arm_macro_fusion_p (void) |
| 33450 |
{ |
| 33451 |
return current_tune->fusible_ops != tune_params::FUSE_NOTHING; |
| 33452 |
} |
| 33453 |
|
| 33454 |
/* Return true if the two back-to-back sets PREV_SET, CURR_SET are suitable |
| 33455 |
for MOVW / MOVT macro fusion. */ |
| 33456 |
|
| 33457 |
static bool |
| 33458 |
arm_sets_movw_movt_fusible_p (rtx prev_set, rtx curr_set) |
| 33459 |
{ |
| 33460 |
/* We are trying to fuse |
| 33461 |
movw imm / movt imm |
| 33462 |
instructions as a group that gets scheduled together. */ |
| 33463 |
|
| 33464 |
rtx set_dest = SET_DEST (curr_set); |
| 33465 |
|
| 33466 |
if (GET_MODE (set_dest) != SImode) |
| 33467 |
return false; |
| 33468 |
|
| 33469 |
/* We are trying to match: |
| 33470 |
prev (movw) == (set (reg r0) (const_int imm16)) |
| 33471 |
curr (movt) == (set (zero_extract (reg r0) |
| 33472 |
(const_int 16) |
| 33473 |
(const_int 16)) |
| 33474 |
(const_int imm16_1)) |
| 33475 |
or |
| 33476 |
prev (movw) == (set (reg r1) |
| 33477 |
(high (symbol_ref ("SYM")))) |
| 33478 |
curr (movt) == (set (reg r0) |
| 33479 |
(lo_sum (reg r1) |
| 33480 |
(symbol_ref ("SYM")))) */ |
| 33481 |
|
| 33482 |
if (GET_CODE (set_dest) == ZERO_EXTRACT) |
| 33483 |
{ |
| 33484 |
if (CONST_INT_P (SET_SRC (curr_set)) |
| 33485 |
&& CONST_INT_P (SET_SRC (prev_set)) |
| 33486 |
&& REG_P (XEXP (set_dest, 0)) |
| 33487 |
&& REG_P (SET_DEST (prev_set)) |
| 33488 |
&& REGNO (XEXP (set_dest, 0)) == REGNO (SET_DEST (prev_set))) |
| 33489 |
return true; |
| 33490 |
|
| 33491 |
} |
| 33492 |
else if (GET_CODE (SET_SRC (curr_set)) == LO_SUM |
| 33493 |
&& REG_P (SET_DEST (curr_set)) |
| 33494 |
&& REG_P (SET_DEST (prev_set)) |
| 33495 |
&& GET_CODE (SET_SRC (prev_set)) == HIGH |
| 33496 |
&& REGNO (SET_DEST (curr_set)) == REGNO (SET_DEST (prev_set))) |
| 33497 |
return true; |
| 33498 |
|
| 33499 |
return false; |
| 33500 |
} |
| 33501 |
|
| 33502 |
static bool |
| 33503 |
aarch_macro_fusion_pair_p (rtx_insn* prev, rtx_insn* curr) |
| 33504 |
{ |
| 33505 |
rtx prev_set = single_set (prev); |
| 33506 |
rtx curr_set = single_set (curr); |
| 33507 |
|
| 33508 |
if (!prev_set |
| 33509 |
|| !curr_set) |
| 33510 |
return false; |
| 33511 |
|
| 33512 |
if (any_condjump_p (curr)) |
| 33513 |
return false; |
| 33514 |
|
| 33515 |
if (!arm_macro_fusion_p ()) |
| 33516 |
return false; |
| 33517 |
|
| 33518 |
if (current_tune->fusible_ops & tune_params::FUSE_MOVW_MOVT |
| 33519 |
&& arm_sets_movw_movt_fusible_p (prev_set, curr_set)) |
| 33520 |
return true; |
| 33521 |
|
| 33522 |
return false; |
| 33523 |
} |
| 33524 |
|
| 33525 |
/* Return true iff the instruction fusion described by OP is enabled. */ |
| 33526 |
bool |
| 33527 |
arm_fusion_enabled_p (tune_params::fuse_ops op) |
| 33528 |
{ |
| 33529 |
return current_tune->fusible_ops & op; |
| 33530 |
} |
| 33531 |
|
| 33532 |
/* Return TRUE if return address signing mechanism is enabled. */ |
| 33533 |
bool |
| 33534 |
arm_current_function_pac_enabled_p (void) |
| 33535 |
{ |
| 33536 |
return (aarch_ra_sign_scope == AARCH_FUNCTION_ALL |
| 33537 |
|| (aarch_ra_sign_scope == AARCH_FUNCTION_NON_LEAF |
| 33538 |
&& !crtl->is_leaf)); |
| 33539 |
} |
| 33540 |
|
| 33541 |
/* Raise an error if the current target arch is not bti compatible. */ |
| 33542 |
void aarch_bti_arch_check (void) |
| 33543 |
{ |
| 33544 |
if (!arm_arch8m_main) |
| 33545 |
error ("This architecture does not support branch protection instructions"); |
| 33546 |
} |
| 33547 |
|
| 33548 |
/* Return TRUE if Branch Target Identification Mechanism is enabled. */ |
| 33549 |
bool |
| 33550 |
aarch_bti_enabled (void) |
| 33551 |
{ |
| 33552 |
return aarch_enable_bti != 0; |
| 33553 |
} |
| 33554 |
|
| 33555 |
/* Check if INSN is a BTI J insn. */ |
| 33556 |
bool |
| 33557 |
aarch_bti_j_insn_p (rtx_insn *insn) |
| 33558 |
{ |
| 33559 |
if (!insn || !INSN_P (insn)) |
| 33560 |
return false; |
| 33561 |
|
| 33562 |
rtx pat = PATTERN (insn); |
| 33563 |
return GET_CODE (pat) == UNSPEC_VOLATILE && XINT (pat, 1) == VUNSPEC_BTI_NOP; |
| 33564 |
} |
| 33565 |
|
| 33566 |
/* Check if X (or any sub-rtx of X) is a PACIASP/PACIBSP instruction. */ |
| 33567 |
bool |
| 33568 |
aarch_pac_insn_p (rtx x) |
| 33569 |
{ |
| 33570 |
if (!x || !INSN_P (x)) |
| 33571 |
return false; |
| 33572 |
|
| 33573 |
rtx pat = PATTERN (x); |
| 33574 |
|
| 33575 |
if (GET_CODE (pat) == SET) |
| 33576 |
{ |
| 33577 |
rtx tmp = XEXP (pat, 1); |
| 33578 |
if (tmp |
| 33579 |
&& ((GET_CODE (tmp) == UNSPEC |
| 33580 |
&& XINT (tmp, 1) == UNSPEC_PAC_NOP) |
| 33581 |
|| (GET_CODE (tmp) == UNSPEC_VOLATILE |
| 33582 |
&& XINT (tmp, 1) == VUNSPEC_PACBTI_NOP))) |
| 33583 |
return true; |
| 33584 |
} |
| 33585 |
|
| 33586 |
return false; |
| 33587 |
} |
| 33588 |
|
| 33589 |
/* Target specific mapping for aarch_gen_bti_c and aarch_gen_bti_j. |
| 33590 |
For Arm, both of these map to a simple BTI instruction. */ |
| 33591 |
|
| 33592 |
rtx |
| 33593 |
aarch_gen_bti_c (void) |
| 33594 |
{ |
| 33595 |
return gen_bti_nop (); |
| 33596 |
} |
| 33597 |
|
| 33598 |
rtx |
| 33599 |
aarch_gen_bti_j (void) |
| 33600 |
{ |
| 33601 |
return gen_bti_nop (); |
| 33602 |
} |
| 33603 |
|
| 33604 |
/* For AArch32, we always return false because indirect_return attribute |
| 33605 |
is only supported on AArch64 targets. */ |
| 33606 |
|
| 33607 |
bool |
| 33608 |
aarch_fun_is_indirect_return (rtx_insn *) |
| 33609 |
{ |
| 33610 |
return false; |
| 33611 |
} |
| 33612 |
|
| 33613 |
/* Implement TARGET_SCHED_CAN_SPECULATE_INSN. Return true if INSN can be |
| 33614 |
scheduled for speculative execution. Reject the long-running division |
| 33615 |
and square-root instructions. */ |
| 33616 |
|
| 33617 |
static bool |
| 33618 |
arm_sched_can_speculate_insn (rtx_insn *insn) |
| 33619 |
{ |
| 33620 |
switch (get_attr_type (insn)) |
| 33621 |
{ |
| 33622 |
case TYPE_SDIV: |
| 33623 |
case TYPE_UDIV: |
| 33624 |
case TYPE_FDIVS: |
| 33625 |
case TYPE_FDIVD: |
| 33626 |
case TYPE_FSQRTS: |
| 33627 |
case TYPE_FSQRTD: |
| 33628 |
case TYPE_NEON_FP_SQRT_S: |
| 33629 |
case TYPE_NEON_FP_SQRT_D: |
| 33630 |
case TYPE_NEON_FP_SQRT_S_Q: |
| 33631 |
case TYPE_NEON_FP_SQRT_D_Q: |
| 33632 |
case TYPE_NEON_FP_DIV_S: |
| 33633 |
case TYPE_NEON_FP_DIV_D: |
| 33634 |
case TYPE_NEON_FP_DIV_S_Q: |
| 33635 |
case TYPE_NEON_FP_DIV_D_Q: |
| 33636 |
return false; |
| 33637 |
default: |
| 33638 |
return true; |
| 33639 |
} |
| 33640 |
} |
| 33641 |
|
| 33642 |
/* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */ |
| 33643 |
|
| 33644 |
static unsigned HOST_WIDE_INT |
| 33645 |
arm_asan_shadow_offset (void) |
| 33646 |
{ |
| 33647 |
return HOST_WIDE_INT_1U << 29; |
| 33648 |
} |
| 33649 |
|
| 33650 |
|
| 33651 |
/* This is a temporary fix for PR60655. Ideally we need |
| 33652 |
to handle most of these cases in the generic part but |
| 33653 |
currently we reject minus (..) (sym_ref). We try to |
| 33654 |
ameliorate the case with minus (sym_ref1) (sym_ref2) |
| 33655 |
where they are in the same section. */ |
| 33656 |
|
| 33657 |
static bool |
| 33658 |
arm_const_not_ok_for_debug_p (rtx p) |
| 33659 |
{ |
| 33660 |
tree decl_op0 = NULL; |
| 33661 |
tree decl_op1 = NULL; |
| 33662 |
|
| 33663 |
if (GET_CODE (p) == UNSPEC) |
| 33664 |
return true; |
| 33665 |
if (GET_CODE (p) == MINUS) |
| 33666 |
{ |
| 33667 |
if (GET_CODE (XEXP (p, 1)) == SYMBOL_REF) |
| 33668 |
{ |
| 33669 |
decl_op1 = SYMBOL_REF_DECL (XEXP (p, 1)); |
| 33670 |
if (decl_op1 |
| 33671 |
&& GET_CODE (XEXP (p, 0)) == SYMBOL_REF |
| 33672 |
&& (decl_op0 = SYMBOL_REF_DECL (XEXP (p, 0)))) |
| 33673 |
{ |
| 33674 |
if ((VAR_P (decl_op1) |
| 33675 |
|| TREE_CODE (decl_op1) == CONST_DECL) |
| 33676 |
&& (VAR_P (decl_op0) |
| 33677 |
|| TREE_CODE (decl_op0) == CONST_DECL)) |
| 33678 |
return (get_variable_section (decl_op1, false) |
| 33679 |
!= get_variable_section (decl_op0, false)); |
| 33680 |
|
| 33681 |
if (TREE_CODE (decl_op1) == LABEL_DECL |
| 33682 |
&& TREE_CODE (decl_op0) == LABEL_DECL) |
| 33683 |
return (DECL_CONTEXT (decl_op1) |
| 33684 |
!= DECL_CONTEXT (decl_op0)); |
| 33685 |
} |
| 33686 |
|
| 33687 |
return true; |
| 33688 |
} |
| 33689 |
} |
| 33690 |
|
| 33691 |
return false; |
| 33692 |
} |
| 33693 |
|
| 33694 |
/* return TRUE if x is a reference to a value in a constant pool */ |
| 33695 |
extern bool |
| 33696 |
arm_is_constant_pool_ref (rtx x) |
| 33697 |
{ |
| 33698 |
return (MEM_P (x) |
| 33699 |
&& GET_CODE (XEXP (x, 0)) == SYMBOL_REF |
| 33700 |
&& CONSTANT_POOL_ADDRESS_P (XEXP (x, 0))); |
| 33701 |
} |
| 33702 |
|
| 33703 |
/* Remember the last target of arm_set_current_function. */ |
| 33704 |
static GTY(()) tree arm_previous_fndecl; |
| 33705 |
|
| 33706 |
/* Restore or save the TREE_TARGET_GLOBALS from or to NEW_TREE. */ |
| 33707 |
|
| 33708 |
void |
| 33709 |
save_restore_target_globals (tree new_tree) |
| 33710 |
{ |
| 33711 |
/* If we have a previous state, use it. */ |
| 33712 |
if (TREE_TARGET_GLOBALS (new_tree)) |
| 33713 |
restore_target_globals (TREE_TARGET_GLOBALS (new_tree)); |
| 33714 |
else if (new_tree == target_option_default_node) |
| 33715 |
restore_target_globals (&default_target_globals); |
| 33716 |
else |
| 33717 |
{ |
| 33718 |
/* Call target_reinit and save the state for TARGET_GLOBALS. */ |
| 33719 |
TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts (); |
| 33720 |
} |
| 33721 |
|
| 33722 |
arm_option_params_internal (); |
| 33723 |
} |
| 33724 |
|
| 33725 |
/* Invalidate arm_previous_fndecl. */ |
| 33726 |
|
| 33727 |
void |
| 33728 |
arm_reset_previous_fndecl (void) |
| 33729 |
{ |
| 33730 |
arm_previous_fndecl = NULL_TREE; |
| 33731 |
} |
| 33732 |
|
| 33733 |
/* Establish appropriate back-end context for processing the function |
| 33734 |
FNDECL. The argument might be NULL to indicate processing at top |
| 33735 |
level, outside of any function scope. */ |
| 33736 |
|
| 33737 |
static void |
| 33738 |
arm_set_current_function (tree fndecl) |
| 33739 |
{ |
| 33740 |
if (!fndecl || fndecl == arm_previous_fndecl) |
| 33741 |
return; |
| 33742 |
|
| 33743 |
tree old_tree = (arm_previous_fndecl |
| 33744 |
? DECL_FUNCTION_SPECIFIC_TARGET (arm_previous_fndecl) |
| 33745 |
: NULL_TREE); |
| 33746 |
|
| 33747 |
tree new_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); |
| 33748 |
|
| 33749 |
/* If current function has no attributes but previous one did, |
| 33750 |
use the default node. */ |
| 33751 |
if (! new_tree && old_tree) |
| 33752 |
new_tree = target_option_default_node; |
| 33753 |
|
| 33754 |
/* If nothing to do return. #pragma GCC reset or #pragma GCC pop to |
| 33755 |
the default have been handled by save_restore_target_globals from |
| 33756 |
arm_pragma_target_parse. */ |
| 33757 |
if (old_tree == new_tree) |
| 33758 |
return; |
| 33759 |
|
| 33760 |
arm_previous_fndecl = fndecl; |
| 33761 |
|
| 33762 |
/* First set the target options. */ |
| 33763 |
cl_target_option_restore (&global_options, &global_options_set, |
| 33764 |
TREE_TARGET_OPTION (new_tree)); |
| 33765 |
|
| 33766 |
save_restore_target_globals (new_tree); |
| 33767 |
|
| 33768 |
arm_override_options_after_change_1 (&global_options, &global_options_set); |
| 33769 |
} |
| 33770 |
|
| 33771 |
/* Implement TARGET_OPTION_PRINT. */ |
| 33772 |
|
| 33773 |
static void |
| 33774 |
arm_option_print (FILE *file, int indent, struct cl_target_option *ptr) |
| 33775 |
{ |
| 33776 |
int flags = ptr->x_target_flags; |
| 33777 |
const char *fpu_name; |
| 33778 |
|
| 33779 |
fpu_name = (ptr->x_arm_fpu_index == TARGET_FPU_auto |
| 33780 |
? "auto" : all_fpus[ptr->x_arm_fpu_index].name); |
| 33781 |
|
| 33782 |
fprintf (file, "%*sselected isa %s\n", indent, "", |
| 33783 |
TARGET_THUMB2_P (flags) ? "thumb2" : |
| 33784 |
TARGET_THUMB_P (flags) ? "thumb1" : |
| 33785 |
"arm"); |
| 33786 |
|
| 33787 |
if (ptr->x_arm_arch_string) |
| 33788 |
fprintf (file, "%*sselected architecture %s\n", indent, "", |
| 33789 |
ptr->x_arm_arch_string); |
| 33790 |
|
| 33791 |
if (ptr->x_arm_cpu_string) |
| 33792 |
fprintf (file, "%*sselected CPU %s\n", indent, "", |
| 33793 |
ptr->x_arm_cpu_string); |
| 33794 |
|
| 33795 |
if (ptr->x_arm_tune_string) |
| 33796 |
fprintf (file, "%*sselected tune %s\n", indent, "", |
| 33797 |
ptr->x_arm_tune_string); |
| 33798 |
|
| 33799 |
fprintf (file, "%*sselected fpu %s\n", indent, "", fpu_name); |
| 33800 |
} |
| 33801 |
|
| 33802 |
/* Hook to determine if one function can safely inline another. */ |
| 33803 |
|
| 33804 |
static bool |
| 33805 |
arm_can_inline_p (tree caller, tree callee) |
| 33806 |
{ |
| 33807 |
tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller); |
| 33808 |
tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee); |
| 33809 |
bool can_inline = true; |
| 33810 |
|
| 33811 |
struct cl_target_option *caller_opts |
| 33812 |
= TREE_TARGET_OPTION (caller_tree ? caller_tree |
| 33813 |
: target_option_default_node); |
| 33814 |
|
| 33815 |
struct cl_target_option *callee_opts |
| 33816 |
= TREE_TARGET_OPTION (callee_tree ? callee_tree |
| 33817 |
: target_option_default_node); |
| 33818 |
|
| 33819 |
if (callee_opts == caller_opts) |
| 33820 |
return true; |
| 33821 |
|
| 33822 |
/* Callee's ISA features should be a subset of the caller's. */ |
| 33823 |
struct arm_build_target caller_target; |
| 33824 |
struct arm_build_target callee_target; |
| 33825 |
caller_target.isa = sbitmap_alloc (isa_num_bits); |
| 33826 |
callee_target.isa = sbitmap_alloc (isa_num_bits); |
| 33827 |
|
| 33828 |
arm_configure_build_target (&caller_target, caller_opts, false); |
| 33829 |
arm_configure_build_target (&callee_target, callee_opts, false); |
| 33830 |
if (!bitmap_subset_p (callee_target.isa, caller_target.isa)) |
| 33831 |
can_inline = false; |
| 33832 |
|
| 33833 |
sbitmap_free (caller_target.isa); |
| 33834 |
sbitmap_free (callee_target.isa); |
| 33835 |
|
| 33836 |
/* OK to inline between different modes. |
| 33837 |
Function with mode specific instructions, e.g using asm, |
| 33838 |
must be explicitly protected with noinline. */ |
| 33839 |
return can_inline; |
| 33840 |
} |
| 33841 |
|
| 33842 |
/* Hook to fix function's alignment affected by target attribute. */ |
| 33843 |
|
| 33844 |
static void |
| 33845 |
arm_relayout_function (tree fndecl) |
| 33846 |
{ |
| 33847 |
if (DECL_USER_ALIGN (fndecl)) |
| 33848 |
return; |
| 33849 |
|
| 33850 |
tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); |
| 33851 |
|
| 33852 |
if (!callee_tree) |
| 33853 |
callee_tree = target_option_default_node; |
| 33854 |
|
| 33855 |
struct cl_target_option *opts = TREE_TARGET_OPTION (callee_tree); |
| 33856 |
SET_DECL_ALIGN |
| 33857 |
(fndecl, |
| 33858 |
FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY_P (opts->x_target_flags))); |
| 33859 |
} |
| 33860 |
|
| 33861 |
/* Inner function to process the attribute((target(...))), take an argument and |
| 33862 |
set the current options from the argument. If we have a list, recursively |
| 33863 |
go over the list. */ |
| 33864 |
|
| 33865 |
static bool |
| 33866 |
arm_valid_target_attribute_rec (tree args, struct gcc_options *opts) |
| 33867 |
{ |
| 33868 |
if (TREE_CODE (args) == TREE_LIST) |
| 33869 |
{ |
| 33870 |
bool ret = true; |
| 33871 |
|
| 33872 |
for (; args; args = TREE_CHAIN (args)) |
| 33873 |
if (TREE_VALUE (args) |
| 33874 |
&& !arm_valid_target_attribute_rec (TREE_VALUE (args), opts)) |
| 33875 |
ret = false; |
| 33876 |
return ret; |
| 33877 |
} |
| 33878 |
|
| 33879 |
else if (TREE_CODE (args) != STRING_CST) |
| 33880 |
{ |
| 33881 |
error ("attribute %<target%> argument not a string"); |
| 33882 |
return false; |
| 33883 |
} |
| 33884 |
|
| 33885 |
char *argstr = ASTRDUP (TREE_STRING_POINTER (args)); |
| 33886 |
char *q; |
| 33887 |
|
| 33888 |
while ((q = strtok (argstr, ",")) != NULL) |
| 33889 |
{ |
| 33890 |
argstr = NULL; |
| 33891 |
if (!strcmp (q, "thumb")) |
| 33892 |
{ |
| 33893 |
opts->x_target_flags |= MASK_THUMB; |
| 33894 |
if (TARGET_FDPIC && !arm_arch_thumb2) |
| 33895 |
sorry ("FDPIC mode is not supported in Thumb-1 mode"); |
| 33896 |
} |
| 33897 |
|
| 33898 |
else if (!strcmp (q, "arm")) |
| 33899 |
opts->x_target_flags &= ~MASK_THUMB; |
| 33900 |
|
| 33901 |
else if (!strcmp (q, "general-regs-only")) |
| 33902 |
opts->x_target_flags |= MASK_GENERAL_REGS_ONLY; |
| 33903 |
|
| 33904 |
else if (startswith (q, "fpu=")) |
| 33905 |
{ |
| 33906 |
int fpu_index; |
| 33907 |
if (! opt_enum_arg_to_value (OPT_mfpu_, q + 4, |
| 33908 |
&fpu_index, CL_TARGET)) |
| 33909 |
{ |
| 33910 |
error ("invalid fpu for target attribute or pragma %qs", q); |
| 33911 |
return false; |
| 33912 |
} |
| 33913 |
if (fpu_index == TARGET_FPU_auto) |
| 33914 |
{ |
| 33915 |
/* This doesn't really make sense until we support |
| 33916 |
general dynamic selection of the architecture and all |
| 33917 |
sub-features. */ |
| 33918 |
sorry ("auto fpu selection not currently permitted here"); |
| 33919 |
return false; |
| 33920 |
} |
| 33921 |
opts->x_arm_fpu_index = (enum fpu_type) fpu_index; |
| 33922 |
} |
| 33923 |
else if (startswith (q, "arch=")) |
| 33924 |
{ |
| 33925 |
char *arch = q + 5; |
| 33926 |
const arch_option *arm_selected_arch |
| 33927 |
= arm_parse_arch_option_name (all_architectures, "arch", arch); |
| 33928 |
|
| 33929 |
if (!arm_selected_arch) |
| 33930 |
{ |
| 33931 |
error ("invalid architecture for target attribute or pragma %qs", |
| 33932 |
q); |
| 33933 |
return false; |
| 33934 |
} |
| 33935 |
|
| 33936 |
opts->x_arm_arch_string = xstrndup (arch, strlen (arch)); |
| 33937 |
} |
| 33938 |
else if (q[0] == '+') |
| 33939 |
{ |
| 33940 |
opts->x_arm_arch_string |
| 33941 |
= xasprintf ("%s%s", opts->x_arm_arch_string, q); |
| 33942 |
} |
| 33943 |
else |
| 33944 |
{ |
| 33945 |
error ("unknown target attribute or pragma %qs", q); |
| 33946 |
return false; |
| 33947 |
} |
| 33948 |
} |
| 33949 |
|
| 33950 |
return true; |
| 33951 |
} |
| 33952 |
|
| 33953 |
/* Return a TARGET_OPTION_NODE tree of the target options listed or NULL. */ |
| 33954 |
|
| 33955 |
tree |
| 33956 |
arm_valid_target_attribute_tree (tree args, struct gcc_options *opts, |
| 33957 |
struct gcc_options *opts_set) |
| 33958 |
{ |
| 33959 |
struct cl_target_option cl_opts; |
| 33960 |
|
| 33961 |
if (!arm_valid_target_attribute_rec (args, opts)) |
| 33962 |
return NULL_TREE; |
| 33963 |
|
| 33964 |
cl_target_option_save (&cl_opts, opts, opts_set); |
| 33965 |
arm_configure_build_target (&arm_active_target, &cl_opts, false); |
| 33966 |
arm_option_check_internal (opts); |
| 33967 |
/* Do any overrides, such as global options arch=xxx. |
| 33968 |
We do this since arm_active_target was overridden. */ |
| 33969 |
arm_option_reconfigure_globals (); |
| 33970 |
arm_options_perform_arch_sanity_checks (); |
| 33971 |
arm_option_override_internal (opts, opts_set); |
| 33972 |
|
| 33973 |
return build_target_option_node (opts, opts_set); |
| 33974 |
} |
| 33975 |
|
| 33976 |
static void |
| 33977 |
add_attribute (const char * mode, tree *attributes) |
| 33978 |
{ |
| 33979 |
size_t len = strlen (mode); |
| 33980 |
tree value = build_string (len, mode); |
| 33981 |
|
| 33982 |
TREE_TYPE (value) = build_array_type (char_type_node, |
| 33983 |
build_index_type (size_int (len))); |
| 33984 |
|
| 33985 |
*attributes = tree_cons (get_identifier ("target"), |
| 33986 |
build_tree_list (NULL_TREE, value), |
| 33987 |
*attributes); |
| 33988 |
} |
| 33989 |
|
| 33990 |
/* For testing. Insert thumb or arm modes alternatively on functions. */ |
| 33991 |
|
| 33992 |
static void |
| 33993 |
arm_insert_attributes (tree fndecl, tree * attributes) |
| 33994 |
{ |
| 33995 |
const char *mode; |
| 33996 |
|
| 33997 |
if (! TARGET_FLIP_THUMB) |
| 33998 |
return; |
| 33999 |
|
| 34000 |
if (TREE_CODE (fndecl) != FUNCTION_DECL || DECL_EXTERNAL(fndecl) |
| 34001 |
|| fndecl_built_in_p (fndecl) || DECL_ARTIFICIAL (fndecl)) |
| 34002 |
return; |
| 34003 |
|
| 34004 |
/* Nested definitions must inherit mode. */ |
| 34005 |
if (current_function_decl) |
| 34006 |
{ |
| 34007 |
mode = TARGET_THUMB ? "thumb" : "arm"; |
| 34008 |
add_attribute (mode, attributes); |
| 34009 |
return; |
| 34010 |
} |
| 34011 |
|
| 34012 |
/* If there is already a setting don't change it. */ |
| 34013 |
if (lookup_attribute ("target", *attributes) != NULL) |
| 34014 |
return; |
| 34015 |
|
| 34016 |
mode = thumb_flipper ? "thumb" : "arm"; |
| 34017 |
add_attribute (mode, attributes); |
| 34018 |
|
| 34019 |
thumb_flipper = !thumb_flipper; |
| 34020 |
} |
| 34021 |
|
| 34022 |
/* Hook to validate attribute((target("string"))). */ |
| 34023 |
|
| 34024 |
static bool |
| 34025 |
arm_valid_target_attribute_p (tree fndecl, tree ARG_UNUSED (name), |
| 34026 |
tree args, int ARG_UNUSED (flags)) |
| 34027 |
{ |
| 34028 |
bool ret = true; |
| 34029 |
struct gcc_options func_options, func_options_set; |
| 34030 |
tree cur_tree, new_optimize; |
| 34031 |
gcc_assert ((fndecl != NULL_TREE) && (args != NULL_TREE)); |
| 34032 |
|
| 34033 |
/* Get the optimization options of the current function. */ |
| 34034 |
tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl); |
| 34035 |
|
| 34036 |
/* If the function changed the optimization levels as well as setting target |
| 34037 |
options, start with the optimizations specified. */ |
| 34038 |
if (!func_optimize) |
| 34039 |
func_optimize = optimization_default_node; |
| 34040 |
|
| 34041 |
/* Init func_options. */ |
| 34042 |
memset (&func_options, 0, sizeof (func_options)); |
| 34043 |
init_options_struct (&func_options, NULL); |
| 34044 |
lang_hooks.init_options_struct (&func_options); |
| 34045 |
memset (&func_options_set, 0, sizeof (func_options_set)); |
| 34046 |
|
| 34047 |
/* Initialize func_options to the defaults. */ |
| 34048 |
cl_optimization_restore (&func_options, &func_options_set, |
| 34049 |
TREE_OPTIMIZATION (func_optimize)); |
| 34050 |
|
| 34051 |
cl_target_option_restore (&func_options, &func_options_set, |
| 34052 |
TREE_TARGET_OPTION (target_option_default_node)); |
| 34053 |
|
| 34054 |
/* Set func_options flags with new target mode. */ |
| 34055 |
cur_tree = arm_valid_target_attribute_tree (args, &func_options, |
| 34056 |
&func_options_set); |
| 34057 |
|
| 34058 |
if (cur_tree == NULL_TREE) |
| 34059 |
ret = false; |
| 34060 |
|
| 34061 |
new_optimize = build_optimization_node (&func_options, &func_options_set); |
| 34062 |
|
| 34063 |
DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = cur_tree; |
| 34064 |
|
| 34065 |
DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize; |
| 34066 |
|
| 34067 |
return ret; |
| 34068 |
} |
| 34069 |
|
| 34070 |
/* Match an ISA feature bitmap to a named FPU. We always use the |
| 34071 |
first entry that exactly matches the feature set, so that we |
| 34072 |
effectively canonicalize the FPU name for the assembler. */ |
| 34073 |
static const char* |
| 34074 |
arm_identify_fpu_from_isa (sbitmap isa) |
| 34075 |
{ |
| 34076 |
auto_sbitmap fpubits (isa_num_bits); |
| 34077 |
auto_sbitmap cand_fpubits (isa_num_bits); |
| 34078 |
|
| 34079 |
bitmap_and (fpubits, isa, isa_all_fpubits_internal); |
| 34080 |
|
| 34081 |
/* If there are no ISA feature bits relating to the FPU, we must be |
| 34082 |
doing soft-float. */ |
| 34083 |
if (bitmap_empty_p (fpubits)) |
| 34084 |
return "softvfp"; |
| 34085 |
|
| 34086 |
for (unsigned int i = 0; i < TARGET_FPU_auto; i++) |
| 34087 |
{ |
| 34088 |
arm_initialize_isa (cand_fpubits, all_fpus[i].isa_bits); |
| 34089 |
if (bitmap_equal_p (fpubits, cand_fpubits)) |
| 34090 |
return all_fpus[i].name; |
| 34091 |
} |
| 34092 |
/* We must find an entry, or things have gone wrong. */ |
| 34093 |
gcc_unreachable (); |
| 34094 |
} |
| 34095 |
|
| 34096 |
/* Implement ASM_DECLARE_FUNCTION_NAME. Output the ISA features used |
| 34097 |
by the function fndecl. */ |
| 34098 |
void |
| 34099 |
arm_declare_function_name (FILE *stream, const char *name, tree decl) |
| 34100 |
{ |
| 34101 |
tree target_parts = DECL_FUNCTION_SPECIFIC_TARGET (decl); |
| 34102 |
|
| 34103 |
struct cl_target_option *targ_options; |
| 34104 |
if (target_parts) |
| 34105 |
targ_options = TREE_TARGET_OPTION (target_parts); |
| 34106 |
else |
| 34107 |
targ_options = TREE_TARGET_OPTION (target_option_current_node); |
| 34108 |
gcc_assert (targ_options); |
| 34109 |
|
| 34110 |
arm_print_asm_arch_directives (stream, targ_options); |
| 34111 |
|
| 34112 |
fprintf (stream, "\t.syntax unified\n"); |
| 34113 |
|
| 34114 |
if (TARGET_THUMB) |
| 34115 |
{ |
| 34116 |
if (is_called_in_ARM_mode (decl) |
| 34117 |
|| (TARGET_THUMB1 && !TARGET_THUMB1_ONLY |
| 34118 |
&& cfun->is_thunk)) |
| 34119 |
fprintf (stream, "\t.code 32\n"); |
| 34120 |
else if (TARGET_THUMB1) |
| 34121 |
fprintf (stream, "\t.code\t16\n\t.thumb_func\n"); |
| 34122 |
else |
| 34123 |
fprintf (stream, "\t.thumb\n\t.thumb_func\n"); |
| 34124 |
} |
| 34125 |
else |
| 34126 |
fprintf (stream, "\t.arm\n"); |
| 34127 |
|
| 34128 |
if (TARGET_POKE_FUNCTION_NAME) |
| 34129 |
arm_poke_function_name (stream, (const char *) name); |
| 34130 |
} |
| 34131 |
|
| 34132 |
/* If MEM is in the form of [base+offset], extract the two parts |
| 34133 |
of address and set to BASE and OFFSET, otherwise return false |
| 34134 |
after clearing BASE and OFFSET. */ |
| 34135 |
|
| 34136 |
static bool |
| 34137 |
extract_base_offset_in_addr (rtx mem, rtx *base, rtx *offset) |
| 34138 |
{ |
| 34139 |
rtx addr; |
| 34140 |
|
| 34141 |
gcc_assert (MEM_P (mem)); |
| 34142 |
|
| 34143 |
addr = XEXP (mem, 0); |
| 34144 |
|
| 34145 |
/* Strip off const from addresses like (const (addr)). */ |
| 34146 |
if (GET_CODE (addr) == CONST) |
| 34147 |
addr = XEXP (addr, 0); |
| 34148 |
|
| 34149 |
if (REG_P (addr)) |
| 34150 |
{ |
| 34151 |
*base = addr; |
| 34152 |
*offset = const0_rtx; |
| 34153 |
return true; |
| 34154 |
} |
| 34155 |
|
| 34156 |
if (GET_CODE (addr) == PLUS |
| 34157 |
&& GET_CODE (XEXP (addr, 0)) == REG |
| 34158 |
&& CONST_INT_P (XEXP (addr, 1))) |
| 34159 |
{ |
| 34160 |
*base = XEXP (addr, 0); |
| 34161 |
*offset = XEXP (addr, 1); |
| 34162 |
return true; |
| 34163 |
} |
| 34164 |
|
| 34165 |
*base = NULL_RTX; |
| 34166 |
*offset = NULL_RTX; |
| 34167 |
|
| 34168 |
return false; |
| 34169 |
} |
| 34170 |
|
| 34171 |
/* If INSN is a load or store of address in the form of [base+offset], |
| 34172 |
extract the two parts and set to BASE and OFFSET. IS_LOAD is set |
| 34173 |
to TRUE if it's a load. Return TRUE if INSN is such an instruction, |
| 34174 |
otherwise return FALSE. */ |
| 34175 |
|
| 34176 |
static bool |
| 34177 |
fusion_load_store (rtx_insn *insn, rtx *base, rtx *offset, bool *is_load) |
| 34178 |
{ |
| 34179 |
rtx x, dest, src; |
| 34180 |
|
| 34181 |
gcc_assert (INSN_P (insn)); |
| 34182 |
x = PATTERN (insn); |
| 34183 |
if (GET_CODE (x) != SET) |
| 34184 |
return false; |
| 34185 |
|
| 34186 |
src = SET_SRC (x); |
| 34187 |
dest = SET_DEST (x); |
| 34188 |
if (REG_P (src) && MEM_P (dest)) |
| 34189 |
{ |
| 34190 |
*is_load = false; |
| 34191 |
extract_base_offset_in_addr (dest, base, offset); |
| 34192 |
} |
| 34193 |
else if (MEM_P (src) && REG_P (dest)) |
| 34194 |
{ |
| 34195 |
*is_load = true; |
| 34196 |
extract_base_offset_in_addr (src, base, offset); |
| 34197 |
} |
| 34198 |
else |
| 34199 |
return false; |
| 34200 |
|
| 34201 |
return (*base != NULL_RTX && *offset != NULL_RTX); |
| 34202 |
} |
| 34203 |
|
| 34204 |
/* Implement the TARGET_SCHED_FUSION_PRIORITY hook. |
| 34205 |
|
| 34206 |
Currently we only support to fuse ldr or str instructions, so FUSION_PRI |
| 34207 |
and PRI are only calculated for these instructions. For other instruction, |
| 34208 |
FUSION_PRI and PRI are simply set to MAX_PRI. In the future, other kind |
| 34209 |
instruction fusion can be supported by returning different priorities. |
| 34210 |
|
| 34211 |
It's important that irrelevant instructions get the largest FUSION_PRI. */ |
| 34212 |
|
| 34213 |
static void |
| 34214 |
arm_sched_fusion_priority (rtx_insn *insn, int max_pri, |
| 34215 |
int *fusion_pri, int *pri) |
| 34216 |
{ |
| 34217 |
int tmp, off_val; |
| 34218 |
bool is_load; |
| 34219 |
rtx base, offset; |
| 34220 |
|
| 34221 |
gcc_assert (INSN_P (insn)); |
| 34222 |
|
| 34223 |
tmp = max_pri - 1; |
| 34224 |
if (!fusion_load_store (insn, &base, &offset, &is_load)) |
| 34225 |
{ |
| 34226 |
*pri = tmp; |
| 34227 |
*fusion_pri = tmp; |
| 34228 |
return; |
| 34229 |
} |
| 34230 |
|
| 34231 |
/* Load goes first. */ |
| 34232 |
if (is_load) |
| 34233 |
*fusion_pri = tmp - 1; |
| 34234 |
else |
| 34235 |
*fusion_pri = tmp - 2; |
| 34236 |
|
| 34237 |
tmp /= 2; |
| 34238 |
|
| 34239 |
/* INSN with smaller base register goes first. */ |
| 34240 |
tmp -= ((REGNO (base) & 0xff) << 20); |
| 34241 |
|
| 34242 |
/* INSN with smaller offset goes first. */ |
| 34243 |
off_val = (int)(INTVAL (offset)); |
| 34244 |
if (off_val >= 0) |
| 34245 |
tmp -= (off_val & 0xfffff); |
| 34246 |
else |
| 34247 |
tmp += ((- off_val) & 0xfffff); |
| 34248 |
|
| 34249 |
*pri = tmp; |
| 34250 |
return; |
| 34251 |
} |
| 34252 |
|
| 34253 |
|
| 34254 |
/* Construct and return a PARALLEL RTX vector with elements numbering the |
| 34255 |
lanes of either the high (HIGH == TRUE) or low (HIGH == FALSE) half of |
| 34256 |
the vector - from the perspective of the architecture. This does not |
| 34257 |
line up with GCC's perspective on lane numbers, so we end up with |
| 34258 |
different masks depending on our target endian-ness. The diagram |
| 34259 |
below may help. We must draw the distinction when building masks |
| 34260 |
which select one half of the vector. An instruction selecting |
| 34261 |
architectural low-lanes for a big-endian target, must be described using |
| 34262 |
a mask selecting GCC high-lanes. |
| 34263 |
|
| 34264 |
Big-Endian Little-Endian |
| 34265 |
|
| 34266 |
GCC 0 1 2 3 3 2 1 0 |
| 34267 |
| x | x | x | x | | x | x | x | x | |
| 34268 |
Architecture 3 2 1 0 3 2 1 0 |
| 34269 |
|
| 34270 |
Low Mask: { 2, 3 } { 0, 1 } |
| 34271 |
High Mask: { 0, 1 } { 2, 3 } |
| 34272 |
*/ |
| 34273 |
|
| 34274 |
rtx |
| 34275 |
arm_simd_vect_par_cnst_half (machine_mode mode, bool high) |
| 34276 |
{ |
| 34277 |
int nunits = GET_MODE_NUNITS (mode); |
| 34278 |
rtvec v = rtvec_alloc (nunits / 2); |
| 34279 |
int high_base = nunits / 2; |
| 34280 |
int low_base = 0; |
| 34281 |
int base; |
| 34282 |
rtx t1; |
| 34283 |
int i; |
| 34284 |
|
| 34285 |
if (BYTES_BIG_ENDIAN) |
| 34286 |
base = high ? low_base : high_base; |
| 34287 |
else |
| 34288 |
base = high ? high_base : low_base; |
| 34289 |
|
| 34290 |
for (i = 0; i < nunits / 2; i++) |
| 34291 |
RTVEC_ELT (v, i) = GEN_INT (base + i); |
| 34292 |
|
| 34293 |
t1 = gen_rtx_PARALLEL (mode, v); |
| 34294 |
return t1; |
| 34295 |
} |
| 34296 |
|
| 34297 |
/* Check OP for validity as a PARALLEL RTX vector with elements |
| 34298 |
numbering the lanes of either the high (HIGH == TRUE) or low lanes, |
| 34299 |
from the perspective of the architecture. See the diagram above |
| 34300 |
arm_simd_vect_par_cnst_half_p for more details. */ |
| 34301 |
|
| 34302 |
bool |
| 34303 |
arm_simd_check_vect_par_cnst_half_p (rtx op, machine_mode mode, |
| 34304 |
bool high) |
| 34305 |
{ |
| 34306 |
rtx ideal = arm_simd_vect_par_cnst_half (mode, high); |
| 34307 |
HOST_WIDE_INT count_op = XVECLEN (op, 0); |
| 34308 |
HOST_WIDE_INT count_ideal = XVECLEN (ideal, 0); |
| 34309 |
int i = 0; |
| 34310 |
|
| 34311 |
if (!VECTOR_MODE_P (mode)) |
| 34312 |
return false; |
| 34313 |
|
| 34314 |
if (count_op != count_ideal) |
| 34315 |
return false; |
| 34316 |
|
| 34317 |
for (i = 0; i < count_ideal; i++) |
| 34318 |
{ |
| 34319 |
rtx elt_op = XVECEXP (op, 0, i); |
| 34320 |
rtx elt_ideal = XVECEXP (ideal, 0, i); |
| 34321 |
|
| 34322 |
if (!CONST_INT_P (elt_op) |
| 34323 |
|| INTVAL (elt_ideal) != INTVAL (elt_op)) |
| 34324 |
return false; |
| 34325 |
} |
| 34326 |
return true; |
| 34327 |
} |
| 34328 |
|
| 34329 |
/* Can output mi_thunk for all cases except for non-zero vcall_offset |
| 34330 |
in Thumb1. */ |
| 34331 |
static bool |
| 34332 |
arm_can_output_mi_thunk (const_tree, HOST_WIDE_INT, HOST_WIDE_INT vcall_offset, |
| 34333 |
const_tree) |
| 34334 |
{ |
| 34335 |
/* For now, we punt and not handle this for TARGET_THUMB1. */ |
| 34336 |
if (vcall_offset && TARGET_THUMB1) |
| 34337 |
return false; |
| 34338 |
|
| 34339 |
/* Otherwise ok. */ |
| 34340 |
return true; |
| 34341 |
} |
| 34342 |
|
| 34343 |
/* Generate RTL for a conditional branch with rtx comparison CODE in |
| 34344 |
mode CC_MODE. The destination of the unlikely conditional branch |
| 34345 |
is LABEL_REF. */ |
| 34346 |
|
| 34347 |
void |
| 34348 |
arm_gen_unlikely_cbranch (enum rtx_code code, machine_mode cc_mode, |
| 34349 |
rtx label_ref) |
| 34350 |
{ |
| 34351 |
rtx x; |
| 34352 |
x = gen_rtx_fmt_ee (code, VOIDmode, |
| 34353 |
gen_rtx_REG (cc_mode, CC_REGNUM), |
| 34354 |
const0_rtx); |
| 34355 |
|
| 34356 |
x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, |
| 34357 |
gen_rtx_LABEL_REF (VOIDmode, label_ref), |
| 34358 |
pc_rtx); |
| 34359 |
emit_unlikely_jump (gen_rtx_SET (pc_rtx, x)); |
| 34360 |
} |
| 34361 |
|
| 34362 |
/* Implement the TARGET_ASM_ELF_FLAGS_NUMERIC hook. |
| 34363 |
|
| 34364 |
For pure-code sections there is no letter code for this attribute, so |
| 34365 |
output all the section flags numerically when this is needed. */ |
| 34366 |
|
| 34367 |
static bool |
| 34368 |
arm_asm_elf_flags_numeric (unsigned int flags, unsigned int *num) |
| 34369 |
{ |
| 34370 |
|
| 34371 |
if (flags & SECTION_ARM_PURECODE) |
| 34372 |
{ |
| 34373 |
*num = 0x20000000; |
| 34374 |
|
| 34375 |
if (!(flags & SECTION_DEBUG)) |
| 34376 |
*num |= 0x2; |
| 34377 |
if (flags & SECTION_EXCLUDE) |
| 34378 |
*num |= 0x80000000; |
| 34379 |
if (flags & SECTION_WRITE) |
| 34380 |
*num |= 0x1; |
| 34381 |
if (flags & SECTION_CODE) |
| 34382 |
*num |= 0x4; |
| 34383 |
if (flags & SECTION_MERGE) |
| 34384 |
*num |= 0x10; |
| 34385 |
if (flags & SECTION_STRINGS) |
| 34386 |
*num |= 0x20; |
| 34387 |
if (flags & SECTION_TLS) |
| 34388 |
*num |= 0x400; |
| 34389 |
if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)) |
| 34390 |
*num |= 0x200; |
| 34391 |
|
| 34392 |
return true; |
| 34393 |
} |
| 34394 |
|
| 34395 |
return false; |
| 34396 |
} |
| 34397 |
|
| 34398 |
/* Implement the TARGET_ASM_FUNCTION_SECTION hook. |
| 34399 |
|
| 34400 |
If pure-code is passed as an option, make sure all functions are in |
| 34401 |
sections that have the SHF_ARM_PURECODE attribute. */ |
| 34402 |
|
| 34403 |
static section * |
| 34404 |
arm_function_section (tree decl, enum node_frequency freq, |
| 34405 |
bool startup, bool exit) |
| 34406 |
{ |
| 34407 |
const char * section_name; |
| 34408 |
section * sec; |
| 34409 |
|
| 34410 |
if (!decl || TREE_CODE (decl) != FUNCTION_DECL) |
| 34411 |
return default_function_section (decl, freq, startup, exit); |
| 34412 |
|
| 34413 |
if (!target_pure_code) |
| 34414 |
return default_function_section (decl, freq, startup, exit); |
| 34415 |
|
| 34416 |
|
| 34417 |
section_name = DECL_SECTION_NAME (decl); |
| 34418 |
|
| 34419 |
/* If a function is not in a named section then it falls under the 'default' |
| 34420 |
text section, also known as '.text'. We can preserve previous behavior as |
| 34421 |
the default text section already has the SHF_ARM_PURECODE section |
| 34422 |
attribute. */ |
| 34423 |
if (!section_name) |
| 34424 |
{ |
| 34425 |
section *default_sec = default_function_section (decl, freq, startup, |
| 34426 |
exit); |
| 34427 |
|
| 34428 |
/* If default_sec is not null, then it must be a special section like for |
| 34429 |
example .text.startup. We set the pure-code attribute and return the |
| 34430 |
same section to preserve existing behavior. */ |
| 34431 |
if (default_sec) |
| 34432 |
default_sec->common.flags |= SECTION_ARM_PURECODE; |
| 34433 |
return default_sec; |
| 34434 |
} |
| 34435 |
|
| 34436 |
/* Otherwise look whether a section has already been created with |
| 34437 |
'section_name'. */ |
| 34438 |
sec = get_named_section (decl, section_name, 0); |
| 34439 |
if (!sec) |
| 34440 |
/* If that is not the case passing NULL as the section's name to |
| 34441 |
'get_named_section' will create a section with the declaration's |
| 34442 |
section name. */ |
| 34443 |
sec = get_named_section (decl, NULL, 0); |
| 34444 |
|
| 34445 |
/* Set the SHF_ARM_PURECODE attribute. */ |
| 34446 |
sec->common.flags |= SECTION_ARM_PURECODE; |
| 34447 |
|
| 34448 |
return sec; |
| 34449 |
} |
| 34450 |
|
| 34451 |
/* Implements the TARGET_SECTION_FLAGS hook. |
| 34452 |
|
| 34453 |
If DECL is a function declaration and pure-code is passed as an option |
| 34454 |
then add the SFH_ARM_PURECODE attribute to the section flags. NAME is the |
| 34455 |
section's name and RELOC indicates whether the declarations initializer may |
| 34456 |
contain runtime relocations. */ |
| 34457 |
|
| 34458 |
static unsigned int |
| 34459 |
arm_elf_section_type_flags (tree decl, const char *name, int reloc) |
| 34460 |
{ |
| 34461 |
unsigned int flags = default_section_type_flags (decl, name, reloc); |
| 34462 |
|
| 34463 |
if (decl && TREE_CODE (decl) == FUNCTION_DECL && target_pure_code) |
| 34464 |
flags |= SECTION_ARM_PURECODE; |
| 34465 |
|
| 34466 |
return flags; |
| 34467 |
} |
| 34468 |
|
| 34469 |
/* Generate call to __aeabi_[mode]divmod (op0, op1). */ |
| 34470 |
|
| 34471 |
static void |
| 34472 |
arm_expand_divmod_libfunc (rtx libfunc, machine_mode mode, |
| 34473 |
rtx op0, rtx op1, |
| 34474 |
rtx *quot_p, rtx *rem_p) |
| 34475 |
{ |
| 34476 |
if (mode == SImode) |
| 34477 |
gcc_assert (!TARGET_IDIV); |
| 34478 |
|
| 34479 |
scalar_int_mode libval_mode |
| 34480 |
= smallest_int_mode_for_size (2 * GET_MODE_BITSIZE (mode)).require (); |
| 34481 |
|
| 34482 |
rtx libval = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST, |
| 34483 |
libval_mode, op0, mode, op1, mode); |
| 34484 |
|
| 34485 |
rtx quotient = simplify_gen_subreg (mode, libval, libval_mode, 0); |
| 34486 |
rtx remainder = simplify_gen_subreg (mode, libval, libval_mode, |
| 34487 |
GET_MODE_SIZE (mode)); |
| 34488 |
|
| 34489 |
gcc_assert (quotient); |
| 34490 |
gcc_assert (remainder); |
| 34491 |
|
| 34492 |
*quot_p = quotient; |
| 34493 |
*rem_p = remainder; |
| 34494 |
} |
| 34495 |
|
| 34496 |
/* This function checks for the availability of the coprocessor builtin passed |
| 34497 |
in BUILTIN for the current target. Returns true if it is available and |
| 34498 |
false otherwise. If a BUILTIN is passed for which this function has not |
| 34499 |
been implemented it will cause an exception. */ |
| 34500 |
|
| 34501 |
bool |
| 34502 |
arm_coproc_builtin_available (enum unspecv builtin) |
| 34503 |
{ |
| 34504 |
/* None of these builtins are available in Thumb mode if the target only |
| 34505 |
supports Thumb-1. */ |
| 34506 |
if (TARGET_THUMB1) |
| 34507 |
return false; |
| 34508 |
|
| 34509 |
switch (builtin) |
| 34510 |
{ |
| 34511 |
case VUNSPEC_CDP: |
| 34512 |
case VUNSPEC_LDC: |
| 34513 |
case VUNSPEC_LDCL: |
| 34514 |
case VUNSPEC_STC: |
| 34515 |
case VUNSPEC_STCL: |
| 34516 |
case VUNSPEC_MCR: |
| 34517 |
case VUNSPEC_MRC: |
| 34518 |
if (arm_arch4) |
| 34519 |
return true; |
| 34520 |
break; |
| 34521 |
case VUNSPEC_CDP2: |
| 34522 |
case VUNSPEC_LDC2: |
| 34523 |
case VUNSPEC_LDC2L: |
| 34524 |
case VUNSPEC_STC2: |
| 34525 |
case VUNSPEC_STC2L: |
| 34526 |
case VUNSPEC_MCR2: |
| 34527 |
case VUNSPEC_MRC2: |
| 34528 |
/* Only present in ARMv5*, ARMv6 (but not ARMv6-M), ARMv7* and |
| 34529 |
ARMv8-{A,M}. */ |
| 34530 |
if (arm_arch5t) |
| 34531 |
return true; |
| 34532 |
break; |
| 34533 |
case VUNSPEC_MCRR: |
| 34534 |
case VUNSPEC_MRRC: |
| 34535 |
/* Only present in ARMv5TE, ARMv6 (but not ARMv6-M), ARMv7* and |
| 34536 |
ARMv8-{A,M}. */ |
| 34537 |
if (arm_arch6 || arm_arch5te) |
| 34538 |
return true; |
| 34539 |
break; |
| 34540 |
case VUNSPEC_MCRR2: |
| 34541 |
case VUNSPEC_MRRC2: |
| 34542 |
if (arm_arch6) |
| 34543 |
return true; |
| 34544 |
break; |
| 34545 |
default: |
| 34546 |
gcc_unreachable (); |
| 34547 |
} |
| 34548 |
return false; |
| 34549 |
} |
| 34550 |
|
| 34551 |
/* This function returns true if OP is a valid memory operand for the ldc and |
| 34552 |
stc coprocessor instructions and false otherwise. */ |
| 34553 |
|
| 34554 |
bool |
| 34555 |
arm_coproc_ldc_stc_legitimate_address (rtx op) |
| 34556 |
{ |
| 34557 |
HOST_WIDE_INT range; |
| 34558 |
/* Has to be a memory operand. */ |
| 34559 |
if (!MEM_P (op)) |
| 34560 |
return false; |
| 34561 |
|
| 34562 |
op = XEXP (op, 0); |
| 34563 |
|
| 34564 |
/* We accept registers. */ |
| 34565 |
if (REG_P (op)) |
| 34566 |
return true; |
| 34567 |
|
| 34568 |
switch GET_CODE (op) |
| 34569 |
{ |
| 34570 |
case PLUS: |
| 34571 |
{ |
| 34572 |
/* Or registers with an offset. */ |
| 34573 |
if (!REG_P (XEXP (op, 0))) |
| 34574 |
return false; |
| 34575 |
|
| 34576 |
op = XEXP (op, 1); |
| 34577 |
|
| 34578 |
/* The offset must be an immediate though. */ |
| 34579 |
if (!CONST_INT_P (op)) |
| 34580 |
return false; |
| 34581 |
|
| 34582 |
range = INTVAL (op); |
| 34583 |
|
| 34584 |
/* Within the range of [-1020,1020]. */ |
| 34585 |
if (!IN_RANGE (range, -1020, 1020)) |
| 34586 |
return false; |
| 34587 |
|
| 34588 |
/* And a multiple of 4. */ |
| 34589 |
return (range % 4) == 0; |
| 34590 |
} |
| 34591 |
case PRE_INC: |
| 34592 |
case POST_INC: |
| 34593 |
case PRE_DEC: |
| 34594 |
case POST_DEC: |
| 34595 |
return REG_P (XEXP (op, 0)); |
| 34596 |
default: |
| 34597 |
gcc_unreachable (); |
| 34598 |
} |
| 34599 |
return false; |
| 34600 |
} |
| 34601 |
|
| 34602 |
/* Return true if OP is a valid memory operand for LDRD/STRD without any |
| 34603 |
register overlap restrictions. Allow [base] and [base, imm] for now. */ |
| 34604 |
bool |
| 34605 |
arm_ldrd_legitimate_address (rtx op) |
| 34606 |
{ |
| 34607 |
if (!MEM_P (op)) |
| 34608 |
return false; |
| 34609 |
|
| 34610 |
op = XEXP (op, 0); |
| 34611 |
if (REG_P (op)) |
| 34612 |
return true; |
| 34613 |
|
| 34614 |
if (GET_CODE (op) != PLUS) |
| 34615 |
return false; |
| 34616 |
if (!REG_P (XEXP (op, 0)) || !CONST_INT_P (XEXP (op, 1))) |
| 34617 |
return false; |
| 34618 |
|
| 34619 |
HOST_WIDE_INT val = INTVAL (XEXP (op, 1)); |
| 34620 |
|
| 34621 |
if (TARGET_ARM) |
| 34622 |
return IN_RANGE (val, -255, 255); |
| 34623 |
return IN_RANGE (val, -1020, 1020) && (val & 3) == 0; |
| 34624 |
} |
| 34625 |
|
| 34626 |
/* Return the diagnostic message string if conversion from FROMTYPE to |
| 34627 |
TOTYPE is not allowed, NULL otherwise. */ |
| 34628 |
|
| 34629 |
static const char * |
| 34630 |
arm_invalid_conversion (const_tree fromtype, const_tree totype) |
| 34631 |
{ |
| 34632 |
if (element_mode (fromtype) != element_mode (totype)) |
| 34633 |
{ |
| 34634 |
/* Do no allow conversions to/from BFmode scalar types. */ |
| 34635 |
if (TYPE_MODE (fromtype) == BFmode) |
| 34636 |
return N_("invalid conversion from type %<bfloat16_t%>"); |
| 34637 |
if (TYPE_MODE (totype) == BFmode) |
| 34638 |
return N_("invalid conversion to type %<bfloat16_t%>"); |
| 34639 |
} |
| 34640 |
|
| 34641 |
/* Conversion allowed. */ |
| 34642 |
return NULL; |
| 34643 |
} |
| 34644 |
|
| 34645 |
/* Return the diagnostic message string if the unary operation OP is |
| 34646 |
not permitted on TYPE, NULL otherwise. */ |
| 34647 |
|
| 34648 |
static const char * |
| 34649 |
arm_invalid_unary_op (int op, const_tree type) |
| 34650 |
{ |
| 34651 |
/* Reject all single-operand operations on BFmode except for &. */ |
| 34652 |
if (element_mode (type) == BFmode && op != ADDR_EXPR) |
| 34653 |
return N_("operation not permitted on type %<bfloat16_t%>"); |
| 34654 |
|
| 34655 |
/* Operation allowed. */ |
| 34656 |
return NULL; |
| 34657 |
} |
| 34658 |
|
| 34659 |
/* Return the diagnostic message string if the binary operation OP is |
| 34660 |
not permitted on TYPE1 and TYPE2, NULL otherwise. */ |
| 34661 |
|
| 34662 |
static const char * |
| 34663 |
arm_invalid_binary_op (int op ATTRIBUTE_UNUSED, const_tree type1, |
| 34664 |
const_tree type2) |
| 34665 |
{ |
| 34666 |
/* Reject all 2-operand operations on BFmode. */ |
| 34667 |
if (element_mode (type1) == BFmode |
| 34668 |
|| element_mode (type2) == BFmode) |
| 34669 |
return N_("operation not permitted on type %<bfloat16_t%>"); |
| 34670 |
|
| 34671 |
/* Operation allowed. */ |
| 34672 |
return NULL; |
| 34673 |
} |
| 34674 |
|
| 34675 |
/* Implement TARGET_CAN_CHANGE_MODE_CLASS. |
| 34676 |
|
| 34677 |
In VFPv1, VFP registers could only be accessed in the mode they were |
| 34678 |
set, so subregs would be invalid there. However, we don't support |
| 34679 |
VFPv1 at the moment, and the restriction was lifted in VFPv2. |
| 34680 |
|
| 34681 |
In big-endian mode, modes greater than word size (i.e. DFmode) are stored in |
| 34682 |
VFP registers in little-endian order. We can't describe that accurately to |
| 34683 |
GCC, so avoid taking subregs of such values. |
| 34684 |
|
| 34685 |
The only exception is going from a 128-bit to a 64-bit type. In that |
| 34686 |
case the data layout happens to be consistent for big-endian, so we |
| 34687 |
explicitly allow that case. */ |
| 34688 |
|
| 34689 |
static bool |
| 34690 |
arm_can_change_mode_class (machine_mode from, machine_mode to, |
| 34691 |
reg_class_t rclass) |
| 34692 |
{ |
| 34693 |
if (TARGET_BIG_END |
| 34694 |
&& !(GET_MODE_SIZE (from) == 16 && GET_MODE_SIZE (to) == 8) |
| 34695 |
&& (GET_MODE_SIZE (from) > UNITS_PER_WORD |
| 34696 |
|| GET_MODE_SIZE (to) > UNITS_PER_WORD) |
| 34697 |
&& reg_classes_intersect_p (VFP_REGS, rclass)) |
| 34698 |
return false; |
| 34699 |
return true; |
| 34700 |
} |
| 34701 |
|
| 34702 |
/* Implement TARGET_CONSTANT_ALIGNMENT. Make strings word-aligned so |
| 34703 |
strcpy from constants will be faster. */ |
| 34704 |
|
| 34705 |
static HOST_WIDE_INT |
| 34706 |
arm_constant_alignment (const_tree exp, HOST_WIDE_INT align) |
| 34707 |
{ |
| 34708 |
unsigned int factor = (TARGET_THUMB || ! arm_tune_xscale ? 1 : 2); |
| 34709 |
if (TREE_CODE (exp) == STRING_CST && !optimize_size) |
| 34710 |
return MAX (align, BITS_PER_WORD * factor); |
| 34711 |
return align; |
| 34712 |
} |
| 34713 |
|
| 34714 |
/* Emit a speculation barrier on target architectures that do not have |
| 34715 |
DSB/ISB directly. Such systems probably don't need a barrier |
| 34716 |
themselves, but if the code is ever run on a later architecture, it |
| 34717 |
might become a problem. */ |
| 34718 |
void |
| 34719 |
arm_emit_speculation_barrier_function () |
| 34720 |
{ |
| 34721 |
emit_library_call (speculation_barrier_libfunc, LCT_NORMAL, VOIDmode); |
| 34722 |
} |
| 34723 |
|
| 34724 |
/* Have we recorded an explicit access to the Q bit of APSR?. */ |
| 34725 |
bool |
| 34726 |
arm_q_bit_access (void) |
| 34727 |
{ |
| 34728 |
if (cfun && cfun->decl) |
| 34729 |
return lookup_attribute ("acle qbit", |
| 34730 |
DECL_ATTRIBUTES (cfun->decl)); |
| 34731 |
return true; |
| 34732 |
} |
| 34733 |
|
| 34734 |
/* Have we recorded an explicit access to the GE bits of PSTATE?. */ |
| 34735 |
bool |
| 34736 |
arm_ge_bits_access (void) |
| 34737 |
{ |
| 34738 |
if (cfun && cfun->decl) |
| 34739 |
return lookup_attribute ("acle gebits", |
| 34740 |
DECL_ATTRIBUTES (cfun->decl)); |
| 34741 |
return true; |
| 34742 |
} |
| 34743 |
|
| 34744 |
/* NULL if insn INSN is valid within a low-overhead loop. |
| 34745 |
Otherwise return why doloop cannot be applied. */ |
| 34746 |
|
| 34747 |
static const char * |
| 34748 |
arm_invalid_within_doloop (const rtx_insn *insn) |
| 34749 |
{ |
| 34750 |
if (!TARGET_HAVE_LOB) |
| 34751 |
return default_invalid_within_doloop (insn); |
| 34752 |
|
| 34753 |
if (CALL_P (insn)) |
| 34754 |
return "Function call in the loop."; |
| 34755 |
|
| 34756 |
if (reg_mentioned_p (gen_rtx_REG (SImode, LR_REGNUM), insn)) |
| 34757 |
return "LR is used inside loop."; |
| 34758 |
|
| 34759 |
return NULL; |
| 34760 |
} |
| 34761 |
|
| 34762 |
bool |
| 34763 |
arm_target_bb_ok_for_lob (basic_block bb) |
| 34764 |
{ |
| 34765 |
/* Make sure the basic block is a simple latch having as the single |
| 34766 |
predecessor and successor the body of the loop itself. |
| 34767 |
Only simple loops with a single basic block as body are supported for |
| 34768 |
low over head loops, making sure that LE target is above LE instruction |
| 34769 |
in the generated code. */ |
| 34770 |
return (single_succ_p (bb) |
| 34771 |
&& single_pred_p (bb) |
| 34772 |
&& single_succ_edge (bb)->dest == single_pred_edge (bb)->src); |
| 34773 |
} |
| 34774 |
|
| 34775 |
/* Utility fuction: Given a VCTP or a VCTP_M insn, return the number of MVE |
| 34776 |
lanes based on the machine mode being used. */ |
| 34777 |
|
| 34778 |
static int |
| 34779 |
arm_mve_get_vctp_lanes (rtx_insn *insn) |
| 34780 |
{ |
| 34781 |
rtx insn_set = single_set (insn); |
| 34782 |
if (insn_set |
| 34783 |
&& GET_CODE (SET_SRC (insn_set)) == UNSPEC |
| 34784 |
&& (XINT (SET_SRC (insn_set), 1) == VCTP |
| 34785 |
|| XINT (SET_SRC (insn_set), 1) == VCTP_M)) |
| 34786 |
{ |
| 34787 |
machine_mode mode = GET_MODE (SET_SRC (insn_set)); |
| 34788 |
return ((VECTOR_MODE_P (mode) && VALID_MVE_PRED_MODE (mode)) |
| 34789 |
? GET_MODE_NUNITS (mode) : 0); |
| 34790 |
} |
| 34791 |
return 0; |
| 34792 |
} |
| 34793 |
|
| 34794 |
enum arm_dl_usage_type { DL_USAGE_ANY = 0, |
| 34795 |
DL_USAGE_READ = 1, |
| 34796 |
DL_USAGE_WRITE = 2 }; |
| 34797 |
|
| 34798 |
/* Check if INSN requires the use of the VPR reg, if it does, return the |
| 34799 |
sub-rtx of the VPR reg. The TYPE argument controls whether |
| 34800 |
this function should: |
| 34801 |
* For TYPE == DL_USAGE_ANY, check all operands, including the OUT operands, |
| 34802 |
and return the first occurrence of the VPR reg. |
| 34803 |
* For TYPE == DL_USAGE_READ, only check the input operands. |
| 34804 |
* For TYPE == DL_USAGE_WRITE, only check the output operands. |
| 34805 |
(INOUT operands are considered both as input and output operands) |
| 34806 |
*/ |
| 34807 |
static rtx |
| 34808 |
arm_get_required_vpr_reg (rtx_insn *insn, |
| 34809 |
arm_dl_usage_type type = DL_USAGE_ANY) |
| 34810 |
{ |
| 34811 |
gcc_assert (type < 3); |
| 34812 |
if (!NONJUMP_INSN_P (insn)) |
| 34813 |
return NULL_RTX; |
| 34814 |
|
| 34815 |
bool requires_vpr; |
| 34816 |
extract_constrain_insn (insn); |
| 34817 |
int n_operands = recog_data.n_operands; |
| 34818 |
if (recog_data.n_alternatives == 0) |
| 34819 |
return NULL_RTX; |
| 34820 |
|
| 34821 |
/* Fill in recog_op_alt with information about the constraints of |
| 34822 |
this insn. */ |
| 34823 |
preprocess_constraints (insn); |
| 34824 |
|
| 34825 |
for (int op = 0; op < n_operands; op++) |
| 34826 |
{ |
| 34827 |
requires_vpr = true; |
| 34828 |
if (type == DL_USAGE_READ |
| 34829 |
&& recog_data.operand_type[op] == OP_OUT) |
| 34830 |
continue; |
| 34831 |
else if (type == DL_USAGE_WRITE |
| 34832 |
&& recog_data.operand_type[op] == OP_IN) |
| 34833 |
continue; |
| 34834 |
|
| 34835 |
/* Iterate through alternatives of operand "op" in recog_op_alt and |
| 34836 |
identify if the operand is required to be the VPR. */ |
| 34837 |
for (int alt = 0; alt < recog_data.n_alternatives; alt++) |
| 34838 |
{ |
| 34839 |
const operand_alternative *op_alt |
| 34840 |
= &recog_op_alt[alt * n_operands]; |
| 34841 |
/* Fetch the reg_class for each entry and check it against the |
| 34842 |
VPR_REG reg_class. */ |
| 34843 |
if (alternative_class (op_alt, op) != VPR_REG) |
| 34844 |
requires_vpr = false; |
| 34845 |
} |
| 34846 |
/* If all alternatives of the insn require the VPR reg for this operand, |
| 34847 |
it means that either this is VPR-generating instruction, like a vctp, |
| 34848 |
vcmp, etc., or it is a VPT-predicated insruction. Return the subrtx |
| 34849 |
of the VPR reg operand. */ |
| 34850 |
if (requires_vpr) |
| 34851 |
return recog_data.operand[op]; |
| 34852 |
} |
| 34853 |
return NULL_RTX; |
| 34854 |
} |
| 34855 |
|
| 34856 |
/* Wrapper function of arm_get_required_vpr_reg with TYPE == DL_USAGE_READ, |
| 34857 |
so return the VPR only if it is an input operand to the insn. */ |
| 34858 |
|
| 34859 |
static rtx |
| 34860 |
arm_get_required_vpr_reg_param (rtx_insn *insn) |
| 34861 |
{ |
| 34862 |
return arm_get_required_vpr_reg (insn, DL_USAGE_READ); |
| 34863 |
} |
| 34864 |
|
| 34865 |
/* Wrapper function of arm_get_required_vpr_reg with TYPE == DL_USAGE_WRITE, |
| 34866 |
so return the VPR only if it is the return value, an output of, or is |
| 34867 |
clobbered by the insn. */ |
| 34868 |
|
| 34869 |
static rtx |
| 34870 |
arm_get_required_vpr_reg_ret_val (rtx_insn *insn) |
| 34871 |
{ |
| 34872 |
return arm_get_required_vpr_reg (insn, DL_USAGE_WRITE); |
| 34873 |
} |
| 34874 |
|
| 34875 |
/* Return the first VCTP instruction in BB, if it exists, or NULL otherwise. */ |
| 34876 |
|
| 34877 |
static rtx_insn * |
| 34878 |
arm_mve_get_loop_vctp (basic_block bb) |
| 34879 |
{ |
| 34880 |
rtx_insn *insn = BB_HEAD (bb); |
| 34881 |
|
| 34882 |
/* Now scan through all the instruction patterns and pick out the VCTP |
| 34883 |
instruction. We require arm_get_required_vpr_reg_param to be false |
| 34884 |
to make sure we pick up a VCTP, rather than a VCTP_M. */ |
| 34885 |
FOR_BB_INSNS (bb, insn) |
| 34886 |
if (NONDEBUG_INSN_P (insn)) |
| 34887 |
if (arm_get_required_vpr_reg_ret_val (insn) |
| 34888 |
&& (arm_mve_get_vctp_lanes (insn) != 0) |
| 34889 |
&& !arm_get_required_vpr_reg_param (insn)) |
| 34890 |
return insn; |
| 34891 |
return NULL; |
| 34892 |
} |
| 34893 |
|
| 34894 |
/* Return true if INSN is a MVE instruction that is VPT-predicable and is |
| 34895 |
predicated on VPR_REG. */ |
| 34896 |
|
| 34897 |
static bool |
| 34898 |
arm_mve_insn_predicated_by (rtx_insn *insn, rtx vpr_reg) |
| 34899 |
{ |
| 34900 |
rtx insn_vpr_reg_operand = (MVE_VPT_PREDICATED_INSN_P (insn) |
| 34901 |
? arm_get_required_vpr_reg_param (insn) |
| 34902 |
: NULL_RTX); |
| 34903 |
return (insn_vpr_reg_operand |
| 34904 |
&& rtx_equal_p (vpr_reg, insn_vpr_reg_operand)); |
| 34905 |
} |
| 34906 |
|
| 34907 |
/* Utility function to identify if INSN is an MVE instruction that performs |
| 34908 |
some across lane operation (and as a result does not align with normal |
| 34909 |
lane predication rules). All such instructions give one only scalar |
| 34910 |
output, except for vshlcq which gives a PARALLEL of a vector and a scalar |
| 34911 |
(one vector result and one carry output). */ |
| 34912 |
|
| 34913 |
static bool |
| 34914 |
arm_mve_across_lane_insn_p (rtx_insn* insn) |
| 34915 |
{ |
| 34916 |
df_ref insn_defs = NULL; |
| 34917 |
if (!MVE_VPT_PREDICABLE_INSN_P (insn)) |
| 34918 |
return false; |
| 34919 |
|
| 34920 |
FOR_EACH_INSN_DEF (insn_defs, insn) |
| 34921 |
if (!VALID_MVE_MODE (GET_MODE (DF_REF_REG (insn_defs))) |
| 34922 |
&& !arm_get_required_vpr_reg_ret_val (insn)) |
| 34923 |
return true; |
| 34924 |
|
| 34925 |
return false; |
| 34926 |
} |
| 34927 |
|
| 34928 |
/* Utility function to identify if INSN is an MVE load or store instruction. |
| 34929 |
* For TYPE == DL_USAGE_ANY, check all operands. If the function returns |
| 34930 |
true, INSN is a load or a store insn. |
| 34931 |
* For TYPE == DL_USAGE_READ, only check the input operands. If the |
| 34932 |
function returns true, INSN is a load insn. |
| 34933 |
* For TYPE == DL_USAGE_WRITE, only check the output operands. If the |
| 34934 |
function returns true, INSN is a store insn. */ |
| 34935 |
|
| 34936 |
static bool |
| 34937 |
arm_mve_load_store_insn_p (rtx_insn* insn, |
| 34938 |
arm_dl_usage_type type = DL_USAGE_ANY) |
| 34939 |
{ |
| 34940 |
gcc_assert (type < 3); |
| 34941 |
int n_operands = recog_data.n_operands; |
| 34942 |
extract_insn (insn); |
| 34943 |
|
| 34944 |
for (int op = 0; op < n_operands; op++) |
| 34945 |
{ |
| 34946 |
if (type == DL_USAGE_READ && recog_data.operand_type[op] == OP_OUT) |
| 34947 |
continue; |
| 34948 |
else if (type == DL_USAGE_WRITE && recog_data.operand_type[op] == OP_IN) |
| 34949 |
continue; |
| 34950 |
if (mve_memory_operand (recog_data.operand[op], |
| 34951 |
GET_MODE (recog_data.operand[op]))) |
| 34952 |
return true; |
| 34953 |
} |
| 34954 |
return false; |
| 34955 |
} |
| 34956 |
|
| 34957 |
/* Return TRUE if INSN is validated for implicit predication by how its outputs |
| 34958 |
are used. |
| 34959 |
|
| 34960 |
If INSN is a MVE operation across lanes that is not predicated by |
| 34961 |
VCTP_VPR_GENERATED it can not be validated by the use of its ouputs. |
| 34962 |
|
| 34963 |
Any other INSN is safe to implicit predicate if we don't use its outputs |
| 34964 |
outside the loop. The instructions that use this INSN's outputs will be |
| 34965 |
validated as we go through the analysis. */ |
| 34966 |
|
| 34967 |
static bool |
| 34968 |
arm_mve_impl_pred_on_outputs_p (rtx_insn *insn, rtx vctp_vpr_generated) |
| 34969 |
{ |
| 34970 |
/* Reject any unpredicated across lane operation. */ |
| 34971 |
if (!arm_mve_insn_predicated_by (insn, vctp_vpr_generated) |
| 34972 |
&& arm_mve_across_lane_insn_p (insn)) |
| 34973 |
return false; |
| 34974 |
|
| 34975 |
/* Next, scan forward to the various USEs of the DEFs in this insn. */ |
| 34976 |
df_ref insn_def = NULL; |
| 34977 |
basic_block insn_bb = BLOCK_FOR_INSN (insn); |
| 34978 |
FOR_EACH_INSN_DEF (insn_def, insn) |
| 34979 |
{ |
| 34980 |
for (df_ref use = DF_REG_USE_CHAIN (DF_REF_REGNO (insn_def)); |
| 34981 |
use; |
| 34982 |
use = DF_REF_NEXT_REG (use)) |
| 34983 |
{ |
| 34984 |
rtx_insn *next_use_insn = DF_REF_INSN (use); |
| 34985 |
if (!INSN_P (next_use_insn) || DEBUG_INSN_P (next_use_insn)) |
| 34986 |
continue; |
| 34987 |
|
| 34988 |
if (insn_bb != BLOCK_FOR_INSN (next_use_insn)) |
| 34989 |
return false; |
| 34990 |
} |
| 34991 |
} |
| 34992 |
return true; |
| 34993 |
} |
| 34994 |
|
| 34995 |
|
| 34996 |
/* Returns the prevailing definition of OP before CUR_INSN in the same |
| 34997 |
basic block as CUR_INSN, if one exists, returns NULL otherwise. */ |
| 34998 |
|
| 34999 |
static rtx_insn* |
| 35000 |
arm_last_vect_def_insn (rtx op, rtx_insn *cur_insn) |
| 35001 |
{ |
| 35002 |
if (!REG_P (op) |
| 35003 |
|| !BLOCK_FOR_INSN (cur_insn)) |
| 35004 |
return NULL; |
| 35005 |
|
| 35006 |
df_ref def_insns; |
| 35007 |
rtx_insn *last_def = NULL; |
| 35008 |
for (def_insns = DF_REG_DEF_CHAIN (REGNO (op)); |
| 35009 |
def_insns; |
| 35010 |
def_insns = DF_REF_NEXT_REG (def_insns)) |
| 35011 |
{ |
| 35012 |
rtx_insn *def_insn = DF_REF_INSN (def_insns); |
| 35013 |
/* Definition not in the loop body or after the current insn. */ |
| 35014 |
if (DF_REF_BB (def_insns) != BLOCK_FOR_INSN (cur_insn) |
| 35015 |
|| INSN_UID (def_insn) >= INSN_UID (cur_insn)) |
| 35016 |
continue; |
| 35017 |
|
| 35018 |
if (!last_def || INSN_UID (def_insn) > INSN_UID (last_def)) |
| 35019 |
last_def = def_insn; |
| 35020 |
} |
| 35021 |
return last_def; |
| 35022 |
} |
| 35023 |
|
| 35024 |
|
| 35025 |
/* This function returns TRUE if we can validate the implicit predication of |
| 35026 |
INSN_IN with VCTP_VPR_GENERATED based on the definition of the instruction's |
| 35027 |
input operands. |
| 35028 |
|
| 35029 |
If INSN_IN is a MVE operation across lanes then all of its MVE vector |
| 35030 |
operands must have its tail-predicated lanes be zeroes. We keep track of any |
| 35031 |
instructions that define vector operands for which this is true in |
| 35032 |
PROPS_ZERO_SET. |
| 35033 |
|
| 35034 |
For any other INSN_IN, the definition of all its operands must be defined |
| 35035 |
inside the loop body by an instruction that comes before INSN_IN and not be |
| 35036 |
a MVE load predicated by a different VPR. These instructions have all been |
| 35037 |
validated for explicit or implicit predication. |
| 35038 |
*/ |
| 35039 |
|
| 35040 |
static bool |
| 35041 |
arm_mve_impl_pred_on_inputs_p (vec <rtx_insn *> *props_zero_set, |
| 35042 |
rtx_insn *insn_in, rtx vctp_vpr_generated) |
| 35043 |
{ |
| 35044 |
/* If all inputs come from instructions that are explicitly or |
| 35045 |
implicitly predicated by the same predicate then it is safe to |
| 35046 |
implicitly predicate this instruction. */ |
| 35047 |
df_ref insn_uses = NULL; |
| 35048 |
bool across_lane = arm_mve_across_lane_insn_p (insn_in); |
| 35049 |
FOR_EACH_INSN_USE (insn_uses, insn_in) |
| 35050 |
{ |
| 35051 |
rtx op = DF_REF_REG (insn_uses); |
| 35052 |
rtx_insn *def_insn = arm_last_vect_def_insn (op, insn_in); |
| 35053 |
if (across_lane) |
| 35054 |
{ |
| 35055 |
if (!VALID_MVE_MODE (GET_MODE (op))) |
| 35056 |
continue; |
| 35057 |
if (!def_insn || !props_zero_set->contains (def_insn)) |
| 35058 |
return false; |
| 35059 |
|
| 35060 |
continue; |
| 35061 |
} |
| 35062 |
|
| 35063 |
if (!def_insn |
| 35064 |
|| (!arm_mve_insn_predicated_by (def_insn, vctp_vpr_generated) |
| 35065 |
&& arm_mve_load_store_insn_p (def_insn, DL_USAGE_READ))) |
| 35066 |
return false; |
| 35067 |
} |
| 35068 |
|
| 35069 |
return true; |
| 35070 |
} |
| 35071 |
|
| 35072 |
|
| 35073 |
/* Determine whether INSN_IN is safe to implicitly predicate based on the type |
| 35074 |
of instruction and where needed the definition of its inputs and the uses of |
| 35075 |
its outputs. |
| 35076 |
Return TRUE if it is safe to implicitly predicate and FALSE otherwise. |
| 35077 |
|
| 35078 |
* If INSN_IN is a store, then it is always unsafe to implicitly predicate it. |
| 35079 |
* If INSN_IN is a load, only reject implicit predication if its uses |
| 35080 |
directly invalidate it. |
| 35081 |
* If INSN_IN operates across vector lanes and does not have the |
| 35082 |
"mve_safe_imp_xlane_pred" attribute, then it is always unsafe to implicitly |
| 35083 |
predicate. |
| 35084 |
* If INSN_IN operates on Floating Point elements and we are not compiling |
| 35085 |
with -Ofast, then it is unsafe to implicitly predicate it as we may be |
| 35086 |
changing exception and cumulative bits behaviour. |
| 35087 |
* If INSN_IN is a VCTP instruction, then it is safe to implicitly predicate, |
| 35088 |
but instructions that use this predicate will need to be checked |
| 35089 |
just like any other UNPREDICATED MVE instruction. |
| 35090 |
* Otherwise check if INSN_IN's inputs or uses of outputs can validate its |
| 35091 |
implicit predication. |
| 35092 |
|
| 35093 |
* If all inputs come from instructions that are explicitly or implicitly |
| 35094 |
predicated by the same predicate then it is safe to implicitly predicate |
| 35095 |
this instruction. |
| 35096 |
* If INSN_IN is an operation across lanes with the "mve_safe_imp_xlane_pred" |
| 35097 |
attribute, then all it's operands must have zeroed falsely predicated tail |
| 35098 |
lanes. |
| 35099 |
|
| 35100 |
* Otherwise, check if the implicit predication of INSN_IN can be validated |
| 35101 |
based on its inputs, and if not check whether it can be validated based on |
| 35102 |
how its outputs are used. */ |
| 35103 |
|
| 35104 |
static bool |
| 35105 |
arm_mve_impl_predicated_p (vec <rtx_insn *> *props_zero_set, |
| 35106 |
rtx_insn *insn_in, rtx vctp_vpr_generated) |
| 35107 |
{ |
| 35108 |
|
| 35109 |
/* If INSN_IN is a store, then it is always unsafe to implicitly |
| 35110 |
predicate it. */ |
| 35111 |
if (arm_mve_load_store_insn_p (insn_in, DL_USAGE_WRITE)) |
| 35112 |
return false; |
| 35113 |
|
| 35114 |
/* If INSN_IN is a load, only reject implicit predication if its uses |
| 35115 |
directly invalidate it. */ |
| 35116 |
if (arm_mve_load_store_insn_p (insn_in, DL_USAGE_READ)) |
| 35117 |
{ |
| 35118 |
if (!arm_mve_impl_pred_on_outputs_p (insn_in, vctp_vpr_generated)) |
| 35119 |
return false; |
| 35120 |
return true; |
| 35121 |
} |
| 35122 |
|
| 35123 |
/* If INSN_IN operates across vector lanes and does not have the |
| 35124 |
"mve_safe_imp_xlane_pred" attribute, then it is always unsafe to implicitly |
| 35125 |
predicate. */ |
| 35126 |
if (arm_mve_across_lane_insn_p (insn_in) |
| 35127 |
&& (get_attr_mve_safe_imp_xlane_pred (insn_in) |
| 35128 |
!= MVE_SAFE_IMP_XLANE_PRED_YES)) |
| 35129 |
return false; |
| 35130 |
|
| 35131 |
/* If INSN_IN operates on Floating Point elements and we are not compiling |
| 35132 |
with -Ofast, then it is unsafe to implicitly predicate it as we may be |
| 35133 |
changing exception and cumulative bits behaviour. */ |
| 35134 |
if (!flag_unsafe_math_optimizations |
| 35135 |
&& flag_trapping_math |
| 35136 |
&& MVE_VPT_UNPREDICATED_INSN_P (insn_in)) |
| 35137 |
{ |
| 35138 |
df_ref def; |
| 35139 |
FOR_EACH_INSN_DEF (def, insn_in) |
| 35140 |
if (DF_REF_TYPE (def) == DF_REF_REG_DEF |
| 35141 |
&& FLOAT_MODE_P (GET_MODE (DF_REF_REG (def)))) |
| 35142 |
return false; |
| 35143 |
FOR_EACH_INSN_USE (def, insn_in) |
| 35144 |
if (DF_REF_TYPE (def) == DF_REF_REG_DEF |
| 35145 |
&& FLOAT_MODE_P (GET_MODE (DF_REF_REG (def)))) |
| 35146 |
return false; |
| 35147 |
} |
| 35148 |
|
| 35149 |
/* If INSN_IN is a VCTP instruction, then it is safe to implicitly predicate, |
| 35150 |
but instructions that use this predicate will need to be checked |
| 35151 |
just like any other UNPREDICATED MVE instruction. */ |
| 35152 |
if (arm_get_required_vpr_reg_ret_val (insn_in) |
| 35153 |
&& (arm_mve_get_vctp_lanes (insn_in) != 0)) |
| 35154 |
return true; |
| 35155 |
|
| 35156 |
/* Otherwise, check if the implicit predication of INSN_IN can be validated |
| 35157 |
based on its inputs, and if not check whether it can be validated based on |
| 35158 |
how its outputs are used. */ |
| 35159 |
return (arm_mve_impl_pred_on_inputs_p (props_zero_set, insn_in, vctp_vpr_generated) |
| 35160 |
|| arm_mve_impl_pred_on_outputs_p (insn_in, vctp_vpr_generated)); |
| 35161 |
} |
| 35162 |
|
| 35163 |
/* Helper function to `arm_mve_dlstp_check_inc_counter` and to |
| 35164 |
`arm_mve_dlstp_check_dec_counter`. In the situations where the loop counter |
| 35165 |
is incrementing by 1 or decrementing by 1 in each iteration, ensure that the |
| 35166 |
number of iterations, the value of REG, going into the loop, was calculated |
| 35167 |
as: |
| 35168 |
REG = (N + [1, VCTP_STEP - 1]) / VCTP_STEP |
| 35169 |
|
| 35170 |
where N is equivalent to the VCTP_REG. |
| 35171 |
*/ |
| 35172 |
|
| 35173 |
static bool |
| 35174 |
arm_mve_check_reg_origin_is_num_elems (loop *loop, rtx reg, rtx vctp_step, |
| 35175 |
rtx vctp_reg) |
| 35176 |
{ |
| 35177 |
df_ref counter_max_last_def = NULL; |
| 35178 |
|
| 35179 |
/* More than one reaching definition. */ |
| 35180 |
if (DF_REG_DEF_COUNT (REGNO (reg)) > 2) |
| 35181 |
return false; |
| 35182 |
|
| 35183 |
/* Look for a single defition of REG going into the loop. The DEF_CHAIN will |
| 35184 |
have at least two values, as this is a loop induction variable that is |
| 35185 |
defined outside the loop. */ |
| 35186 |
for (df_ref def = DF_REG_DEF_CHAIN (REGNO (reg)); |
| 35187 |
def; |
| 35188 |
def = DF_REF_NEXT_REG (def)) |
| 35189 |
{ |
| 35190 |
/* Skip the update inside the loop, this has already been checked by the |
| 35191 |
iv_analyze call earlier. */ |
| 35192 |
if (DF_REF_BB (def) == loop->header) |
| 35193 |
continue; |
| 35194 |
|
| 35195 |
counter_max_last_def = def; |
| 35196 |
break; |
| 35197 |
} |
| 35198 |
|
| 35199 |
if (!counter_max_last_def) |
| 35200 |
return false; |
| 35201 |
|
| 35202 |
rtx counter_max_last_set = single_set (DF_REF_INSN (counter_max_last_def)); |
| 35203 |
|
| 35204 |
if (!counter_max_last_set) |
| 35205 |
return false; |
| 35206 |
|
| 35207 |
/* If we encounter a simple SET from a REG, follow it through. */ |
| 35208 |
if (REG_P (SET_SRC (counter_max_last_set))) |
| 35209 |
{ |
| 35210 |
if (DF_REG_DEF_COUNT (REGNO (SET_SRC (counter_max_last_set))) != 1) |
| 35211 |
return false; |
| 35212 |
|
| 35213 |
counter_max_last_def |
| 35214 |
= DF_REG_DEF_CHAIN (REGNO (SET_SRC (counter_max_last_set))); |
| 35215 |
counter_max_last_set |
| 35216 |
= single_set (DF_REF_INSN (counter_max_last_def)); |
| 35217 |
|
| 35218 |
if (!counter_max_last_set) |
| 35219 |
return false; |
| 35220 |
} |
| 35221 |
|
| 35222 |
/* We are looking for: |
| 35223 |
COUNTER_MAX_LAST_SET = (N + VCTP_STEP - 1) / VCTP_STEP. |
| 35224 |
We currently only support the unsigned VCTP_OP case. */ |
| 35225 |
rtx division = SET_SRC (counter_max_last_set); |
| 35226 |
if (GET_CODE (division) != LSHIFTRT) |
| 35227 |
return false; |
| 35228 |
|
| 35229 |
/* Now check that we are dividing by VCTP_STEP, i.e. the number of lanes. */ |
| 35230 |
rtx divisor = XEXP (division, 1); |
| 35231 |
unsigned vctp_step_cst = abs_hwi (INTVAL (vctp_step)); |
| 35232 |
if (!CONST_INT_P (divisor) |
| 35233 |
|| (1U << INTVAL (divisor) != vctp_step_cst)) |
| 35234 |
return false; |
| 35235 |
|
| 35236 |
rtx dividend = XEXP (division, 0); |
| 35237 |
if (!REG_P (dividend)) |
| 35238 |
/* Subreg? */ |
| 35239 |
return false; |
| 35240 |
|
| 35241 |
/* For now only support the simple case, this only works for unsigned N, any |
| 35242 |
signed N will have further computations to deal with overflow. */ |
| 35243 |
if (DF_REG_DEF_COUNT (REGNO (dividend)) != 1) |
| 35244 |
return false; |
| 35245 |
|
| 35246 |
rtx_insn *dividend_insn = DF_REF_INSN (DF_REG_DEF_CHAIN (REGNO (dividend))); |
| 35247 |
rtx dividend_op = single_set (dividend_insn); |
| 35248 |
if (!dividend_op |
| 35249 |
&& GET_CODE (SET_SRC (dividend_op)) != PLUS) |
| 35250 |
return false; |
| 35251 |
|
| 35252 |
/* Check if PLUS_OP is (VCTP_OP + VAL), where VAL = [1, VCTP_STEP - 1]. */ |
| 35253 |
rtx plus_op = SET_SRC (dividend_op); |
| 35254 |
if (!REG_P (XEXP (plus_op, 0)) |
| 35255 |
|| !CONST_INT_P (XEXP (plus_op, 1)) |
| 35256 |
|| !IN_RANGE (INTVAL (XEXP (plus_op, 1)), 1, vctp_step_cst - 1)) |
| 35257 |
return false; |
| 35258 |
|
| 35259 |
/* VCTP_REG may have been copied before entering the loop, let's see if we can |
| 35260 |
trace such a copy back. If we have more than one reaching definition then |
| 35261 |
bail out as analysis will be too difficult. */ |
| 35262 |
if (DF_REG_DEF_COUNT (REGNO (vctp_reg)) > 2) |
| 35263 |
return false; |
| 35264 |
|
| 35265 |
/* Look for the definition of N. */ |
| 35266 |
for (df_ref def = DF_REG_DEF_CHAIN (REGNO (vctp_reg)); |
| 35267 |
def; |
| 35268 |
def = DF_REF_NEXT_REG (def)) |
| 35269 |
{ |
| 35270 |
if (DF_REF_BB (def) == loop->header) |
| 35271 |
continue; |
| 35272 |
rtx set = single_set (DF_REF_INSN (def)); |
| 35273 |
if (set |
| 35274 |
&& REG_P (SET_SRC (set)) |
| 35275 |
&& !HARD_REGISTER_P (SET_SRC (set))) |
| 35276 |
vctp_reg = SET_SRC (set); |
| 35277 |
} |
| 35278 |
|
| 35279 |
return rtx_equal_p (vctp_reg, XEXP (plus_op, 0)); |
| 35280 |
} |
| 35281 |
|
| 35282 |
/* If we have identified the loop to have an incrementing counter, we need to |
| 35283 |
make sure that it increments by 1 and that the loop is structured correctly: |
| 35284 |
* The counter starts from 0 |
| 35285 |
* The counter terminates at (num_of_elem + num_of_lanes - 1) / num_of_lanes |
| 35286 |
* The vctp insn uses a reg that decrements appropriately in each iteration. |
| 35287 |
*/ |
| 35288 |
|
| 35289 |
static rtx_insn* |
| 35290 |
arm_mve_dlstp_check_inc_counter (loop *loop, rtx_insn* vctp_insn, |
| 35291 |
rtx condconst, rtx condcount) |
| 35292 |
{ |
| 35293 |
rtx vctp_reg = XVECEXP (XEXP (PATTERN (vctp_insn), 1), 0, 0); |
| 35294 |
/* The loop latch has to be empty. When compiling all the known MVE LoLs in |
| 35295 |
user applications, none of those with incrementing counters had any real |
| 35296 |
insns in the loop latch. As such, this function has only been tested with |
| 35297 |
an empty latch and may misbehave or ICE if we somehow get here with an |
| 35298 |
increment in the latch, so, for correctness, error out early. */ |
| 35299 |
if (!empty_block_p (loop->latch)) |
| 35300 |
return NULL; |
| 35301 |
|
| 35302 |
class rtx_iv vctp_reg_iv; |
| 35303 |
/* For loops of DLSTP_TYPE_B, the loop counter is independent of the decrement |
| 35304 |
of the reg used in the vctp_insn. So run iv analysis on that reg. This |
| 35305 |
has to succeed for such loops to be supported. */ |
| 35306 |
if (!iv_analyze (vctp_insn, as_a<scalar_int_mode> (GET_MODE (vctp_reg)), |
| 35307 |
vctp_reg, &vctp_reg_iv)) |
| 35308 |
return NULL; |
| 35309 |
|
| 35310 |
/* Extract the decrementnum of the vctp reg from the iv. This decrementnum |
| 35311 |
is the number of lanes/elements it decrements from the remaining number of |
| 35312 |
lanes/elements to process in the loop, for this reason this is always a |
| 35313 |
negative number, but to simplify later checks we use it's absolute value. */ |
| 35314 |
HOST_WIDE_INT decrementnum = INTVAL (vctp_reg_iv.step); |
| 35315 |
if (decrementnum >= 0) |
| 35316 |
return NULL; |
| 35317 |
decrementnum = abs_hwi (decrementnum); |
| 35318 |
|
| 35319 |
/* Find where both of those are modified in the loop header bb. */ |
| 35320 |
df_ref condcount_reg_set_df = df_bb_regno_only_def_find (loop->header, |
| 35321 |
REGNO (condcount)); |
| 35322 |
df_ref vctp_reg_set_df = df_bb_regno_only_def_find (loop->header, |
| 35323 |
REGNO (vctp_reg)); |
| 35324 |
if (!condcount_reg_set_df || !vctp_reg_set_df) |
| 35325 |
return NULL; |
| 35326 |
rtx condcount_reg_set = single_set (DF_REF_INSN (condcount_reg_set_df)); |
| 35327 |
rtx vctp_reg_set = single_set (DF_REF_INSN (vctp_reg_set_df)); |
| 35328 |
if (!condcount_reg_set || !vctp_reg_set) |
| 35329 |
return NULL; |
| 35330 |
|
| 35331 |
/* Ensure the modification of the vctp reg from df is consistent with |
| 35332 |
the iv and the number of lanes on the vctp insn. */ |
| 35333 |
if (GET_CODE (SET_SRC (vctp_reg_set)) != PLUS |
| 35334 |
|| !REG_P (SET_DEST (vctp_reg_set)) |
| 35335 |
|| !REG_P (XEXP (SET_SRC (vctp_reg_set), 0)) |
| 35336 |
|| REGNO (SET_DEST (vctp_reg_set)) |
| 35337 |
!= REGNO (XEXP (SET_SRC (vctp_reg_set), 0)) |
| 35338 |
|| !CONST_INT_P (XEXP (SET_SRC (vctp_reg_set), 1)) |
| 35339 |
|| INTVAL (XEXP (SET_SRC (vctp_reg_set), 1)) >= 0 |
| 35340 |
|| decrementnum != abs_hwi (INTVAL (XEXP (SET_SRC (vctp_reg_set), 1))) |
| 35341 |
|| decrementnum != arm_mve_get_vctp_lanes (vctp_insn)) |
| 35342 |
return NULL; |
| 35343 |
|
| 35344 |
if (REG_P (condcount) && REG_P (condconst)) |
| 35345 |
{ |
| 35346 |
/* First we need to prove that the loop is going 0..condconst with an |
| 35347 |
inc of 1 in each iteration. */ |
| 35348 |
if (GET_CODE (SET_SRC (condcount_reg_set)) == PLUS |
| 35349 |
&& CONST_INT_P (XEXP (SET_SRC (condcount_reg_set), 1)) |
| 35350 |
&& INTVAL (XEXP (SET_SRC (condcount_reg_set), 1)) == 1) |
| 35351 |
{ |
| 35352 |
rtx counter_reg = SET_DEST (condcount_reg_set); |
| 35353 |
/* Check that the counter did indeed start from zero. */ |
| 35354 |
df_ref this_set = DF_REG_DEF_CHAIN (REGNO (counter_reg)); |
| 35355 |
if (!this_set) |
| 35356 |
return NULL; |
| 35357 |
df_ref last_set_def = DF_REF_NEXT_REG (this_set); |
| 35358 |
if (!last_set_def) |
| 35359 |
return NULL; |
| 35360 |
rtx_insn* last_set_insn = DF_REF_INSN (last_set_def); |
| 35361 |
rtx last_set = single_set (last_set_insn); |
| 35362 |
if (!last_set) |
| 35363 |
return NULL; |
| 35364 |
rtx counter_orig_set; |
| 35365 |
counter_orig_set = SET_SRC (last_set); |
| 35366 |
if (!CONST_INT_P (counter_orig_set) |
| 35367 |
|| (INTVAL (counter_orig_set) != 0)) |
| 35368 |
return NULL; |
| 35369 |
/* And finally check that the target value of the counter, |
| 35370 |
condconst, is of the correct shape. */ |
| 35371 |
if (!arm_mve_check_reg_origin_is_num_elems (loop, condconst, |
| 35372 |
vctp_reg_iv.step, |
| 35373 |
vctp_reg)) |
| 35374 |
return NULL; |
| 35375 |
} |
| 35376 |
else |
| 35377 |
return NULL; |
| 35378 |
} |
| 35379 |
else |
| 35380 |
return NULL; |
| 35381 |
|
| 35382 |
/* Everything looks valid. */ |
| 35383 |
return vctp_insn; |
| 35384 |
} |
| 35385 |
|
| 35386 |
/* Helper function to 'arm_mve_dlstp_check_dec_counter' to make sure DEC_INSN |
| 35387 |
is of the expected form: |
| 35388 |
(set (reg a) (plus (reg a) (const_int))) |
| 35389 |
where (reg a) is the same as CONDCOUNT. |
| 35390 |
Return a rtx with the set if it is in the right format or NULL_RTX |
| 35391 |
otherwise. */ |
| 35392 |
|
| 35393 |
static rtx |
| 35394 |
check_dec_insn (rtx_insn *dec_insn, rtx condcount) |
| 35395 |
{ |
| 35396 |
if (!NONDEBUG_INSN_P (dec_insn)) |
| 35397 |
return NULL_RTX; |
| 35398 |
rtx dec_set = single_set (dec_insn); |
| 35399 |
if (!dec_set |
| 35400 |
|| !REG_P (SET_DEST (dec_set)) |
| 35401 |
|| GET_CODE (SET_SRC (dec_set)) != PLUS |
| 35402 |
|| !REG_P (XEXP (SET_SRC (dec_set), 0)) |
| 35403 |
|| !CONST_INT_P (XEXP (SET_SRC (dec_set), 1)) |
| 35404 |
|| REGNO (SET_DEST (dec_set)) |
| 35405 |
!= REGNO (XEXP (SET_SRC (dec_set), 0)) |
| 35406 |
|| REGNO (SET_DEST (dec_set)) != REGNO (condcount)) |
| 35407 |
return NULL_RTX; |
| 35408 |
|
| 35409 |
return dec_set; |
| 35410 |
} |
| 35411 |
|
| 35412 |
/* Helper function to `arm_mve_loop_valid_for_dlstp`. In the case of a |
| 35413 |
counter that is decrementing, ensure that it is decrementing by the |
| 35414 |
right amount in each iteration and that the target condition is what |
| 35415 |
we expect. */ |
| 35416 |
|
| 35417 |
static rtx_insn* |
| 35418 |
arm_mve_dlstp_check_dec_counter (loop *loop, rtx_insn* vctp_insn, |
| 35419 |
rtx condconst, rtx condcount) |
| 35420 |
{ |
| 35421 |
rtx vctp_reg = XVECEXP (XEXP (PATTERN (vctp_insn), 1), 0, 0); |
| 35422 |
class rtx_iv vctp_reg_iv; |
| 35423 |
HOST_WIDE_INT decrementnum; |
| 35424 |
/* For decrementing loops of DLSTP_TYPE_A, the counter is usually present in the |
| 35425 |
loop latch. Here we simply need to verify that this counter is the same |
| 35426 |
reg that is also used in the vctp_insn and that it is not otherwise |
| 35427 |
modified. */ |
| 35428 |
rtx dec_set = check_dec_insn (BB_END (loop->latch), condcount); |
| 35429 |
/* If not in the loop latch, try to find the decrement in the loop header. */ |
| 35430 |
if (dec_set == NULL_RTX) |
| 35431 |
{ |
| 35432 |
df_ref temp = df_bb_regno_only_def_find (loop->header, REGNO (condcount)); |
| 35433 |
/* If we haven't been able to find the decrement, bail out. */ |
| 35434 |
if (!temp) |
| 35435 |
return NULL; |
| 35436 |
dec_set = check_dec_insn (DF_REF_INSN (temp), condcount); |
| 35437 |
|
| 35438 |
if (dec_set == NULL_RTX) |
| 35439 |
return NULL; |
| 35440 |
} |
| 35441 |
|
| 35442 |
decrementnum = INTVAL (XEXP (SET_SRC (dec_set), 1)); |
| 35443 |
|
| 35444 |
/* This decrementnum is the number of lanes/elements it decrements from the |
| 35445 |
remaining number of lanes/elements to process in the loop, for this reason |
| 35446 |
this is always a negative number, but to simplify later checks we use its |
| 35447 |
absolute value. */ |
| 35448 |
if (decrementnum >= 0) |
| 35449 |
return NULL; |
| 35450 |
decrementnum = -decrementnum; |
| 35451 |
|
| 35452 |
/* If the decrementnum is a 1, then we need to look at the loop vctp_reg and |
| 35453 |
verify that it also decrements correctly. |
| 35454 |
Then, we need to establish that the starting value of the loop decrement |
| 35455 |
originates from the starting value of the vctp decrement. */ |
| 35456 |
if (decrementnum == 1) |
| 35457 |
{ |
| 35458 |
class rtx_iv vctp_reg_iv, condcount_reg_iv; |
| 35459 |
/* The loop counter is found to be independent of the decrement |
| 35460 |
of the reg used in the vctp_insn, again. Ensure that IV analysis |
| 35461 |
succeeds and check the step. */ |
| 35462 |
if (!iv_analyze (vctp_insn, as_a<scalar_int_mode> (GET_MODE (vctp_reg)), |
| 35463 |
vctp_reg, &vctp_reg_iv)) |
| 35464 |
return NULL; |
| 35465 |
/* Ensure it matches the number of lanes of the vctp instruction. */ |
| 35466 |
if (abs (INTVAL (vctp_reg_iv.step)) |
| 35467 |
!= arm_mve_get_vctp_lanes (vctp_insn)) |
| 35468 |
return NULL; |
| 35469 |
|
| 35470 |
if (!arm_mve_check_reg_origin_is_num_elems (loop, condcount, |
| 35471 |
vctp_reg_iv.step, |
| 35472 |
vctp_reg)) |
| 35473 |
return NULL; |
| 35474 |
} |
| 35475 |
/* If the decrements are the same, then the situation is simple: either they |
| 35476 |
are also the same reg, which is safe, or they are different registers, in |
| 35477 |
which case makse sure that there is a only simple SET from one to the |
| 35478 |
other inside the loop.*/ |
| 35479 |
else if (decrementnum == arm_mve_get_vctp_lanes (vctp_insn)) |
| 35480 |
{ |
| 35481 |
if (REGNO (condcount) != REGNO (vctp_reg)) |
| 35482 |
{ |
| 35483 |
/* It wasn't the same reg, but it could be behild a |
| 35484 |
(set (vctp_reg) (condcount)), so instead find where |
| 35485 |
the VCTP insn is DEF'd inside the loop. */ |
| 35486 |
rtx_insn *vctp_reg_insn |
| 35487 |
= DF_REF_INSN (df_bb_regno_only_def_find (loop->header, |
| 35488 |
REGNO (vctp_reg))); |
| 35489 |
rtx vctp_reg_set = single_set (vctp_reg_insn); |
| 35490 |
/* This must just be a simple SET from the condcount. */ |
| 35491 |
if (!vctp_reg_set |
| 35492 |
|| !REG_P (SET_DEST (vctp_reg_set)) |
| 35493 |
|| !REG_P (SET_SRC (vctp_reg_set)) |
| 35494 |
|| REGNO (SET_SRC (vctp_reg_set)) != REGNO (condcount)) |
| 35495 |
return NULL; |
| 35496 |
} |
| 35497 |
} |
| 35498 |
else |
| 35499 |
return NULL; |
| 35500 |
|
| 35501 |
/* We now only need to find out that the loop terminates with a LE |
| 35502 |
zero condition. If condconst is a const_int, then this is easy. |
| 35503 |
If its a REG, look at the last condition+jump in a bb before |
| 35504 |
the loop, because that usually will have a branch jumping over |
| 35505 |
the loop header. */ |
| 35506 |
rtx_insn *jump_insn = BB_END (loop->header); |
| 35507 |
if (CONST_INT_P (condconst) |
| 35508 |
&& !(INTVAL (condconst) == 0 && JUMP_P (jump_insn) |
| 35509 |
&& GET_CODE (XEXP (PATTERN (jump_insn), 1)) == IF_THEN_ELSE |
| 35510 |
&& (GET_CODE (XEXP (XEXP (PATTERN (jump_insn), 1), 0)) == NE |
| 35511 |
||GET_CODE (XEXP (XEXP (PATTERN (jump_insn), 1), 0)) == GT))) |
| 35512 |
return NULL; |
| 35513 |
else if (REG_P (condconst)) |
| 35514 |
{ |
| 35515 |
basic_block preheader_b = loop_preheader_edge (loop)->src; |
| 35516 |
if (!single_pred_p (preheader_b)) |
| 35517 |
return NULL; |
| 35518 |
basic_block pre_loop_bb = single_pred (preheader_b); |
| 35519 |
|
| 35520 |
rtx initial_compare = NULL_RTX; |
| 35521 |
if (!(prev_nonnote_nondebug_insn_bb (BB_END (pre_loop_bb)) |
| 35522 |
&& INSN_P (prev_nonnote_nondebug_insn_bb (BB_END (pre_loop_bb))))) |
| 35523 |
return NULL; |
| 35524 |
else |
| 35525 |
initial_compare |
| 35526 |
= single_set (prev_nonnote_nondebug_insn_bb (BB_END (pre_loop_bb))); |
| 35527 |
if (!(initial_compare |
| 35528 |
&& cc_register (SET_DEST (initial_compare), VOIDmode) |
| 35529 |
&& GET_CODE (SET_SRC (initial_compare)) == COMPARE |
| 35530 |
&& CONST_INT_P (XEXP (SET_SRC (initial_compare), 1)) |
| 35531 |
&& INTVAL (XEXP (SET_SRC (initial_compare), 1)) == 0)) |
| 35532 |
return NULL; |
| 35533 |
|
| 35534 |
/* Usually this is a LE condition, but it can also just be a GT or an EQ |
| 35535 |
condition (if the value is unsigned or the compiler knows its not negative) */ |
| 35536 |
rtx_insn *loop_jumpover = BB_END (pre_loop_bb); |
| 35537 |
if (!(JUMP_P (loop_jumpover) |
| 35538 |
&& GET_CODE (XEXP (PATTERN (loop_jumpover), 1)) == IF_THEN_ELSE |
| 35539 |
&& (GET_CODE (XEXP (XEXP (PATTERN (loop_jumpover), 1), 0)) == LE |
| 35540 |
|| GET_CODE (XEXP (XEXP (PATTERN (loop_jumpover), 1), 0)) == GT |
| 35541 |
|| GET_CODE (XEXP (XEXP (PATTERN (loop_jumpover), 1), 0)) == EQ))) |
| 35542 |
return NULL; |
| 35543 |
} |
| 35544 |
|
| 35545 |
/* Everything looks valid. */ |
| 35546 |
return vctp_insn; |
| 35547 |
} |
| 35548 |
|
| 35549 |
/* Function to check a loop's structure to see if it is a valid candidate for |
| 35550 |
an MVE Tail Predicated Low-Overhead Loop. Returns the loop's VCTP_INSN if |
| 35551 |
it is valid, or NULL if it isn't. */ |
| 35552 |
|
| 35553 |
static rtx_insn* |
| 35554 |
arm_mve_loop_valid_for_dlstp (loop *loop) |
| 35555 |
{ |
| 35556 |
/* Doloop can only be done "elementwise" with predicated dlstp/letp if it |
| 35557 |
contains a VCTP on the number of elements processed by the loop. |
| 35558 |
Find the VCTP predicate generation inside the loop body BB. */ |
| 35559 |
rtx_insn *vctp_insn = arm_mve_get_loop_vctp (loop->header); |
| 35560 |
if (!vctp_insn) |
| 35561 |
return NULL; |
| 35562 |
|
| 35563 |
/* We only support two loop forms for tail predication: |
| 35564 |
DLSTP_TYPE_A) Loops of the form: |
| 35565 |
int num_of_lanes = 128 / elem_size; |
| 35566 |
while (num_of_elem > 0) |
| 35567 |
{ |
| 35568 |
p = vctp<size> (num_of_elem); |
| 35569 |
num_of_elem -= num_of_lanes; |
| 35570 |
} |
| 35571 |
DLSTP_TYPE_B) Loops of the form: |
| 35572 |
int num_of_lanes = 128 / elem_size; |
| 35573 |
int num_of_iters = (num_of_elem + num_of_lanes - 1) / num_of_lanes; |
| 35574 |
for (i = 0; i < num_of_iters; i++) |
| 35575 |
{ |
| 35576 |
p = vctp<size> (num_of_elem); |
| 35577 |
num_of_elem -= num_of_lanes; |
| 35578 |
} |
| 35579 |
|
| 35580 |
Then, depending on the type of loop above we need will need to do |
| 35581 |
different sets of checks. */ |
| 35582 |
iv_analysis_loop_init (loop); |
| 35583 |
|
| 35584 |
/* In order to find out if the loop is of DLSTP_TYPE_A or DLSTP_TYPE_B above |
| 35585 |
look for the loop counter: it will either be incrementing by one per |
| 35586 |
iteration or it will be decrementing by num_of_lanes. We can find the |
| 35587 |
loop counter in the condition at the end of the loop. */ |
| 35588 |
rtx_insn *loop_cond = prev_nonnote_nondebug_insn_bb (BB_END (loop->header)); |
| 35589 |
if (!(cc_register (XEXP (PATTERN (loop_cond), 0), VOIDmode) |
| 35590 |
&& GET_CODE (XEXP (PATTERN (loop_cond), 1)) == COMPARE)) |
| 35591 |
return NULL; |
| 35592 |
|
| 35593 |
/* The operands in the condition: Try to identify which one is the |
| 35594 |
constant and which is the counter and run IV analysis on the latter. */ |
| 35595 |
rtx cond_arg_1 = XEXP (XEXP (PATTERN (loop_cond), 1), 0); |
| 35596 |
rtx cond_arg_2 = XEXP (XEXP (PATTERN (loop_cond), 1), 1); |
| 35597 |
|
| 35598 |
rtx loop_cond_constant; |
| 35599 |
rtx loop_counter; |
| 35600 |
class rtx_iv cond_counter_iv, cond_temp_iv; |
| 35601 |
|
| 35602 |
if (CONST_INT_P (cond_arg_1)) |
| 35603 |
{ |
| 35604 |
/* cond_arg_1 is the constant and cond_arg_2 is the counter. */ |
| 35605 |
loop_cond_constant = cond_arg_1; |
| 35606 |
loop_counter = cond_arg_2; |
| 35607 |
iv_analyze (loop_cond, as_a<scalar_int_mode> (GET_MODE (cond_arg_2)), |
| 35608 |
cond_arg_2, &cond_counter_iv); |
| 35609 |
} |
| 35610 |
else if (CONST_INT_P (cond_arg_2)) |
| 35611 |
{ |
| 35612 |
/* cond_arg_2 is the constant and cond_arg_1 is the counter. */ |
| 35613 |
loop_cond_constant = cond_arg_2; |
| 35614 |
loop_counter = cond_arg_1; |
| 35615 |
iv_analyze (loop_cond, as_a<scalar_int_mode> (GET_MODE (cond_arg_1)), |
| 35616 |
cond_arg_1, &cond_counter_iv); |
| 35617 |
} |
| 35618 |
else if (REG_P (cond_arg_1) && REG_P (cond_arg_2)) |
| 35619 |
{ |
| 35620 |
/* If both operands to the compare are REGs, we can safely |
| 35621 |
run IV analysis on both and then determine which is the |
| 35622 |
constant by looking at the step. |
| 35623 |
First assume cond_arg_1 is the counter. */ |
| 35624 |
loop_counter = cond_arg_1; |
| 35625 |
loop_cond_constant = cond_arg_2; |
| 35626 |
iv_analyze (loop_cond, as_a<scalar_int_mode> (GET_MODE (cond_arg_1)), |
| 35627 |
cond_arg_1, &cond_counter_iv); |
| 35628 |
iv_analyze (loop_cond, as_a<scalar_int_mode> (GET_MODE (cond_arg_2)), |
| 35629 |
cond_arg_2, &cond_temp_iv); |
| 35630 |
|
| 35631 |
/* Look at the steps and swap around the rtx's if needed. Error out if |
| 35632 |
one of them cannot be identified as constant. */ |
| 35633 |
if (!CONST_INT_P (cond_counter_iv.step) || !CONST_INT_P (cond_temp_iv.step)) |
| 35634 |
return NULL; |
| 35635 |
if (INTVAL (cond_counter_iv.step) != 0 && INTVAL (cond_temp_iv.step) != 0) |
| 35636 |
return NULL; |
| 35637 |
if (INTVAL (cond_counter_iv.step) == 0 && INTVAL (cond_temp_iv.step) != 0) |
| 35638 |
{ |
| 35639 |
loop_counter = cond_arg_2; |
| 35640 |
loop_cond_constant = cond_arg_1; |
| 35641 |
cond_counter_iv = cond_temp_iv; |
| 35642 |
} |
| 35643 |
} |
| 35644 |
else |
| 35645 |
return NULL; |
| 35646 |
|
| 35647 |
if (!REG_P (loop_counter)) |
| 35648 |
return NULL; |
| 35649 |
if (!(REG_P (loop_cond_constant) || CONST_INT_P (loop_cond_constant))) |
| 35650 |
return NULL; |
| 35651 |
|
| 35652 |
/* Now we have extracted the IV step of the loop counter, call the |
| 35653 |
appropriate checking function. */ |
| 35654 |
if (INTVAL (cond_counter_iv.step) > 0) |
| 35655 |
return arm_mve_dlstp_check_inc_counter (loop, vctp_insn, |
| 35656 |
loop_cond_constant, loop_counter); |
| 35657 |
else if (INTVAL (cond_counter_iv.step) < 0) |
| 35658 |
return arm_mve_dlstp_check_dec_counter (loop, vctp_insn, |
| 35659 |
loop_cond_constant, loop_counter); |
| 35660 |
else |
| 35661 |
return NULL; |
| 35662 |
} |
| 35663 |
|
| 35664 |
/* Predict whether the given loop in gimple will be transformed in the RTL |
| 35665 |
doloop_optimize pass. It could be argued that turning large enough loops |
| 35666 |
into low-overhead loops would not show a signficant performance boost. |
| 35667 |
However, in the case of tail predication we would still avoid using VPT/VPST |
| 35668 |
instructions inside the loop, and in either case using low-overhead loops |
| 35669 |
would not be detrimental, so we decided to not consider size, avoiding the |
| 35670 |
need of a heuristic to determine what an appropriate size boundary is. */ |
| 35671 |
|
| 35672 |
static bool |
| 35673 |
arm_predict_doloop_p (struct loop *loop) |
| 35674 |
{ |
| 35675 |
gcc_assert (loop); |
| 35676 |
/* On arm, targetm.can_use_doloop_p is actually |
| 35677 |
can_use_doloop_if_innermost. Ensure the loop is innermost, |
| 35678 |
it is valid and as per arm_target_bb_ok_for_lob and the |
| 35679 |
correct architecture flags are enabled. */ |
| 35680 |
if (!(TARGET_HAVE_LOB && optimize > 0)) |
| 35681 |
{ |
| 35682 |
if (dump_file && (dump_flags & TDF_DETAILS)) |
| 35683 |
fprintf (dump_file, "Predict doloop failure due to" |
| 35684 |
" target architecture or optimisation flags.\n"); |
| 35685 |
return false; |
| 35686 |
} |
| 35687 |
else if (loop->inner != NULL) |
| 35688 |
{ |
| 35689 |
if (dump_file && (dump_flags & TDF_DETAILS)) |
| 35690 |
fprintf (dump_file, "Predict doloop failure due to" |
| 35691 |
" loop nesting.\n"); |
| 35692 |
return false; |
| 35693 |
} |
| 35694 |
else if (!arm_target_bb_ok_for_lob (loop->header->next_bb)) |
| 35695 |
{ |
| 35696 |
if (dump_file && (dump_flags & TDF_DETAILS)) |
| 35697 |
fprintf (dump_file, "Predict doloop failure due to" |
| 35698 |
" loop bb complexity.\n"); |
| 35699 |
return false; |
| 35700 |
} |
| 35701 |
else |
| 35702 |
{ |
| 35703 |
gimple_stmt_iterator gsi = gsi_after_labels (loop->header); |
| 35704 |
while (!gsi_end_p (gsi)) |
| 35705 |
{ |
| 35706 |
if (is_gimple_call (gsi_stmt (gsi)) |
| 35707 |
&& !gimple_call_builtin_p (gsi_stmt (gsi))) |
| 35708 |
{ |
| 35709 |
if (dump_file && (dump_flags & TDF_DETAILS)) |
| 35710 |
fprintf (dump_file, "Predict doloop failure due to" |
| 35711 |
" call in loop.\n"); |
| 35712 |
return false; |
| 35713 |
} |
| 35714 |
gsi_next (&gsi); |
| 35715 |
} |
| 35716 |
} |
| 35717 |
|
| 35718 |
return true; |
| 35719 |
} |
| 35720 |
|
| 35721 |
/* Implement targetm.loop_unroll_adjust. Use this to block unrolling of loops |
| 35722 |
that may later be turned into MVE Tail Predicated Low Overhead Loops. The |
| 35723 |
performance benefit of an MVE LoL is likely to be much higher than that of |
| 35724 |
the unrolling. */ |
| 35725 |
|
| 35726 |
unsigned |
| 35727 |
arm_loop_unroll_adjust (unsigned nunroll, struct loop *loop) |
| 35728 |
{ |
| 35729 |
if (TARGET_HAVE_MVE |
| 35730 |
&& arm_target_bb_ok_for_lob (loop->latch) |
| 35731 |
&& arm_mve_loop_valid_for_dlstp (loop)) |
| 35732 |
return 0; |
| 35733 |
else |
| 35734 |
return nunroll; |
| 35735 |
} |
| 35736 |
|
| 35737 |
/* Function to hadle emitting a VPT-unpredicated version of a VPT-predicated |
| 35738 |
insn to a sequence. */ |
| 35739 |
|
| 35740 |
static bool |
| 35741 |
arm_emit_mve_unpredicated_insn_to_seq (rtx_insn* insn) |
| 35742 |
{ |
| 35743 |
rtx insn_vpr_reg_operand = arm_get_required_vpr_reg_param (insn); |
| 35744 |
int new_icode = get_attr_mve_unpredicated_insn (insn); |
| 35745 |
if (!in_sequence_p () |
| 35746 |
|| !MVE_VPT_PREDICATED_INSN_P (insn) |
| 35747 |
|| (!insn_vpr_reg_operand) |
| 35748 |
|| (!new_icode)) |
| 35749 |
return false; |
| 35750 |
|
| 35751 |
extract_insn (insn); |
| 35752 |
rtx arr[8]; |
| 35753 |
int j = 0; |
| 35754 |
|
| 35755 |
/* When transforming a VPT-predicated instruction into its unpredicated |
| 35756 |
equivalent we need to drop the VPR operand and we may need to also drop a |
| 35757 |
merge "vuninit" input operand, depending on the instruction pattern. Here |
| 35758 |
ensure that we have at most a two-operand difference between the two |
| 35759 |
instrunctions. */ |
| 35760 |
int n_operands_diff |
| 35761 |
= recog_data.n_operands - insn_data[new_icode].n_operands; |
| 35762 |
if (!(n_operands_diff > 0 && n_operands_diff <= 2)) |
| 35763 |
return false; |
| 35764 |
|
| 35765 |
rtx move = NULL_RTX; |
| 35766 |
/* Then, loop through the operands of the predicated |
| 35767 |
instruction, and retain the ones that map to the |
| 35768 |
unpredicated instruction. */ |
| 35769 |
for (int i = 0; i < recog_data.n_operands; i++) |
| 35770 |
{ |
| 35771 |
/* Ignore the VPR and, if needed, the vuninit |
| 35772 |
operand. */ |
| 35773 |
if (insn_vpr_reg_operand == recog_data.operand[i]) |
| 35774 |
continue; |
| 35775 |
if (n_operands_diff == 2 |
| 35776 |
&& !strcmp (recog_data.constraints[i], "0")) |
| 35777 |
{ |
| 35778 |
move = gen_rtx_SET (arr[0], recog_data.operand[i]); |
| 35779 |
arr[0] = recog_data.operand[i]; |
| 35780 |
} |
| 35781 |
else |
| 35782 |
arr[j++] = recog_data.operand[i]; |
| 35783 |
} |
| 35784 |
|
| 35785 |
/* Finally, emit the upredicated instruction. */ |
| 35786 |
rtx_insn *new_insn; |
| 35787 |
switch (j) |
| 35788 |
{ |
| 35789 |
case 1: |
| 35790 |
new_insn = emit_insn (GEN_FCN (new_icode) (arr[0])); |
| 35791 |
break; |
| 35792 |
case 2: |
| 35793 |
new_insn = emit_insn (GEN_FCN (new_icode) (arr[0], arr[1])); |
| 35794 |
break; |
| 35795 |
case 3: |
| 35796 |
new_insn = emit_insn (GEN_FCN (new_icode) (arr[0], arr[1], arr[2])); |
| 35797 |
break; |
| 35798 |
case 4: |
| 35799 |
new_insn = emit_insn (GEN_FCN (new_icode) (arr[0], arr[1], arr[2], |
| 35800 |
arr[3])); |
| 35801 |
break; |
| 35802 |
case 5: |
| 35803 |
new_insn = emit_insn (GEN_FCN (new_icode) (arr[0], arr[1], arr[2], |
| 35804 |
arr[3], arr[4])); |
| 35805 |
break; |
| 35806 |
case 6: |
| 35807 |
new_insn = emit_insn (GEN_FCN (new_icode) (arr[0], arr[1], arr[2], |
| 35808 |
arr[3], arr[4], arr[5])); |
| 35809 |
break; |
| 35810 |
case 7: |
| 35811 |
new_insn = emit_insn (GEN_FCN (new_icode) (arr[0], arr[1], arr[2], |
| 35812 |
arr[3], arr[4], arr[5], |
| 35813 |
arr[6])); |
| 35814 |
break; |
| 35815 |
default: |
| 35816 |
gcc_unreachable (); |
| 35817 |
} |
| 35818 |
INSN_LOCATION (new_insn) = INSN_LOCATION (insn); |
| 35819 |
if (move) |
| 35820 |
{ |
| 35821 |
new_insn = emit_insn (move); |
| 35822 |
INSN_LOCATION (new_insn) = INSN_LOCATION (insn); |
| 35823 |
} |
| 35824 |
return true; |
| 35825 |
} |
| 35826 |
|
| 35827 |
/* Return TRUE if INSN defines a MVE vector operand that has zeroed |
| 35828 |
tail-predicated lanes. This is either true if: |
| 35829 |
* INSN is predicated by VCTP_VPR_GENERATED and the 'invalid lanes' operand |
| 35830 |
is in the PROPS_ZERO_SET, |
| 35831 |
* all MVE vector operands are in the PROPS_ZERO_SET |
| 35832 |
*/ |
| 35833 |
|
| 35834 |
static bool |
| 35835 |
arm_mve_propagate_zero_pred_p (vec <rtx_insn *> *props_zero_set, |
| 35836 |
rtx_insn *insn, rtx vctp_vpr_generated) |
| 35837 |
{ |
| 35838 |
if (arm_mve_load_store_insn_p (insn, DL_USAGE_READ)) |
| 35839 |
return true; |
| 35840 |
if (arm_mve_load_store_insn_p (insn, DL_USAGE_WRITE)) |
| 35841 |
return false; |
| 35842 |
|
| 35843 |
int inactive_idx = -1; |
| 35844 |
|
| 35845 |
extract_insn (insn); |
| 35846 |
/* If INSN is predicated by VCTP_VPR_GENERATED, then all tail-predicated |
| 35847 |
lanes will keep the value that is in the 'invalid lanes' register which we |
| 35848 |
identify by the "0" constraint, to ensure it is the same as the 'result' |
| 35849 |
register of this instruction. */ |
| 35850 |
if (arm_mve_insn_predicated_by (insn, vctp_vpr_generated)) |
| 35851 |
{ |
| 35852 |
for (int i = 0; i < recog_data.n_operands; i++) |
| 35853 |
{ |
| 35854 |
if (strcmp (recog_data.constraints[i], "0") == 0 |
| 35855 |
&& VALID_MVE_MODE (GET_MODE (recog_data.operand[i]))) |
| 35856 |
{ |
| 35857 |
inactive_idx = i; |
| 35858 |
break; |
| 35859 |
} |
| 35860 |
} |
| 35861 |
} |
| 35862 |
|
| 35863 |
if (inactive_idx > 0) |
| 35864 |
{ |
| 35865 |
rtx op = recog_data.operand[inactive_idx]; |
| 35866 |
rtx_insn *def_insn = arm_last_vect_def_insn (op, insn); |
| 35867 |
return def_insn != NULL_RTX && props_zero_set->contains (def_insn); |
| 35868 |
} |
| 35869 |
|
| 35870 |
/* If this instruction is not predicated by VCTP_VPR_GENERATED, then we must |
| 35871 |
check that all vector operands have zeroed tail-predicated lanes, and that |
| 35872 |
it has at least one vector operand. */ |
| 35873 |
bool at_least_one_vector = false; |
| 35874 |
df_ref insn_uses; |
| 35875 |
FOR_EACH_INSN_USE (insn_uses, insn) |
| 35876 |
{ |
| 35877 |
rtx reg = DF_REF_REG (insn_uses); |
| 35878 |
if (!VALID_MVE_MODE (GET_MODE (reg))) |
| 35879 |
continue; |
| 35880 |
|
| 35881 |
rtx_insn *def_insn = arm_last_vect_def_insn (reg, insn); |
| 35882 |
if (def_insn && props_zero_set->contains (def_insn)) |
| 35883 |
at_least_one_vector |= true; |
| 35884 |
else |
| 35885 |
return false; |
| 35886 |
|
| 35887 |
} |
| 35888 |
return at_least_one_vector; |
| 35889 |
} |
| 35890 |
|
| 35891 |
|
| 35892 |
/* Attempt to transform the loop contents of loop basic block from VPT |
| 35893 |
predicated insns into unpredicated insns for a dlstp/letp loop. Returns |
| 35894 |
the number to decrement from the total number of elements each iteration. |
| 35895 |
Returns 1 if tail predication can not be performed and fallback to scalar |
| 35896 |
low-overhead loops. */ |
| 35897 |
|
| 35898 |
int |
| 35899 |
arm_attempt_dlstp_transform (rtx label) |
| 35900 |
{ |
| 35901 |
if (!dlstp_enabled) |
| 35902 |
return 1; |
| 35903 |
|
| 35904 |
basic_block body = single_succ (BLOCK_FOR_INSN (label)); |
| 35905 |
|
| 35906 |
/* Ensure that the bb is within a loop that has all required metadata. */ |
| 35907 |
if (!body->loop_father || !body->loop_father->header |
| 35908 |
|| !body->loop_father->simple_loop_desc) |
| 35909 |
return 1; |
| 35910 |
|
| 35911 |
loop *loop = body->loop_father; |
| 35912 |
/* Instruction that sets the predicate mask depending on how many elements |
| 35913 |
are left to process. */ |
| 35914 |
rtx_insn *vctp_insn = arm_mve_loop_valid_for_dlstp (loop); |
| 35915 |
if (!vctp_insn) |
| 35916 |
return 1; |
| 35917 |
|
| 35918 |
gcc_assert (single_set (vctp_insn)); |
| 35919 |
|
| 35920 |
rtx vctp_vpr_generated = single_set (vctp_insn); |
| 35921 |
if (!vctp_vpr_generated) |
| 35922 |
return 1; |
| 35923 |
|
| 35924 |
vctp_vpr_generated = SET_DEST (vctp_vpr_generated); |
| 35925 |
|
| 35926 |
if (!vctp_vpr_generated || !REG_P (vctp_vpr_generated) |
| 35927 |
|| !VALID_MVE_PRED_MODE (GET_MODE (vctp_vpr_generated))) |
| 35928 |
return 1; |
| 35929 |
|
| 35930 |
/* decrementunum is already known to be valid at this point. */ |
| 35931 |
int decrementnum = arm_mve_get_vctp_lanes (vctp_insn); |
| 35932 |
|
| 35933 |
rtx_insn *insn = 0; |
| 35934 |
rtx_insn *cur_insn = 0; |
| 35935 |
rtx_insn *seq; |
| 35936 |
auto_vec <rtx_insn *> props_zero_set; |
| 35937 |
|
| 35938 |
/* Scan through the insns in the loop bb and emit the transformed bb |
| 35939 |
insns to a sequence. */ |
| 35940 |
start_sequence (); |
| 35941 |
FOR_BB_INSNS (body, insn) |
| 35942 |
{ |
| 35943 |
if (GET_CODE (insn) == CODE_LABEL || NOTE_INSN_BASIC_BLOCK_P (insn)) |
| 35944 |
continue; |
| 35945 |
else if (NOTE_P (insn)) |
| 35946 |
emit_note ((enum insn_note)NOTE_KIND (insn)); |
| 35947 |
else if (DEBUG_INSN_P (insn)) |
| 35948 |
emit_debug_insn (PATTERN (insn)); |
| 35949 |
else if (!INSN_P (insn)) |
| 35950 |
{ |
| 35951 |
end_sequence (); |
| 35952 |
return 1; |
| 35953 |
} |
| 35954 |
/* If the transformation is successful we no longer need the vctp |
| 35955 |
instruction. */ |
| 35956 |
else if (insn == vctp_insn) |
| 35957 |
continue; |
| 35958 |
/* If the insn pattern requires the use of the VPR value from the |
| 35959 |
vctp as an input parameter for predication. */ |
| 35960 |
else if (arm_mve_insn_predicated_by (insn, vctp_vpr_generated)) |
| 35961 |
{ |
| 35962 |
/* Check whether this INSN propagates the zeroed tail-predication |
| 35963 |
lanes. */ |
| 35964 |
if (arm_mve_propagate_zero_pred_p (&props_zero_set, insn, |
| 35965 |
vctp_vpr_generated)) |
| 35966 |
props_zero_set.safe_push (insn); |
| 35967 |
bool success = arm_emit_mve_unpredicated_insn_to_seq (insn); |
| 35968 |
if (!success) |
| 35969 |
{ |
| 35970 |
end_sequence (); |
| 35971 |
return 1; |
| 35972 |
} |
| 35973 |
} |
| 35974 |
/* If the insn isn't VPT predicated on vctp_vpr_generated, we need to |
| 35975 |
make sure that it is still valid within the dlstp/letp loop. */ |
| 35976 |
else |
| 35977 |
{ |
| 35978 |
/* If this instruction USE-s the vctp_vpr_generated other than for |
| 35979 |
predication, this blocks the transformation as we are not allowed |
| 35980 |
to optimise the VPR value away. */ |
| 35981 |
df_ref insn_uses = NULL; |
| 35982 |
FOR_EACH_INSN_USE (insn_uses, insn) |
| 35983 |
{ |
| 35984 |
if (reg_overlap_mentioned_p (vctp_vpr_generated, |
| 35985 |
DF_REF_REG (insn_uses))) |
| 35986 |
{ |
| 35987 |
end_sequence (); |
| 35988 |
return 1; |
| 35989 |
} |
| 35990 |
} |
| 35991 |
/* If within the loop we have an MVE vector instruction that is |
| 35992 |
unpredicated, the dlstp/letp looping will add implicit |
| 35993 |
predication to it. This will result in a change in behaviour |
| 35994 |
of the instruction, so we need to find out if any instructions |
| 35995 |
that feed into the current instruction were implicitly |
| 35996 |
predicated. */ |
| 35997 |
if (MVE_VPT_PREDICABLE_INSN_P (insn) |
| 35998 |
&& !arm_mve_impl_predicated_p (&props_zero_set, insn, |
| 35999 |
vctp_vpr_generated)) |
| 36000 |
{ |
| 36001 |
end_sequence (); |
| 36002 |
return 1; |
| 36003 |
} |
| 36004 |
emit_insn (PATTERN (insn)); |
| 36005 |
} |
| 36006 |
} |
| 36007 |
seq = get_insns (); |
| 36008 |
end_sequence (); |
| 36009 |
|
| 36010 |
/* Re-write the entire BB contents with the transformed |
| 36011 |
sequence. */ |
| 36012 |
FOR_BB_INSNS_SAFE (body, insn, cur_insn) |
| 36013 |
if (!(GET_CODE (insn) == CODE_LABEL || NOTE_INSN_BASIC_BLOCK_P (insn))) |
| 36014 |
delete_insn (insn); |
| 36015 |
|
| 36016 |
emit_insn_after (seq, BB_END (body)); |
| 36017 |
|
| 36018 |
/* The transformation has succeeded, so now modify the "count" |
| 36019 |
(a.k.a. niter_expr) for the middle-end. Also set noloop_assumptions |
| 36020 |
to NULL to stop the middle-end from making assumptions about the |
| 36021 |
number of iterations. */ |
| 36022 |
simple_loop_desc (body->loop_father)->niter_expr |
| 36023 |
= XVECEXP (SET_SRC (PATTERN (vctp_insn)), 0, 0); |
| 36024 |
simple_loop_desc (body->loop_father)->noloop_assumptions = NULL_RTX; |
| 36025 |
return decrementnum; |
| 36026 |
} |
| 36027 |
|
| 36028 |
#if CHECKING_P |
| 36029 |
namespace selftest { |
| 36030 |
|
| 36031 |
/* Scan the static data tables generated by parsecpu.awk looking for |
| 36032 |
potential issues with the data. We primarily check for |
| 36033 |
inconsistencies in the option extensions at present (extensions |
| 36034 |
that duplicate others but aren't marked as aliases). Furthermore, |
| 36035 |
for correct canonicalization later options must never be a subset |
| 36036 |
of an earlier option. Any extension should also only specify other |
| 36037 |
feature bits and never an architecture bit. The architecture is inferred |
| 36038 |
from the declaration of the extension. */ |
| 36039 |
static void |
| 36040 |
arm_test_cpu_arch_data (void) |
| 36041 |
{ |
| 36042 |
const arch_option *arch; |
| 36043 |
const cpu_option *cpu; |
| 36044 |
auto_sbitmap target_isa (isa_num_bits); |
| 36045 |
auto_sbitmap isa1 (isa_num_bits); |
| 36046 |
auto_sbitmap isa2 (isa_num_bits); |
| 36047 |
|
| 36048 |
for (arch = all_architectures; arch->common.name != NULL; ++arch) |
| 36049 |
{ |
| 36050 |
const cpu_arch_extension *ext1, *ext2; |
| 36051 |
|
| 36052 |
if (arch->common.extensions == NULL) |
| 36053 |
continue; |
| 36054 |
|
| 36055 |
arm_initialize_isa (target_isa, arch->common.isa_bits); |
| 36056 |
|
| 36057 |
for (ext1 = arch->common.extensions; ext1->name != NULL; ++ext1) |
| 36058 |
{ |
| 36059 |
if (ext1->alias) |
| 36060 |
continue; |
| 36061 |
|
| 36062 |
arm_initialize_isa (isa1, ext1->isa_bits); |
| 36063 |
for (ext2 = ext1 + 1; ext2->name != NULL; ++ext2) |
| 36064 |
{ |
| 36065 |
if (ext2->alias || ext1->remove != ext2->remove) |
| 36066 |
continue; |
| 36067 |
|
| 36068 |
arm_initialize_isa (isa2, ext2->isa_bits); |
| 36069 |
/* If the option is a subset of the parent option, it doesn't |
| 36070 |
add anything and so isn't useful. */ |
| 36071 |
ASSERT_TRUE (!bitmap_subset_p (isa2, isa1)); |
| 36072 |
|
| 36073 |
/* If the extension specifies any architectural bits then |
| 36074 |
disallow it. Extensions should only specify feature bits. */ |
| 36075 |
ASSERT_TRUE (!bitmap_intersect_p (isa2, target_isa)); |
| 36076 |
} |
| 36077 |
} |
| 36078 |
} |
| 36079 |
|
| 36080 |
for (cpu = all_cores; cpu->common.name != NULL; ++cpu) |
| 36081 |
{ |
| 36082 |
const cpu_arch_extension *ext1, *ext2; |
| 36083 |
|
| 36084 |
if (cpu->common.extensions == NULL) |
| 36085 |
continue; |
| 36086 |
|
| 36087 |
arm_initialize_isa (target_isa, arch->common.isa_bits); |
| 36088 |
|
| 36089 |
for (ext1 = cpu->common.extensions; ext1->name != NULL; ++ext1) |
| 36090 |
{ |
| 36091 |
if (ext1->alias) |
| 36092 |
continue; |
| 36093 |
|
| 36094 |
arm_initialize_isa (isa1, ext1->isa_bits); |
| 36095 |
for (ext2 = ext1 + 1; ext2->name != NULL; ++ext2) |
| 36096 |
{ |
| 36097 |
if (ext2->alias || ext1->remove != ext2->remove) |
| 36098 |
continue; |
| 36099 |
|
| 36100 |
arm_initialize_isa (isa2, ext2->isa_bits); |
| 36101 |
/* If the option is a subset of the parent option, it doesn't |
| 36102 |
add anything and so isn't useful. */ |
| 36103 |
ASSERT_TRUE (!bitmap_subset_p (isa2, isa1)); |
| 36104 |
|
| 36105 |
/* If the extension specifies any architectural bits then |
| 36106 |
disallow it. Extensions should only specify feature bits. */ |
| 36107 |
ASSERT_TRUE (!bitmap_intersect_p (isa2, target_isa)); |
| 36108 |
} |
| 36109 |
} |
| 36110 |
} |
| 36111 |
} |
| 36112 |
|
| 36113 |
/* Scan the static data tables generated by parsecpu.awk looking for |
| 36114 |
potential issues with the data. Here we check for consistency between the |
| 36115 |
fpu bits, in particular we check that ISA_ALL_FPU_INTERNAL does not contain |
| 36116 |
a feature bit that is not defined by any FPU flag. */ |
| 36117 |
static void |
| 36118 |
arm_test_fpu_data (void) |
| 36119 |
{ |
| 36120 |
auto_sbitmap isa_all_fpubits_internal (isa_num_bits); |
| 36121 |
auto_sbitmap fpubits (isa_num_bits); |
| 36122 |
auto_sbitmap tmpset (isa_num_bits); |
| 36123 |
|
| 36124 |
static const enum isa_feature fpu_bitlist_internal[] |
| 36125 |
= { ISA_ALL_FPU_INTERNAL, isa_nobit }; |
| 36126 |
arm_initialize_isa (isa_all_fpubits_internal, fpu_bitlist_internal); |
| 36127 |
|
| 36128 |
for (unsigned int i = 0; i < TARGET_FPU_auto; i++) |
| 36129 |
{ |
| 36130 |
arm_initialize_isa (fpubits, all_fpus[i].isa_bits); |
| 36131 |
bitmap_and_compl (tmpset, isa_all_fpubits_internal, fpubits); |
| 36132 |
bitmap_clear (isa_all_fpubits_internal); |
| 36133 |
bitmap_copy (isa_all_fpubits_internal, tmpset); |
| 36134 |
} |
| 36135 |
|
| 36136 |
if (!bitmap_empty_p (isa_all_fpubits_internal)) |
| 36137 |
{ |
| 36138 |
fprintf (stderr, "Error: found feature bits in the ALL_FPU_INTERAL" |
| 36139 |
" group that are not defined by any FPU.\n" |
| 36140 |
" Check your arm-cpus.in.\n"); |
| 36141 |
ASSERT_TRUE (bitmap_empty_p (isa_all_fpubits_internal)); |
| 36142 |
} |
| 36143 |
} |
| 36144 |
|
| 36145 |
static void |
| 36146 |
arm_run_selftests (void) |
| 36147 |
{ |
| 36148 |
arm_test_cpu_arch_data (); |
| 36149 |
arm_test_fpu_data (); |
| 36150 |
} |
| 36151 |
} /* Namespace selftest. */ |
| 36152 |
|
| 36153 |
#undef TARGET_RUN_TARGET_SELFTESTS |
| 36154 |
#define TARGET_RUN_TARGET_SELFTESTS selftest::arm_run_selftests |
| 36155 |
#endif /* CHECKING_P */ |
| 36156 |
|
| 36157 |
/* Implement TARGET_STACK_PROTECT_GUARD. In case of a |
| 36158 |
global variable based guard use the default else |
| 36159 |
return a null tree. */ |
| 36160 |
static tree |
| 36161 |
arm_stack_protect_guard (void) |
| 36162 |
{ |
| 36163 |
if (arm_stack_protector_guard == SSP_GLOBAL) |
| 36164 |
return default_stack_protect_guard (); |
| 36165 |
|
| 36166 |
return NULL_TREE; |
| 36167 |
} |
| 36168 |
|
| 36169 |
/* Worker function for TARGET_MD_ASM_ADJUST, while in thumb1 mode. |
| 36170 |
Unlike the arm version, we do NOT implement asm flag outputs. */ |
| 36171 |
|
| 36172 |
rtx_insn * |
| 36173 |
thumb1_md_asm_adjust (vec<rtx> &outputs, vec<rtx> & /*inputs*/, |
| 36174 |
vec<machine_mode> & /*input_modes*/, |
| 36175 |
vec<const char *> &constraints, |
| 36176 |
vec<rtx> &, vec<rtx> & /*clobbers*/, |
| 36177 |
HARD_REG_SET & /*clobbered_regs*/, location_t /*loc*/) |
| 36178 |
{ |
| 36179 |
for (unsigned i = 0, n = outputs.length (); i < n; ++i) |
| 36180 |
if (startswith (constraints[i], "=@cc")) |
| 36181 |
{ |
| 36182 |
sorry ("%<asm%> flags not supported in thumb1 mode"); |
| 36183 |
break; |
| 36184 |
} |
| 36185 |
return NULL; |
| 36186 |
} |
| 36187 |
|
| 36188 |
/* Generate code to enable conditional branches in functions over 1 MiB. |
| 36189 |
Parameters are: |
| 36190 |
operands: is the operands list of the asm insn (see arm_cond_branch or |
| 36191 |
arm_cond_branch_reversed). |
| 36192 |
pos_label: is an index into the operands array where operands[pos_label] is |
| 36193 |
the asm label of the final jump destination. |
| 36194 |
dest: is a string which is used to generate the asm label of the intermediate |
| 36195 |
destination |
| 36196 |
branch_format: is a string denoting the intermediate branch format, e.g. |
| 36197 |
"beq", "bne", etc. */ |
| 36198 |
|
| 36199 |
const char * |
| 36200 |
arm_gen_far_branch (rtx * operands, int pos_label, const char * dest, |
| 36201 |
const char * branch_format) |
| 36202 |
{ |
| 36203 |
rtx_code_label * tmp_label = gen_label_rtx (); |
| 36204 |
char label_buf[256]; |
| 36205 |
char buffer[128]; |
| 36206 |
ASM_GENERATE_INTERNAL_LABEL (label_buf, dest , \ |
| 36207 |
CODE_LABEL_NUMBER (tmp_label)); |
| 36208 |
const char *label_ptr = arm_strip_name_encoding (label_buf); |
| 36209 |
rtx dest_label = operands[pos_label]; |
| 36210 |
operands[pos_label] = tmp_label; |
| 36211 |
|
| 36212 |
snprintf (buffer, sizeof (buffer), "%s%s", branch_format , label_ptr); |
| 36213 |
output_asm_insn (buffer, operands); |
| 36214 |
|
| 36215 |
snprintf (buffer, sizeof (buffer), "b\t%%l0%d\n%s:", pos_label, label_ptr); |
| 36216 |
operands[pos_label] = dest_label; |
| 36217 |
output_asm_insn (buffer, operands); |
| 36218 |
return ""; |
| 36219 |
} |
| 36220 |
|
| 36221 |
/* If given mode matches, load from memory to LO_REGS. |
| 36222 |
(i.e [Rn], Rn <= LO_REGS). */ |
| 36223 |
enum reg_class |
| 36224 |
arm_mode_base_reg_class (machine_mode mode) |
| 36225 |
{ |
| 36226 |
if (TARGET_HAVE_MVE |
| 36227 |
&& (mode == E_V8QImode || mode == E_V4QImode || mode == E_V4HImode)) |
| 36228 |
return LO_REGS; |
| 36229 |
|
| 36230 |
return MODE_BASE_REG_REG_CLASS (mode); |
| 36231 |
} |
| 36232 |
|
| 36233 |
#undef TARGET_DOCUMENTATION_NAME |
| 36234 |
#define TARGET_DOCUMENTATION_NAME "ARM" |
| 36235 |
|
| 36236 |
struct gcc_target targetm = TARGET_INITIALIZER; |
| 36237 |
|
| 36238 |
/* Implement TARGET_VECTORIZE_GET_MASK_MODE. */ |
| 36239 |
|
| 36240 |
opt_machine_mode |
| 36241 |
arm_get_mask_mode (machine_mode mode) |
| 36242 |
{ |
| 36243 |
if (TARGET_HAVE_MVE) |
| 36244 |
return arm_mode_to_pred_mode (mode); |
| 36245 |
|
| 36246 |
return default_get_mask_mode (mode); |
| 36247 |
} |
| 36248 |
|
| 36249 |
/* Helper function to determine whether SEQ represents a sequence of |
| 36250 |
instructions representing the vsel<cond> floating point instructions. |
| 36251 |
This is an heuristic to check whether the proposed optimisation is desired, |
| 36252 |
the choice has no consequence for correctness. */ |
| 36253 |
static bool |
| 36254 |
arm_is_vsel_fp_insn (rtx_insn *seq) |
| 36255 |
{ |
| 36256 |
rtx_insn *curr_insn = seq; |
| 36257 |
rtx set = NULL_RTX; |
| 36258 |
/* The pattern may start with a simple set with register operands. Skip |
| 36259 |
through any of those. */ |
| 36260 |
while (curr_insn) |
| 36261 |
{ |
| 36262 |
set = single_set (curr_insn); |
| 36263 |
if (!set |
| 36264 |
|| !REG_P (SET_DEST (set))) |
| 36265 |
return false; |
| 36266 |
|
| 36267 |
if (!REG_P (SET_SRC (set))) |
| 36268 |
break; |
| 36269 |
curr_insn = NEXT_INSN (curr_insn); |
| 36270 |
} |
| 36271 |
|
| 36272 |
if (!set) |
| 36273 |
return false; |
| 36274 |
|
| 36275 |
/* The next instruction should be a compare. */ |
| 36276 |
if (!REG_P (SET_DEST (set)) |
| 36277 |
|| GET_CODE (SET_SRC (set)) != COMPARE) |
| 36278 |
return false; |
| 36279 |
|
| 36280 |
curr_insn = NEXT_INSN (curr_insn); |
| 36281 |
if (!curr_insn) |
| 36282 |
return false; |
| 36283 |
|
| 36284 |
/* And the last instruction should be an IF_THEN_ELSE. */ |
| 36285 |
set = single_set (curr_insn); |
| 36286 |
if (!set |
| 36287 |
|| !REG_P (SET_DEST (set)) |
| 36288 |
|| GET_CODE (SET_SRC (set)) != IF_THEN_ELSE) |
| 36289 |
return false; |
| 36290 |
|
| 36291 |
return !NEXT_INSN (curr_insn); |
| 36292 |
} |
| 36293 |
|
| 36294 |
|
| 36295 |
/* Helper function to determine whether SEQ represents a sequence of |
| 36296 |
instructions representing the Armv8.1-M Mainline conditional arithmetic |
| 36297 |
instructions: csinc, csneg and csinv. The cinc instruction is generated |
| 36298 |
using a different mechanism. |
| 36299 |
This is an heuristic to check whether the proposed optimisation is desired, |
| 36300 |
the choice has no consequence for correctness. */ |
| 36301 |
|
| 36302 |
static bool |
| 36303 |
arm_is_v81m_cond_insn (rtx_insn *seq) |
| 36304 |
{ |
| 36305 |
rtx_insn *curr_insn = seq; |
| 36306 |
rtx set = NULL_RTX; |
| 36307 |
/* The pattern may start with a simple set with register operands. Skip |
| 36308 |
through any of those. */ |
| 36309 |
while (curr_insn) |
| 36310 |
{ |
| 36311 |
set = single_set (curr_insn); |
| 36312 |
if (!set |
| 36313 |
|| !REG_P (SET_DEST (set))) |
| 36314 |
return false; |
| 36315 |
|
| 36316 |
if (!REG_P (SET_SRC (set))) |
| 36317 |
break; |
| 36318 |
curr_insn = NEXT_INSN (curr_insn); |
| 36319 |
} |
| 36320 |
|
| 36321 |
if (!set) |
| 36322 |
return false; |
| 36323 |
|
| 36324 |
/* The next instruction should be one of: |
| 36325 |
NEG: for csneg, |
| 36326 |
PLUS: for csinc, |
| 36327 |
NOT: for csinv. */ |
| 36328 |
if (GET_CODE (SET_SRC (set)) != NEG |
| 36329 |
&& GET_CODE (SET_SRC (set)) != PLUS |
| 36330 |
&& GET_CODE (SET_SRC (set)) != NOT) |
| 36331 |
return false; |
| 36332 |
|
| 36333 |
curr_insn = NEXT_INSN (curr_insn); |
| 36334 |
if (!curr_insn) |
| 36335 |
return false; |
| 36336 |
|
| 36337 |
/* The next instruction should be a COMPARE. */ |
| 36338 |
set = single_set (curr_insn); |
| 36339 |
if (!set |
| 36340 |
|| !REG_P (SET_DEST (set)) |
| 36341 |
|| GET_CODE (SET_SRC (set)) != COMPARE) |
| 36342 |
return false; |
| 36343 |
|
| 36344 |
curr_insn = NEXT_INSN (curr_insn); |
| 36345 |
if (!curr_insn) |
| 36346 |
return false; |
| 36347 |
|
| 36348 |
/* And the last instruction should be an IF_THEN_ELSE. */ |
| 36349 |
set = single_set (curr_insn); |
| 36350 |
if (!set |
| 36351 |
|| !REG_P (SET_DEST (set)) |
| 36352 |
|| GET_CODE (SET_SRC (set)) != IF_THEN_ELSE) |
| 36353 |
return false; |
| 36354 |
|
| 36355 |
return !NEXT_INSN (curr_insn); |
| 36356 |
} |
| 36357 |
|
| 36358 |
/* For Armv8.1-M Mainline we have both conditional execution through IT blocks, |
| 36359 |
as well as conditional arithmetic instructions controlled by |
| 36360 |
TARGET_COND_ARITH. To generate the latter we rely on a special part of the |
| 36361 |
"ce" pass that generates code for targets that don't support conditional |
| 36362 |
execution of general instructions known as "noce". These transformations |
| 36363 |
happen before 'reload_completed'. However, "noce" also triggers for some |
| 36364 |
unwanted patterns [PR 116444] that prevent "ce" optimisations after reload. |
| 36365 |
To make sure we can get both we use the TARGET_NOCE_CONVERSION_PROFITABLE_P |
| 36366 |
hook to only allow "noce" to generate the patterns that are profitable. */ |
| 36367 |
|
| 36368 |
bool |
| 36369 |
arm_noce_conversion_profitable_p (rtx_insn *seq, struct noce_if_info *if_info) |
| 36370 |
{ |
| 36371 |
if (!TARGET_COND_ARITH |
| 36372 |
|| reload_completed) |
| 36373 |
return default_noce_conversion_profitable_p (seq, if_info); |
| 36374 |
|
| 36375 |
if (arm_is_v81m_cond_insn (seq)) |
| 36376 |
return true; |
| 36377 |
|
| 36378 |
/* Look for vsel<cond> opportunities as we still want to codegen these for |
| 36379 |
Armv8.1-M Mainline targets. */ |
| 36380 |
if (arm_is_vsel_fp_insn (seq)) |
| 36381 |
return true; |
| 36382 |
|
| 36383 |
return false; |
| 36384 |
} |
| 36385 |
|
| 36386 |
/* Output assembly to read the thread pointer from the appropriate TPIDR |
| 36387 |
register into DEST. If PRED_P also emit the %? that can be used to |
| 36388 |
output the predication code. */ |
| 36389 |
|
| 36390 |
const char * |
| 36391 |
arm_output_load_tpidr (rtx dst, bool pred_p) |
| 36392 |
{ |
| 36393 |
char buf[64]; |
| 36394 |
int tpidr_coproc_num = -1; |
| 36395 |
switch (target_thread_pointer) |
| 36396 |
{ |
| 36397 |
case TP_TPIDRURW: |
| 36398 |
tpidr_coproc_num = 2; |
| 36399 |
break; |
| 36400 |
case TP_TPIDRURO: |
| 36401 |
tpidr_coproc_num = 3; |
| 36402 |
break; |
| 36403 |
case TP_TPIDRPRW: |
| 36404 |
tpidr_coproc_num = 4; |
| 36405 |
break; |
| 36406 |
default: |
| 36407 |
gcc_unreachable (); |
| 36408 |
} |
| 36409 |
snprintf (buf, sizeof (buf), |
| 36410 |
"mrc%s\tp15, 0, %%0, c13, c0, %d\t@ load_tp_hard", |
| 36411 |
pred_p ? "%?" : "", tpidr_coproc_num); |
| 36412 |
output_asm_insn (buf, &dst); |
| 36413 |
return ""; |
| 36414 |
} |
| 36415 |
|
| 36416 |
/* Return the MVE vector mode that has NUNITS elements of mode INNER_MODE. */ |
| 36417 |
opt_machine_mode |
| 36418 |
arm_mve_data_mode (scalar_mode inner_mode, poly_uint64 nunits) |
| 36419 |
{ |
| 36420 |
enum mode_class mclass |
| 36421 |
= (SCALAR_FLOAT_MODE_P (inner_mode) ? MODE_VECTOR_FLOAT : MODE_VECTOR_INT); |
| 36422 |
machine_mode mode; |
| 36423 |
FOR_EACH_MODE_IN_CLASS (mode, mclass) |
| 36424 |
if (inner_mode == GET_MODE_INNER (mode) |
| 36425 |
&& known_eq (nunits, GET_MODE_NUNITS (mode))) |
| 36426 |
return mode; |
| 36427 |
return opt_machine_mode (); |
| 36428 |
} |
| 36429 |
|
| 36430 |
#include "gt-arm.h" |